UAS_出货标签管理.cs 122 KB

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