166 lines
6.8 KiB
C#
166 lines
6.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.Drawing;
|
|
using Tanshu.Accounts.Contracts;
|
|
using Tanshu.Accounts.Entities;
|
|
using System.Collections;
|
|
|
|
namespace Tanshu.Accounts.Helpers
|
|
{
|
|
public delegate void ButtonClickDelegate(object sender, EventArgs e);
|
|
|
|
public static class ControlFactory
|
|
{
|
|
public static void GenerateTables(ref FlowLayoutPanel panel, ref List<Button> buttonList, Point size, int start, IList<FoodTable> inList, ButtonClickDelegate bcDelegate)
|
|
{
|
|
IList<FoodTable> list = new List<FoodTable>();
|
|
int pageLength, stop;
|
|
PageSetup(ref panel, ref buttonList, start, inList as IList, out pageLength, out stop);
|
|
if (start != 0)
|
|
list.Add(new FoodTable() { FoodTableID = start - pageLength, Name = "Previous" });
|
|
for (int i = start; i < stop; i++)
|
|
{
|
|
list.Add(inList[i]);
|
|
}
|
|
if (stop < inList.Count)
|
|
list.Add(new FoodTable() { FoodTableID = stop, Name = "Next" });
|
|
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
var item = list[i];
|
|
var control = GetButton(string.Format("g{0}", i), item.Name, size.X, size.Y, item, bcDelegate);
|
|
//var control = GetButton(string.Format("g{0}", i), string.Format("{0} {1}", item.ProductGroupID, item.Name), size.X, size.Y, item, bcDelegate);
|
|
panel.Controls.Add(control);
|
|
buttonList.Add(control);
|
|
}
|
|
}
|
|
public static void GenerateProducts(ref FlowLayoutPanel panel, ref List<Button> buttonList, Point size, int start, IList<Product> inList, ButtonClickDelegate bcDelegate)
|
|
{
|
|
IList<Product> list = new List<Product>();
|
|
int pageLength, stop;
|
|
PageSetup(ref panel, ref buttonList, start, inList as IList, out pageLength, out stop);
|
|
if (start != 0)
|
|
list.Add(new Product() { ProductID = start - pageLength, Name = "Previous" });
|
|
for (int i = start; i < stop; i++)
|
|
{
|
|
list.Add(inList[i]);
|
|
}
|
|
if (stop < inList.Count)
|
|
list.Add(new Product() { ProductID = stop, Name = "Next" });
|
|
|
|
|
|
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
var item = list[i];
|
|
var control = GetButton(string.Format("p{0}", i), string.Format("{0} ({1})", item.Name, item.Units), size.X, size.Y, item, bcDelegate);
|
|
//var control = GetButton(string.Format("g{0}", i), string.Format("{0} {1}", item.ProductGroupID, item.Name), size.X, size.Y, item, bcDelegate);
|
|
panel.Controls.Add(control);
|
|
buttonList.Add(control);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
public static void GenerateGroups(ref FlowLayoutPanel panel, ref List<Button> buttonList, Point size, int start, IList<ProductGroup> inList, ButtonClickDelegate bcDelegate)
|
|
{
|
|
IList<ProductGroup> list = new List<ProductGroup>();
|
|
int pageLength, stop;
|
|
PageSetup(ref panel, ref buttonList, start, inList as IList, out pageLength, out stop);
|
|
if (start != 0)
|
|
list.Add(new ProductGroup() { ProductGroupID = start - pageLength, Name = "Previous" });
|
|
for (int i = start; i < stop; i++)
|
|
{
|
|
list.Add(inList[i]);
|
|
}
|
|
if (stop < inList.Count)
|
|
list.Add(new ProductGroup() { ProductGroupID = stop, Name = "Next" });
|
|
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
var item = list[i];
|
|
var control = GetButton(string.Format("g{0}", i), item.Name, size.X, size.Y, item, bcDelegate);
|
|
//var control = GetButton(string.Format("g{0}", i), string.Format("{0} {1}", item.ProductGroupID, item.Name), size.X, size.Y, item, bcDelegate);
|
|
panel.Controls.Add(control);
|
|
buttonList.Add(control);
|
|
}
|
|
}
|
|
public static void GenerateModifiers(ref FlowLayoutPanel panel, ref IList<CheckBox> controlList, IList<Modifier> selection, Point size, int count, IList<Modifier> list, ButtonClickDelegate bcDelegate)
|
|
{
|
|
if (controlList.Count != 0)
|
|
{
|
|
for (int i = controlList.Count - 1; i >= 0; i--)
|
|
{
|
|
controlList[i].Dispose();
|
|
}
|
|
controlList = new List<CheckBox>();
|
|
}
|
|
if (count > list.Count)
|
|
count = list.Count;
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
var item = list[i];
|
|
var control = GetCheckbox(i.ToString(), item.Name, size.X, size.Y, item, bcDelegate);
|
|
control.Checked = selection.Contains(item);
|
|
panel.Controls.Add(control);
|
|
controlList.Add(control);
|
|
}
|
|
}
|
|
|
|
private static void PageSetup(ref FlowLayoutPanel panel, ref List<Button> buttonList, int start, IList inList, out int pageLength, out int stop)
|
|
{
|
|
if (buttonList.Count != 0)
|
|
{
|
|
for (int i = buttonList.Count - 1; i >= 0; i--)
|
|
{
|
|
buttonList[i].Dispose();
|
|
}
|
|
buttonList = new List<Button>();
|
|
}
|
|
pageLength = (panel.Height / (3 + 75 + 3));
|
|
pageLength *= (panel.Width / (3 + 75 + 3));
|
|
pageLength -= 2;
|
|
if (inList.Count <= pageLength)
|
|
start = 0;
|
|
if (start == 0)
|
|
pageLength += 1;
|
|
stop = start + pageLength;
|
|
if (stop > inList.Count)
|
|
stop = inList.Count;
|
|
|
|
}
|
|
private static Button GetButton(string name, string text, int width, int height, object tag, ButtonClickDelegate bcDelegate)
|
|
{
|
|
Button control = new Button()
|
|
{
|
|
Name = name,
|
|
Text = text,
|
|
Width = width,
|
|
Height = height,
|
|
Tag = tag,
|
|
};
|
|
if (bcDelegate != null)
|
|
control.Click += new EventHandler(bcDelegate);
|
|
return control;
|
|
}
|
|
private static CheckBox GetCheckbox(string name, string text, int width, int height, object tag, ButtonClickDelegate bcDelegate)
|
|
{
|
|
CheckBox control = new CheckBox()
|
|
{
|
|
Name = name,
|
|
Text = text,
|
|
Width = width,
|
|
Height = height,
|
|
Tag = tag,
|
|
Appearance = Appearance.Button,
|
|
|
|
};
|
|
if (bcDelegate != null)
|
|
control.Click += new EventHandler(bcDelegate);
|
|
return control;
|
|
}
|
|
}
|
|
} |