private void ShowInfo(int pressNo) { BookShop.BLL.Press bll = new BookShop.BLL.Press(); BookShop.Model.Press model = bll.GetModel(pressNo); this.lblpressNo.Text = model.pressNo.ToString(); this.txtpressName.Text = model.pressName; this.txtadress.Text = model.adress; this.txtzipCode.Text = model.zipCode; this.txtcontactPerson.Text = model.contactPerson; this.txttelephone.Text = model.telephone; this.txtfax.Text = model.fax; this.txtemail.Text = model.email; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(BookShop.Model.Press model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Press set "); strSql.Append("pressName=@pressName,"); strSql.Append("adress=@adress,"); strSql.Append("zipCode=@zipCode,"); strSql.Append("contactPerson=@contactPerson,"); strSql.Append("telephone=@telephone,"); strSql.Append("fax=@fax,"); strSql.Append("email=@email"); strSql.Append(" where pressNo=@pressNo "); SqlParameter[] parameters = { new SqlParameter("@pressName", SqlDbType.VarChar, 200), new SqlParameter("@adress", 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, 15), new SqlParameter("@email", SqlDbType.VarChar, 20), new SqlParameter("@pressNo", SqlDbType.Int, 4) }; parameters[0].Value = model.pressName; parameters[1].Value = model.adress; 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.pressNo; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public BookShop.Model.Press DataRowToModel(DataRow row) { BookShop.Model.Press model = new BookShop.Model.Press(); if (row != null) { if (row["pressNo"] != null && row["pressNo"].ToString() != "") { model.pressNo = int.Parse(row["pressNo"].ToString()); } if (row["pressName"] != null) { model.pressName = row["pressName"].ToString(); } if (row["adress"] != null) { model.adress = row["adress"].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.Press model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Press("); strSql.Append("pressNo,pressName,adress,zipCode,contactPerson,telephone,fax,email)"); strSql.Append(" values ("); strSql.Append("@pressNo,@pressName,@adress,@zipCode,@contactPerson,@telephone,@fax,@email)"); SqlParameter[] parameters = { new SqlParameter("@pressNo", SqlDbType.Int, 4), new SqlParameter("@pressName", SqlDbType.VarChar, 200), new SqlParameter("@adress", 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, 15), new SqlParameter("@email", SqlDbType.VarChar, 20) }; parameters[0].Value = model.pressNo; parameters[1].Value = model.pressName; parameters[2].Value = model.adress; 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.Press GetModel(int pressNo) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 pressNo,pressName,adress,zipCode,contactPerson,telephone,fax,email from Press "); strSql.Append(" where pressNo=@pressNo "); SqlParameter[] parameters = { new SqlParameter("@pressNo", SqlDbType.Int, 4) }; parameters[0].Value = pressNo; BookShop.Model.Press model = new BookShop.Model.Press(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtpressNo.Text)) { strErr += "pressNo格式错误!\\n"; } if (this.txtpressName.Text.Trim().Length == 0) { strErr += "pressName不能为空!\\n"; } if (this.txtadress.Text.Trim().Length == 0) { strErr += "adress不能为空!\\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; } int pressNo = int.Parse(this.txtpressNo.Text); string pressName = this.txtpressName.Text; string adress = this.txtadress.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.Press model = new BookShop.Model.Press(); model.pressNo = pressNo; model.pressName = pressName; model.adress = adress; model.zipCode = zipCode; model.contactPerson = contactPerson; model.telephone = telephone; model.fax = fax; model.email = email; BookShop.BLL.Press bll = new BookShop.BLL.Press(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }