public void AddBudgetFromFile(String path, int UserId)
        {
            FileStream   fs                  = new FileStream(path, FileMode.Open);
            StreamReader sr                  = new StreamReader(fs);
            String       name                = sr.ReadLine();
            String       StartDate           = sr.ReadLine();
            String       endDate             = sr.ReadLine();
            String       Income              = sr.ReadLine();
            String       ExpCatagories       = sr.ReadLine();
            String       ExpCatagoriesRanges = sr.ReadLine();

            sr.Close();
            fs.Close();

            Budget b = new Budget();

            b.Name      = name;
            b.UID       = UserId;
            b.StartDate = DateTime.ParseExact(StartDate, "dd/MM/yyyy", null);
            b.EndDate   = DateTime.ParseExact(endDate, "dd/MM/yyyy", null);
            b.Income    = Int32.Parse(Income);
            b.isCurrent = true;

            MoneyManagementEntities2 db  = new MoneyManagementEntities2();
            Budget AlreadySelectedBudget = null;

            foreach (Budget curr in db.Budgets)
            {
                if (curr.isCurrent == true)
                {
                    AlreadySelectedBudget = curr;
                }
            }
            if (AlreadySelectedBudget != null)
            {
                AlreadySelectedBudget.isCurrent = false;
                db.SaveChanges();
            }
            db.Budgets.Add(b);
            db.SaveChanges();

            String []       catagories       = ExpCatagories.Split(',');
            String[]        catagoriesRanges = ExpCatagoriesRanges.Split(',');
            ExpenseCatagory Bcatagory        = new ExpenseCatagory();

            for (int i = 0; i < catagories.Length; i++)
            {
                Bcatagory.BID             = b.BID;
                Bcatagory.CatName         = catagories[i];
                Bcatagory.CatRange        = Int32.Parse(catagoriesRanges[i]);
                Bcatagory.Rangepercentage = ((Bcatagory.CatRange / b.Income) * 100);
                Bcatagory.ExpensesSum     = 0;
                db.ExpenseCatagories.Add(Bcatagory);
                db.SaveChanges();
            }
        }
        public void AddBudgetFromFile(String path,int UserId)
        {
            FileStream fs = new FileStream(path, FileMode.Open);
            StreamReader sr = new StreamReader(fs);
            String name = sr.ReadLine();
            String StartDate = sr.ReadLine();
            String endDate = sr.ReadLine();
            String Income = sr.ReadLine();
            String ExpCatagories = sr.ReadLine();
            String ExpCatagoriesRanges = sr.ReadLine();

            sr.Close();
            fs.Close();

            Budget b = new Budget();
            b.Name = name;
            b.UID = UserId;
            b.StartDate = DateTime.ParseExact(StartDate, "dd/MM/yyyy", null);
            b.EndDate = DateTime.ParseExact(endDate, "dd/MM/yyyy", null);
            b.Income = Int32.Parse(Income);
            b.isCurrent = true;

            MoneyManagementEntities2 db = new MoneyManagementEntities2();
            Budget AlreadySelectedBudget = null;
            foreach (Budget curr in db.Budgets)
            {
                if (curr.isCurrent == true)
                    AlreadySelectedBudget = curr;
            }
            if (AlreadySelectedBudget != null)
            {
                AlreadySelectedBudget.isCurrent = false;
                db.SaveChanges();
            }
            db.Budgets.Add(b);
            db.SaveChanges();

            String [] catagories = ExpCatagories.Split(',');
            String[] catagoriesRanges = ExpCatagoriesRanges.Split(',');
            ExpenseCatagory Bcatagory = new ExpenseCatagory();
            for (int i = 0; i < catagories.Length; i++ )
            {
                Bcatagory.BID = b.BID;
                Bcatagory.CatName = catagories[i];
                Bcatagory.CatRange = Int32.Parse(catagoriesRanges[i]);
                Bcatagory.Rangepercentage = ( (Bcatagory.CatRange / b.Income) * 100 );
                Bcatagory.ExpensesSum = 0;
                db.ExpenseCatagories.Add(Bcatagory);
                db.SaveChanges();
            }
        }
        public void SaveBudget(Budget b, String catagories, String ranges)
        {
            MoneyManagementEntities2 db = new MoneyManagementEntities2();

            db.Budgets.Add(b);
            db.SaveChanges();

            String[] catagoriesList = catagories.Split(',');
            String[] rangesList     = ranges.Split(',');
            Budget   currBudget     = db.Budgets.Find(b.BID);

            for (int i = 0; i < catagoriesList.Length; i++)
            {
                ExpenseCatagory cat = new ExpenseCatagory();
                cat.BID             = b.BID;
                cat.CatName         = catagoriesList[i];
                cat.CatRange        = Int32.Parse(rangesList[i]);
                cat.Rangepercentage = ((cat.CatRange / currBudget.Income) * 100);
                cat.ExpensesSum     = 0;
                db.ExpenseCatagories.Add(cat);
                db.SaveChanges();
            }
        }
        public void SaveBudget(Budget b, String catagories, String ranges)
        {
            MoneyManagementEntities2 db = new MoneyManagementEntities2();
            db.Budgets.Add(b);
            db.SaveChanges();

            String[] catagoriesList = catagories.Split(',');
            String[] rangesList = ranges.Split(',');
            Budget currBudget = db.Budgets.Find(b.BID);
            for (int i = 0; i < catagoriesList.Length; i++)
            {
                ExpenseCatagory cat = new ExpenseCatagory();
                cat.BID = b.BID;
                cat.CatName = catagoriesList[i];
                cat.CatRange = Int32.Parse(rangesList[i]);
                cat.Rangepercentage = ((cat.CatRange / currBudget.Income) * 100);
                cat.ExpensesSum = 0;
                db.ExpenseCatagories.Add(cat);
                db.SaveChanges();
            }
        }