ExcelHandler.cs 341 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408
  1. using System.IO;
  2. using System.Data;
  3. using NPOI.HSSF.UserModel;
  4. using NPOI.SS.UserModel;
  5. using NPOI.HSSF.Util;
  6. using NPOI.XSSF.UserModel;
  7. using System;
  8. using UAS_LabelMachine.Entity;
  9. using UAS_LabelMachine.PublicMethod;
  10. using System.Collections.Generic;
  11. using System.Windows.Forms;
  12. using System.Text.RegularExpressions;
  13. namespace UAS_LabelMachine
  14. {
  15. class ExcelHandler
  16. {
  17. DataHelper dh = SystemInf.dh;
  18. //展示抬头日期的索引
  19. int ShowDataIndex = 7;
  20. //展示芯片尺寸的索引
  21. int ShowSizeIndex = 5;
  22. //显示计数的索引
  23. int ShowCountIndex = 2;
  24. //显示片数的索引
  25. int ShowPieceIndex = 1;
  26. //显示备注的片
  27. int ShowRemarkPiece = 5;
  28. int NumIndex = 0;
  29. /// <summary>
  30. /// 导出Excel,返回文件在客户端的路径
  31. /// </summary>
  32. public string ExportExcel(DataTable dt, string FolderPath, string FileName)
  33. {
  34. //创建一个内存流,用来接收转换成Excel的内容
  35. MemoryStream ms;
  36. ms = DataTableToExcel(dt);
  37. //以系统当前时间命名文件,FileMode.Create表示创建文件,FileAccess.Write表示拥有写的权限
  38. string filePath = @FolderPath + "\\" + FileName + ".xls";
  39. FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
  40. byte[] data = ms.ToArray();
  41. fs.Write(data, 0, data.Length);
  42. fs.Flush();
  43. //释放当前Excel文件,否则打开文件的时候会显示文件被占用
  44. ms.Dispose();
  45. fs.Dispose();
  46. return filePath;
  47. }
  48. /// <summary>
  49. /// 导出Excel,返回文件在客户端的路径
  50. /// </summary>
  51. public string ExportExcel_Normal(DataTable firstsdt, DataTable dt, string FolderPath, string FileName, string Type, int PageSize, List<CheckBox> conditionbox)
  52. {
  53. //创建一个内存流,用来接收转换成Excel的内容
  54. MemoryStream ms;
  55. ms = DataTableToExcel_Normal(firstsdt, dt, Type, FileName, PageSize, conditionbox);
  56. //以系统当前时间命名文件,FileMode.Create表示创建文件,FileAccess.Write表示拥有写的权限
  57. string filePath = @FolderPath + "\\" + FileName + ".xls";
  58. int counter = 1;
  59. string filename = FileName + ".xls";
  60. while (File.Exists(filePath))
  61. {
  62. filename = string.Format("{0}({1}){2}", FileName, counter, ".xls"); //文件名+(count)+后缀
  63. filePath = Path.Combine(FolderPath, filename); //保存路径
  64. counter++; //count+1
  65. }
  66. FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
  67. byte[] data = ms.ToArray();
  68. fs.Write(data, 0, data.Length);
  69. fs.Flush();
  70. //释放当前Excel文件,否则打开文件的时候会显示文件被占用
  71. ms.Dispose();
  72. fs.Dispose();
  73. return filePath;
  74. }
  75. /// <summary>
  76. /// 晶源客户特殊方案
  77. /// </summary>
  78. public string JINYUAN(DataTable firstsdt, DataTable dt, string FolderPath, string FileName, string Type, int PageSize, List<CheckBox> conditionbox)
  79. {
  80. //创建一个内存流,用来接收转换成Excel的内容
  81. MemoryStream ms;
  82. ms = DataTableToExcel_JINYUAN(firstsdt, dt, Type, FileName, PageSize, conditionbox);
  83. //以系统当前时间命名文件,FileMode.Create表示创建文件,FileAccess.Write表示拥有写的权限
  84. string filePath = @FolderPath + "\\" + FileName + ".xls";
  85. int counter = 1;
  86. string filename = FileName + ".xls";
  87. while (File.Exists(filePath))
  88. {
  89. filename = string.Format("{0}({1}){2}", FileName, counter, ".xls"); //文件名+(count)+后缀
  90. filePath = Path.Combine(FolderPath, filename); //保存路径
  91. counter++; //count+1
  92. }
  93. FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
  94. byte[] data = ms.ToArray();
  95. fs.Write(data, 0, data.Length);
  96. fs.Flush();
  97. //释放当前Excel文件,否则打开文件的时候会显示文件被占用
  98. ms.Dispose();
  99. fs.Dispose();
  100. return filePath;
  101. }
  102. /// <summary>
  103. /// 利普芯客户特殊方案
  104. /// </summary>
  105. public string LIPIUXIN(DataTable firstsdt, DataTable dt, string FolderPath, string FileName, string Type, int PageSize, List<CheckBox> conditionbox)
  106. {
  107. //创建一个内存流,用来接收转换成Excel的内容
  108. MemoryStream ms;
  109. ms = DataTableToExcel_LIPUXIN(firstsdt, dt, Type, FileName, PageSize, conditionbox);
  110. //以系统当前时间命名文件,FileMode.Create表示创建文件,FileAccess.Write表示拥有写的权限
  111. string filePath = @FolderPath + "\\" + FileName + ".xls";
  112. int counter = 1;
  113. string filename = FileName + ".xls";
  114. while (File.Exists(filePath))
  115. {
  116. filename = string.Format("{0}({1}){2}", FileName, counter, ".xls"); //文件名+(count)+后缀
  117. filePath = Path.Combine(FolderPath, filename); //保存路径
  118. counter++; //count+1
  119. }
  120. FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
  121. byte[] data = ms.ToArray();
  122. fs.Write(data, 0, data.Length);
  123. fs.Flush();
  124. //释放当前Excel文件,否则打开文件的时候会显示文件被占用
  125. ms.Dispose();
  126. fs.Dispose();
  127. return filePath;
  128. }
  129. public string HETONGGUANGDIAN(DataTable firstsdt, DataTable dt, string FolderPath, string FileName, string Type, int PageSize, List<CheckBox> conditionbox)
  130. {
  131. //创建一个内存流,用来接收转换成Excel的内容
  132. MemoryStream ms;
  133. ms = HETONGGUANGDIAN(firstsdt, dt, Type, FileName, PageSize, conditionbox);
  134. //以系统当前时间命名文件,FileMode.Create表示创建文件,FileAccess.Write表示拥有写的权限
  135. string filePath = @FolderPath + "\\" + FileName + ".xls";
  136. int counter = 1;
  137. string filename = FileName + ".xls";
  138. while (File.Exists(filePath))
  139. {
  140. filename = string.Format("{0}({1}){2}", FileName, counter, ".xls"); //文件名+(count)+后缀
  141. filePath = Path.Combine(FolderPath, filename); //保存路径
  142. counter++; //count+1
  143. }
  144. FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
  145. byte[] data = ms.ToArray();
  146. fs.Write(data, 0, data.Length);
  147. fs.Flush();
  148. //释放当前Excel文件,否则打开文件的时候会显示文件被占用
  149. ms.Dispose();
  150. fs.Dispose();
  151. return filePath;
  152. }
  153. /// <summary>
  154. /// 导入Excel
  155. /// </summary>
  156. public void ImportExcel(DataTable DataTable, string TableName)
  157. {
  158. int columnNum = DataTable.Columns.Count;
  159. int rowNum = DataTable.Columns.Count;
  160. string[] field = new string[columnNum];
  161. for (int i = 0; i < columnNum; i++)
  162. {
  163. field[i] = DataTable.Rows[0][i].ToString();
  164. }
  165. }
  166. public static DataTable ExcelToDataTable(string filePath, bool isColumnName)
  167. {
  168. DataTable dataTable = null;
  169. FileStream fs = null;
  170. DataColumn column = null;
  171. DataRow dataRow = null;
  172. IWorkbook workbook = null;
  173. ISheet sheet = null;
  174. IRow row = null;
  175. ICell cell = null;
  176. int startRow = 0;
  177. try
  178. {
  179. using (fs = File.OpenRead(filePath))
  180. {
  181. // 2007版本
  182. if (filePath.IndexOf(".xlsx") > 0)
  183. {
  184. workbook = new XSSFWorkbook(fs);
  185. }
  186. // 2003版本
  187. else if (filePath.IndexOf(".xls") > 0)
  188. {
  189. workbook = new HSSFWorkbook(fs);
  190. }
  191. if (workbook != null)
  192. {
  193. sheet = workbook.GetSheetAt(0);//读取第一个sheet,当然也可以循环读取每个sheet
  194. dataTable = new DataTable();
  195. if (sheet != null)
  196. {
  197. int rowCount = sheet.LastRowNum;//总行数
  198. if (rowCount > 0)
  199. {
  200. IRow firstRow = sheet.GetRow(0);//第一行
  201. int cellCount = firstRow.LastCellNum;//列数
  202. //构建datatable的列
  203. if (isColumnName)
  204. {
  205. startRow = 1;//如果第一行是列名,则从第二行开始读取
  206. for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
  207. {
  208. cell = firstRow.GetCell(i);
  209. if (cell != null)
  210. {
  211. if (cell.StringCellValue != null)
  212. {
  213. column = new DataColumn(cell.StringCellValue);
  214. dataTable.Columns.Add(column);
  215. }
  216. }
  217. }
  218. }
  219. else
  220. {
  221. for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
  222. {
  223. column = new DataColumn("column" + (i + 1));
  224. dataTable.Columns.Add(column);
  225. }
  226. }
  227. //填充行
  228. for (int i = startRow; i <= rowCount; ++i)
  229. {
  230. row = sheet.GetRow(i);
  231. if (row == null) continue;
  232. dataRow = dataTable.NewRow();
  233. for (int j = row.FirstCellNum; j < cellCount; ++j)
  234. {
  235. cell = row.GetCell(j);
  236. if (cell == null)
  237. {
  238. dataRow[j] = "";
  239. }
  240. else
  241. {
  242. //CellType(Unknown = -1,Numeric = 0,String = 1,Formula = 2,Blank = 3,Boolean = 4,Error = 5,)
  243. switch (cell.CellType)
  244. {
  245. case CellType.Blank:
  246. dataRow[j] = "";
  247. break;
  248. case CellType.Numeric:
  249. short format = cell.CellStyle.DataFormat;
  250. //对时间格式(2015.12.5、2015/12/5、2015-12-5等)的处理
  251. if (format == 14 || format == 31 || format == 57 || format == 58)
  252. dataRow[j] = cell.DateCellValue;
  253. else
  254. dataRow[j] = cell.NumericCellValue;
  255. break;
  256. case CellType.String:
  257. dataRow[j] = cell.StringCellValue;
  258. break;
  259. }
  260. }
  261. }
  262. dataTable.Rows.Add(dataRow);
  263. }
  264. }
  265. }
  266. }
  267. }
  268. return dataTable;
  269. }
  270. catch (Exception)
  271. {
  272. if (fs != null)
  273. {
  274. fs.Close();
  275. }
  276. return null;
  277. }
  278. }
  279. int RowHeight = 12;
  280. /// <summary>
  281. /// 将DataTable形式的数据转成Excel格式的,然后用字节流的形式写入文件
  282. /// </summary>
  283. /// <param name="DataTable"></param>
  284. /// <returns></returns>
  285. public MemoryStream DataTableToExcel(DataTable DataTable)
  286. {
  287. //创建内存流
  288. MemoryStream ms = new MemoryStream();
  289. //创建一个Book,相当于一个Excel文件
  290. HSSFWorkbook book = new HSSFWorkbook();
  291. //Excel中的Sheet
  292. ISheet sheet = book.CreateSheet("sheet1");
  293. //获取行数量和列数量
  294. int rowNum = DataTable.Rows.Count;
  295. int columnNum = DataTable.Columns.Count;
  296. //设置列的宽度,根据首行的列的内容的长度来设置
  297. for (int i = 0; i < columnNum; i++)
  298. {
  299. int dataLength;
  300. //如果内容比标题短则取标题长度
  301. if (DataTable.Rows[0][i].ToString().Length < DataTable.Columns[i].ColumnName.Length)
  302. {
  303. dataLength = DataTable.Columns[i].ColumnName.Length;
  304. dataLength = dataLength * 300;
  305. }
  306. else
  307. {
  308. dataLength = DataTable.Rows[0][i].ToString().Length;
  309. dataLength = dataLength * 300;
  310. }
  311. sheet.SetColumnWidth(i, dataLength);
  312. }
  313. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  314. IRow row = sheet.CreateRow(0);
  315. //冻结第一行
  316. sheet.CreateFreezePane(0, 1, 0, 1);
  317. ICellStyle style = book.CreateCellStyle();
  318. style.FillForegroundColor = HSSFColor.PaleBlue.Index;
  319. style.FillPattern = FillPattern.BigSpots;
  320. style.FillBackgroundColor = HSSFColor.LightGreen.Index;
  321. //设置边框
  322. style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  323. style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  324. style.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  325. style.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  326. row.HeightInPoints = 20;
  327. //固定第一行
  328. //row.RowStyle.IsLocked=true;
  329. //给第一行的标签赋值样式和值
  330. for (int j = 0; j < columnNum; j++)
  331. {
  332. row.CreateCell(j);
  333. row.Cells[j].CellStyle = style;
  334. row.Cells[j].CellStyle.VerticalAlignment = VerticalAlignment.Center;
  335. row.Cells[j].CellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
  336. row.Cells[j].SetCellValue(DataTable.Columns[j].Caption);
  337. }
  338. //将DataTable的值循环赋值给book,Aligment设置居中
  339. //之前已经画了带颜色的第一行,所以从i=1开始画
  340. for (int i = 0; i < rowNum; i++)
  341. {
  342. IRow row1 = sheet.CreateRow(i + 1);
  343. row1.HeightInPoints = 20;
  344. for (int j = 0; j < columnNum; j++)
  345. {
  346. row1.CreateCell(j);
  347. row1.Cells[j].SetCellValue(DataTable.Rows[i][j].ToString());
  348. row1.GetCell(j).CellStyle.VerticalAlignment = VerticalAlignment.Center;
  349. }
  350. }
  351. //将book的内容写入内存流中返回
  352. book.Write(ms);
  353. return ms;
  354. }
  355. /// <summary>
  356. /// 将DataTable形式的数据转成Excel格式的,然后用字节流的形式写入文件
  357. /// </summary>
  358. /// <param name="DataTable"></param>
  359. /// <returns></returns>
  360. public MemoryStream DataTableToExcel_Normal(DataTable FirstDT, DataTable DataTable, string Type, string Inoutno, int PageSize, List<CheckBox> conditionbox)
  361. {
  362. string 小计 = "";
  363. string 总计 = "";
  364. string 片 = "";
  365. string companyname = "";
  366. Dictionary<int, double> PercentSum = new Dictionary<int, double>();
  367. if (dh.getFieldDataByCondition("ProdInout", "pi_exporttype", "pi_inoutno='" + Inoutno + "'").ToString() == "Chinese")
  368. {
  369. 小计 = "小计";
  370. 总计 = "总计";
  371. companyname = "深爱半导体股份有限公司芯片出货清单";
  372. }
  373. else
  374. {
  375. 小计 = "total";
  376. 总计 = "total";
  377. companyname = "SHENZHEN SI SEMICONDUCTORS CO.,LTD";
  378. }
  379. bool CountQty = false;
  380. if (dh.getFieldDataByCondition("ProdInout", "pi_exporttype1", "pi_inoutno='" + Inoutno + "'").ToString() == "QTY")
  381. {
  382. CountQty = true;
  383. }
  384. //转换为序列
  385. CheckBox[] box = conditionbox.ToArray();
  386. //创建内存流
  387. MemoryStream ms = new MemoryStream();
  388. //创建一个Book,相当于一个Excel文件
  389. HSSFWorkbook book = new HSSFWorkbook();
  390. //Excel中的Sheet
  391. ISheet sheet = book.CreateSheet("分页");
  392. sheet.SetMargin(MarginType.TopMargin, 0.4);
  393. sheet.SetMargin(MarginType.BottomMargin, 0.4);
  394. sheet.SetMargin(MarginType.LeftMargin, 0.4);
  395. sheet.SetMargin(MarginType.RightMargin, 0.4);
  396. sheet.FitToPage = true;
  397. sheet.PrintSetup.FitHeight = 200;
  398. //芯片号需要作为更新盒号的条件
  399. HSSFFont ffont = (HSSFFont)book.CreateFont();
  400. ffont.FontName = "宋体";
  401. //更新箱号
  402. List<string> pib_id = new List<string>();
  403. //系统打印箱号
  404. List<string> pib_outboxcode1 = new List<string>();
  405. int BoxCode = 1;
  406. ICellStyle style = book.CreateCellStyle();
  407. style.VerticalAlignment = VerticalAlignment.Center;
  408. style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  409. style.SetFont(ffont);
  410. ICellStyle styleborder = book.CreateCellStyle();
  411. styleborder.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  412. styleborder.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  413. styleborder.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  414. styleborder.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  415. styleborder.VerticalAlignment = VerticalAlignment.Center;
  416. styleborder.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  417. styleborder.SetFont(ffont);
  418. string pi_inoutno = "";
  419. HSSFFont ColumnTitle = (HSSFFont)book.CreateFont();
  420. ColumnTitle.FontName = "宋体";
  421. ColumnTitle.Boldweight = (short)FontBoldWeight.Bold;
  422. ICellStyle ColumnTitleStyle = book.CreateCellStyle();
  423. ColumnTitleStyle.SetFont(ColumnTitle);
  424. ColumnTitleStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  425. ColumnTitleStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  426. ColumnTitleStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  427. ColumnTitleStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  428. List<string> NotShowColumn = new List<string>();
  429. NotShowColumn.Add("ch_level");
  430. NotShowColumn.Add("pib_id");
  431. NotShowColumn.Add("chw_itemname1");
  432. NotShowColumn.Add("chw_itemname2");
  433. NotShowColumn.Add("chw_itemname3");
  434. NotShowColumn.Add("chw_itemname4");
  435. NotShowColumn.Add("chw_itemname5");
  436. NotShowColumn.Add("pd_ordercode");
  437. NotShowColumn.Add("pr_size");
  438. NotShowColumn.Add("me_desc");
  439. NotShowColumn.Add("pr_orispeccode");
  440. NotShowColumn.Add("pr_orispeccode1");
  441. NotShowColumn.Add("pi_title");
  442. NotShowColumn.Add("pi_chipouttype");
  443. NotShowColumn.Add("pi_date");
  444. int ShowColumnCount = 0;
  445. bool ShowSplitBatch = true;
  446. //展示的内容列
  447. //设置列的宽度,根据首行的列的内容的长度来设置
  448. for (int i = DataTable.Columns.Count - 1; i > 0; i--)
  449. {
  450. for (int j = 0; j < box.Length; j++)
  451. {
  452. if (box[j].Name.ToLower() == "ch_bluefilm" && !box[j].Checked)
  453. {
  454. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_bluefilm"))
  455. {
  456. DataTable.Columns.RemoveAt(i);
  457. break;
  458. }
  459. }
  460. if (box[j].Name.ToLower() == "ch_code" && !box[j].Checked)
  461. {
  462. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_code"))
  463. {
  464. DataTable.Columns.RemoveAt(i);
  465. break;
  466. }
  467. }
  468. if (box[j].Name.ToLower() == "ch_splitbatch" && !box[j].Checked)
  469. {
  470. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_splitbatch"))
  471. {
  472. DataTable.Columns.RemoveAt(i);
  473. break;
  474. }
  475. }
  476. if (box[j].Name.ToLower() == "ch_waterid" && !box[j].Checked)
  477. {
  478. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  479. {
  480. DataTable.Columns.RemoveAt(i);
  481. break;
  482. }
  483. }
  484. if (box[j].Name.ToLower() == "ch_pbcode" && !box[j].Checked)
  485. {
  486. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  487. {
  488. DataTable.Columns.RemoveAt(i);
  489. break;
  490. }
  491. }
  492. if (box[j].Name.ToLower() == "ch_remark" && !box[j].Checked)
  493. {
  494. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  495. {
  496. DataTable.Columns.RemoveAt(i);
  497. break;
  498. }
  499. }
  500. if (box[j].Name.ToLower() == "ch_yield" && !box[j].Checked)
  501. {
  502. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_yield"))
  503. {
  504. DataTable.Columns.RemoveAt(i);
  505. break;
  506. }
  507. }
  508. }
  509. }
  510. //获取行数量和列数量
  511. int rowNum = DataTable.Rows.Count;
  512. int columnNum = DataTable.Columns.Count;
  513. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  514. IRow row = sheet.CreateRow(0);
  515. //冻结第一行
  516. sheet.CreateFreezePane(0, 1, 0, 1);
  517. row.HeightInPoints = RowHeight;
  518. //固定第一行
  519. //row.RowStyle.IsLocked=true;
  520. //给第一行的标签赋值样式和值
  521. // ffont.FontHeight = 13;
  522. row.CreateCell(0);
  523. row.Cells[0].SetCellValue(" " + companyname);
  524. row.GetCell(0).CellStyle.SetFont((ffont));
  525. //ffont.FontHeight = 10;
  526. //开始绘制的Index
  527. int PaintIndex = 1;
  528. int sumCount = 0;
  529. int totalCount = 0;
  530. switch (Type)
  531. {
  532. case "FixRow":
  533. //清理系统取出来的数据
  534. BaseUtil.CleanDataTableData(FirstDT);
  535. //首页参数拼接
  536. string First_OrderCode = "";
  537. string First_Prspec = "";
  538. string First_Batch = "";
  539. ArrayList<string> First_WID = new ArrayList<string>();
  540. for (int i = 0; i < rowNum; i++)
  541. {
  542. IRow row1 = sheet.CreateRow(PaintIndex);
  543. PaintIndex = PaintIndex + 1;
  544. row1.HeightInPoints = RowHeight;
  545. //不包含的订单号
  546. if (DataTable.Columns.Contains("pd_ordercode") && !First_OrderCode.Contains(DataTable.Rows[i]["pd_ordercode"].ToString()))
  547. {
  548. First_OrderCode += DataTable.Rows[i]["pd_ordercode"].ToString() + " ";
  549. }
  550. //不包含的物料型号
  551. if (DataTable.Columns.Contains("pr_orispeccode") && !First_Prspec.Contains(DataTable.Rows[i]["pr_orispeccode"].ToString()))
  552. {
  553. First_Prspec += DataTable.Rows[i]["pr_orispeccode"].ToString() + " ";
  554. }
  555. //不包含扩撒批号
  556. if (DataTable.Columns.Contains("ch_splitbatch") && !First_Batch.Contains(DataTable.Rows[i]["ch_splitbatch"].ToString()))
  557. {
  558. First_Batch += DataTable.Rows[i]["ch_splitbatch"].ToString() + " ";
  559. }
  560. //不包含Wafer_id
  561. if (DataTable.Columns.Contains("Wafer_ID") && !First_WID.Contains(DataTable.Rows[i]["Wafer_ID"].ToString()))
  562. {
  563. First_WID.Add(DataTable.Rows[i]["Wafer_ID"].ToString());
  564. }
  565. if (i / PageSize >= 1 && i % PageSize == 0)
  566. {
  567. DataRow dr = FirstDT.NewRow();
  568. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  569. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  570. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  571. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  572. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  573. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  574. pi_inoutno = DataTable.Rows[i]["pi_inoutno"].ToString();
  575. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  576. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  577. dr["pd_ordercode"] = First_OrderCode;
  578. dr["pr_orispeccode"] = First_Prspec;
  579. dr["ch_splitbatch"] = First_Batch;
  580. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  581. dr["num"] = PageSize;
  582. dr["io_qty"] = sumCount;
  583. FirstDT.Rows.Add(dr);
  584. First_OrderCode = "";
  585. First_Prspec = "";
  586. First_Batch = "";
  587. First_WID.Clear();
  588. BoxCode = BoxCode + 1;
  589. for (int j = 0; j < ShowColumnCount; j++)
  590. {
  591. row1.CreateCell(j);
  592. if (j == 0)
  593. {
  594. row1.Cells[j].SetCellValue(小计);
  595. }
  596. else if (j == ShowPieceIndex)
  597. {
  598. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i));
  599. row1.Cells[j].CellStyle = styleborder;
  600. }
  601. else if (j == ShowCountIndex)
  602. {
  603. row1.Cells[j].SetCellValue(sumCount);
  604. }
  605. if (CountQty)
  606. {
  607. for (int k = 0; k < PercentSum.Count; k++)
  608. {
  609. if (PercentSum.ContainsKey(j))
  610. {
  611. if (PercentSum[j] != 0)
  612. {
  613. row1.Cells[j].SetCellValue(PercentSum[j] / PercentSum.Count);
  614. PercentSum[j] = 0;
  615. }
  616. }
  617. }
  618. }
  619. row1.Cells[j].CellStyle = styleborder;
  620. }
  621. sumCount = 0;
  622. row1 = sheet.CreateRow(PaintIndex);
  623. sheet.SetRowBreak(PaintIndex - 1);
  624. sheet.Footer.Center = "第&P页,共&N页";
  625. PaintIndex = PaintIndex + 1;
  626. }
  627. //每次到了页数开始分页
  628. if (i % PageSize == 0 || i == rowNum - 1)
  629. {
  630. //第一行添加客户信息 rownum只有一行的情
  631. if (i != rowNum - 1 || rowNum == 1 || (rowNum - i == rowNum % PageSize))
  632. {
  633. for (int j = 0; j < columnNum - 3; j++)
  634. {
  635. if (j == 0)
  636. {
  637. row1.CreateCell(j);
  638. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  639. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  640. }
  641. else if (j == ShowDataIndex)
  642. {
  643. row1.CreateCell(j);
  644. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  645. }
  646. else
  647. {
  648. row1.CreateCell(j);
  649. }
  650. row1.GetCell(j).CellStyle = style;
  651. }
  652. row1 = sheet.CreateRow(PaintIndex);
  653. PaintIndex = PaintIndex + 1;
  654. //第二行添加型号
  655. for (int j = 0; j < columnNum - 3; j++)
  656. {
  657. if (j == 0)
  658. {
  659. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  660. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ")" + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  661. }
  662. else if (j == ShowSizeIndex)
  663. {
  664. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  665. }
  666. else if (j == ShowDataIndex)
  667. {
  668. row1.CreateCell(j).SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  669. }
  670. }
  671. //添加列名
  672. row1 = sheet.CreateRow(PaintIndex);
  673. PaintIndex = PaintIndex + 1;
  674. //计数列所在的索引
  675. int showcount = 0;
  676. for (int j = 4; j < columnNum; j++)
  677. {
  678. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  679. {
  680. if (!PercentSum.ContainsKey(j - 4))
  681. PercentSum.Add(j - 4, 0);
  682. showcount = showcount + 1;
  683. row1.CreateCell(j - 4);
  684. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  685. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  686. }
  687. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  688. {
  689. if (!PercentSum.ContainsKey(j - 4))
  690. PercentSum.Add(j - 4, 0);
  691. showcount = showcount + 1;
  692. row1.CreateCell(j - 4);
  693. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  694. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  695. }
  696. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  697. {
  698. if (!PercentSum.ContainsKey(j - 4))
  699. PercentSum.Add(j - 4, 0);
  700. showcount = showcount + 1;
  701. row1.CreateCell(j - 4);
  702. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  703. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  704. }
  705. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  706. {
  707. if (!PercentSum.ContainsKey(j - 4))
  708. PercentSum.Add(j - 4, 0);
  709. showcount = showcount + 1;
  710. row1.CreateCell(j - 4);
  711. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  712. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  713. }
  714. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  715. {
  716. if (!PercentSum.ContainsKey(j - 4))
  717. PercentSum.Add(j - 4, 0);
  718. showcount = showcount + 1;
  719. row1.CreateCell(j - 4);
  720. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  721. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  722. }
  723. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  724. {
  725. }
  726. else
  727. {
  728. showcount = showcount + 1;
  729. row1.CreateCell(j - 4);
  730. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  731. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  732. }
  733. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  734. {
  735. NumIndex = j;
  736. if (ShowCountIndex == NumIndex - 4)
  737. {
  738. ShowCountIndex = ShowCountIndex + 1;
  739. }
  740. }
  741. }
  742. ShowColumnCount = showcount;
  743. row1 = sheet.CreateRow(PaintIndex);
  744. PaintIndex = PaintIndex + 1;
  745. }
  746. }
  747. //添加数据内容
  748. for (int j = 4; j < columnNum; j++)
  749. {
  750. string Data = DataTable.Rows[i][j].ToString();
  751. row1.CreateCell(j - 4);
  752. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  753. {
  754. row1.CreateCell(j - 4, CellType.String);
  755. }
  756. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  757. {
  758. }
  759. else
  760. {
  761. double Num = 0;
  762. if (double.TryParse(Data, out Num) && DataTable.Columns[j].ColumnName.ToLower() != "ch_bluefilm")
  763. {
  764. row1.Cells[j - 4].SetCellValue(Num);
  765. for (int k = 0; k < PercentSum.Count; k++)
  766. {
  767. if (PercentSum.ContainsKey(j - 4))
  768. {
  769. PercentSum[j - 4] += Num;
  770. }
  771. }
  772. }
  773. else
  774. {
  775. row1.Cells[j - 4].SetCellValue(Data);
  776. }
  777. row1.Cells[j - 4].CellStyle = styleborder;
  778. }
  779. if (DataTable.Columns[j].ColumnName == "io_qty")
  780. {
  781. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  782. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  783. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  784. }
  785. if (DataTable.Columns[j].ColumnName == "rownum")
  786. {
  787. row1.Cells[j - 4].SetCellValue(i + 1);
  788. }
  789. if (DataTable.Columns[j].ColumnName == "ch_code")
  790. {
  791. sheet.AutoSizeColumn(j - 4);
  792. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  793. }
  794. }
  795. //固定行号分组的时候自动拼接新的DataTable
  796. if (i == rowNum - 1)
  797. {
  798. DataRow dr = FirstDT.NewRow();
  799. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  800. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  801. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  802. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  803. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  804. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  805. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  806. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  807. dr["pd_ordercode"] = First_OrderCode;
  808. dr["pr_orispeccode"] = First_Prspec;
  809. dr["ch_splitbatch"] = First_Batch;
  810. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  811. dr["num"] = (i % PageSize) + 1;
  812. dr["io_qty"] = sumCount;
  813. FirstDT.Rows.Add(dr);
  814. row1 = sheet.CreateRow(PaintIndex);
  815. PaintIndex = PaintIndex + 1;
  816. for (int j = 0; j < ShowColumnCount; j++)
  817. {
  818. row1.CreateCell(j);
  819. if (j == 0)
  820. {
  821. row1.Cells[j].SetCellValue(小计);
  822. }
  823. else if (j == ShowPieceIndex)
  824. {
  825. row1.Cells[ShowPieceIndex].SetCellValue((rowNum % PageSize == 0 ? PageSize : (rowNum % PageSize)));
  826. row1.Cells[j].CellStyle = styleborder;
  827. }
  828. else if (j == ShowCountIndex)
  829. {
  830. row1.Cells[j].SetCellValue(sumCount);
  831. }
  832. if (CountQty)
  833. {
  834. for (int k = 0; k < PercentSum.Count; k++)
  835. {
  836. if (PercentSum.ContainsKey(j))
  837. {
  838. if (PercentSum[j] != 0)
  839. {
  840. row1.Cells[j].SetCellValue(PercentSum[j] / PercentSum.Count);
  841. PercentSum[j] = 0;
  842. }
  843. }
  844. }
  845. }
  846. row1.Cells[j].CellStyle = styleborder;
  847. }
  848. row1 = sheet.CreateRow(PaintIndex);
  849. for (int j = 0; j < columnNum - 3; j++)
  850. {
  851. if (j == 0)
  852. {
  853. row1.CreateCell(j);
  854. row1.Cells[j].SetCellValue("备注");
  855. }
  856. else if (j == ShowCountIndex)
  857. {
  858. row1.CreateCell(j);
  859. row1.Cells[j].SetCellValue(totalCount);
  860. }
  861. else if (j == ShowRemarkPiece)
  862. {
  863. row1.CreateCell(j);
  864. row1.Cells[j].SetCellValue(rowNum + "片");
  865. }
  866. else
  867. {
  868. row1.CreateCell(j);
  869. }
  870. row1.Cells[j].CellStyle = style;
  871. }
  872. sheet.SetRowBreak(PaintIndex);
  873. sheet.Footer.Center = "第&P页,共&N页";
  874. PaintIndex = PaintIndex + 1;
  875. }
  876. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  877. pib_outboxcode1.Add(BoxCode.ToString());
  878. }
  879. break;
  880. case "BatchCode":
  881. string LastBatchCode = "";
  882. int PageNum = 0;
  883. for (int i = 0; i < rowNum; i++)
  884. {
  885. IRow row1 = sheet.CreateRow(PaintIndex);
  886. PaintIndex = PaintIndex + 1;
  887. row1.HeightInPoints = RowHeight;
  888. //如果批号不相等的时候
  889. if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
  890. {
  891. BoxCode = BoxCode + 1;
  892. for (int j = 0; j < ShowColumnCount; j++)
  893. {
  894. row1.CreateCell(j);
  895. if (j == 0)
  896. {
  897. row1.Cells[j].SetCellValue(小计);
  898. row1.Cells[j].CellStyle = styleborder;
  899. }
  900. else if (j == ShowPieceIndex)
  901. {
  902. row1.Cells[ShowPieceIndex].SetCellValue(PageNum);
  903. row1.Cells[j].CellStyle = styleborder;
  904. }
  905. else if (j == ShowCountIndex)
  906. {
  907. row1.Cells[j].SetCellValue(sumCount);
  908. row1.Cells[j].CellStyle = styleborder;
  909. }
  910. else
  911. {
  912. row1.Cells[j].CellStyle = styleborder;
  913. }
  914. if (CountQty)
  915. {
  916. for (int k = 0; k < PercentSum.Count; k++)
  917. {
  918. if (PercentSum.ContainsKey(j))
  919. {
  920. if (PercentSum[j] != 0)
  921. {
  922. row1.Cells[j].SetCellValue(PercentSum[j] / PercentSum.Count);
  923. PercentSum[j] = 0;
  924. }
  925. }
  926. }
  927. }
  928. }
  929. sumCount = 0;
  930. row1 = sheet.CreateRow(PaintIndex);
  931. sheet.SetRowBreak(PaintIndex - 1);
  932. sheet.Footer.Center = "第&P页,共&N页";
  933. PaintIndex = PaintIndex + 1;
  934. PageNum = 0;
  935. }
  936. int SplitBatchIndex = 0;
  937. //每次到了页数开始分页
  938. if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()) || (i == rowNum - 1 && (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())))
  939. {
  940. LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
  941. //第一行添加客户信息
  942. //if (i != rowNum - 1)
  943. {
  944. for (int j = 0; j < columnNum - 3; j++)
  945. {
  946. if (j == 0)
  947. {
  948. row1.CreateCell(j);
  949. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  950. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  951. }
  952. else if (j == ShowDataIndex)
  953. {
  954. row1.CreateCell(j);
  955. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  956. }
  957. else
  958. {
  959. row1.CreateCell(j);
  960. }
  961. row1.GetCell(j).CellStyle = style;
  962. }
  963. row1 = sheet.CreateRow(PaintIndex);
  964. PaintIndex = PaintIndex + 1;
  965. //第二行添加型号
  966. for (int j = 0; j < columnNum - 3; j++)
  967. {
  968. if (j == 0)
  969. {
  970. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  971. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ")" + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  972. }
  973. else if (j == ShowSizeIndex)
  974. {
  975. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  976. }
  977. else if (j == ShowDataIndex)
  978. {
  979. row1.CreateCell(j).SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  980. }
  981. }
  982. //添加列名
  983. row1 = sheet.CreateRow(PaintIndex);
  984. PaintIndex = PaintIndex + 1;
  985. int showcount = 0;
  986. for (int j = 4; j < columnNum; j++)
  987. {
  988. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_splitbatch")
  989. {
  990. SplitBatchIndex = j - 4;
  991. }
  992. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  993. {
  994. if (!PercentSum.ContainsKey(j - 4))
  995. PercentSum.Add(j - 4, 0);
  996. showcount = showcount + 1;
  997. row1.CreateCell(j - 4);
  998. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  999. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  1000. }
  1001. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  1002. {
  1003. if (!PercentSum.ContainsKey(j - 4))
  1004. PercentSum.Add(j - 4, 0);
  1005. showcount = showcount + 1;
  1006. row1.CreateCell(j - 4);
  1007. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1008. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  1009. }
  1010. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  1011. {
  1012. if (!PercentSum.ContainsKey(j - 4))
  1013. PercentSum.Add(j - 4, 0);
  1014. showcount = showcount + 1;
  1015. row1.CreateCell(j - 4);
  1016. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1017. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  1018. }
  1019. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  1020. {
  1021. if (!PercentSum.ContainsKey(j - 4))
  1022. PercentSum.Add(j - 4, 0);
  1023. showcount = showcount + 1;
  1024. row1.CreateCell(j - 4);
  1025. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1026. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  1027. }
  1028. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  1029. {
  1030. if (!PercentSum.ContainsKey(j - 4))
  1031. PercentSum.Add(j - 4, 0);
  1032. showcount = showcount + 1;
  1033. row1.CreateCell(j - 4);
  1034. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1035. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  1036. }
  1037. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  1038. {
  1039. }
  1040. else
  1041. {
  1042. showcount = showcount + 1;
  1043. row1.CreateCell(j - 4);
  1044. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1045. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  1046. }
  1047. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  1048. {
  1049. NumIndex = j;
  1050. if (ShowCountIndex == NumIndex - 4)
  1051. {
  1052. ShowCountIndex = ShowCountIndex + 1;
  1053. }
  1054. }
  1055. }
  1056. ShowColumnCount = showcount;
  1057. row1 = sheet.CreateRow(PaintIndex);
  1058. PaintIndex = PaintIndex + 1;
  1059. }
  1060. }
  1061. //添加数据内容
  1062. for (int j = 4; j < columnNum; j++)
  1063. {
  1064. string Data = DataTable.Rows[i][j].ToString();
  1065. row1.CreateCell(j - 4);
  1066. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  1067. {
  1068. row1.CreateCell(j - 4, CellType.String);
  1069. }
  1070. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  1071. {
  1072. }
  1073. else
  1074. {
  1075. double Num = 0;
  1076. if (double.TryParse(Data, out Num) && DataTable.Columns[j].ColumnName.ToLower() != "ch_bluefilm")
  1077. {
  1078. row1.Cells[j - 4].SetCellValue(Num);
  1079. for (int k = 0; k < PercentSum.Count; k++)
  1080. {
  1081. if (PercentSum.ContainsKey(j - 4))
  1082. {
  1083. PercentSum[j - 4] += Num;
  1084. }
  1085. }
  1086. }
  1087. else
  1088. {
  1089. row1.Cells[j - 4].SetCellValue(Data);
  1090. }
  1091. row1.Cells[j - 4].CellStyle = styleborder;
  1092. }
  1093. if (DataTable.Columns[j].ColumnName == "io_qty")
  1094. {
  1095. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  1096. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  1097. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  1098. }
  1099. if (DataTable.Columns[j].ColumnName == "rownum")
  1100. {
  1101. row1.Cells[j - 4].SetCellValue(i + 1);
  1102. }
  1103. if (DataTable.Columns[j].ColumnName == "ch_code")
  1104. {
  1105. sheet.AutoSizeColumn(j - 4);
  1106. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  1107. }
  1108. }
  1109. if (i == rowNum - 1)
  1110. {
  1111. PageNum = PageNum + 1;
  1112. row1 = sheet.CreateRow(PaintIndex);
  1113. PaintIndex = PaintIndex + 1;
  1114. for (int j = 0; j < ShowColumnCount; j++)
  1115. {
  1116. row1.CreateCell(j);
  1117. if (j == 0)
  1118. {
  1119. row1.Cells[j].SetCellValue(小计);
  1120. row1.Cells[j].CellStyle = styleborder;
  1121. }
  1122. else if (j == ShowPieceIndex)
  1123. {
  1124. row1.Cells[ShowPieceIndex].SetCellValue(PageNum);
  1125. row1.Cells[j].CellStyle = styleborder;
  1126. }
  1127. else if (j == ShowCountIndex)
  1128. {
  1129. if (ShowCountIndex == SplitBatchIndex)
  1130. {
  1131. row1.CreateCell(j + 1);
  1132. row1.Cells[j + 1].SetCellValue(sumCount);
  1133. row1.Cells[j + 1].CellStyle = styleborder;
  1134. }
  1135. else
  1136. {
  1137. row1.Cells[j].SetCellValue(sumCount);
  1138. row1.Cells[j].CellStyle = styleborder;
  1139. }
  1140. }
  1141. else
  1142. {
  1143. row1.Cells[j].CellStyle = styleborder;
  1144. }
  1145. if (CountQty)
  1146. {
  1147. for (int k = 0; k < PercentSum.Count; k++)
  1148. {
  1149. if (PercentSum.ContainsKey(j))
  1150. {
  1151. if (PercentSum[j] != 0)
  1152. {
  1153. row1.Cells[j].SetCellValue(PercentSum[j] / PercentSum.Count);
  1154. PercentSum[j] = 0;
  1155. }
  1156. }
  1157. }
  1158. }
  1159. }
  1160. //创建备注内容
  1161. row1 = sheet.CreateRow(PaintIndex);
  1162. for (int j = 0; j < columnNum - 3; j++)
  1163. {
  1164. if (j == 0)
  1165. {
  1166. row1.CreateCell(j);
  1167. row1.Cells[j].SetCellValue("备注");
  1168. }
  1169. else if (j == ShowCountIndex)
  1170. {
  1171. row1.CreateCell(j);
  1172. row1.Cells[j].SetCellValue(totalCount);
  1173. }
  1174. else if (j == ShowRemarkPiece)
  1175. {
  1176. row1.CreateCell(j);
  1177. row1.Cells[j].SetCellValue(rowNum + "片");
  1178. }
  1179. else if (j == 4)
  1180. {
  1181. row1.CreateCell(j);
  1182. row1.Cells[j].SetCellValue(片);
  1183. }
  1184. else
  1185. {
  1186. row1.CreateCell(j);
  1187. }
  1188. row1.Cells[j].CellStyle = style;
  1189. }
  1190. sheet.SetRowBreak(PaintIndex);
  1191. sheet.Footer.Center = "第&P页,共&N页";
  1192. PaintIndex = PaintIndex + 1;
  1193. PageNum = 0;
  1194. }
  1195. PageNum = PageNum + 1;
  1196. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  1197. pib_outboxcode1.Add(BoxCode.ToString());
  1198. }
  1199. break;
  1200. case "BoxCode":
  1201. string LastBoxCode = "";
  1202. int PageNum1 = 0;
  1203. for (int i = 0; i < rowNum; i++)
  1204. {
  1205. IRow row1 = sheet.CreateRow(PaintIndex);
  1206. PaintIndex = PaintIndex + 1;
  1207. row1.HeightInPoints = RowHeight;
  1208. //如果批号不相等的时候
  1209. if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
  1210. {
  1211. BoxCode = BoxCode + 1;
  1212. for (int j = 0; j < ShowColumnCount; j++)
  1213. {
  1214. row1.CreateCell(j);
  1215. if (j == 0)
  1216. {
  1217. row1.Cells[j].SetCellValue(小计);
  1218. row1.Cells[j].CellStyle = styleborder;
  1219. }
  1220. else if (j == ShowPieceIndex)
  1221. {
  1222. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  1223. row1.Cells[j].CellStyle = styleborder;
  1224. }
  1225. else if (j == ShowCountIndex)
  1226. {
  1227. row1.Cells[j].SetCellValue(sumCount);
  1228. row1.Cells[j].CellStyle = styleborder;
  1229. }
  1230. else
  1231. {
  1232. row1.Cells[j].CellStyle = styleborder;
  1233. }
  1234. if (CountQty)
  1235. {
  1236. for (int k = 0; k < PercentSum.Count; k++)
  1237. {
  1238. if (PercentSum.ContainsKey(j))
  1239. {
  1240. if (PercentSum[j] != 0)
  1241. {
  1242. row1.Cells[j].SetCellValue(PercentSum[j] / PercentSum.Count);
  1243. PercentSum[j] = 0;
  1244. }
  1245. }
  1246. }
  1247. }
  1248. }
  1249. sumCount = 0;
  1250. row1 = sheet.CreateRow(PaintIndex);
  1251. sheet.SetRowBreak(PaintIndex - 1);
  1252. sheet.Footer.Center = "第&P页,共&N页";
  1253. PaintIndex = PaintIndex + 1;
  1254. PageNum1 = 0;
  1255. }
  1256. //每次到了页数开始分页
  1257. if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString())))
  1258. {
  1259. LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
  1260. //第一行添加客户信息
  1261. //if (i != rowNum - 1)
  1262. {
  1263. for (int j = 0; j < columnNum - 3; j++)
  1264. {
  1265. if (j == 0)
  1266. {
  1267. row1.CreateCell(j);
  1268. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  1269. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  1270. }
  1271. else if (j == ShowDataIndex)
  1272. {
  1273. row1.CreateCell(j);
  1274. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  1275. }
  1276. else
  1277. {
  1278. row1.CreateCell(j);
  1279. }
  1280. row1.GetCell(j).CellStyle = style;
  1281. }
  1282. row1 = sheet.CreateRow(PaintIndex);
  1283. PaintIndex = PaintIndex + 1;
  1284. //第二行添加型号
  1285. for (int j = 0; j < columnNum - 3; j++)
  1286. {
  1287. if (j == 0)
  1288. {
  1289. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  1290. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ")" + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  1291. }
  1292. else if (j == ShowSizeIndex)
  1293. {
  1294. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  1295. }
  1296. else if (j == ShowDataIndex)
  1297. {
  1298. row1.CreateCell(j).SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  1299. }
  1300. }
  1301. //添加列名
  1302. row1 = sheet.CreateRow(PaintIndex);
  1303. PaintIndex = PaintIndex + 1;
  1304. int showcount = 0;
  1305. for (int j = 4; j < columnNum; j++)
  1306. {
  1307. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  1308. {
  1309. if (!PercentSum.ContainsKey(j - 4))
  1310. PercentSum.Add(j - 4, 0);
  1311. showcount = showcount + 1;
  1312. row1.CreateCell(j - 4);
  1313. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1314. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  1315. }
  1316. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  1317. {
  1318. if (!PercentSum.ContainsKey(j - 4))
  1319. PercentSum.Add(j - 4, 0);
  1320. showcount = showcount + 1;
  1321. row1.CreateCell(j - 4);
  1322. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1323. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  1324. }
  1325. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  1326. {
  1327. if (!PercentSum.ContainsKey(j - 4))
  1328. PercentSum.Add(j - 4, 0);
  1329. showcount = showcount + 1;
  1330. row1.CreateCell(j - 4);
  1331. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1332. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  1333. }
  1334. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  1335. {
  1336. if (!PercentSum.ContainsKey(j - 4))
  1337. PercentSum.Add(j - 4, 0);
  1338. showcount = showcount + 1;
  1339. row1.CreateCell(j - 4);
  1340. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1341. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  1342. }
  1343. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  1344. {
  1345. if (!PercentSum.ContainsKey(j - 4))
  1346. PercentSum.Add(j - 4, 0);
  1347. showcount = showcount + 1;
  1348. row1.CreateCell(j - 4);
  1349. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1350. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  1351. }
  1352. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  1353. {
  1354. }
  1355. else
  1356. {
  1357. showcount = showcount + 1;
  1358. row1.CreateCell(j - 4);
  1359. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  1360. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  1361. }
  1362. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  1363. {
  1364. NumIndex = j;
  1365. if (ShowCountIndex == NumIndex - 4)
  1366. {
  1367. ShowCountIndex = ShowCountIndex + 1;
  1368. }
  1369. }
  1370. }
  1371. ShowColumnCount = showcount;
  1372. row1 = sheet.CreateRow(PaintIndex);
  1373. PaintIndex = PaintIndex + 1;
  1374. }
  1375. }
  1376. //添加数据内容
  1377. for (int j = 4; j < columnNum; j++)
  1378. {
  1379. string Data = DataTable.Rows[i][j].ToString();
  1380. row1.CreateCell(j - 4);
  1381. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  1382. {
  1383. row1.CreateCell(j - 4, CellType.String);
  1384. }
  1385. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  1386. {
  1387. }
  1388. else
  1389. {
  1390. double Num = 0;
  1391. if (double.TryParse(Data, out Num) && DataTable.Columns[j].ColumnName.ToLower() != "ch_bluefilm")
  1392. {
  1393. row1.Cells[j - 4].SetCellValue(Num);
  1394. for (int k = 0; k < PercentSum.Count; k++)
  1395. {
  1396. if (PercentSum.ContainsKey(j - 4))
  1397. {
  1398. PercentSum[j - 4] += Num;
  1399. }
  1400. }
  1401. }
  1402. else
  1403. {
  1404. row1.Cells[j - 4].SetCellValue(Data);
  1405. }
  1406. row1.Cells[j - 4].CellStyle = styleborder;
  1407. }
  1408. if (DataTable.Columns[j].ColumnName == "io_qty")
  1409. {
  1410. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  1411. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  1412. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  1413. }
  1414. if (DataTable.Columns[j].ColumnName == "rownum")
  1415. {
  1416. row1.Cells[j - 4].SetCellValue(i + 1);
  1417. }
  1418. if (DataTable.Columns[j].ColumnName == "ch_code")
  1419. {
  1420. sheet.AutoSizeColumn(j - 4);
  1421. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  1422. }
  1423. }
  1424. if (i == rowNum - 1)
  1425. {
  1426. PageNum1 = PageNum1 + 1;
  1427. row1 = sheet.CreateRow(PaintIndex);
  1428. PaintIndex = PaintIndex + 1;
  1429. for (int j = 0; j < ShowColumnCount; j++)
  1430. {
  1431. row1.CreateCell(j);
  1432. if (j == 0)
  1433. {
  1434. row1.Cells[j].SetCellValue(小计);
  1435. row1.Cells[j].CellStyle = styleborder;
  1436. }
  1437. else if (j == ShowPieceIndex)
  1438. {
  1439. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  1440. row1.Cells[j].CellStyle = styleborder;
  1441. }
  1442. else if (j == ShowCountIndex)
  1443. {
  1444. row1.Cells[j].SetCellValue(sumCount);
  1445. row1.Cells[j].CellStyle = styleborder;
  1446. }
  1447. else
  1448. {
  1449. row1.Cells[j].CellStyle = styleborder;
  1450. }
  1451. if (CountQty)
  1452. {
  1453. for (int k = 0; k < PercentSum.Count; k++)
  1454. {
  1455. if (PercentSum.ContainsKey(j))
  1456. {
  1457. if (PercentSum[j] != 0)
  1458. {
  1459. row1.Cells[j].SetCellValue(PercentSum[j] / PercentSum.Count);
  1460. PercentSum[j] = 0;
  1461. }
  1462. }
  1463. }
  1464. }
  1465. }
  1466. row1 = sheet.CreateRow(PaintIndex);
  1467. for (int j = 0; j < columnNum - 3; j++)
  1468. {
  1469. if (j == 0)
  1470. {
  1471. row1.CreateCell(j);
  1472. row1.Cells[j].SetCellValue("备注");
  1473. }
  1474. else if (j == ShowCountIndex)
  1475. {
  1476. row1.CreateCell(j);
  1477. row1.Cells[j].SetCellValue(totalCount);
  1478. }
  1479. else if (j == ShowRemarkPiece)
  1480. {
  1481. row1.CreateCell(j);
  1482. row1.Cells[j].SetCellValue(rowNum + "片");
  1483. }
  1484. else
  1485. {
  1486. row1.CreateCell(j);
  1487. }
  1488. row1.Cells[j].CellStyle = style;
  1489. }
  1490. sheet.SetRowBreak(PaintIndex);
  1491. sheet.Footer.Center = "第&P页,共&N页";
  1492. PaintIndex = PaintIndex + 1;
  1493. PageNum1 = 0;
  1494. }
  1495. PageNum1 = PageNum1 + 1;
  1496. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  1497. pib_outboxcode1.Add(BoxCode.ToString());
  1498. }
  1499. //for (int i = 0; i < sheet.LastRowNum; i++)
  1500. //{
  1501. // if (i != 0)
  1502. // {
  1503. // sheet.AutoSizeColumn(i);
  1504. // sheet.SetColumnWidth(i, sheet.GetColumnWidth(i) + 1000);
  1505. // }
  1506. //}
  1507. break;
  1508. default:
  1509. break;
  1510. }
  1511. dh.BatchInsert("update prodiobarcode set pib_outboxcode1=:pib_outboxcode1 where pib_inoutno='" + Inoutno + "' and pib_id=:pib_id", new string[] { "pib_outboxcode1", "pib_id" }, pib_outboxcode1.ToArray(), pib_id.ToArray());
  1512. //删除下载链接再重新插入
  1513. HttpHandler.GenDownLoadLinK(Inoutno);
  1514. //填充首页
  1515. sumCount = 0;
  1516. totalCount = 0;
  1517. PaintIndex = 1;
  1518. ISheet sheet2 = book.CreateSheet("首页");
  1519. row = sheet2.CreateRow(0);
  1520. row.CreateCell(0);
  1521. row.Cells[0].SetCellValue(" " + companyname);
  1522. row.GetCell(0).CellStyle = style;
  1523. rowNum = FirstDT.Rows.Count;
  1524. //不需要显示的列移除
  1525. for (int i = FirstDT.Columns.Count - 1; i > 0; i--)
  1526. {
  1527. for (int j = 0; j < box.Length; j++)
  1528. {
  1529. if (box[j].Name == "FirstPage_WID" && !box[j].Checked)
  1530. {
  1531. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  1532. {
  1533. FirstDT.Columns.RemoveAt(i);
  1534. }
  1535. }
  1536. if (box[j].Name == "FirstPage_YIELD" && !box[j].Checked)
  1537. {
  1538. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_yeild"))
  1539. {
  1540. FirstDT.Columns.RemoveAt(i);
  1541. }
  1542. }
  1543. if (box[j].Name == "FirstPage_REMARK" && !box[j].Checked)
  1544. {
  1545. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  1546. {
  1547. FirstDT.Columns.RemoveAt(i);
  1548. }
  1549. }
  1550. if (box[j].Name == "FirstPage_BOXCODE" && !box[j].Checked)
  1551. {
  1552. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  1553. {
  1554. FirstDT.Columns.RemoveAt(i);
  1555. }
  1556. }
  1557. }
  1558. }
  1559. columnNum = FirstDT.Columns.Count;
  1560. for (int i = 0; i < rowNum; i++)
  1561. {
  1562. IRow row1 = sheet2.CreateRow(PaintIndex);
  1563. PaintIndex = PaintIndex + 1;
  1564. row1.HeightInPoints = RowHeight;
  1565. //只需要绘制一行
  1566. if (i == 0)
  1567. {
  1568. for (int j = 0; j < columnNum - 3; j++)
  1569. {
  1570. if (j == 0)
  1571. {
  1572. row1.CreateCell(j);
  1573. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_title"].Caption + ":" + FirstDT.Rows[i]["pi_title"].ToString() + " "
  1574. + FirstDT.Columns["ch_level"].Caption + ":" + FirstDT.Rows[i]["ch_level"].ToString());
  1575. }
  1576. else if (j > 5 && j == columnNum - 5)
  1577. {
  1578. row1.CreateCell(j);
  1579. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  1580. }
  1581. else if (columnNum > 5 && j == columnNum - 5)
  1582. {
  1583. row1.CreateCell(j);
  1584. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  1585. }
  1586. else
  1587. {
  1588. row1.CreateCell(j);
  1589. }
  1590. row1.GetCell(j).CellStyle = style;
  1591. }
  1592. row1 = sheet2.CreateRow(PaintIndex);
  1593. PaintIndex = PaintIndex + 1;
  1594. //第二行添加型号
  1595. for (int j = 0; j < columnNum - 3; j++)
  1596. {
  1597. if (j == 0)
  1598. {
  1599. row1.CreateCell(j).SetCellValue(FirstDT.Columns["pr_orispeccode"].Caption + ":" + FirstDT.Rows[i]["pr_orispeccode"].ToString() + " "
  1600. + "(" + FirstDT.Rows[i]["me_desc"].ToString() + ")" + FirstDT.Columns["pi_chipouttype"].Caption + ":" + FirstDT.Rows[i]["pi_chipouttype"].ToString());
  1601. }
  1602. else if (j == ShowSizeIndex)
  1603. {
  1604. row1.CreateCell(j);
  1605. row1.Cells[j].SetCellValue(FirstDT.Columns["pr_size"].Caption + ":" + FirstDT.Rows[i]["pr_size"].ToString());
  1606. }
  1607. else if (j > 5 && j == columnNum - 5)
  1608. {
  1609. row1.CreateCell(j);
  1610. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  1611. }
  1612. else if (columnNum > 5 && j == columnNum - 5)
  1613. {
  1614. row1.CreateCell(j);
  1615. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  1616. }
  1617. else
  1618. {
  1619. row1.CreateCell(j);
  1620. }
  1621. row1.GetCell(j).CellStyle = style;
  1622. }
  1623. row1 = sheet2.CreateRow(PaintIndex);
  1624. PaintIndex = PaintIndex + 1;
  1625. //添加列名
  1626. for (int j = 4; j < columnNum; j++)
  1627. {
  1628. row1.CreateCell(j - 4);
  1629. if (NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  1630. {
  1631. }
  1632. else
  1633. {
  1634. row1.Cells[j - 4].CellStyle = styleborder;
  1635. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  1636. }
  1637. }
  1638. row1 = sheet2.CreateRow(PaintIndex);
  1639. PaintIndex = PaintIndex + 1;
  1640. }
  1641. //添加数据内容
  1642. ShowColumnCount = 0;
  1643. for (int j = 4; j < columnNum; j++)
  1644. {
  1645. row1.CreateCell(j - 4);
  1646. if (FirstDT.Columns[j].ColumnName == "ch_bluefilm")
  1647. {
  1648. row1.CreateCell(j - 4, CellType.String);
  1649. }
  1650. if (!NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  1651. {
  1652. string Data = FirstDT.Rows[i][j].ToString();
  1653. row1.Cells[j - 4].SetCellValue(Data);
  1654. row1.GetCell(j - 4).CellStyle = styleborder;
  1655. if (FirstDT.Columns[j].ColumnName == "num")
  1656. {
  1657. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  1658. sumCount += int.Parse(Data);
  1659. }
  1660. if (FirstDT.Columns[j].ColumnName == "io_qty")
  1661. {
  1662. totalCount += int.Parse(Data);
  1663. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  1664. }
  1665. ShowColumnCount = ShowColumnCount + 1;
  1666. }
  1667. else
  1668. {
  1669. }
  1670. }
  1671. //添加总计行
  1672. if (i == rowNum - 1)
  1673. {
  1674. row1 = sheet2.CreateRow(PaintIndex);
  1675. PaintIndex = PaintIndex + 1;
  1676. for (int j = 0; j < ShowColumnCount; j++)
  1677. {
  1678. if (j == 0)
  1679. {
  1680. row1.CreateCell(j);
  1681. row1.Cells[j].CellStyle = styleborder;
  1682. row1.Cells[j].SetCellValue(总计);
  1683. }
  1684. else if (j == ShowColumnCount - 2)
  1685. {
  1686. row1.CreateCell(j);
  1687. row1.Cells[j].CellStyle = styleborder;
  1688. row1.Cells[j].SetCellValue(sumCount);
  1689. }
  1690. else if (j == ShowColumnCount - 1)
  1691. {
  1692. row1.CreateCell(j);
  1693. row1.Cells[j].CellStyle = styleborder;
  1694. row1.Cells[j].SetCellValue(totalCount);
  1695. }
  1696. else
  1697. {
  1698. row1.CreateCell(j);
  1699. row1.Cells[j].CellStyle = styleborder;
  1700. }
  1701. }
  1702. }
  1703. }
  1704. for (int i = 0; i < sheet2.LastRowNum; i++)
  1705. {
  1706. if (i != 0)
  1707. {
  1708. sheet2.AutoSizeColumn(i);
  1709. sheet2.SetColumnWidth(i, sheet2.GetColumnWidth(i) + 1000);
  1710. }
  1711. }
  1712. //将book的内容写入内存流中返回
  1713. book.Write(ms);
  1714. return ms;
  1715. }
  1716. /// <summary>
  1717. /// 将DataTable形式的数据转成Excel格式的,然后用字节流的形式写入文件
  1718. /// </summary>
  1719. /// <param name="DataTable"></param>
  1720. /// <returns></returns>
  1721. private MemoryStream DataTableToExcel_JINYUAN(DataTable FirstDT, DataTable DataTable, string Type, string Inoutno, int PageSize, List<CheckBox> conditionbox)
  1722. {
  1723. string 小计 = "";
  1724. string 总计 = "";
  1725. string 片 = "";
  1726. string companyname = "";
  1727. //晶源的需要显示在数量列下面
  1728. int ShowCountIndex = 2;
  1729. if (dh.getFieldDataByCondition("ProdInout", "pi_exporttype", "pi_inoutno='" + Inoutno + "'").ToString() == "Chinese")
  1730. {
  1731. 小计 = "小计";
  1732. 总计 = "总计";
  1733. 片 = "片";
  1734. companyname = "深爱半导体股份有限公司芯片出货清单";
  1735. }
  1736. else
  1737. {
  1738. 小计 = "total";
  1739. 总计 = "total";
  1740. 片 = "slice";
  1741. companyname = "SHENZHEN SI SEMICONDUCTORS CO.,LTD";
  1742. }
  1743. //转换为序列
  1744. CheckBox[] box = conditionbox.ToArray();
  1745. //创建内存流
  1746. MemoryStream ms = new MemoryStream();
  1747. //创建一个Book,相当于一个Excel文件
  1748. HSSFWorkbook book = new HSSFWorkbook();
  1749. //Excel中的Sheet
  1750. ISheet sheet = book.CreateSheet("分页");
  1751. sheet.SetMargin(MarginType.TopMargin, 0.4);
  1752. sheet.SetMargin(MarginType.BottomMargin, 0.1);
  1753. sheet.SetMargin(MarginType.LeftMargin, 0.4);
  1754. sheet.SetMargin(MarginType.RightMargin, 0.4);
  1755. sheet.PrintSetup.NoColor = true;
  1756. sheet.PrintSetup.Landscape = true;
  1757. //芯片号需要作为更新盒号的条件
  1758. HSSFFont ffont = (HSSFFont)book.CreateFont();
  1759. ffont.FontName = "宋体";
  1760. //更新箱号
  1761. List<string> pib_id = new List<string>();
  1762. //系统打印箱号
  1763. List<string> pib_outboxcode1 = new List<string>();
  1764. int BoxCode = 1;
  1765. ICellStyle style = book.CreateCellStyle();
  1766. style.VerticalAlignment = VerticalAlignment.Center;
  1767. style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  1768. style.SetFont(ffont);
  1769. ICellStyle styleborder = book.CreateCellStyle();
  1770. styleborder.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1771. styleborder.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1772. styleborder.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1773. styleborder.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1774. styleborder.VerticalAlignment = VerticalAlignment.Center;
  1775. styleborder.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  1776. styleborder.SetFont(ffont);
  1777. string pi_inoutno = "";
  1778. List<string> NotShowColumn = new List<string>();
  1779. NotShowColumn.Add("ch_level");
  1780. NotShowColumn.Add("pib_id");
  1781. NotShowColumn.Add("chw_itemname1");
  1782. NotShowColumn.Add("chw_itemname2");
  1783. NotShowColumn.Add("chw_itemname3");
  1784. NotShowColumn.Add("chw_itemname4");
  1785. NotShowColumn.Add("chw_itemname5");
  1786. NotShowColumn.Add("pd_ordercode");
  1787. NotShowColumn.Add("pr_size");
  1788. NotShowColumn.Add("me_desc");
  1789. NotShowColumn.Add("pr_orispeccode");
  1790. NotShowColumn.Add("pr_orispeccode1");
  1791. NotShowColumn.Add("pi_title");
  1792. NotShowColumn.Add("pi_date");
  1793. NotShowColumn.Add("pi_chipouttype");
  1794. //设置列的宽度,根据首行的列的内容的长度来设置
  1795. for (int i = DataTable.Columns.Count - 1; i > 0; i--)
  1796. {
  1797. for (int j = 0; j < box.Length; j++)
  1798. {
  1799. if (box[j].Name.ToLower() == "ch_bluefilm" && !box[j].Checked)
  1800. {
  1801. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_bluefilm"))
  1802. {
  1803. DataTable.Columns.RemoveAt(i);
  1804. break;
  1805. }
  1806. }
  1807. if (box[j].Name.ToLower() == "ch_code" && !box[j].Checked)
  1808. {
  1809. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_code"))
  1810. {
  1811. DataTable.Columns.RemoveAt(i);
  1812. break;
  1813. }
  1814. }
  1815. if (box[j].Name.ToLower() == "ch_splitbatch" && !box[j].Checked)
  1816. {
  1817. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_splitbatch"))
  1818. {
  1819. DataTable.Columns.RemoveAt(i);
  1820. break;
  1821. }
  1822. }
  1823. if (box[j].Name.ToLower() == "ch_waterid" && !box[j].Checked)
  1824. {
  1825. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  1826. {
  1827. DataTable.Columns.RemoveAt(i);
  1828. break;
  1829. }
  1830. }
  1831. if (box[j].Name.ToLower() == "ch_pbcode" && !box[j].Checked)
  1832. {
  1833. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  1834. {
  1835. DataTable.Columns.RemoveAt(i);
  1836. break;
  1837. }
  1838. }
  1839. if (box[j].Name.ToLower() == "ch_remark" && !box[j].Checked)
  1840. {
  1841. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  1842. {
  1843. DataTable.Columns.RemoveAt(i);
  1844. break;
  1845. }
  1846. }
  1847. if (box[j].Name.ToLower() == "ch_yield" && !box[j].Checked)
  1848. {
  1849. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_yield"))
  1850. {
  1851. DataTable.Columns.RemoveAt(i);
  1852. break;
  1853. }
  1854. }
  1855. }
  1856. }
  1857. //获取行数量和列数量
  1858. int rowNum = DataTable.Rows.Count;
  1859. int columnNum = DataTable.Columns.Count;
  1860. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  1861. //ffont.FontHeight = 10;
  1862. //开始绘制的Index
  1863. int PaintIndex = 0;
  1864. int sumCount = 0;
  1865. int totalCount = 0;
  1866. //Title的字体
  1867. HSSFFont titlefont = (HSSFFont)book.CreateFont();
  1868. titlefont.FontName = "宋体";
  1869. titlefont.FontHeight = 270;
  1870. titlefont.Boldweight = (short)FontBoldWeight.Bold;
  1871. HSSFFont ColumnTitle = (HSSFFont)book.CreateFont();
  1872. ColumnTitle.FontName = "宋体";
  1873. ColumnTitle.Boldweight = (short)FontBoldWeight.Bold;
  1874. ICellStyle ColumnTitleStyle = book.CreateCellStyle();
  1875. ColumnTitleStyle.SetFont(ColumnTitle);
  1876. ColumnTitleStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  1877. ColumnTitleStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  1878. ColumnTitleStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  1879. ColumnTitleStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  1880. ICellStyle TitleStyle = book.CreateCellStyle();
  1881. TitleStyle.SetFont(titlefont);
  1882. int ShowColumnCount = 0;
  1883. IRow row1 = null;
  1884. switch (Type)
  1885. {
  1886. case "FixRow":
  1887. //清理系统取出来的数据
  1888. BaseUtil.CleanDataTableData(FirstDT);
  1889. //首页参数拼接
  1890. string First_OrderCode = "";
  1891. string First_Prspec = "";
  1892. string First_Batch = "";
  1893. ArrayList<string> First_WID = new ArrayList<string>();
  1894. for (int i = 0; i < rowNum; i++)
  1895. {
  1896. if (PaintIndex != 0)
  1897. {
  1898. row1 = sheet.CreateRow(PaintIndex);
  1899. PaintIndex = PaintIndex + 1;
  1900. row1.HeightInPoints = RowHeight;
  1901. }
  1902. //不包含的订单号
  1903. if (DataTable.Columns.Contains("pd_ordercode") && !First_OrderCode.Contains(DataTable.Rows[i]["pd_ordercode"].ToString()))
  1904. {
  1905. First_OrderCode += DataTable.Rows[i]["pd_ordercode"].ToString() + " ";
  1906. }
  1907. //不包含的物料型号
  1908. if (DataTable.Columns.Contains("pr_orispeccode") && !First_Prspec.Contains(DataTable.Rows[i]["pr_orispeccode"].ToString()))
  1909. {
  1910. First_Prspec += DataTable.Rows[i]["pr_orispeccode"].ToString() + " ";
  1911. }
  1912. //不包含扩撒批号
  1913. if (DataTable.Columns.Contains("ch_splitbatch") && !First_Batch.Contains(DataTable.Rows[i]["ch_splitbatch"].ToString()))
  1914. {
  1915. First_Batch += DataTable.Rows[i]["ch_splitbatch"].ToString() + " ";
  1916. }
  1917. //不包含Wafer_id
  1918. if (DataTable.Columns.Contains("Wafer_ID") && !First_WID.Contains(DataTable.Rows[i]["Wafer_ID"].ToString()))
  1919. {
  1920. First_WID.Add(DataTable.Rows[i]["Wafer_ID"].ToString());
  1921. }
  1922. if (i / PageSize >= 1 && i % PageSize == 0)
  1923. {
  1924. DataRow dr = FirstDT.NewRow();
  1925. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  1926. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  1927. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  1928. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  1929. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  1930. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  1931. pi_inoutno = DataTable.Rows[i]["pi_inoutno"].ToString();
  1932. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  1933. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  1934. dr["pd_ordercode"] = First_OrderCode;
  1935. dr["pr_orispeccode"] = First_Prspec;
  1936. dr["ch_splitbatch"] = First_Batch;
  1937. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  1938. dr["num"] = PageSize;
  1939. dr["io_qty"] = sumCount;
  1940. FirstDT.Rows.Add(dr);
  1941. First_OrderCode = "";
  1942. First_Prspec = "";
  1943. First_Batch = "";
  1944. First_WID.Clear();
  1945. BoxCode = BoxCode + 1;
  1946. for (int j = 0; j < ShowColumnCount; j++)
  1947. {
  1948. row1.CreateCell(j);
  1949. if (j == 0)
  1950. {
  1951. row1.Cells[j].SetCellValue(小计);
  1952. }
  1953. else if (j == ShowPieceIndex)
  1954. {
  1955. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i) + 片);
  1956. row1.Cells[1].CellStyle = ColumnTitleStyle;
  1957. }
  1958. else if (j == ShowCountIndex)
  1959. {
  1960. row1.Cells[j].SetCellValue(sumCount);
  1961. }
  1962. row1.Cells[j].CellStyle = styleborder;
  1963. }
  1964. sumCount = 0;
  1965. row1 = sheet.CreateRow(PaintIndex);
  1966. sheet.SetRowBreak(PaintIndex - 1);
  1967. sheet.Footer.Center = "第&P页,共&N页";
  1968. }
  1969. //每次到了页数开始分页
  1970. if (i % PageSize == 0 || i == rowNum - 1)
  1971. {
  1972. //第一行添加客户信息 rownum只有一行的情
  1973. if (i != rowNum - 1 || rowNum == 1 || (rowNum - i == rowNum % PageSize))
  1974. {
  1975. //抬头设置
  1976. row1 = sheet.CreateRow(PaintIndex);
  1977. PaintIndex = PaintIndex + 1;
  1978. row1.CreateCell(0).SetCellValue(" " + companyname);
  1979. row1.GetCell(0).CellStyle = TitleStyle;
  1980. row1 = sheet.CreateRow(PaintIndex);
  1981. PaintIndex = PaintIndex + 1;
  1982. for (int j = 0; j < columnNum - 3; j++)
  1983. {
  1984. if (j == 0)
  1985. {
  1986. row1.CreateCell(j);
  1987. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  1988. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  1989. }
  1990. else if (j == ShowDataIndex)
  1991. {
  1992. row1.CreateCell(j);
  1993. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  1994. }
  1995. else
  1996. {
  1997. row1.CreateCell(j);
  1998. }
  1999. row1.GetCell(j).CellStyle = style;
  2000. }
  2001. row1 = sheet.CreateRow(PaintIndex);
  2002. PaintIndex = PaintIndex + 1;
  2003. //第二行添加型号
  2004. for (int j = 0; j < columnNum - 3; j++)
  2005. {
  2006. if (j == 0)
  2007. {
  2008. row1.CreateCell(j);
  2009. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  2010. + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  2011. }
  2012. else if (j == ShowSizeIndex)
  2013. {
  2014. row1.CreateCell(j);
  2015. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  2016. }
  2017. else if (j == ShowDataIndex)
  2018. {
  2019. row1.CreateCell(j);
  2020. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  2021. }
  2022. else
  2023. {
  2024. row1.CreateCell(j);
  2025. }
  2026. row1.GetCell(j).CellStyle = style;
  2027. }
  2028. //特殊客户添加一列空行
  2029. row1 = sheet.CreateRow(PaintIndex);
  2030. PaintIndex = PaintIndex + 1;
  2031. for (int j = 0; j < columnNum; j++)
  2032. {
  2033. row1.CreateCell(j).SetCellValue("");
  2034. }
  2035. //添加列名
  2036. row1 = sheet.CreateRow(PaintIndex);
  2037. PaintIndex = PaintIndex + 1;
  2038. //计数列所在的索引
  2039. int showcount = 0;
  2040. //前面有4列标题内容,数据库设置的,需要从4开始索引
  2041. for (int j = 4; j < columnNum; j++)
  2042. {
  2043. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  2044. {
  2045. showcount = showcount + 1;
  2046. row1.CreateCell(j - 4);
  2047. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2048. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  2049. }
  2050. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  2051. {
  2052. showcount = showcount + 1;
  2053. row1.CreateCell(j - 4);
  2054. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2055. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  2056. }
  2057. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  2058. {
  2059. showcount = showcount + 1;
  2060. row1.CreateCell(j - 4);
  2061. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2062. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  2063. }
  2064. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  2065. {
  2066. showcount = showcount + 1;
  2067. row1.CreateCell(j - 4);
  2068. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2069. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  2070. }
  2071. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  2072. {
  2073. showcount = showcount + 1;
  2074. row1.CreateCell(j - 4);
  2075. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2076. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  2077. }
  2078. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2079. {
  2080. }
  2081. else
  2082. {
  2083. showcount = showcount + 1;
  2084. row1.CreateCell(j - 4);
  2085. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2086. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  2087. }
  2088. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  2089. {
  2090. NumIndex = j - 4;
  2091. }
  2092. }
  2093. ShowColumnCount = showcount;
  2094. row1 = sheet.CreateRow(PaintIndex);
  2095. PaintIndex = PaintIndex + 1;
  2096. }
  2097. }
  2098. //添加数据内容
  2099. for (int j = 4; j < columnNum; j++)
  2100. {
  2101. string Data = DataTable.Rows[i][j].ToString();
  2102. row1.CreateCell(j - 4);
  2103. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  2104. {
  2105. row1.CreateCell(j - 4, CellType.String);
  2106. }
  2107. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2108. {
  2109. }
  2110. else
  2111. {
  2112. double Num = 0;
  2113. if (double.TryParse(Data, out Num) && DataTable.Columns[j].ColumnName.ToLower() != "ch_bluefilm")
  2114. {
  2115. row1.Cells[j - 4].SetCellValue(Num);
  2116. }
  2117. else
  2118. {
  2119. row1.Cells[j - 4].SetCellValue(Data);
  2120. }
  2121. row1.Cells[j - 4].CellStyle = styleborder;
  2122. }
  2123. if (DataTable.Columns[j].ColumnName == "io_qty")
  2124. {
  2125. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2126. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  2127. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  2128. }
  2129. if (DataTable.Columns[j].ColumnName == "rownum")
  2130. {
  2131. row1.Cells[j - 4].SetCellValue(i + 1);
  2132. }
  2133. if (DataTable.Columns[j].ColumnName == "ch_code")
  2134. {
  2135. sheet.AutoSizeColumn(j - 4);
  2136. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  2137. }
  2138. }
  2139. //固定行号分组的时候自动拼接新的DataTable
  2140. if (i == rowNum - 1)
  2141. {
  2142. DataRow dr = FirstDT.NewRow();
  2143. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  2144. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  2145. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  2146. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  2147. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  2148. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  2149. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  2150. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  2151. dr["pd_ordercode"] = First_OrderCode;
  2152. dr["pr_orispeccode"] = First_Prspec;
  2153. dr["ch_splitbatch"] = First_Batch;
  2154. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  2155. dr["num"] = (i % PageSize) + 1;
  2156. dr["io_qty"] = sumCount;
  2157. FirstDT.Rows.Add(dr);
  2158. row1 = sheet.CreateRow(PaintIndex);
  2159. PaintIndex = PaintIndex + 1;
  2160. for (int j = 0; j < ShowColumnCount; j++)
  2161. {
  2162. row1.CreateCell(j);
  2163. if (j == 0)
  2164. {
  2165. row1.Cells[j].SetCellValue(小计);
  2166. }
  2167. else if (j == ShowPieceIndex)
  2168. {
  2169. row1.Cells[ShowPieceIndex].SetCellValue((rowNum % PageSize == 0 ? PageSize : (rowNum % PageSize)) + 片);
  2170. row1.Cells[1].CellStyle = ColumnTitleStyle;
  2171. }
  2172. else if (j == ShowCountIndex)
  2173. {
  2174. row1.Cells[j].SetCellValue(sumCount);
  2175. }
  2176. row1.Cells[j].CellStyle = styleborder;
  2177. }
  2178. row1 = sheet.CreateRow(PaintIndex);
  2179. for (int j = 0; j < columnNum - 3; j++)
  2180. {
  2181. if (j == 0)
  2182. {
  2183. row1.CreateCell(j);
  2184. row1.Cells[j].SetCellValue("备注");
  2185. }
  2186. else if (j == ShowCountIndex)
  2187. {
  2188. row1.CreateCell(j);
  2189. row1.Cells[j].SetCellValue(totalCount);
  2190. }
  2191. else if (j == ShowRemarkPiece)
  2192. {
  2193. row1.CreateCell(j);
  2194. row1.Cells[j].SetCellValue(rowNum + 片);
  2195. }
  2196. else
  2197. {
  2198. row1.CreateCell(j);
  2199. }
  2200. row1.Cells[j].CellStyle = style;
  2201. }
  2202. sheet.SetRowBreak(PaintIndex);
  2203. sheet.Footer.Center = "第&P页,共&N页";
  2204. }
  2205. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  2206. pib_outboxcode1.Add(BoxCode.ToString());
  2207. }
  2208. break;
  2209. case "BatchCode":
  2210. string LastBatchCode = "";
  2211. int PageNum = 0;
  2212. for (int i = 0; i < rowNum; i++)
  2213. {
  2214. row1 = sheet.CreateRow(PaintIndex);
  2215. if (i != 0)
  2216. PaintIndex = PaintIndex + 1;
  2217. row1.HeightInPoints = RowHeight;
  2218. //如果批号不相等的时候
  2219. if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
  2220. {
  2221. BoxCode = BoxCode + 1;
  2222. for (int j = 0; j < ShowColumnCount; j++)
  2223. {
  2224. row1.CreateCell(j);
  2225. if (j == 0)
  2226. {
  2227. row1.Cells[j].SetCellValue(小计);
  2228. row1.Cells[j].CellStyle = styleborder;
  2229. }
  2230. else if (j == ShowPieceIndex)
  2231. {
  2232. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 片);
  2233. row1.Cells[1].CellStyle = ColumnTitleStyle;
  2234. }
  2235. else if (j == ShowCountIndex)
  2236. {
  2237. row1.Cells[j].SetCellValue(sumCount);
  2238. row1.Cells[j].CellStyle = styleborder;
  2239. }
  2240. else
  2241. {
  2242. row1.Cells[j].CellStyle = styleborder;
  2243. }
  2244. }
  2245. sumCount = 0;
  2246. //row1 = sheet.CreateRow(PaintIndex);
  2247. sheet.SetRowBreak(PaintIndex - 1);
  2248. sheet.Footer.Center = "第&P页,共&N页";
  2249. PageNum = 0;
  2250. }
  2251. //每次到了页数开始分页
  2252. if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()))
  2253. {
  2254. LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
  2255. //第一行添加客户信息
  2256. row1 = sheet.CreateRow(PaintIndex);
  2257. PaintIndex = PaintIndex + 1;
  2258. row1.CreateCell(0).SetCellValue(" " + companyname);
  2259. row1.GetCell(0).CellStyle = TitleStyle;
  2260. row1 = sheet.CreateRow(PaintIndex);
  2261. PaintIndex = PaintIndex + 1;
  2262. //if (i != rowNum - 1)
  2263. {
  2264. for (int j = 0; j < columnNum - 3; j++)
  2265. {
  2266. if (j == 0)
  2267. {
  2268. row1.CreateCell(j);
  2269. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  2270. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  2271. }
  2272. else if (j == ShowDataIndex)
  2273. {
  2274. row1.CreateCell(j);
  2275. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  2276. }
  2277. else
  2278. {
  2279. row1.CreateCell(j);
  2280. }
  2281. row1.GetCell(j).CellStyle = style;
  2282. }
  2283. row1 = sheet.CreateRow(PaintIndex);
  2284. PaintIndex = PaintIndex + 1;
  2285. //第二行添加型号
  2286. for (int j = 0; j < columnNum - 3; j++)
  2287. {
  2288. if (j == 0)
  2289. {
  2290. row1.CreateCell(j);
  2291. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  2292. + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  2293. }
  2294. else if (j == ShowSizeIndex)
  2295. {
  2296. row1.CreateCell(j);
  2297. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  2298. }
  2299. else if (j == ShowDataIndex)
  2300. {
  2301. row1.CreateCell(j);
  2302. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  2303. }
  2304. else
  2305. {
  2306. row1.CreateCell(j);
  2307. }
  2308. row1.GetCell(j).CellStyle = style;
  2309. }
  2310. //特殊客户添加一列空行
  2311. row1 = sheet.CreateRow(PaintIndex);
  2312. PaintIndex = PaintIndex + 1;
  2313. for (int j = 0; j < columnNum; j++)
  2314. {
  2315. row1.CreateCell(j).SetCellValue("");
  2316. }
  2317. //添加列名
  2318. row1 = sheet.CreateRow(PaintIndex);
  2319. PaintIndex = PaintIndex + 1;
  2320. int showcount = 0;
  2321. for (int j = 4; j < columnNum; j++)
  2322. {
  2323. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  2324. {
  2325. showcount = showcount + 1;
  2326. row1.CreateCell(j - 4);
  2327. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2328. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  2329. }
  2330. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  2331. {
  2332. showcount = showcount + 1;
  2333. row1.CreateCell(j - 4);
  2334. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2335. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  2336. }
  2337. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  2338. {
  2339. showcount = showcount + 1;
  2340. row1.CreateCell(j - 4);
  2341. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2342. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  2343. }
  2344. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  2345. {
  2346. showcount = showcount + 1;
  2347. row1.CreateCell(j - 4);
  2348. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2349. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  2350. }
  2351. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  2352. {
  2353. showcount = showcount + 1;
  2354. row1.CreateCell(j - 4);
  2355. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2356. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  2357. }
  2358. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2359. {
  2360. }
  2361. else
  2362. {
  2363. showcount = showcount + 1;
  2364. row1.CreateCell(j - 4);
  2365. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2366. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  2367. }
  2368. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  2369. {
  2370. NumIndex = j - 4;
  2371. }
  2372. }
  2373. ShowColumnCount = showcount;
  2374. row1 = sheet.CreateRow(PaintIndex);
  2375. PaintIndex = PaintIndex + 1;
  2376. }
  2377. }
  2378. //添加数据内容
  2379. for (int j = 4; j < columnNum; j++)
  2380. {
  2381. string Data = DataTable.Rows[i][j].ToString();
  2382. row1.CreateCell(j - 4);
  2383. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  2384. {
  2385. row1.CreateCell(j - 4, CellType.String);
  2386. }
  2387. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2388. {
  2389. }
  2390. else
  2391. {
  2392. double Num = 0;
  2393. if (double.TryParse(Data, out Num) && DataTable.Columns[j].ColumnName.ToLower() != "ch_bluefilm")
  2394. {
  2395. row1.Cells[j - 4].SetCellValue(Num);
  2396. }
  2397. else
  2398. {
  2399. row1.Cells[j - 4].SetCellValue(Data);
  2400. }
  2401. row1.Cells[j - 4].CellStyle = styleborder;
  2402. }
  2403. if (DataTable.Columns[j].ColumnName == "io_qty")
  2404. {
  2405. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2406. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  2407. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  2408. }
  2409. if (DataTable.Columns[j].ColumnName == "rownum")
  2410. {
  2411. row1.Cells[j - 4].SetCellValue(i + 1);
  2412. }
  2413. if (DataTable.Columns[j].ColumnName == "ch_code")
  2414. {
  2415. sheet.AutoSizeColumn(j - 4);
  2416. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  2417. }
  2418. }
  2419. if (i == rowNum - 1)
  2420. {
  2421. row1 = sheet.CreateRow(PaintIndex);
  2422. PaintIndex = PaintIndex + 1;
  2423. for (int j = 0; j < ShowColumnCount; j++)
  2424. {
  2425. row1.CreateCell(j);
  2426. if (j == 0)
  2427. {
  2428. row1.Cells[j].SetCellValue(小计);
  2429. row1.Cells[j].CellStyle = styleborder;
  2430. }
  2431. else if (j == ShowPieceIndex)
  2432. {
  2433. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 片);
  2434. row1.Cells[1].CellStyle = ColumnTitleStyle;
  2435. }
  2436. else if (j == ShowCountIndex)
  2437. {
  2438. row1.Cells[j].SetCellValue(sumCount);
  2439. row1.Cells[j].CellStyle = styleborder;
  2440. }
  2441. else
  2442. {
  2443. row1.Cells[j].CellStyle = styleborder;
  2444. }
  2445. }
  2446. //创建备注内容
  2447. row1 = sheet.CreateRow(PaintIndex);
  2448. for (int j = 0; j < columnNum - 3; j++)
  2449. {
  2450. if (j == 0)
  2451. {
  2452. row1.CreateCell(j);
  2453. row1.Cells[j].SetCellValue("备注");
  2454. }
  2455. else if (j == ShowCountIndex)
  2456. {
  2457. row1.CreateCell(j);
  2458. row1.Cells[j].SetCellValue(totalCount);
  2459. }
  2460. else if (j == ShowRemarkPiece)
  2461. {
  2462. row1.CreateCell(j);
  2463. row1.Cells[j].SetCellValue(rowNum + 片);
  2464. }
  2465. else
  2466. {
  2467. row1.CreateCell(j);
  2468. }
  2469. row1.Cells[j].CellStyle = style;
  2470. }
  2471. sheet.SetRowBreak(PaintIndex);
  2472. sheet.Footer.Center = "第&P页,共&N页";
  2473. PageNum = 0;
  2474. }
  2475. PageNum = PageNum + 1;
  2476. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  2477. pib_outboxcode1.Add(BoxCode.ToString());
  2478. }
  2479. break;
  2480. case "BoxCode":
  2481. string LastBoxCode = "";
  2482. int PageNum1 = 0;
  2483. for (int i = 0; i < rowNum; i++)
  2484. {
  2485. row1 = sheet.CreateRow(PaintIndex);
  2486. if (i != 0)
  2487. PaintIndex = PaintIndex + 1;
  2488. row1.HeightInPoints = RowHeight;
  2489. //如果箱号不相等的时候
  2490. if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
  2491. {
  2492. BoxCode = BoxCode + 1;
  2493. for (int j = 0; j < ShowColumnCount; j++)
  2494. {
  2495. row1.CreateCell(j);
  2496. if (j == 0)
  2497. {
  2498. row1.Cells[j].SetCellValue(小计);
  2499. row1.Cells[j].CellStyle = styleborder;
  2500. }
  2501. else if (j == ShowPieceIndex)
  2502. {
  2503. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  2504. row1.Cells[1].CellStyle = ColumnTitleStyle;
  2505. }
  2506. else if (j == ShowCountIndex)
  2507. {
  2508. row1.Cells[j].SetCellValue(sumCount);
  2509. row1.Cells[j].CellStyle = styleborder;
  2510. }
  2511. else
  2512. {
  2513. row1.Cells[j].CellStyle = styleborder;
  2514. }
  2515. }
  2516. sumCount = 0;
  2517. //row1 = sheet.CreateRow(PaintIndex);
  2518. sheet.SetRowBreak(PaintIndex - 1);
  2519. sheet.Footer.Center = "第&P页,共&N页";
  2520. PageNum1 = 0;
  2521. }
  2522. //每次到了页数开始分页
  2523. if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString())))
  2524. {
  2525. LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
  2526. row1 = sheet.CreateRow(PaintIndex);
  2527. PaintIndex = PaintIndex + 1;
  2528. row1.CreateCell(0).SetCellValue(" " + companyname);
  2529. row1.GetCell(0).CellStyle = TitleStyle;
  2530. row1 = sheet.CreateRow(PaintIndex);
  2531. PaintIndex = PaintIndex + 1;
  2532. //第一行添加客户信息
  2533. //if (i != rowNum - 1)
  2534. {
  2535. for (int j = 0; j < columnNum - 3; j++)
  2536. {
  2537. if (j == 0)
  2538. {
  2539. row1.CreateCell(j);
  2540. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  2541. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  2542. }
  2543. else if (j == ShowDataIndex)
  2544. {
  2545. row1.CreateCell(j);
  2546. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  2547. }
  2548. else
  2549. {
  2550. row1.CreateCell(j);
  2551. }
  2552. row1.GetCell(j).CellStyle = style;
  2553. }
  2554. row1 = sheet.CreateRow(PaintIndex);
  2555. PaintIndex = PaintIndex + 1;
  2556. //第二行添加型号
  2557. for (int j = 0; j < columnNum - 3; j++)
  2558. {
  2559. if (j == 0)
  2560. {
  2561. row1.CreateCell(j);
  2562. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  2563. + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  2564. }
  2565. else if (j == ShowSizeIndex)
  2566. {
  2567. row1.CreateCell(j);
  2568. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  2569. }
  2570. else if (j == ShowDataIndex)
  2571. {
  2572. row1.CreateCell(j);
  2573. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  2574. }
  2575. else
  2576. {
  2577. row1.CreateCell(j);
  2578. }
  2579. row1.GetCell(j).CellStyle = style;
  2580. }
  2581. //特殊客户添加一列空行
  2582. row1 = sheet.CreateRow(PaintIndex);
  2583. PaintIndex = PaintIndex + 1;
  2584. for (int j = 0; j < columnNum; j++)
  2585. {
  2586. row1.CreateCell(j).SetCellValue("");
  2587. }
  2588. //添加列名
  2589. row1 = sheet.CreateRow(PaintIndex);
  2590. PaintIndex = PaintIndex + 1;
  2591. int showcount = 0;
  2592. for (int j = 4; j < columnNum; j++)
  2593. {
  2594. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  2595. {
  2596. showcount = showcount + 1;
  2597. row1.CreateCell(j - 4);
  2598. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2599. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  2600. }
  2601. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  2602. {
  2603. showcount = showcount + 1;
  2604. row1.CreateCell(j - 4);
  2605. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2606. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  2607. }
  2608. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  2609. {
  2610. showcount = showcount + 1;
  2611. row1.CreateCell(j - 4);
  2612. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2613. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  2614. }
  2615. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  2616. {
  2617. showcount = showcount + 1;
  2618. row1.CreateCell(j - 4);
  2619. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2620. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  2621. }
  2622. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  2623. {
  2624. showcount = showcount + 1;
  2625. row1.CreateCell(j - 4);
  2626. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2627. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  2628. }
  2629. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2630. {
  2631. }
  2632. else
  2633. {
  2634. showcount = showcount + 1;
  2635. row1.CreateCell(j - 4);
  2636. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  2637. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  2638. }
  2639. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  2640. {
  2641. NumIndex = j - 4;
  2642. }
  2643. }
  2644. ShowColumnCount = showcount;
  2645. row1 = sheet.CreateRow(PaintIndex);
  2646. PaintIndex = PaintIndex + 1;
  2647. }
  2648. }
  2649. //添加数据内容
  2650. for (int j = 4; j < columnNum; j++)
  2651. {
  2652. string Data = DataTable.Rows[i][j].ToString();
  2653. row1.CreateCell(j - 4);
  2654. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  2655. {
  2656. row1.CreateCell(j - 4, CellType.String);
  2657. }
  2658. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  2659. {
  2660. }
  2661. else
  2662. {
  2663. double Num = 0;
  2664. if (double.TryParse(Data, out Num) && DataTable.Columns[j].ColumnName.ToLower() != "ch_bluefilm")
  2665. {
  2666. row1.Cells[j - 4].SetCellValue(Num);
  2667. }
  2668. else
  2669. {
  2670. row1.Cells[j - 4].SetCellValue(Data);
  2671. }
  2672. row1.Cells[j - 4].CellStyle = styleborder;
  2673. }
  2674. if (DataTable.Columns[j].ColumnName == "io_qty")
  2675. {
  2676. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2677. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  2678. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  2679. }
  2680. if (DataTable.Columns[j].ColumnName == "rownum")
  2681. {
  2682. row1.Cells[j - 4].SetCellValue(i + 1);
  2683. }
  2684. if (DataTable.Columns[j].ColumnName == "ch_code")
  2685. {
  2686. sheet.AutoSizeColumn(j - 4);
  2687. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  2688. }
  2689. }
  2690. if (i == rowNum - 1)
  2691. {
  2692. PageNum1 = PageNum1 + 1;
  2693. row1 = sheet.CreateRow(PaintIndex);
  2694. PaintIndex = PaintIndex + 1;
  2695. for (int j = 0; j < ShowColumnCount; j++)
  2696. {
  2697. row1.CreateCell(j);
  2698. if (j == 0)
  2699. {
  2700. row1.Cells[j].SetCellValue(小计);
  2701. row1.Cells[j].CellStyle = styleborder;
  2702. }
  2703. else if (j == ShowPieceIndex)
  2704. {
  2705. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1 + 片);
  2706. row1.Cells[1].CellStyle = ColumnTitleStyle;
  2707. }
  2708. else if (j == ShowCountIndex)
  2709. {
  2710. row1.Cells[j].SetCellValue(sumCount);
  2711. row1.Cells[j].CellStyle = styleborder;
  2712. }
  2713. else
  2714. {
  2715. row1.Cells[j].CellStyle = styleborder;
  2716. }
  2717. }
  2718. row1 = sheet.CreateRow(PaintIndex);
  2719. for (int j = 0; j < columnNum - 3; j++)
  2720. {
  2721. if (j == 0)
  2722. {
  2723. row1.CreateCell(j);
  2724. row1.Cells[j].SetCellValue("备注");
  2725. }
  2726. else if (j == ShowCountIndex)
  2727. {
  2728. row1.CreateCell(j);
  2729. row1.Cells[j].SetCellValue(totalCount);
  2730. }
  2731. else if (j == ShowRemarkPiece)
  2732. {
  2733. row1.CreateCell(j);
  2734. row1.Cells[j].SetCellValue(rowNum + 片);
  2735. }
  2736. else
  2737. {
  2738. row1.CreateCell(j);
  2739. }
  2740. row1.Cells[j].CellStyle = style;
  2741. }
  2742. sheet.SetRowBreak(PaintIndex);
  2743. sheet.Footer.Center = "第&P页,共&N页";
  2744. PageNum1 = 0;
  2745. }
  2746. PageNum1 = PageNum1 + 1;
  2747. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  2748. pib_outboxcode1.Add(BoxCode.ToString());
  2749. }
  2750. break;
  2751. default:
  2752. break;
  2753. }
  2754. dh.BatchInsert("update prodiobarcode set pib_outboxcode1=:pib_outboxcode1 where pib_inoutno='" + Inoutno + "' and pib_id=:pib_id", new string[] { "pib_outboxcode1", "pib_id" }, pib_outboxcode1.ToArray(), pib_id.ToArray());
  2755. //删除下载链接再重新插入
  2756. HttpHandler.GenDownLoadLinK(Inoutno);
  2757. //填充首页
  2758. sumCount = 0;
  2759. totalCount = 0;
  2760. PaintIndex = 1;
  2761. ISheet sheet2 = book.CreateSheet("首页");
  2762. IRow row = sheet2.CreateRow(0);
  2763. row.CreateCell(0);
  2764. row.Cells[0].SetCellValue(" " + companyname);
  2765. row.GetCell(0).CellStyle = style;
  2766. rowNum = FirstDT.Rows.Count;
  2767. //不需要显示的列移除
  2768. for (int i = FirstDT.Columns.Count - 1; i > 0; i--)
  2769. {
  2770. for (int j = 0; j < box.Length; j++)
  2771. {
  2772. if (box[j].Name == "FirstPage_WID" && !box[j].Checked)
  2773. {
  2774. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  2775. {
  2776. FirstDT.Columns.RemoveAt(i);
  2777. }
  2778. }
  2779. if (box[j].Name == "FirstPage_YIELD" && !box[j].Checked)
  2780. {
  2781. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_yeild"))
  2782. {
  2783. FirstDT.Columns.RemoveAt(i);
  2784. }
  2785. }
  2786. if (box[j].Name == "FirstPage_REMARK" && !box[j].Checked)
  2787. {
  2788. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  2789. {
  2790. FirstDT.Columns.RemoveAt(i);
  2791. }
  2792. }
  2793. if (box[j].Name == "FirstPage_BOXCODE" && !box[j].Checked)
  2794. {
  2795. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  2796. {
  2797. FirstDT.Columns.RemoveAt(i);
  2798. }
  2799. }
  2800. }
  2801. }
  2802. columnNum = FirstDT.Columns.Count;
  2803. for (int i = 0; i < rowNum; i++)
  2804. {
  2805. row1 = sheet2.CreateRow(PaintIndex);
  2806. PaintIndex = PaintIndex + 1;
  2807. row1.HeightInPoints = RowHeight;
  2808. //只需要绘制一行
  2809. if (i == 0)
  2810. {
  2811. for (int j = 0; j < columnNum - 3; j++)
  2812. {
  2813. if (j == 0)
  2814. {
  2815. row1.CreateCell(j);
  2816. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_title"].Caption + ":" + FirstDT.Rows[i]["pi_title"].ToString() + " "
  2817. + FirstDT.Columns["ch_level"].Caption + ":" + FirstDT.Rows[i]["ch_level"].ToString());
  2818. }
  2819. else if (j > 5 && j == columnNum - 5)
  2820. {
  2821. row1.CreateCell(j);
  2822. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  2823. }
  2824. else if (columnNum > 5 && j == columnNum - 5)
  2825. {
  2826. row1.CreateCell(j);
  2827. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  2828. }
  2829. else
  2830. {
  2831. row1.CreateCell(j);
  2832. }
  2833. row1.GetCell(j).CellStyle = style;
  2834. }
  2835. row1 = sheet2.CreateRow(PaintIndex);
  2836. PaintIndex = PaintIndex + 1;
  2837. //第二行添加型号
  2838. for (int j = 0; j < columnNum - 3; j++)
  2839. {
  2840. if (j == 0)
  2841. {
  2842. row1.CreateCell(j).SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + " "
  2843. + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  2844. }
  2845. else if (j == ShowSizeIndex)
  2846. {
  2847. row1.CreateCell(j);
  2848. row1.Cells[j].SetCellValue(FirstDT.Columns["pr_size"].Caption + ":" + FirstDT.Rows[i]["pr_size"].ToString());
  2849. }
  2850. else if (j > 5 && j == columnNum - 5)
  2851. {
  2852. row1.CreateCell(j);
  2853. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  2854. }
  2855. else if (columnNum > 5 && j == columnNum - 5)
  2856. {
  2857. row1.CreateCell(j);
  2858. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  2859. }
  2860. else
  2861. {
  2862. row1.CreateCell(j);
  2863. }
  2864. row1.GetCell(j).CellStyle = style;
  2865. }
  2866. row1 = sheet2.CreateRow(PaintIndex);
  2867. PaintIndex = PaintIndex + 1;
  2868. //添加列名
  2869. for (int j = 4; j < columnNum; j++)
  2870. {
  2871. row1.CreateCell(j - 4);
  2872. if (NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  2873. {
  2874. }
  2875. else
  2876. {
  2877. row1.Cells[j - 4].CellStyle = styleborder;
  2878. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  2879. }
  2880. }
  2881. row1 = sheet2.CreateRow(PaintIndex);
  2882. PaintIndex = PaintIndex + 1;
  2883. }
  2884. //添加数据内容
  2885. ShowColumnCount = 0;
  2886. for (int j = 4; j < columnNum; j++)
  2887. {
  2888. row1.CreateCell(j - 4);
  2889. if (FirstDT.Columns[j].ColumnName == "ch_bluefilm")
  2890. {
  2891. row1.CreateCell(j - 4, CellType.String);
  2892. }
  2893. if (!NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  2894. {
  2895. string Data = FirstDT.Rows[i][j].ToString();
  2896. row1.Cells[j - 4].SetCellValue(Data);
  2897. row1.GetCell(j - 4).CellStyle = styleborder;
  2898. if (FirstDT.Columns[j].ColumnName == "num")
  2899. {
  2900. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2901. sumCount += int.Parse(Data);
  2902. }
  2903. if (FirstDT.Columns[j].ColumnName == "io_qty")
  2904. {
  2905. totalCount += int.Parse(Data);
  2906. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  2907. }
  2908. ShowColumnCount = ShowColumnCount + 1;
  2909. }
  2910. else
  2911. {
  2912. }
  2913. }
  2914. //添加总计行
  2915. if (i == rowNum - 1)
  2916. {
  2917. row1 = sheet2.CreateRow(PaintIndex);
  2918. PaintIndex = PaintIndex + 1;
  2919. for (int j = 0; j < ShowColumnCount; j++)
  2920. {
  2921. if (j == 0)
  2922. {
  2923. row1.CreateCell(j);
  2924. row1.Cells[j].CellStyle = styleborder;
  2925. row1.Cells[j].SetCellValue(总计);
  2926. }
  2927. else if (j == ShowColumnCount - 2)
  2928. {
  2929. row1.CreateCell(j);
  2930. row1.Cells[j].CellStyle = styleborder;
  2931. row1.Cells[j].SetCellValue(sumCount);
  2932. }
  2933. else if (j == ShowColumnCount - 1)
  2934. {
  2935. row1.CreateCell(j);
  2936. row1.Cells[j].CellStyle = styleborder;
  2937. row1.Cells[j].SetCellValue(totalCount);
  2938. }
  2939. else
  2940. {
  2941. row1.CreateCell(j);
  2942. row1.Cells[j].CellStyle = styleborder;
  2943. }
  2944. }
  2945. }
  2946. }
  2947. for (int i = 0; i < sheet2.LastRowNum; i++)
  2948. {
  2949. if (i != 0)
  2950. {
  2951. sheet2.AutoSizeColumn(i);
  2952. sheet2.SetColumnWidth(i, sheet2.GetColumnWidth(i) + 1000);
  2953. }
  2954. }
  2955. //将book的内容写入内存流中返回
  2956. book.Write(ms);
  2957. return ms;
  2958. }
  2959. /// <summary>
  2960. /// 将DataTable形式的数据转成Excel格式的,然后用字节流的形式写入文件
  2961. /// </summary>
  2962. /// <param name="DataTable"></param>
  2963. /// <returns></returns>
  2964. private MemoryStream DataTableToExcel_LIPUXIN(DataTable FirstDT, DataTable DataTable, string Type, string Inoutno, int PageSize, List<CheckBox> conditionbox)
  2965. {
  2966. string 小计 = "";
  2967. string 批小计 = "";
  2968. string 总计 = "";
  2969. string 片 = "";
  2970. string companyname = "";
  2971. int ShowBoxIndex = 0;
  2972. //用于小计的盒号
  2973. string LastBox = "";
  2974. if (dh.getFieldDataByCondition("ProdInout", "pi_exporttype", "pi_inoutno='" + Inoutno + "'").ToString() == "Chinese")
  2975. {
  2976. 小计 = "小计";
  2977. 总计 = "总计";
  2978. 批小计 = "批小计";
  2979. 片 = "片";
  2980. companyname = "深爱半导体股份有限公司芯片出货清单";
  2981. }
  2982. else
  2983. {
  2984. 批小计 = "BatchTotal";
  2985. 小计 = "total";
  2986. 总计 = "total";
  2987. companyname = "SHENZHEN SI SEMICONDUCTORS CO.,LTD";
  2988. }
  2989. //转换为序列
  2990. CheckBox[] box = conditionbox.ToArray();
  2991. //创建内存流
  2992. MemoryStream ms = new MemoryStream();
  2993. //创建一个Book,相当于一个Excel文件
  2994. HSSFWorkbook book = new HSSFWorkbook();
  2995. //Excel中的Sheet
  2996. ISheet sheet = book.CreateSheet("分页");
  2997. sheet.SetMargin(MarginType.TopMargin, 0.4);
  2998. sheet.SetMargin(MarginType.BottomMargin, 0.4);
  2999. sheet.SetMargin(MarginType.LeftMargin, 0.4);
  3000. sheet.SetMargin(MarginType.RightMargin, 0.4);
  3001. sheet.FitToPage = true;
  3002. sheet.PrintSetup.FitHeight = 200;
  3003. //芯片号需要作为更新盒号的条件
  3004. HSSFFont ffont = (HSSFFont)book.CreateFont();
  3005. ffont.FontName = "宋体";
  3006. //更新箱号
  3007. List<string> pib_id = new List<string>();
  3008. //系统打印箱号
  3009. List<string> pib_outboxcode1 = new List<string>();
  3010. int BoxCode = 1;
  3011. ICellStyle style = book.CreateCellStyle();
  3012. style.VerticalAlignment = VerticalAlignment.Center;
  3013. style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  3014. style.SetFont(ffont);
  3015. ICellStyle styleborder = book.CreateCellStyle();
  3016. styleborder.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  3017. styleborder.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  3018. styleborder.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  3019. styleborder.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  3020. styleborder.VerticalAlignment = VerticalAlignment.Center;
  3021. styleborder.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  3022. styleborder.SetFont(ffont);
  3023. string pi_inoutno = "";
  3024. HSSFFont ColumnTitle = (HSSFFont)book.CreateFont();
  3025. ColumnTitle.FontName = "宋体";
  3026. ColumnTitle.Boldweight = (short)FontBoldWeight.Bold;
  3027. ICellStyle ColumnTitleStyle = book.CreateCellStyle();
  3028. ColumnTitleStyle.SetFont(ColumnTitle);
  3029. ColumnTitleStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  3030. ColumnTitleStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  3031. ColumnTitleStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  3032. ColumnTitleStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  3033. List<string> NotShowColumn = new List<string>();
  3034. NotShowColumn.Add("ch_level");
  3035. NotShowColumn.Add("pib_id");
  3036. NotShowColumn.Add("chw_itemname1");
  3037. NotShowColumn.Add("chw_itemname2");
  3038. NotShowColumn.Add("chw_itemname3");
  3039. NotShowColumn.Add("chw_itemname4");
  3040. NotShowColumn.Add("chw_itemname5");
  3041. NotShowColumn.Add("pd_ordercode");
  3042. NotShowColumn.Add("pr_size");
  3043. NotShowColumn.Add("me_desc");
  3044. NotShowColumn.Add("pr_orispeccode");
  3045. NotShowColumn.Add("pr_orispeccode1");
  3046. NotShowColumn.Add("pi_title");
  3047. NotShowColumn.Add("pi_chipouttype");
  3048. NotShowColumn.Add("pi_date");
  3049. int ShowColumnCount = 0;
  3050. //展示的内容列
  3051. //设置列的宽度,根据首行的列的内容的长度来设置
  3052. for (int i = DataTable.Columns.Count - 1; i > 0; i--)
  3053. {
  3054. for (int j = 0; j < box.Length; j++)
  3055. {
  3056. if (box[j].Name.ToLower() == "ch_bluefilm" && !box[j].Checked)
  3057. {
  3058. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_bluefilm"))
  3059. {
  3060. DataTable.Columns.RemoveAt(i);
  3061. break;
  3062. }
  3063. }
  3064. if (box[j].Name.ToLower() == "ch_code" && !box[j].Checked)
  3065. {
  3066. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_code"))
  3067. {
  3068. DataTable.Columns.RemoveAt(i);
  3069. break;
  3070. }
  3071. }
  3072. if (box[j].Name.ToLower() == "ch_splitbatch" && !box[j].Checked)
  3073. {
  3074. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_splitbatch"))
  3075. {
  3076. DataTable.Columns.RemoveAt(i);
  3077. break;
  3078. }
  3079. }
  3080. if (box[j].Name.ToLower() == "ch_waterid" && !box[j].Checked)
  3081. {
  3082. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  3083. {
  3084. DataTable.Columns.RemoveAt(i);
  3085. break;
  3086. }
  3087. }
  3088. if (box[j].Name.ToLower() == "ch_pbcode" && !box[j].Checked)
  3089. {
  3090. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  3091. {
  3092. DataTable.Columns.RemoveAt(i);
  3093. break;
  3094. }
  3095. }
  3096. if (box[j].Name.ToLower() == "ch_remark" && !box[j].Checked)
  3097. {
  3098. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  3099. {
  3100. DataTable.Columns.RemoveAt(i);
  3101. break;
  3102. }
  3103. }
  3104. if (box[j].Name.ToLower() == "ch_yield" && !box[j].Checked)
  3105. {
  3106. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_yield"))
  3107. {
  3108. DataTable.Columns.RemoveAt(i);
  3109. break;
  3110. }
  3111. }
  3112. }
  3113. }
  3114. //获取行数量和列数量
  3115. int rowNum = DataTable.Rows.Count;
  3116. int columnNum = DataTable.Columns.Count;
  3117. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  3118. IRow row = sheet.CreateRow(0);
  3119. //冻结第一行
  3120. sheet.CreateFreezePane(0, 1, 0, 1);
  3121. row.HeightInPoints = RowHeight;
  3122. //固定第一行
  3123. //row.RowStyle.IsLocked=true;
  3124. //给第一行的标签赋值样式和值
  3125. // ffont.FontHeight = 13;
  3126. row.CreateCell(0);
  3127. row.Cells[0].SetCellValue(" " + companyname);
  3128. row.GetCell(0).CellStyle.SetFont((ffont));
  3129. //ffont.FontHeight = 10;
  3130. //开始绘制的Index
  3131. int PaintIndex = 1;
  3132. int sumCount = 0;
  3133. int totalCount = 0;
  3134. switch (Type)
  3135. {
  3136. case "FixRow":
  3137. //清理系统取出来的数据
  3138. BaseUtil.CleanDataTableData(FirstDT);
  3139. //首页参数拼接
  3140. string First_OrderCode = "";
  3141. string First_Prspec = "";
  3142. string First_Batch = "";
  3143. int NumIndex = 0;
  3144. ArrayList<string> First_WID = new ArrayList<string>();
  3145. for (int i = 0; i < rowNum; i++)
  3146. {
  3147. IRow row1 = sheet.CreateRow(PaintIndex);
  3148. PaintIndex = PaintIndex + 1;
  3149. row1.HeightInPoints = RowHeight;
  3150. //不包含的订单号
  3151. if (DataTable.Columns.Contains("pd_ordercode") && !First_OrderCode.Contains(DataTable.Rows[i]["pd_ordercode"].ToString()))
  3152. {
  3153. First_OrderCode += DataTable.Rows[i]["pd_ordercode"].ToString() + " ";
  3154. }
  3155. //不包含的物料型号
  3156. if (DataTable.Columns.Contains("pr_orispeccode") && !First_Prspec.Contains(DataTable.Rows[i]["pr_orispeccode"].ToString()))
  3157. {
  3158. First_Prspec += DataTable.Rows[i]["pr_orispeccode"].ToString() + " ";
  3159. }
  3160. //不包含扩撒批号
  3161. if (DataTable.Columns.Contains("ch_splitbatch") && !First_Batch.Contains(DataTable.Rows[i]["ch_splitbatch"].ToString()))
  3162. {
  3163. First_Batch += DataTable.Rows[i]["ch_splitbatch"].ToString() + " ";
  3164. }
  3165. //不包含Wafer_id
  3166. if (DataTable.Columns.Contains("Wafer_ID") && !First_WID.Contains(DataTable.Rows[i]["Wafer_ID"].ToString()))
  3167. {
  3168. First_WID.Add(DataTable.Rows[i]["Wafer_ID"].ToString());
  3169. }
  3170. if (i / PageSize >= 1 && i % PageSize == 0)
  3171. {
  3172. DataRow dr = FirstDT.NewRow();
  3173. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  3174. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  3175. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  3176. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  3177. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  3178. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  3179. pi_inoutno = DataTable.Rows[i]["pi_inoutno"].ToString();
  3180. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  3181. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  3182. dr["pd_ordercode"] = First_OrderCode;
  3183. dr["pr_orispeccode"] = First_Prspec;
  3184. dr["ch_splitbatch"] = First_Batch;
  3185. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  3186. dr["num"] = PageSize;
  3187. dr["io_qty"] = sumCount;
  3188. FirstDT.Rows.Add(dr);
  3189. First_OrderCode = "";
  3190. First_Prspec = "";
  3191. First_Batch = "";
  3192. First_WID.Clear();
  3193. BoxCode = BoxCode + 1;
  3194. for (int j = 0; j < ShowColumnCount; j++)
  3195. {
  3196. row1.CreateCell(j);
  3197. if (j == 0)
  3198. {
  3199. row1.Cells[j].SetCellValue(批小计);
  3200. }
  3201. else if (j == ShowPieceIndex)
  3202. {
  3203. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i));
  3204. row1.Cells[j].CellStyle = styleborder;
  3205. }
  3206. else if (j == ShowCountIndex)
  3207. {
  3208. row1.Cells[j].SetCellValue(sumCount);
  3209. }
  3210. else if (j == ShowBoxIndex - 4)
  3211. {
  3212. row1.Cells[j].SetCellValue(LastBox);
  3213. row1.Cells[j].CellStyle = styleborder;
  3214. }
  3215. row1.Cells[j].CellStyle = styleborder;
  3216. }
  3217. row1 = sheet.CreateRow(PaintIndex);
  3218. PaintIndex = PaintIndex + 1;
  3219. for (int j = 0; j < ShowColumnCount; j++)
  3220. {
  3221. row1.CreateCell(j);
  3222. if (j == 0)
  3223. {
  3224. row1.Cells[j].SetCellValue(小计);
  3225. }
  3226. else if (j == ShowPieceIndex)
  3227. {
  3228. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i));
  3229. }
  3230. else if (j == ShowCountIndex)
  3231. {
  3232. row1.Cells[j].SetCellValue(sumCount);
  3233. }
  3234. else if (j == ShowBoxIndex - 4)
  3235. {
  3236. row1.Cells[j].SetCellValue(LastBox);
  3237. row1.Cells[j].CellStyle = styleborder;
  3238. }
  3239. row1.Cells[j].CellStyle = styleborder;
  3240. }
  3241. sumCount = 0;
  3242. row1 = sheet.CreateRow(PaintIndex);
  3243. sheet.SetRowBreak(PaintIndex - 1);
  3244. sheet.Footer.Center = "第&P页,共&N页";
  3245. PaintIndex = PaintIndex + 1;
  3246. }
  3247. //每次到了页数开始分页
  3248. if (i % PageSize == 0 || i == rowNum - 1)
  3249. {
  3250. //第一行添加客户信息 rownum只有一行的情
  3251. if (i != rowNum - 1 || rowNum == 1 || (rowNum - i == rowNum % PageSize))
  3252. {
  3253. for (int j = 0; j < columnNum - 3; j++)
  3254. {
  3255. if (j == 0)
  3256. {
  3257. row1.CreateCell(j);
  3258. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  3259. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  3260. }
  3261. else if (j == ShowDataIndex)
  3262. {
  3263. row1.CreateCell(j);
  3264. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  3265. }
  3266. else
  3267. {
  3268. row1.CreateCell(j);
  3269. }
  3270. row1.GetCell(j).CellStyle = style;
  3271. }
  3272. row1 = sheet.CreateRow(PaintIndex);
  3273. PaintIndex = PaintIndex + 1;
  3274. //第二行添加型号
  3275. for (int j = 0; j < columnNum - 3; j++)
  3276. {
  3277. if (j == 0)
  3278. {
  3279. row1.CreateCell(j);
  3280. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString()
  3281. + "_(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  3282. }
  3283. else if (j == ShowSizeIndex)
  3284. {
  3285. row1.CreateCell(j);
  3286. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  3287. }
  3288. else if (j == ShowDataIndex)
  3289. {
  3290. row1.CreateCell(j);
  3291. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  3292. }
  3293. else
  3294. {
  3295. row1.CreateCell(j);
  3296. }
  3297. row1.GetCell(j).CellStyle = style;
  3298. }
  3299. //添加列名
  3300. row1 = sheet.CreateRow(PaintIndex);
  3301. PaintIndex = PaintIndex + 1;
  3302. //计数列所在的索引
  3303. int showcount = 0;
  3304. for (int j = 4; j < columnNum; j++)
  3305. {
  3306. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  3307. {
  3308. showcount = showcount + 1;
  3309. row1.CreateCell(j - 4);
  3310. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3311. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  3312. }
  3313. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  3314. {
  3315. showcount = showcount + 1;
  3316. row1.CreateCell(j - 4);
  3317. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3318. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  3319. }
  3320. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  3321. {
  3322. showcount = showcount + 1;
  3323. row1.CreateCell(j - 4);
  3324. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3325. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  3326. }
  3327. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  3328. {
  3329. showcount = showcount + 1;
  3330. row1.CreateCell(j - 4);
  3331. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3332. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  3333. }
  3334. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  3335. {
  3336. showcount = showcount + 1;
  3337. row1.CreateCell(j - 4);
  3338. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3339. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  3340. }
  3341. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3342. {
  3343. }
  3344. else
  3345. {
  3346. showcount = showcount + 1;
  3347. row1.CreateCell(j - 4);
  3348. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3349. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  3350. }
  3351. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  3352. {
  3353. ShowBoxIndex = j;
  3354. }
  3355. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  3356. {
  3357. NumIndex = j;
  3358. if (ShowCountIndex == NumIndex - 4)
  3359. {
  3360. ShowCountIndex = ShowCountIndex + 1;
  3361. }
  3362. }
  3363. }
  3364. ShowColumnCount = showcount;
  3365. row1 = sheet.CreateRow(PaintIndex);
  3366. PaintIndex = PaintIndex + 1;
  3367. }
  3368. }
  3369. //添加数据内容
  3370. for (int j = 4; j < columnNum; j++)
  3371. {
  3372. string Data = DataTable.Rows[i][j].ToString();
  3373. row1.CreateCell(j - 4);
  3374. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  3375. {
  3376. row1.CreateCell(j - 4, CellType.String);
  3377. }
  3378. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3379. {
  3380. }
  3381. else
  3382. {
  3383. double Num = 0;
  3384. if (double.TryParse(Data, out Num) && DataTable.Columns[j].ColumnName.ToLower() != "ch_bluefilm")
  3385. {
  3386. row1.Cells[j - 4].SetCellValue(Num);
  3387. }
  3388. else
  3389. {
  3390. row1.Cells[j - 4].SetCellValue(Data);
  3391. }
  3392. row1.GetCell(j - 4).CellStyle = styleborder;
  3393. }
  3394. if (DataTable.Columns[j].ColumnName == "io_qty")
  3395. {
  3396. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  3397. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  3398. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  3399. row1.Cells[j - 4].CellStyle = styleborder;
  3400. }
  3401. if (DataTable.Columns[j].ColumnName == "rownum")
  3402. {
  3403. row1.Cells[j - 4].SetCellValue(i + 1);
  3404. row1.Cells[j - 4].CellStyle = styleborder;
  3405. }
  3406. if (DataTable.Columns[j].ColumnName == "ch_code")
  3407. {
  3408. sheet.AutoSizeColumn(j - 4);
  3409. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  3410. }
  3411. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  3412. {
  3413. LastBox = Data;
  3414. }
  3415. }
  3416. //固定行号分组的时候自动拼接新的DataTable
  3417. if (i == rowNum - 1)
  3418. {
  3419. DataRow dr = FirstDT.NewRow();
  3420. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  3421. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  3422. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  3423. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  3424. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  3425. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  3426. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  3427. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  3428. dr["pd_ordercode"] = First_OrderCode;
  3429. dr["pr_orispeccode"] = First_Prspec;
  3430. dr["ch_splitbatch"] = First_Batch;
  3431. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  3432. dr["num"] = (i % PageSize) + 1;
  3433. dr["io_qty"] = sumCount;
  3434. FirstDT.Rows.Add(dr);
  3435. row1 = sheet.CreateRow(PaintIndex);
  3436. PaintIndex = PaintIndex + 1;
  3437. for (int j = 0; j < ShowColumnCount; j++)
  3438. {
  3439. row1.CreateCell(j);
  3440. if (j == 0)
  3441. {
  3442. row1.Cells[j].SetCellValue(批小计);
  3443. }
  3444. else if (j == ShowPieceIndex)
  3445. {
  3446. row1.Cells[ShowPieceIndex].SetCellValue((rowNum % PageSize == 0 ? PageSize : (rowNum % PageSize)));
  3447. row1.Cells[j].CellStyle = styleborder;
  3448. }
  3449. else if (j == ShowBoxIndex - 4)
  3450. {
  3451. row1.Cells[j].SetCellValue(LastBox);
  3452. row1.Cells[j].CellStyle = styleborder;
  3453. }
  3454. else if (j == ShowCountIndex)
  3455. {
  3456. row1.Cells[j].SetCellValue(sumCount);
  3457. }
  3458. row1.Cells[j].CellStyle = styleborder;
  3459. }
  3460. row1 = sheet.CreateRow(PaintIndex);
  3461. PaintIndex = PaintIndex + 1;
  3462. for (int j = 0; j < ShowColumnCount; j++)
  3463. {
  3464. row1.CreateCell(j);
  3465. if (j == 0)
  3466. {
  3467. row1.Cells[j].SetCellValue(小计);
  3468. }
  3469. else if (j == ShowPieceIndex)
  3470. {
  3471. row1.Cells[ShowPieceIndex].SetCellValue(rowNum % PageSize);
  3472. row1.Cells[j].CellStyle = styleborder;
  3473. }
  3474. else if (j == ShowBoxIndex - 4)
  3475. {
  3476. row1.Cells[j].SetCellValue(LastBox);
  3477. row1.Cells[j].CellStyle = styleborder;
  3478. }
  3479. else if (j == ShowCountIndex)
  3480. {
  3481. row1.Cells[j].SetCellValue(sumCount);
  3482. }
  3483. row1.Cells[j].CellStyle = styleborder;
  3484. }
  3485. row1 = sheet.CreateRow(PaintIndex);
  3486. for (int j = 0; j < columnNum - 3; j++)
  3487. {
  3488. if (j == 0)
  3489. {
  3490. row1.CreateCell(j);
  3491. row1.Cells[j].SetCellValue("备注");
  3492. }
  3493. else if (j == ShowCountIndex)
  3494. {
  3495. row1.CreateCell(j);
  3496. row1.Cells[j].SetCellValue(totalCount);
  3497. }
  3498. else if (j == ShowRemarkPiece)
  3499. {
  3500. row1.CreateCell(j);
  3501. row1.Cells[j].SetCellValue(rowNum + 片);
  3502. }
  3503. else
  3504. {
  3505. row1.CreateCell(j);
  3506. }
  3507. row1.Cells[j].CellStyle = style;
  3508. }
  3509. sheet.SetRowBreak(PaintIndex);
  3510. sheet.Footer.Center = "第&P页,共&N页";
  3511. PaintIndex = PaintIndex + 1;
  3512. }
  3513. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  3514. pib_outboxcode1.Add(BoxCode.ToString());
  3515. }
  3516. break;
  3517. case "BatchCode":
  3518. string LastBatchCode = "";
  3519. int PageNum = 0;
  3520. for (int i = 0; i < rowNum; i++)
  3521. {
  3522. IRow row1 = sheet.CreateRow(PaintIndex);
  3523. PaintIndex = PaintIndex + 1;
  3524. row1.HeightInPoints = RowHeight;
  3525. //如果批号不相等的时候
  3526. if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
  3527. {
  3528. BoxCode = BoxCode + 1;
  3529. for (int j = 0; j < ShowColumnCount; j++)
  3530. {
  3531. row1.CreateCell(j);
  3532. if (j == 0)
  3533. {
  3534. row1.Cells[j].SetCellValue(批小计);
  3535. row1.Cells[j].CellStyle = styleborder;
  3536. }
  3537. else if (j == ShowPieceIndex)
  3538. {
  3539. row1.Cells[ShowPieceIndex].SetCellValue(PageNum);
  3540. row1.Cells[j].CellStyle = styleborder;
  3541. }
  3542. else if (j == ShowCountIndex)
  3543. {
  3544. row1.Cells[j].SetCellValue(sumCount);
  3545. row1.Cells[j].CellStyle = styleborder;
  3546. }
  3547. else if (j == ShowBoxIndex - 4)
  3548. {
  3549. row1.Cells[j].SetCellValue(LastBox);
  3550. row1.Cells[j].CellStyle = styleborder;
  3551. }
  3552. else
  3553. {
  3554. row1.Cells[j].CellStyle = styleborder;
  3555. }
  3556. }
  3557. row1 = sheet.CreateRow(PaintIndex);
  3558. PaintIndex = PaintIndex + 1;
  3559. for (int j = 0; j < ShowColumnCount; j++)
  3560. {
  3561. row1.CreateCell(j);
  3562. if (j == 0)
  3563. {
  3564. row1.Cells[j].SetCellValue(小计);
  3565. row1.Cells[j].CellStyle = styleborder;
  3566. }
  3567. else if (j == ShowPieceIndex)
  3568. {
  3569. row1.Cells[ShowPieceIndex].SetCellValue(PageNum);
  3570. row1.Cells[j].CellStyle = styleborder;
  3571. }
  3572. else if (j == ShowCountIndex)
  3573. {
  3574. row1.Cells[j].SetCellValue(sumCount);
  3575. row1.Cells[j].CellStyle = styleborder;
  3576. }
  3577. else if (j == ShowBoxIndex - 4)
  3578. {
  3579. row1.Cells[j].SetCellValue(LastBox);
  3580. row1.Cells[j].CellStyle = styleborder;
  3581. }
  3582. else
  3583. {
  3584. row1.Cells[j].CellStyle = styleborder;
  3585. }
  3586. }
  3587. sumCount = 0;
  3588. row1 = sheet.CreateRow(PaintIndex);
  3589. sheet.SetRowBreak(PaintIndex - 1);
  3590. sheet.Footer.Center = "第&P页,共&N页";
  3591. PaintIndex = PaintIndex + 1;
  3592. PageNum = 0;
  3593. }
  3594. //每次到了页数开始分页
  3595. if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()) || (i == rowNum - 1 && (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())))
  3596. {
  3597. Console.WriteLine(DataTable.Rows[i]["ch_splitbatch"].ToString());
  3598. LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
  3599. //第一行添加客户信息
  3600. //if (i != rowNum - 1)
  3601. {
  3602. for (int j = 0; j < columnNum - 3; j++)
  3603. {
  3604. if (j == 0)
  3605. {
  3606. row1.CreateCell(j);
  3607. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  3608. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  3609. }
  3610. else if (j == ShowDataIndex)
  3611. {
  3612. row1.CreateCell(j);
  3613. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  3614. }
  3615. else
  3616. {
  3617. row1.CreateCell(j);
  3618. }
  3619. row1.GetCell(j).CellStyle = style;
  3620. }
  3621. row1 = sheet.CreateRow(PaintIndex);
  3622. PaintIndex = PaintIndex + 1;
  3623. //第二行添加型号
  3624. for (int j = 0; j < columnNum - 3; j++)
  3625. {
  3626. if (j == 0)
  3627. {
  3628. row1.CreateCell(j);
  3629. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + "_"
  3630. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  3631. }
  3632. else if (j == ShowSizeIndex)
  3633. {
  3634. row1.CreateCell(j);
  3635. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  3636. }
  3637. else if (j == ShowDataIndex)
  3638. {
  3639. row1.CreateCell(j);
  3640. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  3641. }
  3642. else
  3643. {
  3644. row1.CreateCell(j);
  3645. }
  3646. row1.GetCell(j).CellStyle = style;
  3647. }
  3648. //添加列名
  3649. row1 = sheet.CreateRow(PaintIndex);
  3650. PaintIndex = PaintIndex + 1;
  3651. int showcount = 0;
  3652. for (int j = 4; j < columnNum; j++)
  3653. {
  3654. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  3655. {
  3656. showcount = showcount + 1;
  3657. row1.CreateCell(j - 4);
  3658. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3659. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  3660. }
  3661. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  3662. {
  3663. showcount = showcount + 1;
  3664. row1.CreateCell(j - 4);
  3665. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3666. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  3667. }
  3668. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  3669. {
  3670. showcount = showcount + 1;
  3671. row1.CreateCell(j - 4);
  3672. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3673. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  3674. }
  3675. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  3676. {
  3677. showcount = showcount + 1;
  3678. row1.CreateCell(j - 4);
  3679. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3680. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  3681. }
  3682. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  3683. {
  3684. showcount = showcount + 1;
  3685. row1.CreateCell(j - 4);
  3686. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3687. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  3688. }
  3689. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3690. {
  3691. }
  3692. else
  3693. {
  3694. showcount = showcount + 1;
  3695. row1.CreateCell(j - 4);
  3696. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3697. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  3698. }
  3699. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  3700. {
  3701. ShowBoxIndex = j;
  3702. }
  3703. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  3704. {
  3705. NumIndex = j;
  3706. if (ShowCountIndex == NumIndex - 4)
  3707. {
  3708. ShowCountIndex = ShowCountIndex + 1;
  3709. }
  3710. }
  3711. }
  3712. ShowColumnCount = showcount;
  3713. row1 = sheet.CreateRow(PaintIndex);
  3714. PaintIndex = PaintIndex + 1;
  3715. }
  3716. }
  3717. //添加数据内容
  3718. for (int j = 4; j < columnNum; j++)
  3719. {
  3720. string Data = DataTable.Rows[i][j].ToString();
  3721. row1.CreateCell(j - 4);
  3722. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  3723. {
  3724. row1.CreateCell(j - 4, CellType.String);
  3725. }
  3726. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  3727. {
  3728. }
  3729. else
  3730. {
  3731. double Num = 0;
  3732. if (double.TryParse(Data, out Num) && DataTable.Columns[j].ColumnName.ToLower() != "ch_bluefilm")
  3733. {
  3734. row1.Cells[j - 4].SetCellValue(Num);
  3735. }
  3736. else
  3737. {
  3738. row1.Cells[j - 4].SetCellValue(Data);
  3739. }
  3740. row1.Cells[j - 4].CellStyle = styleborder;
  3741. }
  3742. if (DataTable.Columns[j].ColumnName == "io_qty")
  3743. {
  3744. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  3745. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  3746. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  3747. }
  3748. if (DataTable.Columns[j].ColumnName == "rownum")
  3749. {
  3750. row1.Cells[j - 4].SetCellValue(i + 1);
  3751. row1.Cells[j - 4].CellStyle = styleborder;
  3752. }
  3753. if (DataTable.Columns[j].ColumnName == "ch_code")
  3754. {
  3755. sheet.AutoSizeColumn(j - 4);
  3756. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  3757. }
  3758. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  3759. {
  3760. LastBox = Data;
  3761. }
  3762. }
  3763. if (i == rowNum - 1)
  3764. {
  3765. row1 = sheet.CreateRow(PaintIndex);
  3766. PaintIndex = PaintIndex + 1;
  3767. for (int j = 0; j < ShowColumnCount; j++)
  3768. {
  3769. row1.CreateCell(j);
  3770. if (j == 0)
  3771. {
  3772. row1.Cells[j].SetCellValue(批小计);
  3773. row1.Cells[j].CellStyle = styleborder;
  3774. }
  3775. else if (j == ShowPieceIndex)
  3776. {
  3777. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 1);
  3778. row1.Cells[j].CellStyle = styleborder;
  3779. }
  3780. else if (j == ShowCountIndex)
  3781. {
  3782. row1.Cells[j].SetCellValue(sumCount);
  3783. row1.Cells[j].CellStyle = styleborder;
  3784. }
  3785. else
  3786. {
  3787. row1.Cells[j].CellStyle = styleborder;
  3788. }
  3789. }
  3790. row1 = sheet.CreateRow(PaintIndex);
  3791. PaintIndex = PaintIndex + 1;
  3792. for (int j = 0; j < ShowColumnCount; j++)
  3793. {
  3794. row1.CreateCell(j);
  3795. if (j == 0)
  3796. {
  3797. row1.Cells[j].SetCellValue(小计);
  3798. row1.Cells[j].CellStyle = styleborder;
  3799. }
  3800. else if (j == ShowPieceIndex)
  3801. {
  3802. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 1);
  3803. row1.Cells[j].CellStyle = styleborder;
  3804. }
  3805. else if (j == ShowCountIndex)
  3806. {
  3807. row1.Cells[j].SetCellValue(sumCount);
  3808. row1.Cells[j].CellStyle = styleborder;
  3809. }
  3810. else
  3811. {
  3812. row1.Cells[j].CellStyle = styleborder;
  3813. }
  3814. }
  3815. //创建备注内容
  3816. row1 = sheet.CreateRow(PaintIndex);
  3817. for (int j = 0; j < columnNum - 3; j++)
  3818. {
  3819. if (j == 0)
  3820. {
  3821. row1.CreateCell(j);
  3822. row1.Cells[j].SetCellValue("备注");
  3823. }
  3824. else if (j == ShowCountIndex)
  3825. {
  3826. row1.CreateCell(j);
  3827. row1.Cells[j].SetCellValue(totalCount);
  3828. }
  3829. else if (j == ShowRemarkPiece)
  3830. {
  3831. row1.CreateCell(j);
  3832. row1.Cells[j].SetCellValue(rowNum + 片);
  3833. }
  3834. else
  3835. {
  3836. row1.CreateCell(j);
  3837. }
  3838. row1.Cells[j].CellStyle = style;
  3839. }
  3840. sheet.SetRowBreak(PaintIndex);
  3841. sheet.Footer.Center = "第&P页,共&N页";
  3842. PaintIndex = PaintIndex + 1;
  3843. PageNum = 0;
  3844. }
  3845. PageNum = PageNum + 1;
  3846. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  3847. pib_outboxcode1.Add(BoxCode.ToString());
  3848. }
  3849. break;
  3850. case "BoxCode":
  3851. string LastBoxCode = "";
  3852. int PageNum1 = 0;
  3853. for (int i = 0; i < rowNum; i++)
  3854. {
  3855. IRow row1 = sheet.CreateRow(PaintIndex);
  3856. PaintIndex = PaintIndex + 1;
  3857. row1.HeightInPoints = RowHeight;
  3858. //如果批号不相等的时候
  3859. if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
  3860. {
  3861. BoxCode = BoxCode + 1;
  3862. for (int j = 0; j < ShowColumnCount; j++)
  3863. {
  3864. row1.CreateCell(j);
  3865. if (j == 0)
  3866. {
  3867. row1.Cells[j].SetCellValue(批小计);
  3868. row1.Cells[j].CellStyle = styleborder;
  3869. }
  3870. else if (j == ShowPieceIndex)
  3871. {
  3872. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  3873. row1.Cells[j].CellStyle = styleborder;
  3874. }
  3875. else if (j == ShowCountIndex)
  3876. {
  3877. row1.Cells[j].SetCellValue(sumCount);
  3878. row1.Cells[j].CellStyle = styleborder;
  3879. }
  3880. else if (j == ShowBoxIndex - 4)
  3881. {
  3882. row1.Cells[j].SetCellValue(LastBox);
  3883. row1.Cells[j].CellStyle = styleborder;
  3884. }
  3885. else
  3886. {
  3887. row1.Cells[j].CellStyle = styleborder;
  3888. }
  3889. }
  3890. row1 = sheet.CreateRow(PaintIndex);
  3891. PaintIndex = PaintIndex + 1;
  3892. for (int j = 0; j < ShowColumnCount; j++)
  3893. {
  3894. row1.CreateCell(j);
  3895. if (j == 0)
  3896. {
  3897. row1.Cells[j].SetCellValue(小计);
  3898. row1.Cells[j].CellStyle = styleborder;
  3899. }
  3900. else if (j == ShowPieceIndex)
  3901. {
  3902. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  3903. row1.Cells[j].CellStyle = styleborder;
  3904. }
  3905. else if (j == ShowCountIndex)
  3906. {
  3907. row1.Cells[j].SetCellValue(sumCount);
  3908. row1.Cells[j].CellStyle = styleborder;
  3909. }
  3910. else if (j == ShowBoxIndex - 4)
  3911. {
  3912. row1.Cells[j].SetCellValue(LastBox);
  3913. row1.Cells[j].CellStyle = styleborder;
  3914. }
  3915. else
  3916. {
  3917. row1.Cells[j].CellStyle = styleborder;
  3918. }
  3919. }
  3920. sumCount = 0;
  3921. row1 = sheet.CreateRow(PaintIndex);
  3922. sheet.SetRowBreak(PaintIndex - 1);
  3923. sheet.Footer.Center = "第&P页,共&N页";
  3924. PaintIndex = PaintIndex + 1;
  3925. PageNum1 = 0;
  3926. }
  3927. //每次到了页数开始分页
  3928. if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString())))
  3929. {
  3930. LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
  3931. //第一行添加客户信息
  3932. //if (i != rowNum - 1)
  3933. {
  3934. for (int j = 0; j < columnNum - 3; j++)
  3935. {
  3936. if (j == 0)
  3937. {
  3938. row1.CreateCell(j);
  3939. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  3940. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  3941. }
  3942. else if (j == ShowDataIndex)
  3943. {
  3944. row1.CreateCell(j);
  3945. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  3946. }
  3947. else
  3948. {
  3949. row1.CreateCell(j);
  3950. }
  3951. row1.GetCell(j).CellStyle = style;
  3952. }
  3953. row1 = sheet.CreateRow(PaintIndex);
  3954. PaintIndex = PaintIndex + 1;
  3955. //第二行添加型号
  3956. for (int j = 0; j < columnNum - 3; j++)
  3957. {
  3958. if (j == 0)
  3959. {
  3960. row1.CreateCell(j);
  3961. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + "_"
  3962. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  3963. }
  3964. else if (j == ShowSizeIndex)
  3965. {
  3966. row1.CreateCell(j);
  3967. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  3968. }
  3969. else if (j == ShowDataIndex)
  3970. {
  3971. row1.CreateCell(j);
  3972. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  3973. }
  3974. else
  3975. {
  3976. row1.CreateCell(j);
  3977. }
  3978. }
  3979. //添加列名
  3980. row1 = sheet.CreateRow(PaintIndex);
  3981. PaintIndex = PaintIndex + 1;
  3982. int showcount = 0;
  3983. for (int j = 4; j < columnNum; j++)
  3984. {
  3985. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  3986. {
  3987. showcount = showcount + 1;
  3988. row1.CreateCell(j - 4);
  3989. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3990. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  3991. }
  3992. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  3993. {
  3994. showcount = showcount + 1;
  3995. row1.CreateCell(j - 4);
  3996. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  3997. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  3998. }
  3999. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  4000. {
  4001. showcount = showcount + 1;
  4002. row1.CreateCell(j - 4);
  4003. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  4004. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  4005. }
  4006. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  4007. {
  4008. showcount = showcount + 1;
  4009. row1.CreateCell(j - 4);
  4010. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  4011. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  4012. }
  4013. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  4014. {
  4015. showcount = showcount + 1;
  4016. row1.CreateCell(j - 4);
  4017. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  4018. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  4019. }
  4020. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  4021. {
  4022. }
  4023. else
  4024. {
  4025. showcount = showcount + 1;
  4026. row1.CreateCell(j - 4);
  4027. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  4028. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  4029. }
  4030. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  4031. {
  4032. ShowBoxIndex = j;
  4033. }
  4034. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  4035. {
  4036. NumIndex = j;
  4037. if (ShowCountIndex == NumIndex - 4)
  4038. {
  4039. ShowCountIndex = ShowCountIndex + 1;
  4040. }
  4041. }
  4042. }
  4043. ShowColumnCount = showcount;
  4044. row1 = sheet.CreateRow(PaintIndex);
  4045. PaintIndex = PaintIndex + 1;
  4046. }
  4047. }
  4048. //添加数据内容
  4049. for (int j = 4; j < columnNum; j++)
  4050. {
  4051. string Data = DataTable.Rows[i][j].ToString();
  4052. row1.CreateCell(j - 4);
  4053. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  4054. {
  4055. row1.CreateCell(j - 4, CellType.String);
  4056. }
  4057. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  4058. {
  4059. }
  4060. else
  4061. {
  4062. double Num = 0;
  4063. if (double.TryParse(Data, out Num) && DataTable.Columns[j].ColumnName.ToLower() != "ch_bluefilm")
  4064. {
  4065. row1.Cells[j - 4].SetCellValue(Num);
  4066. }
  4067. else
  4068. {
  4069. row1.Cells[j - 4].SetCellValue(Data);
  4070. }
  4071. row1.Cells[j - 4].CellStyle = styleborder;
  4072. }
  4073. if (DataTable.Columns[j].ColumnName == "io_qty")
  4074. {
  4075. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  4076. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  4077. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  4078. row1.Cells[j - 4].CellStyle = styleborder;
  4079. }
  4080. if (DataTable.Columns[j].ColumnName == "rownum")
  4081. {
  4082. row1.Cells[j - 4].SetCellValue(i + 1);
  4083. row1.Cells[j - 4].CellStyle = styleborder;
  4084. }
  4085. if (DataTable.Columns[j].ColumnName == "ch_code")
  4086. {
  4087. sheet.AutoSizeColumn(j - 4);
  4088. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  4089. }
  4090. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  4091. {
  4092. LastBox = Data;
  4093. }
  4094. }
  4095. if (i == rowNum - 1)
  4096. {
  4097. PageNum1 = PageNum1 + 1;
  4098. row1 = sheet.CreateRow(PaintIndex);
  4099. PaintIndex = PaintIndex + 1;
  4100. for (int j = 0; j < ShowColumnCount; j++)
  4101. {
  4102. row1.CreateCell(j);
  4103. if (j == 0)
  4104. {
  4105. row1.Cells[j].SetCellValue(批小计);
  4106. row1.Cells[j].CellStyle = styleborder;
  4107. }
  4108. else if (j == ShowPieceIndex)
  4109. {
  4110. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  4111. row1.Cells[j].CellStyle = styleborder;
  4112. }
  4113. else if (j == ShowCountIndex)
  4114. {
  4115. row1.Cells[j].SetCellValue(sumCount);
  4116. row1.Cells[j].CellStyle = styleborder;
  4117. }
  4118. else if (j == ShowBoxIndex - 4)
  4119. {
  4120. row1.Cells[j].SetCellValue(LastBox);
  4121. row1.Cells[j].CellStyle = styleborder;
  4122. }
  4123. else
  4124. {
  4125. row1.Cells[j].CellStyle = styleborder;
  4126. }
  4127. }
  4128. row1 = sheet.CreateRow(PaintIndex);
  4129. PaintIndex = PaintIndex + 1;
  4130. for (int j = 0; j < ShowColumnCount; j++)
  4131. {
  4132. row1.CreateCell(j);
  4133. if (j == 0)
  4134. {
  4135. row1.Cells[j].SetCellValue(小计);
  4136. row1.Cells[j].CellStyle = styleborder;
  4137. }
  4138. else if (j == ShowPieceIndex)
  4139. {
  4140. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  4141. row1.Cells[j].CellStyle = styleborder;
  4142. }
  4143. else if (j == ShowCountIndex)
  4144. {
  4145. row1.Cells[j].SetCellValue(sumCount);
  4146. row1.Cells[j].CellStyle = styleborder;
  4147. }
  4148. else if (j == ShowBoxIndex - 4)
  4149. {
  4150. row1.Cells[j].SetCellValue(LastBox);
  4151. row1.Cells[j].CellStyle = styleborder;
  4152. }
  4153. else
  4154. {
  4155. row1.Cells[j].CellStyle = styleborder;
  4156. }
  4157. }
  4158. row1 = sheet.CreateRow(PaintIndex);
  4159. for (int j = 0; j < columnNum - 3; j++)
  4160. {
  4161. if (j == 0)
  4162. {
  4163. row1.CreateCell(j);
  4164. row1.Cells[j].SetCellValue("备注");
  4165. }
  4166. else if (j == ShowCountIndex)
  4167. {
  4168. row1.CreateCell(j);
  4169. row1.Cells[j].SetCellValue(totalCount);
  4170. }
  4171. else if (j == ShowRemarkPiece)
  4172. {
  4173. row1.CreateCell(j);
  4174. row1.Cells[j].SetCellValue(rowNum + 片);
  4175. }
  4176. else
  4177. {
  4178. row1.CreateCell(j);
  4179. }
  4180. row1.Cells[j].CellStyle = style;
  4181. }
  4182. sheet.SetRowBreak(PaintIndex);
  4183. sheet.Footer.Center = "第&P页,共&N页";
  4184. PaintIndex = PaintIndex + 1;
  4185. PageNum1 = 0;
  4186. }
  4187. PageNum1 = PageNum1 + 1;
  4188. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  4189. pib_outboxcode1.Add(BoxCode.ToString());
  4190. }
  4191. break;
  4192. case "BoxSplit":
  4193. string LastBoxCode1 = "";
  4194. int PageNum2 = 0;
  4195. string LastBatch = "";
  4196. int MidCount = 0;
  4197. int SerialNum = 1;
  4198. for (int i = 0; i < rowNum; i++)
  4199. {
  4200. IRow row1 = sheet.CreateRow(PaintIndex);
  4201. PaintIndex = PaintIndex + 1;
  4202. row1.HeightInPoints = RowHeight;
  4203. //如果批号不相等的时候
  4204. if (LastBatch == "" || (LastBatch != "" && LastBatch != DataTable.Rows[i]["ch_splitbatch"].ToString()))
  4205. {
  4206. LastBatch = DataTable.Rows[i]["ch_splitbatch"].ToString();
  4207. for (int j = 0; j < ShowColumnCount; j++)
  4208. {
  4209. if (j == 0)
  4210. {
  4211. row1.CreateCell(j).SetCellValue(SerialNum - 1);
  4212. }
  4213. else if (j == 1)
  4214. {
  4215. row1.CreateCell(j).SetCellValue("批小计");
  4216. }
  4217. else if (j == 2)
  4218. {
  4219. row1.CreateCell(j).SetCellValue(MidCount);
  4220. }
  4221. else if (j == ShowBoxIndex - 4)
  4222. {
  4223. row1.CreateCell(j).SetCellValue(LastBox);
  4224. }
  4225. else
  4226. {
  4227. row1.CreateCell(j);
  4228. }
  4229. row1.Cells[j].CellStyle = styleborder;
  4230. }
  4231. SerialNum = 1;
  4232. MidCount = 0;
  4233. row1 = sheet.CreateRow(PaintIndex);
  4234. PaintIndex = PaintIndex + 1;
  4235. }
  4236. if (LastBoxCode1 != "" && LastBoxCode1 != DataTable.Rows[i]["CH_PBCODE"].ToString())
  4237. {
  4238. BoxCode = BoxCode + 1;
  4239. for (int j = 0; j < ShowColumnCount; j++)
  4240. {
  4241. row1.CreateCell(j);
  4242. if (j == 1)
  4243. {
  4244. row1.Cells[j].SetCellValue(小计);
  4245. row1.Cells[j].CellStyle = styleborder;
  4246. }
  4247. else if (j == 0)
  4248. {
  4249. row1.Cells[0].SetCellValue(PageNum2);
  4250. row1.Cells[j].CellStyle = styleborder;
  4251. }
  4252. else if (j == ShowCountIndex)
  4253. {
  4254. row1.Cells[j].SetCellValue(sumCount);
  4255. row1.Cells[j].CellStyle = styleborder;
  4256. }
  4257. else if (j == ShowBoxIndex - 4)
  4258. {
  4259. row1.Cells[j].SetCellValue(LastBox);
  4260. row1.Cells[j].CellStyle = styleborder;
  4261. }
  4262. else
  4263. {
  4264. row1.Cells[j].CellStyle = styleborder;
  4265. }
  4266. }
  4267. sumCount = 0;
  4268. row1 = sheet.CreateRow(PaintIndex);
  4269. sheet.SetRowBreak(PaintIndex - 1);
  4270. sheet.Footer.Center = "第&P页,共&N页";
  4271. PaintIndex = PaintIndex + 1;
  4272. PageNum2 = 0;
  4273. }
  4274. //每次到了页数开始分页
  4275. if (LastBoxCode1 == "" || (LastBoxCode1 != "" && LastBoxCode1 != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode1 != "" && LastBoxCode1 != DataTable.Rows[i]["ch_pbcode"].ToString())))
  4276. {
  4277. LastBoxCode1 = DataTable.Rows[i]["CH_PBCODE"].ToString();
  4278. //第一行添加客户信息
  4279. //if (i != rowNum - 1)
  4280. {
  4281. for (int j = 0; j < columnNum - 3; j++)
  4282. {
  4283. if (j == 0)
  4284. {
  4285. row1.CreateCell(j);
  4286. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  4287. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  4288. }
  4289. else if (j == ShowDataIndex)
  4290. {
  4291. row1.CreateCell(j);
  4292. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  4293. }
  4294. else
  4295. {
  4296. row1.CreateCell(j);
  4297. }
  4298. row1.GetCell(j).CellStyle = style;
  4299. }
  4300. row1 = sheet.CreateRow(PaintIndex);
  4301. PaintIndex = PaintIndex + 1;
  4302. //第二行添加型号
  4303. for (int j = 0; j < columnNum - 3; j++)
  4304. {
  4305. if (j == 0)
  4306. {
  4307. row1.CreateCell(j);
  4308. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + "_"
  4309. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  4310. }
  4311. else if (j == ShowSizeIndex)
  4312. {
  4313. row1.CreateCell(j);
  4314. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  4315. }
  4316. else if (j == ShowDataIndex)
  4317. {
  4318. row1.CreateCell(j);
  4319. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  4320. }
  4321. else
  4322. {
  4323. row1.CreateCell(j);
  4324. }
  4325. }
  4326. //添加列名
  4327. row1 = sheet.CreateRow(PaintIndex);
  4328. PaintIndex = PaintIndex + 1;
  4329. int showcount = 0;
  4330. for (int j = 4; j < columnNum; j++)
  4331. {
  4332. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  4333. {
  4334. showcount = showcount + 1;
  4335. row1.CreateCell(j - 4);
  4336. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  4337. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  4338. }
  4339. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  4340. {
  4341. showcount = showcount + 1;
  4342. row1.CreateCell(j - 4);
  4343. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  4344. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  4345. }
  4346. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  4347. {
  4348. showcount = showcount + 1;
  4349. row1.CreateCell(j - 4);
  4350. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  4351. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  4352. }
  4353. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  4354. {
  4355. showcount = showcount + 1;
  4356. row1.CreateCell(j - 4);
  4357. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  4358. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  4359. }
  4360. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  4361. {
  4362. showcount = showcount + 1;
  4363. row1.CreateCell(j - 4);
  4364. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  4365. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  4366. }
  4367. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  4368. {
  4369. }
  4370. else
  4371. {
  4372. showcount = showcount + 1;
  4373. row1.CreateCell(j - 4);
  4374. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  4375. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  4376. }
  4377. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  4378. {
  4379. ShowBoxIndex = j;
  4380. }
  4381. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  4382. {
  4383. NumIndex = j;
  4384. if (ShowCountIndex == NumIndex - 4)
  4385. {
  4386. ShowCountIndex = ShowCountIndex + 1;
  4387. }
  4388. }
  4389. }
  4390. ShowColumnCount = showcount;
  4391. row1 = sheet.CreateRow(PaintIndex);
  4392. PaintIndex = PaintIndex + 1;
  4393. }
  4394. }
  4395. //添加数据内容
  4396. for (int j = 4; j < columnNum; j++)
  4397. {
  4398. string Data = DataTable.Rows[i][j].ToString();
  4399. row1.CreateCell(j - 4);
  4400. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  4401. {
  4402. row1.CreateCell(j - 4, CellType.String);
  4403. }
  4404. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  4405. {
  4406. }
  4407. else
  4408. {
  4409. row1.Cells[j - 4].SetCellValue(Data);
  4410. row1.GetCell(j - 4).CellStyle = styleborder;
  4411. }
  4412. if (DataTable.Columns[j].ColumnName == "io_qty")
  4413. {
  4414. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  4415. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  4416. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  4417. MidCount += int.Parse(DataTable.Rows[i][j].ToString());
  4418. }
  4419. if (DataTable.Columns[j].ColumnName == "rownum")
  4420. {
  4421. row1.Cells[j - 4].SetCellValue(SerialNum);
  4422. }
  4423. if (DataTable.Columns[j].ColumnName == "ch_code")
  4424. {
  4425. sheet.AutoSizeColumn(j - 4);
  4426. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  4427. }
  4428. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  4429. {
  4430. LastBox = Data;
  4431. }
  4432. }
  4433. if (i == rowNum - 1)
  4434. {
  4435. PageNum2 = PageNum2 + 1;
  4436. row1 = sheet.CreateRow(PaintIndex);
  4437. PaintIndex = PaintIndex + 1;
  4438. for (int j = 0; j < ShowColumnCount; j++)
  4439. {
  4440. row1.CreateCell(j);
  4441. if (j == 0)
  4442. {
  4443. row1.Cells[j].SetCellValue(批小计);
  4444. row1.Cells[j].CellStyle = styleborder;
  4445. }
  4446. else if (j == ShowPieceIndex)
  4447. {
  4448. row1.Cells[ShowPieceIndex].SetCellValue(PageNum2);
  4449. row1.Cells[j].CellStyle = styleborder;
  4450. }
  4451. else if (j == ShowCountIndex)
  4452. {
  4453. row1.Cells[j].SetCellValue(sumCount);
  4454. row1.Cells[j].CellStyle = styleborder;
  4455. }
  4456. else if (j == ShowBoxIndex - 4)
  4457. {
  4458. row1.Cells[j].SetCellValue(LastBox);
  4459. row1.Cells[j].CellStyle = styleborder;
  4460. }
  4461. else
  4462. {
  4463. row1.Cells[j].CellStyle = styleborder;
  4464. }
  4465. }
  4466. row1 = sheet.CreateRow(PaintIndex);
  4467. PaintIndex = PaintIndex + 1;
  4468. for (int j = 0; j < ShowColumnCount; j++)
  4469. {
  4470. row1.CreateCell(j);
  4471. if (j == 0)
  4472. {
  4473. row1.Cells[j].SetCellValue(小计);
  4474. row1.Cells[j].CellStyle = styleborder;
  4475. }
  4476. else if (j == ShowPieceIndex)
  4477. {
  4478. row1.Cells[ShowPieceIndex].SetCellValue(PageNum2);
  4479. row1.Cells[j].CellStyle = styleborder;
  4480. }
  4481. else if (j == ShowCountIndex)
  4482. {
  4483. row1.Cells[j].SetCellValue(sumCount);
  4484. row1.Cells[j].CellStyle = styleborder;
  4485. }
  4486. else if (j == ShowBoxIndex - 4)
  4487. {
  4488. row1.Cells[j].SetCellValue(LastBox);
  4489. row1.Cells[j].CellStyle = styleborder;
  4490. }
  4491. else
  4492. {
  4493. row1.Cells[j].CellStyle = styleborder;
  4494. }
  4495. }
  4496. row1 = sheet.CreateRow(PaintIndex);
  4497. for (int j = 0; j < columnNum - 3; j++)
  4498. {
  4499. if (j == 0)
  4500. {
  4501. row1.CreateCell(j);
  4502. row1.Cells[j].SetCellValue("备注");
  4503. }
  4504. else if (j == ShowCountIndex)
  4505. {
  4506. row1.CreateCell(j);
  4507. row1.Cells[j].SetCellValue(totalCount);
  4508. }
  4509. else if (j == ShowRemarkPiece)
  4510. {
  4511. row1.CreateCell(j);
  4512. row1.Cells[j].SetCellValue(rowNum + 片);
  4513. }
  4514. else
  4515. {
  4516. row1.CreateCell(j);
  4517. }
  4518. row1.Cells[j].CellStyle = style;
  4519. }
  4520. sheet.SetRowBreak(PaintIndex);
  4521. sheet.Footer.Center = "第&P页,共&N页";
  4522. PaintIndex = PaintIndex + 1;
  4523. PageNum1 = 0;
  4524. }
  4525. PageNum2 = PageNum2 + 1;
  4526. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  4527. pib_outboxcode1.Add(BoxCode.ToString());
  4528. SerialNum = SerialNum + 1;
  4529. }
  4530. break;
  4531. default:
  4532. break;
  4533. }
  4534. dh.BatchInsert("update prodiobarcode set pib_outboxcode1=:pib_outboxcode1 where pib_inoutno='" + Inoutno + "' and pib_id=:pib_id", new string[] { "pib_outboxcode1", "pib_id" }, pib_outboxcode1.ToArray(), pib_id.ToArray());
  4535. //删除下载链接再重新插入
  4536. HttpHandler.GenDownLoadLinK(Inoutno);
  4537. //填充首页
  4538. sumCount = 0;
  4539. totalCount = 0;
  4540. PaintIndex = 1;
  4541. ISheet sheet2 = book.CreateSheet("首页");
  4542. row = sheet2.CreateRow(0);
  4543. row.CreateCell(0);
  4544. row.Cells[0].SetCellValue(" " + companyname);
  4545. row.GetCell(0).CellStyle = style;
  4546. rowNum = FirstDT.Rows.Count;
  4547. //不需要显示的列移除
  4548. for (int i = FirstDT.Columns.Count - 1; i > 0; i--)
  4549. {
  4550. for (int j = 0; j < box.Length; j++)
  4551. {
  4552. if (box[j].Name == "FirstPage_WID" && !box[j].Checked)
  4553. {
  4554. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  4555. {
  4556. FirstDT.Columns.RemoveAt(i);
  4557. }
  4558. }
  4559. if (box[j].Name == "FirstPage_YIELD" && !box[j].Checked)
  4560. {
  4561. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_yeild"))
  4562. {
  4563. FirstDT.Columns.RemoveAt(i);
  4564. }
  4565. }
  4566. if (box[j].Name == "FirstPage_REMARK" && !box[j].Checked)
  4567. {
  4568. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  4569. {
  4570. FirstDT.Columns.RemoveAt(i);
  4571. }
  4572. }
  4573. if (box[j].Name == "FirstPage_BOXCODE" && !box[j].Checked)
  4574. {
  4575. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  4576. {
  4577. FirstDT.Columns.RemoveAt(i);
  4578. }
  4579. }
  4580. }
  4581. }
  4582. columnNum = FirstDT.Columns.Count;
  4583. for (int i = 0; i < rowNum; i++)
  4584. {
  4585. IRow row1 = sheet2.CreateRow(PaintIndex);
  4586. PaintIndex = PaintIndex + 1;
  4587. row1.HeightInPoints = RowHeight;
  4588. //只需要绘制一行
  4589. if (i == 0)
  4590. {
  4591. for (int j = 0; j < columnNum - 3; j++)
  4592. {
  4593. if (j == 0)
  4594. {
  4595. row1.CreateCell(j);
  4596. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_title"].Caption + ":" + FirstDT.Rows[i]["pi_title"].ToString() + " "
  4597. + FirstDT.Columns["ch_level"].Caption + ":" + FirstDT.Rows[i]["ch_level"].ToString());
  4598. }
  4599. else if (j > 5 && j == columnNum - 5)
  4600. {
  4601. row1.CreateCell(j);
  4602. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  4603. }
  4604. else if (columnNum > 5 && j == columnNum - 5)
  4605. {
  4606. row1.CreateCell(j);
  4607. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  4608. }
  4609. else
  4610. {
  4611. row1.CreateCell(j);
  4612. }
  4613. row1.GetCell(j).CellStyle = style;
  4614. }
  4615. row1 = sheet2.CreateRow(PaintIndex);
  4616. PaintIndex = PaintIndex + 1;
  4617. //第二行添加型号
  4618. for (int j = 0; j < columnNum - 3; j++)
  4619. {
  4620. if (j == 0)
  4621. {
  4622. row1.CreateCell(j).SetCellValue(FirstDT.Columns["pr_orispeccode"].Caption + ":" + FirstDT.Rows[i]["pr_orispeccode"].ToString() + "_"
  4623. + "(" + FirstDT.Rows[i]["me_desc"].ToString() + ")" + FirstDT.Columns["pi_chipouttype"].Caption + ":" + FirstDT.Rows[i]["pi_chipouttype"].ToString());
  4624. }
  4625. else if (j == ShowSizeIndex)
  4626. {
  4627. row1.CreateCell(j);
  4628. row1.Cells[j].SetCellValue(FirstDT.Columns["pr_size"].Caption + ":" + FirstDT.Rows[i]["pr_size"].ToString());
  4629. }
  4630. else if (j > 5 && j == columnNum - 5)
  4631. {
  4632. row1.CreateCell(j);
  4633. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  4634. }
  4635. else if (columnNum > 5 && j == columnNum - 5)
  4636. {
  4637. row1.CreateCell(j);
  4638. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  4639. }
  4640. else
  4641. {
  4642. row1.CreateCell(j);
  4643. }
  4644. row1.GetCell(j).CellStyle = style;
  4645. }
  4646. row1 = sheet2.CreateRow(PaintIndex);
  4647. PaintIndex = PaintIndex + 1;
  4648. //添加列名
  4649. for (int j = 4; j < columnNum; j++)
  4650. {
  4651. row1.CreateCell(j - 4);
  4652. if (NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  4653. {
  4654. }
  4655. else
  4656. {
  4657. row1.Cells[j - 4].CellStyle = styleborder;
  4658. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  4659. }
  4660. }
  4661. row1 = sheet2.CreateRow(PaintIndex);
  4662. PaintIndex = PaintIndex + 1;
  4663. }
  4664. //添加数据内容
  4665. ShowColumnCount = 0;
  4666. for (int j = 4; j < columnNum; j++)
  4667. {
  4668. row1.CreateCell(j - 4);
  4669. if (FirstDT.Columns[j].ColumnName == "ch_bluefilm")
  4670. {
  4671. row1.CreateCell(j - 4, CellType.String);
  4672. }
  4673. if (!NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  4674. {
  4675. string Data = FirstDT.Rows[i][j].ToString();
  4676. row1.Cells[j - 4].SetCellValue(Data);
  4677. row1.GetCell(j - 4).CellStyle = styleborder;
  4678. if (FirstDT.Columns[j].ColumnName == "num")
  4679. {
  4680. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  4681. sumCount += int.Parse(Data);
  4682. }
  4683. if (FirstDT.Columns[j].ColumnName == "io_qty")
  4684. {
  4685. totalCount += int.Parse(Data);
  4686. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  4687. }
  4688. ShowColumnCount = ShowColumnCount + 1;
  4689. }
  4690. else
  4691. {
  4692. }
  4693. }
  4694. //添加总计行
  4695. if (i == rowNum - 1)
  4696. {
  4697. row1 = sheet2.CreateRow(PaintIndex);
  4698. PaintIndex = PaintIndex + 1;
  4699. for (int j = 0; j < ShowColumnCount; j++)
  4700. {
  4701. if (j == 0)
  4702. {
  4703. row1.CreateCell(j);
  4704. row1.Cells[j].CellStyle = styleborder;
  4705. row1.Cells[j].SetCellValue(总计);
  4706. }
  4707. else if (j == ShowColumnCount - 2)
  4708. {
  4709. row1.CreateCell(j);
  4710. row1.Cells[j].CellStyle = styleborder;
  4711. row1.Cells[j].SetCellValue(sumCount);
  4712. }
  4713. else if (j == ShowColumnCount - 1)
  4714. {
  4715. row1.CreateCell(j);
  4716. row1.Cells[j].CellStyle = styleborder;
  4717. row1.Cells[j].SetCellValue(totalCount);
  4718. }
  4719. else
  4720. {
  4721. row1.CreateCell(j);
  4722. row1.Cells[j].CellStyle = styleborder;
  4723. }
  4724. }
  4725. }
  4726. }
  4727. //将book的内容写入内存流中返回
  4728. book.Write(ms);
  4729. return ms;
  4730. }
  4731. private MemoryStream HETONGGUANGDIAN(DataTable FirstDT, DataTable DataTable, string Type, string Inoutno, int PageSize, List<CheckBox> conditionbox)
  4732. {
  4733. string 小计 = "";
  4734. string 总计 = "";
  4735. string 片 = "";
  4736. string companyname = "";
  4737. int ShowBoxIndex = 0;
  4738. //用于小计的盒号
  4739. string LastBox = "";
  4740. if (dh.getFieldDataByCondition("ProdInout", "pi_exporttype", "pi_inoutno='" + Inoutno + "'").ToString() == "Chinese")
  4741. {
  4742. 小计 = "小计";
  4743. 总计 = "总计";
  4744. 片 = "片";
  4745. companyname = "深爱半导体股份有限公司芯片出货清单";
  4746. }
  4747. else
  4748. {
  4749. 小计 = "total";
  4750. 总计 = "total";
  4751. companyname = "SHENZHEN SI SEMICONDUCTORS CO.,LTD";
  4752. }
  4753. //转换为序列
  4754. CheckBox[] box = conditionbox.ToArray();
  4755. //创建内存流
  4756. MemoryStream ms = new MemoryStream();
  4757. //创建一个Book,相当于一个Excel文件
  4758. HSSFWorkbook book = new HSSFWorkbook();
  4759. //Excel中的Sheet
  4760. ISheet sheet = book.CreateSheet("分页");
  4761. sheet.SetMargin(MarginType.TopMargin, 0.4);
  4762. sheet.SetMargin(MarginType.BottomMargin, 0.4);
  4763. sheet.SetMargin(MarginType.LeftMargin, 0.4);
  4764. sheet.SetMargin(MarginType.RightMargin, 0.4);
  4765. sheet.FitToPage = true;
  4766. sheet.PrintSetup.FitHeight = 200;
  4767. //芯片号需要作为更新盒号的条件
  4768. HSSFFont ffont = (HSSFFont)book.CreateFont();
  4769. ffont.FontName = "宋体";
  4770. //更新箱号
  4771. List<string> pib_id = new List<string>();
  4772. //系统打印箱号
  4773. List<string> pib_outboxcode1 = new List<string>();
  4774. int BoxCode = 1;
  4775. ICellStyle style = book.CreateCellStyle();
  4776. style.VerticalAlignment = VerticalAlignment.Center;
  4777. style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
  4778. style.SetFont(ffont);
  4779. ICellStyle styleborder = book.CreateCellStyle();
  4780. styleborder.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  4781. styleborder.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  4782. styleborder.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  4783. styleborder.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  4784. styleborder.VerticalAlignment = VerticalAlignment.Center;
  4785. styleborder.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
  4786. styleborder.SetFont(ffont);
  4787. string pi_inoutno = "";
  4788. HSSFFont ColumnTitle = (HSSFFont)book.CreateFont();
  4789. ColumnTitle.FontName = "宋体";
  4790. ColumnTitle.Boldweight = (short)FontBoldWeight.Bold;
  4791. ICellStyle ColumnTitleStyle = book.CreateCellStyle();
  4792. ColumnTitleStyle.SetFont(ColumnTitle);
  4793. ColumnTitleStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  4794. ColumnTitleStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  4795. ColumnTitleStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  4796. ColumnTitleStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  4797. ColumnTitleStyle.VerticalAlignment = VerticalAlignment.Center;
  4798. ColumnTitleStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
  4799. List<string> NotShowColumn = new List<string>();
  4800. NotShowColumn.Add("ch_level");
  4801. NotShowColumn.Add("pib_id");
  4802. NotShowColumn.Add("chw_itemname1");
  4803. NotShowColumn.Add("chw_itemname2");
  4804. NotShowColumn.Add("chw_itemname3");
  4805. NotShowColumn.Add("chw_itemname4");
  4806. NotShowColumn.Add("chw_itemname5");
  4807. NotShowColumn.Add("pd_ordercode");
  4808. NotShowColumn.Add("pr_size");
  4809. NotShowColumn.Add("me_desc");
  4810. NotShowColumn.Add("pr_orispeccode");
  4811. NotShowColumn.Add("pr_orispeccode1");
  4812. NotShowColumn.Add("pi_title");
  4813. NotShowColumn.Add("pi_chipouttype");
  4814. NotShowColumn.Add("pi_date");
  4815. int ShowColumnCount = 0;
  4816. //展示的内容列
  4817. //设置列的宽度,根据首行的列的内容的长度来设置
  4818. for (int i = DataTable.Columns.Count - 1; i > 0; i--)
  4819. {
  4820. for (int j = 0; j < box.Length; j++)
  4821. {
  4822. if (box[j].Name.ToLower() == "ch_bluefilm" && !box[j].Checked)
  4823. {
  4824. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_bluefilm"))
  4825. {
  4826. DataTable.Columns.RemoveAt(i);
  4827. break;
  4828. }
  4829. }
  4830. if (box[j].Name.ToLower() == "ch_code" && !box[j].Checked)
  4831. {
  4832. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_code"))
  4833. {
  4834. DataTable.Columns.RemoveAt(i);
  4835. break;
  4836. }
  4837. }
  4838. if (box[j].Name.ToLower() == "ch_splitbatch" && !box[j].Checked)
  4839. {
  4840. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_splitbatch"))
  4841. {
  4842. DataTable.Columns.RemoveAt(i);
  4843. break;
  4844. }
  4845. }
  4846. if (box[j].Name.ToLower() == "ch_waterid" && !box[j].Checked)
  4847. {
  4848. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  4849. {
  4850. DataTable.Columns.RemoveAt(i);
  4851. break;
  4852. }
  4853. }
  4854. if (box[j].Name.ToLower() == "ch_pbcode" && !box[j].Checked)
  4855. {
  4856. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  4857. {
  4858. DataTable.Columns.RemoveAt(i);
  4859. break;
  4860. }
  4861. }
  4862. if (box[j].Name.ToLower() == "ch_remark" && !box[j].Checked)
  4863. {
  4864. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  4865. {
  4866. DataTable.Columns.RemoveAt(i);
  4867. break;
  4868. }
  4869. }
  4870. if (box[j].Name.ToLower() == "ch_yield" && !box[j].Checked)
  4871. {
  4872. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_yield"))
  4873. {
  4874. DataTable.Columns.RemoveAt(i);
  4875. break;
  4876. }
  4877. }
  4878. }
  4879. }
  4880. //获取行数量和列数量
  4881. int rowNum = DataTable.Rows.Count;
  4882. int columnNum = DataTable.Columns.Count;
  4883. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  4884. IRow row = sheet.CreateRow(0);
  4885. //冻结第一行
  4886. sheet.CreateFreezePane(0, 1, 0, 1);
  4887. row.HeightInPoints = RowHeight;
  4888. //固定第一行
  4889. //row.RowStyle.IsLocked=true;
  4890. //给第一行的标签赋值样式和值
  4891. // ffont.FontHeight = 13;
  4892. row.CreateCell(0);
  4893. row.Cells[0].SetCellValue(" " + companyname);
  4894. row.GetCell(0).CellStyle.SetFont((ffont));
  4895. //ffont.FontHeight = 10;
  4896. //开始绘制的Index
  4897. int PaintIndex = 1;
  4898. int sumCount = 0;
  4899. int totalCount = 0;
  4900. ShowPieceIndex = 5;
  4901. switch (Type)
  4902. {
  4903. case "FixRow":
  4904. //清理系统取出来的数据
  4905. BaseUtil.CleanDataTableData(FirstDT);
  4906. //首页参数拼接
  4907. string First_OrderCode = "";
  4908. string First_Prspec = "";
  4909. string First_Batch = "";
  4910. int NumIndex = 0;
  4911. ArrayList<string> First_WID = new ArrayList<string>();
  4912. for (int i = 0; i < rowNum; i++)
  4913. {
  4914. IRow row1 = sheet.CreateRow(PaintIndex);
  4915. PaintIndex = PaintIndex + 1;
  4916. //不包含的订单号
  4917. if (DataTable.Columns.Contains("pd_ordercode") && !First_OrderCode.Contains(DataTable.Rows[i]["pd_ordercode"].ToString()))
  4918. {
  4919. First_OrderCode += DataTable.Rows[i]["pd_ordercode"].ToString() + " ";
  4920. }
  4921. //不包含的物料型号
  4922. if (DataTable.Columns.Contains("pr_orispeccode") && !First_Prspec.Contains(DataTable.Rows[i]["pr_orispeccode"].ToString()))
  4923. {
  4924. First_Prspec += DataTable.Rows[i]["pr_orispeccode"].ToString() + " ";
  4925. }
  4926. //不包含扩撒批号
  4927. if (DataTable.Columns.Contains("ch_splitbatch") && !First_Batch.Contains(DataTable.Rows[i]["ch_splitbatch"].ToString()))
  4928. {
  4929. First_Batch += DataTable.Rows[i]["ch_splitbatch"].ToString() + " ";
  4930. }
  4931. //不包含Wafer_id
  4932. if (DataTable.Columns.Contains("Wafer_ID") && !First_WID.Contains(DataTable.Rows[i]["Wafer_ID"].ToString()))
  4933. {
  4934. First_WID.Add(DataTable.Rows[i]["Wafer_ID"].ToString());
  4935. }
  4936. if (i / PageSize >= 1 && i % PageSize == 0)
  4937. {
  4938. DataRow dr = FirstDT.NewRow();
  4939. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  4940. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  4941. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  4942. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  4943. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  4944. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  4945. pi_inoutno = DataTable.Rows[i]["pi_inoutno"].ToString();
  4946. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  4947. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  4948. dr["pd_ordercode"] = First_OrderCode;
  4949. dr["pr_orispeccode"] = First_Prspec;
  4950. dr["ch_splitbatch"] = First_Batch;
  4951. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  4952. dr["num"] = PageSize;
  4953. dr["io_qty"] = sumCount;
  4954. FirstDT.Rows.Add(dr);
  4955. First_OrderCode = "";
  4956. First_Prspec = "";
  4957. First_Batch = "";
  4958. First_WID.Clear();
  4959. BoxCode = BoxCode + 1;
  4960. row1.HeightInPoints = RowHeight;
  4961. for (int j = 0; j < ShowColumnCount; j++)
  4962. {
  4963. row1.CreateCell(j);
  4964. if (j == 0)
  4965. {
  4966. row1.Cells[j].SetCellValue(小计);
  4967. }
  4968. else if (j == ShowPieceIndex)
  4969. {
  4970. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i));
  4971. }
  4972. else if (j == ShowCountIndex)
  4973. {
  4974. row1.Cells[j].SetCellValue(sumCount);
  4975. }
  4976. //else if (j == ShowBoxIndex - 4)
  4977. //{
  4978. // row1.Cells[j].SetCellValue(LastBox);
  4979. // row1.Cells[j].CellStyle = styleborder;
  4980. //}
  4981. row1.Cells[j].CellStyle = styleborder;
  4982. }
  4983. sumCount = 0;
  4984. row1 = sheet.CreateRow(PaintIndex);
  4985. sheet.SetRowBreak(PaintIndex - 1);
  4986. sheet.Footer.Center = "第&P页,共&N页";
  4987. PaintIndex = PaintIndex + 1;
  4988. }
  4989. //每次到了页数开始分页
  4990. if (i % PageSize == 0 || i == rowNum - 1)
  4991. {
  4992. //第一行添加客户信息 rownum只有一行的情
  4993. if (i != rowNum - 1 || rowNum == 1 || (rowNum - i == rowNum % PageSize))
  4994. {
  4995. for (int j = 0; j < columnNum - 3; j++)
  4996. {
  4997. if (j == 0)
  4998. {
  4999. row1.CreateCell(j);
  5000. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  5001. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  5002. }
  5003. else if (j == 4)
  5004. {
  5005. row1.CreateCell(j);
  5006. row1.Cells[j].SetCellValue("发货日期"+ ":" + DataTable.Rows[i]["pi_date"].ToString());
  5007. }
  5008. else if (j == ShowDataIndex)
  5009. {
  5010. row1.CreateCell(j);
  5011. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  5012. }
  5013. else
  5014. {
  5015. row1.CreateCell(j);
  5016. }
  5017. row1.GetCell(j).CellStyle = style;
  5018. }
  5019. row1 = sheet.CreateRow(PaintIndex);
  5020. PaintIndex = PaintIndex + 1;
  5021. //第二行添加型号
  5022. for (int j = 0; j < columnNum - 3; j++)
  5023. {
  5024. if (j == 0)
  5025. {
  5026. row1.CreateCell(j);
  5027. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString()
  5028. + "_(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  5029. }
  5030. else if (j == 4)
  5031. {
  5032. row1.CreateCell(j);
  5033. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  5034. }
  5035. else
  5036. {
  5037. row1.CreateCell(j);
  5038. }
  5039. row1.GetCell(j).CellStyle = style;
  5040. }
  5041. //添加列名
  5042. row1 = sheet.CreateRow(PaintIndex);
  5043. PaintIndex = PaintIndex + 1;
  5044. //计数列所在的索引
  5045. int showcount = 0;
  5046. for (int j = 4; j < columnNum; j++)
  5047. {
  5048. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  5049. {
  5050. showcount = showcount + 1;
  5051. row1.CreateCell(j - 4);
  5052. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5053. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  5054. }
  5055. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  5056. {
  5057. showcount = showcount + 1;
  5058. row1.CreateCell(j - 4);
  5059. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5060. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  5061. }
  5062. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  5063. {
  5064. showcount = showcount + 1;
  5065. row1.CreateCell(j - 4);
  5066. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5067. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  5068. }
  5069. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  5070. {
  5071. showcount = showcount + 1;
  5072. row1.CreateCell(j - 4);
  5073. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5074. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  5075. }
  5076. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  5077. {
  5078. showcount = showcount + 1;
  5079. row1.CreateCell(j - 4);
  5080. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5081. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  5082. }
  5083. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5084. {
  5085. }
  5086. else
  5087. {
  5088. showcount = showcount + 1;
  5089. row1.CreateCell(j - 4);
  5090. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5091. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  5092. }
  5093. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  5094. {
  5095. ShowBoxIndex = j;
  5096. }
  5097. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  5098. {
  5099. NumIndex = j;
  5100. if (ShowCountIndex == NumIndex - 4)
  5101. {
  5102. ShowCountIndex = ShowCountIndex + 1;
  5103. }
  5104. }
  5105. }
  5106. ShowColumnCount = showcount;
  5107. row1 = sheet.CreateRow(PaintIndex);
  5108. PaintIndex = PaintIndex + 1;
  5109. }
  5110. }
  5111. //添加数据内容
  5112. for (int j = 4; j < columnNum; j++)
  5113. {
  5114. string Data = DataTable.Rows[i][j].ToString();
  5115. row1.CreateCell(j - 4);
  5116. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  5117. {
  5118. row1.CreateCell(j - 4, CellType.String);
  5119. }
  5120. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5121. {
  5122. }
  5123. else
  5124. {
  5125. double Num = 0;
  5126. if (double.TryParse(Data, out Num) && DataTable.Columns[j].ColumnName.ToLower() != "ch_bluefilm")
  5127. {
  5128. row1.Cells[j - 4].SetCellValue(Num);
  5129. }
  5130. else
  5131. {
  5132. row1.Cells[j - 4].SetCellValue(Data);
  5133. }
  5134. row1.GetCell(j - 4).CellStyle = styleborder;
  5135. }
  5136. if (DataTable.Columns[j].ColumnName == "io_qty")
  5137. {
  5138. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  5139. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  5140. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  5141. row1.Cells[j - 4].CellStyle = styleborder;
  5142. }
  5143. if (DataTable.Columns[j].ColumnName == "rownum")
  5144. {
  5145. row1.Cells[j - 4].SetCellValue(i + 1);
  5146. row1.Cells[j - 4].CellStyle = styleborder;
  5147. }
  5148. if (DataTable.Columns[j].ColumnName == "ch_code")
  5149. {
  5150. sheet.AutoSizeColumn(j - 4);
  5151. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  5152. }
  5153. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  5154. {
  5155. LastBox = Data;
  5156. }
  5157. }
  5158. //固定行号分组的时候自动拼接新的DataTable
  5159. if (i == rowNum - 1)
  5160. {
  5161. DataRow dr = FirstDT.NewRow();
  5162. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  5163. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  5164. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  5165. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  5166. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  5167. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  5168. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  5169. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  5170. dr["pd_ordercode"] = First_OrderCode;
  5171. dr["pr_orispeccode"] = First_Prspec;
  5172. dr["ch_splitbatch"] = First_Batch;
  5173. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  5174. dr["num"] = (i % PageSize) + 1;
  5175. dr["io_qty"] = sumCount;
  5176. FirstDT.Rows.Add(dr);
  5177. row1 = sheet.CreateRow(PaintIndex);
  5178. PaintIndex = PaintIndex + 1;
  5179. for (int j = 0; j < ShowColumnCount; j++)
  5180. {
  5181. row1.CreateCell(j);
  5182. if (j == 0)
  5183. {
  5184. row1.Cells[j].SetCellValue(小计);
  5185. }
  5186. else if (j == ShowPieceIndex)
  5187. {
  5188. row1.Cells[ShowPieceIndex].SetCellValue(rowNum % PageSize);
  5189. row1.Cells[j].CellStyle = styleborder;
  5190. }
  5191. else if (j == ShowBoxIndex - 4)
  5192. {
  5193. row1.Cells[j].SetCellValue(LastBox);
  5194. row1.Cells[j].CellStyle = styleborder;
  5195. }
  5196. else if (j == ShowCountIndex)
  5197. {
  5198. row1.Cells[j].SetCellValue(sumCount);
  5199. }
  5200. row1.Cells[j].CellStyle = styleborder;
  5201. }
  5202. row1 = sheet.CreateRow(PaintIndex);
  5203. for (int j = 0; j < columnNum - 3; j++)
  5204. {
  5205. if (j == 0)
  5206. {
  5207. row1.CreateCell(j);
  5208. row1.Cells[j].SetCellValue("备注");
  5209. }
  5210. else if (j == ShowCountIndex)
  5211. {
  5212. row1.CreateCell(j);
  5213. row1.Cells[j].SetCellValue(totalCount);
  5214. }
  5215. else if (j == ShowRemarkPiece)
  5216. {
  5217. row1.CreateCell(j);
  5218. row1.Cells[j].SetCellValue(rowNum + 片);
  5219. }
  5220. else
  5221. {
  5222. row1.CreateCell(j);
  5223. }
  5224. row1.Cells[j].CellStyle = style;
  5225. }
  5226. sheet.SetRowBreak(PaintIndex);
  5227. sheet.Footer.Center = "第&P页,共&N页";
  5228. PaintIndex = PaintIndex + 1;
  5229. }
  5230. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  5231. pib_outboxcode1.Add(BoxCode.ToString());
  5232. }
  5233. break;
  5234. case "BatchCode":
  5235. string LastBatchCode = "";
  5236. int PageNum = 0;
  5237. for (int i = 0; i < rowNum; i++)
  5238. {
  5239. IRow row1 = sheet.CreateRow(PaintIndex);
  5240. PaintIndex = PaintIndex + 1;
  5241. row1.HeightInPoints = RowHeight;
  5242. //如果批号不相等的时候
  5243. if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
  5244. {
  5245. BoxCode = BoxCode + 1;
  5246. for (int j = 0; j < ShowColumnCount; j++)
  5247. {
  5248. row1.CreateCell(j);
  5249. if (j == 0)
  5250. {
  5251. row1.Cells[j].SetCellValue(小计);
  5252. row1.Cells[j].CellStyle = styleborder;
  5253. }
  5254. else if (j == ShowPieceIndex)
  5255. {
  5256. row1.Cells[ShowPieceIndex].SetCellValue(PageNum);
  5257. row1.Cells[j].CellStyle = styleborder;
  5258. }
  5259. else if (j == ShowCountIndex)
  5260. {
  5261. row1.Cells[j].SetCellValue(sumCount);
  5262. row1.Cells[j].CellStyle = styleborder;
  5263. }
  5264. else if (j == ShowBoxIndex - 4)
  5265. {
  5266. row1.Cells[j].SetCellValue(LastBox);
  5267. row1.Cells[j].CellStyle = styleborder;
  5268. }
  5269. else
  5270. {
  5271. row1.Cells[j].CellStyle = styleborder;
  5272. }
  5273. }
  5274. sumCount = 0;
  5275. row1 = sheet.CreateRow(PaintIndex);
  5276. sheet.SetRowBreak(PaintIndex - 1);
  5277. sheet.Footer.Center = "第&P页,共&N页";
  5278. PaintIndex = PaintIndex + 1;
  5279. PageNum = 0;
  5280. }
  5281. //每次到了页数开始分页
  5282. if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()) || (i == rowNum - 1 && (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())))
  5283. {
  5284. Console.WriteLine(DataTable.Rows[i]["ch_splitbatch"].ToString());
  5285. LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
  5286. //第一行添加客户信息
  5287. //if (i != rowNum - 1)
  5288. {
  5289. for (int j = 0; j < columnNum - 3; j++)
  5290. {
  5291. if (j == 0)
  5292. {
  5293. row1.CreateCell(j);
  5294. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  5295. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  5296. }
  5297. else if (j == 4)
  5298. {
  5299. row1.CreateCell(j);
  5300. row1.Cells[j].SetCellValue("发货日期" + ":" + DataTable.Rows[i]["pi_date"].ToString());
  5301. }
  5302. else if (j == ShowDataIndex)
  5303. {
  5304. row1.CreateCell(j);
  5305. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  5306. }
  5307. else
  5308. {
  5309. row1.CreateCell(j);
  5310. }
  5311. row1.GetCell(j).CellStyle = style;
  5312. }
  5313. row1 = sheet.CreateRow(PaintIndex);
  5314. PaintIndex = PaintIndex + 1;
  5315. //第二行添加型号
  5316. for (int j = 0; j < columnNum - 3; j++)
  5317. {
  5318. if (j == 0)
  5319. {
  5320. row1.CreateCell(j);
  5321. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString()
  5322. + "_(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  5323. }
  5324. else if (j == 4)
  5325. {
  5326. row1.CreateCell(j);
  5327. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  5328. }
  5329. else
  5330. {
  5331. row1.CreateCell(j);
  5332. }
  5333. row1.GetCell(j).CellStyle = style;
  5334. }
  5335. //添加列名
  5336. row1 = sheet.CreateRow(PaintIndex);
  5337. PaintIndex = PaintIndex + 1;
  5338. int showcount = 0;
  5339. for (int j = 4; j < columnNum; j++)
  5340. {
  5341. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  5342. {
  5343. showcount = showcount + 1;
  5344. row1.CreateCell(j - 4);
  5345. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5346. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  5347. }
  5348. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  5349. {
  5350. showcount = showcount + 1;
  5351. row1.CreateCell(j - 4);
  5352. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5353. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  5354. }
  5355. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  5356. {
  5357. showcount = showcount + 1;
  5358. row1.CreateCell(j - 4);
  5359. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5360. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  5361. }
  5362. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  5363. {
  5364. showcount = showcount + 1;
  5365. row1.CreateCell(j - 4);
  5366. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5367. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  5368. }
  5369. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  5370. {
  5371. showcount = showcount + 1;
  5372. row1.CreateCell(j - 4);
  5373. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5374. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  5375. }
  5376. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5377. {
  5378. }
  5379. else
  5380. {
  5381. showcount = showcount + 1;
  5382. row1.CreateCell(j - 4);
  5383. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5384. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  5385. }
  5386. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  5387. {
  5388. ShowBoxIndex = j;
  5389. }
  5390. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  5391. {
  5392. NumIndex = j;
  5393. if (ShowCountIndex == NumIndex - 4)
  5394. {
  5395. ShowCountIndex = ShowCountIndex + 1;
  5396. }
  5397. }
  5398. }
  5399. ShowColumnCount = showcount;
  5400. row1 = sheet.CreateRow(PaintIndex);
  5401. PaintIndex = PaintIndex + 1;
  5402. }
  5403. }
  5404. //添加数据内容
  5405. for (int j = 4; j < columnNum; j++)
  5406. {
  5407. string Data = DataTable.Rows[i][j].ToString();
  5408. row1.CreateCell(j - 4);
  5409. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  5410. {
  5411. row1.CreateCell(j - 4, CellType.String);
  5412. }
  5413. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5414. {
  5415. }
  5416. else
  5417. {
  5418. double Num = 0;
  5419. if (double.TryParse(Data, out Num) && DataTable.Columns[j].ColumnName.ToLower() != "ch_bluefilm")
  5420. {
  5421. row1.Cells[j - 4].SetCellValue(Num);
  5422. }
  5423. else
  5424. {
  5425. row1.Cells[j - 4].SetCellValue(Data);
  5426. }
  5427. row1.Cells[j - 4].CellStyle = styleborder;
  5428. }
  5429. if (DataTable.Columns[j].ColumnName == "io_qty")
  5430. {
  5431. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  5432. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  5433. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  5434. }
  5435. if (DataTable.Columns[j].ColumnName == "rownum")
  5436. {
  5437. row1.Cells[j - 4].SetCellValue(i + 1);
  5438. row1.Cells[j - 4].CellStyle = styleborder;
  5439. }
  5440. if (DataTable.Columns[j].ColumnName == "ch_code")
  5441. {
  5442. sheet.AutoSizeColumn(j - 4);
  5443. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  5444. }
  5445. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  5446. {
  5447. LastBox = Data;
  5448. }
  5449. }
  5450. if (i == rowNum - 1)
  5451. {
  5452. row1 = sheet.CreateRow(PaintIndex);
  5453. PaintIndex = PaintIndex + 1;
  5454. for (int j = 0; j < ShowColumnCount; j++)
  5455. {
  5456. row1.CreateCell(j);
  5457. if (j == 0)
  5458. {
  5459. row1.Cells[j].SetCellValue(小计);
  5460. row1.Cells[j].CellStyle = styleborder;
  5461. }
  5462. else if (j == ShowPieceIndex)
  5463. {
  5464. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 1);
  5465. row1.Cells[j].CellStyle = styleborder;
  5466. }
  5467. else if (j == ShowCountIndex)
  5468. {
  5469. row1.Cells[j].SetCellValue(sumCount);
  5470. row1.Cells[j].CellStyle = styleborder;
  5471. }
  5472. else
  5473. {
  5474. row1.Cells[j].CellStyle = styleborder;
  5475. }
  5476. }
  5477. //创建备注内容
  5478. row1 = sheet.CreateRow(PaintIndex);
  5479. for (int j = 0; j < columnNum - 3; j++)
  5480. {
  5481. if (j == 0)
  5482. {
  5483. row1.CreateCell(j);
  5484. row1.Cells[j].SetCellValue("备注");
  5485. }
  5486. else if (j == ShowCountIndex)
  5487. {
  5488. row1.CreateCell(j);
  5489. row1.Cells[j].SetCellValue(totalCount);
  5490. }
  5491. else if (j == ShowRemarkPiece)
  5492. {
  5493. row1.CreateCell(j);
  5494. row1.Cells[j].SetCellValue(rowNum + 片);
  5495. }
  5496. else
  5497. {
  5498. row1.CreateCell(j);
  5499. }
  5500. row1.Cells[j].CellStyle = style;
  5501. }
  5502. sheet.SetRowBreak(PaintIndex);
  5503. sheet.Footer.Center = "第&P页,共&N页";
  5504. PaintIndex = PaintIndex + 1;
  5505. PageNum = 0;
  5506. }
  5507. PageNum = PageNum + 1;
  5508. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  5509. pib_outboxcode1.Add(BoxCode.ToString());
  5510. }
  5511. break;
  5512. case "BoxCode":
  5513. string LastBoxCode = "";
  5514. int PageNum1 = 0;
  5515. for (int i = 0; i < rowNum; i++)
  5516. {
  5517. IRow row1 = sheet.CreateRow(PaintIndex);
  5518. PaintIndex = PaintIndex + 1;
  5519. row1.HeightInPoints = RowHeight;
  5520. //如果批号不相等的时候
  5521. if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
  5522. {
  5523. BoxCode = BoxCode + 1;
  5524. for (int j = 0; j < ShowColumnCount; j++)
  5525. {
  5526. row1.CreateCell(j);
  5527. if (j == 0)
  5528. {
  5529. row1.Cells[j].SetCellValue(小计);
  5530. row1.Cells[j].CellStyle = styleborder;
  5531. }
  5532. else if (j == ShowPieceIndex)
  5533. {
  5534. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  5535. row1.Cells[j].CellStyle = styleborder;
  5536. }
  5537. else if (j == ShowCountIndex)
  5538. {
  5539. row1.Cells[j].SetCellValue(sumCount);
  5540. row1.Cells[j].CellStyle = styleborder;
  5541. }
  5542. //else if (j == ShowBoxIndex - 4)
  5543. //{
  5544. // row1.Cells[j].SetCellValue(LastBox);
  5545. // row1.Cells[j].CellStyle = styleborder;
  5546. //}
  5547. else
  5548. {
  5549. row1.Cells[j].CellStyle = styleborder;
  5550. }
  5551. }
  5552. sumCount = 0;
  5553. row1 = sheet.CreateRow(PaintIndex);
  5554. sheet.SetRowBreak(PaintIndex - 1);
  5555. sheet.Footer.Center = "第&P页,共&N页";
  5556. PaintIndex = PaintIndex + 1;
  5557. PageNum1 = 0;
  5558. }
  5559. //每次到了页数开始分页
  5560. if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString())))
  5561. {
  5562. LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
  5563. //第一行添加客户信息
  5564. //if (i != rowNum - 1)
  5565. {
  5566. for (int j = 0; j < columnNum - 3; j++)
  5567. {
  5568. if (j == 0)
  5569. {
  5570. row1.CreateCell(j);
  5571. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  5572. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  5573. }
  5574. else if (j == 4)
  5575. {
  5576. row1.CreateCell(j);
  5577. row1.Cells[j].SetCellValue("发货日期" + ":" + DataTable.Rows[i]["pi_date"].ToString());
  5578. }
  5579. else if (j == ShowDataIndex)
  5580. {
  5581. row1.CreateCell(j);
  5582. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  5583. }
  5584. else
  5585. {
  5586. row1.CreateCell(j);
  5587. }
  5588. row1.GetCell(j).CellStyle = style;
  5589. }
  5590. row1 = sheet.CreateRow(PaintIndex);
  5591. PaintIndex = PaintIndex + 1;
  5592. //第二行添加型号
  5593. for (int j = 0; j < columnNum - 3; j++)
  5594. {
  5595. if (j == 0)
  5596. {
  5597. row1.CreateCell(j);
  5598. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString()
  5599. + "_(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  5600. }
  5601. else if (j == 4)
  5602. {
  5603. row1.CreateCell(j);
  5604. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  5605. }
  5606. else
  5607. {
  5608. row1.CreateCell(j);
  5609. }
  5610. row1.GetCell(j).CellStyle = style;
  5611. }
  5612. //添加列名
  5613. row1 = sheet.CreateRow(PaintIndex);
  5614. PaintIndex = PaintIndex + 1;
  5615. int showcount = 0;
  5616. for (int j = 4; j < columnNum; j++)
  5617. {
  5618. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  5619. {
  5620. showcount = showcount + 1;
  5621. row1.CreateCell(j - 4);
  5622. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5623. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  5624. }
  5625. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  5626. {
  5627. showcount = showcount + 1;
  5628. row1.CreateCell(j - 4);
  5629. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5630. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  5631. }
  5632. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  5633. {
  5634. showcount = showcount + 1;
  5635. row1.CreateCell(j - 4);
  5636. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5637. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  5638. }
  5639. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  5640. {
  5641. showcount = showcount + 1;
  5642. row1.CreateCell(j - 4);
  5643. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5644. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  5645. }
  5646. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  5647. {
  5648. showcount = showcount + 1;
  5649. row1.CreateCell(j - 4);
  5650. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5651. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  5652. }
  5653. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5654. {
  5655. }
  5656. else
  5657. {
  5658. showcount = showcount + 1;
  5659. row1.CreateCell(j - 4);
  5660. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5661. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  5662. }
  5663. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  5664. {
  5665. ShowBoxIndex = j;
  5666. }
  5667. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  5668. {
  5669. NumIndex = j;
  5670. if (ShowCountIndex == NumIndex - 4)
  5671. {
  5672. ShowCountIndex = ShowCountIndex + 1;
  5673. }
  5674. }
  5675. }
  5676. ShowColumnCount = showcount;
  5677. row1 = sheet.CreateRow(PaintIndex);
  5678. PaintIndex = PaintIndex + 1;
  5679. }
  5680. }
  5681. //添加数据内容
  5682. for (int j = 4; j < columnNum; j++)
  5683. {
  5684. string Data = DataTable.Rows[i][j].ToString();
  5685. row1.CreateCell(j - 4);
  5686. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  5687. {
  5688. row1.CreateCell(j - 4, CellType.String);
  5689. }
  5690. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5691. {
  5692. }
  5693. else
  5694. {
  5695. double Num = 0;
  5696. if (double.TryParse(Data, out Num) && DataTable.Columns[j].ColumnName.ToLower() != "ch_bluefilm")
  5697. {
  5698. row1.Cells[j - 4].SetCellValue(Num);
  5699. }
  5700. else
  5701. {
  5702. row1.Cells[j - 4].SetCellValue(Data);
  5703. }
  5704. row1.Cells[j - 4].CellStyle = styleborder;
  5705. }
  5706. if (DataTable.Columns[j].ColumnName == "io_qty")
  5707. {
  5708. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  5709. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  5710. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  5711. row1.Cells[j - 4].CellStyle = styleborder;
  5712. }
  5713. if (DataTable.Columns[j].ColumnName == "rownum")
  5714. {
  5715. row1.Cells[j - 4].SetCellValue(i + 1);
  5716. row1.Cells[j - 4].CellStyle = styleborder;
  5717. }
  5718. if (DataTable.Columns[j].ColumnName == "ch_code")
  5719. {
  5720. sheet.AutoSizeColumn(j - 4);
  5721. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  5722. }
  5723. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  5724. {
  5725. LastBox = Data;
  5726. }
  5727. }
  5728. if (i == rowNum - 1)
  5729. {
  5730. PageNum1 = PageNum1 + 1;
  5731. row1 = sheet.CreateRow(PaintIndex);
  5732. PaintIndex = PaintIndex + 1;
  5733. for (int j = 0; j < ShowColumnCount; j++)
  5734. {
  5735. row1.CreateCell(j);
  5736. if (j == 0)
  5737. {
  5738. row1.Cells[j].SetCellValue(小计);
  5739. row1.Cells[j].CellStyle = styleborder;
  5740. }
  5741. else if (j == ShowPieceIndex)
  5742. {
  5743. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  5744. row1.Cells[j].CellStyle = styleborder;
  5745. }
  5746. else if (j == ShowCountIndex)
  5747. {
  5748. row1.Cells[j].SetCellValue(sumCount);
  5749. row1.Cells[j].CellStyle = styleborder;
  5750. }
  5751. //else if (j == ShowBoxIndex - 4)
  5752. //{
  5753. // row1.Cells[j].SetCellValue(LastBox);
  5754. // row1.Cells[j].CellStyle = styleborder;
  5755. //}
  5756. else
  5757. {
  5758. row1.Cells[j].CellStyle = styleborder;
  5759. }
  5760. }
  5761. row1 = sheet.CreateRow(PaintIndex);
  5762. for (int j = 0; j < columnNum - 3; j++)
  5763. {
  5764. if (j == 0)
  5765. {
  5766. row1.CreateCell(j);
  5767. row1.Cells[j].SetCellValue("备注");
  5768. }
  5769. else if (j == ShowCountIndex)
  5770. {
  5771. row1.CreateCell(j);
  5772. row1.Cells[j].SetCellValue(totalCount);
  5773. }
  5774. else if (j == ShowRemarkPiece)
  5775. {
  5776. row1.CreateCell(j);
  5777. row1.Cells[j].SetCellValue(rowNum + 片);
  5778. }
  5779. else
  5780. {
  5781. row1.CreateCell(j);
  5782. }
  5783. row1.Cells[j].CellStyle = style;
  5784. }
  5785. sheet.SetRowBreak(PaintIndex);
  5786. sheet.Footer.Center = "第&P页,共&N页";
  5787. PaintIndex = PaintIndex + 1;
  5788. PageNum1 = 0;
  5789. }
  5790. PageNum1 = PageNum1 + 1;
  5791. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  5792. pib_outboxcode1.Add(BoxCode.ToString());
  5793. }
  5794. break;
  5795. case "BoxSplit":
  5796. string LastBoxCode1 = "";
  5797. int PageNum2 = 0;
  5798. string LastBatch = "";
  5799. int MidCount = 0;
  5800. int SerialNum = 1;
  5801. for (int i = 0; i < rowNum; i++)
  5802. {
  5803. IRow row1 = sheet.CreateRow(PaintIndex);
  5804. PaintIndex = PaintIndex + 1;
  5805. row1.HeightInPoints = RowHeight;
  5806. //如果批号不相等的时候
  5807. if (LastBatch == "" || (LastBatch != "" && LastBatch != DataTable.Rows[i]["ch_splitbatch"].ToString()))
  5808. {
  5809. LastBatch = DataTable.Rows[i]["ch_splitbatch"].ToString();
  5810. for (int j = 0; j < ShowColumnCount; j++)
  5811. {
  5812. if (j == 0)
  5813. {
  5814. row1.CreateCell(j).SetCellValue(SerialNum - 1);
  5815. }
  5816. else if (j == 1)
  5817. {
  5818. row1.CreateCell(j).SetCellValue("批小计");
  5819. }
  5820. else if (j == 2)
  5821. {
  5822. row1.CreateCell(j).SetCellValue(MidCount);
  5823. }
  5824. else if (j == ShowBoxIndex - 4)
  5825. {
  5826. row1.CreateCell(j).SetCellValue(LastBox);
  5827. }
  5828. else
  5829. {
  5830. row1.CreateCell(j);
  5831. }
  5832. row1.Cells[j].CellStyle = styleborder;
  5833. }
  5834. SerialNum = 1;
  5835. MidCount = 0;
  5836. row1 = sheet.CreateRow(PaintIndex);
  5837. PaintIndex = PaintIndex + 1;
  5838. }
  5839. if (LastBoxCode1 != "" && LastBoxCode1 != DataTable.Rows[i]["CH_PBCODE"].ToString())
  5840. {
  5841. BoxCode = BoxCode + 1;
  5842. for (int j = 0; j < ShowColumnCount; j++)
  5843. {
  5844. row1.CreateCell(j);
  5845. if (j == 1)
  5846. {
  5847. row1.Cells[j].SetCellValue(小计);
  5848. row1.Cells[j].CellStyle = styleborder;
  5849. }
  5850. else if (j == 0)
  5851. {
  5852. row1.Cells[0].SetCellValue(PageNum2);
  5853. row1.Cells[j].CellStyle = styleborder;
  5854. }
  5855. else if (j == ShowCountIndex)
  5856. {
  5857. row1.Cells[j].SetCellValue(sumCount);
  5858. row1.Cells[j].CellStyle = styleborder;
  5859. }
  5860. else if (j == ShowBoxIndex - 4)
  5861. {
  5862. row1.Cells[j].SetCellValue(LastBox);
  5863. row1.Cells[j].CellStyle = styleborder;
  5864. }
  5865. else
  5866. {
  5867. row1.Cells[j].CellStyle = styleborder;
  5868. }
  5869. }
  5870. sumCount = 0;
  5871. row1 = sheet.CreateRow(PaintIndex);
  5872. sheet.SetRowBreak(PaintIndex - 1);
  5873. sheet.Footer.Center = "第&P页,共&N页";
  5874. PaintIndex = PaintIndex + 1;
  5875. PageNum2 = 0;
  5876. }
  5877. //每次到了页数开始分页
  5878. if (LastBoxCode1 == "" || (LastBoxCode1 != "" && LastBoxCode1 != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode1 != "" && LastBoxCode1 != DataTable.Rows[i]["ch_pbcode"].ToString())))
  5879. {
  5880. LastBoxCode1 = DataTable.Rows[i]["CH_PBCODE"].ToString();
  5881. //第一行添加客户信息
  5882. //if (i != rowNum - 1)
  5883. {
  5884. for (int j = 0; j < columnNum - 3; j++)
  5885. {
  5886. if (j == 0)
  5887. {
  5888. row1.CreateCell(j);
  5889. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  5890. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  5891. }
  5892. else if (j == ShowDataIndex)
  5893. {
  5894. row1.CreateCell(j);
  5895. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  5896. }
  5897. else
  5898. {
  5899. row1.CreateCell(j);
  5900. }
  5901. row1.GetCell(j).CellStyle = style;
  5902. }
  5903. row1 = sheet.CreateRow(PaintIndex);
  5904. PaintIndex = PaintIndex + 1;
  5905. //第二行添加型号
  5906. for (int j = 0; j < columnNum - 3; j++)
  5907. {
  5908. if (j == 0)
  5909. {
  5910. row1.CreateCell(j);
  5911. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + "_"
  5912. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  5913. }
  5914. else if (j == ShowSizeIndex)
  5915. {
  5916. row1.CreateCell(j);
  5917. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  5918. }
  5919. else if (j == ShowDataIndex)
  5920. {
  5921. row1.CreateCell(j);
  5922. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  5923. }
  5924. else
  5925. {
  5926. row1.CreateCell(j);
  5927. }
  5928. }
  5929. //添加列名
  5930. row1 = sheet.CreateRow(PaintIndex);
  5931. PaintIndex = PaintIndex + 1;
  5932. int showcount = 0;
  5933. for (int j = 4; j < columnNum; j++)
  5934. {
  5935. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  5936. {
  5937. showcount = showcount + 1;
  5938. row1.CreateCell(j - 4);
  5939. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5940. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  5941. }
  5942. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  5943. {
  5944. showcount = showcount + 1;
  5945. row1.CreateCell(j - 4);
  5946. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5947. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  5948. }
  5949. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  5950. {
  5951. showcount = showcount + 1;
  5952. row1.CreateCell(j - 4);
  5953. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5954. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  5955. }
  5956. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  5957. {
  5958. showcount = showcount + 1;
  5959. row1.CreateCell(j - 4);
  5960. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5961. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  5962. }
  5963. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  5964. {
  5965. showcount = showcount + 1;
  5966. row1.CreateCell(j - 4);
  5967. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5968. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  5969. }
  5970. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5971. {
  5972. }
  5973. else
  5974. {
  5975. showcount = showcount + 1;
  5976. row1.CreateCell(j - 4);
  5977. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5978. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  5979. }
  5980. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  5981. {
  5982. ShowBoxIndex = j;
  5983. }
  5984. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  5985. {
  5986. NumIndex = j;
  5987. if (ShowCountIndex == NumIndex - 4)
  5988. {
  5989. ShowCountIndex = ShowCountIndex + 1;
  5990. }
  5991. }
  5992. }
  5993. ShowColumnCount = showcount;
  5994. row1 = sheet.CreateRow(PaintIndex);
  5995. PaintIndex = PaintIndex + 1;
  5996. }
  5997. }
  5998. //添加数据内容
  5999. for (int j = 4; j < columnNum; j++)
  6000. {
  6001. string Data = DataTable.Rows[i][j].ToString();
  6002. row1.CreateCell(j - 4);
  6003. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  6004. {
  6005. row1.CreateCell(j - 4, CellType.String);
  6006. }
  6007. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  6008. {
  6009. }
  6010. else
  6011. {
  6012. row1.Cells[j - 4].SetCellValue(Data);
  6013. row1.GetCell(j - 4).CellStyle = styleborder;
  6014. }
  6015. if (DataTable.Columns[j].ColumnName == "io_qty")
  6016. {
  6017. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  6018. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  6019. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  6020. MidCount += int.Parse(DataTable.Rows[i][j].ToString());
  6021. }
  6022. if (DataTable.Columns[j].ColumnName == "rownum")
  6023. {
  6024. row1.Cells[j - 4].SetCellValue(SerialNum);
  6025. }
  6026. if (DataTable.Columns[j].ColumnName == "ch_code")
  6027. {
  6028. sheet.AutoSizeColumn(j - 4);
  6029. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  6030. }
  6031. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  6032. {
  6033. LastBox = Data;
  6034. }
  6035. }
  6036. if (i == rowNum - 1)
  6037. {
  6038. PageNum2 = PageNum2 + 1;
  6039. row1 = sheet.CreateRow(PaintIndex);
  6040. PaintIndex = PaintIndex + 1;
  6041. for (int j = 0; j < ShowColumnCount; j++)
  6042. {
  6043. row1.CreateCell(j);
  6044. if (j == 0)
  6045. {
  6046. row1.Cells[j].SetCellValue(小计);
  6047. row1.Cells[j].CellStyle = styleborder;
  6048. }
  6049. else if (j == ShowPieceIndex)
  6050. {
  6051. row1.Cells[ShowPieceIndex].SetCellValue(PageNum2);
  6052. row1.Cells[j].CellStyle = styleborder;
  6053. }
  6054. else if (j == ShowCountIndex)
  6055. {
  6056. row1.Cells[j].SetCellValue(sumCount);
  6057. row1.Cells[j].CellStyle = styleborder;
  6058. }
  6059. else if (j == ShowBoxIndex - 4)
  6060. {
  6061. row1.Cells[j].SetCellValue(LastBox);
  6062. row1.Cells[j].CellStyle = styleborder;
  6063. }
  6064. else
  6065. {
  6066. row1.Cells[j].CellStyle = styleborder;
  6067. }
  6068. }
  6069. row1 = sheet.CreateRow(PaintIndex);
  6070. for (int j = 0; j < columnNum - 3; j++)
  6071. {
  6072. if (j == 0)
  6073. {
  6074. row1.CreateCell(j);
  6075. row1.Cells[j].SetCellValue("备注");
  6076. }
  6077. else if (j == ShowCountIndex)
  6078. {
  6079. row1.CreateCell(j);
  6080. row1.Cells[j].SetCellValue(totalCount);
  6081. }
  6082. else if (j == ShowRemarkPiece)
  6083. {
  6084. row1.CreateCell(j);
  6085. row1.Cells[j].SetCellValue(rowNum + 片);
  6086. }
  6087. else
  6088. {
  6089. row1.CreateCell(j);
  6090. }
  6091. row1.Cells[j].CellStyle = style;
  6092. }
  6093. sheet.SetRowBreak(PaintIndex);
  6094. sheet.Footer.Center = "第&P页,共&N页";
  6095. PaintIndex = PaintIndex + 1;
  6096. PageNum1 = 0;
  6097. }
  6098. PageNum2 = PageNum2 + 1;
  6099. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  6100. pib_outboxcode1.Add(BoxCode.ToString());
  6101. SerialNum = SerialNum + 1;
  6102. }
  6103. break;
  6104. default:
  6105. break;
  6106. }
  6107. dh.BatchInsert("update prodiobarcode set pib_outboxcode1=:pib_outboxcode1 where pib_inoutno='" + Inoutno + "' and pib_id=:pib_id", new string[] { "pib_outboxcode1", "pib_id" }, pib_outboxcode1.ToArray(), pib_id.ToArray());
  6108. //删除下载链接再重新插入
  6109. HttpHandler.GenDownLoadLinK(Inoutno);
  6110. //填充首页
  6111. sumCount = 0;
  6112. totalCount = 0;
  6113. PaintIndex = 1;
  6114. ISheet sheet2 = book.CreateSheet("首页");
  6115. row = sheet2.CreateRow(0);
  6116. row.CreateCell(0);
  6117. row.Cells[0].SetCellValue(" " + companyname);
  6118. row.GetCell(0).CellStyle = style;
  6119. rowNum = FirstDT.Rows.Count;
  6120. //不需要显示的列移除
  6121. for (int i = FirstDT.Columns.Count - 1; i > 0; i--)
  6122. {
  6123. for (int j = 0; j < box.Length; j++)
  6124. {
  6125. if (box[j].Name == "FirstPage_WID" && !box[j].Checked)
  6126. {
  6127. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  6128. {
  6129. FirstDT.Columns.RemoveAt(i);
  6130. }
  6131. }
  6132. if (box[j].Name == "FirstPage_YIELD" && !box[j].Checked)
  6133. {
  6134. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_yeild"))
  6135. {
  6136. FirstDT.Columns.RemoveAt(i);
  6137. }
  6138. }
  6139. if (box[j].Name == "FirstPage_REMARK" && !box[j].Checked)
  6140. {
  6141. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  6142. {
  6143. FirstDT.Columns.RemoveAt(i);
  6144. }
  6145. }
  6146. if (box[j].Name == "FirstPage_BOXCODE" && !box[j].Checked)
  6147. {
  6148. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  6149. {
  6150. FirstDT.Columns.RemoveAt(i);
  6151. }
  6152. }
  6153. }
  6154. }
  6155. columnNum = FirstDT.Columns.Count;
  6156. for (int i = 0; i < rowNum; i++)
  6157. {
  6158. IRow row1 = sheet2.CreateRow(PaintIndex);
  6159. PaintIndex = PaintIndex + 1;
  6160. row1.HeightInPoints = RowHeight;
  6161. //只需要绘制一行
  6162. if (i == 0)
  6163. {
  6164. for (int j = 0; j < columnNum - 3; j++)
  6165. {
  6166. if (j == 0)
  6167. {
  6168. row1.CreateCell(j);
  6169. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_title"].Caption + ":" + FirstDT.Rows[i]["pi_title"].ToString() + " "
  6170. + FirstDT.Columns["ch_level"].Caption + ":" + FirstDT.Rows[i]["ch_level"].ToString());
  6171. }
  6172. else if (j > 5 && j == columnNum - 5)
  6173. {
  6174. row1.CreateCell(j);
  6175. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  6176. }
  6177. else if (columnNum > 5 && j == columnNum - 5)
  6178. {
  6179. row1.CreateCell(j);
  6180. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  6181. }
  6182. else
  6183. {
  6184. row1.CreateCell(j);
  6185. }
  6186. row1.GetCell(j).CellStyle = style;
  6187. }
  6188. row1 = sheet2.CreateRow(PaintIndex);
  6189. PaintIndex = PaintIndex + 1;
  6190. //第二行添加型号
  6191. for (int j = 0; j < columnNum - 3; j++)
  6192. {
  6193. if (j == 0)
  6194. {
  6195. row1.CreateCell(j).SetCellValue(FirstDT.Columns["pr_orispeccode"].Caption + ":" + FirstDT.Rows[i]["pr_orispeccode"].ToString() + "_"
  6196. + "(" + FirstDT.Rows[i]["me_desc"].ToString() + ")" + FirstDT.Columns["pi_chipouttype"].Caption + ":" + FirstDT.Rows[i]["pi_chipouttype"].ToString());
  6197. }
  6198. else if (j == ShowSizeIndex)
  6199. {
  6200. row1.CreateCell(j);
  6201. row1.Cells[j].SetCellValue(FirstDT.Columns["pr_size"].Caption + ":" + FirstDT.Rows[i]["pr_size"].ToString());
  6202. }
  6203. else if (j > 5 && j == columnNum - 5)
  6204. {
  6205. row1.CreateCell(j);
  6206. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  6207. }
  6208. else if (columnNum > 5 && j == columnNum - 5)
  6209. {
  6210. row1.CreateCell(j);
  6211. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  6212. }
  6213. else
  6214. {
  6215. row1.CreateCell(j);
  6216. }
  6217. row1.GetCell(j).CellStyle = style;
  6218. }
  6219. row1 = sheet2.CreateRow(PaintIndex);
  6220. PaintIndex = PaintIndex + 1;
  6221. //添加列名
  6222. for (int j = 4; j < columnNum; j++)
  6223. {
  6224. row1.CreateCell(j - 4);
  6225. if (NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  6226. {
  6227. }
  6228. else
  6229. {
  6230. row1.Cells[j - 4].CellStyle = styleborder;
  6231. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  6232. }
  6233. }
  6234. row1 = sheet2.CreateRow(PaintIndex);
  6235. PaintIndex = PaintIndex + 1;
  6236. }
  6237. //添加数据内容
  6238. ShowColumnCount = 0;
  6239. for (int j = 4; j < columnNum; j++)
  6240. {
  6241. row1.CreateCell(j - 4);
  6242. if (FirstDT.Columns[j].ColumnName == "ch_bluefilm")
  6243. {
  6244. row1.CreateCell(j - 4, CellType.String);
  6245. }
  6246. if (!NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  6247. {
  6248. string Data = FirstDT.Rows[i][j].ToString();
  6249. row1.Cells[j - 4].SetCellValue(Data);
  6250. row1.GetCell(j - 4).CellStyle = styleborder;
  6251. if (FirstDT.Columns[j].ColumnName == "num")
  6252. {
  6253. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  6254. sumCount += int.Parse(Data);
  6255. }
  6256. if (FirstDT.Columns[j].ColumnName == "io_qty")
  6257. {
  6258. totalCount += int.Parse(Data);
  6259. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  6260. }
  6261. ShowColumnCount = ShowColumnCount + 1;
  6262. }
  6263. else
  6264. {
  6265. }
  6266. }
  6267. //添加总计行
  6268. if (i == rowNum - 1)
  6269. {
  6270. row1 = sheet2.CreateRow(PaintIndex);
  6271. PaintIndex = PaintIndex + 1;
  6272. for (int j = 0; j < ShowColumnCount; j++)
  6273. {
  6274. if (j == 0)
  6275. {
  6276. row1.CreateCell(j);
  6277. row1.Cells[j].CellStyle = styleborder;
  6278. row1.Cells[j].SetCellValue(总计);
  6279. }
  6280. else if (j == ShowColumnCount - 2)
  6281. {
  6282. row1.CreateCell(j);
  6283. row1.Cells[j].CellStyle = styleborder;
  6284. row1.Cells[j].SetCellValue(sumCount);
  6285. }
  6286. else if (j == ShowColumnCount - 1)
  6287. {
  6288. row1.CreateCell(j);
  6289. row1.Cells[j].CellStyle = styleborder;
  6290. row1.Cells[j].SetCellValue(totalCount);
  6291. }
  6292. else
  6293. {
  6294. row1.CreateCell(j);
  6295. row1.Cells[j].CellStyle = styleborder;
  6296. }
  6297. }
  6298. }
  6299. }
  6300. //将book的内容写入内存流中返回
  6301. book.Write(ms);
  6302. return ms;
  6303. }
  6304. }
  6305. }