UAS_出货标签管理.cs 83 KB

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