2010-03-02 17:56:21 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Drawing;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
using Tanshu.Accounts.Entities;
|
|
|
|
|
using System.Collections;
|
2011-01-31 20:33:22 +00:00
|
|
|
|
using Tanshu.Common.KeyboardControl;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.Helpers
|
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
public delegate void ButtonClickDelegate(object sender, EventArgs e);
|
|
|
|
|
|
2010-03-02 17:56:21 +00:00
|
|
|
|
public static class ControlFactory
|
|
|
|
|
{
|
2011-02-18 16:54:48 +00:00
|
|
|
|
public static void GenerateTables(ref FlowLayoutPanel panel, Point size, int start, IList<FoodTable> inList, ButtonClickDelegate bcDelegate)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
IList<FoodTable> list = new List<FoodTable>();
|
|
|
|
|
int pageLength, stop;
|
2012-12-01 09:49:33 +00:00
|
|
|
|
PageSetup(panel, start, inList as IList, size, out pageLength, out stop);
|
2011-01-30 07:14:05 +00:00
|
|
|
|
if (start != 0)
|
|
|
|
|
list.Add(new FoodTable() { FoodTableID = start - pageLength, Name = "Previous" });
|
|
|
|
|
for (int i = start; i < stop; i++)
|
2011-01-09 23:36:24 +00:00
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
list.Add(inList[i]);
|
2011-01-09 23:36:24 +00:00
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
if (stop < inList.Count)
|
|
|
|
|
list.Add(new FoodTable() { FoodTableID = stop, Name = "Next" });
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < list.Count; i++)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
var item = list[i];
|
2011-02-18 16:54:48 +00:00
|
|
|
|
var status = item.Status;
|
2012-12-01 09:49:33 +00:00
|
|
|
|
var control = GetButton(string.Format("g{0}", i), item.Name, size, item, bcDelegate);
|
2011-01-31 20:33:22 +00:00
|
|
|
|
if (status == "printed")
|
|
|
|
|
control.BackColor = Color.Green;
|
|
|
|
|
else if (status == "running")
|
|
|
|
|
control.BackColor = Color.Red;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
panel.Controls.Add(control);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-18 16:54:48 +00:00
|
|
|
|
public static void GenerateProducts(ref FlowLayoutPanel panel, Point size, int start, IList<Product> inList, ButtonClickDelegate bcDelegate)
|
2011-01-09 23:36:24 +00:00
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
IList<Product> list = new List<Product>();
|
|
|
|
|
int pageLength, stop;
|
2012-12-01 09:49:33 +00:00
|
|
|
|
PageSetup(panel, start, inList as IList, size, out pageLength, out stop);
|
2011-01-30 07:14:05 +00:00
|
|
|
|
if (start != 0)
|
|
|
|
|
list.Add(new Product() { ProductID = start - pageLength, Name = "Previous" });
|
|
|
|
|
for (int i = start; i < stop; i++)
|
2011-01-09 23:36:24 +00:00
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
list.Add(inList[i]);
|
2011-01-09 23:36:24 +00:00
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
if (stop < inList.Count)
|
|
|
|
|
list.Add(new Product() { ProductID = stop, Name = "Next" });
|
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
for (var i = 0; i < list.Count; i++)
|
2011-01-09 23:36:24 +00:00
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
var item = list[i];
|
2012-12-01 09:49:33 +00:00
|
|
|
|
var control = GetButton(string.Format("p{0}", i), item.Units == string.Empty ? item.Name : string.Format("{0} ({1})", item.Name, item.Units), size, item, bcDelegate);
|
2011-08-28 12:17:15 +00:00
|
|
|
|
if (item.Price == 0)
|
2011-06-23 12:47:48 +00:00
|
|
|
|
control.BackColor = Color.Yellow;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
panel.Controls.Add(control);
|
|
|
|
|
}
|
2011-01-31 20:33:22 +00:00
|
|
|
|
}
|
2011-02-18 16:54:48 +00:00
|
|
|
|
// For Discount Form
|
|
|
|
|
public static void GenerateGroups(ref FlowLayoutPanel panel, Point size, IList<string> list, ButtonClickDelegate bcDelegate)
|
2011-01-31 20:33:22 +00:00
|
|
|
|
{
|
2011-02-18 16:54:48 +00:00
|
|
|
|
panel.Controls.Clear();
|
2011-01-31 20:33:22 +00:00
|
|
|
|
for (int i = 0; i < list.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var item = list[i];
|
2012-12-01 09:49:33 +00:00
|
|
|
|
var control = GetUnselectableCheckbox(i.ToString(), item, size, item, bcDelegate);
|
2011-01-31 20:33:22 +00:00
|
|
|
|
panel.Controls.Add(control);
|
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
2011-02-18 16:54:48 +00:00
|
|
|
|
// For Main Form
|
|
|
|
|
public static void GenerateGroups(ref FlowLayoutPanel panel, Point size, int start, IList<ProductGroup> inList, ButtonClickDelegate bcDelegate)
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
|
|
|
|
IList<ProductGroup> list = new List<ProductGroup>();
|
|
|
|
|
int pageLength, stop;
|
2012-12-01 09:49:33 +00:00
|
|
|
|
PageSetup(panel, start, inList as IList, size, out pageLength, out stop);
|
2011-01-30 07:14:05 +00:00
|
|
|
|
if (start != 0)
|
|
|
|
|
list.Add(new ProductGroup() { ProductGroupID = start - pageLength, Name = "Previous" });
|
|
|
|
|
for (int i = start; i < stop; i++)
|
|
|
|
|
{
|
|
|
|
|
list.Add(inList[i]);
|
2011-01-09 23:36:24 +00:00
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
if (stop < inList.Count)
|
|
|
|
|
list.Add(new ProductGroup() { ProductGroupID = stop, Name = "Next" });
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < list.Count; i++)
|
2011-01-09 23:36:24 +00:00
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
var item = list[i];
|
2012-12-01 09:49:33 +00:00
|
|
|
|
var control = GetButton(string.Format("g{0}", i), item.Name, size, item, bcDelegate);
|
2011-01-30 07:14:05 +00:00
|
|
|
|
panel.Controls.Add(control);
|
2011-01-09 23:36:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
public static void GenerateModifiers(ref FlowLayoutPanel panel, ref IList<CheckBox> controlList, IList<Modifier> selection, Point size, int count, IList<Modifier> list, ButtonClickDelegate bcDelegate)
|
2011-01-22 12:38:30 +00:00
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
if (controlList.Count != 0)
|
2011-01-22 12:38:30 +00:00
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
for (int i = controlList.Count - 1; i >= 0; i--)
|
2011-01-22 12:38:30 +00:00
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
controlList[i].Dispose();
|
2011-01-22 12:38:30 +00:00
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
controlList = new List<CheckBox>();
|
2011-01-22 12:38:30 +00:00
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
if (count > list.Count)
|
|
|
|
|
count = list.Count;
|
|
|
|
|
for (int i = 0; i < count; i++)
|
2011-01-22 12:38:30 +00:00
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
var item = list[i];
|
2012-12-01 09:49:33 +00:00
|
|
|
|
var control = GetCheckbox(i.ToString(), item.Name, size, item, bcDelegate);
|
2011-01-30 07:14:05 +00:00
|
|
|
|
control.Checked = selection.Contains(item);
|
|
|
|
|
panel.Controls.Add(control);
|
|
|
|
|
controlList.Add(control);
|
2011-01-22 12:38:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
|
2012-12-01 09:49:33 +00:00
|
|
|
|
private static void PageSetup(FlowLayoutPanel panel, int start, ICollection inList, Point size, out int pageLength, out int stop)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-02-18 16:54:48 +00:00
|
|
|
|
panel.Controls.Clear();
|
2012-12-01 09:49:33 +00:00
|
|
|
|
var marginWidth = panel.Margin.Right + panel.Margin.Left;
|
|
|
|
|
var marginHeight = panel.Margin.Top + panel.Margin.Bottom;
|
|
|
|
|
pageLength = (panel.ClientSize.Height / (marginHeight + size.Y));
|
|
|
|
|
pageLength *= (panel.ClientSize.Width / (marginWidth + size.X));
|
2011-01-30 07:14:05 +00:00
|
|
|
|
pageLength -= 2;
|
|
|
|
|
if (inList.Count <= pageLength)
|
|
|
|
|
start = 0;
|
|
|
|
|
if (start == 0)
|
|
|
|
|
pageLength += 1;
|
|
|
|
|
stop = start + pageLength;
|
|
|
|
|
if (stop > inList.Count)
|
|
|
|
|
stop = inList.Count;
|
2011-01-22 12:38:30 +00:00
|
|
|
|
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
2012-12-01 09:49:33 +00:00
|
|
|
|
private static Button GetButton(string name, string text, Point size, object tag, ButtonClickDelegate bcDelegate)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2012-12-01 09:49:33 +00:00
|
|
|
|
var control = new Button()
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
|
|
|
|
Name = name,
|
|
|
|
|
Text = text,
|
2012-12-01 09:49:33 +00:00
|
|
|
|
Width = size.X,
|
|
|
|
|
Height = size.Y,
|
2011-01-30 07:14:05 +00:00
|
|
|
|
Tag = tag,
|
|
|
|
|
};
|
2010-03-02 17:56:21 +00:00
|
|
|
|
if (bcDelegate != null)
|
2011-01-30 07:14:05 +00:00
|
|
|
|
control.Click += new EventHandler(bcDelegate);
|
|
|
|
|
return control;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
2012-12-01 09:49:33 +00:00
|
|
|
|
private static UnselectableCheckbox GetUnselectableCheckbox(string name, string text, Point size, object tag, ButtonClickDelegate bcDelegate)
|
2011-01-31 20:33:22 +00:00
|
|
|
|
{
|
2012-12-01 09:49:33 +00:00
|
|
|
|
var control = new UnselectableCheckbox()
|
2011-01-31 20:33:22 +00:00
|
|
|
|
{
|
|
|
|
|
Name = name,
|
|
|
|
|
Text = text,
|
2012-12-01 09:49:33 +00:00
|
|
|
|
Width = size.X,
|
|
|
|
|
Height = size.Y,
|
2011-01-31 20:33:22 +00:00
|
|
|
|
Tag = tag,
|
|
|
|
|
Appearance = Appearance.Button,
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
if (bcDelegate != null)
|
|
|
|
|
control.Click += new EventHandler(bcDelegate);
|
|
|
|
|
return control;
|
|
|
|
|
}
|
2012-12-01 09:49:33 +00:00
|
|
|
|
private static CheckBox GetCheckbox(string name, string text, Point size, object tag, ButtonClickDelegate bcDelegate)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2012-12-01 09:49:33 +00:00
|
|
|
|
var control = new CheckBox()
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
Name = name,
|
|
|
|
|
Text = text,
|
2012-12-01 09:49:33 +00:00
|
|
|
|
Width = size.X,
|
|
|
|
|
Height = size.Y,
|
2011-01-30 07:14:05 +00:00
|
|
|
|
Tag = tag,
|
|
|
|
|
Appearance = Appearance.Button,
|
2011-01-31 20:33:22 +00:00
|
|
|
|
|
2011-01-30 07:14:05 +00:00
|
|
|
|
};
|
|
|
|
|
if (bcDelegate != null)
|
|
|
|
|
control.Click += new EventHandler(bcDelegate);
|
|
|
|
|
return control;
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|