Пример #1
0
 private void buttonSave_Click(object sender, EventArgs e)
 {
     if (this.appManager.m_bAccountDashboardLoading)
     {
         MessageBox.Show("The Dashboard is currently refreshing accounts, please wait until complete to save account.", this.appManager.m_strApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
     }
     else
     {
         this.textBoxPhoneNumber.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
         if (this.textBoxPhoneNumber.Text.Length != 0)
         {
             try
             {
                 this.buttonSave.Enabled = false;
                 if (this.bNewAccount)
                 {
                     if (!this.appManager.IsDigitsOnly(this.textBoxPhoneNumber.Text))
                     {
                         this.strError = "Phone number must be numeric digits...";
                         this.textBoxPhoneNumber.Select();
                     }
                     if (!this.appManager.IsValidMobileNumber(this.appManager.FormatContactAddress(this.textBoxPhoneNumber.Text, true, false)))
                     {
                         this.strError = "Phone number is not a valid number of digits...";
                         this.textBoxPhoneNumber.Select();
                     }
                     if (this.appManager.GetAccountItem(this.textBoxPhoneNumber.Text).number != null)
                     {
                         this.strError = "Phone number is already saved, please select from the dropdown and update...";
                         this.comboBoxAccountList.Focus();
                     }
                     if (this.textBoxPassword.Text.Length == 0)
                     {
                         this.strError = "Please enter a password...";
                         this.textBoxPassword.Select();
                     }
                     if (this.comboBoxCountry.SelectedValue.ToString() == "")
                     {
                         this.strError = "Please select a country code...";
                         this.comboBoxCountry.Focus();
                     }
                 }
                 if (string.IsNullOrEmpty(this.strError))
                 {
                     bool   flag    = false;
                     bool   flag2   = false;
                     string session = string.Empty;
                     this.appManager.ShowBalloon("Please wait, account information is being verified...", 5);
                     string strPhoneDigits = this.appManager.FormatContactAddress(this.textBoxPhoneNumber.Text, true, false);
                     if (this.appManager.m_textService == null)
                     {
                         this.appManager.m_textService = new TextService();
                     }
                     try
                     {
                         if (AppRegistry.AuthorizeUser(strPhoneDigits, ref this.strError))
                         {
                             flag = this.appManager.m_textService.AccountLogIn(strPhoneDigits, this.textBoxPassword.Text, this.comboBoxCountry.SelectedValue.ToString(), ref session);
                         }
                     }
                     catch
                     {
                         flag2 = true;
                     }
                     if (flag2)
                     {
                         this.strError = "Exception connecting to Text Service\n\nPlease check your internet connection...";
                     }
                     else if (!flag)
                     {
                         this.strError = "Account Failed Authentication.\n\nPlease check your log in information and selected country...";
                     }
                     else
                     {
                         RegistryKey key = AppRegistry.GetSubKey(AppRegistry.GetRootKey(ref this.strError), strPhoneDigits, true, ref this.strError);
                         if (this.strError == string.Empty)
                         {
                             AppRegistry.SaveUserName(key, strPhoneDigits, ref this.strError);
                             AppRegistry.SavePassword(key, this.textBoxPassword.Text, ref this.strError);
                             AppRegistry.SaveValue(key, "CountryCode", this.comboBoxCountry.SelectedValue.ToString(), ref this.strError, false, RegistryValueKind.Unknown);
                             AppRegistry.SaveValue(key, "Title", this.textBoxAccountTitle.Text, ref this.strError, false, RegistryValueKind.Unknown);
                             AppRegistry.SaveValue(key, "Session", session, ref this.strError, false, RegistryValueKind.Unknown);
                         }
                         if (this.strError == string.Empty)
                         {
                             this.appManager.m_lsAccountItems = (from val in this.appManager.m_lsAccountItems
                                                                 where val.number != strPhoneDigits
                                                                 select val).ToList <AccountItem>();
                             AccountItem item = new AccountItem {
                                 countryCode       = this.comboBoxCountry.SelectedValue.ToString(),
                                 number            = strPhoneDigits,
                                 password          = this.textBoxPassword.Text,
                                 title             = this.textBoxAccountTitle.Text,
                                 session           = session,
                                 unReadMessageList = new List <TextMessage>(),
                                 connectionStatus  = "Connected"
                             };
                             this.appManager.m_lsAccountItems.Add(item);
                         }
                     }
                 }
             }
             catch (Exception exception)
             {
                 this.strError = "Error saving account: " + exception.Message;
             }
             if (!string.IsNullOrEmpty(this.strError))
             {
                 MessageBox.Show(this.strError, this.appManager.m_strApplicationName + " Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                 this.strError           = string.Empty;
                 this.buttonSave.Enabled = true;
             }
             else
             {
                 this.appManager.ShowBalloon("Account has been verified and saved.", 5);
                 this.ResetDisplay();
             }
             this.buttonSave.Enabled = true;
         }
     }
 }