private void buttonUpdateExpenses_Click(object sender, EventArgs e) { expense = ExpensesModel.SelectAll(); if (expense.Count != 0) { var index = dataGridViewExpenses.CurrentRow.Index; UpdatePriceExpenses updatePrice = new UpdatePriceExpenses(); updatePrice.eModel = expense[index]; updatePrice.ShowDialog(); ShowExpenses(); Show(); } else { MessageBox.Show("Таблица пустая"); } }
private void buttonUpdate_Click(object sender, EventArgs e) { if (eModel != null) { eModel.Price = Convert.ToInt32(textBoxPrice.Text); eModel.Date = textBoxDate.Text; eModel.Name = textBoxName.Text; bool isUpdate = ExpensesModel.Update(eModel); if (isUpdate) { Close(); } else { MessageBox.Show("Ошибка"); } } }
private void buttonAddExpenses_Click(object sender, EventArgs e) { if (textBoxExpenses.Text != "" && textBoxPrice.Text != "") { expenses = new ExpensesModel(); expenses.Name = textBoxExpenses.Text; expenses.Price = int.Parse(textBoxPrice.Text); var hour = DateTime.Now.Hour; var day = DateTime.Now.Day; var month = DateTime.Now.Month; var year = DateTime.Now.Year; if (hour >= 0 && hour <= 6) { var date = new DateTime(year, month, day - 1, hour, dateTimePicker1.Value.Minute, dateTimePicker1.Value.Second); dateTimePicker1.Value = date; } else if (hour >= 9 && hour <= 23) { var date = new DateTime(year, month, day, hour, dateTimePicker1.Value.Minute, dateTimePicker1.Value.Second); dateTimePicker1.Value = date; } else { MessageBox.Show("Рабочий день закончился"); } expenses.Date = dateTimePicker1.Value.ToString("dd-MM-yyyy HH:mm"); int lastId = ExpensesModel.Insert(expenses); if (lastId > 0) { ShowExpenses(); ClearTextBox(); } else { MessageBox.Show("Ошибка при добавление"); } } else { MessageBox.Show("Заполните поля"); } }
private void ShowExpenses() { expense = ExpensesModel.SelectAll(); dataGridViewExpenses.DataSource = expense; }
public static bool Update(ExpensesModel expenses) { return(DBManager.UpdateExpenses(expenses)); }
public static int Insert(ExpensesModel expenses) { return(DBManager.InsertExpenses(expenses)); }