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

MainWindow.xaml.cs 152KB

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