UAS_出货标签管理.cs 97 KB

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