コード例 #1
0
ファイル: Receipts.cs プロジェクト: GamezAr94/ExpensesTracker
 //Method to delete a record from the datagrid
 private void DeletingForm(Expenses purchase)
 {
     try
     {
         int rowsAffected;
         rowsAffected = ExpensesValidation.DeleteExpenses(purchase);
         if (rowsAffected <= 0)
         {
             MessageBox.Show("No changes were made");
             labelMessage.Text = "Entry not deleted";
         }
         else
         {
             labelMessage.Text = string.Empty;
             refreshListBox();
         }
         //creates a new empty object to set the form for a new record, changuing manually the combobox
         purchasesVM.SetDisplayPurchase(new Expenses()
         {
             Date = DateTime.Today
         });
         comboBoxCategory.SelectedIndex = -1;
     }
     catch (MySqlException ex)
     {
         MessageBox.Show(ex.ToString(), "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(), "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #2
0
ファイル: Receipts.cs プロジェクト: GamezAr94/ExpensesTracker
        //Try to add the data from the fields with cash type, if it has rows affected it will reset the comboBox, the error provider and it will create a new Expenses with the current date
        //if not it will shows an error provider depends of the error
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            try
            {
                int rowsAffected;
                purchasesVM.Purchase.Type = "Cash";
                rowsAffected = ExpensesValidation.AddExpenses(purchasesVM.GetDisplayPurchase());
                if (rowsAffected > 0)
                {
                    refreshListBox();

                    //reset the values in the form an create an empty purchase
                    comboBoxCategory.SelectedIndex = -1;
                    purchasesVM.SetDisplayPurchase(new Expenses()
                    {
                        Date = DateTime.Today
                    });
                    errorProvider1.SetError(buttonAdd, string.Empty);
                    labelMessage.Text = string.Empty;
                }
                else
                {
                    if (rowsAffected == 0)
                    {
                        //MessageBox.Show("No DB changes were made\n\nPlease revise if the data is correct or if the data provided is not duplicated with an existing field\n\nIf you want to add duplicated data please specify in the Notes section and try again.", "Zero Affected Rows", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        errorProvider1.SetError(buttonAdd, "No DB changes were made\n\nPlease revise if the data is correct or if the data provided is not duplicated with an existing field\n\nIf you want to add duplicated data please specify it in the Notes section and try again.");
                        labelMessage.Text = "Probable repetition of data\nPlease check your entry if is not repeated\nif you want to repeat this entry\nplease provide details on Notes section";
                    }
                    else
                    {
                        //MessageBox.Show(ExpensesValidation.MessageError, "Validation error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        errorProvider1.SetError(buttonAdd, ExpensesValidation.MessageError);
                        labelMessage.Text = ExpensesValidation.MessageError;
                    }
                }
                dateTimePickerDay.Select();
            }
            catch (MySqlException ex)
            {
                MessageBox.Show(ex.Message + "\nPlease save this message and contact with technical support.", "DB Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\nPlease save this message and contact with technical support.", "Processing Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #3
0
ファイル: Receipts.cs プロジェクト: GamezAr94/ExpensesTracker
 //Method to edit a record from the data grid
 private void EditingForm(Expenses purchase)
 {
     try
     {
         int rowsAffected;
         rowsAffected = ExpensesValidation.EditRecord(purchase);
         if (rowsAffected > 0)
         {
             errorProvider1.SetError(buttonAdd, string.Empty);
             labelMessage.Text = string.Empty;
             refreshListBox();
         }
         else
         {
             if (rowsAffected == 0)
             {
                 errorProvider1.SetError(buttonAdd, "No DB changes were made\n\nPlease revise if the data is correct or if the data provided is not duplicated with an existing field\n\nIf you want to add duplicated data please specify it in the Notes section and try again.");
                 labelMessage.Text = "No DB changes were made\nPlease revise if the data is not repeated";
             }
             else
             {
                 errorProvider1.SetError(buttonAdd, ExpensesValidation.MessageError);
                 labelMessage.Text = ExpensesValidation.MessageError;
             }
         }
         //creates a new empty object to set the form for a new record, changuing manually the combobox
         purchasesVM.SetDisplayPurchase(new Expenses()
         {
             Date = DateTime.Today
         });
         comboBoxCategory.SelectedIndex = -1;
     }
     catch (MySqlException ex)
     {
         MessageBox.Show(ex.ToString(), "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(), "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }