Ejemplo n.º 1
0
 public new void Dispose()
 {
     if (Status != ActionStatus.Succeed)
     {
         rollBack();
         MakeOtherSystemsOnline();
         var _ids    = ActionHistoryModifiedIds.Select(k => k.HistoryId).ToList();
         var actions = _context.ACTION_TAKEN_HISTORY.Where(m => _ids.Any(k => k == m.history_id));
         foreach (var act in actions)
         {
             act.recordStatus          = ActionHistoryModifiedIds.Where(m => m.HistoryId == act.history_id).Select(m => m.Status).FirstOrDefault();
             _context.Entry(act).State = EntityState.Modified;
         }
         _context.SaveChangesAsync();
     }
     else
     {
         _gContext = new DAL.GETContext();
         string _log = "";
         UpdateGETByAction(_current, ref _log);
         ActionLog += _log + Environment.NewLine;
     }
     _context.Dispose();
 }
Ejemplo n.º 2
0
        private void AdjustLives()
        {
            var _ids = ActionHistoryModifiedIds.Select(m => m.HistoryId);

            if (OldSystemCMU != null && DALSystem != null)
            {
                var _difference = (int)(((DALSystem.CMU ?? 0) - OldSystemCMU.CMU) + (OldSystemCMU.SmuAtInstall - (DALSystem.SMU_at_install ?? 0)));
                var lives       = _context.UCSYSTEM_LIFE.Where(m => m.SystemId == OldSystemCMU.Id && !_ids.Any(k => m.ActionId == k) && m.ACTION_TAKEN_HISTORY.recordStatus == (int)RecordStatus.TemporarilyDisabled);
                foreach (var life in lives)
                {
                    life.ActualLife           += _difference;
                    _context.Entry(life).State = EntityState.Modified;
                }
            }
            var components = _context.GENERAL_EQ_UNIT.Where(m => m.module_ucsub_auto == Params.Id).ToList();
            var _compIds   = components.Select(m => m.equnit_auto);

            foreach (var component in components)
            {
                var _item = OldComponentsCMU.Where(m => m.Id == component.equnit_auto).FirstOrDefault();
                if (_item == null)
                {
                    continue;
                }
                int _difference = 0;
                if (ReplacedComponentIds.Any(k => component.equnit_auto == k))
                {
                    _difference = (int)(((component.cmu ?? 0) - _item.CMU));
                }
                else
                {
                    _difference = (int)(((component.cmu ?? 0) - _item.CMU) + (_item.SmuAtInstall - (component.eq_smu_at_install ?? 0)));
                }
                var lives = _context.COMPONENT_LIFE.Where(m => m.ComponentId == _item.Id && !_ids.Any(k => m.ActionId == k) && m.ACTION_TAKEN_HISTORY.recordStatus == (int)RecordStatus.TemporarilyDisabled);
                foreach (var life in lives)
                {
                    life.ActualLife           += _difference;
                    _context.Entry(life).State = EntityState.Modified;
                }
            }

            var inspections = _context.TRACK_INSPECTION_DETAIL.Where(m => _compIds.Any(k => m.track_unit_auto == k));

            foreach (var inspection in inspections)
            {
                int _difference = 0;
                var _item       = OldComponentsCMU.Where(m => m.Id == inspection.track_unit_auto).FirstOrDefault();
                if (_item == null)
                {
                    continue;
                }
                if (ReplacedComponentIds.Any(k => inspection.track_unit_auto == k))
                {
                    _difference = (int)(((inspection.GENERAL_EQ_UNIT.cmu ?? 0) - _item.CMU));
                }
                else
                {
                    _difference = (int)(((inspection.GENERAL_EQ_UNIT.cmu ?? 0) - _item.CMU) + (_item.SmuAtInstall - (inspection.GENERAL_EQ_UNIT.eq_smu_at_install ?? 0)));
                }
                inspection.hours_on_surface += _difference;

                _context.Entry(inspection).State = EntityState.Modified;
            }
            try
            {
                _context.SaveChanges();
                ActionLog += "lives adjusted successfully!" + Environment.NewLine;
            }
            catch (Exception ex)
            {
                ActionLog += "Updating lives failed! " + ex.ToDetailedString() + Environment.NewLine;
            }
        }