Make_Aging.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using UAS_MES_NEW.DataOperate;
  10. using UAS_MES_NEW.Entity;
  11. using UAS_MES_NEW.PublicMethod;
  12. namespace UAS_MES_NEW.Make
  13. {
  14. public partial class Make_Aging : Form
  15. {
  16. DataHelper dh;
  17. AutoSizeFormClass asc = new AutoSizeFormClass();
  18. LogStringBuilder sql = new LogStringBuilder();
  19. DataTable dt;
  20. //当前序列号记录
  21. string sn_code;
  22. //制造单号
  23. string macode;
  24. //采集网标号
  25. float net_code;
  26. //网标查询条件ms_id
  27. string oMsID;
  28. //打印计数
  29. int printcount = 0;
  30. int ma_unlimitin;
  31. string ErrorMessage = "";
  32. string LastSncode;
  33. public Make_Aging()
  34. {
  35. InitializeComponent();
  36. }
  37. private void Make_CollectNetCode_Load(object sender, EventArgs e)
  38. {
  39. asc.controllInitializeSize(this);
  40. sncode.Focus();
  41. dh = SystemInf.dh;
  42. }
  43. private void sncode_KeyDown(object sender, KeyEventArgs e)
  44. {
  45. if (e.KeyCode == Keys.Enter)
  46. {
  47. string ErrorMessage2;
  48. string oMakeCode;
  49. //采集序列号
  50. if (sncode.Text == "")
  51. {
  52. OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
  53. return;
  54. }
  55. if (!quxiao.Checked)
  56. {
  57. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage2))
  58. {
  59. //判断界面工单是否为空时的序列号是否自动归属工单
  60. string oStatus = "";
  61. if (!LogicHandler.GetMakeInfo(sncode.Text, out oMakeCode, out oStatus, out ErrorMessage2))
  62. {
  63. if (ms_makecode.Text == "")
  64. {
  65. OperateResult.AppendText(">>" + ErrorMessage2 + "\n", Color.Red, sncode);
  66. return;
  67. }
  68. }
  69. //OperateResult.AppendText("<<" + sncode.Text + "\n", Color.Black);
  70. dt = (DataTable)dh.ExecuteSql("select ms_status,ms_id,ms_makecode,ms_nextstepcode,ms_craftcode,ms_prodcode from makeserial left join product on ms_prodcode = pr_code where ms_sncode ='" + sncode.Text + "' order by ms_id desc", "select");
  71. if (dt.Rows.Count == 0)
  72. {
  73. OperateResult.AppendText(">>SN:" + sncode.Text + "不存在\n", Color.Red, sncode);
  74. return;
  75. }
  76. //判断工单工序
  77. // 获取工单归属工单下一工序是否正确
  78. if (LogicHandler.CheckStepSNAndMacode(ms_makecode.Text == "" ? oMakeCode : ms_makecode.Text, User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage2) || (dt.Rows.Count > 0 && dt.Rows[0]["ms_status"].ToString() == "1"))
  79. {
  80. if (oMsID == "" || oMsID == "null" || oMsID == "0")
  81. {
  82. oMsID = dt.Rows[0]["ms_id"].ToString();
  83. oMakeCode = dt.Rows[0]["ms_makecode"].ToString();
  84. }
  85. sql.Clear();
  86. sql.Append("select ms_makecode,ms_prodcode,pr_detail,ms_craftcode from makeserial left join product on ");
  87. sql.Append(" ms_prodcode = pr_code where ms_id = '" + oMsID + "'");
  88. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  89. BaseUtil.SetFormValue(this.Controls, dt);
  90. sn_code = sncode.Text;
  91. }
  92. else
  93. {
  94. OperateResult.AppendText(">>" + ErrorMessage2 + "\n", Color.Red, sncode);
  95. return;
  96. }
  97. if (agcode.Text == "")
  98. {
  99. if (checkBox1.Checked)
  100. {
  101. agcode.Text = LogicHandler.GetAGCode();
  102. fildgv();
  103. }
  104. else
  105. {
  106. DataTable dtc = (DataTable)dh.ExecuteSql("select ag_code,ag_status from ageingdetail left join ageing on agd_agid = ag_id where agd_sncode = '" + sncode.Text + "' order by agd_id desc", "select");
  107. if (dtc.Rows.Count > 0)
  108. {
  109. if (dtc.Rows[0]["ag_status"].ToString().Contains("0"))
  110. {
  111. agcode.Text = dtc.Rows[0]["ag_code"].ToString();
  112. fildgv();
  113. sncode.Text = "";
  114. return;
  115. }
  116. else if (dtc.Rows[0]["ag_status"].ToString().Contains("1"))
  117. {
  118. OperateResult.AppendText(">>SN:" + sncode.Text + "处于老化中老化批:" + dtc.Rows[0]["ag_code"].ToString() + "中,无法采集进新批\n", Color.Red, sncode);
  119. return;
  120. }
  121. else if (dtc.Rows[0]["ag_status"].ToString().Contains("2"))
  122. {
  123. OperateResult.AppendText(">>SN:" + sncode.Text + "处于老化结束批:" + dtc.Rows[0]["ag_code"].ToString() + "中,无法采集进新批\n", Color.Red, sncode);
  124. return;
  125. }
  126. }
  127. else
  128. {
  129. OperateResult.AppendText(">>SN:" + sncode.Text + "未采集老化,老化编号不可为空\n", Color.Red, sncode);
  130. return;
  131. }
  132. }
  133. }
  134. else
  135. {
  136. fildgv();
  137. }
  138. DataTable dtB = (DataTable)dh.ExecuteSql("select ag_code from ageingdetail left join ageing on agd_agid = ag_id where agd_sncode = '" + sncode.Text + "' and ag_status <>2", "select");
  139. if (dtB.Rows.Count > 0)
  140. {
  141. OperateResult.AppendText(">>SN:" + sncode.Text + "处于未结束老化批:" + dtB.Rows[0]["ag_code"].ToString() + "中,无法采集进新批\n", Color.Red, sncode);
  142. return;
  143. }
  144. if (dh.CheckExist("craft left join craftdetail on cr_id = cd_crid", "cr_code = '" + dt.Rows[0]["ms_craftcode"].ToString() + "' and cr_prodcode = '" + dt.Rows[0]["ms_prodcode"].ToString() + "' and cd_stepcode = 'Aging'"))
  145. {
  146. if (LogicHandler.CheckStepSNAndMacode(ms_makecode.Text == "" ? oMakeCode : ms_makecode.Text, User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage2))
  147. {
  148. //良品信息采集
  149. if (LogicHandler.SetStepResult(ms_makecode.Text, User.UserSourceCode, sncode.Text, "老化采集", "采集成功", User.UserCode, out ErrorMessage))
  150. {
  151. //提示正确返回时传递的信息
  152. if (ErrorMessage.Contains("AFTERSUCCESS"))
  153. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  154. LastSncode = sncode.Text;
  155. }
  156. else
  157. {
  158. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sncode);
  159. return;
  160. }
  161. }
  162. else
  163. {
  164. OperateResult.AppendText(">>" + ErrorMessage2 + "\n", Color.Red, sncode);
  165. return;
  166. }
  167. }
  168. else
  169. {
  170. LastSncode = sncode.Text;
  171. }
  172. if (!dh.CheckExist("ageing", "ag_code = '" + agcode.Text + "'"))
  173. {
  174. dh.ExecuteSql("insert into ageing(ag_id,ag_code,ag_indate,ag_status) values(ageing_seq.nextval,'" + agcode.Text + "',sysdate,0)", "insert");
  175. }
  176. dh.ExecuteSql("insert into ageingdetail(agd_id,agd_agid,agd_agcode,agd_makecode,agd_sncode,agd_indate) select ageingdetail_seq.nextval,ag_id,ag_code,'" + ms_makecode.Text + "','" + sncode.Text + "',sysdate from ageing where ag_code = '" + agcode.Text + "'", "insert");
  177. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "老化采集" + agcode.Text, "采集成功", LastSncode, "");
  178. OperateResult.AppendText(">>" + sncode.Text + "老化采集成功\n", Color.Green, sncode);
  179. fildgv();
  180. }
  181. else OperateResult.AppendText(">>" + ErrorMessage2 + "\n", Color.Red, sncode);
  182. }
  183. else {
  184. if (agcode.Text == "")
  185. {
  186. OperateResult.AppendText(">>老化编号不可为空\n", Color.Red, sncode);
  187. return;
  188. }
  189. else
  190. {
  191. fildgv();
  192. }
  193. DataTable dtB = (DataTable)dh.ExecuteSql("select ag_code from ageingdetail left join ageing on agd_agid = ag_id where agd_agcode = '"+agcode.Text+"' and agd_sncode = '" + sncode.Text + "' and ag_status =0", "select");
  194. if (dtB.Rows.Count > 0)
  195. {
  196. dh.ExecuteSql("delete ageingdetail where agd_agcode = '" + agcode.Text + "' and agd_sncode = '" + sncode.Text + "' ", "delete");
  197. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "取消老化采集" + agcode.Text, "取消采集成功", sncode.Text, "");
  198. OperateResult.AppendText(">>SN:" + sncode.Text + "取消采集老化批:" + dtB.Rows[0]["ag_code"].ToString() + "成功\n", Color.Green, sncode);
  199. fildgv();
  200. return;
  201. }
  202. else
  203. {
  204. OperateResult.AppendText(">>SN:" + sncode.Text + "未处于在录入老化批:" + agcode.Text + "中,无法取消采集\n", Color.Red, sncode);
  205. return;
  206. }
  207. }
  208. }
  209. }
  210. private void Make_CollectNetCode_SizeChanged(object sender, EventArgs e)
  211. {
  212. asc.controlAutoSize(this);
  213. }
  214. private void Make_CollectNetCode_Activated(object sender, EventArgs e)
  215. {
  216. sncode.Focus();
  217. }
  218. private void deleteButton1_Click(object sender, EventArgs e)
  219. {
  220. string Seal = MessageBox.Show(this.ParentForm, "是否确认老化?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  221. if (Seal == "Yes")
  222. {
  223. fildgv();
  224. if (agcode.Text != "")
  225. {
  226. dt = (DataTable)dh.ExecuteSql("select * from ageing where ag_code = '" + agcode.Text + "' and ag_status <>0 ", "select");
  227. if (dt.Rows.Count > 0)
  228. {
  229. OperateResult.AppendText(">>老化编号" + agcode.Text + "已开始或结束老化\n", Color.Red, agcode);
  230. return;
  231. }
  232. else
  233. {
  234. dh.ExecuteSql("update ageing set ag_startdate = sysdate,ag_status = 1 where ag_code = '" + agcode.Text + "'", "update");
  235. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "老化开始" + agcode.Text, "采集开始", agcode.Text, "");
  236. OperateResult.AppendText(">>" + agcode.Text + "老化批次开始\n", Color.CornflowerBlue, agcode);
  237. BaseUtil.CleanControls(this.Controls);
  238. if (!checkBox1.Checked)
  239. {
  240. agcode.Focus();
  241. }
  242. else
  243. {
  244. sncode.Focus();
  245. }
  246. }
  247. }
  248. else
  249. {
  250. OperateResult.AppendText(">>老化编号" + agcode.Text + "不可为空\n", Color.Red, agcode);
  251. return;
  252. }
  253. }
  254. }
  255. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  256. {
  257. }
  258. void fildgv()
  259. {
  260. DataTable dtc;
  261. if (agcode.Text != "")
  262. {
  263. dtc = (DataTable)dh.ExecuteSql("select * from ageingdetail left join ageing on agd_agid = ag_id where ag_code = '" + agcode.Text + "' and ag_status <>0 ", "select");
  264. if (dtc.Rows.Count > 0)
  265. {
  266. OperateResult.AppendText(">>老化编号" + agcode.Text + "已开始或结束老化\n", Color.Red, agcode);
  267. return;
  268. }
  269. else
  270. {
  271. dtc = (DataTable)dh.ExecuteSql("select * from ageingdetail left join ageing on agd_agid = ag_id where ag_code = '" + agcode.Text + "' ", "select");
  272. agsum.Text = dh.getFieldDataByCondition("ageingdetail", "count(1) cn"," agd_agcode = '"+ agcode.Text + "'").ToString();
  273. }
  274. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dtc);
  275. }
  276. }
  277. private void snCollectionBox1_KeyDown(object sender, KeyEventArgs e)
  278. {
  279. if (e.KeyCode == Keys.Enter)
  280. {
  281. fildgv();
  282. sncode.Focus();
  283. sncode.SelectAll();
  284. }
  285. }
  286. }
  287. }