ExcelHandler.cs 351 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601
  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 片 = "";
  4737. string companyname = "";
  4738. int ShowBoxIndex = 0;
  4739. //用于小计的盒号
  4740. string LastBox = "";
  4741. if (dh.getFieldDataByCondition("ProdInout", "pi_exporttype", "pi_inoutno='" + Inoutno + "'").ToString() == "Chinese")
  4742. {
  4743. 小计 = "小计";
  4744. 总计 = "总计";
  4745. 批小计 = "批小计";
  4746. 片 = "片";
  4747. companyname = "深爱半导体股份有限公司芯片出货清单";
  4748. }
  4749. else
  4750. {
  4751. 批小计 = "BatchTotal";
  4752. 小计 = "total";
  4753. 总计 = "total";
  4754. companyname = "SHENZHEN SI SEMICONDUCTORS CO.,LTD";
  4755. }
  4756. //转换为序列
  4757. CheckBox[] box = conditionbox.ToArray();
  4758. //创建内存流
  4759. MemoryStream ms = new MemoryStream();
  4760. //创建一个Book,相当于一个Excel文件
  4761. HSSFWorkbook book = new HSSFWorkbook();
  4762. //Excel中的Sheet
  4763. ISheet sheet = book.CreateSheet("分页");
  4764. sheet.SetMargin(MarginType.TopMargin, 0.4);
  4765. sheet.SetMargin(MarginType.BottomMargin, 0.4);
  4766. sheet.SetMargin(MarginType.LeftMargin, 0.4);
  4767. sheet.SetMargin(MarginType.RightMargin, 0.4);
  4768. sheet.FitToPage = true;
  4769. sheet.PrintSetup.FitHeight = 200;
  4770. //芯片号需要作为更新盒号的条件
  4771. HSSFFont ffont = (HSSFFont)book.CreateFont();
  4772. ffont.FontName = "宋体";
  4773. //更新箱号
  4774. List<string> pib_id = new List<string>();
  4775. //系统打印箱号
  4776. List<string> pib_outboxcode1 = new List<string>();
  4777. int BoxCode = 1;
  4778. ICellStyle style = book.CreateCellStyle();
  4779. style.VerticalAlignment = VerticalAlignment.Center;
  4780. style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
  4781. style.SetFont(ffont);
  4782. ICellStyle styleborder = book.CreateCellStyle();
  4783. styleborder.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  4784. styleborder.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  4785. styleborder.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  4786. styleborder.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  4787. styleborder.VerticalAlignment = VerticalAlignment.Center;
  4788. styleborder.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
  4789. styleborder.SetFont(ffont);
  4790. string pi_inoutno = "";
  4791. HSSFFont ColumnTitle = (HSSFFont)book.CreateFont();
  4792. ColumnTitle.FontName = "宋体";
  4793. ColumnTitle.Boldweight = (short)FontBoldWeight.Bold;
  4794. ICellStyle ColumnTitleStyle = book.CreateCellStyle();
  4795. ColumnTitleStyle.SetFont(ColumnTitle);
  4796. ColumnTitleStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
  4797. ColumnTitleStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
  4798. ColumnTitleStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
  4799. ColumnTitleStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
  4800. List<string> NotShowColumn = new List<string>();
  4801. NotShowColumn.Add("ch_level");
  4802. NotShowColumn.Add("pib_id");
  4803. NotShowColumn.Add("chw_itemname1");
  4804. NotShowColumn.Add("chw_itemname2");
  4805. NotShowColumn.Add("chw_itemname3");
  4806. NotShowColumn.Add("chw_itemname4");
  4807. NotShowColumn.Add("chw_itemname5");
  4808. NotShowColumn.Add("pd_ordercode");
  4809. NotShowColumn.Add("pr_size");
  4810. NotShowColumn.Add("me_desc");
  4811. NotShowColumn.Add("pr_orispeccode");
  4812. NotShowColumn.Add("pr_orispeccode1");
  4813. NotShowColumn.Add("pi_title");
  4814. NotShowColumn.Add("pi_chipouttype");
  4815. NotShowColumn.Add("pi_date");
  4816. int ShowColumnCount = 0;
  4817. //展示的内容列
  4818. //设置列的宽度,根据首行的列的内容的长度来设置
  4819. for (int i = DataTable.Columns.Count - 1; i > 0; i--)
  4820. {
  4821. for (int j = 0; j < box.Length; j++)
  4822. {
  4823. if (box[j].Name.ToLower() == "ch_bluefilm" && !box[j].Checked)
  4824. {
  4825. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_bluefilm"))
  4826. {
  4827. DataTable.Columns.RemoveAt(i);
  4828. break;
  4829. }
  4830. }
  4831. if (box[j].Name.ToLower() == "ch_code" && !box[j].Checked)
  4832. {
  4833. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_code"))
  4834. {
  4835. DataTable.Columns.RemoveAt(i);
  4836. break;
  4837. }
  4838. }
  4839. if (box[j].Name.ToLower() == "ch_splitbatch" && !box[j].Checked)
  4840. {
  4841. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_splitbatch"))
  4842. {
  4843. DataTable.Columns.RemoveAt(i);
  4844. break;
  4845. }
  4846. }
  4847. if (box[j].Name.ToLower() == "ch_waterid" && !box[j].Checked)
  4848. {
  4849. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  4850. {
  4851. DataTable.Columns.RemoveAt(i);
  4852. break;
  4853. }
  4854. }
  4855. if (box[j].Name.ToLower() == "ch_pbcode" && !box[j].Checked)
  4856. {
  4857. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  4858. {
  4859. DataTable.Columns.RemoveAt(i);
  4860. break;
  4861. }
  4862. }
  4863. if (box[j].Name.ToLower() == "ch_remark" && !box[j].Checked)
  4864. {
  4865. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  4866. {
  4867. DataTable.Columns.RemoveAt(i);
  4868. break;
  4869. }
  4870. }
  4871. if (box[j].Name.ToLower() == "ch_yield" && !box[j].Checked)
  4872. {
  4873. if (DataTable.Columns[i].ColumnName.ToLower().Contains("ch_yield"))
  4874. {
  4875. DataTable.Columns.RemoveAt(i);
  4876. break;
  4877. }
  4878. }
  4879. }
  4880. }
  4881. //获取行数量和列数量
  4882. int rowNum = DataTable.Rows.Count;
  4883. int columnNum = DataTable.Columns.Count;
  4884. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  4885. IRow row = sheet.CreateRow(0);
  4886. //冻结第一行
  4887. sheet.CreateFreezePane(0, 1, 0, 1);
  4888. row.HeightInPoints = RowHeight;
  4889. //固定第一行
  4890. //row.RowStyle.IsLocked=true;
  4891. //给第一行的标签赋值样式和值
  4892. // ffont.FontHeight = 13;
  4893. row.CreateCell(0);
  4894. row.Cells[0].SetCellValue(" " + companyname);
  4895. row.GetCell(0).CellStyle.SetFont((ffont));
  4896. //ffont.FontHeight = 10;
  4897. //开始绘制的Index
  4898. int PaintIndex = 1;
  4899. int sumCount = 0;
  4900. int totalCount = 0;
  4901. switch (Type)
  4902. {
  4903. case "FixRow":
  4904. //清理系统取出来的数据
  4905. BaseUtil.CleanDataTableData(FirstDT);
  4906. //首页参数拼接
  4907. string First_OrderCode = "";
  4908. string First_Prspec = "";
  4909. string First_Batch = "";
  4910. int NumIndex = 0;
  4911. ArrayList<string> First_WID = new ArrayList<string>();
  4912. for (int i = 0; i < rowNum; i++)
  4913. {
  4914. IRow row1 = sheet.CreateRow(PaintIndex);
  4915. PaintIndex = PaintIndex + 1;
  4916. row1.HeightInPoints = RowHeight;
  4917. //不包含的订单号
  4918. if (DataTable.Columns.Contains("pd_ordercode") && !First_OrderCode.Contains(DataTable.Rows[i]["pd_ordercode"].ToString()))
  4919. {
  4920. First_OrderCode += DataTable.Rows[i]["pd_ordercode"].ToString() + " ";
  4921. }
  4922. //不包含的物料型号
  4923. if (DataTable.Columns.Contains("pr_orispeccode") && !First_Prspec.Contains(DataTable.Rows[i]["pr_orispeccode"].ToString()))
  4924. {
  4925. First_Prspec += DataTable.Rows[i]["pr_orispeccode"].ToString() + " ";
  4926. }
  4927. //不包含扩撒批号
  4928. if (DataTable.Columns.Contains("ch_splitbatch") && !First_Batch.Contains(DataTable.Rows[i]["ch_splitbatch"].ToString()))
  4929. {
  4930. First_Batch += DataTable.Rows[i]["ch_splitbatch"].ToString() + " ";
  4931. }
  4932. //不包含Wafer_id
  4933. if (DataTable.Columns.Contains("Wafer_ID") && !First_WID.Contains(DataTable.Rows[i]["Wafer_ID"].ToString()))
  4934. {
  4935. First_WID.Add(DataTable.Rows[i]["Wafer_ID"].ToString());
  4936. }
  4937. if (i / PageSize >= 1 && i % PageSize == 0)
  4938. {
  4939. DataRow dr = FirstDT.NewRow();
  4940. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  4941. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  4942. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  4943. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  4944. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  4945. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  4946. pi_inoutno = DataTable.Rows[i]["pi_inoutno"].ToString();
  4947. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  4948. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  4949. dr["pd_ordercode"] = First_OrderCode;
  4950. dr["pr_orispeccode"] = First_Prspec;
  4951. dr["ch_splitbatch"] = First_Batch;
  4952. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  4953. dr["num"] = PageSize;
  4954. dr["io_qty"] = sumCount;
  4955. FirstDT.Rows.Add(dr);
  4956. First_OrderCode = "";
  4957. First_Prspec = "";
  4958. First_Batch = "";
  4959. First_WID.Clear();
  4960. BoxCode = BoxCode + 1;
  4961. for (int j = 0; j < ShowColumnCount; j++)
  4962. {
  4963. row1.CreateCell(j);
  4964. if (j == 0)
  4965. {
  4966. row1.Cells[j].SetCellValue(批小计);
  4967. }
  4968. else if (j == ShowPieceIndex)
  4969. {
  4970. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i));
  4971. row1.Cells[j].CellStyle = styleborder;
  4972. }
  4973. else if (j == ShowCountIndex)
  4974. {
  4975. row1.Cells[j].SetCellValue(sumCount);
  4976. }
  4977. else if (j == ShowBoxIndex - 4)
  4978. {
  4979. row1.Cells[j].SetCellValue(LastBox);
  4980. row1.Cells[j].CellStyle = styleborder;
  4981. }
  4982. row1.Cells[j].CellStyle = styleborder;
  4983. }
  4984. row1 = sheet.CreateRow(PaintIndex);
  4985. PaintIndex = PaintIndex + 1;
  4986. for (int j = 0; j < ShowColumnCount; j++)
  4987. {
  4988. row1.CreateCell(j);
  4989. if (j == 0)
  4990. {
  4991. row1.Cells[j].SetCellValue(小计);
  4992. }
  4993. else if (j == ShowPieceIndex)
  4994. {
  4995. row1.Cells[ShowPieceIndex].SetCellValue((i % PageSize == 0 ? PageSize : i));
  4996. }
  4997. else if (j == ShowCountIndex)
  4998. {
  4999. row1.Cells[j].SetCellValue(sumCount);
  5000. }
  5001. else if (j == ShowBoxIndex - 4)
  5002. {
  5003. row1.Cells[j].SetCellValue(LastBox);
  5004. row1.Cells[j].CellStyle = styleborder;
  5005. }
  5006. row1.Cells[j].CellStyle = styleborder;
  5007. }
  5008. sumCount = 0;
  5009. row1 = sheet.CreateRow(PaintIndex);
  5010. sheet.SetRowBreak(PaintIndex - 1);
  5011. sheet.Footer.Center = "第&P页,共&N页";
  5012. PaintIndex = PaintIndex + 1;
  5013. }
  5014. //每次到了页数开始分页
  5015. if (i % PageSize == 0 || i == rowNum - 1)
  5016. {
  5017. //第一行添加客户信息 rownum只有一行的情
  5018. if (i != rowNum - 1 || rowNum == 1 || (rowNum - i == rowNum % PageSize))
  5019. {
  5020. for (int j = 0; j < columnNum - 3; j++)
  5021. {
  5022. if (j == 0)
  5023. {
  5024. row1.CreateCell(j);
  5025. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  5026. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  5027. }
  5028. else if (j == 4)
  5029. {
  5030. row1.CreateCell(j);
  5031. row1.Cells[j].SetCellValue("出货日期"+ ":" + DataTable.Rows[i]["pi_date"].ToString());
  5032. }
  5033. else if (j == ShowDataIndex)
  5034. {
  5035. row1.CreateCell(j);
  5036. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  5037. }
  5038. else
  5039. {
  5040. row1.CreateCell(j);
  5041. }
  5042. row1.GetCell(j).CellStyle = style;
  5043. }
  5044. row1 = sheet.CreateRow(PaintIndex);
  5045. PaintIndex = PaintIndex + 1;
  5046. //第二行添加型号
  5047. for (int j = 0; j < columnNum - 3; j++)
  5048. {
  5049. if (j == 0)
  5050. {
  5051. row1.CreateCell(j);
  5052. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString()
  5053. + "_(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  5054. }
  5055. else if (j == 4)
  5056. {
  5057. row1.CreateCell(j);
  5058. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  5059. }
  5060. else
  5061. {
  5062. row1.CreateCell(j);
  5063. }
  5064. row1.GetCell(j).CellStyle = style;
  5065. }
  5066. //添加列名
  5067. row1 = sheet.CreateRow(PaintIndex);
  5068. PaintIndex = PaintIndex + 1;
  5069. //计数列所在的索引
  5070. int showcount = 0;
  5071. for (int j = 4; j < columnNum; j++)
  5072. {
  5073. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  5074. {
  5075. showcount = showcount + 1;
  5076. row1.CreateCell(j - 4);
  5077. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5078. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  5079. }
  5080. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  5081. {
  5082. showcount = showcount + 1;
  5083. row1.CreateCell(j - 4);
  5084. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5085. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  5086. }
  5087. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  5088. {
  5089. showcount = showcount + 1;
  5090. row1.CreateCell(j - 4);
  5091. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5092. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  5093. }
  5094. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  5095. {
  5096. showcount = showcount + 1;
  5097. row1.CreateCell(j - 4);
  5098. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5099. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  5100. }
  5101. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  5102. {
  5103. showcount = showcount + 1;
  5104. row1.CreateCell(j - 4);
  5105. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5106. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  5107. }
  5108. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5109. {
  5110. }
  5111. else
  5112. {
  5113. showcount = showcount + 1;
  5114. row1.CreateCell(j - 4);
  5115. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5116. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  5117. }
  5118. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  5119. {
  5120. ShowBoxIndex = j;
  5121. }
  5122. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  5123. {
  5124. NumIndex = j;
  5125. if (ShowCountIndex == NumIndex - 4)
  5126. {
  5127. ShowCountIndex = ShowCountIndex + 1;
  5128. }
  5129. }
  5130. }
  5131. ShowColumnCount = showcount;
  5132. row1 = sheet.CreateRow(PaintIndex);
  5133. PaintIndex = PaintIndex + 1;
  5134. }
  5135. }
  5136. //添加数据内容
  5137. for (int j = 4; j < columnNum; j++)
  5138. {
  5139. string Data = DataTable.Rows[i][j].ToString();
  5140. row1.CreateCell(j - 4);
  5141. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  5142. {
  5143. row1.CreateCell(j - 4, CellType.String);
  5144. }
  5145. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5146. {
  5147. }
  5148. else
  5149. {
  5150. double Num = 0;
  5151. if (double.TryParse(Data, out Num) && DataTable.Columns[j].ColumnName.ToLower() != "ch_bluefilm")
  5152. {
  5153. row1.Cells[j - 4].SetCellValue(Num);
  5154. }
  5155. else
  5156. {
  5157. row1.Cells[j - 4].SetCellValue(Data);
  5158. }
  5159. row1.GetCell(j - 4).CellStyle = styleborder;
  5160. }
  5161. if (DataTable.Columns[j].ColumnName == "io_qty")
  5162. {
  5163. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  5164. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  5165. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  5166. row1.Cells[j - 4].CellStyle = styleborder;
  5167. }
  5168. if (DataTable.Columns[j].ColumnName == "rownum")
  5169. {
  5170. row1.Cells[j - 4].SetCellValue(i + 1);
  5171. row1.Cells[j - 4].CellStyle = styleborder;
  5172. }
  5173. if (DataTable.Columns[j].ColumnName == "ch_code")
  5174. {
  5175. sheet.AutoSizeColumn(j - 4);
  5176. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  5177. }
  5178. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  5179. {
  5180. LastBox = Data;
  5181. }
  5182. }
  5183. //固定行号分组的时候自动拼接新的DataTable
  5184. if (i == rowNum - 1)
  5185. {
  5186. DataRow dr = FirstDT.NewRow();
  5187. dr["me_desc"] = DataTable.Rows[i]["me_desc"].ToString();
  5188. dr["pr_size"] = DataTable.Rows[i]["pr_size"].ToString();
  5189. dr["pi_chipouttype"] = DataTable.Rows[i]["pi_chipouttype"].ToString();
  5190. dr["ch_level"] = DataTable.Rows[i]["ch_level"].ToString();
  5191. dr["pr_orispeccode"] = DataTable.Rows[i]["pr_orispeccode"].ToString();
  5192. dr["pi_inoutno"] = DataTable.Rows[i]["pi_inoutno"].ToString();
  5193. dr["pi_title"] = DataTable.Rows[i]["pi_title"].ToString();
  5194. dr["pi_date"] = DataTable.Rows[i]["pi_date"].ToString();
  5195. dr["pd_ordercode"] = First_OrderCode;
  5196. dr["pr_orispeccode"] = First_Prspec;
  5197. dr["ch_splitbatch"] = First_Batch;
  5198. dr["ch_waterid"] = BaseUtil.GetArrStr(First_WID, " ");
  5199. dr["num"] = (i % PageSize) + 1;
  5200. dr["io_qty"] = sumCount;
  5201. FirstDT.Rows.Add(dr);
  5202. row1 = sheet.CreateRow(PaintIndex);
  5203. PaintIndex = PaintIndex + 1;
  5204. for (int j = 0; j < ShowColumnCount; j++)
  5205. {
  5206. row1.CreateCell(j);
  5207. if (j == 0)
  5208. {
  5209. row1.Cells[j].SetCellValue(批小计);
  5210. }
  5211. else if (j == ShowPieceIndex)
  5212. {
  5213. row1.Cells[ShowPieceIndex].SetCellValue((rowNum % PageSize == 0 ? PageSize : (rowNum % PageSize)));
  5214. row1.Cells[j].CellStyle = styleborder;
  5215. }
  5216. else if (j == ShowBoxIndex - 4)
  5217. {
  5218. row1.Cells[j].SetCellValue(LastBox);
  5219. row1.Cells[j].CellStyle = styleborder;
  5220. }
  5221. else if (j == ShowCountIndex)
  5222. {
  5223. row1.Cells[j].SetCellValue(sumCount);
  5224. }
  5225. row1.Cells[j].CellStyle = styleborder;
  5226. }
  5227. row1 = sheet.CreateRow(PaintIndex);
  5228. PaintIndex = PaintIndex + 1;
  5229. for (int j = 0; j < ShowColumnCount; j++)
  5230. {
  5231. row1.CreateCell(j);
  5232. if (j == 0)
  5233. {
  5234. row1.Cells[j].SetCellValue(小计);
  5235. }
  5236. else if (j == ShowPieceIndex)
  5237. {
  5238. row1.Cells[ShowPieceIndex].SetCellValue(rowNum % PageSize);
  5239. row1.Cells[j].CellStyle = styleborder;
  5240. }
  5241. else if (j == ShowBoxIndex - 4)
  5242. {
  5243. row1.Cells[j].SetCellValue(LastBox);
  5244. row1.Cells[j].CellStyle = styleborder;
  5245. }
  5246. else if (j == ShowCountIndex)
  5247. {
  5248. row1.Cells[j].SetCellValue(sumCount);
  5249. }
  5250. row1.Cells[j].CellStyle = styleborder;
  5251. }
  5252. row1 = sheet.CreateRow(PaintIndex);
  5253. for (int j = 0; j < columnNum - 3; j++)
  5254. {
  5255. if (j == 0)
  5256. {
  5257. row1.CreateCell(j);
  5258. row1.Cells[j].SetCellValue("备注");
  5259. }
  5260. else if (j == ShowCountIndex)
  5261. {
  5262. row1.CreateCell(j);
  5263. row1.Cells[j].SetCellValue(totalCount);
  5264. }
  5265. else if (j == ShowRemarkPiece)
  5266. {
  5267. row1.CreateCell(j);
  5268. row1.Cells[j].SetCellValue(rowNum + 片);
  5269. }
  5270. else
  5271. {
  5272. row1.CreateCell(j);
  5273. }
  5274. row1.Cells[j].CellStyle = style;
  5275. }
  5276. sheet.SetRowBreak(PaintIndex);
  5277. sheet.Footer.Center = "第&P页,共&N页";
  5278. PaintIndex = PaintIndex + 1;
  5279. }
  5280. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  5281. pib_outboxcode1.Add(BoxCode.ToString());
  5282. }
  5283. break;
  5284. case "BatchCode":
  5285. string LastBatchCode = "";
  5286. int PageNum = 0;
  5287. for (int i = 0; i < rowNum; i++)
  5288. {
  5289. IRow row1 = sheet.CreateRow(PaintIndex);
  5290. PaintIndex = PaintIndex + 1;
  5291. row1.HeightInPoints = RowHeight;
  5292. //如果批号不相等的时候
  5293. if (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())
  5294. {
  5295. BoxCode = BoxCode + 1;
  5296. for (int j = 0; j < ShowColumnCount; j++)
  5297. {
  5298. row1.CreateCell(j);
  5299. if (j == 0)
  5300. {
  5301. row1.Cells[j].SetCellValue(批小计);
  5302. row1.Cells[j].CellStyle = styleborder;
  5303. }
  5304. else if (j == ShowPieceIndex)
  5305. {
  5306. row1.Cells[ShowPieceIndex].SetCellValue(PageNum);
  5307. row1.Cells[j].CellStyle = styleborder;
  5308. }
  5309. else if (j == ShowCountIndex)
  5310. {
  5311. row1.Cells[j].SetCellValue(sumCount);
  5312. row1.Cells[j].CellStyle = styleborder;
  5313. }
  5314. else if (j == ShowBoxIndex - 4)
  5315. {
  5316. row1.Cells[j].SetCellValue(LastBox);
  5317. row1.Cells[j].CellStyle = styleborder;
  5318. }
  5319. else
  5320. {
  5321. row1.Cells[j].CellStyle = styleborder;
  5322. }
  5323. }
  5324. row1 = sheet.CreateRow(PaintIndex);
  5325. PaintIndex = PaintIndex + 1;
  5326. for (int j = 0; j < ShowColumnCount; j++)
  5327. {
  5328. row1.CreateCell(j);
  5329. if (j == 0)
  5330. {
  5331. row1.Cells[j].SetCellValue(小计);
  5332. row1.Cells[j].CellStyle = styleborder;
  5333. }
  5334. else if (j == ShowPieceIndex)
  5335. {
  5336. row1.Cells[ShowPieceIndex].SetCellValue(PageNum);
  5337. row1.Cells[j].CellStyle = styleborder;
  5338. }
  5339. else if (j == ShowCountIndex)
  5340. {
  5341. row1.Cells[j].SetCellValue(sumCount);
  5342. row1.Cells[j].CellStyle = styleborder;
  5343. }
  5344. else if (j == ShowBoxIndex - 4)
  5345. {
  5346. row1.Cells[j].SetCellValue(LastBox);
  5347. row1.Cells[j].CellStyle = styleborder;
  5348. }
  5349. else
  5350. {
  5351. row1.Cells[j].CellStyle = styleborder;
  5352. }
  5353. }
  5354. sumCount = 0;
  5355. row1 = sheet.CreateRow(PaintIndex);
  5356. sheet.SetRowBreak(PaintIndex - 1);
  5357. sheet.Footer.Center = "第&P页,共&N页";
  5358. PaintIndex = PaintIndex + 1;
  5359. PageNum = 0;
  5360. }
  5361. //每次到了页数开始分页
  5362. if (LastBatchCode == "" || (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString()) || (i == rowNum - 1 && (LastBatchCode != "" && LastBatchCode != DataTable.Rows[i]["ch_splitbatch"].ToString())))
  5363. {
  5364. Console.WriteLine(DataTable.Rows[i]["ch_splitbatch"].ToString());
  5365. LastBatchCode = DataTable.Rows[i]["ch_splitbatch"].ToString();
  5366. //第一行添加客户信息
  5367. //if (i != rowNum - 1)
  5368. {
  5369. for (int j = 0; j < columnNum - 3; j++)
  5370. {
  5371. if (j == 0)
  5372. {
  5373. row1.CreateCell(j);
  5374. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  5375. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  5376. }
  5377. else if (j == ShowDataIndex)
  5378. {
  5379. row1.CreateCell(j);
  5380. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  5381. }
  5382. else
  5383. {
  5384. row1.CreateCell(j);
  5385. }
  5386. row1.GetCell(j).CellStyle = style;
  5387. }
  5388. row1 = sheet.CreateRow(PaintIndex);
  5389. PaintIndex = PaintIndex + 1;
  5390. //第二行添加型号
  5391. for (int j = 0; j < columnNum - 3; j++)
  5392. {
  5393. if (j == 0)
  5394. {
  5395. row1.CreateCell(j);
  5396. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + "_"
  5397. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  5398. }
  5399. else if (j == ShowSizeIndex)
  5400. {
  5401. row1.CreateCell(j);
  5402. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  5403. }
  5404. else if (j == ShowDataIndex)
  5405. {
  5406. row1.CreateCell(j);
  5407. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  5408. }
  5409. else
  5410. {
  5411. row1.CreateCell(j);
  5412. }
  5413. row1.GetCell(j).CellStyle = style;
  5414. }
  5415. //添加列名
  5416. row1 = sheet.CreateRow(PaintIndex);
  5417. PaintIndex = PaintIndex + 1;
  5418. int showcount = 0;
  5419. for (int j = 4; j < columnNum; j++)
  5420. {
  5421. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  5422. {
  5423. showcount = showcount + 1;
  5424. row1.CreateCell(j - 4);
  5425. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5426. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  5427. }
  5428. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  5429. {
  5430. showcount = showcount + 1;
  5431. row1.CreateCell(j - 4);
  5432. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5433. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  5434. }
  5435. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  5436. {
  5437. showcount = showcount + 1;
  5438. row1.CreateCell(j - 4);
  5439. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5440. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  5441. }
  5442. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  5443. {
  5444. showcount = showcount + 1;
  5445. row1.CreateCell(j - 4);
  5446. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5447. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  5448. }
  5449. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  5450. {
  5451. showcount = showcount + 1;
  5452. row1.CreateCell(j - 4);
  5453. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5454. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  5455. }
  5456. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5457. {
  5458. }
  5459. else
  5460. {
  5461. showcount = showcount + 1;
  5462. row1.CreateCell(j - 4);
  5463. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5464. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  5465. }
  5466. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  5467. {
  5468. ShowBoxIndex = j;
  5469. }
  5470. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  5471. {
  5472. NumIndex = j;
  5473. if (ShowCountIndex == NumIndex - 4)
  5474. {
  5475. ShowCountIndex = ShowCountIndex + 1;
  5476. }
  5477. }
  5478. }
  5479. ShowColumnCount = showcount;
  5480. row1 = sheet.CreateRow(PaintIndex);
  5481. PaintIndex = PaintIndex + 1;
  5482. }
  5483. }
  5484. //添加数据内容
  5485. for (int j = 4; j < columnNum; j++)
  5486. {
  5487. string Data = DataTable.Rows[i][j].ToString();
  5488. row1.CreateCell(j - 4);
  5489. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  5490. {
  5491. row1.CreateCell(j - 4, CellType.String);
  5492. }
  5493. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5494. {
  5495. }
  5496. else
  5497. {
  5498. double Num = 0;
  5499. if (double.TryParse(Data, out Num) && DataTable.Columns[j].ColumnName.ToLower() != "ch_bluefilm")
  5500. {
  5501. row1.Cells[j - 4].SetCellValue(Num);
  5502. }
  5503. else
  5504. {
  5505. row1.Cells[j - 4].SetCellValue(Data);
  5506. }
  5507. row1.Cells[j - 4].CellStyle = styleborder;
  5508. }
  5509. if (DataTable.Columns[j].ColumnName == "io_qty")
  5510. {
  5511. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  5512. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  5513. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  5514. }
  5515. if (DataTable.Columns[j].ColumnName == "rownum")
  5516. {
  5517. row1.Cells[j - 4].SetCellValue(i + 1);
  5518. row1.Cells[j - 4].CellStyle = styleborder;
  5519. }
  5520. if (DataTable.Columns[j].ColumnName == "ch_code")
  5521. {
  5522. sheet.AutoSizeColumn(j - 4);
  5523. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  5524. }
  5525. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  5526. {
  5527. LastBox = Data;
  5528. }
  5529. }
  5530. if (i == rowNum - 1)
  5531. {
  5532. row1 = sheet.CreateRow(PaintIndex);
  5533. PaintIndex = PaintIndex + 1;
  5534. for (int j = 0; j < ShowColumnCount; j++)
  5535. {
  5536. row1.CreateCell(j);
  5537. if (j == 0)
  5538. {
  5539. row1.Cells[j].SetCellValue(批小计);
  5540. row1.Cells[j].CellStyle = styleborder;
  5541. }
  5542. else if (j == ShowPieceIndex)
  5543. {
  5544. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 1);
  5545. row1.Cells[j].CellStyle = styleborder;
  5546. }
  5547. else if (j == ShowCountIndex)
  5548. {
  5549. row1.Cells[j].SetCellValue(sumCount);
  5550. row1.Cells[j].CellStyle = styleborder;
  5551. }
  5552. else
  5553. {
  5554. row1.Cells[j].CellStyle = styleborder;
  5555. }
  5556. }
  5557. row1 = sheet.CreateRow(PaintIndex);
  5558. PaintIndex = PaintIndex + 1;
  5559. for (int j = 0; j < ShowColumnCount; j++)
  5560. {
  5561. row1.CreateCell(j);
  5562. if (j == 0)
  5563. {
  5564. row1.Cells[j].SetCellValue(小计);
  5565. row1.Cells[j].CellStyle = styleborder;
  5566. }
  5567. else if (j == ShowPieceIndex)
  5568. {
  5569. row1.Cells[ShowPieceIndex].SetCellValue(PageNum + 1);
  5570. row1.Cells[j].CellStyle = styleborder;
  5571. }
  5572. else if (j == ShowCountIndex)
  5573. {
  5574. row1.Cells[j].SetCellValue(sumCount);
  5575. row1.Cells[j].CellStyle = styleborder;
  5576. }
  5577. else
  5578. {
  5579. row1.Cells[j].CellStyle = styleborder;
  5580. }
  5581. }
  5582. //创建备注内容
  5583. row1 = sheet.CreateRow(PaintIndex);
  5584. for (int j = 0; j < columnNum - 3; j++)
  5585. {
  5586. if (j == 0)
  5587. {
  5588. row1.CreateCell(j);
  5589. row1.Cells[j].SetCellValue("备注");
  5590. }
  5591. else if (j == ShowCountIndex)
  5592. {
  5593. row1.CreateCell(j);
  5594. row1.Cells[j].SetCellValue(totalCount);
  5595. }
  5596. else if (j == ShowRemarkPiece)
  5597. {
  5598. row1.CreateCell(j);
  5599. row1.Cells[j].SetCellValue(rowNum + 片);
  5600. }
  5601. else
  5602. {
  5603. row1.CreateCell(j);
  5604. }
  5605. row1.Cells[j].CellStyle = style;
  5606. }
  5607. sheet.SetRowBreak(PaintIndex);
  5608. sheet.Footer.Center = "第&P页,共&N页";
  5609. PaintIndex = PaintIndex + 1;
  5610. PageNum = 0;
  5611. }
  5612. PageNum = PageNum + 1;
  5613. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  5614. pib_outboxcode1.Add(BoxCode.ToString());
  5615. }
  5616. break;
  5617. case "BoxCode":
  5618. string LastBoxCode = "";
  5619. int PageNum1 = 0;
  5620. for (int i = 0; i < rowNum; i++)
  5621. {
  5622. IRow row1 = sheet.CreateRow(PaintIndex);
  5623. PaintIndex = PaintIndex + 1;
  5624. row1.HeightInPoints = RowHeight;
  5625. //如果批号不相等的时候
  5626. if (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["CH_PBCODE"].ToString())
  5627. {
  5628. BoxCode = BoxCode + 1;
  5629. for (int j = 0; j < ShowColumnCount; j++)
  5630. {
  5631. row1.CreateCell(j);
  5632. if (j == 0)
  5633. {
  5634. row1.Cells[j].SetCellValue(批小计);
  5635. row1.Cells[j].CellStyle = styleborder;
  5636. }
  5637. else if (j == ShowPieceIndex)
  5638. {
  5639. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  5640. row1.Cells[j].CellStyle = styleborder;
  5641. }
  5642. else if (j == ShowCountIndex)
  5643. {
  5644. row1.Cells[j].SetCellValue(sumCount);
  5645. row1.Cells[j].CellStyle = styleborder;
  5646. }
  5647. else if (j == ShowBoxIndex - 4)
  5648. {
  5649. row1.Cells[j].SetCellValue(LastBox);
  5650. row1.Cells[j].CellStyle = styleborder;
  5651. }
  5652. else
  5653. {
  5654. row1.Cells[j].CellStyle = styleborder;
  5655. }
  5656. }
  5657. row1 = sheet.CreateRow(PaintIndex);
  5658. PaintIndex = PaintIndex + 1;
  5659. for (int j = 0; j < ShowColumnCount; j++)
  5660. {
  5661. row1.CreateCell(j);
  5662. if (j == 0)
  5663. {
  5664. row1.Cells[j].SetCellValue(小计);
  5665. row1.Cells[j].CellStyle = styleborder;
  5666. }
  5667. else if (j == ShowPieceIndex)
  5668. {
  5669. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  5670. row1.Cells[j].CellStyle = styleborder;
  5671. }
  5672. else if (j == ShowCountIndex)
  5673. {
  5674. row1.Cells[j].SetCellValue(sumCount);
  5675. row1.Cells[j].CellStyle = styleborder;
  5676. }
  5677. else if (j == ShowBoxIndex - 4)
  5678. {
  5679. row1.Cells[j].SetCellValue(LastBox);
  5680. row1.Cells[j].CellStyle = styleborder;
  5681. }
  5682. else
  5683. {
  5684. row1.Cells[j].CellStyle = styleborder;
  5685. }
  5686. }
  5687. sumCount = 0;
  5688. row1 = sheet.CreateRow(PaintIndex);
  5689. sheet.SetRowBreak(PaintIndex - 1);
  5690. sheet.Footer.Center = "第&P页,共&N页";
  5691. PaintIndex = PaintIndex + 1;
  5692. PageNum1 = 0;
  5693. }
  5694. //每次到了页数开始分页
  5695. if (LastBoxCode == "" || (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode != "" && LastBoxCode != DataTable.Rows[i]["ch_pbcode"].ToString())))
  5696. {
  5697. LastBoxCode = DataTable.Rows[i]["CH_PBCODE"].ToString();
  5698. //第一行添加客户信息
  5699. //if (i != rowNum - 1)
  5700. {
  5701. for (int j = 0; j < columnNum - 3; j++)
  5702. {
  5703. if (j == 0)
  5704. {
  5705. row1.CreateCell(j);
  5706. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  5707. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  5708. }
  5709. else if (j == ShowDataIndex)
  5710. {
  5711. row1.CreateCell(j);
  5712. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  5713. }
  5714. else
  5715. {
  5716. row1.CreateCell(j);
  5717. }
  5718. row1.GetCell(j).CellStyle = style;
  5719. }
  5720. row1 = sheet.CreateRow(PaintIndex);
  5721. PaintIndex = PaintIndex + 1;
  5722. //第二行添加型号
  5723. for (int j = 0; j < columnNum - 3; j++)
  5724. {
  5725. if (j == 0)
  5726. {
  5727. row1.CreateCell(j);
  5728. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + "_"
  5729. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  5730. }
  5731. else if (j == ShowSizeIndex)
  5732. {
  5733. row1.CreateCell(j);
  5734. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  5735. }
  5736. else if (j == ShowDataIndex)
  5737. {
  5738. row1.CreateCell(j);
  5739. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  5740. }
  5741. else
  5742. {
  5743. row1.CreateCell(j);
  5744. }
  5745. }
  5746. //添加列名
  5747. row1 = sheet.CreateRow(PaintIndex);
  5748. PaintIndex = PaintIndex + 1;
  5749. int showcount = 0;
  5750. for (int j = 4; j < columnNum; j++)
  5751. {
  5752. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  5753. {
  5754. showcount = showcount + 1;
  5755. row1.CreateCell(j - 4);
  5756. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5757. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  5758. }
  5759. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  5760. {
  5761. showcount = showcount + 1;
  5762. row1.CreateCell(j - 4);
  5763. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5764. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  5765. }
  5766. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  5767. {
  5768. showcount = showcount + 1;
  5769. row1.CreateCell(j - 4);
  5770. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5771. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  5772. }
  5773. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  5774. {
  5775. showcount = showcount + 1;
  5776. row1.CreateCell(j - 4);
  5777. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5778. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  5779. }
  5780. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  5781. {
  5782. showcount = showcount + 1;
  5783. row1.CreateCell(j - 4);
  5784. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5785. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  5786. }
  5787. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5788. {
  5789. }
  5790. else
  5791. {
  5792. showcount = showcount + 1;
  5793. row1.CreateCell(j - 4);
  5794. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  5795. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  5796. }
  5797. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  5798. {
  5799. ShowBoxIndex = j;
  5800. }
  5801. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  5802. {
  5803. NumIndex = j;
  5804. if (ShowCountIndex == NumIndex - 4)
  5805. {
  5806. ShowCountIndex = ShowCountIndex + 1;
  5807. }
  5808. }
  5809. }
  5810. ShowColumnCount = showcount;
  5811. row1 = sheet.CreateRow(PaintIndex);
  5812. PaintIndex = PaintIndex + 1;
  5813. }
  5814. }
  5815. //添加数据内容
  5816. for (int j = 4; j < columnNum; j++)
  5817. {
  5818. string Data = DataTable.Rows[i][j].ToString();
  5819. row1.CreateCell(j - 4);
  5820. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  5821. {
  5822. row1.CreateCell(j - 4, CellType.String);
  5823. }
  5824. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  5825. {
  5826. }
  5827. else
  5828. {
  5829. double Num = 0;
  5830. if (double.TryParse(Data, out Num) && DataTable.Columns[j].ColumnName.ToLower() != "ch_bluefilm")
  5831. {
  5832. row1.Cells[j - 4].SetCellValue(Num);
  5833. }
  5834. else
  5835. {
  5836. row1.Cells[j - 4].SetCellValue(Data);
  5837. }
  5838. row1.Cells[j - 4].CellStyle = styleborder;
  5839. }
  5840. if (DataTable.Columns[j].ColumnName == "io_qty")
  5841. {
  5842. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  5843. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  5844. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  5845. row1.Cells[j - 4].CellStyle = styleborder;
  5846. }
  5847. if (DataTable.Columns[j].ColumnName == "rownum")
  5848. {
  5849. row1.Cells[j - 4].SetCellValue(i + 1);
  5850. row1.Cells[j - 4].CellStyle = styleborder;
  5851. }
  5852. if (DataTable.Columns[j].ColumnName == "ch_code")
  5853. {
  5854. sheet.AutoSizeColumn(j - 4);
  5855. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  5856. }
  5857. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  5858. {
  5859. LastBox = Data;
  5860. }
  5861. }
  5862. if (i == rowNum - 1)
  5863. {
  5864. PageNum1 = PageNum1 + 1;
  5865. row1 = sheet.CreateRow(PaintIndex);
  5866. PaintIndex = PaintIndex + 1;
  5867. for (int j = 0; j < ShowColumnCount; j++)
  5868. {
  5869. row1.CreateCell(j);
  5870. if (j == 0)
  5871. {
  5872. row1.Cells[j].SetCellValue(批小计);
  5873. row1.Cells[j].CellStyle = styleborder;
  5874. }
  5875. else if (j == ShowPieceIndex)
  5876. {
  5877. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  5878. row1.Cells[j].CellStyle = styleborder;
  5879. }
  5880. else if (j == ShowCountIndex)
  5881. {
  5882. row1.Cells[j].SetCellValue(sumCount);
  5883. row1.Cells[j].CellStyle = styleborder;
  5884. }
  5885. else if (j == ShowBoxIndex - 4)
  5886. {
  5887. row1.Cells[j].SetCellValue(LastBox);
  5888. row1.Cells[j].CellStyle = styleborder;
  5889. }
  5890. else
  5891. {
  5892. row1.Cells[j].CellStyle = styleborder;
  5893. }
  5894. }
  5895. row1 = sheet.CreateRow(PaintIndex);
  5896. PaintIndex = PaintIndex + 1;
  5897. for (int j = 0; j < ShowColumnCount; j++)
  5898. {
  5899. row1.CreateCell(j);
  5900. if (j == 0)
  5901. {
  5902. row1.Cells[j].SetCellValue(小计);
  5903. row1.Cells[j].CellStyle = styleborder;
  5904. }
  5905. else if (j == ShowPieceIndex)
  5906. {
  5907. row1.Cells[ShowPieceIndex].SetCellValue(PageNum1);
  5908. row1.Cells[j].CellStyle = styleborder;
  5909. }
  5910. else if (j == ShowCountIndex)
  5911. {
  5912. row1.Cells[j].SetCellValue(sumCount);
  5913. row1.Cells[j].CellStyle = styleborder;
  5914. }
  5915. else if (j == ShowBoxIndex - 4)
  5916. {
  5917. row1.Cells[j].SetCellValue(LastBox);
  5918. row1.Cells[j].CellStyle = styleborder;
  5919. }
  5920. else
  5921. {
  5922. row1.Cells[j].CellStyle = styleborder;
  5923. }
  5924. }
  5925. row1 = sheet.CreateRow(PaintIndex);
  5926. for (int j = 0; j < columnNum - 3; j++)
  5927. {
  5928. if (j == 0)
  5929. {
  5930. row1.CreateCell(j);
  5931. row1.Cells[j].SetCellValue("备注");
  5932. }
  5933. else if (j == ShowCountIndex)
  5934. {
  5935. row1.CreateCell(j);
  5936. row1.Cells[j].SetCellValue(totalCount);
  5937. }
  5938. else if (j == ShowRemarkPiece)
  5939. {
  5940. row1.CreateCell(j);
  5941. row1.Cells[j].SetCellValue(rowNum + 片);
  5942. }
  5943. else
  5944. {
  5945. row1.CreateCell(j);
  5946. }
  5947. row1.Cells[j].CellStyle = style;
  5948. }
  5949. sheet.SetRowBreak(PaintIndex);
  5950. sheet.Footer.Center = "第&P页,共&N页";
  5951. PaintIndex = PaintIndex + 1;
  5952. PageNum1 = 0;
  5953. }
  5954. PageNum1 = PageNum1 + 1;
  5955. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  5956. pib_outboxcode1.Add(BoxCode.ToString());
  5957. }
  5958. break;
  5959. case "BoxSplit":
  5960. string LastBoxCode1 = "";
  5961. int PageNum2 = 0;
  5962. string LastBatch = "";
  5963. int MidCount = 0;
  5964. int SerialNum = 1;
  5965. for (int i = 0; i < rowNum; i++)
  5966. {
  5967. IRow row1 = sheet.CreateRow(PaintIndex);
  5968. PaintIndex = PaintIndex + 1;
  5969. row1.HeightInPoints = RowHeight;
  5970. //如果批号不相等的时候
  5971. if (LastBatch == "" || (LastBatch != "" && LastBatch != DataTable.Rows[i]["ch_splitbatch"].ToString()))
  5972. {
  5973. LastBatch = DataTable.Rows[i]["ch_splitbatch"].ToString();
  5974. for (int j = 0; j < ShowColumnCount; j++)
  5975. {
  5976. if (j == 0)
  5977. {
  5978. row1.CreateCell(j).SetCellValue(SerialNum - 1);
  5979. }
  5980. else if (j == 1)
  5981. {
  5982. row1.CreateCell(j).SetCellValue("批小计");
  5983. }
  5984. else if (j == 2)
  5985. {
  5986. row1.CreateCell(j).SetCellValue(MidCount);
  5987. }
  5988. else if (j == ShowBoxIndex - 4)
  5989. {
  5990. row1.CreateCell(j).SetCellValue(LastBox);
  5991. }
  5992. else
  5993. {
  5994. row1.CreateCell(j);
  5995. }
  5996. row1.Cells[j].CellStyle = styleborder;
  5997. }
  5998. SerialNum = 1;
  5999. MidCount = 0;
  6000. row1 = sheet.CreateRow(PaintIndex);
  6001. PaintIndex = PaintIndex + 1;
  6002. }
  6003. if (LastBoxCode1 != "" && LastBoxCode1 != DataTable.Rows[i]["CH_PBCODE"].ToString())
  6004. {
  6005. BoxCode = BoxCode + 1;
  6006. for (int j = 0; j < ShowColumnCount; j++)
  6007. {
  6008. row1.CreateCell(j);
  6009. if (j == 1)
  6010. {
  6011. row1.Cells[j].SetCellValue(小计);
  6012. row1.Cells[j].CellStyle = styleborder;
  6013. }
  6014. else if (j == 0)
  6015. {
  6016. row1.Cells[0].SetCellValue(PageNum2);
  6017. row1.Cells[j].CellStyle = styleborder;
  6018. }
  6019. else if (j == ShowCountIndex)
  6020. {
  6021. row1.Cells[j].SetCellValue(sumCount);
  6022. row1.Cells[j].CellStyle = styleborder;
  6023. }
  6024. else if (j == ShowBoxIndex - 4)
  6025. {
  6026. row1.Cells[j].SetCellValue(LastBox);
  6027. row1.Cells[j].CellStyle = styleborder;
  6028. }
  6029. else
  6030. {
  6031. row1.Cells[j].CellStyle = styleborder;
  6032. }
  6033. }
  6034. sumCount = 0;
  6035. row1 = sheet.CreateRow(PaintIndex);
  6036. sheet.SetRowBreak(PaintIndex - 1);
  6037. sheet.Footer.Center = "第&P页,共&N页";
  6038. PaintIndex = PaintIndex + 1;
  6039. PageNum2 = 0;
  6040. }
  6041. //每次到了页数开始分页
  6042. if (LastBoxCode1 == "" || (LastBoxCode1 != "" && LastBoxCode1 != DataTable.Rows[i]["ch_pbcode"].ToString()) || ((i == rowNum - 1) && (LastBoxCode1 != "" && LastBoxCode1 != DataTable.Rows[i]["ch_pbcode"].ToString())))
  6043. {
  6044. LastBoxCode1 = DataTable.Rows[i]["CH_PBCODE"].ToString();
  6045. //第一行添加客户信息
  6046. //if (i != rowNum - 1)
  6047. {
  6048. for (int j = 0; j < columnNum - 3; j++)
  6049. {
  6050. if (j == 0)
  6051. {
  6052. row1.CreateCell(j);
  6053. row1.Cells[j].SetCellValue(DataTable.Columns["pi_title"].Caption + ":" + DataTable.Rows[i]["pi_title"].ToString() + " "
  6054. + DataTable.Columns["ch_level"].Caption + ":" + DataTable.Rows[i]["ch_level"].ToString());
  6055. }
  6056. else if (j == ShowDataIndex)
  6057. {
  6058. row1.CreateCell(j);
  6059. row1.Cells[j].SetCellValue(DataTable.Columns["pi_inoutno"].Caption + ":" + DataTable.Rows[i]["pi_inoutno"].ToString());
  6060. }
  6061. else
  6062. {
  6063. row1.CreateCell(j);
  6064. }
  6065. row1.GetCell(j).CellStyle = style;
  6066. }
  6067. row1 = sheet.CreateRow(PaintIndex);
  6068. PaintIndex = PaintIndex + 1;
  6069. //第二行添加型号
  6070. for (int j = 0; j < columnNum - 3; j++)
  6071. {
  6072. if (j == 0)
  6073. {
  6074. row1.CreateCell(j);
  6075. row1.Cells[j].SetCellValue(DataTable.Columns["pr_orispeccode"].Caption + ":" + DataTable.Rows[i]["pr_orispeccode"].ToString() + "_"
  6076. + "(" + DataTable.Rows[i]["me_desc"].ToString() + ") " + DataTable.Columns["pi_chipouttype"].Caption + ":" + DataTable.Rows[i]["pi_chipouttype"].ToString());
  6077. }
  6078. else if (j == ShowSizeIndex)
  6079. {
  6080. row1.CreateCell(j);
  6081. row1.Cells[j].SetCellValue(DataTable.Columns["pr_size"].Caption + ":" + DataTable.Rows[i]["pr_size"].ToString());
  6082. }
  6083. else if (j == ShowDataIndex)
  6084. {
  6085. row1.CreateCell(j);
  6086. row1.Cells[j].SetCellValue(DataTable.Columns["pi_date"].Caption + ":" + DataTable.Rows[i]["pi_date"].ToString());
  6087. }
  6088. else
  6089. {
  6090. row1.CreateCell(j);
  6091. }
  6092. }
  6093. //添加列名
  6094. row1 = sheet.CreateRow(PaintIndex);
  6095. PaintIndex = PaintIndex + 1;
  6096. int showcount = 0;
  6097. for (int j = 4; j < columnNum; j++)
  6098. {
  6099. if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent1")
  6100. {
  6101. showcount = showcount + 1;
  6102. row1.CreateCell(j - 4);
  6103. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  6104. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname1"].ToString());
  6105. }
  6106. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent2")
  6107. {
  6108. showcount = showcount + 1;
  6109. row1.CreateCell(j - 4);
  6110. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  6111. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname2"].ToString());
  6112. }
  6113. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent3")
  6114. {
  6115. showcount = showcount + 1;
  6116. row1.CreateCell(j - 4);
  6117. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  6118. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname3"].ToString());
  6119. }
  6120. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent4")
  6121. {
  6122. showcount = showcount + 1;
  6123. row1.CreateCell(j - 4);
  6124. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  6125. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname4"].ToString());
  6126. }
  6127. else if (DataTable.Columns[j].ColumnName.ToLower() == "chw_percent5")
  6128. {
  6129. showcount = showcount + 1;
  6130. row1.CreateCell(j - 4);
  6131. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  6132. row1.Cells[j - 4].SetCellValue(DataTable.Rows[0]["chw_itemname5"].ToString());
  6133. }
  6134. else if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  6135. {
  6136. }
  6137. else
  6138. {
  6139. showcount = showcount + 1;
  6140. row1.CreateCell(j - 4);
  6141. row1.Cells[j - 4].CellStyle = ColumnTitleStyle;
  6142. row1.Cells[j - 4].SetCellValue(DataTable.Columns[j].Caption);
  6143. }
  6144. if (DataTable.Columns[j].ColumnName.ToLower().ToString() == "ch_pbcode")
  6145. {
  6146. ShowBoxIndex = j;
  6147. }
  6148. if (DataTable.Columns[j].ColumnName.ToString() == "io_qty")
  6149. {
  6150. NumIndex = j;
  6151. if (ShowCountIndex == NumIndex - 4)
  6152. {
  6153. ShowCountIndex = ShowCountIndex + 1;
  6154. }
  6155. }
  6156. }
  6157. ShowColumnCount = showcount;
  6158. row1 = sheet.CreateRow(PaintIndex);
  6159. PaintIndex = PaintIndex + 1;
  6160. }
  6161. }
  6162. //添加数据内容
  6163. for (int j = 4; j < columnNum; j++)
  6164. {
  6165. string Data = DataTable.Rows[i][j].ToString();
  6166. row1.CreateCell(j - 4);
  6167. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_bluefilm")
  6168. {
  6169. row1.CreateCell(j - 4, CellType.String);
  6170. }
  6171. if ((NotShowColumn.Contains(DataTable.Columns[j].ColumnName.ToLower())))
  6172. {
  6173. }
  6174. else
  6175. {
  6176. row1.Cells[j - 4].SetCellValue(Data);
  6177. row1.GetCell(j - 4).CellStyle = styleborder;
  6178. }
  6179. if (DataTable.Columns[j].ColumnName == "io_qty")
  6180. {
  6181. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  6182. sumCount += int.Parse(DataTable.Rows[i][j].ToString());
  6183. totalCount += int.Parse(DataTable.Rows[i][j].ToString());
  6184. MidCount += int.Parse(DataTable.Rows[i][j].ToString());
  6185. }
  6186. if (DataTable.Columns[j].ColumnName == "rownum")
  6187. {
  6188. row1.Cells[j - 4].SetCellValue(SerialNum);
  6189. }
  6190. if (DataTable.Columns[j].ColumnName == "ch_code")
  6191. {
  6192. sheet.AutoSizeColumn(j - 4);
  6193. sheet.SetColumnWidth(j - 4, sheet.GetColumnWidth(j - 4) + 1000);
  6194. }
  6195. if (DataTable.Columns[j].ColumnName.ToLower() == "ch_pbcode")
  6196. {
  6197. LastBox = Data;
  6198. }
  6199. }
  6200. if (i == rowNum - 1)
  6201. {
  6202. PageNum2 = PageNum2 + 1;
  6203. row1 = sheet.CreateRow(PaintIndex);
  6204. PaintIndex = PaintIndex + 1;
  6205. for (int j = 0; j < ShowColumnCount; j++)
  6206. {
  6207. row1.CreateCell(j);
  6208. if (j == 0)
  6209. {
  6210. row1.Cells[j].SetCellValue(批小计);
  6211. row1.Cells[j].CellStyle = styleborder;
  6212. }
  6213. else if (j == ShowPieceIndex)
  6214. {
  6215. row1.Cells[ShowPieceIndex].SetCellValue(PageNum2);
  6216. row1.Cells[j].CellStyle = styleborder;
  6217. }
  6218. else if (j == ShowCountIndex)
  6219. {
  6220. row1.Cells[j].SetCellValue(sumCount);
  6221. row1.Cells[j].CellStyle = styleborder;
  6222. }
  6223. else if (j == ShowBoxIndex - 4)
  6224. {
  6225. row1.Cells[j].SetCellValue(LastBox);
  6226. row1.Cells[j].CellStyle = styleborder;
  6227. }
  6228. else
  6229. {
  6230. row1.Cells[j].CellStyle = styleborder;
  6231. }
  6232. }
  6233. row1 = sheet.CreateRow(PaintIndex);
  6234. PaintIndex = PaintIndex + 1;
  6235. for (int j = 0; j < ShowColumnCount; j++)
  6236. {
  6237. row1.CreateCell(j);
  6238. if (j == 0)
  6239. {
  6240. row1.Cells[j].SetCellValue(小计);
  6241. row1.Cells[j].CellStyle = styleborder;
  6242. }
  6243. else if (j == ShowPieceIndex)
  6244. {
  6245. row1.Cells[ShowPieceIndex].SetCellValue(PageNum2);
  6246. row1.Cells[j].CellStyle = styleborder;
  6247. }
  6248. else if (j == ShowCountIndex)
  6249. {
  6250. row1.Cells[j].SetCellValue(sumCount);
  6251. row1.Cells[j].CellStyle = styleborder;
  6252. }
  6253. else if (j == ShowBoxIndex - 4)
  6254. {
  6255. row1.Cells[j].SetCellValue(LastBox);
  6256. row1.Cells[j].CellStyle = styleborder;
  6257. }
  6258. else
  6259. {
  6260. row1.Cells[j].CellStyle = styleborder;
  6261. }
  6262. }
  6263. row1 = sheet.CreateRow(PaintIndex);
  6264. for (int j = 0; j < columnNum - 3; j++)
  6265. {
  6266. if (j == 0)
  6267. {
  6268. row1.CreateCell(j);
  6269. row1.Cells[j].SetCellValue("备注");
  6270. }
  6271. else if (j == ShowCountIndex)
  6272. {
  6273. row1.CreateCell(j);
  6274. row1.Cells[j].SetCellValue(totalCount);
  6275. }
  6276. else if (j == ShowRemarkPiece)
  6277. {
  6278. row1.CreateCell(j);
  6279. row1.Cells[j].SetCellValue(rowNum + 片);
  6280. }
  6281. else
  6282. {
  6283. row1.CreateCell(j);
  6284. }
  6285. row1.Cells[j].CellStyle = style;
  6286. }
  6287. sheet.SetRowBreak(PaintIndex);
  6288. sheet.Footer.Center = "第&P页,共&N页";
  6289. PaintIndex = PaintIndex + 1;
  6290. PageNum1 = 0;
  6291. }
  6292. PageNum2 = PageNum2 + 1;
  6293. pib_id.Add(DataTable.Rows[i]["pib_id"].ToString());
  6294. pib_outboxcode1.Add(BoxCode.ToString());
  6295. SerialNum = SerialNum + 1;
  6296. }
  6297. break;
  6298. default:
  6299. break;
  6300. }
  6301. 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());
  6302. //删除下载链接再重新插入
  6303. HttpHandler.GenDownLoadLinK(Inoutno);
  6304. //填充首页
  6305. sumCount = 0;
  6306. totalCount = 0;
  6307. PaintIndex = 1;
  6308. ISheet sheet2 = book.CreateSheet("首页");
  6309. row = sheet2.CreateRow(0);
  6310. row.CreateCell(0);
  6311. row.Cells[0].SetCellValue(" " + companyname);
  6312. row.GetCell(0).CellStyle = style;
  6313. rowNum = FirstDT.Rows.Count;
  6314. //不需要显示的列移除
  6315. for (int i = FirstDT.Columns.Count - 1; i > 0; i--)
  6316. {
  6317. for (int j = 0; j < box.Length; j++)
  6318. {
  6319. if (box[j].Name == "FirstPage_WID" && !box[j].Checked)
  6320. {
  6321. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_waterid"))
  6322. {
  6323. FirstDT.Columns.RemoveAt(i);
  6324. }
  6325. }
  6326. if (box[j].Name == "FirstPage_YIELD" && !box[j].Checked)
  6327. {
  6328. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_yeild"))
  6329. {
  6330. FirstDT.Columns.RemoveAt(i);
  6331. }
  6332. }
  6333. if (box[j].Name == "FirstPage_REMARK" && !box[j].Checked)
  6334. {
  6335. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_remark"))
  6336. {
  6337. FirstDT.Columns.RemoveAt(i);
  6338. }
  6339. }
  6340. if (box[j].Name == "FirstPage_BOXCODE" && !box[j].Checked)
  6341. {
  6342. if (FirstDT.Columns[i].ColumnName.ToLower().Contains("ch_pbcode"))
  6343. {
  6344. FirstDT.Columns.RemoveAt(i);
  6345. }
  6346. }
  6347. }
  6348. }
  6349. columnNum = FirstDT.Columns.Count;
  6350. for (int i = 0; i < rowNum; i++)
  6351. {
  6352. IRow row1 = sheet2.CreateRow(PaintIndex);
  6353. PaintIndex = PaintIndex + 1;
  6354. row1.HeightInPoints = RowHeight;
  6355. //只需要绘制一行
  6356. if (i == 0)
  6357. {
  6358. for (int j = 0; j < columnNum - 3; j++)
  6359. {
  6360. if (j == 0)
  6361. {
  6362. row1.CreateCell(j);
  6363. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_title"].Caption + ":" + FirstDT.Rows[i]["pi_title"].ToString() + " "
  6364. + FirstDT.Columns["ch_level"].Caption + ":" + FirstDT.Rows[i]["ch_level"].ToString());
  6365. }
  6366. else if (j > 5 && j == columnNum - 5)
  6367. {
  6368. row1.CreateCell(j);
  6369. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  6370. }
  6371. else if (columnNum > 5 && j == columnNum - 5)
  6372. {
  6373. row1.CreateCell(j);
  6374. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_inoutno"].Caption + ":" + FirstDT.Rows[i]["pi_inoutno"].ToString());
  6375. }
  6376. else
  6377. {
  6378. row1.CreateCell(j);
  6379. }
  6380. row1.GetCell(j).CellStyle = style;
  6381. }
  6382. row1 = sheet2.CreateRow(PaintIndex);
  6383. PaintIndex = PaintIndex + 1;
  6384. //第二行添加型号
  6385. for (int j = 0; j < columnNum - 3; j++)
  6386. {
  6387. if (j == 0)
  6388. {
  6389. row1.CreateCell(j).SetCellValue(FirstDT.Columns["pr_orispeccode"].Caption + ":" + FirstDT.Rows[i]["pr_orispeccode"].ToString() + "_"
  6390. + "(" + FirstDT.Rows[i]["me_desc"].ToString() + ")" + FirstDT.Columns["pi_chipouttype"].Caption + ":" + FirstDT.Rows[i]["pi_chipouttype"].ToString());
  6391. }
  6392. else if (j == ShowSizeIndex)
  6393. {
  6394. row1.CreateCell(j);
  6395. row1.Cells[j].SetCellValue(FirstDT.Columns["pr_size"].Caption + ":" + FirstDT.Rows[i]["pr_size"].ToString());
  6396. }
  6397. else if (j > 5 && j == columnNum - 5)
  6398. {
  6399. row1.CreateCell(j);
  6400. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  6401. }
  6402. else if (columnNum > 5 && j == columnNum - 5)
  6403. {
  6404. row1.CreateCell(j);
  6405. row1.Cells[j].SetCellValue(FirstDT.Columns["pi_date"].Caption + ":" + FirstDT.Rows[i]["pi_date"].ToString());
  6406. }
  6407. else
  6408. {
  6409. row1.CreateCell(j);
  6410. }
  6411. row1.GetCell(j).CellStyle = style;
  6412. }
  6413. row1 = sheet2.CreateRow(PaintIndex);
  6414. PaintIndex = PaintIndex + 1;
  6415. //添加列名
  6416. for (int j = 4; j < columnNum; j++)
  6417. {
  6418. row1.CreateCell(j - 4);
  6419. if (NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  6420. {
  6421. }
  6422. else
  6423. {
  6424. row1.Cells[j - 4].CellStyle = styleborder;
  6425. row1.Cells[j - 4].SetCellValue(FirstDT.Columns[j].Caption);
  6426. }
  6427. }
  6428. row1 = sheet2.CreateRow(PaintIndex);
  6429. PaintIndex = PaintIndex + 1;
  6430. }
  6431. //添加数据内容
  6432. ShowColumnCount = 0;
  6433. for (int j = 4; j < columnNum; j++)
  6434. {
  6435. row1.CreateCell(j - 4);
  6436. if (FirstDT.Columns[j].ColumnName == "ch_bluefilm")
  6437. {
  6438. row1.CreateCell(j - 4, CellType.String);
  6439. }
  6440. if (!NotShowColumn.Contains(FirstDT.Columns[j].ColumnName.ToLower()))
  6441. {
  6442. string Data = FirstDT.Rows[i][j].ToString();
  6443. row1.Cells[j - 4].SetCellValue(Data);
  6444. row1.GetCell(j - 4).CellStyle = styleborder;
  6445. if (FirstDT.Columns[j].ColumnName == "num")
  6446. {
  6447. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  6448. sumCount += int.Parse(Data);
  6449. }
  6450. if (FirstDT.Columns[j].ColumnName == "io_qty")
  6451. {
  6452. totalCount += int.Parse(Data);
  6453. row1.Cells[j - 4].SetCellValue(int.Parse(Data));
  6454. }
  6455. ShowColumnCount = ShowColumnCount + 1;
  6456. }
  6457. else
  6458. {
  6459. }
  6460. }
  6461. //添加总计行
  6462. if (i == rowNum - 1)
  6463. {
  6464. row1 = sheet2.CreateRow(PaintIndex);
  6465. PaintIndex = PaintIndex + 1;
  6466. for (int j = 0; j < ShowColumnCount; j++)
  6467. {
  6468. if (j == 0)
  6469. {
  6470. row1.CreateCell(j);
  6471. row1.Cells[j].CellStyle = styleborder;
  6472. row1.Cells[j].SetCellValue(总计);
  6473. }
  6474. else if (j == ShowColumnCount - 2)
  6475. {
  6476. row1.CreateCell(j);
  6477. row1.Cells[j].CellStyle = styleborder;
  6478. row1.Cells[j].SetCellValue(sumCount);
  6479. }
  6480. else if (j == ShowColumnCount - 1)
  6481. {
  6482. row1.CreateCell(j);
  6483. row1.Cells[j].CellStyle = styleborder;
  6484. row1.Cells[j].SetCellValue(totalCount);
  6485. }
  6486. else
  6487. {
  6488. row1.CreateCell(j);
  6489. row1.Cells[j].CellStyle = styleborder;
  6490. }
  6491. }
  6492. }
  6493. }
  6494. //将book的内容写入内存流中返回
  6495. book.Write(ms);
  6496. return ms;
  6497. }
  6498. }
  6499. }