ExcelHandler.cs 341 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407
  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.Left;
  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. switch (Type)
  4901. {
  4902. case "FixRow":
  4903. //清理系统取出来的数据
  4904. BaseUtil.CleanDataTableData(FirstDT);
  4905. //首页参数拼接
  4906. string First_OrderCode = "";
  4907. string First_Prspec = "";
  4908. string First_Batch = "";
  4909. int NumIndex = 0;
  4910. ArrayList<string> First_WID = new ArrayList<string>();
  4911. for (int i = 0; i < rowNum; i++)
  4912. {
  4913. IRow row1 = sheet.CreateRow(PaintIndex);
  4914. PaintIndex = PaintIndex + 1;
  4915. //不包含的订单号
  4916. if (DataTable.Columns.Contains("pd_ordercode") && !First_OrderCode.Contains(DataTable.Rows[i]["pd_ordercode"].ToString()))
  4917. {
  4918. First_OrderCode += DataTable.Rows[i]["pd_ordercode"].ToString() + " ";
  4919. }
  4920. //不包含的物料型号
  4921. if (DataTable.Columns.Contains("pr_orispeccode") && !First_Prspec.Contains(DataTable.Rows[i]["pr_orispeccode"].ToString()))
  4922. {
  4923. First_Prspec += DataTable.Rows[i]["pr_orispeccode"].ToString() + " ";
  4924. }
  4925. //不包含扩撒批号
  4926. if (DataTable.Columns.Contains("ch_splitbatch") && !First_Batch.Contains(DataTable.Rows[i]["ch_splitbatch"].ToString()))
  4927. {
  4928. First_Batch += DataTable.Rows[i]["ch_splitbatch"].ToString() + " ";
  4929. }
  4930. //不包含Wafer_id
  4931. if (DataTable.Columns.Contains("Wafer_ID") && !First_WID.Contains(DataTable.Rows[i]["Wafer_ID"].ToString()))
  4932. {
  4933. First_WID.Add(DataTable.Rows[i]["Wafer_ID"].ToString());
  4934. }
  4935. if (i / PageSize >= 1 && i % PageSize == 0)
  4936. {
  4937. DataRow dr = FirstDT.NewRow();
  4938. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  4939. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  4940. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  4941. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  4942. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  4943. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  4944. pi_inoutno = DataTable.Rows[i]["pi_inoutno"].ToString();
  4945. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  4946. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  4947. dr["pd_ordercode"] = First_OrderCode;
  4948. dr["pr_orispeccode"] = First_Prspec;
  4949. dr["ch_splitbatch"] = First_Batch;
  4950. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  4951. dr["num"] = PageSize;
  4952. dr["io_qty"] = sumCount;
  4953. FirstDT.Rows.Add(dr);
  4954. First_OrderCode = "";
  4955. First_Prspec = "";
  4956. First_Batch = "";
  4957. First_WID.Clear();
  4958. BoxCode = BoxCode + 1;
  4959. row1.HeightInPoints = RowHeight;
  4960. for (int j = 0; j < ShowColumnCount; j++)
  4961. {
  4962. row1.CreateCell(j);
  4963. if (j == 0)
  4964. {
  4965. row1.Cells[j].SetCellValue(小计);
  4966. }
  4967. else if (j == ShowPieceIndex)
  4968. {
  4969. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i));
  4970. }
  4971. else if (j == ShowCountIndex)
  4972. {
  4973. row1.Cells[j].SetCellValue(sumCount);
  4974. }
  4975. else if (j == ShowBoxIndex - 4)
  4976. {
  4977. row1.Cells[j].SetCellValue(LastBox);
  4978. row1.Cells[j].CellStyle = styleborder;
  4979. }
  4980. row1.Cells[j].CellStyle = styleborder;
  4981. }
  4982. sumCount = 0;
  4983. row1 = sheet.CreateRow(PaintIndex);
  4984. sheet.SetRowBreak(PaintIndex - 1);
  4985. sheet.Footer.Center = "第&P页,共&N页";
  4986. PaintIndex = PaintIndex + 1;
  4987. }
  4988. //每次到了页数开始分页
  4989. if (i % PageSize == 0 || i == rowNum - 1)
  4990. {
  4991. //第一行添加客户信息 rownum只有一行的情
  4992. if (i != rowNum - 1 || rowNum == 1 || (rowNum - i == rowNum % PageSize))
  4993. {
  4994. for (int j = 0; j < columnNum - 3; j++)
  4995. {
  4996. if (j == 0)
  4997. {
  4998. row1.CreateCell(j);
  4999. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  5000. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  5001. }
  5002. else if (j == 4)
  5003. {
  5004. row1.CreateCell(j);
  5005. row1.Cells[j].SetCellValue("出货日期"+ ":" + DataTable.Rows[i]["pi_date"].ToString());
  5006. }
  5007. else if (j == ShowDataIndex)
  5008. {
  5009. row1.CreateCell(j);
  5010. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  5011. }
  5012. else
  5013. {
  5014. row1.CreateCell(j);
  5015. }
  5016. row1.GetCell(j).CellStyle = style;
  5017. }
  5018. row1 = sheet.CreateRow(PaintIndex);
  5019. PaintIndex = PaintIndex + 1;
  5020. //第二行添加型号
  5021. for (int j = 0; j < columnNum - 3; j++)
  5022. {
  5023. if (j == 0)
  5024. {
  5025. row1.CreateCell(j);
  5026. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString()
  5027. + "_(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  5028. }
  5029. else if (j == 4)
  5030. {
  5031. row1.CreateCell(j);
  5032. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  5033. }
  5034. else
  5035. {
  5036. row1.CreateCell(j);
  5037. }
  5038. row1.GetCell(j).CellStyle = style;
  5039. }
  5040. //添加列名
  5041. row1 = sheet.CreateRow(PaintIndex);
  5042. PaintIndex = PaintIndex + 1;
  5043. //计数列所在的索引
  5044. int showcount = 0;
  5045. for (int j = 4; j < columnNum; j++)
  5046. {
  5047. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  5048. {
  5049. showcount = showcount + 1;
  5050. row1.CreateCell(j - 4);
  5051. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5052. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  5053. }
  5054. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  5055. {
  5056. showcount = showcount + 1;
  5057. row1.CreateCell(j - 4);
  5058. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5059. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  5060. }
  5061. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  5062. {
  5063. showcount = showcount + 1;
  5064. row1.CreateCell(j - 4);
  5065. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5066. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  5067. }
  5068. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  5069. {
  5070. showcount = showcount + 1;
  5071. row1.CreateCell(j - 4);
  5072. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5073. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  5074. }
  5075. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  5076. {
  5077. showcount = showcount + 1;
  5078. row1.CreateCell(j - 4);
  5079. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5080. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  5081. }
  5082. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5083. {
  5084. }
  5085. else
  5086. {
  5087. showcount = showcount + 1;
  5088. row1.CreateCell(j - 4);
  5089. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5090. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  5091. }
  5092. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  5093. {
  5094. ShowBoxIndex = j;
  5095. }
  5096. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  5097. {
  5098. NumIndex = j;
  5099. if (ShowCountIndex == NumIndex - 4)
  5100. {
  5101. ShowCountIndex = ShowCountIndex + 1;
  5102. }
  5103. }
  5104. }
  5105. ShowColumnCount = showcount;
  5106. row1 = sheet.CreateRow(PaintIndex);
  5107. PaintIndex = PaintIndex + 1;
  5108. }
  5109. }
  5110. //添加数据内容
  5111. for (int j = 4; j < columnNum; j++)
  5112. {
  5113. string Data = DataTable.Rows[i][j].ToString();
  5114. row1.CreateCell(j - 4);
  5115. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  5116. {
  5117. row1.CreateCell(j - 4, CellType.String);
  5118. }
  5119. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5120. {
  5121. }
  5122. else
  5123. {
  5124. double Num = 0;
  5125. if (double.TryParse(Data, out Num) && DataTable.Columns[j].ColumnName.ToLower() != "ch_bluefilm")
  5126. {
  5127. row1.Cells[j - 4].SetCellValue(Num);
  5128. }
  5129. else
  5130. {
  5131. row1.Cells[j - 4].SetCellValue(Data);
  5132. }
  5133. row1.GetCell(j - 4).CellStyle = styleborder;
  5134. }
  5135. if (DataTable.Columns[j].ColumnName == "io_qty")
  5136. {
  5137. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  5138. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  5139. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  5140. row1.Cells[j - 4].CellStyle = styleborder;
  5141. }
  5142. if (DataTable.Columns[j].ColumnName == "rownum")
  5143. {
  5144. row1.Cells[j - 4].SetCellValue(i + 1);
  5145. row1.Cells[j - 4].CellStyle = styleborder;
  5146. }
  5147. if (DataTable.Columns[j].ColumnName == "ch_code")
  5148. {
  5149. sheet.AutoSizeColumn(j - 4);
  5150. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  5151. }
  5152. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  5153. {
  5154. LastBox = Data;
  5155. }
  5156. }
  5157. //固定行号分组的时候自动拼接新的DataTable
  5158. if (i == rowNum - 1)
  5159. {
  5160. DataRow dr = FirstDT.NewRow();
  5161. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  5162. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  5163. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  5164. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  5165. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  5166. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  5167. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  5168. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  5169. dr["pd_ordercode"] = First_OrderCode;
  5170. dr["pr_orispeccode"] = First_Prspec;
  5171. dr["ch_splitbatch"] = First_Batch;
  5172. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  5173. dr["num"] = (i % PageSize) + 1;
  5174. dr["io_qty"] = sumCount;
  5175. FirstDT.Rows.Add(dr);
  5176. row1 = sheet.CreateRow(PaintIndex);
  5177. PaintIndex = PaintIndex + 1;
  5178. for (int j = 0; j < ShowColumnCount; j++)
  5179. {
  5180. row1.CreateCell(j);
  5181. if (j == 0)
  5182. {
  5183. row1.Cells[j].SetCellValue(小计);
  5184. }
  5185. else if (j == ShowPieceIndex)
  5186. {
  5187. row1.Cells[ShowPieceIndex].SetCellValue(rowNum % PageSize);
  5188. row1.Cells[j].CellStyle = styleborder;
  5189. }
  5190. else if (j == ShowBoxIndex - 4)
  5191. {
  5192. row1.Cells[j].SetCellValue(LastBox);
  5193. row1.Cells[j].CellStyle = styleborder;
  5194. }
  5195. else if (j == ShowCountIndex)
  5196. {
  5197. row1.Cells[j].SetCellValue(sumCount);
  5198. }
  5199. row1.Cells[j].CellStyle = styleborder;
  5200. }
  5201. row1 = sheet.CreateRow(PaintIndex);
  5202. for (int j = 0; j < columnNum - 3; j++)
  5203. {
  5204. if (j == 0)
  5205. {
  5206. row1.CreateCell(j);
  5207. row1.Cells[j].SetCellValue("备注");
  5208. }
  5209. else if (j == ShowCountIndex)
  5210. {
  5211. row1.CreateCell(j);
  5212. row1.Cells[j].SetCellValue(totalCount);
  5213. }
  5214. else if (j == ShowRemarkPiece)
  5215. {
  5216. row1.CreateCell(j);
  5217. row1.Cells[j].SetCellValue(rowNum + 片);
  5218. }
  5219. else
  5220. {
  5221. row1.CreateCell(j);
  5222. }
  5223. row1.Cells[j].CellStyle = style;
  5224. }
  5225. sheet.SetRowBreak(PaintIndex);
  5226. sheet.Footer.Center = "第&P页,共&N页";
  5227. PaintIndex = PaintIndex + 1;
  5228. }
  5229. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  5230. pib_outboxcode1.Add(BoxCode.ToString());
  5231. }
  5232. break;
  5233. case "BatchCode":
  5234. string LastBatchCode = "";
  5235. int PageNum = 0;
  5236. for (int i = 0; i < rowNum; i++)
  5237. {
  5238. IRow row1 = sheet.CreateRow(PaintIndex);
  5239. PaintIndex = PaintIndex + 1;
  5240. row1.HeightInPoints = RowHeight;
  5241. //如果批号不相等的时候
  5242. if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
  5243. {
  5244. BoxCode = BoxCode + 1;
  5245. for (int j = 0; j < ShowColumnCount; j++)
  5246. {
  5247. row1.CreateCell(j);
  5248. if (j == 0)
  5249. {
  5250. row1.Cells[j].SetCellValue(小计);
  5251. row1.Cells[j].CellStyle = styleborder;
  5252. }
  5253. else if (j == ShowPieceIndex)
  5254. {
  5255. row1.Cells[ShowPieceIndex].SetCellValue(PageNum);
  5256. row1.Cells[j].CellStyle = styleborder;
  5257. }
  5258. else if (j == ShowCountIndex)
  5259. {
  5260. row1.Cells[j].SetCellValue(sumCount);
  5261. row1.Cells[j].CellStyle = styleborder;
  5262. }
  5263. else if (j == ShowBoxIndex - 4)
  5264. {
  5265. row1.Cells[j].SetCellValue(LastBox);
  5266. row1.Cells[j].CellStyle = styleborder;
  5267. }
  5268. else
  5269. {
  5270. row1.Cells[j].CellStyle = styleborder;
  5271. }
  5272. }
  5273. sumCount = 0;
  5274. row1 = sheet.CreateRow(PaintIndex);
  5275. sheet.SetRowBreak(PaintIndex - 1);
  5276. sheet.Footer.Center = "第&P页,共&N页";
  5277. PaintIndex = PaintIndex + 1;
  5278. PageNum = 0;
  5279. }
  5280. //每次到了页数开始分页
  5281. if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()) || (i == rowNum - 1 && (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())))
  5282. {
  5283. Console.WriteLine(DataTable.Rows[i]["ch_splitbatch"].ToString());
  5284. LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
  5285. //第一行添加客户信息
  5286. //if (i != rowNum - 1)
  5287. {
  5288. for (int j = 0; j < columnNum - 3; j++)
  5289. {
  5290. if (j == 0)
  5291. {
  5292. row1.CreateCell(j);
  5293. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  5294. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  5295. }
  5296. else if (j == 4)
  5297. {
  5298. row1.CreateCell(j);
  5299. row1.Cells[j].SetCellValue("出货日期" + ":" + DataTable.Rows[i]["pi_date"].ToString());
  5300. }
  5301. else if (j == ShowDataIndex)
  5302. {
  5303. row1.CreateCell(j);
  5304. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  5305. }
  5306. else
  5307. {
  5308. row1.CreateCell(j);
  5309. }
  5310. row1.GetCell(j).CellStyle = style;
  5311. }
  5312. row1 = sheet.CreateRow(PaintIndex);
  5313. PaintIndex = PaintIndex + 1;
  5314. //第二行添加型号
  5315. for (int j = 0; j < columnNum - 3; j++)
  5316. {
  5317. if (j == 0)
  5318. {
  5319. row1.CreateCell(j);
  5320. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString()
  5321. + "_(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  5322. }
  5323. else if (j == 4)
  5324. {
  5325. row1.CreateCell(j);
  5326. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  5327. }
  5328. else
  5329. {
  5330. row1.CreateCell(j);
  5331. }
  5332. row1.GetCell(j).CellStyle = style;
  5333. }
  5334. //添加列名
  5335. row1 = sheet.CreateRow(PaintIndex);
  5336. PaintIndex = PaintIndex + 1;
  5337. int showcount = 0;
  5338. for (int j = 4; j < columnNum; j++)
  5339. {
  5340. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  5341. {
  5342. showcount = showcount + 1;
  5343. row1.CreateCell(j - 4);
  5344. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5345. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  5346. }
  5347. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  5348. {
  5349. showcount = showcount + 1;
  5350. row1.CreateCell(j - 4);
  5351. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5352. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  5353. }
  5354. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  5355. {
  5356. showcount = showcount + 1;
  5357. row1.CreateCell(j - 4);
  5358. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5359. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  5360. }
  5361. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  5362. {
  5363. showcount = showcount + 1;
  5364. row1.CreateCell(j - 4);
  5365. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5366. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  5367. }
  5368. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  5369. {
  5370. showcount = showcount + 1;
  5371. row1.CreateCell(j - 4);
  5372. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5373. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  5374. }
  5375. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5376. {
  5377. }
  5378. else
  5379. {
  5380. showcount = showcount + 1;
  5381. row1.CreateCell(j - 4);
  5382. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5383. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  5384. }
  5385. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  5386. {
  5387. ShowBoxIndex = j;
  5388. }
  5389. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  5390. {
  5391. NumIndex = j;
  5392. if (ShowCountIndex == NumIndex - 4)
  5393. {
  5394. ShowCountIndex = ShowCountIndex + 1;
  5395. }
  5396. }
  5397. }
  5398. ShowColumnCount = showcount;
  5399. row1 = sheet.CreateRow(PaintIndex);
  5400. PaintIndex = PaintIndex + 1;
  5401. }
  5402. }
  5403. //添加数据内容
  5404. for (int j = 4; j < columnNum; j++)
  5405. {
  5406. string Data = DataTable.Rows[i][j].ToString();
  5407. row1.CreateCell(j - 4);
  5408. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  5409. {
  5410. row1.CreateCell(j - 4, CellType.String);
  5411. }
  5412. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5413. {
  5414. }
  5415. else
  5416. {
  5417. double Num = 0;
  5418. if (double.TryParse(Data, out Num) && DataTable.Columns[j].ColumnName.ToLower() != "ch_bluefilm")
  5419. {
  5420. row1.Cells[j - 4].SetCellValue(Num);
  5421. }
  5422. else
  5423. {
  5424. row1.Cells[j - 4].SetCellValue(Data);
  5425. }
  5426. row1.Cells[j - 4].CellStyle = styleborder;
  5427. }
  5428. if (DataTable.Columns[j].ColumnName == "io_qty")
  5429. {
  5430. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  5431. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  5432. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  5433. }
  5434. if (DataTable.Columns[j].ColumnName == "rownum")
  5435. {
  5436. row1.Cells[j - 4].SetCellValue(i + 1);
  5437. row1.Cells[j - 4].CellStyle = styleborder;
  5438. }
  5439. if (DataTable.Columns[j].ColumnName == "ch_code")
  5440. {
  5441. sheet.AutoSizeColumn(j - 4);
  5442. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  5443. }
  5444. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  5445. {
  5446. LastBox = Data;
  5447. }
  5448. }
  5449. if (i == rowNum - 1)
  5450. {
  5451. row1 = sheet.CreateRow(PaintIndex);
  5452. PaintIndex = PaintIndex + 1;
  5453. for (int j = 0; j < ShowColumnCount; j++)
  5454. {
  5455. row1.CreateCell(j);
  5456. if (j == 0)
  5457. {
  5458. row1.Cells[j].SetCellValue(小计);
  5459. row1.Cells[j].CellStyle = styleborder;
  5460. }
  5461. else if (j == ShowPieceIndex)
  5462. {
  5463. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 1);
  5464. row1.Cells[j].CellStyle = styleborder;
  5465. }
  5466. else if (j == ShowCountIndex)
  5467. {
  5468. row1.Cells[j].SetCellValue(sumCount);
  5469. row1.Cells[j].CellStyle = styleborder;
  5470. }
  5471. else
  5472. {
  5473. row1.Cells[j].CellStyle = styleborder;
  5474. }
  5475. }
  5476. //创建备注内容
  5477. row1 = sheet.CreateRow(PaintIndex);
  5478. for (int j = 0; j < columnNum - 3; j++)
  5479. {
  5480. if (j == 0)
  5481. {
  5482. row1.CreateCell(j);
  5483. row1.Cells[j].SetCellValue("备注");
  5484. }
  5485. else if (j == ShowCountIndex)
  5486. {
  5487. row1.CreateCell(j);
  5488. row1.Cells[j].SetCellValue(totalCount);
  5489. }
  5490. else if (j == ShowRemarkPiece)
  5491. {
  5492. row1.CreateCell(j);
  5493. row1.Cells[j].SetCellValue(rowNum + 片);
  5494. }
  5495. else
  5496. {
  5497. row1.CreateCell(j);
  5498. }
  5499. row1.Cells[j].CellStyle = style;
  5500. }
  5501. sheet.SetRowBreak(PaintIndex);
  5502. sheet.Footer.Center = "第&P页,共&N页";
  5503. PaintIndex = PaintIndex + 1;
  5504. PageNum = 0;
  5505. }
  5506. PageNum = PageNum + 1;
  5507. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  5508. pib_outboxcode1.Add(BoxCode.ToString());
  5509. }
  5510. break;
  5511. case "BoxCode":
  5512. string LastBoxCode = "";
  5513. int PageNum1 = 0;
  5514. for (int i = 0; i < rowNum; i++)
  5515. {
  5516. IRow row1 = sheet.CreateRow(PaintIndex);
  5517. PaintIndex = PaintIndex + 1;
  5518. row1.HeightInPoints = RowHeight;
  5519. //如果批号不相等的时候
  5520. if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
  5521. {
  5522. BoxCode = BoxCode + 1;
  5523. for (int j = 0; j < ShowColumnCount; j++)
  5524. {
  5525. row1.CreateCell(j);
  5526. if (j == 0)
  5527. {
  5528. row1.Cells[j].SetCellValue(小计);
  5529. row1.Cells[j].CellStyle = styleborder;
  5530. }
  5531. else if (j == ShowPieceIndex)
  5532. {
  5533. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  5534. row1.Cells[j].CellStyle = styleborder;
  5535. }
  5536. else if (j == ShowCountIndex)
  5537. {
  5538. row1.Cells[j].SetCellValue(sumCount);
  5539. row1.Cells[j].CellStyle = styleborder;
  5540. }
  5541. else if (j == ShowBoxIndex - 4)
  5542. {
  5543. row1.Cells[j].SetCellValue(LastBox);
  5544. row1.Cells[j].CellStyle = styleborder;
  5545. }
  5546. else
  5547. {
  5548. row1.Cells[j].CellStyle = styleborder;
  5549. }
  5550. }
  5551. sumCount = 0;
  5552. row1 = sheet.CreateRow(PaintIndex);
  5553. sheet.SetRowBreak(PaintIndex - 1);
  5554. sheet.Footer.Center = "第&P页,共&N页";
  5555. PaintIndex = PaintIndex + 1;
  5556. PageNum1 = 0;
  5557. }
  5558. //每次到了页数开始分页
  5559. if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString())))
  5560. {
  5561. LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
  5562. //第一行添加客户信息
  5563. //if (i != rowNum - 1)
  5564. {
  5565. for (int j = 0; j < columnNum - 3; j++)
  5566. {
  5567. if (j == 0)
  5568. {
  5569. row1.CreateCell(j);
  5570. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  5571. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  5572. }
  5573. else if (j == 4)
  5574. {
  5575. row1.CreateCell(j);
  5576. row1.Cells[j].SetCellValue("出货日期" + ":" + DataTable.Rows[i]["pi_date"].ToString());
  5577. }
  5578. else if (j == ShowDataIndex)
  5579. {
  5580. row1.CreateCell(j);
  5581. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  5582. }
  5583. else
  5584. {
  5585. row1.CreateCell(j);
  5586. }
  5587. row1.GetCell(j).CellStyle = style;
  5588. }
  5589. row1 = sheet.CreateRow(PaintIndex);
  5590. PaintIndex = PaintIndex + 1;
  5591. //第二行添加型号
  5592. for (int j = 0; j < columnNum - 3; j++)
  5593. {
  5594. if (j == 0)
  5595. {
  5596. row1.CreateCell(j);
  5597. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString()
  5598. + "_(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  5599. }
  5600. else if (j == 4)
  5601. {
  5602. row1.CreateCell(j);
  5603. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  5604. }
  5605. else
  5606. {
  5607. row1.CreateCell(j);
  5608. }
  5609. row1.GetCell(j).CellStyle = style;
  5610. }
  5611. //添加列名
  5612. row1 = sheet.CreateRow(PaintIndex);
  5613. PaintIndex = PaintIndex + 1;
  5614. int showcount = 0;
  5615. for (int j = 4; j < columnNum; j++)
  5616. {
  5617. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  5618. {
  5619. showcount = showcount + 1;
  5620. row1.CreateCell(j - 4);
  5621. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5622. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  5623. }
  5624. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  5625. {
  5626. showcount = showcount + 1;
  5627. row1.CreateCell(j - 4);
  5628. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5629. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  5630. }
  5631. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  5632. {
  5633. showcount = showcount + 1;
  5634. row1.CreateCell(j - 4);
  5635. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5636. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  5637. }
  5638. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  5639. {
  5640. showcount = showcount + 1;
  5641. row1.CreateCell(j - 4);
  5642. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5643. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  5644. }
  5645. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  5646. {
  5647. showcount = showcount + 1;
  5648. row1.CreateCell(j - 4);
  5649. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5650. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  5651. }
  5652. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5653. {
  5654. }
  5655. else
  5656. {
  5657. showcount = showcount + 1;
  5658. row1.CreateCell(j - 4);
  5659. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5660. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  5661. }
  5662. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  5663. {
  5664. ShowBoxIndex = j;
  5665. }
  5666. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  5667. {
  5668. NumIndex = j;
  5669. if (ShowCountIndex == NumIndex - 4)
  5670. {
  5671. ShowCountIndex = ShowCountIndex + 1;
  5672. }
  5673. }
  5674. }
  5675. ShowColumnCount = showcount;
  5676. row1 = sheet.CreateRow(PaintIndex);
  5677. PaintIndex = PaintIndex + 1;
  5678. }
  5679. }
  5680. //添加数据内容
  5681. for (int j = 4; j < columnNum; j++)
  5682. {
  5683. string Data = DataTable.Rows[i][j].ToString();
  5684. row1.CreateCell(j - 4);
  5685. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  5686. {
  5687. row1.CreateCell(j - 4, CellType.String);
  5688. }
  5689. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5690. {
  5691. }
  5692. else
  5693. {
  5694. double Num = 0;
  5695. if (double.TryParse(Data, out Num) && DataTable.Columns[j].ColumnName.ToLower() != "ch_bluefilm")
  5696. {
  5697. row1.Cells[j - 4].SetCellValue(Num);
  5698. }
  5699. else
  5700. {
  5701. row1.Cells[j - 4].SetCellValue(Data);
  5702. }
  5703. row1.Cells[j - 4].CellStyle = styleborder;
  5704. }
  5705. if (DataTable.Columns[j].ColumnName == "io_qty")
  5706. {
  5707. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  5708. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  5709. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  5710. row1.Cells[j - 4].CellStyle = styleborder;
  5711. }
  5712. if (DataTable.Columns[j].ColumnName == "rownum")
  5713. {
  5714. row1.Cells[j - 4].SetCellValue(i + 1);
  5715. row1.Cells[j - 4].CellStyle = styleborder;
  5716. }
  5717. if (DataTable.Columns[j].ColumnName == "ch_code")
  5718. {
  5719. sheet.AutoSizeColumn(j - 4);
  5720. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  5721. }
  5722. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  5723. {
  5724. LastBox = Data;
  5725. }
  5726. }
  5727. if (i == rowNum - 1)
  5728. {
  5729. PageNum1 = PageNum1 + 1;
  5730. row1 = sheet.CreateRow(PaintIndex);
  5731. PaintIndex = PaintIndex + 1;
  5732. for (int j = 0; j < ShowColumnCount; j++)
  5733. {
  5734. row1.CreateCell(j);
  5735. if (j == 0)
  5736. {
  5737. row1.Cells[j].SetCellValue(小计);
  5738. row1.Cells[j].CellStyle = styleborder;
  5739. }
  5740. else if (j == ShowPieceIndex)
  5741. {
  5742. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  5743. row1.Cells[j].CellStyle = styleborder;
  5744. }
  5745. else if (j == ShowCountIndex)
  5746. {
  5747. row1.Cells[j].SetCellValue(sumCount);
  5748. row1.Cells[j].CellStyle = styleborder;
  5749. }
  5750. else if (j == ShowBoxIndex - 4)
  5751. {
  5752. row1.Cells[j].SetCellValue(LastBox);
  5753. row1.Cells[j].CellStyle = styleborder;
  5754. }
  5755. else
  5756. {
  5757. row1.Cells[j].CellStyle = styleborder;
  5758. }
  5759. }
  5760. row1 = sheet.CreateRow(PaintIndex);
  5761. for (int j = 0; j < columnNum - 3; j++)
  5762. {
  5763. if (j == 0)
  5764. {
  5765. row1.CreateCell(j);
  5766. row1.Cells[j].SetCellValue("备注");
  5767. }
  5768. else if (j == ShowCountIndex)
  5769. {
  5770. row1.CreateCell(j);
  5771. row1.Cells[j].SetCellValue(totalCount);
  5772. }
  5773. else if (j == ShowRemarkPiece)
  5774. {
  5775. row1.CreateCell(j);
  5776. row1.Cells[j].SetCellValue(rowNum + 片);
  5777. }
  5778. else
  5779. {
  5780. row1.CreateCell(j);
  5781. }
  5782. row1.Cells[j].CellStyle = style;
  5783. }
  5784. sheet.SetRowBreak(PaintIndex);
  5785. sheet.Footer.Center = "第&P页,共&N页";
  5786. PaintIndex = PaintIndex + 1;
  5787. PageNum1 = 0;
  5788. }
  5789. PageNum1 = PageNum1 + 1;
  5790. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  5791. pib_outboxcode1.Add(BoxCode.ToString());
  5792. }
  5793. break;
  5794. case "BoxSplit":
  5795. string LastBoxCode1 = "";
  5796. int PageNum2 = 0;
  5797. string LastBatch = "";
  5798. int MidCount = 0;
  5799. int SerialNum = 1;
  5800. for (int i = 0; i < rowNum; i++)
  5801. {
  5802. IRow row1 = sheet.CreateRow(PaintIndex);
  5803. PaintIndex = PaintIndex + 1;
  5804. row1.HeightInPoints = RowHeight;
  5805. //如果批号不相等的时候
  5806. if (LastBatch == "" || (LastBatch != "" && LastBatch != DataTable.Rows[i]["ch_splitbatch"].ToString()))
  5807. {
  5808. LastBatch = DataTable.Rows[i]["ch_splitbatch"].ToString();
  5809. for (int j = 0; j < ShowColumnCount; j++)
  5810. {
  5811. if (j == 0)
  5812. {
  5813. row1.CreateCell(j).SetCellValue(SerialNum - 1);
  5814. }
  5815. else if (j == 1)
  5816. {
  5817. row1.CreateCell(j).SetCellValue("批小计");
  5818. }
  5819. else if (j == 2)
  5820. {
  5821. row1.CreateCell(j).SetCellValue(MidCount);
  5822. }
  5823. else if (j == ShowBoxIndex - 4)
  5824. {
  5825. row1.CreateCell(j).SetCellValue(LastBox);
  5826. }
  5827. else
  5828. {
  5829. row1.CreateCell(j);
  5830. }
  5831. row1.Cells[j].CellStyle = styleborder;
  5832. }
  5833. SerialNum = 1;
  5834. MidCount = 0;
  5835. row1 = sheet.CreateRow(PaintIndex);
  5836. PaintIndex = PaintIndex + 1;
  5837. }
  5838. if (LastBoxCode1 != "" && LastBoxCode1 != DataTable.Rows[i]["CH_PBCODE"].ToString())
  5839. {
  5840. BoxCode = BoxCode + 1;
  5841. for (int j = 0; j < ShowColumnCount; j++)
  5842. {
  5843. row1.CreateCell(j);
  5844. if (j == 1)
  5845. {
  5846. row1.Cells[j].SetCellValue(小计);
  5847. row1.Cells[j].CellStyle = styleborder;
  5848. }
  5849. else if (j == 0)
  5850. {
  5851. row1.Cells[0].SetCellValue(PageNum2);
  5852. row1.Cells[j].CellStyle = styleborder;
  5853. }
  5854. else if (j == ShowCountIndex)
  5855. {
  5856. row1.Cells[j].SetCellValue(sumCount);
  5857. row1.Cells[j].CellStyle = styleborder;
  5858. }
  5859. else if (j == ShowBoxIndex - 4)
  5860. {
  5861. row1.Cells[j].SetCellValue(LastBox);
  5862. row1.Cells[j].CellStyle = styleborder;
  5863. }
  5864. else
  5865. {
  5866. row1.Cells[j].CellStyle = styleborder;
  5867. }
  5868. }
  5869. sumCount = 0;
  5870. row1 = sheet.CreateRow(PaintIndex);
  5871. sheet.SetRowBreak(PaintIndex - 1);
  5872. sheet.Footer.Center = "第&P页,共&N页";
  5873. PaintIndex = PaintIndex + 1;
  5874. PageNum2 = 0;
  5875. }
  5876. //每次到了页数开始分页
  5877. if (LastBoxCode1 == "" || (LastBoxCode1 != "" && LastBoxCode1 != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode1 != "" && LastBoxCode1 != DataTable.Rows[i]["ch_pbcode"].ToString())))
  5878. {
  5879. LastBoxCode1 = DataTable.Rows[i]["CH_PBCODE"].ToString();
  5880. //第一行添加客户信息
  5881. //if (i != rowNum - 1)
  5882. {
  5883. for (int j = 0; j < columnNum - 3; j++)
  5884. {
  5885. if (j == 0)
  5886. {
  5887. row1.CreateCell(j);
  5888. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  5889. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  5890. }
  5891. else if (j == ShowDataIndex)
  5892. {
  5893. row1.CreateCell(j);
  5894. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  5895. }
  5896. else
  5897. {
  5898. row1.CreateCell(j);
  5899. }
  5900. row1.GetCell(j).CellStyle = style;
  5901. }
  5902. row1 = sheet.CreateRow(PaintIndex);
  5903. PaintIndex = PaintIndex + 1;
  5904. //第二行添加型号
  5905. for (int j = 0; j < columnNum - 3; j++)
  5906. {
  5907. if (j == 0)
  5908. {
  5909. row1.CreateCell(j);
  5910. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + "_"
  5911. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  5912. }
  5913. else if (j == ShowSizeIndex)
  5914. {
  5915. row1.CreateCell(j);
  5916. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  5917. }
  5918. else if (j == ShowDataIndex)
  5919. {
  5920. row1.CreateCell(j);
  5921. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  5922. }
  5923. else
  5924. {
  5925. row1.CreateCell(j);
  5926. }
  5927. }
  5928. //添加列名
  5929. row1 = sheet.CreateRow(PaintIndex);
  5930. PaintIndex = PaintIndex + 1;
  5931. int showcount = 0;
  5932. for (int j = 4; j < columnNum; j++)
  5933. {
  5934. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  5935. {
  5936. showcount = showcount + 1;
  5937. row1.CreateCell(j - 4);
  5938. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5939. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  5940. }
  5941. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  5942. {
  5943. showcount = showcount + 1;
  5944. row1.CreateCell(j - 4);
  5945. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5946. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  5947. }
  5948. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  5949. {
  5950. showcount = showcount + 1;
  5951. row1.CreateCell(j - 4);
  5952. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5953. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  5954. }
  5955. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  5956. {
  5957. showcount = showcount + 1;
  5958. row1.CreateCell(j - 4);
  5959. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5960. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  5961. }
  5962. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  5963. {
  5964. showcount = showcount + 1;
  5965. row1.CreateCell(j - 4);
  5966. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5967. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  5968. }
  5969. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5970. {
  5971. }
  5972. else
  5973. {
  5974. showcount = showcount + 1;
  5975. row1.CreateCell(j - 4);
  5976. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5977. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  5978. }
  5979. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  5980. {
  5981. ShowBoxIndex = j;
  5982. }
  5983. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  5984. {
  5985. NumIndex = j;
  5986. if (ShowCountIndex == NumIndex - 4)
  5987. {
  5988. ShowCountIndex = ShowCountIndex + 1;
  5989. }
  5990. }
  5991. }
  5992. ShowColumnCount = showcount;
  5993. row1 = sheet.CreateRow(PaintIndex);
  5994. PaintIndex = PaintIndex + 1;
  5995. }
  5996. }
  5997. //添加数据内容
  5998. for (int j = 4; j < columnNum; j++)
  5999. {
  6000. string Data = DataTable.Rows[i][j].ToString();
  6001. row1.CreateCell(j - 4);
  6002. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  6003. {
  6004. row1.CreateCell(j - 4, CellType.String);
  6005. }
  6006. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  6007. {
  6008. }
  6009. else
  6010. {
  6011. row1.Cells[j - 4].SetCellValue(Data);
  6012. row1.GetCell(j - 4).CellStyle = styleborder;
  6013. }
  6014. if (DataTable.Columns[j].ColumnName == "io_qty")
  6015. {
  6016. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  6017. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  6018. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  6019. MidCount += int.Parse(DataTable.Rows[i][j].ToString());
  6020. }
  6021. if (DataTable.Columns[j].ColumnName == "rownum")
  6022. {
  6023. row1.Cells[j - 4].SetCellValue(SerialNum);
  6024. }
  6025. if (DataTable.Columns[j].ColumnName == "ch_code")
  6026. {
  6027. sheet.AutoSizeColumn(j - 4);
  6028. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  6029. }
  6030. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  6031. {
  6032. LastBox = Data;
  6033. }
  6034. }
  6035. if (i == rowNum - 1)
  6036. {
  6037. PageNum2 = PageNum2 + 1;
  6038. row1 = sheet.CreateRow(PaintIndex);
  6039. PaintIndex = PaintIndex + 1;
  6040. for (int j = 0; j < ShowColumnCount; j++)
  6041. {
  6042. row1.CreateCell(j);
  6043. if (j == 0)
  6044. {
  6045. row1.Cells[j].SetCellValue(小计);
  6046. row1.Cells[j].CellStyle = styleborder;
  6047. }
  6048. else if (j == ShowPieceIndex)
  6049. {
  6050. row1.Cells[ShowPieceIndex].SetCellValue(PageNum2);
  6051. row1.Cells[j].CellStyle = styleborder;
  6052. }
  6053. else if (j == ShowCountIndex)
  6054. {
  6055. row1.Cells[j].SetCellValue(sumCount);
  6056. row1.Cells[j].CellStyle = styleborder;
  6057. }
  6058. else if (j == ShowBoxIndex - 4)
  6059. {
  6060. row1.Cells[j].SetCellValue(LastBox);
  6061. row1.Cells[j].CellStyle = styleborder;
  6062. }
  6063. else
  6064. {
  6065. row1.Cells[j].CellStyle = styleborder;
  6066. }
  6067. }
  6068. row1 = sheet.CreateRow(PaintIndex);
  6069. for (int j = 0; j < columnNum - 3; j++)
  6070. {
  6071. if (j == 0)
  6072. {
  6073. row1.CreateCell(j);
  6074. row1.Cells[j].SetCellValue("备注");
  6075. }
  6076. else if (j == ShowCountIndex)
  6077. {
  6078. row1.CreateCell(j);
  6079. row1.Cells[j].SetCellValue(totalCount);
  6080. }
  6081. else if (j == ShowRemarkPiece)
  6082. {
  6083. row1.CreateCell(j);
  6084. row1.Cells[j].SetCellValue(rowNum + 片);
  6085. }
  6086. else
  6087. {
  6088. row1.CreateCell(j);
  6089. }
  6090. row1.Cells[j].CellStyle = style;
  6091. }
  6092. sheet.SetRowBreak(PaintIndex);
  6093. sheet.Footer.Center = "第&P页,共&N页";
  6094. PaintIndex = PaintIndex + 1;
  6095. PageNum1 = 0;
  6096. }
  6097. PageNum2 = PageNum2 + 1;
  6098. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  6099. pib_outboxcode1.Add(BoxCode.ToString());
  6100. SerialNum = SerialNum + 1;
  6101. }
  6102. break;
  6103. default:
  6104. break;
  6105. }
  6106. 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());
  6107. //删除下载链接再重新插入
  6108. HttpHandler.GenDownLoadLinK(Inoutno);
  6109. //填充首页
  6110. sumCount = 0;
  6111. totalCount = 0;
  6112. PaintIndex = 1;
  6113. ISheet sheet2 = book.CreateSheet("首页");
  6114. row = sheet2.CreateRow(0);
  6115. row.CreateCell(0);
  6116. row.Cells[0].SetCellValue(" " + companyname);
  6117. row.GetCell(0).CellStyle = style;
  6118. rowNum = FirstDT.Rows.Count;
  6119. //不需要显示的列移除
  6120. for (int i = FirstDT.Columns.Count - 1; i > 0; i--)
  6121. {
  6122. for (int j = 0; j < box.Length; j++)
  6123. {
  6124. if (box[j].Name == "FirstPage_WID" && !box[j].Checked)
  6125. {
  6126. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  6127. {
  6128. FirstDT.Columns.RemoveAt(i);
  6129. }
  6130. }
  6131. if (box[j].Name == "FirstPage_YIELD" && !box[j].Checked)
  6132. {
  6133. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_yeild"))
  6134. {
  6135. FirstDT.Columns.RemoveAt(i);
  6136. }
  6137. }
  6138. if (box[j].Name == "FirstPage_REMARK" && !box[j].Checked)
  6139. {
  6140. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  6141. {
  6142. FirstDT.Columns.RemoveAt(i);
  6143. }
  6144. }
  6145. if (box[j].Name == "FirstPage_BOXCODE" && !box[j].Checked)
  6146. {
  6147. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  6148. {
  6149. FirstDT.Columns.RemoveAt(i);
  6150. }
  6151. }
  6152. }
  6153. }
  6154. columnNum = FirstDT.Columns.Count;
  6155. for (int i = 0; i < rowNum; i++)
  6156. {
  6157. IRow row1 = sheet2.CreateRow(PaintIndex);
  6158. PaintIndex = PaintIndex + 1;
  6159. row1.HeightInPoints = RowHeight;
  6160. //只需要绘制一行
  6161. if (i == 0)
  6162. {
  6163. for (int j = 0; j < columnNum - 3; j++)
  6164. {
  6165. if (j == 0)
  6166. {
  6167. row1.CreateCell(j);
  6168. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_title"].Caption + ":" + FirstDT.Rows[i]["pi_title"].ToString() + " "
  6169. + FirstDT.Columns["ch_level"].Caption + ":" + FirstDT.Rows[i]["ch_level"].ToString());
  6170. }
  6171. else if (j > 5 && j == columnNum - 5)
  6172. {
  6173. row1.CreateCell(j);
  6174. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  6175. }
  6176. else if (columnNum > 5 && j == columnNum - 5)
  6177. {
  6178. row1.CreateCell(j);
  6179. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  6180. }
  6181. else
  6182. {
  6183. row1.CreateCell(j);
  6184. }
  6185. row1.GetCell(j).CellStyle = style;
  6186. }
  6187. row1 = sheet2.CreateRow(PaintIndex);
  6188. PaintIndex = PaintIndex + 1;
  6189. //第二行添加型号
  6190. for (int j = 0; j < columnNum - 3; j++)
  6191. {
  6192. if (j == 0)
  6193. {
  6194. row1.CreateCell(j).SetCellValue(FirstDT.Columns["pr_orispeccode"].Caption + ":" + FirstDT.Rows[i]["pr_orispeccode"].ToString() + "_"
  6195. + "(" + FirstDT.Rows[i]["me_desc"].ToString() + ")" + FirstDT.Columns["pi_chipouttype"].Caption + ":" + FirstDT.Rows[i]["pi_chipouttype"].ToString());
  6196. }
  6197. else if (j == ShowSizeIndex)
  6198. {
  6199. row1.CreateCell(j);
  6200. row1.Cells[j].SetCellValue(FirstDT.Columns["pr_size"].Caption + ":" + FirstDT.Rows[i]["pr_size"].ToString());
  6201. }
  6202. else if (j > 5 && j == columnNum - 5)
  6203. {
  6204. row1.CreateCell(j);
  6205. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  6206. }
  6207. else if (columnNum > 5 && j == columnNum - 5)
  6208. {
  6209. row1.CreateCell(j);
  6210. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  6211. }
  6212. else
  6213. {
  6214. row1.CreateCell(j);
  6215. }
  6216. row1.GetCell(j).CellStyle = style;
  6217. }
  6218. row1 = sheet2.CreateRow(PaintIndex);
  6219. PaintIndex = PaintIndex + 1;
  6220. //添加列名
  6221. for (int j = 4; j < columnNum; j++)
  6222. {
  6223. row1.CreateCell(j - 4);
  6224. if (NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  6225. {
  6226. }
  6227. else
  6228. {
  6229. row1.Cells[j - 4].CellStyle = styleborder;
  6230. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  6231. }
  6232. }
  6233. row1 = sheet2.CreateRow(PaintIndex);
  6234. PaintIndex = PaintIndex + 1;
  6235. }
  6236. //添加数据内容
  6237. ShowColumnCount = 0;
  6238. for (int j = 4; j < columnNum; j++)
  6239. {
  6240. row1.CreateCell(j - 4);
  6241. if (FirstDT.Columns[j].ColumnName == "ch_bluefilm")
  6242. {
  6243. row1.CreateCell(j - 4, CellType.String);
  6244. }
  6245. if (!NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  6246. {
  6247. string Data = FirstDT.Rows[i][j].ToString();
  6248. row1.Cells[j - 4].SetCellValue(Data);
  6249. row1.GetCell(j - 4).CellStyle = styleborder;
  6250. if (FirstDT.Columns[j].ColumnName == "num")
  6251. {
  6252. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  6253. sumCount += int.Parse(Data);
  6254. }
  6255. if (FirstDT.Columns[j].ColumnName == "io_qty")
  6256. {
  6257. totalCount += int.Parse(Data);
  6258. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  6259. }
  6260. ShowColumnCount = ShowColumnCount + 1;
  6261. }
  6262. else
  6263. {
  6264. }
  6265. }
  6266. //添加总计行
  6267. if (i == rowNum - 1)
  6268. {
  6269. row1 = sheet2.CreateRow(PaintIndex);
  6270. PaintIndex = PaintIndex + 1;
  6271. for (int j = 0; j < ShowColumnCount; j++)
  6272. {
  6273. if (j == 0)
  6274. {
  6275. row1.CreateCell(j);
  6276. row1.Cells[j].CellStyle = styleborder;
  6277. row1.Cells[j].SetCellValue(总计);
  6278. }
  6279. else if (j == ShowColumnCount - 2)
  6280. {
  6281. row1.CreateCell(j);
  6282. row1.Cells[j].CellStyle = styleborder;
  6283. row1.Cells[j].SetCellValue(sumCount);
  6284. }
  6285. else if (j == ShowColumnCount - 1)
  6286. {
  6287. row1.CreateCell(j);
  6288. row1.Cells[j].CellStyle = styleborder;
  6289. row1.Cells[j].SetCellValue(totalCount);
  6290. }
  6291. else
  6292. {
  6293. row1.CreateCell(j);
  6294. row1.Cells[j].CellStyle = styleborder;
  6295. }
  6296. }
  6297. }
  6298. }
  6299. //将book的内容写入内存流中返回
  6300. book.Write(ms);
  6301. return ms;
  6302. }
  6303. }
  6304. }