Ejemplo n.º 1
0
        /// <summary>
        /// Updates the cost of an event.
        /// </summary>
        /// <returns>Tuple with 2 values. First is true if the cost was updated successfully. Second is a message. </returns>
        public Tuple <bool, string> UpdateCost(decimal partsCost, decimal labourCost, decimal miscCost)
        {
            if (partsCost < 0 || labourCost < 0 || miscCost < 0)
            {
                return(Tuple.Create(false, "Failed to update cost. The value can't be less than 0. "));
            }

            // If the history record has a valid component id and the action type was
            // replace with new. We will also update the cost of the new component with the parts cost.
            if (_history.equnit_auto != null && _history.equnit_auto != 0 &&
                _history.TRACK_ACTION_TYPE.action_description == "Replace component with new")
            {
                var component = new BLL.Core.Domain.Component(_context, (int)_history.equnit_auto);
                var result    = component.UpdateComponentCost(partsCost);
                if (!result.Item1)
                {
                    return(result);
                }
            }

            try
            {
                _history.cost       = Convert.ToInt64(partsCost + labourCost + miscCost);
                _history.LabourCost = labourCost;
                _history.PartsCost  = partsCost;
                _history.MiscCost   = miscCost;
                _context.SaveChanges();
                return(Tuple.Create(true, "Cost updated successfully. "));
            }
            catch (Exception e)
            {
                return(Tuple.Create(false, "Failed to update cost. " + e.ToDetailedString()));
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public async Task <Tuple <bool, string> > UpdateComponentRecordMeasurement(int id, decimal newMeasurement, MeasurementType uom)
        {
            var record = await _context.WSREComponentRecord.FindAsync(id);

            if (record == null)
            {
                return(Tuple.Create(false, "Couldn't find a component record with this id. "));
            }

            var component         = new BLL.Core.Domain.Component(new UndercarriageContext(), Convert.ToInt32(record.ComponentId));
            var newWornPercentage = component.CalcWornPercentage(uom == MeasurementType.Milimeter ? newMeasurement.ConvertMMToInch() : newMeasurement, record.MeasurementToolId, InspectionImpact.High);

            record.Measurement    = uom == MeasurementType.Inch ? newMeasurement.InchToMilimeter() : newMeasurement;
            record.WornPercentage = newWornPercentage;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch
            {
                return(Tuple.Create(false, "Failed to save component measurement. "));
            }
            return(Tuple.Create(true, "Measurement and % updated successfully. "));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Mining Shovel APIs
        /// </summary>
        /// <param name="Equip"></param>
        /// <returns></returns>
        public Stream PostValidateMiningShovelEquipInfo(BLL.Core.MiningShovel.Models.SyncModel Equip)
        {
            List <BLL.Core.Domain.ResultMessageExtended> rmList = new List <BLL.Core.Domain.ResultMessageExtended>();

            try
            {
                ///////////////////////////////////////////////////////////
                // Update TRACK_INSPECTION and TRACK_INSPECTION_DETAIL
                EquipmentInspectionListEntity EquipList = new EquipmentInspectionListEntity();

                ///////////////////
                // Equipment count
                EquipList.EquipmentsCount = 1;

                ///////////////////
                // New equipment
                List <NewEquipmentEntity> newEquip = new List <NewEquipmentEntity>();
                EquipList.NewEquipmentsInspectionsList = newEquip;

                ///////////////////
                // Equipment list
                List <UndercarriageInspectionEntity> EquipmentsInspectionsList = new List <UndercarriageInspectionEntity>();
                UndercarriageInspectionEntity        equipInspection           = new UndercarriageInspectionEntity();
                equipInspection.Abrasive              = Equip.abrasive;
                equipInspection.Impact                = Equip.impact;
                equipInspection.Moisture              = Equip.moisture;
                equipInspection.Packing               = Equip.packing;
                equipInspection.SMU                   = Equip.smu.ToString();
                equipInspection.DryJointsLeft         = 0;
                equipInspection.DryJointsRight        = 0;
                equipInspection.EquipmentIdAuto       = Equip.equipmentid_auto;
                equipInspection.Examiner              = Equip.examiner;
                equipInspection.ExtCannonLeft         = 0;
                equipInspection.ExtCannonRight        = 0;
                equipInspection.InspectionDate        = Equip.currentDateandTime;
                equipInspection.InspectorComments     = Equip.notes;
                equipInspection.JobsiteComments       = Equip.Jobsite_Comms;
                equipInspection.leftCannonExtComment  = "";
                equipInspection.leftCannonExtImage    = "";
                equipInspection.leftScallop           = 0;
                equipInspection.leftTrackSagComment   = "";
                equipInspection.leftTrackSagImage     = "";
                equipInspection.rightCannonExtComment = "";
                equipInspection.rightCannonExtImage   = "";
                equipInspection.rightScallop          = 0;
                equipInspection.rightTrackSagComment  = "";
                equipInspection.rightTrackSagImage    = "";
                equipInspection.TrackSagLeft          = 0;
                equipInspection.TrackSagRight         = 0;
                equipInspection.travelForward         = 0;
                equipInspection.travelReverse         = 0;
                equipInspection.TrammingHours         = Equip.TrammingHours;
                equipInspection.CustomerContact       = Equip.CustomerContact;

                // InspectionDetails
                //equipInspection.Details = ???
                List <InspectionDetails> inspectionDetailList = new List <InspectionDetails>();
                foreach (var item in Equip.InspectionDetails)
                {
                    InspectionDetails inspectionDetail = new InspectionDetails();
                    inspectionDetail.AttachmentType = 0;
                    inspectionDetail.Comments       = "";
                    inspectionDetail.TrackUnitAuto  = item.EqunitAuto;

                    DAL.LU_COMPART            compart   = new LU_COMPART();
                    BLL.Core.Domain.Component component = new BLL.Core.Domain.Component(new UndercarriageContext());
                    compart = component.getCompart(item.EqunitAuto);

                    inspectionDetail.CompartIdAuto   = compart.compartid_auto;
                    inspectionDetail.FlangeType      = "";
                    inspectionDetail.Image           = "";
                    inspectionDetail.InspectionImage = "";
                    inspectionDetail.PercentageWorn  = 0;
                    inspectionDetail.Reading         = "";
                    inspectionDetail.ToolUsed        = "";

                    inspectionDetailList.Add(inspectionDetail);
                }

                equipInspection.Details = inspectionDetailList;

                EquipmentsInspectionsList.Add(equipInspection);

                EquipList.EquipmentsInspectionsList = EquipmentsInspectionsList;

                /////////////
                // Validate
                //List<BLL.Core.Domain.ResultMessageExtended> returnList = SaveEquipmentsInspectionsData(EquipList);
                try
                {
                    rmList = EquipmentInspectionList.Instance.SaveRopeShovelEquipmentInspections(EquipList);
                }
                catch (Exception ex)
                {
                    BLL.Core.Domain.ResultMessageExtended rmException = new BLL.Core.Domain.ResultMessageExtended();
                    rmException.ActionLog = "In Service " + ex.Message;
                    if (ex.InnerException != null)
                    {
                        rmException.ActionLog += ex.InnerException.Message;
                    }
                    rmException.OperationSucceed = false;
                    rmException.Id          = -1;
                    rmException.LastMessage = ex.Message;
                    rmList.Add(rmException);
                }
            }
            catch (Exception ex)
            {
                BLL.Core.Domain.ResultMessageExtended rmException = new BLL.Core.Domain.ResultMessageExtended();
                rmException.ActionLog = "In Service " + ex.Message;
                if (ex.InnerException != null)
                {
                    rmException.ActionLog += ex.InnerException.Message;
                }
                rmException.OperationSucceed = false;
                rmException.Id          = -1;
                rmException.LastMessage = ex.Message;
                rmList.Add(rmException);
            }

            //return rmList.First().Id;
            var stream = new MemoryStream();
            var writer = new StreamWriter(stream);

            writer.Write(JsonConvert.SerializeObject(rmList));
            writer.Flush();
            stream.Position = 0;
            return(stream);
        }
Ejemplo n.º 5
0
        public void storeSetupLogic(BLL.Core.Domain.UndercarriageSetupSystemViewModel systemModel,
                                    BLL.Core.Domain.EquipmentSystemsExistence eqStat,
                                    BLL.Core.Domain.SetupSystemParams param,
                                    int LogicalEquipmentId, BLL.Interfaces.IUser user, BLL.Core.Domain.Side selectedSide
                                    )
        {
            if (systemModel.Id == 0 && !eqStat.LeftChain) //NEW SYSTEM
            {
                BLL.Core.Domain.UCSystem leftChain = new BLL.Core.Domain.UCSystem(new DAL.UndercarriageContext());
                param.SerialNo  = systemModel.SerialNo;
                param.Side      = selectedSide;
                param.Life      = systemModel.systemLife;
                param.SetupDate = systemModel.InstallationDate;
                if (leftChain.CreateNewSystem(param, LogicalEquipmentId))
                {
                    param.Id = leftChain.Id;
                    BLL.Interfaces.IEquipmentActionRecord EquipmentAction = new BLL.Core.Domain.EquipmentActionRecord
                    {
                        EquipmentId   = LogicalEquipmentId,
                        ReadSmuNumber = systemModel.EquipmentSMU,
                        TypeOfAction  = BLL.Core.Domain.ActionType.InstallSystemOnEquipment,
                        ActionDate    = systemModel.InstallationDate,
                        ActionUser    = user,
                        Cost          = 0,
                        Comment       = "System Setup"
                    };
                    using (BLL.Core.Domain.Action action = new BLL.Core.Domain.Action(new DAL.UndercarriageContext(), EquipmentAction, new BLL.Core.Domain.InstallSystemParams {
                        Id = leftChain.Id, EquipmentId = LogicalEquipmentId, side = selectedSide
                    }))
                    {
                        if (action.Operation.Start() == BLL.Core.Domain.ActionStatus.Started &&
                            action.Operation.Validate() == BLL.Core.Domain.ActionStatus.Valid &&
                            action.Operation.Commit() == BLL.Core.Domain.ActionStatus.Succeed)
                        {
                            foreach (var comp in systemModel.Components)
                            {
                                var componentParam = new BLL.Core.Domain.SetupComponentParams
                                {
                                    BudgetLife = comp.BudgetLife,
                                    CMU        = comp.ComponentCurrentLife,
                                    CompartId  = comp.CompartId,
                                    Cost       = comp.Cost,
                                    Id         = comp.Id,
                                    Life       = comp.ComponentCurrentLife,
                                    UserId     = user.Id,
                                    UserName   = user.userName
                                };
                                var LogicalComponent = new BLL.Core.Domain.Component(new DAL.UndercarriageContext());
                                if (LogicalComponent.CreateNewComponent(componentParam))
                                {
                                    BLL.Interfaces.IEquipmentActionRecord EquipmentActionForComp = new BLL.Core.Domain.EquipmentActionRecord
                                    {
                                        EquipmentId   = LogicalEquipmentId,
                                        ReadSmuNumber = comp.EquipmetSMU,
                                        TypeOfAction  = BLL.Core.Domain.ActionType.InstallComponentOnSystemOnEquipment,
                                        ActionDate    = comp.InstallationDate,
                                        ActionUser    = user,
                                        Cost          = 0,
                                        Comment       = "Component Setup"
                                    };
                                    using (BLL.Core.Domain.Action compAction = new BLL.Core.Domain.Action(new DAL.UndercarriageContext(), EquipmentActionForComp, new BLL.Core.Domain.InstallComponentOnSystemParams {
                                        Id = LogicalComponent.Id, Position = comp.Position, SystemId = leftChain.Id, side = selectedSide
                                    }))
                                    {
                                        compAction.Operation.Start();
                                        compAction.Operation.Validate();
                                        compAction.Operation.Commit();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else //UPDATE SYSTEM
            {
                var LogicalSystem = new BLL.Core.Domain.UCSystem(new DAL.UndercarriageContext(), systemModel.Id);
                if (LogicalSystem.Id != 0 && LogicalSystem.Components != null)
                {
                    var removiongComponents = LogicalSystem.Components.Where(m => !systemModel.Components.Any(n => m.equnit_auto == n.Id));
                    if (LogicalSystem.removeComponents(removiongComponents.ToList()))
                    {
                        //Components which are not in the list of current components should be removed from installed components!
                        //Just for monitoring purposes
                        string message = "";
                        message += "Components removed successfully";
                    }

                    foreach (var comp in systemModel.Components)
                    {
                        var componentParam = new BLL.Core.Domain.SetupComponentParams
                        {
                            BudgetLife = comp.BudgetLife,
                            CMU        = comp.ComponentCurrentLife,
                            CompartId  = comp.CompartId,
                            Cost       = comp.Cost,
                            Id         = comp.Id,
                            Life       = comp.ComponentCurrentLife,
                            UserId     = user.Id,
                            UserName   = user.userName
                        };
                        if (comp.Id == 0) //New Component Added
                        {
                            var LogicalComponent = new BLL.Core.Domain.Component(new DAL.UndercarriageContext());
                            if (LogicalComponent.CreateNewComponent(componentParam))
                            {
                                BLL.Interfaces.IEquipmentActionRecord EquipmentActionForComp = new BLL.Core.Domain.EquipmentActionRecord
                                {
                                    EquipmentId   = LogicalEquipmentId,
                                    ReadSmuNumber = comp.EquipmetSMU,
                                    TypeOfAction  = BLL.Core.Domain.ActionType.InstallComponentOnSystemOnEquipment,
                                    ActionDate    = comp.InstallationDate,
                                    ActionUser    = user,
                                    Cost          = 0,
                                    Comment       = "Component Setup"
                                };
                                using (BLL.Core.Domain.Action compAction = new BLL.Core.Domain.Action(new DAL.UndercarriageContext(), EquipmentActionForComp, new BLL.Core.Domain.InstallComponentOnSystemParams {
                                    Id = LogicalComponent.Id, Position = comp.Position, SystemId = systemModel.Id, side = selectedSide
                                }))
                                {
                                    compAction.Operation.Start();
                                    compAction.Operation.Validate();
                                    compAction.Operation.Commit();
                                }
                            }
                        }
                        else
                        {
                            var LogicalComponent = new BLL.Core.Domain.Component(new DAL.UndercarriageContext(), comp.Id);
                            LogicalComponent.removeInstallationRecord();
                            LogicalComponent.UpdateComponentOnSetup(componentParam);
                            BLL.Interfaces.IEquipmentActionRecord EquipmentActionForComp = new BLL.Core.Domain.EquipmentActionRecord
                            {
                                EquipmentId   = LogicalEquipmentId,
                                ReadSmuNumber = comp.EquipmetSMU,
                                TypeOfAction  = BLL.Core.Domain.ActionType.InstallComponentOnSystemOnEquipment,
                                ActionDate    = comp.InstallationDate,
                                ActionUser    = user,
                                Cost          = 0,
                                Comment       = "Component Setup"
                            };
                            using (BLL.Core.Domain.Action compAction = new BLL.Core.Domain.Action(new DAL.UndercarriageContext(), EquipmentActionForComp, new BLL.Core.Domain.InstallComponentOnSystemParams {
                                Id = LogicalComponent.Id, Position = comp.Position, SystemId = systemModel.Id, side = selectedSide
                            }))
                            {
                                compAction.Operation.Start();
                                compAction.Operation.Validate();
                                compAction.Operation.Commit();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public Boolean SaveWSREComponentRecords(
            DAL.WSREComponentRecord record,
            WSREComponentRecordModel item)
        {
            // Comment
            record.Comment = item.Comment;

            // ComponentId
            record.ComponentId = item.ComponentId;

            // Measurement
            record.Measurement = item.Measurement;

            // MeasurementToolId
            TrackTool tool = new TrackTool();
            int       Id   = tool.GetIdByToolCode(item.MeasurementToolId);

            record.MeasurementToolId = Id;

            // WornPercentage
            var component = new BLL.Core.Domain.Component(new UndercarriageContext(), Convert.ToInt32(record.ComponentId));

            record.WornPercentage = component.CalcWornPercentage(record.Measurement.ConvertMMToInch(), record.MeasurementToolId, InspectionImpact.High);
            char charEval = record.WornPercentage.toEvalChar();

            _overallEval = GetOverallEval(charEval, _overallEval);

            // INSERT
            _WSREComponentRecords.Add(record);
            _context.SaveChanges();
            _arrComponentRecordId.Add(record.Id);

            //////////////////////////////////
            // WSREComponentImages table
            foreach (var image in item.Images)
            {
                // ComponentrecordId
                DAL.WSREComponentImage imgRecord = new DAL.WSREComponentImage();
                imgRecord.ComponentRecordId = record.Id;

                // Data
                byte[] imageData = GetUploadImageData(image.Data);
                imgRecord.Data = imageData;

                // Title
                imgRecord.Title = image.ImageTitle;

                // Comment
                imgRecord.Comment = image.ImageComment;

                // IncludeInReport
                imgRecord.IncludeInReport = true;

                // Deleted
                imgRecord.Deleted = false;

                // INSERT
                _WSREComponentImages.Add(imgRecord);
            }

            ///////////////////////////////////////////////
            // WSREComponentRecordRecommendations table
            foreach (var recommend in item.RecommendationId)
            {
                DAL.WSREComponentRecordRecommendation recommendRecord = new DAL.WSREComponentRecordRecommendation();
                recommendRecord.ComponentRecordId = record.Id;
                recommendRecord.RecommendationId  = recommend;

                // INSERT
                _WSREComponentRecordRecommendations.Add(recommendRecord);
            }

            return(true);
        }