private static T Process <T>(T obj, AtmlActionType actionType, IAtmlController <T> controller, EventArgs args) { T retVal = default(T); switch (actionType) { case AtmlActionType.Add: controller.Save(obj); break; case AtmlActionType.Edit: controller.Save(obj); break; case AtmlActionType.Delete: controller.Save(obj); break; case AtmlActionType.Find: AtmlActionEventArgs aeArgs = args as AtmlActionEventArgs; if (aeArgs != null) { retVal = controller.Find(aeArgs.Guid); } break; } return(retVal); }
/** * Lookup the Instrument by the part number and test station in the asset table. */ public static String FindInstrumentReference(string partNumber, string stationId) { string referenceId = ""; try { IAtmlController <TestStationDescription11> controller = AtmlControllerFactory <TestStationDescription11> .Controller; TestStationDescription11 testStation = controller.Find(Guid.Parse(stationId)); if (testStation == null) { throw new Exception(string.Format(ErrorLocatingTestStation, stationId)); } string stationType = testStation.Identification.ModelName; string basePartNumber = partNumber.Split('#')[0]; string fullPartNumber = stationType + "." + basePartNumber; string combinedPartNumber = stationType + "." + partNumber; //--- has "#xxx" string instrumentName = fullPartNumber + ATMLContext.ATML_INSTRUMENT_FILENAME_SUFFIX; //--------------------------------------------------------------------------------------------------------// //--- TODO: Need to adjust this process //--- Strip the #xxx off //--- Prefix it with the station name //--- Check if instrument is in database - if not create a placeholder //--- Get instrument uuid for reference //--- Using the original part number (ie with #xxx) make sure its associated with the test station //--- This will provide quantities of an instrument via #xxx //--------------------------------------------------------------------------------------------------------// //-----------------------------------------// //--- Look for an asset in the database ---// //-----------------------------------------// AssetIdentificationBean asset = DocumentManager.FindAsset(AssetTypePart, combinedPartNumber); if (asset != null) { //-----------------------------// //--- Grab the reference id ---// //-----------------------------// referenceId = asset.uuid.ToString(); } else { //--- Lookup Document by Instrument Id ---// Document document = DocumentManager.GetDocumentByName(instrumentName); if (document == null) { //--- We should only prompt if the base part number is missing ---// referenceId = PromptUserToAddInstrument(basePartNumber, stationType, referenceId); } else { referenceId = document.uuid; CreateAsset(referenceId, combinedPartNumber); } } //-------------------------------------------------------------------------------------------------------// //--- Let see if the test station has a reference to the instrument instance, if no we need to add it ---// //-------------------------------------------------------------------------------------------------------// if (!AtmlControllerFactory <TestStationDescription11> .Controller.HasInstrumentReference(testStation, partNumber)) { //InstrumentDescription instrument = InstrumentController.FindInstrument(partNumber); AtmlControllerFactory <TestStationDescription11> .Controller.AddInstrumentReference(testStation as TestStationDescription11, partNumber, referenceId); } } catch (Exception e) { LogManager.SourceError(ATMLReader.SOURCE, ErrorSavingInstrument, partNumber, e.Message); } return(referenceId); }