UAS_出货标签管理.cs 89 KB

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