Пример #1
0
 public new void Dispose()
 {
     if (Status != ActionStatus.Succeed)
     {
         rollBack();
         string str = "";
         if (removingActionRecord != null)
         {
             UpdateEquipmentByAction(removingActionRecord, ref str);
             var ti = _context.TRACK_INSPECTION.Find(Params.EquipmentInspection.inspection_auto);
             if (ti != null && actionLifeUpdate != null && actionLifeUpdate.ActionTakenHistory != null)
             {
                 ti.ActionHistoryId       = actionLifeUpdate.ActionTakenHistory.history_id;
                 _context.Entry(ti).State = EntityState.Modified;
                 try
                 {
                     _context.SaveChanges();
                 }
                 catch (Exception e1)
                 {
                     string m = e1.Message;
                 }
             }
         }
     }
     else
     {
         _gContext = new GETContext();
         rollBackGETAction(removingActionRecord, ref pvActionLog);
         UpdateGETByAction(_actionRecord, ref pvActionLog);
     }
     _context.Dispose();
 }
Пример #2
0
 public Action(DbContext context, DbContext gContext, IEquipmentActionRecord actionRecord, GETEquipmentSetupParams Parameters)
 {
     _context  = (UndercarriageContext)context;
     _gContext = (GETContext)gContext;
     if (Parameters.IsUpdating)
     {
         Operation = new BLL.Core.Actions.UpdateEquipmentSetupAction(context, actionRecord, Parameters);
     }
     else
     {
         Operation = new BLL.GETCore.Repositories.GETEquipmentSetupAction(context, gContext, actionRecord, Parameters);
     }
 }
Пример #3
0
 public new void Dispose()
 {
     if (Status != ActionStatus.Succeed)
     {
         rollBack();
     }
     else
     {
         _gContext = new GETContext();
         UpdateGETByAction(_actionRecord, ref pvActionLog);
     }
     _context.Dispose();
 }
Пример #4
0
        public new void Dispose()
        {
            if (Status != ActionStatus.Succeed)
            {
                _Logicalsystem.detachSystemNoAction();
                rollBack();
            }

            else
            {
                _gContext = new GETContext();
                UpdateGETByAction(_actionRecord, ref pvActionLog);
            }
            _context.Dispose();
        }
Пример #5
0
        /// <summary>
        /// Find and return the previous component event given the GET Component auto
        /// and an event date.
        /// </summary>
        /// <param name="_gContext"></param>
        /// <param name="GETComponentAuto"></param>
        /// <param name="eventDate"></param>
        /// <returns></returns>
        public GET_EVENTS_COMPONENT findPreviousComponentEvent(GETContext _gContext, long GETComponentAuto, DateTime eventDate)
        {
            GET_EVENTS_COMPONENT result     = new GET_EVENTS_COMPONENT();
            DateTime             eventDate2 = new DateTime(eventDate.Year, eventDate.Month, eventDate.Day, 23, 59, 59);

            result = (from c in _gContext.GET_EVENTS_COMPONENT
                      join ge in _gContext.GET_EVENTS
                      on c.events_auto equals ge.events_auto
                      where c.get_component_auto == GETComponentAuto &&
                      ge.event_date <= eventDate2 &&
                      ge.recordStatus == 0
                      orderby ge.event_date descending, ge.events_auto descending
                      select c).FirstOrDefault();

            return(result);
        }
Пример #6
0
        /// <summary>
        /// Find and return the previous equipment event given the equipment Id
        /// and an event date.
        /// </summary>
        /// <param name="_gContext"></param>
        /// <param name="equipmentAuto"></param>
        /// <param name="eventDate"></param>
        /// <returns></returns>
        public GET_EVENTS_EQUIPMENT findPreviousEquipmentEvent(GETContext _gContext, long equipmentAuto, DateTime eventDate)
        {
            GET_EVENTS_EQUIPMENT result     = new GET_EVENTS_EQUIPMENT();
            DateTime             eventDate2 = new DateTime(eventDate.Year, eventDate.Month, eventDate.Day, 23, 59, 59);

            result = (from ee in _gContext.GET_EVENTS_EQUIPMENT
                      join ge in _gContext.GET_EVENTS
                      on ee.events_auto equals ge.events_auto
                      where ee.equipment_auto == equipmentAuto &&
                      ge.event_date <= eventDate2 &&
                      ge.recordStatus == 0
                      orderby ge.event_date descending, ge.events_auto descending
                      select ee).FirstOrDefault();

            return(result);
        }
