private void ShowInfo(int StateCode) { WebDemo.BLL.WebDemo.MeterStateDictionary bll = new WebDemo.BLL.WebDemo.MeterStateDictionary(); WebDemo.Model.WebDemo.MeterStateDictionary model = bll.GetModel(StateCode); this.lblStateCode.Text = model.StateCode.ToString(); this.lblStateName.Text = model.StateName; this.lblEnable.Text = model.Enable?"是":"否"; this.lblIsShow.Text = model.IsShow?"是":"否"; this.lblOrderNum.Text = model.OrderNum.ToString(); this.lblReasion.Text = model.Reasion; this.lblOperation.Text = model.Operation; }
private void ShowInfo(int StateCode) { WebDemo.BLL.WebDemo.MeterStateDictionary bll = new WebDemo.BLL.WebDemo.MeterStateDictionary(); WebDemo.Model.WebDemo.MeterStateDictionary model = bll.GetModel(StateCode); this.lblStateCode.Text = model.StateCode.ToString(); this.txtStateName.Text = model.StateName; this.chkEnable.Checked = model.Enable; this.chkIsShow.Checked = model.IsShow; this.txtOrderNum.Text = model.OrderNum.ToString(); this.txtReasion.Text = model.Reasion; this.txtOperation.Text = model.Operation; }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtStateCode.Text)) { strErr += "StateCode格式错误!\\n"; } if (this.txtStateName.Text.Trim().Length == 0) { strErr += "StateName不能为空!\\n"; } if (!PageValidate.IsNumber(txtOrderNum.Text)) { strErr += "OrderNum格式错误!\\n"; } if (this.txtReasion.Text.Trim().Length == 0) { strErr += "Reasion不能为空!\\n"; } if (this.txtOperation.Text.Trim().Length == 0) { strErr += "Operation不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int StateCode = int.Parse(this.txtStateCode.Text); string StateName = this.txtStateName.Text; bool Enable = this.chkEnable.Checked; bool IsShow = this.chkIsShow.Checked; int OrderNum = int.Parse(this.txtOrderNum.Text); string Reasion = this.txtReasion.Text; string Operation = this.txtOperation.Text; WebDemo.Model.WebDemo.MeterStateDictionary model = new WebDemo.Model.WebDemo.MeterStateDictionary(); model.StateCode = StateCode; model.StateName = StateName; model.Enable = Enable; model.IsShow = IsShow; model.OrderNum = OrderNum; model.Reasion = Reasion; model.Operation = Operation; WebDemo.BLL.WebDemo.MeterStateDictionary bll = new WebDemo.BLL.WebDemo.MeterStateDictionary(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.MeterStateDictionary DataRowToModel(DataRow row) { WebDemo.Model.WebDemo.MeterStateDictionary model = new WebDemo.Model.WebDemo.MeterStateDictionary(); if (row != null) { if (row["StateCode"] != null && row["StateCode"].ToString() != "") { model.StateCode = int.Parse(row["StateCode"].ToString()); } if (row["StateName"] != null) { model.StateName = row["StateName"].ToString(); } if (row["Enable"] != null && row["Enable"].ToString() != "") { if ((row["Enable"].ToString() == "1") || (row["Enable"].ToString().ToLower() == "true")) { model.Enable = true; } else { model.Enable = false; } } if (row["IsShow"] != null && row["IsShow"].ToString() != "") { if ((row["IsShow"].ToString() == "1") || (row["IsShow"].ToString().ToLower() == "true")) { model.IsShow = true; } else { model.IsShow = false; } } if (row["OrderNum"] != null && row["OrderNum"].ToString() != "") { model.OrderNum = int.Parse(row["OrderNum"].ToString()); } if (row["Reasion"] != null) { model.Reasion = row["Reasion"].ToString(); } if (row["Operation"] != null) { model.Operation = row["Operation"].ToString(); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebDemo.Model.WebDemo.MeterStateDictionary model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update MeterStateDictionary set "); strSql.Append("StateName=@StateName,"); strSql.Append("Enable=@Enable,"); strSql.Append("IsShow=@IsShow,"); strSql.Append("OrderNum=@OrderNum,"); strSql.Append("Reasion=@Reasion,"); strSql.Append("Operation=@Operation"); strSql.Append(" where StateCode=@StateCode "); SqlParameter[] parameters = { new SqlParameter("@StateName", SqlDbType.VarChar, 50), new SqlParameter("@Enable", SqlDbType.Bit, 1), new SqlParameter("@IsShow", SqlDbType.Bit, 1), new SqlParameter("@OrderNum", SqlDbType.Int, 4), new SqlParameter("@Reasion", SqlDbType.VarChar, 500), new SqlParameter("@Operation", SqlDbType.VarChar, 500), new SqlParameter("@StateCode", SqlDbType.Int, 4) }; parameters[0].Value = model.StateName; parameters[1].Value = model.Enable; parameters[2].Value = model.IsShow; parameters[3].Value = model.OrderNum; parameters[4].Value = model.Reasion; parameters[5].Value = model.Operation; parameters[6].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.MeterStateDictionary model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into MeterStateDictionary("); strSql.Append("StateCode,StateName,Enable,IsShow,OrderNum,Reasion,Operation)"); strSql.Append(" values ("); strSql.Append("@StateCode,@StateName,@Enable,@IsShow,@OrderNum,@Reasion,@Operation)"); SqlParameter[] parameters = { new SqlParameter("@StateCode", SqlDbType.Int, 4), new SqlParameter("@StateName", SqlDbType.VarChar, 50), new SqlParameter("@Enable", SqlDbType.Bit, 1), new SqlParameter("@IsShow", SqlDbType.Bit, 1), new SqlParameter("@OrderNum", SqlDbType.Int, 4), new SqlParameter("@Reasion", SqlDbType.VarChar, 500), new SqlParameter("@Operation", SqlDbType.VarChar, 500) }; parameters[0].Value = model.StateCode; parameters[1].Value = model.StateName; parameters[2].Value = model.Enable; parameters[3].Value = model.IsShow; parameters[4].Value = model.OrderNum; parameters[5].Value = model.Reasion; parameters[6].Value = model.Operation; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.MeterStateDictionary GetModel(int StateCode) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 StateCode,StateName,Enable,IsShow,OrderNum,Reasion,Operation from MeterStateDictionary "); strSql.Append(" where StateCode=@StateCode "); SqlParameter[] parameters = { new SqlParameter("@StateCode", SqlDbType.Int, 4) }; parameters[0].Value = StateCode; WebDemo.Model.WebDemo.MeterStateDictionary model = new WebDemo.Model.WebDemo.MeterStateDictionary(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }