/// <summary> /// 更新一条数据 /// </summary> public bool Update(YueDuLibrary.Model.Admin model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Admin set "); strSql.Append("adminName=@adminName,"); strSql.Append("adminPass=@adminPass,"); strSql.Append("adminType=@adminType,"); strSql.Append("adminImg=@adminImg"); strSql.Append(" where adminId=@adminId"); SqlParameter[] parameters = { new SqlParameter("@adminName", SqlDbType.VarChar, 25), new SqlParameter("@adminPass", SqlDbType.VarChar, 100), new SqlParameter("@adminType", SqlDbType.Int, 4), new SqlParameter("@adminImg", SqlDbType.VarChar, 60), new SqlParameter("@adminId", SqlDbType.Int, 4) }; parameters[0].Value = model.adminName; parameters[1].Value = model.adminPass; parameters[2].Value = model.adminType; parameters[3].Value = model.adminImg; parameters[4].Value = model.adminId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(YueDuLibrary.Model.Admin model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Admin("); strSql.Append("adminName,adminPass,adminType,adminImg)"); strSql.Append(" values ("); strSql.Append("@adminName,@adminPass,@adminType,@adminImg)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@adminName", SqlDbType.VarChar, 25), new SqlParameter("@adminPass", SqlDbType.VarChar, 100), new SqlParameter("@adminType", SqlDbType.Int, 4), new SqlParameter("@adminImg", SqlDbType.VarChar, 60) }; parameters[0].Value = model.adminName; parameters[1].Value = model.adminPass; parameters[2].Value = model.adminType; parameters[3].Value = model.adminImg; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public YueDuLibrary.Model.Admin DataRowToModel(DataRow row) { YueDuLibrary.Model.Admin model = new YueDuLibrary.Model.Admin(); if (row != null) { if (row["adminId"] != null && row["adminId"].ToString() != "") { model.adminId = int.Parse(row["adminId"].ToString()); } if (row["adminName"] != null) { model.adminName = row["adminName"].ToString(); } if (row["adminPass"] != null) { model.adminPass = row["adminPass"].ToString(); } if (row["adminType"] != null && row["adminType"].ToString() != "") { model.adminType = int.Parse(row["adminType"].ToString()); } if (row["adminImg"] != null) { model.adminImg = row["adminImg"].ToString(); } } return(model); }
private void ShowInfo(int adminId) { YueDuLibrary.BLL.Admin bll = new YueDuLibrary.BLL.Admin(); YueDuLibrary.Model.Admin model = bll.GetModel(adminId); this.txtadminName.Text = model.adminName; this.txtadminPass.Text = ""; this.txtadminType.Text = model.adminType.ToString(); this.txtadminImg.Text = model.adminImg; }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtadminName.Text.Trim().Length == 0) { strErr += "adminName不能为空!\\n"; } if (this.txtadminPass.Text.Trim().Length == 0) { strErr += "adminPass不能为空!\\n"; } if (!PageValidate.IsNumber(txtadminType.Text)) { strErr += "adminType格式错误!\\n"; } if (this.txtadminImg.Text.Trim().Length == 0) { strErr += "adminImg不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string adminName = this.txtadminName.Text; string adminPass = FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtadminPass.Text, "MD5"); int adminType = int.Parse(this.txtadminType.Text); string adminImg = this.txtadminImg.Text; YueDuLibrary.Model.Admin model = new YueDuLibrary.Model.Admin(); model.adminName = adminName; model.adminPass = adminPass; model.adminType = adminType; model.adminImg = adminImg; YueDuLibrary.BLL.Admin bll = new YueDuLibrary.BLL.Admin(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
/// <summary> /// 得到一个对象实体 /// </summary> public YueDuLibrary.Model.Admin GetModel(int adminId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 adminId,adminName,adminPass,adminType,adminImg from Admin "); strSql.Append(" where adminId=@adminId"); SqlParameter[] parameters = { new SqlParameter("@adminId", SqlDbType.Int, 4) }; parameters[0].Value = adminId; YueDuLibrary.Model.Admin model = new YueDuLibrary.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); } }