Make_PositionStock.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Drawing;
  5. using System.Text;
  6. using System.Windows.Forms;
  7. using UAS_MES_NEW.DataOperate;
  8. using UAS_MES_NEW.Entity;
  9. using UAS_MES_NEW.PublicMethod;
  10. namespace UAS_MES_NEW.Make
  11. {
  12. public partial class Make_PositionStock : Form
  13. {
  14. AutoSizeFormClass asc = new AutoSizeFormClass();
  15. DataHelper dh;
  16. DataTable dt;
  17. LogStringBuilder sql = new LogStringBuilder();
  18. DataTable Dbfind;
  19. string ma_id;
  20. //上一次查询的工单号
  21. string last_macoe = "";
  22. string craftcode_condition = "";
  23. public Make_PositionStock()
  24. {
  25. InitializeComponent();
  26. }
  27. private void Make_PositionStock_Load(object sender, EventArgs e)
  28. {
  29. asc.controllInitializeSize(this);
  30. ma_code.TableName = "make left join product on ma_prodcode=pr_code ";
  31. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,pr_orispeccode # 型号,ma_inqty # 投入数,ma_craftcode # 工艺路线,ma_craftcode # 工艺路线";
  32. ma_code.FormName = Name;
  33. ma_code.DBTitle = "工单查询";
  34. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "pr_orispeccode", "ma_craftcode" };
  35. ma_code.Condition = "ma_statuscode='STARTED' order by ma_auditdate desc";
  36. ma_code.DbChange += Ma_code_DbChange;
  37. sc_stepcode.Text = User.CurrentStepCode;
  38. ma_code.SetLockCheckBox(Lock);
  39. Lock.GetMakeCodeCtl(ma_code);
  40. dh = SystemInf.dh;
  41. }
  42. private void Ma_code_DbChange(object sender, EventArgs e)
  43. {
  44. Dbfind = ma_code.ReturnData;
  45. BaseUtil.SetFormValue(this.Controls, Dbfind);
  46. FillDataGridView();
  47. }
  48. private void Make_PositionStock_SizeChanged(object sender, EventArgs e)
  49. {
  50. asc.controlAutoSize(this);
  51. }
  52. private void Clean_Click(object sender, EventArgs e)
  53. {
  54. OperateResult.Clear();
  55. }
  56. //物料批号Enter事件
  57. private void pr_batchnum_KeyDown(object sender, KeyEventArgs e)
  58. {
  59. if (e.KeyCode == Keys.Enter)
  60. {
  61. if (pr_batchnum.Text != "")
  62. {
  63. if (ma_code.Text != "")
  64. {
  65. sql.Clear();
  66. sql.Append("select cr_code from craft left join craftdetail on cd_crid=cr_id where cr_code in (" + craftcode_condition + ") ");
  67. sql.Append("and cr_prodcode='" + ma_prodcode.Text + "' and cr_statuscode='AUDITED' and cd_stepcode='" + User.CurrentStepCode + "'");
  68. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  69. if (dt.Rows.Count > 0)
  70. {
  71. //输入的是条码号的时候
  72. dt = (DataTable)dh.ExecuteSql("select nvl(bar_remain,0) bar_remain,bar_prodcode from barcode inner join product on pr_code=bar_prodcode where bar_code ='" + pr_batchnum.Text + "'", "select");
  73. if (dt.Rows.Count > 0)
  74. {
  75. string bar_remain = dt.Rows[0]["bar_remain"].ToString();
  76. string bar_prodcode = dt.Rows[0]["bar_prodcode"].ToString();
  77. sql.Clear();
  78. sql.Append("select sp_id,sp_oneuseqty,sp_fsoncode,sp_soncode,sp_prefix from stepbom left join stepproduct on sp_sbid=sb_id ");
  79. sql.Append("where sb_craftcode='" + ma_craftcode.Text + "' and sb_prodcode='" + ma_prodcode.Text + "' and ");
  80. sql.Append("sb_bomversion='" + ma_bomversion.Text + "' and sp_stepcode='" + User.CurrentStepCode + "' and (sp_soncode ='" + bar_prodcode + "' or sp_fsoncode='" + bar_prodcode + "')and sp_tracekind=2 ");
  81. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  82. if (dt.Rows.Count > 0)
  83. {
  84. sql.Clear();
  85. sql.Append("select mss_makecode,mss_linecode from makesourcestock where mss_barcode = '" + pr_batchnum.Text + "'");
  86. DataTable BARCODE = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  87. if (BARCODE.Rows.Count > 0)
  88. {
  89. OperateResult.AppendText(">>物料批号" + pr_batchnum.Text + "已经被工单:" + BARCODE.Rows[0]["mss_makecode"] + ",线别:" + BARCODE.Rows[0]["mss_linecode"] + "备料\n", Color.Red, pr_batchnum);
  90. return;
  91. }
  92. InsertMakeSourceStock(dt, int.Parse(bar_remain));
  93. }
  94. else OperateResult.AppendText(">>物料批号" + pr_batchnum.Text + "对应的物料不是当前工单当前工序需要备的物料\n", Color.Red, pr_batchnum);
  95. }
  96. else
  97. {
  98. //是否包含备料的批管控物料号
  99. sql.Clear();
  100. sql.Append("select sp_id,sp_oneuseqty,sp_fsoncode,sp_soncode,sp_prefix from stepbom left join stepproduct on sp_sbid=sb_id ");
  101. sql.Append("where sb_craftcode='" + ma_craftcode.Text + "' and sb_prodcode='" + ma_prodcode.Text + "' and ");
  102. sql.Append("sb_bomversion='" + ma_bomversion.Text + "' and sp_stepcode='" + User.CurrentStepCode + "' and sp_tracekind=2 ");
  103. sql.Append("and (instr('" + pr_batchnum.Text + "',SP_SONCODE) > 0 or instr('" + pr_batchnum.Text + "',SP_FSONCODE)>0)");
  104. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  105. if (dt.Rows.Count > 0)
  106. {
  107. InsertMakeSourceStock(dt, 0);
  108. }
  109. else
  110. {
  111. //匹配批管控物料中的前缀和长度
  112. sql.Clear();
  113. sql.Append("select sp_id,sp_fsoncode,sp_oneuseqty,sp_soncode,sp_prefix from stepbom left join stepproduct on sp_sbid=sb_id ");
  114. sql.Append("where sb_craftcode='" + ma_craftcode.Text + "' and sb_prodcode='" + ma_prodcode.Text + "' and ");
  115. sql.Append("sb_bomversion='" + ma_bomversion.Text + "' and sp_stepcode='" + User.CurrentStepCode + "' and sp_tracekind=2 ");
  116. sql.Append("and instr('" + pr_batchnum.Text + "',sp_prefix) > 0 and ((nvl(SP_LENGTH,0)>0 and sp_length ");
  117. sql.Append("= length('" + pr_batchnum.Text + "')) or nvl(SP_LENGTH,0)=0)");
  118. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  119. if (dt.Rows.Count > 0)
  120. {
  121. InsertMakeSourceStock(dt, 0);
  122. }
  123. else OperateResult.AppendText(">>物料批号" + pr_batchnum.Text + "对应的物料不是当前工单当前工序需要备的物料\n", Color.Red, pr_batchnum);
  124. }
  125. }
  126. }
  127. else OperateResult.AppendText(">>当前岗位资源工序不在工单对应的途程中\n", Color.Red);
  128. }
  129. else OperateResult.AppendText(">>工单号不能为空\n", Color.Red, pr_batchnum);
  130. }
  131. else OperateResult.AppendText(">>物料批号不允许为空\n", Color.Red);
  132. }
  133. }
  134. private void InsertMakeSourceStock(DataTable dt, int Barremain)
  135. {
  136. string sp_oneuseqty = dt.Rows[0]["sp_oneuseqty"].ToString();
  137. string sp_fsoncode = dt.Rows[0]["sp_fsoncode"].ToString();
  138. string sp_soncode = dt.Rows[0]["sp_soncode"].ToString();
  139. string sp_prefix = dt.Rows[0]["sp_prefix"].ToString();
  140. sql.Clear();
  141. sql.Append("insert into makesourcestock (mss_id,mss_makecode,mss_linecode ,mss_craftcode,");
  142. sql.Append("mss_stepcode,mss_barcode,mss_fprodcode,mss_indate,mss_inman,mss_qty,");
  143. sql.Append("mss_remain,mss_baseqty,mss_prodcode,mss_maid,mss_sourcecode) values(makesourcestock_seq.nextval,'" + ma_code.Text + "','" + User.UserLineCode + "',");
  144. sql.Append("'" + ma_craftcode.Text + "','" + sc_stepcode.Text + "','" + pr_batchnum.Text + "','" + sp_fsoncode + "',");
  145. sql.Append("sysdate,'" + User.UserCode + "','" + Barremain + "','" + Barremain + "','" + sp_oneuseqty + "','" + sp_soncode + "','" + ma_id + "','" + User.UserSourceCode + "')");
  146. dh.ExecuteSql(sql.GetString(), "insert");
  147. dh.UpdateByCondition("barcode", "bar_place='" + ma_code.Text + "'", "bar_code='" + pr_batchnum.Text + "'");
  148. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "岗位备料", "上料物料" + pr_batchnum.Text, "", "");
  149. //数据插入成功后加载Grid的数据
  150. FillDataGridView();
  151. OperateResult.AppendText(">>物料批号" + pr_batchnum.Text + "备料成功\n", Color.Green, pr_batchnum);
  152. }
  153. //加载Grid数据
  154. private void FillDataGridView()
  155. {
  156. if (!show_all_check.Checked)
  157. {
  158. sql.Clear();
  159. sql.Append("select nvl(mss_makecode,' ') mss_makecode,mss_linecode,sp_fsoncode,nvl(mss_id,0) mss_id,sp_soncode,mss_prodcode,sp_oneuseqty,mss_barcode,nvl(mss_qty,0) mss_qty ,nvl(mss_remain,0)mss_remain,");
  160. sql.Append("pr_detail,nvl(mss_useqty,0) mss_useqty from stepbom left join stepproduct on sp_sbid=sb_id left join product on ");
  161. sql.Append("pr_code=sp_mothercode left join makesourcestock on mss_craftcode=sb_craftcode and mss_makecode='" + ma_code.Text + "' and mss_linecode = '" + User.UserLineCode + "' ");
  162. sql.Append("and mss_stepcode=sp_stepcode and sp_soncode=mss_prodcode and sp_fsoncode=mss_fprodcode left join make on ma_bomversion=sb_bomversion where sb_prodcode='" + ma_prodcode.Text + "' and sb_craftcode='" + ma_craftcode.Text + "' ");
  163. sql.Append("and sp_stepcode='" + User.CurrentStepCode + "' and sp_tracekind=2 and ma_code='" + ma_code.Text + "' order by sp_soncode");
  164. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  165. BaseUtil.FillDgvWithDataTable(BatchProductDGV, dt);
  166. }
  167. else
  168. {
  169. sql.Clear();
  170. sql.Append("select nvl(mss_makecode,' ') mss_makecode,mss_linecode,sp_fsoncode,nvl(mss_id,0) mss_id,sp_soncode,mss_prodcode,sp_oneuseqty,mss_barcode,nvl(mss_qty,0) mss_qty ,nvl(mss_remain,0)mss_remain,");
  171. sql.Append("pr_detail,nvl(mss_useqty,0) mss_useqty from stepbom left join stepproduct on sp_sbid=sb_id left join product on ");
  172. sql.Append("pr_code=sp_mothercode left join makesourcestock on mss_craftcode=sb_craftcode ");
  173. sql.Append("and mss_stepcode=sp_stepcode and sp_soncode=mss_prodcode and sp_fsoncode=mss_fprodcode where ");
  174. sql.Append(" sp_stepcode='" + User.CurrentStepCode + "' and sp_tracekind=2 and mss_linecode = '" + User.UserLineCode + "' order by sp_soncode");
  175. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  176. BaseUtil.FillDgvWithDataTable(BatchProductDGV, dt);
  177. }
  178. }
  179. private void Confirm_Click(object sender, EventArgs e)
  180. {
  181. pr_batchnum_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  182. }
  183. private void Screen_Click(object sender, EventArgs e)
  184. {
  185. FillDataGridView();
  186. }
  187. private void ma_prodcode_TextChanged(object sender, EventArgs e)
  188. {
  189. if (ma_code.Text != "")
  190. {
  191. dt = (DataTable)dh.ExecuteSql("select ma_id,ma_craftcode,ma_statuscode,ma_code,ma_prodcode,pr_spec,pr_detail,ma_bomversion from make left join product on ma_prodcode=pr_code where ma_code='" + ma_code.Text + "'", "select");
  192. if (dt.Rows.Count > 0)
  193. {
  194. ma_id = dt.Rows[0]["ma_id"].ToString();
  195. string craftcode = dt.Rows[0]["ma_craftcode"].ToString();
  196. BaseUtil.SetFormValue(this.Controls, dt);
  197. }
  198. else OperateResult.AppendText(">>工单号不存在\n", Color.Red);
  199. }
  200. else OperateResult.AppendText(">>工单号不允许为空\n", Color.Red);
  201. }
  202. private void BatchProduct_CellContentClick(object sender, DataGridViewCellEventArgs e)
  203. {
  204. if (BatchProductDGV.Columns[e.ColumnIndex].Name == "DeleteRow")
  205. {
  206. if (e.RowIndex >= 0)
  207. {
  208. string id = BatchProductDGV.Rows[e.RowIndex].Cells["mss_id"].Value.ToString();
  209. string useqty = BatchProductDGV.Rows[e.RowIndex].Cells["mss_useqty"].Value.ToString();
  210. string soncode = BatchProductDGV.Rows[e.RowIndex].Cells["sp_soncode"].Value.ToString();
  211. if (id != "0")
  212. {
  213. dh.ExecuteSql("delete from makesourcestock where mss_id='" + id + "'", "delete");
  214. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "岗位备料", "删除物料" + soncode, "", "");
  215. OperateResult.AppendText(">>料号" + soncode + "删除成功\n");
  216. FillDataGridView();
  217. }
  218. }
  219. }
  220. }
  221. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  222. {
  223. if (ma_code.Text.Length > 4)
  224. {
  225. string ErrMessage = "";
  226. if (LogicHandler.CheckMakeStatus(ma_code.Text, out ErrMessage))
  227. {
  228. craftcode_condition = "";
  229. DataTable dt = (DataTable)dh.ExecuteSql("select ma_craftcode from make where ma_code='" + ma_code.Text + "'", "select");
  230. string craftcode = "";
  231. if (dt.Rows.Count > 0)
  232. {
  233. craftcode = dt.Rows[0]["ma_craftcode"].ToString();
  234. }
  235. sql.Clear();
  236. sql.Append("select distinct ms_craftcode ma_craftcode from makeserial left join craft on cr_code=ms_craftcode ");
  237. sql.Append("where ms_makecode='" + ma_code.Text + "' and ms_craftcode<>'" + craftcode + "'");
  238. dt.Merge((DataTable)dh.ExecuteSql(sql.GetString(), "select"));
  239. ma_craftcode.DisplayMember = "ma_craftcode";
  240. ma_craftcode.ValueMember = "ma_craftcode";
  241. ma_craftcode.DataSource = dt;
  242. for (int i = 0; i < dt.Rows.Count; i++)
  243. {
  244. if (dt.Rows.Count - 1 == i)
  245. craftcode_condition += "'" + dt.Rows[i]["ma_craftcode"].ToString() + "'";
  246. else
  247. craftcode_condition += "'" + dt.Rows[i]["ma_craftcode"].ToString() + "',";
  248. }
  249. }
  250. }
  251. }
  252. private void BatchProductDGV_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  253. {
  254. if (BatchProductDGV.Columns[e.ColumnIndex].Name == "mss_qty")
  255. {
  256. string id = BatchProductDGV.Rows[e.RowIndex].Cells["mss_id"].Value.ToString();
  257. string qty = "0";
  258. if (id != "0")
  259. {
  260. try
  261. {
  262. if (int.Parse(BatchProductDGV.Rows[e.RowIndex].Cells["mss_qty"].Value.ToString()) > 0)
  263. {
  264. qty = BatchProductDGV.Rows[e.RowIndex].Cells["mss_qty"].Value.ToString();
  265. }
  266. else
  267. {
  268. OperateResult.AppendText(">>数量必须大于0\n", Color.Red);
  269. return;
  270. }
  271. }
  272. catch (Exception)
  273. {
  274. OperateResult.AppendText(">>数量必须大于0\n", Color.Red);
  275. return;
  276. }
  277. dh.UpdateByCondition("makesourcestock", "mss_qty='" + qty + "'", "mss_id='" + id + "'");
  278. BatchProductDGV.Rows[e.RowIndex].Cells["mss_remain"].Value = int.Parse(BatchProductDGV.Rows[e.RowIndex].Cells["mss_qty"].Value.ToString()) - int.Parse(BatchProductDGV.Rows[e.RowIndex].Cells["mss_useqty"].Value.ToString());
  279. dh.UpdateByCondition("makesourcestock", "mss_remain=mss_qty-nvl(mss_useqty,0)", "mss_id='" + id + "'");
  280. }
  281. }
  282. }
  283. private void BatchProductDGV_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
  284. {
  285. if (BatchProductDGV.Columns[e.ColumnIndex].Name == "DeleteRow")
  286. {
  287. if (BatchProductDGV.Rows[e.RowIndex].Cells["mss_id"].Value.ToString() == "0")
  288. e.Value = Properties.Resources.WhiteImage;
  289. else
  290. e.Value = Properties.Resources.bindingNavigatorDeleteItem_Image;
  291. }
  292. }
  293. private void ma_craftcode_SelectedIndexChanged(object sender, EventArgs e)
  294. {
  295. Screen.PerformClick();
  296. }
  297. private void BatchProductDGV_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  298. {
  299. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  300. if (e.ColumnIndex > 0)
  301. {
  302. if (BatchProductDGV.Columns[e.ColumnIndex].Name == "mss_remain")
  303. {
  304. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  305. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
  306. Rectangle border = e.CellBounds;
  307. border.Width -= 1;
  308. e.Graphics.DrawRectangle(Pens.White, border);
  309. e.PaintContent(e.CellBounds);
  310. e.Handled = true;
  311. }
  312. }
  313. }
  314. private void pi_type_check_CheckedChanged(object sender, EventArgs e)
  315. {
  316. if (show_all_check.Checked)
  317. {
  318. pr_batchnum.Enabled = false;
  319. FillDataGridView();
  320. }
  321. else
  322. {
  323. pr_batchnum.Enabled = true;
  324. FillDataGridView();
  325. }
  326. }
  327. private void normalButton1_Click(object sender, EventArgs e)
  328. {
  329. bool makesources = false;
  330. for (int i = 0; i < BatchProductDGV.Rows.Count; i++)
  331. {
  332. string id_1 = BatchProductDGV.Rows[i].Cells["mss_id"].Value.ToString();
  333. if (id_1 != "0")
  334. {
  335. makesources = true;
  336. }
  337. }
  338. if (makesources)
  339. {
  340. String dialog = MessageBox.Show("是否确认全部下料", "提示", MessageBoxButtons.OKCancel).ToString();
  341. if (dialog != "OK")
  342. {
  343. OperateResult.AppendText("取消全部下料\n", Color.Black);
  344. return;
  345. }
  346. else
  347. {
  348. List<string> idcol = new List<string>();
  349. List<string> makecodecol = new List<string>();
  350. List<string> soncodecol = new List<string>();
  351. for (int i = 0; i < BatchProductDGV.Rows.Count; i++)
  352. {
  353. string id = BatchProductDGV.Rows[i].Cells["mss_id"].Value.ToString();
  354. string useqty = BatchProductDGV.Rows[i].Cells["mss_useqty"].Value.ToString();
  355. string soncode = BatchProductDGV.Rows[i].Cells["sp_soncode"].Value.ToString();
  356. string makecode = BatchProductDGV.Rows[i].Cells["mss_makecode"].Value.ToString();
  357. if (id != "0")
  358. {
  359. idcol.Add(id);
  360. makecodecol.Add(makecode);
  361. soncodecol.Add("删除物料" + soncode);
  362. OperateResult.AppendText(">>料号" + soncode + "删除成功\n");
  363. }
  364. }
  365. sql.Clear();
  366. sql.Append("insert into commandlog(cl_id,cl_caller,cl_man,cl_date,cl_linecode,cl_sourcecode,cl_makecode,cl_operate,");
  367. sql.Append("cl_result,cl_sncode,cl_code) values( commandlog_seq.nextval,'" + Tag.ToString() + "','" + User.UserCode + "',sysdate,'" + User.UserLineCode + "' ,");
  368. sql.Append("'" + User.UserSourceCode + " ' ,:iMakeCode,'岗位备料',:iResult,' ',' ')");
  369. dh.BatchInsert(sql.GetString(), new String[] { "iMakeCode", "iResult" }, makecodecol.ToArray(), soncodecol.ToArray());
  370. dh.BatchInsert("delete from makesourcestock where mss_id=:id", new String[] { "id" }, idcol.ToArray());
  371. FillDataGridView();
  372. }
  373. }
  374. else
  375. {
  376. OperateResult.AppendText(">>没有上料记录,无需全部下料\n", Color.Red);
  377. }
  378. }
  379. }
  380. }