예제 #1
0
        private ComponentRecord GetComponentRecord(int componentId, TRACK_INSPECTION_DETAIL inspectionDetail, string uom)
        {
            var dalComponent = new BLL.Core.Domain.Component(_context, componentId);
            var photo        = dalComponent.GetComponentPhoto();
            var x            = new ComponentRecord();

            x.Id             = inspectionDetail.inspection_detail_auto;
            x.WornPercentage = Decimal.Round(inspectionDetail.worn_percentage, 2);
            x.Name           = dalComponent.GetComponentDescription();
            x.Photo          = photo != null?Convert.ToBase64String(photo) : "";

            x.Position          = dalComponent.GetPositionLabel();
            x.MeasurementPoints = GetMeasurementPointsForComponent(dalComponent, inspectionDetail, uom);
            return(x);
        }
예제 #2
0
        private string GetAverageReadingForMeasurementPoint(COMPART_MEASUREMENT_POINT measurementPoint, TRACK_INSPECTION_DETAIL inspectionDetail, string uom)
        {
            var readings = inspectionDetail.MeaseurementPointRecors
                           .Where(r => r.CompartMeasurePointId == measurementPoint.Id)
                           .Where(r => r.ToolId != -1)
                           .ToList();

            if (readings.Count == 0)
            {
                return("?");
            }
            if (readings.First().Tool.tool_code == "YES/NO")
            {
                switch ((int)readings.First().Reading)
                {
                case 1:
                    return("Yes");

                case 0:
                    return("No");

                default:
                    return("?");
                }
            }
            if (readings.First().Tool.tool_code == "KPO")
            {
                switch ((int)readings.First().Reading)
                {
                case 1:
                    return("A");

                case 2:
                    return("B");

                case 3:
                    return("C");

                case 4:
                    return("D");

                default:
                    return("?");
                }
            }
            decimal total = 0;
            decimal count = 0;

            readings.ForEach(r =>
            {
                total += uom == "mm" ? r.Reading : r.Reading.MilimeterToInch();
                count++;
            });
            if (total > 0 && count > 0)
            {
                return(Decimal.Round(total / count, 2).ToString());
            }
            return("0");
        }
예제 #3
0
        private MeasurementPointRecord GetMeasurementPointRecord(COMPART_MEASUREMENT_POINT measurementPoint, TRACK_INSPECTION_DETAIL inspectionDetail, string uom)
        {
            var readingList = new List <MeasurementPointReading>();
            var tool        = measurementPoint.PossibleTools.FirstOrDefault();

            return(new MeasurementPointRecord()
            {
                CompartMeasurementPointId = measurementPoint.Id,
                Name = measurementPoint.Name,
                Photo = tool != null?Convert.ToBase64String(tool.HowToUseImage) : null,
                            AverageReading = GetAverageReadingForMeasurementPoint(measurementPoint, inspectionDetail, uom),
                            Comment = GetCommentForMeasurementPoint(measurementPoint, inspectionDetail),
                            Photos = GetPhotosForMeasurementPoint(measurementPoint, inspectionDetail),
                            WornPercentage = GetAverageWornPercentageForMeasurementPoint(measurementPoint, inspectionDetail),
                            Readings = GetReadingsForMeasurementPoint(measurementPoint, inspectionDetail, uom)
            });
        }
예제 #4
0
        private List <MeasurementPointRecord> GetMeasurementPointsForComponent(Domain.Component component, TRACK_INSPECTION_DETAIL inspectionDetail, string uom)
        {
            var possibleMeasurementPoints = _context.COMPART_MEASUREMENT_POINT.Where(p => p.CompartId == component.DALComponent.compartid_auto).ToList();
            List <MeasurementPointRecord> measurementPoints = new List <MeasurementPointRecord>();

            possibleMeasurementPoints.ForEach(p =>
            {
                measurementPoints.Add(GetMeasurementPointRecord(p, inspectionDetail, uom));
            });
            return(measurementPoints);
        }
예제 #5
0
        private List <MeasurementPointPhoto> GetPhotosForMeasurementPoint(COMPART_MEASUREMENT_POINT measurementPoint, TRACK_INSPECTION_DETAIL inspectionDetail)
        {
            var reading = inspectionDetail.MeaseurementPointRecors.Where(r => r.CompartMeasurePointId == measurementPoint.Id).FirstOrDefault();

            if (reading == null)
            {
                return(new List <MeasurementPointPhoto>());
            }

            return(reading.Photos.Select(p => new MeasurementPointPhoto()
            {
                //Comment = p.Comment,
                Id = p.Id,
                //Photo = Convert.ToBase64String(p.Data),
                //Title = p.Title
            }).ToList());
        }
