UAS_出货标签管理.cs 101 KB

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