コード例 #1
0
 /// <summary>
 /// 公司原来通用版中的方法
 /// </summary>
 /// <param name="Bar_Data"></param>
 /// <param name="IsPrint"></param>
 /// <param name="xmlFile"></param>
 public void PrintBarcodeMore(DataTable Bar_Data, bool IsPrint, string xmlFile)
 {
     if (Bar_Data != null && Bar_Data.Rows.Count > 0)
     {
         List <PrinterSet> printerInfo = OperateXML.GetPrinterInfo(xmlFile);
         List <TextSet>    txtInfo     = OperateXML.GetTxtInfo(xmlFile);
         List <BarcodeSet> barcode     = OperateXML.GetBarcode(xmlFile);
         Image[]           array       = new Image[Bar_Data.Rows.Count];
         for (int i = 0; i < Bar_Data.Rows.Count; i++)
         {
             Bitmap   bitmap   = new Bitmap(int.Parse(printerInfo[0].Width), int.Parse(printerInfo[0].Height));
             Graphics graphics = Graphics.FromImage(bitmap);
             graphics.Clear(Color.White);
             int j;
             for (j = 0; j < Bar_Data.Columns.Count; j++)
             {
                 if (Bar_Data.Columns[j].ColumnName.ToLower() != "barcode" && Bar_Data.Columns[j].ColumnName.ToLower() != "printnum" && Bar_Data.Columns[j].ColumnName.ToLower() != "条形码")
                 {
                     int    num        = 10;
                     string familyName = "";
                     int    num2       = 1;
                     int    num3       = 1;
                     int    num4       = 0;
                     int    num5       = 10;
                     string text       = Bar_Data.Rows[i][j].ToString();
                     //TextSet textSet = txtInfo.Find((TextSet t) => t.TextName == Bar_Data.Columns[j].ColumnName);
                     TextSet textSet = txtInfo.Find(delegate(TextSet t)
                     {
                         return(t.TextName == Bar_Data.Columns[j].ColumnName);
                     });
                     if (textSet != null)
                     {
                         num        = int.Parse(textSet.TextFontSize);
                         familyName = textSet.TextFontName;
                         num2       = int.Parse(textSet.TextX);
                         num3       = int.Parse(textSet.TextY);
                         num4       = 1;
                     }
                     if (num4 == 1)
                     {
                         string text2 = text;
                         if (num5 > 0)
                         {
                             int    length = num5;
                             string text3  = this.bSubstring(text2, length);
                             if (text3.Trim() != "")
                             {
                                 if (text3 != text2)
                                 {
                                     graphics.DrawString(text3, new Font(familyName, (float)num), Brushes.Black, new PointF((float)num2, (float)num3));
                                     graphics.DrawString(text2.Replace(text3, ""), new Font(familyName, (float)num), Brushes.Black, new PointF((float)num2, (float)(num3 + num + 3)));
                                 }
                                 else
                                 {
                                     graphics.DrawString(text2, new Font(familyName, (float)num), Brushes.Black, new PointF((float)num2, (float)num3));
                                 }
                             }
                         }
                     }
                 }
             }
             string txm_data = Bar_Data.Rows[i]["barcode"].ToString();
             int    num6     = 1;
             try
             {
                 num6 = Convert.ToInt32(Bar_Data.Rows[i]["printnum"].ToString());
             }
             catch
             {
             }
             if (num6 < 1)
             {
                 num6 = 1;
             }
             Image image = this.TxmImage(txm_data, int.Parse(barcode[0].BarcodeLineWidth), int.Parse(barcode[0].BarcodeHeight));
             if (image != null)
             {
                 graphics.DrawImage(image, int.Parse(barcode[0].BarcodeX), int.Parse(barcode[0].BarcodeY));
             }
             graphics.Dispose();
             bitmap.Tag = num6;
             array[i]   = bitmap;
         }
         if (IsPrint)
         {
             Image[] array2 = array;
             for (int l = 0; l < array2.Length; l++)
             {
                 Image image2 = array2[l];
                 if (image2 != null)
                 {
                     try
                     {
                         this.Image_Ok = image2;
                         PrintDocument printDocument = new PrintDocument();
                         printDocument.PrintPage += new PrintPageEventHandler(this.prt_PrintPage);
                         PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog();
                         if (this.Print_MachName.Trim() != "")
                         {
                             printDocument.PrinterSettings.PrinterName = this.Print_MachName;
                         }
                         printPreviewDialog.Document = printDocument;
                         for (int k = 0; k < Convert.ToInt32(image2.Tag.ToString()); k++)
                         {
                             printPreviewDialog.Document.Print();
                         }
                     }
                     catch
                     {
                     }
                 }
             }
         }
         else
         {
             Form_SeeTxm form_SeeTxm = new Form_SeeTxm(array, Bar_Data, this.Print_MachName);
             form_SeeTxm.ShowDialog();
         }
     }
 }
