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
{
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 )
{
2011-12-05 09:41:02 +00:00
int baseCode = 0 ;
2011-08-28 12:17:15 +00:00
if ( rbLight . Checked )
{
2011-12-05 09:41:02 +00:00
baseCode = 1 ;
2011-08-28 12:17:15 +00:00
}
else if ( rbPremium . Checked )
{
2011-12-05 09:41:02 +00:00
baseCode = 2 ;
2011-08-28 12:17:15 +00:00
}
else if ( rbWheat . Checked )
{
2011-12-05 09:41:02 +00:00
baseCode = 3 ;
2011-08-28 12:17:15 +00:00
}
else if ( rbDark . Checked )
{
2011-12-05 09:41:02 +00:00
baseCode = 4 ;
2011-08-28 12:17:15 +00:00
}
else if ( rbFestival . Checked )
{
2011-12-05 09:41:02 +00:00
baseCode = 5 ;
2011-08-28 12:17:15 +00:00
}
2011-12-05 09:41:02 +00:00
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 ) ;
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 ;
if ( baseCode < = 0 )
continue ;
if ( ! decimal . TryParse ( data [ 2 ] , out quantity ) )
continue ;
bi . SetQuantity ( baseCode , quantity , startDate , finishDate ) ;
}
}
}
2011-08-28 12:17:15 +00:00
}
}
}