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

XHMicroLessonSystemWindow.xaml.cs 225KB

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