Warehouse_FinishedProductOut.cs 43 KB

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