public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtCommandName.Text.Trim().Length == 0) { strErr += "指令名称不能为空!\\n"; } if (!PageValidate.IsNumber(txtFlag.Text)) { strErr += "Flag格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int CommandID = int.Parse(this.lblCommandID.Text); string CommandName = this.txtCommandName.Text; int Flag = int.Parse(this.txtFlag.Text); WebDemo.Model.WebDemo.CommandType model = new WebDemo.Model.WebDemo.CommandType(); model.CommandID = CommandID; model.CommandName = CommandName; model.Flag = Flag; WebDemo.BLL.WebDemo.CommandType bll = new WebDemo.BLL.WebDemo.CommandType(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebDemo.Model.WebDemo.CommandType model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update CommandType set "); strSql.Append("CommandName=@CommandName,"); strSql.Append("Flag=@Flag"); strSql.Append(" where CommandID=@CommandID "); SqlParameter[] parameters = { new SqlParameter("@CommandName", SqlDbType.VarChar, 50), new SqlParameter("@Flag", SqlDbType.Int, 4), new SqlParameter("@CommandID", SqlDbType.Int, 4) }; parameters[0].Value = model.CommandName; parameters[1].Value = model.Flag; parameters[2].Value = model.CommandID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(WebDemo.Model.WebDemo.CommandType model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into CommandType("); strSql.Append("CommandID,CommandName,Flag)"); strSql.Append(" values ("); strSql.Append("@CommandID,@CommandName,@Flag)"); SqlParameter[] parameters = { new SqlParameter("@CommandID", SqlDbType.Int, 4), new SqlParameter("@CommandName", SqlDbType.VarChar, 50), new SqlParameter("@Flag", SqlDbType.Int, 4) }; parameters[0].Value = model.CommandID; parameters[1].Value = model.CommandName; parameters[2].Value = model.Flag; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
private void ShowInfo(int CommandID) { WebDemo.BLL.WebDemo.CommandType bll = new WebDemo.BLL.WebDemo.CommandType(); WebDemo.Model.WebDemo.CommandType model = bll.GetModel(CommandID); this.lblCommandID.Text = model.CommandID.ToString(); this.lblCommandName.Text = model.CommandName; this.lblFlag.Text = model.Flag.ToString(); }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.CommandType DataRowToModel(DataRow row) { WebDemo.Model.WebDemo.CommandType model = new WebDemo.Model.WebDemo.CommandType(); if (row != null) { if (row["CommandID"] != null && row["CommandID"].ToString() != "") { model.CommandID = int.Parse(row["CommandID"].ToString()); } if (row["CommandName"] != null) { model.CommandName = row["CommandName"].ToString(); } if (row["Flag"] != null && row["Flag"].ToString() != "") { model.Flag = int.Parse(row["Flag"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.CommandType GetModel(int CommandID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 CommandID,CommandName,Flag from CommandType "); strSql.Append(" where CommandID=@CommandID "); SqlParameter[] parameters = { new SqlParameter("@CommandID", SqlDbType.Int, 4) }; parameters[0].Value = CommandID; WebDemo.Model.WebDemo.CommandType model = new WebDemo.Model.WebDemo.CommandType(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }