Açıklama Yok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Frm_BG_main.vb 242KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923
  1. Imports System.Data.SqlClient
  2. Imports OfficeOpenXml
  3. Imports System.Net
  4. Imports Microsoft.Office.Interop
  5. 'Imports Microsoft.Office.Interop.Excel
  6. 'Imports Microsoft.Office.Core.XlPivotFieldOrientation
  7. Public Class Frm_BG_main
  8. Dim cmd As New SqlCommand
  9. Dim da As New SqlDataAdapter
  10. Dim my_year111 As Integer
  11. Dim my_month111 As Integer
  12. 'Dim my_year As Integer
  13. Dim dt1 As New DataTable
  14. Dim sql As String
  15. Dim conn As New SqlConnection
  16. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  17. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  18. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  19. Dim xlRange As Microsoft.Office.Interop.Excel.Range
  20. Dim PTCache As Microsoft.Office.Interop.Excel.PivotCache
  21. Dim PT As Microsoft.Office.Interop.Excel.PivotTable
  22. Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
  23. Frm_wb_out.Show()
  24. End Sub
  25. Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
  26. Frm_Stock_Month.Show()
  27. End Sub
  28. Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
  29. Frm_BG_PROCESS.Show()
  30. End Sub
  31. Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
  32. Frm_BG_Record.Show()
  33. End Sub
  34. Private Sub Button19_Click(sender As Object, e As EventArgs) Handles Button19.Click
  35. Frm_Ship_detail.Show()
  36. End Sub
  37. Private Sub Button20_Click(sender As Object, e As EventArgs) Handles Button20.Click
  38. Frm_BG_IN_SUM.Show()
  39. End Sub
  40. Private Sub Button21_Click(sender As Object, e As EventArgs) Handles Button21.Click
  41. Frm_BG_OUT_SUM.Show()
  42. End Sub
  43. Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
  44. Frm_BG_Chem_Out_Daily.Show()
  45. End Sub
  46. Private Sub Button22_Click(sender As Object, e As EventArgs) Handles Button22.Click '---每日发货
  47. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  48. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  49. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  50. Dim name(1000) As String
  51. Dim no(1000) As String
  52. Dim SERIAL(1000) As String
  53. Dim YEAR1(1000) As String
  54. Dim MONTH1(1000) As String
  55. Dim DATE1(1000) As String
  56. Dim COMMENT(1000) As String
  57. Dim qty(1000) As Double
  58. Dim QTY1(1000) As Double
  59. Dim po_no(1000) As String
  60. Dim sku_no(1000) As String
  61. Dim nw(1000) As Double
  62. Dim gw(1000) As Double
  63. Dim price(1000) As Double
  64. Dim dt As New DataTable
  65. Dim file_name As String = ""
  66. Dim file_name1 As String = ""
  67. ListBox1.Items.Clear()
  68. Dim my_weight As Double = 0
  69. Dim a As Integer = 0
  70. Dim my_count As Integer = 0
  71. 'OpenFileDialog1.Multiselect = True
  72. If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
  73. file_name = OpenFileDialog1.FileName
  74. file_name1 = OpenFileDialog1.SafeFileName
  75. Else
  76. Exit Sub
  77. End If
  78. xlApp = CreateObject("Excel.Application")
  79. xlApp.Visible = True
  80. xlApp.DisplayAlerts = False
  81. 'sql = "delete from rt_bg_io"
  82. 'cmd.CommandText = sql
  83. 'cmd.ExecuteNonQuery()
  84. xlBook = xlApp.Workbooks.Open(file_name,, True)
  85. xlBook.Activate()
  86. Dim yy As Integer = 0
  87. ListBox1.Items.Add(file_name)
  88. Dim my_customer As String = ""
  89. If OpenFileDialog1.SafeFileName Like "*上杰*" And OpenFileDialog1.SafeFileName Like "*越南*" Then '---------------------------------------上杰越南
  90. my_weight = InputBox("请输入货柜重量",, 0)
  91. sql = "delete from rt_ship_daily_sj_vn"
  92. cmd.CommandText = sql
  93. cmd.ExecuteNonQuery()
  94. xlSheet = xlApp.Workbooks(1).Worksheets(1)
  95. xlSheet.Activate()
  96. Dim y As Integer = 0
  97. For y = 14 To xlApp.ActiveSheet.UsedRange.Rows.Count
  98. If Len(xlSheet.Cells(y, 2).value) < 1 Then
  99. Exit For
  100. End If
  101. Next y
  102. xlApp.Range("A14:N" & y - 1).Select()
  103. xlApp.Selection.UnMerge
  104. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  105. 'xlApp.CutCopyMode = False
  106. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  107. For y = 14 To y - 1
  108. sql = "insert into rt_ship_daily_sj_vn (my_weight,no,name,qty,weight,po_no,unit_price,sku_no,order_month) values(" & my_weight & ",'" & xlSheet.Cells(y, 1).value & "',N'" & xlSheet.Cells(y, 2).value & "'," & xlSheet.Cells(y, 3).value & "," & Math.Round(xlSheet.Cells(y, 5).value, 3) & ",N'" & Math.Round(xlSheet.Cells(y, 6).value, 3) & "'," & xlSheet.Cells(y, 9).value & ",N'" & xlSheet.Cells(y, 10).value & "','" & xlSheet.Cells(y, 11).value & "')"
  109. cmd.CommandText = sql
  110. cmd.ExecuteScalar()
  111. Next
  112. sql = "select po_no as 订单号,name as 品名, thick as 厚度, cast(sum(qty) as numeric(10,1)) as 尺数,cast(sum(weight) as numeric(10,1)) as 重量 from (SELECT my_weight,no, po_no, name,qty,weight, case when left(name,3)='1.2' then '1.24' when left(name,3)='1.4' then '1.46' end as thick FROM RT_SHIP_DAILY_sj_vn) as p group by po_no,name,thick"
  113. cmd.CommandText = sql
  114. dt = New DataTable
  115. da.SelectCommand = cmd
  116. da.Fill(dt)
  117. dgv1.DataSource = dt
  118. sql = "select 品名,厚度,尺数,cast(尺数/SUM(尺数) OVER () *货柜重 as numeric(10,4)) as 重量 from
  119. (SELECT 品名, thick AS 厚度, CAST(SUM(qty) AS numeric(10, 1)) AS 尺数, CAST(SUM(weight) AS numeric(10, 1)) AS 重量 ,
  120. AVG(my_weight) AS 货柜重
  121. FROM (SELECT my_weight, no, po_no, name, qty, weight, CASE WHEN LEFT(name, 3) = '1.2' THEN '1.24' WHEN LEFT(name,
  122. 3) = '1.4' THEN '1.46' END AS thick, CASE WHEN name LIKE '%PU%' OR
  123. name LIKE '%action%' OR
  124. name LIKE N'%榔%' THEN 'PU' ELSE '反毛' END AS 品名
  125. FROM RT_SHIP_DAILY_SJ_VN) AS p
  126. GROUP BY 品名, thick) as q"
  127. cmd.CommandText = sql
  128. dt = New DataTable
  129. da.SelectCommand = cmd
  130. da.Fill(dt)
  131. dgv2.DataSource = dt
  132. ' sql = "select 品名,thick as 厚度, cast(sum(qty_sf) as numeric(10,1)) as 尺数,sum(weight) as 净重 from (SELECT no, po_no, no1, m_no, name, ltrim(thick) as thick, color, qty_sf, no2, p, nw, gw,cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no) *nw as numeric(10,1)) as weight,case when name like '%PU%' or name like N'%纹%' or name like '%action%' or name like N'%榔%' then 'pu' else '反毛' end as 品名
  133. 'FROM RT_SHIP_DAILY_JH) as p group by 品名,thick"
  134. ' cmd.CommandText = sql
  135. ' dt = New DataTable
  136. ' da.SelectCommand = cmd
  137. ' da.Fill(dt)
  138. 'dgv3.DataSource = dt
  139. ElseIf OpenFileDialog1.SafeFileName Like "*上杰*" Then '----------------------------------------------------------------------------------上杰
  140. sql = "delete from rt_ship_daily_sj"
  141. cmd.CommandText = sql
  142. cmd.ExecuteNonQuery()
  143. xlSheet = xlApp.Workbooks(1).Worksheets(1)
  144. Dim y As Integer = 0
  145. For y = 14 To xlApp.Workbooks(1).Worksheets(1).UsedRange.Rows.Count
  146. If Len(xlSheet.Cells(y, 2).value) < 1 Then
  147. Exit For
  148. End If
  149. Next y
  150. xlApp.Range("A14:N" & y - 1).Select()
  151. ' If xlApp.Selection.mergecells = True Then
  152. xlApp.Selection.UnMerge
  153. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  154. 'xlApp.CutCopyMode = False
  155. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  156. ' End If
  157. Dim my_no As String
  158. Dim my_nw As Double
  159. Dim my_gw As Double
  160. Dim my_sf As Double
  161. Dim my_price As Double
  162. Dim s1 As Integer = 1
  163. For y = 14 To y - 1
  164. If Not (xlSheet.Cells(y, 10).value Is Nothing) Then
  165. If (xlSheet.Cells(y, 6).value Is Nothing) And (xlSheet.Cells(y, 7).value Is Nothing) Then
  166. my_nw = xlSheet.Cells(y - 1, 6).value
  167. my_gw = xlSheet.Cells(y - 1, 7).value
  168. my_no = xlSheet.Cells(y - 1, 1).value
  169. Else
  170. my_nw = xlSheet.Cells(y, 6).value
  171. my_gw = xlSheet.Cells(y, 7).value
  172. my_no = xlSheet.Cells(y, 1).value
  173. End If
  174. my_sf = xlSheet.Cells(y, 3).value
  175. my_price = xlSheet.Cells(y, 12).value
  176. sql = "insert into rt_ship_daily_sj (filename,serial,order_item,no,name,qty_sf,nw,gw,po_no,qty_sf1,unit_price) values
  177. (N'" & file_name & "','" & s1 & "','" & xlSheet.Cells(y, 9).value & "','" & my_no & "',N'" & xlSheet.Cells(y, 2).value & "'," & my_sf & "," & my_nw & "," & my_gw & ",N'" & xlSheet.Cells(y, 8).value & "'," & xlSheet.Cells(y, 10).value & "," & my_price & ")"
  178. cmd.CommandText = sql
  179. cmd.ExecuteScalar()
  180. End If
  181. Next
  182. ' sql = "select 品名,cast(sum(淨重) as numeric(10,1)) as 淨重 from (select case when 品名 like '%PU%' or 品名 like '%action%' or 品名 like N'%榔%' then 'pu' else '反毛' end as 品名,淨重 from (select name as 品名,sum(weight) as 淨重 from (SELECT no, name, qty_sf1, nw,qty_sf1/SUM(qty_sf1) OVER (PARTITION BY no) AS Ratio, cast(qty_sf1/SUM(qty_sf1) OVER (PARTITION BY no) *nw as numeric(10,3)) as weight FROM rt_ship_daily_sj) as p group by name) as q ) as qq group by 品名"
  183. ' cmd.CommandText = sql
  184. ' dt = New DataTable
  185. ' da.SelectCommand = cmd
  186. ' da.Fill(dt)
  187. ' dt.Columns.Add("尺数")
  188. ' dt.Columns.Add("货值")
  189. ' For rr As Integer = 0 To dt.Rows.Count - 1
  190. ' sql = "SELECT CAST(SUM(qty_sf1) AS numeric(10, 1)) AS 呎數 FROM (SELECT DISTINCT no, name, CASE WHEN name LIKE '%PU%' OR name LIKE '%action%' OR name LIKE N'%榔%' THEN 'pu' ELSE '反毛' END AS 品名, qty_sf, unit, nw, gw, po_no, po_serial, qty_sf1, sku_no, order_month, supplier, type, unit_price, cbm FROM rt_ship_daily_sj) AS p
  191. 'GROUP BY 品名 having 品名=N'" & dt.Rows(rr).Item("品名") & "'"
  192. ' cmd.CommandText = sql
  193. ' dt.Rows(rr).Item("尺数") = cmd.ExecuteScalar
  194. ' Next
  195. ' For rr As Integer = 0 To dt.Rows.Count - 1
  196. ' sql = "SELECT CAST(SUM(qty_sf1 * unit_price) AS numeric(10, 3)) AS 金額 FROM (SELECT DISTINCT no, name, CASE WHEN name LIKE '%PU%' OR name LIKE '%action%' OR name LIKE N'%榔%' THEN 'pu' ELSE '反毛' END AS 品名, qty_sf, unit, nw, gw, po_no, po_serial, qty_sf1, sku_no, order_month, supplier, type, unit_price, cbm FROM rt_ship_daily_sj) AS p
  197. 'GROUP BY 品名 having 品名=N'" & dt.Rows(rr).Item("品名") & "'"
  198. ' cmd.CommandText = sql
  199. ' dt.Rows(rr).Item("货值") = cmd.ExecuteScalar
  200. ' Next
  201. ' dgv1.DataSource = dt
  202. sql = "select 品名,po_no as 订购单号,厚度,cast(sum(qty_sf1) as numeric(10,1)) as 尺数,cast(sum(unit_price*qty_sf1)/sum(qty_sf1) as numeric(10,2)) as 单价,cast(sum(unit_price*qty_sf1) as numeric(10,2)) as 货值,sum(净重) as 净重 from
  203. (SELECT no, case when (name like '%PU%' or name like '%action%' or name like N'%榔%') AND name NOT LIKE '%tpu%' then N'贴膜' else '反毛' end as 品名, nw, gw, po_no, qty_sf1, unit_price,case when name like '%1.2%' then '1.24' when name like '%1.4%' then '1.46' else '1.24' end as 厚度,cast(qty_sf1/sum(qty_sf1) over (partition by no) *nw as numeric(10,1)) as 净重
  204. FROM rt_ship_daily_sj) as p group by 品名,po_no,厚度" '----旧
  205. sql = "select name as 品名 ,po_no as 订单号,order_item as 项次号,cast(sum(qty_sf1) as numeric(10,1)) as 尺数,deli_no as 发货单号 from rt_ship_daily_sj group by name,po_no,order_item,deli_no "
  206. cmd.CommandText = sql
  207. dt = New DataTable
  208. da.SelectCommand = cmd
  209. da.Fill(dt)
  210. dgv1.DataSource = dt
  211. dgv1.Columns("品名").Width = 300
  212. dgv1.Columns("订单号").Width = 180
  213. dgv1.Columns("项次号").Width = 80
  214. dgv1.Columns("尺数").Width = 120
  215. sql = "select 品名,颜色,厚度,sum(尺数) as 尺数,sum(货值) as 货值,sum(净重) as 净重 from (select 品名,颜色,po_no as 订购单号,厚度,sum(qty_sf1) as 尺数,sum(unit_price*qty_sf1)/sum(qty_sf1) as 单价,sum(unit_price*qty_sf1) as 货值,sum(净重) as 净重 from
  216. (SELECT no, case when (name like '%PU%' or name like '%action%' or name like N'%榔%') and name not like '%tpu%' then N'贴膜' else '反毛' end as 品名, case when name like '%黑色%' then '黑色' else '其他' end as 颜色, nw, gw, po_no, qty_sf1, unit_price,case when name like '%1.2%' then '1.24' when name like '%1.4%' then '1.46' else '1.24' end as 厚度,cast(qty_sf1/sum(qty_sf1) over (partition by no) *nw as numeric(10,1)) as 净重
  217. FROM rt_ship_daily_sj) as p group by 品名,po_no,厚度,颜色) as q group by 品名,颜色,厚度 order by 品名"
  218. cmd.CommandText = sql
  219. dt = New DataTable
  220. da.SelectCommand = cmd
  221. da.Fill(dt)
  222. dgv2.DataSource = dt
  223. sql = "select 品名,颜色,sum(尺数) as 尺数,sum(货值) as 货值,sum(净重) as 净重 from (select 品名,颜色,po_no as 订购单号,厚度,cast(sum(qty_sf1) as numeric(10,1)) as 尺数,cast(sum(unit_price*qty_sf1)/sum(qty_sf1) as numeric(10,2)) as 单价,cast(sum(unit_price*qty_sf1) as numeric(10,2)) as 货值,sum(净重) as 净重 from
  224. (SELECT no, case when (name like '%PU%' or name like '%action%' or name like N'%榔%') and name not like '%tpu%' then N'贴膜' else '反毛' end as 品名, case when name like '%黑色%' then '黑色' else '其他' end as 颜色, nw, gw, po_no, qty_sf1, unit_price,case when name like '%1.2%' then '1.24' when name like '%1.4%' then '1.46' else '1.24' end as 厚度,cast(qty_sf1/sum(qty_sf1) over (partition by no) *nw as numeric(10,1)) as 净重
  225. FROM rt_ship_daily_sj) as p group by 品名,po_no,厚度,颜色) as q group by 品名,颜色 order by 品名"
  226. cmd.CommandText = sql
  227. dt = New DataTable
  228. da.SelectCommand = cmd
  229. da.Fill(dt)
  230. dgv3.DataSource = dt
  231. ElseIf OpenFileDialog1.SafeFileName Like "*永正货柜*" Then '--------------------------------------------------------------------------永正货柜
  232. sql = "delete from rt_ship_uz_HG"
  233. cmd.CommandText = sql
  234. cmd.ExecuteNonQuery()
  235. xlSheet = xlApp.Workbooks(1).Worksheets(1)
  236. Dim y As Integer = 0
  237. For y = 14 To xlApp.Workbooks(1).Worksheets(1).UsedRange.Rows.Count
  238. If Len(xlSheet.Cells(y, 2).value) < 1 Then
  239. Exit For
  240. End If
  241. Next y
  242. xlApp.Range("A14:N" & y - 1).Select()
  243. ' If xlApp.Selection.mergecells = True Then
  244. xlApp.Selection.UnMerge
  245. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  246. 'xlApp.CutCopyMode = False
  247. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  248. ' End If
  249. Dim mc As Integer = 1
  250. For y = 14 To y - 1
  251. sql = "insert into rt_ship_uz_HG (no,name,qty_sf,nw,gw,po_no,qty_sf1,unit_price,serial) values('" & xlSheet.Cells(y, 1).value & "',N'" & xlSheet.Cells(y, 2).value & "'," & xlSheet.Cells(y, 3).value & "," & xlSheet.Cells(y, 5).value & "," & xlSheet.Cells(y, 6).value & ",N'" & xlSheet.Cells(y, 7).value & "'," & xlSheet.Cells(y, 9).value & "," & xlSheet.Cells(y, 14).value & "," & mc & ")"
  252. cmd.CommandText = sql
  253. cmd.ExecuteScalar()
  254. mc = mc + 1
  255. Next
  256. ' sql = "select 品名,厚度,cast(sum(淨重) as numeric(10,1)) as 淨重 from (select case when 品名 like '%PU%' or 品名 like '%action%' or 品名 like N'%榔%' then 'pu' else '反毛' end as 品名,淨重,厚度 from (select name as 品名, thick as 厚度,sum(weight) as 淨重 from (SELECT no, name,CASE WHEN name LIKE '%1.2%' THEN 1.24 ELSE 1.46 END AS thick, qty_sf1, nw,qty_sf1/SUM(qty_sf1) OVER (PARTITION BY no) AS Ratio, cast(qty_sf1/SUM(qty_sf1) OVER (PARTITION BY no) *nw as numeric(10,3)) as weight FROM RT_Ship_UZ_HG) as p group by name,thick) as q ) as qq group by 品名,厚度"
  257. ' cmd.CommandText = sql
  258. ' dt = New DataTable
  259. ' da.SelectCommand = cmd
  260. ' da.Fill(dt)
  261. ' dt.Columns.Add("尺数")
  262. ' dt.Columns.Add("货值")
  263. ' For rr As Integer = 0 To dt.Rows.Count - 1
  264. ' sql = "SELECT CAST(SUM(qty_sf1) AS numeric(10, 1)) AS 呎數 FROM (SELECT DISTINCT no, name, CASE WHEN name LIKE '%PU%' OR name LIKE '%action%' OR name LIKE N'%榔%' THEN 'pu' ELSE '反毛' END AS 品名, qty_sf, nw, gw, po_no, qty_sf1, unit_price FROM RT_Ship_UZ_HG) AS p
  265. 'GROUP BY 品名 having 品名=N'" & dt.Rows(rr).Item("品名") & "'"
  266. ' cmd.CommandText = sql
  267. ' dt.Rows(rr).Item("尺数") = cmd.ExecuteScalar
  268. ' Next
  269. ' For rr As Integer = 0 To dt.Rows.Count - 1
  270. ' sql = "SELECT CAST(SUM(qty_sf1 * unit_price) AS numeric(10, 3)) AS 金額 FROM (SELECT DISTINCT no, name, CASE WHEN name LIKE '%PU%' OR name LIKE '%action%' OR name LIKE N'%榔%' THEN 'pu' ELSE '反毛' END AS 品名, qty_sf, nw, po_no, qty_sf1,unit_price FROM RT_Ship_UZ_HG) AS p
  271. 'GROUP BY 品名 having 品名=N'" & dt.Rows(rr).Item("品名") & "'"
  272. ' cmd.CommandText = sql
  273. ' dt.Rows(rr).Item("货值") = cmd.ExecuteScalar
  274. ' Next
  275. ' dgv1.DataSource = dt
  276. sql = "select po_no as 订单号,品名 as 类别, 颜色,sum(qty_sf1) as 尺数,cast(sum(qty_sf1*单价)/sum(qty_sf1) as numeric(10,2)) as 单价 from (SELECT rt_ship_uz_hg.po_no, case when name like '%PU%' or name like '%action%' or name like N'%榔%' then '貼膜' else '反毛' end as 品名,case when name like '%黑色%' then '黑色' else '其他' end as 颜色,name,CASE WHEN name LIKE '%1.2%' THEN 1.24 ELSE 1.46 END AS thick,
  277. unit_price as 单价, qty_sf1, nw,qty_sf1/SUM(qty_sf1) OVER (PARTITION BY no) AS Ratio, cast(qty_sf1/SUM(qty_sf1) OVER (PARTITION BY no) *nw as numeric(10,3)) as weight FROM RT_Ship_UZ_HG) as p group by po_no,品名,颜色"
  278. cmd.CommandText = sql
  279. dt = New DataTable
  280. da.SelectCommand = cmd
  281. da.Fill(dt)
  282. dgv1.DataSource = dt
  283. dgv1.Columns(0).Width = 200
  284. dgv1.Columns(1).Width = 80
  285. dgv1.Columns(2).Width = 80
  286. sql = "select 类别,颜色,sum(尺数) as 尺数,cast(sum(货值)/sum(尺数) as numeric(10,2)) as 单价,cast(sum(货值) as numeric(10,2)) as 货值,sum(毛重) as 毛重,sum(净重) as 净重,sum(件数) as 件数 from
  287. ( select po_no as 订单号,类别,sum(nw) as 净重,sum(gw) as 毛重, 颜色,sum(qty_sf1) as 尺数,sum(qty_sf1*单价)as 货值,count(*) as 件数 from
  288. (SELECT rt_ship_uz_hg.po_no, case when name like '%PU%' or name like '%action%' or name like N'%榔%' then '貼膜' else '反毛' end as 类别,case when name like '%黑色%' then '黑色' else '其他' end as 颜色,name,
  289. unit_price as 单价, qty_sf1, nw, gw,qty_sf1/SUM(qty_sf1) OVER (PARTITION BY no) AS Ratio, cast(qty_sf1/SUM(qty_sf1) OVER (PARTITION BY no) *nw as numeric(10,3)) as weight FROM RT_Ship_UZ_HG) as p group by po_no,类别,颜色) as q group by 类别,颜色 order by 类别"
  290. cmd.CommandText = sql
  291. dt = New DataTable
  292. da.SelectCommand = cmd
  293. da.Fill(dt)
  294. dgv2.DataSource = dt
  295. dgv2.Columns(0).Width = 70
  296. dgv2.Columns(1).Width = 70
  297. dgv2.Columns(2).Width = 120
  298. dgv2.Columns(3).Width = 70
  299. dgv2.Columns(4).Width = 120
  300. dgv2.Columns(5).Width = 120
  301. With dgv2.Columns("尺数").DefaultCellStyle
  302. .Format = "n2"
  303. .Alignment = DataGridViewContentAlignment.MiddleRight
  304. End With
  305. With dgv2.Columns("货值").DefaultCellStyle
  306. .Format = "n2"
  307. .Alignment = DataGridViewContentAlignment.MiddleRight
  308. End With
  309. With dgv2.Columns("净重").DefaultCellStyle
  310. .Format = "n2"
  311. .Alignment = DataGridViewContentAlignment.MiddleRight
  312. End With
  313. With dgv2.Columns("毛重").DefaultCellStyle
  314. .Format = "n2"
  315. .Alignment = DataGridViewContentAlignment.MiddleRight
  316. End With
  317. ElseIf OpenFileDialog1.SafeFileName Like "永正发货*" Then '-----------永正发货
  318. sql = "delete from rt_ship_daily_uz_1"
  319. cmd.CommandText = sql
  320. cmd.ExecuteNonQuery()
  321. xlSheet = xlApp.Workbooks(1).Worksheets(1)
  322. Dim y As Integer = 0
  323. For y = 14 To xlApp.Workbooks(1).Worksheets(1).UsedRange.Rows.Count
  324. If Len(xlSheet.Cells(y, 2).value) < 1 Then
  325. Exit For
  326. End If
  327. Next y
  328. yy = y - 1
  329. xlApp.Range("A14:q" & yy).Select()
  330. 'If xlApp.Selection.mergecells = True Then
  331. xlApp.Selection.UnMerge
  332. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  333. 'xlApp.CutCopyMode = False
  334. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  335. 'End If
  336. Dim my_card As String
  337. Dim my_no As String
  338. Dim my_nw As String
  339. Dim my_gw As String
  340. Dim my_name As String
  341. Dim my_po As String
  342. Dim my_price As String
  343. Dim s1 As String = 1
  344. Dim my_skuno As String
  345. Dim my_order_item As String
  346. For y = 14 To y - 1
  347. If y = 14 Then
  348. my_no = xlSheet.Cells(y, 1).value
  349. my_order_item = xlSheet.Cells(y, 1).value
  350. my_name = xlSheet.Cells(y, 2).value
  351. my_card = xlSheet.Cells(y, 5).value
  352. my_nw = xlSheet.Cells(y, 6).value
  353. my_gw = xlSheet.Cells(y, 7).value
  354. my_po = xlSheet.Cells(y, 8).value
  355. my_skuno = xlSheet.Cells(y, 12).value
  356. End If
  357. If xlSheet.Cells(y, 1).value Is Nothing And xlSheet.Cells(y, 3).value Is Nothing And xlSheet.Cells(y, 8).value Is Nothing And xlSheet.Cells(y, 10).value Is Nothing Then
  358. Else
  359. If xlSheet.Cells(y, 10).value Is Nothing Then
  360. Else
  361. If xlSheet.Cells(y, 3).value Is Nothing And xlSheet.Cells(y, 6).value Is Nothing And xlSheet.Cells(y, 7).value Is Nothing Then
  362. my_name = xlSheet.Cells(y, 2).value
  363. my_po = xlSheet.Cells(y, 8).value
  364. Else
  365. my_no = xlSheet.Cells(y, 1).value
  366. my_name = xlSheet.Cells(y, 2).value
  367. my_po = xlSheet.Cells(y, 8).value
  368. my_nw = xlSheet.Cells(y, 6).value
  369. my_gw = xlSheet.Cells(y, 7).value
  370. End If
  371. If xlSheet.Cells(y, 16).value Is Nothing Then
  372. my_price = 0
  373. ListBox2.Items.Add(my_no & "_" & my_name & "_" & xlSheet.Cells(y, 10).value & " 无单价")
  374. Else
  375. my_price = xlSheet.Cells(y, 16).value
  376. End If
  377. If my_nw Is Nothing Then my_nw = 0
  378. If my_gw Is Nothing Then my_gw = 0
  379. sql = "insert into rt_ship_daily_uz_1 (order_item,filename,sku_no,serial,card,no,name,nw,gw,po_no,qty_sf1,unit_price) values('" & xlSheet.Cells(y, 9).value & "',N'" & file_name & "','" & my_skuno & "','" & s1 & "','" & xlSheet.Cells(y, 5).value & "','" & my_no & "',N'" & my_name & "'," & my_nw & "," & my_gw & ",'" & my_po & "'," & xlSheet.Cells(y, 10).value & "," & my_price & ")"
  380. cmd.CommandText = sql
  381. cmd.ExecuteScalar()
  382. s1 = s1 + 1
  383. End If
  384. End If
  385. Next
  386. sql = "select 品名,po_no as 订购单号,厚度,cast(sum(qty_sf1) as numeric(10,1)) as 尺数,cast(sum(unit_price*qty_sf1)/sum(qty_sf1) as numeric(10,2)) as 单价,cast(sum(unit_price*qty_sf1) as numeric(10,2)) as 货值,sum(净重) as 净重 from
  387. (SELECT no, case when name like '%PU%' or name like '%action%' or name like N'%榔%' then N'贴膜' else '反毛' end as 品名, nw, gw, po_no, qty_sf1, unit_price,case when name like '%1.2%' then '1.24' when name like '%1.4%' then '1.46' else '1.24' end as 厚度,cast(qty_sf1/sum(qty_sf1) over (partition by no) *nw as numeric(10,1)) as 净重
  388. FROM RT_SHIP_DAILY_UZ_1) as p group by 品名,po_no,厚度" '----旧
  389. sql = "select name as 品名,po_no as 订单号,order_item as 项次号,cast(sum(qty_sf1) as numeric(10,1)) as 尺数 from rt_ship_daily_uz_1 group by name,po_no,order_item"
  390. cmd.CommandText = sql
  391. dt = New DataTable
  392. da.SelectCommand = cmd
  393. da.Fill(dt)
  394. dt.Columns.Add("发货单号")
  395. dgv1.DataSource = dt
  396. dgv1.Columns("品名").Width = 300
  397. dgv1.Columns("订单号").Width = 120
  398. dgv1.Columns("项次号").Width = 80
  399. dgv1.Columns("尺数").Width = 120
  400. sql = "select 品名,厚度,sum(尺数) as 尺数,sum(货值) as 货值,sum(净重) as 净重 from (select 品名,po_no as 订购单号,厚度,cast(sum(qty_sf1) as numeric(10,1)) as 尺数,cast(sum(unit_price*qty_sf1)/sum(qty_sf1) as numeric(10,2)) as 单价,cast(sum(unit_price*qty_sf1) as numeric(10,2)) as 货值,sum(净重) as 净重 from
  401. (SELECT no, case when name like '%PU%' or name like '%action%' or name like N'%榔%' then N'贴膜' else '反毛' end as 品名, nw, gw, po_no, qty_sf1, unit_price,case when name like '%1.2%' then '1.24' when name like '%1.4%' then '1.46' else '1.24' end as 厚度,cast(qty_sf1/sum(qty_sf1) over (partition by no) *nw as numeric(10,1)) as 净重
  402. FROM RT_SHIP_DAILY_UZ_1) as p group by 品名,po_no,厚度) as q group by 品名,厚度 order by 品名"
  403. cmd.CommandText = sql
  404. dt = New DataTable
  405. da.SelectCommand = cmd
  406. da.Fill(dt)
  407. dgv2.DataSource = dt
  408. sql = "select 品名,sum(尺数) as 尺数,sum(货值) as 货值,sum(净重) as 净重 from (select 品名,po_no as 订购单号,厚度,cast(sum(qty_sf1) as numeric(10,1)) as 尺数,cast(sum(unit_price*qty_sf1)/sum(qty_sf1) as numeric(10,2)) as 单价,cast(sum(unit_price*qty_sf1) as numeric(10,2)) as 货值,sum(净重) as 净重 from
  409. (SELECT no, case when name like '%PU%' or name like '%action%' or name like N'%榔%' then N'贴膜' else '反毛' end as 品名, nw, gw, po_no, qty_sf1, unit_price,case when name like '%1.2%' then '1.24' when name like '%1.4%' then '1.46' else '1.24' end as 厚度,cast(qty_sf1/sum(qty_sf1) over (partition by no) *nw as numeric(10,1)) as 净重
  410. FROM RT_SHIP_DAILY_UZ_1) as p group by 品名,po_no,厚度) as q group by 品名 order by 品名"
  411. cmd.CommandText = sql
  412. dt = New DataTable
  413. da.SelectCommand = cmd
  414. da.Fill(dt)
  415. dgv3.DataSource = dt
  416. ElseIf OpenFileDialog1.SafeFileName Like "*亿博样*" And Not (OpenFileDialog1.SafeFileName Like "*华盛*") Then
  417. sql = "delete from rt_ship_daily_yby"
  418. cmd.CommandText = sql
  419. cmd.ExecuteNonQuery()
  420. Dim s1 As Integer = 0
  421. Dim my_no As Integer
  422. For i = 1 To xlApp.Worksheets.Count
  423. If xlApp.Workbooks(1).Worksheets(i).name = "1" Then
  424. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  425. xlSheet.Activate()
  426. Exit For
  427. End If
  428. Next
  429. Dim y As Integer = 0
  430. For y = 2 To xlApp.ActiveSheet.UsedRange.Rows.Count
  431. If xlSheet.Cells(y, 2).value = "合计:" Then
  432. Exit For
  433. End If
  434. Next y
  435. xlApp.Range("A2:i" & y - 1).Select()
  436. ' If xlApp.Selection.mergecells = True Then
  437. xlApp.Selection.UnMerge
  438. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  439. 'xlApp.CutCopyMode = False
  440. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  441. 'End If
  442. s1 = 1
  443. For y = 2 To y - 1
  444. If xlSheet.Cells(y, 1).value Is Nothing Then
  445. Else
  446. my_no = xlSheet.Cells(y, 1).value
  447. End If
  448. sql = "insert into rt_ship_daily_yby (serial,filename,no,name,qty,nw,gw,po_no) values('" & s1 & "',N'" & file_name & "','" & my_no & "',N'" & xlSheet.Cells(y, 2).value & "'," & xlSheet.Cells(y, 3).value & "," & xlSheet.Cells(y, 5).value & "," & xlSheet.Cells(y, 6).value & ",'" & xlSheet.Cells(y, 7).value & "')"
  449. cmd.CommandText = sql
  450. cmd.ExecuteScalar()
  451. s1 = s1 + 1
  452. Next
  453. sql = "select 订单号,cast(sum(数量) as numeric(10,1)) as 尺数,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度
  454. FROM RT_SHIP_DAILY_YB ) as p group by 订单号,厚度" '旧
  455. sql = "SELECT name as 品名,po_no as 订单号, cast(sum(qty) as numeric(10,1)) as 尺数,deli_no as 发货单号 from RT_SHIP_DAILY_YBy group by po_no,name,deli_no"
  456. cmd.CommandText = sql
  457. dt = New DataTable
  458. da.SelectCommand = cmd
  459. da.Fill(dt)
  460. dgv1.DataSource = dt
  461. dgv1.Columns("品名").Width = 350
  462. dgv1.Columns("订单号").Width = 150
  463. ElseIf OpenFileDialog1.SafeFileName Like "亿博*" And Not (OpenFileDialog1.SafeFileName Like "*亿博样*") Then
  464. sql = "delete from rt_ship_daily_yb"
  465. cmd.CommandText = sql
  466. cmd.ExecuteNonQuery()
  467. Dim s1 As Integer = 0
  468. Dim my_no As Integer
  469. For i = 1 To xlApp.Worksheets.Count
  470. If xlApp.Workbooks(1).Worksheets(i).name = "1" Then
  471. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  472. xlSheet.Activate()
  473. Exit For
  474. End If
  475. Next
  476. Dim y As Integer = 0
  477. For y = 2 To xlApp.ActiveSheet.UsedRange.Rows.Count
  478. If xlSheet.Cells(y, 2).value = "合计:" Then
  479. Exit For
  480. End If
  481. Next y
  482. xlApp.Range("A2:i" & y - 1).Select()
  483. ' If xlApp.Selection.mergecells = True Then
  484. xlApp.Selection.UnMerge
  485. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  486. xlApp.CutCopyMode = False
  487. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  488. 'End If
  489. s1 = 1
  490. For y = 2 To y - 1
  491. If xlSheet.Cells(y, 1).value Is Nothing Then
  492. Else
  493. my_no = xlSheet.Cells(y, 1).value
  494. End If
  495. sql = "insert into rt_ship_daily_yb (serial,filename,no,name,qty,nw,gw,po_no,unit_price) values('" & s1 & "',N'" & file_name & "','" & my_no & "',N'" & xlSheet.Cells(y, 2).value & "'," & xlSheet.Cells(y, 3).value & "," & xlSheet.Cells(y, 5).value & "," & xlSheet.Cells(y, 6).value & ",N'" & xlSheet.Cells(y, 7).value & "',0)"
  496. cmd.CommandText = sql
  497. cmd.ExecuteScalar()
  498. s1 = s1 + 1
  499. Next
  500. sql = "select 订单号,cast(sum(数量) as numeric(10,1)) as 尺数,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度
  501. FROM RT_SHIP_DAILY_YB ) as p group by 订单号,厚度" '旧
  502. sql = "SELECT name as 品名,po_no as 订单号, cast(sum(qty) as numeric(10,1)) as 尺数,deli_no as 发货单号 from RT_SHIP_DAILY_YB group by po_no,name,deli_no"
  503. cmd.CommandText = sql
  504. dt = New DataTable
  505. da.SelectCommand = cmd
  506. da.Fill(dt)
  507. dgv1.DataSource = dt
  508. dgv1.Columns("品名").Width = 350
  509. dgv1.Columns("订单号").Width = 150
  510. ' sql = "select 订单号,类别,cast(sum(数量) as numeric(10,1)) as 尺数,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名,case when name like '%PU%' or name like '%action%' or name like N'%榔%' or name like N'%virgin%' then 'PU' else '反毛' end as 类别, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度
  511. 'FROM RT_SHIP_DAILY_YB) as p group by 订单号,类别,厚度"
  512. ' cmd.CommandText = sql
  513. ' dt = New DataTable
  514. ' da.SelectCommand = cmd
  515. ' da.Fill(dt)
  516. ' dgv2.DataSource = dt
  517. ' sql = "select 类别,sum(尺数),sum(净重) from (select 订单号,类别,cast(sum(数量) as numeric(10,1)) as 尺数,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名,case when name like '%PU%' or name like '%action%' or name like N'%榔%' or name like N'%virgin%' then 'PU' else '反毛' end as 类别, case when name like '%black%' then '黑色' else '其他' end as 颜色, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度
  518. 'FROM RT_SHIP_DAILY_YB) as p group by 订单号,类别,厚度) as q group by 类别"
  519. ' cmd.CommandText = sql
  520. ' dt = New DataTable
  521. ' da.SelectCommand = cmd
  522. ' da.Fill(dt)
  523. ' dgv3.DataSource = dt
  524. ' sql = "select name as 品名,cast(sum(qty_sf) as numeric(10,1)) as 尺数,cast(sum(qty_sf*unit_price) as numeric(10,1)) as 总价,sum(weight) as 淨重 from (SELECT no, name, color, qty_sf, gw1, po_no, unit_price, cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no) *gw1 as numeric(10,1)) as weight
  525. 'FROM RT_SHIP_DAILY_PUMA) as p group by name"
  526. ' cmd.CommandText = sql
  527. ' dt = New DataTable
  528. ' da.SelectCommand = cmd
  529. ' da.Fill(dt)
  530. 'sql = ""
  531. 'cmd.CommandText = sql
  532. 'dt = New DataTable
  533. 'da.SelectCommand = cmd
  534. 'da.Fill(dt)
  535. 'dgv2.DataSource = dt
  536. ElseIf OpenFileDialog1.SafeFileName Like "加和*" Then
  537. sql = "delete from rt_ship_daily_jh"
  538. cmd.CommandText = sql
  539. cmd.ExecuteNonQuery()
  540. For i = 1 To xlApp.Worksheets.Count
  541. If xlApp.Workbooks(1).Worksheets(i).name = "加和" Then
  542. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  543. xlSheet.Activate()
  544. Exit For
  545. End If
  546. Next
  547. Dim y As Integer = 0
  548. For y = 4 To xlApp.ActiveSheet.UsedRange.Rows.Count
  549. If Len(xlSheet.Cells(y, 5).value) < 1 Then
  550. Exit For
  551. End If
  552. Next y
  553. xlApp.Range("A4:m" & y - 1).Select()
  554. ' If xlApp.Selection.mergecells = True Then
  555. xlApp.Selection.UnMerge
  556. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  557. 'xlApp.CutCopyMode = False
  558. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  559. ' End If
  560. For y = 4 To y - 1
  561. sql = "insert into rt_ship_daily_jh (no1,po_no,m_no,name,thick,
  562. color,qty_sf,nw,gw,no2) values('" &
  563. xlSheet.Cells(y, 1).value & "',N'" & xlSheet.Cells(y, 2).value & "','" & xlSheet.Cells(y, 4).value & "',N'" & xlSheet.Cells(y, 5).value & "','" & xlSheet.Cells(y, 6).value &
  564. "',N'" & xlSheet.Cells(y, 7).value & "'," & xlSheet.Cells(y, 8).value & "," & xlSheet.Cells(y, 11).value & "," & xlSheet.Cells(y, 12).value & "," & xlSheet.Cells(y, 10).value & ")"
  565. cmd.CommandText = sql
  566. cmd.ExecuteScalar()
  567. Next
  568. ' sql = "select po_no as 订单号,m_no as 料号,name as 品名, color as 颜色,thick as 厚度,cast(sum(qty_sf) as numeric(10,1)) as 尺数,cast(sum(weight) as numeric(10,1)) as 净重 from (SELECT no1, po_no, no2, m_no, name, ltrim(thick) as thick, color, qty_sf, nw, gw,cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no1) *nw as numeric(10,1)) as weight
  569. ' FROM RT_SHIP_DAILY_JH) as p group by po_no,m_no,name,color,thick"
  570. ' cmd.CommandText = sql
  571. ' dt = New DataTable
  572. ' da.SelectCommand = cmd
  573. ' da.Fill(dt)
  574. ' dgv1.DataSource = dt
  575. ' sql = "select po_no as 订单号,thick as 厚度,cast(sum(qty_sf) as numeric(10,1)) as 尺数,cast(sum(weight) as numeric(10,1)) as 净重 from (SELECT no1, po_no, no2, m_no, name, ltrim(thick) as thick, color, qty_sf, nw, gw,cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no1) *nw as numeric(10,1)) as weight FROM RT_SHIP_DAILY_JH) as p group by po_no,thick"
  576. ' cmd.CommandText = sql
  577. ' dt = New DataTable
  578. ' da.SelectCommand = cmd
  579. ' da.Fill(dt)
  580. ' dgv2.DataSource = dt
  581. ' sql = "select 品名,thick as 厚度, cast(sum(qty_sf) as numeric(10,1)) as 尺数,sum(weight) as 净重 from (SELECT no1, po_no, no2, m_no, name, ltrim(thick) as thick, color, qty_sf, nw, gw,cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no1) *nw as numeric(10,1)) as weight,case when name like '%PU%' or name like N'%纹%' or name like '%action%' or name like N'%榔%' then 'pu' else '反毛' end as 品名
  582. 'FROM RT_SHIP_DAILY_JH) as p group by 品名,thick"
  583. ' cmd.CommandText = sql
  584. ' dt = New DataTable
  585. ' da.SelectCommand = cmd
  586. ' da.Fill(dt)
  587. ' dgv3.DataSource = dt
  588. sql = "SELECT no1, po_no, no2, m_no, name, ltrim(thick) as thick, color, qty_sf, nw, gw,cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no1) *nw as numeric(10,1)) as weight,
  589. case when name like '%PU%' or name like N'%纹%' or name like '%action%' or name like N'%榔%' then 'pu' else '反毛' end as 品名
  590. FROM RT_SHIP_DAILY_JH"
  591. cmd.CommandText = sql
  592. dt = New DataTable
  593. da.SelectCommand = cmd
  594. da.Fill(dt)
  595. dgv1.DataSource = dt
  596. ElseIf OpenFileDialog1.SafeFileName Like "吉兴*" Then
  597. sql = "delete from rt_ship_daily_JX"
  598. cmd.CommandText = sql
  599. cmd.ExecuteNonQuery()
  600. 'For i = 1 To xlApp.Worksheets.Count
  601. ' If xlApp.Workbooks(1).Worksheets(i).name = "0" Then
  602. ' Exit For
  603. ' End If
  604. 'Next
  605. xlSheet = xlApp.Workbooks(1).Worksheets(1)
  606. xlSheet.Activate()
  607. Dim y As Integer = 0
  608. For y = 8 To xlApp.ActiveSheet.UsedRange.Rows.Count
  609. If Len(xlSheet.Cells(y, 2).value) < 1 Then
  610. Exit For
  611. End If
  612. Next y
  613. xlApp.Range("A2:u" & y - 1).Select()
  614. xlApp.Selection.UnMerge
  615. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  616. xlApp.CutCopyMode = False
  617. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  618. For y = 8 To y - 1
  619. sql = "insert into rt_ship_daily_jx (no,name,color,qty,nw,gw,po_no) values('" & xlSheet.Cells(y, 4).value & "',N'" & xlSheet.Cells(y, 8).value & "',N'" & xlSheet.Cells(y, 10).value & "'," & xlSheet.Cells(y, 13).value & "," & xlSheet.Cells(y, 17).value & "," & xlSheet.Cells(y, 20).value & ",N'" & xlSheet.Cells(y, 2).value & "')"
  620. cmd.CommandText = sql
  621. cmd.ExecuteScalar()
  622. Next
  623. sql = "select 订单号,类别,cast(sum(数量) as numeric(10,1)) as 尺数,cast(sum(数量*单价) as numeric(10,3)) as 货值,sum(重量) as 净重,厚度 from
  624. (SELECT po_no as 订单号,name as 品名,case when name like '%PU %' or name like '%action%' or name like N'%榔%' or name like N'%virgin%' then 'PU' else '反毛' end as 类别, qty as 数量,
  625. cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度,unit_price as 单价
  626. FROM RT_SHIP_DAILY_jx) as p group by 订单号,类别,厚度"
  627. cmd.CommandText = sql
  628. dt = New DataTable
  629. da.SelectCommand = cmd
  630. da.Fill(dt)
  631. dgv1.DataSource = dt
  632. sql = "select 类别,sum(尺数),sum(净重),sum(货值) from(select 订单号,类别,cast(sum(数量) as numeric(10,1)) as 尺数,cast(sum(数量*单价) as numeric(10,3)) as 货值,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名,case when name like '%PU %' or name like '% action %' or name like N'%榔%' or name like N'% virgin %' then 'PU' else '反毛' end as 类别, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度,unit_price as 单价 FROM RT_SHIP_DAILY_jx) as p group by 订单号,类别,厚度) as q group by 类别"
  633. cmd.CommandText = sql
  634. dt = New DataTable
  635. da.SelectCommand = cmd
  636. da.Fill(dt)
  637. dgv2.DataSource = dt
  638. ElseIf OpenFileDialog1.SafeFileName Like "*PEI HAI*" Then
  639. sql = "delete from rt_ship_daily_xbh"
  640. cmd.CommandText = sql
  641. cmd.ExecuteNonQuery()
  642. Dim s1 As Integer = 0
  643. Dim my_no As Integer
  644. For i = 1 To xlApp.Worksheets.Count
  645. If xlApp.Workbooks(1).Worksheets(i).name = "1" Then
  646. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  647. xlSheet.Activate()
  648. Exit For
  649. End If
  650. Next
  651. Dim y As Integer = 0
  652. For y = 2 To xlApp.ActiveSheet.UsedRange.Rows.Count
  653. If xlSheet.Cells(y, 2).value Is Nothing Then
  654. Exit For
  655. End If
  656. Next y
  657. xlApp.Range("A2:J" & y - 1).Select()
  658. ' If xlApp.Selection.mergecells = True Then
  659. xlApp.Selection.UnMerge
  660. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  661. xlApp.CutCopyMode = False
  662. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  663. 'End If
  664. s1 = 1
  665. For y = 2 To y - 1
  666. If xlSheet.Cells(y, 1).value Is Nothing Then
  667. Else
  668. my_no = xlSheet.Cells(y, 1).value
  669. End If
  670. sql = "insert into rt_ship_daily_xbh (serial,filename,no,name,qty,nw,gw,po_no) values('" & s1 & "',N'" & file_name & "','" & my_no & "',N'" & xlSheet.Cells(y, 2).value & "'," & xlSheet.Cells(y, 3).value & "," & xlSheet.Cells(y, 6).value & "," & xlSheet.Cells(y, 7).value & ",N'" & xlSheet.Cells(y, 8).value & "')"
  671. cmd.CommandText = sql
  672. cmd.ExecuteScalar()
  673. s1 = s1 + 1
  674. Next
  675. sql = "select 订单号,cast(sum(数量) as numeric(10,1)) as 尺数,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度
  676. FROM RT_SHIP_DAILY_YB ) as p group by 订单号,厚度" '旧
  677. sql = "SELECT name as 品名,po_no as 订单号, cast(sum(qty) as numeric(10,1)) as 尺数,deli_no as 发货单号 from RT_SHIP_DAILY_xbh group by po_no,name,deli_no"
  678. cmd.CommandText = sql
  679. dt = New DataTable
  680. da.SelectCommand = cmd
  681. da.Fill(dt)
  682. dgv1.DataSource = dt
  683. dgv1.Columns("品名").Width = 400
  684. dgv1.Columns("订单号").Width = 150
  685. ElseIf OpenFileDialog1.SafeFileName Like "*锐奇*" Then
  686. sql = "delete from rt_ship_daily_ruiqi"
  687. cmd.CommandText = sql
  688. cmd.ExecuteNonQuery()
  689. Dim s1 As Integer = 0
  690. Dim my_no As Integer
  691. For i = 1 To xlApp.Worksheets.Count
  692. If xlApp.Workbooks(1).Worksheets(i).name = "1" Then
  693. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  694. xlSheet.Activate()
  695. Exit For
  696. End If
  697. Next
  698. Dim y As Integer = 0
  699. For y = 2 To xlApp.ActiveSheet.UsedRange.Rows.Count
  700. If xlSheet.Cells(y, 2).value Is Nothing Then
  701. Exit For
  702. End If
  703. Next y
  704. xlApp.Range("A2:h" & y - 1).Select()
  705. ' If xlApp.Selection.mergecells = True Then
  706. xlApp.Selection.UnMerge
  707. 'End If
  708. s1 = 1
  709. For y = 2 To y - 1
  710. If xlSheet.Cells(y, 1).value Is Nothing Then
  711. Else
  712. my_no = xlSheet.Cells(y, 1).value
  713. End If
  714. sql = "insert into rt_ship_daily_ruiqi (serial,filename,no,name,qty,po_no,work_no) values('" & s1 & "',N'" & file_name & "','" & my_no & "',N'" & xlSheet.Cells(y, 2).value & "','" & xlSheet.Cells(y, 3).value & "','" & xlSheet.Cells(y, 5).value & "','" & xlSheet.Cells(y, 6).value & "')"
  715. cmd.CommandText = sql
  716. cmd.ExecuteScalar()
  717. s1 = s1 + 1
  718. Next
  719. sql = "select 订单号,cast(sum(数量) as numeric(10,1)) as 尺数,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度
  720. FROM RT_SHIP_DAILY_YB ) as p group by 订单号,厚度" '旧
  721. sql = "SELECT name as 品名,po_no as 采购号,work_no as 订单号, cast(sum(qty) as numeric(10,1)) as 尺数,deli_no as 发货单号 from RT_SHIP_DAILY_ruiqi group by po_no,name,work_no,deli_no"
  722. cmd.CommandText = sql
  723. dt = New DataTable
  724. da.SelectCommand = cmd
  725. da.Fill(dt)
  726. dgv1.DataSource = dt
  727. dgv1.Columns("品名").Width = 300
  728. dgv1.Columns("采购号").Width = 150
  729. dgv1.Columns("订单号").Width = 200
  730. ElseIf OpenFileDialog1.SafeFileName Like "宏美*" Then
  731. ElseIf OpenFileDialog1.SafeFileName Like "*HATAY*" Then
  732. ElseIf OpenFileDialog1.SafeFileName Like "宏美*" Then
  733. ElseIf OpenFileDialog1.SafeFileName Like "*亿博*" And OpenFileDialog1.SafeFileName Like "*华盛*" Then
  734. sql = "delete from rt_ship_daily_yby_huasheng"
  735. cmd.CommandText = sql
  736. cmd.ExecuteNonQuery()
  737. Dim s1 As Integer = 0
  738. Dim my_no As Integer
  739. For i = 1 To xlApp.Worksheets.Count
  740. If xlApp.Workbooks(1).Worksheets(i).name = "明细" Then
  741. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  742. xlSheet.Activate()
  743. Exit For
  744. End If
  745. Next
  746. Dim y As Integer = 0
  747. For y = 2 To xlApp.ActiveSheet.UsedRange.Rows.Count
  748. If xlSheet.Cells(y, 2).value = "合计:" Then
  749. Exit For
  750. End If
  751. Next y
  752. xlApp.Range("A2:i" & y - 1).Select()
  753. ' If xlApp.Selection.mergecells = True Then
  754. xlApp.Selection.UnMerge
  755. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  756. xlApp.CutCopyMode = False
  757. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  758. 'End If
  759. s1 = 1
  760. For y = 2 To y - 1
  761. If xlSheet.Cells(y, 1).value Is Nothing Then
  762. Else
  763. my_no = xlSheet.Cells(y, 1).value
  764. End If
  765. sql = "insert into rt_ship_daily_yby_huasheng (serial,filename,no,name,qty,nw,gw,po_no,thick) values('" & s1 & "',N'" & file_name & "','" & my_no & "',N'" & xlSheet.Cells(y, 2).value & "'," & xlSheet.Cells(y, 4).value & "," & xlSheet.Cells(y, 7).value & "," & xlSheet.Cells(y, 8).value & ",N'" & xlSheet.Cells(y, 9).value & "','" & xlSheet.Cells(y, 3).value & "')"
  766. cmd.CommandText = sql
  767. cmd.ExecuteScalar()
  768. s1 = s1 + 1
  769. Next
  770. sql = "select 订单号,cast(sum(数量) as numeric(10,1)) as 尺数,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度
  771. FROM RT_SHIP_DAILY_YB ) as p group by 订单号,厚度" '旧
  772. sql = "SELECT name as 品名,po_no as 订单号, cast(sum(qty) as numeric(10,1)) as 尺数,deli_no as 发货单号 from rt_ship_daily_yby_huasheng group by po_no,name,deli_no"
  773. cmd.CommandText = sql
  774. dt = New DataTable
  775. da.SelectCommand = cmd
  776. da.Fill(dt)
  777. dgv1.DataSource = dt
  778. dgv1.Columns("品名").Width = 350
  779. dgv1.Columns("订单号").Width = 150
  780. ElseIf OpenFileDialog1.SafeFileName Like "EVERGREE*" Then
  781. sql = "delete from rt_ship_daily_evergree"
  782. cmd.CommandText = sql
  783. cmd.ExecuteNonQuery()
  784. Dim s1 As Integer = 0
  785. Dim my_no As Integer
  786. For i = 1 To xlApp.Worksheets.Count
  787. If xlApp.Workbooks(1).Worksheets(i).name = "1" Then
  788. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  789. xlSheet.Activate()
  790. Exit For
  791. End If
  792. Next
  793. Dim y As Integer = 0
  794. For y = 2 To xlApp.ActiveSheet.UsedRange.Rows.Count
  795. If xlSheet.Cells(y, 2).value Is Nothing Then
  796. Exit For
  797. End If
  798. Next y
  799. xlApp.Range("A2:J" & y - 1).Select()
  800. ' If xlApp.Selection.mergecells = True Then
  801. xlApp.Selection.UnMerge
  802. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  803. xlApp.CutCopyMode = False
  804. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  805. 'End If
  806. s1 = 1
  807. For y = 2 To y - 1
  808. If xlSheet.Cells(y, 1).value Is Nothing Then
  809. Else
  810. my_no = xlSheet.Cells(y, 1).value
  811. End If
  812. sql = "insert into rt_ship_daily_evergree (serial,filename,no,name,qty,nw,gw,po_no) values('" & s1 & "',N'" & file_name & "','" & my_no & "',N'" & xlSheet.Cells(y, 2).value & "'," & xlSheet.Cells(y, 3).value & "," & xlSheet.Cells(y, 6).value & "," & xlSheet.Cells(y, 7).value & ",N'" & xlSheet.Cells(y, 8).value & "')"
  813. cmd.CommandText = sql
  814. cmd.ExecuteScalar()
  815. s1 = s1 + 1
  816. Next
  817. sql = "select 订单号,cast(sum(数量) as numeric(10,1)) as 尺数,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度
  818. FROM RT_SHIP_DAILY_YB ) as p group by 订单号,厚度" '旧
  819. sql = "SELECT name as 品名,po_no as 订单号, cast(sum(qty) as numeric(10,1)) as 尺数,deli_no as 发货单号 from RT_SHIP_DAILY_evergree group by po_no,name,deli_no"
  820. cmd.CommandText = sql
  821. dt = New DataTable
  822. da.SelectCommand = cmd
  823. da.Fill(dt)
  824. dgv1.DataSource = dt
  825. dgv1.Columns("品名").Width = 400
  826. dgv1.Columns("订单号").Width = 150
  827. ElseIf OpenFileDialog1.SafeFileName Like "*THANH*" Then
  828. sql = "delete from rt_ship_daily_thanhhu"
  829. cmd.CommandText = sql
  830. cmd.ExecuteNonQuery()
  831. Dim s1 As Integer = 0
  832. Dim my_no As Integer
  833. For i = 1 To xlApp.Worksheets.Count
  834. If xlApp.Workbooks(1).Worksheets(i).name = "1" Then
  835. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  836. xlSheet.Activate()
  837. Exit For
  838. End If
  839. Next
  840. Dim y As Integer = 0
  841. For y = 2 To xlApp.ActiveSheet.UsedRange.Rows.Count
  842. If xlSheet.Cells(y, 2).value Is Nothing Then
  843. Exit For
  844. End If
  845. Next y
  846. xlApp.Range("A2:J" & y - 1).Select()
  847. ' If xlApp.Selection.mergecells = True Then
  848. xlApp.Selection.UnMerge
  849. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  850. xlApp.CutCopyMode = False
  851. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  852. 'End If
  853. s1 = 1
  854. For y = 2 To y - 1
  855. If xlSheet.Cells(y, 1).value Is Nothing Then
  856. Else
  857. my_no = xlSheet.Cells(y, 1).value
  858. End If
  859. sql = "insert into rt_ship_daily_thanhhu (serial,filename,no,name,qty,nw,gw,po_no) values('" & s1 & "',N'" & file_name & "','" & my_no & "',N'" & xlSheet.Cells(y, 2).value & "'," & xlSheet.Cells(y, 3).value & "," & xlSheet.Cells(y, 6).value & "," & xlSheet.Cells(y, 7).value & ",N'" & xlSheet.Cells(y, 8).value & "')"
  860. cmd.CommandText = sql
  861. cmd.ExecuteScalar()
  862. s1 = s1 + 1
  863. Next
  864. sql = "select 订单号,cast(sum(数量) as numeric(10,1)) as 尺数,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度
  865. FROM RT_SHIP_DAILY_YB ) as p group by 订单号,厚度" '旧
  866. sql = "SELECT name as 品名,po_no as 订单号, cast(sum(qty) as numeric(10,1)) as 尺数,deli_no as 发货单号 from RT_SHIP_DAILY_thanhhu group by po_no,name,deli_no"
  867. cmd.CommandText = sql
  868. dt = New DataTable
  869. da.SelectCommand = cmd
  870. da.Fill(dt)
  871. dgv1.DataSource = dt
  872. dgv1.Columns("品名").Width = 400
  873. dgv1.Columns("订单号").Width = 150
  874. ElseIf OpenFileDialog1.SafeFileName Like "PROPER*" Then
  875. sql = "delete from rt_ship_daily_PROPERWELL"
  876. cmd.CommandText = sql
  877. cmd.ExecuteNonQuery()
  878. Dim s1 As Integer = 0
  879. Dim my_no As Integer
  880. For i = 1 To xlApp.Worksheets.Count
  881. If xlApp.Workbooks(1).Worksheets(i).name = "1" Then
  882. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  883. xlSheet.Activate()
  884. Exit For
  885. End If
  886. Next
  887. Dim y As Integer = 0
  888. For y = 2 To xlApp.ActiveSheet.UsedRange.Rows.Count
  889. If xlSheet.Cells(y, 2).value Is Nothing Then
  890. Exit For
  891. End If
  892. Next y
  893. xlApp.Range("A2:J" & y - 1).Select()
  894. ' If xlApp.Selection.mergecells = True Then
  895. xlApp.Selection.UnMerge
  896. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  897. xlApp.CutCopyMode = False
  898. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  899. 'End If
  900. s1 = 1
  901. For y = 2 To y - 1
  902. If xlSheet.Cells(y, 1).value Is Nothing Then
  903. Else
  904. my_no = xlSheet.Cells(y, 1).value
  905. End If
  906. sql = "insert into rt_ship_daily_PROPERWELL (serial,filename,no,name,qty,nw,gw,po_no) values('" & s1 & "',N'" & file_name & "','" & my_no & "',N'" & xlSheet.Cells(y, 2).value & "'," & xlSheet.Cells(y, 3).value & "," & xlSheet.Cells(y, 5).value & "," & xlSheet.Cells(y, 6).value & ",N'" & xlSheet.Cells(y, 7).value & "')"
  907. cmd.CommandText = sql
  908. cmd.ExecuteScalar()
  909. s1 = s1 + 1
  910. Next
  911. sql = "select 订单号,cast(sum(数量) as numeric(10,1)) as 尺数,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度
  912. FROM RT_SHIP_DAILY_YB ) as p group by 订单号,厚度" '旧
  913. sql = "SELECT name as 品名,po_no as 订单号, cast(sum(qty) as numeric(10,1)) as 尺数,deli_no as 发货单号 from RT_SHIP_DAILY_PROPERWELL group by po_no,name,deli_no"
  914. cmd.CommandText = sql
  915. dt = New DataTable
  916. da.SelectCommand = cmd
  917. da.Fill(dt)
  918. dgv1.DataSource = dt
  919. dgv1.Columns("品名").Width = 400
  920. dgv1.Columns("订单号").Width = 150
  921. ElseIf OpenFileDialog1.SafeFileName Like "*STELLA*" Then
  922. sql = "delete from rt_ship_daily_STELLA"
  923. cmd.CommandText = sql
  924. cmd.ExecuteNonQuery()
  925. Dim s1 As Integer = 0
  926. Dim my_no As Integer
  927. For i = 1 To xlApp.Worksheets.Count
  928. If xlApp.Workbooks(1).Worksheets(i).name = "1" Then
  929. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  930. xlSheet.Activate()
  931. Exit For
  932. End If
  933. Next
  934. Dim y As Integer = 0
  935. For y = 2 To xlApp.ActiveSheet.UsedRange.Rows.Count
  936. If xlSheet.Cells(y, 2).value Is Nothing Then
  937. Exit For
  938. End If
  939. Next y
  940. xlApp.Range("A2:J" & y - 1).Select()
  941. ' If xlApp.Selection.mergecells = True Then
  942. xlApp.Selection.UnMerge
  943. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  944. xlApp.CutCopyMode = False
  945. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  946. 'End If
  947. s1 = 1
  948. For y = 2 To y - 1
  949. If xlSheet.Cells(y, 1).value Is Nothing Then
  950. Else
  951. my_no = xlSheet.Cells(y, 1).value
  952. End If
  953. sql = "insert into rt_ship_daily_stella (serial,filename,no,name,qty,nw,gw,po_no) values('" & s1 & "',N'" & file_name & "','" & my_no & "',N'" & xlSheet.Cells(y, 2).value & "'," & xlSheet.Cells(y, 3).value & "," & xlSheet.Cells(y, 6).value & "," & xlSheet.Cells(y, 7).value & ",N'" & xlSheet.Cells(y, 8).value & "')"
  954. cmd.CommandText = sql
  955. cmd.ExecuteScalar()
  956. s1 = s1 + 1
  957. Next
  958. sql = "select 订单号,cast(sum(数量) as numeric(10,1)) as 尺数,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度
  959. FROM RT_SHIP_DAILY_YB ) as p group by 订单号,厚度" '旧
  960. sql = "SELECT name as 品名,po_no as 订单号, cast(sum(qty) as numeric(10,1)) as 尺数,deli_no as 发货单号 from RT_SHIP_DAILY_stella group by po_no,name,deli_no"
  961. cmd.CommandText = sql
  962. dt = New DataTable
  963. da.SelectCommand = cmd
  964. da.Fill(dt)
  965. dgv1.DataSource = dt
  966. dgv1.Columns("品名").Width = 400
  967. dgv1.Columns("订单号").Width = 150
  968. ElseIf OpenFileDialog1.SafeFileName Like "*HATAY*" Then
  969. sql = "delete from rt_ship_daily_HATAY"
  970. cmd.CommandText = sql
  971. cmd.ExecuteNonQuery()
  972. 'For i = 1 To xlApp.Worksheets.Count
  973. ' If xlApp.Workbooks(1).Worksheets(i).name = "0" Then
  974. ' Exit For
  975. ' End If
  976. 'Next
  977. xlSheet = xlApp.Workbooks(1).Worksheets(1)
  978. xlSheet.Activate()
  979. Dim y As Integer = 0
  980. For y = 2 To xlApp.ActiveSheet.UsedRange.Rows.Count
  981. If Len(xlSheet.Cells(y, 2).value) < 1 Then
  982. Exit For
  983. End If
  984. Next y
  985. xlApp.Range("A2:j" & y - 1).Select()
  986. xlApp.Selection.UnMerge
  987. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  988. xlApp.CutCopyMode = False
  989. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  990. For y = 2 To y - 1
  991. sql = "insert into rt_ship_daily_HATAY (no,name,qty,nw,gw,po_no) values('" & xlSheet.Cells(y, 1).value & "',N'" & xlSheet.Cells(y, 2).value & "'," & xlSheet.Cells(y, 3).value & "," & xlSheet.Cells(y, 5).value & "," & xlSheet.Cells(y, 6).value & ",N'" & xlSheet.Cells(y, 7).value & "')"
  992. cmd.CommandText = sql
  993. cmd.ExecuteScalar()
  994. Next
  995. sql = "select 订单号,类别,cast(sum(数量) as numeric(10,1)) as 尺数,cast(sum(数量*单价) as numeric(10,3)) as 货值,sum(重量) as 净重,厚度 from
  996. (SELECT po_no as 订单号,name as 品名,case when name like '%PU %' or name like '%action%' or name like N'%榔%' or name like N'%virgin%' then 'PU' else '反毛' end as 类别, qty as 数量,
  997. cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度,unit_price as 单价
  998. FROM RT_SHIP_DAILY_HATAY) as p group by 订单号,类别,厚度"
  999. cmd.CommandText = sql
  1000. dt = New DataTable
  1001. da.SelectCommand = cmd
  1002. da.Fill(dt)
  1003. dgv1.DataSource = dt
  1004. sql = "select 类别,sum(尺数),sum(净重),sum(货值) from(select 订单号,类别,cast(sum(数量) as numeric(10,1)) as 尺数,cast(sum(数量*单价) as numeric(10,3)) as 货值,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名,case when name like '%PU %' or name like '% action %' or name like N'%榔%' or name like N'% virgin %' then 'PU' else '反毛' end as 类别, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度,unit_price as 单价 FROM RT_SHIP_DAILY_HATAY) as p group by 订单号,类别,厚度) as q group by 类别"
  1005. cmd.CommandText = sql
  1006. dt = New DataTable
  1007. da.SelectCommand = cmd
  1008. da.Fill(dt)
  1009. dgv2.DataSource = dt
  1010. ElseIf OpenFileDialog1.SafeFileName Like "东治*" Then
  1011. ElseIf OpenFileDialog1.SafeFileName Like "东家*" Then
  1012. sql = "delete from rt_ship_daily_dj"
  1013. cmd.CommandText = sql
  1014. cmd.ExecuteNonQuery()
  1015. For i = 1 To xlApp.Worksheets.Count
  1016. If xlApp.Workbooks(1).Worksheets(i).name = "0" Then
  1017. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  1018. xlSheet.Activate()
  1019. Exit For
  1020. End If
  1021. Next
  1022. Dim y As Integer = 0
  1023. For y = 2 To xlApp.ActiveSheet.UsedRange.Rows.Count
  1024. If Len(xlSheet.Cells(y, 7).value) < 1 Then
  1025. Exit For
  1026. End If
  1027. Next y
  1028. xlApp.Range("A2:K" & y - 1).Select()
  1029. xlApp.Selection.UnMerge
  1030. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  1031. xlApp.CutCopyMode = False
  1032. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  1033. For y = 2 To y - 1
  1034. sql = "insert into rt_ship_daily_dj (no,name,qty,nw,gw,po_no,unit_price) values('" & xlSheet.Cells(y, 1).value & "',N'" & xlSheet.Cells(y, 2).value & "'," & xlSheet.Cells(y, 3).value & "," & xlSheet.Cells(y, 5).value & "," & xlSheet.Cells(y, 6).value & ",N'" & xlSheet.Cells(y, 7).value & "'," & xlSheet.Cells(y, 10).value & ")"
  1035. cmd.CommandText = sql
  1036. cmd.ExecuteScalar()
  1037. Next
  1038. sql = "select 订单号,类别,cast(sum(数量) as numeric(10,1)) as 尺数,cast(sum(数量*单价) as numeric(10,3)) as 货值,sum(重量) as 净重,厚度 from
  1039. (SELECT po_no as 订单号,name as 品名,case when name like '%PU%' or name like '%action%' or name like N'%榔%' or name like N'%virgin%' then 'PU' else '反毛' end as 类别, qty as 数量,
  1040. cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度,unit_price as 单价
  1041. FROM RT_SHIP_DAILY_dj) as p group by 订单号,类别,厚度"
  1042. cmd.CommandText = sql
  1043. dt = New DataTable
  1044. da.SelectCommand = cmd
  1045. da.Fill(dt)
  1046. dgv1.DataSource = dt
  1047. sql = "select 类别,sum(尺数),sum(净重),sum(货值) from(select 订单号,类别,cast(sum(数量) as numeric(10,1)) as 尺数,cast(sum(数量*单价) as numeric(10,3)) as 货值,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名,case when name like '%PU%' or name like '%action%' or name like N'%榔%' or name like N'%virgin%' then 'PU' else '反毛' end as 类别, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度,unit_price as 单价 FROM RT_SHIP_DAILY_dj) as p group by 订单号,类别,厚度) as q group by 类别"
  1048. cmd.CommandText = sql
  1049. dt = New DataTable
  1050. da.SelectCommand = cmd
  1051. da.Fill(dt)
  1052. dgv2.DataSource = dt
  1053. ' sql = "select name as 品名,cast(sum(qty_sf) as numeric(10,1)) as 尺数,cast(sum(qty_sf*unit_price) as numeric(10,1)) as 总价,sum(weight) as 淨重 from (SELECT no, name, color, qty_sf, gw1, po_no, unit_price, cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no) *gw1 as numeric(10,1)) as weight
  1054. 'FROM RT_SHIP_DAILY_PUMA) as p group by name"
  1055. ' cmd.CommandText = sql
  1056. ' dt = New DataTable
  1057. ' da.SelectCommand = cmd
  1058. ' da.Fill(dt)
  1059. 'sql = ""
  1060. 'cmd.CommandText = sql
  1061. 'dt = New DataTable
  1062. 'da.SelectCommand = cmd
  1063. 'da.Fill(dt)
  1064. 'dgv2.DataSource = dt
  1065. ElseIf OpenFileDialog1.SafeFileName Like "*威弘*" Then
  1066. sql = "delete from rt_ship_daily_wh"
  1067. cmd.CommandText = sql
  1068. cmd.ExecuteNonQuery()
  1069. Dim s1 As Integer = 1
  1070. Dim s11 As Integer = 1001
  1071. For i = 1 To xlApp.Worksheets.Count
  1072. xlSheet = xlApp.Worksheets(i)
  1073. xlSheet.Activate()
  1074. Dim y As Integer
  1075. For y = xlApp.Workbooks(1).Worksheets(i).UsedRange.Rows.Count To 3 Step -1
  1076. If xlSheet.Cells(y, 1).value = Nothing Then
  1077. GoTo OK2
  1078. End If
  1079. If xlSheet.Cells(y, 1).value.ToString = "数量合计" Then
  1080. Exit For
  1081. End If
  1082. OK2:
  1083. Next y
  1084. Dim yyy As Integer
  1085. For yyy = 3 To xlApp.Workbooks(1).Worksheets(i).UsedRange.Rows.Count
  1086. If xlSheet.Cells(yyy, 14).value = "制 表" Then
  1087. Exit For
  1088. End If
  1089. Next yyy
  1090. xlSheet.Range("A3:A" & y - 1).Select()
  1091. xlApp.Selection.UnMerge
  1092. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  1093. 'xlApp.CutCopyMode = False
  1094. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  1095. xlSheet.Range("c4:g" & y - 1).Select()
  1096. xlApp.Selection.UnMerge
  1097. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  1098. 'xlApp.CutCopyMode = False
  1099. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  1100. xlSheet.Range("k3:k" & yyy - 1).Select()
  1101. xlApp.Selection.UnMerge
  1102. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  1103. 'xlApp.CutCopyMode = False
  1104. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  1105. If xlSheet.Range("N3:Q" & yyy - 1).MergeCells.ToString <> "False" Then
  1106. xlSheet.Range("N3:Q" & yyy - 1).Select()
  1107. xlApp.Selection.UnMerge
  1108. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  1109. 'xlApp.CutCopyMode = False
  1110. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  1111. End If
  1112. Dim my_no As String
  1113. Dim my_po As String
  1114. Dim my_work As String
  1115. Dim my_color As String
  1116. Dim my_thick As String
  1117. Dim my_no1 As String
  1118. Dim my_po1 As String
  1119. Dim my_work1 As String
  1120. Dim my_color1 As String
  1121. Dim my_thick1 As String
  1122. Dim my_card As String
  1123. For y = 3 To y - 1
  1124. If xlSheet.Cells(y, 2).value = Nothing And xlSheet.Cells(y, 4).value = Nothing And xlSheet.Cells(y, 5).value = Nothing And xlSheet.Cells(y, 6).value = Nothing And xlSheet.Cells(y, 7).value = Nothing Then
  1125. ' Exit For
  1126. Else
  1127. If xlSheet.Cells(y, 2).value Is Nothing Then
  1128. Else
  1129. If xlSheet.Cells(y, 4).VALUE Is Nothing Then
  1130. If xlSheet.Cells(y, 1).value Is Nothing Then
  1131. Else
  1132. my_no = xlSheet.Cells(y, 1).value
  1133. End If
  1134. sql = "insert into rt_ship_daily_wh (filename,card,serial,no,sf,order_no,i_no,color,thick) values(N'" & file_name & "','" & xlSheet.Cells(y, 3).value & "','" & s1 & "','" & my_no & "'," & xlSheet.Cells(y, 2).value & ",N'" & my_po & "',N'" & my_work & "',N'" & my_color & "','" & my_thick & "')"
  1135. cmd.CommandText = sql
  1136. cmd.ExecuteScalar()
  1137. s1 = s1 + 1
  1138. Else
  1139. If xlSheet.Cells(y, 1).value Is Nothing Then
  1140. Else
  1141. my_no = xlSheet.Cells(y, 1).value
  1142. End If
  1143. my_po = xlSheet.Cells(y, 4).value
  1144. my_work = xlSheet.Cells(y, 5).value
  1145. my_color = xlSheet.Cells(y, 6).value
  1146. my_thick = xlSheet.Cells(y, 7).value
  1147. sql = "insert into rt_ship_daily_wh (filename,card,serial,no,sf,order_no,i_no,color,thick) values(N'" & file_name & "','" & xlSheet.Cells(y, 3).value & "','" & s1 & "','" & my_no & "'," & xlSheet.Cells(y, 2).value & ",N'" & my_po & "',N'" & my_work & "',N'" & my_color & "','" & my_thick & "')"
  1148. cmd.CommandText = sql
  1149. cmd.ExecuteScalar()
  1150. s1 = s1 + 1
  1151. End If
  1152. End If
  1153. End If
  1154. If xlSheet.Cells(y, 12).value = Nothing And xlSheet.Cells(y, 14).value = Nothing And xlSheet.Cells(y, 15).value = Nothing And xlSheet.Cells(y, 16).value = Nothing And xlSheet.Cells(y, 17).value = Nothing Then
  1155. ' Exit For
  1156. Else
  1157. If xlSheet.Cells(y, 12).value Is Nothing Then
  1158. Else
  1159. If xlSheet.Cells(y, 14).VALUE Is Nothing Then
  1160. If xlSheet.Cells(y, 11).value Is Nothing Then
  1161. Else
  1162. my_no1 = xlSheet.Cells(y, 11).value
  1163. End If
  1164. sql = "insert into rt_ship_daily_wh (filename,card,serial,no,sf,order_no,i_no,color,thick) values(N'" & file_name & "','" & xlSheet.Cells(y, 13).value & "','" & s11 & "','" & my_no1 & "'," & xlSheet.Cells(y, 12).value & ",N'" & my_po1 & "',N'" & my_work1 & "',N'" & my_color1 & "','" & my_thick1 & "')"
  1165. cmd.CommandText = sql
  1166. cmd.ExecuteScalar()
  1167. s11 = s11 + 1
  1168. Else
  1169. If xlSheet.Cells(y, 11).value Is Nothing Then
  1170. Else
  1171. my_no1 = xlSheet.Cells(y, 11).value
  1172. End If
  1173. my_po1 = xlSheet.Cells(y, 14).value
  1174. my_work1 = xlSheet.Cells(y, 15).value
  1175. my_color1 = xlSheet.Cells(y, 16).value
  1176. my_thick1 = xlSheet.Cells(y, 17).value
  1177. sql = "insert into rt_ship_daily_wh (filename,card,serial,no,sf,order_no,i_no,color,thick) values(N'" & file_name & "','" & xlSheet.Cells(y, 13).value & "','" & s11 & "','" & my_no1 & "'," & xlSheet.Cells(y, 12).value & ",N'" & my_po1 & "',N'" & my_work1 & "',N'" & my_color1 & "','" & my_thick1 & "')"
  1178. cmd.CommandText = sql
  1179. cmd.ExecuteScalar()
  1180. s11 = s11 + 1
  1181. End If
  1182. End If
  1183. 'sql = "insert into rt_ship_076_1 (no,sf,order_no,i_no,color,thick) values('" & my_no1 & "'," & xlSheet.Cells(y, 10).value & ",N'" & my_po1 & "',N'" & my_work1 & "',N'" & my_color1 & "','" & my_thick1 & "')"
  1184. 'cmd.CommandText = sql
  1185. 'cmd.ExecuteScalar()
  1186. End If
  1187. Next
  1188. Next
  1189. sql = "SELECT order_no AS 订单号, i_no AS 指令号, color AS 颜色, thick AS 厚度, cast(SUM(sf) as numeric(10,1)) AS 尺数,deli_no as 发货单号 FROM RT_ship_daily_wh GROUP BY order_no, i_no, color, thick,deli_no ORDER BY 订单号, 指令号, 颜色"
  1190. cmd.CommandText = sql
  1191. dt = New DataTable
  1192. da.SelectCommand = cmd
  1193. da.Fill(dt)
  1194. dgv1.DataSource = dt
  1195. 'dt.Columns.Add("尺数")
  1196. 'dt.Columns.Add("货值")
  1197. sql = "SELECT 订单类别, 厚度, SUM(尺数) AS 尺数, 类别
  1198. FROM (SELECT CASE WHEN LEFT(order_no, 2)
  1199. = 'RT' THEN N'人民币' WHEN order_no LIKE 'SX%' THEN '美元' ELSE order_no END AS 订单类别,
  1200. i_no AS 指令号, color AS 颜色, thick AS 厚度, CAST(SUM(sf) AS numeric(10, 1)) AS 尺数,
  1201. CASE WHEN color LIKE '%pu%' OR
  1202. color LIKE '%action%' OR
  1203. color LIKE N'%纹%' THEN 'PU' ELSE '反毛' END AS 类别
  1204. FROM RT_ship_daily_wh
  1205. GROUP BY order_no, i_no, color, thick) AS p
  1206. GROUP BY 订单类别, 厚度, 类别
  1207. ORDER BY 订单类别"
  1208. cmd.CommandText = sql
  1209. dt = New DataTable
  1210. da.SelectCommand = cmd
  1211. da.Fill(dt)
  1212. dgv2.DataSource = dt
  1213. sql = "SELECT 订单类别, SUM(尺数) AS 尺数, 类别
  1214. FROM (SELECT CASE WHEN LEFT(order_no, 2)
  1215. = 'RT' THEN N'人民币' WHEN order_no LIKE 'SX%' THEN '美元' ELSE order_no END AS 订单类别,
  1216. i_no AS 指令号, color AS 颜色, thick AS 厚度, CAST(SUM(sf) AS numeric(10, 1)) AS 尺数,
  1217. CASE WHEN color LIKE '%pu%' OR
  1218. color LIKE '%action%' OR
  1219. color LIKE N'%纹%' THEN 'PU' ELSE '反毛' END AS 类别
  1220. FROM RT_ship_daily_wh
  1221. GROUP BY order_no, i_no, color, thick) AS p
  1222. GROUP BY 订单类别, 类别 ORDER BY 订单类别"
  1223. cmd.CommandText = sql
  1224. dt = New DataTable
  1225. da.SelectCommand = cmd
  1226. da.Fill(dt)
  1227. dgv3.DataSource = dt
  1228. ElseIf OpenFileDialog1.SafeFileName Like "SAMIL*" Then
  1229. sql = "delete from rt_ship_daily_samil"
  1230. cmd.CommandText = sql
  1231. cmd.ExecuteNonQuery()
  1232. Dim s1 As Integer = 1
  1233. 'For i = 1 To xlApp.Worksheets.Count
  1234. ' If xlApp.Workbooks(1).Worksheets(i).name = "0" Then
  1235. ' Exit For
  1236. ' End If
  1237. 'Next
  1238. xlSheet = xlApp.Workbooks(1).Worksheets(1)
  1239. xlSheet.Activate()
  1240. Dim y As Integer = 0
  1241. For y = 2 To xlApp.ActiveSheet.UsedRange.Rows.Count
  1242. If Len(xlSheet.Cells(y, 2).value) < 1 Then
  1243. Exit For
  1244. End If
  1245. Next y
  1246. xlApp.Range("A2:j" & y - 1).Select()
  1247. xlApp.Selection.UnMerge
  1248. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  1249. xlApp.CutCopyMode = False
  1250. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  1251. For y = 2 To y - 1
  1252. sql = "insert into rt_ship_daily_samil (serial,filename,card,no,name,qty,nw,gw,po_no) values('" & s1 & "',N'" & file_name & "','" & xlSheet.Cells(y, 6).value & "','" & xlSheet.Cells(y, 1).value & "',N'" & xlSheet.Cells(y, 2).value & "'," & xlSheet.Cells(y, 3).value & "," & xlSheet.Cells(y, 7).value & "," & xlSheet.Cells(y, 8).value & ",N'" & xlSheet.Cells(y, 9).value.ToString.Replace("'", "''") & "')"
  1253. cmd.CommandText = sql
  1254. cmd.ExecuteScalar()
  1255. Next
  1256. sql = "select 订单号,类别,cast(sum(数量) as numeric(10,1)) as 尺数,cast(sum(数量*单价) as numeric(10,3)) as 货值,sum(重量) as 净重,厚度 from
  1257. (SELECT po_no as 订单号,name as 品名,case when name like '%PU %' or name like '%action%' or name like N'%榔%' or name like N'%virgin%' then 'PU' else '反毛' end as 类别, qty as 数量,
  1258. cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度,unit_price as 单价
  1259. FROM RT_SHIP_DAILY_samil) as p group by 订单号,类别,厚度" '旧
  1260. sql = "select name as 品名,po_no as 订单号,cast(sum(qty) as numeric(10,1)) as 尺数,deli_no as 发货单号 from rt_ship_daily_samil group by name,po_no,deli_no"
  1261. cmd.CommandText = sql
  1262. dt = New DataTable
  1263. da.SelectCommand = cmd
  1264. da.Fill(dt)
  1265. dgv1.DataSource = dt
  1266. dgv1.Columns("品名").Width = 350
  1267. dgv1.Columns("订单号").Width = 180
  1268. sql = "select 类别,sum(尺数),sum(净重),sum(货值) from(select 订单号,类别,cast(sum(数量) as numeric(10,1)) as 尺数,cast(sum(数量*单价) as numeric(10,3)) as 货值,sum(重量) as 净重,厚度 from (SELECT po_no as 订单号,name as 品名,case when name like '%PU %' or name like '% action %' or name like N'%榔%' or name like N'% virgin %' then 'PU' else '反毛' end as 类别, qty as 数量,cast(qty/SUM(qty) OVER (PARTITION BY no) *nw as numeric(10,1)) as 重量,case when left(ltrim(name),3)='1.2' then left(ltrim(name),3) +'4' else '1.46' end as 厚度,unit_price as 单价 FROM RT_SHIP_DAILY_samil) as p group by 订单号,类别,厚度) as q group by 类别"
  1269. cmd.CommandText = sql
  1270. dt = New DataTable
  1271. da.SelectCommand = cmd
  1272. da.Fill(dt)
  1273. dgv2.DataSource = dt
  1274. ElseIf OpenFileDialog1.SafeFileName Like "宏福*" Then '-----------------PUMA
  1275. Dim conn1 As New SqlConnection
  1276. conn1.ConnectionString = connstring
  1277. conn1.Open()
  1278. Dim cmd1 As New SqlCommand
  1279. cmd1.Connection = conn1
  1280. Dim dr As SqlDataReader
  1281. sql = "delete from rt_ship_daily_puma"
  1282. cmd.CommandText = sql
  1283. cmd.ExecuteNonQuery()
  1284. For i = 1 To xlApp.Worksheets.Count
  1285. If xlApp.Workbooks(1).Worksheets(i).name = "1" Then
  1286. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  1287. xlSheet.Activate()
  1288. Exit For
  1289. End If
  1290. Next
  1291. Dim y As Integer = 0
  1292. For y = 4 To xlApp.ActiveSheet.UsedRange.Rows.Count
  1293. If Len(xlSheet.Cells(y, 2).value) < 1 Then
  1294. Exit For
  1295. End If
  1296. Next y
  1297. xlApp.Range("A4:v" & y - 1).Select()
  1298. 'If xlApp.Selection.mergecells = True Then
  1299. xlApp.Selection.UnMerge
  1300. xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  1301. xlApp.CutCopyMode = False
  1302. xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  1303. ' End If
  1304. For y = 4 To y - 1
  1305. sql = "insert into rt_ship_daily_puma (no,name,color,qty_sf,gw1,po_no,unit_price) values('" & xlSheet.Cells(y, 1).value & "',N'" & xlSheet.Cells(y, 2).value & "',N'" & xlSheet.Cells(y, 4).value & "'," & xlSheet.Cells(y, 5).value & "," & xlSheet.Cells(y, 12).value & ",N'" & xlSheet.Cells(y, 14).value & "',N'" & xlSheet.Cells(y, 20).value & "')"
  1306. cmd.CommandText = sql
  1307. cmd.ExecuteScalar()
  1308. Next
  1309. sql = "select name as 品名,cast(sum(qty_sf) as numeric(10,1)) as 尺数,cast(sum(qty_sf*unit_price) as numeric(10,2)) as 货值,po_no as 订单号,sum(重量) as 毛重, sum(袋重) as 袋重,sum(重量)-sum(袋重) as 净重 from
  1310. (select no,name,qty_sf,unit_price,po_no,gw1,cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no) *gw1 as numeric(10,2)) as 重量,cast(pa/SUM(pa) OVER (PARTITION BY no)*0.1 as numeric(10,2)) as 袋重 from
  1311. (select no,name,color,qty_sf,unit_price,po_no,gw1,cast(count as numeric(10,1)) as pa from
  1312. (SELECT no, name,case when name<>'' then 1 end as count, color, qty_sf, gw1, po_no, unit_price, cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no) *gw1 as numeric(10,1)) as weight
  1313. FROM RT_SHIP_DAILY_PUMA) as r) as s) as t group by name,po_no order by 品名,po_no"
  1314. cmd.CommandText = sql
  1315. dt = New DataTable
  1316. da.SelectCommand = cmd
  1317. da.Fill(dt)
  1318. dgv1.DataSource = dt
  1319. sql = "select 品名,sum(尺数) as 尺数,cast(sum(净重) as numeric(10,1)) as 淨重 from(select case when (品名 like '%PU%' or 品名 like '%action%' or 品名 like N'%榔%') and 品名 not like '%puma%' then 'pu' else '反毛' end as 品名,尺数,净重 from
  1320. (select name as 品名,cast(sum(qty_sf) as numeric(10,1)) as 尺数,cast(sum(qty_sf*unit_price) as numeric(10,2)) as 货值,po_no as 订单号,sum(重量) as 毛重, sum(袋重) as 袋重,sum(重量)-sum(袋重) as 净重 from
  1321. (select no,name,qty_sf,unit_price,po_no,gw1,cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no) *gw1 as numeric(10,2)) as 重量,cast(pa/SUM(pa) OVER (PARTITION BY no)*0.1 as numeric(10,3)) as 袋重 from
  1322. (select no,name,color,qty_sf,unit_price,po_no,gw1,cast(count as numeric(10,2)) as pa from
  1323. (SELECT no, name,case when name<>'' then 1 end as count, color, qty_sf, gw1, po_no, unit_price, cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no) *gw1 as numeric(10,2)) as weight
  1324. FROM RT_SHIP_DAILY_PUMA) as r) as s) as t group by name,po_no) as u) as v group by 品名"
  1325. cmd.CommandText = sql
  1326. dt = New DataTable
  1327. da.SelectCommand = cmd
  1328. da.Fill(dt)
  1329. dgv2.DataSource = dt
  1330. ' sql = "select name as 品名,cast(sum(qty_sf) as numeric(10,1)) as 尺数,cast(sum(qty_sf*unit_price) as numeric(10,1)) as 总价,sum(weight) as 淨重 from (SELECT no, name, color, qty_sf, gw1, po_no, unit_price, cast(qty_sf/SUM(qty_sf) OVER (PARTITION BY no) *gw1 as numeric(10,1)) as weight
  1331. 'FROM RT_SHIP_DAILY_PUMA) as p group by name"
  1332. ' cmd.CommandText = sql
  1333. ' dt = New DataTable
  1334. ' da.SelectCommand = cmd
  1335. ' da.Fill(dt)
  1336. 'sql = ""
  1337. 'cmd.CommandText = sql
  1338. 'dt = New DataTable
  1339. 'da.SelectCommand = cmd
  1340. 'da.Fill(dt)
  1341. 'dgv2.DataSource = dt
  1342. ElseIf OpenFileDialog1.SafeFileName Like "HATAY*" Then
  1343. ElseIf OpenFileDialog1.SafeFileName Like "穎億*" Then
  1344. sql = "delete from rt_ship_daily_yy"
  1345. cmd.CommandText = sql
  1346. cmd.ExecuteNonQuery()
  1347. For i = 1 To xlApp.Worksheets.Count
  1348. If xlApp.Workbooks(1).Worksheets(i).name = "0" Then
  1349. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  1350. xlSheet.Activate()
  1351. Exit For
  1352. End If
  1353. Next
  1354. Dim y As Integer = 0
  1355. For y = 2 To xlApp.ActiveSheet.UsedRange.Rows.Count
  1356. If Len(xlSheet.Cells(y, 2).value) < 1 Then
  1357. Exit For
  1358. End If
  1359. Next y
  1360. 'xlApp.Range("A2:k" & y - 1).Select()
  1361. ''If xlApp.Selection.mergecells = True Then
  1362. 'xlApp.Selection.UnMerge
  1363. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  1364. 'xlApp.CutCopyMode = False
  1365. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  1366. For y = 2 To y - 1
  1367. sql = "insert into rt_ship_daily_yy (filename,no,name,pcs,qty,unit,
  1368. nw,gw,po_no,work_no,supplier,coin) values(N'" & file_name & "','" &
  1369. xlSheet.Cells(y, 1).value & "',N'" & xlSheet.Cells(y, 2).value & "','" & xlSheet.Cells(y, 3).value & "','" & xlSheet.Cells(y, 4).value & "','" &
  1370. xlSheet.Cells(y, 5).value & "','" & xlSheet.Cells(y, 6).value & "','" & xlSheet.Cells(y, 7).value & "','" &
  1371. xlSheet.Cells(y, 8).value & "','" & xlSheet.Cells(y, 9).value & "',N'" & xlSheet.Cells(y, 10).value & "','" &
  1372. xlSheet.Cells(y, 11).value & "')"
  1373. cmd.CommandText = sql
  1374. cmd.ExecuteScalar()
  1375. Next
  1376. sql = "select name as 品名,cast(sum(qty) as numeric(10,1)) as 尺数,po_no as 订单号,work_no as 指令号,deli_no as 发货单号 from rt_ship_daily_yy group by name,po_no,work_no,deli_no"
  1377. cmd.CommandText = sql
  1378. dt = New DataTable
  1379. da.SelectCommand = cmd
  1380. da.Fill(dt)
  1381. dgv1.DataSource = dt
  1382. dgv1.Columns("品名").Width = 350
  1383. dgv1.Columns("指令号").Width = 250
  1384. ElseIf OpenFileDialog1.SafeFileName Like "澳孚*" Then
  1385. sql = "delete from rt_ship_daily_af"
  1386. cmd.CommandText = sql
  1387. cmd.ExecuteNonQuery()
  1388. xlSheet = xlApp.Workbooks(1).Worksheets(1)
  1389. Dim y As Integer = 0
  1390. For y = 2 To xlApp.Workbooks(1).Worksheets(1).UsedRange.Rows.Count
  1391. If Len(xlSheet.Cells(y, 2).value) < 1 Then
  1392. Exit For
  1393. End If
  1394. Next y
  1395. xlApp.Range("A2:l" & y - 1).Select()
  1396. ' If xlApp.Selection.mergecells = True Then
  1397. xlApp.Selection.UnMerge
  1398. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  1399. 'xlApp.CutCopyMode = False
  1400. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  1401. ' End If
  1402. Dim my_no As String
  1403. Dim my_nw As Double
  1404. Dim my_gw As Double
  1405. Dim my_sf As Double
  1406. Dim my_price As Double
  1407. Dim s1 As Integer = 0
  1408. For y = 2 To y - 1
  1409. If Not (xlSheet.Cells(y, 9).value Is Nothing) Then
  1410. If (xlSheet.Cells(y, 5).value Is Nothing) And (xlSheet.Cells(y, 6).value Is Nothing) Then
  1411. my_nw = xlSheet.Cells(y - 1, 5).value
  1412. my_gw = xlSheet.Cells(y - 1, 6).value
  1413. my_no = xlSheet.Cells(y - 1, 1).value
  1414. Else
  1415. my_nw = xlSheet.Cells(y, 5).value
  1416. my_gw = xlSheet.Cells(y, 6).value
  1417. my_no = xlSheet.Cells(y, 1).value
  1418. End If
  1419. my_sf = xlSheet.Cells(y, 3).value
  1420. my_price = xlSheet.Cells(y, 11).value
  1421. sql = "insert into rt_ship_daily_af (filename,serial,no,name,qty_sf,nw,gw,
  1422. po_no,work_no,unit_price) values(N'" & file_name & "','" & s1 & "','" &
  1423. my_no & "',N'" & xlSheet.Cells(y, 2).value & "'," & my_sf & "," & my_nw & "," & my_gw & ",N'" &
  1424. xlSheet.Cells(y, 8).value & "','" & xlSheet.Cells(y, 9).value & "','" & my_price & "')"
  1425. cmd.CommandText = sql
  1426. cmd.ExecuteScalar()
  1427. End If
  1428. Next
  1429. sql = "select 品名,po_no as 订购单号,厚度,cast(sum(qty_sf) as numeric(10,1)) as 尺数,cast(sum(unit_price*qty_sf)/sum(qty_sf) as numeric(10,2)) as 单价,cast(sum(unit_price*qty_sf) as numeric(10,2)) as 货值,sum(净重) as 净重 from
  1430. (SELECT no, case when (name like '%PU%' or name like '%action%' or name like N'%榔%') AND name NOT LIKE '%tpu%' then N'贴膜' else '反毛' end as 品名, nw, gw, po_no, qty_sf, unit_price,case when name like '%1.2%' then '1.24'
  1431. when name like '%1.4%' then '1.46' else '1.24' end as 厚度,cast(qty_sf/sum(qty_sf) over (partition by no) *nw as numeric(10,1)) as 净重 FROM rt_ship_daily_af) as p group by 品名,po_no,厚度" '旧
  1432. sql = "select name as 品名,po_no as 订单号,work_no as 指令号,sum(qty_sf) as 尺数,deli_no as 发货单号 from rt_ship_daily_af group by name,po_no,work_no,deli_no"
  1433. cmd.CommandText = sql
  1434. dt = New DataTable
  1435. da.SelectCommand = cmd
  1436. da.Fill(dt)
  1437. dgv1.DataSource = dt
  1438. dgv1.Columns("品名").Width = 250
  1439. dgv1.Columns("指令号").Width = 150
  1440. ' sql = "select 品名,颜色,厚度,sum(尺数) as 尺数,sum(货值) as 货值,sum(净重) as 净重 from (select 品名,颜色,po_no as 订购单号,厚度,sum(qty_sf1) as 尺数,sum(unit_price*qty_sf1)/sum(qty_sf1) as 单价,sum(unit_price*qty_sf1) as 货值,sum(净重) as 净重 from
  1441. '(SELECT no, case when (name like '%PU%' or name like '%action%' or name like N'%榔%') and name not like '%tpu%' then N'贴膜' else '反毛' end as 品名, case when name like '%黑色%' then '黑色' else '其他' end as 颜色, nw, gw, po_no, qty_sf, unit_price,case when name like '%1.2%' then '1.24' when name like '%1.4%' then '1.46' else '1.24' end as 厚度,cast(qty_sf1/sum(qty_sf1) over (partition by no) *nw as numeric(10,1)) as 净重
  1442. 'FROM rt_ship_daily_sj) as p group by 品名,po_no,厚度,颜色) as q group by 品名,颜色,厚度 order by 品名"
  1443. ' cmd.CommandText = sql
  1444. ' dt = New DataTable
  1445. ' da.SelectCommand = cmd
  1446. ' da.Fill(dt)
  1447. ' dgv2.DataSource = dt
  1448. ' sql = "select 品名,颜色,sum(尺数) as 尺数,sum(货值) as 货值,sum(净重) as 净重 from (select 品名,颜色,po_no as 订购单号,厚度,cast(sum(qty_sf1) as numeric(10,1)) as 尺数,cast(sum(unit_price*qty_sf1)/sum(qty_sf1) as numeric(10,2)) as 单价,cast(sum(unit_price*qty_sf1) as numeric(10,2)) as 货值,sum(净重) as 净重 from
  1449. '(SELECT no, case when (name like '%PU%' or name like '%action%' or name like N'%榔%') and name not like '%tpu%' then N'贴膜' else '反毛' end as 品名, case when name like '%黑色%' then '黑色' else '其他' end as 颜色, nw, gw, po_no, qty_sf1, unit_price,case when name like '%1.2%' then '1.24' when name like '%1.4%' then '1.46' else '1.24' end as 厚度,cast(qty_sf1/sum(qty_sf1) over (partition by no) *nw as numeric(10,1)) as 净重
  1450. 'FROM rt_ship_daily_sj) as p group by 品名,po_no,厚度,颜色) as q group by 品名,颜色 order by 品名"
  1451. ' cmd.CommandText = sql
  1452. ' dt = New DataTable
  1453. ' da.SelectCommand = cmd
  1454. ' da.Fill(dt)
  1455. ' dgv3.DataSource = dt
  1456. ElseIf OpenFileDialog1.SafeFileName Like "极路客*" Then '--------------------------------------------极路客
  1457. sql = "delete from rt_ship_daily_jlk"
  1458. cmd.CommandText = sql
  1459. cmd.ExecuteNonQuery()
  1460. Dim s1 As Integer = 1
  1461. Dim s11 As Integer = 1001
  1462. For i = 1 To xlApp.Worksheets.Count
  1463. xlSheet = xlApp.Worksheets(i)
  1464. xlSheet.Activate()
  1465. Dim y As Integer
  1466. For y = xlApp.Workbooks(1).Worksheets(i).UsedRange.Rows.Count To 3 Step -1
  1467. If xlSheet.Cells(y, 1).value = Nothing Then
  1468. GoTo OK3
  1469. End If
  1470. If xlSheet.Cells(y, 1).value.ToString = "重量总计:" Then
  1471. Exit For
  1472. End If
  1473. Next y
  1474. OK3:
  1475. Dim yyy As Integer
  1476. For yyy = 3 To xlApp.Workbooks(1).Worksheets(i).UsedRange.Rows.Count
  1477. If xlSheet.Cells(yyy, 10).value = "数量总计:" Then
  1478. Exit For
  1479. End If
  1480. Next yyy
  1481. xlSheet.Range("A4:A" & y - 1).Select()
  1482. xlApp.Selection.UnMerge
  1483. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  1484. 'xlApp.CutCopyMode = False
  1485. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  1486. xlSheet.Range("d4:e" & y - 1).Select()
  1487. xlApp.Selection.UnMerge
  1488. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  1489. 'xlApp.CutCopyMode = False
  1490. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  1491. xlSheet.Range("j3:k" & yyy - 1).Select()
  1492. xlApp.Selection.UnMerge
  1493. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  1494. 'xlApp.CutCopyMode = False
  1495. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  1496. 'If xlSheet.Range("N3:Q" & yyy - 1).MergeCells.ToString <> "False" Then
  1497. ' xlSheet.Range("N3:Q" & yyy - 1).Select()
  1498. ' xlApp.Selection.UnMerge
  1499. ' 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  1500. ' 'xlApp.CutCopyMode = False
  1501. ' 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  1502. 'End If
  1503. Dim my_no As String
  1504. Dim my_po As String
  1505. Dim my_work As String
  1506. Dim my_color As String
  1507. Dim my_thick As String
  1508. Dim my_no1 As String
  1509. Dim my_po1 As String
  1510. Dim my_work1 As String
  1511. Dim my_color1 As String
  1512. Dim my_thick1 As String
  1513. Dim my_card As String
  1514. For y = 4 To y - 1
  1515. If y = 4 Then
  1516. my_no = xlSheet.Cells(y, 1).value
  1517. my_color = xlSheet.Cells(y, 4).value
  1518. my_thick = xlSheet.Cells(y, 5).value
  1519. my_no1 = xlSheet.Cells(y, 7).value
  1520. my_color1 = xlSheet.Cells(y, 10).value
  1521. my_thick1 = xlSheet.Cells(y, 11).value
  1522. End If
  1523. If xlSheet.Cells(y, 2).value = Nothing And xlSheet.Cells(y, 4).value = Nothing And xlSheet.Cells(y, 5).value = Nothing Then
  1524. ' Exit For
  1525. Else
  1526. If xlSheet.Cells(y, 2).value Is Nothing Then
  1527. Else
  1528. If xlSheet.Cells(y, 1).value Is Nothing Then
  1529. Else
  1530. my_no = xlSheet.Cells(y, 1).value
  1531. End If
  1532. If xlSheet.Cells(y, 4).value Is Nothing And xlSheet.Cells(y, 5).value Is Nothing Then
  1533. Else
  1534. my_color = xlSheet.Cells(y, 4).value
  1535. my_thick = xlSheet.Cells(y, 5).value
  1536. End If
  1537. sql = "insert into rt_ship_daily_jlk (filename,card,serial,no,qty,color,thick) values(N'" &
  1538. file_name & "','" & xlSheet.Cells(y, 3).value & "','" & s1 & "','" & my_no & "','" & xlSheet.Cells(y, 2).value & "',N'" & my_color & "','" & my_thick & "')"
  1539. cmd.CommandText = sql
  1540. cmd.ExecuteScalar()
  1541. s1 = s1 + 1
  1542. End If
  1543. End If
  1544. If xlSheet.Cells(y, 8).value = Nothing And xlSheet.Cells(y, 10).value = Nothing And xlSheet.Cells(y, 11).value = Nothing Then
  1545. ' Exit For
  1546. Else
  1547. If xlSheet.Cells(y, 8).value Is Nothing Then
  1548. Else
  1549. If xlSheet.Cells(y, 7).value Is Nothing Then
  1550. Else
  1551. my_no1 = xlSheet.Cells(y, 7).value
  1552. End If
  1553. If xlSheet.Cells(y, 10).value Is Nothing And xlSheet.Cells(y, 11).value Is Nothing Then
  1554. Else
  1555. my_color1 = xlSheet.Cells(y, 10).value
  1556. my_thick1 = xlSheet.Cells(y, 11).value
  1557. End If
  1558. sql = "insert into rt_ship_daily_jlk (filename,card,serial,no,qty,color,thick) values(N'" &
  1559. file_name & "','" & xlSheet.Cells(y, 9).value & "','" & s11 & "','" & my_no1 & "','" & xlSheet.Cells(y, 8).value & "',N'" & my_color1 & "','" & my_thick1 & "')"
  1560. cmd.CommandText = sql
  1561. cmd.ExecuteScalar()
  1562. s11 = s11 + 1
  1563. End If
  1564. End If
  1565. Next
  1566. Next
  1567. sql = "SELECT color as 颜色,thick as 厚度,sum(qty) as 尺数,DELE_NO AS 发货单号 from rt_ship_daily_jlk group by color,thick,DELI_NO "
  1568. cmd.CommandText = sql
  1569. dt = New DataTable
  1570. da.SelectCommand = cmd
  1571. da.Fill(dt)
  1572. dgv1.DataSource = dt
  1573. 'dt.Columns.Add("尺数")
  1574. 'dt.Columns.Add("货值")
  1575. ' sql = "SELECT 订单类别, 厚度, SUM(尺数) AS 尺数, 类别
  1576. 'FROM (SELECT CASE WHEN LEFT(order_no, 2)
  1577. ' = 'RT' THEN N'人民币' WHEN order_no LIKE 'SX%' THEN '美元' ELSE order_no END AS 订单类别,
  1578. ' i_no AS 指令号, color AS 颜色, thick AS 厚度, CAST(SUM(sf) AS numeric(10, 1)) AS 尺数,
  1579. ' CASE WHEN color LIKE '%pu%' OR
  1580. ' color LIKE '%action%' OR
  1581. ' color LIKE N'%纹%' THEN 'PU' ELSE '反毛' END AS 类别
  1582. ' FROM RT_ship_daily_wh
  1583. ' GROUP BY order_no, i_no, color, thick) AS p
  1584. 'GROUP BY 订单类别, 厚度, 类别
  1585. 'ORDER BY 订单类别"
  1586. ' cmd.CommandText = sql
  1587. ' dt = New DataTable
  1588. ' da.SelectCommand = cmd
  1589. ' da.Fill(dt)
  1590. ' dgv2.DataSource = dt
  1591. ' sql = "SELECT 订单类别, SUM(尺数) AS 尺数, 类别
  1592. 'FROM (SELECT CASE WHEN LEFT(order_no, 2)
  1593. ' = 'RT' THEN N'人民币' WHEN order_no LIKE 'SX%' THEN '美元' ELSE order_no END AS 订单类别,
  1594. ' i_no AS 指令号, color AS 颜色, thick AS 厚度, CAST(SUM(sf) AS numeric(10, 1)) AS 尺数,
  1595. ' CASE WHEN color LIKE '%pu%' OR
  1596. ' color LIKE '%action%' OR
  1597. ' color LIKE N'%纹%' THEN 'PU' ELSE '反毛' END AS 类别
  1598. ' FROM RT_ship_daily_wh
  1599. ' GROUP BY order_no, i_no, color, thick) AS p
  1600. 'GROUP BY 订单类别, 类别 ORDER BY 订单类别"
  1601. ' cmd.CommandText = sql
  1602. ' dt = New DataTable
  1603. ' da.SelectCommand = cmd
  1604. ' da.Fill(dt)
  1605. ' dgv3.DataSource = dt
  1606. ElseIf OpenFileDialog1.SafeFileName Like "HATAY*" Then
  1607. ElseIf OpenFileDialog1.SafeFileName Like "DCLASE*" Then
  1608. ElseIf OpenFileDialog1.SafeFileName Like "078*" Then
  1609. ElseIf OpenFileDialog1.SafeFileName Like "076发货*" Then '------------------------金威利
  1610. sql = "delete from rt_ship_076_1"
  1611. cmd.CommandText = sql
  1612. cmd.ExecuteNonQuery()
  1613. Dim my_total_weight As Double = 0
  1614. Dim s1 As Integer = 1
  1615. Dim s11 As Integer = 1001
  1616. For i = 1 To xlApp.Worksheets.Count
  1617. xlSheet = xlApp.Worksheets(i)
  1618. xlSheet.Activate()
  1619. Dim y As Integer
  1620. For y = xlApp.Workbooks(1).Worksheets(i).UsedRange.Rows.Count To 3 Step -1
  1621. If xlSheet.Cells(y, 1).value = Nothing Then
  1622. If xlSheet.Cells(y, 2).value = "重量" Then
  1623. End If
  1624. GoTo OK
  1625. End If
  1626. If xlSheet.Cells(y, 1).value.ToString = "数量合计" Then
  1627. Exit For
  1628. End If
  1629. OK:
  1630. Next y
  1631. Dim yyy As Integer
  1632. For yyy = 3 To xlApp.Workbooks(1).Worksheets(i).UsedRange.Rows.Count
  1633. If xlSheet.Cells(yyy, 14).value = "制 表" Then
  1634. Exit For
  1635. End If
  1636. Next yyy
  1637. If xlSheet.Cells(y + 2, 2).value Like "重量*" Then
  1638. Dim q() As String
  1639. Dim r() As String
  1640. q = Split(xlSheet.Cells(y + 2, 2).value, "重量")
  1641. r = Split(q(1), "KG")
  1642. If IsNumeric(r(0)) Then
  1643. Else
  1644. r = Split(q(1), "kg")
  1645. If IsNumeric(r(0)) Then
  1646. Else
  1647. r = Split(q(1), "Kg")
  1648. End If
  1649. End If
  1650. 'my_total_weight = r(0)
  1651. End If
  1652. xlSheet.Range("A3:A" & y - 1).Select()
  1653. xlApp.Selection.UnMerge
  1654. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  1655. 'xlApp.CutCopyMode = False
  1656. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  1657. xlSheet.Range("c3:g" & y - 1).Select()
  1658. xlApp.Selection.UnMerge
  1659. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  1660. 'xlApp.CutCopyMode = False
  1661. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  1662. xlSheet.Range("N3:Q" & yyy - 1).Select()
  1663. xlApp.Selection.UnMerge
  1664. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  1665. 'xlApp.CutCopyMode = False
  1666. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  1667. If xlSheet.Range("K3:L" & yyy - 1).MergeCells.ToString <> "False" Then
  1668. xlSheet.Range("K3:L" & yyy - 1).Select()
  1669. xlApp.Selection.UnMerge
  1670. 'xlApp.Selection.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeBlanks).Select
  1671. 'xlApp.CutCopyMode = False
  1672. 'xlApp.Selection.FormulaR1C1 = "=R[-1]C"
  1673. End If
  1674. Dim my_card As String
  1675. Dim my_no As String
  1676. Dim my_po As String
  1677. Dim my_work As String
  1678. Dim my_color As String
  1679. Dim my_thick As String
  1680. Dim my_no1 As String
  1681. Dim my_po1 As String
  1682. Dim my_work1 As String
  1683. Dim my_color1 As String
  1684. Dim my_thick1 As String
  1685. For y = 3 To y - 1
  1686. If xlSheet.Cells(y, 2).value = Nothing And xlSheet.Cells(y, 4).value = Nothing And xlSheet.Cells(y, 5).value = Nothing And xlSheet.Cells(y, 6).value = Nothing And xlSheet.Cells(y, 7).value = Nothing Then
  1687. ' Exit For
  1688. Else
  1689. If xlSheet.Cells(y, 2).value Is Nothing Then
  1690. Else
  1691. If xlSheet.Cells(y, 4).VALUE Is Nothing Then
  1692. If xlSheet.Cells(y, 1).value Is Nothing Then
  1693. Else
  1694. my_no = xlSheet.Cells(y, 1).value
  1695. End If
  1696. sql = "insert into rt_ship_076_1 (filename,card,serial,no,sf,order_no,i_no,color,thick) values(N'" & file_name & "','" & xlSheet.Cells(y, 3).value & "','" & s1 & "','" & my_no & "'," & xlSheet.Cells(y, 2).value & ",N'" & my_po & "',N'" & my_work & "',N'" & my_color & "','" & my_thick & "')"
  1697. cmd.CommandText = sql
  1698. cmd.ExecuteScalar()
  1699. s1 = s1 + 1
  1700. Else
  1701. If xlSheet.Cells(y, 1).value Is Nothing Then
  1702. Else
  1703. my_no = xlSheet.Cells(y, 1).value
  1704. End If
  1705. my_po = xlSheet.Cells(y, 4).value
  1706. my_work = xlSheet.Cells(y, 5).value
  1707. my_color = xlSheet.Cells(y, 6).value
  1708. my_thick = xlSheet.Cells(y, 7).value
  1709. sql = "insert into rt_ship_076_1 (filename,card,serial,no,sf,order_no,i_no,color,thick) values(N'" & file_name & "','" & xlSheet.Cells(y, 3).value & "','" & s1 & "','" & my_no & "'," & xlSheet.Cells(y, 2).value & ",N'" & my_po & "',N'" & my_work & "',N'" & my_color & "','" & my_thick & "')"
  1710. cmd.CommandText = sql
  1711. cmd.ExecuteScalar()
  1712. s1 = s1 + 1
  1713. End If
  1714. End If
  1715. End If
  1716. If xlSheet.Cells(y, 12).value = Nothing And xlSheet.Cells(y, 14).value = Nothing And xlSheet.Cells(y, 15).value = Nothing And xlSheet.Cells(y, 16).value = Nothing And xlSheet.Cells(y, 17).value = Nothing Then
  1717. ' Exit For
  1718. Else
  1719. If xlSheet.Cells(y, 12).value Is Nothing Then
  1720. Else
  1721. If xlSheet.Cells(y, 14).VALUE Is Nothing Then
  1722. If xlSheet.Cells(y, 11).value Is Nothing Then
  1723. Else
  1724. my_no1 = xlSheet.Cells(y, 11).value
  1725. End If
  1726. sql = "insert into rt_ship_076_1 (filename,card,serial,no,sf,order_no,i_no,color,thick) values(N'" & file_name & "','" & xlSheet.Cells(y, 13).value & "','" & s11 & "','" & my_no1 & "'," & xlSheet.Cells(y, 12).value & ",N'" & my_po1 & "',N'" & my_work1 & "',N'" & my_color1 & "','" & my_thick1 & "')"
  1727. cmd.CommandText = sql
  1728. cmd.ExecuteScalar()
  1729. s11 = s11 + 1
  1730. Else
  1731. If xlSheet.Cells(y, 11).value Is Nothing Then
  1732. Else
  1733. my_no1 = xlSheet.Cells(y, 11).value
  1734. End If
  1735. my_po1 = xlSheet.Cells(y, 14).value
  1736. my_work1 = xlSheet.Cells(y, 15).value
  1737. my_color1 = xlSheet.Cells(y, 16).value
  1738. my_thick1 = xlSheet.Cells(y, 17).value
  1739. sql = "insert into rt_ship_076_1 (filename,card,serial,no,sf,order_no,i_no,color,thick) values(N'" & file_name & "','" & xlSheet.Cells(y, 13).value & "','" & s11 & "','" & my_no1 & "'," & xlSheet.Cells(y, 12).value & ",N'" & my_po1 & "',N'" & my_work1 & "',N'" & my_color1 & "','" & my_thick1 & "')"
  1740. cmd.CommandText = sql
  1741. cmd.ExecuteScalar()
  1742. s11 = s11 + 1
  1743. End If
  1744. End If
  1745. 'sql = "insert into rt_ship_076_1 (no,sf,order_no,i_no,color,thick) values('" & my_no1 & "'," & xlSheet.Cells(y, 10).value & ",N'" & my_po1 & "',N'" & my_work1 & "',N'" & my_color1 & "','" & my_thick1 & "')"
  1746. 'cmd.CommandText = sql
  1747. 'cmd.ExecuteScalar()
  1748. End If
  1749. Next
  1750. Next
  1751. sql = "insert into rt_ship_temp select * from rt_ship_076_1"
  1752. cmd.CommandText = sql
  1753. cmd.ExecuteNonQuery()
  1754. sql = "SELECT order_no AS 订单号, i_no AS 指令号, color AS 颜色, thick AS 厚度, cast(SUM(sf) as numeric(10,1)) AS 尺数,DELI_NO AS 发货单号 FROM RT_ship_076_1 GROUP BY order_no, i_no, color, thick,DELI_NO "
  1755. cmd.CommandText = sql
  1756. dt = New DataTable
  1757. da.SelectCommand = cmd
  1758. da.Fill(dt)
  1759. dt.Columns.Add("发货单号")
  1760. dgv1.DataSource = dt
  1761. 'dt.Columns.Add("货值")
  1762. sql = "SELECT 订单类别, 厚度, SUM(尺数) AS 尺数, 类别
  1763. FROM (SELECT CASE WHEN LEFT(order_no, 2)
  1764. = 'RT' THEN N'人民币' WHEN order_no LIKE 'SX%' THEN '美元' ELSE order_no END AS 订单类别,
  1765. i_no AS 指令号, color AS 颜色, thick AS 厚度, CAST(SUM(sf) AS numeric(10, 1)) AS 尺数,
  1766. CASE WHEN color LIKE '%pu%' OR
  1767. color LIKE '%action%' OR
  1768. color LIKE N'%纹%' THEN 'PU' ELSE '反毛' END AS 类别
  1769. FROM RT_ship_076_1
  1770. GROUP BY order_no, i_no, color, thick) AS p
  1771. GROUP BY 订单类别, 厚度, 类别
  1772. ORDER BY 订单类别"
  1773. cmd.CommandText = sql
  1774. dt = New DataTable
  1775. da.SelectCommand = cmd
  1776. da.Fill(dt)
  1777. dgv2.DataSource = dt
  1778. sql = "SELECT 订单类别, SUM(尺数) AS 尺数, 类别
  1779. FROM (SELECT CASE WHEN LEFT(order_no, 2)
  1780. = 'RT' THEN N'人民币' WHEN order_no LIKE 'SX%' THEN '美元' ELSE order_no END AS 订单类别,
  1781. i_no AS 指令号, color AS 颜色, thick AS 厚度, CAST(SUM(sf) AS numeric(10, 1)) AS 尺数,
  1782. CASE WHEN color LIKE '%pu%' OR
  1783. color LIKE '%action%' OR
  1784. color LIKE N'%纹%' THEN 'PU' ELSE '反毛' END AS 类别
  1785. FROM RT_ship_076_1
  1786. GROUP BY order_no, i_no, color, thick) AS p
  1787. GROUP BY 订单类别, 类别 ORDER BY 订单类别"
  1788. cmd.CommandText = sql
  1789. dt = New DataTable
  1790. da.SelectCommand = cmd
  1791. da.Fill(dt)
  1792. dgv3.DataSource = dt
  1793. For rr As Integer = 0 To dt.Rows.Count - 1
  1794. 'sql = ""
  1795. 'cmd.CommandText = sql
  1796. 'dt.Rows(rr).Item("尺数") = cmd.ExecuteScalar
  1797. Next
  1798. For rr As Integer = 0 To dt.Rows.Count - 1
  1799. 'sql = ""
  1800. 'cmd.CommandText = sql
  1801. 'dt.Rows(rr).Item("货值") = cmd.ExecuteScalar
  1802. Next
  1803. 'DataGridView1.DataSource = dt
  1804. Else
  1805. MsgBox("找不到相对应的模组")
  1806. End If
  1807. xlApp.Visible = True
  1808. xlSheet = Nothing '釋放sheet物件
  1809. ' xlApp.Quit() '關閉Excel
  1810. xlApp = Nothing
  1811. MsgBox("作业完成")
  1812. End Sub
  1813. Private Sub Frm_BG_main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  1814. conn.ConnectionString = connstring
  1815. conn.Open()
  1816. cmd.Connection = conn
  1817. sql = "select filename from rt_ship_076_1 group by filename"
  1818. cmd.CommandText = sql
  1819. If Not (cmd.ExecuteScalar Is Nothing) Then
  1820. ListBox3.Items.Add(cmd.ExecuteScalar)
  1821. End If
  1822. sql = "select filename from rt_ship_daily_af group by filename"
  1823. cmd.CommandText = sql
  1824. If Not (cmd.ExecuteScalar Is Nothing) Then
  1825. ListBox3.Items.Add(cmd.ExecuteScalar)
  1826. End If
  1827. sql = "select filename from rt_ship_daily_evergree group by filename"
  1828. cmd.CommandText = sql
  1829. If Not (cmd.ExecuteScalar Is Nothing) Then
  1830. ListBox3.Items.Add(cmd.ExecuteScalar)
  1831. End If
  1832. 'sql = "select filename from rt_ship_daily_jh group by filename"
  1833. 'cmd.CommandText = sql
  1834. 'If Not (cmd.ExecuteScalar Is Nothing) Then
  1835. ' ListBox3.Items.Add(cmd.ExecuteScalar)
  1836. 'End If
  1837. sql = "select filename from rt_ship_daily_jlk group by filename"
  1838. cmd.CommandText = sql
  1839. If Not (cmd.ExecuteScalar Is Nothing) Then
  1840. ListBox3.Items.Add(cmd.ExecuteScalar)
  1841. End If
  1842. sql = "select filename from rt_ship_daily_properwell group by filename"
  1843. cmd.CommandText = sql
  1844. If Not (cmd.ExecuteScalar Is Nothing) Then
  1845. ListBox3.Items.Add(cmd.ExecuteScalar)
  1846. End If
  1847. 'sql = "select filename from rt_ship_daily_puma group by filename"
  1848. 'cmd.CommandText = sql
  1849. 'If Not (cmd.ExecuteScalar Is Nothing) Then
  1850. ' ListBox3.Items.Add(cmd.ExecuteScalar)
  1851. 'End If
  1852. sql = "select filename from rt_ship_daily_ruiqi group by filename"
  1853. cmd.CommandText = sql
  1854. If Not (cmd.ExecuteScalar Is Nothing) Then
  1855. ListBox3.Items.Add(cmd.ExecuteScalar)
  1856. End If
  1857. sql = "select filename from rt_ship_daily_samil group by filename"
  1858. cmd.CommandText = sql
  1859. If Not (cmd.ExecuteScalar Is Nothing) Then
  1860. ListBox3.Items.Add(cmd.ExecuteScalar)
  1861. End If
  1862. sql = "select filename from rt_ship_daily_sj group by filename"
  1863. cmd.CommandText = sql
  1864. If Not (cmd.ExecuteScalar Is Nothing) Then
  1865. ListBox3.Items.Add(cmd.ExecuteScalar)
  1866. End If
  1867. sql = "select filename from rt_ship_daily_stella group by filename"
  1868. cmd.CommandText = sql
  1869. If Not (cmd.ExecuteScalar Is Nothing) Then
  1870. ListBox3.Items.Add(cmd.ExecuteScalar)
  1871. End If
  1872. sql = "select filename from rt_ship_daily_thanhhu group by filename"
  1873. cmd.CommandText = sql
  1874. If Not (cmd.ExecuteScalar Is Nothing) Then
  1875. ListBox3.Items.Add(cmd.ExecuteScalar)
  1876. End If
  1877. sql = "select filename from rt_ship_daily_uz_1 group by filename"
  1878. cmd.CommandText = sql
  1879. If Not (cmd.ExecuteScalar Is Nothing) Then
  1880. ListBox3.Items.Add(cmd.ExecuteScalar)
  1881. End If
  1882. sql = "select filename from rt_ship_daily_wh group by filename"
  1883. cmd.CommandText = sql
  1884. If Not (cmd.ExecuteScalar Is Nothing) Then
  1885. ListBox3.Items.Add(cmd.ExecuteScalar)
  1886. End If
  1887. sql = "select filename from rt_ship_daily_xbh group by filename"
  1888. cmd.CommandText = sql
  1889. If Not (cmd.ExecuteScalar Is Nothing) Then
  1890. ListBox3.Items.Add(cmd.ExecuteScalar)
  1891. End If
  1892. sql = "select filename from rt_ship_daily_yb group by filename"
  1893. cmd.CommandText = sql
  1894. If Not (cmd.ExecuteScalar Is Nothing) Then
  1895. ListBox3.Items.Add(cmd.ExecuteScalar)
  1896. End If
  1897. sql = "select filename from rt_ship_daily_yby group by filename"
  1898. cmd.CommandText = sql
  1899. If Not (cmd.ExecuteScalar Is Nothing) Then
  1900. ListBox3.Items.Add(cmd.ExecuteScalar)
  1901. End If
  1902. sql = "select filename from rt_ship_daily_yby_huasheng group by filename"
  1903. cmd.CommandText = sql
  1904. If Not (cmd.ExecuteScalar Is Nothing) Then
  1905. ListBox3.Items.Add(cmd.ExecuteScalar)
  1906. End If
  1907. sql = "select filename from rt_ship_daily_yy group by filename"
  1908. cmd.CommandText = sql
  1909. If Not (cmd.ExecuteScalar Is Nothing) Then
  1910. ListBox3.Items.Add(cmd.ExecuteScalar)
  1911. End If
  1912. End Sub
  1913. Private Sub DataGridView2_MouseUp(sender As Object, e As MouseEventArgs) Handles dgv2.MouseUp
  1914. Dim x As Double = 0
  1915. Dim y As Double = 0
  1916. Dim z As Double = 0
  1917. Dim a As Int16 = 0
  1918. Dim b As Double = 0
  1919. For i As Integer = 0 To dgv2.SelectedRows.Count - 1
  1920. x = x + Math.Round(dgv2.Rows(dgv2.SelectedRows.Item(i).Index).Cells("尺数").Value, 2)
  1921. y = y + Math.Round(dgv2.Rows(dgv2.SelectedRows.Item(i).Index).Cells("货值").Value, 2)
  1922. z = z + Math.Round(dgv2.Rows(dgv2.SelectedRows.Item(i).Index).Cells("净重").Value, 2)
  1923. a = a + dgv2.Rows(dgv2.SelectedRows.Item(i).Index).Cells("件数").Value
  1924. b = b + Math.Round(dgv2.Rows(dgv2.SelectedRows.Item(i).Index).Cells("毛重").Value, 2)
  1925. Next i
  1926. TextBox3.Text = dgv2.SelectedRows.Count
  1927. TextBox2.Text = x
  1928. TextBox1.Text = y
  1929. TextBox4.Text = z
  1930. TextBox5.Text = a
  1931. TextBox6.Text = b
  1932. End Sub
  1933. Private Sub Button23_Click(sender As Object, e As EventArgs) Handles Button23.Click '---报关进口汇总
  1934. sql = "SELECT DATE1 AS 报关日期, Date2 AS 进厂日期, MONTH(Date2) AS 进厂月份, XNO AS 手册号, NAME AS 海关分类,type as 进口类型,matl_name AS 品名, QTY AS 数量, PRICE AS 单价, price*qty as 货值, ORIGIN AS 产地 FROM RT_BG_IN_DETAIL WHERE date2 between '" & dtp1.Value & "' and '" & dtp2.Value & "'"
  1935. cmd.CommandText = sql
  1936. da.SelectCommand = cmd
  1937. Dim dt1 As New DataTable
  1938. da.Fill(dt1)
  1939. If dt1.Rows.Count = 0 Then
  1940. MsgBox("查无记录")
  1941. Exit Sub
  1942. End If
  1943. dgv1.DataSource = dt1
  1944. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  1945. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  1946. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  1947. Dim xlRange As Microsoft.Office.Interop.Excel.Range
  1948. xlApp = CreateObject("Excel.Application")
  1949. xlApp.Visible = False
  1950. xlApp.DisplayAlerts = False
  1951. xlBook = xlApp.Workbooks.Add
  1952. xlSheet = xlBook.Worksheets(1)
  1953. xlSheet.Name = "报关进口汇总"
  1954. xlSheet.Activate()
  1955. xlSheet.Cells(5, 5).select
  1956. dgv1.SelectAll()
  1957. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  1958. Me.dgv1.RowHeadersVisible = False
  1959. Clipboard.SetDataObject(dgv1.GetClipboardContent())
  1960. xlApp.Range("B30").Select()
  1961. xlSheet.Paste()
  1962. xlApp.Visible = True
  1963. '''' xlApp.ActiveSheet.Paste
  1964. ''''xlApp.CutCopyMode = False
  1965. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$30:$L$" & dt1.Rows.Count + 25), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  1966. Dim PTCache As Microsoft.Office.Interop.Excel.PivotCache
  1967. Dim PT As Microsoft.Office.Interop.Excel.PivotTable
  1968. 'Create the Cache
  1969. PTCache = xlApp.ActiveWorkbook.PivotCaches.Create(SourceType:=Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlDatabase, SourceData:=xlApp.Range("$B$30:$L$" & dt1.Rows.Count + 25))
  1970. 'Select the destination sheet
  1971. xlSheet.Range("b2").Select()
  1972. 'Create the Pivot table
  1973. PT = xlSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=xlSheet.Range("B2"), TableName:="Pivot1")
  1974. xlApp.ActiveWorkbook.ShowPivotTableFieldList = True
  1975. 'Adding fields
  1976. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("海关分类")
  1977. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField
  1978. .Position = 1
  1979. End With
  1980. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("进厂月份")
  1981. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  1982. .Position = 1
  1983. End With
  1984. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("手册号")
  1985. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  1986. .Position = 1
  1987. End With
  1988. With xlApp.ActiveSheet.PivotTables("pivot1")
  1989. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("数量"), "数量合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  1990. End With
  1991. With xlApp.ActiveSheet.PivotTables("pivot1")
  1992. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("货值"), "货值合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  1993. End With
  1994. xlApp.Visible = True
  1995. xlApp = Nothing
  1996. xlBook = Nothing
  1997. xlSheet = Nothing
  1998. End Sub
  1999. Private Sub Button24_Click(sender As Object, e As EventArgs) Handles Button24.Click
  2000. Frm_BG_FM_MEASURE.Show()
  2001. End Sub
  2002. Private Sub Button25_Click(sender As Object, e As EventArgs) Handles Button25.Click '----报关出口汇总
  2003. sql = "SELECT RT_BG_OUT.XNO AS 手册号, RT_BG_OUT.date1 AS 报关日期, RT_BG_OUT.NO AS 报关单号,
  2004. MONTH(RT_BG_OUT.date1) AS 报关月份,
  2005. CASE WHEN RT_BG_OUT.name LIKE '%pu%' THEN N'PU皮二层皮' ELSE N'牛二层皮' END AS 品名,
  2006. RT_BG_OUT.NAME AS 品名1, RT_BG_OUT.QTY AS 重量, CAST(RT_BG_OUT.TOTAL AS numeric(10, 1)) AS 货值, CAST(RT_BG_OUT.TOTAL/rt_bg_out.qty AS numeric(10, 3)) AS 单价,
  2007. CAST(RT_BG_OUT.FEE AS numeric(10, 1)) AS 工缴费, RT_BG_MTL_NAME.L_no AS 料号,
  2008. CAST(RT_BG_OUT.FEE / RT_BG_OUT.QTY AS NUMERIC(10, 1)) AS 工缴费单价, RT_BG_OUT.COMMENT AS 客户,
  2009. RT_BG_OUT.DES AS 目的地
  2010. FROM RT_BG_OUT LEFT OUTER JOIN
  2011. RT_BG_MTL_NAME ON RT_BG_OUT.NAME = RT_BG_MTL_NAME.NAME where date1 between '" & dtp1.Value & "' and '" & dtp2.Value & "'"
  2012. cmd.CommandText = sql
  2013. da.SelectCommand = cmd
  2014. Dim dt1 As New DataTable
  2015. da.Fill(dt1)
  2016. If dt1.Rows.Count = 0 Then
  2017. MsgBox("查无记录")
  2018. Exit Sub
  2019. End If
  2020. dgv1.DataSource = dt1
  2021. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  2022. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  2023. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  2024. Dim xlRange As Microsoft.Office.Interop.Excel.Range
  2025. xlApp = CreateObject("Excel.Application")
  2026. xlApp.Visible = True
  2027. xlApp.DisplayAlerts = False
  2028. xlBook = xlApp.Workbooks.Add
  2029. xlSheet = xlBook.Worksheets(1)
  2030. xlSheet.Name = "报关出口汇总"
  2031. xlSheet.Activate()
  2032. xlApp.Range("d25:d2000").Select()
  2033. xlApp.Selection.NumberFormatLocal = "@"
  2034. xlSheet.Cells(5, 5).select
  2035. dgv1.SelectAll()
  2036. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  2037. Me.dgv1.RowHeadersVisible = False
  2038. Dim DT_OBJECT As DataObject =DGV1.GetClipboardContent()
  2039. Clipboard.SetDataObject(DT_OBJECT)
  2040. 'Dim t As New System.Windows.Forms.DataObject
  2041. 't = dgv1.GetClipboardContent
  2042. 'System.Windows.Forms.Clipboard.SetDataObject(t, False, 2, 2)
  2043. xlApp.Range("B25").Select()
  2044. xlSheet.PasteSpecial("Unicode 文本", False, False)
  2045. 'xlSheet.Paste()
  2046. xlApp.Visible = True
  2047. '''' xlApp.ActiveSheet.Paste
  2048. ''''xlApp.CutCopyMode = False
  2049. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$25:$o$" & dt1.Rows.Count + 25), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  2050. Dim PTCache As Microsoft.Office.Interop.Excel.PivotCache
  2051. Dim PT As Microsoft.Office.Interop.Excel.PivotTable
  2052. 'Create the Cache
  2053. PTCache = xlApp.ActiveWorkbook.PivotCaches.Create(SourceType:=Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlDatabase, SourceData:=xlApp.Range("$B$25:$o$" & dt1.Rows.Count + 25))
  2054. 'Select the destination sheet
  2055. xlSheet.Range("b2").Select()
  2056. 'Create the Pivot table
  2057. PT = xlSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=xlSheet.Range("B2"), TableName:="Pivot1")
  2058. xlApp.ActiveWorkbook.ShowPivotTableFieldList = True
  2059. 'Adding fields
  2060. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("手册号")
  2061. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField
  2062. .Position = 1
  2063. End With
  2064. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("报关月份")
  2065. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2066. .Position = 1
  2067. End With
  2068. With xlApp.ActiveSheet.PivotTables("pivot1")
  2069. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("重量"), "重量合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2070. End With
  2071. With xlApp.ActiveSheet.PivotTables("pivot1")
  2072. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("货值"), "货值合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2073. End With
  2074. xlApp.Visible = True
  2075. xlApp = Nothing
  2076. xlBook = Nothing
  2077. xlSheet = Nothing
  2078. End Sub
  2079. Private Sub Button27_Click(sender As Object, e As EventArgs) Handles Button27.Click '----保税入库
  2080. sql = "SELECT m_in AS 入库数量, LEFT(xno, 12) AS 手册号, date AS 日期, MONTH(date) AS 月份, item_new AS 品名, name AS 明细 FROM RT_BG_IO WHERE (m_in <> 0) AND (date between '" & dtp1.Value & "' and '" & dtp2.Value & "') AND (item_new NOT LIKE N'%牛二层皮%')"
  2081. cmd.CommandText = sql
  2082. da.SelectCommand = cmd
  2083. Dim dt1 As New DataTable
  2084. da.Fill(dt1)
  2085. If dt1.Rows.Count = 0 Then
  2086. MsgBox("查无记录")
  2087. Exit Sub
  2088. End If
  2089. dgv1.DataSource = dt1
  2090. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  2091. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  2092. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  2093. Dim xlRange As Microsoft.Office.Interop.Excel.Range
  2094. xlApp = CreateObject("Excel.Application")
  2095. xlApp.Visible = False
  2096. xlApp.DisplayAlerts = False
  2097. xlBook = xlApp.Workbooks.Add
  2098. xlSheet = xlBook.Worksheets(1)
  2099. xlSheet.Name = "保税入库汇总"
  2100. xlSheet.Activate()
  2101. xlSheet.Cells(5, 5).select
  2102. dgv1.SelectAll()
  2103. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  2104. Me.dgv1.RowHeadersVisible = False
  2105. Clipboard.SetDataObject(dgv1.GetClipboardContent())
  2106. xlApp.Range("B30").Select()
  2107. xlSheet.Paste()
  2108. xlApp.Visible = True
  2109. '''' xlApp.ActiveSheet.Paste
  2110. ''''xlApp.CutCopyMode = False
  2111. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$30:$g$" & dt1.Rows.Count + 30), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  2112. Dim PTCache As Microsoft.Office.Interop.Excel.PivotCache
  2113. Dim PT As Microsoft.Office.Interop.Excel.PivotTable
  2114. 'Create the Cache
  2115. PTCache = xlApp.ActiveWorkbook.PivotCaches.Create(SourceType:=Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlDatabase, SourceData:=xlApp.Range("$B$30:$g$" & dt1.Rows.Count + 30))
  2116. 'Select the destination sheet
  2117. xlSheet.Range("b2").Select()
  2118. 'Create the Pivot table
  2119. PT = xlSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=xlSheet.Range("B2"), TableName:="Pivot1")
  2120. xlApp.ActiveWorkbook.ShowPivotTableFieldList = True
  2121. 'Adding fields
  2122. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("品名")
  2123. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField
  2124. .Position = 1
  2125. End With
  2126. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("手册号")
  2127. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2128. .Position = 1
  2129. End With
  2130. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("月份")
  2131. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2132. .Position = 1
  2133. End With
  2134. With xlApp.ActiveSheet.PivotTables("pivot1")
  2135. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("入库数量"), "重量合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2136. End With
  2137. 'With xlApp.ActiveSheet.PivotTables("pivot1")
  2138. ' .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("货值"), "货值合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2139. 'End With
  2140. xlApp.Visible = True
  2141. xlApp = Nothing
  2142. xlBook = Nothing
  2143. xlSheet = Nothing
  2144. End Sub
  2145. Private Sub Button26_Click(sender As Object, e As EventArgs) Handles Button26.Click '----保税出库汇总
  2146. sql = "SELECT m_out AS 出库数量, LEFT(xno, 12) AS 手册号, date AS 日期, MONTH(date) AS 月份, item_new AS 品名, name AS 明细 FROM RT_BG_IO WHERE (m_out <> 0) AND (date between '" & dtp1.Value & "' and '" & dtp2.Value & "') And (item_new Not LIKE N'%牛二层皮%')"
  2147. cmd.CommandText = sql
  2148. da.SelectCommand = cmd
  2149. Dim dt1 As New DataTable
  2150. da.Fill(dt1)
  2151. If dt1.Rows.Count = 0 Then
  2152. MsgBox("查无记录")
  2153. Exit Sub
  2154. End If
  2155. dgv1.DataSource = dt1
  2156. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  2157. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  2158. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  2159. Dim xlRange As Microsoft.Office.Interop.Excel.Range
  2160. xlApp = CreateObject("Excel.Application")
  2161. xlApp.Visible = False
  2162. xlApp.DisplayAlerts = False
  2163. xlBook = xlApp.Workbooks.Add
  2164. xlSheet = xlBook.Worksheets(1)
  2165. xlSheet.Name = "保税出库汇总"
  2166. xlSheet.Activate()
  2167. xlSheet.Cells(5, 5).select
  2168. dgv1.SelectAll()
  2169. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  2170. Me.dgv1.RowHeadersVisible = False
  2171. Clipboard.SetDataObject(dgv1.GetClipboardContent())
  2172. xlApp.Range("B25").Select()
  2173. xlSheet.Paste()
  2174. xlApp.Visible = True
  2175. '''' xlApp.ActiveSheet.Paste
  2176. ''''xlApp.CutCopyMode = False
  2177. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$25:$g$" & dt1.Rows.Count + 25), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  2178. Dim PTCache As Microsoft.Office.Interop.Excel.PivotCache
  2179. Dim PT As Microsoft.Office.Interop.Excel.PivotTable
  2180. 'Create the Cache
  2181. PTCache = xlApp.ActiveWorkbook.PivotCaches.Create(SourceType:=Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlDatabase, SourceData:=xlApp.Range("$B$25:$g$" & dt1.Rows.Count + 25))
  2182. 'Select the destination sheet
  2183. xlSheet.Range("b2").Select()
  2184. 'Create the Pivot table
  2185. PT = xlSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=xlSheet.Range("B2"), TableName:="Pivot1")
  2186. xlApp.ActiveWorkbook.ShowPivotTableFieldList = True
  2187. 'Adding fields
  2188. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("品名")
  2189. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField
  2190. .Position = 1
  2191. End With
  2192. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("手册号")
  2193. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2194. .Position = 1
  2195. End With
  2196. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("月份")
  2197. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2198. .Position = 1
  2199. End With
  2200. With xlApp.ActiveSheet.PivotTables("pivot1")
  2201. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("出库数量"), "重量合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2202. End With
  2203. 'With xlApp.ActiveSheet.PivotTables("pivot1")
  2204. ' .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("货值"), "货值合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2205. 'End With
  2206. xlApp.Visible = True
  2207. xlApp = Nothing
  2208. xlBook = Nothing
  2209. xlSheet = Nothing
  2210. End Sub
  2211. Private Sub Button28_Click(sender As Object, e As EventArgs) Handles Button28.Click '---成品入库
  2212. sql = "SELECT left(xno,12) AS 手册号, item_new AS 品名, name AS 明细, date AS 入库日期,month(date) as 入库月份, CAST(m_in AS numeric(10, 1)) AS 入库数量 FROM RT_BG_IO WHERE (item_new LIKE N'%牛二层皮%') AND (date between '" & dtp1.Value & "' and '" & dtp2.Value & "') AND (m_in <> 0)"
  2213. cmd.CommandText = sql
  2214. da.SelectCommand = cmd
  2215. Dim dt1 As New DataTable
  2216. da.Fill(dt1)
  2217. If dt1.Rows.Count = 0 Then
  2218. MsgBox("查无记录")
  2219. Exit Sub
  2220. End If
  2221. dgv1.DataSource = dt1
  2222. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  2223. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  2224. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  2225. Dim xlRange As Microsoft.Office.Interop.Excel.Range
  2226. xlApp = CreateObject("Excel.Application")
  2227. xlApp.Visible = False
  2228. xlApp.DisplayAlerts = False
  2229. xlBook = xlApp.Workbooks.Add
  2230. xlSheet = xlBook.Worksheets(1)
  2231. xlSheet.Name = "保税入库汇总"
  2232. xlSheet.Activate()
  2233. xlSheet.Cells(5, 5).select
  2234. dgv1.SelectAll()
  2235. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  2236. Me.dgv1.RowHeadersVisible = False
  2237. Clipboard.SetDataObject(dgv1.GetClipboardContent())
  2238. xlApp.Range("B25").Select()
  2239. xlSheet.Paste()
  2240. xlApp.Visible = True
  2241. '''' xlApp.ActiveSheet.Paste
  2242. ''''xlApp.CutCopyMode = False
  2243. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$25:$g$" & dt1.Rows.Count + 25), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  2244. Dim PTCache As Microsoft.Office.Interop.Excel.PivotCache
  2245. Dim PT As Microsoft.Office.Interop.Excel.PivotTable
  2246. 'Create the Cache
  2247. PTCache = xlApp.ActiveWorkbook.PivotCaches.Create(SourceType:=Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlDatabase, SourceData:=xlApp.Range("$B$25:$g$" & dt1.Rows.Count + 25))
  2248. 'Select the destination sheet
  2249. xlSheet.Range("b2").Select()
  2250. 'Create the Pivot table
  2251. PT = xlSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=xlSheet.Range("B2"), TableName:="Pivot1")
  2252. xlApp.ActiveWorkbook.ShowPivotTableFieldList = True
  2253. 'Adding fields
  2254. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("品名")
  2255. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField
  2256. .Position = 1
  2257. End With
  2258. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("手册号")
  2259. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2260. .Position = 1
  2261. End With
  2262. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("入库月份")
  2263. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2264. .Position = 1
  2265. End With
  2266. With xlApp.ActiveSheet.PivotTables("pivot1")
  2267. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("入库数量"), "重量合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2268. End With
  2269. 'With xlApp.ActiveSheet.PivotTables("pivot1")
  2270. ' .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("货值"), "货值合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2271. 'End With
  2272. xlApp.Visible = True
  2273. xlApp = Nothing
  2274. xlBook = Nothing
  2275. xlSheet = Nothing
  2276. End Sub
  2277. Private Sub Button29_Click(sender As Object, e As EventArgs) Handles Button29.Click '----保税成品出库
  2278. sql = "SELECT left(xno,12) AS 手册号, item_new AS 品名, name AS 明细, date AS 出库日期,month(date) as 出库月份, CAST(m_out AS numeric(10, 1)) AS 出库数量 FROM RT_BG_IO WHERE (item_new LIKE N'%牛二层皮%') AND (date between '" & dtp1.Value & "' and '" & dtp2.Value & "') AND (m_out <> 0)"
  2279. cmd.CommandText = sql
  2280. da.SelectCommand = cmd
  2281. Dim dt1 As New DataTable
  2282. da.Fill(dt1)
  2283. If dt1.Rows.Count = 0 Then
  2284. MsgBox("查无记录")
  2285. Exit Sub
  2286. End If
  2287. dgv1.DataSource = dt1
  2288. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  2289. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  2290. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  2291. Dim xlRange As Microsoft.Office.Interop.Excel.Range
  2292. xlApp = CreateObject("Excel.Application")
  2293. xlApp.Visible = False
  2294. xlApp.DisplayAlerts = False
  2295. xlBook = xlApp.Workbooks.Add
  2296. xlSheet = xlBook.Worksheets(1)
  2297. xlSheet.Name = "保税出库汇总"
  2298. xlSheet.Activate()
  2299. xlSheet.Cells(5, 5).select
  2300. dgv1.SelectAll()
  2301. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  2302. Me.dgv1.RowHeadersVisible = False
  2303. Clipboard.SetDataObject(dgv1.GetClipboardContent())
  2304. xlApp.Range("B25").Select()
  2305. xlSheet.Paste()
  2306. xlApp.Visible = True
  2307. '''' xlApp.ActiveSheet.Paste
  2308. ''''xlApp.CutCopyMode = False
  2309. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$25:$g$" & dt1.Rows.Count + 25), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  2310. Dim PTCache As Microsoft.Office.Interop.Excel.PivotCache
  2311. Dim PT As Microsoft.Office.Interop.Excel.PivotTable
  2312. 'Create the Cache
  2313. PTCache = xlApp.ActiveWorkbook.PivotCaches.Create(SourceType:=Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlDatabase, SourceData:=xlApp.Range("$B$25:$g$" & dt1.Rows.Count + 25))
  2314. 'Select the destination sheet
  2315. xlSheet.Range("b2").Select()
  2316. 'Create the Pivot table
  2317. PT = xlSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=xlSheet.Range("B2"), TableName:="Pivot1")
  2318. xlApp.ActiveWorkbook.ShowPivotTableFieldList = True
  2319. 'Adding fields
  2320. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("品名")
  2321. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField
  2322. .Position = 1
  2323. End With
  2324. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("手册号")
  2325. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2326. .Position = 1
  2327. End With
  2328. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("出库月份")
  2329. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2330. .Position = 1
  2331. End With
  2332. With xlApp.ActiveSheet.PivotTables("pivot1")
  2333. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("出库数量"), "重量合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2334. End With
  2335. 'With xlApp.ActiveSheet.PivotTables("pivot1")
  2336. ' .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("货值"), "货值合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2337. 'End With
  2338. xlApp.Visible = True
  2339. xlApp = Nothing
  2340. xlBook = Nothing
  2341. xlSheet = Nothing
  2342. End Sub
  2343. Private Sub Button30_Click(sender As Object, e As EventArgs) Handles Button30.Click '--生产耗料
  2344. sql = "SELECT distinct 手册号, 成品, 明细, 入库数量, 入库日期, 料件, 单耗, 料件耗用, 领料日期, MONTH(领料日期) AS 领料月份 FROM (SELECT TOP (100) PERCENT right(RT_BG_IO.xno, 5) AS 手册号, RT_BG_IO.item AS 成品, RT_BG_IO.name AS 明细, RT_BG_IO.m_in AS 入库数量, RT_BG_IO.date AS 入库日期, RT_BG_COM.NAME AS 料件, RT_BG_COM.PERCENTS AS 单耗, RT_BG_COM.PERCENTS * RT_BG_IO.m_in AS 料件耗用, CASE WHEN rt_bg_com.name LIKE N'%聚%' THEN DATEADD(day, - 2, RT_BG_IO.date) WHEN rt_bg_com.name LIKE N'%pu%' OR rt_bg_com.name LIKE N'%促%' THEN DATEADD(day, - 3, RT_BG_IO.date) WHEN rt_bg_com.name LIKE N'%蓝%' THEN DATEADD(day, - 14, RT_BG_IO.date) ELSE DATEADD(day, - 7, RT_BG_IO.date) END AS 领料日期 FROM RT_BG_IO INNER JOIN RT_BG_COM ON LEFT(RT_BG_IO.xno, 12) = RT_BG_COM.XNO AND RT_BG_IO.item = RT_BG_COM.product1 WHERE (RT_BG_IO.item LIKE N'%牛二层皮%') AND (RT_BG_IO.name LIKE '%入%') AND (RT_BG_IO.m_in <> 0) AND (date between '" & dtp1.Value & "' and '" & dtp2.Value & "') ORDER BY 入库数量) AS p"
  2345. cmd.CommandText = sql
  2346. da.SelectCommand = cmd
  2347. Dim dt1 As New DataTable
  2348. da.Fill(dt1)
  2349. If dt1.Rows.Count = 0 Then
  2350. MsgBox("查无记录")
  2351. Exit Sub
  2352. End If
  2353. dgv1.DataSource = dt1
  2354. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  2355. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  2356. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  2357. Dim xlRange As Microsoft.Office.Interop.Excel.Range
  2358. xlApp = CreateObject("Excel.Application")
  2359. xlApp.Visible = False
  2360. xlApp.DisplayAlerts = False
  2361. xlBook = xlApp.Workbooks.Add
  2362. xlSheet = xlBook.Worksheets(1)
  2363. xlSheet.Name = "料件领料汇总"
  2364. xlSheet.Activate()
  2365. xlSheet.Cells(5, 5).select
  2366. dgv1.SelectAll()
  2367. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  2368. Me.dgv1.RowHeadersVisible = False
  2369. Clipboard.SetDataObject(dgv1.GetClipboardContent())
  2370. xlApp.Range("B30").Select()
  2371. xlSheet.Paste()
  2372. xlApp.Visible = True
  2373. '''' xlApp.ActiveSheet.Paste
  2374. ''''xlApp.CutCopyMode = False
  2375. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$30:$k$" & dt1.Rows.Count + 30), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  2376. Dim PTCache As Microsoft.Office.Interop.Excel.PivotCache
  2377. Dim PT As Microsoft.Office.Interop.Excel.PivotTable
  2378. 'Create the Cache
  2379. PTCache = xlApp.ActiveWorkbook.PivotCaches.Create(SourceType:=Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlDatabase, SourceData:=xlApp.Range("$B$30:$k$" & dt1.Rows.Count + 30))
  2380. 'Select the destination sheet
  2381. xlSheet.Range("b2").Select()
  2382. 'Create the Pivot table
  2383. PT = xlSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=xlSheet.Range("B2"), TableName:="Pivot1")
  2384. xlApp.ActiveWorkbook.ShowPivotTableFieldList = True
  2385. 'Adding fields
  2386. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("料件")
  2387. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField
  2388. .Position = 1
  2389. End With
  2390. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("成品")
  2391. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2392. .Position = 1
  2393. End With
  2394. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("手册号")
  2395. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2396. .Position = 1
  2397. End With
  2398. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("领料月份")
  2399. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2400. .Position = 1
  2401. End With
  2402. With xlApp.ActiveSheet.PivotTables("pivot1")
  2403. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("料件耗用"), "耗用合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2404. End With
  2405. 'With xlApp.ActiveSheet.PivotTables("pivot1")
  2406. ' .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("货值"), "货值合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2407. 'End With
  2408. xlApp.Visible = True
  2409. xlApp = Nothing
  2410. xlBook = Nothing
  2411. xlSheet = Nothing
  2412. End Sub
  2413. Private Sub Button17_Click(sender As Object, e As EventArgs)
  2414. End Sub
  2415. Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
  2416. End Sub
  2417. Private Sub Button8_Click(sender As Object, e As EventArgs)
  2418. End Sub
  2419. Private Sub Button16_Click(sender As Object, e As EventArgs)
  2420. End Sub
  2421. Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  2422. End Sub
  2423. Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
  2424. End Sub
  2425. Private Sub Button3_Click(sender As Object, e As EventArgs)
  2426. End Sub
  2427. Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
  2428. End Sub
  2429. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2430. End Sub
  2431. Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles GroupBox1.Enter
  2432. End Sub
  2433. Private Sub Button3_Click_1(sender As Object, e As EventArgs) Handles Button3.Click '-----------------------------汇总
  2434. Dim a As Integer = 0
  2435. sql = "SELECT DATE1 AS 报关日期, Date2 AS 进厂日期, MONTH(Date2) AS 进厂月份, XNO AS 手册号, NAME AS 海关分类,type as 进口类型,matl_name AS 品名, QTY AS 数量, PRICE AS 单价, price*qty as 货值, ORIGIN AS 产地 FROM RT_BG_IN_DETAIL WHERE date2 between '" & String.Format("{0:d}", dtp1.Value) & "' and '" & String.Format("{0:d}", dtp2.Value) & "'"
  2436. cmd.CommandText = sql
  2437. da.SelectCommand = cmd
  2438. da.Fill(dt1)
  2439. If dt1.Rows.Count = 0 Then
  2440. MsgBox("查无记录")
  2441. Exit Sub
  2442. End If
  2443. dgv1.DataSource = dt1
  2444. xlApp = CreateObject("Excel.Application")
  2445. xlApp.Visible = False
  2446. 'xlApp.DisplayAlerts = False
  2447. xlBook = xlApp.Workbooks.Add
  2448. xlSheet = xlBook.Worksheets.Add
  2449. xlSheet.Name = "报关进口"
  2450. xlSheet.Activate()
  2451. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(1, 1), Address:="", SubAddress:="总表!A1", TextToDisplay:="总表")
  2452. xlSheet.Cells(5, 5).select
  2453. dgv1.SelectAll()
  2454. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  2455. Me.dgv1.RowHeadersVisible = False
  2456. Clipboard.SetDataObject(dgv1.GetClipboardContent())
  2457. System.Threading.Thread.Sleep(1000)
  2458. xlApp.Range("B30").Select()
  2459. 'xlSheet.PasteSpecial("Unicode 文本", False, False)
  2460. xlSheet.PasteSpecial()
  2461. Clipboard.SetDataObject(DBNull.Value)
  2462. ' xlApp.Visible = True
  2463. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$30:$L$" & dt1.Rows.Count + 30), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  2464. 'Create the Cache
  2465. PTCache = xlApp.ActiveWorkbook.PivotCaches.Create(SourceType:=Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlDatabase, SourceData:=xlApp.Range("$B$30:$L$" & dt1.Rows.Count + 30))
  2466. 'Select the destination sheet
  2467. xlSheet.Range("b2").Select()
  2468. 'Create the Pivot table
  2469. PT = xlSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=xlSheet.Range("B2"), TableName:="Pivot1")
  2470. xlApp.ActiveWorkbook.ShowPivotTableFieldList = True
  2471. 'Adding fields
  2472. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("海关分类")
  2473. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField
  2474. .Position = 1
  2475. End With
  2476. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("进厂月份")
  2477. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2478. .Position = 1
  2479. End With
  2480. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("手册号")
  2481. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2482. .Position = 1
  2483. End With
  2484. With xlApp.ActiveSheet.PivotTables("pivot1")
  2485. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("数量"), "数量合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2486. End With
  2487. With xlApp.ActiveSheet.PivotTables("pivot1")
  2488. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("货值"), "货值合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2489. End With
  2490. sql = "SELECT distinct XNO as 手册号, date1 as 报关日期, no as 报关单号,comment as 客户,month(date1) as 报关月份,name AS 品名, QTY AS 重量, cast(TOTAL as numeric(10,2)) AS 货值, cast(FEE as numeric(10,2)) AS 工缴费 FROM RT_BG_OUT where date1 between '" & String.Format("{0:d}", dtp1.Value) & "' and '" & String.Format("{0:d}", dtp2.Value) & "'"
  2491. cmd.CommandText = sql
  2492. da.SelectCommand = cmd
  2493. dt1 = New DataTable
  2494. da.Fill(dt1) '------------------------------报关出口汇总
  2495. dgv1.DataSource = dt1
  2496. xlSheet = xlBook.Worksheets.Add
  2497. xlSheet.Name = "报关出口"
  2498. xlSheet.Activate()
  2499. xlSheet.Cells(5, 5).select
  2500. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(1, 1), Address:="", SubAddress:="总表!A1", TextToDisplay:="总表")
  2501. dgv1.SelectAll()
  2502. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  2503. Me.dgv1.RowHeadersVisible = False
  2504. Clipboard.SetDataObject(dgv1.GetClipboardContent())
  2505. System.Threading.Thread.Sleep(1000)
  2506. xlApp.Columns("d:d").Select
  2507. xlApp.Selection.NumberFormatLocal = "@"
  2508. xlApp.Range("B25").Select()
  2509. 'xlSheet.PasteSpecial("Unicode 文本", False, False)
  2510. xlSheet.PasteSpecial()
  2511. Clipboard.SetDataObject(DBNull.Value)
  2512. ' xlApp.Visible = True
  2513. '''' xlApp.ActiveSheet.Paste
  2514. ''''xlApp.CutCopyMode = False
  2515. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$25:$j$" & dt1.Rows.Count + 25), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  2516. 'Dim PTCache As Microsoft.Office.Interop.Excel.PivotCache
  2517. 'Dim PT As Microsoft.Office.Interop.Excel.PivotTable
  2518. 'Create the Cache
  2519. PTCache = xlApp.ActiveWorkbook.PivotCaches.Create(SourceType:=Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlDatabase, SourceData:=xlApp.Range("$B$25:$j$" & dt1.Rows.Count + 25))
  2520. 'Select the destination sheet
  2521. xlSheet.Range("b2").Select()
  2522. 'Create the Pivot table
  2523. PT = xlSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=xlSheet.Range("B2"), TableName:="Pivot1")
  2524. xlApp.ActiveWorkbook.ShowPivotTableFieldList = True
  2525. 'Adding fields
  2526. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("手册号")
  2527. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField
  2528. .Position = 1
  2529. End With
  2530. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("报关月份")
  2531. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2532. .Position = 1
  2533. End With
  2534. With xlApp.ActiveSheet.PivotTables("pivot1")
  2535. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("重量"), "重量合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2536. End With
  2537. With xlApp.ActiveSheet.PivotTables("pivot1")
  2538. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("货值"), "货值合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2539. End With
  2540. '----------------------------------------------------------------------保税入库
  2541. sql = "SELECT m_in AS 入库数量, LEFT(xno, 12) AS 手册号, date2 AS 进厂日期, MONTH(date2) AS 进厂月份, item_new AS 品名, name AS 明细 FROM RT_BG_IO WHERE (m_in <> 0) AND (date between '" & String.Format("{0:d}", dtp1.Value) & "' and '" & String.Format("{0:d}", dtp2.Value) & "') AND (item_new NOT LIKE N'%牛二层皮%')"
  2542. cmd.CommandText = sql
  2543. da.SelectCommand = cmd
  2544. dt1 = New DataTable
  2545. da.Fill(dt1)
  2546. dgv1.DataSource = dt1
  2547. xlSheet = xlBook.Worksheets.Add
  2548. xlSheet.Name = "保税入库"
  2549. xlSheet.Activate()
  2550. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(1, 1), Address:="", SubAddress:="总表!A1", TextToDisplay:="总表")
  2551. xlSheet.Cells(5, 5).select
  2552. dgv1.SelectAll()
  2553. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  2554. Me.dgv1.RowHeadersVisible = False
  2555. Clipboard.SetDataObject(dgv1.GetClipboardContent())
  2556. System.Threading.Thread.Sleep(1000)
  2557. xlApp.Range("B30").Select()
  2558. ' xlSheet.PasteSpecial("Unicode 文本", False, False)
  2559. 'xlSheet.PasteSpecial()
  2560. xlSheet.Paste()
  2561. Clipboard.SetDataObject(DBNull.Value)
  2562. ' xlApp.Visible = True
  2563. '''' xlApp.ActiveSheet.Paste
  2564. ''''xlApp.CutCopyMode = False
  2565. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$30:$g$" & dt1.Rows.Count + 31), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  2566. 'Create the Cache
  2567. PTCache = xlApp.ActiveWorkbook.PivotCaches.Create(SourceType:=Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlDatabase, SourceData:=xlApp.Range("$B$30:$g$" & dt1.Rows.Count + 31))
  2568. 'Select the destination sheet
  2569. xlSheet.Range("b2").Select()
  2570. 'Create the Pivot table
  2571. PT = xlSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=xlSheet.Range("B2"), TableName:="Pivot1")
  2572. xlApp.ActiveWorkbook.ShowPivotTableFieldList = True
  2573. 'Adding fields
  2574. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("品名")
  2575. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField
  2576. .Position = 1
  2577. End With
  2578. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("手册号")
  2579. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2580. .Position = 1
  2581. End With
  2582. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("进厂月份")
  2583. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2584. .Position = 1
  2585. End With
  2586. With xlApp.ActiveSheet.PivotTables("pivot1")
  2587. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("入库数量"), "重量合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2588. End With
  2589. 'With xlApp.ActiveSheet.PivotTables("pivot1")
  2590. ' .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("货值"), "货值合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2591. 'End With
  2592. '--------------------------------------------------------------------------------------------------------------------------------保税出库汇总
  2593. sql = "SELECT m_out AS 出库数量, LEFT(xno, 12) AS 手册号, date AS 日期, MONTH(date) AS 月份, item_new AS 品名, name AS 明细 FROM RT_BG_IO WHERE (m_out <> 0) AND (date between '" & String.Format("{0:d}", dtp1.Value) & "' and '" & String.Format("{0:d}", dtp2.Value) & "') And (item_new Not LIKE N'%牛二层皮%')"
  2594. cmd.CommandText = sql
  2595. da.SelectCommand = cmd
  2596. dt1 = New DataTable
  2597. da.Fill(dt1)
  2598. dgv1.DataSource = dt1
  2599. xlSheet = xlBook.Worksheets.Add
  2600. xlSheet.Name = "保税出库"
  2601. xlSheet.Activate()
  2602. xlSheet.Cells(5, 5).select
  2603. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(1, 1), Address:="", SubAddress:="总表!A1", TextToDisplay:="总表")
  2604. dgv1.SelectAll()
  2605. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  2606. Me.dgv1.RowHeadersVisible = False
  2607. Clipboard.SetDataObject(dgv1.GetClipboardContent())
  2608. System.Threading.Thread.Sleep(1000)
  2609. xlApp.Range("B30").Select()
  2610. ' xlSheet.PasteSpecial("Unicode 文本", False, False)
  2611. xlSheet.PasteSpecial()
  2612. Clipboard.SetDataObject(DBNull.Value)
  2613. ' xlApp.Visible = True
  2614. '''' xlApp.ActiveSheet.Paste
  2615. ''''xlApp.CutCopyMode = False
  2616. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$30:$g$" & dt1.Rows.Count + 30), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  2617. 'Create the Cache
  2618. PTCache = xlApp.ActiveWorkbook.PivotCaches.Create(SourceType:=Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlDatabase, SourceData:=xlApp.Range("$B$30:$g$" & dt1.Rows.Count + 30))
  2619. 'Select the destination sheet
  2620. xlSheet.Range("b2").Select()
  2621. 'Create the Pivot table
  2622. PT = xlSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=xlSheet.Range("B2"), TableName:="Pivot1")
  2623. xlApp.ActiveWorkbook.ShowPivotTableFieldList = True
  2624. 'Adding fields
  2625. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("品名")
  2626. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField
  2627. .Position = 1
  2628. End With
  2629. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("手册号")
  2630. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2631. .Position = 1
  2632. End With
  2633. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("月份")
  2634. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2635. .Position = 1
  2636. End With
  2637. With xlApp.ActiveSheet.PivotTables("pivot1")
  2638. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("出库数量"), "重量合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2639. End With
  2640. '---------------------------------------------------------------------------------------------------成品入库
  2641. sql = "SELECT distinct left(xno,12) AS 手册号, item AS 品名, name AS 明细, date AS 入库日期,month(date) as 入库月份, CAST(m_in AS numeric(10, 1)) AS 入库数量 FROM RT_BG_IO WHERE (item_new LIKE N'%牛二层皮%') AND (date between '" & String.Format("{0:d}", dtp1.Value) & "' and '" & String.Format("{0:d}", dtp2.Value) & "') AND (m_in <> 0)"
  2642. cmd.CommandText = sql
  2643. da.SelectCommand = cmd
  2644. dt1 = New DataTable
  2645. da.Fill(dt1)
  2646. dgv1.DataSource = dt1
  2647. xlSheet = xlBook.Worksheets.Add
  2648. xlSheet.Name = "成品入库"
  2649. xlSheet.Activate()
  2650. xlSheet.Cells(5, 5).select
  2651. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(1, 1), Address:="", SubAddress:="总表!A1", TextToDisplay:="总表")
  2652. dgv1.SelectAll()
  2653. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  2654. Me.dgv1.RowHeadersVisible = False
  2655. Clipboard.SetDataObject(dgv1.GetClipboardContent())
  2656. System.Threading.Thread.Sleep(1000)
  2657. xlApp.Range("B30").Select()
  2658. 'xlSheet.PasteSpecial("Unicode 文本", False, False)
  2659. xlSheet.PasteSpecial()
  2660. Clipboard.SetDataObject(DBNull.Value)
  2661. ' xlApp.Visible = True
  2662. '''' xlApp.ActiveSheet.Paste
  2663. ''''xlApp.CutCopyMode = False
  2664. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$30:$g$" & dt1.Rows.Count + 30), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  2665. 'Create the Cache
  2666. PTCache = xlApp.ActiveWorkbook.PivotCaches.Create(SourceType:=Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlDatabase, SourceData:=xlApp.Range("$B$30:$g$" & dt1.Rows.Count + 30))
  2667. 'Select the destination sheet
  2668. xlSheet.Range("b2").Select()
  2669. 'Create the Pivot table
  2670. PT = xlSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=xlSheet.Range("B2"), TableName:="Pivot1")
  2671. xlApp.ActiveWorkbook.ShowPivotTableFieldList = True
  2672. 'Adding fields
  2673. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("品名")
  2674. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField
  2675. .Position = 1
  2676. End With
  2677. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("手册号")
  2678. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2679. .Position = 1
  2680. End With
  2681. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("入库月份")
  2682. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2683. .Position = 1
  2684. End With
  2685. With xlApp.ActiveSheet.PivotTables("pivot1")
  2686. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("入库数量"), "重量合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2687. End With
  2688. '--------------------------------------------------------------------------保税成品出库
  2689. sql = "SELECT distinct left(xno,12) AS 手册号, item AS 品名, name AS 明细, date AS 出厂日期,month(date) as 出厂月份, CAST(m_out AS numeric(10, 2)) AS 出库数量 FROM RT_BG_IO WHERE (item_new LIKE N'%牛二层皮%') AND (date between '" & String.Format("{0:d}", dtp1.Value) & "' and '" & String.Format("{0:d}", dtp2.Value) & "') AND (m_out <> 0)"
  2690. cmd.CommandText = sql
  2691. da.SelectCommand = cmd
  2692. dt1 = New DataTable
  2693. da.Fill(dt1)
  2694. dgv1.DataSource = dt1
  2695. xlSheet = xlBook.Worksheets.Add
  2696. xlSheet.Name = "成品出库"
  2697. xlSheet.Activate()
  2698. xlSheet.Cells(5, 5).select
  2699. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(1, 1), Address:="", SubAddress:="总表!A1", TextToDisplay:="总表")
  2700. dgv1.SelectAll()
  2701. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  2702. Me.dgv1.RowHeadersVisible = False
  2703. Clipboard.SetDataObject(dgv1.GetClipboardContent())
  2704. System.Threading.Thread.Sleep(1000)
  2705. xlApp.Range("B30").Select()
  2706. 'xlSheet.PasteSpecial("Unicode 文本", False, False)
  2707. xlSheet.PasteSpecial()
  2708. Clipboard.SetDataObject(DBNull.Value)
  2709. ' xlApp.Visible = True
  2710. '''' xlApp.ActiveSheet.Paste
  2711. ''''xlApp.CutCopyMode = False
  2712. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$30:$g$" & dt1.Rows.Count + 30), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  2713. 'Create the Cache
  2714. PTCache = xlApp.ActiveWorkbook.PivotCaches.Create(SourceType:=Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlDatabase, SourceData:=xlApp.Range("$B$30:$g$" & dt1.Rows.Count + 30))
  2715. 'Select the destination sheet
  2716. xlSheet.Range("b2").Select()
  2717. 'Create the Pivot table
  2718. PT = xlSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=xlSheet.Range("B2"), TableName:="Pivot1")
  2719. xlApp.ActiveWorkbook.ShowPivotTableFieldList = True
  2720. 'Adding fields
  2721. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("品名")
  2722. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField
  2723. .Position = 1
  2724. End With
  2725. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("手册号")
  2726. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2727. .Position = 1
  2728. End With
  2729. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("出厂月份")
  2730. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2731. .Position = 1
  2732. End With
  2733. With xlApp.ActiveSheet.PivotTables("pivot1")
  2734. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("出库数量"), "重量合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2735. End With
  2736. '------------------------------------------------------------------------------成品入库耗料
  2737. sql = "SELECT distinct 手册号, 成品, 明细, 入库数量, 入库日期, 料件, 单耗, 料件耗用, 领料日期, MONTH(领料日期) AS 领料月份 FROM (SELECT TOP (100) PERCENT LEFT(RT_BG_IO.xno, 12) AS 手册号, RT_BG_IO.item AS 成品, RT_BG_IO.name AS 明细,RT_BG_IO.m_in AS 入库数量, RT_BG_IO.date AS 入库日期, RT_BG_COM.NAME AS 料件, RT_BG_COM.PERCENTS AS 单耗, RT_BG_COM.PERCENTS * RT_BG_IO.m_in AS 料件耗用, CASE WHEN rt_bg_com.name LIKE N'%聚%' THEN DATEADD(day, - 2, RT_BG_IO.date) WHEN rt_bg_com.name LIKE N'%pu%' OR rt_bg_com.name LIKE N'%促%' THEN DATEADD(day, - 3, RT_BG_IO.date) WHEN rt_bg_com.name LIKE N'%蓝%' THEN DATEADD(day, - 14, RT_BG_IO.date) ELSE DATEADD(day, - 7, RT_BG_IO.date) END AS 领料日期 FROM RT_BG_IO INNER JOIN RT_BG_COM ON LEFT(RT_BG_IO.xno, 12) = RT_BG_COM.XNO AND RT_BG_IO.item = RT_BG_COM.product1 WHERE (RT_BG_IO.item LIKE N'%牛二层皮%') AND (RT_BG_IO.name LIKE '%入%') AND (RT_BG_IO.m_in <> 0) AND (date between '" & String.Format("{0:d}", dtp1.Value) & "' and '" & String.Format("{0:d}", dtp2.Value) & "') ORDER BY 入库数量) AS p"
  2738. cmd.CommandText = sql
  2739. da.SelectCommand = cmd
  2740. dt1 = New DataTable
  2741. da.Fill(dt1)
  2742. dgv1.DataSource = dt1
  2743. xlSheet = xlBook.Worksheets.Add
  2744. xlSheet.Name = "生产领料"
  2745. xlSheet.Activate()
  2746. xlSheet.Cells(5, 5).select
  2747. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(1, 1), Address:="", SubAddress:="总表!A1", TextToDisplay:="总表")
  2748. dgv1.SelectAll()
  2749. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  2750. Me.dgv1.RowHeadersVisible = False
  2751. Clipboard.SetDataObject(dgv1.GetClipboardContent())
  2752. System.Threading.Thread.Sleep(1000)
  2753. xlApp.Range("B30").Select()
  2754. 'xlSheet.PasteSpecial("Unicode 文本", False, False)
  2755. ' xlSheet.PasteSpecial()
  2756. xlSheet.Paste()
  2757. Clipboard.SetDataObject(DBNull.Value)
  2758. ' xlApp.Visible = True
  2759. 'xlApp.ActiveSheet.Paste
  2760. ''''xlApp.CutCopyMode = False
  2761. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$30:$k$" & dt1.Rows.Count + 30), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  2762. 'Create the Cache
  2763. PTCache = xlApp.ActiveWorkbook.PivotCaches.Create(SourceType:=Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlDatabase, SourceData:=xlApp.Range("$B$30:$k$" & dt1.Rows.Count + 30))
  2764. 'Select the destination sheet
  2765. xlSheet.Range("b2").Select()
  2766. 'Create the Pivot table
  2767. PT = xlSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=xlSheet.Range("B2"), TableName:="Pivot1")
  2768. xlApp.ActiveWorkbook.ShowPivotTableFieldList = True
  2769. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("料件")
  2770. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField
  2771. .Position = 1
  2772. End With
  2773. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("领料月份")
  2774. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2775. .Position = 1
  2776. End With
  2777. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("手册号")
  2778. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2779. .Position = 1
  2780. End With
  2781. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("成品")
  2782. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2783. .Position = 1
  2784. End With
  2785. With xlApp.ActiveSheet.PivotTables("pivot1")
  2786. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("料件耗用"), "耗用合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2787. End With
  2788. '------------------------------------------------------------------------------成品出库耗料
  2789. sql = "SELECT distinct 手册号, 成品, 明细, 出库数量, 出库日期, 料件, 单耗, 料件耗用, 领料日期, MONTH(领料日期) AS 领料月份 FROM (SELECT TOP (100) PERCENT LEFT(RT_BG_IO.xno, 12) AS 手册号, RT_BG_IO.item AS 成品, RT_BG_IO.name AS 明细, RT_BG_IO.m_out AS 出库数量, RT_BG_IO.date AS 出库日期, RT_BG_COM.NAME AS 料件, RT_BG_COM.PERCENTS AS 单耗, RT_BG_COM.PERCENTS * RT_BG_IO.m_out AS 料件耗用, CASE WHEN rt_bg_com.name LIKE N'%聚%' THEN DATEADD(day, - 2, RT_BG_IO.date) WHEN rt_bg_com.name LIKE N'%pu%' OR rt_bg_com.name LIKE N'%促%' THEN DATEADD(day, - 3, RT_BG_IO.date) WHEN rt_bg_com.name LIKE N'%蓝%' THEN DATEADD(day, - 14, RT_BG_IO.date) ELSE DATEADD(day, - 7, RT_BG_IO.date) END AS 领料日期 FROM RT_BG_IO INNER JOIN RT_BG_COM ON LEFT(RT_BG_IO.xno, 12) = RT_BG_COM.XNO AND RT_BG_IO.item = RT_BG_COM.product1 WHERE (RT_BG_IO.item LIKE N'%牛二层皮%') AND (RT_BG_IO.name LIKE '%出%') AND (RT_BG_IO.m_out <> 0) AND (date between '" & String.Format("{0:d}", dtp1.Value) & "' and '" & String.Format("{0:d}", dtp2.Value) & "') ORDER BY 出库数量) AS p"
  2790. cmd.CommandText = sql
  2791. da.SelectCommand = cmd
  2792. dt1 = New DataTable
  2793. da.Fill(dt1)
  2794. dgv1.DataSource = dt1
  2795. xlSheet = xlBook.Worksheets.Add
  2796. xlSheet.Name = "出口耗料"
  2797. xlSheet.Activate()
  2798. xlSheet.Cells(5, 5).select
  2799. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(1, 1), Address:="", SubAddress:="总表!A1", TextToDisplay:="总表")
  2800. dgv1.SelectAll()
  2801. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  2802. Me.dgv1.RowHeadersVisible = False
  2803. Clipboard.SetDataObject(dgv1.GetClipboardContent())
  2804. System.Threading.Thread.Sleep(1000)
  2805. xlApp.Range("B30").Select()
  2806. 'xlSheet.PasteSpecial("Unicode 文本", False, False)
  2807. xlSheet.PasteSpecial()
  2808. Clipboard.SetDataObject(DBNull.Value)
  2809. ' xlApp.Visible = True
  2810. '''' xlApp.ActiveSheet.Paste
  2811. ''''xlApp.CutCopyMode = False
  2812. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$30:$k$" & dt1.Rows.Count + 30), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  2813. 'Create the Cache
  2814. PTCache = xlApp.ActiveWorkbook.PivotCaches.Create(SourceType:=Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlDatabase, SourceData:=xlApp.Range("$B$30:$k$" & dt1.Rows.Count + 30))
  2815. 'Select the destination sheet
  2816. xlSheet.Range("b2").Select()
  2817. 'Create the Pivot table
  2818. PT = xlSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=xlSheet.Range("B2"), TableName:="Pivot1")
  2819. xlApp.ActiveWorkbook.ShowPivotTableFieldList = True
  2820. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("料件")
  2821. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField
  2822. .Position = 1
  2823. End With
  2824. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("领料月份")
  2825. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2826. .Position = 1
  2827. End With
  2828. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("手册号")
  2829. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2830. .Position = 1
  2831. End With
  2832. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("成品")
  2833. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  2834. .Position = 1
  2835. End With
  2836. With xlApp.ActiveSheet.PivotTables("pivot1")
  2837. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("料件耗用"), "耗用合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  2838. End With
  2839. '-----------------------------------------------------------------------------------analysis_data
  2840. analysis_data("A0006", "蓝湿牛皮")
  2841. analysis_data("A0006", "有机鞣料")
  2842. analysis_data("A0006", "无机鞣料")
  2843. ' analysis_data("A0006", "合成油脂(矿)")
  2844. analysis_data("A0006", "合成油脂")
  2845. analysis_data("A0006", "皮革整理剂")
  2846. analysis_data("A0006", "表面活性剂")
  2847. analysis_data("A0006", "聚氨酯混合液")
  2848. analysis_data("A0006", "复鞣助剂")
  2849. analysis_data("A0006", "制革染料")
  2850. analysis_data("A0006", "PU树脂")
  2851. analysis_data("A0006", "皮革促进剂")
  2852. analysis_data("A0008", "蓝湿牛皮")
  2853. analysis_data("A0008", "有机鞣料")
  2854. analysis_data("A0008", "无机鞣料")
  2855. analysis_data("A0008", "合成油脂(矿)")
  2856. analysis_data("A0008", "合成油脂")
  2857. analysis_data("A0008", "皮革整理剂")
  2858. analysis_data("A0008", "表面活性剂")
  2859. analysis_data("A0008", "聚氨酯混合液")
  2860. analysis_data("A0008", "复鞣助剂")
  2861. analysis_data("A0008", "制革染料")
  2862. analysis_data("A0008", "PU树脂")
  2863. analysis_data("A0008", "皮革促进剂")
  2864. '------------------------------------------------车间
  2865. analysis_data_1("A0008", "蓝湿牛皮")
  2866. analysis_data_1("A0008", "有机鞣料")
  2867. analysis_data_1("A0008", "无机鞣料")
  2868. analysis_data_1("A0008", "合成油脂(矿)")
  2869. analysis_data_1("A0008", "合成油脂")
  2870. analysis_data_1("A0008", "皮革整理剂")
  2871. analysis_data_1("A0008", "表面活性剂")
  2872. analysis_data_1("A0008", "聚氨酯混合液")
  2873. analysis_data_1("A0008", "复鞣助剂")
  2874. analysis_data_1("A0008", "制革染料")
  2875. analysis_data_1("A0008", "PU树脂")
  2876. analysis_data_1("A0008", "皮革促进剂")
  2877. analysis_data_1("A0006", "蓝湿牛皮")
  2878. analysis_data_1("A0006", "有机鞣料")
  2879. analysis_data_1("A0006", "无机鞣料")
  2880. 'analysis_data_1("A0006", "合成油脂(矿)")
  2881. analysis_data_1("A0006", "合成油脂")
  2882. analysis_data_1("A0006", "皮革整理剂")
  2883. analysis_data_1("A0006", "表面活性剂")
  2884. analysis_data_1("A0006", "聚氨酯混合液")
  2885. analysis_data_1("A0006", "复鞣助剂")
  2886. analysis_data_1("A0006", "制革染料")
  2887. analysis_data_1("A0006", "PU树脂")
  2888. analysis_data_1("A0006", "皮革促进剂")
  2889. '--------------------------------------------------成品
  2890. analysis_finish("A0008", "PU牛二层皮")
  2891. analysis_finish("A0008", "牛二层皮1")
  2892. analysis_finish("A0008", "牛二层皮2")
  2893. analysis_finish("A0008", "牛二层皮3")
  2894. analysis_finish("A0008", "牛二层皮4")
  2895. analysis_finish("A0006", "PU牛二层皮")
  2896. analysis_finish("A0006", "牛二层皮5")
  2897. analysis_finish("A0006", "牛二层皮6")
  2898. sheet_sum()
  2899. 'With xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("出库累计")
  2900. ' .Calculation = Microsoft.Office.Interop.Excel.XlPivotFieldCalculation.xlRunningTotal
  2901. ' .BaseField = "日期"
  2902. ' .NumberFormat = "#,##0.000;[红色](0.00)"
  2903. 'End With
  2904. 'With xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("入库累计")
  2905. ' .Calculation = Microsoft.Office.Interop.Excel.XlPivotFieldCalculation.xlRunningTotal
  2906. ' .BaseField = "日期"
  2907. ' .NumberFormat = "#,##0.000;[红色](0.00)"
  2908. 'End With
  2909. xlApp.Visible = True
  2910. MsgBox("完成")
  2911. xlApp.Visible = True
  2912. xlApp.Visible = True
  2913. xlApp = Nothing
  2914. xlBook = Nothing
  2915. xlSheet = Nothing
  2916. End Sub
  2917. Private Sub sheet_sum()
  2918. xlSheet = xlBook.Worksheets.Add
  2919. xlSheet.Name = "总表"
  2920. xlSheet.Activate()
  2921. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(3, 3), Address:="", SubAddress:="报关进口!A1", TextToDisplay:="报关进口")
  2922. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(3, 4), Address:="", SubAddress:="报关出口!A1", TextToDisplay:="报关出口")
  2923. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(4, 3), Address:="", SubAddress:="保税入库!A1", TextToDisplay:="保税入库")
  2924. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(4, 4), Address:="", SubAddress:="保税出库!A1", TextToDisplay:="保税出库")
  2925. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(5, 3), Address:="", SubAddress:="成品入库!A1", TextToDisplay:="成品入库")
  2926. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(5, 4), Address:="", SubAddress:="成品出库!A1", TextToDisplay:="成品出库")
  2927. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(6, 3), Address:="", SubAddress:="生产领料!A1", TextToDisplay:="生产领料")
  2928. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(6, 4), Address:="", SubAddress:="出口耗料!A1", TextToDisplay:="出口耗料")
  2929. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(8, 3), Address:="", SubAddress:="A0008蓝湿牛皮!A1", TextToDisplay:="A0008蓝湿牛皮")
  2930. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(9, 3), Address:="", SubAddress:="A0008有机鞣料!A1", TextToDisplay:="A0008有机鞣料")
  2931. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(10, 3), Address:="", SubAddress:="A0008无机鞣料!A1", TextToDisplay:="A0008无机鞣料")
  2932. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(11, 3), Address:="", SubAddress:="'A0008合成油脂(矿)'!A1", TextToDisplay:="A0008合成油脂(矿)")
  2933. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(12, 3), Address:="", SubAddress:="A0008合成油脂!A1", TextToDisplay:="A0008合成油脂")
  2934. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(13, 3), Address:="", SubAddress:="A0008皮革整理剂!A1", TextToDisplay:="A0008皮革整理剂")
  2935. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(14, 3), Address:="", SubAddress:="A0008表面活性剂!A1", TextToDisplay:="A0008表面活性剂")
  2936. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(15, 3), Address:="", SubAddress:="A0008复鞣助剂!A1", TextToDisplay:="A0008复鞣助剂")
  2937. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(16, 3), Address:="", SubAddress:="A0008制革染料!A1", TextToDisplay:="A0008制革染料")
  2938. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(17, 3), Address:="", SubAddress:="A0008聚氨酯混合液!A1", TextToDisplay:="A0008聚氨酯混合液")
  2939. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(18, 3), Address:="", SubAddress:="A0008PU树脂!A1", TextToDisplay:="A0008PU树脂")
  2940. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(19, 3), Address:="", SubAddress:="A0008皮革促进剂!A1", TextToDisplay:="A0008皮革促进剂")
  2941. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(8, 4), Address:="", SubAddress:="A0006蓝湿牛皮!A1", TextToDisplay:="A0006蓝湿牛皮")
  2942. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(9, 4), Address:="", SubAddress:="A0006有机鞣料!A1", TextToDisplay:="A0006有机鞣料")
  2943. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(10, 4), Address:="", SubAddress:="A0006无机鞣料!A1", TextToDisplay:="A0006无机鞣料")
  2944. ' xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(11, 3), Address:="", SubAddress:="A0006'合成油脂(矿)'!A1", TextToDisplay:="合成油脂(矿)")
  2945. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(12, 4), Address:="", SubAddress:="A0006合成油脂!A1", TextToDisplay:="A0006合成油脂")
  2946. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(13, 4), Address:="", SubAddress:="A0006皮革整理剂!A1", TextToDisplay:="A0006皮革整理剂")
  2947. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(14, 4), Address:="", SubAddress:="A0006表面活性剂!A1", TextToDisplay:="A0006表面活性剂")
  2948. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(15, 4), Address:="", SubAddress:="A0006复鞣助剂!A1", TextToDisplay:="A0006复鞣助剂")
  2949. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(16, 4), Address:="", SubAddress:="A0006制革染料!A1", TextToDisplay:="A0006制革染料")
  2950. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(17, 4), Address:="", SubAddress:="A0006聚氨酯混合液!A1", TextToDisplay:="A0006聚氨酯混合液")
  2951. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(18, 4), Address:="", SubAddress:="A0006PU树脂!A1", TextToDisplay:="A0006PU树脂")
  2952. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(19, 4), Address:="", SubAddress:="A0006皮革促进剂!A1", TextToDisplay:="A0006皮革促进剂")
  2953. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(9, 6), Address:="", SubAddress:="'A0008有机鞣料--车间'!A1", TextToDisplay:="A0008有机鞣料--车间")
  2954. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(10, 6), Address:="", SubAddress:="'A0008无机鞣料--车间'!A1", TextToDisplay:="A0008无机鞣料--车间")
  2955. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(11, 6), Address:="", SubAddress:="'A0008合成油脂(矿)--车间'!A1", TextToDisplay:="A0008合成油脂(矿)--车间")
  2956. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(12, 6), Address:="", SubAddress:="'A0008合成油脂--车间'!A1", TextToDisplay:="A0008合成油脂--车间")
  2957. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(13, 6), Address:="", SubAddress:="'A0008皮革整理剂--车间'!A1", TextToDisplay:="A0008皮革整理剂--车间")
  2958. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(14, 6), Address:="", SubAddress:="'A0008表面活性剂--车间'!A1", TextToDisplay:="A0008表面活性剂--车间")
  2959. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(15, 6), Address:="", SubAddress:="'A0008复鞣助剂--车间'!A1", TextToDisplay:="A0008复鞣助剂--车间")
  2960. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(16, 6), Address:="", SubAddress:="'A0008制革染料--车间'!A1", TextToDisplay:="A0008制革染料--车间")
  2961. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(17, 6), Address:="", SubAddress:="'A0008聚氨酯混合液--车间'!A1", TextToDisplay:="聚氨酯混合液--车间")
  2962. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(18, 6), Address:="", SubAddress:="'A0008PU树脂--车间'!A1", TextToDisplay:="A0008PU树脂--车间")
  2963. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(19, 6), Address:="", SubAddress:="'A0008皮革促进剂--车间'!A1", TextToDisplay:="A0008皮革促进剂-车间")
  2964. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(9, 7), Address:="", SubAddress:="'A0006有机鞣料--车间'!A1", TextToDisplay:="A0006有机鞣料--车间")
  2965. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(10, 7), Address:="", SubAddress:="'A0006无机鞣料--车间'!A1", TextToDisplay:="A0006无机鞣料--车间")
  2966. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(11, 7), Address:="", SubAddress:="'A0006合成油脂(矿)--车间'!A1", TextToDisplay:="A0006合成油脂(矿)--车间")
  2967. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(12, 7), Address:="", SubAddress:="'A0006合成油脂--车间'!A1", TextToDisplay:="A0006合成油脂--车间")
  2968. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(13, 7), Address:="", SubAddress:="'A0006皮革整理剂--车间'!A1", TextToDisplay:="A0006皮革整理剂--车间")
  2969. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(14, 7), Address:="", SubAddress:="'A0006表面活性剂--车间'!A1", TextToDisplay:="A0006表面活性剂--车间")
  2970. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(15, 7), Address:="", SubAddress:="'A0006复鞣助剂--车间'!A1", TextToDisplay:="A0006复鞣助剂--车间")
  2971. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(16, 7), Address:="", SubAddress:="'A0006制革染料--车间'!A1", TextToDisplay:="A0006制革染料--车间")
  2972. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(17, 7), Address:="", SubAddress:="'A0006聚氨酯混合液--车间'!A1", TextToDisplay:="A0006聚氨酯混合液--车间")
  2973. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(18, 7), Address:="", SubAddress:="'A0006PU树脂--车间'!A1", TextToDisplay:="A0006PU树脂--车间")
  2974. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(19, 7), Address:="", SubAddress:="'A0006皮革促进剂--车间'!A1", TextToDisplay:="A0006皮革促进剂-车间")
  2975. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(9, 9), Address:="", SubAddress:="'A0008牛二层皮1--成品'!A1", TextToDisplay:="A0008牛二层皮1--成品")
  2976. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(10, 9), Address:="", SubAddress:="'A0008牛二层皮2--成品'!A1", TextToDisplay:="A0008牛二层皮2--成品")
  2977. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(11, 9), Address:="", SubAddress:="'A0008牛二层皮3--成品'!A1", TextToDisplay:="A0008牛二层皮3--成品")
  2978. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(12, 9), Address:="", SubAddress:="'A0008牛二层皮4--成品'!A1", TextToDisplay:="A0008牛二层皮4--成品")
  2979. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(13, 9), Address:="", SubAddress:="'A0008PU牛二层皮--成品'!A1", TextToDisplay:="A0008PU牛二层皮--成品")
  2980. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(9, 10), Address:="", SubAddress:="'A0006牛二层皮5--成品'!A1", TextToDisplay:="A0006牛二层皮5--成品")
  2981. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(10, 10), Address:="", SubAddress:="'A0006牛二层皮6--成品'!A1", TextToDisplay:="A0006牛二层皮6--成品")
  2982. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(13, 10), Address:="", SubAddress:="'A0006PU牛二层皮--成品'!A1", TextToDisplay:="A0006PU牛二层皮--成品")
  2983. xlSheet.Columns("A:K").EntireColumn.AutoFit
  2984. xlSheet.Rows("1:60").Entirerow.AutoFit
  2985. End Sub
  2986. Private Sub analysis_data(xno As String, m_name As String) '------ 保税仓进销存
  2987. sql = "SELECT date AS 日期, item_new AS 品名,m_in AS 入库数量, m_out as 出库数量, LEFT(xno, 12) AS 手册号, MONTH(date) AS 月份, name AS 明细 FROM RT_BG_IO WHERE item_new=N'" & m_name & "' and xno like '%0008%' and (date between '" & dtp1.Value & "' and '" & dtp2.Value & "')"
  2988. sql = "SELECT case when name like N'%入%' then date2 else date end AS 日期, item_new AS 品名,m_in AS 入库数量, m_out as 出库数量, LEFT(xno, 12) AS 手册号, case when name like N'%入%' then MONTH(date2) else month(date) end AS 月份, name AS 明细 FROM RT_BG_IO WHERE item_new=N'" & m_name & "' and xno like '%" & xno & "%'"
  2989. cmd.CommandText = sql
  2990. da.SelectCommand = cmd
  2991. dt1 = New DataTable
  2992. da.Fill(dt1)
  2993. dgv1.DataSource = dt1
  2994. xlSheet = xlBook.Worksheets.Add
  2995. xlSheet.Activate()
  2996. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(1, 1), Address:="", SubAddress:="总表!A1", TextToDisplay:="总表")
  2997. If dt1.Rows.Count = 0 Then
  2998. Exit Sub
  2999. End If
  3000. xlSheet.Cells(5, 5).select
  3001. dgv1.SelectAll()
  3002. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  3003. Me.dgv1.RowHeadersVisible = False
  3004. Clipboard.SetDataObject(dgv1.GetClipboardContent())
  3005. System.Threading.Thread.Sleep(1000)
  3006. xlApp.Rows("3:3").Select
  3007. xlApp.Range("a3").Activate()
  3008. ' xlApp.ActiveWindow.FreezePanes = True
  3009. xlApp.Range("B2").Select()
  3010. ' xlSheet.PasteSpecial("Unicode 文本", False, False)
  3011. xlSheet.PasteSpecial()
  3012. Clipboard.SetDataObject(DBNull.Value)
  3013. ' xlApp.Visible = True
  3014. xlSheet.Columns("B:B").ColumnWidth = 15
  3015. xlSheet.Columns("c:c").ColumnWidth = 12
  3016. xlSheet.Columns("D:D").ColumnWidth = 22
  3017. xlSheet.Columns("e:e").ColumnWidth = 14
  3018. ' xlSheet.Columns("A:L").EntireColumn.AutoFit
  3019. xlSheet.Rows("1:500").Entirerow.AutoFit
  3020. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$2:$H$" & dt1.Rows.Count + 2), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  3021. 'Create the Cache
  3022. PTCache = xlApp.ActiveWorkbook.PivotCaches.Create(SourceType:=Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlDatabase, SourceData:=xlApp.Range("$B$2:$H$" & dt1.Rows.Count + 2))
  3023. 'Select the destination sheet
  3024. xlSheet.Range("J2").Select()
  3025. 'Create the Pivot table
  3026. PT = xlSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=xlSheet.Range("J2"), TableName:="Pivot1")
  3027. xlApp.ActiveWorkbook.ShowPivotTableFieldList = True
  3028. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("日期")
  3029. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField
  3030. .Position = 1
  3031. End With
  3032. With xlApp.ActiveSheet.PivotTables("pivot1")
  3033. .AddDataField(xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("入库数量"), "加总-入库数量", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  3034. .AddDataField(xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("出库数量"), "加总-出库数量", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  3035. ' .AddDataField(xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("入库数量"), "入库累计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  3036. '.AddDataField(xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("出库数量"), "出库累计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  3037. End With
  3038. xlApp.ActiveSheet.PivotTables("pivot1").CalculatedFields.Add("入库", "=入库数量", True)
  3039. xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("入库").Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlDataField
  3040. xlApp.ActiveSheet.PivotTables("pivot1").CalculatedFields.Add("入库累计", "=入库数量", True)
  3041. xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("入库累计").Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlDataField
  3042. xlApp.ActiveSheet.PivotTables("pivot1").CalculatedFields.Add("出库累计", "=出库数量", True)
  3043. xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("出库累计").Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlDataField
  3044. 'With xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("求和项:入库")
  3045. ' .Calculation = Microsoft.Office.Interop.Excel.XlPivotFieldCalculation.xlRunningTotal
  3046. ' .BaseField = "日期"
  3047. ' .NumberFormat = "#,##0.000"
  3048. 'End With
  3049. With xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("求和项:入库")
  3050. .Calculation = Microsoft.Office.Interop.Excel.XlPivotFieldCalculation.xlRunningTotal
  3051. .BaseField = "日期"
  3052. .NumberFormat = "#,##0.000"
  3053. End With
  3054. With xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("求和项:入库累计")
  3055. .Calculation = Microsoft.Office.Interop.Excel.XlPivotFieldCalculation.xlRunningTotal
  3056. .BaseField = "日期"
  3057. .NumberFormat = "#,##0.000"
  3058. End With
  3059. 'With xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("加總:入库累计")
  3060. ' .Calculation = Microsoft.Office.Interop.Excel.XlPivotFieldCalculation.xlRunningTotal
  3061. ' .BaseField = "日期"
  3062. ' .NumberFormat = "#,##0.000"
  3063. 'End With
  3064. With xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("求和项:出库累计")
  3065. .Calculation = Microsoft.Office.Interop.Excel.XlPivotFieldCalculation.xlRunningTotal
  3066. .BaseField = "日期"
  3067. .NumberFormat = "#,##0.000"
  3068. End With
  3069. 'With xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("加總:出库累计")
  3070. ' .Calculation = Microsoft.Office.Interop.Excel.XlPivotFieldCalculation.xlRunningTotal
  3071. ' .BaseField = "日期"
  3072. ' .NumberFormat = "#,##0.000"
  3073. 'End With
  3074. Dim x As Integer = 0
  3075. For x = 3 To 50000
  3076. If xlSheet.Cells(x, 10).value.ToString = "总计" Then
  3077. Exit For
  3078. End If
  3079. Next
  3080. xlApp.Columns("M:M").Select
  3081. xlApp.Selection.EntireColumn.Hidden = True
  3082. 'xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("求和项:入库").Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlHidden
  3083. 'xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("加總:入库").Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlHidden
  3084. xlSheet.Range("p4").FormulaR1C1 = "=RC[-2]-RC[-1]"
  3085. xlSheet.Range("p4").Select()
  3086. xlApp.Selection.AutoFill(Destination:=xlApp.Range("p4:p" & x - 1))
  3087. xlSheet.Cells(2, 16).value = "结存"
  3088. ' xlSheet.Range("P:P").NumberFormat = "#,##0.000;[红色](0.00)"
  3089. ' xlSheet.Range("K:L").NumberFormat = "#,##0.000;[红色](0.00)"
  3090. xlSheet.Columns("P:P").ColumnWidth = 14.11
  3091. ' xlSheet.Columns("P:P").NumberFormat = "#,##0.000;[红色](0.00)"
  3092. End Sub
  3093. Private Sub analysis_finish(xno As String, m_name As String) '-------成品进销存
  3094. sql = "SELECT LEFT(xno, 12) AS 手册号, item AS 品名, name AS 明细, date AS 入库日期, MONTH(date) AS 入库月份, CAST(m_in AS numeric(10, 1)) AS 入库数量, CAST(m_out AS numeric(10, 1)) AS 出库数量, CASE WHEN m_in <> 0 THEN m_in WHEN m_out <> 0 THEN - m_out END AS io FROM RT_BG_IO WHERE (item =N'" & m_name & "') AND (xno LIKE '%" & xno & "%') ORDER BY 入库日期"
  3095. dt1 = New DataTable
  3096. cmd.CommandText = sql
  3097. da.SelectCommand = cmd
  3098. da.Fill(dt1)
  3099. dt1.Columns.Add("结存")
  3100. Dim my_qty As Decimal = 0
  3101. For x As Integer = 0 To dt1.Rows.Count - 1
  3102. If x = 0 Then
  3103. dt1.Rows(x).Item("结存") = dt1.Rows(x).Item("io")
  3104. my_qty = dt1.Rows(x).Item("结存")
  3105. Else
  3106. dt1.Rows(x).Item("结存") = my_qty + dt1.Rows(x).Item("io")
  3107. my_qty = dt1.Rows(x).Item("结存")
  3108. End If
  3109. Next
  3110. dgv1.DataSource = dt1
  3111. xlSheet = xlBook.Worksheets.Add
  3112. xlSheet.Name = xno & m_name & "--成品"
  3113. xlSheet.Activate()
  3114. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(1, 1), Address:="", SubAddress:="总表!A1", TextToDisplay:="总表")
  3115. xlSheet.Cells(5, 5).select
  3116. dgv1.SelectAll()
  3117. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  3118. Me.dgv1.RowHeadersVisible = False
  3119. Clipboard.SetDataObject(dgv1.GetClipboardContent())
  3120. xlApp.Rows("3:3").Select
  3121. xlApp.Range("a3").Activate()
  3122. ' xlApp.ActiveWindow.FreezePanes = True
  3123. xlApp.Range("B2").Select()
  3124. System.Threading.Thread.Sleep(1000)
  3125. xlSheet.PasteSpecial("Unicode 文本", False, False)
  3126. Clipboard.SetDataObject(DBNull.Value)
  3127. ' xlApp.Visible = True
  3128. xlSheet.Columns("B:B").ColumnWidth = 15
  3129. xlSheet.Columns("c:c").ColumnWidth = 12
  3130. xlSheet.Columns("D:D").ColumnWidth = 22
  3131. xlSheet.Columns("e:e").ColumnWidth = 14
  3132. xlSheet.Columns("A:L").EntireColumn.AutoFit
  3133. xlSheet.Rows("1:500").Entirerow.AutoFit
  3134. 'xlSheet.Cells("O2").value = "结存"
  3135. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$2:$J$" & dt1.Rows.Count + 2), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  3136. xlSheet.Columns("j:j").Select
  3137. xlApp.Selection.Style = "Comma"
  3138. xlApp.Selection.NumberFormatLocal = "#,###.00_ ;[红色]-#,###.00 "
  3139. End Sub
  3140. Private Sub analysis_data_1(xno As String, m_name As String) '------核算料件领料是否倒挂
  3141. sql = "SELECT DISTINCT 领料日期, MONTH(领料日期) AS 领料月份 FROM (SELECT TOP (100) PERCENT RIGHT(RT_BG_IO.xno, 5) AS 手册号, RT_BG_IO.item AS 成品, RT_BG_IO.name AS 明细, RT_BG_IO.m_in AS 入库数量, RT_BG_IO.date AS 入库日期, RT_BG_COM.NAME AS 料件, RT_BG_COM.PERCENTS AS 单耗, RT_BG_COM.PERCENTS * RT_BG_IO.m_in AS 料件耗用, CASE WHEN rt_bg_com.name LIKE N'%聚%' THEN DATEADD(day, - 2, RT_BG_IO.date) WHEN rt_bg_com.name LIKE N'%pu%' OR rt_bg_com.name LIKE N'%促%' THEN DATEADD(day, - 3, RT_BG_IO.date) WHEN rt_bg_com.name LIKE N'%蓝%' THEN DATEADD(day, - 14, RT_BG_IO.date) ELSE DATEADD(day, - 7, RT_BG_IO.date) END AS 领料日期 FROM RT_BG_IO INNER JOIN RT_BG_COM ON LEFT(RT_BG_IO.xno, 12) = RT_BG_COM.XNO AND RT_BG_IO.item = RT_BG_COM.product1 WHERE (RT_BG_IO.name LIKE '%入%') AND (RT_BG_IO.m_in <> 0) ORDER BY 入库数量) AS p WHERE (手册号 = '" & xno & "') AND (料件 = N'" & m_name & "') AND (料件耗用 <> 0) ORDER BY 领料日期"
  3142. cmd.CommandText = sql
  3143. Dim my_date As Date
  3144. my_date = cmd.ExecuteScalar
  3145. sql = "SELECT SUM(m_out) AS 保税出库数量 FROM RT_BG_IO WHERE (xno like '%" & xno & "' and item_new = N'" & m_name & "' and date<='" & String.Format("{0:d}", my_date) & "') GROUP BY xno"
  3146. cmd.CommandText = sql
  3147. da.SelectCommand = cmd
  3148. Dim q_begin As Decimal = 0
  3149. q_begin = cmd.ExecuteScalar
  3150. '------------------------0------1-----2-----3---------4------5-----6-----7---------8-----------9
  3151. sql = "SELECT DISTINCT 手册号, 成品, 明细, 入库数量, 入库日期, 料件, 单耗, 料件耗用, 领料日期, MONTH(领料日期) AS 领料月份 FROM (SELECT TOP (100) PERCENT RIGHT(RT_BG_IO.xno, 5) AS 手册号, RT_BG_IO.item AS 成品, RT_BG_IO.name AS 明细, RT_BG_IO.m_in AS 入库数量, RT_BG_IO.date AS 入库日期, RT_BG_COM.NAME AS 料件, RT_BG_COM.PERCENTS AS 单耗, RT_BG_COM.PERCENTS * RT_BG_IO.m_in AS 料件耗用, CASE WHEN rt_bg_com.name LIKE N'%聚%' THEN DATEADD(day, - 2, RT_BG_IO.date) WHEN rt_bg_com.name LIKE N'%pu%' OR rt_bg_com.name LIKE N'%促%' THEN DATEADD(day, - 3, RT_BG_IO.date) WHEN rt_bg_com.name LIKE N'%蓝%' THEN DATEADD(day, - 14, RT_BG_IO.date) ELSE DATEADD(day, - 7, RT_BG_IO.date) END AS 领料日期 FROM RT_BG_IO INNER JOIN RT_BG_COM ON LEFT(RT_BG_IO.xno, 12) = RT_BG_COM.XNO AND RT_BG_IO.item = RT_BG_COM.product1 WHERE (RT_BG_IO.name LIKE '%入%') AND (RT_BG_IO.m_in <> 0) ORDER BY 入库数量) AS p WHERE (手册号 ='" & xno & "') AND (料件 = N'" & m_name & "') AND (料件耗用 <> 0) ORDER BY 领料日期"
  3152. dt1 = New DataTable
  3153. cmd.CommandText = sql
  3154. da.SelectCommand = cmd
  3155. da.Fill(dt1)
  3156. dt1.Columns.Add("结存")
  3157. Dim myRow As DataRow
  3158. myRow = dt1.NewRow
  3159. ' myRow(0) = xno
  3160. 'myRow(5) =
  3161. myRow(10) = q_begin
  3162. dt1.Rows.InsertAt(myRow, 0)
  3163. sql = "SELECT item, name, year, month, date1,m_out, bal, xno, date, id, item_new FROM RT_BG_IO WHERE (xno like '%" & xno & "') AND (item_new = N'" & m_name & "') AND (m_out <> 0) and date >'" & String.Format("{0:d}", my_date) & "'"
  3164. cmd.CommandText = sql
  3165. da.SelectCommand = cmd
  3166. Dim dt2 As New DataTable
  3167. da.Fill(dt2)
  3168. For z As Integer = 0 To dt2.Rows.Count - 1
  3169. myRow = dt1.NewRow
  3170. myRow(7) = dt2.Rows(z).Item("m_out")
  3171. myRow(8) = dt2.Rows(z).Item("date")
  3172. myRow(9) = Month(dt2.Rows(z).Item("date"))
  3173. dt1.Rows.InsertAt(myRow, dt1.Rows.Count)
  3174. Next
  3175. dt1.DefaultView.Sort = "领料日期,手册号"
  3176. Dim dt11 As New DataTable
  3177. dt11 = dt1.DefaultView.ToTable()
  3178. Dim my_begin As Decimal = 0
  3179. For z As Integer = 0 To dt11.Rows.Count - 1
  3180. If z = 0 Then
  3181. my_begin = dt11.Rows(z).Item("结存")
  3182. Else
  3183. If IsDBNull(dt11.Rows(z).Item("手册号")) Then
  3184. my_begin = my_begin + dt11.Rows(z).Item("料件耗用")
  3185. Else
  3186. my_begin = my_begin - dt11.Rows(z).Item("料件耗用")
  3187. End If
  3188. dt11.Rows(z).Item("结存") = my_begin
  3189. End If
  3190. Next
  3191. dgv1.DataSource = dt11
  3192. 'sql = "SELECT date AS 日期, item_new AS 品名,m_in AS 入库数量, m_out as 出库数量, LEFT(xno, 12) AS 手册号, MONTH(date) AS 月份, name AS 明细 FROM RT_BG_IO WHERE item_new=N'" & m_name & "' and xno like '%0008%'"
  3193. 'cmd.CommandText = sql
  3194. 'da.SelectCommand = cmd
  3195. 'dt1 = New DataTable
  3196. 'da.Fill(dt1)
  3197. 'dgv1.DataSource = dt1
  3198. xlSheet = xlBook.Worksheets.Add
  3199. xlSheet.Name = xno & m_name & "--车间"
  3200. xlSheet.Activate()
  3201. xlSheet.Hyperlinks.Add(Anchor:=xlSheet.Cells(1, 1), Address:="", SubAddress:="总表!A1", TextToDisplay:="总表")
  3202. xlSheet.Cells(5, 5).select
  3203. dgv1.SelectAll()
  3204. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  3205. Me.dgv1.RowHeadersVisible = False
  3206. Clipboard.SetDataObject(dgv1.GetClipboardContent())
  3207. System.Threading.Thread.Sleep(1000)
  3208. 'xlApp.Rows("3:3").Select
  3209. 'xlApp.Range("a3").Activate()
  3210. ' xlApp.ActiveWindow.FreezePanes = True
  3211. xlApp.Range("B2").Select()
  3212. ' ExcelPackage.LicenseContext = LicenseContext.NonCommercial
  3213. ' Dim filepath As New System.IO.FileInfo("d:\123.xlsx")
  3214. 'Dim Package As New ExcelPackage(filepath)
  3215. 'Dim wks As ExcelWorksheet = Package.Workbook.Worksheets.Add(xlSheet.Name)
  3216. 'wks.Cells("A1").LoadFromDataTable(dt11, True)
  3217. 'Package.Save()
  3218. ' xlApp.Cells("B2").LoadFromDataTable(dt11, True)
  3219. ' xlSheet.PasteSpecial("Unicode 文本", False, False)
  3220. xlSheet.Paste()
  3221. Clipboard.SetDataObject(DBNull.Value)
  3222. ' xlApp.Visible = True
  3223. xlSheet.Columns("B:B").ColumnWidth = 15
  3224. xlSheet.Columns("c:c").ColumnWidth = 12
  3225. xlSheet.Columns("D:D").ColumnWidth = 22
  3226. xlSheet.Columns("e:e").ColumnWidth = 14
  3227. xlSheet.Columns("A:L").EntireColumn.AutoFit
  3228. xlSheet.Rows("1:500").Entirerow.AutoFit
  3229. 'xlSheet.Cells("O2").value = "结存"
  3230. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$2:$L$" & dt11.Rows.Count + 2), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  3231. xlSheet.Columns("L:L").Select
  3232. xlApp.Selection.NumberFormatLocal = "0.00_ ;[红色]-0.00 "
  3233. 'Create the Cache
  3234. 'PTCache = xlApp.ActiveWorkbook.PivotCaches.Create(SourceType:=Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlDatabase, SourceData:=xlApp.Range("$B$2:$H$" & dt1.Rows.Count + 2))
  3235. ''Select the destination sheet
  3236. 'xlSheet.Range("J2").Select()
  3237. ''Create the Pivot table
  3238. 'PT = xlSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=xlSheet.Range("J2"), TableName:="Pivot1")
  3239. 'xlApp.ActiveWorkbook.ShowPivotTableFieldList = True
  3240. 'With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("日期")
  3241. ' .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField
  3242. ' .Position = 1
  3243. 'End With
  3244. 'With xlApp.ActiveSheet.PivotTables("pivot1")
  3245. ' .AddDataField(xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("入库数量"), "入库数量", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  3246. ' .AddDataField(xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("出库数量"), "出库数量", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  3247. ' ' .AddDataField(xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("入库数量"), "入库累计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  3248. ' '.AddDataField(xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("出库数量"), "出库累计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  3249. 'End With
  3250. 'xlApp.ActiveSheet.PivotTables("pivot1").CalculatedFields.Add("入库", "=入库数量", True)
  3251. 'xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("入库").Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlDataField
  3252. 'xlApp.ActiveSheet.PivotTables("pivot1").CalculatedFields.Add("入库累计", "=入库数量", True)
  3253. 'xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("入库累计").Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlDataField
  3254. 'xlApp.ActiveSheet.PivotTables("pivot1").CalculatedFields.Add("出库累计", "=出库数量", True)
  3255. 'xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("出库累计").Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlDataField
  3256. 'With xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("求和项:入库")
  3257. ' .Calculation = Microsoft.Office.Interop.Excel.XlPivotFieldCalculation.xlRunningTotal
  3258. ' .BaseField = "日期"
  3259. ' .NumberFormat = "#,##0.000"
  3260. 'End With
  3261. 'With xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("求和项:入库累计")
  3262. ' .Calculation = Microsoft.Office.Interop.Excel.XlPivotFieldCalculation.xlRunningTotal
  3263. ' .BaseField = "日期"
  3264. ' .NumberFormat = "#,##0.000"
  3265. 'End With
  3266. 'With xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("求和项:出库累计")
  3267. ' .Calculation = Microsoft.Office.Interop.Excel.XlPivotFieldCalculation.xlRunningTotal
  3268. ' .BaseField = "日期"
  3269. ' .NumberFormat = "#,##0.000"
  3270. 'End With
  3271. 'Dim x As Integer = 0
  3272. 'For x = 3 To 50000
  3273. ' If xlSheet.Cells(x, 10).value.ToString = "总计" Then
  3274. ' Exit For
  3275. ' End If
  3276. 'Next
  3277. 'xlApp.ActiveSheet.PivotTables("pivot1").PivotFields("求和项:入库").Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlHidden
  3278. 'xlSheet.Range("o3").FormulaR1C1 = "=RC[-2]-RC[-1]"
  3279. 'xlSheet.Range("o3").Select()
  3280. 'xlApp.Selection.AutoFill(Destination:=xlApp.Range("o3:o" & x))
  3281. End Sub
  3282. Private Sub Button8_Click_1(sender As Object, e As EventArgs) Handles Button8.Click
  3283. sql = "SELECT distinct 手册号, 成品, 明细, 出库数量, 出库日期, 料件, 单耗, 料件耗用, 领料日期, MONTH(领料日期) AS 领料月份 FROM (SELECT TOP (100) PERCENT LEFT(RT_BG_IO.xno, 12) AS 手册号, RT_BG_IO.item AS 成品, RT_BG_IO.name AS 明细, RT_BG_IO.m_out AS 出库数量, RT_BG_IO.date AS 出库日期, RT_BG_COM.NAME AS 料件, RT_BG_COM.PERCENTS AS 单耗, RT_BG_COM.PERCENTS * RT_BG_IO.m_out AS 料件耗用, CASE WHEN rt_bg_com.name LIKE N'%聚%' THEN DATEADD(day, - 2, RT_BG_IO.date) WHEN rt_bg_com.name LIKE N'%pu%' OR rt_bg_com.name LIKE N'%促%' THEN DATEADD(day, - 3, RT_BG_IO.date) WHEN rt_bg_com.name LIKE N'%蓝%' THEN DATEADD(day, - 14, RT_BG_IO.date) ELSE DATEADD(day, - 7, RT_BG_IO.date) END AS 领料日期 FROM RT_BG_IO INNER JOIN RT_BG_COM ON LEFT(RT_BG_IO.xno, 12) = RT_BG_COM.XNO AND RT_BG_IO.item = RT_BG_COM.product1 WHERE (RT_BG_IO.item LIKE N'%牛二层皮%') AND (RT_BG_IO.name LIKE '%出%') AND (RT_BG_IO.m_out <> 0) AND (date between '" & dtp1.Value & "' and '" & dtp2.Value & "') ORDER BY 出库数量) AS p"
  3284. cmd.CommandText = sql
  3285. da.SelectCommand = cmd
  3286. Dim dt1 As New DataTable
  3287. da.Fill(dt1)
  3288. If dt1.Rows.Count = 0 Then
  3289. MsgBox("查无记录")
  3290. Exit Sub
  3291. End If
  3292. dgv1.DataSource = dt1
  3293. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  3294. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  3295. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  3296. Dim xlRange As Microsoft.Office.Interop.Excel.Range
  3297. xlApp = CreateObject("Excel.Application")
  3298. xlApp.Visible = False
  3299. xlApp.DisplayAlerts = False
  3300. xlBook = xlApp.Workbooks.Add
  3301. xlSheet = xlBook.Worksheets(1)
  3302. xlSheet.Name = "料件领料汇总"
  3303. xlSheet.Activate()
  3304. xlSheet.Cells(5, 5).select
  3305. dgv1.SelectAll()
  3306. Me.dgv1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText
  3307. Me.dgv1.RowHeadersVisible = False
  3308. Clipboard.SetDataObject(dgv1.GetClipboardContent())
  3309. xlApp.Range("B30").Select()
  3310. xlSheet.Paste()
  3311. xlApp.Visible = True
  3312. '''' xlApp.ActiveSheet.Paste
  3313. ''''xlApp.CutCopyMode = False
  3314. xlApp.ActiveSheet.ListObjects.Add(Microsoft.Office.Interop.Excel.XlListObjectSourceType.xlSrcRange, xlApp.Range("$B$30:$k$" & dt1.Rows.Count + 30), , Microsoft.Office.Interop.Excel.XlYesNoGuess.xlYes).Name = "表1"
  3315. Dim PTCache As Microsoft.Office.Interop.Excel.PivotCache
  3316. Dim PT As Microsoft.Office.Interop.Excel.PivotTable
  3317. 'Create the Cache
  3318. PTCache = xlApp.ActiveWorkbook.PivotCaches.Create(SourceType:=Microsoft.Office.Interop.Excel.XlPivotTableSourceType.xlDatabase, SourceData:=xlApp.Range("$B$30:$k$" & dt1.Rows.Count + 30))
  3319. 'Select the destination sheet
  3320. xlSheet.Range("b2").Select()
  3321. 'Create the Pivot table
  3322. PT = xlSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=xlSheet.Range("B2"), TableName:="Pivot1")
  3323. xlApp.ActiveWorkbook.ShowPivotTableFieldList = True
  3324. 'Adding fields
  3325. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("料件")
  3326. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlRowField
  3327. .Position = 1
  3328. End With
  3329. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("领料月份")
  3330. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  3331. .Position = 1
  3332. End With
  3333. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("手册号")
  3334. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  3335. .Position = 1
  3336. End With
  3337. With xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("成品")
  3338. .Orientation = Microsoft.Office.Core.XlPivotFieldOrientation.xlColumnField
  3339. .Position = 1
  3340. End With
  3341. With xlApp.ActiveSheet.PivotTables("pivot1")
  3342. .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("料件耗用"), "耗用合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  3343. End With
  3344. 'With xlApp.ActiveSheet.PivotTables("pivot1")
  3345. ' .AddDataField(xlApp.ActiveSheet.PivotTables("Pivot1").PivotFields("货值"), "货值合计", Microsoft.Office.Interop.Excel.XlConsolidationFunction.xlSum)
  3346. 'End With
  3347. xlApp.Visible = True
  3348. xlApp = Nothing
  3349. xlBook = Nothing
  3350. xlSheet = Nothing
  3351. End Sub
  3352. Private Sub dgv2_MouseDown(sender As Object, e As MouseEventArgs) Handles dgv2.MouseDown
  3353. End Sub
  3354. Private Sub dgv3_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgv3.CellContentClick
  3355. End Sub
  3356. Private Sub dgv3_MouseUp(sender As Object, e As MouseEventArgs) Handles dgv3.MouseUp
  3357. Dim x As Double = 0
  3358. Dim y As Double = 0
  3359. For i As Integer = 0 To dgv2.SelectedRows.Count - 1
  3360. x = x + Math.Round(dgv2.Rows(dgv2.SelectedRows.Item(i).Index).Cells("尺数").Value, 1)
  3361. Next i
  3362. TextBox3.Text = dgv2.SelectedRows.Count
  3363. TextBox2.Text = x
  3364. End Sub
  3365. Private Sub Button16_Click_1(sender As Object, e As EventArgs) Handles Button16.Click
  3366. Frm_wb_out_1.Show()
  3367. End Sub
  3368. Private Sub Button17_Click_1(sender As Object, e As EventArgs) Handles Button17.Click
  3369. Frm_Print_report.Show()
  3370. End Sub
  3371. Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click
  3372. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  3373. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  3374. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  3375. Dim dt As New DataTable
  3376. Dim file_name As String = ""
  3377. Dim file_name1 As String = ""
  3378. Dim my_weight As Double = 0
  3379. Dim a As Integer = 0
  3380. Dim my_count As Integer = 0
  3381. 'OpenFileDialog1.Multiselect = True
  3382. If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
  3383. file_name = OpenFileDialog1.FileName
  3384. file_name1 = OpenFileDialog1.SafeFileName
  3385. Else
  3386. Exit Sub
  3387. End If
  3388. xlApp = CreateObject("Excel.Application")
  3389. xlApp.Visible = True
  3390. xlApp.DisplayAlerts = False
  3391. 'sql = "delete from rt_bg_io"
  3392. 'cmd.CommandText = sql
  3393. 'cmd.ExecuteNonQuery()
  3394. xlBook = xlApp.Workbooks.Open(file_name,, True)
  3395. xlBook.Activate()
  3396. If ListBox1.Items(0) Like "*076*" Then '----------------------------------------------- 蓝皮入库
  3397. For i = 1 To xlApp.Worksheets.Count
  3398. If xlApp.Workbooks(1).Worksheets(i).name = "金威利" Then
  3399. xlSheet = xlApp.Workbooks(1).Worksheets(i)
  3400. xlSheet.Activate()
  3401. Exit For
  3402. End If
  3403. Next
  3404. xlSheet.Range("a1:q17").Copy()
  3405. For y As Integer = 0 To dgv1.Rows.Count - 2
  3406. xlApp.Range("a" & 1 + 17 * (y + 1)).Select()
  3407. xlSheet.Paste()
  3408. Next y
  3409. ' Dim MY_DATE As Date = dgv2.Rows(0).Cells("进厂日期").Value
  3410. Dim MY_COUNT1 As Integer = 0
  3411. Dim MY_ITEM As Integer = 0
  3412. For y As Integer = 0 To dgv2.Rows.Count - 1
  3413. MY_COUNT1 = MY_COUNT1 - 1
  3414. MY_ITEM = MY_ITEM + 1
  3415. xlSheet.Cells(2 + y * 17, 3) = "金威利"
  3416. xlSheet.Cells(6 + y * 17, 1) = dgv1.Rows(y).Cells("颜色").Value
  3417. xlSheet.Cells(6 + y * 17, 3) = dgv1.Rows(y).Cells("类别").Value
  3418. xlSheet.Cells(6 + y * 17, 4) = dgv1.Rows(y).Cells("厚度").Value
  3419. xlSheet.Cells(6 + y * 17, 6) = dgv1.Rows(y).Cells("尺数").Value
  3420. xlSheet.Cells(11 + y * 17, 2) = dgv1.Rows(y).Cells("订单号").Value
  3421. xlSheet.Cells(11 + y * 17, 5) = dgv1.Rows(y).Cells("指令号").Value
  3422. xlSheet.Cells(11 + y * 17, 16) = dgv1.Rows(y).Cells("尺数").Value
  3423. Next
  3424. End If
  3425. Dim yy As Integer = 0
  3426. xlApp = Nothing
  3427. xlBook = Nothing
  3428. xlSheet = Nothing
  3429. MsgBox("")
  3430. End Sub
  3431. Private Sub Button31_Click(sender As Object, e As EventArgs) Handles Button31.Click
  3432. Frm_AC.ShowDialog()
  3433. End Sub
  3434. Private Sub Button32_Click(sender As Object, e As EventArgs) Handles Button32.Click
  3435. analysis_data_1("A0008", "合成油脂(矿)")
  3436. End Sub
  3437. Private Sub Button33_Click(sender As Object, e As EventArgs) Handles Button33.Click
  3438. Dim dt As New DataTable
  3439. Dim file_name As String = ""
  3440. Dim a As Integer = 0
  3441. Dim my_count As Integer = 0
  3442. If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
  3443. file_name = OpenFileDialog1.FileName
  3444. Else
  3445. Exit Sub
  3446. End If
  3447. Dim filepath As String = Me.Button33.Text
  3448. Dim sourceFileName As String = file_name
  3449. Dim address2 As String = "ftp://" & my_ip & ":7788/K3/即时库存/" & OpenFileDialog1.SafeFileName
  3450. Dim address3() As String
  3451. address3 = Split(address2, "ftp://" & my_ip & ":7788/K3/即时库存/")
  3452. Dim add4 As String
  3453. add4 = "d:\k3\" & address3(1)
  3454. add4 = "d:\k3\即时库存\" & OpenFileDialog1.SafeFileName
  3455. Dim userName As String = "matchy3c"
  3456. Dim password As String = "Lafayette11"
  3457. Dim showUI As Boolean = True
  3458. Dim connectionTimeout As Integer = 500
  3459. Dim client As WebClient = New WebClient
  3460. client.Credentials = New NetworkCredential(userName, password)
  3461. ' client.Proxy = GlobalProxySelection.GetEmptyWebProxy()
  3462. client.UploadFile(address2, sourceFileName)
  3463. sql = "delete from rt_realtime_stock" '----
  3464. ' sql = "delete from rt_sys_chem_out " '----化料
  3465. cmd.CommandText = sql
  3466. cmd.ExecuteNonQuery()
  3467. sql = "Select * FROM OPENDATASOURCE ('Microsoft.ACE.OLEDB.12.0','Excel 12.0;HDR=Yes;IMEX=1;Database=" & add4 & "')... [车间化料$]"
  3468. cmd.CommandText = sql
  3469. da.SelectCommand = cmd
  3470. da.Fill(dt)
  3471. ' dgv1.DataSource = dt
  3472. Dim my_sqlbulk As New SqlBulkCopy(conn)
  3473. my_sqlbulk.DestinationTableName = "dbo.rt_realtime_stock"
  3474. my_sqlbulk.WriteToServer(dt)
  3475. sql = "SELECT cls, CLASS2 AS 海关分类, SUM(qty) AS 数量
  3476. FROM (SELECT CASE WHEN matl_no LIKE '%.s.%' THEN N'保税' ELSE N'国内' END AS cls, RT_realtime_stock.matl_name,
  3477. RT_realtime_stock.qty, RT_SYS_CHEM_MAIN.CLASS2
  3478. FROM RT_realtime_stock LEFT OUTER JOIN
  3479. RT_SYS_CHEM_MAIN ON RT_realtime_stock.matl_name = RT_SYS_CHEM_MAIN.name) AS p
  3480. WHERE (CLASS2 IS NOT NULL) AND (CLASS2 <> '') AND (CLASS2 <> 'PU')
  3481. GROUP BY CLASS2, cls
  3482. ORDER BY 海关分类 DESC"
  3483. cmd.CommandText = sql
  3484. dt = New DataTable
  3485. da.SelectCommand = cmd
  3486. da.Fill(dt)
  3487. dgv1.DataSource = dt
  3488. dt = New DataTable
  3489. sql = "delete from rt_realtime_stock" '----
  3490. ' sql = "delete from rt_sys_chem_out " '----化料
  3491. cmd.CommandText = sql
  3492. cmd.ExecuteNonQuery()
  3493. sql = "Select * FROM OPENDATASOURCE ('Microsoft.ACE.OLEDB.12.0','Excel 12.0;HDR=Yes;IMEX=1;Database=" & add4 & "')... [保税仓$]"
  3494. cmd.CommandText = sql
  3495. da.SelectCommand = cmd
  3496. da.Fill(dt)
  3497. ' dgv2.DataSource = dt
  3498. my_sqlbulk.DestinationTableName = "dbo.rt_realtime_stock"
  3499. my_sqlbulk.WriteToServer(dt)
  3500. sql = "SELECT cls, CLASS2 AS 海关分类, SUM(qty) AS 数量
  3501. FROM (SELECT CASE WHEN matl_no LIKE '%.s.%' THEN N'保税' ELSE N'国内' END AS cls, RT_realtime_stock.matl_name,
  3502. RT_realtime_stock.qty, RT_SYS_CHEM_MAIN.CLASS2
  3503. FROM RT_realtime_stock LEFT OUTER JOIN
  3504. RT_SYS_CHEM_MAIN ON RT_realtime_stock.matl_name = RT_SYS_CHEM_MAIN.name) AS p
  3505. WHERE (CLASS2 IS NOT NULL) AND (CLASS2 <> '') AND (CLASS2 <> 'PU')
  3506. GROUP BY CLASS2, cls
  3507. ORDER BY 海关分类 DESC"
  3508. cmd.CommandText = sql
  3509. dt = New DataTable
  3510. da.SelectCommand = cmd
  3511. da.Fill(dt)
  3512. dgv2.DataSource = dt
  3513. MsgBox("完成")
  3514. End Sub
  3515. Private Sub dgv2_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgv2.CellContentClick
  3516. End Sub
  3517. Private Sub dgv2_CellMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgv2.CellMouseClick
  3518. End Sub
  3519. Private Sub Button34_Click(sender As Object, e As EventArgs) Handles Button34.Click
  3520. sql = " update rt_ship_uz_hg set class='fm7' where name like '%黑色%' and name not like '%action%' and name not like '%PU%' and name not like N'%榔%' "
  3521. cmd.CommandText = sql
  3522. cmd.ExecuteNonQuery()
  3523. sql = " update rt_ship_uz_hg set class='fm8' where name not like '%黑色%' and name not like '%action%' and name not like '%PU%' and name not like N'%榔%' "
  3524. cmd.CommandText = sql
  3525. cmd.ExecuteNonQuery()
  3526. sql = " update rt_ship_uz_hg set class='PU3' where name not like '%黑色%' and (name like '%action%' or name like '%PU%' or name like N'%榔%') "
  3527. cmd.CommandText = sql
  3528. cmd.ExecuteNonQuery()
  3529. sql = " update rt_ship_uz_hg set class='PU5' where name like '%黑色%' and (name like '%action%' or name like '%PU%' or name like N'%榔%') "
  3530. cmd.CommandText = sql
  3531. cmd.ExecuteNonQuery()
  3532. sql = "select diff from (select no,rank() over (order by cast(no as integer)) as 序号, cast(no as integer)- rank() over (order by cast(no as integer)) as diff from rt_ship_uz_hg where class='fm7' ) as q group by diff order by diff" '-----fm7
  3533. cmd.CommandText = sql
  3534. Dim dt As New DataTable
  3535. da.SelectCommand = cmd
  3536. da.Fill(dt)
  3537. Dim begin As Boolean = False
  3538. Dim mystring As String = "牛二层皮7 "
  3539. Dim begin_diff As Integer
  3540. Dim a As Integer = 0
  3541. For x As Integer = 0 To dt.Rows.Count - 1
  3542. a = 0
  3543. sql = "select no from (select no,rank() over (order by cast(no as integer)) as 序号, cast(no as integer)- rank() over (order by cast(no as integer)) as diff from rt_ship_uz_hg where class='fm7' ) as p where diff=" & dt.Rows(x).Item("diff") & " order by cast(no as integer) "
  3544. cmd.CommandText = sql
  3545. mystring = mystring & "第" & cmd.ExecuteScalar & "~"
  3546. a = a + 1
  3547. sql = "select top(1) no from (select no,rank() over (order by cast(no as integer)) as 序号, cast(no as integer)- rank() over (order by cast(no as integer)) as diff from rt_ship_uz_hg where class='fm7' ) as p where diff=" & dt.Rows(x).Item("diff") & " order by cast(no as integer) desc"
  3548. cmd.CommandText = sql
  3549. mystring = mystring & cmd.ExecuteScalar & "件 / "
  3550. Next
  3551. If dt.Rows.Count > 0 Then
  3552. ListBox2.Items.Add(mystring)
  3553. End If
  3554. sql = "select diff from (select no,rank() over (order by cast(no as integer)) as 序号, cast(no as integer)- rank() over (order by cast(no as integer)) as diff from rt_ship_uz_hg where class='fm8' ) as q group by diff order by diff" '-----fm8
  3555. cmd.CommandText = sql
  3556. dt = New DataTable
  3557. da.SelectCommand = cmd
  3558. da.Fill(dt)
  3559. mystring = "牛二层皮8 "
  3560. For x As Integer = 0 To dt.Rows.Count - 1
  3561. sql = "select no from (select no,rank() over (order by cast(no as integer)) as 序号, cast(no as integer)- rank() over (order by cast(no as integer)) as diff from rt_ship_uz_hg where class='fm8' ) as p where diff=" & dt.Rows(x).Item("diff") & " order by cast(no as integer) "
  3562. cmd.CommandText = sql
  3563. mystring = mystring & "第" & cmd.ExecuteScalar & "~"
  3564. sql = "select top(1) no from (select no,rank() over (order by cast(no as integer)) as 序号, cast(no as integer)- rank() over (order by cast(no as integer)) as diff from rt_ship_uz_hg where class='fm8' ) as p where diff=" & dt.Rows(x).Item("diff") & " order by cast(no as integer) desc"
  3565. cmd.CommandText = sql
  3566. mystring = mystring & cmd.ExecuteScalar & "件 / "
  3567. Next
  3568. If dt.Rows.Count <> 0 Then
  3569. ListBox2.Items.Add(mystring)
  3570. End If
  3571. sql = "select diff from (select no,rank() over (order by cast(no as integer)) as 序号, cast(no as integer)- rank() over (order by cast(no as integer)) as diff from rt_ship_uz_hg where class='pu3' ) as q group by diff order by diff" '-----pu3
  3572. cmd.CommandText = sql
  3573. dt = New DataTable
  3574. da.SelectCommand = cmd
  3575. da.Fill(dt)
  3576. mystring = "PU牛二层皮3 "
  3577. For x As Integer = 0 To dt.Rows.Count - 1
  3578. sql = "select no from (select no,rank() over (order by cast(no as integer)) as 序号, cast(no as integer)- rank() over (order by cast(no as integer)) as diff from rt_ship_uz_hg where class='pu3' ) as p where diff=" & dt.Rows(x).Item("diff") & " order by cast(no as integer) "
  3579. cmd.CommandText = sql
  3580. mystring = mystring & "第" & cmd.ExecuteScalar & "~"
  3581. sql = "select top(1) no from (select no,rank() over (order by cast(no as integer)) as 序号, cast(no as integer)- rank() over (order by cast(no as integer)) as diff from rt_ship_uz_hg where class='pu3' ) as p where diff=" & dt.Rows(x).Item("diff") & " order by cast(no as integer) desc"
  3582. cmd.CommandText = sql
  3583. mystring = mystring & cmd.ExecuteScalar & "件 / "
  3584. Next
  3585. If dt.Rows.Count <> 0 Then
  3586. ListBox2.Items.Add(mystring)
  3587. End If
  3588. sql = "select diff from (select no,rank() over (order by cast(no as integer)) as 序号, cast(no as integer)- rank() over (order by cast(no as integer)) as diff from rt_ship_uz_hg where class='pu5' ) as q group by diff order by diff" '-----pu5
  3589. cmd.CommandText = sql
  3590. dt = New DataTable
  3591. da.SelectCommand = cmd
  3592. da.Fill(dt)
  3593. mystring = "PU牛二层皮5 "
  3594. For x As Integer = 0 To dt.Rows.Count - 1
  3595. sql = "select no from (select no,rank() over (order by cast(no as integer)) as 序号, cast(no as integer)- rank() over (order by cast(no as integer)) as diff from rt_ship_uz_hg where class='pu5' ) as p where diff=" & dt.Rows(x).Item("diff") & " order by cast(no as integer) "
  3596. cmd.CommandText = sql
  3597. mystring = mystring & "第" & cmd.ExecuteScalar & "~"
  3598. sql = "select top(1) no from (select no,rank() over (order by cast(no as integer)) as 序号, cast(no as integer)- rank() over (order by cast(no as integer)) as diff from rt_ship_uz_hg where class='pu5' ) as p where diff=" & dt.Rows(x).Item("diff") & " order by cast(no as integer) desc"
  3599. cmd.CommandText = sql
  3600. mystring = mystring & cmd.ExecuteScalar & "件 / "
  3601. Next
  3602. If dt.Rows.Count <> 0 Then
  3603. ListBox2.Items.Add(mystring)
  3604. End If
  3605. End Sub
  3606. Private Sub Button35_Click(sender As Object, e As EventArgs) Handles Button35.Click
  3607. Dim xlApp As Microsoft.Office.Interop.Excel.Application
  3608. Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
  3609. Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
  3610. Dim dt As New DataTable
  3611. Dim file_name As String = ""
  3612. Dim file_name1 As String = ""
  3613. ListBox1.Items.Clear()
  3614. Dim my_weight As Double = 0
  3615. Dim a As Integer = 0
  3616. Dim my_count As Integer = 0
  3617. 'OpenFileDialog1.Multiselect = True
  3618. If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
  3619. file_name = OpenFileDialog1.FileName
  3620. file_name1 = OpenFileDialog1.SafeFileName
  3621. Else
  3622. Exit Sub
  3623. End If
  3624. xlApp = CreateObject("Excel.Application")
  3625. xlApp.Visible = True
  3626. xlApp.DisplayAlerts = False
  3627. xlBook = xlApp.Workbooks.Open(file_name)
  3628. xlBook.Activate()
  3629. xlApp.Rows.Item("1:11").delete
  3630. xlBook.Save()
  3631. ' xlBook.Close()
  3632. xlBook.Application.Quit()
  3633. xlApp.Application.Quit()
  3634. KillExcel(xlApp)
  3635. xlBook = Nothing
  3636. xlApp = Nothing
  3637. Dim yy As Integer = 0
  3638. Dim filepath As String = "k3/在制品"
  3639. Dim sourceFileName As String = file_name
  3640. Dim address2 As String = "ftp://" & my_ip & ":7788/" & filepath & "/" & OpenFileDialog1.SafeFileName
  3641. Dim address3() As String
  3642. address3 = Split(address2, "ftp://" & my_ip & ":7788/")
  3643. Dim add4 As String
  3644. add4 = "d:\k3\在制品\" & OpenFileDialog1.SafeFileName
  3645. Dim userName As String = "matchy3c"
  3646. Dim password As String = "Lafayette11"
  3647. Dim showUI As Boolean = True
  3648. Dim connectionTimeout As Integer = 500
  3649. ' System.Threading.Thread.Sleep(30000)
  3650. Dim client As WebClient = New WebClient
  3651. client.Credentials = New NetworkCredential(userName, password)
  3652. 'client.Proxy = GlobalProxySelection.GetEmptyWebProxy()
  3653. client.UploadFile(address2, sourceFileName)
  3654. sql = "delete from rt_inprocess_crust"
  3655. cmd.CommandText = sql
  3656. cmd.ExecuteScalar()
  3657. sql = "Select * FROM OPENDATASOURCE ('Microsoft.ACE.OLEDB.12.0','Excel 12.0;HDR=Yes;IMEX=1;Database=" & add4 & "')... ['1$']"
  3658. cmd.CommandText = sql
  3659. da.SelectCommand = cmd
  3660. da.Fill(dt)
  3661. dgv1.DataSource = dt
  3662. Dim my_sqlbulk As New SqlBulkCopy(conn)
  3663. my_sqlbulk.DestinationTableName = "dbo.rt_inprocess_crust"
  3664. my_sqlbulk.WriteToServer(dt)
  3665. MsgBox("ok")
  3666. End Sub
  3667. Private Sub KillExcel(ByVal objExcel As Object)
  3668. Try
  3669. If objExcel IsNot Nothing Then
  3670. Dim lProcessIdAddr As Integer
  3671. Dim iPID As Integer
  3672. iPID = GetWindowThreadProcessId(objExcel.Hwnd, lProcessIdAddr)
  3673. System.Diagnostics.Process.GetProcessById(lProcessIdAddr).Kill()
  3674. End If
  3675. Catch ex As Exception
  3676. End Try
  3677. End Sub
  3678. Private Sub Button36_Click(sender As Object, e As EventArgs) Handles Button36.Click
  3679. Dim str = ListBox1.Items(0).ToString
  3680. Select Case True
  3681. Case str Like "*076*"
  3682. For x As Integer = 0 To dgv1.Rows.Count - 1
  3683. sql = "update rt_ship_076_1 set deli_no='" & dgv1.Rows(x).Cells("发货单号").Value & "' where order_no =N'" & dgv1.Rows(x).Cells("订单号").Value & "'
  3684. and i_no=N'" & dgv1.Rows(x).Cells("指令号").Value & "'and color=N'" & dgv1.Rows(x).Cells("颜色").Value & "' and thick='" & dgv1.Rows(x).Cells("厚度").Value & "'"
  3685. cmd.CommandText = sql
  3686. cmd.ExecuteScalar()
  3687. Next
  3688. Case str Like "*澳孚*"
  3689. For x As Integer = 0 To dgv1.Rows.Count - 1
  3690. sql = "update rt_ship_daily_af set deli_no='" & dgv1.Rows(x).Cells("发货单号").Value & "' where po_no =N'" & dgv1.Rows(x).Cells("订单号").Value & "'
  3691. and work_no=N'" & dgv1.Rows(x).Cells("指令号").Value & "'"
  3692. cmd.CommandText = sql
  3693. cmd.ExecuteScalar()
  3694. Next
  3695. Case str Like "*威弘*"
  3696. For x As Integer = 0 To dgv1.Rows.Count - 1
  3697. sql = "update rt_ship_daily_wh set deli_no='" & dgv1.Rows(x).Cells("发货单号").Value & "' where order_no =N'" & dgv1.Rows(x).Cells("订单号").Value & "'
  3698. and i_no=N'" & dgv1.Rows(x).Cells("指令号").Value & "'and color=N'" & dgv1.Rows(x).Cells("颜色").Value & "' and thick='" & dgv1.Rows(x).Cells("厚度").Value & "'"
  3699. cmd.CommandText = sql
  3700. cmd.ExecuteScalar()
  3701. Next
  3702. Case str Like "*永正发货*"
  3703. For x As Integer = 0 To dgv1.Rows.Count - 1
  3704. sql = "update rt_ship_daily_uz_1 set deli_no='" & dgv1.Rows(x).Cells("发货单号").Value & "' where po_no =N'" & dgv1.Rows(x).Cells("订单号").Value & "'
  3705. and order_item=N'" & dgv1.Rows(x).Cells("项次号").Value & "'and name=N'" & dgv1.Rows(x).Cells("品名").Value & "'"
  3706. cmd.CommandText = sql
  3707. cmd.ExecuteScalar()
  3708. Next
  3709. Case str Like "*极路客*"
  3710. For x As Integer = 0 To dgv1.Rows.Count - 1
  3711. sql = "update rt_ship_daily_jlk set deli_no='" & dgv1.Rows(x).Cells("发货单号").Value & "' where color =N'" & dgv1.Rows(x).Cells("颜色").Value & "'
  3712. and thick=N'" & dgv1.Rows(x).Cells("厚度").Value & "'"
  3713. cmd.CommandText = sql
  3714. cmd.ExecuteScalar()
  3715. Next
  3716. Case str Like "*上杰发货*"
  3717. For x As Integer = 0 To dgv1.Rows.Count - 1
  3718. sql = "update rt_ship_daily_sj set deli_no='" & dgv1.Rows(x).Cells("发货单号").Value & "' where po_no =N'" & dgv1.Rows(x).Cells("订单号").Value & "'
  3719. and order_item=N'" & dgv1.Rows(x).Cells("项次号").Value & "'and name=N'" & dgv1.Rows(x).Cells("品名").Value & "'"
  3720. cmd.CommandText = sql
  3721. cmd.ExecuteScalar()
  3722. Next
  3723. Case str Like "*SAMIL*"
  3724. For x As Integer = 0 To dgv1.Rows.Count - 2
  3725. sql = "update rt_ship_daily_samil set deli_no='" & dgv1.Rows(x).Cells("发货单号").Value & "' where po_no =N'" & dgv1.Rows(x).Cells("订单号").Value.ToString.Replace("'", "''") & "'
  3726. and name=N'" & dgv1.Rows(x).Cells("品名").Value & "'"
  3727. cmd.CommandText = sql
  3728. cmd.ExecuteScalar()
  3729. Next
  3730. Case str Like "*亿博*" And Not (str Like "*亿博样*")
  3731. For x As Integer = 0 To dgv1.Rows.Count - 1
  3732. sql = "update rt_ship_daily_yb set deli_no='" & dgv1.Rows(x).Cells("发货单号").Value & "' where po_no =N'" & dgv1.Rows(x).Cells("订单号").Value & "'
  3733. and name=N'" & dgv1.Rows(x).Cells("品名").Value & "'"
  3734. cmd.CommandText = sql
  3735. cmd.ExecuteScalar()
  3736. Next
  3737. Case str Like "*亿博*" And (str Like "*华盛*")
  3738. For x As Integer = 0 To dgv1.Rows.Count - 1
  3739. sql = "update rt_ship_daily_yby_huasheng set deli_no='" & dgv1.Rows(x).Cells("发货单号").Value & "' where po_no =N'" & dgv1.Rows(x).Cells("订单号").Value & "'
  3740. and name=N'" & dgv1.Rows(x).Cells("品名").Value & "'"
  3741. cmd.CommandText = sql
  3742. cmd.ExecuteScalar()
  3743. Next
  3744. Case str Like "*亿博样*" And Not (str Like "*华盛*")
  3745. For x As Integer = 0 To dgv1.Rows.Count - 1
  3746. sql = "update rt_ship_daily_yby set deli_no='" & dgv1.Rows(x).Cells("发货单号").Value & "' where po_no =N'" & dgv1.Rows(x).Cells("订单号").Value & "'
  3747. and name=N'" & dgv1.Rows(x).Cells("品名").Value & "'"
  3748. cmd.CommandText = sql
  3749. cmd.ExecuteScalar()
  3750. Next
  3751. Case str Like "*PEI HAI*"
  3752. For x As Integer = 0 To dgv1.Rows.Count - 1
  3753. sql = "update rt_ship_daily_xbh set deli_no='" & dgv1.Rows(x).Cells("发货单号").Value & "' where po_no =N'" & dgv1.Rows(x).Cells("订单号").Value & "'
  3754. and name=N'" & dgv1.Rows(x).Cells("品名").Value & "'"
  3755. cmd.CommandText = sql
  3756. cmd.ExecuteScalar()
  3757. Next
  3758. Case str Like "*EVERGREE*"
  3759. For x As Integer = 0 To dgv1.Rows.Count - 1
  3760. sql = "update rt_ship_daily_evergree set deli_no='" & dgv1.Rows(x).Cells("发货单号").Value & "' where po_no =N'" & dgv1.Rows(x).Cells("订单号").Value & "'
  3761. and name=N'" & dgv1.Rows(x).Cells("品名").Value & "'"
  3762. cmd.CommandText = sql
  3763. cmd.ExecuteScalar()
  3764. Next
  3765. Case str Like "*PROPERWELL*"
  3766. For x As Integer = 0 To dgv1.Rows.Count - 1
  3767. sql = "update rt_ship_daily_PROPERWELL set deli_no='" & dgv1.Rows(x).Cells("发货单号").Value & "' where po_no =N'" & dgv1.Rows(x).Cells("订单号").Value & "'
  3768. and name=N'" & dgv1.Rows(x).Cells("品名").Value & "'"
  3769. cmd.CommandText = sql
  3770. cmd.ExecuteScalar()
  3771. Next
  3772. Case str Like "*STELLA*"
  3773. For x As Integer = 0 To dgv1.Rows.Count - 1
  3774. sql = "update rt_ship_daily_Stella set deli_no='" & dgv1.Rows(x).Cells("发货单号").Value & "' where po_no =N'" & dgv1.Rows(x).Cells("订单号").Value & "'
  3775. and name=N'" & dgv1.Rows(x).Cells("品名").Value & "'"
  3776. cmd.CommandText = sql
  3777. cmd.ExecuteScalar()
  3778. Next
  3779. Case str Like "*THANH*"
  3780. For x As Integer = 0 To dgv1.Rows.Count - 1
  3781. sql = "update rt_ship_daily_thanhhu set deli_no='" & dgv1.Rows(x).Cells("发货单号").Value & "' where po_no =N'" & dgv1.Rows(x).Cells("订单号").Value & "'
  3782. and name=N'" & dgv1.Rows(x).Cells("品名").Value & "'"
  3783. cmd.CommandText = sql
  3784. cmd.ExecuteScalar()
  3785. Next
  3786. Case str Like "*锐奇*"
  3787. For x As Integer = 0 To dgv1.Rows.Count - 1
  3788. sql = "update rt_ship_daily_ruiqi set deli_no='" & dgv1.Rows(x).Cells("发货单号").Value & "' where po_no =N'" & dgv1.Rows(x).Cells("采购号").Value & "'
  3789. and name=N'" & dgv1.Rows(x).Cells("品名").Value & "' and work_no=N'" & dgv1.Rows(x).Cells("订单号").Value & "'"
  3790. cmd.CommandText = sql
  3791. cmd.ExecuteScalar()
  3792. Next
  3793. Case str Like "*穎億*"
  3794. For x As Integer = 0 To dgv1.Rows.Count - 1
  3795. sql = "update rt_ship_daily_yy set deli_no='" & dgv1.Rows(x).Cells("发货单号").Value & "' where po_no =N'" & dgv1.Rows(x).Cells("订单号").Value & "'
  3796. and name=N'" & dgv1.Rows(x).Cells("品名").Value & "' and work_no=N'" & dgv1.Rows(x).Cells("指令号").Value & "'"
  3797. cmd.CommandText = sql
  3798. cmd.ExecuteScalar()
  3799. Next
  3800. End Select
  3801. MsgBox("更新完成")
  3802. End Sub
  3803. End Class