//-------------------------------------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(); } }); }