private void ShowInfo(int id) { Maticsoft.BLL.demand bll = new Maticsoft.BLL.demand(); Maticsoft.Model.demand model = bll.GetModel(id); this.lblid.Text = model.id.ToString(); this.txtPN.Text = model.PN; this.txtmeasureb.Text = model.measureb; this.txttestboard.Text = model.testboard; this.txttime.Text = model.time.ToString(); this.txtstep1.Text = model.step1; this.txtstep2.Text = model.step2; this.txtstep3.Text = model.step3; this.txtresult.Text = model.result; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.demand model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update demand set "); strSql.Append("PN=@PN,"); strSql.Append("measureb=@measureb,"); strSql.Append("testboard=@testboard,"); strSql.Append("time=@time,"); strSql.Append("step1=@step1,"); strSql.Append("step2=@step2,"); strSql.Append("step3=@step3,"); strSql.Append("result=@result"); strSql.Append(" where id=@id"); MySqlParameter[] parameters = { new MySqlParameter("@PN", MySqlDbType.VarChar, 64), new MySqlParameter("@measureb", MySqlDbType.VarChar, 64), new MySqlParameter("@testboard", MySqlDbType.VarChar, 64), new MySqlParameter("@time", MySqlDbType.DateTime), new MySqlParameter("@step1", MySqlDbType.VarChar, 64), new MySqlParameter("@step2", MySqlDbType.VarChar, 64), new MySqlParameter("@step3", MySqlDbType.VarChar, 64), new MySqlParameter("@result", MySqlDbType.VarChar, 64), new MySqlParameter("@id", MySqlDbType.Int32, 64) }; parameters[0].Value = model.PN; parameters[1].Value = model.measureb; parameters[2].Value = model.testboard; parameters[3].Value = model.time; parameters[4].Value = model.step1; parameters[5].Value = model.step2; parameters[6].Value = model.step3; parameters[7].Value = model.result; parameters[8].Value = model.id; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.demand DataRowToModel(DataRow row) { Maticsoft.Model.demand model = new Maticsoft.Model.demand(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["PN"] != null) { model.PN = row["PN"].ToString(); } if (row["measureb"] != null) { model.measureb = row["measureb"].ToString(); } if (row["testboard"] != null) { model.testboard = row["testboard"].ToString(); } if (row["time"] != null && row["time"].ToString() != "") { model.time = DateTime.Parse(row["time"].ToString()); } if (row["step1"] != null) { model.step1 = row["step1"].ToString(); } if (row["step2"] != null) { model.step2 = row["step2"].ToString(); } if (row["step3"] != null) { model.step3 = row["step3"].ToString(); } if (row["result"] != null) { model.result = row["result"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Maticsoft.Model.demand model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into demand("); strSql.Append("PN,measureb,testboard,time,step1,step2,step3,result)"); strSql.Append(" values ("); strSql.Append("@PN,@measureb,@testboard,@time,@step1,@step2,@step3,@result)"); MySqlParameter[] parameters = { new MySqlParameter("@PN", MySqlDbType.VarChar, 64), new MySqlParameter("@measureb", MySqlDbType.VarChar, 64), new MySqlParameter("@testboard", MySqlDbType.VarChar, 64), new MySqlParameter("@time", MySqlDbType.DateTime), new MySqlParameter("@step1", MySqlDbType.VarChar, 64), new MySqlParameter("@step2", MySqlDbType.VarChar, 64), new MySqlParameter("@step3", MySqlDbType.VarChar, 64), new MySqlParameter("@result", MySqlDbType.VarChar, 64) }; parameters[0].Value = model.PN; parameters[1].Value = model.measureb; parameters[2].Value = model.testboard; parameters[3].Value = model.time; parameters[4].Value = model.step1; parameters[5].Value = model.step2; parameters[6].Value = model.step3; parameters[7].Value = model.result; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.demand GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id,PN,measureb,testboard,time,step1,step2,step3,result from demand "); strSql.Append(" where id=@id"); MySqlParameter[] parameters = { new MySqlParameter("@id", MySqlDbType.Int32) }; parameters[0].Value = id; Maticsoft.Model.demand model = new Maticsoft.Model.demand(); DataSet ds = DbHelperMySQL.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.txtPN.Text.Trim().Length == 0) { strErr += "PN不能为空!\\n"; } if (this.txtmeasureb.Text.Trim().Length == 0) { strErr += "measureb不能为空!\\n"; } if (this.txttestboard.Text.Trim().Length == 0) { strErr += "testboard不能为空!\\n"; } if (!PageValidate.IsDateTime(txttime.Text)) { strErr += "time格式错误!\\n"; } if (this.txtstep1.Text.Trim().Length == 0) { strErr += "step1不能为空!\\n"; } if (this.txtstep2.Text.Trim().Length == 0) { strErr += "step2不能为空!\\n"; } if (this.txtstep3.Text.Trim().Length == 0) { strErr += "step3不能为空!\\n"; } if (this.txtresult.Text.Trim().Length == 0) { strErr += "result不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int id = int.Parse(this.lblid.Text); string PN = this.txtPN.Text; string measureb = this.txtmeasureb.Text; string testboard = this.txttestboard.Text; DateTime time = DateTime.Parse(this.txttime.Text); string step1 = this.txtstep1.Text; string step2 = this.txtstep2.Text; string step3 = this.txtstep3.Text; string result = this.txtresult.Text; Maticsoft.Model.demand model = new Maticsoft.Model.demand(); model.id = id; model.PN = PN; model.measureb = measureb; model.testboard = testboard; model.time = time; model.step1 = step1; model.step2 = step2; model.step3 = step3; model.result = result; Maticsoft.BLL.demand bll = new Maticsoft.BLL.demand(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }