ningshuxia
2024-05-06 8f6d2b48f22b695574bd4a6c4ac91b1ac9f780b1
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
namespace IStation.Client
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
 
            this.FormClosed += (sender, e) =>
            {
                System.Diagnostics.Process.GetCurrentProcess().Kill();
            };
            this.cmbStation.SelectedIndex = 0;
        }
 
        int _stationIndex = 0;
        string _floder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data");
 
        private void cmbStation_SelectedIndexChanged(object sender, EventArgs e)
        {
            _stationIndex = cmbStation.SelectedIndex;
            if (_stationIndex == 0)
            {
                this.txtFlow.Text = "16406";
                this.txtHead.Text = "15.92";
                this.txtCurrentOpen.Text = "11,12,13,17";
            }
            else
            {
                this.txtFlow.Text = "39,460";
                this.txtHead.Text = "19.65";
                this.txtCurrentOpen.Text = "22,23,25,26";
            }
 
        }
 
        private void btnAnaCombine_Click(object sender, EventArgs e)
        {
            this.txtInfo.Text += "\r\nÕýÔÚ·ÖÎö±Ã×éºÏ";
            var ch1 = _floder + "\\" + "³ÂÐÐÒ»Êä.json";
            var ch1_json = File.ReadAllText(ch1);
            var ch1Pumps = JsonHelper.Json2Object<List<Model.Pump>>(ch1_json);
 
            var ch2 = _floder + "\\" + "³ÂÐжþÊä.json";
            var ch2_json = File.ReadAllText(ch2);
            var ch2Pumps = JsonHelper.Json2Object<List<Model.Pump>>(ch2_json);
 
            Task.Run(() =>
            {
                var helper = new Algorithm.SchedulingAnaHelper();
                helper.AnaCombine(ch1Pumps);
                this.Invoke(() =>
                {
                    this.txtInfo.Text += "\r\n·ÖÎö±Ã×éºÏÍê±Ï";
                });
            });
        }
 
        private void btnAnaCh1Combine_Click(object sender, EventArgs e)
        {
            var ch1 = _floder + "\\" + "³ÂÐÐÒ»Êä.json";
            var ch1_json = File.ReadAllText(ch1);
            var ch1Pumps = JsonHelper.Json2Object<List<Model.Pump>>(ch1_json);
            this.txtInfo.Text += "\r\nÕýÔÚ·ÖÎö1ÊäË®±Ã×éºÏ";
            Task.Run(() =>
            {
                var helper = new Algorithm.SchedulingAnaHelper();
                helper.AnaCombine(ch1Pumps);
                this.Invoke(() =>
                {
                    this.txtInfo.Text += "\r\n·ÖÎö1ÊäË®±Ã×éºÏÍê±Ï";
                });
            });
        }
 
        private void btnAnaCh2Combine_Click(object sender, EventArgs e)
        {
            var ch2 = _floder + "\\" + "³ÂÐжþÊä.json";
            var ch2_json = File.ReadAllText(ch2);
            var ch2Pumps = JsonHelper.Json2Object<List<Model.Pump>>(ch2_json);
 
            this.txtInfo.Text += "\r\nÕýÔÚ·ÖÎö2ÊäË®±Ã×éºÏ";
            Task.Run(() =>
            {
                var helper = new Algorithm.SchedulingAnaHelper();
                helper.AnaCombine(ch2Pumps);
                this.Invoke(() =>
                {
                    this.txtInfo.Text += "\r\n·ÖÎö2ÊäË®±Ã×éºÏÍê±Ï";
                });
            });
        }
 
        private void btnAnaChConclusion_Click(object sender, EventArgs e)
        {
            this.txtInfo.Text += "\r\nÕýÔÚ·ÖÎöÈ«²¿±Ã×éºÏ½áÂÛ";
            Task.Run(() =>
            {
                var helper = new Algorithm.SchedulingAnaHelper();
                helper.AnaConclusion();
                this.Invoke(() =>
                {
                    this.txtInfo.Text += "\r\nÈ«²¿±Ã×éºÏ·ÖÎöÍê±Ï";
                });
            });
        }
 
        private void btnAna_Click(object sender, EventArgs e)
        {
            this.txtInfo.Text = string.Empty;
            if (!double.TryParse(this.txtFlow.Text, out double targetFlow))
            {
                MessageBox.Show("ÇëÊäÈëÁ÷Á¿!");
                return;
            }
            if (!double.TryParse(this.txtHead.Text, out double targetHead))
            {
                MessageBox.Show("ÇëÊäÈëѹÁ¦!");
                return;
            }
            List<int> current_open_pump_list = new List<int>();
            List<int> must_open_pump_list = new List<int>();
            List<int> must_not_open_pump_list = new List<int>();
 
            var current_open_pump_list_txt = this.txtCurrentOpen.Text.Trim();
            if (!string.IsNullOrEmpty(current_open_pump_list_txt))
            {
                current_open_pump_list = IntListHelper.ToList(current_open_pump_list_txt);
                if (current_open_pump_list == null || current_open_pump_list.Count < 1)
                {
                    MessageBox.Show("ÇëÊäÈëÓÐЧ±Ã×éºÏ!\r\n','ºÅ¼ä¸ô!");
                    return;
                }
            }
 
            var must_open_pump_list_txt = this.txtMustOpen.Text.Trim();
            if (!string.IsNullOrEmpty(must_open_pump_list_txt))
            {
                must_open_pump_list = IntListHelper.ToList(must_open_pump_list_txt);
                if (must_open_pump_list == null || must_open_pump_list.Count < 1)
                {
                    MessageBox.Show("ÇëÊäÈëÓÐЧ±Ã×éºÏ!\r\n','ºÅ¼ä¸ô!");
                    return;
                }
            }
 
            var must_not_open_pump_list_txt = this.txtMustNotOpen.Text.Trim();
            if (!string.IsNullOrEmpty(must_not_open_pump_list_txt))
            {
                must_not_open_pump_list = IntListHelper.ToList(must_not_open_pump_list_txt);
                if (must_not_open_pump_list == null || must_not_open_pump_list.Count < 1)
                {
                    MessageBox.Show("ÇëÊäÈëÓÐЧ±Ã×éºÏ!\r\n','ºÅ¼ä¸ô!");
                    return;
                }
            }
 
            List<Model.Pump> pumps;
            List<int> flags_part1, flags_part2;
            if (_stationIndex == 0)
            {
                var filePath = _floder + "\\" + "³ÂÐÐÒ»Êä.json";
                var jsonInfo = File.ReadAllText(filePath);
                pumps = JsonHelper.Json2Object<List<Model.Pump>>(jsonInfo);
 
                flags_part1 = new List<int>() { 11, 12, 13, 14, 16, 17, 18 };
                flags_part2 = new List<int>() { 15 };
            }
            else
            {
                var filePath = _floder + "\\" + "³ÂÐжþÊä.json";
                var jsonInfo = File.ReadAllText(filePath);
                pumps = JsonHelper.Json2Object<List<Model.Pump>>(jsonInfo);
 
                flags_part1 = new List<int>() { 22, 23, 24, 25, 26 };
                flags_part2 = new List<int>() { 21, 27 };
            }
 
            var helper = new Algorithm.SchedulingHelper();
            var info = helper.Ana(pumps, flags_part1, flags_part2, targetFlow, targetHead, current_open_pump_list, must_open_pump_list, must_not_open_pump_list);
 
            this.txtInfo.Text = info;
        }
 
    }
}