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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460
  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. private bool waveIn_runing = false;
  2578. //音频写入
  2579. private WaveFileWriter writer = null;
  2580. /// <summary>
  2581. /// 录制窗口内容
  2582. /// </summary>
  2583. /// <param name="sender">
  2584. /// </param>
  2585. /// <param name="e">
  2586. /// </param>
  2587. private async void BtnRecord_Click(object sender, RoutedEventArgs e)
  2588. {
  2589. #region 防止连击
  2590. if (IsPressButton)
  2591. {
  2592. return;
  2593. }
  2594. else
  2595. {
  2596. IsPressButton = true;
  2597. new Thread(new ThreadStart(new Action(() =>
  2598. {
  2599. Thread.Sleep(500);
  2600. IsPressButton = false;
  2601. }))).Start();
  2602. }
  2603. #endregion 防止连击
  2604. if (APP.PageContextData.currpage == 0)
  2605. {
  2606. MessageWindow.Show("请先导入文档或截图!");
  2607. return;
  2608. }
  2609. if (RecordType == 0)
  2610. {
  2611. bool microphoneGood = true;
  2612. start_pause_grid.Visibility = Visibility.Hidden;
  2613. stop_grid.Visibility = Visibility.Hidden;
  2614. close_grid.Visibility = Visibility.Hidden;
  2615. await Task.Run(() =>
  2616. {
  2617. microphoneGood = ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.microphone);
  2618. });
  2619. if (!microphoneGood)
  2620. {
  2621. start_pause_grid.Visibility = Visibility.Visible;
  2622. stop_grid.Visibility = Visibility.Visible;
  2623. close_grid.Visibility = Visibility.Visible;
  2624. MessageWindow.Show("麦克风不可用");
  2625. return;
  2626. }
  2627. blackboard_canvas.Visibility = Visibility.Visible;
  2628. if (RectImgBorder.Visibility != Visibility.Hidden)
  2629. {
  2630. HideAngleBorder();
  2631. }
  2632. Record();
  2633. BtnPrint.IsEnabled = false;
  2634. BtnScreenshot.IsEnabled = false;
  2635. BtnImport.IsEnabled = false;
  2636. BtnScreenRecording.IsEnabled = false;
  2637. BtnUpload.IsEnabled = false;
  2638. BtnSetUp.IsEnabled = false;
  2639. BtnDevice.IsEnabled = false;
  2640. BtnLoginType.IsEnabled = false;
  2641. blackboard_canvas.Visibility = Visibility.Visible;
  2642. TxbType.Text = "准备录制";
  2643. BtnRecord.Visibility = Visibility.Collapsed;
  2644. BtnRecordSuspend.Visibility = Visibility.Visible;
  2645. BtnRecord.IsEnabled = true;
  2646. BtnStop.IsEnabled = true;
  2647. #region 录像倒计时
  2648. if (APP.W_CountdownWindow == null)
  2649. {
  2650. APP.W_CountdownWindow = new CountdownWindow();
  2651. APP.W_CountdownWindow.Initialize();
  2652. }
  2653. else
  2654. {
  2655. APP.W_CountdownWindow.Initialize();
  2656. }
  2657. APP.W_CountdownWindow.Show();
  2658. #endregion 录像倒计时
  2659. await Task.Delay(3000);
  2660. //停止中开始录制
  2661. RecordType = 3;
  2662. close_grid.Visibility = Visibility.Visible;
  2663. TxbType.Text = "正在录制";
  2664. RecordType = 1;
  2665. await StartRecord();
  2666. start_pause_grid.Visibility = Visibility.Visible;
  2667. stop_grid.Visibility = Visibility.Visible;
  2668. }
  2669. else if (RecordType == 1)
  2670. {
  2671. //录制中暂停
  2672. RecordType = 2;
  2673. }
  2674. else if (RecordType == 2)
  2675. {
  2676. //暂停中继续录制
  2677. RecordType = 1;
  2678. }
  2679. if (RecordType == 0)
  2680. {
  2681. TxbType.Text = "准备录制";
  2682. BtnRecord.Visibility = Visibility.Visible;
  2683. BtnRecordSuspend.Visibility = Visibility.Collapsed;
  2684. BtnRecord.IsEnabled = true;
  2685. BtnStop.IsEnabled = false;
  2686. }
  2687. else if (RecordType == 1)
  2688. {
  2689. TxbType.Text = "录制中";
  2690. BtnRecord.Visibility = Visibility.Collapsed;
  2691. BtnRecordSuspend.Visibility = Visibility.Visible;
  2692. }
  2693. else if (RecordType == 2)
  2694. {
  2695. TxbType.Text = "暂停中";
  2696. BtnRecord.Visibility = Visibility.Visible;
  2697. BtnRecordSuspend.Visibility = Visibility.Collapsed;
  2698. }
  2699. else if (RecordType == 3)
  2700. {
  2701. TxbType.Text = "倒计时";
  2702. }
  2703. }
  2704. /// <summary>
  2705. /// 停止录制窗口内容
  2706. /// </summary>
  2707. /// <param name="sender">
  2708. /// </param>
  2709. /// <param name="e">
  2710. /// </param>
  2711. private async void BtnStop_Click(object sender, RoutedEventArgs e)
  2712. {
  2713. #region 防止连击
  2714. if (IsPressButton)
  2715. {
  2716. return;
  2717. }
  2718. else
  2719. {
  2720. IsPressButton = true;
  2721. new Thread(new ThreadStart(new Action(() =>
  2722. {
  2723. Thread.Sleep(500);
  2724. IsPressButton = false;
  2725. }))).Start();
  2726. }
  2727. #endregion 防止连击
  2728. if (RecordType != 0)
  2729. {
  2730. blackboard_canvas.Visibility = Visibility.Collapsed;
  2731. //鼠标模式
  2732. luoBoPenUtil.lb_device_mouse();
  2733. await EndRecord();
  2734. RecordType = 0;
  2735. }
  2736. }
  2737. /// <summary>
  2738. /// 停止录制并生成录制文件
  2739. /// </summary>
  2740. private async Task EndRecord()
  2741. {
  2742. #region 恢复被禁用的按钮
  2743. BtnScreenshot.IsEnabled = true;
  2744. BtnImport.IsEnabled = true;
  2745. BtnScreenRecording.IsEnabled = true;
  2746. BtnUpload.IsEnabled = true;
  2747. BtnSetUp.IsEnabled = true;
  2748. BtnDevice.IsEnabled = true;
  2749. BtnLoginType.IsEnabled = true;
  2750. #endregion 恢复被禁用的按钮
  2751. APP.PageContextData.currpage = 0;
  2752. APP.PageContextData.pagenum = 0;
  2753. myblackboard.clear();
  2754. APP.PageDrawList.Clear();
  2755. imgCanvas.Source = null;
  2756. imgDocumentation.Source = null;
  2757. imgPPT.Source = null;
  2758. GridPage.Visibility = Visibility.Collapsed;
  2759. BtnRecord.IsEnabled = false;
  2760. BtnStop.IsEnabled = false;
  2761. BtnScreenRecording.IsEnabled = false;
  2762. timer.Change(-1, 0);
  2763. timer.Dispose();
  2764. TxbTime.Text = "00:00";
  2765. TxbType.Text = "保存中";
  2766. start_pause_grid.Visibility = Visibility.Hidden;
  2767. await Task.Run(() =>
  2768. {
  2769. try
  2770. {
  2771. videoWriter.Close();
  2772. waveIn.StopRecording();
  2773. //等待音频结束回调
  2774. while (waveIn_runing)
  2775. {
  2776. Thread.Sleep(300);
  2777. }
  2778. Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
  2779. foreach (Process KillProcess in KillProcessArray)
  2780. {
  2781. KillProcess.Kill();
  2782. }
  2783. FFMpegConverter ffMpeg = new FFMpegConverter();
  2784. FFMpegInput[] input = new FFMpegInput[] {
  2785. new FFMpegInput(TempVideoPathName),
  2786. new FFMpegInput(TempAudioPathName)
  2787. };
  2788. // 音视频合并
  2789. ffMpeg.ConvertMedia(
  2790. input,
  2791. VideoSavePathName,
  2792. "mp4",
  2793. new OutputSettings() { }
  2794. );
  2795. //生成缩略图
  2796. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  2797. FileToolsCommon.CreateDirectory(ThumbnailPath);
  2798. //缩略图存储位置
  2799. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
  2800. FileToolsCommon.DeleteFile(ThumbnailPathName);
  2801. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2802. VideoInfo.VideoPath = VideoSavePathName;
  2803. VideoInfo.ThumbnailPath = ThumbnailPathName;
  2804. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  2805. VideoInfo.IsUpload = false;
  2806. VideoInfo.Uploaded = 0;
  2807. try
  2808. {
  2809. bool ThuRes = APP.FFmpeg.GenerateThumbnails(TempVideoPathName, ThumbnailPathName, 200, 130);
  2810. }
  2811. catch (Exception ex)
  2812. {
  2813. LogHelper.WriteErrLog("录制生成缩略图", ex);
  2814. }
  2815. if (!APP.VideoList.Exists(x => x.FileGuid == VideoInfo.FileGuid) || !APP.VideoList.Exists(x => x.VideoPath == VideoInfo.VideoPath))
  2816. {
  2817. APP.VideoList.Add(VideoInfo);
  2818. //保存数据
  2819. APP.SaveWkData();
  2820. }
  2821. try
  2822. {
  2823. FileToolsCommon.DeleteFile(TempVideoPathName);
  2824. FileToolsCommon.DeleteFile(TempAudioPathName);
  2825. }
  2826. catch (Exception ex)
  2827. {
  2828. LogHelper.WriteErrLog("删除录制临时文件", ex);
  2829. }
  2830. }
  2831. catch (Exception ex)
  2832. {
  2833. Dispatcher.Invoke(() =>
  2834. {
  2835. MessageWindow.Show(ex.Message);
  2836. });
  2837. }
  2838. });
  2839. BtnRecord.IsEnabled = true;
  2840. BtnStop.IsEnabled = false;
  2841. BtnPrint.IsEnabled = false;
  2842. BtnScreenRecording.IsEnabled = true;
  2843. TxbType.Text = "准备就绪";
  2844. BtnRecord.Visibility = Visibility.Visible;
  2845. BtnRecordSuspend.Visibility = Visibility.Collapsed;
  2846. start_pause_grid.Visibility = Visibility.Visible;
  2847. }
  2848. /// <summary>
  2849. /// 录制保存图片
  2850. /// </summary>
  2851. private void RecordSaveImage()
  2852. {
  2853. try
  2854. {
  2855. //保存图片
  2856. try
  2857. {
  2858. Dispatcher.Invoke(() =>
  2859. {
  2860. Bitmap bm = ImageHelper.SaveUI2Bitmap(GridMain, gridActWidth, gridActHeight);
  2861. videoWriter.WriteVideoFrame(bm);
  2862. bm.Dispose();
  2863. });
  2864. }
  2865. catch (Exception e)
  2866. {
  2867. Console.WriteLine(e.Message);
  2868. }
  2869. }
  2870. catch (Exception ex)
  2871. {
  2872. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  2873. }
  2874. }
  2875. //new WaveInEvent();
  2876. /// <summary>
  2877. /// 开始录制和暂停录制
  2878. /// </summary>
  2879. private async Task StartRecord()
  2880. {
  2881. await Task.Run(() =>
  2882. {
  2883. //电子版切换笔模式
  2884. luoBoPenUtil.lb_device_hand();
  2885. VideoInfo = new Model_Video
  2886. {
  2887. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  2888. WkType = Enum_WKVidetype.RecordingLessons
  2889. };
  2890. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  2891. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  2892. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  2893. TempVideoPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn.avi";
  2894. int num = 1;
  2895. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  2896. {
  2897. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制_" + num + "." + VideoInfo.VideoType.ToString();
  2898. TempVideoPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn_" + num + ".avi";
  2899. num++;
  2900. }
  2901. TempAudioPathName = TempVideoPathName.Replace(".avi", ".mp3");
  2902. gridActWidth = (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f) / 2) * 2;
  2903. gridActHeight = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f) / 2) * 2;
  2904. lock (this)
  2905. {
  2906. videoWriter.Open(
  2907. TempVideoPathName,
  2908. gridActWidth,
  2909. gridActHeight,
  2910. 5,
  2911. VideoCodec.MPEG4,
  2912. gridActWidth * gridActHeight * 10
  2913. );
  2914. waveIn = new WaveInEvent();
  2915. waveIn_runing = true;
  2916. writer = new WaveFileWriter(TempAudioPathName, waveIn.WaveFormat);
  2917. //开始录音,写数据
  2918. waveIn.DataAvailable += (s, a) =>
  2919. {
  2920. if (RecordType == 1)
  2921. {
  2922. writer.Write(a.Buffer, 0, a.BytesRecorded);
  2923. }
  2924. };
  2925. //结束录音
  2926. waveIn.RecordingStopped += (s, a) =>
  2927. {
  2928. writer.Dispose();
  2929. writer = null;
  2930. waveIn.Dispose();
  2931. waveIn_runing = false;
  2932. };
  2933. waveIn.StartRecording();
  2934. }
  2935. });
  2936. SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
  2937. Recorddt = DateTime.Now;
  2938. ///启动截图
  2939. timer = new Timer(new TimerCallback(Timer_Elapsed), null, 0, 200);
  2940. }
  2941. /// <summary>
  2942. /// 录制保存图片计时器
  2943. /// </summary>
  2944. /// <param name="sender">
  2945. /// </param>
  2946. private void Timer_Elapsed(object sender)
  2947. {
  2948. if (RecordType == 1)
  2949. {
  2950. Dispatcher.Invoke(() =>
  2951. {
  2952. SRTime = SRTime.AddMilliseconds(200);
  2953. if (SRTime.Hour > 0)
  2954. {
  2955. TxbTime.Text = SRTime.ToString("HH:mm:ss");
  2956. }
  2957. else
  2958. {
  2959. TxbTime.Text = SRTime.ToString("mm:ss");
  2960. }
  2961. });
  2962. ThreadPool.QueueUserWorkItem(o =>
  2963. {
  2964. RecordSaveImage();
  2965. });
  2966. }
  2967. }
  2968. #endregion 录制窗口
  2969. #region 分页
  2970. private void ImgXY()
  2971. {
  2972. imgCanvas.Width = APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes.CenterX;
  2973. imgCanvas.Height = APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes.CenterY;
  2974. imgCanvas.Margin = new Thickness(APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation.X, APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation.Y, 0, 0);
  2975. }
  2976. /// <summary>
  2977. /// 跳转
  2978. /// </summary>
  2979. private void JumpPageClick()
  2980. {
  2981. myblackboard.changepage(APP.PageContextData.currpage - 1);
  2982. ScroMain.ScrollToVerticalOffset(0);
  2983. if (BtnImport.IsEnabled)
  2984. {
  2985. ///截图可用
  2986. BtnScreenshot.IsEnabled = true;
  2987. }
  2988. if (APP.PageContextData.currpage <= APP.PageDrawList.Count)
  2989. {
  2990. if (APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation != null)
  2991. {
  2992. APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = true;
  2993. }
  2994. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.PageContextData.currpage <= APP.PageDrawList.Count && APP.PageContextData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath))
  2995. {
  2996. if (APP.PageDrawList[APP.PageContextData.currpage - 1].ImgDocumentation)
  2997. {
  2998. if ("ppt".Equals(APP.PageDrawList[APP.PageContextData.currpage - 1].Type))
  2999. {
  3000. imgCanvas.Source = null;
  3001. imgDocumentation.Source = null;
  3002. imgPPT.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
  3003. BtnScreenshot.IsEnabled = false;
  3004. }
  3005. else
  3006. {
  3007. imgPPT.Source = null;
  3008. imgCanvas.Source = null;
  3009. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
  3010. BtnScreenshot.IsEnabled = false;
  3011. }
  3012. }
  3013. else
  3014. {
  3015. imgPPT.Source = null;
  3016. imgDocumentation.Source = null;
  3017. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
  3018. APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = false;
  3019. if (APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation.X > 0)
  3020. {
  3021. mouseDown = false;
  3022. imageOperationUtil.setMouseDown(mouseDown);
  3023. ImgXY();
  3024. }
  3025. }
  3026. }
  3027. else
  3028. {
  3029. imgPPT.Source = null;
  3030. imgCanvas.Source = null;
  3031. imgDocumentation.Source = null;
  3032. }
  3033. }
  3034. }
  3035. /// 上一页 </summary> <param name="sender"></param> <param name="e"></param>
  3036. private void last_button_Click(object sender, RoutedEventArgs e)
  3037. {
  3038. if (APP.PageContextData.currpage > 1)
  3039. {
  3040. mouseDown = false;
  3041. imageOperationUtil.setMouseDown(mouseDown);
  3042. HideAngleBorder();
  3043. APP.PageContextData.currpage -= 1;
  3044. JumpPageClick();
  3045. }
  3046. }
  3047. /// <summary>
  3048. /// 下一页
  3049. /// </summary>
  3050. /// <param name="sender">
  3051. /// </param>
  3052. /// <param name="e">
  3053. /// </param>
  3054. private void next_btn_Click(object sender, RoutedEventArgs e)
  3055. {
  3056. if (APP.PageContextData.currpage < APP.PageContextData.pagenum)
  3057. {
  3058. mouseDown = false;
  3059. imageOperationUtil.setMouseDown(mouseDown);
  3060. HideAngleBorder();
  3061. APP.PageContextData.currpage += 1;
  3062. JumpPageClick();
  3063. }
  3064. }
  3065. #endregion 分页
  3066. #region 图像缩放,移动
  3067. private bool mouseDown;
  3068. private System.Windows.Point mouseXY;
  3069. /// <summary>
  3070. /// x y轴
  3071. /// </summary>
  3072. /// <param name="img">
  3073. /// </param>
  3074. /// <param name="e">
  3075. /// </param>
  3076. private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
  3077. {
  3078. if (e.LeftButton != MouseButtonState.Pressed)
  3079. {
  3080. return;
  3081. }
  3082. if (APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation)
  3083. {
  3084. return;
  3085. }
  3086. TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
  3087. TranslateTransform transform = group.Children[1] as TranslateTransform;
  3088. System.Windows.Point position = e.GetPosition(img);
  3089. transform.X -= mouseXY.X - position.X;
  3090. transform.Y -= mouseXY.Y - position.Y;
  3091. mouseXY = position;
  3092. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
  3093. {
  3094. X = transform.X,
  3095. Y = transform.Y
  3096. };
  3097. }
  3098. private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
  3099. {
  3100. System.Windows.Point pointToContent = group.Inverse.Transform(point);
  3101. ScaleTransform transform = group.Children[0] as ScaleTransform;
  3102. if (transform.ScaleX + delta < 0.1)
  3103. {
  3104. return;
  3105. }
  3106. transform.ScaleX += delta;
  3107. transform.ScaleY += delta;
  3108. TranslateTransform transform1 = group.Children[1] as TranslateTransform;
  3109. transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
  3110. transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
  3111. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
  3112. {
  3113. X = transform1.X,
  3114. Y = transform1.Y
  3115. };
  3116. APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
  3117. {
  3118. CenterX = imgCanvas.ActualWidth,
  3119. CenterY = imgCanvas.ActualHeight
  3120. };
  3121. APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = false;
  3122. }
  3123. private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  3124. {
  3125. ContentControl img = sender as ContentControl;
  3126. if (img == null)
  3127. {
  3128. return;
  3129. }
  3130. img.CaptureMouse();
  3131. mouseDown = true;
  3132. imageOperationUtil.setMouseDown(mouseDown);
  3133. mouseXY = e.GetPosition(img);
  3134. //Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
  3135. }
  3136. private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  3137. {
  3138. ContentControl img = sender as ContentControl;
  3139. if (img == null)
  3140. {
  3141. return;
  3142. }
  3143. img.ReleaseMouseCapture();
  3144. mouseDown = false;
  3145. imageOperationUtil.setMouseDown(mouseDown);
  3146. }
  3147. private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  3148. {
  3149. ContentControl img = sender as ContentControl;
  3150. if (img == null)
  3151. {
  3152. return;
  3153. }
  3154. if (mouseDown)
  3155. {
  3156. Domousemove(img, e);
  3157. }
  3158. }
  3159. private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
  3160. {
  3161. ContentControl img = sender as ContentControl;
  3162. if (img == null)
  3163. {
  3164. return;
  3165. }
  3166. System.Windows.Point point = e.GetPosition(img);
  3167. System.Windows.Point PicLocate = e.GetPosition(imgCanvas);
  3168. TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
  3169. double delta = e.Delta * 0.001;
  3170. DowheelZoom(group, point, delta);
  3171. }
  3172. #endregion 图像缩放,移动
  3173. #region 更改设备连接状态
  3174. /// <summary>
  3175. /// 更新设备状态显示
  3176. /// </summary>
  3177. public void UpdateDevStatus()
  3178. {
  3179. if (APP.BoardStatus && (APP.PenStatus || APP.TQLPenStatus))
  3180. {
  3181. Dispatcher.Invoke(new Action(() =>
  3182. {
  3183. txbNotConnected.Text = "笔/板已连接";
  3184. txbNotConnecteds.Text = "笔/板已连接";
  3185. }));
  3186. }
  3187. else if (APP.BoardStatus)
  3188. {
  3189. Dispatcher.Invoke(new Action(() =>
  3190. {
  3191. txbNotConnected.Text = "手写板已连接";
  3192. txbNotConnecteds.Text = "手写板已连接";
  3193. }));
  3194. }
  3195. else if (APP.PenStatus)
  3196. {
  3197. Dispatcher.Invoke(new Action(() =>
  3198. {
  3199. txbNotConnected.Text = "智能笔已连接";
  3200. txbNotConnecteds.Text = "智能笔已连接";
  3201. }));
  3202. }
  3203. else if (APP.TQLPenStatus)
  3204. {
  3205. Dispatcher.Invoke(new Action(() =>
  3206. {
  3207. txbNotConnected.Text = "智能笔已连接";
  3208. txbNotConnecteds.Text = "智能笔已连接";
  3209. }));
  3210. }
  3211. else
  3212. {
  3213. Dispatcher.Invoke(new Action(() =>
  3214. {
  3215. txbNotConnected.Text = "未连接";
  3216. txbNotConnecteds.Text = "未连接";
  3217. }));
  3218. }
  3219. }
  3220. #endregion 更改设备连接状态
  3221. #region 腾千里手写笔
  3222. private static float TQLA4_HEIGHT = (float)3509 / (float)300 * (float)25.4 / (float)1.524;
  3223. /// <summary>
  3224. /// TQL点阵笔宽高
  3225. /// </summary>
  3226. private static float TQLA4_WIDTH = (float)2480 / (float)300 * (float)25.4 / (float)1.524;
  3227. /// <summary>
  3228. /// 是否在书写
  3229. /// </summary>
  3230. private bool isTQLPenDown = false;
  3231. //(float)1075 / (float)150 * (float)25.4 / (float)1.524; //OID4
  3232. //(float)1512 / (float)150 * (float)25.4 / (float)1.524;
  3233. /// <summary>
  3234. /// TQL初始化
  3235. /// </summary>
  3236. public void InitTQLPPen()
  3237. {
  3238. if (APP.TQLPenevents == null)
  3239. {
  3240. APP.TQLPenevents = new PenEvents(1);
  3241. }
  3242. else
  3243. {
  3244. APP.TQLPenevents.InToType = 1;
  3245. }
  3246. }
  3247. /// <summary>
  3248. /// 笔落下
  3249. /// </summary>
  3250. public void TQLDown()
  3251. {
  3252. isTQLPenDown = true;
  3253. if (APP.PageContextData.currpage > 0)
  3254. {
  3255. Dispatcher.Invoke(new Action(() =>
  3256. {
  3257. myblackboard.changepages(0, 0, true, Color, PenSize, APP.PageContextData.currpage - 1, 0);
  3258. }));
  3259. }
  3260. }
  3261. /// <summary>
  3262. /// 笔书写
  3263. /// </summary>
  3264. /// <param name="cx">
  3265. /// </param>
  3266. /// <param name="cy">
  3267. /// </param>
  3268. /// <param name="force">
  3269. /// </param>
  3270. public void TQLPenWrite(double cx, double cy, int force)
  3271. {
  3272. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  3273. if (!isTQLPenDown)
  3274. {
  3275. return;
  3276. }
  3277. double PropW = blackboard_canvas.ActualWidth / TQLA4_WIDTH;
  3278. double PropH = blackboard_canvas.ActualHeight / TQLA4_HEIGHT;
  3279. //点
  3280. double tempX = cx * PropW;
  3281. double tempY = cy * PropH;
  3282. if (APP.PageContextData.currpage > 0)
  3283. {
  3284. Dispatcher.Invoke(new Action(() =>
  3285. {
  3286. //0~1023,亦即有 1024 阶供应用软件后续应用之用,如笔锋笔触,暂无用
  3287. float Pressure = (float)force / 1023f;
  3288. myblackboard.changepages(tempX, tempY, false, Color, PenSize, APP.PageContextData.currpage - 1, Pressure);
  3289. #region 设置滚动条位置
  3290. //点在显示页面上方
  3291. if (tempY < ScroMain.VerticalOffset)
  3292. {
  3293. //滚动条当前位置
  3294. double RollCurrentLocation = ScroMain.VerticalOffset;
  3295. //向上滚动至以点为中心需要滚动的距离
  3296. double UpRoll = (RollCurrentLocation - tempY) + (ScroMain.ActualHeight / 2);
  3297. //如果小于0则等于0
  3298. double RollLocation = RollCurrentLocation - UpRoll;
  3299. if (RollLocation < 0)
  3300. {
  3301. RollLocation = 0;
  3302. }
  3303. ////滚动条实际偏移量
  3304. //double RollOffset = RollCurrentLocation - RollLocation;
  3305. ScroMain.ScrollToVerticalOffset(RollLocation);
  3306. }
  3307. //点在显示页面下方
  3308. if (tempY > ScroMain.VerticalOffset + ScroMain.ActualHeight)
  3309. {
  3310. //滚动条当前位置
  3311. double RollCurrentLocation = ScroMain.VerticalOffset;
  3312. //向下滚动至以点为中心需要滚动的距离
  3313. double DownRoll = (tempY - RollCurrentLocation) - (ScroMain.ActualHeight / 2);
  3314. //如果小于0则等于0
  3315. double RollLocation = RollCurrentLocation + DownRoll;
  3316. //滚动条最大滚动值
  3317. double ScrollbarMaxNum = GridM.ActualHeight - ScroMain.ActualHeight;
  3318. if (RollLocation > ScrollbarMaxNum)
  3319. {
  3320. RollLocation = ScrollbarMaxNum;
  3321. }
  3322. ////滚动条实际偏移量
  3323. //double RollOffset = RollLocation-RollCurrentLocation;
  3324. ScroMain.ScrollToVerticalOffset(RollLocation);
  3325. }
  3326. #endregion 设置滚动条位置
  3327. if (tempX > 0 && tempY > 0)
  3328. {
  3329. System.Windows.Point getP = ScroMain.PointToScreen(new System.Windows.Point(tempX, tempY - ScroMain.VerticalOffset));
  3330. SetCursorPos((int)getP.X, (int)getP.Y);
  3331. }
  3332. }));
  3333. }
  3334. }
  3335. /// <summary>
  3336. /// 笔抬起
  3337. /// </summary>
  3338. public void TQLUp()
  3339. {
  3340. isTQLPenDown = false;
  3341. //stroke.Clear();
  3342. if (APP.PageContextData.currpage > 0)
  3343. {
  3344. Dispatcher.Invoke(new Action(() =>
  3345. {
  3346. myblackboard.changepages(0, 0, true, Color, PenSize, APP.PageContextData.currpage - 1, 0);
  3347. }));
  3348. }
  3349. }
  3350. #endregion 腾千里手写笔
  3351. #region 图片拉伸移动
  3352. /// <summary>
  3353. /// 点击标题栏 隐藏截图的四个点和线
  3354. /// </summary>
  3355. /// <param name="sender">
  3356. /// </param>
  3357. /// <param name="e">
  3358. /// </param>
  3359. private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
  3360. {
  3361. imageOperationUtil.Grid_MouseDown();
  3362. }
  3363. /// <summary>
  3364. /// 隐藏图片四个点和线
  3365. /// </summary>
  3366. private void HideAngleBorder()
  3367. {
  3368. imageOperationUtil.HideAngleBorder();
  3369. }
  3370. private void imgCanvas_MouseMove(object sender, MouseEventArgs e)
  3371. {
  3372. imageOperationUtil.imgCanvas_MouseMove(sender, e);
  3373. }
  3374. private void imgCanvas_MouseUp(object sender, MouseButtonEventArgs e)
  3375. {
  3376. imageOperationUtil.imgCanvas_MouseUp();
  3377. }
  3378. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  3379. {
  3380. imageOperationUtil.PicEMap_MouseDown(sender, e);
  3381. }
  3382. private void RectRightUp_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
  3383. {
  3384. imageOperationUtil.RectRightUp_DragCompleted();
  3385. }
  3386. private void RectRightUp_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
  3387. {
  3388. imageOperationUtil.RectRightUp_DragDelta(sender, e);
  3389. }
  3390. private void RectRightUp_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
  3391. {
  3392. imageOperationUtil.RectRightUp_DragStarted(sender, e);
  3393. }
  3394. /// <summary>
  3395. /// 鼠标左键点击事件
  3396. /// </summary>
  3397. /// <param name="sender">
  3398. /// </param>
  3399. /// <param name="e">
  3400. /// </param>
  3401. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  3402. {
  3403. imageOperationUtil.Window_MouseLeftButtonDown_1();
  3404. }
  3405. #endregion 图片拉伸移动
  3406. #region 录屏 录制 截图 导入文档 增加 主页面显示
  3407. /// <summary>
  3408. /// 录屏 录制 截图 导入文档 增加 主页面显示
  3409. /// </summary>
  3410. private void Record()
  3411. {
  3412. PageHide();
  3413. GridMain.Visibility = Visibility.Visible;
  3414. GridRecordingTitle.Visibility = Visibility.Visible;
  3415. if (APP.PageContextData.pagenum > 0)
  3416. {
  3417. GridPage.Visibility = Visibility.Visible;
  3418. }
  3419. DataContext = APP.PageContextData;
  3420. }
  3421. #endregion 录屏 录制 截图 导入文档 增加 主页面显示
  3422. #region 页码跳转
  3423. /// <summary>
  3424. /// 确定跳转
  3425. /// </summary>
  3426. /// <param name="sender">
  3427. /// </param>
  3428. /// <param name="e">
  3429. /// </param>
  3430. private void BtnJumpPage_Click(object sender, RoutedEventArgs e)
  3431. {
  3432. int JumpPage = 0;
  3433. if (JumpPage < 1)
  3434. {
  3435. JumpPage = 1;
  3436. }
  3437. if (JumpPage > int.Parse(txbTotalpage.Text))
  3438. {
  3439. JumpPage = int.Parse(txbTotalpage.Text);
  3440. }
  3441. #region 跳转
  3442. APP.PageContextData.currpage = JumpPage;
  3443. JumpPageClick();
  3444. #endregion 跳转
  3445. }
  3446. private void txtJump_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  3447. {
  3448. if (e.Key == Key.Enter)
  3449. {
  3450. BtnJumpPage_Click(null, null);
  3451. }
  3452. }
  3453. /// <summary>
  3454. /// 只允许输入数字
  3455. /// </summary>
  3456. /// <param name="sender">
  3457. /// </param>
  3458. /// <param name="e">
  3459. /// </param>
  3460. private void txtJump_PreviewTextInput(object sender, TextCompositionEventArgs e)
  3461. {
  3462. Regex re = new Regex("[^0-9.-]+");
  3463. e.Handled = re.IsMatch(e.Text);
  3464. }
  3465. #endregion 页码跳转
  3466. #region TQL打印
  3467. public static string gPrintFileName;
  3468. private iTextSharp.text.Document document;
  3469. private bool gbInitDone = false;
  3470. /// <summary>
  3471. /// 授权码
  3472. /// </summary>
  3473. private string gKeyStr;
  3474. private TmatrixClass TMC = new TmatrixClass();
  3475. /// <summary>
  3476. /// 授权文件位置
  3477. /// </summary>
  3478. private string TQLAuthorizationPath;
  3479. /// <summary>
  3480. /// 铺码
  3481. /// </summary>
  3482. private bool GenerateCode(string PDFPath)
  3483. {
  3484. try
  3485. {
  3486. if (gbInitDone == false)
  3487. {
  3488. MessageWindow.Show("打印功能无法使用,无效授权。");
  3489. return false;
  3490. }
  3491. try
  3492. {
  3493. string directoryPath = FileToolsCommon.GetDirectoryName(PDFPath);
  3494. FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Images/");
  3495. FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Vector Images/");
  3496. FileToolsCommon.DeleteDirectory(directoryPath + "Bg without Vector Images/");
  3497. FileToolsCommon.DeleteDirectory(directoryPath + "Vector Images/");
  3498. }
  3499. catch (Exception)
  3500. {
  3501. }
  3502. PDFPath = PDFPath.Replace("/", "\\");
  3503. //初始页
  3504. bool[] bPublishImageType = new bool[4];
  3505. bPublishImageType[0] = false;
  3506. bPublishImageType[1] = false;
  3507. bPublishImageType[2] = false;
  3508. bPublishImageType[3] = true;
  3509. int[] gPointType = { 0, 0, 0, 0, 1 };
  3510. int[] gPointDPI = { 0, 0, 0, 0, 1 };
  3511. string sGenerateResult = TMC.GenerateTmatrixCode_OID4(
  3512. gKeyStr,
  3513. PDFPath,
  3514. 0,
  3515. gPointType,
  3516. bPublishImageType,
  3517. gPointDPI
  3518. );
  3519. if (sGenerateResult.Substring(0, 1) == "1")
  3520. {
  3521. Dispatcher.Invoke(() =>
  3522. {
  3523. MessageWindow.Show("打印功能无法使用,无效授权。");
  3524. });
  3525. return false;
  3526. }
  3527. return true;
  3528. }
  3529. catch (Exception ex)
  3530. {
  3531. Dispatcher.Invoke(() =>
  3532. {
  3533. MessageWindow.Show("打印失败:" + ex.Message);
  3534. });
  3535. return false;
  3536. }
  3537. }
  3538. /// <summary>
  3539. /// TQL初始化打印
  3540. /// </summary>
  3541. private void TQLPrintInit()
  3542. {
  3543. ///初始化
  3544. if (TMC.TmatrixInitialize() == false)
  3545. {
  3546. }
  3547. else
  3548. {
  3549. gbInitDone = true;
  3550. }
  3551. document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0);
  3552. try
  3553. {
  3554. TQLAuthorizationPath = FileToolsCommon.GetFileAbsolutePath("/LatticeXML/S0_O000_B0000_P000-255.tmx");
  3555. StreamReader gsr = new StreamReader(TQLAuthorizationPath);
  3556. gKeyStr = gsr.ReadLine();
  3557. gsr.Close();
  3558. string KeyCheckResult = TMC.TmatrixKeyCheck_OID4(gKeyStr);
  3559. if (KeyCheckResult.Substring(0, 1) == "1")
  3560. {
  3561. MessageWindow.Show("打印服务授权过期,请联系厂家更换授权!");
  3562. LogHelper.WriteErrLog("打印服务授权过期:" + KeyCheckResult, null);
  3563. gbInitDone = false;
  3564. }
  3565. else if (KeyCheckResult.Substring(0, 1) == "0")
  3566. {
  3567. }
  3568. }
  3569. catch (Exception ex)
  3570. {
  3571. LogHelper.WriteErrLog("打印服务授权失败:" + ex.Message, ex);
  3572. MessageWindow.Show("打印服务授权失败,请联系厂家!");
  3573. gbInitDone = false;
  3574. }
  3575. }
  3576. #endregion TQL打印
  3577. #region 打印界面
  3578. /// <summary>
  3579. /// 下拉框数据源
  3580. /// </summary>
  3581. public DataTable printlist = new DataTable();
  3582. private DataTable dtComponentsUniqueNo;
  3583. private double hei = 0;
  3584. private int msgnum = 0;
  3585. private int num = 0;
  3586. /// <summary>
  3587. /// 打印状态消息
  3588. /// </summary>
  3589. private string PrintMsg = "打印中";
  3590. /// <summary>
  3591. /// 打印进度
  3592. /// </summary>
  3593. private System.Timers.Timer timesPrint;
  3594. /// <summary>
  3595. /// 打印消息
  3596. /// </summary>
  3597. private System.Timers.Timer timesPrintMsg;
  3598. private double wit = 0;
  3599. /// <summary>
  3600. /// 初始化页面
  3601. /// </summary>
  3602. /// <param name="_imgPath">
  3603. /// </param>
  3604. /// <param name="_wit">
  3605. /// </param>
  3606. /// <param name="_hei">
  3607. /// </param>
  3608. public void InitializePrint(string _imgPath, double _wit, double _hei)
  3609. {
  3610. wit = _wit;
  3611. hei = _hei;
  3612. if (!string.IsNullOrWhiteSpace(_imgPath))
  3613. {
  3614. imgPri.Source = new BitmapImage(new Uri(_imgPath));
  3615. }
  3616. else
  3617. {
  3618. imgPri.Source = null;
  3619. }
  3620. GridPrintMask.Visibility = Visibility.Collapsed;
  3621. }
  3622. /// <summary>
  3623. /// 打印初始化
  3624. /// </summary>
  3625. public void InitPrint()
  3626. {
  3627. ResizeMode = ResizeMode.NoResize;
  3628. List<string> defaList = ZPrintUtils.GetLocalPrinters();
  3629. if (defaList.Count > 0)
  3630. {
  3631. printlist.Columns.Add("Value");
  3632. printlist.Columns.Add("Key");
  3633. for (int i = 0; i < defaList.Count; i++)
  3634. {
  3635. //创建一行
  3636. DataRow row = printlist.NewRow();
  3637. //将此行添加到table中
  3638. printlist.Rows.Add(row);
  3639. printlist.Rows[i]["Value"] = defaList[i];
  3640. printlist.Rows[i]["Key"] = i.ToString();
  3641. }
  3642. dtComponentsUniqueNo = printlist.DefaultView.ToTable();
  3643. cmbClass.ItemsSource = dtComponentsUniqueNo.DefaultView;
  3644. cmbClass.SelectedIndex = 0;
  3645. }
  3646. TQLPrintInit();
  3647. }
  3648. /// <summary>
  3649. /// 生成图片
  3650. /// </summary>
  3651. /// <param name="_path">
  3652. /// 图片地址
  3653. /// </param>
  3654. /// <param name="_saveimg">
  3655. /// 保存位置
  3656. /// </param>
  3657. /// <param name="_rectangle">
  3658. /// 图片位置
  3659. /// </param>
  3660. /// <param name="errmsg">
  3661. /// 错误消息
  3662. /// </param>
  3663. /// <returns>
  3664. /// </returns>
  3665. private bool MergerPrintImg(string _path, string _saveimg, RectangleF _rectangle, out string errmsg)
  3666. {
  3667. errmsg = null;
  3668. try
  3669. {
  3670. Bitmap bitmap = null;
  3671. //创建要显示的图片对象,根据参数的个数设置宽度
  3672. Bitmap backgroudImg = new Bitmap((int)/*GridM.ActualWidth*/wit, (int)/*GridM.ActualHeight*/hei);
  3673. Graphics g = Graphics.FromImage(backgroudImg);
  3674. //清除画布,背景设置为白色
  3675. g.Clear(System.Drawing.Color.White);
  3676. if (!string.IsNullOrWhiteSpace(_path))
  3677. {
  3678. bitmap = ImageHelper.ReadBitmapFile(_path);
  3679. g.DrawImage(bitmap, _rectangle);
  3680. }
  3681. #region 添加箭头
  3682. string Str = "↑";
  3683. SolidBrush mybrush = new SolidBrush(System.Drawing.Color.Black); //设置默认画刷颜色
  3684. Font myfont = new System.Drawing.Font("黑体", 14); //设置默认字体格式
  3685. g.DrawString(Str, myfont, mybrush, new System.Drawing.Rectangle((int)wit - 50, 20, 50, 50));
  3686. #endregion 添加箭头
  3687. backgroudImg.Save(_saveimg);
  3688. g.Dispose();
  3689. backgroudImg.Dispose();
  3690. if (bitmap != null)
  3691. {
  3692. bitmap.Dispose();
  3693. }
  3694. GC.Collect();
  3695. return true;
  3696. }
  3697. catch (Exception ex)
  3698. {
  3699. errmsg = ex.Message;
  3700. LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
  3701. return false;
  3702. }
  3703. }
  3704. /// <summary>
  3705. /// 开始打印
  3706. /// </summary>
  3707. private void StartPrint(PrintModel printModel)
  3708. {
  3709. try
  3710. {
  3711. document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0f, 0f, 0f, 0f);
  3712. PrintMsg = "生成文件";
  3713. msgnum = 0;
  3714. string SourcePath1 = printModel.filepath;
  3715. try
  3716. {
  3717. SourcePath1 = SourcePath1.Replace("/", "\\");
  3718. FileStream fs = new FileStream(SourcePath1, FileMode.Create, FileAccess.ReadWrite);
  3719. document.AddAuthor("星火微课");//作者
  3720. document.AddCreationDate();//创建时候
  3721. document.AddCreator("星火微课");//创建者
  3722. document.AddSubject("点阵文件");//主题
  3723. document.AddTitle("PrintTmatrixCode");//标题
  3724. document.AddKeywords("Print");
  3725. document.AddHeader("TmatrixCode", "0");
  3726. iTextSharp.text.pdf.PdfWriter.GetInstance(document, fs);
  3727. }
  3728. catch (Exception)
  3729. {
  3730. }
  3731. document.Open();
  3732. iTextSharp.text.Image image;
  3733. for (int i = 0; i < APP.PageDrawList.Count; i++)
  3734. {
  3735. long ii = Timestamp();
  3736. string directoryPath = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  3737. string filePathOutPut = Path.Combine(directoryPath, string.Format("print{0}{1}.jpg", ii, i));
  3738. RectangleF rectangleFs = new RectangleF();
  3739. MergerPrintImg("", filePathOutPut, rectangleFs, out string errmsg);
  3740. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  3741. if (string.IsNullOrEmpty(APP.PageDrawList[i].PageImagePath))//没有图片
  3742. {
  3743. }
  3744. else if (APP.PageDrawList[i].ImgDocumentation == true && !APP.PageDrawList[i].Type.Equals("ppt"))
  3745. {
  3746. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  3747. }
  3748. else
  3749. {
  3750. RectangleF rectangleF = new RectangleF(0, 0, 0, 0);
  3751. Dispatcher.Invoke(() =>
  3752. {
  3753. rectangleF = new RectangleF
  3754. {
  3755. Width = (float)APP.PageDrawList[i].ImageSizes.CenterX,
  3756. Height = (float)APP.PageDrawList[i].ImageSizes.CenterY,
  3757. X = (float)APP.PageDrawList[i].ImageLocation.X,
  3758. Y = (float)APP.PageDrawList[i].ImageLocation.Y
  3759. };
  3760. });
  3761. string msgs = string.Empty;
  3762. bool isImg = MergerPrintImg(APP.PageDrawList[i].PageImagePath, filePathOutPut, rectangleF, out msgs);
  3763. if (isImg)
  3764. {
  3765. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  3766. }
  3767. else
  3768. {
  3769. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  3770. }
  3771. }
  3772. if (image.Height > iTextSharp.text.PageSize.A4.Height)
  3773. {
  3774. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  3775. }
  3776. else if (image.Width > iTextSharp.text.PageSize.A4.Width)
  3777. {
  3778. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  3779. }
  3780. image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
  3781. document.NewPage();
  3782. document.Add(image);
  3783. }
  3784. document.Close();
  3785. }
  3786. catch (Exception ex)
  3787. {
  3788. Dispatcher.Invoke(() =>
  3789. {
  3790. BtnPrint.IsEnabled = true;
  3791. timesPrint.Stop();
  3792. timesPrintMsg.Stop();
  3793. GridPrintMask.Visibility = Visibility.Collapsed;
  3794. MessageWindow.Show(ex.Message);
  3795. return;
  3796. });
  3797. LogHelper.WriteErrLog("打印转换PDF失败,原因:" + ex.Message, ex);
  3798. }
  3799. //PDF位置
  3800. string SourcePath = printModel.filepath;
  3801. int PrinterNum = printModel.num;
  3802. string PrinterName = printModel.printname;
  3803. if (isHasCode)
  3804. {
  3805. PrintMsg = "铺码中";
  3806. msgnum = 0;
  3807. Thread.Sleep(500);
  3808. //腾千里生成点阵文件
  3809. if (GenerateCode(SourcePath))
  3810. {
  3811. //打印机名称
  3812. string directoryPath = FileToolsCommon.GetDirectoryName(SourcePath) + "Bg with Images/";
  3813. string[] strs = FileToolsCommon.GetFileNames(directoryPath);
  3814. try
  3815. {
  3816. // 腾千里会根据原PDF的页数生成多个PDF文件
  3817. for (int i = 0; i < strs.Count(); i++)
  3818. {
  3819. timesPrint.Stop();
  3820. PrintMsg = "正在打印第" + (i + 1) + "/" + strs.Count() + "页中";
  3821. msgnum = 0;
  3822. num = 0;
  3823. timesPrint.Interval = 100;
  3824. timesPrint.Start();
  3825. string fileName = strs[i];
  3826. //打印文件
  3827. ZPrintUtils.Print(fileName, PrinterName);
  3828. }
  3829. Dispatcher.Invoke(() =>
  3830. {
  3831. BtnPrint.IsEnabled = true;
  3832. num = 99;
  3833. timesPrint.Stop();
  3834. pgbProcess.Value = 100;
  3835. lbProcess.Content = "100%";
  3836. GridPrintMask.Visibility = Visibility.Collapsed;
  3837. //MessageWindow.Show("已加入打印机队列,打印中。");
  3838. });
  3839. }
  3840. catch (Exception ex)
  3841. {
  3842. Dispatcher.Invoke(() =>
  3843. {
  3844. MessageWindow.Show("打印失败:" + ex.Message);
  3845. BtnPrint.IsEnabled = true;
  3846. timesPrint.Stop();
  3847. GridPrintMask.Visibility = Visibility.Collapsed;
  3848. return;
  3849. });
  3850. }
  3851. }
  3852. else
  3853. {
  3854. Dispatcher.Invoke(() =>
  3855. {
  3856. BtnPrint.IsEnabled = true;
  3857. timesPrint.Stop();
  3858. timesPrintMsg.Stop();
  3859. GridPrintMask.Visibility = Visibility.Collapsed;
  3860. return;
  3861. });
  3862. }
  3863. }
  3864. else
  3865. {
  3866. //打印文件
  3867. ZPrintUtils.Print(SourcePath, PrinterName);
  3868. Dispatcher.Invoke(() =>
  3869. {
  3870. BtnPrint.IsEnabled = true;
  3871. num = 99;
  3872. timesPrint.Stop();
  3873. pgbProcess.Value = 100;
  3874. lbProcess.Content = "100%";
  3875. GridPrintMask.Visibility = Visibility.Collapsed;
  3876. //MessageWindow.Show("已加入打印机队列,打印中。");
  3877. });
  3878. }
  3879. }
  3880. /// <summary>
  3881. /// 计时器
  3882. /// </summary>
  3883. /// <param name="sender">
  3884. /// </param>
  3885. /// <param name="e">
  3886. /// </param>
  3887. private void Times_ElapsedClick(object sender, System.Timers.ElapsedEventArgs e)
  3888. {
  3889. Dispatcher.Invoke(() =>
  3890. {
  3891. pgbProcess.Value = num;
  3892. lbProcess.Content = num.ToString() + "%";
  3893. if (num < 99)
  3894. {
  3895. num++;
  3896. timesPrint.Interval += (num / 2);
  3897. }
  3898. else
  3899. {
  3900. timesPrint.Stop();
  3901. }
  3902. });
  3903. }
  3904. /// <summary>
  3905. /// 消息
  3906. /// </summary>
  3907. /// <param name="sender">
  3908. /// </param>
  3909. /// <param name="e">
  3910. /// </param>
  3911. private void TimesPrintMsg_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  3912. {
  3913. if (msgnum > 5)
  3914. msgnum = 0;
  3915. else
  3916. msgnum++;
  3917. string point = "";
  3918. point = point.ToString().PadRight(msgnum, '.');
  3919. Dispatcher.Invoke(() =>
  3920. {
  3921. LabPrintMessage.Content = PrintMsg + point;
  3922. });
  3923. }
  3924. #endregion 打印界面
  3925. #region 笔事件回调
  3926. public void penPointEvent(byte bIndex, byte bPenStatus, short bx, short by, short bPress, int m_nDeviceW, int m_nDeviceH)
  3927. {
  3928. //17是按下,16是抬起
  3929. if (bPenStatus == 16 || bPenStatus == 0)
  3930. {
  3931. //stroke.Clear();
  3932. if (APP.PageContextData.currpage > 0)
  3933. {
  3934. Dispatcher.Invoke(new Action(() =>
  3935. {
  3936. myblackboard.changepages(0, 0, true, Color, PenSize, APP.PageContextData.currpage - 1, 0);
  3937. }));
  3938. }
  3939. }
  3940. double PropW = blackboard_canvas.ActualWidth / m_nDeviceH;
  3941. double PropH = blackboard_canvas.ActualHeight / m_nDeviceW;
  3942. //点
  3943. double tempY = (m_nDeviceW - bx) * PropH;
  3944. double tempX = by * PropW;
  3945. //pageSerial //点阵IP地址 与打印的页面关联
  3946. if (APP.PageContextData.currpage > 0)
  3947. {
  3948. Dispatcher.Invoke(new Action(() =>
  3949. {
  3950. float Pressure = bPress / 100f;
  3951. if (bPress > 0)
  3952. {
  3953. myblackboard.changepages(tempX, tempY, false, Color, PenSize, APP.PageContextData.currpage - 1, Pressure);
  3954. }
  3955. #region 设置滚动条位置
  3956. //点在显示页面上方
  3957. if (tempY < ScroMain.VerticalOffset)
  3958. {
  3959. //滚动条当前位置
  3960. double RollCurrentLocation = ScroMain.VerticalOffset;
  3961. //向上滚动至以点为中心需要滚动的距离
  3962. double UpRoll = (RollCurrentLocation - tempY) + (ScroMain.ActualHeight / 2);
  3963. //如果小于0则等于0
  3964. double RollLocation = RollCurrentLocation - UpRoll;
  3965. if (RollLocation < 0)
  3966. {
  3967. RollLocation = 0;
  3968. }
  3969. ////滚动条实际偏移量
  3970. //double RollOffset = RollCurrentLocation - RollLocation;
  3971. ScroMain.ScrollToVerticalOffset(RollLocation);
  3972. }
  3973. //点在显示页面下方
  3974. if (tempY > ScroMain.VerticalOffset + ScroMain.ActualHeight)
  3975. {
  3976. //滚动条当前位置
  3977. double RollCurrentLocation = ScroMain.VerticalOffset;
  3978. //向下滚动至以点为中心需要滚动的距离
  3979. double DownRoll = (tempY - RollCurrentLocation) - (ScroMain.ActualHeight / 2);
  3980. //如果小于0则等于0
  3981. double RollLocation = RollCurrentLocation + DownRoll;
  3982. //滚动条最大滚动值
  3983. double ScrollbarMaxNum = GridM.ActualHeight - ScroMain.ActualHeight;
  3984. if (RollLocation > ScrollbarMaxNum)
  3985. {
  3986. RollLocation = ScrollbarMaxNum;
  3987. }
  3988. ////滚动条实际偏移量
  3989. //double RollOffset = RollLocation-RollCurrentLocation;
  3990. ScroMain.ScrollToVerticalOffset(RollLocation);
  3991. }
  3992. #endregion 设置滚动条位置
  3993. if (tempX > 0 && tempY > 0)
  3994. {
  3995. //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
  3996. System.Windows.Point getP = ScroMain.PointToScreen(new System.Windows.Point(tempX, tempY - ScroMain.VerticalOffset));
  3997. SetCursorPos((int)getP.X, (int)getP.Y);
  3998. }
  3999. }));
  4000. }
  4001. }
  4002. public void penStatusEvent()
  4003. {
  4004. UpdateDevStatus();
  4005. }
  4006. #endregion 笔事件回调
  4007. }
  4008. public class PageData
  4009. {
  4010. public int PageCode { get; set; }
  4011. public string PageName { get; set; }
  4012. }
  4013. }