narsil/Tanshu.Accounts.PointOfSale/Management/NcForm.cs

130 lines
4.4 KiB
C#
Raw Normal View History

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 NcForm : Form
{
private IList<CheckBox> checkBoxes;
private IDictionary<int, string> list;
public NcForm()
{
InitializeComponent();
}
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)
{
checkBoxes = new List<CheckBox>();
var startDate = dtpStartDate.Value.Date.AddHours(7);
var finishDate = dtpFinishDate.Value.Date.AddDays(1).AddHours(7);
var details = GetNc(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 checkBox = GetBox((int)item[0]);
checkBoxes.Add(checkBox);
flpProducts.Controls.Add(checkBox);
}
}
private ComboBox GetBox(int code)
{
var checkBox = new CheckBox()
{
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 GetNcable(DateTime startDate, DateTime finishDate)
{
using (var bi = new ManagementBI())
return bi.GetNcable(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);
}
}
}
}