예제 #6
0
        private List <MeasurementPointReading> GetReadingsForMeasurementPoint(COMPART_MEASUREMENT_POINT measurementPoint, TRACK_INSPECTION_DETAIL inspectionDetail, string uom)
        {
            var readings         = inspectionDetail.MeaseurementPointRecors.Where(r => r.CompartMeasurePointId == measurementPoint.Id).ToList();
            var possibleReadings = measurementPoint.DefaultNumberOfMeasurements;
            List <MeasurementPointReading> readingList = new List <MeasurementPointReading>();

            for (int i = 0; i < possibleReadings; i++)
            {
                var record = new MeasurementPointReading()
                {
                    Id             = i + 1,
                    Measurement    = Decimal.Round(-1, 2),
                    ToolId         = measurementPoint.DefaultToolId != null ? (int)measurementPoint.DefaultToolId : 0,
                    WornPercentage = Decimal.Round(0, 2)
                };

                var recordDal = readings.Where(r => r.MeasureNumber == i + 1).FirstOrDefault();
                if (recordDal != null)
                {
                    //If tool is KPO, YES/NO, or Drive Lugs dont convert to inch because the front end wont be able to convert it to the answer
                    record.Measurement    = Decimal.Round((uom == "mm" || recordDal.ToolId == 5 || recordDal.ToolId == 6 || recordDal.ToolId == 7) ? recordDal.Reading : recordDal.Reading.MilimeterToInch(), 2);
                    record.ToolId         = recordDal.ToolId;
                    record.WornPercentage = Decimal.Round(recordDal.Worn, 2);
                }
                readingList.Add(record);
            }

            return(readingList);
        }
예제 #7
0
        private string GetCommentForMeasurementPoint(COMPART_MEASUREMENT_POINT measurementPoint, TRACK_INSPECTION_DETAIL inspectionDetail)
        {
            var reading = inspectionDetail.MeaseurementPointRecors.Where(r => r.CompartMeasurePointId == measurementPoint.Id).FirstOrDefault();

            if (reading == null)
            {
                return("");
            }
            return(reading.Notes);
        }
예제 #8
0
        private decimal GetAverageWornPercentageForMeasurementPoint(COMPART_MEASUREMENT_POINT measurementPoint, TRACK_INSPECTION_DETAIL inspectionDetail)
        {
            var readings = inspectionDetail.MeaseurementPointRecors.Where(r => r.CompartMeasurePointId == measurementPoint.Id).ToList();

            if (readings.Count == 0)
            {
                return(0);
            }
            decimal total = 0;
            int     count = 0;

            readings.ForEach(r =>
            {
                total += r.Worn;
                count++;
            });
            if (total > 0)
            {
                return(Decimal.Round(total / count, 2));
            }
            return(Decimal.Round(0, 2));
        }
