UAS_出货标签管理.cs 94 KB

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