private void ShowInfo(string compantNo) { BookShop.BLL.Company bll = new BookShop.BLL.Company(); BookShop.Model.Company model = bll.GetModel(compantNo); this.lblcompantNo.Text = model.compantNo; this.lblcompanyName.Text = model.companyName; this.lbladdress.Text = model.address; this.lblzipCode.Text = model.zipCode; this.lblcontactPerson.Text = model.contactPerson; this.lbltelephone.Text = model.telephone; this.lblfax.Text = model.fax; this.lblemail.Text = model.email; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(BookShop.Model.Company model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Company set "); strSql.Append("companyName=@companyName,"); strSql.Append("address=@address,"); strSql.Append("zipCode=@zipCode,"); strSql.Append("contactPerson=@contactPerson,"); strSql.Append("telephone=@telephone,"); strSql.Append("fax=@fax,"); strSql.Append("email=@email"); strSql.Append(" where compantNo=@compantNo "); SqlParameter[] parameters = { new SqlParameter("@companyName", SqlDbType.VarChar, 20), new SqlParameter("@address", SqlDbType.VarChar, 40), new SqlParameter("@zipCode", SqlDbType.Char, 6), new SqlParameter("@contactPerson", SqlDbType.VarChar, 12), new SqlParameter("@telephone", SqlDbType.VarChar, 15), new SqlParameter("@fax", SqlDbType.VarChar, 20), new SqlParameter("@email", SqlDbType.VarChar, 20), new SqlParameter("@compantNo", SqlDbType.Char, 12) }; parameters[0].Value = model.companyName; parameters[1].Value = model.address; parameters[2].Value = model.zipCode; parameters[3].Value = model.contactPerson; parameters[4].Value = model.telephone; parameters[5].Value = model.fax; parameters[6].Value = model.email; parameters[7].Value = model.compantNo; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public BookShop.Model.Company DataRowToModel(DataRow row) { BookShop.Model.Company model = new BookShop.Model.Company(); if (row != null) { if (row["compantNo"] != null) { model.compantNo = row["compantNo"].ToString(); } if (row["companyName"] != null) { model.companyName = row["companyName"].ToString(); } if (row["address"] != null) { model.address = row["address"].ToString(); } if (row["zipCode"] != null) { model.zipCode = row["zipCode"].ToString(); } if (row["contactPerson"] != null) { model.contactPerson = row["contactPerson"].ToString(); } if (row["telephone"] != null) { model.telephone = row["telephone"].ToString(); } if (row["fax"] != null) { model.fax = row["fax"].ToString(); } if (row["email"] != null) { model.email = row["email"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(BookShop.Model.Company model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Company("); strSql.Append("compantNo,companyName,address,zipCode,contactPerson,telephone,fax,email)"); strSql.Append(" values ("); strSql.Append("@compantNo,@companyName,@address,@zipCode,@contactPerson,@telephone,@fax,@email)"); SqlParameter[] parameters = { new SqlParameter("@compantNo", SqlDbType.Char, 12), new SqlParameter("@companyName", SqlDbType.VarChar, 20), new SqlParameter("@address", SqlDbType.VarChar, 40), new SqlParameter("@zipCode", SqlDbType.Char, 6), new SqlParameter("@contactPerson", SqlDbType.VarChar, 12), new SqlParameter("@telephone", SqlDbType.VarChar, 15), new SqlParameter("@fax", SqlDbType.VarChar, 20), new SqlParameter("@email", SqlDbType.VarChar, 20) }; parameters[0].Value = model.compantNo; parameters[1].Value = model.companyName; parameters[2].Value = model.address; parameters[3].Value = model.zipCode; parameters[4].Value = model.contactPerson; parameters[5].Value = model.telephone; parameters[6].Value = model.fax; parameters[7].Value = model.email; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public BookShop.Model.Company GetModel(string compantNo) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 compantNo,companyName,address,zipCode,contactPerson,telephone,fax,email from Company "); strSql.Append(" where compantNo=@compantNo "); SqlParameter[] parameters = { new SqlParameter("@compantNo", SqlDbType.Char, 12) }; parameters[0].Value = compantNo; BookShop.Model.Company model = new BookShop.Model.Company(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtcompanyName.Text.Trim().Length == 0) { strErr += "companyName不能为空!\\n"; } if (this.txtaddress.Text.Trim().Length == 0) { strErr += "address不能为空!\\n"; } if (this.txtzipCode.Text.Trim().Length == 0) { strErr += "zipCode不能为空!\\n"; } if (this.txtcontactPerson.Text.Trim().Length == 0) { strErr += "contactPerson不能为空!\\n"; } if (this.txttelephone.Text.Trim().Length == 0) { strErr += "telephone不能为空!\\n"; } if (this.txtfax.Text.Trim().Length == 0) { strErr += "fax不能为空!\\n"; } if (this.txtemail.Text.Trim().Length == 0) { strErr += "email不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string compantNo = this.lblcompantNo.Text; string companyName = this.txtcompanyName.Text; string address = this.txtaddress.Text; string zipCode = this.txtzipCode.Text; string contactPerson = this.txtcontactPerson.Text; string telephone = this.txttelephone.Text; string fax = this.txtfax.Text; string email = this.txtemail.Text; BookShop.Model.Company model = new BookShop.Model.Company(); model.compantNo = compantNo; model.companyName = companyName; model.address = address; model.zipCode = zipCode; model.contactPerson = contactPerson; model.telephone = telephone; model.fax = fax; model.email = email; BookShop.BLL.Company bll = new BookShop.BLL.Company(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }