UAS_出货标签管理.cs 88 KB

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