222
schangxiang@126.com
2025-09-02 ac4209926b9d911988be67a8957d5a7a53ec2ce8
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
using System;
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;
using sunui.wcs;
using System.Threading;
using System.Configuration;
 
namespace sunui
{
 
    public partial class Form1 : Form
    {
        int areaNum = 1;
        int lastWidth = 0;
        bool zoom = true;//全屏切换标志
        public static wcs.IyunneiWcfClient wcs = new wcs.IyunneiWcfClient();
        List<sunui.wcs.task> taskList = null;
        List<Label> labels = new List<Label>();
        string[] columnHead = { "状态", "任务名称", "产品编号", "数量", "创建时间" };
        string[] taskStatus = { "", "新建", "未下发", "已下发", "待完成", "完成" };
        public Form1()
        {
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;
 
        }
        /// <summary>全屏控制
        /// 全屏控制
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F11)
            {
                if (zoom)
                {
                    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
 
                    this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
                }
                else
                {
                    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
                    this.WindowState = FormWindowState.Normal;
                }
                zoom = !zoom;
            }
            if (e.KeyCode == Keys.F5)//窗口尺寸发生变化要按F5刷新
            {
                labels.Clear();
                panelTable.Controls.Clear();
                tableHead();
                if (taskList != null)
                {
                    tableBody();
                }
            }
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {//Panel1.BackColor = Color.FromArgb(0, Panel1.BackColor); labelWeek
 
            try
            {
                areaNum = Convert.ToInt32(ConfigurationManager.AppSettings["arae"].ToString());
                this.lableTime.BackColor = Color.FromArgb(0, this.lableTime.BackColor);
                this.labelWeek.BackColor = Color.FromArgb(0, this.labelWeek.BackColor);
                this.panelHead.BackColor = Color.FromArgb(0, this.panelHead.BackColor);
                this.lableTitle.BackColor = Color.FromArgb(0, this.lableTitle.BackColor);//panelTable
                this.panelTable.BackColor = Color.FromArgb(0, this.panelTable.BackColor);//
                lastWidth = this.Width;
                var res = wcs.TaskDisplay(areaNum);
                if (res.status == 200)
                {
                    taskList = res.date.ToList();
 
                    tableBody();
                }
                else
                {
 
                    taskList = null;
                }
                tableHead();
                lableTime.Text = DateTime.Now.ToLocalTime().ToString();
                labelWeek.Text = DateTime.Now.ToString("dddd");
            }
            catch (Exception )
            {
                MessageBox.Show("wcs服务没开,请检查后在开启");
                Environment.Exit(0);//退出本进程所有线程
            }
          
        }
 
