星火微课系统客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

XHMicroLessonSystemWindow.xaml.cs 172KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452
  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 System;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Text.RegularExpressions;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. using System.Windows;
  17. using System.Windows.Controls;
  18. using System.Windows.Controls.Primitives;
  19. using System.Windows.Ink;
  20. using System.Windows.Input;
  21. using System.Windows.Media;
  22. using System.Windows.Media.Imaging;
  23. using System.Windows.Threading;
  24. using TmatrixLibrary;
  25. using XHWK.Model;
  26. using XHWK.WKTool.Models;
  27. using XHWK.WKTool.Skin;
  28. using XHWK.WKTool.UControl;
  29. using XHWK.WKTool.Utils;
  30. using XHWK.WKTool.Utils.luobo;
  31. using XHWK.WKTool.Utils.pen;
  32. namespace XHWK.WKTool
  33. {
  34. /// <summary>
  35. /// 主页面
  36. /// </summary>
  37. public partial class XHMicroLessonSystemWindow : Window, PenEventI
  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 System.Windows.Media.Color Color = Colors.Red;
  62. /// <summary>
  63. /// 笔迹粗细
  64. /// </summary>
  65. private int PenSize = 2;
  66. //private DispatcherTimer t = null;
  67. /// <summary>
  68. /// 计时器状态
  69. /// </summary>
  70. private enum State
  71. {
  72. Start,
  73. Pause,
  74. End
  75. }
  76. #region 上传
  77. /// <summary>
  78. /// 视频模型
  79. /// </summary>
  80. private List<Model_Video> model_VideoList = null;
  81. /// <summary>
  82. /// 数据列表
  83. /// </summary>
  84. internal FileDirectoryData pageData = new FileDirectoryData();
  85. #endregion 上传
  86. /// <summary>
  87. /// 键盘钩子
  88. /// </summary>
  89. private KeyboardHookCommon k_hook;
  90. #endregion 字段
  91. #region 初始化
  92. /// <summary>
  93. /// 引用user32.dll动态链接库(windows api), 使用库中定义 API:SetCursorPos 设置光标位置
  94. /// </summary>
  95. [System.Runtime.InteropServices.DllImport("user32.dll")]
  96. private static extern int SetCursorPos(int x, int y);
  97. private LuoBoPenUtil luoBoPenUtil;
  98. private ImageOperationUtil imageOperationUtil;
  99. /// <summary>
  100. /// 主页面
  101. /// </summary>
  102. public XHMicroLessonSystemWindow()
  103. {
  104. InitializeComponent();
  105. #region 调整文字大小
  106. APP.PageContextData.WordSize20 = 20.00;
  107. APP.PageContextData.WordSize18 = 18.00;
  108. APP.PageContextData.WordSize16 = 16.00;
  109. APP.PageContextData.WordSize14 = 14.00;
  110. APP.PageContextData.WordSize12 = 12.00;
  111. #endregion 调整文字大小
  112. ResizeMode = ResizeMode.CanMinimize;
  113. BtnPrint.IsEnabled = false;
  114. myblackboard = new BlackboardNew(blackboard_canvas);
  115. APP.PageContextData.pagenum = 0;
  116. APP.PageContextData.currpage = 0;
  117. DataContext = APP.PageContextData;
  118. //APP.SaveDraw();//画板模型第一页初始化
  119. APP.PageDrawList = new List<Model_DrawData>();
  120. Model_DrawData model_DrawData = new Model_DrawData
  121. {
  122. PageNum = APP.PageContextData.currpage
  123. };
  124. APP.PageDrawList.Add(model_DrawData);
  125. txbv.Text = "v" + FileToolsCommon.GetConfigValue("VersionName");
  126. txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoType");
  127. txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoSavePath");
  128. Initialize();
  129. //罗博手写板
  130. luoBoPenUtil = new LuoBoPenUtil(this);
  131. luoBoPenUtil.InitlbPen();
  132. //腾千里
  133. InitTQLPPen();
  134. InitPrint();
  135. SkinSelectInit();
  136. byte[] license = Convert.FromBase64String("PExpY2Vuc2U+CiAgPERhdGE+CiAgICA8TGljZW5zZWRUbz5TdXpob3UgQXVuYm94IFNvZnR3YXJlIENvLiwgTHRkLjwvTGljZW5zZWRUbz4KICAgIDxFbWFpbFRvPnNhbGVzQGF1bnRlYy5jb208L0VtYWlsVG8+CiAgICA8TGljZW5zZVR5cGU+RGV2ZWxvcGVyIE9FTTwvTGljZW5zZVR5cGU+CiAgICA8TGljZW5zZU5vdGU+TGltaXRlZCB0byAxIGRldmVsb3BlciwgdW5saW1pdGVkIHBoeXNpY2FsIGxvY2F0aW9uczwvTGljZW5zZU5vdGU+CiAgICA8T3JkZXJJRD4xOTA4MjYwODA3NTM8L09yZGVySUQ+CiAgICA8VXNlcklEPjEzNDk3NjAwNjwvVXNlcklEPgogICAgPE9FTT5UaGlzIGlzIGEgcmVkaXN0cmlidXRhYmxlIGxpY2Vuc2U8L09FTT4KICAgIDxQcm9kdWN0cz4KICAgICAgPFByb2R1Y3Q+QXNwb3NlLlRvdGFsIGZvciAuTkVUPC9Qcm9kdWN0PgogICAgPC9Qcm9kdWN0cz4KICAgIDxFZGl0aW9uVHlwZT5FbnRlcnByaXNlPC9FZGl0aW9uVHlwZT4KICAgIDxTZXJpYWxOdW1iZXI+M2U0NGRlMzAtZmNkMi00MTA2LWIzNWQtNDZjNmEzNzE1ZmMyPC9TZXJpYWxOdW1iZXI+CiAgICA8U3Vic2NyaXB0aW9uRXhwaXJ5PjIwMjAwODI3PC9TdWJzY3JpcHRpb25FeHBpcnk+CiAgICA8TGljZW5zZVZlcnNpb24+My4wPC9MaWNlbnNlVmVyc2lvbj4KICAgIDxMaWNlbnNlSW5zdHJ1Y3Rpb25zPmh0dHBzOi8vcHVyY2hhc2UuYXNwb3NlLmNvbS9wb2xpY2llcy91c2UtbGljZW5zZTwvTGljZW5zZUluc3RydWN0aW9ucz4KICA8L0RhdGE+CiAgPFNpZ25hdHVyZT53UGJtNUt3ZTYvRFZXWFNIY1o4d2FiVEFQQXlSR0pEOGI3L00zVkV4YWZpQnd5U2h3YWtrNGI5N2c2eGtnTjhtbUFGY3J0c0cwd1ZDcnp6MytVYk9iQjRYUndTZWxsTFdXeXNDL0haTDNpN01SMC9jZUFxaVZFOU0rWndOQkR4RnlRbE9uYTFQajhQMzhzR1grQ3ZsemJLZFZPZXk1S3A2dDN5c0dqYWtaL1E9PC9TaWduYXR1cmU+CjwvTGljZW5zZT4=");
  137. new Aspose.Words.License().SetLicense(new MemoryStream(license));
  138. new Aspose.Pdf.License().SetLicense(new MemoryStream(license));
  139. new Aspose.Slides.License().SetLicense(new MemoryStream(license));
  140. imageOperationUtil = new ImageOperationUtil(
  141. RectLeftUp,
  142. RectRightUp,
  143. RectLeftDown,
  144. RectRightDown,
  145. RectImgBorder,
  146. imgCanvas,
  147. GridM
  148. );
  149. }
  150. /// <summary>
  151. /// 初始化
  152. /// </summary>
  153. public void Initialize()
  154. {
  155. if (APP.isDebug)
  156. {
  157. txbVersion.Text = "测试版:";
  158. }
  159. else
  160. {
  161. txbVersion.Text = "正式版:";
  162. }
  163. #region 数据初始化
  164. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  165. FileToolsCommon.CreateDirectory(pathTemp);
  166. APP.PageContextData.pagenum = 0;
  167. APP.PageContextData.currpage = APP.PageContextData.pagenum;
  168. BtnStop.IsEnabled = false;//停止录制按钮不可点击
  169. #endregion 数据初始化
  170. k_hook = new KeyboardHookCommon();
  171. k_hook.KeyDownEvent += K_hook_KeyDownEvent;
  172. k_hook.Start();//安装键盘钩子
  173. APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  174. //创建 DrawingAttributes 类的一个实例
  175. drawingAttributes = new DrawingAttributes();
  176. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  177. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  178. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  179. blackboard_canvas.UseCustomCursor = true;
  180. drawingAttributes.FitToCurve = true;
  181. drawingAttributes.IgnorePressure = false;
  182. drawingAttributes.Width = PenSize;
  183. drawingAttributes.Height = PenSize;
  184. drawingAttributes.Color = Color;
  185. blackboard_canvas.Cursor = Cursors.Pen;
  186. }
  187. /// <summary>
  188. /// 初始化快捷键
  189. /// </summary>
  190. public void InitializeKeyDownEvent()
  191. {
  192. k_hook.Start();//安装键盘钩子
  193. }
  194. /// <summary>
  195. /// 快捷键
  196. /// </summary>
  197. /// <param name="sender">
  198. /// </param>
  199. /// <param name="e">
  200. /// </param>
  201. private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
  202. {
  203. if (e.KeyValue == (int)System.Windows.Forms.Keys.Left)
  204. {
  205. if (APP.PageContextData.currpage > 1)
  206. {
  207. //上一页
  208. last_button_Click(null, null);
  209. }
  210. }
  211. if (e.KeyValue == (int)System.Windows.Forms.Keys.Right)
  212. {
  213. if (APP.PageContextData.currpage < APP.PageContextData.pagenum)
  214. {
  215. //下一页
  216. next_btn_Click(null, null);
  217. }
  218. }
  219. if (e.KeyValue == (int)System.Windows.Forms.Keys.Delete)
  220. {
  221. if (RectImgBorder.Visibility != Visibility.Hidden)
  222. {
  223. HideAngleBorder();
  224. imgCanvas.Source = null;
  225. APP.PageDrawList[APP.PageContextData.currpage - 1].PdfImagePath = null;
  226. APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath = null;
  227. }
  228. }
  229. }
  230. /// <summary>
  231. /// 加载完成后调整录制区域大小
  232. /// </summary>
  233. /// <param name="sender">
  234. /// </param>
  235. /// <param name="e">
  236. /// </param>
  237. private void Window_Loaded(object sender, RoutedEventArgs e)
  238. {
  239. //调整录制区域宽高
  240. double proportion = 210.0 / 297.0;
  241. GridM.Height = GridM.ActualWidth / proportion;
  242. }
  243. #endregion 初始化
  244. #region 事件
  245. #region 登录
  246. /// <summary>
  247. /// 登录事件
  248. /// </summary>
  249. /// <param name="sender">
  250. /// </param>
  251. /// <param name="e">
  252. /// </param>
  253. private void BtnLoginType_Click(object sender, RoutedEventArgs e)
  254. {
  255. if ("未登录".Equals(TxbLoginType.Text) || ImgHeadImgN.Visibility == Visibility.Visible)
  256. {
  257. Login();
  258. }
  259. else
  260. {
  261. MessageBoxResult dr = MessageWindow.Show("确定退出登录?", "提示", MessageBoxButton.OKCancel);
  262. if (dr == MessageBoxResult.OK)
  263. {
  264. LoginType();
  265. Login();
  266. }
  267. }
  268. }
  269. /// <summary>
  270. /// 登录
  271. /// </summary>
  272. private void Login()
  273. {
  274. if (APP.W_LoginWindow == null)
  275. {
  276. APP.W_LoginWindow = new LoginWindow
  277. {
  278. WindowStartupLocation = WindowStartupLocation.CenterOwner,
  279. Owner = this
  280. };
  281. }
  282. else
  283. {
  284. APP.W_LoginWindow.Initialize();
  285. }
  286. APP.W_LoginWindow.ShowDialog();
  287. if (APP.IsLoginType)
  288. {
  289. string HeadpicPath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + ".png");
  290. if (FileToolsCommon.IsExistFile(HeadpicPath))
  291. {
  292. ImgHead.ImageSource = new BitmapImage(new Uri(HeadpicPath));
  293. }
  294. else
  295. {
  296. ImgHead.ImageSource = new BitmapImage(new Uri("pack://application:,,,/BlackImages/HM_HeadImg.png"));
  297. }
  298. TxbLoginType.Text = APP.UserInfo.Username;
  299. ImgHeadImgN.Visibility = Visibility.Collapsed;
  300. ImgHeadImg.Visibility = Visibility.Visible;
  301. }
  302. else
  303. {
  304. TxbLoginType.Text = "未登录";
  305. ImgHeadImgN.Visibility = Visibility.Visible;
  306. ImgHeadImg.Visibility = Visibility.Collapsed;
  307. }
  308. }
  309. /// <summary>
  310. /// 状态更改为未登录
  311. /// </summary>
  312. private void LoginType()
  313. {
  314. APP.IsLoginType = false;
  315. TxbLoginType.Text = "未登录";
  316. ImgHeadImgN.Visibility = Visibility.Visible;
  317. ImgHeadImg.Visibility = Visibility.Collapsed;
  318. APP.UserInfo = new Model_UserInfo();
  319. //ImgUpload.Visibility = Visibility.Collapsed;
  320. //ImgUploadTwo.Visibility = Visibility.Visible;
  321. }
  322. #endregion 登录
  323. #region 设置
  324. /// <summary>
  325. /// 设置事件
  326. /// </summary>
  327. /// <param name="sender">
  328. /// </param>
  329. /// <param name="e">
  330. /// </param>
  331. private void BtnSetUp_Click(object sender, RoutedEventArgs e)
  332. {
  333. if (gridSetUp.Visibility == Visibility.Collapsed)
  334. {
  335. PageHide();
  336. gridSetUp.Visibility = Visibility.Visible;
  337. txbStoragePath.Content = APP.WKData.WkPath;
  338. #region 读取用户配置
  339. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  340. if ("1".Equals(APP.CameraPosition))
  341. {
  342. rbnRight.IsChecked = true;
  343. }
  344. else if ("2".Equals(APP.CameraPosition))
  345. {
  346. rbnLeft.IsChecked = true;
  347. }
  348. else if ("3".Equals(APP.CameraPosition))
  349. {
  350. rbnRightUnder.IsChecked = true;
  351. }
  352. else if ("4".Equals(APP.CameraPosition))
  353. {
  354. rbnLeftUnder.IsChecked = true;
  355. }
  356. string type = FileToolsCommon.GetConfigValue("VideoType");//<!--视频格式 1、MP4 2、FlV 3、AVI-->
  357. if ("1".Equals(type))
  358. {
  359. rbnMP4.IsChecked = true;
  360. }
  361. else if ("2".Equals(type))
  362. {
  363. rbnFLV.IsChecked = true;
  364. }
  365. else if ("3".Equals(type))
  366. {
  367. rbnAVI.IsChecked = true;
  368. }
  369. string isHide = FileToolsCommon.GetConfigValue("IsHideSRTool"); //工具栏是否隐藏
  370. if (isHide.Equals("1"))
  371. {
  372. rbnHide.IsChecked = true;
  373. }
  374. else
  375. {
  376. rbnvisi.IsChecked = true;
  377. }
  378. //string isSound = FileToolsCommon.GetConfigValue("IsSound");//<!--声音 true 有 false 无-->
  379. //if (isSound == "true")
  380. //{
  381. // rbnY.IsChecked = true;
  382. //}
  383. //else
  384. //{
  385. // rbnN.IsChecked = true;
  386. //}
  387. //加载皮肤按钮
  388. SkinSelectInit();
  389. #endregion 读取用户配置
  390. }
  391. else
  392. {
  393. GridMain.Visibility = Visibility.Visible;
  394. GridM.IsEnabled = true;
  395. GridRecordingTitle.Visibility = Visibility.Visible;
  396. gridSetUp.Visibility = Visibility.Collapsed;
  397. }
  398. }
  399. /// <summary>
  400. /// 设置 保存事件
  401. /// </summary>
  402. /// <param name="sender">
  403. /// </param>
  404. /// <param name="e">
  405. /// </param>
  406. private void BtnSave_Click(object sender, RoutedEventArgs e)
  407. {
  408. try
  409. {
  410. BtnRecord.IsEnabled = true;//设置结束时可录制
  411. if (rbnMP4.IsChecked == true)
  412. {
  413. //存储文件
  414. FileToolsCommon.SetConfigValue("VideoType", "1");
  415. }
  416. else if (rbnFLV.IsChecked == true)
  417. {
  418. FileToolsCommon.SetConfigValue("VideoType", "2");
  419. }
  420. else
  421. {
  422. FileToolsCommon.SetConfigValue("VideoType", "3");
  423. }
  424. UpdateHideSRToolConfig();
  425. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  426. if (rbnRight.IsChecked == true)
  427. {
  428. FileToolsCommon.SetConfigValue("CameraPosition", "1");
  429. }
  430. else if (rbnLeft.IsChecked == true)
  431. {
  432. FileToolsCommon.SetConfigValue("CameraPosition", "2");
  433. }
  434. else if (rbnRightUnder.IsChecked == true)
  435. {
  436. FileToolsCommon.SetConfigValue("CameraPosition", "3");
  437. }
  438. else if (rbnLeftUnder.IsChecked == true)
  439. {
  440. FileToolsCommon.SetConfigValue("CameraPosition", "4");
  441. }
  442. //格式
  443. if (rbnMP4.IsChecked == true)
  444. {
  445. FileToolsCommon.SetConfigValue("VideoType", "1");
  446. }
  447. else if (rbnFLV.IsChecked == true)
  448. {
  449. FileToolsCommon.SetConfigValue("VideoType", "2");
  450. }
  451. else if (rbnAVI.IsChecked == true)
  452. {
  453. FileToolsCommon.SetConfigValue("VideoType", "3");
  454. }
  455. APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  456. GridMain.Visibility = Visibility.Visible;
  457. GridM.IsEnabled = true;
  458. GridRecordingTitle.Visibility = Visibility.Visible;
  459. gridSetUp.Visibility = Visibility.Collapsed;
  460. imgPlayerRight.Visibility = Visibility.Collapsed;
  461. imgPlayerLeft.Visibility = Visibility.Collapsed;
  462. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  463. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  464. if (!txbStoragePath.Content.ToString().Equals(APP.WKData.WkPath))
  465. {
  466. //存储文件
  467. FileToolsCommon.SetConfigValue("VideoSavePath", txbStoragePath.Content.ToString());
  468. MessageWindow.Show("路径已变更,下次创建微课时自动生效。");
  469. }
  470. }
  471. catch (Exception ex)
  472. {
  473. LogHelper.WriteErrLog("XHMicroLessonSystemWindow(设置保存事件报错:)" + ex.Message, ex);
  474. }
  475. }
  476. /// <summary>
  477. /// 设置 浏览事件
  478. /// </summary>
  479. /// <param name="sender">
  480. /// </param>
  481. /// <param name="e">
  482. /// </param>
  483. private void BtnBrowse_Click(object sender, RoutedEventArgs e)
  484. {
  485. //System.Diagnostics.Process.Start(APP.WKData.WkPath);
  486. //string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  487. Ofd = new System.Windows.Forms.FolderBrowserDialog();
  488. Result = Ofd.ShowDialog();
  489. if (Result == System.Windows.Forms.DialogResult.OK)
  490. {
  491. if (Ofd.SelectedPath != "")
  492. {
  493. txbStoragePath.Content = Ofd.SelectedPath;
  494. //string ApplicationData = ZConfig.dataPath + "fileStorageAddress.txt";
  495. //string temp = ofd.SelectedPath;
  496. //System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  497. }
  498. }
  499. }
  500. /// <summary>
  501. /// 打开文件所在位置
  502. /// </summary>
  503. /// <param name="sender">
  504. /// </param>
  505. /// <param name="e">
  506. /// </param>
  507. private void btnOpen_Click(object sender, RoutedEventArgs e)
  508. {
  509. System.Diagnostics.Process.Start(APP.WKData.WkPath);
  510. }
  511. /// <summary>
  512. /// 更新隐藏录屏工具栏隐藏状态
  513. /// </summary>
  514. private void UpdateHideSRToolConfig()
  515. {
  516. if (rbnHide.IsChecked == true)
  517. {
  518. //隐藏
  519. FileToolsCommon.SetConfigValue("IsHideSRTool", "1");
  520. APP.IsHideSRTool = true;
  521. }
  522. else
  523. {
  524. //显示
  525. FileToolsCommon.SetConfigValue("IsHideSRTool", "0");
  526. APP.IsHideSRTool = false;
  527. }
  528. }
  529. #region 切换皮肤
  530. /// <summary>
  531. /// 加载皮肤选项
  532. /// </summary>
  533. private void SkinSelectInit()
  534. {
  535. if (APP.SkinStyle == "0")
  536. {
  537. HideSkinSelect();
  538. SkinSelectWhite.Visibility = Visibility.Visible;
  539. SkinConfig.SwitchSkin(0);
  540. }
  541. else if (APP.SkinStyle == "1")
  542. {
  543. HideSkinSelect();
  544. SkinSelectTechnologyBlue.Visibility = Visibility.Visible;
  545. SkinConfig.SwitchSkin(1);
  546. }
  547. else
  548. {
  549. HideSkinSelect();
  550. SkinSelectWhite.Visibility = Visibility.Visible;
  551. }
  552. }
  553. /// <summary>
  554. /// 白色
  555. /// </summary>
  556. /// <param name="sender">
  557. /// </param>
  558. /// <param name="e">
  559. /// </param>
  560. private void BtnSkinWhite_Click(object sender, RoutedEventArgs e)
  561. {
  562. if (APP.SkinStyle != "0")
  563. {
  564. HideSkinSelect();
  565. SkinSelectWhite.Visibility = Visibility.Visible;
  566. APP.SkinStyle = "0";
  567. FileToolsCommon.SetConfigValue("SkinStyle", "0");
  568. SkinConfig.SwitchSkin(0);
  569. }
  570. }
  571. /// <summary>
  572. /// 科技蓝
  573. /// </summary>
  574. /// <param name="sender">
  575. /// </param>
  576. /// <param name="e">
  577. /// </param>
  578. private void BtnSkinTechnologyBlue_Click(object sender, RoutedEventArgs e)
  579. {
  580. if (APP.SkinStyle != "1")
  581. {
  582. HideSkinSelect();
  583. SkinSelectTechnologyBlue.Visibility = Visibility.Visible;
  584. APP.SkinStyle = "1";
  585. FileToolsCommon.SetConfigValue("SkinStyle", "1");
  586. SkinConfig.SwitchSkin(1);
  587. }
  588. }
  589. /// <summary>
  590. /// 隐藏皮肤选择键
  591. /// </summary>
  592. private void HideSkinSelect()
  593. {
  594. SkinSelectWhite.Visibility = Visibility.Hidden;
  595. SkinSelectTechnologyBlue.Visibility = Visibility.Hidden;
  596. }
  597. #endregion 切换皮肤
  598. #endregion 设置
  599. /// <summary>
  600. /// 窗体移动
  601. /// </summary>
  602. /// <param name="sender">
  603. /// </param>
  604. /// <param name="e">
  605. /// </param>
  606. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  607. {
  608. DragMove();
  609. }
  610. private void PageHide()
  611. {
  612. //设置
  613. gridSetUp.Visibility = Visibility.Collapsed;
  614. //我的
  615. GridMyVideo.Visibility = Visibility.Collapsed;
  616. //首页
  617. GridMain.Visibility = Visibility.Collapsed;
  618. GridM.IsEnabled = true;
  619. //打印
  620. GridPrintContent.Visibility = Visibility.Collapsed;
  621. //标题 录制
  622. GridRecordingTitle.Visibility = Visibility.Collapsed;
  623. //标题 打印
  624. GridPrintingTitle.Visibility = Visibility.Collapsed;
  625. }
  626. #region 摄像头
  627. private System.Timers.Timer times;
  628. private List<string> RbnOpen;
  629. private bool IsRbnOpen = false;
  630. /// <summary>
  631. /// 摄像头打开事件
  632. /// </summary>
  633. /// <param name="sender">
  634. /// </param>
  635. /// <param name="e">
  636. /// </param>
  637. private void RbnOpen_Click(object sender, RoutedEventArgs e)
  638. {
  639. if (!IsRbnOpen)
  640. {
  641. #region 防止连击
  642. if (IsPressButton)
  643. {
  644. return;
  645. }
  646. else
  647. {
  648. IsPressButton = true;
  649. new Thread(new ThreadStart(new Action(() =>
  650. {
  651. //Dispatcher.Invoke(new Action(() => { rbnTurnOff.IsEnabled = false; }));
  652. Thread.Sleep(500);
  653. //Dispatcher.Invoke(new Action(() => { rbnTurnOff.IsEnabled = true; }));
  654. IsPressButton = false;
  655. }))).Start();
  656. }
  657. #endregion 防止连击
  658. CameraHelper.UpdateCameraDevices();
  659. if (CameraHelper.CameraDevices.Count > 0)
  660. {
  661. int CameraIndex = 0;
  662. for (int i = 0; i < CameraHelper.CameraDevices.Count; i++)
  663. {
  664. if (CameraHelper.CameraDevices[i].MonikerString == APP.CameraName)
  665. {
  666. CameraIndex = i;
  667. }
  668. }
  669. CameraHelper.SetCameraDevice(CameraIndex);
  670. RbnOpen = new List<string>();
  671. times = new System.Timers.Timer(200)//初始值为300
  672. {
  673. AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
  674. };//设置执行一次(false)还是一直执行(true)
  675. times.Elapsed += new System.Timers.ElapsedEventHandler(Times_Elapsed);
  676. times.Enabled = true; //启动计时器
  677. IsRbnOpen = true;
  678. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  679. FileToolsCommon.CreateDirectory(imgPath);
  680. }
  681. }
  682. }
  683. private int I = 9999;
  684. private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  685. {
  686. if (IsRbnOpen)
  687. {
  688. try
  689. {
  690. Dispatcher.Invoke(() =>
  691. {
  692. if (I > 10010)
  693. {
  694. long time = Timestamp();
  695. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  696. //string FilePathName = ImgPath + RsImgName.Count + ".png";
  697. string path = CameraHelper.CaptureImage(imgPath, time.ToString());
  698. if (!string.IsNullOrWhiteSpace(path))
  699. {
  700. RbnOpen.Add(path);
  701. imgPlayerRight.Visibility = Visibility.Visible;
  702. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  703. if ("1".Equals(APP.CameraPosition))
  704. {
  705. imgPlayerRight.Visibility = Visibility.Visible;
  706. imgPlayerLeft.Visibility = Visibility.Collapsed;
  707. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  708. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  709. imgPlayerRight.Source = new BitmapImage(new Uri(path));
  710. }
  711. else if ("2".Equals(APP.CameraPosition))
  712. {
  713. imgPlayerRight.Visibility = Visibility.Collapsed;
  714. imgPlayerLeft.Visibility = Visibility.Visible;
  715. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  716. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  717. imgPlayerLeft.Source = new BitmapImage(new Uri(path));
  718. }
  719. else if ("3".Equals(APP.CameraPosition))
  720. {
  721. imgPlayerRight.Visibility = Visibility.Collapsed;
  722. imgPlayerLeft.Visibility = Visibility.Collapsed;
  723. imgPlayerRightUnder.Visibility = Visibility.Visible;
  724. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  725. imgPlayerRightUnder.Source = new BitmapImage(new Uri(path));
  726. }
  727. else if ("4".Equals(APP.CameraPosition))
  728. {
  729. imgPlayerRight.Visibility = Visibility.Collapsed;
  730. imgPlayerLeft.Visibility = Visibility.Collapsed;
  731. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  732. imgPlayerLeftUnder.Visibility = Visibility.Visible;
  733. imgPlayerLeftUnder.Source = new BitmapImage(new Uri(path));
  734. }
  735. else
  736. {
  737. imgPlayerLeft.Visibility = Visibility.Collapsed;
  738. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  739. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  740. imgPlayerRight.Source = new BitmapImage(new Uri(path));
  741. }
  742. }
  743. }
  744. I++;
  745. });
  746. }
  747. catch (Exception ex)
  748. {
  749. LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
  750. }
  751. }
  752. }
  753. /// <summary>
  754. /// 摄像头关闭事件
  755. /// </summary>
  756. /// <param name="sender">
  757. /// </param>
  758. /// <param name="e">
  759. /// </param>
  760. private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
  761. {
  762. if (IsRbnOpen)
  763. {
  764. #region 防止连击
  765. if (IsPressButton)
  766. {
  767. return;
  768. }
  769. else
  770. {
  771. IsPressButton = true;
  772. new Thread(new ThreadStart(new Action(() =>
  773. {
  774. //Dispatcher.Invoke(new Action(() => { rbnOpen.IsEnabled = false; }));
  775. Thread.Sleep(500);
  776. //Dispatcher.Invoke(new Action(() => { rbnOpen.IsEnabled = true; }));
  777. IsPressButton = false;
  778. }))).Start();
  779. }
  780. #endregion 防止连击
  781. IsRbnOpen = false;
  782. imgPlayerRight.Visibility = Visibility.Collapsed;
  783. imgPlayerLeft.Visibility = Visibility.Collapsed;
  784. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  785. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  786. CameraHelper.CloseDevice();
  787. I = 9999;
  788. }
  789. }
  790. #endregion 摄像头
  791. /// <summary>
  792. /// 关闭事件
  793. /// </summary>
  794. /// <param name="sender">
  795. /// </param>
  796. /// <param name="e">
  797. /// </param>
  798. private void BtnClose_Click(object sender, RoutedEventArgs e)
  799. {
  800. if (RecordType == 0)
  801. {
  802. try
  803. {
  804. MessageBoxResult br = MessageWindow.Show("确定退出系统?", "退出", MessageBoxButton.OKCancel);
  805. if (br == MessageBoxResult.OK)
  806. {
  807. try
  808. {
  809. APP.Killffmpeg();
  810. }
  811. catch (Exception ex)
  812. {
  813. LogHelper.WriteErrLog("获取进程失败," + ex.Message, ex);
  814. }
  815. APP.SaveWkData();
  816. APP.SaveDraw();
  817. TMC.TmatrixUninitialize();
  818. Environment.Exit(0);
  819. }
  820. }
  821. catch (Exception ex)
  822. {
  823. LogHelper.WriteErrLog("关闭微课失败," + ex.Message, ex);
  824. Close();
  825. Application.Current.Shutdown();
  826. TMC.TmatrixUninitialize();
  827. Environment.Exit(0);
  828. }
  829. }
  830. else
  831. {
  832. MessageWindow.Show("当前正在录制,请先停止录制。");
  833. return;
  834. }
  835. }
  836. /// <summary>
  837. /// 增加事件
  838. /// </summary>
  839. /// <param name="sender">
  840. /// </param>
  841. /// <param name="e">
  842. /// </param>
  843. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  844. {
  845. luoBoPenUtil.lb_device_hand();
  846. Record();
  847. if (APP.PageContextData.currpage > 0)
  848. {
  849. APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = true;
  850. }
  851. if (blackboard_canvas.Visibility == Visibility.Collapsed)
  852. {
  853. blackboard_canvas.Visibility = Visibility.Visible;
  854. }
  855. APP.PageContextData.pagenum += 1;
  856. HideAngleBorder();
  857. GridPage.Visibility = Visibility.Visible;//页码大于0 显示
  858. APP.PageContextData.currpage = APP.PageContextData.pagenum;
  859. myblackboard.changepage(APP.PageContextData.currpage - 1);
  860. ScroMain.ScrollToVerticalOffset(0);
  861. ///清空页面图片UI
  862. imgCanvas.Source = null;
  863. imgDocumentation.Source = null;
  864. imgPPT.Source = null;
  865. if (APP.PageContextData.pagenum == 1)
  866. {
  867. APP.PageDrawList = new List<Model_DrawData>();
  868. }
  869. ///画板模型增加一页
  870. Model_DrawData model_DrawData = new Model_DrawData
  871. {
  872. PageNum = APP.PageContextData.currpage
  873. };
  874. APP.PageDrawList.Add(model_DrawData);
  875. if (RecordType == 0)
  876. {
  877. BtnPrint.IsEnabled = true;
  878. }
  879. //APP.SaveDraw();
  880. if (BtnImport.IsEnabled)
  881. {
  882. ///截图可用
  883. BtnScreenshot.IsEnabled = true;
  884. }
  885. #region 插入页码
  886. PageData = new List<PageData>();
  887. for (int i = 1; i <= APP.PageContextData.pagenum; i++)
  888. {
  889. PageData pd = new PageData();
  890. pd.PageName = i.ToString();// + "页";
  891. pd.PageCode = i;
  892. PageData.Add(pd);
  893. }
  894. #endregion 插入页码
  895. }
  896. /// <summary>
  897. /// 打印事件
  898. /// </summary>
  899. /// <param name="sender">
  900. /// </param>
  901. /// <param name="e">
  902. /// </param>
  903. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  904. {
  905. try
  906. {
  907. //3种情况 1.文档图片 2.截图图片 3.没有图片
  908. if (APP.PageDrawList.Count == 0)
  909. {
  910. MessageWindow.Show("没有可打印的页,您可以通过加页、截图或导入来增加页!");
  911. return;
  912. }
  913. }
  914. catch (Exception ex)
  915. {
  916. MessageWindow.Show(ex.Message);
  917. Console.WriteLine("转换失败,原因:" + ex.Message);
  918. }
  919. if (GridPrintingTitle.Visibility == Visibility.Visible)
  920. {
  921. GridPrintingTitle.Visibility = Visibility.Collapsed;
  922. }
  923. else
  924. {
  925. GridPrintingTitle.Visibility = Visibility.Visible;
  926. if (APP.PageDrawList.Count > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[0].PageImagePath))
  927. {
  928. InitializePrint(APP.PageDrawList[0].PageImagePath, GridM.ActualWidth, GridM.ActualHeight);
  929. }
  930. else
  931. {
  932. InitializePrint("", GridM.ActualWidth, gridActHeight);
  933. }
  934. }
  935. }
  936. private void BtnPrintCloseClick(object sender, RoutedEventArgs e)
  937. {
  938. GridPrintingTitle.Visibility = Visibility.Collapsed;
  939. }
  940. private bool isHasCode = false;
  941. private void Print_No_Code_Click(object sender, RoutedEventArgs e)
  942. {
  943. isHasCode = false;
  944. print();
  945. }
  946. /// <summary>
  947. /// 打印
  948. /// </summary>
  949. /// <param name="sender">
  950. /// </param>
  951. /// <param name="e">
  952. /// </param>
  953. private void BtnPrint_Print_Click(object sender, RoutedEventArgs e)
  954. {
  955. isHasCode = true;
  956. print();
  957. }
  958. private void print()
  959. {
  960. if (string.IsNullOrWhiteSpace(cmbClass.Text))
  961. {
  962. MessageWindow.Show("请设置打印机!");
  963. return;
  964. }
  965. BtnPrint.IsEnabled = false;
  966. PrintModel printmodel = new PrintModel();
  967. string imgPath = FileToolsCommon.GetFileAbsolutePath("temp/");
  968. imgPath = imgPath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf";
  969. printmodel.filepath = imgPath;
  970. //打印数量
  971. printmodel.num = 1;
  972. //打印机名称
  973. string PrinterName = cmbClass.Text;
  974. printmodel.printname = PrinterName;
  975. PrintMsg = "准备中";
  976. msgnum = 0;
  977. num = 0;
  978. GridPrintMask.Visibility = Visibility.Visible;
  979. Task.Run(() =>
  980. {
  981. StartPrint(printmodel);
  982. });
  983. timesPrint = new System.Timers.Timer(100);
  984. timesPrint.Elapsed += Times_ElapsedClick;
  985. timesPrint.Start();
  986. timesPrintMsg = new System.Timers.Timer(500);
  987. timesPrintMsg.Elapsed += TimesPrintMsg_Elapsed;
  988. timesPrintMsg.Start();
  989. GridPrintingTitle.Visibility = Visibility.Collapsed;
  990. }
  991. /// <summary>
  992. /// 打印说明
  993. /// </summary>
  994. /// <param name="sender">
  995. /// </param>
  996. /// <param name="e">
  997. /// </param>
  998. private void btnPrintExplain_Click(object sender, RoutedEventArgs e)
  999. {
  1000. System.Diagnostics.Process.Start(FileToolsCommon.GetFileAbsolutePath("/星火微课点阵码打印及印刷指导手册.docx"));
  1001. }
  1002. #region 设备检测
  1003. /// <summary>
  1004. /// 设备检测
  1005. /// </summary>
  1006. /// <param name="sender">
  1007. /// </param>
  1008. /// <param name="e">
  1009. /// </param>
  1010. private void BtnDevice_Click(object sender, RoutedEventArgs e)
  1011. {
  1012. rbnTurnOff.IsChecked = true;
  1013. RbnTurnOff_Click(null, null);
  1014. DeviceWindow deviceWin = new DeviceWindow();
  1015. deviceWin.Show();
  1016. }
  1017. #endregion 设备检测
  1018. #endregion 事件
  1019. #region 画笔
  1020. /// <summary>
  1021. /// 画笔颜色事件 白色
  1022. /// </summary>
  1023. /// <param name="sender">
  1024. /// </param>
  1025. /// <param name="e">
  1026. /// </param>
  1027. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  1028. {
  1029. ////创建 DrawingAttributes 类的一个实例
  1030. //drawingAttributes = new DrawingAttributes();
  1031. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  1032. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  1033. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  1034. ////设置 DrawingAttributes 的 Color 属性设置颜色
  1035. drawingAttributes.Color = Colors.White;
  1036. Color = Colors.White;
  1037. }
  1038. /// <summary>
  1039. /// 画笔颜色事件 红色
  1040. /// </summary>
  1041. /// <param name="sender">
  1042. /// </param>
  1043. /// <param name="e">
  1044. /// </param>
  1045. private void BtnRed_Click(object sender, RoutedEventArgs e)
  1046. {
  1047. //设置 DrawingAttributes 的 Color 属性设置颜色
  1048. drawingAttributes.Color = Colors.Red;
  1049. Color = Colors.Red;
  1050. imgRed.Visibility = Visibility.Visible;
  1051. imgGray.Visibility = Visibility.Collapsed;
  1052. imgCyanBlue.Visibility = Visibility.Collapsed;
  1053. imgYellow.Visibility = Visibility.Collapsed;
  1054. imgBlue.Visibility = Visibility.Collapsed;
  1055. }
  1056. /// <summary>
  1057. /// 画笔颜色事件 黑色
  1058. /// </summary>
  1059. /// <param name="sender">
  1060. /// </param>
  1061. /// <param name="e">
  1062. /// </param>
  1063. private void BtnGray_Click(object sender, RoutedEventArgs e)
  1064. {
  1065. drawingAttributes.Color = Colors.Black;
  1066. Color = Colors.Black;
  1067. imgRed.Visibility = Visibility.Collapsed;
  1068. imgGray.Visibility = Visibility.Visible;
  1069. imgCyanBlue.Visibility = Visibility.Collapsed;
  1070. imgYellow.Visibility = Visibility.Collapsed;
  1071. imgBlue.Visibility = Visibility.Collapsed;
  1072. }
  1073. /// <summary>
  1074. /// 画笔颜色事件 青色
  1075. /// </summary>
  1076. /// <param name="sender">
  1077. /// </param>
  1078. /// <param name="e">
  1079. /// </param>
  1080. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  1081. {
  1082. drawingAttributes.Color = Colors.LimeGreen;
  1083. Color = Colors.LimeGreen;
  1084. imgRed.Visibility = Visibility.Collapsed;
  1085. imgGray.Visibility = Visibility.Collapsed;
  1086. imgCyanBlue.Visibility = Visibility.Visible;
  1087. imgYellow.Visibility = Visibility.Collapsed;
  1088. imgBlue.Visibility = Visibility.Collapsed;
  1089. }
  1090. /// <summary>
  1091. /// 画笔颜色事件 黄色
  1092. /// </summary>
  1093. /// <param name="sender">
  1094. /// </param>
  1095. /// <param name="e">
  1096. /// </param>
  1097. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  1098. {
  1099. drawingAttributes.Color = Colors.Gold;
  1100. Color = Colors.Gold;
  1101. imgRed.Visibility = Visibility.Collapsed;
  1102. imgGray.Visibility = Visibility.Collapsed;
  1103. imgCyanBlue.Visibility = Visibility.Collapsed;
  1104. imgYellow.Visibility = Visibility.Visible;
  1105. imgBlue.Visibility = Visibility.Collapsed;
  1106. }
  1107. /// <summary>
  1108. /// 画笔颜色事件 蓝色
  1109. /// </summary>
  1110. /// <param name="sender">
  1111. /// </param>
  1112. /// <param name="e">
  1113. /// </param>
  1114. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  1115. {
  1116. drawingAttributes.Color = Colors.DeepSkyBlue;
  1117. Color = Colors.DeepSkyBlue;
  1118. imgRed.Visibility = Visibility.Collapsed;
  1119. imgGray.Visibility = Visibility.Collapsed;
  1120. imgCyanBlue.Visibility = Visibility.Collapsed;
  1121. imgYellow.Visibility = Visibility.Collapsed;
  1122. imgBlue.Visibility = Visibility.Visible;
  1123. }
  1124. /// <summary>
  1125. /// 画笔粗细事件 细
  1126. /// </summary>
  1127. /// <param name="sender">
  1128. /// </param>
  1129. /// <param name="e">
  1130. /// </param>
  1131. private void RbnFine_Click(object sender, RoutedEventArgs e)
  1132. {
  1133. drawingAttributes.Width = 1;
  1134. drawingAttributes.Height = 1;
  1135. PenSize = 1;
  1136. }
  1137. /// <summary>
  1138. /// 画笔粗细事件 中
  1139. /// </summary>
  1140. /// <param name="sender">
  1141. /// </param>
  1142. /// <param name="e">
  1143. /// </param>
  1144. private void RbnIn_Click(object sender, RoutedEventArgs e)
  1145. {
  1146. drawingAttributes.Width = 3;
  1147. drawingAttributes.Height = 3;
  1148. PenSize = 3;
  1149. }
  1150. /// <summary>
  1151. /// 画笔粗细事件 粗
  1152. /// </summary>
  1153. /// <param name="sender">
  1154. /// </param>
  1155. /// <param name="e">
  1156. /// </param>
  1157. private void RbnCrude_Click(object sender, RoutedEventArgs e)
  1158. {
  1159. drawingAttributes.Width = 5;
  1160. drawingAttributes.Height = 5;
  1161. PenSize = 5;
  1162. }
  1163. private void imgCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1164. {
  1165. mouseDown = true;
  1166. imageOperationUtil.setMouseDown(mouseDown);
  1167. }
  1168. #endregion 画笔
  1169. #region 导入截图
  1170. /// <summary>
  1171. /// 截图事件
  1172. /// </summary>
  1173. /// <param name="sender">
  1174. /// </param>
  1175. /// <param name="e">
  1176. /// </param>
  1177. private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
  1178. {
  1179. double do1 = GridContent.ActualHeight;
  1180. double dou = GridMain.ActualHeight;
  1181. Record();
  1182. HideAngleBorder();
  1183. imgCanvas.Margin = new Thickness(0, 0, 0, 0);
  1184. APP.ImgPath = string.Empty;
  1185. string time = GetTimeStamp();
  1186. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
  1187. APP.ImgPath = desktopPath;
  1188. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), desktopPath, false, out BitmapImage bitmap);
  1189. k_hook.Stop();
  1190. if (WindowState == WindowState.Normal)//截图隐藏窗口
  1191. {
  1192. WindowState = WindowState.Minimized;
  1193. }
  1194. if (APP.W_JieTuWindow != null)
  1195. {
  1196. APP.W_JieTuWindow.initialization();
  1197. APP.W_JieTuWindow.Screenshot();
  1198. APP.W_JieTuWindow.InitializeKeyDownEvent();
  1199. APP.W_JieTuWindow.WindowState = WindowState.Maximized;
  1200. APP.W_JieTuWindow.Visibility = Visibility.Visible;
  1201. }
  1202. else
  1203. {
  1204. APP.W_JieTuWindow = new JieTuWindow();
  1205. APP.W_JieTuWindow.InitializeKeyDownEvent();
  1206. // 订阅事件
  1207. APP.W_JieTuWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
  1208. APP.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
  1209. APP.W_JieTuWindow.Show();
  1210. }
  1211. }
  1212. /// <summary>
  1213. /// 获取时间戳
  1214. /// </summary>
  1215. /// <returns>
  1216. /// </returns>
  1217. public string GetTimeStamp()
  1218. {
  1219. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  1220. return Convert.ToInt64(ts.TotalSeconds).ToString();
  1221. }
  1222. /// <summary>
  1223. /// 返回一个时间戳到毫秒
  1224. /// </summary>
  1225. /// <returns>
  1226. /// </returns>
  1227. public static long Timestamp()
  1228. {
  1229. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  1230. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  1231. return timestr;
  1232. }
  1233. public void WindowType()
  1234. {
  1235. this.Activate();
  1236. }
  1237. /// <summary>
  1238. /// 截图关闭窗口
  1239. /// </summary>
  1240. /// <param name="text">
  1241. /// </param>
  1242. private void frm_ChangeTextEvent(string text)
  1243. {
  1244. if ("关闭窗口".Equals(text))
  1245. {
  1246. if (WindowState == WindowState.Minimized)//截图完恢复窗口
  1247. {
  1248. WindowState = WindowState.Normal;
  1249. Activate();
  1250. }
  1251. InitializeKeyDownEvent();
  1252. if (!string.IsNullOrWhiteSpace(APP.ImgPath) && File.Exists(APP.ImgPath))
  1253. {
  1254. if (APP.PageContextData.currpage == 0)
  1255. {
  1256. APP.PageContextData.pagenum += 1;
  1257. APP.PageContextData.currpage = APP.PageContextData.pagenum;
  1258. myblackboard.changepage(APP.PageContextData.currpage - 1);
  1259. GridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1260. #region 插入页码
  1261. PageData = new List<PageData>();
  1262. for (int i = 1; i <= APP.PageContextData.pagenum; i++)
  1263. {
  1264. PageData pd = new PageData();
  1265. pd.PageName = i.ToString();// + "页";
  1266. pd.PageCode = i;
  1267. PageData.Add(pd);
  1268. }
  1269. #endregion 插入页码
  1270. }
  1271. if (APP.PageDrawList.Count >= APP.PageContextData.currpage)
  1272. {
  1273. APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath = APP.ImgPath;//zxycs
  1274. APP.PageDrawList[APP.PageContextData.currpage - 1].PdfImagePath = APP.ImgPath;
  1275. }
  1276. else
  1277. {
  1278. Model_DrawData model_DrawData = new Model_DrawData
  1279. {
  1280. PageImagePath = APP.ImgPath,
  1281. PdfImagePath = APP.ImgPath
  1282. };
  1283. APP.PageDrawList.Add(model_DrawData);
  1284. }
  1285. if (APP.PageDrawList.Count >= APP.PageContextData.currpage && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath))
  1286. {
  1287. imgDocumentation.Source = null;
  1288. BitmapImage bitImg = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
  1289. mouseDown = false;
  1290. imageOperationUtil.setMouseDown(mouseDown);
  1291. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
  1292. {
  1293. X = 0.1,
  1294. Y = 0.1
  1295. };
  1296. APP.PageDrawList[APP.PageContextData.currpage - 1].Type = "截图";
  1297. APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = false;
  1298. imgCanvas.Source = bitImg;
  1299. imgCanvas.Width = bitImg.Width;
  1300. imgCanvas.Height = bitImg.Height;
  1301. ScroMain.ScrollToVerticalOffset(0);
  1302. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
  1303. {
  1304. CenterX = imgCanvas.Width,
  1305. CenterY = imgCanvas.Height
  1306. };
  1307. BtnPrint.IsEnabled = true;
  1308. }
  1309. }
  1310. }
  1311. else if ("取消".Equals(text))
  1312. {
  1313. if (WindowState == WindowState.Minimized)//截图完恢复窗口
  1314. {
  1315. WindowState = WindowState.Normal;
  1316. }
  1317. }
  1318. }
  1319. /// <summary>
  1320. /// 截图关闭 非正常关闭截图时,截图清空
  1321. /// </summary>
  1322. private void JietuWindow_click_closeJietuWindowClick()
  1323. {
  1324. if (WindowState == WindowState.Minimized)//截图完恢复窗口
  1325. {
  1326. WindowState = WindowState.Normal;
  1327. }
  1328. APP.W_JieTuWindow = null;
  1329. }
  1330. /// 截图的图片鼠标右键事件 </summary> <param name="sender"></param> <param name="e"></param>
  1331. private void imgCanvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
  1332. {
  1333. imgCanvas.Source = null;
  1334. APP.PageDrawList[APP.PageContextData.currpage - 1].PdfImagePath = null;
  1335. APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath = null;
  1336. }
  1337. /// <summary>
  1338. /// 导入事件
  1339. /// </summary>
  1340. /// <param name="sender">
  1341. /// </param>
  1342. /// <param name="e">
  1343. /// </param>
  1344. private void BtnImport_Click(object sender, RoutedEventArgs e)
  1345. {
  1346. try
  1347. {
  1348. Record();
  1349. HideAngleBorder();
  1350. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  1351. ofd = new System.Windows.Forms.OpenFileDialog
  1352. {
  1353. //Filter = "文档|*.docx;*.doc;*.ppt;*.pptx",
  1354. //增加导入图片
  1355. Filter = "文档|*.docx;*.doc;*.ppt;*.pptx;*.pdf|图片|*.jpg;*.jpeg;*.png;*.bmp",
  1356. InitialDirectory = desktopPath,
  1357. Multiselect = false,
  1358. AddExtension = true,
  1359. DereferenceLinks = true
  1360. };
  1361. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
  1362. }
  1363. catch (Exception ex)
  1364. {
  1365. LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
  1366. }
  1367. }
  1368. /// <summary>
  1369. /// 导入-开始
  1370. /// </summary>
  1371. /// <returns>
  1372. /// </returns>
  1373. private object InvokeServering()
  1374. {
  1375. Dispatcher.Invoke(new Action(() =>
  1376. {
  1377. result = ofd.ShowDialog();
  1378. }));
  1379. if (result == System.Windows.Forms.DialogResult.OK)
  1380. {
  1381. if (ofd.FileName != "")
  1382. {
  1383. List<string> imagelist = new List<string>() { "jpg", "jpeg", "png", "bmp" };
  1384. Dispatcher.Invoke(new Action(() =>
  1385. {
  1386. APP.myloading.Show();
  1387. myblackboard.changepage(APP.PageContextData.pagenum);
  1388. }));
  1389. string filepath = ofd.FileName;
  1390. string filesuff = filepath.Substring(filepath.LastIndexOf(".") + 1).ToLower();
  1391. string path = ofd.SafeFileName.Replace(".ppt", "").Replace(".pptx", "").Trim();
  1392. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Replace(".pptx", "typezsygppt").Replace(".pdf", "typepdf").Trim();
  1393. if (type.Contains("typezsygppt"))//ppt
  1394. {
  1395. try
  1396. {
  1397. #region PPT转PDF
  1398. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1399. path = pathTemp + path + ".pdf";
  1400. FileToolsCommon.CreateDirectory(pathTemp);
  1401. //PPT转PDF
  1402. Presentation ppt = new Presentation(filepath);
  1403. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  1404. #endregion PPT转PDF
  1405. #region PDF转图片
  1406. // 图片绝对路径集合
  1407. List<string> images = new List<string>();
  1408. string directoryPath = pathTemp;
  1409. //定义Jpeg转换设备
  1410. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  1411. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1412. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1413. //directoryPath += quality;
  1414. Directory.CreateDirectory(directoryPath);
  1415. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1416. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1417. //遍历每一页转为jpg
  1418. for (int i = 1; i <= document.Pages.Count; i++)
  1419. {
  1420. long ii = Timestamp();
  1421. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1422. images.Add(filePathOutPut);
  1423. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1424. try
  1425. {
  1426. device.Process(document.Pages[i], fs);
  1427. fs.Close();
  1428. }
  1429. catch (Exception)
  1430. {
  1431. fs.Close();
  1432. File.Delete(filePathOutPut);
  1433. }
  1434. }
  1435. #endregion PDF转图片
  1436. Dispatcher.Invoke(new Action(() =>
  1437. {
  1438. string[] page = images.ToArray();
  1439. int num = 0;
  1440. int iStart = APP.PageContextData.pagenum;//导入文档的开始下标
  1441. int iEnd = page.Length + APP.PageContextData.pagenum;//导入文档的结束下标
  1442. for (int i = 0 + APP.PageContextData.pagenum; i < page.Length + APP.PageContextData.pagenum; i++)//给画板模型加图片路径
  1443. {
  1444. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1445. {
  1446. APP.PageDrawList[i].PageImagePath = page[i - APP.PageContextData.pagenum]; //zxycs
  1447. APP.PageDrawList[i].PdfImagePath = page[i - APP.PageContextData.pagenum];
  1448. APP.PageDrawList[i].PageNum = i + 1;
  1449. APP.PageDrawList[i].ImgDocumentation = true;
  1450. APP.PageDrawList[i].Type = "ppt";
  1451. }
  1452. else
  1453. {
  1454. Model_DrawData model_DrawData = new Model_DrawData
  1455. {
  1456. PageImagePath = page[i - APP.PageContextData.pagenum],
  1457. PdfImagePath = page[i - APP.PageContextData.pagenum],
  1458. PageNum = i + 1,
  1459. ImgDocumentation = true,
  1460. Type = "ppt"
  1461. };
  1462. APP.PageDrawList.Add(model_DrawData);
  1463. }
  1464. BtnPrint.IsEnabled = true;
  1465. APP.SaveDraw();
  1466. num++;
  1467. }
  1468. if (num > 0)
  1469. {
  1470. APP.PageContextData.currpage = APP.PageContextData.pagenum + 1;
  1471. APP.PageContextData.pagenum += num;
  1472. GridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1473. }
  1474. if (APP.PageContextData.currpage > 0 && APP.PageContextData.currpage <= APP.PageDrawList.Count)
  1475. {
  1476. imgCanvas.Source = null;
  1477. BtnScreenshot.IsEnabled = false;
  1478. imgDocumentation.Source = null;
  1479. imgPPT.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
  1480. ScroMain.ScrollToVerticalOffset(0);
  1481. for (int i = iStart; i < iEnd; i++)
  1482. {
  1483. APP.PageDrawList[i].ImageLocation = new TranslateTransform
  1484. {
  1485. X = 0.1,
  1486. Y = 0.1
  1487. };
  1488. APP.PageDrawList[i].IsImageLocation = true;
  1489. APP.PageDrawList[i].ImageSizes = new ScaleTransform
  1490. {
  1491. CenterX = imgCanvas.Width,
  1492. CenterY = imgCanvas.Height
  1493. };
  1494. }
  1495. }
  1496. else
  1497. {
  1498. imgDocumentation.Source = null;
  1499. imgCanvas.Source = null;
  1500. imgPPT.Source = null;
  1501. ///截图可用
  1502. BtnScreenshot.IsEnabled = true;
  1503. }
  1504. }));
  1505. }
  1506. catch (Exception ex)
  1507. {
  1508. Dispatcher.Invoke(new Action(() =>
  1509. {
  1510. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1511. }));
  1512. LogHelper.WriteErrLog("【打开ppt】(OpenDialog PPT)" + ex.Message, ex);
  1513. }
  1514. }
  1515. else if (type.Contains("typepdf"))
  1516. {
  1517. try
  1518. {
  1519. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1520. #region PDF转图片
  1521. // 图片绝对路径集合
  1522. List<string> images = new List<string>();
  1523. string directoryPath = pathTemp;
  1524. //aspose许可证
  1525. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1526. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1527. //l.SetLicense(licenseName);
  1528. //定义Jpeg转换设备
  1529. Aspose.Pdf.Document document = new Aspose.Pdf.Document(filepath);
  1530. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1531. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1532. //directoryPath += quality;
  1533. Directory.CreateDirectory(directoryPath);
  1534. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1535. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1536. //遍历每一页转为jpg
  1537. for (int i = 1; i <= document.Pages.Count; i++)
  1538. {
  1539. long ii = Timestamp();
  1540. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1541. images.Add(filePathOutPut);
  1542. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1543. try
  1544. {
  1545. device.Process(document.Pages[i], fs);
  1546. fs.Close();
  1547. }
  1548. catch (Exception)
  1549. {
  1550. fs.Close();
  1551. File.Delete(filePathOutPut);
  1552. }
  1553. }
  1554. #endregion PDF转图片
  1555. string[] page = images.ToArray();
  1556. int num = 0;
  1557. int iStart = APP.PageContextData.pagenum;//导入文档的开始下标
  1558. int iEnd = page.Length + APP.PageContextData.pagenum;//导入文档的结束下标
  1559. Dispatcher.Invoke(new Action(() =>
  1560. {
  1561. for (int i = APP.PageContextData.pagenum; i < page.Length + APP.PageContextData.pagenum; i++)//给画板模型加图片路径
  1562. {
  1563. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1564. {
  1565. APP.PageDrawList[i].PageImagePath = page[i - APP.PageContextData.pagenum]; //zxycs
  1566. APP.PageDrawList[i].PdfImagePath = page[i - APP.PageContextData.pagenum];
  1567. APP.PageDrawList[i].PageNum = i + 1;
  1568. APP.PageDrawList[i].ImgDocumentation = true;
  1569. APP.PageDrawList[i].Type = "word";
  1570. }
  1571. else
  1572. {
  1573. Model_DrawData model_DrawData = new Model_DrawData
  1574. {
  1575. PageImagePath = page[i - APP.PageContextData.pagenum],
  1576. PdfImagePath = page[i - APP.PageContextData.pagenum],
  1577. PageNum = i + 1,
  1578. ImgDocumentation = true,
  1579. Type = "word"
  1580. };
  1581. APP.PageDrawList.Add(model_DrawData);
  1582. }
  1583. BtnPrint.IsEnabled = true;
  1584. APP.SaveDraw();
  1585. num++;
  1586. }
  1587. if (num > 0)
  1588. {
  1589. APP.PageContextData.currpage = APP.PageContextData.pagenum + 1;
  1590. APP.PageContextData.pagenum += num;
  1591. GridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1592. }
  1593. if (APP.PageContextData.currpage > 0 && APP.PageContextData.currpage <= APP.PageDrawList.Count)
  1594. {
  1595. imgCanvas.Source = null;
  1596. imgPPT.Source = null;
  1597. BtnScreenshot.IsEnabled = false;
  1598. imgDocumentation.Visibility = Visibility.Visible;
  1599. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));//给当前页面展示图片
  1600. ScroMain.ScrollToVerticalOffset(0);
  1601. }
  1602. else
  1603. {
  1604. imgDocumentation.Source = null;
  1605. imgCanvas.Source = null;
  1606. imgPPT.Source = null;
  1607. ///截图可用
  1608. BtnScreenshot.IsEnabled = true;
  1609. }
  1610. }));
  1611. }
  1612. catch (Exception ex)
  1613. {
  1614. Dispatcher.Invoke(new Action(() =>
  1615. {
  1616. MessageWindow.Show(ex.Message);
  1617. }));
  1618. LogHelper.WriteErrLog("【打开pdf】(OpenDialog pdf)" + ex.Message, ex);
  1619. }
  1620. }
  1621. else if (imagelist.Contains(filesuff))///导入图片
  1622. {
  1623. string imagepath = AppDomain.CurrentDomain.BaseDirectory + "temp";
  1624. if (!Directory.Exists(imagepath))
  1625. {
  1626. Directory.CreateDirectory(imagepath);
  1627. }
  1628. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  1629. string timestr = Convert.ToInt64(ts.TotalMilliseconds).ToString();
  1630. string filepathCopy = Path.Combine(imagepath, timestr + ofd.SafeFileName);
  1631. System.IO.File.Copy(filepath, filepathCopy);
  1632. filepath = filepathCopy;
  1633. APP.ImgPath = filepath;
  1634. Dispatcher.Invoke(new Action(() =>
  1635. {
  1636. if (APP.PageContextData.currpage == 0)
  1637. {
  1638. APP.PageContextData.pagenum += 1;
  1639. APP.PageContextData.currpage = APP.PageContextData.pagenum;
  1640. myblackboard.changepage(APP.PageContextData.currpage - 1);
  1641. GridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1642. #region 插入页码
  1643. PageData = new List<PageData>();
  1644. for (int i = 1; i <= APP.PageContextData.pagenum; i++)
  1645. {
  1646. PageData pd = new PageData();
  1647. pd.PageName = i.ToString();// + "页";
  1648. pd.PageCode = i;
  1649. PageData.Add(pd);
  1650. }
  1651. #endregion 插入页码
  1652. }
  1653. else
  1654. {
  1655. APP.PageContextData.pagenum += 1;
  1656. APP.PageContextData.currpage = APP.PageContextData.pagenum;
  1657. myblackboard.changepage(APP.PageContextData.currpage - 1);
  1658. }
  1659. if (APP.PageDrawList.Count >= APP.PageContextData.currpage)
  1660. {
  1661. APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath = APP.ImgPath;//zxycs
  1662. APP.PageDrawList[APP.PageContextData.currpage - 1].PdfImagePath = APP.ImgPath;
  1663. }
  1664. else
  1665. {
  1666. Model_DrawData model_DrawData = new Model_DrawData
  1667. {
  1668. PageImagePath = APP.ImgPath,
  1669. PdfImagePath = APP.ImgPath
  1670. };
  1671. APP.PageDrawList.Add(model_DrawData);
  1672. }
  1673. if (APP.PageDrawList.Count >= APP.PageContextData.currpage && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath))
  1674. {
  1675. imgDocumentation.Source = null;
  1676. BitmapImage bitImg = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
  1677. mouseDown = false;
  1678. imageOperationUtil.setMouseDown(mouseDown);
  1679. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
  1680. {
  1681. X = 0.1,
  1682. Y = 0.1
  1683. };
  1684. APP.PageDrawList[APP.PageContextData.currpage - 1].Type = "截图";
  1685. APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = false;
  1686. imgCanvas.Source = bitImg;
  1687. imgCanvas.Width = bitImg.Width;
  1688. imgCanvas.Height = bitImg.Height;
  1689. ScroMain.ScrollToVerticalOffset(0);
  1690. imgCanvas.Margin = new Thickness(APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation.X, APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation.Y, 0, 0);
  1691. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
  1692. {
  1693. CenterX = imgCanvas.Width,
  1694. CenterY = imgCanvas.Height
  1695. };
  1696. BtnPrint.IsEnabled = true;
  1697. }
  1698. }));
  1699. }
  1700. else//word
  1701. {
  1702. try
  1703. {
  1704. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1705. WordImgNum += 1;
  1706. string[] page = ZAsposeUtil.ConvertWordToImage(filepath, paths, "" + WordImgNum, 0, 0).ToArray();
  1707. int num = 0;
  1708. Dispatcher.Invoke(new Action(() =>
  1709. {
  1710. for (int i = 0 + APP.PageContextData.pagenum; i < page.Length + APP.PageContextData.pagenum; i++)//给画板模型加图片路径
  1711. {
  1712. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1713. {
  1714. APP.PageDrawList[i].PageImagePath = page[i - APP.PageContextData.pagenum]; //zxycs
  1715. APP.PageDrawList[i].PdfImagePath = page[i - APP.PageContextData.pagenum];
  1716. APP.PageDrawList[i].PageNum = i + 1;
  1717. APP.PageDrawList[i].ImgDocumentation = true;
  1718. APP.PageDrawList[i].Type = "word";
  1719. }
  1720. else
  1721. {
  1722. Model_DrawData model_DrawData = new Model_DrawData
  1723. {
  1724. PageImagePath = page[i - APP.PageContextData.pagenum],
  1725. PdfImagePath = page[i - APP.PageContextData.pagenum],
  1726. PageNum = i + 1,
  1727. ImgDocumentation = true,
  1728. Type = "word"
  1729. };
  1730. APP.PageDrawList.Add(model_DrawData);
  1731. }
  1732. BtnPrint.IsEnabled = true;
  1733. APP.SaveDraw();
  1734. num++;
  1735. }
  1736. if (num > 0)
  1737. {
  1738. APP.PageContextData.currpage = APP.PageContextData.pagenum + 1;
  1739. APP.PageContextData.pagenum += num;
  1740. GridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1741. }
  1742. if (APP.PageContextData.currpage > 0 && APP.PageContextData.currpage <= APP.PageDrawList.Count)
  1743. {
  1744. imgCanvas.Source = null;
  1745. imgPPT.Source = null;
  1746. BtnScreenshot.IsEnabled = false;
  1747. imgDocumentation.Visibility = Visibility.Visible;
  1748. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));//给当前页面展示图片
  1749. ScroMain.ScrollToVerticalOffset(0);
  1750. }
  1751. else
  1752. {
  1753. imgDocumentation.Source = null;
  1754. imgCanvas.Source = null;
  1755. imgPPT.Source = null;
  1756. ///截图可用
  1757. BtnScreenshot.IsEnabled = true;
  1758. }
  1759. }));
  1760. }
  1761. catch (Exception ex)
  1762. {
  1763. Dispatcher.Invoke(new Action(() =>
  1764. {
  1765. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1766. }));
  1767. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
  1768. }
  1769. }
  1770. #region 插入页码
  1771. Dispatcher.Invoke(new Action(() =>
  1772. {
  1773. PageData = new List<PageData>();
  1774. for (int i = 1; i <= APP.PageContextData.pagenum; i++)
  1775. {
  1776. PageData pd = new PageData();
  1777. pd.PageName = i.ToString();//+ "页";
  1778. pd.PageCode = i;
  1779. PageData.Add(pd);
  1780. }
  1781. }));
  1782. #endregion 插入页码
  1783. }
  1784. }
  1785. //OpenDialog();
  1786. return "";
  1787. }
  1788. /// <summary>
  1789. /// 导入-结束
  1790. /// </summary>
  1791. /// <returns>
  1792. /// </returns>
  1793. public void InvokeServerCompate(object obj)
  1794. {
  1795. //APP.myloading.Hide();
  1796. APP.myloading.Hide();
  1797. }
  1798. /// <summary>
  1799. /// 防止图片地址重复
  1800. /// </summary>
  1801. private long WordImgNum = 9999;
  1802. /// <summary>
  1803. /// 导入文档
  1804. /// </summary>
  1805. private void OpenDialog()
  1806. {
  1807. Dispatcher.Invoke(new Action(() =>
  1808. {
  1809. result = ofd.ShowDialog();
  1810. if (result == System.Windows.Forms.DialogResult.OK)
  1811. {
  1812. if (ofd.FileName != "")
  1813. {
  1814. APP.myloading.Show();
  1815. myblackboard.changepage(APP.PageContextData.pagenum);
  1816. #region PPT转PDF
  1817. string filepath = ofd.FileName;
  1818. string path = ofd.SafeFileName.Replace(".ppt", "").Replace(".pptx", "").Trim();
  1819. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Replace(".pptx", "typezsygppt").Replace(".pdf", "typepdf").Trim();
  1820. if (type.Contains("typezsygppt"))//ppt
  1821. {
  1822. try
  1823. {
  1824. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1825. path = pathTemp + path + ".pdf";
  1826. FileToolsCommon.CreateDirectory(pathTemp);
  1827. //PPT转PDF
  1828. Presentation ppt = new Presentation(filepath);
  1829. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  1830. #endregion PPT转PDF
  1831. #region PDF转图片
  1832. // 图片绝对路径集合
  1833. List<string> images = new List<string>();
  1834. string directoryPath = pathTemp;
  1835. //aspose许可证
  1836. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1837. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1838. //l.SetLicense(licenseName);
  1839. //定义Jpeg转换设备
  1840. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  1841. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1842. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1843. //directoryPath += quality;
  1844. Directory.CreateDirectory(directoryPath);
  1845. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1846. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1847. //遍历每一页转为jpg
  1848. for (int i = 1; i <= document.Pages.Count; i++)
  1849. {
  1850. long ii = Timestamp();
  1851. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1852. images.Add(filePathOutPut);
  1853. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1854. try
  1855. {
  1856. device.Process(document.Pages[i], fs);
  1857. fs.Close();
  1858. }
  1859. catch (Exception)
  1860. {
  1861. fs.Close();
  1862. File.Delete(filePathOutPut);
  1863. }
  1864. }
  1865. #endregion PDF转图片
  1866. string[] page = images.ToArray();
  1867. int num = 0;
  1868. for (int i = 0 + APP.PageContextData.pagenum; i < page.Length + APP.PageContextData.pagenum; i++)//给画板模型加图片路径
  1869. {
  1870. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1871. {
  1872. APP.PageDrawList[i].PageImagePath = page[i - APP.PageContextData.pagenum]; //zxycs
  1873. APP.PageDrawList[i].PdfImagePath = page[i - APP.PageContextData.pagenum];
  1874. APP.PageDrawList[i].PageNum = i + 1;
  1875. APP.PageDrawList[i].ImgDocumentation = true;
  1876. }
  1877. else
  1878. {
  1879. Model_DrawData model_DrawData = new Model_DrawData
  1880. {
  1881. PageImagePath = page[i - APP.PageContextData.pagenum],
  1882. PdfImagePath = page[i - APP.PageContextData.pagenum],
  1883. PageNum = i + 1,
  1884. ImgDocumentation = true
  1885. };
  1886. APP.PageDrawList.Add(model_DrawData);
  1887. }
  1888. BtnPrint.IsEnabled = true;
  1889. APP.SaveDraw();
  1890. num++;
  1891. }
  1892. if (num > 0)
  1893. {
  1894. APP.PageContextData.currpage = APP.PageContextData.pagenum + 1;
  1895. APP.PageContextData.pagenum += num;
  1896. GridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1897. }
  1898. if (APP.PageContextData.currpage > 0 && APP.PageContextData.currpage < APP.PageDrawList.Count)
  1899. {
  1900. imgCanvas.Source = null;
  1901. BtnScreenshot.IsEnabled = false;
  1902. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));//给当前页面展示图片
  1903. }
  1904. else
  1905. {
  1906. imgDocumentation.Source = null;
  1907. imgCanvas.Source = null;
  1908. ///截图可用
  1909. BtnScreenshot.IsEnabled = true;
  1910. }
  1911. APP.myloading.Hide();
  1912. }
  1913. catch (Exception ex)
  1914. {
  1915. APP.myloading.Hide();
  1916. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1917. LogHelper.WriteErrLog("【打开ppt】(OpenDialog PPT)" + ex.Message, ex);
  1918. }
  1919. }
  1920. else if (type.Contains("typepdf"))
  1921. {
  1922. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1923. #region PDF转图片
  1924. // 图片绝对路径集合
  1925. List<string> images = new List<string>();
  1926. string directoryPath = pathTemp;
  1927. //aspose许可证
  1928. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1929. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1930. //l.SetLicense(licenseName);
  1931. //定义Jpeg转换设备
  1932. Aspose.Pdf.Document document = new Aspose.Pdf.Document(filepath);
  1933. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1934. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1935. //directoryPath += quality;
  1936. Directory.CreateDirectory(directoryPath);
  1937. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1938. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1939. //遍历每一页转为jpg
  1940. for (int i = 1; i <= document.Pages.Count; i++)
  1941. {
  1942. long ii = Timestamp();
  1943. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1944. images.Add(filePathOutPut);
  1945. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1946. try
  1947. {
  1948. device.Process(document.Pages[i], fs);
  1949. fs.Close();
  1950. }
  1951. catch (Exception)
  1952. {
  1953. fs.Close();
  1954. File.Delete(filePathOutPut);
  1955. }
  1956. }
  1957. #endregion PDF转图片
  1958. string[] page = images.ToArray();
  1959. int num = 0;
  1960. for (int i = 0 + APP.PageContextData.pagenum; i < page.Length + APP.PageContextData.pagenum; i++)//给画板模型加图片路径
  1961. {
  1962. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1963. {
  1964. APP.PageDrawList[i].PageImagePath = page[i - APP.PageContextData.pagenum]; //zxycs
  1965. APP.PageDrawList[i].PdfImagePath = page[i - APP.PageContextData.pagenum];
  1966. APP.PageDrawList[i].PageNum = i + 1;
  1967. APP.PageDrawList[i].ImgDocumentation = true;
  1968. }
  1969. else
  1970. {
  1971. Model_DrawData model_DrawData = new Model_DrawData
  1972. {
  1973. PageImagePath = page[i - APP.PageContextData.pagenum],
  1974. PdfImagePath = page[i - APP.PageContextData.pagenum],
  1975. PageNum = i + 1,
  1976. ImgDocumentation = true
  1977. };
  1978. APP.PageDrawList.Add(model_DrawData);
  1979. }
  1980. BtnPrint.IsEnabled = true;
  1981. APP.SaveDraw();
  1982. num++;
  1983. }
  1984. if (num > 0)
  1985. {
  1986. APP.PageContextData.currpage = APP.PageContextData.pagenum + 1;
  1987. APP.PageContextData.pagenum += num;
  1988. GridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1989. }
  1990. if (APP.PageContextData.currpage > 0 && APP.PageContextData.currpage < APP.PageDrawList.Count)
  1991. {
  1992. imgCanvas.Source = null;
  1993. BtnScreenshot.IsEnabled = false;
  1994. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));//给当前页面展示图片
  1995. }
  1996. else
  1997. {
  1998. imgDocumentation.Source = null;
  1999. imgCanvas.Source = null;
  2000. ///截图可用
  2001. BtnScreenshot.IsEnabled = true;
  2002. }
  2003. APP.myloading.Hide();
  2004. }
  2005. else//word
  2006. {
  2007. try
  2008. {
  2009. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  2010. WordImgNum += 1;
  2011. string[] page = ZAsposeUtil.ConvertWordToImage(filepath, paths, "" + WordImgNum, 0, 0).ToArray();
  2012. int num = 0;
  2013. for (int i = 0 + APP.PageContextData.pagenum; i < page.Length + APP.PageContextData.pagenum; i++)//给画板模型加图片路径
  2014. {
  2015. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  2016. {
  2017. APP.PageDrawList[i].PageImagePath = page[i - APP.PageContextData.pagenum]; //zxycs
  2018. APP.PageDrawList[i].PdfImagePath = page[i - APP.PageContextData.pagenum];
  2019. APP.PageDrawList[i].PageNum = i + 1;
  2020. APP.PageDrawList[i].ImgDocumentation = true;
  2021. }
  2022. else
  2023. {
  2024. Model_DrawData model_DrawData = new Model_DrawData
  2025. {
  2026. PageImagePath = page[i - APP.PageContextData.pagenum],
  2027. PdfImagePath = page[i - APP.PageContextData.pagenum],
  2028. PageNum = i + 1,
  2029. ImgDocumentation = true
  2030. };
  2031. APP.PageDrawList.Add(model_DrawData);
  2032. }
  2033. BtnPrint.IsEnabled = true;
  2034. APP.SaveDraw();
  2035. num++;
  2036. }
  2037. if (num > 0)
  2038. {
  2039. APP.PageContextData.currpage = APP.PageContextData.pagenum + 1;
  2040. APP.PageContextData.pagenum += num;
  2041. GridPage.Visibility = Visibility.Visible;//页码大于0 显示
  2042. }
  2043. if (APP.PageContextData.currpage > 0 && APP.PageContextData.currpage < APP.PageDrawList.Count)
  2044. {
  2045. imgCanvas.Source = null;
  2046. BtnScreenshot.IsEnabled = false;
  2047. imgDocumentation.Visibility = Visibility.Visible;
  2048. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));//给当前页面展示图片
  2049. }
  2050. else
  2051. {
  2052. imgDocumentation.Source = null;
  2053. imgCanvas.Source = null;
  2054. ///截图可用
  2055. BtnScreenshot.IsEnabled = true;
  2056. }
  2057. APP.myloading.Hide();
  2058. }
  2059. catch (Exception ex)
  2060. {
  2061. APP.myloading.Hide();
  2062. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
  2063. }
  2064. }
  2065. }
  2066. }
  2067. }
  2068. ));
  2069. }
  2070. #region 导入转换图片
  2071. /// <summary>
  2072. /// 生成图片
  2073. /// </summary>
  2074. /// <param name="_path">
  2075. /// 图片地址
  2076. /// </param>
  2077. /// <param name="_saveimg">
  2078. /// 保存位置
  2079. /// </param>
  2080. /// <param name="_rectangle">
  2081. /// 图片位置
  2082. /// </param>
  2083. /// <param name="errmsg">
  2084. /// 错误消息
  2085. /// </param>
  2086. /// <returns>
  2087. /// </returns>
  2088. private bool MergerImg(string _path, string _saveimg, RectangleF _rectangle, out string errmsg)
  2089. {
  2090. errmsg = null;
  2091. try
  2092. {
  2093. Bitmap bitmap = null;
  2094. //创建要显示的图片对象,根据参数的个数设置宽度
  2095. Bitmap backgroudImg = new Bitmap((int)GridM.ActualWidth, (int)GridM.ActualHeight);
  2096. Graphics g = Graphics.FromImage(backgroudImg);
  2097. //清除画布,背景设置为白色
  2098. g.Clear(System.Drawing.Color.White);
  2099. if (!string.IsNullOrWhiteSpace(_path))
  2100. {
  2101. bitmap = ImageHelper.ReadBitmapFile(_path);
  2102. g.DrawImage(bitmap, _rectangle);
  2103. }
  2104. backgroudImg.Save(_saveimg);
  2105. g.Dispose();
  2106. backgroudImg.Dispose();
  2107. if (bitmap != null)
  2108. {
  2109. bitmap.Dispose();
  2110. }
  2111. GC.Collect();
  2112. return true;
  2113. }
  2114. catch (Exception ex)
  2115. {
  2116. errmsg = ex.Message;
  2117. LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
  2118. return false;
  2119. }
  2120. }
  2121. #endregion 导入转换图片
  2122. #endregion 导入截图
  2123. #region 上传 列表
  2124. /// <summary>
  2125. /// 上传事件
  2126. /// </summary>
  2127. /// <param name="sender">
  2128. /// </param>
  2129. /// <param name="e">
  2130. /// </param>
  2131. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  2132. {
  2133. if (GridMyVideo.Visibility == Visibility.Visible)
  2134. {
  2135. GridMyVideo.Visibility = Visibility.Collapsed;
  2136. GridMain.Visibility = Visibility.Visible;
  2137. GridM.IsEnabled = true;
  2138. GridRecordingTitle.Visibility = Visibility.Visible;
  2139. }
  2140. else
  2141. {
  2142. PageHide();
  2143. GridMyVideo.Visibility = Visibility.Visible;
  2144. LoadUploadInitData();
  2145. }
  2146. }
  2147. /// <summary>
  2148. /// 加载视频列表
  2149. /// </summary>
  2150. public void LoadingVideoList()
  2151. {
  2152. try
  2153. {
  2154. model_VideoList = new List<Model_Video>();
  2155. foreach (Model_WKData Vdata in APP.WKDataList)
  2156. {
  2157. #region 计时器初始化
  2158. if (Vdata.VideoList == null)
  2159. {
  2160. continue;
  2161. }
  2162. foreach (Model_Video videoinfo in Vdata.VideoList)
  2163. {
  2164. try
  2165. {
  2166. if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
  2167. {
  2168. continue;
  2169. }
  2170. if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
  2171. {
  2172. videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMB(videoinfo.VideoPath).ToString() + " MB";
  2173. videoinfo.VideoSizebyte = FileToolsCommon.GetFileSize(videoinfo.VideoPath);
  2174. }
  2175. model_VideoList.Add(videoinfo);
  2176. }
  2177. catch (Exception ex)
  2178. {
  2179. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  2180. }
  2181. }
  2182. #endregion 计时器初始化
  2183. }
  2184. //翻转
  2185. if (model_VideoList.Count > 1)
  2186. {
  2187. model_VideoList.Reverse();
  2188. }
  2189. }
  2190. catch (Exception ex)
  2191. {
  2192. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  2193. }
  2194. }
  2195. /// <summary>
  2196. /// 搜索集合匹配的索引
  2197. /// </summary>
  2198. /// <typeparam name="T">
  2199. /// </typeparam>
  2200. /// <param name="parent">
  2201. /// </param>
  2202. /// <param name="childName">
  2203. /// </param>
  2204. /// <returns>
  2205. /// </returns>
  2206. public static List<T> FindChilds<T>(DependencyObject parent, string childName)
  2207. where T : DependencyObject
  2208. {
  2209. List<T> list = new List<T>();
  2210. if (parent == null)
  2211. {
  2212. return list;
  2213. }
  2214. int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
  2215. for (int i = 0; i < childrenCount; i++)
  2216. {
  2217. DependencyObject child = VisualTreeHelper.GetChild(parent, i);
  2218. // 如果子控件不是需查找的控件类型
  2219. T childType = child as T;
  2220. if (childType == null)
  2221. {
  2222. // 在下一级控件中递归查找
  2223. List<T> findChildList = FindChilds<T>(child, childName);
  2224. for (int j = 0; j < findChildList.Count; j++)
  2225. {
  2226. }
  2227. list.AddRange(FindChilds<T>(child, childName));
  2228. }
  2229. else if (!string.IsNullOrEmpty(childName))
  2230. {
  2231. FrameworkElement frameworkElement = child as FrameworkElement;
  2232. // 如果控件名称符合参数条件
  2233. if (frameworkElement != null && frameworkElement.Name == childName)
  2234. {
  2235. list.Add((T)child);
  2236. }
  2237. }
  2238. else
  2239. {
  2240. // 查找到了控件
  2241. list.Add((T)child);
  2242. }
  2243. }
  2244. return list;
  2245. }
  2246. #endregion 上传 列表
  2247. #region 新上传 显示缩略图
  2248. #region 初始值
  2249. /// <summary>
  2250. /// 总页数
  2251. /// </summary>
  2252. private int TotalPage = 0;
  2253. /// <summary>
  2254. /// 当前页
  2255. /// </summary>
  2256. private int CurrentPage = 1;
  2257. /// <summary>
  2258. /// 每页显示的视频数
  2259. /// </summary>
  2260. private int PageShowNum = 0;
  2261. /// <summary>
  2262. /// 视频信息列表
  2263. /// </summary>
  2264. private List<Uc_VideoItem> VideoControlList = new List<Uc_VideoItem>();
  2265. /// <summary>
  2266. /// 横向间隔
  2267. /// </summary>
  2268. private double IntervalX = 0;
  2269. /// <summary>
  2270. /// 纵向间隔
  2271. /// </summary>
  2272. private double IntervalY = 0;
  2273. /// <summary>
  2274. /// 页面宽
  2275. /// </summary>
  2276. private double pageW;
  2277. /// <summary>
  2278. /// 页面高
  2279. /// </summary>
  2280. private double pageH;
  2281. private double ControlWidth = 250;
  2282. private double ControlHeight = 260;
  2283. #endregion 初始值
  2284. /// <summary>
  2285. /// 初始化加载上传页面数据
  2286. /// </summary>
  2287. private void LoadUploadInitData()
  2288. {
  2289. APP.myloading.Show();
  2290. //加载视频列表
  2291. LoadingVideoList();
  2292. if (model_VideoList.Count > 0)
  2293. {
  2294. lblVideoMess.Visibility = Visibility.Hidden;
  2295. BtnVideoUpPage.Visibility = Visibility.Visible;
  2296. lblVideoPageNum.Visibility = Visibility.Visible;
  2297. BtnVideoDownPage.Visibility = Visibility.Visible;
  2298. if (GridMyVideo.ActualHeight > 0)
  2299. {
  2300. pageW = GridMyVideo.ActualWidth;
  2301. pageH = GridMyVideo.ActualHeight;
  2302. }
  2303. else
  2304. {
  2305. pageW = GridRecordingArea.ActualWidth;
  2306. pageH = GridRecordingArea.ActualHeight;
  2307. }
  2308. //获取设置控件大小 新增 页面原始1061 911
  2309. double PropWid = pageW / 1061.00;
  2310. double PropHei = pageH / 911.00;
  2311. //ControlWidth = 250.00 * PropWid;
  2312. //ControlHeight = 260.00 * PropHei;
  2313. //ControlWidth=
  2314. //ControlHeight=
  2315. //根据页面大小获取每页显示的数量 H260W250
  2316. int videoRow = (int)((pageH - 50) / ControlHeight);
  2317. int videColumn = (int)(pageW / ControlWidth);
  2318. //横向间隔
  2319. IntervalX = (pageW - (videColumn * ControlWidth)) / (videColumn + 1);
  2320. IntervalY = (pageH - 50 - (videoRow * ControlHeight)) / (videoRow + 1);
  2321. PageShowNum = (videoRow == 0 ? 1 : videoRow) * (videColumn == 0 ? 1 : videColumn);
  2322. //获取总页数
  2323. TotalPage = model_VideoList.Count / PageShowNum + (model_VideoList.Count % PageShowNum > 0 ? 1 : 0);
  2324. //如果当前页大于总页数 总页数为当前页
  2325. if (TotalPage < CurrentPage)
  2326. {
  2327. CurrentPage = TotalPage;
  2328. }
  2329. LoadCurrentPageData();
  2330. }
  2331. else
  2332. {
  2333. lblVideoMess.Visibility = Visibility.Visible;
  2334. BtnVideoUpPage.Visibility = Visibility.Hidden;
  2335. lblVideoPageNum.Visibility = Visibility.Hidden;
  2336. BtnVideoDownPage.Visibility = Visibility.Hidden;
  2337. //隐藏显示的控件
  2338. if (VideoControlList.Count > 0)
  2339. {
  2340. foreach (Uc_VideoItem item in VideoControlList)
  2341. {
  2342. if (item.Visibility != Visibility.Hidden)
  2343. {
  2344. item.Visibility = Visibility.Hidden;
  2345. }
  2346. }
  2347. }
  2348. }
  2349. APP.myloading.Hide();
  2350. }
  2351. /// <summary>
  2352. /// 加载当前页数据
  2353. /// </summary>
  2354. private void LoadCurrentPageData()
  2355. {
  2356. lblVideoPageNum.Content = CurrentPage + "/" + TotalPage;
  2357. //隐藏显示的控件
  2358. if (VideoControlList.Count > 0)
  2359. {
  2360. foreach (Uc_VideoItem item in VideoControlList)
  2361. {
  2362. if (item.Visibility != Visibility.Hidden)
  2363. {
  2364. item.Visibility = Visibility.Hidden;
  2365. }
  2366. }
  2367. }
  2368. double W = IntervalX;//每次增加250
  2369. double H = IntervalY;//每次增加260
  2370. //加载控件
  2371. for (int i = 0; i < PageShowNum; i++)
  2372. {
  2373. int DataIndex = (CurrentPage - 1) * PageShowNum + i;
  2374. if (DataIndex == model_VideoList.Count)
  2375. {
  2376. return;
  2377. }
  2378. Uc_VideoItem videoItem;
  2379. if (VideoControlList.Exists(x => x.Tag.ToString() == model_VideoList[DataIndex].FileGuid))
  2380. {
  2381. videoItem = VideoControlList.Find(x => x.Tag.ToString() == model_VideoList[DataIndex].FileGuid);
  2382. }
  2383. else
  2384. {
  2385. if (!FileToolsCommon.IsExistFile(model_VideoList[DataIndex].ThumbnailPath))
  2386. {
  2387. continue;
  2388. }
  2389. videoItem = new Uc_VideoItem(model_VideoList[DataIndex])
  2390. {
  2391. Tag = model_VideoList[DataIndex].FileGuid
  2392. };
  2393. videoItem.Click_refreshVideoList += LoadUploadInitData;
  2394. videoItem.Click_UploadLogin += Login;
  2395. videoItem.Width = ControlWidth;
  2396. videoItem.Height = ControlHeight;
  2397. videoItem.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
  2398. videoItem.VerticalAlignment = System.Windows.VerticalAlignment.Top;
  2399. GridMyVideo.Children.Add(videoItem);
  2400. VideoControlList.Add(videoItem);
  2401. }
  2402. videoItem.Margin = new Thickness(W, H, 0, 0);
  2403. videoItem.Visibility = Visibility.Visible;
  2404. if (W + ControlWidth + ControlWidth > pageW)
  2405. {
  2406. W = IntervalX;
  2407. H += ControlHeight + IntervalY;
  2408. }
  2409. else
  2410. {
  2411. W += ControlWidth + IntervalX;
  2412. }
  2413. //Uc_VideoItem videoItem = new Uc_VideoItem();
  2414. //return;
  2415. }
  2416. }
  2417. #region 分页
  2418. /// <summary>
  2419. /// 上一页
  2420. /// </summary>
  2421. /// <param name="sender">
  2422. /// </param>
  2423. /// <param name="e">
  2424. /// </param>
  2425. private void BtnVideoUpPage_Click(object sender, RoutedEventArgs e)
  2426. {
  2427. if (CurrentPage > 1)
  2428. {
  2429. CurrentPage--;
  2430. LoadCurrentPageData();
  2431. }
  2432. }
  2433. /// <summary>
  2434. /// 下一页
  2435. /// </summary>
  2436. /// <param name="sender">
  2437. /// </param>
  2438. /// <param name="e">
  2439. /// </param>
  2440. private void BtnVideoDownPage_Click(object sender, RoutedEventArgs e)
  2441. {
  2442. if (CurrentPage < TotalPage)
  2443. {
  2444. CurrentPage++;
  2445. LoadCurrentPageData();
  2446. }
  2447. }
  2448. #endregion 分页
  2449. #endregion 新上传 显示缩略图
  2450. #region 录屏
  2451. /// <summary>
  2452. /// 录屏事件
  2453. /// </summary>
  2454. /// <param name="sender">
  2455. /// </param>
  2456. /// <param name="e">
  2457. /// </param>
  2458. private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
  2459. {
  2460. luoBoPenUtil.lb_device_mouse();
  2461. ThreadPool.QueueUserWorkItem(o =>
  2462. {
  2463. bool microphoneGood = ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.microphone);
  2464. bool loudspeakerGood = ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.loudspeaker);
  2465. Dispatcher.Invoke(() =>
  2466. {
  2467. if (!microphoneGood)
  2468. {
  2469. MessageWindow.Show("麦克风不可用");
  2470. return;
  2471. }
  2472. if (!loudspeakerGood)
  2473. {
  2474. MessageWindow.Show("扬声器不可用");
  2475. return;
  2476. }
  2477. Record();
  2478. k_hook.Stop();
  2479. if (APP.W_ScreenRecordingToolbarWindow == null)
  2480. {
  2481. APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow
  2482. {
  2483. Topmost = true
  2484. };
  2485. APP.W_ScreenRecordingToolbarWindow.Initialize();
  2486. }
  2487. else
  2488. {
  2489. APP.W_ScreenRecordingToolbarWindow.Initialize();
  2490. }
  2491. APP.W_ScreenRecordingToolbarWindow.Click_stopRecordingScreen += W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen;
  2492. //显示在右下角
  2493. APP.W_ScreenRecordingToolbarWindow.WindowStartupLocation = WindowStartupLocation.Manual;
  2494. Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
  2495. float DIP = graphics.DpiX;
  2496. float DIPY = graphics.DpiY;
  2497. APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.WorkingArea.Width / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Width;
  2498. APP.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.WorkingArea.Height / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Height - 100;
  2499. APP.W_ScreenRecordingToolbarWindow.Topmost = true;
  2500. APP.W_ScreenRecordingToolbarWindow.Show();
  2501. Hide();
  2502. });
  2503. });
  2504. }
  2505. /// <summary>
  2506. /// 保存录屏中
  2507. /// </summary>
  2508. private void W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen()
  2509. {
  2510. TxbTime.Text = "00:00";
  2511. //TxbTime.Visibility = Visibility.Hidden;
  2512. //ImgLZImg.Visibility = Visibility.Hidden;
  2513. //TxbType.Visibility = Visibility.Visible;
  2514. TxbType.Text = "保存中";
  2515. BtnScreenRecording.IsEnabled = false;
  2516. new Thread(new ThreadStart(new Action(() =>
  2517. {
  2518. while (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath + "temprs/"))
  2519. {
  2520. Thread.Sleep(100);
  2521. }
  2522. Thread.Sleep(100);
  2523. Dispatcher.Invoke(() =>
  2524. {
  2525. BtnScreenRecording.IsEnabled = true;
  2526. TxbType.Text = "准备就绪";
  2527. //TxbType.Visibility = Visibility.Hidden;
  2528. //TxbRecordScreenWord.Text = "录屏";
  2529. });
  2530. }))).Start();
  2531. }
  2532. #endregion 录屏
  2533. #region 录制窗口
  2534. #region 变量
  2535. /// <summary>
  2536. /// 视频合成前路径名
  2537. /// </summary>
  2538. private string TempVideoPathName;
  2539. /// <summary>
  2540. /// 音频保存路径名
  2541. /// </summary>
  2542. private string TempAudioPathName;
  2543. /// <summary>
  2544. /// 视频保存路径名
  2545. /// </summary>
  2546. private string VideoSavePathName;
  2547. /// <summary>
  2548. /// 截图定时器
  2549. /// </summary>
  2550. private System.Threading.Timer timer;
  2551. /// <summary>
  2552. /// 录制计时
  2553. /// </summary>
  2554. private DateTime SRTime = DateTime.Now;
  2555. /// <summary>
  2556. /// 录制大小
  2557. /// </summary>
  2558. private int gridActWidth = 1276;
  2559. /// <summary>
  2560. /// 录制大小
  2561. /// </summary>
  2562. private int gridActHeight = 898;
  2563. /// <summary>
  2564. /// 录制类型 0停止中,1录制中,2暂停中 3倒计时
  2565. /// </summary>
  2566. private int RecordType = 0;
  2567. #endregion 变量
  2568. private bool IsPressButton = false;
  2569. /// <summary>
  2570. /// 录制窗口内容
  2571. /// </summary>
  2572. /// <param name="sender">
  2573. /// </param>
  2574. /// <param name="e">
  2575. /// </param>
  2576. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  2577. {
  2578. #region 防止连击
  2579. if (IsPressButton)
  2580. {
  2581. return;
  2582. }
  2583. else
  2584. {
  2585. IsPressButton = true;
  2586. new Thread(new ThreadStart(new Action(() =>
  2587. {
  2588. Thread.Sleep(500);
  2589. IsPressButton = false;
  2590. }))).Start();
  2591. }
  2592. #endregion 防止连击
  2593. if (APP.PageContextData.currpage == 0)
  2594. {
  2595. MessageWindow.Show("请先导入文档或截图!");
  2596. return;
  2597. }
  2598. if (RecordType == 0)
  2599. {
  2600. ThreadPool.QueueUserWorkItem(o =>
  2601. {
  2602. bool microphoneGood = ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.microphone);
  2603. Dispatcher.Invoke(() =>
  2604. {
  2605. if (!microphoneGood)
  2606. {
  2607. MessageWindow.Show("麦克风不可用");
  2608. return;
  2609. }
  2610. //停止中开始录制
  2611. RecordType = 3;
  2612. blackboard_canvas.Visibility = Visibility.Visible;
  2613. if (RectImgBorder.Visibility != Visibility.Hidden)
  2614. {
  2615. HideAngleBorder();
  2616. }
  2617. Record();
  2618. BtnPrint.IsEnabled = false;
  2619. BtnScreenshot.IsEnabled = false;
  2620. BtnImport.IsEnabled = false;
  2621. BtnScreenRecording.IsEnabled = false;
  2622. BtnUpload.IsEnabled = false;
  2623. BtnSetUp.IsEnabled = false;
  2624. BtnDevice.IsEnabled = false;
  2625. BtnLoginType.IsEnabled = false;
  2626. blackboard_canvas.Visibility = Visibility.Visible;
  2627. TxbType.Text = "准备录制";
  2628. BtnRecord.Visibility = Visibility.Collapsed;
  2629. BtnRecordSuspend.Visibility = Visibility.Visible;
  2630. BtnRecord.IsEnabled = true;
  2631. BtnStop.IsEnabled = true;
  2632. #region 录像倒计时
  2633. if (APP.W_CountdownWindow == null)
  2634. {
  2635. APP.W_CountdownWindow = new CountdownWindow();
  2636. APP.W_CountdownWindow.Initialize();
  2637. }
  2638. else
  2639. {
  2640. APP.W_CountdownWindow.Initialize();
  2641. }
  2642. APP.W_CountdownWindow.Show();
  2643. #endregion 录像倒计时
  2644. new Thread(new ThreadStart(new Action(() =>
  2645. {
  2646. Thread.Sleep(3000);
  2647. Dispatcher.Invoke(() =>
  2648. {
  2649. TxbType.Text = "正在录制";
  2650. });
  2651. RecordType = 1;
  2652. StartRecord();
  2653. }))).Start();
  2654. });
  2655. });
  2656. }
  2657. else if (RecordType == 1)
  2658. {
  2659. //录制中暂停
  2660. RecordType = 2;
  2661. }
  2662. else if (RecordType == 2)
  2663. {
  2664. //暂停中继续录制
  2665. RecordType = 1;
  2666. }
  2667. if (RecordType == 0)
  2668. {
  2669. TxbType.Text = "准备录制";
  2670. BtnRecord.Visibility = Visibility.Visible;
  2671. BtnRecordSuspend.Visibility = Visibility.Collapsed;
  2672. BtnRecord.IsEnabled = true;
  2673. BtnStop.IsEnabled = false;
  2674. }
  2675. else if (RecordType == 1)
  2676. {
  2677. TxbType.Text = "录制中";
  2678. BtnRecord.Visibility = Visibility.Collapsed;
  2679. BtnRecordSuspend.Visibility = Visibility.Visible;
  2680. }
  2681. else if (RecordType == 2)
  2682. {
  2683. TxbType.Text = "暂停中";
  2684. BtnRecord.Visibility = Visibility.Visible;
  2685. BtnRecordSuspend.Visibility = Visibility.Collapsed;
  2686. }
  2687. else if (RecordType == 3)
  2688. {
  2689. TxbType.Text = "倒计时";
  2690. }
  2691. }
  2692. /// <summary>
  2693. /// 停止录制窗口内容
  2694. /// </summary>
  2695. /// <param name="sender">
  2696. /// </param>
  2697. /// <param name="e">
  2698. /// </param>
  2699. private void BtnStop_Click(object sender, RoutedEventArgs e)
  2700. {
  2701. #region 防止连击
  2702. if (IsPressButton)
  2703. {
  2704. return;
  2705. }
  2706. else
  2707. {
  2708. IsPressButton = true;
  2709. new Thread(new ThreadStart(new Action(() =>
  2710. {
  2711. Thread.Sleep(500);
  2712. IsPressButton = false;
  2713. }))).Start();
  2714. }
  2715. #endregion 防止连击
  2716. if (RecordType != 0)
  2717. {
  2718. RecordType = 0;
  2719. blackboard_canvas.Visibility = Visibility.Collapsed;
  2720. new Thread(new ThreadStart(new Action(() =>
  2721. {
  2722. EndRecord();
  2723. }))).Start();
  2724. //鼠标模式
  2725. luoBoPenUtil.lb_device_mouse();
  2726. }
  2727. }
  2728. //视频写入
  2729. private VideoFileWriter videoWriter = new VideoFileWriter();
  2730. //录制麦克风的声音
  2731. private WaveInEvent waveIn = null; //new WaveInEvent();
  2732. //音频写入
  2733. private WaveFileWriter writer = null;
  2734. /// <summary>
  2735. /// 开始录制和暂停录制
  2736. /// </summary>
  2737. private void StartRecord()
  2738. {
  2739. //电子版切换笔模式
  2740. luoBoPenUtil.lb_device_hand();
  2741. VideoInfo = new Model_Video
  2742. {
  2743. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  2744. WkType = Enum_WKVidetype.RecordingLessons
  2745. };
  2746. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  2747. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  2748. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  2749. TempVideoPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn.avi";
  2750. int num = 1;
  2751. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  2752. {
  2753. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制_" + num + "." + VideoInfo.VideoType.ToString();
  2754. TempVideoPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn_" + num + ".avi";
  2755. num++;
  2756. }
  2757. TempAudioPathName = TempVideoPathName.Replace(".avi", ".mp3");
  2758. gridActWidth = (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f) / 2) * 2;
  2759. gridActHeight = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f) / 2) * 2;
  2760. lock (this)
  2761. {
  2762. videoWriter.Open(
  2763. TempVideoPathName,
  2764. gridActWidth,
  2765. gridActHeight,
  2766. 5,
  2767. VideoCodec.MPEG4,
  2768. gridActWidth * gridActHeight * 10
  2769. );
  2770. waveIn = new WaveInEvent();
  2771. writer = new WaveFileWriter(TempAudioPathName, waveIn.WaveFormat);
  2772. //开始录音,写数据
  2773. waveIn.DataAvailable += (s, a) =>
  2774. {
  2775. if (RecordType == 1)
  2776. {
  2777. writer.Write(a.Buffer, 0, a.BytesRecorded);
  2778. }
  2779. };
  2780. //结束录音
  2781. waveIn.RecordingStopped += (s, a) =>
  2782. {
  2783. writer.Dispose();
  2784. writer = null;
  2785. waveIn.Dispose();
  2786. };
  2787. waveIn.StartRecording();
  2788. }
  2789. Dispatcher.Invoke(() =>
  2790. {
  2791. SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
  2792. Recorddt = DateTime.Now;
  2793. });
  2794. ///启动截图
  2795. timer = new System.Threading.Timer(new TimerCallback(Timer_Elapsed), null, 0, 200);
  2796. }
  2797. /// <summary>
  2798. /// 记录上次截图时间
  2799. /// </summary>
  2800. private DateTime Recorddt = DateTime.Now;
  2801. /// <summary>
  2802. /// 录制保存图片计时器
  2803. /// </summary>
  2804. /// <param name="sender">
  2805. /// </param>
  2806. private void Timer_Elapsed(object sender)
  2807. {
  2808. if (RecordType == 1)
  2809. {
  2810. Dispatcher.Invoke(() =>
  2811. {
  2812. SRTime = SRTime.AddMilliseconds(200);
  2813. if (SRTime.Hour > 0)
  2814. {
  2815. TxbTime.Text = SRTime.ToString("HH:mm:ss");
  2816. }
  2817. else
  2818. {
  2819. TxbTime.Text = SRTime.ToString("mm:ss");
  2820. }
  2821. });
  2822. ThreadPool.QueueUserWorkItem(o =>
  2823. {
  2824. RecordSaveImage();
  2825. });
  2826. }
  2827. }
  2828. /// <summary>
  2829. /// 录制保存图片
  2830. /// </summary>
  2831. private void RecordSaveImage()
  2832. {
  2833. try
  2834. {
  2835. //保存图片
  2836. try
  2837. {
  2838. Dispatcher.Invoke(() =>
  2839. {
  2840. Bitmap bm = ImageHelper.SaveUI2Bitmap(GridMain, gridActWidth, gridActHeight);
  2841. videoWriter.WriteVideoFrame(bm);
  2842. bm.Dispose();
  2843. });
  2844. }
  2845. catch (Exception e)
  2846. {
  2847. Console.WriteLine(e.Message);
  2848. }
  2849. }
  2850. catch (Exception ex)
  2851. {
  2852. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  2853. }
  2854. }
  2855. /// <summary>
  2856. /// 停止录制并生成录制文件
  2857. /// </summary>
  2858. private void EndRecord()
  2859. {
  2860. #region 恢复被禁用的按钮
  2861. Dispatcher.Invoke(() =>
  2862. {
  2863. //打印按钮不恢复
  2864. //BtnPrint.IsEnabled = true;
  2865. BtnScreenshot.IsEnabled = true;
  2866. BtnImport.IsEnabled = true;
  2867. BtnScreenRecording.IsEnabled = true;
  2868. BtnUpload.IsEnabled = true;
  2869. BtnSetUp.IsEnabled = true;
  2870. BtnDevice.IsEnabled = true;
  2871. BtnLoginType.IsEnabled = true;
  2872. //btnStop.IsEnabled = false;//停止录制按钮不可点击
  2873. });
  2874. #endregion 恢复被禁用的按钮
  2875. try
  2876. {
  2877. #region 清空画板数据
  2878. Dispatcher.Invoke(() =>
  2879. {
  2880. APP.PageContextData.currpage = 0;
  2881. APP.PageContextData.pagenum = 0;
  2882. myblackboard.clear();
  2883. APP.PageDrawList.Clear();
  2884. imgCanvas.Source = null;
  2885. imgDocumentation.Source = null;
  2886. imgPPT.Source = null;
  2887. GridPage.Visibility = Visibility.Collapsed;
  2888. });
  2889. #endregion 清空画板数据
  2890. Dispatcher.Invoke(() =>
  2891. {
  2892. BtnRecord.IsEnabled = false;
  2893. BtnStop.IsEnabled = false;
  2894. BtnScreenRecording.IsEnabled = false;
  2895. });
  2896. //缩略图
  2897. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  2898. FileToolsCommon.CreateDirectory(ThumbnailPath);
  2899. //缩略图存储位置
  2900. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
  2901. videoWriter.Close();
  2902. waveIn.StopRecording();
  2903. //停止截图
  2904. Dispatcher.Invoke(() =>
  2905. {
  2906. timer.Change(-1, 0);
  2907. timer.Dispose();
  2908. TxbTime.Text = "00:00";
  2909. TxbType.Text = "保存中";
  2910. });
  2911. FileToolsCommon.DeleteFile(ThumbnailPathName);
  2912. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2913. VideoInfo.VideoPath = VideoSavePathName;
  2914. VideoInfo.ThumbnailPath = ThumbnailPathName;
  2915. Console.WriteLine("生成缩略图");
  2916. Console.WriteLine("合并音视频 gridActWidth:" + gridActWidth + " gridActHeight:" + gridActHeight);
  2917. //APP.FFmpeg.VideoAudioMerge(VideoSynthesisPathName, AudioPathName, VideoSavePathName, gridActWidth, gridActHeight);
  2918. FFMpegConverter ffMpeg = new FFMpegConverter();
  2919. //ffMpeg.ConvertProgress += FfMpeg_ConvertProgress;
  2920. FFMpegInput[] input = new FFMpegInput[] {
  2921. new FFMpegInput(TempVideoPathName),
  2922. new FFMpegInput(TempAudioPathName)
  2923. };
  2924. // 音视频合并
  2925. ffMpeg.ConvertMedia(
  2926. input,
  2927. VideoSavePathName,
  2928. "mp4",
  2929. new OutputSettings() { }
  2930. );
  2931. //生成缩略图
  2932. bool ThuRes = APP.FFmpeg.GenerateThumbnails(TempVideoPathName, ThumbnailPathName, 200, 130);
  2933. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  2934. VideoInfo.IsUpload = false;
  2935. VideoInfo.Uploaded = 0;
  2936. if (!APP.VideoList.Exists(x => x.FileGuid == VideoInfo.FileGuid) || !APP.VideoList.Exists(x => x.VideoPath == VideoInfo.VideoPath))
  2937. {
  2938. APP.VideoList.Add(VideoInfo);
  2939. //保存数据
  2940. APP.SaveWkData();
  2941. }
  2942. FileToolsCommon.DeleteFile(TempVideoPathName);
  2943. FileToolsCommon.DeleteFile(TempAudioPathName);
  2944. Dispatcher.Invoke(() =>
  2945. {
  2946. BtnRecord.IsEnabled = true;
  2947. BtnStop.IsEnabled = false;
  2948. BtnPrint.IsEnabled = false;
  2949. BtnScreenRecording.IsEnabled = true;
  2950. TxbType.Text = "准备就绪";
  2951. BtnRecord.Visibility = Visibility.Visible;
  2952. BtnRecordSuspend.Visibility = Visibility.Collapsed;
  2953. });
  2954. }
  2955. catch (Exception ex)
  2956. {
  2957. Dispatcher.Invoke(() =>
  2958. {
  2959. MessageWindow.Show(ex.Message);
  2960. });
  2961. }
  2962. }
  2963. #endregion 录制窗口
  2964. #region 分页
  2965. /// 上一页 </summary> <param name="sender"></param> <param name="e"></param>
  2966. private void last_button_Click(object sender, RoutedEventArgs e)
  2967. {
  2968. if (APP.PageContextData.currpage > 1)
  2969. {
  2970. mouseDown = false;
  2971. imageOperationUtil.setMouseDown(mouseDown);
  2972. HideAngleBorder();
  2973. APP.PageContextData.currpage -= 1;
  2974. JumpPageClick();
  2975. }
  2976. }
  2977. /// <summary>
  2978. /// 下一页
  2979. /// </summary>
  2980. /// <param name="sender">
  2981. /// </param>
  2982. /// <param name="e">
  2983. /// </param>
  2984. private void next_btn_Click(object sender, RoutedEventArgs e)
  2985. {
  2986. if (APP.PageContextData.currpage < APP.PageContextData.pagenum)
  2987. {
  2988. mouseDown = false;
  2989. imageOperationUtil.setMouseDown(mouseDown);
  2990. HideAngleBorder();
  2991. APP.PageContextData.currpage += 1;
  2992. JumpPageClick();
  2993. }
  2994. }
  2995. /// <summary>
  2996. /// 跳转
  2997. /// </summary>
  2998. private void JumpPageClick()
  2999. {
  3000. myblackboard.changepage(APP.PageContextData.currpage - 1);
  3001. ScroMain.ScrollToVerticalOffset(0);
  3002. if (BtnImport.IsEnabled)
  3003. {
  3004. ///截图可用
  3005. BtnScreenshot.IsEnabled = true;
  3006. }
  3007. if (APP.PageContextData.currpage <= APP.PageDrawList.Count)
  3008. {
  3009. if (APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation != null)
  3010. {
  3011. APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = true;
  3012. }
  3013. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.PageContextData.currpage <= APP.PageDrawList.Count && APP.PageContextData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath))
  3014. {
  3015. if (APP.PageDrawList[APP.PageContextData.currpage - 1].ImgDocumentation)
  3016. {
  3017. if ("ppt".Equals(APP.PageDrawList[APP.PageContextData.currpage - 1].Type))
  3018. {
  3019. imgCanvas.Source = null;
  3020. imgDocumentation.Source = null;
  3021. imgPPT.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
  3022. BtnScreenshot.IsEnabled = false;
  3023. }
  3024. else
  3025. {
  3026. imgPPT.Source = null;
  3027. imgCanvas.Source = null;
  3028. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
  3029. BtnScreenshot.IsEnabled = false;
  3030. }
  3031. }
  3032. else
  3033. {
  3034. imgPPT.Source = null;
  3035. imgDocumentation.Source = null;
  3036. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
  3037. APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = false;
  3038. if (APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation.X > 0)
  3039. {
  3040. mouseDown = false;
  3041. imageOperationUtil.setMouseDown(mouseDown);
  3042. ImgXY();
  3043. }
  3044. }
  3045. }
  3046. else
  3047. {
  3048. imgPPT.Source = null;
  3049. imgCanvas.Source = null;
  3050. imgDocumentation.Source = null;
  3051. }
  3052. }
  3053. }
  3054. private void ImgXY()
  3055. {
  3056. imgCanvas.Width = APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes.CenterX;
  3057. imgCanvas.Height = APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes.CenterY;
  3058. imgCanvas.Margin = new Thickness(APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation.X, APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation.Y, 0, 0);
  3059. }
  3060. #endregion 分页
  3061. #region 图像缩放,移动
  3062. private bool mouseDown;
  3063. private System.Windows.Point mouseXY;
  3064. private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  3065. {
  3066. ContentControl img = sender as ContentControl;
  3067. if (img == null)
  3068. {
  3069. return;
  3070. }
  3071. img.CaptureMouse();
  3072. mouseDown = true;
  3073. imageOperationUtil.setMouseDown(mouseDown);
  3074. mouseXY = e.GetPosition(img);
  3075. //Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
  3076. }
  3077. private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  3078. {
  3079. ContentControl img = sender as ContentControl;
  3080. if (img == null)
  3081. {
  3082. return;
  3083. }
  3084. img.ReleaseMouseCapture();
  3085. mouseDown = false;
  3086. imageOperationUtil.setMouseDown(mouseDown);
  3087. }
  3088. private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  3089. {
  3090. ContentControl img = sender as ContentControl;
  3091. if (img == null)
  3092. {
  3093. return;
  3094. }
  3095. if (mouseDown)
  3096. {
  3097. Domousemove(img, e);
  3098. }
  3099. }
  3100. /// <summary>
  3101. /// x y轴
  3102. /// </summary>
  3103. /// <param name="img">
  3104. /// </param>
  3105. /// <param name="e">
  3106. /// </param>
  3107. private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
  3108. {
  3109. if (e.LeftButton != MouseButtonState.Pressed)
  3110. {
  3111. return;
  3112. }
  3113. if (APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation)
  3114. {
  3115. return;
  3116. }
  3117. TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
  3118. TranslateTransform transform = group.Children[1] as TranslateTransform;
  3119. System.Windows.Point position = e.GetPosition(img);
  3120. transform.X -= mouseXY.X - position.X;
  3121. transform.Y -= mouseXY.Y - position.Y;
  3122. mouseXY = position;
  3123. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
  3124. {
  3125. X = transform.X,
  3126. Y = transform.Y
  3127. };
  3128. }
  3129. private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
  3130. {
  3131. ContentControl img = sender as ContentControl;
  3132. if (img == null)
  3133. {
  3134. return;
  3135. }
  3136. System.Windows.Point point = e.GetPosition(img);
  3137. System.Windows.Point PicLocate = e.GetPosition(imgCanvas);
  3138. TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
  3139. double delta = e.Delta * 0.001;
  3140. DowheelZoom(group, point, delta);
  3141. }
  3142. private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
  3143. {
  3144. System.Windows.Point pointToContent = group.Inverse.Transform(point);
  3145. ScaleTransform transform = group.Children[0] as ScaleTransform;
  3146. if (transform.ScaleX + delta < 0.1)
  3147. {
  3148. return;
  3149. }
  3150. transform.ScaleX += delta;
  3151. transform.ScaleY += delta;
  3152. TranslateTransform transform1 = group.Children[1] as TranslateTransform;
  3153. transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
  3154. transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
  3155. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
  3156. {
  3157. X = transform1.X,
  3158. Y = transform1.Y
  3159. };
  3160. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
  3161. {
  3162. CenterX = imgCanvas.ActualWidth,
  3163. CenterY = imgCanvas.ActualHeight
  3164. };
  3165. APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = false;
  3166. }
  3167. #endregion 图像缩放,移动
  3168. #region 更改设备连接状态
  3169. /// <summary>
  3170. /// 更新设备状态显示
  3171. /// </summary>
  3172. public void UpdateDevStatus()
  3173. {
  3174. if (APP.BoardStatus && (APP.PenStatus || APP.TQLPenStatus))
  3175. {
  3176. Dispatcher.Invoke(new Action(() =>
  3177. {
  3178. txbNotConnected.Text = "笔/板已连接";
  3179. txbNotConnecteds.Text = "笔/板已连接";
  3180. }));
  3181. }
  3182. else if (APP.BoardStatus)
  3183. {
  3184. Dispatcher.Invoke(new Action(() =>
  3185. {
  3186. txbNotConnected.Text = "手写板已连接";
  3187. txbNotConnecteds.Text = "手写板已连接";
  3188. }));
  3189. }
  3190. else if (APP.PenStatus)
  3191. {
  3192. Dispatcher.Invoke(new Action(() =>
  3193. {
  3194. txbNotConnected.Text = "智能笔已连接";
  3195. txbNotConnecteds.Text = "智能笔已连接";
  3196. }));
  3197. }
  3198. else if (APP.TQLPenStatus)
  3199. {
  3200. Dispatcher.Invoke(new Action(() =>
  3201. {
  3202. txbNotConnected.Text = "智能笔已连接";
  3203. txbNotConnecteds.Text = "智能笔已连接";
  3204. }));
  3205. }
  3206. else
  3207. {
  3208. Dispatcher.Invoke(new Action(() =>
  3209. {
  3210. txbNotConnected.Text = "未连接";
  3211. txbNotConnecteds.Text = "未连接";
  3212. }));
  3213. }
  3214. }
  3215. #endregion 更改设备连接状态
  3216. #region 腾千里手写笔
  3217. /// <summary>
  3218. /// 是否在书写
  3219. /// </summary>
  3220. private bool isTQLPenDown = false;
  3221. /// <summary>
  3222. /// TQL点阵笔宽高
  3223. /// </summary>
  3224. 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
  3225. 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;
  3226. /// <summary>
  3227. /// TQL初始化
  3228. /// </summary>
  3229. public void InitTQLPPen()
  3230. {
  3231. if (APP.TQLPenevents == null)
  3232. {
  3233. APP.TQLPenevents = new PenEvents(1);
  3234. }
  3235. else
  3236. {
  3237. APP.TQLPenevents.InToType = 1;
  3238. }
  3239. }
  3240. /// <summary>
  3241. /// 笔落下
  3242. /// </summary>
  3243. public void TQLDown()
  3244. {
  3245. isTQLPenDown = true;
  3246. if (APP.PageContextData.currpage > 0)
  3247. {
  3248. Dispatcher.Invoke(new Action(() =>
  3249. {
  3250. myblackboard.changepages(0, 0, true, Color, PenSize, APP.PageContextData.currpage - 1, 0);
  3251. }));
  3252. }
  3253. }
  3254. /// <summary>
  3255. /// 笔抬起
  3256. /// </summary>
  3257. public void TQLUp()
  3258. {
  3259. isTQLPenDown = false;
  3260. //stroke.Clear();
  3261. if (APP.PageContextData.currpage > 0)
  3262. {
  3263. Dispatcher.Invoke(new Action(() =>
  3264. {
  3265. myblackboard.changepages(0, 0, true, Color, PenSize, APP.PageContextData.currpage - 1, 0);
  3266. }));
  3267. }
  3268. }
  3269. /// <summary>
  3270. /// 笔书写
  3271. /// </summary>
  3272. /// <param name="cx">
  3273. /// </param>
  3274. /// <param name="cy">
  3275. /// </param>
  3276. /// <param name="force">
  3277. /// </param>
  3278. public void TQLPenWrite(double cx, double cy, int force)
  3279. {
  3280. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  3281. if (!isTQLPenDown)
  3282. {
  3283. return;
  3284. }
  3285. double PropW = blackboard_canvas.ActualWidth / TQLA4_WIDTH;
  3286. double PropH = blackboard_canvas.ActualHeight / TQLA4_HEIGHT;
  3287. //点
  3288. double tempX = cx * PropW;
  3289. double tempY = cy * PropH;
  3290. if (APP.PageContextData.currpage > 0)
  3291. {
  3292. Dispatcher.Invoke(new Action(() =>
  3293. {
  3294. //0~1023,亦即有 1024 阶供应用软件后续应用之用,如笔锋笔触,暂无用
  3295. float Pressure = (float)force / 1023f;
  3296. myblackboard.changepages(tempX, tempY, false, Color, PenSize, APP.PageContextData.currpage - 1, Pressure);
  3297. #region 设置滚动条位置
  3298. //点在显示页面上方
  3299. if (tempY < ScroMain.VerticalOffset)
  3300. {
  3301. //滚动条当前位置
  3302. double RollCurrentLocation = ScroMain.VerticalOffset;
  3303. //向上滚动至以点为中心需要滚动的距离
  3304. double UpRoll = (RollCurrentLocation - tempY) + (ScroMain.ActualHeight / 2);
  3305. //如果小于0则等于0
  3306. double RollLocation = RollCurrentLocation - UpRoll;
  3307. if (RollLocation < 0)
  3308. {
  3309. RollLocation = 0;
  3310. }
  3311. ////滚动条实际偏移量
  3312. //double RollOffset = RollCurrentLocation - RollLocation;
  3313. ScroMain.ScrollToVerticalOffset(RollLocation);
  3314. }
  3315. //点在显示页面下方
  3316. if (tempY > ScroMain.VerticalOffset + ScroMain.ActualHeight)
  3317. {
  3318. //滚动条当前位置
  3319. double RollCurrentLocation = ScroMain.VerticalOffset;
  3320. //向下滚动至以点为中心需要滚动的距离
  3321. double DownRoll = (tempY - RollCurrentLocation) - (ScroMain.ActualHeight / 2);
  3322. //如果小于0则等于0
  3323. double RollLocation = RollCurrentLocation + DownRoll;
  3324. //滚动条最大滚动值
  3325. double ScrollbarMaxNum = GridM.ActualHeight - ScroMain.ActualHeight;
  3326. if (RollLocation > ScrollbarMaxNum)
  3327. {
  3328. RollLocation = ScrollbarMaxNum;
  3329. }
  3330. ////滚动条实际偏移量
  3331. //double RollOffset = RollLocation-RollCurrentLocation;
  3332. ScroMain.ScrollToVerticalOffset(RollLocation);
  3333. }
  3334. #endregion 设置滚动条位置
  3335. if (tempX > 0 && tempY > 0)
  3336. {
  3337. System.Windows.Point getP = ScroMain.PointToScreen(new System.Windows.Point(tempX, tempY - ScroMain.VerticalOffset));
  3338. SetCursorPos((int)getP.X, (int)getP.Y);
  3339. }
  3340. }));
  3341. }
  3342. }
  3343. #endregion 腾千里手写笔
  3344. #region 图片拉伸移动
  3345. /// <summary>
  3346. /// 隐藏图片四个点和线
  3347. /// </summary>
  3348. private void HideAngleBorder()
  3349. {
  3350. imageOperationUtil.HideAngleBorder();
  3351. }
  3352. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  3353. {
  3354. imageOperationUtil.PicEMap_MouseDown(sender, e);
  3355. }
  3356. private void imgCanvas_MouseMove(object sender, MouseEventArgs e)
  3357. {
  3358. imageOperationUtil.imgCanvas_MouseMove(sender,e);
  3359. }
  3360. private void imgCanvas_MouseUp(object sender, MouseButtonEventArgs e)
  3361. {
  3362. imageOperationUtil.imgCanvas_MouseUp();
  3363. }
  3364. private void RectRightUp_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
  3365. {
  3366. imageOperationUtil.RectRightUp_DragStarted(sender, e);
  3367. }
  3368. private void RectRightUp_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
  3369. {
  3370. imageOperationUtil.RectRightUp_DragDelta(sender, e);
  3371. }
  3372. private void RectRightUp_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
  3373. {
  3374. imageOperationUtil.RectRightUp_DragCompleted();
  3375. }
  3376. /// <summary>
  3377. /// 点击标题栏 隐藏截图的四个点和线
  3378. /// </summary>
  3379. /// <param name="sender">
  3380. /// </param>
  3381. /// <param name="e">
  3382. /// </param>
  3383. private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
  3384. {
  3385. imageOperationUtil.Grid_MouseDown();
  3386. }
  3387. /// <summary>
  3388. /// 鼠标左键点击事件
  3389. /// </summary>
  3390. /// <param name="sender">
  3391. /// </param>
  3392. /// <param name="e">
  3393. /// </param>
  3394. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  3395. {
  3396. imageOperationUtil.Window_MouseLeftButtonDown_1();
  3397. }
  3398. #endregion 图片拉伸移动
  3399. #region 录屏 录制 截图 导入文档 增加 主页面显示
  3400. /// <summary>
  3401. /// 录屏 录制 截图 导入文档 增加 主页面显示
  3402. /// </summary>
  3403. private void Record()
  3404. {
  3405. PageHide();
  3406. GridMain.Visibility = Visibility.Visible;
  3407. GridRecordingTitle.Visibility = Visibility.Visible;
  3408. if (APP.PageContextData.pagenum > 0)
  3409. {
  3410. GridPage.Visibility = Visibility.Visible;
  3411. }
  3412. DataContext = APP.PageContextData;
  3413. }
  3414. #endregion 录屏 录制 截图 导入文档 增加 主页面显示
  3415. #region 页码跳转
  3416. /// <summary>
  3417. /// 确定跳转
  3418. /// </summary>
  3419. /// <param name="sender">
  3420. /// </param>
  3421. /// <param name="e">
  3422. /// </param>
  3423. private void BtnJumpPage_Click(object sender, RoutedEventArgs e)
  3424. {
  3425. int JumpPage = 0;
  3426. if (JumpPage < 1)
  3427. {
  3428. JumpPage = 1;
  3429. }
  3430. if (JumpPage > int.Parse(txbTotalpage.Text))
  3431. {
  3432. JumpPage = int.Parse(txbTotalpage.Text);
  3433. }
  3434. #region 跳转
  3435. APP.PageContextData.currpage = JumpPage;
  3436. JumpPageClick();
  3437. #endregion 跳转
  3438. }
  3439. /// <summary>
  3440. /// 只允许输入数字
  3441. /// </summary>
  3442. /// <param name="sender">
  3443. /// </param>
  3444. /// <param name="e">
  3445. /// </param>
  3446. private void txtJump_PreviewTextInput(object sender, TextCompositionEventArgs e)
  3447. {
  3448. Regex re = new Regex("[^0-9.-]+");
  3449. e.Handled = re.IsMatch(e.Text);
  3450. }
  3451. private void txtJump_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  3452. {
  3453. if (e.Key == Key.Enter)
  3454. {
  3455. BtnJumpPage_Click(null, null);
  3456. }
  3457. }
  3458. #endregion 页码跳转
  3459. #region TQL打印
  3460. /// <summary>
  3461. /// 授权文件位置
  3462. /// </summary>
  3463. private string TQLAuthorizationPath;
  3464. /// <summary>
  3465. /// 授权码
  3466. /// </summary>
  3467. private string gKeyStr;
  3468. private TmatrixClass TMC = new TmatrixClass();
  3469. public static string gPrintFileName;
  3470. private bool gbInitDone = false;
  3471. private iTextSharp.text.Document document;
  3472. /// <summary>
  3473. /// TQL初始化打印
  3474. /// </summary>
  3475. private void TQLPrintInit()
  3476. {
  3477. ///初始化
  3478. if (TMC.TmatrixInitialize() == false)
  3479. {
  3480. }
  3481. else
  3482. {
  3483. gbInitDone = true;
  3484. }
  3485. document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0);
  3486. try
  3487. {
  3488. TQLAuthorizationPath = FileToolsCommon.GetFileAbsolutePath("/LatticeXML/S0_O000_B0000_P000-255.tmx");
  3489. StreamReader gsr = new StreamReader(TQLAuthorizationPath);
  3490. gKeyStr = gsr.ReadLine();
  3491. gsr.Close();
  3492. string KeyCheckResult = TMC.TmatrixKeyCheck_OID4(gKeyStr);
  3493. if (KeyCheckResult.Substring(0, 1) == "1")
  3494. {
  3495. MessageWindow.Show("打印服务授权过期,请联系厂家更换授权!");
  3496. LogHelper.WriteErrLog("打印服务授权过期:" + KeyCheckResult, null);
  3497. gbInitDone = false;
  3498. }
  3499. else if (KeyCheckResult.Substring(0, 1) == "0")
  3500. {
  3501. }
  3502. }
  3503. catch (Exception ex)
  3504. {
  3505. LogHelper.WriteErrLog("打印服务授权失败:" + ex.Message, ex);
  3506. MessageWindow.Show("打印服务授权失败,请联系厂家!");
  3507. gbInitDone = false;
  3508. }
  3509. }
  3510. /// <summary>
  3511. /// 铺码
  3512. /// </summary>
  3513. private bool GenerateCode(string PDFPath)
  3514. {
  3515. try
  3516. {
  3517. if (gbInitDone == false)
  3518. {
  3519. MessageWindow.Show("打印功能无法使用,无效授权。");
  3520. return false;
  3521. }
  3522. try
  3523. {
  3524. string directoryPath = FileToolsCommon.GetDirectoryName(PDFPath);
  3525. FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Images/");
  3526. FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Vector Images/");
  3527. FileToolsCommon.DeleteDirectory(directoryPath + "Bg without Vector Images/");
  3528. FileToolsCommon.DeleteDirectory(directoryPath + "Vector Images/");
  3529. }
  3530. catch (Exception)
  3531. {
  3532. }
  3533. PDFPath = PDFPath.Replace("/", "\\");
  3534. //初始页
  3535. bool[] bPublishImageType = new bool[4];
  3536. bPublishImageType[0] = false;
  3537. bPublishImageType[1] = false;
  3538. bPublishImageType[2] = false;
  3539. bPublishImageType[3] = true;
  3540. int[] gPointType = { 0, 0, 0, 0, 1 };
  3541. int[] gPointDPI = { 0, 0, 0, 0, 1 };
  3542. string sGenerateResult = TMC.GenerateTmatrixCode_OID4(
  3543. gKeyStr,
  3544. PDFPath,
  3545. 0,
  3546. gPointType,
  3547. bPublishImageType,
  3548. gPointDPI
  3549. );
  3550. if (sGenerateResult.Substring(0, 1) == "1")
  3551. {
  3552. Dispatcher.Invoke(() =>
  3553. {
  3554. MessageWindow.Show("打印功能无法使用,无效授权。");
  3555. });
  3556. return false;
  3557. }
  3558. return true;
  3559. }
  3560. catch (Exception ex)
  3561. {
  3562. Dispatcher.Invoke(() =>
  3563. {
  3564. MessageWindow.Show("打印失败:" + ex.Message);
  3565. });
  3566. return false;
  3567. }
  3568. }
  3569. #endregion TQL打印
  3570. #region 打印界面
  3571. /// <summary>
  3572. /// 下拉框数据源
  3573. /// </summary>
  3574. public DataTable printlist = new DataTable();
  3575. private DataTable dtComponentsUniqueNo;
  3576. /// <summary>
  3577. /// 打印进度
  3578. /// </summary>
  3579. private System.Timers.Timer timesPrint;
  3580. /// <summary>
  3581. /// 打印消息
  3582. /// </summary>
  3583. private System.Timers.Timer timesPrintMsg;
  3584. private double wit = 0;
  3585. private double hei = 0;
  3586. /// <summary>
  3587. /// 打印状态消息
  3588. /// </summary>
  3589. private string PrintMsg = "打印中";
  3590. /// <summary>
  3591. /// 打印初始化
  3592. /// </summary>
  3593. public void InitPrint()
  3594. {
  3595. ResizeMode = ResizeMode.NoResize;
  3596. List<string> defaList = ZPrintUtils.GetLocalPrinters();
  3597. if (defaList.Count > 0)
  3598. {
  3599. printlist.Columns.Add("Value");
  3600. printlist.Columns.Add("Key");
  3601. for (int i = 0; i < defaList.Count; i++)
  3602. {
  3603. //创建一行
  3604. DataRow row = printlist.NewRow();
  3605. //将此行添加到table中
  3606. printlist.Rows.Add(row);
  3607. printlist.Rows[i]["Value"] = defaList[i];
  3608. printlist.Rows[i]["Key"] = i.ToString();
  3609. }
  3610. dtComponentsUniqueNo = printlist.DefaultView.ToTable();
  3611. cmbClass.ItemsSource = dtComponentsUniqueNo.DefaultView;
  3612. cmbClass.SelectedIndex = 0;
  3613. }
  3614. TQLPrintInit();
  3615. }
  3616. /// <summary>
  3617. /// 初始化页面
  3618. /// </summary>
  3619. /// <param name="_imgPath">
  3620. /// </param>
  3621. /// <param name="_wit">
  3622. /// </param>
  3623. /// <param name="_hei">
  3624. /// </param>
  3625. public void InitializePrint(string _imgPath, double _wit, double _hei)
  3626. {
  3627. wit = _wit;
  3628. hei = _hei;
  3629. if (!string.IsNullOrWhiteSpace(_imgPath))
  3630. {
  3631. imgPri.Source = new BitmapImage(new Uri(_imgPath));
  3632. }
  3633. else
  3634. {
  3635. imgPri.Source = null;
  3636. }
  3637. GridPrintMask.Visibility = Visibility.Collapsed;
  3638. }
  3639. private int msgnum = 0;
  3640. /// <summary>
  3641. /// 消息
  3642. /// </summary>
  3643. /// <param name="sender">
  3644. /// </param>
  3645. /// <param name="e">
  3646. /// </param>
  3647. private void TimesPrintMsg_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  3648. {
  3649. if (msgnum > 5)
  3650. msgnum = 0;
  3651. else
  3652. msgnum++;
  3653. string point = "";
  3654. point = point.ToString().PadRight(msgnum, '.');
  3655. Dispatcher.Invoke(() =>
  3656. {
  3657. LabPrintMessage.Content = PrintMsg + point;
  3658. });
  3659. }
  3660. private int num = 0;
  3661. /// <summary>
  3662. /// 计时器
  3663. /// </summary>
  3664. /// <param name="sender">
  3665. /// </param>
  3666. /// <param name="e">
  3667. /// </param>
  3668. private void Times_ElapsedClick(object sender, System.Timers.ElapsedEventArgs e)
  3669. {
  3670. Dispatcher.Invoke(() =>
  3671. {
  3672. pgbProcess.Value = num;
  3673. lbProcess.Content = num.ToString() + "%";
  3674. if (num < 99)
  3675. {
  3676. num++;
  3677. timesPrint.Interval += (num / 2);
  3678. }
  3679. else
  3680. {
  3681. timesPrint.Stop();
  3682. }
  3683. });
  3684. }
  3685. /// <summary>
  3686. /// 开始打印
  3687. /// </summary>
  3688. private void StartPrint(PrintModel printModel)
  3689. {
  3690. try
  3691. {
  3692. document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0f, 0f, 0f, 0f);
  3693. PrintMsg = "生成文件";
  3694. msgnum = 0;
  3695. string SourcePath1 = printModel.filepath;
  3696. try
  3697. {
  3698. SourcePath1 = SourcePath1.Replace("/", "\\");
  3699. FileStream fs = new FileStream(SourcePath1, FileMode.Create, FileAccess.ReadWrite);
  3700. document.AddAuthor("星火微课");//作者
  3701. document.AddCreationDate();//创建时候
  3702. document.AddCreator("星火微课");//创建者
  3703. document.AddSubject("点阵文件");//主题
  3704. document.AddTitle("PrintTmatrixCode");//标题
  3705. document.AddKeywords("Print");
  3706. document.AddHeader("TmatrixCode", "0");
  3707. iTextSharp.text.pdf.PdfWriter.GetInstance(document, fs);
  3708. }
  3709. catch (Exception)
  3710. {
  3711. }
  3712. document.Open();
  3713. iTextSharp.text.Image image;
  3714. for (int i = 0; i < APP.PageDrawList.Count; i++)
  3715. {
  3716. long ii = Timestamp();
  3717. string directoryPath = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  3718. string filePathOutPut = Path.Combine(directoryPath, string.Format("print{0}{1}.jpg", ii, i));
  3719. RectangleF rectangleFs = new RectangleF();
  3720. MergerPrintImg("", filePathOutPut, rectangleFs, out string errmsg);
  3721. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  3722. if (string.IsNullOrEmpty(APP.PageDrawList[i].PageImagePath))//没有图片
  3723. {
  3724. }
  3725. else if (APP.PageDrawList[i].ImgDocumentation == true && !APP.PageDrawList[i].Type.Equals("ppt"))
  3726. {
  3727. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  3728. }
  3729. else
  3730. {
  3731. RectangleF rectangleF = new RectangleF(0, 0, 0, 0);
  3732. Dispatcher.Invoke(() =>
  3733. {
  3734. rectangleF = new RectangleF
  3735. {
  3736. Width = (float)APP.PageDrawList[i].ImageSizes.CenterX,
  3737. Height = (float)APP.PageDrawList[i].ImageSizes.CenterY,
  3738. X = (float)APP.PageDrawList[i].ImageLocation.X,
  3739. Y = (float)APP.PageDrawList[i].ImageLocation.Y
  3740. };
  3741. });
  3742. string msgs = string.Empty;
  3743. bool isImg = MergerPrintImg(APP.PageDrawList[i].PageImagePath, filePathOutPut, rectangleF, out msgs);
  3744. if (isImg)
  3745. {
  3746. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  3747. }
  3748. else
  3749. {
  3750. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  3751. }
  3752. }
  3753. if (image.Height > iTextSharp.text.PageSize.A4.Height)
  3754. {
  3755. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  3756. }
  3757. else if (image.Width > iTextSharp.text.PageSize.A4.Width)
  3758. {
  3759. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  3760. }
  3761. image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
  3762. document.NewPage();
  3763. document.Add(image);
  3764. }
  3765. document.Close();
  3766. }
  3767. catch (Exception ex)
  3768. {
  3769. Dispatcher.Invoke(() =>
  3770. {
  3771. BtnPrint.IsEnabled = true;
  3772. timesPrint.Stop();
  3773. timesPrintMsg.Stop();
  3774. GridPrintMask.Visibility = Visibility.Collapsed;
  3775. MessageWindow.Show(ex.Message);
  3776. return;
  3777. });
  3778. LogHelper.WriteErrLog("打印转换PDF失败,原因:" + ex.Message, ex);
  3779. }
  3780. //PDF位置
  3781. string SourcePath = printModel.filepath;
  3782. int PrinterNum = printModel.num;
  3783. string PrinterName = printModel.printname;
  3784. if (isHasCode)
  3785. {
  3786. PrintMsg = "铺码中";
  3787. msgnum = 0;
  3788. Thread.Sleep(500);
  3789. //腾千里生成点阵文件
  3790. if (GenerateCode(SourcePath))
  3791. {
  3792. //打印机名称
  3793. string directoryPath = FileToolsCommon.GetDirectoryName(SourcePath) + "Bg with Images/";
  3794. string[] strs = FileToolsCommon.GetFileNames(directoryPath);
  3795. try
  3796. {
  3797. // 腾千里会根据原PDF的页数生成多个PDF文件
  3798. for (int i = 0; i < strs.Count(); i++)
  3799. {
  3800. timesPrint.Stop();
  3801. PrintMsg = "正在打印第" + (i + 1) + "/" + strs.Count() + "页中";
  3802. msgnum = 0;
  3803. num = 0;
  3804. timesPrint.Interval = 100;
  3805. timesPrint.Start();
  3806. string fileName = strs[i];
  3807. //打印文件
  3808. ZPrintUtils.Print(fileName, PrinterName);
  3809. }
  3810. Dispatcher.Invoke(() =>
  3811. {
  3812. BtnPrint.IsEnabled = true;
  3813. num = 99;
  3814. timesPrint.Stop();
  3815. pgbProcess.Value = 100;
  3816. lbProcess.Content = "100%";
  3817. GridPrintMask.Visibility = Visibility.Collapsed;
  3818. //MessageWindow.Show("已加入打印机队列,打印中。");
  3819. });
  3820. }
  3821. catch (Exception ex)
  3822. {
  3823. Dispatcher.Invoke(() =>
  3824. {
  3825. MessageWindow.Show("打印失败:" + ex.Message);
  3826. BtnPrint.IsEnabled = true;
  3827. timesPrint.Stop();
  3828. GridPrintMask.Visibility = Visibility.Collapsed;
  3829. return;
  3830. });
  3831. }
  3832. }
  3833. else
  3834. {
  3835. Dispatcher.Invoke(() =>
  3836. {
  3837. BtnPrint.IsEnabled = true;
  3838. timesPrint.Stop();
  3839. timesPrintMsg.Stop();
  3840. GridPrintMask.Visibility = Visibility.Collapsed;
  3841. return;
  3842. });
  3843. }
  3844. }
  3845. else
  3846. {
  3847. //打印文件
  3848. ZPrintUtils.Print(SourcePath, PrinterName);
  3849. Dispatcher.Invoke(() =>
  3850. {
  3851. BtnPrint.IsEnabled = true;
  3852. num = 99;
  3853. timesPrint.Stop();
  3854. pgbProcess.Value = 100;
  3855. lbProcess.Content = "100%";
  3856. GridPrintMask.Visibility = Visibility.Collapsed;
  3857. //MessageWindow.Show("已加入打印机队列,打印中。");
  3858. });
  3859. }
  3860. }
  3861. /// <summary>
  3862. /// 生成图片
  3863. /// </summary>
  3864. /// <param name="_path">
  3865. /// 图片地址
  3866. /// </param>
  3867. /// <param name="_saveimg">
  3868. /// 保存位置
  3869. /// </param>
  3870. /// <param name="_rectangle">
  3871. /// 图片位置
  3872. /// </param>
  3873. /// <param name="errmsg">
  3874. /// 错误消息
  3875. /// </param>
  3876. /// <returns>
  3877. /// </returns>
  3878. private bool MergerPrintImg(string _path, string _saveimg, RectangleF _rectangle, out string errmsg)
  3879. {
  3880. errmsg = null;
  3881. try
  3882. {
  3883. Bitmap bitmap = null;
  3884. //创建要显示的图片对象,根据参数的个数设置宽度
  3885. Bitmap backgroudImg = new Bitmap((int)/*GridM.ActualWidth*/wit, (int)/*GridM.ActualHeight*/hei);
  3886. Graphics g = Graphics.FromImage(backgroudImg);
  3887. //清除画布,背景设置为白色
  3888. g.Clear(System.Drawing.Color.White);
  3889. if (!string.IsNullOrWhiteSpace(_path))
  3890. {
  3891. bitmap = ImageHelper.ReadBitmapFile(_path);
  3892. g.DrawImage(bitmap, _rectangle);
  3893. }
  3894. #region 添加箭头
  3895. string Str = "↑";
  3896. SolidBrush mybrush = new SolidBrush(System.Drawing.Color.Black); //设置默认画刷颜色
  3897. Font myfont = new System.Drawing.Font("黑体", 14); //设置默认字体格式
  3898. g.DrawString(Str, myfont, mybrush, new System.Drawing.Rectangle((int)wit - 50, 20, 50, 50));
  3899. #endregion 添加箭头
  3900. backgroudImg.Save(_saveimg);
  3901. g.Dispose();
  3902. backgroudImg.Dispose();
  3903. if (bitmap != null)
  3904. {
  3905. bitmap.Dispose();
  3906. }
  3907. GC.Collect();
  3908. return true;
  3909. }
  3910. catch (Exception ex)
  3911. {
  3912. errmsg = ex.Message;
  3913. LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
  3914. return false;
  3915. }
  3916. }
  3917. #endregion 打印界面
  3918. #region 笔事件回调
  3919. public void penPointEvent(byte bIndex, byte bPenStatus, short bx, short by, short bPress, int m_nDeviceW, int m_nDeviceH)
  3920. {
  3921. //17是按下,16是抬起
  3922. if (bPenStatus == 16 || bPenStatus == 0)
  3923. {
  3924. //stroke.Clear();
  3925. if (APP.PageContextData.currpage > 0)
  3926. {
  3927. Dispatcher.Invoke(new Action(() =>
  3928. {
  3929. myblackboard.changepages(0, 0, true, Color, PenSize, APP.PageContextData.currpage - 1, 0);
  3930. }));
  3931. }
  3932. }
  3933. double PropW = blackboard_canvas.ActualWidth / m_nDeviceH;
  3934. double PropH = blackboard_canvas.ActualHeight / m_nDeviceW;
  3935. //点
  3936. double tempY = (m_nDeviceW - bx) * PropH;
  3937. double tempX = by * PropW;
  3938. //pageSerial //点阵IP地址 与打印的页面关联
  3939. if (APP.PageContextData.currpage > 0)
  3940. {
  3941. Dispatcher.Invoke(new Action(() =>
  3942. {
  3943. float Pressure = bPress / 100f;
  3944. if (bPress > 0)
  3945. {
  3946. myblackboard.changepages(tempX, tempY, false, Color, PenSize, APP.PageContextData.currpage - 1, Pressure);
  3947. }
  3948. #region 设置滚动条位置
  3949. //点在显示页面上方
  3950. if (tempY < ScroMain.VerticalOffset)
  3951. {
  3952. //滚动条当前位置
  3953. double RollCurrentLocation = ScroMain.VerticalOffset;
  3954. //向上滚动至以点为中心需要滚动的距离
  3955. double UpRoll = (RollCurrentLocation - tempY) + (ScroMain.ActualHeight / 2);
  3956. //如果小于0则等于0
  3957. double RollLocation = RollCurrentLocation - UpRoll;
  3958. if (RollLocation < 0)
  3959. {
  3960. RollLocation = 0;
  3961. }
  3962. ////滚动条实际偏移量
  3963. //double RollOffset = RollCurrentLocation - RollLocation;
  3964. ScroMain.ScrollToVerticalOffset(RollLocation);
  3965. }
  3966. //点在显示页面下方
  3967. if (tempY > ScroMain.VerticalOffset + ScroMain.ActualHeight)
  3968. {
  3969. //滚动条当前位置
  3970. double RollCurrentLocation = ScroMain.VerticalOffset;
  3971. //向下滚动至以点为中心需要滚动的距离
  3972. double DownRoll = (tempY - RollCurrentLocation) - (ScroMain.ActualHeight / 2);
  3973. //如果小于0则等于0
  3974. double RollLocation = RollCurrentLocation + DownRoll;
  3975. //滚动条最大滚动值
  3976. double ScrollbarMaxNum = GridM.ActualHeight - ScroMain.ActualHeight;
  3977. if (RollLocation > ScrollbarMaxNum)
  3978. {
  3979. RollLocation = ScrollbarMaxNum;
  3980. }
  3981. ////滚动条实际偏移量
  3982. //double RollOffset = RollLocation-RollCurrentLocation;
  3983. ScroMain.ScrollToVerticalOffset(RollLocation);
  3984. }
  3985. #endregion 设置滚动条位置
  3986. if (tempX > 0 && tempY > 0)
  3987. {
  3988. //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
  3989. System.Windows.Point getP = ScroMain.PointToScreen(new System.Windows.Point(tempX, tempY - ScroMain.VerticalOffset));
  3990. SetCursorPos((int)getP.X, (int)getP.Y);
  3991. }
  3992. }));
  3993. }
  3994. }
  3995. public void penStatusEvent()
  3996. {
  3997. UpdateDevStatus();
  3998. }
  3999. #endregion 笔事件回调
  4000. }
  4001. public class PageData
  4002. {
  4003. public int PageCode { get; set; }
  4004. public string PageName { get; set; }
  4005. }
  4006. }