UAS_出货标签管理.cs 101 KB

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