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

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