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

XHMicroLessonSystemWindow.xaml.cs 229KB

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