Beispiel #1
0
        public bool RecordAcrion(InventoryActionParam Param)
        {
            BLL.Core.Domain.Component LogicalComponent = new Component(_context, Param.ComponentId);
            if (LogicalComponent.Id == 0)
            {
                _message = "Component Not Found!";
                return(false);
            }

            var user = new BLL.Core.Domain.TTDevUser(new DAL.SharedContext(), Param.userId).getUCUser();

            if (user == null)
            {
                _message = "User Not Found!";
                return(false);
            }
            var actions = _context.ACTION_TAKEN_HISTORY.Where(m => m.equnit_auto == Param.ComponentId && m.recordStatus == 0 && (m.action_type_auto == (int)ActionType.TurnPinsAndBushingsLink || m.action_type_auto == (int)ActionType.TurnPinsAndBushingsBush));

            if (actions.Count() > 0)
            {
                _message = "This component has already been tunred!";
                return(false);
            }
            DAL.ACTION_TAKEN_HISTORY record = new DAL.ACTION_TAKEN_HISTORY
            {
                action_type_auto = (int)ActionType.TurnPinsAndBushingsLink,
                comment          = Param.Comment,
                compartid_auto   = LogicalComponent.DALComponent.compartid_auto,
                cost             = (long)Param.Cost,
                event_date       = Param.ActionDate,
                entry_date       = DateTime.Now,
                entry_user_auto  = Param.userId,
                equnit_auto      = Param.ComponentId,
                recordStatus     = 0,
                system_auto_id   = LogicalComponent.DALComponent.module_ucsub_auto
            };
            _context.ACTION_TAKEN_HISTORY.Add(record);
            try
            {
                _context.SaveChanges();
                _message = "Action recorded sucessfully!";
                return(true);
            }
            catch (Exception ex)
            {
                _message    = "Recording Action Failed! Please check Log for details";
                _actionLog += ex.Message;
                if (ex.InnerException != null)
                {
                    _actionLog += ex.InnerException.Message;
                }
                return(false);
            }
        }
        ActionStatus IAction.Start()
        {
            if (_status != ActionStatus.Close)
            {
                _message = "Action cannot be started becasue it's state indicates that it is not closed!";
                _log    += _message + Environment.NewLine;
                return(_status);
            }
            if (Params.Id <= 0)
            {
                _message = "Action cannot be started becasue it is not an update action!";
                _log    += _message + Environment.NewLine;
                return(_status);
            }
            _oldDALInspection = _context.TRACK_INSPECTION
                                .Include("TRACK_ACTION")
                                .Include("TRACK_INSPECTION_DETAIL")
                                .Include("TRACK_INSPECTION_DETAIL.Images")
                                .Include("TRACK_INSPECTION_DETAIL.MeaseurementPointRecors")
                                .Include("TRACK_INSPECTION_DETAIL.MeaseurementPointRecors.Photos")
                                .Include("CompartTypeAdditionals")
                                .Include("CompartTypeAdditionals.RecordImages")
                                .Include("CompartTypeAdditionalImages")
                                .Include("CompartTypeAdditionalImages.HiddenInReports")
                                .Include("InspectionMandatoryImages")
                                .Include("InspectionMandatoryImages.HiddenInReports")
                                .Include("InspectionCompartTypeImages")
                                .Include("InspectionCompartTypeImages.HiddenInReports")
                                .Include("Quotes")
                                .Include("Quotes.Recommendations")
                                .Where(m => m.inspection_auto == Params.Id).FirstOrDefault();
            if (_oldDALInspection == null)
            {
                foreach (var _detail in _oldDALInspection.TRACK_INSPECTION_DETAIL)
                {
                    _context.Entry(_detail).Reference(m => m.SIDE).Load();
                }
                _message = "Inspection cannot be found!";
                _log    += _message + Environment.NewLine;
                return(_status);
            }
            _modifiedDALHistory = _context.ACTION_TAKEN_HISTORY.Find(_oldDALInspection.ActionHistoryId);
            if (_modifiedDALHistory == null)
            {
                _message = "History of the inspection cannot be found!";
                _log    += _message + Environment.NewLine;
                return(_status);
            }
            if (_modifiedDALHistory.recordStatus != (int)RecordStatus.Available)
            {
                _message = "This inspection is not available to be updated!";
                _log    += _message + "RecordStatus for this inspection must be 0 in TRACK_ACTION_HISTORY table" + Environment.NewLine;
                return(_status);
            }
            _previousRecordState                      = (RecordStatus)_modifiedDALHistory.recordStatus;
            _modifiedDALHistory.recordStatus          = (int)RecordStatus.Modified;
            _context.Entry(_modifiedDALHistory).State = System.Data.Entity.EntityState.Modified;
            try
            {
                _log += "Start modifying ACTION_TAKEN_HISTORY RecordStatus to modified" + Environment.NewLine;
                _context.SaveChanges();
                _log += "Saved successfully." + Environment.NewLine;
            }
            catch (Exception ex) {
                _log    += "Failed to save!" + Environment.NewLine;
                _log    += "Error Details: " + ex.Message + Environment.NewLine;
                _status  = ActionStatus.Failed;
                _message = "Operation failed! Cannot update existing history record!";
                return(_status);
            }
            _current = UpdateEquipmentByAction(_current, ref _log);
            _message = Message;
            if (_current == null || _current.Id == 0)
            {
                _message = Message;
                return(_status);
            }
            var dalActionRecord = _context.ACTION_TAKEN_HISTORY.Find(_current.Id);

            dalActionRecord.action_type_auto      = (int)ActionType.UpdateInspectionGeneral;
            dalActionRecord.recordStatus          = (int)RecordStatus.MiddleOfAction;
            _context.Entry(dalActionRecord).State = System.Data.Entity.EntityState.Modified;
            _status  = ActionStatus.Started;
            _message = "Action Started Successfully!";
            _log    += _message + Environment.NewLine;
            return(_status);
        }
