示例#1
0
        private void bt_Print_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cmb_OrdPrinter.Text))
            {
                MessageBox.Show(this, @"请选择打印机!", @"注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (WMSService.WMSOrderNos != null && WMSService.WMSOrderNos.Values.Count > 0)
            {
                MessageBox.Show(this, @"打印正在进行,请等待打印完成之后再进行此操作!", @"注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            var downGoodsBillNo    = string.Empty;
            var downGoodsBillState = string.Empty;

            foreach (var row in dgv_Order.Rows.Cast <DataGridViewRow>().Where(row => null != row.Cells[0].Value && ((bool)row.Cells[0].Value)))
            {
                downGoodsBillNo    = row.Cells[2].Value.ToString();
                downGoodsBillState = row.Cells[5].Value.ToString();
                break;
            }
            if (string.IsNullOrWhiteSpace(downGoodsBillNo))
            {
                MessageBox.Show(this, @"请选择要打印的下货单!", @"注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            var result = WMSService.CurrentWMSService.GetPrintOrderBill(new Guid(ConfigManager.ConfigInfo.WarehouseId),
                                                                        new Guid(ConfigManager.ConfigInfo.InvoiceFilialeId), downGoodsBillNo);

            if (result.IsSuccess)
            {
                var printType = downGoodsBillState == "待下货" ? PrintType.Manual : PrintType.Again;
                try
                {
                    PrinterManager.PrintOrder(ConfigManager.ConfigInfo.PrintOrderModel, result.Data,
                                              cmb_OrdPrinter.Text, printType, YesOrNo.No, PrintAbout.Order);
                }
                catch (Exception ex)
                {
                    WMSService.NoPrintedResetReaderId(new List <string> {
                        downGoodsBillNo
                    });
                    MessageBox.Show(ex.Message, @"提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show(this, result.Msg, @"注意", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
示例#2
0
        /// <summary>启动打印
        /// </summary>
        public static void PrintEngine()
        {
            var expSelectedList = ConfigManager.ConfigInfo.ExpList.Where(e => e.Selected).ToList();

            if (expSelectedList.Count == 0)
            {
                return;
            }
            else if (expSelectedList.Count != 1)
            {
                throw new ArgumentException("必须勾选1个且只有1个快递公司使用自动打印服务,请重新设置!");
            }
            var expSelected = expSelectedList[0];

            //取得与打印机绑订的快递公司模版
            if (ConfigManager.ConfigInfo.PrintOrderModel == null ||
                ConfigManager.ConfigInfo.PrintOrderModel == new Guid())
            {
                throw new Exception("未找到模版");
            }
            if (string.IsNullOrEmpty(expSelected.ExpressPrinter))
            {
                throw new Exception("未绑定打印机");
            }


            //首先检查有没有上次没有打印的订单
            if (WMSService.WMSGroupOrder.Count == 0)
            {
                //重新获取订单
                Guid _warehouseId       = new Guid(ConfigManager.ConfigInfo.WarehouseId);
                Guid _hosttingFilialeId = new Guid(ConfigManager.ConfigInfo.InvoiceFilialeId);
                var  salePlatformIds    = ConfigManager.ConfigInfo.PrintPlatformSetModelList.Where(ent => ent.IsProcess).Select(ent => ent.SalePlatformId).ToList();
                var  expressIds         = expSelectedList.Select(exp => exp.ExpressCompanyId).ToList();
                var  result             = WMSService.CurrentWMSService.AutoPrintOrderBills(_warehouseId, _hosttingFilialeId,
                                                                                           salePlatformIds, expressIds, false, 10, ConfigManager.ConfigInfo.OrderType);
                //缓存打印数据
                if (result.IsSuccess)
                {
                    WMSService.WMSGroupOrder.Clear();
                    List <OrderPrintDataDTO> cacheDatas = new List <OrderPrintDataDTO>();
                    //将待打印的订单记录缓存
                    foreach (var orderPrintDataDto in result.Data)
                    {
                        cacheDatas.Add(orderPrintDataDto);
                    }
                    WMSService.WMSGroupOrder = cacheDatas;
                }
            }
            for (int i = 0; i < WMSService.WMSGroupOrder.Count;)
            {
                OrderPrintDataDTO printOrder = WMSService.WMSGroupOrder[0];
                try
                {
                    //打印发货单
                    PrintOrder(ConfigManager.ConfigInfo.PrintOrderModel, printOrder,
                               expSelectedList[0].OrderPrinter, DataEntity.PrintType.Auto, YesOrNo.No, PrintAbout.Order);
                    //打印快递单
                    if (expSelectedList[0].AutoPrint)
                    {
                        PrintOrder(expSelectedList[0].ExpressPrintModel, printOrder,
                                   expSelectedList[0].ExpressPrinter, DataEntity.PrintType.Auto, YesOrNo.No, PrintAbout.Express);
                    }
                    WMSService.WMSGroupOrder.Remove(printOrder);
                    WMSService.UpdateCacheData();
                }
                catch (Exception ex)
                {
                    WMSService.NoPrintedResetReaderId(WMSService.WMSGroupOrder.Select(t => t.DownGoodsBillNo).ToList());
                    throw ex;
                }
            }
        }