예제 #9
0
        public ResultMessage TransitFromMobileInspection(long EquipmentId, long MblEquipmentId, int InspectionId, Interfaces.IUser user)
        {
            var rm = new BLL.Core.Domain.ResultMessage
            {
                OperationSucceed = false,
                ActionLog        = "Operation failed in TransitFromMobileInspection",
                LastMessage      = "Operation failed!",
                Id = 0
            };

            if (user == null)
            {
                rm.LastMessage = "Operation failed! User not found!";
                rm.ActionLog   = "user is null";
                return(rm);
            }
            var equipment                    = _context.EQUIPMENTs.Find(EquipmentId);
            var equipmentInspection          = _context.Mbl_Track_Inspection.Where(m => m.inspection_auto == InspectionId && m.equipmentid_auto == MblEquipmentId).FirstOrDefault();
            Mbl_NewEquipment mobileEquipment = _context.Mbl_NewEquipment.Where(m => m.equipmentid_auto == MblEquipmentId).FirstOrDefault();

            if (equipment == null || equipmentInspection == null || mobileEquipment == null)
            {
                rm.LastMessage = "Operation failed! equipment or inspection not found!";
                rm.ActionLog   = "(equipment == null || equipmentInspection == null || mobileEquipment == null) detected!";
                return(rm);
            }
            var mobileEqInspection = _context.Mbl_Track_Inspection.Where(m => m.equipmentid_auto == MblEquipmentId).FirstOrDefault();

            if (mobileEqInspection == null)
            {
                rm.LastMessage = "Operation failed! Inspection from mobile not found!";
                rm.ActionLog   = "Mbl_Track_Inspection(this inspection).count() is 0";
                return(rm);
            }

            var mobileInspectionDetails = _context.Mbl_Track_Inspection_Detail.Where(m => m.inspection_auto == mobileEqInspection.inspection_auto).ToList();

            var mobileComponents = _context.Mbl_NewGENERAL_EQ_UNIT.Where(m => m.equipmentid_auto == MblEquipmentId).ToList();
            var geuComponents    = _context.GENERAL_EQ_UNIT.Where(m => m.equipmentid_auto == EquipmentId).ToList();

            BLL.Core.Domain.InspectionImpact impact = equipmentInspection.impact == 2 ? BLL.Core.Domain.InspectionImpact.High : BLL.Core.Domain.InspectionImpact.Low;

            DAL.TRACK_INSPECTION EquipmentInspectionParam = new TRACK_INSPECTION
            {
                abrasive            = equipmentInspection.abrasive,
                allowableWear       = equipmentInspection.allowableWear,
                inspection_comments = equipmentInspection.inspection_comments,
                impact           = equipmentInspection.impact,
                inspection_date  = equipmentInspection.inspection_date,
                Jobsite_Comms    = equipmentInspection.Jobsite_Comms,
                quote_auto       = equipmentInspection.quote_auto,
                last_interp_date = equipmentInspection.last_interp_date,
                last_interp_user = equipmentInspection.last_interp_user,
                location         = equipmentInspection.location,
                ltd                         = equipmentInspection.ltd,
                confirmed_date              = equipmentInspection.confirmed_date,
                confirmed_user              = equipmentInspection.confirmed_user,
                created_date                = equipmentInspection.created_date,
                created_user                = equipmentInspection.created_user,
                docket_no                   = equipmentInspection.docket_no + DateTime.Now.Millisecond,
                dry_joints_left             = equipmentInspection.dry_joints_left,
                dry_joints_right            = equipmentInspection.dry_joints_right,
                evalcode                    = equipmentInspection.evalcode,
                eval_comment                = equipmentInspection.eval_comment,
                equipmentid_auto            = EquipmentId,
                examiner                    = equipmentInspection.examiner,
                ext_cannon_left             = equipmentInspection.ext_cannon_left,
                ext_cannon_right            = equipmentInspection.ext_cannon_right,
                frame_ext_left              = equipmentInspection.frame_ext_left,
                frame_ext_right             = equipmentInspection.frame_ext_right,
                moisture                    = equipmentInspection.moisture,
                notes                       = equipmentInspection.notes,
                packing                     = equipmentInspection.packing,
                released_by                 = equipmentInspection.released_by,
                released_date               = equipmentInspection.released_date,
                smu                         = equipmentInspection.smu,
                sprocket_left_status        = equipmentInspection.sprocket_left_status,
                sprocket_right_status       = equipmentInspection.sprocket_right_status,
                track_sag_left              = equipmentInspection.track_sag_left,
                track_sag_left_status       = equipmentInspection.track_sag_left_status,
                track_sag_right             = equipmentInspection.track_sag_right,
                track_sag_right_status      = equipmentInspection.track_sag_right_status,
                ucbrand                     = equipmentInspection.ucbrand,
                uccode                      = equipmentInspection.uccode,
                uccodedesc                  = equipmentInspection.uccodedesc,
                wear                        = equipmentInspection.wear,
                LeftTrackSagComment         = equipmentInspection.LeftTrackSagComment,
                RightTrackSagComment        = equipmentInspection.RightTrackSagComment,
                LeftCannonExtensionComment  = equipmentInspection.LeftCannonExtensionComment,
                RightCannonExtensionComment = equipmentInspection.RightCannonExtensionComment,
                LeftTrackSagImage           = equipmentInspection.LeftTrackSagImage,
                RightTrackSagImage          = equipmentInspection.RightTrackSagImage,
                LeftCannonExtensionImage    = equipmentInspection.LeftCannonExtensionImage,
                RightCannonExtensionImage   = equipmentInspection.RightCannonExtensionImage,
                TravelledKms                = equipmentInspection.TravelledKms,
                ForwardTravelHours          = equipmentInspection.ForwardTravelHours,
                ReverseTravelHours          = equipmentInspection.ReverseTravelHours,
                LeftScallopMeasurement      = equipmentInspection.LeftScallopMeasurement,
                RightScallopMeasurement     = equipmentInspection.RightScallopMeasurement
            };

            var matchedComponents = getMatchingForInspectionSync(EquipmentId.LongNullableToInt(), MblEquipmentId.LongNullableToInt());
            List <BLL.Core.Domain.InspectionDetailWithSide> tidWithSIdeList = new List <BLL.Core.Domain.InspectionDetailWithSide>();

            foreach (var mtid in mobileInspectionDetails)
            {
                var matched = matchedComponents.Where(m => m.ComponentIndex == mtid.track_unit_auto).FirstOrDefault();

                if (matched == null || matched.MatchedComponentId == 0)
                {
                    continue;
                }

                BLL.Core.Domain.Component LogicalComponent = new Component(_context, matched.MatchedComponentId);

                if (LogicalComponent != null && LogicalComponent.Id != 0)
                {
                    decimal worn = LogicalComponent.CalcWornPercentage(ConvertFrom(BLL.Core.Domain.MeasurementType.Milimeter, mtid.reading), mtid.tool_auto ?? 0, impact);
                    char    eval = ' ';
                    LogicalComponent.GetEvalCodeByWorn(worn, out eval);
                    List <TRACK_INSPECTION_IMAGES>   imageList       = new List <TRACK_INSPECTION_IMAGES>();
                    List <COMPART_ATTACH_FILESTREAM> imageStreamList = new List <COMPART_ATTACH_FILESTREAM>();
                    var mobileFileStream = _context.Mbl_CompartAttach_filestream.Where(m => m.inspection_auto == mobileEqInspection.inspection_auto && m.compartid_auto == matched.ComponentIndex).ToList();
                    foreach (var streamImage in mobileFileStream)
                    {
                        TRACK_INSPECTION_IMAGES inspectionImage = new TRACK_INSPECTION_IMAGES
                        {
                            GUID          = streamImage.guid,
                            image_comment = streamImage.comment,
                            image_data    = streamImage.attachment
                        };
                        imageList.Add(inspectionImage);
                        COMPART_ATTACH_FILESTREAM inspectionStreamImage = new COMPART_ATTACH_FILESTREAM
                        {
                            attachment               = streamImage.attachment,
                            attachment_name          = streamImage.attachment_name,
                            comment                  = streamImage.comment,
                            compartid_auto           = LogicalComponent.DALComponent.compartid_auto,
                            comparttype_auto         = LogicalComponent.DALComponent.LU_COMPART.comparttype_auto,
                            compart_attach_type_auto = streamImage.compart_attach_type_auto,
                            entry_date               = streamImage.entry_date,
                            guid            = streamImage.guid,
                            inspection_auto = InspectionId,
                            position        = LogicalComponent.DALComponent.pos,
                            tool_auto       = mtid.tool_auto,
                            user_auto       = user.Id
                        };
                        imageStreamList.Add(inspectionStreamImage);
                    }
                    TRACK_INSPECTION_DETAIL tid = new TRACK_INSPECTION_DETAIL
                    {
                        comments            = mtid.comments,
                        worn_percentage     = worn,
                        eval_code           = eval.ToString(),
                        ext_projected_hours = mtid.ext_projected_hours,
                        ext_remaining_hours = mtid.ext_remaining_hours,
                        hours_on_surface    = mtid.hours_on_surface,
                        projected_hours     = mtid.projected_hours,
                        reading             = mtid.reading,
                        remaining_hours     = mtid.remaining_hours,
                        tool_auto           = mtid.tool_auto,
                        track_unit_auto     = LogicalComponent.Id,
                        Images = imageList
                    };
                    BLL.Core.Domain.InspectionDetailWithSide tidWithSide = new BLL.Core.Domain.InspectionDetailWithSide
                    {
                        CompartAttachFileStreamImage = imageStreamList,
                        ComponentInspectionDetail    = tid,
                        side = (LogicalComponent.DALComponent.side == null || LogicalComponent.DALComponent.side > 2 || LogicalComponent.DALComponent.side < 0) ? 0 : (int)LogicalComponent.DALComponent.side
                    };
                    tidWithSIdeList.Add(tidWithSide);
                }
            }

            BLL.Core.Domain.InsertInspectionParams Params = new BLL.Core.Domain.InsertInspectionParams
            {
                EquipmentInspection  = EquipmentInspectionParam,
                ComponentsInspection = tidWithSIdeList,
                EvaluationOverall    = ' '
            };

            BLL.Interfaces.IEquipmentActionRecord EquipmentAction = new BLL.Core.Domain.EquipmentActionRecord
            {
                ActionDate    = Params.EquipmentInspection.inspection_date,
                ActionUser    = user,
                EquipmentId   = Params.EquipmentInspection.equipmentid_auto > int.MaxValue ? int.MaxValue : (int)Params.EquipmentInspection.equipmentid_auto,
                Comment       = Params.EquipmentInspection.inspection_comments,
                ReadSmuNumber = Params.EquipmentInspection.smu == null ? 0 : (int)Params.EquipmentInspection.smu,
                TypeOfAction  = BLL.Core.Domain.ActionType.InsertInspection,
                Cost          = 0
            };

            using (BLL.Core.Domain.Action UCAction = new BLL.Core.Domain.Action(new DAL.UndercarriageContext(), EquipmentAction, Params))
            {
                System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();

                UCAction.Operation.Start();
                if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Close)
                {
                    rm.OperationSucceed = false;
                    rm.ActionLog        = UCAction.Operation.ActionLog;
                    rm.LastMessage      = UCAction.Operation.Message;
                }
                if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Started)
                {
                    UCAction.Operation.Validate();
                }

                if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Invalid)
                {
                    rm.OperationSucceed = false;
                    rm.ActionLog        = UCAction.Operation.ActionLog;
                    rm.LastMessage      = UCAction.Operation.Message;
                }
                if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Valid)
                {
                    UCAction.Operation.Commit();
                }
                if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Failed)
                {
                    rm.OperationSucceed = false;
                    rm.ActionLog        = UCAction.Operation.ActionLog;
                    rm.LastMessage      = UCAction.Operation.Message;
                }
                if (UCAction.Operation.Status == BLL.Core.Domain.ActionStatus.Succeed)
                {
                    rm.OperationSucceed = true;
                    rm.ActionLog        = UCAction.Operation.ActionLog;
                    rm.LastMessage      = UCAction.Operation.Message;
                }
                rm.Id = UCAction.Operation.UniqueId;
                if (rm.OperationSucceed)
                {
                    // TT-49
                    if (mobileEquipment.EquipmentPhoto != null)
                    {
                        _context.EQUIPMENTs.Find(equipment.equipmentid_auto).EquipmentPhoto = mobileEquipment.EquipmentPhoto;
                    }

                    _context.Mbl_Track_Inspection_Detail.RemoveRange(mobileInspectionDetails);
                    _context.Mbl_Track_Inspection.Remove(mobileEqInspection);
                    _context.Mbl_NewGENERAL_EQ_UNIT.RemoveRange(mobileComponents);
                    _context.Mbl_NewEquipment.Remove(mobileEquipment);
                    var imagesTobeDelete = _context.Mbl_CompartAttach_filestream.Where(m => m.inspection_auto == mobileEqInspection.inspection_auto);
                    _context.Mbl_CompartAttach_filestream.RemoveRange(imagesTobeDelete);

                    try
                    {
                        _context.SaveChanges();
                        rm.OperationSucceed = true;
                        rm.LastMessage      = "Operation was successfull!";
                    }
                    catch (Exception m)
                    {
                        string Message = m.Message;
                        rm.OperationSucceed = false;
                        rm.LastMessage      = "Operation failed! please check log for more details!";
                        rm.ActionLog        = Message + ((m.InnerException != null) ? m.InnerException.Message : "");
                    }
                }
            }
            try
            {
                BLL.Core.Domain.Equipment LogicalEquipment = new BLL.Core.Domain.Equipment(new UndercarriageContext(), (int)EquipmentId);
                if (LogicalEquipment.Id == 0 || LogicalEquipment.GetEquipmentFamily() != BLL.Core.Domain.EquipmentFamily.MEX_Mining_Shovel)
                {
                    return(rm);
                }
                LogicalEquipment.UpdateMiningShovelInspectionParentsFromChildren(rm.Id);
                return(rm);
            } catch (Exception ex)
            {
                string message = ex.Message;
                return(rm);
            }
        }// End of transit from mobile