Beispiel #3
0
        ActionStatus IAction.Start()
        {
            if (_status != ActionStatus.Close)
            {
                _message = "Action cannot be started becasue it's state indicates that it is not closed!";
                _log    += _message + Environment.NewLine;
                return(_status);
            }
            if (!Params.IsUpdating)
            {
                _message = "Action cannot be started becasue it is not an update action!";
                _log    += _message + Environment.NewLine;
                return(_status);
            }
            _equipment = _context.EQUIPMENTs.Find(Params.EquipmentId);
            if (_equipment == null)
            {
                _message = "Equipment cannot be found!";
                _log    += _message + Environment.NewLine;
                return(_status);
            }

            _modifiedDALHistory = _context.ACTION_TAKEN_HISTORY.Find(_equipment.ActionTakenHistoryId);
            if (_modifiedDALHistory == null)
            {
                _modifiedDALHistory = _context.ACTION_TAKEN_HISTORY.Where(m => m.equipmentid_auto == _equipment.equipmentid_auto && m.recordStatus == (int)RecordStatus.Available && m.action_type_auto == (int)ActionType.EquipmentSetup).FirstOrDefault();
                if (_modifiedDALHistory == null)
                {
                    _message = "History of the equipment setup cannot be found!";
                    _log    += _message + Environment.NewLine;
                    _id      = -2;
                    return(_status);
                }
            }
            if (_modifiedDALHistory.recordStatus != (int)RecordStatus.Available)
            {
                _message = "This equipment is not available to be updated!";
                _log    += _message + "RecordStatus for this equipment must be 0 in TRACK_ACTION_HISTORY table" + Environment.NewLine;
                return(_status);
            }
            _previousRecordState             = (RecordStatus)_modifiedDALHistory.recordStatus;
            _modifiedDALHistory.recordStatus = (int)RecordStatus.Modified;
            OldSmu = (int)(_equipment.smu_at_start ?? 0);
            OldLtd = (int)(_equipment.LTD_at_start ?? 0);
            _equipment.smu_at_start                   = Params.MeterReading;
            _equipment.LTD_at_start                   = Params.EquipmentLTD;
            _context.Entry(_equipment).State          = System.Data.Entity.EntityState.Modified;
            _context.Entry(_modifiedDALHistory).State = System.Data.Entity.EntityState.Modified;
            try
            {
                _log += "Start modifying ACTION_TAKEN_HISTORY RecordStatus to modified" + Environment.NewLine;
                _context.SaveChanges();
                _log += "Saved successfully." + Environment.NewLine;
            }
            catch (Exception ex)
            {
                _log    += "Failed to save!" + Environment.NewLine;
                _log    += "Error Details: " + ex.Message + Environment.NewLine;
                _status  = ActionStatus.Failed;
                _message = "Operation failed! Cannot update existing history record!";
                return(_status);
            }
            _current = UpdateEquipmentByAction(_current, ref _log);
            _message = Message;
            if (_current == null || _current.Id == 0)
            {
                _message = Message;
                return(_status);
            }
            var dalActionRecord = _context.ACTION_TAKEN_HISTORY.Find(_current.Id);

            dalActionRecord.action_type_auto      = (int)ActionType.UpdateSetupEquipment;
            dalActionRecord.recordStatus          = (int)RecordStatus.MiddleOfAction;
            _context.Entry(dalActionRecord).State = System.Data.Entity.EntityState.Modified;
            try
            {
                _log += "Saving Record Status... " + Environment.NewLine;
                _context.SaveChanges();
                _log += "Record status updated successfully";
            }
            catch (Exception Ex)
            {
                _log    += "Saving record status failed!" + Ex.Message + "InnerException:" + Ex.InnerException != null ? Ex.InnerException.Message : "";
                _message = "Cannot Update equipment! Please check log!";
                return(_status);
            }
            _status  = ActionStatus.Started;
            _message = "Action Started Successfully!";
            _log    += _message + Environment.NewLine;
            return(_status);
        }
