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

94 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Tanshu.Accounts.Entities;
using Tanshu.Common.Helpers;
namespace Tanshu.Accounts.PointOfSale
{
public partial class VoucherTypeForm : Form
{
private readonly IList<Button> _list;
public VoucherTypeForm()
{
InitializeComponent();
_list = new List<Button>();
Selection = null;
}
private void ButtonClick(object sender, EventArgs e)
{
var button = sender as Button;
if (button == null || button.Tag == null)
return;
if (button.Tag is VoucherType)
{
Selection = (VoucherType)button.Tag;
foreach (var item in _list)
item.Enabled = (VoucherType)item.Tag != Selection.Value;
}
else
{
if ((string)button.Tag == "Cancel")
Selection = null;
this.Close();
}
}
public VoucherType? Selection { get; private set; }
private void SettleChoicesFormLoad(object sender, EventArgs e)
{
var count = 0;
foreach (VoucherType item in Enum.GetValues(typeof(VoucherType)))
{
var attribute = item.Attribute();
if (!attribute.ShowInChoices)
continue;
var button = new Button
{
Name = item.ToString(),
Text = attribute.Name,
Size = new Size(75, 75),
TabIndex = count,
UseVisualStyleBackColor = true,
Tag = item
};
button.Click += new EventHandler(ButtonClick);
flpSettlement.Controls.Add(button);
_list.Add(button);
count++;
}
var controlButton = new Button
{
Name = "btnOK",
Text = "OK",
Size = new Size(75, 75),
TabIndex = count,
UseVisualStyleBackColor = true,
Tag = "OK"
};
controlButton.Click += new EventHandler(ButtonClick);
flpSettlement.Controls.Add(controlButton);
// _list.Add(controlButton); --- Do not add to list
count++;
controlButton = new Button
{
Name = "btnCancel",
Text = "Cancel",
Size = new System.Drawing.Size(75, 75),
TabIndex = count,
UseVisualStyleBackColor = true,
Tag = "Cancel"
};
controlButton.Click += new EventHandler(ButtonClick);
flpSettlement.Controls.Add(controlButton);
//_list.Add(controlButton); --- Do not add to list
count++;
this.Size = this.SizeFromClientSize(new Size(count * (75 + 6), 3 + 75 + 3));
}
}
}