ASp.net 텍스트 상자(TextBox) 계산, 숫자 입력 여부 판단

2217 단어
 
  
protected void txtQty_TextChanged(object sender, EventArgs e)
{
checkForm();
}
// ,
protected void checkForm()
{
try
{
if (!IsNumberic(txtQty.Text) && txtQty.Text != "")
{
checkbool = false;
Response.Write("alert(' , , !')");
txtQty.Text = "";
txtQty.Focus();
}
else if (txtQty.Text != "")
{
Qty = int.Parse(txtQty.Text);
}
if (!IsNumberic(txtVat.Text) && txtVat.Text != "")
{
Response.Write("alert(' , , !')");
checkbool = false;
txtVat.Text = "";
txtVat.Focus();
}
else if (txtVat.Text != "")
{
Vat = Double.Parse(txtVat.Text);
}
if (!IsNumberic(txtUnitPrice.Text) && txtUnitPrice.Text != "")
{
Response.Write("alert(' , , !')");
checkbool = false;
txtUnitPrice.Text = "";
txtUnitPrice.Focus();
}
else if (txtUnitPrice.Text != "")
{
UnitPrice = Double.Parse(txtUnitPrice.Text);
}
if (checkbool == true)
{
if (Vat != 0 && ExVatAmount != 0)
{
AmountVat = ExVatAmount / (1 - Vat / 100);
txtAmountVat.Text = AmountVat.ToString();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
///
/// :IsNumberic
/// :
/// :string oText:
/// : bool true:  false:
///

public bool IsNumberic(string oText)
{
try
{
// , Double, , 。
Double var1 = Convert.ToDouble(oText);
return true;
}
catch
{
return false;
}
}
}

좋은 웹페이지 즐겨찾기