/* public void generateBarcode(string numberOrder) * { * Barcode barcodeAPI = new Barcode(); * * // Define basic settings of the image * int imageWidth = 290; * int imageHeight = 120; * Color foreColor = Color.Black; * Color backColor = Color.Transparent; * * * // Generate the barcode with your settings * Image barcodeImage = barcodeAPI.Encode(TYPE.ISBN, numberOrder, foreColor, backColor, imageWidth, imageHeight); * * // Store image in some path with the desired format * // barcodeImage.Save(@"C:\Users\sdkca\Desktop\isbn_example.png", ImageFormat.Png); * * } */ public void printReturnOrder(dynamic returnorder) { MessageBox.Show(templateDir); string id = returnorder["id"]; string salesorderNo = ""; if (returnorder["salesorder_no"] != null) { salesorderNo = returnorder["salesorder_no"]; } string barcode = ""; if (returnorder["returnorder_no"] != null) { barcode = '*' + returnorder["returnorder_no"] + '*'; } string returnorderNo = ""; if (returnorder["returnorder_no"] != null) { returnorderNo = returnorder["returnorder_no"]; } string orderTime = ""; if (returnorder["order_datetime"] != null) { orderTime = returnorder["order_datetime"]; } /* float netAmount = returnorder["net_amount"]; * float amount = returnorder["amount"]; * float discount = returnorder["discount"];*/ float rePayAmount = returnorder["repay_amount"]; string contactName = ""; if (returnorder["contact_name"] != null) { contactName = returnorder["contact_name"]; } string contactPhone = ""; if (returnorder["contact_phone"] != null) { contactPhone = returnorder["contact_phone"]; } string cashier = returnorder["created_by_name"]; List <ReturnOrderItem> items = new List <ReturnOrderItem>(); foreach (var element in returnorder["items"]) { ReturnOrderItem item = new ReturnOrderItem(); item.id = element["id"]; item.item_id = element["item_id"]; item.item_name = element["item_name"]; item.list_price = element["list_price"]; item.quantity = element["quantity"]; item.net_amount = element["net_amount"]; // item.amount = element["amount"]; //item.discount = element["discount"]; items.Add(item); } var cr = new ReportDocument(); cr.Load(templateDir + "\\ReturnOrderTemplate.rpt"); cr.SetDataSource(items); cr.SetParameterValue("order_time", orderTime); cr.SetParameterValue("saleorder_no", salesorderNo); cr.SetParameterValue("return_order_no", returnorderNo); cr.SetParameterValue("cashier", cashier); cr.SetParameterValue("repay_amount", rePayAmount); cr.SetParameterValue("contact_name", contactName); cr.SetParameterValue("contact_phone", contactPhone); cr.SetParameterValue("barcode", barcode); cr.SetParameterValue("workstation_name", "LalaMart Văn Phú"); cr.SetParameterValue("address", "09LK13 KĐT mới Văn Phú, Phường Phú La, Hà Đông"); cr.SetParameterValue("hotline", "1900112233"); System.Drawing.Printing.PrinterSettings printSetings = new System.Drawing.Printing.PrinterSettings(); System.Drawing.Printing.PageSettings pageSetings = new System.Drawing.Printing.PageSettings(); // Console.WriteLine("====================Printer_Name: " + salesorder["printer"]["name"]); printSetings.PrinterName = "SLK-TS100"; cr.PrintToPrinter(printSetings, pageSetings, false); //cr.Refresh(); cr.Clone(); cr.Dispose(); }
public void ReceiveShipment(int orderid, List <TransactionItemPOCO> received, List <RejectedItemPOCO> rejected) { List <string> errors = new List <string>(); using (var context = new RaceContext()) { var closed = (from x in context.Orders where x.OrderID == orderid select x.Closed).FirstOrDefault(); if (closed) { errors.Add("You cannot receive a closed order"); } else if (received.Any(x => x.ItemQuantity < 0)) { errors.Add("You cannot have a negative received amount"); } else { int newrecieveorderid = context.ReceiveOrders.Select(x => x.ReceiveOrderID).Max(); newrecieveorderid++; var recieveorderlist = new List <ReceiveOrderItem>(); var returnorderlist = new List <ReturnOrderItem>(); foreach (var item in received) { int newrecieveorderitemid = context.ReceiveOrderItems.Select(x => x.ReceiveOrderItemID).Max(); newrecieveorderid++; int orderDetailID = (from x in context.Products from y in x.OrderDetails where x.ItemName == item.ItemName && y.OrderID == orderid select y.OrderDetailID).FirstOrDefault(); recieveorderlist.Add(new ReceiveOrderItem() { ReceiveOrderItemID = newrecieveorderitemid, ReceiveOrderID = newrecieveorderid, OrderDetailID = orderDetailID, ItemQuantity = item.ItemQuantity, OrderDetail = (from x in context.OrderDetails where x.OrderDetailID == orderDetailID select x).FirstOrDefault(), ReceiveOrder = (from x in context.ReceiveOrders where x.ReceiveOrderID == newrecieveorderid select x).FirstOrDefault() }); } if (rejected.Count() > 0) { foreach (var item in rejected) { int newreturnorderitemid = context.ReturnOrderItems.Select(x => x.ReturnOrderItemID).Max(); newreturnorderitemid++; int orderDetailID = (from x in context.Products from y in x.OrderDetails where x.ItemName == item.ItemName && y.OrderID == orderid select y.OrderDetailID).FirstOrDefault(); returnorderlist.Add(new ReturnOrderItem() { ReturnOrderItemID = newreturnorderitemid, ReceiveOrderID = newrecieveorderid, OrderDetailID = orderDetailID, UnOrderedItem = null, ItemQuantity = item.ItemQuantity, Comment = item.Reason, VendorProductID = null, OrderDetail = (from x in context.OrderDetails where x.OrderDetailID == orderDetailID select x).FirstOrDefault(), ReceiveOrder = (from x in context.ReceiveOrders where x.ReceiveOrderID == newrecieveorderid select x).FirstOrDefault() }); } } ReceiveOrder receiveOrder = new ReceiveOrder { ReceiveOrderID = newrecieveorderid, OrderID = orderid, ReceiveDate = DateTime.Now, EmployeeID = 56, Employee = (from x in context.Employees where x.EmployeeID == 56 select x).FirstOrDefault(), Order = (from x in context.Orders where x.OrderID == orderid select x).FirstOrDefault(), ReceiveOrderItems = recieveorderlist, ReturnOrderItems = returnorderlist }; context.ReceiveOrders.Add(receiveOrder); foreach (var item in recieveorderlist.ToList()) { ReceiveOrderItem receiveOrderItem = new ReceiveOrderItem { ReceiveOrderItemID = item.ReceiveOrderItemID, ReceiveOrderID = item.ReceiveOrderID, OrderDetailID = item.OrderDetailID, ItemQuantity = item.ItemQuantity, OrderDetail = item.OrderDetail, ReceiveOrder = item.ReceiveOrder }; var query = (from x in context.OrderDetails join prod in context.Products on x.ProductID equals prod.ProductID where x.OrderDetailID == receiveOrderItem.OrderDetailID select prod).FirstOrDefault(); query.QuantityOnHand = query.QuantityOnHand + receiveOrderItem.ItemQuantity; query.QuantityOnOrder = query.QuantityOnOrder - receiveOrderItem.ItemQuantity; } if (returnorderlist.Count > 0) { foreach (var item in returnorderlist.ToList()) { ReturnOrderItem returnOrderItem = new ReturnOrderItem() { ReturnOrderItemID = item.ReturnOrderItemID, ReceiveOrderID = item.ReceiveOrderID, OrderDetailID = item.OrderDetailID, UnOrderedItem = item.UnOrderedItem, ItemQuantity = item.ItemQuantity, Comment = item.Comment, VendorProductID = item.VendorProductID, OrderDetail = item.OrderDetail, ReceiveOrder = item.ReceiveOrder }; var query = (from x in context.OrderDetails join prod in context.Products on x.ProductID equals prod.ProductID where x.OrderDetailID == returnOrderItem.OrderDetailID select prod).FirstOrDefault(); } } context.SaveChanges(); } if (errors.Count > 0) { throw new BusinessRuleException("Receive Shipment", errors); } } }