Packing_CartonSplit.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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.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 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,pa_iostatus 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_iostatus"].ToString() == "1")
  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_downstatus"].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. if (dt.Rows[0]["pa_checkno"].ToString() != "")
  170. {
  171. 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");
  172. //cn>0 ,则返回提示用户“箱号处于送检状态,不允许拆箱”
  173. if (int.Parse(checknoInfo.Rows[0]["cn"].ToString()) > 0)
  174. {
  175. if (flag)
  176. {
  177. MessageBox.Show("箱号" + pa_outboxcode.Text + "处于送检状态,不允许拆箱");
  178. pa_outboxcode.Focus();
  179. return false;
  180. }
  181. OperateResult.AppendText("<<箱号" + pa_outboxcode.Text + "处于送检状态,不允许拆箱\n", Color.Red, pa_outboxcode);
  182. return false;
  183. }
  184. }
  185. //验证mothercode是否为空,有没有装大箱
  186. if (dh.getFieldDataByCondition("package", "pa_mothercode", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() != "")
  187. {
  188. if (flag)
  189. {
  190. MessageBox.Show("<<卡通箱:" + pa_outboxcode.Text + "已装箱,不允许拆箱\n");
  191. pa_outboxcode.Focus();
  192. return false;
  193. }
  194. OperateResult.AppendText("<<卡通箱:" + pa_outboxcode.Text + "已装箱,不允许拆箱\n", Color.Red, sncode);
  195. return false;
  196. }
  197. return true;
  198. }
  199. private void lock_outbox_CheckedChanged(object sender, EventArgs e)
  200. {
  201. if (!lock_outbox.Checked)
  202. {
  203. if (!pa_outboxcode.Enabled)
  204. {
  205. //取消勾选,箱号不可编辑时设置可编辑
  206. pa_outboxcode.Enabled = true;
  207. }
  208. pa_outboxcode.Focus();
  209. }
  210. else
  211. {
  212. //勾选
  213. if (!lKeyDown(true))
  214. {
  215. lock_outbox.Checked = false;
  216. }
  217. }
  218. }
  219. private void Packing_CartonSplit_SizeChanged(object sender, EventArgs e)
  220. {
  221. asc.controlAutoSize(this);
  222. }
  223. private bool lKeyDown(bool flag)
  224. {
  225. //输入不能为空
  226. if (pa_outboxcode.Text == "")
  227. {
  228. if (flag)
  229. {
  230. MessageBox.Show("输入不能为空");
  231. pa_outboxcode.Focus();
  232. return false; ;
  233. }
  234. OperateResult.AppendText("<<输入不能为空\n", Color.Red);
  235. return false;
  236. }
  237. if (pa_outboxcode.Enabled)
  238. {
  239. OperateResult.AppendText(">>" + pa_outboxcode.Text + "\n", Color.Black);
  240. }
  241. //验证箱号
  242. if (!checkOutboxcode(flag))
  243. {
  244. return false;
  245. }
  246. //判定通过,则自动勾选,显示箱号相关信息
  247. BaseUtil.SetFormValue(this.Controls, dt);
  248. //特殊赋值
  249. if (dt.Rows[0]["pa_packtype"].ToString() == "SALE")
  250. {
  251. packtype.Text = dt.Rows[0]["pa_salecode"].ToString();
  252. }
  253. else if (dt.Rows[0]["pa_packtype"].ToString() == "MAKE")
  254. {
  255. packtype.Text = dt.Rows[0]["pa_makecode"].ToString();
  256. }
  257. else if (dt.Rows[0]["pa_packtype"].ToString() == "MIX" || dt.Rows[0]["pa_packtype"].ToString() == "SPEC")
  258. {
  259. pa_prodcode.Text = "混包";
  260. }
  261. pa_outboxcode.Enabled = false;
  262. lock_outbox.Checked = true;
  263. sncode.Focus();
  264. return true;
  265. }
  266. private void pa_outboxcode_Leave(object sender, EventArgs e)
  267. {
  268. if (pa_outboxcode.Text != "")
  269. {
  270. lKeyDown(true);
  271. }
  272. }
  273. }
  274. }