UAS_出货标签管理.cs 84 KB

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