        public void tableHead()
        {
            for (int i = 0; i < 5; i++)
            {
                #region 生成表头
                Label head = new Label();
                head.Text = columnHead[i];
                #region 定义宽度
                switch (i)
                {
                    case 0:
                        head.Width = Convert.ToInt32(this.Width * 0.15);
                        head.Location = new Point(10, 70);
                        break;
                    case 1:
                        head.Width = Convert.ToInt32(this.Width * 0.25);
 
                        head.Location = new Point(10 + Convert.ToInt32(this.Width * 0.15), 70);
                        break;
                    case 2:
                        head.Width = Convert.ToInt32(this.Width * 0.2);
                        head.Location = new Point(10 + Convert.ToInt32(this.Width * 0.4), 70);
                        break;
                    case 3:
                        head.Width = Convert.ToInt32(this.Width * 0.15);
                        head.Location = new Point(10 + Convert.ToInt32(this.Width * 0.6), 70);
                        break;
                    case 4:
                        head.Width = Convert.ToInt32(this.Width * 0.25);
                        head.Location = new Point(Convert.ToInt32(this.Width * 0.75), 70);
                        break;
                    default:
                        break;
                }
                #endregion
 
                head.Height = 50;
                head.Font = new System.Drawing.Font("宋体", 35, FontStyle.Bold);
                head.TextAlign = ContentAlignment.MiddleCenter;
                head.ForeColor = Color.FromArgb(255, 221, 17);
 
                panelTable.Controls.Add(head);
 
                #endregion
 
            }
 
            bool chang = true;
            for (int j = 0; j < 10; j++)
            {
                #region 创建表格控件
                chang = !chang;
                for (int i = 0; i < 5; i++)
                {
                    Label head = new Label();
                    head.Text = "";
                    #region 定义宽度
                    switch (i)
                    {
                        case 0:
                            head.Width = Convert.ToInt32(this.Width * 0.15);
                            head.Location = new Point(10, 150 + j * 60);
                            break;
                        case 1:
                            head.Width = Convert.ToInt32(this.Width * 0.25);
 
                            head.Location = new Point(10 + Convert.ToInt32(this.Width * 0.15), 150 + j * 60);
                            break;
                        case 2:
                            head.Width = Convert.ToInt32(this.Width * 0.2);
                            head.Location = new Point(10 + Convert.ToInt32(this.Width * 0.4), 150 + j * 60);
                            break;
                        case 3:
                            head.Width = Convert.ToInt32(this.Width * 0.15);
                            head.Location = new Point(10 + Convert.ToInt32(this.Width * 0.6), 150 + j * 60);
                            break;
                        case 4:
                            head.Width = Convert.ToInt32(this.Width * 0.25);
                            head.Location = new Point(Convert.ToInt32(this.Width * 0.75), 150 + j * 60);
                            break;
                        default:
                            break;
                    }
                    #endregion
                    head.Height = 60;
                    head.Font = new System.Drawing.Font("宋体", 35, FontStyle.Bold);
                    head.TextAlign = ContentAlignment.MiddleCenter;
                    head.ForeColor = chang == true ? Color.FromArgb(47, 187, 80) : Color.FromArgb(245, 66, 150);
 
                    panelTable.Controls.Add(head);
                    labels.Add(head);
 
                }
                #endregion
 
            }
 
        }
 
        /// <summary>刷新表格数据
        /// 
        /// </summary>
        public void tableBody()
        {
 
            if (labels.Count == 50)
            {
 
                bool chang = true;
                int num = 0;
                for (int j = 0; j < 10; j++)
                {
                    #region 刷新表格数据
                    chang = !chang;
 
                    for (int i = 0; i < 5; i++)
                    {
                        if (taskList != null)
                        {
                            if (j < taskList.Count)
                            {
                                switch (i)
                                {
                                    #region 获取名称
                                    case 0:
                                        labels[num].Text = (int)taskList[j].taskStatus < 5 ? "执行中" : "完成";
 
                                        break;
                                    case 1:
                                        labels[num].Text = taskList[j].taskName;
 
                                        break;
                                    case 2:
                                        labels[num].Text = taskList[j].materialCode;
                                        break;
                                    case 3:
                                        labels[num].Text = taskList[j].quantity.ToString();
                                        break;
                                    case 4:
                                        labels[num].Text = ((DateTime)taskList[j].createTime).ToString("dd日HH:mm:ss");
                                        break;
                                    default:
                                        break;
                                    #endregion
 
                                }
                            }
                            else
                            {
                                labels[num].Text = "";
                            }
 
                        }
                        else
                        {
                            labels[num].Text = "";
                        }
                        num++;
                    }
                }
                    #endregion
 
            }
 
 
        }
 
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Environment.Exit(0);//退出本进程所有线程
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                var res = wcs.TaskDisplay(areaNum);
                if (res.status == 200)
                {
                    taskList = res.date.ToList();
                    tableBody();
                }
                else
                {
                    taskList = null;
                }
            }
            catch (Exception)
            {
                taskList = null;
                tableBody();
            }
          
        }
        /// <summary>更新时间
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer2_Tick(object sender, EventArgs e)
        {
            lableTime.Text = DateTime.Now.ToLocalTime().ToString();
            labelWeek.Text = DateTime.Now.ToString("dddd");
        }
    }
}