Пример #1
0
        private void LoadCommunicationStatuses()
        {
            var communicationsStatuses = Enum.GetValues(typeof(MWFCommunicationStatusEnum)).Cast <MWFCommunicationStatusEnum>().Select(s => new
            {
                Text  = MWF_Instruction.GetCommunicationStatusDescription(s),
                Value = (int)s
            }).Distinct();

            this.CommunicationStatusCheckBoxList.DataSource = communicationsStatuses;
            this.CommunicationStatusCheckBoxList.DataBind();
        }
Пример #2
0
        public void SendMessage(IEnumerable <int> driverIDs, DateTime?messageDateTime, int?pointID, int?heJobID, string message)
        {
            if (driverIDs == null || !driverIDs.Any())
            {
                throw new ApplicationException("No driver IDs passed to SendMessage web service method");
            }

            var instructionsToCommunicate = new Dictionary <MWF_Instruction, MWFDeviceDataActionEnum>(driverIDs.Count());

            using (var uow = DIContainer.CreateUnitOfWork())
            {
                var jobRepo = DIContainer.CreateRepository <IMWF_JobRepository>(uow);

                foreach (var driverID in driverIDs)
                {
                    Models.MWF_Job job = null;

                    if (heJobID.HasValue)
                    {
                        job = jobRepo.FindForHaulierEnterpriseJob(heJobID.Value);
                    }

                    if (job == null)
                    {
                        job = new MWF_Job {
                            InternalID = new Guid(), Title = "Message", HEJobID = heJobID
                        };
                        jobRepo.Add(job);
                    }

                    var instruction = new MWF_Instruction
                    {
                        InternalID          = Guid.Empty,
                        IsChanged           = true,
                        InstructionType     = MWFInstructionTypeEnum.OrderMessage,
                        ArriveDateTime      = (messageDateTime ?? DateTime.Today).ToLocalTime(),
                        PointID             = pointID,
                        DriverID            = driverID,
                        CommunicationStatus = MWFCommunicationStatusEnum.NewInformationNeedsCommunicating,
                    };
                    Facade.MWF.ICommunication facComm = new Facade.MWF.Communication();

                    instruction.DeviceData = facComm.GenerateDeviceDataForNonOrderInstruction(job.ID, job.Title, instruction.InstructionType, instruction.PointID, instruction.ArriveDateTime, instruction.DepartDateTime, 1, "ADD", message);

                    job.Instructions.Add(instruction);
                    instructionsToCommunicate.Add(instruction, MWFDeviceDataActionEnum.Add);
                }

                uow.SaveChanges();

                MobileWorkerFlow.MWFServicesCommunication.Client.CommunicateInstructions(new Guid(Orchestrator.Globals.Configuration.BlueSphereCustomerId), instructionsToCommunicate);
                uow.SaveChanges();
            }
        }
Пример #3
0
        private void LoadStatuses()
        {
            var statuses = Enum.GetValues(typeof(MWFStatusEnum)).Cast <MWFStatusEnum>()
                           .Where(s => (((int)s == (int)MWFStatusEnum.Complete) || ((int)s == (int)MWFStatusEnum.OnSite) || ((int)s == (int)MWFStatusEnum.Drive) || ((int)s == (int)MWFStatusEnum.Unknown)))
                           .Select(s => new
            {
                Text  = MWF_Instruction.GetStatusDescription(s),
                Value = (int)s
            }).Distinct();

            this.StatusCheckboxList.DataSource = statuses;
            this.StatusCheckboxList.DataBind();
        }
Пример #4
0
        /// <summary>
        /// Return an instruction id based on a MobileApplicationId
        /// </summary>
        private int?GetInstructionId(IUnitOfWork uow, Guid madId)
        {
            IMWF_InstructionRepository mwf_InstructionRepo = DIContainer.CreateRepository <IMWF_InstructionRepository>(uow);

            MWF_Instruction instruction = mwf_InstructionRepo.GetForMobileApplicationDataId(madId);

            if (instruction != null)
            {
                return(instruction.HEInstructionID);
            }
            else
            {
                return(null);
            }
        }
