首页上一页 1 下一页尾页 1 条记录 1/1页
《ASP.NET实例自学手册》中输入小数出错?
发表在ASP.NET图书答疑
2008-09-11
是否精华
是
否
版块置顶:
是
否
ASP.NET实例自学手册
在文件Stock_add.aspx.cs中
protected void Button1_Click(object sender, EventArgs e)
{
string CommodityId=this.CommodityId.Text.ToString();
string CompanyId=this.CompanyId.Value.ToString();
int Number = Math.Abs(Convert.ToInt32(this.Number.Text));
int Pirce = Math.Abs(Convert.ToInt32(this.Pirce.Text));
string StockDate=this.StockDate.SelectedDate.ToShortDateString();
string SettlementType=this.SettlementType.Text.ToString();
int Payment = Math.Abs(Convert.ToInt32(Request["Payment"]));
int FactPayment = Math.Abs(Convert.ToInt32(this.FactPayment.Text));
int NotPayment = Math.Abs(Convert.ToInt32(Request["NotPayment"]));
string ManageMan=this.ManageMan.Text.ToString();
string Username = Convert.ToString(Session["username"]);
string AddTime=Convert.ToString(DateTime.Now);
string Type = "进货信息";
//计算输入的金额是否正确
if (Number * Pirce < Payment)
{
Response.Write("<script>alert('应付金额填写错误');history.back()</script>");
Response.End();
}
SqlConnection strcon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]);
strcon.Open();
SqlCommand scd = new SqlCommand("insert into tb_Stock (CommodityId,CompanyId,Number,Pirce,StockDate,SettlementType,Payment,FactPayment,NotPayment,ManageMan,Username,AddTime,Type)values('" + CommodityId + "','" + CompanyId + "','" + Number + "','" + Pirce + "','" + StockDate + "','" + SettlementType + "','" + Payment + "','" + FactPayment + "','" + NotPayment + "','" + ManageMan + "','" + Username + "','" + AddTime + "','" + Type + "')", strcon);
scd.ExecuteNonQuery();
strcon.Close();
Response.Write("<script language=javascript>alert('添加成功');location='Stock_return.aspx'</script>");
}
其中Pirce,Payment,FactPayment,NotPayment都是int,在输入带有小数点的数字时,会出错,应该怎样改才合理呢?而还有很多地方又怎样改呢?
在文件Stock_add.aspx.cs中
protected void Button1_Click(object sender, EventArgs e)
{
string CommodityId=this.CommodityId.Text.ToString();
string CompanyId=this.CompanyId.Value.ToString();
int Number = Math.Abs(Convert.ToInt32(this.Number.Text));
int Pirce = Math.Abs(Convert.ToInt32(this.Pirce.Text));
string StockDate=this.StockDate.SelectedDate.ToShortDateString();
string SettlementType=this.SettlementType.Text.ToString();
int Payment = Math.Abs(Convert.ToInt32(Request["Payment"]));
int FactPayment = Math.Abs(Convert.ToInt32(this.FactPayment.Text));
int NotPayment = Math.Abs(Convert.ToInt32(Request["NotPayment"]));
string ManageMan=this.ManageMan.Text.ToString();
string Username = Convert.ToString(Session["username"]);
string AddTime=Convert.ToString(DateTime.Now);
string Type = "进货信息";
//计算输入的金额是否正确
if (Number * Pirce < Payment)
{
Response.Write("<script>alert('应付金额填写错误');history.back()</script>");
Response.End();
}
SqlConnection strcon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]);
strcon.Open();
SqlCommand scd = new SqlCommand("insert into tb_Stock (CommodityId,CompanyId,Number,Pirce,StockDate,SettlementType,Payment,FactPayment,NotPayment,ManageMan,Username,AddTime,Type)values('" + CommodityId + "','" + CompanyId + "','" + Number + "','" + Pirce + "','" + StockDate + "','" + SettlementType + "','" + Payment + "','" + FactPayment + "','" + NotPayment + "','" + ManageMan + "','" + Username + "','" + AddTime + "','" + Type + "')", strcon);
scd.ExecuteNonQuery();
strcon.Close();
Response.Write("<script language=javascript>alert('添加成功');location='Stock_return.aspx'</script>");
}
其中Pirce,Payment,FactPayment,NotPayment都是int,在输入带有小数点的数字时,会出错,应该怎样改才合理呢?而还有很多地方又怎样改呢?