Exemplo n.º 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                string item     = "";
                string price    = "";
                string quantity = "";
                int    days     = 0;
                int    years    = 0;
                //Add the expenses and load on the gridview
                if (cmbItem.SelectedIndex != -1 && txtPrice.Text.Trim() != string.Empty && txtQuantity.Text.Trim() != string.Empty)
                {
                    DataTable data = expenseService.GetLastIdInt();
                    {
                        expenseId = int.Parse(data.Rows[0]["Expr1000"].ToString()) + 1;
                    }
                    item     = itemselected;
                    price    = txtPrice.Text.Trim();
                    quantity = txtQuantity.Text.Trim();
                    DateTime dtpicker = Dtp.Value;
                    days  = dtpicker.Day;
                    years = dtpicker.Year;

                    // Assign the values to the model
                    Expenses expenseModel = new Expenses()
                    {
                        ID        = expenseId,
                        Item      = item,
                        Price     = price,
                        Quantity  = quantity,
                        DateSpent = dtpicker,
                        Days      = days,
                        Months    = Format.ConvertIntToMonth(dtpicker.Month),
                        Years     = years
                    };

                    // Call the service method and assign the return status to variable
                    var success = this.expenseService.RegisterExpense(expenseModel);

                    // if status of success variable is true then display a information else display the error message
                    if (success)
                    {
                        // display the message box
                        MessageBox.Show("Stored in DB", "Alert Message",
                                        //Resources.Registration_Successful_Message,
                                        //Resources.Registration_Successful_Message_Title,
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information
                                        );

                        // Reset the screen
                        this.ResetRegistration();
                        cmbItem.Focus();
                    }
                    else
                    {
                        // display the error messge
                        MessageBox.Show("Error", "Alert Message",
                                        //Resources.Registration_Error_Message,
                                        //Resources.Registration_Error_Message_Title,
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error
                                        );
                    }
                }
                else
                {
                    MessageBox.Show("Item is empty or Expense is empty");
                }
            }
            catch (Exception ex)
            {
                this.ShowErrorMessage(ex);
            }
            LoadRefresh();
        }