private void buttonUpdate_Click(object sender, EventArgs e) { if (store != null) { store.Name = textBoxName.Text; store.Price = Convert.ToInt32(textBoxPrice.Text); store.Amount = Convert.ToInt32(textBoxAmount.Text); store.Type = textBoxType.Text; bool isUpdate = StoreModel.Update2(store); if (isUpdate) { StoreReportModel report = new StoreReportModel(); report.Name = textBoxName.Text; report.Amount = Convert.ToInt32(textBoxAmount.Text); report.Date = dateTimePicker1.Value.ToString("dd-MM-yyyy"); report.Type = store.Type; int Id = StoreReportModel.Insert(report); if (Id >= 0) { Close(); } else { MessageBox.Show("Ошибки"); } } else { MessageBox.Show("ошибка"); } } }
private void buttonInsert_Click(object sender, EventArgs e) { if (store == null) { stores = StoreModel.SelectAll(); store = new StoreModel(); if (textBoxName.Text != "" && textBoxPrice.Text != "" && textBoxAmount.Text != "") { InsertGoods(); if (radioButtonDrink.Checked == true) { store.Type = textBoxDrink.Text; } else if (radioButtonGoods.Checked == true) { store.Type = textBoxGoods.Text; } for (int i = 0; i < stores.Count; i++) { if (store.Name == stores[i].Name) { MessageBox.Show("Товар с таким названием уже есть"); textBoxName.Text = null; textBoxAmount.Text = null; textBoxPrice.Text = null; store = null; return; } } int lastId = StoreModel.Insert(store); if (lastId >= 0) { StoreReportModel report = new StoreReportModel(); report.Name = textBoxName.Text; report.Amount = Convert.ToInt32(textBoxAmount.Text); report.Date = dateTimePicker1.Value.ToString("dd-MM-yyyy"); report.Type = store.Type; int Id = StoreReportModel.Insert(report); if (Id >= 0) { Close(); } else { MessageBox.Show("ошибки"); } } else { MessageBox.Show("Ошибка"); } } else { MessageBox.Show("Заполните поля"); } } else { if (textBoxName.Text != "" && ((textBoxPrice.Text != "" && textBoxAmount.Text != "") || (textBoxPrice.Text != "" || textBoxAmount.Text != ""))) { InsertGoods(); StoreReportModel report = new StoreReportModel(); if (radioButtonDrink.Checked == true) { store.Type = textBoxDrink.Text; } else if (radioButtonGoods.Checked == true) { store.Type = textBoxGoods.Text; } bool isUpdated = StoreModel.Update(store); if (isUpdated) { stores = StoreModel.SelectAll(); for (int i = 0; i < stores.Count; i++) { if (stores[i].Id == store.Id) { var numb = i; report.Amount = stores[numb].Amount; } } report.Name = textBoxName.Text; report.Date = dateTimePicker1.Value.ToString("dd-MM-yyyy"); report.Type = store.Type; int Id = StoreReportModel.Insert(report); if (Id >= 0) { Close(); } else { MessageBox.Show("Ошибки"); } } else { MessageBox.Show("ошибка изменения"); } } else { MessageBox.Show("Заполните поля"); } } }