Packing_PackageCollectionIn.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. using LabelManager2;
  2. using System;
  3. using System.Data;
  4. using System.Windows.Forms;
  5. using UAS_MES_NEW.DataOperate;
  6. using UAS_MES_NEW.Entity;
  7. using UAS_MES_NEW.PublicMethod;
  8. using System.Drawing;
  9. using System.Threading;
  10. using UAS_MES_NEW.PublicForm;
  11. using System.Collections.Generic;
  12. using System.Diagnostics;
  13. using System.Runtime.InteropServices;
  14. using DevExpress.Printing.Core.PdfExport.Metafile;
  15. //using Seagull.BarTender.Print;
  16. namespace UAS_MES_NEW.Packing
  17. {
  18. public partial class Packing_PackageCollectionIn : Form
  19. {
  20. DataHelper dh;
  21. DataTable dt;
  22. LogStringBuilder sql = new LogStringBuilder();
  23. AutoSizeFormClass asc = new AutoSizeFormClass();
  24. ApplicationClass lbl;
  25. BarTender.Application engine;
  26. Thread thread;
  27. DataTable Dbfind;
  28. string ErrorMessage = "";
  29. string oMakeCode = "";
  30. string oMsID = "";
  31. string oMsStatus = "";
  32. string oOutBoxCode = "";
  33. decimal StandardQTY = 0;
  34. string LastSncode;
  35. Document doc;
  36. string PR_CHECKCARTONW = "0";
  37. ModeBusTCPServer md;
  38. public Packing_PackageCollectionIn()
  39. {
  40. InitializeComponent();
  41. }
  42. //创建打印进程
  43. private void NewPrint()
  44. {
  45. try
  46. {
  47. engine = new BarTender.Application();
  48. //lbl = new ApplicationClass();
  49. //BaseUtil.WriteLbl();
  50. }
  51. catch (Exception ex)
  52. {
  53. OperateResult.AppendText("未正确安装打印软件\n" + ex.Message, Color.Red);
  54. }
  55. }
  56. private void PackCollection_Load(object sender, EventArgs e)
  57. {
  58. // 杀死之前全部未关闭的进程
  59. Process[] processes = System.Diagnostics.Process.GetProcessesByName("lppa");
  60. Process[] processes1 = System.Diagnostics.Process.GetProcessesByName("bartend");
  61. for (int i = 0; i < processes1.Length; i++)
  62. {
  63. processes1[i].Kill();
  64. }
  65. for (int i = 0; i < processes.Length; i++)
  66. {
  67. processes[i].Kill();
  68. }
  69. //设置DbFind的必须的数据
  70. PrintNum.Text = "1";
  71. asc.controllInitializeSize(this);
  72. thread = new Thread(NewPrint);
  73. thread.Start();
  74. md = new ModeBusTCPServer();
  75. dh = SystemInf.dh;
  76. }
  77. private void PackCollection_SizeChanged(object sender, EventArgs e)
  78. {
  79. asc.controlAutoSize(this);
  80. }
  81. private void PackCollection_Activated(object sender, EventArgs e)
  82. {
  83. ct_code.Focus();
  84. }
  85. //刷新表单的数据的数据
  86. private void LoadData()
  87. {
  88. LoadCollectedNum();
  89. }
  90. private void LoadGridData()
  91. {
  92. //加载Grid数据
  93. dt = (DataTable)dh.ExecuteSql(" select * from CUSTOMTABLEDETAIL left join CUSTOMTABLE on cd_ctid = ct_id where ct_code = '"+ct_code.Text+ "' and ct_caller='CAFEN' order by cd_id asc ", "select");
  94. BaseUtil.FillDgvWithDataTable(PackageDetail, dt);
  95. }
  96. private void Print_Click(object sender, EventArgs e)
  97. {
  98. }
  99. //加载工单信息和装箱明细信息
  100. private void pa_code_KeyDown(object sender, KeyEventArgs e)
  101. {
  102. if (e.KeyCode == Keys.Enter)
  103. {
  104. if (!dh.CheckExist("CUSTOMTABLE", "ct_code = '" + ct_code.Text + "' and CT_CALLER = 'CAFEN'"))
  105. {
  106. OperateResult.AppendText(">>单据" + ct_code.Text + "不存在\n", Color.Red, ct_code);
  107. return;
  108. }
  109. dt = (DataTable)dh.ExecuteSql(" select * from CUSTOMTABLE where ct_code = '" + ct_code.Text + "' ", "select");
  110. BaseUtil.SetFormValue(this.Controls, dt);
  111. LoadGridData();
  112. }
  113. }
  114. //输入序列号的回车事件
  115. private void barcode_KeyDown(object sender, KeyEventArgs e)
  116. {
  117. }
  118. private void Clean_Click(object sender, EventArgs e)
  119. {
  120. OperateResult.Clear();
  121. }
  122. DataTable _dt;
  123. private void pr_code_TextChanged(object sender, EventArgs e)
  124. {
  125. _dt = (DataTable)dh.ExecuteSql("select la_id,la_sql from label where la_name='CAFEN'", "select");
  126. PrintLabel.DataSource = _dt;
  127. PrintLabel.DisplayMember = "la_sql";
  128. PrintLabel.ValueMember = "la_id";
  129. }
  130. private void PackCollection_FormClosing(object sender, FormClosingEventArgs e)
  131. {
  132. BaseUtil.ClosePrint(lbl);
  133. if (engine != null)
  134. engine.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
  135. dh.Dispose();
  136. }
  137. private void Packing_Click(object sender, EventArgs e)
  138. {
  139. }
  140. bool AutoCut;
  141. //private void pr_outboxinnerqty_KeyDown(object sender, KeyEventArgs e)
  142. //{
  143. // if (e.KeyCode == Keys.Enter)
  144. // ResetPackQTY();
  145. //}
  146. //private void pr_outboxinnerqty_Leave(object sender, EventArgs e)
  147. //{
  148. // ResetPackQTY();
  149. //}
  150. //private void ResetPackQTY()
  151. //{
  152. // //数据不符合限制的时候保持原有值
  153. // int curretnqty = int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text);
  154. // if (!(int.Parse(pr_outboxinnerqty.Text) >= curretnqty))
  155. // {
  156. // pr_outboxinnerqty.Text = StandardQTY.ToString();
  157. // }
  158. // else
  159. // {
  160. // if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  161. // {
  162. // string checknostatus = dh.getFieldDataByCondition("oqcbatch", "ob_status", "ob_checkno='" + pa_checkno.Text + "'").ToString();
  163. // if (checknostatus == "" || checknostatus == "ENTERING")
  164. // {
  165. // if (pa_downstatus.Text == "0")
  166. // {
  167. // if (dh.CheckExist("source", "sc_code='" + pa_sccode.Text + "' and sc_stepcode='" + User.CurrentStepCode + "'"))
  168. // {
  169. // dh.UpdateByCondition("package", "pa_standardqty='" + pr_outboxinnerqty.Text + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  170. // LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "修改箱内容量", "原容量" + StandardQTY + ",修改为" + pr_outboxinnerqty.Text + "'", pa_outboxcode.Text, pa_checkno.Text);
  171. // return;
  172. // }
  173. // else
  174. // OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "当前所在工序不是登录岗位资源所在工序,不允许修改数量\n", Color.Red);
  175. // }
  176. // else
  177. // OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "处于下地状态,不允许修改标准容量\n", Color.Red);
  178. // }
  179. // else
  180. // OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "处于送检中,不允许修改标准容量\n", Color.Red);
  181. // }
  182. // else
  183. // OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在,修改容量无效\n", Color.Red);
  184. // pr_outboxinnerqty.Text = StandardQTY.ToString();
  185. // }
  186. //}
  187. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  188. {
  189. }
  190. private void DeleteAll_Click(object sender, EventArgs e)
  191. {
  192. }
  193. private void LoadCollectedNum()
  194. {
  195. }
  196. private void pa_remark_KeyDown(object sender, KeyEventArgs e)
  197. {
  198. }
  199. private void PreFix_KeyDown(object sender, KeyEventArgs e)
  200. {
  201. }
  202. private void BuildServer_Click(object sender, EventArgs e)
  203. {
  204. }
  205. private void CloseServer_Click(object sender, EventArgs e)
  206. {
  207. if (md.IsOpen)
  208. {
  209. md.Close();
  210. OperateResult.AppendText(">>服务关闭成功\n");
  211. }
  212. else
  213. OperateResult.AppendText(">>服务尚未开启\n");
  214. }
  215. private void Remark_PreFix_KeyDown(object sender, KeyEventArgs e)
  216. {
  217. }
  218. private void PackageDetail_CellContentClick(object sender, DataGridViewCellEventArgs e)
  219. {
  220. if (PackageDetail.Columns[e.ColumnIndex].Name == "print" && e.RowIndex >= 0)
  221. {
  222. Console.WriteLine(PackageDetail.Rows[e.RowIndex].Cells["cd_id"].Value.ToString());
  223. int fenshu;
  224. try
  225. {
  226. fenshu = int.Parse(PrintNum.Text.ToString());
  227. }
  228. catch (Exception ex)
  229. {
  230. OperateResult.AppendText(">>打印数量以及打印张数不符合要求\n",Color.Red);
  231. return;
  232. }
  233. if (fenshu > 0)
  234. {
  235. if (!Print.SinglePrint(Tag.ToString(), engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrintList.Text, PackageDetail.Rows[e.RowIndex].Cells["cd_id"].Value.ToString(), int.Parse(PrintNum.Text), "", "", "", "", out ErrorMessage))
  236. {
  237. OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
  238. }
  239. }
  240. else
  241. {
  242. OperateResult.AppendText(">>打印张数不符合要求\n", Color.Red);
  243. return;
  244. }
  245. }
  246. }
  247. }
  248. }