2011-01-30 07:14:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Tanshu.Accounts.Entities;
|
|
|
|
|
using Tanshu.Accounts.Helpers;
|
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.PointOfSale
|
|
|
|
|
{
|
|
|
|
|
public partial class ModifierForm : Form
|
|
|
|
|
{
|
2016-03-29 09:36:46 +00:00
|
|
|
|
private IList<InventoryModifier> selection;
|
2016-12-03 06:38:47 +00:00
|
|
|
|
private IList<Modifier> modifiersList;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
private IList<CheckBox> list;
|
2016-03-29 09:36:46 +00:00
|
|
|
|
public ModifierForm(IList<Modifier> source, IList<InventoryModifier> selection)
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
this.selection = selection;
|
2016-12-03 06:38:47 +00:00
|
|
|
|
this.modifiersList = source;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
list = new List<CheckBox>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void button_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CheckBox button = sender as CheckBox;
|
2016-04-11 07:01:52 +00:00
|
|
|
|
if (button == null)
|
|
|
|
|
return;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
if (button.CheckState == CheckState.Checked)
|
2016-03-29 09:36:46 +00:00
|
|
|
|
selection.Add(new InventoryModifier() { Modifier = (Modifier)button.Tag });
|
2011-01-30 07:14:05 +00:00
|
|
|
|
else
|
2016-03-29 09:36:46 +00:00
|
|
|
|
selection.Remove(selection.First(x => x.Modifier.ModifierID == ((Modifier)button.Tag).ModifierID));
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
2016-12-03 06:38:47 +00:00
|
|
|
|
private static Point GetSize(FlowLayoutPanel panel, int count)
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2016-12-03 06:38:47 +00:00
|
|
|
|
Point min = new Point(20, 50);
|
|
|
|
|
Point max = new Point(75, 75);
|
|
|
|
|
|
|
|
|
|
var marginWidth = panel.Margin.Right + panel.Margin.Left;
|
|
|
|
|
var marginHeight = panel.Margin.Top + panel.Margin.Bottom;
|
|
|
|
|
|
|
|
|
|
var rows = panel.ClientSize.Height / (max.Y + marginHeight);
|
|
|
|
|
var cols = panel.ClientSize.Width / (max.X + marginWidth);
|
|
|
|
|
|
|
|
|
|
var num = rows * cols;
|
|
|
|
|
|
|
|
|
|
if (num >= count)
|
|
|
|
|
return max;
|
|
|
|
|
|
|
|
|
|
var w = max.X;
|
|
|
|
|
var h = max.Y;
|
|
|
|
|
while (w > min.X && h > min.Y)
|
2016-03-29 09:36:46 +00:00
|
|
|
|
{
|
2016-12-03 06:38:47 +00:00
|
|
|
|
h = (panel.ClientSize.Height / (rows + 1)) - marginHeight;
|
|
|
|
|
if (h >= min.Y)
|
|
|
|
|
{
|
|
|
|
|
++rows;
|
|
|
|
|
}
|
|
|
|
|
if (rows * cols >= count)
|
|
|
|
|
break;
|
|
|
|
|
w = (panel.ClientSize.Width / (cols + 1)) - marginWidth;
|
|
|
|
|
if (w >= min.X)
|
2016-03-29 09:36:46 +00:00
|
|
|
|
{
|
2016-12-03 06:38:47 +00:00
|
|
|
|
++cols;
|
2016-03-29 09:36:46 +00:00
|
|
|
|
}
|
2016-12-03 06:38:47 +00:00
|
|
|
|
if (rows * cols >= count)
|
|
|
|
|
break;
|
2016-03-29 09:36:46 +00:00
|
|
|
|
}
|
2016-12-03 06:38:47 +00:00
|
|
|
|
max.X = (panel.ClientSize.Width / cols) - marginWidth;
|
|
|
|
|
max.Y = (panel.ClientSize.Height / rows) - marginHeight;
|
|
|
|
|
|
|
|
|
|
return max;
|
|
|
|
|
}
|
|
|
|
|
private void ModifierForm_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var size = GetSize(flpModifier, modifiersList.Count);
|
|
|
|
|
ButtonClickDelegate bcDelegate = new ButtonClickDelegate(button_Click);
|
|
|
|
|
for (int i = 0; i < modifiersList.Count; i++)
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2016-03-29 09:36:46 +00:00
|
|
|
|
var control = new CheckBox()
|
|
|
|
|
{
|
|
|
|
|
Name = i.ToString(),
|
2016-12-03 06:38:47 +00:00
|
|
|
|
Text = modifiersList[i].Name,
|
2016-03-29 09:36:46 +00:00
|
|
|
|
Width = size.X,
|
|
|
|
|
Height = size.Y,
|
2016-12-03 06:38:47 +00:00
|
|
|
|
Tag = modifiersList[i],
|
2016-03-29 09:36:46 +00:00
|
|
|
|
Appearance = Appearance.Button,
|
2016-12-03 06:38:47 +00:00
|
|
|
|
Checked = selection.Count(x => x.Modifier.ModifierID == modifiersList[i].ModifierID) > 0
|
2016-03-29 09:36:46 +00:00
|
|
|
|
};
|
|
|
|
|
control.Click += new EventHandler(bcDelegate);
|
|
|
|
|
flpModifier.Controls.Add(control);
|
|
|
|
|
list.Add(control);
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
2016-12-03 06:38:47 +00:00
|
|
|
|
|
|
|
|
|
private void flpModifier_Resize(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var size = GetSize(flpModifier, modifiersList.Count);
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
item.Width = size.X;
|
|
|
|
|
item.Height = size.Y;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|