using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using Tanshu.Accounts.Helpers; namespace Tanshu.Accounts.PointOfSale { public partial class DiscountForm : Form { private readonly IList _source; private readonly HashSet _selection; decimal _discount; public DiscountForm(IList source) { InitializeComponent(); this._source = source; _selection = new HashSet(); } private void button_Click(object sender, EventArgs e) { var button = sender as CheckBox; if (button == null) return; var item = (string)button.Tag; if (button.CheckState == CheckState.Checked) _selection.Add(item); else _selection.Remove(item); } public decimal Selection(out HashSet list) { list = _selection; return _discount; } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } private void DiscountForm_Load(object sender, EventArgs e) { ControlFactory.GenerateGroups(ref flpModifier, new Point(75, 75), _source, new ButtonClickDelegate(button_Click)); } private void txtAmount_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Return && decimal.TryParse(txtAmount.Text, out _discount) && _discount >= 0 && _discount <= 100) { this.DialogResult = DialogResult.OK; this.Close(); } else if (e.KeyCode == Keys.Escape) { this.DialogResult = DialogResult.Cancel; this.Close(); } } } }