private void UpdateAdjustment() { if (_forecastInfo.DatausageEnum == DataUsageEnum.DATA_USAGE1 || _forecastInfo.DatausageEnum == DataUsageEnum.DATA_USAGE2) { foreach (ForecastSite fs in _forecastInfo.ForecastSites) { foreach (ForecastSiteTest ft in fs.SiteTests) { ft.Adjusted = ft.AmountUsed; if (ft.AmountUsed == 0) { try { Consumption cs = GetConsumption(ft.Test.Id, ft); ft.Adjusted = Math.Round(cs.TotalConsumption / cs.NoConsumption, 2, MidpointRounding.ToEven); } catch { ft.Adjusted = ft.AmountUsed; } } if ((ft.InstrumentDowntime > 0 || ft.StockOut > 0) && ft.AmountUsed > 0) { ft.Adjusted = LqtUtil.GetAdjustedVolume(ft.AmountUsed, ft.StockOut + ft.InstrumentDowntime, _forecastInfo.PeriodEnum, GetActiveSiteWorkingDays(ft)); //b } } } } else { foreach (ForecastCategory fc in _forecastInfo.ForecastCategories) { foreach (ForecastCategoryTest ft in fc.CategoryTests) { ft.Adjusted = ft.AmountUsed; if (ft.AmountUsed == 0) { try { Consumption cs = GetConsumption(ft.Product.Id, ft); ft.Adjusted = Math.Round(cs.TotalConsumption / cs.NoConsumption, 2, MidpointRounding.ToEven); } catch { ft.Adjusted = ft.AmountUsed; } } if ((ft.InstrumentDowntime > 0 || ft.StockOut > 0) && ft.AmountUsed > 0) { ft.Adjusted = LqtUtil.GetAdjustedVolume(ft.AmountUsed, ft.StockOut + ft.InstrumentDowntime, _forecastInfo.PeriodEnum, 22);//b } } } } }
private void SaveAsSite() { bool isduplicate = false; ForecastSite fs = new ForecastSite(); IList <ForecastSiteTest> exsistingFst = new List <ForecastSiteTest>(); foreach (ForecastSite efs in _forecastInfo.ForecastSites) { foreach (ForecastSiteTest efst in efs.SiteTests) { exsistingFst.Add(efst); } } foreach (ReportedData rd in _rdata) { if (!rd.HasError) { ForecastSiteTest ft = new ForecastSiteTest(); fs = _forecastInfo.GetForecastSiteBySiteId(rd.Site.Id); if (fs == null) { fs = new ForecastSite(); fs.Site = rd.Site; fs.ForecastInfo = _forecastInfo; _forecastInfo.ForecastSites.Add(fs); } ft.ForecastSite = fs; ft.Test = rd.Test; ft.CDuration = rd.Duration; ft.AmountUsed = rd.Amount; ft.StockOut = rd.StockOut; ft.InstrumentDowntime = rd.InstrumentDownTime; //b ft.Adjusted = rd.Amount; //b rd.Adjusted; ft.DurationDateTime = LqtUtil.DurationToDateTime(ft.CDuration); fs.SiteTests.Add(ft); if (ft.AmountUsed == 0) { Consumption cs = GetConsumption(ft.Test.Id, ft); if (cs.NoConsumption != 0) { ft.Adjusted = Math.Round(cs.TotalConsumption / cs.NoConsumption, 2, MidpointRounding.ToEven); } } if (ft.StockOut > 0) { int days = ft.StockOut; decimal workingday = GetActiveSiteWorkingDays(ft); if (days >= workingday) { days = 0; ft.StockOut = 0; } if (days >= 0) { ft.StockOut = days; } } if ((ft.InstrumentDowntime > 0 || ft.StockOut > 0) && ft.AmountUsed > 0) { ft.Adjusted = LqtUtil.GetAdjustedVolume(ft.AmountUsed, ft.StockOut + ft.InstrumentDowntime, _forecastInfo.PeriodEnum, GetActiveSiteWorkingDays(ft)); } foreach (ForecastSiteTest efst in exsistingFst) { isduplicate = false; if (ft.ForecastSite.Site.Region == efst.ForecastSite.Site.Region) { if (ft.ForecastSite.Site == efst.ForecastSite.Site) { if (ft.Test == efst.Test && ft.DurationDateTime == efst.DurationDateTime) { isduplicate = true; break; } } } } foreach (ForecastSiteTest fst in fs.SiteTests) { isduplicate = false; if (ft.ForecastSite.Site.Region == fst.ForecastSite.Site.Region) { if (ft.ForecastSite.Site == fst.ForecastSite.Site) { if (ft.Test == fst.Test && ft.DurationDateTime == fst.DurationDateTime) { isduplicate = true; break; } } } } if (!isduplicate) { fs.SiteTests.Add(ft); } } } }