UAS_出货标签管理.cs 93 KB

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