Esempio n. 1
0
        public void CalcIngredientCost(PercentageView model)
        {
            //to get percentage for the ingredient added
            double percRate = model.Percentage / 100;

            using (_fStockRepo)
            {
                var stockItem = _fStockRepo.GetById(model.FeedingStockId);

                if (stockItem != null)
                {
//to get total mass of the ingredient in stock
                    double totalMass = stockItem.NumberOfItems * stockItem.Mass;

//to get amount of mass to remove from stock item according to percentage inputted
                    double massUsed = totalMass * percRate;

//to get number of items that should be left in stock for the ingredient chosen
                    int numItemsLeft = (int)(totalMass - massUsed) / stockItem.Mass;

                    stockItem.NumberOfItems = numItemsLeft;

                    _fStockRepo.Update(stockItem);
//to get how much the ingredient to be used costs
                    double ingCost = (massUsed / stockItem.Mass) * stockItem.ItemPrice;

                    var feedingScheme = _fSchemeRepo.GetById(model.FeedingSchemeId);
                    feedingScheme.TotalFeedingCost += ingCost;

                    _fSchemeRepo.Update(feedingScheme);
                }
            }
        }
Esempio n. 2
0
        public MainForm()
        {
            calculator = new BiorhythmCalculator();
            calculator.Load();


            standardGraphView = new StandardGraphView(calculator);
            percentageView    = new PercentageView(calculator);
            settingsMenu      = new SettingMenu(this.Handle, calculator);

            tabView = new TabView(this.Handle);

            tabView.TabPages.Add(new TabPage(standardGraphView, "Standard"));
            //tabView.TabPages.Add(new TabPage(extraGraphView, "Extra"));
            tabView.TabPages.Add(new TabPage(percentageView, "Percentage"));
            tabView.ToolsSweep.Enabled   = true;
            tabView.ToolsSweep.Occurred += new System.ComponentModel.CancelEventHandler(ToolsSweep_Occurred);

            percentageView.ToolsSweep.Enabled   = true;
            percentageView.ToolsSweep.Occurred += new System.ComponentModel.CancelEventHandler(ToolsSweep_Occurred);

            standardGraphView.ToolsSweep.Enabled   = true;
            standardGraphView.ToolsSweep.Occurred += new System.ComponentModel.CancelEventHandler(ToolsSweep_Occurred);

            tabView.Closed += new EventHandler(OnClose);

            this.Load += new EventHandler(MainForm_Load);
        }
Esempio n. 3
0
        public void DeletePercent(PercentageView model)
        {
            using (var percRepo = new PercentageRepository())
            {
                Percentage feed = percRepo.GetById(model.FeedingSchemeId);

                if (feed != null)
                {
                    percRepo.Delete(feed);
                }
            }
        }
Esempio n. 4
0
 public void AddPercent(PercentageView model)
 {
     using (var percRepo = new PercentageRepository())
     {
         var ingPerc = new Percentage()
         {
             PercentageId    = model.PercentageId,
             FeedingStockId  = _fStockRepo.GetAll().Find(x => x.FeedingStockId == model.FeedingStockId).FeedingStockId,
             PercentageRate  = model.Percentage,
             FeedingSchemeId = _fSchemeRepo.GetAll().Find(p => p.FeedingSchemeId == model.FeedingSchemeId).FeedingSchemeId
         };
         percRepo.Insert(ingPerc);
         CalcIngredientCost(model);
     }
 }
Esempio n. 5
0
        //Method to validate if stock items exist from which a percenatge can be obtained from
        public bool IsAvailable(PercentageView model)
        {
            var available = false;

            FeedingStockBussiness stockItem = new FeedingStockBussiness();

            FeedingStockView stockView = stockItem.GetFeedingStockById(model.FeedingStockId);

            if (stockView != null)
            {
                if (stockView.NumberOfItems >= 1)
                {
                    available = true;
                }
            }

            return(available);
        }
Esempio n. 6
0
        public ActionResult AddPercentage(PercentageView model)
        {
            if (ModelState.IsValid)
            {
                FeedingStockBussiness fStock = new FeedingStockBussiness();
                ViewBag.FeedingStockId = new SelectList(fStock.GetAllFeedingStock(), "FeedingStockId", "ItemName");
                FeedingSchemeBl fScheme = new FeedingSchemeBl();
                ViewBag.FeedingSchemeId = new SelectList(fScheme.GetAllFeedSchemeViews(), "FeedingSchemeId", "SchemeCode");

                PercentageBl percBl = new PercentageBl();

                if (percBl.IsAvailable(model))
                {
                    percBl.AddPercent(model);
                    return(RedirectToAction("GetAllPercentage"));
                }

                return(RedirectToAction("ValidateAvailable"));
            }

            return(View());
        }