Пример #5
0
        private object GetInstructionsGridData()
        {
            Facade.IPoint   facPoint              = new Facade.Point();
            Facade.Resource facDriver             = new Facade.Resource();
            var             signatureImageBaseUri = Utilities.GetSignatureImageBaseUri();

            using (var uow = DIContainer.CreateUnitOfWork())
            {
                var repo         = DIContainer.CreateRepository <IMWF_InstructionRepository>(uow);
                var instructions = repo.GetAll();

                // Apply filters
                if (!string.IsNullOrEmpty(DriverPicker.SelectedValue))
                {
                    int selectedDriverID = int.Parse(DriverPicker.SelectedValue);
                    instructions = instructions.Where(i => i.Driver.ResourceID == selectedDriverID);
                }
                if (!string.IsNullOrEmpty(VehiclePicker.SelectedValue))
                {
                    string selectedVehicleReg = VehiclePicker.SelectedValue;
                    instructions = instructions.Where(i => i.VehicleReg == selectedVehicleReg);
                }

                var statusIDs = Utilities.ExtractCheckBoxListValues(StatusCheckboxList);
                if (statusIDs.Count > 0)
                {
                    instructions = instructions.Where(e => statusIDs.Contains((int)e.Status));
                }

                // Comm status filter
                var communicationStatusIDs = Utilities.ExtractCheckBoxListValues(CommunicationStatusCheckBoxList);
                if (communicationStatusIDs.Count > 0)
                {
                    instructions = instructions.Where(e => communicationStatusIDs.Contains((int)e.CommunicationStatus));
                }

                if (ArrivalFrom.SelectedDate != null && ArrivalTo.SelectedDate != null)
                {
                    instructions = instructions.Where(i => i.ArriveDateTime >= ArrivalFrom.SelectedDate.Value &&
                                                      i.ArriveDateTime <= ArrivalTo.SelectedDate.Value);
                }

                if (ArrivalFrom.SelectedDate != null && ArrivalTo.SelectedDate == null)
                {
                    instructions = instructions.Where(i => i.ArriveDateTime >= ArrivalFrom.SelectedDate.Value);
                }

                if (!string.IsNullOrEmpty(txtSearchField.Text))
                {
                    var searchTextAsStr = txtSearchField.Text.Trim();
                    var searchTextAsInt = Utilities.ParseNullable <int>(txtSearchField.Text);

                    if (searchTextAsInt.HasValue)
                    {
                        instructions = instructions.Where(i => i.Job.Title.Contains(txtSearchField.Text.Trim()) || i.Job.ID == searchTextAsInt.Value);
                    }
                    else
                    {
                        instructions = instructions.Where(i => i.Job.Title.Contains(searchTextAsStr) || i.OrderInstructions.FirstOrDefault().Order.ItemTitle.Contains(searchTextAsStr));
                    }
                }

                var queryData = instructions.Select(i => new
                {
                    i.ID,
                    JobID             = i.Job.ID,
                    InstructionTypeID = i.InstructionType,
                    CustomerReference = i.Job.Title,
                    CustomerOrder     = (i.OrderInstructions.Any()) ? i.OrderInstructions.FirstOrDefault().Order.ItemTitle : "",
                    PointDescription  = i.Point.Description,
                    DriverIndividual  = i.Driver == null ? null : i.Driver.Individual,
                    Vehicle           = i.VehicleReg == null ? string.Empty : i.VehicleReg,
                    i.ArriveDateTime,
                    i.DepartDateTime,
                    i.CommunicateDateTime,
                    i.LastUpdateDateTime,
                    CommunicationStatusID = i.CommunicationStatus,
                    StatusID       = i.Status,
                    SignedBy       = i.InstructionSignatures.FirstOrDefault().SignedBy,
                    SignedComment  = i.InstructionSignatures.FirstOrDefault().Comment,
                    SignatureImage = i.InstructionSignatures.FirstOrDefault().ImageName,
                    SignedDateTime = i.CompleteDateTime,
                    CQuantity      = i.InstructionType == MWFInstructionTypeEnum.Collect ?
                                     i.OrderInstructions.Sum(f => f.Order.ConfirmedCollectQuantity) :
                                     i.OrderInstructions.Sum(f => f.Order.ConfirmedDeliverQuantity),
                    RunStatus          = i.Job.Status,
                    SignatureLatitude  = i.InstructionSignatures.FirstOrDefault().Latitude,
                    SignatureLongitude = i.InstructionSignatures.FirstOrDefault().Longitude,
                    OrderID            = (i.OrderInstructions.Any()) ? (int?)i.OrderInstructions.FirstOrDefault().Order.ID : (int?)null,
                    OrderComplete      = i.CompleteDateTime.HasValue,
                    i.DriveDateTime,
                    i.CompleteDateTime
                }).OrderByDescending(i => i.ArriveDateTime).ToList();

                var gridData = queryData.Select(qd => new
                {
                    qd.ID,
                    qd.JobID,
                    InstructionType = MWF_Instruction.GetInstructionTypeDescription(qd.InstructionTypeID),
                    qd.CustomerReference,
                    qd.CustomerOrder,
                    Location    = qd.PointDescription,
                    ArrivalTime = qd.ArriveDateTime,
                    Status      = MWF_Instruction.GetStatusDescription(qd.StatusID),
                    qd.RunStatus,
                    qd.StatusID,
                    qd.CommunicationStatusID,
                    Driver                = qd.DriverIndividual == null ? string.Empty : Entities.Utilities.MergeStrings(" ", qd.DriverIndividual.FirstNames, qd.DriverIndividual.LastName),
                    VehicleReg            = qd.Vehicle,
                    CommunicationStatus   = MWF_Instruction.GetCommunicationStatusDescription((int)qd.CommunicationStatusID),
                    CommunicationDateTime = qd.CommunicateDateTime,
                    SignedBy              = qd.SignedBy,
                    SignedComment         = qd.SignedComment,
#if DEBUG
                    SignatureImage = String.IsNullOrEmpty(qd.SignatureImage) ? "" : "http://demo.orchestrator.co.uk/signatures/" + qd.SignatureImage,
#else
                    SignatureImage = String.IsNullOrEmpty(qd.SignatureImage) ? "" : new Uri(signatureImageBaseUri, qd.SignatureImage).AbsoluteUri,
#endif
                    SignedDateTime    = qd.SignedDateTime.HasValue ? qd.SignedDateTime.Value.ToLongDateString() + " " + qd.SignedDateTime.Value.ToLongTimeString() : "",
                    ConfirmedQuantity = qd.CQuantity,
                    qd.SignatureLatitude,
                    qd.SignatureLongitude,
                    qd.OrderID,
                    qd.OrderComplete,
                    qd.DriveDateTime,
                    qd.CompleteDateTime
                });

                return(gridData.ToList());
            }
        }
Пример #6
0
        private void BindTrafficSheetFilter(Entities.TrafficSheetFilter filter)
        {
            txtFilterName.Text = filter.FilterName;
            SelectItem(cboFilters.Items, filter.FilterId);

            cboControlArea.ClearSelection();
            SelectItem(cboControlArea.Items, filter.ControlAreaId);

            cboTrafficAreas.ClearSelection();
            foreach (var trafficAreaID in filter.TrafficAreaIDs)
            {
                SelectItem(cboTrafficAreas.Items, trafficAreaID);
            }

            cboDepot.ClearSelection();
            cboDepot.Items.FindByValue(filter.DepotId.ToString()).Selected = true;

            chkShowStockMovementJobs.Checked = filter.ShowStockMovementJobs;
            chkShowPlanned.Checked           = filter.ShowPlannedLegs;

            cblBusinessType.ClearSelection();
            foreach (int i in filter.BusinessTypes)
            {
                cblBusinessType.Items.FindByValue(i.ToString()).Selected = true;
            }

            cblInstructionStates.ClearSelection();
            foreach (int i in filter.InstructionStates)
            {
                cblInstructionStates.Items.FindByValue(((eInstructionState)i).ToString()).Selected = true;
            }

            cblInProgressSubStates.ClearSelection();
            if (!filter.InProgressSubStates.Any())
            {
                foreach (ListItem i in cblInProgressSubStates.Items)
                {
                    i.Selected = true;
                }
            }
            else
            {
                foreach (int i in filter.InProgressSubStates)
                {
                    cblInProgressSubStates.Items.FindByValue(((int)i).ToString()).Selected = true;
                }
            }

            chkSortbyEvent.Checked = filter.SortbyEvent;

            // MWF Comms States
            cblMWFCommsStates.ClearSelection();
            var states = MWF_Instruction.GetTrafficSheetStatesFromCommunicationStatesFilter(filter.MWFCommsStates);

            foreach (int i in states)
            {
                cblMWFCommsStates.Items.FindByValue(i.ToString()).Selected = true;
            }

            // MWF Instruction States
            cblMWFInstructionStates.ClearSelection();
            foreach (int i in filter.MWFInstructionStates)
            {
                cblMWFInstructionStates.Items.FindByValue(i.ToString()).Selected = true;
            }
        }
Пример #7
0
        private void PopulateStaticControls()
        {
            #region // Configure the min and max dates.
            dteStartDate.MinDate = new DateTime(2000, 1, 1);
            dteEndDate.MaxDate   = new DateTime(2036, 12, 31);
            #endregion

            #region // Populate Control Areas
            Facade.IControlArea facControlArea = new Facade.Traffic();
            cboControlArea.DataSource = facControlArea.GetAll();
            cboControlArea.DataBind();
            cboControlArea.Items[0].Selected = true;
            #endregion

            #region // Populate Traffic Areas
            Facade.ITrafficArea facTrafficArea = (Facade.ITrafficArea)facControlArea;
            cboTrafficAreas.DataSource = facTrafficArea.GetAll();
            cboTrafficAreas.DataBind();

            if (cboTrafficAreas.Items.Count > 8)
            {
                divTrafficAreas.Attributes.Add("class", "overflowHandler");
                divTrafficAreas.Attributes.Add("style", "height:100px;");
            }
            #endregion

            #region // Populate Depots
            Facade.IOrganisationLocation facOrganisationLocation = new Facade.Organisation();
            cboDepot.DataSource = facOrganisationLocation.GetAllDepots(Orchestrator.Globals.Configuration.IdentityId);
            cboDepot.DataBind();
            cboDepot.Items.Insert(0, new ListItem("Use Control Area and Traffic Areas to determine resource pool", "0"));
            #endregion

            #region // Populate Filters for this user
            PopulateFilterList();
            #endregion

            #region // Configure the default dates.
            // Default dates are from the start of today until:
            //   1) On a Saturday, until the end of Monday.
            //   2) On any other day, until the end of tomorrow.
            DateTime startOfToday = DateTime.Now;
            startOfToday = startOfToday.Subtract(startOfToday.TimeOfDay);
            DateTime endOfTomorrow = startOfToday.Add(new TimeSpan(1, 23, 59, 59));

            DateTime startDate = startOfToday;
            DateTime endDate   = endOfTomorrow;
            if (startOfToday.DayOfWeek == DayOfWeek.Saturday)
            {
                DateTime endOfMonday = startOfToday.Add(new TimeSpan(2, 23, 59, 59));
                endDate = endOfMonday;
            }
            #endregion

            #region // Populate the Business Types
            Facade.IBusinessType facBusinessType = new Facade.BusinessType();
            cblBusinessType.DataSource     = facBusinessType.GetAll();
            cblBusinessType.DataTextField  = "Description";
            cblBusinessType.DataValueField = "BusinessTypeID";
            cblBusinessType.DataBind();
            #endregion

            #region // Populate the Instruction States

            cblInstructionStates.DataSource = Enum.GetNames(typeof(eInstructionState));
            cblInstructionStates.DataBind();

            #endregion

            #region // Populate the In Progress Sub-States

            cblInProgressSubStates.DataSource = this.InProgressSubStateDescriptions.ToDictionary(kvp => (int)kvp.Key, kvp => kvp.Value);
            cblInProgressSubStates.DataBind();

            #endregion

            #region // Populate the Planning Categories Types

            cblPlanningCategory.DataSource = DataContext.PlanningCategorySet.OrderBy(pc => pc.DisplayShort);
            cblPlanningCategory.DataBind();
            var liAll = new ListItem("All", "-1")
            {
                Selected = true
            };

            cblPlanningCategory.Items.Add(liAll);

            #endregion

            #region // Populate the Instruction Types

            cblInstructionType.Items.Clear();

            var liMWF = new ListItem("MWF", "1");
            liMWF.Attributes.Add("onclick", "onInstructionTypeChecked();");
            var liNonMWF = new ListItem("Non-MWF", "2");
            liNonMWF.Attributes.Add("onclick", "onInstructionTypeChecked();");

            cblInstructionType.Items.Add(liMWF);
            cblInstructionType.Items.Add(liNonMWF);

            #endregion

            #region // Populate the MWF Comms Status

            var list = Enum.GetValues(typeof(MWFCommunicationStatusForTrafficSheetEnum)).Cast <object>().ToDictionary(v => (int)v, v => MWF_Instruction.GetCommunicationStatusForTrafficSheetDescription((int)v));

            cblMWFCommsStates.DataSource = list;
            cblMWFCommsStates.DataBind();

            #endregion

            #region // Populate the MWF Instruction States

            // Only adding the states that we use for now
            var list2 = new Dictionary <int, string>
            {
                { (int)MWFStatusEnum.Drive, "Drive" },
                { (int)MWFStatusEnum.OnSite, "On Site" },
                { (int)MWFStatusEnum.Suspend, "Suspend" },
                { (int)MWFStatusEnum.Resume, "Resume" },
                { (int)MWFStatusEnum.Complete, "Complete" }
            };

            cblMWFInstructionStates.DataSource = list2;
            cblMWFInstructionStates.DataBind();

            #endregion

            if (Filter == null)
            {
                Filter = Utilities.GetFilterFromCookie(this.CookieSessionID, Request);
            }



            if (Filter == null)
            {
                Filter = GetDefaultFilter();

                // Configure the default dates.
                // Default dates are from the start of today until:
                //   1) On a Saturday, until the end of Monday.
                //   2) On any other day, until the end of tomorrow.
                Filter.FilterStartDate = startOfToday;
                if (startOfToday.DayOfWeek == DayOfWeek.Saturday)
                {
                    DateTime endOfMonday = startOfToday.Add(new TimeSpan(2, 23, 59, 59));
                    Filter.FilterEnddate = endOfMonday;
                }
                else
                {
                    Filter.FilterEnddate = endOfTomorrow;
                }
            }


            cboControlArea.ClearSelection();
            SelectItem(cboControlArea.Items, Filter.ControlAreaId);

            foreach (var taid in Filter.TrafficAreaIDs)
            {
                SelectItem(cboTrafficAreas.Items, taid);
            }

            startDate = Filter.FilterStartDate;
            endDate   = Filter.FilterEnddate;
            chkShowPlanned.Checked           = Filter.ShowPlannedLegs;
            chkShowStockMovementJobs.Checked = Filter.ShowStockMovementJobs;

            cboDepot.ClearSelection();
            cboDepot.Items.FindByValue(Filter.DepotId.ToString()).Selected = true;

            foreach (var i in Filter.BusinessTypes)
            {
                try
                {
                    // P1 use if we try to work on different client's version of Orchestrator
                    // the same cookie is used (domain).
                    cblBusinessType.Items.FindByValue(i.ToString()).Selected = true;
                }
                catch { }
            }

            foreach (int i in this.Filter.InstructionStates)
            {
                cblInstructionStates.Items.FindByValue(((eInstructionState)i).ToString()).Selected = true;
            }

            foreach (var ipss in this.Filter.InProgressSubStates)
            {
                cblInProgressSubStates.Items.FindByValue(((int)ipss).ToString()).Selected = true;
            }

            if (this.Filter.PlanningCategories.Count > 0)
            {
                foreach (ListItem li in cblPlanningCategory.Items)
                {
                    li.Selected = this.Filter.PlanningCategories.Contains(int.Parse(li.Value));
                }
            }

            this.chkSortbyEvent.Checked  = Filter.SortbyEvent;
            this.chkCollapseRuns.Checked = this.Filter.CollapseRuns;

            liMWF.Selected    = Filter.IncludeMWFInstructions;
            liNonMWF.Selected = Filter.IncludeNonMWFInstructions;

            chkSelectAllInstructionTypes.Checked = (liMWF.Selected && liNonMWF.Selected);

            bool allSelected = false;
            if (Filter.MWFCommsStates.Count > 0)
            {
                allSelected = true;
                foreach (ListItem li in cblMWFCommsStates.Items)
                {
                    li.Selected = Filter.MWFCommsStates.Contains(int.Parse(li.Value));
                    if (!li.Selected)
                    {
                        allSelected = false;
                    }
                }
            }

            chkSelectAllMWFCommsStates.Checked = allSelected;


            var selected = false;
            if (Filter.MWFInstructionStates.Count > 0)
            {
                selected = true;
                foreach (ListItem li in cblMWFInstructionStates.Items)
                {
                    li.Selected = Filter.MWFInstructionStates.Contains(int.Parse(li.Value));
                    if (!li.Selected)
                    {
                        selected = false;
                    }
                }
            }

            chkSelectAllMWFInstructionStates.Checked = selected;


            #region     // Apply the dates.
            dteStartDate.SelectedDate = startDate;
            dteEndDate.SelectedDate   = endDate;
            #endregion
        }