Пример #7
0
        /// <summary>
        /// Update all implements for an equipment when the SMU is changed.
        /// </summary>
        /// <param name="_gContext"></param>
        /// <param name="equipmentAuto"></param>
        /// <param name="SMU_difference"></param>
        /// <param name="eventAuto"></param>
        /// <param name="eventDate"></param>
        /// <returns></returns>
        public bool updateImplementsForEquipment(GETContext _gContext, long equipmentAuto, int SMU_difference,
                                                 long eventAuto, DateTime eventDate)
        {
            bool result = false;

            var GETs = _gContext.GET
                       .Where(g => g.equipmentid_auto == equipmentAuto && g.on_equipment == true)
                       .ToArray();

            // No implements to update, so just return back.
            if (GETs == null)
            {
                return(true);
            }
            else if (GETs.Length == 0)
            {
                return(true);
            }

            for (int n = 0; n < GETs.Count(); n++)
            {
                int GETAuto = GETs[n].get_auto;

                var previousImplementEvent = findPreviousImplementEvent(_gContext, GETAuto, eventDate);
                if (previousImplementEvent == null)
                {
                    return(false);
                }

                int newLTD = (previousImplementEvent.ltd + SMU_difference);

                var implementEvent = createImplementEvent(GETAuto, newLTD, eventAuto);
                _gContext.GET_EVENTS_IMPLEMENT.Add(implementEvent);
                int _changesSavedImplementEvent = _gContext.SaveChanges();

                if (_changesSavedImplementEvent == 0)
                {
                    return(false);
                }
                else
                {
                    result = updateComponentsForGET(_gContext, GETAuto, SMU_difference, eventAuto, eventDate);
                }
            }

            return(result);
        }
Пример #8
0
        /// <summary>
        /// Update all components for an implement when the SMU is changed.
        /// </summary>
        /// <param name="_gContext"></param>
        /// <param name="GETAuto"></param>
        /// <param name="SMU_difference"></param>
        /// <param name="eventAuto"></param>
        /// <param name="eventDate"></param>
        /// <returns></returns>
        public bool updateComponentsForGET(GETContext _gContext, long GETAuto, int SMU_difference,
                                           long eventAuto, DateTime eventDate)
        {
            bool result = false;

            var GETComponents = _gContext.GET_COMPONENT
                                .Where(gc => gc.get_auto == GETAuto && gc.active == true)
                                .ToArray();

            // Handle case when there are no components.
            if (GETComponents == null)
            {
                return(true);
            }
            else if (GETComponents.Length == 0)
            {
                return(true);
            }

            for (int n = 0; n < GETComponents.Count(); n++)
            {
                int GETComponentAuto = GETComponents[n].get_component_auto;

                var previousComponentEvent = findPreviousComponentEvent(_gContext, GETComponentAuto, eventDate);
                if (previousComponentEvent == null)
                {
                    return(false);
                }

                int newLTD = (previousComponentEvent.ltd + SMU_difference);

                var componentEvent = createComponentEvent(GETComponentAuto, newLTD, eventAuto, 0);
                _gContext.GET_EVENTS_COMPONENT.Add(componentEvent);
                int _changesSavedComponentEvent = _gContext.SaveChanges();

                if (_changesSavedComponentEvent == 0)
                {
                    return(false);
                }
                else
                {
                    result = true;
                }
            }

            return(result);
        }
Пример #9
0
        private DateTime?GetDateOfLastComponentEvent(int componentId, int action, GETContext _context)
        {
            DateTime?result = null;

            var lastEvent = (from e in _context.GET_EVENTS
                             join ec in _context.GET_EVENTS_COMPONENT
                             on e.events_auto equals ec.events_auto
                             where ec.get_component_auto == componentId &&
                             e.action_auto == action
                             orderby e.event_date descending, e.events_auto descending
                             select new
            {
                eventDate = e.event_date
            }).FirstOrDefault();

            if (lastEvent != null)
            {
                result = lastEvent.eventDate;
            }

            return(result);
        }
Пример #10
0
        private DateTime?GetDateOfLastImplementEvent(int getAuto, int action, GETContext _context)
        {
            DateTime?result = null;

            var lastEvent = (from e in _context.GET_EVENTS
                             join ei in _context.GET_EVENTS_IMPLEMENT
                             on e.events_auto equals ei.events_auto
                             where ei.get_auto == getAuto &&
                             e.action_auto == action
                             orderby e.event_date descending, e.events_auto descending
                             select new
            {
                eventDate = e.event_date
            }).FirstOrDefault();

            if (lastEvent != null)
            {
                result = lastEvent.eventDate;
            }

            return(result);
        }
