UAS_出货标签管理.cs 120 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506
  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. AccessDBHelper back_adh;
  26. DataTable dt;
  27. StringBuilder sql = new StringBuilder();
  28. /// <summary>
  29. /// CodeSoft新建打印机引擎
  30. /// </summary>
  31. ApplicationClass lbl;
  32. /// <summary>
  33. /// 单盘打印文件
  34. /// </summary>
  35. Document SingleDoc;
  36. /// <summary>
  37. /// 中盒打印文件
  38. /// </summary>
  39. Document MidDoc;
  40. /// <summary>
  41. /// 外箱打印文件
  42. /// </summary>
  43. Document OutBoxDoc;
  44. /// <summary>
  45. /// Loading窗口
  46. /// </summary>
  47. SetLoadingWindow stw;
  48. /// <summary>
  49. /// 弹窗线程
  50. /// </summary>
  51. Thread thread;
  52. string PI_ID;
  53. /// <summary>
  54. /// 当前扫描的所在行
  55. /// </summary>
  56. int CurrentRowIndex = 0;
  57. /// <summary>
  58. /// 正则表达式用于项目匹配
  59. /// </summary>
  60. Regex reg;
  61. bool logout = false;
  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. back_adh = SystemInf.back_adh;
  129. CheckForIllegalCrossThreadCalls = false;
  130. pi_inoutno.Focus();
  131. Point pt = new Point();
  132. //禁止所有列的排序
  133. foreach (DataGridViewColumn dgv in LabelInf.Columns)
  134. {
  135. dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
  136. }
  137. AutoCollection.Checked = true;
  138. int ScreenWidth = Screen.GetWorkingArea(pt).Width;
  139. //设置获取当前屏幕大小自动全屏但是保留任务栏
  140. Rectangle ScreenArea = Screen.GetWorkingArea(this);
  141. Top = 0;
  142. Left = 0;
  143. Width = ScreenArea.Width;
  144. Height = ScreenArea.Height;
  145. MidBoxCapacity.Value = Properties.Settings.Default.MidBoxCapacity;
  146. OutBoxCapacity.Value = Properties.Settings.Default.OutboxCapacity;
  147. asc.controllInitializeSize(this);
  148. asc.controlAutoSize(this);
  149. //实例化打印进程
  150. try
  151. {
  152. lbl = new ApplicationClass();
  153. }
  154. catch (Exception)
  155. {
  156. MessageBox.Show("未安装CodeSoft软件或者版本不正确");
  157. }
  158. RefreshDBConnect.Interval = 60000;
  159. RefreshDBConnect.Start();
  160. DataTable dt = (DataTable)adh.ExecuteSql("select * from cominfo", "select");
  161. DataRow[] dr;
  162. try
  163. {
  164. dr = dt.Select("comtype='FrontendCheck'");
  165. if (dr.Length > 0)
  166. {
  167. FrontendCheck.PortName = dr[0]["COM"].ToString();
  168. int sleeptime = 0;
  169. if (int.TryParse(dr[0]["DATAWAIT"].ToString(), out sleeptime))
  170. {
  171. FrontendCheck.SleepTime = sleeptime;
  172. }
  173. FrontendCheck.Tag = "FrontendCheck";
  174. FrontendCheck.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
  175. FrontendCheck.DataReceived += Serial_DataReceived;
  176. FrontendCheck.Open();
  177. }
  178. }
  179. catch (Exception ex)
  180. {
  181. MessageLog.AppendText(ex.Message);
  182. }
  183. try
  184. {
  185. dr = dt.Select("comtype='BackendCheck'");
  186. if (dr.Length > 0)
  187. {
  188. BackendCheck.PortName = dr[0]["COM"].ToString();
  189. BackendCheck.Tag = "BackendCheck";
  190. int sleeptime = 0;
  191. if (int.TryParse(dr[0]["DATAWAIT"].ToString(), out sleeptime))
  192. {
  193. BackendCheck.SleepTime = sleeptime;
  194. }
  195. BackendCheck.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
  196. BackendCheck.DataReceived += Serial_DataReceived;
  197. BackendCheck.Open();
  198. }
  199. }
  200. catch (Exception ex)
  201. {
  202. MessageLog.AppendText(ex.Message);
  203. }
  204. try
  205. {
  206. dr = dt.Select("comtype='PLC1'");
  207. if (dr.Length > 0)
  208. {
  209. if (!PLC1.IsOpen)
  210. {
  211. PLC1.PortName = dr[0]["COM"].ToString();
  212. PLC1.Tag = "PLC1";
  213. int sleeptime = 0;
  214. if (int.TryParse(dr[0]["DATAWAIT"].ToString(), out sleeptime))
  215. {
  216. PLC1.SleepTime = sleeptime;
  217. }
  218. PLC1.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
  219. PLC1.DataReceived += Serial_DataReceived;
  220. PLC1.Open();
  221. }
  222. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.DeviceStart, adh);
  223. MessageLog.AppendText("PLC启动成功\n", Color.Blue);
  224. }
  225. }
  226. catch (Exception ex)
  227. {
  228. MessageLog.AppendText(ex.Message);
  229. }
  230. try
  231. {
  232. dr = dt.Select("comtype='ManBackendCheck'");
  233. if (dr.Length > 0)
  234. {
  235. if (!ManBackendCheck.IsOpen)
  236. {
  237. ManBackendCheck.PortName = dr[0]["COM"].ToString();
  238. ManBackendCheck.Tag = "ManBackendCheck";
  239. int sleeptime = 0;
  240. if (int.TryParse(dr[0]["DATAWAIT"].ToString(), out sleeptime))
  241. {
  242. ManBackendCheck.SleepTime = sleeptime;
  243. }
  244. ManBackendCheck.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
  245. ManBackendCheck.DataReceived += Serial_DataReceived;
  246. ManBackendCheck.Open();
  247. }
  248. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.DeviceStart, adh);
  249. MessageLog.AppendText("PLC启动成功\n", Color.Blue);
  250. }
  251. }
  252. catch (Exception ex)
  253. {
  254. MessageLog.AppendText(ex.Message);
  255. }
  256. RefreshPLCInstruct();
  257. }
  258. string LotNo = "";
  259. string DateCode = "";
  260. string Order = "";
  261. string QTY = "";
  262. string PN = "";
  263. string OutBox = "";
  264. List<int> ManualCheckCount = new List<int>();
  265. //获取串口数据
  266. private void Serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
  267. {
  268. try
  269. {
  270. string ErrorMsg = "";
  271. SerialPortWithTag port = sender as SerialPortWithTag;
  272. Thread.Sleep(port.SleepTime);
  273. int len = port.BytesToRead;
  274. byte[] readBuffer = new byte[len];
  275. port.Read(readBuffer, 0, len); //将数据读入缓存
  276. string msg = Encoding.ASCII.GetString(readBuffer, 0, len); //获取出入库产品编号
  277. int pib_pdno = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["pib_pdno"].Value.ToString());
  278. if (DetailRange.Checked)
  279. {
  280. //不在范围内的不进行处理
  281. if (!(pib_pdno >= DetailRange1.Value && pib_pdno <= DetailRange2.Value))
  282. {
  283. return;
  284. }
  285. }
  286. switch (port.Tag)
  287. {
  288. case "PLC1":
  289. //MessageLog.AppendText(msg + "\n", Color.Blue);
  290. ////返回的指令和设备执行的动作对应
  291. //foreach (var item in instruct)
  292. //{
  293. // //接收到的数据和指令的对应则
  294. // if (item.Value == msg)
  295. // {
  296. // }
  297. //}
  298. break;
  299. case "PLC2":
  300. break;
  301. case "FrontendCheck":
  302. //比对当前箱数量和容量
  303. FrontCollect.Text = msg;
  304. if (!FrontCheckFunction(msg, out ErrorMsg))
  305. {
  306. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.FrontDataDelete, adh);
  307. BaseUtil.PlaySound("Scan.Error.wav");
  308. MessageLog.AppendText(">>" + ErrorMsg + "\n", Color.Red);
  309. }
  310. else
  311. {
  312. if (cu_print_checkdatecode.Checked)
  313. {
  314. string datecode = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString();
  315. string lotno = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString();
  316. if (datecode == "" || lotno == "")
  317. {
  318. MessageLog.AppendText(">>设定必须采集DateCode内容,请先采集再打印\n", Color.Red);
  319. return;
  320. }
  321. }
  322. //勾选了单盘自动打印
  323. if (SingleLabelAutoPrint.Checked)
  324. {
  325. if (SingleLabelCombox.SelectedValue != null)
  326. {
  327. AutoPrintSingleLabel();
  328. }
  329. else
  330. {
  331. MessageBox.Show("未维护单盘标签");
  332. return;
  333. }
  334. }
  335. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
  336. BaseUtil.PlaySound("Scan.Finish.wav");
  337. //勾选了中盒自动打印
  338. if (MidLabelAutoPrint.Checked)
  339. AutoPrintMidLabel();
  340. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.FrontDataPass, adh);
  341. LabelInf.Invalidate();
  342. RefreshProcessData();
  343. }
  344. break;
  345. case "BackendCheck":
  346. BackCheck.Text = msg;
  347. if (BackendCheckFunction(msg, "Auto", out ErrorMsg))
  348. {
  349. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.BackDataPass, adh);
  350. BaseUtil.PlaySound("Confirm.Finish.wav");
  351. }
  352. else
  353. {
  354. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.BackDataDelete, adh);
  355. BaseUtil.PlaySound("Confirm.Error.wav");
  356. MessageLog.AppendText(">>" + ErrorMsg + "\n", Color.Red);
  357. }
  358. break;
  359. case "ManBackendCheck":
  360. if (ManualBackCheck.Checked)
  361. {
  362. BackCheck.Text = msg;
  363. if (BackendCheckFunction(msg, "Manual", out ErrorMsg))
  364. {
  365. ManualCheckCount.Add(1);
  366. }
  367. else
  368. {
  369. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.BackDataDelete, adh);
  370. BaseUtil.PlaySound("Confirm.Error.wav");
  371. MessageLog.AppendText(">>" + ErrorMsg + "\n", Color.Red);
  372. }
  373. if (ManualCheckCount.Count == 2)
  374. {
  375. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.BackDataPass, adh);
  376. BaseUtil.PlaySound("Confirm.Finish.wav");
  377. ManualCheckCount.Clear();
  378. }
  379. }
  380. else
  381. {
  382. MessageLog.AppendText(">>该串口为手动复核串口,请选择手动后端复核模式\n", Color.Red);
  383. }
  384. break;
  385. default:
  386. break;
  387. }
  388. }
  389. catch (Exception ex)
  390. {
  391. LogManager.DoLog(ex.Message + ex.StackTrace);
  392. MessageLog.AppendText("接收返回消息异常!具体原因:" + ex.Message + ex.StackTrace, Color.Red);
  393. }
  394. }
  395. private bool RegexMatch(string CheckType, string msg, out string ErrorMsg)
  396. {
  397. ErrorMsg = "";
  398. bool Matched = false;
  399. for (int i = 0; i < ScanGroup.Rows.Count; i++)
  400. {
  401. string sg_name = ScanGroup.Rows[i]["sg_name"].ToString();
  402. string sg_brand = ScanGroup.Rows[i]["sg_brand"].ToString();
  403. string sg_script = ScanGroup.Rows[i]["sg_script"].ToString();
  404. string sg_id = ScanGroup.Rows[i]["sg_id"].ToString();
  405. reg = new Regex(sg_script);
  406. Match matchs1 = reg.Match(msg);
  407. DataTable dt = BaseUtil.filterDataTable(ScanItem, "sg_id=" + sg_id);
  408. if (matchs1.Success)
  409. {
  410. int rownum = 0;
  411. Matched = true;
  412. string ItemStr = "";
  413. foreach (var groupName in reg.GetGroupNames())
  414. {
  415. for (int j = 0; j < dt.Rows.Count; j++)
  416. {
  417. //如果组别名称相等的话
  418. if (groupName == dt.Rows[j]["si_name"].ToString())
  419. {
  420. ItemStr += dt.Rows[j]["si_item"].ToString() + ",";
  421. string si_expression = dt.Rows[j]["si_expression"].ToString();
  422. Regex si_exp;
  423. switch (dt.Rows[j]["si_item"].ToString())
  424. {
  425. case "DateCode":
  426. if (si_expression != "")
  427. {
  428. si_exp = new Regex(si_expression);
  429. DateCode = si_exp.Match(matchs1.Groups[reg.GroupNumberFromName(groupName)].Value).Value;
  430. }
  431. else
  432. {
  433. DateCode = matchs1.Groups[reg.GroupNumberFromName(groupName)].Value;
  434. }
  435. break;
  436. case "LotNo":
  437. LotNo = matchs1.Groups[reg.GroupNumberFromName(groupName)].Value;
  438. break;
  439. case "PN":
  440. PN = matchs1.Groups[reg.GroupNumberFromName(groupName)].Value;
  441. //自动匹配客户PN
  442. string sql = "select min(rownum) as rn from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pr_orispeccode='" + PN + "'";
  443. if (CheckType == "FrontCheck")
  444. {
  445. sql += "and pib_ifpick=0";
  446. }
  447. else if (CheckType == "BackCheck")
  448. {
  449. sql += "and pib_ifrecheck=0";
  450. }
  451. DataTable pndt = (DataTable)adh.ExecuteSql(sql, "select");
  452. if (pndt.Rows[0][0].ToString() != "")
  453. {
  454. rownum = int.Parse(pndt.Rows[0]["rn"].ToString());
  455. //如果需要翻页的话
  456. if (!(rownum >= (PageSize * (CurrentPage - 1) + 1) && rownum <= PageSize * CurrentPage))
  457. {
  458. CurrentPage = rownum / PageSize + 1;
  459. LoadGridData();
  460. CurrentRowIndex = rownum % PageSize == 0 ? PageSize - 1 : rownum % PageSize - 1;
  461. if (CurrentRowIndex - 10 > 0)
  462. LabelInf.FirstDisplayedScrollingRowIndex = CurrentRowIndex - 5;
  463. }
  464. else
  465. {
  466. CurrentRowIndex = rownum % PageSize == 0 ? PageSize - 1 : rownum % PageSize - 1;
  467. if (CurrentRowIndex - 10 > 0)
  468. LabelInf.FirstDisplayedScrollingRowIndex = CurrentRowIndex - 5;
  469. }
  470. }
  471. else
  472. {
  473. ErrorMsg = "未能匹配到合适的原厂型号";
  474. }
  475. break;
  476. case "Order":
  477. Order = matchs1.Groups[reg.GroupNumberFromName(groupName)].Value;
  478. if (LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString() != Order)
  479. {
  480. ErrorMsg = "订单号不匹配";
  481. }
  482. break;
  483. case "QTY":
  484. if (si_expression != "")
  485. {
  486. si_exp = new Regex(si_expression);
  487. QTY = si_exp.Match(matchs1.Groups[reg.GroupNumberFromName(groupName)].Value).Value;
  488. }
  489. else
  490. {
  491. QTY = matchs1.Groups[reg.GroupNumberFromName(groupName)].Value;
  492. }
  493. break;
  494. case "OutBox":
  495. OutBox = matchs1.Groups[reg.GroupNumberFromName(groupName)].Value;
  496. break;
  497. default:
  498. break;
  499. }
  500. }
  501. }
  502. }
  503. //如果品牌不对应的话则不能使用本次的匹配规则
  504. if (ErrorMsg == "" && ItemStr.Contains("QTY") && LabelInf.Rows[CurrentRowIndex].Cells["pib_qty"].Value.ToString() != QTY.ToString())
  505. {
  506. ErrorMsg = "数量不匹配";
  507. }
  508. if (ErrorMsg == "" && ItemStr.Contains("PO") && LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString() != Order)
  509. {
  510. ErrorMsg = "订单号不匹配";
  511. }
  512. if (LabelInf.Rows[CurrentRowIndex].Cells["pib_brand"].Value.ToString() != sg_brand)
  513. {
  514. ErrorMsg = "";
  515. continue;
  516. }
  517. else
  518. {
  519. break;
  520. }
  521. }
  522. }
  523. if (!Matched)
  524. {
  525. ErrorMsg = "未匹配到合适的采集策略";
  526. }
  527. if (ErrorMsg == "")
  528. {
  529. return true;
  530. }
  531. else
  532. {
  533. return false;
  534. }
  535. }
  536. private bool FrontCheckFunction(string msg, out string ErrorMsg)
  537. {
  538. ErrorMsg = "";
  539. //调用正则验证
  540. RegexMatch("FrontCheck", msg, out ErrorMsg);
  541. if (ErrorMsg != "")
  542. {
  543. return false;
  544. }
  545. else
  546. {
  547. //获取当前最大的箱号
  548. LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value = DateCode;
  549. LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value = LotNo;
  550. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifmodify"].Value = true;
  551. SetOutboxBarcode();
  552. return true;
  553. }
  554. }
  555. //外箱条码号
  556. string OutBoxBarCode = "";
  557. //中盒条码号
  558. string MidBoxBarCode = "";
  559. string pibid1 = "";
  560. private bool BackendCheckFunction(string msg, string type, out string ErrorMsg)
  561. {
  562. ErrorMsg = "";
  563. DataTable dtt = LabelInf.DataSource as DataTable;
  564. MessageLog.AppendText(msg + "\n");
  565. string[] msgArr = msg.Split(back_sg_separator.Text.ToCharArray());
  566. //如果包含则分隔符则需要解析,如果不包含则直接前端解析
  567. if (msg.Contains(back_sg_separator.Text))
  568. {
  569. //需要校验2项数据,完成校验后此项的值需要为2则表示校验成功
  570. List<string> CheckItem = new List<string>();
  571. string pibid = "";
  572. for (int i = 0; i < msgArr.Length; i++)
  573. {
  574. if (RecheckCuprodcode.Checked)
  575. {
  576. if (!CheckItem.Contains("客户料号") && !CheckItem.Contains("原厂型号"))
  577. {
  578. CheckItem.Add("客户料号");
  579. CheckItem.Add("原厂型号");
  580. }
  581. //直接验证两个值相等
  582. if (Equal.Checked)
  583. {
  584. pibid = back_adh.getFieldDataByCondition("prodiobarcode", "min(pib_id)", "pib_inoutno='" + pi_inoutno.Text + "' and pd_custprodcode='" + msgArr[i] + "' and pib_ifrecheck=0").ToString();
  585. if (pibid != "")
  586. {
  587. pibid1 = pibid;
  588. CheckItem.Remove("客户料号");
  589. }
  590. }
  591. //验证正则匹配过之后相等
  592. else if (Expression.Checked)
  593. {
  594. Regex re = new Regex(cu_print_regexpression.Text);
  595. if (re.Match(msgArr[i]).Value == LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString())
  596. {
  597. CheckItem.Remove("客户料号");
  598. }
  599. }
  600. if (RegexMatch("BackCheck", msgArr[i], out ErrorMsg))
  601. {
  602. CheckItem.Remove("原厂型号");
  603. }
  604. }
  605. else if (RecheckBarcode.Checked)
  606. {
  607. if (!CheckItem.Contains("唯一条码") && !CheckItem.Contains("原厂型号"))
  608. {
  609. CheckItem.Add("唯一条码");
  610. CheckItem.Add("原厂型号");
  611. }
  612. pibid = back_adh.getFieldDataByCondition("prodiobarcode", "min(pib_id)", "pib_inoutno='" + pi_inoutno.Text + "' and pib_custbarcode='" + msgArr[i] + "' and pib_ifrecheck=0").ToString();
  613. if (pibid != "")
  614. {
  615. pibid1 = pibid;
  616. CheckItem.Remove("唯一条码");
  617. }
  618. else
  619. {
  620. if (RegexMatch("BackCheck", msgArr[i], out ErrorMsg))
  621. {
  622. CheckItem.Remove("原厂型号");
  623. }
  624. }
  625. }
  626. }
  627. //如果是自动复核或者手动复核扫描了两次数据的话
  628. if (CheckItem.Count == 0 || (type == "Manual" && CheckItem.Count == 1))
  629. {
  630. if (CheckItem.Count == 0 || (ManualCheckCount.Count == 1 && CheckItem.Count == 1))
  631. {
  632. string year = "0";
  633. string month = "0";
  634. string day = "0";
  635. DataRow[] dr = LabelInfDataTable.Select("pib_id=" + pibid1 + " and pr_orispeccode='" + PN + "'");
  636. if (dr.Length > 0)
  637. {
  638. dr[0]["pib_ifrecheck"] = -1;
  639. dr[0]["pib_lotno"] = LotNo;
  640. dr[0]["pib_datecode"] = DateCode;
  641. try
  642. {
  643. LogicHandler.GetTimeFromDatecode(DateCode, "", out year, out month, out day);
  644. dr[0]["pib_year"] = year;
  645. dr[0]["pib_month"] = month;
  646. dr[0]["pib_day"] = day;
  647. }
  648. catch (Exception)
  649. {
  650. }
  651. }
  652. else
  653. {
  654. ErrorMsg = "未匹配到合适的原厂型号";
  655. return false;
  656. }
  657. back_adh.ExecuteSql("update prodiobarcode set pib_year=" + year + ",pib_month=" + month + ",pib_day=" + day + ",pib_ifrecheck=-1,pib_datecode='" + DateCode + "',pib_lotno='" + LotNo + "' where pib_id=" + pibid1 + " and pr_orispeccode='" + PN + "'", "update");
  658. }
  659. }
  660. else
  661. {
  662. string Item = "";
  663. for (int i = 0; i < CheckItem.Count; i++)
  664. {
  665. Item += CheckItem[i].ToString() + " ";
  666. }
  667. //如果通过正则校验,则不需要传递出来的错误信息了
  668. if (!CheckItem.Contains("原厂型号"))
  669. {
  670. ErrorMsg = "";
  671. }
  672. else
  673. {
  674. ErrorMsg = "【" + ErrorMsg + "】";
  675. }
  676. ErrorMsg += Item + "复核不通过";
  677. return false;
  678. }
  679. if (CheckItem.Count == 0 || (ManualCheckCount.Count == 1 && CheckItem.Count == 1))
  680. {
  681. LabelInf.Invalidate();
  682. RefreshProcessData();
  683. if (CurrentRowIndex - 10 > 0)
  684. LabelInf.FirstDisplayedScrollingRowIndex = CurrentRowIndex - 5;
  685. //如果成功上传了数据
  686. if (LogicHandler.CheckUploadData(pi_inoutno.Text, UploadNum))
  687. {
  688. for (int i = 0; i < dtt.Rows.Count; i++)
  689. {
  690. if (dtt.Rows[i]["pib_ifrecheck"].ToString() != "0" && dtt.Rows[i]["pib_ifupload"].ToString() == "0")
  691. {
  692. dtt.Rows[i]["pib_ifupload"] = -1;
  693. }
  694. }
  695. }
  696. return true;
  697. }
  698. else
  699. {
  700. if (type == "Manual" && CheckItem.Count == 1)
  701. return true;
  702. else
  703. return false;
  704. }
  705. }
  706. else
  707. {
  708. if (RegexMatch("BackCheck", msg, out ErrorMsg))
  709. {
  710. string year = "0";
  711. string month = "0";
  712. string day = "0";
  713. LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value = DateCode;
  714. //解析DateCode,将值设置到年月日
  715. try
  716. {
  717. LogicHandler.GetTimeFromDatecode(DateCode, "", out year, out month, out day);
  718. LabelInf.Rows[CurrentRowIndex].Cells["pib_year"].Value = year;
  719. LabelInf.Rows[CurrentRowIndex].Cells["pib_month"].Value = month;
  720. LabelInf.Rows[CurrentRowIndex].Cells["pib_day"].Value = day;
  721. }
  722. catch (Exception) { }
  723. LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value = LotNo;
  724. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifmodify"].Value = true;
  725. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifrecheck"].Value = true;
  726. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
  727. adh.ExecuteSQLTran("update prodiobarcode set pib_year=" + year + ",pib_month=" + month + ",pib_day=" + day + ",pib_lotno='" + LotNo + "',pib_datecode='" + DateCode + "',pib_ifpick=-1,pib_ifmodify=-1,pib_ifrecheck=-1 where pib_id=" + LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value);
  728. LogicHandler.CheckUploadData(pi_inoutno.Text, UploadNum);
  729. LabelInf.Invalidate();
  730. return true;
  731. }
  732. return false;
  733. }
  734. }
  735. //只执行一次窗体自适应
  736. bool AutoSized = false;
  737. private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
  738. {
  739. if (!AutoSized)
  740. {
  741. asc.controlAutoSize(this);
  742. AutoSized = true;
  743. }
  744. }
  745. private void LabelMaintain_Click(object sender, EventArgs e)
  746. {
  747. 客户标签维护 form = new 客户标签维护();
  748. BaseUtil.SetFormCenter(form);
  749. if (SingleDoc != null)
  750. SingleDoc.Close();
  751. if (MidDoc != null)
  752. MidDoc.Close();
  753. if (OutBoxDoc != null)
  754. OutBoxDoc.Close();
  755. form.FormClosed += LabelFormClose;
  756. form.ShowDialog();
  757. }
  758. private void LabelFormClose(object sender, EventArgs e)
  759. {
  760. if (GetGridOnly.Checked)
  761. GetInOutInfAndLabelFile();
  762. else
  763. {
  764. GetGridOnly.Checked = true;
  765. GetInOutInfAndLabelFile();
  766. GetGridOnly.Checked = false;
  767. }
  768. }
  769. private bool AutoPrintSingleLabel()
  770. {
  771. //用标签本身的变量作为最外层的循环条件去匹配;
  772. SinglePrint(LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString());
  773. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifprint"].Value = true;
  774. return true;
  775. }
  776. //关闭窗口前提示用户确认
  777. private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
  778. {
  779. //如果不是注销的话
  780. if (!logout)
  781. {
  782. string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  783. if (close.ToString() != "Yes")
  784. e.Cancel = true;
  785. else
  786. {
  787. lbl.Quit();
  788. LogManager.DoLog("关闭程序");
  789. }
  790. }
  791. }
  792. /// <summary>
  793. /// 获取打印标签
  794. /// </summary>
  795. private void GetInOutInfAndLabelFile()
  796. {
  797. ComBoxClickChangeLabelDoc = false;
  798. Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LabelAttachPARAMETER where lap_custcode='" + pi_cardcode.Text + "'", "select");
  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. SingleLabelCombox.DisplayMember = "cl_labelname";
  805. SingleLabelCombox.ValueMember = "la_id";
  806. SingleLabelCombox.DataSource = dt;
  807. if (SingleDoc != null)
  808. SingleDoc.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 (SingleLabelCombox.Text != "")
  820. {
  821. SingleDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + SingleLabelCombox.Text);
  822. SingleLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + SingleLabelCombox.SelectedValue.ToString().Split('#')[0], "select");
  823. }
  824. sql.Clear();
  825. 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 ");
  826. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  827. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='中盒' order by cl_custcode");
  828. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  829. MidLabelCombox.DisplayMember = "cl_labelname";
  830. MidLabelCombox.ValueMember = "la_id";
  831. MidLabelCombox.DataSource = dt;
  832. if (MidDoc != null)
  833. MidDoc.Close();
  834. if (!GetGridOnly.Checked)
  835. for (int i = 0; i < dt.Rows.Count; i++)
  836. {
  837. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  838. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  839. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  840. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  841. if (time.ToString() != file.LastWriteTime.ToString())
  842. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  843. }
  844. if (MidLabelCombox.Text != "")
  845. {
  846. MidDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + MidLabelCombox.Text);
  847. MidLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + MidLabelCombox.SelectedValue.ToString().Split('#')[0], "select");
  848. }
  849. //缓存中盒参数
  850. sql.Clear();
  851. 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 ");
  852. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  853. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='外箱' order by cl_custcode");
  854. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  855. OutBoxCombox.DisplayMember = "cl_labelname";
  856. OutBoxCombox.ValueMember = "la_id";
  857. OutBoxCombox.DataSource = dt;
  858. if (OutBoxDoc != null)
  859. OutBoxDoc.Close();
  860. if (!GetGridOnly.Checked)
  861. for (int i = 0; i < dt.Rows.Count; i++)
  862. {
  863. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  864. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  865. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  866. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  867. if (time.ToString() != file.LastWriteTime.ToString())
  868. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  869. }
  870. if (OutBoxCombox.Text != "")
  871. {
  872. OutBoxDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + OutBoxCombox.Text);
  873. 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");
  874. }
  875. //缓存外箱参数
  876. ComBoxClickChangeLabelDoc = true;
  877. }
  878. /// <summary>
  879. /// 出入库单录入框的回车事件
  880. /// </summary>
  881. /// <param name="sender"></param>
  882. /// <param name="e"></param>
  883. private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
  884. {
  885. if (e.KeyCode == Keys.Enter)
  886. {
  887. CurrentPage = 1;
  888. sql.Clear();
  889. sql.Append("select pi_id,pi_cardcode,to_char(pi_date,'yyyymmdd')pi_date from prodinout where pi_inoutno='" + pi_inoutno.Text + "'");
  890. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  891. if (dt.Rows.Count > 0)
  892. {
  893. pi_cardcode.Text = dt.Rows[0]["pi_cardcode"].ToString();
  894. pi_date.Text = dt.Rows[0]["pi_date"].ToString();
  895. PI_ID = dt.Rows[0]["pi_id"].ToString();
  896. //if (dh.GetConfig("AutoBarcode", "ProdInOut!Sale").ToString() != "")
  897. //{
  898. string[] param = new string[] { PI_ID, "" };
  899. dh.CallProcedure("GetCustBarcode", ref param);
  900. //}
  901. //获取客户自定义设置
  902. sql.Clear();
  903. sql.Append("select cu_print_middc,cu_print_outdc,cu_print_dateformat,cu_print_checkdatecode,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");
  904. 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 + "'");
  905. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  906. if (dt.Rows.Count > 0)
  907. {
  908. BaseUtil.SetFormValue(this.Controls, dt);
  909. switch (dt.Rows[0]["cu_print_custprodmatchmodel"].ToString())
  910. {
  911. case "Equal":
  912. Equal.Checked = true;
  913. break;
  914. case "Expression":
  915. Expression.Checked = true;
  916. break;
  917. default:
  918. Equal.Checked = true;
  919. break;
  920. }
  921. switch (dt.Rows[0]["cu_print_recheck"].ToString())
  922. {
  923. case "CP":
  924. RecheckCuprodcode.Checked = true;
  925. break;
  926. case "BR":
  927. RecheckBarcode.Checked = true;
  928. break;
  929. default:
  930. RecheckCuprodcode.Checked = true;
  931. break;
  932. }
  933. }
  934. //查询所有的采集策略
  935. sql.Clear();
  936. 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 ");
  937. 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 ");
  938. 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 ");
  939. ScanItem = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  940. sql.Clear();
  941. sql.Append("select distinct sg_brand from prodiodetail left join product on pd_prodcode=pr_code left join scangroup ");
  942. sql.Append("on nvl(pd_brand,pr_brand)=sg_brand where pd_inoutno='" + pi_inoutno.Text + "' and sg_brand is not null");
  943. DataTable dt1 = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  944. FrontCombo.DataSource = dt1;
  945. FrontCombo.DisplayMember = "sg_brand";
  946. FrontCombo.ValueMember = "sg_brand";
  947. BackCombo.DataSource = dt1;
  948. BackCombo.DisplayMember = "sg_brand";
  949. BackCombo.ValueMember = "sg_brand";
  950. LoadGridData();
  951. //重新输入单号后清除缓存
  952. MidBoxArgument.Clear();
  953. SingleBoxArgument.Clear();
  954. MidIDAndOutboxcode.Clear();
  955. SingleID.Clear();
  956. thread = new Thread(GetInOutInfAndLabelFile);
  957. stw = new SetLoadingWindow(thread, "正在获取打印标签");
  958. BaseUtil.SetFormCenter(stw);
  959. stw.ShowDialog();
  960. LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
  961. }
  962. else
  963. MessageBox.Show("当前出入库单号不存在!");
  964. }
  965. }
  966. private void SingleBoxPrint()
  967. {
  968. try
  969. {
  970. if (SingleDoc.Variables.FormVariables.Count == 0) { }
  971. }
  972. catch (Exception)
  973. {
  974. MessageBox.Show("单盘标签未维护参数");
  975. }
  976. if (MidLabelAutoPrint.Checked)
  977. {
  978. try
  979. {
  980. if (MidDoc.Variables.FormVariables.Count == 0) { }
  981. }
  982. catch (Exception)
  983. {
  984. MessageBox.Show("中盘标签未维护参数");
  985. }
  986. }
  987. if (SingleLabelParam.Rows.Count > 0 && LabelInf.Rows.Count > 0)
  988. {
  989. //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
  990. MidIDAndOutboxcode.Clear();
  991. SingleID.Clear();
  992. //获取全部的中盒号
  993. Dictionary<string, bool> outboxcode1 = new Dictionary<string, bool>();
  994. //判断所有盒号为该盒的是否勾选已采集
  995. outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true);
  996. for (int i = 0; i < LabelInf.Rows.Count; i++)
  997. {
  998. if (!SingleID.Contains(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()))
  999. SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1000. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() != "True")
  1001. {
  1002. //如果不存在中盒号则进行添加
  1003. if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))
  1004. {
  1005. MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString());
  1006. }
  1007. }
  1008. }
  1009. if (SingleID.ToArray().Length == 0)
  1010. {
  1011. MessageBox.Show("选择的行未勾选采集或者已打印");
  1012. return;
  1013. }
  1014. for (int i = 0; i < LabelInf.RowCount; i++)
  1015. {
  1016. if (i + 1 < LabelInf.RowCount)
  1017. {
  1018. //如果本行的中盒号和下一行不相等的话
  1019. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString())
  1020. {
  1021. if (!outboxcode1.ContainsKey(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
  1022. outboxcode1.Add(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString(), true);
  1023. }
  1024. }
  1025. //只要有一行没有采集满就不打印
  1026. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  1027. {
  1028. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1029. outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()] = false;
  1030. }
  1031. }
  1032. //用于判断用户是否勾选了行
  1033. int CheckedRowCount = 0;
  1034. for (int i = 0; i < LabelInf.RowCount; i++)
  1035. {
  1036. //勾选了并且未打印
  1037. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() != "True")
  1038. {
  1039. if (cu_print_checkdatecode.Checked)
  1040. {
  1041. string datecode = LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString();
  1042. string lotno = LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString();
  1043. if (datecode == "" || lotno == "")
  1044. {
  1045. MessageLog.AppendText(">>设定必须采集DateCode内容,请先采集再打印\n", Color.Red);
  1046. return;
  1047. }
  1048. }
  1049. CheckedRowCount = CheckedRowCount + 1;
  1050. CurrentRowIndex = i;
  1051. //以标签模板的参数为基准,循环取数
  1052. try
  1053. {
  1054. SinglePrint(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1055. if (MidLabelAutoPrint.Checked)
  1056. {
  1057. //判断当前行的盒号和下一行不相等或者已经是最后一行了
  1058. 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())
  1059. {
  1060. if (outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()])
  1061. {
  1062. if (MidLabelCombox.SelectedValue != null)
  1063. {
  1064. MidBoxCodePrint(CurrentRowIndex);
  1065. }
  1066. }
  1067. }
  1068. }
  1069. //勾选为已打印
  1070. LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
  1071. }
  1072. catch (Exception ex) { LogManager.DoLog(ex.Message); }
  1073. }
  1074. }
  1075. if (CheckedRowCount == 0)
  1076. MessageBox.Show("未勾选打印明细!");
  1077. else if (CurrentRowIndex + 1 < LabelInf.Rows.Count)
  1078. CurrentRowIndex = CurrentRowIndex + 1;
  1079. outboxcode1.Clear();
  1080. }
  1081. else
  1082. {
  1083. MessageBox.Show("此模板尚未维护参数或不存在打印明细");
  1084. return;
  1085. }
  1086. }
  1087. private void SingleLabelPrint_Click(object sender, EventArgs e)
  1088. {
  1089. if (SingleLabelCombox.Text != "")
  1090. {
  1091. if (SingleBoxBegin.Text != "" || SingleBoxEnd.Text != "")
  1092. {
  1093. try
  1094. {
  1095. int begin = int.Parse(SingleBoxBegin.Text == "" ? "1" : SingleBoxBegin.Text);
  1096. int end = int.Parse(SingleBoxEnd.Text == "" ? LabelInf.Rows.Count.ToString() : SingleBoxEnd.Text);
  1097. if (begin > 0 && end <= LabelInf.Rows.Count && begin <= end)
  1098. {
  1099. for (int i = begin - 1; i < end; i++)
  1100. {
  1101. LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
  1102. LabelInf.Rows[i].Cells["pib_ifprint"].Value = false;
  1103. }
  1104. }
  1105. else
  1106. {
  1107. MessageBox.Show("单盘打印范围错误");
  1108. return;
  1109. }
  1110. }
  1111. catch (Exception)
  1112. {
  1113. MessageBox.Show("单盘打印范围错误");
  1114. return;
  1115. }
  1116. }
  1117. thread = new Thread(SingleBoxPrint);
  1118. stw = new SetLoadingWindow(thread, "正在打印单盘");
  1119. BaseUtil.SetFormCenter(stw);
  1120. stw.ShowDialog();
  1121. }
  1122. else
  1123. MessageBox.Show("未维护单盘标签");
  1124. }
  1125. private void MidBoxLabelPrint()
  1126. {
  1127. //未输入内容打印全部中盒
  1128. if (MidLabelNum.Text == "")
  1129. {
  1130. int begin = 0;
  1131. int end = 0;
  1132. if (MidBoxBegin.Text != "" || MidBoxEnd.Text != "")
  1133. {
  1134. try
  1135. {
  1136. begin = int.Parse(MidBoxBegin.Text == "" ? "1" : MidBoxBegin.Text);
  1137. end = int.Parse(MidBoxEnd.Text == "" ? LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString() : MidBoxEnd.Text);
  1138. int minmidbox = int.Parse(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString());
  1139. int maxmidbox = int.Parse(LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString());
  1140. if (begin >= minmidbox && end <= maxmidbox && begin <= end)
  1141. {
  1142. //设置中盒打印范围的行号
  1143. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1144. {
  1145. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == begin)
  1146. {
  1147. begin = i;
  1148. }
  1149. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == end)
  1150. {
  1151. end = i;
  1152. }
  1153. }
  1154. }
  1155. else
  1156. {
  1157. MessageBox.Show("中盒打印范围错误");
  1158. return;
  1159. }
  1160. }
  1161. catch (Exception)
  1162. {
  1163. MessageBox.Show("中盒打印范围错误");
  1164. return;
  1165. }
  1166. }
  1167. MidBoxArgument.Clear();
  1168. List<int> MidOutBoxCode = new List<int>();
  1169. List<int> MidOutBoxCodeIndex = new List<int>();
  1170. string la_id = MidLabelCombox.SelectedValue.ToString().Split('#')[0];
  1171. for (int i = (begin == 0 ? 0 : begin); i <= (end == 0 ? LabelInf.Rows.Count - 1 : end); i++)
  1172. {
  1173. if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))
  1174. MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString());
  1175. string outboxcode1 = LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString();
  1176. if (!MidOutBoxCode.Contains(int.Parse(outboxcode1 == "" ? "0" : outboxcode1)))
  1177. {
  1178. MidOutBoxCode.Add(int.Parse(outboxcode1 == "" ? "0" : outboxcode1));
  1179. MidOutBoxCodeIndex.Add(i);
  1180. }
  1181. }
  1182. for (int i = 0; i < MidOutBoxCodeIndex.Count; i++)
  1183. {
  1184. MidBoxCodePrint(MidOutBoxCodeIndex[i]);
  1185. }
  1186. MidBoxArgument.Clear();
  1187. return;
  1188. }
  1189. bool FindMidLabel = false;
  1190. if (MidLabelCombox.SelectedValue != null)
  1191. {
  1192. //中盒号所在的行
  1193. int MidLabelRowIndex = 0;
  1194. //缓存中盒数据
  1195. for (int i = 0; i < LabelInf.RowCount; i++)
  1196. {
  1197. if (MidLabelNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1198. {
  1199. //找到了输入的中盒号停止循环
  1200. FindMidLabel = true;
  1201. MidLabelRowIndex = i;
  1202. }
  1203. }
  1204. //找到了指定的盒号
  1205. if (FindMidLabel)
  1206. MidBoxCodePrint(MidLabelRowIndex);
  1207. else
  1208. MessageBox.Show("该出入库单未找到该中盒号!");
  1209. }
  1210. else
  1211. MessageBox.Show("未维护中盒模板");
  1212. }
  1213. private void MidLabelPrint_Click(object sender, EventArgs e)
  1214. {
  1215. if (MidLabelCombox.Text != "")
  1216. {
  1217. thread = new Thread(MidBoxLabelPrint);
  1218. stw = new SetLoadingWindow(thread, "正在打印中盒");
  1219. BaseUtil.SetFormCenter(stw);
  1220. stw.ShowDialog();
  1221. }
  1222. else
  1223. MessageBox.Show("未维护中盒标签");
  1224. }
  1225. private void OutBoxPrint()
  1226. {
  1227. List<string> Outboxcode = new List<string>();
  1228. //如果未勾选箱号则对勾选的数据的箱号进行整合
  1229. if (OutBoxNum.Text == "")
  1230. {
  1231. for (int i = 0; i < LabelInf.RowCount; i++)
  1232. {
  1233. string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  1234. //如果不包含该箱号则进行添加
  1235. if (!Outboxcode.Contains(outboxcode2))
  1236. Outboxcode.Add(outboxcode2);
  1237. }
  1238. //按获取到的箱号列表进行打印
  1239. if (Outboxcode.ToArray().Length > 0)
  1240. {
  1241. try
  1242. {
  1243. // 循环打印外箱号
  1244. for (int i = 0; i < Outboxcode.ToArray().Length; i++)
  1245. {
  1246. for (int h = 0; h < LabelInf.RowCount; h++)
  1247. {
  1248. if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i])
  1249. {
  1250. OutBoxCodePrint(h);
  1251. break;
  1252. }
  1253. }
  1254. }
  1255. }
  1256. catch { }
  1257. }
  1258. else
  1259. {
  1260. MessageBox.Show("请勾选需要打印的外箱");
  1261. }
  1262. }
  1263. else
  1264. {
  1265. bool FindMidLabel = false;
  1266. try
  1267. {
  1268. int OutBoxLabelRowIndex = 0;
  1269. //查找是否存在该中盒号
  1270. for (int i = 0; i < LabelInf.RowCount; i++)
  1271. {
  1272. if (OutBoxNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString())
  1273. {
  1274. //找到了输入的中盒号停止循环
  1275. FindMidLabel = true;
  1276. OutBoxLabelRowIndex = i;
  1277. break;
  1278. }
  1279. }
  1280. //找到了指定的盒号
  1281. if (FindMidLabel)
  1282. OutBoxCodePrint(OutBoxLabelRowIndex);
  1283. else
  1284. MessageBox.Show("该出入库单未找到该外箱号!");
  1285. }
  1286. catch (Exception) { }
  1287. }
  1288. Outboxcode.Clear();
  1289. }
  1290. private void MidBoxCodePrint(int rowindex)
  1291. {
  1292. if (cu_print_checkdatecode.Checked)
  1293. {
  1294. string datecode = LabelInf.Rows[rowindex].Cells["pib_datecode"].Value.ToString();
  1295. string lotno = LabelInf.Rows[rowindex].Cells["pib_lotno"].Value.ToString();
  1296. if (datecode == "" || lotno == "")
  1297. {
  1298. MessageLog.AppendText(">>设定必须采集DateCode内容,请先采集再打印\n", Color.Red);
  1299. return;
  1300. }
  1301. }
  1302. //获取对应行的pib_id
  1303. string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
  1304. string pib_outboxcode1 = LabelInf.Rows[rowindex].Cells["pib_outboxcode1"].Value.ToString();
  1305. sql.Clear();
  1306. //设置最少打印盘数
  1307. if (OnlyPrint.Checked)
  1308. {
  1309. if (adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + pib_outboxcode1) < LeastPrintNum.Value)
  1310. {
  1311. return;
  1312. }
  1313. }
  1314. //查询参数名称相同的获取到取值字段
  1315. for (int j = 0; j < MidDoc.Variables.FormVariables.Count; j++)
  1316. {
  1317. DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name.ToLower() + "'");
  1318. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串")
  1319. {
  1320. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  1321. }
  1322. }
  1323. sql.Append("1,");
  1324. 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");
  1325. for (int j = 0; j < MidDoc.Variables.FormVariables.Count; j++)
  1326. {
  1327. DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name.ToLower() + "'");
  1328. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串")
  1329. {
  1330. MidDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  1331. }
  1332. //SQL判断多个值的时候
  1333. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  1334. {
  1335. DataTable dt1 = (DataTable)adh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno.Text + "'").Replace("{2}", pib_outboxcode1), "select");
  1336. for (int i = 0; i < dt1.Rows.Count; i++)
  1337. {
  1338. for (int k = 0; k < MidDoc.Variables.FormVariables.Count; k++)
  1339. {
  1340. if (i == 0 & MidDoc.Variables.FormVariables.Item(k + 1).Name.ToUpper() == dr1[0]["lp_name"].ToString().ToUpper())
  1341. {
  1342. MidDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[0][0].ToString();
  1343. }
  1344. //使用SN开头的参数赋值SN1,SN2,SN3等参数
  1345. if (MidDoc.Variables.FormVariables.Item(k + 1).Name.ToUpper() == (dr1[0]["lp_name"].ToString() + (i + 1)).ToUpper())
  1346. {
  1347. MidDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[i][0].ToString();
  1348. }
  1349. }
  1350. }
  1351. }
  1352. if (MidDoc.Variables.FormVariables.Item(j + 1).Value == "")
  1353. {
  1354. dr1 = Attach.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name.ToLower() + "'");
  1355. if (dr1.Length > 0)
  1356. MidDoc.Variables.FormVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
  1357. }
  1358. }
  1359. MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
  1360. MidDoc.PrintDocument();
  1361. }
  1362. /// <summary>
  1363. /// 执行打印外箱号
  1364. /// </summary>
  1365. private void OutBoxCodePrint(int rowindex)
  1366. {
  1367. if (cu_print_checkdatecode.Checked)
  1368. {
  1369. string datecode = LabelInf.Rows[rowindex].Cells["pib_datecode"].Value.ToString();
  1370. string lotno = LabelInf.Rows[rowindex].Cells["pib_lotno"].Value.ToString();
  1371. if (datecode == "" || lotno == "")
  1372. {
  1373. MessageLog.AppendText(">>设定必须采集DateCode内容,请先采集再打印\n", Color.Red);
  1374. return;
  1375. }
  1376. }
  1377. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray, adh);
  1378. //获取对应行的pib_id
  1379. string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
  1380. string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
  1381. sql.Clear();
  1382. for (int j = 0; j < OutBoxDoc.Variables.FormVariables.Count; j++)
  1383. {
  1384. DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name.ToLower() + "'");
  1385. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串")
  1386. {
  1387. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  1388. }
  1389. }
  1390. sql.Append("1,");
  1391. 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");
  1392. if (dt.Rows.Count > 0)
  1393. {
  1394. for (int j = 0; j < OutBoxDoc.Variables.FormVariables.Count; j++)
  1395. {
  1396. DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name.ToLower() + "'");
  1397. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串")
  1398. {
  1399. OutBoxDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  1400. }
  1401. //SQL判断多个值的时候
  1402. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  1403. {
  1404. DataTable dt1 = (DataTable)adh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno.Text + "'").Replace("{2}", pib_outboxcode2), "select");
  1405. for (int i = 0; i < dt1.Rows.Count; i++)
  1406. {
  1407. for (int k = 0; k < OutBoxDoc.Variables.FormVariables.Count; k++)
  1408. {
  1409. if (i == 0 & OutBoxDoc.Variables.FormVariables.Item(k + 1).Name.ToUpper() == dr1[0]["lp_name"].ToString().ToUpper())
  1410. {
  1411. OutBoxDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[0][0].ToString();
  1412. }
  1413. //使用SN开头的参数赋值SN1,SN2,SN3等参数
  1414. if (OutBoxDoc.Variables.FormVariables.Item(k + 1).Name.ToUpper() == (dr1[0]["lp_name"].ToString() + (i + 1)).ToUpper())
  1415. {
  1416. OutBoxDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[i][0].ToString();
  1417. }
  1418. }
  1419. }
  1420. }
  1421. if (OutBoxDoc.Variables.FormVariables.Item(j + 1).Value == "")
  1422. {
  1423. dr1 = Attach.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name.ToLower() + "'");
  1424. if (dr1.Length > 0)
  1425. OutBoxDoc.Variables.FormVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
  1426. }
  1427. }
  1428. OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
  1429. OutBoxDoc.PrintDocument();
  1430. }
  1431. }
  1432. private void OutBoxLabelPrint_Click(object sender, EventArgs e)
  1433. {
  1434. if (OutBoxCombox.Text != "")
  1435. {
  1436. thread = new Thread(OutBoxPrint);
  1437. stw = new SetLoadingWindow(thread, "正在打印外箱");
  1438. BaseUtil.SetFormCenter(stw);
  1439. stw.ShowDialog();
  1440. }
  1441. else
  1442. MessageBox.Show("未维护外箱标签");
  1443. }
  1444. /// <summary>
  1445. /// 刷新采集进度
  1446. /// </summary>
  1447. private void RefreshProcessData()
  1448. {
  1449. if (LabelInf.Rows.Count > 0)
  1450. {
  1451. //设置初始化的采集进度
  1452. int Count = Count = adh.getRowCount("prodiobarcode", "pib_ifrecheck=-1 and pib_inoutno='" + pi_inoutno.Text + "'");
  1453. string midboxcode = "";
  1454. string outboxcode = "";
  1455. if (CurrentRowIndex - 1 >= 0)
  1456. {
  1457. midboxcode = adh.getFieldDataByCondition("prodiobarcode", "max(pib_outboxcode1)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  1458. outboxcode = adh.getFieldDataByCondition("prodiobarcode", "max(pib_outboxcode2)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  1459. }
  1460. //未超出当前范围的时候
  1461. int midboxcount = adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + (midboxcode == "" ? "1" : midboxcode));
  1462. int outboxcount = adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2=" + (outboxcode == "" ? "1" : outboxcode));
  1463. midboxProcess.Text = midboxcount + "/" + MidBoxCapacity.Value;
  1464. outboxProcess.Text = outboxcount + "/" + OutBoxCapacity.Value;
  1465. //设置当前的箱号和盒号
  1466. Process_midboxcode.Text = midboxcode == "" ? "1" : midboxcode;
  1467. Process_outboxcode.Text = outboxcode == "" ? "1" : outboxcode;
  1468. //设置当前总数和已采集数量
  1469. CollectedCount.Text = Count + "/" + PageNum.Text.Replace("总数", "");
  1470. }
  1471. }
  1472. private void LoadGridData()
  1473. {
  1474. LoadGridData(new object(), new EventArgs());
  1475. }
  1476. int CurrentPage = 1;
  1477. int PageSize = 500;
  1478. int DataSize = 0;
  1479. int MaxPageSize = 0;
  1480. DataTable LabelInfDataTable;
  1481. /// <summary>
  1482. /// 自定义函数 加载明细行的数据,多处使用添加进函数
  1483. /// </summary>
  1484. /// <param name="sender"></param>
  1485. /// <param name="e"></param>
  1486. private void LoadGridData(object sender, EventArgs e)
  1487. {
  1488. ManualCheckCount.Clear();
  1489. sql.Clear();
  1490. sql.Append("select * from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and rownum ");
  1491. sql.Append("between " + ((CurrentPage - 1) * PageSize + 1) + " and " + CurrentPage * PageSize + " ");
  1492. if (DetailRange.Checked)
  1493. {
  1494. sql.Append(" and pib_pdno between " + DetailRange1.Value + " and " + DetailRange2.Value);
  1495. }
  1496. sql.Append(" order by rownum");
  1497. LabelInfDataTable = (DataTable)adh.ExecuteSql(sql.ToString(), "select");
  1498. if (LabelInfDataTable.Rows.Count == 0)
  1499. {
  1500. //嵌套查询重置RowNum
  1501. sql.Clear();
  1502. sql.Append("select t.*,rownum from (select pd_ordercode,pib_year,pib_month,pib_day,pr_detail,pib_custoutboxcode,pib_custmidboxcode,pr_orispeccode,pd_id,pd_custprodcode,pib_indate,pi_date,pib_inoutno,pd_custprodspec,");
  1503. 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,");
  1504. 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,");
  1505. 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 ");
  1506. 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");
  1507. LabelInfDataTable = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1508. //检验查询的字段和本地数据库字段是否匹配
  1509. adh.AddColumFromDataTable(LabelInfDataTable, "prodiobarcode");
  1510. //将数据保存在本地数据库
  1511. adh.SaveDataTable(LabelInfDataTable, "prodiobarcode");
  1512. if (!DetailRange.Checked)
  1513. {
  1514. LabelInfDataTable = BaseUtil.filterDataTable(LabelInfDataTable, "rownum <=" + PageSize);
  1515. }
  1516. else
  1517. {
  1518. LabelInfDataTable = BaseUtil.filterDataTable(LabelInfDataTable, "rownum <=" + PageSize + " and pib_pdno >= " + DetailRange1.Value + " and pib_pdno<=" + DetailRange2.Value);
  1519. }
  1520. }
  1521. bindingsource(LabelInf, LabelInfDataTable);
  1522. //LabelInf.DataSource = null;
  1523. BaseUtil.FillDgvWithDataTable(LabelInf, LabelInfDataTable);
  1524. //获取数据总条数
  1525. if (!DetailRange.Checked)
  1526. {
  1527. DataSize = adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "'");
  1528. }
  1529. else
  1530. {
  1531. DataSize = adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno between " + DetailRange1.Value + " and " + DetailRange2.Value);
  1532. }
  1533. PageNum.Text = "总数" + DataSize;
  1534. MaxPageSize = DataSize % PageSize == 0 ? DataSize / PageSize : (DataSize / PageSize) + 1;
  1535. PageInf.Text = CurrentPage + "/" + MaxPageSize;
  1536. //获取系统设置的上传数量,如参数异常则默认为100
  1537. dt = (DataTable)adh.ExecuteSql("select uploadnum,splitback,splitfront from dataextra", "select");
  1538. if (dt.Rows.Count > 0)
  1539. {
  1540. if (!int.TryParse(dt.Rows[0]["uploadnum"].ToString(), out UploadNum))
  1541. {
  1542. UploadNum = 100;
  1543. }
  1544. front_sg_separator.Text = dt.Rows[0]["splitfront"].ToString();
  1545. back_sg_separator.Text = dt.Rows[0]["splitback"].ToString();
  1546. }
  1547. //获取所有的匹配脚本
  1548. 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");
  1549. RefreshProcessData();
  1550. }
  1551. delegate void BindDataSource(DataGridView dgv, DataTable dt);//定义委托
  1552. void bindingsource(DataGridView dgv, DataTable dt)
  1553. {
  1554. if (dgv.InvokeRequired)
  1555. {
  1556. dgv.Invoke(new BindDataSource(bindingsource), new object[] { dgv, dt });
  1557. }
  1558. else
  1559. {
  1560. dgv.AutoGenerateColumns = false;
  1561. dgv.DataSource = dt;
  1562. }
  1563. }
  1564. /// <summary>
  1565. /// 重绘Cell的颜色
  1566. /// </summary>
  1567. /// <param name="sender"></param>
  1568. /// <param name="e"></param>
  1569. private void LabelInf_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  1570. {
  1571. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  1572. if (e.ColumnIndex > 0)
  1573. {
  1574. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_lotno" || LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
  1575. {
  1576. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1577. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
  1578. Rectangle border = e.CellBounds;
  1579. border.Width -= 1;
  1580. e.Graphics.DrawRectangle(Pens.White, border);
  1581. e.PaintContent(e.CellBounds);
  1582. e.Handled = true;
  1583. }
  1584. if (e.RowIndex >= 0)
  1585. {
  1586. if (LabelInf.Rows[e.RowIndex].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
  1587. {
  1588. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_lotno" || LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
  1589. {
  1590. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1591. e.Graphics.FillRectangle(Brushes.ForestGreen, e.CellBounds);
  1592. Rectangle border = e.CellBounds;
  1593. border.Width -= 1;
  1594. e.Graphics.DrawRectangle(Pens.Black, border);
  1595. e.PaintContent(e.CellBounds);
  1596. e.Handled = true;
  1597. }
  1598. }
  1599. if (LabelInf.Rows[e.RowIndex].Cells["pib_ifrecheck"].FormattedValue.ToString() == "True")
  1600. {
  1601. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_custbarcode")
  1602. {
  1603. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1604. e.Graphics.FillRectangle(Brushes.CadetBlue, e.CellBounds);
  1605. Rectangle border = e.CellBounds;
  1606. border.Width -= 1;
  1607. e.Graphics.DrawRectangle(Pens.Black, border);
  1608. e.PaintContent(e.CellBounds);
  1609. e.Handled = true;
  1610. }
  1611. }
  1612. }
  1613. }
  1614. }
  1615. private void CusLabelPrint()
  1616. {
  1617. //MaxOutBoxCode = MaxOutBoxCode + 1;
  1618. List<int> CusOutBoxCode = new List<int>();
  1619. //统计客户外箱号
  1620. if (LabelInf.Rows.Count > 0)
  1621. CusOutBoxCode.Add(0);
  1622. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1623. {
  1624. if (i - 1 > 0 && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() == "True")
  1625. {
  1626. string cutboxcode = LabelInf.Rows[i].Cells["pib_cusoutboxcode"].Value.ToString();
  1627. string nextcutboxcode = LabelInf.Rows[i - 1].Cells["pib_cusoutboxcode"].Value.ToString();
  1628. if (cutboxcode != nextcutboxcode)
  1629. CusOutBoxCode.Add(i);
  1630. }
  1631. }
  1632. }
  1633. private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1634. {
  1635. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  1636. pi_inoutno_KeyDown(sender, e2);
  1637. }
  1638. private void AutoPrintMidLabel()
  1639. {
  1640. if (adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value) == MidBoxCapacity.Value)
  1641. {
  1642. if (MidLabelCombox.SelectedValue != null)
  1643. {
  1644. MidBoxCodePrint(CurrentRowIndex);
  1645. }
  1646. else
  1647. MessageBox.Show("未维护中盒模板");
  1648. }
  1649. }
  1650. private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1651. {
  1652. string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1653. if (close.ToString() == "Yes")
  1654. {
  1655. Login login = new Login();
  1656. //注销的时候需要将拼接的连接字符串置空
  1657. DataHelper.DBConnectionString = null;
  1658. logout = true;
  1659. lbl.Quit();
  1660. this.Hide();
  1661. login.ShowDialog();
  1662. this.Close();
  1663. }
  1664. }
  1665. private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1666. /// <summary>
  1667. /// 切换打开的单盘文件
  1668. /// </summary>
  1669. /// <param name="sender"></param>
  1670. /// <param name="e"></param>
  1671. private void SingleLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1672. {
  1673. try
  1674. {
  1675. if (ComBoxClickChangeLabelDoc)
  1676. {
  1677. if (SingleDoc != null)
  1678. SingleDoc.Close();
  1679. if (SingleLabelCombox.Text != "" && SingleLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  1680. {
  1681. System.DateTime time = Convert.ToDateTime(SingleLabelCombox.SelectedValue.ToString().Split('#')[2]);
  1682. SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
  1683. }
  1684. }
  1685. }
  1686. catch (Exception) { }
  1687. }
  1688. /// <summary>
  1689. /// 切换打开的中盒文件
  1690. /// </summary>
  1691. /// <param name="sender"></param>
  1692. /// <param name="e"></param>
  1693. private void MidLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1694. {
  1695. try
  1696. {
  1697. if (ComBoxClickChangeLabelDoc)
  1698. {
  1699. if (MidDoc != null)
  1700. MidDoc.Close();
  1701. if (MidLabelCombox.Text != "" && MidLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  1702. {
  1703. System.DateTime time = Convert.ToDateTime(MidLabelCombox.SelectedValue.ToString().Split('#')[2]);
  1704. MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
  1705. }
  1706. }
  1707. }
  1708. catch (Exception) { }
  1709. }
  1710. /// <summary>
  1711. /// 切换打开的外箱文件
  1712. /// </summary>
  1713. /// <param name="sender"></param>
  1714. /// <param name="e"></param>
  1715. private void OutBoxCombox_SelectedIndexChanged(object sender, EventArgs e)
  1716. {
  1717. try
  1718. {
  1719. if (ComBoxClickChangeLabelDoc)
  1720. {
  1721. if (OutBoxDoc != null)
  1722. OutBoxDoc.Close();
  1723. if (OutBoxCombox.Text != "" && OutBoxCombox.SelectedValue != null && !GetGridOnly.Checked)
  1724. {
  1725. System.DateTime time = Convert.ToDateTime(OutBoxCombox.SelectedValue.ToString().Split('#')[2]);
  1726. OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
  1727. }
  1728. }
  1729. }
  1730. catch (Exception) { }
  1731. }
  1732. private void ExportData_Click(object sender, EventArgs e)
  1733. {
  1734. ExportFileDialog.Description = "选择导出的路径";
  1735. DialogResult result = ExportFileDialog.ShowDialog();
  1736. DataTable dt = (DataTable)adh.ExecuteSql("select * from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "select");
  1737. if (result == DialogResult.OK)
  1738. {
  1739. ExcelHandler eh = new ExcelHandler();
  1740. for (int i = dt.Columns.Count - 1; i >= 0; i--)
  1741. {
  1742. for (int j = 0; j < LabelInf.Columns.Count; j++)
  1743. {
  1744. //去除ID列
  1745. 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")
  1746. {
  1747. dt.Columns.RemoveAt(i);
  1748. break;
  1749. }
  1750. switch (dt.Columns[i].ColumnName.ToLower())
  1751. {
  1752. case "pib_lotno":
  1753. dt.Columns[i].ColumnName = "批次号";
  1754. break;
  1755. case "pib_datecode":
  1756. dt.Columns[i].ColumnName = "生产日期";
  1757. break;
  1758. case "pib_custbarcode":
  1759. dt.Columns[i].ColumnName = "最小产品包装条码";
  1760. break;
  1761. default:
  1762. break;
  1763. }
  1764. if (dt.Columns[i].ColumnName.ToLower() == LabelInf.Columns[j].DataPropertyName.ToLower())
  1765. {
  1766. dt.Columns[i].ColumnName = LabelInf.Columns[j].HeaderText;
  1767. break;
  1768. }
  1769. }
  1770. }
  1771. eh.ExportExcel(dt, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text);
  1772. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1773. if (close.ToString() == "Yes")
  1774. System.Diagnostics.Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + ".xls");
  1775. }
  1776. }
  1777. private void MidBoxCapacity_Leave(object sender, EventArgs e)
  1778. {
  1779. NumericUpDown nup = (NumericUpDown)sender;
  1780. switch (nup.Name)
  1781. {
  1782. case "MidBoxCapacity":
  1783. Properties.Settings.Default.MidBoxCapacity = nup.Value;
  1784. Properties.Settings.Default.Save();
  1785. break;
  1786. case "OutboxCapacity":
  1787. Properties.Settings.Default.OutboxCapacity = nup.Value;
  1788. Properties.Settings.Default.Save();
  1789. break;
  1790. default:
  1791. break;
  1792. }
  1793. }
  1794. private void RefreshDBConnect_Tick(object sender, EventArgs e)
  1795. {
  1796. dh.getRowCount("employee", "1=1");
  1797. }
  1798. private void ButtonSetting_Click(object sender, EventArgs e)
  1799. {
  1800. ListButtonMenu.BringToFront();
  1801. ListButtonMenu.Visible = true;
  1802. }
  1803. private void ListButtonMenu_SelectedIndexChanged(object sender, EventArgs e)
  1804. {
  1805. ListButtonMenu.Visible = false;
  1806. switch (ListButtonMenu.SelectedItem.ToString())
  1807. {
  1808. case "采集策略设置":
  1809. 采集策略_NEW form = new 采集策略_NEW();
  1810. BaseUtil.SetFormCenter(form);
  1811. form.ShowDialog();
  1812. break;
  1813. case "生成条码":
  1814. 生成条码 form3 = new 生成条码(pi_inoutno.Text);
  1815. BaseUtil.SetFormCenter(form3);
  1816. form3.ShowDialog();
  1817. break;
  1818. case "附加信息设置":
  1819. if (pi_cardcode.Text != "")
  1820. {
  1821. 附件内容打印 att = new 附件内容打印(pi_cardcode.Text);
  1822. att.ShowDialog();
  1823. }
  1824. else MessageBox.Show("请先获取出库单信息");
  1825. break;
  1826. case "客户标签维护":
  1827. 客户标签维护 form1 = new 客户标签维护();
  1828. BaseUtil.SetFormCenter(form1);
  1829. if (SingleDoc != null)
  1830. SingleDoc.Close();
  1831. if (MidDoc != null)
  1832. MidDoc.Close();
  1833. if (OutBoxDoc != null)
  1834. OutBoxDoc.Close();
  1835. form1.FormClosed += LabelFormClose;
  1836. form1.ShowDialog();
  1837. break;
  1838. case "客户采集规则":
  1839. CustomerRule cust = new CustomerRule();
  1840. BaseUtil.SetFormCenter(cust);
  1841. cust.ShowDialog();
  1842. break;
  1843. case "参数配置":
  1844. ParamSetting form2 = new ParamSetting();
  1845. form2.FormClosed += Form2_FormClosed;
  1846. BaseUtil.SetFormCenter(form2);
  1847. form2.ShowDialog();
  1848. break;
  1849. case "权限管理":
  1850. PowerSetting pws = new PowerSetting();
  1851. BaseUtil.SetFormCenter(pws);
  1852. pws.ShowDialog();
  1853. break;
  1854. default:
  1855. break;
  1856. }
  1857. }
  1858. private void Form2_FormClosed(object sender, FormClosedEventArgs e)
  1859. {
  1860. RefreshPLCInstruct();
  1861. }
  1862. private void DetailRange_CheckedChanged(object sender, EventArgs e)
  1863. {
  1864. if (DetailRange.Checked)
  1865. {
  1866. if (DetailRange1.Value > DetailRange2.Value)
  1867. {
  1868. MessageBox.Show("请输入正确的范围");
  1869. DetailRange.Checked = false;
  1870. return;
  1871. }
  1872. if (DetailRange1.Value == DetailRange2.Value)
  1873. {
  1874. if (dh.getRowCount("prodiodetail", "pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno in(" + DetailRange1.Value + ")") != 1)
  1875. {
  1876. MessageBox.Show("出货单" + pi_inoutno.Text + "不存在明细序号" + DetailRange1.Value);
  1877. DetailRange.Checked = false;
  1878. return;
  1879. }
  1880. }
  1881. else
  1882. {
  1883. if (dh.getRowCount("prodiodetail", "pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno in(" + DetailRange1.Value + "," + DetailRange2.Value + ")") != 2)
  1884. {
  1885. MessageBox.Show("出货单" + pi_inoutno.Text + "不存在明细序号" + DetailRange1.Value + "或" + DetailRange2.Value);
  1886. DetailRange.Checked = false;
  1887. return;
  1888. }
  1889. }
  1890. DetailRange1.Enabled = false;
  1891. DetailRange2.Enabled = false;
  1892. LoadGridData();
  1893. }
  1894. else
  1895. {
  1896. LoadGridData();
  1897. DetailRange1.Enabled = true;
  1898. DetailRange2.Enabled = true;
  1899. }
  1900. }
  1901. private void PLCStart_Click(object sender, EventArgs e)
  1902. {
  1903. //查询前端检验的端口号
  1904. DataTable dt = (DataTable)adh.ExecuteSql("select * from cominfo", "select");
  1905. DataRow[] dr = dt.Select("comtype='PLC1'");
  1906. if (dr.Length > 0)
  1907. {
  1908. if (!PLC1.IsOpen)
  1909. {
  1910. PLC1.PortName = dr[0]["COM"].ToString();
  1911. PLC1.Tag = "PLC1";
  1912. PLC1.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
  1913. PLC1.DataReceived += Serial_DataReceived;
  1914. PLC1.Open();
  1915. }
  1916. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.DeviceStart, adh);
  1917. MessageLog.AppendText("PLC启动成功\n", Color.Blue);
  1918. }
  1919. adh.ExecuteSql("update prodiobarcode set pib_ifpick=0,pib_ifprint=0,pib_ifmodify=0 where pib_ifrecheck=0 and pib_inoutno='" + pi_inoutno.Text + "'", "update");
  1920. dr = LabelInfDataTable.Select("pib_ifrecheck=0");
  1921. for (int i = 0; i < dr.Length; i++)
  1922. {
  1923. dr[i]["pib_ifpick"] = 0;
  1924. dr[i]["pib_ifprint"] = 0;
  1925. dr[i]["pib_ifmodify"] = 0;
  1926. }
  1927. LabelInf.Invalidate();
  1928. }
  1929. private void PLCStop_Click(object sender, EventArgs e)
  1930. {
  1931. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.DeviceStop, adh);
  1932. MessageLog.AppendText("PLC暂停成功\n", Color.Blue);
  1933. }
  1934. private void ButtonCollectPass_Click(object sender, EventArgs e)
  1935. {
  1936. int pib_pdno = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["pib_pdno"].Value.ToString());
  1937. string ErrorMsg = "";
  1938. FrontCheckFunction("", out ErrorMsg);
  1939. }
  1940. private void ButtonRecheckPass_Click(object sender, EventArgs e)
  1941. {
  1942. string ErrorMsg = "";
  1943. int pib_pdno = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["pib_pdno"].Value.ToString());
  1944. BackendCheckFunction("", "Auto", out ErrorMsg);
  1945. }
  1946. private void ButtonSetMidBox_Click(object sender, EventArgs e)
  1947. {
  1948. Process_midboxcode.Text = SetMidBox.Text;
  1949. }
  1950. private void ButtonSetOutBox_Click(object sender, EventArgs e)
  1951. {
  1952. Process_outboxcode.Text = SetOutBox.Text;
  1953. }
  1954. private void Collection_CheckedChanged(object sender, EventArgs e)
  1955. {
  1956. ButtonCollectPass.Enabled = ManualCollection.Checked;
  1957. ButtonRecheckPass.Enabled = ManualCollection.Checked;
  1958. ButtonSetMidBox.Enabled = ManualCollection.Checked;
  1959. ButtonSetOutBox.Enabled = ManualCollection.Checked;
  1960. ManualFrontCheck.Enabled = ManualCollection.Checked;
  1961. ManualBackCheck.Enabled = ManualCollection.Checked;
  1962. ManualAutoCheck.Enabled = ManualCollection.Checked;
  1963. if (AutoCollection.Checked)
  1964. {
  1965. ManualFrontCheck.Checked = false;
  1966. ManualBackCheck.Checked = false;
  1967. ManualAutoCheck.Checked = false;
  1968. }
  1969. }
  1970. private void AddCutBox_Click(object sender, EventArgs e)
  1971. {
  1972. Button button = sender as Button;
  1973. switch (button.Name)
  1974. {
  1975. case "AddMidBox":
  1976. Process_midboxcode.Text = (int.Parse(Process_midboxcode.Text) + 1).ToString();
  1977. break;
  1978. case "CutMidBox":
  1979. if (int.Parse(Process_midboxcode.Text) > 1)
  1980. Process_midboxcode.Text = (int.Parse(Process_midboxcode.Text) - 1).ToString();
  1981. break;
  1982. case "AddOutBox":
  1983. Process_outboxcode.Text = (int.Parse(Process_outboxcode.Text) + 1).ToString();
  1984. break;
  1985. case "CutOutBox":
  1986. if (int.Parse(Process_outboxcode.Text) > 1)
  1987. Process_outboxcode.Text = (int.Parse(Process_outboxcode.Text) - 1).ToString();
  1988. break;
  1989. default:
  1990. break;
  1991. }
  1992. }
  1993. private void Page_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1994. {
  1995. switch ((sender as LinkLabel).Name)
  1996. {
  1997. case "FirstPage":
  1998. CurrentPage = 1;
  1999. break;
  2000. case "LastPage":
  2001. CurrentPage = MaxPageSize;
  2002. break;
  2003. case "BeforePage":
  2004. if (CurrentPage == 1)
  2005. {
  2006. MessageBox.Show("已经是第一页了", "提示");
  2007. return;
  2008. }
  2009. CurrentPage = CurrentPage - 1;
  2010. break;
  2011. case "NextPage":
  2012. if (CurrentPage == MaxPageSize)
  2013. {
  2014. MessageBox.Show("已经是最后一页了", "提示");
  2015. return;
  2016. }
  2017. CurrentPage = CurrentPage + 1;
  2018. break;
  2019. default:
  2020. break;
  2021. }
  2022. PageInf.Text = CurrentPage + "/" + MaxPageSize;
  2023. LoadGridData();
  2024. }
  2025. Dictionary<string, string> instruct = new Dictionary<string, string>();
  2026. private void RefreshPLCInstruct()
  2027. {
  2028. //查询所有的PLC指令
  2029. DataTable dtPLCInstruct = (DataTable)adh.ExecuteSql("select * from PLCInstruct", "select");
  2030. instruct.Clear();
  2031. //如果存在指令参数的话则全部添加到键值对当中
  2032. if (dtPLCInstruct.Rows.Count > 0)
  2033. {
  2034. for (int i = 0; i < dtPLCInstruct.Columns.Count; i++)
  2035. {
  2036. instruct.Add(dtPLCInstruct.Columns[i].ColumnName, dtPLCInstruct.Rows[0][dtPLCInstruct.Columns[i].ColumnName].ToString());
  2037. }
  2038. }
  2039. }
  2040. private void MessageLog_MouseUp(object sender, MouseEventArgs e)
  2041. {
  2042. if (e.Button == MouseButtons.Right)
  2043. {
  2044. LogMenu.Show(new Point(MessageLog.Location.X + 100, MessageLog.Location.Y + 20));
  2045. }
  2046. }
  2047. private void UploadData_Click(object sender, EventArgs e)
  2048. {
  2049. if (LogicHandler.CheckUploadData(pi_inoutno.Text))
  2050. {
  2051. DataTable dtt = LabelInf.DataSource as DataTable;
  2052. for (int i = 0; i < dtt.Rows.Count; i++)
  2053. {
  2054. if (dtt.Rows[i]["pib_ifrecheck"].ToString() != "0" && dtt.Rows[i]["pib_ifupload"].ToString() == "0")
  2055. {
  2056. dtt.Rows[i]["pib_ifupload"] = -1;
  2057. }
  2058. }
  2059. MessageLog.AppendText(">>上传数据成功\n", Color.Green);
  2060. }
  2061. else
  2062. {
  2063. MessageLog.AppendText(">>无可上传数据\n", Color.Red);
  2064. }
  2065. }
  2066. private void DocRefresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2067. {
  2068. switch ((sender as Control).Name)
  2069. {
  2070. case "SingleDocRefresh":
  2071. if (SingleDoc != null)
  2072. SingleDoc.Close();
  2073. if (SingleLabelCombox.Text != "" && SingleLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  2074. {
  2075. System.DateTime time = Convert.ToDateTime(SingleLabelCombox.SelectedValue.ToString().Split('#')[2]);
  2076. SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
  2077. }
  2078. break;
  2079. case "MidDocRefresh":
  2080. if (MidDoc != null)
  2081. MidDoc.Close();
  2082. if (MidLabelCombox.Text != "" && MidLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  2083. {
  2084. System.DateTime time = Convert.ToDateTime(MidLabelCombox.SelectedValue.ToString().Split('#')[2]);
  2085. MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
  2086. }
  2087. break;
  2088. case "OutDocRefresh":
  2089. if (OutBoxDoc != null)
  2090. OutBoxDoc.Close();
  2091. if (OutBoxCombox.Text != "" && OutBoxCombox.SelectedValue != null && !GetGridOnly.Checked)
  2092. {
  2093. System.DateTime time = Convert.ToDateTime(OutBoxCombox.SelectedValue.ToString().Split('#')[2]);
  2094. OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
  2095. }
  2096. break;
  2097. default:
  2098. break;
  2099. }
  2100. }
  2101. private void PageSizeNum_ValueChanged(object sender, EventArgs e)
  2102. {
  2103. PageSize = int.Parse(PageSizeNum.Value.ToString());
  2104. LoadGridData();
  2105. }
  2106. private void button1_Click(object sender, EventArgs e)
  2107. {
  2108. string close = MessageBox.Show(this.ParentForm, "是否重新下载服务端条码,将会覆盖本地记录", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  2109. if (close.ToString() == "Yes")
  2110. {
  2111. adh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  2112. LoadGridData();
  2113. }
  2114. }
  2115. private void LabelInf_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  2116. {
  2117. string columnname = LabelInf.Columns[e.ColumnIndex].Name;
  2118. if (columnname == "pib_lotno" || columnname == "pib_datecode")
  2119. {
  2120. string data = LabelInf.Rows[e.RowIndex].Cells[columnname].Value.ToString();
  2121. if (data != "")
  2122. {
  2123. string close = MessageBox.Show(this.ParentForm, "确认修改该出货明细行" + columnname.Replace("pib_", ""), "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  2124. if (close.ToString() == "Yes")
  2125. {
  2126. string pib_pdno = LabelInf.Rows[e.RowIndex].Cells["pib_pdno"].Value.ToString();
  2127. DataRow[] dr = (LabelInf.DataSource as DataTable).Select("pib_pdno=" + pib_pdno);
  2128. for (int i = 0; i < dr.Length; i++)
  2129. {
  2130. dr[i][columnname] = data;
  2131. dr[i]["pib_ifmodify"] = -1;
  2132. dr[i]["pib_ifpick"] = -1;
  2133. }
  2134. adh.UpdateByCondition("prodiobarcode", columnname + "='" + data + "',pib_ifmodify=-1,pib_ifpick=-1", "pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pib_pdno + "");
  2135. LabelInf.Invalidate();
  2136. }
  2137. }
  2138. }
  2139. }
  2140. private void ManualCheck_CheckedChanged(object sender, EventArgs e)
  2141. {
  2142. RadioButton ctl = sender as RadioButton;
  2143. if (ctl.Checked)
  2144. {
  2145. switch (ctl.Name)
  2146. {
  2147. case "ManualBackCheck":
  2148. MessageLog.AppendText(">>切换为手动复核模式,需扫描两段数据\n", Color.Blue);
  2149. break;
  2150. default:
  2151. break;
  2152. }
  2153. }
  2154. }
  2155. int rowindex = 0;
  2156. private void LabelInf_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  2157. {
  2158. if (e.Button == MouseButtons.Right)
  2159. {
  2160. rowindex = e.RowIndex;
  2161. DateCodeSetAndPrint date = new DateCodeSetAndPrint();
  2162. date.Controls["SetValue"].Click += SetValue_ButtonClick;
  2163. date.Controls["SetValueAndPrint"].Click += SetValueAndPrint_ButtonClick;
  2164. date.ShowDialog();
  2165. }
  2166. }
  2167. private void SetValue_ButtonClick(object sender, EventArgs e)
  2168. {
  2169. Button setvalue = sender as Button;
  2170. string pdno = LabelInf.Rows[rowindex].Cells["pib_pdno"].Value.ToString();
  2171. string datecode = setvalue.FindForm().Controls["datecode"].Text;
  2172. string lotno = setvalue.FindForm().Controls["lotno"].Text;
  2173. string year = "0";
  2174. string month = "0";
  2175. string day = "0";
  2176. LogicHandler.GetTimeFromDatecode(datecode, "", out year, out month, out day);
  2177. adh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_ifmodify=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year=" + year + ",pib_month=" + month + ",pib_day=" + day + " where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno, "update");
  2178. LoadGridData();
  2179. setvalue.FindForm().Close();
  2180. }
  2181. private void SetValueAndPrint_ButtonClick(object sender, EventArgs e)
  2182. {
  2183. Button setvalueandprint = sender as Button;
  2184. string pdno = LabelInf.Rows[rowindex].Cells["pib_pdno"].Value.ToString();
  2185. string datecode = setvalueandprint.FindForm().Controls["datecode"].Text;
  2186. string lotno = setvalueandprint.FindForm().Controls["lotno"].Text;
  2187. string year = "0";
  2188. string month = "0";
  2189. string day = "0";
  2190. LogicHandler.GetTimeFromDatecode(datecode, "", out year, out month, out day);
  2191. adh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_ifmodify=-1,pib_ifprint=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year=" + year + ",pib_month=" + month + ",pib_day=" + day + " where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno, "update");
  2192. LoadGridData();
  2193. DataTable pibid_dt = (DataTable)adh.ExecuteSql("select pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno, "select");
  2194. for (int i = 0; i < pibid_dt.Rows.Count; i++)
  2195. {
  2196. SinglePrint(pibid_dt.Rows[i]["pib_id1"].ToString());
  2197. }
  2198. setvalueandprint.FindForm().Close();
  2199. }
  2200. private void ResetBarcode_Click(object sender, EventArgs e)
  2201. {
  2202. string close = MessageBox.Show(this.ParentForm, "是否重置本单据条码", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  2203. if (close == "Yes")
  2204. {
  2205. dh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  2206. adh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  2207. }
  2208. }
  2209. private void SetOutboxBarcode()
  2210. {
  2211. string year = "0";
  2212. string month = "0";
  2213. string day = "0";
  2214. //解析DateCode,将值设置到年月日
  2215. try
  2216. {
  2217. LogicHandler.GetTimeFromDatecode(DateCode, "", out year, out month, out day);
  2218. LabelInf.Rows[CurrentRowIndex].Cells["pib_year"].Value = year;
  2219. LabelInf.Rows[CurrentRowIndex].Cells["pib_month"].Value = month;
  2220. LabelInf.Rows[CurrentRowIndex].Cells["pib_day"].Value = day;
  2221. }
  2222. catch (Exception) { }
  2223. int outboxcode1 = int.Parse(Process_midboxcode.Text == "" ? "1" : Process_midboxcode.Text);
  2224. int outboxcode2 = int.Parse(Process_outboxcode.Text == "" ? "1" : Process_outboxcode.Text);
  2225. string pd_id = LabelInf.Rows[CurrentRowIndex].Cells["pd_id"].Value.ToString();
  2226. //如果满容量获取过箱号就不再重复获取了
  2227. bool GetBarcode = false;
  2228. //超过中盒容量中盒号+1
  2229. if (adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + outboxcode1) >= MidBoxCapacity.Value)
  2230. {
  2231. outboxcode1 = outboxcode1 + 1;
  2232. GetBarcode = true;
  2233. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
  2234. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray, adh);
  2235. }
  2236. //获取当前的行号
  2237. int CurrentRowNum = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["rownum"].Value.ToString());
  2238. //获取上一行的数据
  2239. DataTable LastRowData = null;
  2240. if (CurrentRowNum - 1 > 0)
  2241. {
  2242. 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");
  2243. //或者不符合合并条件中盒号+1
  2244. if (cu_print_midlotno.Checked)
  2245. {
  2246. string TempData = LastRowData.Rows[0]["pib_lotno"].ToString();
  2247. if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString() && !GetBarcode)
  2248. {
  2249. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
  2250. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray, adh);
  2251. LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
  2252. outboxcode1 = outboxcode1 + 1;
  2253. }
  2254. }
  2255. else if (cu_print_midpo.Checked)
  2256. {
  2257. string TempData = LastRowData.Rows[0]["pd_pocode"].ToString();
  2258. if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString() && !GetBarcode)
  2259. {
  2260. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
  2261. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray, adh);
  2262. LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
  2263. outboxcode1 = outboxcode1 + 1;
  2264. }
  2265. }
  2266. else if (cu_print_midprod.Checked)
  2267. {
  2268. string TempData = LastRowData.Rows[0]["pd_custprodcode"].ToString();
  2269. if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString() && !GetBarcode)
  2270. {
  2271. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
  2272. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray, adh);
  2273. LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
  2274. outboxcode1 = outboxcode1 + 1;
  2275. }
  2276. }
  2277. else if (cu_print_midspec.Checked)
  2278. {
  2279. string TempData = LastRowData.Rows[0]["pd_custprodspec"].ToString();
  2280. if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodspec"].Value.ToString() && !GetBarcode)
  2281. {
  2282. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
  2283. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray, adh);
  2284. LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
  2285. outboxcode1 = outboxcode1 + 1;
  2286. }
  2287. }
  2288. else if (cu_print_middc.Checked)
  2289. {
  2290. string TempData = LastRowData.Rows[0]["pib_datecode"].ToString();
  2291. if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString() && !GetBarcode)
  2292. {
  2293. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
  2294. LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray, adh);
  2295. LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
  2296. outboxcode1 = outboxcode1 + 1;
  2297. }
  2298. }
  2299. if (LastRowData.Rows[0]["pib_custmidboxcode"].ToString() == MidBoxBarCode)
  2300. LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = LastRowData.Rows[0]["pib_custmidboxcode"].ToString();
  2301. else
  2302. LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
  2303. }
  2304. else
  2305. {
  2306. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
  2307. LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
  2308. }
  2309. GetBarcode = false;
  2310. if (adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2=" + outboxcode2) >= OutBoxCapacity.Value)
  2311. {
  2312. GetBarcode = true;
  2313. outboxcode2 = outboxcode2 + 1;
  2314. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
  2315. Console.WriteLine("1" + OutBoxBarCode);
  2316. LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
  2317. }
  2318. else if (CurrentRowNum - 1 > 0)
  2319. {
  2320. //或者不符合合并条件中盒号+1
  2321. if (cu_print_outlotno.Checked)
  2322. {
  2323. string TempData = LastRowData.Rows[0]["pib_lotno"].ToString();
  2324. if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString() && !GetBarcode)
  2325. {
  2326. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
  2327. Console.WriteLine("2" + OutBoxBarCode);
  2328. LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
  2329. }
  2330. }
  2331. else if (cu_print_outpo.Checked)
  2332. {
  2333. string TempData = LastRowData.Rows[0]["pd_pocode"].ToString();
  2334. if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString() && !GetBarcode)
  2335. {
  2336. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
  2337. Console.WriteLine("3" + OutBoxBarCode);
  2338. LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
  2339. }
  2340. }
  2341. else if (cu_print_outprod.Checked)
  2342. {
  2343. string TempData = LastRowData.Rows[0]["pd_custprodcode"].ToString();
  2344. if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString() && !GetBarcode)
  2345. {
  2346. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
  2347. Console.WriteLine("4" + OutBoxBarCode);
  2348. LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
  2349. }
  2350. }
  2351. else if (cu_print_outspec.Checked)
  2352. {
  2353. string TempData = LastRowData.Rows[0]["pd_custprodspec"].ToString();
  2354. if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodspec"].Value.ToString() && !GetBarcode)
  2355. {
  2356. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
  2357. Console.WriteLine("5" + OutBoxBarCode);
  2358. LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
  2359. }
  2360. }
  2361. else if (cu_print_outdc.Checked)
  2362. {
  2363. string TempData = LastRowData.Rows[0]["pib_datecode"].ToString();
  2364. if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString() && !GetBarcode)
  2365. {
  2366. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
  2367. Console.WriteLine("6" + OutBoxBarCode);
  2368. LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
  2369. }
  2370. }
  2371. if (OutBoxBarCode == LastRowData.Rows[0]["pib_custoutboxcode"].ToString())
  2372. LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = LastRowData.Rows[0]["pib_custoutboxcode"].ToString();
  2373. else
  2374. LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
  2375. }
  2376. else
  2377. {
  2378. LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
  2379. Console.WriteLine("1" + OutBoxBarCode);
  2380. LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
  2381. }
  2382. //设置中盒外箱号
  2383. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value = outboxcode1;
  2384. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = outboxcode2;
  2385. string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
  2386. if (SingleLabelAutoPrint.Checked)
  2387. adh.ExecuteSql("update prodiobarcode set pib_year=" + year + ",pib_month=" + month + ",pib_day=" + day + ",pib_outboxcode2=" + outboxcode2 + ",pib_outboxcode1=" + outboxcode1 + ",pib_custoutboxcode='" + OutBoxBarCode + "',pib_custmidboxcode='" + MidBoxBarCode + "',pib_lotno='" + LotNo + "',pib_datecode='" + DateCode + "',pib_ifpick=-1,pib_ifmodify=-1,pib_ifprint=-1 where pib_id=" + pib_id, "update");
  2388. else
  2389. adh.ExecuteSql("update prodiobarcode set pib_year=" + year + ",pib_month=" + month + ",pib_day=" + day + ",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");
  2390. LabelInf.Invalidate();
  2391. }
  2392. private void SinglePrint(string pib_id)
  2393. {
  2394. sql.Clear();
  2395. for (int j = 0; j < SingleDoc.Variables.FormVariables.Count; j++)
  2396. {
  2397. DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FormVariables.Item(j + 1).Name.ToLower() + "'");
  2398. if (dr1.Length > 0)
  2399. {
  2400. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  2401. }
  2402. }
  2403. sql.Append("1,");
  2404. DataTable dt = (DataTable)adh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_id=" + pib_id, "select");
  2405. for (int j = 0; j < SingleDoc.Variables.FormVariables.Count; j++)
  2406. {
  2407. DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FormVariables.Item(j + 1).Name.ToLower() + "'");
  2408. if (dr1.Length > 0)
  2409. {
  2410. SingleDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  2411. }
  2412. if (SingleDoc.Variables.FormVariables.Item(j + 1).Value == "")
  2413. {
  2414. dr1 = Attach.Select("lp_name='" + SingleDoc.Variables.FormVariables.Item(j + 1).Name.ToLower() + "'");
  2415. if (dr1.Length > 0)
  2416. SingleDoc.Variables.FormVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
  2417. }
  2418. }
  2419. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  2420. SingleDoc.PrintDocument();
  2421. LogicHandler.UpdateRowPrinted(pib_id);
  2422. }
  2423. }
  2424. }