163 lines
6.0 KiB
C#
163 lines
6.0 KiB
C#
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Globalization;
|
|||
|
using System.Windows.Forms;
|
|||
|
using Tanshu.Accounts.Repository;
|
|||
|
|
|||
|
namespace Tanshu.Accounts.Management
|
|||
|
{
|
|||
|
public partial class MoveForm : Form
|
|||
|
{
|
|||
|
private IList<ComboBox> comboBoxes;
|
|||
|
private IDictionary<int, string> list;
|
|||
|
public MoveForm()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
list = new Dictionary<int, string>
|
|||
|
{
|
|||
|
{1, "1 - Dark"},
|
|||
|
{2, "2 - Wheat"},
|
|||
|
{3, "3 - Premium"},
|
|||
|
{4, "4 - Light"},
|
|||
|
{5, "5 - Dragon"},
|
|||
|
{6, "6 - Festival"},
|
|||
|
{7, "7 - Vanilla"},
|
|||
|
{8, "8 - Strong"}
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
private void Sale_Analysis_Form_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
dtpStartDate.Value = DateTime.Today;
|
|||
|
dtpFinishDate.Value = DateTime.Today;
|
|||
|
}
|
|||
|
|
|||
|
private void btnGo_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
comboBoxes = new List<ComboBox>();
|
|||
|
var startDate = dtpStartDate.Value.Date.AddHours(7);
|
|||
|
var finishDate = dtpFinishDate.Value.Date.AddDays(1).AddHours(7);
|
|||
|
var details = GetMove(startDate, finishDate);
|
|||
|
foreach (var detail in details)
|
|||
|
{
|
|||
|
var item = (object[])detail;
|
|||
|
var text = GetName((int)item[0]) + " ---> " + ((decimal)item[1]).ToString();
|
|||
|
|
|||
|
var label = new Label()
|
|||
|
{
|
|||
|
Name = "label" + ((int)item[0]).ToString(CultureInfo.InvariantCulture),
|
|||
|
AutoSize = true,
|
|||
|
Text = text
|
|||
|
};
|
|||
|
flpProducts.Controls.Add(label);
|
|||
|
var comboBox = GetBox((int)item[0]);
|
|||
|
comboBoxes.Add(comboBox);
|
|||
|
flpProducts.Controls.Add(comboBox);
|
|||
|
|
|||
|
}
|
|||
|
//foreach (var comboBox in comboBoxes)
|
|||
|
//{
|
|||
|
// var startDate = dtpStartDate.Value.Date.AddHours(7);
|
|||
|
// var finishDate = startDate.AddDays(1);
|
|||
|
|
|||
|
// var baseCode = (int)(((object[])comboBox.Tag)[0]);
|
|||
|
// var text = (string)(((object[])comboBox.Tag)[1]);
|
|||
|
// foreach (var item in comboBox.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);
|
|||
|
// }
|
|||
|
//}
|
|||
|
}
|
|||
|
private ComboBox GetBox(int code)
|
|||
|
{
|
|||
|
var comboBox = new ComboBox()
|
|||
|
{
|
|||
|
Name = "comboBox" + (code).ToString(CultureInfo.InvariantCulture),
|
|||
|
Width = 400,
|
|||
|
Height = 20,
|
|||
|
Tag = code,
|
|||
|
DisplayMember = "Value",
|
|||
|
ValueMember = "Key",
|
|||
|
DropDownStyle = ComboBoxStyle.DropDownList,
|
|||
|
DataSource = new BindingSource(list, null)
|
|||
|
};
|
|||
|
//foreach (var item in list)
|
|||
|
// comboBox.Items.Add(new { Code = item.Key, Name = item.Value });
|
|||
|
//MessageBox.Show(code.ToString());
|
|||
|
//comboBox.SelectedIndex = code - 1;
|
|||
|
comboBox.SelectedValue = code;
|
|||
|
return comboBox;
|
|||
|
}
|
|||
|
private static string GetName(int code)
|
|||
|
{
|
|||
|
switch (code)
|
|||
|
{
|
|||
|
case 1:
|
|||
|
return "1 - Dark";
|
|||
|
case 2:
|
|||
|
return "2 - Wheat";
|
|||
|
case 3:
|
|||
|
return "3 - Premium";
|
|||
|
case 4:
|
|||
|
return "4 - Light";
|
|||
|
case 5:
|
|||
|
return "5 - Dragon";
|
|||
|
case 6:
|
|||
|
return "6 - Festival";
|
|||
|
case 7:
|
|||
|
return "7 - Vanilla";
|
|||
|
case 8:
|
|||
|
return "8 - Strong";
|
|||
|
default:
|
|||
|
return "";
|
|||
|
}
|
|||
|
}
|
|||
|
private static decimal TryConvert(string amount)
|
|||
|
{
|
|||
|
decimal result = 0;
|
|||
|
decimal.TryParse(amount, out result);
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
private static IList GetMove(DateTime startDate, DateTime finishDate)
|
|||
|
{
|
|||
|
using (var bi = new ManagementBI())
|
|||
|
return bi.GetMove(startDate, finishDate);
|
|||
|
}
|
|||
|
private static void SetMove(int fromBaseCode, int toBaseCode, DateTime startDate, DateTime finishDate)
|
|||
|
{
|
|||
|
using (var bi = new ManagementBI())
|
|||
|
bi.SetMove(fromBaseCode, toBaseCode, startDate, finishDate);
|
|||
|
}
|
|||
|
|
|||
|
private void btnProcess_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
btnProcess.Enabled = false;
|
|||
|
var startDate = dtpStartDate.Value.Date.AddHours(7);
|
|||
|
var finishDate = dtpFinishDate.Value.Date.AddDays(1).AddHours(7);
|
|||
|
foreach (var item in comboBoxes)
|
|||
|
{
|
|||
|
var fromBaseCode = (int) item.Tag;
|
|||
|
var toBaseCode = (int) item.SelectedValue;
|
|||
|
if (fromBaseCode == toBaseCode)
|
|||
|
continue;
|
|||
|
Text = GetName(fromBaseCode) + " to " + GetName(toBaseCode);
|
|||
|
MessageBox.Show(Text);
|
|||
|
SetMove(fromBaseCode, toBaseCode, startDate , finishDate);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|