星火微课系统客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

XHMicroLessonSystemWindow.xaml.cs 250KB

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