public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtname.Text.Trim().Length == 0) { strErr += "name不能为空!\\n"; } if (this.txtdepartment.Text.Trim().Length == 0) { strErr += "department不能为空!\\n"; } if (this.txtjob.Text.Trim().Length == 0) { strErr += "job不能为空!\\n"; } if (this.txtpermission.Text.Trim().Length == 0) { strErr += "permission不能为空!\\n"; } if (this.txtapplyState.Text.Trim().Length == 0) { strErr += "applyState不能为空!\\n"; } if (this.txtisRead.Text.Trim().Length == 0) { strErr += "isRead不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int ApplyID = int.Parse(this.lblApplyID.Text); string name = this.txtname.Text; string department = this.txtdepartment.Text; string job = this.txtjob.Text; string permission = this.txtpermission.Text; string applyState = this.txtapplyState.Text; string isRead = this.txtisRead.Text; UFB.Model.Apply_Message model = new UFB.Model.Apply_Message(); model.ApplyID = ApplyID; model.name = name; model.department = department; model.job = job; model.permission = permission; model.applyState = applyState; model.isRead = isRead; UFB.BLL.Apply_MessageManager bll = new UFB.BLL.Apply_MessageManager(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
private void ShowInfo(int ApplyID) { UFB.BLL.Apply_MessageManager bll = new UFB.BLL.Apply_MessageManager(); UFB.Model.Apply_Message model = bll.GetModel(ApplyID); this.lblApplyID.Text = model.ApplyID.ToString(); this.txtname.Text = model.name; this.txtdepartment.Text = model.department; this.txtjob.Text = model.job; this.txtpermission.Text = model.permission; this.txtapplyState.Text = model.applyState; this.txtisRead.Text = model.isRead; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(UFB.Model.Apply_Message model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Apply_Message set "); strSql.Append("name=@name,"); strSql.Append("department=@department,"); strSql.Append("job=@job,"); strSql.Append("permission=@permission,"); strSql.Append("applyState=@applyState,"); strSql.Append("isRead=@isRead"); strSql.Append(" where ApplyID=@ApplyID"); SqlParameter[] parameters = { new SqlParameter("@name", SqlDbType.VarChar, 64), new SqlParameter("@department", SqlDbType.VarChar, 64), new SqlParameter("@job", SqlDbType.VarChar, 64), new SqlParameter("@permission", SqlDbType.VarChar, 16), new SqlParameter("@applyState", SqlDbType.VarChar, 16), new SqlParameter("@isRead", SqlDbType.VarChar, 16), new SqlParameter("@ApplyID", SqlDbType.Int, 4) }; parameters[0].Value = model.name; parameters[1].Value = model.department; parameters[2].Value = model.job; parameters[3].Value = model.permission; parameters[4].Value = model.applyState; parameters[5].Value = model.isRead; parameters[6].Value = model.ApplyID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(UFB.Model.Apply_Message model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Apply_Message("); strSql.Append("name,department,job,permission,applyState,isRead)"); strSql.Append(" values ("); strSql.Append("@name,@department,@job,@permission,@applyState,@isRead)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@name", SqlDbType.VarChar, 64), new SqlParameter("@department", SqlDbType.VarChar, 64), new SqlParameter("@job", SqlDbType.VarChar, 64), new SqlParameter("@permission", SqlDbType.VarChar, 16), new SqlParameter("@applyState", SqlDbType.VarChar, 16), new SqlParameter("@isRead", SqlDbType.VarChar, 16) }; parameters[0].Value = model.name; parameters[1].Value = model.department; parameters[2].Value = model.job; parameters[3].Value = model.permission; parameters[4].Value = model.applyState; parameters[5].Value = model.isRead; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(false); } else { return(true); } }
/// <summary> /// 得到一个对象实体 /// </summary> public UFB.Model.Apply_Message DataRowToModel(DataRow row) { UFB.Model.Apply_Message model = new UFB.Model.Apply_Message(); if (row != null) { if (row["ApplyID"] != null && row["ApplyID"].ToString() != "") { model.ApplyID = int.Parse(row["ApplyID"].ToString()); } if (row["name"] != null) { model.name = row["name"].ToString(); } if (row["department"] != null) { model.department = row["department"].ToString(); } if (row["job"] != null) { model.job = row["job"].ToString(); } if (row["permission"] != null) { model.permission = row["permission"].ToString(); } if (row["applyState"] != null) { model.applyState = row["applyState"].ToString(); } if (row["isRead"] != null) { model.isRead = row["isRead"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public UFB.Model.Apply_Message GetModel(int ApplyID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ApplyID,name,department,job,permission,applyState,isRead from Apply_Message "); strSql.Append(" where ApplyID=@ApplyID"); SqlParameter[] parameters = { new SqlParameter("@ApplyID", SqlDbType.Int, 4) }; parameters[0].Value = ApplyID; UFB.Model.Apply_Message model = new UFB.Model.Apply_Message(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }