コード例 #1
0
 /// <summary>
 /// 显示快递模板
 /// </summary>
 /// <param name="expTempLate">快递模板</param>
 /// <param name="zoom">显示模板的缩放系数</param>
 public void ShowExpress(ExpressModel expTempLate, double zoom)
 {
     zoomCoefficient = zoom;
     edge            = 44 * zoomCoefficient;
     //设置expressGrid
     expressGrid.Children.Clear();
     expressGrid.Width  = expTempLate.宽 * 0.96 * zoomCoefficient;
     expressGrid.Height = expTempLate.高 * 0.96 * zoomCoefficient;
     //载入背景图片
     expressImage        = new Image();
     expressImage.Width  = expressGrid.Width;
     expressImage.Height = expressGrid.Height;
     expressImage.Source = Other.GetImage(expTempLate.ID);
     //添加背景图片和编辑文本框
     expressGrid.Children.Add(expressImage);
     expressGrid.Children.Add(editTB);
     //向expressGrid添加Text元素
     foreach (var item in expTempLate.标签)
     {
         AddTextBlock(item, true);
     }
 }
コード例 #2
0
        /// <summary>
        /// 向expressGrid添加TextBlock
        /// </summary>
        /// <param name="labelInfo">要添加的标签信息</param>
        /// <param name="isZoom">是否执行缩放计算</param>
        private void AddTextBlock(LabelModel labelInfo, bool isZoom)
        {
            if (labelInfo.文本 == null)
            {
                return;
            }
            string textString = labelInfo.文本.Trim();

            if (textString.Length == 0)
            {
                return;
            }
            else
            {
                //初始化TextBlock,设置必要的相同属性
                TextBlock elementTB = new TextBlock()
                {
                    Cursor              = Cursors.Hand,
                    FontFamily          = new FontFamily(labelInfo.字体),
                    HorizontalAlignment = HorizontalAlignment.Left,
                    MaxWidth            = 288 * zoomCoefficient,
                    TextWrapping        = TextWrapping.Wrap,
                    VerticalAlignment   = VerticalAlignment.Top,
                    Background          = Brushes.Violet,
                    //Background = new SolidColorBrush(Color.FromArgb(0x50, 0xff, 0, 0xff)),
                    ContextMenu = textCM
                };
                if (isZoom)
                {
                    elementTB.FontSize = labelInfo.字号 * zoomCoefficient;
                    elementTB.Margin   = new Thickness(labelInfo.水平边距 * zoomCoefficient, labelInfo.垂直边距 * zoomCoefficient, 0, 0);
                }
                else
                {
                    elementTB.FontSize = labelInfo.字号;
                    elementTB.Margin   = new Thickness(labelInfo.水平边距, labelInfo.垂直边距, 0, 0);
                }
                elementTB.MouseLeftButtonDown += TextBlock_MouseLeftButtonDown;
                elementTB.MouseLeftButtonUp   += TextBlock_MouseLeftButtonUp;
                elementTB.MouseRightButtonUp  += TextBlock_MouseRightButtonUp;

                //绑定联系人数据源
                if (isBinding)
                {
                    //替换标签用户信息
                    textString = Other.ReplaceLabel(textString);
                    //需要绑定的联系人数据源
                    Binding binding;
                    switch (textString)
                    {
                    case "[联系人]":
                        binding = new Binding("名称");
                        BindingOperations.SetBinding(elementTB, TextBlock.TextProperty, binding);
                        break;

                    case "[昵称]":
                        binding = new Binding("昵称");
                        BindingOperations.SetBinding(elementTB, TextBlock.TextProperty, binding);
                        break;

                    case "[公司名称]":
                        binding = new Binding("显示公司");
                        BindingOperations.SetBinding(elementTB, TextBlock.TextProperty, binding);
                        break;

                    case "[公司简称]":
                        binding = new Binding("公司简称");
                        BindingOperations.SetBinding(elementTB, TextBlock.TextProperty, binding);
                        break;

                    case "[地址]":
                        binding = new Binding("地址");
                        BindingOperations.SetBinding(elementTB, TextBlock.TextProperty, binding);
                        break;

                    case "[手机]":
                        binding = new Binding("手机优先");
                        BindingOperations.SetBinding(elementTB, TextBlock.TextProperty, binding);
                        break;

                    case "[电话]":
                        binding = new Binding("电话优先");
                        BindingOperations.SetBinding(elementTB, TextBlock.TextProperty, binding);
                        break;

                    case "[传真]":
                        binding = new Binding("传真优先");
                        BindingOperations.SetBinding(elementTB, TextBlock.TextProperty, binding);
                        break;

                    case "[日期]":
                        elementTB.Text = DateTime.Now.ToShortDateString();
                        break;

                    default:
                        elementTB.Text = textString;
                        break;
                    }
                }
                //向expressGrid添加此元素
                expressGrid.Children.Add(elementTB);
            }
        }
