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

XHMicroLessonSystemWindow.xaml.cs 263KB

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