コード例 #1
0
        private void PrintBill(long Id)
        {
            Order order = db.Orders.Find(Id);
            ICollection <OrderedProduct> orderedProducts = order.OrderedProducts.Where(i => i.Status == 1).ToList();

            if (orderedProducts != null && orderedProducts.Count > 0)
            {
                OrderedProduct firstOrderedProduct = order.OrderedProducts.FirstOrDefault();
                string         createdBy;
                if (firstOrderedProduct != null)
                {
                    createdBy = Membership.GetUser(order.OrderedProducts.First().CreatedBy).UserName;
                }
                else
                {
                    createdBy = Membership.GetUser().UserName;
                }

                string forcePrinter = string.Empty;

                if (Request.Cookies["printerfullname"] != null)
                {
                    //var encryptedBytes = Convert.FromBase64String(Request.Cookies["printerfullname"].Value);
                    //var decryptedBytes = System.Security.Cryptography.ProtectedData.Unprotect(encryptedBytes, null, System.Security.Cryptography.DataProtectionScope.CurrentUser);
                    forcePrinter = HttpUtility.UrlDecode(Request.Cookies["printerfullname"].Value);
                }

                if (string.IsNullOrEmpty(forcePrinter) || forcePrinter.Equals("Dynamic"))
                {
                    forcePrinter = ConfigurationManager.AppSettings["CommonPrinter"].ToString();
                }

                PrintingSystem.ReceiptPrint rcpt = new PrintingSystem.ReceiptPrint();
                rcpt.PrinterName = forcePrinter;

                rcpt.TotalAmount     = order.OrderedProducts.Where(op => op.Status == 1).Sum(op => (op.Quantity * op.Price));
                rcpt.OrderNo         = Id;
                rcpt.CreatedBy       = createdBy;
                rcpt.Seats           = order.Seats;
                rcpt.CreateDate      = order.CreatedDate.Value.ToString("dd-MM-yyyy HH:mm");
                rcpt.OrderedProducts = orderedProducts;

                Task.Run(() => rcpt.print());
                //.print();
            }
        }
コード例 #2
0
ファイル: OrderController.cs プロジェクト: PCDCOM/RT
        private void PrintBill(long Id)
        {
            Order  order     = db.Orders.Find(Id);
            string createdBy = Membership.GetUser(order.OrderedProducts.First().CreatedBy).UserName;
            ICollection <OrderedProduct> orderedProducts = order.OrderedProducts.Where(i => i.Status == 1).ToList();

            if (orderedProducts != null && orderedProducts.Count > 0)
            {
                string seats = order.Seats;

                char   firstSeatNo = seats.FirstOrDefault();
                bool   anyDinining = order.OrderedProducts.Where(i => i.Status == 1).Any(i => i.Type == 0);
                string printername = getPrinterName(anyDinining, firstSeatNo);
                //TOD: Need to change this hardcode to dynamic
                if (printername.StartsWith("Datecs"))
                {
                    PrintingSystem.MiniReceiptPrint rcpt = new PrintingSystem.MiniReceiptPrint();
                    rcpt.Seats       = seats;
                    rcpt.PrinterName = printername;
                    rcpt.TotalAmount = order.OrderedProducts.Where(op => op.Status == 1).Sum(op => (op.Quantity * op.Price));
                    rcpt.OrderNo     = Id;
                    rcpt.CreatedBy   = createdBy;

                    rcpt.CreateDate      = order.CreatedDate.Value.ToString("dd-MM-yyyy HH:mm");
                    rcpt.OrderedProducts = orderedProducts;
                    Task.Run(() => rcpt.print());
                }
                else
                {
                    PrintingSystem.ReceiptPrint rcpt = new PrintingSystem.ReceiptPrint();
                    rcpt.Seats       = seats;
                    rcpt.PrinterName = printername;
                    rcpt.TotalAmount = order.OrderedProducts.Where(op => op.Status == 1).Sum(op => (op.Quantity * op.Price));
                    rcpt.OrderNo     = Id;
                    rcpt.CreatedBy   = createdBy;

                    rcpt.CreateDate      = order.CreatedDate.Value.ToString("dd-MM-yyyy HH:mm");
                    rcpt.OrderedProducts = orderedProducts;
                    Task.Run(() => rcpt.print());
                }
            }
        }