public LoginPanel() { InitializeComponent(); // Set System Settings SystemSettings._PlatformType = PlatformType.Windows; // Set autoincrement value try { MockBasicUsersRepository mockBasicUsersRepository = new MockBasicUsersRepository(SystemSettings._PlatformType); User._Id_counter = (mockBasicUsersRepository.GetAll().Last()._Id + 1); } catch (MockBasicUsersRepository_Exception mbur_e) { } // Set Pin Code TextBox this.PinCodeTextBox.PasswordChar = '*'; // Set Error Label this.ErrorLabel.Hide(); }
private void AddBasicUserButton_Click(object sender, System.EventArgs e) { // Redirect to add basic user panel AdministratorAddBasicUserPanel administratorAddBasicUserPanel = new AdministratorAddBasicUserPanel(); administratorAddBasicUserPanel.ShowDialog(); // Update grid view information try { // Connect with database MockBasicUsersRepository mockBasicUsersRepository = new MockBasicUsersRepository(SystemSettings._PlatformType); // Get basic users var basicUsersDataGridViewModels = mockBasicUsersRepository.GetAll().Select((singleBasicUser) => { return(new BasicUsersDataGridViewModel { BasicUserId = singleBasicUser._Id, accountState = singleBasicUser._BankAccount.state._Value, pin = singleBasicUser._Pin._Value, name = singleBasicUser._Name._Value, surname = singleBasicUser._Surname._Value }); }).ToList(); this.BasicUsersDataGridView.DataSource = basicUsersDataGridViewModels; } catch (MockBasicUsersRepository_Exception mbur_e) { } }
private void AcceptButton_Click(object sender, EventArgs e) { // Pin Code PinVAL pinCode = null; // Validate Pin Code try { pinCode = new PinVAL(PinCodeTextBox.Text); } catch (PinVAL_Exception p_e) { ErrorLabel.Text = p_e.What(); ErrorLabel.Show(); } if (pinCode != null) { // Login basic user if (pinCode._Value.Length == 4) { try { // Connect with basic users database MockBasicUsersRepository mockBasicUsersRepository = new MockBasicUsersRepository(SystemSettings._PlatformType); // Get information about basic user with respectively pin code // from database BasicUserPanelVM basicUserPanelVM = new BasicUserPanelVM { basicUser = mockBasicUsersRepository.GetAll().FirstOrDefault( (singleBasicUser) => singleBasicUser._Pin._Value == pinCode._Value) }; // Check basic user's find result if (basicUserPanelVM.basicUser != null) { // Redirect to Basic User Panel basicUserPanelVM.loginPanel = this; BasicUserPanel basicUserPanel = new BasicUserPanel(basicUserPanelVM); this.PinCodeTextBox.Clear(); this.ErrorLabel.Hide(); basicUserPanel.Show(); this.Hide(); } else { ErrorLabel.Text = "!!! Użytkownik O Podanym Pinie Nie Istnieje !!!"; ErrorLabel.Show(); } } catch (MockBasicUsersRepository_Exception mbur_e) { ErrorLabel.Text = mbur_e.What(); ErrorLabel.Show(); } } // Login administrator else if (pinCode._Value.Length == 6) { try { // Connect with administrators database MockAdministratorsRepository mockAdministratorsRepository = new MockAdministratorsRepository(SystemSettings._PlatformType); // Get information about administrator with respectively pin code // from database AdministratorPanelVM administratorPanelVM = new AdministratorPanelVM { administrator = mockAdministratorsRepository.GetAll(). FirstOrDefault((singleAdministrator) => singleAdministrator._Pin._Value == pinCode._Value) }; // Check administrator's find result if (administratorPanelVM.administrator != null) { // Redirect to administrator panel administratorPanelVM.loginPanel = this; AdministratorPanel administratorPanel = new AdministratorPanel(administratorPanelVM); this.PinCodeTextBox.Clear(); this.ErrorLabel.Hide(); administratorPanel.Show(); this.Hide(); } else { ErrorLabel.Text = "!!! Użytkownik O Podanym Pinie Nie Istnieje !!!"; ErrorLabel.Show(); } } catch (MockAdministratorsRepository_Exception mar_e) { ErrorLabel.Text = mar_e.What(); ErrorLabel.Show(); } } } }
public AdministratorManageBasicUsersPanel( AdministratorManageBasicUsersPanelVM administratorManageBasicUsersPanelVM) { InitializeComponent(); // Set login panel information this.loginPanel = administratorManageBasicUsersPanelVM.loginPanel; // Set administrator panel information this.administratorPanel = administratorManageBasicUsersPanelVM.administratorPanel; // Set administrator information this.administrator = administratorManageBasicUsersPanelVM.administrator; // Set selected basic users data grid view row try { MockBasicUsersRepository mockBasicUsersRepository = new MockBasicUsersRepository(SystemSettings._PlatformType); this.selectedBasicUsersDataGridViewRow = mockBasicUsersRepository.GetAll().First(); } catch (MockBasicUsersRepository_Exception mbur_e) { } // Set grid view information try { // Connect with database MockBasicUsersRepository mockBasicUsersRepository = new MockBasicUsersRepository(SystemSettings._PlatformType); // Get basic users var basicUsersDataGridViewModels = mockBasicUsersRepository.GetAll().Select((singleBasicUser) => { return(new BasicUsersDataGridViewModel { BasicUserId = singleBasicUser._Id, pin = singleBasicUser._Pin._Value, name = singleBasicUser._Name._Value, surname = singleBasicUser._Surname._Value, accountState = singleBasicUser._BankAccount.state._Value }); }).ToList(); this.BasicUsersDataGridView.DataSource = basicUsersDataGridViewModels; } catch (MockBasicUsersRepository_Exception mbur_e) { } // Set column headers names this.BasicUsersDataGridView.Columns[0].HeaderText = "Id"; this.BasicUsersDataGridView.Columns[0].Visible = false; this.BasicUsersDataGridView.Columns[1].HeaderText = "Pin"; this.BasicUsersDataGridView.Columns[2].HeaderText = "Imię"; this.BasicUsersDataGridView.Columns[3].HeaderText = "Nazwisko"; this.BasicUsersDataGridView.Columns[4].HeaderText = "Stan Konta"; // Show administration information this.AdministratorInformationLabel.Text = ("Zalogowano Jako :" + $"{this.administrator._Name._Value} {this.administrator._Surname._Value}"); // Center basic user data grid view columns headers foreach (DataGridViewColumn basicUsersDataGridViewColumn in this.BasicUsersDataGridView.Columns) { basicUsersDataGridViewColumn.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; } }
public void MockBasicUsersRepository_When_Get_All( string[] basicUsersData, string expected) { string result = "OK"; //arrange var mockBasicUsers = new List <BasicUser>(); var insertBasicUsers = new List <string[]>(); //Convert basic users data foreach (var basicUserData in basicUsersData) { insertBasicUsers.Add(basicUserData.Split(';')); } //Save basic users data using (StreamWriter sw = new StreamWriter( (cashDispenserLibraryTestSettings._SystemSettings == PlatformType.Windows) ? "cashDispenserDatabase\\BasicUsers.txt" : "cashDispenserDatabase/BasicUsers.txt", false)) { foreach (var basicUserData in basicUsersData) { sw.WriteLine(basicUserData); } } //act //Connect with database MockBasicUsersRepository mockBasicUsersRepository = new MockBasicUsersRepository( cashDispenserLibraryTestSettings._SystemSettings); //Get all basic users try { mockBasicUsers = mockBasicUsersRepository.GetAll().ToList(); } catch (MockBasicUsersRepository_Exception mbur_e) { result = mbur_e.What(); } if (result.Equals("OK")) { //Check got basic users for (int i = 0; i < insertBasicUsers.Count; ++i) { if ((!(mockBasicUsers[i]._Id.ToString().Equals(insertBasicUsers[i][0]))) || (!(mockBasicUsers[i]._Pin._Value.Equals(insertBasicUsers[i][1]))) || (!(mockBasicUsers[i]._Name._Value.Equals(insertBasicUsers[i][2]))) || (!(mockBasicUsers[i]._Surname._Value.Equals(insertBasicUsers[i][3]))) || (!(mockBasicUsers[i]._BankAccount.state._Value.ToString( new CultureInfo("en-US")).Equals(insertBasicUsers[i][4]))) || (mockBasicUsers[i]._BankAccount.state._Currency != Currency.PLN)) { result = "!!! Issue with get basic user !!!"; } } } //assert Assert.AreEqual(expected: expected, actual: result); }
private void AddBasicUserButton_Click(object sender, EventArgs e) { // Add new basic user try { // Get new basic user's informations string basicUserName = this.NameValueTextBox.Text; string basicUserSurname = this.SurnameValueTextBox.Text; string basicUserPin = this.PinValueTextBox.Text; // Connect with database MockBasicUsersRepository mockBasicUsersRepository = new MockBasicUsersRepository(SystemSettings._PlatformType); // Check pin in database if (mockBasicUsersRepository.GetAll().Any((singleBasicUser) => singleBasicUser._Pin._Value == basicUserPin) == true) { this.ErrorLabel.Show(); this.ErrorLabel.Text = "Użytkownik O Podanym Pinie Istnieje W Bazie"; throw new Exception(); } decimal basicUserAccountState = ((this.AccountStateValueTextBox.Text.Length > 0) ? decimal.Parse( this.AccountStateValueTextBox.Text.Replace(',', '.'), CultureInfo.InvariantCulture) : 0.0M); BasicUser basicUser = new BasicUser( id: -1, name: new NameVAL(value: basicUserName), pin: new PinVAL(value: basicUserPin), surname: new SurnameVAL(value: basicUserSurname), bankAccount: new BankAccount( state: new MoneyVAL(value: basicUserAccountState, currency: Currency.PLN))); // Add new basic user's record mockBasicUsersRepository.Add(basicUser: basicUser); // Show add new basic user result AdministratorAddBasicUserResultPanel administratorAddBasicUserResultPanel = new AdministratorAddBasicUserResultPanel(); administratorAddBasicUserResultPanel.ShowDialog(); this.Dispose(); } catch (NameVAL_Exception n_e) { this.ErrorLabel.Text = n_e.What(); this.ErrorLabel.Show(); } catch (SurnameVAL_Exception s_e) { this.ErrorLabel.Text = s_e.What(); this.ErrorLabel.Show(); } catch (PinVAL_Exception p_e) { this.ErrorLabel.Text = p_e.What(); this.ErrorLabel.Show(); } catch (BankAccount_Exception b_e) { this.ErrorLabel.Text = b_e.What(); this.ErrorLabel.Show(); } catch (MoneyVAL_Exception m_e) { this.ErrorLabel.Text = m_e.What(); this.ErrorLabel.Show(); } catch (Exception ex) { } }