| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195 |
- /*******************************************************************************
- * Copyright(c) 2012 dongke All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:LayoutBox.cs
- * 2.功能描述:票据主控件
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 欧阳涛 2012/09/11 1.00 新建
- *******************************************************************************/
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Printing;
- using System.IO;
- using System.Runtime.InteropServices;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.Security.Cryptography;
- using System.Windows.Forms;
- namespace Dongke.WinForm.Controls.InvoiceLayout
- {
- /// <summary>
- /// 票据模板控件
- /// </summary>
- public partial class LayoutBox : UserControl
- {
- #region 常量
- internal const string ITEMNAME_FIX = "Free";
- #region 保存、读取相关
- // TODO 加密保存 解密读取
- private static readonly byte[] KEY = new byte[] { 106, 240, 243, 74, 29, 163, 145, 29, 39, 65, 118, 96, 247, 237, 40, 121, 116, 10, 14, 50, 139, 117, 244, 163, 193, 190, 184, 66, 8, 185, 78, 73 };
- private static readonly byte[] IV = new byte[] { 26, 122, 25, 28, 97, 211, 152, 32, 223, 110, 120, 242, 170, 35, 96, 93 };
- #endregion 保存、读取相关
- #endregion 常量
- #region 成员变量
- #region Layout相关
- private bool _isDirty; // Layout是否变更
- private short _updateCount; // 更新数量
- private int _newItemID; // 生成新的ItemID
- private LayoutBoxDataBinding _dataBinding; // 数据源绑定
- private object _dataSource; // 数据源
- private string _dataMember; // 数据源名
- private LayoutBoxPrintDataBinding _printDataBinding; // 打印的数据源绑定
- private object _printDataSource; // 打印的数据源
- private string _printDataMember; // 打印的数据源名
- /* Item的显示循序
- * Items PaperArea.Controls
- * Item的显示循序 Index Index
- * 最前面 count-1 0
- * ↓ ↑ ↓
- * ↓ ↑ ↓
- * ↓ ↑ ↓
- * 最背面 0 count-1
- */
- private Comparison<LayoutItem> _comparisonItems; // 排序Item
- private List<LayoutItem> _items; // LayoutBox中的Item集合
- private List<LayoutItem> _selectedItems; // 选择状态的Item集合
- private LayoutMode _layoutMode; // Layout编辑模式
- private ZoomType _zoomType; // Layout缩放模式
- private int _zoom; // Layout缩放比例
- private float _paperHeight; // Layout的纸张的高
- private float _paperWidth; // Layout的纸张的宽
- private DataFormats.Format _clipboardFormat; // 剪贴板数据格式
- private string _backgroundImageName; // 背景图片名
- #endregion Layout相关
- #region Item选择
- private bool _isMouseDownInPaperArea; // 鼠标按下
- private bool _isMouseMoveInPaperArea; // 鼠标移动
- private Rectangle _mouseRect; // 鼠标框选范围
- #endregion Item选择
- #region Item移动
- private int _startX; // 鼠标按下位置X
- private int _startY; // 鼠标按下位置Y
- private int _mouseMoveX; // 鼠标移动位置X
- private int _mouseMoveY; // 鼠标移动位置Y
- private bool _isMouseDown; // 鼠标按下
- private bool _isMouseMove; // 鼠标移动
- private Rectangle[] _downRectangles; // 鼠标按下Item范围
- private Rectangle[] _moveRectangles; // 鼠标移动Item范围
- private bool _isShiftDown = false; // Shift按下
- private bool _isCtrlDown = false; // Ctrl按下
- #endregion Item移动
- #region 打印相关
- private bool _isPrintAreaVisible; // 是否标识打印范围
- private bool _isPrintBackground; // 是否打印背景
- private bool _landscape; // true:横向打印;false:纵向打印
- private float _printOffsetX; // 打印横向偏移
- private float _printOffsetY; // 打印纵向偏移
- //private PrintPreviewDialogEx printPreviewDialogEx;
- private int _numberOfCopies = 1; // 打印份数
- private int _allocationSkipCount = 0; // 分配打印开头跳过的位置数
- private int _allocationNumX = 1; // 分配打印横方向的分配数
- private int _allocationNumY = 1; // 分配打印纵方向的分配数
- private float _allocationVerticalSpace; // 分配打印横方向的间隔
- private float _allocationHorizontalSpace; // 分配打印纵方向的间隔
- private float _marginLeft; // 分配打印左侧余白
- private float _marginRight; // 分配打印右侧余白
- private float _marginTop; // 分配打印上侧余白
- private float _marginBottom; // 分配打印下侧余白
- private PrintType _printType; // 打印类别
- private int _printDataPosition = -1; // 打印数据源位置
- private int _printDataTotal = 0; // 打印数据总数
- private int _printDataCopies = -1; // 打印数据份数
- private int _allocationNum = 0; // 分配打印每页的分配数
- private PrintAction _printAction; // 打印种类
- private RectangleF _rectangleFGreed; // 打印范围
- private float _allOffsetX; // 打印横向偏移
- private float _allOffsetY; // 打印纵向偏移
- private float _printerOffsetX; // 打印横向偏移
- private float _printerOffsetY; // 打印纵向偏移
- #endregion 打印相关
- #region Item相关
- private int _maxItemLeft = 0; // 位置X上限(Pixel)
- private int _maxItemTop = 0; // 位置Y上限(Pixel)
- private int _maxItemWidth = 0; // 尺寸宽上限(Pixel)
- private int _maxItemHeight = 0; // 尺寸高上限(Pixel)
- private int _minItemWidth = 0; // 尺寸幅下限(Pixel)
- private int _minItemHeight = 0; // 尺寸高下限(Pixel)
- private int _pasteCount = 0;
- private RectangleF _lastItemRF = RectangleF.Empty;
- #endregion Item相关
- #region GridItem相关
- private int _currentPageNum = 1; // 当前页码
- private int _printPageNum = 1; // 打印页的当前页码
- private int _totalPageNum = 1; // 总页数
- private DataSet _gridDataSet = null; // GridItem利用的数据源
- #endregion GridItem相关
- #endregion 成员变量
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- public LayoutBox()
- : this(InvoiceLayout.LayoutMode.Preview)
- {
- }
- /// <summary>
- /// 构造函数
- /// </summary>
- public LayoutBox(LayoutMode layoutMode = InvoiceLayout.LayoutMode.Preview)
- {
- this._layoutMode = layoutMode;
- InitializeComponent();
- InitializeLayoutBox();
- //printPreviewDialogEx = new PrintPreviewDialogEx();
- //this.printPreviewDialogEx.AutoScrollMargin = new System.Drawing.Size(0, 0);
- //this.printPreviewDialogEx.AutoScrollMinSize = new System.Drawing.Size(0, 0);
- //this.printPreviewDialogEx.ClientSize = new System.Drawing.Size(400, 300);
- //this.printPreviewDialogEx.Document = this.printDocument;
- //this.printPreviewDialogEx.Enabled = true;
- //this.printPreviewDialogEx.Name = "printPreviewDialogEx";
- //this.printPreviewDialogEx.Visible = false;
- }
- #endregion 构造函数
- #region 属性
- #region Layout
- /// <summary>
- /// Item选择状态变化中
- /// </summary>
- public bool ItemSelectionChanging
- {
- get;
- private set;
- }
- /// <summary>
- /// 一个GridItem
- /// </summary>
- public GridItem OneGridItem
- {
- get;
- private set;
- }
- /// <summary>
- /// 打印纸张
- /// </summary>
- [Browsable(false)]
- public Control PaperArea
- {
- get
- {
- return paperArea;
- }
- }
- /// <summary>
- /// 打印纸张图形范围
- /// </summary>
- [Browsable(false)]
- internal Microsoft.VisualBasic.PowerPacks.ShapeContainer ItemShapeContainer
- {
- get
- {
- return paperArea.ShapeContainer;
- }
- }
- /// <summary>
- /// Item图形集合
- /// </summary>
- [Browsable(false)]
- internal Microsoft.VisualBasic.PowerPacks.ShapeCollection ItemShapes
- {
- get
- {
- return paperArea.ShapeContainer.Shapes;
- }
- }
- /// <summary>
- /// 获得新的ItemID
- /// </summary>
- [Browsable(false)]
- internal int NewItemID
- {
- get
- {
- lock (this)
- {
- return _newItemID++;
- }
- }
- }
- /// <summary>
- /// 获取或设置数据源
- /// </summary>
- [Browsable(true)]
- [Description(" 获取或设置数据源"), Category("LayoutBox")]
- [DefaultValue((string)null), RefreshProperties(RefreshProperties.Repaint), AttributeProvider(typeof(IListSource))]
- public object DataSource
- {
- get
- {
- return _dataSource;
- }
- set
- {
- if (value != _dataSource)
- {
- _dataSource = value;
- if (_layoutMode == LayoutMode.Preview)
- {
- SetDataSource();
- }
- }
- }
- }
- /// <summary>
- /// 获取或设置被用作模块的基表中的数据源名称
- /// </summary>
- [Description("获取或设置被用作模块的基表中的数据源名称"), Category("LayoutBox")]
- [DefaultValue("")]
- public string DataMember
- {
- get
- {
- return _dataMember;
- }
- set
- {
- if (string.IsNullOrEmpty(value))
- {
- value = string.Empty;
- }
- if (!value.Equals(_dataMember))
- {
- _dataMember = value;
- if (_layoutMode == LayoutMode.Preview)
- {
- SetDataMember();
- }
- }
- }
- }
- /// <summary>
- /// 获取数据绑定源,从外部刷新数据源
- /// </summary>
- [Browsable(false)]
- [Description("获取数据绑定源,从外部刷新数据源"), Category("LayoutBox")]
- [DefaultValue((string)null)]
- public BindingSource BindingSource
- {
- get
- {
- if (_layoutMode == LayoutMode.Preview)
- {
- if (_dataBinding != null)
- {
- return _dataBinding.BindingSource;
- }
- }
- return null;
- }
- }
- /// <summary>
- /// 获取LayoutBox的全部Item集合
- /// </summary>
- [Description("获取LayoutBox的全部Item集合"), Category("LayoutBox")]
- [Browsable(false)]
- public List<LayoutItem> Items
- {
- get
- {
- return _items;
- }
- }
- /// <summary>
- /// 获取LayoutBox的全部Item集合
- /// </summary>
- [Description("获取剪贴板的内容"), Category("LayoutBox")]
- public DataFormats.Format ClipboardFormat
- {
- get
- {
- return GetCipboardFormat();
- //return _clipboardFormat;
- }
- }
- /// <summary>
- /// 获取LayoutBox的选择状态的Item集合
- /// </summary>
- [Description("获取LayoutBox的选择状态的Item集合"), Category("LayoutBox")]
- [Browsable(false)]
- public List<LayoutItem> SelectedItems
- {
- get
- {
- return _selectedItems;
- }
- }
- /// <summary>
- /// 获取或设置LayoutBox的编辑模式
- /// </summary>
- [Description("获取或设置LayoutBox的编辑模式"), Category("LayoutBox")]
- [DefaultValue(LayoutMode.Preview)]
- public LayoutMode LayoutMode
- {
- get
- {
- return _layoutMode;
- }
- set
- {
- if (_layoutMode != value)
- {
- if (_layoutMode == LayoutMode.Edit)
- {
- ClearSelection();
- }
- _layoutMode = value;
- if (_layoutMode == LayoutMode.Edit)
- {
- //// TODO
- //if (this._clipboardFormat == null)
- //{
- // _clipboardFormat =
- // DataFormats.GetFormat(typeof(LayoutItem).FullName
- // + "{"
- // + Guid.NewGuid().ToString().ToUpper()
- // + "}");
- //}
- tsmiAllSelect.Enabled = true;
- tsmiBackgroundImage.Enabled = true;
- tsmiPaperSize.Enabled = true;
- paperArea.Click += new System.EventHandler(this.paperArea_Click);
- paperArea.MouseDown += new System.Windows.Forms.MouseEventHandler(this.paperArea_MouseDown);
- paperArea.MouseMove += new System.Windows.Forms.MouseEventHandler(this.paperArea_MouseMove);
- paperArea.MouseUp += new System.Windows.Forms.MouseEventHandler(this.paperArea_MouseUp);
- // TODO Item范围内移动
- paperArea.ShapeContainer.KeyDown += new KeyEventHandler(RectTracker_KeyDown);
- paperArea.ShapeContainer.KeyUp += new KeyEventHandler(RectTracker_KeyUp);
- paperArea.ShapeContainer.MouseDown += new MouseEventHandler(RectTracker_MouseDown);
- paperArea.ShapeContainer.MouseMove += new MouseEventHandler(RectTracker_MouseMove);
- paperArea.ShapeContainer.MouseUp += new MouseEventHandler(RectTracker_MouseUp);
- paperArea.ShapeContainer.LostFocus += new EventHandler(RectTracker_LostFocus);
- }
- else
- {
- tsmiAllSelect.Enabled = false;
- tsmiBackgroundImage.Enabled = false;
- tsmiPaperSize.Enabled = false;
- paperArea.Click -= new System.EventHandler(this.paperArea_Click);
- paperArea.MouseDown -= new System.Windows.Forms.MouseEventHandler(this.paperArea_MouseDown);
- paperArea.MouseMove -= new System.Windows.Forms.MouseEventHandler(this.paperArea_MouseMove);
- paperArea.MouseUp -= new System.Windows.Forms.MouseEventHandler(this.paperArea_MouseUp);
- // TODO Item范围内移动
- paperArea.ShapeContainer.KeyDown -= new KeyEventHandler(RectTracker_KeyDown);
- paperArea.ShapeContainer.KeyUp -= new KeyEventHandler(RectTracker_KeyUp);
- paperArea.ShapeContainer.MouseDown -= new MouseEventHandler(RectTracker_MouseDown);
- paperArea.ShapeContainer.MouseMove -= new MouseEventHandler(RectTracker_MouseMove);
- paperArea.ShapeContainer.MouseUp -= new MouseEventHandler(RectTracker_MouseUp);
- paperArea.ShapeContainer.LostFocus -= new EventHandler(RectTracker_LostFocus);
- if (_layoutMode == LayoutMode.Preview)
- {
- SetDataSource();
- SetDataMember();
- SetPrintDataSource();
- SetPrintDataMember();
- }
- }
- }
- }
- }
- /// <summary>
- /// 获取或设置LayoutBox的缩放模式
- /// </summary>
- [Description("获取或设置LayoutBox的缩放模式"), Category("LayoutBox")]
- [DefaultValue(ZoomType.Specify)]
- public ZoomType ZoomType
- {
- get
- {
- return _zoomType;
- }
- set
- {
- if (_zoomType != value)
- {
- _zoomType = value;
- if (value != ZoomType.Whole)
- {
- paperBox.AutoScroll = true;
- // 改变纸张大小
- ChangePaperSize();
- // 设置全部Item的比例
- ZoomAllItems();
- }
- else
- {
- paperBox.AutoScroll = false;
- // 全部Item显示
- InitializeZoom();
- }
- if (ZoomChanged != null)
- {
- ZoomChanged(this, EventArgs.Empty);
- }
- }
- }
- }
- /// <summary>
- /// 获取或设置LayoutBox的缩放比例(%)
- /// </summary>
- [Description("获取或设置LayoutBox的缩放比例"), Category("LayoutBox")]
- [DefaultValue(100)]
- public int Zoom
- {
- get
- {
- return _zoom;
- }
- set
- {
- if (0 <= value && _zoom != value)
- {
- _zoom = value;
- if (_zoomType == ZoomType.Specify)
- {
- // 改变纸张大小
- ChangePaperSize();
- // 设置全部Item的比例
- ZoomAllItems();
- if (ZoomChanged != null)
- {
- ZoomChanged(this, EventArgs.Empty);
- }
- }
- else
- {
- ZoomType = ZoomType.Specify;
- }
- }
- }
- }
- /// <summary>
- /// 获取或设置纸张的高(mm)
- /// </summary>
- [Description("获取或设置纸张的高"), Category("LayoutBox")]
- [DefaultValue(297f)]
- public float PaperHeight
- {
- get
- {
- return _paperHeight;
- }
- set
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return;
- }
- SetPaperAreaSize(_paperWidth, value);
- }
- }
- /// <summary>
- /// 获取或设置纸张的宽(mm)
- /// </summary>
- [Description("获取或设置纸张的宽"), Category("LayoutBox")]
- [DefaultValue(210f)]
- public float PaperWidth
- {
- get
- {
- return _paperWidth;
- }
- set
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return;
- }
- SetPaperAreaSize(value, _paperHeight);
- }
- }
- /// <summary>
- /// 获取纸张的背景图片名
- /// </summary>
- [Description("获取或设置纸张的背景图片"), Category("LayoutBox")]
- [DefaultValue("")]
- public string BackgroundImageName
- {
- get
- {
- return _backgroundImageName;
- }
- }
- /// <summary>
- /// 获取或设置纸张的背景图片
- /// </summary>
- [Description("获取或设置纸张的背景图片"), Category("LayoutBox")]
- [DefaultValue((string)null)]
- public override Image BackgroundImage
- {
- get
- {
- return paperArea.BackgroundImage;
- }
- set
- {
- paperArea.BackgroundImage = value;
- _backgroundImageName = string.Empty;
- }
- }
- /// <summary>
- /// 获取LayoutBox的布局是否已经改变
- /// </summary>
- //[Description("获取LayoutBox的布局是否已经改变"), Category("LayoutBox")]
- [Browsable(false)]
- public bool Dirty
- {
- get
- {
- return _isDirty;
- }
- internal set
- {
- SetDitry(value);
- }
- }
- /// <summary>
- /// 获取或设置是否加密保存、读取流
- /// </summary>
- [Description("获取或设置是否加密保存、读取流"), Category("LayoutBox")]
- [DefaultValue(true)]
- public bool CryptoStream = true;
- #endregion Layout
- #region 打印相关
- /// <summary>
- /// 获取或设置打印数据源
- /// </summary>
- [Browsable(true)]
- [Description("获取或设置打印数据源"), Category("打印相关")]
- [DefaultValue((string)null), RefreshProperties(RefreshProperties.Repaint), AttributeProvider(typeof(IListSource))]
- public object PrintDataSource
- {
- get
- {
- return _printDataSource;
- }
- set
- {
- if (value != _printDataSource)
- {
- _printDataSource = value;
- if (_layoutMode == LayoutMode.Preview)
- {
- SetPrintDataSource();
- }
- }
- }
- }
- /// <summary>
- /// 获取或设置打印数据源
- /// </summary>
- [Description("获取或设置打印数据源"), Category("打印相关")]
- [DefaultValue("")]
- public string PrintDataMember
- {
- get
- {
- return _printDataMember;
- }
- set
- {
- if (string.IsNullOrEmpty(value))
- {
- value = string.Empty;
- }
- if (!value.Equals(_printDataMember))
- {
- _printDataMember = value;
- if (_layoutMode == LayoutMode.Preview)
- {
- SetPrintDataMember();
- }
- }
- }
- }
- /// <summary>
- /// 获取或设置是否用绿色虚线标识出打印区域
- /// </summary>
- [Description("获取或设置是否用绿色虚线标识出打印区域"), Category("打印相关")]
- [DefaultValue(true)]
- public bool PrintAreaVisible
- {
- get
- {
- return _isPrintAreaVisible;
- }
- set
- {
- if (_isPrintAreaVisible != value)
- {
- _isPrintAreaVisible = value;
- _isDirty = true;
- }
- }
- }
- /// <summary>
- /// 获取或设置一个值,该值指示是否打印背景
- /// </summary>
- [Description("获取或设置一个值,该值指示是否打印背景"), Category("打印相关")]
- [DefaultValue(false)]
- public bool PrintBackground
- {
- get
- {
- return _isPrintBackground;
- }
- set
- {
- if (_isPrintBackground != value)
- {
- _isPrintBackground = value;
- _isDirty = true;
- }
- }
- }
- /// <summary>
- /// 获取或设置一个值,该值指示是否在横向或纵向的纸张打印页面
- /// </summary>
- [Description("获取或设置一个值,该值指示是否在横向或纵向的纸张时打印页面\r\n打印横向的页面为true;否则为false。默认是由打印机决定。"), Category("打印相关")]
- [DefaultValue(false)]
- public bool Landscape
- {
- get
- {
- return _landscape;
- }
- set
- {
- printDocument.DefaultPageSettings.Landscape = value;
- _landscape = value;
- }
- }
- /// <summary>
- /// 获取或设置打印纸张的大小
- /// </summary>
- [Description("获取或设置打印纸张的大小"), Category("LayoutBox")]
- [AmbientValue(typeof(Size), "0, 0")]
- [Browsable(false)]
- [DefaultValue((string)null)]
- public PaperSize PaperSize
- {
- get
- {
- return printDocument.PrinterSettings.DefaultPageSettings.PaperSize;
- }
- set
- {
- printDocument.PrinterSettings.DefaultPageSettings.PaperSize = value;
- }
- }
- /// <summary>
- /// Defines a reusable object that sends output to a printer, when printing from a Windows Forms application
- /// </summary>
- [Description("Defines a reusable object that sends output to a printer, when printing from a Windows Forms application"), Category("打印相关")]
- [Browsable(false)]
- public PrintDocument PrintDocument
- {
- get
- {
- return printDocument;
- }
- }
- /// <summary>
- /// 获取或设置打印机的配置信息
- /// </summary>
- [Description("获取或设置打印机的配置信息"), Category("打印相关")]
- [Browsable(false)]
- [DefaultValue((string)null)]
- public PrinterSettings PrinterSettings
- {
- get
- {
- return printDocument.PrinterSettings;
- }
- set
- {
- printDocument.PrinterSettings = value;
- _landscape = printDocument.PrinterSettings.DefaultPageSettings.Landscape;
- }
- }
- /// <summary>
- /// 获取或设置水平方向打印偏移(mm)
- /// </summary>
- [Description("获取或设置水平方向打印偏移"), Category("打印相关")]
- [DefaultValue(0f)]
- public float PrintOffsetX
- {
- get
- {
- return _printOffsetX;
- }
- set
- {
- _printOffsetX = value;
- }
- }
- /// <summary>
- /// 获取或设置垂直方向打印偏移(mm)
- /// </summary>
- [Description("获取或设置垂直方向打印偏移"), Category("打印相关")]
- [DefaultValue(0f)]
- public float PrintOffsetY
- {
- get
- {
- return _printOffsetY;
- }
- set
- {
- _printOffsetY = value;
- }
- }
- /// <summary>
- /// 获取或设置分配打印时,水平方向的分配数
- /// </summary>
- [Description("获取或设置分配打印时,水平方向的分配数"), Category("打印相关")]
- [DefaultValue(1)]
- public int AllocationNumX
- {
- get
- {
- return _allocationNumX;
- }
- set
- {
- if (0 < value)
- {
- _allocationNumX = value;
- }
- else
- {
- _allocationNumX = 1;
- }
- }
- }
- /// <summary>
- /// 获取或设置分配打印时,垂直方向的分配数
- /// </summary>
- [Description("获取或设置分配打印时,垂直方向的分配数"), Category("打印相关")]
- [DefaultValue(1)]
- public int AllocationNumY
- {
- get
- {
- return _allocationNumY;
- }
- set
- {
- if (0 < value)
- {
- _allocationNumY = value;
- }
- else
- {
- _allocationNumY = 1;
- }
- }
- }
- /// <summary>
- /// 获取或设置分配打印时,左侧余白(mm)
- /// </summary>
- [Description("获取或设置分配打印时,左侧余白(mm)"), Category("打印相关")]
- [DefaultValue(0f)]
- public float MarginLeft
- {
- get
- {
- return _marginLeft;
- }
- set
- {
- _marginLeft = value;
- }
- }
- /// <summary>
- /// 获取或设置分配打印时,右侧余白(mm)
- /// </summary>
- [Description("获取或设置分配打印时,右侧余白(mm)"), Category("打印相关")]
- [DefaultValue(0f)]
- public float MarginRight
- {
- get
- {
- return _marginRight;
- }
- set
- {
- _marginRight = value;
- }
- }
- /// <summary>
- /// 获取或设置分配打印时,上侧余白(mm)
- /// </summary>
- [Description("获取或设置分配打印时,上侧余白(mm)"), Category("打印相关")]
- [DefaultValue(0f)]
- public float MarginTop
- {
- get
- {
- return _marginTop;
- }
- set
- {
- _marginTop = value;
- }
- }
- /// <summary>
- /// 获取或设置分配打印时,下侧余白(mm)
- /// </summary>
- [Description("获取或设置分配打印时,下侧余白(mm)"), Category("打印相关")]
- [DefaultValue(0f)]
- public float MarginBottom
- {
- get
- {
- return _marginBottom;
- }
- set
- {
- _marginBottom = value;
- }
- }
- /// <summary>
- /// 获取或设置分配打印时,上下间隔(mm)
- /// </summary>
- [Description("获取或设置分配打印时,上下间隔(mm)"), Category("打印相关")]
- [DefaultValue(0f)]
- public float AllocationVirticalSpace
- {
- get
- {
- return _allocationVerticalSpace;
- }
- set
- {
- if (value < 0)
- {
- _allocationVerticalSpace = 0;
- }
- else
- {
- _allocationVerticalSpace = value;
- }
- }
- }
- /// <summary>
- /// 获取或设置分配打印时,左右间隔(mm)
- /// </summary>
- [Description("获取或设置分配打印时,左右间隔(mm)"), Category("打印相关")]
- [DefaultValue(0f)]
- public float AllocationHorizontalSpace
- {
- get
- {
- return _allocationHorizontalSpace;
- }
- set
- {
- if (value < 0)
- {
- _allocationHorizontalSpace = 0;
- }
- else
- {
- _allocationHorizontalSpace = value;
- }
- }
- }
- /// <summary>
- /// 获取或设置打印份数
- /// </summary>
- [Description("获取或设置打印份数"), Category("打印相关")]
- [DefaultValue(1)]
- public int NumberOfCopies
- {
- get
- {
- return _numberOfCopies;
- }
- set
- {
- if (0 < value)
- {
- _numberOfCopies = value;
- }
- else
- {
- _numberOfCopies = 1;
- }
- }
- }
- /// <summary>
- /// 获取或设置分配打印时,开头跳过的位置数
- /// </summary>
- [Description("获取或设置分配打印时,开头跳过的位置数"), Category("打印相关")]
- [DefaultValue(0)]
- public int AllocationSkipCount
- {
- get
- {
- return _allocationSkipCount;
- }
- set
- {
- if (0 < value)
- {
- _allocationSkipCount = value;
- }
- else
- {
- _allocationSkipCount = 0;
- }
- }
- }
- #endregion 打印相关
- #region Item相关
- /// <summary>
- /// 位置X上限(Pixel)
- /// </summary>
- [Browsable(false)]
- internal int MaxItemLeft
- {
- get
- {
- return _maxItemLeft;
- }
- }
- /// <summary>
- /// 位置Y上限(Pixel)
- /// </summary>
- [Browsable(false)]
- internal int MaxItemTop
- {
- get
- {
- return _maxItemTop;
- }
- }
- /// <summary>
- /// 尺寸宽上限(Pixel)
- /// </summary>
- [Browsable(false)]
- internal int MaxItemWidth
- {
- get
- {
- return _maxItemWidth;
- }
- }
- /// <summary>
- /// 尺寸高上限(Pixel)
- /// </summary>
- [Browsable(false)]
- internal int MaxItemHeight
- {
- get
- {
- return _maxItemHeight;
- }
- }
- /// <summary>
- ///尺寸宽下限(Pixel)
- /// </summary>
- [Browsable(false)]
- internal int MinItemWidth
- {
- get
- {
- return _minItemWidth;
- }
- }
- /// <summary>
- /// 尺寸高下限(Pixel)
- /// </summary>
- [Browsable(false)]
- internal int MinItemHeight
- {
- get
- {
- return _minItemHeight;
- }
- }
- #endregion Item相关
- #endregion 属性
- #region public函数
- #region 保存、读取相关
- /// <summary>
- /// 从模版中读取Layout
- /// </summary>
- /// <param name="bytes">布局模版</param>
- /// <returns>读取成功true;读取失败false</returns>
- public bool ReadLayout(byte[] bytes)
- {
- MemoryStream memoryStream = null;
- if (bytes != null && 0 < bytes.Length)
- {
- memoryStream = new MemoryStream(bytes);
- memoryStream.Position = 0;
- }
- return ReadLayout(memoryStream);
- }
- /// <summary>
- /// 保存Layout到布局模版
- /// </summary>
- /// <returns>布局模版</returns>
- public byte[] WriteLayout()
- {
- MemoryStream memoryStream = new MemoryStream();
- if (WriteLayout(memoryStream))
- {
- return memoryStream.ToArray();
- }
- return null;
- }
- /// <summary>
- /// 从模版中读取Layout
- /// </summary>
- /// <param name="stream">布局模版</param>
- /// <returns>读取成功true;读取失败false</returns>
- public bool ReadLayout(Stream stream)
- {
- // TODO 异常分析
- int err_level = 0;
- try
- {
- if (stream == null)
- {
- // 清除Layout布局
- ClearLayoutBox();
- //paperArea.Refresh();
- return true;
- }
- err_level = 1;
- // TODO
- if (_clipboardFormat != null)
- {
- this.ClearClipboard();
- //if (Clipboard.ContainsData(_clipboardFormat.Name))
- //{
- // CopyToClipboard(_clipboardFormat.Name, null);
- //}
- //_clipboardFormat =
- // DataFormats.GetFormat(typeof(LayoutItem).FullName
- // + "{"
- // + Guid.NewGuid().ToString().ToUpper()
- // + "}");
- }
- err_level = 2;
- _lastItemRF = RectangleF.Empty;
- _mouseRect = Rectangle.Empty;
- SetDitry(false);
- _selectedItems.Clear();
- err_level = 3;
- foreach (LayoutItem item in _items)
- {
- if (item.Frame != null)
- {
- item.Frame.Dispose();
- item.Frame = null;
- }
- item.Selected = false;
- item.Dispose();
- }
- _items.Clear();
- err_level = 4;
- // 反序列化
- BinaryFormatter formatter = new BinaryFormatter();
- PropertyOfLayoutBox propertyOflayoutBox = null;
- // TODO 解密读取
- if (CryptoStream)
- {
- Rijndael age = Rijndael.Create();
- CryptoStream cStream = new CryptoStream(stream,
- age.CreateDecryptor(KEY, IV),
- CryptoStreamMode.Read);
- propertyOflayoutBox = (PropertyOfLayoutBox)formatter.Deserialize(cStream);
- }
- else
- {
- propertyOflayoutBox = (PropertyOfLayoutBox)formatter.Deserialize(stream);
- }
- err_level = 5;
- _lastItemRF = propertyOflayoutBox.LastItemRF;
- _newItemID = propertyOflayoutBox.NewItemID;
- _paperHeight = propertyOflayoutBox.PaperHeight;
- _paperWidth = propertyOflayoutBox.PaperWidth;
- if (_zoomType != ZoomType.Whole)
- {
- ChangePaperSize();
- }
- else
- {
- InitializeZoom();
- }
- err_level = 6;
- paperArea.BackgroundImage = propertyOflayoutBox.BackgroundImage;
- _backgroundImageName = propertyOflayoutBox.BackgroundImageName;
- _isPrintBackground = propertyOflayoutBox.PrintBackground;
- _isPrintAreaVisible = propertyOflayoutBox.PrintAreaVisible;
- ArrayList items = propertyOflayoutBox.Items;
- if (items != null && 0 < items.Count)
- {
- foreach (LayoutItem item in items)
- {
- item.Init(this, false);
- if (item.ItemType == ItemType.Grid)
- {
- this.OneGridItem = item as GridItem;
- }
- // TODO
- if (item is TextItem)
- {
- TextItem ttt = (item as TextItem);
- if (ttt.ItemCode == "OUTONLYCODE2")
- {
- ttt.ItemCode = "OUTONLYCODE2_HTTP";
- ttt.DataMember = "WaiterCodeHttp";
- ttt.ItemSample = "https://hap.hegii.com/jump?state=productInfo-F01020300100015020181105003N";
- ttt.DisplayValue = ttt.ItemSample;
- }
- }
- }
- }
- err_level = 7;
- paperArea.Select();
- RefreshItemsBound();
- //paperArea.Refresh();
- return true;
- }
- catch (Exception ex)
- {
- Dongke.IBOSS.PRD.Basics.Library.OutputLog.TraceLog(Dongke.IBOSS.PRD.Basics.Library.LogPriority.Debug,
- "PrintBarcode --- " + err_level, ex.ToString(),
- DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff"),
- Dongke.IBOSS.PRD.Basics.Library.LocalPath.LogExePath + @"printdebug\");
- throw ex;
- }
- }
- /// <summary>
- /// 保存Layout到布局模版
- /// </summary>
- /// <param name="stream">布局模版</param>
- /// <returns>保存成功true;保存失败false</returns>
- public bool WriteLayout(Stream stream)
- {
- PropertyOfLayoutBox propertyOflayoutBox = new PropertyOfLayoutBox();
- propertyOflayoutBox.LastItemRF = _lastItemRF;
- propertyOflayoutBox.NewItemID = _newItemID;
- propertyOflayoutBox.PaperHeight = _paperHeight;
- propertyOflayoutBox.PaperWidth = _paperWidth;
- propertyOflayoutBox.BackgroundImage = paperArea.BackgroundImage;
- propertyOflayoutBox.BackgroundImageName = _backgroundImageName;
- propertyOflayoutBox.PrintBackground = _isPrintBackground;
- propertyOflayoutBox.PrintAreaVisible = _isPrintAreaVisible;
- propertyOflayoutBox.Items = new ArrayList(_items);
- // 序列化
- BinaryFormatter formatter = new BinaryFormatter();
- // TODO 加密保存
- if (CryptoStream)
- {
- Rijndael age = Rijndael.Create();
- CryptoStream cStream = new CryptoStream(stream,
- age.CreateEncryptor(KEY, IV),
- CryptoStreamMode.Write);
- formatter.Serialize(cStream, propertyOflayoutBox);
- cStream.FlushFinalBlock();
- }
- else
- {
- formatter.Serialize(stream, propertyOflayoutBox);
- }
- return true;
- }
- /// <summary>
- /// 根据指定的ItemType,创建一个新Item对象
- /// </summary>
- /// <param name="itemType">ItemType的枚举值,表示创建的项目类型</param>
- /// <param name="isShowDialog">是否显示属性设置对话框</param>
- /// <returns>创建的新Item对象</returns>
- public LayoutItem NewItem(ItemType itemType, bool isShowDialog)
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return null;
- }
- LayoutItem item = null;
- switch (itemType)
- {
- case ItemType.Text:
- item = NewTextItem(isShowDialog);
- break;
- case ItemType.Image:
- item = NewImageItem(isShowDialog);
- break;
- case ItemType.Rectangle:
- item = NewRectangleItem(isShowDialog);
- break;
- case ItemType.Ellipse:
- item = NewEllipseItem(isShowDialog);
- break;
- case ItemType.Grid:
- if (OneGridItem != null)
- {
- return null;
- }
- item = NewGridItem(isShowDialog);
- OneGridItem = item as GridItem;
- break;
- case ItemType.PageNum:
- item = NewPageNumItem(isShowDialog);
- break;
- case ItemType.TotalText:
- item = NewTotalTextItem(isShowDialog);
- break;
- case ItemType.Barcode:
- item = NewBarcodeItem(isShowDialog);
- break;
- case ItemType.QRcode:
- item = NewQRcodeItem(isShowDialog);
- break;
- case ItemType.LinearGraph:
- item = NewLinearGraphItem(isShowDialog);
- break;
- default:
- return null;
- }
- if (item != null)
- {
- _lastItemRF.X = item.Left;
- _lastItemRF.Y = item.Top;
- if (_lastItemRF.Width < item.Width)
- {
- _lastItemRF.Width = item.Width;
- }
- _lastItemRF.Height = item.Height;
- _isDirty = true;
- SetItemChangedArgs(item, ItemChangeType.Added);
- }
- return item;
- }
- #endregion 保存、读取相关
- #region Item操作相关
- /// <summary>
- /// 根据ItemID,获取Item
- /// </summary>
- /// <param name="itemID">ItemID</param>
- /// <returns>Item</returns>
- public LayoutItem GetItem(int itemID)
- {
- foreach (LayoutItem item in _items)
- {
- if (item.ID == itemID)
- {
- return item;
- }
- }
- return null;
- }
- /// <summary>
- /// 根据指定的ItemType,获取Item
- /// </summary>
- /// <param name="itemType">ItemType</param>
- /// <returns>Item</returns>
- public LayoutItem[] GetItems(ItemType itemType)
- {
- //var q = from item in _items where item.ItemType ==itemType select item;
- Predicate<LayoutItem> isPrime = delegate(LayoutItem item)
- {
- return (item.ItemType == itemType) ? true : false;
- };
- return _items.FindAll(isPrime).ToArray();
- }
- /// <summary>
- /// 改变指定Item的选择状态
- /// </summary>
- /// <param name="index">Item在Item集合中的索引</param>
- /// <param name="value">Item的选择状态,选中为true;未选中为true</param>
- public void SelectItem(int index, bool value)
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return;
- }
- if (index < 0 || index >= Items.Count)
- {
- return;
- }
- LayoutItem item = _items[index];
- SelectItemMultiple(item, value);
- }
- /// <summary>
- /// 改变指定Item的选择状态
- /// </summary>
- /// <param name="indexes">Item在Item集合中的索引</param>
- /// <param name="value">Item的选择状态,选中为true;未选中为true</param>
- public void SelectItems(int[] indexes, bool value)
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return;
- }
- List<LayoutItem> items = new List<LayoutItem>();
- foreach (int index in indexes)
- {
- if (index < 0 || Items.Count <= index)
- {
- continue;
- }
- items.Add(Items[index]);
- }
- if (0 < items.Count)
- {
- SelectItemsSingle(items.ToArray(), value);
- }
- }
- /// <summary>
- /// 改变指定Item的选择状态
- /// </summary>
- /// <param name="item">Item</param>
- /// <param name="value">Item的选择状态,选中为true;未选中为true</param>
- public void SelectItemSingle(LayoutItem item, bool value)
- {
- if (_layoutMode != LayoutMode.Edit || item == null)
- {
- return;
- }
- bool isChanging = false;
- ItemSelectionChanging = true;
- if (value)
- {
- if (0 < _selectedItems.Count)
- {
- LayoutItem[] selectedItems = _selectedItems.ToArray();
- foreach (LayoutItem selectedItem in selectedItems)
- {
- if (item == null || item.ID == selectedItem.ID)
- {
- continue;
- }
- isChanging = true;
- selectedItem.Selected = false;
- _selectedItems.Remove(selectedItem);
- if (selectedItem.Frame != null)
- {
- selectedItem.Frame.Dispose();
- selectedItem.Frame = null;
- }
- SetItemSelectionChangedArgs(selectedItem, false);
- }
- }
- }
- if (value != item.Selected)
- {
- if (value)
- {
- item.Frame = new ItemFrame(item);
- item.Selected = true;
- _selectedItems.Add(item);
- _selectedItems.Sort(_comparisonItems);
- paperArea.Controls.Add(item.Frame);
- item.Frame.BringToFront();
- }
- else
- {
- item.Selected = false;
- _selectedItems.Remove(item);
- if (item.Frame != null)
- {
- item.Frame.Dispose();
- item.Frame = null;
- }
- }
- isChanging = true;
- SetItemSelectionChangedArgs(item, value);
- }
- ItemSelectionChanging = false;
- if (isChanging)
- {
- if (UserSelectionChanged != null)
- {
- UserSelectionChanged(this, EventArgs.Empty);
- }
- }
- }
- /// <summary>
- /// 改变指定Item的选择状态
- /// </summary>
- /// <param name="items">Item</param>
- /// <param name="value">Item的选择状态,选中为true;未选中为true</param>
- public void SelectItemsSingle(LayoutItem[] items, bool value)
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return;
- }
- if (items == null || items.Length <= 0)
- {
- return;
- }
- bool isChanging = false;
- ItemSelectionChanging = true;
- if (value)
- {
- if (0 < _selectedItems.Count)
- {
- LayoutItem[] selecteditems = _selectedItems.ToArray();
- foreach (LayoutItem selecteditem in selecteditems)
- {
- if (selecteditem == null)
- {
- continue;
- }
- foreach (LayoutItem item in items)
- {
- if (item == null || item.ID == selecteditem.ID)
- {
- continue;
- }
- isChanging = true;
- selecteditem.Selected = false;
- _selectedItems.Remove(selecteditem);
- if (selecteditem.Frame != null)
- {
- selecteditem.Frame.Dispose();
- selecteditem.Frame = null;
- }
- SetItemSelectionChangedArgs(selecteditem, false);
- }
- }
- }
- }
- foreach (LayoutItem item in items)
- {
- SelectItemMultiple(item, value, ref isChanging);
- }
- ItemSelectionChanging = false;
- if (isChanging)
- {
- if (UserSelectionChanged != null)
- {
- UserSelectionChanged(this, EventArgs.Empty);
- }
- }
- }
- /// <summary>
- /// 改变指定Item的选择状态
- /// </summary>
- /// <param name="item">Item</param>
- /// <param name="value">Item的选择状态,选中为true;未选中为true</param>
- public void SelectItemMultiple(LayoutItem item, bool value)
- {
- bool isChanging = false;
- ItemSelectionChanging = true;
- SelectItemMultiple(item, value, ref isChanging);
- ItemSelectionChanging = false;
- if (isChanging)
- {
- if (UserSelectionChanged != null)
- {
- UserSelectionChanged(this, EventArgs.Empty);
- }
- }
- }
- /// <summary>
- /// 改变指定Item的选择状态
- /// </summary>
- /// <param name="item">Item</param>
- /// <param name="value">Item的选择状态,选中为true;未选中为true</param>
- /// <param name="isChanging">是否改变</param>
- private void SelectItemMultiple(LayoutItem item, bool value, ref bool isChanging)
- {
- if (_layoutMode != LayoutMode.Edit || item == null)
- {
- return;
- }
- if (value != item.Selected)
- {
- if (value)
- {
- item.Frame = new ItemFrame(item);
- item.Selected = true;
- _selectedItems.Add(item);
- _selectedItems.Sort(_comparisonItems);
- paperArea.Controls.Add(item.Frame);
- item.Frame.BringToFront();
- }
- else
- {
- item.Selected = false;
- _selectedItems.Remove(item);
- if (item.Frame != null)
- {
- item.Frame.Dispose();
- item.Frame = null;
- }
- }
- isChanging = true;
- SetItemSelectionChangedArgs(item, value);
- }
- }
- /// <summary>
- /// 改变指定Item的选择状态
- /// </summary>
- /// <param name="items">Item</param>
- /// <param name="value">Item的选择状态,选中为true;未选中为true</param>
- public void SelectItemsMultiple(LayoutItem[] items, bool value)
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return;
- }
- if (items == null || items.Length <= 0)
- {
- return;
- }
- bool isChanging = false;
- ItemSelectionChanging = true;
- foreach (LayoutItem item in items)
- {
- SelectItemMultiple(item, value, ref isChanging);
- }
- ItemSelectionChanging = false;
- if (isChanging)
- {
- if (UserSelectionChanged != null)
- {
- UserSelectionChanged(this, EventArgs.Empty);
- }
- }
- }
- /// <summary>
- /// 取消所有选择的项目
- /// </summary>
- public void ClearSelection()
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return;
- }
- bool isChanging = false;
- ItemSelectionChanging = true;
- if (0 < _selectedItems.Count)
- {
- LayoutItem[] selectedItems = _selectedItems.ToArray();
- foreach (LayoutItem selectedItem in selectedItems)
- {
- if (selectedItem == null)
- {
- continue;
- }
- isChanging = true;
- selectedItem.Selected = false;
- _selectedItems.Remove(selectedItem);
- if (selectedItem.Frame != null)
- {
- selectedItem.Frame.Dispose();
- selectedItem.Frame = null;
- }
- SetItemSelectionChangedArgs(selectedItem, false);
- }
- }
- ItemSelectionChanging = false;
- if (isChanging)
- {
- if (UserSelectionChanged != null)
- {
- UserSelectionChanged(this, EventArgs.Empty);
- }
- }
- }
- /// <summary>
- /// 剪切选中的Item到剪切板
- /// </summary>
- public void CutItem()
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return;
- }
- _pasteCount = 0;
- if (0 < _selectedItems.Count)
- {
- CopyToClipboard(new ArrayList(_selectedItems));
- DeleteItem();
- _isDirty = true;
- }
- }
- /// <summary>
- /// 粘贴Item到LayoutBox
- /// </summary>
- public void PasteItem()
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return;
- }
- object objectItems = GetFromClipboard();
- if (objectItems == null)
- {
- _pasteCount = 0;
- return;
- }
- ArrayList items = objectItems as ArrayList;
- if (items == null || items.Count <= 0)
- {
- _pasteCount = 0;
- return;
- }
- List<LayoutItem> layoutItems = new List<LayoutItem>();
- _pasteCount++;
- foreach (LayoutItem item in items)
- {
- if (item == null || item is GridItem)
- {
- continue;
- }
- int id = item.ID;
- TextItem textItem = null;
- string dataMember = null;
- string defaultItemName = null;
- string textItemName = null;
- if (item.ItemType == ItemType.Text || item.ItemType == ItemType.TotalText)
- {
- textItem = item as TextItem;
- if (textItem != null)
- {
- dataMember = textItem.DataMember;
- defaultItemName = textItem.DefaultItemName;
- textItemName = textItem.TextItemName;
- }
- }
- item.Init(this, true);
- if (textItem != null)
- {
- textItem.DataMember = dataMember;
- textItem.DefaultItemName = defaultItemName;
- textItem.TextItemName = textItemName;
- }
- //int top = item.ShapeBounds.Top + (item.ShapeBounds.Height + 2) * _pasteCount;
- // 下移60mm
- //int top = item.ShapeBounds.Top + 227;
- ////item.ResetItemLocation(item.ShapeBounds.Left, top);
- //设置图形像素坐标时刷新毫米坐标
- //item.MoveItem(item.ShapeBounds.Left, top);
- // 下移5mm
- item.Top += 5;
- _isDirty = true;
- layoutItems.Add(item);
- if (this.UserAddedItem != null)
- {
- ItemChangedEventArgs e = new ItemChangedEventArgs();
- e.Item = item;
- e.ChangedType = ItemChangeType.Added;
- e.ItemID = item.ID;
- this.UserAddedItem(this, e);
- }
- SetItemChangedArgs(item, ItemChangeType.Added);
- }
- // 粘贴的新Item为选择状态
- if (1 == layoutItems.Count)
- {
- SelectItemSingle(layoutItems[0], true);
- }
- else if (1 < layoutItems.Count)
- {
- ClearSelection();
- SelectItemsMultiple(layoutItems.ToArray(), true);
- }
- }
- /// <summary>
- /// 复制选中的Item到剪切板
- /// </summary>
- public void CopyItem()
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return;
- }
- _pasteCount = 0;
- if (0 < _selectedItems.Count)
- {
- CopyToClipboard(new ArrayList(_selectedItems));
- }
- }
- /// <summary>
- /// 删除选中的Item
- /// </summary>
- public void DeleteItem()
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return;
- }
- if (0 < _selectedItems.Count)
- {
- LayoutItem[] items = _selectedItems.ToArray();
- foreach (LayoutItem item in items)
- {
- ItemChangedEventArgs e = new ItemChangedEventArgs();
- e.Item = item;
- e.ChangedType = ItemChangeType.Deleted;
- e.ItemID = item.ID;
- DeletetItem(item);
- if (this.UserDeletedItem != null)
- {
- this.UserDeletedItem(this, e);
- }
- }
- }
- }
- /// <summary>
- /// 根据ItemID删除Item
- /// </summary>
- /// <param name="itemID">ItemID</param>
- public void DeletetItem(int itemID)
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return;
- }
- LayoutItem item = GetItem(itemID);
- DeletetItem(item);
- }
- /// <summary>
- /// 删除指定的Item
- /// </summary>
- /// <param name="item">item</param>
- public void DeletetItem(LayoutItem item)
- {
- if (_layoutMode != LayoutMode.Edit || item == null)
- {
- return;
- }
- if (item.Selected)
- {
- item.Selected = false;
- _selectedItems.Remove(item);
- if (item.Frame != null)
- {
- item.Frame.Dispose();
- item.Frame = null;
- }
- SetItemSelectionChangedArgs(item, false);
- }
- _items.Remove(item);
- item.Dispose();
- _isDirty = true;
- SetItemChangedArgs(item, ItemChangeType.Deleted);
- }
- /// <summary>
- /// 重绘Item的内容
- /// </summary>
- public void RefreshItems()
- {
- if (_layoutMode == LayoutMode.Preview)
- {
- RefreshItemsCurrentPositionValue();
- }
- }
- /// <summary>
- /// 对齐选定的Item
- /// </summary>
- /// <param name="arrangeType">对齐方式</param>
- public void ArrangeItem(ArrangeType arrangeType)
- {
- if (_layoutMode != LayoutMode.Edit || _selectedItems.Count < 2)
- {
- return;
- }
- switch (arrangeType)
- {
- case ArrangeType.Left:
- ArrangeItemsLeft();
- break;
- case ArrangeType.Right:
- ArrangeItemsRight();
- break;
- case ArrangeType.HorizontalCenter:
- ArrangeItemsHorizontalCenter();
- break;
- case ArrangeType.Top:
- ArrangeItemsTop();
- break;
- case ArrangeType.Bottom:
- ArrangeItemsBottom();
- break;
- case ArrangeType.VerticalCenter:
- ArrangeItemsVerticalCenter();
- break;
- //case ArrangeType.LeftRight:
- // ArrangeItemsLeftRight();
- // break;
- //case ArrangeType.TopBottom:
- // ArrangeItemsTopBottom();
- // break;
- default:
- break;
- }
- }
- /// <summary>
- /// 所有选中的Item的顶部对齐
- /// </summary>
- public void ArrangeItemsTop()
- {
- if (_layoutMode != LayoutMode.Edit || _selectedItems.Count < 2)
- {
- return;
- }
- float minTop = paperArea.Height;
- foreach (LayoutItem item in _selectedItems)
- {
- minTop = Math.Min(item.Top, minTop);
- }
- foreach (LayoutItem item in _selectedItems)
- {
- item.Top = minTop;
- }
- _isDirty = true;
- }
- /// <summary>
- /// 所有选中的Item的底部对齐
- /// </summary>
- public void ArrangeItemsBottom()
- {
- if (_layoutMode != LayoutMode.Edit || _selectedItems.Count < 2)
- {
- return;
- }
- float maxBottom = 0;
- foreach (LayoutItem item in _selectedItems)
- {
- maxBottom = Math.Max(item.Bottom, maxBottom);
- }
- foreach (LayoutItem item in _selectedItems)
- {
- item.Top = maxBottom - item.Height;
- }
- _isDirty = true;
- }
- /// <summary>
- /// 所有选中的Item的左侧对齐
- /// </summary>
- public void ArrangeItemsLeft()
- {
- if (_layoutMode != LayoutMode.Edit || _selectedItems.Count < 2)
- {
- return;
- }
- float minLeft = paperArea.Width;
- foreach (LayoutItem item in _selectedItems)
- {
- minLeft = Math.Min(item.Left, minLeft);
- }
- foreach (LayoutItem item in _selectedItems)
- {
- item.Left = minLeft;
- }
- _isDirty = true;
- }
- /// <summary>
- /// 所有选中的Item的右侧对齐
- /// </summary>
- public void ArrangeItemsRight()
- {
- if (_layoutMode != LayoutMode.Edit || _selectedItems.Count < 2)
- {
- return;
- }
- float maxRight = 0;
- foreach (LayoutItem item in _selectedItems)
- {
- maxRight = Math.Max(item.Right, maxRight);
- }
- foreach (LayoutItem item in _selectedItems)
- {
- item.Left = maxRight - item.Width;
- }
- _isDirty = true;
- }
- /// <summary>
- /// 所有选中的Item的垂直方向中心对齐
- /// </summary>
- public void ArrangeItemsVerticalCenter()
- {
- if (_layoutMode != LayoutMode.Edit || _selectedItems.Count < 2)
- {
- return;
- }
- float minTop = paperArea.Height;
- float maxBottom = 0;
- foreach (LayoutItem item in _selectedItems)
- {
- minTop = Math.Min(item.Top, minTop);
- maxBottom = Math.Max(item.Bottom, maxBottom);
- }
- float center = (minTop + maxBottom) / 2;
- foreach (LayoutItem item in _selectedItems)
- {
- item.Top = center - item.Height / 2;
- }
- _isDirty = true;
- }
- /// <summary>
- /// 所有选中的Item的水平方向中心对齐
- /// </summary>
- public void ArrangeItemsHorizontalCenter()
- {
- if (_layoutMode != LayoutMode.Edit || _selectedItems.Count < 2)
- {
- return;
- }
- float minLeft = paperArea.Width;
- float maxRight = 0;
- foreach (LayoutItem item in _selectedItems)
- {
- minLeft = Math.Min(item.Left, minLeft);
- maxRight = Math.Max(item.Right, maxRight);
- }
- float center = (minLeft + maxRight) / 2;
- foreach (LayoutItem item in _selectedItems)
- {
- item.Left = center - item.Width / 2;
- }
- _isDirty = true;
- }
- /// <summary>
- /// 更改所选Item(Z顺序)的顺序
- /// </summary>
- /// <param name="position">指定的位置MovingPosition的枚举值,Z-顺序</param>
- public void ChangeItemOrder(MovingPosition position)
- {
- if (_layoutMode != LayoutMode.Edit || 0 == _selectedItems.Count)
- {
- return;
- }
- switch (position)
- {
- case MovingPosition.Foremost:
- ChangeItemsOrderForemost();
- break;
- case MovingPosition.Aftermost:
- ChangeItemsOrderAftermost();
- break;
- case MovingPosition.Front:
- ChangeItemsOrderFront();
- break;
- case MovingPosition.Back:
- ChangeItemsOrderBack();
- break;
- default:
- break;
- }
- }
- /// <summary>
- /// 将选定的Item移动到最前面
- /// </summary>
- public void ChangeItemsOrderForemost()
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return;
- }
- int count = _selectedItems.Count;
- if (0 < count)
- {
- foreach (LayoutItem item in _selectedItems)
- {
- paperArea.ShapeContainer.Shapes.SetChildIndex(item.Shape, 0);
- }
- paperArea.ShapeContainer.Refresh();
- _items.Sort(_comparisonItems);
- _isDirty = true;
- }
- }
- /// <summary>
- /// 将选定的Item上移一层
- /// </summary>
- public void ChangeItemsOrderFront()
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return;
- }
- int count = _selectedItems.Count;
- if (0 < count)
- {
- int childIndex = paperArea.ShapeContainer.Shapes.
- GetChildIndex(_selectedItems[count - 1].Shape) - 1;
- childIndex = (childIndex < 0) ? 0 : childIndex;
- foreach (LayoutItem item in _selectedItems)
- {
- paperArea.ShapeContainer.Shapes.SetChildIndex(item.Shape, childIndex);
- }
- paperArea.ShapeContainer.Refresh();
- _items.Sort(_comparisonItems);
- _isDirty = true;
- }
- }
- /// <summary>
- /// 将选定的Item移动到最后面
- /// </summary>
- public void ChangeItemsOrderBack()
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return;
- }
- int count = _selectedItems.Count;
- if (0 < count)
- {
- int childIndex = paperArea.ShapeContainer.Shapes.
- GetChildIndex(_selectedItems[0].Shape) + 1;
- for (int i = count - 1; 0 <= i; i--)
- {
- paperArea.ShapeContainer.Shapes.SetChildIndex(_selectedItems[i].Shape, childIndex);
- }
- paperArea.ShapeContainer.Refresh();
- _items.Sort(_comparisonItems);
- _isDirty = true;
- }
- }
- /// <summary>
- /// 将选定的Item下移一层
- /// </summary>
- public void ChangeItemsOrderAftermost()
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return;
- }
- int count = _selectedItems.Count;
- if (0 < count)
- {
- for (int i = count - 1; 0 <= i; i--)
- {
- paperArea.ShapeContainer.Shapes.SetChildIndex(_selectedItems[i].Shape, int.MaxValue);
- }
- paperArea.ShapeContainer.Refresh();
- _items.Sort(_comparisonItems);
- _isDirty = true;
- }
- }
- /// <summary>
- /// 将LayoutBox的Dirty状态修改成false
- /// 接受之前所有的改变
- /// </summary>
- public void AcceptChange()
- {
- this._isDirty = false;
- }
- #endregion Item操作相关
- #region 设置对话框
- /// <summary>
- /// 显示背景设置的对话框
- /// </summary>
- /// <returns>
- /// DialogResult.OK:设置成功<br/>
- /// DialogResult.Cancel:取消设置<br/>
- /// DialogResult.None:LayoutBox不是编辑模式
- /// </returns>
- public DialogResult ShowBackgroundSettingDialog()
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return DialogResult.None;
- }
- using (BackgroundSetting backgroundSetting = new BackgroundSetting(this))
- {
- DialogResult result = backgroundSetting.ShowDialog();
- if (result == DialogResult.OK)
- {
- _backgroundImageName = backgroundSetting.BackgroundImageName;
- paperArea.BackgroundImage = backgroundSetting.BackgroundImage;
- _isDirty = true;
- }
- return result;
- }
- }
- /// <summary>
- /// 显示纸张设置的对话框
- /// </summary>
- /// <returns>
- /// DialogResult.OK:设置成功<br/>
- /// DialogResult.Cancel:取消设置<br/>
- /// DialogResult.None:LayoutBox不是编辑模式
- /// </returns>
- public DialogResult ShowPaperPropertyDialog()
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return DialogResult.None;
- }
- using (PaperAreaSetting paperSizeSetting = new PaperAreaSetting())
- {
- paperSizeSetting.PaperWidth = _paperWidth;
- paperSizeSetting.PaperHeight = _paperHeight;
- DialogResult result = paperSizeSetting.ShowDialog();
- if (result == DialogResult.OK)
- {
- SetPaperAreaSize(paperSizeSetting.PaperWidth,
- paperSizeSetting.PaperHeight);
- }
- return result;
- }
- }
- /// <summary>
- /// 显示选中Item的属性设置画面
- /// </summary>
- /// <returns>
- /// DialogResult.OK:选中的Item有效,设置成功<br/>
- /// DialogResult.Cancel:选中的Item有效,取消设置<br/>
- /// DialogResult.None:LayoutBox不是编辑模式,或选中的Item不是一个
- /// </returns>
- public DialogResult ShowItemPropertyDialog()
- {
- if (_layoutMode != LayoutMode.Edit || _selectedItems.Count != 1)
- {
- return DialogResult.None;
- }
- LayoutItem item = _selectedItems[0];
- if (item != null)
- {
- return item.ShowItemPropertyDialog();
- }
- return DialogResult.None;
- }
- #endregion 设置对话框
- #region 打印相关
- /// <summary>
- /// 使用打印机已设置的信息进行打印测试
- /// </summary>
- public bool PrintTest()
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return false;
- }
- _printType = PrintType.PrintTest;
- if (CheckPrintSetting())
- {
- DialogResult result = printDialog.ShowDialog(this);
- if (result == DialogResult.OK)
- {
- printDocument.PrinterSettings.PrinterName = printDialog.PrinterSettings.PrinterName;
- if (printDocument.PrinterSettings.IsValid)
- {
- printDocument.Print();
- return true;
- }
- else
- {
- MessageBox.Show(string.Format("打印机名({0}/{1})不正确。"
- , printDocument.PrinterSettings.PrinterName
- , printDialog.PrinterSettings.PrinterName),
- "打印失败",
- MessageBoxButtons.OK,
- MessageBoxIcon.Error,
- MessageBoxDefaultButton.Button1);
- return false;
- }
- }
- }
- return false;
- }
- /// <summary>
- /// 使用打印机已设置的信息进行打印
- /// </summary>
- public bool Print(bool checkPrintSetting = true)
- {
- //#if DEBUG
- // Dongke.IBOSS.PRD.Basics.Library.OutputLog.TraceLog(Dongke.IBOSS.PRD.Basics.Library.LogPriority.Debug,
- // "Print",
- // "begin",
- // DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff"),
- // Dongke.IBOSS.PRD.Basics.Library.LocalPath.LogExePath + @"printdebug\");
- //#endif
- _printType = PrintType.Print;
- if (!checkPrintSetting || CheckPrintSetting())
- {
- printDocument.Print();
- //#if DEBUG
- // Dongke.IBOSS.PRD.Basics.Library.OutputLog.TraceLog(Dongke.IBOSS.PRD.Basics.Library.LogPriority.Debug,
- // "Print",
- // "end",
- // DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff"),
- // Dongke.IBOSS.PRD.Basics.Library.LocalPath.LogExePath + @"printdebug\");
- //#endif
- return true;
- }
- return false;
- }
- /// <summary>
- /// 使用打印机已设置的信息进行分配打印
- /// </summary>
- public bool AllocationPrint()
- {
- _printType = PrintType.AllocationPrint;
- if (CheckPrintSetting())
- {
- printDocument.Print();
- return true;
- }
- return false;
- }
- /// <summary>
- /// 使用打印机已设置的信息进行打印预览
- /// </summary>
- public bool PrintPreview()
- {
- _printType = PrintType.PrintPreview;
- if (CheckPrintSetting())
- {
- //printPreviewDialogEx.WindowState = FormWindowState.Maximized;
- //printPreviewDialogEx.PrintPreviewControl.Columns = 1;
- //printPreviewDialogEx.PrintPreviewControl.Rows = 1;
- //printPreviewDialogEx.PrintPreviewControl.StartPage = 0;
- //printPreviewDialogEx.ShowDialog();
- printPreviewDialog1.WindowState = FormWindowState.Maximized;
- printPreviewDialog1.PrintPreviewControl.Columns = 1;
- printPreviewDialog1.PrintPreviewControl.Rows = 1;
- printPreviewDialog1.PrintPreviewControl.StartPage = 0;
- printPreviewDialog1.ShowDialog();
- return true;
- }
- return false;
- }
- /// <summary>
- /// 使用打印机已设置的信息进行分配打印预览
- /// </summary>
- public bool AllocationPrintPreview()
- {
- _printType = PrintType.AllocationPrintPreview;
- if (CheckPrintSetting())
- {
- //printPreviewDialogEx.WindowState = FormWindowState.Maximized;
- //printPreviewDialogEx.PrintPreviewControl.Columns = 1;
- //printPreviewDialogEx.PrintPreviewControl.Rows = 1;
- //printPreviewDialogEx.PrintPreviewControl.StartPage = 0;
- //printPreviewDialogEx.ShowDialog();
- printPreviewDialog1.WindowState = FormWindowState.Maximized;
- printPreviewDialog1.PrintPreviewControl.Columns = 1;
- printPreviewDialog1.PrintPreviewControl.Rows = 1;
- printPreviewDialog1.PrintPreviewControl.StartPage = 0;
- printPreviewDialog1.ShowDialog();
- return true;
- }
- return false;
- }
- #endregion 打印相关
- #endregion public函数
- #region private函数
- #region 保存、读取相关
- /// <summary>
- /// 创建一个线性图item xuwei add 2024-04-12
- /// </summary>
- /// <param name="isShowDialog">是否显示属性设置对话框</param>
- /// <returns>创建的新Item对象</returns>
- private LayoutItem NewLinearGraphItem(bool isShowDialog)
- {
- /*
- TextItem textItem = new TextItem(null);
- textItem.IsNew = true;
- PointF newItemLocation = GetNewItemLocation(LayoutCommon.DefaultTextItemSizeWidth,
- LayoutCommon.DefaultTextItemSizeHeight);
- if (isShowDialog)
- {
- using (TextItemSetting itemPropertySetting = new TextItemSetting())
- {
- itemPropertySetting.IsNew = true;
- itemPropertySetting.IsDataBinding = false;
- itemPropertySetting.TextPreview = "";
- itemPropertySetting.TextWidth = 50;
- itemPropertySetting.TextHeight = 20;
- itemPropertySetting.TextFont = textItem.Font;
- itemPropertySetting.TextLocationX = newItemLocation.X;
- itemPropertySetting.TextLocationY = newItemLocation.Y;
- itemPropertySetting.ItemStyle = ItemStyle.LinearGraph;
- itemPropertySetting.ItemName = LayoutBox.ITEMNAME_FIX + _newItemID;
- DialogResult result = itemPropertySetting.ShowDialog();
- if (result == DialogResult.OK)
- {
- textItem.Init(this, true);
- textItem.IsDataBinding = false;
- textItem.Left = itemPropertySetting.TextLocationX;
- textItem.Top = itemPropertySetting.TextLocationY;
- textItem.Width = itemPropertySetting.TextWidth;
- textItem.Height = itemPropertySetting.TextHeight;
- textItem.LineSpace = itemPropertySetting.LineSpace;
- textItem.CharacterSpace = itemPropertySetting.CharacterSpace;
- textItem.CharacterCount = itemPropertySetting.CharacterCount;
- textItem.Font = itemPropertySetting.TextFont;
- textItem.Wrap = itemPropertySetting.Wrap;
- textItem.TextColor = itemPropertySetting.TextColor;
- textItem.TextAlign = itemPropertySetting.TextAlign;
- textItem.TextAlignVertical = itemPropertySetting.TextAlignVertical;
- textItem.DisplayValue = itemPropertySetting.TextPreview;
- textItem.ItemStyle = itemPropertySetting.ItemStyle;
- textItem.TextItemName = itemPropertySetting.ItemName;
- textItem.Format = itemPropertySetting.TextFormat;
- textItem.Culture = itemPropertySetting.Culture;
- textItem.DefaultValue = itemPropertySetting.DefaultValue;
- textItem.IsNew = false;
- textItem.PicColumn = false;
- textItem.PicMargin = itemPropertySetting.chkM.Checked;
- textItem.FixedRatio = itemPropertySetting.chkFixedRatio.Checked;
- textItem.SetDrawProperty();
- return textItem;
- }
- else
- {
- return null;
- }
- }
- }
- else
- {
- textItem.Init(this, true);
- textItem.Left = newItemLocation.X;
- textItem.Top = newItemLocation.Y;
- textItem.ItemStyle = ItemStyle.LinearGraph;
- textItem.Width = 50;
- textItem.Height = 20;
- textItem.DisplayValue = "";
- textItem.IsNew = false;
- textItem.PicColumn = false;
- textItem.PicMargin = false;
- textItem.FixedRatio = false;
- textItem.SetDrawProperty();
- return textItem;
- }
- */
- //TextItem imageItem = new TextItem(null, ItemType.LinearGraph);
- TextItem imageItem = new TextItem(null);
- imageItem.ItemStyle = ItemStyle.LinearGraph;
- imageItem.PicColumn = true;
- imageItem.IsNew = true;
- PointF newItemLocation = GetNewItemLocation(LayoutCommon.DefaultTextItemSizeWidth,
- LayoutCommon.DefaultTextItemSizeHeight);
- if (isShowDialog)
- {
- ImageItemSetting itemPropertySetting = new ImageItemSetting();
- itemPropertySetting.ImageLocationX = newItemLocation.X;
- itemPropertySetting.ImageLocationY = newItemLocation.Y;
- itemPropertySetting.ImageWidth = 50;
- itemPropertySetting.ImageHeight = 50;
- DialogResult result = itemPropertySetting.ShowDialog();
- if (result == DialogResult.OK)
- {
- imageItem.Init(this, true);
- imageItem.Width = itemPropertySetting.ImageWidth;
- imageItem.Height = itemPropertySetting.ImageHeight;
- imageItem.Left = itemPropertySetting.ImageLocationX;
- imageItem.Top = itemPropertySetting.ImageLocationY;
- imageItem.SideRatioFixed = itemPropertySetting.SideRatioFixed;
- //imageItem.Image = null;
- //imageItem.FileName = null;
- imageItem.IsNew = false;
- imageItem.SetDrawProperty();
- return imageItem;
- }
- else
- {
- return null;
- }
- }
- else
- {
- imageItem.Init(this, true);
- imageItem.Left = newItemLocation.X;
- imageItem.Top = newItemLocation.Y;
- imageItem.Width = 50;
- imageItem.Height = 50;
- //imageItem.Image = null;
- //imageItem.FileName = null;
- imageItem.SideRatioFixed = true;
- imageItem.IsNew = false;
- imageItem.SetDrawProperty();
- return imageItem;
- }
- }
- /// <summary>
- /// 创建一个新条码文本Item
- /// </summary>
- /// <param name="isShowDialog">是否显示属性设置对话框</param>
- /// <returns>创建的新Item对象</returns>
- private LayoutItem NewQRcodeItem(bool isShowDialog)
- {
- TextItem textItem = new TextItem(null);
- textItem.IsNew = true;
- PointF newItemLocation = GetNewItemLocation(LayoutCommon.DefaultTextItemSizeWidth,
- LayoutCommon.DefaultTextItemSizeHeight);
- if (isShowDialog)
- {
- using (TextItemSetting itemPropertySetting = new TextItemSetting())
- {
- itemPropertySetting.IsNew = true;
- itemPropertySetting.IsDataBinding = false;
- itemPropertySetting.TextPreview = "1234567890";
- itemPropertySetting.TextWidth = 25;
- itemPropertySetting.TextHeight = 25;
- itemPropertySetting.TextFont = textItem.Font;
- itemPropertySetting.TextLocationX = newItemLocation.X;
- itemPropertySetting.TextLocationY = newItemLocation.Y;
- itemPropertySetting.ItemStyle = ItemStyle.QRCode;
- itemPropertySetting.ItemName = LayoutBox.ITEMNAME_FIX + _newItemID;
- DialogResult result = itemPropertySetting.ShowDialog();
- if (result == DialogResult.OK)
- {
- textItem.Init(this, true);
- textItem.IsDataBinding = false;
- textItem.Left = itemPropertySetting.TextLocationX;
- textItem.Top = itemPropertySetting.TextLocationY;
- textItem.Width = itemPropertySetting.TextWidth;
- textItem.Height = itemPropertySetting.TextHeight;
- textItem.LineSpace = itemPropertySetting.LineSpace;
- textItem.CharacterSpace = itemPropertySetting.CharacterSpace;
- textItem.CharacterCount = itemPropertySetting.CharacterCount;
- textItem.Font = itemPropertySetting.TextFont;
- textItem.Wrap = itemPropertySetting.Wrap;
- textItem.TextColor = itemPropertySetting.TextColor;
- textItem.TextAlign = itemPropertySetting.TextAlign;
- textItem.TextAlignVertical = itemPropertySetting.TextAlignVertical;
- textItem.DisplayValue = itemPropertySetting.TextPreview;
- textItem.ItemStyle = itemPropertySetting.ItemStyle;
- textItem.TextItemName = itemPropertySetting.ItemName;
- textItem.Format = itemPropertySetting.TextFormat;
- textItem.Culture = itemPropertySetting.Culture;
- textItem.DefaultValue = itemPropertySetting.DefaultValue;
- textItem.IsNew = false;
- textItem.PicColumn = false;
- textItem.PicMargin = itemPropertySetting.chkM.Checked;
- textItem.FixedRatio = itemPropertySetting.chkFixedRatio.Checked;
- textItem.SetDrawProperty();
- return textItem;
- }
- else
- {
- return null;
- }
- }
- }
- else
- {
- textItem.Init(this, true);
- textItem.Left = newItemLocation.X;
- textItem.Top = newItemLocation.Y;
- textItem.ItemStyle = ItemStyle.QRCode;
- textItem.Width = 25;
- textItem.Height = 25;
- textItem.DisplayValue = "1234567890";
- textItem.IsNew = false;
- textItem.PicColumn = false;
- textItem.PicMargin = false;
- textItem.FixedRatio = false;
- textItem.SetDrawProperty();
- return textItem;
- }
- }
- /// <summary>
- /// 创建一个新条码文本Item
- /// </summary>
- /// <param name="isShowDialog">是否显示属性设置对话框</param>
- /// <returns>创建的新Item对象</returns>
- private LayoutItem NewBarcodeItem(bool isShowDialog)
- {
- TextItem textItem = new TextItem(null);
- textItem.IsNew = true;
- PointF newItemLocation = GetNewItemLocation(LayoutCommon.DefaultTextItemSizeWidth,
- LayoutCommon.DefaultTextItemSizeHeight);
- if (isShowDialog)
- {
- using (TextItemSetting itemPropertySetting = new TextItemSetting())
- {
- itemPropertySetting.IsNew = true;
- itemPropertySetting.IsDataBinding = false;
- itemPropertySetting.TextPreview = "12345678901";
- itemPropertySetting.TextWidth = 50;
- itemPropertySetting.TextHeight = 20;
- itemPropertySetting.TextFont = textItem.Font;
- itemPropertySetting.TextLocationX = newItemLocation.X;
- itemPropertySetting.TextLocationY = newItemLocation.Y;
- itemPropertySetting.ItemStyle = ItemStyle.Barcode;
- itemPropertySetting.ItemName = LayoutBox.ITEMNAME_FIX + _newItemID;
- DialogResult result = itemPropertySetting.ShowDialog();
- if (result == DialogResult.OK)
- {
- textItem.Init(this, true);
- textItem.IsDataBinding = false;
- textItem.Left = itemPropertySetting.TextLocationX;
- textItem.Top = itemPropertySetting.TextLocationY;
- textItem.Width = itemPropertySetting.TextWidth;
- textItem.Height = itemPropertySetting.TextHeight;
- textItem.LineSpace = itemPropertySetting.LineSpace;
- textItem.CharacterSpace = itemPropertySetting.CharacterSpace;
- textItem.CharacterCount = itemPropertySetting.CharacterCount;
- textItem.Font = itemPropertySetting.TextFont;
- textItem.Wrap = itemPropertySetting.Wrap;
- textItem.TextColor = itemPropertySetting.TextColor;
- textItem.TextAlign = itemPropertySetting.TextAlign;
- textItem.TextAlignVertical = itemPropertySetting.TextAlignVertical;
- textItem.DisplayValue = itemPropertySetting.TextPreview;
- textItem.ItemStyle = itemPropertySetting.ItemStyle;
- textItem.TextItemName = itemPropertySetting.ItemName;
- textItem.Format = itemPropertySetting.TextFormat;
- textItem.Culture = itemPropertySetting.Culture;
- textItem.DefaultValue = itemPropertySetting.DefaultValue;
- textItem.IsNew = false;
- textItem.PicColumn = false;
- textItem.PicMargin = itemPropertySetting.chkM.Checked;
- textItem.FixedRatio = itemPropertySetting.chkFixedRatio.Checked;
- textItem.SetDrawProperty();
- return textItem;
- }
- else
- {
- return null;
- }
- }
- }
- else
- {
- textItem.Init(this, true);
- textItem.Left = newItemLocation.X;
- textItem.Top = newItemLocation.Y;
- textItem.ItemStyle = ItemStyle.Barcode;
- textItem.Width = 50;
- textItem.Height = 20;
- textItem.DisplayValue = "12345678901";
- textItem.IsNew = false;
- textItem.PicColumn = false;
- textItem.PicMargin = false;
- textItem.FixedRatio = false;
- textItem.SetDrawProperty();
- return textItem;
- }
- }
- /// <summary>
- /// 创建一个新文本Item
- /// </summary>
- /// <param name="isShowDialog">是否显示属性设置对话框</param>
- /// <returns>创建的新Item对象</returns>
- private LayoutItem NewTextItem(bool isShowDialog)
- {
- TextItem textItem = new TextItem(null);
- textItem.IsNew = true;
- PointF newItemLocation = GetNewItemLocation(LayoutCommon.DefaultTextItemSizeWidth,
- LayoutCommon.DefaultTextItemSizeHeight);
- if (isShowDialog)
- {
- using (TextItemSetting itemPropertySetting = new TextItemSetting())
- {
- itemPropertySetting.IsNew = true;
- itemPropertySetting.IsDataBinding = false;
- itemPropertySetting.TextFont = textItem.Font;
- itemPropertySetting.TextLocationX = newItemLocation.X;
- itemPropertySetting.TextLocationY = newItemLocation.Y;
- itemPropertySetting.ItemStyle = ItemStyle.Other;
- itemPropertySetting.ItemName = LayoutBox.ITEMNAME_FIX + _newItemID;
- DialogResult result = itemPropertySetting.ShowDialog();
- if (result == DialogResult.OK)
- {
- textItem.Init(this, true);
- textItem.IsDataBinding = false;
- textItem.Left = itemPropertySetting.TextLocationX;
- textItem.Top = itemPropertySetting.TextLocationY;
- textItem.Width = itemPropertySetting.TextWidth;
- textItem.Height = itemPropertySetting.TextHeight;
- textItem.LineSpace = itemPropertySetting.LineSpace;
- textItem.CharacterSpace = itemPropertySetting.CharacterSpace;
- textItem.CharacterCount = itemPropertySetting.CharacterCount;
- textItem.Font = itemPropertySetting.TextFont;
- textItem.Wrap = itemPropertySetting.Wrap;
- textItem.TextColor = itemPropertySetting.TextColor;
- textItem.TextAlign = itemPropertySetting.TextAlign;
- textItem.TextAlignVertical = itemPropertySetting.TextAlignVertical;
- textItem.DisplayValue = itemPropertySetting.TextPreview;
- textItem.ItemStyle = itemPropertySetting.ItemStyle;
- textItem.TextItemName = itemPropertySetting.ItemName;
- textItem.Format = itemPropertySetting.TextFormat;
- textItem.Culture = itemPropertySetting.Culture;
- textItem.DefaultValue = itemPropertySetting.DefaultValue;
- textItem.IsNew = false;
- textItem.SetDrawProperty();
- return textItem;
- }
- else
- {
- return null;
- }
- }
- }
- else
- {
- textItem.Init(this, true);
- textItem.Left = newItemLocation.X;
- textItem.Top = newItemLocation.Y;
- textItem.IsNew = false;
- textItem.SetDrawProperty();
- return textItem;
- }
- }
- /// <summary>
- /// 创建一个新图片Item
- /// </summary>
- /// <param name="isShowDialog">是否显示属性设置对话框</param>
- /// <returns>创建的新Item对象</returns>
- private LayoutItem NewImageItem(bool isShowDialog)
- {
- ImageItem imageItem = new ImageItem(null);
- imageItem.IsNew = true;
- openFileDialog.FileName = string.Empty;
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- FileInfo fileInfo = new FileInfo(openFileDialog.FileName);
- // 图片尺寸超过200kbyte
- if (LayoutConsts.FILE_DIALOG_IMAGE_MAX_SIZE < fileInfo.Length)
- {
- DialogResult dr = MessageBox.Show(
- "图片太大,影响显示和打印速度,请准备200KByte以下的图片。",
- "LayoutBox",
- MessageBoxButtons.YesNo,
- MessageBoxIcon.Warning,
- MessageBoxDefaultButton.Button1);
- if (dr == DialogResult.Yes)
- {
- return null;
- }
- }
- Image image = null;
- float imageWidth = LayoutConsts.SHAPE_ITEM_SIZE_DEFAULT_WIDTH;
- float imageHeigh = LayoutConsts.SHAPE_ITEM_SIZE_DEFAULT_HEIGHT;
- if (fileInfo.Length > 0)
- {
- Stream imageStream = null;
- try
- {
- imageStream = fileInfo.Open(FileMode.Open,
- FileAccess.Read,
- FileShare.ReadWrite | FileShare.Delete);
- image = Image.FromStream(imageStream);
- MemoryStream mstream = new MemoryStream();
- image.Save(mstream, image.RawFormat);
- image = Image.FromStream(mstream);
- }
- finally
- {
- if (imageStream != null)
- {
- imageStream.Dispose();
- }
- }
- imageWidth = LayoutCommon.PixelToMillimeter(image.Width, _zoom, image.HorizontalResolution);
- imageHeigh = LayoutCommon.PixelToMillimeter(image.Height, _zoom, image.VerticalResolution);
- }
- else
- {
- MessageBox.Show("不能设置大小为0的图片。",
- "LayoutBox",
- MessageBoxButtons.OK,
- MessageBoxIcon.Error,
- MessageBoxDefaultButton.Button1);
- return null;
- }
- PointF newItemLocation = GetNewItemLocation(imageWidth, imageHeigh);
- if (isShowDialog)
- {
- ImageItemSetting itemPropertySetting = new ImageItemSetting();
- itemPropertySetting.ImageLocationX = newItemLocation.X;
- itemPropertySetting.ImageLocationY = newItemLocation.Y;
- itemPropertySetting.ImageWidth = imageWidth;
- itemPropertySetting.ImageHeight = imageHeigh;
- DialogResult result = itemPropertySetting.ShowDialog();
- if (result == DialogResult.OK)
- {
- imageItem.Init(this, true);
- imageItem.Width = itemPropertySetting.ImageWidth;
- imageItem.Height = itemPropertySetting.ImageHeight;
- imageItem.Left = itemPropertySetting.ImageLocationX;
- imageItem.Top = itemPropertySetting.ImageLocationY;
- imageItem.SideRatioFixed = itemPropertySetting.SideRatioFixed;
- imageItem.Image = image;
- imageItem.FileName = openFileDialog.FileName;
- imageItem.IsNew = false;
- imageItem.SetDrawProperty();
- return imageItem;
- }
- else
- {
- if (image != null)
- {
- image.Dispose();
- }
- return null;
- }
- }
- else
- {
- if (imageWidth < LayoutConsts.ITEM_SIZE_MIN)
- {
- imageWidth = LayoutConsts.ITEM_SIZE_MIN;
- }
- else if (LayoutConsts.ITEM_SIZE_WIDTH_MAX < imageWidth)
- {
- imageWidth = LayoutConsts.ITEM_SIZE_WIDTH_MAX;
- }
- if (imageHeigh < LayoutConsts.ITEM_SIZE_MIN)
- {
- imageHeigh = LayoutConsts.ITEM_SIZE_MIN;
- }
- else if (LayoutConsts.ITEM_SIZE_HEIGHT_MAX < imageHeigh)
- {
- imageHeigh = LayoutConsts.ITEM_SIZE_HEIGHT_MAX;
- }
- imageItem.Init(this, true);
- imageItem.Left = newItemLocation.X;
- imageItem.Top = newItemLocation.Y;
- imageItem.Width = imageWidth;
- imageItem.Height = imageHeigh;
- imageItem.Image = image;
- imageItem.FileName = openFileDialog.FileName;
- imageItem.SideRatioFixed = true;
- imageItem.IsNew = false;
- imageItem.SetDrawProperty();
- return imageItem;
- }
- }
- else
- {
- return null;
- }
- }
- /// <summary>
- /// 创建一个新矩形Item
- /// </summary>
- /// <param name="isShowDialog">是否显示属性设置对话框</param>
- /// <returns>创建的新Item对象</returns>
- private LayoutItem NewRectangleItem(bool isShowDialog)
- {
- RectangleItem rectangleItem = new RectangleItem(null);
- rectangleItem.IsNew = true;
- PointF newItemLocation = GetNewItemLocation(50, 50);
- if (isShowDialog)
- {
- using (GraphicsItemSetting itemPropertySetting = new GraphicsItemSetting())
- {
- itemPropertySetting.ShapeLocationX = newItemLocation.X;
- itemPropertySetting.ShapeLocationY = newItemLocation.Y;
- itemPropertySetting.ShapeWidth = rectangleItem.Width;
- itemPropertySetting.ShapeHeight = rectangleItem.Height;
- itemPropertySetting.LineColor = rectangleItem.LineColor;
- itemPropertySetting.FillColor = rectangleItem.FillColor;
- itemPropertySetting.LineWidth = rectangleItem.LineWidth;
- itemPropertySetting.Transparent = rectangleItem.Transparent;
- DialogResult result = itemPropertySetting.ShowDialog();
- if (result == DialogResult.OK)
- {
- rectangleItem.Init(this, true);
- rectangleItem.Left = itemPropertySetting.ShapeLocationX;
- rectangleItem.Top = itemPropertySetting.ShapeLocationY;
- rectangleItem.Width = itemPropertySetting.ShapeWidth;
- rectangleItem.Height = itemPropertySetting.ShapeHeight;
- rectangleItem.LineColor = itemPropertySetting.LineColor;
- rectangleItem.FillColor = itemPropertySetting.FillColor;
- rectangleItem.LineWidth = itemPropertySetting.LineWidth;
- rectangleItem.Transparent = itemPropertySetting.Transparent;
- rectangleItem.IsNew = false;
- rectangleItem.SetDrawProperty();
- return rectangleItem;
- }
- else
- {
- return null;
- }
- }
- }
- else
- {
- rectangleItem.Init(this, true);
- rectangleItem.Left = newItemLocation.X;
- rectangleItem.Top = newItemLocation.Y;
- rectangleItem.IsNew = false;
- rectangleItem.SetDrawProperty();
- return rectangleItem;
- }
- }
- /// <summary>
- /// 创建一个新椭圆Item
- /// </summary>
- /// <param name="isShowDialog">是否显示属性设置对话框</param>
- /// <returns>创建的新Item对象</returns>
- private LayoutItem NewEllipseItem(bool isShowDialog)
- {
- EllipseItem ellipseItem = new EllipseItem(null);
- ellipseItem.IsNew = true;
- PointF newItemLocation = GetNewItemLocation(50, 50);
- if (isShowDialog)
- {
- using (GraphicsItemSetting itemPropertySetting = new GraphicsItemSetting())
- {
- itemPropertySetting.ShapeLocationX = newItemLocation.X;
- itemPropertySetting.ShapeLocationY = newItemLocation.Y;
- itemPropertySetting.ShapeWidth = ellipseItem.Width;
- itemPropertySetting.ShapeHeight = ellipseItem.Height;
- itemPropertySetting.LineColor = ellipseItem.LineColor;
- itemPropertySetting.FillColor = ellipseItem.FillColor;
- itemPropertySetting.LineWidth = ellipseItem.LineWidth;
- itemPropertySetting.Transparent = ellipseItem.Transparent;
- DialogResult result = itemPropertySetting.ShowDialog();
- if (result == DialogResult.OK)
- {
- ellipseItem.Init(this, true);
- ellipseItem.Left = itemPropertySetting.ShapeLocationX;
- ellipseItem.Top = itemPropertySetting.ShapeLocationY;
- ellipseItem.Width = itemPropertySetting.ShapeWidth;
- ellipseItem.Height = itemPropertySetting.ShapeHeight;
- ellipseItem.LineColor = itemPropertySetting.LineColor;
- ellipseItem.FillColor = itemPropertySetting.FillColor;
- ellipseItem.LineWidth = itemPropertySetting.LineWidth;
- ellipseItem.Transparent = itemPropertySetting.Transparent;
- ellipseItem.IsNew = false;
- ellipseItem.SetDrawProperty();
- return ellipseItem;
- }
- else
- {
- return null;
- }
- }
- }
- else
- {
- ellipseItem.Init(this, true);
- ellipseItem.Left = newItemLocation.X;
- ellipseItem.Top = newItemLocation.Y;
- ellipseItem.IsNew = false;
- ellipseItem.SetDrawProperty();
- return ellipseItem;
- }
- }
- /// <summary>
- /// 创建一个新表格Item
- /// </summary>
- /// <param name="isShowDialog">是否显示属性设置对话框</param>
- /// <returns>创建的新Item对象</returns>
- private LayoutItem NewGridItem(bool isShowDialog)
- {
- GridItem gridItem = new GridItem(null);
- gridItem.IsNew = true;
- PointF newItemLocation = GetNewItemLocation(50, 50);
- if (isShowDialog)
- {
- using (GridItemSetting itemPropertySetting = new GridItemSetting())
- {
- itemPropertySetting.ShapeLocationX = newItemLocation.X;
- itemPropertySetting.ShapeLocationY = newItemLocation.Y;
- itemPropertySetting.ShapeWidth = gridItem.Width;
- itemPropertySetting.ShapeHeight = gridItem.Height;
- itemPropertySetting.LineColor = gridItem.LineColor;
- itemPropertySetting.FillColor = gridItem.FillColor;
- itemPropertySetting.LineWidth = gridItem.LineWidth;
- itemPropertySetting.Transparent = gridItem.Transparent;
- itemPropertySetting.TitleVisible = gridItem.TitleVisible;
- itemPropertySetting.AlwaysTitleVisible = gridItem.AlwaysTitleVisible;
- itemPropertySetting.RowsHeight = gridItem.RowsHeight;
- itemPropertySetting.HeadRowsHeight = gridItem.HeadRowsHeight;
- itemPropertySetting.RowsCount = gridItem.DisplayRowCount;
- itemPropertySetting.Columns = gridItem.Columns.CopyTo();
- DialogResult result = itemPropertySetting.ShowDialog();
- if (result == DialogResult.OK)
- {
- gridItem.Init(this, true);
- gridItem.Left = itemPropertySetting.ShapeLocationX;
- gridItem.Top = itemPropertySetting.ShapeLocationY;
- gridItem.Width = itemPropertySetting.ShapeWidth;
- gridItem.Height = itemPropertySetting.ShapeHeight;
- gridItem.LineColor = itemPropertySetting.LineColor;
- gridItem.FillColor = itemPropertySetting.FillColor;
- gridItem.LineWidth = itemPropertySetting.LineWidth;
- gridItem.Transparent = itemPropertySetting.Transparent;
- gridItem.TitleVisible = itemPropertySetting.TitleVisible;
- gridItem.AlwaysTitleVisible = itemPropertySetting.AlwaysTitleVisible;
- gridItem.DisplayRowCount = itemPropertySetting.RowsCount;
- gridItem.RowsHeight = itemPropertySetting.RowsHeight;
- gridItem.HeadRowsHeight = itemPropertySetting.HeadRowsHeight;
- if (itemPropertySetting.ColumnsChanged)
- {
- itemPropertySetting.Columns.GridItem = gridItem;
- gridItem.Columns = itemPropertySetting.Columns;
- }
- gridItem.IsNew = false;
- gridItem.SetDrawProperty();
- return gridItem;
- }
- else
- {
- return null;
- }
- }
- }
- else
- {
- gridItem.Init(this, true);
- gridItem.Left = newItemLocation.X;
- gridItem.Top = newItemLocation.Y;
- gridItem.IsNew = false;
- gridItem.SetDrawProperty();
- return gridItem;
- }
- }
- /// <summary>
- /// 创建一个Grid页码Item
- /// </summary>
- /// <param name="isShowDialog">是否显示属性设置对话框</param>
- /// <returns>创建的新Item对象</returns>
- private LayoutItem NewPageNumItem(bool isShowDialog)
- {
- PageNumItem pageNumItem = new PageNumItem(null);
- pageNumItem.IsNew = true;
- PointF newItemLocation = GetNewItemLocation(50, 50);
- if (isShowDialog)
- {
- using (PageNumItemSetting itemPropertySetting = new PageNumItemSetting())
- {
- itemPropertySetting.TextLocationX = newItemLocation.X;
- itemPropertySetting.TextLocationY = newItemLocation.Y;
- itemPropertySetting.TextWidth = pageNumItem.Width;
- itemPropertySetting.TextHeight = pageNumItem.Height;
- itemPropertySetting.TextAlign = pageNumItem.TextAlign;
- itemPropertySetting.TextAlignVertical = pageNumItem.TextAlignVertical;
- itemPropertySetting.TextColor = pageNumItem.TextColor;
- itemPropertySetting.TextFormat = pageNumItem.Format;
- itemPropertySetting.TextFont = pageNumItem.Font;
- DialogResult result = itemPropertySetting.ShowDialog();
- if (result == DialogResult.OK)
- {
- pageNumItem.Init(this, true);
- pageNumItem.Left = itemPropertySetting.TextLocationX;
- pageNumItem.Top = itemPropertySetting.TextLocationY;
- pageNumItem.Width = itemPropertySetting.TextWidth;
- pageNumItem.Height = itemPropertySetting.TextHeight;
- pageNumItem.Font = itemPropertySetting.TextFont;
- pageNumItem.TextAlign = itemPropertySetting.TextAlign;
- pageNumItem.TextAlignVertical = itemPropertySetting.TextAlignVertical;
- pageNumItem.TextColor = itemPropertySetting.TextColor;
- pageNumItem.Format = itemPropertySetting.TextFormat;
- pageNumItem.IsNew = false;
- pageNumItem.SetDrawProperty();
- return pageNumItem;
- }
- else
- {
- return null;
- }
- }
- }
- else
- {
- pageNumItem.Init(this, true);
- pageNumItem.Left = newItemLocation.X;
- pageNumItem.Top = newItemLocation.Y;
- pageNumItem.IsNew = false;
- pageNumItem.SetDrawProperty();
- return pageNumItem;
- }
- }
- /// <summary>
- /// 创建一个合计文本Item
- /// </summary>
- /// <param name="isShowDialog">是否显示属性设置对话框</param>
- /// <returns>创建的新Item对象</returns>
- private LayoutItem NewTotalTextItem(bool isShowDialog)
- {
- TotalTextItem textItem = new TotalTextItem(null);
- textItem.IsNew = true;
- PointF newItemLocation = GetNewItemLocation(LayoutCommon.DefaultTextItemSizeWidth,
- LayoutCommon.DefaultTextItemSizeHeight);
- if (isShowDialog)
- {
- using (TotalTextItemSetting itemPropertySetting = new TotalTextItemSetting())
- {
- itemPropertySetting.IsNew = true;
- itemPropertySetting.IsDataBinding = false;
- itemPropertySetting.TextFont = textItem.Font;
- itemPropertySetting.TextLocationX = newItemLocation.X;
- itemPropertySetting.TextLocationY = newItemLocation.Y;
- itemPropertySetting.ItemStyle = ItemStyle.Other;
- itemPropertySetting.ItemName = LayoutBox.ITEMNAME_FIX + _newItemID;
- itemPropertySetting.NotTotalFont = textItem.NotTotalFont;
- itemPropertySetting.NotTotalColor = textItem.NotTotalColor;
- itemPropertySetting.NotTotalValue = textItem.NotTotalValue;
- itemPropertySetting.NotTotalAlign = textItem.NotTotalAlign;
- itemPropertySetting.NotTotalAlignVertical = textItem.NotTotalAlignVertical;
- DialogResult result = itemPropertySetting.ShowDialog();
- if (result == DialogResult.OK)
- {
- textItem.Init(this, true);
- textItem.IsDataBinding = false;
- textItem.Left = itemPropertySetting.TextLocationX;
- textItem.Top = itemPropertySetting.TextLocationY;
- textItem.Width = itemPropertySetting.TextWidth;
- textItem.Height = itemPropertySetting.TextHeight;
- textItem.LineSpace = itemPropertySetting.LineSpace;
- textItem.CharacterSpace = itemPropertySetting.CharacterSpace;
- textItem.CharacterCount = itemPropertySetting.CharacterCount;
- textItem.Font = itemPropertySetting.TextFont;
- textItem.Wrap = itemPropertySetting.Wrap;
- textItem.TextColor = itemPropertySetting.TextColor;
- textItem.TextAlign = itemPropertySetting.TextAlign;
- textItem.TextAlignVertical = itemPropertySetting.TextAlignVertical;
- textItem.DisplayValue = itemPropertySetting.TextPreview;
- textItem.ItemStyle = itemPropertySetting.ItemStyle;
- textItem.TextItemName = itemPropertySetting.ItemName;
- textItem.Format = itemPropertySetting.TextFormat;
- textItem.Culture = itemPropertySetting.Culture;
- textItem.DefaultValue = itemPropertySetting.DefaultValue;
- textItem.NotTotalFont = itemPropertySetting.NotTotalFont;
- textItem.NotTotalColor = itemPropertySetting.NotTotalColor;
- textItem.NotTotalValue = itemPropertySetting.NotTotalValue;
- textItem.NotTotalAlign = itemPropertySetting.NotTotalAlign;
- textItem.NotTotalAlignVertical = itemPropertySetting.NotTotalAlignVertical;
- textItem.IsNew = false;
- textItem.SetDrawProperty();
- return textItem;
- }
- else
- {
- return null;
- }
- }
- }
- else
- {
- textItem.Init(this, true);
- textItem.Left = newItemLocation.X;
- textItem.Top = newItemLocation.Y;
- textItem.IsNew = false;
- textItem.SetDrawProperty();
- return textItem;
- }
- }
- /// <summary>
- /// 清除LayoutBox的设置
- /// </summary>
- private void ClearLayoutBox()
- {
- // TODO
- if (this._clipboardFormat != null)
- {
- this.ClearClipboard();
- //if (Clipboard.ContainsData(_clipboardFormat.Name))
- //{
- // CopyToClipboard(_clipboardFormat.Name, null);
- //}
- //_clipboardFormat =
- // DataFormats.GetFormat(typeof(LayoutItem).FullName
- // + "{"
- // + Guid.NewGuid().ToString().ToUpper()
- // + "}");
- }
- _lastItemRF = RectangleF.Empty;
- _mouseRect = Rectangle.Empty;
- SetDitry(false);
- _selectedItems.Clear();
- foreach (LayoutItem item in _items)
- {
- if (item.Frame != null)
- {
- item.Frame.Dispose();
- item.Frame = null;
- }
- item.Selected = false;
- item.Dispose();
- }
- _items.Clear();
- _updateCount = 0;
- _newItemID = 1;
- _paperHeight = 297.0f;
- _paperWidth = 210.0f;
- _backgroundImageName = string.Empty;
- paperArea.BackgroundImage = null;
- _isPrintAreaVisible = true;
- _isPrintBackground = false;
- if (_zoomType != ZoomType.Whole)
- {
- ChangePaperSize();
- }
- else
- {
- InitializeZoom();
- }
- }
- /// <summary>
- /// 初始化LayoutBox
- /// </summary>
- private void InitializeLayoutBox()
- {
- openFileDialog.Filter = LayoutConsts.FILE_DIALOG_IMAGE_FILTER;
- openFileDialog.FilterIndex = 6;
- string directory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
- if (Directory.Exists(directory))
- {
- openFileDialog.InitialDirectory = directory;
- }
- else
- {
- openFileDialog.InitialDirectory =
- Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
- }
- _comparisonItems = new Comparison<LayoutItem>(SortItemsWithChildIndex);
- //// TODO
- //if (this._layoutMode == InvoiceLayout.LayoutMode.Edit)
- //{
- // _clipboardFormat =
- // DataFormats.GetFormat(typeof(LayoutItem).FullName
- // + "{"
- // + Guid.NewGuid().ToString().ToUpper()
- // + "}");
- //}
- tsmiPaste.Enabled = true;
- _lastItemRF = RectangleF.Empty;
- _mouseRect = Rectangle.Empty;
- _updateCount = 0;
- _newItemID = 1;
- _dataMember = string.Empty;
- _printDataMember = string.Empty;
- //_layoutMode = LayoutMode.Display;
- _paperHeight = 297.0f;
- _paperWidth = 210.0f;
- _zoom = 100;
- _backgroundImageName = string.Empty;
- _isDirty = false;
- _isPrintAreaVisible = true;
- _isPrintBackground = false;
- _selectedItems = new List<LayoutItem>();
- _items = new List<LayoutItem>();
- _zoomType = ZoomType.Specify;
- ChangePaperSize();
- InitItemZoom();
- }
- /// <summary>
- /// 获取新建Item的位置
- /// </summary>
- /// <returns>新建Item的位置</returns>
- private PointF GetNewItemLocation(float itemWidth, float itemHeight)
- {
- PointF newItemLocation = new PointF(LayoutConsts.ITEM_LOCATION_DEF, LayoutConsts.ITEM_LOCATION_DEF);
- if (paperArea.Left < 0)
- {
- newItemLocation.X += LayoutCommon.PixelToMillimeter(Math.Abs(paperArea.Left), _zoom);
- }
- if (paperArea.Top < 0)
- {
- newItemLocation.Y += LayoutCommon.PixelToMillimeter(Math.Abs(paperArea.Top), _zoom);
- }
- return newItemLocation;
- }
- /// <summary>
- /// 复制到剪贴板中
- /// </summary>
- /// <param name="format">格式</param>
- /// <param name="items">选定的Item</param>
- private void CopyToClipboard(object items)
- {
- this.GetCipboardFormat();
- if (this._clipboardFormat != null)
- {
- IDataObject dataObj = new DataObject();
- dataObj.SetData(this._clipboardFormat.Name, false, items);
- Clipboard.SetDataObject(dataObj, false);
- }
- }
- /// <summary>
- /// 获取剪贴板中的数据
- /// </summary>
- /// <param name="format">格式</param>
- /// <returns>Item</returns>
- private object GetFromClipboard()
- {
- this.GetCipboardFormat();
- if (this._clipboardFormat != null)
- {
- if (Clipboard.ContainsData(this._clipboardFormat.Name))
- {
- return Clipboard.GetData(this._clipboardFormat.Name);
- }
- }
- return null;
- }
- private void ClearClipboard()
- {
- if (this._clipboardFormat != null)
- {
- if (Clipboard.ContainsData(_clipboardFormat.Name))
- {
- IDataObject dataObj = new DataObject();
- dataObj.SetData(this._clipboardFormat.Name, false, null);
- Clipboard.SetDataObject(dataObj, false);
- }
- }
- this._clipboardFormat = null;
- }
- private DataFormats.Format GetCipboardFormat()
- {
- if (_clipboardFormat != null)
- {
- return _clipboardFormat;
- }
- // TODO
- if (this._layoutMode == InvoiceLayout.LayoutMode.Edit)
- {
- _clipboardFormat =
- DataFormats.GetFormat(typeof(LayoutItem).FullName
- + "{"
- + Guid.NewGuid().ToString().ToUpper()
- + "}");
- }
- return _clipboardFormat;
- }
- #endregion 保存、读取相关
- #region 缩放比例和位置
- /// <summary>
- /// 设置纸张的高和宽
- /// </summary>
- /// <param name="paperWidth">纸张的宽</param>
- /// <param name="paperHeight">纸张的高</param>
- public void SetPaperAreaSize(float paperWidth, float paperHeight)
- {
- if (paperWidth < LayoutConsts.PAPER_SIZE_MIN
- || LayoutConsts.PAPER_SIZE_MAX < paperWidth)
- {
- return;
- }
- if (paperHeight < LayoutConsts.PAPER_SIZE_MIN
- || LayoutConsts.PAPER_SIZE_MAX < paperHeight)
- {
- return;
- }
- if (_paperHeight != paperHeight || _paperWidth != paperWidth)
- {
- //foreach (LayoutItem item in _items)
- //{
- // if (paperHeight < item.Top + item.Height
- // || paperWidth < item.Left + item.Width)
- // {
- // MessageBox.Show("在纸张范围外有Item,请设置纸张大小包含所有Item",
- // "LayoutBox",
- // MessageBoxButtons.OK,
- // MessageBoxIcon.Error,
- // MessageBoxDefaultButton.Button1);
- // return;
- // }
- //}
- _paperHeight = paperHeight;
- _paperWidth = paperWidth;
- if (_zoomType != ZoomType.Whole)
- {
- ChangePaperSize();
- }
- else
- {
- InitializeZoom();
- }
- if (PaperSizeChanged != null)
- {
- PaperSizeChanged(this, EventArgs.Empty);
- }
- _isDirty = true;
- }
- }
- /// <summary>
- /// 设置所有Item的缩放比例
- /// </summary>
- private void ZoomAllItems()
- {
- InitItemZoom();
- if (0 < _items.Count)
- {
- foreach (LayoutItem item in _items)
- {
- item.ResetShapeLocationAndSize(false);
- item.SetDrawProperty();
- }
- }
- }
- /// <summary>
- /// 整页显示
- /// </summary>
- private void InitializeZoom()
- {
- int paperHeight = LayoutCommon.MillimeterToPixel(_paperHeight);
- int paperWidth = LayoutCommon.MillimeterToPixel(_paperWidth);
- int marginHeight = Height - LayoutConsts.LAYOUT_MARGIN - LayoutConsts.LAYOUT_MARGIN;
- int marginWidth = Width - LayoutConsts.LAYOUT_MARGIN - LayoutConsts.LAYOUT_MARGIN;
- double zoomHeight = 100.0 * marginHeight / paperHeight;
- double zoomWidth = 100.0 * marginWidth / paperWidth;
- int zoom = System.Convert.ToInt32(Math.Truncate(Math.Min(zoomHeight, zoomWidth)));
- if (zoom < 0)
- {
- _zoom = 0;
- }
- else
- {
- _zoom = zoom;
- }
- ChangePaperSize();
- ZoomAllItems();
- }
- /// <summary>
- /// 纸张的显示比率
- /// </summary>
- private void ChangePaperSize()
- {
- int width = LayoutCommon.MillimeterToPixel(_paperWidth, _zoom);
- int height = LayoutCommon.MillimeterToPixel(_paperHeight, _zoom);
- paperArea.Size = new Size(width, height);
- AdjustPaperArea();
- }
- /// <summary>
- /// 缩放比例变更
- /// </summary>
- private void InitItemZoom()
- {
- _maxItemLeft = LayoutCommon.MillimeterToPixel(LayoutConsts.ITEM_LOCATION_MAX, _zoom);
- _maxItemTop = _maxItemLeft;
- _maxItemWidth = LayoutCommon.MillimeterToPixel(LayoutConsts.ITEM_SIZE_WIDTH_MAX, _zoom);
- _maxItemHeight = LayoutCommon.MillimeterToPixel(LayoutConsts.ITEM_SIZE_HEIGHT_MAX, _zoom);
- _minItemWidth = LayoutCommon.MillimeterToPixel(LayoutConsts.ITEM_SIZE_MIN, _zoom);
- _minItemHeight = _minItemWidth;
- }
- /// <summary>
- /// 设置纸张范围和位置
- /// </summary>
- private void AdjustPaperArea()
- {
- int top = AdjustPaperAreaTop();
- int left = AdjustPaperAreaLeft();
- paperArea.Location = new Point(left, top);
- lblRightBottomPoint.Location = new Point(paperArea.Right, paperArea.Bottom);
- }
- /// <summary>
- /// 设置纸张位置Y
- /// </summary>
- /// <returns>位置Y</returns>
- private int AdjustPaperAreaTop()
- {
- int margin = paperBox.ClientSize.Height
- - paperArea.Height
- - LayoutConsts.LAYOUT_MARGIN
- - LayoutConsts.LAYOUT_MARGIN;
- if (0 < margin)
- {
- return lblLeftTopPoint.Top + LayoutConsts.LAYOUT_MARGIN + (margin) / 2;
- }
- else
- {
- return lblLeftTopPoint.Top + LayoutConsts.LAYOUT_MARGIN;
- }
- }
- /// <summary>
- /// 设置纸张位置X
- /// </summary>
- /// <returns>位置X</returns>
- private int AdjustPaperAreaLeft()
- {
- int margin = paperBox.ClientSize.Width
- - paperArea.Width
- - LayoutConsts.LAYOUT_MARGIN
- - LayoutConsts.LAYOUT_MARGIN;
- if (0 < margin)
- {
- return lblLeftTopPoint.Left + LayoutConsts.LAYOUT_MARGIN + (margin) / 2;
- }
- else
- {
- return lblLeftTopPoint.Left + LayoutConsts.LAYOUT_MARGIN;
- }
- }
- #endregion 缩放比例和位置
- #region Item操作相关
- /// <summary>
- /// 设置Ditry
- /// </summary>
- /// <param name="vaule"></param>
- private void SetDitry(bool vaule)
- {
- _isDirty = vaule;
- }
- /// <summary>
- /// 计算滚动到指定子控制的偏移
- /// </summary>
- /// <param name="activeControl">滚动显示的子控制</param>
- /// <returns>滚动到指定子控制的偏移</returns>
- protected override Point ScrollToControl(Control activeControl)
- {
- // 选定Item时,滚动条不动
- return DisplayRectangle.Location;
- }
- /// <summary>
- /// 代表一个函数来比较两个相同类型的对象
- /// </summary>
- /// <param name="itemX">第一个比较对象</param>
- /// <param name="itemY">第二个比较对象</param>
- /// <returns>
- /// 小于0 x小于y。
- /// 等于0 x等于y。
- /// 大于0 x大于y。
- /// </returns>
- private int SortItemsWithChildIndex(LayoutItem itemX, LayoutItem itemY)
- {
- try
- {
- int x = paperArea.ShapeContainer.Shapes.GetChildIndex(itemX.Shape);
- int y = paperArea.ShapeContainer.Shapes.GetChildIndex(itemY.Shape);
- return y - x;
- }
- catch
- {
- return 0;
- }
- }
- /// <summary>
- /// 调整拖动范围
- /// </summary>
- /// <param name="p">鼠标所在位置</param>
- private void ResizeToRectangle(Point p)
- {
- Rectangle rect = _mouseRect;
- _mouseRect.Width = p.X - _mouseRect.Left;
- _mouseRect.Height = p.Y - _mouseRect.Top;
- DrawReversibleFrame(_mouseRect);
- DrawReversibleFrame(rect);
- }
- /// <summary>
- /// 显示拖动范围
- /// </summary>
- /// <param name="rect">范围</param>
- internal void DrawReversibleFrame(Rectangle rect)
- {
- /*
- ControlPaint.DrawReversibleFrame(
- //paperArea.RectangleToScreen(rect)
- DipClass.ToScale(paperArea.RectangleToScreen(rect)),
- Color.Black, FrameStyle.Dashed);
- */
- ControlPaint.DrawReversibleFrame(
- DipClass.ToScale2(this, paperArea.RectangleToScreen(rect)),
- Color.Black, FrameStyle.Dashed);
- }
- /// <summary>
- /// 当前选择的对象已经改变
- /// </summary>
- private void SetTSMIOnSelectionChanged()
- {
- if (0 < _selectedItems.Count)
- {
- tsmiCut.Enabled = true;
- tsmiCopy.Enabled = true;
- tsmiDelete.Enabled = true;
- tsmiOrder.Enabled = true;
- if (_selectedItems.Count == 1)
- {
- tsmiProperties.Enabled = true;
- tsmiArrange.Enabled = false;
- }
- else
- {
- tsmiProperties.Enabled = false;
- tsmiArrange.Enabled = true;
- }
- }
- else
- {
- tsmiCut.Enabled = false;
- tsmiCopy.Enabled = false;
- tsmiDelete.Enabled = false;
- tsmiProperties.Enabled = false;
- tsmiArrange.Enabled = false;
- tsmiOrder.Enabled = false;
- }
- }
- /// <summary>
- /// 调整Item范围
- /// </summary>
- /// <param name="p">鼠标所在位置</param>
- /// <param name="index">Item索引</param>
- private void ResizeToRectangle(Point p, int index)
- {
- Rectangle rect = _moveRectangles[index];
- if (_isShiftDown)
- {
- // 长宽比例
- double sizeRatio = 1.0 * _downRectangles[index].Height / _downRectangles[index].Width;
- int changedX = Math.Abs(p.X - _startX);
- int changedY = Math.Abs(p.Y - _startY);
- if (Math.Abs(p.X - _startX) < Math.Abs(p.Y - _startY))
- {
- rect.X = _downRectangles[index].Left;
- rect.Y = _downRectangles[index].Top + p.Y - _startY;
- }
- else
- {
- rect.X = _downRectangles[index].Left + p.X - _startX;
- rect.Y = _downRectangles[index].Top;
- }
- rect.Width = _downRectangles[index].Width;
- rect.Height = _downRectangles[index].Height;
- }
- else if (_isCtrlDown)
- {
- rect.X = _downRectangles[index].Left + p.X - _startX;
- rect.Y = _downRectangles[index].Top + p.Y - _startY;
- rect.Width = _downRectangles[index].Width;
- rect.Height = _downRectangles[index].Height;
- }
- else
- {
- rect.X = _downRectangles[index].Left + p.X - _startX;
- rect.Y = _downRectangles[index].Top + p.Y - _startY;
- rect.Width = _downRectangles[index].Width;
- rect.Height = _downRectangles[index].Height;
- }
- {
- DrawReversibleFrame(_selectedItems[index].ItemLockType, _moveRectangles[index], rect);
- }
- _moveRectangles[index] = rect;
- }
- /// <summary>
- /// 绘制Item移动范围
- /// </summary>
- /// <param name="itemLock">Item锁定状态</param>
- /// <param name="rectOriginal">源范围</param>
- /// <param name="rectCurrent">新范围</param>
- private void DrawReversibleFrame(ItemLock itemLock, Rectangle? rectOriginal, Rectangle? rectCurrent)
- {
- if (itemLock == ItemLock.LockLocationAndSize)
- {
- return;
- }
- if (rectCurrent.HasValue)
- {
- Rectangle rect = rectCurrent.Value;
- rect.Width += 1;
- rect.Height += 1;
- DrawReversibleFrame(rect);
- }
- if (rectOriginal.HasValue && _isMouseMove)
- {
- Rectangle rect = rectOriginal.Value;
- rect.Width += 1;
- rect.Height += 1;
- DrawReversibleFrame(rect);
- }
- }
- /// <summary>
- /// 调整控件的大小
- /// </summary>
- /// <param name="item">Item</param>
- /// <param name="rect">范围</param>
- private void DragHandler(LayoutItem item, Rectangle rect)
- {
- if (item.ItemLockType == ItemLock.LockLocationAndSize)
- {
- return;
- }
- int top = 0;
- int left = 0;
- int width = 0;
- int height = 0;
- if (rect.Width < 0)
- {
- left = rect.Right;
- width -= rect.Width;
- }
- else
- {
- left = rect.Left;
- width = rect.Width;
- }
- if (rect.Height < 0)
- {
- top = rect.Bottom;
- height -= rect.Height;
- }
- else
- {
- top = rect.Top;
- height = rect.Height;
- }
- if (left < 0
- || _maxItemLeft < left
- || top < 0
- || _maxItemTop < top
- || width < _minItemWidth
- || _maxItemWidth < width
- || height < _minItemHeight
- || _maxItemHeight < height
- || paperArea.Width - 1 < left
- || paperArea.Height - 1 < top
- )
- {
- //return;
- }
- item.MoveItem(left, top);
- item.ChangeItemSize(width, height);
- item.ResetItemFrame();
- Dirty = true;
- }
- #endregion Item操作相关
- #region 数据绑定相关
- /// <summary>
- /// 设置数据源
- /// </summary>
- private void SetDataSource()
- {
- if (_dataBinding == null)
- {
- _dataBinding = new LayoutBoxDataBinding(this);
- _dataBinding.SetDataConnection(_dataSource, _dataMember);
- }
- else
- {
- if (_dataBinding.ContainsDataMember(_dataSource))
- {
- _dataMember = string.Empty;
- }
- _dataBinding.SetDataConnection(_dataSource, _dataMember);
- if (_dataSource == null)
- {
- _dataBinding = null;
- }
- }
- RefreshItemsBound();
- }
- /// <summary>
- /// 设置数据成员
- /// </summary>
- private void SetDataMember()
- {
- if (_dataBinding == null)
- {
- _dataBinding = new LayoutBoxDataBinding(this);
- }
- _dataBinding.SetDataConnection(_dataSource, _dataMember);
- RefreshItemsBound();
- }
- /// <summary>
- /// 设置打印数据源
- /// </summary>
- private void SetPrintDataSource()
- {
- if (_printDataBinding == null)
- {
- _printDataBinding = new LayoutBoxPrintDataBinding(this);
- _printDataBinding.SetDataConnection(_printDataSource, _printDataMember);
- }
- else
- {
- if (_printDataBinding.ContainsDataMember(_printDataSource))
- {
- _printDataMember = string.Empty;
- }
- _printDataBinding.SetDataConnection(_printDataSource, _printDataMember);
- if (_printDataSource == null)
- {
- _printDataBinding = null;
- }
- }
- RefreshItemsPrintBound();
- }
- /// <summary>
- /// 设置打印数据成员
- /// </summary>
- private void SetPrintDataMember()
- {
- if (_printDataBinding == null)
- {
- _printDataBinding = new LayoutBoxPrintDataBinding(this);
- }
- _printDataBinding.SetDataConnection(_printDataSource, _printDataMember);
- RefreshItemsPrintBound();
- }
- /// <summary>
- /// 启动数据更新
- /// </summary>
- private void BeginUpdateInternal()
- {
- if (IsHandleCreated)
- {
- if (_updateCount == 0)
- {
- SendMessage(new HandleRef(this, Handle), 11, 0, 0);
- }
- _updateCount = (short)(_updateCount + 1);
- }
- }
- /// <summary>
- /// 结束数据更新
- /// </summary>
- private void EndUpdateInternal()
- {
- if (_updateCount <= 0)
- {
- return;
- }
- _updateCount = (short)(_updateCount - 1);
- if (_updateCount == 0)
- {
- SendMessage(new HandleRef(this, Handle), 11, -1, 0);
- }
- }
- /// <summary>
- /// 刷新该项目的数据
- /// </summary>
- private void RefreshItemsCurrentPositionValue()
- {
- bool visible = base.Visible;
- if (visible)
- {
- BeginUpdateInternal();
- }
- try
- {
- if (_dataBinding == null)
- {
- return;
- }
- foreach (LayoutItem item in _items)
- {
- if ((item.ItemType == ItemType.Text || item.ItemType == ItemType.TotalText) && _dataBinding != null)
- {
- _dataBinding.BoundDataValueToTextItem(item as TextItem);
- }
- else
- {
- continue;
- }
- }
- }
- finally
- {
- if (visible)
- {
- EndUpdateInternal();
- base.Invalidate(true);
- }
- }
- }
- /// <summary>
- /// 刷新该项目的数据绑定
- /// </summary>
- internal void RefreshItemsBound()
- {
- bool visible = base.Visible;
- if (visible)
- {
- BeginUpdateInternal();
- }
- try
- {
- if (_dataBinding == null)
- {
- return;
- }
- foreach (LayoutItem item in _items)
- {
- if ((item.ItemType == ItemType.Text || item.ItemType == ItemType.TotalText) && _dataBinding != null)
- {
- _dataBinding.BoundFieldToTextItem(item as TextItem);
- }
- else
- {
- continue;
- }
- }
- }
- finally
- {
- if (visible)
- {
- EndUpdateInternal();
- base.Invalidate(true);
- }
- }
- }
- /// <summary>
- /// 刷新文本项目的数据绑定
- /// </summary>
- /// <param name="textItem">文本Item</param>
- internal void RefreshTextItemBound(TextItem textItem)
- {
- bool visible = base.Visible;
- if (visible)
- {
- BeginUpdateInternal();
- }
- try
- {
- if (_dataBinding != null)
- {
- _dataBinding.BoundFieldToTextItem(textItem);
- }
- }
- finally
- {
- if (visible)
- {
- EndUpdateInternal();
- base.Invalidate(true);
- }
- }
- }
- /// <summary>
- /// 刷新该项目的打印数据
- /// </summary>
- internal void RefreshItemsCurrentPositionPrintValue()
- {
- bool visible = base.Visible;
- if (visible)
- {
- BeginUpdateInternal();
- }
- try
- {
- if (_printDataBinding == null)
- {
- return;
- }
- foreach (LayoutItem item in _items)
- {
- if ((item.ItemType == ItemType.Text || item.ItemType == ItemType.TotalText) && _printDataBinding != null)
- {
- _printDataBinding.BoundPrintDataValueToTextItem(item as TextItem);
- }
- else
- {
- continue;
- }
- }
- }
- finally
- {
- if (visible)
- {
- EndUpdateInternal();
- base.Invalidate(true);
- }
- }
- }
- /// <summary>
- /// 刷新该项目的打印数据绑定
- /// </summary>
- internal void RefreshItemsPrintBound()
- {
- bool visible = base.Visible;
- if (visible)
- {
- BeginUpdateInternal();
- }
- try
- {
- if (_printDataBinding == null)
- {
- return;
- }
- foreach (LayoutItem item in _items)
- {
- if ((item.ItemType == ItemType.Text || item.ItemType == ItemType.TotalText) && _printDataBinding != null)
- {
- _printDataBinding.BoundPrintFieldToTextItem(item as TextItem);
- }
- else
- {
- continue;
- }
- }
- }
- finally
- {
- if (visible)
- {
- EndUpdateInternal();
- base.Invalidate(true);
- }
- }
- }
- /// <summary>
- /// 刷新文本项目的打印数据绑定
- /// </summary>
- /// <param name="textItem">文本Item</param>
- internal void RefreshTextItemPrintBound(TextItem textItem)
- {
- bool visible = base.Visible;
- if (visible)
- {
- BeginUpdateInternal();
- }
- try
- {
- if (_printDataBinding != null)
- {
- _printDataBinding.BoundPrintFieldToTextItem(textItem);
- }
- }
- finally
- {
- if (visible)
- {
- EndUpdateInternal();
- base.Invalidate(true);
- }
- }
- }
- #endregion 数据绑定相关
- #region 打印相关
- /// <summary>
- /// 检查打印设置
- /// </summary>
- /// <returns>可以打印true;其他为false</returns>
- public bool CheckPrintSetting()
- {
- // 获取打印机设置非常慢,暂不校验
- return true;
- //string message = this.CheckPrintSettingIn(_printType);
- //if (!string.IsNullOrWhiteSpace(message))
- //{
- // MessageBox.Show(message,
- // "打印失败",
- // MessageBoxButtons.OK,
- // MessageBoxIcon.Error,
- // MessageBoxDefaultButton.Button1);
- // return false;
- //}
- //return true;
- }
- public string CheckPrintSettingIn(PrintType printType)
- {
- // 获取打印机设置非常慢,暂不校验
- return null;
- /*
- if (System.Drawing.Printing.PrinterSettings.InstalledPrinters.Count < 1)
- {
- return "请安装打印机驱动程序。";
- }
- if (PrinterSettings == null || PrinterSettings.DefaultPageSettings == null)
- {
- return "请设置打印机。";
- }
- if (PaperSize == null)
- {
- return "请设置打印纸张大小。";
- }
- if (!printDocument.PrinterSettings.IsValid)
- {
- return string.Format("打印机名称({0}/{1})不正确。"
- , printDocument.PrinterSettings.PrinterName
- , printDialog.PrinterSettings.PrinterName);
- }
- if (short.MaxValue < _numberOfCopies)
- {
- return string.Format("此打印机一次可以打印的最大份数是{0},不能打印{1}份。"
- , short.MaxValue
- , _numberOfCopies);
- }
- if (printType == PrintType.Print || printType == PrintType.PrintPreview)
- {
- if (PrinterSettings.MaximumCopies < _numberOfCopies)
- {
- return string.Format("此打印机一次可以打印的最大份数是{0},不能打印{1}份。"
- , PrinterSettings.MaximumCopies
- , _numberOfCopies);
- }
- }
- else if (printType == PrintType.AllocationPrint || printType == PrintType.AllocationPrintPreview)
- {
- float paperWidth = 0;
- float paperHeight = 0;
- float horizontal = 0;
- float vertical = 0;
- if (_landscape)
- {
- paperWidth = (float)Math.Round(LayoutCommon.Inch100ToMillimeter(PaperSize.Height), 0);
- paperHeight = (float)Math.Round(LayoutCommon.Inch100ToMillimeter(PaperSize.Width), 0);
- horizontal = paperWidth + _allocationHorizontalSpace
- - _marginLeft
- - _marginRight
- - (_allocationHorizontalSpace + _paperWidth)
- * _allocationNumX;
- vertical = paperHeight + _allocationVerticalSpace
- - _marginTop
- - _marginBottom
- - (_allocationVerticalSpace + _paperHeight)
- * _allocationNumY;
- }
- else
- {
- paperWidth = (float)Math.Round(LayoutCommon.Inch100ToMillimeter(PaperSize.Width), 0);
- paperHeight = (float)Math.Round(LayoutCommon.Inch100ToMillimeter(PaperSize.Height), 0);
- horizontal = paperWidth + _allocationHorizontalSpace
- - _marginLeft
- - _marginRight
- - (_allocationHorizontalSpace + _paperWidth)
- * _allocationNumX;
- vertical = paperHeight + _allocationVerticalSpace
- - _marginTop
- - _marginBottom
- - (_allocationVerticalSpace + _paperHeight)
- * _allocationNumY;
- }
- if (horizontal < 0 && vertical < 0)
- {
- return "设置值大于纸张尺寸。请检查纸张横纵个数,间距,和余白。";
- }
- if (horizontal < 0)
- {
- return string.Format("分配的纸张宽度不能打印{0}列,请确认。"
- , _allocationNumX);
- }
- if (vertical < 0)
- {
- return string.Format("分配的纸张高度不能打印{0}行,请确认。"
- , _allocationNumY);
- }
- }
- return null;
- */
- }
- /// <summary>
- /// 打印背景图片
- /// </summary>
- /// <param name="graphics">用于绘制的System.Drawing.Graphics</param>
- private void PrintBackgroundImage(Graphics graphics)
- {
- if (BackgroundImage != null)
- {
- // 背景图片的高宽比例
- float imgWHRate = (float)BackgroundImage.Width / (float)BackgroundImage.Height;
- // 打印纸张的高宽比例
- float paperWHRate = PaperWidth / PaperHeight;
- // 背景图片打印范围
- RectangleF newImgRectangleF = RectangleF.Empty;
- // 缩放背景图片,但保持图片高宽比例
- if (imgWHRate > paperWHRate)
- {
- newImgRectangleF.Width = PaperWidth;
- newImgRectangleF.Height = PaperWidth / imgWHRate;
- newImgRectangleF.X = _allOffsetX;
- newImgRectangleF.Y = (PaperHeight - newImgRectangleF.Height) / 2 + _allOffsetY;
- }
- else
- {
- newImgRectangleF.Width = PaperHeight * imgWHRate;
- newImgRectangleF.Height = PaperHeight;
- newImgRectangleF.X = (PaperWidth - newImgRectangleF.Width) / 2 + _allOffsetX;
- newImgRectangleF.Y = _allOffsetY;
- }
- // 在指定的范围绘制背景图片
- graphics.DrawImage(BackgroundImage, newImgRectangleF);
- }
- }
- /// <summary>
- /// 打印文本Item
- /// </summary>
- /// <param name="graphics">用于绘制的System.Drawing.Graphics</param>
- /// <param name="textItem">文本Item</param>
- private void DrawTextItem(Graphics graphics, TextItem textItem)
- {
- // 文本Item打印范围
- RectangleF rectangleFM = new RectangleF(
- _allOffsetX + textItem.Left,
- _allOffsetY + textItem.Top,
- textItem.Width,
- textItem.Height);
- RectangleF rectangleF = rectangleFM;
- rectangleF.Inflate(0 - LayoutConsts.TEXT_MARGIN, 0 - LayoutConsts.TEXT_MARGIN);
- rectangleFM.Height -= LayoutConsts.TEXT_MARGIN;
- /* Edit For Draw Pic
- // 在指定的范围绘制文本Item
- LayoutUtility.DrawText(graphics,
- rectangleFM,
- rectangleF,
- textItem.PrintText,
- textItem.Font,
- textItem.TextColor,
- textItem.LineSpace,
- textItem.CharacterSpace,
- textItem.CharacterCount,
- textItem.TextAlign,
- textItem.Wrap,
- textItem.Clip,
- false);
- */
- textItem.DrawTextItem(textItem.PrintDataValue, textItem.PrintBoundField, graphics, rectangleFM, rectangleF, true);
- }
- /// <summary>
- /// 打印图片Item
- /// </summary>
- /// <param name="graphics">用于绘制的System.Drawing.Graphics</param>
- /// <param name="imageItem">图片Item</param>
- private void DrawImageItem(Graphics graphics, ImageItem imageItem)
- {
- // 图片Item打印范围
- RectangleF rectangleF = new RectangleF(
- _allOffsetX + imageItem.Left,
- _allOffsetY + imageItem.Top,
- imageItem.Width,
- imageItem.Height);
- // 在指定的范围绘制图片Item
- LayoutUtility.DrawImage(graphics, rectangleF, imageItem.Image);
- }
- /// <summary>
- /// 打印矩形Item
- /// </summary>
- /// <param name="graphics">用于绘制的System.Drawing.Graphics</param>
- /// <param name="rectangleItem">矩形Item</param>
- private void DrawRectangleItem(Graphics graphics, RectangleItem rectangleItem)
- {
- // 矩形Item打印范围
- RectangleF rectangleF = new RectangleF(
- _allOffsetX + rectangleItem.Left,
- _allOffsetY + rectangleItem.Top,
- rectangleItem.Width,
- rectangleItem.Height);
- float lineWidthDraw = rectangleItem.LineWidth;
- // 在指定的范围绘制矩形Item
- LayoutUtility.DrawRectangle(graphics, rectangleF, rectangleItem.LineColor,
- rectangleItem.FillColor, lineWidthDraw, rectangleItem.Transparent);
- }
- /// <summary>
- /// 打印椭圆Item
- /// </summary>
- /// <param name="graphics">用于绘制的System.Drawing.Graphics</param>
- /// <param name="ellipseItem">椭圆Item</param>
- private void DrawEllipseItem(Graphics graphics, EllipseItem ellipseItem)
- {
- // 椭圆Item打印范围
- RectangleF rectangleF = new RectangleF(
- _allOffsetX + ellipseItem.Left,
- _allOffsetY + ellipseItem.Top,
- ellipseItem.Width,
- ellipseItem.Height);
- float lineWidthDraw = ellipseItem.LineWidth;
- // 在指定的范围绘制椭圆Item
- LayoutUtility.DrawEllipse(graphics, rectangleF, ellipseItem.LineColor,
- ellipseItem.FillColor, lineWidthDraw, ellipseItem.Transparent);
- }
- /// <summary>
- /// 打印表格Item
- /// </summary>
- /// <param name="graphics">用于绘制的System.Drawing.Graphics</param>
- /// <param name="gridItem">表格Item</param>
- private void DrawGridItem(Graphics graphics, GridItem gridItem)
- {
- // 表格Item打印范围
- RectangleF rectangleF = new RectangleF(
- _allOffsetX + gridItem.Left,
- _allOffsetY + gridItem.Top,
- gridItem.Width,
- gridItem.Height);
- //// 在指定的范围绘制表格Item
- gridItem.DrawGridItem(graphics, rectangleF, 1, _printPageNum);
- }
- /// <summary>
- /// 打印页码Item
- /// </summary>
- /// <param name="graphics">用于绘制的System.Drawing.Graphics</param>
- /// <param name="pageNumItem">页码Item</param>
- private void DrawPageNumItem(Graphics graphics, PageNumItem pageNumItem)
- {
- // 文本Item打印范围
- RectangleF rectangleFM = new RectangleF(
- _allOffsetX + pageNumItem.Left,
- _allOffsetY + pageNumItem.Top,
- pageNumItem.Width,
- pageNumItem.Height);
- RectangleF rectangleF = rectangleFM;
- rectangleF.Inflate(0 - LayoutConsts.TEXT_MARGIN, 0 - LayoutConsts.TEXT_MARGIN);
- rectangleFM.Height -= LayoutConsts.TEXT_MARGIN;
- // 在指定的范围绘制文本Item
- LayoutUtility.DrawText(graphics,
- rectangleFM,
- rectangleF,
- pageNumItem.PrintText,
- pageNumItem.Font,
- pageNumItem.TextColor,
- 0,
- 0,
- 0,
- pageNumItem.TextAlign,
- pageNumItem.TextAlignVertical,
- false,
- false,
- false);
- }
- /// <summary>
- /// 打印合计Item
- /// </summary>
- /// <param name="graphics">用于绘制的System.Drawing.Graphics</param>
- /// <param name="totalTextItem">合计Item</param>
- private void DrawTotalTextItem(Graphics graphics, TotalTextItem totalTextItem)
- {
- // 文本Item打印范围
- RectangleF rectangleFM = new RectangleF(
- _allOffsetX + totalTextItem.Left,
- _allOffsetY + totalTextItem.Top,
- totalTextItem.Width,
- totalTextItem.Height);
- RectangleF rectangleF = rectangleFM;
- rectangleF.Inflate(0 - LayoutConsts.TEXT_MARGIN, 0 - LayoutConsts.TEXT_MARGIN);
- rectangleFM.Height -= LayoutConsts.TEXT_MARGIN;
- if (PrintPageNum != TotalPageNum)
- {
- LayoutUtility.DrawText(graphics,
- rectangleFM,
- rectangleF,
- totalTextItem.NotTotalValue,
- totalTextItem.NotTotalFont,
- totalTextItem.NotTotalColor,
- totalTextItem.LineSpace,
- totalTextItem.CharacterSpace,
- totalTextItem.CharacterCount,
- totalTextItem.NotTotalAlign,
- totalTextItem.NotTotalAlignVertical,
- totalTextItem.Wrap,
- totalTextItem.Clip,
- false);
- return;
- }
- // 在指定的范围绘制文本Item
- string text = totalTextItem.ResetTextValue(totalTextItem.PrintDataValue, totalTextItem.BoundField.IsDataBound) as string;
- LayoutUtility.DrawText(graphics,
- rectangleFM,
- rectangleF,
- text,
- totalTextItem.Font,
- totalTextItem.TextColor,
- totalTextItem.LineSpace,
- totalTextItem.CharacterSpace,
- totalTextItem.CharacterCount,
- totalTextItem.TextAlign,
- totalTextItem.NotTotalAlignVertical,
- totalTextItem.Wrap,
- totalTextItem.Clip,
- false);
- }
- #endregion 打印相关
- #region 事件
- /// <summary>
- /// 当一个项目被改变,移动,添加或删除引发此事件。
- /// </summary>
- /// <param name="layoutItem">Item</param>
- /// <param name="itemChangeType">变更类型</param>
- internal void SetItemChangedArgs(LayoutItem layoutItem, ItemChangeType itemChangeType)
- {
- if (ItemChanged != null && !layoutItem.IsNew)
- {
- ItemChangedEventArgs e = new ItemChangedEventArgs();
- e.Item = layoutItem;
- e.ChangedType = itemChangeType;
- e.ItemID = layoutItem.ID;
- _isDirty = true;
- ItemChanged(this, e);
- }
- if (itemChangeType != ItemChangeType.Deleted)
- {
- layoutItem.Shape.Refresh();
- }
- else
- {
- if (layoutItem.ItemType == ItemType.Grid)
- {
- this.OneGridItem = null;
- }
- }
- }
- /// <summary>
- /// 当一个项目被改变,移动,添加或删除引发此事件。
- /// </summary>
- /// <param name="layoutItem">Item</param>
- /// <param name="itemChangeType">变更类型</param>
- /// <param name="property">属性</param>
- internal void SetItemChangedArgs(LayoutItem layoutItem, ItemChangeType itemChangeType, string property)
- {
- if (ItemChanged != null && !layoutItem.IsNew)
- {
- ItemChangedEventArgs e = new ItemChangedEventArgs();
- e.Item = layoutItem;
- e.ChangedType = itemChangeType;
- e.ItemID = layoutItem.ID;
- e.Property = property;
- _isDirty = true;
- ItemChanged(this, e);
- }
- if (itemChangeType != ItemChangeType.Deleted)
- {
- layoutItem.Shape.Refresh();
- }
- else
- {
- if (layoutItem.ItemType == ItemType.Grid)
- {
- this.OneGridItem = null;
- }
- }
- }
- /// <summary>
- /// 项目的选择状态改变时引发此事件。
- /// </summary>
- /// <param name="layoutItem">Item</param>
- /// <param name="isSelect">选择状态</param>
- internal void SetItemSelectionChangedArgs(LayoutItem layoutItem, bool isSelect)
- {
- SetTSMIOnSelectionChanged();
- if (ItemSelectionChanged != null && !layoutItem.IsNew)
- {
- ItemSelectionChangedEventArgs e = new ItemSelectionChangedEventArgs();
- e.Item = layoutItem;
- e.IsSelected = isSelect;
- e.ItemID = layoutItem.ID;
- ItemSelectionChanged(this, e);
- }
- }
- /// <summary>
- /// 打印或显示数据之前引发此事件。
- /// </summary>
- /// <param name="layoutItem">Item</param>
- /// <param name="value">数据</param>
- /// <param name="format">格式</param>
- /// <returns>e.Result格式化后结果</returns>
- internal object SetItemValueFormattingArgs(LayoutItem layoutItem, object value, string format)
- {
- if (ItemValueFormatting != null && !layoutItem.IsNew)
- {
- ItemValueFormattingEventArgs e = new ItemValueFormattingEventArgs();
- e.Item = layoutItem;
- e.ItemID = layoutItem.ID;
- e.Value = value;
- e.Format = format;
- ItemValueFormatting(this, e);
- return e.Result;
- }
- return null;
- }
- internal void SetUserChangedGridItemArgs(GridItem gItem, CollectionChangeEventArgs e)
- {
- if (this.UserChangedGridItem != null)
- {
- this.UserChangedGridItem(gItem, e);
- }
- }
- #endregion 事件
- #endregion private函数
- #region 事件处理
- #region 缩放比例和位置
- /// <summary>
- /// 调整纸张大小
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void PaperBox_SizeChanged(object sender, EventArgs e)
- {
- if (_zoomType == ZoomType.Whole)
- {
- InitializeZoom();
- }
- else
- {
- AdjustPaperArea();
- }
- }
- #endregion 缩放比例和位置
- #region 右键菜单
- /// <summary>
- /// 打开右键菜单
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void contextMenu_Opening(object sender, CancelEventArgs e)
- {
- //SetTSMIOnSelectionChanged();
- tsmiPaste.Enabled = (_clipboardFormat != null && Clipboard.ContainsData(_clipboardFormat.Name));
- }
- /// <summary>
- /// 打开对齐右键菜单
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void contextMenuArrange_Opening(object sender, CancelEventArgs e)
- {
- e.Cancel = !tsmiArrange.Enabled;
- }
- /// <summary>
- /// 打开排序右键菜单
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void contextMenuOrder_Opening(object sender, CancelEventArgs e)
- {
- e.Cancel = !tsmiOrder.Enabled;
- }
- /// <summary>
- /// 关闭右键菜单
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void contextMenu_Closing(object sender, ToolStripDropDownClosingEventArgs e)
- {
- tsmiPaste.Enabled = true;
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiDelete_Click(object sender, EventArgs e)
- {
- DeleteItem();
- }
- /// <summary>
- /// 属性
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiProperties_Click(object sender, EventArgs e)
- {
- ShowItemPropertyDialog();
- }
- /// <summary>
- /// 选择全部Item
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiAllSelect_Click(object sender, EventArgs e)
- {
- SelectItemsMultiple(_items.ToArray(), true);
- }
- /// <summary>
- /// 纸张大小
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiPaperSize_Click(object sender, EventArgs e)
- {
- ShowPaperPropertyDialog();
- }
- /// <summary>
- /// 背景图片
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiBackgroundImage_Click(object sender, EventArgs e)
- {
- ShowBackgroundSettingDialog();
- }
- /// <summary>
- /// 打开缩放比例右键菜单
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void contextMenuZoom_Opening(object sender, CancelEventArgs e)
- {
- tsmiZoom500.Checked = false;
- tsmiZoom200.Checked = false;
- tsmiZoom100.Checked = false;
- tsmiZoom75.Checked = false;
- tsmiZoom50.Checked = false;
- tsmiZoom33.Checked = false;
- tsmiZoom25.Checked = false;
- tsmiZoom10.Checked = false;
- tsmiZoomWhole.Checked = false;
- switch (_zoom)
- {
- case 500:
- tsmiZoom500.Checked = true;
- break;
- case 200:
- tsmiZoom200.Checked = true;
- break;
- case 100:
- tsmiZoom100.Checked = true;
- break;
- case 75:
- tsmiZoom75.Checked = true;
- break;
- case 50:
- tsmiZoom50.Checked = true;
- break;
- case 33:
- tsmiZoom33.Checked = true;
- break;
- case 25:
- tsmiZoom25.Checked = true;
- break;
- case 10:
- tsmiZoom10.Checked = true;
- break;
- default:
- tsmiZoomWhole.Checked = true;
- break;
- }
- }
- /// <summary>
- /// 缩放比例
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiZoom_Click(object sender, EventArgs e)
- {
- ToolStripMenuItem itemZoom = sender as ToolStripMenuItem;
- if (itemZoom == null)
- {
- return;
- }
- int zoom = System.Convert.ToInt32(itemZoom.Tag);
- if (zoom > 0)
- {
- Zoom = zoom;
- }
- else
- {
- ZoomType = ZoomType.Whole;
- }
- }
- /// <summary>
- /// 置于顶层
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiForemost_Click(object sender, EventArgs e)
- {
- ChangeItemsOrderForemost();
- }
- /// <summary>
- /// 上移一层
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiFront_Click(object sender, EventArgs e)
- {
- ChangeItemsOrderFront();
- }
- /// <summary>
- /// 下移一层
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiBack_Click(object sender, EventArgs e)
- {
- ChangeItemsOrderBack();
- }
- /// <summary>
- /// 置于底层
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiAftermost_Click(object sender, EventArgs e)
- {
- ChangeItemsOrderAftermost();
- }
- /// <summary>
- /// 顶端对齐
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiTop_Click(object sender, EventArgs e)
- {
- ArrangeItemsTop();
- }
- /// <summary>
- /// 底端对齐
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiBottom_Click(object sender, EventArgs e)
- {
- ArrangeItemsBottom();
- }
- /// <summary>
- /// 垂直居中对齐
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiVerticalCenter_Click(object sender, EventArgs e)
- {
- ArrangeItemsVerticalCenter();
- }
- /// <summary>
- /// 右侧对齐
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiRight_Click(object sender, EventArgs e)
- {
- ArrangeItemsRight();
- }
- /// <summary>
- /// 左侧对齐
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiLeft_Click(object sender, EventArgs e)
- {
- ArrangeItemsLeft();
- }
- /// <summary>
- /// 水平居中对齐
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiHorizontalCenter_Click(object sender, EventArgs e)
- {
- ArrangeItemsHorizontalCenter();
- }
- /// <summary>
- /// 剪切
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiCut_Click(object sender, EventArgs e)
- {
- CutItem();
- }
- /// <summary>
- /// 复制
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiCopy_Click(object sender, EventArgs e)
- {
- CopyItem();
- }
- /// <summary>
- /// 粘贴
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void tsmiPaste_Click(object sender, EventArgs e)
- {
- PasteItem();
- }
- #endregion 右键菜单
- #region Item操作相关
- /// <summary>
- /// Item选择边框失去焦点时发生。
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void RectTracker_LostFocus(object sender, EventArgs e)
- {
- if (_moveRectangles != null && _isMouseMove)
- {
- //if (!_isRealFollow)
- {
- int count = _moveRectangles.Length;
- for (int i = 0; i < count; i++)
- {
- DrawReversibleFrame(_selectedItems[i].ItemLockType, _moveRectangles[i], null);
- }
- }
- _isMouseDown = false;
- _isMouseMove = false;
- _moveRectangles = null;
- }
- }
- /// <summary>
- /// Item选择边框 KeyDown事件
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void RectTracker_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.ShiftKey && !_isShiftDown)
- {
- _isShiftDown = true;
- }
- else if (e.KeyCode == Keys.ControlKey && !_isCtrlDown)
- {
- _isCtrlDown = true;
- }
- else
- {
- return;
- }
- if (_isMouseMove)
- {
- int count = _moveRectangles.Length;
- for (int i = 0; i < count; i++)
- {
- ResizeToRectangle(new Point(_mouseMoveX, _mouseMoveY), i);
- }
- }
- }
- /// <summary>
- /// Item选择边框 KeyUp事件
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void RectTracker_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.ShiftKey)
- {
- _isShiftDown = false;
- }
- else if (e.KeyCode == Keys.ControlKey)
- {
- _isCtrlDown = false;
- }
- else
- {
- return;
- }
- if (_isMouseMove)
- {
- int count = _moveRectangles.Length;
- for (int i = 0; i < count; i++)
- {
- ResizeToRectangle(new Point(_mouseMoveX, _mouseMoveY), i);
- }
- }
- }
- /// <summary>
- /// Item选择边框 MouseDown事件
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void RectTracker_MouseDown(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left)
- {
- if (ItemShapeContainer.ClientRectangle.Contains(e.Location))
- {
- _startX = e.X;
- _startY = e.Y;
- _mouseMoveX = e.X;
- _mouseMoveY = e.Y;
- int count = _selectedItems.Count;
- _downRectangles = new Rectangle[count];
- _moveRectangles = new Rectangle[count];
- for (int i = 0; i < count; i++)
- {
- _downRectangles[i] = _selectedItems[i].ShapeBounds;
- _moveRectangles[i] = _downRectangles[i];
- }
- _isMouseDown = true;
- Cursor.Current = Cursors.SizeAll;
- }
- }
- }
- /// <summary>
- /// Item选择边框 MouseMove事件
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void RectTracker_MouseMove(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left && _isMouseDown)
- {
- Cursor.Current = Cursors.SizeAll;
- int mx = e.X;
- int my = e.Y;
- if (_mouseMoveX != mx || _mouseMoveY != my)
- {
- int count = _moveRectangles.Length;
- for (int i = 0; i < count; i++)
- {
- ResizeToRectangle(new Point(mx, my), i);
- }
- _isMouseMove = true;
- _mouseMoveX = mx;
- _mouseMoveY = my;
- }
- }
- }
- /// <summary>
- /// Item选择边框 MouseUp事件
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void RectTracker_MouseUp(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left && _isMouseDown)
- {
- if (_isMouseMove)
- {
- Capture = false;
- int count = _moveRectangles.Length;
- for (int i = 0; i < count; i++)
- {
- DrawReversibleFrame(_selectedItems[i].ItemLockType, _moveRectangles[i], null);
- DragHandler(_selectedItems[i], _moveRectangles[i]);
- }
- }
- _isMouseDown = false;
- _isMouseMove = false;
- _moveRectangles = null;
- }
- }
- /// <summary>
- /// 鼠标在纸张范围内移动
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void paperArea_MouseMove(object sender, MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left && _layoutMode == LayoutMode.Edit)
- {
- if (_isMouseDownInPaperArea)
- {
- _mouseRect.X = e.X;
- _mouseRect.Y = e.Y;
- _isMouseDownInPaperArea = false;
- _isMouseMoveInPaperArea = true;
- }
- else if (_isMouseMoveInPaperArea)
- {
- ResizeToRectangle(e.Location);
- }
- }
- }
- /// <summary>
- /// 鼠标在纸张范围内抬起
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void paperArea_MouseUp(object sender, MouseEventArgs e)
- {
- if (_layoutMode != LayoutMode.Edit || e.Button != MouseButtons.Left)
- {
- return;
- }
- if (_isMouseMoveInPaperArea)
- {
- Capture = false;
- DrawReversibleFrame(_mouseRect);
- bool isChanging = false;
- if (Items.Count > 0)
- {
- if (_mouseRect.Height > 0 && _mouseRect.Width > 0)
- {
- //_mouseRect.X = _mouseRect.X - paperArea.Left;
- //_mouseRect.Y = _mouseRect.Y - paperArea.Top;
- }
- else if (_mouseRect.Height <= 0 && _mouseRect.Width > 0)
- {
- //_mouseRect.X = _mouseRect.X - paperArea.Left;
- _mouseRect.Y = e.Y;
- _mouseRect.Height = Math.Abs(_mouseRect.Height);
- //_mouseRect.Width = Math.Abs(_mouseRect.Width);
- }
- else if (_mouseRect.Height > 0 && _mouseRect.Width <= 0)
- {
- _mouseRect.X = e.X;
- //_mouseRect.Y = _mouseRect.Y - paperArea.Top;
- _mouseRect.Width = Math.Abs(_mouseRect.Width);
- }
- else if (_mouseRect.Height <= 0 && _mouseRect.Width <= 0)
- {
- _mouseRect.X = e.X;
- _mouseRect.Y = e.Y;
- _mouseRect.Height = Math.Abs(_mouseRect.Height);
- _mouseRect.Width = Math.Abs(_mouseRect.Width);
- }
- ItemSelectionChanging = true;
- if (Control.ModifierKeys == Keys.Control)
- {
- foreach (LayoutItem item in _items)
- {
- if (item.BoundsContainsBy(_mouseRect))
- {
- SelectItemMultiple(item, !item.Selected, ref isChanging);
- }
- }
- }
- else if (Control.ModifierKeys == Keys.Shift)
- {
- foreach (LayoutItem item in _items)
- {
- if (item.BoundsContainsBy(_mouseRect))
- {
- SelectItemMultiple(item, true, ref isChanging);
- }
- }
- }
- else
- {
- foreach (LayoutItem item in _items)
- {
- //if (item.BoundsContainsBy(_mouseRect))
- //{
- // SelectItemMultiple(item, true, ref isChanging);
- //}
- //else
- //{
- // SelectItemMultiple(item, false, ref isChanging);
- //}
- bool isSelet = false;
- if (item.ShapeBounds.Height <= 1 ||
- item.ShapeBounds.Width <= 1)
- {
- isSelet = item.IntersectsWith(_mouseRect);
- }
- else
- {
- isSelet = item.BoundsContainsBy(_mouseRect);
- }
- SelectItemMultiple(item, isSelet, ref isChanging);
- }
- }
- }
- ItemSelectionChanging = false;
- if (isChanging)
- {
- if (UserSelectionChanged != null)
- {
- UserSelectionChanged(this, EventArgs.Empty);
- }
- }
- _isMouseMoveInPaperArea = false;
- _mouseRect = Rectangle.Empty;
- }
- }
- /// <summary>
- /// 鼠标在纸张范围内按下
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void paperArea_MouseDown(object sender, MouseEventArgs e)
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return;
- }
- if (e.Button == MouseButtons.Left)
- {
- _isMouseDownInPaperArea = true;
- _isMouseMoveInPaperArea = false;
- }
- }
- /// <summary>
- /// 鼠标在纸张范围内点击
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void paperArea_Click(object sender, EventArgs e)
- {
- if (_layoutMode != LayoutMode.Edit)
- {
- return;
- }
- // 选择状态全部解除
- if (Control.ModifierKeys == Keys.Control || Control.ModifierKeys == Keys.Shift)
- {
- return;
- }
- ClearSelection();
- paperArea.Focus();
- }
- #endregion Item操作相关
- #region 打印相关
- //private PageSettings _defaultPageSettings = null;
- //private PaperSize _defaultPaperSize = null;
- //private RectangleF _defaultPrintableArea = RectangleF.Empty;
- /// <summary>
- /// 打印开始。
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void printDocument_BeginPrint(object sender, PrintEventArgs e)
- {
- //#if DEBUG
- // Dongke.IBOSS.PRD.Basics.Library.OutputLog.TraceLog(Dongke.IBOSS.PRD.Basics.Library.LogPriority.Debug,
- // "printDocument_BeginPrint",
- // "begin",
- // DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff"),
- // Dongke.IBOSS.PRD.Basics.Library.LocalPath.LogExePath + @"printdebug\");
- //#endif
- // 选定打印页码 modify by chenxy 2014-03-27 begin
- //if (PrinterSettings.PrintRange == PrintRange.SomePages)
- //{
- // if (PrinterSettings.ToPage == 0 || TotalPageNum < PrinterSettings.FromPage)
- // {
- // e.Cancel = true;
- // return;
- // }
- //}
- // 选定打印页码 modify by chenxy 2014-03-27 end
- //if (_numberOfCopies < 1 || !CheckPrintSetting())
- //{
- // e.Cancel = true;
- // return;
- //}
- // 获取打印机配置非常慢,
- //_defaultPageSettings = PrinterSettings.DefaultPageSettings;
- //_defaultPaperSize = _defaultPageSettings.PaperSize;
- //_defaultPrintableArea = _defaultPageSettings.PrintableArea;
- // 页面左上点的坐标(1/100英寸)
- if (_printAction == PrintAction.PrintToPreview)
- {
- _printerOffsetX = 0;
- _printerOffsetY = 0;
- _allOffsetX = _printOffsetX;
- _allOffsetY = _printOffsetY;
- }
- else
- {
- //if (_landscape)
- //{
- // _printerOffsetX = LayoutCommon.Inch100ToMillimeter(_defaultPaperSize.Height - _defaultPrintableArea.Bottom);
- // _printerOffsetY = LayoutCommon.Inch100ToMillimeter(_defaultPrintableArea.Left);
- //}
- //else
- //{
- // _printerOffsetX = LayoutCommon.Inch100ToMillimeter(_defaultPrintableArea.Left);
- // _printerOffsetY = LayoutCommon.Inch100ToMillimeter(_defaultPrintableArea.Top);
- //}
- _allOffsetX = _printOffsetX - _printerOffsetX;
- _allOffsetY = _printOffsetY - _printerOffsetY;
- }
- _rectangleFGreed = RectangleF.Empty;
- _printPageNum = 1;
- if (_printType == PrintType.PrintTest)
- {
- //printDocument.PrinterSettings.Copies = 1;
- }
- else if (_printType == PrintType.Print || _printType == PrintType.PrintPreview)
- {
- if (_printDataBinding != null && _printDataBinding.BindingSource != null && 0 < _printDataBinding.BindingSource.Count)
- {
- _printDataBinding.BindingSource.MoveFirst();
- _printDataTotal = _printDataBinding.BindingSource.Count * _numberOfCopies;
- }
- else
- {
- _printDataTotal = _numberOfCopies;
- }
- _printDataPosition = 0;
- _printDataCopies = 0;
- //if (_printType == PrintType.Print)
- if (_printAction == PrintAction.PrintToPrinter)
- {
- printDocument.PrinterSettings.Copies = (short)_numberOfCopies;
- }
- else
- {
- printDocument.PrinterSettings.Copies = 1;
- }
- }
- else if (_printType == PrintType.AllocationPrint || _printType == PrintType.AllocationPrintPreview)
- {
- if (_printDataBinding != null && _printDataBinding.BindingSource != null && 0 < _printDataBinding.BindingSource.Count)
- {
- _printDataBinding.BindingSource.MoveFirst();
- _printDataTotal = _printDataBinding.BindingSource.Count * _numberOfCopies;
- }
- else
- {
- _printDataTotal = _numberOfCopies;
- }
- _printDataPosition = 0;
- _printDataCopies = 0;
- _allocationNum = _allocationNumY * _allocationNumX;
- _printDataTotal = _printDataTotal + _allocationSkipCount;
- printDocument.PrinterSettings.Copies = 1;
- }
- else
- {
- printDocument.PrinterSettings.Copies = 1;
- }
- //#if DEBUG
- // Dongke.IBOSS.PRD.Basics.Library.OutputLog.TraceLog(Dongke.IBOSS.PRD.Basics.Library.LogPriority.Debug,
- // "printDocument_BeginPrint",
- // "end",
- // DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff"),
- // Dongke.IBOSS.PRD.Basics.Library.LocalPath.LogExePath + @"printdebug\");
- //#endif
- }
- // 选定打印页码 modify by chenxy 2014-03-27 begin
- /// <summary>
- /// 打印每页
- /// </summary>
- /// <param name="sender">指定的对象</param>
- /// <param name="e">提供的事件数据</param>
- private void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
- {
- //#if DEBUG
- // Dongke.IBOSS.PRD.Basics.Library.OutputLog.TraceLog(Dongke.IBOSS.PRD.Basics.Library.LogPriority.Debug,
- // "PrintDocument_PrintPage",
- // "begin",
- // DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff"),
- // Dongke.IBOSS.PRD.Basics.Library.LocalPath.LogExePath + @"printdebug\");
- //#endif
- /*
- if (PrinterSettings.PrintRange == PrintRange.SomePages)
- {
- bool isPrintCurrentPage = false;
- do
- {
- if (_printPageNum < PrinterSettings.FromPage)
- {
- isPrintCurrentPage = false;
- }
- else if (PrinterSettings.ToPage < _printPageNum)
- {
- isPrintCurrentPage = false;
- e.HasMorePages = false;
- e.Cancel = true;
- return;
- }
- else
- {
- isPrintCurrentPage = true;
- }
- if (isPrintCurrentPage)
- {
- e.Cancel = false;
- this.PrintPage(e);
- if (_printPageNum - 1 == PrinterSettings.ToPage)
- {
- e.HasMorePages = false;
- }
- }
- else
- {
- e.Cancel = true;
- if (_printType == PrintType.PrintTest)
- {
- e.HasMorePages = false;
- return;
- }
- else if (_printType == PrintType.Print || _printType == PrintType.PrintPreview)
- {
- // 表格Item是否有下一页
- if (_printPageNum < TotalPageNum)
- {
- _printPageNum++;
- e.HasMorePages = true;
- //return;
- }
- else
- {
- if (_printAction == PrintAction.PrintToPrinter)
- {
- // 纸张数是否增加判断
- if (_printDataBinding != null && _printDataBinding.BindingSource != null && 0 < _printDataBinding.BindingSource.Count)
- {
- if (_printDataBinding.BindingSource.Position + 1 < _printDataBinding.BindingSource.Count)
- {
- // 打印数据源下移一条记录
- _printDataBinding.BindingSource.MoveNext();
- _printPageNum = 1;
- e.HasMorePages = true;
- }
- else
- {
- e.HasMorePages = false;
- return;
- }
- }
- else
- {
- e.HasMorePages = false;
- return;
- }
- }
- else
- {
- // 纸张数是否增加判断
- if (++_printDataPosition < _printDataTotal)
- {
- _printPageNum = 1;
- e.HasMorePages = true;
- // 同一数据一次印刷/分批印刷
- if (true)
- {
- // 同一数据一次印刷
- if (++_printDataCopies < _numberOfCopies)
- {
- return;
- }
- else
- {
- _printDataCopies = 0;
- }
- }
- }
- else
- {
- e.HasMorePages = false;
- return;
- }
- if (_printDataBinding != null && _printDataBinding.BindingSource != null && 0 < _printDataBinding.BindingSource.Count)
- {
- // 打印数据源下移一条记录
- if (_printDataBinding.BindingSource.Position + 1 < _printDataBinding.BindingSource.Count)
- {
- _printDataBinding.BindingSource.MoveNext();
- }
- else
- {
- _printDataBinding.BindingSource.MoveFirst();
- }
- }
- }
- }
- }
- else if (_printType == PrintType.AllocationPrint || _printType == PrintType.AllocationPrintPreview)
- {
- int allocationIndex = -1;
- // 一张纸打印
- for (int i = 0; i < _allocationNum; i++)
- {
- allocationIndex++;
- if (_printDataPosition < _allocationSkipCount)
- {
- // 跳过的打印位置
- e.HasMorePages = true;
- continue;
- }
- // 表格Item是否有下一页
- if (_printPageNum < TotalPageNum)
- {
- _printPageNum++;
- continue;
- }
- // 纸张数是否增加判断
- if (++_printDataPosition < _printDataTotal)
- {
- _printPageNum = 1;
- e.HasMorePages = true;
- // 同一数据一次印刷/分批印刷
- if (true)
- {
- // 同一数据一次印刷
- if (++_printDataCopies < _numberOfCopies)
- {
- continue;
- }
- else
- {
- _printDataCopies = 0;
- }
- }
- }
- else
- {
- e.HasMorePages = false;
- break;
- }
- if (_printDataBinding != null && _printDataBinding.BindingSource != null && 1 < _printDataBinding.BindingSource.Count)
- {
- // 打印数据源下移一条记录
- if (_printDataBinding.BindingSource.Position + 1 < _printDataBinding.BindingSource.Count)
- {
- _printDataBinding.BindingSource.MoveNext();
- }
- else
- {
- _printDataBinding.BindingSource.MoveFirst();
- }
- }
- }
- // 纸张数是否增加判断
- if (e.HasMorePages && _printDataPosition < _printDataTotal)
- {
- e.HasMorePages = true;
- }
- else
- {
- e.HasMorePages = false;
- return;
- }
- }
- else
- {
- e.HasMorePages = false;
- return;
- }
- //e.HasMorePages = false;
- //e.Graphics.Clear(Color.White);
- }
- } while (!isPrintCurrentPage);
- }
- else
- */
- {
- this.PrintPage(e);
- }
-
- //#if DEBUG
- // Dongke.IBOSS.PRD.Basics.Library.OutputLog.TraceLog(Dongke.IBOSS.PRD.Basics.Library.LogPriority.Debug,
- // "PrintDocument_PrintPage",
- // "end",
- // DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff"),
- // Dongke.IBOSS.PRD.Basics.Library.LocalPath.LogExePath + @"printdebug\");
- //#endif
- }
- private void PrintPage(PrintPageEventArgs e)
- {
- e.Graphics.PageUnit = GraphicsUnit.Millimeter;
- if (_isPrintAreaVisible && _rectangleFGreed.IsEmpty)
- {
- //if (_landscape)
- //{
- // // 横向打印
- // _rectangleFGreed = new RectangleF(
- // (_defaultPaperSize.Height - _defaultPrintableArea.Bottom) / 100 * e.Graphics.DpiY,
- // _defaultPrintableArea.Left / 100 * e.Graphics.DpiX,
- // _defaultPrintableArea.Height / 100 * e.Graphics.DpiY,
- // _defaultPrintableArea.Width / 100 * e.Graphics.DpiX);
- //}
- //else
- //{
- // // 纵向打印
- // _rectangleFGreed = new RectangleF(
- // _defaultPrintableArea.Left / 100 * e.Graphics.DpiX,
- // _defaultPrintableArea.Top / 100 * e.Graphics.DpiY,
- // _defaultPrintableArea.Width / 100 * e.Graphics.DpiX,
- // _defaultPrintableArea.Height / 100 * e.Graphics.DpiY);
- //}
- _rectangleFGreed = new RectangleF(
- 0,
- 0,
- LayoutCommon.MillimeterToInch100Single(this.PaperWidth) / 100 * e.Graphics.DpiX,
- LayoutCommon.MillimeterToInch100Single(this.PaperHeight) / 100 * e.Graphics.DpiY);
- }
- if (_printType == PrintType.PrintTest)
- {
- // 打印范围
- RectangleF rectangleF = new RectangleF(_allOffsetX,
- _allOffsetY,
- _paperWidth,
- _paperHeight);
- e.Graphics.SetClip(rectangleF);
- // 背景打印
- if (_isPrintBackground)
- {
- PrintBackgroundImage(e.Graphics);
- }
- // Item打印
- foreach (LayoutItem layoutItem in _items)
- {
- switch (layoutItem.ItemType)
- {
- case ItemType.Text:
- DrawTextItem(e.Graphics, (TextItem)layoutItem);
- break;
- case ItemType.Image:
- DrawImageItem(e.Graphics, (ImageItem)layoutItem);
- break;
- case ItemType.Rectangle:
- DrawRectangleItem(e.Graphics, (RectangleItem)layoutItem);
- break;
- case ItemType.Ellipse:
- DrawEllipseItem(e.Graphics, (EllipseItem)layoutItem);
- break;
- //case ItemType.Line:
- // DrawLineItem(e.Graphics, (LineItem)layoutItem);
- // break;
- case ItemType.Grid:
- DrawGridItem(e.Graphics, (GridItem)layoutItem);
- break;
- case ItemType.PageNum:
- DrawPageNumItem(e.Graphics, (PageNumItem)layoutItem);
- break;
- case ItemType.TotalText:
- DrawTotalTextItem(e.Graphics, (TotalTextItem)layoutItem);
- break;
- default:
- //throw new NotImplementedException();
- break;
- }
- }
- // 可以打印范围
- if (_isPrintAreaVisible)
- {
- e.Graphics.PageUnit = GraphicsUnit.Pixel;
- e.Graphics.ResetClip();
- e.Graphics.DrawRectangle(LayoutCommon.GreedDotPen,
- _rectangleFGreed.X,
- _rectangleFGreed.Y,
- _rectangleFGreed.Width,
- _rectangleFGreed.Height);
- }
- e.HasMorePages = false;
- }
- else if (_printType == PrintType.Print || _printType == PrintType.PrintPreview)
- {
- // 打印范围
- RectangleF rectangleF = new RectangleF(_allOffsetX,
- _allOffsetY,
- _paperWidth,
- _paperHeight);
- e.Graphics.SetClip(rectangleF);
- // 背景打印
- if (_isPrintBackground)
- {
- PrintBackgroundImage(e.Graphics);
- }
- // Item打印
- foreach (LayoutItem layoutItem in _items)
- {
- switch (layoutItem.ItemType)
- {
- case ItemType.Text:
- DrawTextItem(e.Graphics, (TextItem)layoutItem);
- break;
- case ItemType.Image:
- DrawImageItem(e.Graphics, (ImageItem)layoutItem);
- break;
- case ItemType.Rectangle:
- DrawRectangleItem(e.Graphics, (RectangleItem)layoutItem);
- break;
- case ItemType.Ellipse:
- DrawEllipseItem(e.Graphics, (EllipseItem)layoutItem);
- break;
- //case ItemType.Line:
- // DrawLineItem(e.Graphics, (LineItem)layoutItem);
- // break;
- case ItemType.Grid:
- DrawGridItem(e.Graphics, (GridItem)layoutItem);
- break;
- case ItemType.PageNum:
- DrawPageNumItem(e.Graphics, (PageNumItem)layoutItem);
- break;
- case ItemType.TotalText:
- DrawTotalTextItem(e.Graphics, (TotalTextItem)layoutItem);
- break;
- default:
- //throw new NotImplementedException();
- break;
- }
- }
- // 可以打印范围
- if (_isPrintAreaVisible)
- {
- e.Graphics.PageUnit = GraphicsUnit.Pixel;
- e.Graphics.ResetClip();
- e.Graphics.DrawRectangle(LayoutCommon.GreedDotPen,
- _rectangleFGreed.X,
- _rectangleFGreed.Y,
- _rectangleFGreed.Width,
- _rectangleFGreed.Height);
- }
- // 表格Item是否有下一页
- if (_printPageNum < TotalPageNum)
- {
- _printPageNum++;
- e.HasMorePages = true;
- return;
- }
- if (_printAction == PrintAction.PrintToPrinter)
- {
- // 纸张数是否增加判断
- if (_printDataBinding != null && _printDataBinding.BindingSource != null && 0 < _printDataBinding.BindingSource.Count)
- {
- if (_printDataBinding.BindingSource.Position + 1 < _printDataBinding.BindingSource.Count)
- {
- // 打印数据源下移一条记录
- _printDataBinding.BindingSource.MoveNext();
- _printPageNum = 1;
- e.HasMorePages = true;
- }
- else
- {
- e.HasMorePages = false;
- }
- }
- else
- {
- e.HasMorePages = false;
- }
- }
- else
- {
- // 纸张数是否增加判断
- if (++_printDataPosition < _printDataTotal)
- {
- _printPageNum = 1;
- e.HasMorePages = true;
- // 同一数据一次印刷/分批印刷
- if (true)
- {
- // 同一数据一次印刷
- if (++_printDataCopies < _numberOfCopies)
- {
- return;
- }
- else
- {
- _printDataCopies = 0;
- }
- }
- }
- else
- {
- e.HasMorePages = false;
- return;
- }
- if (_printDataBinding != null && _printDataBinding.BindingSource != null && 0 < _printDataBinding.BindingSource.Count)
- {
- // 打印数据源下移一条记录
- if (_printDataBinding.BindingSource.Position + 1 < _printDataBinding.BindingSource.Count)
- {
- _printDataBinding.BindingSource.MoveNext();
- }
- else
- {
- _printDataBinding.BindingSource.MoveFirst();
- }
- }
- }
- }
- else if (_printType == PrintType.AllocationPrint || _printType == PrintType.AllocationPrintPreview)
- {
- e.Graphics.SetClip(RectangleF.Empty);
- int allocationIndex = -1;
- // 一张纸打印
- for (int i = 0; i < _allocationNum; i++)
- {
- allocationIndex++;
- if (_printDataPosition < _allocationSkipCount)
- {
- // 跳过的打印位置
- e.HasMorePages = true;
- continue;
- }
- _allOffsetX = _marginLeft
- + (allocationIndex % _allocationNumX)
- * (_paperWidth + _allocationHorizontalSpace)
- - _printerOffsetX;
- _allOffsetY = _marginTop
- + (allocationIndex / _allocationNumX)
- * (_paperHeight + _allocationVerticalSpace)
- - _printerOffsetY;
- // 打印范围
- RectangleF rectangleF = new RectangleF(_allOffsetX,
- _allOffsetY,
- _paperWidth,
- _paperHeight);
- e.Graphics.SetClip(rectangleF);
- // 背景打印
- if (_isPrintBackground)
- {
- PrintBackgroundImage(e.Graphics);
- }
- // Item打印
- foreach (LayoutItem layoutItem in _items)
- {
- switch (layoutItem.ItemType)
- {
- case ItemType.Text:
- DrawTextItem(e.Graphics, (TextItem)layoutItem);
- break;
- case ItemType.Image:
- DrawImageItem(e.Graphics, (ImageItem)layoutItem);
- break;
- case ItemType.Rectangle:
- DrawRectangleItem(e.Graphics, (RectangleItem)layoutItem);
- break;
- case ItemType.Ellipse:
- DrawEllipseItem(e.Graphics, (EllipseItem)layoutItem);
- break;
- //case ItemType.Line:
- // DrawLineItem(e.Graphics, (LineItem)layoutItem);
- // break;
- case ItemType.Grid:
- DrawGridItem(e.Graphics, (GridItem)layoutItem);
- break;
- case ItemType.PageNum:
- DrawPageNumItem(e.Graphics, (PageNumItem)layoutItem);
- break;
- case ItemType.TotalText:
- DrawTotalTextItem(e.Graphics, (TotalTextItem)layoutItem);
- break;
- default:
- break;
- }
- }
- // 表格Item是否有下一页
- if (_printPageNum < TotalPageNum)
- {
- _printPageNum++;
- continue;
- }
- // 纸张数是否增加判断
- if (++_printDataPosition < _printDataTotal)
- {
- _printPageNum = 1;
- e.HasMorePages = true;
- // 同一数据一次印刷/分批印刷
- if (true)
- {
- // 同一数据一次印刷
- if (++_printDataCopies < _numberOfCopies)
- {
- continue;
- }
- else
- {
- _printDataCopies = 0;
- }
- }
- }
- else
- {
- e.HasMorePages = false;
- break;
- }
- if (_printDataBinding != null && _printDataBinding.BindingSource != null && 1 < _printDataBinding.BindingSource.Count)
- {
- // 打印数据源下移一条记录
- if (_printDataBinding.BindingSource.Position + 1 < _printDataBinding.BindingSource.Count)
- {
- _printDataBinding.BindingSource.MoveNext();
- }
- else
- {
- _printDataBinding.BindingSource.MoveFirst();
- }
- }
- }
- // 可以打印范围
- if (_isPrintAreaVisible)
- {
- e.Graphics.PageUnit = GraphicsUnit.Pixel;
- e.Graphics.ResetClip();
- e.Graphics.DrawRectangle(LayoutCommon.GreedDotPen,
- _rectangleFGreed.X,
- _rectangleFGreed.Y,
- _rectangleFGreed.Width,
- _rectangleFGreed.Height);
- }
- // 纸张数是否增加判断
- if (e.HasMorePages && _printDataPosition < _printDataTotal)
- {
- e.HasMorePages = true;
- }
- else
- {
- e.HasMorePages = false;
- }
- }
- else
- {
- e.HasMorePages = false;
- }
- }
- // 选定打印页码 modify by chenxy 2014-03-27 end
- #endregion 打印相关
- #endregion 事件处理
- #region 委托事件
- /// <summary>
- /// 用户操作数据项目完成时发生
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public delegate void UserChangedItemEventHandler(object sender, ItemChangedEventArgs e);
- /// <summary>
- /// 用户操作数据项目完成时发生
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public delegate void UserChangedGridItemEventHandler(object sender, CollectionChangeEventArgs e);
- #endregion
- #region 事件
- /// <summary>
- /// 改变纸张尺寸。
- /// </summary>
- public event EventHandler PaperSizeChanged;
- /// <summary>
- /// 改变缩放比例
- /// </summary>
- public event EventHandler ZoomChanged;
- /// <summary>
- /// 当一个项目被改变,移动,添加或删除引发此事件。
- /// </summary>
- public event ItemChangedEventHandler ItemChanged;
- /// <summary>
- /// 项目的选择状态改变时引发此事件。
- /// </summary>
- public event ItemSelectionChangedEventHandler ItemSelectionChanged;
- /// <summary>
- /// 打印或显示数据之前引发此事件。
- /// </summary>
- public event ItemValueFormattingEventHandler ItemValueFormatting;
- /// <summary>
- /// 用户追加Item完成时触发事件
- /// </summary>
- public event UserChangedItemEventHandler UserAddedItem;
- /// <summary>
- /// 用户删除Item完成时触发事件
- /// </summary>
- public event UserChangedItemEventHandler UserDeletedItem;
- /// <summary>
- /// 用户修改GridItem列时触发事件
- /// </summary>
- public event UserChangedGridItemEventHandler UserChangedGridItem;
- /// <summary>
- /// 改变项目的选中状态
- /// </summary>
- public event EventHandler UserSelectionChanged;
- #endregion 事件
- #region User32
- /// <summary>
- ///
- /// </summary>
- [DllImport("user32.dll", CharSet = CharSet.Auto)]
- public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, int lParam);
- #endregion User32
- #region Grid页码相关
- /// <summary>
- /// 当前页码
- /// </summary>
- [Browsable(false)]
- public int CurrentPageNum
- {
- get
- {
- return _currentPageNum;
- }
- }
- /// <summary>
- /// 页数
- /// </summary>
- [Browsable(false)]
- public int TotalPageNum
- {
- get
- {
- return _totalPageNum;
- }
- }
- /// <summary>
- /// 打印页码
- /// </summary>
- internal int PrintPageNum
- {
- get
- {
- return _printPageNum;
- }
- }
- /// <summary>
- /// 设置总页数
- /// </summary>
- internal void SetTotalPageNum()
- {
- LayoutItem[] grids = this.GetItems(ItemType.Grid);
- int total = 1;
- foreach (GridItem grid in grids)
- {
- total = Math.Max(total, grid.TotalPageNum);
- }
- if (total != _totalPageNum)
- {
- _totalPageNum = total;
- LayoutItem[] pageNums = this.GetItems(ItemType.PageNum);
- foreach (PageNumItem pageNum in pageNums)
- {
- pageNum.Refresh();
- }
- }
- }
- /// <summary>
- /// 设定显示第几页
- /// </summary>
- /// <param name="pageNum"></param>
- public void SetPageNum(int pageNum)
- {
- if (pageNum < 1)
- {
- pageNum = 1;
- }
- if (pageNum > _totalPageNum)
- {
- pageNum = _totalPageNum;
- }
- if (pageNum != _currentPageNum)
- {
- _currentPageNum = pageNum;
- LayoutItem[] grids = this.GetItems(ItemType.Grid);
- foreach (GridItem grid in grids)
- {
- grid.Refresh();
- }
- LayoutItem[] pageNums = this.GetItems(ItemType.PageNum);
- foreach (PageNumItem pageNumItem in pageNums)
- {
- pageNumItem.Refresh();
- }
- LayoutItem[] totalTextItems = this.GetItems(ItemType.TotalText);
- foreach (TotalTextItem totalTextItem in totalTextItems)
- {
- totalTextItem.Refresh();
- }
- }
- }
- /// <summary>
- /// Grid使用的数据源
- /// </summary>
- [Browsable(false)]
- public DataSet GridDataSource
- {
- get
- {
- return _gridDataSet;
- }
- set
- {
- if (value != _gridDataSet)
- {
- _gridDataSet = value;
- LayoutItem[] grids = this.GetItems(ItemType.Grid);
- if (grids != null && grids.Length > 0)
- {
- if (_gridDataSet == null || _gridDataSet.Tables.Count == 0)
- {
- foreach (GridItem grid in grids)
- {
- grid.GridSource = null;
- }
- }
- else
- {
- foreach (GridItem grid in grids)
- {
- if (_gridDataSet.Tables.Contains(grid.GridDataMember))
- {
- grid.GridSource = _gridDataSet.Tables[grid.GridDataMember];
- }
- else
- {
- grid.GridSource = null;
- }
- }
- }
- }
- }
- }
- }
- #endregion Grid页码相关
- }
- }
|