SMT_Feeding.cs 65 KB

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