AddUser.aspx.cs
上传用户:gooyliu
上传日期:2018-09-29
资源大小:5816k
文件大小:3k
源码类别:

.net编程

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. using System.Web.UI.HtmlControls;
  12. using System.Xml.Linq;
  13. using Model;
  14. using BusinessLogicLayer;
  15. namespace Web.SysAdmin
  16. {
  17.     public partial class AddUser : System.Web.UI.Page
  18.     {
  19.         protected void Page_Load(object sender, EventArgs e)
  20.         {
  21.             if (!Page.IsPostBack)
  22.                 BindRB();
  23.             else { };
  24.         }
  25.         private void BindRB()
  26.         {
  27.             for (int i = 1950; i < 2010; i++)
  28.             {
  29.                 ddlYear.Items.Add(i.ToString());
  30.             }
  31.             for (int i = 1; i < 13; i++)
  32.             {
  33.                 ddlMonth.Items.Add(i.ToString());
  34.             }
  35.             for (int i = 1; i < 32; i++)
  36.             {
  37.                 ddlDay.Items.Add(i.ToString());
  38.             }
  39.         }
  40.         protected void imgBtnAdd_Click(object sender, ImageClickEventArgs e)
  41.         {
  42.             UserInfo usInfo = new UserInfo();
  43.             usInfo.UserID = txtUserID.Text.Trim();
  44.             usInfo.UserName = txtUserName.Text.Trim();
  45.             usInfo.UserPassword = txtPassword.Text.Trim();
  46.             usInfo.Gender = Convert.ToBoolean(rblUserSex.SelectedItem.Value);
  47.             usInfo.UserDepartment = txtUserDepart.Text.Trim();
  48.             usInfo.UserAddress = txtUserAddress.Text.Trim();
  49.             usInfo.UserPhone = txtUserTelephone.Text.Trim();
  50.             usInfo.UserBirthdate = Convert.ToDateTime(ddlYear.SelectedItem.Text + "-" + ddlMonth.SelectedItem.Text + "-" + ddlDay.SelectedItem.Text);
  51.             usInfo.RoleID = Convert.ToInt16(ddlUserRole.SelectedItem.Value);
  52.             string InsertStr = "INSERT INTO Users VALUES('" + usInfo.UserID + "','" + usInfo.UserName + "','" + usInfo.UserPassword + "','" + usInfo.Gender + "','" + usInfo.UserDepartment + "','" + usInfo.UserAddress + "','" + usInfo.UserPhone + "','" + usInfo.UserBirthdate + "'," + usInfo.RoleID + ")";
  53.             Users bllUser = new Users();
  54.             if (bllUser.AddUser(InsertStr))
  55.                 lblMessage.Text = "Add user success!!";
  56.             else
  57.                 lblMessage.Text = "Can't add!!";
  58.             clearAll();
  59.         }
  60.         protected void imgBtnReset_Click(object sender, ImageClickEventArgs e)
  61.         {
  62.             clearAll();
  63.         }
  64.         public void clearAll() //清空所有输入框
  65.         {
  66.             this.txtUserID.Text = string.Empty;
  67.             this.txtPassword.Text = string.Empty;
  68.             this.txtConfirmPwd.Text = string.Empty;
  69.             this.txtUserName.Text = string.Empty;
  70.             this.txtUserDepart.Text = string.Empty;
  71.             this.txtUserAddress.Text = string.Empty;
  72.             this.txtUserTelephone.Text = string.Empty;
  73.         }
  74.     }
  75. }