Make_FuselageLabelPrint.cs 15 KB

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