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

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