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