Packing_CartonSplit.cs 12 KB

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