- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- public partial class AddUserForm : System.Web.UI.Page
- {
- Model.Users nc_Users = new Model.Users();
- BLL.Users bll_Users = new BLL.Users();
- protected void Page_Load(object sender, EventArgs e)
- {
- LoginLogic.MatchLoad("", "AddUserForm");
- if (!IsPostBack)
- {
- DropLoadSet();
- }
- }
- public void DropLoadSet()
- {
- KeyValue_DeptId.DataTextField = "DeptName";
- KeyValue_DeptId.DataValueField = "ID";
- KeyValue_DeptId.DataSource = EnumGet.DepartmentGetEnum();
- KeyValue_DeptId.DataBind();
- ListItem linone = new ListItem();
- linone.Text = "无";
- linone.Value = "0";
- KeyValue_DeptId.Items.Add(linone);
- KeyValue_DeptId.SelectedIndex = KeyValue_DeptId.Items.Count - 1;
- KeyValue_PrivId.DataTextField = "privName";
- KeyValue_PrivId.DataValueField = "ID";
- KeyValue_PrivId.DataSource = new BLL.User_Priv().GetList();//51(aspx)
- KeyValue_PrivId.DataBind();
- }
- public void LoadSet()
- {
- try
- {
- //UserId
- if (KeyValue_UserId.Text == "")
- {
- throw new Exception("用户名不能为空!");
- }
- BLL.Users bu = new BLL.Users();
- if (bu.GetCount("UserId='" + KeyValue_UserId.Text + "'") > 0)
- {
- throw new Exception("用户名有重复!");
- }
- //UserNo
- int UserNo = 0;
- if (!int.TryParse(this.KeyValue_UserNo.Text, out UserNo))
- {
- throw new Exception("用户排序号必须为数字!");
- }
- //Password
- if (KeyValue_Password.Text == "")
- {
- throw new Exception("密码不能为空!");
- }
- if (KeyValue_Password.Text != KeyValue_Password1.Text)
- {
- throw new Exception("确认密码不符!");
- }
- //PrivId
- int PrivId = 0;
- if (!int.TryParse(this.KeyValue_PrivId.SelectedValue, out PrivId))
- {
- throw new Exception("角色不能为空!");
- }
- nc_Users.UserId = this.KeyValue_UserId.Text;
- nc_Users.UserId2 = this.KeyValue_UserId2.Text;
- nc_Users.UserNo = UserNo;
- nc_Users.UserName = this.KeyValue_UserName.Text;
- nc_Users.Password =this.KeyValue_Password.Text;
- nc_Users.PrivId = PrivId;
- nc_Users.PrivId2 = "";
- nc_Users.PostPriv = this.KeyValue_PostPriv.Text;
- nc_Users.PostDept = "";
- nc_Users.DeptId =int.Parse(this.KeyValue_DeptId.SelectedValue);
- nc_Users.DeptId2 = "";
- nc_Users.CanBroadcast = true;
- if(this.KeyValue_Sex.SelectedValue == "0")
- {
- nc_Users.Sex = true;
- }
- else
- {
- nc_Users.Sex = false;
- }
- nc_Users.Birthday = DateTime.Parse(this.DropDownList6.Text + "-" + this.DropDownList7.Text + "-" + this.DropDownList8.Text);
- nc_Users.IsHideBirthday = CheckBox5.Checked;
- nc_Users.TelNoDept = "";
- nc_Users.FaxNoDept = "";
- nc_Users.AddressHome = "";
- nc_Users.ZipHome = "";
- nc_Users.TelHome = "";
- nc_Users.Mobile = TextBox12.Text;
- nc_Users.IsHideMobile = false;
- nc_Users.Bp = "";
- nc_Users.Email = "";
- nc_Users.Oicq = "";
- nc_Users.Icq = "";
- nc_Users.Msn = "";
- nc_Users.Skype = "";
- nc_Users.Photo = "";
- nc_Users.NickName = this.KeyValue_UserId.Text;
- nc_Users.Avatar = 0;
- nc_Users.MenuType = false;
- nc_Users.MenuHide = false;
- nc_Users.SmsOn =false;
- nc_Users.CallSound = 1;
- nc_Users.Theme = 1;
- nc_Users.Note = "";
- nc_Users.MytableLeft = "";
- nc_Users.MytableRight = "";
- nc_Users.EmailCapacity = int.Parse(TextBox4.Text);
- nc_Users.FolderCapacity = int.Parse(TextBox5.Text);
- nc_Users.OnlineTime = 10;
- nc_Users.DutyType = 1;
- nc_Users.AttendCard = "00000";
- nc_Users.State = 1;
- nc_Users.LastPassTime = DateTime.Now;
- nc_Users.LastVisitTime = DateTime.Now;
- nc_Users.LastIp = "127.0.0.1";
- nc_Users.Disabled = this.KeyValue_Disabled.Checked;
- nc_Users.BindIp = TextBox8.Text;
- nc_Users.UsingKey = this.KeyValue_UsingKey.Checked;
- nc_Users.UGuid = "";
- nc_Users.UKey = "";
- nc_Users.UExt = "";
- if (this.KeyValue_NotUser.Checked)
- {
- nc_Users.NotUser = 1;
- }
- else
- {
- nc_Users.NotUser = 0;
- }
- if (this.KeyValue_NotTable.Checked)
- {
- nc_Users.NotTable = 1;
- }
- else
- {
- nc_Users.NotTable = 0;
- }
- nc_Users.DefaultMenu = "";
- nc_Users.TablePhoto = "";
- nc_Users.WebmailNum = int.Parse(TextBox6.Text);
- nc_Users.WebmailCapacity = int.Parse(TextBox7.Text);
- nc_Users.AdUserId = "";
- nc_Users.UsingAd = true;
- nc_Users.EmailSite = KeyValue_OutSieEmailTextBox.Text;// "http://domain.live.com";
- bll_Users.Add(nc_Users);
- MessageBox.Show("新建成功!");
- }
- catch(Exception exp)
- {
- MessageBox.Show(exp.Message);
- }
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- if (MyIsValid)
- {
- LoadSet();
- }
- }
- public bool MyIsValid = true;
- protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
- {
- BLL.Users mbu = new BLL.Users();
- if (mbu.GetCount("UserId='" + args.Value + "'") > 0)
- {
- args.IsValid = false;
- MyIsValid = false;
- return;
- }
- else
- {
- args.IsValid = true;
- MyIsValid = true;
- }
- }
- }