コード例 #2
0
 /// <summary>
 /// 邵阳版本中的方法
 /// </summary>
 /// <param name="Bar_Data"></param>
 /// <param name="IsPrint"></param>
 /// <param name="_Type_Set"></param>
 public void PrintBarcodeMore(DataTable Bar_Data, bool IsPrint, int _Type_Set)
 {
     if (Bar_Data != null && Bar_Data.Rows.Count > 0)
     {
         this.Type_Set = _Type_Set;
         this.ReadLocatSet();
         DataTable dataTable = this.OtherInfoLocatSet();
         Image[]   array     = new Image[Bar_Data.Rows.Count];
         for (int i = 0; i < Bar_Data.Rows.Count; i++)
         {
             Bitmap   bitmap   = new Bitmap(this.Width_Print, this.Height_Print);
             Graphics graphics = Graphics.FromImage(bitmap);
             graphics.Clear(Color.White);
             int num = 0;
             for (int j = 0; j < Bar_Data.Columns.Count; j++)
             {
                 if (Bar_Data.Columns[j].ColumnName.ToLower() != "barcode" && Bar_Data.Columns[j].ColumnName.ToLower() != "printnum")
                 {
                     num++;
                     int    num2       = 8;
                     string familyName = "";
                     int    num3       = 1;
                     int    num4       = 1;
                     int    num5       = 1;
                     string text       = Bar_Data.Rows[i][j].ToString();
                     int    num6       = text.Length;
                     try
                     {
                         if (dataTable != null && dataTable.Rows.Count > 0)
                         {
                             DataRow[] array2 = dataTable.Select("ID='" + num.ToString() + "'");
                             if (array2.Length > 0)
                             {
                                 num2       = Convert.ToInt32(array2[0]["Info_font"].ToString());
                                 familyName = array2[0]["Info_FontName"].ToString();
                                 num3       = Convert.ToInt32(array2[0]["Info_Left"].ToString());
                                 num4       = Convert.ToInt32(array2[0]["Info_Top"].ToString());
                                 num5       = Convert.ToInt32(array2[0]["Info_Show"].ToString());
                                 num6       = Convert.ToInt32(array2[0]["Info_Max"].ToString());
                             }
                         }
                     }
                     catch
                     {
                     }
                     if (num5 == 1)
                     {
                         string text2 = text;
                         if (num6 > 0)
                         {
                             int    length = num6;
                             string text3  = this.bSubstring(text2, length);
                             if (text3.Trim() != "")
                             {
                                 if (text3 != text2)
                                 {
                                     graphics.DrawString(text3, new Font(familyName, (float)num2), Brushes.Black, new PointF((float)num3, (float)num4));
                                     graphics.DrawString(text2.Replace(text3, ""), new Font(familyName, (float)num2), Brushes.Black, new PointF((float)num3, (float)(num4 + num2 + 3)));
                                 }
                                 else
                                 {
                                     graphics.DrawString(text2, new Font(familyName, (float)num2), Brushes.Black, new PointF((float)num3, (float)num4));
                                 }
                             }
                         }
                     }
                 }
             }
             string txm_data = Bar_Data.Rows[i]["barcode"].ToString();
             int    num7     = 1;
             try
             {
                 num7 = Convert.ToInt32(Bar_Data.Rows[i]["printnum"].ToString());
             }
             catch
             {
             }
             if (num7 < 1)
             {
                 num7 = 1;
             }
             Image image = this.TxmImage(txm_data);
             if (image != null)
             {
                 graphics.DrawImage(image, this.Left_Txm, this.Top_Txm);
             }
             graphics.Dispose();
             bitmap.Tag = num7;
             array[i]   = bitmap;
         }
         if (IsPrint)
         {
             Image[] array3 = array;
             for (int k = 0; k < array3.Length; k++)
             {
                 Image image2 = array3[k];
                 if (image2 != null)
                 {
                     try
                     {
                         this.Image_Ok = image2;
                         PrintDocument printDocument = new PrintDocument();
                         printDocument.PrintPage += new PrintPageEventHandler(this.prt_PrintPage);
                         PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog();
                         if (this.Print_MachName.Trim() != "")
                         {
                             printDocument.PrinterSettings.PrinterName = this.Print_MachName;
                         }
                         printPreviewDialog.Document = printDocument;
                         for (int l = 0; l < Convert.ToInt32(image2.Tag.ToString()); l++)
                         {
                             printPreviewDialog.Document.Print();
                         }
                     }
                     catch
                     {
                     }
                 }
             }
         }
         else
         {
             Form_SeeTxm form_SeeTxm = new Form_SeeTxm(array, Bar_Data, this.Print_MachName);
             form_SeeTxm.ShowDialog();
         }
     }
 }