コード例 #1
0
        /// <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;
        }
コード例 #2
0
        /// <summary>
        /// 更新巨集編程
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool UpdateMacroPlan(ExportMacroPlanViewModel model)
        {
            bool success = false;
            try
            {
                var plan = _dc.MacroPlan.SingleOrDefault(p => p.MacroGuid == model.MacroGuid);

                var shapeModelFilepath = plan.ShapeModelFilepath;
                var trainingImageFilepath = plan.TrainingImageFilepath;

                File.WriteAllBytes(shapeModelFilepath, model.ShapeModelBinary.ToArray());
                File.WriteAllBytes(trainingImageFilepath, model.TrainingImageBinary.ToArray());

                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.ModifiedBy = model.ModifiedBy;
                plan.ModifiedOn = DateTime.Now;
                plan.IsDeleted = model.IsDeleted;
                _dc.SubmitChanges();
                success = true;
            }
            catch (Exception ex)
            {
                Hanbo.Log.LogManager.Error(ex);
            }
            return success;
        }
コード例 #3
0
 /// <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;
 }