de tai ltm2
5 posters
:: Góc Học Tập :: Lập Trình Mạng 2
Trang 1 trong tổng số 1 trang
de tai ltm2
ai code duoc bai 1 may tinh roi up len cho moi nguoi tham khao di nao
quocanh- Góp sức
- Tổng số bài gửi : 86
Join date : 18/09/2009
Age : 41
Đến từ : HỐ CHÍ MINH CITY
Code ne bac, giao dien thi tu ve nhe.
private void ResultOperator()
{
float vR = 0, vR1 = 0, vRs = 0;
bool vIsError = false;
//Using this code when set data format by VietNam
txtValue.Text = txtValue.Text.Replace(".", ",");
vR1 = float.Parse(txtValue.Text);
vR = float.Parse(hfResult.Value);
switch (hfOperator.Value.ToString())
{
case "/":
if(vR1 == 0)
{
ltrError.Text = "Can not devide for zero value.";
vIsError = true;
}
else
{
vRs = vR/vR1;
}
break;
case "*":
vRs = vR * vR1;
break;
case "+":
vRs = vR + vR1;
break;
case "-":
//Check if add operator in last item then replace with new operator
vRs = vR - vR1;
break;
default:
vIsError = true;
vRs = vR1;
break;
}
hfResult.Value = vRs.ToString();
if(!vIsError)
{
txtValue.Text = vRs.ToString();
}
}
///
/// Set value from button to display text when keypress.
///
protected void Button_Click(object sender, EventArgs e)
{
Button vbtn = sender as Button;
string vValue = "";
if (vbtn == null) { return; }
vValue = vbtn.Text;
switch (vValue)
{
case "/":
case "*":
case "+":
case "-":
//Check if add operator in last item then replace with new operator
if (("+-*/".IndexOf(Right(txtDisplay.Text.Trim(), 1)) != -1) && ("+-*/".IndexOf(hfLastValue.Value.ToString().Trim()) == -1))//Kiem tra khi nhan toan tu cung luc
{
txtDisplay.Text += txtValue.Text;
}
else if (("+-*/".IndexOf(Right(txtDisplay.Text.Trim(), 1)) != -1) && ("+-*/".IndexOf(vValue.Trim()) != -1))//Thay doi toan tu khi da co 1 toan tu hien hanh
{
txtDisplay.Text = Left(txtDisplay.Text.Trim(), txtDisplay.Text.Trim().Length - 1) + vValue + " ";
}
if ("+-*/".IndexOf(hfLastValue.Value.ToString().Trim()) == -1)
{
ResultOperator();
vValue = " " + vValue + " ";
}
else
{
vValue = "";
}
if ((txtDisplay.Text.Trim() == ""))// && (float.Parse(hfResult.Value.ToString()) >= 0)
{
txtDisplay.Text += hfResult.Value.ToString();
}
txtDisplay.Text += vValue;
hfOperator.Value = vbtn.Text;
break;
default:
if (("+-*/".IndexOf(hfLastValue.Value.ToString().Trim()) != -1) || (hfOperator.Value == "="))// &&(txtValue.Text.Length>1))
{
txtValue.Text = "";
}
if (txtDisplay.Text.Trim() != "") //Not fill when isempty
{
if (("+-*/".IndexOf(hfOperator.Value.Trim()) == -1))
{
txtDisplay.Text += vValue;
}
}
txtValue.Text += vValue;
break;
}
hfLastValue.Value = vbtn.Text;
}
{
float vR = 0, vR1 = 0, vRs = 0;
bool vIsError = false;
//Using this code when set data format by VietNam
txtValue.Text = txtValue.Text.Replace(".", ",");
vR1 = float.Parse(txtValue.Text);
vR = float.Parse(hfResult.Value);
switch (hfOperator.Value.ToString())
{
case "/":
if(vR1 == 0)
{
ltrError.Text = "Can not devide for zero value.";
vIsError = true;
}
else
{
vRs = vR/vR1;
}
break;
case "*":
vRs = vR * vR1;
break;
case "+":
vRs = vR + vR1;
break;
case "-":
//Check if add operator in last item then replace with new operator
vRs = vR - vR1;
break;
default:
vIsError = true;
vRs = vR1;
break;
}
hfResult.Value = vRs.ToString();
if(!vIsError)
{
txtValue.Text = vRs.ToString();
}
}
///
/// Set value from button to display text when keypress.
///
protected void Button_Click(object sender, EventArgs e)
{
Button vbtn = sender as Button;
string vValue = "";
if (vbtn == null) { return; }
vValue = vbtn.Text;
switch (vValue)
{
case "/":
case "*":
case "+":
case "-":
//Check if add operator in last item then replace with new operator
if (("+-*/".IndexOf(Right(txtDisplay.Text.Trim(), 1)) != -1) && ("+-*/".IndexOf(hfLastValue.Value.ToString().Trim()) == -1))//Kiem tra khi nhan toan tu cung luc
{
txtDisplay.Text += txtValue.Text;
}
else if (("+-*/".IndexOf(Right(txtDisplay.Text.Trim(), 1)) != -1) && ("+-*/".IndexOf(vValue.Trim()) != -1))//Thay doi toan tu khi da co 1 toan tu hien hanh
{
txtDisplay.Text = Left(txtDisplay.Text.Trim(), txtDisplay.Text.Trim().Length - 1) + vValue + " ";
}
if ("+-*/".IndexOf(hfLastValue.Value.ToString().Trim()) == -1)
{
ResultOperator();
vValue = " " + vValue + " ";
}
else
{
vValue = "";
}
if ((txtDisplay.Text.Trim() == ""))// && (float.Parse(hfResult.Value.ToString()) >= 0)
{
txtDisplay.Text += hfResult.Value.ToString();
}
txtDisplay.Text += vValue;
hfOperator.Value = vbtn.Text;
break;
default:
if (("+-*/".IndexOf(hfLastValue.Value.ToString().Trim()) != -1) || (hfOperator.Value == "="))// &&(txtValue.Text.Length>1))
{
txtValue.Text = "";
}
if (txtDisplay.Text.Trim() != "") //Not fill when isempty
{
if (("+-*/".IndexOf(hfOperator.Value.Trim()) == -1))
{
txtDisplay.Text += vValue;
}
}
txtValue.Text += vValue;
break;
}
hfLastValue.Value = vbtn.Text;
}
Re: de tai ltm2
Viết code khủng quá, đọc hổng có hỉu (
nguyenduc- Cống hiến
- Tổng số bài gửi : 312
Join date : 17/09/2009
Age : 44
Đến từ : Bến tre - Hồ chí minh
Re: de tai ltm2
Bạn nén luôn code & giao diện thành file share cho pà con tham khảo được ko ? Coi cái này cũng chả biết cáo nào ứng với cài nào. Đa tạ bácdragoniron đã viết:private void ResultOperator()
{
float vR = 0, vR1 = 0, vRs = 0;
bool vIsError = false;
//Using this code when set data format by VietNam
txtValue.Text = txtValue.Text.Replace(".", ","
Re: de tai ltm2
dung roi do bac, nhin vo cha hieu cai gi het
quocanh- Góp sức
- Tổng số bài gửi : 86
Join date : 18/09/2009
Age : 41
Đến từ : HỐ CHÍ MINH CITY
Re: de tai ltm2
Hiểu được hay không chưa biết . Nhưng nhìn vô thì không muốn hiểu luôn .
mr_h- Khởi đầu
- Tổng số bài gửi : 41
Join date : 19/09/2009
:: Góc Học Tập :: Lập Trình Mạng 2
Trang 1 trong tổng số 1 trang
Permissions in this forum:
Bạn không có quyền trả lời bài viết
|
|
10/12/2020, 01:06 by Ti3uThucodon93
» Tiểu thuyết : Yêu anh là sai lầm của cuộc đời em
24/2/2019, 11:49 by Ti3uThucodon93
» Tiểu thuyết : Yêu sai thời điểm
23/2/2019, 16:39 by Ti3uThucodon93
» Thơ Trung Quốc !
15/10/2018, 10:05 by Ti3uThucodon93
» Câu nói hay !
22/1/2017, 15:59 by Ti3uThucodon93
» Thơ tình dài !
15/11/2016, 11:45 by Ti3uThucodon93
» Thơ 4 câu !
1/9/2016, 16:14 by Ti3uThucodon93
» Thơ hài hước !
9/8/2016, 09:04 by Ti3uThucodon93
» Cách chữa trị bệnh hôi nách dành cho sinh viên
30/7/2016, 16:02 by thammybacsihathanh