/// <summary> /// 读取行元素中的内容元素 /// </summary> /// <param name="EL"></param> /// <returns></returns> private List <ContentEntity> ReadContent(XElement EL) { List <ContentEntity> listResult = new List <ContentEntity>(); foreach (XElement Node in EL.Elements()) { if (Node.Name == "Text") { TextEntity Result = this.ReadText(Node); listResult.Add(Result); } else if (Node.Name == "StrLine") { StrLineEntity Result = this.ReadStrLine(Node); listResult.Add(Result); } else if (Node.Name == "Image") { ImageEntity Result = this.ReadImage(Node); listResult.Add(Result); } else if (Node.Name == "QRCode") { QRCodeEntity Result = this.ReadQRCode(Node); listResult.Add(Result); } else if (Node.Name == "BarCode") { BarCodeEntity Result = this.ReadBarCode(Node); listResult.Add(Result); } } return(listResult); }
/// <summary> /// 读取条码节点 /// </summary> /// <param name="Node"></param> /// <returns></returns> private BarCodeEntity ReadBarCode(XElement Node) { BarCodeEntity Result = new BarCodeEntity(); float Left = Node.Value <float>("Left"); float Top = Node.Value <float>("Top"); float Width = Node.Value <float>("Width"); float Height = Node.Value <float>("Height"); int BarCodeFormat = Node.Value <int>("BarCodeFormat"); string Content = Node.Value; if (Content.Contains("{{") && Content.Contains("}}")) { Result.ContentType = 2; } else { Result.ContentType = 1; } Result.Content = Content; Result.Left = Left; Result.Top = Top; Result.Width = Width; Result.Height = Height; Result.BarCodeFormat = BarCodeFormat; return(Result); }
/// <summary> /// 写入条码 /// </summary> /// <param name="entity"></param> private void WriteBarCode(BarCodeEntity entity, Dictionary <string, object> dicSource) { float CurrentTop = entity.Top + this.CurrentHeight; string content = string.Empty; if (entity.ContentType == 2) { content = entity.Content; int beginIndex = content.IndexOf("{{"); int endIndex = content.LastIndexOf("}}"); string key = content.Substring(beginIndex + 2, endIndex - beginIndex - 2); string Value = dicSource.Value <string, object>(key) as string; content = Value; } else if (entity.ContentType == 1) { content = entity.Content; } cpcl_dll.CPCL_AddBarCode(dll.printer, cpcl_dll.ROTATE_NONE, cpcl_dll.BARCODE_39, (int)entity.Width, 2, (int)entity.Height, (int)entity.Left, (int)CurrentTop, content); //QrCodeEncodingOptions options = new QrCodeEncodingOptions //{ // DisableECI = true, // CharacterSet = "UTF-8", // Width = (int)Math.Ceiling(entity.Width), // Height = (int)Math.Ceiling(entity.Height), //}; //BarcodeWriter writer = new BarcodeWriter(); //writer.Format = BarCodeOption.GetBarcodeFormat(entity.BarCodeFormat); //writer.Options = options; //Bitmap bitmap = writer.Write(content); //g.DrawImage(bitmap, new PointF(entity.Left, CurrentTop)); }
/// <summary> /// 写入单行 /// </summary> /// <param name="entity"></param> private void WriteLine(LineEntity entity, Dictionary <string, object> dicSource) { if (!entity.ListContent.IsNullOrEmpty()) { foreach (ContentEntity item in entity.ListContent) { if (item is StrLineEntity) { StrLineEntity Content = item as StrLineEntity; this.WriteLine(Content); } else if (item is TextEntity) { TextEntity Content = item as TextEntity; this.WriteText(Content, dicSource); } else if (item is ImageEntity) { ImageEntity Content = item as ImageEntity; this.WriteImage(Content, dicSource); } else if (item is QRCodeEntity) { QRCodeEntity Content = item as QRCodeEntity; this.WriteQRCode(Content, dicSource); } else if (item is BarCodeEntity) { BarCodeEntity Content = item as BarCodeEntity; this.WriteBarCode(Content, dicSource); } } } this.CurrentHeight += entity.Height; }
/// <summary> /// 写入条码 /// </summary> /// <param name="entity"></param> private void WriteBarCode(BarCodeEntity entity, Dictionary <string, object> dicSource) { float CurrentTop = entity.Top + this.CurrentHeight; string content = string.Empty; if (entity.ContentType == 2) { content = entity.Content; int beginIndex = content.IndexOf("{{"); int endIndex = content.LastIndexOf("}}"); string key = content.Substring(beginIndex + 2, endIndex - beginIndex - 2); string Value = dicSource.Value <string, object>(key) as string; content = Value; } else if (entity.ContentType == 1) { content = entity.Content; } QrCodeEncodingOptions options = new QrCodeEncodingOptions { DisableECI = true, CharacterSet = "UTF-8", Width = (int)Math.Ceiling(entity.Width), Height = (int)Math.Ceiling(entity.Height), }; BarcodeWriter writer = new BarcodeWriter(); writer.Format = BarCodeOption.GetBarcodeFormat(entity.BarCodeFormat); writer.Options = options; Bitmap bitmap = writer.Write(content); g.DrawImage(bitmap, new PointF(entity.Left, CurrentTop)); }
private void InitPlineList() { List <string> lst_pline = new List <string> { "M010", "M020", "M050" }; List <ProductLineEntity> lst = ProductLineFactory.GetAll(); //var s = (from p in lst from q in lst_pline where p.AUTO_TYPE == "A" && p.PLINE_CODE==q orderby p.PLINE_NAME select p).ToList(); BarCodeEntity s = null; comboBox1.DisplayMember = "PLINE_NAME"; comboBox1.ValueMember = "PLINE_CODE"; comboBox1.DataSource = s; }
/// <summary> /// 打印触发事件 /// </summary> private void PrintEvent() { foreach (RowEntity row in this.Page.Rows.Where(item => item.RowType == (int)ERowType.Table)) { TableEntity RowItem = row as TableEntity; float TabLeft = RowItem.Left; Action <List <TdEntity> > action = (List <TdEntity> listTD) => { float CurrentLeft = TabLeft; foreach (TdEntity Td in listTD) { if (!Td.ListContent.IsNullOrEmpty()) { foreach (ContentEntity item in Td.ListContent) { if (item is StrLineEntity) { } else if (item is TextEntity) { TextEntity Content = item as TextEntity; Content.Left = Content.Left + CurrentLeft; } else if (item is ImageEntity) { ImageEntity Content = item as ImageEntity; Content.Left = Content.Left + CurrentLeft; } else if (item is QRCodeEntity) { QRCodeEntity Content = item as QRCodeEntity; Content.Left = Content.Left + CurrentLeft; } else if (item is BarCodeEntity) { BarCodeEntity Content = item as BarCodeEntity; Content.Left = Content.Left + CurrentLeft; } } } CurrentLeft = CurrentLeft + Td.Width; } }; if (RowItem.Head != null) { action(RowItem.Head.ListTD); } if (!RowItem.ListTR.IsNullOrEmpty()) { foreach (TrEntity td in RowItem.ListTR) { action(td.ListTD); } } } foreach (RowEntity row in this.Page.Rows) { if (row.RowType == (int)ERowType.Line) { LineEntity RowItem = row as LineEntity; this.WriteLine(RowItem, this.DataSource); } else if (row.RowType == (int)ERowType.Loop) { LoopEntity RowItem = row as LoopEntity; string KeyName = RowItem.KeyName; object ds = this.DataSource.Value <string, object>(KeyName); List <Dictionary <string, object> > listSource = ds as List <Dictionary <string, object> >; if (!listSource.IsNullOrEmpty()) { this.WriteLoop(RowItem, listSource); } } else if (row.RowType == (int)ERowType.Table) { TableEntity RowItem = row as TableEntity; string KeyName = RowItem.KeyName; object ds = this.DataSource.Value <string, object>(KeyName); List <Dictionary <string, object> > listSource = ds as List <Dictionary <string, object> >; if (!listSource.IsNullOrEmpty()) { this.WriteTable(RowItem, listSource); } } } }