Ejemplo n.º 1
0
        public void GhostPlayerCollision(ComponentPosition positionComponent, ComponentCollision collisionComponent, ComponentVelocity velocityComponent, ComponentPosition fpositionComponent, ComponentCollision fcollisionComponent, ComponentVelocity fvelocityComponent, ComponentLife healthComponent, string entname, List <Entity> EntList, ComponentAudio faudioComponent)
        {
            int test = healthComponent.health();

            if (test == 1)
            {
                if (entname == "Ghost")
                {
                    if (positionComponent.Position.X > fpositionComponent.Position.X - 1 && positionComponent.Position.X < fpositionComponent.Position.X + 1 && positionComponent.Position.Y > fpositionComponent.Position.Y - 1 && positionComponent.Position.Y < fpositionComponent.Position.Y + 1)
                    {
                        GameScene.gameInstance.test();
                        faudioComponent.Start();
                    }
                }
                else
                {
                    if (fpositionComponent.Position.X > positionComponent.Position.X - 1 && fpositionComponent.Position.X < positionComponent.Position.X + 1 && fpositionComponent.Position.Y > positionComponent.Position.Y - 1 && fpositionComponent.Position.Y < positionComponent.Position.Y + 1)
                    {
                        GameScene.gameInstance.test();
                        faudioComponent.Start();
                    }
                }
            }
            else
            {
                if (entname == "Ghost")
                {
                    if (positionComponent.Position.X > fpositionComponent.Position.X - 1 && positionComponent.Position.X < fpositionComponent.Position.X + 1 && positionComponent.Position.Y > fpositionComponent.Position.Y - 1 && positionComponent.Position.Y < fpositionComponent.Position.Y + 1)
                    {
                        healthComponent.down();
                        fpositionComponent.Position = new Vector3(0.0f, 0.25f, -29.5f);
                        foreach (Entity x in EntList)
                        {
                            if (x.Name == "Ghost")
                            {
                                List <IComponent> components             = x.Components;
                                IComponent        GhostpositionComponent = components.Find(delegate(IComponent component)
                                {
                                    return(component.ComponentType == ComponentTypes.COMPONENT_POSITION);
                                });
                                GhostResest((ComponentPosition)GhostpositionComponent);
                            }
                        }
                        ghostCount = 0;
                        faudioComponent.Start();
                    }
                }
                else
                {
                    if (fpositionComponent.Position.X > positionComponent.Position.X - 1 && fpositionComponent.Position.X < positionComponent.Position.X + 1 && fpositionComponent.Position.Y > positionComponent.Position.Y - 1 && fpositionComponent.Position.Y < positionComponent.Position.Y + 1)
                    {
                        healthComponent.down();
                        positionComponent.Position = new Vector3(0.0f, 0.25f, -29.5f);
                        foreach (Entity x in EntList)
                        {
                            if (x.Name == "Ghost")
                            {
                                List <IComponent> components             = x.Components;
                                IComponent        GhostpositionComponent = components.Find(delegate(IComponent component)
                                {
                                    return(component.ComponentType == ComponentTypes.COMPONENT_POSITION);
                                });
                                GhostResest((ComponentPosition)GhostpositionComponent);
                            }
                        }
                        ghostCount = 0;
                        faudioComponent.Start();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public ActionStatus Commit()
        {
            ActionLog += "Commiting the Operation ..." + Environment.NewLine;
            if (Status != ActionStatus.Valid)
            {
                ActionLog += "Operation Status is not valid" + Environment.NewLine;
                Status     = ActionStatus.Failed;
                return(Status);
            }
            int tempEQId = longNullableToint(DALOldSystem.equipmentid_auto);

            DALNewSystem.equipmentid_auto            = tempEQId;
            DALNewSystem.crsf_auto                   = logicalOldSystem.DALEquipment.crsf_auto;
            DALNewSystem.equipment_LTD_at_attachment = _actionRecord.EquipmentActualLife;
            DALNewSystem.modifiedDate                = _actionRecord.ActionDate.ToLocalTime().Date;
            DALNewSystem.SMU_at_install              = _actionRecord.ReadSmuNumber;

            //When systems are created these values are not added!!!
            //So when system is going to be placed in inventory, values are set
            DALOldSystem.crsf_auto             = logicalOldSystem.DALEquipment.crsf_auto;
            DALOldSystem.system_LTD_on_removal = logicalOldSystem.GetSystemLife(_actionRecord.ActionDate);
            DALOldSystem.make_auto             = MMTA.make_auto;
            DALOldSystem.model_auto            = MMTA.model_auto;
            DALOldSystem.type_auto             = MMTA.type_auto;
            DALOldSystem.equipmentid_auto      = null;

            //Update any recorded life for the old system which actualy should belong to the new one
            var systemRecordedLifes = _context.UCSYSTEM_LIFE.Where(m => m.SystemId == logicalOldSystem.Id && m.ActionDate > _actionRecord.ActionDate).ToList();

            foreach (var life in systemRecordedLifes)
            {
                var athistoryFuture      = _context.ACTION_TAKEN_HISTORY.Find(life.ActionId);
                int EqLifeInFutureAction = 0;
                int EqSMUInFutureAction  = 0;
                if (athistoryFuture != null)
                {
                    if (athistoryFuture.system_auto_id == DALOldSystem.Module_sub_auto)
                    {
                        athistoryFuture.system_auto_id        = DALNewSystem.Module_sub_auto;
                        _context.Entry(athistoryFuture).State = EntityState.Modified;
                    }
                    EqLifeInFutureAction = athistoryFuture.equipment_ltd;
                    EqSMUInFutureAction  = athistoryFuture.equipment_smu;
                }
                int newSystemActualLife = logicalNewSystem.GetSystemLife(_actionRecord.ActionDate);

                if (EqLifeInFutureAction != 0 && EqLifeInFutureAction > _actionRecord.EquipmentActualLife)
                {
                    newSystemActualLife += (EqLifeInFutureAction - _actionRecord.EquipmentActualLife);
                }
                else if (EqSMUInFutureAction != 0 && EqSMUInFutureAction > _actionRecord.ReadSmuNumber)
                {
                    newSystemActualLife += (EqSMUInFutureAction - _actionRecord.ReadSmuNumber);
                }

                life.ActualLife            = newSystemActualLife;
                life.SystemId              = logicalNewSystem.Id;
                life.Title                 = "Updated because of system replacement in the past";
                _context.Entry(life).State = EntityState.Modified;
            }
            foreach (var Comp in logicalOldSystem.Components)
            {
                //Update all life records of the old components which belongs to the new components
                var componentRecordedLifes = _context.COMPONENT_LIFE.Where(m => m.ComponentId == Comp.equnit_auto && m.ActionDate > _actionRecord.ActionDate).ToList();
                foreach (var life in componentRecordedLifes)
                {
                    var newcmpnt = GetComponentBasedOnTypeAndPositionFromOldSystemToTheNewOne(Comp.equnit_auto);
                    //         ↓↓↓↓↓     Means there is no component with the same type and position on the new system
                    if (newcmpnt == null)
                    {
                        continue;
                    }
                    var athistoryFuture      = _context.ACTION_TAKEN_HISTORY.Find(life.ActionId);
                    int EqLifeInFutureAction = 0;
                    int EqSMUInFutureAction  = 0;
                    //     ↓↓↓↓↓ Updating a field in the ACTION_TAKEN_HISTORY Table to point to the new component
                    if (athistoryFuture != null)
                    {
                        if (athistoryFuture.equnit_auto == Comp.equnit_auto)
                        {
                            athistoryFuture.equnit_auto           = newcmpnt.Id;
                            _context.Entry(athistoryFuture).State = EntityState.Modified;
                        }
                        EqLifeInFutureAction = athistoryFuture.equipment_ltd;
                        EqSMUInFutureAction  = athistoryFuture.equipment_smu;
                    }
                    int newComponentActualLife = newcmpnt.GetComponentLife(_actionRecord.ActionDate);

                    if (EqLifeInFutureAction != 0 && EqLifeInFutureAction > _actionRecord.EquipmentActualLife)
                    {
                        newComponentActualLife += (EqLifeInFutureAction - _actionRecord.EquipmentActualLife);
                    }
                    else if (EqSMUInFutureAction != 0 && EqSMUInFutureAction > _actionRecord.ReadSmuNumber)
                    {
                        newComponentActualLife += (EqSMUInFutureAction - _actionRecord.ReadSmuNumber);
                    }

                    life.ActualLife            = newComponentActualLife;
                    life.ComponentId           = newcmpnt.Id;
                    life.Title                 = "Updated because of system replacement in the past";
                    _context.Entry(life).State = EntityState.Modified;
                }
                Comp.equipmentid_auto = null;
                //This line is Commented because of an issue in the inspection page.
                //Comp.cmu = GetComponentLife(longNullableToint(Comp.equnit_auto), _actionRecord.ActionDate);
                _context.Entry(Comp).State = EntityState.Modified;
            }

            foreach (var Comp in logicalNewSystem.Components)
            {
                Comp.equipmentid_auto      = DALNewSystem.equipmentid_auto;
                Comp.side                  = (byte?)logicalOldSystem.side;
                Comp.eq_smu_at_install     = GetEquipmentSerialMeterUnit(tempEQId, _actionRecord.ActionDate);
                Comp.system_LTD_at_install = logicalNewSystem.GetSystemLife(_actionRecord.ActionDate);
                Comp.eq_ltd_at_install     = GetEquipmentLife(tempEQId, _actionRecord.ActionDate);
                //Comp.cmu = GetComponentLife(longNullableToint(Comp.equnit_auto), _actionRecord.ActionDate);
                Comp.smu_at_install        = Comp.eq_smu_at_install;
                Comp.date_installed        = _actionRecord.ActionDate;
                _context.Entry(Comp).State = EntityState.Modified;
            }

            //Step3 Update action record to have system 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
            dalActionRecord.action_type_auto      = (int)ActionType.ReplaceSystemFromInventory;
            dalActionRecord.cost                  = (long)_actionRecord.Cost;
            dalActionRecord.system_auto_id        = Params.OldSystemId;
            dalActionRecord.system_auto_id_new    = Params.NewSystemId;
            dalActionRecord.recordStatus          = (int)RecordStatus.Available;
            _context.Entry(dalActionRecord).State = System.Data.Entity.EntityState.Modified;

            //Update all inspections after this change out
            var inspections = _context.EQUIPMENTs.Find(_actionRecord.EquipmentId).TRACK_INSPECTION.Where(m => m.inspection_date > _actionRecord.ActionDate).ToList();

            foreach (var inspect in inspections)
            {
                var details = inspect.TRACK_INSPECTION_DETAIL.Where(m => m.UCSystemId == Params.OldSystemId).ToList();
                foreach (var d in details)
                {
                    var Newcmpnt = GetComponentBasedOnTypeAndPositionFromOldSystemToTheNewOne(d.track_unit_auto);
                    // Does the new component found in the inspection details?
                    if (Newcmpnt != null)
                    {
                        InspectionImpact impact = d.TRACK_INSPECTION.impact == 2 ? InspectionImpact.High : InspectionImpact.Low;
                        int ToolId = d.tool_auto == null ? 0 : (int)d.tool_auto;
                        if (Newcmpnt.Id != 0)
                        {
                            d.worn_percentage = Newcmpnt.CalcWornPercentage(ConvertFrom(MeasurementType.Milimeter, d.reading), ToolId, impact);
                            char evl = '-';
                            if (Newcmpnt.GetEvalCodeByWorn(d.worn_percentage, out evl))
                            {
                                d.eval_code = evl.ToString();
                            }
                            d.hours_on_surface = Newcmpnt.GetComponentLife(inspect.inspection_date);
                        }
                        d.track_unit_auto       = Newcmpnt.Id;
                        d.UCSystemId            = logicalNewSystem.Id;
                        _context.Entry(d).State = EntityState.Modified;
                    }
                }
                try
                {
                    ActionLog += "Save inspection changes to the database ..." + Environment.NewLine;
                    _context.SaveChanges();
                    ActionLog += "Save all succeeded" + Environment.NewLine;
                }
                catch (Exception e)
                {
                    ActionLog += "Save inspection changes FAILED : " + e.Message;
                    Status     = ActionStatus.Failed;
                    Message    = "Save inspection changes FAILED ";
                    return(Status);
                }
                new Equipment(_context, (int)inspect.equipmentid_auto).UpdateMiningShovelInspectionParentsFromChildren(inspect.inspection_auto);
            }
            _context.Entry(DALNewSystem).State = EntityState.Modified;
            _context.Entry(DALOldSystem).State = EntityState.Modified;
            try
            {
                ActionLog += "Save all changes to the database ..." + Environment.NewLine;
                _context.SaveChanges();
                ActionLog += "Save all succeeded" + Environment.NewLine;
            }
            catch (Exception e)
            {
                ActionLog += "Save all changes FAILED : " + e.Message;
                Status     = ActionStatus.Failed;
                Message    = "Save all changes FAILED ";
                return(Status);
            }
            //Add life for new system and all new components
            foreach (var Comp in logicalNewSystem.Components)
            {
                ActionLog += "Adding Life of the new component";
                DAL.ComponentLife NewComponentLife = new ComponentLife
                {
                    ActionDate  = _actionRecord.ActionDate,
                    ActionId    = _actionRecord.Id,
                    ActualLife  = longNullableToint(Comp.cmu),
                    ComponentId = Comp.equnit_auto,
                    Title       = "New component life added by replace System Action",
                    UserId      = _actionRecord.ActionUser.Id
                };
                _context.COMPONENT_LIFE.Add(NewComponentLife);
            }
            //Add life for the new system
            SystemLife NewSystemLife = new SystemLife
            {
                ActionDate = _actionRecord.ActionDate,
                ActionId   = _actionRecord.Id,
                SystemId   = logicalNewSystem.Id,
                Title      = "New System life added by replace System Action",
                UserId     = _actionRecord.ActionUser.Id,
                ActualLife = logicalNewSystem.GetSystemLife(_actionRecord.ActionDate)
            };

            _context.UCSYSTEM_LIFE.Add(NewSystemLife);
            try
            {
                ActionLog += "Adding Life of the new components nad system";
                _context.SaveChanges();
                ActionLog += "Adding Life of the new components and system Succeeded";
            }
            catch (Exception e1)
            {
                ActionLog += "Adding Life of the new components Filed " + e1.Message;
                string Message = e1.Message;
            }


            Status  = ActionStatus.Succeed;
            Message = "All done successfully";
            return(Status);
        }
Ejemplo n.º 3
0
        public ActionStatus Commit()
        {
            ActionLog += "Commiting the Operation ..." + Environment.NewLine;
            if (Status != ActionStatus.Valid)
            {
                ActionLog += "Operation Status is not valid" + Environment.NewLine;
                Status     = ActionStatus.Failed;
                return(Status);
            }

            //Including Steps:
            //Step1 Detach the old component
            //Step2 Create a new component attached to this Equipment and set system as well
            //Step3 Update ActionRecord

            //Step1
            ActionLog += "Adding New Component ..." + Environment.NewLine;
            GENERAL_EQ_UNIT geuNew = new GENERAL_EQ_UNIT
            {
                equipmentid_auto  = _actionRecord.EquipmentId,
                module_ucsub_auto = Params.oldgeuComponent.module_ucsub_auto,
                date_installed    = _actionRecord.ActionDate,
                created_user      = _actionRecord.ActionUser.userStrId,
                compartid_auto    = Params.newComponent.CompartId,
                created_date      = _actionRecord.ActionDate,
                comp_status       = (byte)Params.newComponent.ComponentStatus,
                pos  = Params.oldgeuComponent.pos,
                side = Params.oldgeuComponent.side,
                eq_ltd_at_install = _actionRecord.EquipmentActualLife,
                track_0_worn      = 0,
                track_100_worn    = 0,
                track_120_worn    = 0,
                track_budget_life = Params.newComponent.BudgetedLife,
                cmu  = Params.newComponent.ComponentLifeAtInstall,
                cost = Params.newComponent.Cost,
                eq_smu_at_install       = _actionRecord.ReadSmuNumber,
                smu_at_install          = _actionRecord.ReadSmuNumber,
                system_LTD_at_install   = GetSystemLife(longNullableToint(Params.oldgeuComponent.equnit_auto), _actionRecord.ActionDate),
                component_current_value = 0,
                variable_comp           = false,
                insp_uom  = 0,
                make_auto = Params.newComponent.brandId == 0 ? null : (int?)Params.newComponent.brandId
            };

            _context.GENERAL_EQ_UNIT.Add(geuNew);
            try
            {
                ActionLog += "Save new component to the database and get the new Id ..." + Environment.NewLine;
                _context.SaveChanges();
                ActionLog += "Save new component succeed" + Environment.NewLine;
            }
            catch (Exception e)
            {
                ActionLog += "Save new component FAILED : " + e.Message;
                Status     = ActionStatus.Failed;
                Message    = "Save new component FAILED";
                return(Status);
            }

            //Step3 Update action record to have component fields
            ActionLog += "Updating Action History ..." + Environment.NewLine;
            var dalActionRecord = _context.ACTION_TAKEN_HISTORY.Find(_actionRecord.Id);

            //Now the Action Taken History Table should be updated to show actions details
            dalActionRecord.compartid_auto = Params.oldgeuComponent.compartid_auto;

            if (new Compart(_context).isAChild(Params.oldgeuComponent.compartid_auto)) //TT-610 -> if is a child then don't reference the old component because it would cause duplicate records in history page
            {
                dalActionRecord.equnit_auto     = -(Params.oldgeuComponent.equnit_auto);
                dalActionRecord.equnit_auto_new = -geuNew.equnit_auto;
            }
            else
            {
                dalActionRecord.equnit_auto     = Params.oldgeuComponent.equnit_auto;
                dalActionRecord.equnit_auto_new = geuNew.equnit_auto;
            }

            dalActionRecord.action_type_auto = (int)ActionType.ReplaceComponentWithNew;
            dalActionRecord.cmu  = (int)Params.oldgeuComponent.cmu;
            dalActionRecord.cost = (long)_actionRecord.Cost;

            dalActionRecord.system_auto_id        = Params.oldgeuComponent.module_ucsub_auto;
            dalActionRecord.recordStatus          = (int)RecordStatus.Available;
            _context.Entry(dalActionRecord).State = System.Data.Entity.EntityState.Modified;
            //Update all life records of the old component to be for the new component
            var componentLifesAfterChangeOut = _context.COMPONENT_LIFE.Where(m => m.ComponentId == Params.oldgeuComponent.equnit_auto && m.ActionDate > _actionRecord.ActionDate).ToList();

            foreach (var life in componentLifesAfterChangeOut)
            {
                var athistoryFuture      = _context.ACTION_TAKEN_HISTORY.Find(life.ActionId);
                int EqLifeInFutureAction = 0;
                int EqSMUInFutureAction  = 0;
                if (athistoryFuture != null)
                {
                    if (athistoryFuture.equnit_auto == Params.oldgeuComponent.equnit_auto)
                    {
                        athistoryFuture.equnit_auto           = geuNew.equnit_auto;
                        _context.Entry(athistoryFuture).State = EntityState.Modified;
                    }
                    EqLifeInFutureAction = athistoryFuture.equipment_ltd;
                    EqSMUInFutureAction  = athistoryFuture.equipment_smu;
                }
                int newComponentActualLife = 0;
                if (EqLifeInFutureAction != 0 && EqLifeInFutureAction > _actionRecord.EquipmentActualLife)
                {
                    newComponentActualLife = Params.newComponent.ComponentLifeAtInstall + (EqLifeInFutureAction - _actionRecord.EquipmentActualLife);
                }
                else if (EqSMUInFutureAction != 0 && EqSMUInFutureAction > _actionRecord.ReadSmuNumber)
                {
                    newComponentActualLife = Params.newComponent.ComponentLifeAtInstall + (EqSMUInFutureAction - _actionRecord.ReadSmuNumber);
                }
                if (newComponentActualLife == 0)
                {
                    newComponentActualLife = Params.newComponent.ComponentLifeAtInstall;
                }

                life.ActualLife            = newComponentActualLife;
                life.ComponentId           = geuNew.equnit_auto;
                life.Title                 = "Updated because of component replacement in the past";
                _context.Entry(life).State = EntityState.Modified;
            }

            //Step4 Update all inspections after this change out
            var inspections      = _context.EQUIPMENTs.Find(_actionRecord.EquipmentId).TRACK_INSPECTION.Where(m => m.inspection_date > _actionRecord.ActionDate).ToList();
            var logicalEquipment = new Equipment(_context, _actionRecord.EquipmentId);

            foreach (var inspect in inspections)
            {
                var details = inspect.TRACK_INSPECTION_DETAIL.Where(m => m.track_unit_auto == Params.oldgeuComponent.equnit_auto).ToList();
                foreach (var d in details)
                {
                    var cmpnt = new Component(_context, longNullableToint(geuNew.equnit_auto));
                    InspectionImpact impact = d.TRACK_INSPECTION.impact == 2 ? InspectionImpact.High : InspectionImpact.Low;
                    int ToolId = d.tool_auto == null ? 0 : (int)d.tool_auto;
                    if (cmpnt.Id != 0)
                    {
                        d.worn_percentage = cmpnt.CalcWornPercentage(ConvertFrom(MeasurementType.Milimeter, d.reading), ToolId, impact);
                        char evl = '-';
                        if (cmpnt.GetEvalCodeByWorn(d.worn_percentage, out evl))
                        {
                            d.eval_code = evl.ToString();
                        }
                        d.hours_on_surface = cmpnt.GetComponentLife(inspect.inspection_date);
                    }
                    // Update images stored in the old table to reference the new compartid_auto if the component type has changed
                    // with the new replacement. Otherwise the image will not be viewable in the image popup.
                    var images = _context.COMPART_ATTACH_FILESTREAM.Where(f => f.compartid_auto == Params.oldgeuComponent.compartid_auto)
                                 .Where(f => f.position == Params.oldgeuComponent.pos)
                                 .Where(f => f.inspection_auto == d.inspection_auto);
                    foreach (var i in images)
                    {
                        i.compartid_auto        = geuNew.compartid_auto;
                        _context.Entry(i).State = EntityState.Modified;
                    }

                    d.track_unit_auto       = geuNew.equnit_auto;
                    _context.Entry(d).State = System.Data.Entity.EntityState.Modified;
                }
                logicalEquipment.UpdateMiningShovelInspectionParentsFromChildren(inspect.inspection_auto);
            }

            Params.oldgeuComponent.equipmentid_auto      = null;
            Params.oldgeuComponent.module_ucsub_auto     = null;
            Params.oldgeuComponent.modified_user         = _actionRecord.ActionUser.userStrId;
            _context.Entry(Params.oldgeuComponent).State = System.Data.Entity.EntityState.Modified;

            try
            {
                ActionLog += "Save all changes to the database and get the new Id ..." + Environment.NewLine;
                _context.SaveChanges();
                ActionLog += "Save all succeeded" + Environment.NewLine;
            }
            catch (Exception e)
            {
                ActionLog += "Save all changes FAILED : " + e.Message;
                Status     = ActionStatus.Failed;
                Message    = "Save all changes FAILED ";
                return(Status);
            }
            //Add a life record for the new component
            ActionLog += "Adding Life of the new component";
            DAL.ComponentLife NewComponentLife = new ComponentLife
            {
                ActionDate  = _actionRecord.ActionDate,
                ActionId    = _actionRecord.Id,
                ActualLife  = longNullableToint(geuNew.cmu),
                ComponentId = geuNew.equnit_auto,
                Title       = "New component added by replace Action",
                UserId      = _actionRecord.ActionUser.Id
            };
            _context.COMPONENT_LIFE.Add(NewComponentLife);
            try
            {
                ActionLog += "Adding Life of the new component";
                _context.SaveChanges();
                ActionLog += "Adding Life of the new component Succeed";
            }
            catch (Exception e1)
            {
                ActionLog += "Adding Life of the new component Filed " + e1.Message;
                string Message = e1.Message;
            }
            UniqueId = geuNew.equnit_auto.LongNullableToInt();
            Status   = ActionStatus.Succeed;
            Message  = "All done successfully";
            return(Status);
        }