星火微课系统客户端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

XHMicroLessonSystemWindow.xaml.cs 225KB

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