/// <summary> /// 增加一条数据 /// </summary> public int Add(ZhangWei.Model.Supplier model) { StringBuilder strSql=new StringBuilder(); strSql.Append("insert into Supplier("); strSql.Append("Name,Address,Phone,Fax,PostalCode,ConstactPerson)"); strSql.Append(" values ("); strSql.Append("@Name,@Address,@Phone,@Fax,@PostalCode,@ConstactPerson)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Name", SqlDbType.VarChar,250), new SqlParameter("@Address", SqlDbType.VarChar,250), new SqlParameter("@Phone", SqlDbType.VarChar,25), new SqlParameter("@Fax", SqlDbType.VarChar,25), new SqlParameter("@PostalCode", SqlDbType.VarChar,10), new SqlParameter("@ConstactPerson", SqlDbType.VarChar,20)}; parameters[0].Value = model.Name; parameters[1].Value = model.Address; parameters[2].Value = model.Phone; parameters[3].Value = model.Fax; parameters[4].Value = model.PostalCode; parameters[5].Value = model.ConstactPerson; object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters); if (obj == null) { return 0; } else { return Convert.ToInt32(obj); } }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtName.Text.Trim().Length == 0) { strErr += "名称不能为空!\\n"; } //if(this.txtAddress.Text.Trim().Length==0) //{ // strErr+="Address不能为空!\\n"; //} //if(this.txtPhone.Text.Trim().Length==0) //{ // strErr+="Phone不能为空!\\n"; //} //if(this.txtFax.Text.Trim().Length==0) //{ // strErr+="Fax不能为空!\\n"; //} //if(this.txtPostalCode.Text.Trim().Length==0) //{ // strErr+="PostalCode不能为空!\\n"; //} //if(this.txtConstactPerson.Text.Trim().Length==0) //{ // strErr+="ConstactPerson不能为空!\\n"; //} if (strErr != "") { MessageBox.Show(this, strErr); return; } int Supplier_ID = int.Parse(this.lblSupplier_ID.Text); string Name = this.txtName.Text; string Address = this.txtAddress.Text; string Phone = this.txtPhone.Text; string Fax = this.txtFax.Text; string PostalCode = this.txtPostalCode.Text; string ConstactPerson = this.txtConstactPerson.Text; ZhangWei.Model.Supplier model = new ZhangWei.Model.Supplier(); model.Supplier_ID = Supplier_ID; model.Name = Name; model.Address = Address; model.Phone = Phone; model.Fax = Fax; model.PostalCode = PostalCode; model.ConstactPerson = ConstactPerson; ZhangWei.BLL.Supplier bll = new ZhangWei.BLL.Supplier(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
private void ShowInfo(int Supplier_ID) { ZhangWei.BLL.Supplier bll = new ZhangWei.BLL.Supplier(); ZhangWei.Model.Supplier model = bll.GetModel(Supplier_ID); this.lblSupplier_ID.Text = model.Supplier_ID.ToString(); this.txtName.Text = model.Name; this.txtAddress.Text = model.Address; this.txtPhone.Text = model.Phone; this.txtFax.Text = model.Fax; this.txtPostalCode.Text = model.PostalCode; this.txtConstactPerson.Text = model.ConstactPerson; }
/// <summary> /// 得到一个对象实体 /// </summary> public ZhangWei.Model.Supplier GetModel(int Supplier_ID) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 Supplier_ID,Name,Address,Phone,Fax,PostalCode,ConstactPerson from Supplier "); strSql.Append(" where Supplier_ID=@Supplier_ID"); SqlParameter[] parameters = { new SqlParameter("@Supplier_ID", SqlDbType.Int,4) }; parameters[0].Value = Supplier_ID; ZhangWei.Model.Supplier model=new ZhangWei.Model.Supplier(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { if(ds.Tables[0].Rows[0]["Supplier_ID"]!=null && ds.Tables[0].Rows[0]["Supplier_ID"].ToString()!="") { model.Supplier_ID=int.Parse(ds.Tables[0].Rows[0]["Supplier_ID"].ToString()); } if(ds.Tables[0].Rows[0]["Name"]!=null && ds.Tables[0].Rows[0]["Name"].ToString()!="") { model.Name=ds.Tables[0].Rows[0]["Name"].ToString(); } if(ds.Tables[0].Rows[0]["Address"]!=null && ds.Tables[0].Rows[0]["Address"].ToString()!="") { model.Address=ds.Tables[0].Rows[0]["Address"].ToString(); } if(ds.Tables[0].Rows[0]["Phone"]!=null && ds.Tables[0].Rows[0]["Phone"].ToString()!="") { model.Phone=ds.Tables[0].Rows[0]["Phone"].ToString(); } if(ds.Tables[0].Rows[0]["Fax"]!=null && ds.Tables[0].Rows[0]["Fax"].ToString()!="") { model.Fax=ds.Tables[0].Rows[0]["Fax"].ToString(); } if(ds.Tables[0].Rows[0]["PostalCode"]!=null && ds.Tables[0].Rows[0]["PostalCode"].ToString()!="") { model.PostalCode=ds.Tables[0].Rows[0]["PostalCode"].ToString(); } if(ds.Tables[0].Rows[0]["ConstactPerson"]!=null && ds.Tables[0].Rows[0]["ConstactPerson"].ToString()!="") { model.ConstactPerson=ds.Tables[0].Rows[0]["ConstactPerson"].ToString(); } return model; } else { return null; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ZhangWei.Model.Supplier model) { StringBuilder strSql=new StringBuilder(); strSql.Append("update Supplier set "); strSql.Append("Name=@Name,"); strSql.Append("Address=@Address,"); strSql.Append("Phone=@Phone,"); strSql.Append("Fax=@Fax,"); strSql.Append("PostalCode=@PostalCode,"); strSql.Append("ConstactPerson=@ConstactPerson"); strSql.Append(" where Supplier_ID=@Supplier_ID"); SqlParameter[] parameters = { new SqlParameter("@Name", SqlDbType.VarChar,250), new SqlParameter("@Address", SqlDbType.VarChar,250), new SqlParameter("@Phone", SqlDbType.VarChar,25), new SqlParameter("@Fax", SqlDbType.VarChar,25), new SqlParameter("@PostalCode", SqlDbType.VarChar,10), new SqlParameter("@ConstactPerson", SqlDbType.VarChar,20), new SqlParameter("@Supplier_ID", SqlDbType.Int,4)}; parameters[0].Value = model.Name; parameters[1].Value = model.Address; parameters[2].Value = model.Phone; parameters[3].Value = model.Fax; parameters[4].Value = model.PostalCode; parameters[5].Value = model.ConstactPerson; parameters[6].Value = model.Supplier_ID; int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters); if (rows > 0) { return true; } else { return false; } }