Warehouse_FinishedProductOut.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  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. needMakeIn = dh.GetConfig("needMakeIn", "MESSetting").ToString();
  204. if (input.Text == "")
  205. {
  206. OperateResult.AppendText("录入信息不能为空\n", Color.Red, input);
  207. return;
  208. }
  209. sql.Clear();
  210. sql.Append("select nvl(pi_pdastatus,'未备货')pi_pdastatus,pi_type from prodinout where pi_inoutno='" + pi_inoutno.Text + "'");
  211. dta = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  212. if (dta.Rows.Count > 0)
  213. {
  214. if (!cancel.Checked)
  215. {
  216. if (palletBtn.Checked)
  217. {
  218. string pa_makecode = "";
  219. sql.Clear();
  220. 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");
  221. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  222. if (dt.Rows.Count > 0)
  223. {
  224. if (!checkinput(dt, "栈板号"))
  225. return;
  226. pa_makecode = dt.Rows[0]["pa_makecode"].ToString();
  227. }
  228. else
  229. {
  230. OperateResult.AppendText("栈板号" + input.Text + "不存在,请重新输入\n", Color.Red, input);
  231. return;
  232. }
  233. if (!checkinsertprodiomac("栈板号"))
  234. return;
  235. //更新箱号对应的出货单号
  236. dh.UpdateByCondition("package", "pa_outno = '" + pi_inoutno.Text + "'", "pa_outboxcode = '" + input.Text + "'");
  237. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode, User.UserLineCode, User.UserSourceCode, "栈板" + input.Text + "出货备货", "栈板" + input.Text + "出货备货成功", "", input.Text);
  238. }
  239. else if (bigboxBtn.Checked)
  240. {
  241. string outboxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_sncode = '" + input.Text + "'").ToString();
  242. string pa_makecode = "";
  243. if (outboxcode != "")
  244. {
  245. input.Text = outboxcode;
  246. }
  247. sql.Clear();
  248. 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)");
  249. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  250. if (dt.Rows.Count > 0)
  251. {
  252. pa_makecode = dt.Rows[0]["pa_makecode"].ToString();
  253. if (dt.Rows[0]["pa_mothercode"].ToString() != "")
  254. {
  255. OperateResult.AppendText("箱号" + input.Text + "已经装大箱或者栈板" + dt.Rows[0]["pa_mothercode"].ToString() + ",不允许单独出货\n", Color.Red, input);
  256. return;
  257. }
  258. if (!checkinput(dt, "箱号"))
  259. return;
  260. }
  261. else
  262. {
  263. OperateResult.AppendText("箱号" + input.Text + "不存在,请重新输入\n", Color.Red, input);
  264. return;
  265. }
  266. if (!checkinsertprodiomac("箱号"))
  267. return;
  268. //更新箱号对应的出货单号
  269. dh.UpdateByCondition("package", "pa_outno = '" + pi_inoutno.Text + "'", "pa_outboxcode = '" + input.Text + "'");
  270. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode, User.UserLineCode, User.UserSourceCode, "箱号" + input.Text + "出货备货", "箱号" + input.Text + "出货备货成功", "", input.Text);
  271. }
  272. else if (serBtn.Checked)
  273. {
  274. string ms_id = dh.getFieldDataByCondition("makeserial", "max(ms_id)ms_id", "ms_sncode='" + input.Text + "'").ToString();
  275. if (ms_id == "")
  276. {
  277. OperateResult.AppendText("序列号" + input.Text + "不存在,请重新输入\n", Color.Red, input);
  278. return;
  279. }
  280. else
  281. {
  282. sql.Clear();
  283. 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 + "'");
  284. dtms = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  285. string ms_downstatus = dtms.Rows[0]["ms_downstatus"].ToString();
  286. string ms_status = dtms.Rows[0]["ms_status"].ToString();
  287. string ms_outboxcode = dtms.Rows[0]["ms_outboxcode"].ToString();
  288. string ms_iostatus = dtms.Rows[0]["ms_iostatus"].ToString();
  289. string ms_outno = dtms.Rows[0]["ms_outno"].ToString();
  290. string ms_prodcode = dtms.Rows[0]["ms_prodcode"].ToString();
  291. string ms_makecode = dtms.Rows[0]["ms_makecode"].ToString();
  292. if (ms_status != "2")
  293. {
  294. OperateResult.AppendText("序列号" + input.Text + "未完工,不允许出货\n", Color.Red, input);
  295. return;
  296. }
  297. if (ms_outboxcode != "")
  298. {
  299. OperateResult.AppendText("序列号" + input.Text + "有外箱号,不允许单独出货\n", Color.Red, input);
  300. return;
  301. }
  302. if (ms_downstatus != "0")
  303. {
  304. OperateResult.AppendText("序列号" + input.Text + "处于下地状态,不允许出货\n", Color.Red, input);
  305. return;
  306. }
  307. if (needMakeIn != "0")
  308. {
  309. if (ms_iostatus != "1")
  310. {
  311. OperateResult.AppendText("序列号" + input.Text + "必须完工入库才允许出库\n", Color.Red, input);
  312. return;
  313. }
  314. }
  315. if (ms_iostatus == "2")
  316. {
  317. OperateResult.AppendText("序列号" + input.Text + "已出库,出库单号:" + ms_outno + "\n", Color.Red, input);
  318. return;
  319. }
  320. if (ms_iostatus == "3")
  321. {
  322. OperateResult.AppendText("序列号" + input.Text + "出入库状态异常\n", Color.Red, input);
  323. return;
  324. }
  325. if (ms_outno != "")
  326. {
  327. OperateResult.AppendText("序列号" + input.Text + "已经被出货单:" + ms_outno + "采集\n", Color.Red, input);
  328. return;
  329. }
  330. if (dta.Rows[0]["pi_type"].ToString() == "按订单出货")
  331. {
  332. sql.Clear();
  333. 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");
  334. 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() + "')");
  335. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  336. if (dt.Rows[0]["cn"].ToString() == "0")
  337. {
  338. OperateResult.AppendText("序列号" + input.Text + "所属产品:" + dtms.Rows[0]["ms_prodcode"].ToString() + ",合同号:" + dtms.Rows[0]["ms_salecode"].ToString() + ",不在出货单" + pi_inoutno.Text + "中\n", Color.Red, input);
  339. return;
  340. }
  341. else if (int.Parse(dt.Rows[0]["cn"].ToString()) > 0 && int.Parse(dt.Rows[0]["ungetqty"].ToString()) <= 0)
  342. {
  343. OperateResult.AppendText("出货单产品" + dtms.Rows[0]["ms_prodcode"].ToString() + "+合同" + dtms.Rows[0]["ms_salecode"].ToString() + ",已经完成出货采集\n", Color.Red, input);
  344. return;
  345. }
  346. updatesn(ms_id);
  347. }
  348. else if (dta.Rows[0]["pi_type"].ToString() == "自由出货")
  349. {
  350. updatesn(ms_id);
  351. }
  352. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode, User.UserLineCode, User.UserSourceCode, "序列号" + input.Text + "出货备货", "序列号" + input.Text + "出货备货成功", input.Text, "");
  353. }
  354. }
  355. else
  356. {
  357. OperateResult.AppendText("未选择录入数据类型\n", Color.Red, input);
  358. return;
  359. }
  360. LoadFormData();
  361. LoadGridData();
  362. if (dta.Rows[0]["pi_type"].ToString() == "按订单出货")
  363. {
  364. if (int.Parse(dtform.Rows[0]["outqty"].ToString()) > int.Parse(dtform.Rows[0]["getqty"].ToString()))
  365. {
  366. dh.UpdateByCondition("prodinout", "pi_pdastatus='备货中'", "pi_inoutno='" + pi_inoutno.Text + "'");
  367. OperateResult.AppendText("出货单" + pi_inoutno.Text + "备货成功\n", Color.Black, input);
  368. }
  369. else
  370. {
  371. dh.UpdateByCondition("prodinout", "pi_pdastatus='已备货'", "pi_inoutno='" + pi_inoutno.Text + "'");
  372. OperateResult.AppendText("出货单" + pi_inoutno.Text + "已完成备货\n", Color.Black, input);
  373. ConfirmOut_Click(sender, e);
  374. return;
  375. }
  376. }
  377. else if (dta.Rows[0]["pi_type"].ToString() == "自由出货")
  378. {
  379. dh.UpdateByCondition("prodinout", "pi_pdastatus='备货中'", "pi_inoutno='" + pi_inoutno.Text + "'");
  380. OperateResult.AppendText("出货单" + pi_inoutno.Text + "备货成功\n", Color.Black, input);
  381. }
  382. }
  383. else
  384. {
  385. if (dta.Rows[0]["pi_pdastatus"].ToString() == "已出库")
  386. {
  387. OperateResult.AppendText("出货单" + pi_inoutno.Text + "已经出库不允许取消备货\n", Color.Red);
  388. return;
  389. }
  390. else if (dta.Rows[0]["pi_pdastatus"].ToString() == "未备货")
  391. {
  392. OperateResult.AppendText("出货单" + pi_inoutno.Text + "尚未备货,无法取消\n", Color.Red);
  393. return;
  394. }
  395. if (palletBtn.Checked)
  396. {
  397. sql.Clear();
  398. sql.Append("select pa_id,pa_outboxcode,pa_status,nvl(pa_downstatus,0)pa_downstatus, ");
  399. sql.Append("pa_outno, nvl(pa_iostatus,0) pa_iostatus,pa_makecode from package ");
  400. sql.Append("where pa_outboxcode='" + input.Text + "' and pa_type=3");
  401. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  402. if (dt.Rows.Count > 0)
  403. {
  404. string pa_iostatus = dt.Rows[0]["pa_iostatus"].ToString();
  405. string pa_outno = dt.Rows[0]["pa_outno"].ToString();
  406. string pa_makecode = dt.Rows[0]["pa_makecode"].ToString();
  407. if (pa_iostatus != "0" && pa_iostatus != "1")
  408. {
  409. OperateResult.AppendText("栈板号" + input.Text + "不是备货状态,无法取消备货\n", Color.Red, input);
  410. return;
  411. }
  412. if (pa_outno == "")
  413. {
  414. OperateResult.AppendText("栈板号" + input.Text + "无所属出货单号\n", Color.Red, input);
  415. return;
  416. }
  417. if (pa_outno != pi_inoutno.Text)
  418. {
  419. OperateResult.AppendText("栈板号" + input.Text + "所属出货单号" + pa_outno + "与当前所选出货单号" + pi_inoutno.Text + "\n", Color.Red, input);
  420. return;
  421. }
  422. 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");
  423. dh.UpdateByCondition("package", "pa_outno=''", "pa_outboxcode='" + input.Text + "'");
  424. OperateResult.AppendText("栈板号" + input.Text + "取消备货成功\n", Color.Black, input);
  425. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode, User.UserLineCode, User.UserSourceCode, "栈板" + input.Text + "取消出货备货", "栈板" + input.Text + "取消出货备货成功", "", input.Text);
  426. }
  427. else
  428. {
  429. OperateResult.AppendText("栈板号" + input.Text + "不存在,请重新输入\n", Color.Red, input);
  430. return;
  431. }
  432. }
  433. else if (bigboxBtn.Checked)
  434. {
  435. string outboxcode = dh.getFieldDataByCondition("makeserial", "ms_outboxcode", "ms_sncode = '" + input.Text + "'").ToString();
  436. if (outboxcode != "")
  437. {
  438. input.Text = outboxcode;
  439. }
  440. sql.Clear();
  441. sql.Append("select pa_id,pa_outboxcode,pa_status,nvl(pa_downstatus,0)pa_downstatus, ");
  442. sql.Append("pa_outno,nvl(pa_iostatus,0) pa_iostatus,pa_makecode,pa_mothercode from package ");
  443. sql.Append("where pa_outboxcode='" + input.Text + "' and pa_type in (1,2)");
  444. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  445. if (dt.Rows.Count > 0)
  446. {
  447. string pa_iostatus = dt.Rows[0]["pa_iostatus"].ToString();
  448. string pa_outno = dt.Rows[0]["pa_outno"].ToString();
  449. string pa_mothercode = dt.Rows[0]["pa_mothercode"].ToString();
  450. string pa_makecode = dt.Rows[0]["pa_makecode"].ToString();
  451. if (pa_iostatus != "0" && pa_iostatus != "1")
  452. {
  453. OperateResult.AppendText("箱号" + input.Text + "不是备货状态,无法取消备货\n", Color.Red, input);
  454. return;
  455. }
  456. if (pa_outno == "")
  457. {
  458. OperateResult.AppendText("箱号" + input.Text + "无所属出货单号\n", Color.Red, input);
  459. return;
  460. }
  461. if (pa_outno != pi_inoutno.Text)
  462. {
  463. OperateResult.AppendText("箱号" + input.Text + "所属出货单号" + pa_outno + "与当前所选出货单号" + pi_inoutno.Text + "\n", Color.Red, input);
  464. return;
  465. }
  466. if (pa_mothercode != "")
  467. {
  468. OperateResult.AppendText("箱号" + input.Text + "已经装大箱或栈板:" + pa_mothercode + ",不允许单独操作\n", Color.Red, input);
  469. return;
  470. }
  471. 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");
  472. dh.UpdateByCondition("package", "pa_outno=''", "pa_outboxcode='" + input.Text + "'");
  473. OperateResult.AppendText("箱号" + input.Text + "取消备货成功\n", Color.Black, input);
  474. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, pa_makecode, User.UserLineCode, User.UserSourceCode, "箱号" + input.Text + "取消出货备货", "箱号" + input.Text + "取消出货备货成功", "", input.Text);
  475. }
  476. else
  477. {
  478. OperateResult.AppendText("箱号" + input.Text + "不在备货数据中\n", Color.Red, input);
  479. return;
  480. }
  481. }
  482. else if (serBtn.Checked)
  483. {
  484. string ms_id = dh.getFieldDataByCondition("makeserial", "max(ms_id)ms_id", "ms_sncode='" + input.Text + "'").ToString();
  485. if (ms_id == "")
  486. {
  487. OperateResult.AppendText("序列号" + input.Text + "不存在,请重新输入\n", Color.Red, input);
  488. return;
  489. }
  490. sql.Clear();
  491. sql.Append("select ms_status,nvl(ms_downstatus,0)ms_downstatus,ms_outboxcode,ms_makecode,");
  492. sql.Append("nvl(ms_iostatus,0)ms_iostatus,ms_prodcode,ms_outno from makeserial where ms_id='" + ms_id + "'");
  493. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  494. if (dt.Rows.Count > 0)
  495. {
  496. string ms_outboxcode = dt.Rows[0]["ms_outboxcode"].ToString();
  497. string ms_outno = dt.Rows[0]["ms_outno"].ToString();
  498. string ms_iostatus = dt.Rows[0]["ms_iostatus"].ToString();
  499. string ms_makecode = dt.Rows[0]["ms_makecode"].ToString();
  500. if (ms_iostatus != "0" && ms_iostatus != "1")
  501. {
  502. OperateResult.AppendText("序列号号" + input.Text + "不是备货状态,无法取消备货\n", Color.Red, input);
  503. return;
  504. }
  505. if (ms_outno == "")
  506. {
  507. OperateResult.AppendText("序列号" + input.Text + "无所属出货单号\n", Color.Red, input);
  508. return;
  509. }
  510. if (ms_outno != pi_inoutno.Text)
  511. {
  512. OperateResult.AppendText("序列号" + input.Text + "所属出货单号" + ms_outno + "与当前所选出货单号" + pi_inoutno.Text + "\n", Color.Red, input);
  513. return;
  514. }
  515. if (ms_outboxcode != "")
  516. {
  517. OperateResult.AppendText("箱号" + input.Text + "已经装大箱:" + ms_outboxcode + ",不允许单独操作\n", Color.Red, input);
  518. return;
  519. }
  520. 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");
  521. dh.UpdateByCondition("makeserial", "ms_iostatus=1 , ms_outno = ''", "ms_id = '" + ms_id + "'");
  522. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode, User.UserLineCode, User.UserSourceCode, "序列号" + input.Text + "取消出货备货", "序列号" + input.Text + "取消出货备货成功", input.Text, "");
  523. OperateResult.AppendText("序列号" + input.Text + "取消备货成功\n", Color.Black, input);
  524. }
  525. else
  526. {
  527. OperateResult.AppendText("序列号" + input.Text + "不在备货数据中\n", Color.Red, input);
  528. return;
  529. }
  530. }
  531. else
  532. {
  533. OperateResult.AppendText("未选择录入数据类型\n", Color.Red, input);
  534. return;
  535. }
  536. LoadFormData();
  537. LoadGridData();
  538. }
  539. }
  540. else
  541. {
  542. OperateResult.AppendText("出货单" + pi_inoutno.Text + "不存在\n", Color.Red, pi_inoutno);
  543. return;
  544. }
  545. }
  546. }
  547. private void updatesn(string ms_id)
  548. {
  549. //更新操作
  550. sql.Clear();
  551. 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)");
  552. sql.Append("values(prodiomac_seq.nextval,'" + pi_inoutno.Text + "','" + pi_id.Text + "','" + dtms.Rows[0]["ms_prodcode"].ToString() + "','" + input.Text + "',sysdate,'" + User.UserCode + "',' ','OUT','出货')");
  553. dh.ExecuteSql(sql.GetString(), "insert");
  554. dh.UpdateByCondition("makeserial", "ms_outno='" + pi_inoutno.Text + "'", " ms_id='" + ms_id + "'");
  555. }
  556. //插入prodiomac表
  557. private void insertprodiomac(string type)
  558. {
  559. string pib_type = "";
  560. if (type == "栈板号")
  561. {
  562. pib_type = "PALLET";
  563. }
  564. else if (type == "箱号")
  565. {
  566. pib_type = "BOX";
  567. }
  568. sql.Clear();
  569. 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)");
  570. 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 + "'");
  571. dh.ExecuteSql(sql.GetString(), "insert");
  572. }
  573. private Boolean checkinsertprodiomac(string type)
  574. {
  575. sql.Clear();
  576. 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");
  577. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  578. if (dt.Rows[0]["data"].ToString() != "" && int.Parse(dt.Rows[0]["cn"].ToString()) > 0)
  579. {
  580. OperateResult.AppendText(type + input.Text + "内序列号未完工,序列号:" + dt.Rows[0]["data"].ToString() + "\n", Color.Red, input);
  581. return false;
  582. }
  583. if (dta.Rows[0]["pi_type"].ToString() == "按订单出货")
  584. {
  585. sql.Clear();
  586. 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 + "' ");
  587. 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");
  588. 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)");
  589. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  590. if ((int.Parse(dt.Rows[0]["cn"].ToString()) > 0))
  591. {
  592. 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);
  593. return false;
  594. }
  595. else
  596. {
  597. //插入prodiomac表
  598. insertprodiomac(type);
  599. return true;
  600. }
  601. }
  602. else if (dta.Rows[0]["pi_type"].ToString() == "自由出货")
  603. {
  604. insertprodiomac(type);
  605. return true;
  606. }
  607. return true;
  608. }
  609. private Boolean checkinput(DataTable dt, string type)
  610. {
  611. if (dt.Rows[0]["pa_outno"].ToString() != "")
  612. {
  613. OperateResult.AppendText(type + input.Text + "已经被出货单:" + dt.Rows[0]["pa_outno"].ToString() + "采集,请重新输入\n", Color.Red, input);
  614. return false;
  615. }
  616. if (dt.Rows[0]["pa_status"].ToString() != "1")
  617. {
  618. OperateResult.AppendText(type + input.Text + "未封装,请重新输入\n", Color.Red, input);
  619. return false;
  620. }
  621. else if (dt.Rows[0]["pa_status"].ToString() == "2")
  622. {
  623. OperateResult.AppendText(type + input.Text + "已出库,请重新输入\n", Color.Red, input);
  624. return false;
  625. }
  626. if (needMakeIn != "0")
  627. {
  628. if (dt.Rows[0]["pa_iostatus"].ToString() != "1")
  629. {
  630. OperateResult.AppendText(type + input.Text + "必须完工入库才允许出库\n", Color.Red, input);
  631. return false;
  632. }
  633. }
  634. if (dt.Rows[0]["pa_downstatus"].ToString() != "0")
  635. {
  636. OperateResult.AppendText(type + input.Text + "处于下地状态,若需出货,请先取消下地\n", Color.Red, input);
  637. return false;
  638. }
  639. if (dt.Rows[0]["pa_iostatus"].ToString() == "2")
  640. {
  641. OperateResult.AppendText(type + input.Text + "已经出货\n", Color.Red, input);
  642. return false;
  643. }
  644. if (dt.Rows[0]["pa_iostatus"].ToString() == "3")
  645. {
  646. OperateResult.AppendText(type + input.Text + "处于销售退货状态\n", Color.Red, input);
  647. return false;
  648. }
  649. if (dt.Rows[0]["pa_outno"].ToString() != "")
  650. {
  651. OperateResult.AppendText(type + input.Text + "已经被出货单" + dt.Rows[0]["pa_outno"].ToString() + "采集\n", Color.Red, input);
  652. return false;
  653. }
  654. return true;
  655. }
  656. private void Clean_Click(object sender, EventArgs e)
  657. {
  658. sql.Clear();
  659. sql.Append("select nvl(pi_pdastatus,'未备货')pi_pdastatus,pi_id from prodinout where pi_inoutno='" + pi_inoutno.Text + "'");
  660. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  661. if (dt.Rows.Count > 0)
  662. {
  663. if (dt.Rows[0]["pi_pdastatus"].ToString() == "已出库")
  664. {
  665. OperateResult.AppendText("出货单" + pi_inoutno.Text + "已经出库,不允许取消明细\n", Color.Red);
  666. return;
  667. }
  668. else if (dt.Rows[0]["pi_pdastatus"].ToString() == "未备货")
  669. {
  670. OperateResult.AppendText("出货单" + pi_inoutno.Text + "尚未备货,无法取消明细\n", Color.Red);
  671. return;
  672. }
  673. List<String> ExeSQL = new List<string>();
  674. 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");
  675. 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 + "'");
  676. ExeSQL.Add("delete from prodiomac where pim_inoutno='" + pi_inoutno.Text + "'");
  677. ExeSQL.Add("update prodinout set pi_pdastatus='未备货' where pi_inoutno='" + pi_inoutno.Text + "'");
  678. 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 + "')");
  679. dh.ExecuteSQLTran(ExeSQL.ToArray());
  680. OperateResult.AppendText("出货单" + pi_inoutno.Text + "取消明细成功\n", Color.Black, input);
  681. }
  682. else
  683. {
  684. OperateResult.AppendText("出货单" + pi_inoutno.Text + "不存在\n", Color.Red, pi_inoutno);
  685. return;
  686. }
  687. LoadFormData();
  688. LoadGridData();
  689. }
  690. private void serBtn_Click(object sender, EventArgs e)
  691. {
  692. if (((RadioButton)sender).Checked == true)
  693. {
  694. if (((RadioButton)sender).Name == "serBtn")
  695. {
  696. input.Focus();
  697. OperateResult.AppendText("请输入序列号进行采集\n", Color.Black, input);
  698. }
  699. else if (((RadioButton)sender).Name == "bigboxBtn")
  700. {
  701. input.Focus();
  702. OperateResult.AppendText("请输入箱号进行采集\n", Color.Black, input);
  703. }
  704. else if (((RadioButton)sender).Name == "palletBtn")
  705. {
  706. input.Focus();
  707. OperateResult.AppendText("请输入栈板进行采集\n", Color.Black, input);
  708. }
  709. }
  710. }
  711. }
  712. }