Packing_CartonSplit.cs 11 KB

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