Form1.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace ZebraSample
  9. {
  10. public partial class Form1 : Form
  11. {
  12. public Form1()
  13. {
  14. InitializeComponent();
  15. }
  16. private void button1_Click(object sender, EventArgs e)
  17. {
  18. PrintLabel("12345", "ABCDEFGHIJK", "SN123", "Test");
  19. }
  20. public void PrintLabel(string ProductID, string MAC, string SN, string ProductDesc)
  21. {
  22. string strContenx1 = ProductID;
  23. string strContenx2 = MAC;
  24. string strContenx3 = SN;
  25. //全局参数
  26. int GlobalStartX = int.Parse(txtStartX.Text);
  27. int GlobalStartY = int.Parse(txtStartY.Text);
  28. int Deep = int.Parse(coBoxND.SelectedValue.ToString());
  29. int Quatity = 15;
  30. int Speed = int.Parse(coBoxSD.SelectedValue.ToString());
  31. //条码参数
  32. int BcStartX = int.Parse(txtBcX.Text);
  33. int BcStartY = int.Parse(txtBcY.Text);
  34. int BcHeight = int.Parse(txtBcHeight.Text);
  35. int BcW = int.Parse(cbwidth.SelectedValue.ToString());
  36. double BcR = double.Parse(cbRatio.SelectedValue.ToString());
  37. //文字参数
  38. int intTextH = int.Parse(txtTextHeight.Text);
  39. int intTextW = int.Parse(txtTextWidth.Text);
  40. List<GetPrintRowString> bcList = new List<GetPrintRowString>(); ;
  41. //第一个条码
  42. Barcode1Dimension bc1 = new Barcode1Dimension(BcStartX, BcStartY);
  43. bc1.bcContent = strContenx1;//填充打印内容
  44. bc1.bcSize = BcHeight;//填充条码大小
  45. bc1.bcW = BcW;
  46. bc1.bcR = BcR;
  47. bcList.Add(bc1);
  48. //第二个条码
  49. Barcode1Dimension bc2 = new Barcode1Dimension(BcStartX, BcStartY + (BcHeight + intTextH + 10));
  50. bc2.bcContent = strContenx2.Split('-')[0]; ;//填充打印内容
  51. bc2.bcSize = BcHeight;//填充条码大小
  52. bc2.bcW = BcW;
  53. bc2.bcR = BcR;
  54. bcList.Add(bc2);
  55. //第三个条码
  56. Barcode1Dimension bc3 = new Barcode1Dimension(BcStartX, BcStartY + (BcHeight + intTextH + 10) * 2);
  57. bc3.bcContent = strContenx3;//填充打印内容
  58. bc3.bcSize = BcHeight;//填充条码大小
  59. bc3.bcW = BcW;
  60. bc3.bcR = BcR;
  61. bcList.Add(bc3);
  62. //第一个文本
  63. Text text1 = new Text(BcStartX, BcStartY + BcHeight + 5);
  64. text1.txtContent = "PROD ID:" + strContenx1 + " " + ProductDesc;//填充打印内容
  65. text1.txtH = intTextH;
  66. text1.txtW = intTextW;
  67. bcList.Add(text1);
  68. //第二个文本
  69. Text text2 = new Text(BcStartX, BcStartY + (BcHeight + intTextH + 10) + BcHeight + 5);
  70. text2.txtContent = "MAC:" + strContenx2;//填充打印内容
  71. text2.txtH = intTextH;
  72. text2.txtW = intTextW;
  73. bcList.Add(text2);
  74. //第三个文本
  75. Text text3 = new Text(BcStartX, BcStartY + (BcHeight + intTextH + 10) * 2 + BcHeight + 5);
  76. text3.txtContent = "SN:" + strContenx3;//填充打印内容
  77. text3.txtH = intTextH;
  78. text3.txtW = intTextW;
  79. bcList.Add(text3);
  80. ////图片
  81. //Images imgPrint = new Images(10, 10);
  82. //imgPrint.imgName = cmbImage.SelectedItem.ToString(); ;
  83. //imgPrint.imgMX = int.Parse(cbMagnification.SelectedValue.ToString());
  84. //imgPrint.imgMY = int.Parse(cbMagnification.SelectedValue.ToString());
  85. //bcList.Add(imgPrint);
  86. GetPrintString model = new GetPrintString();
  87. model.Deep = Deep;
  88. model.Quatity = Quatity;
  89. model.Speed = Speed;
  90. model.StartX = GlobalStartX;
  91. model.StartY = GlobalStartY;
  92. model.list = bcList;
  93. //model.imgPath = cmbImage.SelectedItem.ToString() + ".GRF";
  94. model.Print();
  95. }
  96. private void Form1_Load(object sender, EventArgs e)
  97. {
  98. FillDataND();
  99. FillDataSD();
  100. FillMagnification();
  101. FillRatio();
  102. FillWidth();
  103. }
  104. private void FillDataND() //浓度
  105. {
  106. DataTable dt = new DataTable();
  107. dt.Columns.Add("code", typeof(string));
  108. DataRow dr;
  109. for (int i = 1; i <= 30; i++)
  110. {
  111. dr = dt.NewRow();
  112. dr["code"] = i.ToString();
  113. dt.Rows.Add(dr);
  114. }
  115. this.coBoxND.DataSource = dt;
  116. this.coBoxND.DisplayMember = "code";
  117. this.coBoxND.ValueMember = "code";
  118. }
  119. private void FillMagnification() //图片倍数
  120. {
  121. DataTable dt = new DataTable();
  122. dt.Columns.Add("code", typeof(string));
  123. DataRow dr;
  124. for (int i = 1; i <= 10; i++)
  125. {
  126. dr = dt.NewRow();
  127. dr["code"] = i.ToString();
  128. dt.Rows.Add(dr);
  129. }
  130. this.cbMagnification.DataSource = dt;
  131. this.cbMagnification.DisplayMember = "code";
  132. this.cbMagnification.ValueMember = "code";
  133. }
  134. private void FillWidth() //W
  135. {
  136. DataTable dt = new DataTable();
  137. dt.Columns.Add("code", typeof(string));
  138. DataRow dr;
  139. for (int i = 1; i <= 10; i++)
  140. {
  141. dr = dt.NewRow();
  142. dr["code"] = i.ToString();
  143. dt.Rows.Add(dr);
  144. }
  145. this.cbwidth.DataSource = dt;
  146. this.cbwidth.DisplayMember = "code";
  147. this.cbwidth.ValueMember = "code";
  148. }
  149. private void FillRatio() //R
  150. {
  151. DataTable dt = new DataTable();
  152. dt.Columns.Add("code", typeof(double));
  153. DataRow dr;
  154. double douSeed = 2.0;
  155. for (int i = 1; i <= 11; i++)
  156. {
  157. dr = dt.NewRow();
  158. dr["code"] = douSeed.ToString();
  159. dt.Rows.Add(dr);
  160. douSeed = douSeed + 0.1;
  161. }
  162. this.cbRatio.DataSource = dt;
  163. this.cbRatio.DisplayMember = "code";
  164. this.cbRatio.ValueMember = "code";
  165. }
  166. private void FillDataSD() //速度
  167. {
  168. DataTable dt = new DataTable();
  169. dt.Columns.Add("code", typeof(string));
  170. dt.Columns.Add("name", typeof(string));
  171. DataRow dr = dt.NewRow();
  172. dr["code"] = "1";
  173. dr["name"] = "1英寸/每秒";
  174. dt.Rows.Add(dr);
  175. dr = dt.NewRow();
  176. dr["code"] = "2";
  177. dr["name"] = "2英寸/每秒";
  178. dt.Rows.Add(dr);
  179. dr = dt.NewRow();
  180. dr["code"] = "3";
  181. dr["name"] = "3英寸/每秒";
  182. dt.Rows.Add(dr);
  183. this.coBoxSD.DataSource = dt;
  184. this.coBoxSD.DisplayMember = "name";
  185. this.coBoxSD.ValueMember = "code";
  186. }
  187. }
  188. }