Esempio n. 1
0
 private void btnPrintBill_Click(object sender, EventArgs e)
 {
     if (dgvGoodsOrder.Rows.Count > 0)
     {
         foreach (DataGridViewRow dr in dgvGoodsOrder.Rows)
         {
             if (dr.Cells["OrderDetailsID"].Value == null)
             {
                 MessageBox.Show("存在新单,不能印单!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             }
         }
         if (ConstantValuePool.BizSettingConfig.printConfig.Enabled)
         {
             //打印
             PrintData printData = new PrintData();
             printData.ShopName = ConstantValuePool.CurrentShop.ShopName;
             printData.DeskName = _salesOrder.order.DeskName;
             printData.PersonNum = "1";
             printData.PrintTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
             printData.EmployeeNo = ConstantValuePool.CurrentEmployee.EmployeeNo;
             printData.TranSequence = _salesOrder.order.TranSequence.ToString();
             printData.ShopAddress = ConstantValuePool.CurrentShop.RunAddress;
             printData.Telephone = ConstantValuePool.CurrentShop.Telephone;
             printData.GoodsOrderList = new List<GoodsOrder>();
             foreach (DataGridViewRow dr in dgvGoodsOrder.Rows)
             {
                 GoodsOrder goodsOrder = new GoodsOrder();
                 goodsOrder.GoodsName = dr.Cells["GoodsName"].Value.ToString();
                 decimal itemQty = Convert.ToDecimal(dr.Cells["GoodsNum"].Value);
                 decimal totalSellPrice = Convert.ToDecimal(dr.Cells["GoodsPrice"].Value);
                 goodsOrder.GoodsNum = itemQty.ToString("f1");
                 goodsOrder.SellPrice = (totalSellPrice/itemQty).ToString("f2");
                 goodsOrder.TotalSellPrice = totalSellPrice.ToString("f2");
                 goodsOrder.TotalDiscount = Convert.ToDecimal(dr.Cells["GoodsDiscount"].Value).ToString("f2");
                 goodsOrder.Unit = dr.Cells["ItemUnit"].Value.ToString();
                 printData.GoodsOrderList.Add(goodsOrder);
             }
             printData.CustomerPhone = this.txtTelephone.Text.Trim();
             printData.CustomerName = this.txtName.Text.Trim();
             printData.DeliveryAddress = this.txtAddress.Text.Trim();
             printData.Remark = string.Empty;
             printData.DeliveryEmployeeName = string.Empty;
             string paperWidth = ConstantValuePool.BizSettingConfig.printConfig.PaperWidth;
             if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.DRIVER)
             {
                 string printerName = ConstantValuePool.BizSettingConfig.printConfig.Name;
                 string paperName = ConstantValuePool.BizSettingConfig.printConfig.PaperName;
                 DriverOrderPrint printer = DriverOrderPrint.GetInstance(printerName, paperName, paperWidth);
                 if (_salesOrder.order.EatType == (int) EatWayType.Takeout)
                 {
                     printer.DoPrintOrder(printData);
                 }
                 else
                 {
                     printer.DoPrintDeliveryOrder(printData);
                 }
             }
             if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.COM)
             {
                 string port = ConstantValuePool.BizSettingConfig.printConfig.Name;
                 if (port.Length > 3)
                 {
                     if (port.Substring(0, 3).ToUpper() == "COM")
                     {
                         string portName = port.Substring(0, 4).ToUpper();
                         InstructionOrderPrint printer = new InstructionOrderPrint(portName, 9600, Parity.None, 8, StopBits.One, paperWidth);
                         if (_salesOrder.order.EatType == (int) EatWayType.Takeout)
                         {
                             printer.DoPrintOrder(printData);
                         }
                         else
                         {
                             printer.DoPrintDeliveryOrder(printData);
                         }
                     }
                 }
             }
             if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.ETHERNET)
             {
                 string ipAddress = ConstantValuePool.BizSettingConfig.printConfig.Name;
                 InstructionOrderPrint printer = new InstructionOrderPrint(ipAddress, 9100, paperWidth);
                 if (_salesOrder.order.EatType == (int) EatWayType.Takeout)
                 {
                     printer.DoPrintOrder(printData);
                 }
                 else
                 {
                     printer.DoPrintDeliveryOrder(printData);
                 }
             }
             if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.USB)
             {
                 string vid = ConstantValuePool.BizSettingConfig.printConfig.VID;
                 string pid = ConstantValuePool.BizSettingConfig.printConfig.PID;
                 string endpointId = ConstantValuePool.BizSettingConfig.printConfig.EndpointID;
                 InstructionOrderPrint printer = new InstructionOrderPrint(vid, pid, endpointId, paperWidth);
                 if (_salesOrder.order.EatType == (int) EatWayType.Takeout)
                 {
                     printer.DoPrintOrder(printData);
                 }
                 else
                 {
                     printer.DoPrintDeliveryOrder(printData);
                 }
             }
         }
     }
 }
