Exemplo n.º 1
0
        /// <summary>
        /// Sets the intial state and current state expense properties of the form
        /// </summary>
        /// <param name="income">The income the form was opened for</param>
        public IncomeViewer(Income income)
        {
            this.currentIncome = income;

            // Makes a shallow copy of the income passed in
            this.originalIncome = this.currentIncome.Copy();
            InitializeComponent();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves the new income 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 (!BusinessLogic.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 income
            else
            {
                Income newIncome =
                    new Income(double.Parse(this.txtAmount.Text), this.dtPick.Value,
                                IncomeCategoryHandler.LoadById(Convert.ToInt32(this.cmbCategory.SelectedValue)),
                                PaymentMethodHandler.LoadById(Convert.ToInt32(this.cmbPayment.SelectedValue)),
                                this.txtDetail.Text);

                IncomeHandler.AddNewIncome(newIncome);

                // Asks if more data is being entered
                DialogResult = MessageBox.Show("The entry was saved" +
                                               "\nDo you want to add another income? ",
                                               "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 = "";
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Updates the cache with the changes of the income
 /// </summary>
 /// <param name="expenseToSave">The income to be saved</param>
 /// <returns>True on success, false on any exception</returns>
 public static bool Save(Income incomeToSave)
 {
     try
     {
         UpdateDataBase(incomeToSave);
         return true;
     }
     catch
     {
         return false;
     }
 }
Exemplo n.º 4
0
        /// <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.currentIncome = this.originalIncome.Copy();

            // Resets the data bindings
            this.SetDataBindings();
        }
Exemplo n.º 5
0
        public static int AddNewIncome(Income newIncome)
        {
            StaticDataSet.t_incomesRow newDbIncome = Cache.SDB.t_incomes.Newt_incomesRow();
            newDbIncome.ID = GetNextId();
            newDbIncome.AMOUNT = newIncome.Amount;
            newDbIncome.CATEGORY = newIncome.Category.Id;
            newDbIncome.METHOD = newIncome.Method.Id;
            newDbIncome.INC_DATE = newIncome.Date;
            newDbIncome.COMMENTS = newIncome.Comment;

            Cache.SDB.t_incomes.Addt_incomesRow(newDbIncome);

            return newDbIncome.ID;
        }
Exemplo n.º 6
0
 public static int AddNewIncome(Income newIncome)
 {
     return IncomeAccess.AddNewIncome(newIncome);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Updates the cache with the changes of the Income
 /// </summary>
 /// <param name="incomeToSave">The Income to be saved</param>
 public static void Save(Income incomeToSave)
 {
     IncomeAccess.Save(incomeToSave);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Updates the row in the database that corrosponds to the income entity
        /// passed in
        /// </summary>
        /// <param name="incomeTranslating">The income entity to update the database with</param>
        private static void UpdateDataBase(Income incomeTranslating)
        {
            StaticDataSet.t_incomesRow translatedRow = Cache.SDB.t_incomes.FindByID(incomeTranslating.ID);

            //Because this form is only for updating, there is no check if it exists in the database

            translatedRow.ID = incomeTranslating.ID;
            translatedRow.AMOUNT = incomeTranslating.Amount;
            translatedRow.COMMENTS = incomeTranslating.Comment;
            translatedRow.INC_DATE = incomeTranslating.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 do not allow the user to create new ones
            translatedRow.CATEGORY = incomeTranslating.Category.Id;
            translatedRow.METHOD = incomeTranslating.Method.Id;
        }
Exemplo n.º 9
0
 private void CreateNewIncome(DateTime dtCurrentSaveDate)
 {
     Income newIncome =
             new Income(double.Parse(this.txtAmount.Text), dtCurrentSaveDate,
                         IncomeCategoryHandler.LoadById(Convert.ToInt32(this.cmbCategory.SelectedValue)),
                         PaymentMethodHandler.LoadById(Convert.ToInt32(this.cmbPayment.SelectedValue)),
                         this.txtDetail.Text);
 }