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

XHMicroLessonSystemWindow.xaml.cs 256KB

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