Ejemplo n.º 1
0
        /// <summary>
        /// Rerturns a system if user has access to and system is not installed on any equipment
        /// </summary>
        /// <param name="SystemId"></param>
        /// <returns></returns>
        public SystemForSetupVwMdl GetSelectedSystemForInventorySelection(int SystemId)
        {
            var result = new SystemForSetupVwMdl();

            if (!Initialized)
            {
                return(result);
            }

            var m = _context.LU_Module_Sub.Find(SystemId);

            if (m == null || m.equipmentid_auto != null || m.equipmentid_auto > 0)
            {
                return(result);
            }
            result = new SystemForSetupVwMdl {
                Id = m.Module_sub_auto.LongNullableToInt(), JobsiteId = m.crsf_auto.LongNullableToInt(), Serial = m.Serialno, EquipmentId = m.equipmentid_auto.LongNullableToInt(), Side = Side.Unknown, SystemType = (UCSystemType)m.systemTypeEnumIndex
            };
            var logicalSystem = new UCSystem(new DAL.UndercarriageContext(), SystemId);

            result.Make       = logicalSystem.getMake();
            result.Model      = logicalSystem.getModel();
            result.Family     = logicalSystem.getFamily();
            result.Side       = logicalSystem.side;
            result.SystemType = logicalSystem.GetSystemType();
            return(result);
        }
