private void butSave_Click(object sender, EventArgs e) { foreach (ReportedData rd in _rdata) { ForecastSiteProduct fp = new ForecastSiteProduct(); ForecastSite fs = _forecastInfo.GetForecastSiteBySiteId(rd.Site.Id); if (fs == null) { fs = new ForecastSite(); fs.Site = rd.Site; fs.ForecastInfo = _forecastInfo; _forecastInfo.ForecastSites.Add(fs); } fp.ForecastSite = fs; fp.Product = rd.Product; fp.CDuration = rd.Duration; fp.AmountUsed = rd.Amount; fp.StockOut = rd.StockOut; fp.InstrumentDowntime = rd.InstrumentDownTime; //b fp.Adjusted = rd.Amount; //b fs.SiteProducts.Add(fp); } try { DataRepository.SaveOrUpdateForecastInfo(_forecastInfo); MessageBox.Show("Consumption data imported and saved successfully.", "Importing", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } catch { MessageBox.Show("Error: Unable to imported and saved consumption data.", "Importing", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void lbtRemoveNrsite_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { if (lvNrSite.SelectedItems.Count > 0) { int id = (int)lvNrSite.SelectedItems[0].Tag; ForecastNRSite fp; if (id > 0) { fp = _activeFSite.GetNReportedSite(id); } else { fp = _activeFSite.NoneReportedSites[lvNrSite.SelectedItems[0].Index]; } _activeFSite.NoneReportedSites.Remove(fp); ForecastSite fs = _forecastInfo.GetForecastSiteBySiteId(fp.NReportedSite.Id); _forecastInfo.ForecastSites.Remove(fs); DataRepository.DeleteForecastSite(fs);//b BindNoneReportedSite(); BindSites(); OnForecastInfoDataChanged(); } }
private void lbtAddsiteall_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { for (int i = 0; i < lvSiteAll.Items.Count; i++) { lvSiteAll.Items[i].Selected = true; lvSiteAll.Select(); } int len = lvSiteAll.SelectedItems.Count; for (int i = 0; i < len; i++) { int siteid = (int)lvSiteAll.SelectedItems[i].Tag; ForecastSite fs = new ForecastSite(); fs.Site = DataRepository.GetSiteById(siteid); fs.ForecastInfo = _forecastInfo; _forecastInfo.ForecastSites.Add(fs); } BindSites(); BindForecastSite(); ShowSummary(); lbtAddsiteall.Enabled = false; lbtAddsite.Enabled = false; }
private void lbtRemovesite_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { if (lvSite.SelectedItems.Count > 0) { int id = (int)lvSite.SelectedItems[0].Tag; ForecastSite fs = _forecastInfo.GetForecastSite(id); if (id > 0) { fs = _forecastInfo.GetForecastSite(id); } else { fs = _forecastInfo.ForecastSites[lvSite.SelectedItems[0].Index]; } _forecastInfo.ForecastSites.Remove(fs); _activeFSite = null; DataRepository.DeleteForecastSite(fs);//b BindSites(); BindForecastSite(); BindForecastSiteProduct(); txtSitename.Text = ""; //b txtPcount.Text = ""; //b } }
private void lbtRemovesite_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { bool haschild = false; if (lvSite.SelectedItems.Count > 0)//if selected { int id = (int)lvSite.SelectedItems[0].Tag; if (!lvSite.SelectedItems[0].Text.Contains("..."))//if not non reported { ForecastSite fs; ForecastSite nfs = _activeFSite;//b if (id > 0) { fs = _forecastInfo.GetForecastSite(id); } else { fs = _forecastInfo.ForecastSites[lvSite.SelectedItems[0].Index]; } if (fs.NoneReportedSites.Count > 0) { //int count = fs.NoneReportedSites.Count; //ForecastSite site = new ForecastSite(); //for (int i = count - 1; i >= count - 1 && count > 0; i--) //{ // site = _forecastInfo.GetForecastSiteBySiteId(fs.NoneReportedSites[count - 1].NReportedSite.Id); // _activeFSite.NoneReportedSites.Remove(fs.NoneReportedSites[count - 1]); // DataRepository.CloseSession(); // DataRepository.DeleteForecastSite(site);//b // count--; haschild = true; //} MessageBox.Show("You have first to Remove Non Reported Site .", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (!haschild) { _forecastInfo.ForecastSites.Remove(fs); DataRepository.DeleteForecastSite(fs);//b _activeFSite = null; BindSites(); BindForecastProduct(); BindNoneReportedSite(); OnForecastInfoDataChanged(); txtSitename.Text = ""; //b txtPcount.Text = ""; //b //if(haschild) //this.Parent.Parent.Parent.Dispose(); } } } }
private void lbtAddsite_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { int len = lvSiteAll.SelectedItems.Count; for (int i = 0; i < len; i++) { int siteid = (int)lvSiteAll.SelectedItems[i].Tag; ForecastSite fs = new ForecastSite(); fs.Site = DataRepository.GetSiteById(siteid); fs.ForecastInfo = _forecastInfo; _forecastInfo.ForecastSites.Add(fs); } BindSites(); BindForecastSite(); }
public static void DeleteForecastSite(ForecastSite t) { DaoFactory.GetDaoFactory().CreateForecastSiteDao().Delete(t); }
//public static IList<ForecastSite> GetAllForecasSite() //{ // return DaoFactory.GetDaoFactory()().GetAll(); //} //public static GetById(int id) //{ // return DaoFactory.GetDaoFactory()().GetById(id); //} public static void SaveOrUpdateForecastSite(ForecastSite fsite) { DaoFactory.GetDaoFactory().CreateForecastSiteDao().SaveOrUpdate(fsite); }
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); } } } }
private void butImport_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtFilename.Text.Trim())) { return; } try { DataSet ds = LqtUtil.ReadExcelFileforecast(txtFilename.Text, _noColumn); _rdata = GetDataRow(ds); bool haserror = false; lvImport.BeginUpdate(); lvImport.Items.Clear(); ForecastSite fs = new ForecastSite(); ForecastCategorySite fcatsite = new ForecastCategorySite(); bool isduplicate = false; ForecastSite efs = new ForecastSite();//existing IList <ForecastSiteTest> existingFst = new List <ForecastSiteTest>(); foreach (ForecastSite efss in _forecastInfo.ForecastSites) { foreach (ForecastSiteTest efst in efss.SiteTests) { existingFst.Add(efst); } } foreach (ReportedData rd in _rdata) { ListViewItem li = new ListViewItem(rd.RowNo.ToString()); if (_forecastInfo.DatausageEnum == DataUsageEnum.DATA_USAGE3) { li.SubItems.Add(rd.CategoryName); } else { li.SubItems.Add(rd.RegionName); li.SubItems.Add(rd.SiteName); } li.SubItems.Add(rd.TestName); if (!LqtUtil.IsDateTime(rd.Duration)) { try { DateTime dd = LqtUtil.DurationToDateTime(rd.Duration); if (rd.Duration.StartsWith("Q") && (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Yearly)) { rd.Duration = dd.Year.ToString(); li.SubItems.Add(LqtUtil.DatetimeToDurationStr(_forecastInfo.PeriodEnum, dd)); } else { li.SubItems.Add(rd.Duration); } } catch { li.SubItems.Add(rd.Duration); rd.HasError = true; } } else { string datestr = LqtUtil.DatetimeToDurationStr(_forecastInfo.PeriodEnum, DateTime.Parse(rd.Duration)); if (!rd.Duration.StartsWith("Q")) { rd.Duration = LqtUtil.DatetimeToDurationStr(_forecastInfo.PeriodEnum, DateTime.Parse(rd.Duration)); if (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Yearly) { li.SubItems.Add(datestr); } else { li.SubItems.Add(rd.Duration); } } else { { li.SubItems.Add(datestr); } } } li.SubItems.Add(rd.Amount.ToString()); li.SubItems.Add(rd.StockOut.ToString()); li.SubItems.Add(rd.InstrumentDownTime.ToString()); if (rd.HasError == true && rd.ErrorDescription == "") { rd.ErrorDescription = " Test Performed Required "; } if (LqtUtil.validDate(rd.Duration, _forecastInfo.PeriodEnum)) { rd.HasError = true; } //check if stockout and instrument downtime is less than site working days try { if (rd.Site != null) { if (!LqtUtil.ValidDownTime(rd.StockOut + rd.InstrumentDownTime, _forecastInfo.PeriodEnum, rd.Site.WorkingDays)) { rd.HasError = true; rd.ErrorDescription += " Sum of Stockout and Instrument Downtime can not be greater than site working days"; } } } catch { } li.SubItems.Add(rd.ErrorDescription.ToString()); //add to forecast site test if (!rd.HasError && _forecastInfo.DatausageEnum != DataUsageEnum.DATA_USAGE3) { 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; if (!LqtUtil.IsDateTime(rd.Duration)) { ft.CDuration = rd.Duration; ft.DurationDateTime = LqtUtil.DurationToDateTime(rd.Duration); } else { ft.CDuration = LqtUtil.DatetimeToDurationStr(_forecastInfo.PeriodEnum, DateTime.Parse(rd.Duration)); ft.DurationDateTime = DateTime.Parse(rd.Duration); } ft.AmountUsed = rd.Amount; ft.StockOut = rd.StockOut; ft.InstrumentDowntime = rd.InstrumentDownTime;//b ft.Adjusted = rd.Amount; 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; } } foreach (ForecastSiteTest efst in existingFst) { 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); } } //end adding //add by category if (!rd.HasError && _forecastInfo.DatausageEnum == DataUsageEnum.DATA_USAGE3) { ForecastCategory fcat = new ForecastCategory(); ForecastCategoryTest ft = new ForecastCategoryTest(); // fcat = DataRepository.GetForecastCategoryByName(_forecastInfo.Id, rd.CategoryName); fcat = _forecastInfo.GetForecastCategorybyname(rd.CategoryName); if (fcat == null) { fcat = new ForecastCategory(); fcat.CategoryName = rd.CategoryName; fcat.ForecastInfo = _forecastInfo; _forecastInfo.ForecastCategories.Add(fcat); } ft = fcat.GetFCatTest(rd.Test.Id, rd.Duration); isduplicate = false; if (ft == null) { ft = new ForecastCategoryTest(); } else { isduplicate = true; } ft.Category = fcat; ft.Test = rd.Test; // ft.CDuration = rd.Duration; ft.AmountUsed = rd.Amount; ft.StockOut = rd.StockOut; ft.InstrumentDowntime = rd.InstrumentDownTime;//b // ft.Adjusted = rd.Adjusted; // ft.DurationDateTime = LqtUtil.DurationToDateTime(ft.CDuration); if (!LqtUtil.IsDateTime(rd.Duration)) { ft.CDuration = rd.Duration; ft.DurationDateTime = LqtUtil.DurationToDateTime(rd.Duration); } else { ft.CDuration = LqtUtil.DatetimeToDurationStr(_forecastInfo.PeriodEnum, DateTime.Parse(rd.Duration)); ft.DurationDateTime = DateTime.Parse(rd.Duration); } if (ft.StockOut > 0) { int days = ft.StockOut; decimal workingday = 22; if (days >= workingday) { days = 0; ft.StockOut = 0; } if (days >= 0) { ft.StockOut = days; } } if (!isduplicate) { fcat.CategoryTests.Add(ft); } } //end category adding if (rd.HasError) { li.BackColor = Color.Red; _error++; } else if (isduplicate) { li.BackColor = Color.Yellow; _error++; } else { _count++; } lvImport.Items.Add(li); } sort(); lvImport.EndUpdate(); butClear.Enabled = true; butSave.Enabled = true; } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message, "Importing", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ProcessBySite() { foreach (ListViewItem li in lsvSites.CheckedItems) { ForlabSite site = (ForlabSite)li.Tag; fsite = _forecastInfo.GetForecastSiteBySiteId(site.Id); if (fsite == null) { fsite = new ForecastSite(); fsite.Site = site; fsite.ForecastInfo = _forecastInfo; _forecastInfo.ForecastSites.Add(fsite); } _selectedProductids = fsite.GetSelectedTestId(); int month = _forecastInfo.StartDate.Month; foreach (ListViewItem l in lvProductAll.SelectedItems) { int noperiod = NoRPeriod(); MasterProduct pro = (MasterProduct)l.Tag; if (!IsTestSelected(pro.Id)) { int year = _forecastInfo.StartDate.Year; DateTime lastd = _forecastInfo.StartDate; int quar = LqtUtil.GetQuarter(_forecastInfo.StartDate); int quartermonth = 1; IList <ForecastSiteProduct> historicalSiteProduct = DataRepository.GetHistoricalProduct(_forecastInfo.Period, _forecastInfo.Methodology, _forecastInfo.DataUsage, pro.Id, fsite.Site.Id, _forecastInfo.StartDate, 0); TimeSpan diff = new TimeSpan();; if (historicalSiteProduct.Count > 0) { DateTime lasthistorydate = historicalSiteProduct[0].DurationDateTime.Value;//sd DateTime startdate = _forecastInfo.StartDate; diff = startdate.Subtract(lasthistorydate); if (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Bimonthly) { int noofemptyM = (((int)diff.TotalDays / 30) * 2) - 1; if (noofemptyM >= 1) { if (noperiod > noofemptyM) { noHistoryRecord = noperiod - noofemptyM; noperiod = noofemptyM; getHistory = true; } else { getHistory = false; } } else { noHistoryRecord = noperiod; getHistory = true; noperiod = 0; } } else if (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Monthly) { int noofemptyM = ((int)diff.TotalDays / 30) - 1; if (noofemptyM >= 1) { if (noperiod > noofemptyM) { noHistoryRecord = noperiod - noofemptyM; noperiod = noofemptyM; getHistory = true; } else { getHistory = false; } } else { noHistoryRecord = noperiod; getHistory = true; noperiod = 0; } } else if (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Quarterly) { int noofemptyQ = ((int)diff.TotalDays / (30 * 3)) - 1; if (noofemptyQ >= 1) { if (noperiod > noofemptyQ) { noHistoryRecord = noperiod - noofemptyQ; noperiod = noofemptyQ; getHistory = true; } else { getHistory = false; } } else { noofemptyQ = noperiod; noHistoryRecord = noperiod; getHistory = true; noperiod = 0; } } else { int noofemptyY = ((int)diff.TotalDays / 365) - 1; if (noofemptyY >= 1) { if (noperiod > noofemptyY) { noHistoryRecord = noperiod - noofemptyY; noperiod = noofemptyY; getHistory = true; } else { getHistory = false; } } else { noHistoryRecord = noperiod; getHistory = true; noperiod = 0; } } } else { getHistory = false; } if (getHistory) { AddForecastProductHistory(pro.Id, fsite.Site.Id, _forecastInfo.StartDate); } for (int x = 1; x <= noperiod; x++) { ForecastSiteProduct sp = new ForecastSiteProduct(); sp.Product = pro; sp.ForecastSite = fsite; sp.AmountUsed = 1; sp.Adjusted = 1; if (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Bimonthly) { //int y = month - x; //if (y <= 0) // y = 12 + y; lastd = lastd.AddMonths(-2); sp.CDuration = LqtUtil.Months[lastd.Month - 1] + "-" + lastd.Year.ToString(); DateTime Duration = new DateTime(lastd.Year, lastd.Month, 1); sp.DurationDateTime = Duration; } else if (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Monthly) { //int y = month - x; //if (y <= 0) // y = 12 + y; lastd = lastd.AddMonths(-1); sp.CDuration = LqtUtil.Months[lastd.Month - 1] + "-" + lastd.Year.ToString(); DateTime Duration = new DateTime(lastd.Year, lastd.Month, 1); sp.DurationDateTime = Duration; } else if (_forecastInfo.PeriodEnum == ForecastPeriodEnum.Quarterly) { if (quar == 1) { quar = 4; year--; } else { quar--; } sp.CDuration = String.Format("{0}-Qua{1}", year, quar); if (quar == 1) { quartermonth = 1; } else if (quar == 2) { quartermonth = 4; } else if (quar == 3) { quartermonth = 7; } else { quartermonth = 10; } DateTime Duration = new DateTime(year, quartermonth, 1); sp.DurationDateTime = Duration; } else { year--; sp.CDuration = year.ToString(); DateTime Duration = new DateTime(year, 1, 1); sp.DurationDateTime = Duration; } fsite.SiteProducts.Add(sp); } } } // _forecastInfo.ForecastSites.Add(fsite); } }