SMT_Feeding.cs 64 KB

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