2011-08-28 12:17:15 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2011-12-05 09:41:02 +00:00
|
|
|
|
using System.Globalization;
|
2011-08-28 12:17:15 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Tanshu.Accounts.Repository;
|
|
|
|
|
using Tanshu.Accounts.Contracts;
|
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.Management
|
|
|
|
|
{
|
|
|
|
|
public partial class QuantityForm : Form
|
|
|
|
|
{
|
2012-12-01 09:48:02 +00:00
|
|
|
|
private IList<TextBox> textBoxes;
|
2011-08-28 12:17:15 +00:00
|
|
|
|
public QuantityForm()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Sale_Analysis_Form_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2012-12-01 09:48:02 +00:00
|
|
|
|
dtpDate.Value = DateTime.Today;
|
|
|
|
|
|
|
|
|
|
textBoxes = new List<TextBox>();
|
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
|
{
|
|
|
|
|
var text = "";
|
|
|
|
|
switch (i)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
text = "1 - Dark";
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
text = "2 - Wheat";
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
text = "3 - Premium";
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
text = "4 - Light";
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
text = "5 - Dragon";
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
text = "6 - Festival";
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
text = "7 - Vanilla";
|
|
|
|
|
break;
|
|
|
|
|
case 7:
|
|
|
|
|
text = "8 - Strong";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
var label = new Label()
|
|
|
|
|
{
|
|
|
|
|
Name = "label" + (i + 1).ToString(CultureInfo.InvariantCulture),
|
|
|
|
|
AutoSize = true,
|
|
|
|
|
Text = text
|
|
|
|
|
};
|
|
|
|
|
flpProducts.Controls.Add(label);
|
|
|
|
|
var textBox = new TextBox()
|
|
|
|
|
{
|
|
|
|
|
Name = "textBox" + (i + 1).ToString(CultureInfo.InvariantCulture),
|
|
|
|
|
Width = 400,
|
|
|
|
|
Height = 22,
|
|
|
|
|
Tag = new object[] { (i + 1), text }
|
|
|
|
|
};
|
|
|
|
|
textBoxes.Add(textBox);
|
|
|
|
|
flpProducts.Controls.Add(textBox);
|
|
|
|
|
}
|
2011-08-28 12:17:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnGo_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2012-12-01 09:48:02 +00:00
|
|
|
|
foreach (var textBox in textBoxes)
|
2011-08-28 12:17:15 +00:00
|
|
|
|
{
|
2012-12-01 09:48:02 +00:00
|
|
|
|
var startDate = dtpDate.Value.Date.AddHours(7);
|
|
|
|
|
var finishDate = startDate.AddDays(1);
|
|
|
|
|
|
|
|
|
|
var baseCode = (int)(((object[])textBox.Tag)[0]);
|
|
|
|
|
var text = (string)(((object[])textBox.Tag)[1]);
|
|
|
|
|
foreach (var item in textBox.Text.Split(','))
|
|
|
|
|
{
|
|
|
|
|
var newQuantity = TryConvert(item);
|
|
|
|
|
var quantity = GetQuantity(baseCode, startDate, finishDate);
|
|
|
|
|
|
|
|
|
|
if (MessageBox.Show(text + " " + startDate.ToString("dd-MMM-yyyy") + " " + quantity.ToString(), "Quantity of Beer", MessageBoxButtons.YesNo,
|
|
|
|
|
MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.Yes &&
|
|
|
|
|
quantity > newQuantity && newQuantity > 0)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(SetQuantity(baseCode, newQuantity, startDate, finishDate).ToString());
|
|
|
|
|
}
|
|
|
|
|
startDate = startDate.AddDays(1);
|
|
|
|
|
finishDate = finishDate.AddDays(1);
|
|
|
|
|
}
|
2011-12-05 09:41:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-12-01 09:48:02 +00:00
|
|
|
|
private decimal TryConvert(string amount)
|
|
|
|
|
{
|
|
|
|
|
decimal result = 0;
|
|
|
|
|
decimal.TryParse(amount, out result);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
private decimal GetQuantity(int baseCode, DateTime startDate, DateTime finishDate)
|
2011-12-05 09:41:02 +00:00
|
|
|
|
{
|
|
|
|
|
using (var bi = new ManagementBI())
|
2012-12-01 09:48:02 +00:00
|
|
|
|
return bi.GetQuantity(baseCode, startDate, finishDate);
|
2011-12-05 09:41:02 +00:00
|
|
|
|
}
|
2012-12-01 09:48:02 +00:00
|
|
|
|
private decimal SetQuantity(int baseCode, decimal quantity, DateTime startDate, DateTime finishDate)
|
2011-12-05 09:41:02 +00:00
|
|
|
|
{
|
|
|
|
|
using (var bi = new ManagementBI())
|
2012-12-01 09:48:02 +00:00
|
|
|
|
return bi.SetQuantity(baseCode, quantity, startDate, finishDate);
|
2011-08-28 12:17:15 +00:00
|
|
|
|
}
|
2011-12-05 09:41:02 +00:00
|
|
|
|
|
|
|
|
|
private void btnGetClipboard_Click(object sender, EventArgs e)
|
2011-08-28 12:17:15 +00:00
|
|
|
|
{
|
2011-12-05 09:41:02 +00:00
|
|
|
|
//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;
|
2012-12-01 09:48:02 +00:00
|
|
|
|
if (baseCode <= 0)
|
2011-12-05 09:41:02 +00:00
|
|
|
|
continue;
|
|
|
|
|
if (!decimal.TryParse(data[2], out quantity))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
bi.SetQuantity(baseCode, quantity, startDate, finishDate);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-08-28 12:17:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|