星火微课系统客户端
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 219KB

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