Make_PositionStock.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using UAS_MES.DataOperate;
  7. using UAS_MES.Entity;
  8. using UAS_MES.PublicMethod;
  9. namespace UAS_MES.Make
  10. {
  11. public partial class Make_PositionStock : Form
  12. {
  13. AutoSizeFormClass asc = new AutoSizeFormClass();
  14. DataHelper dh;
  15. DataTable dt;
  16. LogStringBuilder sql = new LogStringBuilder();
  17. DataTable Dbfind;
  18. string ma_id;
  19. string craftcode_condition = "";
  20. public Make_PositionStock()
  21. {
  22. InitializeComponent();
  23. }
  24. private void 岗位备料_Load(object sender, EventArgs e)
  25. {
  26. asc.controllInitializeSize(this);
  27. ma_code.TableName = "make left join product on ma_prodcode=pr_code ";
  28. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_craftcode # 工艺路线,pr_detail # 产品名称";
  29. ma_code.FormName = Name;
  30. ma_code.DBTitle = "工单查询";
  31. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "pr_detail", "ma_craftcode" };
  32. ma_code.Condition = "ma_statuscode='STARTED'";
  33. ma_code.DbChange += Ma_code_DbChange;
  34. sc_stepcode.Text = User.CurrentStepCode;
  35. ma_code.SetLockCheckBox(Lock);
  36. Lock.GetMakeCodeCtl(ma_code);
  37. dh = new DataHelper();
  38. }
  39. private void Ma_code_DbChange(object sender, EventArgs e)
  40. {
  41. Dbfind = ma_code.ReturnData;
  42. BaseUtil.SetFormValue(this.Controls, Dbfind);
  43. FillDataGridView();
  44. }
  45. private void 岗位备料_SizeChanged(object sender, EventArgs e)
  46. {
  47. asc.controlAutoSize(this);
  48. }
  49. private void Clean_Click(object sender, EventArgs e)
  50. {
  51. OperateResult.Clear();
  52. }
  53. //物料批号Enter事件
  54. private void pr_batchnum_KeyDown(object sender, KeyEventArgs e)
  55. {
  56. if (e.KeyCode == Keys.Enter)
  57. {
  58. if (pr_batchnum.Text != "")
  59. {
  60. if (ma_code.Text != "")
  61. {
  62. sql.Clear();
  63. sql.Append("select cr_code from craft left join craftdetail on cd_crid=cr_id where cr_code in (" + craftcode_condition + ") ");
  64. sql.Append("and cr_prodcode='" + ma_prodcode.Text + "' and cr_statuscode='AUDITED' and cd_stepcode='" + User.CurrentStepCode + "'");
  65. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  66. if (dt.Rows.Count > 0)
  67. {
  68. //输入的是条码号的时候
  69. 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");
  70. if (dt.Rows.Count > 0)
  71. {
  72. string bar_remain = dt.Rows[0]["bar_remain"].ToString();
  73. string bar_prodcode = dt.Rows[0]["bar_prodcode"].ToString();
  74. sql.Clear();
  75. sql.Append("select sp_id,sp_oneuseqty,sp_soncode,sp_prefix from stepbom left join stepproduct on sp_sbid=sb_id ");
  76. sql.Append("where sb_craftcode='" + ma_craftcode.Text + "' and sb_prodcode='" + ma_prodcode.Text + "' and ");
  77. sql.Append("sb_bomversion='" + ma_bomversion.Text + "' and sp_stepcode='" + User.CurrentStepCode + "' and sp_soncode ='" + bar_prodcode + "' and sp_tracekind=2 ");
  78. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  79. if (dt.Rows.Count > 0)
  80. {
  81. InsertMakeSourceStock(dt, int.Parse(bar_remain));
  82. }
  83. else OperateResult.AppendText(">>物料批号" + pr_batchnum.Text + "对应的物料不是当前工单当前工序需要备的物料\n", Color.Red, pr_batchnum);
  84. }
  85. else
  86. {
  87. //是否包含备料的批管控物料号
  88. sql.Clear();
  89. sql.Append("select sp_id,sp_oneuseqty,sp_soncode,sp_prefix from stepbom left join stepproduct on sp_sbid=sb_id ");
  90. sql.Append("where sb_craftcode='" + ma_craftcode.Text + "' and sb_prodcode='" + ma_prodcode.Text + "' and ");
  91. sql.Append("sb_bomversion='" + ma_bomversion.Text + "' and sp_stepcode='" + User.CurrentStepCode + "' and sp_tracekind=2 ");
  92. sql.Append("and instr('" + pr_batchnum.Text + "',SP_SONCODE) > 0");
  93. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  94. if (dt.Rows.Count > 0)
  95. {
  96. InsertMakeSourceStock(dt, 0);
  97. }
  98. else
  99. {
  100. //匹配批管控物料中的前缀和长度
  101. sql.Clear();
  102. sql.Append("select sp_id,sp_oneuseqty,sp_soncode,sp_prefix from stepbom left join stepproduct on sp_sbid=sb_id ");
  103. sql.Append("where sb_craftcode='" + ma_craftcode.Text + "' and sb_prodcode='" + ma_prodcode.Text + "' and ");
  104. sql.Append("sb_bomversion='" + ma_bomversion.Text + "' and sp_stepcode='" + User.CurrentStepCode + "' and sp_tracekind=2 ");
  105. sql.Append("and instr('" + pr_batchnum.Text + "',sp_prefix) > 0 and ((nvl(SP_LENGTH,0)>0 and sp_length ");
  106. sql.Append("= length('" + pr_batchnum.Text + "')) or nvl(SP_LENGTH,0)=0)");
  107. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  108. if (dt.Rows.Count > 0)
  109. {
  110. InsertMakeSourceStock(dt, 0);
  111. }
  112. else OperateResult.AppendText(">>物料批号" + pr_batchnum.Text + "对应的物料不是当前工单当前工序需要备的物料\n", Color.Red, pr_batchnum);
  113. }
  114. }
  115. }
  116. else OperateResult.AppendText(">>当前岗位资源工序不在工单对应的途程中\n", Color.Red);
  117. }
  118. else OperateResult.AppendText(">>工单号不能为空\n", Color.Red, pr_batchnum);
  119. }
  120. else OperateResult.AppendText(">>物料批号不允许为空\n", Color.Red);
  121. }
  122. }
  123. private void InsertMakeSourceStock(DataTable dt, int Barremain)
  124. {
  125. string sp_oneuseqty = dt.Rows[0]["sp_oneuseqty"].ToString();
  126. string sp_soncode = dt.Rows[0]["sp_soncode"].ToString();
  127. string sp_prefix = dt.Rows[0]["sp_prefix"].ToString();
  128. sql.Clear();
  129. sql.Append("insert into makesourcestock (mss_id,mss_makecode,mss_linecode ,mss_craftcode,");
  130. sql.Append("mss_stepcode,mss_barcode,mss_fprodcode,mss_indate,mss_inman,mss_qty,");
  131. sql.Append("mss_remain,mss_baseqty,mss_prodcode,mss_maid,mss_sourcecode) values(makesourcestock_seq.nextval,'" + ma_code.Text + "','" + User.UserLineCode + "',");
  132. sql.Append("'" + ma_craftcode.Text + "','" + sc_stepcode.Text + "','" + pr_batchnum.Text + "','" + sp_soncode + "',");
  133. sql.Append("sysdate,'" + User.UserCode + "','" + Barremain + "','" + Barremain + "','" + sp_oneuseqty + "','" + sp_soncode + "','" + ma_id + "','" + User.UserSourceCode + "')");
  134. dh.ExecuteSql(sql.GetString(), "insert");
  135. dh.UpdateByCondition("barcode", "bar_place='" + ma_code.Text + "'", "bar_code='" + pr_batchnum.Text + "'");
  136. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "岗位备料", "上料物料" + pr_batchnum.Text, "", "");
  137. //数据插入成功后加载Grid的数据
  138. FillDataGridView();
  139. OperateResult.AppendText(">>物料批号" + pr_batchnum.Text + "备料成功\n", Color.Green, pr_batchnum);
  140. }
  141. //加载Grid数据
  142. private void FillDataGridView()
  143. {
  144. sql.Clear();
  145. sql.Append("select 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,");
  146. sql.Append("pr_detail,nvl(mss_useqty,0) mss_useqty from stepbom left join stepproduct on sp_sbid=sb_id left join product on ");
  147. sql.Append("pr_code=sp_mothercode left join makesourcestock on mss_makecode='" + ma_code.Text + "' and mss_craftcode=sb_craftcode ");
  148. sql.Append("and mss_stepcode=sp_stepcode and sp_soncode=mss_prodcode where sb_prodcode='" + ma_prodcode.Text + "' and sb_craftcode='" + ma_craftcode.Text + "' ");
  149. sql.Append("and sp_stepcode='" + User.CurrentStepCode + "' and sp_tracekind=2 order by sp_soncode");
  150. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  151. BaseUtil.FillDgvWithDataTable(BatchProductDGV, dt);
  152. }
  153. private void Confirm_Click(object sender, EventArgs e)
  154. {
  155. pr_batchnum_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  156. }
  157. private void Screen_Click(object sender, EventArgs e)
  158. {
  159. FillDataGridView();
  160. }
  161. private void ma_prodcode_TextChanged(object sender, EventArgs e)
  162. {
  163. if (ma_code.Text != "")
  164. {
  165. 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");
  166. if (dt.Rows.Count > 0)
  167. {
  168. ma_id = dt.Rows[0]["ma_id"].ToString();
  169. string craftcode = dt.Rows[0]["ma_craftcode"].ToString();
  170. BaseUtil.SetFormValue(this.Controls, dt);
  171. }
  172. else OperateResult.AppendText(">>工单号不存在\n", Color.Red);
  173. }
  174. else OperateResult.AppendText(">>工单号不允许为空\n", Color.Red);
  175. }
  176. private void BatchProduct_CellContentClick(object sender, DataGridViewCellEventArgs e)
  177. {
  178. if (BatchProductDGV.Columns[e.ColumnIndex].Name == "DeleteRow")
  179. {
  180. if (e.RowIndex >= 0)
  181. {
  182. string id = BatchProductDGV.Rows[e.RowIndex].Cells["mss_id"].Value.ToString();
  183. string useqty = BatchProductDGV.Rows[e.RowIndex].Cells["mss_useqty"].Value.ToString();
  184. string soncode = BatchProductDGV.Rows[e.RowIndex].Cells["sp_soncode"].Value.ToString();
  185. if (id != "0")
  186. {
  187. if (useqty == "0")
  188. {
  189. BatchProductDGV.Rows.RemoveAt(e.RowIndex);
  190. dh.ExecuteSql("delete from makesourcestock where mss_id='" + id + "'", "delete");
  191. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "岗位备料", "删除物料" + soncode, "", "");
  192. OperateResult.AppendText(">>料号" + soncode + "删除成功\n");
  193. FillDataGridView();
  194. }
  195. else OperateResult.AppendText(">>料号" + soncode + "已被使用,不允许删除\n", Color.Red);
  196. }
  197. }
  198. }
  199. }
  200. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  201. {
  202. if (ma_code.Text.Length > 4)
  203. {
  204. string ErrMessage = "";
  205. if (LogicHandler.CheckMakeStatus(ma_code.Text, out ErrMessage))
  206. {
  207. craftcode_condition = "";
  208. DataTable dt = (DataTable)dh.ExecuteSql("select ma_craftcode from make where ma_code='" + ma_code.Text + "'", "select");
  209. string craftcode = "";
  210. if (dt.Rows.Count > 0)
  211. {
  212. craftcode = dt.Rows[0]["ma_craftcode"].ToString();
  213. }
  214. sql.Clear();
  215. sql.Append("select distinct ms_craftcode ma_craftcode from makeserial left join craft on cr_code=ms_craftcode ");
  216. sql.Append("where ms_makecode='" + ma_code.Text + "' and ms_craftcode<>'" + craftcode + "'");
  217. dt.Merge((DataTable)dh.ExecuteSql(sql.GetString(), "select"));
  218. ma_craftcode.DisplayMember = "ma_craftcode";
  219. ma_craftcode.ValueMember = "ma_craftcode";
  220. ma_craftcode.DataSource = dt;
  221. for (int i = 0; i < dt.Rows.Count; i++)
  222. {
  223. if (dt.Rows.Count - 1 == i)
  224. craftcode_condition += "'" + dt.Rows[i]["ma_craftcode"].ToString() + "'";
  225. else
  226. craftcode_condition += "'" + dt.Rows[i]["ma_craftcode"].ToString() + "',";
  227. }
  228. }
  229. }
  230. }
  231. private void BatchProductDGV_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  232. {
  233. if (BatchProductDGV.Columns[e.ColumnIndex].Name == "mss_qty")
  234. {
  235. string id = BatchProductDGV.Rows[e.RowIndex].Cells["mss_id"].Value.ToString();
  236. string qty = "0";
  237. if (id != "0")
  238. {
  239. try
  240. {
  241. if (int.Parse(BatchProductDGV.Rows[e.RowIndex].Cells["mss_qty"].Value.ToString()) > 0)
  242. {
  243. qty = BatchProductDGV.Rows[e.RowIndex].Cells["mss_qty"].Value.ToString();
  244. }
  245. else
  246. {
  247. OperateResult.AppendText(">>数量必须大于0\n", Color.Red);
  248. return;
  249. }
  250. }
  251. catch (Exception)
  252. {
  253. OperateResult.AppendText(">>数量必须大于0\n", Color.Red);
  254. return;
  255. }
  256. dh.UpdateByCondition("makesourcestock", "mss_qty='" + qty + "'", "mss_id='" + id + "'");
  257. 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());
  258. dh.UpdateByCondition("makesourcestock", "mss_remain=mss_qty-nvl(mss_useqty,0)", "mss_id='" + id + "'");
  259. }
  260. }
  261. }
  262. private void BatchProductDGV_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
  263. {
  264. if (BatchProductDGV.Columns[e.ColumnIndex].Name == "DeleteRow")
  265. {
  266. if (BatchProductDGV.Rows[e.RowIndex].Cells["mss_id"].Value.ToString() == "0")
  267. e.Value = Properties.Resources.WhiteImage;
  268. else
  269. e.Value = Properties.Resources.bindingNavigatorDeleteItem_Image;
  270. }
  271. }
  272. private void ma_craftcode_SelectedIndexChanged(object sender, EventArgs e)
  273. {
  274. Screen.PerformClick();
  275. }
  276. private void BatchProductDGV_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  277. {
  278. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  279. if (e.ColumnIndex > 0)
  280. {
  281. if (BatchProductDGV.Columns[e.ColumnIndex].Name == "mss_remain")
  282. {
  283. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  284. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
  285. Rectangle border = e.CellBounds;
  286. border.Width -= 1;
  287. e.Graphics.DrawRectangle(Pens.White, border);
  288. e.PaintContent(e.CellBounds);
  289. e.Handled = true;
  290. }
  291. }
  292. }
  293. }
  294. }