Beispiel #4
0
        public bool RecordAcrion(InventoryActionParam Param)
        {
            BLL.Core.Domain.Component LogicalComponent = new Component(_context, Param.ComponentId);
            if (LogicalComponent.Id == 0)
            {
                _message = "Component Not Found!";
                return(false);
            }
            var user = new BLL.Core.Domain.TTDevUser(new DAL.SharedContext(), Param.userId).getUCUser();

            if (user == null)
            {
                _message = "User Not Found!";
                return(false);
            }
            _actionLog += "Repalce childs first" + Environment.NewLine;
            if (!LogicalComponent.isAChildBasedOnCompart() && ReplaceChildsFirst(new InventoryActionParam {
                ActionDate = Param.ActionDate,
                BudgetLife = Param.BudgetLife,
                CMU = Param.CMU,
                Comment = Param.Comment,
                ComponentId = Param.ComponentId,
                Cost = Param.Cost,
                NewCompartId = Param.NewCompartId,
                userId = Param.userId
            }))
            {
                _actionLog += "Repalce childs returned true" + Environment.NewLine;
            }
            else
            {
                _actionLog += "Warning!! Repalce childs returned false!" + Environment.NewLine;
            }

            _actionLog += "Adding New Component ..." + Environment.NewLine;
            var LogicalCompart = new BLL.Core.Domain.Compart(_context, Param.NewCompartId);
            int systemId       = LogicalComponent.DALComponent.module_ucsub_auto.LongNullableToInt();

            DAL.GENERAL_EQ_UNIT geuNew = new DAL.GENERAL_EQ_UNIT
            {
                equipmentid_auto  = null,
                module_ucsub_auto = systemId,
                date_installed    = Param.ActionDate,
                created_user      = user.userName,
                compartid_auto    = Param.NewCompartId,
                compartsn         = LogicalCompart.GetCompartSerialNumber(),
                created_date      = Param.ActionDate,
                comp_status       = 0,
                pos  = LogicalComponent.DALComponent.pos,
                side = LogicalComponent.DALComponent.side,
                eq_ltd_at_install = 0,
                track_0_worn      = 0,
                track_100_worn    = 0,
                track_120_worn    = 0,
                track_budget_life = Param.BudgetLife,
                cmu  = Param.CMU,
                cost = Param.Cost,
                eq_smu_at_install       = 0,
                smu_at_install          = 0,
                system_LTD_at_install   = 0,
                component_current_value = 0,
                variable_comp           = false,
                insp_uom = 0
            };

            DAL.ACTION_TAKEN_HISTORY record = new DAL.ACTION_TAKEN_HISTORY
            {
                action_type_auto = (int)ActionType.TurnPinsAndBushingsLink,
                comment          = Param.Comment,
                compartid_auto   = LogicalComponent.DALComponent.compartid_auto,
                cost             = (long)Param.Cost,
                event_date       = Param.ActionDate,
                entry_date       = DateTime.Now,
                entry_user_auto  = Param.userId,
                equnit_auto      = Param.ComponentId,
                recordStatus     = 0,
                system_auto_id   = LogicalComponent.DALComponent.module_ucsub_auto
            };
            LogicalComponent.DALComponent.module_ucsub_auto     = null;
            _context.Entry(LogicalComponent.DALComponent).State = EntityState.Modified;
            _context.ACTION_TAKEN_HISTORY.Add(record);
            _context.GENERAL_EQ_UNIT.Add(geuNew);
            try
            {
                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                _message    = "Recording Action Failed! Please check Log for details";
                _actionLog += ex.Message;
                if (ex.InnerException != null)
                {
                    _actionLog += ex.InnerException.Message;
                }
                return(false);
            }
            _actionLog += "Creating a new life for the new component!" + Environment.NewLine;
            _context.COMPONENT_LIFE.Add(new DAL.ComponentLife {
                ActionDate  = Param.ActionDate,
                ActionId    = record.history_id,
                ActualLife  = Param.CMU,
                ComponentId = geuNew.equnit_auto,
                UserId      = Param.userId,
                Title       = "Installed on the system in inventory"
            });
            try
            {
                _context.SaveChanges();
                _message = "Action recorded sucessfully!";
                return(true);
            }
            catch (Exception ex)
            {
                _message    = "Action recorded with 1 warning! please check log";
                _actionLog += ex.Message;
                if (ex.InnerException != null)
                {
                    _actionLog += ex.InnerException.Message;
                }
                return(false);
            }
        }