Пример #1
0
 private void LoginPassWord_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         IntPtr p        = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(LoginPassWord.SecurePassword);
         string password = System.Runtime.InteropServices.Marshal.PtrToStringBSTR(p);
         ///
         string LoginAccount = Account.Text;
         Account.Focus();
         if (string.IsNullOrEmpty(LoginAccount))
         {
             AccountError.Content = "登陆账户不可为空";
             return;
         }
         if (string.IsNullOrEmpty(password))
         {
             PassWordError.Content = "登陆密码不可为空";
             return;
         }
         LoginDAL loginDAL = new LoginDAL(LoginAccount, password);
         object   errorMsg = null;
         if (loginDAL.GetLoginResult(ref errorMsg))
         {
             ServerSetting.BarcodePrinterName  = null;
             ServerSetting.BookmarkPrinterName = null;
             ServerSetting.Account             = LoginAccount;
             ServerSetting.PassWord            = password;
             GetUserDAL.GetUser();
             ServerSetting.userInfo.PassWord = password;
             try
             {
                 Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); //首先打开配置文件
                 cfa.AppSettings.Settings["Account"].Value = LoginAccount;
                 if (Check.IsChecked == true)
                 {
                     cfa.AppSettings.Settings["PassWord"].Value = password;
                     cfa.AppSettings.Settings["IsCheck"].Value  = "True";
                 }
                 else
                 {
                     cfa.AppSettings.Settings["IsCheck"].Value = "False";
                 }
                 cfa.Save(ConfigurationSaveMode.Modified);           //保存配置文件
                 ConfigurationManager.RefreshSection("appSettings"); //刷新配置文件
             }
             catch { }
             MainControl mainControl = new MainControl(mainWindow);
             mainWindow.gridControl.Children.Clear();
             mainWindow.gridControl.Children.Add(mainControl);
             mainControl.Focus();
         }
         else
         {
             try
             {
                 RetrunInfo retrunInfo = errorMsg as RetrunInfo;
                 if (retrunInfo.ResultCode.Equals("301"))
                 {
                     AccountError.Content = retrunInfo.result.ToString();
                 }
                 if (retrunInfo.ResultCode.Equals("201"))
                 {
                     PassWordError.Content = retrunInfo.result.ToString();
                 }
             }
             catch
             {
                 ErrorPage errorPage = new ErrorPage(errorMsg.ToString(), mainWindow);
                 errorPage.ShowDialog();
             }
         }
     }
 }