2011-03-11 18:49:48 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
using System.Linq;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Tanshu.Accounts.Entities;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
using Tanshu.Common.Helpers;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
using Tanshu.Common.KeyboardControl;
|
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.PointOfSale
|
|
|
|
|
{
|
|
|
|
|
public partial class SettleChoicesForm : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly IDictionary<Button, int> _list;
|
|
|
|
|
private decimal _amount;
|
2011-12-05 09:41:02 +00:00
|
|
|
|
private readonly VoucherType _voucherType;
|
|
|
|
|
public SettleChoicesForm(decimal amount, VoucherType voucherType)
|
2011-03-11 18:49:48 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2011-06-23 12:47:48 +00:00
|
|
|
|
_amount = amount;
|
2011-12-05 09:41:02 +00:00
|
|
|
|
_voucherType = voucherType;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
OptionsChosen = new Dictionary<SettleOption, decimal>();
|
|
|
|
|
_list = new Dictionary<Button, int>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var button = sender as Button;
|
|
|
|
|
if (button == null || button.Tag == null)
|
|
|
|
|
return;
|
|
|
|
|
if (button.Tag is SettleOption)
|
|
|
|
|
{
|
|
|
|
|
var settleOption = (SettleOption)button.Tag;
|
2011-08-23 07:10:05 +00:00
|
|
|
|
using (var frm = new SettleAmountsForm(new NumpadControl(), settleOption, _amount))
|
2011-03-11 18:49:48 +00:00
|
|
|
|
{
|
|
|
|
|
frm.ShowDialog();
|
|
|
|
|
UpdateChoice(settleOption, frm.AmountSettled, _list[button]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ((string)button.Tag == "Cancel")
|
|
|
|
|
_optionsChosen.Clear();
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateChoice(SettleOption settleOption, decimal amount, int group)
|
|
|
|
|
{
|
|
|
|
|
var oldAmount = _optionsChosen.ContainsKey(settleOption) ? _optionsChosen[settleOption] : 0;
|
|
|
|
|
if (amount == 0 && _optionsChosen.ContainsKey(settleOption))
|
|
|
|
|
_optionsChosen.Remove(settleOption);
|
|
|
|
|
else if (_optionsChosen.ContainsKey(settleOption))
|
|
|
|
|
_optionsChosen[settleOption] = amount;
|
|
|
|
|
else if (amount != 0)
|
|
|
|
|
_optionsChosen.Add(settleOption, amount);
|
|
|
|
|
_amount += oldAmount - amount;
|
|
|
|
|
txtAmount.Text = string.Format("Pending Amount: Rs. {0}", _amount);
|
|
|
|
|
|
|
|
|
|
if (_optionsChosen.Count == 0)
|
2011-12-05 09:41:02 +00:00
|
|
|
|
foreach (var item in _list)
|
2011-03-11 18:49:48 +00:00
|
|
|
|
item.Key.Enabled = true;
|
|
|
|
|
else
|
2011-12-05 09:41:02 +00:00
|
|
|
|
foreach (var item in _list.Where(item => item.Value != group))
|
2011-03-11 18:49:48 +00:00
|
|
|
|
item.Key.Enabled = false;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IDictionary<SettleOption, decimal> _optionsChosen;
|
|
|
|
|
public IDictionary<SettleOption, decimal> OptionsChosen
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _amount == 0 ? _optionsChosen : new Dictionary<SettleOption, decimal>();
|
|
|
|
|
}
|
|
|
|
|
private set { _optionsChosen = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SettleChoicesFormLoad(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
txtAmount.Text = string.Format("Pending Amount: Rs. {0}", _amount);
|
|
|
|
|
var count = 0;
|
|
|
|
|
foreach (SettleOption item in Enum.GetValues(typeof(SettleOption)))
|
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
var attribute = item.Attribute();
|
2011-12-05 09:41:02 +00:00
|
|
|
|
if (!attribute.ShowInChoices || attribute.Group != _voucherType.Attribute().Group)
|
2011-03-11 18:49:48 +00:00
|
|
|
|
continue;
|
|
|
|
|
var button = new Button
|
|
|
|
|
{
|
|
|
|
|
Name = item.ToString(),
|
|
|
|
|
Text = attribute.Name,
|
2011-12-05 09:41:02 +00:00
|
|
|
|
Size = new Size(75, 75),
|
2011-03-11 18:49:48 +00:00
|
|
|
|
TabIndex = count,
|
|
|
|
|
UseVisualStyleBackColor = true,
|
|
|
|
|
Tag = item
|
|
|
|
|
};
|
|
|
|
|
button.Click += new EventHandler(ButtonClick);
|
|
|
|
|
flpSettlement.Controls.Add(button);
|
|
|
|
|
_list.Add(button, attribute.Group);
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
var controlButton = new Button
|
|
|
|
|
{
|
|
|
|
|
Name = "btnOK",
|
|
|
|
|
Text = "OK",
|
2011-12-05 09:41:02 +00:00
|
|
|
|
Size = new Size(75, 75),
|
2011-03-11 18:49:48 +00:00
|
|
|
|
TabIndex = count,
|
|
|
|
|
UseVisualStyleBackColor = true,
|
|
|
|
|
Tag = "OK"
|
|
|
|
|
};
|
|
|
|
|
controlButton.Click += new EventHandler(ButtonClick);
|
|
|
|
|
flpSettlement.Controls.Add(controlButton);
|
2011-12-05 09:41:02 +00:00
|
|
|
|
// _list.Add(controlButton); --- Do not add to list
|
2011-03-11 18:49:48 +00:00
|
|
|
|
count++;
|
|
|
|
|
controlButton = new Button
|
|
|
|
|
{
|
|
|
|
|
Name = "btnCancel",
|
|
|
|
|
Text = "Cancel",
|
2011-12-05 09:41:02 +00:00
|
|
|
|
Size = new Size(75, 75),
|
2011-03-11 18:49:48 +00:00
|
|
|
|
TabIndex = count,
|
|
|
|
|
UseVisualStyleBackColor = true,
|
|
|
|
|
Tag = "Cancel"
|
|
|
|
|
};
|
|
|
|
|
controlButton.Click += new EventHandler(ButtonClick);
|
|
|
|
|
flpSettlement.Controls.Add(controlButton);
|
2011-12-05 09:41:02 +00:00
|
|
|
|
// _list.Add(controlButton); --- Do not add to list
|
2011-03-11 18:49:48 +00:00
|
|
|
|
count++;
|
|
|
|
|
txtAmount.TabIndex = count;
|
|
|
|
|
|
2011-12-05 09:41:02 +00:00
|
|
|
|
this.Size = this.SizeFromClientSize(new Size(count * (75 + 6), 3 + txtAmount.Height + 6 + 75 + 3));
|
2011-03-11 18:49:48 +00:00
|
|
|
|
txtAmount.Width = flpSettlement.Width - 6;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|