Warehouse_FinishedProductOut.cs 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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.Warehouse
  13. {
  14. public partial class Warehouse_FinishedProductOut : Form
  15. {
  16. DataTable dbfind;
  17. AutoSizeFormClass asc = new AutoSizeFormClass();
  18. LogStringBuilder sql = new LogStringBuilder();
  19. DataTable dt;
  20. DataHelper dh;
  21. DataTable dta;
  22. DataTable dtpi;
  23. DataTable dtform;
  24. DataTable dtms;
  25. Warehouse_NewPiInOut newpi;
  26. string needMakeIn;
  27. public Warehouse_FinishedProductOut()
  28. {
  29. InitializeComponent();
  30. }
  31. private void Warehouse_FinishedProductOut_Load(object sender, EventArgs e)
  32. {
  33. pi_inoutno.TableName = "prodinout";
  34. pi_inoutno.DBTitle = "出货单查询";
  35. pi_inoutno.SelectField = "pi_id # ID,pi_title # 客户名称,pi_inoutno # 出货单号,pi_type # 出货类型";
  36. pi_inoutno.SetValueField = new string[] { "pi_title", "pi_inoutno", "pi_id", "pi_type" };
  37. pi_inoutno.FormName = Name;
  38. pi_inoutno.Condition = "pi_pdastatus<>'已出库' and pi_class='出货单'";
  39. pi_inoutno.DbChange += Pi_inoutno_DbChange;
  40. dh = new DataHelper();
  41. asc.controllInitializeSize(this);
  42. needMakeIn = dh.GetConfig("needMakeIn", "MESSetting").ToString();
  43. }
  44. private void Pi_inoutno_DbChange(object sender, EventArgs e)
  45. {
  46. dbfind = pi_inoutno.ReturnData;
  47. BaseUtil.SetFormValue(this.Controls, dbfind);
  48. LoadFormData();
  49. LoadGridData();
  50. }
  51. /// <summary>
  52. /// j加载Form数据
  53. /// </summary>
  54. private void LoadFormData()
  55. {
  56. BaseUtil.CleanControls(panel1.Controls);
  57. sql.Clear();
  58. sql.Append("select pi_id,pi_title,pi_inoutno,pi_type from prodinout where pi_inoutno = '" + pi_inoutno.Text + "'");
  59. dtpi = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  60. if (dtpi.Rows.Count > 0)
  61. {
  62. BaseUtil.SetFormValue(this.Controls, dtpi);
  63. }
  64. if (pi_type.Text == "按订单出货")
  65. {
  66. sql.Clear();
  67. sql.Append("select nvl((select sum(pd_outqty) from prodiodetail where pd_piid=" + pi_id.Text + "),0)outqty,nvl((select count(1)cn from prodiomac where pim_inoutno=pd_inoutno),0) getqty ");
  68. sql.Append(" from prodiodetail where pd_piid='" + pi_id.Text + "' ");
  69. dtform = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  70. if (dtform.Rows.Count > 0)
  71. {
  72. int boxqtycount = 0;
  73. BaseUtil.SetFormValue(this.Controls, dtform);
  74. ungetqty.Text = (int.Parse(dtform.Rows[0]["outqty"].ToString()) - int.Parse(dtform.Rows[0]["getqty"].ToString())).ToString();
  75. sql.Clear();
  76. sql.Append("select pim_type,pim_outboxcode from prodiomac where pim_inoutno='" + pi_inoutno.Text + "' and NVL(PIM_OUTBOXCODE,' ')<>' ' AND pim_type ='BOX' GROUP BY pim_outboxcode,pim_type");
  77. DataTable dtout = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  78. boxqtycount += dtout.Rows.Count;
  79. boxqtycount += int.Parse(dh.getFieldDataByCondition("package", "nvl(sum(pa_packageqty),0)", " pa_outboxcode in (select pim_outboxcode from prodiomac where pim_inoutno='" + pi_inoutno.Text + "' and NVL(PIM_OUTBOXCODE,' ')<>' ' AND pim_type ='PALLET' GROUP BY pim_outboxcode)").ToString());
  80. boxqty.Text = boxqtycount.ToString();
  81. }
  82. pi_type_check.Checked = true;
  83. }
  84. else
  85. {
  86. sql.Clear();
  87. sql.Append("select count(1)getqty from prodiomac where pim_inoutno = '" + pi_inoutno.Text + "'");
  88. dtform = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  89. if (dtform.Rows.Count > 0)
  90. {
  91. int boxqtycount = 0;
  92. BaseUtil.SetFormValue(this.Controls, dtform);
  93. sql.Clear();
  94. sql.Append("select pim_type,pim_outboxcode from prodiomac where pim_inoutno='" + pi_inoutno.Text + "' and NVL(PIM_OUTBOXCODE,' ')<>' ' AND pim_type ='BOX' GROUP BY pim_outboxcode,pim_type");
  95. DataTable dtout = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  96. boxqtycount += dtout.Rows.Count;
  97. boxqtycount += int.Parse(dh.getFieldDataByCondition("package", "nvl(sum(pa_packageqty),0)", " pa_outboxcode in (select pim_outboxcode from prodiomac where pim_inoutno='" + pi_inoutno.Text + "' and NVL(PIM_OUTBOXCODE,' ')<>' ' AND pim_type ='PALLET' GROUP BY pim_outboxcode)").ToString());
  98. boxqty.Text = boxqtycount.ToString();
  99. }
  100. pi_type_check.Checked = false;
  101. }
  102. }
  103. /// <summary>
  104. /// 加载Grid数据
  105. /// </summary>
  106. private void LoadGridData()
  107. {
  108. sql.Clear();
  109. sql.Append("select pim_outboxcode,pim_mac,pim_prodcode,pr_detail,pr_spec from prodiomac ");
  110. sql.Append("left join product on pr_code=pim_prodcode where pim_inoutno='" + pi_inoutno.Text + "'");
  111. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  112. BaseUtil.FillDgvWithDataTable(InOutDetailDGV, dt);
  113. }
  114. private void Warehouse_FinishedProductOut_SizeChanged(object sender, EventArgs e)
  115. {
  116. asc.controlAutoSize(this);
  117. }
  118. private void NewProdInOut_Click(object sender, EventArgs e)
  119. {
  120. newpi = new Warehouse_NewPiInOut();
  121. newpi.Controls["Confirm"].Click += newpi_clck;
  122. BaseUtil.SetFormCenter(newpi);
  123. newpi.ShowDialog();
  124. }
  125. private void newpi_clck(object sender, EventArgs e)
  126. {
  127. if (newpi.generate)
  128. {
  129. pi_inoutno.Text = newpi.pi_inoutno_text;
  130. LoadFormData();
  131. LoadGridData();
  132. newpi.Close();
  133. }
  134. }
  135. private void ProdDetail_Click(object sender, EventArgs e)
  136. {
  137. Warehouse_ProdDetail newpd = new Warehouse_ProdDetail(pi_inoutno.Text, pi_id.Text);
  138. BaseUtil.SetFormCenter(newpd);
  139. newpd.ShowDialog();
  140. }
  141. private void ConfirmOut_Click(object sender, EventArgs e)
  142. {
  143. if (ungetqty.Text == "" || int.Parse(ungetqty.Text.ToString()) >= 0)
  144. {
  145. String dialog = MessageBox.Show("是否确认出货", "提示", MessageBoxButtons.OKCancel).ToString();
  146. if (dialog != "OK")
  147. {
  148. OperateResult.AppendText("取消确认出货\n", Color.Black);
  149. return;
  150. }
  151. else
  152. {
  153. sql.Clear();
  154. sql.Append("select nvl(pi_pdastatus,'未备货')pi_pdastatus,pi_id,pi_type from prodinout where pi_inoutno='" + pi_inoutno.Text + "'");
  155. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  156. if (dt.Rows.Count > 0)
  157. {
  158. if (dt.Rows[0]["pi_pdastatus"].ToString() == "已出库")
  159. {
  160. OperateResult.AppendText("出货单" + pi_inoutno.Text + "已经出库,无需重复确认\n", Color.Red);
  161. return;
  162. }
  163. else if (dt.Rows[0]["pi_pdastatus"].ToString() == "未备货")
  164. {
  165. OperateResult.AppendText("出货单" + pi_inoutno.Text + "尚未备货,无法确认出货\n", Color.Red);
  166. return;
  167. }
  168. else if (dt.Rows[0]["pi_type"].ToString() == "按订单出货" && dt.Rows[0]["pi_pdastatus"].ToString() == "备货中")
  169. {
  170. OperateResult.AppendText("出货单" + pi_inoutno.Text + "未完成备货,无法确认出货\n", Color.Red);
  171. return;
  172. }
  173. else
  174. {
  175. List<String> ExeSQL = new List<string>();
  176. ExeSQL.Add("update package set pa_iostatus=2 where exists (select 1 from prodiomac where pim_inoutno='" + pi_inoutno.Text + "' and pim_outboxcode=pa_outboxcode and ((pim_type='PALLET' AND PA_TYPE=3) OR (PIM_TYPE='BOX' AND PA_TYPE IN(1,2)))) AND PA_OUTNO='" + pi_inoutno.Text + "'");
  177. ExeSQL.Add("update makeserial set ms_iostatus=2 where ms_outno='" + pi_inoutno.Text + "' and exists(select 1 from prodiomac where pim_inoutno='" + pi_inoutno.Text + "' and pim_mac=ms_sncode and pim_inorout='OUT')");
  178. ExeSQL.Add("update prodinout set pi_pdastatus='已出库' where pi_inoutno='" + pi_inoutno.Text + "'");
  179. ExeSQL.Add("insert into messagelog(ml_id,ml_date,ml_man,ml_content,ml_result,ml_search)values(messagelog_seq.nextval,sysdate,'" + User.UserName + "','确认出货','确认出货成功','ProdInOut!Sale|pi_id=" + pi_id.Text + "')");
  180. dh.ExecuteSQLTran(ExeSQL.ToArray());
  181. OperateResult.AppendText("出货单" + pi_inoutno.Text + "出库成功\n", Color.Black, pi_inoutno);
  182. BaseUtil.CleanDGVData(InOutDetailDGV);
  183. BaseUtil.CleanControls(panel1.Controls);
  184. }
  185. }
  186. else
  187. {
  188. OperateResult.AppendText("出货单" + pi_inoutno.Text + "不存在\n", Color.Red, pi_inoutno);
  189. return;
  190. }
  191. }
  192. }
  193. else
  194. {
  195. OperateResult.AppendText("出货单" + pi_inoutno.Text + "待采集数不能为负\n", Color.Red);
  196. return;
  197. }
  198. }
  199. private void input_KeyDown(object sender, KeyEventArgs e)
  200. {
  201. if (e.KeyCode == Keys.Enter)
  202. {
  203. if (input.Text == "")
  204. {
  205. OperateResult.AppendText("录入信息不能为空\n", Color.Red, input);
  206. return;
  207. }
  208. sql.Clear();
  209. sql.Append("select nvl(pi_pdastatus,'未备货')pi_pdastatus,pi_type from prodinout where pi_inoutno='" + pi_inoutno.Text + "'");
  210. dta = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  211. if (dta.Rows.Count > 0)
  212. {
  213. if (!cancel.Checked)
  214. {
  215. if (palletBtn.Checked)
  216. {
  217. string pa_makecode = "";
  218. sql.Clear();
  219. sql.Append("select pa_outboxcode,pa_status,nvl(pa_iostatus,0) pa_iostatus,pa_makecode,nvl(pa_downstatus,0)pa_downstatus,pa_outno from package where pa_outboxcode='" + input.Text + "' and pa_type=3");
  220. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  221. if (dt.Rows.Count > 0)
  222. {
  223. if (!checkinput(dt, "栈板号"))
  224. return;
  225. pa_makecode = dt.Rows[0]["pa_makecode"].ToString();
  226. }
  227. else
  228. {
  229. OperateResult.AppendText("栈板号" + input.Text + "不存在,请重新输入\n", Color.Red, input);
  230. return;
  231. }
  232. if (!checkinsertprodiomac("栈板号"))
  233. return;
  234. //更新箱号对应的出货单号
  235. dh.UpdateByCondition("package", "pa_outno = '" + pi_inoutno.Text + "'", "pa_outboxcode = '" + input.Text + "'");
  236. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode, User.UserLineCode, User.UserSourceCode, "栈板" + input.Text + "出货备货", "栈板" + input.Text + "出货备货成功", "", input.Text);
  237. }
  238. else if (bigboxBtn.Checked)
  239. {
  240. string outboxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_sncode = '" + input.Text + "'").ToString();
  241. string pa_makecode = "";
  242. if (outboxcode != "")
  243. {
  244. input.Text = outboxcode;
  245. }
  246. sql.Clear();
  247. sql.Append("select pa_outboxcode,pa_makecode,pa_status,nvl(pa_iostatus,0) pa_iostatus,nvl(pa_downstatus,0)pa_downstatus,pa_outno, pa_mothercode from package where pa_outboxcode='" + input.Text + "' and pa_type in(1,2)");
  248. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  249. if (dt.Rows.Count > 0)
  250. {
  251. pa_makecode = dt.Rows[0]["pa_makecode"].ToString();
  252. if (dt.Rows[0]["pa_mothercode"].ToString() != "")
  253. {
  254. OperateResult.AppendText("箱号" + input.Text + "已经装大箱或者栈板" + dt.Rows[0]["pa_mothercode"].ToString() + ",不允许单独出货\n", Color.Red, input);
  255. return;
  256. }
  257. if (!checkinput(dt, "箱号"))
  258. return;
  259. }
  260. else
  261. {
  262. OperateResult.AppendText("箱号" + input.Text + "不存在,请重新输入\n", Color.Red, input);
  263. return;
  264. }
  265. if (!checkinsertprodiomac("箱号"))
  266. return;
  267. //更新箱号对应的出货单号
  268. dh.UpdateByCondition("package", "pa_outno = '" + pi_inoutno.Text + "'", "pa_outboxcode = '" + input.Text + "'");
  269. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode, User.UserLineCode, User.UserSourceCode, "箱号" + input.Text + "出货备货", "箱号" + input.Text + "出货备货成功", "", input.Text);
  270. }
  271. else if (serBtn.Checked)
  272. {
  273. string ms_id = dh.getFieldDataByCondition("makeserial", "max(ms_id)ms_id", "ms_sncode='" + input.Text + "'").ToString();
  274. if (ms_id == "")
  275. {
  276. OperateResult.AppendText("序列号" + input.Text + "不存在,请重新输入\n", Color.Red, input);
  277. return;
  278. }
  279. else
  280. {
  281. sql.Clear();
  282. sql.Append("select ms_status,ms_outno,ms_makecode,nvl(ms_downstatus,0)ms_downstatus,ms_outboxcode,nvl(ms_iostatus,0)ms_iostatus,ms_prodcode,ms_salecode from makeserial where ms_id='" + ms_id + "'");
  283. dtms = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  284. string ms_downstatus = dtms.Rows[0]["ms_downstatus"].ToString();
  285. string ms_status = dtms.Rows[0]["ms_status"].ToString();
  286. string ms_outboxcode = dtms.Rows[0]["ms_outboxcode"].ToString();
  287. string ms_iostatus = dtms.Rows[0]["ms_iostatus"].ToString();
  288. string ms_outno = dtms.Rows[0]["ms_outno"].ToString();
  289. string ms_prodcode = dtms.Rows[0]["ms_prodcode"].ToString();
  290. string ms_makecode = dtms.Rows[0]["ms_makecode"].ToString();
  291. if (ms_status != "2")
  292. {
  293. OperateResult.AppendText("序列号" + input.Text + "未完工,不允许出货\n", Color.Red, input);
  294. return;
  295. }
  296. if (ms_outboxcode != "")
  297. {
  298. OperateResult.AppendText("序列号" + input.Text + "有外箱号,不允许单独出货\n", Color.Red, input);
  299. return;
  300. }
  301. if (ms_downstatus != "0")
  302. {
  303. OperateResult.AppendText("序列号" + input.Text + "处于下地状态,不允许出货\n", Color.Red, input);
  304. return;
  305. }
  306. if (needMakeIn != "0")
  307. {
  308. if (ms_iostatus != "1")
  309. {
  310. OperateResult.AppendText("序列号" + input.Text + "必须完工入库才允许出库\n", Color.Red, input);
  311. return;
  312. }
  313. }
  314. if (ms_iostatus == "2")
  315. {
  316. OperateResult.AppendText("序列号" + input.Text + "已出库,出库单号:" + ms_outno + "\n", Color.Red, input);
  317. return;
  318. }
  319. if (ms_iostatus == "3")
  320. {
  321. OperateResult.AppendText("序列号" + input.Text + "出入库状态异常\n", Color.Red, input);
  322. return;
  323. }
  324. if (ms_outno != "")
  325. {
  326. OperateResult.AppendText("序列号" + input.Text + "已经被出货单:" + ms_outno + "采集\n", Color.Red, input);
  327. return;
  328. }
  329. if (dta.Rows[0]["pi_type"].ToString() == "按订单出货")
  330. {
  331. sql.Clear();
  332. sql.Append("select cn,outqty,outqty-nvl((select count(1) from prodiomac where pim_inoutno='" + pi_inoutno.Text + "' and pim_prodcode='" + dtms.Rows[0]["ms_prodcode"].ToString() + "'),0)ungetqty from");
  333. sql.Append("(select nvl(sum(pd_outqty),0) outqty ,count(1)cn from prodiodetail where pd_piid=" + pi_id.Text + " and pd_ordercode='" + dtms.Rows[0]["ms_salecode"].ToString() + "' and pd_prodcode='" + dtms.Rows[0]["ms_prodcode"].ToString() + "')");
  334. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  335. if (dt.Rows[0]["cn"].ToString() == "0")
  336. {
  337. OperateResult.AppendText("序列号" + input.Text + "所属产品:" + dtms.Rows[0]["ms_prodcode"].ToString() + ",合同号:" + dtms.Rows[0]["ms_salecode"].ToString() + ",不在出货单" + pi_inoutno.Text + "中\n", Color.Red, input);
  338. return;
  339. }
  340. else if (int.Parse(dt.Rows[0]["cn"].ToString()) > 0 && int.Parse(dt.Rows[0]["ungetqty"].ToString()) <= 0)
  341. {
  342. OperateResult.AppendText("出货单产品" + dtms.Rows[0]["ms_prodcode"].ToString() + "+合同" + dtms.Rows[0]["ms_salecode"].ToString() + ",已经完成出货采集\n", Color.Red, input);
  343. return;
  344. }
  345. updatesn(ms_id);
  346. }
  347. else if (dta.Rows[0]["pi_type"].ToString() == "自由出货")
  348. {
  349. updatesn(ms_id);
  350. }
  351. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode, User.UserLineCode, User.UserSourceCode, "序列号" + input.Text + "出货备货", "序列号" + input.Text + "出货备货成功", input.Text, "");
  352. }
  353. }
  354. else
  355. {
  356. OperateResult.AppendText("未选择录入数据类型\n", Color.Red, input);
  357. return;
  358. }
  359. LoadFormData();
  360. LoadGridData();
  361. if (dta.Rows[0]["pi_type"].ToString() == "按订单出货")
  362. {
  363. if (int.Parse(dtform.Rows[0]["outqty"].ToString()) > int.Parse(dtform.Rows[0]["getqty"].ToString()))
  364. {
  365. dh.UpdateByCondition("prodinout", "pi_pdastatus='备货中'", "pi_inoutno='" + pi_inoutno.Text + "'");
  366. OperateResult.AppendText("出货单" + pi_inoutno.Text + "备货成功\n", Color.Black, input);
  367. }
  368. else
  369. {
  370. dh.UpdateByCondition("prodinout", "pi_pdastatus='已备货'", "pi_inoutno='" + pi_inoutno.Text + "'");
  371. OperateResult.AppendText("出货单" + pi_inoutno.Text + "已完成备货\n", Color.Black, input);
  372. ConfirmOut_Click(sender, e);
  373. return;
  374. }
  375. }
  376. else if (dta.Rows[0]["pi_type"].ToString() == "自由出货")
  377. {
  378. dh.UpdateByCondition("prodinout", "pi_pdastatus='备货中'", "pi_inoutno='" + pi_inoutno.Text + "'");
  379. OperateResult.AppendText("出货单" + pi_inoutno.Text + "备货成功\n", Color.Black, input);
  380. }
  381. }
  382. else
  383. {
  384. if (dta.Rows[0]["pi_pdastatus"].ToString() == "已出库")
  385. {
  386. OperateResult.AppendText("出货单" + pi_inoutno.Text + "已经出库不允许取消备货\n", Color.Red);
  387. return;
  388. }
  389. else if (dta.Rows[0]["pi_pdastatus"].ToString() == "未备货")
  390. {
  391. OperateResult.AppendText("出货单" + pi_inoutno.Text + "尚未备货,无法取消\n", Color.Red);
  392. return;
  393. }
  394. if (palletBtn.Checked)
  395. {
  396. sql.Clear();
  397. sql.Append("select pa_id,pa_outboxcode,pa_status,nvl(pa_downstatus,0)pa_downstatus, ");
  398. sql.Append("pa_outno, nvl(pa_iostatus,0) pa_iostatus,pa_makecode from package ");
  399. sql.Append("where pa_outboxcode='" + input.Text + "' and pa_type=3");
  400. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  401. if (dt.Rows.Count > 0)
  402. {
  403. string pa_iostatus = dt.Rows[0]["pa_iostatus"].ToString();
  404. string pa_outno = dt.Rows[0]["pa_outno"].ToString();
  405. string pa_makecode = dt.Rows[0]["pa_makecode"].ToString();
  406. if (pa_iostatus != "0" && pa_iostatus != "1")
  407. {
  408. OperateResult.AppendText("栈板号" + input.Text + "不是备货状态,无法取消备货\n", Color.Red, input);
  409. return;
  410. }
  411. if (pa_outno == "")
  412. {
  413. OperateResult.AppendText("栈板号" + input.Text + "无所属出货单号\n", Color.Red, input);
  414. return;
  415. }
  416. if (pa_outno != pi_inoutno.Text)
  417. {
  418. OperateResult.AppendText("栈板号" + input.Text + "所属出货单号" + pa_outno + "与当前所选出货单号" + pi_inoutno.Text + "\n", Color.Red, input);
  419. return;
  420. }
  421. dh.ExecuteSql("delete from prodiomac where pim_inoutno='" + pi_inoutno.Text + "' and pim_outboxcode='" + input.Text + "' and pim_type='PALLET' and pim_inorout='OUT' AND pim_class='出货'", "delete");
  422. dh.UpdateByCondition("package", "pa_outno=''", "pa_outboxcode='" + input.Text + "'");
  423. OperateResult.AppendText("栈板号" + input.Text + "取消备货成功\n", Color.Black, input);
  424. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode, User.UserLineCode, User.UserSourceCode, "栈板" + input.Text + "取消出货备货", "栈板" + input.Text + "取消出货备货成功", "", input.Text);
  425. }
  426. else
  427. {
  428. OperateResult.AppendText("栈板号" + input.Text + "不存在,请重新输入\n", Color.Red, input);
  429. return;
  430. }
  431. }
  432. else if (bigboxBtn.Checked)
  433. {
  434. string outboxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_sncode = '" + input.Text + "'").ToString();
  435. if (outboxcode != "")
  436. {
  437. input.Text = outboxcode;
  438. }
  439. sql.Clear();
  440. sql.Append("select pa_id,pa_outboxcode,pa_status,nvl(pa_downstatus,0)pa_downstatus, ");
  441. sql.Append("pa_outno,nvl(pa_iostatus,0) pa_iostatus,pa_makecode,pa_mothercode from package ");
  442. sql.Append("where pa_outboxcode='" + input.Text + "' and pa_type in (1,2)");
  443. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  444. if (dt.Rows.Count > 0)
  445. {
  446. string pa_iostatus = dt.Rows[0]["pa_iostatus"].ToString();
  447. string pa_outno = dt.Rows[0]["pa_outno"].ToString();
  448. string pa_mothercode = dt.Rows[0]["pa_mothercode"].ToString();
  449. string pa_makecode = dt.Rows[0]["pa_makecode"].ToString();
  450. if (pa_iostatus != "0" && pa_iostatus != "1")
  451. {
  452. OperateResult.AppendText("箱号" + input.Text + "不是备货状态,无法取消备货\n", Color.Red, input);
  453. return;
  454. }
  455. if (pa_outno == "")
  456. {
  457. OperateResult.AppendText("箱号" + input.Text + "无所属出货单号\n", Color.Red, input);
  458. return;
  459. }
  460. if (pa_outno != pi_inoutno.Text)
  461. {
  462. OperateResult.AppendText("箱号" + input.Text + "所属出货单号" + pa_outno + "与当前所选出货单号" + pi_inoutno.Text + "\n", Color.Red, input);
  463. return;
  464. }
  465. if (pa_mothercode != "")
  466. {
  467. OperateResult.AppendText("箱号" + input.Text + "已经装大箱或栈板:" + pa_mothercode + ",不允许单独操作\n", Color.Red, input);
  468. return;
  469. }
  470. dh.ExecuteSql("delete from prodiomac where pim_inoutno='" + pi_inoutno.Text + "' and pim_outboxcode='" + input.Text + "' and pim_type='BOX' and pim_inorout='OUT' AND pim_class='出货'", "delete");
  471. dh.UpdateByCondition("package", "pa_outno=''", "pa_outboxcode='" + input.Text + "'");
  472. OperateResult.AppendText("箱号" + input.Text + "取消备货成功\n", Color.Black, input);
  473. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode, User.UserLineCode, User.UserSourceCode, "箱号" + input.Text + "取消出货备货", "箱号" + input.Text + "取消出货备货成功", "", input.Text);
  474. }
  475. else
  476. {
  477. OperateResult.AppendText("箱号" + input.Text + "不在备货数据中\n", Color.Red, input);
  478. return;
  479. }
  480. }
  481. else if (serBtn.Checked)
  482. {
  483. string ms_id = dh.getFieldDataByCondition("makeserial", "max(ms_id)ms_id", "ms_sncode='" + input.Text + "'").ToString();
  484. if (ms_id == "")
  485. {
  486. OperateResult.AppendText("序列号" + input.Text + "不存在,请重新输入\n", Color.Red, input);
  487. return;
  488. }
  489. sql.Clear();
  490. sql.Append("select ms_status,nvl(ms_downstatus,0)ms_downstatus,ms_outboxcode,ms_makecode,");
  491. sql.Append("nvl(ms_iostatus,0)ms_iostatus,ms_prodcode,ms_outno from makeserial where ms_id='" + ms_id + "'");
  492. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  493. if (dt.Rows.Count > 0)
  494. {
  495. string ms_outboxcode = dt.Rows[0]["ms_outboxcode"].ToString();
  496. string ms_outno = dt.Rows[0]["ms_outno"].ToString();
  497. string ms_iostatus = dt.Rows[0]["ms_iostatus"].ToString();
  498. string ms_makecode = dt.Rows[0]["ms_makecode"].ToString();
  499. if (ms_iostatus != "0" && ms_iostatus != "1")
  500. {
  501. OperateResult.AppendText("序列号号" + input.Text + "不是备货状态,无法取消备货\n", Color.Red, input);
  502. return;
  503. }
  504. if (ms_outno == "")
  505. {
  506. OperateResult.AppendText("序列号" + input.Text + "无所属出货单号\n", Color.Red, input);
  507. return;
  508. }
  509. if (ms_outno != pi_inoutno.Text)
  510. {
  511. OperateResult.AppendText("序列号" + input.Text + "所属出货单号" + ms_outno + "与当前所选出货单号" + pi_inoutno.Text + "\n", Color.Red, input);
  512. return;
  513. }
  514. if (ms_outboxcode != "")
  515. {
  516. OperateResult.AppendText("箱号" + input.Text + "已经装大箱:" + ms_outboxcode + ",不允许单独操作\n", Color.Red, input);
  517. return;
  518. }
  519. dh.ExecuteSql("delete from prodiomac where pim_id in (select pim_id from prodiomac where pim_inoutno='" + pi_inoutno.Text + "' and pim_mac='" + input.Text + "' and pim_inorout='OUT' and pim_class='出货')", "delete");
  520. dh.UpdateByCondition("makeserial", "ms_iostatus=1 , ms_outno = ''", "ms_id = '" + ms_id + "'");
  521. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode, User.UserLineCode, User.UserSourceCode, "序列号" + input.Text + "取消出货备货", "序列号" + input.Text + "取消出货备货成功", input.Text, "");
  522. OperateResult.AppendText("序列号" + input.Text + "取消备货成功\n", Color.Black, input);
  523. }
  524. else
  525. {
  526. OperateResult.AppendText("序列号" + input.Text + "不在备货数据中\n", Color.Red, input);
  527. return;
  528. }
  529. }
  530. else
  531. {
  532. OperateResult.AppendText("未选择录入数据类型\n", Color.Red, input);
  533. return;
  534. }
  535. LoadFormData();
  536. LoadGridData();
  537. }
  538. }
  539. else
  540. {
  541. OperateResult.AppendText("出货单" + pi_inoutno.Text + "不存在\n", Color.Red, pi_inoutno);
  542. return;
  543. }
  544. }
  545. }
  546. private void updatesn(string ms_id)
  547. {
  548. //更新操作
  549. sql.Clear();
  550. sql.Append("insert into prodiomac(pim_id,pim_inoutno,pim_piid,pim_prodcode,pim_mac,pim_indate,pim_inman,pim_type,pim_inorout,pim_class)");
  551. sql.Append("values(prodiomac_seq.nextval,'" + pi_inoutno.Text + "','" + pi_id.Text + "','" + dtms.Rows[0]["ms_prodcode"].ToString() + "','" + input.Text + "',sysdate,'" + User.UserCode + "',' ','OUT','出货')");
  552. dh.ExecuteSql(sql.GetString(), "insert");
  553. dh.UpdateByCondition("makeserial", "ms_outno='" + pi_inoutno.Text + "'", " ms_id='" + ms_id + "'");
  554. }
  555. //插入prodiomac表
  556. private void insertprodiomac(string type)
  557. {
  558. string pib_type = "";
  559. if (type == "栈板号")
  560. {
  561. pib_type = "PALLET";
  562. }
  563. else if (type == "箱号")
  564. {
  565. pib_type = "BOX";
  566. }
  567. sql.Clear();
  568. sql.Append("insert into prodiomac(pim_id,pim_inoutno,pim_piid,pim_prodcode,pim_mac,pim_indate,pim_inman,pim_type,pim_outboxcode,pim_inorout,pim_class)");
  569. sql.Append("select prodiomac_seq.nextval,'" + pi_inoutno.Text + "','" + pi_id.Text + "',v_prodcode,v_barcode,sysdate,'" + User.UserCode + "','" + pib_type + "','" + input.Text + "','OUT','出货' from mes_package_view where v_outboxcode='" + input.Text + "'");
  570. dh.ExecuteSql(sql.GetString(), "insert");
  571. }
  572. private Boolean checkinsertprodiomac(string type)
  573. {
  574. sql.Clear();
  575. sql.Append("select wm_concat(v_barcode)data,count(1)cn from mes_package_view left join makeserial on ms_sncode=v_barcode and ms_makecode=v_makecode where v_outboxcode='" + input.Text + "' and nvl(ms_status,0)<>2 and rownum<20");
  576. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  577. if (dt.Rows[0]["data"].ToString() != "" && int.Parse(dt.Rows[0]["cn"].ToString()) > 0)
  578. {
  579. OperateResult.AppendText(type + input.Text + "内序列号未完工,序列号:" + dt.Rows[0]["data"].ToString() + "\n", Color.Red, input);
  580. return false;
  581. }
  582. if (dta.Rows[0]["pi_type"].ToString() == "按订单出货")
  583. {
  584. sql.Clear();
  585. sql.Append("select ms_prodcode,ms_salecode,cn from (select ms_prodcode,ms_salecode,count(1)cn from mes_package_view left join makeserial on ms_sncode=v_barcode and ms_makecode=v_makecode where v_outboxcode='" + input.Text + "' ");
  586. sql.Append(" group by ms_prodcode,ms_salecode) left join (select pd_ordercode,pd_prodcode,outqty-nvl((select count(1) from prodiomac where pim_inoutno='" + pi_inoutno.Text + "' and pim_prodcode=pd_prodcode),0)ungetqty");
  587. sql.Append(" from (select pd_ordercode,pd_prodcode,sum(pd_outqty)outqty from prodiodetail where pd_piid=" + pi_id.Text + " group by pd_prodcode,pd_ordercode)) on ms_prodcode=pd_prodcode and ms_salecode=pd_ordercode where nvl(pd_prodcode,' ')<>' ' or nvl(pd_ordercode,' ')<>' ' or cn>nvl(ungetqty,0)");
  588. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  589. if (!(int.Parse(dt.Rows[0]["cn"].ToString()) > 0))
  590. {
  591. OperateResult.AppendText(type + input.Text + "内的序列号中的物料+订单不在出货单中或者栈板内中序列号的数量大于剩余出货数,栈板内物料号:" + dt.Rows[0]["ms_prodcode"].ToString() + ",订单号:" + dt.Rows[0]["ms_salecode"].ToString() + ",数量:" + dt.Rows[0]["cn"].ToString() + "\n", Color.Red, input);
  592. return false;
  593. }
  594. else
  595. {
  596. //插入prodiomac表
  597. insertprodiomac(type);
  598. return true;
  599. }
  600. }
  601. else if (dta.Rows[0]["pi_type"].ToString() == "自由出货")
  602. {
  603. insertprodiomac(type);
  604. return true;
  605. }
  606. return true;
  607. }
  608. private Boolean checkinput(DataTable dt, string type)
  609. {
  610. if (dt.Rows[0]["pa_outno"].ToString() != "")
  611. {
  612. OperateResult.AppendText(type + input.Text + "已经被出货单:" + dt.Rows[0]["pa_outno"].ToString() + "采集,请重新输入\n", Color.Red, input);
  613. return false;
  614. }
  615. if (dt.Rows[0]["pa_status"].ToString() != "1")
  616. {
  617. OperateResult.AppendText(type + input.Text + "未封装,请重新输入\n", Color.Red, input);
  618. return false;
  619. }
  620. else if (dt.Rows[0]["pa_status"].ToString() == "2")
  621. {
  622. OperateResult.AppendText(type + input.Text + "已出库,请重新输入\n", Color.Red, input);
  623. return false;
  624. }
  625. if (needMakeIn != "0")
  626. {
  627. if (dt.Rows[0]["pa_iostatus"].ToString() != "1")
  628. {
  629. OperateResult.AppendText(type + input.Text + "必须完工入库才允许出库\n", Color.Red, input);
  630. return false;
  631. }
  632. }
  633. if (dt.Rows[0]["pa_downstatus"].ToString() != "0")
  634. {
  635. OperateResult.AppendText(type + input.Text + "处于下地状态,若需出货,请先取消下地\n", Color.Red, input);
  636. return false;
  637. }
  638. if (dt.Rows[0]["pa_iostatus"].ToString() == "2")
  639. {
  640. OperateResult.AppendText(type + input.Text + "已经出货\n", Color.Red, input);
  641. return false;
  642. }
  643. if (dt.Rows[0]["pa_iostatus"].ToString() == "3")
  644. {
  645. OperateResult.AppendText(type + input.Text + "处于销售退货状态\n", Color.Red, input);
  646. return false;
  647. }
  648. if (dt.Rows[0]["pa_outno"].ToString() != "")
  649. {
  650. OperateResult.AppendText(type + input.Text + "已经被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集\n", Color.Red, input);
  651. return false;
  652. }
  653. return true;
  654. }
  655. private void Clean_Click(object sender, EventArgs e)
  656. {
  657. sql.Clear();
  658. sql.Append("select nvl(pi_pdastatus,'未备货')pi_pdastatus,pi_id from prodinout where pi_inoutno='" + pi_inoutno.Text + "'");
  659. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  660. if (dt.Rows.Count > 0)
  661. {
  662. if (dt.Rows[0]["pi_pdastatus"].ToString() == "已出库")
  663. {
  664. OperateResult.AppendText("出货单" + pi_inoutno.Text + "已经出库,不允许取消明细\n", Color.Red);
  665. return;
  666. }
  667. else if (dt.Rows[0]["pi_pdastatus"].ToString() == "未备货")
  668. {
  669. OperateResult.AppendText("出货单" + pi_inoutno.Text + "尚未备货,无法取消明细\n", Color.Red);
  670. return;
  671. }
  672. List<String> ExeSQL = new List<string>();
  673. ExeSQL.Add("update makeserial set ms_outno = '' where exists (select 1 from prodiomac where pim_inoutno='" + pi_inoutno.Text + "' and pim_mac=ms_sncode and pim_prodcode=ms_prodcode and nvl(pim_outboxcode,' ')=' ') and ms_status=2");
  674. ExeSQL.Add("update package set pa_outno = '' where exists (select 1 from prodiomac where pim_inoutno='" + pi_inoutno.Text + "' and pim_outboxcode=pa_outboxcode and ((pim_type='PALLET' AND PA_TYPE=3) OR (PIM_TYPE='BOX' AND PA_TYPE IN(1,2)))) AND PA_OUTNO='" + pi_inoutno.Text + "'");
  675. ExeSQL.Add("delete from prodiomac where pim_inoutno='" + pi_inoutno.Text + "'");
  676. ExeSQL.Add("update prodinout set pi_pdastatus='未备货' where pi_inoutno='" + pi_inoutno.Text + "'");
  677. ExeSQL.Add("insert into messagelog(ml_id,ml_date,ml_man,ml_content,ml_result,ml_search)values(messagelog_seq.nextval,sysdate,'" + User.UserName + "','清除全部备货明细','清除备货明细成功','ProdInOut!Sale|pi_id=" + pi_id.Text + "')");
  678. dh.ExecuteSQLTran(ExeSQL.ToArray());
  679. OperateResult.AppendText("出货单" + pi_inoutno.Text + "取消明细成功\n", Color.Black, input);
  680. }
  681. else
  682. {
  683. OperateResult.AppendText("出货单" + pi_inoutno.Text + "不存在\n", Color.Red, pi_inoutno);
  684. return;
  685. }
  686. LoadFormData();
  687. LoadGridData();
  688. }
  689. private void serBtn_Click(object sender, EventArgs e)
  690. {
  691. if (((RadioButton)sender).Checked == true)
  692. {
  693. if (((RadioButton)sender).Name == "serBtn")
  694. {
  695. input.Focus();
  696. OperateResult.AppendText("请输入序列号进行采集\n", Color.Black, input);
  697. }
  698. else if (((RadioButton)sender).Name == "bigboxBtn")
  699. {
  700. input.Focus();
  701. OperateResult.AppendText("请输入箱号进行采集\n", Color.Black, input);
  702. }
  703. else if (((RadioButton)sender).Name == "palletBtn")
  704. {
  705. input.Focus();
  706. OperateResult.AppendText("请输入栈板进行采集\n", Color.Black, input);
  707. }
  708. }
  709. }
  710. }
  711. }