コード例 #1
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.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);
        }
コード例 #2
0
        ActionStatus IAction.Commit()
        {
            _log += "Commiting the Operation ..." + Environment.NewLine;
            if (_status != ActionStatus.Valid)
            {
                _log   += "Operation Status is not valid" + Environment.NewLine;
                _status = ActionStatus.Failed;
                return(_status);
            }
            var impact = LowNormalHigh.Low;

            try { impact = (LowNormalHigh)Params.Impact; } catch (Exception ex) { string message = ex.Message; }
            var abrasive = LowNormalHigh.Low;

            try { abrasive = (LowNormalHigh)Params.Abrasive; } catch (Exception ex) { string message = ex.Message; }
            var moisture = LowNormalHigh.Low;

            try { moisture = (LowNormalHigh)Params.Moisture; } catch (Exception ex) { string message = ex.Message; }
            var packing = LowNormalHigh.Low;

            try { packing = (LowNormalHigh)Params.Packing; } catch (Exception ex) { string message = ex.Message; }

            var _inspectionEntity = new DAL.TRACK_INSPECTION();

            _inspectionEntity.equipmentid_auto = _current.EquipmentId;
            _inspectionEntity.inspection_date  = _current.ActionDate.ToLocalTime().Date;
            _inspectionEntity.smu              = _current.ReadSmuNumber;
            _inspectionEntity.examiner         = _current.ActionUser.userName;
            _inspectionEntity.notes            = Params.InspectionNotes;
            _inspectionEntity.Jobsite_Comms    = Params.JobSiteNotes;
            _inspectionEntity.CustomerContact  = Params.CustomerContact;
            _inspectionEntity.TrammingHours    = Params.TrammingHours;
            _inspectionEntity.track_sag_left   = Params.TrackSagLeft;
            _inspectionEntity.track_sag_right  = Params.TrackSagRight;
            _inspectionEntity.dry_joints_left  = Params.DryJointsLeft;
            _inspectionEntity.dry_joints_right = Params.DryJointsRight;
            _inspectionEntity.impact           = (short)impact;
            _inspectionEntity.abrasive         = (short)abrasive;
            _inspectionEntity.packing          = (short)packing;
            _inspectionEntity.moisture         = (short)moisture;
            _inspectionEntity.created_date     = DateTime.Now.ToLocalTime();
            _inspectionEntity.created_user     = _current.ActionUser.userName;
            _inspectionEntity.docket_no        = Params.DocketNo;
            _inspectionEntity.ltd              = _current.EquipmentActualLife;
            _inspectionEntity.evalcode         = "U";//░░░░░░Needs to be updated later░░░░░░
            _inspectionEntity.ActionHistoryId  = _current.Id;
            //░░░░░░There are some other fields that needs to be updated later░░░░░░

            _context.TRACK_INSPECTION.Add(_inspectionEntity);
            try
            {
                _log += "Start saving New Inspection in TRACK_INSPECTION" + Environment.NewLine;
                _context.SaveChanges();
                _id   = _inspectionEntity.inspection_auto;
                _log += "Saved successfully." + Environment.NewLine;
            }
            catch (Exception e1)
            {
                _log    += "Failed to save!" + Environment.NewLine;
                _log    += "Error Details: " + e1.Message + Environment.NewLine;
                _status  = ActionStatus.Failed;
                _message = "Inspection saving failed!";
                return(_status);
            }

            //var components = _context.GENERAL_EQ_UNIT.Where(m => m.equipmentid_auto == _current.EquipmentId);
            //var _detailEntities = new List<DAL.TRACK_INSPECTION_DETAIL>();
            //foreach (var comp in components)
            //{
            //    var cmpntd = new Component(_context, longNullableToint(comp.equnit_auto));
            //    var _detailEntity = new DAL.TRACK_INSPECTION_DETAIL {
            //        inspection_auto = _inspectionEntity.inspection_auto,
            //        track_unit_auto = comp.equnit_auto,
            //        tool_auto = -1, /*░░░░░░Needs to be updated later░░░░░░*/
            //        reading = 0, /*░░░░░░Needs to be updated later░░░░░░*/
            //        worn_percentage = 0, /*░░░░░░Needs to be updated later░░░░░░*/
            //        eval_code = "U",/*░░░░░░Needs to be updated later░░░░░░*/
            //        hours_on_surface = cmpntd.GetComponentLifeMiddleOfNewAction(_current.ActionDate),
            //        projected_hours = 0,/*░░░░░░Needs to be updated later░░░░░░*/
            //        ext_projected_hours = 0, /*░░░░░░Needs to be updated later░░░░░░*/
            //        remaining_hours = 0, /*░░░░░░Needs to be updated later░░░░░░*/
            //        ext_remaining_hours = 0, /*░░░░░░Needs to be updated later░░░░░░*/
            //        worn_percentage_120 = 0, /*░░░░░░Needs to be updated later░░░░░░*/
            //        UCSystemId = comp.module_ucsub_auto,
            //        Side = comp.side ?? 0
            //    };
            //    _detailEntities.Add(_detailEntity);
            //}
            //_context.TRACK_INSPECTION_DETAIL.AddRange(_detailEntities);
            //try
            //{
            //    _log += "Start saving range of inspection details to the TRACK_INSPECTION_DETAIL" + Environment.NewLine;
            //    _context.SaveChanges();
            //    _log += "Saved successfully." + Environment.NewLine;
            //}
            //catch (Exception e2)
            //{
            //    _log += "Failed to save!" + Environment.NewLine;
            //    _log += "Error Details: " + e2.Message + Environment.NewLine;
            //    _status = ActionStatus.Failed;
            //    _message = "Save details range failed";
            //    return _status;
            //}

            //foreach (var tid in _detailEntities)
            //    _context.InspectionDetails_Side.Add(new DAL.InspectionDetails_Side { InspectionDetailsId = tid.inspection_detail_auto, Side = tid.Side });
            //try
            //{
            //    _log += "Start saving range of inspection sides to the InspectionDetails_Side" + Environment.NewLine;
            //    _context.SaveChanges();
            //    _log += "Saved successfully." + Environment.NewLine;
            //}
            //catch (Exception e2)
            //{
            //    _log += "Failed to save!" + Environment.NewLine;
            //    _log += "Error Details: " + e2.Message + Environment.NewLine;
            //    _status = ActionStatus.Failed;
            //    _message = "Save side for the component failed";
            //    return _status;
            //}
            Available();
            _status  = ActionStatus.Succeed;
            _message = "All done successfully";
            return(_status);
        }