2010-03-02 17:56:21 +00:00
using System ;
using System.Collections.Generic ;
using System.Drawing ;
using System.Globalization ;
using System.Linq ;
using System.Threading ;
using System.Windows.Forms ;
using Tanshu.Accounts.BI ;
using Tanshu.Accounts.Contracts ;
using Tanshu.Accounts.Helpers ;
using Tanshu.Common ;
namespace Tanshu.Accounts.PointOfSale
{
public partial class SalesForm : Form
{
2011-01-09 23:36:24 +00:00
List < Button > buttonList = new List < Button > ( ) ;
List < Button > buttonHeads = new List < Button > ( ) ;
int page = 0 ;
int pageSize = 6 ;
2010-03-02 17:56:21 +00:00
#region Billing
private Dictionary < BillItemKey , SalesBillItemBO > bill = new Dictionary < BillItemKey , SalesBillItemBO > ( ) ;
private CustomerBO customer = new CustomerBI ( ) . GetCustomer ( new Guid ( "F016CBAD-206C-42C0-BB1D-6006CE57BAB5" ) ) ;
#endregion
private SaleVoucherBO billInfo ;
object lockObject = new object ( ) ;
Guid ? newBillID ;
public SalesForm ( )
{
InitializeComponent ( ) ;
btnCustomer . Text = customer . Name ;
2011-01-09 23:36:24 +00:00
this . Text = Session . User . Name ;
2010-03-02 17:56:21 +00:00
}
public SalesForm ( Guid voucherID )
: this ( )
{
newBillID = voucherID ;
}
private void SalesForm_KeyDown ( object sender , KeyEventArgs e )
{
2011-01-09 23:36:24 +00:00
switch ( e . KeyCode )
2010-03-02 17:56:21 +00:00
{
2011-01-09 23:36:24 +00:00
case Keys . F2 :
{
if ( dgvProducts . Rows . Count > 0 )
SetQuantity ( CurrentProduct , 0 , false , true ) ;
break ;
}
case Keys . F3 :
{
btnDiscount_Click ( sender , new EventArgs ( ) ) ;
break ;
}
case Keys . F4 :
{
if ( ! e . Alt )
ShowCustomerList ( false ) ;
break ;
}
case Keys . F5 :
{
btnWaiter_Click ( sender , new EventArgs ( ) ) ;
break ;
}
case Keys . F7 :
{
using ( SelectProduct selectProduct = new SelectProduct ( new ProductBI ( ) . GetFilteredProducts , true ) )
2010-03-02 17:56:21 +00:00
{
2011-01-09 23:36:24 +00:00
selectProduct . ShowDialog ( ) ;
if ( selectProduct . SelectedItem ! = null )
AddProductToGrid ( selectProduct . SelectedItem . ProductID ) ;
2010-03-02 17:56:21 +00:00
}
2011-01-09 23:36:24 +00:00
break ;
}
case Keys . F8 :
{
LoadBillFromTable ( ) ;
break ;
}
case Keys . F9 :
{
if ( dgvProducts . Rows . Count > 0 )
SetAmount ( CurrentProduct , - 1 ) ;
break ;
}
case Keys . F11 :
{
btnPrintBill_Click ( sender , e ) ;
break ;
}
case Keys . F12 :
{
btnPrintKot_Click ( sender , e ) ;
break ;
}
case Keys . Delete :
{
if ( dgvProducts . Rows . Count > 0 )
ProductRemove ( CurrentProduct ) ;
break ;
}
case Keys . Add :
{
if ( dgvProducts . Rows . Count > 0 )
SetQuantity ( CurrentProduct , 1 , false , false ) ;
break ;
}
case Keys . Subtract :
{
if ( dgvProducts . Rows . Count > 0 )
SetQuantity ( CurrentProduct , - 1 , false , false ) ;
break ;
}
case Keys . Up :
{
if ( ( bindingSource . Position > = 1 ) & & ( ! dgvProducts . Focused ) )
bindingSource . Position - = 1 ;
break ;
}
case Keys . Down :
{
if ( ( bindingSource . Position < bindingSource . Count - 1 ) & & ( ! dgvProducts . Focused ) )
bindingSource . Position + = 1 ;
break ;
}
case Keys . Escape :
{
if ( bill . Count ! = 0 )
if ( MessageBox . Show ( "Cancel current bill?" , "Cancel bill" , MessageBoxButtons . YesNo , MessageBoxIcon . Question , MessageBoxDefaultButton . Button2 ) = = DialogResult . No )
return ;
ClearBill ( ) ;
break ;
}
2010-03-02 17:56:21 +00:00
}
}
#region Helper Functions
private void ClearBill ( )
{
ShowCustomerList ( true ) ;
this . billInfo = null ;
this . txtBillID . Text = "" ;
this . txtKotID . Text = "" ;
this . txtCreationDate . Text = "" ;
this . txtDate . Text = "" ;
this . txtLastEditDate . Text = "" ;
this . txtTableID . Text = "" ;
this . btnWaiter . Text = "Waiter - F5" ;
this . btnWaiter . Tag = null ;
txtGrossTax . Text = "0.00" ;
txtDiscount . Text = "0.00" ;
txtGrossAmount . Text = "0.00" ;
txtAmount . Text = "0.00" ;
bill . Clear ( ) ;
bindingSource . DataSource = bill . Values ;
ChangeFormState ( SaleFormState . Waiting ) ;
}
private void AddProductToGrid ( Guid productID )
{
BillHelperFunctions . AddProductToGrid ( productID , bindingSource , bill ) ;
calculateAmount ( ) ;
}
private void SetQuantity ( SalesBillItemBO product , decimal quantity , bool absolute , bool prompt )
{
if ( product = = null )
return ;
BillHelperFunctions . SetQuantity ( product , quantity , absolute , prompt , bindingSource , bill ) ;
calculateAmount ( ) ;
}
private void SetAmount ( SalesBillItemBO product , decimal amount )
{
if ( product = = null )
return ;
BillHelperFunctions . SetAmount ( product , amount , bindingSource , bill ) ;
calculateAmount ( ) ;
}
private void SetDiscount ( SalesBillItemBO product , decimal discount )
{
if ( product = = null )
return ;
BillHelperFunctions . SetDiscount ( product . productID , discount , customer , bill ) ;
calculateAmount ( ) ;
return ;
}
private bool ProductRemove ( SalesBillItemBO product )
{
if ( product = = null )
return false ;
if ( product . Printed > 0 )
{
if ( ! Thread . CurrentPrincipal . IsInRole ( "Sales/EditPrintedProduct" ) )
{
MessageBox . Show ( "You are not allowed to delete already printed products" ) ;
return false ;
}
if ( MessageBox . Show ( string . Format ( "Already {0} items have been printed.\n\rAre you sure you want to delete this item?" , product . Printed ) , "Delete" , MessageBoxButtons . YesNo , MessageBoxIcon . Question ) = = DialogResult . No )
return false ;
//If BillList(Location).Printed <> 0 Then ItemsDeleted.Add("Deleted " & BillList(Location).Printed & " " & BillList(Location).Name & " from Bill No " & mBillNo)
}
bill . Remove ( new BillItemKey ( product . productID , product . Printed = = 0 ) ) ;
calculateAmount ( ) ;
return true ;
}
private void InputBox_Validating ( object sender , InputBoxValidatingArgs e )
{
}
2011-01-09 23:36:24 +00:00
private void productTypeButton_Click ( object sender , EventArgs e )
{
Button button = sender as Button ;
if ( button = = null )
return ;
Guid tag = ( Guid ) button . Tag ;
ControlFactory . GenerateButtons ( ref pnlBilling , ref buttonList , new Rectangle ( 390 , 94 , 499 , 385 ) , 5 , 6 , 2 , new ProductBI ( ) . GetProducts ( tag ) , new ButtonClickDelegate ( productButton_Click ) ) ;
}
private void productButton_Click ( object sender , EventArgs e )
2010-03-02 17:56:21 +00:00
{
Button button = sender as Button ;
if ( button = = null )
return ;
Guid tag = ( Guid ) button . Tag ;
AddProductToGrid ( tag ) ;
}
2011-01-09 23:36:24 +00:00
private void tableButton_Click ( object sender , EventArgs e )
{
Button button = sender as Button ;
if ( button = = null )
return ;
int tag = ( int ) button . Tag ;
MessageBox . Show ( "Table No " + tag . ToString ( ) ) ;
ChangeFormState ( SaleFormState . Billing ) ;
//AddProductToGrid(tag);
}
2010-03-02 17:56:21 +00:00
private void calculateAmount ( )
{
txtGrossTax . Text = string . Format ( "{0:#0.00}" , bill . Values . Sum ( b = > b . TaxAmount ) ) ;
txtDiscount . Text = string . Format ( "{0:#0.00}" , bill . Values . Sum ( b = > b . DiscountAmount ) ) ;
txtGrossAmount . Text = string . Format ( "{0:#0.00}" , bill . Values . Sum ( b = > b . GrossAmount ) ) ;
txtAmount . Text = string . Format ( "{0:#0.00}" , Math . Round ( bill . Values . Sum ( b = > b . Value ) ) ) ;
bindingSource . DataSource = bill . Values . ToList ( ) ;
dgvProducts . AutoResizeColumns ( DataGridViewAutoSizeColumnsMode . DisplayedCells ) ;
}
private void btnPrintBill_Click ( object sender , EventArgs e )
{
Save ( true ) ;
}
private void btnPrintKot_Click ( object sender , EventArgs e )
{
Save ( false ) ;
}
private void btnMultiPrint_Click ( object sender , EventArgs e )
{
Save ( true ) ;
}
private void btnCancel_Click ( object sender , EventArgs e )
{
if ( bill . Count ! = 0 )
if ( MessageBox . Show ( "Cancel current bill?" , "Cancel bill" , MessageBoxButtons . YesNo , MessageBoxIcon . Question , MessageBoxDefaultButton . Button2 ) = = DialogResult . No )
return ;
ClearBill ( ) ;
}
private SalesBillItemBO CurrentProduct
{
get
{
if ( dgvProducts . Rows . Count = = 0 )
return null ;
SalesBillItemBO product = bill . ElementAt ( dgvProducts . CurrentRow . Index ) . Value ;
return product ;
}
}
private void btnQuantity_Click ( object sender , EventArgs e )
{
if ( dgvProducts . Rows . Count > 0 )
SetQuantity ( CurrentProduct , 0 , false , true ) ;
}
private void btnDiscount_Click ( object sender , EventArgs e )
{
if ( dgvProducts . Rows . Count > 0 )
SetDiscount ( CurrentProduct , - 1 ) ;
}
#endregion
private void SalesForm_Load ( object sender , EventArgs e )
{
ChangeFormState ( SaleFormState . Waiting ) ;
if ( newBillID . HasValue )
{
LoadBill ( newBillID . Value ) ;
ChangeFormState ( SaleFormState . Billing ) ;
}
2011-01-09 23:36:24 +00:00
//ControlFactory.GenerateButtons(ref pnlBilling, new Rectangle(489, 94, 400, 385), 5, 6, 2, new ProductBI().GetUnFilteredProducts(), new ButtonClickDelegate(productButton_Click));
//ControlFactory.GenerateButtons(ref pnlBilling, ref buttonHeads, new Rectangle(889, 0, 80, 688), 1, pageSize, 2, page, new ProductTypeBI().GetProductTypes(), new ButtonClickDelegate(productTypeButton_Click));
//ControlFactory.GenerateButtons(ref pnlBilling, ref buttonHeads, new Rectangle(889, 90, 85, 498), 1, pageSize, 2, page, new ProductTypeBI().GetProductTypes(), new ButtonClickDelegate(productTypeButton_Click));
ControlFactory . GenerateButtons ( ref pnlBilling , ref buttonHeads , new Rectangle ( 390 , 94 , 499 , 385 ) , 6 , 10 , 2 , new FoodTableBI ( ) . GetFoodTables ( ) , new ButtonClickDelegate ( tableButton_Click ) ) ;
2010-03-02 17:56:21 +00:00
}
private void ChangeFormState ( SaleFormState state )
{
2011-01-09 23:36:24 +00:00
pnlBilling . Visible = true ;
2010-03-02 17:56:21 +00:00
}
#region Save Bill
private void Save ( bool print )
{
if ( ( billInfo ! = null ) & & ( new SaleVoucherBI ( ) . IsBillPrinted ( billInfo . VoucherID ) ) & & ( ! Thread . CurrentPrincipal . IsInRole ( "Sales/EditBill" ) ) )
MessageBox . Show ( "You are not authorized to access" ) ;
else
{
if ( bill . Count ! = 0 )
{
Guid ? saved ;
if ( billInfo = = null )
saved = AddNewSale ( print ) ;
else
saved = UpdateSale ( print ) ;
if ( saved . HasValue )
{
if ( newBillID . HasValue )
this . Close ( ) ;
else
PrintBill ( print , saved . Value ) ;
}
ClearBill ( ) ;
}
}
}
private void PrintBill ( bool finalBill , Guid voucherID )
{
if ( ! Thread . CurrentPrincipal . IsInRole ( "Sales/PrintKOT" ) )
{
MessageBox . Show ( "You are not authorized to access" ) ;
return ;
}
if ( ! finalBill )
Accounts . Print . Thermal . PrintWaiterKot ( "KOT" , voucherID , bill . Values . ToList ( ) ) ;
else
{
if ( ! Thread . CurrentPrincipal . IsInRole ( "Sales/PrintBill" ) )
{
MessageBox . Show ( "You are not authorized to access" ) ;
return ;
}
else
{
2011-01-06 07:17:00 +00:00
Accounts . Print . Thermal . PrintBill ( Session . printer ( ) , true , voucherID , bill . Values . ToList ( ) ) ;
2010-03-02 17:56:21 +00:00
Accounts . Print . Thermal . PrintCustomerKot ( "KOT" , voucherID , bill . Values . ToList ( ) ) ;
}
}
}
private Guid ? AddNewSale ( bool finalBill )
{
if ( billInfo ! = null )
{
MessageBox . Show ( "Error in AddNewSale, there is a previous sale in memory" , "Error" ) ;
return null ;
}
if ( btnWaiter . Tag = = null )
btnWaiter . Tag = new WaiterBI ( ) . GetWaiters ( ) [ 0 ] . WaiterID ;
#region SaleVoucher
2011-01-06 07:17:00 +00:00
UserBO user = Session . User ;
2010-03-02 17:56:21 +00:00
SaleVoucherBO saleVoucher = new SaleVoucherBO
{
CustomerID = customer . CustomerID ,
Paid = false ,
//Paid = finalBill,
TableID = txtTableID . Text ,
WaiterID = ( Guid ) btnWaiter . Tag ,
Printed = finalBill ,
Void = false ,
Date = DateTime . Now ,
2011-01-09 23:36:24 +00:00
Narration = "" ,
2010-03-02 17:56:21 +00:00
Ref = "" ,
Type = 'S' ,
UserID = user . UserID
} ;
#endregion
#region Inventories
List < InventoryBO > iList = new SaleVoucherBI ( ) . SaleInventory ( bill . Values , null ) ;
#endregion
new SaleVoucherBI ( ) . Insert ( saleVoucher , iList ) ;
return saleVoucher . VoucherID ;
}
#region TransactionUpdate
private Guid ? UpdateSale ( bool finalBill )
{
if ( btnWaiter . Tag = = null )
btnWaiter . Tag = new WaiterBI ( ) . GetWaiters ( ) [ 0 ] . WaiterID ;
2011-01-06 07:17:00 +00:00
UserBO user = Session . User ;
2010-03-02 17:56:21 +00:00
#region Voucher and SaleVoucher
SaleVoucherBO saleVoucher = new SaleVoucherBO
{
VoucherID = billInfo . VoucherID ,
timestamp = ( byte [ ] ) billInfo . timestamp ,
UserID = billInfo . UserID ,
Date = billInfo . Date ,
CreationDate = DateTime . Now ,
LastEditDate = DateTime . Now ,
Narration = billInfo . Narration ,
Ref = "" ,
Type = 'S' ,
Alarm = billInfo . Alarm ,
BillID = billInfo . BillID ,
CustomerID = customer . CustomerID ,
KotID = billInfo . KotID ,
Paid = billInfo . Paid ,
Printed = billInfo . Printed | | finalBill ,
TableID = txtTableID . Text ,
Void = billInfo . Void ,
VoidReason = billInfo . VoidReason ,
WaiterID = ( Guid ) btnWaiter . Tag ,
SaleTimestamp = ( byte [ ] ) billInfo . SaleTimestamp
} ;
if ( ( ! billInfo . Printed ) & & finalBill )
saleVoucher . Date = null ;
#endregion
#region Inventory
List < InventoryBO > iList = new SaleVoucherBI ( ) . SaleInventory ( bill . Values , billInfo . VoucherID ) ;
#endregion
new SaleVoucherBI ( ) . Update ( saleVoucher , iList ) ;
return saleVoucher . VoucherID ;
}
#endregion
#endregion
private void LoadBillFromTable ( )
{
InputBoxResult result = InputBox . Show ( "Enter Table Number" , "Table" , "0" , InputBox_Validating ) ;
if ( result . OK )
{
txtTableID . Text = result . Text . Trim ( ) ;
if ( ( txtTableID . Text ! = "C" ) & & ( txtTableID . Text ! = "" ) & & ( ! txtTableID . Text . Contains ( "." ) ) )
{
Guid ? tID = new SaleVoucherBI ( ) . GetPendingVoucherID ( txtTableID . Text ) ;
if ( tID . HasValue )
{
LoadBill ( tID . Value ) ;
ChangeFormState ( SaleFormState . Billing ) ;
}
}
else
ClearBill ( ) ;
}
}
private void LoadBill ( Guid voucherID )
{
ClearBill ( ) ;
List < InventoryDisplayBO > iList = new List < InventoryDisplayBO > ( ) ;
new SaleVoucherBI ( ) . GetSaleVoucher ( voucherID , ref billInfo , ref iList ) ;
this . txtBillID . Text = billInfo . BillID ;
this . txtKotID . Text = billInfo . KotID ;
this . txtCreationDate . Text = billInfo . CreationDate . ToString ( "HH:mm dd-MMM-yyyy" ) ;
this . txtDate . Text = billInfo . Date . Value . ToString ( "HH:mm dd-MMM-yyyy" ) ;
this . txtLastEditDate . Text = billInfo . LastEditDate . ToString ( "HH:mm dd-MMM-yyyy" ) ;
this . customer = new CustomerBI ( ) . GetCustomer ( billInfo . CustomerID ) ;
this . btnCustomer . Text = this . customer . Name ;
this . txtTableID . Text = billInfo . TableID ;
this . btnWaiter . Tag = billInfo . WaiterID ;
this . btnWaiter . Text = string . Format ( "{0} - F5" , new WaiterBI ( ) . GetWaiter ( billInfo . WaiterID ) . Name ) ;
foreach ( InventoryDisplayBO inventory in iList )
{
if ( inventory . ComplexProductID . HasValue )
{
BillItemKey key = new BillItemKey ( inventory . ComplexProductID . Value , inventory . Quantity = = 0 ) ;
if ( ! bill . ContainsKey ( key ) )
{
decimal rate = 0 , quantity = 0 ;
string name = "" ;
new SaleVoucherBI ( ) . GetComplexBillInformation ( voucherID , inventory . ComplexProductID . Value , ref rate , ref quantity , ref name ) ;
bill . Add ( key , new SalesBillItemBO
{
productID = inventory . ComplexProductID . Value ,
Discount = inventory . Discount ,
Name = name ,
Price = rate ,
Printed = quantity ,
Quantity = quantity ,
Tax = inventory . Tax ,
} ) ;
}
}
else
{
BillItemKey key = new BillItemKey ( inventory . ProductID , inventory . Quantity = = 0 ) ;
bill . Add ( key , new SalesBillItemBO
{
productID = inventory . ProductID ,
Discount = inventory . Discount ,
Name = inventory . ProductName ,
Price = inventory . Rate ,
Printed = inventory . Quantity ,
Quantity = inventory . Quantity ,
Tax = inventory . Tax ,
} ) ;
}
}
calculateAmount ( ) ;
}
#region Waiting
private void btnStartBill_Click ( object sender , EventArgs e )
{
ChangeFormState ( SaleFormState . Billing ) ;
}
private void btnSelectBill_Click ( object sender , EventArgs e )
{
if ( bsPending . Current ! = null )
{
LoadBill ( ( ( PendingBillsBO ) bsPending . Current ) . voucherID ) ;
ChangeFormState ( SaleFormState . Billing ) ;
}
}
private void dgvPending_CellFormatting ( object sender , DataGridViewCellFormattingEventArgs e )
{
try
{
DataGridView dgv = sender as DataGridView ;
PendingBillsBO data = dgv . Rows [ e . RowIndex ] . DataBoundItem as PendingBillsBO ;
if ( data . Printed )
e . CellStyle . BackColor = Color . LightSlateGray ;
}
catch
{
// Catch and swallow exception when DataGridView attemps to get values for removed rows.
}
}
#endregion
#region Billing
private void btnCustomer_Click ( object sender , EventArgs e )
{
ShowCustomerList ( false ) ;
}
private void ShowCustomerList ( bool reset )
{
if ( ( customer . CustomerID = = new Guid ( "F016CBAD-206C-42C0-BB1D-6006CE57BAB5" ) ) & & ( ! reset ) )
{
using ( SelectCustomer selectCustomer = new SelectCustomer ( new CustomerBI ( ) . GetFilteredCustomers , true ) )
{
selectCustomer . customerEvent + = new CustomerEventHandler ( selectCustomer_customerEvent ) ;
selectCustomer . ShowDialog ( ) ;
if ( selectCustomer . SelectedItem ! = null )
{
customer = selectCustomer . SelectedItem ;
btnCustomer . Text = customer . Name ;
}
else
{
customer = new CustomerBI ( ) . GetCustomer ( new Guid ( "F016CBAD-206C-42C0-BB1D-6006CE57BAB5" ) ) ;
}
}
}
else
{
customer = new CustomerBI ( ) . GetCustomer ( new Guid ( "F016CBAD-206C-42C0-BB1D-6006CE57BAB5" ) ) ;
btnCustomer . Text = customer . Name ;
}
}
CustomerBO selectCustomer_customerEvent ( object sender , CustomerEventArgs e )
{
using ( CustomersForm form = new CustomersForm ( e . CustomerID , e . Phone ) )
{
form . ShowDialog ( ) ;
return form . Customer ;
}
}
#endregion
private void btnVoid_Click ( object sender , EventArgs e )
{
if ( billInfo ! = null )
{
if ( ( billInfo . Printed ) & & ( ! Thread . CurrentPrincipal . IsInRole ( "Sales/VoidPrintedBill" ) ) )
MessageBox . Show ( "Cannot void a paid bill" ) ;
else if ( MessageBox . Show ( "Are you sure you want to void this bill?" , "Void Bill" , MessageBoxButtons . YesNo , MessageBoxIcon . Question , MessageBoxDefaultButton . Button2 ) = = DialogResult . Yes )
{
SelectVoidReason voidReason = new SelectVoidReason ( GetVoidReason , true ) ;
voidReason . ShowDialog ( ) ;
if ( voidReason . SelectedItem ! = null )
{
new SaleVoucherBI ( ) . VoidBill ( billInfo . VoucherID , voidReason . SelectedItem . Description ) ;
ClearBill ( ) ;
}
else
{
MessageBox . Show ( "Please Select a reason if you want to void the bill" , "Bill NOT Voided" , MessageBoxButtons . OK , MessageBoxIcon . Asterisk ) ;
}
}
}
}
private List < StringType > GetVoidReason ( Dictionary < string , string > filter )
{
List < StringType > list = new List < StringType > ( ) ;
list . Add ( new StringType ( "Discount" ) ) ;
list . Add ( new StringType ( "Printing Fault" ) ) ;
list . Add ( new StringType ( "Item Changed" ) ) ;
list . Add ( new StringType ( "Quantity Reduced" ) ) ;
list . Add ( new StringType ( "Costing Bill for Party" ) ) ;
list . Add ( new StringType ( "Cashier Mistake" ) ) ;
list . Add ( new StringType ( "Management Freesale" ) ) ;
list . Add ( new StringType ( "Other" ) ) ;
return list . Where ( i = > i . Description . ToLower ( ) . Contains ( filter [ "Name" ] . ToLower ( ) . Trim ( ) ) ) . ToList ( ) ;
}
private void btnRate_Click ( object sender , EventArgs e )
{
if ( ! Thread . CurrentPrincipal . IsInRole ( "Sales/ChangeRate" ) )
MessageBox . Show ( "You are not authorized to access" ) ;
else
{
if ( dgvProducts . Rows . Count > 0 )
{
SalesBillItemBO product = bill . ElementAt ( dgvProducts . CurrentRow . Index ) . Value ;
decimal rate = 0 ;
InputBoxResult result = InputBox . Show ( "Enter Rate" , "Rate" , product . Price . ToString ( ) , InputBox_Validating ) ;
if ( result . OK )
rate = Convert . ToDecimal ( result . Text ) ;
if ( rate ! = 0 )
{
BillHelperFunctions . SetRate ( product . productID , rate , bill ) ;
calculateAmount ( ) ;
}
}
}
}
private void btnClear_Click ( object sender , EventArgs e )
{
ClearBill ( ) ;
}
private void btnAlarm_Click ( object sender , EventArgs e )
{
if ( bsPending . Current ! = null )
{
PendingBillsBO billAlarm = ( PendingBillsBO ) bsPending . Current ;
InputBoxResult result = InputBox . Show (
string . Format ( "Alarm for Bill {0} Rs. {1}" , billAlarm . BillNo , billAlarm . Amount ) ,
"Alarm" ,
string . Format ( "{0:dd-MMM-yyy HH:mm}" , billAlarm . LastEdited ) ,
InputBox_Validating ) ;
if ( result . OK )
{
DateTime alarmTime ;
if ( result . Text = = string . Empty )
{
new SaleVoucherBI ( ) . SetAlarm ( billAlarm . voucherID , null ) ;
MessageBox . Show ( "Alarm Cleared" , "Alarm Cleared" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
}
else if ( DateTime . TryParseExact ( result . Text , "dd-MMM-yyyy HH:mm" , new CultureInfo ( "en-US" ) , DateTimeStyles . None , out alarmTime ) )
{
new SaleVoucherBI ( ) . SetAlarm ( billAlarm . voucherID , alarmTime ) ;
MessageBox . Show ( "Alarm set" , "Alarm Set" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
}
else
{
MessageBox . Show ( "Alarm NOT set, please try again" , "Alarm NOT Set" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
}
}
}
}
private void dgvProducts_CellFormatting ( object sender , DataGridViewCellFormattingEventArgs e )
{
DataGridView dgv = sender as DataGridView ;
SalesBillItemBO data = dgv . Rows [ e . RowIndex ] . DataBoundItem as SalesBillItemBO ;
if ( data . Printed > 0 )
{
e . CellStyle . SelectionBackColor = Color . HotPink ;
e . CellStyle . BackColor = Color . LightPink ;
}
else
{
e . CellStyle . SelectionBackColor = Color . Green ;
e . CellStyle . BackColor = Color . LightGreen ;
}
}
private void btnWaiter_Click ( object sender , EventArgs e )
{
using ( SelectWaiter selectWaiter = new SelectWaiter ( new WaiterBI ( ) . GetFilteredWaiters , true ) )
{
selectWaiter . waiterEvent + = new WaiterEventHandler ( selectWaiter_waiterEvent ) ;
selectWaiter . ShowDialog ( ) ;
if ( selectWaiter . SelectedItem ! = null )
{
btnWaiter . Text = string . Format ( "{0} - F5" , selectWaiter . SelectedItem . Name ) ;
btnWaiter . Tag = selectWaiter . SelectedItem . WaiterID ;
}
else
{
btnWaiter . Text = "Select Waiter - F5" ;
btnWaiter . Tag = new WaiterBI ( ) . GetWaiters ( ) [ 0 ] . WaiterID ;
}
}
}
WaiterBO selectWaiter_waiterEvent ( object sender , WaiterEventArgs e )
{
WaiterBO waiter = e . Waiter ;
if ( ! Thread . CurrentPrincipal . IsInRole ( "Waiter/Master" ) )
return waiter ;
switch ( e . Action )
{
case 1 : // Add
new WaiterBI ( ) . Insert ( waiter ) ;
e . Handled = true ;
return waiter ;
case 2 : // Edit
new WaiterBI ( ) . Update ( waiter ) ;
e . Handled = true ;
return waiter ;
case 3 : // Delete
e . Handled = new WaiterBI ( ) . Delete ( waiter . WaiterID ) ;
return new WaiterBI ( ) . GetWaiter ( 1 ) ;
default :
throw new ArgumentException ( ) ;
}
}
2011-01-09 23:36:24 +00:00
#region Dynamic Buttons
private void btnPrevious_Click ( object sender , EventArgs e )
{
page - - ;
var list = new ProductTypeBI ( ) . GetProductTypes ( ) ;
if ( page = = - 1 )
page = 0 ;
ControlFactory . GenerateButtons ( ref pnlBilling , ref buttonHeads , new Rectangle ( 889 , 90 , 85 , 498 ) , 1 , pageSize , 2 , page , list , new ButtonClickDelegate ( productTypeButton_Click ) ) ;
}
2010-03-02 17:56:21 +00:00
2011-01-09 23:36:24 +00:00
private void btnNext_Click ( object sender , EventArgs e )
2010-03-02 17:56:21 +00:00
{
2011-01-09 23:36:24 +00:00
page + + ;
var list = new ProductTypeBI ( ) . GetProductTypes ( ) ;
int pages = Convert . ToInt32 ( Math . Ceiling ( Convert . ToDouble ( list . Count ) / Convert . ToDouble ( pageSize ) ) ) ;
if ( page = = pages )
page - - ;
2010-03-02 17:56:21 +00:00
2011-01-09 23:36:24 +00:00
ControlFactory . GenerateButtons ( ref pnlBilling , ref buttonHeads , new Rectangle ( 889 , 90 , 85 , 498 ) , 1 , pageSize , 2 , page , list , new ButtonClickDelegate ( productTypeButton_Click ) ) ;
2010-03-02 17:56:21 +00:00
}
2011-01-09 23:36:24 +00:00
#endregion
2010-03-02 17:56:21 +00:00
}
}