Esempio n. 1
0
        public WornPercentage GetEquipmentWorn(long inspectionId)
        {
            // TRACK_INSPECTION_DETAIL
            var inspectionDetails =
                _context.TRACK_INSPECTION_DETAIL
                .Where(m => m.inspection_auto == inspectionId)
                .Where(m => m.GENERAL_EQ_UNIT.LU_COMPART.LU_COMPART_TYPE.comparttype == "Link") // Only take %worn from the link for rope shovel inspections
                .ToList();
            if (inspectionDetails == null)
                return null;

            WornPercentage worstComponentWorn = new WornPercentage(-1, 0, 0, 'U');
            int count = 0;
            foreach(var inspectionDetail in inspectionDetails)
            {
                int tool = -1;
                if (inspectionDetail.tool_auto.HasValue)
                    tool = inspectionDetail.tool_auto.Value;

                WornPercentage componentWorn = new WornPercentage(
                    tool, inspectionDetail.reading, inspectionDetail.worn_percentage, inspectionDetail.eval_code[0]);

                if (count == 0)
                    worstComponentWorn = componentWorn;
                else
                    worstComponentWorn = CompareWornPercentage(worstComponentWorn, componentWorn);
                
                // Reset
                count++;
            }

            return worstComponentWorn;
        }
Esempio n. 2
0
 private WornPercentage CompareWornPercentage(WornPercentage oldObj, WornPercentage newObj)
 {
     if (newObj.wornPercentage > oldObj.wornPercentage)
         return newObj;
     else
         return oldObj;
 }
Esempio n. 3
0
        public WornPercentage GetComponentWorn(long inspectionId, long eqUnitAuto)
        {
            WornPercentage worstPointWorn = new WornPercentage(-1, 0, 0, 'U');

            // GENERAL_EQ_UNIT
            var cmpntd = new Component(_context, longNullableToint(eqUnitAuto));
            var component = _context.GENERAL_EQ_UNIT.Where(m => m.equnit_auto == eqUnitAuto).FirstOrDefault();
            if (component == null)
            {
                return null;
            }

            // TRACK_INSPECTION_DETAIL
            var inspectionDetail = 
                _context.TRACK_INSPECTION_DETAIL.Where(m => m.inspection_auto == inspectionId && m.track_unit_auto == eqUnitAuto).FirstOrDefault();
            if (inspectionDetail == null)
                return null;

            // COMPART_MEASUREMENT_POINT
            var compartMeasureRecords =
                _context.COMPART_MEASUREMENT_POINT.Where(m => m.CompartId == component.compartid_auto).ToList();
            if (compartMeasureRecords == null)
                return null;

            int countPoint = 0;
            foreach (var point in compartMeasureRecords)
            {
                // Readings (MEASUREMENT_POINT_RECORD)
                List<MEASUREMENT_POINT_RECORD> readingGroup =
                    _context.MEASUREMENT_POINT_RECORD.Where(
                        m => m.InspectionDetailId == inspectionDetail.inspection_detail_auto
                        && m.CompartMeasurePointId == point.Id
                        && m.ToolId != -1 && m.ToolId != 5 && m.ToolId != 7 && m.ToolId != 8    // invalid, kpo, yesno, observation
                    ).ToList();
                if (readingGroup == null || readingGroup.Count == 0)
                    continue;

                WornPercentage pointWorn = GetMeasurementPointWorn(readingGroup, point.Id, inspectionDetail.inspection_detail_auto);
                if (pointWorn == null) continue;

                // Get worst worn
                if (countPoint == 0)
                    worstPointWorn = pointWorn;
                else
                    worstPointWorn = CompareWornPercentage(worstPointWorn, pointWorn);

                // Reset
                countPoint++;
            }

            // Component worn = Worst measurement point
            return worstPointWorn;
        }
