private void button2_Click(object sender, EventArgs e) { t = new Tovar(); Form2 addform = new Form2(t, true); if (addform.ShowDialog() == DialogResult.OK) { comboBox1.Items.Add(t); } }
public Form2(Tovar t, bool addnew) { InitializeComponent(); this.addnew = addnew; this.t = t;//Запомнили ссылку на товар if (addnew == false) { textBox1.Text = t.Name; textBox3.Text = t.Opisanie; textBox2.Text = t.Price.ToString(); this.Text = "Редактирование товара"; this.button1.Text = "Обновить"; } else { this.Text = "Добавление товара"; } }
private void button1_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex == -1) { MessageBox.Show("Вы не выбрали товар"); return; } t = (Tovar)comboBox1.Items[comboBox1.SelectedIndex]; //this.Text = $"Итого продали за день: {TOTALPRICE+=t.Price}"; //listBox1.Items.Add(t); Tovar t2 = new Tovar(t); listBox1.Items.Add(t2); this.Text = $"Итого продали за день: {TOTALPRICE += t2.Price}"; //foreach (Tovar item in listBox1.Items) //{ // TOTALPRICE += item.Price; //} //this.Text = $"Итого продали за день: {TOTALPRICE}"; //TOTALPRICE = 0; }
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "") { MessageBox.Show("Заполните все поля"); return; } if (t == null) { t = new Tovar(); } t.Name = textBox1.Text; t.Opisanie = textBox3.Text; try { t.Price = Convert.ToDouble(textBox2.Text); } catch (Exception) { MessageBox.Show("Цена указана неверно"); return; } this.DialogResult = DialogResult.OK; }
public Tovar(Tovar t) { Name = t.name; Price = t.Price; Opisanie = t.Opisanie; }
private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e) { t = (Tovar)comboBox1.Items[comboBox1.SelectedIndex]; textBox1.Text = Convert.ToString(t.Price); }