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

XHMicroLessonSystemWindow.xaml.cs 229KB

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