星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XHMicroLessonSystemWindow.xaml.cs 229KB

4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
4 년 전
3 년 전
3 년 전
3 년 전
4 년 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832
  1. using Accord.Video.FFMPEG;
  2. using Aspose.Slides;
  3. using ComeCapture;
  4. using Common.system;
  5. using NAudio.Wave;
  6. using NReco.VideoConverter;
  7. using RobotpenGateway;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.Diagnostics;
  12. using System.Drawing;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Text.RegularExpressions;
  16. using System.Threading;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Controls.Primitives;
  20. //using System.Windows.Forms;
  21. using System.Windows.Ink;
  22. using System.Windows.Input;
  23. using System.Windows.Media;
  24. using System.Windows.Media.Imaging;
  25. using System.Windows.Threading;
  26. using TmatrixLibrary;
  27. using TStudyDigitalPen.HID;
  28. using XHWK.Model;
  29. using XHWK.WKTool.DAL;
  30. using XHWK.WKTool.Models;
  31. using XHWK.WKTool.Skin;
  32. using XHWK.WKTool.UControl;
  33. using XHWK.WKTool.Utils;
  34. namespace XHWK.WKTool
  35. {
  36. /// <summary>
  37. /// 主页面
  38. /// </summary>
  39. public partial class XHMicroLessonSystemWindow : Window
  40. {
  41. #region 字段
  42. /// <summary>
  43. /// 页码下拉列表
  44. /// </summary>
  45. private List<PageData> PageData = null;
  46. private System.Windows.Forms.FolderBrowserDialog Ofd;
  47. private System.Windows.Forms.DialogResult Result;
  48. public BlackboardNew myblackboard;
  49. private System.Windows.Forms.DialogResult result;
  50. private System.Windows.Forms.OpenFileDialog ofd;
  51. //声明一个 DrawingAttributes 类型的变量
  52. private DrawingAttributes drawingAttributes;
  53. private Model_Video VideoInfo = null;
  54. ////定义事件
  55. //public event ChangeTextHandler ChangeTextEvent;
  56. //定义委托
  57. public delegate void ChangeTextHandler(string text);
  58. //定义委托
  59. public delegate void ChangeTextHandlers(string text, int i);
  60. /// <summary>
  61. /// 图片
  62. /// </summary>
  63. private string[] ImgPDFPath = new string[300];
  64. /// <summary>
  65. /// 当前颜色
  66. /// </summary>
  67. private System.Windows.Media.Color Color = System.Windows.Media.Colors.Red;
  68. /// <summary>
  69. /// 笔迹粗细
  70. /// </summary>
  71. private int PenSize = 2;
  72. //private DispatcherTimer t = null;
  73. /// <summary>
  74. /// 计时器状态
  75. /// </summary>
  76. private enum State
  77. {
  78. Start,
  79. Pause,
  80. End
  81. }
  82. #region 上传
  83. /// <summary>
  84. /// 视频模型
  85. /// </summary>
  86. private List<Model_Video> model_VideoList = null;
  87. /// <summary>
  88. /// 数据列表
  89. /// </summary>
  90. internal FileDirectoryData pageData = new FileDirectoryData();
  91. /// <summary>
  92. /// 下标
  93. /// </summary>
  94. private int Subscript = 0;
  95. /// <summary>
  96. /// 是否是修改状态
  97. /// </summary>
  98. private bool IsModify = false;
  99. #endregion 上传
  100. /// <summary>
  101. /// 键盘钩子
  102. /// </summary>
  103. private KeyboardHookCommon k_hook;
  104. #endregion 字段
  105. #region 初始化
  106. /// <summary>
  107. /// 主页面
  108. /// </summary>
  109. public XHMicroLessonSystemWindow()
  110. {
  111. byte[] license = Convert.FromBase64String("PExpY2Vuc2U+CiAgPERhdGE+CiAgICA8TGljZW5zZWRUbz5TdXpob3UgQXVuYm94IFNvZnR3YXJlIENvLiwgTHRkLjwvTGljZW5zZWRUbz4KICAgIDxFbWFpbFRvPnNhbGVzQGF1bnRlYy5jb208L0VtYWlsVG8+CiAgICA8TGljZW5zZVR5cGU+RGV2ZWxvcGVyIE9FTTwvTGljZW5zZVR5cGU+CiAgICA8TGljZW5zZU5vdGU+TGltaXRlZCB0byAxIGRldmVsb3BlciwgdW5saW1pdGVkIHBoeXNpY2FsIGxvY2F0aW9uczwvTGljZW5zZU5vdGU+CiAgICA8T3JkZXJJRD4xOTA4MjYwODA3NTM8L09yZGVySUQ+CiAgICA8VXNlcklEPjEzNDk3NjAwNjwvVXNlcklEPgogICAgPE9FTT5UaGlzIGlzIGEgcmVkaXN0cmlidXRhYmxlIGxpY2Vuc2U8L09FTT4KICAgIDxQcm9kdWN0cz4KICAgICAgPFByb2R1Y3Q+QXNwb3NlLlRvdGFsIGZvciAuTkVUPC9Qcm9kdWN0PgogICAgPC9Qcm9kdWN0cz4KICAgIDxFZGl0aW9uVHlwZT5FbnRlcnByaXNlPC9FZGl0aW9uVHlwZT4KICAgIDxTZXJpYWxOdW1iZXI+M2U0NGRlMzAtZmNkMi00MTA2LWIzNWQtNDZjNmEzNzE1ZmMyPC9TZXJpYWxOdW1iZXI+CiAgICA8U3Vic2NyaXB0aW9uRXhwaXJ5PjIwMjAwODI3PC9TdWJzY3JpcHRpb25FeHBpcnk+CiAgICA8TGljZW5zZVZlcnNpb24+My4wPC9MaWNlbnNlVmVyc2lvbj4KICAgIDxMaWNlbnNlSW5zdHJ1Y3Rpb25zPmh0dHBzOi8vcHVyY2hhc2UuYXNwb3NlLmNvbS9wb2xpY2llcy91c2UtbGljZW5zZTwvTGljZW5zZUluc3RydWN0aW9ucz4KICA8L0RhdGE+CiAgPFNpZ25hdHVyZT53UGJtNUt3ZTYvRFZXWFNIY1o4d2FiVEFQQXlSR0pEOGI3L00zVkV4YWZpQnd5U2h3YWtrNGI5N2c2eGtnTjhtbUFGY3J0c0cwd1ZDcnp6MytVYk9iQjRYUndTZWxsTFdXeXNDL0haTDNpN01SMC9jZUFxaVZFOU0rWndOQkR4RnlRbE9uYTFQajhQMzhzR1grQ3ZsemJLZFZPZXk1S3A2dDN5c0dqYWtaL1E9PC9TaWduYXR1cmU+CjwvTGljZW5zZT4=");
  112. new Aspose.Words.License().SetLicense(new MemoryStream(license));
  113. new Aspose.Pdf.License().SetLicense(new MemoryStream(license));
  114. new Aspose.Slides.License().SetLicense(new MemoryStream(license));
  115. InitializeComponent();
  116. #region 调整文字大小
  117. APP.PageContextData.WordSize20 = 20.00;
  118. APP.PageContextData.WordSize18 = 18.00;
  119. APP.PageContextData.WordSize16 = 16.00;
  120. APP.PageContextData.WordSize14 = 14.00;
  121. APP.PageContextData.WordSize12 = 12.00;
  122. #endregion 调整文字大小
  123. ResizeMode = System.Windows.ResizeMode.CanMinimize;
  124. BtnPrint.IsEnabled = false;
  125. myblackboard = new BlackboardNew(blackboard_canvas);
  126. APP.PageContextData.pagenum = 0;
  127. APP.PageContextData.currpage = 0;
  128. DataContext = APP.PageContextData;
  129. //APP.SaveDraw();//画板模型第一页初始化
  130. APP.PageDrawList = new List<Model_DrawData>();
  131. Model_DrawData model_DrawData = new Model_DrawData
  132. {
  133. PageNum = APP.PageContextData.currpage
  134. };
  135. APP.PageDrawList.Add(model_DrawData);
  136. txbv.Text = "v" + FileToolsCommon.GetConfigValue("VersionName");
  137. txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoType");
  138. txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoSavePath");
  139. Initialize();
  140. InitPen();
  141. InitlbPen();
  142. InitTQLPPen();
  143. InitPrint();
  144. }
  145. /// <summary>
  146. /// 初始化
  147. /// </summary>
  148. public void Initialize()
  149. {
  150. if (APP.isDebug)
  151. {
  152. txbVersion.Text = "测试版:";
  153. }
  154. else
  155. {
  156. txbVersion.Text = "正式版:";
  157. }
  158. #region 数据初始化
  159. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  160. FileToolsCommon.CreateDirectory(pathTemp);
  161. APP.PageContextData.pagenum = 0;
  162. APP.PageContextData.currpage = APP.PageContextData.pagenum;
  163. BtnStop.IsEnabled = false;//停止录制按钮不可点击
  164. #endregion 数据初始化
  165. k_hook = new KeyboardHookCommon();
  166. k_hook.KeyDownEvent += K_hook_KeyDownEvent;
  167. k_hook.Start();//安装键盘钩子
  168. APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  169. //创建 DrawingAttributes 类的一个实例
  170. drawingAttributes = new DrawingAttributes();
  171. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  172. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  173. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  174. blackboard_canvas.UseCustomCursor = true;
  175. drawingAttributes.FitToCurve = true;
  176. drawingAttributes.IgnorePressure = false;
  177. drawingAttributes.Width = PenSize;
  178. drawingAttributes.Height = PenSize;
  179. drawingAttributes.Color = Color;
  180. blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  181. //wfhCamera.Visibility = Visibility.Hidden;
  182. ImgPDFPath = null;
  183. ImgPDFPath = new string[300];
  184. }
  185. /// <summary>
  186. /// 初始化快捷键
  187. /// </summary>
  188. public void InitializeKeyDownEvent()
  189. {
  190. k_hook.Start();//安装键盘钩子
  191. }
  192. /// <summary>
  193. /// 快捷键
  194. /// </summary>
  195. /// <param name="sender"></param>
  196. /// <param name="e"></param>
  197. private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
  198. {
  199. if (e.KeyValue == (int)System.Windows.Forms.Keys.Left)
  200. {
  201. if (APP.PageContextData.currpage > 1)
  202. {
  203. //上一页
  204. last_button_Click(null, null);
  205. }
  206. }
  207. if (e.KeyValue == (int)System.Windows.Forms.Keys.Right)
  208. {
  209. if (APP.PageContextData.currpage < APP.PageContextData.pagenum)
  210. {
  211. //下一页
  212. next_btn_Click(null, null);
  213. }
  214. }
  215. if (e.KeyValue == (int)System.Windows.Forms.Keys.Delete)
  216. {
  217. if (RectImgBorder.Visibility != Visibility.Hidden)
  218. {
  219. HideAngleBorder();
  220. imgCanvas.Source = null;
  221. APP.PageDrawList[APP.PageContextData.currpage - 1].PdfImagePath = null;
  222. APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath = null;
  223. }
  224. }
  225. }
  226. /// <summary>
  227. /// 加载完成后调整录制区域大小
  228. /// </summary>
  229. /// <param name="sender"></param>
  230. /// <param name="e"></param>
  231. private void Window_Loaded(object sender, RoutedEventArgs e)
  232. {
  233. //调整录制区域宽高
  234. double proportion = 210.0 / 297.0;
  235. GridM.Height = GridM.ActualWidth / proportion;
  236. }
  237. #endregion 初始化
  238. #region 事件
  239. /// <summary>
  240. /// 窗体移动
  241. /// </summary>
  242. /// <param name="sender"></param>
  243. /// <param name="e"></param>
  244. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  245. {
  246. DragMove();
  247. }
  248. private void PageHide()
  249. {
  250. //设置
  251. gridSetUp.Visibility = Visibility.Collapsed;
  252. ////页码
  253. //GridPage.Visibility = Visibility.Collapsed;
  254. //我的
  255. GridMyVideo.Visibility = Visibility.Collapsed;
  256. //首页
  257. GridMain.Visibility = Visibility.Collapsed;
  258. GridM.IsEnabled = true;
  259. //打印
  260. GridPrintContent.Visibility = Visibility.Collapsed;
  261. //标题 录制
  262. GridRecordingTitle.Visibility = Visibility.Collapsed;
  263. //标题 打印
  264. GridPrintingTitle.Visibility = Visibility.Collapsed;
  265. }
  266. #region 摄像头
  267. private System.Timers.Timer times;
  268. private List<string> RbnOpen;
  269. private bool IsRbnOpen = false;
  270. /// <summary>
  271. /// 摄像头打开事件
  272. /// </summary>
  273. /// <param name="sender"></param>
  274. /// <param name="e"></param>
  275. private void RbnOpen_Click(object sender, RoutedEventArgs e)
  276. {
  277. if (!IsRbnOpen)
  278. {
  279. #region 防止连击
  280. if (IsPressButton)
  281. {
  282. return;
  283. }
  284. else
  285. {
  286. IsPressButton = true;
  287. new Thread(new ThreadStart(new Action(() =>
  288. {
  289. //Dispatcher.Invoke(new Action(() => { rbnTurnOff.IsEnabled = false; }));
  290. Thread.Sleep(500);
  291. //Dispatcher.Invoke(new Action(() => { rbnTurnOff.IsEnabled = true; }));
  292. IsPressButton = false;
  293. }))).Start();
  294. }
  295. #endregion 防止连击
  296. CameraHelper.UpdateCameraDevices();
  297. if (CameraHelper.CameraDevices.Count > 0)
  298. {
  299. int CameraIndex = 0;
  300. for (int i = 0; i < CameraHelper.CameraDevices.Count; i++)
  301. {
  302. if (CameraHelper.CameraDevices[i].MonikerString == APP.CameraName)
  303. {
  304. CameraIndex = i;
  305. }
  306. }
  307. CameraHelper.SetCameraDevice(CameraIndex);
  308. RbnOpen = new List<string>();
  309. times = new System.Timers.Timer(200)//初始值为300
  310. {
  311. AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
  312. };//设置执行一次(false)还是一直执行(true)
  313. times.Elapsed += new System.Timers.ElapsedEventHandler(Times_Elapsed);
  314. times.Enabled = true; //启动计时器
  315. IsRbnOpen = true;
  316. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  317. FileToolsCommon.CreateDirectory(imgPath);
  318. }
  319. }
  320. }
  321. private int I = 9999;
  322. private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  323. {
  324. if (IsRbnOpen)
  325. {
  326. try
  327. {
  328. Dispatcher.Invoke(() =>
  329. {
  330. if (I > 10010)
  331. {
  332. long time = Timestamp();
  333. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  334. //string FilePathName = ImgPath + RsImgName.Count + ".png";
  335. string path = CameraHelper.CaptureImage(imgPath, time.ToString());
  336. if (!string.IsNullOrWhiteSpace(path))
  337. {
  338. RbnOpen.Add(path);
  339. imgPlayerRight.Visibility = Visibility.Visible;
  340. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  341. if ("1".Equals(APP.CameraPosition))
  342. {
  343. imgPlayerRight.Visibility = Visibility.Visible;
  344. imgPlayerLeft.Visibility = Visibility.Collapsed;
  345. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  346. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  347. imgPlayerRight.Source = new BitmapImage(new Uri(path));
  348. }
  349. else if ("2".Equals(APP.CameraPosition))
  350. {
  351. imgPlayerRight.Visibility = Visibility.Collapsed;
  352. imgPlayerLeft.Visibility = Visibility.Visible;
  353. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  354. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  355. imgPlayerLeft.Source = new BitmapImage(new Uri(path));
  356. }
  357. else if ("3".Equals(APP.CameraPosition))
  358. {
  359. imgPlayerRight.Visibility = Visibility.Collapsed;
  360. imgPlayerLeft.Visibility = Visibility.Collapsed;
  361. imgPlayerRightUnder.Visibility = Visibility.Visible;
  362. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  363. imgPlayerRightUnder.Source = new BitmapImage(new Uri(path));
  364. }
  365. else if ("4".Equals(APP.CameraPosition))
  366. {
  367. imgPlayerRight.Visibility = Visibility.Collapsed;
  368. imgPlayerLeft.Visibility = Visibility.Collapsed;
  369. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  370. imgPlayerLeftUnder.Visibility = Visibility.Visible;
  371. imgPlayerLeftUnder.Source = new BitmapImage(new Uri(path));
  372. }
  373. else
  374. {
  375. imgPlayerLeft.Visibility = Visibility.Collapsed;
  376. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  377. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  378. imgPlayerRight.Source = new BitmapImage(new Uri(path));
  379. }
  380. }
  381. }
  382. I++;
  383. });
  384. }
  385. catch (Exception ex)
  386. {
  387. LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
  388. }
  389. }
  390. }
  391. /// <summary>
  392. /// 摄像头关闭事件
  393. /// </summary>
  394. /// <param name="sender"></param>
  395. /// <param name="e"></param>
  396. private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
  397. {
  398. if (IsRbnOpen)
  399. {
  400. #region 防止连击
  401. if (IsPressButton)
  402. {
  403. return;
  404. }
  405. else
  406. {
  407. IsPressButton = true;
  408. new Thread(new ThreadStart(new Action(() =>
  409. {
  410. //Dispatcher.Invoke(new Action(() => { rbnOpen.IsEnabled = false; }));
  411. Thread.Sleep(500);
  412. //Dispatcher.Invoke(new Action(() => { rbnOpen.IsEnabled = true; }));
  413. IsPressButton = false;
  414. }))).Start();
  415. }
  416. #endregion 防止连击
  417. IsRbnOpen = false;
  418. imgPlayerRight.Visibility = Visibility.Collapsed;
  419. imgPlayerLeft.Visibility = Visibility.Collapsed;
  420. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  421. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  422. CameraHelper.CloseDevice();
  423. I = 9999;
  424. }
  425. }
  426. #endregion 摄像头
  427. /// <summary>
  428. /// 关闭事件
  429. /// </summary>
  430. /// <param name="sender"></param>
  431. /// <param name="e"></param>
  432. private void BtnClose_Click(object sender, RoutedEventArgs e)
  433. {
  434. if (RecordType == 0)
  435. {
  436. try
  437. {
  438. MessageBoxResult br = MessageWindow.Show("确定退出系统?", "退出", MessageBoxButton.OKCancel);
  439. if (br == MessageBoxResult.OK)
  440. {
  441. try
  442. {
  443. APP.Killffmpeg();
  444. }
  445. catch (Exception ex)
  446. {
  447. LogHelper.WriteErrLog("获取进程失败," + ex.Message, ex);
  448. }
  449. APP.SaveWkData();
  450. APP.SaveDraw();
  451. TMC.TmatrixUninitialize();
  452. Environment.Exit(0);
  453. }
  454. }
  455. catch (Exception ex)
  456. {
  457. LogHelper.WriteErrLog("关闭微课失败," + ex.Message, ex);
  458. Close();
  459. Application.Current.Shutdown();
  460. TMC.TmatrixUninitialize();
  461. Environment.Exit(0);
  462. }
  463. }
  464. else
  465. {
  466. MessageWindow.Show("当前正在录制,请先停止录制。");
  467. return;
  468. }
  469. }
  470. /// <summary>
  471. /// 增加事件
  472. /// </summary>
  473. /// <param name="sender"></param>
  474. /// <param name="e"></param>
  475. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  476. {
  477. Record();
  478. if (APP.PageContextData.currpage > 0)
  479. {
  480. APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = true;
  481. }
  482. if (blackboard_canvas.Visibility == Visibility.Collapsed)
  483. {
  484. blackboard_canvas.Visibility = Visibility.Visible;
  485. }
  486. APP.PageContextData.pagenum += 1;
  487. HideAngleBorder();
  488. GridPage.Visibility = Visibility.Visible;//页码大于0 显示
  489. APP.PageContextData.currpage = APP.PageContextData.pagenum;
  490. myblackboard.changepage(APP.PageContextData.currpage - 1);
  491. ScroMain.ScrollToVerticalOffset(0);
  492. ///清空页面图片UI
  493. imgCanvas.Source = null;
  494. imgDocumentation.Source = null;
  495. imgPPT.Source = null;
  496. if (APP.PageContextData.pagenum == 1)
  497. {
  498. APP.PageDrawList = new List<Model_DrawData>();
  499. }
  500. ///画板模型增加一页
  501. Model_DrawData model_DrawData = new Model_DrawData
  502. {
  503. PageNum = APP.PageContextData.currpage
  504. };
  505. APP.PageDrawList.Add(model_DrawData);
  506. if (RecordType == 0)
  507. {
  508. BtnPrint.IsEnabled = true;
  509. }
  510. //APP.SaveDraw();
  511. if (BtnImport.IsEnabled)
  512. {
  513. ///截图可用
  514. BtnScreenshot.IsEnabled = true;
  515. }
  516. #region 插入页码
  517. PageData = new List<PageData>();
  518. for (int i = 1; i <= APP.PageContextData.pagenum; i++)
  519. {
  520. PageData pd = new PageData();
  521. pd.PageName = i.ToString();// + "页";
  522. pd.PageCode = i;
  523. PageData.Add(pd);
  524. }
  525. CbxPageList.ItemsSource = PageData;
  526. CbxPageList.SelectedIndex = APP.PageContextData.currpage - 1;
  527. #endregion 插入页码
  528. }
  529. /// <summary>
  530. /// 打印事件
  531. /// </summary>
  532. /// <param name="sender"></param>
  533. /// <param name="e"></param>
  534. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  535. {
  536. try
  537. {
  538. //3种情况 1.文档图片 2.截图图片 3.没有图片
  539. if (APP.PageDrawList.Count == 0)
  540. {
  541. MessageWindow.Show("没有可打印的页,您可以通过加页、截图或导入来增加页!");
  542. return;
  543. }
  544. }
  545. catch (Exception ex)
  546. {
  547. MessageWindow.Show(ex.Message);
  548. Console.WriteLine("转换失败,原因:" + ex.Message);
  549. }
  550. if (GridPrintingTitle.Visibility == Visibility.Visible)
  551. {
  552. GridPrintingTitle.Visibility = Visibility.Collapsed;
  553. }
  554. else
  555. {
  556. GridPrintingTitle.Visibility = Visibility.Visible;
  557. if (APP.PageDrawList.Count > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[0].PageImagePath))
  558. {
  559. InitializePrint(APP.PageDrawList[0].PageImagePath, GridM.ActualWidth, GridM.ActualHeight);
  560. }
  561. else
  562. {
  563. InitializePrint("", GridM.ActualWidth, gridActHeight);
  564. }
  565. }
  566. }
  567. /// <summary>
  568. /// 最小化
  569. /// </summary>
  570. /// <param name="sender"></param>
  571. /// <param name="e"></param>
  572. private void BtnShrink_Click(object sender, RoutedEventArgs e)
  573. {
  574. if (WindowState == WindowState.Minimized)
  575. {
  576. WindowState = WindowState.Normal;
  577. }
  578. else
  579. {
  580. WindowState = WindowState.Minimized;
  581. }
  582. }
  583. #endregion 事件
  584. #region 设置
  585. /// <summary>
  586. /// 设置事件
  587. /// </summary>
  588. /// <param name="sender"></param>
  589. /// <param name="e"></param>
  590. private void BtnSetUp_Click(object sender, RoutedEventArgs e)
  591. {
  592. if (gridSetUp.Visibility == Visibility.Collapsed)
  593. {
  594. PageHide();
  595. gridSetUp.Visibility = Visibility.Visible;
  596. txbStoragePath.Content = APP.WKData.WkPath;
  597. #region 读取用户配置
  598. #region 请求地址 废弃 --2021年7月9日赵耀
  599. ////接口地址
  600. //if (!File.Exists(APP.DataPath + "interfaceAddress.txt")) //若为空
  601. //{
  602. // txbInterfaceAddress.Text = APP.apiUrl.Replace("http://", "").Trim();
  603. //}
  604. //else
  605. //{
  606. // txbInterfaceAddress.Text = System.IO.File.ReadAllText(APP.DataPath + "interfaceAddress.txt", Encoding.Default).Replace("http://", "").Trim();
  607. //}
  608. ////上传地址
  609. //if (!File.Exists(APP.DataPath + "imageUploadAddress.txt")) //若为空
  610. //{
  611. // txbImageUploadAddress.Text = APP.uploadUrl.Replace("http://", "").Replace("/", "").Trim();
  612. //}
  613. //else
  614. //{
  615. // txbImageUploadAddress.Text = System.IO.File.ReadAllText(APP.DataPath + "imageUploadAddress.txt", Encoding.Default).Replace("http://", "").Replace("/", "").Trim();
  616. //}
  617. ////下载地址
  618. //if (!File.Exists(APP.DataPath + "pictureShowsAddress.txt")) //若为空
  619. //{
  620. // txbPictureShowsAddress.Text = APP.showImageUrl.Replace("http://", "").Replace("/static", "").Replace("/", "").Trim();
  621. //}
  622. //else
  623. //{
  624. // txbPictureShowsAddress.Text = System.IO.File.ReadAllText(APP.DataPath + "pictureShowsAddress.txt", Encoding.Default).Replace("http://", "").Replace("/static", "").Replace("/", "").Trim();
  625. //}
  626. #endregion 请求地址 废弃 --2021年7月9日赵耀
  627. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  628. if ("1".Equals(APP.CameraPosition))
  629. {
  630. rbnRight.IsChecked = true;
  631. }
  632. else if ("2".Equals(APP.CameraPosition))
  633. {
  634. rbnLeft.IsChecked = true;
  635. }
  636. else if ("3".Equals(APP.CameraPosition))
  637. {
  638. rbnRightUnder.IsChecked = true;
  639. }
  640. else if ("4".Equals(APP.CameraPosition))
  641. {
  642. rbnLeftUnder.IsChecked = true;
  643. }
  644. string type = FileToolsCommon.GetConfigValue("VideoType");//<!--视频格式 1、MP4 2、FlV 3、AVI-->
  645. if ("1".Equals(type))
  646. {
  647. rbnMP4.IsChecked = true;
  648. }
  649. else if ("2".Equals(type))
  650. {
  651. rbnFLV.IsChecked = true;
  652. }
  653. else if ("3".Equals(type))
  654. {
  655. rbnAVI.IsChecked = true;
  656. }
  657. string isHide = FileToolsCommon.GetConfigValue("IsHideSRTool"); //工具栏是否隐藏
  658. if (isHide.Equals("1"))
  659. {
  660. rbnHide.IsChecked = true;
  661. }
  662. else
  663. {
  664. rbnvisi.IsChecked = true;
  665. }
  666. //string isSound = FileToolsCommon.GetConfigValue("IsSound");//<!--声音 true 有 false 无-->
  667. //if (isSound == "true")
  668. //{
  669. // rbnY.IsChecked = true;
  670. //}
  671. //else
  672. //{
  673. // rbnN.IsChecked = true;
  674. //}
  675. //加载皮肤按钮
  676. SkinSelectInit();
  677. #endregion 读取用户配置
  678. }
  679. else
  680. {
  681. GridMain.Visibility = Visibility.Visible;
  682. GridM.IsEnabled = true;
  683. GridRecordingTitle.Visibility = Visibility.Visible;
  684. gridSetUp.Visibility = Visibility.Collapsed;
  685. //if (APP.pageData.pagenum > 0)
  686. //{
  687. // GridPage.Visibility = Visibility.Visible;
  688. //}
  689. //DataContext = APP.pageData;
  690. }
  691. }
  692. /// <summary>
  693. /// 设置 保存事件
  694. /// </summary>
  695. /// <param name="sender"></param>
  696. /// <param name="e"></param>
  697. private void BtnSave_Click(object sender, RoutedEventArgs e)
  698. {
  699. try
  700. {
  701. BtnRecord.IsEnabled = true;//设置结束时可录制
  702. if (rbnMP4.IsChecked == true)
  703. {
  704. //存储文件
  705. FileToolsCommon.SetConfigValue("VideoType", "1");
  706. }
  707. else if (rbnFLV.IsChecked == true)
  708. {
  709. FileToolsCommon.SetConfigValue("VideoType", "2");
  710. }
  711. else
  712. {
  713. FileToolsCommon.SetConfigValue("VideoType", "3");
  714. }
  715. //if (rbnY.IsChecked == true)
  716. //{
  717. // FileToolsCommon.SetConfigValue("IsSound", "true");
  718. //}
  719. //else
  720. //{
  721. // FileToolsCommon.SetConfigValue("IsSound", "false");
  722. //}
  723. UpdateHideSRToolConfig();
  724. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  725. if (rbnRight.IsChecked == true)
  726. {
  727. FileToolsCommon.SetConfigValue("CameraPosition", "1");
  728. }
  729. else if (rbnLeft.IsChecked == true)
  730. {
  731. FileToolsCommon.SetConfigValue("CameraPosition", "2");
  732. }
  733. else if (rbnRightUnder.IsChecked == true)
  734. {
  735. FileToolsCommon.SetConfigValue("CameraPosition", "3");
  736. }
  737. else if (rbnLeftUnder.IsChecked == true)
  738. {
  739. FileToolsCommon.SetConfigValue("CameraPosition", "4");
  740. }
  741. //格式
  742. if (rbnMP4.IsChecked == true)
  743. {
  744. FileToolsCommon.SetConfigValue("VideoType", "1");
  745. }
  746. else if (rbnFLV.IsChecked == true)
  747. {
  748. FileToolsCommon.SetConfigValue("VideoType", "2");
  749. }
  750. else if (rbnAVI.IsChecked == true)
  751. {
  752. FileToolsCommon.SetConfigValue("VideoType", "3");
  753. }
  754. APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  755. GridMain.Visibility = Visibility.Visible;
  756. GridM.IsEnabled = true;
  757. GridRecordingTitle.Visibility = Visibility.Visible;
  758. gridSetUp.Visibility = Visibility.Collapsed;
  759. imgPlayerRight.Visibility = Visibility.Collapsed;
  760. imgPlayerLeft.Visibility = Visibility.Collapsed;
  761. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  762. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  763. if (!txbStoragePath.Content.ToString().Equals(APP.WKData.WkPath))
  764. {
  765. //存储文件
  766. FileToolsCommon.SetConfigValue("VideoSavePath", txbStoragePath.Content.ToString());
  767. MessageWindow.Show("路径已变更,下次创建微课时自动生效。");
  768. }
  769. }
  770. catch (Exception ex)
  771. {
  772. LogHelper.WriteErrLog("XHMicroLessonSystemWindow(设置保存事件报错:)" + ex.Message, ex);
  773. }
  774. }
  775. /// <summary>
  776. /// 设置 浏览事件
  777. /// </summary>
  778. /// <param name="sender"></param>
  779. /// <param name="e"></param>
  780. private void BtnBrowse_Click(object sender, RoutedEventArgs e)
  781. {
  782. //System.Diagnostics.Process.Start(APP.WKData.WkPath);
  783. //string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  784. Ofd = new System.Windows.Forms.FolderBrowserDialog();
  785. Result = Ofd.ShowDialog();
  786. if (Result == System.Windows.Forms.DialogResult.OK)
  787. {
  788. if (Ofd.SelectedPath != "")
  789. {
  790. txbStoragePath.Content = Ofd.SelectedPath;
  791. //string ApplicationData = ZConfig.dataPath + "fileStorageAddress.txt";
  792. //string temp = ofd.SelectedPath;
  793. //System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  794. }
  795. }
  796. }
  797. /// <summary>
  798. /// 打开文件所在位置
  799. /// </summary>
  800. /// <param name="sender"></param>
  801. /// <param name="e"></param>
  802. private void btnOpen_Click(object sender, RoutedEventArgs e)
  803. {
  804. System.Diagnostics.Process.Start(APP.WKData.WkPath);
  805. }
  806. /// <summary>
  807. /// 更新隐藏录屏工具栏隐藏状态
  808. /// </summary>
  809. private void UpdateHideSRToolConfig()
  810. {
  811. if (rbnHide.IsChecked == true)
  812. {
  813. //隐藏
  814. FileToolsCommon.SetConfigValue("IsHideSRTool", "1");
  815. APP.IsHideSRTool = true;
  816. }
  817. else
  818. {
  819. //显示
  820. FileToolsCommon.SetConfigValue("IsHideSRTool", "0");
  821. APP.IsHideSRTool = false;
  822. }
  823. }
  824. #region 切换皮肤
  825. /// <summary>
  826. /// 加载皮肤选项
  827. /// </summary>
  828. private void SkinSelectInit()
  829. {
  830. if (APP.SkinStyle == "0")
  831. {
  832. HideSkinSelect();
  833. SkinSelectWhite.Visibility = Visibility.Visible;
  834. }
  835. else if (APP.SkinStyle == "1")
  836. {
  837. HideSkinSelect();
  838. SkinSelectTechnologyBlue.Visibility = Visibility.Visible;
  839. }
  840. else
  841. {
  842. HideSkinSelect();
  843. SkinSelectWhite.Visibility = Visibility.Visible;
  844. }
  845. }
  846. /// <summary>
  847. /// 白色
  848. /// </summary>
  849. /// <param name="sender"></param>
  850. /// <param name="e"></param>
  851. private void BtnSkinWhite_Click(object sender, RoutedEventArgs e)
  852. {
  853. if (APP.SkinStyle != "0")
  854. {
  855. HideSkinSelect();
  856. SkinSelectWhite.Visibility = Visibility.Visible;
  857. APP.SkinStyle = "0";
  858. FileToolsCommon.SetConfigValue("SkinStyle", "0");
  859. SkinConfig.SwitchSkin(0);
  860. }
  861. }
  862. /// <summary>
  863. /// 科技蓝
  864. /// </summary>
  865. /// <param name="sender"></param>
  866. /// <param name="e"></param>
  867. private void BtnSkinTechnologyBlue_Click(object sender, RoutedEventArgs e)
  868. {
  869. if (APP.SkinStyle != "1")
  870. {
  871. HideSkinSelect();
  872. SkinSelectTechnologyBlue.Visibility = Visibility.Visible;
  873. APP.SkinStyle = "1";
  874. FileToolsCommon.SetConfigValue("SkinStyle", "1");
  875. SkinConfig.SwitchSkin(1);
  876. }
  877. }
  878. /// <summary>
  879. /// 隐藏皮肤选择键
  880. /// </summary>
  881. private void HideSkinSelect()
  882. {
  883. SkinSelectWhite.Visibility = Visibility.Hidden;
  884. SkinSelectTechnologyBlue.Visibility = Visibility.Hidden;
  885. }
  886. #endregion 切换皮肤
  887. #endregion 设置
  888. #region 画笔
  889. /// <summary>
  890. /// 画笔颜色事件 白色
  891. /// </summary>
  892. /// <param name="sender"></param>
  893. /// <param name="e"></param>
  894. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  895. {
  896. ////创建 DrawingAttributes 类的一个实例
  897. //drawingAttributes = new DrawingAttributes();
  898. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  899. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  900. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  901. ////设置 DrawingAttributes 的 Color 属性设置颜色
  902. drawingAttributes.Color = Colors.White;
  903. Color = Colors.White;
  904. }
  905. /// <summary>
  906. /// 画笔颜色事件 红色
  907. /// </summary>
  908. /// <param name="sender"></param>
  909. /// <param name="e"></param>
  910. private void BtnRed_Click(object sender, RoutedEventArgs e)
  911. {
  912. //设置 DrawingAttributes 的 Color 属性设置颜色
  913. drawingAttributes.Color = Colors.Red;
  914. Color = Colors.Red;
  915. imgRed.Visibility = Visibility.Visible;
  916. imgGray.Visibility = Visibility.Collapsed;
  917. imgCyanBlue.Visibility = Visibility.Collapsed;
  918. imgYellow.Visibility = Visibility.Collapsed;
  919. imgBlue.Visibility = Visibility.Collapsed;
  920. }
  921. /// <summary>
  922. /// 画笔颜色事件 黑色
  923. /// </summary>
  924. /// <param name="sender"></param>
  925. /// <param name="e"></param>
  926. private void BtnGray_Click(object sender, RoutedEventArgs e)
  927. {
  928. drawingAttributes.Color = Colors.Black;
  929. Color = Colors.Black;
  930. imgRed.Visibility = Visibility.Collapsed;
  931. imgGray.Visibility = Visibility.Visible;
  932. imgCyanBlue.Visibility = Visibility.Collapsed;
  933. imgYellow.Visibility = Visibility.Collapsed;
  934. imgBlue.Visibility = Visibility.Collapsed;
  935. }
  936. /// <summary>
  937. /// 画笔颜色事件 青色
  938. /// </summary>
  939. /// <param name="sender"></param>
  940. /// <param name="e"></param>
  941. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  942. {
  943. drawingAttributes.Color = Colors.LimeGreen;
  944. Color = Colors.LimeGreen;
  945. imgRed.Visibility = Visibility.Collapsed;
  946. imgGray.Visibility = Visibility.Collapsed;
  947. imgCyanBlue.Visibility = Visibility.Visible;
  948. imgYellow.Visibility = Visibility.Collapsed;
  949. imgBlue.Visibility = Visibility.Collapsed;
  950. }
  951. /// <summary>
  952. /// 画笔颜色事件 黄色
  953. /// </summary>
  954. /// <param name="sender"></param>
  955. /// <param name="e"></param>
  956. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  957. {
  958. drawingAttributes.Color = Colors.Gold;
  959. Color = Colors.Gold;
  960. imgRed.Visibility = Visibility.Collapsed;
  961. imgGray.Visibility = Visibility.Collapsed;
  962. imgCyanBlue.Visibility = Visibility.Collapsed;
  963. imgYellow.Visibility = Visibility.Visible;
  964. imgBlue.Visibility = Visibility.Collapsed;
  965. }
  966. /// <summary>
  967. /// 画笔颜色事件 蓝色
  968. /// </summary>
  969. /// <param name="sender"></param>
  970. /// <param name="e"></param>
  971. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  972. {
  973. drawingAttributes.Color = Colors.DeepSkyBlue;
  974. Color = Colors.DeepSkyBlue;
  975. imgRed.Visibility = Visibility.Collapsed;
  976. imgGray.Visibility = Visibility.Collapsed;
  977. imgCyanBlue.Visibility = Visibility.Collapsed;
  978. imgYellow.Visibility = Visibility.Collapsed;
  979. imgBlue.Visibility = Visibility.Visible;
  980. }
  981. /// <summary>
  982. /// 画笔粗细事件 细
  983. /// </summary>
  984. /// <param name="sender"></param>
  985. /// <param name="e"></param>
  986. private void RbnFine_Click(object sender, RoutedEventArgs e)
  987. {
  988. drawingAttributes.Width = 1;
  989. drawingAttributes.Height = 1;
  990. PenSize = 1;
  991. }
  992. /// <summary>
  993. /// 画笔粗细事件 中
  994. /// </summary>
  995. /// <param name="sender"></param>
  996. /// <param name="e"></param>
  997. private void RbnIn_Click(object sender, RoutedEventArgs e)
  998. {
  999. drawingAttributes.Width = 3;
  1000. drawingAttributes.Height = 3;
  1001. PenSize = 3;
  1002. }
  1003. /// <summary>
  1004. /// 画笔粗细事件 粗
  1005. /// </summary>
  1006. /// <param name="sender"></param>
  1007. /// <param name="e"></param>
  1008. private void RbnCrude_Click(object sender, RoutedEventArgs e)
  1009. {
  1010. drawingAttributes.Width = 5;
  1011. drawingAttributes.Height = 5;
  1012. PenSize = 5;
  1013. }
  1014. private void imgCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1015. {
  1016. mouseDown = true;
  1017. }
  1018. #endregion 画笔
  1019. #region 导入截图
  1020. /// <summary>
  1021. /// 截图事件
  1022. /// </summary>
  1023. /// <param name="sender"></param>
  1024. /// <param name="e"></param>
  1025. private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
  1026. {
  1027. double do1 = GridContent.ActualHeight;
  1028. double dou = GridMain.ActualHeight;
  1029. Record();
  1030. HideAngleBorder();
  1031. imgCanvas.Margin = new Thickness(0, 0, 0, 0);
  1032. APP.ImgPath = string.Empty;
  1033. string time = GetTimeStamp();
  1034. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
  1035. APP.ImgPath = desktopPath;
  1036. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), desktopPath, false, out BitmapImage bitmap);
  1037. k_hook.Stop();
  1038. if (WindowState == WindowState.Normal)//截图隐藏窗口
  1039. {
  1040. WindowState = WindowState.Minimized;
  1041. }
  1042. if (APP.W_JieTuWindow != null)
  1043. {
  1044. APP.W_JieTuWindow.initialization();
  1045. APP.W_JieTuWindow.Screenshot();
  1046. APP.W_JieTuWindow.InitializeKeyDownEvent();
  1047. APP.W_JieTuWindow.WindowState = WindowState.Maximized;
  1048. APP.W_JieTuWindow.Visibility = Visibility.Visible;
  1049. }
  1050. else
  1051. {
  1052. APP.W_JieTuWindow = new JieTuWindow();
  1053. APP.W_JieTuWindow.InitializeKeyDownEvent();
  1054. // 订阅事件
  1055. APP.W_JieTuWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
  1056. APP.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
  1057. APP.W_JieTuWindow.Show();
  1058. }
  1059. }
  1060. /// <summary>
  1061. /// 获取时间戳
  1062. /// </summary>
  1063. /// <returns></returns>
  1064. public string GetTimeStamp()
  1065. {
  1066. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  1067. return Convert.ToInt64(ts.TotalSeconds).ToString();
  1068. }
  1069. /// <summary>
  1070. /// 返回一个时间戳到毫秒
  1071. /// </summary>
  1072. /// <returns></returns>
  1073. public static long Timestamp()
  1074. {
  1075. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  1076. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  1077. return timestr;
  1078. }
  1079. public void WindowType()
  1080. {
  1081. if (WindowState == WindowState.Minimized)//截图完恢复窗口
  1082. {
  1083. Topmost = true;
  1084. WindowState = WindowState.Normal;
  1085. }
  1086. }
  1087. /// <summary>
  1088. /// 截图关闭窗口
  1089. /// </summary>
  1090. /// <param name="text"></param>
  1091. private void frm_ChangeTextEvent(string text)
  1092. {
  1093. if ("关闭窗口".Equals(text))
  1094. {
  1095. if (WindowState == WindowState.Minimized)//截图完恢复窗口
  1096. {
  1097. Topmost = true;
  1098. WindowState = WindowState.Normal;
  1099. }
  1100. InitializeKeyDownEvent();
  1101. if (!string.IsNullOrWhiteSpace(APP.ImgPath) && File.Exists(APP.ImgPath))
  1102. {
  1103. if (APP.PageContextData.currpage == 0)
  1104. {
  1105. APP.PageContextData.pagenum += 1;
  1106. APP.PageContextData.currpage = APP.PageContextData.pagenum;
  1107. myblackboard.changepage(APP.PageContextData.currpage - 1);
  1108. GridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1109. #region 插入页码
  1110. PageData = new List<PageData>();
  1111. for (int i = 1; i <= APP.PageContextData.pagenum; i++)
  1112. {
  1113. PageData pd = new PageData();
  1114. pd.PageName = i.ToString();// + "页";
  1115. pd.PageCode = i;
  1116. PageData.Add(pd);
  1117. }
  1118. CbxPageList.ItemsSource = PageData;
  1119. CbxPageList.SelectedIndex = APP.PageContextData.currpage - 1;
  1120. #endregion 插入页码
  1121. }
  1122. if (APP.PageDrawList.Count >= APP.PageContextData.currpage)
  1123. {
  1124. APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath = APP.ImgPath;//zxycs
  1125. APP.PageDrawList[APP.PageContextData.currpage - 1].PdfImagePath = APP.ImgPath;
  1126. }
  1127. else
  1128. {
  1129. Model_DrawData model_DrawData = new Model_DrawData
  1130. {
  1131. PageImagePath = APP.ImgPath,
  1132. PdfImagePath = APP.ImgPath
  1133. };
  1134. APP.PageDrawList.Add(model_DrawData);
  1135. }
  1136. if (APP.PageDrawList.Count >= APP.PageContextData.currpage && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath))
  1137. {
  1138. imgDocumentation.Source = null;
  1139. BitmapImage bitImg = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
  1140. mouseDown = false;
  1141. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
  1142. {
  1143. X = 0.1,
  1144. Y = 0.1
  1145. };
  1146. APP.PageDrawList[APP.PageContextData.currpage - 1].Type = "截图";
  1147. APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = false;
  1148. imgCanvas.Source = bitImg;
  1149. imgCanvas.Width = bitImg.Width;
  1150. imgCanvas.Height = bitImg.Height;
  1151. ScroMain.ScrollToVerticalOffset(0);
  1152. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
  1153. {
  1154. CenterX = imgCanvas.Width,
  1155. CenterY = imgCanvas.Height
  1156. };
  1157. BtnPrint.IsEnabled = true;
  1158. }
  1159. }
  1160. Topmost = false;
  1161. }
  1162. else if ("取消".Equals(text))
  1163. {
  1164. if (WindowState == WindowState.Minimized)//截图完恢复窗口
  1165. {
  1166. Topmost = true;
  1167. WindowState = WindowState.Normal;
  1168. }
  1169. }
  1170. }
  1171. /// <summary>
  1172. /// 截图关闭 非正常关闭截图时,截图清空
  1173. /// </summary>
  1174. private void JietuWindow_click_closeJietuWindowClick()
  1175. {
  1176. if (WindowState == WindowState.Minimized)//截图完恢复窗口
  1177. {
  1178. WindowState = WindowState.Normal;
  1179. }
  1180. APP.W_JieTuWindow = null;
  1181. }
  1182. /// 截图的图片鼠标右键事件 </summary> <param name="sender"></param> <param name="e"></param>
  1183. private void imgCanvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
  1184. {
  1185. imgCanvas.Source = null;
  1186. APP.PageDrawList[APP.PageContextData.currpage - 1].PdfImagePath = null;
  1187. APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath = null;
  1188. }
  1189. /// <summary>
  1190. /// 导入事件
  1191. /// </summary>
  1192. /// <param name="sender"></param>
  1193. /// <param name="e"></param>
  1194. private void BtnImport_Click(object sender, RoutedEventArgs e)
  1195. {
  1196. try
  1197. {
  1198. Record();
  1199. HideAngleBorder();
  1200. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  1201. ofd = new System.Windows.Forms.OpenFileDialog
  1202. {
  1203. //Filter = "文档|*.docx;*.doc;*.ppt;*.pptx",
  1204. //增加导入图片
  1205. Filter = "文档|*.docx;*.doc;*.ppt;*.pptx;*.pdf|图片|*.jpg;*.jpeg;*.png;*.bmp",
  1206. InitialDirectory = desktopPath,
  1207. Multiselect = false,
  1208. AddExtension = true,
  1209. DereferenceLinks = true
  1210. };
  1211. //APP.myloading.Show();
  1212. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
  1213. //new Thread(
  1214. // o =>
  1215. // {
  1216. // Thread.Sleep(400);
  1217. // Dispatcher.Invoke(new Action(() =>
  1218. // {
  1219. // OpenDialog();
  1220. // }
  1221. // ));
  1222. // })
  1223. //{
  1224. // IsBackground = true
  1225. //}.Start();
  1226. }
  1227. catch (Exception ex)
  1228. {
  1229. LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
  1230. }
  1231. }
  1232. /// <summary>
  1233. /// 导入-开始
  1234. /// </summary>
  1235. /// <returns></returns>
  1236. private object InvokeServering()
  1237. {
  1238. Dispatcher.Invoke(new Action(() =>
  1239. {
  1240. result = ofd.ShowDialog();
  1241. }));
  1242. if (result == System.Windows.Forms.DialogResult.OK)
  1243. {
  1244. if (ofd.FileName != "")
  1245. {
  1246. List<string> imagelist = new List<string>() { "jpg", "jpeg", "png", "bmp" };
  1247. Dispatcher.Invoke(new Action(() =>
  1248. {
  1249. APP.myloading.Show();
  1250. myblackboard.changepage(APP.PageContextData.pagenum);
  1251. }));
  1252. string filepath = ofd.FileName;
  1253. string filesuff = filepath.Substring(filepath.LastIndexOf(".") + 1).ToLower();
  1254. string path = ofd.SafeFileName.Replace(".ppt", "").Replace(".pptx", "").Trim();
  1255. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Replace(".pptx", "typezsygppt").Replace(".pdf", "typepdf").Trim();
  1256. if (type.Contains("typezsygppt"))//ppt
  1257. {
  1258. try
  1259. {
  1260. #region PPT转PDF
  1261. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1262. path = pathTemp + path + ".pdf";
  1263. FileToolsCommon.CreateDirectory(pathTemp);
  1264. //PPT转PDF
  1265. Presentation ppt = new Presentation(filepath);
  1266. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  1267. #endregion PPT转PDF
  1268. #region PDF转图片
  1269. // 图片绝对路径集合
  1270. List<string> images = new List<string>();
  1271. string directoryPath = pathTemp;
  1272. //定义Jpeg转换设备
  1273. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  1274. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1275. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1276. //directoryPath += quality;
  1277. Directory.CreateDirectory(directoryPath);
  1278. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1279. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1280. //遍历每一页转为jpg
  1281. for (int i = 1; i <= document.Pages.Count; i++)
  1282. {
  1283. long ii = Timestamp();
  1284. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1285. images.Add(filePathOutPut);
  1286. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1287. try
  1288. {
  1289. device.Process(document.Pages[i], fs);
  1290. fs.Close();
  1291. }
  1292. catch (Exception)
  1293. {
  1294. fs.Close();
  1295. File.Delete(filePathOutPut);
  1296. }
  1297. }
  1298. #endregion PDF转图片
  1299. Dispatcher.Invoke(new Action(() =>
  1300. {
  1301. string[] page = images.ToArray();
  1302. int num = 0;
  1303. int iStart = APP.PageContextData.pagenum;//导入文档的开始下标
  1304. int iEnd = page.Length + APP.PageContextData.pagenum;//导入文档的结束下标
  1305. for (int i = 0 + APP.PageContextData.pagenum; i < page.Length + APP.PageContextData.pagenum; i++)//给画板模型加图片路径
  1306. {
  1307. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1308. {
  1309. APP.PageDrawList[i].PageImagePath = page[i - APP.PageContextData.pagenum]; //zxycs
  1310. APP.PageDrawList[i].PdfImagePath = page[i - APP.PageContextData.pagenum];
  1311. APP.PageDrawList[i].PageNum = i + 1;
  1312. APP.PageDrawList[i].ImgDocumentation = true;
  1313. APP.PageDrawList[i].Type = "ppt";
  1314. }
  1315. else
  1316. {
  1317. Model_DrawData model_DrawData = new Model_DrawData
  1318. {
  1319. PageImagePath = page[i - APP.PageContextData.pagenum],
  1320. PdfImagePath = page[i - APP.PageContextData.pagenum],
  1321. PageNum = i + 1,
  1322. ImgDocumentation = true,
  1323. Type = "ppt"
  1324. };
  1325. APP.PageDrawList.Add(model_DrawData);
  1326. }
  1327. BtnPrint.IsEnabled = true;
  1328. APP.SaveDraw();
  1329. num++;
  1330. }
  1331. if (num > 0)
  1332. {
  1333. APP.PageContextData.currpage = APP.PageContextData.pagenum + 1;
  1334. APP.PageContextData.pagenum += num;
  1335. GridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1336. }
  1337. if (APP.PageContextData.currpage > 0 && APP.PageContextData.currpage <= APP.PageDrawList.Count)
  1338. {
  1339. imgCanvas.Source = null;
  1340. BtnScreenshot.IsEnabled = false;
  1341. imgDocumentation.Source = null;
  1342. imgPPT.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
  1343. ScroMain.ScrollToVerticalOffset(0);
  1344. for (int i = iStart; i < iEnd; i++)
  1345. {
  1346. APP.PageDrawList[i].ImageLocation = new TranslateTransform
  1347. {
  1348. X = 0.1,
  1349. Y = 0.1
  1350. };
  1351. APP.PageDrawList[i].IsImageLocation = true;
  1352. APP.PageDrawList[i].ImageSizes = new ScaleTransform
  1353. {
  1354. CenterX = imgCanvas.Width,
  1355. CenterY = imgCanvas.Height
  1356. };
  1357. }
  1358. }
  1359. else
  1360. {
  1361. imgDocumentation.Source = null;
  1362. imgCanvas.Source = null;
  1363. imgPPT.Source = null;
  1364. ///截图可用
  1365. BtnScreenshot.IsEnabled = true;
  1366. }
  1367. }));
  1368. }
  1369. catch (Exception ex)
  1370. {
  1371. Dispatcher.Invoke(new Action(() =>
  1372. {
  1373. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1374. }));
  1375. LogHelper.WriteErrLog("【打开ppt】(OpenDialog PPT)" + ex.Message, ex);
  1376. }
  1377. }
  1378. else if (type.Contains("typepdf"))
  1379. {
  1380. try
  1381. {
  1382. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1383. #region PDF转图片
  1384. // 图片绝对路径集合
  1385. List<string> images = new List<string>();
  1386. string directoryPath = pathTemp;
  1387. //aspose许可证
  1388. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1389. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1390. //l.SetLicense(licenseName);
  1391. //定义Jpeg转换设备
  1392. Aspose.Pdf.Document document = new Aspose.Pdf.Document(filepath);
  1393. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1394. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1395. //directoryPath += quality;
  1396. Directory.CreateDirectory(directoryPath);
  1397. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1398. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1399. //遍历每一页转为jpg
  1400. for (int i = 1; i <= document.Pages.Count; i++)
  1401. {
  1402. long ii = Timestamp();
  1403. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1404. images.Add(filePathOutPut);
  1405. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1406. try
  1407. {
  1408. device.Process(document.Pages[i], fs);
  1409. fs.Close();
  1410. }
  1411. catch (Exception)
  1412. {
  1413. fs.Close();
  1414. File.Delete(filePathOutPut);
  1415. }
  1416. }
  1417. #endregion PDF转图片
  1418. string[] page = images.ToArray();
  1419. int num = 0;
  1420. int iStart = APP.PageContextData.pagenum;//导入文档的开始下标
  1421. int iEnd = page.Length + APP.PageContextData.pagenum;//导入文档的结束下标
  1422. Dispatcher.Invoke(new Action(() =>
  1423. {
  1424. for (int i = APP.PageContextData.pagenum; i < page.Length + APP.PageContextData.pagenum; i++)//给画板模型加图片路径
  1425. {
  1426. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1427. {
  1428. APP.PageDrawList[i].PageImagePath = page[i - APP.PageContextData.pagenum]; //zxycs
  1429. APP.PageDrawList[i].PdfImagePath = page[i - APP.PageContextData.pagenum];
  1430. APP.PageDrawList[i].PageNum = i + 1;
  1431. APP.PageDrawList[i].ImgDocumentation = true;
  1432. APP.PageDrawList[i].Type = "word";
  1433. }
  1434. else
  1435. {
  1436. Model_DrawData model_DrawData = new Model_DrawData
  1437. {
  1438. PageImagePath = page[i - APP.PageContextData.pagenum],
  1439. PdfImagePath = page[i - APP.PageContextData.pagenum],
  1440. PageNum = i + 1,
  1441. ImgDocumentation = true,
  1442. Type = "word"
  1443. };
  1444. APP.PageDrawList.Add(model_DrawData);
  1445. }
  1446. BtnPrint.IsEnabled = true;
  1447. APP.SaveDraw();
  1448. num++;
  1449. }
  1450. if (num > 0)
  1451. {
  1452. APP.PageContextData.currpage = APP.PageContextData.pagenum + 1;
  1453. APP.PageContextData.pagenum += num;
  1454. GridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1455. }
  1456. if (APP.PageContextData.currpage > 0 && APP.PageContextData.currpage <= APP.PageDrawList.Count)
  1457. {
  1458. imgCanvas.Source = null;
  1459. imgPPT.Source = null;
  1460. BtnScreenshot.IsEnabled = false;
  1461. imgDocumentation.Visibility = Visibility.Visible;
  1462. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));//给当前页面展示图片
  1463. ScroMain.ScrollToVerticalOffset(0);
  1464. }
  1465. else
  1466. {
  1467. imgDocumentation.Source = null;
  1468. imgCanvas.Source = null;
  1469. imgPPT.Source = null;
  1470. ///截图可用
  1471. BtnScreenshot.IsEnabled = true;
  1472. }
  1473. }));
  1474. }
  1475. catch (Exception ex)
  1476. {
  1477. Dispatcher.Invoke(new Action(() =>
  1478. {
  1479. MessageWindow.Show(ex.Message);
  1480. }));
  1481. LogHelper.WriteErrLog("【打开pdf】(OpenDialog pdf)" + ex.Message, ex);
  1482. }
  1483. }
  1484. else if (imagelist.Contains(filesuff))///导入图片
  1485. {
  1486. string imagepath = AppDomain.CurrentDomain.BaseDirectory + "temp";
  1487. if (!Directory.Exists(imagepath))
  1488. {
  1489. Directory.CreateDirectory(imagepath);
  1490. }
  1491. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  1492. string timestr = Convert.ToInt64(ts.TotalMilliseconds).ToString();
  1493. string filepathCopy = Path.Combine(imagepath, timestr + ofd.SafeFileName);
  1494. System.IO.File.Copy(filepath, filepathCopy);
  1495. filepath = filepathCopy;
  1496. APP.ImgPath = filepath;
  1497. Dispatcher.Invoke(new Action(() =>
  1498. {
  1499. if (APP.PageContextData.currpage == 0)
  1500. {
  1501. APP.PageContextData.pagenum += 1;
  1502. APP.PageContextData.currpage = APP.PageContextData.pagenum;
  1503. myblackboard.changepage(APP.PageContextData.currpage - 1);
  1504. GridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1505. #region 插入页码
  1506. PageData = new List<PageData>();
  1507. for (int i = 1; i <= APP.PageContextData.pagenum; i++)
  1508. {
  1509. PageData pd = new PageData();
  1510. pd.PageName = i.ToString();// + "页";
  1511. pd.PageCode = i;
  1512. PageData.Add(pd);
  1513. }
  1514. CbxPageList.ItemsSource = PageData;
  1515. CbxPageList.SelectedIndex = APP.PageContextData.currpage - 1;
  1516. #endregion 插入页码
  1517. }
  1518. else
  1519. {
  1520. APP.PageContextData.pagenum += 1;
  1521. APP.PageContextData.currpage = APP.PageContextData.pagenum;
  1522. myblackboard.changepage(APP.PageContextData.currpage - 1);
  1523. }
  1524. if (APP.PageDrawList.Count >= APP.PageContextData.currpage)
  1525. {
  1526. APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath = APP.ImgPath;//zxycs
  1527. APP.PageDrawList[APP.PageContextData.currpage - 1].PdfImagePath = APP.ImgPath;
  1528. }
  1529. else
  1530. {
  1531. Model_DrawData model_DrawData = new Model_DrawData
  1532. {
  1533. PageImagePath = APP.ImgPath,
  1534. PdfImagePath = APP.ImgPath
  1535. };
  1536. APP.PageDrawList.Add(model_DrawData);
  1537. }
  1538. if (APP.PageDrawList.Count >= APP.PageContextData.currpage && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath))
  1539. {
  1540. imgDocumentation.Source = null;
  1541. BitmapImage bitImg = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
  1542. mouseDown = false;
  1543. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
  1544. {
  1545. X = 0.1,
  1546. Y = 0.1
  1547. };
  1548. APP.PageDrawList[APP.PageContextData.currpage - 1].Type = "截图";
  1549. APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = false;
  1550. imgCanvas.Source = bitImg;
  1551. imgCanvas.Width = bitImg.Width;
  1552. imgCanvas.Height = bitImg.Height;
  1553. ScroMain.ScrollToVerticalOffset(0);
  1554. imgCanvas.Margin = new Thickness(APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation.X, APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation.Y, 0, 0);
  1555. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
  1556. {
  1557. CenterX = imgCanvas.Width,
  1558. CenterY = imgCanvas.Height
  1559. };
  1560. BtnPrint.IsEnabled = true;
  1561. }
  1562. }));
  1563. }
  1564. else//word
  1565. {
  1566. try
  1567. {
  1568. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1569. WordImgNum += 1;
  1570. string[] page = ZAsposeUtil.ConvertWordToImage(filepath, paths, "" + WordImgNum, 0, 0).ToArray();
  1571. int num = 0;
  1572. Dispatcher.Invoke(new Action(() =>
  1573. {
  1574. for (int i = 0 + APP.PageContextData.pagenum; i < page.Length + APP.PageContextData.pagenum; i++)//给画板模型加图片路径
  1575. {
  1576. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1577. {
  1578. APP.PageDrawList[i].PageImagePath = page[i - APP.PageContextData.pagenum]; //zxycs
  1579. APP.PageDrawList[i].PdfImagePath = page[i - APP.PageContextData.pagenum];
  1580. APP.PageDrawList[i].PageNum = i + 1;
  1581. APP.PageDrawList[i].ImgDocumentation = true;
  1582. APP.PageDrawList[i].Type = "word";
  1583. }
  1584. else
  1585. {
  1586. Model_DrawData model_DrawData = new Model_DrawData
  1587. {
  1588. PageImagePath = page[i - APP.PageContextData.pagenum],
  1589. PdfImagePath = page[i - APP.PageContextData.pagenum],
  1590. PageNum = i + 1,
  1591. ImgDocumentation = true,
  1592. Type = "word"
  1593. };
  1594. APP.PageDrawList.Add(model_DrawData);
  1595. }
  1596. BtnPrint.IsEnabled = true;
  1597. APP.SaveDraw();
  1598. num++;
  1599. }
  1600. if (num > 0)
  1601. {
  1602. APP.PageContextData.currpage = APP.PageContextData.pagenum + 1;
  1603. APP.PageContextData.pagenum += num;
  1604. GridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1605. }
  1606. if (APP.PageContextData.currpage > 0 && APP.PageContextData.currpage <= APP.PageDrawList.Count)
  1607. {
  1608. imgCanvas.Source = null;
  1609. imgPPT.Source = null;
  1610. BtnScreenshot.IsEnabled = false;
  1611. imgDocumentation.Visibility = Visibility.Visible;
  1612. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));//给当前页面展示图片
  1613. ScroMain.ScrollToVerticalOffset(0);
  1614. }
  1615. else
  1616. {
  1617. imgDocumentation.Source = null;
  1618. imgCanvas.Source = null;
  1619. imgPPT.Source = null;
  1620. ///截图可用
  1621. BtnScreenshot.IsEnabled = true;
  1622. }
  1623. }));
  1624. }
  1625. catch (Exception ex)
  1626. {
  1627. Dispatcher.Invoke(new Action(() =>
  1628. {
  1629. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1630. }));
  1631. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
  1632. }
  1633. }
  1634. #region 插入页码
  1635. Dispatcher.Invoke(new Action(() =>
  1636. {
  1637. PageData = new List<PageData>();
  1638. for (int i = 1; i <= APP.PageContextData.pagenum; i++)
  1639. {
  1640. PageData pd = new PageData();
  1641. pd.PageName = i.ToString();//+ "页";
  1642. pd.PageCode = i;
  1643. PageData.Add(pd);
  1644. }
  1645. CbxPageList.ItemsSource = PageData;
  1646. CbxPageList.SelectedIndex = APP.PageContextData.currpage - 1;
  1647. }));
  1648. #endregion 插入页码
  1649. }
  1650. }
  1651. //OpenDialog();
  1652. return "";
  1653. }
  1654. /// <summary>
  1655. /// 导入-结束
  1656. /// </summary>
  1657. /// <returns></returns>
  1658. public void InvokeServerCompate(object obj)
  1659. {
  1660. //APP.myloading.Hide();
  1661. APP.myloading.Hide();
  1662. }
  1663. /// <summary>
  1664. /// 防止图片地址重复
  1665. /// </summary>
  1666. private long WordImgNum = 9999;
  1667. /// <summary>
  1668. /// 导入文档
  1669. /// </summary>
  1670. private void OpenDialog()
  1671. {
  1672. Dispatcher.Invoke(new Action(() =>
  1673. {
  1674. result = ofd.ShowDialog();
  1675. if (result == System.Windows.Forms.DialogResult.OK)
  1676. {
  1677. if (ofd.FileName != "")
  1678. {
  1679. APP.myloading.Show();
  1680. myblackboard.changepage(APP.PageContextData.pagenum);
  1681. #region PPT转PDF
  1682. string filepath = ofd.FileName;
  1683. string path = ofd.SafeFileName.Replace(".ppt", "").Replace(".pptx", "").Trim();
  1684. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Replace(".pptx", "typezsygppt").Replace(".pdf", "typepdf").Trim();
  1685. if (type.Contains("typezsygppt"))//ppt
  1686. {
  1687. try
  1688. {
  1689. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1690. path = pathTemp + path + ".pdf";
  1691. FileToolsCommon.CreateDirectory(pathTemp);
  1692. //PPT转PDF
  1693. Presentation ppt = new Presentation(filepath);
  1694. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  1695. #endregion PPT转PDF
  1696. #region PDF转图片
  1697. // 图片绝对路径集合
  1698. List<string> images = new List<string>();
  1699. string directoryPath = pathTemp;
  1700. //aspose许可证
  1701. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1702. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1703. //l.SetLicense(licenseName);
  1704. //定义Jpeg转换设备
  1705. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  1706. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1707. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1708. //directoryPath += quality;
  1709. Directory.CreateDirectory(directoryPath);
  1710. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1711. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1712. //遍历每一页转为jpg
  1713. for (int i = 1; i <= document.Pages.Count; i++)
  1714. {
  1715. long ii = Timestamp();
  1716. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1717. images.Add(filePathOutPut);
  1718. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1719. try
  1720. {
  1721. device.Process(document.Pages[i], fs);
  1722. fs.Close();
  1723. }
  1724. catch (Exception)
  1725. {
  1726. fs.Close();
  1727. File.Delete(filePathOutPut);
  1728. }
  1729. }
  1730. #endregion PDF转图片
  1731. string[] page = images.ToArray();
  1732. int num = 0;
  1733. for (int i = 0 + APP.PageContextData.pagenum; i < page.Length + APP.PageContextData.pagenum; i++)//给画板模型加图片路径
  1734. {
  1735. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1736. {
  1737. APP.PageDrawList[i].PageImagePath = page[i - APP.PageContextData.pagenum]; //zxycs
  1738. APP.PageDrawList[i].PdfImagePath = page[i - APP.PageContextData.pagenum];
  1739. APP.PageDrawList[i].PageNum = i + 1;
  1740. APP.PageDrawList[i].ImgDocumentation = true;
  1741. }
  1742. else
  1743. {
  1744. Model_DrawData model_DrawData = new Model_DrawData
  1745. {
  1746. PageImagePath = page[i - APP.PageContextData.pagenum],
  1747. PdfImagePath = page[i - APP.PageContextData.pagenum],
  1748. PageNum = i + 1,
  1749. ImgDocumentation = true
  1750. };
  1751. APP.PageDrawList.Add(model_DrawData);
  1752. }
  1753. BtnPrint.IsEnabled = true;
  1754. APP.SaveDraw();
  1755. num++;
  1756. }
  1757. if (num > 0)
  1758. {
  1759. APP.PageContextData.currpage = APP.PageContextData.pagenum + 1;
  1760. APP.PageContextData.pagenum += num;
  1761. GridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1762. }
  1763. if (APP.PageContextData.currpage > 0 && APP.PageContextData.currpage < APP.PageDrawList.Count)
  1764. {
  1765. imgCanvas.Source = null;
  1766. BtnScreenshot.IsEnabled = false;
  1767. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));//给当前页面展示图片
  1768. }
  1769. else
  1770. {
  1771. imgDocumentation.Source = null;
  1772. imgCanvas.Source = null;
  1773. ///截图可用
  1774. BtnScreenshot.IsEnabled = true;
  1775. }
  1776. APP.myloading.Hide();
  1777. }
  1778. catch (Exception ex)
  1779. {
  1780. APP.myloading.Hide();
  1781. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1782. LogHelper.WriteErrLog("【打开ppt】(OpenDialog PPT)" + ex.Message, ex);
  1783. }
  1784. }
  1785. else if (type.Contains("typepdf"))
  1786. {
  1787. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1788. #region PDF转图片
  1789. // 图片绝对路径集合
  1790. List<string> images = new List<string>();
  1791. string directoryPath = pathTemp;
  1792. //aspose许可证
  1793. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1794. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1795. //l.SetLicense(licenseName);
  1796. //定义Jpeg转换设备
  1797. Aspose.Pdf.Document document = new Aspose.Pdf.Document(filepath);
  1798. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1799. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1800. //directoryPath += quality;
  1801. Directory.CreateDirectory(directoryPath);
  1802. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1803. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1804. //遍历每一页转为jpg
  1805. for (int i = 1; i <= document.Pages.Count; i++)
  1806. {
  1807. long ii = Timestamp();
  1808. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1809. images.Add(filePathOutPut);
  1810. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1811. try
  1812. {
  1813. device.Process(document.Pages[i], fs);
  1814. fs.Close();
  1815. }
  1816. catch (Exception)
  1817. {
  1818. fs.Close();
  1819. File.Delete(filePathOutPut);
  1820. }
  1821. }
  1822. #endregion PDF转图片
  1823. string[] page = images.ToArray();
  1824. int num = 0;
  1825. for (int i = 0 + APP.PageContextData.pagenum; i < page.Length + APP.PageContextData.pagenum; i++)//给画板模型加图片路径
  1826. {
  1827. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1828. {
  1829. APP.PageDrawList[i].PageImagePath = page[i - APP.PageContextData.pagenum]; //zxycs
  1830. APP.PageDrawList[i].PdfImagePath = page[i - APP.PageContextData.pagenum];
  1831. APP.PageDrawList[i].PageNum = i + 1;
  1832. APP.PageDrawList[i].ImgDocumentation = true;
  1833. }
  1834. else
  1835. {
  1836. Model_DrawData model_DrawData = new Model_DrawData
  1837. {
  1838. PageImagePath = page[i - APP.PageContextData.pagenum],
  1839. PdfImagePath = page[i - APP.PageContextData.pagenum],
  1840. PageNum = i + 1,
  1841. ImgDocumentation = true
  1842. };
  1843. APP.PageDrawList.Add(model_DrawData);
  1844. }
  1845. BtnPrint.IsEnabled = true;
  1846. APP.SaveDraw();
  1847. num++;
  1848. }
  1849. if (num > 0)
  1850. {
  1851. APP.PageContextData.currpage = APP.PageContextData.pagenum + 1;
  1852. APP.PageContextData.pagenum += num;
  1853. GridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1854. }
  1855. if (APP.PageContextData.currpage > 0 && APP.PageContextData.currpage < APP.PageDrawList.Count)
  1856. {
  1857. imgCanvas.Source = null;
  1858. BtnScreenshot.IsEnabled = false;
  1859. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));//给当前页面展示图片
  1860. }
  1861. else
  1862. {
  1863. imgDocumentation.Source = null;
  1864. imgCanvas.Source = null;
  1865. ///截图可用
  1866. BtnScreenshot.IsEnabled = true;
  1867. }
  1868. APP.myloading.Hide();
  1869. }
  1870. else//word
  1871. {
  1872. try
  1873. {
  1874. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1875. WordImgNum += 1;
  1876. string[] page = ZAsposeUtil.ConvertWordToImage(filepath, paths, "" + WordImgNum, 0, 0).ToArray();
  1877. int num = 0;
  1878. for (int i = 0 + APP.PageContextData.pagenum; i < page.Length + APP.PageContextData.pagenum; i++)//给画板模型加图片路径
  1879. {
  1880. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1881. {
  1882. APP.PageDrawList[i].PageImagePath = page[i - APP.PageContextData.pagenum]; //zxycs
  1883. APP.PageDrawList[i].PdfImagePath = page[i - APP.PageContextData.pagenum];
  1884. APP.PageDrawList[i].PageNum = i + 1;
  1885. APP.PageDrawList[i].ImgDocumentation = true;
  1886. }
  1887. else
  1888. {
  1889. Model_DrawData model_DrawData = new Model_DrawData
  1890. {
  1891. PageImagePath = page[i - APP.PageContextData.pagenum],
  1892. PdfImagePath = page[i - APP.PageContextData.pagenum],
  1893. PageNum = i + 1,
  1894. ImgDocumentation = true
  1895. };
  1896. APP.PageDrawList.Add(model_DrawData);
  1897. }
  1898. BtnPrint.IsEnabled = true;
  1899. APP.SaveDraw();
  1900. num++;
  1901. }
  1902. if (num > 0)
  1903. {
  1904. APP.PageContextData.currpage = APP.PageContextData.pagenum + 1;
  1905. APP.PageContextData.pagenum += num;
  1906. GridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1907. }
  1908. if (APP.PageContextData.currpage > 0 && APP.PageContextData.currpage < APP.PageDrawList.Count)
  1909. {
  1910. imgCanvas.Source = null;
  1911. BtnScreenshot.IsEnabled = false;
  1912. imgDocumentation.Visibility = Visibility.Visible;
  1913. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));//给当前页面展示图片
  1914. }
  1915. else
  1916. {
  1917. imgDocumentation.Source = null;
  1918. imgCanvas.Source = null;
  1919. ///截图可用
  1920. BtnScreenshot.IsEnabled = true;
  1921. }
  1922. APP.myloading.Hide();
  1923. }
  1924. catch (Exception ex)
  1925. {
  1926. APP.myloading.Hide();
  1927. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
  1928. }
  1929. }
  1930. }
  1931. }
  1932. }
  1933. ));
  1934. }
  1935. #region 导入转换图片
  1936. /// <summary>
  1937. /// 生成图片
  1938. /// </summary>
  1939. /// <param name="_path">图片地址</param>
  1940. /// <param name="_saveimg">保存位置</param>
  1941. /// <param name="_rectangle">图片位置</param>
  1942. /// <param name="errmsg">错误消息</param>
  1943. /// <returns></returns>
  1944. private bool MergerImg(string _path, string _saveimg, RectangleF _rectangle, out string errmsg)
  1945. {
  1946. errmsg = null;
  1947. try
  1948. {
  1949. Bitmap bitmap = null;
  1950. //创建要显示的图片对象,根据参数的个数设置宽度
  1951. Bitmap backgroudImg = new Bitmap((int)GridM.ActualWidth, (int)GridM.ActualHeight);
  1952. Graphics g = Graphics.FromImage(backgroudImg);
  1953. //清除画布,背景设置为白色
  1954. g.Clear(System.Drawing.Color.White);
  1955. if (!string.IsNullOrWhiteSpace(_path))
  1956. {
  1957. bitmap = ImageHelper.ReadBitmapFile(_path);
  1958. g.DrawImage(bitmap, _rectangle);
  1959. }
  1960. backgroudImg.Save(_saveimg);
  1961. g.Dispose();
  1962. backgroudImg.Dispose();
  1963. if (bitmap != null)
  1964. {
  1965. bitmap.Dispose();
  1966. }
  1967. GC.Collect();
  1968. return true;
  1969. }
  1970. catch (Exception ex)
  1971. {
  1972. errmsg = ex.Message;
  1973. LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
  1974. return false;
  1975. }
  1976. }
  1977. #endregion 导入转换图片
  1978. #endregion 导入截图
  1979. #region 上传 列表
  1980. /// <summary>
  1981. /// 上传事件
  1982. /// </summary>
  1983. /// <param name="sender"></param>
  1984. /// <param name="e"></param>
  1985. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  1986. {
  1987. if (GridMyVideo.Visibility == Visibility.Visible)
  1988. {
  1989. GridMyVideo.Visibility = Visibility.Collapsed;
  1990. GridMain.Visibility = Visibility.Visible;
  1991. GridM.IsEnabled = true;
  1992. GridRecordingTitle.Visibility = Visibility.Visible;
  1993. }
  1994. else
  1995. {
  1996. PageHide();
  1997. GridMyVideo.Visibility = Visibility.Visible;
  1998. LoadUploadInitData();
  1999. }
  2000. }
  2001. /// <summary>
  2002. /// 初始化上传
  2003. /// </summary>
  2004. public void InitializeUpload()
  2005. {
  2006. APP.myloading.Show();
  2007. //MouseNumber = 0;
  2008. IsModify = false;
  2009. //加载视频列表
  2010. LoadingVideoList();
  2011. Currpage = 0;
  2012. PageNum = 0;
  2013. APP.myloading.Hide();
  2014. DataContext = pageData;
  2015. }
  2016. /// <summary>
  2017. /// 当前页
  2018. /// </summary>
  2019. private int Currpage = 0;
  2020. /// <summary>
  2021. /// 总页码
  2022. /// </summary>
  2023. private int PageNum = 0;
  2024. /// <summary>
  2025. /// 加载视频列表
  2026. /// </summary>
  2027. public void LoadingVideoList()
  2028. {
  2029. try
  2030. {
  2031. model_VideoList = new List<Model_Video>();
  2032. foreach (Model_WKData Vdata in APP.WKDataList)
  2033. {
  2034. #region 计时器初始化
  2035. if (Vdata.VideoList == null)
  2036. {
  2037. continue;
  2038. }
  2039. foreach (Model_Video videoinfo in Vdata.VideoList)
  2040. {
  2041. try
  2042. {
  2043. if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
  2044. {
  2045. continue;
  2046. }
  2047. if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
  2048. {
  2049. videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMB(videoinfo.VideoPath).ToString() + " MB";
  2050. videoinfo.VideoSizebyte = FileToolsCommon.GetFileSize(videoinfo.VideoPath);
  2051. }
  2052. model_VideoList.Add(videoinfo);
  2053. }
  2054. catch (Exception ex)
  2055. {
  2056. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  2057. }
  2058. }
  2059. #endregion 计时器初始化
  2060. }
  2061. //翻转
  2062. if (model_VideoList.Count > 1)
  2063. {
  2064. model_VideoList.Reverse();
  2065. }
  2066. }
  2067. catch (Exception ex)
  2068. {
  2069. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  2070. }
  2071. }
  2072. /// <summary>
  2073. /// 搜索集合匹配的索引
  2074. /// </summary>
  2075. /// <typeparam name="T"></typeparam>
  2076. /// <param name="parent"></param>
  2077. /// <param name="childName"></param>
  2078. /// <returns></returns>
  2079. public static List<T> FindChilds<T>(DependencyObject parent, string childName)
  2080. where T : DependencyObject
  2081. {
  2082. List<T> list = new List<T>();
  2083. if (parent == null)
  2084. {
  2085. return list;
  2086. }
  2087. int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
  2088. for (int i = 0; i < childrenCount; i++)
  2089. {
  2090. DependencyObject child = VisualTreeHelper.GetChild(parent, i);
  2091. // 如果子控件不是需查找的控件类型
  2092. T childType = child as T;
  2093. if (childType == null)
  2094. {
  2095. // 在下一级控件中递归查找
  2096. List<T> findChildList = FindChilds<T>(child, childName);
  2097. for (int j = 0; j < findChildList.Count; j++)
  2098. {
  2099. }
  2100. list.AddRange(FindChilds<T>(child, childName));
  2101. }
  2102. else if (!string.IsNullOrEmpty(childName))
  2103. {
  2104. FrameworkElement frameworkElement = child as FrameworkElement;
  2105. // 如果控件名称符合参数条件
  2106. if (frameworkElement != null && frameworkElement.Name == childName)
  2107. {
  2108. list.Add((T)child);
  2109. }
  2110. }
  2111. else
  2112. {
  2113. // 查找到了控件
  2114. list.Add((T)child);
  2115. }
  2116. }
  2117. return list;
  2118. }
  2119. #endregion 上传 列表
  2120. #region 新上传 显示缩略图
  2121. #region 初始值
  2122. /// <summary>
  2123. /// 总页数
  2124. /// </summary>
  2125. private int TotalPage = 0;
  2126. /// <summary>
  2127. /// 当前页
  2128. /// </summary>
  2129. private int CurrentPage = 1;
  2130. /// <summary>
  2131. /// 每页显示的视频数
  2132. /// </summary>
  2133. private int PageShowNum = 0;
  2134. /// <summary>
  2135. /// 视频信息列表
  2136. /// </summary>
  2137. private List<Uc_VideoItem> VideoControlList = new List<Uc_VideoItem>();
  2138. /// <summary>
  2139. /// 横向间隔
  2140. /// </summary>
  2141. private double IntervalX = 0;
  2142. /// <summary>
  2143. /// 纵向间隔
  2144. /// </summary>
  2145. private double IntervalY = 0;
  2146. /// <summary>
  2147. /// 页面宽
  2148. /// </summary>
  2149. private double pageW;
  2150. /// <summary>
  2151. /// 页面高
  2152. /// </summary>
  2153. private double pageH;
  2154. private double ControlWidth = 250;
  2155. private double ControlHeight = 260;
  2156. #endregion 初始值
  2157. /// <summary>
  2158. /// 初始化加载上传页面数据
  2159. /// </summary>
  2160. private void LoadUploadInitData()
  2161. {
  2162. APP.myloading.Show();
  2163. //加载视频列表
  2164. LoadingVideoList();
  2165. if (model_VideoList.Count > 0)
  2166. {
  2167. lblVideoMess.Visibility = Visibility.Hidden;
  2168. BtnVideoUpPage.Visibility = Visibility.Visible;
  2169. lblVideoPageNum.Visibility = Visibility.Visible;
  2170. BtnVideoDownPage.Visibility = Visibility.Visible;
  2171. if (GridMyVideo.ActualHeight > 0)
  2172. {
  2173. pageW = GridMyVideo.ActualWidth;
  2174. pageH = GridMyVideo.ActualHeight;
  2175. }
  2176. else
  2177. {
  2178. pageW = GridRecordingArea.ActualWidth;
  2179. pageH = GridRecordingArea.ActualHeight;
  2180. }
  2181. //获取设置控件大小 新增 页面原始1061 911
  2182. double PropWid = pageW / 1061.00;
  2183. double PropHei = pageH / 911.00;
  2184. //ControlWidth = 250.00 * PropWid;
  2185. //ControlHeight = 260.00 * PropHei;
  2186. //ControlWidth=
  2187. //ControlHeight=
  2188. //根据页面大小获取每页显示的数量 H260W250
  2189. int videoRow = (int)((pageH - 50) / ControlHeight);
  2190. int videColumn = (int)(pageW / ControlWidth);
  2191. //横向间隔
  2192. IntervalX = (pageW - (videColumn * ControlWidth)) / (videColumn + 1);
  2193. IntervalY = (pageH - 50 - (videoRow * ControlHeight)) / (videoRow + 1);
  2194. PageShowNum = (videoRow == 0 ? 1 : videoRow) * (videColumn == 0 ? 1 : videColumn);
  2195. //获取总页数
  2196. TotalPage = model_VideoList.Count / PageShowNum + (model_VideoList.Count % PageShowNum > 0 ? 1 : 0);
  2197. //如果当前页大于总页数 总页数为当前页
  2198. if (TotalPage < CurrentPage)
  2199. {
  2200. CurrentPage = TotalPage;
  2201. }
  2202. LoadCurrentPageData();
  2203. }
  2204. else
  2205. {
  2206. lblVideoMess.Visibility = Visibility.Visible;
  2207. BtnVideoUpPage.Visibility = Visibility.Hidden;
  2208. lblVideoPageNum.Visibility = Visibility.Hidden;
  2209. BtnVideoDownPage.Visibility = Visibility.Hidden;
  2210. //隐藏显示的控件
  2211. if (VideoControlList.Count > 0)
  2212. {
  2213. foreach (Uc_VideoItem item in VideoControlList)
  2214. {
  2215. if (item.Visibility != Visibility.Hidden)
  2216. {
  2217. item.Visibility = Visibility.Hidden;
  2218. }
  2219. }
  2220. }
  2221. }
  2222. APP.myloading.Hide();
  2223. }
  2224. /// <summary>
  2225. /// 加载当前页数据
  2226. /// </summary>
  2227. private void LoadCurrentPageData()
  2228. {
  2229. lblVideoPageNum.Content = CurrentPage + "/" + TotalPage;
  2230. //隐藏显示的控件
  2231. if (VideoControlList.Count > 0)
  2232. {
  2233. foreach (Uc_VideoItem item in VideoControlList)
  2234. {
  2235. if (item.Visibility != Visibility.Hidden)
  2236. {
  2237. item.Visibility = Visibility.Hidden;
  2238. }
  2239. }
  2240. }
  2241. double W = IntervalX;//每次增加250
  2242. double H = IntervalY;//每次增加260
  2243. //加载控件
  2244. for (int i = 0; i < PageShowNum; i++)
  2245. {
  2246. int DataIndex = (CurrentPage - 1) * PageShowNum + i;
  2247. if (DataIndex == model_VideoList.Count)
  2248. {
  2249. return;
  2250. }
  2251. Uc_VideoItem videoItem;
  2252. if (VideoControlList.Exists(x => x.Tag.ToString() == model_VideoList[DataIndex].FileGuid))
  2253. {
  2254. videoItem = VideoControlList.Find(x => x.Tag.ToString() == model_VideoList[DataIndex].FileGuid);
  2255. }
  2256. else
  2257. {
  2258. if (!FileToolsCommon.IsExistFile(model_VideoList[DataIndex].ThumbnailPath))
  2259. {
  2260. continue;
  2261. }
  2262. videoItem = new Uc_VideoItem(model_VideoList[DataIndex])
  2263. {
  2264. Tag = model_VideoList[DataIndex].FileGuid
  2265. };
  2266. videoItem.Click_refreshVideoList += LoadUploadInitData;
  2267. videoItem.Click_UploadLogin += Login;
  2268. videoItem.Width = ControlWidth;
  2269. videoItem.Height = ControlHeight;
  2270. videoItem.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
  2271. videoItem.VerticalAlignment = System.Windows.VerticalAlignment.Top;
  2272. GridMyVideo.Children.Add(videoItem);
  2273. VideoControlList.Add(videoItem);
  2274. }
  2275. videoItem.Margin = new Thickness(W, H, 0, 0);
  2276. videoItem.Visibility = Visibility.Visible;
  2277. if (W + ControlWidth + ControlWidth > pageW)
  2278. {
  2279. W = IntervalX;
  2280. H += ControlHeight + IntervalY;
  2281. }
  2282. else
  2283. {
  2284. W += ControlWidth + IntervalX;
  2285. }
  2286. //Uc_VideoItem videoItem = new Uc_VideoItem();
  2287. //return;
  2288. }
  2289. }
  2290. #region 分页
  2291. /// <summary>
  2292. /// 上一页
  2293. /// </summary>
  2294. /// <param name="sender"></param>
  2295. /// <param name="e"></param>
  2296. private void BtnVideoUpPage_Click(object sender, RoutedEventArgs e)
  2297. {
  2298. if (CurrentPage > 1)
  2299. {
  2300. CurrentPage--;
  2301. LoadCurrentPageData();
  2302. }
  2303. }
  2304. /// <summary>
  2305. /// 下一页
  2306. /// </summary>
  2307. /// <param name="sender"></param>
  2308. /// <param name="e"></param>
  2309. private void BtnVideoDownPage_Click(object sender, RoutedEventArgs e)
  2310. {
  2311. if (CurrentPage < TotalPage)
  2312. {
  2313. CurrentPage++;
  2314. LoadCurrentPageData();
  2315. }
  2316. }
  2317. #endregion 分页
  2318. #endregion 新上传 显示缩略图
  2319. #region 设备检测
  2320. /// <summary>
  2321. /// 设备检测
  2322. /// </summary>
  2323. /// <param name="sender"></param>
  2324. /// <param name="e"></param>
  2325. private void BtnDevice_Click(object sender, RoutedEventArgs e)
  2326. {
  2327. if (APP.W_DeviceWindow == null)
  2328. {
  2329. APP.W_DeviceWindow = new DeviceWindow();
  2330. APP.W_DeviceWindow.Owner = this;
  2331. }
  2332. rbnTurnOff.IsChecked = true;
  2333. RbnTurnOff_Click(null, null);
  2334. APP.W_DeviceWindow.Initialize();
  2335. APP.W_DeviceWindow.ShowDialog();
  2336. }
  2337. #endregion 设备检测
  2338. #region 录屏
  2339. /// <summary>
  2340. /// 录屏事件
  2341. /// </summary>
  2342. /// <param name="sender"></param>
  2343. /// <param name="e"></param>
  2344. private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
  2345. {
  2346. ThreadPool.QueueUserWorkItem(o =>
  2347. {
  2348. bool microphoneGood = ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.microphone);
  2349. bool loudspeakerGood = ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.loudspeaker);
  2350. Dispatcher.Invoke(() =>
  2351. {
  2352. if (!microphoneGood)
  2353. {
  2354. MessageWindow.Show("麦克风不可用");
  2355. return;
  2356. }
  2357. if (!loudspeakerGood)
  2358. {
  2359. MessageWindow.Show("扬声器不可用");
  2360. return;
  2361. }
  2362. Record();
  2363. k_hook.Stop();
  2364. if (APP.W_ScreenRecordingToolbarWindow == null)
  2365. {
  2366. APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow
  2367. {
  2368. Topmost = true
  2369. };
  2370. APP.W_ScreenRecordingToolbarWindow.Initialize();
  2371. }
  2372. else
  2373. {
  2374. APP.W_ScreenRecordingToolbarWindow.Initialize();
  2375. }
  2376. APP.W_ScreenRecordingToolbarWindow.Click_stopRecordingScreen += W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen;
  2377. //显示在右下角
  2378. APP.W_ScreenRecordingToolbarWindow.WindowStartupLocation = WindowStartupLocation.Manual;
  2379. Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
  2380. float DIP = graphics.DpiX;
  2381. float DIPY = graphics.DpiY;
  2382. APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.WorkingArea.Width / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Width;
  2383. APP.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.WorkingArea.Height / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Height - 100;
  2384. APP.W_ScreenRecordingToolbarWindow.Topmost = true;
  2385. APP.W_ScreenRecordingToolbarWindow.Show();
  2386. Hide();
  2387. });
  2388. });
  2389. }
  2390. /// <summary>
  2391. /// 保存录屏中
  2392. /// </summary>
  2393. private void W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen()
  2394. {
  2395. TxbTime.Text = "00:00";
  2396. //TxbTime.Visibility = Visibility.Hidden;
  2397. //ImgLZImg.Visibility = Visibility.Hidden;
  2398. //TxbType.Visibility = Visibility.Visible;
  2399. TxbType.Text = "保存中";
  2400. BtnScreenRecording.IsEnabled = false;
  2401. new Thread(new ThreadStart(new Action(() =>
  2402. {
  2403. while (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath + "temprs/"))
  2404. {
  2405. Thread.Sleep(100);
  2406. }
  2407. Thread.Sleep(100);
  2408. Dispatcher.Invoke(() =>
  2409. {
  2410. BtnScreenRecording.IsEnabled = true;
  2411. TxbType.Text = "准备就绪";
  2412. //TxbType.Visibility = Visibility.Hidden;
  2413. //TxbRecordScreenWord.Text = "录屏";
  2414. });
  2415. }))).Start();
  2416. }
  2417. #endregion 录屏
  2418. #region 录制窗口
  2419. #region 变量
  2420. /// <summary>
  2421. /// 视频合成前路径名
  2422. /// </summary>
  2423. private string TempVideoPathName;
  2424. /// <summary>
  2425. /// 音频保存路径名
  2426. /// </summary>
  2427. private string TempAudioPathName;
  2428. /// <summary>
  2429. /// 视频保存路径名
  2430. /// </summary>
  2431. private string VideoSavePathName;
  2432. /// <summary>
  2433. /// 截图定时器
  2434. /// </summary>
  2435. private System.Threading.Timer timer;
  2436. /// <summary>
  2437. /// 录制计时
  2438. /// </summary>
  2439. private DateTime SRTime = DateTime.Now;
  2440. /// <summary>
  2441. /// 录制大小
  2442. /// </summary>
  2443. private int gridActWidth = 1276;
  2444. /// <summary>
  2445. /// 录制大小
  2446. /// </summary>
  2447. private int gridActHeight = 898;
  2448. /// <summary>
  2449. /// 录制类型 0停止中,1录制中,2暂停中 3倒计时
  2450. /// </summary>
  2451. private int RecordType = 0;
  2452. #endregion 变量
  2453. private bool IsPressButton = false;
  2454. /// <summary>
  2455. /// 录制窗口内容
  2456. /// </summary>
  2457. /// <param name="sender"></param>
  2458. /// <param name="e"></param>
  2459. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  2460. {
  2461. #region 防止连击
  2462. if (IsPressButton)
  2463. {
  2464. return;
  2465. }
  2466. else
  2467. {
  2468. IsPressButton = true;
  2469. new Thread(new ThreadStart(new Action(() =>
  2470. {
  2471. Thread.Sleep(500);
  2472. IsPressButton = false;
  2473. }))).Start();
  2474. }
  2475. #endregion 防止连击
  2476. if (APP.PageContextData.currpage == 0)
  2477. {
  2478. MessageWindow.Show("请先导入文档或截图!");
  2479. return;
  2480. }
  2481. if (RecordType == 0)
  2482. {
  2483. ThreadPool.QueueUserWorkItem(o =>
  2484. {
  2485. bool microphoneGood = ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.microphone);
  2486. Dispatcher.Invoke(() =>
  2487. {
  2488. if (!microphoneGood)
  2489. {
  2490. MessageWindow.Show("麦克风不可用");
  2491. return;
  2492. }
  2493. //停止中开始录制
  2494. RecordType = 3;
  2495. blackboard_canvas.Visibility = Visibility.Visible;
  2496. if (RectImgBorder.Visibility != Visibility.Hidden)
  2497. {
  2498. HideAngleBorder();
  2499. }
  2500. Record();
  2501. BtnPrint.IsEnabled = false;
  2502. BtnScreenshot.IsEnabled = false;
  2503. BtnImport.IsEnabled = false;
  2504. BtnScreenRecording.IsEnabled = false;
  2505. BtnUpload.IsEnabled = false;
  2506. BtnSetUp.IsEnabled = false;
  2507. BtnDevice.IsEnabled = false;
  2508. BtnLoginType.IsEnabled = false;
  2509. blackboard_canvas.Visibility = Visibility.Visible;
  2510. TxbType.Text = "准备录制";
  2511. BtnRecord.Visibility = Visibility.Collapsed;
  2512. BtnRecordSuspend.Visibility = Visibility.Visible;
  2513. BtnRecord.IsEnabled = true;
  2514. BtnStop.IsEnabled = true;
  2515. #region 录像倒计时
  2516. if (APP.W_CountdownWindow == null)
  2517. {
  2518. APP.W_CountdownWindow = new CountdownWindow();
  2519. APP.W_CountdownWindow.Initialize();
  2520. }
  2521. else
  2522. {
  2523. APP.W_CountdownWindow.Initialize();
  2524. }
  2525. APP.W_CountdownWindow.Show();
  2526. #endregion 录像倒计时
  2527. new Thread(new ThreadStart(new Action(() =>
  2528. {
  2529. Thread.Sleep(3000);
  2530. Dispatcher.Invoke(() =>
  2531. {
  2532. TxbType.Text = "正在录制";
  2533. });
  2534. RecordType = 1;
  2535. StartRecord();
  2536. }))).Start();
  2537. });
  2538. });
  2539. }
  2540. else if (RecordType == 1)
  2541. {
  2542. //录制中暂停
  2543. RecordType = 2;
  2544. }
  2545. else if (RecordType == 2)
  2546. {
  2547. //暂停中继续录制
  2548. RecordType = 1;
  2549. }
  2550. if (RecordType == 0)
  2551. {
  2552. TxbType.Text = "准备录制";
  2553. BtnRecord.Visibility = Visibility.Visible;
  2554. BtnRecordSuspend.Visibility = Visibility.Collapsed;
  2555. BtnRecord.IsEnabled = true;
  2556. BtnStop.IsEnabled = false;
  2557. }
  2558. else if (RecordType == 1)
  2559. {
  2560. TxbType.Text = "录制中";
  2561. BtnRecord.Visibility = Visibility.Collapsed;
  2562. BtnRecordSuspend.Visibility = Visibility.Visible;
  2563. }
  2564. else if (RecordType == 2)
  2565. {
  2566. TxbType.Text = "暂停中";
  2567. BtnRecord.Visibility = Visibility.Visible;
  2568. BtnRecordSuspend.Visibility = Visibility.Collapsed;
  2569. }
  2570. else if (RecordType == 3)
  2571. {
  2572. TxbType.Text = "倒计时";
  2573. }
  2574. }
  2575. /// <summary>
  2576. /// 停止录制窗口内容
  2577. /// </summary>
  2578. /// <param name="sender"></param>
  2579. /// <param name="e"></param>
  2580. private void BtnStop_Click(object sender, RoutedEventArgs e)
  2581. {
  2582. #region 防止连击
  2583. if (IsPressButton)
  2584. {
  2585. return;
  2586. }
  2587. else
  2588. {
  2589. IsPressButton = true;
  2590. new Thread(new ThreadStart(new Action(() =>
  2591. {
  2592. Thread.Sleep(500);
  2593. IsPressButton = false;
  2594. }))).Start();
  2595. }
  2596. #endregion 防止连击
  2597. if (RecordType != 0)
  2598. {
  2599. RecordType = 0;
  2600. blackboard_canvas.Visibility = Visibility.Collapsed;
  2601. new Thread(new ThreadStart(new Action(() =>
  2602. {
  2603. EndRecord();
  2604. }))).Start();
  2605. //鼠标模式
  2606. deviceMouse();
  2607. }
  2608. }
  2609. //视频写入
  2610. private VideoFileWriter videoWriter = new VideoFileWriter();
  2611. //录制麦克风的声音
  2612. private WaveInEvent waveIn = null; //new WaveInEvent();
  2613. //音频写入
  2614. private WaveFileWriter writer = null;
  2615. /// <summary>
  2616. /// 开始录制和暂停录制
  2617. /// </summary>
  2618. private void StartRecord()
  2619. {
  2620. //电子版切换笔模式
  2621. deviceHand();
  2622. VideoInfo = new Model_Video
  2623. {
  2624. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  2625. WkType = Enum_WKVidetype.RecordingLessons
  2626. };
  2627. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  2628. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  2629. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  2630. TempVideoPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn.avi";
  2631. int num = 1;
  2632. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  2633. {
  2634. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制_" + num + "." + VideoInfo.VideoType.ToString();
  2635. TempVideoPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn_" + num + ".avi";
  2636. num++;
  2637. }
  2638. TempAudioPathName = TempVideoPathName.Replace(".avi", ".mp3");
  2639. gridActWidth = (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f) / 2) * 2;
  2640. gridActHeight = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f) / 2) * 2;
  2641. lock (this)
  2642. {
  2643. videoWriter.Open(
  2644. TempVideoPathName,
  2645. gridActWidth,
  2646. gridActHeight,
  2647. 5,
  2648. VideoCodec.MPEG4,
  2649. gridActWidth * gridActHeight * 10
  2650. );
  2651. waveIn = new WaveInEvent();
  2652. writer = new WaveFileWriter(TempAudioPathName, waveIn.WaveFormat);
  2653. //开始录音,写数据
  2654. waveIn.DataAvailable += (s, a) =>
  2655. {
  2656. if (RecordType == 1)
  2657. {
  2658. writer.Write(a.Buffer, 0, a.BytesRecorded);
  2659. }
  2660. };
  2661. //结束录音
  2662. waveIn.RecordingStopped += (s, a) =>
  2663. {
  2664. writer.Dispose();
  2665. writer = null;
  2666. waveIn.Dispose();
  2667. };
  2668. waveIn.StartRecording();
  2669. }
  2670. Dispatcher.Invoke(() =>
  2671. {
  2672. SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
  2673. Recorddt = DateTime.Now;
  2674. });
  2675. ///启动截图
  2676. timer = new System.Threading.Timer(new TimerCallback(Timer_Elapsed), null, 0, 200);
  2677. }
  2678. /// <summary>
  2679. /// 记录上次截图时间
  2680. /// </summary>
  2681. private DateTime Recorddt = DateTime.Now;
  2682. /// <summary>
  2683. /// 录制保存图片计时器
  2684. /// </summary>
  2685. /// <param name="sender"></param>
  2686. private void Timer_Elapsed(object sender)
  2687. {
  2688. if (RecordType == 1)
  2689. {
  2690. Dispatcher.Invoke(() =>
  2691. {
  2692. SRTime = SRTime.AddMilliseconds(200);
  2693. if (SRTime.Hour > 0)
  2694. {
  2695. TxbTime.Text = SRTime.ToString("HH:mm:ss");
  2696. }
  2697. else
  2698. {
  2699. TxbTime.Text = SRTime.ToString("mm:ss");
  2700. }
  2701. });
  2702. ThreadPool.QueueUserWorkItem(o =>
  2703. {
  2704. RecordSaveImage();
  2705. });
  2706. }
  2707. }
  2708. /// <summary>
  2709. /// 录制保存图片
  2710. /// </summary>
  2711. private void RecordSaveImage()
  2712. {
  2713. try
  2714. {
  2715. //保存图片
  2716. try
  2717. {
  2718. Dispatcher.Invoke(() =>
  2719. {
  2720. Bitmap bm = ImageHelper.SaveUI2Bitmap(GridMain, gridActWidth, gridActHeight);
  2721. videoWriter.WriteVideoFrame(bm);
  2722. bm.Dispose();
  2723. });
  2724. }
  2725. catch (Exception e)
  2726. {
  2727. Console.WriteLine(e.Message);
  2728. }
  2729. }
  2730. catch (Exception ex)
  2731. {
  2732. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  2733. }
  2734. }
  2735. /// <summary>
  2736. /// 停止录制并生成录制文件
  2737. /// </summary>
  2738. private void EndRecord()
  2739. {
  2740. #region 恢复被禁用的按钮
  2741. Dispatcher.Invoke(() =>
  2742. {
  2743. //打印按钮不恢复
  2744. //BtnPrint.IsEnabled = true;
  2745. BtnScreenshot.IsEnabled = true;
  2746. BtnImport.IsEnabled = true;
  2747. BtnScreenRecording.IsEnabled = true;
  2748. BtnUpload.IsEnabled = true;
  2749. BtnSetUp.IsEnabled = true;
  2750. BtnDevice.IsEnabled = true;
  2751. BtnLoginType.IsEnabled = true;
  2752. //btnStop.IsEnabled = false;//停止录制按钮不可点击
  2753. });
  2754. #endregion 恢复被禁用的按钮
  2755. try
  2756. {
  2757. #region 清空画板数据
  2758. Dispatcher.Invoke(() =>
  2759. {
  2760. APP.PageContextData.currpage = 0;
  2761. APP.PageContextData.pagenum = 0;
  2762. myblackboard.clear();
  2763. APP.PageDrawList.Clear();
  2764. imgCanvas.Source = null;
  2765. imgDocumentation.Source = null;
  2766. imgPPT.Source = null;
  2767. GridPage.Visibility = Visibility.Collapsed;
  2768. });
  2769. #endregion 清空画板数据
  2770. Dispatcher.Invoke(() =>
  2771. {
  2772. BtnRecord.IsEnabled = false;
  2773. BtnStop.IsEnabled = false;
  2774. BtnScreenRecording.IsEnabled = false;
  2775. });
  2776. //缩略图
  2777. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  2778. FileToolsCommon.CreateDirectory(ThumbnailPath);
  2779. //缩略图存储位置
  2780. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
  2781. videoWriter.Close();
  2782. waveIn.StopRecording();
  2783. //停止截图
  2784. Dispatcher.Invoke(() =>
  2785. {
  2786. timer.Change(-1, 0);
  2787. timer.Dispose();
  2788. TxbTime.Text = "00:00";
  2789. TxbType.Text = "保存中";
  2790. });
  2791. FileToolsCommon.DeleteFile(ThumbnailPathName);
  2792. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2793. VideoInfo.VideoPath = VideoSavePathName;
  2794. VideoInfo.ThumbnailPath = ThumbnailPathName;
  2795. Console.WriteLine("生成缩略图");
  2796. Console.WriteLine("合并音视频 gridActWidth:" + gridActWidth + " gridActHeight:" + gridActHeight);
  2797. //APP.FFmpeg.VideoAudioMerge(VideoSynthesisPathName, AudioPathName, VideoSavePathName, gridActWidth, gridActHeight);
  2798. FFMpegConverter ffMpeg = new FFMpegConverter();
  2799. //ffMpeg.ConvertProgress += FfMpeg_ConvertProgress;
  2800. FFMpegInput[] input = new FFMpegInput[] {
  2801. new FFMpegInput(TempVideoPathName),
  2802. new FFMpegInput(TempAudioPathName)
  2803. };
  2804. // 音视频合并
  2805. ffMpeg.ConvertMedia(
  2806. input,
  2807. VideoSavePathName,
  2808. "mp4",
  2809. new OutputSettings() { }
  2810. );
  2811. //生成缩略图
  2812. bool ThuRes = APP.FFmpeg.GenerateThumbnails(TempVideoPathName, ThumbnailPathName, 200, 130);
  2813. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  2814. VideoInfo.IsUpload = false;
  2815. VideoInfo.Uploaded = 0;
  2816. if (!APP.VideoList.Exists(x => x.FileGuid == VideoInfo.FileGuid) || !APP.VideoList.Exists(x => x.VideoPath == VideoInfo.VideoPath))
  2817. {
  2818. APP.VideoList.Add(VideoInfo);
  2819. //保存数据
  2820. APP.SaveWkData();
  2821. }
  2822. FileToolsCommon.DeleteFile(TempVideoPathName);
  2823. FileToolsCommon.DeleteFile(TempAudioPathName);
  2824. Dispatcher.Invoke(() =>
  2825. {
  2826. BtnRecord.IsEnabled = true;
  2827. BtnStop.IsEnabled = false;
  2828. BtnPrint.IsEnabled = false;
  2829. BtnScreenRecording.IsEnabled = true;
  2830. TxbType.Text = "准备就绪";
  2831. BtnRecord.Visibility = Visibility.Visible;
  2832. BtnRecordSuspend.Visibility = Visibility.Collapsed;
  2833. });
  2834. }
  2835. catch (Exception ex)
  2836. {
  2837. Dispatcher.Invoke(() =>
  2838. {
  2839. MessageWindow.Show(ex.Message);
  2840. });
  2841. }
  2842. }
  2843. #endregion 录制窗口
  2844. #region 登录
  2845. /// <summary>
  2846. /// 登录事件
  2847. /// </summary>
  2848. /// <param name="sender"></param>
  2849. /// <param name="e"></param>
  2850. private void BtnLoginType_Click(object sender, RoutedEventArgs e)
  2851. {
  2852. if ("未登录".Equals(TxbLoginType.Text) || ImgHeadImgN.Visibility == Visibility.Visible)
  2853. {
  2854. Login();
  2855. }
  2856. else
  2857. {
  2858. MessageBoxResult dr = MessageWindow.Show("确定退出登录?", "提示", MessageBoxButton.OKCancel);
  2859. if (dr == MessageBoxResult.OK)
  2860. {
  2861. LoginType();
  2862. Login();
  2863. }
  2864. }
  2865. }
  2866. /// <summary>
  2867. /// 登录
  2868. /// </summary>
  2869. private void Login()
  2870. {
  2871. if (APP.W_LoginWindow == null)
  2872. {
  2873. APP.W_LoginWindow = new LoginWindow
  2874. {
  2875. WindowStartupLocation = WindowStartupLocation.CenterOwner,
  2876. Owner = this
  2877. };
  2878. }
  2879. else
  2880. {
  2881. APP.W_LoginWindow.Initialize();
  2882. }
  2883. APP.W_LoginWindow.ShowDialog();
  2884. if (APP.IsLoginType)
  2885. {
  2886. string HeadpicPath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + ".png");
  2887. if (FileToolsCommon.IsExistFile(HeadpicPath))
  2888. {
  2889. ImgHead.ImageSource = new BitmapImage(new Uri(HeadpicPath));
  2890. }
  2891. else
  2892. {
  2893. ImgHead.ImageSource = new BitmapImage(new Uri("pack://application:,,,/BlackImages/HM_HeadImg.png"));
  2894. }
  2895. TxbLoginType.Text = APP.UserInfo.Username;
  2896. ImgHeadImgN.Visibility = Visibility.Collapsed;
  2897. ImgHeadImg.Visibility = Visibility.Visible;
  2898. }
  2899. else
  2900. {
  2901. TxbLoginType.Text = "未登录";
  2902. ImgHeadImgN.Visibility = Visibility.Visible;
  2903. ImgHeadImg.Visibility = Visibility.Collapsed;
  2904. }
  2905. }
  2906. /// <summary>
  2907. /// 状态更改为未登录
  2908. /// </summary>
  2909. private void LoginType()
  2910. {
  2911. APP.IsLoginType = false;
  2912. TxbLoginType.Text = "未登录";
  2913. ImgHeadImgN.Visibility = Visibility.Visible;
  2914. ImgHeadImg.Visibility = Visibility.Collapsed;
  2915. APP.UserInfo = new Model_UserInfo();
  2916. //ImgUpload.Visibility = Visibility.Collapsed;
  2917. //ImgUploadTwo.Visibility = Visibility.Visible;
  2918. }
  2919. #endregion 登录
  2920. #region 分页
  2921. /// 上一页 </summary> <param name="sender"></param> <param name="e"></param>
  2922. private void last_button_Click(object sender, RoutedEventArgs e)
  2923. {
  2924. if (APP.PageContextData.currpage > 1)
  2925. {
  2926. mouseDown = false;
  2927. HideAngleBorder();
  2928. APP.PageContextData.currpage -= 1;
  2929. JumpPageClick();
  2930. }
  2931. }
  2932. /// <summary>
  2933. /// 下一页
  2934. /// </summary>
  2935. /// <param name="sender"></param>
  2936. /// <param name="e"></param>
  2937. private void next_btn_Click(object sender, RoutedEventArgs e)
  2938. {
  2939. if (APP.PageContextData.currpage < APP.PageContextData.pagenum)
  2940. {
  2941. mouseDown = false;
  2942. HideAngleBorder();
  2943. APP.PageContextData.currpage += 1;
  2944. JumpPageClick();
  2945. }
  2946. }
  2947. /// <summary>
  2948. /// 跳转
  2949. /// </summary>
  2950. private void JumpPageClick()
  2951. {
  2952. myblackboard.changepage(APP.PageContextData.currpage - 1);
  2953. ScroMain.ScrollToVerticalOffset(0);
  2954. if (BtnImport.IsEnabled)
  2955. {
  2956. ///截图可用
  2957. BtnScreenshot.IsEnabled = true;
  2958. }
  2959. if (APP.PageContextData.currpage <= APP.PageDrawList.Count)
  2960. {
  2961. if (APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation != null)
  2962. {
  2963. APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = true;
  2964. }
  2965. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.PageContextData.currpage <= APP.PageDrawList.Count && APP.PageContextData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath))
  2966. {
  2967. if (APP.PageDrawList[APP.PageContextData.currpage - 1].ImgDocumentation)
  2968. {
  2969. if ("ppt".Equals(APP.PageDrawList[APP.PageContextData.currpage - 1].Type))
  2970. {
  2971. imgCanvas.Source = null;
  2972. imgDocumentation.Source = null;
  2973. imgPPT.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
  2974. BtnScreenshot.IsEnabled = false;
  2975. }
  2976. else
  2977. {
  2978. imgPPT.Source = null;
  2979. imgCanvas.Source = null;
  2980. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
  2981. BtnScreenshot.IsEnabled = false;
  2982. }
  2983. //imgCanvas.Source = null;
  2984. //imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  2985. //ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  2986. //ImgScreenshotTwo.Visibility = Visibility.Visible;
  2987. //btnScreenshot.IsEnabled = false;
  2988. }
  2989. else
  2990. {
  2991. imgPPT.Source = null;
  2992. imgDocumentation.Source = null;
  2993. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
  2994. APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = false;
  2995. if (APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation.X > 0)
  2996. {
  2997. mouseDown = false;
  2998. ImgXY();
  2999. }
  3000. }
  3001. }
  3002. else
  3003. {
  3004. imgPPT.Source = null;
  3005. imgCanvas.Source = null;
  3006. imgDocumentation.Source = null;
  3007. }
  3008. #region 修改跳转页码
  3009. CbxPageList.SelectedIndex = APP.PageContextData.currpage - 1;
  3010. #endregion 修改跳转页码
  3011. }
  3012. }
  3013. private void ImgXY()
  3014. {
  3015. imgCanvas.Width = APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes.CenterX;
  3016. imgCanvas.Height = APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes.CenterY;
  3017. imgCanvas.Margin = new Thickness(APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation.X, APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation.Y, 0, 0);
  3018. }
  3019. #endregion 分页
  3020. #region 图像缩放,移动
  3021. private bool mouseDown;
  3022. private System.Windows.Point mouseXY;
  3023. private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  3024. {
  3025. ContentControl img = sender as ContentControl;
  3026. if (img == null)
  3027. {
  3028. return;
  3029. }
  3030. img.CaptureMouse();
  3031. mouseDown = true;
  3032. mouseXY = e.GetPosition(img);
  3033. //Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
  3034. }
  3035. private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  3036. {
  3037. ContentControl img = sender as ContentControl;
  3038. if (img == null)
  3039. {
  3040. return;
  3041. }
  3042. img.ReleaseMouseCapture();
  3043. mouseDown = false;
  3044. }
  3045. private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  3046. {
  3047. ContentControl img = sender as ContentControl;
  3048. if (img == null)
  3049. {
  3050. return;
  3051. }
  3052. if (mouseDown)
  3053. {
  3054. Domousemove(img, e);
  3055. }
  3056. }
  3057. /// <summary>
  3058. /// x y轴
  3059. /// </summary>
  3060. /// <param name="img"></param>
  3061. /// <param name="e"></param>
  3062. private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
  3063. {
  3064. if (e.LeftButton != MouseButtonState.Pressed)
  3065. {
  3066. return;
  3067. }
  3068. if (APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation)
  3069. {
  3070. return;
  3071. }
  3072. TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
  3073. TranslateTransform transform = group.Children[1] as TranslateTransform;
  3074. System.Windows.Point position = e.GetPosition(img);
  3075. transform.X -= mouseXY.X - position.X;
  3076. transform.Y -= mouseXY.Y - position.Y;
  3077. mouseXY = position;
  3078. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
  3079. {
  3080. X = transform.X,
  3081. Y = transform.Y
  3082. };
  3083. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  3084. }
  3085. private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
  3086. {
  3087. ContentControl img = sender as ContentControl;
  3088. if (img == null)
  3089. {
  3090. return;
  3091. }
  3092. System.Windows.Point point = e.GetPosition(img);
  3093. //Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
  3094. System.Windows.Point PicLocate = e.GetPosition(imgCanvas);
  3095. //Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
  3096. TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
  3097. double delta = e.Delta * 0.001;
  3098. DowheelZoom(group, point, delta);
  3099. }
  3100. private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
  3101. {
  3102. System.Windows.Point pointToContent = group.Inverse.Transform(point);
  3103. ScaleTransform transform = group.Children[0] as ScaleTransform;
  3104. if (transform.ScaleX + delta < 0.1)
  3105. {
  3106. return;
  3107. }
  3108. transform.ScaleX += delta;
  3109. transform.ScaleY += delta;
  3110. TranslateTransform transform1 = group.Children[1] as TranslateTransform;
  3111. transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
  3112. transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
  3113. //LogHelper.WriteInfoLog("【img宽高】" + imgCanvas.ActualWidth.ToString() + ":"
  3114. // + imgCanvas.ActualHeight.ToString() + "百分比:" + transform.ScaleX.ToString() + ":" + transform.ScaleY.ToString()
  3115. // );
  3116. //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
  3117. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize = new ScaleTransform();
  3118. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX = transform.ScaleX;
  3119. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY = transform.ScaleY;
  3120. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
  3121. {
  3122. X = transform1.X,
  3123. Y = transform1.Y
  3124. };
  3125. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
  3126. {
  3127. CenterX = imgCanvas.ActualWidth,
  3128. CenterY = imgCanvas.ActualHeight
  3129. };
  3130. APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = false;
  3131. }
  3132. #endregion 图像缩放,移动
  3133. #region 拓思德点阵笔
  3134. #region 值初始化
  3135. // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
  3136. /// <summary>
  3137. /// A4点阵纸点阵宽度
  3138. /// </summary>
  3139. private const int A4_WIDTH = 5600;
  3140. /// <summary>
  3141. /// A4点阵纸点阵高度
  3142. /// </summary>
  3143. private const int A4_HEIGHT = 7920;
  3144. ///// <summary>
  3145. ///// 画板
  3146. ///// </summary>
  3147. //private Graphics graphics;
  3148. /// <summary>
  3149. /// 笔画坐标数组
  3150. /// </summary>
  3151. //private List<System.Drawing.Point> stroke;
  3152. /// <summary>
  3153. /// 笔序列号
  3154. /// </summary>
  3155. private string penSerial;
  3156. /// <summary>
  3157. /// 笔是否在点
  3158. /// </summary>
  3159. private bool isPenDown;
  3160. //当前点阵地址
  3161. private string currentPageSerial = string.Empty;
  3162. //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
  3163. //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
  3164. private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
  3165. #endregion 值初始化
  3166. public void InitPen()
  3167. {
  3168. //stroke = new List<System.Drawing.Point>();
  3169. //获取点阵笔实例,并绑定点阵笔事件
  3170. //将授权文件内容传入,获取点阵笔对象实例
  3171. APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
  3172. //绑定笔连接事件
  3173. APP.digitalPen.PenConnected += OnPenConnect;
  3174. //绑定笔断开事件
  3175. APP.digitalPen.PenDisconnect += OnPenDisconnect;
  3176. //绑定笔书写输出坐标事件
  3177. APP.digitalPen.PenCoordinate += OnPenCoordinate;
  3178. //绑定抬笔事件
  3179. APP.digitalPen.PenUp += OnPenUp;
  3180. //绑定落笔事件
  3181. APP.digitalPen.PenDown += OnPenDown;
  3182. APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
  3183. APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
  3184. //完成初始化点阵笔,开始与点阵笔通信
  3185. ERROR_CODE ER = APP.digitalPen.Start();
  3186. ////绑定笔在新的点阵地址页面书写事件
  3187. //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
  3188. ////绑定笔信息事件
  3189. //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
  3190. //启动接收笔数据,完成初始化工作
  3191. ERROR_CODE rc = APP.digitalPen.Start();
  3192. //判断是否成功
  3193. if (ER != ERROR_CODE.ERROR_OK)
  3194. {
  3195. MessageWindow.Show("初始化失败,授权过期,返回值:" + ER.ToString());
  3196. }
  3197. }
  3198. /// <summary>
  3199. /// 落笔
  3200. /// </summary>
  3201. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  3202. /// <param name="penSerial">点阵笔序列号</param>
  3203. /// <param name="penType">点阵笔型号编号</param>
  3204. private void OnPenDown(ulong time, string penSerial, int penType)
  3205. {
  3206. if (CheckAccess())
  3207. {
  3208. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
  3209. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  3210. }
  3211. else
  3212. {
  3213. //labPenSerial.Text = penSerial;
  3214. //labPenStatus.Text = "PenDown";
  3215. isPenDown = true;
  3216. //Dispatcher.Invoke(new Action(() =>
  3217. //{
  3218. // for (int i = 0; i < APP.PageDrawList.Count; i++)
  3219. // {
  3220. // if (APP.PageDrawList[i].PageCode == penSerial)
  3221. // {
  3222. // if (i < APP.pageData.pagenum)
  3223. // {
  3224. // if (i < APP.pageData.currpage)
  3225. // {
  3226. // int num = APP.pageData.currpage - i;
  3227. // APP.pageData.currpage -= num;
  3228. // myblackboard.changepage(APP.pageData.currpage - 1);
  3229. // if (APP.PageDrawList.Count > 0)
  3230. // {
  3231. // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  3232. // {
  3233. // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  3234. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  3235. // }
  3236. // else
  3237. // {
  3238. // imgCanvas.Source = null;
  3239. // }
  3240. // }
  3241. // }
  3242. // else
  3243. // {
  3244. // int num = i - APP.pageData.currpage;
  3245. // APP.pageData.currpage += num;
  3246. // myblackboard.changepage(APP.pageData.currpage - 1);
  3247. // if (APP.PageDrawList.Count > 0)
  3248. // {
  3249. // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  3250. // {
  3251. // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  3252. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  3253. // }
  3254. // else
  3255. // {
  3256. // imgCanvas.Source = null;
  3257. // }
  3258. // }
  3259. // }
  3260. // }
  3261. // return;
  3262. // }
  3263. // }
  3264. // //myblackboard.changepages(0, 0, true);
  3265. // //myblackboard.changepaget(0, 0, true, blackboard_canvas);
  3266. //}));
  3267. }
  3268. //myblackboard.changepages(0, 0, true);
  3269. }
  3270. /// <summary>
  3271. /// 抬笔
  3272. /// </summary>
  3273. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  3274. /// <param name="penSerial">点阵笔序列号</param>
  3275. /// <param name="penType">点阵笔型号编号</param>
  3276. private void OnPenUp(ulong time, string penSerial, int penType)
  3277. {
  3278. if (CheckAccess())
  3279. {
  3280. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
  3281. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  3282. }
  3283. else
  3284. {
  3285. isPenDown = false;
  3286. APP.PenSerial = penSerial;
  3287. //int leftPoints = stroke.Count % 3;
  3288. //if (0 != leftPoints)
  3289. //{
  3290. // int from = stroke.Count - leftPoints - 1;
  3291. // if (from < 0)
  3292. // from = 0;
  3293. // int to = stroke.Count - 1;
  3294. // DrawCoordinates(from, to);
  3295. //}
  3296. //stroke.Clear();
  3297. }
  3298. if (APP.PageContextData.currpage > 0)
  3299. {
  3300. Dispatcher.Invoke(new Action(() =>
  3301. {
  3302. myblackboard.changepages(0, 0, true, Color, PenSize, APP.PageContextData.currpage - 1, 0);
  3303. }));
  3304. }
  3305. }
  3306. /// <summary>
  3307. /// 笔断开
  3308. /// </summary>
  3309. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  3310. /// <param name="penSerial">点阵笔序列号</param>
  3311. /// <param name="penType">点阵笔型号编号</param>
  3312. private void OnPenDisconnect(ulong time, string penSerial, int penType)
  3313. {
  3314. if (CheckAccess())
  3315. {
  3316. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
  3317. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  3318. }
  3319. else
  3320. {
  3321. APP.PenSerial = penSerial;
  3322. APP.PenStatus = false;
  3323. UpdateDevStatus();
  3324. //Dispatcher.Invoke(new Action(() =>
  3325. //{
  3326. // txbNotConnected.Text = "未连接";
  3327. // txbNotConnecteds.Text = "未连接";
  3328. //}));
  3329. }
  3330. }
  3331. /// <summary>
  3332. /// 笔连接
  3333. /// </summary>
  3334. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  3335. /// <param name="penSerial">点阵笔序列号</param>
  3336. /// <param name="penType">点阵笔型号编号</param>
  3337. private void OnPenConnect(ulong time, string penSerial, int penType)
  3338. {
  3339. if (CheckAccess())
  3340. {
  3341. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
  3342. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  3343. }
  3344. else
  3345. {
  3346. APP.PenSerial = penSerial;
  3347. APP.PenStatus = true;
  3348. this.penSerial = penSerial;
  3349. //连接后,在获取笔数据前,可以清除笔内的历史数据
  3350. //APP.digitalPen.ClearMemory(penSerial);
  3351. //开始接收笔数据
  3352. APP.digitalPen.GetPenData(penSerial);
  3353. UpdateDevStatus();
  3354. }
  3355. }
  3356. /// <summary>
  3357. /// 电池电量
  3358. /// </summary>
  3359. /// <param name="time"></param>
  3360. /// <param name="penSerial"></param>
  3361. /// <param name="penType"></param>
  3362. /// <param name="capacity"></param>
  3363. private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
  3364. {
  3365. if (CheckAccess())
  3366. {
  3367. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
  3368. Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
  3369. }
  3370. else
  3371. {
  3372. //System.Windows.MessageWindow.Show("电池电量:" + capacity.ToString());
  3373. }
  3374. }
  3375. /// <summary>
  3376. /// 已用存储
  3377. /// </summary>
  3378. /// <param name="time"></param>
  3379. /// <param name="penSerial"></param>
  3380. /// <param name="penType"></param>
  3381. /// <param name="fillLevel"></param>
  3382. private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
  3383. {
  3384. if (CheckAccess())
  3385. {
  3386. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
  3387. Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
  3388. }
  3389. else
  3390. {
  3391. //System.Windows.MessageWindow.Show("存储:" + fillLevel.ToString());
  3392. }
  3393. }
  3394. /// <summary>
  3395. /// 笔书写,收到坐标
  3396. /// </summary>
  3397. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  3398. /// <param name="penSerial">点阵笔序列号</param>
  3399. /// <param name="penType">点阵笔型号编号</param>
  3400. /// <param name="pageSerial">点阵地址</param>
  3401. /// <param name="cx">x坐标</param>
  3402. /// <param name="cy">y坐标</param>
  3403. /// <param name="force">压力值</param>
  3404. private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
  3405. {
  3406. if (CheckAccess())
  3407. {
  3408. Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
  3409. Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
  3410. }
  3411. else
  3412. {
  3413. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  3414. if (!isPenDown)
  3415. {
  3416. return;
  3417. }
  3418. //stroke.Add(new System.Drawing.Point(cx, cy));
  3419. double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
  3420. double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
  3421. //点
  3422. double tempX = cx * PropW;
  3423. double tempY = cy * PropH;
  3424. //pageSerial //点阵IP地址 与打印的页面关联
  3425. if (APP.PageContextData.currpage > 0)
  3426. {
  3427. Dispatcher.Invoke(new Action(() =>
  3428. {
  3429. float Pressure = force / 100f;
  3430. //myblackboard.changepages(testX, testY,false);
  3431. myblackboard.changepages(tempX, tempY, false, Color, PenSize, APP.PageContextData.currpage - 1, Pressure);
  3432. #region 设置滚动条位置
  3433. //点在显示页面上方
  3434. if (tempY < ScroMain.VerticalOffset)
  3435. {
  3436. //滚动条当前位置
  3437. double RollCurrentLocation = ScroMain.VerticalOffset;
  3438. //向上滚动至以点为中心需要滚动的距离
  3439. double UpRoll = (RollCurrentLocation - tempY) + (ScroMain.ActualHeight / 2);
  3440. //如果小于0则等于0
  3441. double RollLocation = RollCurrentLocation - UpRoll;
  3442. if (RollLocation < 0)
  3443. {
  3444. RollLocation = 0;
  3445. }
  3446. ////滚动条实际偏移量
  3447. //double RollOffset = RollCurrentLocation - RollLocation;
  3448. ScroMain.ScrollToVerticalOffset(RollLocation);
  3449. }
  3450. //点在显示页面下方
  3451. if (tempY > ScroMain.VerticalOffset + ScroMain.ActualHeight)
  3452. {
  3453. //滚动条当前位置
  3454. double RollCurrentLocation = ScroMain.VerticalOffset;
  3455. //向下滚动至以点为中心需要滚动的距离
  3456. double DownRoll = (tempY - RollCurrentLocation) - (ScroMain.ActualHeight / 2);
  3457. //如果小于0则等于0
  3458. double RollLocation = RollCurrentLocation + DownRoll;
  3459. //滚动条最大滚动值
  3460. double ScrollbarMaxNum = GridM.ActualHeight - ScroMain.ActualHeight;
  3461. if (RollLocation > ScrollbarMaxNum)
  3462. {
  3463. RollLocation = ScrollbarMaxNum;
  3464. }
  3465. ////滚动条实际偏移量
  3466. //double RollOffset = RollLocation-RollCurrentLocation;
  3467. ScroMain.ScrollToVerticalOffset(RollLocation);
  3468. }
  3469. #endregion 设置滚动条位置
  3470. //gridM.Height //A4高度
  3471. //ScroMain.VerticalOffset;//获取滚动条位置
  3472. //ScroMain.ActualHeight//A4纸显示高度
  3473. //ScroMain.ScrollToHorizontalOffset()//设置滚动条位置
  3474. //Mouse.GetPosition(this)
  3475. if (tempX > 0 && tempY > 0)
  3476. {
  3477. //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
  3478. System.Windows.Point getP = ScroMain.PointToScreen(new System.Windows.Point(tempX, tempY - ScroMain.VerticalOffset));
  3479. SetCursorPos((int)getP.X, (int)getP.Y);
  3480. }
  3481. }));
  3482. }
  3483. ////每3个点画一条曲线
  3484. //if (stroke.Count % 3 == 0)
  3485. //{
  3486. // int from = stroke.Count - 3 - 1;
  3487. // if (from < 0)
  3488. // from = 0;
  3489. // int to = stroke.Count - 1;
  3490. // DrawCoordinates(from, to);
  3491. //}
  3492. }
  3493. }
  3494. /// <summary>
  3495. /// 停止笔
  3496. /// </summary>
  3497. public void StopDigitalPen()
  3498. {
  3499. //停止,释放资源
  3500. APP.digitalPen.Stop();
  3501. }
  3502. /// <summary>
  3503. /// 清空笔内存储
  3504. /// </summary>
  3505. public void ClearPenStorage()
  3506. {
  3507. if (!string.IsNullOrEmpty(penSerial))
  3508. {
  3509. APP.digitalPen.ClearMemory(penSerial);
  3510. }
  3511. }
  3512. /// <summary>
  3513. /// 获取剩余电量
  3514. /// </summary>
  3515. public void GetPenElectricityQuantity()
  3516. {
  3517. if (!string.IsNullOrEmpty(penSerial))
  3518. {
  3519. APP.digitalPen.GetBatteryCapacity(penSerial);
  3520. }
  3521. }
  3522. /// <summary>
  3523. /// 获取存储空间
  3524. /// </summary>
  3525. public void GetUsedStorage()
  3526. {
  3527. if (!string.IsNullOrEmpty(penSerial))
  3528. {
  3529. APP.digitalPen.GetMemoryFillLevel(penSerial);
  3530. }
  3531. }
  3532. /// <summary>
  3533. /// 开启悬浮
  3534. /// </summary>
  3535. public void 开启悬浮()
  3536. {
  3537. if (!string.IsNullOrEmpty(penSerial))
  3538. {
  3539. APP.digitalPen.SetPenHoverMode(true, penSerial);
  3540. }
  3541. }
  3542. /// <summary>
  3543. /// 关闭悬浮
  3544. /// </summary>
  3545. public void 关闭悬浮()
  3546. {
  3547. if (!string.IsNullOrEmpty(penSerial))
  3548. {
  3549. APP.digitalPen.SetPenHoverMode(false, penSerial);
  3550. }
  3551. }
  3552. /// <summary>
  3553. /// 引用user32.dll动态链接库(windows api), 使用库中定义 API:SetCursorPos 设置光标位置
  3554. /// </summary>
  3555. [System.Runtime.InteropServices.DllImport("user32.dll")]
  3556. private static extern int SetCursorPos(int x, int y);
  3557. #endregion 拓思德点阵笔
  3558. #region 写字板模式
  3559. #region 值初始化
  3560. [System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
  3561. public static extern void OutputDebugString(string message);
  3562. public bool usbIsConnected = false;
  3563. //Angle angle = Angle._270;
  3564. private eDeviceType deviceType = eDeviceType.Unknow;
  3565. ///// <summary>
  3566. ///// 点缩放比例
  3567. ///// </summary>
  3568. //private double m_nCompress = 0;
  3569. //private double m_nCompress_x = 0;
  3570. //private double m_nCompress_y = 0;
  3571. ///// <summary>
  3572. ///// 0:画布根据板子适配
  3573. ///// 1:板子根据画布适配
  3574. ///// </summary>
  3575. //private int type = 1;//默认画笔根据板子适配
  3576. //bool bScreenO = false;//判断是否是横屏,默认横屏,true:横屏幕;false:竖屏
  3577. //Drawing drawing;
  3578. //List<RobotPoint> plist = new List<RobotPoint>();
  3579. //画布宽高
  3580. //private int m_nDeviceW = 21000;
  3581. //private int m_nDeviceH = 29700;
  3582. private int m_nDeviceW = 22600;
  3583. private int m_nDeviceH = 16650;
  3584. private RobotpenGateway.robotpenController.returnPointData date = null;
  3585. //private int nResource = 0;
  3586. //private ReportRate RR = ReportRate.R_200;
  3587. //string Mac = string.Empty;
  3588. //int Recog_create = 0;
  3589. //int Recog_adddate = 0;
  3590. //int Recog_start = 0;
  3591. public bool isOpen = true;
  3592. //PrintType ptype = PrintType.NoMarkCode_FB2;
  3593. //int pageData = 0;
  3594. //bool AreSynchronized = false;
  3595. /// <summary>
  3596. /// 是否为笔模式
  3597. /// </summary>
  3598. private bool IsPen = false;
  3599. private bool IsT8 = true;
  3600. #endregion 值初始化
  3601. #region 罗博智慧笔
  3602. /// <summary>
  3603. /// 笔模式
  3604. /// </summary>
  3605. private void deviceHand()
  3606. {
  3607. IsPen = true;
  3608. if (APP.IsOutputInfoLog)
  3609. {
  3610. LogHelper.WriteInfoLog(string.Format("切换笔模式:设备类型:{0}", deviceType.ToString()));
  3611. }
  3612. if (deviceType == eDeviceType.T8B_D2 || deviceType == eDeviceType.T8Y || deviceType == eDeviceType.T8S_LQ)
  3613. {
  3614. IsT8 = true;
  3615. robotpenController.GetInstance().setDeviceMode(eDeviceMode.DEVICE_HAND);
  3616. if (APP.IsOutputInfoLog)
  3617. {
  3618. LogHelper.WriteInfoLog("使用robotpenController.GetInstance().setDeviceMode(eDeviceMode.DEVICE_HAND)切换");
  3619. }
  3620. }
  3621. else
  3622. {
  3623. IsT8 = false;
  3624. //获取当前设备模式,根据模式切换鼠标和笔
  3625. robotpenController.GetInstance()._Send(cmdId.SearchMode);
  3626. if (APP.IsOutputInfoLog)
  3627. {
  3628. LogHelper.WriteInfoLog("发送(cmdId.SearchMode)");
  3629. }
  3630. }
  3631. }
  3632. /// <summary>
  3633. /// 鼠标模式
  3634. /// </summary>
  3635. private void deviceMouse()
  3636. {
  3637. IsPen = false;
  3638. if (deviceType == eDeviceType.T8B_D2 || deviceType == eDeviceType.T8Y || deviceType == eDeviceType.T8S_LQ)
  3639. {
  3640. IsT8 = true;
  3641. robotpenController.GetInstance().setDeviceMode(eDeviceMode.DEVICE_MOUSE);
  3642. if (APP.IsOutputInfoLog)
  3643. {
  3644. LogHelper.WriteInfoLog("使用robotpenController.GetInstance().setDeviceMode(eDeviceMode.DEVICE_MOUSE)切换");
  3645. }
  3646. }
  3647. else
  3648. {
  3649. IsT8 = false;
  3650. //获取当前设备模式,根据模式切换鼠标和笔
  3651. robotpenController.GetInstance()._Send(cmdId.SearchMode);
  3652. if (APP.IsOutputInfoLog)
  3653. {
  3654. LogHelper.WriteInfoLog("发送(cmdId.SearchMode)");
  3655. }
  3656. }
  3657. }
  3658. private void Form1_searchModeEvt(int modeType)
  3659. {
  3660. //笔模式
  3661. if (modeType == 1)
  3662. {
  3663. if (APP.IsOutputInfoLog)
  3664. {
  3665. LogHelper.WriteInfoLog("当前为笔模式时,切换回鼠标模式");
  3666. }
  3667. //当前为笔模式时 切换回鼠标模式
  3668. if (!IsPen && !IsT8)
  3669. {
  3670. robotpenController.GetInstance()._Send(cmdId.SwitchMode);
  3671. if (APP.IsOutputInfoLog)
  3672. {
  3673. LogHelper.WriteInfoLog("T7设备切换成鼠标模式._Send(cmdId.SwitchMode)");
  3674. }
  3675. }
  3676. }
  3677. else
  3678. {
  3679. if (APP.IsOutputInfoLog)
  3680. {
  3681. LogHelper.WriteInfoLog("当前为鼠标模式 切换为笔模式");
  3682. }
  3683. //当前为鼠标模式 切换为笔模式
  3684. if (isOpen && !IsT8)
  3685. {
  3686. robotpenController.GetInstance()._Send(cmdId.SwitchMode);
  3687. if (APP.IsOutputInfoLog)
  3688. {
  3689. LogHelper.WriteInfoLog("T7设备切换成笔模式._Send(cmdId.SwitchMode)");
  3690. }
  3691. }
  3692. }
  3693. }
  3694. private void Form1_switchModeEvt(int modeType)
  3695. {
  3696. if (modeType == 1)
  3697. {
  3698. if (APP.IsOutputInfoLog)
  3699. {
  3700. LogHelper.WriteInfoLog("当前为笔模式");
  3701. }
  3702. if (!IsPen)
  3703. {
  3704. deviceMouse();
  3705. }
  3706. ////当前为笔模式时 切换回鼠标模式
  3707. //if (!IsPen && !IsT8)
  3708. //{
  3709. // robotpenController.GetInstance()._Send(cmdId.SwitchMode);
  3710. // if (APP.IsOutputInfoLog)
  3711. // {
  3712. // LogHelper.WriteInfoLog("T7设备切换成鼠标模式._Send(cmdId.SwitchMode)");
  3713. // }
  3714. //}
  3715. }
  3716. else
  3717. {
  3718. if (APP.IsOutputInfoLog)
  3719. {
  3720. LogHelper.WriteInfoLog("当前为鼠标模式");
  3721. }
  3722. if (IsPen)
  3723. {
  3724. deviceHand();
  3725. }
  3726. ////当前为鼠标模式 切换为笔模式
  3727. //if (isOpen && !IsT8)
  3728. //{
  3729. // robotpenController.GetInstance()._Send(cmdId.SwitchMode);
  3730. // if (APP.IsOutputInfoLog)
  3731. // {
  3732. // LogHelper.WriteInfoLog("T7设备切换成笔模式._Send(cmdId.SwitchMode)");
  3733. // }
  3734. //}
  3735. }
  3736. }
  3737. //初始化笔服务
  3738. private void InitlbPen()
  3739. {
  3740. try
  3741. {
  3742. robotpenController.GetInstance()._ConnectInitialize(eDeviceType.Gateway, IntPtr.Zero);
  3743. robotpenController.GetInstance().deviceChangeEvt += new robotpenController.DeviceChange(Form1_deviceChangeEvt);
  3744. robotpenController.GetInstance().searchModeEvt += Form1_searchModeEvt;
  3745. robotpenController.GetInstance().switchModeEvt += Form1_switchModeEvt;
  3746. //robotpenController.GetInstance().deviceChangeEvt += new robotpenController.DeviceChange(Form1_deviceChangeEvt);
  3747. //robotpenController.GetInstance().gatewatVersionEvt += Form1_gatewatVersionEvt;
  3748. //robotpenController.GetInstance().nodeStatusEvt += Form1_nodeStatusEvt;
  3749. //// 所有设备均注册该页码显示消息 目前只有T9设备才会有页码识别功能, 客户代码可以根据设备来判断是否消费该事件
  3750. //robotpenController.GetInstance().showPageEvt += new robotpenController.ShowPage(Form1_showPageEvt);
  3751. // T8A 按键消息 为了适应其他demo也能响应, 所以任何demo都消费此事件, 客户代码可根据设备类型判断是否消费此事件
  3752. robotpenController.GetInstance().keyPressEvt += new robotpenController.KeyPress(Form1_keyPressEvt);
  3753. //robotpenController.GetInstance().PageSensorCallback_Evt += Rbtnet__PageSensorEvt_;
  3754. date = new RobotpenGateway.robotpenController.returnPointData(Form1_bigDataReportEvt1);
  3755. robotpenController.GetInstance().initDeletgate(ref date);
  3756. CheckUsbConnect();
  3757. ////robotpenController.GetInstance().returnOptimizePointDataEvt += new robotpenController.returnOptimizePointData(Form1_returnOptimizePointDataEvt);
  3758. //robotpenController.GetInstance().startSyncNoteDataEvt += new robotpenController.startSyncNoteData(Form1_startSyncNoteDataEvt);
  3759. //robotpenController.GetInstance().startSyncNoteData_kzEvt += Form1_startSyncNoteData_kzEvt;
  3760. //robotpenController.GetInstance().syncNoteDataEvt += new robotpenController.syncNoteData(Form1_syncNoteDataEvt);
  3761. //robotpenController.GetInstance().endSyncNoteDataEvt += new robotpenController.endSyncNoteData(Form1_endSyncNoteDataEvt);
  3762. //robotpenController.GetInstance().getOfflineNoteDataEvt += new robotpenController.getOfflineNoteData(Form1_getOfflineNoteDataEvt);
  3763. }
  3764. catch (Exception ex)
  3765. {
  3766. LogHelper.WriteErrLog("设备初始化失败:" + ex.Message, ex);
  3767. }
  3768. }
  3769. /// <summary>
  3770. /// 委托实例函数,用于异步修改listview显示的USB连接设备信息
  3771. /// </summary>
  3772. private void SetListView()
  3773. {
  3774. if (usbIsConnected)
  3775. {
  3776. robotpenController.GetInstance()._CloseConnect();
  3777. }
  3778. CheckUsbConnect();
  3779. }
  3780. /// <summary>
  3781. /// 设备插拔消息,更新listview
  3782. /// </summary>
  3783. /// <param name="bStatus"></param>
  3784. /// <param name="uPid"></param>
  3785. private void Form1_deviceChangeEvt(bool bStatus, ushort uPid)
  3786. {
  3787. //throw new NotImplementedException();
  3788. //Console.WriteLine();
  3789. try
  3790. {
  3791. if (APP.IsOutputInfoLog)
  3792. {
  3793. LogHelper.WriteInfoLog(string.Format("设备状态{0} PID = {1}", bStatus, uPid));
  3794. }
  3795. }
  3796. catch (Exception)
  3797. {
  3798. }
  3799. //SetListView();
  3800. CheckUsbConnect();
  3801. }
  3802. /// <summary>
  3803. /// 书写
  3804. /// </summary>
  3805. /// ///
  3806. /// <param name="bIndex"></param>
  3807. /// <param name="bPenStatus"></param>
  3808. /// <param name="bx"></param>
  3809. /// <param name="by"></param>
  3810. /// <param name="bPress"></param>
  3811. private void Form1_bigDataReportEvt1(byte bIndex, byte bPenStatus, short bx, short by, short bPress)
  3812. {
  3813. if (bx == 0 && by == 0 && bPenStatus == 0 && bPress == 0)
  3814. {
  3815. return;
  3816. }
  3817. //17是按下,16是抬起
  3818. if (bPenStatus == 16 || bPenStatus == 0)
  3819. {
  3820. //stroke.Clear();
  3821. if (APP.PageContextData.currpage > 0)
  3822. {
  3823. Dispatcher.Invoke(new Action(() =>
  3824. {
  3825. myblackboard.changepages(0, 0, true, Color, PenSize, APP.PageContextData.currpage - 1, 0);
  3826. }));
  3827. }
  3828. }
  3829. ////按下
  3830. //if (bPenStatus == 17)
  3831. //{
  3832. //}
  3833. //if (APP.IsOutputInfoLog)
  3834. //{
  3835. // LogHelper.WriteInfoLog(string.Format(@"x={0},y={1},s={2},p={3}", bx, by, bPenStatus, bPress));
  3836. //}
  3837. //stroke.Add(new System.Drawing.Point(by, bx));
  3838. double PropW = blackboard_canvas.ActualWidth / m_nDeviceH;
  3839. double PropH = blackboard_canvas.ActualHeight / m_nDeviceW;
  3840. //点
  3841. double tempY = (m_nDeviceW - bx) * PropH;
  3842. double tempX = by * PropW;
  3843. //pageSerial //点阵IP地址 与打印的页面关联
  3844. if (APP.PageContextData.currpage > 0)
  3845. {
  3846. Dispatcher.Invoke(new Action(() =>
  3847. {
  3848. float Pressure = bPress / 100f;
  3849. //myblackboard.changepages(testX, testY,false);
  3850. if (bPress > 0)
  3851. {
  3852. myblackboard.changepages(tempX, tempY, false, Color, PenSize, APP.PageContextData.currpage - 1, Pressure);
  3853. }
  3854. #region 设置滚动条位置
  3855. //点在显示页面上方
  3856. if (tempY < ScroMain.VerticalOffset)
  3857. {
  3858. //滚动条当前位置
  3859. double RollCurrentLocation = ScroMain.VerticalOffset;
  3860. //向上滚动至以点为中心需要滚动的距离
  3861. double UpRoll = (RollCurrentLocation - tempY) + (ScroMain.ActualHeight / 2);
  3862. //如果小于0则等于0
  3863. double RollLocation = RollCurrentLocation - UpRoll;
  3864. if (RollLocation < 0)
  3865. {
  3866. RollLocation = 0;
  3867. }
  3868. ////滚动条实际偏移量
  3869. //double RollOffset = RollCurrentLocation - RollLocation;
  3870. ScroMain.ScrollToVerticalOffset(RollLocation);
  3871. }
  3872. //点在显示页面下方
  3873. if (tempY > ScroMain.VerticalOffset + ScroMain.ActualHeight)
  3874. {
  3875. //滚动条当前位置
  3876. double RollCurrentLocation = ScroMain.VerticalOffset;
  3877. //向下滚动至以点为中心需要滚动的距离
  3878. double DownRoll = (tempY - RollCurrentLocation) - (ScroMain.ActualHeight / 2);
  3879. //如果小于0则等于0
  3880. double RollLocation = RollCurrentLocation + DownRoll;
  3881. //滚动条最大滚动值
  3882. double ScrollbarMaxNum = GridM.ActualHeight - ScroMain.ActualHeight;
  3883. if (RollLocation > ScrollbarMaxNum)
  3884. {
  3885. RollLocation = ScrollbarMaxNum;
  3886. }
  3887. ////滚动条实际偏移量
  3888. //double RollOffset = RollLocation-RollCurrentLocation;
  3889. ScroMain.ScrollToVerticalOffset(RollLocation);
  3890. }
  3891. #endregion 设置滚动条位置
  3892. if (tempX > 0 && tempY > 0)
  3893. {
  3894. //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
  3895. System.Windows.Point getP = ScroMain.PointToScreen(new System.Windows.Point(tempX, tempY - ScroMain.VerticalOffset));
  3896. SetCursorPos((int)getP.X, (int)getP.Y);
  3897. }
  3898. }));
  3899. }
  3900. }
  3901. /// <summary>
  3902. /// 判断是否有设备连接
  3903. /// </summary>
  3904. public void CheckUsbConnect()
  3905. {
  3906. usbIsConnected = false;
  3907. Thread.Sleep(200);
  3908. int nDeviceCount = robotpenController.GetInstance()._GetDeviceCount();
  3909. if (APP.IsOutputInfoLog)
  3910. {
  3911. LogHelper.WriteInfoLog(string.Format("当前有 {0} 个设备", nDeviceCount));
  3912. }
  3913. if (nDeviceCount > 0)
  3914. {
  3915. //this.listView1.BeginUpdate();
  3916. for (int i = 0; i < nDeviceCount; ++i)
  3917. {
  3918. ushort npid = 0;
  3919. ushort nvid = 0;
  3920. string strDeviceName = string.Empty;
  3921. eDeviceType dtype = eDeviceType.Unknow;
  3922. if (robotpenController.GetInstance()._GetAvailableDevice(i, ref npid, ref nvid, ref strDeviceName, ref dtype))
  3923. {
  3924. if (!usbIsConnected)
  3925. {
  3926. usbIsConnected = true;
  3927. deviceType = dtype;
  3928. robotpenController.GetInstance()._ConnectInitialize(deviceType, IntPtr.Zero);
  3929. int nRes = robotpenController.GetInstance()._ConnectOpen();
  3930. if (nRes != 0)
  3931. {
  3932. //LogHelper.WriteInfoLog(string.Format(@"x={0},y={1},s={2},p={3}", bx, by, bPenStatus, bPress));
  3933. LogHelper.WriteErrLog("设备自动连接失败,请重新插拔设备或尝试手动连接!", null);
  3934. usbIsConnected = false;
  3935. break;
  3936. }
  3937. //robotpenController.GetInstance()._Send(cmdId.SwitchMode);
  3938. robotpenController.GetInstance()._Send(cmdId.GetConfig);
  3939. APP.BoardStatus = true;
  3940. try
  3941. {
  3942. int banWidth = robotpenController.GetInstance().getWidth();
  3943. int banHeight = robotpenController.GetInstance().getHeight();
  3944. if (banWidth > 0 && banHeight > 0)
  3945. {
  3946. if (banWidth > banHeight)
  3947. {
  3948. m_nDeviceW = banWidth;
  3949. m_nDeviceH = banHeight;
  3950. }
  3951. else
  3952. {
  3953. m_nDeviceW = banHeight;
  3954. m_nDeviceH = banWidth;
  3955. }
  3956. }
  3957. if (APP.IsOutputInfoLog)
  3958. {
  3959. LogHelper.WriteInfoLog(string.Format("手写板宽度为:{0} 高度为:{1}", m_nDeviceW, m_nDeviceH));
  3960. }
  3961. }
  3962. catch (Exception ex)
  3963. {
  3964. LogHelper.WriteErrLog("手写板大小获取失败:" + ex.Message, ex);
  3965. }
  3966. UpdateDevStatus();
  3967. if (APP.IsOutputInfoLog)
  3968. {
  3969. LogHelper.WriteInfoLog(string.Format("设备类型:{0}", deviceType.ToString()));
  3970. }
  3971. new Thread(new ThreadStart(new Action(() =>
  3972. {
  3973. Thread.Sleep(500);
  3974. robotpenController.GetInstance()._Send(cmdId.SearchMode);
  3975. }))).Start();
  3976. }
  3977. }
  3978. }
  3979. }
  3980. else
  3981. {
  3982. APP.BoardStatus = false;
  3983. UpdateDevStatus();
  3984. }
  3985. }
  3986. /// <summary>
  3987. /// 按键回调函数
  3988. /// </summary>
  3989. /// <param name="Value"></param>
  3990. private void Form1_keyPressEvt(eKeyPress Value)
  3991. {
  3992. Dispatcher.Invoke(new Action(() =>
  3993. {
  3994. switch (Value)
  3995. {
  3996. case eKeyPress.CLICK:
  3997. break;
  3998. case eKeyPress.DBCLICK:
  3999. break;
  4000. case eKeyPress.PAGEUP:
  4001. last_button_Click(null, null);
  4002. break;
  4003. case eKeyPress.PAGEDOWN:
  4004. next_btn_Click(null, null);
  4005. break;
  4006. case eKeyPress.CREATEPAGE://关机键
  4007. break;
  4008. case eKeyPress.KEY_A:
  4009. break;
  4010. case eKeyPress.KEY_B:
  4011. break;
  4012. case eKeyPress.KEY_C:
  4013. break;
  4014. case eKeyPress.KEY_D:
  4015. break;
  4016. case eKeyPress.KEY_E:
  4017. break;
  4018. case eKeyPress.KEY_F:
  4019. break;
  4020. case eKeyPress.KEY_UP:
  4021. last_button_Click(null, null);
  4022. break;
  4023. case eKeyPress.KEY_DOWN:
  4024. next_btn_Click(null, null);
  4025. break;
  4026. case eKeyPress.KEY_YES:
  4027. break;
  4028. case eKeyPress.KEY_NO:
  4029. break;
  4030. case eKeyPress.KEY_CANCEL:
  4031. break;
  4032. case eKeyPress.KEY_OK:
  4033. break;
  4034. case eKeyPress.PAGEUPCLICK://上一页
  4035. last_button_Click(null, null);
  4036. break;
  4037. case eKeyPress.PAGEUPDBCLICK://双击上一页
  4038. break;
  4039. case eKeyPress.PAGEUPPRESS://长按上一页
  4040. break;
  4041. case eKeyPress.PAGEDOWNCLICK://下一页
  4042. next_btn_Click(null, null);
  4043. break;
  4044. case eKeyPress.PAGEDOWNDBCLICK://双击下一页
  4045. break;
  4046. case eKeyPress.PAGEDOWNPRESS://长按下一页
  4047. break;
  4048. }
  4049. }));
  4050. }
  4051. #endregion 罗博智慧笔
  4052. /// <summary>
  4053. /// 更新设备状态显示
  4054. /// </summary>
  4055. public void UpdateDevStatus()
  4056. {
  4057. if (APP.BoardStatus && (APP.PenStatus || APP.TQLPenStatus))
  4058. {
  4059. Dispatcher.Invoke(new Action(() =>
  4060. {
  4061. txbNotConnected.Text = "笔/板已连接";
  4062. txbNotConnecteds.Text = "笔/板已连接";
  4063. }));
  4064. }
  4065. else if (APP.BoardStatus)
  4066. {
  4067. Dispatcher.Invoke(new Action(() =>
  4068. {
  4069. txbNotConnected.Text = "手写板已连接";
  4070. txbNotConnecteds.Text = "手写板已连接";
  4071. }));
  4072. }
  4073. else if (APP.PenStatus)
  4074. {
  4075. Dispatcher.Invoke(new Action(() =>
  4076. {
  4077. txbNotConnected.Text = "智能笔已连接";
  4078. txbNotConnecteds.Text = "智能笔已连接";
  4079. }));
  4080. }
  4081. else if (APP.TQLPenStatus)
  4082. {
  4083. Dispatcher.Invoke(new Action(() =>
  4084. {
  4085. txbNotConnected.Text = "智能笔已连接";
  4086. txbNotConnecteds.Text = "智能笔已连接";
  4087. }));
  4088. }
  4089. else
  4090. {
  4091. Dispatcher.Invoke(new Action(() =>
  4092. {
  4093. txbNotConnected.Text = "未连接";
  4094. txbNotConnecteds.Text = "未连接";
  4095. }));
  4096. }
  4097. }
  4098. #endregion 写字板模式
  4099. #region 腾千里手写笔
  4100. /// <summary>
  4101. /// 是否在书写
  4102. /// </summary>
  4103. private bool isTQLPenDown = false;
  4104. /// <summary>
  4105. /// TQL点阵笔宽高
  4106. /// </summary>
  4107. private static float TQLA4_WIDTH = (float)2480 / (float)300 * (float)25.4 / (float)1.524; //(float)1075 / (float)150 * (float)25.4 / (float)1.524; //OID4
  4108. private static float TQLA4_HEIGHT = (float)3509 / (float)300 * (float)25.4 / (float)1.524;//(float)1512 / (float)150 * (float)25.4 / (float)1.524;
  4109. /// <summary>
  4110. /// TQL初始化
  4111. /// </summary>
  4112. public void InitTQLPPen()
  4113. {
  4114. if (APP.TQLPenevents == null)
  4115. {
  4116. APP.TQLPenevents = new PenEvents(1);
  4117. }
  4118. else
  4119. {
  4120. APP.TQLPenevents.InToType = 1;
  4121. }
  4122. }
  4123. /// <summary>
  4124. /// 笔落下
  4125. /// </summary>
  4126. public void TQLDown()
  4127. {
  4128. isTQLPenDown = true;
  4129. if (APP.PageContextData.currpage > 0)
  4130. {
  4131. Dispatcher.Invoke(new Action(() =>
  4132. {
  4133. myblackboard.changepages(0, 0, true, Color, PenSize, APP.PageContextData.currpage - 1, 0);
  4134. }));
  4135. }
  4136. }
  4137. /// <summary>
  4138. /// 笔抬起
  4139. /// </summary>
  4140. public void TQLUp()
  4141. {
  4142. isTQLPenDown = false;
  4143. //stroke.Clear();
  4144. if (APP.PageContextData.currpage > 0)
  4145. {
  4146. Dispatcher.Invoke(new Action(() =>
  4147. {
  4148. myblackboard.changepages(0, 0, true, Color, PenSize, APP.PageContextData.currpage - 1, 0);
  4149. }));
  4150. }
  4151. }
  4152. /// <summary>
  4153. /// 笔书写
  4154. /// </summary>
  4155. /// <param name="cx"></param>
  4156. /// <param name="cy"></param>
  4157. /// <param name="force"></param>
  4158. public void TQLPenWrite(double cx, double cy, int force)
  4159. {
  4160. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  4161. if (!isTQLPenDown)
  4162. {
  4163. return;
  4164. }
  4165. double PropW = blackboard_canvas.ActualWidth / TQLA4_WIDTH;
  4166. double PropH = blackboard_canvas.ActualHeight / TQLA4_HEIGHT;
  4167. //点
  4168. double tempX = cx * PropW;
  4169. double tempY = cy * PropH;
  4170. if (APP.PageContextData.currpage > 0)
  4171. {
  4172. Dispatcher.Invoke(new Action(() =>
  4173. {
  4174. //0~1023,亦即有 1024 阶供应用软件后续应用之用,如笔锋笔触,暂无用
  4175. float Pressure = (float)force / 1023f;
  4176. myblackboard.changepages(tempX, tempY, false, Color, PenSize, APP.PageContextData.currpage - 1, Pressure);
  4177. #region 设置滚动条位置
  4178. //点在显示页面上方
  4179. if (tempY < ScroMain.VerticalOffset)
  4180. {
  4181. //滚动条当前位置
  4182. double RollCurrentLocation = ScroMain.VerticalOffset;
  4183. //向上滚动至以点为中心需要滚动的距离
  4184. double UpRoll = (RollCurrentLocation - tempY) + (ScroMain.ActualHeight / 2);
  4185. //如果小于0则等于0
  4186. double RollLocation = RollCurrentLocation - UpRoll;
  4187. if (RollLocation < 0)
  4188. {
  4189. RollLocation = 0;
  4190. }
  4191. ////滚动条实际偏移量
  4192. //double RollOffset = RollCurrentLocation - RollLocation;
  4193. ScroMain.ScrollToVerticalOffset(RollLocation);
  4194. }
  4195. //点在显示页面下方
  4196. if (tempY > ScroMain.VerticalOffset + ScroMain.ActualHeight)
  4197. {
  4198. //滚动条当前位置
  4199. double RollCurrentLocation = ScroMain.VerticalOffset;
  4200. //向下滚动至以点为中心需要滚动的距离
  4201. double DownRoll = (tempY - RollCurrentLocation) - (ScroMain.ActualHeight / 2);
  4202. //如果小于0则等于0
  4203. double RollLocation = RollCurrentLocation + DownRoll;
  4204. //滚动条最大滚动值
  4205. double ScrollbarMaxNum = GridM.ActualHeight - ScroMain.ActualHeight;
  4206. if (RollLocation > ScrollbarMaxNum)
  4207. {
  4208. RollLocation = ScrollbarMaxNum;
  4209. }
  4210. ////滚动条实际偏移量
  4211. //double RollOffset = RollLocation-RollCurrentLocation;
  4212. ScroMain.ScrollToVerticalOffset(RollLocation);
  4213. }
  4214. #endregion 设置滚动条位置
  4215. if (tempX > 0 && tempY > 0)
  4216. {
  4217. System.Windows.Point getP = ScroMain.PointToScreen(new System.Windows.Point(tempX, tempY - ScroMain.VerticalOffset));
  4218. SetCursorPos((int)getP.X, (int)getP.Y);
  4219. }
  4220. }));
  4221. }
  4222. }
  4223. #endregion 腾千里手写笔
  4224. #region 图片拉伸移动
  4225. private System.Windows.Point initialPoint;
  4226. /// <summary>
  4227. /// 隐藏图片四个点和线
  4228. /// </summary>
  4229. private void HideAngleBorder()
  4230. {
  4231. RectLeftUp.Visibility = Visibility.Hidden;
  4232. RectRightUp.Visibility = Visibility.Hidden;
  4233. RectLeftDown.Visibility = Visibility.Hidden;
  4234. RectRightDown.Visibility = Visibility.Hidden;
  4235. RectImgBorder.Visibility = Visibility.Hidden;
  4236. }
  4237. private void ShowAngleBorder()
  4238. {
  4239. PointLocation();
  4240. RectLeftUp.Visibility = Visibility.Visible;
  4241. RectRightUp.Visibility = Visibility.Visible;
  4242. RectLeftDown.Visibility = Visibility.Visible;
  4243. RectRightDown.Visibility = Visibility.Visible;
  4244. RectImgBorder.Visibility = Visibility.Visible;
  4245. }
  4246. /// <summary>
  4247. /// 确定四个点和边框的位置大小
  4248. /// </summary>
  4249. private void PointLocation()
  4250. {
  4251. RectImgBorder.Width = imgCanvas.ActualWidth + 10.0;
  4252. RectImgBorder.Height = imgCanvas.ActualHeight + 10.0;
  4253. RectImgBorder.Margin = new Thickness(imgCanvas.Margin.Left - 5.0, imgCanvas.Margin.Top - 5.0, 0, 0);
  4254. Canvas.SetLeft(RectLeftUp, imgCanvas.Margin.Left - 10.0);
  4255. Canvas.SetTop(RectLeftUp, imgCanvas.Margin.Top - 10.0);
  4256. Canvas.SetLeft(RectRightUp, imgCanvas.Margin.Left + imgCanvas.ActualWidth - 10.0);
  4257. Canvas.SetTop(RectRightUp, imgCanvas.Margin.Top - 10.0);
  4258. Canvas.SetLeft(RectLeftDown, imgCanvas.Margin.Left - 10.0);
  4259. Canvas.SetTop(RectLeftDown, imgCanvas.Margin.Top + imgCanvas.ActualHeight - 10.0);
  4260. Canvas.SetLeft(RectRightDown, imgCanvas.Margin.Left + imgCanvas.ActualWidth - 10.0);
  4261. Canvas.SetTop(RectRightDown, imgCanvas.Margin.Top + imgCanvas.ActualHeight - 10.0);
  4262. }
  4263. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  4264. {
  4265. System.Windows.Point point = e.GetPosition(imgCanvas);
  4266. initialPoint = point;
  4267. HideAngleBorder();
  4268. }
  4269. private void imgCanvas_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  4270. {
  4271. if (e.LeftButton == MouseButtonState.Pressed && mouseDown)
  4272. {
  4273. System.Windows.Point point = e.GetPosition(imgCanvas);
  4274. imgCanvas.Margin = new Thickness(imgCanvas.Margin.Left + (point.X - initialPoint.X), imgCanvas.Margin.Top + (point.Y - initialPoint.Y), 0, 0);
  4275. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
  4276. {
  4277. X = imgCanvas.Margin.Left,
  4278. Y = imgCanvas.Margin.Top
  4279. };
  4280. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
  4281. {
  4282. CenterX = imgCanvas.ActualWidth,
  4283. CenterY = imgCanvas.ActualHeight
  4284. };
  4285. APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = false;
  4286. }
  4287. }
  4288. private void imgCanvas_MouseUp(object sender, MouseButtonEventArgs e)
  4289. {
  4290. if (mouseDown)
  4291. {
  4292. ShowAngleBorder();
  4293. }
  4294. }
  4295. private System.Drawing.PointF imgRightDown;
  4296. /// <summary>
  4297. /// 设置控件最上层
  4298. /// </summary>
  4299. /// <param name="element"></param>
  4300. public void BringToFront(Thumb element)//图片置于最顶层显示
  4301. {
  4302. if (element == null)
  4303. {
  4304. return;
  4305. }
  4306. Canvas parent = element.Parent as Canvas;
  4307. if (parent == null)
  4308. {
  4309. return;
  4310. }
  4311. int maxZ = parent.Children.OfType<UIElement>()//linq语句,取Zindex的最大值
  4312. .Where(x => x != element)
  4313. .Select(x => Canvas.GetZIndex(x))
  4314. .Max();
  4315. Canvas.SetZIndex(element, maxZ + 1);
  4316. }
  4317. private void RectRightUp_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
  4318. {
  4319. try
  4320. {
  4321. Thumb thu = (Thumb)sender;
  4322. BringToFront(thu);
  4323. imgRightDown = new System.Drawing.PointF((float)(imgCanvas.Margin.Left + imgCanvas.ActualWidth), (float)(imgCanvas.Margin.Top + imgCanvas.ActualHeight));
  4324. HideAngleBorder();
  4325. switch (thu.Name)
  4326. {
  4327. case "RectLeftUp":
  4328. RectLeftUp.Visibility = Visibility.Visible;
  4329. break;
  4330. case "RectRightUp":
  4331. RectRightUp.Visibility = Visibility.Visible;
  4332. break;
  4333. case "RectLeftDown":
  4334. RectLeftDown.Visibility = Visibility.Visible;
  4335. break;
  4336. case "RectRightDown":
  4337. RectRightDown.Visibility = Visibility.Visible;
  4338. break;
  4339. default:
  4340. break;
  4341. }
  4342. }
  4343. catch (Exception ex)
  4344. {
  4345. MessageWindow.Show(ex.Message);
  4346. }
  4347. }
  4348. private void RectRightUp_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
  4349. {
  4350. try
  4351. {
  4352. if (mouseDown)
  4353. {
  4354. Thumb thu = (Thumb)sender;
  4355. #region 判断是否超出 暂无
  4356. double plul = Canvas.GetLeft(RectLeftUp);
  4357. double plut = Canvas.GetTop(RectLeftUp);
  4358. double prdl = Canvas.GetLeft(RectRightDown);
  4359. double prdt = Canvas.GetTop(RectRightDown);
  4360. #endregion 判断是否超出 暂无
  4361. //Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4362. //Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4363. double imgW = 0;
  4364. double imgH = 0;
  4365. double imgX = 0;
  4366. double imgY = 0;
  4367. switch (thu.Name)
  4368. {
  4369. case "RectLeftUp":
  4370. #region 左上
  4371. imgW = imgRightDown.X - (Mouse.GetPosition(GridM).X);
  4372. imgH = imgRightDown.Y - (Mouse.GetPosition(GridM).Y);
  4373. imgX = 0;
  4374. imgY = 0;
  4375. if (imgW < 50)
  4376. {
  4377. imgCanvas.Width = 50;
  4378. imgX = imgCanvas.Margin.Left;
  4379. Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
  4380. }
  4381. else
  4382. {
  4383. imgCanvas.Width = imgW;
  4384. imgX = Mouse.GetPosition(GridM).X;
  4385. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4386. }
  4387. if (imgH < 50)
  4388. {
  4389. imgCanvas.Height = 50;
  4390. imgY = imgCanvas.Margin.Top;
  4391. Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
  4392. }
  4393. else
  4394. {
  4395. imgCanvas.Height = imgH;
  4396. imgY = Mouse.GetPosition(GridM).Y;
  4397. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4398. }
  4399. imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  4400. #endregion 左上
  4401. break;
  4402. case "RectRightUp":
  4403. #region 右上
  4404. imgW = Mouse.GetPosition(GridM).X - imgCanvas.Margin.Left;
  4405. imgH = imgRightDown.Y - (Mouse.GetPosition(GridM).Y);
  4406. imgX = 0;
  4407. imgY = 0;
  4408. if (imgW < 50)
  4409. {
  4410. imgCanvas.Width = 50;
  4411. imgX = imgCanvas.Margin.Left;
  4412. Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
  4413. }
  4414. else
  4415. {
  4416. imgCanvas.Width = imgW;
  4417. imgX = imgCanvas.Margin.Left;
  4418. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4419. }
  4420. if (imgH < 50)
  4421. {
  4422. imgCanvas.Height = 50;
  4423. imgY = imgCanvas.Margin.Top;
  4424. Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
  4425. }
  4426. else
  4427. {
  4428. imgCanvas.Height = imgH;
  4429. imgY = Mouse.GetPosition(GridM).Y;
  4430. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4431. }
  4432. imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  4433. #endregion 右上
  4434. break;
  4435. case "RectLeftDown":
  4436. #region 左下
  4437. imgW = imgRightDown.X - (Mouse.GetPosition(GridM).X);
  4438. imgH = Mouse.GetPosition(GridM).Y - imgCanvas.Margin.Top;
  4439. imgX = 0;
  4440. imgY = 0;
  4441. if (imgW < 50)
  4442. {
  4443. imgCanvas.Width = 50;
  4444. imgX = imgCanvas.Margin.Left;
  4445. Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
  4446. }
  4447. else
  4448. {
  4449. imgCanvas.Width = imgW;
  4450. imgX = Mouse.GetPosition(GridM).X;
  4451. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4452. }
  4453. if (imgH < 50)
  4454. {
  4455. imgCanvas.Height = 50;
  4456. imgY = imgCanvas.Margin.Top;
  4457. Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
  4458. }
  4459. else
  4460. {
  4461. imgCanvas.Height = imgH;
  4462. imgY = imgCanvas.Margin.Top;
  4463. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4464. }
  4465. imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  4466. //imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(GridM).X);
  4467. //imgCanvas.Height = Mouse.GetPosition(GridM).Y - imgCanvas.Margin.Top;
  4468. //imgCanvas.Margin = new Thickness(Mouse.GetPosition(GridM).X, imgCanvas.Margin.Top, 0, 0);
  4469. #endregion 左下
  4470. break;
  4471. case "RectRightDown":
  4472. #region 右下
  4473. imgW = Mouse.GetPosition(GridM).X - imgCanvas.Margin.Left;
  4474. imgH = Mouse.GetPosition(GridM).Y - imgCanvas.Margin.Top;
  4475. if (imgW < 50)
  4476. {
  4477. imgCanvas.Width = 50;
  4478. Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
  4479. }
  4480. else
  4481. {
  4482. imgCanvas.Width = imgW;
  4483. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4484. }
  4485. if (imgH < 50)
  4486. {
  4487. imgCanvas.Height = 50;
  4488. Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
  4489. }
  4490. else
  4491. {
  4492. imgCanvas.Height = imgH;
  4493. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4494. }
  4495. //imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  4496. //imgCanvas.Width += e.HorizontalChange;
  4497. //imgCanvas.Height += e.VerticalChange;
  4498. #endregion 右下
  4499. break;
  4500. default:
  4501. break;
  4502. }
  4503. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
  4504. {
  4505. X = imgCanvas.Margin.Left,
  4506. Y = imgCanvas.Margin.Top
  4507. };
  4508. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
  4509. {
  4510. CenterX = imgCanvas.ActualWidth,
  4511. CenterY = imgCanvas.ActualHeight
  4512. };
  4513. APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = false;
  4514. }
  4515. //lbl1.Content = imgCanvas.Margin.Left + "," + imgCanvas.Margin.Top;
  4516. //lbl2.Content = (imgCanvas.Margin.Left+ imgCanvas.Width) +"," + imgCanvas.Margin.Top;
  4517. //lbl3.Content = imgCanvas.Margin.Left + "," + (imgCanvas.Margin.Top+ imgCanvas.Height);
  4518. //lbl4.Content= (imgCanvas.Margin.Left + imgCanvas.Width )+ "," + (imgCanvas.Margin.Top + imgCanvas.Height);
  4519. }
  4520. catch (Exception)
  4521. {
  4522. MessageWindow.Show("图片过小!");
  4523. }
  4524. }
  4525. private void RectRightUp_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
  4526. {
  4527. ShowAngleBorder();
  4528. }
  4529. /// <summary>
  4530. /// 点击标题栏 隐藏截图的四个点和线
  4531. /// </summary>
  4532. /// <param name="sender"></param>
  4533. /// <param name="e"></param>
  4534. private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
  4535. {
  4536. HideAngleBorder();
  4537. }
  4538. /// <summary>
  4539. /// 鼠标左键点击事件
  4540. /// </summary>
  4541. /// <param name="sender"></param>
  4542. /// <param name="e"></param>
  4543. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  4544. {
  4545. if (RectImgBorder.Visibility != Visibility.Hidden)
  4546. {
  4547. HideAngleBorder();
  4548. }
  4549. }
  4550. #endregion 图片拉伸移动
  4551. #region 方法
  4552. /// <summary>
  4553. /// 录屏 录制 截图 导入文档 增加 主页面显示
  4554. /// </summary>
  4555. private void Record()
  4556. {
  4557. PageHide();
  4558. GridMain.Visibility = Visibility.Visible;
  4559. GridRecordingTitle.Visibility = Visibility.Visible;
  4560. if (APP.PageContextData.pagenum > 0)
  4561. {
  4562. GridPage.Visibility = Visibility.Visible;
  4563. }
  4564. DataContext = APP.PageContextData;
  4565. }
  4566. #endregion 方法
  4567. #region 跳转
  4568. /// <summary>
  4569. /// 跳转
  4570. /// </summary>
  4571. /// <param name="sender"></param>
  4572. /// <param name="e"></param>
  4573. private void CbxPageList_SelectionChanged(object sender, SelectionChangedEventArgs e)
  4574. {
  4575. #region 安全
  4576. if (CbxPageList.SelectedValue == null)
  4577. {
  4578. return;
  4579. }
  4580. if (APP.PageContextData.currpage == int.Parse(CbxPageList.SelectedValue.ToString()))
  4581. {
  4582. return;
  4583. }
  4584. #endregion 安全
  4585. int JumpPage;
  4586. try
  4587. {
  4588. JumpPage = int.Parse(CbxPageList.SelectedValue.ToString());
  4589. }
  4590. catch (Exception)
  4591. {
  4592. MessageWindow.Show("操作有误!请输入有效的页码!");
  4593. return;
  4594. }
  4595. if (JumpPage < 1)
  4596. {
  4597. JumpPage = 1;
  4598. }
  4599. if (JumpPage > int.Parse(txbTotalpage.Text))
  4600. {
  4601. JumpPage = int.Parse(txbTotalpage.Text);
  4602. }
  4603. #region 跳转
  4604. APP.PageContextData.currpage = JumpPage;
  4605. JumpPageClick();
  4606. #endregion 跳转
  4607. }
  4608. #endregion 跳转
  4609. #region 原跳转
  4610. /// <summary>
  4611. /// 确定跳转
  4612. /// </summary>
  4613. /// <param name="sender"></param>
  4614. /// <param name="e"></param>
  4615. private void BtnJumpPage_Click(object sender, RoutedEventArgs e)
  4616. {
  4617. int JumpPage = 0;
  4618. //try
  4619. //{
  4620. // JumpPage = int.Parse(txtJump.Text);
  4621. //}
  4622. //catch (Exception ex)
  4623. //{
  4624. // MessageWindow.Show("操作有误!请输入有效的页码!");
  4625. // return;
  4626. //}
  4627. if (JumpPage < 1)
  4628. {
  4629. JumpPage = 1;
  4630. }
  4631. if (JumpPage > int.Parse(txbTotalpage.Text))
  4632. {
  4633. JumpPage = int.Parse(txbTotalpage.Text);
  4634. }
  4635. #region 跳转
  4636. APP.PageContextData.currpage = JumpPage;
  4637. JumpPageClick();
  4638. #endregion 跳转
  4639. //txbCurrpage.Visibility = Visibility.Visible;
  4640. //txtJump.Visibility = Visibility.Hidden;
  4641. //BtnJumpPage.Visibility = Visibility.Hidden;
  4642. }
  4643. /// <summary>
  4644. /// 只允许输入数字
  4645. /// </summary>
  4646. /// <param name="sender"></param>
  4647. /// <param name="e"></param>
  4648. private void txtJump_PreviewTextInput(object sender, TextCompositionEventArgs e)
  4649. {
  4650. Regex re = new Regex("[^0-9.-]+");
  4651. e.Handled = re.IsMatch(e.Text);
  4652. }
  4653. private void txtJump_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  4654. {
  4655. if (e.Key == Key.Enter)
  4656. {
  4657. BtnJumpPage_Click(null, null);
  4658. }
  4659. }
  4660. #endregion 原跳转
  4661. #region TQL打印
  4662. /// <summary>
  4663. /// 授权文件位置
  4664. /// </summary>
  4665. private string TQLAuthorizationPath;
  4666. /// <summary>
  4667. /// 授权码
  4668. /// </summary>
  4669. private string gKeyStr;
  4670. private TmatrixClass TMC = new TmatrixClass();
  4671. public static string gPrintFileName;
  4672. private bool gbInitDone = false;
  4673. private iTextSharp.text.Document document;
  4674. /// <summary>
  4675. /// TQL初始化打印
  4676. /// </summary>
  4677. private void TQLInit()
  4678. {
  4679. ///初始化
  4680. if (TMC.TmatrixInitialize() == false)
  4681. {
  4682. //MessageBox.Show(this, "点阵码初始化失败!", "生成点阵码", MessageBoxButtons.OK, MessageBoxIcon.Error);
  4683. //Close();
  4684. }
  4685. else
  4686. {
  4687. gbInitDone = true;
  4688. }
  4689. document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0);
  4690. try
  4691. {
  4692. TQLAuthorizationPath = FileToolsCommon.GetFileAbsolutePath("/LatticeXML/S0_O000_B0000_P000-255.tmx");
  4693. StreamReader gsr = new StreamReader(TQLAuthorizationPath);
  4694. gKeyStr = gsr.ReadLine();
  4695. gsr.Close();
  4696. string KeyCheckResult = TMC.TmatrixKeyCheck_OID4(gKeyStr);
  4697. if (KeyCheckResult.Substring(0, 1) == "1")
  4698. {
  4699. MessageWindow.Show("打印服务授权过期,请联系厂家更换授权!");
  4700. LogHelper.WriteErrLog("打印服务授权过期:" + KeyCheckResult, null);
  4701. gbInitDone = false;
  4702. }
  4703. else if (KeyCheckResult.Substring(0, 1) == "0")
  4704. {
  4705. }
  4706. }
  4707. catch (Exception ex)
  4708. {
  4709. LogHelper.WriteErrLog("打印服务授权失败:" + ex.Message, ex);
  4710. MessageWindow.Show("打印服务授权失败,请联系厂家!");
  4711. gbInitDone = false;
  4712. }
  4713. }
  4714. /// <summary>
  4715. /// 铺码
  4716. /// </summary>
  4717. private bool GenerateCode(string PDFPath)
  4718. {
  4719. try
  4720. {
  4721. if (gbInitDone == false)
  4722. {
  4723. MessageWindow.Show("打印功能无法使用,无效授权。");
  4724. return false;
  4725. }
  4726. try
  4727. {
  4728. string directoryPath = FileToolsCommon.GetDirectoryName(PDFPath);
  4729. FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Images/");
  4730. FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Vector Images/");
  4731. FileToolsCommon.DeleteDirectory(directoryPath + "Bg without Vector Images/");
  4732. FileToolsCommon.DeleteDirectory(directoryPath + "Vector Images/");
  4733. }
  4734. catch (Exception)
  4735. {
  4736. }
  4737. PDFPath = PDFPath.Replace("/", "\\");
  4738. //初始页
  4739. bool[] bPublishImageType = new bool[4];
  4740. bPublishImageType[0] = false;
  4741. bPublishImageType[1] = false;
  4742. bPublishImageType[2] = false;
  4743. bPublishImageType[3] = true;
  4744. int[] gPointType = { 0, 0, 0, 0, 1 };
  4745. int[] gPointDPI = { 0, 0, 0, 0, 1 };
  4746. string sGenerateResult = TMC.GenerateTmatrixCode_OID4(
  4747. gKeyStr,
  4748. PDFPath,
  4749. 0,
  4750. gPointType,
  4751. bPublishImageType,
  4752. gPointDPI
  4753. );
  4754. if (sGenerateResult.Substring(0, 1) == "1")
  4755. {
  4756. Dispatcher.Invoke(() =>
  4757. {
  4758. MessageWindow.Show("打印功能无法使用,无效授权。");
  4759. });
  4760. return false;
  4761. }
  4762. return true;
  4763. }
  4764. catch (Exception ex)
  4765. {
  4766. Dispatcher.Invoke(() =>
  4767. {
  4768. MessageWindow.Show("打印失败:" + ex.Message);
  4769. });
  4770. return false;
  4771. }
  4772. }
  4773. #endregion TQL打印
  4774. #region 事件
  4775. private void BtnPrintCloseClick(object sender, RoutedEventArgs e)
  4776. {
  4777. GridPrintingTitle.Visibility = Visibility.Collapsed;
  4778. }
  4779. /// <summary>
  4780. /// 打印
  4781. /// </summary>
  4782. /// <param name="sender"></param>
  4783. /// <param name="e"></param>
  4784. private void BtnPrint_Print_Click(object sender, RoutedEventArgs e)
  4785. {
  4786. if (string.IsNullOrWhiteSpace(cmbClass.Text))
  4787. {
  4788. MessageWindow.Show("请设置打印机!");
  4789. return;
  4790. }
  4791. BtnPrint.IsEnabled = false;
  4792. Thread myThread = new Thread(StartPrint);
  4793. PrintModel printmodel = new PrintModel();
  4794. int ipdf = 102;
  4795. string imgPath = FileToolsCommon.GetFileAbsolutePath("temp/");
  4796. string tempImgPath = imgPath;
  4797. imgPath += "101.pdf";
  4798. while (File.Exists(imgPath))
  4799. {
  4800. imgPath = tempImgPath + ipdf.ToString() + ".pdf";
  4801. ipdf++;
  4802. }
  4803. printmodel.filepath = imgPath;
  4804. //打印数量
  4805. int PrinterNum = 1;
  4806. printmodel.num = PrinterNum;
  4807. //打印机名称
  4808. string PrinterName = cmbClass.Text;
  4809. printmodel.printname = PrinterName;
  4810. PrintMsg = "准备中";
  4811. msgnum = 0;
  4812. num = 0;
  4813. GridPrintMask.Visibility = Visibility.Visible;
  4814. myThread.Start(printmodel);
  4815. timesPrint = new System.Timers.Timer(100);
  4816. timesPrint.Elapsed += Times_ElapsedClick;
  4817. timesPrint.Start();
  4818. timesPrintMsg = new System.Timers.Timer(500);
  4819. timesPrintMsg.Elapsed += TimesPrintMsg_Elapsed;
  4820. timesPrintMsg.Start();
  4821. GridPrintingTitle.Visibility = Visibility.Collapsed;
  4822. }
  4823. /// <summary>
  4824. /// 打印说明
  4825. /// </summary>
  4826. /// <param name="sender"></param>
  4827. /// <param name="e"></param>
  4828. private void btnPrintExplain_Click(object sender, RoutedEventArgs e)
  4829. {
  4830. System.Diagnostics.Process.Start(FileToolsCommon.GetFileAbsolutePath("/星火微课点阵码打印及印刷指导手册.docx"));
  4831. }
  4832. #endregion 事件
  4833. #region 打印界面
  4834. /// <summary>
  4835. /// 下拉框数据源
  4836. /// </summary>
  4837. public DataTable printlist = new DataTable();
  4838. private DataTable dtComponentsUniqueNo;
  4839. /// <summary>
  4840. /// 打印进度
  4841. /// </summary>
  4842. private System.Timers.Timer timesPrint;
  4843. /// <summary>
  4844. /// 打印消息
  4845. /// </summary>
  4846. private System.Timers.Timer timesPrintMsg;
  4847. private double wit = 0;
  4848. private double hei = 0;
  4849. /// <summary>
  4850. /// 打印状态消息
  4851. /// </summary>
  4852. private string PrintMsg = "打印中";
  4853. /// <summary>
  4854. /// 打印初始化
  4855. /// </summary>
  4856. public void InitPrint()
  4857. {
  4858. ResizeMode = ResizeMode.NoResize;
  4859. List<string> defaList = ZPrintUtils.GetLocalPrinters();
  4860. if (defaList.Count > 0)
  4861. {
  4862. printlist.Columns.Add("Value");
  4863. printlist.Columns.Add("Key");
  4864. for (int i = 0; i < defaList.Count; i++)
  4865. {
  4866. //创建一行
  4867. DataRow row = printlist.NewRow();
  4868. //将此行添加到table中
  4869. printlist.Rows.Add(row);
  4870. printlist.Rows[i]["Value"] = defaList[i];
  4871. printlist.Rows[i]["Key"] = i.ToString();
  4872. }
  4873. dtComponentsUniqueNo = printlist.DefaultView.ToTable();
  4874. cmbClass.ItemsSource = dtComponentsUniqueNo.DefaultView;
  4875. cmbClass.SelectedIndex = 0;
  4876. }
  4877. TQLInit();
  4878. }
  4879. /// <summary>
  4880. /// 初始化页面
  4881. /// </summary>
  4882. /// <param name="_imgPath"></param>
  4883. /// <param name="_wit"></param>
  4884. /// <param name="_hei"></param>
  4885. public void InitializePrint(string _imgPath, double _wit, double _hei)
  4886. {
  4887. wit = _wit;
  4888. hei = _hei;
  4889. if (!string.IsNullOrWhiteSpace(_imgPath))
  4890. {
  4891. imgPri.Source = new BitmapImage(new Uri(_imgPath));
  4892. }
  4893. else
  4894. {
  4895. imgPri.Source = null;
  4896. }
  4897. GridPrintMask.Visibility = Visibility.Collapsed;
  4898. }
  4899. private int msgnum = 0;
  4900. /// <summary>
  4901. /// 消息
  4902. /// </summary>
  4903. /// <param name="sender"></param>
  4904. /// <param name="e"></param>
  4905. private void TimesPrintMsg_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  4906. {
  4907. if (msgnum > 5)
  4908. msgnum = 0;
  4909. else
  4910. msgnum++;
  4911. string point = "";
  4912. point = point.ToString().PadRight(msgnum, '.');
  4913. Dispatcher.Invoke(() =>
  4914. {
  4915. LabPrintMessage.Content = PrintMsg + point;
  4916. });
  4917. }
  4918. private int num = 0;
  4919. /// <summary>
  4920. /// 计时器
  4921. /// </summary>
  4922. /// <param name="sender"></param>
  4923. /// <param name="e"></param>
  4924. private void Times_ElapsedClick(object sender, System.Timers.ElapsedEventArgs e)
  4925. {
  4926. Dispatcher.Invoke(() =>
  4927. {
  4928. pgbProcess.Value = num;
  4929. lbProcess.Content = num.ToString() + "%";
  4930. if (num < 99)
  4931. {
  4932. num++;
  4933. timesPrint.Interval += (num / 2);
  4934. }
  4935. else
  4936. {
  4937. timesPrint.Stop();
  4938. }
  4939. });
  4940. }
  4941. /// <summary>
  4942. /// 开始打印
  4943. /// </summary>
  4944. private void StartPrint(object obj)
  4945. {
  4946. PrintModel printModel = (PrintModel)obj;
  4947. try
  4948. {
  4949. document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0f, 0f, 0f, 0f);
  4950. PrintMsg = "生成文件";
  4951. msgnum = 0;
  4952. string SourcePath1 = printModel.filepath;
  4953. try
  4954. {
  4955. SourcePath1 = SourcePath1.Replace("/", "\\");
  4956. FileStream fs = new FileStream(SourcePath1, FileMode.Create, FileAccess.ReadWrite);
  4957. document.AddAuthor("星火微课");//作者
  4958. document.AddCreationDate();//创建时候
  4959. document.AddCreator("星火微课");//创建者
  4960. document.AddSubject("点阵文件");//主题
  4961. document.AddTitle("PrintTmatrixCode");//标题
  4962. document.AddKeywords("Print");
  4963. document.AddHeader("TmatrixCode", "0");
  4964. iTextSharp.text.pdf.PdfWriter.GetInstance(document, fs);
  4965. }
  4966. catch (Exception)
  4967. {
  4968. }
  4969. document.Open();
  4970. iTextSharp.text.Image image;
  4971. for (int i = 0; i < APP.PageDrawList.Count; i++)
  4972. {
  4973. long ii = Timestamp();
  4974. string directoryPath = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  4975. string filePathOutPut = Path.Combine(directoryPath, string.Format("print{0}{1}.jpg", ii, i));
  4976. RectangleF rectangleFs = new RectangleF();
  4977. MergerPrintImg("", filePathOutPut, rectangleFs, out string errmsg);
  4978. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  4979. if (string.IsNullOrEmpty(APP.PageDrawList[i].PageImagePath))//没有图片
  4980. {
  4981. }
  4982. else if (APP.PageDrawList[i].ImgDocumentation == true && !APP.PageDrawList[i].Type.Equals("ppt"))
  4983. {
  4984. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  4985. }
  4986. else
  4987. {
  4988. RectangleF rectangleF = new RectangleF(0, 0, 0, 0);
  4989. Dispatcher.Invoke(() =>
  4990. {
  4991. rectangleF = new RectangleF
  4992. {
  4993. Width = (float)APP.PageDrawList[i].ImageSizes.CenterX,
  4994. Height = (float)APP.PageDrawList[i].ImageSizes.CenterY,
  4995. X = (float)APP.PageDrawList[i].ImageLocation.X,
  4996. Y = (float)APP.PageDrawList[i].ImageLocation.Y
  4997. };
  4998. });
  4999. string msgs = string.Empty;
  5000. bool isImg = MergerPrintImg(APP.PageDrawList[i].PageImagePath, filePathOutPut, rectangleF, out msgs);
  5001. if (isImg)
  5002. {
  5003. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  5004. }
  5005. else
  5006. {
  5007. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  5008. }
  5009. }
  5010. if (image.Height > iTextSharp.text.PageSize.A4.Height)
  5011. {
  5012. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  5013. }
  5014. else if (image.Width > iTextSharp.text.PageSize.A4.Width)
  5015. {
  5016. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  5017. }
  5018. image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
  5019. document.NewPage();
  5020. document.Add(image);
  5021. }
  5022. document.Close();
  5023. }
  5024. catch (Exception ex)
  5025. {
  5026. Dispatcher.Invoke(() =>
  5027. {
  5028. BtnPrint.IsEnabled = true;
  5029. timesPrint.Stop();
  5030. timesPrintMsg.Stop();
  5031. GridPrintMask.Visibility = Visibility.Collapsed;
  5032. MessageWindow.Show(ex.Message);
  5033. return;
  5034. });
  5035. LogHelper.WriteErrLog("打印转换PDF失败,原因:" + ex.Message, ex);
  5036. }
  5037. //PDF位置
  5038. string SourcePath = printModel.filepath;
  5039. int PrinterNum = printModel.num;
  5040. string PrinterName = printModel.printname;
  5041. PrintMsg = "铺码中";
  5042. msgnum = 0;
  5043. Thread.Sleep(500);
  5044. //腾千里生成点阵文件
  5045. if (GenerateCode(SourcePath))
  5046. {
  5047. //打印机名称
  5048. string directoryPath = FileToolsCommon.GetDirectoryName(SourcePath) + "Bg with Images/";
  5049. string[] strs = FileToolsCommon.GetFileNames(directoryPath);
  5050. try
  5051. {
  5052. // 腾千里会根据原PDF的页数生成多个PDF文件
  5053. for (int i = 0; i < strs.Count(); i++)
  5054. {
  5055. timesPrint.Stop();
  5056. PrintMsg = "正在打印第" + (i + 1) + "/" + strs.Count() + "页中";
  5057. msgnum = 0;
  5058. num = 0;
  5059. timesPrint.Interval = 100;
  5060. timesPrint.Start();
  5061. string fileName = strs[i];
  5062. //打印文件
  5063. ZPrintUtils.Print(fileName, PrinterName);
  5064. }
  5065. Dispatcher.Invoke(() =>
  5066. {
  5067. BtnPrint.IsEnabled = true;
  5068. num = 99;
  5069. timesPrint.Stop();
  5070. pgbProcess.Value = 100;
  5071. lbProcess.Content = "100%";
  5072. GridPrintMask.Visibility = Visibility.Collapsed;
  5073. //MessageWindow.Show("已加入打印机队列,打印中。");
  5074. });
  5075. }
  5076. catch (Exception ex)
  5077. {
  5078. Dispatcher.Invoke(() =>
  5079. {
  5080. MessageWindow.Show("打印失败:" + ex.Message);
  5081. BtnPrint.IsEnabled = true;
  5082. timesPrint.Stop();
  5083. GridPrintMask.Visibility = Visibility.Collapsed;
  5084. return;
  5085. });
  5086. }
  5087. }
  5088. else
  5089. {
  5090. Dispatcher.Invoke(() =>
  5091. {
  5092. BtnPrint.IsEnabled = true;
  5093. timesPrint.Stop();
  5094. timesPrintMsg.Stop();
  5095. GridPrintMask.Visibility = Visibility.Collapsed;
  5096. return;
  5097. });
  5098. }
  5099. #region 拓思德生成点阵文件
  5100. ////TPF文件位置
  5101. //string TPFPath = FileToolsCommon.GetFileAbsolutePath("temp/");
  5102. //FileToolsCommon.CreateDirectory(TPFPath);
  5103. //TPFPath += "101.TPF";
  5104. ////生成点阵文件
  5105. //LatticeFileHelper.GeneratingPDF(SourcePath, TPFPath, out int pr, out string msg, out string outPut/*, pyte*/);
  5106. //while (!FileToolsCommon.IsExistFile(TPFPath))
  5107. //{
  5108. // Thread.Sleep(100);
  5109. //}
  5110. //while (string.IsNullOrWhiteSpace(pr.ToString()))
  5111. //{
  5112. // Thread.Sleep(100);
  5113. //}
  5114. //Thread.Sleep(1000);
  5115. #endregion 拓思德生成点阵文件
  5116. #region 拓思德打印
  5117. ////打印
  5118. //LatticeFileHelper.PrinterTPFFile(TPFPath, PrinterNum, PrinterName, out int printResult, out string standardError, out string standardOutput);
  5119. //if (printResult == 0)
  5120. //{
  5121. // Dispatcher.Invoke(() =>
  5122. // {
  5123. // btnClose.IsEnabled = true;
  5124. // btnPrint.IsEnabled = true;
  5125. // num = 99;
  5126. // timesPrint.Stop();
  5127. // pgbProcess.Value = 100;
  5128. // lbProcess.Content = "100%";
  5129. // MessageWindow.Show("打印成功!");
  5130. // GridPrintMask.Visibility = Visibility.Collapsed;
  5131. // });
  5132. //}
  5133. //else
  5134. //{
  5135. // Dispatcher.Invoke(() =>
  5136. // {
  5137. // btnClose.IsEnabled = true;
  5138. // btnPrint.IsEnabled = true;
  5139. // timesPrint.Stop();
  5140. // GridPrintMask.Visibility = Visibility.Collapsed;
  5141. // MessageWindow.Show(standardError);
  5142. // });
  5143. //}
  5144. #endregion 拓思德打印
  5145. }
  5146. /// <summary>
  5147. /// 生成图片
  5148. /// </summary>
  5149. /// <param name="_path">图片地址</param>
  5150. /// <param name="_saveimg">保存位置</param>
  5151. /// <param name="_rectangle">图片位置</param>
  5152. /// <param name="errmsg">错误消息</param>
  5153. /// <returns></returns>
  5154. private bool MergerPrintImg(string _path, string _saveimg, RectangleF _rectangle, out string errmsg)
  5155. {
  5156. errmsg = null;
  5157. try
  5158. {
  5159. Bitmap bitmap = null;
  5160. //创建要显示的图片对象,根据参数的个数设置宽度
  5161. Bitmap backgroudImg = new Bitmap((int)/*GridM.ActualWidth*/wit, (int)/*GridM.ActualHeight*/hei);
  5162. Graphics g = Graphics.FromImage(backgroudImg);
  5163. //清除画布,背景设置为白色
  5164. g.Clear(System.Drawing.Color.White);
  5165. if (!string.IsNullOrWhiteSpace(_path))
  5166. {
  5167. bitmap = ImageHelper.ReadBitmapFile(_path);
  5168. g.DrawImage(bitmap, _rectangle);
  5169. }
  5170. #region 添加箭头
  5171. string Str = "↑";
  5172. SolidBrush mybrush = new SolidBrush(System.Drawing.Color.Black); //设置默认画刷颜色
  5173. System.Drawing.Font myfont = new System.Drawing.Font("黑体", 14); //设置默认字体格式
  5174. g.DrawString(Str, myfont, mybrush, new System.Drawing.Rectangle((int)wit - 50, 20, 50, 50));
  5175. #endregion 添加箭头
  5176. backgroudImg.Save(_saveimg);
  5177. g.Dispose();
  5178. backgroudImg.Dispose();
  5179. if (bitmap != null)
  5180. {
  5181. bitmap.Dispose();
  5182. }
  5183. GC.Collect();
  5184. return true;
  5185. }
  5186. catch (Exception ex)
  5187. {
  5188. errmsg = ex.Message;
  5189. LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
  5190. return false;
  5191. }
  5192. }
  5193. #endregion 打印界面
  5194. }
  5195. public class PageData
  5196. {
  5197. public int PageCode { get; set; }
  5198. public string PageName { get; set; }
  5199. }
  5200. }