public PopupCollectionModelControl(Panel vPanel, Panel hPanel, Form popUpForm, SalesAndCollectionControl salesAndCollectionControl, string dealerCode) { _popUpForm = popUpForm; _vPanel = vPanel; _hPanel = hPanel; _salesAndCollectionControl = salesAndCollectionControl; _dealerList = DealerManager.GetAllDealers(); if (string.IsNullOrEmpty(dealerCode) || dealerCode.ToLower().Equals("any")) { _dealer = null; } else { _dealer = DealerManager.FindDealer(dealerCode); } InitializeComponent(); this.Load += new System.EventHandler(this.PopupModelControl_Load); }
private void BindAllFilters() { var filteredSalesAndCollections = new List <SalesAndCollectionModel>(); if (string.IsNullOrEmpty(CB_SAC_DealerCode.Text)) { CB_SAC_DealerCode.Text = "Any"; CB_SAC_DealerCode.Items.Add("Any"); CB_SAC_DealerCode.Items.AddRange(_dealerList.Select(x => x.Code).ToArray()); } else if (CB_SAC_DealerCode.Items.Count <= 1) { CB_SAC_DealerCode.Items.Add("Any"); CB_SAC_DealerCode.Items.AddRange(_dealerList.Select(x => x.Code).ToArray()); } if (CB_SAC_DealerCode.Text.ToLower().Equals("any")) { _dealer = null; } else { if (!string.IsNullOrEmpty(CB_SAC_DealerCode.Text)) { _dealer = DealerManager.FindDealer(CB_SAC_DealerCode.Text); } } if (_dealer != null) { CB_SAC_DealerCode.Text = _dealer.Code; LSAC_PartyName.Visible = true; LSAC_PartyAddress.Visible = true; LSAC_PartyContact.Visible = true; TB_SAC_PartyName.Visible = true; TB_SAC_PartyAddress.Visible = true; TB_SAC_PartyContact.Visible = true; TB_SAC_PartyName.Text = _dealer.DealerName; TB_SAC_PartyAddress.Text = _dealer.Address; TB_SAC_PartyContact.Text = _dealer.Contact; //TB_SAC_PartyName.Enabled = false; //TB_SAC_PartyAddress.Enabled = false; //TB_SAC_PartyContact.Enabled = false; } else { LSAC_PartyName.Visible = false; LSAC_PartyAddress.Visible = false; LSAC_PartyContact.Visible = false; TB_SAC_PartyName.Visible = false; TB_SAC_PartyAddress.Visible = false; TB_SAC_PartyContact.Visible = false; TB_SAC_PartyName.Text = ""; TB_SAC_PartyAddress.Text = ""; TB_SAC_PartyContact.Text = ""; } if (CKB_GroupBy.Checked) { if (CB_SAC_DealerCode.Text.ToLower().Equals("any")) { filteredSalesAndCollections = SalesAndCollectionManager.EverydaySalesAndCollections(); } else { filteredSalesAndCollections = SalesAndCollectionManager.EverydaySalesAndCollections(CB_SAC_DealerCode.Text); } } else { if (CB_SAC_DealerCode.Text.ToLower().Equals("any")) { filteredSalesAndCollections = SalesAndCollectionManager.GetAllSalesAndCollections(); } else { filteredSalesAndCollections = SalesAndCollectionManager.GetSalesAndCollections(CB_SAC_DealerCode.Text); } } if (filteredSalesAndCollections.Count > 0) { if (!string.IsNullOrEmpty(TB_SAC_Search.Text)) { filteredSalesAndCollections = SearchResult(TB_SAC_Search.Text, filteredSalesAndCollections); } if (CB_SAC_TimePeriod.Text.Equals("Custom")) { filteredSalesAndCollections = filteredSalesAndCollections.Where(x => x.Date >= DTP_SAC_FromDate.Value && x.Date <= DTP_SAC_ToDate.Value).ToList(); } else if (CB_SAC_TimePeriod.Text.Equals("Today")) { DTP_SAC_FromDate.Value = DateTime.Today; DTP_SAC_ToDate.Value = DTP_SAC_FromDate.Value; filteredSalesAndCollections = filteredSalesAndCollections.Where(x => x.Date > DTP_SAC_FromDate.Value.AddDays(-1) && x.Date <= DTP_SAC_ToDate.Value).ToList(); } else if (CB_SAC_TimePeriod.Text.Equals("Yesterday")) { DTP_SAC_FromDate.Value = DateTime.Today.AddDays(-1); DTP_SAC_ToDate.Value = DTP_SAC_FromDate.Value; filteredSalesAndCollections = filteredSalesAndCollections.Where(x => x.Date > DTP_SAC_FromDate.Value.AddDays(-1) && x.Date <= DTP_SAC_ToDate.Value).ToList(); } else if (CB_SAC_TimePeriod.Text.Equals("Weekly")) { DTP_SAC_FromDate.Value = DateTime.Today.AddDays(-7); DTP_SAC_ToDate.Value = DateTime.Today; filteredSalesAndCollections = filteredSalesAndCollections.Where(x => x.Date > DTP_SAC_FromDate.Value && x.Date <= DTP_SAC_ToDate.Value).ToList(); } else if (CB_SAC_TimePeriod.Text.Equals("Monthly")) { DTP_SAC_FromDate.Value = DateTime.Today.AddDays(-30); DTP_SAC_ToDate.Value = DateTime.Today; filteredSalesAndCollections = filteredSalesAndCollections.Where(x => x.Date > DTP_SAC_FromDate.Value && x.Date <= DTP_SAC_ToDate.Value).ToList(); } else if (CB_SAC_TimePeriod.Text.Equals("This Month")) { DateTime date = DateTime.Today; DTP_SAC_FromDate.Value = new DateTime(date.Year, date.Month, 1); DTP_SAC_ToDate.Value = DTP_SAC_FromDate.Value.AddMonths(1).AddDays(-1); filteredSalesAndCollections = filteredSalesAndCollections.Where(x => x.Date >= DTP_SAC_FromDate.Value && x.Date <= DTP_SAC_ToDate.Value).ToList(); } else if (CB_SAC_TimePeriod.Text.Equals("Last Month")) { DateTime date = DateTime.Today; DTP_SAC_FromDate.Value = new DateTime(date.Year, date.AddMonths(-1).Month, 1); DTP_SAC_ToDate.Value = DTP_SAC_FromDate.Value.AddMonths(1).AddDays(-1); filteredSalesAndCollections = filteredSalesAndCollections.Where(x => x.Date >= DTP_SAC_FromDate.Value && x.Date <= DTP_SAC_ToDate.Value).ToList(); } else if (CB_SAC_TimePeriod.Text.Equals("Default")) { DTP_SAC_FromDate.Value = new DateTime(2020, 1, 1); DTP_SAC_ToDate.Value = DateTime.Today; filteredSalesAndCollections = filteredSalesAndCollections.Where(x => x.Date >= DTP_SAC_FromDate.Value && x.Date <= DTP_SAC_ToDate.Value).ToList(); } var allDates = filteredSalesAndCollections.Select(x => x.Date).Distinct().ToList(); allDates.RemoveAll(item => item == null); if (CKB_Ascending.Checked) { allDates = allDates.OrderBy(x => x.Value).ToList(); } else { allDates = allDates.OrderByDescending(x => x.Value).ToList(); } var mapSalesAndCollections = new List <SalesAndCollectionModel>(); foreach (var date in allDates) { var thatDaysHistory = filteredSalesAndCollections.Where(x => x.Date == date).ToList(); var allDealerForThatDay = thatDaysHistory.Select(x => x.DealerCode).Distinct().ToList(); foreach (var dealerCode in allDealerForThatDay) { var dealerHistoryForThatDay = thatDaysHistory.Where(x => x.DealerCode.Equals(dealerCode)).ToList(); mapSalesAndCollections.AddRange(dealerHistoryForThatDay); } } filteredSalesAndCollections = mapSalesAndCollections; int count = 1; foreach (var soc in filteredSalesAndCollections) { soc.Sl = (count++).ToString(); } } if (filteredSalesAndCollections != null) { BindDataTable(filteredSalesAndCollections); _tempedSalesAndCollections = filteredSalesAndCollections; } isTimePeriodChanged = false; }