UAS_出货标签管理.cs 107 KB

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