Пример #11
0
        /// <summary>
        /// Update an existing Inventory record for an implement.
        /// </summary>
        /// <param name="details"></param>
        /// <param name="jobsiteId"></param>
        /// <param name="authUserId"></param>
        /// <param name="_context"></param>
        /// <returns>The ID of the updated inventory record.</returns>
        public int UpdateInventoryRecord(ImplementDetails details, int jobsiteId, long authUserId, GETContext _context)
        {
            int result = -1;

            try
            {
                GET_INVENTORY inventoryRecord = _context.GET_INVENTORY.Where(w => w.get_auto == details.Id).FirstOrDefault();
                if (inventoryRecord != null)
                {
                    inventoryRecord.modified_date = DateTime.Now;
                    inventoryRecord.modified_user = (int)authUserId;
                    inventoryRecord.ltd           = (int)details.ImplementHoursAtSetup;

                    int _changesSaved = _context.SaveChanges();
                    if (_changesSaved > 0)
                    {
                        result = inventoryRecord.inventory_auto;
                    }
                }
            }
            catch (Exception ex1)
            {
            }

            return(result);
        }
Пример #12
0
        /// <summary>
        /// Create a new inventory record for an implement.
        /// </summary>
        /// <param name="details"></param>
        /// <param name="jobsiteId"></param>
        /// <param name="authUserId"></param>
        /// <param name="_context"></param>
        /// <returns>The ID of the created inventory record.</returns>
        public int InsertIntoInventory(ImplementDetails details, int jobsiteId, long authUserId, GETContext _context)
        {
            int result = -1;

            try
            {
                GET_INVENTORY newGETinInventory = new GET_INVENTORY();
                newGETinInventory.get_auto      = details.Id;
                newGETinInventory.jobsite_auto  = jobsiteId;
                newGETinInventory.status_auto   = (int)GETInterfaces.Enum.InventoryStatus.Ready_for_Use;
                newGETinInventory.modified_date = DateTime.Now;
                newGETinInventory.modified_user = (int)authUserId;
                newGETinInventory.ltd           = (int)details.ImplementHoursAtSetup;
                newGETinInventory.workshop_auto = null;

                _context.GET_INVENTORY.Add(newGETinInventory);
                int _changesSaved = _context.SaveChanges();

                if (_changesSaved > 0)
                {
                    result = newGETinInventory.inventory_auto;
                }
            }
            catch (Exception ex1)
            {
            }

            return(result);
        }
Пример #13
0
 public Action(DbContext context, DbContext gContext, IEquipmentActionRecord actionRecord, MoveImplementToInventoryParams Parameters)
 {
     _context  = (UndercarriageContext)context;
     _gContext = (GETContext)gContext;
     Operation = new BLL.GETCore.Repositories.MoveImplementToInventoryAction(context, gContext, actionRecord, Parameters);
 }
Пример #14
0
 public Action(GETContext context)
 {
     _gContext = context;
 }
Пример #15
0
        /// <summary>
        /// Update all implements and components with new SMU.
        /// </summary>
        /// <param name="_gContext"></param>
        /// <param name="equipmentAuto"></param>
        /// <param name="meter_reading"></param>
        /// <param name="userId"></param>
        /// <param name="eventDate"></param>
        /// <param name="comment"></param>
        /// <param name="cost"></param>
        /// <returns></returns>
        public long cascadeUpdateWithNewSMU(GETContext _gContext, long equipmentAuto, int meter_reading,
                                            long userId, DateTime eventDate, string comment, decimal cost)
        {
            long ERROR_CODE = -1;
            long result     = ERROR_CODE;

            // Find the previous equipment event.
            var previousEquipmentEvent = findPreviousEquipmentEvent(_gContext, equipmentAuto, eventDate);

            if (previousEquipmentEvent == null)
            {
                return(ERROR_CODE);
            }

            int SMU_difference = meter_reading - previousEquipmentEvent.smu;
            int newLTD         = (previousEquipmentEvent.ltd + SMU_difference);

            if (SMU_difference > 0)
            {
                // Create an event record.
                int actionAuto      = (int)GETActionType.Equipment_SMU_Changed;
                var SMUChangedEvent = createGETEvent(userId, actionAuto, eventDate, comment, cost);
                _gContext.GET_EVENTS.Add(SMUChangedEvent);
                int _changesSaved = _gContext.SaveChanges();

                if (_changesSaved > 0)
                {
                    // Create an equipment event.
                    var equipmentEvent = createEquipmentEvent(SMUChangedEvent.events_auto, equipmentAuto, meter_reading, newLTD);
                    _gContext.GET_EVENTS_EQUIPMENT.Add(equipmentEvent);
                    int _changesSavedEquipmentEvent = _gContext.SaveChanges();

                    if (_changesSavedEquipmentEvent > 0)
                    {
                        // Create implement events
                        bool update_success = updateImplementsForEquipment(_gContext, equipmentAuto, SMU_difference, SMUChangedEvent.events_auto, eventDate);
                        if (update_success)
                        {
                            result = SMUChangedEvent.events_auto;
                        }
                        else
                        {
                            // Failed to save Implement or Component events.
                            SMUChangedEvent.recordStatus = 1;
                            result = ERROR_CODE;
                        }
                    }
                    else
                    {
                        // Failed to save Equipment event.
                        SMUChangedEvent.recordStatus = 1;
                        result = ERROR_CODE;
                    }
                }
                else
                {
                    // Failed to save new GET_EVENT.
                    SMUChangedEvent.recordStatus = 1;
                    result = ERROR_CODE;
                }
            }
            else if (SMU_difference == 0)
            {
                result = 0;
            }

            return(result);
        }
