Make_FeedingCollection.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. using System;
  2. using System.Data;
  3. using System.Text;
  4. using System.Windows.Forms;
  5. using UAS_MES_NEW.CustomControl.TextBoxWithIcon;
  6. using UAS_MES_NEW.DataOperate;
  7. using UAS_MES_NEW.Entity;
  8. using UAS_MES_NEW.PublicMethod;
  9. using System.Drawing;
  10. using System.Text.RegularExpressions;
  11. using System.Collections.Generic;
  12. using System.Threading;
  13. using UAS_MES_NEW.PublicForm;
  14. namespace UAS_MES_NEW.Make
  15. {
  16. public partial class Make_FeedingCollection : Form
  17. {
  18. //MakeSerial表主键
  19. string ms_id;
  20. //制造单号
  21. string make_code;
  22. //产品编号
  23. string make_prodcode;
  24. //工序编号
  25. string nextstepcode;
  26. //完工状态
  27. string ms_status;
  28. //工艺路线编号
  29. //Bom版本
  30. string mabomversion;
  31. string ErrorMessage = "";
  32. List<string> TSN = new List<string>();
  33. Dictionary<string, string> CheckBarcode = new Dictionary<string, string>();
  34. //用于提醒的序列B
  35. string[] RemainList = new string[0];
  36. //提醒序列的索引
  37. int RemainIndex = 0;
  38. string oMakeCode = "";
  39. string oMsid = "";
  40. string ms_firstsn = "";
  41. DataHelper dh;
  42. LogStringBuilder sql = new LogStringBuilder();
  43. DataTable DBFind;
  44. DataTable dt;
  45. //保存ListB中的数据
  46. DataTable dt1;
  47. Thread InitPrint;
  48. BarTender.Application engine;
  49. AutoSizeFormClass asc = new AutoSizeFormClass();
  50. List<string> CollectData = new List<string>();
  51. List<string> CollectDataSonCode = new List<string>();
  52. List<string> SPID = new List<string>();
  53. string replacestring = "";
  54. public Make_FeedingCollection()
  55. {
  56. InitializeComponent();
  57. }
  58. private void Make_FeedingCollection_Load(object sender, EventArgs e)
  59. {
  60. asc.controllInitializeSize(this);
  61. LockMakeCode.GetMakeCodeCtl(ma_code);
  62. ma_code.SetLockCheckBox(LockMakeCode);
  63. //InitPrint = new Thread(InPrint);
  64. //SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
  65. //BaseUtil.SetFormCenter(stw);
  66. //stw.ShowDialog();
  67. //工单号放大镜配置
  68. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  69. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,ma_craftcode # 途程编号,pr_spec # 产品规格,ma_bomversion # Bom版本,ma_softversion # 软件版本";
  70. ma_code.FormName = Name;
  71. ma_code.DBTitle = "工单查询";
  72. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_orispeccode pr_spec", "ma_craftcode", "ma_bomversion", "ma_softversion" };
  73. ma_code.Condition = "ma_statuscode='STARTED'";
  74. ma_code.DbChange += Ma_code_DBChange;
  75. code.Focus();
  76. dh = SystemInf.dh;
  77. StepCount.StepCode = User.CurrentStepCode;
  78. StepCount.Source = User.UserSourceCode;
  79. StepCount.LineCode = User.UserLineCode;
  80. StepCount.Dh = dh;
  81. StepCount.Start();
  82. }
  83. private void InPrint()
  84. {
  85. try
  86. {
  87. engine = new BarTender.Application();
  88. //lbl = new ApplicationClass();
  89. //BaseUtil.WriteLbl();
  90. }
  91. catch (Exception ex)
  92. {
  93. OperateResult.AppendText("未正确安装打印软件\n", Color.Red);
  94. }
  95. }
  96. private void Ma_code_DBChange(object sender, EventArgs e)
  97. {
  98. DBFind = ma_code.ReturnData;
  99. BaseUtil.SetFormValue(this.Controls, DBFind);
  100. string ifforsn = dh.getFieldDataByCondition("make left join stepbom on ma_prodcode=sb_prodcode left join stepproduct on sb_id=sp_sbid", "nvl(sp_ifforsn,0) sp_ifforsn", "ma_code='" + ma_code.Text + "' and sp_craftcode='" + ma_craftcode.Text + "' and sp_stepcode='" + User.CurrentStepCode + "' and sb_bomversion='" + ma_bomversion.Text + "' order by sp_detno").ToString();
  101. if (ifforsn != "" && ifforsn != "0")
  102. iflastsn.Checked = true;
  103. else
  104. iflastsn.Checked = false;
  105. }
  106. private void Make_FeedingCollection_SizeChanged(object sender, EventArgs e)
  107. {
  108. asc.controlAutoSize(this);
  109. }
  110. private void Clean_Click(object sender, EventArgs e)
  111. {
  112. OperateResult.Clear();
  113. }
  114. private void Confirm_Click(object sender, EventArgs e)
  115. {
  116. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  117. code_KeyDown(sender, e2);
  118. }
  119. private void code_KeyDown(object sender, KeyEventArgs e)
  120. {
  121. if (e.KeyCode == Keys.Enter)
  122. {
  123. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  124. {
  125. if (Loading.Checked)
  126. {
  127. if (code.Text.Replace(" ", "") == "")
  128. {
  129. OperateResult.AppendText(">>采集数据不可为空\n", Color.Red);
  130. return;
  131. }
  132. //如果录入框和工单号均有输入
  133. if (code.Text != "" && ma_code.Text != "" && sn_code.Text == "")
  134. {
  135. GetCollectItem();
  136. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  137. }
  138. //输入框有值但未选择工单号
  139. else if (code.Text != "" && ma_code.Text == "" && sn_code.Text == "")
  140. {
  141. GetCollectItem();
  142. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
  143. }
  144. else if (sn_code.Text != "")
  145. {
  146. //索引超出长度表示内容均已提醒
  147. if (RemainIndex >= RemainList.Length)
  148. {
  149. OperateResult.AppendText(">>当前序列号" + sn_code.Text + "不在本道工序,请采集其它序列号\n", Color.Red);
  150. sn_code.Text = "";
  151. code.Text = "";
  152. return;
  153. }
  154. string sp_soncode = dt1.Rows[RemainIndex]["sp_soncode"].ToString();
  155. string sp_fsoncode = dt1.Rows[RemainIndex]["sp_fsoncode"].ToString();
  156. string sp_prefix = dt1.Rows[RemainIndex]["sp_prefix"].ToString();
  157. string sp_regex = dt1.Rows[RemainIndex]["sp_regex"].ToString();
  158. string length = dt1.Rows[RemainIndex]["sp_length"].ToString();
  159. string sp_id = dt1.Rows[RemainIndex]["sp_id"].ToString();
  160. string sp_ifrepeat = dt1.Rows[RemainIndex]["sp_ifrepeat"].ToString();
  161. string sp_ifforsn = dt1.Rows[RemainIndex]["sp_ifforsn"].ToString();
  162. string sp_barcoderule = dt1.Rows[RemainIndex]["sp_barcoderule"].ToString();
  163. string sp_checkbarcode = dt1.Rows[RemainIndex]["sp_checkbarcode"].ToString();
  164. string sp_checksalecode = dt1.Rows[RemainIndex]["sp_checksalecode"].ToString();
  165. string sp_ifuseregex = dt1.Rows[RemainIndex]["sp_ifuseregex"].ToString();
  166. if (LogicHandler.CheckSNBeforeLoad(ma_code.Text, code.Text, sp_fsoncode, sp_soncode, sp_barcoderule, sp_prefix, length, sp_ifrepeat, sp_checksalecode, out ErrorMessage))
  167. {
  168. //判断采集的条码和本次采集的也不能重复
  169. if (CollectData.Contains(code.Text) && sp_ifrepeat != "-1")
  170. {
  171. OperateResult.AppendText(">>条码" + code.Text + "已经上料\n", Color.Red, code);
  172. return;
  173. }
  174. if (sp_checkbarcode != "")
  175. {
  176. if (CheckBarcode.ContainsKey(sp_checkbarcode))
  177. {
  178. if (CheckBarcode[sp_checkbarcode] != code.Text)
  179. {
  180. OperateResult.AppendText(">>条码" + code.Text + "需要检查物料,未匹配到之前上料数据\n", Color.Red, code);
  181. return;
  182. }
  183. }
  184. else
  185. {
  186. OperateResult.AppendText(">>条码" + code.Text + "需要检查物料,未匹配到之前上料数据\n", Color.Red, code);
  187. return;
  188. }
  189. }
  190. if (sp_ifuseregex == "-1")
  191. {
  192. dt = (DataTable)dh.ExecuteSql("select SR_REPLACE from SPREPLACE where INSTR('" + code.Text + "',SR_CONTAIN)>0 AND LENGTH('" + code.Text + "') = SR_LENGTH", "select");
  193. if (dt.Rows.Count == 0)
  194. {
  195. OperateResult.AppendText(">>条码" + code.Text + "属于特殊物料,但是并未找到对应特殊物料规则\n", Color.Red, code);
  196. return;
  197. }
  198. replacestring = dt.Rows[0]["SR_REPLACE"].ToString();
  199. }
  200. TSN.Add(code.Text);
  201. if (sp_barcoderule == "BARCODE")
  202. {
  203. sp_soncode = ErrorMessage;
  204. }
  205. Save_OtherCode(sp_fsoncode, sp_soncode, make_code, sn_code.Text, sp_id);
  206. }
  207. else
  208. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  209. }
  210. }
  211. //勾选了下料的时候
  212. else if (UnLoading.Checked)
  213. {
  214. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, code.Text, User.UserCode, out oMakeCode, out oMsid, out ErrorMessage))
  215. {
  216. sql.Clear();
  217. sql.Append("select ms_firstsn,cm_makecode,cm_craftcode,nvl(cm_status,0)cm_status,cm_id,cm_stepcode,");
  218. sql.Append("ms_makecode,cm_mccode,cm_materialtype from craftmaterial left join makeserial on cm_makecode");
  219. sql.Append("=ms_makecode and cm_sncode=ms_sncode where cm_sncode='" + code.Text + "' and cm_makecode='" + oMakeCode + "'");
  220. sql.Append("and cm_materialtype=1");
  221. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  222. if (dt.Rows.Count > 0)
  223. {
  224. string ms_macode = dt.Rows[0]["ms_makecode"].ToString();
  225. string ms_firstsn = dt.Rows[0]["ms_firstsn"].ToString();
  226. string cm_stepcode = dt.Rows[0]["cm_stepcode"].ToString();
  227. string cm_mccode = dt.Rows[0]["cm_mccode"].ToString();
  228. string cm_materialtype = dt.Rows[0]["cm_materialtype"].ToString();
  229. string cm_status = dt.Rows[0]["cm_status"].ToString();
  230. string cm_makecode = dt.Rows[0]["cm_makecode"].ToString();
  231. string cm_craftcode = dt.Rows[0]["cm_craftcode"].ToString();
  232. //清除已被使用的序列号
  233. sql.Clear();
  234. sql.Append("update makeserial set ms_nextmacode='' where ms_sncode in(select cm_barcode from craftmaterial where ");
  235. sql.Append("cm_makecode='" + cm_makecode + "' and cm_sncode='" + code.Text + "' and cm_stepcode='" + cm_stepcode + "' and cm_craftcode='" + cm_craftcode + "' ");
  236. sql.Append("and cm_materialtype=1 and nvl(cm_status,0) =0) and ms_nextmacode='" + oMakeCode + "'");
  237. dh.ExecuteSql(sql.GetString(), "update");
  238. //进行下料
  239. sql.Clear();
  240. sql.Append("delete from craftmaterial where (cm_sncode in (select sn from makesnrelation where firstsn");
  241. sql.Append("='" + ms_firstsn + "') or cm_sncode = '" + ms_firstsn + "') and cm_makecode = '" + oMakeCode + "' ");
  242. sql.Append("and cm_status = 0 and cm_stepcode='" + User.CurrentStepCode + "' and cm_materialtype=1");
  243. dh.ExecuteSql(sql.GetString(), "delete");
  244. LogicHandler.InsertMakeProcess(ms_macode, code.Text, User.UserSourceCode, "上料采集操作", "下料成功", User.UserCode);
  245. //刷新界面值
  246. sql.Clear();
  247. sql.Append("select mcd_inqty,ma_qty-mcd_inqty mcd_remainqty ");
  248. sql.Append("from make left join makecraftdetail_view on mcd_macode=ma_code where ");
  249. sql.Append("ma_code='" + oMakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  250. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  251. BaseUtil.SetFormValue(Controls, dt);
  252. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "上料采集", "下料成功", code.Text, "");
  253. OperateResult.AppendText(">>序列号" + code.Text + "下料成功\n", Color.Green, code);
  254. }
  255. else OperateResult.AppendText(">>序列号" + code.Text + "未上料,无需下料\n", Color.Red, code);
  256. }
  257. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  258. }
  259. }
  260. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  261. }
  262. }
  263. //获取采集的项目
  264. private void GetCollectItem()
  265. {
  266. bool NoteAlready = LogicHandler.CheckDiffMakeCodeBeforeStepCheck(code.Text, ma_code.Text, NoteForChange.Checked, out oMakeCode, out ErrorMessage);
  267. if (!NoteAlready)
  268. {
  269. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  270. return;
  271. }
  272. if (LogicHandler.CheckStepSNAndMacode(oMakeCode, User.UserSourceCode, code.Text, User.UserCode, out oMakeCode, out oMsid, out ErrorMessage))
  273. {
  274. if (!LogicHandler.CheckDiffMakeCodeAfterStepCheck(code.Text, oMakeCode, NoteForChange.Checked, NoteAlready, ma_code, out ErrorMessage))
  275. {
  276. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  277. return;
  278. }
  279. //将录入框的值给序列号
  280. sn_code.Text = code.Text;
  281. sql.Clear();
  282. sql.Append("select ma_prodcode,ma_ecncode,ma_softversion,ms_firstsn,ma_bomversion,ma_qty,ma_code,pr_orispeccode pr_spec,ms_status,ms_id,ms_craftcode,ms_nextstepcode");
  283. sql.Append(",ms_prodcode,ms_makecode,ms_code,ms_stepname from makeserial left join make on ma_code=ms_makecode ");
  284. sql.Append("left join product on ms_prodcode=pr_code where ms_sncode='" + code.Text + "' order by ms_id desc");
  285. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  286. if (dt.Rows.Count > 0)
  287. {
  288. ms_id = dt.Rows[0]["ms_id"].ToString();
  289. make_code = dt.Rows[0]["ma_code"].ToString();
  290. mabomversion = dt.Rows[0]["ma_bomversion"].ToString();
  291. make_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  292. nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  293. ms_status = dt.Rows[0]["ms_status"].ToString();
  294. ms_firstsn = dt.Rows[0]["ms_firstsn"].ToString();
  295. BaseUtil.SetFormValue(this.Controls, dt);
  296. string ifforsn = dh.getFieldDataByCondition("make left join stepbom on ma_prodcode=sb_prodcode left join stepproduct on sb_id=sp_sbid", "nvl(sp_ifforsn,0) sp_ifforsn", "ma_code='" + ma_code.Text + "' and sp_stepcode='" + User.CurrentStepCode + "' and sp_craftcode='" + ms_craftcode.Text + "' and sb_bomversion='" + ma_bomversion.Text + "' order by sp_detno").ToString();
  297. if (ifforsn != "" && ifforsn != "0")
  298. iflastsn.Checked = true;
  299. else
  300. iflastsn.Checked = false;
  301. LockMakeCode.Checked = true;
  302. //勾选了前一工单
  303. if (iflastsn.Checked)
  304. {
  305. dt = (DataTable)dh.ExecuteSql("select ms_id,ms_makecode,ms_craftcode,ms_status,ms_nextstepcode,ms_prodcode,ms_code from makeserial where ms_sncode='" + code.Text + "' and ms_makecode<>'" + ma_code.Text + "' order by ms_id desc", "select");
  306. string make_code = "";
  307. string make_prodcode = "";
  308. string nextstepcode = "";
  309. string ms_status = "";
  310. if (dt.Rows.Count > 0)
  311. {
  312. ms_id = dt.Rows[0]["ms_id"].ToString();
  313. make_code = dt.Rows[0]["ms_makecode"].ToString();
  314. make_prodcode = dt.Rows[0]["ms_prodcode"].ToString();
  315. nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  316. ms_status = dt.Rows[0]["ms_status"].ToString();
  317. //判断序列号的前一工单是否已经完工
  318. if (dt.Rows[0]["ms_makecode"].ToString() != ma_code.Text && dt.Rows[0]["ms_status"].ToString() == "2")
  319. {
  320. sql.Clear();
  321. sql.Append("select sp_id,sp_soncode from make inner join stepbom on ma_prodcode=sb_prodcode and ma_bomversion=sb_bomversion left ");
  322. sql.Append("join stepproduct on sp_sbid=sb_id where ma_code='" + ma_code.Text + "' and sp_craftcode='" + ms_craftcode.Text + "' ");
  323. sql.Append("and sp_stepcode='" + User.CurrentStepCode + "' and nvl(sp_ifforsn,0)<>0");
  324. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  325. if (dt.Rows.Count > 0)
  326. {
  327. string sp_id = dt.Rows[0]["sp_id"].ToString();
  328. string sp_soncode = dt.Rows[0]["sp_soncode"].ToString();
  329. if (!dh.CheckExist("Craftmaterial", "cm_makecode='" + ma_code.Text + "' and cm_soncode='" + make_prodcode + "' and cm_sncode='" + code.Text + "' and cm_status=0"))
  330. {
  331. CollectDataSonCode.Add(sp_soncode);
  332. SPID.Add(sp_id);
  333. CollectData.Add(code.Text);
  334. sn_code.Text = code.Text;
  335. OperateResult.AppendText(">>序列号" + code.Text + ",物料" + sp_soncode + "上料成功\n", Color.Green);
  336. RemainIndex = RemainIndex + 1;
  337. GetItem();
  338. return;
  339. }
  340. else
  341. {
  342. GetItem();
  343. }
  344. }
  345. else OperateResult.AppendText(">>序列号" + code.Text + "无生产信息\n", Color.Red, code);
  346. }
  347. else OperateResult.AppendText(">>序列号" + code.Text + "已被工单" + dt.Rows[0]["ms_makecode"].ToString() + "绑定,尚未完工\n", Color.Red, code);
  348. }
  349. else OperateResult.AppendText(">>序列号" + code.Text + "无生产信息\n", Color.Red, code);
  350. }
  351. else
  352. {
  353. dt = (DataTable)dh.ExecuteSql("select ms_status,ms_stepcode,ms_nextstepcode from makeserial where ms_sncode='" + code.Text + "' and ms_makecode='" + ma_code.Text + "' order by ms_id desc", "select");
  354. nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  355. ms_status = dt.Rows[0]["ms_status"].ToString();
  356. sn_code.Text = code.Text;
  357. sql.Clear();
  358. sql.Append("select ma_code,ma_softversion,ma_ecncode,ma_prodcode,pr_orispeccode pr_spec,ma_qty from makeserial left join product ");
  359. sql.Append(" on ms_prodcode=pr_code left join make on ms_makecode=ma_code ");
  360. sql.Append(" where ms_id='" + oMsid + "'");
  361. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  362. BaseUtil.SetFormValue(this.Controls, dt);
  363. OperateResult.AppendText(">>获取序列号" + code.Text + "成功\n", Color.Green);
  364. GetItem();
  365. }
  366. }
  367. else
  368. {
  369. OperateResult.AppendText(">>序列号" + code.Text + "不存在\n", Color.Red, code);
  370. code.Text = "";
  371. sn_code.Text = "";
  372. }
  373. }
  374. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  375. }
  376. private void GetItem()
  377. {
  378. //单独用一个DataTable存储一个
  379. dt1 = new DataTable();
  380. sql.Clear();
  381. sql.Append("select max(sp_id)sp_id,max(sp_detno)sp_detno,min(sp_ifrepeat)sp_ifrepeat,min(sp_iflabelcheck) sp_iflabelcheck,max(sp_checkbarcode)sp_checkbarcode,min(sp_checksalecode)sp_checksalecode,");
  382. sql.Append("sp_fsoncode,max(sp_barcoderule)sp_barcoderule,wm_concat(sp_soncode) sp_soncode,max(sp_ifuseregex)sp_ifuseregex,max(sp_ifforsn)");
  383. sql.Append("sp_ifforsn,max(sp_length)sp_length,max(sp_type)sp_type,replace(wm_concat(pr_oriname),',','|')sp_prefix,max(sp_regex)");
  384. sql.Append("sp_regex,max(pr_detail)pr_detail from stepproduct left join product on pr_code=sp_fsoncode where ");
  385. sql.Append("sp_bomversion='" + ma_bomversion.Text + "' and sp_craftcode='" + ms_craftcode.Text + "' and sp_stepcode='" + User.CurrentStepCode + "' ");
  386. sql.Append("And sp_mothercode ='" + ma_prodcode.Text + "' and sp_tracekind=1 and not exists(select 1 from craftmaterial where ");
  387. sql.Append("cm_sncode in (select '" + ms_firstsn + "' from dual union select sn from makesnrelation where firstsn='" + ms_firstsn + "') and cm_makecode='" + ma_code.Text + "' and cm_fsoncode=");
  388. sql.Append("sp_fsoncode and cm_status=0) group by sp_fsoncode order by SP_DETNO asc");
  389. dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  390. code.Clear();
  391. //用于记录提醒的数据长度
  392. RemainList = new string[dt1.Rows.Count];
  393. for (int i = 0; i < dt1.Rows.Count; i++)
  394. {
  395. string soncode = dt1.Rows[i]["sp_soncode"].ToString();
  396. string prdetail = dt1.Rows[i]["pr_detail"].ToString();
  397. RemainList[i] = soncode + "(" + prdetail + ")";
  398. }
  399. if (dt1.Rows.Count > 0)
  400. {
  401. try
  402. {
  403. string soncode = dt1.Rows[RemainIndex]["sp_soncode"].ToString();
  404. string prdetail = dt1.Rows[RemainIndex]["pr_detail"].ToString();
  405. OperateResult.AppendText("<<请采集" + soncode + "(" + prdetail + ")的物料数据\n", Color.Black);
  406. }
  407. catch (Exception)
  408. {
  409. OperateResult.AppendText(">>序列号" + sn_code.Text + "上料采集完成!\n", Color.Green);
  410. code.Text = "";
  411. sn_code.Text = "";
  412. }
  413. }
  414. else
  415. {
  416. string nextstepcode = dh.getFieldDataByCondition("makeserial left join step on ms_nextstepcode = st_code", "st_name", "ms_sncode = '" + sn_code.Text + "'").ToString();
  417. OperateResult.AppendText(">>序列号" + sn_code.Text + "已经上料完成,处于" + nextstepcode + "工序,请采集其它序列号\n", Color.Red);
  418. if (!LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, sn_code.Text, "上料采集", "上料成功", User.UserCode, out ErrorMessage))
  419. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  420. else
  421. {
  422. //提示正确返回时传递的信息
  423. if (ErrorMessage.Contains("AFTERSUCCESS"))
  424. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  425. OperateResult.AppendText(">>序列号" + sn_code.Text + "采集成功!\n", Color.Green);
  426. }
  427. code.Text = "";
  428. sn_code.Text = "";
  429. }
  430. }
  431. //此类中通用的保存逻辑
  432. private void Save_OtherCode(string sp_fsoncode, string sp_soncode, string ma_code, string ms_sncode, string sp_id)
  433. {
  434. CollectDataSonCode.Add(sp_soncode);
  435. //采集成功提示
  436. CollectData.Add(code.Text);
  437. if (!CheckBarcode.ContainsKey(sp_fsoncode))
  438. {
  439. CheckBarcode.Add(sp_fsoncode, code.Text);
  440. }
  441. SPID.Add(sp_id);
  442. OperateResult.AppendText(">>物料" + sp_soncode + "采集成功,条码" + code.Text + "\n", Color.Green);
  443. LabelDataGridView.Rows[RemainIndex].Cells["BarCode"].Value = code.Text;
  444. //if (code.Text.Length > 200)
  445. // OperateResult.AppendText(">>采集条码" + code.Text + "程度超过长度限制200,内容截取前200位进行采集\n", Color.Red);
  446. code.Clear();
  447. RemainIndex = RemainIndex + 1;
  448. //如果+1后不小于B序列的长度,则已采集完成,不需要进行提示了
  449. if (RemainIndex < RemainList.Length)
  450. {
  451. OperateResult.AppendText("<<请采集" + RemainList[RemainIndex] + "的物料数据\n", Color.Black);
  452. }
  453. else
  454. {
  455. sql.Clear();
  456. sql.Append("insert into Craftmaterial (cm_id ,cm_makecode,cm_maid,cm_maprodcode, cm_soncode, cm_mscode, cm_sncode, cm_stepcode, cm_stepname,cm_fsoncode,");
  457. sql.Append("cm_craftcode,cm_craftname,cm_barcode,cm_inqty,cm_indate,cm_inman,cm_linecode,cm_wccode,cm_sourcecode,cm_spid,cm_status,cm_materialtype,cm_firstsn)");
  458. sql.Append("select Craftmaterial_seq.nextval, ma_code, ma_id, ma_prodcode,:soncode,ms_code,ms_sncode,mcd_stepcode,");
  459. sql.Append("mcd_stepname,sp_fsoncode,ms_craftcode,ms_craftname,:barcode,1,sysdate,'" + User.UserCode + "','" + User.UserLineCode + "',ma_wccode,");
  460. sql.Append("'" + User.UserSourceCode + "',:sp_id,0,1,ms_firstsn from make left join makecraftdetail on mcd_macode=ma_code left join stepproduct on sp_stepcode=mcd_stepcode ");
  461. sql.Append(" and sp_mothercode = ma_prodcode left join makeserial on ms_makecode=ma_code and sp_craftcode=ms_craftcode ");
  462. sql.Append("where ma_code='" + make_code + "'and sp_id=:sp_id1 and mcd_stepcode = '" + User.CurrentStepCode + "' and ms_sncode='" + ms_sncode + "'");
  463. dh.BatchInsert(sql.GetString(), new string[] { "soncode", "barcode", "sp_id", "sp_id1" }, CollectDataSonCode.ToArray(), CollectData.ToArray(), SPID.ToArray(), SPID.ToArray());
  464. try
  465. {
  466. string Log = "";
  467. for (int i = 0; i < CollectDataSonCode.Count; i++)
  468. {
  469. Log += CollectDataSonCode.ToArray()[i] + " " + CollectData.ToArray()[i] + " " + SPID.ToArray()[i];
  470. }
  471. LogManager.DoLog(Log);
  472. }
  473. catch (Exception)
  474. {
  475. }
  476. //更新序列号半成品已被使用
  477. //dh.BatchInsert("update makeserial set ms_nextmacode='" + ma_code + "' where ms_id=(select max(ms_id) from makeserial where ms_sncode=:sncode and ms_nextmacode is null and ms_makecode<>'" + ma_code + "')", new string[] { "sncode" }, TSN.ToArray());
  478. //if (ma_ecncode_label.Checked || ma_softversion_label.Checked)
  479. //{
  480. // string ecnText = ma_ecncode_label.Checked ? ma_ecncode.Text : "";
  481. // string softversionText = ma_softversion_label.Checked ? ma_softversion.Text : "";
  482. // string remark = sir_remark_label.Checked ? sir_remark.Text : "";
  483. // sql.Clear();
  484. // sql.Append("insert into SNRELATIONINFORECORD(SIR_ID,SIR_SNCODE,SIR_MSCODE,SIR_ECNCODE,SIR_SOFTVER,");
  485. // sql.Append("SIR_LINECODE,SIR_SOURCECODE,SIR_STEPCODE,SIR_MACODE,SIR_PRODCODE,SIR_INMAN,SIR_INDATE,sir_firstsn,sir_remark) select ");
  486. // sql.Append("SNRELATIONINFORECORD_SEQ.nextval,'" + sn_code.Text + "',ms_code,'" + ecnText + "','" + softversionText + "',");
  487. // sql.Append("'" + User.UserLineCode + "','" + User.UserSourceCode + "','" + User.CurrentStepCode + "','" + ma_code + "','" + ma_prodcode.Text + "',");
  488. // sql.Append("'" + User.UserCode + "',sysdate,ms_firstsn,'" + remark + "' from makeserial where ms_sncode='" + sn_code.Text + "' and ms_makecode='" + ma_code + "'");
  489. // dh.ExecuteSql(sql.GetString(), "insert");
  490. //}
  491. CollectData.Clear();
  492. TSN.Clear();
  493. SPID.Clear();
  494. CheckBarcode.Clear();
  495. CollectDataSonCode.Clear();
  496. //采集成功,设置序列号栏目为空
  497. RemainIndex = 0;
  498. OperateResult.AppendText(">>序列号" + sn_code.Text + "上料采集完成!\n", Color.Green);
  499. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "上料采集", "上料成功", sn_code.Text, "");
  500. if (LogicHandler.SetStepResult(ma_code, User.UserSourceCode, sn_code.Text, "上料采集", "上料成功", User.UserCode, out ErrorMessage))
  501. {
  502. //提示正确返回时传递的信息
  503. if (ErrorMessage.Contains("AFTERSUCCESS"))
  504. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  505. //if (checkBox1.Checked)
  506. //{
  507. // if (Print.SinglePrint(Tag.ToString(), engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, sn_code.Text, int.Parse(PrintNum.Text), oMakeCode, ma_prodcode.Text, "机身标", "-1", out ErrorMessage))
  508. // {
  509. // //提示用户打印成功
  510. // OperateResult.AppendText(">>序列号:" + sn_code.Text + "打印成功\n", Color.Green);
  511. // }
  512. // else
  513. // {
  514. // OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
  515. // }
  516. //}
  517. sn_code.Text = "";
  518. //刷新数据
  519. EventArgs e = new EventArgs();
  520. object sender = null;
  521. replacestring = "";
  522. ma_code_UserControlTextChanged(sender, e);
  523. }
  524. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
  525. }
  526. }
  527. private void ClearSn_code_Click(object sender, EventArgs e)
  528. {
  529. sn_code.Clear();
  530. SPID.Clear();
  531. TSN.Clear();
  532. CheckBarcode.Clear();
  533. CollectData.Clear();
  534. CollectDataSonCode.Clear();
  535. replacestring = "";
  536. if (dt1 != null)
  537. BaseUtil.CleanDataTableData(dt1);
  538. RemainIndex = 0;
  539. BaseUtil.CleanDGVData(LabelDataGridView);
  540. OperateResult.AppendText(">>请采集序列号\n", Color.Black);
  541. }
  542. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  543. {
  544. if (ma_code.Text.Length > 4)
  545. {
  546. if (ma_code.Text.Length > 4)
  547. {
  548. BaseUtil.CleanControlsText(mcd_inqty, mcd_remainqty);
  549. LoadCollectedNum();
  550. }
  551. }
  552. }
  553. private void LoadCollectedNum()
  554. {
  555. dt = (DataTable)dh.ExecuteSql("select mcd_inqty,ma_qty-mcd_inqty mcd_remainqty,mcd_ngqty,mcd_okqty,mcd_totalng from make left join makecraftdetail_view on mcd_macode=ma_code where ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'", "select");
  556. BaseUtil.SetFormValue(Controls, dt);
  557. }
  558. private void Make_FeedingCollection_FormClosing(object sender, FormClosingEventArgs e)
  559. {
  560. //if (engine != null)
  561. // engine.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
  562. dh.Dispose();
  563. }
  564. private void ma_prodcode_TextChanged(object sender, EventArgs e)
  565. {
  566. //DataTable dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault from label where la_prodcode='" + ma_prodcode.Text + "' and la_templatetype='机身标' and la_statuscode='AUDITED' order by la_isdefault", "select");
  567. //if (dt.Rows.Count == 0)
  568. //{
  569. // return;
  570. //}
  571. //PrintLabel.DataSource = dt;
  572. //PrintLabel.DisplayMember = "la_url";
  573. //PrintLabel.ValueMember = "la_id";
  574. }
  575. }
  576. }