/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebDemo.Model.WebDemo.MeterCurrentState model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update MeterCurrentState set "); strSql.Append("StateValue=@StateValue,"); strSql.Append("StateInfo=@StateInfo,"); strSql.Append("UpdateTime=@UpdateTime"); strSql.Append(" where MeterID=@MeterID and StateCode=@StateCode "); SqlParameter[] parameters = { new SqlParameter("@StateValue", SqlDbType.VarChar, 50), new SqlParameter("@StateInfo", SqlDbType.VarChar, 50), new SqlParameter("@UpdateTime", SqlDbType.DateTime), new SqlParameter("@MeterID", SqlDbType.Int, 4), new SqlParameter("@StateCode", SqlDbType.Int, 4) }; parameters[0].Value = model.StateValue; parameters[1].Value = model.StateInfo; parameters[2].Value = model.UpdateTime; parameters[3].Value = model.MeterID; parameters[4].Value = model.StateCode; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(WebDemo.Model.WebDemo.MeterCurrentState model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into MeterCurrentState("); strSql.Append("MeterID,StateCode,StateValue,StateInfo,UpdateTime)"); strSql.Append(" values ("); strSql.Append("@MeterID,@StateCode,@StateValue,@StateInfo,@UpdateTime)"); SqlParameter[] parameters = { new SqlParameter("@MeterID", SqlDbType.Int, 4), new SqlParameter("@StateCode", SqlDbType.Int, 4), new SqlParameter("@StateValue", SqlDbType.VarChar, 50), new SqlParameter("@StateInfo", SqlDbType.VarChar, 50), new SqlParameter("@UpdateTime", SqlDbType.DateTime) }; parameters[0].Value = model.MeterID; parameters[1].Value = model.StateCode; parameters[2].Value = model.StateValue; parameters[3].Value = model.StateInfo; parameters[4].Value = model.UpdateTime; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.MeterCurrentState DataRowToModel(DataRow row) { WebDemo.Model.WebDemo.MeterCurrentState model = new WebDemo.Model.WebDemo.MeterCurrentState(); if (row != null) { if (row["MeterID"] != null && row["MeterID"].ToString() != "") { model.MeterID = int.Parse(row["MeterID"].ToString()); } if (row["StateCode"] != null && row["StateCode"].ToString() != "") { model.StateCode = int.Parse(row["StateCode"].ToString()); } if (row["StateValue"] != null) { model.StateValue = row["StateValue"].ToString(); } if (row["StateInfo"] != null) { model.StateInfo = row["StateInfo"].ToString(); } if (row["UpdateTime"] != null && row["UpdateTime"].ToString() != "") { model.UpdateTime = DateTime.Parse(row["UpdateTime"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.MeterCurrentState GetModel(int MeterID, int StateCode) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 MeterID,StateCode,StateValue,StateInfo,UpdateTime from MeterCurrentState "); strSql.Append(" where MeterID=@MeterID and StateCode=@StateCode "); SqlParameter[] parameters = { new SqlParameter("@MeterID", SqlDbType.Int, 4), new SqlParameter("@StateCode", SqlDbType.Int, 4) }; parameters[0].Value = MeterID; parameters[1].Value = StateCode; WebDemo.Model.WebDemo.MeterCurrentState model = new WebDemo.Model.WebDemo.MeterCurrentState(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
private void ShowInfo(int MeterID, int StateCode) { WebDemo.BLL.WebDemo.MeterCurrentState bll = new WebDemo.BLL.WebDemo.MeterCurrentState(); WebDemo.Model.WebDemo.MeterCurrentState model = bll.GetModel(MeterID, StateCode); this.lblMeterID.Text = model.MeterID.ToString(); this.lblStateCode.Text = model.StateCode.ToString(); this.lblStateValue.Text = model.StateValue; this.lblStateInfo.Text = model.StateInfo; this.lblUpdateTime.Text = model.UpdateTime.ToString(); }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtMeterID.Text)) { strErr += "MeterID格式错误!\\n"; } if (!PageValidate.IsNumber(txtStateCode.Text)) { strErr += "StateCode格式错误!\\n"; } if (this.txtStateValue.Text.Trim().Length == 0) { strErr += "StateValue不能为空!\\n"; } if (this.txtStateInfo.Text.Trim().Length == 0) { strErr += "StateInfo不能为空!\\n"; } if (!PageValidate.IsDateTime(txtUpdateTime.Text)) { strErr += "UpdateTime格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int MeterID = int.Parse(this.txtMeterID.Text); int StateCode = int.Parse(this.txtStateCode.Text); string StateValue = this.txtStateValue.Text; string StateInfo = this.txtStateInfo.Text; DateTime UpdateTime = DateTime.Parse(this.txtUpdateTime.Text); WebDemo.Model.WebDemo.MeterCurrentState model = new WebDemo.Model.WebDemo.MeterCurrentState(); model.MeterID = MeterID; model.StateCode = StateCode; model.StateValue = StateValue; model.StateInfo = StateInfo; model.UpdateTime = UpdateTime; WebDemo.BLL.WebDemo.MeterCurrentState bll = new WebDemo.BLL.WebDemo.MeterCurrentState(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }