Esempio n. 1
0
        /// <summary>
        /// Close the work order if it doesnt have any current open events associated with.
        /// </summary>
        /// <param name="maintenanceEntities"></param>
        /// <param name="workOrderId"></param>
        /// <param name="localTime"></param>
        /// <param name="vandalism"></param>
        public void CloseWorkOrder(MaintenanceEntities maintenanceEntities, long workOrderId, DateTime localTime,
                                   bool vandalism = false)
        {
            //get the work order
            var workOrder = maintenanceEntities.FMWorkOrders.FirstOrDefault(x => x.WorkOrderId == workOrderId);

            if (workOrder != null)
            {
                //check to see if there are any open events for this work order
                var openEvents = workOrder.WorkOrderEvents.Any(x => x.Status == (int)WorkOrderEventStatus.Open);
                if (openEvents)
                {
                    return;
                }

                //for each event, set the status to resolved (completed).
                var fmworkorder = maintenanceEntities.FMWorkOrders.FirstOrDefault(x => x.WorkOrderId == workOrderId);
                if (fmworkorder != null)
                {
                    fmworkorder.WorkOrderStatusId = (int)WorkOrderStatus.Closed;
                    fmworkorder.CompletedDate     = localTime;
                    //we are using Maintnenance code of 8 - Closed from Meter. This should exist in the DB.
                    fmworkorder.ResolutionCode = Constants.FieldMaintenance.AutomatedMaintenanceCodeId;
                    fmworkorder.ResolutionDesc = Constants.FieldMaintenance.AutomatedMaintenanceCodeDescription;
                    maintenanceEntities.SaveChanges();
                }
                //if there arent any, close the work order
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Updates a work order sla and highest severity base don the open events assigned to this work order, then saves that data.
        /// </summary>
        /// <param name="workOrderId"></param>
        public void UpdateEventAggregateInfo(long workOrderId)
        {
            //get the work order
            var workOrder = MaintenanceEntities.FMWorkOrders.FirstOrDefault(x => x.WorkOrderId == workOrderId);

            if (workOrder != null)
            {
                //now update the sla and highest severity (event alarm tier)

                //SLA - most recent - get the date
                var eventWithSoonestSLA = workOrder.WorkOrderEvents.Where(x => x.Status == (int)WorkOrderEventStatus.Open).OrderByDescending(x => x.SLADue).FirstOrDefault();
                if (eventWithSoonestSLA != null)
                {
                    workOrder.SLADue = eventWithSoonestSLA.SLADue;
                }

                //highest severity (alarm tier) - the alarm tiers are 0=Severe, 1 Major, - minor, so sort asc
                var eventWithHighestSeverity = workOrder.WorkOrderEvents.Where(x => x.Status == (int)WorkOrderEventStatus.Open).OrderBy(x => x.AlarmTier).FirstOrDefault();
                if (eventWithHighestSeverity != null)
                {
                    workOrder.HighestSeverity = eventWithHighestSeverity.AlarmTier;
                }

                MaintenanceEntities.SaveChanges();
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Updates the part quantities for the parts assigned ot a work order.
 /// </summary>
 /// <param name="workOrderParts"></param>
 /// <param name="workOrderId"></param>
 protected void UpdatePartQuantities(List <WorkOrderPart> workOrderParts, long workOrderId)
 {
     //get the work order
     //update quantities for all the parts. if it is 0, then delete it from the work order entirely.
     foreach (var workOrderPart in workOrderParts)
     {
         //get the fmWork Order Part
         var fmWorkOrderPart =
             MaintenanceEntities.FMWorkOrderParts.FirstOrDefault(
                 x => x.WorkOrderPartId == workOrderPart.WorkOrderPartId && x.WorkOrderId == workOrderId);
         if (fmWorkOrderPart != null)
         {
             //if 0, delete it from the work order parts
             if (workOrderPart.Quantity == 0)
             {
                 MaintenanceEntities.FMWorkOrderParts.Remove(fmWorkOrderPart);
             }
             else
             {
                 //get it from main entities, update quantity, and save
                 fmWorkOrderPart.Quantity = workOrderPart.Quantity;
             }
         }
     }
     MaintenanceEntities.SaveChanges();
 }
        /// <summary>
        /// Creates a work order in the system for a mobile user (technician)
        /// </summary>
        /// <param name="assetId"></param>
        /// <param name="faultDescription"></param>
        /// <param name="notes"></param>
        /// <param name="customerId"></param>
        /// <param name="areaId"></param>
        /// <param name="localTime"></param>
        /// <returns></returns>
        public long CreateWorkOrder(int assetId, string faultDescription, int customerId, int areaId,
                                    DateTime localTime, string crossStreet, string notes)
        {
            //we have to check to see if htey asset already has a work order. if it does, use that work order. This includes any open, incomplete or rejected work orders.
            //we add it to any open work order, even if it is assigned ot another technician (in practice this will almost never happen)
            var existingWorkOrder =
                MaintenanceEntities.FMWorkOrders.FirstOrDefault(x => x.MeterId == assetId &&
                                                                (x.WorkOrderStatusId == (int)WorkOrderStatus.Open ||
                                                                 x.WorkOrderStatusId == (int)WorkOrderStatus.Incomplete ||
                                                                 x.WorkOrderStatusId == (int)WorkOrderStatus.Rejected));

            if (existingWorkOrder != null)
            {
                return(existingWorkOrder.WorkOrderId);
            }
            //first we have to go to PEMS db to get the asset
            var assetFactory = (new AssetFactory(ConnectionStringName));

            var asset = assetFactory.GetAsset(customerId, areaId, assetId);

            //fail state
            if (asset == null)
            {
                return(-1);
            }

            //create the work order now. commented out properties we ignore upon creation.
            var fmWorkOrder = new FMWorkOrder
            {
                AreaId = areaId,
                //  AssignedDate = localTime, - not set until it is assigned
                CreateDateTime  = localTime,
                CreatedById     = WebSecurity.CurrentUserId,
                CrossStreet     = crossStreet,
                CustomerId      = customerId,
                HighestSeverity = 0,
                Location        = asset.Location,
                Mechanism       = asset.MeterType,
                MeterGroup      = asset.MeterGroup ?? 1,
                MeterId         = assetId,
                Notes           = notes,
                ReportingUserId = WebSecurity.CurrentUserId,
                SLADue          = localTime.AddHours(2),
                //TechnicianId = WebSecurity.CurrentUserId, - assign it to nothing since the dispatch is creating this
                WorkOrderStatusId = (int)WorkOrderStatus.Open,
                AssignmentState   = (int)AssignmentState.Unassigned,
                ZoneId            =
                    asset.MeterMaps.FirstOrDefault() != null?asset.MeterMaps.FirstOrDefault().ZoneId : (int?)null
            };

            fmWorkOrder.AssignmentState = (int)AssignmentState.Unassigned;
            //fmWorkOrder.CompletedDate; //not set here, set upon resolution
            // fmWorkOrder.ParkingSpaceId; //not used, dont have to set parkingspace ID
            //fmWorkOrder.ResolutionCode; - nothing on creation, when resolving, these are maintenance codes
            //fmWorkOrder.ResolutionDesc; -  nothing on creation, when resolving, these are maintenance codes
            MaintenanceEntities.FMWorkOrders.Add(fmWorkOrder);
            MaintenanceEntities.SaveChanges();
            return(fmWorkOrder.WorkOrderId);
        }
Esempio n. 5
0
        /// <summary>
        /// Gets a work order ID for this asset. IF one does not exist, it will create it instead.
        /// </summary>
        /// <param name="activeAlarmResponse"></param>
        /// <returns></returns>
        private string GetWorkOrderId(DataResponseActiveAlarmsActiveAlarm activeAlarmResponse)
        {
            const int defaultValue = -1;
            //first, parse the ids
            int customeId   = int.TryParse(activeAlarmResponse.cid, out customeId) ? customeId : defaultValue;
            int meterId     = int.TryParse(activeAlarmResponse.mid, out meterId) ? meterId : defaultValue;
            int areaId      = int.TryParse(activeAlarmResponse.aid, out areaId) ? areaId : defaultValue;
            int eventSource = int.TryParse(activeAlarmResponse.EventSource, out eventSource)
                                  ? eventSource
                                  : defaultValue;
            int  eventCode   = int.TryParse(activeAlarmResponse.EventCode, out eventCode) ? eventCode : defaultValue;
            long eventUID    = long.TryParse(activeAlarmResponse.EventUID, out eventUID) ? eventUID : defaultValue;
            long workOrderId = defaultValue;

            //check ot make sure all the ids were parsed correctly
            if (customeId > defaultValue && meterId > defaultValue && areaId > defaultValue &&
                eventCode > defaultValue && eventSource > defaultValue && eventUID > defaultValue)
            {
                var currentCustomer = new PemsCity(customeId.ToString());
                //go get the customer so we can get the correct connection string
                using (
                    var maintenanceEntities = new MaintenanceEntities(currentCustomer.MaintenanceConnectionStringName))
                {
                    //first we have to go to PEMS db to get the asset
                    //return nothing if the asset doesnt exist.
                    var assetFactory = (new AssetFactory(currentCustomer.PemsConnectionStringName));
                    var asset        = assetFactory.GetAsset(customeId, areaId, meterId);
                    //fail state - work order or work orde3r event will not be created
                    if (asset == null)
                    {
                        return(string.Empty);
                    }

                    //now create the work order/ or get the exisitng one
                    var fmWorkOrder = CreateWorkOrder(activeAlarmResponse, areaId, currentCustomer, customeId, asset,
                                                      meterId, maintenanceEntities);
                    workOrderId = fmWorkOrder.WorkOrderId;

                    //now that we have our work order id (exisitng or new), we haev to create the event for this work order.
                    //first, we have to get the vlaues we need ot create an event (tier, etc)
                    //get event code

                    CreateWorkOrderEvent(activeAlarmResponse, currentCustomer, customeId, eventSource, eventCode,
                                         eventUID, workOrderId, maintenanceEntities);

                    //every time a event is created, resolved , etc, we have to update the sladue and highest severity, so lets do that now
                    var mobileWorkOrderFactory =
                        (new TechnicianWorkOrderFactory(currentCustomer.MaintenanceConnectionStringName,
                                                        currentCustomer.PemsConnectionStringName));
                    mobileWorkOrderFactory.UpdateEventAggregateInfo(workOrderId);
                    return(workOrderId.ToString());
                }
            }
            return(string.Empty);
        }
Esempio n. 6
0
        /// <summary>
        /// Update the status of each event to be "Rejected" WorkOrderEventStatus.Rejected
        /// </summary>
        /// <param name="eventIds"></param>
        public void ResolveEvents(long[] eventIds, DateTime localTime, bool vandalism = false)
        {
            if (eventIds == null)
            {
                return;
            }
            //for each event, set the status to closed., as they are closing out individual events on a work order
            if (eventIds.Any())
            {
                var webServiceFactory = new WebServiceFactory();
                foreach (var eventId in eventIds)
                {
                    var fmworkOrderEvent =
                        MaintenanceEntities.FMWorkOrderEvents.FirstOrDefault(x => x.WorkOrderEventId == eventId);
                    if (fmworkOrderEvent != null)
                    {
                        fmworkOrderEvent.Vandalism = vandalism;
                        //now that we have closed them on our side, we need to close them on Duncans side, so for each event, send the request off to duncan to close this alarm as well.
                        //create the event  via the web service factory.
                        //create the close Alarm Request object to pass to the web services
                        var closeAlarmRequest = new CloseAlarmRequest
                        {
                            AreaId     = fmworkOrderEvent.WorkOrder.AreaId,
                            AssetId    = fmworkOrderEvent.WorkOrder.MeterId,
                            CustomerId = fmworkOrderEvent.WorkOrder.CustomerId,
                            EventCode  = fmworkOrderEvent.EventCode,
                            EventUID   = fmworkOrderEvent.EventId,
                            LocalTime  = localTime,
                        };
                        var closeAlarmResponse = webServiceFactory.CloseAlarm(closeAlarmRequest);
                        //set the status and if there were errors, report them
                        //first, check to see if it is valid. if it is, then

                        if (closeAlarmResponse.Closed)
                        {
                            fmworkOrderEvent.Status = (int)WorkOrderEventStatus.Closed;
                        }
                        else
                        {
                            fmworkOrderEvent.Status = (int)WorkOrderEventStatus.Open;
                            var eventResource = (new ResourceFactory()).GetLocalizedTitle(ResourceTypes.Glossary, "Event(s) not closed:");
                            if (string.IsNullOrEmpty(ErrorMessage))
                            {
                                ErrorMessage = string.Format(eventResource + " {0}", fmworkOrderEvent.WorkOrderEventId);
                            }
                            else
                            {
                                ErrorMessage += string.Format(", {0}", fmworkOrderEvent.WorkOrderEventId);
                            }
                        }
                    }
                }
                MaintenanceEntities.SaveChanges();
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Updates the notes for this work order
        /// </summary>
        /// <param name="workOrderId"></param>
        /// <param name="notes"></param>
        public void UpdateNotes(long workOrderId, string notes)
        {
            //get the work order
            var workOrder = MaintenanceEntities.FMWorkOrders.FirstOrDefault(x => x.WorkOrderId == workOrderId);

            if (workOrder != null)
            {
                workOrder.Notes = notes;
                MaintenanceEntities.SaveChanges();
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Creates an associated work order image for the work order id passed in.
        /// </summary>
        /// <param name="workOrderId"></param>
        /// <param name="imageData"></param>
        /// <returns></returns>
        public long CreateWorkOrderImage(long workOrderId, byte[] imageData, DateTime dateTaken)
        {
            var fmWorkOrderImage = new FMWorkOrderImage();

            fmWorkOrderImage.DateTaken   = dateTaken;
            fmWorkOrderImage.ImageData   = imageData;
            fmWorkOrderImage.WorkOrderId = workOrderId;
            MaintenanceEntities.FMWorkOrderImages.Add(fmWorkOrderImage);
            MaintenanceEntities.SaveChanges();
            return(fmWorkOrderImage.WorkOrderImageId);
        }
Esempio n. 9
0
        /// <summary>
        /// Creates a work order in the system
        /// </summary>
        /// <param name="activeAlarmResponse"></param>
        /// <param name="areaId"></param>
        /// <param name="currentCustomer"></param>
        /// <param name="customeId"></param>
        /// <param name="asset"></param>
        /// <param name="meterId"></param>
        /// <param name="maintenanceEntities"></param>
        /// <returns></returns>
        private static FMWorkOrder CreateWorkOrder(DataResponseActiveAlarmsActiveAlarm activeAlarmResponse, int areaId,
                                                   PemsCity currentCustomer, int customeId, Meter asset, int meterId,
                                                   MaintenanceEntities maintenanceEntities)
        {
            //we have to check to see if htey asset already has a work order. if it does, use that work order. This includes any open, incomplete or rejected work orders.
            //we add it to any open work order, even if it is assigned ot another technician (in practice this will almost never happen)
            var existingWorkOrder =
                maintenanceEntities.FMWorkOrders.FirstOrDefault(
                    x =>
                    x.MeterId == meterId && x.CustomerId == customeId && x.AreaId == areaId &&
                    (x.WorkOrderStatusId == (int)WorkOrderStatus.Open ||
                     x.WorkOrderStatusId == (int)WorkOrderStatus.Incomplete ||
                     x.WorkOrderStatusId == (int)WorkOrderStatus.Rejected));

            if (existingWorkOrder != null)
            {
                return(existingWorkOrder);
            }


            //we need to crate a new work order
            //create the work order now. commented out properties we ignore upon creation.
            var fmWorkOrder = new FMWorkOrder
            {
                AreaId            = areaId,
                CreateDateTime    = currentCustomer.LocalTime,
                CustomerId        = customeId, //cid
                HighestSeverity   = 0,
                Location          = asset.Location,
                Mechanism         = asset.MeterType,
                MeterGroup        = asset.MeterGroup ?? 1,
                MeterId           = meterId,
                Notes             = string.Empty,
                SLADue            = activeAlarmResponse.SLADue, //this gets reset anyways, jsut set it to
                WorkOrderStatusId = (int)WorkOrderStatus.Open,
                AssignmentState   = (int)AssignmentState.Unassigned,
                ZoneId            =
                    asset.MeterMaps.FirstOrDefault() != null?asset.MeterMaps.FirstOrDefault().ZoneId : (int?)null
            };

            maintenanceEntities.FMWorkOrders.Add(fmWorkOrder);
            maintenanceEntities.SaveChanges();

            //every time a event is created, resolved , etc, we have to update the sladue and highest severity, so lets do that now
            var mobileWorkOrderFactory =
                (new TechnicianWorkOrderFactory(currentCustomer.MaintenanceConnectionStringName,
                                                currentCustomer.PemsConnectionStringName));

            mobileWorkOrderFactory.UpdateEventAggregateInfo(fmWorkOrder.WorkOrderId);
            return(fmWorkOrder);
        }
Esempio n. 10
0
        /// <summary>
        /// Changes the state of the work order to unassigned and removes the technicianid
        /// </summary>
        /// <param name="workOrderId"></param>
        public void SuspendWorkOrder(long workOrderId)
        {
            //get the work order
            var fmworkorder =
                MaintenanceEntities.FMWorkOrders.FirstOrDefault(x => x.WorkOrderId == workOrderId);

            if (fmworkorder != null)
            {
                fmworkorder.WorkOrderStatusId = (int)WorkOrderStatus.Suspended;
                fmworkorder.AssignmentState   = (int)AssignmentState.Suspended;
                fmworkorder.TechnicianId      = (int?)null;
            }
            MaintenanceEntities.SaveChanges();
        }
Esempio n. 11
0
        /// <summary>
        /// Changes the state of the work order to unassigned and removes the technicianid
        /// </summary>
        /// <param name="workOrderId"></param>
        public void UnassignWorkOrder(long workOrderId)
        {
            //get the work order
            var fmworkorder =
                MaintenanceEntities.FMWorkOrders.FirstOrDefault(x => x.WorkOrderId == workOrderId);

            if (fmworkorder != null)
            {
                //fmworkorder.WorkOrderStatusId = no change on unnasignment
                fmworkorder.AssignmentState = (int)AssignmentState.Unassigned;
                fmworkorder.AssignedDate    = (DateTime?)null;
                fmworkorder.TechnicianId    = (int?)null;
            }
            MaintenanceEntities.SaveChanges();
        }
Esempio n. 12
0
        /// <summary>
        /// Reject the work order and assign it back to the empty pool so dispatch can see that it is unassigned and rejected
        /// </summary>
        /// <param name="workOrderId"></param>
        public void RejectWorkOrder(long workOrderId)
        {
            //for each event, set the status to rejected.
            var fmworkorder =
                MaintenanceEntities.FMWorkOrders.FirstOrDefault(x => x.WorkOrderId == workOrderId);

            if (fmworkorder != null)
            {
                //change the status to rejected and clear out the technician
                fmworkorder.WorkOrderStatusId = (int)WorkOrderStatus.Rejected;
                fmworkorder.AssignmentState   = (int)AssignmentState.Unassigned;
                fmworkorder.TechnicianId      = (int?)null;
                MaintenanceEntities.SaveChanges();
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Public method to add an available part ot hte parts system
        /// </summary>
        public FMPart CreateAvailablePart(int category, int metergroup, int costInCents, string description, string name, int status)
        {
            //create a part
            var fmPart = new FMPart
            {
                Category    = category,
                MeterGroup  = metergroup,
                CostInCents = costInCents,
                PartDesc    = description,
                PartName    = name,
                Status      = status
            };

            MaintenanceEntities.FMParts.Add(fmPart);
            MaintenanceEntities.SaveChanges();
            return(fmPart);
        }
Esempio n. 14
0
        /// <summary>
        /// Creates a work order event if we need to.
        /// </summary>
        /// <param name="activeAlarmResponse"></param>
        /// <param name="currentCustomer"></param>
        /// <param name="customeId"></param>
        /// <param name="eventSource"></param>
        /// <param name="eventCode"></param>
        /// <param name="eventUID"></param>
        /// <param name="workOrderId"></param>
        /// <param name="maintenanceEntities"></param>
        private void CreateWorkOrderEvent(DataResponseActiveAlarmsActiveAlarm activeAlarmResponse,
                                          PemsCity currentCustomer,
                                          int customeId, int eventSource, int eventCode, long eventUID, long workOrderId,
                                          MaintenanceEntities maintenanceEntities)
        {
            //check to see if we need to crate the event first. the PK for it is workorderid, eventid, eventcode
            var existingWorkOrderEvent =
                maintenanceEntities.FMWorkOrderEvents.FirstOrDefault(
                    x =>
                    x.WorkOrderId == workOrderId && x.EventId == eventUID && x.EventCode == eventCode &&
                    x.Status == (int)WorkOrderEventStatus.Open);

            if (existingWorkOrderEvent != null)
            {
                return;
            }

            //if we got here, we have to creat the event.
            using (var pemsEntities = new PEMEntities(currentCustomer.PemsConnectionStringName))
            {
                var ec =
                    pemsEntities.EventCodes.FirstOrDefault(
                        x => x.CustomerID == customeId && x.EventSource == eventSource && x.EventCode1 == eventCode);
                if (ec != null)
                {
                    //we found the event code, continue. .
                    var fmWorkOrderEvent = new FMWorkOrderEvent();
                    fmWorkOrderEvent.AlarmTier     = ec.AlarmTier; // alarm tier of the event code
                    fmWorkOrderEvent.Automated     = true;
                    fmWorkOrderEvent.EventCode     = eventCode;
                    fmWorkOrderEvent.EventDateTime = activeAlarmResponse.TimeOfOccurrance;
                    fmWorkOrderEvent.EventDesc     = ec.EventDescVerbose;
                    fmWorkOrderEvent.EventId       = eventUID;
                    fmWorkOrderEvent.Notes         = activeAlarmResponse.Notes;
                    fmWorkOrderEvent.SLADue        = activeAlarmResponse.SLADue;
                    fmWorkOrderEvent.Status        = (int)WorkOrderEventStatus.Open;
                    fmWorkOrderEvent.Vandalism     = false;
                    fmWorkOrderEvent.WorkOrderId   = workOrderId;

                    maintenanceEntities.FMWorkOrderEvents.Add(fmWorkOrderEvent);
                    maintenanceEntities.SaveChanges();
                }
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Adds a FMPart to a work order as a workorderpart db entry
        /// </summary>
        /// <param name="partId"></param>
        /// <param name="workOrderId"></param>
        /// <param name="notes"></param>
        public void AddPartToWorkOrder(long partId, long workOrderId, string notes)
        {
            //get the part
            var fmPart = MaintenanceEntities.FMParts.FirstOrDefault(x => x.PartId == partId);

            if (fmPart == null)
            {
                return;
            }

            //we only add unique when the part is notht he"Other" part. if it is other, then we want to add it with new notes no matter what
            if (fmPart.PartName != Constants.FieldMaintenance.OtherPartName)
            {
                //if they are adding a part that already exist, just increment it by one
                //check to see if the work order part isnt already part of this work order.
                //if it exist, get it from the maint entities, increment once, then save
                var fmwoPart = MaintenanceEntities.FMWorkOrderParts.FirstOrDefault(x => x.PartId == partId && x.WorkOrderId == workOrderId);
                if (fmwoPart != null)
                {
                    fmwoPart.Quantity = fmwoPart.Quantity + 1;
                    //update the notes as well, only if htere is a value for it. we dont want to override the existing notes
                    if (!string.IsNullOrEmpty(notes))
                    {
                        fmwoPart.Notes = notes;
                    }
                    MaintenanceEntities.SaveChanges();
                    return;
                }
            }

            //now create a work order part if is doesnt already exist for this work order.
            var fmWordOrderPart = new FMWorkOrderPart
            {
                Notes       = notes ?? string.Empty,
                PartId      = partId,
                Quantity    = 1,
                WorkOrderId = workOrderId
            };

            MaintenanceEntities.FMWorkOrderParts.Add(fmWordOrderPart);
            MaintenanceEntities.SaveChanges();
        }
Esempio n. 16
0
        /// <summary>
        /// Changes the state of the work order to assigned and adds the technicianid
        /// </summary>
        /// <param name="workOrderId"></param>
        /// <param name="technicianId"></param>
        public void AssignWorkOrder(long workOrderId, int technicianId, DateTime localTime)
        {
            //get the work order
            var fmworkorder =
                MaintenanceEntities.FMWorkOrders.FirstOrDefault(x => x.WorkOrderId == workOrderId);

            if (fmworkorder != null)
            {
                //if the work order status is rejected, set it back to incomplete.
                //this way they will be able to see it in the work order list. otherwise they wont, and they shouldnt see rejected work orders.
                if (fmworkorder.WorkOrderStatusId == (int)WorkOrderStatus.Rejected)
                {
                    fmworkorder.WorkOrderStatusId = (int)WorkOrderStatus.Incomplete;
                }
                fmworkorder.AssignmentState = (int)AssignmentState.Assigned;

                fmworkorder.TechnicianId = technicianId;
                fmworkorder.AssignedDate = localTime;
            }
            MaintenanceEntities.SaveChanges();
        }
Esempio n. 17
0
        /// <summary>
        /// Resolves a work order and assigns the associated maintenance code to the resoluction for the work order
        /// This will also close out any exisiting events for this work order
        /// </summary>
        /// <param name="workOrderId"></param>
        /// <param name="maintCodeId"></param>
        /// <param name="vandalism"></param>
        public void ResolveWorkOrder(long workOrderId, int maintCodeId, bool vandalism)
        {
            //for each event, set the status to resolved (completed).
            var fmworkorder = MaintenanceEntities.FMWorkOrders.FirstOrDefault(x => x.WorkOrderId == workOrderId);

            if (fmworkorder != null)
            {
                ErrorMessage = string.Empty;
                //now lets close out all the work order events
                var localTime = (new Customers.SettingsFactory().GetCustomerLocalTime(fmworkorder.CustomerId));
                //only try to close the non -closed ones. if they are already closed, then the web service will return (incorrectly) that it was not closed.
                if (fmworkorder.WorkOrderEvents.Any(x => x.Status != (int)WorkOrderStatus.Closed))
                {
                    ResolveEvents(fmworkorder.WorkOrderEvents.Where(x => x.Status != (int)WorkOrderStatus.Closed).Select(x => x.WorkOrderEventId).ToArray(), localTime, vandalism);
                }

                //only close it out if the events were closed.
                if (!string.IsNullOrEmpty(ErrorMessage))
                {
                    var woResource = (new ResourceFactory()).GetLocalizedTitle(ResourceTypes.Glossary, "Work Order was not closed:");
                    var woTryAgain = (new ResourceFactory()).GetLocalizedTitle(ResourceTypes.Glossary, "Try again later.");
                    ErrorMessage = woResource + " " + ErrorMessage + ". " + woTryAgain;
                }
                else
                {
                    fmworkorder.WorkOrderStatusId = (int)WorkOrderStatus.Closed;
                    fmworkorder.CompletedDate     = localTime;
                    //fmworkorder.AssignmentState = - no change to assignment state one resolution
                    //now we have to get the resolution code (maintenance code) from pems
                    var maintenanceCode =
                        PemsEntities.MaintenanceCodes.FirstOrDefault(x => x.MaintenanceCode1 == maintCodeId);
                    if (maintenanceCode != null)
                    {
                        fmworkorder.ResolutionCode = maintenanceCode.MaintenanceCode1;
                        fmworkorder.ResolutionDesc = maintenanceCode.Description;
                    }
                    MaintenanceEntities.SaveChanges();
                }
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Creates a work order event for a given work order and returns the ID of the generated event.
        /// </summary>
        /// <param name="eventId"></param>
        /// <param name="workOrderId"></param>
        /// <param name="eventCode"></param>
        /// <param name="eventDateTime"></param>
        /// <param name="eventDescription"></param>
        /// <param name="slaDue"></param>
        /// <param name="alarmTier"></param>
        /// <param name="notes"></param>
        /// <param name="automated"></param>
        /// <param name="vandalism"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public long CreateWorkOrderEvent(int eventId, long workOrderId, int eventCode, DateTime eventDateTime,
                                         string eventDescription, DateTime slaDue, int alarmTier, string notes,
                                         bool automated, bool vandalism, int status)
        {
            var fmWorkOrderEvent = new FMWorkOrderEvent();

            fmWorkOrderEvent.AlarmTier     = alarmTier; // alarm tier of the event code
            fmWorkOrderEvent.Automated     = automated;
            fmWorkOrderEvent.EventCode     = eventCode;
            fmWorkOrderEvent.EventDateTime = eventDateTime;
            fmWorkOrderEvent.EventDesc     = eventDescription;
            fmWorkOrderEvent.EventId       = eventId;
            fmWorkOrderEvent.Notes         = notes;
            fmWorkOrderEvent.SLADue        = slaDue;
            fmWorkOrderEvent.Status        = status;
            fmWorkOrderEvent.Vandalism     = vandalism;
            fmWorkOrderEvent.WorkOrderId   = workOrderId;

            MaintenanceEntities.FMWorkOrderEvents.Add(fmWorkOrderEvent);
            MaintenanceEntities.SaveChanges();
            return(fmWorkOrderEvent.WorkOrderEventId);
        }
        public DispatcherPartUploadResultModel ProcessPartImport(string file)
        {
            var model = new DispatcherPartUploadResultModel()
            {
                UploadedFileName = file
            };

            try
            {
                // Prep the LINQtoCSV context.
                _csvContext         = new CsvContext();
                _csvFileDescription = new CsvFileDescription()
                {
                    MaximumNbrExceptions = 100,
                    SeparatorChar        = ','
                };

                IEnumerable <UploadPartModel> items = _csvContext.Read <UploadPartModel>(file, _csvFileDescription);

                foreach (var item in items)
                {
                    bool canCreateItem = true;

                    // First, validate that certain data, if present, resolves to the
                    // associated referential table.

                    //check name first
                    if (string.IsNullOrEmpty(item.PartName))
                    {
                        model.Errors.Add(string.Format("Record {0}, Part Name is required.", item.Id));
                        canCreateItem = false;
                    }

                    //metergroup
                    var meterGroup = PemsEntities.MeterGroups.FirstOrDefault(m => m.MeterGroupId == item.MeterGroup);
                    if (meterGroup == null)
                    {
                        model.Errors.Add(string.Format("Record {0}, MeterGroup '{1}' is invalid.", item.Id, item.MeterGroup));
                        canCreateItem = false;
                    }

                    //Category - mech master
                    var category = PemsEntities.MechanismMasters.FirstOrDefault(m => m.MechanismId == item.Category);
                    if (category == null)
                    {
                        model.Errors.Add(string.Format("Record {0}, Category '{1}' is invalid.", item.Id, item.Category));
                        canCreateItem = false;
                    }

                    if (item.CostInCents < 0)
                    {
                        model.Errors.Add(string.Format("Record {0}, CostInCents '{1}' is invalid. Defaulting to 0.", item.Id, item.CostInCents));
                        item.CostInCents = 0;
                    }

                    if (item.Status != 1 && item.Status != 0)
                    {
                        model.Errors.Add(string.Format("Record {0}, Status '{1}' is invalid. Defaulting to 1.", item.Id, item.Status));
                        item.Status = 1;
                    }

                    item.PartDesc = item.PartDesc.Trim();
                    item.PartName = item.PartName.Trim();

                    // If a CashBox cannot be created continue on to next record.
                    if (!canCreateItem)
                    {
                        continue;
                    }

                    // Now should be able to create the item
                    // For each uplaoded model, create a new item o r update an existing one
                    //this is an update for create based on part name / meter group, cateegory.
                    var fmPart = MaintenanceEntities.FMParts.FirstOrDefault(x => x.MeterGroup == item.MeterGroup && x.Category == item.Category && x.PartName == item.PartName);
                    if (fmPart == null)
                    {
                        fmPart = CreateAvailablePart(item.Category, item.MeterGroup, item.CostInCents, item.PartDesc, item.PartName, item.Status);
                        model.Results.Add(string.Format("Record {0}, '{1}' added successfully.", item.Id, item.PartName));
                    }
                    //otherwise we want to update it - metergroup, cate, and name wont change
                    else
                    {
                        fmPart.CostInCents = item.CostInCents;
                        fmPart.PartDesc    = item.PartDesc;
                        fmPart.Status      = item.Status;
                        MaintenanceEntities.SaveChanges();
                        model.Results.Add(string.Format("Record {0}, '{1}' updated successfully.", item.Id, item.PartName));
                    }
                }
            }
            catch (AggregatedException ae)
            {
                // Process all exceptions generated while processing the file
                var innerExceptionsList =
                    (List <Exception>)ae.Data["InnerExceptionsList"];

                foreach (Exception e in innerExceptionsList)
                {
                    model.Errors.Add(e.Message);
                }
            }
            catch (Exception ex)
            {
                model.Errors.Add("General exception");
                model.Errors.Add(ex.Message);
            }
            return(model);
        }
Esempio n. 20
0
        private string ClearAlarm(DataRequestHistoricalAlarm historicAlarmRequest)
        {
            //clear the work order event

            const int defaultValue = -1;
            //first, parse the ids
            int customeId   = int.TryParse(historicAlarmRequest.cid, out customeId) ? customeId : defaultValue;
            int meterId     = int.TryParse(historicAlarmRequest.mid, out meterId) ? meterId : defaultValue;
            int areaId      = int.TryParse(historicAlarmRequest.aid, out areaId) ? areaId : defaultValue;
            int eventSource = int.TryParse(historicAlarmRequest.EventSource, out eventSource)
                                  ? eventSource
                                  : defaultValue;
            int  eventCode   = int.TryParse(historicAlarmRequest.EventCode, out eventCode) ? eventCode : defaultValue;
            long eventUID    = long.TryParse(historicAlarmRequest.EventUID, out eventUID) ? eventUID : defaultValue;
            int  workOrderId = int.TryParse(historicAlarmRequest.WorkOrderId, out workOrderId)
                                  ? workOrderId
                                  : defaultValue;


            //check ot make sure all the ids were parsed correctly
            if (customeId > defaultValue && meterId > defaultValue && areaId > defaultValue &&
                eventCode > defaultValue && eventSource > defaultValue && eventUID > defaultValue &&
                workOrderId > defaultValue)
            {
                var currentCustomer = new PemsCity(customeId.ToString());
                //go get the customer so we can get the correct connection string
                using (
                    var maintenanceEntities = new MaintenanceEntities(currentCustomer.MaintenanceConnectionStringName))
                {
                    //first we have to go to PEMS db to get the asset
                    //return nothing if the asset doesnt exist.
                    var assetFactory = (new AssetFactory(currentCustomer.PemsConnectionStringName));
                    var asset        = assetFactory.GetAsset(customeId, areaId, meterId);
                    //fail state - work order or work order event will not be closed
                    if (asset == null)
                    {
                        return(((int)WorkOrderEventStatus.Open).ToString());
                    }

                    //close out the work order event
                    //go get the event
                    //check to see if the event exist first
                    var existingWorkOrderEvent =
                        maintenanceEntities.FMWorkOrderEvents.FirstOrDefault(
                            x => x.WorkOrderId == workOrderId && x.EventId == eventUID && x.EventCode == eventCode);
                    //if it doesnt exist, cant close it, just return closed
                    if (existingWorkOrderEvent == null)
                    {
                        return(((int)WorkOrderEventStatus.Closed).ToString());
                    }

                    //clear the event
                    existingWorkOrderEvent.Status = (int)WorkOrderEventStatus.Closed;
                    maintenanceEntities.SaveChanges();

                    //every time a event is created, resolved , etc, we have to update the sladue and highest severity, so lets do that now
                    var mobileWorkOrderFactory =
                        (new TechnicianWorkOrderFactory(currentCustomer.MaintenanceConnectionStringName,
                                                        currentCustomer.PemsConnectionStringName));
                    mobileWorkOrderFactory.UpdateEventAggregateInfo(workOrderId);

                    //then clear the work order (if its the last event that was open was just closed)
                    CloseWorkOrder(maintenanceEntities, workOrderId, currentCustomer.LocalTime);
                    return(((int)WorkOrderEventStatus.Closed).ToString());
                }
            }
            //cant find the itme the request was referencing, return closed.
            //return WorkOrderEventStatus enum representing if it were closed or not.
            return(((int)WorkOrderEventStatus.Closed).ToString());
        }