Packing_CartonSplit.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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.DataOperate;
  10. using UAS_MES.Entity;
  11. using UAS_MES.PublicMethod;
  12. namespace UAS_MES.Packing
  13. {
  14. public partial class Packing_CartonSplit : Form
  15. {
  16. //拼接sql的
  17. LogStringBuilder sql = new LogStringBuilder();
  18. DataHelper dh;
  19. DataTable dt;//存放箱号查询信息
  20. DataTable checknoInfo;
  21. string error = "";//记录错误信息
  22. string ms_id = "";
  23. string outboxcode = "";
  24. string pd_id = "";
  25. AutoSizeFormClass asc = new AutoSizeFormClass();
  26. public Packing_CartonSplit()
  27. {
  28. InitializeComponent();
  29. }
  30. private void Packing_CartonSplit_Load(object sender, EventArgs e)
  31. {
  32. dh = new DataHelper();
  33. asc.controllInitializeSize(this);
  34. OperateResult.AppendText(">>请输入箱号\n", Color.Black);
  35. pa_outboxcode.Focus();
  36. }
  37. private void pa_outboxcode_KeyDown(object sender, KeyEventArgs e)
  38. {
  39. //按下回车
  40. if (e.KeyCode == Keys.Enter)
  41. {
  42. lKeyDown(false);
  43. }
  44. }
  45. private void sncode_KeyDown(object sender, KeyEventArgs e)
  46. {
  47. if (e.KeyCode == Keys.Enter)
  48. {
  49. if (sncode.Text == "")
  50. {
  51. OperateResult.AppendText("<<输入不能为空\n", Color.Red);
  52. return;
  53. }
  54. //判断箱号是否为空
  55. if (pa_outboxcode.Text == "")
  56. {
  57. OperateResult.AppendText("<<请先选择箱号\n", Color.Red, sncode);
  58. return;
  59. }
  60. OperateResult.AppendText(">>" + sncode.Text + "\n", Color.Black);
  61. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out error))
  62. {
  63. //验证序列号是否存在,是否装箱,箱号等于页面输入的箱号
  64. //select max(ms_id) from makeserial where ms_sncode=?
  65. ms_id = dh.getFieldDataByCondition("makeserial", "max(ms_id)", "ms_sncode='" + sncode.Text + "'").ToString();
  66. if (ms_id == "")
  67. {
  68. OperateResult.AppendText("<<序列号" + sncode.Text + "不存在\n", Color.Red, sncode);
  69. return;
  70. }
  71. outboxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + ms_id + "' and nvl(ms_outboxcode,' ')<>' '").ToString();
  72. if (outboxcode == "")
  73. {
  74. OperateResult.AppendText("<<序列号" + sncode.Text + "未装箱\n", Color.Red, sncode);
  75. return;
  76. }
  77. if (pa_outboxcode.Text != outboxcode)
  78. {
  79. OperateResult.AppendText("<<序列号" + sncode.Text + "箱号为:" + outboxcode + ",不在箱号:" + pa_outboxcode.Text + "中,无法拆箱\n", Color.Red, sncode);
  80. return;
  81. }
  82. //验证箱号
  83. if (!checkOutboxcode(false))
  84. {
  85. return;
  86. }
  87. //验证是否在箱内
  88. pd_id = dh.getFieldDataByCondition("packagedetail", "pd_id", "pd_outboxcode='" + pa_outboxcode.Text + "' and pd_barcode='" + sncode.Text + "'").ToString();
  89. if (pd_id == "")
  90. {
  91. OperateResult.AppendText("<<序列号" + sncode.Text + "不在箱号:" + pa_outboxcode.Text + "内,不允许拆箱\n", Color.Red, sncode);
  92. return;
  93. }
  94. //进行拆箱处理
  95. //删除明细
  96. dh.ExecuteSql("delete from packagedetail where pd_id='" + pd_id + "'", "select");
  97. //更新序列号
  98. dh.ExecuteSql("update makeserial set ms_outboxcode='' , ms_nextstepcode=ms_stepcode where ms_id='" + ms_id + "'", "update");
  99. //更新箱内当前数量
  100. dh.ExecuteSql("update package set pa_currentqty=pa_currentqty-1 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  101. //记录拆箱操作日志
  102. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, packtype.Text, User.UserLineCode, User.UserSourceCode, "卡通箱拆箱", "卡通箱拆箱成功,序列号:" + sncode.Text + ",箱号:" + pa_outboxcode.Text, sncode.Text, "");
  103. //提示拆箱成功
  104. OperateResult.AppendText("<<拆箱成功,序列号:" + sncode.Text + ",已从箱号:" + pa_outboxcode.Text + "内移除\n", Color.Green);
  105. //刷新箱内数量
  106. pa_currentqty.Text = int.Parse(pa_currentqty.Text) - 1 + "";
  107. //计数加1
  108. count.Text = int.Parse(count.Text) + 1 + "";
  109. sncode.Text = "";
  110. }
  111. else
  112. {
  113. OperateResult.AppendText("<<" + error + "\n", Color.Red, sncode);
  114. }
  115. }
  116. }
  117. private bool checkOutboxcode(bool flag)
  118. {
  119. //校验箱号
  120. sql.Clear();
  121. sql.Append("select pa_prodcode,pr_detail,pr_spec,pa_standardqty,nvl(pa_currentqty,0) pa_currentqty,pa_salecode,pa_makecode,");
  122. sql.Append("pa_packtype,nvl(pa_downstatus,0) pa_downstatus,pa_checkno from package left join product on ");
  123. sql.Append("pr_code=pa_prodcode where pa_outboxcode='" + pa_outboxcode.Text + "' and PA_TYPE=1");
  124. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  125. //查询无值,提示用户 “箱号不存在”,清空输入框中的值
  126. if (dt.Rows.Count == 0)
  127. {
  128. if (flag)
  129. {
  130. MessageBox.Show("箱号" + pa_outboxcode.Text + "不存在");
  131. pa_outboxcode.Focus();
  132. return false;
  133. }
  134. OperateResult.AppendText("<<箱号" + pa_outboxcode.Text + "不存在\n", Color.Red, pa_outboxcode);
  135. return false;
  136. }
  137. //判断是否下地
  138. if (dt.Rows[0]["pa_downstatus"].ToString() != "0")
  139. {
  140. if (flag)
  141. {
  142. MessageBox.Show("箱号" + pa_outboxcode.Text + "处于下地状态不允许操作");
  143. pa_outboxcode.Focus();
  144. return false;
  145. }
  146. OperateResult.AppendText("<<箱号" + pa_outboxcode.Text + "处于下地状态不允许操作\n", Color.Red, pa_outboxcode);
  147. return false;
  148. }
  149. //判断是否有抽检批次号,并且未判定
  150. if (dt.Rows[0]["pa_checkno"].ToString() != "")
  151. {
  152. checknoInfo = (DataTable)dh.ExecuteSql("select count(1) cn from oqcbatch where ob_checkno='" + dt.Rows[0]["pa_checkno"].ToString() + "' and ob_status not in('OK','NG')", "select");
  153. //cn>0 ,则返回提示用户“箱号处于送检状态,不允许拆箱”
  154. if (int.Parse(checknoInfo.Rows[0]["cn"].ToString()) > 0)
  155. {
  156. if (flag)
  157. {
  158. MessageBox.Show("箱号" + pa_outboxcode.Text + "处于送检状态,不允许拆箱");
  159. pa_outboxcode.Focus();
  160. return false;
  161. }
  162. OperateResult.AppendText("<<箱号" + pa_outboxcode.Text + "处于送检状态,不允许拆箱\n", Color.Red, pa_outboxcode);
  163. return false;
  164. }
  165. }
  166. //验证mothercode是否为空,有没有装大箱
  167. if (dh.getFieldDataByCondition("package", "pa_mothercode", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() != "")
  168. {
  169. if (flag)
  170. {
  171. MessageBox.Show("<<卡通箱:" + pa_outboxcode.Text + "已装箱,不允许拆箱\n");
  172. pa_outboxcode.Focus();
  173. return false;
  174. }
  175. OperateResult.AppendText("<<卡通箱:" + pa_outboxcode.Text + "已装箱,不允许拆箱\n", Color.Red, sncode);
  176. return false;
  177. }
  178. return true;
  179. }
  180. private void lock_outbox_CheckedChanged(object sender, EventArgs e)
  181. {
  182. if (!lock_outbox.Checked)
  183. {
  184. if (!pa_outboxcode.Enabled)
  185. {
  186. //取消勾选,箱号不可编辑时设置可编辑
  187. pa_outboxcode.Enabled = true;
  188. }
  189. pa_outboxcode.Focus();
  190. }
  191. else
  192. {
  193. //勾选
  194. if (!lKeyDown(true))
  195. {
  196. lock_outbox.Checked = false;
  197. }
  198. }
  199. }
  200. private void Packing_CartonSplit_SizeChanged(object sender, EventArgs e)
  201. {
  202. asc.controlAutoSize(this);
  203. }
  204. private bool lKeyDown(bool flag)
  205. {
  206. //输入不能为空
  207. if (pa_outboxcode.Text == "")
  208. {
  209. if (flag)
  210. {
  211. MessageBox.Show("输入不能为空");
  212. pa_outboxcode.Focus();
  213. return false; ;
  214. }
  215. OperateResult.AppendText("<<输入不能为空\n", Color.Red);
  216. return false;
  217. }
  218. if (pa_outboxcode.Enabled)
  219. {
  220. OperateResult.AppendText(">>" + pa_outboxcode.Text + "\n", Color.Black);
  221. }
  222. //验证箱号
  223. if (!checkOutboxcode(flag))
  224. {
  225. return false;
  226. }
  227. //判定通过,则自动勾选,显示箱号相关信息
  228. BaseUtil.SetFormValue(this.Controls, dt);
  229. //特殊赋值
  230. if (dt.Rows[0]["pa_packtype"].ToString() == "SALE")
  231. {
  232. packtype.Text = dt.Rows[0]["pa_salecode"].ToString();
  233. }
  234. else if (dt.Rows[0]["pa_packtype"].ToString() == "MAKE")
  235. {
  236. packtype.Text = dt.Rows[0]["pa_makecode"].ToString();
  237. }
  238. else if (dt.Rows[0]["pa_packtype"].ToString() == "MIX" || dt.Rows[0]["pa_packtype"].ToString() == "SPEC")
  239. {
  240. pa_prodcode.Text = "混包";
  241. }
  242. pa_outboxcode.Enabled = false;
  243. lock_outbox.Checked = true;
  244. sncode.Focus();
  245. return true;
  246. }
  247. private void pa_outboxcode_Leave(object sender, EventArgs e)
  248. {
  249. if (pa_outboxcode.Text != "")
  250. {
  251. lKeyDown(true);
  252. }
  253. }
  254. }
  255. }