private void modifyAccountButton_Click(object sender, EventArgs e) { IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream("conf.bin", FileMode.Open, FileAccess.Read); DBDataSerialization dbds = (DBDataSerialization)formatter.Deserialize(stream); DBConnection dBConnection = new DBConnection(dbds.dbhost, dbds.dbname, dbds.dblogin, dbds.dbpassword); string firstName = firstNameTextBox.Text; string lastName = lastNameTextBox.Text; string login = loginTextBox.Text; string emailAddress = emailAddressTextBox.Text; string birthday = birthdayTextBox.Text; string employmentMonth = employmentTextBox.Text; PwdEncryption pwde = new PwdEncryption(); string password = pwde.GenerateHash(passwordTextBox.Text); string pwdhash = File.ReadAllText("salt.txt"); File.Delete("salt.txt"); dBConnection.Update(firstName, lastName, birthday, login, employmentMonth, emailAddress, password, pwdhash, id); logWriting logWriting = new logWriting("Użytkownik zmodyfikował konto."); existingAccountsListBox.Items.Clear(); List <string>[] list = dBConnection.CheckLogin(); var index = 0; foreach (var item in list[3]) { existingAccountsListBox.Items.Add(list[3].ElementAt(index).ToString() + " " + list[4].ElementAt(index).ToString()); index++; } }
private void installButton_Click(object sender, EventArgs e) { string adminLogin = adminLoginTextBox.Text; string adminFirstName = adminFirstNameTextBox.Text; string adminLastName = adminLastNameTextBox.Text; string adminEmail = adminEmailTextBox.Text; string databaseHost = databaseHostTextBox.Text; string databasePassword = databasePasswordTextBox.Text; string databaseName = databaseNameTextBox.Text; string databaseLogin = databaseLoginTextBox.Text; var dayOfBirth = adminBirthdayDatePicker.Value.Day.ToString(); var monthOfBirth = adminBirthdayDatePicker.Value.Month.ToString(); var yearOfBirth = adminBirthdayDatePicker.Value.Year.ToString(); var adminBirthday = dayOfBirth + "/" + monthOfBirth + "/" + yearOfBirth; var workgroup = "administrator"; var monthOfEmployment = employmentMonthDatePicker.Value.Month.ToString(); progressBar.Visible = true; progressBar.Value = 0; DBConnection dBConnection = new DBConnection(databaseHost, databaseName, databaseLogin, databasePassword); if (!dBConnection.ConnectionTest()) { databaseHostTextBox.Text = null; databasePasswordTextBox.Text = null; databaseNameTextBox.Text = null; databaseLoginTextBox.Text = null; progressBar.Value = 0; } else if (string.IsNullOrWhiteSpace(adminLoginTextBox.Text)) { MessageBox.Show("Login administratora nie może być pusty!", "Pusty login administratora", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(adminPasswordTextBox.Text)) { MessageBox.Show("Hasło administratora nie może być puste!", "Puste hasło administratora", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(adminFirstNameTextBox.Text)) { MessageBox.Show("Imię administratora nie może być puste!", "Puste imię administratora", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(adminLastNameTextBox.Text)) { MessageBox.Show("Nazwisko administratora nie może być puste!", "Puste nazwisko administratora", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(adminEmailTextBox.Text)) { MessageBox.Show("Adres e-mail administratora nie może być pusty!", "Pusty adres e-mail administratora", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(databaseHostTextBox.Text)) { MessageBox.Show("Host bazy danych nie może być pusty!", "Pusty host bazy danych", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(databasePasswordTextBox.Text)) { MessageBox.Show("Hasło do bazy danych nie może być puste!", "Puste hasło do bazy danych", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(databaseNameTextBox.Text)) { MessageBox.Show("Nazwa bazy danych nie może być pusta!", "Pusta nazwa bazy danych", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(databaseLoginTextBox.Text)) { MessageBox.Show("Login do bazy danych nie może być pusty!", "Pusty login do bazy danych", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(companyNameTextBox.Text)) { MessageBox.Show("Nazwa firmy nie może być pusta!", "Pusta nazwa firmy", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(companyNIPTextBox.Text)) { MessageBox.Show("NIP nie może być pusty!", "Pusty NIP", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(companyREGONTextBox.Text)) { MessageBox.Show("REGON nie może być pusty!", "Pusty REGON", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(companyKRSTextBox.Text)) { MessageBox.Show("KRS nie może być pusty!", "Pusty KRS", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { createTable(); dBConnection.CreateTable(); PwdEncryption pwde = new PwdEncryption(); string adminPassword = pwde.GenerateHash(adminPasswordTextBox.Text); string adminPwdSalt = File.ReadAllText("salt.txt"); File.Delete("salt.txt"); insertDataIntoSQLFiles(adminLogin, adminPassword, adminPwdSalt, adminFirstName, adminLastName, adminEmail, adminBirthday, workgroup, monthOfEmployment); dBConnection.CreateAdmin(); progressBar.Value = 20; var companyName = companyNameTextBox.Text; var companyNIP = long.Parse(companyNIPTextBox.Text); var companyREGON = long.Parse(companyREGONTextBox.Text); var companyKRS = long.Parse(companyKRSTextBox.Text); dBConnection.InsertNewCompany(companyName, companyNIP, companyREGON, companyKRS); progressBar.Value = 75; DBDataSerialization bwr = new DBDataSerialization(); bwr.SerializeIt(databaseHostTextBox.Text, databaseNameTextBox.Text, databaseLoginTextBox.Text, databasePasswordTextBox.Text, path); progressBar.Value = 100; MessageBox.Show("Wszystko w porządku. Można używać programu.", "OK"); loginForm loginForm = new loginForm(); loginForm.Show(); loginForm.Activate(); this.Hide(); } }
private void registerNewAccountButton_Click(object sender, EventArgs e) { IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream("conf.bin", FileMode.Open, FileAccess.Read); DBDataSerialization dbds = (DBDataSerialization)formatter.Deserialize(stream); DBConnection dBConnection = new DBConnection(dbds.dbhost, dbds.dbname, dbds.dblogin, dbds.dbpassword); string checkLogin = loginTextBox.Text; bool isLoginUsed = false; if (dBConnection.ConnectionTest()) { List <string>[] list = dBConnection.CheckLogin(); string workgroup = ""; foreach (var item in list[0]) { if (item == checkLogin) { MessageBox.Show("Login jest już w użyciu! Proszę wprowadzić inny login.", "Błąd dodawania użytkownika."); isLoginUsed = true; } else { if (workgroupListBox.SelectedItems.Count > 0) { switch (workgroupListBox.SelectedItem.ToString()) { case "Finanse i rachunkowość": { workgroup = "finances"; break; } case "Logistyka i magazyny": { workgroup = "logistics"; break; } case "Produkcja": { workgroup = "production"; break; } case "Właściciel": { workgroup = "owner"; break; } case "Zasoby ludzkie": { workgroup = "hr"; break; } default: { workgroup = ""; MessageBox.Show("Zła grupa robocza. Spróbuj jeszcze raz."); break; } } } } } var dayOfBirth = birthdayDateTimePicker.Value.Day.ToString(); var monthOfBirth = birthdayDateTimePicker.Value.Month.ToString(); var yearOfBirth = birthdayDateTimePicker.Value.Year.ToString(); var firstName = firstNameTextBox.Text; var lastName = lastNameTextBox.Text; var birthday = dayOfBirth + "/" + monthOfBirth + "/" + yearOfBirth; var login = loginTextBox.Text; var employmentMonth = employmentMonthDatePicker.Value.Month.ToString(); var emailAddress = emailAddressTextBox.Text; PwdEncryption pwde = new PwdEncryption(); string password = pwde.GenerateHash(passwordTextBox.Text); string pwdhash = File.ReadAllText("salt.txt"); File.Delete("salt.txt"); if (string.IsNullOrWhiteSpace(firstNameTextBox.Text)) { MessageBox.Show("Imię nie może być puste!", "Puste imię", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(lastNameTextBox.Text)) { MessageBox.Show("Nazwisko nie może być puste!", "Puste nazwisko", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(loginTextBox.Text)) { MessageBox.Show("Login nie może być pusty!", "Puste imię administratora", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(passwordTextBox.Text)) { MessageBox.Show("Hasło nie może być puste!", "Puste hasło administratora", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (string.IsNullOrWhiteSpace(emailAddressTextBox.Text)) { MessageBox.Show("Adres e-mail nie może być pusty!", "Pusty adres e-mail", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (!isLoginUsed) { dBConnection.InsertNewAccount(firstName, lastName, birthday, workgroup, login, password, pwdhash, employmentMonth, emailAddress); MessageBox.Show("Konto utworzone poprawnie.", "Tworzenie konta", MessageBoxButtons.OK, MessageBoxIcon.Information); logWriting logWriting = new logWriting("Użytkownik dodał nowe konto - " + login); firstNameTextBox.Text = ""; lastNameTextBox.Text = ""; loginTextBox.Text = ""; passwordTextBox.Text = ""; emailAddressTextBox.Text = ""; workgroupListBox.ClearSelected(); } } }