narsil/Tanshu.Accounts.PointOfSale/Sales/SettleChoicesForm.cs
unknown 964d0a78bf Added Basecode to Product
Added Voucher Type During Printing
Added Discount Report
Fixed Void bill table not getting cleared error
Added PAX to table
Removed Itital Setup button in MainForm as it was not doing anything
2011-12-05 15:11:02 +05:30

136 lines
5.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Tanshu.Accounts.Entities;
using Tanshu.Common.Helpers;
using Tanshu.Common.KeyboardControl;
namespace Tanshu.Accounts.PointOfSale
{
public partial class SettleChoicesForm : Form
{
private readonly IDictionary<Button, int> _list;
private decimal _amount;
private readonly VoucherType _voucherType;
public SettleChoicesForm(decimal amount, VoucherType voucherType)
{
InitializeComponent();
_amount = amount;
_voucherType = voucherType;
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;
using (var frm = new SettleAmountsForm(new NumpadControl(), settleOption, _amount))
{
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)
foreach (var item in _list)
item.Key.Enabled = true;
else
foreach (var item in _list.Where(item => item.Value != group))
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)))
{
var attribute = item.Attribute();
if (!attribute.ShowInChoices || attribute.Group != _voucherType.Attribute().Group)
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, attribute.Group);
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 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++;
txtAmount.TabIndex = count;
this.Size = this.SizeFromClientSize(new Size(count * (75 + 6), 3 + txtAmount.Height + 6 + 75 + 3));
txtAmount.Width = flpSettlement.Width - 6;
}
}
}