protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtBlanceDate.Text.Trim().Length == 0) { strErr += "BlanceDate不能为空!\\n"; } if (this.txtFailUserCode.Text.Trim().Length == 0) { strErr += "FailUserCode不能为空!\\n"; } if (!PageValidate.IsNumber(txtFail.Text)) { strErr += "Fail格式错误!\\n"; } if (!PageValidate.IsNumber(txtAllCount.Text)) { strErr += "AllCount格式错误!\\n"; } if (!PageValidate.IsDecimal(txtAllMoney.Text)) { strErr += "AllMoney格式错误!\\n"; } if (!PageValidate.IsDecimal(txtRefundMoney.Text)) { strErr += "RefundMoney格式错误!\\n"; } if (!PageValidate.IsDateTime(txtBlanceTime.Text)) { strErr += "BlanceTime格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string BlanceDate = this.txtBlanceDate.Text; string FailUserCode = this.txtFailUserCode.Text; int Fail = int.Parse(this.txtFail.Text); int AllCount = int.Parse(this.txtAllCount.Text); decimal AllMoney = decimal.Parse(this.txtAllMoney.Text); decimal RefundMoney = decimal.Parse(this.txtRefundMoney.Text); DateTime BlanceTime = DateTime.Parse(this.txtBlanceTime.Text); WebDemo.Model.WebDemo.BlanceAccount model = new WebDemo.Model.WebDemo.BlanceAccount(); model.BlanceDate = BlanceDate; model.FailUserCode = FailUserCode; model.Fail = Fail; model.AllCount = AllCount; model.AllMoney = AllMoney; model.RefundMoney = RefundMoney; model.BlanceTime = BlanceTime; WebDemo.BLL.WebDemo.BlanceAccount bll = new WebDemo.BLL.WebDemo.BlanceAccount(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }
private void ShowInfo(int ID) { WebDemo.BLL.WebDemo.BlanceAccount bll = new WebDemo.BLL.WebDemo.BlanceAccount(); WebDemo.Model.WebDemo.BlanceAccount model = bll.GetModel(ID); this.lblID.Text = model.ID.ToString(); this.txtBlanceDate.Text = model.BlanceDate; this.txtFailUserCode.Text = model.FailUserCode; this.txtFail.Text = model.Fail.ToString(); this.txtAllCount.Text = model.AllCount.ToString(); this.txtAllMoney.Text = model.AllMoney.ToString(); this.txtRefundMoney.Text = model.RefundMoney.ToString(); this.txtBlanceTime.Text = model.BlanceTime.ToString(); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebDemo.Model.WebDemo.BlanceAccount model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update BlanceAccount set "); strSql.Append("BlanceDate=@BlanceDate,"); strSql.Append("FailUserCode=@FailUserCode,"); strSql.Append("Fail=@Fail,"); strSql.Append("AllCount=@AllCount,"); strSql.Append("AllMoney=@AllMoney,"); strSql.Append("RefundMoney=@RefundMoney,"); strSql.Append("BlanceTime=@BlanceTime"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@BlanceDate", SqlDbType.VarChar, 20), new SqlParameter("@FailUserCode", SqlDbType.VarChar, 1000), new SqlParameter("@Fail", SqlDbType.Int, 4), new SqlParameter("@AllCount", SqlDbType.Int, 4), new SqlParameter("@AllMoney", SqlDbType.Decimal, 9), new SqlParameter("@RefundMoney", SqlDbType.Decimal, 9), new SqlParameter("@BlanceTime", SqlDbType.DateTime), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.BlanceDate; parameters[1].Value = model.FailUserCode; parameters[2].Value = model.Fail; parameters[3].Value = model.AllCount; parameters[4].Value = model.AllMoney; parameters[5].Value = model.RefundMoney; parameters[6].Value = model.BlanceTime; parameters[7].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.BlanceAccount DataRowToModel(DataRow row) { WebDemo.Model.WebDemo.BlanceAccount model = new WebDemo.Model.WebDemo.BlanceAccount(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["BlanceDate"] != null) { model.BlanceDate = row["BlanceDate"].ToString(); } if (row["FailUserCode"] != null) { model.FailUserCode = row["FailUserCode"].ToString(); } if (row["Fail"] != null && row["Fail"].ToString() != "") { model.Fail = int.Parse(row["Fail"].ToString()); } if (row["AllCount"] != null && row["AllCount"].ToString() != "") { model.AllCount = int.Parse(row["AllCount"].ToString()); } if (row["AllMoney"] != null && row["AllMoney"].ToString() != "") { model.AllMoney = decimal.Parse(row["AllMoney"].ToString()); } if (row["RefundMoney"] != null && row["RefundMoney"].ToString() != "") { model.RefundMoney = decimal.Parse(row["RefundMoney"].ToString()); } if (row["BlanceTime"] != null && row["BlanceTime"].ToString() != "") { model.BlanceTime = DateTime.Parse(row["BlanceTime"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(WebDemo.Model.WebDemo.BlanceAccount model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into BlanceAccount("); strSql.Append("BlanceDate,FailUserCode,Fail,AllCount,AllMoney,RefundMoney,BlanceTime)"); strSql.Append(" values ("); strSql.Append("@BlanceDate,@FailUserCode,@Fail,@AllCount,@AllMoney,@RefundMoney,@BlanceTime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@BlanceDate", SqlDbType.VarChar, 20), new SqlParameter("@FailUserCode", SqlDbType.VarChar, 1000), new SqlParameter("@Fail", SqlDbType.Int, 4), new SqlParameter("@AllCount", SqlDbType.Int, 4), new SqlParameter("@AllMoney", SqlDbType.Decimal, 9), new SqlParameter("@RefundMoney", SqlDbType.Decimal, 9), new SqlParameter("@BlanceTime", SqlDbType.DateTime) }; parameters[0].Value = model.BlanceDate; parameters[1].Value = model.FailUserCode; parameters[2].Value = model.Fail; parameters[3].Value = model.AllCount; parameters[4].Value = model.AllMoney; parameters[5].Value = model.RefundMoney; parameters[6].Value = model.BlanceTime; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.BlanceAccount GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,BlanceDate,FailUserCode,Fail,AllCount,AllMoney,RefundMoney,BlanceTime from BlanceAccount "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; WebDemo.Model.WebDemo.BlanceAccount model = new WebDemo.Model.WebDemo.BlanceAccount(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }