コード例 #1
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);
     }
     _Logicalcomponent.DALComponent.date_installed    = _actionRecord.ActionDate;
     _Logicalcomponent.DALComponent.smu_at_install    = _actionRecord.ReadSmuNumber;
     _Logicalcomponent.DALComponent.eq_smu_at_install = _actionRecord.ReadSmuNumber;
     _Logicalcomponent.DALComponent.pos  = Params.Position;
     _Logicalcomponent.DALComponent.side = (byte)Params.side;
     _Logicalcomponent.DALComponent.eq_ltd_at_install     = _actionRecord.EquipmentActualLife;
     _Logicalcomponent.DALComponent.module_ucsub_auto     = _Logicalsystem.Id;
     _Logicalcomponent.DALComponent.system_LTD_at_install = _Logicalsystem.GetSystemLife(_actionRecord.ActionDate);
     _Logicalcomponent.DALComponent.equipmentid_auto      = _Logicalequipment.Id;
     _context.COMPONENT_LIFE.Add(new ComponentLife
     {
         ActionDate  = _actionRecord.ActionDate,
         ActionId    = _actionRecord.Id,
         ActualLife  = (_Logicalcomponent.DALComponent.cmu ?? 0).LongNullableToInt(),//_Logicalcomponent.GetComponentLife(_actionRecord.ActionDate),
         ComponentId = _Logicalcomponent.Id,
         Title       = "Installing component on the system!",
         UserId      = _actionRecord.ActionUser.Id
     });
     _context.Entry(_Logicalcomponent.DALComponent).State = EntityState.Modified;
     try
     {
         _context.SaveChanges();
         ActionLog += "Installing component completed!";
         Message    = "Installing component succeeded";
         Status     = ActionStatus.Succeed;
     }
     catch (Exception e)
     {
         ActionLog += "Installing component failed!" + e.Message;
         Message    = "Failed to install component!";
         Status     = ActionStatus.Failed;
     }
     if (Status == ActionStatus.Succeed)
     {
         UniqueId = _actionRecord.Id;
         updateActionRecord();
     }
     return(Status);
 }
コード例 #2
0
ファイル: InstallSystemAction.cs プロジェクト: hari81/BLL
        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);
            }
            _Logicalsystem.DALSystem.SMU_at_install              = _actionRecord.ReadSmuNumber;
            _Logicalsystem.DALSystem.equipmentid_auto            = Params.EquipmentId;
            _Logicalsystem.DALSystem.equipment_LTD_at_attachment = _actionRecord.EquipmentActualLife;

            foreach (var comp in _Logicalsystem.Components)
            {
                comp.equipmentid_auto  = Params.EquipmentId;
                comp.date_installed    = _actionRecord.ActionDate;
                comp.smu_at_install    = _actionRecord.ReadSmuNumber;
                comp.eq_smu_at_install = _actionRecord.ReadSmuNumber;
                comp.side = (byte)Params.side;
                comp.eq_ltd_at_install     = _actionRecord.EquipmentActualLife;
                comp.module_ucsub_auto     = _Logicalsystem.Id;
                comp.system_LTD_at_install = _Logicalsystem.GetSystemLife(_actionRecord.ActionDate);
                _context.Entry(comp).State = EntityState.Modified;
            }
            _context.Entry(_Logicalsystem.DALSystem).State = EntityState.Modified;
            try
            {
                _context.SaveChanges();
                ActionLog += "Setup system completed!";
                Message    = "System setup succeeded";
                Status     = ActionStatus.Succeed;
            }
            catch (Exception e)
            {
                ActionLog += "installing system failed!" + e.Message;
                Message    = "Failed to install system!";
                Status     = ActionStatus.Failed;
            }
            if (Status == ActionStatus.Succeed)
            {
                UniqueId = _actionRecord.Id;
                updateActionRecord();
            }
            return(Status);
        }
コード例 #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);
            }
            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);
        }