Make_FuselageLabelPrint.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using UAS_MES_NEW.DataOperate;
  7. using UAS_MES_NEW.PublicMethod;
  8. using UAS_MES_NEW.Entity;
  9. using LabelManager2;
  10. using System.IO;
  11. using System.Threading;
  12. using UAS_MES_NEW.PublicForm;
  13. using Seagull.BarTender.Print;
  14. using static System.Runtime.CompilerServices.RuntimeHelpers;
  15. namespace UAS_MES_NEW.Make
  16. {
  17. public partial class Make_FuselageLabelPrint : Form
  18. {
  19. DataHelper dh;
  20. DataTable dt;
  21. LogStringBuilder sql = new LogStringBuilder();
  22. Document doc;
  23. AutoSizeFormClass asc = new AutoSizeFormClass();
  24. //保存StepProduct查询出来的数据
  25. // DataTable ListA = new DataTable();
  26. //保存make left join makecraftdetail left join product的数据
  27. // DataTable ListB;
  28. DataTable mapB;
  29. string ma_unlimitin = "";
  30. ApplicationClass lbl;
  31. string oMakeCode = "";
  32. string oMsId = "";
  33. string oErrorMessage = "";
  34. Thread InitPrint;
  35. bool pr_change = false;
  36. ftpOperater ftp;
  37. DataTable Dbfind;
  38. public Make_FuselageLabelPrint()
  39. {
  40. InitializeComponent();
  41. }
  42. private void Make_FuselageLabelPrint_Load(object sender, EventArgs e)
  43. {
  44. asc.controllInitializeSize(this);
  45. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  46. InitPrint = new Thread(InPrint);
  47. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
  48. BaseUtil.SetFormCenter(stw);
  49. stw.ShowDialog();
  50. sncode.Focus();
  51. LockMakeCode.GetMakeCodeCtl(ma_code);
  52. ma_code.SetLockCheckBox(LockMakeCode);
  53. //工单号放大镜配置
  54. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  55. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,pr_detail # 产品名称";
  56. ma_code.FormName = Name;
  57. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "pr_detail" };
  58. ma_code.DbChange += Ma_code_DbChange;
  59. ma_code.Condition = "(ma_statuscode='STARTED' or ma_statuscode='FINISH')";
  60. dh = SystemInf.dh;
  61. StepCount.StepCode = User.CurrentStepCode;
  62. StepCount.Source = User.UserSourceCode;
  63. StepCount.LineCode = User.UserLineCode;
  64. StepCount.Dh = dh;
  65. StepCount.Start();
  66. }
  67. private void Ma_code_DbChange(object sender, EventArgs e)
  68. {
  69. Dbfind = ma_code.ReturnData;
  70. BaseUtil.SetFormValue(this.Controls, Dbfind);
  71. ////获取工单的其他信息
  72. //sql.Clear();
  73. //sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode as pr_code ,pr_detail,");
  74. //sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty from make left join makecraftdetail on ");
  75. //sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  76. //dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  77. //if (dt.Rows.Count > 0)
  78. //{
  79. // BaseUtil.SetFormValue(this.Controls, dt);
  80. //}
  81. }
  82. Engine engine;
  83. private void InPrint()
  84. {
  85. try
  86. {
  87. engine = new Engine(true);
  88. }
  89. catch (Exception ex)
  90. {
  91. OperateResult.AppendText("未正确安装BarTender软件\n", Color.Red);
  92. }
  93. }
  94. private void sn_code_KeyDown(object sender, KeyEventArgs e)
  95. {
  96. //按下enter键
  97. if (e.KeyCode == Keys.Enter)
  98. {
  99. //如果输入的值为空的话,提示不能为空
  100. if (sncode.Text == "")
  101. {
  102. OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
  103. return;
  104. }
  105. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out oErrorMessage))
  106. {
  107. //定义临时变量
  108. string oStatus = "";
  109. //调用公共方法CheckStepSNAndMacode判断工序是否正确
  110. string status = "";
  111. dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei1='" + sncode.Text + "' order by ms_id desc", "select");
  112. if (dt.Rows.Count > 0)
  113. {
  114. sncode.Text = dt.Rows[0]["ms_sncode"].ToString();
  115. }
  116. else
  117. {
  118. dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei2='" + sncode.Text + "' order by ms_id desc", "select");
  119. if (dt.Rows.Count > 0)
  120. {
  121. sncode.Text = dt.Rows[0]["ms_sncode"].ToString();
  122. }
  123. else
  124. {
  125. dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei1='" + sncode.Text + "' order by mil_id desc", "select");
  126. if (dt.Rows.Count > 0)
  127. {
  128. sncode.Text = dt.Rows[0]["mil_sncode"].ToString();
  129. }
  130. else
  131. {
  132. dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei2='" + sncode.Text + "' order by mil_id desc", "select");
  133. if (dt.Rows.Count > 0)
  134. {
  135. sncode.Text = dt.Rows[0]["mil_sncode"].ToString();
  136. }
  137. }
  138. }
  139. }
  140. LogicHandler.GetMakeInfo(sncode.Text, out oMakeCode, out status, out oErrorMessage);
  141. if (oMakeCode == "" || oMakeCode == null)
  142. oMakeCode = ma_code.Text;
  143. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsId, out oErrorMessage))
  144. {
  145. string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsId + "'").ToString();
  146. if (nextstepcode != User.CurrentStepCode)
  147. {
  148. string stname = dh.getFieldDataByCondition("step", "st_name", "st_code='" + nextstepcode + "'").ToString();
  149. OperateResult.AppendText("<<序列号:" + sncode.Text + "下一工序是" + stname + ",不是当前岗位的工序\n", Color.Red, sncode);
  150. return;
  151. }
  152. //IF (如果ma_code 为空)THEN
  153. if (ma_code.Text == "" || ma_code.Text != oMakeCode)
  154. {
  155. //获取工单的其他信息
  156. sql.Clear();
  157. sql.Append("select ma_code,nvl(mcd_okqty,0),ma_prodcode,pr_detail,nvl(ma_unlimitin,0)ma_unlimitin,");
  158. sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty from make left join makecraftdetail on ");
  159. sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + oMakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  160. mapB = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  161. //如果有数据的话
  162. if (mapB.Rows.Count > 0)
  163. {
  164. ma_unlimitin = mapB.Rows[0]["ma_unlimitin"].ToString();
  165. //将工单的其他信息赋值到对应的控件
  166. BaseUtil.SetFormValue(this.Controls, mapB);
  167. //提示用户“<<工单号:取ma_makecode”
  168. OperateResult.AppendText("<<工单号:" + ma_code.Text + "\n", Color.Black);
  169. //提示用户“<< 序列号:XXXX”
  170. if (PrintLabel.SelectedValue == null)
  171. {
  172. OperateResult.AppendText(">>产品编号:" + ma_prodcode.Text + "未维护机身标签\n", Color.Red, sncode);
  173. return;
  174. }
  175. if (pr_change)
  176. {
  177. pr_change = false;
  178. if (MessageBox.Show("是否使用默认标签", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
  179. {
  180. OperateResult.AppendText(">>请选择标签模板\n", Color.Green, sncode);
  181. return;
  182. }
  183. }
  184. }
  185. //没有数据
  186. else
  187. {
  188. OperateResult.AppendText(">>无序列号" + sncode.Text + "对应工单信息\n", Color.Red);
  189. return;
  190. }
  191. }
  192. //所选标签不为空
  193. if (PrintLabel.SelectedValue != null)
  194. {
  195. //如果打印张数为空,返回
  196. if (PrintNum.Text == "" || int.Parse(PrintNum.Text) == 0)
  197. {
  198. OperateResult.AppendText(">>打印张数不可空或者为0\n", Color.Red, sncode);
  199. //清空输入框的值,聚焦
  200. sncode.Focus();
  201. //提示用户“>>请输入SN”
  202. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  203. return;
  204. }
  205. OperateResult.AppendText("<<序列号:" + sncode.Text + "\n", Color.Black);
  206. //按照打印张数打印
  207. //doc = lbl.Documents.Open(PrintLabel.Text);
  208. if (Print.BarTenderS(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, sncode.Text, int.Parse(PrintNum.Text), oMakeCode, ma_prodcode.Text, "机身标", "0", out oErrorMessage))
  209. {
  210. //提示用户打印成功
  211. OperateResult.AppendText(">>序列号:" + sncode.Text + "打印结束\n", Color.Green);
  212. }
  213. else
  214. {
  215. OperateResult.AppendText(oErrorMessage + "\n", Color.Red);
  216. }
  217. //if (Print.CodeSoft(Tag.ToString(), ref lbl, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, sncode.Text, int.Parse(PrintNum.Text), oMakeCode, ma_prodcode.Text, "机身标", "0", out oErrorMessage))
  218. //{
  219. // //提示用户打印成功
  220. // OperateResult.AppendText(">>序列号:" + sncode.Text + "打印成功\n", Color.Green);
  221. //}
  222. //else
  223. //{
  224. // OperateResult.AppendText(oErrorMessage + "\n", Color.Red);
  225. //}
  226. //记录日志
  227. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "机身标打印", "机身标打印成功", sncode.Text, "");
  228. //更新打印的数据
  229. if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, sncode.Text, "机身标打印", "机身标打印成功", User.UserCode, out oErrorMessage))
  230. {
  231. //提示正确返回时传递的信息
  232. if (oErrorMessage.Contains("AFTERSUCCESS"))
  233. OperateResult.AppendText(">>" + oErrorMessage + "\n");
  234. if (CollectRemark.Checked && Remark.Text != "")
  235. {
  236. LogicHandler.CollectRemarkInf(sncode.Text, "", "", oMakeCode, ma_prodcode.Text, Remark.Text);
  237. }
  238. //清空输入框的值,聚焦
  239. sncode.Text = "";
  240. sncode.Focus();
  241. //刷新打印数量和剩余数量
  242. dt = (DataTable)dh.ExecuteSql("select ma_qty - nvl(mcd_inqty, 0) mcd_remainqty,nvl(ma_unlimitin,0)ma_unlimitin from make left join makecraftdetail on mcd_macode=ma_code where ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'", "select");
  243. BaseUtil.SetFormValue(Controls, dt);
  244. mcd_okqty.Text = int.Parse(mcd_okqty.Text) + 1 + "";
  245. //IF 剩余数=0,则清空form中的数据, 提示用户“工单:xx已经打印完成,>>请输入SN”, 清空mapB,listC 中的数据
  246. if (int.Parse(mcd_remainqty.Text) == 0 && ma_unlimitin == "0")
  247. {
  248. OperateResult.AppendText(">>工单:" + ma_code.Text + "打印完成,>>请输入SN\n", Color.Green);
  249. }
  250. //剩余数量不为0
  251. else
  252. {
  253. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  254. }
  255. }
  256. else
  257. {
  258. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  259. //清空输入框的值,聚焦
  260. sncode.Text = "";
  261. sncode.Focus();
  262. }
  263. }
  264. //标签为空
  265. else
  266. {
  267. OperateResult.AppendText(">>产品编号:" + ma_prodcode.Text + "未维护机身标签\n", Color.Red, sncode);
  268. }
  269. }
  270. else
  271. {
  272. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  273. }
  274. }
  275. else
  276. {
  277. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  278. }
  279. }
  280. }
  281. private void pr_code_TextChanged(object sender, EventArgs e)
  282. {
  283. DataTable _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault,replace(LA_SOFTTYPE,';',',')LA_SOFTTYPE from label where la_prodcode='" + ma_prodcode.Text + "' and la_templatetype='机身标' and la_statuscode='AUDITED' order by la_isdefault", "select");
  284. if (_dt.Rows.Count == 0)
  285. {
  286. _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault,replace(LA_SOFTTYPE,';',',')LA_SOFTTYPE from label where la_prodcode is null and la_templatetype='机身标' and la_statuscode='AUDITED' order by la_isdefault", "select");
  287. }
  288. if (_dt.Rows.Count > 0)
  289. {
  290. string la_id = _dt.Rows[0]["la_id"].ToString();
  291. _dt = (DataTable)dh.ExecuteSql("select fp_name la_url,'" + la_id + "' la_id from FILEPATH where fp_id in (select * from table(select parsestring(LA_SOFTTYPE,';') from label where la_id='"+la_id+"' ) where COLUMN_VALUE is not null)", "select");
  292. PrintLabel.DataSource = _dt;
  293. PrintLabel.DisplayMember = "la_url";
  294. PrintLabel.ValueMember = "la_id";
  295. pr_change = true;
  296. }
  297. }
  298. private void Make_FuselageLabelPrint_Activated(object sender, EventArgs e)
  299. {
  300. sncode.Focus();
  301. }
  302. private void Make_FuselageLabelPrint_FormClosing(object sender, FormClosingEventArgs e)
  303. {
  304. BaseUtil.ClosePrint(lbl);
  305. }
  306. private void Make_FuselageLabelPrint_SizeChanged(object sender, EventArgs e)
  307. {
  308. asc.controlAutoSize(this);
  309. }
  310. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  311. {
  312. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  313. {
  314. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  315. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  316. }
  317. }
  318. private void StepCount_Load(object sender, EventArgs e)
  319. {
  320. }
  321. }
  322. }