/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebDemo.Model.WebDemo.MeterModal model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update MeterModal set "); strSql.Append("Modalname=@Modalname,"); strSql.Append("Remark=@Remark,"); strSql.Append("UseProtocol=@UseProtocol,"); strSql.Append("FactoryCode=@FactoryCode,"); strSql.Append("FactoryName=@FactoryName,"); strSql.Append("MaxValue=@MaxValue,"); strSql.Append("MaxYear=@MaxYear,"); strSql.Append("Caliber=@Caliber,"); strSql.Append("MaxFlow=@MaxFlow,"); strSql.Append("MeterHeaderType=@MeterHeaderType,"); strSql.Append("MeterStatusCode=@MeterStatusCode"); strSql.Append(" where Modalid=@Modalid "); SqlParameter[] parameters = { new SqlParameter("@Modalname", SqlDbType.VarChar, 50), new SqlParameter("@Remark", SqlDbType.VarChar, 500), new SqlParameter("@UseProtocol", SqlDbType.Int, 4), new SqlParameter("@FactoryCode", SqlDbType.VarChar, 50), new SqlParameter("@FactoryName", SqlDbType.VarChar, 50), new SqlParameter("@MaxValue", SqlDbType.Int, 4), new SqlParameter("@MaxYear", SqlDbType.Int, 4), new SqlParameter("@Caliber", SqlDbType.VarChar, 50), new SqlParameter("@MaxFlow", SqlDbType.Decimal, 9), new SqlParameter("@MeterHeaderType", SqlDbType.Int, 4), new SqlParameter("@MeterStatusCode", SqlDbType.VarChar, 4), new SqlParameter("@Modalid", SqlDbType.Int, 4) }; parameters[0].Value = model.Modalname; parameters[1].Value = model.Remark; parameters[2].Value = model.UseProtocol; parameters[3].Value = model.FactoryCode; parameters[4].Value = model.FactoryName; parameters[5].Value = model.MaxValue; parameters[6].Value = model.MaxYear; parameters[7].Value = model.Caliber; parameters[8].Value = model.MaxFlow; parameters[9].Value = model.MeterHeaderType; parameters[10].Value = model.MeterStatusCode; parameters[11].Value = model.Modalid; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.MeterModal DataRowToModel(DataRow row) { WebDemo.Model.WebDemo.MeterModal model = new WebDemo.Model.WebDemo.MeterModal(); if (row != null) { if (row["Modalid"] != null && row["Modalid"].ToString() != "") { model.Modalid = int.Parse(row["Modalid"].ToString()); } if (row["Modalname"] != null) { model.Modalname = row["Modalname"].ToString(); } if (row["Remark"] != null) { model.Remark = row["Remark"].ToString(); } if (row["UseProtocol"] != null && row["UseProtocol"].ToString() != "") { model.UseProtocol = int.Parse(row["UseProtocol"].ToString()); } if (row["FactoryCode"] != null) { model.FactoryCode = row["FactoryCode"].ToString(); } if (row["FactoryName"] != null) { model.FactoryName = row["FactoryName"].ToString(); } if (row["MaxValue"] != null && row["MaxValue"].ToString() != "") { model.MaxValue = int.Parse(row["MaxValue"].ToString()); } if (row["MaxYear"] != null && row["MaxYear"].ToString() != "") { model.MaxYear = int.Parse(row["MaxYear"].ToString()); } if (row["Caliber"] != null) { model.Caliber = row["Caliber"].ToString(); } if (row["MaxFlow"] != null && row["MaxFlow"].ToString() != "") { model.MaxFlow = decimal.Parse(row["MaxFlow"].ToString()); } if (row["MeterHeaderType"] != null && row["MeterHeaderType"].ToString() != "") { model.MeterHeaderType = int.Parse(row["MeterHeaderType"].ToString()); } if (row["MeterStatusCode"] != null) { model.MeterStatusCode = row["MeterStatusCode"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(WebDemo.Model.WebDemo.MeterModal model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into MeterModal("); strSql.Append("Modalid,Modalname,Remark,UseProtocol,FactoryCode,FactoryName,MaxValue,MaxYear,Caliber,MaxFlow,MeterHeaderType,MeterStatusCode)"); strSql.Append(" values ("); strSql.Append("@Modalid,@Modalname,@Remark,@UseProtocol,@FactoryCode,@FactoryName,@MaxValue,@MaxYear,@Caliber,@MaxFlow,@MeterHeaderType,@MeterStatusCode)"); SqlParameter[] parameters = { new SqlParameter("@Modalid", SqlDbType.Int, 4), new SqlParameter("@Modalname", SqlDbType.VarChar, 50), new SqlParameter("@Remark", SqlDbType.VarChar, 500), new SqlParameter("@UseProtocol", SqlDbType.Int, 4), new SqlParameter("@FactoryCode", SqlDbType.VarChar, 50), new SqlParameter("@FactoryName", SqlDbType.VarChar, 50), new SqlParameter("@MaxValue", SqlDbType.Int, 4), new SqlParameter("@MaxYear", SqlDbType.Int, 4), new SqlParameter("@Caliber", SqlDbType.VarChar, 50), new SqlParameter("@MaxFlow", SqlDbType.Decimal, 9), new SqlParameter("@MeterHeaderType", SqlDbType.Int, 4), new SqlParameter("@MeterStatusCode", SqlDbType.VarChar, 4) }; parameters[0].Value = model.Modalid; parameters[1].Value = model.Modalname; parameters[2].Value = model.Remark; parameters[3].Value = model.UseProtocol; parameters[4].Value = model.FactoryCode; parameters[5].Value = model.FactoryName; parameters[6].Value = model.MaxValue; parameters[7].Value = model.MaxYear; parameters[8].Value = model.Caliber; parameters[9].Value = model.MaxFlow; parameters[10].Value = model.MeterHeaderType; parameters[11].Value = model.MeterStatusCode; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
private void ShowInfo(int Modalid) { WebDemo.BLL.WebDemo.MeterModal bll = new WebDemo.BLL.WebDemo.MeterModal(); WebDemo.Model.WebDemo.MeterModal model = bll.GetModel(Modalid); this.lblModalid.Text = model.Modalid.ToString(); this.lblModalname.Text = model.Modalname; this.lblRemark.Text = model.Remark; this.lblUseProtocol.Text = model.UseProtocol.ToString(); this.lblFactoryCode.Text = model.FactoryCode; this.lblFactoryName.Text = model.FactoryName; this.lblMaxValue.Text = model.MaxValue.ToString(); this.lblMaxYear.Text = model.MaxYear.ToString(); this.lblCaliber.Text = model.Caliber; this.lblMaxFlow.Text = model.MaxFlow.ToString(); this.lblMeterHeaderType.Text = model.MeterHeaderType.ToString(); this.lblMeterStatusCode.Text = model.MeterStatusCode; }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.MeterModal GetModel(int Modalid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Modalid,Modalname,Remark,UseProtocol,FactoryCode,FactoryName,MaxValue,MaxYear,Caliber,MaxFlow,MeterHeaderType,MeterStatusCode from MeterModal "); strSql.Append(" where Modalid=@Modalid "); SqlParameter[] parameters = { new SqlParameter("@Modalid", SqlDbType.Int, 4) }; parameters[0].Value = Modalid; WebDemo.Model.WebDemo.MeterModal model = new WebDemo.Model.WebDemo.MeterModal(); 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.txtModalname.Text.Trim().Length == 0) { strErr += "型号名称不能为空!\\n"; } if (this.txtRemark.Text.Trim().Length == 0) { strErr += "备注不能为空!\\n"; } if (!PageValidate.IsNumber(txtUseProtocol.Text)) { strErr += "UseProtocol格式错误!\\n"; } if (this.txtFactoryCode.Text.Trim().Length == 0) { strErr += "FactoryCode不能为空!\\n"; } if (this.txtFactoryName.Text.Trim().Length == 0) { strErr += "FactoryName不能为空!\\n"; } if (!PageValidate.IsNumber(txtMaxValue.Text)) { strErr += "MaxValue格式错误!\\n"; } if (!PageValidate.IsNumber(txtMaxYear.Text)) { strErr += "MaxYear格式错误!\\n"; } if (this.txtCaliber.Text.Trim().Length == 0) { strErr += "Caliber不能为空!\\n"; } if (!PageValidate.IsDecimal(txtMaxFlow.Text)) { strErr += "MaxFlow格式错误!\\n"; } if (!PageValidate.IsNumber(txtMeterHeaderType.Text)) { strErr += "MeterHeaderType格式错误!\\n"; } if (this.txtMeterStatusCode.Text.Trim().Length == 0) { strErr += "MeterStatusCode不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int Modalid = int.Parse(this.lblModalid.Text); string Modalname = this.txtModalname.Text; string Remark = this.txtRemark.Text; int UseProtocol = int.Parse(this.txtUseProtocol.Text); string FactoryCode = this.txtFactoryCode.Text; string FactoryName = this.txtFactoryName.Text; int MaxValue = int.Parse(this.txtMaxValue.Text); int MaxYear = int.Parse(this.txtMaxYear.Text); string Caliber = this.txtCaliber.Text; decimal MaxFlow = decimal.Parse(this.txtMaxFlow.Text); int MeterHeaderType = int.Parse(this.txtMeterHeaderType.Text); string MeterStatusCode = this.txtMeterStatusCode.Text; WebDemo.Model.WebDemo.MeterModal model = new WebDemo.Model.WebDemo.MeterModal(); model.Modalid = Modalid; model.Modalname = Modalname; model.Remark = Remark; model.UseProtocol = UseProtocol; model.FactoryCode = FactoryCode; model.FactoryName = FactoryName; model.MaxValue = MaxValue; model.MaxYear = MaxYear; model.Caliber = Caliber; model.MaxFlow = MaxFlow; model.MeterHeaderType = MeterHeaderType; model.MeterStatusCode = MeterStatusCode; WebDemo.BLL.WebDemo.MeterModal bll = new WebDemo.BLL.WebDemo.MeterModal(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }