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

XHMicroLessonSystemWindow.xaml.cs 299KB

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