Make_BigBoxCollection.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. using LabelManager2;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Windows.Forms;
  11. using UAS_MES.DataOperate;
  12. using UAS_MES.Entity;
  13. using UAS_MES.PublicForm;
  14. using UAS_MES.PublicMethod;
  15. namespace UAS_MES.Make
  16. {
  17. public partial class Make_BigBoxCollection : Form
  18. {
  19. AutoSizeFormClass asc = new AutoSizeFormClass();
  20. DataHelper dh;
  21. DataTable dt;
  22. LogStringBuilder sql = new LogStringBuilder();
  23. Document doc;
  24. Make_NewBigBox NewBigBox;
  25. //箱类型
  26. string pa_type;
  27. //物料编号
  28. string pr_code;
  29. //标准容量
  30. int pa_stanqty;
  31. //Package表的主键
  32. string pa_id;
  33. ApplicationClass lbl;
  34. Thread thread;
  35. string ErrorMessage = "";
  36. string pa_nextstep = "";
  37. public Make_BigBoxCollection()
  38. {
  39. InitializeComponent();
  40. }
  41. //创建打印进程
  42. private void NewPrint()
  43. {
  44. try
  45. {
  46. lbl = new ApplicationClass();
  47. BaseUtil.WriteLbl(lbl);
  48. }
  49. catch
  50. {
  51. OperateResult.AppendText("未正确安装CodeSoft软件\n", Color.Red);
  52. }
  53. }
  54. private void 栈板称重_Load(object sender, EventArgs e)
  55. {
  56. asc.controllInitializeSize(this);
  57. thread = new Thread(NewPrint);
  58. SetLoadingWindow stw = new SetLoadingWindow(thread, "初始化打印程序");
  59. BaseUtil.SetFormCenter(stw);
  60. stw.ShowDialog();
  61. dh = new DataHelper();
  62. }
  63. private void Clean_Click(object sender, EventArgs e)
  64. {
  65. OperateResult.Clear();
  66. }
  67. //大箱号Enter事件
  68. private void palletcode_KeyDown(object sender, KeyEventArgs e)
  69. {
  70. if (e.KeyCode == Keys.Enter)
  71. {
  72. if (bigoutboxcode.Text == "")
  73. {
  74. OperateResult.AppendText(">>大箱号不能为空\n", Color.Red);
  75. return;
  76. }
  77. sql.Clear();
  78. sql.Append("select pa_makecode,pa_standardqty,pa_packageqty,pa_prodcode,pa_outboxcode,pa_totalqty,pa_currentqty,pa_custcode,pa_salecode ");
  79. sql.Append("from package where pa_outboxcode='" + bigoutboxcode.Text + "' and pa_type =2");
  80. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  81. BaseUtil.SetFormValue(Controls, dt);
  82. if (dt.Rows.Count > 0)
  83. {
  84. LoadGridData();
  85. dt = dh.getFieldsDataByCondition("Package", new string[] { "pa_id", "pa_standardqty" }, "pa_outboxcode='" + bigoutboxcode.Text + "'");
  86. pa_stanqty = int.Parse(dt.Rows[0]["pa_standardqty"].ToString());
  87. pa_id = dt.Rows[0]["pa_id"].ToString();
  88. FillPrintLabel();
  89. outboxcode.Focus();
  90. }
  91. else OperateResult.AppendText(">>大箱号不存在\n", Color.Red);
  92. }
  93. }
  94. //箱号Enter事件
  95. private void outboxcode_KeyDown(object sender, KeyEventArgs e)
  96. {
  97. if (e.KeyCode == Keys.Enter)
  98. {
  99. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  100. {
  101. if (outboxcode.Text == "")
  102. {
  103. OperateResult.AppendText(">>卡通箱号不能为空\n", Color.Red);
  104. return;
  105. }
  106. pa_nextstep = dh.getFieldDataByCondition("package", "pa_nextstep", "pa_outboxcode='" + outboxcode.Text + "'").ToString();
  107. if (pa_nextstep != User.CurrentStepCode && pa_nextstep != "")
  108. {
  109. OperateResult.AppendText(">>箱号" + outboxcode.Text + "的下一工序不是当前岗位资源对应工序\n", Color.Red, outboxcode);
  110. return;
  111. }
  112. else
  113. {
  114. //判断线外,必须已完工并且未入库
  115. dt = (DataTable)dh.ExecuteSql("select wm_concat(ms_sncode) from mes_package_view left join makeserial on v_barcode=ms_sncode where v_outboxcode='" + outboxcode.Text + "' and ms_status<>2", "select");
  116. if (dt.Rows[0][0].ToString() == "")
  117. {
  118. //判断箱未入库
  119. dt = (DataTable)dh.ExecuteSql("select count(1) from package where pa_outboxcode='" + outboxcode.Text + "' and nvl(pa_iostatus,0)<>0", "select");
  120. if (dt.Rows[0][0].ToString() != "0")
  121. {
  122. OperateResult.AppendText(">>序列号" + dt.Rows[0][0].ToString() + "已入库,不允许装箱\n", Color.Red);
  123. return;
  124. }
  125. }
  126. else
  127. {
  128. OperateResult.AppendText(">>序列号" + dt.Rows[0][0].ToString() + "尚未完工\n", Color.Red);
  129. return;
  130. }
  131. }
  132. if (!dh.CheckExist("package", "pa_outboxcode='" + bigoutboxcode.Text + "' and pa_type=2"))
  133. {
  134. OperateResult.AppendText(">>大箱号不存在\n", Color.Red);
  135. return;
  136. }
  137. //获取大箱的状态
  138. string pa_status = dh.getFieldDataByCondition("package", "nvl(pa_status,0)pa_status", "pa_outboxcode='" + bigoutboxcode.Text + "'").ToString();
  139. if (pa_standardqty.Text == pa_currentqty.Text && pa_status == "0")
  140. {
  141. dh.ExecuteSql("update package set pa_status=1 where pa_outboxcode='" + bigoutboxcode.Text + "'", "update");
  142. }
  143. //如果未装满的话
  144. if (int.Parse(pa_currentqty.Text) < pa_stanqty && pa_status == "0")
  145. {
  146. CollectBox();
  147. }
  148. else
  149. {
  150. bigoutboxcode.Text = LogicHandler.GetOutBoxCode("BIGBOX", "", pa_prodcode.Text, User.UserCode);
  151. //更新箱号已封箱
  152. sql.Clear();
  153. sql.Append("insert into package (pa_id,pa_outboxcode,pa_makecode,pa_indate,pa_packageqty,pa_type,pa_prodcode,pa_level,PA_STATUS,pa_standardqty,pa_sccode,pa_currentstep)values");
  154. sql.Append("(package_seq.nextval,'" + bigoutboxcode.Text + "','" + pa_makecode.Text + "',sysdate,'0',2,'" + pa_prodcode.Text + "',0,'','" + pa_standardqty.Text + "','" + User.UserSourceCode + "','" + User.CurrentStepCode + "')");
  155. dh.ExecuteSql(sql.GetString(), "insert");
  156. palletcode_KeyDown(new object(), new KeyEventArgs(Keys.Enter));
  157. CollectBox();
  158. }
  159. }
  160. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  161. }
  162. }
  163. private void LoadGridData()
  164. {
  165. sql.Clear();
  166. sql.Append("select pa_prodcode,nvl(pd_barcode,PD_INNERBOXCODE) code ,pd_innerqty,pa_salecode");
  167. sql.Append(",pa_makecode,pa_custcode,pa_packageqty from packagedetail left join package on pd_paid=pa_id left ");
  168. sql.Append("join product on pr_code=pa_prodcode where pa_outboxcode ='" + bigoutboxcode.Text + "' and pa_type=2");
  169. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  170. BaseUtil.FillDgvWithDataTable(PackageInf, dt);
  171. }
  172. private void CollectBox()
  173. {
  174. sql.Clear();
  175. sql.Append("select count(0) cn from packagedetail left join package on pa_id=pd_paid where ");
  176. sql.Append("pa_outboxcode='" + bigoutboxcode.Text + "'");
  177. int packageqty = int.Parse((dh.ExecuteSql(sql.GetString(), "select") as DataTable).Rows[0][0].ToString());
  178. DataTable dt = (DataTable)dh.ExecuteSql("select nvl(pa_status,1) pa_status,pa_mothercode from package where pa_outboxcode='" + outboxcode.Text + "' and pa_type=1", "select");
  179. //采集的卡通箱号存在
  180. if (dt.Rows.Count > 0)
  181. {
  182. if (dt.Rows[0]["pa_status"].ToString() == "1")
  183. {
  184. //判断是否已经装箱
  185. if (dt.Rows[0]["pa_mothercode"].ToString() == "")
  186. {
  187. //插入大箱明细
  188. sql.Clear();
  189. sql.Append("insert into packagedetail(pd_id, pd_paid, pd_outboxcode,pd_innerboxcode, pd_innerqty)");
  190. sql.Append("select packagedetail_seq.nextval,'" + pa_id + "','" + bigoutboxcode.Text + "','" + outboxcode.Text + "'");
  191. sql.Append(",pa_packageqty from package where pa_outboxcode='" + outboxcode.Text + "'");
  192. dh.ExecuteSql(sql.GetString(), "insert");
  193. //箱内计数+1
  194. dh.UpdateByCondition("package", "PA_CURRENTQTY=PA_CURRENTQTY+1,PA_PACKAGEQTY=PA_PACKAGEQTY+1,PA_TOTALQTY=(select sum(pd_innerqty) from packagedetail left join package on pa_id=pd_paid where pa_outboxcode='" + bigoutboxcode.Text + "')", "pa_outboxcode='" + bigoutboxcode.Text + "' and pa_type=2");
  195. //更新采集的子箱记录母箱号
  196. dh.UpdateByCondition("package", "pa_mothercode='" + bigoutboxcode.Text + "'", "pa_outboxcode='" + outboxcode.Text + "'");
  197. if (dh.getFieldDataByCondition("package", "pa_makecode", "pa_outboxcode='" + bigoutboxcode.Text + "'").ToString() == "")
  198. {
  199. string carton_macode = dh.getFieldDataByCondition("package", "pa_makecode", "pa_outboxcode='" + outboxcode.Text + "'").ToString();
  200. pa_makecode.Text = carton_macode;
  201. dh.ExecuteSql("update package set pa_makecode='" + carton_macode + "' where pa_outboxcode='" + bigoutboxcode.Text + "'", "update");
  202. }
  203. LogicHandler.DoCommandLog(Tag.ToString(), User.UserSourceCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "大箱采集", "卡通箱" + outboxcode.Text + "采集成功", outboxcode.Text, "");
  204. //记录卡通箱所有序列号操作日志
  205. if (pa_nextstep != "")
  206. {
  207. LogicHandler.OutBoxStepPass(outboxcode.Text, pa_makecode.Text, User.UserSourceCode, User.UserCode, "大箱采集成功,大箱号:" + bigoutboxcode.Text, "大箱采集");
  208. }
  209. LoadGridData();
  210. LoadCollectNum();
  211. //更新箱号的NextStepCode
  212. if (pa_currentqty.Text == "1")
  213. {
  214. string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_outboxcode='" + outboxcode.Text + "'").ToString();
  215. dh.UpdateByCondition("package", "pa_nextstep='" + nextstepcode + "'", "pa_outboxcode='" + bigoutboxcode.Text + "'");
  216. }
  217. OperateResult.AppendText(">>卡通箱号" + outboxcode.Text + "采集成功!\n", Color.Green, outboxcode);
  218. if (packageqty + 1 == pa_stanqty)
  219. {
  220. dh.ExecuteSql("update package set pa_status=1 where pa_outboxcode='" + bigoutboxcode.Text + "'", "update");
  221. if (AutoPrint.Checked)
  222. {
  223. OperateResult.AppendText(">>箱已装满,自动打印!\n", Color.Green);
  224. Printlab.PerformClick();
  225. }
  226. }
  227. }
  228. else OperateResult.AppendText(">>卡通箱号" + outboxcode.Text + "已采集\n", Color.Red, outboxcode);
  229. }
  230. else OperateResult.AppendText(">>卡通箱号" + outboxcode.Text + "尚未封箱\n", Color.Red, outboxcode);
  231. }
  232. else OperateResult.AppendText(">>卡通箱号" + outboxcode.Text + "不存在\n", Color.Red, outboxcode);
  233. }
  234. private void FillPrintLabel()
  235. {
  236. DataTable _dt = (DataTable)dh.ExecuteSql("select la_id,la_printnos,substr(la_url,instr(la_url,'\\',-1)+1)la_name,la_url,la_isdefault from label where la_prodcode='" + pa_prodcode.Text + "' and la_templatetype='大箱标' and la_statuscode='AUDITED' order by la_isdefault", "select");
  237. PrintLabel.DataSource = _dt;
  238. PrintLabel.DisplayMember = "la_name";
  239. PrintLabel.ValueMember = "la_id";
  240. for (int i = 0; i < _dt.Rows.Count; i++)
  241. {
  242. BaseUtil.GetPrintLabel(_dt.Rows[i]["la_name"].ToString(), _dt.Rows[i]["la_url"].ToString());
  243. }
  244. }
  245. private void LoadCollectNum()
  246. {
  247. pa_currentqty.Text = dh.getFieldDataByCondition("package", "PA_CURRENTQTY", "pa_outboxcode='" + bigoutboxcode.Text + "' and pa_type=2").ToString();
  248. }
  249. private void 栈板称重_SizeChanged(object sender, EventArgs e)
  250. {
  251. asc.controlAutoSize(this);
  252. }
  253. private void NewPallet_Click(object sender, EventArgs e)
  254. {
  255. NewBigBox = new Make_NewBigBox("BIGBOX", pa_makecode.Text);
  256. NewBigBox.Controls["Confirm"].Click += Make_BigBoxCollection_Click;
  257. BaseUtil.SetFormCenter(NewBigBox);
  258. NewBigBox.ShowDialog();
  259. }
  260. private void Make_BigBoxCollection_Click(object sender, EventArgs e)
  261. {
  262. bigoutboxcode.Text = NewBigBox.OutBoxCode;
  263. palletcode_KeyDown(new object(), new KeyEventArgs(Keys.Enter));
  264. }
  265. private void Print_Click(object sender, EventArgs e)
  266. {
  267. if (PrintLabel.Items.Count != 0)
  268. {
  269. if (dh.getFieldDataByCondition("package", "pa_status", "pa_outboxcode='" + bigoutboxcode.Text + "'").ToString() == "1")
  270. {
  271. OperateResult.AppendText(">>打印箱号" + bigoutboxcode.Text + "\n", Color.Black);
  272. doc = lbl.Documents.Open(ftpOperater.DownLoadTo + PrintLabel.Text);
  273. Print.CodeSoft(Tag.ToString(), doc, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), PrinterList.Text, pa_outboxcode.Text, int.Parse(PrintNum.Text));
  274. }
  275. else OperateResult.AppendText(">>必须封箱才能进行打印\n", Color.Red);
  276. }
  277. else OperateResult.AppendText(">>产品" + pa_prodcode.Text + "未维护打印标签或者标签未审核\n", Color.Red);
  278. }
  279. private void ReleasePallet_Click(object sender, EventArgs e)
  280. {
  281. if (dh.getRowCount("packagedetail", "pd_outboxcode='" + bigoutboxcode.Text + "'") > 0)
  282. {
  283. if (dh.getFieldDataByCondition("package", "pa_mothercode", "pa_outboxcode='" + bigoutboxcode.Text + "'").ToString() == "")
  284. {
  285. if (dh.getFieldDataByCondition("package", "pa_nextstep", "pa_mothercode='" + bigoutboxcode.Text + "'").ToString() != "")
  286. LogicHandler.OutBoxDrawStepPass(bigoutboxcode.Text, pa_makecode.Text, User.UserSourceCode);
  287. else
  288. {
  289. //删除明细
  290. dh.ExecuteSql("delete from packagedetail where pd_outboxcode='" + bigoutboxcode.Text + "'", "delete");
  291. sql.Clear();
  292. sql.Append("update set package pa_packageqty=0,pa_totalqty=0,pa_currentqty=0,pa_status=0 where pa_outboxcode='" + bigoutboxcode.Text + "'");
  293. dh.ExecuteSql(sql.GetString(), "select");
  294. }
  295. //将子箱的母箱编号置成空
  296. OperateResult.AppendText(">>箱号" + bigoutboxcode.Text + "解除成功\n", Color.Green);
  297. LogicHandler.DoCommandLog(Tag.ToString(), User.UserSourceCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "大箱采集", "解除大箱" + bigoutboxcode.Text + "成功", bigoutboxcode.Text, "");
  298. palletcode_KeyDown(new object(), new KeyEventArgs(Keys.Enter));
  299. }
  300. else OperateResult.AppendText(">>箱号" + bigoutboxcode.Text + "已装箱,不能取消解除装箱\n", Color.Red);
  301. }
  302. else OperateResult.AppendText(">>箱号" + bigoutboxcode.Text + "未采集箱\n", Color.Red);
  303. }
  304. private void Make_BigBoxCollection_FormClosed(object sender, FormClosedEventArgs e)
  305. {
  306. BaseUtil.ClosePrint(lbl);
  307. }
  308. private void Packing_Click(object sender, EventArgs e)
  309. {
  310. if (bigoutboxcode.Text != "")
  311. {
  312. if (dh.CheckExist("package", "pa_outboxcode='" + bigoutboxcode.Text + "' and nvl(pa_status,0)=0"))
  313. {
  314. OperateResult.AppendText(">>" + bigoutboxcode.Text + "封箱成功\n", Color.Green);
  315. LogicHandler.DoCommandLog(Tag.ToString(), User.UserSourceCode, pa_makecode.Text, User.UserLineCode, User.UserSourceCode, "大箱采集", "装箱" + bigoutboxcode.Text + "成功", outboxcode.Text, "");
  316. dh.ExecuteSql("update package set pa_status=1 where pa_outboxcode='" + bigoutboxcode.Text + "'", "update");
  317. }
  318. else OperateResult.AppendText(">>箱号" + bigoutboxcode.Text + "错误或者已封箱\n", Color.Red);
  319. }
  320. else OperateResult.AppendText(">>大箱号不能为空\n", Color.Red);
  321. }
  322. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  323. {
  324. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  325. {
  326. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  327. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  328. }
  329. }
  330. }
  331. }