Пример #16
0
 public Action(GETContext gContext, UndercarriageContext UCContext)
 {
     _gContext = gContext;
     _context  = UCContext;
 }
Пример #17
0
 public UserManagement()
 {
     this._context = new GETContext();
 }
Пример #18
0
 public Action(DbContext context, IEquipmentActionRecord actionRecord, GETFlagIgnoredParams Parameters)
 {
     _gContext = (GETContext)context;
     Operation = new BLL.GETCore.Repositories.GETFlagIgnoredAction(context, actionRecord, Parameters);
 }
Пример #19
0
        /// <summary>
        /// Update the GET_INVENTORY record for a specified implement.
        /// </summary>
        /// <param name="details"></param>
        /// <param name="jobsiteId"></param>
        /// <param name="authUserId"></param>
        /// <param name="_context"></param>
        /// <returns>The ID of the GET_INVENTORY record that was inserted or updated.</returns>
        public int UpdateImplementInInventory(ImplementDetails details, int jobsiteId, long authUserId, GETContext _context)
        {
            int result = 0;

            // Check if the record already exists in inventory.
            var inventoryRecordExists = _context.GET_INVENTORY.Where(w => w.get_auto == details.Id).Any();

            if (!inventoryRecordExists)
            {
                // Add a new inventory record for this implement.
                result = InsertIntoInventory(details, jobsiteId, authUserId, _context);
            }
            else
            {
                // Update the existing inventory record for this implement.
                result = UpdateInventoryRecord(details, jobsiteId, authUserId, _context);
            }

            return(result);
        }
Пример #20
0
 public ImplementTemplateManager()
 {
     this._context     = new GETContext();
     this._userManager = new UserManagement();
 }
Пример #21
0
        public int CreateNewMeasurementPoints(int get_auto, GETContext _context)
        {
            int result        = 0;
            int _changesSaved = 0;

            // 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);
            long implement_auto = GT.implement_auto.Value;

            List <int> comparttypes = (from ic in _context.GET_IMPLEMENT_COMPARTTYPE
                                       join g in _context.GET
                                       on ic.implement_auto equals g.implement_auto
                                       where g.get_auto == get_auto
                                       select ic.comparttype_auto
                                       ).ToList();

            List <string> schematics = _context.LU_IMPLEMENT.Find(implement_auto)
                                       .schematic_auto_multiple
                                       .Split('_')
                                       .ToList();

            var measurementPoints = (from gsc in _context.GET_SCHEMATIC_COMPONENT
                                     join lc in _context.LU_COMPART_TYPE
                                     on gsc.comparttype_auto equals lc.comparttype_auto
                                     where comparttypes.Contains(gsc.comparttype_auto) &&
                                     schematics.Contains(gsc.schematic_auto.ToString()) &&
                                     gsc.active == true
                                     select new
            {
                Id = lc.comparttype,
                SchematicComponent = gsc.schematic_component_auto
            }).ToList();

            // There are no records, i.e. this is setting up components for a new implement.
            if (existingRecords.Count == 0)
            {
                for (int i = 0; i < measurementPoints.Count; i++)
                {
                    GET_COMPONENT gc = new GET_COMPONENT();
                    gc.get_auto                 = get_auto;
                    gc.cmu                      = 0;
                    gc.install_date             = GT.created_date;
                    gc.ltd_at_setup             = (int)GT.impsetup_hours.Value;
                    gc.req_measure              = false;
                    gc.initial_length           = 0;
                    gc.worn_length              = 0;
                    gc.price                    = 0;
                    gc.part_no                  = "";
                    gc.active                   = true;
                    gc.schematic_component_auto = measurementPoints[i].SchematicComponent;
                    _context.GET_COMPONENT.Add(gc);
                }

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

            return(result);
        }
Пример #22
0
 public Action(DbContext context, IEquipmentActionRecord actionRecord, GETUndoComponentReplacementParams Parameters)
 {
     _gContext = (GETContext)context;
     Operation = new BLL.GETCore.Repositories.GETUndoComponentReplacementAction(context, actionRecord, Parameters);
 }