예제 #1
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);
        }
예제 #2
0
        public ActionStatus Commit()
        {
            if (Status != ActionStatus.Valid)
            {
                ActionLog += "Operation Status is not valid" + Environment.NewLine;
                Status     = ActionStatus.Failed;
                return(Status);
            }
            var Components          = _context.GENERAL_EQ_UNIT.Where(m => m.module_ucsub_auto == Params.Id);
            var paramsId            = Params.Components.Select(n => n.Id).ToList();
            var removiongComponents = _context.GENERAL_EQ_UNIT.Where(m => m.module_ucsub_auto == Params.Id && !paramsId.Any(k => m.equnit_auto == k));
            var childToBeRemoved    = new List <GENERAL_EQ_UNIT>();

            foreach (var parent in removiongComponents)
            {
                var childComparts = new Compart(_context, parent.compartid_auto).getChildComparts().Select(m => m.compartid_auto);
                childToBeRemoved.AddRange(Components.Where(m => childComparts.Any(k => k == m.compartid_auto)).ToList());
            }
            removiongComponents.ToList().AddRange(childToBeRemoved);
            //All child components will be removed automatically
            if (removeComponents(removiongComponents.GroupBy(m => m.equnit_auto).Select(m => m.FirstOrDefault()).ToList()))
            {
                //Components which are not in the list of current components should be removed from installed components!
                //Just for monitoring purposes
                string message = "";
                message += "Components removed successfully";
            }


            //↓↓↓↓↓ Adding all child compartments
            List <ComponentSetup> ChildsList = new List <ComponentSetup>();

            foreach (var cmpnt in Params.Components.OrderBy(m => m.InstallDate))
            {
                var childCompartments = _context.COMPART_PARENT_RELATION.Where(m => m.ParentCompartId == cmpnt.Compart.Id).Select(m => m.ParentCompartment).ToList();
                int childPos          = cmpnt.Pos + 1;
                foreach (var childCompart in childCompartments)
                {
                    ChildsList.Add(new ComponentSetup
                    {
                        Brand      = cmpnt.Brand,
                        BudgetLife = cmpnt.BudgetLife,
                        Compart    = new CompartV {
                            Id = childCompart.compartid_auto, CompartStr = childCompart.compartid, CompartTitle = childCompart.compart, CompartType = new CompartTypeV {
                                Id = childCompart.comparttype_auto, Title = childCompart.LU_COMPART_TYPE.comparttype, Order = childCompart.LU_COMPART_TYPE.sorder ?? 1
                            }
                        },
                        EquipmentSMU   = cmpnt.EquipmentSMU,
                        Grouser        = cmpnt.Grouser,
                        HoursAtInstall = cmpnt.HoursAtInstall,
                        Id             = 0,
                        InstallCost    = 0,
                        InstallDate    = cmpnt.InstallDate.ToLocalTime().Date,
                        Note           = cmpnt.Note,
                        Pos            = childPos,
                        Result         = new ResultMessage(),
                        ShoeSize       = cmpnt.ShoeSize,
                        SystemId       = cmpnt.SystemId,
                        Validity       = cmpnt.Validity,
                        listPosition   = -1,
                        Points         = -1
                    });
                    childPos++;
                }
            }
            Params.Components.AddRange(ChildsList);
            //↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

            foreach (var comp in Params.Components.Where(m => m.Id == 0))
            {
                var componentParam = new SetupComponentParams
                {
                    BudgetLife = comp.BudgetLife,
                    CMU        = comp.HoursAtInstall,
                    CompartId  = comp.Compart.Id,
                    Cost       = comp.InstallCost,
                    Id         = comp.Id,
                    Life       = comp.HoursAtInstall,
                    UserId     = Params.UserId,
                    UserName   = _current.ActionUser.userName
                };
                if (comp.Id == 0) //New Component Added
                {
                    var LogicalComponent = new Component(new UndercarriageContext());
                    comp.Result = LogicalComponent.CreateNewComponent(comp, _current.ActionUser.Id, _current.ActionUser.userName).Result;
                    if (comp.Result.OperationSucceed)
                    {
                        IEquipmentActionRecord EquipmentActionForComp = new BLL.Core.Domain.EquipmentActionRecord
                        {
                            EquipmentId   = Params.EquipmentId,
                            ReadSmuNumber = comp.EquipmentSMU,
                            TypeOfAction  = ActionType.InstallComponentOnSystemOnEquipment,
                            ActionDate    = comp.InstallDate.ToLocalTime().Date,
                            ActionUser    = _current.ActionUser,
                            Cost          = comp.InstallCost,
                            Comment       = "Component Setup in Update Undercarriage Setup",
                        };
                        using (Domain.Action compAction = new Domain.Action(new UndercarriageContext(), EquipmentActionForComp, new BLL.Core.Domain.InstallComponentOnSystemParams {
                            Id = LogicalComponent.Id, Position = (byte)comp.Pos, SystemId = Params.Id, side = Params.Side
                        }))
                        {
                            if (compAction.Operation.Start() == ActionStatus.Started)
                            {
                                if (compAction.Operation.Validate() == ActionStatus.Valid)
                                {
                                    if (compAction.Operation.Commit() == ActionStatus.Succeed)
                                    {
                                        comp.Result.Id = compAction.Operation.UniqueId;
                                        comp.Result.OperationSucceed = true;
                                        comp.SystemId = Params.Id;
                                    }
                                }
                            }
                            comp.Result.LastMessage = compAction.Operation.Message;
                            comp.Result.ActionLog   = compAction.Operation.ActionLog;
                        }
                    }
                }
            }
            Available();
            UpdateLtds();
            AdjustLives();
            MakeExistingActionsAvailable();
            if (!MakeOtherSystemsOnline())
            {
                Status = ActionStatus.Failed;
            }
            else
            {
                Status = ActionStatus.Succeed;
            }
            return(Status);
        }