Esempio n. 4
0
        public Boolean SaveInspectionDetails(InspectionDetail item)
        {
            ////////////////////////////////////
            // Update TRACK_INSPECTION_DETAIL
            DAL.TRACK_INSPECTION_DETAIL recordInspectDetail = new DAL.TRACK_INSPECTION_DETAIL();
            var cmpntd = new Component(_context, longNullableToint(item.EqunitAuto));
            var component = _context.GENERAL_EQ_UNIT.Where(m => m.equnit_auto == item.EqunitAuto).FirstOrDefault();
            if (component == null)
                return false;

            // FK ID
            recordInspectDetail.inspection_auto = _InspectionAuto;

            // FK ID
            recordInspectDetail.track_unit_auto = item.EqunitAuto;

            // tool_auto ???
            recordInspectDetail.tool_auto = -1;

            // reading ????
            recordInspectDetail.reading = 0;

            // worn percentage ????
            recordInspectDetail.worn_percentage = 0;

            // eval_code ????
            recordInspectDetail.eval_code = "U";

            // ReadingEnteredByEval
            recordInspectDetail.ReadingEnteredByEval = false;

            // hours_on_surface
            recordInspectDetail.hours_on_surface = cmpntd.GetComponentLifeMiddleOfNewAction(DateTime.Now);

            // Side
            recordInspectDetail.Side = component.side ?? 0;

            // UCSystemId
            recordInspectDetail.UCSystemId = component.module_ucsub_auto;

            // INSERT
            _TRACK_INSPECTION_DETAIL.Add(recordInspectDetail);
            _context.SaveChanges();

            /////////////////////////////////////////////////////////
            // MEASUREMENT_POINT_RECORD, MEASUREPOINT_RECORD_IMAGES
            foreach (var measurementPoint in item.MeasurementPoints)
            {
                ///////////////////////////////
                // MEASUREMENT_POINT_RECORD
                int newMeasurePointId = 0;
                int firstMeasurePointId = 0;
                int countReading = 0;
                foreach (var reading in measurementPoint.Measures)
                {
                    newMeasurePointId = SaveInspectionReading(
                        recordInspectDetail.inspection_detail_auto,
                        measurementPoint.MeasurementPointId,
                        measurementPoint.ToolCode,
                        measurementPoint.Notes,
                        reading,
                        countReading);

                    if (countReading == 0)
                        firstMeasurePointId = newMeasurePointId;
                    countReading++;
                }

                ////////////////////////////////////////////////////////////
                // MEASUREPOINT_RECORD_IMAGES
                foreach (var image in measurementPoint.Images)
                {
                    SaveInspectionImg(
                        firstMeasurePointId,
                        image);
                }
            }
            _context.SaveChanges();

            ///////////////////////////
            // Update component worn
            WornPercentage componentWorn = GetComponentWorn(_InspectionAuto, item.EqunitAuto);
            if (componentWorn != null && componentWorn.wornPercentage != 0 && !componentWorn.evalCode.Equals('U'))
            {
                // tool_auto
                recordInspectDetail.tool_auto = componentWorn.tool_auto;

                // reading
                recordInspectDetail.reading = componentWorn.reading;

                // worn percentage
                recordInspectDetail.worn_percentage = componentWorn.wornPercentage;

                // eval_code
                recordInspectDetail.eval_code = componentWorn.evalCode.ToString();

                // Update
                //_TRACK_INSPECTION_DETAIL   .Upda.Add(recordInspectDetail);
                _context.SaveChanges();
            }

            return true;
        }
Esempio n. 5
0
        public Boolean SaveMiningShovelInfo(SyncModel equip)
        {
            try
            {
                _InspectionAuto = equip.serverInspectionId;
                _Impact = GetInspectionImpact(equip.impact);

                /////////////////////////
                // _TRACK_INSPECTION
                UpdateTrackInspection(equip);

                ///////////////////////////////////////
                // _INSPECTION_MANDATORY_IMAGES table
                foreach (var item in equip.EquipmentImages)
                {
                    // Equipment photos
                    SaveEquipmentImages(item);
                }

                ///////////////////////////////////////
                // _INSPECTION_MANDATORY_IMAGES table
                foreach (var item in equip.JobsiteImages)
                {
                    // Jobsite photos
                    SaveJobsiteImages(item);
                }

                ////////////////////////////////////////////////////////////////////////////////////
                // INSPECTION_COMPARTTYPE_RECORD, INSPECTION_COMPARTTYPE_RECORD_IMAGES tables
                foreach (var item in equip.AdditionalImages)
                {
                    // Additional photos
                    SaveAdditionalImages(item);
                }

                ///////////////////////////////////////
                // _INSPECTION_COMPARTTYPE_IMAGES table
                foreach (var item in equip.MandatoryImages)
                {
                    // Equipment photos
                    SaveMandatoryImages(item);
                }

                ////////////////////////////////////////////////////////////////////////////////////
                // TRACK_INSPECTION_DETAIL, MEASUREMENT_POINT_RECORD, MEASUREPOINT_RECORD_IMAGES
                foreach (var item in equip.InspectionDetails)
                {
                    // Inspection Detail
                    SaveInspectionDetails(item);
                }

                // COMMIT
                _context.SaveChanges();

                ///////////////////////////////////////////////////////////////
                // Update eval code for equipment in TRACK_INSPECTION table
                WornPercentage equipWorn = GetEquipmentWorn(_InspectionAuto);
                if (equipWorn != null && equipWorn.wornPercentage != 0 && !equipWorn.evalCode.Equals('U'))
                {
                    var inspectionRecord =
                        _context.TRACK_INSPECTION.Where(m => m.inspection_auto == _InspectionAuto).FirstOrDefault();
                    if (inspectionRecord == null)
                        return false;

                    inspectionRecord.evalcode = equipWorn.evalCode.ToString();
                    _context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                // Sync failed, roll back
                //RollbackWSREInfo();
                return false;
            }

            return true;
        }