C3204
2025-12-18 d85cbf0ccd61d95b96695756e0c90db8b7679545
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using LB_VisionProcesses;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace LB_SmartVision.Forms.Pages.SettingPage
{
    public partial class CsvPage : UserControl
    {
        public CsvPage()
        {
            InitializeComponent();
 
            btn_Save.Click += (sender, e) =>
            {
                if (!VisionForm.SaveAllCsv())
                    MessageBox.Show("!!!保存失败!!!", "异常");
                else
                    MessageBox.Show("保存成功!");
            };
 
            btnDel.Click += (sender, e) =>
            {
                foreach (var control in pnlLayout.Controls)
                {
                    if (control is CsvSettingControl csvSettingControl
                        && csvSettingControl.IsSelected)
                    {
                        var item = GlobalVar.dicLayout.FirstOrDefault(x => x.Value.Title == csvSettingControl.Title);
                        GlobalVar.dicLayout.TryRemove(item.Key, out _);
                    }
                }
                this.Invalidate();
            };
        }
 
        private void CsvPage_Paint(object sender, PaintEventArgs e)
        {
            //this.pnlLayout.Controls.Clear();
 
            //var sortedKeys = GlobalVar.dicCsvSetting.Keys
            //    .OrderBy(k => k, new NaturalStringComparer())
            //    .ToList();
 
            //int index = 0;
            //foreach (var key in sortedKeys)
            //{
            //    string ProcessesName = key;
 
            //    CsvSettingControl control = new CsvSettingControl(GlobalVar.dicCsvSetting[ProcessesName]);
            //    control.Size = new Size(this.pnlLayout.Size.Width, control.Size.Height);
            //    control.Location = new Point(0, control.Size.Height * index);
            //    this.pnlLayout.Controls.Add(control);
            //    index++;
            //}
        }
 
        private void CsvPage_SizeChanged(object sender, EventArgs e) => CsvPage_VisibleChanged(sender, e);
 
        private void CsvPage_VisibleChanged(object sender, EventArgs e)
        {
            this.pnlLayout.Controls.Clear();
 
            var sortedKeys = GlobalVar.dicCsvSetting.Keys
                .OrderBy(k => k, new NaturalStringComparer())
                .ToList();
 
            int index = 0;
            foreach (var key in sortedKeys)
            {
                string ProcessesName = key;
 
                CsvSettingControl control = new CsvSettingControl(GlobalVar.dicCsvSetting[ProcessesName]);
                control.Size = new Size(this.pnlLayout.Size.Width, control.Size.Height);
                control.Location = new Point(0, control.Size.Height * index);
                this.pnlLayout.Controls.Add(control);
                index++;
            }
        }
 
        private void btnAdd_Click(object sender, EventArgs e)
        {
            GlobalVar.dicCsvSetting.TryAdd($"{GlobalVar.dicCsvSetting.Count}", new CsvSetting());
 
            CsvPage_VisibleChanged(sender, e);
        }
    }
 
    [Serializable]
    public class CsvSetting
    {
        public string ProcessName { get; set; } = string.Empty;
 
        public List<string> Others { get; set; } = new List<string>();
 
        public CsvSetting() { }
    }
}