public bool SearchPass(string Login, string password, bool flag) { CryptoHash cr = new CryptoHash(); password = cr.Crypto(Login, password); int result = 0; try { string command = ""; if (flag) { command = "Select COUNT(User_id) FROM Users Where Login = '******' and password = '******';"; } else { command = "Select COUNT(Worker_id) FROM Worker Where Login = '******' and password = '******';"; } MySqlCommand cmd2 = new MySqlCommand { Connection = conn, CommandText = string.Format(command) }; MySqlDataReader reader = cmd2.ExecuteReader(); while (reader.Read()) { result = reader.GetInt32(0); } reader.Close(); } catch (Exception) { } if (result == 1) { return(true); } else { return(false); } }
private void Button1_Click(object sender, EventArgs e) { switch (UserType) { case 0: //////ADMIN { if (ConfirmedAdmin) { if (ConfirmedLogin) { if (ConfirmedPassword) { if (textBox1.Text != " " && textBox2.Text != " " && textBox4.Text != " " && dateTimePicker1.Text != " " && textBox7.Text != " " && textBox5.Text != " " && textBox3.Text != " " && textBox9.Text != " " && textBox9.Text != " " && textBox1.Text != "" && textBox2.Text != "" && textBox4.Text != "" && dateTimePicker1.Text != "" && textBox7.Text != "" && textBox5.Text != "" && textBox3.Text != "" && textBox9.Text != "" && textBox9.Text != "" ) { try { CryptoHash cr = new CryptoHash(); string pass = cr.Crypto(textBox3.Text, textBox6.Text); /////////////////////Password string sql = "insert into Users(User_id, User_name, User_surname," + " User_fname, Birthdate, Phone, Login, Password, Adress, Email) values (null, '" + textBox1.Text + "', '" + textBox2.Text + "', '" + textBox4.Text + "', '" + dateTimePicker1.Text + "', '" + textBox7.Text + "', '" + textBox3.Text + "', '" + pass + "', '" + textBox9.Text + "', '" + textBox10.Text + "')"; MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.ExecuteNonQuery(); MessageBox.Show("Реєстрація була успішною!"); conn.Close(); LogIn lg = new LogIn(); lg.Show(); this.Close(); } catch (Exception) { } } else { MessageBox.Show("Не всі поля заповнені! Будь-ласка, перевірте правильність завонення полів!"); } } else { MessageBox.Show("Помилка паролю!"); } } else { MessageBox.Show("Помилка логіну!"); } } else { MessageBox.Show("Адміністратор не підтвердив паролю!"); } break; } case 1: //////USER { if (ConfirmedLogin) { if (ConfirmedPassword) { if (ConfirmedEmail) { if (textBox1.Text != " " && textBox2.Text != " " && textBox4.Text != " " && dateTimePicker1.Text != " " && textBox7.Text != " " && textBox5.Text != " " && textBox3.Text != " " && textBox9.Text != " " && textBox9.Text != " " && textBox1.Text != "" && textBox2.Text != "" && textBox4.Text != "" && dateTimePicker1.Text != "" && textBox7.Text != "" && textBox5.Text != "" && textBox3.Text != "" && textBox9.Text != "" && textBox9.Text != "" ) { try { CryptoHash cr = new CryptoHash(); string pass = cr.Crypto(textBox3.Text, textBox6.Text); /////////////////////Password string sql = "insert into Users(User_id, User_name, User_surname," + " User_fname, Birthdate, Phone, Login, Password, Adress, Email) values (null, '" + textBox1.Text + "', '" + textBox2.Text + "', '" + textBox4.Text + "', '" + dateTimePicker1.Text + "', '" + textBox7.Text + "', '" + textBox3.Text + "', '" + pass + "', '" + textBox9.Text + "', '" + textBox10.Text + "')"; MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.ExecuteNonQuery(); MessageBox.Show("Реєстрація була успішною!"); conn.Close(); LogIn lg = new LogIn(); lg.Show(); this.Close(); } catch (Exception) { } } else { MessageBox.Show("Не всі поля заповнені! Будь-ласка, перевірте правильність заповнення полів!"); } } else { MessageBox.Show("Помилка E-mail адреси!"); } } else { MessageBox.Show("Помилка паролю!"); } } else { MessageBox.Show("Помилка логіну!"); } break; } case 2: //////WORKER { if (ConfirmedLogin) { if (ConfirmedPassword) { if (textBox1.Text != " " && textBox2.Text != " " && textBox4.Text != " " && dateTimePicker1.Text != " " && textBox7.Text != " " && textBox5.Text != " " && textBox3.Text != " " && textBox11.Text != " " && comboBox3.Text != " " && textBox1.Text != "" && textBox2.Text != "" && textBox4.Text != "" && dateTimePicker1.Text != "" && textBox7.Text != "" && textBox5.Text != "" && textBox3.Text != "" && textBox11.Text != "" && comboBox3.Text != "" ) { try { CryptoHash cr = new CryptoHash(); string pass = cr.Crypto(textBox3.Text, textBox6.Text); /////////////////////Password int index = Office_ids[comboBox3.SelectedIndex]; string sql = "insert into Worker(Worker_id, Worker_name, Worker_surname," + "Worker_fname, Birthdate, Phone, Login, Password, Worker_proffession, Office_id) values (null, '" + textBox1.Text + "', '" + textBox2.Text + "', '" + textBox4.Text + "', '" + dateTimePicker1.Text + "', '" + textBox7.Text + "', '" + textBox3.Text + "', '" + pass + "', '" + textBox11.Text + "', '" + index + "')"; MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.ExecuteNonQuery(); //INSERT INTO Orders VALUES (null, 1, 1, 5, 'AN55SLRT12FF', 2, 'TEST', '2017:01:01', 'NULL', 10, 0); MessageBox.Show("Реєстрація була успішною!"); int worker_id = 0; cmd = new MySqlCommand { Connection = conn, CommandText = string.Format("SELECT MAX(Worker_id) FROM Worker;") }; MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { worker_id = reader.GetInt32(0); } sql = "iINSERT INTO Orders(Order_id, User_id, Service_id, Worker_id, Serial_number" + "Status_id,Description,Order_Date, Complete_set, Appearance, Order_price) VALUES (null, 1, 1, " + worker_id + ", 'AN55SLRT12FF', 2, 'TEST', '2017:01:01', 'NULL', 10, 0);"; cmd = new MySqlCommand(sql, conn); cmd.ExecuteNonQuery(); reader.Close(); conn.Close(); LogIn lg = new LogIn(); lg.Show(); this.Close(); } catch (Exception) { } } else { MessageBox.Show("Не всі поля заповнені! Будь-ласка, перевірте правильність заповнення полів!"); } } else { MessageBox.Show("Помилка пароля!"); } } else { MessageBox.Show("Помилка логіну!"); } break; } default: { MessageBox.Show("Користувач не обраний!"); break; } } }