Esempio n. 2
0
        private void btnDelivery_Click(object sender, EventArgs e)
        {
            CustomerOrder customerOrder = new CustomerOrder();
            customerOrder.OrderID = _salesOrder.order.OrderID;
            customerOrder.Telephone = this.txtTelephone.Text.Trim();
            customerOrder.CustomerName = this.txtName.Text.Trim();
            customerOrder.Address = this.txtAddress.Text.Trim();
            customerOrder.Remark = this.txtRemark.Text.Trim();
            customerOrder.DeliveryEmployeeNo = this.txtEmployeeNo.Text.Trim();
            if (CustomersService.GetInstance().UpdateTakeoutOrderStatus(customerOrder))
            {
                //打印
                _printData.CustomerPhone = this.txtTelephone.Text.Trim();
                _printData.CustomerName = this.txtName.Text.Trim();
                _printData.DeliveryAddress = this.txtAddress.Text.Trim();
                _printData.Remark = this.txtRemark.Text.Trim();
                _printData.DeliveryEmployeeName = this.txtEmployeeName.Text.Trim();
                
                if (ConstantValuePool.BizSettingConfig.printConfig.Enabled)
                {
                    int copies = ConstantValuePool.BizSettingConfig.printConfig.Copies;
                    string paperWidth = ConstantValuePool.BizSettingConfig.printConfig.PaperWidth;
                    if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.DRIVER)
                    {
                        string printerName = ConstantValuePool.BizSettingConfig.printConfig.Name;
                        string paperName = ConstantValuePool.BizSettingConfig.printConfig.PaperName;
                        DriverOrderPrint printer = DriverOrderPrint.GetInstance(printerName, paperName, paperWidth);
                        for (int i = 0; i < copies; i++)
                        {
                            printer.DoPrintDeliveryOrder(_printData);
                        }
                    }
                    if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.COM)
                    {
                        string port = ConstantValuePool.BizSettingConfig.printConfig.Name;
                        if (port.Length > 3)
                        {
                            if (port.Substring(0, 3).ToUpper() == "COM")
                            {
                                string portName = port.Substring(0, 4).ToUpper();
                                InstructionOrderPrint printer = new InstructionOrderPrint(portName, 9600, Parity.None, 8, StopBits.One, paperWidth);
                                for (int i = 0; i < copies; i++)
                                {
                                    printer.DoPrintDeliveryOrder(_printData);
                                }
                            }
                        }
                    }
                    if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.ETHERNET)
                    {
                        string ipAddress = ConstantValuePool.BizSettingConfig.printConfig.Name;
                        InstructionOrderPrint printer = new InstructionOrderPrint(ipAddress, 9100, paperWidth);
                        for (int i = 0; i < copies; i++)
                        {
                            printer.DoPrintDeliveryOrder(_printData);
                        }
                    }
                    if (ConstantValuePool.BizSettingConfig.printConfig.PrinterPort == PortType.USB)
                    {
                        string vid = ConstantValuePool.BizSettingConfig.printConfig.VID;
                        string pid = ConstantValuePool.BizSettingConfig.printConfig.PID;
                        string endpointId = ConstantValuePool.BizSettingConfig.printConfig.EndpointID;
                        InstructionOrderPrint printer = new InstructionOrderPrint(vid, pid, endpointId, paperWidth);
                        for (int i = 0; i < copies; i++)
                        {
                            printer.DoPrintDeliveryOrder(_printData);
                        }
                    }
                }

                _hasDeliveried = true;
                this.Close();
            }
            else
            {
                MessageBox.Show("出货失败,请重新操作!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }