private void loadCommandsFromDB() { try { List <string> commandsFromDB = _model.Commands; foreach (string commandStr in commandsFromDB) { nrOfCommands++; //creare lista de Produs cu pentru comenzile stocate in baza de date List <Produs> productList = new List <Produs>(); //Sirul de carctere cu datele din baza de date este de forma: //id#lista de produse#Pret comanda-NrMasa string[] productListStr = commandStr.Split('#'); string[] productListStr2 = productListStr[1].Split('-'); string[] infoCommandStr = productListStr[2].Split('-'); foreach (string p in productListStr2) { //se obtine din meniu produsul dupa nume si se adauga in lista de Produse Produs pr = _presenter.getProductByName(p); if (pr != null) { productList.Add(pr); } } //creare comanda si setarea detaliilor acesteia Command command = new Command(productList); command.PretComanda = Convert.ToDouble(infoCommandStr[0]); command.NrMasa = Convert.ToInt32(infoCommandStr[1]); CommandLabel cl = new CommandLabel(_presenter, 0, nrOfCommands, command, panelEmployee); } } catch (SqlException sqlEx) { MessageBox.Show("Eroare la citirea comenzilor din baza de date: \r\n" + sqlEx.Message, "EROARE", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button7_Click(object sender, EventArgs e) { nrOfCommands++; List <Produs> produseComanda = new List <Produs>(); foreach (string com in listBoxComenzi.Items) { Produs p = _presenter.getProductByName(com); produseComanda.Add(p); } Command c = new Command(produseComanda); CommandLabel cl = new CommandLabel(_presenter, 0, nrOfCommands, c, panelEmployee); try { _presenter.addCommand(c); } catch (SqlException sqlEx) { MessageBox.Show("Eroare la adaugarea comenzii in baza de date:\r\n" + sqlEx.Message, "EROARE", MessageBoxButtons.OK, MessageBoxIcon.Error); } listBoxComenzi.Items.Clear(); }