using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using WMS.Model;
using WMS.Untils;
using System.Linq;
using WMS.yunneiWCS;
namespace WMS.UI.SynthesizeQuery
{
public partial class FrmStore : Form
{
private yunneiWCS.IyunneiWcfClient clent = new yunneiWCS.IyunneiWcfClient();
private string one_emptyStr = " ";
///
/// 每排的列数
///
private readonly int _column = 38;
///
/// 每排的层数
///
private readonly int _layer = 6;
private FrmStore fatherFrmStore = null;
private bool isFullSrceen = false;//是否全屏
private bool isHasOpenFullSrceen = false;//是否已经打开了全屏
private Thread t = null;
private Thread t_tips = null;
AutoSizeFormClass asc = new AutoSizeFormClass();
public static Dictionary ColorDic = new Dictionary() {
{"LOCK",Color.Red},
{"FULL",Color.DeepSkyBlue},
{"EMPTY",Color.Lime},
{"NODIE",Color.Orange},
{"STATYMONTHS",Color.Magenta}
};
///
/// 目前所有库存1信息
///
List currentAll_Stored_cache = null;
///
/// 系统配置的呆滞库位时长
///
static string BasicDataSetForStayMonths = "";
///
/// 所有库存信息
///
List Stored_cache = null;
///
/// 空托盘库位
///
List StoredplaceInfo = null;
///
/// 呆滞库位
///
List Store_StatyMonths = null;
///
/// 空库位信息
///
private List emptyplaceInfo;
///
/// 锁定库位信息
///
private List lockedplace;
private delegate void BindRack1Delegate(); // 创建委托和委托对象
public FrmStore(bool _isFullSrceen, FrmStore _this)
{
InitializeComponent();
WMSFrmMain.isCurrentShowFrmStore = true;
fatherFrmStore = _this;
isFullSrceen = _isFullSrceen;
CheckForIllegalCrossThreadCalls = false;
this.KeyPreview = true;//让界面相应按钮事件
}
public FrmStore()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
this.KeyPreview = true;//让界面相应按钮事件
}
private void FrmStore_Load(object sender, EventArgs e)
{
//如果是全屏状态,并且判断是有两个屏幕,就默认显示到第二个屏幕上
if (isFullSrceen)
{
WMSCommon.ShowScreen2(this);
this.WindowState = FormWindowState.Maximized;
}
btnReload_Click(null, null);
t = new Thread(SetValue);
t.Start();
if (isFullSrceen)
{
}
asc.controllInitializeSize(this);
this.Dock = DockStyle.Fill;
}
///
/// 控件赋值
///
///
private void SetValue()
{
while (true)
{
if (WMSFrmMain.isCurrentShowFrmStore)
{
RefreshAll();
}
Thread.Sleep(2000);//2秒刷新一次
}
}
///
/// 库位各种状态下的库位数量显示
///
private void RefreshAll()
{
GetAllStore();
//List storeList = clent.findAllProductStock().ToList();
List storeList = currentAll_Stored_cache;
//整体去掉10001库位
//storeList = storeList.Where(x => x.positionName != 10001).ToList();
//获取空库位
emptyplaceInfo = storeList.Where(x => x.isfree != true).Select(x => x.positionName).ToList();
//获取有货库位
StoredplaceInfo = storeList.Where(x => !string.IsNullOrEmpty(x.materialCode)).ToList();
//获取有货物的货位
var existDiePlaces = StoredplaceInfo.Where(x =>
!string.IsNullOrEmpty(x.materialCode)
&& x.materialCode != "GT-KTP"
&& x.materialCode != "GG-KTP"
).ToList();
//给有货一栏统计当前有货的个数
lb_hasItem.Text = existDiePlaces.Select(x => x.positionName).Distinct().Count().ToString();
//获取呆滞库位 [EditBy shaocx,2022-04-17]
int statyMonths = 0;
Store_StatyMonths = new List();
if (existDiePlaces != null && existDiePlaces.Count > 0)
{
var queryTime = DateTime.Now.AddMonths(-Convert.ToInt32(BasicDataSetForStayMonths));
Store_StatyMonths = existDiePlaces.Where(x => x.createTime <= queryTime).ToList();
}
statyMonths = Store_StatyMonths.Select(x => x.positionName).Distinct().Count();
this.lbl_StatyMonth.Text = statyMonths.ToString();
////获取空托盘所在库位
var PlaceOfEmptyContainer = StoredplaceInfo.Where(x =>
!string.IsNullOrEmpty(x.materialCode) && x.materialCode == "GT-KTP"
&& x.materialCode == "GG-KTP"
).ToList();
////给空托盘统计个数
lb_EmptyContainer.Text = PlaceOfEmptyContainer.Count.ToString();
//获取被锁定库位
lockedplace = storeList.Where(x => x.isLock == true).Select(x => x.positionName).ToList();
//给被锁定的的一栏统计个数
lb_isLock.Text = lockedplace.Count.ToString();
//空库位个数
lb_emptyPlace.Text = emptyplaceInfo.Count.ToString();
BindingPlace();//将数据和对应的lable对应并分别显示不同的颜色
}
///
/// 给各种图标附上颜色
///
private void BindingPlace()
{
foreach (Control c in pnl_Rack1.Controls)//查找在pn_01中的所有控件
{
if (c is System.Windows.Forms.Label)//如果是Label
{
System.Windows.Forms.Label lb = c as System.Windows.Forms.Label;
//首先初始化这个颜色 【EditBy shaocx,2021-12-21】
lb.BackColor = ColorDic["EMPTY"];
var realPlaceNo = lb.Text;//截取前五位
if (lb.Text.IndexOf(one_emptyStr) > -1)
{
realPlaceNo = lb.Text.Substring(0, lb.Text.IndexOf(one_emptyStr));
}
// lb.MouseDoubleClick += new MouseEventHandler(lb_Click);
string listFind = "";
//用List.Find方法加兰姆达表达式在几个List中分别查找库位的情况
//锁定
listFind = lockedplace.Find(x => x == realPlaceNo);
if (!string.IsNullOrEmpty(listFind) && listFind != "0")
{
lb.BackColor = ColorDic["LOCK"];
}
listFind = "";
listFind = emptyplaceInfo.Find(x => x == realPlaceNo); //将代表空库位的Lable设置为灰色
if (!string.IsNullOrEmpty(listFind))
{
if (lb.BackColor != ColorDic["LOCK"])
{
lb.BackColor = ColorDic["EMPTY"];
}
}
listFind = "";
var tmp1 = (StoredplaceInfo.Find(x => x.positionName == realPlaceNo)); //将代表有货库位的Lable设置为蓝色
if (tmp1 != null)
{
listFind = tmp1.materialName.ToString();
}
if (!string.IsNullOrEmpty(listFind))
{
if (lb.BackColor != ColorDic["LOCK"])
{
lb.BackColor = GetColor(tmp1);
}
lb.ContextMenuStrip = contextMenuStrip1;//添加右键点击菜单
lb.MouseHover += new EventHandler(lb_Mousehover);
}
//最后重新给Lable赋值,显示全部的信息 【EditBy shaocx,2021-03-06】
SetDisplayValue(lb, realPlaceNo);
}
}
foreach (Control c in pnl_Rack2.Controls)//查找在pn_01中的所有控件
{
if (c is Label)//如果是Label
{
Label lb = c as Label;
//首先初始化这个颜色 【EditBy shaocx,2021-12-21】
lb.BackColor = ColorDic["EMPTY"];
var realPlaceNo = lb.Text;//截取前五位
if (lb.Text.IndexOf(one_emptyStr) > -1)
{
realPlaceNo = lb.Text.Substring(0, lb.Text.IndexOf(one_emptyStr));
}
// lb.MouseDoubleClick += new MouseEventHandler(lb_Click);
string listFind = "";
//用List.Find方法加兰姆达表达式在几个List中分别查找库位的情况
//锁定
listFind = lockedplace.Find(x => x == realPlaceNo);
if (!string.IsNullOrEmpty(listFind) && listFind != "0")
{
lb.BackColor = ColorDic["LOCK"];
}
listFind = "";
listFind = emptyplaceInfo.Find(x => x == realPlaceNo); //将代表空库位的Lable设置为灰色
if (!string.IsNullOrEmpty(listFind))
{
if (lb.BackColor != ColorDic["LOCK"])
{
lb.BackColor = ColorDic["EMPTY"];
}
}
listFind = "";
var tmp1 = (StoredplaceInfo.Find(x => x.positionName == realPlaceNo)); //将代表有货库位的Lable设置为蓝色
if (tmp1 != null)
{
listFind = tmp1.materialName.ToString();
}
if (!string.IsNullOrEmpty(listFind))
{
if (lb.BackColor != ColorDic["LOCK"])
{
lb.BackColor = GetColor(tmp1);
}
lb.ContextMenuStrip = contextMenuStrip1;//添加右键点击菜单
lb.MouseHover += new EventHandler(lb_Mousehover);
}
//最后重新给Lable赋值,显示全部的信息 【EditBy shaocx,2021-03-06】
SetDisplayValue(lb, realPlaceNo);
}
}
}
///
/// 根据类型获取颜色
///
///
///
private Color GetColor(MyVproductStock store)
{
//if (Convert.ToInt16(store.mouldId) >= SysGloble.MinNoDieNumber)
//先判断是否是呆滞库位
if (WMSCommon.isStatyMonths(BasicDataSetForStayMonths, store))
{//呆滞库位
return ColorDic["STATYMONTHS"];
}
if (WMSCommon.isEmptySalver(store))
{//空托盘?
return ColorDic["NODIE"];
}
if (WMSCommon.isCatogroy(store))
{//货物?
return ColorDic["FULL"];
}
return ColorDic["EMPTY"];
}
///
/// 鼠标悬停是更新右键菜单的值
///
///
///
private void lb_Mousehover(object sender, EventArgs e)
{
string plcName;
if (sender is Label) //如果悬停的控件是label
{
contextMenuStrip1.Items["Sku"].Text = "物料号: "; //初始化右键菜单
contextMenuStrip1.Items["SkuDesc"].Text = "物料名称: ";
contextMenuStrip1.Items["QTY"].Text = "数量: ";
try
{
Label lb = sender as Label;
plcName = lb.Text.Trim();
StringBuilder sb = new StringBuilder();//获取物料号.物料名称,状态,数量
if (Stored_cache != null)
{
var storeds = Stored_cache.FindAll(x => x.positionName == plcName);
if (storeds != null && storeds.Count > 0)
{
foreach (var it in storeds)
{
//此处存疑??
contextMenuStrip1.Items["ITEMNO"].Text += it.materialCode + "; ";
contextMenuStrip1.Items["TYPE"].Text += it.materialName + "; ";
//if (!string.IsNullOrEmpty(it.ITEMNO) && !string.IsNullOrEmpty(it.TYPE))
//{
// contextMenuStrip1.Items["QTY"].Text += it.ITEMQTY + "; ";
//}
}
}
}
}
catch
{
this.Show();
}
}
}
private void initialForRack1()
{
initialForRack(pnl_Rack1, 2, _column, _layer);
}
private void initialForRack2()
{
initialForRack(pnl_Rack2, 1, _column, _layer);
}
private void btnReload_Click(object sender, EventArgs e)
{
//初始化层数列表
initialNumberOfLayer(pnl_LayerFor1, _layer);
initialNumberOfLayer(pnl_LayerFor2, _layer);
//初始化列数列表
initialNumberOfColumn(pnl_ColFor1, _column);
initialNumberOfColumn(pnl_ColFor2, _column);
GetAllStore();
if (this.WindowState == FormWindowState.Normal || this.WindowState == FormWindowState.Maximized)
{
//var t1 = new Thread(RefreshRack2);//刷新第二排货架
//t1.Start();
//var t2 = new Thread(RefreshRack1);//刷新第一排货架
//t2.Start();
//RefreshRack2();
//RefreshRack1();
initialForRack1();
initialForRack2();
}
Thread.Sleep(50);
//将所有库位的状态(颜色)显示出来
RefreshAll();
}
///
/// 显示库存的详细信息
///
///
///
private string SetDisplayValue(Label lb, string placeNo)
{
var newLine = "\r\n";
var textConntent = placeNo;
MyVproductStock curStroe = null;
curStroe = currentAll_Stored_cache.Where(p => p.positionName != null && p.positionName == placeNo && p.isfree == true).FirstOrDefault();
if (curStroe == null)
{
textConntent = placeNo + one_emptyStr;
}
else
{
textConntent = placeNo + one_emptyStr + newLine;
if (!string.IsNullOrEmpty(curStroe.materialName))
{
textConntent += curStroe.materialName;
}
if (!string.IsNullOrEmpty(curStroe.containerCode))
{
textConntent += curStroe.containerCode + newLine;
}
}
lb.Text = textConntent;
return textConntent;
}
///
/// 根据列和层数初始化货架模型
///
/// 控件
/// 列
/// 层
private void initialForRack(object sender, int row, int column, int layer)
{
(sender as Panel).Controls.Clear();
int pnlWidth = (sender as Panel).Width;
int pnlHeight = (sender as Panel).Height;
int lblWidth = pnlWidth / column;
int lblHeight = pnlHeight / layer;
string r = row.ToString();
string c = "";
string l = "";
(sender as Panel).Margin = new Padding(1, 1, 1, 5);
for (int i = 1; i <= column; i++)
//for (int i = column; i >= 1; i--)
{
if (row == 2)
{//第二排
for (int j = layer; j >= 1; j--)
{
Label lb = new Label();
c = (column - i + 1).ToString();
if (j < 10)
{
l = j.ToString();
}
else
{
l = j.ToString();
}
lb.Width = lblWidth;
lb.Height = lblHeight;
lb.Margin = new Padding(1, 1, 1, 1);
int y = pnlHeight - j * lb.Height;
int x = (i - 1) * lb.Width;
Point startlocation = new Point(x, y);
lb.Location = startlocation;
//lb.Text = r + c + l;
var placeNo = r + "-" + c + "-" + l;//库位号命名
SetDisplayValue(lb, placeNo);
lb.ForeColor = Color.Blue;
lb.BorderStyle = BorderStyle.FixedSingle;
lb.TextAlign = ContentAlignment.MiddleCenter;
(sender as Panel).Controls.Add(lb);
}
}
else if (row == 1)//一排从下至上排列
{//第一排
for (int j = 1; j <= layer; j++)
{
Label lb = new Label();
c = (column - i + 1).ToString();
if (j < 10)
{
l = j.ToString();
}
else
{
l = j.ToString();
}
lb.Width = lblWidth;
lb.Height = lblHeight;
lb.Margin = new Padding(1, 1, 1, 1);
int y = (j - 1) * lb.Height;
int x = (i - 1) * lb.Width;
Point startlocation = new Point(x, y);
lb.Location = startlocation;
//lb.Text = r + c + l;
var placeNo = r + "-" + c + "-" + l;
SetDisplayValue(lb, placeNo);
lb.ForeColor = Color.Blue;
lb.BorderStyle = BorderStyle.FixedSingle;
lb.TextAlign = ContentAlignment.MiddleCenter;
(sender as Panel).Controls.Add(lb);
}
}
}
}
///
/// 初始化列数列表
///
///
private void initialNumberOfColumn(object sender, int column)
{
(sender as Panel).Controls.Clear();
int pnlWidth = (sender as Panel).Width;
int pnlHeight = (sender as Panel).Height;
for (int i = 1; i <= column; i++)
{
Label lb = new Label();
lb.Font = new Font("微软雅黑", 9f);
lb.Text = (column - i + 1).ToString();
lb.Width = pnlWidth / column;
lb.Height = pnlHeight;
lb.Margin = new Padding(2, 1, 0, 1);
int y = 0;
int x = (i - 1) * lb.Width + lb.Width / 4;
Point startlocation = new Point(x, y);
lb.Location = startlocation;
(sender as Panel).Controls.Add(lb);
}
}
///
/// 初始化层数列表
///
///
private void initialNumberOfLayer(object sender, int layer)
{
if ((sender as Panel).Name == "pnl_LayerFor1")
{
(sender as Panel).Controls.Clear();
int pnlWidth = (sender as Panel).Width;
int pnlHeight = (sender as Panel).Height;
for (int i = layer; i > 0; i--)
{
Label lb = new Label();
lb.Font = new Font("微软雅黑", 9f);
if (i < 10)
{
lb.Text = i.ToString();
}
else
{
lb.Text = i.ToString();
}
lb.Width = pnlWidth;
lb.Height = pnlHeight / layer;
lb.Margin = new Padding(1, 2, 1, 0);
int y = pnlHeight - ((i - 1) * lb.Height + lb.Height / 4) - (int)(lb.Height * 0.6);
int x = 0;
Point startlocation = new Point(x, y);
lb.Location = startlocation;
(sender as Panel).Controls.Add(lb);
(sender as Panel).Refresh();
}
}
else
{
(sender as Panel).Controls.Clear();
int pnlWidth = (sender as Panel).Width;
int pnlHeight = (sender as Panel).Height;
for (int i = 1; i <= layer; i++)
{
Label lb = new Label();
lb.Font = new Font("微软雅黑", 9f);
if (i < 10)
{
lb.Text = i.ToString();
}
else
{
lb.Text = i.ToString();
}
lb.Width = pnlWidth;
lb.Height = pnlHeight / layer;
lb.Margin = new Padding(1, 2, 1, 0);
int y = (i - 1) * lb.Height + lb.Height / 4;
int x = 0;
Point startlocation = new Point(x, y);
lb.Location = startlocation;
(sender as Panel).Controls.Add(lb);
(sender as Panel).Refresh();
}
}
}
private void btnClose_Click(object sender, EventArgs e)
{
try
{
this.Dispose();
}
catch (Exception)
{
}
this.Close();
}
///
/// 获取所有的库存数据
///
private void GetAllStore()
{
currentAll_Stored_cache = clent.findAllProductStock().ToList();
BasicDataSetForStayMonths = clent.GetBasicDataSetForStayMonths();
}
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
if (isHasOpenFullSrceen)
{
MessageBox.Show("已经打开了全屏!");
return;
}
FrmStore frm = new FrmStore(true, this);
// '如果不把Border设为None,则无法隐藏Windows的开始任务栏
frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
// frm.WindowState = FormWindowState.Maximized;
//frm.WindowState = FormWindowState.Normal;//注意WindowState不能是Maximized
//'如果不允许运行其他程序,则可设为True,屏蔽其他窗体的显示
// '但必须确保自身所有的窗体的TopMost除了子窗体外都要设置为true,否则也同样会被屏蔽
//frm.TopMost = true;
frm.menuStrip2.Visible = false;
this.isHasOpenFullSrceen = true;//父窗体
frm.Show();
}
private void FrmStore_KeyUp(object sender, KeyEventArgs e)
{
//先设置窗体属性KeyPreview=True。
if (e.KeyData == Keys.Escape)
{
if (this.isFullSrceen)
{
if (fatherFrmStore != null) fatherFrmStore.isHasOpenFullSrceen = false;//父窗体
//退出全屏
this.Close();//子窗体
}
}
}
private void FrmStore_SizeChanged(object sender, EventArgs e)
{
asc.controlAutoSize(this);
}
private void FrmStore_FormClosing(object sender, FormClosingEventArgs e)
{
if (t != null)
{
t.Abort();
}
if (this.isFullSrceen)
{
if (t_tips != null)
{
t_tips.Abort();
}
}
}
private void tableLayoutPanel4_Paint(object sender, PaintEventArgs e)
{
}
}
}