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

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