private void NameTxtBox_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { this.ActiveControl = PasswordTxtBox; PasswordTxtBox.Focus(); } }
private void UpdateInfoBtn_Click(object sender, EventArgs e) { try { if (UserNameComboBox.SelectedValue != null && UserNameComboBox.Text != "") { UserNameComboBox.BackColor = UserBGColor; if (Validators.TxtBoxNotEmpty(PasswordTxtBox.Text)) { PasswordTxtBox.BackColor = PasswordBGColor; Users aUser = new Users(); aUser.User_Name = NameTxtBox.Text; aUser.User_Address = AddressTxtBox.Text; aUser.User_Phone1 = Phone1TxtBox.Text; aUser.User_Phone2 = Phone2TxtBox.Text; aUser.User_Password = PasswordTxtBox.Text; aUser.User_Description = DescriptionTxtBox.Text; aUser.User_ID = int.Parse(UserNameComboBox.SelectedValue.ToString()); UsersMgmt.UpdateUser(aUser); foreach (TextBox aTextBox in this.UserInfoGB.Controls.OfType <TextBox>()) { aTextBox.Text = ""; } MessageBox.Show(MsgTxt.AddedSuccessfully, MsgTxt.AddedSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information); UserNameComboBox.Text = ""; } else { MessageBox.Show(MsgTxt.PleaseAddAllRequiredFields, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); PasswordTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor; PasswordTxtBox.Focus(); } } else { MessageBox.Show(MsgTxt.PleaseAddAllRequiredFields, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); UserNameComboBox.BackColor = SharedVariables.TxtBoxRequiredColor; UserNameComboBox.Focus(); } } catch (Exception ex) { MessageBox.Show(MsgTxt.UnexpectedError + "\n IN [UpdateInfoBtn_Click] \n Exception: \n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } }
private void AddUserBtn_Click(object sender, EventArgs e) { try { if (Validators.TxtBoxNotEmpty(UserNameTxtBox.Text) && Validators.TxtBoxNotEmpty(PasswordTxtBox.Text)) { if (!UsersMgmt.IsUserExist(UserNameTxtBox.Text)) { Users aUser = new Users(); aUser.User_Name = NameTxtBox.Text; aUser.User_Address = AddressTxtBox.Text; aUser.User_Phone1 = Phone1TxtBox.Text; aUser.User_Phone2 = Phone2TxtBox.Text; aUser.User_Password = PasswordTxtBox.Text; aUser.User_Description = DescriptionTxtBox.Text; aUser.User_UserName = UserNameTxtBox.Text; if (UsersMgmt.AddUser(aUser)) { MessageBox.Show(MsgTxt.AddedSuccessfully, MsgTxt.AddedSuccessfully, MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult ret; ret = MessageBox.Show(MsgTxt.AddAnotherItemTxt, MsgTxt.InformationCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); if (ret == DialogResult.Yes) { foreach (TextBox aTextBox in this.UserInfoGB.Controls.OfType <TextBox>()) { aTextBox.Text = ""; } } else { this.Close(); } } else { MessageBox.Show(MsgTxt.UnexpectedError + " \n[DataBase Error]:IN [AddUserBtn_Click]" + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } } else { MessageBox.Show(MsgTxt.UserTxt + " [ " + UserNameTxtBox.Text + " ] " + MsgTxt.AlreadyUsedTxt, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show(MsgTxt.PleaseAddAllRequiredFields, MsgTxt.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); if (!Validators.TxtBoxNotEmpty(PasswordTxtBox.Text)) { PasswordTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor; PasswordTxtBox.Focus(); } else { PasswordTxtBox.BackColor = PasswordBGColor; } if (!Validators.TxtBoxNotEmpty(UserNameTxtBox.Text)) { UserNameTxtBox.BackColor = SharedVariables.TxtBoxRequiredColor; UserNameTxtBox.Focus(); } else { UserNameTxtBox.BackColor = NameBGColor; } } } catch (Exception ex) { MessageBox.Show(MsgTxt.UnexpectedError + " \n[Exception]:IN [AddUserBtn_Click]" + "\n" + ex.ToString() + "\n" + MsgTxt.FormWillCloseNowTxt, MsgTxt.ErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } }