Exemple #1
0
        private void dataGridEditValue(object sender, DataGridViewCellEventArgs e)
        {
            int budgetItemId = Convert.ToInt32(dataGridBudget.SelectedRows[0].Cells[0].Value.ToString());

            Console.WriteLine("selected id :" + budgetItemId);

            BudgetManagerModelContainer db = new BudgetManagerModelContainer();
            var query = from BudgetItem in db.BudgetItems
                        where BudgetItem.Id == budgetItemId
                        select BudgetItem;

            BudgetItem budgetItem = query.First();

            txtYear.Text           = budgetItem.Budget.Year.ToString();
            txtYear.ReadOnly       = true;
            cmbMonth.SelectedIndex = (budgetItem.Budget.Month - 1);
            //cmbMonth
            txtMonth.Visible          = true;
            txtMonth.Text             = (String)cmbMonth.SelectedItem;
            txtMonth.ReadOnly         = true;
            cmbMonth.Visible          = false;
            cmbCategory.SelectedValue = budgetItem.CategoryId;
            cmbType.SelectedItem      = budgetItem.ItemType;
            Console.WriteLine("55 :" + budgetItem.ItemType);
            txtAmount.Text       = budgetItem.Allocation.ToString();
            txtBudgetItemId.Text = budgetItem.Id.ToString();
        }
Exemple #2
0
 private double GetBudgetValue(Category category)
 {
     getBudgetItems();
     if (ThisMonthItemList != null)
     {
         BudgetItem bitem = ThisMonthItemList.Find(f => f.CategoryId == category.Id);
         if (bitem != null)
         {
             return(bitem.Allocation);
         }
     }
     return(0.0);
 }
Exemple #3
0
        private void getBudgetforMonth(int year, int month)
        {
            BudgetManagerModelContainer db             = new BudgetManagerModelContainer();
            List <BudgetItem>           budgetItemList = new List <BudgetItem>();

            var query = from Budget in db.Budgets
                        where Budget.Month == month && Budget.Year == year && Budget.UserId == 1
                        select Budget;

            Budget budgets = new Budget();

            if (query.Any())
            {
                budgets = query.First();
            }
            else
            {
                budgets = null;
            }

            BudgetItem budgetItem = new BudgetItem();

            budgetItem.ItemType   = (TransactionType)cmbType.SelectedItem;
            budgetItem.Allocation = Double.Parse(txtAmount.Text);
            budgetItem.CategoryId = ((Category)cmbCategory.SelectedItem).Id;

            if (budgets != null)
            {
                budgetItem.BudgetId = budgets.Id;
                budgetItemList      = budgets.BudgetItems.ToList();
                budgetItemList.Add(budgetItem);
                budgets.BudgetItems = budgetItemList;
                db.BudgetItems.Add(budgetItem);
                db.SaveChanges();
            }
            else
            {
                budgets = new Budget();
                budgetItemList.Add(budgetItem);
                budgets.UserId      = 1;
                budgets.Year        = Convert.ToInt16(year);
                budgets.Month       = Convert.ToInt16(month);
                budgets.BudgetItems = budgetItemList;
                db.Budgets.Add(budgets);
                db.SaveChanges();
            }

            cleanFields();
            setDataGridValue(year, month);
            MessageBox.Show("Successful");
        }
Exemple #4
0
        private void saveBudgetItem(Int16 id)
        {
            int year = Int16.Parse(txtYear.Text);

            Console.WriteLine("year :" + year);
            int month = (cmbMonth.SelectedIndex) + 1;

            Console.WriteLine("month :" + month);

            BudgetManagerModelContainer db = new BudgetManagerModelContainer();
            var query = from BudgetItem in db.BudgetItems
                        where BudgetItem.Id == id
                        select BudgetItem;
            BudgetItem budgetItem = query.First();

            budgetItem.ItemType   = (TransactionType)cmbType.SelectedItem;
            budgetItem.Allocation = Double.Parse(txtAmount.Text);
            budgetItem.CategoryId = ((Category)cmbCategory.SelectedItem).Id;
            db.SaveChanges();

            cleanFields();
            setDataGridValue(year, month);
            MessageBox.Show("Successful");
        }