UAS_出货标签管理.cs 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using System.Text.RegularExpressions;
  6. using System.Text;
  7. using System.Collections.Generic;
  8. using System.Diagnostics;
  9. using LabelManager2;
  10. using UAS_LabelMachine.PublicMethod;
  11. using UAS_LabelMachine.Entity;
  12. using UAS_LabelMachine.PublicForm;
  13. using System.Threading;
  14. using System.IO;
  15. using System.IO.Ports;
  16. using UAS_LabelMachine.CustomControl;
  17. namespace UAS_LabelMachine
  18. {
  19. public partial class UAS_出货标签打印 : Form
  20. {
  21. //自适应屏幕
  22. AutoSizeFormClass asc = new AutoSizeFormClass();
  23. DataHelper dh;
  24. AccessDBHelper adh;
  25. DataTable dt;
  26. StringBuilder sql = new StringBuilder();
  27. /// <summary>
  28. /// CodeSoft新建打印机引擎
  29. /// </summary>
  30. ApplicationClass lbl;
  31. /// <summary>
  32. /// 单盘打印文件
  33. /// </summary>
  34. Document SingleDoc;
  35. /// <summary>
  36. /// 中盒打印文件
  37. /// </summary>
  38. Document MidDoc;
  39. /// <summary>
  40. /// 外箱打印文件
  41. /// </summary>
  42. Document OutBoxDoc;
  43. /// <summary>
  44. /// Loading窗口
  45. /// </summary>
  46. SetLoadingWindow stw;
  47. /// <summary>
  48. /// 弹窗线程
  49. /// </summary>
  50. Thread thread;
  51. string PI_ID;
  52. /// <summary>
  53. /// 当前扫描的所在行
  54. /// </summary>
  55. int CurrentRowIndex = 0;
  56. /// <summary>
  57. /// 正则表达式用于项目匹配
  58. /// </summary>
  59. Regex reg;
  60. bool logout = false;
  61. string SplitChar = ",@#| &";
  62. DataTable SingleLabelParam;
  63. DataTable MidLabelParam;
  64. DataTable OutLabelParam;
  65. /// <summary>
  66. /// 存放单盘的ID
  67. /// </summary>
  68. List<string> SingleID = new List<string>();
  69. /// <summary>
  70. /// 单盘的打印参数
  71. /// </summary>
  72. List<string> SingleBoxArgument = new List<string>();
  73. /// <summary>
  74. /// 存放中盒的ID和盒号
  75. /// </summary>
  76. Dictionary<string, string> MidIDAndOutboxcode = new Dictionary<string, string>();
  77. /// <summary>
  78. /// 中盒的打印参数
  79. /// </summary>
  80. List<string> MidBoxArgument = new List<string>();
  81. /// <summary>
  82. /// 默认采集了指定的数据上传
  83. /// </summary>
  84. int UploadNum = 100;
  85. /*需要重绘的Cell*/
  86. Dictionary<DataGridViewCell, bool> PaintCell = new Dictionary<DataGridViewCell, bool>();
  87. /// <summary>
  88. /// 是否通过选择Combox来改变打开的文件
  89. /// </summary>
  90. bool ComBoxClickChangeLabelDoc = false;
  91. /// <summary>
  92. /// 附加信息DataTable
  93. /// </summary>
  94. DataTable Attach;
  95. /// <summary>
  96. /// 采集策略DataTable
  97. /// </summary>
  98. DataTable ScanGroup;
  99. /// <summary>
  100. /// 采集明细DataTable
  101. /// </summary>
  102. DataTable ScanItem;
  103. public UAS_出货标签打印(string Master)
  104. {
  105. InitializeComponent();
  106. Text = Text + "-" + Master;
  107. }
  108. protected override void WndProc(ref Message m)
  109. {
  110. //拦截双击标题栏、移动窗体的系统消息
  111. if (m.Msg != 0xA3)
  112. {
  113. base.WndProc(ref m);
  114. }
  115. }
  116. private void 贴标机条码打印_Load(object sender, EventArgs e)
  117. {
  118. //杀死之前全部未关闭的进程
  119. Process[] processes = System.Diagnostics.Process.GetProcessesByName("lppa");
  120. for (int i = 0; i < processes.Length; i++)
  121. {
  122. processes[i].Kill();
  123. }
  124. //用计时器重置数据库链接
  125. LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】");
  126. dh = SystemInf.dh;
  127. adh = SystemInf.adh;
  128. CheckForIllegalCrossThreadCalls = false;
  129. pi_inoutno.Focus();
  130. Point pt = new Point();
  131. //禁止所有列的排序
  132. foreach (DataGridViewColumn dgv in LabelInf.Columns)
  133. {
  134. dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
  135. }
  136. AutoCollection.Checked = true;
  137. int ScreenWidth = Screen.GetWorkingArea(pt).Width;
  138. //设置获取当前屏幕大小自动全屏但是保留任务栏
  139. Rectangle ScreenArea = Screen.GetWorkingArea(this);
  140. Top = 0;
  141. Left = 0;
  142. Width = ScreenArea.Width;
  143. Height = ScreenArea.Height;
  144. MidBoxCapacity.Value = Properties.Settings.Default.MidBoxCapacity;
  145. OutBoxCapacity.Value = Properties.Settings.Default.OutboxCapacity;
  146. asc.controllInitializeSize(this);
  147. asc.controlAutoSize(this);
  148. //实例化打印进程
  149. try
  150. {
  151. lbl = new ApplicationClass();
  152. }
  153. catch (Exception)
  154. {
  155. MessageBox.Show("未安装CodeSoft软件或者版本不正确");
  156. }
  157. RefreshDBConnect.Interval = 60000;
  158. RefreshDBConnect.Start();
  159. DataTable dt = (DataTable)adh.ExecuteSql("select * from cominfo", "select");
  160. DataRow[] dr = dt.Select("comtype='FrontendCheck'");
  161. if (dr.Length > 0)
  162. {
  163. FrontendCheck.PortName = dr[0]["COM"].ToString();
  164. FrontendCheck.Tag = "FrontendCheck";
  165. FrontendCheck.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
  166. FrontendCheck.DataReceived += Serial_DataReceived;
  167. FrontendCheck.Open();
  168. }
  169. dr = dt.Select("comtype='BackendCheck'");
  170. if (dr.Length > 0)
  171. {
  172. BackendCheck.PortName = dr[0]["COM"].ToString();
  173. BackendCheck.Tag = "BackendCheck";
  174. BackendCheck.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
  175. BackendCheck.DataReceived += Serial_DataReceived;
  176. BackendCheck.Open();
  177. }
  178. RefreshPLCInstruct();
  179. }
  180. string LotNo = "";
  181. string DateCode = "";
  182. string Order = "";
  183. string QTY = "";
  184. string PN = "";
  185. string OutBox = "";
  186. //获取串口数据
  187. private void Serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
  188. {
  189. try
  190. {
  191. string ErrorMsg = "";
  192. SerialPortWithTag port = sender as SerialPortWithTag;
  193. int len = port.BytesToRead;
  194. byte[] readBuffer = new byte[len];
  195. port.Read(readBuffer, 0, len); //将数据读入缓存
  196. string msg = Encoding.ASCII.GetString(readBuffer, 0, len); //获取出入库产品编号
  197. string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
  198. int pib_pdno = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["pib_pdno"].Value.ToString());
  199. if (DetailRange.Checked)
  200. {
  201. //不在范围内的不进行处理
  202. if (!(pib_pdno >= DetailRange1.Value && pib_pdno <= DetailRange2.Value))
  203. {
  204. return;
  205. }
  206. }
  207. switch (port.Tag)
  208. {
  209. case "PLC1":
  210. //返回的指令和设备执行的动作对应
  211. foreach (var item in instruct)
  212. {
  213. //接收到的数据和指令的对应则
  214. if (item.Value == msg)
  215. {
  216. }
  217. }
  218. break;
  219. case "PLC2":
  220. break;
  221. case "FrontendCheck":
  222. //比对当前箱数量和容量
  223. FrontCollect.Text = msg;
  224. if (!FrontCheckFunction(msg, out ErrorMsg))
  225. {
  226. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.FrontDataDelete);
  227. MessageLog.AppendText(">>" + ErrorMsg + "\n", Color.Red);
  228. }
  229. else
  230. {
  231. //勾选了单盘自动打印
  232. if (SingleLabelAutoPrint.Checked)
  233. {
  234. if (SingleLabelCombox.SelectedValue != null)
  235. {
  236. AutoPrintSingleLabel();
  237. }
  238. else
  239. {
  240. MessageBox.Show("未维护单盘标签");
  241. return;
  242. }
  243. }
  244. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
  245. //勾选了中盒自动打印
  246. if (MidLabelAutoPrint.Checked)
  247. AutoPrintMidLabel();
  248. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.FrontDataPass);
  249. LabelInf.Invalidate();
  250. }
  251. break;
  252. case "BackendCheck":
  253. BackCheck.Text = msg;
  254. if (BackendCheckFunction(msg, pib_id, out ErrorMsg))
  255. {
  256. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.BackDataPass);
  257. }
  258. else
  259. {
  260. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.BackDataDelete);
  261. MessageLog.AppendText(">>" + ErrorMsg + "\n", Color.Red);
  262. }
  263. break;
  264. default:
  265. break;
  266. }
  267. }
  268. catch (Exception ex)
  269. {
  270. LogManager.DoLog(ex.StackTrace);
  271. MessageBox.Show("接收返回消息异常!具体原因:" + ex.Message, "提示信息");
  272. }
  273. }
  274. private bool RegexMatch(string CheckType, string msg, out string ErrorMsg, out int GroupCount)
  275. {
  276. ErrorMsg = "";
  277. GroupCount = 0;
  278. for (int i = 0; i < ScanGroup.Rows.Count; i++)
  279. {
  280. string sg_name = ScanGroup.Rows[i]["sg_name"].ToString();
  281. string sg_brand = ScanGroup.Rows[i]["sg_brand"].ToString();
  282. string sg_script = ScanGroup.Rows[i]["sg_script"].ToString();
  283. string sg_id = ScanGroup.Rows[i]["sg_id"].ToString();
  284. reg = new Regex(sg_script);
  285. Match matchs1 = reg.Match(msg);
  286. int index = 0;
  287. //自动获取分隔符号,分割解析到的数据
  288. char Splitor = BaseUtil.GetSplitChar(matchs1.Value.ToString());
  289. string[] sgarr = sg_script.Split(Splitor);
  290. string[] arr = matchs1.Value.Split(Splitor);
  291. DataTable dt = BaseUtil.filterDataTable(ScanItem, "sg_id=" + sg_id);
  292. List<int> ItemIndex = new List<int>();
  293. for (int j = 0; j < sgarr.Length; j++)
  294. {
  295. for (int k = 0; k < dt.Rows.Count; k++)
  296. {
  297. if (sgarr[j].Contains(dt.Rows[k]["si_name"].ToString()))
  298. {
  299. ItemIndex.Add(j);
  300. }
  301. }
  302. }
  303. //成功获取到了分隔符号并且匹配的项次相等, 如果不包含分隔符只需要一项
  304. if (matchs1.Value.ToString() != "" && ((SplitChar.Contains(Splitor.ToString()) && ItemIndex.Count == dt.Rows.Count) || (!SplitChar.Contains(Splitor.ToString()) && ItemIndex.Count == 1 && arr.Length == 1)))
  305. {
  306. string ItemStr = "";
  307. for (int j = 0; j < dt.Rows.Count; j++)
  308. {
  309. ItemStr += dt.Rows[j]["si_item"].ToString() + ",";
  310. string si_expression = dt.Rows[j]["si_expression"].ToString();
  311. Regex si_exp;
  312. switch (dt.Rows[j]["si_item"].ToString())
  313. {
  314. case "DateCode":
  315. if (si_expression != "")
  316. {
  317. si_exp = new Regex(si_expression);
  318. DateCode = si_exp.Match(arr[ItemIndex[j]]).Value;
  319. }
  320. else
  321. {
  322. DateCode = arr[ItemIndex[j]];
  323. }
  324. break;
  325. case "LotNo":
  326. LotNo = arr[ItemIndex[j]];
  327. break;
  328. case "PN":
  329. PN = arr[ItemIndex[j]];
  330. //自动匹配客户PN
  331. DataTable pndt = (DataTable)adh.ExecuteSql("select min(rownum) as rn from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pr_orispeccode='" + PN + "' and pib_ifpick=0", "select");
  332. int rownum = 0;
  333. if (pndt.Rows[0][0].ToString() != "")
  334. {
  335. if (CheckType == "FrontCheck")
  336. {
  337. rownum = int.Parse(pndt.Rows[0]["rn"].ToString());
  338. //如果需要翻页的话
  339. if (!(rownum >= (PageSize * (CurrentPage - 1) + 1) && rownum <= PageSize * CurrentPage))
  340. {
  341. CurrentPage = rownum / PageSize + 1;
  342. LoadGridData();
  343. CurrentRowIndex = rownum % PageSize == 0 ? PageSize - 1 : rownum % PageSize - 1;
  344. if (CurrentRowIndex - 10 > 0)
  345. LabelInf.FirstDisplayedScrollingRowIndex = CurrentRowIndex - 5;
  346. }
  347. else
  348. {
  349. CurrentRowIndex = rownum % PageSize == 0 ? PageSize - 1 : rownum % PageSize - 1;
  350. if (CurrentRowIndex - 10 > 0)
  351. LabelInf.FirstDisplayedScrollingRowIndex = CurrentRowIndex - 5;
  352. }
  353. }
  354. }
  355. else
  356. {
  357. ErrorMsg = "未能匹配到合适的原厂型号";
  358. }
  359. break;
  360. case "Order":
  361. Order = arr[ItemIndex[j]];
  362. if (LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString() != Order)
  363. {
  364. ErrorMsg = "订单号不匹配";
  365. }
  366. break;
  367. case "QTY":
  368. if (si_expression != "")
  369. {
  370. si_exp = new Regex(si_expression);
  371. QTY = si_exp.Match(arr[ItemIndex[j]]).Value;
  372. }
  373. else
  374. {
  375. QTY = arr[ItemIndex[j]];
  376. }
  377. break;
  378. case "OutBox":
  379. OutBox = arr[ItemIndex[j]];
  380. break;
  381. default:
  382. break;
  383. }
  384. index = index + 1;
  385. }
  386. if (ErrorMsg == "" && ItemStr.Contains("QTY") && LabelInf.Rows[CurrentRowIndex].Cells["pib_qty"].Value.ToString() != QTY.ToString())
  387. {
  388. ErrorMsg = "数量不匹配";
  389. }
  390. if (ErrorMsg == "" && ItemStr.Contains("PO") && LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString() != Order)
  391. {
  392. ErrorMsg = "订单号不匹配";
  393. }
  394. //如果品牌不对应的话则不能使用本次的匹配规则
  395. if (LabelInf.Rows[CurrentRowIndex].Cells["pib_brand"].Value.ToString() != sg_brand)
  396. {
  397. break;
  398. }
  399. }
  400. else
  401. {
  402. GroupCount = GroupCount + 1;
  403. }
  404. }
  405. if (GroupCount == ScanGroup.Rows.Count)
  406. {
  407. ErrorMsg = "未匹配到合适的采集策略";
  408. }
  409. if (ErrorMsg == "")
  410. {
  411. return true;
  412. }
  413. else
  414. {
  415. return false;
  416. }
  417. }
  418. private bool FrontCheckFunction(string msg, out string ErrorMsg)
  419. {
  420. int GroupCount = 0;
  421. ErrorMsg = "";
  422. //调用正则验证
  423. RegexMatch("FrontCheck", msg, out ErrorMsg, out GroupCount);
  424. if (ErrorMsg != "")
  425. {
  426. return false;
  427. }
  428. else
  429. {
  430. //获取当前最大的箱号
  431. LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value = DateCode;
  432. LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value = LotNo;
  433. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifmodify"].Value = true;
  434. string boxcode = adh.getFieldDataByCondition("prodiobarcode", "max(pib_outboxcode1)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  435. int outboxcode1 = int.Parse(boxcode == "" ? "1" : boxcode);
  436. boxcode = adh.getFieldDataByCondition("prodiobarcode", "max(pib_outboxcode2)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  437. int outboxcode2 = int.Parse(boxcode == "" ? "1" : boxcode);
  438. string pd_id = LabelInf.Rows[CurrentRowIndex].Cells["pd_id"].Value.ToString();
  439. //如果满容量获取过箱号就不再重复获取了
  440. bool GetBarcode = false;
  441. //超过中盒容量中盒号+1
  442. if (adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + outboxcode1) >= MidBoxCapacity.Value)
  443. {
  444. outboxcode1 = outboxcode1 + 1;
  445. GetBarcode = true;
  446. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
  447. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray);
  448. }
  449. //获取当前的行号
  450. int CurrentRowNum = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["rownum"].Value.ToString());
  451. //获取上一行的数据
  452. DataTable LastRowData = null;
  453. if (CurrentRowNum - 1 > 0)
  454. {
  455. LastRowData = (DataTable)adh.ExecuteSql("select pib_lotno,pib_custmidboxcode,pib_custoutboxcode,pd_pocode,pd_custprodcode,pd_custprodspec,pib_datecode from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and rownum=" + (CurrentRowNum - 1), "select");
  456. //或者不符合合并条件中盒号+1
  457. if (cu_print_midlotno.Checked)
  458. {
  459. if (LastRowData.Rows[0]["pib_lotno"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString() && !GetBarcode)
  460. {
  461. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
  462. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray);
  463. LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
  464. outboxcode1 = outboxcode1 + 1;
  465. }
  466. }
  467. else if (cu_print_midpo.Checked)
  468. {
  469. if (LastRowData.Rows[0]["pd_pocode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString() && !GetBarcode)
  470. {
  471. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
  472. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray);
  473. LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
  474. outboxcode1 = outboxcode1 + 1;
  475. }
  476. }
  477. else if (cu_print_midprod.Checked)
  478. {
  479. if (LastRowData.Rows[0]["pd_custprodcode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString() && !GetBarcode)
  480. {
  481. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
  482. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray);
  483. LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
  484. outboxcode1 = outboxcode1 + 1;
  485. }
  486. }
  487. else if (cu_print_midspec.Checked)
  488. {
  489. if (LastRowData.Rows[0]["pd_custprodspec"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodspec"].Value.ToString() && !GetBarcode)
  490. {
  491. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
  492. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray);
  493. LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
  494. outboxcode1 = outboxcode1 + 1;
  495. }
  496. }
  497. else if (cu_print_middc.Checked)
  498. {
  499. if (LastRowData.Rows[0]["pib_datecode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString() && !GetBarcode)
  500. {
  501. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
  502. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray);
  503. LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
  504. outboxcode1 = outboxcode1 + 1;
  505. }
  506. }
  507. if (LastRowData.Rows[0]["pib_custmidboxcode"].ToString() == MidBoxBarCode)
  508. LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = LastRowData.Rows[0]["pib_custmidboxcode"].ToString();
  509. else
  510. LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
  511. }
  512. else
  513. {
  514. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
  515. LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
  516. }
  517. GetBarcode = false;
  518. if (adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2=" + outboxcode2) >= OutBoxCapacity.Value)
  519. {
  520. GetBarcode = true;
  521. outboxcode2 = outboxcode2 + 1;
  522. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
  523. LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
  524. }
  525. else if (CurrentRowNum - 1 > 0)
  526. {
  527. //或者不符合合并条件中盒号+1
  528. if (cu_print_outlotno.Checked)
  529. {
  530. if (LastRowData.Rows[0]["pib_lotno"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString() && !GetBarcode)
  531. {
  532. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
  533. LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
  534. }
  535. }
  536. else if (cu_print_outpo.Checked)
  537. {
  538. if (LastRowData.Rows[0]["pd_pocode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString() && !GetBarcode)
  539. {
  540. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
  541. LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
  542. }
  543. }
  544. else if (cu_print_outprod.Checked)
  545. {
  546. if (LastRowData.Rows[0]["pd_custprodcode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString() && !GetBarcode)
  547. {
  548. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
  549. LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
  550. }
  551. }
  552. else if (cu_print_outspec.Checked)
  553. {
  554. if (LastRowData.Rows[0]["pd_custprodspec"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodspec"].Value.ToString() && !GetBarcode)
  555. {
  556. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
  557. LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
  558. }
  559. }
  560. else if (cu_print_outdc.Checked)
  561. {
  562. if (LastRowData.Rows[0]["pib_datecode"].ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString() && !GetBarcode)
  563. {
  564. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
  565. LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
  566. }
  567. }
  568. if (OutBoxBarCode == LastRowData.Rows[0]["pib_custoutboxcode"].ToString())
  569. LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = LastRowData.Rows[0]["pib_custoutboxcode"].ToString();
  570. else
  571. LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
  572. }
  573. else
  574. {
  575. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
  576. LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
  577. }
  578. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value = outboxcode1;
  579. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = outboxcode2;
  580. string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
  581. adh.ExecuteSql("update prodiobarcode set pib_outboxcode2=" + outboxcode2 + ",pib_outboxcode1=" + outboxcode1 + ",pib_custoutboxcode='" + OutBoxBarCode + "',pib_custmidboxcode='" + MidBoxBarCode + "',pib_lotno='" + LotNo + "',pib_datecode='" + DateCode + "',pib_ifpick=-1,pib_ifmodify=-1 where pib_id=" + pib_id, "update");
  582. LabelInf.Refresh();
  583. return true;
  584. }
  585. }
  586. //外箱条码号
  587. string OutBoxBarCode = "";
  588. //中盒条码号
  589. string MidBoxBarCode = "";
  590. private bool BackendCheckFunction(string msg, string pib_id, out string ErrorMsg)
  591. {
  592. ErrorMsg = "";
  593. DataTable dtt = LabelInf.DataSource as DataTable;
  594. string[] msgArr = msg.Split(back_sg_separator.Text.ToCharArray());
  595. //需要校验2项数据,完成校验后此项的值需要为2则表示校验成功
  596. int checkItemCount = 0;
  597. List<string> CheckItem = new List<string>();
  598. int GroupCount = 0;
  599. for (int i = 0; i < msgArr.Length; i++)
  600. {
  601. if (RecheckCuprodcode.Checked)
  602. {
  603. if (!CheckItem.Contains("客户料号") && !CheckItem.Contains("原厂型号"))
  604. {
  605. CheckItem.Add("客户料号");
  606. CheckItem.Add("原厂型号");
  607. }
  608. //直接验证两个值相等
  609. if (Equal.Checked)
  610. {
  611. if (msgArr[i] == LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString())
  612. {
  613. CheckItem.Remove("客户料号");
  614. checkItemCount = checkItemCount + 1;
  615. }
  616. }
  617. //验证正则匹配过之后相等
  618. else if (Expression.Checked)
  619. {
  620. Regex re = new Regex(cu_print_regexpression.Text);
  621. if (re.Match(msgArr[i]).Value == LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString())
  622. {
  623. CheckItem.Remove("客户料号");
  624. checkItemCount = checkItemCount + 1;
  625. }
  626. }
  627. if (RegexMatch("BackCheck", msgArr[i], out ErrorMsg, out GroupCount))
  628. {
  629. CheckItem.Remove("原厂型号");
  630. checkItemCount = checkItemCount + 1;
  631. }
  632. }
  633. else if (RecheckBarcode.Checked)
  634. {
  635. if (!CheckItem.Contains("唯一条码") && !CheckItem.Contains("原厂型号"))
  636. {
  637. CheckItem.Add("唯一条码");
  638. CheckItem.Add("原厂型号");
  639. }
  640. if (msgArr[i] == LabelInf.Rows[CurrentRowIndex].Cells["pib_custbarcode"].Value.ToString())
  641. {
  642. CheckItem.Remove("唯一条码");
  643. checkItemCount = checkItemCount + 1;
  644. }
  645. if (RegexMatch("BackCheck", msgArr[i], out ErrorMsg, out GroupCount))
  646. {
  647. CheckItem.Remove("原厂型号");
  648. checkItemCount = checkItemCount + 1;
  649. }
  650. }
  651. }
  652. if (checkItemCount != 2)
  653. {
  654. string Item = "";
  655. for (int i = 0; i < CheckItem.Count; i++)
  656. {
  657. Item += CheckItem[i].ToString() + " ";
  658. }
  659. ErrorMsg = Item + "复核不通过";
  660. return false;
  661. }
  662. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifrecheck"].Value = true;
  663. adh.ExecuteSql("update prodiobarcode set pib_ifrecheck=-1 where pib_id=" + pib_id, "update");
  664. LabelInf.Refresh();
  665. if (CurrentRowIndex + 1 < LabelInf.Rows.Count)
  666. CurrentRowIndex = CurrentRowIndex + 1;
  667. RefreshProcessData();
  668. if (CurrentRowIndex - 10 > 0)
  669. LabelInf.FirstDisplayedScrollingRowIndex = CurrentRowIndex - 5;
  670. //如果成功上传了数据
  671. if (LogicHandler.CheckUploadData(pi_inoutno.Text, UploadNum))
  672. {
  673. for (int i = 0; i < dtt.Rows.Count; i++)
  674. {
  675. if (dtt.Rows[i]["pib_ifrecheck"].ToString() != "0" && dtt.Rows[i]["pib_ifupload"].ToString() == "0")
  676. {
  677. dtt.Rows[i]["pib_ifupload"] = -1;
  678. }
  679. }
  680. }
  681. return true;
  682. }
  683. //只执行一次窗体自适应
  684. bool AutoSized = false;
  685. private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
  686. {
  687. if (!AutoSized)
  688. {
  689. asc.controlAutoSize(this);
  690. AutoSized = true;
  691. }
  692. }
  693. private void LabelMaintain_Click(object sender, EventArgs e)
  694. {
  695. 客户标签维护 form = new 客户标签维护();
  696. BaseUtil.SetFormCenter(form);
  697. if (SingleDoc != null)
  698. SingleDoc.Close();
  699. if (MidDoc != null)
  700. MidDoc.Close();
  701. if (OutBoxDoc != null)
  702. OutBoxDoc.Close();
  703. form.FormClosed += LabelFormClose;
  704. form.ShowDialog();
  705. }
  706. private void LabelFormClose(object sender, EventArgs e)
  707. {
  708. if (GetGridOnly.Checked)
  709. GetInOutInfAndLabelFile();
  710. else
  711. {
  712. GetGridOnly.Checked = true;
  713. GetInOutInfAndLabelFile();
  714. GetGridOnly.Checked = false;
  715. }
  716. }
  717. private void AutoPrintSingleLabel()
  718. {
  719. //用标签本身的变量作为最外层的循环条件去匹配;
  720. string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
  721. sql.Clear();
  722. for (int i = 0; i < SingleDoc.Variables.FreeVariables.Count; i++)
  723. {
  724. DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower() + "'");
  725. if (dr1.Length > 0)
  726. {
  727. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  728. }
  729. }
  730. DataTable dt = (DataTable)adh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_id=" + pib_id, "select");
  731. for (int i = 0; i < SingleDoc.Variables.FreeVariables.Count; i++)
  732. {
  733. DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower() + "'");
  734. if (dr1.Length > 0)
  735. {
  736. SingleDoc.Variables.FreeVariables.Item(i + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  737. }
  738. if (SingleDoc.Variables.FreeVariables.Item(i + 1).Value == "")
  739. {
  740. dr1 = Attach.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower() + "'");
  741. if (dr1.Length > 0)
  742. SingleDoc.Variables.FreeVariables.Item(i + 1).Value = dr1[0]["lp_sql"].ToString();
  743. }
  744. }
  745. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  746. SingleDoc.PrintDocument();
  747. LogicHandler.UpdateRowPrinted(pib_id);
  748. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifprint"].Value = true;
  749. }
  750. //关闭窗口前提示用户确认
  751. private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
  752. {
  753. //如果不是注销的话
  754. if (!logout)
  755. {
  756. string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  757. if (close.ToString() != "Yes")
  758. e.Cancel = true;
  759. else
  760. {
  761. lbl.Quit();
  762. LogManager.DoLog("关闭程序");
  763. }
  764. }
  765. }
  766. /// <summary>
  767. /// 获取打印标签
  768. /// </summary>
  769. private void GetInOutInfAndLabelFile()
  770. {
  771. ComBoxClickChangeLabelDoc = false;
  772. Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LabelAttachPARAMETER where lap_custcode='" + pi_cardcode.Text + "'", "select");
  773. sql.Clear();
  774. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  775. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  776. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='单盘' order by cl_custcode");
  777. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  778. SingleLabelCombox.DisplayMember = "cl_labelname";
  779. SingleLabelCombox.ValueMember = "la_id";
  780. SingleLabelCombox.DataSource = dt;
  781. if (SingleDoc != null)
  782. SingleDoc.Close();
  783. if (!GetGridOnly.Checked)
  784. for (int i = 0; i < dt.Rows.Count; i++)
  785. {
  786. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  787. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  788. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  789. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  790. if (time.ToString() != file.LastWriteTime.ToString())
  791. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  792. }
  793. if (SingleLabelCombox.Text != "")
  794. {
  795. SingleDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + SingleLabelCombox.Text);
  796. SingleLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + SingleLabelCombox.SelectedValue.ToString().Split('#')[0], "select");
  797. }
  798. sql.Clear();
  799. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  800. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  801. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='中盒' order by cl_custcode");
  802. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  803. MidLabelCombox.DisplayMember = "cl_labelname";
  804. MidLabelCombox.ValueMember = "la_id";
  805. MidLabelCombox.DataSource = dt;
  806. if (MidDoc != null)
  807. MidDoc.Close();
  808. if (!GetGridOnly.Checked)
  809. for (int i = 0; i < dt.Rows.Count; i++)
  810. {
  811. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  812. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  813. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  814. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  815. if (time.ToString() != file.LastWriteTime.ToString())
  816. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  817. }
  818. if (MidLabelCombox.Text != "")
  819. {
  820. MidDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + MidLabelCombox.Text);
  821. MidLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + MidLabelCombox.SelectedValue.ToString().Split('#')[0], "select");
  822. }
  823. //缓存中盒参数
  824. sql.Clear();
  825. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  826. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  827. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='外箱' order by cl_custcode");
  828. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  829. OutBoxCombox.DisplayMember = "cl_labelname";
  830. OutBoxCombox.ValueMember = "la_id";
  831. OutBoxCombox.DataSource = dt;
  832. if (OutBoxDoc != null)
  833. OutBoxDoc.Close();
  834. if (!GetGridOnly.Checked)
  835. for (int i = 0; i < dt.Rows.Count; i++)
  836. {
  837. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  838. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  839. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  840. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  841. if (time.ToString() != file.LastWriteTime.ToString())
  842. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  843. }
  844. if (OutBoxCombox.Text != "")
  845. {
  846. OutBoxDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + OutBoxCombox.Text);
  847. OutLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + OutBoxCombox.SelectedValue.ToString().Split('#')[0], "select");
  848. }
  849. //缓存外箱参数
  850. ComBoxClickChangeLabelDoc = true;
  851. }
  852. /// <summary>
  853. /// 出入库单录入框的回车事件
  854. /// </summary>
  855. /// <param name="sender"></param>
  856. /// <param name="e"></param>
  857. private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
  858. {
  859. if (e.KeyCode == Keys.Enter)
  860. {
  861. CurrentPage = 1;
  862. sql.Clear();
  863. sql.Append("select pi_id,pi_cardcode,to_char(pi_date,'yyyymmdd')pi_date from prodinout where pi_inoutno='" + pi_inoutno.Text + "'");
  864. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  865. if (dt.Rows.Count > 0)
  866. {
  867. pi_cardcode.Text = dt.Rows[0]["pi_cardcode"].ToString();
  868. pi_date.Text = dt.Rows[0]["pi_date"].ToString();
  869. PI_ID = dt.Rows[0]["pi_id"].ToString();
  870. //if (dh.GetConfig("AutoBarcode", "ProdInOut!Sale").ToString() != "")
  871. //{
  872. string[] param = new string[] { PI_ID, "" };
  873. dh.CallProcedure("GetCustBarcode", ref param);
  874. //}
  875. //获取客户自定义设置
  876. sql.Clear();
  877. sql.Append("select cu_print_middc,cu_print_outdc,cu_print_midlotno,nvl(cu_print_custprodmatchmodel,'Equal')cu_print_custprodmatchmodel,cu_print_midspec,cu_print_midpo,cu_print_midprod,cu_print_outlotno,cu_print_outspec,cu_print_outpo");
  878. sql.Append(",cu_print_outprod,cu_print_checkonly,nvl(cu_print_papercount,0)cu_print_papercount,cu_print_regexpression,cu_print_recheck from customer where cu_code='" + pi_cardcode.Text + "'");
  879. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  880. if (dt.Rows.Count > 0)
  881. {
  882. BaseUtil.SetFormValue(this.Controls, dt);
  883. switch (dt.Rows[0]["cu_print_custprodmatchmodel"].ToString())
  884. {
  885. case "Equal":
  886. Equal.Checked = true;
  887. break;
  888. case "Expression":
  889. Expression.Checked = true;
  890. break;
  891. default:
  892. Equal.Checked = true;
  893. break;
  894. }
  895. switch (dt.Rows[0]["cu_print_recheck"].ToString())
  896. {
  897. case "CP":
  898. RecheckCuprodcode.Checked = true;
  899. break;
  900. case "BR":
  901. RecheckBarcode.Checked = true;
  902. break;
  903. default:
  904. RecheckCuprodcode.Checked = true;
  905. break;
  906. }
  907. }
  908. //查询所有的采集策略
  909. sql.Clear();
  910. sql.Append("select sg_id,sg_brand,si_item ,sg_script,max(si_expression)si_expression,instr(sg_name,si_name)itemindex,sg_name,si_name,sg_step from prodiodetail left join ");
  911. sql.Append("product on pd_prodcode=pr_code left join scangroup on nvl(pd_brand,pr_brand) =sg_brand left join scanitem on sg_id=si_sgid ");
  912. sql.Append("where pd_inoutno='" + pi_inoutno.Text + "' and si_enable=-1 group by sg_id,sg_script,sg_brand,si_item,sg_name,si_name,sg_step order by sg_step,itemindex ");
  913. ScanItem = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  914. sql.Clear();
  915. sql.Append("select distinct sg_brand from prodiodetail left join product on pd_prodcode=pr_code left join scangroup ");
  916. sql.Append("on nvl(pd_brand,pr_brand)=sg_brand where pd_inoutno='" + pi_inoutno.Text + "' and sg_brand is not null");
  917. DataTable dt1 = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  918. FrontCombo.DataSource = dt1;
  919. FrontCombo.DisplayMember = "sg_brand";
  920. FrontCombo.ValueMember = "sg_brand";
  921. BackCombo.DataSource = dt1;
  922. BackCombo.DisplayMember = "sg_brand";
  923. BackCombo.ValueMember = "sg_brand";
  924. LoadGridData();
  925. //重新输入单号后清除缓存
  926. MidBoxArgument.Clear();
  927. SingleBoxArgument.Clear();
  928. MidIDAndOutboxcode.Clear();
  929. SingleID.Clear();
  930. //刷新采集进度
  931. RefreshProcessData();
  932. thread = new Thread(GetInOutInfAndLabelFile);
  933. stw = new SetLoadingWindow(thread, "正在获取打印标签");
  934. BaseUtil.SetFormCenter(stw);
  935. stw.ShowDialog();
  936. LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
  937. }
  938. else
  939. MessageBox.Show("当前出入库单号不存在!");
  940. }
  941. }
  942. private void SingleBoxPrint()
  943. {
  944. try
  945. {
  946. if (SingleDoc.Variables.FreeVariables.Count == 0) { }
  947. }
  948. catch (Exception)
  949. {
  950. MessageBox.Show("单盘标签未维护参数");
  951. }
  952. if (MidLabelAutoPrint.Checked)
  953. {
  954. try
  955. {
  956. if (MidDoc.Variables.FreeVariables.Count == 0) { }
  957. }
  958. catch (Exception)
  959. {
  960. MessageBox.Show("中盘标签未维护参数");
  961. }
  962. }
  963. if (SingleLabelParam.Rows.Count > 0 && LabelInf.Rows.Count > 0)
  964. {
  965. //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
  966. MidIDAndOutboxcode.Clear();
  967. SingleID.Clear();
  968. //获取全部的中盒号
  969. Dictionary<string, bool> outboxcode1 = new Dictionary<string, bool>();
  970. //判断所有盒号为该盒的是否勾选已采集
  971. outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true);
  972. for (int i = 0; i < LabelInf.Rows.Count; i++)
  973. {
  974. if (!SingleID.Contains(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()))
  975. SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  976. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() != "True")
  977. {
  978. //如果不存在中盒号则进行添加
  979. if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))
  980. {
  981. MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString());
  982. }
  983. }
  984. }
  985. if (SingleID.ToArray().Length == 0)
  986. {
  987. MessageBox.Show("选择的行未勾选采集或者已打印");
  988. return;
  989. }
  990. for (int i = 0; i < LabelInf.RowCount; i++)
  991. {
  992. if (i + 1 < LabelInf.RowCount)
  993. {
  994. //如果本行的中盒号和下一行不相等的话
  995. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString())
  996. {
  997. if (!outboxcode1.ContainsKey(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
  998. outboxcode1.Add(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString(), true);
  999. }
  1000. }
  1001. //只要有一行没有采集满就不打印
  1002. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  1003. {
  1004. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1005. outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()] = false;
  1006. }
  1007. }
  1008. //用于判断用户是否勾选了行
  1009. int CheckedRowCount = 0;
  1010. for (int i = 0; i < LabelInf.RowCount; i++)
  1011. {
  1012. //勾选了并且未打印
  1013. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() != "True")
  1014. {
  1015. CheckedRowCount = CheckedRowCount + 1;
  1016. CurrentRowIndex = i;
  1017. //以标签模板的参数为基准,循环取数
  1018. try
  1019. {
  1020. string pib_id = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
  1021. sql.Clear();
  1022. for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++)
  1023. {
  1024. DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
  1025. if (dr1.Length > 0)
  1026. {
  1027. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  1028. }
  1029. }
  1030. DataTable dt = (DataTable)adh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_id=" + pib_id, "select");
  1031. for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++)
  1032. {
  1033. DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
  1034. if (dr1.Length > 0)
  1035. {
  1036. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  1037. }
  1038. if (SingleDoc.Variables.FreeVariables.Item(j + 1).Value == "")
  1039. {
  1040. dr1 = Attach.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
  1041. if (dr1.Length > 0)
  1042. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
  1043. }
  1044. }
  1045. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  1046. SingleDoc.PrintDocument();
  1047. LogicHandler.UpdateRowPrinted(pib_id);
  1048. if (MidLabelAutoPrint.Checked)
  1049. {
  1050. //判断当前行的盒号和下一行不相等或者已经是最后一行了
  1051. if (i + 1 == LabelInf.RowCount || LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1 == LabelInf.RowCount ? i : i + 1].Cells["pib_outboxcode1"].Value.ToString())
  1052. {
  1053. if (outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()])
  1054. {
  1055. if (MidLabelCombox.SelectedValue != null)
  1056. {
  1057. MidBoxCodePrint(CurrentRowIndex);
  1058. }
  1059. }
  1060. }
  1061. }
  1062. //勾选为已打印
  1063. LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
  1064. }
  1065. catch (Exception ex) { LogManager.DoLog(ex.Message); }
  1066. }
  1067. }
  1068. dh.BatchInsert("update prodiobarcode set pib_printdate=sysdate where pib_id=:pib_id", new string[] { "pib_id" }, SingleID.ToArray());
  1069. if (CheckedRowCount == 0)
  1070. MessageBox.Show("未勾选打印明细!");
  1071. else if (CurrentRowIndex + 1 < LabelInf.Rows.Count)
  1072. CurrentRowIndex = CurrentRowIndex + 1;
  1073. outboxcode1.Clear();
  1074. }
  1075. else
  1076. {
  1077. MessageBox.Show("此模板尚未维护参数或不存在打印明细");
  1078. return;
  1079. }
  1080. }
  1081. private void SingleLabelPrint_Click(object sender, EventArgs e)
  1082. {
  1083. if (SingleLabelCombox.Text != "")
  1084. {
  1085. if (SingleBoxBegin.Text != "" || SingleBoxEnd.Text != "")
  1086. {
  1087. try
  1088. {
  1089. int begin = int.Parse(SingleBoxBegin.Text == "" ? "1" : SingleBoxBegin.Text);
  1090. int end = int.Parse(SingleBoxEnd.Text == "" ? LabelInf.Rows.Count.ToString() : SingleBoxEnd.Text);
  1091. if (begin > 0 && end <= LabelInf.Rows.Count && begin <= end)
  1092. {
  1093. for (int i = begin - 1; i < end; i++)
  1094. {
  1095. LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
  1096. LabelInf.Rows[i].Cells["pib_ifprint"].Value = false;
  1097. }
  1098. }
  1099. else
  1100. {
  1101. MessageBox.Show("单盘打印范围错误");
  1102. return;
  1103. }
  1104. }
  1105. catch (Exception)
  1106. {
  1107. MessageBox.Show("单盘打印范围错误");
  1108. return;
  1109. }
  1110. }
  1111. thread = new Thread(SingleBoxPrint);
  1112. stw = new SetLoadingWindow(thread, "正在打印单盘");
  1113. BaseUtil.SetFormCenter(stw);
  1114. stw.ShowDialog();
  1115. }
  1116. else
  1117. MessageBox.Show("未维护单盘标签");
  1118. }
  1119. private void MidBoxLabelPrint()
  1120. {
  1121. //未输入内容打印全部中盒
  1122. if (MidLabelNum.Text == "")
  1123. {
  1124. int begin = 0;
  1125. int end = 0;
  1126. if (MidBoxBegin.Text != "" || MidBoxEnd.Text != "")
  1127. {
  1128. try
  1129. {
  1130. begin = int.Parse(MidBoxBegin.Text == "" ? "1" : MidBoxBegin.Text);
  1131. end = int.Parse(MidBoxEnd.Text == "" ? LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString() : MidBoxEnd.Text);
  1132. int minmidbox = int.Parse(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString());
  1133. int maxmidbox = int.Parse(LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString());
  1134. if (begin >= minmidbox && end <= maxmidbox && begin <= end)
  1135. {
  1136. //设置中盒打印范围的行号
  1137. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1138. {
  1139. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == begin)
  1140. {
  1141. begin = i;
  1142. }
  1143. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == end)
  1144. {
  1145. end = i;
  1146. }
  1147. }
  1148. }
  1149. else
  1150. {
  1151. MessageBox.Show("中盒打印范围错误");
  1152. return;
  1153. }
  1154. }
  1155. catch (Exception)
  1156. {
  1157. MessageBox.Show("中盒打印范围错误");
  1158. return;
  1159. }
  1160. }
  1161. MidBoxArgument.Clear();
  1162. List<int> MidOutBoxCode = new List<int>();
  1163. List<int> MidOutBoxCodeIndex = new List<int>();
  1164. string la_id = MidLabelCombox.SelectedValue.ToString().Split('#')[0];
  1165. for (int i = (begin == 0 ? 0 : begin); i <= (end == 0 ? LabelInf.Rows.Count - 1 : end); i++)
  1166. {
  1167. if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))
  1168. MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString());
  1169. string outboxcode1 = LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString();
  1170. if (!MidOutBoxCode.Contains(int.Parse(outboxcode1 == "" ? "0" : outboxcode1)))
  1171. {
  1172. MidOutBoxCode.Add(int.Parse(outboxcode1 == "" ? "0" : outboxcode1));
  1173. MidOutBoxCodeIndex.Add(i);
  1174. }
  1175. }
  1176. for (int i = 0; i < MidOutBoxCodeIndex.Count; i++)
  1177. {
  1178. MidBoxCodePrint(MidOutBoxCodeIndex[i]);
  1179. }
  1180. MidBoxArgument.Clear();
  1181. return;
  1182. }
  1183. bool FindMidLabel = false;
  1184. if (MidLabelCombox.SelectedValue != null)
  1185. {
  1186. //中盒号所在的行
  1187. int MidLabelRowIndex = 0;
  1188. //缓存中盒数据
  1189. for (int i = 0; i < LabelInf.RowCount; i++)
  1190. {
  1191. if (MidLabelNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1192. {
  1193. //找到了输入的中盒号停止循环
  1194. FindMidLabel = true;
  1195. MidLabelRowIndex = i;
  1196. }
  1197. }
  1198. //找到了指定的盒号
  1199. if (FindMidLabel)
  1200. MidBoxCodePrint(MidLabelRowIndex);
  1201. else
  1202. MessageBox.Show("该出入库单未找到该中盒号!");
  1203. }
  1204. else
  1205. MessageBox.Show("未维护中盒模板");
  1206. }
  1207. private void MidLabelPrint_Click(object sender, EventArgs e)
  1208. {
  1209. if (MidLabelCombox.Text != "")
  1210. {
  1211. thread = new Thread(MidBoxLabelPrint);
  1212. stw = new SetLoadingWindow(thread, "正在打印中盒");
  1213. BaseUtil.SetFormCenter(stw);
  1214. stw.ShowDialog();
  1215. }
  1216. else
  1217. MessageBox.Show("未维护中盒标签");
  1218. }
  1219. private void OutBoxPrint()
  1220. {
  1221. List<string> Outboxcode = new List<string>();
  1222. //如果未勾选箱号则对勾选的数据的箱号进行整合
  1223. if (OutBoxNum.Text == "")
  1224. {
  1225. for (int i = 0; i < LabelInf.RowCount; i++)
  1226. {
  1227. string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  1228. //如果不包含该箱号则进行添加
  1229. if (!Outboxcode.Contains(outboxcode2))
  1230. Outboxcode.Add(outboxcode2);
  1231. }
  1232. //按获取到的箱号列表进行打印
  1233. if (Outboxcode.ToArray().Length > 0)
  1234. {
  1235. try
  1236. {
  1237. // 循环打印外箱号
  1238. for (int i = 0; i < Outboxcode.ToArray().Length; i++)
  1239. {
  1240. for (int h = 0; h < LabelInf.RowCount; h++)
  1241. {
  1242. if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i])
  1243. {
  1244. OutBoxCodePrint(h);
  1245. break;
  1246. }
  1247. }
  1248. }
  1249. }
  1250. catch { }
  1251. }
  1252. else
  1253. {
  1254. MessageBox.Show("请勾选需要打印的外箱");
  1255. }
  1256. }
  1257. else
  1258. {
  1259. bool FindMidLabel = false;
  1260. try
  1261. {
  1262. int OutBoxLabelRowIndex = 0;
  1263. //查找是否存在该中盒号
  1264. for (int i = 0; i < LabelInf.RowCount; i++)
  1265. {
  1266. if (OutBoxNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString())
  1267. {
  1268. //找到了输入的中盒号停止循环
  1269. FindMidLabel = true;
  1270. OutBoxLabelRowIndex = i;
  1271. break;
  1272. }
  1273. }
  1274. //找到了指定的盒号
  1275. if (FindMidLabel)
  1276. OutBoxCodePrint(OutBoxLabelRowIndex);
  1277. else
  1278. MessageBox.Show("该出入库单未找到该外箱号!");
  1279. }
  1280. catch (Exception) { }
  1281. }
  1282. Outboxcode.Clear();
  1283. }
  1284. private void MidBoxCodePrint(int rowindex)
  1285. {
  1286. //获取对应行的pib_id
  1287. string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
  1288. string pib_outboxcode1 = LabelInf.Rows[rowindex].Cells["pib_outboxcode1"].Value.ToString();
  1289. sql.Clear();
  1290. //设置最少打印盘数
  1291. if (OnlyPrint.Checked)
  1292. {
  1293. if (adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + pib_outboxcode1) < LeastPrintNum.Value)
  1294. {
  1295. return;
  1296. }
  1297. }
  1298. for (int j = 0; j < MidDoc.Variables.FreeVariables.Count; j++)
  1299. {
  1300. DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
  1301. if (dr1.Length > 0)
  1302. {
  1303. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  1304. }
  1305. }
  1306. DataTable dt = (DataTable)adh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + (pib_outboxcode1 == "" ? "0" : pib_outboxcode1), "select");
  1307. for (int j = 0; j < MidDoc.Variables.FreeVariables.Count; j++)
  1308. {
  1309. DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
  1310. if (dr1.Length > 0)
  1311. {
  1312. MidDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  1313. }
  1314. if (MidDoc.Variables.FreeVariables.Item(j + 1).Value == "")
  1315. {
  1316. dr1 = Attach.Select("lp_name='" + MidDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
  1317. if (dr1.Length > 0)
  1318. MidDoc.Variables.FreeVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
  1319. }
  1320. }
  1321. MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
  1322. MidDoc.PrintDocument();
  1323. }
  1324. /// <summary>
  1325. /// 执行打印外箱号
  1326. /// </summary>
  1327. private void OutBoxCodePrint(int rowindex)
  1328. {
  1329. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray);
  1330. //获取对应行的pib_id
  1331. string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
  1332. string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
  1333. sql.Clear();
  1334. for (int j = 0; j < OutBoxDoc.Variables.FreeVariables.Count; j++)
  1335. {
  1336. DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
  1337. if (dr1.Length > 0)
  1338. {
  1339. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  1340. }
  1341. }
  1342. DataTable dt = (DataTable)adh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2=" + (pib_outboxcode2 == "" ? "0" : pib_outboxcode2), "select");
  1343. if (dt.Rows.Count > 0)
  1344. {
  1345. for (int j = 0; j < OutBoxDoc.Variables.FreeVariables.Count; j++)
  1346. {
  1347. DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
  1348. if (dr1.Length > 0)
  1349. {
  1350. OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  1351. }
  1352. if (OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value == "")
  1353. {
  1354. dr1 = Attach.Select("lp_name='" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
  1355. if (dr1.Length > 0)
  1356. OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
  1357. }
  1358. }
  1359. OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
  1360. OutBoxDoc.PrintDocument();
  1361. }
  1362. }
  1363. private void OutBoxLabelPrint_Click(object sender, EventArgs e)
  1364. {
  1365. if (OutBoxCombox.Text != "")
  1366. {
  1367. thread = new Thread(OutBoxPrint);
  1368. stw = new SetLoadingWindow(thread, "正在打印外箱");
  1369. BaseUtil.SetFormCenter(stw);
  1370. stw.ShowDialog();
  1371. }
  1372. else
  1373. MessageBox.Show("未维护外箱标签");
  1374. }
  1375. /// <summary>
  1376. /// 刷新采集进度
  1377. /// </summary>
  1378. private void RefreshProcessData()
  1379. {
  1380. if (LabelInf.Rows.Count > 0)
  1381. {
  1382. //设置初始化的采集进度
  1383. int Count = Count = adh.getRowCount("prodiobarcode", "pib_ifrecheck=-1");
  1384. string midboxcode = "";
  1385. string outboxcode = "";
  1386. if (CurrentRowIndex - 1 >= 0)
  1387. {
  1388. outboxcode = LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_outboxcode2"].Value.ToString();
  1389. midboxcode = LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_outboxcode1"].Value.ToString();
  1390. }
  1391. //未超出当前范围的时候
  1392. int midboxcount = adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + (midboxcode == "" ? "0" : midboxcode));
  1393. int outboxcount = adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2=" + (outboxcode == "" ? "0" : outboxcode));
  1394. midboxProcess.Text = midboxcount + "/" + MidBoxCapacity.Value;
  1395. outboxProcess.Text = outboxcount + "/" + OutBoxCapacity.Value;
  1396. //设置当前的箱号和盒号
  1397. Process_midboxcode.Text = midboxcode;
  1398. Process_outboxcode.Text = outboxcode;
  1399. //设置当前总数和已采集数量
  1400. CollectedCount.Text = Count + "/" + PageNum.Text.Replace("总数", "");
  1401. }
  1402. }
  1403. private void LoadGridData()
  1404. {
  1405. LoadGridData(new object(), new EventArgs());
  1406. }
  1407. int CurrentPage = 1;
  1408. int PageSize = 500;
  1409. int DataSize = 0;
  1410. int MaxPageSize = 0;
  1411. /// <summary>
  1412. /// 自定义函数 加载明细行的数据,多处使用添加进函数
  1413. /// </summary>
  1414. /// <param name="sender"></param>
  1415. /// <param name="e"></param>
  1416. private void LoadGridData(object sender, EventArgs e)
  1417. {
  1418. sql.Clear();
  1419. sql.Append("select * from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and rownum ");
  1420. sql.Append("between " + ((CurrentPage - 1) * PageSize + 1) + " and " + CurrentPage * PageSize + " ");
  1421. if (DetailRange.Checked)
  1422. {
  1423. sql.Append(" and pib_pdno between " + DetailRange1.Value + " and " + DetailRange2.Value);
  1424. }
  1425. sql.Append(" order by rownum");
  1426. DataTable LabelInfDataTable = (DataTable)adh.ExecuteSql(sql.ToString(), "select");
  1427. if (LabelInfDataTable.Rows.Count == 0)
  1428. {
  1429. //嵌套查询重置RowNum
  1430. sql.Clear();
  1431. sql.Append("select t.*,rownum from (select pr_detail,pib_custoutboxcode,pib_custmidboxcode,pr_orispeccode,pd_id,pd_custprodcode,pib_indate,pi_date,pib_inoutno,pd_custprodspec,");
  1432. sql.Append("nvl(pib_ifrecheck,0)pib_ifrecheck,nvl(pib_ifupload,0)pib_ifupload,nvl(pib_ifmodify,0)pib_ifmodify,pd_pocode,pib_madein,pib_custbarcode,pib_id,pib_pdid,pib_piid,");
  1433. sql.Append("pib_pdno,pib_prodcode,nvl(nvl(pd_brand,pib_brand),pr_brand)pib_brand, pr_vendprodcode,pib_lotno,pib_datecode,pib_qty,pr_spec,pi_title,pr_zxbzs,pr_unit,pib_barcode,pib_outboxcode1,");
  1434. sql.Append("pib_outboxcode2,nvl(pib_ifpick,0)pib_ifpick,nvl(pib_ifprint,0)pib_ifprint from prodiobarcode left join prodinout on pib_piid=pi_id left join prodiodetail on pib_piid=pd_piid and ");
  1435. sql.Append("pd_pdno=pib_pdno and pd_prodcode=pib_prodcode left join product on pr_code=pib_prodcode left join sale on sa_code=pib_ordercode where pib_piid='" + PI_ID + "' order by to_number(pib_id))t");
  1436. LabelInfDataTable = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1437. //检验查询的字段和本地数据库字段是否匹配
  1438. adh.AddColumFromDataTable(LabelInfDataTable, "prodiobarcode");
  1439. //将数据保存在本地数据库
  1440. adh.SaveDataTable(LabelInfDataTable, "prodiobarcode");
  1441. if (!DetailRange.Checked)
  1442. {
  1443. LabelInfDataTable = BaseUtil.filterDataTable(LabelInfDataTable, "rownum <=" + PageSize);
  1444. }
  1445. else
  1446. {
  1447. LabelInfDataTable = BaseUtil.filterDataTable(LabelInfDataTable, "rownum <=" + PageSize + " and pib_pdno >= " + DetailRange1.Value + " and pib_pdno<=" + DetailRange2.Value);
  1448. }
  1449. }
  1450. bindingsource(LabelInf, LabelInfDataTable);
  1451. //LabelInf.DataSource = null;
  1452. BaseUtil.FillDgvWithDataTable(LabelInf, LabelInfDataTable);
  1453. //获取数据总条数
  1454. if (!DetailRange.Checked)
  1455. {
  1456. DataSize = adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "'");
  1457. }
  1458. else
  1459. {
  1460. DataSize = adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno between " + DetailRange1.Value + " and " + DetailRange2.Value);
  1461. }
  1462. PageNum.Text = "总数" + DataSize;
  1463. MaxPageSize = DataSize % PageSize == 0 ? DataSize / PageSize : (DataSize / PageSize) + 1;
  1464. PageInf.Text = CurrentPage + "/" + MaxPageSize;
  1465. //获取系统设置的上传数量,如参数异常则默认为100
  1466. dt = (DataTable)adh.ExecuteSql("select uploadnum,splitback,splitfront from dataextra", "select");
  1467. if (dt.Rows.Count > 0)
  1468. {
  1469. if (!int.TryParse(dt.Rows[0]["uploadnum"].ToString(), out UploadNum))
  1470. {
  1471. UploadNum = 100;
  1472. }
  1473. front_sg_separator.Text = dt.Rows[0]["splitfront"].ToString();
  1474. back_sg_separator.Text = dt.Rows[0]["splitback"].ToString();
  1475. }
  1476. //获取所有的匹配脚本
  1477. ScanGroup = (DataTable)dh.ExecuteSql("select distinct sg_brand,sg_id,sg_name,sg_script from prodiobarcode left join scangroup on pib_brand=sg_brand where pib_inoutno='" + pi_inoutno.Text + "' and sg_id is not null and nvl(sg_autolabel,0)=0", "select");
  1478. //绑定数据之后往下找到未采集的数据显示在当前采集的栏目
  1479. for (int i = 0; i < LabelInf.RowCount; i++)
  1480. {
  1481. if (LabelInf.Rows[i].Cells["pib_ifrecheck"].FormattedValue.ToString() != "True")
  1482. {
  1483. CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
  1484. break;
  1485. }
  1486. }
  1487. }
  1488. delegate void BindDataSource(DataGridView dgv, DataTable dt);//定义委托
  1489. void bindingsource(DataGridView dgv, DataTable dt)
  1490. {
  1491. if (dgv.InvokeRequired)
  1492. {
  1493. dgv.Invoke(new BindDataSource(bindingsource), new object[] { dgv, dt });
  1494. }
  1495. else
  1496. {
  1497. dgv.AutoGenerateColumns = false;
  1498. dgv.DataSource = dt;
  1499. }
  1500. }
  1501. /// <summary>
  1502. /// 重绘Cell的颜色
  1503. /// </summary>
  1504. /// <param name="sender"></param>
  1505. /// <param name="e"></param>
  1506. private void LabelInf_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  1507. {
  1508. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  1509. if (e.ColumnIndex > 0)
  1510. {
  1511. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_lotno" || LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
  1512. {
  1513. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1514. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
  1515. Rectangle border = e.CellBounds;
  1516. border.Width -= 1;
  1517. e.Graphics.DrawRectangle(Pens.White, border);
  1518. e.PaintContent(e.CellBounds);
  1519. e.Handled = true;
  1520. }
  1521. if (e.RowIndex >= 0)
  1522. {
  1523. if (LabelInf.Rows[e.RowIndex].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
  1524. {
  1525. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_lotno" || LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
  1526. {
  1527. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1528. e.Graphics.FillRectangle(Brushes.ForestGreen, e.CellBounds);
  1529. Rectangle border = e.CellBounds;
  1530. border.Width -= 1;
  1531. e.Graphics.DrawRectangle(Pens.Black, border);
  1532. e.PaintContent(e.CellBounds);
  1533. e.Handled = true;
  1534. }
  1535. }
  1536. if (LabelInf.Rows[e.RowIndex].Cells["pib_ifrecheck"].FormattedValue.ToString() == "True")
  1537. {
  1538. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_custbarcode")
  1539. {
  1540. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1541. e.Graphics.FillRectangle(Brushes.CadetBlue, e.CellBounds);
  1542. Rectangle border = e.CellBounds;
  1543. border.Width -= 1;
  1544. e.Graphics.DrawRectangle(Pens.Black, border);
  1545. e.PaintContent(e.CellBounds);
  1546. e.Handled = true;
  1547. }
  1548. }
  1549. }
  1550. }
  1551. }
  1552. private void CusLabelPrint()
  1553. {
  1554. //MaxOutBoxCode = MaxOutBoxCode + 1;
  1555. List<int> CusOutBoxCode = new List<int>();
  1556. //统计客户外箱号
  1557. if (LabelInf.Rows.Count > 0)
  1558. CusOutBoxCode.Add(0);
  1559. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1560. {
  1561. if (i - 1 > 0 && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() == "True")
  1562. {
  1563. string cutboxcode = LabelInf.Rows[i].Cells["pib_cusoutboxcode"].Value.ToString();
  1564. string nextcutboxcode = LabelInf.Rows[i - 1].Cells["pib_cusoutboxcode"].Value.ToString();
  1565. if (cutboxcode != nextcutboxcode)
  1566. CusOutBoxCode.Add(i);
  1567. }
  1568. }
  1569. }
  1570. private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1571. {
  1572. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  1573. pi_inoutno_KeyDown(sender, e2);
  1574. }
  1575. private void AutoPrintMidLabel()
  1576. {
  1577. if (adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value) == MidBoxCapacity.Value)
  1578. {
  1579. if (MidLabelCombox.SelectedValue != null)
  1580. {
  1581. MidBoxCodePrint(CurrentRowIndex);
  1582. }
  1583. else
  1584. MessageBox.Show("未维护中盒模板");
  1585. }
  1586. }
  1587. private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1588. {
  1589. string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1590. if (close.ToString() == "Yes")
  1591. {
  1592. Login login = new Login();
  1593. //注销的时候需要将拼接的连接字符串置空
  1594. DataHelper.DBConnectionString = null;
  1595. logout = true;
  1596. lbl.Quit();
  1597. this.Hide();
  1598. login.ShowDialog();
  1599. this.Close();
  1600. }
  1601. }
  1602. private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1603. /// <summary>
  1604. /// 切换打开的单盘文件
  1605. /// </summary>
  1606. /// <param name="sender"></param>
  1607. /// <param name="e"></param>
  1608. private void SingleLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1609. {
  1610. try
  1611. {
  1612. if (ComBoxClickChangeLabelDoc)
  1613. {
  1614. if (SingleDoc != null)
  1615. SingleDoc.Close();
  1616. if (SingleLabelCombox.Text != "" && SingleLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  1617. {
  1618. System.DateTime time = Convert.ToDateTime(SingleLabelCombox.SelectedValue.ToString().Split('#')[2]);
  1619. SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
  1620. }
  1621. }
  1622. }
  1623. catch (Exception) { }
  1624. }
  1625. /// <summary>
  1626. /// 切换打开的中盒文件
  1627. /// </summary>
  1628. /// <param name="sender"></param>
  1629. /// <param name="e"></param>
  1630. private void MidLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1631. {
  1632. try
  1633. {
  1634. if (ComBoxClickChangeLabelDoc)
  1635. {
  1636. if (MidDoc != null)
  1637. MidDoc.Close();
  1638. if (MidLabelCombox.Text != "" && MidLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  1639. {
  1640. System.DateTime time = Convert.ToDateTime(MidLabelCombox.SelectedValue.ToString().Split('#')[2]);
  1641. MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
  1642. }
  1643. }
  1644. }
  1645. catch (Exception) { }
  1646. }
  1647. /// <summary>
  1648. /// 切换打开的外箱文件
  1649. /// </summary>
  1650. /// <param name="sender"></param>
  1651. /// <param name="e"></param>
  1652. private void OutBoxCombox_SelectedIndexChanged(object sender, EventArgs e)
  1653. {
  1654. try
  1655. {
  1656. if (ComBoxClickChangeLabelDoc)
  1657. {
  1658. if (OutBoxDoc != null)
  1659. OutBoxDoc.Close();
  1660. if (OutBoxCombox.Text != "" && OutBoxCombox.SelectedValue != null && !GetGridOnly.Checked)
  1661. {
  1662. System.DateTime time = Convert.ToDateTime(OutBoxCombox.SelectedValue.ToString().Split('#')[2]);
  1663. OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
  1664. }
  1665. }
  1666. }
  1667. catch (Exception) { }
  1668. }
  1669. private void ExportData_Click(object sender, EventArgs e)
  1670. {
  1671. ExportFileDialog.Description = "选择导出的路径";
  1672. DialogResult result = ExportFileDialog.ShowDialog();
  1673. if (result == DialogResult.OK)
  1674. {
  1675. ExcelHandler eh = new ExcelHandler();
  1676. for (int i = dt.Columns.Count - 1; i >= 0; i--)
  1677. {
  1678. for (int j = 0; j < LabelInf.Columns.Count; j++)
  1679. {
  1680. //去除ID列
  1681. if (dt.Columns[i].ColumnName.ToLower().Contains("id") || dt.Columns[i].ColumnName.ToLower() == "pib_barcode" || dt.Columns[i].ColumnName.ToLower() == "pib_pdno" || dt.Columns[i].ColumnName.ToLower() == "pib_ifpick" || dt.Columns[i].ColumnName.ToLower() == "pib_ifprint" || dt.Columns[i].ColumnName.ToLower() == "pib_datecode1" || dt.Columns[i].ColumnName.ToLower() == "pr_vendprodcode")
  1682. {
  1683. dt.Columns.RemoveAt(i);
  1684. break;
  1685. }
  1686. switch (dt.Columns[i].ColumnName.ToLower())
  1687. {
  1688. case "pib_lotno":
  1689. dt.Columns[i].ColumnName = "批次号";
  1690. break;
  1691. case "pib_datecode":
  1692. dt.Columns[i].ColumnName = "生产日期";
  1693. break;
  1694. case "pib_custbarcode":
  1695. dt.Columns[i].ColumnName = "最小产品包装条码";
  1696. break;
  1697. default:
  1698. break;
  1699. }
  1700. if (dt.Columns[i].ColumnName.ToLower() == LabelInf.Columns[j].DataPropertyName.ToLower())
  1701. {
  1702. dt.Columns[i].ColumnName = LabelInf.Columns[j].HeaderText;
  1703. break;
  1704. }
  1705. }
  1706. }
  1707. eh.ExportExcel(dt, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text);
  1708. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1709. if (close.ToString() == "Yes")
  1710. System.Diagnostics.Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + ".xls");
  1711. }
  1712. }
  1713. private void MidBoxCapacity_Leave(object sender, EventArgs e)
  1714. {
  1715. NumericUpDown nup = (NumericUpDown)sender;
  1716. switch (nup.Name)
  1717. {
  1718. case "MidBoxCapacity":
  1719. Properties.Settings.Default.MidBoxCapacity = nup.Value;
  1720. Properties.Settings.Default.Save();
  1721. break;
  1722. case "OutboxCapacity":
  1723. Properties.Settings.Default.OutboxCapacity = nup.Value;
  1724. Properties.Settings.Default.Save();
  1725. break;
  1726. default:
  1727. break;
  1728. }
  1729. }
  1730. private void RefreshDBConnect_Tick(object sender, EventArgs e)
  1731. {
  1732. dh.getRowCount("employee", "1=1");
  1733. }
  1734. private void ButtonSetting_Click(object sender, EventArgs e)
  1735. {
  1736. ListButtonMenu.BringToFront();
  1737. ListButtonMenu.Visible = true;
  1738. }
  1739. private void ListButtonMenu_SelectedIndexChanged(object sender, EventArgs e)
  1740. {
  1741. ListButtonMenu.Visible = false;
  1742. switch (ListButtonMenu.SelectedItem.ToString())
  1743. {
  1744. case "采集策略设置":
  1745. 采集策略_NEW form = new 采集策略_NEW();
  1746. BaseUtil.SetFormCenter(form);
  1747. form.ShowDialog();
  1748. break;
  1749. case "附加信息设置":
  1750. if (pi_cardcode.Text != "")
  1751. {
  1752. 附件内容打印 att = new 附件内容打印(pi_cardcode.Text);
  1753. att.ShowDialog();
  1754. }
  1755. else MessageBox.Show("请先获取出库单信息");
  1756. break;
  1757. case "客户标签维护":
  1758. 客户标签维护 form1 = new 客户标签维护();
  1759. BaseUtil.SetFormCenter(form1);
  1760. if (SingleDoc != null)
  1761. SingleDoc.Close();
  1762. if (MidDoc != null)
  1763. MidDoc.Close();
  1764. if (OutBoxDoc != null)
  1765. OutBoxDoc.Close();
  1766. form1.FormClosed += LabelFormClose;
  1767. form1.ShowDialog();
  1768. break;
  1769. case "客户采集规则":
  1770. CustomerRule cust = new CustomerRule();
  1771. BaseUtil.SetFormCenter(cust);
  1772. cust.ShowDialog();
  1773. break;
  1774. case "参数配置":
  1775. ParamSetting form2 = new ParamSetting();
  1776. form2.FormClosed += Form2_FormClosed;
  1777. BaseUtil.SetFormCenter(form2);
  1778. form2.ShowDialog();
  1779. break;
  1780. case "权限管理":
  1781. PowerSetting pws = new PowerSetting();
  1782. BaseUtil.SetFormCenter(pws);
  1783. pws.ShowDialog();
  1784. break;
  1785. default:
  1786. break;
  1787. }
  1788. }
  1789. private void Form2_FormClosed(object sender, FormClosedEventArgs e)
  1790. {
  1791. RefreshPLCInstruct();
  1792. }
  1793. private void DetailRange_CheckedChanged(object sender, EventArgs e)
  1794. {
  1795. if (DetailRange.Checked)
  1796. {
  1797. if (DetailRange1.Value > DetailRange2.Value)
  1798. {
  1799. MessageBox.Show("请输入正确的范围");
  1800. DetailRange.Checked = false;
  1801. return;
  1802. }
  1803. if (DetailRange1.Value == DetailRange2.Value)
  1804. {
  1805. if (dh.getRowCount("prodiodetail", "pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno in(" + DetailRange1.Value + ")") != 1)
  1806. {
  1807. MessageBox.Show("出货单" + pi_inoutno.Text + "不存在明细序号" + DetailRange1.Value);
  1808. DetailRange.Checked = false;
  1809. return;
  1810. }
  1811. }
  1812. else
  1813. {
  1814. if (dh.getRowCount("prodiodetail", "pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno in(" + DetailRange1.Value + "," + DetailRange2.Value + ")") != 2)
  1815. {
  1816. MessageBox.Show("出货单" + pi_inoutno.Text + "不存在明细序号" + DetailRange1.Value + "或" + DetailRange2.Value);
  1817. DetailRange.Checked = false;
  1818. return;
  1819. }
  1820. }
  1821. DetailRange1.Enabled = false;
  1822. DetailRange2.Enabled = false;
  1823. LoadGridData();
  1824. }
  1825. else
  1826. {
  1827. DetailRange1.Enabled = true;
  1828. DetailRange2.Enabled = true;
  1829. }
  1830. }
  1831. private void PLCStart_Click(object sender, EventArgs e)
  1832. {
  1833. //查询前端检验的端口号
  1834. DataTable dt = (DataTable)adh.ExecuteSql("select * from cominfo", "select");
  1835. DataRow[] dr = dt.Select("comtype='PLC1'");
  1836. if (dr.Length > 0)
  1837. {
  1838. if (!PLC1.IsOpen)
  1839. {
  1840. PLC1.PortName = dr[0]["COM"].ToString();
  1841. PLC1.Tag = "PLC1";
  1842. PLC1.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
  1843. PLC1.DataReceived += Serial_DataReceived;
  1844. PLC1.Open();
  1845. }
  1846. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.DeviceStart);
  1847. MessageLog.AppendText("PLC启动成功", Color.Blue);
  1848. }
  1849. }
  1850. private void PLCStop_Click(object sender, EventArgs e)
  1851. {
  1852. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.DeviceStop);
  1853. MessageLog.AppendText("PLC暂停成功", Color.Blue);
  1854. }
  1855. private void ButtonCollectPass_Click(object sender, EventArgs e)
  1856. {
  1857. string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
  1858. int pib_pdno = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["pib_pdno"].Value.ToString());
  1859. string ErrorMsg = "";
  1860. FrontCheckFunction("", out ErrorMsg);
  1861. }
  1862. private void ButtonRecheckPass_Click(object sender, EventArgs e)
  1863. {
  1864. string ErrorMsg = "";
  1865. string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
  1866. int pib_pdno = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["pib_pdno"].Value.ToString());
  1867. BackendCheckFunction("", pib_id, out ErrorMsg);
  1868. }
  1869. private void ButtonSetMidBox_Click(object sender, EventArgs e)
  1870. {
  1871. Process_midboxcode.Text = SetMidBox.Text;
  1872. }
  1873. private void ButtonSetOutBox_Click(object sender, EventArgs e)
  1874. {
  1875. Process_outboxcode.Text = SetOutBox.Text;
  1876. }
  1877. private void Collection_CheckedChanged(object sender, EventArgs e)
  1878. {
  1879. ButtonCollectPass.Enabled = ManualCollection.Checked;
  1880. ButtonRecheckPass.Enabled = ManualCollection.Checked;
  1881. ButtonSetMidBox.Enabled = ManualCollection.Checked;
  1882. ButtonSetOutBox.Enabled = ManualCollection.Checked;
  1883. }
  1884. private void AddCutBox_Click(object sender, EventArgs e)
  1885. {
  1886. Button button = sender as Button;
  1887. switch (button.Name)
  1888. {
  1889. case "AddMidBox":
  1890. Process_midboxcode.Text = (int.Parse(Process_midboxcode.Text) + 1).ToString();
  1891. break;
  1892. case "CutMidBox":
  1893. if (int.Parse(Process_midboxcode.Text) > 1)
  1894. Process_midboxcode.Text = (int.Parse(Process_midboxcode.Text) - 1).ToString();
  1895. break;
  1896. case "AddOutBox":
  1897. Process_outboxcode.Text = (int.Parse(Process_outboxcode.Text) + 1).ToString();
  1898. break;
  1899. case "CutOutBox":
  1900. if (int.Parse(Process_outboxcode.Text) > 1)
  1901. Process_outboxcode.Text = (int.Parse(Process_outboxcode.Text) - 1).ToString();
  1902. break;
  1903. default:
  1904. break;
  1905. }
  1906. }
  1907. private void Page_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1908. {
  1909. switch ((sender as LinkLabel).Name)
  1910. {
  1911. case "FirstPage":
  1912. CurrentPage = 1;
  1913. break;
  1914. case "LastPage":
  1915. CurrentPage = MaxPageSize;
  1916. break;
  1917. case "BeforePage":
  1918. if (CurrentPage == 1)
  1919. {
  1920. MessageBox.Show("已经是第一页了", "提示");
  1921. return;
  1922. }
  1923. CurrentPage = CurrentPage - 1;
  1924. break;
  1925. case "NextPage":
  1926. if (CurrentPage == MaxPageSize)
  1927. {
  1928. MessageBox.Show("已经是最后一页了", "提示");
  1929. return;
  1930. }
  1931. CurrentPage = CurrentPage + 1;
  1932. break;
  1933. default:
  1934. break;
  1935. }
  1936. PageInf.Text = CurrentPage + "/" + MaxPageSize;
  1937. LoadGridData();
  1938. }
  1939. Dictionary<string, string> instruct = new Dictionary<string, string>();
  1940. private void RefreshPLCInstruct()
  1941. {
  1942. //查询所有的PLC指令
  1943. DataTable dtPLCInstruct = (DataTable)adh.ExecuteSql("select * from PLCInstruct", "select");
  1944. instruct.Clear();
  1945. //如果存在指令参数的话则全部添加到键值对当中
  1946. if (dtPLCInstruct.Rows.Count > 0)
  1947. {
  1948. for (int i = 0; i < dtPLCInstruct.Columns.Count; i++)
  1949. {
  1950. instruct.Add(dtPLCInstruct.Columns[i].ColumnName, dtPLCInstruct.Rows[0][dtPLCInstruct.Columns[i].ColumnName].ToString());
  1951. }
  1952. }
  1953. }
  1954. private void MessageLog_MouseUp(object sender, MouseEventArgs e)
  1955. {
  1956. if (e.Button == MouseButtons.Right)
  1957. {
  1958. LogMenu.Show(new Point(MessageLog.Location.X + 100, MessageLog.Location.Y + 20));
  1959. }
  1960. }
  1961. private void UploadData_Click(object sender, EventArgs e)
  1962. {
  1963. if (LogicHandler.CheckUploadData(pi_inoutno.Text))
  1964. {
  1965. DataTable dtt = LabelInf.DataSource as DataTable;
  1966. for (int i = 0; i < dtt.Rows.Count; i++)
  1967. {
  1968. if (dtt.Rows[i]["pib_ifrecheck"].ToString() != "0" && dtt.Rows[i]["pib_ifupload"].ToString() == "0")
  1969. {
  1970. dtt.Rows[i]["pib_ifupload"] = -1;
  1971. }
  1972. }
  1973. MessageLog.AppendText(">>上传数据成功\n", Color.Green);
  1974. }
  1975. }
  1976. }
  1977. }