/// <summary> /// 儲存程式編輯 /// </summary> /// <param name="macroName">程式編輯名稱</param> /// <param name="macroGuid">程式編輯 ID</param> /// <param name="shapeModelFilepath">程式編輯模型檔案路徑</param> /// <param name="note">程式編輯描述</param> /// <param name="trainingImage">程式編輯訓練影像二元檔</param> /// <param name="exportUnit">輸出單位</param> /// <param name="matchingParamData">模型參數二元檔</param> /// <param name="measureBinaryData">測量資料二元檔</param> /// <param name="measureAssistantParamData">測量參數二元檔</param> /// <param name="upperLight">上光源</param> /// <param name="bottomLight">下光源</param> /// <param name="findedShapeViewModel">Matching 模型資訊</param> /// <param name="loginUser">登入者</param> /// <param name="trainingImageFilepath">程式編輯訓練影像實體路徑</param> /// <param name="snapshot">程式編輯縮圖二元檔</param> /// <param name="objectXLength">物件大小 X</param> /// <param name="objectYLength">物件大小 Y</param> /// <param name="technicalDrawingModel">工程圖資訊</param> /// <returns></returns> public static bool SaveMacroPlan(string macroName, string macroGuid, string shapeModelFilepath, string note, Binary trainingImage , string exportUnit, Binary matchingParamData, Binary measureBinaryData, Binary measureAssistantParamData , LightChannel upperLight, LightChannel bottomLight , ShapeViewModel findedShapeViewModel, string loginUser , string trainingImageFilepath , Binary snapshot , double objectXLength, double objectYLength , XDocument technicalDrawingModel) { bool success = true; try { MacroPlan plan = _dc.MacroPlan.SingleOrDefault(p => p.MacroGuid == macroGuid); var isUpdate = (plan != null); if (!isUpdate) { plan = new MacroPlan() { CreateBy = loginUser, CreateOn = DateTime.Now, MacroGuid = macroGuid }; } plan.MacroName = macroName; plan.ShapeModelFilepath = shapeModelFilepath; plan.Note = note; plan.TrainingImage = trainingImage; plan.TrainingImageFilepath = trainingImageFilepath; plan.ExportUnit = exportUnit; plan.MatchingParamBinaryData = matchingParamData; plan.MeasureBinaryData = measureBinaryData; plan.UpperLightSwitch = (upperLight.OnOff == LightControl.LightSwitch.On); plan.UpperLightValue = upperLight.Intensity.ToString("d3"); plan.BottomLightSiwtch = (bottomLight.OnOff == LightControl.LightSwitch.On); plan.BottomLigthValue = bottomLight.Intensity.ToString("d3"); plan.ModifiedOn = DateTime.Now; plan.ModifiedBy = loginUser; plan.MeasureAssistantBinaryData = measureAssistantParamData; plan.ModelRow = findedShapeViewModel.Row; plan.ModelCol = findedShapeViewModel.Col; plan.ModelAngle = findedShapeViewModel.Angle; plan.IsDeleted = false; plan.Snapshot = snapshot; plan.ObjectXLength = objectXLength; plan.ObjectYLength = objectYLength; plan.TechnicalDrawingModel = XElement.Load(technicalDrawingModel.CreateReader()); if (!isUpdate) { _dc.MacroPlan.InsertOnSubmit(plan); } _dc.SubmitChanges(); } catch (Exception ex) { success = false; Hanbo.Log.LogManager.Error(ex.Message); } return success; }
/// <summary> /// 匯入巨集編程 /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool ImportMacroPlan(ExportMacroPlanViewModel model) { var success = false; try { MacroPlan plan = new MacroPlan() { }; plan.MacroGuid = Guid.NewGuid().ToString(); plan.MacroName = model.MacroName; plan.MacroGuid = model.MacroGuid; plan.Note = model.Note; plan.TrainingImage = model.TrainingImageBinary; plan.MatchingParamBinaryData = model.MatchingParamBinaryData; plan.MeasureBinaryData = model.MeasureBinaryData; plan.MeasureAssistantBinaryData = model.MeasureAssistantBinaryData; plan.ModelRow = model.ModelRow; plan.ModelCol = model.ModelCol; plan.ModelAngle = model.ModelAngle; plan.ExportUnit = model.ExportUnit; plan.UpperLightValue = model.UpperLightValue; plan.BottomLigthValue = model.BottomLigthValue; plan.UpperLightSwitch = model.UpperLightSwitch; plan.BottomLightSiwtch = model.BottomLightSiwtch; plan.CreateBy = model.CreateBy; plan.ModifiedBy = model.ModifiedBy; plan.CreateOn = model.CreateOn; plan.ModifiedOn = model.ModifiedOn; plan.IsDeleted = model.IsDeleted; var shapeModelFilepath = ConfigurationHelper.GetShapeModelFilePath(); var trainingImageFilepath = ConfigurationHelper.GetTrainingImageFilepath(); File.WriteAllBytes(shapeModelFilepath, model.ShapeModelBinary.ToArray()); File.WriteAllBytes(trainingImageFilepath, model.TrainingImageBinary.ToArray()); plan.ShapeModelFilepath = shapeModelFilepath; plan.TrainingImageFilepath = trainingImageFilepath; _dc.MacroPlan.InsertOnSubmit(plan); _dc.SubmitChanges(); success = true; } catch (Exception ex) { Hanbo.Log.LogManager.Error(ex); } return success; }
/// <summary> /// 匯出巨集編程 /// </summary> /// <param name="plan">巨集編程</param> /// <returns></returns> public static ExportMacroPlanViewModel ExportMacroPlan(MacroPlan plan) { ExportMacroPlanViewModel model = null; if (plan != null) { try { model = new ExportMacroPlanViewModel() { MacroName = plan.MacroName, MacroGuid = plan.MacroGuid, Note = plan.Note, ShapeModelBinary = new Binary(File.ReadAllBytes(plan.ShapeModelFilepath)), TrainingImageBinary = new Binary(File.ReadAllBytes(plan.TrainingImageFilepath)), MatchingParamBinaryData = plan.MatchingParamBinaryData, MeasureBinaryData = plan.MeasureBinaryData, MeasureAssistantBinaryData = plan.MeasureAssistantBinaryData, ModelRow = plan.ModelRow, ModelCol = plan.ModelCol, ModelAngle = plan.ModelAngle, ExportUnit = plan.ExportUnit, UpperLightValue = plan.UpperLightValue, BottomLigthValue = plan.BottomLigthValue, UpperLightSwitch = plan.UpperLightSwitch, BottomLightSiwtch = plan.BottomLightSiwtch, CreateBy = plan.CreateBy, ModifiedBy = plan.ModifiedBy, CreateOn = plan.CreateOn, ModifiedOn = plan.ModifiedOn, IsDeleted = plan.IsDeleted, }; } catch (Exception ex) { Hanbo.Log.LogManager.Error(ex); } } return model; }
partial void DeleteMacroPlan(MacroPlan instance);
partial void UpdateMacroPlan(MacroPlan instance);
partial void InsertMacroPlan(MacroPlan instance);