UAS_出货标签管理.cs 105 KB

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