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

MainWindow.xaml.cs 153KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142
  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. private System.Timers.Timer _times;
  853. /// <summary>
  854. /// 摄像头打开事件
  855. /// </summary>
  856. /// <param name="sender">
  857. /// </param>
  858. /// <param name="e">
  859. /// </param>
  860. private void RbnOpen_Click(object sender, RoutedEventArgs e)
  861. {
  862. if (!_isRbnOpen)
  863. {
  864. #region 防止连击
  865. if (_isPressButton)
  866. {
  867. return;
  868. }
  869. _isPressButton = true;
  870. Task.Run
  871. (
  872. () =>
  873. {
  874. Thread.Sleep(3000);
  875. _isPressButton = false;
  876. }
  877. );
  878. #endregion 防止连击
  879. CameraHelper.UpdateCameraDevices();
  880. if (CameraHelper.CameraDevices.Count > 0)
  881. {
  882. if (string.IsNullOrWhiteSpace(App.CameraName))
  883. {
  884. App.CameraName = CameraHelper.CameraDevices[0].MonikerString;
  885. }
  886. int cameraIndex = 0;
  887. for (int i = 0; i < CameraHelper.CameraDevices.Count; i++)
  888. {
  889. if (CameraHelper.CameraDevices[i].MonikerString == App.CameraName)
  890. {
  891. cameraIndex = i;
  892. }
  893. }
  894. CameraHelper.imageCallback = LoadImage;
  895. CameraHelper.StartCameraDevice(cameraIndex, this.Dispatcher);
  896. if (_timer != null)
  897. {
  898. _times.Elapsed -= Times_Elapsed;
  899. _times.Enabled = false;
  900. _times.Dispose();
  901. }
  902. _times = new System.Timers.Timer(200) //初始值为300
  903. {
  904. AutoReset = true //设置是否执行System.Timers.Timer.Elapsed事件
  905. }; //设置执行一次(false)还是一直执行(true)
  906. _times.Elapsed += Times_Elapsed;
  907. _times.Enabled = true; //启动计时器
  908. _isRbnOpen = true;
  909. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  910. FileToolsCommon.CreateDirectory(imgPath);
  911. HeadImg.Visibility = Visibility.Visible;
  912. // < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  913. switch (App.CameraPosition)
  914. {
  915. case "1":
  916. HeadImg.HorizontalAlignment = HorizontalAlignment.Right;
  917. HeadImg.VerticalAlignment = VerticalAlignment.Top;
  918. break;
  919. case "2":
  920. HeadImg.HorizontalAlignment = HorizontalAlignment.Left;
  921. HeadImg.VerticalAlignment = VerticalAlignment.Top;
  922. break;
  923. case "3":
  924. HeadImg.HorizontalAlignment = HorizontalAlignment.Right;
  925. HeadImg.VerticalAlignment = VerticalAlignment.Bottom;
  926. break;
  927. case "4":
  928. HeadImg.HorizontalAlignment = HorizontalAlignment.Left;
  929. HeadImg.VerticalAlignment = VerticalAlignment.Bottom;
  930. break;
  931. }
  932. RbnTurnOff.IsEnabled = false;
  933. Task.Run
  934. (
  935. () =>
  936. {
  937. Thread.Sleep(3000);
  938. Dispatcher.Invoke
  939. (
  940. () =>
  941. {
  942. RbnTurnOff.IsEnabled = true;
  943. }
  944. );
  945. }
  946. );
  947. }
  948. }
  949. }
  950. /// <summary>
  951. /// 摄像头关闭事件
  952. /// </summary>
  953. /// <param name="sender">
  954. /// </param>
  955. /// <param name="e">
  956. /// </param>
  957. private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
  958. {
  959. if (_isRbnOpen)
  960. {
  961. #region 防止连击
  962. if (_isPressButton)
  963. {
  964. return;
  965. }
  966. _isPressButton = true;
  967. Task.Run
  968. (
  969. () =>
  970. {
  971. Thread.Sleep(500);
  972. _isPressButton = false;
  973. }
  974. );
  975. #endregion 防止连击
  976. _isRbnOpen = false;
  977. HeadImg.Visibility = Visibility.Hidden;
  978. RbnOpen.IsEnabled = false;
  979. CameraHelper.CloseDevice();
  980. RbnOpen.IsEnabled = true;
  981. if (_timer != null)
  982. {
  983. _times.Elapsed -= Times_Elapsed;
  984. _times.Enabled = false;
  985. _times.Dispose();
  986. _times = null;
  987. }
  988. }
  989. }
  990. private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  991. {
  992. if (_isRbnOpen)
  993. {
  994. try
  995. {
  996. long time = Timestamp();
  997. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  998. CameraHelper.CaptureImage(imgPath, time.ToString());
  999. }
  1000. catch (Exception ex)
  1001. {
  1002. LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
  1003. }
  1004. }
  1005. }
  1006. #endregion 摄像头
  1007. #region 设备检测
  1008. /// <summary>
  1009. /// 设备检测
  1010. /// </summary>
  1011. /// <param name="sender">
  1012. /// </param>
  1013. /// <param name="e">
  1014. /// </param>
  1015. private async void BtnDevice_Click(object sender, RoutedEventArgs e)
  1016. {
  1017. if (RbnTurnOff.IsChecked != null && !(bool)RbnTurnOff.IsChecked)
  1018. {
  1019. RbnTurnOff.IsChecked = true;
  1020. RbnTurnOff_Click(null, null);
  1021. await Task.Delay(1000);
  1022. }
  1023. DeviceWindow deviceWin = new DeviceWindow();
  1024. deviceWin.ShowDialog();
  1025. }
  1026. #endregion 设备检测
  1027. #endregion 事件
  1028. #region 画笔
  1029. /// <summary>
  1030. /// 画笔颜色事件 蓝色
  1031. /// </summary>
  1032. /// <param name="sender">
  1033. /// </param>
  1034. /// <param name="e">
  1035. /// </param>
  1036. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  1037. {
  1038. _drawingAttributes.Color = Colors.DeepSkyBlue;
  1039. _color = Colors.DeepSkyBlue;
  1040. ImgRed.Visibility = Visibility.Collapsed;
  1041. ImgGray.Visibility = Visibility.Collapsed;
  1042. ImgCyanBlue.Visibility = Visibility.Collapsed;
  1043. ImgYellow.Visibility = Visibility.Collapsed;
  1044. ImgBlue.Visibility = Visibility.Visible;
  1045. }
  1046. /// <summary>
  1047. /// 画笔颜色事件 青色
  1048. /// </summary>
  1049. /// <param name="sender">
  1050. /// </param>
  1051. /// <param name="e">
  1052. /// </param>
  1053. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  1054. {
  1055. _drawingAttributes.Color = Colors.LimeGreen;
  1056. _color = Colors.LimeGreen;
  1057. ImgRed.Visibility = Visibility.Collapsed;
  1058. ImgGray.Visibility = Visibility.Collapsed;
  1059. ImgCyanBlue.Visibility = Visibility.Visible;
  1060. ImgYellow.Visibility = Visibility.Collapsed;
  1061. ImgBlue.Visibility = Visibility.Collapsed;
  1062. }
  1063. /// <summary>
  1064. /// 画笔颜色事件 黑色
  1065. /// </summary>
  1066. /// <param name="sender">
  1067. /// </param>
  1068. /// <param name="e">
  1069. /// </param>
  1070. private void BtnGray_Click(object sender, RoutedEventArgs e)
  1071. {
  1072. _drawingAttributes.Color = Colors.Black;
  1073. _color = Colors.Black;
  1074. ImgRed.Visibility = Visibility.Collapsed;
  1075. ImgGray.Visibility = Visibility.Visible;
  1076. ImgCyanBlue.Visibility = Visibility.Collapsed;
  1077. ImgYellow.Visibility = Visibility.Collapsed;
  1078. ImgBlue.Visibility = Visibility.Collapsed;
  1079. }
  1080. /// <summary>
  1081. /// 画笔颜色事件 红色
  1082. /// </summary>
  1083. /// <param name="sender">
  1084. /// </param>
  1085. /// <param name="e">
  1086. /// </param>
  1087. private void BtnRed_Click(object sender, RoutedEventArgs e)
  1088. {
  1089. //设置 DrawingAttributes 的 Color 属性设置颜色
  1090. _drawingAttributes.Color = Colors.Red;
  1091. _color = Colors.Red;
  1092. ImgRed.Visibility = Visibility.Visible;
  1093. ImgGray.Visibility = Visibility.Collapsed;
  1094. ImgCyanBlue.Visibility = Visibility.Collapsed;
  1095. ImgYellow.Visibility = Visibility.Collapsed;
  1096. ImgBlue.Visibility = Visibility.Collapsed;
  1097. }
  1098. /// <summary>
  1099. /// 画笔颜色事件 白色
  1100. /// </summary>
  1101. /// <param name="sender">
  1102. /// </param>
  1103. /// <param name="e">
  1104. /// </param>
  1105. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  1106. {
  1107. _drawingAttributes.Color = Colors.White;
  1108. _color = Colors.White;
  1109. }
  1110. /// <summary>
  1111. /// 画笔颜色事件 黄色
  1112. /// </summary>
  1113. /// <param name="sender">
  1114. /// </param>
  1115. /// <param name="e">
  1116. /// </param>
  1117. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  1118. {
  1119. _drawingAttributes.Color = Colors.Gold;
  1120. _color = Colors.Gold;
  1121. ImgRed.Visibility = Visibility.Collapsed;
  1122. ImgGray.Visibility = Visibility.Collapsed;
  1123. ImgCyanBlue.Visibility = Visibility.Collapsed;
  1124. ImgYellow.Visibility = Visibility.Visible;
  1125. ImgBlue.Visibility = Visibility.Collapsed;
  1126. }
  1127. private void imgCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1128. {
  1129. _mouseDown = true;
  1130. _imageOperationUtil.setMouseDown(_mouseDown);
  1131. }
  1132. /// <summary>
  1133. /// 画笔粗细事件 粗
  1134. /// </summary>
  1135. /// <param name="sender">
  1136. /// </param>
  1137. /// <param name="e">
  1138. /// </param>
  1139. private void RbnCrude_Click(object sender, RoutedEventArgs e)
  1140. {
  1141. _drawingAttributes.Width = 5;
  1142. _drawingAttributes.Height = 5;
  1143. _penSize = 5;
  1144. }
  1145. /// <summary>
  1146. /// 画笔粗细事件 细
  1147. /// </summary>
  1148. /// <param name="sender">
  1149. /// </param>
  1150. /// <param name="e">
  1151. /// </param>
  1152. private void RbnFine_Click(object sender, RoutedEventArgs e)
  1153. {
  1154. _drawingAttributes.Width = 1;
  1155. _drawingAttributes.Height = 1;
  1156. _penSize = 1;
  1157. }
  1158. /// <summary>
  1159. /// 画笔粗细事件 中
  1160. /// </summary>
  1161. /// <param name="sender">
  1162. /// </param>
  1163. /// <param name="e">
  1164. /// </param>
  1165. private void RbnIn_Click(object sender, RoutedEventArgs e)
  1166. {
  1167. _drawingAttributes.Width = 3;
  1168. _drawingAttributes.Height = 3;
  1169. _penSize = 3;
  1170. }
  1171. #endregion 画笔
  1172. #region 导入截图
  1173. /// <summary>
  1174. /// 防止图片地址重复
  1175. /// </summary>
  1176. private long _wordImgNum = 9999;
  1177. /// <summary>
  1178. /// 返回一个时间戳到毫秒
  1179. /// </summary>
  1180. /// <returns>
  1181. /// </returns>
  1182. public static long Timestamp()
  1183. {
  1184. TimeSpan ts = DateTime.UtcNow
  1185. - new DateTime
  1186. (
  1187. 1970,
  1188. 1,
  1189. 1,
  1190. 0,
  1191. 0,
  1192. 0,
  1193. 0
  1194. );
  1195. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  1196. return timestr;
  1197. }
  1198. /// <summary>
  1199. /// 获取时间戳
  1200. /// </summary>
  1201. /// <returns>
  1202. /// </returns>
  1203. public string GetTimeStamp()
  1204. {
  1205. TimeSpan ts = DateTime.Now
  1206. - new DateTime
  1207. (
  1208. 1970,
  1209. 1,
  1210. 1,
  1211. 0,
  1212. 0,
  1213. 0,
  1214. 0
  1215. );
  1216. return Convert.ToInt64(ts.TotalSeconds).ToString();
  1217. }
  1218. /// <summary>
  1219. /// 导入-结束
  1220. /// </summary>
  1221. /// <returns>
  1222. /// </returns>
  1223. public void InvokeServerCompate(object obj)
  1224. {
  1225. //APP.myloading.Hide();
  1226. App.myloading.Hide();
  1227. }
  1228. public void WindowType()
  1229. {
  1230. this.Activate();
  1231. }
  1232. /// <summary>
  1233. /// 导入事件
  1234. /// </summary>
  1235. /// <param name="sender">
  1236. /// </param>
  1237. /// <param name="e">
  1238. /// </param>
  1239. private void BtnImport_Click(object sender, RoutedEventArgs e)
  1240. {
  1241. try
  1242. {
  1243. PrepareRecord();
  1244. HideAngleBorder();
  1245. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  1246. _ofd = new System.Windows.Forms.OpenFileDialog
  1247. {
  1248. //Filter = "文档|*.docx;*.doc;*.ppt;*.pptx",
  1249. //增加导入图片
  1250. Filter = @"文档|*.docx;*.doc;*.ppt;*.pptx;*.pdf|图片|*.jpg;*.jpeg;*.png;*.bmp",
  1251. InitialDirectory = desktopPath,
  1252. Multiselect = false,
  1253. AddExtension = true,
  1254. DereferenceLinks = true
  1255. };
  1256. App.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
  1257. }
  1258. catch (Exception ex)
  1259. {
  1260. LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
  1261. }
  1262. }
  1263. /// <summary>
  1264. /// 截图事件
  1265. /// </summary>
  1266. /// <param name="sender">
  1267. /// </param>
  1268. /// <param name="e">
  1269. /// </param>
  1270. private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
  1271. {
  1272. if (_recordType == 4)
  1273. {
  1274. return;
  1275. }
  1276. JietuAction();
  1277. }
  1278. private async void JietuAction()
  1279. {
  1280. PrepareRecord();
  1281. HideAngleBorder();
  1282. if (WindowState == WindowState.Normal) //截图隐藏窗口
  1283. {
  1284. WindowState = WindowState.Minimized;
  1285. }
  1286. await Task.Delay(300);
  1287. ImgCanvas.Margin = new Thickness
  1288. (
  1289. 0,
  1290. 0,
  1291. 0,
  1292. 0
  1293. );
  1294. App.ImgPath = string.Empty;
  1295. string time = GetTimeStamp();
  1296. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
  1297. App.ImgPath = desktopPath;
  1298. ImageHelper.GetScreenshot
  1299. (
  1300. new Rectangle
  1301. (
  1302. 0,
  1303. 0,
  1304. 0,
  1305. 0
  1306. )
  1307. {
  1308. Location = default,
  1309. Size = default
  1310. },
  1311. desktopPath,
  1312. false,
  1313. out var _
  1314. );
  1315. _kHook.Stop();
  1316. if (App.W_JieTuWindow != null)
  1317. {
  1318. App.W_JieTuWindow.initialization();
  1319. App.W_JieTuWindow.Screenshot();
  1320. App.W_JieTuWindow.InitializeKeyDownEvent();
  1321. App.W_JieTuWindow.WindowState = WindowState.Maximized;
  1322. App.W_JieTuWindow.Visibility = Visibility.Visible;
  1323. }
  1324. else
  1325. {
  1326. App.W_JieTuWindow = new JieTuWindow();
  1327. App.W_JieTuWindow.InitializeKeyDownEvent();
  1328. // 订阅事件
  1329. App.W_JieTuWindow.ChangeTextEvent += frm_ChangeTextEvent;
  1330. App.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
  1331. App.W_JieTuWindow.Show();
  1332. }
  1333. }
  1334. /// <summary>
  1335. /// 截图关闭窗口
  1336. /// </summary>
  1337. /// <param name="text">
  1338. /// </param>
  1339. private void frm_ChangeTextEvent(string text)
  1340. {
  1341. if ("关闭窗口".Equals(text))
  1342. {
  1343. if (WindowState == WindowState.Minimized) //截图完恢复窗口
  1344. {
  1345. WindowState = WindowState.Normal;
  1346. Activate();
  1347. }
  1348. InitializeKeyDownEvent();
  1349. if (!string.IsNullOrWhiteSpace(App.ImgPath) && File.Exists(App.ImgPath))
  1350. {
  1351. if (App.PageContextData.currpage == 0)
  1352. {
  1353. App.PageContextData.pagenum += 1;
  1354. App.PageContextData.currpage = App.PageContextData.pagenum;
  1355. myblackboard.changepage(App.PageContextData.currpage - 1);
  1356. GridPage.Visibility = Visibility.Visible; //页码大于0 显示
  1357. #region 插入页码
  1358. #endregion 插入页码
  1359. }
  1360. if (App.PageDrawList.Count >= App.PageContextData.currpage)
  1361. {
  1362. App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath = App.ImgPath; //zxycs
  1363. App.PageDrawList[App.PageContextData.currpage - 1].PdfImagePath = App.ImgPath;
  1364. }
  1365. else
  1366. {
  1367. Model_DrawData modelDrawData = new Model_DrawData
  1368. {
  1369. PageImagePath = App.ImgPath,
  1370. PdfImagePath = App.ImgPath
  1371. };
  1372. App.PageDrawList.Add(modelDrawData);
  1373. }
  1374. if (App.PageDrawList.Count >= App.PageContextData.currpage && !string.IsNullOrWhiteSpace(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath))
  1375. {
  1376. ImgDocumentation.Source = null;
  1377. BitmapImage bitImg = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
  1378. _mouseDown = false;
  1379. _imageOperationUtil.setMouseDown(_mouseDown);
  1380. App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
  1381. {
  1382. X = 0.1,
  1383. Y = 0.1
  1384. };
  1385. App.PageDrawList[App.PageContextData.currpage - 1].Type = "截图";
  1386. App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = false;
  1387. ImgCanvas.Source = bitImg;
  1388. ImgCanvas.Width = bitImg.Width;
  1389. ImgCanvas.Height = bitImg.Height;
  1390. ScroMain.ScrollToVerticalOffset(0);
  1391. App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
  1392. {
  1393. CenterX = ImgCanvas.Width,
  1394. CenterY = ImgCanvas.Height
  1395. };
  1396. BtnPrint.IsEnabled = true;
  1397. }
  1398. }
  1399. }
  1400. else if ("取消".Equals(text))
  1401. {
  1402. if (WindowState == WindowState.Minimized) //截图完恢复窗口
  1403. {
  1404. WindowState = WindowState.Normal;
  1405. }
  1406. }
  1407. }
  1408. /// <summary>
  1409. /// 导入-开始
  1410. /// </summary>
  1411. /// <returns>
  1412. /// </returns>
  1413. private object InvokeServering()
  1414. {
  1415. Dispatcher.Invoke
  1416. (
  1417. () =>
  1418. {
  1419. _result = _ofd.ShowDialog();
  1420. }
  1421. );
  1422. if (_result == System.Windows.Forms.DialogResult.OK)
  1423. {
  1424. if (_ofd.FileName != "")
  1425. {
  1426. List<string> imagelist = new List<string>()
  1427. {
  1428. "jpg",
  1429. "jpeg",
  1430. "png",
  1431. "bmp"
  1432. };
  1433. Dispatcher.Invoke
  1434. (
  1435. () =>
  1436. {
  1437. App.myloading.Show();
  1438. myblackboard.changepage(App.PageContextData.pagenum);
  1439. }
  1440. );
  1441. string filepath = _ofd.FileName;
  1442. string filesuff = filepath.Substring(filepath.LastIndexOf(".", StringComparison.Ordinal) + 1).ToLower();
  1443. if (_ofd.SafeFileName != null)
  1444. {
  1445. string path = _ofd.SafeFileName.Replace(".ppt", "").Replace(".pptx", "").Trim();
  1446. string type = _ofd.SafeFileName.Replace(".ppt", "typezsygppt").Replace(".pptx", "typezsygppt").Replace(".pdf", "typepdf").Trim();
  1447. if (type.Contains("typezsygppt")) //ppt
  1448. {
  1449. try
  1450. {
  1451. #region PPT转PDF
  1452. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1453. path = pathTemp + path + ".pdf";
  1454. FileToolsCommon.CreateDirectory(pathTemp);
  1455. //PPT转PDF
  1456. Presentation ppt = new Presentation(filepath);
  1457. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  1458. #endregion PPT转PDF
  1459. #region PDF转图片
  1460. // 图片绝对路径集合
  1461. List<string> images = new List<string>();
  1462. string directoryPath = pathTemp;
  1463. //定义Jpeg转换设备
  1464. Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(path);
  1465. Directory.CreateDirectory(directoryPath);
  1466. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1467. var device = new Aspose.Pdf.Devices.JpegDevice(100);
  1468. //遍历每一页转为jpg
  1469. for (int i = 1; i <= pdfDoc.Pages.Count; i++)
  1470. {
  1471. long ii = Timestamp();
  1472. string filePathOutPut = Path.Combine
  1473. (
  1474. directoryPath,
  1475. string.Format
  1476. (
  1477. "{0}{1}.jpg",
  1478. ii,
  1479. i
  1480. )
  1481. );
  1482. images.Add(filePathOutPut);
  1483. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1484. try
  1485. {
  1486. device.Process(pdfDoc.Pages[i], fs);
  1487. fs.Close();
  1488. }
  1489. catch (Exception)
  1490. {
  1491. fs.Close();
  1492. File.Delete(filePathOutPut);
  1493. }
  1494. }
  1495. #endregion PDF转图片
  1496. Dispatcher.Invoke
  1497. (
  1498. () =>
  1499. {
  1500. string[] page = images.ToArray();
  1501. int num = 0;
  1502. int iStart = App.PageContextData.pagenum; //导入文档的开始下标
  1503. int iEnd = page.Length + App.PageContextData.pagenum; //导入文档的结束下标
  1504. for (int i = 0 + App.PageContextData.pagenum; i < page.Length + App.PageContextData.pagenum; i++) //给画板模型加图片路径
  1505. {
  1506. if (App.PageDrawList != null && App.PageDrawList.Count > i)
  1507. {
  1508. App.PageDrawList[i].PageImagePath = page[i - App.PageContextData.pagenum]; //zxycs
  1509. App.PageDrawList[i].PdfImagePath = page[i - App.PageContextData.pagenum];
  1510. App.PageDrawList[i].PageNum = i + 1;
  1511. App.PageDrawList[i].ImgDocumentation = true;
  1512. App.PageDrawList[i].Type = "ppt";
  1513. }
  1514. else
  1515. {
  1516. Model_DrawData modelDrawData = new Model_DrawData
  1517. {
  1518. PageImagePath = page[i - App.PageContextData.pagenum],
  1519. PdfImagePath = page[i - App.PageContextData.pagenum],
  1520. PageNum = i + 1,
  1521. ImgDocumentation = true,
  1522. Type = "ppt"
  1523. };
  1524. if (App.PageDrawList != null)
  1525. {
  1526. App.PageDrawList.Add(modelDrawData);
  1527. }
  1528. }
  1529. BtnPrint.IsEnabled = true;
  1530. App.SaveDraw();
  1531. num++;
  1532. }
  1533. if (num > 0)
  1534. {
  1535. App.PageContextData.currpage = App.PageContextData.pagenum + 1;
  1536. App.PageContextData.pagenum += num;
  1537. GridPage.Visibility = Visibility.Visible; //页码大于0 显示
  1538. }
  1539. if (App.PageDrawList != null && App.PageContextData.currpage > 0 && App.PageContextData.currpage <= App.PageDrawList.Count)
  1540. {
  1541. ImgCanvas.Source = null;
  1542. BtnScreenshot.IsEnabled = false;
  1543. ImgDocumentation.Source = null;
  1544. ImgPpt.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
  1545. ScroMain.ScrollToVerticalOffset(0);
  1546. for (int i = iStart; i < iEnd; i++)
  1547. {
  1548. App.PageDrawList[i].ImageLocation = new TranslateTransform
  1549. {
  1550. X = 0.1,
  1551. Y = 0.1
  1552. };
  1553. App.PageDrawList[i].IsImageLocation = true;
  1554. App.PageDrawList[i].ImageSizes = new ScaleTransform
  1555. {
  1556. CenterX = ImgCanvas.Width,
  1557. CenterY = ImgCanvas.Height
  1558. };
  1559. }
  1560. }
  1561. else
  1562. {
  1563. ImgDocumentation.Source = null;
  1564. ImgCanvas.Source = null;
  1565. ImgPpt.Source = null;
  1566. //截图可用
  1567. BtnScreenshot.IsEnabled = true;
  1568. }
  1569. }
  1570. );
  1571. }
  1572. catch (Exception ex)
  1573. {
  1574. Dispatcher.Invoke
  1575. (
  1576. () =>
  1577. {
  1578. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1579. }
  1580. );
  1581. LogHelper.WriteErrLog("【打开ppt】(OpenDialog PPT)" + ex.Message, ex);
  1582. }
  1583. }
  1584. else if (type.Contains("typepdf"))
  1585. {
  1586. try
  1587. {
  1588. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1589. #region PDF转图片
  1590. // 图片绝对路径集合
  1591. List<string> images = new List<string>();
  1592. string directoryPath = pathTemp;
  1593. //aspose许可证
  1594. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1595. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1596. //l.SetLicense(licenseName);
  1597. //定义Jpeg转换设备
  1598. Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(filepath);
  1599. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1600. //directoryPath += quality;
  1601. Directory.CreateDirectory(directoryPath);
  1602. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1603. var device = new Aspose.Pdf.Devices.JpegDevice(100);
  1604. //遍历每一页转为jpg
  1605. for (int i = 1; i <= pdfDoc.Pages.Count; i++)
  1606. {
  1607. long ii = Timestamp();
  1608. string filePathOutPut = Path.Combine
  1609. (
  1610. directoryPath,
  1611. string.Format
  1612. (
  1613. "{0}{1}.jpg",
  1614. ii,
  1615. i
  1616. )
  1617. );
  1618. images.Add(filePathOutPut);
  1619. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1620. try
  1621. {
  1622. device.Process(pdfDoc.Pages[i], fs);
  1623. fs.Close();
  1624. }
  1625. catch (Exception)
  1626. {
  1627. fs.Close();
  1628. File.Delete(filePathOutPut);
  1629. }
  1630. }
  1631. #endregion PDF转图片
  1632. string[] page = images.ToArray();
  1633. int num = 0;
  1634. Dispatcher.Invoke
  1635. (
  1636. () =>
  1637. {
  1638. for (int i = App.PageContextData.pagenum; i < page.Length + App.PageContextData.pagenum; i++) //给画板模型加图片路径
  1639. {
  1640. if (App.PageDrawList != null && App.PageDrawList.Count > i)
  1641. {
  1642. App.PageDrawList[i].PageImagePath = page[i - App.PageContextData.pagenum]; //zxycs
  1643. App.PageDrawList[i].PdfImagePath = page[i - App.PageContextData.pagenum];
  1644. App.PageDrawList[i].PageNum = i + 1;
  1645. App.PageDrawList[i].ImgDocumentation = true;
  1646. App.PageDrawList[i].Type = "word";
  1647. }
  1648. else
  1649. {
  1650. Model_DrawData modelDrawData = new Model_DrawData
  1651. {
  1652. PageImagePath = page[i - App.PageContextData.pagenum],
  1653. PdfImagePath = page[i - App.PageContextData.pagenum],
  1654. PageNum = i + 1,
  1655. ImgDocumentation = true,
  1656. Type = "word"
  1657. };
  1658. if (App.PageDrawList != null)
  1659. {
  1660. App.PageDrawList.Add(modelDrawData);
  1661. }
  1662. }
  1663. BtnPrint.IsEnabled = true;
  1664. App.SaveDraw();
  1665. num++;
  1666. }
  1667. if (num > 0)
  1668. {
  1669. App.PageContextData.currpage = App.PageContextData.pagenum + 1;
  1670. App.PageContextData.pagenum += num;
  1671. GridPage.Visibility = Visibility.Visible; //页码大于0 显示
  1672. }
  1673. if (App.PageDrawList != null && App.PageContextData.currpage > 0 && App.PageContextData.currpage <= App.PageDrawList.Count)
  1674. {
  1675. ImgCanvas.Source = null;
  1676. ImgPpt.Source = null;
  1677. BtnScreenshot.IsEnabled = false;
  1678. ImgDocumentation.Visibility = Visibility.Visible;
  1679. ImgDocumentation.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath)); //给当前页面展示图片
  1680. ScroMain.ScrollToVerticalOffset(0);
  1681. }
  1682. else
  1683. {
  1684. ImgDocumentation.Source = null;
  1685. ImgCanvas.Source = null;
  1686. ImgPpt.Source = null;
  1687. //截图可用
  1688. BtnScreenshot.IsEnabled = true;
  1689. }
  1690. }
  1691. );
  1692. }
  1693. catch (Exception ex)
  1694. {
  1695. Dispatcher.Invoke
  1696. (
  1697. () =>
  1698. {
  1699. MessageWindow.Show(ex.Message);
  1700. }
  1701. );
  1702. LogHelper.WriteErrLog("【打开pdf】(OpenDialog pdf)" + ex.Message, ex);
  1703. }
  1704. }
  1705. else if (imagelist.Contains(filesuff)) //导入图片
  1706. {
  1707. string imagepath = AppDomain.CurrentDomain.BaseDirectory + "temp";
  1708. if (!Directory.Exists(imagepath))
  1709. {
  1710. Directory.CreateDirectory(imagepath);
  1711. }
  1712. TimeSpan ts = DateTime.UtcNow
  1713. - new DateTime
  1714. (
  1715. 1970,
  1716. 1,
  1717. 1,
  1718. 0,
  1719. 0,
  1720. 0,
  1721. 0
  1722. );
  1723. string timestr = Convert.ToInt64(ts.TotalMilliseconds).ToString();
  1724. string filepathCopy = Path.Combine(imagepath, timestr + _ofd.SafeFileName);
  1725. File.Copy(filepath, filepathCopy);
  1726. filepath = filepathCopy;
  1727. App.ImgPath = filepath;
  1728. Dispatcher.Invoke
  1729. (
  1730. () =>
  1731. {
  1732. if (App.PageContextData.currpage == 0)
  1733. {
  1734. App.PageContextData.pagenum += 1;
  1735. App.PageContextData.currpage = App.PageContextData.pagenum;
  1736. myblackboard.changepage(App.PageContextData.currpage - 1);
  1737. GridPage.Visibility = Visibility.Visible; //页码大于0 显示
  1738. #region 插入页码
  1739. #endregion 插入页码
  1740. }
  1741. else
  1742. {
  1743. App.PageContextData.pagenum += 1;
  1744. App.PageContextData.currpage = App.PageContextData.pagenum;
  1745. myblackboard.changepage(App.PageContextData.currpage - 1);
  1746. }
  1747. if (App.PageDrawList.Count >= App.PageContextData.currpage)
  1748. {
  1749. App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath = App.ImgPath; //zxycs
  1750. App.PageDrawList[App.PageContextData.currpage - 1].PdfImagePath = App.ImgPath;
  1751. }
  1752. else
  1753. {
  1754. Model_DrawData modelDrawData = new Model_DrawData
  1755. {
  1756. PageImagePath = App.ImgPath,
  1757. PdfImagePath = App.ImgPath
  1758. };
  1759. App.PageDrawList.Add(modelDrawData);
  1760. }
  1761. if (App.PageDrawList.Count >= App.PageContextData.currpage && !string.IsNullOrWhiteSpace(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath))
  1762. {
  1763. ImgDocumentation.Source = null;
  1764. BitmapImage bitImg = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
  1765. _mouseDown = false;
  1766. _imageOperationUtil.setMouseDown(_mouseDown);
  1767. App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
  1768. {
  1769. X = 0.1,
  1770. Y = 0.1
  1771. };
  1772. App.PageDrawList[App.PageContextData.currpage - 1].Type = "截图";
  1773. App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = false;
  1774. ImgCanvas.Source = bitImg;
  1775. ImgCanvas.Width = bitImg.Width;
  1776. ImgCanvas.Height = bitImg.Height;
  1777. ScroMain.ScrollToVerticalOffset(0);
  1778. ImgCanvas.Margin = new Thickness
  1779. (
  1780. App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.X,
  1781. App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.Y,
  1782. 0,
  1783. 0
  1784. );
  1785. App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
  1786. {
  1787. CenterX = ImgCanvas.Width,
  1788. CenterY = ImgCanvas.Height
  1789. };
  1790. BtnPrint.IsEnabled = true;
  1791. }
  1792. }
  1793. );
  1794. }
  1795. else //word
  1796. {
  1797. try
  1798. {
  1799. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1800. _wordImgNum += 1;
  1801. string[] page = ZAsposeUtil.ConvertWordToImage
  1802. (
  1803. filepath,
  1804. paths,
  1805. "" + _wordImgNum
  1806. )
  1807. .ToArray();
  1808. int num = 0;
  1809. Dispatcher.Invoke
  1810. (
  1811. () =>
  1812. {
  1813. for (int i = 0 + App.PageContextData.pagenum; i < page.Length + App.PageContextData.pagenum; i++) //给画板模型加图片路径
  1814. {
  1815. if (App.PageDrawList != null && App.PageDrawList.Count > i)
  1816. {
  1817. App.PageDrawList[i].PageImagePath = page[i - App.PageContextData.pagenum]; //zxycs
  1818. App.PageDrawList[i].PdfImagePath = page[i - App.PageContextData.pagenum];
  1819. App.PageDrawList[i].PageNum = i + 1;
  1820. App.PageDrawList[i].ImgDocumentation = true;
  1821. App.PageDrawList[i].Type = "word";
  1822. }
  1823. else
  1824. {
  1825. Model_DrawData modelDrawData = new Model_DrawData
  1826. {
  1827. PageImagePath = page[i - App.PageContextData.pagenum],
  1828. PdfImagePath = page[i - App.PageContextData.pagenum],
  1829. PageNum = i + 1,
  1830. ImgDocumentation = true,
  1831. Type = "word"
  1832. };
  1833. if (App.PageDrawList != null)
  1834. {
  1835. App.PageDrawList.Add(modelDrawData);
  1836. }
  1837. }
  1838. BtnPrint.IsEnabled = true;
  1839. App.SaveDraw();
  1840. num++;
  1841. }
  1842. if (num > 0)
  1843. {
  1844. App.PageContextData.currpage = App.PageContextData.pagenum + 1;
  1845. App.PageContextData.pagenum += num;
  1846. GridPage.Visibility = Visibility.Visible; //页码大于0 显示
  1847. }
  1848. if (App.PageDrawList != null && App.PageContextData.currpage > 0 && App.PageContextData.currpage <= App.PageDrawList.Count)
  1849. {
  1850. ImgCanvas.Source = null;
  1851. ImgPpt.Source = null;
  1852. BtnScreenshot.IsEnabled = false;
  1853. ImgDocumentation.Visibility = Visibility.Visible;
  1854. ImgDocumentation.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath)); //给当前页面展示图片
  1855. ScroMain.ScrollToVerticalOffset(0);
  1856. }
  1857. else
  1858. {
  1859. ImgDocumentation.Source = null;
  1860. ImgCanvas.Source = null;
  1861. ImgPpt.Source = null;
  1862. //截图可用
  1863. BtnScreenshot.IsEnabled = true;
  1864. }
  1865. }
  1866. );
  1867. }
  1868. catch (Exception ex)
  1869. {
  1870. Dispatcher.Invoke
  1871. (
  1872. () =>
  1873. {
  1874. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1875. }
  1876. );
  1877. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
  1878. }
  1879. }
  1880. }
  1881. #region 插入页码
  1882. #endregion 插入页码
  1883. }
  1884. }
  1885. //OpenDialog();
  1886. return "";
  1887. }
  1888. /// <summary>
  1889. /// 截图关闭 非正常关闭截图时,截图清空
  1890. /// </summary>
  1891. private void JietuWindow_click_closeJietuWindowClick()
  1892. {
  1893. if (WindowState == WindowState.Minimized) //截图完恢复窗口
  1894. {
  1895. WindowState = WindowState.Normal;
  1896. }
  1897. App.W_JieTuWindow = null;
  1898. }
  1899. #region 导入转换图片
  1900. #endregion 导入转换图片
  1901. #endregion 导入截图
  1902. #region 上传 列表
  1903. /// <summary>
  1904. /// 搜索集合匹配的索引
  1905. /// </summary>
  1906. /// <typeparam name="T">
  1907. /// </typeparam>
  1908. /// <param name="parent">
  1909. /// </param>
  1910. /// <param name="childName">
  1911. /// </param>
  1912. /// <returns>
  1913. /// </returns>
  1914. public static List<T> FindChilds<T>(DependencyObject parent, string childName) where T : DependencyObject
  1915. {
  1916. List<T> list = new List<T>();
  1917. if (parent == null)
  1918. {
  1919. return list;
  1920. }
  1921. int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
  1922. for (int i = 0; i < childrenCount; i++)
  1923. {
  1924. DependencyObject child = VisualTreeHelper.GetChild(parent, i);
  1925. // 如果子控件不是需查找的控件类型
  1926. T childType = child as T;
  1927. if (childType == null)
  1928. {
  1929. // 在下一级控件中递归查找
  1930. FindChilds<T>(child, childName);
  1931. list.AddRange(FindChilds<T>(child, childName));
  1932. }
  1933. else if (!string.IsNullOrEmpty(childName))
  1934. {
  1935. FrameworkElement frameworkElement = child as FrameworkElement;
  1936. // 如果控件名称符合参数条件
  1937. if (frameworkElement != null && frameworkElement.Name == childName)
  1938. {
  1939. list.Add((T)child);
  1940. }
  1941. }
  1942. else
  1943. {
  1944. // 查找到了控件
  1945. list.Add((T)child);
  1946. }
  1947. }
  1948. return list;
  1949. }
  1950. /// <summary>
  1951. /// 加载视频列表
  1952. /// </summary>
  1953. public void LoadingVideoList()
  1954. {
  1955. try
  1956. {
  1957. _modelVideoList = new List<Model_Video>();
  1958. foreach (Model_WKData vdata in App.WKDataList)
  1959. {
  1960. #region 计时器初始化
  1961. if (vdata.VideoList == null)
  1962. {
  1963. continue;
  1964. }
  1965. foreach (Model_Video videoinfo in vdata.VideoList)
  1966. {
  1967. try
  1968. {
  1969. if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
  1970. {
  1971. continue;
  1972. }
  1973. if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
  1974. {
  1975. videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMB(videoinfo.VideoPath).ToString(CultureInfo.InvariantCulture) + " MB";
  1976. videoinfo.VideoSizebyte = FileToolsCommon.GetFileSize(videoinfo.VideoPath);
  1977. }
  1978. _modelVideoList.Add(videoinfo);
  1979. }
  1980. catch (Exception ex)
  1981. {
  1982. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  1983. }
  1984. }
  1985. #endregion 计时器初始化
  1986. }
  1987. //翻转
  1988. if (_modelVideoList.Count > 1)
  1989. {
  1990. _modelVideoList.Reverse();
  1991. }
  1992. }
  1993. catch (Exception ex)
  1994. {
  1995. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  1996. }
  1997. }
  1998. /// <summary>
  1999. /// 上传事件
  2000. /// </summary>
  2001. /// <param name="sender">
  2002. /// </param>
  2003. /// <param name="e">
  2004. /// </param>
  2005. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  2006. {
  2007. if (GridMyVideo.Visibility == Visibility.Visible)
  2008. {
  2009. GridMyVideo.Visibility = Visibility.Collapsed;
  2010. GridMain.Visibility = Visibility.Visible;
  2011. GridM.IsEnabled = true;
  2012. GridRecordingTitle.Visibility = Visibility.Visible;
  2013. }
  2014. else
  2015. {
  2016. PageHide();
  2017. GridMyVideo.Visibility = Visibility.Visible;
  2018. LoadUploadInitData();
  2019. }
  2020. }
  2021. #endregion 上传 列表
  2022. #region 新上传 显示缩略图
  2023. #region 初始值
  2024. private readonly double _controlHeight = 260;
  2025. private readonly double _controlWidth = 250;
  2026. /// <summary>
  2027. /// 当前页
  2028. /// </summary>
  2029. private int _currentPage = 1;
  2030. /// <summary>
  2031. /// 横向间隔
  2032. /// </summary>
  2033. private double _intervalX;
  2034. /// <summary>
  2035. /// 纵向间隔
  2036. /// </summary>
  2037. private double _intervalY;
  2038. /// <summary>
  2039. /// 页面高
  2040. /// </summary>
  2041. private double _pageH;
  2042. /// <summary>
  2043. /// 每页显示的视频数
  2044. /// </summary>
  2045. private int _pageShowNum;
  2046. /// <summary>
  2047. /// 页面宽
  2048. /// </summary>
  2049. private double _pageW;
  2050. /// <summary>
  2051. /// 总页数
  2052. /// </summary>
  2053. private int _totalPage;
  2054. /// <summary>
  2055. /// 视频信息列表
  2056. /// </summary>
  2057. private readonly List<Uc_VideoItem> _videoControlList = new List<Uc_VideoItem>();
  2058. #endregion 初始值
  2059. /// <summary>
  2060. /// 加载当前页数据
  2061. /// </summary>
  2062. private void LoadCurrentPageData()
  2063. {
  2064. LblVideoPageNum.Content = _currentPage + "/" + _totalPage;
  2065. //隐藏显示的控件
  2066. if (_videoControlList.Count > 0)
  2067. {
  2068. foreach (Uc_VideoItem item in _videoControlList)
  2069. {
  2070. if (item.Visibility != Visibility.Hidden)
  2071. {
  2072. item.Visibility = Visibility.Hidden;
  2073. }
  2074. }
  2075. }
  2076. double w = _intervalX; //每次增加250
  2077. double h = _intervalY; //每次增加260
  2078. //加载控件
  2079. for (int i = 0; i < _pageShowNum; i++)
  2080. {
  2081. int dataIndex = (_currentPage - 1) * _pageShowNum + i;
  2082. if (dataIndex == _modelVideoList.Count)
  2083. {
  2084. return;
  2085. }
  2086. Uc_VideoItem videoItem;
  2087. if (_videoControlList.Exists(x => x.Tag.ToString() == _modelVideoList[dataIndex].FileGuid))
  2088. {
  2089. videoItem = _videoControlList.Find(x => x.Tag.ToString() == _modelVideoList[dataIndex].FileGuid);
  2090. }
  2091. else
  2092. {
  2093. if (!FileToolsCommon.IsExistFile(_modelVideoList[dataIndex].ThumbnailPath))
  2094. {
  2095. continue;
  2096. }
  2097. videoItem = new Uc_VideoItem(_modelVideoList[dataIndex]) { Tag = _modelVideoList[dataIndex].FileGuid };
  2098. videoItem.Click_refreshVideoList += LoadUploadInitData;
  2099. videoItem.Click_UploadLogin += Login;
  2100. videoItem.Width = _controlWidth;
  2101. videoItem.Height = _controlHeight;
  2102. videoItem.HorizontalAlignment = HorizontalAlignment.Left;
  2103. videoItem.VerticalAlignment = VerticalAlignment.Top;
  2104. GridMyVideo.Children.Add(videoItem);
  2105. _videoControlList.Add(videoItem);
  2106. }
  2107. videoItem.Margin = new Thickness
  2108. (
  2109. w,
  2110. h,
  2111. 0,
  2112. 0
  2113. );
  2114. videoItem.Visibility = Visibility.Visible;
  2115. if (w + _controlWidth + _controlWidth > _pageW)
  2116. {
  2117. w = _intervalX;
  2118. h += _controlHeight + _intervalY;
  2119. }
  2120. else
  2121. {
  2122. w += _controlWidth + _intervalX;
  2123. }
  2124. //Uc_VideoItem videoItem = new Uc_VideoItem();
  2125. //return;
  2126. }
  2127. }
  2128. /// <summary>
  2129. /// 初始化加载上传页面数据
  2130. /// </summary>
  2131. private void LoadUploadInitData()
  2132. {
  2133. App.myloading.Show();
  2134. //加载视频列表
  2135. LoadingVideoList();
  2136. if (_modelVideoList.Count > 0)
  2137. {
  2138. LblVideoMess.Visibility = Visibility.Hidden;
  2139. BtnVideoUpPage.Visibility = Visibility.Visible;
  2140. LblVideoPageNum.Visibility = Visibility.Visible;
  2141. BtnVideoDownPage.Visibility = Visibility.Visible;
  2142. if (GridMyVideo.ActualHeight > 0)
  2143. {
  2144. _pageW = GridMyVideo.ActualWidth;
  2145. _pageH = GridMyVideo.ActualHeight;
  2146. }
  2147. else
  2148. {
  2149. _pageW = GridRecordingArea.ActualWidth;
  2150. _pageH = GridRecordingArea.ActualHeight;
  2151. }
  2152. //获取设置控件大小 新增 页面原始1061 911
  2153. //ControlWidth = 250.00 * PropWid;
  2154. //ControlHeight = 260.00 * PropHei;
  2155. //ControlWidth=
  2156. //ControlHeight=
  2157. //根据页面大小获取每页显示的数量 H260W250
  2158. int videoRow = (int)((_pageH - 50) / _controlHeight);
  2159. int videColumn = (int)(_pageW / _controlWidth);
  2160. //横向间隔
  2161. _intervalX = (_pageW - (videColumn * _controlWidth)) / (videColumn + 1);
  2162. _intervalY = (_pageH - 50 - (videoRow * _controlHeight)) / (videoRow + 1);
  2163. _pageShowNum = (videoRow == 0 ? 1 : videoRow) * (videColumn == 0 ? 1 : videColumn);
  2164. //获取总页数
  2165. _totalPage = _modelVideoList.Count / _pageShowNum + (_modelVideoList.Count % _pageShowNum > 0 ? 1 : 0);
  2166. //如果当前页大于总页数 总页数为当前页
  2167. if (_totalPage < _currentPage)
  2168. {
  2169. _currentPage = _totalPage;
  2170. }
  2171. LoadCurrentPageData();
  2172. }
  2173. else
  2174. {
  2175. LblVideoMess.Visibility = Visibility.Visible;
  2176. BtnVideoUpPage.Visibility = Visibility.Hidden;
  2177. LblVideoPageNum.Visibility = Visibility.Hidden;
  2178. BtnVideoDownPage.Visibility = Visibility.Hidden;
  2179. //隐藏显示的控件
  2180. if (_videoControlList.Count > 0)
  2181. {
  2182. foreach (Uc_VideoItem item in _videoControlList)
  2183. {
  2184. if (item.Visibility != Visibility.Hidden)
  2185. {
  2186. item.Visibility = Visibility.Hidden;
  2187. }
  2188. }
  2189. }
  2190. }
  2191. App.myloading.Hide();
  2192. }
  2193. #region 分页
  2194. /// <summary>
  2195. /// 下一页
  2196. /// </summary>
  2197. /// <param name="sender">
  2198. /// </param>
  2199. /// <param name="e">
  2200. /// </param>
  2201. private void BtnVideoDownPage_Click(object sender, RoutedEventArgs e)
  2202. {
  2203. if (_currentPage < _totalPage)
  2204. {
  2205. _currentPage++;
  2206. LoadCurrentPageData();
  2207. }
  2208. }
  2209. /// <summary>
  2210. /// 上一页
  2211. /// </summary>
  2212. /// <param name="sender">
  2213. /// </param>
  2214. /// <param name="e">
  2215. /// </param>
  2216. private void BtnVideoUpPage_Click(object sender, RoutedEventArgs e)
  2217. {
  2218. if (_currentPage > 1)
  2219. {
  2220. _currentPage--;
  2221. LoadCurrentPageData();
  2222. }
  2223. }
  2224. #endregion 分页
  2225. #endregion 新上传 显示缩略图
  2226. #region 录屏
  2227. /// <summary>
  2228. /// 录屏事件
  2229. /// </summary>
  2230. /// <param name="sender">
  2231. /// </param>
  2232. /// <param name="e">
  2233. /// </param>
  2234. private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
  2235. {
  2236. _luoBoPenUtil.lb_device_mouse();
  2237. if (!_microphoneGood)
  2238. {
  2239. MessageWindow.Show("麦克风不可用");
  2240. return;
  2241. }
  2242. if (!_loudspeakerGood)
  2243. {
  2244. MessageWindow.Show("扬声器不可用");
  2245. return;
  2246. }
  2247. PrepareRecord();
  2248. _kHook.Stop();
  2249. if (App.W_ScreenRecordingToolbarWindow == null)
  2250. {
  2251. App.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow { Topmost = true };
  2252. App.W_ScreenRecordingToolbarWindow.Initialize();
  2253. }
  2254. else
  2255. {
  2256. App.W_ScreenRecordingToolbarWindow.Initialize();
  2257. }
  2258. App.W_ScreenRecordingToolbarWindow.ClickStopRecordingScreen += W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen;
  2259. //显示在右下角
  2260. App.W_ScreenRecordingToolbarWindow.WindowStartupLocation = WindowStartupLocation.Manual;
  2261. Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
  2262. float dip = graphics.DpiX;
  2263. App.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.WorkingArea.Width / (dip / 96) - App.W_ScreenRecordingToolbarWindow.Width;
  2264. App.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.WorkingArea.Height / (dip / 96) - App.W_ScreenRecordingToolbarWindow.Height - 100;
  2265. App.W_ScreenRecordingToolbarWindow.Topmost = true;
  2266. App.W_ScreenRecordingToolbarWindow.Show();
  2267. Hide();
  2268. }
  2269. /// <summary>
  2270. /// 保存录屏中
  2271. /// </summary>
  2272. private void W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen()
  2273. {
  2274. TxbTime.Text = "00:00";
  2275. TxbType.Text = "保存中";
  2276. _recordType = 4;
  2277. RecordBtnStatus();
  2278. new Thread
  2279. (
  2280. () =>
  2281. {
  2282. while (FileToolsCommon.IsExistDirectory(App.WKData.WkPath + "_temppath/"))
  2283. {
  2284. Thread.Sleep(100);
  2285. }
  2286. Thread.Sleep(100);
  2287. Dispatcher.Invoke
  2288. (
  2289. () =>
  2290. {
  2291. _recordType = 0;
  2292. RecordBtnStatus();
  2293. }
  2294. );
  2295. }
  2296. ).Start();
  2297. }
  2298. #endregion 录屏
  2299. #region 录制窗口
  2300. #region 变量
  2301. /// <summary>
  2302. /// 录制大小
  2303. /// </summary>
  2304. private int _gridActHeight = 898;
  2305. /// <summary>
  2306. /// 录制大小
  2307. /// </summary>
  2308. private int _gridActWidth = 1276;
  2309. /// <summary>
  2310. /// 录制类型 0停止,1录制中,2暂停中 3倒计时 4合并中
  2311. /// </summary>
  2312. private int _recordType;
  2313. /// <summary>
  2314. /// 录制计时
  2315. /// </summary>
  2316. private DateTime _srTime = DateTime.Now;
  2317. /// <summary>
  2318. /// 音频保存路径名
  2319. /// </summary>
  2320. private string _tempAudioPathName;
  2321. /// <summary>
  2322. /// 视频合成前路径名
  2323. /// </summary>
  2324. private string _tempVideoPathName;
  2325. /// <summary>
  2326. /// 截图定时器
  2327. /// </summary>
  2328. private Timer _timer;
  2329. /// <summary>
  2330. /// 视频保存路径名
  2331. /// </summary>
  2332. private string _videoSavePathName;
  2333. #endregion 变量
  2334. private bool _isPressButton;
  2335. //视频写入
  2336. private readonly VideoFileWriter _videoWriter = new VideoFileWriter();
  2337. //录制麦克风的声音
  2338. private WaveInEvent _waveIn;
  2339. private bool _waveInRuning;
  2340. //音频写入
  2341. private WaveFileWriter _writer;
  2342. /// <summary>
  2343. /// 录制窗口内容
  2344. /// </summary>
  2345. /// <param name="sender">
  2346. /// </param>
  2347. /// <param name="e">
  2348. /// </param>
  2349. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  2350. {
  2351. RecordAction();
  2352. }
  2353. private async void RecordAction()
  2354. {
  2355. #region 防止连击
  2356. if (_isPressButton)
  2357. {
  2358. return;
  2359. }
  2360. _isPressButton = true;
  2361. new Thread
  2362. (
  2363. () =>
  2364. {
  2365. Thread.Sleep(500);
  2366. _isPressButton = false;
  2367. }
  2368. ).Start();
  2369. #endregion 防止连击
  2370. if (_recordType == 4)
  2371. {
  2372. return;
  2373. }
  2374. if (_recordType != 0)
  2375. {
  2376. if (_recordType == 1)
  2377. {
  2378. //录制中暂停
  2379. _recordType = 2;
  2380. RecordBtnStatus();
  2381. }
  2382. else if (_recordType == 2)
  2383. {
  2384. //暂停中继续录制
  2385. _recordType = 1;
  2386. RecordBtnStatus();
  2387. }
  2388. }
  2389. else
  2390. {
  2391. if (App.PageContextData.currpage == 0)
  2392. {
  2393. MessageWindow.Show("请先导入文档或截图!");
  2394. return;
  2395. }
  2396. StartPauseGrid.Visibility = Visibility.Hidden;
  2397. StopGrid.Visibility = Visibility.Hidden;
  2398. CloseGrid.Visibility = Visibility.Hidden;
  2399. if (!_microphoneGood)
  2400. {
  2401. StartPauseGrid.Visibility = Visibility.Visible;
  2402. StopGrid.Visibility = Visibility.Visible;
  2403. CloseGrid.Visibility = Visibility.Visible;
  2404. MessageWindow.Show("麦克风不可用");
  2405. return;
  2406. }
  2407. BlackboardCanvas.Visibility = Visibility.Visible;
  2408. if (RectImgBorder.Visibility != Visibility.Hidden)
  2409. {
  2410. HideAngleBorder();
  2411. }
  2412. PrepareRecord();
  2413. BtnPrint.IsEnabled = false;
  2414. BtnScreenshot.IsEnabled = false;
  2415. BtnImport.IsEnabled = false;
  2416. BtnScreenRecording.IsEnabled = false;
  2417. BtnUpload.IsEnabled = false;
  2418. BtnSetUp.IsEnabled = false;
  2419. BtnDevice.IsEnabled = false;
  2420. BtnLoginType.IsEnabled = false;
  2421. BlackboardCanvas.Visibility = Visibility.Visible;
  2422. TxbType.Text = "准备录制";
  2423. BtnRecord.Visibility = Visibility.Collapsed;
  2424. BtnRecordSuspend.Visibility = Visibility.Visible;
  2425. BtnRecord.IsEnabled = true;
  2426. BtnStop.IsEnabled = true;
  2427. #region 录像倒计时
  2428. if (App.W_CountdownWindow == null)
  2429. {
  2430. App.W_CountdownWindow = new CountdownWindow();
  2431. }
  2432. App.W_CountdownWindow.InitAndShow();
  2433. #endregion 录像倒计时
  2434. await Task.Delay(3000);
  2435. //停止中开始录制
  2436. CloseGrid.Visibility = Visibility.Visible;
  2437. _recordType = 1;
  2438. RecordBtnStatus();
  2439. await StartRecord();
  2440. StartPauseGrid.Visibility = Visibility.Visible;
  2441. StopGrid.Visibility = Visibility.Visible;
  2442. }
  2443. RecordBtnStatus();
  2444. }
  2445. private void RecordBtnStatus()
  2446. {
  2447. if (_recordType == 0)
  2448. {
  2449. StartPauseGrid.Visibility = Visibility.Visible;
  2450. TxbType.Text = "准备录制";
  2451. BtnRecord.Visibility = Visibility.Visible;
  2452. BtnRecordSuspend.Visibility = Visibility.Collapsed;
  2453. BtnScreenRecording.IsEnabled = true;
  2454. BtnRecord.IsEnabled = true;
  2455. BtnStop.IsEnabled = false;
  2456. }
  2457. else if (_recordType == 1)
  2458. {
  2459. StartPauseGrid.Visibility = Visibility.Visible;
  2460. TxbType.Text = "录制中";
  2461. BtnRecord.Visibility = Visibility.Collapsed;
  2462. BtnRecordSuspend.Visibility = Visibility.Visible;
  2463. }
  2464. else if (_recordType == 2)
  2465. {
  2466. StartPauseGrid.Visibility = Visibility.Visible;
  2467. TxbType.Text = "暂停中";
  2468. BtnRecord.Visibility = Visibility.Visible;
  2469. BtnRecordSuspend.Visibility = Visibility.Collapsed;
  2470. }
  2471. else if (_recordType == 3)
  2472. {
  2473. TxbType.Text = "倒计时";
  2474. }
  2475. else if (_recordType == 4)
  2476. {
  2477. TxbType.Text = "合并中";
  2478. StartPauseGrid.Visibility = Visibility.Hidden;
  2479. BtnScreenRecording.IsEnabled = false;
  2480. }
  2481. }
  2482. /// <summary>
  2483. /// 停止录制窗口内容
  2484. /// </summary>
  2485. /// <param name="sender">
  2486. /// </param>
  2487. /// <param name="e">
  2488. /// </param>
  2489. private async void BtnStop_Click(object sender, RoutedEventArgs e)
  2490. {
  2491. #region 防止连击
  2492. if (_isPressButton)
  2493. {
  2494. return;
  2495. }
  2496. else
  2497. {
  2498. _isPressButton = true;
  2499. new Thread
  2500. (
  2501. () =>
  2502. {
  2503. Thread.Sleep(500);
  2504. _isPressButton = false;
  2505. }
  2506. ).Start();
  2507. }
  2508. #endregion 防止连击
  2509. if (_recordType != 0)
  2510. {
  2511. _recordType = 4;
  2512. BlackboardCanvas.Visibility = Visibility.Collapsed;
  2513. RecordBtnStatus();
  2514. //鼠标模式
  2515. _luoBoPenUtil.lb_device_mouse();
  2516. await EndRecord();
  2517. _recordType = 0;
  2518. RecordBtnStatus();
  2519. }
  2520. }
  2521. /// <summary>
  2522. /// 停止录制并生成录制文件
  2523. /// </summary>
  2524. private async Task EndRecord()
  2525. {
  2526. #region 恢复被禁用的按钮
  2527. BtnScreenshot.IsEnabled = true;
  2528. BtnImport.IsEnabled = true;
  2529. BtnScreenRecording.IsEnabled = true;
  2530. BtnUpload.IsEnabled = true;
  2531. BtnSetUp.IsEnabled = true;
  2532. BtnDevice.IsEnabled = true;
  2533. BtnLoginType.IsEnabled = true;
  2534. #endregion 恢复被禁用的按钮
  2535. App.PageContextData.currpage = 0;
  2536. App.PageContextData.pagenum = 0;
  2537. myblackboard.clear();
  2538. App.PageDrawList.Clear();
  2539. ImgCanvas.Source = null;
  2540. ImgDocumentation.Source = null;
  2541. ImgPpt.Source = null;
  2542. GridPage.Visibility = Visibility.Collapsed;
  2543. BtnRecord.IsEnabled = false;
  2544. BtnStop.IsEnabled = false;
  2545. BtnScreenRecording.IsEnabled = false;
  2546. _timer.Change(-1, 0);
  2547. _timer.Dispose();
  2548. TxbTime.Text = "00:00";
  2549. TxbType.Text = "保存中";
  2550. _recordType = 4;
  2551. RecordBtnStatus();
  2552. await Task.Run
  2553. (
  2554. () =>
  2555. {
  2556. try
  2557. {
  2558. _videoWriter.Close();
  2559. _waveIn.StopRecording();
  2560. //等待音频结束回调
  2561. while (_waveInRuning)
  2562. {
  2563. Thread.Sleep(300);
  2564. }
  2565. Process[] killProcessArray = Process.GetProcessesByName("ffmpeg");
  2566. foreach (Process killProcess in killProcessArray)
  2567. {
  2568. killProcess.Kill();
  2569. }
  2570. FFMpegConverter ffMpeg = new FFMpegConverter();
  2571. FFMpegInput[] input =
  2572. {
  2573. new FFMpegInput(_tempVideoPathName),
  2574. new FFMpegInput(_tempAudioPathName)
  2575. };
  2576. // 音视频合并
  2577. ffMpeg.ConvertMedia
  2578. (
  2579. input,
  2580. _videoSavePathName,
  2581. "mp4",
  2582. new OutputSettings()
  2583. );
  2584. //生成缩略图
  2585. string thumbnailPath = FileToolsCommon.GetDirectoryName(_videoSavePathName) + "ThumbnailPath/";
  2586. FileToolsCommon.CreateDirectory(thumbnailPath);
  2587. //缩略图存储位置
  2588. string thumbnailPathName = thumbnailPath + FileToolsCommon.GetIOFileName(_videoSavePathName).Replace(".", "") + ".JPG";
  2589. FileToolsCommon.DeleteFile(thumbnailPathName);
  2590. _videoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2591. _videoInfo.VideoPath = _videoSavePathName;
  2592. _videoInfo.ThumbnailPath = thumbnailPathName;
  2593. _videoInfo.FileGuid = Guid.NewGuid().ToString();
  2594. _videoInfo.IsUpload = false;
  2595. _videoInfo.Uploaded = 0;
  2596. try
  2597. {
  2598. ZVideoRecordHelper.GetVideoPic(_tempVideoPathName, thumbnailPathName);
  2599. }
  2600. catch (Exception ex)
  2601. {
  2602. LogHelper.WriteErrLog("录制生成缩略图", ex);
  2603. }
  2604. if (!App.VideoList.Exists(x => x.FileGuid == _videoInfo.FileGuid) || !App.VideoList.Exists(x => x.VideoPath == _videoInfo.VideoPath))
  2605. {
  2606. App.VideoList.Add(_videoInfo);
  2607. //保存数据
  2608. App.SaveWkData();
  2609. }
  2610. try
  2611. {
  2612. FileToolsCommon.DeleteFile(_tempVideoPathName);
  2613. FileToolsCommon.DeleteFile(_tempAudioPathName);
  2614. }
  2615. catch (Exception ex)
  2616. {
  2617. LogHelper.WriteErrLog("删除录制临时文件", ex);
  2618. }
  2619. }
  2620. catch (Exception ex)
  2621. {
  2622. Dispatcher.Invoke
  2623. (
  2624. () =>
  2625. {
  2626. MessageWindow.Show(ex.Message);
  2627. }
  2628. );
  2629. }
  2630. }
  2631. );
  2632. BtnRecord.IsEnabled = true;
  2633. BtnStop.IsEnabled = false;
  2634. BtnPrint.IsEnabled = false;
  2635. BtnScreenRecording.IsEnabled = true;
  2636. TxbType.Text = "准备就绪";
  2637. _recordType = 0;
  2638. RecordBtnStatus();
  2639. }
  2640. /// <summary>
  2641. /// 录制保存图片
  2642. /// </summary>
  2643. private void RecordSaveImage()
  2644. {
  2645. try
  2646. {
  2647. //保存图片
  2648. try
  2649. {
  2650. Dispatcher.Invoke
  2651. (
  2652. () =>
  2653. {
  2654. Bitmap bm = ImageHelper.SaveUI2Bitmap
  2655. (
  2656. GridMain,
  2657. _gridActWidth,
  2658. _gridActHeight
  2659. );
  2660. _videoWriter.WriteVideoFrame(bm);
  2661. bm.Dispose();
  2662. }
  2663. );
  2664. }
  2665. catch (Exception e)
  2666. {
  2667. Console.WriteLine(e.Message);
  2668. }
  2669. }
  2670. catch (Exception ex)
  2671. {
  2672. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  2673. }
  2674. }
  2675. //new WaveInEvent();
  2676. /// <summary>
  2677. /// 开始录制和暂停录制
  2678. /// </summary>
  2679. private async Task StartRecord()
  2680. {
  2681. await Task.Run
  2682. (
  2683. () =>
  2684. {
  2685. //电子版切换笔模式
  2686. _luoBoPenUtil.lb_device_hand();
  2687. _videoInfo = new Model_Video
  2688. {
  2689. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  2690. WkType = Enum_WKVidetype.RecordingLessons
  2691. };
  2692. FileToolsCommon.DeleteDirectory(App.WKData.WkPath + "temp/");
  2693. FileToolsCommon.CreateDirectory(App.WKData.WkPath);
  2694. _videoSavePathName = App.WKData.WkPath + App.WKData.WkName + "_录制." + _videoInfo.VideoType.ToString();
  2695. _tempVideoPathName = App.WKData.WkPath + App.WKData.WkName + "_录制Syn.avi";
  2696. int num = 1;
  2697. while (FileToolsCommon.IsExistFile(_videoSavePathName))
  2698. {
  2699. _videoSavePathName = App.WKData.WkPath + App.WKData.WkName + "_录制_" + num + "." + _videoInfo.VideoType.ToString();
  2700. _tempVideoPathName = App.WKData.WkPath + App.WKData.WkName + "_录制Syn_" + num + ".avi";
  2701. num++;
  2702. }
  2703. _tempAudioPathName = _tempVideoPathName.Replace(".avi", ".mp3");
  2704. _gridActWidth = (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f) / 2) * 2;
  2705. _gridActHeight = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f) / 2) * 2;
  2706. lock (this)
  2707. {
  2708. _videoWriter.Open
  2709. (
  2710. _tempVideoPathName,
  2711. _gridActWidth,
  2712. _gridActHeight,
  2713. 5,
  2714. VideoCodec.MPEG4,
  2715. _gridActWidth * _gridActHeight * 10
  2716. );
  2717. _waveIn = new WaveInEvent();
  2718. _waveInRuning = true;
  2719. _writer = new WaveFileWriter(_tempAudioPathName, _waveIn.WaveFormat);
  2720. //开始录音,写数据
  2721. _waveIn.DataAvailable += (s, a) =>
  2722. {
  2723. if (_recordType == 1)
  2724. {
  2725. _writer.Write
  2726. (
  2727. a.Buffer,
  2728. 0,
  2729. a.BytesRecorded
  2730. );
  2731. }
  2732. };
  2733. //结束录音
  2734. _waveIn.RecordingStopped += (s, a) =>
  2735. {
  2736. _writer.Dispose();
  2737. _writer = null;
  2738. _waveIn.Dispose();
  2739. _waveInRuning = false;
  2740. };
  2741. _waveIn.StartRecording();
  2742. }
  2743. }
  2744. );
  2745. _srTime = Convert.ToDateTime("2020-01-01 00:00:00");
  2746. //启动截图
  2747. _timer = new Timer
  2748. (
  2749. Timer_Elapsed,
  2750. null,
  2751. 0,
  2752. 200
  2753. );
  2754. }
  2755. /// <summary>
  2756. /// 录制保存图片计时器
  2757. /// </summary>
  2758. /// <param name="sender">
  2759. /// </param>
  2760. private void Timer_Elapsed(object sender)
  2761. {
  2762. if (_recordType == 1)
  2763. {
  2764. Dispatcher.Invoke
  2765. (
  2766. () =>
  2767. {
  2768. _srTime = _srTime.AddMilliseconds(200);
  2769. if (_srTime.Hour > 0)
  2770. {
  2771. TxbTime.Text = _srTime.ToString("HH:mm:ss");
  2772. }
  2773. else
  2774. {
  2775. TxbTime.Text = _srTime.ToString("mm:ss");
  2776. }
  2777. }
  2778. );
  2779. ThreadPool.QueueUserWorkItem
  2780. (
  2781. o =>
  2782. {
  2783. RecordSaveImage();
  2784. }
  2785. );
  2786. }
  2787. }
  2788. #endregion 录制窗口
  2789. #region 分页
  2790. private void ImgXy()
  2791. {
  2792. ImgCanvas.Width = App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes.CenterX;
  2793. ImgCanvas.Height = App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes.CenterY;
  2794. ImgCanvas.Margin = new Thickness
  2795. (
  2796. App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.X,
  2797. App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.Y,
  2798. 0,
  2799. 0
  2800. );
  2801. }
  2802. /// <summary>
  2803. /// 跳转
  2804. /// </summary>
  2805. private void JumpPageClick()
  2806. {
  2807. myblackboard.changepage(App.PageContextData.currpage - 1);
  2808. ScroMain.ScrollToVerticalOffset(0);
  2809. if (BtnImport.IsEnabled)
  2810. {
  2811. //截图可用
  2812. BtnScreenshot.IsEnabled = true;
  2813. }
  2814. if (App.PageContextData.currpage <= App.PageDrawList.Count)
  2815. {
  2816. if (App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation != null)
  2817. {
  2818. App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = true;
  2819. }
  2820. if (!string.IsNullOrWhiteSpace(TxbCurrpage.Text) && App.PageContextData.currpage <= App.PageDrawList.Count && App.PageContextData.currpage > 0 && !string.IsNullOrWhiteSpace(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath))
  2821. {
  2822. if (App.PageDrawList[App.PageContextData.currpage - 1].ImgDocumentation)
  2823. {
  2824. if ("ppt".Equals(App.PageDrawList[App.PageContextData.currpage - 1].Type))
  2825. {
  2826. ImgCanvas.Source = null;
  2827. ImgDocumentation.Source = null;
  2828. ImgPpt.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
  2829. BtnScreenshot.IsEnabled = false;
  2830. }
  2831. else
  2832. {
  2833. ImgPpt.Source = null;
  2834. ImgCanvas.Source = null;
  2835. ImgDocumentation.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
  2836. BtnScreenshot.IsEnabled = false;
  2837. }
  2838. }
  2839. else
  2840. {
  2841. ImgPpt.Source = null;
  2842. ImgDocumentation.Source = null;
  2843. ImgCanvas.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
  2844. App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = false;
  2845. if (App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation != null && App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.X > 0)
  2846. {
  2847. _mouseDown = false;
  2848. _imageOperationUtil.setMouseDown(_mouseDown);
  2849. ImgXy();
  2850. }
  2851. }
  2852. }
  2853. else
  2854. {
  2855. ImgPpt.Source = null;
  2856. ImgCanvas.Source = null;
  2857. ImgDocumentation.Source = null;
  2858. }
  2859. }
  2860. }
  2861. // 上一页
  2862. private void last_button_Click(object sender, RoutedEventArgs e)
  2863. {
  2864. if (App.PageContextData.currpage > 1)
  2865. {
  2866. _mouseDown = false;
  2867. _imageOperationUtil.setMouseDown(_mouseDown);
  2868. HideAngleBorder();
  2869. App.PageContextData.currpage -= 1;
  2870. JumpPageClick();
  2871. }
  2872. }
  2873. /// <summary>
  2874. /// 下一页
  2875. /// </summary>
  2876. /// <param name="sender">
  2877. /// </param>
  2878. /// <param name="e">
  2879. /// </param>
  2880. private void next_btn_Click(object sender, RoutedEventArgs e)
  2881. {
  2882. if (App.PageContextData.currpage < App.PageContextData.pagenum)
  2883. {
  2884. _mouseDown = false;
  2885. _imageOperationUtil.setMouseDown(_mouseDown);
  2886. HideAngleBorder();
  2887. App.PageContextData.currpage += 1;
  2888. JumpPageClick();
  2889. }
  2890. }
  2891. #endregion 分页
  2892. #region 图像缩放,移动
  2893. private bool _mouseDown;
  2894. #endregion 图像缩放,移动
  2895. #region 更改设备连接状态
  2896. /// <summary>
  2897. /// 更新设备状态显示
  2898. /// </summary>
  2899. public void UpdateDevStatus()
  2900. {
  2901. if (App.BoardStatus && (App.PenStatus || App.TQLPenStatus))
  2902. {
  2903. Dispatcher.Invoke
  2904. (
  2905. () =>
  2906. {
  2907. TxbNotConnected.Text = "笔/板已连接";
  2908. TxbNotConnecteds.Text = "笔/板已连接";
  2909. }
  2910. );
  2911. }
  2912. else if (App.BoardStatus)
  2913. {
  2914. Dispatcher.Invoke
  2915. (
  2916. () =>
  2917. {
  2918. TxbNotConnected.Text = "手写板已连接";
  2919. TxbNotConnecteds.Text = "手写板已连接";
  2920. }
  2921. );
  2922. }
  2923. else if (App.PenStatus)
  2924. {
  2925. Dispatcher.Invoke
  2926. (
  2927. () =>
  2928. {
  2929. TxbNotConnected.Text = "智能笔已连接";
  2930. TxbNotConnecteds.Text = "智能笔已连接";
  2931. }
  2932. );
  2933. }
  2934. else if (App.TQLPenStatus)
  2935. {
  2936. Dispatcher.Invoke
  2937. (
  2938. () =>
  2939. {
  2940. TxbNotConnected.Text = "智能笔已连接";
  2941. TxbNotConnecteds.Text = "智能笔已连接";
  2942. }
  2943. );
  2944. }
  2945. else
  2946. {
  2947. Dispatcher.Invoke
  2948. (
  2949. () =>
  2950. {
  2951. TxbNotConnected.Text = "未连接";
  2952. TxbNotConnecteds.Text = "未连接";
  2953. }
  2954. );
  2955. }
  2956. }
  2957. #endregion 更改设备连接状态
  2958. #region 腾千里手写笔
  2959. private const float TQLA4_HEIGHT = 1.0f * 3509 / 300 * (float)25.4 / (float)1.524;
  2960. /// <summary>
  2961. /// TQL点阵笔宽高
  2962. /// </summary>
  2963. private const float TQLA4_WIDTH = 1.0f * 2480 / 300 * (float)25.4 / (float)1.524;
  2964. /// <summary>
  2965. /// 是否在书写
  2966. /// </summary>
  2967. private bool _isTqlPenDown;
  2968. //(float)1075 / (float)150 * (float)25.4 / (float)1.524; //OID4
  2969. //(float)1512 / (float)150 * (float)25.4 / (float)1.524;
  2970. /// <summary>
  2971. /// TQL初始化
  2972. /// </summary>
  2973. public void InitTqlpPen()
  2974. {
  2975. if (App.TQLPenevents == null)
  2976. {
  2977. App.TQLPenevents = new PenEvents(1);
  2978. }
  2979. else
  2980. {
  2981. App.TQLPenevents.InToType = 1;
  2982. }
  2983. }
  2984. /// <summary>
  2985. /// 笔落下
  2986. /// </summary>
  2987. public void TqlDown()
  2988. {
  2989. _isTqlPenDown = true;
  2990. if (App.PageContextData.currpage > 0)
  2991. {
  2992. Dispatcher.Invoke
  2993. (
  2994. () =>
  2995. {
  2996. myblackboard.changepages
  2997. (
  2998. 0,
  2999. 0,
  3000. true,
  3001. _color,
  3002. _penSize,
  3003. App.PageContextData.currpage - 1,
  3004. 0
  3005. );
  3006. }
  3007. );
  3008. }
  3009. }
  3010. /// <summary>
  3011. /// 笔书写
  3012. /// </summary>
  3013. /// <param name="cx">
  3014. /// </param>
  3015. /// <param name="cy">
  3016. /// </param>
  3017. /// <param name="force">
  3018. /// </param>
  3019. public void TqlPenWrite
  3020. (
  3021. double cx,
  3022. double cy,
  3023. int force
  3024. )
  3025. {
  3026. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  3027. if (!_isTqlPenDown)
  3028. {
  3029. return;
  3030. }
  3031. double propW = BlackboardCanvas.ActualWidth / TQLA4_WIDTH;
  3032. double propH = BlackboardCanvas.ActualHeight / TQLA4_HEIGHT;
  3033. //点
  3034. double tempX = cx * propW;
  3035. double tempY = cy * propH;
  3036. if (App.PageContextData.currpage > 0)
  3037. {
  3038. Dispatcher.Invoke
  3039. (
  3040. () =>
  3041. {
  3042. //0~1023,亦即有 1024 阶供应用软件后续应用之用,如笔锋笔触,暂无用
  3043. float pressure = 1.0f * force / 1023f;
  3044. myblackboard.changepages
  3045. (
  3046. tempX,
  3047. tempY,
  3048. false,
  3049. _color,
  3050. _penSize,
  3051. App.PageContextData.currpage - 1,
  3052. pressure
  3053. );
  3054. #region 设置滚动条位置
  3055. //点在显示页面上方
  3056. if (tempY < ScroMain.VerticalOffset)
  3057. {
  3058. //滚动条当前位置
  3059. double rollCurrentLocation = ScroMain.VerticalOffset;
  3060. //向上滚动至以点为中心需要滚动的距离
  3061. double upRoll = (rollCurrentLocation - tempY) + (ScroMain.ActualHeight / 2);
  3062. //如果小于0则等于0
  3063. double rollLocation = rollCurrentLocation - upRoll;
  3064. if (rollLocation < 0)
  3065. {
  3066. rollLocation = 0;
  3067. }
  3068. ////滚动条实际偏移量
  3069. //double RollOffset = RollCurrentLocation - RollLocation;
  3070. ScroMain.ScrollToVerticalOffset(rollLocation);
  3071. }
  3072. //点在显示页面下方
  3073. if (tempY > ScroMain.VerticalOffset + ScroMain.ActualHeight)
  3074. {
  3075. //滚动条当前位置
  3076. double rollCurrentLocation = ScroMain.VerticalOffset;
  3077. //向下滚动至以点为中心需要滚动的距离
  3078. double downRoll = (tempY - rollCurrentLocation) - (ScroMain.ActualHeight / 2);
  3079. //如果小于0则等于0
  3080. double rollLocation = rollCurrentLocation + downRoll;
  3081. //滚动条最大滚动值
  3082. double scrollbarMaxNum = GridM.ActualHeight - ScroMain.ActualHeight;
  3083. if (rollLocation > scrollbarMaxNum)
  3084. {
  3085. rollLocation = scrollbarMaxNum;
  3086. }
  3087. ////滚动条实际偏移量
  3088. //double RollOffset = RollLocation-RollCurrentLocation;
  3089. ScroMain.ScrollToVerticalOffset(rollLocation);
  3090. }
  3091. #endregion 设置滚动条位置
  3092. if (tempX > 0 && tempY > 0)
  3093. {
  3094. System.Windows.Point getP = ScroMain.PointToScreen(new System.Windows.Point(tempX, tempY - ScroMain.VerticalOffset));
  3095. SetCursorPos((int)getP.X, (int)getP.Y);
  3096. }
  3097. }
  3098. );
  3099. }
  3100. }
  3101. /// <summary>
  3102. /// 笔抬起
  3103. /// </summary>
  3104. public void TqlUp()
  3105. {
  3106. _isTqlPenDown = false;
  3107. //stroke.Clear();
  3108. if (App.PageContextData.currpage > 0)
  3109. {
  3110. Dispatcher.Invoke
  3111. (
  3112. () =>
  3113. {
  3114. myblackboard.changepages
  3115. (
  3116. 0,
  3117. 0,
  3118. true,
  3119. _color,
  3120. _penSize,
  3121. App.PageContextData.currpage - 1,
  3122. 0
  3123. );
  3124. }
  3125. );
  3126. }
  3127. }
  3128. #endregion 腾千里手写笔
  3129. #region 图片拉伸移动
  3130. /// <summary>
  3131. /// 隐藏图片四个点和线
  3132. /// </summary>
  3133. private void HideAngleBorder()
  3134. {
  3135. _imageOperationUtil.HideAngleBorder();
  3136. }
  3137. private void imgCanvas_MouseMove(object sender, MouseEventArgs e)
  3138. {
  3139. _imageOperationUtil.imgCanvas_MouseMove(sender, e);
  3140. }
  3141. private void imgCanvas_MouseUp(object sender, MouseButtonEventArgs e)
  3142. {
  3143. _imageOperationUtil.imgCanvas_MouseUp();
  3144. }
  3145. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  3146. {
  3147. _imageOperationUtil.PicEMap_MouseDown(sender, e);
  3148. }
  3149. private void RectRightUp_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
  3150. {
  3151. _imageOperationUtil.RectRightUp_DragCompleted();
  3152. }
  3153. private void RectRightUp_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
  3154. {
  3155. _imageOperationUtil.RectRightUp_DragDelta(sender, e);
  3156. }
  3157. private void RectRightUp_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
  3158. {
  3159. _imageOperationUtil.RectRightUp_DragStarted(sender, e);
  3160. }
  3161. /// <summary>
  3162. /// 鼠标左键点击事件
  3163. /// </summary>
  3164. /// <param name="sender">
  3165. /// </param>
  3166. /// <param name="e">
  3167. /// </param>
  3168. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  3169. {
  3170. _imageOperationUtil.Window_MouseLeftButtonDown_1();
  3171. }
  3172. #endregion 图片拉伸移动
  3173. #region 录屏 录制 截图 导入文档 增加 主页面显示
  3174. /// <summary>
  3175. /// 录屏 录制 截图 导入文档 增加 主页面显示
  3176. /// </summary>
  3177. private void PrepareRecord()
  3178. {
  3179. PageHide();
  3180. GridMain.Visibility = Visibility.Visible;
  3181. GridRecordingTitle.Visibility = Visibility.Visible;
  3182. if (App.PageContextData.pagenum > 0)
  3183. {
  3184. GridPage.Visibility = Visibility.Visible;
  3185. }
  3186. DataContext = App.PageContextData;
  3187. }
  3188. #endregion 录屏 录制 截图 导入文档 增加 主页面显示
  3189. #region 页码跳转
  3190. #endregion 页码跳转
  3191. #region TQL打印
  3192. public static string gPrintFileName;
  3193. private iTextSharp.text.Document _document;
  3194. private bool _gbInitDone;
  3195. /// <summary>
  3196. /// 授权码
  3197. /// </summary>
  3198. private string _gKeyStr;
  3199. private readonly TmatrixClass _tmc = new TmatrixClass();
  3200. /// <summary>
  3201. /// 授权文件位置
  3202. /// </summary>
  3203. private string _tqlAuthorizationPath;
  3204. /// <summary>
  3205. /// 铺码
  3206. /// </summary>
  3207. private bool GenerateCode(string pdfPath)
  3208. {
  3209. try
  3210. {
  3211. if (_gbInitDone == false)
  3212. {
  3213. MessageWindow.Show("打印功能无法使用,无效授权。");
  3214. return false;
  3215. }
  3216. try
  3217. {
  3218. string directoryPath = FileToolsCommon.GetDirectoryName(pdfPath);
  3219. FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Images/");
  3220. FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Vector Images/");
  3221. FileToolsCommon.DeleteDirectory(directoryPath + "Bg without Vector Images/");
  3222. FileToolsCommon.DeleteDirectory(directoryPath + "Vector Images/");
  3223. }
  3224. catch (Exception)
  3225. {
  3226. // ignored
  3227. }
  3228. pdfPath = pdfPath.Replace("/", "\\");
  3229. //初始页
  3230. bool[] bPublishImageType = new bool[4];
  3231. bPublishImageType[0] = false;
  3232. bPublishImageType[1] = false;
  3233. bPublishImageType[2] = false;
  3234. bPublishImageType[3] = true;
  3235. int[] gPointType =
  3236. {
  3237. 0,
  3238. 0,
  3239. 0,
  3240. 0,
  3241. 1
  3242. };
  3243. int[] gPointDpi =
  3244. {
  3245. 0,
  3246. 0,
  3247. 0,
  3248. 0,
  3249. 1
  3250. };
  3251. string sGenerateResult = _tmc.GenerateTmatrixCode_OID4
  3252. (
  3253. _gKeyStr,
  3254. pdfPath,
  3255. 0,
  3256. gPointType,
  3257. bPublishImageType,
  3258. gPointDpi
  3259. );
  3260. if (sGenerateResult.Substring(0, 1) == "1")
  3261. {
  3262. Dispatcher.Invoke
  3263. (
  3264. () =>
  3265. {
  3266. MessageWindow.Show("打印功能无法使用,无效授权。");
  3267. }
  3268. );
  3269. return false;
  3270. }
  3271. return true;
  3272. }
  3273. catch (Exception ex)
  3274. {
  3275. Dispatcher.Invoke
  3276. (
  3277. () =>
  3278. {
  3279. MessageWindow.Show("打印失败:" + ex.Message);
  3280. }
  3281. );
  3282. return false;
  3283. }
  3284. }
  3285. /// <summary>
  3286. /// TQL初始化打印
  3287. /// </summary>
  3288. private void TqlPrintInit()
  3289. {
  3290. //初始化
  3291. if (_tmc.TmatrixInitialize() == false)
  3292. {
  3293. }
  3294. else
  3295. {
  3296. _gbInitDone = true;
  3297. }
  3298. _document = new iTextSharp.text.Document
  3299. (
  3300. iTextSharp.text.PageSize.A4,
  3301. 0,
  3302. 0,
  3303. 0,
  3304. 0
  3305. );
  3306. try
  3307. {
  3308. _tqlAuthorizationPath = FileToolsCommon.GetFileAbsolutePath("/LatticeXML/S0_O000_B0000_P000-255.tmx");
  3309. StreamReader gsr = new StreamReader(_tqlAuthorizationPath);
  3310. _gKeyStr = gsr.ReadLine();
  3311. gsr.Close();
  3312. string keyCheckResult = _tmc.TmatrixKeyCheck_OID4(_gKeyStr);
  3313. if (keyCheckResult.Substring(0, 1) == "1")
  3314. {
  3315. MessageWindow.Show("打印服务授权过期,请联系厂家更换授权!");
  3316. LogHelper.WriteErrLog("打印服务授权过期:" + keyCheckResult, null);
  3317. _gbInitDone = false;
  3318. }
  3319. else if (keyCheckResult.Substring(0, 1) == "0")
  3320. {
  3321. }
  3322. }
  3323. catch (Exception ex)
  3324. {
  3325. LogHelper.WriteErrLog("打印服务授权失败:" + ex.Message, ex);
  3326. MessageWindow.Show("打印服务授权失败,请联系厂家!");
  3327. _gbInitDone = false;
  3328. }
  3329. }
  3330. #endregion TQL打印
  3331. #region 打印界面
  3332. private double _hei;
  3333. private int _msgnum;
  3334. private int _num;
  3335. /// <summary>
  3336. /// 打印状态消息
  3337. /// </summary>
  3338. private string _printMsg = "打印中";
  3339. /// <summary>
  3340. /// 打印进度
  3341. /// </summary>
  3342. private System.Timers.Timer _timesPrint;
  3343. /// <summary>
  3344. /// 打印消息
  3345. /// </summary>
  3346. private System.Timers.Timer _timesPrintMsg;
  3347. private double _wit;
  3348. /// <summary>
  3349. /// 初始化页面
  3350. /// </summary>
  3351. /// <param name="imgPath">
  3352. /// </param>
  3353. /// <param name="wit">
  3354. /// </param>
  3355. /// <param name="hei">
  3356. /// </param>
  3357. public void InitializePrint
  3358. (
  3359. string imgPath,
  3360. double wit,
  3361. double hei
  3362. )
  3363. {
  3364. this._wit = wit;
  3365. this._hei = hei;
  3366. if (!string.IsNullOrWhiteSpace(imgPath))
  3367. {
  3368. ImgPri.Source = new BitmapImage(new Uri(imgPath));
  3369. }
  3370. else
  3371. {
  3372. ImgPri.Source = null;
  3373. }
  3374. GridPrintMask.Visibility = Visibility.Collapsed;
  3375. }
  3376. /// <summary>
  3377. /// 打印初始化
  3378. /// </summary>
  3379. public void InitPrint()
  3380. {
  3381. ResizeMode = ResizeMode.NoResize;
  3382. TqlPrintInit();
  3383. }
  3384. /// <summary>
  3385. /// 生成图片
  3386. /// </summary>
  3387. /// <param name="path">
  3388. /// 图片地址
  3389. /// </param>
  3390. /// <param name="saveimg">
  3391. /// 保存位置
  3392. /// </param>
  3393. /// <param name="rectangle">
  3394. /// 图片位置
  3395. /// </param>
  3396. /// <returns>
  3397. /// </returns>
  3398. private bool MergerPrintImg
  3399. (
  3400. string path,
  3401. string saveimg,
  3402. RectangleF rectangle
  3403. )
  3404. {
  3405. try
  3406. {
  3407. Bitmap bitmap = null;
  3408. //创建要显示的图片对象,根据参数的个数设置宽度
  3409. Bitmap backgroudImg = new Bitmap((int) /*GridM.ActualWidth*/_wit, (int) /*GridM.ActualHeight*/_hei);
  3410. Graphics g = Graphics.FromImage(backgroudImg);
  3411. //清除画布,背景设置为白色
  3412. g.Clear(System.Drawing.Color.White);
  3413. if (!string.IsNullOrWhiteSpace(path))
  3414. {
  3415. bitmap = ImageHelper.ReadBitmapFile(path);
  3416. g.DrawImage(bitmap, rectangle);
  3417. }
  3418. #region 添加箭头
  3419. string str = "↑";
  3420. SolidBrush mybrush = new SolidBrush(System.Drawing.Color.Black); //设置默认画刷颜色
  3421. Font myfont = new Font("黑体", 14); //设置默认字体格式
  3422. g.DrawString
  3423. (
  3424. str,
  3425. myfont,
  3426. mybrush,
  3427. new Rectangle
  3428. (
  3429. (int)_wit - 50,
  3430. 20,
  3431. 50,
  3432. 50
  3433. )
  3434. );
  3435. #endregion 添加箭头
  3436. backgroudImg.Save(saveimg);
  3437. g.Dispose();
  3438. backgroudImg.Dispose();
  3439. if (bitmap != null)
  3440. {
  3441. bitmap.Dispose();
  3442. }
  3443. GC.Collect();
  3444. return true;
  3445. }
  3446. catch (Exception ex)
  3447. {
  3448. LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
  3449. return false;
  3450. }
  3451. }
  3452. /// <summary>
  3453. /// 开始打印
  3454. /// </summary>
  3455. private void StartPrint(PrintModel printModel)
  3456. {
  3457. try
  3458. {
  3459. _document = new iTextSharp.text.Document
  3460. (
  3461. iTextSharp.text.PageSize.A4,
  3462. 0f,
  3463. 0f,
  3464. 0f,
  3465. 0f
  3466. );
  3467. _printMsg = "生成文件";
  3468. _msgnum = 0;
  3469. string sourcePath1 = printModel.filepath;
  3470. try
  3471. {
  3472. sourcePath1 = sourcePath1.Replace("/", "\\");
  3473. FileStream fs = new FileStream
  3474. (
  3475. sourcePath1,
  3476. FileMode.Create,
  3477. FileAccess.ReadWrite
  3478. );
  3479. _document.AddAuthor("星火微课"); //作者
  3480. _document.AddCreationDate(); //创建时候
  3481. _document.AddCreator("星火微课"); //创建者
  3482. _document.AddSubject("点阵文件"); //主题
  3483. _document.AddTitle("PrintTmatrixCode"); //标题
  3484. _document.AddKeywords("Print");
  3485. _document.AddHeader("TmatrixCode", "0");
  3486. iTextSharp.text.pdf.PdfWriter.GetInstance(_document, fs);
  3487. }
  3488. catch (Exception)
  3489. {
  3490. // ignored
  3491. }
  3492. _document.Open();
  3493. iTextSharp.text.Image image;
  3494. for (int i = 0; i < App.PageDrawList.Count; i++)
  3495. {
  3496. long ii = Timestamp();
  3497. string directoryPath = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  3498. string filePathOutPut = Path.Combine
  3499. (
  3500. directoryPath,
  3501. string.Format
  3502. (
  3503. "print{0}{1}.jpg",
  3504. ii,
  3505. i
  3506. )
  3507. );
  3508. RectangleF rectangleFs = new RectangleF();
  3509. MergerPrintImg
  3510. (
  3511. "",
  3512. filePathOutPut,
  3513. rectangleFs
  3514. );
  3515. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  3516. if (string.IsNullOrEmpty(App.PageDrawList[i].PageImagePath)) //没有图片
  3517. {
  3518. }
  3519. else if (App.PageDrawList[i].ImgDocumentation && !App.PageDrawList[i].Type.Equals("ppt"))
  3520. {
  3521. image = iTextSharp.text.Image.GetInstance(App.PageDrawList[i].PageImagePath);
  3522. }
  3523. else
  3524. {
  3525. RectangleF rectangleF = new RectangleF
  3526. (
  3527. 0,
  3528. 0,
  3529. 0,
  3530. 0
  3531. );
  3532. var i1 = i;
  3533. Dispatcher.Invoke
  3534. (
  3535. () =>
  3536. {
  3537. rectangleF = new RectangleF
  3538. {
  3539. Width = (float)App.PageDrawList[i1].ImageSizes.CenterX,
  3540. Height = (float)App.PageDrawList[i1].ImageSizes.CenterY,
  3541. X = (float)App.PageDrawList[i1].ImageLocation.X,
  3542. Y = (float)App.PageDrawList[i1].ImageLocation.Y
  3543. };
  3544. }
  3545. );
  3546. bool isImg = MergerPrintImg
  3547. (
  3548. App.PageDrawList[i].PageImagePath,
  3549. filePathOutPut,
  3550. rectangleF
  3551. );
  3552. if (isImg)
  3553. {
  3554. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  3555. }
  3556. else
  3557. {
  3558. image = iTextSharp.text.Image.GetInstance(App.PageDrawList[i].PageImagePath);
  3559. }
  3560. }
  3561. if (image.Height > iTextSharp.text.PageSize.A4.Height)
  3562. {
  3563. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  3564. }
  3565. else if (image.Width > iTextSharp.text.PageSize.A4.Width)
  3566. {
  3567. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  3568. }
  3569. image.Alignment = iTextSharp.text.Element.ALIGN_MIDDLE;
  3570. _document.NewPage();
  3571. _document.Add(image);
  3572. }
  3573. _document.Close();
  3574. }
  3575. catch (Exception ex)
  3576. {
  3577. Dispatcher.Invoke
  3578. (
  3579. () =>
  3580. {
  3581. BtnPrint.IsEnabled = true;
  3582. _timesPrint.Stop();
  3583. _timesPrintMsg.Stop();
  3584. GridPrintMask.Visibility = Visibility.Collapsed;
  3585. MessageWindow.Show(ex.Message);
  3586. }
  3587. );
  3588. LogHelper.WriteErrLog("打印转换PDF失败,原因:" + ex.Message, ex);
  3589. }
  3590. //PDF位置
  3591. string sourcePath = printModel.filepath;
  3592. if (_isHasCode)
  3593. {
  3594. _printMsg = "铺码中";
  3595. _msgnum = 0;
  3596. Thread.Sleep(500);
  3597. //腾千里生成点阵文件
  3598. if (GenerateCode(sourcePath))
  3599. {
  3600. //打印机名称
  3601. string directoryPath = FileToolsCommon.GetDirectoryName(sourcePath) + "Bg with Images/";
  3602. string[] strs = FileToolsCommon.GetFileNames(directoryPath);
  3603. try
  3604. {
  3605. // 腾千里会根据原PDF的页数生成多个PDF文件
  3606. for (int i = 0; i < strs.Count(); i++)
  3607. {
  3608. _timesPrint.Stop();
  3609. _printMsg = "正在打印第" + (i + 1) + "/" + strs.Count() + "页中";
  3610. _msgnum = 0;
  3611. _num = 0;
  3612. _timesPrint.Interval = 100;
  3613. _timesPrint.Start();
  3614. string fileName = strs[i];
  3615. //打印文件
  3616. ZPrintUtils.Print2(fileName);
  3617. }
  3618. Dispatcher.Invoke
  3619. (
  3620. () =>
  3621. {
  3622. BtnPrint.IsEnabled = true;
  3623. _num = 99;
  3624. _timesPrint.Stop();
  3625. PgbProcess.Value = 100;
  3626. LbProcess.Content = "100%";
  3627. GridPrintMask.Visibility = Visibility.Collapsed;
  3628. //MessageWindow.Show("已加入打印机队列,打印中。");
  3629. }
  3630. );
  3631. }
  3632. catch (Exception ex)
  3633. {
  3634. Dispatcher.Invoke
  3635. (
  3636. () =>
  3637. {
  3638. MessageWindow.Show("打印失败:" + ex.Message);
  3639. BtnPrint.IsEnabled = true;
  3640. _timesPrint.Stop();
  3641. GridPrintMask.Visibility = Visibility.Collapsed;
  3642. }
  3643. );
  3644. }
  3645. }
  3646. else
  3647. {
  3648. Dispatcher.Invoke
  3649. (
  3650. () =>
  3651. {
  3652. BtnPrint.IsEnabled = true;
  3653. _timesPrint.Stop();
  3654. _timesPrintMsg.Stop();
  3655. GridPrintMask.Visibility = Visibility.Collapsed;
  3656. }
  3657. );
  3658. }
  3659. }
  3660. else
  3661. {
  3662. //打印文件
  3663. ZPrintUtils.Print2(sourcePath);
  3664. Dispatcher.Invoke
  3665. (
  3666. () =>
  3667. {
  3668. BtnPrint.IsEnabled = true;
  3669. _num = 99;
  3670. _timesPrint.Stop();
  3671. PgbProcess.Value = 100;
  3672. LbProcess.Content = "100%";
  3673. GridPrintMask.Visibility = Visibility.Collapsed;
  3674. //MessageWindow.Show("已加入打印机队列,打印中。");
  3675. }
  3676. );
  3677. }
  3678. }
  3679. /// <summary>
  3680. /// 计时器
  3681. /// </summary>
  3682. /// <param name="sender">
  3683. /// </param>
  3684. /// <param name="e">
  3685. /// </param>
  3686. private void Times_ElapsedClick(object sender, System.Timers.ElapsedEventArgs e)
  3687. {
  3688. Dispatcher.Invoke
  3689. (
  3690. () =>
  3691. {
  3692. PgbProcess.Value = _num;
  3693. LbProcess.Content = _num + "%";
  3694. if (_num < 99)
  3695. {
  3696. _num++;
  3697. _timesPrint.Interval += 1.0 * _num / 2;
  3698. }
  3699. else
  3700. {
  3701. _timesPrint.Stop();
  3702. }
  3703. }
  3704. );
  3705. }
  3706. /// <summary>
  3707. /// 消息
  3708. /// </summary>
  3709. /// <param name="sender">
  3710. /// </param>
  3711. /// <param name="e">
  3712. /// </param>
  3713. private void TimesPrintMsg_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  3714. {
  3715. if (_msgnum > 5)
  3716. _msgnum = 0;
  3717. else
  3718. _msgnum++;
  3719. string point = "";
  3720. point = point.PadRight(_msgnum, '.');
  3721. Dispatcher.Invoke
  3722. (
  3723. () =>
  3724. {
  3725. LabPrintMessage.Content = _printMsg + point;
  3726. }
  3727. );
  3728. }
  3729. #endregion 打印界面
  3730. #region 笔事件回调
  3731. public void penPointEvent
  3732. (
  3733. byte bIndex,
  3734. byte bPenStatus,
  3735. short bx,
  3736. short by,
  3737. short bPress,
  3738. int mNDeviceW,
  3739. int mNDeviceH
  3740. )
  3741. {
  3742. //17是按下,16是抬起
  3743. if (bPenStatus == 16 || bPenStatus == 0)
  3744. {
  3745. //stroke.Clear();
  3746. if (App.PageContextData.currpage > 0)
  3747. {
  3748. Dispatcher.Invoke
  3749. (
  3750. () =>
  3751. {
  3752. myblackboard.changepages
  3753. (
  3754. 0,
  3755. 0,
  3756. true,
  3757. _color,
  3758. _penSize,
  3759. App.PageContextData.currpage - 1,
  3760. 0
  3761. );
  3762. }
  3763. );
  3764. }
  3765. }
  3766. double propW = BlackboardCanvas.ActualWidth / mNDeviceH;
  3767. double propH = BlackboardCanvas.ActualHeight / mNDeviceW;
  3768. //点
  3769. double tempY = (mNDeviceW - bx) * propH;
  3770. double tempX = by * propW;
  3771. //pageSerial //点阵IP地址 与打印的页面关联
  3772. if (App.PageContextData.currpage > 0)
  3773. {
  3774. Dispatcher.Invoke
  3775. (
  3776. () =>
  3777. {
  3778. float pressure = bPress / 100f;
  3779. if (bPress > 0)
  3780. {
  3781. myblackboard.changepages
  3782. (
  3783. tempX,
  3784. tempY,
  3785. false,
  3786. _color,
  3787. _penSize,
  3788. App.PageContextData.currpage - 1,
  3789. pressure
  3790. );
  3791. }
  3792. #region 设置滚动条位置
  3793. //点在显示页面上方
  3794. if (tempY < ScroMain.VerticalOffset)
  3795. {
  3796. //滚动条当前位置
  3797. double rollCurrentLocation = ScroMain.VerticalOffset;
  3798. //向上滚动至以点为中心需要滚动的距离
  3799. double upRoll = (rollCurrentLocation - tempY) + (ScroMain.ActualHeight / 2);
  3800. //如果小于0则等于0
  3801. double rollLocation = rollCurrentLocation - upRoll;
  3802. if (rollLocation < 0)
  3803. {
  3804. rollLocation = 0;
  3805. }
  3806. ////滚动条实际偏移量
  3807. //double RollOffset = RollCurrentLocation - RollLocation;
  3808. ScroMain.ScrollToVerticalOffset(rollLocation);
  3809. }
  3810. //点在显示页面下方
  3811. if (tempY > ScroMain.VerticalOffset + ScroMain.ActualHeight)
  3812. {
  3813. //滚动条当前位置
  3814. double rollCurrentLocation = ScroMain.VerticalOffset;
  3815. //向下滚动至以点为中心需要滚动的距离
  3816. double downRoll = (tempY - rollCurrentLocation) - (ScroMain.ActualHeight / 2);
  3817. //如果小于0则等于0
  3818. double rollLocation = rollCurrentLocation + downRoll;
  3819. //滚动条最大滚动值
  3820. double scrollbarMaxNum = GridM.ActualHeight - ScroMain.ActualHeight;
  3821. if (rollLocation > scrollbarMaxNum)
  3822. {
  3823. rollLocation = scrollbarMaxNum;
  3824. }
  3825. ////滚动条实际偏移量
  3826. //double RollOffset = RollLocation-RollCurrentLocation;
  3827. ScroMain.ScrollToVerticalOffset(rollLocation);
  3828. }
  3829. #endregion 设置滚动条位置
  3830. if (tempX > 0 && tempY > 0)
  3831. {
  3832. //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
  3833. System.Windows.Point getP = ScroMain.PointToScreen(new System.Windows.Point(tempX, tempY - ScroMain.VerticalOffset));
  3834. SetCursorPos((int)getP.X, (int)getP.Y);
  3835. }
  3836. }
  3837. );
  3838. }
  3839. }
  3840. public void penStatusEvent()
  3841. {
  3842. UpdateDevStatus();
  3843. }
  3844. #endregion 笔事件回调
  3845. private void Window_Closed(object sender, EventArgs e)
  3846. {
  3847. Environment.Exit(0);
  3848. }
  3849. }
  3850. }