/// <summary> /// 修改职务(确定按钮) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ImageButton2_Click(object sender, EventArgs e) { try { if (TextBox4.Text.Trim() != "") { Maticsoft.Model.Position zhiwu = zw.GetModel(Convert.ToInt32(Label1.Text)); zhiwu.name = TextBox4.Text.Trim(); zhiwu.beizhu = TextBox5.Text.Trim(); bool a = zw.Update(zhiwu); if (a == true) { ClientScript.RegisterClientScriptBlock(this.GetType(), "this", "<script language=javascript>alert('修改成功!');</script>"); bind(sql); } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "this", "<script language=javascript>alert('修改失败!');</script>"); ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>javascript:showDiv2();</script>"); } } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "this", "<script language=javascript>alert('职务名称不能为空!');</script>"); ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>javascript:showDiv2();</script>"); } } catch (Exception ee) { ClientScript.RegisterClientScriptBlock(this.GetType(), "this", "<script language=javascript>alert('确定异常 " + ee.Message + "');</script>"); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.Position model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Position set "); strSql.Append("name=@name,"); strSql.Append("beizhu=@beizhu,"); strSql.Append("By1=@By1,"); strSql.Append("By2=@By2,"); strSql.Append("By3=@By3,"); strSql.Append("By4=@By4,"); strSql.Append("By5=@By5,"); strSql.Append("By6=@By6,"); strSql.Append("By7=@By7"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@name", SqlDbType.VarChar, 200), new SqlParameter("@beizhu", SqlDbType.VarChar, 4000), new SqlParameter("@By1", SqlDbType.Decimal, 9), new SqlParameter("@By2", SqlDbType.Decimal, 9), new SqlParameter("@By3", SqlDbType.Decimal, 9), new SqlParameter("@By4", SqlDbType.VarChar, 4000), new SqlParameter("@By5", SqlDbType.VarChar, 4000), new SqlParameter("@By6", SqlDbType.VarChar, 4000), new SqlParameter("@By7", SqlDbType.VarChar, 4000), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.name; parameters[1].Value = model.beizhu; parameters[2].Value = model.By1; parameters[3].Value = model.By2; parameters[4].Value = model.By3; parameters[5].Value = model.By4; parameters[6].Value = model.By5; parameters[7].Value = model.By6; parameters[8].Value = model.By7; parameters[9].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
private void ShowInfo(int id) { Maticsoft.BLL.Position bll = new Maticsoft.BLL.Position(); Maticsoft.Model.Position model = bll.GetModel(id); this.lblid.Text = model.id.ToString(); this.txtname.Text = model.name; this.txtbeizhu.Text = model.beizhu; this.txtBy1.Text = model.By1.ToString(); this.txtBy2.Text = model.By2.ToString(); this.txtBy3.Text = model.By3.ToString(); this.txtBy4.Text = model.By4; this.txtBy5.Text = model.By5; this.txtBy6.Text = model.By6; this.txtBy7.Text = model.By7; }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.Position DataRowToModel(DataRow row) { Maticsoft.Model.Position model = new Maticsoft.Model.Position(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["name"] != null) { model.name = row["name"].ToString(); } if (row["beizhu"] != null) { model.beizhu = row["beizhu"].ToString(); } if (row["By1"] != null && row["By1"].ToString() != "") { model.By1 = decimal.Parse(row["By1"].ToString()); } if (row["By2"] != null && row["By2"].ToString() != "") { model.By2 = decimal.Parse(row["By2"].ToString()); } if (row["By3"] != null && row["By3"].ToString() != "") { model.By3 = decimal.Parse(row["By3"].ToString()); } if (row["By4"] != null) { model.By4 = row["By4"].ToString(); } if (row["By5"] != null) { model.By5 = row["By5"].ToString(); } if (row["By6"] != null) { model.By6 = row["By6"].ToString(); } if (row["By7"] != null) { model.By7 = row["By7"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Maticsoft.Model.Position model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Position("); strSql.Append("name,beizhu,By1,By2,By3,By4,By5,By6,By7)"); strSql.Append(" values ("); strSql.Append("@name,@beizhu,@By1,@By2,@By3,@By4,@By5,@By6,@By7)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@name", SqlDbType.VarChar, 200), new SqlParameter("@beizhu", SqlDbType.VarChar, 4000), new SqlParameter("@By1", SqlDbType.Decimal, 9), new SqlParameter("@By2", SqlDbType.Decimal, 9), new SqlParameter("@By3", SqlDbType.Decimal, 9), new SqlParameter("@By4", SqlDbType.VarChar, 4000), new SqlParameter("@By5", SqlDbType.VarChar, 4000), new SqlParameter("@By6", SqlDbType.VarChar, 4000), new SqlParameter("@By7", SqlDbType.VarChar, 4000) }; parameters[0].Value = model.name; parameters[1].Value = model.beizhu; parameters[2].Value = model.By1; parameters[3].Value = model.By2; parameters[4].Value = model.By3; parameters[5].Value = model.By4; parameters[6].Value = model.By5; parameters[7].Value = model.By6; parameters[8].Value = model.By7; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.Position GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,name,beizhu,By1,By2,By3,By4,By5,By6,By7 from Position "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Maticsoft.Model.Position model = new Maticsoft.Model.Position(); 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.txtname.Text.Trim().Length == 0) { strErr += "name不能为空!\\n"; } if (this.txtbeizhu.Text.Trim().Length == 0) { strErr += "beizhu不能为空!\\n"; } if (!PageValidate.IsDecimal(txtBy1.Text)) { strErr += "By1格式错误!\\n"; } if (!PageValidate.IsDecimal(txtBy2.Text)) { strErr += "By2格式错误!\\n"; } if (!PageValidate.IsDecimal(txtBy3.Text)) { strErr += "By3格式错误!\\n"; } if (this.txtBy4.Text.Trim().Length == 0) { strErr += "By4不能为空!\\n"; } if (this.txtBy5.Text.Trim().Length == 0) { strErr += "By5不能为空!\\n"; } if (this.txtBy6.Text.Trim().Length == 0) { strErr += "By6不能为空!\\n"; } if (this.txtBy7.Text.Trim().Length == 0) { strErr += "By7不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int id = int.Parse(this.lblid.Text); string name = this.txtname.Text; string beizhu = this.txtbeizhu.Text; decimal By1 = decimal.Parse(this.txtBy1.Text); decimal By2 = decimal.Parse(this.txtBy2.Text); decimal By3 = decimal.Parse(this.txtBy3.Text); string By4 = this.txtBy4.Text; string By5 = this.txtBy5.Text; string By6 = this.txtBy6.Text; string By7 = this.txtBy7.Text; Maticsoft.Model.Position model = new Maticsoft.Model.Position(); model.id = id; model.name = name; model.beizhu = beizhu; model.By1 = By1; model.By2 = By2; model.By3 = By3; model.By4 = By4; model.By5 = By5; model.By6 = By6; model.By7 = By7; Maticsoft.BLL.Position bll = new Maticsoft.BLL.Position(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }