Make_RePrintLabel.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. using LabelManager2;
  2. using Seagull.BarTender.Print;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Windows.Forms;
  12. using UAS_MES_NEW.DataOperate;
  13. using UAS_MES_NEW.Entity;
  14. using UAS_MES_NEW.PublicForm;
  15. using UAS_MES_NEW.PublicMethod;
  16. namespace UAS_MES_NEW.Make
  17. {
  18. public partial class Make_RePrintLabel : Form
  19. {
  20. DataHelper dh;
  21. LogStringBuilder sql = new LogStringBuilder();
  22. AutoSizeFormClass asc = new AutoSizeFormClass();
  23. Engine engine;
  24. Thread InitPrint;//实例化打印进程
  25. DataTable dt;
  26. DataTable listA;
  27. string getlabel = "";
  28. DataTable mapB;
  29. string ms_id = "";
  30. DataTable formValue;//界面赋值
  31. string type = "";
  32. string errorMessage = "";
  33. public Make_RePrintLabel()
  34. {
  35. InitializeComponent();
  36. }
  37. private void Make_RePrintLabel_Load(object sender, EventArgs e)
  38. {
  39. asc.controllInitializeSize(this);
  40. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  41. InitPrint = new Thread(InPrint);
  42. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
  43. BaseUtil.SetFormCenter(stw);
  44. stw.ShowDialog();
  45. inputText.Focus();
  46. dh = SystemInf.dh;
  47. }
  48. private void InPrint()
  49. {
  50. try
  51. {
  52. engine = new Engine(true);
  53. BaseUtil.WriteLbl();
  54. }
  55. catch (Exception)
  56. {
  57. OperateResult.AppendText("未正确安装Bartender软件\n", Color.Red);
  58. }
  59. }
  60. private void Make_RePrintLabel_SizeChanged(object sender, EventArgs e)
  61. {
  62. //窗体大小变化的时候
  63. asc.controlAutoSize(this);
  64. }
  65. private void Make_RePrintLabel_FormClosing(object sender, FormClosingEventArgs e)
  66. {
  67. //窗口关闭的时候
  68. BaseUtil.ClosePrint(engine);
  69. }
  70. private void radioButton_CheckedChange(object sender, EventArgs e)
  71. {
  72. RadioButton btn = sender as RadioButton;
  73. if ((btn.Name == "giftBox" || btn.Name == "fuselagel") && btn.Checked)
  74. {
  75. //如果是切换成彩盒或者机身标提示用户 输入SN
  76. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  77. clearAll();
  78. }
  79. else if (btn.Name == "CartonBox" && btn.Checked)
  80. {
  81. OperateResult.AppendText(">>请输入卡通箱号\n", Color.Black);
  82. clearAll();
  83. }
  84. }
  85. private void inputText_KeyDown(object sender, KeyEventArgs e)
  86. {
  87. //按下enter键
  88. if (e.KeyCode == Keys.Enter)
  89. {
  90. if (inputText.Text == "")
  91. {
  92. OperateResult.AppendText("<<输入不能为空\n", Color.Red);
  93. return;
  94. }
  95. OperateResult.AppendText(">>" + inputText.Text + "\n", Color.Black);
  96. //打印类型为彩盒或者机身标
  97. if (giftBox.Checked || fuselagel.Checked)
  98. {
  99. //select max(ms_id)ms_id from makeserial where ms_sncode=?
  100. ms_id = dh.getFieldDataByCondition("makeserial", "max(ms_id) ms_id", "ms_sncode='" + inputText.Text + "'").ToString();
  101. //如果ms_id 无值或者为空,提示用户SN不存在,请输入SN
  102. if (ms_id == "")
  103. {
  104. OperateResult.AppendText("<<SN:" + inputText.Text + "不存在\n", Color.Red, inputText);
  105. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  106. return;
  107. }
  108. ////判断是否装箱通过
  109. //if (checkPacked())
  110. //{
  111. // return;
  112. //}
  113. //界面赋值
  114. formValue = (DataTable)dh.ExecuteSql("select ms_makecode,pr_code,pr_detail from makeserial left join product on MS_PRODCODE=pr_code where ms_id='" + ms_id + "'", "select");
  115. BaseUtil.SetFormValue(this.Controls, formValue);
  116. //无值,可补打
  117. inputValue.Text = inputText.Text;
  118. inputText.Text = "";
  119. }
  120. //打印类型为卡通箱
  121. else if (CartonBox.Checked)
  122. {
  123. //查询箱号是否存在
  124. dt = (DataTable)dh.ExecuteSql("select pa_id,pa_prodcode pr_code,pa_makecode ms_makecode,pr_detail from package left join product on pr_code=pa_prodcode where pa_outboxcode='" + inputText.Text + "' and pa_type=1", "select");
  125. if (dt.Rows.Count == 0)
  126. {
  127. //无值,返回提示用户“箱号不存在”, “>>请输入卡通箱号”
  128. OperateResult.AppendText("<<箱号:" + inputText.Text + "不存在\n", Color.Red, inputText);
  129. OperateResult.AppendText(">>请输入卡通箱号\n", Color.Black);
  130. return;
  131. }
  132. //界面赋值
  133. BaseUtil.SetFormValue(this.Controls, dt);
  134. //有值,可以打
  135. //展示产品编号和标签模板到界面
  136. inputValue.Text = inputText.Text;
  137. inputText.Text = "";
  138. }
  139. print_Click(sender, new EventArgs());
  140. }
  141. }
  142. private void PrintLabel_TextChanged(object sender, EventArgs e)
  143. {
  144. if (pr_code.Text == "")
  145. {
  146. return;
  147. }
  148. if (fuselagel.Checked)
  149. type = "机身标";
  150. else if (giftBox.Checked)
  151. type = "彩盒标";
  152. else
  153. type = "卡通箱标";
  154. getlabel = "select la_id,substr(la_url,instr(la_url,'\\',-1)+1)la_name,la_url,la_isdefault from label where la_prodcode='" + pr_code.Text + "' and la_templatetype='" + type + "' and la_statuscode='AUDITED' order by la_isdefault";
  155. listA = (DataTable)dh.ExecuteSql(getlabel, "select");
  156. if (listA.Rows.Count == 0)
  157. {
  158. OperateResult.AppendText("<<产品:" + pr_code.Text + "未维护" + type + "模板\n", Color.Red);
  159. }
  160. PrintLabel.DataSource = listA;
  161. PrintLabel.DisplayMember = "la_url";
  162. PrintLabel.ValueMember = "la_id";
  163. }
  164. private void print_Click(object sender, EventArgs e)
  165. {
  166. //输入值字段值不为空,打印不为空,有选中打印模板,才可以进行打印,打印前再次判断
  167. if (inputValue.Text == "")
  168. {
  169. OperateResult.AppendText("<<无箱号或者序列号\n", Color.Red);
  170. return;
  171. }
  172. if (PrintLabel.Text == "")
  173. {
  174. OperateResult.AppendText("<<无打印模板\n", Color.Red);
  175. return;
  176. }
  177. //打印类型 彩盒或者标签,再次判断是否已装箱,未转号
  178. if (giftBox.Checked || fuselagel.Checked)
  179. {
  180. mapB = (DataTable)dh.ExecuteSql("select ms_outboxcode, nvl(ms_downstatus,0) ms_downstatus from makeserial where ms_id='" + ms_id + "' and ms_sncode='" + inputValue.Text + "'", "select");
  181. if (mapB.Rows.Count == 0)
  182. {
  183. //无值提示用户序列号错误,不存在或者已经发生转号
  184. OperateResult.AppendText("<<序列号错误,不存在或已经发生转号\n", Color.Red);
  185. return;
  186. }
  187. //如果ms_outboxcode 不为空,则提示用户,已经装箱不允许单独打印
  188. if (mapB.Rows[0]["ms_outboxcode"].ToString() != "")
  189. {
  190. OperateResult.AppendText("<<SN:" + inputValue.Text + "已经装箱" + mapB.Rows[0]["ms_outboxcode"].ToString() + "不允许单独补打\n", Color.Red);
  191. return;
  192. }
  193. //判定通过进行打印
  194. //doc = lbl.Documents.Open(PrintLabel.Text);
  195. if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, inputValue.Text, int.Parse(printNum.Text), ms_makecode.Text, pr_code.Text, giftBox.Checked ? "彩盒标" : "机身标", "-1", out errorMessage))
  196. {
  197. //按照打印张数打印
  198. OperateResult.AppendText("<<打印成功\n", Color.Green);
  199. }
  200. else
  201. {
  202. OperateResult.AppendText(errorMessage + "\n", Color.Red);
  203. }
  204. //打印成功,记录日志commandlog , cl_operate彩盒或者机身标补打印,cl_result补打印成功
  205. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, giftBox.Checked ? "彩盒标补打印" : "机身标补打印", "补打印成功", inputValue.Text, "");
  206. //如果ms_downstatus<>0,则更新ms_downstatus=-1 where ms_id=?id,同时插入记录至表 MAKEDOWN
  207. if (mapB.Rows[0]["ms_downstatus"].ToString() == "0")
  208. {
  209. //dh.ExecuteSql("update makeserial set ms_downstatus='-1' where ms_id='" + ms_id + "'", "update");
  210. //插入数据
  211. //putInfo2MakeDown();
  212. }
  213. }
  214. //打印类型为卡通箱标签
  215. else if (CartonBox.Checked)
  216. {
  217. //select pa_downstatus from package where pa_outboxcode=? 输入值code
  218. mapB = (DataTable)dh.ExecuteSql("select pa_downstatus from package where pa_outboxcode='" + inputValue.Text + "'", "select");
  219. //无值提示用户箱号错误,不存在。
  220. if (mapB.Rows.Count == 0)
  221. {
  222. OperateResult.AppendText("<<箱号:" + inputValue.Text + "错误,不存在\n", Color.Red);
  223. return;
  224. }
  225. //doc = lbl.Documents.Open(PrintLabel.Text);
  226. if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, inputValue.Text, int.Parse(printNum.Text), ms_makecode.Text, pr_code.Text, "卡通箱标", "-1", out errorMessage))
  227. {
  228. //判断通过,打印
  229. OperateResult.AppendText("<<打印成功\n", Color.Green);
  230. }
  231. else
  232. {
  233. OperateResult.AppendText(errorMessage + "\n", Color.Red);
  234. }
  235. //打印成功,记录日志commandlog , cl_operate彩盒或者机身标补打印,cl_result补打印成功
  236. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱标签补打印,箱号:" + inputValue.Text, "补打印成功", inputValue.Text, "");
  237. //如果pa_downstatus<>0,则更新pa_downstatus=-1 where pa_outboxcode=?code,同时插入记录至表 MAKEDOWN
  238. //if (mapB.Rows[0]["pa_downstatus"].ToString() == "0")
  239. //{
  240. // dh.ExecuteSql("update package set pa_downstatus='-1' where pa_outboxcode='" + inputValue.Text + "'", "update");
  241. // //插入MakeDown表
  242. // putInfo2MakeDown();
  243. //}
  244. }
  245. }
  246. /// <summary>
  247. /// 判断彩盒和机身标序列是否已经装箱
  248. /// </summary>
  249. /// <returns></returns>
  250. private bool checkPacked()
  251. {
  252. //如果存在,则判断是否装箱
  253. dt = (DataTable)dh.ExecuteSql("select ms_id,ms_prodcode,ms_makecode,pr_detail, ms_outboxcode from makeserial left join product on pr_code=ms_prodcode where ms_id='" + ms_id + "'", "select");
  254. //判断ms_outboxcode 是否为空,如果有值,则返回提示用户“已经装箱
  255. if (dt.Rows.Count == 0)
  256. {
  257. OperateResult.AppendText("<<SN:" + inputText.Text + "不存在\n", Color.Red, inputText);
  258. return true;
  259. }
  260. if (dt.Rows[0]["ms_outboxcode"].ToString() != "")
  261. {
  262. OperateResult.AppendText("<<SN:" + inputText.Text + "已经装箱" + dt.Rows[0]["ms_outboxcode"].ToString() + "不允许单独补打\n", Color.Red, inputText);
  263. return true;
  264. }
  265. return false;
  266. }
  267. /// <summary>
  268. /// 插入表MAKEDOWN
  269. /// </summary>
  270. private void putInfo2MakeDown()
  271. {
  272. //插入数据至表MAKEDOWN
  273. string md_code = "";
  274. LogicHandler.GetSerialNumByCaller("MakeDown", out md_code);
  275. sql.Clear();
  276. sql.Append("INSERT INTO MAKEDOWN (MD_ID,MD_LINECODE,MD_SCCODE,MD_STEPCODE,");
  277. sql.Append((CartonBox.Checked ? "MD_OUTBOXCODE" : "MD_SNCODE") + ",MD_PRODCODE,MD_MACODE, MD_DOWNREASON, MD_CODE,");
  278. sql.Append("MD_DOWNDATE,MD_DOWNMAN,MD_STATUS) values (MAKEDOWN_seq.nextval,'" + User.UserLineCode + "','" + User.UserSourceCode + "',");
  279. sql.Append("'" + User.CurrentStepCode + "','" + inputValue.Text + "','" + pr_code.Text + "','" + ms_makecode.Text + "','补打标签','" + md_code + "',sysdate,'" + User.UserCode + "','-1')");
  280. dh.ExecuteSql(sql.GetString(), "insert");
  281. }
  282. private void rePrintCheck_KeyDown(object sender, KeyEventArgs e)
  283. {
  284. }
  285. /// <summary>
  286. /// 清除信息
  287. /// </summary>
  288. private void clearAll()
  289. {
  290. //清除输入值、工单代码、产品编号,名称、打印模板、核对第一次输入的SN
  291. inputValue.Text = "";
  292. ms_makecode.Text = "";
  293. pr_code.Text = "";
  294. pr_detail.Text = "";
  295. if (listA != null)
  296. {
  297. listA.Clear();
  298. }
  299. }
  300. }
  301. }