SMT_Feeding.cs 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Text;
  5. using System.Threading;
  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.SMT
  11. {
  12. public partial class SMT_Feeding : Form
  13. {
  14. AutoSizeFormClass asc = new AutoSizeFormClass();
  15. DataHelper dh;
  16. DataTable dt;
  17. LogStringBuilder sql = new LogStringBuilder();
  18. RadioButton[] RadioButton;
  19. //判断用户是否执行过筛选
  20. bool Filtered = false;
  21. //勾选的RadioButton
  22. RadioButton CheckedRadio;
  23. //一些全局变量作为传值条件
  24. //站位表的物料编号
  25. string psl_prodcode;
  26. //站位表的替代料
  27. string psl_repcode;
  28. double barremain;
  29. string barcode;
  30. string forcastremain;
  31. string psltable = "";
  32. string bar_prodcode;
  33. //DevSmtLocation表主键
  34. string dsl_id;
  35. //DevSmtLocation表主键
  36. int dsl_remainqty;
  37. //DevSmtLocation表条码号
  38. string dsl_barcode;
  39. //制造单号的机台编号
  40. string ma_smtcode;
  41. SMT_MakeShift MShift;
  42. public SMT_Feeding()
  43. {
  44. InitializeComponent();
  45. try { UAS_MES_NEW.I18n.LanguageManager.Localize(this); } catch { }
  46. }
  47. private void SMT上料_Load(object sender, EventArgs e)
  48. {
  49. de_table.Text = "全部";
  50. asc.controllInitializeSize(this);
  51. dh = new DataHelper();
  52. //机台编号
  53. de_code.FormName = Name;
  54. de_code.SetValueField = new string[] { "ma_code", "de_runstatus", "de_code", "de_table" };
  55. de_code.TableName = "device left join make on de_macode=ma_code";
  56. de_code.SelectField = "de_code # 设备编号,de_linecode # 线别编号,de_name # 设备名称,de_runstatus # 运行状态,ma_code # 工单号,de_table # 版面";
  57. de_code.Condition = "de_linecode='" + User.UserLineCode + "'";
  58. //工单号
  59. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  60. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 物料编号,ma_qty # 数量,ma_prodname # 物料名称,ma_wccode # 工作中心编号,ma_linecode # 工单线别,pr_spec # 产品规格";
  61. ma_code.FormName = Name;
  62. ma_code.SetValueField = new string[] { "ma_code", "ma_qty", "ma_prodspec", "ma_id", "ma_linecode", "ma_prodcode", "pr_spec" };
  63. RadioButton = new RadioButton[] { UpLoad, DownLoad, Shift, PickUp };
  64. }
  65. private void Input_KeyDown(object sender, KeyEventArgs e)
  66. {
  67. if (Keys.Enter == e.KeyData)
  68. {
  69. //点击过筛选按钮才允许
  70. if (Filtered)
  71. {
  72. switch (CheckedRadio.Name.ToUpper())
  73. {
  74. //上料
  75. case "UPLOAD":
  76. //首先录入面板号
  77. if (psl_location.Text == "")
  78. {
  79. sql.Clear();
  80. sql.Append("select psl_prodcode,psl_repcode,psl_table from productsmtlocation left join productsmt on ps_id=psl_psid ");
  81. sql.Append("left join make on ma_smtcode=ps_code where ma_code='" + ma_code.Text + "' and psl_location='" + Input.Text + "'");
  82. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  83. LogManager.DoLog("【" + Text + "】上料操作", sql.GetString());
  84. if (dt.Rows.Count > 0)
  85. {
  86. psltable = dt.Rows[0]["psl_table"].ToString();
  87. psl_prodcode = dt.Rows[0]["psl_prodcode"].ToString();
  88. psl_repcode = dt.Rows[0]["psl_repcode"].ToString();
  89. sql.Clear();
  90. sql.Append("select dsl_id,dsl_barcode from devSMTLocation left join make on ma_code=dsl_makecode and dsl_linecode=");
  91. sql.Append("ma_linecode where dSL_MAKECODE='" + ma_code.Text + "' and dsl_devcode ='" + de_code.Text + "' And");
  92. sql.Append(" dsl_location='" + Input.Text + "' and dsl_status = 0");
  93. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  94. if (dt.Rows.Count == 0)
  95. {
  96. psl_location.Text = Input.Text;
  97. OperateResult.AppendText(">>站位采集" + Input.Text + "成功,请采集物料" + psl_prodcode + " 的料卷号\n", Color.Green);
  98. }
  99. else {
  100. OperateResult.AppendText(">>站位已有料卷" + dt.Rows[0]["dsl_barcode"].ToString() + ",不允许重复上料\n", Color.Red);
  101. }
  102. Input.Text = "";
  103. }
  104. else {
  105. OperateResult.AppendText(">>站位错误,不存在上料排位表中\n", Color.Red);
  106. }
  107. }
  108. //采集料圈数量
  109. else if (bar_code.Text == "")
  110. {
  111. dt = (DataTable)dh.ExecuteSql("select bar_remain,nvl(bar_place,1) bar_place,bar_prodcode,bar_code,bar_forcastremain from barcode where bar_code='" + Input.Text + "' and bar_status=1", "select");
  112. //查询回来的有库存的话
  113. if (dt.Rows.Count > 0)
  114. {
  115. forcastremain = dt.Rows[0]["bar_forcastremain"].ToString();
  116. barremain = double.Parse(dt.Rows[0]["bar_remain"].ToString());
  117. barcode = dt.Rows[0]["bar_code"].ToString();
  118. //并且库存不为0
  119. //到此步骤已采集成功站位和料卷号
  120. if (dt.Rows[0]["bar_remain"].ToString() != "0")
  121. {
  122. if (dt.Rows[0]["bar_place"].ToString() == "1")
  123. {
  124. bar_prodcode = dt.Rows[0]["bar_prodcode"].ToString();
  125. //如果采集的料卷的物料编号和站位表的物料或者替代料相等
  126. if (bar_prodcode == psl_prodcode || psl_repcode.Contains(bar_prodcode))
  127. {
  128. if (forcastremain != "0" && forcastremain != "" && forcastremain != barremain.ToString())
  129. {
  130. bar_code.Text = Input.Text;
  131. bar_remain.Text = forcastremain;
  132. }
  133. else {
  134. bar_remain.Text = double.Parse(barremain.ToString()).ToString();
  135. //插入数据至devSMTLocation
  136. sql.Clear();
  137. sql.Append("insert into DEVSMTLocation(dsl_id,dsl_maid,dsl_makecode, dsl_mmdetno,dsl_location,dsl_prodcode,dsl_repcode,dsl_fespec,");
  138. sql.Append("dsl_getqty,dsl_remainqty,dsl_barcode,dsl_linecode,dsl_devcode,dsl_status,dsl_validtime,dsl_indate,dsl_smtid)");
  139. sql.Append(" select devSMTLocation_SEQ.nextval,ma_id,ma_code,'','" + psl_location.Text + "','" + bar_prodcode + "',");
  140. sql.Append("'" + psl_repcode + "',psl_feeder,'" + bar_remain.Text + "','" + bar_remain.Text + "',");
  141. sql.Append("'" + barcode + "',ma_linecode,'" + de_code.Text + "',0,sysdate,sysdate,ps_id from make left join productsmt on ma_smtcode=ps_code ");
  142. sql.Append("left join productsmtlocation on ps_id=psl_psid where ma_code='" + ma_code.Text + "' and psl_location='" + psl_location.Text + "' and rownum<=1");
  143. dh.ExecuteSql(sql.GetString(), "insert");
  144. //如果几台绑定的工单号未空的情况下更新成当前采集料的
  145. if (dh.getFieldDataByCondition("device", "de_macode", "de_code='" + de_code.Text + "'").ToString() == "")
  146. {
  147. dh.ExecuteSql("update device set de_macode='" + ma_code.Text + "' where de_code='" + de_code.Text + "'", "update");
  148. }
  149. //更新条码(barcode)状态在线上 bar_Place=工单号
  150. dh.ExecuteSql("update barcode set bar_Place='" + ma_code.Text + "' where bar_code='" + Input.Text + "' and bar_status=1", "update");
  151. OperateResult.AppendText(">>料卷采集成功,数量" + barremain + "\n", Color.Green);
  152. LoadGridData();
  153. CleanInf();
  154. }
  155. }
  156. else
  157. {
  158. OperateResult.AppendText(">>采集的物料号" + Input.Text + "不匹配\n", Color.Red);
  159. Input.Text = "";
  160. }
  161. }
  162. else {
  163. OperateResult.AppendText(">>料卷" + Input.Text + "已上线\n", Color.Red);
  164. Input.Text = "";
  165. }
  166. }
  167. else {
  168. OperateResult.AppendText(">> 料卷编号" + Input.Text + "错误,库存数量为0\n", Color.Green);
  169. Input.Text = "";
  170. }
  171. }
  172. else {
  173. OperateResult.AppendText(">>料卷编号" + Input.Text + "错误,不存在或者状态无效\n", Color.Red);
  174. Input.Text = "";
  175. }
  176. }
  177. else if (bar_code.Text != "" && psl_location.Text != "" && bar_remain.Text != "")
  178. {
  179. bar_remain.Text = double.Parse(barremain.ToString()).ToString();
  180. //插入数据至devSMTLocation
  181. sql.Clear();
  182. sql.Append("insert into DEVSMTLocation(dsl_id,dsl_maid,dsl_makecode, dsl_mmdetno,dsl_location,dsl_prodcode,dsl_repcode,dsl_fespec,");
  183. sql.Append("dsl_getqty,dsl_remainqty,dsl_barcode,dsl_linecode,dsl_devcode,dsl_status,dsl_validtime,dsl_indate,dsl_smtid)");
  184. sql.Append(" select devSMTLocation_SEQ.nextval,ma_id,ma_code,'','" + psl_location.Text + "','" + bar_prodcode + "',");
  185. sql.Append("'" + psl_repcode + "',psl_feeder,'" + bar_remain.Text + "','" + bar_remain.Text + "',");
  186. sql.Append("'" + barcode + "',ma_linecode,'" + de_code.Text + "',0,sysdate,sysdate,ps_id from make left join productsmt on ma_smtcode=ps_code ");
  187. sql.Append("left join productsmtlocation on ps_id=psl_psid where ma_code='" + ma_code.Text + "' and psl_location='" + psl_location.Text + "' and rownum<=1");
  188. dh.ExecuteSql(sql.GetString(), "insert");
  189. //如果几台绑定的工单号未空的情况下更新成当前采集料的
  190. if (dh.getFieldDataByCondition("device", "de_macode", "de_code='" + de_code.Text + "'").ToString() == "")
  191. {
  192. dh.ExecuteSql("update device set de_macode='" + ma_code.Text + "' where de_code='" + de_code.Text + "'", "update");
  193. }
  194. //更新条码(barcode)状态在线上 bar_Place=工单号
  195. dh.ExecuteSql("update barcode set bar_Place='" + ma_code.Text + "' where bar_code='" + Input.Text + "' and bar_status=1", "update");
  196. OperateResult.AppendText(">>料卷采集成功,数量" + barremain + "\n", Color.Green);
  197. LoadGridData();
  198. CleanInf();
  199. }
  200. break;
  201. //下料
  202. case "DOWNLOAD":
  203. sql.Clear();
  204. sql.Append("select dsl_location,dsl_barcode,dsl_remainqty,dsl_prodcode from devSMTLocation left join make on ma_code=dsl_makecode and ma_linecode=dsl_linecode ");
  205. sql.Append("where dsl_makecode='" + ma_code.Text + "' and dsl_devcode='" + de_code.Text + "' and (dsl_barcode='" + Input.Text + "' or ");
  206. sql.Append("dsl_location='" + Input.Text + "') and nvl(dsl_status,0)=0");
  207. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  208. if (dt.Rows.Count > 0)
  209. {
  210. string dsl_location = dt.Rows[0]["dsl_location"].ToString();
  211. string dsl_barcode = dt.Rows[0]["dsl_barcode"].ToString();
  212. string dsl_remainqty = dt.Rows[0]["dsl_remainqty"].ToString();
  213. string dsl_prodcode = dt.Rows[0]["dsl_prodcode"].ToString();
  214. dh.UpdateByCondition("DEVSMTLocation", "dsl_status=-1,dsl_invalidtime=sysdate", "dsl_location='" + dsl_location + "'");
  215. dh.UpdateByCondition("barcode", "bar_place=1,bar_forcastremain =" + dsl_remainqty, "bar_code='" + dsl_barcode + "'");
  216. OperateResult.AppendText(">>退料成功\n", Color.Green);
  217. //下料后判断当前的设备时候还有料存在
  218. sql.Clear();
  219. sql.Append("select dsl_makecode from device left join devSMTLocation ");
  220. sql.Append("on de_code=dsl_devcode where de_code='" + de_code.Text + "' and dsl_status=0 and dsl_makecode<>'" + ma_code.Text + "'");
  221. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  222. if (dt.Rows.Count == 0)
  223. {
  224. dh.ExecuteSql("update device set de_macode='' where de_code='" + de_code.Text + "'", "update");
  225. }
  226. LoadGridData();
  227. }
  228. else {
  229. OperateResult.AppendText(">>料卷号或者站位错误,无需退料\n", Color.Red);
  230. }
  231. break;
  232. //接料
  233. case "PICKUP":
  234. //查询站位是否存在
  235. if (psl_location.Text == "")
  236. {
  237. sql.Clear();
  238. sql.Append("select psl_prodcode,psl_repcode from productsmtlocation left join productsmt on ps_id=psl_psid left join make on ");
  239. sql.Append("ma_smtcode=ps_code where ma_code='" + ma_code.Text + "' and psl_location='" + Input.Text + "' ");
  240. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  241. if (dt.Rows.Count > 0)
  242. {
  243. psl_location.Text = Input.Text;
  244. Input.Text = "";
  245. //获取物料号和替代料
  246. psl_prodcode = dt.Rows[0]["psl_prodcode"].ToString();
  247. psl_repcode = dt.Rows[0]["psl_repcode"].ToString();
  248. OperateResult.AppendText(">>站位采集成功,请采集物料" + psl_prodcode + " 的料卷号\n", Color.Green);
  249. }
  250. else {
  251. OperateResult.AppendText(">>站位错误,不存在上料排位表中\n", Color.Red);
  252. }
  253. }
  254. else if (bar_code.Text == "")
  255. {
  256. dt = (DataTable)dh.ExecuteSql("select bar_remain,bar_forcastremain from barcode where bar_code='" + Input.Text + "' and bar_status=1", "select");
  257. barremain = double.Parse(dt.Rows[0]["bar_remain"].ToString());
  258. forcastremain = dt.Rows[0]["bar_remain"].ToString();
  259. if (dt.Rows.Count > 0)
  260. {
  261. //如果剩余的数量不为0的话
  262. if (dt.Rows[0]["bar_remain"].ToString() != "0")
  263. {
  264. sql.Clear();
  265. sql.Append("select * from devSMTLocation left join make on ma_code=dsl_makecode and ma_linecode=dsl_linecode where dsl_makecode='" + ma_code.Text + "'");
  266. sql.Append(" and dsl_devcode='" + de_code.Text + "' and dsl_location='" + psl_location.Text + "' and dsl_status=0");
  267. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  268. if (dt.Rows.Count > 0)
  269. {
  270. //上一条码的剩余数量
  271. int dsl_remainqty = int.Parse(dt.Rows[0]["dsl_remainqty"].ToString());
  272. string dsl_barcode = dt.Rows[0]["dsl_barcode"].ToString();
  273. string dsl_id = dt.Rows[0]["dsl_id"].ToString();
  274. dt = (DataTable)dh.ExecuteSql("select nvl(bar_place,1) bar_place,bar_remain,bar_prodcode from barcode where bar_code='" + Input.Text + "'", "select");
  275. if (dt.Rows.Count > 0)
  276. {
  277. if (dt.Rows[0]["bar_place"].ToString() == "1")
  278. {
  279. string bar_prodcode = dt.Rows[0]["bar_prodcode"].ToString();
  280. //本次切换的料卷剩余的
  281. barremain = int.Parse(dt.Rows[0]["bar_remain"].ToString());
  282. if (psl_prodcode == bar_prodcode || psl_repcode == bar_prodcode)
  283. {
  284. if (forcastremain != "0" && forcastremain != "" && forcastremain != barremain.ToString())
  285. {
  286. bar_code.Text = Input.Text;
  287. bar_remain.Text = forcastremain;
  288. }
  289. else {
  290. bar_remain.Text = barremain.ToString();
  291. //插入数据至devSMTLocation
  292. sql.Clear();
  293. sql.Append("insert into devSMTLocation(dsl_id,dsl_maid,dsl_makecode, dsl_mmdetno,dsl_location,dsl_prodcode,dsl_repcode,dsl_fespec,");
  294. sql.Append("dsl_getqty,dsl_remainqty,dsl_barcode,dsl_linecode,dsl_devcode,dsl_status,dsl_smtid,dsl_indate) select devSMTLocation_SEQ.nextval,");
  295. sql.Append("ma_id,ma_code,'','" + psl_location.Text + "','" + bar_prodcode + "',");
  296. sql.Append("'" + psl_repcode + "',psl_feeder,'" + bar_remain.Text + "','" + bar_remain.Text + "','" + Input.Text + "',");
  297. sql.Append("ma_linecode,'" + de_code.Text + "',0,ps_id,sysdate from make left join productsmt on ma_smtcode=ps_code ");
  298. sql.Append("left join productsmtlocation on ps_id=psl_psid where ma_code='" + ma_code.Text + "' ");
  299. sql.Append("and psl_location='" + psl_location.Text + "' and rownum<=1 ");
  300. dh.ExecuteSql(sql.GetString(), "insert");
  301. //更新站位原料卷号下线,bar_forcastremain 剩余数为0
  302. //dh.UpdateByCondition("barcode", "bar_place=1,bar_forcastremain=0", "bar_code='" + dsl_barcode + "'");
  303. //更新条码状态在线上 bar_Place=2
  304. dh.UpdateByCondition("barcode", "bar_place='" + ma_code.Text + "'", "bar_code='" + Input.Text + "'");
  305. LoadGridData();
  306. CleanInf();
  307. OperateResult.AppendText(">>采集成功\n", Color.Green);
  308. }
  309. Input.Text = "";
  310. }
  311. else {
  312. OperateResult.AppendText(">>采集的物料号" + Input.Text + "不匹配\n", Color.Red);
  313. Input.Text = "";
  314. }
  315. }
  316. else {
  317. OperateResult.AppendText(">>料卷" + Input.Text + "已经上料或者备料\n", Color.Red);
  318. Input.Text = "";
  319. }
  320. }
  321. else {
  322. OperateResult.AppendText(">>料卷编号" + Input.Text + "错误,不存在或者状态无效\n", Color.Red);
  323. Input.Text = "";
  324. }
  325. }
  326. else {
  327. OperateResult.AppendText(">>站位" + Input.Text + "错误,无此机台工单站位\n", Color.Red);
  328. Input.Text = "";
  329. }
  330. }
  331. else {
  332. OperateResult.AppendText(">>料卷编号" + Input.Text + "错误,库存数量为0\n", Color.Red);
  333. Input.Text = "";
  334. }
  335. }
  336. else {
  337. OperateResult.AppendText(">>料卷编号" + Input.Text + "错误,不存在或者状态无效\n", Color.Red);
  338. Input.Text = "";
  339. }
  340. }
  341. else if (bar_code.Text != "" && psl_location.Text != "" && bar_remain.Text != "")
  342. {
  343. bar_remain.Text = barremain.ToString();
  344. //插入数据至devSMTLocation
  345. sql.Clear();
  346. sql.Append("insert into devSMTLocation(dsl_id,dsl_maid,dsl_makecode, dsl_mmdetno,dsl_location,dsl_prodcode,dsl_repcode,dsl_fespec,");
  347. sql.Append("dsl_getqty,dsl_remainqty,dsl_barcode,dsl_linecode,dsl_devcode,dsl_status,dsl_smtid,dsl_indate) select devSMTLocation_SEQ.nextval,");
  348. sql.Append("ma_id,ma_code,'','" + psl_location.Text + "','" + bar_prodcode + "',");
  349. sql.Append("'" + psl_repcode + "',psl_feeder,'" + bar_remain.Text + "','" + bar_remain.Text + "','" + Input.Text + "',");
  350. sql.Append("ma_linecode,'" + de_code.Text + "',0,ps_id,sysdate from make left join productsmt on ma_smtcode=ps_code ");
  351. sql.Append("left join productsmtlocation on ps_id=psl_psid where ma_code='" + ma_code.Text + "' ");
  352. sql.Append("and psl_location='" + psl_location.Text + "' and rownum<=1 ");
  353. dh.ExecuteSql(sql.GetString(), "insert");
  354. //更新站位原料卷号下线,bar_forcastremain 剩余数为0
  355. //dh.UpdateByCondition("barcode", "bar_place=1,bar_forcastremain=0", "bar_code='" + dsl_barcode + "'");
  356. //更新条码状态在线上 bar_Place=2
  357. dh.UpdateByCondition("barcode", "bar_place='" + ma_code.Text + "'", "bar_code='" + Input.Text + "'");
  358. LoadGridData();
  359. CleanInf();
  360. OperateResult.AppendText(">>采集成功\n", Color.Green);
  361. }
  362. break;
  363. //换料
  364. case "SHIFT":
  365. if (psl_location.Text == "")
  366. {
  367. sql.Clear();
  368. sql.Append("select psl_prodcode,psl_repcode from productsmtlocation left join productsmt on ps_id=psl_psid left join make on ");
  369. sql.Append("ma_smtcode=ps_code where ma_code='" + ma_code.Text + "' and psl_location='" + Input.Text + "'");
  370. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  371. if (dt.Rows.Count > 0)
  372. {
  373. psl_location.Text = Input.Text;
  374. Input.Text = "";
  375. //获取物料号和替代料
  376. psl_prodcode = dt.Rows[0]["psl_prodcode"].ToString();
  377. psl_repcode = dt.Rows[0]["psl_repcode"].ToString();
  378. OperateResult.AppendText(">>站位采集成功,请采集物料" + psl_prodcode + " 的料卷号\n", Color.Green);
  379. }
  380. else {
  381. OperateResult.AppendText(">>站位错误,不存在上料排位表中\n", Color.Red);
  382. }
  383. }
  384. else if (bar_code.Text == "")
  385. {
  386. dt = (DataTable)dh.ExecuteSql("select bar_remain,bar_forcastremain from barcode where bar_code='" + Input.Text + "' and bar_status=1", "select");
  387. if (dt.Rows.Count > 0)
  388. {
  389. //如果剩余的数量不为0的话
  390. if (dt.Rows[0]["bar_remain"].ToString() != "0")
  391. {
  392. bar_remain.Text = dt.Rows[0]["bar_remain"].ToString();
  393. forcastremain = dt.Rows[0]["bar_forcastremain"].ToString();
  394. sql.Clear();
  395. sql.Append("select * from devSMTLocation left join make on ma_code=dsl_makecode and ma_linecode=dsl_linecode ");
  396. sql.Append("where dsl_makecode='" + ma_code.Text + "' and dsl_devcode='" + de_code.Text + "' and dsl_location='" + psl_location.Text + "'");
  397. sql.Append("and dsl_status=0 ");
  398. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  399. if (dt.Rows.Count > 0)
  400. {
  401. //上一条码的剩余数量
  402. dsl_remainqty = int.Parse(dt.Rows[0]["dsl_remainqty"].ToString());
  403. dsl_barcode = dt.Rows[0]["dsl_barcode"].ToString();
  404. dsl_id = dt.Rows[0]["dsl_id"].ToString();
  405. dt = (DataTable)dh.ExecuteSql("select nvl(bar_place,1) bar_place,bar_remain,bar_prodcode from barcode where bar_code='" + Input.Text + "'", "select");
  406. if (dt.Rows.Count > 0)
  407. {
  408. if (dt.Rows[0]["bar_place"].ToString() == "1")
  409. {
  410. string bar_prodcode = dt.Rows[0]["bar_prodcode"].ToString();
  411. //本次切换的料卷剩余的
  412. barremain = int.Parse(dt.Rows[0]["bar_remain"].ToString());
  413. if (psl_prodcode == bar_prodcode || psl_repcode == bar_prodcode)
  414. {
  415. if (forcastremain != "0" && forcastremain != "" && forcastremain != barremain.ToString())
  416. {
  417. bar_code.Text = Input.Text;
  418. bar_remain.Text = forcastremain;
  419. }
  420. else {
  421. //更新原料卷站位状态下料dsl_status=-1
  422. dh.ExecuteSql("Update devSMTLocation set dsl_status=-1 where dsl_id=" + dsl_id, "update");
  423. //更新站位原料卷号下线,bar_forcastremain 剩余数 dsl_remain
  424. dh.UpdateByCondition("barcode", "bar_forcastremain=" + dsl_remainqty + ",bar_place=1", "bar_code='" + dsl_barcode + "'");
  425. //将新条码数据插入至devSMTLocation
  426. sql.Clear();
  427. sql.Append("insert into devSMTLocation(dsl_id,dsl_maid,dsl_makecode, dsl_mmdetno,dsl_location,dsl_prodcode,dsl_repcode,dsl_fespec,dsl_indate,");
  428. sql.Append("dsl_getqty,dsl_remainqty,dsl_barcode,dsl_linecode,dsl_devcode,dsl_status,dsl_validtime,dsl_indate,dsl_smtid)");
  429. sql.Append(" select devSMTLocation_SEQ.nextval,ma_id,ma_code,'','" + psl_location.Text + "','" + bar_prodcode + "',");
  430. sql.Append("'" + psl_repcode + "',psl_feeder,sysdate,'" + bar_remain.Text + "','" + bar_remain.Text + "',");
  431. sql.Append("'" + Input.Text + "',ma_linecode,'" + de_code.Text + "',0,sysdate,sysdate,ps_id from make left join productsmt ");
  432. sql.Append("on ma_smtcode=ps_code left join productsmtlocation on ps_id=psl_psid where ma_code='" + ma_code.Text + "' and ");
  433. sql.Append("psl_location='" + psl_location.Text + "' and rownum<=1");
  434. dh.ExecuteSql(sql.GetString(), "insert");
  435. //更新新条码状态在线上 bar_Place=2
  436. dh.UpdateByCondition("barcode", "bar_Place='" + ma_code.Text + "'", "bar_code='" + Input.Text + "'");
  437. //更新原条码上料记录
  438. LoadGridData();
  439. CleanInf();
  440. OperateResult.AppendText(">>换料成功\n", Color.Green);
  441. }
  442. }
  443. else {
  444. OperateResult.AppendText(">>采集的物料号" + Input.Text + "不匹配\n", Color.Red);
  445. }
  446. }
  447. else {
  448. OperateResult.AppendText(">>料卷" + Input.Text + "已经上料或者备料\n", Color.Red);
  449. }
  450. }
  451. else {
  452. OperateResult.AppendText(">>料卷编号" + Input.Text + "错误,不存在或者状态无效\n", Color.Red);
  453. }
  454. }
  455. else {
  456. OperateResult.AppendText(">>站位" + Input.Text + "错误,无此机台工单站位\n", Color.Red);
  457. }
  458. }
  459. else {
  460. OperateResult.AppendText(">>料卷编号" + Input.Text + "错误,库存数量为0\n", Color.Red);
  461. }
  462. }
  463. else {
  464. OperateResult.AppendText(">>料卷编号" + Input.Text + "错误,不存在或者状态无效\n", Color.Red);
  465. }
  466. }
  467. else if (bar_code.Text != "" && psl_location.Text != "" && bar_remain.Text != "")
  468. {
  469. //更新原料卷站位状态下料dsl_status=-1
  470. dh.ExecuteSql("Update devSMTLocation set dsl_status=-1 where dsl_id=" + dsl_id, "update");
  471. //更新站位原料卷号下线,bar_forcastremain 剩余数 dsl_remain
  472. dh.UpdateByCondition("barcode", "bar_forcastremain=" + dsl_remainqty + ",bar_place=1", "bar_code='" + dsl_barcode + "'");
  473. //将新条码数据插入至devSMTLocation
  474. sql.Clear();
  475. sql.Append("insert into devSMTLocation(dsl_id,dsl_maid,dsl_makecode, dsl_mmdetno,dsl_location,dsl_prodcode,dsl_repcode,dsl_fespec,");
  476. sql.Append("dsl_getqty,dsl_remainqty,dsl_barcode,dsl_linecode,dsl_devcode,dsl_status,dsl_validtime,dsl_indate,dsl_smtid)");
  477. sql.Append(" select devSMTLocation_SEQ.nextval,ma_id,ma_code,'','" + psl_location.Text + "','" + bar_prodcode + "',");
  478. sql.Append("'" + psl_repcode + "',psl_feeder,'" + bar_remain.Text + "','" + bar_remain.Text + "',");
  479. sql.Append("'" + Input.Text + "',ma_linecode,'" + de_code.Text + "',0,sysdate,sysdate,ps_id from make left join productsmt ");
  480. sql.Append("on ma_smtcode=ps_code left join productsmtlocation on ps_id=psl_psid where ma_code='" + ma_code.Text + "' and ");
  481. sql.Append("psl_location='" + psl_location.Text + "' and rownum<=1");
  482. dh.ExecuteSql(sql.GetString(), "insert");
  483. //更新新条码状态在线上 bar_Place=2
  484. dh.UpdateByCondition("barcode", "bar_Place='" + ma_code.Text + "'", "bar_code='" + Input.Text + "'");
  485. //更新原条码上料记录
  486. LoadGridData();
  487. CleanInf();
  488. OperateResult.AppendText(">>换料成功\n", Color.Green);
  489. }
  490. break;
  491. }
  492. Input.Text = "";
  493. }
  494. else {
  495. MessageBox.Show(UAS_MES_NEW.I18n.LanguageManager.T("必须执行过筛选操作"));
  496. }
  497. }
  498. }
  499. private void SMT上料_SizeChanged(object sender, EventArgs e)
  500. {
  501. asc.controlAutoSize(this);
  502. }
  503. /// <summary>
  504. /// 筛选按钮
  505. /// </summary>
  506. /// <param name="sender"></param>
  507. /// <param name="e"></param>
  508. private void Screen_Click(object sender, EventArgs e)
  509. {
  510. CleanInf();
  511. if (ma_code.Text != "" && de_code.Text != "")
  512. {
  513. sql.Clear();
  514. sql.Append("select dsl_makecode from device left join devsmtlocation ");
  515. sql.Append("on de_code=dsl_devcode where de_code='" + de_code.Text + "' and dsl_status=0 and dsl_makecode<>'" + ma_code.Text + "'");
  516. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  517. LogManager.DoLog("【" + Text + "】筛选操作", sql.GetString());
  518. //判断机台是否存在工单
  519. if (dt.Rows.Count > 0)
  520. {
  521. OperateResult.AppendText(">>机台号:" + de_code.Text + " ,存在工单:" + dt.Rows[0]["dsl_makecode"].ToString() + "的料卷未下料,请先下料!\n", Color.Red);
  522. return;
  523. }
  524. sql.Clear();
  525. sql.Append("select dsl_devcode from devsmtlocation where dsl_devcode<>'" + de_code.Text + "' and dsl_status=0 and dsl_makecode='" + ma_code.Text + "'");
  526. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  527. //判断工单是否已经在机台上线
  528. if (dt.Rows.Count > 0)
  529. {
  530. OperateResult.AppendText(">>工单号:" + ma_code.Text + " ,已上机台号:" + de_code.Text + "需要转线才能重新上其他机台!\n", Color.Red);
  531. return;
  532. }
  533. //判断岗位资源的线别和制造单的线别是否相等
  534. dt = (DataTable)dh.ExecuteSql("select ma_smtcode,ma_linecode from make where ma_code='" + ma_code.Text + "'", "select");
  535. ma_smtcode = dt.Rows[0]["ma_smtcode"].ToString();
  536. if (User.UserLineCode != dt.Rows[0]["ma_linecode"].ToString())
  537. {
  538. OperateResult.AppendText(">>岗位资源的线别必须等于制造单的线别\n", Color.Red);
  539. return;
  540. }
  541. LoadGridData();
  542. Filtered = true;
  543. Filter.Text = "已筛选";
  544. MakeShift.Visible = true;
  545. if (Filtered)
  546. {
  547. for (int i = 0; i < RadioButton.Length; i++)
  548. {
  549. switch (RadioButton[i].Name.ToUpper())
  550. {
  551. //上料
  552. case "UPLOAD":
  553. if (RadioButton[i].Checked)
  554. {
  555. CheckedRadio = RadioButton[i];
  556. OperateResult.AppendText(">>请采集站位\n", Color.Green);
  557. }
  558. if (!BaseUtil.ControlHasEvent(RadioButton[i], "EVENT_CHECKEDCHANGED"))
  559. {
  560. RadioButton[i].CheckedChanged += RadioCheckedChange;
  561. }
  562. break;
  563. //下料
  564. case "DOWNLOAD":
  565. if (RadioButton[i].Checked)
  566. {
  567. CheckedRadio = RadioButton[i];
  568. OperateResult.AppendText(">>请采集需要退料的料卷号或者站位\n", Color.Green);
  569. }
  570. if (!BaseUtil.ControlHasEvent(RadioButton[i], "EVENT_CHECKEDCHANGED"))
  571. {
  572. RadioButton[i].CheckedChanged += RadioCheckedChange;
  573. }
  574. break;
  575. //换料
  576. case "SHIFT":
  577. if (RadioButton[i].Checked)
  578. {
  579. CheckedRadio = RadioButton[i];
  580. OperateResult.AppendText(">>请采集需要换料的站位\n", Color.Green);
  581. }
  582. if (!BaseUtil.ControlHasEvent(RadioButton[i], "EVENT_CHECKEDCHANGED"))
  583. {
  584. RadioButton[i].CheckedChanged += RadioCheckedChange;
  585. }
  586. break;
  587. //接料
  588. case "PICKUP":
  589. if (RadioButton[i].Checked)
  590. {
  591. CheckedRadio = RadioButton[i];
  592. OperateResult.AppendText(">>请采集需要接料的站位\n", Color.Green);
  593. }
  594. if (!BaseUtil.ControlHasEvent(RadioButton[i], "EVENT_CHECKEDCHANGED"))
  595. {
  596. RadioButton[i].CheckedChanged += RadioCheckedChange;
  597. }
  598. break;
  599. }
  600. }
  601. }
  602. }
  603. else {
  604. MessageBox.Show(UAS_MES_NEW.I18n.LanguageManager.T("工单号和机台号不允许为空"));
  605. }
  606. }
  607. private void RadioCheckedChange(object sender, EventArgs e)
  608. {
  609. if ((sender as RadioButton).Checked)
  610. {
  611. CleanInf();
  612. switch ((sender as RadioButton).Name.ToUpper())
  613. { //上料
  614. case "UPLOAD":
  615. OperateResult.AppendText(">>请采集站位\n", Color.Green);
  616. CheckedRadio = sender as RadioButton;
  617. break;
  618. //下料
  619. case "DOWNLOAD":
  620. OperateResult.AppendText(">>请采集需要退料的料卷号或者站位\n", Color.Green);
  621. CheckedRadio = sender as RadioButton;
  622. break;
  623. //换料
  624. case "SHIFT":
  625. OperateResult.AppendText(">>请采集需要换料的站位\n", Color.Green);
  626. CheckedRadio = sender as RadioButton;
  627. break;
  628. //接料
  629. case "PICKUP":
  630. OperateResult.AppendText(">>请采集需要接料的站位\n", Color.Green);
  631. CheckedRadio = sender as RadioButton;
  632. break;
  633. default:
  634. break;
  635. }
  636. }
  637. }
  638. /// <summary>
  639. /// 根据四个不同的RadioButton的勾选状态不同执行不同的逻辑
  640. /// </summary>
  641. /// <param name="sender"></param>
  642. /// <param name="e"></param>
  643. private void Confirm_Click(object sender, EventArgs e)
  644. {
  645. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  646. Input_KeyDown(sender, e2);
  647. }
  648. private void Start_Click(object sender, EventArgs e)
  649. {
  650. if (Filtered)
  651. {
  652. if (de_code.Text != "")
  653. {
  654. if (de_table.Text != "全部")
  655. {
  656. sql.Clear();
  657. sql.Append("select ps_id from productsmt left join productsmtlocation on ps_id=psl_psid where ps_code='" + ma_smtcode + "' and psl_table='" + de_table.Text + "'");
  658. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  659. if (dt.Rows.Count > 0)
  660. {
  661. string psl_psid = dt.Rows[0]["ps_id"].ToString();
  662. //1、刚开始启动的时候更新版面,单位用量
  663. sql.Clear();
  664. sql.Append("update devsmtlocation set dsl_baseqty=(select psl_baseqty from productsmtlocation where psl_psid='" + psl_psid + "' and psl_table='" + de_table.Text + "' ");
  665. sql.Append("and psl_location=dsl_location) where dsl_makecode='" + ma_code.Text + "' and dsl_linecode='" + User.UserLineCode + "' and dsl_devcode='" + de_code.Text + "' and dsl_status=0 ");
  666. dh.ExecuteSql(sql.GetString(), "update");
  667. //2、判断站位是否上齐料
  668. sql.Clear();
  669. sql.Append("SELECT wm_concat(psl_location) FROM Productsmtlocation where psl_psid='" + psl_psid + "' and psl_table='" + de_table.Text + "' ");
  670. sql.Append("and not exists (select 1 from devsmtlocation where dsl_makecode='" + ma_code.Text + "' and dsl_linecode='" + User.UserLineCode + "'");
  671. sql.Append("and dsl_devcode='" + de_code.Text + "' and dsl_devcode='" + de_code.Text + "' and dsl_status=0 and dsl_location=psl_location) and rownum<=20");
  672. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  673. if (dt.Rows[0][0].ToString() == "")
  674. {
  675. LogManager.DoLog("【" + Text + "】启用机台操作", dh.UpdateByCondition("device", "de_runstatus = '运行中',de_table='" + de_table.Text + "'", "de_code = '" + de_code.Text + "' and de_runstatus = '停止'"));
  676. de_code.RefreshDB(sender, e);
  677. MessageBox.Show(UAS_MES_NEW.I18n.LanguageManager.T("启用机台成功"));
  678. }
  679. else {
  680. MessageBox.Show(UAS_MES_NEW.I18n.LanguageManager.T("站位") + dt.Rows[0][0].ToString() + UAS_MES_NEW.I18n.LanguageManager.T("未上料"));
  681. }
  682. }
  683. else {
  684. MessageBox.Show(UAS_MES_NEW.I18n.LanguageManager.T("该版面不存在于排位表中"));
  685. }
  686. }
  687. else {
  688. MessageBox.Show(UAS_MES_NEW.I18n.LanguageManager.T("必须选择一个版面"));
  689. }
  690. }
  691. else {
  692. MessageBox.Show(UAS_MES_NEW.I18n.LanguageManager.T("机台号不能为空!"));
  693. }
  694. }
  695. else {
  696. MessageBox.Show(UAS_MES_NEW.I18n.LanguageManager.T("必须执行过筛选操作"));
  697. }
  698. }
  699. private void DownLoadAll_Click(object sender, EventArgs e)
  700. {
  701. if (Filtered)
  702. {
  703. sql.Clear();
  704. sql.Append("select count(1) from devSmtLocation where dsl_makecode='" + ma_code.Text + "' and dsl_devcode='" + de_code.Text + "'");
  705. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  706. LogManager.DoLog("【" + Text + "】全部下料操作", sql.GetString());
  707. if (dt.Rows[0][0].ToString() != "0")
  708. {
  709. //更新在线料卷所在场所,剩余数
  710. sql.Clear();
  711. sql.Append("update barcode set bar_place='1',bar_forcastremain=(select dsl_remainqty from ");
  712. sql.Append("devsmtlocation where dsl_barcode=bar_code and dsl_makecode='" + ma_code.Text + "' and dsl_devcode='" + de_code.Text + "' and ");
  713. sql.Append("nvl(dsl_status,0)=0) where exists (select 1 from devsmtlocation where ");
  714. sql.Append("dsl_barcode=bar_code and dsl_makecode='" + ma_code.Text + "' and dsl_devcode='" + de_code.Text + "' and dsl_status=0)");
  715. dh.ExecuteSql(sql.GetString(), "update");
  716. //将信息插入MakeSMTLocation表中
  717. sql.Clear();
  718. sql.Append("insert into makeSMTLocation(msl_id,msl_maid,msl_makecode, msl_mmdetno,msl_location,msl_prodcode,msl_repcode,msl_fespec,msl_invalidtime,");
  719. sql.Append("msl_baseqty,msl_table,msl_needqty,msl_getqty,msl_remainqty,msl_barcode,msl_linecode,msl_devcode,msl_status,msl_validtime,msl_indate)");
  720. sql.Append("select makeSMTLocation_SEQ.nextval,dsl_maid,dsl_makecode,dsl_mmdetno,dsl_location,dsl_prodcode,dsl_repcode,dsl_fespec,sysdate,");
  721. sql.Append("dsl_baseqty,dsl_table,dsl_needqty,dsl_getqty,dsl_remainqty,dsl_barcode,dsl_linecode,dsl_devcode,-1,dsl_validtime,dsl_indate ");
  722. sql.Append("from devsmtlocation where dsl_makecode='" + ma_code.Text + "' and dsl_devcode='" + de_code.Text + "'");
  723. dh.ExecuteSql(sql.GetString(), "insert");
  724. //从DevSMTLocation中移除
  725. dh.ExecuteSql("delete from devsmtlocation where dsl_makecode='" + ma_code.Text + "' and dsl_devcode='" + de_code.Text + "'", "delete");
  726. LogManager.DoLog("【" + Text + "】全部下料操作", sql.GetString());
  727. //更新上料排位表状态为-1
  728. LogManager.DoLog("【" + Text + "】全部下料操作", sql.GetString());
  729. OperateResult.AppendText(">>" + Input.Text + "退料成功\n", Color.Green);
  730. dh.ExecuteSql("update device set de_macode='',de_table='' where de_code='" + de_code.Text + "'", "update");
  731. ma_code.Enabled = true;
  732. de_table.Enabled = true;
  733. LoadGridData();
  734. }
  735. else {
  736. OperateResult.AppendText(">>没有需要下料的料卷\n", Color.Red);
  737. LogManager.DoLog("【" + Text + "】没有需要下料的料卷");
  738. }
  739. }
  740. else {
  741. MessageBox.Show(UAS_MES_NEW.I18n.LanguageManager.T("必须执行过筛选操作"));
  742. }
  743. }
  744. /// <summary>
  745. /// 工单切换
  746. /// </summary>
  747. /// <param name="sender"></param>
  748. /// <param name="e"></param>
  749. private void MakeShift_Click(object sender, EventArgs e)
  750. {
  751. MShift = new SMT_MakeShift();
  752. //给小窗口的确认按钮加一个事件
  753. MShift.Controls["Confirm"].Click += MakeShiftButtonClick;
  754. BaseUtil.SetFormCenter(MShift);
  755. MShift.ShowDialog();
  756. }
  757. private void MakeShiftButtonClick(object sender, EventArgs e)
  758. {
  759. //从工单切换窗口取得字符串
  760. string macode = MShift.Controls["ma_code"].Text;
  761. string maprodcode = MShift.Controls["ma_prodcode"].Text;
  762. string maid = MShift.Controls["ma_id"].Text;
  763. string maqty = MShift.Controls["ma_qty"].Text;
  764. string maline = MShift.Controls["ma_linecode"].Text;
  765. string masmtcode = MShift.Controls["ma_smtcode"].Text;
  766. sql.Clear();
  767. sql.Append("select dsl_smtid from devsmtlocation where dsl_devcode='" + de_code.Text + "' and ");
  768. sql.Append("NVL(dsl_status,0)=0 and dsl_makecode='" + ma_code.Text + "' and dsl_remainqty>0");
  769. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  770. if (dt.Rows.Count > 0)
  771. {
  772. //判断工单站位是否一致
  773. //原工单
  774. string dsl_smtid = dt.Rows[0]["dsl_smtid"].ToString();
  775. //新工单
  776. string psl_id1 = dh.getFieldDataByCondition("productsmt left join productsmtlocation on ps_id=psl_psid", "psl_psid", "ps_code='" + masmtcode + "'").ToString();
  777. sql.Clear();
  778. sql.Append("select psl_location from productsmtlocation where psl_psid=:dsl_smtid minus select psl_location from productsmtlocation where psl_psid=:psl_id1");
  779. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select", dsl_smtid, psl_id1);
  780. if (dt.Rows.Count > 0)
  781. {
  782. OperateResult.AppendText(">>切换站位工单不一致\n", Color.Red);
  783. return;
  784. }
  785. sql.Clear();
  786. sql.Append("select psl_location from productsmtlocation where psl_psid=:dsl_smtid minus select psl_location from productsmtlocation where psl_psid=:psl_id1");
  787. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select", psl_id1, dsl_smtid);
  788. if (dt.Rows.Count > 0)
  789. {
  790. OperateResult.AppendText(">>切换站位工单不一致\n", Color.Red);
  791. return;
  792. }
  793. sql.Clear();
  794. sql.Append("select a.psl_location,wm_concat(a.psl_prodcode||','||a.psl_repcode) a_prodcode,wm_concat(','||b.psl_prodcode||','");
  795. sql.Append("||b.psl_repcode) b_prodcode from productsmtlocation a left join productsmtlocation b on a.psl_location");
  796. sql.Append("=b.psl_location where a.psl_psid=:dsl_smtid and b.psl_psid=:psl_id1 group by a.psl_location");
  797. bool Break = false;
  798. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select", dsl_smtid, psl_id1);
  799. for (int i = 0; i < dt.Rows.Count; i++)
  800. {
  801. string[] a_prodcode = dt.Rows[i]["a_prodcode"].ToString().Split(',');
  802. for (int j = 0; j < a_prodcode.Length; j++)
  803. {
  804. if (dt.Rows[i]["b_prodcode"].ToString().Contains("," + a_prodcode[i] + ","))
  805. {
  806. Break = true;
  807. break;
  808. }
  809. }
  810. if (Break)
  811. {
  812. break;
  813. }
  814. }
  815. if (!Break)
  816. {
  817. OperateResult.AppendText(">>工单物料不匹配\n", Color.Red);
  818. return;
  819. }
  820. sql.Clear();
  821. sql.Append("select count(1) cn from devsmtlocation where dsl_makecode='" + macode + "' and NVL(dsl_status,0)=0");
  822. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  823. if (dt.Rows[0][0].ToString() == "0")
  824. {
  825. if (User.UserLineCode == maline)
  826. {
  827. //该机台原工单中在线剩余数为0的料卷更新所在场所为下线
  828. sql.Clear();
  829. sql.Append("update barcode set bar_place=1,bar_forcastremain=0 where exists (select 1 from devsmtlocation ");
  830. sql.Append("where dsl_barcode=bar_code and dsl_makecode='" + ma_code.Text + "' and dsl_status=0 and nvl(dsl_remainqty,0)=0)");
  831. dh.ExecuteSql(sql.GetString(), "update");
  832. //将数据插入MakeSmtLoaction表中
  833. sql.Clear();
  834. sql.Append("insert into makeSMTLocation(msl_id,msl_maid,msl_makecode, msl_mmdetno,msl_location,msl_prodcode,msl_repcode,msl_fespec,msl_invalidtime,");
  835. sql.Append("msl_baseqty,msl_table,msl_needqty,msl_getqty,msl_remainqty,msl_barcode,msl_linecode,msl_devcode,msl_status,msl_validtime,msl_indate)");
  836. sql.Append("select makeSMTLocation_SEQ.nextval,dsl_maid,dsl_makecode,dsl_mmdetno,dsl_location,dsl_prodcode,dsl_repcode,dsl_fespec,sysdate,");
  837. sql.Append("dsl_baseqty,dsl_table,dsl_needqty,dsl_getqty,dsl_remainqty,dsl_barcode,dsl_linecode,dsl_devcode,-1,dsl_validtime,dsl_indate ");
  838. sql.Append("from devsmtlocation where dsl_makecode='" + ma_code.Text + "' and dsl_devcode='" + de_code.Text + "'");
  839. dh.ExecuteSql(sql.GetString(), "insert");
  840. //从DevSMTLocation中移除
  841. dh.ExecuteSql("delete from devsmtlocation where dsl_makecode='" + ma_code.Text + "' and dsl_devcode='" + de_code.Text + "'", "delete");
  842. //更新机台绑定的工单为空
  843. dh.UpdateByCondition("device", "de_macode='" + macode + "'", "de_code='" + de_code.Text + "'");
  844. MShift.Close();
  845. //重新加载数据
  846. de_code.RefreshDB(sender, e);
  847. MessageBox.Show(UAS_MES_NEW.I18n.LanguageManager.T("切换成功"));
  848. }
  849. else {
  850. OperateResult.AppendText(">>切换的工单" + macode + "线别不一致\n", Color.Red);
  851. }
  852. }
  853. else {
  854. OperateResult.AppendText(">>切换的工单" + macode + "已在其他机台上料\n", Color.Red);
  855. }
  856. }
  857. else {
  858. OperateResult.AppendText(">>该机台工单无在线料卷无法切换\n", Color.Red);
  859. }
  860. }
  861. private void Pause_Click(object sender, EventArgs e)
  862. {
  863. if (de_code.Text != "")
  864. {
  865. dh.ExecuteSql("update device set de_runstatus='停止' where de_code='" + de_code.Text + "' and de_runstatus='运行中'", "update");
  866. LogManager.DoLog(Text + "暂停使用机台", "update device set de_runstatus='停止' where de_code='" + de_code.Text + "' and de_runstatus='运行中'");
  867. de_code.RefreshDB(sender, e);
  868. MessageBox.Show(UAS_MES_NEW.I18n.LanguageManager.T("停用机台成功"));
  869. }
  870. else {
  871. MessageBox.Show(UAS_MES_NEW.I18n.LanguageManager.T("机台号不能为空!"));
  872. }
  873. }
  874. private void Clean_Click(object sender, EventArgs e)
  875. {
  876. OperateResult.Clear();
  877. }
  878. private void LoadGridData()
  879. {
  880. sql.Clear();
  881. sql.Append("select v_location,v_table,v_prodcode,v_baseqty,v_baseqty*ma_qty v_needqty,v_feeder,v_barcode,v_remainqty,v_indate,v_nextbarcode, ");
  882. sql.Append("v_nextremainqty from make left join MES_SMTLOCATION_VIEW on MA_SMTCODE=V_SMTCODE where ma_code =:ma_code ");
  883. if (de_table.Text != "全部")
  884. {
  885. sql.Append(" and v_table =:v_table");
  886. }
  887. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select", ma_code.Text, de_table.Text);
  888. BaseUtil.FillDgvWithDataTable(SMTInf, dt);
  889. }
  890. //清除采集信息
  891. private void CleanInf()
  892. {
  893. psl_location.Text = "";
  894. bar_code.Text = "";
  895. Input.Text = "";
  896. bar_remain.Text = "";
  897. }
  898. private void Clearpsl_location_Click(object sender, EventArgs e)
  899. {
  900. psl_location.Text = "";
  901. OperateResult.AppendText(">>请采集站位\n", Color.Green);
  902. }
  903. //Text事件触发界面赋值的方法
  904. private void de_macode_UserControlTextChanged(object sender, EventArgs e)
  905. {
  906. ma_code.TextBox_Leave(sender, e);
  907. //如果通过Leavl事件找到了数据
  908. if (ma_code.LeaveFindData)
  909. {
  910. if (de_code.Text != "" && ma_code.Text != "")
  911. {
  912. Screen_Click(sender, new EventArgs());
  913. }
  914. }
  915. }
  916. //机台号的EnTer事件,触发筛选
  917. private void de_code_TextKeyDown(object sender, KeyEventArgs e)
  918. {
  919. if (e.KeyCode == Keys.Enter)
  920. {
  921. if (de_code.Text != "" && ma_code.Text != "")
  922. {
  923. Screen_Click(sender, new EventArgs());
  924. }
  925. }
  926. }
  927. private void AddDataToDataTable(params object[] param)
  928. {
  929. DataTable copydata = (DataTable)(SMTInf.DataSource);
  930. DataRow dr = copydata.NewRow();
  931. for (int i = 0; i < copydata.Columns.Count; i++)
  932. {
  933. switch (copydata.Columns[i].DataType.ToString())
  934. {
  935. case "System.String":
  936. dr[i] = param[i].ToString();
  937. break;
  938. case "System.Decimal":
  939. dr[i] = (decimal)param[i];
  940. break;
  941. case "System.DateTime":
  942. if (param[i] == null)
  943. {
  944. dr[i] = DBNull.Value;
  945. }
  946. else {
  947. dr[i] = (DateTime)param[i];
  948. }
  949. break;
  950. default:
  951. break;
  952. }
  953. }
  954. copydata.Rows.Add(dr);
  955. }
  956. private void Clearbar_code_Click(object sender, EventArgs e)
  957. {
  958. bar_code.Text = "";
  959. }
  960. private void de_code_UserControlTextChanged(object sender, EventArgs e)
  961. {
  962. de_code.TextBox_Leave(sender, e);
  963. //如果工单号不为空并且找到了数据
  964. if (ma_code.Text != "" && de_code.LeaveFindData)
  965. {
  966. ma_code.Enabled = false;
  967. }
  968. if (de_table.Text != "全部")
  969. {
  970. de_table.Enabled = false;
  971. }
  972. }
  973. }
  974. }