private void Button4_Click(object sender, EventArgs e) { if (listBox1.SelectedIndex != -1) { if (MessageBox.Show("Really want to delete the nutrient?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { Tapanyag t = (Tapanyag)listBox1.SelectedItem; //élelmiszerek dictinoray-ből is törölni kell a tápanyagot foreach (Elelmiszer item in ABKezelo.Kiolvasas().Where(x => x is Elelmiszer)) { item.TapanyagTartalom.Remove(t); ABKezelo.Modositas(item); } string nev = t.Megnevezes; ABKezelo.Torol(t); Logolas.Ment("Nutrient deleted, name: " + nev); ListBoxRefresh(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("To delete a nutrient choose one!", "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void Button6_Click(object sender, EventArgs e) { try { if (listBox1.SelectedIndex != -1 || listBox2.SelectedIndex != -1) { Elelmiszer el; if (listBox1.SelectedIndex != -1) { el = (Elelmiszer)listBox1.SelectedItem; } else { el = (Elelmiszer)listBox2.SelectedItem; } bool torolheto = true; foreach (Menu item in ABKezelo.Kiolvasas().Where(x => x is Menu)) { if (item.Osszetevo.ContainsKey(el)) { torolheto = false; break; } } if (!torolheto) { throw new WarningException("The food has been used by a menu, so it is not deletable! [delete all menu that is using it or only the food from the menu]"); } if (MessageBox.Show("Really want to delete the food?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string nev = el.Megnevezes; ABKezelo.Torol(el); Logolas.Ment("Deleted food, name: " + nev); listBoxRefresh(); } } else { throw new WarningException("For deletion choose a food!"); } } catch (Exception ex) { if (ex is WarningException) { MessageBox.Show(ex.Message, "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void Button1_Click(object sender, EventArgs e) { try { string fnev = ABKezelo.GetCurrentUser(); int i, j, k; int p = 0, q = 0; for (i = 0; i < 2; i++) { for (j = 0; j < 4; j++) { for (k = 0; k < 2; k++) { EtkezesFeltetel etk = new EtkezesFeltetel(fnev, (ElelmiszerTipus2)i, (EtkezesTipus2)j, (Szamlalo)k, (double)numericUpDowns[p].Value, checkBoxs[q].Checked, (double)numericUpDowns[p + 1].Value); p += 2; q++; ABKezelo.Torol(etk); ABKezelo.Beszuras(etk); } } } EtrendIdopont et = new EtrendIdopont(fnev, new List <DateTime>(3)); for (i = 0; i < 3; i++) { et.Datum.Add(new DateTime(2018, 1, 1, (int)numericUpDowns2[2 * i].Value, (int)numericUpDowns2[2 * i + 1].Value, 0)); } if (ABKezelo.Kiolvasas().Where(x => x is EtrendIdopont).ToList().Count > 0) { ABKezelo.Modositas(et); } else { ABKezelo.Beszuras(et); } Logolas.Ment("Saved diet conditions."); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Button4_Click(object sender, EventArgs e) { try { if (listBox1.SelectedIndex != -1) { string str = (listBox1.SelectedItem as Mertekegyseg).Megnevezes; bool torolheto = true; foreach (Elelmiszer item in ABKezelo.Kiolvasas().Where(x => x is Elelmiszer)) { if (item is Ital && (item as Ital).Urmertek.Megnevezes == str) { torolheto = false; break; } if (item is Etel && (item as Etel).TomegMertek.Megnevezes == str) { torolheto = false; break; } } if (!torolheto) { throw new WarningException( "This unit is not deletable, beaucse there is a food using it!"); } if (ABKezelo.Kiolvasas().Where(x => x is Tapanyag && (x as Tapanyag).Mertek.Megnevezes == str).ToList().Count > 0) { throw new WarningException( "This unit is not deletable, because there is a nutrient using it!"); } if (ABKezelo.Kiolvasas().Where(x => x is Etel && (x as Etel).TomegMertek.Megnevezes == str).ToList().Count > 0) { throw new WarningException( "This unit is not deletable, because there is a meal using it!"); } if (ABKezelo.Kiolvasas().Where(x => x is Ital && (x as Ital).Urmertek.Megnevezes == str).ToList().Count > 0) { throw new WarningException( "This unit is not deletable, because there is a drink using it!"); } if (((Mertekegyseg)listBox1.SelectedItem).Torolheto) { if (MessageBox.Show("Really want to delete the unit?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string nev = ((Mertekegyseg)listBox1.SelectedItem).Megnevezes; ABKezelo.Torol((Mertekegyseg)listBox1.SelectedItem); Logolas.Ment("Unit deleted, name: " + nev); ListBoxRefresh(); } } else { throw new WarningException("This unit is not deletable!"); } } else { throw new WarningException("To delete a unit choose one!"); } } catch (Exception ex) { if (ex is WarningException) { MessageBox.Show(ex.Message, "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void Button4_Click(object sender, EventArgs e) { try { if (listBox1.SelectedIndex != -1) { Penznem p = (Penznem)listBox1.SelectedItem; bool torolheto = true; foreach (Elelmiszer item in ABKezelo.Kiolvasas().Where(x => x is Elelmiszer)) { if (item.Penz.Megnevezes == p.Megnevezes) { torolheto = false; break; } } if (!torolheto) { throw new WarningException("This currency is not deletable, because there is a food using it!"); } EtrendFeltetel et = (EtrendFeltetel)ABKezelo.Kiolvasas().Where(x => x is EtrendFeltetel).ToList().First(); if (et.Penz.Megnevezes == p.Megnevezes) { throw new WarningException("This currency is not deletable, bceause Form1 is using it!"); } if (((Penznem)listBox1.SelectedItem).Torolheto) { if (MessageBox.Show("Really want to delete the currency?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string nev = ((Penznem)listBox1.SelectedItem).Megnevezes; ABKezelo.Torol((Penznem)listBox1.SelectedItem); Logolas.Ment("Currency deleted, name: " + nev); ListBoxRefresh(); } } else { throw new WarningException("This currency is not deletable!"); } } else { throw new WarningException("To delete a currency choose one!"); } } catch (Exception ex) { if (ex is WarningException) { MessageBox.Show(ex.Message, "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }