private void ShowInfo(int id) { Jium.BLL.clerk bll = new Jium.BLL.clerk(); Jium.Model.clerk model = bll.GetModel(id); this.lblid.Text = model.id.ToString(); this.txtcname.Text = model.cname; this.txtcphone.Text = model.cphone; this.txtcemail.Text = model.cemail; this.txtcsex.Text = model.csex.ToString(); this.txtclevel.Text = model.clevel.ToString(); this.lblccode.Text = model.ccode; this.txtcaddress.Text = model.caddress; this.txtcsalesum.Text = model.csalesum.ToString(); this.txtcremark.Text = model.cremark; this.txtcls1.Text = model.cls1; this.txtcls2.Text = model.cls2; this.txtcls3.Text = model.cls3; this.txtcls4.Text = model.cls4; this.txtcls5.Text = model.cls5; this.txtcld1.Text = model.cld1.ToString(); this.txtcld2.Text = model.cld2.ToString(); this.txtcld3.Text = model.cld3.ToString(); this.txtcld4.Text = model.cld4.ToString(); this.txtcld5.Text = model.cld5.ToString(); this.txtcldc1.Text = model.cldc1.ToString(); this.txtcldc2.Text = model.cldc2.ToString(); this.txtcldc3.Text = model.cldc3.ToString(); this.txtcldc4.Text = model.cldc4.ToString(); this.txtcldc5.Text = model.cldc5.ToString(); }
/// <summary> /// 得到一个对象实体 /// </summary> public Jium.Model.clerk GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id,cname,cphone,cemail,csex,clevel,ccode,caddress,csalesum,cremark,cls1,cls2,cls3,cls4,cls5,cld1,cld2,cld3,cld4,cld5,cldc1,cldc2,cldc3,cldc4,cldc5 from clerk "); strSql.Append(" where id=@id"); MySqlParameter[] parameters = { new MySqlParameter("@id", MySqlDbType.Int32) }; parameters[0].Value = id; Jium.Model.clerk model = new Jium.Model.clerk(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Jium.Model.clerk model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into clerk("); strSql.Append("cname,cphone,cemail,csex,clevel,ccode,caddress,csalesum,cremark,cls1,cls2,cls3,cls4,cls5,cld1,cld2,cld3,cld4,cld5,cldc1,cldc2,cldc3,cldc4,cldc5)"); strSql.Append(" values ("); strSql.Append("@cname,@cphone,@cemail,@csex,@clevel,@ccode,@caddress,@csalesum,@cremark,@cls1,@cls2,@cls3,@cls4,@cls5,@cld1,@cld2,@cld3,@cld4,@cld5,@cldc1,@cldc2,@cldc3,@cldc4,@cldc5)"); MySqlParameter[] parameters = { new MySqlParameter("@cname", MySqlDbType.VarChar, 40), new MySqlParameter("@cphone", MySqlDbType.VarChar, 20), new MySqlParameter("@cemail", MySqlDbType.VarChar, 50), new MySqlParameter("@csex", MySqlDbType.Int32, 11), new MySqlParameter("@clevel", MySqlDbType.Int32, 11), new MySqlParameter("@ccode", MySqlDbType.VarChar, 20), new MySqlParameter("@caddress", MySqlDbType.VarChar, 100), new MySqlParameter("@csalesum", MySqlDbType.Decimal, 20), new MySqlParameter("@cremark", MySqlDbType.VarChar, 200), new MySqlParameter("@cls1", MySqlDbType.VarChar, 20), new MySqlParameter("@cls2", MySqlDbType.VarChar, 20), new MySqlParameter("@cls3", MySqlDbType.VarChar, 20), new MySqlParameter("@cls4", MySqlDbType.VarChar, 20), new MySqlParameter("@cls5", MySqlDbType.VarChar, 20), new MySqlParameter("@cld1", MySqlDbType.Int32, 11), new MySqlParameter("@cld2", MySqlDbType.Int32, 11), new MySqlParameter("@cld3", MySqlDbType.Int32, 11), new MySqlParameter("@cld4", MySqlDbType.Int32, 11), new MySqlParameter("@cld5", MySqlDbType.Int32, 11), new MySqlParameter("@cldc1", MySqlDbType.Decimal, 20), new MySqlParameter("@cldc2", MySqlDbType.Decimal, 20), new MySqlParameter("@cldc3", MySqlDbType.Decimal, 20), new MySqlParameter("@cldc4", MySqlDbType.Decimal, 20), new MySqlParameter("@cldc5", MySqlDbType.Decimal, 20) }; parameters[0].Value = model.cname; parameters[1].Value = model.cphone; parameters[2].Value = model.cemail; parameters[3].Value = model.csex; parameters[4].Value = model.clevel; parameters[5].Value = model.ccode; parameters[6].Value = model.caddress; parameters[7].Value = model.csalesum; parameters[8].Value = model.cremark; parameters[9].Value = model.cls1; parameters[10].Value = model.cls2; parameters[11].Value = model.cls3; parameters[12].Value = model.cls4; parameters[13].Value = model.cls5; parameters[14].Value = model.cld1; parameters[15].Value = model.cld2; parameters[16].Value = model.cld3; parameters[17].Value = model.cld4; parameters[18].Value = model.cld5; parameters[19].Value = model.cldc1; parameters[20].Value = model.cldc2; parameters[21].Value = model.cldc3; parameters[22].Value = model.cldc4; parameters[23].Value = model.cldc5; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Jium.Model.clerk DataRowToModel(DataRow row) { Jium.Model.clerk model = new Jium.Model.clerk(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["cname"] != null) { model.cname = row["cname"].ToString(); } if (row["cphone"] != null) { model.cphone = row["cphone"].ToString(); } if (row["cemail"] != null) { model.cemail = row["cemail"].ToString(); } if (row["csex"] != null && row["csex"].ToString() != "") { model.csex = int.Parse(row["csex"].ToString()); } if (row["clevel"] != null && row["clevel"].ToString() != "") { model.clevel = int.Parse(row["clevel"].ToString()); } if (row["ccode"] != null) { model.ccode = row["ccode"].ToString(); } if (row["caddress"] != null) { model.caddress = row["caddress"].ToString(); } if (row["csalesum"] != null && row["csalesum"].ToString() != "") { model.csalesum = decimal.Parse(row["csalesum"].ToString()); } if (row["cremark"] != null) { model.cremark = row["cremark"].ToString(); } if (row["cls1"] != null) { model.cls1 = row["cls1"].ToString(); } if (row["cls2"] != null) { model.cls2 = row["cls2"].ToString(); } if (row["cls3"] != null) { model.cls3 = row["cls3"].ToString(); } if (row["cls4"] != null) { model.cls4 = row["cls4"].ToString(); } if (row["cls5"] != null) { model.cls5 = row["cls5"].ToString(); } if (row["cld1"] != null && row["cld1"].ToString() != "") { model.cld1 = int.Parse(row["cld1"].ToString()); } if (row["cld2"] != null && row["cld2"].ToString() != "") { model.cld2 = int.Parse(row["cld2"].ToString()); } if (row["cld3"] != null && row["cld3"].ToString() != "") { model.cld3 = int.Parse(row["cld3"].ToString()); } if (row["cld4"] != null && row["cld4"].ToString() != "") { model.cld4 = int.Parse(row["cld4"].ToString()); } if (row["cld5"] != null && row["cld5"].ToString() != "") { model.cld5 = int.Parse(row["cld5"].ToString()); } if (row["cldc1"] != null && row["cldc1"].ToString() != "") { model.cldc1 = decimal.Parse(row["cldc1"].ToString()); } if (row["cldc2"] != null && row["cldc2"].ToString() != "") { model.cldc2 = decimal.Parse(row["cldc2"].ToString()); } if (row["cldc3"] != null && row["cldc3"].ToString() != "") { model.cldc3 = decimal.Parse(row["cldc3"].ToString()); } if (row["cldc4"] != null && row["cldc4"].ToString() != "") { model.cldc4 = decimal.Parse(row["cldc4"].ToString()); } if (row["cldc5"] != null && row["cldc5"].ToString() != "") { model.cldc5 = decimal.Parse(row["cldc5"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Jium.Model.clerk model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update clerk set "); strSql.Append("cname=@cname,"); strSql.Append("cphone=@cphone,"); strSql.Append("cemail=@cemail,"); strSql.Append("csex=@csex,"); strSql.Append("clevel=@clevel,"); strSql.Append("caddress=@caddress,"); strSql.Append("csalesum=@csalesum,"); strSql.Append("cremark=@cremark,"); strSql.Append("cls1=@cls1,"); strSql.Append("cls2=@cls2,"); strSql.Append("cls3=@cls3,"); strSql.Append("cls4=@cls4,"); strSql.Append("cls5=@cls5,"); strSql.Append("cld1=@cld1,"); strSql.Append("cld2=@cld2,"); strSql.Append("cld3=@cld3,"); strSql.Append("cld4=@cld4,"); strSql.Append("cld5=@cld5,"); strSql.Append("cldc1=@cldc1,"); strSql.Append("cldc2=@cldc2,"); strSql.Append("cldc3=@cldc3,"); strSql.Append("cldc4=@cldc4,"); strSql.Append("cldc5=@cldc5"); strSql.Append(" where id=@id"); MySqlParameter[] parameters = { new MySqlParameter("@cname", MySqlDbType.VarChar, 40), new MySqlParameter("@cphone", MySqlDbType.VarChar, 20), new MySqlParameter("@cemail", MySqlDbType.VarChar, 50), new MySqlParameter("@csex", MySqlDbType.Int32, 11), new MySqlParameter("@clevel", MySqlDbType.Int32, 11), new MySqlParameter("@caddress", MySqlDbType.VarChar, 100), new MySqlParameter("@csalesum", MySqlDbType.Decimal, 20), new MySqlParameter("@cremark", MySqlDbType.VarChar, 200), new MySqlParameter("@cls1", MySqlDbType.VarChar, 20), new MySqlParameter("@cls2", MySqlDbType.VarChar, 20), new MySqlParameter("@cls3", MySqlDbType.VarChar, 20), new MySqlParameter("@cls4", MySqlDbType.VarChar, 20), new MySqlParameter("@cls5", MySqlDbType.VarChar, 20), new MySqlParameter("@cld1", MySqlDbType.Int32, 11), new MySqlParameter("@cld2", MySqlDbType.Int32, 11), new MySqlParameter("@cld3", MySqlDbType.Int32, 11), new MySqlParameter("@cld4", MySqlDbType.Int32, 11), new MySqlParameter("@cld5", MySqlDbType.Int32, 11), new MySqlParameter("@cldc1", MySqlDbType.Decimal, 20), new MySqlParameter("@cldc2", MySqlDbType.Decimal, 20), new MySqlParameter("@cldc3", MySqlDbType.Decimal, 20), new MySqlParameter("@cldc4", MySqlDbType.Decimal, 20), new MySqlParameter("@cldc5", MySqlDbType.Decimal, 20), new MySqlParameter("@id", MySqlDbType.Int32, 11), new MySqlParameter("@ccode", MySqlDbType.VarChar, 20) }; parameters[0].Value = model.cname; parameters[1].Value = model.cphone; parameters[2].Value = model.cemail; parameters[3].Value = model.csex; parameters[4].Value = model.clevel; parameters[5].Value = model.caddress; parameters[6].Value = model.csalesum; parameters[7].Value = model.cremark; parameters[8].Value = model.cls1; parameters[9].Value = model.cls2; parameters[10].Value = model.cls3; parameters[11].Value = model.cls4; parameters[12].Value = model.cls5; parameters[13].Value = model.cld1; parameters[14].Value = model.cld2; parameters[15].Value = model.cld3; parameters[16].Value = model.cld4; parameters[17].Value = model.cld5; parameters[18].Value = model.cldc1; parameters[19].Value = model.cldc2; parameters[20].Value = model.cldc3; parameters[21].Value = model.cldc4; parameters[22].Value = model.cldc5; parameters[23].Value = model.id; parameters[24].Value = model.ccode; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtcname.Text.Trim().Length == 0) { strErr += "cname不能为空!\\n"; } if (this.txtcphone.Text.Trim().Length == 0) { strErr += "cphone不能为空!\\n"; } if (this.txtcemail.Text.Trim().Length == 0) { strErr += "cemail不能为空!\\n"; } if (!PageValidate.IsNumber(txtcsex.Text)) { strErr += "csex格式错误!\\n"; } if (!PageValidate.IsNumber(txtclevel.Text)) { strErr += "clevel格式错误!\\n"; } if (this.txtcaddress.Text.Trim().Length == 0) { strErr += "caddress不能为空!\\n"; } if (!PageValidate.IsDecimal(txtcsalesum.Text)) { strErr += "csalesum格式错误!\\n"; } if (this.txtcremark.Text.Trim().Length == 0) { strErr += "cremark不能为空!\\n"; } if (this.txtcls1.Text.Trim().Length == 0) { strErr += "cls1不能为空!\\n"; } if (this.txtcls2.Text.Trim().Length == 0) { strErr += "cls2不能为空!\\n"; } if (this.txtcls3.Text.Trim().Length == 0) { strErr += "cls3不能为空!\\n"; } if (this.txtcls4.Text.Trim().Length == 0) { strErr += "cls4不能为空!\\n"; } if (this.txtcls5.Text.Trim().Length == 0) { strErr += "cls5不能为空!\\n"; } if (!PageValidate.IsNumber(txtcld1.Text)) { strErr += "cld1格式错误!\\n"; } if (!PageValidate.IsNumber(txtcld2.Text)) { strErr += "cld2格式错误!\\n"; } if (!PageValidate.IsNumber(txtcld3.Text)) { strErr += "cld3格式错误!\\n"; } if (!PageValidate.IsNumber(txtcld4.Text)) { strErr += "cld4格式错误!\\n"; } if (!PageValidate.IsNumber(txtcld5.Text)) { strErr += "cld5格式错误!\\n"; } if (!PageValidate.IsDecimal(txtcldc1.Text)) { strErr += "cldc1格式错误!\\n"; } if (!PageValidate.IsDecimal(txtcldc2.Text)) { strErr += "cldc2格式错误!\\n"; } if (!PageValidate.IsDecimal(txtcldc3.Text)) { strErr += "cldc3格式错误!\\n"; } if (!PageValidate.IsDecimal(txtcldc4.Text)) { strErr += "cldc4格式错误!\\n"; } if (!PageValidate.IsDecimal(txtcldc5.Text)) { strErr += "cldc5格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int id = int.Parse(this.lblid.Text); string cname = this.txtcname.Text; string cphone = this.txtcphone.Text; string cemail = this.txtcemail.Text; int csex = int.Parse(this.txtcsex.Text); int clevel = int.Parse(this.txtclevel.Text); string ccode = this.lblccode.Text; string caddress = this.txtcaddress.Text; decimal csalesum = decimal.Parse(this.txtcsalesum.Text); string cremark = this.txtcremark.Text; string cls1 = this.txtcls1.Text; string cls2 = this.txtcls2.Text; string cls3 = this.txtcls3.Text; string cls4 = this.txtcls4.Text; string cls5 = this.txtcls5.Text; int cld1 = int.Parse(this.txtcld1.Text); int cld2 = int.Parse(this.txtcld2.Text); int cld3 = int.Parse(this.txtcld3.Text); int cld4 = int.Parse(this.txtcld4.Text); int cld5 = int.Parse(this.txtcld5.Text); decimal cldc1 = decimal.Parse(this.txtcldc1.Text); decimal cldc2 = decimal.Parse(this.txtcldc2.Text); decimal cldc3 = decimal.Parse(this.txtcldc3.Text); decimal cldc4 = decimal.Parse(this.txtcldc4.Text); decimal cldc5 = decimal.Parse(this.txtcldc5.Text); Jium.Model.clerk model = new Jium.Model.clerk(); model.id = id; model.cname = cname; model.cphone = cphone; model.cemail = cemail; model.csex = csex; model.clevel = clevel; model.ccode = ccode; model.caddress = caddress; model.csalesum = csalesum; model.cremark = cremark; model.cls1 = cls1; model.cls2 = cls2; model.cls3 = cls3; model.cls4 = cls4; model.cls5 = cls5; model.cld1 = cld1; model.cld2 = cld2; model.cld3 = cld3; model.cld4 = cld4; model.cld5 = cld5; model.cldc1 = cldc1; model.cldc2 = cldc2; model.cldc3 = cldc3; model.cldc4 = cldc4; model.cldc5 = cldc5; Jium.BLL.clerk bll = new Jium.BLL.clerk(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }