Packing_CartonSplit.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. asc.controllInitializeSize(this);
  33. OperateResult.AppendText(">>请输入箱号\n", Color.Black);
  34. pa_outboxcode.Focus();
  35. dh = SystemInf.dh;
  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. //没填箱号,就赋值箱号
  78. if (pa_outboxcode.Text == "")
  79. {
  80. pa_outboxcode.Text = outboxcode;
  81. //勾上
  82. lock_outbox.Checked = true;
  83. }
  84. if (pa_outboxcode.Text != outboxcode)
  85. {
  86. OperateResult.AppendText("<<序列号" + sncode.Text + "箱号为:" + outboxcode + ",不在箱号:" + pa_outboxcode.Text + "中,无法拆箱\n", Color.Red, sncode);
  87. return;
  88. }
  89. //验证箱号
  90. if (!checkOutboxcode(false))
  91. {
  92. return;
  93. }
  94. //验证是否在箱内
  95. pd_id = dh.getFieldDataByCondition("packagedetail", "pd_id", "pd_outboxcode='" + pa_outboxcode.Text + "' and pd_barcode='" + sncode.Text + "'").ToString();
  96. if (pd_id == "")
  97. {
  98. OperateResult.AppendText("<<序列号" + sncode.Text + "不在箱号:" + pa_outboxcode.Text + "内,不允许拆箱\n", Color.Red, sncode);
  99. return;
  100. }
  101. //进行拆箱处理
  102. //删除明细
  103. dh.ExecuteSql("delete from packagedetail where pd_id='" + pd_id + "'", "select");
  104. //更新序列号
  105. dh.ExecuteSql("update makeserial set ms_outboxcode='' , ms_nextstepcode=ms_stepcode where ms_id='" + ms_id + "'", "update");
  106. //更新箱内当前数量
  107. dh.ExecuteSql("update package set pa_currentqty=pa_currentqty-1,pa_status=0 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  108. //记录拆箱操作日志
  109. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, packtype.Text, User.UserLineCode, User.UserSourceCode, "卡通箱拆箱", "卡通箱拆箱成功,序列号:" + sncode.Text + ",箱号:" + pa_outboxcode.Text, sncode.Text, "");
  110. //提示拆箱成功
  111. OperateResult.AppendText("<<拆箱成功,序列号:" + sncode.Text + ",已从箱号:" + pa_outboxcode.Text + "内移除\n", Color.Green);
  112. //刷新箱内数量
  113. pa_currentqty.Text = int.Parse(pa_currentqty.Text) - 1 + "";
  114. //计数加1
  115. count.Text = int.Parse(count.Text) + 1 + "";
  116. sncode.Text = "";
  117. }
  118. else
  119. {
  120. OperateResult.AppendText("<<" + error + "\n", Color.Red, sncode);
  121. }
  122. }
  123. }
  124. private bool checkOutboxcode(bool flag)
  125. {
  126. //校验箱号
  127. sql.Clear();
  128. sql.Append("select pa_prodcode,pr_detail,pr_spec,pa_standardqty,nvl(pa_currentqty,0) pa_currentqty,pa_salecode,pa_makecode,");
  129. sql.Append("pa_packtype,nvl(pa_downstatus,0) pa_downstatus,pa_checkno from package left join product on ");
  130. sql.Append("pr_code=pa_prodcode where pa_outboxcode='" + pa_outboxcode.Text + "' and PA_TYPE=1");
  131. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  132. //查询无值,提示用户 “箱号不存在”,清空输入框中的值
  133. if (dt.Rows.Count == 0)
  134. {
  135. if (flag)
  136. {
  137. MessageBox.Show("箱号" + pa_outboxcode.Text + "不存在");
  138. pa_outboxcode.Focus();
  139. return false;
  140. }
  141. OperateResult.AppendText("<<箱号" + pa_outboxcode.Text + "不存在\n", Color.Red, pa_outboxcode);
  142. return false;
  143. }
  144. //判断是否下地
  145. if (dt.Rows[0]["pa_downstatus"].ToString() != "0")
  146. {
  147. if (flag)
  148. {
  149. MessageBox.Show("箱号" + pa_outboxcode.Text + "处于下地状态不允许操作");
  150. pa_outboxcode.Focus();
  151. return false;
  152. }
  153. OperateResult.AppendText("<<箱号" + pa_outboxcode.Text + "处于下地状态不允许操作\n", Color.Red, pa_outboxcode);
  154. return false;
  155. }
  156. //判断是否有抽检批次号,并且未判定
  157. if (dt.Rows[0]["pa_checkno"].ToString() != "")
  158. {
  159. 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");
  160. //cn>0 ,则返回提示用户“箱号处于送检状态,不允许拆箱”
  161. if (int.Parse(checknoInfo.Rows[0]["cn"].ToString()) > 0)
  162. {
  163. if (flag)
  164. {
  165. MessageBox.Show("箱号" + pa_outboxcode.Text + "处于送检状态,不允许拆箱");
  166. pa_outboxcode.Focus();
  167. return false;
  168. }
  169. OperateResult.AppendText("<<箱号" + pa_outboxcode.Text + "处于送检状态,不允许拆箱\n", Color.Red, pa_outboxcode);
  170. return false;
  171. }
  172. }
  173. //验证mothercode是否为空,有没有装大箱
  174. if (dh.getFieldDataByCondition("package", "pa_mothercode", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() != "")
  175. {
  176. if (flag)
  177. {
  178. MessageBox.Show("<<卡通箱:" + pa_outboxcode.Text + "已装箱,不允许拆箱\n");
  179. pa_outboxcode.Focus();
  180. return false;
  181. }
  182. OperateResult.AppendText("<<卡通箱:" + pa_outboxcode.Text + "已装箱,不允许拆箱\n", Color.Red, sncode);
  183. return false;
  184. }
  185. return true;
  186. }
  187. private void lock_outbox_CheckedChanged(object sender, EventArgs e)
  188. {
  189. if (!lock_outbox.Checked)
  190. {
  191. if (!pa_outboxcode.Enabled)
  192. {
  193. //取消勾选,箱号不可编辑时设置可编辑
  194. pa_outboxcode.Enabled = true;
  195. }
  196. pa_outboxcode.Focus();
  197. }
  198. else
  199. {
  200. //勾选
  201. if (!lKeyDown(true))
  202. {
  203. lock_outbox.Checked = false;
  204. }
  205. }
  206. }
  207. private void Packing_CartonSplit_SizeChanged(object sender, EventArgs e)
  208. {
  209. asc.controlAutoSize(this);
  210. }
  211. private bool lKeyDown(bool flag)
  212. {
  213. //输入不能为空
  214. if (pa_outboxcode.Text == "")
  215. {
  216. if (flag)
  217. {
  218. MessageBox.Show("输入不能为空");
  219. pa_outboxcode.Focus();
  220. return false; ;
  221. }
  222. OperateResult.AppendText("<<输入不能为空\n", Color.Red);
  223. return false;
  224. }
  225. if (pa_outboxcode.Enabled)
  226. {
  227. OperateResult.AppendText(">>" + pa_outboxcode.Text + "\n", Color.Black);
  228. }
  229. //验证箱号
  230. if (!checkOutboxcode(flag))
  231. {
  232. return false;
  233. }
  234. //判定通过,则自动勾选,显示箱号相关信息
  235. BaseUtil.SetFormValue(this.Controls, dt);
  236. //特殊赋值
  237. if (dt.Rows[0]["pa_packtype"].ToString() == "SALE")
  238. {
  239. packtype.Text = dt.Rows[0]["pa_salecode"].ToString();
  240. }
  241. else if (dt.Rows[0]["pa_packtype"].ToString() == "MAKE")
  242. {
  243. packtype.Text = dt.Rows[0]["pa_makecode"].ToString();
  244. }
  245. else if (dt.Rows[0]["pa_packtype"].ToString() == "MIX" || dt.Rows[0]["pa_packtype"].ToString() == "SPEC")
  246. {
  247. pa_prodcode.Text = "混包";
  248. }
  249. pa_outboxcode.Enabled = false;
  250. lock_outbox.Checked = true;
  251. sncode.Focus();
  252. return true;
  253. }
  254. private void pa_outboxcode_Leave(object sender, EventArgs e)
  255. {
  256. if (pa_outboxcode.Text != "")
  257. {
  258. lKeyDown(true);
  259. }
  260. }
  261. }
  262. }