极测_出货清单打印.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. using LabelManager2;
  2. using Seagull.BarTender.Print;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Drawing.Printing;
  8. using System.Linq;
  9. using System.Media;
  10. using System.Threading;
  11. using System.Windows.Forms;
  12. using static System.Runtime.CompilerServices.RuntimeHelpers;
  13. namespace UAS_BARCODEIO
  14. {
  15. public partial class 极测_出货清单打印 : Form
  16. {
  17. DataHelper dh = new DataHelper();
  18. Engine engine;
  19. DataTable Dbfind;
  20. //自适应屏幕
  21. AutoSizeFormClass asc = new AutoSizeFormClass();
  22. LabelFormatDocument format;
  23. public 极测_出货清单打印()
  24. {
  25. InitializeComponent();
  26. }
  27. delegate void BindDataSource(DataGridView dgv, DataTable dt);//定义委托
  28. void bindingsource(DataGridView dgv, DataTable dt)
  29. {
  30. //dgv.AutoGenerateColumns = false;
  31. //dgv.DataSource = null;
  32. //dgv.DataSource = dt;
  33. if (dgv.InvokeRequired)
  34. {
  35. dgv.Invoke(new BindDataSource(bindingsource), new object[] { dgv, dt });
  36. }
  37. else
  38. {
  39. dgv.AutoGenerateColumns = false;
  40. dgv.DataSource = dt;
  41. }
  42. }
  43. private void Form1_Load(object sender, EventArgs e)
  44. {
  45. SystemInf.dh = dh;
  46. spl_code.TableName = "SnPartsList ";
  47. spl_code.SelectField = "spl_code # 单据编号";
  48. spl_code.FormName = Name;
  49. spl_code.DBTitle = "解析规则查询";
  50. spl_code.SetValueField = new string[] { "spl_code" };
  51. spl_code.Condition = "";
  52. spl_code.DbChange += nr_rule_DBChange;
  53. SystemInf.dh = dh;
  54. try
  55. {
  56. engine = new Engine(true);
  57. format = engine.Documents.Open(System.Windows.Forms.Application.StartupPath + @"\BARCODE.btw");
  58. }
  59. catch (Exception ex)
  60. {
  61. Console.WriteLine(ex.Message);
  62. throw;
  63. }
  64. asc.controllInitializeSize(this);
  65. asc.controlAutoSize(this);
  66. PrintDocument print = new PrintDocument();
  67. string sDefault = print.PrinterSettings.PrinterName;//默认打印机名
  68. foreach (string sPrint in PrinterSettings.InstalledPrinters)//获取所有打印机名称
  69. {
  70. PrinterList.Items.Add(sPrint);
  71. if (sPrint == sDefault)
  72. PrinterList.SelectedIndex = PrinterList.Items.IndexOf(sPrint);
  73. }
  74. }
  75. private void nr_rule_DBChange(object sender, EventArgs e)
  76. {
  77. Dbfind = spl_code.ReturnData;
  78. BaseUtil.SetFormValue(this.Controls, Dbfind);
  79. }
  80. private void pi_inoutnokeydown(object sender, KeyEventArgs e)
  81. {
  82. if (e.KeyCode == Keys.Enter)
  83. {
  84. LoadGridData();
  85. }
  86. }
  87. private void LoadGridData()
  88. {
  89. }
  90. bool AutoSized = false;
  91. private void 入库条码规则解析_AutoSizeChanged(object sender, EventArgs e)
  92. {
  93. if (!AutoSized)
  94. {
  95. asc.controlAutoSize(this);
  96. AutoSized = true;
  97. }
  98. }
  99. private void PrintBarCode_Click(object sender, EventArgs e)
  100. {
  101. for (int i = 0; i < BarcodeIO.Rows.Count; i++)
  102. {
  103. if (BarcodeIO.Rows[i].Cells["CheckBox"].FormattedValue != null && BarcodeIO.Rows[i].Cells["CheckBox"].FormattedValue.ToString() == "True")
  104. {
  105. string barcode = "";
  106. string[] param = new string[] { "", "", barcode };
  107. dh.CallProcedure("SP_GETBARCODE", ref param);
  108. barcode = param[2].Replace("BARCODE:", "");
  109. format.SubStrings["BARCODE"].Value = barcode;
  110. format.SubStrings["PRSPEC"].Value = BarcodeIO.Rows[i].Cells["spld_prodspec"].Value.ToString();
  111. format.SubStrings["PRCODE"].Value = BarcodeIO.Rows[i].Cells["spld_prodcode"].Value.ToString();
  112. format.SubStrings["PRDETAIL"].Value = BarcodeIO.Rows[i].Cells["spld_proddetail"].Value.ToString();
  113. format.SubStrings["QTY"].Value = BarcodeIO.Rows[i].Cells["spld_thisqty"].Value.ToString();
  114. format.SubStrings["DC"].Value = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  115. dh.ExecuteSql("insert into prodiobarcode(pib_id,pib_prodcode,pib_inoutno,pib_barcode,pib_indate,pib_qty)" +
  116. "values(prodiobarcode_seq.nextval,'" + BarcodeIO.Rows[i].Cells["spld_prodcode"].Value.ToString() + "','" + spl_code.Text + "','" + barcode + "',sysdate,'" + BarcodeIO.Rows[i].Cells["spld_thisqty"].Value.ToString() + "')", "insert");
  117. format.PrintSetup.PrinterName = PrinterList.Text;
  118. format.PrintSetup.IdenticalCopiesOfLabel = 1;
  119. format.Print();
  120. }
  121. }
  122. }
  123. private void ChooseAll_Click(object sender, EventArgs e)
  124. {
  125. for (int i = 0; i < BarcodeIO.Rows.Count; i++)
  126. {
  127. BarcodeIO.Rows[i].Cells["CheckBox"].Value = true;
  128. }
  129. }
  130. private void PrintStockBarCode_Click(object sender, EventArgs e)
  131. {
  132. 库存条码打印 form = new 库存条码打印();
  133. form.ShowDialog();
  134. }
  135. Thread thread;
  136. string FileName = "";
  137. public void Play(string Type)
  138. {
  139. if (Type == "OK")
  140. {
  141. FileName = System.Windows.Forms.Application.StartupPath + @"\Resources\Sound\8378.wav";
  142. thread = new Thread(PlaySound);
  143. thread.Start();
  144. }
  145. else
  146. {
  147. FileName = System.Windows.Forms.Application.StartupPath + @"\Resources\Sound\5185.wav";
  148. thread = new Thread(PlaySound);
  149. thread.Start();
  150. }
  151. }
  152. private void PlaySound()
  153. {
  154. //要加载COM组件:Microsoft speech object Library
  155. if (!System.IO.File.Exists(FileName))
  156. {
  157. return;
  158. }
  159. try
  160. {
  161. SoundPlayer player = new SoundPlayer();
  162. player.SoundLocation = FileName;
  163. player.Load();
  164. player.Play();
  165. }
  166. catch (Exception e)
  167. {
  168. MessageBox.Show(e.Message);
  169. }
  170. }
  171. private void spl_code_UserControlTextChanged(object sender, EventArgs e)
  172. {
  173. DataTable dt = (DataTable)dh.ExecuteSql("select spld_detno,spld_module,spld_prodcode,spld_proddetail" +
  174. ",spld_prodspec,spld_produnit,spld_baseqty,spld_qty,spld_sncode,spld_sndetno,spld_thisqty,spld_remark " +
  175. " from SnPartsList left join SNPARTSLISTDETAIL on spl_id=spld_splid where spl_code='" + spl_code.Text + "'", "select");
  176. if (dt.Rows.Count == 0)
  177. {
  178. MessageBox.Show("单据编号不存在");
  179. return;
  180. }
  181. BarcodeIO.DataSource = dt;
  182. }
  183. }
  184. }