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

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