public void Update(IncomeAndExpense incomeAndExpense) { SQLiteConnection sqlite_conn; SQLiteCommand sqlite_cmd; sqlite_conn = new SQLiteConnection(DataProvider.SQLiteConnectionString); sqlite_conn.Open(); sqlite_cmd = sqlite_conn.CreateCommand(); StringBuilder commandText = new StringBuilder(); commandText.Append("UPDATE ДоходыИРасходы SET "); DataProvider.AddCommandTextUpdate(commandText, "Дата", DataProvider.ConvertDateToSQLiteFormat(incomeAndExpense.Date)); DataProvider.AddCommandTextUpdate(commandText, "НомерДокумента", incomeAndExpense.DocumentsNumber); DataProvider.AddCommandTextUpdate(commandText, "СодержаниеОперации", incomeAndExpense.SubstanceOfTransaction); DataProvider.AddCommandTextUpdate(commandText, "Доход", incomeAndExpense.Income); DataProvider.AddCommandTextUpdate(commandText, "Расход", incomeAndExpense.Expense, last: true); commandText.Append(" WHERE Индекс = " + incomeAndExpense.GetInternalIndex() + ";"); sqlite_cmd.CommandText = commandText.ToString(); sqlite_cmd.ExecuteNonQuery(); sqlite_conn.Close(); }
private void editIncomeAndExpenseButton_Click(object sender, EventArgs e) { string internalIndex = incomeAndExpense.GetInternalIndex(); incomeAndExpense = new IncomeAndExpense(); incomeAndExpense.SetInternalIndex(internalIndex); incomeAndExpense.Date = dateDateTimePicker.Text; incomeAndExpense.DocumentsNumber = documentsNumberTextBox.Text; incomeAndExpense.SubstanceOfTransaction = substanceOfTransactionTextBox.Text; incomeAndExpense.Income = incomeTextBox.Text; incomeAndExpense.Expense = expenseTextBox.Text; try { Convert.ToDouble(incomeAndExpense.Income); } catch (FormatException) { MessageBox.Show("Поле дохода указано неверно."); return; } try { Convert.ToDouble(incomeAndExpense.Expense); } catch (FormatException) { MessageBox.Show("Поле расхода указано не верно"); return; } MainForm.programLogic.incomeAndExpenseLogic.Update(incomeAndExpense, timePeriod, INN); Close(); }
public void UpdateIncomeAndExpense(IncomeAndExpense incomeAndExpense, IncomeAndExpenseTimePeriod timePeriod) { OleDbConnection myOleDbConnection = new OleDbConnection(connectionString); OleDbCommand myOleDbCommand = myOleDbConnection.CreateCommand(); StringBuilder commandText = new StringBuilder(); commandText.Append("UPDATE [Доходы и расходы " + timePeriod.Year + "] SET "); DataProvider.AddCommandTextUpdate(commandText, "Дата", incomeAndExpense.Date); DataProvider.AddCommandTextUpdate(commandText, "№ документа", incomeAndExpense.DocumentsNumber); DataProvider.AddCommandTextUpdate(commandText, "Содержание операции", incomeAndExpense.SubstanceOfTransaction); DataProvider.AddCommandTextUpdate(commandText, "Доход", incomeAndExpense.Income); DataProvider.AddCommandTextUpdate(commandText, "Расход", incomeAndExpense.Expense, last: true); commandText.Append(" WHERE [№ п/п] = "); commandText.Append(incomeAndExpense.GetInternalIndex()); commandText.Append(";"); myOleDbCommand.CommandText = commandText.ToString(); myOleDbConnection.Open(); myOleDbCommand.ExecuteScalar(); myOleDbConnection.Close(); }