Packing_PackageCollection1.cs 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  1. using System;
  2. using System.Data;
  3. using System.Windows.Forms;
  4. using UAS_MES_NEW.DataOperate;
  5. using UAS_MES_NEW.Entity;
  6. using UAS_MES_NEW.PublicMethod;
  7. using System.Drawing;
  8. using System.Threading;
  9. using UAS_MES_NEW.PublicForm;
  10. using System.Collections.Generic;
  11. using System.Diagnostics;
  12. using Seagull.BarTender.Print;
  13. namespace UAS_MES_NEW.Packing
  14. {
  15. public partial class Packing_PackageCollection1 : Form
  16. {
  17. DataHelper dh;
  18. DataTable dt;
  19. LogStringBuilder sql = new LogStringBuilder();
  20. AutoSizeFormClass asc = new AutoSizeFormClass();
  21. Thread thread;
  22. Engine engine;
  23. DataTable Dbfind;
  24. string ErrorMessage = "";
  25. string oMakeCode = "";
  26. string oMsID = "";
  27. string oMsStatus = "";
  28. string oOutBoxCode = "";
  29. decimal StandardQTY = 0;
  30. string LastSncode;
  31. string PR_CHECKCARTONW = "0";
  32. ModeBusTCPServer md;
  33. public Packing_PackageCollection1()
  34. {
  35. InitializeComponent();
  36. }
  37. //创建打印进程
  38. private void NewPrint()
  39. {
  40. try
  41. {
  42. engine = new Engine(true);
  43. }
  44. catch (Exception ex)
  45. {
  46. OperateResult.AppendText("未正确安装BarTender软件\n" + ex.Message, Color.Red);
  47. }
  48. }
  49. private void PackCollection_Load(object sender, EventArgs e)
  50. {
  51. // 杀死之前全部未关闭的进程
  52. Process[] processes = System.Diagnostics.Process.GetProcessesByName("lppa");
  53. Process[] processes1 = System.Diagnostics.Process.GetProcessesByName("bartend");
  54. for (int i = 0; i < processes1.Length; i++)
  55. {
  56. processes1[i].Kill();
  57. }
  58. for (int i = 0; i < processes.Length; i++)
  59. {
  60. processes[i].Kill();
  61. }
  62. IP.Text = BaseUtil.GetCacheData("IP").ToString();
  63. Port.Text = BaseUtil.GetCacheData("IPPort").ToString();
  64. //设置DbFind的必须的数据
  65. PrintNum.Text = "1";
  66. asc.controllInitializeSize(this);
  67. thread = new Thread(NewPrint);
  68. SetLoadingWindow stw = new SetLoadingWindow(thread, "初始化打印程序");
  69. BaseUtil.SetFormCenter(stw);
  70. md = new ModeBusTCPServer();
  71. stw.ShowDialog();
  72. try
  73. {
  74. OutBoxLength.Text = BaseUtil.GetCacheData("OutBoxLength").ToString();
  75. PreFix.Text = BaseUtil.GetCacheData("PreFix").ToString();
  76. Remark_PreFix.Text = BaseUtil.GetCacheData("Remark_PreFix").ToString();
  77. }
  78. catch (Exception) { }
  79. sn_code.Focus();
  80. dh = SystemInf.dh;
  81. StepCount.StepCode = User.CurrentStepCode;
  82. StepCount.Source = User.UserSourceCode;
  83. StepCount.LineCode = User.UserLineCode;
  84. StepCount.Dh = dh;
  85. StepCount.Start();
  86. }
  87. private void PackCollection_SizeChanged(object sender, EventArgs e)
  88. {
  89. asc.controlAutoSize(this);
  90. }
  91. private void PackCollection_Activated(object sender, EventArgs e)
  92. {
  93. pa_outboxcode.Focus();
  94. }
  95. //刷新表单的数据的数据
  96. private void LoadData()
  97. {
  98. //加载表单数据
  99. sql.Clear();
  100. sql.Append("select pr_code,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype,pa_remark,pa_outboxcode,pa_prodcode,pa_salecode,pa_makecode,pa_sccode,nvl(pa_downstatus,0) pa_downstatus,pa_checkno,pa_status,pr_packrule,nvl(PR_CHECKCARTONW,'0') PR_CHECKCARTONW,pr_detail,pa_packageqty,nvl(pa_standardqty,0) pa_standardqty,nvl(pr_outboxinnerqty,0)pr_outboxinnerqty,pa_currentqty from package left join product on pa_prodcode=");
  101. sql.Append("pr_code where pa_outboxcode='" + pa_outboxcode.Text + "'");
  102. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  103. if (dt.Rows.Count > 0)
  104. {
  105. //记录该数据保证在修改不被允许的前提下能偶回复之前的值
  106. StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
  107. if (dt.Rows[0]["pa_salecode"].ToString() != "")
  108. {
  109. ms_salecode.Text = dt.Rows[0]["pa_salecode"].ToString();
  110. }
  111. BaseUtil.SetFormValue(this.Controls, dt);
  112. if (pa_standardqty.Text != "0")
  113. {
  114. pr_outboxinnerqty.Text = pa_standardqty.Text;
  115. }
  116. }
  117. else
  118. {
  119. pa_makecode.Text = "";
  120. }
  121. LoadCollectedNum();
  122. LoadCheckQTY();
  123. }
  124. private void LoadGridData()
  125. {
  126. //加载Grid数据
  127. dt = (DataTable)dh.ExecuteSql("select pa_outboxcode,pa_prodcode,pd_barcode,pd_innerqty,pd_makecode,pa_indate from packageDetail left join package on pa_id=pd_paid where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
  128. BaseUtil.FillDgvWithDataTable(PackageDetail, dt);
  129. if (dt.Rows.Count > 0)
  130. {
  131. string choose_pd_barcode = dt.Rows[0]["pd_barcode"].ToString();
  132. string choose_pd_makecode = dt.Rows[0]["pd_makecode"].ToString();
  133. PR_CHECKCARTONW = dh.getFieldDataByCondition("craftdetail left join craft on cr_id=cd_crid left join makeserial on ms_craftcode =cr_code and cr_prodcode = ms_prodcode", "nvl(cd_ifweigh,'0') cd_ifweigh", "ms_sncode='" + choose_pd_barcode + "' and ms_makecode='" + choose_pd_makecode + "' and cd_stepcode = '" + User.CurrentStepCode + "'").ToString();
  134. }
  135. //更新界面的采集数量
  136. pa_currentqty.Text = dh.getFieldDataByCondition("package", "pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString();
  137. }
  138. private void Print_Click(object sender, EventArgs e)
  139. {
  140. if (PrintLabel.Items.Count != 0)
  141. {
  142. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  143. {
  144. dh.ExecuteSql("update package set pa_printcount=pa_printcount+1,pa_remark='" + PrintLabel.Text + "' where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  145. if (Print.BarTenderS(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrintList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text), oMakeCode == "" ? pa_makecode.Text : oMakeCode, pr_code.Text, "卡通箱标", "0", out ErrorMessage))
  146. {
  147. OperateResult.AppendText(">>开始打印箱号" + pa_outboxcode.Text + "\n", Color.Black);
  148. }
  149. else
  150. {
  151. OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
  152. }
  153. if (!AutoGenBoxCode.Checked)
  154. {
  155. pa_outboxcode.SelectAll();
  156. pa_outboxcode.Focus();
  157. }
  158. else
  159. {
  160. sn_code.Focus();
  161. sn_code.SelectAll();
  162. }
  163. }
  164. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "尚未封箱,请封箱后执行打印\n", Color.Red);
  165. }
  166. else OperateResult.AppendText(">>产品" + pr_code.Text + "未维护打印标签\n", Color.Red);
  167. }
  168. //加载工单信息和装箱明细信息
  169. private void pa_code_KeyDown(object sender, KeyEventArgs e)
  170. {
  171. //try
  172. //{
  173. if (e.KeyCode == Keys.Enter)
  174. {
  175. LoadData();
  176. LoadGridData();
  177. if (CheckOutBoxLength())
  178. {
  179. sn_code.Focus();
  180. }
  181. }
  182. //}
  183. //catch (Exception ex)
  184. //{
  185. // MessageBox.Show(ex.Message);
  186. //}
  187. }
  188. //输入序列号的回车事件
  189. private void barcode_KeyDown(object sender, KeyEventArgs e)
  190. {
  191. //当用户输入回车键的时候
  192. if (e.KeyCode == Keys.Enter)
  193. {
  194. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  195. {
  196. dt = (DataTable)dh.ExecuteSql("select ms_status,ms_id,ms_makecode,ms_nextstepcode,ms_craftcode,ms_prodcode from makeserial where ms_sncode ='" + sn_code.Text + "' order by ms_id desc", "select");
  197. if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sn_code.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage) || (dt.Rows.Count > 0 && dt.Rows[0]["ms_status"].ToString() == "2"))
  198. {
  199. if (oMsID == "" || oMsID == "null" || oMsID == "0")
  200. {
  201. oMsID = dt.Rows[0]["ms_id"].ToString();
  202. oMsStatus = dt.Rows[0]["ms_status"].ToString();
  203. oMakeCode = dt.Rows[0]["ms_makecode"].ToString();
  204. }
  205. //如果是已完工序列号验证装箱工序是否存在于途程中
  206. if (oMsStatus == "2")
  207. {
  208. string prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  209. string craftcode = dt.Rows[0]["ms_craftcode"].ToString();
  210. string craftstepcode = dh.getFieldDataByCondition("craft left join craftdetail on cr_id =cd_crid", "(cd_stepcode)", "cr_prodcode='" + prodcode + "' and cr_code='" + craftcode + "' and cd_stepcode='" + User.CurrentStepCode + "'").ToString();
  211. if (craftstepcode == "")
  212. {
  213. OperateResult.AppendText("工序" + User.CurrentStepCode + "不在途程" + craftcode + "内,不允许采集\n", Color.Red);
  214. return;
  215. }
  216. }
  217. string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_id='" + oMsID + "'").ToString();
  218. if (nextstepcode != "" && nextstepcode != User.CurrentStepCode)
  219. {
  220. OperateResult.AppendText("当前序列号下一道工序" + nextstepcode + ",当前资源不允许采集\n", Color.Red);
  221. if (md.IsOpen)
  222. {
  223. md.SendOrder("M502_ON");
  224. }
  225. return;
  226. }
  227. PR_CHECKCARTONW = dh.getFieldDataByCondition("craftdetail left join craft on cr_id=cd_crid left join makeserial on ms_craftcode =cr_code and cr_prodcode = ms_prodcode", "nvl(cd_ifweigh,'0') cd_ifweigh", "ms_sncode='" + sn_code.Text + "' and ms_makecode='" + oMakeCode + "' and cd_stepcode = '" + User.CurrentStepCode + "'").ToString();
  228. //获取序列号信息
  229. sql.Clear();
  230. sql.Append("select nvl(ms_iostatus,0) ms_iostatus,pa_salecode,ms_salecode,ms_outno,ms_makecode,ms_prodcode,nvl(pa_downstatus,0) pa_downstatus,pa_sccode,pa_checkno,pr_packrule,");
  231. sql.Append("nvl(pr_outboxinnerqty,0)pr_outboxinnerqty,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype from makeserial left join product on ms_prodcode=pr_code left join packagedetail ");
  232. sql.Append("on pd_barcode=ms_sncode left join package on pa_id =pd_paid where ms_id='" + oMsID + "'");
  233. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  234. string ms_makecode = "";
  235. string ms_prodcode = "";
  236. string ms_iostatus = "";
  237. string ms_outno = "";
  238. string ms_salecode_text = "";
  239. if (dt.Rows.Count > 0)
  240. {
  241. StandardQTY = decimal.Parse(dt.Rows[0]["pr_outboxinnerqty"].ToString());
  242. ms_makecode = dt.Rows[0]["ms_makecode"].ToString();
  243. ms_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  244. ms_iostatus = dt.Rows[0]["ms_iostatus"].ToString();
  245. ms_outno = dt.Rows[0]["ms_outno"].ToString();
  246. ms_salecode_text = dt.Rows[0]["ms_salecode"].ToString();
  247. if (locksalecode.Checked && ms_salecode.Text != "" && ms_salecode.Text != ms_salecode_text)
  248. {
  249. OperateResult.AppendText(">>序列号" + sn_code.Text + "所属订单号" + ms_salecode_text + "与界面订单号" + ms_salecode.Text + "不同,无法采集\n", Color.Red, sn_code);
  250. if (md.IsOpen)
  251. {
  252. md.SendOrder("M502_ON");
  253. }
  254. return;
  255. }
  256. BaseUtil.SetFormValue(this.Controls, dt);
  257. }
  258. if (dt.Rows[0]["ms_outno"].ToString() != "")
  259. {
  260. OperateResult.AppendText(">>序列号" + sn_code.Text + "已被出货单" + dt.Rows[0]["ms_outno"].ToString() + "采集,不允许操作\n", Color.Red, sn_code);
  261. if (md.IsOpen)
  262. {
  263. md.SendOrder("M502_ON");
  264. }
  265. return;
  266. }
  267. if (dt.Rows[0]["ms_iostatus"].ToString() != "0")
  268. {
  269. OperateResult.AppendText(">>序列号" + sn_code.Text + "已入库不允许采集\n", Color.Red, sn_code);
  270. if (md.IsOpen)
  271. {
  272. md.SendOrder("M502_ON");
  273. }
  274. return;
  275. }
  276. //保证箱内容量不会被重置
  277. if (pa_standardqty.Text != "0" && pa_standardqty.Text != "")
  278. {
  279. pr_outboxinnerqty.Text = pa_standardqty.Text;
  280. }
  281. if (pa_outboxcode.Text == "")
  282. {
  283. string boxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
  284. //序列号存在箱号的情况下获取所有的装箱数据
  285. if (boxcode != "")
  286. {
  287. pa_outboxcode.Text = boxcode;
  288. pa_makecode.Text = "";
  289. LoadGridData();
  290. }
  291. else
  292. {
  293. //如果勾选了自动生成箱号,在封箱或者首次
  294. if (AutoGenBoxCode.Checked && (pa_status.Text == "1" || pa_status.Text == "" || pa_status.Text == "0"))
  295. {
  296. pa_outboxcode.Text = LogicHandler.GetOutBoxCode1("PACKAGE", ms_makecode, pr_code.Text, User.UserCode);
  297. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "自动生成", sn_code.Text, PreFix.Text + ":" + OutBoxLength.Text);
  298. }
  299. }
  300. }
  301. if (pa_outboxcode.Text == "")
  302. {
  303. OperateResult.AppendText(">>箱号不能为空\n", Color.Red, sn_code);
  304. return;
  305. }
  306. //判断箱内总数必须大于0
  307. if (pr_outboxinnerqty.Text == "" || pr_outboxinnerqty.Text == "0")
  308. {
  309. OperateResult.AppendText(">>箱内容量必须大于0\n", Color.Red);
  310. return;
  311. }
  312. sql.Clear();
  313. sql.Append("select nvl(pa_iostatus,0)pa_iostatus,pa_outno,pa_mothercode,pa_type from package where pa_outboxcode='" + pa_outboxcode.Text + "'");
  314. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  315. string MotherBoxCode = "";
  316. if (dt.Rows.Count > 0)
  317. {
  318. if (dt.Rows[0]["pa_mothercode"].ToString() != "")
  319. {
  320. MotherBoxCode = dt.Rows[0]["pa_mothercode"].ToString();
  321. }
  322. if (dt.Rows[0]["pa_outno"].ToString() != "")
  323. {
  324. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red, sn_code);
  325. if (md.IsOpen)
  326. {
  327. md.SendOrder("M502_ON");
  328. }
  329. return;
  330. }
  331. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  332. {
  333. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "处于入库状态,不允许操作\n", Color.Red, sn_code);
  334. if (md.IsOpen)
  335. {
  336. md.SendOrder("M502_ON");
  337. }
  338. return;
  339. }
  340. }
  341. //如果未勾选了取消录入
  342. if (!Cancel.Checked)
  343. {
  344. //判断序列号是否已经装箱
  345. string ms_outboxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_id='" + oMsID + "'").ToString();
  346. if (ms_outboxcode != "")
  347. {
  348. if (ms_outboxcode == pa_outboxcode.Text)
  349. {
  350. if (md.IsOpen)
  351. {
  352. md.SendOrder("M501_ON");
  353. }
  354. OperateResult.AppendText(">>序列号" + sn_code.Text + "已在本箱内\n", Color.Red, sn_code);
  355. }
  356. else
  357. {
  358. if (md.IsOpen)
  359. {
  360. md.SendOrder("M502_ON");
  361. }
  362. OperateResult.AppendText(">>序列号" + sn_code.Text + "已采集至箱" + ms_outboxcode + "\n", Color.Red, sn_code);
  363. }
  364. LoadData();
  365. }
  366. else
  367. {
  368. //满箱之后采集下一个之前自动清除内容,生成新的箱号
  369. if ((AutoGenBoxCode.Checked && pa_currentqty.Text != "" && pr_outboxinnerqty.Text == pa_currentqty.Text) || (AutoGenBoxCode.Checked && pa_status.Text == "1"))
  370. {
  371. pa_currentqty.Text = "";
  372. pa_outboxcode.Text = "";
  373. pa_status.Text = "0";
  374. BaseUtil.CleanDGVData(PackageDetail);
  375. pa_outboxcode.Text = LogicHandler.GetOutBoxCode1("PACKAGE", ms_makecode, pr_code.Text, User.UserCode);
  376. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "自动生成", sn_code.Text, PreFix.Text + ":" + OutBoxLength.Text);
  377. }
  378. if (!CheckOutBoxLength(ms_salecode_text))
  379. {
  380. return;
  381. }
  382. ////箱号不存在的情况
  383. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  384. {
  385. if (md.IsOpen)
  386. {
  387. md.SendOrder("M501_ON");
  388. }
  389. //提示正确返回时传递的信息
  390. if (ErrorMessage.Contains("AFTERSUCCESS"))
  391. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  392. LastSncode = sn_code.Text;
  393. OperateResult.AppendText(">>序列号" + sn_code.Text + "采集成功!\n", Color.Green);
  394. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "采集成功", sn_code.Text, "");
  395. //满箱更新状态为1
  396. LoadData();
  397. LoadGridData();
  398. LoadCheckQTY();
  399. dh.ExecuteSql("update packagedetail set pd_innerqty=(select pa_packageqty from package where pa_outboxcode='" + pa_outboxcode.Text + "') where pd_innerboxcode='" + pa_outboxcode.Text + "'", "update");
  400. if (MotherBoxCode != "")
  401. {
  402. dt = (DataTable)dh.ExecuteSql("select pa_mothercode,pa_type from package where pa_outboxcode='" + MotherBoxCode + "'", "select");
  403. //如果母箱号不为空,需要更新总数
  404. if (dt.Rows.Count > 0)
  405. {
  406. if (dt.Rows[0]["pa_type"].ToString() == "2")
  407. {
  408. string MotherCode2 = dt.Rows[0]["pa_mothercode"].ToString();
  409. //更新大箱数量
  410. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
  411. //外层有栈板则更新栈板数量
  412. if (MotherCode2 != "")
  413. {
  414. dh.ExecuteSql("update packagedetail set pd_innerqty=(select sum(pd_innerqty) from packagedetail where pd_outboxcode='" + MotherBoxCode + "') where pd_innerboxcode='" + MotherBoxCode + "'", "update");
  415. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherCode2 + "') where pa_outboxcode='" + MotherCode2 + "'", "update");
  416. }
  417. }
  418. if (dt.Rows[0]["pa_type"].ToString() == "3")
  419. {
  420. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
  421. }
  422. }
  423. }
  424. //采集完后如果是第一个装的序列号,把序列号的NextStepCode赋值给箱号
  425. if (pa_currentqty.Text == "1")
  426. {
  427. dh.UpdateByCondition("package", "pa_nextstep='" + User.CurrentStepCode + "', PA_CURRENTSTEP = '" + User.CurrentStepCode + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  428. }
  429. if (int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text) == int.Parse(pr_outboxinnerqty.Text))
  430. {
  431. dh.UpdateByCondition("package", "pa_status=1,pa_packageqty=pa_currentqty,pa_totalqty=pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  432. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "满箱采集完成,封箱成功\n", Color.Green);
  433. pa_status.Text = "1";
  434. pa_standardqty.Text = "";
  435. if (AutoPrint.Checked)
  436. Print_Click(new object(), new EventArgs());
  437. if (!CollecRemark.Checked)
  438. {
  439. if (!AutoGenBoxCode.Checked)
  440. {
  441. pa_outboxcode.SelectAll();
  442. pa_outboxcode.Focus();
  443. }
  444. else
  445. {
  446. sn_code.Focus();
  447. sn_code.SelectAll();
  448. }
  449. }
  450. else
  451. {
  452. pa_remark.SelectAll();
  453. pa_remark.Focus();
  454. }
  455. if (PR_CHECKCARTONW != "0")
  456. {
  457. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "满箱处于称重工序,请在卡通箱称重界面进行称重打印\n", Color.Black, sn_code);
  458. return;
  459. }
  460. if (LogicHandler.OutBoxStepPass(pa_outboxcode.Text, ms_makecode, User.UserSourceCode, User.UserCode, "卡通箱:" + pa_outboxcode.Text + "整箱过站", "卡通箱整箱过站", out ErrorMessage))
  461. {
  462. dh.UpdateByCondition("package", "pa_nextstep='" + dh.getFieldDataByCondition("packagedetail left join makeserial on ms_sncode=pd_barcode and ms_makecode=pd_makecode", "max(ms_nextstepcode)", "pd_outboxcode='" + pa_outboxcode.Text + "'").ToString() + "', PA_CURRENTSTEP = '' ", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  463. }
  464. else
  465. {
  466. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  467. }
  468. LoadCollectedNum();
  469. LoadCheckQTY();
  470. }
  471. sn_code.Clear();
  472. }
  473. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  474. }
  475. }
  476. //勾选了取消箱号先验证箱号存不存在,存在的话移除掉,重新加载一次数据
  477. else
  478. {
  479. if (LogicHandler.Packing(sn_code.Text, pa_outboxcode.Text, AutoGenBoxCode.Checked, "标准", User.UserSourceCode, User.UserCode, pr_outboxinnerqty.Text, Cancel.Checked, out oOutBoxCode, out ErrorMessage))
  480. {
  481. dh.UpdateByCondition("makeserial", "ms_outboxcode=''", "ms_id='" + oMsID + "'");
  482. dh.ExecuteSql("update packagedetail set pd_innerqty=(select pa_packageqty from package where pa_outboxcode='" + pa_outboxcode.Text + "') where pd_innerboxcode='" + pa_outboxcode.Text + "'", "update");
  483. //如果母箱号不为空,需要更新总数
  484. if (MotherBoxCode != "")
  485. {
  486. DataTable dt = (DataTable)dh.ExecuteSql("select pa_mothercode,pa_type from package where pa_outboxcode='" + MotherBoxCode + "'", "select");
  487. if (dt.Rows.Count > 0)
  488. {
  489. if (dt.Rows[0]["pa_type"].ToString() == "2")
  490. {
  491. string MotherCode2 = dt.Rows[0]["pa_mothercode"].ToString();
  492. //更新大箱数量
  493. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
  494. //外层有栈板则更新栈板数量
  495. if (MotherCode2 != "")
  496. {
  497. dh.ExecuteSql("update packagedetail set pd_innerqty=(select sum(pd_innerqty) from packagedetail where pd_outboxcode='" + MotherBoxCode + "') where pd_innerboxcode='" + MotherBoxCode + "'", "update");
  498. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherCode2 + "') where pa_outboxcode='" + MotherCode2 + "'", "update");
  499. }
  500. }
  501. if (dt.Rows[0]["pa_type"].ToString() == "3")
  502. {
  503. dh.ExecuteSql("update package set PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + MotherBoxCode + "') where pa_outboxcode='" + MotherBoxCode + "'", "update");
  504. }
  505. }
  506. }
  507. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "卡通箱采集", "卡通箱" + pa_outboxcode.Text + "取消采集成功", sn_code.Text, "");
  508. LoadGridData();
  509. pa_status.Text = "0";
  510. OperateResult.AppendText(">>已从该箱中移除序列号" + sn_code.Text + "\n", Color.Green, sn_code);
  511. }
  512. else
  513. {
  514. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  515. if (md.IsOpen)
  516. {
  517. md.SendOrder("M502_ON");
  518. }
  519. }
  520. }
  521. }
  522. else
  523. {
  524. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  525. if (md.IsOpen)
  526. {
  527. md.SendOrder("M502_ON");
  528. }
  529. }
  530. }
  531. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sn_code);
  532. }
  533. }
  534. private void Clean_Click(object sender, EventArgs e)
  535. {
  536. OperateResult.Clear();
  537. }
  538. DataTable _dt;
  539. private void pr_code_TextChanged(object sender, EventArgs e)
  540. {
  541. LoadCheckQTY();
  542. _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault from label where la_prodcode='" + pr_code.Text + "' and la_templatetype='卡通箱标' and la_statuscode='AUDITED' order by la_isdefault", "select");
  543. if (_dt.Rows.Count == 0)
  544. {
  545. _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault from label where la_prodcode is null and la_templatetype='卡通箱标' and la_statuscode='AUDITED' order by la_isdefault", "select");
  546. }
  547. PrintLabel.DataSource = _dt;
  548. PrintLabel.DisplayMember = "la_url";
  549. PrintLabel.ValueMember = "la_id";
  550. }
  551. private void PackCollection_FormClosing(object sender, FormClosingEventArgs e)
  552. {
  553. //BaseUtil.ClosePrint(lbl);
  554. dh.Dispose();
  555. }
  556. private void Packing_Click(object sender, EventArgs e)
  557. {
  558. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "' and nvl(pa_status,0)=0"))
  559. {
  560. string Seal = MessageBox.Show(this.ParentForm, "是否确认封箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  561. if (Seal == "Yes")
  562. {
  563. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "采集完成,手动封箱成功\n", Color.Green);
  564. dh.UpdateByCondition("package", "pa_status=1,pa_totalqty=pa_currentqty,pa_packageqty=pa_currentqty", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  565. pa_status.Text = "1";
  566. pa_standardqty.Text = "";
  567. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "装箱采集", "卡通箱" + pa_outboxcode.Text + "封箱成功", pa_outboxcode.Text, "");
  568. if (!CollecRemark.Checked)
  569. {
  570. if (!AutoGenBoxCode.Checked)
  571. {
  572. pa_outboxcode.SelectAll();
  573. pa_outboxcode.Focus();
  574. }
  575. else
  576. {
  577. sn_code.Focus();
  578. sn_code.SelectAll();
  579. }
  580. }
  581. else
  582. {
  583. pa_remark.SelectAll();
  584. pa_remark.Focus();
  585. }
  586. if (PR_CHECKCARTONW != "0")
  587. {
  588. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "处于称重工序,请在卡通箱称重界面进行操作\n", Color.Black, sn_code);
  589. return;
  590. }
  591. string ms_makecode = dh.getFieldDataByCondition("packagedetail", "pd_makecode", "pd_outboxcode = '" + pa_outboxcode.Text + "'").ToString();
  592. if (LogicHandler.OutBoxStepPass(pa_outboxcode.Text, ms_makecode, User.UserSourceCode, User.UserCode, "卡通箱:" + pa_outboxcode.Text + "整箱过站", "卡通箱整箱过站", out ErrorMessage))
  593. {
  594. dh.UpdateByCondition("package", "pa_nextstep='" + dh.getFieldDataByCondition("packagedetail left join makeserial on ms_sncode=pd_barcode and ms_makecode=pd_makecode", "max(ms_nextstepcode)", "pd_outboxcode='" + pa_outboxcode.Text + "'").ToString() + "', PA_CURRENTSTEP = '' ", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  595. }
  596. else
  597. {
  598. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  599. }
  600. LoadCheckQTY();
  601. }
  602. }
  603. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "错误或者已封箱\n", Color.Red);
  604. }
  605. private void SendCheck_Click(object sender, EventArgs e)
  606. {
  607. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + pa_outboxcode.Text + "'").ToString() == "1")
  608. {
  609. DataTable dt = (DataTable)dh.ExecuteSql("select wm_concat(pa_outboxcode) pa_outboxcode from package where pa_checkno='" + ob_checkno.Text + "' and pa_status=0 ", "select");
  610. if (dt.Rows[0][0].ToString() != "")
  611. {
  612. OperateResult.AppendText(">>批次" + ob_checkno.Text + "存在箱号" + dt.Rows[0][0].ToString() + "未封箱,请先进行封箱\n", Color.Red);
  613. return;
  614. }
  615. sql.Clear();
  616. sql.Append("update oqcbatch set ob_status='UNCHECK',ob_breakingdate=sysdate where ob_checkno ='" + ob_checkno.Text + "'");
  617. dh.ExecuteSql(sql.GetString(), "select");
  618. ob_nowcheckqty.Text = "";
  619. ob_batchqty.Text = "";
  620. ob_nowcheckqty.ForeColor = Color.Black;
  621. SendCheck.Enabled = false;
  622. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Green);
  623. LogicHandler.InsertMakeProcess(LastSncode, oMakeCode, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  624. //记录操作日志
  625. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  626. ob_checkno.Text = "";
  627. }
  628. else OperateResult.AppendText(">>必须封箱才能送检\n", Color.Red);
  629. }
  630. bool AutoCut;
  631. private void LoadCheckQTY()
  632. {
  633. sql.Clear();
  634. string condition = "";
  635. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  636. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  637. if (nowcheckqty + 1 == batchqty && AutoCut)
  638. {
  639. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  640. }
  641. else
  642. {
  643. condition = "and ob_status='ENTERING' ";
  644. }
  645. if (pr_sendchecktype.Text == "SaleCode")
  646. {
  647. condition += " and ob_salecode='" + ms_salecode.Text + "'";
  648. }
  649. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  650. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + pr_code.Text + "' and ");
  651. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  652. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  653. if (dt.Rows.Count > 0)
  654. {
  655. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  656. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  657. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  658. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  659. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  660. if (nowcheckqty >= batchqty)
  661. {
  662. ob_nowcheckqty.ForeColor = Color.Red;
  663. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
  664. if (AutoCut)
  665. {
  666. OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动断批\n", Color.Green);
  667. }
  668. }
  669. }
  670. else
  671. {
  672. ob_batchqty.Text = "";
  673. ob_nowcheckqty.Text = "";
  674. ob_checkno.Text = "";
  675. SendCheck.Enabled = false;
  676. }
  677. if (ob_batchqty.Text != "" && PR_CHECKCARTONW == "0")
  678. {
  679. SendCheck.Enabled = true;
  680. }
  681. else
  682. {
  683. SendCheck.Enabled = false;
  684. }
  685. }
  686. private void ob_checkno_TextChanged(object sender, EventArgs e)
  687. {
  688. if (ob_checkno.Text != "")
  689. {
  690. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  691. if (Cut == "" || Cut == "0")
  692. AutoCut = false;
  693. else
  694. AutoCut = true;
  695. SendCheck.Enabled = true;
  696. }
  697. }
  698. //private void pr_outboxinnerqty_KeyDown(object sender, KeyEventArgs e)
  699. //{
  700. // if (e.KeyCode == Keys.Enter)
  701. // ResetPackQTY();
  702. //}
  703. //private void pr_outboxinnerqty_Leave(object sender, EventArgs e)
  704. //{
  705. // ResetPackQTY();
  706. //}
  707. //private void ResetPackQTY()
  708. //{
  709. // //数据不符合限制的时候保持原有值
  710. // int curretnqty = int.Parse(pa_currentqty.Text == "" ? "0" : pa_currentqty.Text);
  711. // if (!(int.Parse(pr_outboxinnerqty.Text) >= curretnqty))
  712. // {
  713. // pr_outboxinnerqty.Text = StandardQTY.ToString();
  714. // }
  715. // else
  716. // {
  717. // if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  718. // {
  719. // string checknostatus = dh.getFieldDataByCondition("oqcbatch", "ob_status", "ob_checkno='" + pa_checkno.Text + "'").ToString();
  720. // if (checknostatus == "" || checknostatus == "ENTERING")
  721. // {
  722. // if (pa_downstatus.Text == "0")
  723. // {
  724. // if (dh.CheckExist("source", "sc_code='" + pa_sccode.Text + "' and sc_stepcode='" + User.CurrentStepCode + "'"))
  725. // {
  726. // dh.UpdateByCondition("package", "pa_standardqty='" + pr_outboxinnerqty.Text + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  727. // LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, "", User.UserLineCode, User.UserSourceCode, "修改箱内容量", "原容量" + StandardQTY + ",修改为" + pr_outboxinnerqty.Text + "'", pa_outboxcode.Text, pa_checkno.Text);
  728. // return;
  729. // }
  730. // else
  731. // OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "当前所在工序不是登录岗位资源所在工序,不允许修改数量\n", Color.Red);
  732. // }
  733. // else
  734. // OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "处于下地状态,不允许修改标准容量\n", Color.Red);
  735. // }
  736. // else
  737. // OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "处于送检中,不允许修改标准容量\n", Color.Red);
  738. // }
  739. // else
  740. // OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在,修改容量无效\n", Color.Red);
  741. // pr_outboxinnerqty.Text = StandardQTY.ToString();
  742. // }
  743. //}
  744. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  745. {
  746. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  747. {
  748. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  749. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  750. }
  751. }
  752. private void DeleteAll_Click(object sender, EventArgs e)
  753. {
  754. if (pa_outboxcode.Text == "")
  755. {
  756. OperateResult.AppendText(">>箱号不能为空\n", Color.Red);
  757. return;
  758. }
  759. string Delete = MessageBox.Show(this.ParentForm, "是否确认拆箱?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  760. if (Delete == "Yes")
  761. {
  762. DataTable dt = (DataTable)dh.ExecuteSql("select nvl(pa_iostatus,0)pa_iostatus,pa_outno,pa_checkno,ob_status,pa_mothercode,nvl(pa_downstatus,0)pa_downstatus from package left join oqcbatch on pa_checkno=ob_checkno where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
  763. if (dt.Rows.Count > 0)
  764. {
  765. if (dt.Rows[0]["pa_outno"].ToString() != "")
  766. {
  767. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "已被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集,不允许操作\n", Color.Red);
  768. return;
  769. }
  770. if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
  771. {
  772. OperateResult.AppendText(">>卡通箱" + pa_outboxcode.Text + "处于入库状态,不允许操作\n", Color.Red);
  773. return;
  774. }
  775. if (dt.Rows[0]["pa_mothercode"].ToString() == "")
  776. {
  777. if (dt.Rows[0]["pa_downstatus"].ToString() == "0")
  778. {
  779. string ob_status = dt.Rows[0]["ob_status"].ToString();
  780. string pa_checkno = dt.Rows[0]["pa_checkno"].ToString();
  781. //不存在抽检批次或者还未检验可以拆解
  782. if (ob_status == "" || ob_status == "ENTERING" || ob_status == "UNCHECK")
  783. {
  784. sql.Clear();
  785. sql.Append("select pd_makecode,count(1) num from packagedetail left join makeserial ");
  786. sql.Append("on ms_sncode=pd_barcode and ms_makecode=pd_makecode where pd_outboxcode='" + pa_outboxcode.Text + "' group by pd_makecode");
  787. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  788. List<string> SQLS1 = new List<string>();
  789. for (int i = 0; i < dt.Rows.Count; i++)
  790. {
  791. string ma_code = dt.Rows[i]["pd_makecode"].ToString();
  792. string num = dt.Rows[i]["num"].ToString();
  793. SQLS1.Add("delete from makeprocess where mp_sncode in (select ms_sncode from makeserial where ms_outboxcode='" + pa_outboxcode.Text + "' and ms_makecode='" + ma_code + "') and mp_makecode='" + ma_code + "' and mp_stepcode='" + User.CurrentStepCode + "'");
  794. SQLS1.Add("delete from steppassed where sp_sncode in (select ms_sncode from makeserial where ms_outboxcode='" + pa_outboxcode.Text + "' and ms_makecode='" + ma_code + "') and sp_makecode='" + ma_code + "' and sp_stepcode='" + User.CurrentStepCode + "'");
  795. SQLS1.Add("update makecraftdetail set mcd_inqty=mcd_inqty-" + num + ",mcd_outqty=mcd_outqty-" + num + ",mcd_okqty=mcd_okqty-" + num + " where mcd_macode='" + ma_code + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  796. //扣减已完工数
  797. SQLS1.Add("update make set ma_endqty=ma_endqty-(select count(1) from makeserial where ms_outboxcode='" + pa_outboxcode.Text + "' and ms_makecode='" + ma_code + "' and ms_status=2) where ma_code='" + ma_code + "'");
  798. }
  799. if (pa_checkno != "")
  800. {
  801. SQLS1.Add("update makeserial set ms_checkno='' where ms_outboxcode='" + pa_outboxcode.Text + "'");
  802. SQLS1.Add("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-(select count(1) from oqcbatchdetail where obd_outboxcode='" + pa_outboxcode.Text + "') where ob_checkno='" + pa_checkno + "'");
  803. SQLS1.Add("delete from oqcbatchdetail where obd_outboxcode='" + pa_outboxcode.Text + "'");
  804. }
  805. //更新序列号状态
  806. SQLS1.Add("update makeserial set ms_status=1,ms_outboxcode='',ms_nextstepcode= (case when ms_nextstepcode='" + User.CurrentStepCode + "' then ms_nextstepcode else ms_stepcode end ),ms_paststep=replace(ms_paststep,'," + User.CurrentStepCode + "','') where ms_outboxcode='" + pa_outboxcode.Text + "'");
  807. //抽检批次不为空的时候进行移除
  808. dh.ExecuteSQLTran(SQLS1.ToArray());
  809. string prcode = dh.getFieldDataByCondition("packagedetail", "pd_prodcode", "pd_outboxcode = '" + pa_outboxcode.Text + "'").ToString();
  810. string standqty = dh.getFieldDataByCondition("product", "pr_outboxinnerqty", "pr_code = '" + prcode + "'").ToString();
  811. if (standqty != "")
  812. {
  813. //置空原箱
  814. dh.ExecuteSql("update package set pa_checkno='',pa_prodcode='',pa_packtype='',pa_salecode='',pa_packageqty=0,pa_totalqty=0,pa_currentqty=0,pa_status=0,PA_STANDARDQTY = '" + standqty + "' where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  815. }
  816. else
  817. //置空原箱
  818. dh.ExecuteSql("update package set pa_checkno='',pa_prodcode='',pa_packtype='',pa_salecode='',pa_packageqty=0,pa_totalqty=0,pa_currentqty=0,pa_status=0 where pa_outboxcode='" + pa_outboxcode.Text + "'", "update");
  819. pa_status.Text = "0";
  820. //删除箱的明细
  821. dh.ExecuteSql("delete from packagedetail where pd_outboxcode='" + pa_outboxcode.Text + "'", "delete");
  822. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱拆解", "成功", pa_outboxcode.Text, ob_checkno.Text);
  823. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "成功拆解!\n", Color.Green);
  824. LoadGridData();
  825. LoadCheckQTY();
  826. }
  827. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已送检,不允许解除\n", Color.Red);
  828. }
  829. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已下地,不允许解除\n", Color.Red);
  830. }
  831. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "已装箱" + dt.Rows[0]["pa_mothercode"].ToString() + ",不允许解除\n", Color.Red);
  832. }
  833. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在\n", Color.Red);
  834. }
  835. }
  836. private void OutBoxLength_KeyDown(object sender, KeyEventArgs e)
  837. {
  838. if (e.KeyCode == Keys.Enter)
  839. {
  840. try
  841. {
  842. if (OutBoxLength.Text != "")
  843. {
  844. int.Parse(OutBoxLength.Text);
  845. }
  846. BaseUtil.SetCacheData("OutBoxLength", OutBoxLength.Text);
  847. if (!AutoGenBoxCode.Checked)
  848. {
  849. pa_outboxcode.SelectAll();
  850. pa_outboxcode.Focus();
  851. }
  852. else
  853. {
  854. sn_code.Focus();
  855. }
  856. }
  857. catch (Exception)
  858. {
  859. OutBoxLength.Clear();
  860. MessageBox.Show("请输入正确的长度");
  861. }
  862. }
  863. }
  864. private bool CheckOutBoxLength()
  865. {
  866. //勾选了检验长度进行校验
  867. if (OutBoxLength.Text != "")
  868. {
  869. try
  870. {
  871. int.Parse(OutBoxLength.Text);
  872. }
  873. catch (Exception)
  874. {
  875. MessageBox.Show("请填写正确的箱号长度");
  876. return false;
  877. }
  878. if (pa_outboxcode.Text.Length != int.Parse(OutBoxLength.Text))
  879. {
  880. OperateResult.AppendText(">>箱号长度错误,请重新输入箱号\n", Color.Red);
  881. return false;
  882. }
  883. }
  884. if (PreFix.Text != "")
  885. {
  886. try
  887. {
  888. if (pa_outboxcode.Text.Substring(0, PreFix.Text.Length) != PreFix.Text)
  889. {
  890. OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red);
  891. return false;
  892. }
  893. }
  894. catch (Exception)
  895. {
  896. OperateResult.AppendText(">>箱号前缀不匹配,请重新输入箱号\n", Color.Red);
  897. return false;
  898. }
  899. }
  900. return true;
  901. }
  902. private void LoadCollectedNum()
  903. {
  904. dt = (DataTable)dh.ExecuteSql("select mcd_inqty,ma_qty-mcd_inqty mcd_remainqty from make left join makecraftdetail on mcd_macode=ma_code where ma_code='" + ms_makecode.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'", "select");
  905. BaseUtil.SetFormValue(Controls, dt);
  906. }
  907. private void pa_remark_KeyDown(object sender, KeyEventArgs e)
  908. {
  909. if (Keys.Enter == e.KeyCode)
  910. {
  911. if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode.Text + "'"))
  912. {
  913. if (Remark_PreFix.Text != "")
  914. {
  915. try
  916. {
  917. if (pa_remark.Text.Substring(0, Remark_PreFix.Text.Length) != Remark_PreFix.Text)
  918. {
  919. OperateResult.AppendText(">>备注前缀不匹配,请重新输入备注信息\n", Color.Red);
  920. return;
  921. }
  922. }
  923. catch (Exception)
  924. {
  925. OperateResult.AppendText(">>备注前缀不匹配,请重新输入备注信息\n", Color.Red);
  926. return;
  927. }
  928. }
  929. if (!AllowRepeat.Checked)
  930. {
  931. DataTable dt = (DataTable)dh.ExecuteSql("select pa_outboxcode from package where pa_remark='" + pa_remark.Text.ToUpper() + "'", "select");
  932. if (dt.Rows.Count > 0)
  933. {
  934. OperateResult.AppendText(">>箱号" + dt.Rows[0][0].ToString() + "已采集关联信息" + pa_remark.Text + "\n", Color.Red);
  935. return;
  936. }
  937. }
  938. dh.UpdateByCondition("package", "pa_remark='" + pa_remark.Text.ToUpper() + "'", "pa_outboxcode='" + pa_outboxcode.Text + "'");
  939. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "关联信息" + pa_remark.Text + "采集成功\n", Color.Green);
  940. pa_remark.Text = "";
  941. if (!AutoGenBoxCode.Checked)
  942. {
  943. pa_outboxcode.SelectAll();
  944. pa_outboxcode.Focus();
  945. }
  946. else
  947. {
  948. sn_code.Focus();
  949. }
  950. }
  951. else OperateResult.AppendText(">>请先采集箱内数据\n", Color.Red);
  952. }
  953. }
  954. private void PreFix_KeyDown(object sender, KeyEventArgs e)
  955. {
  956. if (e.KeyCode == Keys.Enter)
  957. {
  958. BaseUtil.SetCacheData("PreFix", PreFix.Text);
  959. if (!AutoGenBoxCode.Checked)
  960. {
  961. pa_outboxcode.SelectAll();
  962. pa_outboxcode.Focus();
  963. }
  964. else
  965. {
  966. sn_code.Focus();
  967. sn_code.SelectAll();
  968. }
  969. }
  970. }
  971. private void BuildServer_Click(object sender, EventArgs e)
  972. {
  973. if (!md.IsOpen)
  974. {
  975. md.IP = IP.Text;
  976. md.Port = Port.Text;
  977. if (md.Open())
  978. {
  979. BaseUtil.SetCacheData("IP", IP.Text);
  980. BaseUtil.SetCacheData("IPPort", Port.Text);
  981. OperateResult.AppendText(">>服务开启成功\n");
  982. }
  983. }
  984. else
  985. OperateResult.AppendText(">>服务已经开启\n");
  986. }
  987. private void CloseServer_Click(object sender, EventArgs e)
  988. {
  989. if (md.IsOpen)
  990. {
  991. md.Close();
  992. OperateResult.AppendText(">>服务关闭成功\n");
  993. }
  994. else
  995. OperateResult.AppendText(">>服务尚未开启\n");
  996. }
  997. private void Remark_PreFix_KeyDown(object sender, KeyEventArgs e)
  998. {
  999. if (e.KeyCode == Keys.Enter)
  1000. {
  1001. BaseUtil.SetCacheData("Remark_PreFix", Remark_PreFix.Text);
  1002. if (CollecRemark.Checked)
  1003. {
  1004. pa_remark.SelectAll();
  1005. pa_remark.Focus();
  1006. }
  1007. }
  1008. }
  1009. private bool CheckOutBoxLength(string ms_salecode_text)
  1010. {
  1011. if (AutoGenBoxCode.Checked)
  1012. {
  1013. if (ms_salecode_text != "")
  1014. {
  1015. DataTable dt = (DataTable)dh.ExecuteSql(" select pn_number,pn_id,pn_caller,pn_numberlength,pn_leadcode from PACKAGENUMBER where pn_caller='" + pr_code.Text + "'", "select");
  1016. if (dt.Rows.Count > 0)
  1017. {
  1018. string pn_leadcode = dt.Rows[0]["pn_leadcode"].ToString();
  1019. int pn_numberlength = int.Parse(dt.Rows[0]["pn_numberlength"].ToString());
  1020. if (OutBoxLength.Text != (pn_leadcode.Length + pn_numberlength).ToString())
  1021. {
  1022. OutBoxLength.Text = (pn_leadcode.Length + pn_numberlength).ToString();
  1023. BaseUtil.SetCacheData("OutBoxLength", OutBoxLength.Text);
  1024. }
  1025. if (PreFix.Text != pn_leadcode)
  1026. {
  1027. PreFix.Text = pn_leadcode;
  1028. BaseUtil.SetCacheData("PreFix", PreFix.Text);
  1029. }
  1030. }
  1031. else
  1032. {
  1033. //OperateResult.AppendText(">>产品" + pr_code.Text + "未维护箱号规则\n", Color.Black);
  1034. }
  1035. }
  1036. return true;
  1037. }
  1038. return CheckOutBoxLength();
  1039. }
  1040. private void AutoGenBoxCode_CheckedChanged(object sender, EventArgs e)
  1041. {
  1042. if (AutoGenBoxCode.Checked)
  1043. {
  1044. OutBoxLength.Enabled = false;
  1045. PreFix.Enabled = false;
  1046. }
  1047. else
  1048. {
  1049. OutBoxLength.Enabled = true;
  1050. PreFix.Enabled = true;
  1051. }
  1052. }
  1053. }
  1054. }