예제 #1
0
        private void cbBudgetCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            List <DataModel.Budget> lBudget = oFactory.oData.Budget_RetrieveAll();

            if (cbBudgetCategory.SelectedItem != null)
            {
                if (lBudget?.Count > 0)
                {
                    DataModel.Budget oBudget = lBudget.Where(tmpbudget => tmpbudget.Category.ToString() == cbBudgetCategory.SelectedItem.ToString()).FirstOrDefault();
                    if (oBudget != null)
                    {
                        tbBudget.Text = oBudget.Value;
                    }
                    else
                    {
                        tbBudget.Text = "";
                    }
                }
            }
        }
예제 #2
0
 private void btnUpdateBudget_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(tbBudget.Text))
     {
         Regex regExpresion = new Regex(@"^-*[0-9\.]+$");
         // If they are updating the budget with a valid number
         if (regExpresion.IsMatch(tbBudget.Text))
         {
             DataModel.Budget oBudget = new DataModel.Budget()
             {
                 Category = cbBudgetCategory.SelectedItem.ToString(),
                 Value    = tbBudget.Text
             };
             oBudget = oFactory.oDataManager.AddUpdateBudget(oBudget);
             if (oBudget.Success)
             {
                 string SuccessMessage = "Successfully updated budget. ";
                 if (!string.IsNullOrEmpty(oBudget.Message))
                 {
                     SuccessMessage += oBudget.Message;
                 }
                 MessageBox.Show(SuccessMessage);
             }
             else
             {
                 MessageBox.Show(oBudget.Message);
             }
         }
         else
         {
             DataModel.Budget oBudget = oFactory.oDataManager.GetBudget(cbBudgetCategory.SelectedItem.ToString());
             if (oBudget != null)
             {
                 tbBudget.Text = oBudget.Value;
             }
             else
             {
                 tbBudget.Text = "";
             }
             MessageBox.Show("Please provide a valid number. Ex. 1234.56");
         }
     }
     else
     {
         DataModel.Budget oBudget = new DataModel.Budget()
         {
             Category = cbBudgetCategory.SelectedItem.ToString(),
             Value    = ""
         };
         oBudget = oFactory.oDataManager.RemoveBudget(oBudget);
         if (oBudget.Success)
         {
             MessageBox.Show("Successfully removed budget. ");
         }
         else
         {
             MessageBox.Show(oBudget.Message);
             oBudget = oFactory.oDataManager.GetBudget(cbBudgetCategory.SelectedItem.ToString());
             if (oBudget != null)
             {
                 tbBudget.Text = oBudget.Value;
             }
             else
             {
                 tbBudget.Text = "";
             }
         }
     }
 }