/// <summary>
        /// 打印测试
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPrintTest_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var printTemplate = this.lstDeliveryPrintTemplates.SelectedItem as PrintTemplate;
                if (printTemplate == null)
                {
                    MessageBox.Show("请选择一个模板");
                    return;
                }

                int count = 0;
                if (int.TryParse(this.tbTestCount.Text.Trim(), out count) == false)
                {
                    MessageBox.Show("请输入要打印测试的数量");
                    return;
                }
                var ret = pd.ShowDialog();
                if (ret.Value == false)
                {
                    return;
                }
                pd.PrintTicket.PageMediaSize = new System.Printing.PageMediaSize(printTemplate.Width, printTemplate.Height);
                if (printTemplate.Type == PrintTemplate.TYPE_GOODS)
                {
                    OrderGoods[] orderGoodss = new OrderGoods[count];
                    for (int i = 0; i < count; i++)
                    {
                        orderGoodss[i] = CreateTestOrderGoods();
                    }
                    GoodsPrintDocument doc = new GoodsPrintDocument();
                    doc.StartPrint(orderGoodss, "", true, printTemplate);
                }
                else if (printTemplate.Type == PrintTemplate.TYPE_RETURN)
                {
                    OrderReturn[] or = new OrderReturn[count];
                    for (int i = 0; i < count; i++)
                    {
                        or[i] = CreateTestOrderReturn();
                    }
                    OrderReturnPrintDocument od = new OrderReturnPrintDocument();
                    od.StartPrint(or, "", true, printTemplate);
                }
                MessageBox.Show("打印完成");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        private void btnPrintOrderGoodsButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                FrameworkElement fe = sender as FrameworkElement;
                if (fe == null)
                {
                    MessageBox.Show("事件源不正确");
                    return;
                }

                var orderGoods = fe.Tag as OrderGoods;
                if (orderGoods == null)
                {
                    MessageBox.Show("Tag对象不为OrderGoods");
                    return;
                }
                var goodsTemplate = LocalConfigService.GetValue(SystemNames.CONFIG_GOODS_TEMPLATE, "");
                if (string.IsNullOrWhiteSpace(goodsTemplate))
                {
                    throw new Exception("系统中没有配置商品模板不能打印");
                }
                var template = PrintTemplateService.GetAllLocal().FirstOrDefault(obj => obj.Type == PrintTemplate.TYPE_GOODS && obj.Name == goodsTemplate);
                if (template == null)
                {
                    throw new Exception("系统中配置的商品模板:" + goodsTemplate + "不存在,或者类型不对");
                }
                var    gpd     = new GoodsPrintDocument();
                string printer = LocalConfigService.GetValue(SystemNames.CONFIG_PRINTER_GOODS_BARCODE, "");
                gpd.StartPrint(new OrderGoods[] { orderGoods }, printer, false, template);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }