优化料盘横向排序或者竖向排序

master
lhiven 2 years ago
parent 9a44b4eade
commit 7708ff1c93

@ -11,19 +11,43 @@ using System.Xml.Serialization;
namespace Rs.Controls
{
public enum ESortDir
{
Horizontal,
Vertical
}
public enum ESlotStatus
{
Have,
NotHave,
Ok,
Ng
}
public partial class RsTray : UserControl
{
public ESortDir SortDir { get; set; } = ESortDir.Horizontal;
public event Action<TraySlot, MouseEventArgs> SlotClickEvent;
public RsTray()
{
InitializeComponent();
DoubleBuffered = true;
InitSlot();
InitSlot(InitSlotStatus);
this.SizeChanged += (s, e) => {
UpdateSlotPos();
};
}
private ESlotStatus _InitSlotStatus = ESlotStatus.Have;
public ESlotStatus InitSlotStatus
{
get { return _InitSlotStatus; }
set { _InitSlotStatus = value; InitSlot(InitSlotStatus); Invalidate(); }
}
public bool CanDraw { get; set; } = true;
private List<TraySlot> traySlots = new List<TraySlot>();
@ -45,7 +69,7 @@ namespace Rs.Controls
public int RowNum
{
get { return _RowNum; }
set { _RowNum = value; InitSlot(); Invalidate(); }
set { _RowNum = value; InitSlot(InitSlotStatus); Invalidate(); }
}
private int _ColumnNum = 10;
@ -56,7 +80,7 @@ namespace Rs.Controls
public int ColumnNum
{
get { return _ColumnNum; }
set { _ColumnNum = value; InitSlot(); Invalidate(); }
set { _ColumnNum = value; InitSlot(InitSlotStatus); Invalidate(); }
}
private int _TopSpaceHeight = 20;
@ -80,6 +104,23 @@ namespace Rs.Controls
set { _LeftSpaceWidth = value; }
}
private int _RowSpace = 3;
public int RowSpace
{
get { return _RowSpace; }
set { _RowSpace = value; }
}
private int _ColSpace = 5;
public int ColSpace
{
get { return _ColSpace; }
set { _ColSpace = value; }
}
private bool _ShowText;
public bool ShowText
@ -91,34 +132,78 @@ namespace Rs.Controls
private Bitmap drawImage;
private void InitSlot()
private void InitSlot(ESlotStatus status)
{
int index = 0;
traySlots.Clear();
traySlotsDic.Clear();
for (int c = 0; c < ColumnNum; c++)
if(SortDir== ESortDir.Vertical)
{
for (int c = 0; c < ColumnNum; c++)
{
for (int r = 0; r < RowNum; r++)
{
index++;
TraySlot slot = new TraySlot();
slot.Index = index;
slot.Row = r;
slot.Column = c;
slot.SlotStatus = status;
//slot.Bound = new RectangleF((LeftSpaceWidth + widthPer * c), (TopSpaceHeight + heightPer * r), (int)widthPer - 5, (int)heightPer - 5);
//slot.Draw(g2);
traySlots.Add(slot);
traySlotsDic.Add(index, slot);
}
}
}
else
{
for (int r = 0; r < RowNum; r++)
{
index++;
TraySlot slot = new TraySlot();
slot.Index = index;
slot.Row = r;
slot.Column = c;
//slot.Bound = new RectangleF((LeftSpaceWidth + widthPer * c), (TopSpaceHeight + heightPer * r), (int)widthPer - 5, (int)heightPer - 5);
//slot.Draw(g2);
traySlots.Add(slot);
traySlotsDic.Add(index, slot);
for (int c = 0; c < ColumnNum; c++)
{
index++;
TraySlot slot = new TraySlot();
slot.Index = index;
slot.Row = r;
slot.Column = c;
slot.SlotStatus = status;
//slot.Bound = new RectangleF((LeftSpaceWidth + widthPer * c), (TopSpaceHeight + heightPer * r), (int)widthPer - 5, (int)heightPer - 5);
//slot.Draw(g2);
traySlots.Add(slot);
traySlotsDic.Add(index, slot);
}
}
}
UpdateSlotPos();
}
public void ChangeStatus(int index,int status)
public void Fill()
{
traySlotsDic[index].Status = status;
traySlotsDic[index].Refresh(this.panel2.CreateGraphics(),ShowText);
foreach (TraySlot item in traySlots)
{
ChangeStatus(item.Index, ESlotStatus.Have);
}
}
public void Clear()
{
foreach (TraySlot item in traySlots)
{
ChangeStatus(item.Index, ESlotStatus.NotHave);
}
}
public void ChangeStatus(int index,ESlotStatus status)
{
if(traySlotsDic.ContainsKey(index))
{
traySlotsDic[index].SlotStatus = status;
traySlotsDic[index].Refresh(this.panel2.CreateGraphics(), ShowText);
}
//panel2_Paint(null, null);
}
@ -127,25 +212,35 @@ namespace Rs.Controls
float slotWidth = (this.panel2.Width - LeftSpaceWidth) / ColumnNum;
float slotHeight = (this.panel2.Height - TopSpaceHeight) / RowNum;
int index = 0;
for (int c = 0; c < ColumnNum; c++)
if(SortDir== ESortDir.Vertical)
{
for (int c = 0; c < ColumnNum; c++)
{
for (int r = 0; r < RowNum; r++)
{
index++;
if (traySlotsDic.ContainsKey(index))
{
traySlotsDic[index].Bound = new RectangleF((LeftSpaceWidth + slotWidth * c), (TopSpaceHeight + slotHeight * r), (int)slotWidth - ColSpace, (int)slotHeight - RowSpace);
}
}
}
}
else
{
for (int r = 0; r < RowNum; r++)
{
index++;
if (traySlotsDic.ContainsKey(index))
for (int c = 0; c < ColumnNum; c++)
{
traySlotsDic[index].Bound = new RectangleF((LeftSpaceWidth + slotWidth * c), (TopSpaceHeight + slotHeight * r), (int)slotWidth - 5, (int)slotHeight - 3);
index++;
if (traySlotsDic.ContainsKey(index))
{
traySlotsDic[index].Bound = new RectangleF((LeftSpaceWidth + slotWidth * c), (TopSpaceHeight + slotHeight * r), (int)slotWidth - ColSpace, (int)slotHeight - RowSpace);
}
}
//TraySlot slot = new TraySlot();
//slot.Index = index;
//slot.Row = r;
//slot.Column = c;
//slot.Bound = new RectangleF((LeftSpaceWidth + widthPer * c), (TopSpaceHeight + heightPer * r), (int)widthPer - 5, (int)heightPer - 5);
//slot.Draw(g2);
//traySlots.Add(slot);
//traySlotsDic.Add(index, slot);
}
}
panel2.Refresh();
}
@ -271,6 +366,7 @@ namespace Rs.Controls
/// </summary>
public class TraySlot
{
public ESlotStatus SlotStatus { get; set; } = ESlotStatus.Have;
private PointF _Position;
@ -280,14 +376,6 @@ namespace Rs.Controls
set { _Position = value; }
}
private int _Status;
public int Status
{
get { return _Status; }
set { _Status = value; }
}
private int _Index;
public int Index
@ -331,16 +419,33 @@ namespace Rs.Controls
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
if(Status==1)
{
g.FillRectangle(new SolidBrush(Color.Red), Bound.X, Bound.Y, Bound.Width - 1, Bound.Height - 1);
}
else if(Status==0)
switch (SlotStatus)
{
g.FillRectangle(new SolidBrush(Color.FromArgb(11, 16, 36)), Bound.X, Bound.Y, Bound.Width-1, Bound.Height-1);
// g.FillRectangle(new SolidBrush(Color.Red), Bound.X, Bound.Y, Bound.Width , Bound.Height );
case ESlotStatus.Have:
g.FillRectangle(new SolidBrush(Color.Red), Bound.X, Bound.Y, Bound.Width - 1, Bound.Height - 1);
break;
case ESlotStatus.NotHave:
g.FillRectangle(new SolidBrush(Color.FromArgb(11, 16, 36)), Bound.X, Bound.Y, Bound.Width - 1, Bound.Height - 1);
break;
case ESlotStatus.Ok:
g.FillRectangle(new SolidBrush(Color.Green), Bound.X, Bound.Y, Bound.Width - 1, Bound.Height - 1);
break;
case ESlotStatus.Ng:
g.FillRectangle(new SolidBrush(Color.Gray), Bound.X, Bound.Y, Bound.Width - 1, Bound.Height - 1);
break;
default:
break;
}
//if(Status==1)
//{
// g.FillRectangle(new SolidBrush(Color.Red), Bound.X, Bound.Y, Bound.Width - 1, Bound.Height - 1);
//}
//else if(Status==0)
//{
// g.FillRectangle(new SolidBrush(Color.FromArgb(11, 16, 36)), Bound.X, Bound.Y, Bound.Width-1, Bound.Height-1);
// // g.FillRectangle(new SolidBrush(Color.Red), Bound.X, Bound.Y, Bound.Width , Bound.Height );
//}
g.DrawRectangle(Pens.White, Bound.X, Bound.Y, Bound.Width, Bound.Height);
if (isShowText)
{

Loading…
Cancel
Save