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

72 lines
2.0 KiB
C#

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.SqlDAO;
using Tanshu.Accounts.Helpers;
using Tanshu.Common.KeyboardControl;
namespace Tanshu.Accounts.PointOfSale
{
public partial class DiscountForm : Form
{
private IList<string> source;
private HashSet<string> selection;
decimal discount;
public DiscountForm(IList<string> source)
{
InitializeComponent();
this.source = source;
selection = new HashSet<string>();
}
private void button_Click(object sender, EventArgs e)
{
CheckBox 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<string> 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();
}
}
}
}