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
|
{
|
private bool isCreateTableFinish = false;//是否创建表格完毕
|
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 = { "状态", "任务名称", "托盘号", "产品编号", "数量", "创建时间" };
|
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刷新
|
{
|
KyeCodeForF5();
|
}
|
}
|
|
private void KyeCodeForF5()
|
{
|
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()
|
{
|
double width_0 = 0.1;//状态
|
double width_1 = 0.22;//任务名称
|
double width_2 = 0.16;//托盘号
|
double width_3 = 0.2;//产品编号
|
double width_4 = 0.08;//数量
|
double width_5 = 0.25;//日期
|
|
for (int i = 0; i < 6; i++)
|
{
|
#region 生成表头
|
Label head = new Label();
|
head.Text = columnHead[i];
|
#region 定义宽度
|
switch (i)
|
{
|
case 0:
|
head.Width = Convert.ToInt32(this.Width * width_0);
|
head.Location = new Point(10, 70);
|
break;
|
case 1:
|
head.Width = Convert.ToInt32(this.Width * width_1);
|
|
head.Location = new Point(10 + Convert.ToInt32(this.Width * width_0), 70);
|
break;
|
case 2:
|
head.Width = Convert.ToInt32(this.Width * width_2);
|
head.Location = new Point(10 + Convert.ToInt32(this.Width * (width_0 + width_1)), 70);
|
break;
|
case 3:
|
head.Width = Convert.ToInt32(this.Width * width_3);
|
head.Location = new Point(10 + Convert.ToInt32(this.Width * (width_0 + width_1 + width_2)), 70);
|
break;
|
case 4:
|
head.Width = Convert.ToInt32(this.Width * width_4);
|
head.Location = new Point(10 + Convert.ToInt32(this.Width * (width_0 + width_1 + width_2 + width_3)), 70);
|
break;
|
case 5:
|
head.Width = Convert.ToInt32(this.Width * width_5);
|
head.Location = new Point(Convert.ToInt32(this.Width * (width_0 + width_1 + width_2 + width_3 + width_4)), 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 < 6; i++)
|
{
|
Label tBody = new Label();
|
tBody.Text = "";
|
#region 定义宽度
|
switch (i)
|
{
|
case 0://状态
|
tBody.Width = Convert.ToInt32(this.Width * width_0);
|
tBody.Location = new Point(10, 150 + j * 60);
|
break;
|
case 1://任务名称
|
tBody.Width = Convert.ToInt32(this.Width * width_1);
|
|
tBody.Location = new Point(10 + Convert.ToInt32(this.Width * width_0), 150 + j * 60);
|
break;
|
case 2://托盘号
|
tBody.Width = Convert.ToInt32(this.Width * width_2);
|
tBody.Location = new Point(10 + Convert.ToInt32(this.Width * (width_0 + width_1)), 150 + j * 60);
|
break;
|
case 3://产品编号
|
tBody.Width = Convert.ToInt32(this.Width * width_3);
|
tBody.Location = new Point(10 + Convert.ToInt32(this.Width * (width_0 + width_1 + width_2)), 150 + j * 60);
|
break;
|
case 4://数量
|
tBody.Width = Convert.ToInt32(this.Width * width_4);
|
tBody.Location = new Point(10 + Convert.ToInt32(this.Width * (width_0 + width_1 + width_2 + width_3)), 150 + j * 60);
|
break;
|
case 5://创建时间
|
tBody.Width = Convert.ToInt32(this.Width * width_5);
|
tBody.Location = new Point(Convert.ToInt32(this.Width * (width_0 + width_1 + width_2 + width_3 + width_4)), 150 + j * 60);
|
break;
|
default:
|
break;
|
}
|
#endregion
|
tBody.Height = 60;
|
tBody.Font = new System.Drawing.Font("宋体", 35, FontStyle.Bold);
|
tBody.TextAlign = ContentAlignment.MiddleCenter;
|
tBody.ForeColor = chang == true ? Color.FromArgb(47, 187, 80) : Color.FromArgb(245, 66, 150);
|
|
panelTable.Controls.Add(tBody);
|
labels.Add(tBody);
|
|
}
|
#endregion
|
|
}
|
isCreateTableFinish = true;
|
}
|
|
|
/// <summary>
|
/// 设置宽度
|
/// </summary>
|
/// <param name="i"></param>
|
/// <param name="head"></param>
|
private void SetWidth(int i, Label head)
|
{
|
decimal _coefficient = 0;
|
switch (i)
|
{
|
case 0:
|
_coefficient = 0.1M;
|
break;
|
case 1:
|
_coefficient = 0.2M;
|
break;
|
case 2:
|
_coefficient = 0.2M;
|
break;
|
case 3:
|
_coefficient = 0.2M;
|
break;
|
case 4:
|
_coefficient = 0.1M;
|
break;
|
case 5:
|
_coefficient = 0.2M;
|
break;
|
default:
|
break;
|
}
|
head.Width = Convert.ToInt32(this.Width * _coefficient);
|
}
|
|
/// <summary>刷新表格数据
|
///
|
/// </summary>
|
public void tableBody()
|
{
|
|
//if (labels.Count == 60)
|
if (isCreateTableFinish && labels.Count > 0)
|
{
|
|
bool chang = true;
|
int num = 0;
|
for (int j = 0; j < 10; j++)
|
{
|
#region 刷新表格数据
|
chang = !chang;
|
|
for (int i = 0; i < 6; 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].containerCode;
|
// labels[num].Text = "TP-L-0054";//模拟
|
break;
|
case 3:
|
labels[num].Text = taskList[j].materialCode;
|
break;
|
case 4:
|
labels[num].Text = taskList[j].quantity.ToString();
|
break;
|
case 5:
|
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");
|
}
|
|
private void Form1_SizeChanged(object sender, EventArgs e)
|
{
|
}
|
}
|
}
|