/// <summary> /// Sets the intial state and current state expense properties of the form /// </summary> /// <param name="expense">The expense the form was opened for</param> public ExpenseViewer(Expense expense) { this.currentExpense = expense; // Makes a shallow copy of the expense passed in this.originalExpense = this.currentExpense.Copy(); InitializeComponent(); }
/// <summary> /// Saves the new expense into the cache -validates the amount /// and gives an option to enter more data /// </summary> /// <param name="sender">Standard sender object</param> /// <param name="e">Standard event object</param> private void btnSave_Click(object sender, EventArgs e) { // If the amount is blank if (this.txtAmount.Text == "") { MessageBox.Show("The amount can not be blank", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } // Checks that the amount is in numbers else if (!HelperMethods.IsNumeric(this.txtAmount.Text)) { MessageBox.Show("The amount must be in numbers", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); this.txtAmount.Text = ""; } // Otherwise saves the new expense else { Expense newExpense = new Expense(double.Parse(this.txtAmount.Text), this.dtPick.Value, ExpenseCategoryHandler.LoadById(Convert.ToInt32(this.cmbCategory.SelectedValue)), PaymentMethodHandler.LoadById(Convert.ToInt32(this.cmbPayment.SelectedValue)), this.txtDetail.Text); ExpenseHandler.AddNewExpense(newExpense); // Asks if more data is being entered DialogResult = MessageBox.Show("The entry was saved" + "\nDo you want to add another expense? ", "Save successful", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (DialogResult != DialogResult.Yes) { this.Close(); } // If more data is being entered clears the user entered data for the new data else { // Puts the focus back to the top of the form and resets the selected values this.cmbCategory.Focus(); this.txtAmount.Text = ""; this.txtDetail.Text = ""; } } }
/// <summary> /// Cancels the edit and leaves the form open /// -clears any changes made /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCancel_Click(object sender, EventArgs e) { // Enables the controls for editing and updates which buttons are visible this.ToggleEnableControls(this.txtAmount, this.txtDetail, this.cmbCategory, this.cmbPayment, this.dtPick, this.btnSave, this.btnEdit, this.btnCancel, this.btnDelete); this.ToggleVisibility(this.btnSave, this.btnCancel, this.btnEdit, this.btnDelete); // Makes sure that the expense of the binding has the origional values this.currentExpense = this.originalExpense.Copy(); // Resets the data bindings this.SetDataBindings(); }
public static int AddNewExpense(Expense newExpense) { StaticDataSet.t_expensesRow newDbExpense = Cache.SDB.t_expenses.Newt_expensesRow(); newDbExpense.ID = GetNextId(); newDbExpense.AMOUNT = newExpense.Amount; newDbExpense.CATEGORY = newExpense.Category.Id; newDbExpense.METHOD = newExpense.Method.Id; newDbExpense.EXP_DATE = newExpense.Date; newDbExpense.COMMENTS = newExpense.Comment; Cache.SDB.t_expenses.Addt_expensesRow(newDbExpense); return newDbExpense.ID; }
/// <summary> /// Updates the cache with the changes of the expense /// </summary> /// <param name="expenseToSave">The expense to be saved</param> /// <returns>True on success, false on any exception</returns> public static bool Save(Expense expenseToSave) { try { UpdateDataBase(expenseToSave); return true; } catch { return false; } }
/// <summary> /// Updates the row in the database that corrosponds to the expense entity /// passed in /// </summary> /// <param name="expenseTranslating">The expense entity to update the database with</param> private static void UpdateDataBase(Expense expenseTranslating) { StaticDataSet.t_expensesRow translatedRow = Cache.SDB.t_expenses.FindByID(expenseTranslating.ID); //Because this form is only for updating, there is no check if it exists in the database translatedRow.ID = expenseTranslating.ID; translatedRow.AMOUNT = expenseTranslating.Amount; translatedRow.COMMENTS = expenseTranslating.Comment; translatedRow.EXP_DATE = expenseTranslating.Date; // There is no check to see if they exist in the database or not // because as of 20.02.2014 the form only shows categories/methods // that already exist - and does not allow the user to create new ones translatedRow.CATEGORY = expenseTranslating.Category.Id; translatedRow.METHOD = expenseTranslating.Method.Id; }
private void SaveNewExpense(DateTime dtCurrentSaveDate) { Expense newExpense = new Expense(double.Parse(this.txtAmount.Text), dtCurrentSaveDate, ExpenseCategoryHandler.LoadById(Convert.ToInt32(this.cmbCategory.SelectedValue)), PaymentMethodHandler.LoadById(Convert.ToInt32(this.cmbPayment.SelectedValue)), this.txtDetail.Text); ExpenseHandler.AddNewExpense(newExpense); }
public static int AddNewExpense(Expense newExpense) { return ExpenseAccess.AddNewExpense(newExpense); }
/// <summary> /// Updates the cache with the changes of the expense /// </summary> /// <param name="expenseToSave">The expense to be saved</param> public static void Save(Expense expenseToSave) { ExpenseAccess.Save(expenseToSave); }