//-------------------------------------SPRAWDZA CZY ISTNIEJE POLACZENIE------------------------------------------- public MySqlConnector tryToConnectAgain(MySqlConnector mysql, string loginString) { while (!mysql.isConnected()) { MessageBoxResult result = MessageBox.Show("Failed connecting to database\nTry again?", "ERROR" , MessageBoxButton.YesNo); mysql = new MySqlConnector(loginString); switch (result) { case MessageBoxResult.No: { System.Environment.Exit(0); break; } case MessageBoxResult.Yes: { continue; } } } return(mysql); }
public MainWindow() { InitializeComponent(); WindowStyle = WindowStyle.None; Hide(); //string loginString = //"SERVER=localhost;DATABASE=db_system_realizacji_zamowien_posilkow_21042020;UID=root;PASSWORD="******"SELECT * from tb_beverages"); n[1] = mysql.sendRequest("SELECT * from tb_desserts"); n[2] = mysql.sendRequest("SELECT * from tb_sandwiches"); n[3] = mysql.sendRequest("SELECT * from tb_sets"); n[4] = mysql.sendRequest("SELECT * from tb_snacks"); categories = mysql.sendRequest("SELECT * from tb_categories"); var WholeDesserts = new List <string>(); var WholeBevereges = new List <string>(); var WholeSandwiches = new List <string>(); var WholeSets = new List <string>(); var WholeSnacks = new List <string>(); var listOfCategories = new List <string>(); var WholeProduct = new List <string>(); // znajduja sie tu wszystkie elementy z bazy danych(cena, nazwa itd) for (int l = 0; l < numOfFoodCategories; ++l) { loopThroughDataT(n[l], WholeProduct); } loopThroughDataT(categories, listOfCategories); loopThroughDataT(n[0], WholeBevereges); loopThroughDataT(n[1], WholeDesserts); loopThroughDataT(n[2], WholeSandwiches); loopThroughDataT(n[3], WholeSets); loopThroughDataT(n[4], WholeSnacks); var wholeNames = new List <string>(); var wholePrices = new List <string>(); var wholeShort = new List <string>(); int iteratorProductID = 0; int iteratorFullName = 1; int iteratorShortNames = 2; int iteratorCategoriesID = 3; int iteratorCallories = 4; int iteratorPrice = 5; int orderCount = 6; var dessertsNames = parseDataFromDataTable(iteratorShortNames, 7, WholeDesserts); var dessertsFullNames = parseDataFromDataTable(iteratorFullName, 7, WholeDesserts); var dessertsCosts = parseDataFromDataTable(iteratorPrice, 7, WholeDesserts); var sandwichesNames = parseDataFromDataTable(iteratorShortNames, 7, WholeSandwiches); var sandwichesFullNames = parseDataFromDataTable(iteratorFullName, 7, WholeSandwiches); var sandwichesCosts = parseDataFromDataTable(iteratorPrice, 7, WholeSandwiches); var setsNames = parseDataFromDataTable(iteratorShortNames, 7, WholeSets); var setsFullNames = parseDataFromDataTable(iteratorFullName, 7, WholeSets); var setsCosts = parseDataFromDataTable(iteratorPrice, 7, WholeSets); var snacksNames = parseDataFromDataTable(iteratorShortNames, 7, WholeSnacks); var snacksFullNames = parseDataFromDataTable(iteratorFullName, 7, WholeSnacks); var snacksCosts = parseDataFromDataTable(iteratorPrice, 7, WholeSnacks); var beveregesNames = parseDataFromDataTable(iteratorShortNames, 7, WholeBevereges); var beveregesFullNames = parseDataFromDataTable(iteratorFullName, 7, WholeBevereges); var beveregesCosts = parseDataFromDataTable(iteratorPrice, 7, WholeBevereges); wholeNames.AddRange(parseDataFromDataTable(iteratorFullName, 7, WholeBevereges)); wholeNames.AddRange(parseDataFromDataTable(iteratorFullName, 7, WholeDesserts)); wholeNames.AddRange(parseDataFromDataTable(iteratorFullName, 7, WholeSandwiches)); wholeNames.AddRange(parseDataFromDataTable(iteratorFullName, 7, WholeSets)); wholeNames.AddRange(parseDataFromDataTable(iteratorFullName, 7, WholeSnacks)); wholePrices.AddRange(parseDataFromDataTable(iteratorPrice, 7, WholeBevereges)); wholePrices.AddRange(parseDataFromDataTable(iteratorPrice, 7, WholeDesserts)); wholePrices.AddRange(parseDataFromDataTable(iteratorPrice, 7, WholeSandwiches)); wholePrices.AddRange(parseDataFromDataTable(iteratorPrice, 7, WholeSets)); wholePrices.AddRange(parseDataFromDataTable(iteratorPrice, 7, WholeSnacks)); wholeShort.AddRange(parseDataFromDataTable(iteratorShortNames, 7, WholeBevereges)); wholeShort.AddRange(parseDataFromDataTable(iteratorShortNames, 7, WholeDesserts)); wholeShort.AddRange(parseDataFromDataTable(iteratorShortNames, 7, WholeSandwiches)); wholeShort.AddRange(parseDataFromDataTable(iteratorShortNames, 7, WholeSets)); wholeShort.AddRange(parseDataFromDataTable(iteratorShortNames, 7, WholeSnacks)); var categoriesDisplay = parseDataFromDataTable(1, 2, listOfCategories); this.Logout.Click += new RoutedEventHandler( (sendItem, args) => { var Login = new Login(mysql); SystemRealizacjiZamowien.Order.user = ""; if (SystemRealizacjiZamowien.Order.productNames.Count > 0) { ResetEverything(); } Login.Show(); Hide(); }); this.Remove.Background = Brushes.Tomato; this.Remove.Click += new RoutedEventHandler( (sendItem, args) => { if (SystemRealizacjiZamowien.Order.productNames.Count > 0) { MessageBoxResult result = MessageBox.Show("Do you really want to reset the order?", "Warning", MessageBoxButton.YesNo); switch (result) { case MessageBoxResult.Yes: ResetEverything(); break; case MessageBoxResult.No: break; } } }); categoryButton[] categoryButto = new categoryButton[categoriesDisplay.Count]; for (int q = 0; q < categoriesDisplay.Count; ++q) { categoryButto[q] = new categoryButton(categoriesDisplay[q]); grid.Children.Add(categoryButto[q]); } categoryButto[0].Background = Brushes.SeaGreen; categoryButto[0].Foreground = Brushes.White; categoryButto[0].Click += new RoutedEventHandler( (sendItem, args) => { onlyInstanceCat = new Categories(CashToPay, setsNames, setsCosts, setsFullNames, false); onlyInstanceCat.Name = "Categories"; Hide(); }); categoryButto[1].Background = Brushes.SeaGreen; categoryButto[1].Foreground = Brushes.White; categoryButto[1].Click += new RoutedEventHandler( (sendItem, args) => { onlyInstanceCat = new Categories(CashToPay, beveregesNames, beveregesCosts, beveregesFullNames, false); onlyInstanceCat.Name = "Categories"; Hide(); }); categoryButto[2].Background = Brushes.SeaGreen; categoryButto[2].Foreground = Brushes.White; categoryButto[2].Click += new RoutedEventHandler( (sendItem, args) => { onlyInstanceCat = new Categories(CashToPay, sandwichesNames, sandwichesCosts, sandwichesFullNames, false); onlyInstanceCat.Name = "Categories"; Hide(); }); categoryButto[3].Background = Brushes.SeaGreen; categoryButto[3].Foreground = Brushes.White; categoryButto[3].Click += new RoutedEventHandler( (sendItem, args) => { onlyInstanceCat = new Categories(CashToPay, snacksNames, snacksCosts, snacksFullNames, false); onlyInstanceCat.Name = "Categories"; Hide(); }); categoryButto[4].Background = Brushes.SeaGreen; categoryButto[4].Foreground = Brushes.White; categoryButto[4].Click += new RoutedEventHandler( (sendItem, args) => { onlyInstanceCat = new Categories(CashToPay, dessertsNames, dessertsCosts, dessertsFullNames, false); onlyInstanceCat.Name = "Categories"; Hide(); }); this.Find.Background = Brushes.Teal; this.Find.Click += new RoutedEventHandler( (sendItem, args) => { if (this.SearchFor.Text != "") { onlyInstanceCat = new Categories(CashToPay, wholeNames, wholePrices, wholeShort, true); onlyInstanceCat.Name = "Categories"; Hide(); } }); }
public Login(MySqlConnector mysql) { this.mysql = mysql; InitializeComponent(); WindowStyle = WindowStyle.None; }
private void btnZaloguj_Click(object sender, RoutedEventArgs e) { try { string ZapytanieSQL = "SELECT login, password FROM tb_workers;"; MySqlDataAdapter AdapterSQL = new MySqlDataAdapter(); AdapterSQL.SelectCommand = new MySqlCommand(ZapytanieSQL, mysql.databaseCon); MySqlCommandBuilder builder = new MySqlCommandBuilder(AdapterSQL); DataTable n1 = new DataTable(); AdapterSQL.Fill(n1); var Users = new List <string>(); // znajduja sie tu wszystkie elementy z bazy danych(cena, nazwa itd) loopThroughDataT(n1, Users); for (int i = 0; i < Users.Count; i += 2) { if (txtUsername.Text == Users[i]) { if (txtPassword.Password == Users[i + 1]) { Order.user = txtUsername.Text.ToString(); MainWindow.employeePosition = ""; DataTable[] PersonalInfo = new DataTable[1]; List <string> loginString = new List <string>(); MySqlConnector mysql = new MySqlConnector(MainWindow.loginString); PersonalInfo[0] = mysql.sendRequest("SELECT firstName FROM tb_workers WHERE login = "******"'" + Order.user + "'"); MainWindow.loopThroughDataT(PersonalInfo[0], loginString); MessageBox.Show("Hello, " + loginString[0] + "!"); //txtUsername.Text Application.Current.MainWindow.Show(); Close(); var mainWin = Application.Current.Windows.Cast <Window>().FirstOrDefault(window => window is MainWindow) as MainWindow; mainWin.User.Content = "Logged as "; mainWin.User.Content += txtUsername.Text; string login = "******" + txtUsername.Text + "'"; string positionIdQuery = "SELECT position_id FROM tb_workers WHERE tb_workers.login = "******";"; AdapterSQL.SelectCommand = new MySqlCommand(positionIdQuery, mysql.databaseCon); DataTable id = new DataTable(); AdapterSQL.Fill(id); MainWindow.employeePosition = id.Rows[0][0].ToString(); if (MainWindow.employeePosition.Equals("3") || MainWindow.employeePosition.Equals("4")) { mainWin.RegisterBtn.Visibility = Visibility.Visible; } else { mainWin.RegisterBtn.Visibility = Visibility.Hidden; } break; } } if (i > Users.Count - 3) { MessageBox.Show("Incorrect login or password. Try again."); } } mysql.databaseCon.Close(); } catch (Exception error) { MessageBox.Show(error.Message); } }
private void register(object sender, RoutedEventArgs e) { string loginString = "SERVER=localhost;DATABASE=db_system_realizacji_zamowien_posilkow_21042020;UID=root;PASSWORD="******"SELECT login FROM tb_workers"); int rows = n1.Rows.Count; var logins = new List <string>(); loopThroughDataT(n1, logins); List <string> temporaryArr = new List <string>(); int iterator = 0; var nazwy = parseDataFromDataTable(iterator = 0, 7, logins); int log_ok = 0; if (imie == "" || nazwisko == "" || miasto == "" || ulica == "" || nr_domu == "" || kod == "" || log == "" || pass == "" || stanowisko < 1) { fill_error.Visibility = Visibility.Visible; if (pass != pass2) { pass_error.Visibility = Visibility.Visible; } else if (pass == pass2) { pass_error.Visibility = Visibility.Hidden; } log_ok = check_login(nazwy); if (log_ok == 1) { login_error.Visibility = Visibility.Hidden; } else { login_error.Visibility = Visibility.Visible; } } else { fill_error.Visibility = Visibility.Hidden; log_ok = check_login(nazwy); if (log_ok == 1) { if (pass == pass2) { bool capital = false; fill_error.Visibility = Visibility.Hidden; pass_error.Visibility = Visibility.Hidden; for (int i = 0; i < pass.Length; i++) { if (char.IsUpper(pass, i) == true) { capital = true; } } if (capital == true && pass.Length > 5 && log_ok == 1) { mysql.sendRequest("INSERT INTO tb_workers (firstName, secondName, street, houseNumber, postCode, cityOFResidence, login, password, position_id) " + "VALUES ('" + imie + "', '" + nazwisko + "','" + ulica + "','" + nr_domu + "','" + kod + "','" + miasto + "','" + log + "','" + pass + "', " + stanowisko + ")"); MessageBox.Show("A new employee has been registered successfuly"); var mainWin = Application.Current.Windows.Cast <Window>().FirstOrDefault(window => window is MainWindow) as MainWindow; mainWin.Show(); Close(); } else { pass_error2.Visibility = Visibility.Visible; } } else { pass_error.Visibility = Visibility.Visible; } } } }