/// <summary> /// This method calls when user click on button btnAddExp and user adds a new Expenditure. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddExp_Click(object sender, EventArgs e) { ExpenditureForm expenditureForm = new ExpenditureForm(); if (expenditureForm.ShowDialog() == DialogResult.OK) { Expenditure expenditure = expenditureForm.ExpenditureData; expenditureManager.Add(expenditure); UpdateGui(); } }
/// <summary> /// This method reads all user input and puts in the class variables of Expenditure. /// </summary> /// <returns> Returns true if inputs are valid</returns> private bool ReadInput() { int amount; if (!string.IsNullOrEmpty(tbDescriptionExp.Text) && cbExp.SelectedIndex != -1 && int.TryParse(tbAmountExp.Text, out amount)) { expenditure = new Expenditure(dateTimePickerExp.Value, tbDescriptionExp.Text, (ExpencesEnum)Enum.Parse(typeof(ExpencesEnum), cbExp.SelectedItem.ToString()), amount); return(true); } else { return(false); } }
/// <summary> /// This method calls when user click on button btnEditExp and user edits the selected Expenditure object. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnEditExp_Click(object sender, EventArgs e) { int index = lbExp.SelectedIndex; if (index != -1) { Expenditure expenditure = expenditureManager.GetExpenditureAt(index); ExpenditureForm expenditureForm = new ExpenditureForm(); expenditureForm.ExpenditureData = expenditure; if (expenditureForm.ShowDialog() == DialogResult.OK) { expenditure = expenditureForm.ExpenditureData; expenditureManager.Edit(index, expenditure); UpdateGui(); } } }
/// <summary> /// This method changes the Expenditure object with a new one. /// </summary> /// <param name="index"></param> /// <param name="newIncome"></param> public void Edit(int index, Expenditure newExpend) { expenditureList[index] = newExpend; expenditureList.Sort((x, y) => x.Date.CompareTo(y.Date)); }
/// <summary> /// This method adds the given Expenditure object in the end of the List. /// </summary> /// <param name="task"></param> public void Add(Expenditure expenditure) { expenditureList.Add(expenditure); expenditureList.Sort((x, y) => x.Date.CompareTo(y.Date)); }