Exemple #1
0
 private void Register()
 {
     if (this.valid.IsValid())
     {
         //真实姓名是否为中文
         string realName = this.txtRealName.Text.Trim();
         string code     = this.txtCode.Text.Trim();
         string ip       = WSH.Windows.Common.HardwareInfo.GetNetCardIP();
         string mac      = WSH.Windows.Common.HardwareInfo.GetMacAddress();
         loading.Show(this);
         CodeBuilderService service = ServiceHelper.GetCodeBuilderService();
         //先看本机是否已经注册过账号
         UserInfoEntity userInfo = service.GetUserInfo(new UserInfoEntity()
         {
             IPAddress  = ip,
             MacAddress = mac
         });
         if (userInfo != null && userInfo.ID > 0)
         {
             MsgBox.Alert("您本机已经注册过了,如果忘记,请点击左下角链接找回用户名和密码!");
             this.Close();
             return;
         }
         //没注册重新注册
         string         pwd  = this.txtPassword.Text.Trim();
         UserInfoEntity user = new UserInfoEntity()
         {
             UserName   = this.txtUserName.Text.Trim(),
             RealName   = realName,
             Password   = CryptHelper.EncryptDES(pwd, CryptHelper.DefaultKey),
             CreateTime = DateTime.Now,
             Enabled    = true,
             IsAdmin    = false,
             IPAddress  = ip,
             Email      = this.txtEmail.Text.Trim(),
             MacAddress = mac
         };
         if (service.ExistsUser(user))
         {
             loading.Hide();
             MsgBox.Alert("用户已经存在!"); return;
         }
         user.ID = service.AddUser(user);
         loading.Hide();
         if (user.ID > 0)
         {
             User          = user;
             User.Password = pwd;
             MsgBox.Alert("注册成功");
             this.Close();
         }
         else
         {
             MsgBox.Alert("注册失败");
         }
     }
 }