AddUserForm.aspx.cs
上传用户:simon2hong
上传日期:2021-11-18
资源大小:16746k
文件大小:7k
源码类别:

OA系统

开发平台:

C#

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. public partial class AddUserForm : System.Web.UI.Page
  12. {
  13.     Model.Users nc_Users = new Model.Users();
  14.     BLL.Users bll_Users = new BLL.Users();
  15.     protected void Page_Load(object sender, EventArgs e)
  16.     {
  17.         LoginLogic.MatchLoad("", "AddUserForm");
  18.         if (!IsPostBack)
  19.         {
  20.             DropLoadSet();
  21.         }
  22.     }
  23.     public void DropLoadSet()
  24.     {
  25.         KeyValue_DeptId.DataTextField = "DeptName";
  26.         KeyValue_DeptId.DataValueField = "ID";
  27.         KeyValue_DeptId.DataSource = EnumGet.DepartmentGetEnum();
  28.         KeyValue_DeptId.DataBind();
  29.         ListItem linone = new ListItem();
  30.         linone.Text = "无";
  31.         linone.Value = "0";
  32.         KeyValue_DeptId.Items.Add(linone);
  33.         KeyValue_DeptId.SelectedIndex = KeyValue_DeptId.Items.Count - 1;
  34.         KeyValue_PrivId.DataTextField = "privName";
  35.         KeyValue_PrivId.DataValueField = "ID";
  36.         KeyValue_PrivId.DataSource = new BLL.User_Priv().GetList();//51(aspx)
  37.         KeyValue_PrivId.DataBind();
  38.     }
  39.     public void LoadSet()
  40.     {
  41.         try
  42.         {
  43.             //UserId
  44.             if (KeyValue_UserId.Text == "")
  45.             {
  46.                 throw new Exception("用户名不能为空!");
  47.             }
  48.             BLL.Users bu = new BLL.Users();
  49.             if (bu.GetCount("UserId='" + KeyValue_UserId.Text + "'") > 0)
  50.             {
  51.                 throw new Exception("用户名有重复!");
  52.             }
  53.         
  54.             //UserNo
  55.             int UserNo = 0;
  56.             if (!int.TryParse(this.KeyValue_UserNo.Text, out UserNo))
  57.             {
  58.                 throw new Exception("用户排序号必须为数字!");
  59.             }
  60.             //Password
  61.             if (KeyValue_Password.Text == "")
  62.             {
  63.                 throw new Exception("密码不能为空!");
  64.             }
  65.             if (KeyValue_Password.Text != KeyValue_Password1.Text)
  66.             {
  67.                 throw new Exception("确认密码不符!");
  68.             }
  69.             //PrivId
  70.             int PrivId = 0;
  71.             if (!int.TryParse(this.KeyValue_PrivId.SelectedValue, out PrivId))
  72.             {
  73.                 throw new Exception("角色不能为空!");
  74.             }
  75.            
  76.             nc_Users.UserId = this.KeyValue_UserId.Text;
  77.             nc_Users.UserId2 = this.KeyValue_UserId2.Text;
  78.             nc_Users.UserNo = UserNo;
  79.             nc_Users.UserName = this.KeyValue_UserName.Text;
  80.             nc_Users.Password =this.KeyValue_Password.Text;
  81.             nc_Users.PrivId = PrivId;
  82.             nc_Users.PrivId2 = "";
  83.             nc_Users.PostPriv = this.KeyValue_PostPriv.Text;
  84.             nc_Users.PostDept = "";
  85.             nc_Users.DeptId =int.Parse(this.KeyValue_DeptId.SelectedValue);
  86.             nc_Users.DeptId2 = "";
  87.             nc_Users.CanBroadcast = true;
  88.             if(this.KeyValue_Sex.SelectedValue == "0")
  89.             {
  90.             nc_Users.Sex = true;
  91.             }
  92.                 else
  93.                 {
  94.                     nc_Users.Sex = false;
  95.                 }
  96.             nc_Users.Birthday = DateTime.Parse(this.DropDownList6.Text + "-" + this.DropDownList7.Text + "-" + this.DropDownList8.Text);
  97.             nc_Users.IsHideBirthday = CheckBox5.Checked;
  98.             nc_Users.TelNoDept = "";
  99.             nc_Users.FaxNoDept = "";
  100.             nc_Users.AddressHome = "";
  101.             nc_Users.ZipHome = "";
  102.             nc_Users.TelHome = "";
  103.             nc_Users.Mobile = TextBox12.Text;
  104.             nc_Users.IsHideMobile = false;
  105.             nc_Users.Bp = "";
  106.             nc_Users.Email = "";
  107.             nc_Users.Oicq = "";
  108.             nc_Users.Icq = "";
  109.             nc_Users.Msn = "";
  110.             nc_Users.Skype = "";
  111.             nc_Users.Photo = "";
  112.             nc_Users.NickName = this.KeyValue_UserId.Text;
  113.             nc_Users.Avatar = 0;
  114.             nc_Users.MenuType = false;
  115.             nc_Users.MenuHide = false;
  116.             nc_Users.SmsOn =false;
  117.             nc_Users.CallSound = 1;
  118.             nc_Users.Theme = 1;
  119.             nc_Users.Note = "";
  120.             nc_Users.MytableLeft = "";
  121.             nc_Users.MytableRight = "";
  122.             nc_Users.EmailCapacity = int.Parse(TextBox4.Text);
  123.             nc_Users.FolderCapacity = int.Parse(TextBox5.Text);
  124.             nc_Users.OnlineTime = 10;
  125.             nc_Users.DutyType = 1;
  126.             nc_Users.AttendCard = "00000";
  127.             nc_Users.State = 1;
  128.             nc_Users.LastPassTime = DateTime.Now;
  129.             nc_Users.LastVisitTime = DateTime.Now;
  130.             nc_Users.LastIp = "127.0.0.1";
  131.             nc_Users.Disabled = this.KeyValue_Disabled.Checked;
  132.             nc_Users.BindIp = TextBox8.Text;
  133.             nc_Users.UsingKey = this.KeyValue_UsingKey.Checked;
  134.             nc_Users.UGuid = "";
  135.             nc_Users.UKey = "";
  136.             nc_Users.UExt = "";
  137.             if (this.KeyValue_NotUser.Checked)
  138.             {
  139.                 nc_Users.NotUser = 1;
  140.             }
  141.             else
  142.             {
  143.                 nc_Users.NotUser = 0;
  144.             }
  145.             if (this.KeyValue_NotTable.Checked)
  146.             {
  147.                 nc_Users.NotTable = 1;
  148.             }
  149.             else
  150.             {
  151.                 nc_Users.NotTable = 0;
  152.             }     
  153.             nc_Users.DefaultMenu = "";
  154.             nc_Users.TablePhoto = "";
  155.             nc_Users.WebmailNum = int.Parse(TextBox6.Text);
  156.             nc_Users.WebmailCapacity = int.Parse(TextBox7.Text);
  157.             nc_Users.AdUserId = "";
  158.             nc_Users.UsingAd = true;
  159.             nc_Users.EmailSite = KeyValue_OutSieEmailTextBox.Text;// "http://domain.live.com";
  160.             bll_Users.Add(nc_Users);
  161.             MessageBox.Show("新建成功!");
  162.         }
  163.         catch(Exception exp)
  164.         {
  165.          
  166.             MessageBox.Show(exp.Message);
  167.         }
  168.     }
  169.     protected void Button1_Click(object sender, EventArgs e)
  170.     {
  171.         if (MyIsValid)
  172.         {
  173.             LoadSet();
  174.         }
  175.     }
  176.     public bool MyIsValid = true;
  177.     protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
  178.     {
  179.       
  180.         BLL.Users mbu = new BLL.Users();
  181.         if (mbu.GetCount("UserId='" + args.Value + "'") > 0)
  182.         {
  183.             
  184.             args.IsValid = false;
  185.             MyIsValid = false;
  186.             return;
  187.         }
  188.         else
  189.         {
  190.             args.IsValid = true;
  191.             MyIsValid = true;
  192.         }
  193.         
  194.     }
  195. }