/// <summary> /// The users wishes to save the filter. /// </summary> void btnSaveFilter_Click(object sender, EventArgs e) { btnSaveFilter.DisableServerSideValidation(); if (Page.IsValid) { Facade.ITrafficSheetFilter facTrafficSheetFilter = new Facade.Traffic(); var user = (Entities.CustomPrincipal)Page.User; Entities.TrafficSheetFilter filter = null; var isUpdate = false; if (cboFilters.SelectedValue != "0" && cboFilters.SelectedItem.Text == txtFilterName.Text) { // We are going to update the old version of the filter. isUpdate = true; filter = facTrafficSheetFilter.GetForTrafficSheetFilterId(Convert.ToInt32(cboFilters.SelectedValue)); } else { filter = new Entities.TrafficSheetFilter(user.IdentityId) { FilterName = txtFilterName.Text }; } filter.FilterOutExcludedPoints = false; filter.TrafficSheetGrouping = eTrafficSheetGrouping.None; filter.TrafficSheetSorting = eTrafficSheetSorting.EarliestLeg; this.PopulateFilter(filter); Facade.ITrafficArea facTrafficArea = new Facade.Traffic(); if (isUpdate) { ((Facade.ITrafficSheetFilter)facTrafficArea).Update(filter, user.UserName); } else { filter.FilterId = ((Facade.ITrafficSheetFilter)facTrafficArea).Create(filter, user.UserName); } PopulateFilterList(); cboFilters.ClearSelection(); SelectItem(cboFilters.Items, filter.FilterId); Filter = filter; SetCookie(); ReturnValue = "filterupdated"; } }
/// <summary> /// The user has selected one of their previously saved filters. /// </summary> void cboFilters_SelectedIndexChanged(object sender, EventArgs e) { int trafficSheetFilterId = Convert.ToInt32(cboFilters.SelectedValue); if (trafficSheetFilterId == 0) { // This is the "blank filter" setting. cboControlArea.ClearSelection(); cboTrafficAreas.ClearSelection(); cboDepot.SelectedIndex = 0; txtFilterName.Text = string.Empty; } else { // Load the filter and configure the textbox to allow saving a new version Facade.ITrafficSheetFilter facTrafficSheetFilter = new Facade.Traffic(); Entities.TrafficSheetFilter selectedFilter = facTrafficSheetFilter.GetForTrafficSheetFilterId(trafficSheetFilterId); BindTrafficSheetFilter(selectedFilter); } }
/// <summary> /// The users wishes to save the filter. /// </summary> void btnSaveFilter_Click(object sender, EventArgs e) { btnSaveFilter.DisableServerSideValidation(); if (Page.IsValid) { Facade.ITrafficSheetFilter facTrafficSheetFilter = new Facade.Traffic(); Entities.CustomPrincipal user = (Entities.CustomPrincipal)Page.User; Entities.TrafficSheetFilter filter = null; bool isUpdate = false; if (dteStartDate.SelectedDate != null && dteEndDate.SelectedDate == null) { dteEndDate.SelectedDate = ((DateTime)dteStartDate.SelectedDate).AddDays(1).Add(new TimeSpan(23, 59, 59)); } if (cboFilters.SelectedValue != "0" && cboFilters.SelectedItem.Text == txtFilterName.Text) { // We are going to update the old version of the filter. isUpdate = true; filter = facTrafficSheetFilter.GetForTrafficSheetFilterId(Convert.ToInt32(cboFilters.SelectedValue)); } else { filter = new Entities.TrafficSheetFilter(user.IdentityId); filter.FilterName = txtFilterName.Text; } filter.FilterStartDate = (DateTime)dteStartDate.SelectedDate; filter.FilterEnddate = (DateTime)dteEndDate.SelectedDate; // Configure the filter filter.ControlAreaId = Convert.ToInt32(cboControlArea.SelectedValue); filter.TrafficAreaIDs.Clear(); foreach (ListItem item in cboTrafficAreas.Items) { if (item.Selected) { filter.TrafficAreaIDs.Add(Convert.ToInt32(item.Value)); } } filter.FilterOutExcludedPoints = false; filter.TrafficSheetGrouping = eTrafficSheetGrouping.None; filter.TrafficSheetSorting = eTrafficSheetSorting.EarliestLeg; filter.JobStates.Clear(); foreach (ListItem item in chkJobStates.Items) { if (item.Selected) { filter.JobStates.Add(Enum.Parse(typeof(eJobState), item.Value.Replace(" ", ""))); } } filter.BusinessTypes.Clear(); foreach (ListItem li in cblBusinessType.Items) { if (li.Selected) { filter.BusinessTypes.Add((int)int.Parse(li.Value)); } } filter.DepotId = int.Parse(cboDepot.SelectedValue); filter.OnlyShowJobsWithDemurrage = chkOnlyShowJobsWithDemurrage.Checked; filter.OnlyShowJobsWithDemurrageAwaitingAcceptance = chkOnlyShowJobsWithDemurrageAwaitingAcceptance.Checked; filter.OnlyShowJobsWithPCVs = chkOnlyShowJobsWithPCVs.Checked; filter.OnlyShowMyJobs = false; Facade.ITrafficArea facTrafficArea = new Facade.Traffic(); if (isUpdate) { ((Facade.ITrafficSheetFilter)facTrafficArea).Update(filter, user.UserName); } else { filter.FilterId = ((Facade.ITrafficSheetFilter)facTrafficArea).Create(filter, user.UserName); } SetFilter(); PopulateFilterList(); cboFilters.ClearSelection(); SelectItem(cboFilters.Items, filter.FilterId); this.ReturnValue = "refresh"; this.Close(); } }