narsil/Tanshu.Accounts.PointOfSale/Sales/ModifierForm.cs

78 lines
2.5 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Helpers;
namespace Tanshu.Accounts.PointOfSale
{
public partial class ModifierForm : Form
{
private IList<InventoryModifier> selection;
private IList<Modifier> source;
private IList<CheckBox> list;
public ModifierForm(IList<Modifier> source, IList<InventoryModifier> selection)
{
InitializeComponent();
this.selection = selection;
this.source = source;
list = new List<CheckBox>();
}
private void button_Click(object sender, EventArgs e)
{
CheckBox button = sender as CheckBox;
if (button == null)
return;
if (button.CheckState == CheckState.Checked)
selection.Add(new InventoryModifier() { Modifier = (Modifier)button.Tag });
else
selection.Remove(selection.First(x => x.Modifier.ModifierID == ((Modifier)button.Tag).ModifierID));
}
private void ModifierForm_Load(object sender, EventArgs e)
{
var size = new Point(75, 75);
int count = 30;
ButtonClickDelegate bcDelegate = new ButtonClickDelegate(button_Click);
if (list.Count != 0)
{
for (int i = list.Count - 1; i >= 0; i--)
{
list[i].Dispose();
}
list = new List<CheckBox>();
}
if (count > source.Count)
count = source.Count;
for (int i = 0; i < count; i++)
{
var control = new CheckBox()
{
Name = i.ToString(),
Text = source[i].Name,
Width = size.X,
Height = size.Y,
Tag = source[i],
Appearance = Appearance.Button,
Checked = selection.Count(x => x.Modifier.ModifierID == source[i].ModifierID) > 0
};
control.Click += new EventHandler(bcDelegate);
flpModifier.Controls.Add(control);
list.Add(control);
}
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
}
}