UAS_出货标签管理.cs 91 KB

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