protected void add_Click(object sender, EventArgs e) { T_InfoAdmin model = new T_InfoAdmin(); model = bll.getAdminByID(name.Text.Trim()); //检查账户名是否存在 if (model.InfoAdminPwd == null) { model.InfoAdminAccount = name.Text.Trim(); model.InfoAdminName = reaname.Text.ToString().Trim(); model.InfoAdminPwd = pwd.Text.ToString().Trim(); model.InfoAdminTel = phone.Text.ToString().Trim(); //绑定类别下拉菜单 model.InfoAdminCategory = DropDownList1.SelectedIndex; model.InfoAdminEmail = useremail.Text.ToString().Trim(); model.InfoAdminSector = ""; if (bll.Insert(model) == 1) { Alert.ShowInTop("添加成功~"); PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } } else { Alert.ShowInTop("用户存在,请重新填写"); } }
protected void add_Click(object sender, EventArgs e) { T_InfoAdmin model = new T_InfoAdmin(); model.InfoAdminAccount = name.Text.ToString().Trim(); model.InfoAdminName = reaname.Text.ToString().Trim(); model.InfoAdminPwd = pwd.Text.ToString().Trim(); model.InfoAdminTel = phone.Text.ToString().Trim(); //绑定类别下拉菜单 model.InfoAdminCategory = DropDownList1.SelectedIndex; model.InfoAdminEmail = useremail.Text.ToString().Trim(); model.InfoAdminSector = ""; if (bll.Update(model)) { Alert.ShowInTop("文章内容修改成功,请关闭窗口~"); PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } else { Alert.ShowInTop("文章内容修改失败"); } }
protected void btnLogin_Click(object sender, EventArgs e) { string username = tbxUserName.Text.Trim(); string pwd = tbxPassword.Text.Trim(); infoadminBLL bll = new infoadminBLL(); T_InfoAdmin model = new T_InfoAdmin(); model = bll.GetInfoAdmin(username); if (model.InfoAdminName == null) { Alert.ShowInTop("该用户不存在!", MessageBoxIcon.Error); } else if (model.InfoAdminPwd == pwd) { Session["admin_name"] = model.InfoAdminName; Session["admin_category"] = model.InfoAdminCategory; Alert.ShowInTop("成功登录!"); PageContext.Redirect("default.aspx"); } else { Alert.ShowInTop("用户名或密码错误!", MessageBoxIcon.Error); } }
/// <summary> /// 转化datarow 到文章实体 /// </summary> /// <param name="row"></param> /// <returns></returns> public T_InfoAdmin DataRowToModel(DataRow row) { T_InfoAdmin model = new T_InfoAdmin(); if (row != null) { if (row["C_InfoAdminName"] != null && row["C_InfoAdminName"].ToString() != "") { model.InfoAdminName = row["C_InfoAdminName"].ToString(); } if (row["C_InfoAdminAccount"] != null) { model.InfoAdminAccount = row["C_InfoAdminAccount"].ToString(); } if (row["C_InfoAdminTel"] != null) { model.InfoAdminTel = row["C_InfoAdminTel"].ToString(); } if (row["C_InfoAdminEmail"] != null) { model.InfoAdminEmail = row["C_InfoAdminEmail"].ToString(); } if (row["C_InfoAdminPwd"] != null) { model.InfoAdminPwd = row["C_InfoAdminPwd"].ToString(); } if (row["C_InfoAdminCategory"] != null && row["C_InfoAdminCategory"].ToString() != "") { model.InfoAdminCategory = int.Parse(row["C_InfoAdminCategory"].ToString()); } } return(model); }
public T_InfoAdmin getAdminByID(string id) { string strSql = "select * from T_InfoAdmin where C_InfoAdminAccount = '" + id + "'"; T_InfoAdmin model = new T_InfoAdmin(); DataSet tb = DbHelperSQL.Query(strSql.ToString()); if (tb.Tables[0].Rows.Count > 0) { model = DataRowToModel(tb.Tables[0].Rows[0]); } return(model); }
/// <summary> /// 插入数据 /// </summary> /// <param name="model">传入model类</param> /// <returns></returns> public int InsertInfoAdmin(T_InfoAdmin model) { //C_InfoAdminAccount, C_InfoAdminPwd, C_InfoAdminSector, C_InfoAdminCategory, C_InfoAdminName, C_InfoAdminTel, C_InfoAdminEmail string sql = "insert into T_InfoAdmin(C_InfoAdminAccount,C_InfoAdminPwd, C_InfoAdminSector,C_InfoAdminCategory,C_InfoAdminName,C_InfoAdminTel,C_InfoAdminEmail) values(@account,@pwd,@sector,@category,@name,@tel,@email)"; SqlParameter[] pms = new SqlParameter[] { new SqlParameter("@account", model.InfoAdminAccount), new SqlParameter("@pwd", model.InfoAdminPwd), new SqlParameter("@sector", model.InfoAdminSector), new SqlParameter("@category", model.InfoAdminCategory), new SqlParameter("@name", model.InfoAdminName), new SqlParameter("@tel", model.InfoAdminTel), new SqlParameter("@email", model.InfoAdminEmail), }; return(SqlHelper.ExecuteNonQuery(sql, System.Data.CommandType.Text, pms)); }
/// <summary> /// 获得adminmodel /// </summary> /// <param name="username"></param> /// <returns></returns> public T_InfoAdmin GetInfoAdmin(string username) { T_InfoAdmin InfoAdminmodel = new T_InfoAdmin(); DataTable InfoAdminTab = dal.GetInfoAdmin(username); if (InfoAdminTab.Rows.Count > 0) { InfoAdminmodel.InfoAdminAccount = InfoAdminTab.Rows[0]["C_InfoAdminAccount"].ToString(); InfoAdminmodel.InfoAdminPwd = InfoAdminTab.Rows[0]["C_InfoAdminPwd"].ToString(); InfoAdminmodel.InfoAdminName = InfoAdminTab.Rows[0]["C_InfoAdminName"].ToString(); InfoAdminmodel.InfoAdminTel = InfoAdminTab.Rows[0]["C_InfoAdminTel"].ToString(); InfoAdminmodel.InfoAdminEmail = InfoAdminTab.Rows[0]["C_InfoAdminEmail"].ToString(); InfoAdminmodel.InfoAdminSector = InfoAdminTab.Rows[0]["C_InfoAdminSector"].ToString(); InfoAdminmodel.InfoAdminCategory = (int)InfoAdminTab.Rows[0]["C_InfoAdminCategory"]; } return(InfoAdminmodel); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string id = Request["id"].ToString(); model = bll.getAdminByID(id);//直接绑定 // name.Text = model.InfoAdminAccount; reaname.Text = model.InfoAdminName; pwd.Text = model.InfoAdminPwd; phone.Text = model.InfoAdminTel; //绑定类别下拉菜单 DropDownList1.SelectedIndex = model.InfoAdminCategory; useremail.Text = model.InfoAdminEmail; } }
//修改信息发布者 public bool UpdateInfoAdmin(T_InfoAdmin model) { //C_InfoAdminAccount, C_InfoAdminPwd, C_InfoAdminSector, C_InfoAdminCategory, C_InfoAdminName, C_InfoAdminTel, C_InfoAdminEmail StringBuilder strSql = new StringBuilder(); strSql.Append("update T_InfoAdmin set "); strSql.Append("C_InfoAdminPwd=@pwd,"); strSql.Append("C_InfoAdminName=@name,"); strSql.Append("C_InfoAdminCategory=@cat,"); strSql.Append("C_InfoAdminTel=@tel,"); strSql.Append("C_InfoAdminEmail=@email"); strSql.Append(" where C_InfoAdminAccount=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Char, 8), new SqlParameter("@pwd", SqlDbType.NVarChar, 100), new SqlParameter("@name", SqlDbType.NVarChar, 40), new SqlParameter("@cat", SqlDbType.Int), new SqlParameter("@tel", SqlDbType.Char, 11), new SqlParameter("@email", SqlDbType.NVarChar, 20) }; parameters[0].Value = model.InfoAdminAccount; parameters[1].Value = model.InfoAdminPwd; parameters[2].Value = model.InfoAdminName; parameters[3].Value = model.InfoAdminCategory; parameters[4].Value = model.InfoAdminTel; parameters[5].Value = model.InfoAdminEmail; int flag = SqlHelper.ExecuteNonQuery(strSql.ToString(), CommandType.Text, parameters); if (flag > 0) { return(true); } else { return(false); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(T_InfoAdmin model) { return(dal.UpdateInfoAdmin(model)); }
/// <summary> /// 业务逻辑层添加model方法 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Insert(T_InfoAdmin model) { return(dal.InsertInfoAdmin(model)); }