narsil/Tanshu.Accounts.PointOfSale/Management/QuantityForm.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

117 lines
3.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Contracts;
namespace Tanshu.Accounts.Management
{
public partial class QuantityForm : Form
{
public QuantityForm()
{
InitializeComponent();
}
private void ShowStatement()
{
}
private void Sale_Analysis_Form_Load(object sender, EventArgs e)
{
dtpStart.Value = DateTime.Today;
dtpFinish.Value = DateTime.Today;
}
private void btnGo_Click(object sender, EventArgs e)
{
int baseCode = 0;
if (rbLight.Checked)
{
baseCode = 1;
}
else if (rbPremium.Checked)
{
baseCode = 2;
}
else if (rbWheat.Checked)
{
baseCode = 3;
}
else if (rbDark.Checked)
{
baseCode = 4;
}
else if (rbFestival.Checked)
{
baseCode = 5;
}
dtpStart.Value = dtpStart.Value.Date.AddHours(7);
dtpFinish.Value = dtpFinish.Value.Date.AddDays(1).AddHours(7);
var quantity = GetQuantity(baseCode);
var newQuantity = Convert.ToDecimal(txtQuantity.Text);
if (MessageBox.Show(quantity.ToString(), "Quantity of Beer", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.Yes && quantity > newQuantity)
{
MessageBox.Show(SetQuantity(baseCode, newQuantity).ToString());
}
}
private decimal GetQuantity(int baseCode)
{
using (var bi = new ManagementBI())
return bi.GetQuantity(baseCode, dtpStart.Value, dtpFinish.Value);
}
private decimal SetQuantity(int baseCode, decimal quantity)
{
using (var bi = new ManagementBI())
return bi.SetQuantity(baseCode, quantity, dtpStart.Value, dtpFinish.Value);
}
private void btnGetClipboard_Click(object sender, EventArgs e)
{
//Clipboard format -- Date,BaseCode,Quantity"
var fmtCsv = DataFormats.CommaSeparatedValue;
// read the CSV
var dataobject = Clipboard.GetDataObject();
if (dataobject == null)
{
MessageBox.Show(@"No Data in clipboard");
return;
}
var stream = (System.IO.Stream)dataobject.GetData(fmtCsv);
var enc = new System.Text.UTF8Encoding();
IFormatProvider culture = new CultureInfo("en-US", true);
using (var reader = new System.IO.StreamReader(stream, enc))
{
using (var bi = new ManagementBI())
{
string line;
while ((line = reader.ReadLine()) != null)
{
DateTime startDate;
int baseCode;
decimal quantity;
var data = line.Split(',');
if (!DateTime.TryParseExact(data[0], "dd-MMM-yyyy", culture, DateTimeStyles.NoCurrentDateDefault, out startDate))
continue;
var finishDate = startDate.AddDays(1).AddHours(7);
startDate = startDate.AddHours(7);
if (!int.TryParse(data[1], out baseCode))
continue;
if (baseCode <=0)
continue;
if (!decimal.TryParse(data[2], out quantity))
continue;
bi.SetQuantity(baseCode, quantity, startDate, finishDate);
}
}
}
}
}
}