コード例 #3
0
ファイル: Linq.cs プロジェクト: 1988wj/Invoice
        /// <summary>
        /// 发货单模板
        /// </summary>
        public static BillModel GetInvoiceTemplate(InvoiceModelPrint invoicePrintInfo, bool payment)
        {
            BillModel r;
            string    _nameString;

            if (payment)
            {
                _nameString = "现金";
            }
            else
            {
                _nameString = "赊欠";
            }
            //载入配置文件数据
            XElement _XE        = XElement.Load(Global.ConfigPath);
            XElement TemplateXE = _XE.Elements("InvoiceTemplate").First(_func => _func.Attribute("Name").Value == _nameString);

            _nameString = TemplateXE.Attribute("PaperName").Value;
            XElement  paperSizeXE = _XE.Elements("PaperSize").First(_func => _func.Attribute("Name").Value == _nameString);
            PaperSize paperSize   = new PaperSize(_nameString, int.Parse(paperSizeXE.Attribute("Width").Value), int.Parse(paperSizeXE.Attribute("Height").Value));

            //初始化发货单模板
            r = new BillModel()
            {
                纸张尺寸 = paperSize,
                水平边距 = int.Parse(TemplateXE.Attribute("HorizontalMargin").Value),
                水平平移 = int.Parse(TemplateXE.Attribute("HorizontalMove").Value),
                垂直边距 = int.Parse(TemplateXE.Attribute("VerticalMargin").Value),
                垂直平移 = int.Parse(TemplateXE.Attribute("VerticalMove").Value),

                表字体 = TemplateXE.Element("Table").Attribute("FontFamily").Value,
                表字号 = int.Parse(TemplateXE.Element("Table").Attribute("FontSize").Value),
                表行号 = int.Parse(TemplateXE.Element("Table").Attribute("RowNumber").Value),

                段落 = TemplateXE.Elements("Row").Select(_func => new RowModel
                {
                    行号 = int.Parse(_func.Attribute("Number").Value),
                    行高 = int.Parse(_func.Attribute("Height").Value),
                }).ToList(),

                标签 = TemplateXE.Elements("Label").Select(_func => new LabelModel
                {
                    文本   = _func.Value,
                    字体   = _func.Attribute("FontFamily").Value,
                    字号   = int.Parse(_func.Attribute("FontSize").Value),
                    水平边距 = int.Parse(_func.Attribute("HorizontalMargin").Value),
                    水平对齐 = _func.Attribute("Horizontal").Value,
                    垂直边距 = int.Parse(_func.Attribute("VerticalMargin").Value),
                    垂直对齐 = _func.Attribute("Vertical").Value,
                    行号   = int.Parse(_func.Attribute("RowNumber").Value),
                    绝对定位 = bool.Parse(_func.Attribute("Absolute").Value)
                }).ToList(),

                表列 = TemplateXE.Element("Table").Elements("Column").Select(_func => new TableColumnModel
                {
                    绑定   = _func.Attribute("Binding").Value,
                    表头   = _func.Attribute("Hesder").Value,
                    列宽   = int.Parse(_func.Attribute("Width").Value),
                    水平对齐 = _func.Attribute("Horizontal").Value
                }).ToList()
            };


            //替换标签模板信息
            string pageNumber  = string.Format("{0}\r\n{1}", invoicePrintInfo.分页码, invoicePrintInfo.总页码.ToString("'No.'00000000"));
            string totalAmount = (invoicePrintInfo.金额 == 0 ? "" : string.Format("{0} {1}", Other.MoneyToCN(invoicePrintInfo.金额), invoicePrintInfo.金额.ToString("C")));

            foreach (var item in r.标签)
            {
                item.文本 = Other.ReplaceLabel(item.文本)
                          .Replace("[页码]", pageNumber)
                          .Replace("[总金额]", totalAmount)
                          .Replace("[公司名称]", invoicePrintInfo.公司名称)
                          .Replace("[赊欠金额]", invoicePrintInfo.赊欠金额.ToString("C"))
                          .Replace("[联系人]", invoicePrintInfo.联系人)
                          .Replace("[备注]", invoicePrintInfo.Comment)
                          .Replace("[打印日期]", invoicePrintInfo.打印时间.ToLongDateString());
            }
            return(r);
        }