Ejemplo n.º 1
0
        public async Task <Tuple <bool, NewImplementTemplateViewModel> > ReturnTemplateById(long templateId)
        {
            bool status = false;
            NewImplementTemplateViewModel result = new NewImplementTemplateViewModel();

            using (var dataEntities = new DAL.GETContext())
            {
                var template = dataEntities.LU_IMPLEMENT.Find(templateId);
                if (template != null)
                {
                    result.CustomerId        = template.CustomerId;
                    result.ImplementCategory = (ImplementCategory)template.implement_category_auto;
                    result.TemplateName      = template.implementdescription;
                    result.TemplateId        = template.implement_auto;

                    if (template.CustomerId != null)
                    {
                        result.TemplateAccess = TemplateAccess.Customer;
                    }
                    else
                    {
                        result.TemplateAccess = TemplateAccess.Global;
                    }

                    var implementModels = await dataEntities.GET_IMPLEMENT_MAKE_MODEL
                                          .Where(i => i.implement_auto == templateId)
                                          .Select(s => (int)s.model_auto)
                                          .ToArrayAsync();

                    if (implementModels != null)
                    {
                        result.EquipmentModels = implementModels;
                    }

                    var implementComponents = await(from ic in dataEntities.GET_IMPLEMENT_COMPARTTYPE
                                                    join lct in dataEntities.LU_COMPART_TYPE
                                                    on ic.comparttype_auto equals lct.comparttype_auto
                                                    where ic.implement_auto == templateId
                                                    select new ImplementComponentTypeViewModel
                    {
                        Id   = ic.comparttype_auto,
                        Name = lct.comparttype
                    }).ToListAsync();

                    if (implementComponents != null)
                    {
                        result.ComponentTypes = implementComponents;
                    }

                    status = true;
                }
            }

            return(Tuple.Create(status, result));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Save the measurement points for an implement.
        /// </summary>
        /// <param name="get_auto"></param>
        /// <param name="measurementPoints"></param>
        /// <returns>Result = 1 for successful save, Result = 0 for no save, Result = -1 for error.</returns>
        public int SaveMeasurementPoints(int get_auto, List <MeasurementPointDetails> measurementPoints)
        {
            int result        = 0;
            int _changesSaved = 0;

            using (var _context = new DAL.GETContext())
            {
                // Check if there are any records already for measurement points.
                var existingRecords = _context.GET_COMPONENT
                                      .Where(w => w.get_auto == get_auto && w.active == true)
                                      .ToList();

                // GET record
                var GT = _context.GET.Find(get_auto);

                if (existingRecords.Count != 0)
                {
                    for (int i = 0; i < measurementPoints.Count; i++)
                    {
                        var GETComponentRecord = existingRecords
                                                 .Where(w => w.get_component_auto == measurementPoints[i].Id)
                                                 .FirstOrDefault();

                        // Update the existing record.
                        if (GETComponentRecord != null)
                        {
                            GETComponentRecord.make_auto             = measurementPoints[i].Make != 0 ? measurementPoints[i].Make : (int?)null;
                            GETComponentRecord.observation_list_auto = measurementPoints[i].ObservationListId;
                            GETComponentRecord.req_measure           = ((measurementPoints[i].InitialLength) == 0 &&
                                                                        (measurementPoints[i].WornLength == 0)) ? false : true;
                            GETComponentRecord.initial_length = measurementPoints[i].InitialLength;
                            GETComponentRecord.worn_length    = measurementPoints[i].WornLength;
                            GETComponentRecord.part_no        = measurementPoints[i].PartNo;
                        }
                    }
                }

                // Save changes
                try
                {
                    _changesSaved = _context.SaveChanges();
                    if (_changesSaved > 0)
                    {
                        result = 1;
                    }
                }
                catch (Exception ex1)
                {
                    result = -1;
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        public List <EquipmentListVM> getCompatibleEquipmentForImplementByJobsite(long jobsiteId, int getAuto, System.Security.Principal.IPrincipal User)
        {
            List <EquipmentListVM> result = new List <EquipmentListVM>();

            using (var context = new DAL.GETContext())
            {
                // Get implement id
                long implementAuto = context.GET.Find(getAuto).implement_auto ?? 0;
                if (implementAuto == 0)
                {
                    return(result);
                }

                // Find valid models for implement.
                var validModels = context.GET_IMPLEMENT_MAKE_MODEL.Where(w => w.implement_auto == implementAuto)
                                  .Select(s => new
                {
                    equipmentModel = s.model_auto
                }).ToList();

                // Find all equipment at the specified jobsite for which the user has permissions to access.
                var allEquipmentAtJobsite = new BLL.Core.Domain.UserAccess(new SharedContext(), User)
                                            .getAccessibleEquipments().Where(e => e.crsf_auto == jobsiteId)
                                            .Select(s => new
                {
                    equipmentId       = s.equipmentid_auto,
                    equipmentSerialNo = s.serialno,
                    equipmentSMU      = s.currentsmu.Value,
                    equipmentModel    = s.LU_MMTA.model_auto
                }).ToList();

                // Filter results by valid models for the specified jobsite.
                for (int i = 0; i < allEquipmentAtJobsite.Count; i++)
                {
                    for (int j = 0; j < validModels.Count; j++)
                    {
                        if (allEquipmentAtJobsite[i].equipmentModel == validModels[j].equipmentModel)
                        {
                            result.Add(new EquipmentListVM
                            {
                                equipmentId       = allEquipmentAtJobsite[i].equipmentId,
                                equipmentSerialNo = allEquipmentAtJobsite[i].equipmentSerialNo,
                                equipmentSMU      = allEquipmentAtJobsite[i].equipmentSMU
                            });
                        }
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns status for implements in inventory. Excludes status 'On Equipment'.
        /// </summary>
        /// <returns></returns>
        public List <GenericIdNameVM> ReturnInventoryStatusList()
        {
            List <GenericIdNameVM> result = new List <GenericIdNameVM>();

            using (var dataEntities = new DAL.GETContext())
            {
                result = dataEntities.GET_INVENTORY_STATUS
                         .Where(s => s.status_auto != (int)GETInterfaces.Enum.InventoryStatus.On_Equipment)
                         .Select(i => new GenericIdNameVM
                {
                    Id   = i.status_auto,
                    Name = i.status_desc
                }).ToList();
            }

            return(result);
        }
Ejemplo n.º 5
0
        public List <GenericIdNameVM> GetObservationLists(long customerId)
        {
            List <GenericIdNameVM> result = new List <GenericIdNameVM>();

            using (var _context = new DAL.GETContext())
            {
                result = (from gol in _context.GET_OBSERVATION_LIST
                          where gol.active == true && gol.customer_auto == customerId
                          select new GenericIdNameVM
                {
                    Id = gol.observation_list_auto,
                    Name = gol.name
                }).ToList();
            }

            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Save the observation points for an implement.
        /// </summary>
        /// <param name="get_auto"></param>
        /// <param name="observationPoints"></param>
        /// <returns>Result = 1 for successful save, Result = 0 for no save, Result = -1 for error.</returns>
        public int SaveObservationPoints(int get_auto, List <ObservationPointDetails> observationPoints)
        {
            int result        = 0;
            int _changesSaved = 0;

            using (var _context = new DAL.GETContext())
            {
                // Check if there are any existing records.
                var existingRecords = _context.GET_OBSERVATION_POINTS
                                      .Where(w => w.get_auto == get_auto && w.active == true)
                                      .ToList();

                if (existingRecords.Count != 0)
                {
                    for (int i = 0; i < observationPoints.Count; i++)
                    {
                        var gop = _context.GET_OBSERVATION_POINTS.Find(observationPoints[i].Id);

                        gop.observation_list = (observationPoints[i].ObservationListId != 0) ?
                                               observationPoints[i].ObservationListId : (int?)null;
                        gop.req_measure = ((observationPoints[i].InitialLength) == 0 &&
                                           (observationPoints[i].WornLength == 0)) ? false : true;
                        gop.initial_length = observationPoints[i].InitialLength;
                        gop.worn_length    = observationPoints[i].WornLength;
                    }
                }

                // Save changes
                try
                {
                    _changesSaved = _context.SaveChanges();
                    if (_changesSaved > 0)
                    {
                        result = 1;
                    }
                }
                catch (Exception ex1)
                {
                    result = -1;
                }
            }

            return(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Returns the minimum date for the component replace, based on
        /// the date when the implement last had a repair, or replacement
        /// recorded against it.
        /// </summary>
        /// <param name="componentId"></param>
        /// <returns></returns>
        public string ReturnMinDateForReplace(int componentId)
        {
            string result = "";

            using (var dataEntities = new DAL.GETContext())
            {
                int ACTION_MovedToInventory     = (int)Core.Domain.GETActionType.Move_Implement_To_Inventory;
                int ACTION_ComponentReplacement = (int)Core.Domain.GETActionType.Component_Replacement;
                int ACTION_ComponentRepair      = (int)Core.Domain.GETActionType.Component_Repair;

                var implement = dataEntities.GET_COMPONENT.Find(componentId);
                if (implement != null)
                {
                    // Get the last 'moved to inventory' event for this component.
                    var movedToInventoryDate = GetDateOfLastImplementEvent(implement.get_auto, ACTION_MovedToInventory, dataEntities);

                    // Get the last 'component repair' event.
                    var componentRepairDate = GetDateOfLastComponentEvent(componentId, ACTION_ComponentRepair, dataEntities);

                    // Get the last 'component replaced' event.
                    var componentReplaceDate = GetDateOfLastComponentEvent(componentId, ACTION_ComponentReplacement, dataEntities);

                    // The date of the repair must be on the same day or after the implement
                    // was last moved from equipment to inventory. If that component has
                    // been replaced / repaired, then the min date must be after the date of
                    // the replacement or a repair
                    if (movedToInventoryDate != null)
                    {
                        string dateFormat = "yyyy-MM-dd";

                        DateTime?recentEventDate     = ReturnMostRecentDateTime(movedToInventoryDate, componentReplaceDate);
                        DateTime?mostRecentEventDate = ReturnMostRecentDateTime(recentEventDate, componentRepairDate);

                        if (mostRecentEventDate != null)
                        {
                            result = mostRecentEventDate.Value.ToString(dateFormat);
                        }
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Verifies the given user ID's access to review GET Inspection Data
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static bool verifyAccessToGETInspectionData(long userId, int inspectionID)
        {
            bool userHasAccess = false;

            using (var context = new DAL.GETContext())
            {
                try
                {
                    var jobsiteId = context.GET_IMPLEMENT_INSPECTION.Find(inspectionID).GET.EQUIPMENT.crsf_auto;
                    userHasAccess = verifyAccessToJobsite(userId, jobsiteId, false);
                }
                catch (Exception ex1)
                {
                    userHasAccess = false;
                }
            }

            return(userHasAccess);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns the list of available workshops for a given repairer.
        /// </summary>
        /// <param name="repairerId"></param>
        /// <returns></returns>
        public List <GenericIdNameVM> ReturnWorkshopListForRepairer(int repairerId)
        {
            List <GenericIdNameVM> result = new List <GenericIdNameVM>();

            using (var dataEntities = new DAL.GETContext())
            {
                var repairer = dataEntities.GET_REPAIRER.Find(repairerId);
                if (repairer != null)
                {
                    result = dataEntities.GET_WORKSHOP
                             .Where(w => w.repairer_auto == repairer.repairer_auto)
                             .Select(s => new GenericIdNameVM
                    {
                        Id   = s.workshop_auto,
                        Name = s.name
                    }).ToList();
                }
            }

            return(result);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Returns the list of available repairers for a customer. Uses the jobsiteId
        /// of the implement in inventory to determine which customer to filter by.
        /// </summary>
        /// <param name="jobsiteId"></param>
        /// <returns></returns>
        public List <GenericIdNameVM> ReturnRepairerListForCustomer(long jobsiteId)
        {
            List <GenericIdNameVM> result = new List <GenericIdNameVM>();

            using (var dataEntities = new DAL.GETContext())
            {
                var crsf = dataEntities.CRSF.Find(jobsiteId);
                if (crsf != null)
                {
                    result = dataEntities.GET_REPAIRER
                             .Where(r => r.customer_auto == crsf.customer_auto)
                             .Select(s => new GenericIdNameVM
                    {
                        Id   = s.repairer_auto,
                        Name = s.name
                    }).ToList();
                }
            }

            return(result);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a new repairer for the customer at the specified jobsite.
        /// </summary>
        /// <param name="jobsiteId"></param>
        /// <param name="repairerName"></param>
        /// <returns></returns>
        public int CreateRepairer(long jobsiteId, string repairerName)
        {
            int result = 0;

            using (var dataEntities = new DAL.GETContext())
            {
                // Check that the customer exists.
                var jobsite = dataEntities.CRSF.Find(jobsiteId);
                if (jobsite != null)
                {
                    var customer = dataEntities.CUSTOMERs.Find(jobsite.customer_auto);
                    if (customer != null)
                    {
                        // Check that the repairer doesn't already exist.
                        var repairer = dataEntities.GET_REPAIRER
                                       .Where(r => r.name == repairerName)
                                       .FirstOrDefault();

                        if (repairer == null)
                        {
                            // Add new repairer.
                            DAL.GET_REPAIRER newRepairer = new DAL.GET_REPAIRER
                            {
                                name          = repairerName,
                                customer_auto = customer.customer_auto
                            };
                            dataEntities.GET_REPAIRER.Add(newRepairer);

                            int _changesSaved = dataEntities.SaveChanges();
                            if (_changesSaved > 0)
                            {
                                result = newRepairer.repairer_auto;
                            }
                        }
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 12
0
        public string returnPreviousEquipmentEventDate(long equipmentId, System.Security.Principal.IPrincipal User)
        {
            string result = "";

            if (!new BLL.Core.Domain.UserAccess(new SharedContext(), User).hasAccessToEquipment(equipmentId))
            {
                return("Access Denied!");
            }

            using (var dataEntities = new DAL.GETContext())
            {
                var previousEvent = eventManagement.findPreviousEquipmentEvent(dataEntities, equipmentId, DateTime.Now);
                if (previousEvent != null)
                {
                    var previousGETEvent = dataEntities.GET_EVENTS.Find(previousEvent.events_auto);
                    if (previousGETEvent != null)
                    {
                        result = previousGETEvent.event_date.Date.ToShortDateString();
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates a new workshop for the specified repairer.
        /// </summary>
        /// <param name="repairerId"></param>
        /// <param name="workshopName"></param>
        /// <returns></returns>
        public int CreateWorkshop(int repairerId, string workshopName)
        {
            int result = 0;

            using (var dataEntities = new DAL.GETContext())
            {
                // Check that the repairer exists.
                var repairer = dataEntities.GET_REPAIRER.Find(repairerId);
                if (repairer != null)
                {
                    // Check that the workshop doesn't already exist.
                    var workshop = dataEntities.GET_WORKSHOP
                                   .Where(w => w.name == workshopName)
                                   .FirstOrDefault();

                    if (workshop == null)
                    {
                        // Add new workshop.
                        DAL.GET_WORKSHOP newWorkshop = new DAL.GET_WORKSHOP
                        {
                            name          = workshopName,
                            repairer_auto = repairerId
                        };
                        dataEntities.GET_WORKSHOP.Add(newWorkshop);

                        int _changesSaved = dataEntities.SaveChanges();
                        if (_changesSaved > 0)
                        {
                            result = newWorkshop.workshop_auto;
                        }
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 14
0
 public new void Dispose()
 {
     if (Status != ActionStatus.Succeed)
     {
         rollBack();
         MakeOtherSystemsOnline();
         var _ids    = ActionHistoryModifiedIds.Select(k => k.HistoryId).ToList();
         var actions = _context.ACTION_TAKEN_HISTORY.Where(m => _ids.Any(k => k == m.history_id));
         foreach (var act in actions)
         {
             act.recordStatus          = ActionHistoryModifiedIds.Where(m => m.HistoryId == act.history_id).Select(m => m.Status).FirstOrDefault();
             _context.Entry(act).State = EntityState.Modified;
         }
         _context.SaveChangesAsync();
     }
     else
     {
         _gContext = new DAL.GETContext();
         string _log = "";
         UpdateGETByAction(_current, ref _log);
         ActionLog += _log + Environment.NewLine;
     }
     _context.Dispose();
 }
Ejemplo n.º 15
0
        public List <ObservationPointDetails> GetObservationPointDetails(int implement_auto, int get_auto)
        {
            List <ObservationPointDetails> result = new List <ObservationPointDetails>();

            using (var _context = new DAL.GETContext())
            {
                result = (from gop in _context.GET_OBSERVATION_POINTS
                          join gol in _context.GET_OBSERVATION_LIST
                          on gop.observation_list equals gol.observation_list_auto into gol_join
                          from gol2 in gol_join.DefaultIfEmpty()
                          where gop.active == true &&
                          gop.get_auto == get_auto
                          select new ObservationPointDetails
                {
                    Id = gop.observation_point_auto,
                    Name = gop.observation_name,
                    ObservationListId = gop.observation_list != null ? gop.observation_list.Value : 0,
                    InitialLength = gop.initial_length.Value,
                    WornLength = gop.worn_length.Value
                }).ToList();
            }

            return(result);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Record a Component Repair action for a component in Inventory.
        /// </summary>
        /// <param name="componentId"></param>
        /// <param name="cost"></param>
        /// <param name="date"></param>
        /// <param name="comment"></param>
        /// <param name="authUserId"></param>
        /// <returns></returns>
        public bool RecordComponentRepair(int componentId, decimal cost, DateTime date, string comment, long authUserId)
        {
            bool result = false;

            using (var dataEntities = new DAL.GETContext())
            {
                int _changesSaved_GETEvent       = 0;
                int _changesSaved_ComponentEvent = 0;
                int _changesSaved_ImplementEvent = 0;

                // Create a new entry in GET_EVENTS.
                var GETEvent = eventManagement.createGETEvent(authUserId, (int)Core.Domain.GETActionType.Component_Repair, date, comment, cost);
                dataEntities.GET_EVENTS.Add(GETEvent);
                _changesSaved_GETEvent = dataEntities.SaveChanges();

                // Create a new entry in GET_EVENTS_COMPONENT.
                if (_changesSaved_GETEvent > 0)
                {
                    var previousComponentEvent = dataEntities.GET_EVENTS_COMPONENT
                                                 .Where(gc => gc.get_component_auto == componentId)
                                                 .OrderByDescending(ce => ce.component_events_auto)
                                                 .FirstOrDefault();
                    int previousComponentLTD = 0;
                    if (previousComponentEvent != null)
                    {
                        previousComponentLTD = previousComponentEvent.ltd;
                    }

                    var componentEvent = eventManagement.createComponentEvent(componentId, previousComponentLTD, GETEvent.events_auto, 0);
                    dataEntities.GET_EVENTS_COMPONENT.Add(componentEvent);
                    _changesSaved_ComponentEvent = dataEntities.SaveChanges();
                }

                // Create a new entry in GET_EVENTS_IMPLEMENT.
                if (_changesSaved_GETEvent > 0)
                {
                    var GETComponent = dataEntities.GET_COMPONENT.Find(componentId);
                    if (GETComponent != null)
                    {
                        var previousImplementEvent = dataEntities.GET_EVENTS_IMPLEMENT
                                                     .Where(e => e.get_auto == GETComponent.get_auto)
                                                     .OrderByDescending(ie => ie.implement_events_auto)
                                                     .FirstOrDefault();
                        int previousImplementLTD = 0;
                        if (previousImplementEvent != null)
                        {
                            previousImplementLTD = previousImplementEvent.ltd;
                        }

                        var implementEvent = eventManagement.createImplementEvent(GETComponent.get_auto, previousImplementLTD, GETEvent.events_auto);
                        dataEntities.GET_EVENTS_IMPLEMENT.Add(implementEvent);
                        _changesSaved_ImplementEvent = dataEntities.SaveChanges();
                    }
                }

                if ((_changesSaved_GETEvent > 0) && (_changesSaved_ComponentEvent > 0) &&
                    (_changesSaved_ImplementEvent > 0))
                {
                    GETEvent.recordStatus = 0;
                    result = true;
                }
                else
                {
                    GETEvent.recordStatus = 1;
                }
                dataEntities.SaveChanges();
            }

            return(result);
        }
Ejemplo n.º 17
0
        public bool equipmentSetupEvent(long equipmentId, int equipment_smu,
                                        int equipment_ltd, long user_auto)
        {
            //bool result = false;
            long lUserAuto     = user_auto;
            int  iMeterReading = equipment_smu;
            int  iEquipmentLTD = equipment_ltd;

            var  eventDate  = DateTime.Now;
            long eqmtIDAuto = 0;

            using (var dataContext = new DAL.GETContext())
            {
                var eqmt = dataContext.EQUIPMENTs
                           .Where(e => e.equipmentid_auto == equipmentId)
                           .FirstOrDefault();
                if (eqmt != null)
                {
                    eqmtIDAuto = eqmt.equipmentid_auto;
                    eventDate  = eventDate = eqmt.purchase_date != null ? eqmt.purchase_date.Value : eventDate;
                }
            }

            if (eqmtIDAuto == 0)
            {
                return(false);
            }

            var ActionParam = new BLL.Core.Domain.EquipmentActionRecord
            {
                ActionUser = new User {
                    Id = (int)lUserAuto
                },
                EquipmentId         = (int)eqmtIDAuto,
                ReadSmuNumber       = iMeterReading,
                EquipmentActualLife = 0,
                TypeOfAction        = ActionType.EquipmentSetup,
                Cost       = 0.0M,
                Comment    = "Equipment Setup",
                ActionDate = eventDate
            };

            var EquipmentSetupParams = new BLL.Core.Domain.GETEquipmentSetupParams
            {
                UserAuto     = lUserAuto,
                ActionType   = BLL.Core.Domain.GETActionType.Equipment_Setup,
                RecordedDate = DateTime.Now,
                EventDate    = eventDate,
                Comment      = "Equipment Setup",
                Cost         = 0.0M,
                MeterReading = iMeterReading,
                EquipmentLTD = iEquipmentLTD,
                EquipmentId  = equipmentId
            };

            var rm = new BLL.Core.Domain.ResultMessage
            {
                OperationSucceed = false,
                ActionLog        = " ",
                LastMessage      = " ",
                Id = 0
            };

            using (var EquipmentSetupAction = new BLL.Core.Domain.Action(new DAL.UndercarriageContext(), new DAL.GETContext(), ActionParam, EquipmentSetupParams))
            {
                EquipmentSetupAction.Operation.Start();

                if (EquipmentSetupAction.Operation.Status == BLL.Core.Domain.ActionStatus.Close)
                {
                    rm.OperationSucceed = false;
                    rm.ActionLog        = EquipmentSetupAction.Operation.ActionLog;
                    rm.LastMessage      = EquipmentSetupAction.Operation.Message;
                }

                if (EquipmentSetupAction.Operation.Status == BLL.Core.Domain.ActionStatus.Started)
                {
                    EquipmentSetupAction.Operation.Validate();
                }

                if (EquipmentSetupAction.Operation.Status == BLL.Core.Domain.ActionStatus.Invalid)
                {
                    rm.OperationSucceed = false;
                    rm.ActionLog        = EquipmentSetupAction.Operation.ActionLog;
                    rm.LastMessage      = EquipmentSetupAction.Operation.Message;
                }

                if (EquipmentSetupAction.Operation.Status == BLL.Core.Domain.ActionStatus.Valid)
                {
                    EquipmentSetupAction.Operation.Commit();
                }

                if (EquipmentSetupAction.Operation.Status == BLL.Core.Domain.ActionStatus.Failed)
                {
                    rm.OperationSucceed = false;
                    rm.ActionLog        = EquipmentSetupAction.Operation.ActionLog;
                    rm.LastMessage      = EquipmentSetupAction.Operation.Message;
                }

                if (EquipmentSetupAction.Operation.Status == BLL.Core.Domain.ActionStatus.Succeed)
                {
                    rm.OperationSucceed = true;
                    rm.ActionLog        = EquipmentSetupAction.Operation.ActionLog;
                    rm.LastMessage      = EquipmentSetupAction.Operation.Message;
                }

                rm.Id = EquipmentSetupAction.Operation.UniqueId;
            }

            return(rm.OperationSucceed);
        }
Ejemplo n.º 18
0
        public List <GETComponentDetailsVM> ReturnComponentsForGET(int get_auto)
        {
            List <GETComponentDetailsVM> result = new List <GETComponentDetailsVM>();

            using (var dataEntities = new DAL.GETContext())
            {
                var get_components = (from gc in dataEntities.GET_COMPONENT
                                      join g in dataEntities.GET
                                      on gc.get_auto equals g.get_auto
                                      join gsc in dataEntities.GET_SCHEMATIC_COMPONENT
                                      on gc.schematic_component_auto equals gsc.schematic_component_auto
                                      join ct in dataEntities.LU_COMPART_TYPE
                                      on gsc.comparttype_auto equals ct.comparttype_auto
                                      join m in dataEntities.MAKE
                                      on gc.make_auto equals m.make_auto
                                      where gc.get_auto == get_auto && gc.active == true
                                      select new
                {
                    get_component_auto = gc.get_component_auto,
                    condition = 0,
                    require_measurement = gc.req_measure,
                    initial_length = gc.initial_length,
                    worn_length = gc.worn_length,
                    component = ct.comparttype,
                    part_number = gc.part_no,
                    make = m.makedesc,
                    cost = (int)gc.price,
                    life = 0
                }).ToList();

                for (int i = 0; i < get_components.Count; i++)
                {
                    var gcAuto = get_components[i].get_component_auto;

                    var life_record = dataEntities.GET_EVENTS_COMPONENT
                                      .Where(c => c.get_component_auto == gcAuto)
                                      .OrderByDescending(e => e.component_events_auto)
                                      .FirstOrDefault();

                    var inspection_record = dataEntities.GET_COMPONENT_INSPECTION
                                            .Where(c => c.get_component_auto == gcAuto)
                                            .OrderByDescending(e => e.inspection_auto)
                                            .FirstOrDefault();

                    int ltd = 0;
                    if (life_record != null)
                    {
                        ltd = life_record.ltd;
                    }

                    bool    req_measure       = get_components[i].require_measurement.Value;
                    decimal current_condition = 0;
                    if (inspection_record != null)
                    {
                        decimal measurement    = inspection_record.measurement;
                        decimal initial_length = get_components[i].initial_length.Value;
                        decimal worn_length    = get_components[i].worn_length.Value;

                        if ((req_measure == true) && (initial_length - worn_length > 0))
                        {
                            current_condition = ((initial_length - measurement) / (initial_length - worn_length)) * 100;
                        }
                    }

                    if (req_measure == false)
                    {
                        current_condition = -1;
                    }

                    result.Add(new GETComponentDetailsVM
                    {
                        componentId = get_components[i].get_component_auto,
                        condition   = (int)current_condition,
                        component   = get_components[i].component,
                        part_number = get_components[i].part_number,
                        make        = get_components[i].make,
                        cost        = get_components[i].cost,
                        life        = ltd
                    });
                }
            }

            return(result);
        }
Ejemplo n.º 19
0
        public List <GETImplementInventoryVM> returnImplementInventory(long customer, long jobsite, int make, long type,
                                                                       string equipmentSerial, string equipmentUnit, string implementSerial, int status, string userId)
        {
            List <GETImplementInventoryVM> result = new List <GETImplementInventoryVM>();

            // Parse the user id.
            long lUserId = long.TryParse(userId, out lUserId) ? lUserId : 0;

            // Set the initial condition and LTD for an implement.
            int INITIAL_CONDITION = 0; // 0% worn
            int INITIAL_LTD       = 0;

            // Filter by customers that the user has permissions to view.
            List <CustomerIdAndNameDataSet> customers = new List <CustomerIdAndNameDataSet>();
            CustomerManagement customerManagement     = new CustomerManagement();

            customers = customerManagement.getListOfCustomersForLoggedInUser(lUserId);

            // Filter by customer dropdown list.
            long[] customerIds = new long[customers.Count];
            for (int i = 0; i < customers.Count; i++)
            {
                if ((customer == customers[i].customerId) || (customer == 0))
                {
                    customerIds[i] = customers[i].customerId;
                }
            }

            // Parse the status bit positions.
            int status_OnEquipment       = (status & 0x01);
            int status_AwaitingRepairs   = (status & 0x02) >> 1;
            int status_UndergoingRepairs = (status & 0x04) >> 2;
            int status_ReadyForUse       = (status & 0x08) >> 3;
            int status_Scrapped          = (status & 0x10) >> 4;

            // These statuses map to the values in GET_INVENTORY_STATUS table.
            // Needs to be made dynamic eventually.
            int STATUS_ON_EQUIPMENT      = (int)GETInterfaces.Enum.InventoryStatus.On_Equipment;
            int STATUS_AWAITING_REPAIR   = (int)GETInterfaces.Enum.InventoryStatus.Awaiting_Repair;
            int STATUS_UNDERGOING_REPAIR = (int)GETInterfaces.Enum.InventoryStatus.Undergoing_Repair;
            int STATUS_READY_FOR_USE     = (int)GETInterfaces.Enum.InventoryStatus.Ready_for_Use;
            int STATUS_SCRAPPED          = (int)GETInterfaces.Enum.InventoryStatus.Scrapped;

            using (var dataEntities = new DAL.GETContext())
            {
                // Find the implements that are already installed on equipment.
                var statusDescription_OnEquipment = dataEntities.GET_INVENTORY_STATUS.Find(STATUS_ON_EQUIPMENT).status_desc;
                var inventoryOnEquipment          = (from g in dataEntities.GET
                                                     join l in dataEntities.LU_IMPLEMENT
                                                     on g.implement_auto equals l.implement_auto
                                                     join e in dataEntities.EQUIPMENTs
                                                     on g.equipmentid_auto equals e.equipmentid_auto
                                                     join j in dataEntities.CRSF
                                                     on e.crsf_auto equals j.crsf_auto
                                                     join c in dataEntities.CUSTOMERs
                                                     on j.customer_auto equals c.customer_auto
                                                     join m in dataEntities.MAKE
                                                     on g.make_auto equals m.make_auto
                                                     where customerIds.Contains(c.customer_auto) &&
                                                     ((j.crsf_auto == jobsite) || (jobsite == 0)) &&
                                                     ((m.make_auto == make) || (make == 0)) &&
                                                     ((l.implement_auto == type) || (type == 0)) &&
                                                     ((g.impserial.ToString().Contains(implementSerial)) || (implementSerial == null) || (implementSerial == "")) &&
                                                     ((e.serialno.ToString().Contains(equipmentSerial)) || (equipmentSerial == null) || (equipmentSerial == "")) &&
                                                     ((e.unitno.ToString().Contains(equipmentUnit)) || (equipmentUnit == null) || (equipmentUnit == "")) &&
                                                     ((g.on_equipment == true) && (status_OnEquipment == 1))
                                                     select new
                {
                    g.get_auto,
                    condition = INITIAL_CONDITION,
                    c.cust_name,
                    j.site_name,
                    m.makedesc,
                    l.implementdescription,
                    g.impserial,
                    ltd = INITIAL_LTD,
                    status_desc = statusDescription_OnEquipment,
                    e.serialno,
                    e.unitno
                });

                // Find implements that are in inventory (status != onEquipment).
                var inventoryList = (from gi in dataEntities.GET_INVENTORY
                                     join gis in dataEntities.GET_INVENTORY_STATUS
                                     on gi.status_auto equals gis.status_auto
                                     join gw in dataEntities.GET_WORKSHOP
                                     on gi.workshop_auto equals gw.workshop_auto into gw_gi
                                     from gw2 in gw_gi.DefaultIfEmpty()
                                     join gr in dataEntities.GET_REPAIRER
                                     on gw2.repairer_auto equals gr.repairer_auto into gr_gw2
                                     from gr2 in gr_gw2.DefaultIfEmpty()
                                     join g in dataEntities.GET
                                     on gi.get_auto equals g.get_auto
                                     join l in dataEntities.LU_IMPLEMENT
                                     on g.implement_auto equals l.implement_auto
                                     join j in dataEntities.CRSF
                                     on gi.jobsite_auto equals j.crsf_auto
                                     join c in dataEntities.CUSTOMERs
                                     on j.customer_auto equals c.customer_auto
                                     join m in dataEntities.MAKE
                                     on g.make_auto equals m.make_auto
                                     where customerIds.Contains(c.customer_auto) &&
                                     ((j.crsf_auto == jobsite) || (jobsite == 0)) &&
                                     ((m.make_auto == make) || (make == 0)) &&
                                     ((l.implement_auto == type) || (type == 0)) &&
                                     ((equipmentSerial == null) || (equipmentSerial.Trim() == "")) &&
                                     ((equipmentUnit == null) || (equipmentUnit.Trim() == "")) &&
                                     ((g.impserial.ToString().Contains(implementSerial)) || (implementSerial == null) || (implementSerial == "")) &&
                                     (
                                         ((gi.status_auto == STATUS_AWAITING_REPAIR) && (g.on_equipment == false) && (status_AwaitingRepairs == 1)) ||
                                         ((gi.status_auto == STATUS_UNDERGOING_REPAIR) && (g.on_equipment == false) && (status_UndergoingRepairs == 1)) ||
                                         ((gi.status_auto == STATUS_READY_FOR_USE) && (g.on_equipment == false) && (status_ReadyForUse == 1)) ||
                                         ((gi.status_auto == STATUS_SCRAPPED) && (g.on_equipment == false) && (status_Scrapped == 1))
                                     )
                                     select new
                {
                    g.get_auto,
                    condition = INITIAL_CONDITION,
                    c.cust_name,
                    j.site_name,
                    m.makedesc,
                    l.implementdescription,
                    g.impserial,
                    ltd = INITIAL_LTD,
                    gis.status_desc,
                    serialno = "",
                    unitno = "",
                    workshopName = (gw2 != null ? gw2.name : ""),
                    repairerName = (gr2 != null ? gr2.name : "")
                });

                result = inventoryOnEquipment.Select(
                    i => new GETImplementInventoryVM
                {
                    get_auto           = i.get_auto,
                    condition          = i.condition,
                    customer           = i.cust_name,
                    jobsite            = i.site_name,
                    make               = i.makedesc,
                    type               = i.implementdescription,
                    serial_no          = i.impserial,
                    ltd                = i.ltd,
                    status             = i.status_desc,
                    equipment_serialno = (i.serialno != null ? i.serialno : ""),
                    equipment_unitno   = (i.unitno != null ? i.unitno : ""),
                    repairer           = "",
                    workshop           = ""
                }).ToList();

                result.AddRange(
                    inventoryList.Select(
                        i => new GETImplementInventoryVM
                {
                    get_auto           = i.get_auto,
                    condition          = i.condition,
                    customer           = i.cust_name,
                    jobsite            = i.site_name,
                    make               = i.makedesc,
                    type               = i.implementdescription,
                    serial_no          = i.impserial,
                    ltd                = i.ltd,
                    status             = i.status_desc,
                    equipment_serialno = (i.serialno != null ? i.serialno : ""),
                    equipment_unitno   = (i.unitno != null ? i.unitno : ""),
                    repairer           = i.repairerName,
                    workshop           = i.workshopName
                }).ToList()
                    );


                foreach (var item in result)
                {
                    // Find the LTD for each implement.
                    var eventRecord = dataEntities.GET_EVENTS_IMPLEMENT
                                      .Where(s => s.get_auto == item.get_auto)
                                      .OrderByDescending(m => m.implement_events_auto)
                                      .FirstOrDefault();
                    if (eventRecord != null)
                    {
                        item.ltd = eventRecord.ltd;
                    }

                    // Find the remaining life for each implement.
                    var inspectionRecord = dataEntities.GET_IMPLEMENT_INSPECTION
                                           .Where(g => g.get_auto == item.get_auto)
                                           .OrderByDescending(h => h.inspection_auto)
                                           .FirstOrDefault();
                    if (inspectionRecord != null)
                    {
                        item.condition = inspectionRecord.eval;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Record a Component Replace action for a component in Inventory.
        /// </summary>
        /// <param name="componentId"></param>
        /// <param name="cost"></param>
        /// <param name="date"></param>
        /// <param name="comment"></param>
        /// <param name="authUserId"></param>
        /// <returns></returns>
        public bool RecordComponentReplace(int componentId, decimal cost, DateTime date, string comment, long authUserId)
        {
            bool result = false;

            using (var dataEntities = new DAL.GETContext())
            {
                int _changesSaved_GETEvent          = 0;
                int _changesSaved_ImplementEvent    = 0;
                int _changesSaved_NewComponent      = 0;
                int _changesSaved_OldComponentEvent = 0;
                int _changesSaved_NewComponentEvent = 0;

                DateTime recordedDate = DateTime.Now;

                var GETComponent = dataEntities.GET_COMPONENT.Find(componentId);

                // Create a new entry in GET_EVENTS.
                var GETEvent = eventManagement.createGETEvent(authUserId, (int)Core.Domain.GETActionType.Component_Replacement, date, comment, cost, recordedDate);
                dataEntities.GET_EVENTS.Add(GETEvent);
                _changesSaved_GETEvent = dataEntities.SaveChanges();

                // Create a new entry in GET_EVENTS_IMPLEMENT.
                if (_changesSaved_GETEvent > 0)
                {
                    if (GETComponent != null)
                    {
                        var previousImplementEvent = dataEntities.GET_EVENTS_IMPLEMENT
                                                     .Where(e => e.get_auto == GETComponent.get_auto)
                                                     .OrderByDescending(ie => ie.implement_events_auto)
                                                     .FirstOrDefault();
                        int previousImplementLTD = 0;
                        if (previousImplementEvent != null)
                        {
                            previousImplementLTD = previousImplementEvent.ltd;
                        }

                        var implementEvent = eventManagement.createImplementEvent(GETComponent.get_auto, previousImplementLTD, GETEvent.events_auto);
                        dataEntities.GET_EVENTS_IMPLEMENT.Add(implementEvent);
                        _changesSaved_ImplementEvent = dataEntities.SaveChanges();
                    }
                }

                // Create a new component entry.
                GET_COMPONENT newComponent = new GET_COMPONENT
                {
                    make_auto             = GETComponent.make_auto,
                    get_auto              = GETComponent.get_auto,
                    observation_list_auto = GETComponent.observation_list_auto,
                    cmu                      = 0,
                    install_date             = recordedDate,
                    ltd_at_setup             = 0,
                    req_measure              = GETComponent.req_measure,
                    initial_length           = GETComponent.initial_length,
                    worn_length              = GETComponent.worn_length,
                    price                    = cost,
                    part_no                  = GETComponent.part_no,
                    schematic_component_auto = GETComponent.schematic_component_auto,
                    active                   = true
                };
                dataEntities.GET_COMPONENT.Add(newComponent);
                _changesSaved_NewComponent = dataEntities.SaveChanges();

                // Mark the old component as inactive.
                if (_changesSaved_NewComponent > 0)
                {
                    GETComponent.active = false;
                    dataEntities.SaveChanges();
                }

                // Create an entry in GET_EVENTS_COMPONENT for the component being replaced.
                var oldComponentEvent = eventManagement.createComponentEvent(GETComponent.get_component_auto,
                                                                             GETComponent.cmu, GETEvent.events_auto, 1);
                dataEntities.GET_EVENTS_COMPONENT.Add(oldComponentEvent);
                _changesSaved_OldComponentEvent = dataEntities.SaveChanges();

                // Create an entry in GET_EVENTS_COMPONENT for the new component.
                var newComponentEvent = eventManagement.createComponentEvent(newComponent.get_component_auto,
                                                                             newComponent.cmu, GETEvent.events_auto, 0);
                dataEntities.GET_EVENTS_COMPONENT.Add(newComponentEvent);
                _changesSaved_NewComponentEvent = dataEntities.SaveChanges();

                if ((_changesSaved_GETEvent > 0) && (_changesSaved_OldComponentEvent > 0) &&
                    (_changesSaved_NewComponentEvent > 0) && (_changesSaved_ImplementEvent > 0))
                {
                    GETEvent.recordStatus = 0;
                    result = true;
                }
                else
                {
                    oldComponentEvent.recordStatus = 0;
                    newComponentEvent.recordStatus = 1;
                    GETEvent.recordStatus          = 1;
                }
                dataEntities.SaveChanges();
            }

            return(result);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Get the component details (or Measurement Points, according to the new nomenclature).
        /// </summary>
        /// <param name="implement_auto"></param>
        /// <param name="get_auto"></param>
        /// <returns></returns>
        public List <MeasurementPointDetails> GetMeasurementPointDetails(int implement_auto, int get_auto)
        {
            List <MeasurementPointDetails> result = new List <MeasurementPointDetails>();

            using (var _context = new DAL.GETContext())
            {
                if ((implement_auto == 0) && (get_auto > 0))
                {
                    implement_auto = (int)_context.GET.Find(get_auto).implement_auto;
                }

                var MPs_Template = (from ic in _context.GET_IMPLEMENT_COMPARTTYPE
                                    join lc in _context.LU_COMPART_TYPE
                                    on ic.comparttype_auto equals lc.comparttype_auto
                                    join gsc in _context.GET_SCHEMATIC_COMPONENT
                                    on lc.comparttype_auto equals gsc.comparttype_auto
                                    where ic.implement_auto == implement_auto &&
                                    gsc.active == true
                                    select new
                {
                    Id = gsc.schematic_component_auto,
                    Name = lc.comparttype,
                    Make = 0,
                    ObservationListId = 0,
                    InitialLength = 0,
                    WornLength = 0,
                    PartNo = ""
                }).ToList();

                var MPs_Detail = (from gc in _context.GET_COMPONENT
                                  join gsc in _context.GET_SCHEMATIC_COMPONENT
                                  on gc.schematic_component_auto equals gsc.schematic_component_auto
                                  join lc in _context.LU_COMPART_TYPE
                                  on gsc.comparttype_auto equals lc.comparttype_auto
                                  where gc.get_auto == get_auto &&
                                  gc.active == true &&
                                  gsc.active == true
                                  select new
                {
                    Id = gc.get_component_auto,
                    Name = lc.comparttype,
                    Make = gc.make_auto == null ? 0 : gc.make_auto.Value,
                    ObservationListId = gc.observation_list_auto == null ? 0 : gc.observation_list_auto.Value,
                    InitialLength = gc.initial_length.Value,
                    WornLength = gc.worn_length.Value,
                    PartNo = gc.part_no
                }).ToList();

                // If the Measurement Points have not been configured yet, show the template.
                if (MPs_Detail.Count == 0)
                {
                    for (int i = 0; i < MPs_Template.Count; i++)
                    {
                        result.Add(new MeasurementPointDetails
                        {
                            Id   = MPs_Template[i].Id,
                            Name = MPs_Template[i].Name,
                            Make = MPs_Template[i].Make,
                            ObservationListId = MPs_Template[i].ObservationListId,
                            InitialLength     = MPs_Template[i].InitialLength,
                            WornLength        = MPs_Template[i].WornLength,
                            PartNo            = MPs_Template[i].PartNo
                        });
                    }
                }
                else
                {
                    // Show the details.
                    for (int i = 0; i < MPs_Detail.Count; i++)
                    {
                        result.Add(new MeasurementPointDetails
                        {
                            Id   = MPs_Detail[i].Id,
                            Name = MPs_Detail[i].Name,
                            Make = MPs_Detail[i].Make,
                            ObservationListId = MPs_Detail[i].ObservationListId,
                            InitialLength     = MPs_Detail[i].InitialLength,
                            WornLength        = MPs_Detail[i].WornLength,
                            PartNo            = MPs_Detail[i].PartNo
                        });
                    }
                }
            }

            return(result);
        }