星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

XHMicroLessonSystemWindow.xaml.cs 249KB

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