public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtName.Text.Trim().Length == 0) { strErr += "Name不能为空!\\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 Customer_ID = int.Parse(this.lblCustomer_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.Customer model = new ZhangWei.Model.Customer(); model.Customer_ID = Customer_ID; model.Name = Name; model.Address = Address; model.Phone = Phone; model.Fax = Fax; model.PostalCode = PostalCode; model.ConstactPerson = ConstactPerson; ZhangWei.BLL.Customer bll = new ZhangWei.BLL.Customer(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
private void ShowInfo(int Customer_ID) { ZhangWei.BLL.Customer bll = new ZhangWei.BLL.Customer(); ZhangWei.Model.Customer model = bll.GetModel(Customer_ID); this.lblCustomer_ID.Text = model.Customer_ID.ToString(); this.lblName.Text = model.Name; this.lblAddress.Text = model.Address; this.lblPhone.Text = model.Phone; this.lblFax.Text = model.Fax; this.lblPostalCode.Text = model.PostalCode; this.lblConstactPerson.Text = model.ConstactPerson; }
protected 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; } 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.Customer model = new ZhangWei.Model.Customer(); model.Name = Name; model.Address = Address; model.Phone = Phone; model.Fax = Fax; model.PostalCode = PostalCode; model.ConstactPerson = ConstactPerson; ZhangWei.BLL.Customer bll = new ZhangWei.BLL.Customer(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }
/// <summary> /// 得到一个对象实体 /// </summary> public ZhangWei.Model.Customer GetModel(int Customer_ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Customer_ID,Name,Address,Phone,Fax,PostalCode,ConstactPerson from Customer "); strSql.Append(" where Customer_ID=@Customer_ID"); SqlParameter[] parameters = { new SqlParameter("@Customer_ID", SqlDbType.Int, 4) }; parameters[0].Value = Customer_ID; ZhangWei.Model.Customer model = new ZhangWei.Model.Customer(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Customer_ID"] != null && ds.Tables[0].Rows[0]["Customer_ID"].ToString() != "") { model.Customer_ID = int.Parse(ds.Tables[0].Rows[0]["Customer_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.Customer model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Customer 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 Customer_ID=@Customer_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("@Customer_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.Customer_ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(ZhangWei.Model.Customer model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Customer("); 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)); } }