UAS_出货标签管理.cs 87 KB

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