UAS_出货标签管理.cs 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570
  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.Globalization;
  16. using FastReport;
  17. namespace UAS_LabelMachine
  18. {
  19. public partial class UAS_出货标签打印 : Form
  20. {
  21. //自适应屏幕
  22. AutoSizeFormClass asc = new AutoSizeFormClass();
  23. DataHelper dh;
  24. DataTable dt;
  25. StringBuilder sql = new StringBuilder();
  26. /// <summary>
  27. /// CodeSoft新建打印机引擎
  28. /// </summary>
  29. ApplicationClass lbl;
  30. /// <summary>
  31. /// 单盘打印文件
  32. /// </summary>
  33. Report SingleReport = new Report();
  34. /// <summary>
  35. /// 中盒打印文件
  36. /// </summary>
  37. Report MidReport = new Report();
  38. /// <summary>
  39. /// 外箱打印文件
  40. /// </summary>
  41. Report OutReport = new Report();
  42. /// <summary>
  43. /// 唛头文件
  44. /// </summary>
  45. Document FootDoc;
  46. /// <summary>
  47. /// Loading窗口
  48. /// </summary>
  49. SetLoadingWindow stw;
  50. /// <summary>
  51. /// 弹窗线程
  52. /// </summary>
  53. Thread thread;
  54. /// <summary>
  55. /// 当前品牌
  56. /// </summary>
  57. string PI_ID;
  58. bool logout = false;
  59. //主表数据源
  60. DataTable LabelInfDataTable;
  61. /// <summary>
  62. /// 存放单盘的ID
  63. /// </summary>
  64. List<string> SingleID = new List<string>();
  65. /// <summary>
  66. /// 是否全选
  67. /// </summary>
  68. bool AllChecked = false;
  69. /// <summary>
  70. /// 是否通过选择Combox来改变打开的文件
  71. /// </summary>
  72. bool ComBoxClickChangeLabelDoc = false;
  73. //当前采集的物料编号
  74. string CurrentPrCode = "";
  75. //当前采集的最小包装
  76. string CurrentZXBZ = "";
  77. //当前采集的单位
  78. string CurrentUnit = "";
  79. //当前采集的总数
  80. string CurrentPrCount = "";
  81. //当前明细序号
  82. string CurrentPDNO = "";
  83. //当前的物料品牌
  84. string CurrentBrand = "";
  85. string Prefix = "";
  86. string Suffix = "";
  87. int MaxNum = 0;
  88. int NumLength = 0;
  89. int Radix = 0;
  90. private bool EnablePrint = true;
  91. string[] PIBID;
  92. DataTable Attach;
  93. public UAS_出货标签打印(string Master)
  94. {
  95. InitializeComponent();
  96. Text = Text + "-" + Master;
  97. }
  98. protected override void WndProc(ref Message m)
  99. {
  100. //拦截双击标题栏、移动窗体的系统消息
  101. if (m.Msg != 0xA3)
  102. {
  103. base.WndProc(ref m);
  104. }
  105. }
  106. private void 贴标机条码打印_Load(object sender, EventArgs e)
  107. {
  108. //杀死之前全部未关闭的进程
  109. Process[] processes = Process.GetProcessesByName("lppa");
  110. for (int i = 0; i < processes.Length; i++)
  111. {
  112. processes[i].Kill();
  113. }
  114. //用计时器重置数据库链接
  115. LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】");
  116. dh = SystemInf.dh;
  117. CheckForIllegalCrossThreadCalls = false;
  118. pi_inoutno.Focus();
  119. Point pt = new Point();
  120. //禁止所有列的排序
  121. foreach (DataGridViewColumn dgv in LabelInf.Columns)
  122. {
  123. dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
  124. }
  125. int ScreenWidth = Screen.GetWorkingArea(pt).Width;
  126. //设置获取当前屏幕大小自动全屏但是保留任务栏
  127. Rectangle ScreenArea = Screen.GetWorkingArea(this);
  128. Top = 0;
  129. Left = 0;
  130. Width = ScreenArea.Width;
  131. Height = ScreenArea.Height;
  132. OutboxCapacity.Value = Properties.Settings.Default.OutboxCapacity;
  133. MidboxCapacity.Value = Properties.Settings.Default.MidBoxCapacity;
  134. DCCheck.Text = Properties.Settings.Default.DCCheck.ToString();
  135. OutBoxPrinter.Text = Properties.Settings.Default.OPrinter;
  136. MidLabelPrinter.Text = Properties.Settings.Default.MPrinter;
  137. SingleLabelPrinter.Text = Properties.Settings.Default.SPrinter;
  138. asc.controllInitializeSize(this);
  139. asc.controlAutoSize(this);
  140. //实例化打印进程
  141. try
  142. {
  143. lbl = new ApplicationClass();
  144. }
  145. catch (Exception)
  146. {
  147. MessageBox.Show("未安装CodeSoft软件或者版本不正确", "提示");
  148. }
  149. RefreshDBConnect.Interval = 60000;
  150. RefreshDBConnect.Start();
  151. }
  152. //只执行一次窗体自适应
  153. bool AutoSized = false;
  154. private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
  155. {
  156. if (!AutoSized)
  157. {
  158. asc.controlAutoSize(this);
  159. AutoSized = true;
  160. }
  161. }
  162. private void LabelMaintain_Click(object sender, EventArgs e)
  163. {
  164. 客户标签维护 form = new 客户标签维护();
  165. BaseUtil.SetFormCenter(form);
  166. if (FootDoc != null)
  167. FootDoc.Close();
  168. form.FormClosed += LabelFormClose;
  169. form.ShowDialog();
  170. }
  171. private void LabelFormClose(object sender, EventArgs e)
  172. {
  173. if (GetGridOnly.Checked)
  174. GetInOutInfAndLabelFile();
  175. else
  176. {
  177. GetGridOnly.Checked = true;
  178. GetInOutInfAndLabelFile();
  179. GetGridOnly.Checked = false;
  180. }
  181. }
  182. //输入框Enter事件
  183. private void Input_KeyDown(object sender, KeyEventArgs e)
  184. {
  185. if (e.KeyCode == Keys.Enter)
  186. {
  187. if (Input.Text == "")
  188. {
  189. MessageBox.Show("采集的数据不能为空");
  190. return;
  191. }
  192. CollectInputData();
  193. Input.SelectAll();
  194. }
  195. }
  196. /// <summary>
  197. /// 采集数据
  198. /// </summary>
  199. private void CollectInputData()
  200. {
  201. if (Input.Text == "SC")
  202. {
  203. PrintStatus.PerformClick();
  204. Input.Text = "";
  205. return;
  206. }
  207. Dictionary<string, string> Data = new Dictionary<string, string>();
  208. string[] SplitData = Input.Text.Split('*');
  209. if (SplitData.Length < 6)
  210. {
  211. MessageBox.Show("数据格式错误,无法解析", "提示");
  212. return;
  213. }
  214. for (int i = 0; i < SplitData.Length; i++)
  215. {
  216. switch (i.ToString())
  217. {
  218. case "0":
  219. Data.Add("PRCODE", SplitData[i]);
  220. break;
  221. case "1":
  222. Data.Add("QTY", SplitData[i]);
  223. break;
  224. case "2":
  225. Data.Add("DATECODE", SplitData[i]);
  226. break;
  227. case "3":
  228. Data.Add("BRAND", SplitData[i]);
  229. break;
  230. case "4":
  231. Data.Add("LOTNO", SplitData[i]);
  232. break;
  233. case "5":
  234. Data.Add("PO", SplitData[i]);
  235. break;
  236. case "6":
  237. Data.Add("SERIAL", SplitData[i]);
  238. break;
  239. default:
  240. break;
  241. }
  242. }
  243. //校验DateCode是否过期
  244. if (!CheckDateCode(Data["DATECODE"]))
  245. {
  246. MessageBox.Show("物料" + Data["PRCODE"] + "【DateCode】超出校验日期");
  247. return;
  248. }
  249. if (Data["PRCODE"] != CurrentPrCode)
  250. {
  251. MessageBox.Show("当前采集【物料编号】不对应,请重新采集", "提示");
  252. return;
  253. }
  254. if (Data["BRAND"] != CurrentBrand)
  255. {
  256. MessageBox.Show("当前采集【品牌】不对应,请重新采集", "提示");
  257. return;
  258. }
  259. int CodeCount = 0;
  260. //如果单位是KPCS则需要除1000
  261. int CollectNum = 0;
  262. if (CurrentUnit == "KPCS")
  263. {
  264. //如果单位是KPCS则必须是1000的整数倍
  265. if (int.Parse(Data["QTY"]) % 1000 != 0 || int.Parse(Data["QTY"]) / 1000 % int.Parse(CurrentZXBZ) != 0)
  266. {
  267. MessageBox.Show("物料" + Data["PRCODE"] + "采集数量无法按照最小包装数拆分", "提示");
  268. return;
  269. }
  270. CodeCount = int.Parse(Data["QTY"]) / 1000 / int.Parse(CurrentZXBZ);
  271. CollectNum = int.Parse(Data["QTY"]) / 1000;
  272. }
  273. else
  274. {
  275. if (int.Parse(Data["QTY"]) % int.Parse(CurrentZXBZ) != 0)
  276. {
  277. MessageBox.Show("采集【数量】无法按照最小包装数拆分", "提示");
  278. return;
  279. }
  280. CodeCount = int.Parse(Data["QTY"]) / int.Parse(CurrentZXBZ);
  281. CollectNum = int.Parse(Data["QTY"]);
  282. }
  283. string pib_barcode = Data.ContainsKey("SERIAL") ? Data["SERIAL"] : "";
  284. //获取ID
  285. PIBID = dh.GetSEQ("prodiobarcode_seq", CodeCount);
  286. string pib_outboxcode2 = "";
  287. if (OutBoxNum.Text == "新增")
  288. {
  289. string maxoutbox = dh.getFieldDataByCondition("prodiobarcode", "max(pib_outboxcode2)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  290. //如果没有则从开始插入
  291. if (maxoutbox == "")
  292. {
  293. pib_outboxcode2 = "1";
  294. }
  295. else
  296. {
  297. pib_outboxcode2 = (int.Parse(maxoutbox) + 1).ToString();
  298. }
  299. }
  300. else
  301. {
  302. pib_outboxcode2 = OutBoxNum.Text;
  303. }
  304. //计算当前采集数量
  305. string collectqty = (LabelInfDataTable.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  306. int CollectQty = (collectqty == "" ? 0 : int.Parse(collectqty));
  307. if (CollectQty + CollectNum > int.Parse(CurrentPrCount))
  308. {
  309. MessageBox.Show("物料" + Data["PRCODE"] + "采集后数量为" + (CollectQty + CollectNum) + ",【超出】本行出货数量" + CurrentPrCount, "提示");
  310. return;
  311. }
  312. List<string> CustBarCode = new List<string>();
  313. for (int i = 0; i < CodeCount; i++)
  314. {
  315. if (Radix > 0)
  316. {
  317. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  318. for (int j = serialcode.ToString().Length; j < NumLength; j++)
  319. {
  320. serialcode = "0" + serialcode;
  321. }
  322. CustBarCode.Add(Prefix + serialcode + Suffix);
  323. MaxNum = MaxNum + 1;
  324. }
  325. else
  326. {
  327. CustBarCode.Add("");
  328. }
  329. }
  330. sql.Clear();
  331. sql.Append("insert into prodiobarcode(PIB_ID,PIB_PRODCODE,PIB_INDATE,PIB_INOUTNO,PIB_PIID,PIB_PDNO, PIB_PDID,PIB_PICLASS,");
  332. sql.Append("PIB_BARCODE,PIB_CUSTBARCODE,PIB_QTY,pib_brand,pib_datecode,pib_lotno,PIB_OUTBOXCODE2,pib_inman,PIB_IFPRINT,PIB_ORDERCODE,PIB_CUSTPO) ");
  333. sql.Append("select :PIB_ID,pd_prodcode,sysdate,pi_inoutno,pi_id,pd_pdno,pd_id,pi_class,");
  334. sql.Append("'" + pib_barcode + "',:PIB_CUSTBARCODE,'" + CurrentZXBZ + "',pjd_brand,'" + Data["DATECODE"] + "','" + Data["LOTNO"] + "','" + pib_outboxcode2 + "','" + User.UserCode + "','" + (EnablePrint && SingleLabelAutoPrint.Checked ? 1 : 0).ToString() + "',pd_ordercode,pd_pocode ");
  335. sql.Append("from prodinout left join prodiodetail on pi_id=pd_piid left join PRODJOINVENDDETAIL on pjd_brand =pd_brand and pjd_prodcode=pd_prodcode where pi_id='" + PI_ID + "' and pd_prodcode='" + CurrentPrCode + "' and pd_pdno='" + CurrentPDNO + "'");
  336. dh.BatchInsert(sql.ToString(), new string[] { "PIB_ID", "PIB_CUSTBARCODE" }, PIBID, CustBarCode.ToArray());
  337. //更新流水号
  338. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + CodeCount) + "'", "rmn_nrcode='" + pi_cardcode.Text + "' and rmn_prefix='" + Prefix + "'");
  339. LoadGridData(new object(), new EventArgs());
  340. //加载完数据之后进行容量的判断
  341. int BoxNum = LabelInfDataTable.Select("pib_outboxcode2='" + OutBoxNum.Text + "'").Length;
  342. if (BoxNum > OutboxCapacity.Value)
  343. {
  344. MessageBox.Show("箱号【" + OutBoxNum.Text + "】超出容量,当前已采集" + BoxNum, "提示");
  345. }
  346. if (SingleLabelAutoPrint.Checked)
  347. {
  348. thread = new Thread(AutoPrintSingleLabel);
  349. stw = new SetLoadingWindow(thread, "正在打印单盘标签");
  350. BaseUtil.SetFormCenter(stw);
  351. stw.ShowDialog();
  352. }
  353. //采集后重新计数,自动跳到下一行
  354. collectqty = (LabelInfDataTable.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  355. CollectQty = (collectqty == "" ? 0 : int.Parse(collectqty));
  356. //采集达到了数量进行换行
  357. if (CollectQty == int.Parse(CurrentPrCount))
  358. {
  359. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  360. {
  361. string outqty = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  362. string collectnum = GridPrcode.Rows[i].Cells["CollectedNum"].Value.ToString();
  363. //采集之前的行,如后续行有物料编号相同的并且编号较大的跳到这样
  364. if (GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString() == CurrentPrCode && int.Parse(outqty) > int.Parse(collectnum == "" ? "0" : collectnum))
  365. {
  366. if (int.Parse(GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString()) > int.Parse(CurrentPDNO))
  367. {
  368. GridPrcode.Rows[i].Selected = true;
  369. return;
  370. }
  371. }
  372. }
  373. for (int i = GridPrcode.Rows.Count - 1; i >= 0; i--)
  374. {
  375. string outqty = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  376. string collectnum = GridPrcode.Rows[i].Cells["CollectedNum"].Value.ToString();
  377. if (int.Parse(outqty) > int.Parse(collectnum == "" ? "0" : collectnum))
  378. {
  379. GridPrcode.Rows[i].Selected = true;
  380. }
  381. }
  382. }
  383. OutBoxNum_Click(new object(), new EventArgs());
  384. }
  385. private void AutoPrintSingleLabel()
  386. {
  387. if (EnablePrint)
  388. {
  389. //用标签本身的变量作为最外层的循环条件去匹配;
  390. StringBuilder ParamLog = new StringBuilder();
  391. for (int i = 0; i < PIBID.Length; i++)
  392. {
  393. for (int k = 0; k < Attach.Rows.Count; k++)
  394. {
  395. for (int j = 0; j < SingleReport.Parameters.Count; j++)
  396. {
  397. if (Attach.Rows[k][0].ToString() == SingleReport.Parameters[j].Name)
  398. {
  399. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
  400. }
  401. }
  402. }
  403. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiosingleinfo_view where 主键ID=" + PIBID[i], "select");
  404. SingleReport.RegisterData(dt, "prodiosingleinfo_view");
  405. SingleReport.GetDataSource("prodiosingleinfo_view").Enabled = true;
  406. SingleReport.PrintSettings.ShowDialog = false;
  407. SingleReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  408. SingleReport.Print();
  409. Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text;
  410. Properties.Settings.Default.Save();
  411. }
  412. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "自动打印箱标", "打印成功");
  413. }
  414. }
  415. //关闭窗口前提示用户确认
  416. private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
  417. {
  418. //如果不是注销的话
  419. if (!logout)
  420. {
  421. string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  422. if (close.ToString() != "Yes")
  423. e.Cancel = true;
  424. else
  425. {
  426. lbl.Quit();
  427. LogManager.DoLog("关闭程序");
  428. }
  429. }
  430. }
  431. /// <summary>
  432. /// 获取打印标签
  433. /// </summary>
  434. private void GetInOutInfAndLabelFile()
  435. {
  436. ComBoxClickChangeLabelDoc = false;
  437. sql.Clear();
  438. 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 ");
  439. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  440. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='单盘' order by cl_custcode");
  441. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  442. SingleLabelCombox.DisplayMember = "cl_labelname";
  443. SingleLabelCombox.ValueMember = "la_id";
  444. SingleLabelCombox.DataSource = dt;
  445. if (!GetGridOnly.Checked)
  446. for (int i = 0; i < dt.Rows.Count; i++)
  447. {
  448. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  449. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  450. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  451. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  452. if (time.ToString() != file.LastWriteTime.ToString())
  453. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  454. }
  455. if (SingleLabelCombox.Text != "")
  456. {
  457. SingleReport.Load(@"F:/Simple List.frx");
  458. }
  459. sql.Clear();
  460. 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 ");
  461. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  462. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='中盒' order by cl_custcode");
  463. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  464. MidLabelCombox.DisplayMember = "cl_labelname";
  465. MidLabelCombox.ValueMember = "la_id";
  466. MidLabelCombox.DataSource = dt;
  467. if (!GetGridOnly.Checked)
  468. for (int i = 0; i < dt.Rows.Count; i++)
  469. {
  470. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  471. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  472. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  473. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  474. if (time.ToString() != file.LastWriteTime.ToString())
  475. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  476. }
  477. if (MidLabelCombox.Text != "")
  478. {
  479. MidReport.Load(@"F:/Simple List.frx");
  480. }
  481. //缓存中盒参数
  482. sql.Clear();
  483. 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 ");
  484. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  485. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='外箱' order by cl_custcode");
  486. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  487. OutBoxCombox.DisplayMember = "cl_labelname";
  488. OutBoxCombox.ValueMember = "la_id";
  489. OutBoxCombox.DataSource = dt;
  490. if (!GetGridOnly.Checked)
  491. for (int i = 0; i < dt.Rows.Count; i++)
  492. {
  493. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  494. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  495. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  496. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  497. if (time.ToString() != file.LastWriteTime.ToString())
  498. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  499. }
  500. if (OutBoxCombox.Text != "")
  501. {
  502. OutReport.Load(@"F:/Simple List.frx");
  503. }
  504. if (!File.Exists(ftpOperater.DownLoadTo + "唛头.lab"))
  505. {
  506. BaseUtil.GetLabelUrl(DataHelper.FTPAdress, "唛头.lab", System.DateTime.Now);
  507. if (FootDoc != null)
  508. FootDoc.Close();
  509. FootDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + "唛头.lab");
  510. }
  511. else
  512. {
  513. if (FootDoc != null)
  514. FootDoc.Close();
  515. FootDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + "唛头.lab");
  516. }
  517. //缓存外箱参数
  518. ComBoxClickChangeLabelDoc = true;
  519. }
  520. /// <summary>
  521. /// 出入库单录入框的回车事件
  522. /// </summary>
  523. /// <param name="sender"></param>
  524. /// <param name="e"></param>
  525. private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
  526. {
  527. if (e.KeyCode == Keys.Enter)
  528. {
  529. sql.Clear();
  530. sql.Append("select pi_id,pi_cardcode,to_char(pi_date,'yyyymmdd')pi_date from prodinout where pi_inoutno='" + pi_inoutno.Text + "'");
  531. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  532. if (dt.Rows.Count > 0)
  533. {
  534. pi_cardcode.Text = dt.Rows[0]["pi_cardcode"].ToString();
  535. pi_date.Text = dt.Rows[0]["pi_date"].ToString();
  536. PI_ID = dt.Rows[0]["pi_id"].ToString();
  537. LoadPrcodeData();
  538. LoadGridData(sender, e);
  539. //获取条码规则
  540. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix);
  541. SingleID.Clear();
  542. Input.Focus();
  543. //从后往前找未采集的行
  544. for (int i = GridPrcode.Rows.Count - 1; i >= 0; i--)
  545. {
  546. string outqty = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  547. string collectnum = GridPrcode.Rows[i].Cells["CollectedNum"].Value.ToString();
  548. if (int.Parse(outqty) > int.Parse(collectnum == "" ? "0" : collectnum))
  549. {
  550. GridPrcode.Rows[i].Selected = true;
  551. }
  552. }
  553. Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LABELATTACHPARAMETER where lap_custcode='" + pi_cardcode.Text + "'", "select");
  554. thread = new Thread(GetInOutInfAndLabelFile);
  555. stw = new SetLoadingWindow(thread, "正在获取打印标签");
  556. BaseUtil.SetFormCenter(stw);
  557. stw.ShowDialog();
  558. LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
  559. }
  560. else
  561. MessageBox.Show("当前出入库单号不存在!", "提示");
  562. }
  563. }
  564. private void SingleBoxPrint()
  565. {
  566. if (EnablePrint)
  567. {
  568. if (LabelInf.Rows.Count > 0)
  569. {
  570. //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
  571. SingleID.Clear();
  572. //获取全部的中盒号
  573. Dictionary<string, bool> outboxcode1 = new Dictionary<string, bool>();
  574. //判断所有盒号为该盒的是否勾选已采集
  575. outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true);
  576. for (int i = 0; i < LabelInf.Rows.Count; i++)
  577. {
  578. if (!SingleID.Contains(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()))
  579. SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  580. }
  581. if (SingleID.ToArray().Length == 0)
  582. {
  583. MessageBox.Show("选择的行未勾选采集或者已打印", "提示");
  584. return;
  585. }
  586. for (int i = 0; i < LabelInf.RowCount; i++)
  587. {
  588. if (i + 1 < LabelInf.RowCount)
  589. {
  590. //如果本行的中盒号和下一行不相等的话
  591. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString())
  592. {
  593. if (!outboxcode1.ContainsKey(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
  594. outboxcode1.Add(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString(), true);
  595. }
  596. }
  597. }
  598. //用于判断用户是否勾选了行
  599. int CheckedRowCount = 0;
  600. for (int i = 0; i < LabelInf.RowCount; i++)
  601. {
  602. //勾选了并且未打印
  603. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true" && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString().ToLower() != "true")
  604. {
  605. for (int k = 0; k < Attach.Rows.Count; k++)
  606. {
  607. for (int j = 0; j < SingleReport.Parameters.Count; j++)
  608. {
  609. if (Attach.Rows[k][0].ToString() == SingleReport.Parameters[j].Name)
  610. {
  611. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
  612. }
  613. }
  614. }
  615. CheckedRowCount = CheckedRowCount + 1;
  616. string pib_id = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
  617. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiosingleinfo_view where 主键ID=" + pib_id, "select");
  618. SingleReport.RegisterData(dt, "prodiosingleinfo_view");
  619. SingleReport.GetDataSource("prodiosingleinfo_view").Enabled = true;
  620. //保存参数打印
  621. SingleReport.PrintSettings.ShowDialog = false;
  622. SingleReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  623. SingleReport.Print();
  624. Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text;
  625. Properties.Settings.Default.Save();
  626. LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
  627. }
  628. }
  629. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印箱标", "打印成功");
  630. dh.BatchInsert("update prodiobarcode set pib_printdate=sysdate where pib_id=:pib_id", new string[] { "pib_id" }, SingleID.ToArray());
  631. if (CheckedRowCount == 0)
  632. MessageBox.Show("未勾选打印明细!", "提示");
  633. outboxcode1.Clear();
  634. }
  635. else
  636. {
  637. MessageBox.Show("此模板尚未维护参数或不存在打印明细", "提示");
  638. return;
  639. }
  640. }
  641. }
  642. private void SingleLabelPrint_Click(object sender, EventArgs e)
  643. {
  644. if (SingleLabelCombox.Text != "")
  645. {
  646. if (SingleBoxBegin.Text != "" || SingleBoxEnd.Text != "")
  647. {
  648. try
  649. {
  650. int begin = int.Parse(SingleBoxBegin.Text == "" ? "1" : SingleBoxBegin.Text);
  651. int end = int.Parse(SingleBoxEnd.Text == "" ? LabelInf.Rows.Count.ToString() : SingleBoxEnd.Text);
  652. if (begin > 0 && end <= LabelInf.Rows.Count && begin <= end)
  653. {
  654. for (int i = begin - 1; i < end; i++)
  655. {
  656. LabelInf.Rows[i].Cells["Choose"].Value = true;
  657. LabelInf.Rows[i].Cells["pib_ifprint"].Value = false;
  658. }
  659. }
  660. else
  661. {
  662. MessageBox.Show("单盘打印范围错误", "提示");
  663. return;
  664. }
  665. }
  666. catch (Exception)
  667. {
  668. MessageBox.Show("单盘打印范围错误", "提示");
  669. return;
  670. }
  671. }
  672. thread = new Thread(SingleBoxPrint);
  673. stw = new SetLoadingWindow(thread, "正在打印单盘");
  674. BaseUtil.SetFormCenter(stw);
  675. stw.ShowDialog();
  676. Input.Focus();
  677. }
  678. else
  679. {
  680. MessageBox.Show("未维护单盘标签", "提示");
  681. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印箱标", "打印失败,未维护标签");
  682. }
  683. }
  684. private void MidBoxLabelPrint()
  685. {
  686. //未输入内容打印全部中盒
  687. if (MidLabelNum.Text == "")
  688. {
  689. int begin = 0;
  690. int end = 0;
  691. if (MidBoxBegin.Text != "" || MidBoxEnd.Text != "")
  692. {
  693. try
  694. {
  695. begin = int.Parse(MidBoxBegin.Text == "" ? "1" : MidBoxBegin.Text);
  696. end = int.Parse(MidBoxEnd.Text == "" ? LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString() : MidBoxEnd.Text);
  697. int minmidbox = int.Parse(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString());
  698. int maxmidbox = int.Parse(LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString());
  699. if (begin >= minmidbox && end <= maxmidbox && begin <= end)
  700. {
  701. //设置中盒打印范围的行号
  702. for (int i = 0; i < LabelInf.Rows.Count; i++)
  703. {
  704. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == begin)
  705. {
  706. begin = i;
  707. }
  708. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == end)
  709. {
  710. end = i;
  711. }
  712. }
  713. }
  714. else
  715. {
  716. MessageBox.Show("中盒打印范围错误", "提示");
  717. return;
  718. }
  719. }
  720. catch (Exception)
  721. {
  722. MessageBox.Show("中盒打印范围错误", "提示");
  723. return;
  724. }
  725. }
  726. List<int> MidOutBoxCode = new List<int>();
  727. List<int> MidOutBoxCodeIndex = new List<int>();
  728. string la_id = MidLabelCombox.SelectedValue.ToString().Split('#')[0];
  729. for (int i = (begin == 0 ? 0 : begin); i <= (end == 0 ? LabelInf.Rows.Count - 1 : end); i++)
  730. {
  731. try
  732. {
  733. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  734. {
  735. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  736. MidOutBoxCodeIndex.Add(i);
  737. }
  738. }
  739. catch (Exception)
  740. {
  741. MessageBox.Show("请先封箱!");
  742. return;
  743. }
  744. }
  745. for (int i = 0; i < MidOutBoxCodeIndex.Count; i++)
  746. {
  747. MidBoxCodePrint(la_id, MidOutBoxCodeIndex[i]);
  748. }
  749. return;
  750. }
  751. bool FindMidLabel = false;
  752. if (MidLabelCombox.SelectedValue != null)
  753. {
  754. string la_id = MidLabelCombox.SelectedValue.ToString().Split('#')[0];
  755. string cl_labelname = MidLabelCombox.Text;
  756. string LabelUrl = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id + "' and cl_labelname='" + cl_labelname + "'").ToString();
  757. //中盒号所在的行
  758. int MidLabelRowIndex = 0;
  759. //缓存中盒数据
  760. for (int i = 0; i < LabelInf.RowCount; i++)
  761. {
  762. if (MidLabelNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  763. {
  764. //找到了输入的中盒号停止循环
  765. FindMidLabel = true;
  766. MidLabelRowIndex = i;
  767. }
  768. }
  769. //找到了指定的盒号
  770. if (FindMidLabel)
  771. MidBoxCodePrint(la_id, MidLabelRowIndex);
  772. else
  773. MessageBox.Show("该出入库单未找到该中盒号!", "提示");
  774. }
  775. else
  776. MessageBox.Show("未维护中盒模板", "提示");
  777. }
  778. private void MidLabelPrint_Click(object sender, EventArgs e)
  779. {
  780. if (MidLabelCombox.Text != "")
  781. {
  782. thread = new Thread(MidBoxLabelPrint);
  783. stw = new SetLoadingWindow(thread, "正在打印中盒");
  784. BaseUtil.SetFormCenter(stw);
  785. stw.ShowDialog();
  786. }
  787. else
  788. MessageBox.Show("未维护中盒标签", "提示");
  789. }
  790. private void OutBoxPrint()
  791. {
  792. List<string> Outboxcode = new List<string>();
  793. //如果未勾选箱号则对勾选的数据的箱号进行整合
  794. string la_id = OutBoxCombox.SelectedValue.ToString().Split('#')[0];
  795. string cl_labelname = OutBoxCombox.Text;
  796. string LabelUrl = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id + "' and cl_labelname='" + cl_labelname + "'").ToString();
  797. if (OutBoxNum.Text == "" || OutBoxNum.Text == "新增")
  798. {
  799. for (int i = 0; i < LabelInf.RowCount; i++)
  800. {
  801. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true")
  802. {
  803. string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  804. //富为使用包装单的逻辑
  805. //如果不包含该箱号则进行添加
  806. if (!Outboxcode.Contains(outboxcode2))
  807. Outboxcode.Add(outboxcode2);
  808. }
  809. }
  810. //按获取到的箱号列表进行打印
  811. if (Outboxcode.ToArray().Length > 0)
  812. {
  813. try
  814. {
  815. // 循环打印外箱号
  816. for (int i = 0; i < Outboxcode.ToArray().Length; i++)
  817. {
  818. for (int h = 0; h < LabelInf.RowCount; h++)
  819. {
  820. if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i])
  821. {
  822. OutBoxCodePrint(la_id, h);
  823. break;
  824. }
  825. }
  826. }
  827. }
  828. catch { }
  829. }
  830. else
  831. {
  832. MessageBox.Show("请勾选需要打印的外箱", "提示");
  833. }
  834. }
  835. else
  836. {
  837. bool FindMidLabel = false;
  838. try
  839. {
  840. int OutBoxLabelRowIndex = 0;
  841. //查找是否存在该中盒号
  842. for (int i = 0; i < LabelInf.RowCount; i++)
  843. {
  844. if (OutBoxNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString())
  845. {
  846. //找到了输入的中盒号停止循环
  847. FindMidLabel = true;
  848. OutBoxLabelRowIndex = i;
  849. break;
  850. }
  851. }
  852. //找到了指定的盒号
  853. if (FindMidLabel)
  854. OutBoxCodePrint(la_id, OutBoxLabelRowIndex);
  855. else
  856. MessageBox.Show("该出入库单未找到该外箱号!", "提示");
  857. }
  858. catch (Exception) { }
  859. }
  860. Outboxcode.Clear();
  861. }
  862. private void MidBoxCodePrint(string la_id, int rowindex)
  863. {
  864. if (EnablePrint)
  865. {
  866. for (int i = 0; i < Attach.Rows.Count; i++)
  867. {
  868. for (int j = 0; j < MidReport.Parameters.Count; j++)
  869. {
  870. if (Attach.Rows[i][0].ToString() == MidReport.Parameters[j].Name)
  871. {
  872. MidReport.SetParameterValue(MidReport.Parameters[j].Name, Attach.Rows[i][1].ToString());
  873. }
  874. }
  875. }
  876. //名称相等的时候,取SQL进行值的查询
  877. string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
  878. string pib_outboxcode1 = LabelInf.Rows[rowindex].Cells["pib_outboxcode1"].Value.ToString();
  879. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiobarcode where pib_id=" + pib_id, "select");
  880. MidReport.RegisterData(dt, "Prodiobarcode");
  881. MidReport.GetDataSource("Prodiobarcode").Enabled = true;
  882. MidReport.PrintSettings.Printer = MidLabelPrinter.Text;
  883. MidReport.Print();
  884. Properties.Settings.Default.MPrinter = MidLabelPrinter.Text;
  885. Properties.Settings.Default.Save();
  886. }
  887. }
  888. /// <summary>
  889. /// 执行打印外箱号
  890. /// </summary>
  891. private void OutBoxCodePrint(string la_id, int rowindex)
  892. {
  893. if (EnablePrint)
  894. {
  895. for (int i = 0; i < Attach.Rows.Count; i++)
  896. {
  897. for (int j = 0; j < OutReport.Parameters.Count; j++)
  898. {
  899. if (Attach.Rows[i][0].ToString() == OutReport.Parameters[j].Name)
  900. {
  901. OutReport.SetParameterValue(OutReport.Parameters[j].Name, Attach.Rows[i][1].ToString());
  902. }
  903. }
  904. }
  905. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiooutinfo_view where 出货单号='" + pi_inoutno.Text + "' and 外箱号='" + pib_outboxcode2 + "'", "select");
  906. DataTable dt1 = dt.Clone();
  907. for (int i = 0; i < dt.Rows.Count; i++)
  908. {
  909. DataRow dr = dt1.NewRow();
  910. for (int j = 0; j < dt.Columns.Count; j++)
  911. {
  912. dr[j] = dt.Rows[i][j].ToString();
  913. }
  914. dt1.Rows.Add(dr);
  915. if ((i + 1) % 5 == 0 || (i + 1) == dt.Rows.Count)
  916. {
  917. OutReport.RegisterData(dt1, "prodiooutinfo_view");
  918. OutReport.GetDataSource("prodiooutinfo_view").Enabled = true;
  919. OutReport.PrintSettings.ShowDialog = false;
  920. OutReport.PrintSettings.Printer = OutBoxPrinter.Text;
  921. OutReport.Print();
  922. BaseUtil.CleanDataTableData(dt1);
  923. }
  924. }
  925. }
  926. }
  927. private void CleanDetail_Click(object sender, EventArgs e)
  928. {
  929. ArrayList<string> DeleteID = new ArrayList<string>();
  930. for (int i = 0; i < LabelInf.RowCount; i++)
  931. {
  932. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true")
  933. DeleteID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  934. }
  935. //勾选了删除的明细之后
  936. if (DeleteID.ToArray().Length > 0)
  937. {
  938. string close = MessageBox.Show(this.ParentForm, "删除后不可恢复,是否确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  939. if (close.ToString() == "Yes")
  940. {
  941. dh.BatchInsert("delete from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray());
  942. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "删除明细", "删除明细成功");
  943. MessageBox.Show("删除成功", "提示");
  944. LoadGridData(sender, e);
  945. }
  946. }
  947. else
  948. MessageBox.Show("尚未勾选需要删除的明细", "提示");
  949. }
  950. private void OutBoxLabelPrint_Click(object sender, EventArgs e)
  951. {
  952. if (OutBoxCombox.Text != "")
  953. {
  954. thread = new Thread(OutBoxPrint);
  955. stw = new SetLoadingWindow(thread, "正在打印外箱");
  956. BaseUtil.SetFormCenter(stw);
  957. stw.ShowDialog();
  958. Input.Focus();
  959. }
  960. else
  961. MessageBox.Show("未维护外箱标签", "提示");
  962. }
  963. private void LoadGridData()
  964. {
  965. LoadGridData(new object(), new EventArgs());
  966. }
  967. /// <summary>
  968. /// 自定义函数 加载明细行的数据,多处使用添加进函数
  969. /// </summary>
  970. /// <param name="sender"></param>
  971. /// <param name="e"></param>
  972. private void LoadGridData(object sender, EventArgs e)
  973. {
  974. AllChecked = false;
  975. sql.Clear();
  976. sql.Append("select pd_custprodcode,pd_custprodspec,pib_custmidboxcode,pd_pocode,pjd_orispeccode,pib_madein,pib_custbarcode,pib_custoutboxcode,pib_id,pib_datecode1,pib_pdid,pib_piid,");
  977. 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,");
  978. sql.Append("pr_zxbzs,pr_unit,pib_barcode,pib_outboxcode1,pib_outboxcode2,nvl(pib_ifprint,0)pib_ifprint from prodiobarcode left join ");
  979. sql.Append("prodiodetail on pib_piid=pd_piid and pd_pdno=pib_pdno and pd_prodcode=pib_prodcode left join product on pr_code=pib_prodcode ");
  980. sql.Append("left join sale on sa_code=pib_ordercode left join PRODJOINVENDDETAIL on pjd_brand =pd_brand and pjd_prodcode=pd_prodcode where pib_piid='" + PI_ID + "' ");
  981. sql.Append(" order by to_number(pib_outboxcode2),pib_id,pd_prodcode");
  982. LabelInfDataTable = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  983. if (OutBoxNum.Text != "新增")
  984. {
  985. BaseUtil.FillDgvWithDataTable(LabelInf, BaseUtil.filterDataTable(LabelInfDataTable, " pib_outboxcode2='" + OutBoxNum.Text + "'"));
  986. }
  987. else
  988. {
  989. BaseUtil.FillDgvWithDataTable(LabelInf, LabelInfDataTable);
  990. }
  991. //有数据的话默认取第一条的品牌去取采集策略
  992. if (LabelInf.Rows.Count > 0)
  993. LabelInf.FirstDisplayedScrollingRowIndex = LabelInf.Rows.Count - 1;
  994. //计算所有的采集数量
  995. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  996. {
  997. string CurrentPrCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  998. string CurrentPDNO = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  999. string collectqty = (LabelInfDataTable.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  1000. GridPrcode.Rows[i].Cells["CollectedNum"].Value = collectqty;
  1001. GridPrcode.Rows[i].Cells["UnCollectedNum"].Value = int.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString()) - int.Parse(collectqty == "" ? "0" : collectqty);
  1002. }
  1003. }
  1004. private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1005. {
  1006. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  1007. pi_inoutno_KeyDown(sender, e2);
  1008. }
  1009. /// <summary>
  1010. /// 勾选的时候自动打印
  1011. /// </summary>
  1012. /// <param name="sender"></param>
  1013. /// <param name="e"></param>
  1014. private void LabelInf_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  1015. {
  1016. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
  1017. {
  1018. string datecode = LabelInf.Rows[e.RowIndex].Cells["pib_datecode"].Value.ToString();
  1019. try
  1020. {
  1021. System.DateTime dt = System.DateTime.ParseExact(datecode, "yyyyMMdd", CultureInfo.CurrentCulture);
  1022. GregorianCalendar gc = new GregorianCalendar();
  1023. int weekOfYear = gc.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
  1024. if (weekOfYear < 10)
  1025. LabelInf.Rows[e.RowIndex].Cells["pib_datecode1"].Value = dt.Year.ToString().Substring(2, 2) + "0" + weekOfYear;
  1026. else
  1027. LabelInf.Rows[e.RowIndex].Cells["pib_datecode1"].Value = dt.Year.ToString().Substring(2, 2) + weekOfYear;
  1028. }
  1029. catch (Exception) { }
  1030. }
  1031. }
  1032. private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1033. {
  1034. string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1035. if (close.ToString() == "Yes")
  1036. {
  1037. Login login = new Login();
  1038. //注销的时候需要将拼接的连接字符串置空
  1039. DataHelper.DBConnectionString = null;
  1040. logout = true;
  1041. lbl.Quit();
  1042. this.Hide();
  1043. login.ShowDialog();
  1044. this.Close();
  1045. }
  1046. }
  1047. private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1048. /// <summary>
  1049. /// 切换打开的单盘文件
  1050. /// </summary>
  1051. /// <param name="sender"></param>
  1052. /// <param name="e"></param>
  1053. private void SingleLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1054. {
  1055. try
  1056. {
  1057. if (ComBoxClickChangeLabelDoc)
  1058. {
  1059. }
  1060. }
  1061. catch (Exception) { }
  1062. }
  1063. /// <summary>
  1064. /// 切换打开的中盒文件
  1065. /// </summary>
  1066. /// <param name="sender"></param>
  1067. /// <param name="e"></param>
  1068. private void MidLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1069. {
  1070. try
  1071. {
  1072. if (ComBoxClickChangeLabelDoc)
  1073. {
  1074. }
  1075. }
  1076. catch (Exception) { }
  1077. }
  1078. /// <summary>
  1079. /// 切换打开的外箱文件
  1080. /// </summary>
  1081. /// <param name="sender"></param>
  1082. /// <param name="e"></param>
  1083. private void OutBoxCombox_SelectedIndexChanged(object sender, EventArgs e)
  1084. {
  1085. try
  1086. {
  1087. if (ComBoxClickChangeLabelDoc)
  1088. {
  1089. }
  1090. }
  1091. catch (Exception) { }
  1092. }
  1093. private void ChooseAll_Click(object sender, EventArgs e)
  1094. {
  1095. if (AllChecked)
  1096. {
  1097. foreach (DataGridViewRow dr in LabelInf.Rows)
  1098. dr.Cells[0].Value = false;
  1099. AllChecked = false;
  1100. }
  1101. else
  1102. {
  1103. foreach (DataGridViewRow dr in LabelInf.Rows)
  1104. dr.Cells[0].Value = true;
  1105. AllChecked = true;
  1106. }
  1107. }
  1108. private void ExportData_Click(object sender, EventArgs e)
  1109. {
  1110. ExportFileDialog.Description = "选择导出的路径";
  1111. DialogResult result = ExportFileDialog.ShowDialog();
  1112. if (result == DialogResult.OK)
  1113. {
  1114. ExcelHandler eh = new ExcelHandler();
  1115. DataTable dt = LabelInfDataTable.Copy();
  1116. for (int i = dt.Columns.Count - 1; i >= 0; i--)
  1117. {
  1118. for (int j = 0; j < LabelInf.Columns.Count; j++)
  1119. {
  1120. //去除ID列
  1121. 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_ifprint" || dt.Columns[i].ColumnName.ToLower() == "pib_datecode1" || dt.Columns[i].ColumnName.ToLower() == "pr_vendprodcode")
  1122. {
  1123. dt.Columns.RemoveAt(i);
  1124. break;
  1125. }
  1126. switch (dt.Columns[i].ColumnName.ToLower())
  1127. {
  1128. case "pib_lotno":
  1129. dt.Columns[i].ColumnName = "批次号";
  1130. break;
  1131. case "pib_datecode":
  1132. dt.Columns[i].ColumnName = "生产日期";
  1133. break;
  1134. case "pib_custbarcode":
  1135. dt.Columns[i].ColumnName = "最小产品包装条码";
  1136. break;
  1137. default:
  1138. break;
  1139. }
  1140. if (dt.Columns[i].ColumnName.ToLower() == LabelInf.Columns[j].DataPropertyName.ToLower())
  1141. {
  1142. dt.Columns[i].ColumnName = LabelInf.Columns[j].HeaderText;
  1143. break;
  1144. }
  1145. }
  1146. }
  1147. eh.ExportExcel(dt, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text);
  1148. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1149. if (close.ToString() == "Yes")
  1150. Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + ".xls");
  1151. }
  1152. }
  1153. private void AttachInfo_Click(object sender, EventArgs e)
  1154. {
  1155. if (pi_cardcode.Text != "")
  1156. {
  1157. 附件内容打印 att = new 附件内容打印(pi_cardcode.Text);
  1158. att.ShowDialog();
  1159. }
  1160. else MessageBox.Show("请先获取出库单信息", "提示");
  1161. }
  1162. private void MidBoxCapacity_Leave(object sender, EventArgs e)
  1163. {
  1164. NumericUpDown nup = (NumericUpDown)sender;
  1165. switch (nup.Name)
  1166. {
  1167. case "MidBoxCapacity":
  1168. Properties.Settings.Default.MidBoxCapacity = nup.Value;
  1169. Properties.Settings.Default.Save();
  1170. break;
  1171. case "OutboxCapacity":
  1172. Properties.Settings.Default.OutboxCapacity = nup.Value;
  1173. Properties.Settings.Default.Save();
  1174. break;
  1175. default:
  1176. break;
  1177. }
  1178. }
  1179. private void RefreshDBConnect_Tick(object sender, EventArgs e)
  1180. {
  1181. dh.ExecuteSql("select sysdate from dual", "select");
  1182. }
  1183. private void LoadPrcodeData()
  1184. {
  1185. GridPrcode.DataSource = (DataTable)dh.ExecuteSql("select pd_pdno,pd_prodcode,'0' CollectedNum,'0' UnCollectedNum,pd_outqty,pr_unit,pd_brand,pjd_zxbzs_user,pjd_id from prodiodetail left join prodinout on pi_id=pd_piid left join PRODJOINVENDDETAIL on pjd_brand =pd_brand and pjd_prodcode=pd_prodcode left join product on pd_prodcode=pr_code where pi_id='" + PI_ID + "' order by pd_pdno", "select");
  1186. if (GridPrcode.Rows.Count > 0)
  1187. {
  1188. CurrentPrCode = GridPrcode.Rows[0].Cells["pd_prodcode"].Value.ToString();
  1189. CurrentZXBZ = GridPrcode.Rows[0].Cells["pjd_zxbzs_user"].Value.ToString();
  1190. CurrentUnit = GridPrcode.Rows[0].Cells["pr_unit"].Value.ToString();
  1191. CurrentPDNO = GridPrcode.Rows[0].Cells["pd_pdno"].Value.ToString();
  1192. CurrentPrCount = GridPrcode.Rows[0].Cells["pd_outqty"].Value.ToString();
  1193. CurrentBrand = GridPrcode.Rows[0].Cells["pd_brand"].Value.ToString();
  1194. GridPrcode.Rows[0].Selected = true;
  1195. }
  1196. }
  1197. private void OutBoxNum_Click(object sender, EventArgs e)
  1198. {
  1199. OutBoxNum.Items.Clear();
  1200. DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by pib_outboxcode2", "select");
  1201. ItemObject io = new ItemObject("新增", "新增");
  1202. OutBoxNum.Items.Add(io);
  1203. for (int i = 0; i < dt.Rows.Count; i++)
  1204. {
  1205. string pib_outboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  1206. io = new ItemObject(pib_outboxcode2, pib_outboxcode2);
  1207. OutBoxNum.Items.Add(io);
  1208. }
  1209. if (OutBoxNum.Text == "新增")
  1210. OutBoxNum.SelectedIndex = OutBoxNum.Items.Count - 1;
  1211. }
  1212. /// <summary>
  1213. /// 获取条码规则
  1214. /// </summary>
  1215. /// <param name="Type"></param>
  1216. /// <param name="Prefix"></param>
  1217. /// <param name="Suffix"></param>
  1218. /// <param name="CurrentMaxNum"></param>
  1219. /// <param name="SerialNumLength"></param>
  1220. /// <param name="Radix"></param>
  1221. private void GetBarCodeRule(out string Prefix, out string Suffix, out int CurrentMaxNum, out int SerialNumLength, out int Radix)
  1222. {
  1223. //获取编码规则
  1224. Prefix = "";
  1225. Suffix = "";
  1226. CurrentMaxNum = 0;
  1227. SerialNumLength = 0;
  1228. Radix = 0;
  1229. DataTable Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_type,nrd_radix,nrd_sql,nrd_length from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode='" + pi_cardcode.Text + "' order by nrd_detno", "select");
  1230. //如果没有则取公共规则
  1231. if (Nr.Rows.Count == 0)
  1232. Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_radix,nrd_type,nrd_sql,nrd_length from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode is null and nr_isdefault <> 0 order by nrd_detno", "select");
  1233. //用于过滤参数的正则表达式
  1234. Regex match = new Regex("{\\w+}");
  1235. //用于存放每一项的明细的数据
  1236. string[] NrData = new string[Nr.Rows.Count];
  1237. //流水长度
  1238. Dictionary<int, string> NrDic = new Dictionary<int, string>();
  1239. Prefix = "";
  1240. for (int m = 0; m < Nr.Rows.Count; m++)
  1241. {
  1242. switch (Nr.Rows[m]["nrd_type"].ToString())
  1243. {
  1244. //常量直接进行拼接
  1245. case "常量":
  1246. Prefix += Nr.Rows[m]["nrd_sql"].ToString();
  1247. Suffix += Nr.Rows[m]["nrd_sql"].ToString();
  1248. break;
  1249. case "SQL":
  1250. string SQL = Nr.Rows[m]["nrd_sql"].ToString();
  1251. DataTable Temp;
  1252. //如果不包含参数替换
  1253. if (SQL.IndexOf("{") == 0)
  1254. {
  1255. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  1256. }
  1257. else
  1258. {
  1259. //替换参数后重新执行SQL
  1260. foreach (Match mch in match.Matches(SQL))
  1261. {
  1262. SQL = SQL.Replace(mch.Value.Trim(), "'" + pi_inoutno.Text + "'");
  1263. }
  1264. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  1265. }
  1266. if (Temp.Rows.Count > 0)
  1267. {
  1268. Prefix += Temp.Rows[0][0].ToString();
  1269. Suffix += Temp.Rows[0][0].ToString();
  1270. }
  1271. break;
  1272. //流水需要通过MaxNumber去取
  1273. case "流水":
  1274. string maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + pi_cardcode.Text + "' and rmn_prefix='" + Prefix + "'").ToString();
  1275. //设置当前流水
  1276. if (maxnum == "")
  1277. {
  1278. dh.ExecuteSql("insert into RuleMaxNum(rmn_id,rmn_nrcode,rmn_prefix,rmn_maxnumber) values(RuleMaxNum_seq.nextval,'" + pi_cardcode.Text + "','" + Prefix + "','1')", "insert");
  1279. CurrentMaxNum = 1;
  1280. }
  1281. else
  1282. {
  1283. CurrentMaxNum = int.Parse(maxnum);
  1284. }
  1285. SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString());
  1286. Radix = int.Parse(Nr.Rows[m]["nrd_radix"].ToString());
  1287. Suffix = "";
  1288. break;
  1289. default:
  1290. break;
  1291. }
  1292. }
  1293. }
  1294. private void GridPrcode_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  1295. {
  1296. string Value = GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  1297. string ID = GridPrcode.Rows[e.RowIndex].Cells["pjd_id"].Value.ToString();
  1298. dh.UpdateByCondition("PRODJOINVENDDETAIL", "pjd_zxbzs_user='" + Value + "'", "pjd_id='" + ID + "'");
  1299. //删除对应物料的明细
  1300. CurrentPrCode = GridPrcode.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString();
  1301. CurrentZXBZ = GridPrcode.Rows[e.RowIndex].Cells["pjd_zxbzs_user"].Value.ToString();
  1302. CurrentUnit = GridPrcode.Rows[e.RowIndex].Cells["pr_unit"].Value.ToString();
  1303. CurrentPDNO = GridPrcode.Rows[e.RowIndex].Cells["pd_pdno"].Value.ToString();
  1304. CurrentPrCount = GridPrcode.Rows[e.RowIndex].Cells["pd_outqty"].Value.ToString();
  1305. CurrentBrand = GridPrcode.Rows[e.RowIndex].Cells["pd_brand"].Value.ToString();
  1306. GridPrcode.Rows[e.RowIndex].Selected = true;
  1307. dh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno='" + CurrentPDNO + "' and pib_prodcode='" + CurrentPrCode + "'", "delete");
  1308. LoadGridData(sender, new EventArgs());
  1309. }
  1310. private void GridPrcode_SelectionChanged(object sender, EventArgs e)
  1311. {
  1312. if (GridPrcode.SelectedRows.Count > 0)
  1313. {
  1314. DataGridViewSelectedRowCollection dsc = GridPrcode.SelectedRows;
  1315. CurrentPrCode = GridPrcode.Rows[dsc[0].Index].Cells["pd_prodcode"].Value.ToString();
  1316. CurrentZXBZ = GridPrcode.Rows[dsc[0].Index].Cells["pjd_zxbzs_user"].Value.ToString();
  1317. CurrentUnit = GridPrcode.Rows[dsc[0].Index].Cells["pr_unit"].Value.ToString();
  1318. CurrentPDNO = GridPrcode.Rows[dsc[0].Index].Cells["pd_pdno"].Value.ToString();
  1319. CurrentPrCount = GridPrcode.Rows[dsc[0].Index].Cells["pd_outqty"].Value.ToString();
  1320. CurrentBrand = GridPrcode.Rows[dsc[0].Index].Cells["pd_brand"].Value.ToString();
  1321. GridPrcode.Rows[dsc[0].Index].Selected = true;
  1322. }
  1323. }
  1324. private void GridPrcode_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1325. private void GridPrcode_CellClick(object sender, DataGridViewCellEventArgs e)
  1326. {
  1327. if (e.RowIndex >= 0)
  1328. {
  1329. GridPrcode.Rows[e.RowIndex].Selected = true;
  1330. }
  1331. }
  1332. private void DCCheck_Leave(object sender, EventArgs e)
  1333. {
  1334. try
  1335. {
  1336. Properties.Settings.Default.DCCheck = int.Parse(DCCheck.Text);
  1337. Properties.Settings.Default.Save();
  1338. }
  1339. catch (Exception)
  1340. {
  1341. MessageBox.Show("DC校验时间必须是整数");
  1342. }
  1343. }
  1344. /// <summary>
  1345. /// 校验DateCode
  1346. /// </summary>
  1347. /// <param name="DateCode"></param>
  1348. private bool CheckDateCode(string DateCode)
  1349. {
  1350. //根据DateCode计算的日期
  1351. string Year = DateCode.Substring(0, 2);
  1352. System.DateTime dt = new System.DateTime(int.Parse("20" + Year), 01, 01);
  1353. string Week = DateCode.Substring(2, 2);
  1354. System.DateTime dt1 = dt.AddDays(int.Parse(Week) * 7);
  1355. //减去DC校验后的日期
  1356. System.DateTime now = System.DateTime.Now;
  1357. System.DateTime now1 = now.AddDays(-int.Parse(DCCheck.Text));
  1358. //物料的DateCode大于限制日期即可
  1359. if (dt1 > now1)
  1360. {
  1361. return true;
  1362. }
  1363. return false;
  1364. }
  1365. private void PrintFooter_Click(object sender, EventArgs e)
  1366. {
  1367. DataTable dt = (DataTable)dh.ExecuteSql("select pib_outboxcode2,max(pib_id) pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' group by pib_outboxcode2 order by pib_outboxcode2", "select");
  1368. string SQL = "select pib_outboxcode2||'/'||(select max(pib_outboxcode2) from prodiobarcode where pib_inoutno={pib_inoutno}) from prodiobarcode where pib_id={pib_id}";
  1369. for (int i = 0; i < dt.Rows.Count; i++)
  1370. {
  1371. DataTable dt1 = (DataTable)dh.ExecuteSql(SQL.Replace("{pib_inoutno}", "'" + pi_inoutno.Text + "'").Replace("{pib_id}", dt.Rows[i]["pib_id"].ToString()), "select");
  1372. FootDoc.Variables.FreeVariables.Item("唛头").Value = dt1.Rows[0][0].ToString();
  1373. FootDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  1374. FootDoc.PrintDocument();
  1375. }
  1376. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "打印唛头", "成功");
  1377. }
  1378. private void Input_KeyUp(object sender, KeyEventArgs e)
  1379. {
  1380. if (e.KeyCode == Keys.Enter)
  1381. {
  1382. Input.SelectAll();
  1383. }
  1384. }
  1385. private void GridPrcode_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  1386. {
  1387. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  1388. if (e.ColumnIndex > 0 && e.RowIndex >= 0)
  1389. {
  1390. if (GridPrcode.Columns[e.ColumnIndex].Name == "pd_outqty")
  1391. {
  1392. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1393. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
  1394. Rectangle border = e.CellBounds;
  1395. border.Width -= 1;
  1396. e.Graphics.DrawRectangle(Pens.White, border);
  1397. e.PaintContent(e.CellBounds);
  1398. e.Handled = true;
  1399. }
  1400. if (GridPrcode.Columns[e.ColumnIndex].Name == "UnCollectedNum" || GridPrcode.Columns[e.ColumnIndex].Name == "CollectedNum")
  1401. {
  1402. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1403. if (GridPrcode.Rows[e.RowIndex].Cells["UnCollectedNum"].Value.ToString() == "0")
  1404. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
  1405. else
  1406. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.Gray, e.CellBounds);
  1407. Rectangle border = e.CellBounds;
  1408. border.Width -= 1;
  1409. e.Graphics.DrawRectangle(Pens.White, border);
  1410. e.PaintContent(e.CellBounds);
  1411. e.Handled = true;
  1412. }
  1413. }
  1414. }
  1415. private void GridPrcode_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
  1416. {
  1417. if (e.Button == MouseButtons.Right)
  1418. {
  1419. if (e.RowIndex >= 0 && e.ColumnIndex > 0)
  1420. {
  1421. string Conetent = GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  1422. Clipboard.SetText(Conetent);
  1423. MessageBox.Show("已复制内容" + Conetent);
  1424. }
  1425. }
  1426. }
  1427. private void OutBoxNum_SelectedIndexChanged(object sender, EventArgs e)
  1428. {
  1429. LoadGridData(sender, e);
  1430. }
  1431. private void Pack_Click(object sender, EventArgs e)
  1432. {
  1433. DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by pib_outboxcode2", "select");
  1434. string Prefix = "";
  1435. string Suffix = "";
  1436. int CurrentMaxNum = 0;
  1437. int Length = 0;
  1438. int Radix = 0;
  1439. GetBarCodeRule(out Prefix, out Suffix, out CurrentMaxNum, out Length, out Radix);
  1440. if (Radix > 0)
  1441. {
  1442. //生成中盒条码
  1443. int pib_outboxcode1 = 0;
  1444. for (int i = 0; i < dt.Rows.Count; i++)
  1445. {
  1446. List<string> MidBoxCode = new List<string>();
  1447. List<string> PIBID = new List<string>();
  1448. List<string> PIBOUTBOXCODE1 = new List<string>();
  1449. DataTable dt1 = (DataTable)dh.ExecuteSql("select pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + dt.Rows[i]["pib_outboxcode2"].ToString() + "' order by to_number(pib_id)", "select");
  1450. //如果不是10的整数倍则为尾盒
  1451. for (int j = 0; j < dt1.Rows.Count; j++)
  1452. {
  1453. if (j % 10 == 0 && j != 0)
  1454. {
  1455. pib_outboxcode1 = pib_outboxcode1 + 1;
  1456. CurrentMaxNum = CurrentMaxNum + 1;
  1457. }
  1458. string serialcode = BaseUtil.DToAny(CurrentMaxNum, Radix);
  1459. for (int k = serialcode.ToString().Length; k < NumLength; k++)
  1460. {
  1461. serialcode = "0" + serialcode;
  1462. }
  1463. MidBoxCode.Add(Prefix + serialcode + Suffix);
  1464. PIBID.Add(dt1.Rows[j]["pib_id"].ToString());
  1465. PIBOUTBOXCODE1.Add(pib_outboxcode1.ToString());
  1466. }
  1467. dh.BatchInsert("update prodiobarcode set pib_custmidboxcode=:pib_custmidboxcode,pib_outboxcode1=:pib_outboxcode1 where pib_id=:pib_id and pib_custmidboxcode is null", new string[] { "pib_custmidboxcode", "pib_outboxcode1", "pib_id" }, MidBoxCode.ToArray(), PIBOUTBOXCODE1.ToArray(), PIBID.ToArray());
  1468. }
  1469. CurrentMaxNum = CurrentMaxNum + 1;
  1470. //生成外箱条码
  1471. for (int i = 0; i < dt.Rows.Count; i++)
  1472. {
  1473. List<string> OutBoxCode = new List<string>();
  1474. List<string> PIBOUTBOXCODE2 = new List<string>();
  1475. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  1476. for (int k = serialcode.ToString().Length; k < NumLength; k++)
  1477. {
  1478. serialcode = "0" + serialcode;
  1479. }
  1480. OutBoxCode.Add(Prefix + serialcode + Suffix);
  1481. PIBOUTBOXCODE2.Add(dt.Rows[i]["pib_outboxcode2"].ToString());
  1482. MaxNum = MaxNum + 1;
  1483. dh.BatchInsert("update prodiobarcode set pib_custoutboxcode=:pib_custoutboxcode where pib_outboxcode2=:pib_outboxcode2 and pib_custoutboxcode is null", new string[] { "pib_custoutboxcode", "pib_outboxcode2" }, OutBoxCode.ToArray(), PIBOUTBOXCODE2.ToArray());
  1484. }
  1485. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + CurrentMaxNum + "'", "rmn_nrcode='" + pi_cardcode.Text + "' and rmn_prefix='" + Prefix + "'");
  1486. }
  1487. LoadGridData(sender, e);
  1488. }
  1489. private void PrintStatus_Click(object sender, EventArgs e)
  1490. {
  1491. EnablePrint = !EnablePrint;
  1492. if (EnablePrint)
  1493. {
  1494. SetPrintStatus_label.ForeColor = Color.Green;
  1495. SetPrintStatus_label.Text = "可打印";
  1496. }
  1497. else
  1498. {
  1499. SetPrintStatus_label.ForeColor = Color.Red;
  1500. SetPrintStatus_label.Text = "暂停打印";
  1501. }
  1502. }
  1503. }
  1504. }