public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtInvoiceCode.Text)) { strErr += "InvoiceCode格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int InvoiceID = int.Parse(this.lblInvoiceID.Text); int InvoiceCode = int.Parse(this.txtInvoiceCode.Text); WebDemo.Model.WebDemo.InvoiceLog model = new WebDemo.Model.WebDemo.InvoiceLog(); model.InvoiceID = InvoiceID; model.InvoiceCode = InvoiceCode; WebDemo.BLL.WebDemo.InvoiceLog bll = new WebDemo.BLL.WebDemo.InvoiceLog(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
private void ShowInfo(int InvoiceID) { WebDemo.BLL.WebDemo.InvoiceLog bll = new WebDemo.BLL.WebDemo.InvoiceLog(); WebDemo.Model.WebDemo.InvoiceLog model = bll.GetModel(InvoiceID); this.lblInvoiceID.Text = model.InvoiceID.ToString(); this.txtInvoiceCode.Text = model.InvoiceCode.ToString(); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebDemo.Model.WebDemo.InvoiceLog model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update InvoiceLog set "); strSql.Append("InvoiceCode=@InvoiceCode"); strSql.Append(" where InvoiceID=@InvoiceID"); SqlParameter[] parameters = { new SqlParameter("@InvoiceCode", SqlDbType.Int, 4), new SqlParameter("@InvoiceID", SqlDbType.Int, 4) }; parameters[0].Value = model.InvoiceCode; parameters[1].Value = model.InvoiceID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(WebDemo.Model.WebDemo.InvoiceLog model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into InvoiceLog("); strSql.Append("InvoiceCode)"); strSql.Append(" values ("); strSql.Append("@InvoiceCode)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@InvoiceCode", SqlDbType.Int, 4) }; parameters[0].Value = model.InvoiceCode; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.InvoiceLog DataRowToModel(DataRow row) { WebDemo.Model.WebDemo.InvoiceLog model = new WebDemo.Model.WebDemo.InvoiceLog(); if (row != null) { if (row["InvoiceID"] != null && row["InvoiceID"].ToString() != "") { model.InvoiceID = int.Parse(row["InvoiceID"].ToString()); } if (row["InvoiceCode"] != null && row["InvoiceCode"].ToString() != "") { model.InvoiceCode = int.Parse(row["InvoiceCode"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.InvoiceLog GetModel(int InvoiceID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 InvoiceID,InvoiceCode from InvoiceLog "); strSql.Append(" where InvoiceID=@InvoiceID"); SqlParameter[] parameters = { new SqlParameter("@InvoiceID", SqlDbType.Int, 4) }; parameters[0].Value = InvoiceID; WebDemo.Model.WebDemo.InvoiceLog model = new WebDemo.Model.WebDemo.InvoiceLog(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }