You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
308 lines
13 KiB
308 lines
13 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Data;
|
|
using SSWMS.Common;
|
|
|
|
namespace SSWMS.Client.UC
|
|
{
|
|
public partial class ucStoreCell : UserControl
|
|
{
|
|
public delegate void DelegateCellClick(WH_CELL wc);
|
|
public event DelegateCellClick U_CellDoubleClick;
|
|
public event DelegateCellClick U_CellClick;
|
|
public Border SelectedBorder = null;
|
|
private const int iHignLowDiff = 10;
|
|
|
|
public ucStoreCell()
|
|
{
|
|
InitializeComponent();
|
|
this.ucWare.U_WareHouseChanged += () =>
|
|
{
|
|
this.tbCellCode.Text = string.Empty;
|
|
this.SelectedBorder = null;
|
|
this.InitCell();
|
|
};
|
|
this.bRefresh.Click += (sender, e) => { this.InitCell(); };
|
|
this.bZoom.Click += (sender, e) =>
|
|
{
|
|
this.txtZoom.Text = "100";
|
|
this.InitCell();
|
|
};
|
|
this.bZoomIn.PreviewMouseDown += (sender, e) =>
|
|
{
|
|
int iZoom = Convert.ToInt32(this.txtZoom.Text);
|
|
if (e.ClickCount == 1)
|
|
{
|
|
iZoom += 1;
|
|
}
|
|
else if (e.ClickCount == 2)
|
|
{
|
|
iZoom += 4;
|
|
}
|
|
else if (e.ClickCount > 2)
|
|
{
|
|
iZoom += 5;
|
|
}
|
|
this.txtZoom.Text = (iZoom < 100 ? iZoom : 100).ToString();
|
|
this.InitCell();
|
|
};
|
|
this.bZoomOut.PreviewMouseDown += (sender, e) =>
|
|
{
|
|
int iZoom = Convert.ToInt32(this.txtZoom.Text);
|
|
if (e.ClickCount == 1)
|
|
{
|
|
iZoom -= 1;
|
|
}
|
|
else if (e.ClickCount == 2)
|
|
{
|
|
iZoom -= 4;
|
|
}
|
|
else if (e.ClickCount > 2)
|
|
{
|
|
iZoom -= 5;
|
|
}
|
|
this.txtZoom.Text = (iZoom > 0 ? iZoom : 0).ToString();
|
|
this.InitCell();
|
|
};
|
|
}
|
|
|
|
public void U_InitControl()
|
|
{
|
|
this.ucWare.U_InitControl();
|
|
}
|
|
|
|
public void InitCell()
|
|
{
|
|
try
|
|
{
|
|
// 初始化
|
|
this.cWarehouseCells.Children.Clear();
|
|
this.spCellStatus.Children.Clear();
|
|
this.spRunStatus.Children.Clear();
|
|
IList<WH_CELL> lWarehouseCells = WCFChannel._I_CellService.GetCellByCellZ(
|
|
this.ucWare.U_WAREHOUSE_CODE, this.ucWare.U_CELL_Z, MainApp._USER.USER_ID);
|
|
if (lWarehouseCells == null || lWarehouseCells.Count == 0)
|
|
{
|
|
MessageDialog.ShowException("未找到货位");
|
|
return;
|
|
}
|
|
double dPercent = Convert.ToDouble(this.txtZoom.Text) / 100;
|
|
const int iMariginX = 2;
|
|
const int iMariginY = 2;
|
|
const int iTotalBottom = 40;
|
|
const int iTotalLeft = 40;
|
|
const int iTotalRight = 30;
|
|
int iMaxX = lWarehouseCells.Max(l => l.CELL_X);
|
|
int iMinX = lWarehouseCells.Min(l => l.CELL_X);
|
|
int iMaxY = lWarehouseCells.Max(l => l.CELL_Y);
|
|
int iMinY = lWarehouseCells.Min(l => l.CELL_Y);
|
|
int iMinWidth = Convert.ToInt32(lWarehouseCells.Max(l => l.CELL_WIDTH) * dPercent);
|
|
iMinWidth = iMinWidth > 20 ? iMinWidth : 20;
|
|
int iMinCellHeigth = lWarehouseCells.Min(l => l.CELL_HEIGHT);
|
|
int iMinHeight = Convert.ToInt32(iMinCellHeigth * dPercent);
|
|
int iMaxHeight = Convert.ToInt32(lWarehouseCells.Max(l => l.CELL_HEIGHT) * dPercent);
|
|
iMinHeight = iMinHeight > 20 ? iMinHeight : 20;
|
|
iMaxHeight = iMaxHeight > 20 ? iMaxHeight : 20;
|
|
//int iHighIndex = Int32.MaxValue;
|
|
//int iHighIndex = lWarehouseCells.Where(l => l.CELL_HEIGHT > iMinCellHeigth).Max(l => l.CELL_Y);
|
|
IEnumerable<WH_CELL> iHighCells = lWarehouseCells.Where(l => l.CELL_HEIGHT > iMinCellHeigth);
|
|
int iHighIndex = iHighCells.Count() > 0 ? iHighCells.Min(l => l.CELL_Y) : 0;
|
|
int iTotalTop = 20 + (iMaxY - iHighIndex + 1) * (iMaxHeight - iMinHeight);
|
|
int iCanvasWidth = (iMaxX - iMinX + 1) * iMinWidth + iTotalLeft + iTotalRight;
|
|
this.cWarehouseCells.Width = iCanvasWidth > 200 ? iCanvasWidth : 200;
|
|
int iCanvasHeight = (iMaxY - iMinY + 1) * iMinHeight + iTotalTop + iTotalBottom;
|
|
this.cWarehouseCells.Height = iCanvasHeight > 200 ? iCanvasHeight : 200;
|
|
|
|
// 货位图
|
|
for (int i = iMinX; i <= iMaxX; ++i)
|
|
{
|
|
Label l = new Label
|
|
{
|
|
Content = i.ToString("D2"),
|
|
Foreground = Brushes.DarkBlue,
|
|
Width = iMinWidth,
|
|
Height = 20,
|
|
HorizontalContentAlignment = HorizontalAlignment.Center,
|
|
VerticalContentAlignment = VerticalAlignment.Top
|
|
};
|
|
Canvas.SetTop(l, (iMaxY - iMinY + 1) * iMinHeight + iTotalTop);
|
|
Canvas.SetLeft(l, (i - iMinX) * iMinWidth + iTotalLeft);
|
|
this.cWarehouseCells.Children.Add(l);
|
|
}
|
|
for (int i = iMinY; i <= iMaxY; ++i)
|
|
{
|
|
Label l = new Label
|
|
{
|
|
Content = i.ToString("D2"),
|
|
Foreground = Brushes.DarkBlue,
|
|
Width = 20,
|
|
Height = iMinHeight,
|
|
HorizontalContentAlignment = HorizontalAlignment.Right,
|
|
VerticalContentAlignment = VerticalAlignment.Center
|
|
};
|
|
if (i < iHighIndex)
|
|
{
|
|
Canvas.SetTop(l, (iMaxY - i) * iMinHeight + iTotalTop);
|
|
}
|
|
else
|
|
{
|
|
Canvas.SetTop(l, (iMaxY - i) * iMinHeight + iTotalTop - (i - iHighIndex + 0.5) * (iMaxHeight - iMinHeight));
|
|
}
|
|
Canvas.SetLeft(l, iTotalLeft - l.Width - iMariginX * 2);
|
|
this.cWarehouseCells.Children.Add(l);
|
|
}
|
|
int iSelectedCellID = 0;
|
|
if (this.SelectedBorder != null)
|
|
{
|
|
iSelectedCellID = (this.SelectedBorder.DataContext as WH_CELL).CELL_ID;
|
|
}
|
|
foreach (WH_CELL wc in lWarehouseCells)
|
|
{
|
|
int iWidth = Convert.ToInt32(wc.CELL_WIDTH * dPercent);
|
|
int iHeight = Convert.ToInt32(wc.CELL_HEIGHT * dPercent);
|
|
Border b = new Border
|
|
{
|
|
BorderBrush = wc.CELL_ID == iSelectedCellID ? Brushes.Red : Brushes.Black,
|
|
BorderThickness = new Thickness(1),
|
|
CornerRadius = new CornerRadius(1),
|
|
Background = new LinearGradientBrush(SystemCode.WH_CELL_COLOR.GetColor(wc),
|
|
Colors.White, new Point(0, 0), new Point(0, 1)),
|
|
Width = (iWidth > iMinWidth ? iWidth : iMinWidth) - 2 * iMariginX,
|
|
Height = (iHeight > iMinHeight ? iHeight : iMinHeight) - 2 * iMariginY,
|
|
DataContext = wc,
|
|
Child = new TextBlock
|
|
{
|
|
Text = wc.MANAGE_ID == 0 ? string.Empty : "R",
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
HorizontalAlignment = HorizontalAlignment.Center,
|
|
Foreground = Brushes.Black
|
|
}
|
|
};
|
|
b.MouseDown += Border_MouseDown;
|
|
Canvas.SetLeft(b, (wc.CELL_X - iMinX) * iMinWidth + iTotalLeft + iMariginX);
|
|
if (wc.CELL_Y < iHighIndex)
|
|
{
|
|
Canvas.SetTop(b, (iMaxY - wc.CELL_Y) * iMinHeight + iTotalTop + iMariginY);
|
|
}
|
|
else
|
|
{
|
|
Canvas.SetTop(b, (iMaxY - wc.CELL_Y) * iMinHeight + iTotalTop + iMariginY - (wc.CELL_Y - iHighIndex + 1) * (iMaxHeight - iMinHeight));
|
|
}
|
|
this.cWarehouseCells.Children.Add(b);
|
|
if (wc.CELL_ID == iSelectedCellID)
|
|
{
|
|
this.SelectedBorder = b;
|
|
}
|
|
}
|
|
|
|
// 统计数据
|
|
this.spRunStatus.Children.Add(new TextBlock
|
|
{
|
|
Margin = new Thickness(5),
|
|
Text = $" - 空闲[{lWarehouseCells.Count(wc => wc.MANAGE_ID == 0)}]"
|
|
});
|
|
this.spRunStatus.Children.Add(new TextBlock
|
|
{
|
|
Margin = new Thickness(5),
|
|
Text = $"R - 运行[{lWarehouseCells.Count(wc => wc.MANAGE_ID > 0)}]"
|
|
});
|
|
|
|
foreach (Color color in SystemCode.WH_CELL_COLOR.CellColors)
|
|
{
|
|
StackPanel sp = new StackPanel
|
|
{
|
|
Orientation = Orientation.Horizontal,
|
|
Margin = new Thickness(5)
|
|
};
|
|
sp.Children.Add(new Border
|
|
{
|
|
Margin = new Thickness(2),
|
|
CornerRadius = new CornerRadius(2),
|
|
Width = 25,
|
|
BorderThickness = new Thickness(1, 1.5, 2, 1),
|
|
BorderBrush = Brushes.Black,
|
|
Background = new LinearGradientBrush(color, Colors.White, new Point(0, 0), new Point(0, 1))
|
|
});
|
|
string sText = string.Empty;
|
|
if (color == SystemCode.WH_CELL_COLOR.Full)
|
|
{
|
|
sText = $" - 物料[{lWarehouseCells.Count(wc => wc.CELL_FLAG == SystemCode.FLAG.Enable && wc.STORAGE_ID > 0 && wc.GOODS_ID > SystemCode.GOODS_ID.MaxStock)}]";
|
|
}
|
|
else if (color == SystemCode.WH_CELL_COLOR.Stock)
|
|
{
|
|
sText = $" - 托盘[{lWarehouseCells.Count(wc => wc.CELL_FLAG == SystemCode.FLAG.Enable && wc.STORAGE_ID > 0 && wc.GOODS_ID < SystemCode.GOODS_ID.MaxStock)}]";
|
|
}
|
|
else if (color == SystemCode.WH_CELL_COLOR.Nohave)
|
|
{
|
|
sText = $" - 空[{lWarehouseCells.Count(wc => wc.CELL_FLAG == SystemCode.FLAG.Enable && wc.STORAGE_ID == 0)}]";
|
|
}
|
|
else if (color == SystemCode.WH_CELL_COLOR.Exception)
|
|
{
|
|
sText = $" - 异常[{lWarehouseCells.Count(wc => wc.CELL_FLAG == SystemCode.FLAG.Disable)}]";
|
|
}
|
|
sp.Children.Add(new TextBlock
|
|
{
|
|
VerticalAlignment = VerticalAlignment.Center,
|
|
Margin = new Thickness(1),
|
|
Text = sText
|
|
});
|
|
this.spCellStatus.Children.Add(sp);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageDialog.ShowException(ex);
|
|
}
|
|
}
|
|
|
|
private void Border_MouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
if (e.LeftButton == MouseButtonState.Pressed)
|
|
{
|
|
try
|
|
{
|
|
Border b = sender as Border;
|
|
if (b == null)
|
|
{
|
|
return;
|
|
}
|
|
WH_CELL wc = b.DataContext as WH_CELL;
|
|
if (this.SelectedBorder != b)
|
|
{
|
|
if (this.SelectedBorder != null)
|
|
{
|
|
this.SelectedBorder.BorderBrush = Brushes.Black;
|
|
}
|
|
b.BorderBrush = Brushes.Red;
|
|
this.SelectedBorder = b;
|
|
this.tbCellCode.Text = wc.CELL_NAME;
|
|
}
|
|
switch (e.ClickCount)
|
|
{
|
|
case 1:
|
|
if (this.U_CellClick != null)
|
|
{
|
|
this.U_CellClick(wc);
|
|
}
|
|
break;
|
|
case 2:
|
|
if (this.U_CellDoubleClick != null)
|
|
{
|
|
this.U_CellDoubleClick(wc);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageDialog.ShowException(ex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|