|
|
|
@ -15,10 +15,11 @@ using System.Xml.Serialization;
|
|
|
|
|
|
|
|
|
|
namespace Rs.Controls
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public enum ESortDir
|
|
|
|
|
{
|
|
|
|
|
Horizontal,
|
|
|
|
|
Vertical
|
|
|
|
|
LeftToRight,
|
|
|
|
|
RightToLeft
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum ESlotStatus
|
|
|
|
@ -32,14 +33,26 @@ namespace Rs.Controls
|
|
|
|
|
|
|
|
|
|
public partial class RsTray : UserControl
|
|
|
|
|
{
|
|
|
|
|
private int CurrentSlot { get; set; } = 1;
|
|
|
|
|
public string ItemName { get; set; }
|
|
|
|
|
public ESortDir SortDir { get; set; } = ESortDir.Horizontal;
|
|
|
|
|
public event Action<TraySlot, MouseEventArgs> SlotClickEvent;
|
|
|
|
|
public string ItemName { get; set; }
|
|
|
|
|
|
|
|
|
|
private ESortDir sortDir = ESortDir.LeftToRight;
|
|
|
|
|
|
|
|
|
|
public ESortDir SortDir
|
|
|
|
|
{
|
|
|
|
|
get { return sortDir; }
|
|
|
|
|
set { sortDir = value;
|
|
|
|
|
UpdateSlotPos();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public event Action<TraySlot, MouseEventArgs> SlotClickEvent;
|
|
|
|
|
|
|
|
|
|
#region 是否显示状态
|
|
|
|
|
private bool mShowStatus = true;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否显示状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool ShowStatus
|
|
|
|
|
{
|
|
|
|
|
get { return mShowStatus; }
|
|
|
|
@ -47,6 +60,7 @@ namespace Rs.Controls
|
|
|
|
|
lblStatus.Visible = mShowStatus;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private string mStatus;
|
|
|
|
|
|
|
|
|
@ -72,15 +86,7 @@ namespace Rs.Controls
|
|
|
|
|
|
|
|
|
|
public void ResetTray()
|
|
|
|
|
{
|
|
|
|
|
CurrentSlot = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsLastSlot()
|
|
|
|
|
{
|
|
|
|
|
if(CurrentSlot == RowNum*ColumnNum) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ESlotStatus _InitSlotStatus = ESlotStatus.Have;
|
|
|
|
@ -101,20 +107,7 @@ namespace Rs.Controls
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<TraySlot> GetSlots(ESlotStatus status)
|
|
|
|
|
{
|
|
|
|
|
List<TraySlot> slots = new List<TraySlot>();
|
|
|
|
|
foreach (KeyValuePair<int, TraySlot> kv in traySlotsDic)
|
|
|
|
|
{
|
|
|
|
|
if (kv.Value.SlotStatus == status)
|
|
|
|
|
slots.Add(kv.Value);
|
|
|
|
|
}
|
|
|
|
|
return slots;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CanDraw { get; set; } = true;
|
|
|
|
|
|
|
|
|
|
private List<TraySlot> traySlots = new List<TraySlot>();
|
|
|
|
|
private Dictionary<int, TraySlot> traySlotsDic = new Dictionary<int, TraySlot>();
|
|
|
|
|
|
|
|
|
|
private string _HeadText;
|
|
|
|
@ -245,59 +238,36 @@ namespace Rs.Controls
|
|
|
|
|
private void InitSlot(ESlotStatus status)
|
|
|
|
|
{
|
|
|
|
|
int index = 0;
|
|
|
|
|
traySlots.Clear();
|
|
|
|
|
traySlotsDic.Clear();
|
|
|
|
|
if (SortDir == ESortDir.Vertical)
|
|
|
|
|
for (int r = 0; r < RowNum; r++)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
traySlots.Add(slot);
|
|
|
|
|
traySlotsDic.Add(index, slot);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (int r = 0; r < RowNum; r++)
|
|
|
|
|
{
|
|
|
|
|
for (int c = 0; c < ColumnNum; c++)
|
|
|
|
|
{
|
|
|
|
|
index++;
|
|
|
|
|
TraySlot slot = new TraySlot();
|
|
|
|
|
slot.Index = index;
|
|
|
|
|
slot.Row = r;
|
|
|
|
|
slot.Column = c;
|
|
|
|
|
slot.SlotStatus = status;
|
|
|
|
|
traySlots.Add(slot);
|
|
|
|
|
traySlotsDic.Add(index, slot);
|
|
|
|
|
}
|
|
|
|
|
index++;
|
|
|
|
|
TraySlot slot = new TraySlot();
|
|
|
|
|
slot.Index = index;
|
|
|
|
|
slot.Row = r;
|
|
|
|
|
slot.Column = c;
|
|
|
|
|
slot.SlotStatus = status;
|
|
|
|
|
traySlotsDic.Add(index, slot);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
UpdateSlotPos();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Fill()
|
|
|
|
|
{
|
|
|
|
|
foreach (TraySlot item in traySlots)
|
|
|
|
|
foreach (KeyValuePair<int, TraySlot> kv in traySlotsDic)
|
|
|
|
|
{
|
|
|
|
|
ChangeStatus(item.Index, ESlotStatus.Have);
|
|
|
|
|
ChangeStatus(kv.Value.Index, ESlotStatus.Have);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
|
|
|
|
foreach (TraySlot item in traySlots)
|
|
|
|
|
foreach (KeyValuePair<int, TraySlot> kv in traySlotsDic)
|
|
|
|
|
{
|
|
|
|
|
ChangeStatus(item.Index, ESlotStatus.NotHave);
|
|
|
|
|
ChangeStatus(kv.Value.Index, ESlotStatus.NotHave);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -315,11 +285,11 @@ namespace Rs.Controls
|
|
|
|
|
float slotWidth = (this.panel2.Width - LeftSpaceWidth) / ColumnNum;
|
|
|
|
|
float slotHeight = (this.panel2.Height - TopSpaceHeight) / RowNum;
|
|
|
|
|
int index = 0;
|
|
|
|
|
if (SortDir == ESortDir.Vertical)
|
|
|
|
|
if (SortDir == ESortDir.LeftToRight)
|
|
|
|
|
{
|
|
|
|
|
for (int c = 0; c < ColumnNum; c++)
|
|
|
|
|
for (int r = 0; r < RowNum; r++)
|
|
|
|
|
{
|
|
|
|
|
for (int r = 0; r < RowNum; r++)
|
|
|
|
|
for (int c = 0; c < ColumnNum; c++)
|
|
|
|
|
{
|
|
|
|
|
index++;
|
|
|
|
|
if (traySlotsDic.ContainsKey(index))
|
|
|
|
@ -329,7 +299,7 @@ namespace Rs.Controls
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
else if (SortDir == ESortDir.RightToLeft)
|
|
|
|
|
{
|
|
|
|
|
for (int r = 0; r < RowNum; r++)
|
|
|
|
|
{
|
|
|
|
@ -338,7 +308,7 @@ namespace Rs.Controls
|
|
|
|
|
index++;
|
|
|
|
|
if (traySlotsDic.ContainsKey(index))
|
|
|
|
|
{
|
|
|
|
|
traySlotsDic[index].Bound = new RectangleF((LeftSpaceWidth + slotWidth * c), (TopSpaceHeight + slotHeight * r), (int)slotWidth - ColSpace, (int)slotHeight - RowSpace);
|
|
|
|
|
traySlotsDic[index].Bound = new RectangleF((LeftSpaceWidth + slotWidth * (ColumnNum-1-c)), (TopSpaceHeight + slotHeight * r), (int)slotWidth - ColSpace, (int)slotHeight - RowSpace);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -367,7 +337,14 @@ namespace Rs.Controls
|
|
|
|
|
if (r == 0)
|
|
|
|
|
{
|
|
|
|
|
//画料盘的列号
|
|
|
|
|
g2.DrawString((c + 1).ToString(), new Font("宋体", 7.0F), new SolidBrush(Color.White), new PointF(LeftSpaceWidth + (widthPer * c) + 5, 5));
|
|
|
|
|
if (SortDir == ESortDir.LeftToRight)
|
|
|
|
|
{
|
|
|
|
|
g2.DrawString((c+ 1).ToString(), new Font("宋体", 7.0F), new SolidBrush(Color.White), new PointF(LeftSpaceWidth + (widthPer * c) + 5, 5));
|
|
|
|
|
}
|
|
|
|
|
else if(SortDir== ESortDir.RightToLeft)
|
|
|
|
|
{
|
|
|
|
|
g2.DrawString((ColumnNum - c).ToString(), new Font("宋体", 7.0F), new SolidBrush(Color.White), new PointF(LeftSpaceWidth + (widthPer * c) + 5, 5));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (c == 0)
|
|
|
|
|
{
|
|
|
|
@ -435,12 +412,12 @@ namespace Rs.Controls
|
|
|
|
|
{
|
|
|
|
|
SelectSlot = null;
|
|
|
|
|
bool find = false;
|
|
|
|
|
foreach (TraySlot slot in this.traySlots)
|
|
|
|
|
foreach (KeyValuePair<int,TraySlot> kvSlot in traySlotsDic)
|
|
|
|
|
{
|
|
|
|
|
if (slot.Bound.Contains(e.Location))
|
|
|
|
|
if (kvSlot.Value.Bound.Contains(e.Location))
|
|
|
|
|
{
|
|
|
|
|
find = true;
|
|
|
|
|
SelectSlot = slot;
|
|
|
|
|
SelectSlot = kvSlot.Value;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -460,11 +437,11 @@ namespace Rs.Controls
|
|
|
|
|
|
|
|
|
|
private void ChangeSlotStatus(ESlotStatus status)
|
|
|
|
|
{
|
|
|
|
|
foreach (TraySlot slot in this.traySlots)
|
|
|
|
|
foreach (KeyValuePair<int, TraySlot> kvSlot in traySlotsDic)
|
|
|
|
|
{
|
|
|
|
|
if (drawRect.IntersectsWith(slot.Bound))
|
|
|
|
|
if (drawRect.IntersectsWith(kvSlot.Value.Bound))
|
|
|
|
|
{
|
|
|
|
|
slot.SlotStatus = status;
|
|
|
|
|
kvSlot.Value.SlotStatus = status;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
UpdateSlotPos();
|
|
|
|
@ -488,14 +465,6 @@ namespace Rs.Controls
|
|
|
|
|
{
|
|
|
|
|
public ESlotStatus SlotStatus { get; set; } = ESlotStatus.Have;
|
|
|
|
|
|
|
|
|
|
private PointF _Position;
|
|
|
|
|
|
|
|
|
|
public PointF Position
|
|
|
|
|
{
|
|
|
|
|
get { return _Position; }
|
|
|
|
|
set { _Position = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int _Index;
|
|
|
|
|
|
|
|
|
|
public int Index
|
|
|
|
@ -562,7 +531,7 @@ namespace Rs.Controls
|
|
|
|
|
g.DrawRectangle(Pens.White, Bound.X, Bound.Y, Bound.Width, Bound.Height);
|
|
|
|
|
if (isShowText)
|
|
|
|
|
{
|
|
|
|
|
g.DrawString((Row + 1) + "-" + (Column + 1), new Font("宋体", 8), new SolidBrush(Color.Yellow), _Bound, sf);
|
|
|
|
|
g.DrawString(Index.ToString(), new Font("宋体", 8), new SolidBrush(Color.Yellow), _Bound, sf);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|