UAS_出货标签管理.cs 77 KB

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