UAS_出货标签管理.cs 93 KB

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