private void button1_Click(object sender, EventArgs e) { // mark paid if (dataGridViewOrders.SelectedRows.Count > 0) { var ret = MessageBox.Show("Are you sure you want to mark paid this Order?", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (ret != System.Windows.Forms.DialogResult.OK) { return; } OrderKassa order = (OrderKassa)dataGridViewOrders.SelectedRows[0].DataBoundItem; if (!order.IsComplete) { var itemOrder = ctx.OrderKassas.First(m => m.OrderID == order.OrderID); itemOrder.IsComplete = true; ctx.SubmitChanges(); } if (_show == 1) { this.btnShowOrder_Click(sender, e); } else { this.btnShowToday_Click(sender, e); } MessageBox.Show("Done"); } }
private void btnDeleteOrder_Click(object sender, EventArgs e) { if (dataGridViewOrders.SelectedRows.Count > 0) { //ctx.DetectChanges(); OrderKassa order = (OrderKassa)dataGridViewOrders.SelectedRows[0].DataBoundItem; var orderdetails = from a in ctx.OrderDetails where a.OrderID == order.OrderID select a; List <OrderDetail> orderDetails = new List <OrderDetail>(orderdetails.ToArray()); foreach (OrderDetail orderDetail in orderDetails) { ctx.OrderDetails.DeleteOnSubmit(orderDetail); ctx.SubmitChanges(); } ctx.OrderKassas.DeleteOnSubmit(order); ctx.SubmitChanges(); if (_show == 1) { this.btnShowOrder_Click(sender, e); } else { this.btnShowToday_Click(sender, e); } MessageBox.Show("Done"); } }
private void button2_Click(object sender, EventArgs e) { //print selected without btw if (dataGridViewOrders.SelectedRows.Count > 0) { OrderKassa order = (OrderKassa)dataGridViewOrders.SelectedRows[0].DataBoundItem; Helper.PrintOrder(this.ctx, order, false, false); } }
private void btnClose_Click(object sender, EventArgs e) { POSDataContext db = new POSDataContext(); //close table var ret = MessageBox.Show("Are you sure you want to close this table?", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (ret != System.Windows.Forms.DialogResult.OK) { return; } int tableId = SelectedTable.TableID; var order = from a in db.OrderKassas where a.OrderID == _currentOrderId && a.TableID == tableId select a; if (order.Count() > 0) { OrderKassa itemOrder = order.ToArray()[0]; var tab = db.TableSeats.First(m => m.TableID == tableId); tab.TableStatus = "Free"; var details = from a in db.OrderDetails where a.OrderID == itemOrder.OrderID select a; decimal total = 0; if (details.Count() > 0) { foreach (var detail in details) { if (detail.CustomMenuPrice > 0) { total = total + detail.Quantity * detail.CustomMenuPrice; } else { total = total + detail.Quantity * detail.MenuCard.Price; } } itemOrder.OrderTotal = total; itemOrder.IsComplete = false; itemOrder.CompletedDate = DateTime.Now; } else { db.OrderKassas.DeleteOnSubmit(itemOrder); } db.SubmitChanges(); this.OnBackToTablesHandler(e); } else { MessageBox.Show("Order was not found for this table"); } }
private void dataGridViewOrders_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (this.dataGridViewOrders.Columns[e.ColumnIndex].Name == "tableIDDataGridViewTextBoxColumn") { OrderKassa order = (OrderKassa)this.dataGridViewOrders.Rows[e.RowIndex].DataBoundItem; e.Value = order.TableSeat.TableName; } //orderTotalDataGridViewTextBoxColumn if (this.dataGridViewOrders.Columns[e.ColumnIndex].Name == "orderTotalDataGridViewTextBoxColumn") { if (Convert.ToDecimal(e.Value) == 0 || e.Value == null) { e.Value = "0"; } } }
private void Initialize() { //PopulateMenus(); POSDataContext db = new POSDataContext(); panelRightContent.Controls.Clear(); TableSeat seat = SelectedTable; //ctx.DetectChanges(); ctx.SubmitChanges(); if (seat.TableStatus.ToLower() == "occupied") { int id = seat.TableID; var order = (from a in db.OrderKassas where (a.TableID == id && a.IsComplete == false && a.OrderTotal == 0) select a).ToList <OrderKassa>().LastOrDefault(); if (order != null) { _currentOrderId = order.OrderID; OrderDetailPopulate(order.OrderID); _currentOrder = order; txtNamaPemesan.Text = order.Name; } } else { int id = seat.TableID; var table = from a in ctx.TableSeats where a.TableID == id select a; if (table.Count() > 0) { var item = table.ToArray()[0]; item.TableStatus = "Occupied"; OrderKassa order = new OrderKassa(); order.OrderDate = DateTime.Now; order.IsComplete = false; order.Remarks = string.Empty; order.TableID = id; order.CompletedDate = DateTime.Now.AddDays(-1); ctx.OrderKassas.InsertOnSubmit(order); ctx.SubmitChanges(); _currentOrderId = order.OrderID; _currentOrder = order; } } }
public static void PrintOrder(POSDataContext ctx, OrderKassa order, bool btw, bool isKitchen, bool bni = false) { var orderdetails = from a in ctx.OrderDetails where a.OrderID == order.OrderID select a; List <OrderDetail> orderDetails = new List <OrderDetail>(orderdetails.ToArray()); float fontSize = Convert.ToSingle(ConfigurationManager.AppSettings["FontSize"]); Font printFont = new Font("Arial", fontSize); PrintDocument pd = new PrintDocument(); pd.PrinterSettings.PrinterName = ConfigurationManager.AppSettings["PrinterName"]; if (isKitchen) { pd.PrinterSettings.PrinterName = ConfigurationManager.AppSettings["PrinterNameKitchen"]; } string tableNameHeader = order.TableSeat.TableName + ": " + order.Name; string dateHeader = "\nTanggal : " + order.OrderDate.ToLongDateString(); decimal grandTotal = 0; string strBillSubtotal = ""; string strBillSubtotalAmount = ""; string strBillBTW = ""; string strBillBTWAmount = ""; string strBillDrink = ""; string strBillDrinkAmount = ""; string strBillBTWDrink = ""; string strBillBTWDrinkAmount = ""; string strBillTotal = ""; string strBillTotalAmount = ""; string strBillFooter = "Terima kasih dan sampai jumpa"; string strBillDiskon = ""; string strBillDiskonAmount = ""; pd.PrintPage += (s, ev) => { float linesPerPage = 0; //not using //float yPos = 0; //int count = 0; float leftMargin = 10; float topMargin = 10; string currentLine = null; Pen p = new Pen(Color.White, 1); float lineHeight = printFont.GetHeight(ev.Graphics); int intLineHeight = (int)lineHeight; // Calculate the number of lines per page. linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics); StringFormat sfHeader = new StringFormat(); sfHeader.Alignment = StringAlignment.Center; StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Near; StringFormat sfFar = new StringFormat(); sfFar.Alignment = StringAlignment.Far; // header Rectangle rectHeader = new Rectangle((int)leftMargin, (int)topMargin, 260, 50); Rectangle rectHeader2 = new Rectangle((int)leftMargin, rectHeader.Height + 20, 260, 35); ev.Graphics.DrawString("Meat Compiler", printFont, Brushes.Black, rectHeader, sfHeader); ev.Graphics.DrawString("\nTel: 0817-6328-000", printFont, Brushes.Black, rectHeader, sfHeader); ev.Graphics.DrawString("\n\nwww.meatcompiler.id", printFont, Brushes.Black, rectHeader, sfHeader); ev.Graphics.DrawString(tableNameHeader, printFont, Brushes.Black, rectHeader2, sf); ev.Graphics.DrawString(dateHeader, printFont, Brushes.Black, rectHeader2, sf); ev.Graphics.DrawRectangle(p, rectHeader); ev.Graphics.DrawRectangle(p, rectHeader2); int topMarginBody1 = 100; ev.Graphics.DrawLine(Pens.Black, (int)leftMargin, topMarginBody1, (int)leftMargin + 260, topMarginBody1); decimal orderTotal = 0; decimal orderTotalDrink = 0; int topMarginBody = topMarginBody1 + 10; foreach (OrderDetail orderDetail in orderDetails) { Rectangle rectBodyLeft = new Rectangle((int)leftMargin, topMarginBody, 200, intLineHeight); Rectangle rectBodyright = new Rectangle(rectBodyLeft.Width + 5 - 40, topMarginBody, 100, intLineHeight); string menuNameBill = ""; string menuAmountBill = ""; if (orderDetail.CustomMenuPrice > 0) { orderTotal += orderDetail.CustomMenuPrice * orderDetail.Quantity; menuNameBill = orderDetail.Quantity + "x " + orderDetail.CustomMenuName; menuAmountBill = Helper.FormatPrice(orderDetail.CustomMenuPrice * orderDetail.Quantity); } else { orderTotal += orderDetail.MenuCard.Price * orderDetail.Quantity; menuNameBill = orderDetail.Quantity + "x " + orderDetail.MenuCard.MenuName; menuAmountBill = Helper.FormatPrice(orderDetail.MenuCard.Price * orderDetail.Quantity); } ev.Graphics.DrawString(menuNameBill, printFont, Brushes.Black, rectBodyLeft, sf); ev.Graphics.DrawString(menuAmountBill, printFont, Brushes.Black, rectBodyright, sfFar); ev.Graphics.DrawRectangle(p, rectBodyLeft); ev.Graphics.DrawRectangle(p, rectBodyright); topMarginBody = topMarginBody + intLineHeight + 5; } grandTotal = orderTotalDrink + orderTotal; strBillTotal = "Total "; strBillTotalAmount = Helper.FormatPrice(grandTotal); int topMarginFooter1 = topMarginBody + 15; // bodyHeight + 5; int topMarginFooter = topMarginFooter1 + 15; int topMarginFooterFinal = topMarginFooter; ev.Graphics.DrawLine(Pens.Black, (int)leftMargin, topMarginFooter1, (int)leftMargin + 260, topMarginFooter1); POSDataContext db = new POSDataContext(); var theOrder = db.OrderKassas.FirstOrDefault(x => x.OrderID == order.OrderID); if (theOrder.Discount > 0) { strBillSubtotal = "Subtotal: "; strBillSubtotalAmount = Helper.FormatPrice(grandTotal); int subTotalTopMargin = topMarginFooter + intLineHeight + 5; Rectangle rectFooterSubtotal = new Rectangle((int)leftMargin, subTotalTopMargin, 200, intLineHeight); Rectangle rectFooterSubtotalAmount = new Rectangle(rectFooterSubtotal.Width + 5 - 40, topMarginFooter, 100, intLineHeight); ev.Graphics.DrawString(strBillSubtotal, printFont, Brushes.Black, rectFooterSubtotal, sf); ev.Graphics.DrawString(strBillSubtotalAmount, printFont, Brushes.Black, rectFooterSubtotalAmount, sfFar); strBillDiskon = "Diskon: "; strBillDiskonAmount = (grandTotal * (order.Discount / 100)).ToString("N0"); int diskonTopMargin = subTotalTopMargin + intLineHeight + 5; grandTotal = grandTotal - (grandTotal * (order.Discount / 100)); strBillTotalAmount = Helper.FormatPrice(grandTotal); Rectangle rectFooterDiskon = new Rectangle((int)leftMargin, diskonTopMargin, 200, intLineHeight); Rectangle rectFooterDiskonAmount = new Rectangle(rectFooterDiskon.Width + 5 - 40, diskonTopMargin, 100, intLineHeight); ev.Graphics.DrawString(strBillDiskon, printFont, Brushes.Black, rectFooterDiskon, sf); ev.Graphics.DrawString(strBillDiskonAmount, printFont, Brushes.Black, rectFooterDiskonAmount, sfFar); } if (bni) { decimal cardChargeAmount = grandTotal * (decimal)(0.02); decimal subTotal = grandTotal; strBillSubtotal = "Subtotal: "; strBillSubtotalAmount = Helper.FormatPrice(subTotal); strBillBTW = "Card Charge 2%: "; strBillBTWAmount = Helper.FormatPrice(cardChargeAmount); Rectangle rectFooterSubtotal = new Rectangle((int)leftMargin, topMarginFooter, 200, intLineHeight); Rectangle rectFooterSubtotalAmount = new Rectangle(rectFooterSubtotal.Width + 5 - 40, topMarginFooter, 100, intLineHeight); int btwTopMargin = topMarginFooter + intLineHeight + 5; Rectangle rectFooterBTW = new Rectangle((int)leftMargin, btwTopMargin, 200, intLineHeight); Rectangle rectFooterBTWAmount = new Rectangle(rectFooterBTW.Width + 5 - 40, btwTopMargin, 100, intLineHeight); ev.Graphics.DrawString(strBillSubtotal, printFont, Brushes.Black, rectFooterSubtotal, sf); ev.Graphics.DrawString(strBillSubtotalAmount, printFont, Brushes.Black, rectFooterSubtotalAmount, sfFar); ev.Graphics.DrawString(strBillBTW, printFont, Brushes.Black, rectFooterBTW, sf); ev.Graphics.DrawString(strBillBTWAmount, printFont, Brushes.Black, rectFooterBTWAmount, sfFar); ev.Graphics.DrawRectangle(p, rectFooterSubtotal); ev.Graphics.DrawRectangle(p, rectFooterSubtotalAmount); ev.Graphics.DrawRectangle(p, rectFooterBTW); ev.Graphics.DrawRectangle(p, rectFooterBTWAmount); topMarginFooterFinal = btwTopMargin + intLineHeight + 5; grandTotal = subTotal + cardChargeAmount; strBillTotalAmount = Helper.FormatPrice(grandTotal); } if (btw) { decimal btwAmount = orderTotal * (decimal)((decimal)6 / (decimal)106); decimal subTotal = orderTotal - btwAmount; strBillSubtotal = "Subtotal: "; strBillSubtotalAmount = Helper.FormatPrice(subTotal); strBillBTW = "BTW 6%: "; strBillBTWAmount = Helper.FormatPrice(btwAmount); Rectangle rectFooterSubtotal = new Rectangle((int)leftMargin, topMarginFooter, 200, intLineHeight); Rectangle rectFooterSubtotalAmount = new Rectangle(rectFooterSubtotal.Width + 5, topMarginFooter, 60, intLineHeight); int btwTopMargin = topMarginFooter + intLineHeight + 5; Rectangle rectFooterBTW = new Rectangle((int)leftMargin, btwTopMargin, 200, intLineHeight); Rectangle rectFooterBTWAmount = new Rectangle(rectFooterBTW.Width + 5, btwTopMargin, 60, intLineHeight); ev.Graphics.DrawString(strBillSubtotal, printFont, Brushes.Black, rectFooterSubtotal, sf); ev.Graphics.DrawString(strBillSubtotalAmount, printFont, Brushes.Black, rectFooterSubtotalAmount, sfFar); ev.Graphics.DrawString(strBillBTW, printFont, Brushes.Black, rectFooterBTW, sf); ev.Graphics.DrawString(strBillBTWAmount, printFont, Brushes.Black, rectFooterBTWAmount, sfFar); ev.Graphics.DrawRectangle(p, rectFooterSubtotal); ev.Graphics.DrawRectangle(p, rectFooterSubtotalAmount); ev.Graphics.DrawRectangle(p, rectFooterBTW); ev.Graphics.DrawRectangle(p, rectFooterBTWAmount); topMarginFooterFinal = btwTopMargin + intLineHeight + 5; if (orderTotalDrink > 0) { decimal btwAmountDrink = orderTotalDrink * (decimal)((decimal)19 / (decimal)119); decimal subTotalDrink = orderTotalDrink - btwAmountDrink; strBillDrink = "Alcoholic Drink: "; strBillDrinkAmount = Helper.FormatPrice(subTotalDrink); strBillBTWDrink = "BTW 19%: "; strBillBTWDrinkAmount = Helper.FormatPrice(btwAmountDrink); Rectangle rectFooterDrink = new Rectangle((int)leftMargin, topMarginFooterFinal, 200, intLineHeight); Rectangle rectFooterDrinkAmount = new Rectangle(rectFooterDrink.Width + 5, topMarginFooterFinal, 60, intLineHeight); topMarginFooterFinal = topMarginFooterFinal + intLineHeight + 5; Rectangle rectFooterBTWDrink = new Rectangle((int)leftMargin, topMarginFooterFinal, 200, intLineHeight); Rectangle rectFooterBTWDrinkAmount = new Rectangle(rectFooterBTW.Width + 5, topMarginFooterFinal, 60, intLineHeight); ev.Graphics.DrawString(strBillDrink, printFont, Brushes.Black, rectFooterDrink, sf); ev.Graphics.DrawString(strBillDrinkAmount, printFont, Brushes.Black, rectFooterDrinkAmount, sfFar); ev.Graphics.DrawString(strBillBTWDrink, printFont, Brushes.Black, rectFooterBTWDrink, sf); ev.Graphics.DrawString(strBillBTWDrinkAmount, printFont, Brushes.Black, rectFooterBTWDrinkAmount, sfFar); ev.Graphics.DrawRectangle(p, rectFooterDrink); ev.Graphics.DrawRectangle(p, rectFooterDrinkAmount); ev.Graphics.DrawRectangle(p, rectFooterBTWDrink); ev.Graphics.DrawRectangle(p, rectFooterBTWDrinkAmount); topMarginFooterFinal = topMarginFooterFinal + intLineHeight + 5; } } Rectangle rectFooterTotal = new Rectangle((int)leftMargin, topMarginFooterFinal, 200, intLineHeight); Rectangle rectFooterTotalAmount = new Rectangle(rectFooterTotal.Width + 5 - 40, topMarginFooterFinal, 100, intLineHeight); Rectangle rectFooterClose = new Rectangle((int)leftMargin, topMarginFooterFinal + intLineHeight + 30, 260, intLineHeight); ev.Graphics.DrawString(strBillTotal, printFont, Brushes.Black, rectFooterTotal, sf); ev.Graphics.DrawString(strBillTotalAmount, printFont, Brushes.Black, rectFooterTotalAmount, sfFar); ev.Graphics.DrawString(strBillFooter, printFont, Brushes.Black, rectFooterClose, sfHeader); ev.Graphics.DrawRectangle(p, rectFooterTotal); ev.Graphics.DrawRectangle(p, rectFooterTotalAmount); ev.Graphics.DrawRectangle(p, rectFooterClose); // If more lines exist, print another page. if (currentLine != null) { ev.HasMorePages = true; currentLine = null; } else { ev.HasMorePages = false; } }; pd.EndPrint += (s, ev) => { }; pd.Print(); }