Пример #1
0
        public async Task <Tuple <bool, string> > UploadNewMeasurementPointPhoto(int inspectionDetailId, int compartMeasurePointId, string photo)
        {
            var measurementPoint = _context.MEASUREMENT_POINT_RECORD
                                   .Where(i => i.InspectionDetailId == inspectionDetailId)
                                   .Where(i => i.CompartMeasurePointId == compartMeasurePointId)
                                   .Where(i => i.MeasureNumber == 1)
                                   .FirstOrDefault();

            if (measurementPoint == null)
            {
                var compartMeasurePoint = await _context.COMPART_MEASUREMENT_POINT.FindAsync(compartMeasurePointId);

                measurementPoint = new MEASUREMENT_POINT_RECORD()
                {
                    CompartMeasurePointId = compartMeasurePointId,
                    EvalCode           = "",
                    InboardOutborad    = 0,
                    InspectionDetailId = inspectionDetailId,
                    MeasureNumber      = 1,
                    Notes   = "",
                    Reading = 0,
                    ToolId  = compartMeasurePoint.DefaultToolId != null ? (int)compartMeasurePoint.DefaultToolId : -1,
                    Worn    = 0
                };

                _context.MEASUREMENT_POINT_RECORD.Add(measurementPoint);
                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    return(Tuple.Create(false, e.ToDetailedString()));
                }
            }

            var photoRecord = new MEASUREPOINT_RECORD_IMAGES()
            {
                Comment = "",
                Data    = Convert.FromBase64String(photo),
                MeasurePointRecordId = measurementPoint.Id,
                Title = ""
            };

            _context.MEASUREPOINT_RECORD_IMAGES.Add(photoRecord);

            try
            {
                await _context.SaveChangesAsync();

                return(Tuple.Create(true, "Measurement point comment updated successfully. "));
            }
            catch (Exception e)
            {
                return(Tuple.Create(false, e.ToDetailedString()));
            }
        }
Пример #2
0
        public async Task <Tuple <bool, string> > UpdateMeasurementPointComment(int inspectionDetailId, int compartMeasurePointId, string comment)
        {
            var measurementPoint = _context.MEASUREMENT_POINT_RECORD
                                   .Where(i => i.InspectionDetailId == inspectionDetailId)
                                   .Where(i => i.CompartMeasurePointId == compartMeasurePointId)
                                   .Where(i => i.MeasureNumber == 1)
                                   .FirstOrDefault();

            if (measurementPoint == null)
            {
                var compartMeasurePoint = await _context.COMPART_MEASUREMENT_POINT.FindAsync(compartMeasurePointId);

                measurementPoint = new MEASUREMENT_POINT_RECORD()
                {
                    CompartMeasurePointId = compartMeasurePointId,
                    EvalCode           = "",
                    InboardOutborad    = 0,
                    InspectionDetailId = inspectionDetailId,
                    MeasureNumber      = 1,
                    Notes   = comment,
                    Reading = 0,
                    ToolId  = -1,//compartMeasurePoint.DefaultToolId != null ? (int)compartMeasurePoint.DefaultToolId : -1,
                    Worn    = 0
                };
                _context.MEASUREMENT_POINT_RECORD.Add(measurementPoint);
            }
            else
            {
                measurementPoint.Notes = comment;
            }

            try
            {
                await _context.SaveChangesAsync();

                return(Tuple.Create(true, "Measurement point comment updated successfully. "));
            }
            catch (Exception e)
            {
                return(Tuple.Create(false, e.ToDetailedString()));
            }
        }
Пример #3
0
        public async Task <Tuple <decimal, string> > UpdateMeasurementPointReading(int inspectionDetailId, int compartMeasurePointId, int readingNumber, decimal reading)
        {
            bool _deleted         = false;
            var  measurementPoint = _context.MEASUREMENT_POINT_RECORD
                                    .Where(i => i.InspectionDetailId == inspectionDetailId)
                                    .Where(i => i.CompartMeasurePointId == compartMeasurePointId)
                                    .Where(i => i.MeasureNumber == readingNumber)
                                    .FirstOrDefault();

            if (measurementPoint == null && reading < 0)
            {
                return(Tuple.Create((decimal) - 1, "Reading updated successfully."));
            }
            if (measurementPoint == null)
            {
                var compartMeasurePoint = await _context.COMPART_MEASUREMENT_POINT.FindAsync(compartMeasurePointId);

                measurementPoint = new MEASUREMENT_POINT_RECORD()
                {
                    CompartMeasurePointId = compartMeasurePointId,
                    EvalCode           = "",
                    InboardOutborad    = 0,
                    InspectionDetailId = inspectionDetailId,
                    MeasureNumber      = readingNumber,
                    Notes   = "",
                    Reading = reading,
                    ToolId  = compartMeasurePoint.DefaultToolId != null ? (int)compartMeasurePoint.DefaultToolId : -1,
                    Worn    = 0
                };
                _context.MEASUREMENT_POINT_RECORD.Add(measurementPoint);
            }
            else if (reading < 0)
            {
                _context.MEASUREMENT_POINT_RECORD.Remove(measurementPoint);
                _deleted = true;
            }
            else
            {
                measurementPoint.Reading = reading;
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                return(Tuple.Create((decimal) - 999, e.ToDetailedString()));
            }
            decimal worn = 0;

            if (!_deleted)
            {
                // Worn
                BLL.Core.Domain.MiningShovelDomain.MeasurementPoint pointRecord = new Domain.MiningShovelDomain.MeasurementPoint(_context, measurementPoint.Id);
                worn = pointRecord.CalcWornPercentage(
                    reading.ConvertMMToInch(),
                    measurementPoint.ToolId,
                    InspectionImpact.High
                    );

                measurementPoint.Worn = worn;
                //if (inspectionDetail != null && inspectionDetail.worn_percentage < worn)
                //inspectionDetail.worn_percentage = worn;
                //var details = _context.TRACK_INSPECTION_DETAIL.Where(d => d.inspection_auto == inspectionDetail.inspection_auto).ToList();

                try
                {
                    await _context.SaveChangesAsync();

                    //return Tuple.Create(worn, "Reading updated successfully. ");
                }
                catch (Exception e)
                {
                    return(Tuple.Create((decimal) - 999, e.ToDetailedString()));
                }
            }
            var inspectionDetail = await _context.TRACK_INSPECTION_DETAIL.FindAsync(measurementPoint.InspectionDetailId);

            var manager = new MiningShovelMobileSyncManager(_context);
            var newWorn = manager.GetComponentWorn(inspectionDetail.inspection_auto, inspectionDetail.track_unit_auto);

            inspectionDetail.worn_percentage = newWorn.wornPercentage;
            inspectionDetail.eval_code       = newWorn.evalCode.ToString();
            try
            {
                await _context.SaveChangesAsync();

                //return Tuple.Create(worn, "Reading updated successfully. ");
            }
            catch (Exception e)
            {
                return(Tuple.Create((decimal) - 999, e.ToDetailedString()));
            }

            var newEquipmentWorn = manager.GetEquipmentWorn(inspectionDetail.inspection_auto);

            inspectionDetail.TRACK_INSPECTION.evalcode = newEquipmentWorn.evalCode.ToString();

            try
            {
                await _context.SaveChangesAsync();

                return(Tuple.Create(worn, "Reading updated successfully. "));
            }
            catch (Exception e)
            {
                return(Tuple.Create((decimal) - 999, e.ToDetailedString()));
            }
        }