kingno
5 天以前 6caff8e3b06535a9652a791454135cf0e6ac110e
src/Bro.M141.Process/M141Config.cs
@@ -13,11 +13,18 @@
using System.Drawing.Printing;
using System.Reflection;
using System.Windows.Forms.Design;
using static Bro.Common.Helper.EnumHelper;
namespace Bro.M141.Process
{
    public class M141Config : ProcessConfigBase
    {
        [Category("打印机配置")]
        [Description("打印机配置集合")]
        [DisplayName("打印机配置集合")]
@@ -31,6 +38,7 @@
        [Description("字体大小")]
        [DisplayName("字体大小")]
        public int FontSize_p { get; set; } = 15;
        [Category("产品显示界面配置")]
        [Description("每行列数")]
@@ -65,8 +73,39 @@
        [Category("检测异常指示")]
        [Description("选择某个Spec,其表示检测过程中异常")]
        [DisplayName("异常指示标准")]
        [TypeConverter(typeof(SpecCodeSelectorConverter))]
        [TypeConverter(typeof(SpecCodeSelectorConverter))]
        public string CheckErrorSpecCode { get; set; } = "";
        [Category("特定缺陷配置")]
        [Description("S3和S5共同判断缺陷")]
        [DisplayName("缺陷名称")]
        [TypeConverter(typeof(GlobalDefectNameConverter))]
        public string defectname { get; set; } = "";
        private class GlobalDefectNameConverter : StringConverter
        {
            public override bool GetStandardValuesExclusive(ITypeDescriptorContext? context)
            {
                return false;
            }
            public override bool GetStandardValuesSupported(ITypeDescriptorContext? context)
            {
                return true;
            }
            public override StandardValuesCollection? GetStandardValues(ITypeDescriptorContext? context)
            {
                using (var scope = GlobalVar.Container.BeginLifetimeScope())
                {
                    var config = scope.Resolve<IProcessConfig>();
                    return new StandardValuesCollection((config as IDefectSwitcher).DefectSwitchCollection.Select(u => u.DefectName).ToList());
                }
            }
        }
        [Category("位置度设置")]
@@ -237,16 +276,13 @@
        [Editor(typeof(ComplexCollectionEditor<PLCAlarmDetails>), typeof(UITypeEditor))]
        public List<PLCAlarmDetails> AlarmDetails { get; set; } = new List<PLCAlarmDetails>();
        public string GetDisplayText()
        {
            return plcname + (isused ? "启用" : "禁用");
        }
    }
    public class PLCAlarmDetails : IComplexDisplay
    public class PLCAlarmDetails : IComplexDisplay, IImportFromFileInEditor
    {
        [Category("配置")]
        [DisplayName("首地址")]
@@ -271,6 +307,74 @@
        {
            return alarmname;
        }
        public IImportFromFileInEditor GetImportObject(string data, out string msg)
        {
            msg = "";
            PLCAlarmDetails ret = new PLCAlarmDetails();
            try
            {
                var temchar = data.Split(',');
                ret.alarmname = temchar[0];
                ret.address =Convert.ToInt32(temchar[1]);
                ret.address2 = Convert.ToInt32(temchar[2]);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ret;
        }
        public bool ICSVOutput(object o)
        {
            try
            {
                if (o is List<PLCAlarmDetails> Pl)
                {
                    SaveFileDialog saveFileDialog = new SaveFileDialog();
                    saveFileDialog.Filter = "CSV files (*.csv)|*.csv"; // 设置文件过滤器,只显示CSV文件
                    saveFileDialog.Title = "Save CSV File"; // 设置对话框标题
                    saveFileDialog.FileName = "PLCAlarms"; // 默认文件名
                    saveFileDialog.DefaultExt = "csv"; // 默认文件扩展名
                    string filePath = "";
                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        filePath = saveFileDialog.FileName; // 获取用户选择的文件路径
                    }
                    else
                    {
                        return false;
                    }
                    using (StreamWriter writer = new StreamWriter(filePath))
                    {
                        // 写入标题行
                        writer.WriteLine("报警名称,首地址,子地址");
                        // 写入数据行
                        foreach (var row in Pl)
                        {
                            writer.WriteLine($"{row.alarmname},{row.address},{row.address2}");
                        }
                    }
                }
            }
            catch
            {
            }
            return true;
        }
    }
@@ -298,6 +402,11 @@
        [DisplayName("图像索引")]
        [Description("应对单次检测项需要多次拍照时,记录图片的索引号,从0开始")]
        public int ImageIndex { get; set; } = 0;
        [Category("启用配置")]
        [DisplayName("固定检测项")]
        [Description("true:该检测项是固定检测项目,必须执行 false:该检测是可变检测项目,流程中决定是否检测,默认不检测")]
        public bool IsFixed { get; set; } = true;
        [Category("取像设置")]
        [DisplayName("相机选择")]
@@ -357,7 +466,10 @@
        [DisplayName("OK图片保存开关")]
        public bool OKImageSwitch { get; set; } = false;
        [Category("图片保存设置")]
        [Description("该站检测图片保存时,保存的图片顺序后缀")]
        [DisplayName("图片保存顺序后缀")]
        public string ImageSaveSeq { get; set; } = "1";
        public string GetDisplayText()
        {
@@ -842,6 +954,21 @@
    }
    [Device("OfflineDemo", "离线测试", DeviceAttributeType.OperationConfig)]
    public class OfflineDemoOperationConfig : OperationConfigBase
    {
        [Category("图片目录")]
        [Description("图片目录")]
        [DisplayName("图片目录")]
        [Editor(typeof(FoldDialogEditor), typeof(UITypeEditor))]
        public string ImageFolder { get; set; }
        [Category("启动配置")]
        [Description("true:启动离线测试 false:停止离线测试")]
        [DisplayName("测试开关")]
        public bool IsStart { get; set; } = true;
    }
    public class RealTimeAdjustDataDetail : IComplexDisplay
    {
        [Category("点位设置")]