Ejemplo n.º 2
0
 public ActionStatus Start()
 {
     if (Status == ActionStatus.Close)
     {
         string log = "";
         _actionRecord    = UpdateEquipmentByAction(_actionRecord, ref log);
         ActionLog       += log;
         Message          = base.Message;
         DALOldSystem     = _context.LU_Module_Sub.Find(Params.OldSystemId);
         DALNewSystem     = _context.LU_Module_Sub.Find(Params.NewSystemId);
         logicalOldSystem = new UCSystem(_context, Params.OldSystemId, true);
         logicalNewSystem = new UCSystem(_context, Params.NewSystemId, true);
         if (_actionRecord != null && _actionRecord.Id != 0)
         {
             //Step3 Update action record to have component fields
             ActionLog += "Updating Action History ..." + Environment.NewLine;
             var dalActionRecord = _context.ACTION_TAKEN_HISTORY.Find(_actionRecord.Id);
             //TRACK_ACTION_TYPE Table should be updated to show actions related to the new actions and previous ones were unusable
             dalActionRecord.action_type_auto      = (int)ActionType.ReplaceSystemFromInventory;
             dalActionRecord.system_auto_id        = logicalOldSystem.Id;
             _context.Entry(dalActionRecord).State = System.Data.Entity.EntityState.Modified;
             Status  = ActionStatus.Started;
             Message = "Started successfully";
         }
         else
         {
             Status = ActionStatus.Close;
             return(Status);
         }
     }
     return(Status);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns a list of all systems in a specific jobsite which user has access to
        /// </summary>
        /// <param name="JobSiteId"></param>
        /// <param name="PageNo"></param>
        /// <param name="PageSize"></param>
        /// <returns></returns>
        public List <SystemForSetupVwMdl> getSystemListForSetupInInventory(int JobSiteId, int PageNo, int PageSize)
        {
            PageNo = PageNo <= 1 ? 0 : PageNo - 1;
            var result = new List <SystemForSetupVwMdl>();

            if (!Initialized)
            {
                return(result);
            }
            var _access = new BLL.Core.Domain.UserAccess(new SharedContext(), userTableId);

            if (!_access.hasAccessToJobsite(JobSiteId))
            {
                return(result);
            }
            var jobsites = _access.getAccessibleJobsites().Select(k => k.crsf_auto).ToList();
            var systems  = _context.LU_Module_Sub.Where(m => jobsites.Any(k => m.crsf_auto == k) && (m.equipmentid_auto == null || m.equipmentid_auto == 0)).ToList();

            result = systems.Select(m => new SystemForSetupVwMdl {
                Id = m.Module_sub_auto.LongNullableToInt(), JobsiteId = m.crsf_auto.LongNullableToInt(), Serial = m.Serialno, EquipmentId = m.equipmentid_auto.LongNullableToInt(), Side = Side.Unknown, SystemType = (UCSystemType)m.systemTypeEnumIndex
            }).GroupBy(m => m.Id).Select(m => m.First()).Skip(PageNo * PageSize).Take(PageSize).ToList();
            foreach (var system in result)
            {
                var logicalSystem = new UCSystem(new DAL.UndercarriageContext(), system.Id);
                system.Make       = logicalSystem.getMake();
                system.Model      = logicalSystem.getModel();
                system.Family     = logicalSystem.getFamily();
                system.Side       = logicalSystem.side;
                system.SystemType = logicalSystem.GetSystemType();
            }
            return(result.OrderBy(m => m.Serial).ToList());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// If there is any system replacement in the future on the same side with the same system type
        /// Opeation is not allowed
        /// </summary>
        /// <returns></returns>
        private bool ValidateForSystemReplacement()
        {
            var systemReplacements   = _context.ACTION_TAKEN_HISTORY.Where(m => m.equipmentid_auto == _actionRecord.EquipmentId && m.recordStatus == 0 && m.event_date > _actionRecord.ActionDate && m.action_type_auto == (int)ActionType.ReplaceSystemFromInventory).ToList();
            var logicalCurrentSystem = new UCSystem(_context, longNullableToint(Params.oldgeuComponent.module_ucsub_auto));

            //If we cannot find the current system we cannot validate the operation and operation should be continued
            if (logicalCurrentSystem.Id == 0)
            {
                return(true);
            }
            bool isValid = true;

            foreach (var replace in systemReplacements)
            {
                if (replace.system_auto_id != null)
                {
                    var k = new UCSystem(_context, (int)replace.system_auto_id);
                    if (k.Id != 0)
                    {
                        if (logicalCurrentSystem.side == k.side && logicalCurrentSystem.SystemType == k.SystemType)
                        {
                            isValid = false;
                        }
                    }
                }
            }
            return(isValid);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Lors du chargement d'un jeu, initialise les différents onglets
 /// </summary>
 public void InitializeDatabase()
 {
     UCCharacters.InitializeDBCharacters();
     UCPlayers.InitializeDBPlayers();
     UCActions.InitializeDBActions();
     UCClasses.InitializeDBClasses();
     UCGlobalEvents.InitializeDBGlobalEvents();
     UCItems.InitializeDBItems();
     UCItemsInteraction.InitializeDBItemsInteraction();
     UCMenu.InitializeDBMenus();
     UCSystem.InitializeDBSystem();
     UCTerminology.InitializeDBTerminology();
 }
Ejemplo n.º 6
0
        public ActionStatus Start()
        {
            if (Status == ActionStatus.Close)
            {
                var DALSystemTobeInstalled = _context.LU_Module_Sub.Find(Params.Id);
                if (DALSystemTobeInstalled == null)
                {
                    Message = "System cannot be found!";
                    Status  = ActionStatus.Close;
                    return(Status);
                }
                if (DALSystemTobeInstalled.equipmentid_auto != null)
                {
                    Message = "System is already installed!";
                    Status  = ActionStatus.Close;
                    return(Status);
                }

                DALSystemTobeInstalled.equipmentid_auto = Params.EquipmentId;

                string log = "";
                _actionRecord = UpdateEquipmentByAction(_actionRecord, ref log);
                ActionLog    += log;
                Message       = base.Message;
                if (_actionRecord != null && _actionRecord.Id != 0)
                {
                    _Logicalsystem    = new UCSystem(_context, Params.Id);
                    _Logicalequipment = new Equipment(_context, Params.EquipmentId);
                    Status            = ActionStatus.Started;
                    Message           = "Started successfully";
                }
                else
                {
                    Message = "Cannot Start the action!";
                    Status  = ActionStatus.Close;
                    return(Status);
                }
            }
            return(Status);
        }
Ejemplo n.º 7
0
 public ActionStatus Start()
 {
     if (Status == ActionStatus.Close)
     {
         string log = "";
         _actionRecord = UpdateEquipmentByAction(_actionRecord, ref log);
         ActionLog    += log;
         Message       = base.Message;
         if (_actionRecord != null && _actionRecord.Id != 0)
         {
             _Logicalsystem    = new UCSystem(_context, Params.SystemId);
             _Logicalcomponent = new Component(_context, Params.Id);
             Status            = ActionStatus.Started;
             Message           = "Started successfully";
         }
         else
         {
             Message = "Cannot Start the action!";
             Status  = ActionStatus.Close;
             return(Status);
         }
     }
     return(Status);
 }
Ejemplo n.º 8
0
        public ActionStatus Validate()
        {
            ActionLog += "Starting validation ..." + Environment.NewLine;
            if (Status == ActionStatus.Started)
            {
                if (DALOldSystem == null)
                {
                    ActionLog += "System to be replaced not found!";
                    Status     = ActionStatus.Invalid;
                    Message    = "System to be replaced not found!";
                    return(Status);
                }
                if (DALNewSystem == null)
                {
                    ActionLog += "Replacing system not found!";
                    Status     = ActionStatus.Invalid;
                    Message    = "Replacing system not found!";
                    return(Status);
                }
                if (logicalOldSystem == null || logicalOldSystem.Id == 0 || logicalOldSystem.DALEquipment == null)
                {
                    ActionLog += "System to be replaced is not correct!";
                    Status     = ActionStatus.Invalid;
                    Message    = "System to be replaced is not correct!";
                    return(Status);
                }
                if (logicalNewSystem == null || logicalNewSystem.Id == 0)
                {
                    ActionLog += "System to to replace the old one is not found!";
                    Status     = ActionStatus.Invalid;
                    Message    = "System to to replace the old one is not found!";
                    return(Status);
                }
                //If there is a system replacement in the same side and same system type on this equipment in the future, operation is not allowed
                var  replaceActions = _context.ACTION_TAKEN_HISTORY.Where(m => m.equipmentid_auto == DALOldSystem.equipmentid_auto && m.recordStatus == 0 && m.event_date > _actionRecord.ActionDate && m.action_type_auto == (int)ActionType.ReplaceSystemFromInventory).ToList();
                bool isAny          = false;
                foreach (var replace in replaceActions)
                {
                    if (replace.system_auto_id != null)
                    {
                        var k = new UCSystem(_context, (int)replace.system_auto_id);
                        if (k.Id != 0)
                        {
                            if (logicalOldSystem.side == k.side && logicalOldSystem.SystemType == k.SystemType)
                            {
                                isAny = true;
                            }
                        }
                    }
                }
                if (isAny)
                {
                    ActionLog += "Operation is not allowed! At least one system replacement for the system type and side is recorded for a future date!";
                    Status     = ActionStatus.Invalid;
                    Message    = "Operation is not allowed! At least one system replacement for the system type and side is recorded for a future date!";
                    return(Status);
                }
                MMTA = _context.LU_MMTA.Find(logicalOldSystem.DALEquipment.mmtaid_auto);
                if (MMTA == null)
                {
                    ActionLog += "Make and model of the equipment couln'd be found";
                    Status     = ActionStatus.Invalid;
                    Message    = "Make and model of the equipment couln'd be found";
                    return(Status);
                }

                Status  = ActionStatus.Valid;
                Message = "Validation succeed";
                return(Status);
            }
            return(Status);
        }
Ejemplo n.º 9
0
        public BLL.Core.ViewModel.SetupViewModel createNewChain(WSRENewChain newchain)
        {
            BLL.Core.ViewModel.SetupViewModel system = new Core.ViewModel.SetupViewModel();

            ///////////
            // User
            var userEntity = _context.USER_TABLE.Where(m => m.userid == newchain.UserId).FirstOrDefault();

            if (userEntity == null)
            {
                return(system);
            }
            var _user = new BLL.Core.Domain.User
            {
                Id        = userEntity.user_auto.LongNullableToInt(),
                userName  = userEntity.username,
                userStrId = userEntity.userid
            };

            //////////
            // Make
            var makeEntity = _context.MAKE.Where(m => m.make_auto == newchain.MakeAuto).FirstOrDefault();

            if (makeEntity == null)
            {
                return(system);
            }
            MakeForSelectionVwMdl makeVwMdl = new MakeForSelectionVwMdl();

            makeVwMdl.Id     = makeEntity.make_auto;
            makeVwMdl.Title  = makeEntity.makedesc;
            makeVwMdl.Symbol = makeEntity.makeid;
            //makeVwMdl.ExistingCount = 0;

            ////////////
            // Family
            var mmtaEntity = _context.LU_MMTA.Where(m => m.model_auto == newchain.ModelAuto).FirstOrDefault();

            if (mmtaEntity == null)
            {
                return(system);
            }
            var familyEntity = _context.TYPEs.Where(m => m.type_auto == mmtaEntity.type_auto).FirstOrDefault();

            if (familyEntity == null)
            {
                return(system);
            }
            FamilyForSelectionVwMdl familyVwMdl = new FamilyForSelectionVwMdl();

            familyVwMdl.Id     = familyEntity.type_auto;
            familyVwMdl.Title  = familyEntity.typedesc;
            familyVwMdl.Symbol = familyEntity.typeid;
            //familyVwMdl.ExistingCount = 0;

            ///////////
            // Model
            var modelEntity = _context.MODELs.Where(m => m.model_auto == newchain.ModelAuto).FirstOrDefault();

            if (modelEntity == null)
            {
                return(system);
            }
            ModelForSelectionVwMdl modelVwMdl = new ModelForSelectionVwMdl();

            modelVwMdl.Id       = newchain.ModelAuto;
            modelVwMdl.MakeId   = newchain.MakeAuto;
            modelVwMdl.FamilyId = familyVwMdl.Id;
            modelVwMdl.Title    = modelEntity.modeldesc;
            //makeVwMdl.ExistingCount = 0;

            BLL.Core.ViewModel.ComponentSetup linkComponent    = null;
            BLL.Core.ViewModel.ComponentSetup bushingComponent = null;
            BLL.Core.ViewModel.ComponentSetup shoeComponent    = null;

            /////////////////
            // Link Compart
            if (newchain.LinkComponent.compartid_auto > 0)
            {
                var linkCompartEntity = _context.LU_COMPART.Where(m => m.compartid_auto == newchain.LinkComponent.compartid_auto).FirstOrDefault();
                if (linkCompartEntity == null)
                {
                    return(system);
                }
                var linkCompartExtEntity = _context.TRACK_COMPART_EXT
                                           .Where(
                    m => m.compartid_auto == newchain.LinkComponent.compartid_auto).FirstOrDefault();
                if (linkCompartExtEntity == null)
                {
                    return(system);
                }

                linkComponent          = new Core.ViewModel.ComponentSetup();
                linkComponent.Id       = 0;
                linkComponent.SystemId = 0;
                linkComponent.Note     = "";
                linkComponent.Result   = new ResultMessage
                {
                    Id = 0,
                    OperationSucceed = true,
                    LastMessage      = "",
                    ActionLog        = ""
                };
                linkComponent.Validity       = false;
                linkComponent.listPosition   = 1;
                linkComponent.BudgetLife     = newchain.LinkComponent.budget_life;
                linkComponent.HoursAtInstall = newchain.LinkComponent.hours_on_surface;
                linkComponent.InstallDate    = DateTime.Now;
                linkComponent.EquipmentSMU   = 0;
                linkComponent.InstallCost    = newchain.LinkComponent.cost;
                linkComponent.Pos            = 1;
                linkComponent.Points         = 1;

                CompartV linkCompart = new CompartV();
                linkCompart.Id                  = newchain.LinkComponent.compartid_auto;
                linkCompart.CompartStr          = linkCompartEntity.compartid;
                linkCompart.CompartTitle        = linkCompartEntity.compart;
                linkCompart.MeasurementPointsNo = 1;
                linkCompart.DefaultBudgetLife   = linkCompartExtEntity.budget_life.Value;

                CompartTypeV linkCompartType = new CompartTypeV();
                linkCompartType.Id      = 230;
                linkCompartType.Title   = "Link";
                linkCompartType.Order   = 121;
                linkCompart.CompartType = linkCompartType;

                ModelForSelectionVwMdl linkModel = new ModelForSelectionVwMdl();
                linkModel.Id      = newchain.ModelAuto;
                linkModel.Title   = modelEntity.modeldesc;
                linkCompart.Model = linkModel;

                MakeForSelectionVwMdl linkDefaultMake = new MakeForSelectionVwMdl();
                linkDefaultMake.Id      = newchain.MakeAuto;
                linkDefaultMake.Title   = makeVwMdl.Title;
                linkDefaultMake.Symbol  = makeVwMdl.Symbol;
                linkCompart.DefaultMake = linkDefaultMake;

                linkComponent.Compart = linkCompart;
                linkComponent.Grouser = new IdTitleV
                {
                    Id    = 0,
                    Title = ""
                };

                var brandEntity = _context.MAKE.Where(m => m.make_auto == newchain.LinkComponent.brand_auto).FirstOrDefault();
                if (brandEntity == null)
                {
                    return(system);
                }
                linkComponent.Brand = new MakeForSelectionVwMdl
                {
                    Id            = newchain.LinkComponent.brand_auto,
                    Title         = brandEntity.makedesc,
                    Symbol        = brandEntity.makeid,
                    ExistingCount = 0
                };
                linkComponent.ShoeSize = new ShoeSizeV
                {
                    Id    = 0,
                    Title = "",
                    Size  = 0
                };
            }

            ////////////////////
            // Bushing Compart
            if (newchain.BushingComponent.compartid_auto > 0)
            {
                var bushingCompartEntity = _context.LU_COMPART.Where(m => m.compartid_auto == newchain.BushingComponent.compartid_auto).FirstOrDefault();
                if (bushingCompartEntity == null)
                {
                    return(system);
                }
                var bushingCompartExtEntity = _context.TRACK_COMPART_EXT
                                              .Where(
                    m => m.compartid_auto == newchain.BushingComponent.compartid_auto).FirstOrDefault();
                if (bushingCompartExtEntity == null)
                {
                    return(system);
                }

                bushingComponent          = new Core.ViewModel.ComponentSetup();
                bushingComponent.Id       = 0;
                bushingComponent.SystemId = 0;
                bushingComponent.Note     = "";
                bushingComponent.Result   = new ResultMessage
                {
                    Id = 0,
                    OperationSucceed = true,
                    LastMessage      = "",
                    ActionLog        = ""
                };
                bushingComponent.Validity       = false;
                bushingComponent.listPosition   = 1;
                bushingComponent.BudgetLife     = newchain.BushingComponent.budget_life;
                bushingComponent.HoursAtInstall = newchain.BushingComponent.hours_on_surface;
                bushingComponent.InstallDate    = DateTime.Now;
                bushingComponent.EquipmentSMU   = 0;
                bushingComponent.InstallCost    = newchain.BushingComponent.cost;
                bushingComponent.Pos            = 1;
                bushingComponent.Points         = 1;

                CompartV bushingCompart = new CompartV();
                bushingCompart.Id                  = newchain.BushingComponent.compartid_auto;
                bushingCompart.CompartStr          = bushingCompartEntity.compartid;
                bushingCompart.CompartTitle        = bushingCompartEntity.compart;
                bushingCompart.MeasurementPointsNo = 1;
                bushingCompart.DefaultBudgetLife   = bushingCompartExtEntity.budget_life.Value;

                CompartTypeV bushingCompartType = new CompartTypeV();
                bushingCompartType.Id      = 231;
                bushingCompartType.Title   = "Bushing";
                bushingCompartType.Order   = 122;
                bushingCompart.CompartType = bushingCompartType;

                ModelForSelectionVwMdl bushingModel = new ModelForSelectionVwMdl();
                bushingModel.Id      = newchain.ModelAuto;
                bushingModel.Title   = modelEntity.modeldesc;
                bushingCompart.Model = bushingModel;

                MakeForSelectionVwMdl bushingDefaultMake = new MakeForSelectionVwMdl();
                bushingDefaultMake.Id      = newchain.MakeAuto;
                bushingDefaultMake.Title   = makeVwMdl.Title;
                bushingDefaultMake.Symbol  = makeVwMdl.Symbol;
                bushingCompart.DefaultMake = bushingDefaultMake;

                bushingComponent.Compart = bushingCompart;
                bushingComponent.Grouser = new IdTitleV
                {
                    Id    = 0,
                    Title = ""
                };

                var brandBushingEntity = _context.MAKE.Where(m => m.make_auto == newchain.BushingComponent.brand_auto).FirstOrDefault();
                if (brandBushingEntity == null)
                {
                    return(system);
                }
                bushingComponent.Brand = new MakeForSelectionVwMdl
                {
                    Id            = newchain.BushingComponent.brand_auto,
                    Title         = brandBushingEntity.makedesc,
                    Symbol        = brandBushingEntity.makeid,
                    ExistingCount = 0
                };
                bushingComponent.ShoeSize = new ShoeSizeV
                {
                    Id    = 0,
                    Title = "",
                    Size  = 0
                };
            }

            /////////////////
            // Shoe Compart
            if (newchain.ShoeComponent.compartid_auto > 0)
            {
                var shoeCompartEntity = _context.LU_COMPART.Where(m => m.compartid_auto == newchain.ShoeComponent.compartid_auto).FirstOrDefault();
                if (shoeCompartEntity == null)
                {
                    return(system);
                }
                var shoeCompartExtEntity = _context.TRACK_COMPART_EXT
                                           .Where(
                    m => m.compartid_auto == newchain.ShoeComponent.compartid_auto).FirstOrDefault();
                if (shoeCompartExtEntity == null)
                {
                    return(system);
                }

                shoeComponent          = new Core.ViewModel.ComponentSetup();
                shoeComponent.Id       = 0;
                shoeComponent.SystemId = 0;
                shoeComponent.Note     = "";
                shoeComponent.Result   = new ResultMessage
                {
                    Id = 0,
                    OperationSucceed = true,
                    LastMessage      = "",
                    ActionLog        = ""
                };
                shoeComponent.Validity       = false;
                shoeComponent.listPosition   = 1;
                shoeComponent.BudgetLife     = newchain.ShoeComponent.budget_life;
                shoeComponent.HoursAtInstall = newchain.ShoeComponent.hours_on_surface;
                shoeComponent.InstallDate    = DateTime.Now;
                shoeComponent.EquipmentSMU   = 0;
                shoeComponent.InstallCost    = newchain.ShoeComponent.cost;
                shoeComponent.Pos            = 1;
                shoeComponent.Points         = 1;

                CompartV shoeCompart = new CompartV();
                shoeCompart.Id                  = newchain.ShoeComponent.compartid_auto;
                shoeCompart.CompartStr          = shoeCompartEntity.compartid;
                shoeCompart.CompartTitle        = shoeCompartEntity.compart;
                shoeCompart.MeasurementPointsNo = 1;
                shoeCompart.DefaultBudgetLife   = shoeCompartExtEntity.budget_life.Value;

                CompartTypeV shoeCompartType = new CompartTypeV();
                shoeCompartType.Id      = 232;
                shoeCompartType.Title   = "Shoe";
                shoeCompartType.Order   = 123;
                shoeCompart.CompartType = shoeCompartType;

                ModelForSelectionVwMdl shoeModel = new ModelForSelectionVwMdl();
                shoeModel.Id      = newchain.ModelAuto;
                shoeModel.Title   = modelEntity.modeldesc;
                shoeCompart.Model = shoeModel;

                MakeForSelectionVwMdl shoeDefaultMake = new MakeForSelectionVwMdl();
                shoeDefaultMake.Id      = newchain.MakeAuto;
                shoeDefaultMake.Title   = makeVwMdl.Title;
                shoeDefaultMake.Symbol  = makeVwMdl.Symbol;
                shoeCompart.DefaultMake = shoeDefaultMake;

                shoeComponent.Compart = shoeCompart;
                shoeComponent.Grouser = new IdTitleV
                {
                    Id    = GetGrouserId(newchain.ShoeComponent.grouser),
                    Title = newchain.ShoeComponent.grouser
                };

                var brandShoeEntity = _context.MAKE.Where(m => m.make_auto == newchain.ShoeComponent.brand_auto).FirstOrDefault();
                if (brandShoeEntity == null)
                {
                    return(system);
                }
                shoeComponent.Brand = new MakeForSelectionVwMdl
                {
                    Id            = newchain.ShoeComponent.brand_auto,
                    Title         = brandShoeEntity.makedesc,
                    Symbol        = brandShoeEntity.makeid,
                    ExistingCount = 0
                };

                var shoeSizeEntity = _context.SHOE_SIZE.Where(m => m.Id == newchain.ShoeComponent.shoe_size_id).FirstOrDefault();
                if (shoeSizeEntity == null)
                {
                    return(system);
                }
                shoeComponent.ShoeSize = new ShoeSizeV
                {
                    Id    = newchain.ShoeComponent.shoe_size_id,
                    Title = shoeSizeEntity.Title,
                    Size  = shoeSizeEntity.Size
                };
            }

            ///////////////////
            // List Component
            List <BLL.Core.ViewModel.ComponentSetup> Components = new List <Core.ViewModel.ComponentSetup>();

            if (linkComponent != null)
            {
                Components.Add(linkComponent);
            }
            if (bushingComponent != null)
            {
                Components.Add(bushingComponent);
            }
            if (shoeComponent != null)
            {
                Components.Add(shoeComponent);
            }

            ///////////////////
            // Result
            ResultMessage result = new ResultMessage
            {
                Id = 0,
                OperationSucceed = true,
                LastMessage      = "",
                ActionLog        = ""
            };

            ///////////////////////
            // Create new chain
            system.Serial           = newchain.Serial;
            system.JobsiteId        = newchain.JobsiteId;
            system.Type             = UCSystemType.Chain;
            system.EquipmentId      = 0;
            system.SmuAtInstall     = 0;
            system.HoursAtInstall   = newchain.HoursAtInstall;
            system.UserId           = unchecked ((int)userEntity.user_auto);
            system.SetupDate        = DateTime.Now;
            system.InstallationDate = DateTime.Now;
            // Cost, Comment, InstallOnEquipment, Side
            system.Make       = makeVwMdl;
            system.Model      = modelVwMdl;
            system.Family     = familyVwMdl;
            system.Components = Components;
            system.Result     = result;

            BLL.Core.ViewModel.SetupViewModel SystemSetup =
                new UCSystem(new DAL.UndercarriageContext()).CreateAndUpdateSystemForInventory(system, _user);

            return(SystemSetup);
        }
Ejemplo n.º 10
0
Archivo: Action.cs Proyecto: hari81/BLL
        // Update smu and return new life
        private bool UpdateEquipmentLife(int id, int ReadSmuNumber, int UserId, int ActionId, DateTime ActionDate, ref string OperationResult)
        {
            //1- Insert a record in the EQUIPMENT_LIFE Table
            //2- Find all systems which are currently on this Equipment
            //3- Update all system lifes by inserting a record for each system in the System Life table
            //3-1 Update all components on each system by inserting a record for each component in the Component Life Table

            OperationResult += "Checking action Id " + Environment.NewLine;
            if (_context.ACTION_TAKEN_HISTORY.Find(ActionId) == null)
            {
                OperationResult += " Failed!" + System.Environment.NewLine;
                actionLifeUpdate.ActionTakenHistory = null;
                Message = "Action history has not been recorded successfully";
                return(false);
            }

            int currentSMU  = GetEquipmentSerialMeterUnit(id, ActionDate);
            int nextSMU     = GetNextEquipmentSerialMeterUnit(id, ActionDate);
            int currentLife = GetEquipmentLife(id, ActionDate);

            if (ReadSmuNumber < currentSMU || ReadSmuNumber > nextSMU)
            {
                OperationResult += "Checking SMU Failed: For the " + ActionDate + ", accepted SMU is between " + currentSMU + " and " + nextSMU + Environment.NewLine;
                if (nextSMU == int.MaxValue)
                {
                    Message = "Checking SMU Failed: For the " + ActionDate + ", accepted SMU must be greater than" + currentSMU;
                }
                else
                {
                    Message = "Checking SMU Failed: For the " + ActionDate + ", accepted SMU is between " + currentSMU + " and " + nextSMU;
                }
                return(false);
            }

            int increasedSMU = (ReadSmuNumber - currentSMU);

            OperationResult += "Insert Into Equipment Life " + Environment.NewLine;
            _context.EQUIPMENT_LIVES.Add(
                new EQUIPMENT_LIFE
            {
                ActionDate         = ActionDate,
                ActionId           = ActionId,
                ActualLife         = currentLife + increasedSMU,
                EquipmentId        = id,
                SerialMeterReading = ReadSmuNumber,
                Title  = "Inserted by a normal action",
                UserId = UserId
            }
                );
            // If it is the most recent action, update current smu of the equipment
            int actionsAfterThisAction = _context.ACTION_TAKEN_HISTORY.Where(m => m.equipmentid_auto == id && m.recordStatus == 0 && m.event_date > ActionDate && m.recordStatus == 0).Count();

            if (actionsAfterThisAction == 0)
            {
                var geuEquipment = _context.EQUIPMENTs.Find(id);
                if (geuEquipment != null)
                {
                    actionLifeUpdate.EqCurrentSMU      = longNullableToint(geuEquipment.currentsmu);
                    geuEquipment.currentsmu            = ReadSmuNumber;
                    geuEquipment.last_reading_date     = ActionDate;
                    _context.Entry(geuEquipment).State = EntityState.Modified;
                }
            }

            OperationResult += "Start Svaing Changes In Equipment Life and EQUIPMENT" + Environment.NewLine;
            bool _op = true;

            try
            {
                _context.SaveChanges();
                OperationResult += "Update life of Equipment succeeded" + Environment.NewLine;
            }
            catch (Exception e1)
            {
                OperationResult += "Error: " + e1.Message + Environment.NewLine;
                Message          = "Updating the life of EQUIPMENT has been failed!";
                _op              = false;
            }

            OperationResult += "Query all systems " + Environment.NewLine;
            var EqSystems = new Equipment(_context).getEquipmentSystems(id, ActionDate).ToList();

            foreach (var s in EqSystems)
            {
                OperationResult += "Insert system life " + s.Module_sub_auto + Environment.NewLine;
                int currentSystemLife = GetSystemLife(longNullableToint(s.Module_sub_auto), ActionDate);

                int SystemIncreasedLife = increasedSMU;

                if (!s.Life.Any(m => m.ACTION_TAKEN_HISTORY.recordStatus == (int)RecordStatus.Available))
                {
                    SystemIncreasedLife = 0;
                }

                _context.UCSYSTEM_LIFE.Add(
                    new SystemLife
                {
                    ActionDate = ActionDate,
                    ActualLife = currentSystemLife + SystemIncreasedLife,
                    ActionId   = ActionId,
                    SystemId   = s.Module_sub_auto,
                    Title      = "Inserted by a normal action",
                    UserId     = UserId,
                }
                    );
                OperationResult += "Query all components " + Environment.NewLine;
                var SYsComponents = new UCSystem(_context).getSystemComponents((int)s.Module_sub_auto, ActionDate).ToList();
                foreach (var comp in SYsComponents)
                {
                    OperationResult += "Insert component life " + comp.equnit_auto + Environment.NewLine;
                    int currentComponentLife = GetComponentLife(longNullableToint(comp.equnit_auto), ActionDate);
                    _context.COMPONENT_LIFE.Add(
                        new ComponentLife
                    {
                        ActionDate  = ActionDate,
                        ActualLife  = currentComponentLife + SystemIncreasedLife,
                        ActionId    = ActionId,
                        ComponentId = comp.equnit_auto,
                        Title       = "Inserted by a normal action",
                        UserId      = UserId,
                    }
                        );
                }
            }

            OperationResult += "Start Svaing Changes " + Environment.NewLine;
            _op              = true;
            try
            {
                _context.SaveChanges();
                OperationResult += "Update life of Equipment, Systems and all components succeeded" + Environment.NewLine;
            }
            catch (Exception e1)
            {
                OperationResult += "Error: " + e1.Message + Environment.NewLine;
                Message          = "Updating the life has been failed!";
                _op              = false;
            }
            var EqlifeList = _context.EQUIPMENT_LIVES.Where(m => m.ActionId == ActionId);

            if (EqlifeList.Count() > 0)
            {
                actionLifeUpdate.EquipmentLife = EqlifeList.First();
            }
            actionLifeUpdate.SystemsLife    = _context.UCSYSTEM_LIFE.Where(m => m.ActionId == ActionId).ToList();
            actionLifeUpdate.ComponentsLife = _context.COMPONENT_LIFE.Where(m => m.ActionId == ActionId).ToList();
            return(_op);
        }