public static decimal KomatsuReadingMapper(TRACK_COMPART_WORN_LIMIT_KOMATSU r, decimal reading, InspectionImpact?i) { if (i == null) { return((decimal) - 0.0007); } InspectionImpact impact = (InspectionImpact)i; decimal? A; decimal? B; decimal? C; if (i == InspectionImpact.High) { A = r.impact_secondorder; B = r.impact_slope; C = r.impact_intercept; } else { A = r.normal_secondorder; B = r.normal_slope; C = r.normal_intercept; } return(secondOrder(A, B, C, reading)); }
public static decimal HitachiReadingMapper(TRACK_COMPART_WORN_LIMIT_HITACHI r, decimal reading, InspectionImpact?i) { if (i == null) { return((decimal) - 0.0008); } InspectionImpact impact = (InspectionImpact)i; decimal? A; decimal? B; if (i == InspectionImpact.High) { A = r.impact_slope; B = r.impact_intercept; } else { A = r.normal_slope; B = r.normal_intercept; } return(firstOrder(A, B, reading)); }
public ActionStatus Commit() { ActionLog += "Commiting the Operation ..." + Environment.NewLine; if (Status != ActionStatus.Valid) { ActionLog += "Operation Status is not valid" + Environment.NewLine; Status = ActionStatus.Failed; return(Status); } int tempEQId = longNullableToint(DALOldSystem.equipmentid_auto); DALNewSystem.equipmentid_auto = tempEQId; DALNewSystem.crsf_auto = logicalOldSystem.DALEquipment.crsf_auto; DALNewSystem.equipment_LTD_at_attachment = _actionRecord.EquipmentActualLife; DALNewSystem.modifiedDate = _actionRecord.ActionDate.ToLocalTime().Date; DALNewSystem.SMU_at_install = _actionRecord.ReadSmuNumber; //When systems are created these values are not added!!! //So when system is going to be placed in inventory, values are set DALOldSystem.crsf_auto = logicalOldSystem.DALEquipment.crsf_auto; DALOldSystem.system_LTD_on_removal = logicalOldSystem.GetSystemLife(_actionRecord.ActionDate); DALOldSystem.make_auto = MMTA.make_auto; DALOldSystem.model_auto = MMTA.model_auto; DALOldSystem.type_auto = MMTA.type_auto; DALOldSystem.equipmentid_auto = null; //Update any recorded life for the old system which actualy should belong to the new one var systemRecordedLifes = _context.UCSYSTEM_LIFE.Where(m => m.SystemId == logicalOldSystem.Id && m.ActionDate > _actionRecord.ActionDate).ToList(); foreach (var life in systemRecordedLifes) { var athistoryFuture = _context.ACTION_TAKEN_HISTORY.Find(life.ActionId); int EqLifeInFutureAction = 0; int EqSMUInFutureAction = 0; if (athistoryFuture != null) { if (athistoryFuture.system_auto_id == DALOldSystem.Module_sub_auto) { athistoryFuture.system_auto_id = DALNewSystem.Module_sub_auto; _context.Entry(athistoryFuture).State = EntityState.Modified; } EqLifeInFutureAction = athistoryFuture.equipment_ltd; EqSMUInFutureAction = athistoryFuture.equipment_smu; } int newSystemActualLife = logicalNewSystem.GetSystemLife(_actionRecord.ActionDate); if (EqLifeInFutureAction != 0 && EqLifeInFutureAction > _actionRecord.EquipmentActualLife) { newSystemActualLife += (EqLifeInFutureAction - _actionRecord.EquipmentActualLife); } else if (EqSMUInFutureAction != 0 && EqSMUInFutureAction > _actionRecord.ReadSmuNumber) { newSystemActualLife += (EqSMUInFutureAction - _actionRecord.ReadSmuNumber); } life.ActualLife = newSystemActualLife; life.SystemId = logicalNewSystem.Id; life.Title = "Updated because of system replacement in the past"; _context.Entry(life).State = EntityState.Modified; } foreach (var Comp in logicalOldSystem.Components) { //Update all life records of the old components which belongs to the new components var componentRecordedLifes = _context.COMPONENT_LIFE.Where(m => m.ComponentId == Comp.equnit_auto && m.ActionDate > _actionRecord.ActionDate).ToList(); foreach (var life in componentRecordedLifes) { var newcmpnt = GetComponentBasedOnTypeAndPositionFromOldSystemToTheNewOne(Comp.equnit_auto); // ↓↓↓↓↓ Means there is no component with the same type and position on the new system if (newcmpnt == null) { continue; } var athistoryFuture = _context.ACTION_TAKEN_HISTORY.Find(life.ActionId); int EqLifeInFutureAction = 0; int EqSMUInFutureAction = 0; // ↓↓↓↓↓ Updating a field in the ACTION_TAKEN_HISTORY Table to point to the new component if (athistoryFuture != null) { if (athistoryFuture.equnit_auto == Comp.equnit_auto) { athistoryFuture.equnit_auto = newcmpnt.Id; _context.Entry(athistoryFuture).State = EntityState.Modified; } EqLifeInFutureAction = athistoryFuture.equipment_ltd; EqSMUInFutureAction = athistoryFuture.equipment_smu; } int newComponentActualLife = newcmpnt.GetComponentLife(_actionRecord.ActionDate); if (EqLifeInFutureAction != 0 && EqLifeInFutureAction > _actionRecord.EquipmentActualLife) { newComponentActualLife += (EqLifeInFutureAction - _actionRecord.EquipmentActualLife); } else if (EqSMUInFutureAction != 0 && EqSMUInFutureAction > _actionRecord.ReadSmuNumber) { newComponentActualLife += (EqSMUInFutureAction - _actionRecord.ReadSmuNumber); } life.ActualLife = newComponentActualLife; life.ComponentId = newcmpnt.Id; life.Title = "Updated because of system replacement in the past"; _context.Entry(life).State = EntityState.Modified; } Comp.equipmentid_auto = null; //This line is Commented because of an issue in the inspection page. //Comp.cmu = GetComponentLife(longNullableToint(Comp.equnit_auto), _actionRecord.ActionDate); _context.Entry(Comp).State = EntityState.Modified; } foreach (var Comp in logicalNewSystem.Components) { Comp.equipmentid_auto = DALNewSystem.equipmentid_auto; Comp.side = (byte?)logicalOldSystem.side; Comp.eq_smu_at_install = GetEquipmentSerialMeterUnit(tempEQId, _actionRecord.ActionDate); Comp.system_LTD_at_install = logicalNewSystem.GetSystemLife(_actionRecord.ActionDate); Comp.eq_ltd_at_install = GetEquipmentLife(tempEQId, _actionRecord.ActionDate); //Comp.cmu = GetComponentLife(longNullableToint(Comp.equnit_auto), _actionRecord.ActionDate); Comp.smu_at_install = Comp.eq_smu_at_install; Comp.date_installed = _actionRecord.ActionDate; _context.Entry(Comp).State = EntityState.Modified; } //Step3 Update action record to have system fields ActionLog += "Updating Action History ..." + Environment.NewLine; var dalActionRecord = _context.ACTION_TAKEN_HISTORY.Find(_actionRecord.Id); //TRACK_ACTION_TYPE Table should be updated to show actions related to the new actions dalActionRecord.action_type_auto = (int)ActionType.ReplaceSystemFromInventory; dalActionRecord.cost = (long)_actionRecord.Cost; dalActionRecord.system_auto_id = Params.OldSystemId; dalActionRecord.system_auto_id_new = Params.NewSystemId; dalActionRecord.recordStatus = (int)RecordStatus.Available; _context.Entry(dalActionRecord).State = System.Data.Entity.EntityState.Modified; //Update all inspections after this change out var inspections = _context.EQUIPMENTs.Find(_actionRecord.EquipmentId).TRACK_INSPECTION.Where(m => m.inspection_date > _actionRecord.ActionDate).ToList(); foreach (var inspect in inspections) { var details = inspect.TRACK_INSPECTION_DETAIL.Where(m => m.UCSystemId == Params.OldSystemId).ToList(); foreach (var d in details) { var Newcmpnt = GetComponentBasedOnTypeAndPositionFromOldSystemToTheNewOne(d.track_unit_auto); // Does the new component found in the inspection details? if (Newcmpnt != null) { InspectionImpact impact = d.TRACK_INSPECTION.impact == 2 ? InspectionImpact.High : InspectionImpact.Low; int ToolId = d.tool_auto == null ? 0 : (int)d.tool_auto; if (Newcmpnt.Id != 0) { d.worn_percentage = Newcmpnt.CalcWornPercentage(ConvertFrom(MeasurementType.Milimeter, d.reading), ToolId, impact); char evl = '-'; if (Newcmpnt.GetEvalCodeByWorn(d.worn_percentage, out evl)) { d.eval_code = evl.ToString(); } d.hours_on_surface = Newcmpnt.GetComponentLife(inspect.inspection_date); } d.track_unit_auto = Newcmpnt.Id; d.UCSystemId = logicalNewSystem.Id; _context.Entry(d).State = EntityState.Modified; } } try { ActionLog += "Save inspection changes to the database ..." + Environment.NewLine; _context.SaveChanges(); ActionLog += "Save all succeeded" + Environment.NewLine; } catch (Exception e) { ActionLog += "Save inspection changes FAILED : " + e.Message; Status = ActionStatus.Failed; Message = "Save inspection changes FAILED "; return(Status); } new Equipment(_context, (int)inspect.equipmentid_auto).UpdateMiningShovelInspectionParentsFromChildren(inspect.inspection_auto); } _context.Entry(DALNewSystem).State = EntityState.Modified; _context.Entry(DALOldSystem).State = EntityState.Modified; try { ActionLog += "Save all changes to the database ..." + Environment.NewLine; _context.SaveChanges(); ActionLog += "Save all succeeded" + Environment.NewLine; } catch (Exception e) { ActionLog += "Save all changes FAILED : " + e.Message; Status = ActionStatus.Failed; Message = "Save all changes FAILED "; return(Status); } //Add life for new system and all new components foreach (var Comp in logicalNewSystem.Components) { ActionLog += "Adding Life of the new component"; DAL.ComponentLife NewComponentLife = new ComponentLife { ActionDate = _actionRecord.ActionDate, ActionId = _actionRecord.Id, ActualLife = longNullableToint(Comp.cmu), ComponentId = Comp.equnit_auto, Title = "New component life added by replace System Action", UserId = _actionRecord.ActionUser.Id }; _context.COMPONENT_LIFE.Add(NewComponentLife); } //Add life for the new system SystemLife NewSystemLife = new SystemLife { ActionDate = _actionRecord.ActionDate, ActionId = _actionRecord.Id, SystemId = logicalNewSystem.Id, Title = "New System life added by replace System Action", UserId = _actionRecord.ActionUser.Id, ActualLife = logicalNewSystem.GetSystemLife(_actionRecord.ActionDate) }; _context.UCSYSTEM_LIFE.Add(NewSystemLife); try { ActionLog += "Adding Life of the new components nad system"; _context.SaveChanges(); ActionLog += "Adding Life of the new components and system Succeeded"; } catch (Exception e1) { ActionLog += "Adding Life of the new components Filed " + e1.Message; string Message = e1.Message; } Status = ActionStatus.Succeed; Message = "All done successfully"; return(Status); }
public static decimal CATReadingMapper(TRACK_COMPART_WORN_LIMIT_CAT r, decimal reading, InspectionImpact?i) { if (i == null) { return((decimal) - 0.0006); } InspectionImpact impact = (InspectionImpact)i; decimal? slope; decimal? intercept; if (impact == InspectionImpact.High) { if (r.slope == 0) { if (reading >= r.hi_inflectionPoint) { slope = r.hi_slope1; intercept = r.hi_intercept1; } else { slope = r.hi_slope2; intercept = r.hi_intercept2; } } else { if (reading >= r.hi_inflectionPoint) { slope = r.hi_slope2; intercept = r.hi_intercept2; } else { slope = r.hi_slope1; intercept = r.hi_intercept1; } } } else { if (r.slope == 0) { if (reading >= r.mi_inflectionPoint) { slope = r.mi_slope1; intercept = r.mi_intercept1; } else { slope = r.mi_slope2; intercept = r.mi_intercept2; } } else { if (reading >= r.mi_inflectionPoint) { slope = r.mi_slope2; intercept = r.mi_intercept2; } else { slope = r.mi_slope1; intercept = r.mi_intercept1; } } } if (slope == null || intercept == null) { return((decimal) - 0.00069); } return(Math.Round(((decimal)slope * reading) + ((decimal)intercept), 3)); }
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; }
public ActionStatus Commit() { ActionLog += "Commiting the Operation ..." + Environment.NewLine; if (Status != ActionStatus.Valid) { ActionLog += "Operation Status is not valid" + Environment.NewLine; Status = ActionStatus.Failed; return(Status); } //Including Steps: //Step1 Detach the old component //Step2 Create a new component attached to this Equipment and set system as well //Step3 Update ActionRecord //Step1 ActionLog += "Adding New Component ..." + Environment.NewLine; GENERAL_EQ_UNIT geuNew = new GENERAL_EQ_UNIT { equipmentid_auto = _actionRecord.EquipmentId, module_ucsub_auto = Params.oldgeuComponent.module_ucsub_auto, date_installed = _actionRecord.ActionDate, created_user = _actionRecord.ActionUser.userStrId, compartid_auto = Params.newComponent.CompartId, created_date = _actionRecord.ActionDate, comp_status = (byte)Params.newComponent.ComponentStatus, pos = Params.oldgeuComponent.pos, side = Params.oldgeuComponent.side, eq_ltd_at_install = _actionRecord.EquipmentActualLife, track_0_worn = 0, track_100_worn = 0, track_120_worn = 0, track_budget_life = Params.newComponent.BudgetedLife, cmu = Params.newComponent.ComponentLifeAtInstall, cost = Params.newComponent.Cost, eq_smu_at_install = _actionRecord.ReadSmuNumber, smu_at_install = _actionRecord.ReadSmuNumber, system_LTD_at_install = GetSystemLife(longNullableToint(Params.oldgeuComponent.equnit_auto), _actionRecord.ActionDate), component_current_value = 0, variable_comp = false, insp_uom = 0, make_auto = Params.newComponent.brandId == 0 ? null : (int?)Params.newComponent.brandId }; _context.GENERAL_EQ_UNIT.Add(geuNew); try { ActionLog += "Save new component to the database and get the new Id ..." + Environment.NewLine; _context.SaveChanges(); ActionLog += "Save new component succeed" + Environment.NewLine; } catch (Exception e) { ActionLog += "Save new component FAILED : " + e.Message; Status = ActionStatus.Failed; Message = "Save new component FAILED"; return(Status); } //Step3 Update action record to have component fields ActionLog += "Updating Action History ..." + Environment.NewLine; var dalActionRecord = _context.ACTION_TAKEN_HISTORY.Find(_actionRecord.Id); //Now the Action Taken History Table should be updated to show actions details dalActionRecord.compartid_auto = Params.oldgeuComponent.compartid_auto; if (new Compart(_context).isAChild(Params.oldgeuComponent.compartid_auto)) //TT-610 -> if is a child then don't reference the old component because it would cause duplicate records in history page { dalActionRecord.equnit_auto = -(Params.oldgeuComponent.equnit_auto); dalActionRecord.equnit_auto_new = -geuNew.equnit_auto; } else { dalActionRecord.equnit_auto = Params.oldgeuComponent.equnit_auto; dalActionRecord.equnit_auto_new = geuNew.equnit_auto; } dalActionRecord.action_type_auto = (int)ActionType.ReplaceComponentWithNew; dalActionRecord.cmu = (int)Params.oldgeuComponent.cmu; dalActionRecord.cost = (long)_actionRecord.Cost; dalActionRecord.system_auto_id = Params.oldgeuComponent.module_ucsub_auto; dalActionRecord.recordStatus = (int)RecordStatus.Available; _context.Entry(dalActionRecord).State = System.Data.Entity.EntityState.Modified; //Update all life records of the old component to be for the new component var componentLifesAfterChangeOut = _context.COMPONENT_LIFE.Where(m => m.ComponentId == Params.oldgeuComponent.equnit_auto && m.ActionDate > _actionRecord.ActionDate).ToList(); foreach (var life in componentLifesAfterChangeOut) { var athistoryFuture = _context.ACTION_TAKEN_HISTORY.Find(life.ActionId); int EqLifeInFutureAction = 0; int EqSMUInFutureAction = 0; if (athistoryFuture != null) { if (athistoryFuture.equnit_auto == Params.oldgeuComponent.equnit_auto) { athistoryFuture.equnit_auto = geuNew.equnit_auto; _context.Entry(athistoryFuture).State = EntityState.Modified; } EqLifeInFutureAction = athistoryFuture.equipment_ltd; EqSMUInFutureAction = athistoryFuture.equipment_smu; } int newComponentActualLife = 0; if (EqLifeInFutureAction != 0 && EqLifeInFutureAction > _actionRecord.EquipmentActualLife) { newComponentActualLife = Params.newComponent.ComponentLifeAtInstall + (EqLifeInFutureAction - _actionRecord.EquipmentActualLife); } else if (EqSMUInFutureAction != 0 && EqSMUInFutureAction > _actionRecord.ReadSmuNumber) { newComponentActualLife = Params.newComponent.ComponentLifeAtInstall + (EqSMUInFutureAction - _actionRecord.ReadSmuNumber); } if (newComponentActualLife == 0) { newComponentActualLife = Params.newComponent.ComponentLifeAtInstall; } life.ActualLife = newComponentActualLife; life.ComponentId = geuNew.equnit_auto; life.Title = "Updated because of component replacement in the past"; _context.Entry(life).State = EntityState.Modified; } //Step4 Update all inspections after this change out var inspections = _context.EQUIPMENTs.Find(_actionRecord.EquipmentId).TRACK_INSPECTION.Where(m => m.inspection_date > _actionRecord.ActionDate).ToList(); var logicalEquipment = new Equipment(_context, _actionRecord.EquipmentId); foreach (var inspect in inspections) { var details = inspect.TRACK_INSPECTION_DETAIL.Where(m => m.track_unit_auto == Params.oldgeuComponent.equnit_auto).ToList(); foreach (var d in details) { var cmpnt = new Component(_context, longNullableToint(geuNew.equnit_auto)); InspectionImpact impact = d.TRACK_INSPECTION.impact == 2 ? InspectionImpact.High : InspectionImpact.Low; int ToolId = d.tool_auto == null ? 0 : (int)d.tool_auto; if (cmpnt.Id != 0) { d.worn_percentage = cmpnt.CalcWornPercentage(ConvertFrom(MeasurementType.Milimeter, d.reading), ToolId, impact); char evl = '-'; if (cmpnt.GetEvalCodeByWorn(d.worn_percentage, out evl)) { d.eval_code = evl.ToString(); } d.hours_on_surface = cmpnt.GetComponentLife(inspect.inspection_date); } // Update images stored in the old table to reference the new compartid_auto if the component type has changed // with the new replacement. Otherwise the image will not be viewable in the image popup. var images = _context.COMPART_ATTACH_FILESTREAM.Where(f => f.compartid_auto == Params.oldgeuComponent.compartid_auto) .Where(f => f.position == Params.oldgeuComponent.pos) .Where(f => f.inspection_auto == d.inspection_auto); foreach (var i in images) { i.compartid_auto = geuNew.compartid_auto; _context.Entry(i).State = EntityState.Modified; } d.track_unit_auto = geuNew.equnit_auto; _context.Entry(d).State = System.Data.Entity.EntityState.Modified; } logicalEquipment.UpdateMiningShovelInspectionParentsFromChildren(inspect.inspection_auto); } Params.oldgeuComponent.equipmentid_auto = null; Params.oldgeuComponent.module_ucsub_auto = null; Params.oldgeuComponent.modified_user = _actionRecord.ActionUser.userStrId; _context.Entry(Params.oldgeuComponent).State = System.Data.Entity.EntityState.Modified; try { ActionLog += "Save all changes to the database and get the new Id ..." + Environment.NewLine; _context.SaveChanges(); ActionLog += "Save all succeeded" + Environment.NewLine; } catch (Exception e) { ActionLog += "Save all changes FAILED : " + e.Message; Status = ActionStatus.Failed; Message = "Save all changes FAILED "; return(Status); } //Add a life record for the new component ActionLog += "Adding Life of the new component"; DAL.ComponentLife NewComponentLife = new ComponentLife { ActionDate = _actionRecord.ActionDate, ActionId = _actionRecord.Id, ActualLife = longNullableToint(geuNew.cmu), ComponentId = geuNew.equnit_auto, Title = "New component added by replace Action", UserId = _actionRecord.ActionUser.Id }; _context.COMPONENT_LIFE.Add(NewComponentLife); try { ActionLog += "Adding Life of the new component"; _context.SaveChanges(); ActionLog += "Adding Life of the new component Succeed"; } catch (Exception e1) { ActionLog += "Adding Life of the new component Filed " + e1.Message; string Message = e1.Message; } UniqueId = geuNew.equnit_auto.LongNullableToInt(); Status = ActionStatus.Succeed; Message = "All done successfully"; return(Status); }