UAS_出货标签管理.cs 166 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490
  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. //传送贴标角度
  94. string Angle = "";
  95. string X = "";
  96. string Y = "";
  97. bool CheckPassWord = true;
  98. //贴标机采集的行数
  99. int MachineCollectRowIndex = 0;
  100. public UAS_出货标签打印(string Master)
  101. {
  102. this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
  103. this.UpdateStyles();
  104. InitializeComponent();
  105. //利用反射设置DataGridView的双缓冲
  106. Type dgvType = this.LabelInf.GetType();
  107. PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
  108. pi.SetValue(this.LabelInf, true, null);
  109. pi.SetValue(this.GridPrcode, true, null);
  110. (new EnvironmentSettings()).ReportSettings.ShowProgress = false;
  111. Text = Text + "-" + Master;
  112. }
  113. //protected override void WndProc(ref Message m)
  114. //{
  115. // //拦截双击标题栏、移动窗体的系统消息
  116. // if (m.Msg != 0xA3)
  117. // {
  118. // base.WndProc(ref m);
  119. // }
  120. //}
  121. delegate void BindDataSource(DataGridView dgv, DataTable dt);//定义委托
  122. void bindingsource(DataGridView dgv, DataTable dt)
  123. {
  124. //dgv.AutoGenerateColumns = false;
  125. //dgv.DataSource = null;
  126. //dgv.DataSource = dt;
  127. if (dgv.InvokeRequired)
  128. {
  129. dgv.Invoke(new BindDataSource(bindingsource), new object[] { dgv, dt });
  130. }
  131. else
  132. {
  133. dgv.AutoGenerateColumns = false;
  134. dgv.DataSource = dt;
  135. }
  136. }
  137. private void 贴标机条码打印_Load(object sender, EventArgs e)
  138. {
  139. //用计时器重置数据库链接
  140. LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】");
  141. dh = SystemInf.dh;
  142. CheckForIllegalCrossThreadCalls = false;
  143. pi_inoutno.Focus();
  144. Point pt = new Point();
  145. //禁止所有列的排序
  146. foreach (DataGridViewColumn dgv in LabelInf.Columns)
  147. {
  148. dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
  149. }
  150. foreach (DataGridViewColumn dgv in GridPrcode.Columns)
  151. {
  152. dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
  153. }
  154. DataTable size = new DataTable();
  155. size.Columns.Add("size_name");
  156. size.Columns.Add("size_value");
  157. DataRow dr = size.NewRow(); dr[0] = "大箱"; dr[1] = "38.3*38.3*20CM";
  158. DataRow dr1 = size.NewRow(); dr1[0] = "中箱"; dr1[1] = "38.3*19*20CM";
  159. DataRow dr2 = size.NewRow(); dr2[0] = "小盒"; dr2[1] = "19*19*6.5CM";
  160. DataRow dr3 = size.NewRow(); dr3[0] = "小白盒07"; dr3[1] = "19*19*9CM";
  161. DataRow dr4 = size.NewRow(); dr4[0] = "三星盒10"; dr4[1] = "18*12*18.3CM";
  162. DataRow dr5 = size.NewRow(); dr5[0] = "国巨40"; dr5[1] = "39*30*21CM";
  163. DataRow dr6 = size.NewRow(); dr6[0] = "国巨25"; dr6[1] = "32*20*21CM";
  164. DataRow dr7 = size.NewRow(); dr7[0] = "国巨14"; dr7[1] = "19.5*16*20CM";
  165. size.Rows.Add(dr);
  166. size.Rows.Add(dr1);
  167. size.Rows.Add(dr2);
  168. size.Rows.Add(dr3);
  169. size.Rows.Add(dr4);
  170. size.Rows.Add(dr5);
  171. size.Rows.Add(dr6);
  172. size.Rows.Add(dr7);
  173. pib_size.DataSource = size;
  174. pib_size.DisplayMember = "size_name";
  175. pib_size.ValueMember = "size_value";
  176. int ScreenWidth = Screen.GetWorkingArea(pt).Width;
  177. //设置获取当前屏幕大小自动全屏但是保留任务栏
  178. Rectangle ScreenArea = Screen.GetWorkingArea(this);
  179. Top = 0;
  180. Left = 0;
  181. Width = ScreenArea.Width;
  182. Height = ScreenArea.Height;
  183. //OutboxCapacity.Value = Properties.Settings.Default.OutboxCapacity;
  184. MidboxCapacity.Value = Properties.Settings.Default.MidBoxCapacity;
  185. if (MidboxCapacity.Value == 0)
  186. {
  187. MidboxCapacity.Value = 10;
  188. }
  189. DCCheck.Text = Properties.Settings.Default.DCCheck.ToString();
  190. OutBoxPrinter.Text = Properties.Settings.Default.OPrinter;
  191. MidLabelPrinter.Text = Properties.Settings.Default.MPrinter;
  192. SingleLabelPrinter.Text = Properties.Settings.Default.SPrinter;
  193. asc.controllInitializeSize(this);
  194. asc.controlAutoSize(this);
  195. RefreshDBConnect.Interval = 60000;
  196. RefreshDBConnect.Start();
  197. }
  198. //只执行一次窗体自适应
  199. bool AutoSized = false;
  200. private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
  201. {
  202. if (!AutoSized)
  203. {
  204. asc.controlAutoSize(this);
  205. AutoSized = true;
  206. }
  207. }
  208. private void LabelMaintain_Click(object sender, EventArgs e)
  209. {
  210. 客户标签维护 form = new 客户标签维护();
  211. BaseUtil.SetFormCenter(form);
  212. form.FormClosed += LabelFormClose;
  213. form.ShowDialog();
  214. }
  215. int combined = 0;
  216. private void LabelFormClose(object sender, EventArgs e)
  217. {
  218. GetInOutInfAndLabelFile();
  219. }
  220. int PassTenCount = 1;
  221. int PassSixTenCount = 1;
  222. //输入框Enter事件
  223. private void Input_KeyDown(object sender, KeyEventArgs e)
  224. {
  225. if (e.KeyCode == Keys.Enter)
  226. {
  227. if (Input.Text == "")
  228. {
  229. richTextAutoBottom1.AppendText("采集的数据不能为空\n");
  230. receiveClient.Client.Send(Encoding.ASCII.GetBytes("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N")));
  231. return;
  232. }
  233. CollectInputData();
  234. }
  235. }
  236. /// <summary>
  237. /// 采集数据
  238. /// </summary>
  239. private void CollectInputData()
  240. {
  241. if (Input.Text == "SC")
  242. {
  243. PrintStatus.PerformClick();
  244. Input.Text = "";
  245. return;
  246. }
  247. Input.Text = Input.Text.Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "");
  248. Dictionary<string, string> Data = new Dictionary<string, string>();
  249. string[] SplitData = Input.Text.Split('*');
  250. string[] SplitData2 = Input.Text.Split('*');
  251. string[] SplitData3 = Input.Text.Split(';');
  252. if (SplitData3.Length > 5)
  253. {
  254. Data.Add("PRCODE", SplitData3[1]);
  255. Data.Add("QTY", SplitData3[5]);
  256. string ddc = SplitData3[0].Substring(0, 4).Replace("O", "10").Replace("N", "11").Replace("D", "12");
  257. if (ddc.Length == 4)
  258. {
  259. ddc = "202" + ddc.Substring(0, 1) + "0" + ddc.Substring(1);
  260. }
  261. else
  262. {
  263. ddc = "202" + ddc;
  264. }
  265. ddc = dh.getFieldDataByCondition("dual", "to_char(trunc(to_date('" + ddc + "','yyyymmdd')+1,'iw')+6,'yy')||to_char(to_date('" + ddc + "','yyyymmdd')+1,'iw')", "1=1").ToString();
  266. Data.Add("DATECODE", ddc);
  267. Data.Add("BRAND", "A");
  268. Data.Add("LOTNO", SplitData3[0]);
  269. Data.Add("PO", "");
  270. Data.Add("SERIAL", "");
  271. }
  272. else if (SplitData.Length < 5)
  273. {
  274. SplitData2 = Input.Text.Split(System.Convert.ToChar(29));//< GS >
  275. SplitData2 = Regex.Split(Input.Text, "<GS>", RegexOptions.IgnoreCase);
  276. String qty;
  277. for (int i = 0; i < SplitData2.Length; i++)
  278. {
  279. Console.WriteLine(SplitData2[i]);
  280. }
  281. if (SplitData2.Length < 10)
  282. {
  283. richTextAutoBottom1.AppendText("数据格式错误,无法解析\n");
  284. if (ConnectToMachine)
  285. {
  286. receiveClient.Client.Send(Encoding.ASCII.GetBytes("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N")));
  287. }
  288. //Input.SelectAll();
  289. return;
  290. }
  291. else
  292. {
  293. String qtycheck = SplitData2[3].Substring(1, SplitData2[3].Length - 1).Split('/')[0];
  294. try
  295. {
  296. qty = SplitData2[3].Substring(1, SplitData2[3].Length - 1).Split('/')[1];
  297. }
  298. catch
  299. {
  300. qty = SplitData2[3].Substring(1, SplitData2[3].Length - 1).Split('/')[0];
  301. }
  302. if (dh.CheckExist("product", "pr_code = '" + SplitData2[2].Substring(3, SplitData2[2].Length - 3) + "-" + SplitData2[1].Substring(SplitData2[1].Length - 3, 3) + "'"))
  303. {
  304. Data.Add("PRCODE", SplitData2[2].Substring(3, SplitData2[2].Length - 3) + "-" + SplitData2[1].Substring(SplitData2[1].Length - 3, 3));
  305. }
  306. else if (dh.CheckExist("product", "pr_specvalue = '" + SplitData2[2].Substring(3, SplitData2[2].Length - 3) + "' and pr_nexbzs_user = '" + qtycheck + "' "))
  307. {
  308. Data.Add("PRCODE", dh.getFieldDataByCondition("product", "pr_code", "pr_specvalue = '" + SplitData2[2].Substring(3, SplitData2[2].Length - 3) + "' and pr_nexbzs_user = '" + qtycheck + "'").ToString());
  309. }
  310. else
  311. {
  312. Data.Add("PRCODE", "");
  313. }
  314. }
  315. Data.Add("QTY", qty);
  316. Data.Add("DATECODE", SplitData2[4].Substring(2, SplitData2[4].Length - 2));
  317. if (checkBox1.Checked)
  318. {
  319. Data.Add("BRAND", "P");
  320. }
  321. else
  322. {
  323. Data.Add("BRAND", "NEX");
  324. }
  325. Data.Add("LOTNO", SplitData2[5].Substring(2, SplitData2[5].Length - 2));
  326. Data.Add("PO", SplitData2[5].Substring(2, SplitData2[5].Length - 2));
  327. Data.Add("SERIAL", SplitData2[5].Substring(2, SplitData2[5].Length - 2));
  328. }
  329. else
  330. {
  331. for (int i = 0; i < SplitData.Length; i++)
  332. {
  333. switch (i.ToString())
  334. {
  335. case "0":
  336. Data.Add("PRCODE", SplitData[i]);
  337. break;
  338. case "1":
  339. Data.Add("QTY", SplitData[i]);
  340. break;
  341. case "2":
  342. Data.Add("DATECODE", SplitData[i]);
  343. break;
  344. case "3":
  345. Data.Add("BRAND", SplitData[i]);
  346. break;
  347. case "4":
  348. Data.Add("LOTNO", SplitData[i]);
  349. break;
  350. case "5":
  351. Data.Add("PO", SplitData[i]);
  352. break;
  353. case "6":
  354. Data.Add("SERIAL", SplitData[i]);
  355. break;
  356. default:
  357. break;
  358. }
  359. }
  360. }
  361. if (Data["PRCODE"] != CurrentPrCode)
  362. {
  363. if (!MixPrCode.Checked)
  364. {
  365. richTextAutoBottom1.AppendText("当前采集【物料编号" + Data["PRCODE"] + "】不对应,请重新采集\n");
  366. //Input.SelectAll();
  367. if (ConnectToMachine)
  368. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N"))));
  369. return;
  370. }
  371. else
  372. {
  373. bool FindProd = false;
  374. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  375. {
  376. string prodcode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  377. string outqty = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  378. string collectnum = GridPrcode.Rows[i].Cells["collectednum"].Value.ToString();
  379. //判断其他行是否有料可以匹配
  380. if (prodcode == Data["PRCODE"] && decimal.Parse(outqty) > decimal.Parse(collectnum))
  381. {
  382. GridPrcode.Rows[i].Selected = true;
  383. FindProd = true;
  384. }
  385. }
  386. if (!FindProd)
  387. {
  388. richTextAutoBottom1.AppendText("当前采集【物料编号" + Data["PRCODE"] + "】没有需要采集的内容\n");
  389. //Input.SelectAll();
  390. if (ConnectToMachine)
  391. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N"))));
  392. return;
  393. }
  394. }
  395. }
  396. //校验DateCode是否过期
  397. if (!CheckDateCode(Data["DATECODE"]))
  398. {
  399. if (ConnectToMachine)
  400. {
  401. richTextAutoBottom1.AppendText("物料" + Data["PRCODE"] + "【DateCode】超出校验日期\n");
  402. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N"))));
  403. return;
  404. }
  405. else
  406. {
  407. string close = MessageBox.Show(this.ParentForm, "物料" + Data["PRCODE"] + "【DateCode】超出校验日期\n", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  408. if (close.ToString() != "Yes")
  409. return;
  410. }
  411. }
  412. if (CheckDC.Checked)
  413. {
  414. string datecode = dh.getFieldDataByCondition("prodiobarcode", "max(case when length(pib_datecode)=4 then pib_datecode else to_char(to_date(custdate(pib_datecode),'yyyy-mm-dd'),'yyiw') end )", "PIB_CUSTCODE='" + pi_cardcode.Text + "' and pib_inoutno<>'" + pi_inoutno.Text + "' and pib_prodcode='" + Data["PRCODE"] + "'").ToString();
  415. string datecod1 = dh.getFieldDataByCondition("dual", "case when length('" + Data["DATECODE"] + "')=4 then '" + Data["DATECODE"] + "' else to_char(to_date(custdate('" + Data["DATECODE"] + "'),'yyyy-mm-dd'),'yyiw') end", "1=1").ToString();
  416. //客户已经出货的最大年周
  417. string Year = datecode.Substring(0, 2);
  418. System.DateTime dt = new DateTime(int.Parse("20" + Year), 01, 01);
  419. string Week = datecode.Substring(2, 2);
  420. System.DateTime dt1 = dt.AddDays(int.Parse(Week) * 7);
  421. //当前扫码的年周
  422. string Year1 = datecod1.Substring(0, 2);
  423. System.DateTime dt2 = new DateTime(int.Parse("20" + Year1), 01, 01);
  424. string Week1 = datecod1.Substring(2, 2);
  425. System.DateTime dt3 = dt2.AddDays(int.Parse(Week1) * 7 + 7);
  426. //当前扫码的年周
  427. if (dt1 > dt3)
  428. {
  429. MessageBox.Show("客户出货日期最近DC【" + datecode + "】,不允许采集【" + Data["DATECODE"] + "】");
  430. return;
  431. }
  432. }
  433. if (Data["BRAND"] != CurrentBrand)
  434. {
  435. if (ConnectToMachine)
  436. {
  437. richTextAutoBottom1.AppendText("当前采集【品牌" + Data["BRAND"] + "】不对应\n");
  438. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N"))));
  439. return;
  440. }
  441. else
  442. {
  443. string close = MessageBox.Show(this.ParentForm, "当前采集【品牌" + Data["BRAND"] + "】不对应", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  444. if (close.ToString() != "Yes")
  445. return;
  446. }
  447. }
  448. int CodeCount = 0;
  449. //如果单位是KPCS则需要除1000
  450. double CollectNum = 0;
  451. if (CurrentUnit == "KPCS")
  452. {
  453. try
  454. {
  455. double.Parse(CurrentZXBZ);
  456. }
  457. catch (Exception)
  458. {
  459. MessageBox.Show("请检查最小包装数");
  460. }
  461. //如果单位是KPCS则必须是1000的整数倍
  462. if (decimal.Parse((Convert.ToDouble((double.Parse(Data["QTY"]) / 1000).ToString("0.000")) / Convert.ToDouble(double.Parse(CurrentZXBZ).ToString("0.000"))).ToString()) % 1 != 0)
  463. {
  464. richTextAutoBottom1.AppendText("物料" + Data["PRCODE"] + "采集数量无法按照最小包装数拆分\n");
  465. //Input.SelectAll();
  466. if (ConnectToMachine)
  467. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N"))));
  468. return;
  469. }
  470. CodeCount = int.Parse((double.Parse(Data["QTY"]) / 1000 / double.Parse(CurrentZXBZ)).ToString());
  471. CollectNum = double.Parse(Data["QTY"]) / 1000;
  472. }
  473. else
  474. {
  475. if (double.Parse(Data["QTY"]) % double.Parse(CurrentZXBZ) != 0)
  476. {
  477. richTextAutoBottom1.AppendText("采集【数量】无法按照最小包装数拆分\n");
  478. if (ConnectToMachine)
  479. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N"))));
  480. //Input.SelectAll();
  481. return;
  482. }
  483. CodeCount = int.Parse((double.Parse(Data["QTY"]) / double.Parse(CurrentZXBZ)).ToString());
  484. CollectNum = double.Parse(Data["QTY"]);
  485. }
  486. string pib_barcode = Data.ContainsKey("SERIAL") ? Data["SERIAL"] : "";
  487. //获取ID
  488. PIBID = dh.GetSEQ("prodiobarcode_seq", CodeCount);
  489. //加载完数据之后进行容量的判断
  490. string pib_outboxcode2 = "";
  491. int BoxNum = LabelInfDataTable.Select("pib_outboxcode2='" + OutBoxNum.Text + "'").Length;
  492. if (ConnectToMachine)
  493. {
  494. if (BoxNum + CodeCount > OutboxCapacity.Value && AutoSetOutBox.Checked)
  495. {
  496. string maxoutbox = dh.getFieldDataByCondition("prodiobarcode", "max(to_number(pib_outboxcode2))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  497. //如果没有则从开始插入
  498. if (maxoutbox == "")
  499. {
  500. pib_outboxcode2 = "1";
  501. }
  502. else
  503. {
  504. pib_outboxcode2 = (int.Parse(maxoutbox) + 1).ToString();
  505. }
  506. OutBoxNum.Items.Clear();
  507. 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");
  508. ItemObject io = new ItemObject("新增", "新增");
  509. OutBoxNum.Items.Add(io);
  510. io = new ItemObject("全部", "全部");
  511. OutBoxNum.Items.Add(io);
  512. io = new ItemObject(pib_outboxcode2, pib_outboxcode2);
  513. OutBoxNum.Items.Add(io);
  514. PassSixTenCount = 1;
  515. for (int i = 0; i < dt.Rows.Count; i++)
  516. {
  517. string piboutboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  518. io = new ItemObject(piboutboxcode2, piboutboxcode2);
  519. OutBoxNum.Items.Add(io);
  520. }
  521. if (OutBoxNum.Items.Count > 2)
  522. OutBoxNum.SelectedIndex = 2;
  523. BoxNum = LabelInfDataTable.Select("pib_outboxcode2='" + OutBoxNum.Text + "'").Length;
  524. }
  525. else
  526. {
  527. if (OutBoxNum.Text == "新增")
  528. {
  529. string maxoutbox = dh.getFieldDataByCondition("prodiobarcode", "max(to_number(pib_outboxcode2))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  530. //如果没有则从开始插入
  531. if (maxoutbox == "")
  532. {
  533. pib_outboxcode2 = "1";
  534. }
  535. else
  536. {
  537. pib_outboxcode2 = (int.Parse(maxoutbox) + 1).ToString();
  538. }
  539. OutBoxNum.Items.Clear();
  540. 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");
  541. ItemObject io = new ItemObject("新增", "新增");
  542. OutBoxNum.Items.Add(io);
  543. io = new ItemObject("全部", "全部");
  544. OutBoxNum.Items.Add(io);
  545. io = new ItemObject(pib_outboxcode2, pib_outboxcode2);
  546. OutBoxNum.Items.Add(io);
  547. PassSixTenCount = 1;
  548. for (int i = 0; i < dt.Rows.Count; i++)
  549. {
  550. string piboutboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  551. io = new ItemObject(piboutboxcode2, piboutboxcode2);
  552. OutBoxNum.Items.Add(io);
  553. }
  554. if (OutBoxNum.Items.Count > 2)
  555. OutBoxNum.SelectedIndex = 2;
  556. BoxNum = LabelInfDataTable.Select("pib_outboxcode2='" + OutBoxNum.Text + "'").Length;
  557. }
  558. else
  559. {
  560. pib_outboxcode2 = OutBoxNum.Text;
  561. }
  562. }
  563. }
  564. else
  565. {
  566. if (BoxNum + CodeCount > OutboxCapacity.Value && AutoSetOutBox.Checked)
  567. {
  568. OutBoxNum.Text = "新增";
  569. BoxNum = 0;
  570. }
  571. if (OutBoxNum.Text == "新增")
  572. {
  573. string maxoutbox = dh.getFieldDataByCondition("prodiobarcode", "max(to_number(pib_outboxcode2))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  574. //如果没有则从开始插入
  575. if (maxoutbox == "")
  576. {
  577. pib_outboxcode2 = "1";
  578. }
  579. else
  580. {
  581. pib_outboxcode2 = (int.Parse(maxoutbox) + 1).ToString();
  582. }
  583. }
  584. else
  585. {
  586. pib_outboxcode2 = OutBoxNum.Text;
  587. }
  588. if (!AutoPrintOutBox.Checked)
  589. {
  590. if (BoxNum + CodeCount > OutboxCapacity.Value && !AutoSetOutBox.Checked)
  591. {
  592. string close = MessageBox.Show(this.ParentForm, "箱号【" + OutBoxNum.Text + "】后超数量为" + (BoxNum + CodeCount) + ",超出容量" + OutboxCapacity.Value + ",是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  593. if (close != "Yes")
  594. {
  595. Input.SelectAll();
  596. return;
  597. }
  598. }
  599. }
  600. }
  601. if (OutBoxNum.Text == "全部")
  602. {
  603. MessageBox.Show("请选择指定箱号或者新增");
  604. return;
  605. }
  606. //计算当前采集数量
  607. string collectqty = dh.getFieldDataByCondition("prodiobarcode", "sum(pib_qty)", "pib_inoutno='" + pi_inoutno.Text + "' and pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString();
  608. double CollectQty = (collectqty == "" ? 0 : double.Parse(collectqty));
  609. if (Convert.ToDouble((CollectQty + CollectNum).ToString("0.000")) > Convert.ToDouble(double.Parse(CurrentPrCount).ToString("0.000")))
  610. {
  611. richTextAutoBottom1.AppendText("物料" + Data["PRCODE"] + "采集后数量为" + (CollectQty + CollectNum) + ",【超出】本行出货数量" + CurrentPrCount + "\n");
  612. if (ConnectToMachine)
  613. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N"))));
  614. //Input.SelectAll();
  615. return;
  616. }
  617. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, CodeCount);
  618. List<string> CustBarCode = new List<string>();
  619. if (!(Radix > 0))
  620. {
  621. string close = MessageBox.Show(this.ParentForm, "未维护条码规则,是否继续生成", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  622. if (close.ToString() != "Yes")
  623. return;
  624. }
  625. for (int i = 0; i < CodeCount; i++)
  626. {
  627. if (Radix > 0)
  628. {
  629. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  630. for (int j = serialcode.ToString().Length; j < NumLength; j++)
  631. {
  632. serialcode = "0" + serialcode;
  633. }
  634. CustBarCode.Add(Prefix + serialcode + Suffix);
  635. MaxNum = MaxNum + 1;
  636. }
  637. else
  638. {
  639. CustBarCode.Add("");
  640. }
  641. }
  642. string rulecode = ShareRule == "" ? NrCode : ShareRule;
  643. sql.Clear();
  644. sql.Append("insert into prodiobarcode(PIB_ID,PIB_PRODCODE,PIB_INDATE,PIB_INOUTNO,PIB_PIID,PIB_PDNO, PIB_PDID,PIB_PICLASS,");
  645. 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,pib_ismachine,pib_rulecode,pib_remark1) ");
  646. sql.Append("select :PIB_ID,pd_prodcode,sysdate,pi_inoutno,pi_id,pd_pdno,pd_id,pi_class,");
  647. 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 + "','" + (ConnectToMachine ? "Y" : "N") + "','" + rulecode + "','" + remarkinfo.Text + "'");
  648. 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 + "'");
  649. int rowsnum = 0;
  650. try
  651. {
  652. rowsnum = dh.BatchInsert(sql.ToString(), new string[] { "PIB_ID", "PIB_CUSTBARCODE" }, PIBID, CustBarCode.ToArray());
  653. }
  654. catch (Exception)
  655. {
  656. if (ReSetType != " ")
  657. {
  658. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'");
  659. }
  660. else
  661. {
  662. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "'");
  663. }
  664. CollectInputData();
  665. return;
  666. }
  667. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, Input.Text, "数据插入成功");
  668. if (rowsnum == 0)
  669. {
  670. MessageBox.Show("未成功插入数据,请核对出货单当前明细", "提示");
  671. }
  672. //更新流水号
  673. if (!ConnectToMachine)
  674. {
  675. if (OutBoxNum.Text == "新增")
  676. {
  677. OutBoxNum.Items.Clear();
  678. 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");
  679. ItemObject io = new ItemObject("新增", "新增");
  680. OutBoxNum.Items.Add(io);
  681. io = new ItemObject("全部", "全部");
  682. OutBoxNum.Items.Add(io);
  683. for (int i = 0; i < dt.Rows.Count; i++)
  684. {
  685. string piboutboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  686. io = new ItemObject(piboutboxcode2, piboutboxcode2);
  687. OutBoxNum.Items.Add(io);
  688. }
  689. if (OutBoxNum.Items.Count > 2)
  690. OutBoxNum.SelectedIndex = 2;
  691. }
  692. }
  693. LoadGridData(new object(), new EventArgs());
  694. if (LabelInf.Rows.Count > 0)
  695. {
  696. LabelInf.Rows[LabelInf.Rows.Count - 1].Selected = true;
  697. }
  698. if (SingleLabelAutoPrint.Checked)
  699. {
  700. thread = new Thread(AutoPrintSingleLabel);
  701. stw = new SetLoadingWindow(thread, "正在打印单盘标签");
  702. BaseUtil.SetFormCenter(stw);
  703. stw.ShowDialog();
  704. if (ConnectToMachine)
  705. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|OK|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N"))));
  706. }
  707. else
  708. {
  709. if (ConnectToMachine)
  710. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|OK|,|N")));
  711. }
  712. if (SumQty.Columns.Count == 0)
  713. {
  714. sql.Clear();
  715. sql.Append("select pib_pdno,pib_prodcode,sum(pib_qty) pib_qty from prodiobarcode left join prodiodetail on pd_id=pib_pdid and pd_pdno=pib_pdno ");
  716. sql.Append("where pd_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno ");
  717. SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  718. }
  719. //采集后重新计数,自动跳到下一行
  720. if (SumQty == null)
  721. {
  722. sql.Clear();
  723. sql.Append("select pib_pdno,pib_prodcode,sum(pib_qty) pib_qty from prodiobarcode left join prodiodetail on pd_id=pib_pdid and pd_pdno=pib_pdno ");
  724. sql.Append("where pd_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno ");
  725. SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  726. }
  727. collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  728. CollectQty = (collectqty == "" ? 0 : double.Parse(collectqty));
  729. if (Combindetail.Checked)
  730. combined = 1;
  731. if (CombindetailTwo.Checked)
  732. combined = 2;
  733. if (CombindetailThree.Checked)
  734. combined = 3;
  735. dh.UpdateByCondition("CS$InoutPrcode", "Collectednum='" + CollectQty + "'", "pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + CurrentPDNO + "' and combined=" + combined);
  736. CollectNum = 0;
  737. double OutNum = 0;
  738. if (GridPrcode.SelectedRows.Count > 0)
  739. {
  740. GridPrcode.Rows[GridPrcode.SelectedRows[0].Index].Cells["CollectedNum"].Value = CollectQty;
  741. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  742. {
  743. CollectNum += float.Parse(GridPrcode.Rows[i].Cells["CollectedNum"].Value.ToString());
  744. OutNum += float.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString());
  745. }
  746. }
  747. Console.WriteLine(DateTime.Now.ToString("yyyy-mm-dd hh:mm:ss:ffffff"));
  748. ProcessCount.Text = CollectNum + "/" + OutNum;
  749. if (CollectNum == OutNum)
  750. {
  751. dh.UpdateByCondition("prodinout", "pi_user_packingstatus='Packed'", "pi_inoutno='" + pi_inoutno.Text + "'");
  752. }
  753. if (CollectQty / double.Parse(CurrentZXBZ) % double.Parse(MidboxCapacity.Value.ToString()) == 0)
  754. {
  755. if (LabelInf.Rows.Count > 0)
  756. LabelInf.Rows[LabelInf.Rows.Count - 1].Selected = true;
  757. if (AutoPrintMidBox.Checked)
  758. {
  759. CheckPassWord = false;
  760. MidLabelPrint.PerformClick();
  761. CheckPassWord = true;
  762. }
  763. }
  764. //采集达到了数量进行换行
  765. if (CollectQty == double.Parse(CurrentPrCount))
  766. {
  767. if (AutoPrintMidBox.Checked && (CollectQty / double.Parse(CurrentZXBZ) % double.Parse(MidboxCapacity.Value.ToString()) != 0))
  768. {
  769. CheckPassWord = false;
  770. MidLabelPrint.PerformClick();
  771. CheckPassWord = true;
  772. }
  773. //需要换行,当前最后一盒
  774. DataGridViewSelectedRowCollection selectrow = GridPrcode.SelectedRows;
  775. if (selectrow.Count > 0)
  776. {
  777. if (selectrow[0].Index + 1 < GridPrcode.Rows.Count)
  778. {
  779. string outqty = GridPrcode.Rows[selectrow[0].Index + 1].Cells["pd_outqty"].Value.ToString();
  780. string collectnum = GridPrcode.Rows[selectrow[0].Index + 1].Cells["CollectedNum"].Value.ToString();
  781. if (double.Parse(outqty) > double.Parse(collectnum == "" ? "0" : collectnum))
  782. {
  783. GridPrcode.Rows[selectrow[0].Index + 1].Selected = true;
  784. }
  785. }
  786. }
  787. }
  788. if (AutoPrintOutBox.Checked)
  789. {
  790. if (BoxNum + CodeCount >= OutboxCapacity.Value)
  791. {
  792. CheckPassWord = false;
  793. OutBoxLabelPrint.PerformClick();
  794. CheckPassWord = true;
  795. }
  796. }
  797. GridPrcode.Refresh();
  798. if (!IsSum)
  799. if (!forinput.Checked)
  800. {
  801. Input.Clear();
  802. }
  803. else
  804. {
  805. RemainTxt();
  806. }
  807. }
  808. private void AutoPrintSingleLabel()
  809. {
  810. if (EnablePrint)
  811. {
  812. //用标签本身的变量作为最外层的循环条件去匹配;
  813. StringBuilder ParamLog = new StringBuilder();
  814. string pibid = "";
  815. for (int i = 0; i < PIBID.Length; i++)
  816. {
  817. if (i != PIBID.Length - 1)
  818. pibid += "'" + PIBID[i] + "',";
  819. else
  820. pibid += "'" + PIBID[i] + "'";
  821. }
  822. if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  823. SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
  824. for (int j = 0; j < SingleReport.Parameters.Count; j++)
  825. {
  826. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, "");
  827. for (int k = 0; k < Attach.Rows.Count; k++)
  828. {
  829. if (Attach.Rows[k][0].ToString() == SingleReport.Parameters[j].Name)
  830. {
  831. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
  832. }
  833. }
  834. }
  835. StringBuilder sql = new StringBuilder();
  836. sql.Clear();
  837. sql.Append("select * from (select pb_ywmc_user 品牌英文名称,to_char(pi_date,'yyiw')出库年周,to_char(sysdate,'yyiw')当前DateCode,pi_remark 单据备注,pi_date-1 出库前一天,pib_outboxcode2 外箱号,pd_orderdetno 订单序号,pib_totalweight 总重,pr_ywmc_user 英文名称,pib_boxweight 箱重,nvl(pib_totalweight,0)-nvl(pib_boxweight,0) 净重,pib_id 主键ID,pd_pdno 出货序号,pib_prodcode 物料编号,pr_detail 物料名称,to_char(pi_date,'yyyy-mm-dd') 送达日期,pd_custprodspec 客户型号,pd_custproddetail 客户物料名称,pi_title 客户全称,cu_shortname 客户简称,pr_spec 物料规格,pib_custbarcode 客户条码,pib_custmidboxcode 中盒条码,pib_custoutboxcode 外箱条码,pib_inoutno 出货单号,");
  838. sql.Append("PD_HBSL_USER 出库数量,PD_HBSL_USER*1000 出库数量k,pjd_orispeccode 原厂型号,pib_datecode DateCode,(week_to_date(pib_datecode))DateCode1,pd_remark 备注,pd_remark2 备注2,pd_remark3 备注3,pib_lotno LotNo,");
  839. sql.Append("nvl(nvl(pd_brand,pib_brand),pr_brand)品牌,pr_unit 单位, to_char(pi_date,'yyyy-mm-dd')出库日期,PIB_QTY 最小封装数量,PIB_QTY*1000 最小封装数量k,pd_pocode 客户PO,pd_custprodcode CPN客户料号,");
  840. sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),12),'yyyy-mm-dd') 有效期一年,");
  841. sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),24),'yyyy-mm-dd') 有效期两年,");
  842. sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),36),'yyyy-mm-dd') 有效期三年,");
  843. sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),12),'yyyy-iw')有效期一年_年周,");
  844. sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),24),'yyyy-iw')有效期两年_年周,");
  845. sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),36),'yyyy-iw')有效期三年_年周,");
  846. sql.Append("wh_ppmc_user 中文品牌,em_code 装箱员编号,em_name 装箱员名称 from prodiobarcode left join prodinout on pib_piid=pi_id left join product on pib_prodcode=pr_code left join ProdIODetail on pd_id=PIB_PDID ");
  847. sql.Append("left join PRODJOINVENDDETAIL on pjd_brand=pib_brand and pjd_prodcode=pib_prodcode left join customer on pi_cardcode=cu_code left join productcustomer on pc_custid=cu_id and pc_prodcode=pd_prodcode ");
  848. if (pibid.IndexOf(",") > 0)
  849. {
  850. sql.Append("and pc_custprodcode=pd_custprodcode left join WareHouse on wh_code=pd_whcode left join employee on em_code=pib_inman left join ProductBrand on pib_brand = pb_name where pib_id in (" + pibid + ") order by pib_custbarcode)prodiosingleinfo_view");
  851. }
  852. else
  853. {
  854. sql.Append("and pc_custprodcode=pd_custprodcode left join WareHouse on wh_code=pd_whcode left join employee on em_code=pib_inman left join ProductBrand on pib_brand = pb_name where pib_id=" + pibid + " order by pib_custbarcode)prodiosingleinfo_view");
  855. }
  856. DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  857. SingleReport.RegisterData(dt, "prodiosingleinfo_view");
  858. SingleReport.GetDataSource("prodiosingleinfo_view").Enabled = true;
  859. SingleReport.PrintSettings.ShowDialog = false;
  860. SingleReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  861. try
  862. {
  863. SingleReport.Print();
  864. }
  865. catch (Exception e)
  866. {
  867. MessageBox.Show(e.Message);
  868. return;
  869. }
  870. Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text;
  871. Properties.Settings.Default.Save();
  872. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "自动打印箱标", "打印成功");
  873. }
  874. }
  875. //关闭窗口前提示用户确认
  876. private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
  877. {
  878. //如果不是注销的话
  879. if (!logout)
  880. {
  881. string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  882. if (close.ToString() != "Yes")
  883. e.Cancel = true;
  884. else
  885. {
  886. LogManager.DoLog("关闭程序");
  887. }
  888. }
  889. }
  890. /// <summary>
  891. /// 获取打印标签
  892. /// </summary>
  893. private void GetInOutInfAndLabelFile()
  894. {
  895. ComBoxClickChangeLabelDoc = false;
  896. sql.Clear();
  897. 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 ");
  898. //sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,replace(upper(CL_LABELURL),'\\\\10.2.10.238\\PRINTE\\FASTREPORT\\','C:\\打印标签\\') 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 ");
  899. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  900. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='单盘' order by cl_custcode,cl_date desc");
  901. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  902. SingleLabelCombox.DisplayMember = "cl_labelname";
  903. SingleLabelCombox.ValueMember = "cl_labelurl";
  904. SingleLabelCombox.DataSource = dt;
  905. sql.Clear();
  906. 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 ");
  907. //sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,replace(upper(CL_LABELURL),'\\\\10.2.10.238\\PRINTE\\FASTREPORT\\','C:\\打印标签\\') 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 ");
  908. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  909. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='中盒' order by cl_custcode,cl_date desc");
  910. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  911. MidLabelCombox.DisplayMember = "cl_labelname";
  912. MidLabelCombox.ValueMember = "cl_labelurl";
  913. MidLabelCombox.DataSource = dt;
  914. sql.Clear();
  915. 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 ");
  916. //sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,replace(upper(CL_LABELURL),'\\\\10.2.10.238\\PRINTE\\FASTREPORT\\','C:\\打印标签\\') 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 ");
  917. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  918. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='外箱' order by cl_custcode,cl_date desc");
  919. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  920. OutBoxCombox.DisplayMember = "cl_labelname";
  921. OutBoxCombox.ValueMember = "cl_labelurl";
  922. OutBoxCombox.DataSource = dt;
  923. ComBoxClickChangeLabelDoc = true;
  924. }
  925. bool LoadCheck = true;
  926. /// <summary>
  927. /// 出入库单录入框的回车事件
  928. /// </summary>
  929. /// <param name="sender"></param>
  930. /// <param name="e"></param>
  931. private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
  932. {
  933. if (e.KeyCode == Keys.Enter)
  934. {
  935. LoadCheck = false;
  936. Combindetail.Checked = false;
  937. CombindetailTwo.Checked = false;
  938. CombindetailThree.Checked = false;
  939. LoadCheck = true;
  940. if (!forinput.Checked)
  941. {
  942. Input.Clear();
  943. }
  944. else
  945. {
  946. RemainTxt();
  947. }
  948. sql.Clear();
  949. 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,nvl(cu_controlinout,0)cu_controlinout,nvl(cu_zxyq_user,' ')cu_zxyq_user from prodinout left join customer on pi_cardcode=cu_code where pi_inoutno='" + pi_inoutno.Text + "' and pi_invostatuscode='AUDITED'");
  950. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  951. if (dt.Rows.Count > 0)
  952. {
  953. pi_cardcode.Text = dt.Rows[0]["pi_cardcode"].ToString();
  954. pi_title.Text = dt.Rows[0]["pi_title"].ToString();
  955. pi_date.Text = dt.Rows[0]["pi_date"].ToString();
  956. PI_ID = dt.Rows[0]["pi_id"].ToString();
  957. cu_controlinout.Text = dt.Rows[0]["cu_controlinout"].ToString();
  958. cu_zxyq_user.Text = dt.Rows[0]["cu_zxyq_user"].ToString();
  959. switch (dt.Rows[0]["pi_combine_user"].ToString())
  960. {
  961. case "1":
  962. Combindetail.Checked = true;
  963. break;
  964. case "2":
  965. CombindetailTwo.Checked = true;
  966. break;
  967. case "3":
  968. CombindetailThree.Checked = true;
  969. break;
  970. default:
  971. break;
  972. }
  973. PassTenCount = 1;
  974. PassSixTenCount = 1;
  975. if (pi_cardcode.Text != "ZGCC")
  976. {
  977. CustomerLabel.Enabled = false;
  978. }
  979. else
  980. {
  981. CustomerLabel.Enabled = true;
  982. }
  983. DataTable XY = (DataTable)dh.ExecuteSql("select * from PRINTXY where px_custcode='" + pi_cardcode.Text + "' and px_machine='" + SystemInf.Machine + "'", "select");
  984. if (XY.Rows.Count == 0)
  985. {
  986. XY = (DataTable)dh.ExecuteSql("select * from PRINTXY where px_custcode='" + pi_cardcode.Text + "'", "select");
  987. }
  988. if (XY.Rows.Count > 0)
  989. {
  990. Angle = XY.Rows[0]["px_angle"].ToString();
  991. X = XY.Rows[0]["px_x"].ToString();
  992. Y = XY.Rows[0]["px_y"].ToString();
  993. }
  994. OutBoxNum_Click(new object(), new EventArgs());
  995. LoadPrcodeData();
  996. //获取条码规则
  997. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, 1);
  998. SingleID.Clear();
  999. Input.Focus();
  1000. ////从后往前找未采集的行
  1001. for (int i = GridPrcode.Rows.Count - 1; i >= 0; i--)
  1002. {
  1003. string outqty = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  1004. string collectnum = GridPrcode.Rows[i].Cells["CollectedNum"].Value.ToString();
  1005. if (double.Parse(outqty) > double.Parse(collectnum == "" ? "0" : collectnum))
  1006. {
  1007. GridPrcode.Rows[i].Selected = true;
  1008. MachineCollectRowIndex = GridPrcode.SelectedRows[0].Index;
  1009. if (i - 2 >= 0)
  1010. GridPrcode.FirstDisplayedScrollingRowIndex = i - 2;
  1011. else
  1012. GridPrcode.FirstDisplayedScrollingRowIndex = i;
  1013. }
  1014. }
  1015. pib_indate.Text = dh.getFieldDataByCondition("prodiobarcode", "min(to_char(pib_indate,'yyyy-mm-dd'))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  1016. bi_inman.Text = dh.getFieldDataByCondition("barcodeio left join employee on bi_inman=em_code", "wm_concat(distinct em_name)", "bi_piid=" + PI_ID).ToString();
  1017. pib_inman.Text = dh.getFieldDataByCondition("prodiobarcode left join employee on pib_inman=em_code", "wm_concat(distinct em_name)", "pib_piid=" + PI_ID).ToString();
  1018. 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");
  1019. thread = new Thread(GetInOutInfAndLabelFile);
  1020. stw = new SetLoadingWindow(thread, "正在获取打印标签");
  1021. BaseUtil.SetFormCenter(stw);
  1022. stw.ShowDialog();
  1023. LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
  1024. }
  1025. else MessageBox.Show("当前出入库单号不存在或者未审核!", "提示");
  1026. }
  1027. }
  1028. private void SingleBoxPrint()
  1029. {
  1030. if (EnablePrint)
  1031. {
  1032. if (LabelInf.Rows.Count > 0)
  1033. {
  1034. //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
  1035. SingleID.Clear();
  1036. //获取全部的中盒号
  1037. Dictionary<string, bool> outboxcode1 = new Dictionary<string, bool>();
  1038. //判断所有盒号为该盒的是否勾选已采集
  1039. outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true);
  1040. bool NeedPassword = false;
  1041. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1042. {
  1043. if (!SingleID.Contains(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()))
  1044. SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1045. if (LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString().ToUpper() == "TRUE")
  1046. {
  1047. NeedPassword = true;
  1048. }
  1049. }
  1050. if (NeedPassword)
  1051. {
  1052. if (PassCheck() != dh.getFieldDataByCondition("configs", "data", "code='PassWord' and caller='BarCodeSetting'").ToString())
  1053. {
  1054. MessageBox.Show("密码不正确,不允许操作");
  1055. return;
  1056. }
  1057. }
  1058. if (SingleID.ToArray().Length == 0)
  1059. {
  1060. MessageBox.Show("选择的行未勾选采集或者已打印", "提示");
  1061. return;
  1062. }
  1063. for (int i = 0; i < LabelInf.RowCount; i++)
  1064. {
  1065. if (i + 1 < LabelInf.RowCount)
  1066. {
  1067. //如果本行的中盒号和下一行不相等的话
  1068. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString())
  1069. {
  1070. if (!outboxcode1.ContainsKey(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
  1071. outboxcode1.Add(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString(), true);
  1072. }
  1073. }
  1074. }
  1075. string pibid = "";
  1076. for (int i = 0; i < LabelInf.RowCount; i++)
  1077. {
  1078. //勾选了并且未打印
  1079. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue != null && LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true")
  1080. {
  1081. pibid += "'" + LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() + "',";
  1082. LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
  1083. }
  1084. }
  1085. if (pibid != "")
  1086. {
  1087. if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1088. SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
  1089. for (int j = 0; j < SingleReport.Parameters.Count; j++)
  1090. {
  1091. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, "");
  1092. for (int k = 0; k < Attach.Rows.Count; k++)
  1093. {
  1094. if (Attach.Rows[k][0].ToString() == SingleReport.Parameters[j].Name)
  1095. {
  1096. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
  1097. }
  1098. }
  1099. }
  1100. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiosingleinfo_view where 主键ID in (" + pibid.Substring(0, pibid.Length - 1) + ")", "select");
  1101. SingleReport.RegisterData(dt, "prodiosingleinfo_view");
  1102. SingleReport.GetDataSource("prodiosingleinfo_view").Enabled = true;
  1103. //保存参数打印
  1104. SingleReport.PrintSettings.ShowDialog = false;
  1105. SingleReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  1106. try
  1107. {
  1108. SingleReport.Print();
  1109. }
  1110. catch (Exception e)
  1111. {
  1112. MessageBox.Show(e.Message);
  1113. return;
  1114. }
  1115. Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text;
  1116. Properties.Settings.Default.Save();
  1117. }
  1118. else
  1119. {
  1120. MessageBox.Show("未勾选打印明细", "提示", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  1121. }
  1122. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印盘标", "打印成功");
  1123. dh.BatchInsert("update prodiobarcode set pib_printdate=sysdate where pib_id=:pib_id", new string[] { "pib_id" }, SingleID.ToArray());
  1124. outboxcode1.Clear();
  1125. }
  1126. else
  1127. {
  1128. MessageBox.Show("此模板尚未维护参数或不存在打印明细", "提示");
  1129. return;
  1130. }
  1131. }
  1132. }
  1133. private void SingleLabelPrint_Click(object sender, EventArgs e)
  1134. {
  1135. if (SingleLabelCombox.Text != "")
  1136. {
  1137. if (SingleBoxBegin.Text != "" || SingleBoxEnd.Text != "")
  1138. {
  1139. try
  1140. {
  1141. int begin = int.Parse(SingleBoxBegin.Text == "" ? "1" : SingleBoxBegin.Text);
  1142. int end = int.Parse(SingleBoxEnd.Text == "" ? LabelInf.Rows.Count.ToString() : SingleBoxEnd.Text);
  1143. if (begin > 0 && end <= LabelInf.Rows.Count && begin <= end)
  1144. {
  1145. for (int i = begin - 1; i < end; i++)
  1146. {
  1147. LabelInf.Rows[i].Cells["Choose"].Value = true;
  1148. LabelInf.Rows[i].Cells["pib_ifprint"].Value = false;
  1149. }
  1150. }
  1151. else
  1152. {
  1153. MessageBox.Show("单盘打印范围错误", "提示");
  1154. return;
  1155. }
  1156. }
  1157. catch (Exception)
  1158. {
  1159. MessageBox.Show("单盘打印范围错误", "提示");
  1160. return;
  1161. }
  1162. }
  1163. thread = new Thread(SingleBoxPrint);
  1164. stw = new SetLoadingWindow(thread, "正在打印单盘");
  1165. BaseUtil.SetFormCenter(stw);
  1166. stw.ShowDialog();
  1167. Input.Focus();
  1168. }
  1169. else
  1170. {
  1171. MessageBox.Show("未维护单盘标签", "提示");
  1172. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印盘标", "打印失败,未维护标签");
  1173. }
  1174. }
  1175. private void MidBoxLabelPrint()
  1176. {
  1177. //if (CheckPassWord && PassCheck() != dh.getFieldDataByCondition("configs", "data", "code='PassWord' and caller='BarCodeSetting'").ToString())
  1178. //{
  1179. // MessageBox.Show("密码不正确,不允许操作");
  1180. // return;
  1181. //}
  1182. //未输入内容打印全部中盒
  1183. if (MidLabelNum.Text == "")
  1184. {
  1185. int begin = 0;
  1186. int end = 0;
  1187. if (MidBoxBegin.Text != "" || MidBoxEnd.Text != "")
  1188. {
  1189. try
  1190. {
  1191. begin = int.Parse(MidBoxBegin.Text == "" ? "1" : MidBoxBegin.Text);
  1192. end = int.Parse(MidBoxEnd.Text == "" ? LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString() : MidBoxEnd.Text);
  1193. int minmidbox = int.Parse(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString());
  1194. int maxmidbox = int.Parse(LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString());
  1195. if (begin >= minmidbox && end <= maxmidbox && begin <= end)
  1196. {
  1197. //设置中盒打印范围的行号
  1198. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1199. {
  1200. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == begin)
  1201. {
  1202. begin = i;
  1203. }
  1204. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == end)
  1205. {
  1206. end = i;
  1207. }
  1208. }
  1209. }
  1210. else
  1211. {
  1212. MessageBox.Show("中盒打印范围错误", "提示");
  1213. return;
  1214. }
  1215. }
  1216. catch (Exception)
  1217. {
  1218. MessageBox.Show("中盒打印范围错误", "提示");
  1219. return;
  1220. }
  1221. }
  1222. List<int> MidOutBoxCode = new List<int>();
  1223. List<int> MidOutBoxCodeIndex = new List<int>();
  1224. for (int i = (begin == 0 ? 0 : begin); i <= (end == 0 ? LabelInf.Rows.Count - 1 : end); i++)
  1225. {
  1226. try
  1227. {
  1228. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  1229. {
  1230. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  1231. MidOutBoxCodeIndex.Add(i);
  1232. }
  1233. }
  1234. catch (Exception)
  1235. {
  1236. MessageBox.Show("请先封箱!");
  1237. return;
  1238. }
  1239. }
  1240. try
  1241. {
  1242. //如果有选中行
  1243. if (SelectRowIndex >= 0 && LabelInf.Rows.Count > SelectRowIndex)
  1244. {
  1245. MidOutBoxCode.Clear();
  1246. MidOutBoxCodeIndex.Clear();
  1247. SelectProdcode = LabelInf.Rows[SelectRowIndex].Cells["pib_prodcode"].Value.ToString();
  1248. for (int i = SelectRowIndex; i >= 0; i--)
  1249. {
  1250. if ((LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() == SelectProdcode && LabelInf.Rows[i].Cells["pib_midifprint"].FormattedValue.ToString().ToLower() != "true") || i == SelectRowIndex)
  1251. {
  1252. LabelInf.Rows[i].Cells["pib_midifprint"].Value = true;
  1253. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  1254. {
  1255. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  1256. MidOutBoxCodeIndex.Add(i);
  1257. }
  1258. }
  1259. else
  1260. {
  1261. break;
  1262. }
  1263. }
  1264. for (int i = SelectRowIndex; i < LabelInf.Rows.Count - 1; i++)
  1265. {
  1266. if ((LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() == SelectProdcode && LabelInf.Rows[i].Cells["pib_midifprint"].FormattedValue.ToString().ToLower() != "true") || i == SelectRowIndex)
  1267. {
  1268. LabelInf.Rows[i].Cells["pib_midifprint"].Value = true;
  1269. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  1270. {
  1271. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  1272. MidOutBoxCodeIndex.Add(i);
  1273. }
  1274. }
  1275. else
  1276. {
  1277. break;
  1278. }
  1279. }
  1280. }
  1281. }
  1282. catch (Exception e)
  1283. {
  1284. MessageBox.Show(e.Message);
  1285. LogManager.DoLog(e.Message + e.StackTrace);
  1286. return;
  1287. }
  1288. try
  1289. {
  1290. MidBoxCodePrint(MidOutBoxCodeIndex.ToArray());
  1291. }
  1292. catch (Exception e)
  1293. {
  1294. MessageBox.Show(e.Message);
  1295. LogManager.DoLog(e.Message + e.StackTrace);
  1296. return;
  1297. }
  1298. return;
  1299. }
  1300. bool FindMidLabel = false;
  1301. if (MidLabelCombox.SelectedValue != null)
  1302. {
  1303. //中盒号所在的行
  1304. int MidLabelRowIndex = 0;
  1305. //缓存中盒数据
  1306. for (int i = 0; i < LabelInf.RowCount; i++)
  1307. {
  1308. if (MidLabelNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1309. {
  1310. //找到了输入的中盒号停止循环
  1311. FindMidLabel = true;
  1312. MidLabelRowIndex = i;
  1313. }
  1314. }
  1315. int[] rowindx = new int[] { MidLabelRowIndex };
  1316. //找到了指定的盒号
  1317. if (FindMidLabel)
  1318. MidBoxCodePrint(rowindx);
  1319. else
  1320. MessageBox.Show("该出入库单未找到该中盒号!", "提示");
  1321. }
  1322. else
  1323. MessageBox.Show("未维护中盒模板", "提示");
  1324. }
  1325. private void MidLabelPrint_Click(object sender, EventArgs e)
  1326. {
  1327. if (MidLabelCombox.Text != "")
  1328. {
  1329. PackMidBox_Click(sender, e);
  1330. thread = new Thread(MidBoxLabelPrint);
  1331. stw = new SetLoadingWindow(thread, "正在打印中盒");
  1332. BaseUtil.SetFormCenter(stw);
  1333. stw.ShowDialog();
  1334. }
  1335. else
  1336. MessageBox.Show("未维护中盒标签", "提示");
  1337. Input.Focus();
  1338. }
  1339. private void OutBoxPrint()
  1340. {
  1341. List<string> Outboxcode = new List<string>();
  1342. //如果未勾选箱号则对勾选的数据的箱号进行整合
  1343. if (OutBoxNum.Text == "" || OutBoxNum.Text == "全部")
  1344. {
  1345. for (int i = 0; i < LabelInf.RowCount; i++)
  1346. {
  1347. string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  1348. //富为使用包装单的逻辑
  1349. //如果不包含该箱号则进行添加
  1350. if (!Outboxcode.Contains(outboxcode2))
  1351. Outboxcode.Add(outboxcode2);
  1352. }
  1353. //按获取到的箱号列表进行打印
  1354. if (Outboxcode.ToArray().Length > 0)
  1355. {
  1356. for (int i = 0; i < Outboxcode.ToArray().Length; i++)
  1357. {
  1358. for (int h = 0; h < LabelInf.RowCount; h++)
  1359. {
  1360. if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i])
  1361. {
  1362. if (!AllLabel.Checked)
  1363. OutBoxCodePrint(h);
  1364. else
  1365. OutBoxCodePrint(h, true);
  1366. break;
  1367. }
  1368. }
  1369. }
  1370. }
  1371. else
  1372. {
  1373. MessageBox.Show("请勾选需要打印的外箱", "提示");
  1374. }
  1375. }
  1376. else
  1377. {
  1378. bool FindMidLabel = false;
  1379. try
  1380. {
  1381. int OutBoxLabelRowIndex = 0;
  1382. //查找是否存在该中盒号
  1383. for (int i = 0; i < LabelInf.RowCount; i++)
  1384. {
  1385. if (OutBoxNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString())
  1386. {
  1387. //找到了输入的中盒号停止循环
  1388. FindMidLabel = true;
  1389. OutBoxLabelRowIndex = i;
  1390. break;
  1391. }
  1392. }
  1393. //找到了指定的盒号
  1394. if (FindMidLabel)
  1395. {
  1396. if (!AllLabel.Checked)
  1397. OutBoxCodePrint(OutBoxLabelRowIndex);
  1398. else
  1399. OutBoxCodePrint(OutBoxLabelRowIndex, true);
  1400. }
  1401. else
  1402. MessageBox.Show("该出入库单未找到该外箱号!", "提示");
  1403. }
  1404. catch (Exception) { }
  1405. }
  1406. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印箱标" + OutBoxNum.Text, "打印成功");
  1407. Outboxcode.Clear();
  1408. }
  1409. private void MidBoxCodePrint(int[] rowindex)
  1410. {
  1411. if (EnablePrint)
  1412. {
  1413. string pib_outboxcode1 = "";
  1414. for (int i = 0; i < rowindex.Length; i++)
  1415. {
  1416. if (i != rowindex.Length - 1)
  1417. pib_outboxcode1 += "'" + LabelInf.Rows[rowindex[i]].Cells["pib_outboxcode1"].Value.ToString() + "'" + ",";
  1418. else
  1419. pib_outboxcode1 += "'" + LabelInf.Rows[rowindex[i]].Cells["pib_outboxcode1"].Value.ToString() + "'";
  1420. }
  1421. //名称相等的时候,取SQL进行值的查询
  1422. DataTable dt;
  1423. sql.Clear();
  1424. sql.Append("update prodiobarcode set pib_midboxweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' ");
  1425. sql.Append(" and pib_outboxcode1 in(" + pib_outboxcode1 + ")");
  1426. dh.ExecuteSql(sql.ToString(), "update");
  1427. if (MidLabelAutoPrint.Checked)
  1428. {
  1429. if (CurrentRowOnly.Checked)
  1430. {
  1431. string PDNO = "";
  1432. if (SelectRowIndex >= 0)
  1433. {
  1434. PDNO = LabelInf.Rows[SelectRowIndex].Cells["pib_pdno"].Value.ToString();
  1435. }
  1436. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ") and 出货序号='" + (PDNO == "" ? CurrentPDNO : PDNO) + "'", "select");
  1437. }
  1438. else
  1439. {
  1440. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ")", "select");
  1441. }
  1442. }
  1443. else
  1444. {
  1445. if (CurrentRowOnly.Checked)
  1446. {
  1447. string PDNO = "";
  1448. if (SelectRowIndex >= 0)
  1449. {
  1450. PDNO = LabelInf.Rows[SelectRowIndex].Cells["pib_pdno"].Value.ToString();
  1451. }
  1452. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ") and 中盒标识='外' and 出货序号='" + (PDNO == "" ? CurrentPDNO : PDNO) + "'", "select");
  1453. }
  1454. else
  1455. {
  1456. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ") and 中盒标识='外'", "select");
  1457. }
  1458. }
  1459. if (dt.Rows.Count > 0)
  1460. {
  1461. if (!MidLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1462. MidReport.Load(MidLabelCombox.SelectedValue.ToString());
  1463. for (int j = 0; j < MidReport.Parameters.Count; j++)
  1464. {
  1465. MidReport.SetParameterValue(MidReport.Parameters[j].Name, "");
  1466. for (int i = 0; i < Attach.Rows.Count; i++)
  1467. {
  1468. if (Attach.Rows[i][0].ToString() == MidReport.Parameters[j].Name)
  1469. {
  1470. MidReport.SetParameterValue(MidReport.Parameters[j].Name, Attach.Rows[i][1].ToString());
  1471. }
  1472. }
  1473. }
  1474. MidReport.RegisterData(dt, "prodiomidinfo_view");
  1475. MidReport.GetDataSource("prodiomidinfo_view").Enabled = true;
  1476. MidReport.PrintSettings.ShowDialog = false;
  1477. MidReport.PrintSettings.Printer = MidLabelPrinter.Text;
  1478. MidReport.Print();
  1479. dh.UpdateByCondition("prodiobarcode", "pib_midifprint=-1", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1 in (" + pib_outboxcode1 + ")");
  1480. SelectRowIndex = -1;
  1481. LoadGridData(new object(), new EventArgs());
  1482. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "打印中盒" + pib_outboxcode1.Replace("'", ""), "打印成功");
  1483. }
  1484. Properties.Settings.Default.MPrinter = MidLabelPrinter.Text;
  1485. Properties.Settings.Default.Save();
  1486. }
  1487. }
  1488. /// <summary>
  1489. /// 执行打印外箱号
  1490. /// </summary>
  1491. private void OutBoxCodePrint(int rowindex)
  1492. {
  1493. if (EnablePrint)
  1494. {
  1495. if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1496. OutReport.Load(OutBoxCombox.SelectedValue.ToString());
  1497. for (int j = 0; j < OutReport.Parameters.Count; j++)
  1498. {
  1499. OutReport.SetParameterValue(OutReport.Parameters[j].Name, "");
  1500. for (int i = 0; i < Attach.Rows.Count; i++)
  1501. {
  1502. if (Attach.Rows[i][0].ToString() == OutReport.Parameters[j].Name)
  1503. {
  1504. OutReport.SetParameterValue(OutReport.Parameters[j].Name, Attach.Rows[i][1].ToString());
  1505. }
  1506. }
  1507. }
  1508. string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
  1509. string SQL = "";
  1510. if (OnlyOneRow.Checked)
  1511. {
  1512. SQL = "select * from prodiooutinfo_view where 出货单号 = '" + pi_inoutno.Text + "' and 外箱号 = '" + pib_outboxcode2 + "' and rownum=1";
  1513. }
  1514. else
  1515. {
  1516. SQL = "select * from prodiooutinfo_view where 出货单号 = '" + pi_inoutno.Text + "' and 外箱号 = '" + pib_outboxcode2 + "'";
  1517. }
  1518. DataTable dt = (DataTable)dh.ExecuteSql(SQL, "select");
  1519. OutReport.RegisterData(dt, "prodiooutinfo_view");
  1520. OutReport.GetDataSource("prodiooutinfo_view").Enabled = true;
  1521. OutReport.PrintSettings.ShowDialog = false;
  1522. OutReport.PrintSettings.Printer = OutBoxPrinter.Text;
  1523. OutReport.Print();
  1524. Properties.Settings.Default.OPrinter = OutBoxPrinter.Text;
  1525. Properties.Settings.Default.Save();
  1526. dh.UpdateByCondition("prodiobarcode", "pib_outifprint=-1", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + pib_outboxcode2 + "'");
  1527. }
  1528. }
  1529. /// <summary>
  1530. /// 执行打印外箱号
  1531. /// </summary>
  1532. private void OutBoxCodePrint(int rowindex, bool AllLabel)
  1533. {
  1534. if (EnablePrint)
  1535. {
  1536. int selectedindex = OutBoxCombox.SelectedIndex;
  1537. for (int i = 0; i < OutBoxCombox.Items.Count; i++)
  1538. {
  1539. OutBoxCombox.SelectedIndex = i;
  1540. if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1541. OutReport.Load(OutBoxCombox.SelectedValue.ToString());
  1542. for (int j = 0; j < OutReport.Parameters.Count; j++)
  1543. {
  1544. OutReport.SetParameterValue(OutReport.Parameters[j].Name, "");
  1545. for (int k = 0; k < Attach.Rows.Count; k++)
  1546. {
  1547. if (Attach.Rows[k][0].ToString() == OutReport.Parameters[j].Name)
  1548. {
  1549. OutReport.SetParameterValue(OutReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
  1550. }
  1551. }
  1552. }
  1553. string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
  1554. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiooutinfo_view where 出货单号='" + pi_inoutno.Text + "' and 外箱号='" + pib_outboxcode2 + "'", "select");
  1555. OutReport.RegisterData(dt, "prodiooutinfo_view");
  1556. OutReport.GetDataSource("prodiooutinfo_view").Enabled = true;
  1557. OutReport.PrintSettings.ShowDialog = false;
  1558. OutReport.PrintSettings.Printer = OutBoxPrinter.Text;
  1559. OutReport.Print();
  1560. }
  1561. OutBoxCombox.SelectedIndex = selectedindex;
  1562. Properties.Settings.Default.OPrinter = OutBoxPrinter.Text;
  1563. Properties.Settings.Default.Save();
  1564. dh.UpdateByCondition("prodiobarcode", "pib_outifprint=-1", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + pib_outboxcode2 + "'");
  1565. }
  1566. }
  1567. private string PassCheck()
  1568. {
  1569. PassWordConfirm form = new PassWordConfirm();
  1570. form.StartPosition = FormStartPosition.CenterScreen;
  1571. form.ShowDialog();
  1572. return form.Controls["PassWord"].Text;
  1573. }
  1574. private void CleanDetail_Click(object sender, EventArgs e)
  1575. {
  1576. if (PassCheck() != dh.getFieldDataByCondition("configs", "data", "code='PassWord' and caller='BarCodeSetting'").ToString())
  1577. {
  1578. MessageBox.Show("密码不正确,不允许操作");
  1579. return;
  1580. }
  1581. if (dh.getFieldDataByCondition("prodinout", "pi_statuscode", "pi_inoutno='" + pi_inoutno.Text + "'").ToString() == "POSTED")
  1582. {
  1583. MessageBox.Show("单据" + pi_inoutno.Text + "已过账,不允许删除条码");
  1584. return;
  1585. }
  1586. ArrayList<string> DeleteID = new ArrayList<string>();
  1587. for (int i = 0; i < LabelInf.RowCount; i++)
  1588. {
  1589. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true")
  1590. DeleteID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1591. }
  1592. //勾选了删除的明细之后
  1593. if (DeleteID.ToArray().Length > 0)
  1594. {
  1595. string close = MessageBox.Show(this.ParentForm, "删除后不可恢复,是否确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1596. if (close.ToString() == "Yes")
  1597. {
  1598. dh.BatchInsert("insert into prodiobarcode_delete select * from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray());
  1599. dh.BatchInsert("delete from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray());
  1600. 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 + "'");
  1601. //dh.UpdateByCondition("CS$InoutPrcode", "checknum=CollectedNum/pjd_zxbzs_user", "pd_inoutno='" + pi_inoutno.Text + "'");
  1602. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "删除明细", "删除明细成功");
  1603. MessageBox.Show("删除成功", "提示");
  1604. if (!forinput.Checked)
  1605. {
  1606. Input.Clear();
  1607. }
  1608. else
  1609. {
  1610. RemainTxt();
  1611. }
  1612. LoadPrcodeData();
  1613. LoadGridData(sender, e);
  1614. if (int.Parse(dh.getFieldDataByCondition("prodiobarcode", "count(1)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString()) == 0)
  1615. {
  1616. dh.UpdateByCondition("prodinout", "pi_user_packingstatus=''", "pi_inoutno='" + pi_inoutno.Text + "'");
  1617. }
  1618. else
  1619. {
  1620. dh.UpdateByCondition("prodinout", "pi_user_packingstatus='Packing'", "pi_inoutno='" + pi_inoutno.Text + "'");
  1621. }
  1622. }
  1623. }
  1624. else
  1625. MessageBox.Show("尚未勾选需要删除的明细", "提示");
  1626. }
  1627. private void OutBoxLabelPrint_Click(object sender, EventArgs e)
  1628. {
  1629. //if (CheckPassWord && PassCheck() != dh.getFieldDataByCondition("configs", "data", "code='PassWord' and caller='BarCodeSetting'").ToString())
  1630. //{
  1631. // MessageBox.Show("密码不正确,不允许操作");
  1632. // return;
  1633. //}
  1634. if (OutBoxCombox.Text != "")
  1635. {
  1636. Pack_Click(sender, e);
  1637. if (Weight.Text != "" && Weight.Text != "0.000")
  1638. {
  1639. //记录整箱的重量
  1640. sql.Clear();
  1641. sql.Append("update prodiobarcode set pib_totalweight='" + Weight.Text + "',pib_size='" + pib_size.SelectedValue + "' where pib_inoutno='" + pi_inoutno.Text + "' ");
  1642. sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "'");
  1643. dh.ExecuteSql(sql.ToString(), "update");
  1644. }
  1645. LoadGridData(sender, e);
  1646. thread = new Thread(OutBoxPrint);
  1647. stw = new SetLoadingWindow(thread, "正在打印外箱");
  1648. BaseUtil.SetFormCenter(stw);
  1649. stw.ShowDialog();
  1650. Input.Focus();
  1651. if (AutoAfterPrint.Checked)
  1652. OutBoxNum.Text = "新增";
  1653. }
  1654. else
  1655. MessageBox.Show("未维护外箱标签", "提示");
  1656. Input.Focus();
  1657. }
  1658. /// <summary>
  1659. /// 自定义函数 加载明细行的数据,多处使用添加进函数
  1660. /// </summary>
  1661. /// <param name="sender"></param>
  1662. /// <param name="e"></param>
  1663. private void LoadGridData(object sender, EventArgs e)
  1664. {
  1665. AllChecked = false;
  1666. string SQL = "";
  1667. if (OutBoxNum.Text != "全部")
  1668. {
  1669. //LogicHandler.GetDataSQL(PI_ID, "and pib_outboxcode2='" + OutBoxNum.Text + "'", out SQL);
  1670. SQL = "select to_char(pib_indate,'yyyy-mm-dd hh24:mi:ss')pib_indate,pib_boxweight,pib_midboxweight,pib_totalweight,pd_custprodcode,pd_custprodspec,nvl(pib_midifprint,0)pib_midifprint,pib_custmidboxcode,pd_pocode,pjd_orispeccode," +
  1671. "pib_madein,pib_custbarcode,pib_custoutboxcode,pib_id,pib_datecode1,pib_pdid,pib_piid,pib_pdno,pib_prodcode,pib_brand,pr_vendprodcode,pib_lotno,pib_datecode," +
  1672. "week_to_date(pib_datecode) datecode1,pib_qty,pr_spec,pr_zxbzs,pr_unit,pib_barcode,pib_outboxcode1,pib_outboxcode2,nvl(pib_ifprint, 0)pib_ifprint,pd_remark,pd_remark2 from prodiobarcode left join " +
  1673. "prodiodetail on pib_piid = pd_piid and pd_pdno = pib_pdno and pd_prodcode = pib_prodcode left join product on pr_code = pib_prodcode left join sale on sa_code = pib_ordercode left join " +
  1674. "PRODJOINVENDDETAIL on pjd_brand = pd_brand and pjd_prodcode = pd_prodcode where pib_piid = '" + PI_ID + "' and pib_outboxcode2='" + OutBoxNum.Text + "' order by to_number(pib_outboxcode2),pib_id,pd_prodcode";
  1675. }
  1676. else
  1677. {
  1678. SQL = "select to_char(pib_indate,'yyyy-mm-dd hh24:mi:ss')pib_indate,pib_boxweight,pib_midboxweight,pib_totalweight,pd_custprodcode,pd_custprodspec,nvl(pib_midifprint,0)pib_midifprint,pib_custmidboxcode,pd_pocode,pjd_orispeccode," +
  1679. "pib_madein,pib_custbarcode,pib_custoutboxcode,pib_id,pib_datecode1,pib_pdid,pib_piid,pib_pdno,pib_prodcode,pib_brand,pr_vendprodcode,pib_lotno,pib_datecode," +
  1680. "week_to_date(pib_datecode) datecode1,pib_qty,pr_spec,pr_zxbzs,pr_unit,pib_barcode,pib_outboxcode1,pib_outboxcode2,nvl(pib_ifprint, 0)pib_ifprint,pd_remark,pd_remark2 from prodiobarcode left join " +
  1681. "prodiodetail on pib_piid = pd_piid and pd_pdno = pib_pdno and pd_prodcode = pib_prodcode left join product on pr_code = pib_prodcode left join sale on sa_code = pib_ordercode left join " +
  1682. "PRODJOINVENDDETAIL on pjd_brand = pd_brand and pjd_prodcode = pd_prodcode where pib_piid = '" + PI_ID + "' order by to_number(pib_outboxcode2),pib_id,pd_prodcode";
  1683. }
  1684. LabelInfDataTable = (DataTable)dh.ExecuteSql(SQL, "select");
  1685. BoxCount.Text = LabelInfDataTable.Compute("sum(pib_qty)", "1=1").ToString() + "KPCS";
  1686. bindingsource(LabelInf, LabelInfDataTable);
  1687. if (LabelInf.Rows.Count > 0)
  1688. {
  1689. LabelInf.FirstDisplayedScrollingRowIndex = LabelInf.Rows.Count - 1;
  1690. }
  1691. sql.Clear();
  1692. sql.Append("select pib_pdno,pib_prodcode,sum(pib_qty) pib_qty from prodiobarcode left join prodiodetail on pd_id=pib_pdid and pd_pdno=pib_pdno ");
  1693. sql.Append("where pd_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno ");
  1694. SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1695. }
  1696. private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1697. {
  1698. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  1699. pi_inoutno_KeyDown(sender, e2);
  1700. }
  1701. private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1702. {
  1703. string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1704. if (close.ToString() == "Yes")
  1705. {
  1706. Login login = new Login();
  1707. //注销的时候需要将拼接的连接字符串置空
  1708. DataHelper.DBConnectionString = null;
  1709. logout = true;
  1710. this.Hide();
  1711. login.ShowDialog();
  1712. this.Close();
  1713. }
  1714. }
  1715. private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1716. /// <summary>
  1717. /// 切换打开的单盘文件
  1718. /// </summary>
  1719. /// <param name="sender"></param>
  1720. /// <param name="e"></param>
  1721. private void SingleLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1722. {
  1723. try
  1724. {
  1725. if (ComBoxClickChangeLabelDoc)
  1726. {
  1727. if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1728. SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
  1729. }
  1730. }
  1731. catch (Exception) { }
  1732. }
  1733. /// <summary>
  1734. /// 切换打开的中盒文件
  1735. /// </summary>
  1736. /// <param name="sender"></param>
  1737. /// <param name="e"></param>
  1738. private void MidLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1739. {
  1740. try
  1741. {
  1742. if (ComBoxClickChangeLabelDoc)
  1743. {
  1744. if (!MidLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1745. MidReport.Load(MidLabelCombox.SelectedValue.ToString());
  1746. }
  1747. }
  1748. catch (Exception) { }
  1749. }
  1750. /// <summary>
  1751. /// 切换打开的外箱文件
  1752. /// </summary>
  1753. /// <param name="sender"></param>
  1754. /// <param name="e"></param>
  1755. private void OutBoxCombox_SelectedIndexChanged(object sender, EventArgs e)
  1756. {
  1757. try
  1758. {
  1759. if (ComBoxClickChangeLabelDoc)
  1760. {
  1761. if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1762. OutReport.Load(OutBoxCombox.SelectedValue.ToString());
  1763. }
  1764. }
  1765. catch (Exception) { }
  1766. }
  1767. private void ChooseAll_Click(object sender, EventArgs e)
  1768. {
  1769. if (AllChecked)
  1770. {
  1771. foreach (DataGridViewRow dr in LabelInf.Rows)
  1772. dr.Cells[0].Value = false;
  1773. AllChecked = false;
  1774. }
  1775. else
  1776. {
  1777. foreach (DataGridViewRow dr in LabelInf.Rows)
  1778. dr.Cells[0].Value = true;
  1779. AllChecked = true;
  1780. }
  1781. }
  1782. private void ExportData_Click(object sender, EventArgs e)
  1783. {
  1784. ShowMenu.Items.Clear();
  1785. DataTable dt = (DataTable)dh.ExecuteSql("select * from CS_EXPORTSETTING where es_custcode='" + pi_cardcode.Text + "'", "select");
  1786. if (dt.Rows.Count == 0)
  1787. dt = (DataTable)dh.ExecuteSql("select * from CS_EXPORTSETTING where es_custcode is null", "select");
  1788. for (int i = 0; i < dt.Rows.Count; i++)
  1789. {
  1790. ShowMenu.Items.Add(new ToolStripMenuItem(dt.Rows[i]["el_remark"].ToString() + "#" + dt.Rows[i]["el_type"].ToString()));
  1791. }
  1792. ShowMenu.Show(new Point(ExportData.Location.X, ExportData.Location.Y + 20));
  1793. }
  1794. private void ShowMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  1795. {
  1796. //获取类型,单盘或者外箱
  1797. string type = e.ClickedItem.Text.Split('#')[1];
  1798. ExportFileDialog.Description = "选择导出的路径";
  1799. DialogResult result = ExportFileDialog.ShowDialog();
  1800. if (result == DialogResult.OK)
  1801. {
  1802. ExcelHandler eh = new ExcelHandler();
  1803. 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");
  1804. if (Field.Rows.Count == 0)
  1805. {
  1806. 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");
  1807. }
  1808. string Fileds = "";
  1809. for (int i = 0; i < Field.Rows.Count; i++)
  1810. {
  1811. Fileds += Field.Rows[i]["esd_filed"].ToString() + ",";
  1812. }
  1813. sql.Clear();
  1814. sql.Append("select " + Fileds.Substring(0, Fileds.Length - 1) + " from ExportView where pib_inoutno='" + pi_inoutno.Text + "'");
  1815. string finnalSQL = "";
  1816. LogicHandler.GetExportDataSQL(pi_inoutno.Text, pi_cardcode.Text, type, sql.ToString(), out finnalSQL);
  1817. dt = (DataTable)dh.ExecuteSql(finnalSQL, "select");
  1818. eh.ExportExcel(dt, Field, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text + type);
  1819. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1820. if (close.ToString() == "Yes")
  1821. Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + type + ".xls");
  1822. }
  1823. }
  1824. private void AttachInfo_Click(object sender, EventArgs e)
  1825. {
  1826. if (pi_cardcode.Text != "")
  1827. {
  1828. 附件内容打印 att = new 附件内容打印(pi_cardcode.Text);
  1829. att.ShowDialog();
  1830. }
  1831. else MessageBox.Show("请先获取出库单信息", "提示");
  1832. }
  1833. private void MidBoxCapacity_Leave(object sender, EventArgs e)
  1834. {
  1835. NumericUpDown nup = (NumericUpDown)sender;
  1836. switch (nup.Name)
  1837. {
  1838. case "MidBoxCapacity":
  1839. Properties.Settings.Default.MidBoxCapacity = nup.Value;
  1840. Properties.Settings.Default.Save();
  1841. break;
  1842. case "OutboxCapacity":
  1843. Properties.Settings.Default.OutboxCapacity = nup.Value;
  1844. Properties.Settings.Default.Save();
  1845. break;
  1846. default:
  1847. break;
  1848. }
  1849. }
  1850. private void RefreshDBConnect_Tick(object sender, EventArgs e)
  1851. {
  1852. dh.ExecuteSql("select sysdate from dual", "select");
  1853. }
  1854. DataTable CSPrcode;
  1855. private void LoadPrcodeData()
  1856. {
  1857. DataTable Prcode = (DataTable)dh.ExecuteSql("select '' pd_piid,pd_inoutno,pd_remark,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");
  1858. GridPrcode.DataSource = Prcode;
  1859. List<int> RemoveIndex = new List<int>();
  1860. double CollectNum = 0;
  1861. double OutNum = 0;
  1862. int combined = 0;
  1863. if (Combindetail.Checked)
  1864. combined = 1;
  1865. if (CombindetailTwo.Checked)
  1866. combined = 2;
  1867. if (CombindetailThree.Checked)
  1868. combined = 3;
  1869. if (Combindetail.Checked || CombindetailTwo.Checked || CombindetailThree.Checked)
  1870. {
  1871. 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,pd_remark from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "' and combined=" + combined + " order by pd_pdno", "select");
  1872. if (CSPrcode.Rows.Count == 0)
  1873. {
  1874. int CurrentIndex = 0;
  1875. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1876. {
  1877. string CurrentPrCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1878. string CurrentPDNO = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  1879. string CurrentOutQTY = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  1880. if (SumQty == null)
  1881. {
  1882. sql.Clear();
  1883. sql.Append("select pib_pdno,pib_prodcode,sum(pib_qty) pib_qty from prodiobarcode left join prodiodetail on pd_id=pib_pdid and pd_pdno=pib_pdno ");
  1884. sql.Append("where pd_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno ");
  1885. SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1886. }
  1887. string collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  1888. CollectNum += double.Parse(collectqty == "" ? "0" : collectqty);
  1889. OutNum += double.Parse(CurrentOutQTY);
  1890. GridPrcode.Rows[i].Cells["CollectedNum"].Value = collectqty == "" ? "0" : collectqty;
  1891. }
  1892. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1893. {
  1894. if (i + 1 < GridPrcode.Rows.Count)
  1895. {
  1896. string BProdCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1897. string BCustProdCode = GridPrcode.Rows[i].Cells["pd_custprodcode1"].Value.ToString();
  1898. string BWhCode = GridPrcode.Rows[i].Cells["pd_whcode"].Value.ToString();
  1899. string BPrUnit = GridPrcode.Rows[i].Cells["pr_unit"].Value.ToString();
  1900. string BPrBrand = GridPrcode.Rows[i].Cells["pd_brand"].Value.ToString();
  1901. string BPoCode = GridPrcode.Rows[i].Cells["pd_pocode1"].Value.ToString();
  1902. string BRemark = GridPrcode.Rows[i].Cells["pd_remark1"].Value.ToString();
  1903. string FProdCode = GridPrcode.Rows[i + 1].Cells["pd_prodcode"].Value.ToString();
  1904. string FCustProdCode = GridPrcode.Rows[i + 1].Cells["pd_custprodcode1"].Value.ToString();
  1905. string FPrUnit = GridPrcode.Rows[i + 1].Cells["pr_unit"].Value.ToString();
  1906. string FrBrand = GridPrcode.Rows[i + 1].Cells["pd_brand"].Value.ToString();
  1907. string FWhCode = GridPrcode.Rows[i + 1].Cells["pd_whcode"].Value.ToString();
  1908. string FPoCode = GridPrcode.Rows[i + 1].Cells["pd_pocode1"].Value.ToString();
  1909. string FRemark = GridPrcode.Rows[i + 1].Cells["pd_remark1"].Value.ToString();
  1910. if (BProdCode == FProdCode && BPrBrand == FrBrand && BCustProdCode == FCustProdCode && (CombindetailTwo.Checked && FPoCode == BPoCode || Combindetail.Checked || CombindetailThree.Checked && FRemark == BRemark && FPoCode == BPoCode))
  1911. {
  1912. 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());
  1913. 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());
  1914. RemoveIndex.Add(i + 1);
  1915. }
  1916. else
  1917. {
  1918. CurrentIndex = i + 1;
  1919. }
  1920. }
  1921. }
  1922. foreach (int item in RemoveIndex.OrderByDescending(x => x))
  1923. {
  1924. (GridPrcode.DataSource as DataTable).Rows.RemoveAt(item);
  1925. }
  1926. }
  1927. else GridPrcode.DataSource = CSPrcode;
  1928. }
  1929. else
  1930. {
  1931. 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,pd_remark from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "' and combined=" + combined + " order by pd_pdno", "select");
  1932. if (CSPrcode.Rows.Count == 0)
  1933. {
  1934. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1935. {
  1936. string CurrentPrCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1937. string CurrentPDNO = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  1938. string CurrentOutQTY = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  1939. if (SumQty == null)
  1940. {
  1941. sql.Clear();
  1942. sql.Append("select pib_pdno,pib_prodcode,sum(pib_qty) pib_qty from prodiobarcode left join prodiodetail on pd_id=pib_pdid and pd_pdno=pib_pdno ");
  1943. sql.Append("where pd_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno ");
  1944. SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1945. }
  1946. string collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  1947. CollectNum += double.Parse(collectqty == "" ? "0" : collectqty);
  1948. OutNum += double.Parse(CurrentOutQTY);
  1949. GridPrcode.Rows[i].Cells["CollectedNum"].Value = collectqty == "" ? "0" : collectqty;
  1950. }
  1951. }
  1952. else GridPrcode.DataSource = CSPrcode;
  1953. }
  1954. dh.UpdateByCondition("prodinout", "pi_combine_user=" + combined, "pi_inoutno='" + pi_inoutno.Text + "'");
  1955. if (CSPrcode.Rows.Count == 0)
  1956. {
  1957. sql.Clear();
  1958. sql.Append("insert into CS$InoutPrcode (pd_piid,pd_pdno,pd_custprodcode,pd_whcode,pd_prodcode,");
  1959. sql.Append("CollectedNum,UnCollectedNum,pd_outqty,pr_unit,pr_spec,pd_brand,pjd_zxbzs_user,pjd_id,pd_inoutno,combined,pd_pocode,pd_remark)");
  1960. 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,:pd_remark)");
  1961. dh.SaveDataTable((GridPrcode.DataSource as DataTable), "CS$InoutPrcode", "pd_piid", sql.ToString());
  1962. }
  1963. else
  1964. {
  1965. CollectNum = float.Parse(CSPrcode.Compute("sum(CollectedNum)", "1=1").ToString());
  1966. OutNum = float.Parse(CSPrcode.Compute("sum(pd_outqty)", "1=1").ToString());
  1967. }
  1968. ProcessCount.Text = CollectNum + "/" + OutNum;
  1969. if (GridPrcode.Rows.Count > 0)
  1970. {
  1971. CurrentPrCode = GridPrcode.Rows[0].Cells["pd_prodcode"].Value.ToString();
  1972. CurrentZXBZ = GridPrcode.Rows[0].Cells["pjd_zxbzs_user"].Value.ToString();
  1973. CurrentUnit = GridPrcode.Rows[0].Cells["pr_unit"].Value.ToString();
  1974. CurrentPDNO = GridPrcode.Rows[0].Cells["pd_pdno"].Value.ToString();
  1975. CurrentPrCount = GridPrcode.Rows[0].Cells["pd_outqty"].Value.ToString();
  1976. CurrentBrand = GridPrcode.Rows[0].Cells["pd_brand"].Value.ToString();
  1977. GridPrcode.Rows[0].Selected = true;
  1978. }
  1979. }
  1980. private void OutBoxNum_Click(object sender, EventArgs e)
  1981. {
  1982. string OutBox = OutBoxNum.Text;
  1983. OutBoxNum.Items.Clear();
  1984. 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");
  1985. ItemObject io = new ItemObject("新增", "新增");
  1986. OutBoxNum.Items.Add(io);
  1987. io = new ItemObject("全部", "全部");
  1988. OutBoxNum.Items.Add(io);
  1989. for (int i = 0; i < dt.Rows.Count; i++)
  1990. {
  1991. string pib_outboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  1992. io = new ItemObject(pib_outboxcode2, pib_outboxcode2);
  1993. OutBoxNum.Items.Add(io);
  1994. }
  1995. if (OutBoxNum.Text == "新增" || OutBoxNum.Text == "")
  1996. {
  1997. if (dt.Rows.Count > 0)
  1998. OutBoxNum.SelectedIndex = 2;
  1999. else
  2000. OutBoxNum.SelectedIndex = 0;
  2001. }
  2002. if (OutBox != "新增" && OutBox != "")
  2003. OutBoxNum.Text = OutBox;
  2004. }
  2005. string ShareRule;
  2006. string ReSetType = "";
  2007. /// <summary>
  2008. /// 获取条码规则
  2009. /// </summary>
  2010. /// <param name="Type"></param>
  2011. /// <param name="Prefix"></param>
  2012. /// <param name="Suffix"></param>
  2013. /// <param name="MaxNum"></param>
  2014. /// <param name="SerialNumLength"></param>
  2015. /// <param name="Radix"></param>
  2016. private void GetBarCodeRule(out string Prefix, out string Suffix, out int MaxNum, out int SerialNumLength, out int Radix, int Count)
  2017. {
  2018. //获取编码规则
  2019. Prefix = "";
  2020. Suffix = "";
  2021. NrCode = "";
  2022. MaxNum = 0;
  2023. SerialNumLength = 0;
  2024. Radix = 0;
  2025. 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");
  2026. //如果没有则取公共规则
  2027. if (Nr.Rows.Count == 0)
  2028. 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");
  2029. //用于过滤参数的正则表达式
  2030. ReSetType = "";
  2031. if (Nr.Rows.Count > 0)
  2032. {
  2033. ShareRule = Nr.Rows[0]["nr_sharerule"].ToString();
  2034. 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");
  2035. if (dt1.Rows.Count > 0)
  2036. {
  2037. Nr = dt1;
  2038. }
  2039. else
  2040. {
  2041. if (ShareRule != "")
  2042. {
  2043. MessageBox.Show("共享规则" + ShareRule + "不存在");
  2044. return;
  2045. }
  2046. }
  2047. }
  2048. if (Nr.Rows.Count > 0)
  2049. {
  2050. switch (Nr.Rows[0]["nr_resettype"].ToString())
  2051. {
  2052. case "Year":
  2053. sql.Clear();
  2054. sql.Append("to_char(sysdate,'yyyy')");
  2055. break;
  2056. case "Month":
  2057. sql.Clear();
  2058. sql.Append("to_char(sysdate,'yyyyMM')");
  2059. break;
  2060. case "Week":
  2061. sql.Clear();
  2062. sql.Append("to_char(sysdate,'yyyyiw')");
  2063. break;
  2064. case "Day":
  2065. sql.Clear();
  2066. sql.Append("to_char(sysdate,'yyyyMMdd')");
  2067. break;
  2068. case " ":
  2069. sql.Clear();
  2070. sql.Append("' '");
  2071. break;
  2072. default:
  2073. break;
  2074. }
  2075. ReSetType = dh.getFieldDataByCondition("dual", sql.ToString(), "1=1").ToString();
  2076. }
  2077. Regex match = new Regex("{\\w+}");
  2078. //用于存放每一项的明细的数据
  2079. string[] NrData = new string[Nr.Rows.Count];
  2080. //流水长度
  2081. Dictionary<int, string> NrDic = new Dictionary<int, string>();
  2082. for (int m = 0; m < Nr.Rows.Count; m++)
  2083. {
  2084. NrCode = Nr.Rows[m]["nr_code"].ToString();
  2085. switch (Nr.Rows[m]["nrd_type"].ToString())
  2086. {
  2087. //常量直接进行拼接
  2088. case "常量":
  2089. Prefix += Nr.Rows[m]["nrd_sql"].ToString();
  2090. Suffix += Nr.Rows[m]["nrd_sql"].ToString();
  2091. break;
  2092. case "SQL":
  2093. string SQL = Nr.Rows[m]["nrd_sql"].ToString();
  2094. DataTable Temp;
  2095. //如果不包含参数替换
  2096. if (SQL.IndexOf("{") == 0)
  2097. {
  2098. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  2099. }
  2100. else
  2101. {
  2102. SQL = SQL.Replace("{pd_pdno}", CurrentPDNO);
  2103. //替换参数后重新执行SQL
  2104. foreach (Match mch in match.Matches(SQL))
  2105. {
  2106. SQL = SQL.Replace(mch.Value.Trim(), "'" + pi_inoutno.Text + "'");
  2107. }
  2108. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  2109. }
  2110. if (Temp.Rows.Count > 0)
  2111. {
  2112. Prefix += Temp.Rows[0][0].ToString();
  2113. Suffix += Temp.Rows[0][0].ToString();
  2114. }
  2115. break;
  2116. //流水需要通过MaxNumber去取
  2117. case "流水":
  2118. string maxnum = "";
  2119. if (ReSetType != " ")
  2120. {
  2121. maxnum = dh.getFieldDataByConditionForUpdate("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'", "update of rmn_maxnumber nowait").ToString();
  2122. }
  2123. else
  2124. {
  2125. maxnum = dh.getFieldDataByConditionForUpdate("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "' ", "update of rmn_maxnumber nowait").ToString();
  2126. }
  2127. //设置当前流水
  2128. if (maxnum == "")
  2129. {
  2130. if (ReSetType != " ")
  2131. {
  2132. maxnum = dh.getFieldDataByConditionForUpdate("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'", "update of rmn_maxnumber nowait").ToString();
  2133. }
  2134. else
  2135. {
  2136. maxnum = dh.getFieldDataByConditionForUpdate("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "' ", "update of rmn_maxnumber nowait").ToString();
  2137. }
  2138. if (maxnum == "")
  2139. {
  2140. maxnum = "1";
  2141. }
  2142. Count = int.Parse(maxnum) + Count;
  2143. 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");
  2144. MaxNum = int.Parse(maxnum);
  2145. }
  2146. else
  2147. {
  2148. MaxNum = int.Parse(maxnum);
  2149. if (ReSetType != " ")
  2150. {
  2151. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + Count) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'");
  2152. }
  2153. else
  2154. {
  2155. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + Count) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "'");
  2156. }
  2157. }
  2158. SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString());
  2159. Radix = int.Parse(Nr.Rows[m]["nrd_radix"].ToString());
  2160. Suffix = "";
  2161. break;
  2162. default:
  2163. break;
  2164. }
  2165. }
  2166. }
  2167. private void GridPrcode_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  2168. {
  2169. string Value = GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  2170. string ID = GridPrcode.Rows[e.RowIndex].Cells["pjd_id"].Value.ToString();
  2171. string checknum = GridPrcode.Rows[e.RowIndex].Cells["checknum"].Value.ToString();
  2172. string pdno = GridPrcode.Rows[e.RowIndex].Cells["pd_pdno"].Value.ToString();
  2173. if (GridPrcode.Columns[e.ColumnIndex].Name == "pjd_zxbzs_user")
  2174. {
  2175. dh.UpdateByCondition("PRODJOINVENDDETAIL", "pjd_zxbzs_user='" + Value + "'", "pjd_id='" + ID + "'");
  2176. dh.UpdateByCondition("CS$INOUTPRCODE", "pjd_zxbzs_user='" + Value + "'", "pjd_id='" + ID + "' and pd_inoutno='" + pi_inoutno.Text + "'");
  2177. }
  2178. if (GridPrcode.Columns[e.ColumnIndex].Name == "checknum")
  2179. {
  2180. //更新复核数据
  2181. dh.UpdateByCondition("CS$InoutPrcode", "checknum='" + checknum + "'", "pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + pdno + "' and combined=" + combined);
  2182. }
  2183. //删除对应物料的明细
  2184. CurrentPrCode = GridPrcode.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString();
  2185. CurrentZXBZ = GridPrcode.Rows[e.RowIndex].Cells["pjd_zxbzs_user"].Value.ToString();
  2186. CurrentUnit = GridPrcode.Rows[e.RowIndex].Cells["pr_unit"].Value.ToString();
  2187. CurrentPDNO = GridPrcode.Rows[e.RowIndex].Cells["pd_pdno"].Value.ToString();
  2188. CurrentPrCount = GridPrcode.Rows[e.RowIndex].Cells["pd_outqty"].Value.ToString();
  2189. CurrentBrand = GridPrcode.Rows[e.RowIndex].Cells["pd_brand"].Value.ToString();
  2190. GridPrcode.Rows[e.RowIndex].Selected = true;
  2191. if (e.RowIndex - 2 >= 0)
  2192. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex - 2;
  2193. else
  2194. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex;
  2195. LoadGridData(sender, new EventArgs());
  2196. }
  2197. private void GridPrcode_SelectionChanged(object sender, EventArgs e)
  2198. {
  2199. if (GridPrcode.SelectedRows.Count > 0)
  2200. {
  2201. DataGridViewSelectedRowCollection dsc = GridPrcode.SelectedRows;
  2202. MachineCollectRowIndex = GridPrcode.SelectedRows[0].Index;
  2203. CurrentPrCode = GridPrcode.Rows[dsc[0].Index].Cells["pd_prodcode"].Value.ToString();
  2204. CurrentZXBZ = GridPrcode.Rows[dsc[0].Index].Cells["pjd_zxbzs_user"].Value.ToString();
  2205. CurrentUnit = GridPrcode.Rows[dsc[0].Index].Cells["pr_unit"].Value.ToString();
  2206. CurrentPDNO = GridPrcode.Rows[dsc[0].Index].Cells["pd_pdno"].Value.ToString();
  2207. CurrentPrCount = GridPrcode.Rows[dsc[0].Index].Cells["pd_outqty"].Value.ToString();
  2208. CurrentBrand = GridPrcode.Rows[dsc[0].Index].Cells["pd_brand"].Value.ToString();
  2209. GridPrcode.Rows[dsc[0].Index].Selected = true;
  2210. if (dsc[0].Index - 2 >= 0)
  2211. GridPrcode.FirstDisplayedScrollingRowIndex = dsc[0].Index - 2;
  2212. else
  2213. GridPrcode.FirstDisplayedScrollingRowIndex = dsc[0].Index;
  2214. }
  2215. }
  2216. private void GridPrcode_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  2217. private void GridPrcode_CellClick(object sender, DataGridViewCellEventArgs e)
  2218. {
  2219. if (e.RowIndex >= 0)
  2220. {
  2221. GridPrcode.Rows[e.RowIndex].Selected = true;
  2222. if (e.RowIndex - 2 > 0)
  2223. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex - 2;
  2224. else
  2225. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex;
  2226. }
  2227. }
  2228. private void DCCheck_Leave(object sender, EventArgs e)
  2229. {
  2230. try
  2231. {
  2232. Properties.Settings.Default.DCCheck = int.Parse(DCCheck.Text);
  2233. Properties.Settings.Default.Save();
  2234. }
  2235. catch (Exception)
  2236. {
  2237. MessageBox.Show("DC校验时间必须是整数");
  2238. }
  2239. }
  2240. /// <summary>
  2241. /// 校验DateCode
  2242. /// </summary>
  2243. /// <param name="DateCode"></param>
  2244. private bool CheckDateCode(string DateCode)
  2245. {
  2246. try
  2247. {
  2248. //根据DateCode计算的日期
  2249. string Year = DateCode.Substring(0, 2);
  2250. System.DateTime dt = new DateTime(int.Parse("20" + Year), 01, 01);
  2251. string Week = DateCode.Substring(2, 2);
  2252. System.DateTime dt1 = dt.AddDays((int.Parse(Week) -1)* 7);
  2253. //减去DC校验后的日期
  2254. System.DateTime now = System.DateTime.Now;
  2255. System.DateTime now1 = now.AddDays(-int.Parse(DCCheck.Text));
  2256. //物料的DateCode大于限制日期即可
  2257. if (dt1 > now1 && dt1 < now)
  2258. {
  2259. return true;
  2260. }
  2261. return false;
  2262. }
  2263. catch (Exception)
  2264. {
  2265. return false;
  2266. }
  2267. }
  2268. private void PrintFooter_Click(object sender, EventArgs e)
  2269. {
  2270. FootReport.Load(@"'C:\打印标签\唛头.frx");
  2271. 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");
  2272. string SQL = "select pib_outboxcode2||'/'||(select max(to_number(pib_outboxcode2)) from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "') from prodiobarcode where pib_id=";
  2273. for (int i = 0; i < dt.Rows.Count; i++)
  2274. {
  2275. DataTable dt1 = (DataTable)dh.ExecuteSql(SQL + "'" + dt.Rows[i]["pib_id"].ToString() + "'", "select");
  2276. FootReport.SetParameterValue("唛头", dt1.Rows[0][0].ToString());
  2277. FootReport.PrintSettings.ShowDialog = false;
  2278. FootReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  2279. FootReport.Print();
  2280. }
  2281. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "打印唛头", "成功");
  2282. }
  2283. private void Input_KeyUp(object sender, KeyEventArgs e)
  2284. {
  2285. if (e.KeyCode == Keys.Enter)
  2286. {
  2287. if (!forinput.Checked)
  2288. Input.SelectAll();
  2289. }
  2290. }
  2291. private void GridPrcode_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  2292. {
  2293. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  2294. if (e.ColumnIndex > 0 && e.RowIndex >= 0)
  2295. {
  2296. if (GridPrcode.Columns[e.ColumnIndex].Name == "CollectedNum")
  2297. {
  2298. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  2299. if (GridPrcode.Rows[e.RowIndex].Cells["CollectedNum"].Value.ToString() != GridPrcode.Rows[e.RowIndex].Cells["pd_outqty"].Value.ToString())
  2300. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.Yellow, e.CellBounds);
  2301. else
  2302. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.White, e.CellBounds);
  2303. Rectangle border = e.CellBounds;
  2304. border.Width -= 1;
  2305. e.Graphics.DrawRectangle(Pens.White, border);
  2306. e.PaintContent(e.CellBounds);
  2307. e.Handled = true;
  2308. }
  2309. }
  2310. }
  2311. private void GridPrcode_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
  2312. {
  2313. if (e.Button == MouseButtons.Right)
  2314. {
  2315. if (e.RowIndex >= 0 && e.ColumnIndex > 0)
  2316. {
  2317. string Conetent = GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  2318. Clipboard.SetText(Conetent);
  2319. MessageBox.Show("已复制内容" + Conetent);
  2320. }
  2321. }
  2322. }
  2323. private void Pack_Click(object sender, EventArgs e)
  2324. {
  2325. if (LabelInf.Rows.Count > 0)
  2326. {
  2327. int GetNumCount = 1;
  2328. for (int i = 0; i < LabelInf.Rows.Count; i++)
  2329. {
  2330. if (LabelInf.Rows[i].Cells["pib_custoutboxcode"].Value.ToString() == "")
  2331. {
  2332. if (i + 1 < LabelInf.Rows.Count)
  2333. {
  2334. string FPrcode = LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString();
  2335. string FPocode = LabelInf.Rows[i].Cells["pd_pocode"].Value.ToString();
  2336. string FWhcode = LabelInf.Rows[i].Cells["pib_brand"].Value.ToString();
  2337. string FDC = LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString();
  2338. string FLOTNO = LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString();
  2339. string FPDCustProdCode = LabelInf.Rows[i].Cells["pd_custprodcode"].Value.ToString();
  2340. string BPrcode = LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString();
  2341. string BPocode = LabelInf.Rows[i + 1].Cells["pd_pocode"].Value.ToString();
  2342. string BWhcode = LabelInf.Rows[i + 1].Cells["pib_brand"].Value.ToString();
  2343. string BDC = LabelInf.Rows[i + 1].Cells["pib_datecode"].Value.ToString();
  2344. string BLOTNO = LabelInf.Rows[i + 1].Cells["pib_lotno"].Value.ToString();
  2345. string BPDCustProdCode = LabelInf.Rows[i + 1].Cells["pd_custprodcode"].Value.ToString();
  2346. if (FPDCustProdCode != BPDCustProdCode || FPrcode != BPrcode || FPocode != BPocode || FWhcode != BWhcode || (DiffDC.Checked && FDC != BDC) || (DiffLotNo.Checked && FLOTNO != BLOTNO))
  2347. {
  2348. GetNumCount = GetNumCount + 1;
  2349. }
  2350. }
  2351. }
  2352. }
  2353. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, GetNumCount);
  2354. List<string> OutBoxCode = new List<string>();
  2355. List<string> PIBID = new List<string>();
  2356. string Str_OutBoxCode = "";
  2357. for (int i = 0; i < LabelInf.Rows.Count; i++)
  2358. {
  2359. if (LabelInf.Rows[i].Cells["pib_custoutboxcode"].Value.ToString() == "")
  2360. {
  2361. PIBID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  2362. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  2363. for (int k = serialcode.ToString().Length; k < NumLength; k++)
  2364. {
  2365. serialcode = "0" + serialcode;
  2366. }
  2367. if (i + 1 < LabelInf.Rows.Count)
  2368. {
  2369. string FPrcode = LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString();
  2370. string FPocode = LabelInf.Rows[i].Cells["pd_pocode"].Value.ToString();
  2371. string FWhcode = LabelInf.Rows[i].Cells["pib_brand"].Value.ToString();
  2372. string FDC = LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString();
  2373. string FLOTNO = LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString();
  2374. string FPDCustProdCode = LabelInf.Rows[i].Cells["pd_custprodcode"].Value.ToString();
  2375. string FPDNO = LabelInf.Rows[i].Cells["pib_pdno"].Value.ToString();
  2376. string BPrcode = LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString();
  2377. string BPocode = LabelInf.Rows[i + 1].Cells["pd_pocode"].Value.ToString();
  2378. string BWhcode = LabelInf.Rows[i + 1].Cells["pib_brand"].Value.ToString();
  2379. string BDC = LabelInf.Rows[i + 1].Cells["pib_datecode"].Value.ToString();
  2380. string BLOTNO = LabelInf.Rows[i + 1].Cells["pib_lotno"].Value.ToString();
  2381. string BPDCustProdCode = LabelInf.Rows[i + 1].Cells["pd_custprodcode"].Value.ToString();
  2382. string BPDNO = LabelInf.Rows[i + 1].Cells["pib_pdno"].Value.ToString();
  2383. if ((DiffDetno.Checked && BPDNO != FPDNO) || (DiffCPN.Checked && FPDCustProdCode != BPDCustProdCode) || FPrcode != BPrcode || FPocode != BPocode || FWhcode != BWhcode || (DiffDC.Checked && FDC != BDC) || (DiffLotNo.Checked && FLOTNO != BLOTNO))
  2384. {
  2385. MaxNum = MaxNum + 1;
  2386. }
  2387. }
  2388. OutBoxCode.Add(Prefix + serialcode + Suffix);
  2389. Str_OutBoxCode += "'" + Prefix + serialcode + Suffix + "',";
  2390. }
  2391. }
  2392. if (OutBoxCode.ToArray().Length > 0)
  2393. {
  2394. if (!dh.CheckExist("prodiobarcode", "pib_custcode='" + pi_cardcode.Text + "' and pib_custoutboxcode in (" + Str_OutBoxCode.Substring(0, Str_OutBoxCode.Length - 1) + ")"))
  2395. {
  2396. 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());
  2397. }
  2398. else
  2399. {
  2400. if (ReSetType != " ")
  2401. {
  2402. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'");
  2403. }
  2404. else
  2405. {
  2406. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "'");
  2407. }
  2408. Pack_Click(sender, e);
  2409. return;
  2410. }
  2411. LoadGridData(sender, e);
  2412. }
  2413. }
  2414. }
  2415. private void PackMidBox_Click(object sender, EventArgs e)
  2416. {
  2417. DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + OutBoxNum.Text + "' order by pib_outboxcode2", "select");
  2418. DataTable dt1 = null;
  2419. int GetNumCount = 0;
  2420. for (int i = 0; i < dt.Rows.Count; i++)
  2421. {
  2422. 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");
  2423. //如果不是10的整数倍则为尾盒
  2424. int tencount = 0;
  2425. for (int j = 0; j < dt1.Rows.Count; j++)
  2426. {
  2427. 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()))
  2428. {
  2429. GetNumCount = GetNumCount + 1;
  2430. }
  2431. tencount = tencount + 1;
  2432. }
  2433. }
  2434. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, GetNumCount);
  2435. if (Radix > 0)
  2436. {
  2437. //生成中盒条码
  2438. int pib_outboxcode1 = int.Parse(dh.getFieldDataByCondition("prodiobarcode", "max(to_number(nvl(pib_outboxcode1,0)))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString());
  2439. MaxNum = MaxNum - 1;
  2440. for (int i = 0; i < dt.Rows.Count; i++)
  2441. {
  2442. List<string> MidBoxCode = new List<string>();
  2443. List<string> PIBID = new List<string>();
  2444. List<string> PIBOUTBOXCODE1 = new List<string>();
  2445. 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");
  2446. //如果不是10的整数倍则为尾盒
  2447. int tencount = 0;
  2448. for (int j = 0; j < dt1.Rows.Count; j++)
  2449. {
  2450. 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()))
  2451. {
  2452. pib_outboxcode1 = pib_outboxcode1 + 1;
  2453. MaxNum = MaxNum + 1;
  2454. tencount = 0;
  2455. }
  2456. tencount = tencount + 1;
  2457. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  2458. for (int k = serialcode.ToString().Length; k < NumLength; k++)
  2459. {
  2460. serialcode = "0" + serialcode;
  2461. }
  2462. MidBoxCode.Add(Prefix + serialcode + Suffix);
  2463. PIBID.Add(dt1.Rows[j]["pib_id"].ToString());
  2464. PIBOUTBOXCODE1.Add(pib_outboxcode1.ToString());
  2465. }
  2466. 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());
  2467. }
  2468. }
  2469. LoadGridData(sender, e);
  2470. }
  2471. private void PrintStatus_Click(object sender, EventArgs e)
  2472. {
  2473. EnablePrint = !EnablePrint;
  2474. if (EnablePrint)
  2475. {
  2476. SetPrintStatus_label.ForeColor = Color.Green;
  2477. SetPrintStatus_label.Text = "可打印";
  2478. }
  2479. else
  2480. {
  2481. SetPrintStatus_label.ForeColor = Color.Red;
  2482. SetPrintStatus_label.Text = "暂停打印";
  2483. }
  2484. Input.Focus();
  2485. }
  2486. private void CustomerLabel_Click(object sender, EventArgs e)
  2487. {
  2488. sql.Clear();
  2489. sql.Append("update prodiobarcode set pib_custbarcode=case when instr(pib_custbarcode,'SL')=0 ");
  2490. sql.Append("then ('SL'||pib_custbarcode)else pib_custbarcode end, pib_custoutboxcode=case when instr");
  2491. sql.Append("(pib_custoutboxcode,'SC')=0 then ('SC'||pib_custoutboxcode)else pib_custoutboxcode end where pib_inoutno='" + pi_inoutno.Text + "'");
  2492. dh.ExecuteSql(sql.ToString(), "select");
  2493. LoadGridData(sender, e);
  2494. CustomerLabel.Enabled = false;
  2495. }
  2496. private void Combindetail_CheckedChanged(object sender, EventArgs e)
  2497. {
  2498. if (Combindetail.Checked)
  2499. {
  2500. CombindetailTwo.Checked = false;
  2501. CombindetailThree.Checked = false;
  2502. }
  2503. if (LoadCheck)
  2504. {
  2505. LoadPrcodeData();
  2506. string response = "";
  2507. string[] param = new string[] { PI_ID, "1", response };
  2508. dh.CallProcedure("USER_PRODOUT_GROUPQTY", param);
  2509. }
  2510. }
  2511. private void CombindetailTwo_CheckedChanged(object sender, EventArgs e)
  2512. {
  2513. if (CombindetailTwo.Checked)
  2514. {
  2515. Combindetail.Checked = false;
  2516. CombindetailThree.Checked = false;
  2517. }
  2518. if (LoadCheck)
  2519. {
  2520. LoadPrcodeData();
  2521. string response = "";
  2522. string[] param = new string[] { PI_ID, "2", response };
  2523. dh.CallProcedure("USER_PRODOUT_GROUPQTY", param);
  2524. }
  2525. }
  2526. private void CombindetailThree_CheckedChanged(object sender, EventArgs e)
  2527. {
  2528. if (CombindetailThree.Checked)
  2529. {
  2530. Combindetail.Checked = false;
  2531. CombindetailTwo.Checked = false;
  2532. }
  2533. if (LoadCheck)
  2534. {
  2535. LoadPrcodeData();
  2536. string response = "";
  2537. string[] param = new string[] { PI_ID, "3", response };
  2538. dh.CallProcedure("USER_PRODOUT_GROUPQTY_TEST", param);
  2539. }
  2540. }
  2541. string SelectProdcode = "";
  2542. int SelectRowIndex = -1;
  2543. private void LabelInf_CellClick(object sender, DataGridViewCellEventArgs e)
  2544. {
  2545. if (e.RowIndex >= 0)
  2546. {
  2547. LabelInf.Rows[e.RowIndex].Selected = true;
  2548. SelectRowIndex = e.RowIndex;
  2549. }
  2550. }
  2551. private void OutBoxNum_SelectedIndexChanged(object sender, EventArgs e)
  2552. {
  2553. OutBoxNum1 = OutBoxNum.Text;
  2554. LoadGridData(sender, e);
  2555. }
  2556. private void LabelInf_SelectionChanged(object sender, EventArgs e)
  2557. {
  2558. DataGridViewSelectedRowCollection dsc = LabelInf.SelectedRows;
  2559. if (dsc.Count > 0)
  2560. {
  2561. SelectRowIndex = dsc[0].Index;
  2562. }
  2563. }
  2564. string OutBoxNum1 = "";
  2565. private void OutBoxNum_SelectionChangeCommitted(object sender, EventArgs e)
  2566. {
  2567. if (OutBoxNum1 != "全部" && OutBoxNum1 != "新增")
  2568. if (dh.getFieldDataByCondition("prodiobarcode", "pib_outifprint", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + OutBoxNum1 + "'").ToString() != "-1")
  2569. {
  2570. MessageBox.Show("外箱号" + OutBoxNum1 + "尚未打印标签");
  2571. }
  2572. OutBoxNum1 = OutBoxNum.Text;
  2573. if (OutBoxNum1 == "新增")
  2574. {
  2575. PassSixTenCount = 1;
  2576. PassTenCount = 1;
  2577. CurrentBoxNum.Value = 0;
  2578. CurrentOutBoxNum.Value = 0;
  2579. }
  2580. }
  2581. private void Reset_Click(object sender, EventArgs e)
  2582. {
  2583. string close = MessageBox.Show(this.ParentForm, "清除当前已采集数据,刷新待采集数据", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  2584. if (close.ToString() == "Yes")
  2585. {
  2586. dh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  2587. dh.ExecuteSql("delete from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "'", "delete");
  2588. dh.UpdateByCondition("prodinout", "pi_user_packingstatus=''", "pi_inoutno='" + pi_inoutno.Text + "'");
  2589. pi_inoutno_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  2590. }
  2591. }
  2592. private void AddNewOutBox_Click(object sender, EventArgs e)
  2593. {
  2594. if (OutBoxNum1 != "全部" && OutBoxNum1 != "新增")
  2595. if (dh.getFieldDataByCondition("prodiobarcode", "pib_outifprint", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + OutBoxNum1 + "'").ToString() != "-1")
  2596. {
  2597. MessageBox.Show("外箱号" + OutBoxNum1 + "尚未打印标签");
  2598. }
  2599. OutBoxNum1 = OutBoxNum.Text;
  2600. if (OutBoxNum1 == "新增")
  2601. {
  2602. PassSixTenCount = 1;
  2603. PassTenCount = 1;
  2604. CurrentBoxNum.Value = 0;
  2605. CurrentOutBoxNum.Value = 0;
  2606. }
  2607. OutBoxNum.Text = "新增";
  2608. }
  2609. private void GetPDdata_Click(object sender, EventArgs e)
  2610. {
  2611. dh.ExecuteSql("delete from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "'", "delete");
  2612. LoadPrcodeData();
  2613. 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 + "'");
  2614. MessageBox.Show("同步出货单明细数据成功", "提示");
  2615. }
  2616. private void ResetHBXH_Click(object sender, EventArgs e)
  2617. {
  2618. dh.ExecuteSql("update prodiodetail set PD_HBXH_USER=pd_pdno where pd_inoutno='" + pi_inoutno.Text + "'", "update");
  2619. MessageBox.Show("重置序号成功", "提示");
  2620. }
  2621. private void ButtonWeigh_Click(object sender, EventArgs e)
  2622. {
  2623. if (Weight.Text != "" && Weight.Text != "0.000")
  2624. {
  2625. sql.Clear();
  2626. sql.Append("update prodiobarcode set pib_boxweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' ");
  2627. sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "'");
  2628. dh.ExecuteSql(sql.ToString(), "update");
  2629. LoadGridData(sender, e);
  2630. }
  2631. else
  2632. {
  2633. MessageBox.Show("请先连接电子秤!");
  2634. }
  2635. }
  2636. Regex reg = new Regex(@"\d+.\d+");
  2637. ComInfoSet cis;
  2638. private void ConnectCom_Click(object sender, EventArgs e)
  2639. {
  2640. cis = new ComInfoSet();
  2641. (cis.Controls["PortName"] as SerialPortCombox).SelectedValue = Properties.Settings.Default.PortName;
  2642. cis.Controls["BaudRate"].Text = Properties.Settings.Default.BaudRate;
  2643. cis.Controls["Confirm"].Click += UAS_出货标签打印_Click;
  2644. cis.ShowDialog();
  2645. }
  2646. private void UAS_出货标签打印_Click(object sender, EventArgs e)
  2647. {
  2648. if (Com.IsOpen && Com.PortName == cis.Controls["PortName"].Text)
  2649. {
  2650. MessageBox.Show("串口" + Com.PortName + "已打开");
  2651. return;
  2652. }
  2653. else
  2654. {
  2655. if (Com.IsOpen)
  2656. {
  2657. Com.Close();
  2658. }
  2659. }
  2660. int BaudRate = 0;
  2661. Com.PortName = cis.Controls["PortName"].Text;
  2662. if (int.TryParse(cis.Controls["BaudRate"].Text, out BaudRate))
  2663. {
  2664. Com.BaudRate = BaudRate;
  2665. }
  2666. Properties.Settings.Default.BaudRate = BaudRate.ToString();
  2667. Properties.Settings.Default.PortName = cis.Controls["PortName"].Text;
  2668. Properties.Settings.Default.Save();
  2669. Com.DataReceived += Com_DataReceived;
  2670. Com.Open();
  2671. cis.Close();
  2672. }
  2673. private void Com_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
  2674. {
  2675. try
  2676. {
  2677. int len = Com.BytesToRead;
  2678. byte[] readBuffer = new byte[len];
  2679. Com.Read(readBuffer, 0, len); //将数据读入缓存
  2680. string value = reg.Match(Encoding.ASCII.GetString(readBuffer, 0, len)).Value;
  2681. if (value != "")
  2682. {
  2683. Weight.Text = value;
  2684. }
  2685. //读不到数据的时间删掉
  2686. }
  2687. catch (Exception)
  2688. {
  2689. return;
  2690. }
  2691. }
  2692. private void CloseSerialPort_Click(object sender, EventArgs e)
  2693. {
  2694. if (Com.IsOpen)
  2695. {
  2696. Com.Close();
  2697. Com.DataReceived -= Com_DataReceived;
  2698. }
  2699. }
  2700. private void ShowMenu_Total_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  2701. {
  2702. ShowMenu_Total.Close();
  2703. switch (e.ClickedItem.Text)
  2704. {
  2705. case "清除明细":
  2706. CleanDetail_Click(sender, e);
  2707. break;
  2708. case "标签维护":
  2709. LabelMaintain_Click(sender, e);
  2710. break;
  2711. case "打印唛头":
  2712. PrintFooter_Click(sender, e);
  2713. break;
  2714. case "附加信息":
  2715. AttachInfo_Click(sender, e);
  2716. break;
  2717. case "打印状态":
  2718. PrintStatus_Click(sender, e);
  2719. break;
  2720. case "标签自定义":
  2721. CustomerLabel_Click(sender, e);
  2722. break;
  2723. case "同步出货数据":
  2724. GetPDdata_Click(sender, e);
  2725. break;
  2726. case "重置单据":
  2727. Reset_Click(sender, e);
  2728. break;
  2729. case "贴标机参数设置":
  2730. MachineSetting ms = new MachineSetting();
  2731. BaseUtil.SetFormCenter(ms);
  2732. ms.ShowDialog();
  2733. break;
  2734. case "断开贴标机":
  2735. receiveClient.Close();
  2736. sendClient.Close();
  2737. resetClient.Close();
  2738. break;
  2739. case "内部标签打印":
  2740. 内部标签打印 ms2 = new 内部标签打印(SingleLabelPrinter.Text);
  2741. BaseUtil.SetFormCenter(ms2);
  2742. ms2.ShowDialog();
  2743. break;
  2744. case "贴标角度设置":
  2745. if (pi_cardcode.Text != "")
  2746. {
  2747. 贴标角度设置 ms1 = new 贴标角度设置(pi_cardcode.Text);
  2748. ms1.FormClosed += Ms1_FormClosed;
  2749. BaseUtil.SetFormCenter(ms1);
  2750. ms1.ShowDialog();
  2751. }
  2752. else
  2753. {
  2754. MessageBox.Show("请先获取客户信息");
  2755. }
  2756. break;
  2757. }
  2758. }
  2759. private void Ms1_FormClosed(object sender, FormClosedEventArgs e)
  2760. {
  2761. DataTable XY = (DataTable)dh.ExecuteSql("select * from PRINTXY where px_custcode='" + pi_cardcode.Text + "' and px_machine='" + SystemInf.Machine + "'", "select");
  2762. if (XY.Rows.Count == 0)
  2763. {
  2764. XY = (DataTable)dh.ExecuteSql("select * from PRINTXY where px_custcode='" + pi_cardcode.Text + "'", "select");
  2765. }
  2766. if (XY.Rows.Count > 0)
  2767. {
  2768. Angle = XY.Rows[0]["px_angle"].ToString();
  2769. X = XY.Rows[0]["px_x"].ToString();
  2770. Y = XY.Rows[0]["px_y"].ToString();
  2771. }
  2772. }
  2773. private void MenuManage_Click(object sender, EventArgs e)
  2774. {
  2775. ShowMenu_Total.Show(new Point(MenuManage.Location.X, MenuManage.Location.Y + 20));
  2776. }
  2777. SqliteDBHelper sdh = SystemInf.sdh;
  2778. //接受数据客户端
  2779. TcpClient receiveClient;
  2780. //发送指令客户端
  2781. TcpClient sendClient;
  2782. //复核数据客户端
  2783. TcpClient resetClient;
  2784. NetworkStream ns;
  2785. NetworkStream ns1;
  2786. Thread receiveThread;
  2787. Thread sendThread;
  2788. int dataindex = 0;
  2789. string ps_split = "";
  2790. private void Connect_Click(object sender, EventArgs e)
  2791. {
  2792. SingleLabelAutoPrint.Checked = true;
  2793. MidLabelAutoPrint.Checked = true;
  2794. CurrentRowOnly.Checked = true;
  2795. AutoPrintMidBox.Checked = true;
  2796. receiveClient = new TcpClient();
  2797. sendClient = new TcpClient();
  2798. resetClient = new TcpClient();
  2799. DataTable dt = (DataTable)sdh.ExecuteSql("select * from ParamSetting", "select");
  2800. if (dt.Rows.Count > 0)
  2801. {
  2802. try
  2803. {
  2804. //发起TCP连接
  2805. receiveClient.Connect(dt.Rows[0]["ps_ip"].ToString(), int.Parse(dt.Rows[0]["ps_receiveport"].ToString()));
  2806. sendClient.Connect(dt.Rows[0]["ps_ip"].ToString(), int.Parse(dt.Rows[0]["ps_sendport"].ToString()));
  2807. resetClient.Connect(dt.Rows[0]["ps_ip"].ToString(), int.Parse(dt.Rows[0]["ps_resetport"].ToString()));
  2808. dataindex = int.Parse(dt.Rows[0]["ps_dataindex"].ToString());
  2809. ps_split = dt.Rows[0]["ps_split"].ToString();
  2810. if (receiveClient != null)
  2811. {
  2812. MessageBox.Show("连接服务器成功");
  2813. ConnectToMachine = true;
  2814. //获得绑定的网络数据流
  2815. ns = receiveClient.GetStream();
  2816. ns1 = sendClient.GetStream();
  2817. Control.CheckForIllegalCrossThreadCalls = false;
  2818. //实例化并启动接受消息线程
  2819. receiveThread = new Thread(receive_message);
  2820. receiveThread.Start();
  2821. sendThread = new Thread(send_message);
  2822. sendThread.Start();
  2823. }
  2824. else
  2825. {
  2826. MessageBox.Show("连接服务器失败");
  2827. }
  2828. }
  2829. catch (Exception ex)
  2830. {
  2831. MessageBox.Show(ex.Message);
  2832. }
  2833. }
  2834. }
  2835. bool IsSum = false;
  2836. private void receive_message()
  2837. {
  2838. while (IsOnline(receiveClient))
  2839. {
  2840. try
  2841. {
  2842. //创建接收数据的字节流
  2843. byte[] getData = new byte[1024];
  2844. //从网络流中读取数据
  2845. ns.Read(getData, 0, getData.Length);
  2846. //将字节数组转换成文本形式
  2847. string getMsg = Encoding.Default.GetString(getData);
  2848. if (getMsg.Contains("ReadId"))
  2849. {
  2850. string msgStr = getMsg.Trim('\0').Replace("ReadId1|,|", "");
  2851. if (!msgStr.Contains("三星"))
  2852. {
  2853. msgStr = Regex.Match(msgStr, @"[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+").Value;
  2854. //设置索引和内容
  2855. // msgStr = msgStr.Split(ps_split.ToCharArray()[0])[dataindex];
  2856. Input.Text = msgStr;
  2857. IsSum = false;
  2858. }
  2859. else
  2860. {
  2861. IsSum = true;
  2862. }
  2863. Input_KeyDown(Input, new KeyEventArgs(Keys.Enter));
  2864. }
  2865. }
  2866. catch (Exception)
  2867. {
  2868. //接受消息发生异常
  2869. break;
  2870. //并释放相关资源
  2871. //if (ns != null)
  2872. // ns.Dispose();
  2873. //break;
  2874. }
  2875. }
  2876. MessageBox.Show("网络中断");
  2877. }
  2878. private void send_message()
  2879. {
  2880. while (IsOnline(sendClient))
  2881. {
  2882. try
  2883. {
  2884. //创建接收数据的字节流
  2885. byte[] getData = new byte[1024];
  2886. //从网络流中读取数据 z
  2887. ns1.Read(getData, 0, getData.Length);
  2888. //将字节数组转换成文本形式
  2889. string getMsg = Encoding.Default.GetString(getData);
  2890. if (getMsg.Contains("ReadId3"))
  2891. {
  2892. string msgStr = getMsg.Trim('\0').Replace("ReadId3|,|", "");
  2893. string temp = Regex.Match(msgStr, @"[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+").Value;
  2894. string pr_code = "";
  2895. //如果不存在原厂标签的话
  2896. if (temp != "")
  2897. {
  2898. pr_code = temp.Split('*')[0];
  2899. }
  2900. //如果允许混料的话
  2901. bool OutBoxSplit = false;
  2902. if (PassSixTenCount > OutboxCapacity.Value)
  2903. {
  2904. string close = MessageBox.Show(this.ParentForm, "此箱号采集后超数量,是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly).ToString();
  2905. if (close == "Yes")
  2906. {
  2907. OutBoxSplit = true;
  2908. PassSixTenCount = 1;
  2909. //sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|0"));
  2910. }
  2911. else
  2912. {
  2913. }
  2914. }
  2915. if (MixPrCode.Checked)
  2916. {
  2917. bool SendLast = false;
  2918. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  2919. {
  2920. //获取复核的数据
  2921. int checknum = int.Parse(GridPrcode.Rows[i].Cells["checknum"].Value.ToString());
  2922. double outqty = double.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString());
  2923. double zxbzs = double.Parse(GridPrcode.Rows[i].Cells["PJD_ZXBZS_USER"].Value.ToString());
  2924. string Prcode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  2925. string pdno = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  2926. if (checknum < outqty / zxbzs)
  2927. {
  2928. checknum = checknum + 1;
  2929. GridPrcode.Rows[i].Cells["checknum"].Value = checknum;
  2930. dh.ExecuteSql("update CS$InoutPrcode set checknum=nvl(checknum,0)+1 where pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + pdno + "' and combined=" + combined, "update");
  2931. if (i == GridPrcode.Rows.Count - 1 && checknum == outqty / zxbzs)
  2932. SendLast = true;
  2933. break;
  2934. }
  2935. }
  2936. if (PassTenCount == MidboxCapacity.Value)
  2937. {
  2938. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1"));
  2939. PassTenCount = 0;
  2940. }
  2941. else
  2942. {
  2943. if (SendLast)
  2944. {
  2945. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1"));
  2946. string close = MessageBox.Show("采集完此行数据,是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly).ToString();
  2947. if (close == "Yes")
  2948. {
  2949. }
  2950. else
  2951. {
  2952. }
  2953. }
  2954. else
  2955. {
  2956. if (!OutBoxSplit)
  2957. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|0"));
  2958. }
  2959. }
  2960. }
  2961. else
  2962. {
  2963. bool SendLast = false;
  2964. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  2965. {
  2966. //获取复核的数据
  2967. int checknum = int.Parse(GridPrcode.Rows[i].Cells["checknum"].Value.ToString());
  2968. double outqty = double.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString());
  2969. double zxbzs = double.Parse(GridPrcode.Rows[i].Cells["PJD_ZXBZS_USER"].Value.ToString());
  2970. string Prcode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  2971. string pdno = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  2972. string SelectPrCode = GridPrcode.Rows[MachineCollectRowIndex].Cells["pd_prodcode"].Value.ToString();
  2973. if ((MachineCollectRowIndex == i && SelectPrCode == pr_code) || ((pr_code == Prcode || pr_code == "") && SelectPrCode != pr_code) && checknum < outqty / zxbzs)
  2974. {
  2975. checknum = checknum + 1;
  2976. GridPrcode.Rows[i].Cells["checknum"].Value = checknum;
  2977. if (checknum < outqty / zxbzs)
  2978. {
  2979. dh.ExecuteSql("update CS$InoutPrcode set checknum=nvl(checknum,0)+1 where pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + pdno + "' and combined=" + combined, "update");
  2980. }
  2981. else if (checknum == outqty / zxbzs)
  2982. {
  2983. dh.ExecuteSql("update CS$InoutPrcode set checknum=nvl(checknum,0)+1 where pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + pdno + "' and combined=" + combined, "update");
  2984. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1"));
  2985. checknum = 0;
  2986. SendLast = true;
  2987. PassTenCount = 0;
  2988. string close = MessageBox.Show("采集完此行数据,是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly).ToString();
  2989. if (close == "Yes")
  2990. {
  2991. }
  2992. else
  2993. {
  2994. }
  2995. }
  2996. break;
  2997. }
  2998. }
  2999. //达到了中盒容量之后
  3000. if (PassTenCount == MidboxCapacity.Value)
  3001. {
  3002. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1"));
  3003. PassTenCount = 0;
  3004. }
  3005. else
  3006. {
  3007. //如果发送了最后一盒,则不发送继续堆叠的指令 或者需要分盒的时候
  3008. if ((!SendLast && !OutBoxSplit) || OutBoxSplit)
  3009. {
  3010. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|0"));
  3011. }
  3012. }
  3013. }
  3014. //中盒当前进度
  3015. CurrentBoxNum.Value = PassTenCount;
  3016. PassTenCount = PassTenCount + 1;
  3017. //外箱当前进度
  3018. CurrentOutBoxNum.Value = PassSixTenCount;
  3019. PassSixTenCount = PassSixTenCount + 1;
  3020. }
  3021. //设置索引和内容
  3022. //msgStr = msgStr.Split(ps_split.ToCharArray()[0])[dataindex];
  3023. //Input.Text = msgStr;
  3024. //Input_KeyDown(Input, new KeyEventArgs(Keys.Enter));
  3025. //}
  3026. //catch (ThreadAbortException)
  3027. //{
  3028. // //捕捉到线程被终止异常则表示是人为的断开TCP连接
  3029. // //不弹出错误提示
  3030. // break;
  3031. }
  3032. catch (Exception)
  3033. {
  3034. //接受消息发生异常
  3035. break;
  3036. //并释放相关资源
  3037. //if (ns != null)
  3038. // ns.Dispose();
  3039. //break;
  3040. }
  3041. }
  3042. MessageBox.Show("网络中断");
  3043. }
  3044. private string GetSendCode(string Code)
  3045. {
  3046. if (Angle != "")
  3047. {
  3048. Code = Code + "|,|" + Angle;
  3049. }
  3050. if (X != "")
  3051. {
  3052. Code = Code + "|,|" + X;
  3053. }
  3054. if (Y != "")
  3055. {
  3056. Code = Code + "|,|" + Y;
  3057. }
  3058. return Code;
  3059. }
  3060. /// <summary>
  3061. /// 检测TCP连接是否存在还是已经中断
  3062. /// </summary>
  3063. /// <param name="c"></param>
  3064. /// <returns></returns>
  3065. public bool IsOnline(TcpClient c)
  3066. {
  3067. try
  3068. {
  3069. bool result = !((c.Client.Poll(1000, SelectMode.SelectRead) && (c.Client.Available == 0)) || !c.Client.Connected);
  3070. return result;
  3071. }
  3072. catch
  3073. {
  3074. return false;
  3075. }
  3076. }
  3077. private void CurrentBoxNum_ValueChanged(object sender, EventArgs e)
  3078. {
  3079. }
  3080. private void CurrentBoxNum_KeyDown(object sender, KeyEventArgs e)
  3081. {
  3082. if (e.KeyCode == Keys.Enter)
  3083. {
  3084. PassTenCount = int.Parse(CurrentBoxNum.Value.ToString()) + 1;
  3085. }
  3086. }
  3087. private void CurrentOutBoxNum_KeyDown(object sender, KeyEventArgs e)
  3088. {
  3089. if (e.KeyCode == Keys.Enter)
  3090. {
  3091. PassSixTenCount = int.Parse(CurrentOutBoxNum.Value.ToString()) + 1;
  3092. }
  3093. }
  3094. private void richTextAutoBottom1_TextChanged(object sender, EventArgs e)
  3095. {
  3096. }
  3097. private void Weight_Click(object sender, EventArgs e)
  3098. {
  3099. }
  3100. private void groupBoxWithBorder2_Enter(object sender, EventArgs e)
  3101. {
  3102. }
  3103. private void DCCheck_TextChanged(object sender, EventArgs e)
  3104. {
  3105. }
  3106. private void GridPrcode_CellContentClick(object sender, DataGridViewCellEventArgs e)
  3107. {
  3108. }
  3109. private void label18_Click(object sender, EventArgs e)
  3110. {
  3111. }
  3112. private void MidBoxEnd_TextChanged(object sender, EventArgs e)
  3113. {
  3114. }
  3115. private void MidBoxBegin_TextChanged(object sender, EventArgs e)
  3116. {
  3117. }
  3118. private void label16_Click(object sender, EventArgs e)
  3119. {
  3120. }
  3121. private void SingleBoxEnd_TextChanged(object sender, EventArgs e)
  3122. {
  3123. }
  3124. private void SingleBoxBegin_TextChanged(object sender, EventArgs e)
  3125. {
  3126. }
  3127. private void label12_Click(object sender, EventArgs e)
  3128. {
  3129. }
  3130. private void label7_Click(object sender, EventArgs e)
  3131. {
  3132. }
  3133. private void groupBoxWithBorder1_Enter(object sender, EventArgs e)
  3134. {
  3135. }
  3136. private void Input_TextChanged(object sender, EventArgs e)
  3137. {
  3138. }
  3139. private void LabelInf_CellContentClick(object sender, DataGridViewCellEventArgs e)
  3140. {
  3141. }
  3142. private void pi_inoutno_TextChanged(object sender, EventArgs e)
  3143. {
  3144. }
  3145. private void label14_Click(object sender, EventArgs e)
  3146. {
  3147. }
  3148. private void CurrentOutBoxNum_ValueChanged(object sender, EventArgs e)
  3149. {
  3150. }
  3151. private void label13_Click(object sender, EventArgs e)
  3152. {
  3153. }
  3154. private void SingleLabelPrinter_Load(object sender, EventArgs e)
  3155. {
  3156. }
  3157. private void SingleLabelAutoPrint_CheckedChanged(object sender, EventArgs e)
  3158. {
  3159. }
  3160. private void SingleLabel_Enter(object sender, EventArgs e)
  3161. {
  3162. }
  3163. private void CurrentRowOnly_CheckedChanged(object sender, EventArgs e)
  3164. {
  3165. }
  3166. private void MidboxCapacity_ValueChanged(object sender, EventArgs e)
  3167. {
  3168. }
  3169. private void label2_Click(object sender, EventArgs e)
  3170. {
  3171. }
  3172. private void MidLabelNum_TextChanged(object sender, EventArgs e)
  3173. {
  3174. }
  3175. private void label5_Click(object sender, EventArgs e)
  3176. {
  3177. }
  3178. private void MidLabelPrinter_Load(object sender, EventArgs e)
  3179. {
  3180. }
  3181. private void MidLabelAutoPrint_CheckedChanged(object sender, EventArgs e)
  3182. {
  3183. }
  3184. private void MidLabel_Enter(object sender, EventArgs e)
  3185. {
  3186. }
  3187. private void DiffDetno_CheckedChanged(object sender, EventArgs e)
  3188. {
  3189. }
  3190. private void DiffCPN_CheckedChanged(object sender, EventArgs e)
  3191. {
  3192. }
  3193. private void BoxCount_Click(object sender, EventArgs e)
  3194. {
  3195. }
  3196. private void DiffLotNo_CheckedChanged(object sender, EventArgs e)
  3197. {
  3198. }
  3199. private void DiffDC_CheckedChanged(object sender, EventArgs e)
  3200. {
  3201. }
  3202. private void OnlyOneRow_CheckedChanged(object sender, EventArgs e)
  3203. {
  3204. }
  3205. private void AllLabel_CheckedChanged(object sender, EventArgs e)
  3206. {
  3207. }
  3208. private void label10_Click(object sender, EventArgs e)
  3209. {
  3210. }
  3211. private void label6_Click(object sender, EventArgs e)
  3212. {
  3213. }
  3214. private void OutBoxPrinter_Load(object sender, EventArgs e)
  3215. {
  3216. }
  3217. private void OutboxCapacity_ValueChanged(object sender, EventArgs e)
  3218. {
  3219. }
  3220. private void OutBoxLabel_Enter(object sender, EventArgs e)
  3221. { }
  3222. private void ButtonMidWeigh_Click(object sender, EventArgs e)
  3223. {
  3224. if (Weight.Text != "" && Weight.Text != "0.000")
  3225. {
  3226. string pib_outboxcode1 = LabelInf.Rows[SelectRowIndex].Cells["pib_outboxcode1"].Value.ToString();
  3227. sql.Clear();
  3228. sql.Append("update prodiobarcode set pib_midboxweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' ");
  3229. sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "' and pib_outboxcode1='" + pib_outboxcode1 + "'");
  3230. dh.ExecuteSql(sql.ToString(), "update");
  3231. LoadGridData(sender, e);
  3232. }
  3233. else
  3234. {
  3235. MessageBox.Show("请先连接电子秤!");
  3236. }
  3237. }
  3238. private void RemainTxt()
  3239. {
  3240. string[] str = Input.Text.Split('*');
  3241. Input.Text = "";
  3242. if (str.Length >= 4)
  3243. {
  3244. for (int i = 0; i < 4; i++)
  3245. {
  3246. Input.Text += str[i] + "*";
  3247. }
  3248. Input.Text.Replace("\n", "").Replace("\r", "");
  3249. Input.SelectionStart = Input.Text.Length;
  3250. }
  3251. }
  3252. }
  3253. }