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

XHMicroLessonSystemWindow.xaml.cs 223KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993
  1. using Aspose.Slides;
  2. using Aspose.Words;
  3. using Aspose.Words.Saving;
  4. using ComeCapture;
  5. using Common.system;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Diagnostics;
  9. using System.Drawing;
  10. using System.Drawing.Imaging;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading;
  15. using System.Windows;
  16. using System.Windows.Controls;
  17. using System.Windows.Controls.Primitives;
  18. using System.Windows.Forms;
  19. using System.Windows.Ink;
  20. using System.Windows.Input;
  21. using System.Windows.Media;
  22. using System.Windows.Media.Imaging;
  23. using System.Windows.Threading;
  24. using TStudyDigitalPen.HID;
  25. using XHWK.Model;
  26. using XHWK.WKTool.DAL;
  27. using XHWK.WKTool.UControl;
  28. namespace XHWK.WKTool
  29. {
  30. /// <summary>
  31. /// 主页面
  32. /// </summary>
  33. public partial class XHMicroLessonSystemWindow : Window
  34. {
  35. #region 字段
  36. private FolderBrowserDialog Ofd;
  37. private DialogResult Result;
  38. public BlackboardNew myblackboard;
  39. private System.Windows.Forms.DialogResult result;
  40. private System.Windows.Forms.OpenFileDialog ofd;
  41. //声明一个 DrawingAttributes 类型的变量
  42. private DrawingAttributes drawingAttributes;
  43. private Model_Video VideoInfo = null;
  44. ////定义事件
  45. //public event ChangeTextHandler ChangeTextEvent;
  46. //定义委托
  47. public delegate void ChangeTextHandler(string text);
  48. //定义委托
  49. public delegate void ChangeTextHandlers(string text, int i);
  50. /// <summary>
  51. /// 图片
  52. /// </summary>
  53. private string[] ImgPDFPath = new string[300];
  54. /// <summary>
  55. /// 当前颜色
  56. /// </summary>
  57. private System.Windows.Media.Color Color = System.Windows.Media.Colors.Red;
  58. /// <summary>
  59. /// 笔迹粗细
  60. /// </summary>
  61. private int PenSize = 2;
  62. //private DispatcherTimer t = null;
  63. /// <summary>
  64. /// 计时器状态
  65. /// </summary>
  66. private enum State
  67. {
  68. Start,
  69. Pause,
  70. End
  71. }
  72. /// <summary>
  73. /// 状态
  74. /// </summary>
  75. private State _state = State.End;
  76. /// <summary>
  77. /// 计时用
  78. /// </summary>
  79. private TimeSpan _timeSpan = new TimeSpan(0, 0, 0, 0, 0);
  80. #region 上传
  81. /// <summary>
  82. /// 视频模型
  83. /// </summary>
  84. private List<Model_Video> model_VideoList = null;
  85. /// <summary>
  86. /// 数据列表
  87. /// </summary>
  88. internal FileDirectoryData pageData = new FileDirectoryData();
  89. /// <summary>
  90. /// 下标
  91. /// </summary>
  92. private int Subscript = 0;
  93. /// <summary>
  94. /// 是否是修改状态
  95. /// </summary>
  96. private bool IsModify = false;
  97. #endregion
  98. private double screeHeight = SystemParameters.FullPrimaryScreenHeight;
  99. private double screeWidth = SystemParameters.FullPrimaryScreenWidth;
  100. /// <summary>
  101. /// 键盘钩子
  102. /// </summary>
  103. private KeyboardHookCommon k_hook;
  104. #endregion
  105. #region 初始化
  106. /// <summary>
  107. /// 主页面
  108. /// </summary>
  109. public XHMicroLessonSystemWindow()
  110. {
  111. new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String("PExpY2Vuc2U+CiAgPERhdGE+CiAgICA8TGljZW5zZWRUbz5TdXpob3UgQXVuYm94IFNvZnR3YXJlIENvLiwgTHRkLjwvTGljZW5zZWRUbz4KICAgIDxFbWFpbFRvPnNhbGVzQGF1bnRlYy5jb208L0VtYWlsVG8+CiAgICA8TGljZW5zZVR5cGU+RGV2ZWxvcGVyIE9FTTwvTGljZW5zZVR5cGU+CiAgICA8TGljZW5zZU5vdGU+TGltaXRlZCB0byAxIGRldmVsb3BlciwgdW5saW1pdGVkIHBoeXNpY2FsIGxvY2F0aW9uczwvTGljZW5zZU5vdGU+CiAgICA8T3JkZXJJRD4xOTA4MjYwODA3NTM8L09yZGVySUQ+CiAgICA8VXNlcklEPjEzNDk3NjAwNjwvVXNlcklEPgogICAgPE9FTT5UaGlzIGlzIGEgcmVkaXN0cmlidXRhYmxlIGxpY2Vuc2U8L09FTT4KICAgIDxQcm9kdWN0cz4KICAgICAgPFByb2R1Y3Q+QXNwb3NlLlRvdGFsIGZvciAuTkVUPC9Qcm9kdWN0PgogICAgPC9Qcm9kdWN0cz4KICAgIDxFZGl0aW9uVHlwZT5FbnRlcnByaXNlPC9FZGl0aW9uVHlwZT4KICAgIDxTZXJpYWxOdW1iZXI+M2U0NGRlMzAtZmNkMi00MTA2LWIzNWQtNDZjNmEzNzE1ZmMyPC9TZXJpYWxOdW1iZXI+CiAgICA8U3Vic2NyaXB0aW9uRXhwaXJ5PjIwMjAwODI3PC9TdWJzY3JpcHRpb25FeHBpcnk+CiAgICA8TGljZW5zZVZlcnNpb24+My4wPC9MaWNlbnNlVmVyc2lvbj4KICAgIDxMaWNlbnNlSW5zdHJ1Y3Rpb25zPmh0dHBzOi8vcHVyY2hhc2UuYXNwb3NlLmNvbS9wb2xpY2llcy91c2UtbGljZW5zZTwvTGljZW5zZUluc3RydWN0aW9ucz4KICA8L0RhdGE+CiAgPFNpZ25hdHVyZT53UGJtNUt3ZTYvRFZXWFNIY1o4d2FiVEFQQXlSR0pEOGI3L00zVkV4YWZpQnd5U2h3YWtrNGI5N2c2eGtnTjhtbUFGY3J0c0cwd1ZDcnp6MytVYk9iQjRYUndTZWxsTFdXeXNDL0haTDNpN01SMC9jZUFxaVZFOU0rWndOQkR4RnlRbE9uYTFQajhQMzhzR1grQ3ZsemJLZFZPZXk1S3A2dDN5c0dqYWtaL1E9PC9TaWduYXR1cmU+CjwvTGljZW5zZT4=")));
  112. new Aspose.Pdf.License().SetLicense(new MemoryStream(Convert.FromBase64String("PExpY2Vuc2U+CiAgPERhdGE+CiAgICA8TGljZW5zZWRUbz5TdXpob3UgQXVuYm94IFNvZnR3YXJlIENvLiwgTHRkLjwvTGljZW5zZWRUbz4KICAgIDxFbWFpbFRvPnNhbGVzQGF1bnRlYy5jb208L0VtYWlsVG8+CiAgICA8TGljZW5zZVR5cGU+RGV2ZWxvcGVyIE9FTTwvTGljZW5zZVR5cGU+CiAgICA8TGljZW5zZU5vdGU+TGltaXRlZCB0byAxIGRldmVsb3BlciwgdW5saW1pdGVkIHBoeXNpY2FsIGxvY2F0aW9uczwvTGljZW5zZU5vdGU+CiAgICA8T3JkZXJJRD4xOTA4MjYwODA3NTM8L09yZGVySUQ+CiAgICA8VXNlcklEPjEzNDk3NjAwNjwvVXNlcklEPgogICAgPE9FTT5UaGlzIGlzIGEgcmVkaXN0cmlidXRhYmxlIGxpY2Vuc2U8L09FTT4KICAgIDxQcm9kdWN0cz4KICAgICAgPFByb2R1Y3Q+QXNwb3NlLlRvdGFsIGZvciAuTkVUPC9Qcm9kdWN0PgogICAgPC9Qcm9kdWN0cz4KICAgIDxFZGl0aW9uVHlwZT5FbnRlcnByaXNlPC9FZGl0aW9uVHlwZT4KICAgIDxTZXJpYWxOdW1iZXI+M2U0NGRlMzAtZmNkMi00MTA2LWIzNWQtNDZjNmEzNzE1ZmMyPC9TZXJpYWxOdW1iZXI+CiAgICA8U3Vic2NyaXB0aW9uRXhwaXJ5PjIwMjAwODI3PC9TdWJzY3JpcHRpb25FeHBpcnk+CiAgICA8TGljZW5zZVZlcnNpb24+My4wPC9MaWNlbnNlVmVyc2lvbj4KICAgIDxMaWNlbnNlSW5zdHJ1Y3Rpb25zPmh0dHBzOi8vcHVyY2hhc2UuYXNwb3NlLmNvbS9wb2xpY2llcy91c2UtbGljZW5zZTwvTGljZW5zZUluc3RydWN0aW9ucz4KICA8L0RhdGE+CiAgPFNpZ25hdHVyZT53UGJtNUt3ZTYvRFZXWFNIY1o4d2FiVEFQQXlSR0pEOGI3L00zVkV4YWZpQnd5U2h3YWtrNGI5N2c2eGtnTjhtbUFGY3J0c0cwd1ZDcnp6MytVYk9iQjRYUndTZWxsTFdXeXNDL0haTDNpN01SMC9jZUFxaVZFOU0rWndOQkR4RnlRbE9uYTFQajhQMzhzR1grQ3ZsemJLZFZPZXk1S3A2dDN5c0dqYWtaL1E9PC9TaWduYXR1cmU+CjwvTGljZW5zZT4=")));
  113. new Aspose.Slides.License().SetLicense(new MemoryStream(Convert.FromBase64String("PExpY2Vuc2U+CiAgPERhdGE+CiAgICA8TGljZW5zZWRUbz5TdXpob3UgQXVuYm94IFNvZnR3YXJlIENvLiwgTHRkLjwvTGljZW5zZWRUbz4KICAgIDxFbWFpbFRvPnNhbGVzQGF1bnRlYy5jb208L0VtYWlsVG8+CiAgICA8TGljZW5zZVR5cGU+RGV2ZWxvcGVyIE9FTTwvTGljZW5zZVR5cGU+CiAgICA8TGljZW5zZU5vdGU+TGltaXRlZCB0byAxIGRldmVsb3BlciwgdW5saW1pdGVkIHBoeXNpY2FsIGxvY2F0aW9uczwvTGljZW5zZU5vdGU+CiAgICA8T3JkZXJJRD4xOTA4MjYwODA3NTM8L09yZGVySUQ+CiAgICA8VXNlcklEPjEzNDk3NjAwNjwvVXNlcklEPgogICAgPE9FTT5UaGlzIGlzIGEgcmVkaXN0cmlidXRhYmxlIGxpY2Vuc2U8L09FTT4KICAgIDxQcm9kdWN0cz4KICAgICAgPFByb2R1Y3Q+QXNwb3NlLlRvdGFsIGZvciAuTkVUPC9Qcm9kdWN0PgogICAgPC9Qcm9kdWN0cz4KICAgIDxFZGl0aW9uVHlwZT5FbnRlcnByaXNlPC9FZGl0aW9uVHlwZT4KICAgIDxTZXJpYWxOdW1iZXI+M2U0NGRlMzAtZmNkMi00MTA2LWIzNWQtNDZjNmEzNzE1ZmMyPC9TZXJpYWxOdW1iZXI+CiAgICA8U3Vic2NyaXB0aW9uRXhwaXJ5PjIwMjAwODI3PC9TdWJzY3JpcHRpb25FeHBpcnk+CiAgICA8TGljZW5zZVZlcnNpb24+My4wPC9MaWNlbnNlVmVyc2lvbj4KICAgIDxMaWNlbnNlSW5zdHJ1Y3Rpb25zPmh0dHBzOi8vcHVyY2hhc2UuYXNwb3NlLmNvbS9wb2xpY2llcy91c2UtbGljZW5zZTwvTGljZW5zZUluc3RydWN0aW9ucz4KICA8L0RhdGE+CiAgPFNpZ25hdHVyZT53UGJtNUt3ZTYvRFZXWFNIY1o4d2FiVEFQQXlSR0pEOGI3L00zVkV4YWZpQnd5U2h3YWtrNGI5N2c2eGtnTjhtbUFGY3J0c0cwd1ZDcnp6MytVYk9iQjRYUndTZWxsTFdXeXNDL0haTDNpN01SMC9jZUFxaVZFOU0rWndOQkR4RnlRbE9uYTFQajhQMzhzR1grQ3ZsemJLZFZPZXk1S3A2dDN5c0dqYWtaL1E9PC9TaWduYXR1cmU+CjwvTGljZW5zZT4=")));
  114. InitializeComponent();
  115. double proportion = 1036.0 / 1290.0;
  116. Width = (PrimaryScreen.ScaleWorkingAreaSize.Height) / proportion - (BorderThickness.Left + BorderThickness.Right);
  117. Height = PrimaryScreen.ScaleWorkingAreaSize.Height - (BorderThickness.Top + BorderThickness.Bottom);
  118. GridContent.Width = Width - 14;
  119. GridContent.Height = Height;
  120. #region 读取本地配置
  121. if (File.Exists(APP.dataPath + "interfaceAddress.txt")) //若不为空
  122. {
  123. APP.apiUrl = System.IO.File.ReadAllText(APP.dataPath + "interfaceAddress.txt", Encoding.Default);
  124. }
  125. if (File.Exists(APP.dataPath + "imageUploadAddress.txt")) //若不为空
  126. {
  127. APP.uploadUrl = System.IO.File.ReadAllText(APP.dataPath + "imageUploadAddress.txt", Encoding.Default);
  128. }
  129. if (File.Exists(APP.dataPath + "pictureShowsAddress.txt")) //若不为空
  130. {
  131. APP.showImageUrl = System.IO.File.ReadAllText(APP.dataPath + "pictureShowsAddress.txt", Encoding.Default);
  132. }
  133. #endregion
  134. //GridMain.Height= PrimaryScreen.ScaleScreenSize().Height - 40;
  135. //this.Top = (screeHeight - this.Height) / 2;
  136. //this.Left = (screeWidth - this.Width) / 2;
  137. ResizeMode = System.Windows.ResizeMode.CanMinimize;
  138. btnPrint.IsEnabled = false;
  139. myblackboard = new BlackboardNew(blackboard_canvas);
  140. APP.pageData.pagenum = 0;
  141. APP.pageData.currpage = 0;
  142. DataContext = APP.pageData;
  143. //APP.SaveDraw();//画板模型第一页初始化
  144. APP.PageDrawList = new List<Model_DrawData>();
  145. Model_DrawData model_DrawData = new Model_DrawData
  146. {
  147. PageNum = APP.pageData.currpage
  148. };
  149. APP.PageDrawList.Add(model_DrawData);
  150. txbv.Text = "v" + FileToolsCommon.GetConfigValue("VersionName");
  151. txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoType");
  152. if (FileToolsCommon.GetConfigValue("IsSound").Equals("true"))
  153. {
  154. rbnY.IsChecked = true;
  155. }
  156. else
  157. {
  158. rbnN.IsChecked = true;
  159. }
  160. txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoSavePath");
  161. Initialize();
  162. InitPen();
  163. }
  164. /// <summary>
  165. /// 初始化
  166. /// </summary>
  167. public void Initialize()
  168. {
  169. if (APP.isDebug)
  170. {
  171. txbVersion.Text = "测试版:";
  172. }
  173. else
  174. {
  175. txbVersion.Text = "正式版:";
  176. }
  177. #region 数据初始化
  178. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  179. FileToolsCommon.CreateDirectory(pathTemp);
  180. APP.pageData.pagenum = 0;
  181. APP.pageData.currpage = APP.pageData.pagenum;
  182. btnStop.IsEnabled = false;//停止录制按钮不可点击
  183. #endregion
  184. k_hook = new KeyboardHookCommon();
  185. k_hook.KeyDownEvent += K_hook_KeyDownEvent;
  186. k_hook.Start();//安装键盘钩子
  187. APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  188. //创建 DrawingAttributes 类的一个实例
  189. drawingAttributes = new DrawingAttributes();
  190. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  191. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  192. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  193. blackboard_canvas.UseCustomCursor = true;
  194. drawingAttributes.FitToCurve = true;
  195. drawingAttributes.IgnorePressure = false;
  196. drawingAttributes.Width = PenSize;
  197. drawingAttributes.Height = PenSize;
  198. drawingAttributes.Color = Color;
  199. blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  200. //wfhCamera.Visibility = Visibility.Hidden;
  201. ImgPDFPath = null;
  202. ImgPDFPath = new string[300];
  203. //gridM.Height = gridM.ActualWidth / proportion;
  204. //gridM.Height = gridM.Width / proportion;
  205. }
  206. /// <summary>
  207. /// 初始化快捷键
  208. /// </summary>
  209. public void InitializeKeyDownEvent()
  210. {
  211. k_hook.Start();//安装键盘钩子
  212. }
  213. /// <summary>
  214. /// 快捷键
  215. /// </summary>
  216. /// <param name="sender"></param>
  217. /// <param name="e"></param>
  218. private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
  219. {
  220. if (e.KeyValue == (int)System.Windows.Forms.Keys.Left)
  221. {
  222. if (APP.pageData.currpage > 1)
  223. {
  224. //上一页
  225. last_button_Click(null, null);
  226. }
  227. }
  228. if (e.KeyValue == (int)System.Windows.Forms.Keys.Right)
  229. {
  230. if (APP.pageData.currpage < APP.pageData.pagenum)
  231. {
  232. //下一页
  233. next_btn_Click(null, null);
  234. }
  235. }
  236. if (e.KeyValue == (int)System.Windows.Forms.Keys.Delete)
  237. {
  238. if (RectImgBorder.Visibility != Visibility.Hidden)
  239. {
  240. HideAngleBorder();
  241. imgCanvas.Source = null;
  242. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = null;
  243. APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath = null;
  244. }
  245. }
  246. }
  247. #endregion
  248. #region 事件
  249. /// <summary>
  250. /// 窗体移动
  251. /// </summary>
  252. /// <param name="sender"></param>
  253. /// <param name="e"></param>
  254. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  255. {
  256. DragMove();
  257. }
  258. #region 摄像头
  259. private System.Timers.Timer times;
  260. private List<string> RbnOpen;
  261. private bool IsRbnOpen = false;
  262. /// <summary>
  263. /// 摄像头打开事件
  264. /// </summary>
  265. /// <param name="sender"></param>
  266. /// <param name="e"></param>
  267. private void RbnOpen_Click(object sender, RoutedEventArgs e)
  268. {
  269. if (!IsRbnOpen)
  270. {
  271. #region 防止连击
  272. if (IsPressButton)
  273. {
  274. return;
  275. }
  276. else
  277. {
  278. IsPressButton = true;
  279. new Thread(new ThreadStart(new Action(() =>
  280. {
  281. //Dispatcher.Invoke(new Action(() => { rbnTurnOff.IsEnabled = false; }));
  282. Thread.Sleep(500);
  283. //Dispatcher.Invoke(new Action(() => { rbnTurnOff.IsEnabled = true; }));
  284. IsPressButton = false;
  285. }))).Start();
  286. }
  287. #endregion
  288. CameraHelper.UpdateCameraDevices();
  289. if (CameraHelper.CameraDevices.Count > 0)
  290. {
  291. CameraHelper.SetCameraDevice(0);
  292. RbnOpen = new List<string>();
  293. times = new System.Timers.Timer(200)//初始值为300
  294. {
  295. AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
  296. };//设置执行一次(false)还是一直执行(true)
  297. times.Elapsed += new System.Timers.ElapsedEventHandler(Times_Elapsed);
  298. times.Enabled = true; //启动计时器
  299. IsRbnOpen = true;
  300. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  301. FileToolsCommon.CreateDirectory(imgPath);
  302. }
  303. }
  304. }
  305. private int I = 9999;
  306. private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  307. {
  308. if (IsRbnOpen)
  309. {
  310. try
  311. {
  312. Dispatcher.Invoke(() =>
  313. {
  314. if (I > 10010)
  315. {
  316. long time = Timestamp();
  317. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  318. //string FilePathName = ImgPath + RsImgName.Count + ".png";
  319. string path = CameraHelper.CaptureImage(imgPath, time.ToString());
  320. if (!string.IsNullOrWhiteSpace(path))
  321. {
  322. RbnOpen.Add(path);
  323. imgPlayerRight.Visibility = Visibility.Visible;
  324. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  325. if ("1".Equals(APP.CameraPosition))
  326. {
  327. imgPlayerRight.Visibility = Visibility.Visible;
  328. imgPlayerLeft.Visibility = Visibility.Collapsed;
  329. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  330. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  331. imgPlayerRight.Source = new BitmapImage(new Uri(path));
  332. }
  333. else if ("2".Equals(APP.CameraPosition))
  334. {
  335. imgPlayerRight.Visibility = Visibility.Collapsed;
  336. imgPlayerLeft.Visibility = Visibility.Visible;
  337. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  338. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  339. imgPlayerLeft.Source = new BitmapImage(new Uri(path));
  340. }
  341. else if ("3".Equals(APP.CameraPosition))
  342. {
  343. imgPlayerRight.Visibility = Visibility.Collapsed;
  344. imgPlayerLeft.Visibility = Visibility.Collapsed;
  345. imgPlayerRightUnder.Visibility = Visibility.Visible;
  346. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  347. imgPlayerRightUnder.Source = new BitmapImage(new Uri(path));
  348. }
  349. else if ("4".Equals(APP.CameraPosition))
  350. {
  351. imgPlayerRight.Visibility = Visibility.Collapsed;
  352. imgPlayerLeft.Visibility = Visibility.Collapsed;
  353. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  354. imgPlayerLeftUnder.Visibility = Visibility.Visible;
  355. imgPlayerLeftUnder.Source = new BitmapImage(new Uri(path));
  356. }
  357. else
  358. {
  359. imgPlayerLeft.Visibility = Visibility.Collapsed;
  360. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  361. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  362. imgPlayerRight.Source = new BitmapImage(new Uri(path));
  363. }
  364. }
  365. }
  366. I++;
  367. });
  368. }
  369. catch (Exception ex)
  370. {
  371. LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
  372. }
  373. }
  374. }
  375. /// <summary>
  376. /// 摄像头关闭事件
  377. /// </summary>
  378. /// <param name="sender"></param>
  379. /// <param name="e"></param>
  380. private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
  381. {
  382. if (IsRbnOpen)
  383. {
  384. #region 防止连击
  385. if (IsPressButton)
  386. {
  387. return;
  388. }
  389. else
  390. {
  391. IsPressButton = true;
  392. new Thread(new ThreadStart(new Action(() =>
  393. {
  394. //Dispatcher.Invoke(new Action(() => { rbnOpen.IsEnabled = false; }));
  395. Thread.Sleep(500);
  396. //Dispatcher.Invoke(new Action(() => { rbnOpen.IsEnabled = true; }));
  397. IsPressButton = false;
  398. }))).Start();
  399. }
  400. #endregion
  401. IsRbnOpen = false;
  402. imgPlayerRight.Visibility = Visibility.Collapsed;
  403. imgPlayerLeft.Visibility = Visibility.Collapsed;
  404. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  405. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  406. CameraHelper.CloseDevice();
  407. I = 9999;
  408. }
  409. }
  410. #endregion
  411. #endregion
  412. /// <summary>
  413. /// 关闭事件
  414. /// </summary>
  415. /// <param name="sender"></param>
  416. /// <param name="e"></param>
  417. private void BtnDown_Click(object sender, RoutedEventArgs e)
  418. {
  419. if (IsFirstR)
  420. {
  421. MessageBoxResult br = MessageWindow.Show("确定退出系统?", "退出", MessageBoxButton.OKCancel);
  422. if (br == MessageBoxResult.OK)
  423. {
  424. APP.Killffmpeg();
  425. APP.SaveWkData();
  426. APP.SaveDraw();
  427. Thread.Sleep(100);
  428. System.Environment.Exit(0);
  429. }
  430. }
  431. else
  432. {
  433. MessageWindow.Show("当前正在录制,请先停止录制。");
  434. return;
  435. //MessageBoxResult dr = MessageWindow.Show("当前正在录制,是否停止录制?", "提示", MessageBoxButton.OKCancel);
  436. //if (dr == MessageBoxResult.OK)
  437. //{
  438. // APP.SaveWkData();
  439. // APP.SaveDraw();
  440. // BtnStop_Click(null, null);
  441. // while (!IsFirstR)
  442. // {
  443. // Thread.Sleep(100);
  444. // }
  445. // System.Environment.Exit(0);
  446. //}
  447. //else
  448. //{
  449. // return;
  450. //}
  451. }
  452. }
  453. #region 设置
  454. /// <summary>
  455. /// 设置事件
  456. /// </summary>
  457. /// <param name="sender"></param>
  458. /// <param name="e"></param>
  459. private void BtnSetUp_Click(object sender, RoutedEventArgs e)
  460. {
  461. if (!TxbRecordingWord.Text.Equals("暂停"))
  462. {
  463. if (gridSetUp.Visibility == Visibility.Collapsed)
  464. {
  465. GridMain.Visibility = Visibility.Collapsed;
  466. gridSetUp.Visibility = Visibility.Visible;
  467. //gridUpload.Visibility = Visibility.Collapsed;
  468. GridMyVideo.Visibility = Visibility.Collapsed;
  469. txbStoragePath.Content = APP.WKData.WkPath;
  470. GridMyVideo.Visibility = Visibility.Collapsed;
  471. #region 读取用户配置
  472. //接口地址
  473. if (!File.Exists(APP.dataPath + "interfaceAddress.txt")) //若为空
  474. {
  475. txbInterfaceAddress.Text = APP.apiUrl.Replace("http://", "").Trim();
  476. }
  477. else
  478. {
  479. txbInterfaceAddress.Text = System.IO.File.ReadAllText(APP.dataPath + "interfaceAddress.txt", Encoding.Default).Replace("http://", "").Trim();
  480. }
  481. //上传地址
  482. if (!File.Exists(APP.dataPath + "imageUploadAddress.txt")) //若为空
  483. {
  484. txbImageUploadAddress.Text = APP.uploadUrl.Replace("http://", "").Replace("/", "").Trim();
  485. }
  486. else
  487. {
  488. txbImageUploadAddress.Text = System.IO.File.ReadAllText(APP.dataPath + "imageUploadAddress.txt", Encoding.Default).Replace("http://", "").Replace("/", "").Trim();
  489. }
  490. //下载地址
  491. if (!File.Exists(APP.dataPath + "pictureShowsAddress.txt")) //若为空
  492. {
  493. txbPictureShowsAddress.Text = APP.showImageUrl.Replace("http://", "").Replace("/", "").Replace("static", "").Trim();
  494. }
  495. else
  496. {
  497. txbPictureShowsAddress.Text = System.IO.File.ReadAllText(APP.dataPath + "pictureShowsAddress.txt", Encoding.Default).Replace("http://", "").Replace("/", "").Replace("static", "").Trim();
  498. }
  499. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  500. if ("1".Equals(APP.CameraPosition))
  501. {
  502. rbnRight.IsChecked = true;
  503. }
  504. else if ("2".Equals(APP.CameraPosition))
  505. {
  506. rbnLeft.IsChecked = true;
  507. }
  508. else if ("3".Equals(APP.CameraPosition))
  509. {
  510. rbnRightUnder.IsChecked = true;
  511. }
  512. else if ("4".Equals(APP.CameraPosition))
  513. {
  514. rbnLeftUnder.IsChecked = true;
  515. }
  516. string type = FileToolsCommon.GetConfigValue("VideoType");//<!--视频格式 1、MP4 2、FlV 3、AVI-->
  517. if ("1".Equals(type))
  518. {
  519. rbnMP4.IsChecked = true;
  520. }
  521. else if ("2".Equals(type))
  522. {
  523. rbnFLV.IsChecked = true;
  524. }
  525. else if ("3".Equals(type))
  526. {
  527. rbnAVI.IsChecked = true;
  528. }
  529. string isSound = FileToolsCommon.GetConfigValue("IsSound");//<!--声音 true 有 false 无-->
  530. if (isSound == "true")
  531. {
  532. rbnY.IsChecked = true;
  533. }
  534. else
  535. {
  536. rbnN.IsChecked = true;
  537. }
  538. #endregion
  539. }
  540. else
  541. {
  542. GridMain.Visibility = Visibility.Visible;
  543. gridSetUp.Visibility = Visibility.Collapsed;
  544. //gridUpload.Visibility = Visibility.Collapsed;
  545. GridMyVideo.Visibility = Visibility.Collapsed;
  546. if (APP.pageData.pagenum > 0)
  547. {
  548. gridPage.Visibility = Visibility.Visible;
  549. }
  550. DataContext = APP.pageData;
  551. }
  552. }
  553. }
  554. /// <summary>
  555. /// 设置 保存事件
  556. /// </summary>
  557. /// <param name="sender"></param>
  558. /// <param name="e"></param>
  559. private void BtnSave_Click(object sender, RoutedEventArgs e)
  560. {
  561. try
  562. {
  563. ImgRecord.Visibility = Visibility.Visible;//设置结束时可录制
  564. ImgRecordTwo.Visibility = Visibility.Collapsed;//设置结束时可录制
  565. BtnRecord.IsEnabled = true;//设置结束时可录制
  566. if (!string.IsNullOrWhiteSpace(txbInterfaceAddress.Text))
  567. {
  568. string ApplicationData = APP.dataPath + "interfaceAddress.txt";
  569. string temp = "http://" + txbInterfaceAddress.Text;
  570. System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  571. }
  572. else
  573. {
  574. MessageWindow.Show("请输入接口地址");
  575. return;
  576. }
  577. if (!string.IsNullOrWhiteSpace(txbImageUploadAddress.Text))//图片上传地址
  578. {
  579. string ApplicationData = APP.dataPath + "imageUploadAddress.txt";
  580. string temp = "http://" + txbImageUploadAddress.Text + "/";
  581. System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  582. }
  583. else
  584. {
  585. MessageWindow.Show("请输入上传地址");
  586. return;
  587. }
  588. if (!string.IsNullOrWhiteSpace(txbPictureShowsAddress.Text))
  589. {
  590. string ApplicationData = APP.dataPath + "pictureShowsAddress.txt";
  591. string temp = "http://" + txbPictureShowsAddress.Text + "/static/";
  592. System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  593. }
  594. else
  595. {
  596. MessageWindow.Show("请输入下载地址");
  597. return;
  598. }
  599. if (!APP.apiUrl.Equals("http://" + txbInterfaceAddress.Text))
  600. {
  601. APP.apiUrl = "http://" + txbInterfaceAddress.Text;
  602. if (!txbLoginType.Text.Equals("未登录"))
  603. {
  604. LoginType();
  605. MessageWindow.Show("接口地址已修改,请重新登陆!");
  606. }
  607. }
  608. if (!APP.uploadUrl.Equals(txbImageUploadAddress.Text))
  609. {
  610. APP.uploadUrl = "http://" + txbImageUploadAddress.Text + "/";
  611. }
  612. if (!APP.showImageUrl.Equals(txbPictureShowsAddress.Text))
  613. {
  614. APP.showImageUrl = "http://" + txbPictureShowsAddress.Text + "/static/";
  615. }
  616. if (rbnMP4.IsChecked == true)
  617. {
  618. //存储文件
  619. FileToolsCommon.SetConfigValue("VideoType", "1");
  620. }
  621. else if (rbnFLV.IsChecked == true)
  622. {
  623. FileToolsCommon.SetConfigValue("VideoType", "2");
  624. }
  625. else
  626. {
  627. FileToolsCommon.SetConfigValue("VideoType", "3");
  628. }
  629. if (rbnY.IsChecked == true)
  630. {
  631. FileToolsCommon.SetConfigValue("IsSound", "true");
  632. }
  633. else
  634. {
  635. FileToolsCommon.SetConfigValue("IsSound", "false");
  636. }
  637. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  638. if (rbnRight.IsChecked == true)
  639. {
  640. FileToolsCommon.SetConfigValue("CameraPosition", "1");
  641. }
  642. else if (rbnLeft.IsChecked == true)
  643. {
  644. FileToolsCommon.SetConfigValue("CameraPosition", "2");
  645. }
  646. else if (rbnRightUnder.IsChecked == true)
  647. {
  648. FileToolsCommon.SetConfigValue("CameraPosition", "3");
  649. }
  650. else if (rbnLeftUnder.IsChecked == true)
  651. {
  652. FileToolsCommon.SetConfigValue("CameraPosition", "4");
  653. }
  654. if (rbnMP4.IsChecked == true)
  655. {
  656. FileToolsCommon.SetConfigValue("VideoType", "1");
  657. }
  658. else if (rbnFLV.IsChecked == true)
  659. {
  660. FileToolsCommon.SetConfigValue("VideoType", "2");
  661. }
  662. else if (rbnAVI.IsChecked == true)
  663. {
  664. FileToolsCommon.SetConfigValue("VideoType", "3");
  665. }
  666. APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  667. GridMain.Visibility = Visibility.Visible;
  668. gridSetUp.Visibility = Visibility.Collapsed;
  669. imgPlayerRight.Visibility = Visibility.Collapsed;
  670. imgPlayerLeft.Visibility = Visibility.Collapsed;
  671. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  672. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  673. if (!txbStoragePath.Content.ToString().Equals(APP.WKData.WkPath))
  674. {
  675. //存储文件
  676. FileToolsCommon.SetConfigValue("VideoSavePath", txbStoragePath.Content.ToString());
  677. MessageWindow.Show("路径已变更,下次创建微课时自动生效。");
  678. }
  679. }
  680. catch (Exception ex)
  681. {
  682. LogHelper.WriteErrLog("XHMicroLessonSystemWindow(设置保存事件报错:)" + ex.Message, ex);
  683. }
  684. }
  685. /// <summary>
  686. /// 设置 浏览事件
  687. /// </summary>
  688. /// <param name="sender"></param>
  689. /// <param name="e"></param>
  690. private void BtnBrowse_Click(object sender, RoutedEventArgs e)
  691. {
  692. //System.Diagnostics.Process.Start(APP.WKData.WkPath);
  693. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  694. Ofd = new System.Windows.Forms.FolderBrowserDialog();
  695. Result = Ofd.ShowDialog();
  696. if (Result == System.Windows.Forms.DialogResult.OK)
  697. {
  698. if (Ofd.SelectedPath != "")
  699. {
  700. txbStoragePath.Content = Ofd.SelectedPath;
  701. //string ApplicationData = ZConfig.dataPath + "fileStorageAddress.txt";
  702. //string temp = ofd.SelectedPath;
  703. //System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  704. }
  705. }
  706. }
  707. #endregion
  708. #region 画笔
  709. /// <summary>
  710. /// 画笔颜色事件 白色
  711. /// </summary>
  712. /// <param name="sender"></param>
  713. /// <param name="e"></param>
  714. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  715. {
  716. ////创建 DrawingAttributes 类的一个实例
  717. //drawingAttributes = new DrawingAttributes();
  718. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  719. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  720. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  721. ////设置 DrawingAttributes 的 Color 属性设置颜色
  722. drawingAttributes.Color = Colors.White;
  723. Color = Colors.White;
  724. }
  725. /// <summary>
  726. /// 画笔颜色事件 红色
  727. /// </summary>
  728. /// <param name="sender"></param>
  729. /// <param name="e"></param>
  730. private void BtnRed_Click(object sender, RoutedEventArgs e)
  731. {
  732. //设置 DrawingAttributes 的 Color 属性设置颜色
  733. drawingAttributes.Color = Colors.Red;
  734. Color = Colors.Red;
  735. imgRed.Visibility = Visibility.Visible;
  736. imgGray.Visibility = Visibility.Collapsed;
  737. imgCyanBlue.Visibility = Visibility.Collapsed;
  738. imgYellow.Visibility = Visibility.Collapsed;
  739. imgBlue.Visibility = Visibility.Collapsed;
  740. }
  741. /// <summary>
  742. /// 画笔颜色事件 黑色
  743. /// </summary>
  744. /// <param name="sender"></param>
  745. /// <param name="e"></param>
  746. private void BtnGray_Click(object sender, RoutedEventArgs e)
  747. {
  748. drawingAttributes.Color = Colors.Black;
  749. Color = Colors.Black;
  750. imgRed.Visibility = Visibility.Collapsed;
  751. imgGray.Visibility = Visibility.Visible;
  752. imgCyanBlue.Visibility = Visibility.Collapsed;
  753. imgYellow.Visibility = Visibility.Collapsed;
  754. imgBlue.Visibility = Visibility.Collapsed;
  755. }
  756. /// <summary>
  757. /// 画笔颜色事件 青色
  758. /// </summary>
  759. /// <param name="sender"></param>
  760. /// <param name="e"></param>
  761. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  762. {
  763. drawingAttributes.Color = Colors.LimeGreen;
  764. Color = Colors.LimeGreen;
  765. imgRed.Visibility = Visibility.Collapsed;
  766. imgGray.Visibility = Visibility.Collapsed;
  767. imgCyanBlue.Visibility = Visibility.Visible;
  768. imgYellow.Visibility = Visibility.Collapsed;
  769. imgBlue.Visibility = Visibility.Collapsed;
  770. }
  771. /// <summary>
  772. /// 画笔颜色事件 黄色
  773. /// </summary>
  774. /// <param name="sender"></param>
  775. /// <param name="e"></param>
  776. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  777. {
  778. drawingAttributes.Color = Colors.Gold;
  779. Color = Colors.Gold;
  780. imgRed.Visibility = Visibility.Collapsed;
  781. imgGray.Visibility = Visibility.Collapsed;
  782. imgCyanBlue.Visibility = Visibility.Collapsed;
  783. imgYellow.Visibility = Visibility.Visible;
  784. imgBlue.Visibility = Visibility.Collapsed;
  785. }
  786. /// <summary>
  787. /// 画笔颜色事件 蓝色
  788. /// </summary>
  789. /// <param name="sender"></param>
  790. /// <param name="e"></param>
  791. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  792. {
  793. drawingAttributes.Color = Colors.DeepSkyBlue;
  794. Color = Colors.DeepSkyBlue;
  795. imgRed.Visibility = Visibility.Collapsed;
  796. imgGray.Visibility = Visibility.Collapsed;
  797. imgCyanBlue.Visibility = Visibility.Collapsed;
  798. imgYellow.Visibility = Visibility.Collapsed;
  799. imgBlue.Visibility = Visibility.Visible;
  800. }
  801. /// <summary>
  802. /// 画笔粗细事件 细
  803. /// </summary>
  804. /// <param name="sender"></param>
  805. /// <param name="e"></param>
  806. private void RbnFine_Click(object sender, RoutedEventArgs e)
  807. {
  808. drawingAttributes.Width = 1;
  809. drawingAttributes.Height = 1;
  810. PenSize = 1;
  811. }
  812. /// <summary>
  813. /// 画笔粗细事件 中
  814. /// </summary>
  815. /// <param name="sender"></param>
  816. /// <param name="e"></param>
  817. private void RbnIn_Click(object sender, RoutedEventArgs e)
  818. {
  819. drawingAttributes.Width = 3;
  820. drawingAttributes.Height = 3;
  821. PenSize = 3;
  822. }
  823. /// <summary>
  824. /// 画笔粗细事件 粗
  825. /// </summary>
  826. /// <param name="sender"></param>
  827. /// <param name="e"></param>
  828. private void RbnCrude_Click(object sender, RoutedEventArgs e)
  829. {
  830. drawingAttributes.Width = 5;
  831. drawingAttributes.Height = 5;
  832. PenSize = 5;
  833. }
  834. #endregion
  835. #region 导入截图
  836. /// <summary>
  837. /// 截图事件
  838. /// </summary>
  839. /// <param name="sender"></param>
  840. /// <param name="e"></param>
  841. private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
  842. {
  843. Record();
  844. HideAngleBorder();
  845. imgCanvas.Margin = new Thickness(0, 0, 0, 0);
  846. APP.ImgPath = string.Empty;
  847. string time = GetTimeStamp();
  848. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
  849. APP.ImgPath = desktopPath;
  850. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), desktopPath, false, out BitmapImage bitmap);
  851. k_hook.Stop();
  852. if (WindowState == WindowState.Normal)//截图隐藏窗口
  853. {
  854. WindowState = WindowState.Minimized;
  855. }
  856. if (APP.W_JieTuWindow != null)
  857. {
  858. APP.W_JieTuWindow.initialization();
  859. APP.W_JieTuWindow.Screenshot();
  860. APP.W_JieTuWindow.InitializeKeyDownEvent();
  861. APP.W_JieTuWindow.WindowState = WindowState.Maximized;
  862. APP.W_JieTuWindow.Visibility = Visibility.Visible;
  863. }
  864. else
  865. {
  866. APP.W_JieTuWindow = new JieTuWindow();
  867. APP.W_JieTuWindow.InitializeKeyDownEvent();
  868. // 订阅事件
  869. APP.W_JieTuWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
  870. APP.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
  871. APP.W_JieTuWindow.Show();
  872. }
  873. //imgCanvas.Source = new BitmapImage(new Uri(desktopPath));
  874. }
  875. public void WindowType()
  876. {
  877. if (WindowState == WindowState.Minimized)//截图完恢复窗口
  878. {
  879. Topmost = true;
  880. WindowState = WindowState.Normal;
  881. }
  882. }
  883. /// <summary>
  884. /// 截图关闭窗口
  885. /// </summary>
  886. /// <param name="text"></param>
  887. private void frm_ChangeTextEvent(string text)
  888. {
  889. if ("关闭窗口".Equals(text))
  890. {
  891. if (WindowState == WindowState.Minimized)//截图完恢复窗口
  892. {
  893. Topmost = true;
  894. WindowState = WindowState.Normal;
  895. }
  896. InitializeKeyDownEvent();
  897. if (!string.IsNullOrWhiteSpace(APP.ImgPath) && File.Exists(APP.ImgPath))
  898. {
  899. if (APP.pageData.currpage == 0)
  900. {
  901. APP.pageData.pagenum += 1;
  902. APP.pageData.currpage = APP.pageData.pagenum;
  903. myblackboard.changepage(APP.pageData.currpage - 1);
  904. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  905. }
  906. if (APP.PageDrawList.Count >= APP.pageData.currpage)
  907. {
  908. APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath = APP.ImgPath;//zxycs
  909. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = APP.ImgPath;
  910. }
  911. else
  912. {
  913. Model_DrawData model_DrawData = new Model_DrawData
  914. {
  915. PageImagePath = APP.ImgPath,
  916. PdfImagePath = APP.ImgPath
  917. };
  918. APP.PageDrawList.Add(model_DrawData);
  919. }
  920. if (APP.PageDrawList.Count >= APP.pageData.currpage && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  921. {
  922. imgDocumentation.Source = null;
  923. BitmapImage bitImg = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  924. mouseDown = false;
  925. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  926. {
  927. X = 0.1,
  928. Y = 0.1
  929. };
  930. APP.PageDrawList[APP.pageData.currpage - 1].Type = "截图";
  931. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  932. imgCanvas.Source = bitImg;
  933. imgCanvas.Width = bitImg.Width;
  934. imgCanvas.Height = bitImg.Height;
  935. scroMain.ScrollToVerticalOffset(0);
  936. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  937. {
  938. CenterX = imgCanvas.Width,
  939. CenterY = imgCanvas.Height
  940. };
  941. ImgPrint.Visibility = Visibility.Visible;//截图成功可打印
  942. ImgPrintTwo.Visibility = Visibility.Collapsed;
  943. btnPrint.IsEnabled = true;
  944. }
  945. }
  946. Topmost = false;
  947. }
  948. }
  949. /// <summary>
  950. /// 截图关闭 非正常关闭截图时,截图清空
  951. /// </summary>
  952. private void JietuWindow_click_closeJietuWindowClick()
  953. {
  954. if (WindowState == WindowState.Minimized)//截图完恢复窗口
  955. {
  956. WindowState = WindowState.Normal;
  957. }
  958. APP.W_JieTuWindow = null;
  959. }
  960. /// 截图的图片鼠标右键事件
  961. /// </summary>
  962. /// <param name="sender"></param>
  963. /// <param name="e"></param>
  964. private void imgCanvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
  965. {
  966. imgCanvas.Source = null;
  967. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = null;
  968. APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath = null;
  969. }
  970. /// <summary>
  971. /// 导入事件
  972. /// </summary>
  973. /// <param name="sender"></param>
  974. /// <param name="e"></param>
  975. private void BtnImport_Click(object sender, RoutedEventArgs e)
  976. {
  977. try
  978. {
  979. Record();
  980. HideAngleBorder();
  981. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  982. ofd = new System.Windows.Forms.OpenFileDialog
  983. {
  984. //Filter = "文档|*.docx;*.doc;*.ppt;*.pptx",
  985. Filter = "文档|*.docx;*.doc;*.ppt;*.pptx;*.pdf",
  986. InitialDirectory = desktopPath,
  987. Multiselect = false,
  988. AddExtension = true,
  989. DereferenceLinks = true
  990. };
  991. //APP.myloading.Show();
  992. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
  993. //new Thread(
  994. // o =>
  995. // {
  996. // Thread.Sleep(400);
  997. // Dispatcher.Invoke(new Action(() =>
  998. // {
  999. // OpenDialog();
  1000. // }
  1001. // ));
  1002. // })
  1003. //{
  1004. // IsBackground = true
  1005. //}.Start();
  1006. }
  1007. catch (Exception ex)
  1008. {
  1009. LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
  1010. }
  1011. }
  1012. /// <summary>
  1013. /// 导入-开始
  1014. /// </summary>
  1015. /// <returns></returns>
  1016. private object InvokeServering()
  1017. {
  1018. Dispatcher.Invoke(new Action(() =>
  1019. {
  1020. result = ofd.ShowDialog();
  1021. }));
  1022. if (result == System.Windows.Forms.DialogResult.OK)
  1023. {
  1024. if (ofd.FileName != "")
  1025. {
  1026. Dispatcher.Invoke(new Action(() =>
  1027. {
  1028. APP.myloading.Show();
  1029. myblackboard.changepage(APP.pageData.pagenum);
  1030. }));
  1031. #region PPT转PDF
  1032. string filepath = ofd.FileName;
  1033. string path = ofd.SafeFileName.Replace(".ppt", "").Replace(".pptx", "").Trim();
  1034. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Replace(".pptx", "typezsygppt").Replace(".pdf", "typepdf").Trim();
  1035. if (type.Contains("typezsygppt"))//ppt
  1036. {
  1037. try
  1038. {
  1039. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1040. path = pathTemp + path + ".pdf";
  1041. FileToolsCommon.CreateDirectory(pathTemp);
  1042. //PPT转PDF
  1043. Presentation ppt = new Presentation(filepath);
  1044. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  1045. #endregion
  1046. #region PDF转图片
  1047. // 图片绝对路径集合
  1048. List<string> images = new List<string>();
  1049. string directoryPath = pathTemp;
  1050. //aspose许可证
  1051. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1052. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1053. //l.SetLicense(licenseName);
  1054. //定义Jpeg转换设备
  1055. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  1056. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1057. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1058. //directoryPath += quality;
  1059. Directory.CreateDirectory(directoryPath);
  1060. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1061. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1062. //遍历每一页转为jpg
  1063. for (int i = 1; i <= document.Pages.Count; i++)
  1064. {
  1065. long ii = Timestamp();
  1066. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1067. images.Add(filePathOutPut);
  1068. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1069. try
  1070. {
  1071. device.Process(document.Pages[i], fs);
  1072. fs.Close();
  1073. }
  1074. catch (Exception)
  1075. {
  1076. fs.Close();
  1077. File.Delete(filePathOutPut);
  1078. }
  1079. }
  1080. #endregion
  1081. Dispatcher.Invoke(new Action(() =>
  1082. {
  1083. string[] page = images.ToArray();
  1084. int num = 0;
  1085. int iStart = APP.pageData.pagenum;//导入文档的开始下标
  1086. int iEnd = page.Length + APP.pageData.pagenum;//导入文档的结束下标
  1087. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1088. {
  1089. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1090. {
  1091. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1092. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1093. APP.PageDrawList[i].PageNum = i + 1;
  1094. APP.PageDrawList[i].ImgDocumentation = true;
  1095. APP.PageDrawList[i].Type = "ppt";
  1096. }
  1097. else
  1098. {
  1099. Model_DrawData model_DrawData = new Model_DrawData
  1100. {
  1101. PageImagePath = page[i - APP.pageData.pagenum],
  1102. PdfImagePath = page[i - APP.pageData.pagenum],
  1103. PageNum = i + 1,
  1104. ImgDocumentation = true,
  1105. Type = "ppt"
  1106. };
  1107. APP.PageDrawList.Add(model_DrawData);
  1108. }
  1109. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1110. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1111. btnPrint.IsEnabled = true;
  1112. APP.SaveDraw();
  1113. num++;
  1114. }
  1115. if (num > 0)
  1116. {
  1117. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1118. APP.pageData.pagenum += num;
  1119. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1120. }
  1121. if (APP.pageData.currpage > 0 && APP.pageData.currpage <= APP.PageDrawList.Count)
  1122. {
  1123. imgCanvas.Source = null;
  1124. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1125. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1126. btnScreenshot.IsEnabled = false;
  1127. imgDocumentation.Source = null;
  1128. imgPPT.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1129. scroMain.ScrollToVerticalOffset(0);
  1130. for (int i = iStart; i < iEnd; i++)
  1131. {
  1132. APP.PageDrawList[i].ImageLocation = new TranslateTransform
  1133. {
  1134. X = 0.1,
  1135. Y = 0.1
  1136. };
  1137. APP.PageDrawList[i].IsImageLocation = true;
  1138. APP.PageDrawList[i].ImageSizes = new ScaleTransform
  1139. {
  1140. CenterX = imgCanvas.Width,
  1141. CenterY = imgCanvas.Height
  1142. };
  1143. }
  1144. }
  1145. else
  1146. {
  1147. imgDocumentation.Source = null;
  1148. imgCanvas.Source = null;
  1149. imgPPT.Source = null;
  1150. ///截图可用
  1151. ImgScreenshot.Visibility = Visibility.Visible;
  1152. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1153. btnScreenshot.IsEnabled = true;
  1154. }
  1155. }));
  1156. }
  1157. catch (Exception ex)
  1158. {
  1159. Dispatcher.Invoke(new Action(() =>
  1160. {
  1161. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1162. }));
  1163. LogHelper.WriteErrLog("【打开ppt】(OpenDialog PPT)" + ex.Message, ex);
  1164. }
  1165. }
  1166. else if (type.Contains("typepdf"))
  1167. {
  1168. try
  1169. {
  1170. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1171. #region PDF转图片
  1172. // 图片绝对路径集合
  1173. List<string> images = new List<string>();
  1174. string directoryPath = pathTemp;
  1175. //aspose许可证
  1176. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1177. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1178. //l.SetLicense(licenseName);
  1179. //定义Jpeg转换设备
  1180. Aspose.Pdf.Document document = new Aspose.Pdf.Document(filepath);
  1181. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1182. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1183. //directoryPath += quality;
  1184. Directory.CreateDirectory(directoryPath);
  1185. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1186. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1187. //遍历每一页转为jpg
  1188. for (int i = 1; i <= document.Pages.Count; i++)
  1189. {
  1190. long ii = Timestamp();
  1191. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1192. images.Add(filePathOutPut);
  1193. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1194. try
  1195. {
  1196. device.Process(document.Pages[i], fs);
  1197. fs.Close();
  1198. }
  1199. catch (Exception)
  1200. {
  1201. fs.Close();
  1202. File.Delete(filePathOutPut);
  1203. }
  1204. }
  1205. #endregion
  1206. string[] page = images.ToArray();
  1207. int num = 0;
  1208. int iStart = APP.pageData.pagenum;//导入文档的开始下标
  1209. int iEnd = page.Length + APP.pageData.pagenum;//导入文档的结束下标
  1210. Dispatcher.Invoke(new Action(() =>
  1211. {
  1212. for (int i = APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1213. {
  1214. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1215. {
  1216. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1217. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1218. APP.PageDrawList[i].PageNum = i + 1;
  1219. APP.PageDrawList[i].ImgDocumentation = true;
  1220. APP.PageDrawList[i].Type = "word";
  1221. }
  1222. else
  1223. {
  1224. Model_DrawData model_DrawData = new Model_DrawData
  1225. {
  1226. PageImagePath = page[i - APP.pageData.pagenum],
  1227. PdfImagePath = page[i - APP.pageData.pagenum],
  1228. PageNum = i + 1,
  1229. ImgDocumentation = true,
  1230. Type = "word"
  1231. };
  1232. APP.PageDrawList.Add(model_DrawData);
  1233. }
  1234. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1235. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1236. btnPrint.IsEnabled = true;
  1237. APP.SaveDraw();
  1238. num++;
  1239. }
  1240. if (num > 0)
  1241. {
  1242. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1243. APP.pageData.pagenum += num;
  1244. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1245. }
  1246. if (APP.pageData.currpage > 0 && APP.pageData.currpage <= APP.PageDrawList.Count)
  1247. {
  1248. imgCanvas.Source = null;
  1249. imgPPT.Source = null;
  1250. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1251. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1252. btnScreenshot.IsEnabled = false;
  1253. imgDocumentation.Visibility = Visibility.Visible;
  1254. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  1255. scroMain.ScrollToVerticalOffset(0);
  1256. }
  1257. else
  1258. {
  1259. imgDocumentation.Source = null;
  1260. imgCanvas.Source = null;
  1261. imgPPT.Source = null;
  1262. ///截图可用
  1263. ImgScreenshot.Visibility = Visibility.Visible;
  1264. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1265. btnScreenshot.IsEnabled = true;
  1266. }
  1267. }));
  1268. }
  1269. catch (Exception ex)
  1270. {
  1271. Dispatcher.Invoke(new Action(() =>
  1272. {
  1273. MessageWindow.Show(ex.Message);
  1274. }));
  1275. LogHelper.WriteErrLog("【打开pdf】(OpenDialog pdf)" + ex.Message, ex);
  1276. }
  1277. }
  1278. else//word
  1279. {
  1280. try
  1281. {
  1282. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1283. string[] page = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
  1284. int num = 0;
  1285. Dispatcher.Invoke(new Action(() =>
  1286. {
  1287. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1288. {
  1289. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1290. {
  1291. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1292. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1293. APP.PageDrawList[i].PageNum = i + 1;
  1294. APP.PageDrawList[i].ImgDocumentation = true;
  1295. APP.PageDrawList[i].Type = "word";
  1296. }
  1297. else
  1298. {
  1299. Model_DrawData model_DrawData = new Model_DrawData
  1300. {
  1301. PageImagePath = page[i - APP.pageData.pagenum],
  1302. PdfImagePath = page[i - APP.pageData.pagenum],
  1303. PageNum = i + 1,
  1304. ImgDocumentation = true,
  1305. Type = "word"
  1306. };
  1307. APP.PageDrawList.Add(model_DrawData);
  1308. }
  1309. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1310. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1311. btnPrint.IsEnabled = true;
  1312. APP.SaveDraw();
  1313. num++;
  1314. }
  1315. if (num > 0)
  1316. {
  1317. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1318. APP.pageData.pagenum += num;
  1319. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1320. }
  1321. if (APP.pageData.currpage > 0 && APP.pageData.currpage <= APP.PageDrawList.Count)
  1322. {
  1323. imgCanvas.Source = null;
  1324. imgPPT.Source = null;
  1325. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1326. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1327. btnScreenshot.IsEnabled = false;
  1328. imgDocumentation.Visibility = Visibility.Visible;
  1329. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  1330. scroMain.ScrollToVerticalOffset(0);
  1331. }
  1332. else
  1333. {
  1334. imgDocumentation.Source = null;
  1335. imgCanvas.Source = null;
  1336. imgPPT.Source = null;
  1337. ///截图可用
  1338. ImgScreenshot.Visibility = Visibility.Visible;
  1339. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1340. btnScreenshot.IsEnabled = true;
  1341. }
  1342. }));
  1343. }
  1344. catch (Exception ex)
  1345. {
  1346. Dispatcher.Invoke(new Action(() =>
  1347. {
  1348. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1349. }));
  1350. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
  1351. }
  1352. }
  1353. }
  1354. }
  1355. //OpenDialog();
  1356. return "";
  1357. }
  1358. /// <summary>
  1359. /// 导入-结束
  1360. /// </summary>
  1361. /// <returns></returns>
  1362. public void InvokeServerCompate(object obj)
  1363. {
  1364. //APP.myloading.Hide();
  1365. APP.myloading.Hide();
  1366. }
  1367. /// <summary>
  1368. /// 导入文档
  1369. /// </summary>
  1370. private void OpenDialog()
  1371. {
  1372. Dispatcher.Invoke(new Action(() =>
  1373. {
  1374. result = ofd.ShowDialog();
  1375. if (result == System.Windows.Forms.DialogResult.OK)
  1376. {
  1377. if (ofd.FileName != "")
  1378. {
  1379. APP.myloading.Show();
  1380. myblackboard.changepage(APP.pageData.pagenum);
  1381. #region PPT转PDF
  1382. string filepath = ofd.FileName;
  1383. string path = ofd.SafeFileName.Replace(".ppt", "").Replace(".pptx", "").Trim();
  1384. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Replace(".pptx", "typezsygppt").Replace(".pdf", "typepdf").Trim();
  1385. if (type.Contains("typezsygppt"))//ppt
  1386. {
  1387. try
  1388. {
  1389. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1390. path = pathTemp + path + ".pdf";
  1391. FileToolsCommon.CreateDirectory(pathTemp);
  1392. //PPT转PDF
  1393. Presentation ppt = new Presentation(filepath);
  1394. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  1395. #endregion
  1396. #region PDF转图片
  1397. // 图片绝对路径集合
  1398. List<string> images = new List<string>();
  1399. string directoryPath = pathTemp;
  1400. //aspose许可证
  1401. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1402. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1403. //l.SetLicense(licenseName);
  1404. //定义Jpeg转换设备
  1405. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  1406. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1407. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1408. //directoryPath += quality;
  1409. Directory.CreateDirectory(directoryPath);
  1410. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1411. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1412. //遍历每一页转为jpg
  1413. for (int i = 1; i <= document.Pages.Count; i++)
  1414. {
  1415. long ii = Timestamp();
  1416. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1417. images.Add(filePathOutPut);
  1418. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1419. try
  1420. {
  1421. device.Process(document.Pages[i], fs);
  1422. fs.Close();
  1423. }
  1424. catch (Exception)
  1425. {
  1426. fs.Close();
  1427. File.Delete(filePathOutPut);
  1428. }
  1429. }
  1430. #endregion
  1431. string[] page = images.ToArray();
  1432. int num = 0;
  1433. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1434. {
  1435. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1436. {
  1437. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1438. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1439. APP.PageDrawList[i].PageNum = i + 1;
  1440. APP.PageDrawList[i].ImgDocumentation = true;
  1441. }
  1442. else
  1443. {
  1444. Model_DrawData model_DrawData = new Model_DrawData
  1445. {
  1446. PageImagePath = page[i - APP.pageData.pagenum],
  1447. PdfImagePath = page[i - APP.pageData.pagenum],
  1448. PageNum = i + 1,
  1449. ImgDocumentation = true
  1450. };
  1451. APP.PageDrawList.Add(model_DrawData);
  1452. }
  1453. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1454. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1455. btnPrint.IsEnabled = true;
  1456. APP.SaveDraw();
  1457. num++;
  1458. }
  1459. if (num > 0)
  1460. {
  1461. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1462. APP.pageData.pagenum += num;
  1463. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1464. }
  1465. if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
  1466. {
  1467. imgCanvas.Source = null;
  1468. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1469. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1470. btnScreenshot.IsEnabled = false;
  1471. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  1472. }
  1473. else
  1474. {
  1475. imgDocumentation.Source = null;
  1476. imgCanvas.Source = null;
  1477. ///截图可用
  1478. ImgScreenshot.Visibility = Visibility.Visible;
  1479. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1480. btnScreenshot.IsEnabled = true;
  1481. }
  1482. APP.myloading.Hide();
  1483. }
  1484. catch (Exception ex)
  1485. {
  1486. APP.myloading.Hide();
  1487. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1488. LogHelper.WriteErrLog("【打开ppt】(OpenDialog PPT)" + ex.Message, ex);
  1489. }
  1490. }
  1491. else if (type.Contains("typepdf"))
  1492. {
  1493. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1494. #region PDF转图片
  1495. // 图片绝对路径集合
  1496. List<string> images = new List<string>();
  1497. string directoryPath = pathTemp;
  1498. //aspose许可证
  1499. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1500. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1501. //l.SetLicense(licenseName);
  1502. //定义Jpeg转换设备
  1503. Aspose.Pdf.Document document = new Aspose.Pdf.Document(filepath);
  1504. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1505. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1506. //directoryPath += quality;
  1507. Directory.CreateDirectory(directoryPath);
  1508. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1509. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1510. //遍历每一页转为jpg
  1511. for (int i = 1; i <= document.Pages.Count; i++)
  1512. {
  1513. long ii = Timestamp();
  1514. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1515. images.Add(filePathOutPut);
  1516. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1517. try
  1518. {
  1519. device.Process(document.Pages[i], fs);
  1520. fs.Close();
  1521. }
  1522. catch (Exception)
  1523. {
  1524. fs.Close();
  1525. File.Delete(filePathOutPut);
  1526. }
  1527. }
  1528. #endregion
  1529. string[] page = images.ToArray();
  1530. int num = 0;
  1531. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1532. {
  1533. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1534. {
  1535. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1536. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1537. APP.PageDrawList[i].PageNum = i + 1;
  1538. APP.PageDrawList[i].ImgDocumentation = true;
  1539. }
  1540. else
  1541. {
  1542. Model_DrawData model_DrawData = new Model_DrawData
  1543. {
  1544. PageImagePath = page[i - APP.pageData.pagenum],
  1545. PdfImagePath = page[i - APP.pageData.pagenum],
  1546. PageNum = i + 1,
  1547. ImgDocumentation = true
  1548. };
  1549. APP.PageDrawList.Add(model_DrawData);
  1550. }
  1551. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1552. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1553. btnPrint.IsEnabled = true;
  1554. APP.SaveDraw();
  1555. num++;
  1556. }
  1557. if (num > 0)
  1558. {
  1559. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1560. APP.pageData.pagenum += num;
  1561. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1562. }
  1563. if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
  1564. {
  1565. imgCanvas.Source = null;
  1566. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1567. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1568. btnScreenshot.IsEnabled = false;
  1569. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  1570. }
  1571. else
  1572. {
  1573. imgDocumentation.Source = null;
  1574. imgCanvas.Source = null;
  1575. ///截图可用
  1576. ImgScreenshot.Visibility = Visibility.Visible;
  1577. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1578. btnScreenshot.IsEnabled = true;
  1579. }
  1580. APP.myloading.Hide();
  1581. }
  1582. else//word
  1583. {
  1584. try
  1585. {
  1586. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1587. string[] page = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
  1588. int num = 0;
  1589. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1590. {
  1591. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1592. {
  1593. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1594. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1595. APP.PageDrawList[i].PageNum = i + 1;
  1596. APP.PageDrawList[i].ImgDocumentation = true;
  1597. }
  1598. else
  1599. {
  1600. Model_DrawData model_DrawData = new Model_DrawData
  1601. {
  1602. PageImagePath = page[i - APP.pageData.pagenum],
  1603. PdfImagePath = page[i - APP.pageData.pagenum],
  1604. PageNum = i + 1,
  1605. ImgDocumentation = true
  1606. };
  1607. APP.PageDrawList.Add(model_DrawData);
  1608. }
  1609. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1610. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1611. btnPrint.IsEnabled = true;
  1612. APP.SaveDraw();
  1613. num++;
  1614. }
  1615. if (num > 0)
  1616. {
  1617. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1618. APP.pageData.pagenum += num;
  1619. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1620. }
  1621. if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
  1622. {
  1623. imgCanvas.Source = null;
  1624. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1625. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1626. btnScreenshot.IsEnabled = false;
  1627. imgDocumentation.Visibility = Visibility.Visible;
  1628. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  1629. }
  1630. else
  1631. {
  1632. imgDocumentation.Source = null;
  1633. imgCanvas.Source = null;
  1634. ///截图可用
  1635. ImgScreenshot.Visibility = Visibility.Visible;
  1636. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1637. btnScreenshot.IsEnabled = true;
  1638. }
  1639. APP.myloading.Hide();
  1640. }
  1641. catch (Exception ex)
  1642. {
  1643. APP.myloading.Hide();
  1644. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
  1645. }
  1646. }
  1647. }
  1648. }
  1649. }
  1650. ));
  1651. }
  1652. #endregion
  1653. #region 上传 列表
  1654. /// <summary>
  1655. /// 上传事件
  1656. /// </summary>
  1657. /// <param name="sender"></param>
  1658. /// <param name="e"></param>
  1659. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  1660. {
  1661. //if (gridUpload.Visibility == Visibility.Visible)
  1662. //{
  1663. // gridUpload.Visibility = Visibility.Collapsed;
  1664. // GridMain.Visibility = Visibility.Visible;
  1665. // //ImgRecord.Visibility = Visibility.Visible;//上传结束时可录制
  1666. // //ImgRecordTwo.Visibility = Visibility.Collapsed;//上传结束时可录制
  1667. // //BtnRecord.IsEnabled = true;//设置结束时可录制
  1668. // if (APP.pageData.pagenum > 0)
  1669. // {
  1670. // gridPage.Visibility = Visibility.Visible;
  1671. // }
  1672. // DataContext = APP.pageData;
  1673. //}
  1674. //else
  1675. //{
  1676. // gridPage.Visibility = Visibility.Collapsed;
  1677. // gridUpload.Visibility = Visibility.Visible;
  1678. // GridMain.Visibility = Visibility.Collapsed;
  1679. // //ImgRecord.Visibility = Visibility.Collapsed;//上传时不可录制
  1680. // //ImgRecordTwo.Visibility = Visibility.Visible;//上传时不可录制
  1681. // //BtnRecord.IsEnabled = false;//上传时不可录制
  1682. // InitializeUpload();
  1683. //}
  1684. if (GridMyVideo.Visibility == Visibility.Visible)
  1685. {
  1686. GridMyVideo.Visibility = Visibility.Collapsed;
  1687. GridMain.Visibility = Visibility.Visible;
  1688. if (APP.pageData.pagenum > 0)
  1689. {
  1690. gridPage.Visibility = Visibility.Visible;
  1691. }
  1692. DataContext = APP.pageData;
  1693. }
  1694. else
  1695. {
  1696. gridSetUp.Visibility = Visibility.Collapsed;
  1697. gridPage.Visibility = Visibility.Collapsed;
  1698. GridMyVideo.Visibility = Visibility.Visible;
  1699. GridMain.Visibility = Visibility.Collapsed;
  1700. LoadUploadInitData();
  1701. }
  1702. //btnStop.IsEnabled = true;//停止录制按钮可点击
  1703. }
  1704. /// <summary>
  1705. /// 初始化上传
  1706. /// </summary>
  1707. public void InitializeUpload()
  1708. {
  1709. APP.myloading.Show();
  1710. MouseNumber = 0;
  1711. IsModify = false;
  1712. //加载视频列表
  1713. LoadingVideoList();
  1714. int i = 1;
  1715. bool isColour = true;
  1716. pageData.menuList.Clear();
  1717. //显示视频
  1718. foreach (Model_Video videoinfo in model_VideoList)
  1719. {
  1720. //是否已上传
  1721. //videoinfo.IsUpload;
  1722. //录制时间
  1723. //videoinfo.RSTime;
  1724. //文件大小
  1725. //videoinfo.VideoSize;
  1726. //文件缩略图路径
  1727. //videoinfo.ThumbnailPath;
  1728. //文件唯一标示 上传事件筛选需要上传的视频
  1729. //videoinfo.FileGuid;
  1730. //文件存储路径
  1731. //videoinfo.VidePath;
  1732. string colour = "#FFFFFF";
  1733. if (isColour == true)
  1734. {
  1735. colour = "#FFFFFF";
  1736. isColour = false;
  1737. }
  1738. else
  1739. {
  1740. colour = "#E6F1FF";
  1741. isColour = true;
  1742. }
  1743. string vis = "Visible";
  1744. string cos = "Collapsed";
  1745. if (!videoinfo.IsUpload)
  1746. {
  1747. vis = "Collapsed";
  1748. cos = "Visible";
  1749. }
  1750. //if(i==1)//ceshi
  1751. //{
  1752. // vis = "Visible";
  1753. // cos = "Collapsed";
  1754. //}
  1755. if (i <= 16)
  1756. {
  1757. pageData.menuList.Add(new FileDirectoryModel()
  1758. {
  1759. SerialNumber = i,
  1760. VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  1761. Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  1762. FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
  1763. VideoDuration = 0,
  1764. VideoSize = videoinfo.VideoSize,
  1765. VideoTime = videoinfo.RSTime,
  1766. IsEnabled = false,
  1767. Path = videoinfo.VideoPath,
  1768. Colour = colour,
  1769. Visi = vis,
  1770. Coll = cos,
  1771. FileGuid = videoinfo.FileGuid,
  1772. VideoType = videoinfo.VideoType.ToString(),
  1773. VideoSizes = videoinfo.VideoSizebyte
  1774. }); ;
  1775. }
  1776. i++;
  1777. }
  1778. Currpage = 0;
  1779. PageNum = 0;
  1780. if (pageData.menuList.Count > 0)
  1781. {
  1782. Currpage = 1;
  1783. txbCurrpageTwo.Text = Currpage.ToString();
  1784. stpUp.Visibility = Visibility.Visible;
  1785. }
  1786. else
  1787. {
  1788. stpUp.Visibility = Visibility.Hidden;
  1789. }
  1790. PageNum = model_VideoList.Count;
  1791. if (PageNum > 0)
  1792. {
  1793. int t = 1;
  1794. while (PageNum > 16 * t)
  1795. {
  1796. t++;
  1797. }
  1798. PageNum = t;
  1799. }
  1800. else
  1801. {
  1802. PageNum = 0;
  1803. }
  1804. txbPageNumTwo.Text = PageNum.ToString();
  1805. APP.myloading.Hide();
  1806. DataContext = pageData;
  1807. }
  1808. /// <summary>
  1809. /// 当前页
  1810. /// </summary>
  1811. private int Currpage = 0;
  1812. /// <summary>
  1813. /// 总页码
  1814. /// </summary>
  1815. private int PageNum = 0;
  1816. /// <summary>
  1817. /// 加载视频列表
  1818. /// </summary>
  1819. public void LoadingVideoList()
  1820. {
  1821. try
  1822. {
  1823. model_VideoList = new List<Model_Video>();
  1824. foreach (Model_WKData Vdata in APP.WKDataList)
  1825. {
  1826. #region 计时器初始化
  1827. if (Vdata.VideoList == null)
  1828. {
  1829. continue;
  1830. }
  1831. foreach (Model_Video videoinfo in Vdata.VideoList)
  1832. {
  1833. try
  1834. {
  1835. if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
  1836. {
  1837. continue;
  1838. }
  1839. if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
  1840. {
  1841. videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMB(videoinfo.VideoPath).ToString() + " MB";
  1842. videoinfo.VideoSizebyte = FileToolsCommon.GetFileSize(videoinfo.VideoPath);
  1843. }
  1844. model_VideoList.Add(videoinfo);
  1845. }
  1846. catch (Exception ex)
  1847. {
  1848. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  1849. }
  1850. }
  1851. #endregion
  1852. }
  1853. //翻转
  1854. if (model_VideoList.Count > 1)
  1855. {
  1856. model_VideoList.Reverse();
  1857. }
  1858. }
  1859. catch (Exception ex)
  1860. {
  1861. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  1862. }
  1863. }
  1864. ////定义事件
  1865. //public event ChangeTextHandler ChangeTextEvents;
  1866. /// <summary>
  1867. /// 上传
  1868. /// </summary>
  1869. /// <param name="sender"></param>
  1870. /// <param name="e"></param>
  1871. private void BtnUploads_Click(object sender, RoutedEventArgs e)
  1872. {
  1873. if (APP.IsLoginType == false)
  1874. {
  1875. Login();
  1876. return;
  1877. }
  1878. pageData.menuList[Subscript].IsEnabled = false;
  1879. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnUpload");
  1880. for (int i = 0; i < buttons.Count; i++)
  1881. {
  1882. if (buttons[i] == sender)
  1883. {
  1884. DAL_Upload dAL_Upload = new DAL_Upload();
  1885. if (dAL_Upload.UploadVideo(pageData.menuList[i].FileGuid, out string ErrMessage))
  1886. {
  1887. //MessageWindow.Show("视频上传服务器成功!");
  1888. if (APP.W_UploadWindow == null)
  1889. {
  1890. APP.W_UploadWindow = new UploadWindow
  1891. {
  1892. Owner = this
  1893. };
  1894. APP.W_UploadWindow.ChangeTextEvents += new ChangeTextHandlers(frm_ChangeTextEvents);
  1895. }
  1896. //long size = Convert.ToInt64(FileToolsCommon.GetFileSizeByMB(pageData.menuList[i].FilePath));
  1897. APP.W_UploadWindow.Initialize(pageData.menuList[i].VideoName, pageData.menuList[i].VideoSizes, pageData.menuList[i].VideoType, pageData.menuList[i].FileGuid, i);
  1898. APP.W_UploadWindow.ShowDialog();
  1899. }
  1900. else
  1901. {
  1902. MessageWindow.Show(ErrMessage);
  1903. }
  1904. }
  1905. }
  1906. }
  1907. /// <summary>
  1908. /// 上传返回事件
  1909. /// </summary>
  1910. /// <param name="text"></param>
  1911. private void frm_ChangeTextEvents(string text, int i)
  1912. {
  1913. if ("上传成功".Equals(text))
  1914. {
  1915. pageData.menuList[i].Visi = "Visible";
  1916. pageData.menuList[i].Coll = "Collapsed";
  1917. DataContext = pageData;
  1918. }
  1919. }
  1920. /// <summary>
  1921. /// 删除
  1922. /// </summary>
  1923. /// <param name="sender"></param>
  1924. /// <param name="e"></param>
  1925. private void BtnDelete_Click(object sender, RoutedEventArgs e)
  1926. {
  1927. MessageBoxResult dr = MessageWindow.Show("确定删除该视频?", "提示", MessageBoxButton.OKCancel);
  1928. if (dr == MessageBoxResult.OK)
  1929. {
  1930. pageData.menuList[Subscript].IsEnabled = false;
  1931. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnDelete");
  1932. for (int i = 0; i < buttons.Count; i++)
  1933. {
  1934. if (buttons[i] == sender)
  1935. {
  1936. //if (APP.W_PromptWindow == null)
  1937. //{
  1938. // APP.W_PromptWindow = new PromptWindow();
  1939. // APP.W_PromptWindow.Owner = this;
  1940. //}
  1941. //APP.W_PromptWindow.Initialize(pageData.menuList[i].VideoName);
  1942. //APP.W_PromptWindow.ShowDialog();
  1943. foreach (Model_WKData wKData in APP.WKDataList)
  1944. {
  1945. if (wKData.VideoList == null)
  1946. {
  1947. continue;
  1948. }
  1949. if (wKData.VideoList.Exists(x => x.FileGuid == pageData.menuList[i].FileGuid))
  1950. {
  1951. try
  1952. {
  1953. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).VideoPath);
  1954. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).ThumbnailPath);
  1955. wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid));
  1956. InitializeUpload();
  1957. return;
  1958. }
  1959. catch (Exception ex)
  1960. {
  1961. MessageWindow.Show("无法删除视频!" + ex.Message);
  1962. return;
  1963. }
  1964. }
  1965. }
  1966. }
  1967. }
  1968. }
  1969. }
  1970. /// <summary>
  1971. /// 播放
  1972. /// </summary>
  1973. /// <param name="sender"></param>
  1974. /// <param name="e"></param>
  1975. private void BtnPlay_Click(object sender, RoutedEventArgs e)
  1976. {
  1977. pageData.menuList[Subscript].IsEnabled = false;
  1978. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnPlay");
  1979. for (int i = 0; i < buttons.Count; i++)
  1980. {
  1981. if (buttons[i] == sender)
  1982. {
  1983. try
  1984. {
  1985. ProcessStartInfo psi = new ProcessStartInfo(pageData.menuList[i].Path);
  1986. Process pro = new Process
  1987. {
  1988. StartInfo = psi
  1989. };
  1990. pro.Start();
  1991. }
  1992. catch (Exception ex)
  1993. {
  1994. LogHelper.WriteErrLog("FileDirectoryWindow【BtnPlay_Click】" + ex.Message, ex);
  1995. System.Windows.MessageBox.Show(ex.Message);
  1996. return;
  1997. }
  1998. }
  1999. }
  2000. }
  2001. /// <summary>
  2002. /// 搜索集合匹配的索引
  2003. /// </summary>
  2004. /// <typeparam name="T"></typeparam>
  2005. /// <param name="parent"></param>
  2006. /// <param name="childName"></param>
  2007. /// <returns></returns>
  2008. public static List<T> FindChilds<T>(DependencyObject parent, string childName)
  2009. where T : DependencyObject
  2010. {
  2011. List<T> list = new List<T>();
  2012. if (parent == null)
  2013. {
  2014. return list;
  2015. }
  2016. int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
  2017. for (int i = 0; i < childrenCount; i++)
  2018. {
  2019. DependencyObject child = VisualTreeHelper.GetChild(parent, i);
  2020. // 如果子控件不是需查找的控件类型
  2021. T childType = child as T;
  2022. if (childType == null)
  2023. {
  2024. // 在下一级控件中递归查找
  2025. List<T> findChildList = FindChilds<T>(child, childName);
  2026. for (int j = 0; j < findChildList.Count; j++)
  2027. {
  2028. }
  2029. list.AddRange(FindChilds<T>(child, childName));
  2030. }
  2031. else if (!string.IsNullOrEmpty(childName))
  2032. {
  2033. FrameworkElement frameworkElement = child as FrameworkElement;
  2034. // 如果控件名称符合参数条件
  2035. if (frameworkElement != null && frameworkElement.Name == childName)
  2036. {
  2037. list.Add((T)child);
  2038. }
  2039. }
  2040. else
  2041. {
  2042. // 查找到了控件
  2043. list.Add((T)child);
  2044. }
  2045. }
  2046. return list;
  2047. }
  2048. /// <summary>
  2049. /// 修改
  2050. /// </summary>
  2051. /// <param name="sender"></param>
  2052. /// <param name="e"></param>
  2053. private void BtnModify_Click(object sender, RoutedEventArgs e)
  2054. {
  2055. if (IsModify)
  2056. {
  2057. try
  2058. {
  2059. string newName = pageData.menuList[Subscript].VideoName + "." + pageData.menuList[Subscript].VideoType;
  2060. bool isName = ModifyPathName(pageData.menuList[Subscript].FileGuid, newName, out string Errmessage);
  2061. if (!isName)
  2062. {
  2063. MessageWindow.Show(Errmessage);
  2064. }
  2065. }
  2066. catch (Exception ex)
  2067. {
  2068. LogHelper.WriteErrLog("XHMicroLessonSystemWindow(BtnModify_Click)" + ex.Message, ex);
  2069. }
  2070. IsModify = false;
  2071. pageData.menuList[Subscript].IsEnabled = false;
  2072. listView1.DataContext = pageData;
  2073. }
  2074. else
  2075. {
  2076. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnModify");
  2077. for (int i = 0; i < buttons.Count; i++)
  2078. {
  2079. if (buttons[i] == sender)
  2080. {
  2081. pageData.menuList[i].IsEnabled = true;
  2082. Subscript = i;
  2083. IsModify = true;
  2084. }
  2085. }
  2086. }
  2087. }
  2088. private int MouseNumber = 0;
  2089. /// <summary>
  2090. /// 上传 上页
  2091. /// </summary>
  2092. /// <param name="sender"></param>
  2093. /// <param name="e"></param>
  2094. private void BtnLastPage_Click(object sender, RoutedEventArgs e)
  2095. {
  2096. if (Currpage > 1)
  2097. {
  2098. Currpage -= 1;
  2099. txbCurrpageTwo.Text = Currpage.ToString();
  2100. int i = 1;
  2101. bool isColour = true;
  2102. pageData.menuList.Clear();
  2103. //显示视频
  2104. foreach (Model_Video videoinfo in model_VideoList)
  2105. {
  2106. //是否已上传
  2107. //videoinfo.IsUpload;
  2108. //录制时间
  2109. //videoinfo.RSTime;
  2110. //文件大小
  2111. //videoinfo.VideoSize;
  2112. //文件缩略图路径
  2113. //videoinfo.ThumbnailPath;
  2114. //文件唯一标示 上传事件筛选需要上传的视频
  2115. //videoinfo.FileGuid;
  2116. //文件存储路径
  2117. //videoinfo.VidePath;
  2118. string colour = "#FFFFFF";
  2119. if (isColour == true)
  2120. {
  2121. colour = "#FFFFFF";
  2122. isColour = false;
  2123. }
  2124. else
  2125. {
  2126. colour = "#E6F1FF";
  2127. isColour = true;
  2128. }
  2129. string vis = "Visible";
  2130. string cos = "Collapsed";
  2131. if (!videoinfo.IsUpload)
  2132. {
  2133. vis = "Collapsed";
  2134. cos = "Visible";
  2135. }
  2136. if (i <= Currpage * 16 && i >= (Currpage - 1) * 16)
  2137. {
  2138. pageData.menuList.Add(new FileDirectoryModel()
  2139. {
  2140. SerialNumber = i,
  2141. VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2142. Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2143. FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
  2144. VideoDuration = 0,
  2145. VideoSize = videoinfo.VideoSize,
  2146. VideoTime = videoinfo.RSTime,
  2147. IsEnabled = false,
  2148. Path = videoinfo.VideoPath,
  2149. Colour = colour,
  2150. Visi = vis,
  2151. Coll = cos,
  2152. FileGuid = videoinfo.FileGuid,
  2153. VideoType = videoinfo.VideoType.ToString()
  2154. }); ;
  2155. }
  2156. i++;
  2157. }
  2158. APP.myloading.Hide();
  2159. }
  2160. }
  2161. /// <summary>
  2162. /// 上传 下页
  2163. /// </summary>
  2164. /// <param name="sender"></param>
  2165. /// <param name="e"></param>
  2166. private void BtnNextPage_Click(object sender, RoutedEventArgs e)
  2167. {
  2168. if (Currpage < PageNum)
  2169. {
  2170. Currpage += 1;
  2171. txbCurrpageTwo.Text = Currpage.ToString();
  2172. int i = 1;
  2173. bool isColour = true;
  2174. pageData.menuList.Clear();
  2175. //显示视频
  2176. foreach (Model_Video videoinfo in model_VideoList)
  2177. {
  2178. //是否已上传
  2179. //videoinfo.IsUpload;
  2180. //录制时间
  2181. //videoinfo.RSTime;
  2182. //文件大小
  2183. //videoinfo.VideoSize;
  2184. //文件缩略图路径
  2185. //videoinfo.ThumbnailPath;
  2186. //文件唯一标示 上传事件筛选需要上传的视频
  2187. //videoinfo.FileGuid;
  2188. //文件存储路径
  2189. //videoinfo.VidePath;
  2190. string colour = "#FFFFFF";
  2191. if (isColour == true)
  2192. {
  2193. colour = "#FFFFFF";
  2194. isColour = false;
  2195. }
  2196. else
  2197. {
  2198. colour = "#E6F1FF";
  2199. isColour = true;
  2200. }
  2201. string vis = "Visible";
  2202. string cos = "Collapsed";
  2203. if (!videoinfo.IsUpload)
  2204. {
  2205. vis = "Collapsed";
  2206. cos = "Visible";
  2207. }
  2208. if (i <= Currpage * 16 && i > (Currpage - 1) * 16)
  2209. {
  2210. pageData.menuList.Add(new FileDirectoryModel()
  2211. {
  2212. SerialNumber = i,
  2213. VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2214. Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2215. FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
  2216. VideoDuration = 0,
  2217. VideoSize = videoinfo.VideoSize,
  2218. VideoTime = videoinfo.RSTime,
  2219. IsEnabled = false,
  2220. Path = videoinfo.VideoPath,
  2221. Colour = colour,
  2222. Visi = vis,
  2223. Coll = cos,
  2224. FileGuid = videoinfo.FileGuid,
  2225. VideoType = videoinfo.VideoType.ToString()
  2226. }); ;
  2227. }
  2228. i++;
  2229. }
  2230. APP.myloading.Hide();
  2231. }
  2232. }
  2233. /// <summary>
  2234. /// 修改文件名
  2235. /// </summary>
  2236. /// <param name="Guid">唯一编号</param>
  2237. /// <param name="NewName">新文件名带后缀 不带路径</param>
  2238. /// <param name="Errmessage">错误信息</param>
  2239. /// <returns></returns>
  2240. private bool ModifyPathName(string FileGuid, string NewName, out string Errmessage)
  2241. {
  2242. Errmessage = "";
  2243. foreach (Model_WKData WKData in APP.WKDataList)
  2244. {
  2245. if (WKData.VideoList.Exists(x => x.FileGuid == FileGuid))
  2246. {
  2247. Model_Video model_Video = WKData.VideoList.Find(x => x.FileGuid == FileGuid);
  2248. string filePathName = model_Video.VideoPath;
  2249. string filePath = FileToolsCommon.GetDirectoryName(filePathName);
  2250. string newFilePathName = filePath + NewName;
  2251. //缩略图
  2252. string ThumbnailPath = filePath + "ThumbnailPath/";
  2253. FileToolsCommon.CreateDirectory(ThumbnailPath);
  2254. //缩略图存储位置
  2255. string ThumbnailPathName = ThumbnailPath + NewName.Replace(".", "") + ".JPG";
  2256. if (FileToolsCommon.IsExistFile(newFilePathName))
  2257. {
  2258. Errmessage = "文件已存在,请重新修改文件名!";
  2259. return false;
  2260. }
  2261. else
  2262. {
  2263. //修改文件名
  2264. FileToolsCommon.Copy(filePathName, newFilePathName);
  2265. model_Video.VideoPath = newFilePathName;
  2266. //修改缩略图名
  2267. FileToolsCommon.DeleteFile(ThumbnailPathName);
  2268. FileToolsCommon.Copy(model_Video.ThumbnailPath, ThumbnailPathName);
  2269. model_Video.ThumbnailPath = ThumbnailPathName;
  2270. APP.SaveWkData();
  2271. return true;
  2272. }
  2273. }
  2274. else
  2275. {
  2276. continue;
  2277. }
  2278. }
  2279. Errmessage = "视频文件有改动,当前文件不存在,请关闭后重新打开“我的”";
  2280. return false;
  2281. }
  2282. #endregion
  2283. #region 新上传 显示缩略图
  2284. #region 初始值
  2285. /// <summary>
  2286. /// 总页数
  2287. /// </summary>
  2288. private int TotalPage = 0;
  2289. /// <summary>
  2290. /// 当前页
  2291. /// </summary>
  2292. private int CurrentPage = 1;
  2293. /// <summary>
  2294. /// 每页显示的视频数
  2295. /// </summary>
  2296. private int PageShowNum = 0;
  2297. /// <summary>
  2298. /// 视频信息列表
  2299. /// </summary>
  2300. private List<Uc_VideoItem> VideoControlList = new List<Uc_VideoItem>();
  2301. /// <summary>
  2302. /// 横向间隔
  2303. /// </summary>
  2304. private double IntervalX = 0;
  2305. /// <summary>
  2306. /// 纵向间隔
  2307. /// </summary>
  2308. private double IntervalY = 0;
  2309. #endregion
  2310. /// <summary>
  2311. /// 初始化加载上传页面数据
  2312. /// </summary>
  2313. private void LoadUploadInitData()
  2314. {
  2315. APP.myloading.Show();
  2316. //加载视频列表
  2317. LoadingVideoList();
  2318. if (model_VideoList.Count > 0)
  2319. {
  2320. lblVideoMess.Visibility = Visibility.Hidden;
  2321. BtnVideoUpPage.Visibility = Visibility.Visible;
  2322. lblVideoPageNum.Visibility = Visibility.Visible;
  2323. BtnVideoDownPage.Visibility = Visibility.Visible;
  2324. //根据页面大小获取每页显示的数量 H300W250
  2325. int videoRow = (int)((GridMyVideo.ActualHeight - 50) / 300);
  2326. int videColumn = (int)(GridMyVideo.ActualWidth / 250);
  2327. PageShowNum = (videoRow == 0 ? 1 : videoRow) * (videColumn == 0 ? 1 : videColumn);
  2328. //获取总页数
  2329. TotalPage = model_VideoList.Count / PageShowNum + (model_VideoList.Count % PageShowNum > 0 ? 1 : 0);
  2330. //如果当前页大于总页数 总页数为当前页
  2331. if (TotalPage < CurrentPage)
  2332. {
  2333. CurrentPage = TotalPage;
  2334. }
  2335. //横向间隔
  2336. IntervalX = (GridMyVideo.ActualWidth - (videColumn * 250)) / (videColumn + 1);
  2337. IntervalY = (GridMyVideo.ActualHeight - 50 - (videoRow * 300)) / (videoRow + 1);
  2338. LoadCurrentPageData();
  2339. }
  2340. else
  2341. {
  2342. lblVideoMess.Visibility = Visibility.Visible;
  2343. BtnVideoUpPage.Visibility = Visibility.Hidden;
  2344. lblVideoPageNum.Visibility = Visibility.Hidden;
  2345. BtnVideoDownPage.Visibility = Visibility.Hidden;
  2346. //隐藏显示的控件
  2347. if (VideoControlList.Count > 0)
  2348. {
  2349. foreach (Uc_VideoItem item in VideoControlList)
  2350. {
  2351. if (item.Visibility != Visibility.Hidden)
  2352. {
  2353. item.Visibility = Visibility.Hidden;
  2354. }
  2355. }
  2356. }
  2357. }
  2358. APP.myloading.Hide();
  2359. }
  2360. /// <summary>
  2361. /// 加载当前页数据
  2362. /// </summary>
  2363. private void LoadCurrentPageData()
  2364. {
  2365. lblVideoPageNum.Content = CurrentPage + "/" + TotalPage;
  2366. //隐藏显示的控件
  2367. if (VideoControlList.Count > 0)
  2368. {
  2369. foreach (Uc_VideoItem item in VideoControlList)
  2370. {
  2371. if (item.Visibility != Visibility.Hidden)
  2372. {
  2373. item.Visibility = Visibility.Hidden;
  2374. }
  2375. }
  2376. }
  2377. double W = IntervalX;//每次增加250
  2378. double H = IntervalY;//每次增加300
  2379. //加载控件
  2380. for (int i = 0; i < PageShowNum; i++)
  2381. {
  2382. int DataIndex = (CurrentPage - 1) * PageShowNum + i;
  2383. if (DataIndex == model_VideoList.Count)
  2384. {
  2385. return;
  2386. }
  2387. Uc_VideoItem videoItem;
  2388. if (VideoControlList.Exists(x => x.Tag.ToString() == model_VideoList[DataIndex].FileGuid))
  2389. {
  2390. videoItem = VideoControlList.Find(x => x.Tag.ToString() == model_VideoList[DataIndex].FileGuid);
  2391. }
  2392. else
  2393. {
  2394. if (!FileToolsCommon.IsExistFile(model_VideoList[DataIndex].ThumbnailPath))
  2395. {
  2396. continue;
  2397. }
  2398. videoItem = new Uc_VideoItem(model_VideoList[DataIndex])
  2399. {
  2400. Tag = model_VideoList[DataIndex].FileGuid
  2401. };
  2402. videoItem.Click_refreshVideoList += LoadUploadInitData;
  2403. videoItem.Click_UploadLogin += Login;
  2404. videoItem.Width = 250;
  2405. videoItem.Height = 300;
  2406. videoItem.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
  2407. videoItem.VerticalAlignment = System.Windows.VerticalAlignment.Top;
  2408. GridMyVideo.Children.Add(videoItem);
  2409. VideoControlList.Add(videoItem);
  2410. }
  2411. videoItem.Margin = new Thickness(W, H, 0, 0);
  2412. videoItem.Visibility = Visibility.Visible;
  2413. if (W + 250 + 250 > GridMyVideo.ActualWidth)
  2414. {
  2415. W = IntervalX;
  2416. H += 300 + IntervalY;
  2417. }
  2418. else
  2419. {
  2420. W += 250 + IntervalX;
  2421. }
  2422. //Uc_VideoItem videoItem = new Uc_VideoItem();
  2423. //return;
  2424. }
  2425. }
  2426. #region 分页
  2427. /// <summary>
  2428. /// 上一页
  2429. /// </summary>
  2430. /// <param name="sender"></param>
  2431. /// <param name="e"></param>
  2432. private void BtnVideoUpPage_Click(object sender, RoutedEventArgs e)
  2433. {
  2434. if (CurrentPage > 1)
  2435. {
  2436. CurrentPage--;
  2437. LoadCurrentPageData();
  2438. }
  2439. }
  2440. /// <summary>
  2441. /// 下一页
  2442. /// </summary>
  2443. /// <param name="sender"></param>
  2444. /// <param name="e"></param>
  2445. private void BtnVideoDownPage_Click(object sender, RoutedEventArgs e)
  2446. {
  2447. if (CurrentPage < TotalPage)
  2448. {
  2449. CurrentPage++;
  2450. LoadCurrentPageData();
  2451. }
  2452. }
  2453. #endregion
  2454. #endregion
  2455. #region 录制窗口
  2456. #region 变量
  2457. /// <summary>
  2458. /// 视频保存路径
  2459. /// </summary>
  2460. //string RecordingPath;
  2461. /// <summary>
  2462. /// 图片保存路径
  2463. /// </summary>
  2464. private string ImgPath;
  2465. /// <summary>
  2466. /// 音频保存路径名
  2467. /// </summary>
  2468. private string AudioPathName;
  2469. /// <summary>
  2470. /// 视频保存路径名
  2471. /// </summary>
  2472. private string VideoSavePathName;
  2473. /// <summary>
  2474. /// 视频合成路径名
  2475. /// </summary>
  2476. private string VideoSynthesisPathName;
  2477. /// <summary>
  2478. /// 暂停录制
  2479. /// </summary>
  2480. private bool IsSuspendR = true;
  2481. /// <summary>
  2482. /// 录制是否已停止
  2483. /// </summary>
  2484. private bool IsFirstR = true;
  2485. /// <summary>
  2486. /// 图片
  2487. /// </summary>
  2488. private List<string> RsImgName = null;
  2489. /// <summary>
  2490. /// 是否开始截图计数
  2491. /// </summary>
  2492. private bool IsStartCount = false;
  2493. /// <summary>
  2494. /// 是否录制了音频
  2495. /// </summary>
  2496. private bool IsRecordAudio = false;
  2497. /// <summary>
  2498. /// 截图定时器
  2499. /// </summary>
  2500. private System.Threading.Timer timer;
  2501. /// <summary>
  2502. /// 录制计时
  2503. /// </summary>
  2504. private DateTime SRTime = DateTime.Now;
  2505. /// <summary>
  2506. /// 录制大小
  2507. /// </summary>
  2508. private int gridActWidth = 1276;
  2509. /// <summary>
  2510. /// 录制大小
  2511. /// </summary>
  2512. private int gridActHeight = 898;
  2513. #endregion
  2514. #region 录屏
  2515. /// <summary>
  2516. /// 录屏事件
  2517. /// </summary>
  2518. /// <param name="sender"></param>
  2519. /// <param name="e"></param>
  2520. private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
  2521. {
  2522. Record();
  2523. if (!APP.CheckScreenCapturerRecorder())
  2524. {
  2525. MessageWindow.Show("使用此功能需安装环境,请在确定后依次点击“OK-Next>-Next>Install”完成安装!");
  2526. APP.InstallScreenCapturerRecorder();
  2527. return;
  2528. }
  2529. #region 限制只允许录制一个录屏 废弃
  2530. //string RecordScreenPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  2531. //if (FileToolsCommon.IsExistFile(RecordScreenPathName))
  2532. //{
  2533. // MessageBoxResult dr = MessageWindow.Show("已存在录屏,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  2534. // if (dr == MessageBoxResult.OK)
  2535. // {
  2536. // try
  2537. // {
  2538. // FileToolsCommon.DeleteFile(RecordScreenPathName);
  2539. // APP.VideoList.RemoveAll(x => x.VideoPath == RecordScreenPathName);
  2540. // }
  2541. // catch (Exception ex)
  2542. // {
  2543. // LogHelper.WriteErrLog("【录屏】(BtnRecordingScreen_Click)无法移除视频," + ex.Message, ex);
  2544. // }
  2545. // }
  2546. // else
  2547. // {
  2548. // return;
  2549. // }
  2550. //}
  2551. #endregion
  2552. k_hook.Stop();
  2553. if (APP.W_ScreenRecordingToolbarWindow == null)
  2554. {
  2555. APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow
  2556. {
  2557. Topmost = true
  2558. };
  2559. APP.W_ScreenRecordingToolbarWindow.Initialize();
  2560. }
  2561. else
  2562. {
  2563. APP.W_ScreenRecordingToolbarWindow.Initialize();
  2564. }
  2565. APP.W_ScreenRecordingToolbarWindow.Click_stopRecordingScreen += W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen;
  2566. //显示在右下角
  2567. APP.W_ScreenRecordingToolbarWindow.WindowStartupLocation = WindowStartupLocation.Manual;
  2568. Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
  2569. float DIP = graphics.DpiX;
  2570. float DIPY = graphics.DpiY;
  2571. APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.WorkingArea.Width / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Width - 60;
  2572. APP.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.WorkingArea.Height / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Height - 30;
  2573. APP.W_ScreenRecordingToolbarWindow.Topmost = true;
  2574. APP.W_ScreenRecordingToolbarWindow.Show();
  2575. Hide();
  2576. }
  2577. /// <summary>
  2578. /// 保存录屏中
  2579. /// </summary>
  2580. private void W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen()
  2581. {
  2582. txbTime.Text = "";
  2583. txbTime.Visibility = Visibility.Hidden;
  2584. txbType.Visibility = Visibility.Visible;
  2585. txbType.Text = "保存中";
  2586. btnScreenRecording.IsEnabled = false;
  2587. new Thread(new ThreadStart(new Action(() =>
  2588. {
  2589. while (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath + "temprs/"))
  2590. {
  2591. Thread.Sleep(100);
  2592. }
  2593. Thread.Sleep(100);
  2594. Dispatcher.Invoke(() =>
  2595. {
  2596. btnScreenRecording.IsEnabled = true;
  2597. txbType.Visibility = Visibility.Hidden;
  2598. //TxbRecordScreenWord.Text = "录屏";
  2599. });
  2600. }))).Start();
  2601. }
  2602. #endregion
  2603. private bool IsPressButton = false;
  2604. /// <summary>
  2605. /// 录制窗口内容
  2606. /// </summary>
  2607. /// <param name="sender"></param>
  2608. /// <param name="e"></param>
  2609. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  2610. {
  2611. #region 防止连击
  2612. if (IsPressButton)
  2613. {
  2614. return;
  2615. }
  2616. else
  2617. {
  2618. IsPressButton = true;
  2619. new Thread(new ThreadStart(new Action(() =>
  2620. {
  2621. Thread.Sleep(500);
  2622. IsPressButton = false;
  2623. }))).Start();
  2624. }
  2625. #endregion
  2626. Record();
  2627. if (!APP.CheckScreenCapturerRecorder())
  2628. {
  2629. MessageWindow.Show("使用此功能需安装环境,请在确定后依次点击“OK-Next>-Next>Install”完成安装!");
  2630. APP.InstallScreenCapturerRecorder();
  2631. return;
  2632. }
  2633. if (APP.pageData.currpage > 0)
  2634. {
  2635. blackboard_canvas.Visibility = Visibility.Visible;
  2636. }
  2637. else
  2638. {
  2639. MessageWindow.Show("请先导入文档或截图!");
  2640. return;
  2641. }
  2642. if (RectImgBorder.Visibility != Visibility.Hidden)
  2643. {
  2644. HideAngleBorder();
  2645. }
  2646. //btnStop.IsEnabled = true;//停止录制按钮可点击
  2647. StartRecord();
  2648. }
  2649. /// <summary>
  2650. /// 停止录制窗口内容
  2651. /// </summary>
  2652. /// <param name="sender"></param>
  2653. /// <param name="e"></param>
  2654. private void BtnStop_Click(object sender, RoutedEventArgs e)
  2655. {
  2656. #region 防止连击
  2657. if (IsPressButton)
  2658. {
  2659. return;
  2660. }
  2661. else
  2662. {
  2663. IsPressButton = true;
  2664. new Thread(new ThreadStart(new Action(() =>
  2665. {
  2666. Thread.Sleep(500);
  2667. IsPressButton = false;
  2668. }))).Start();
  2669. }
  2670. #endregion
  2671. blackboard_canvas.Visibility = Visibility.Collapsed;
  2672. EndRecord();
  2673. }
  2674. /// <summary>
  2675. /// 设置录屏文件地址
  2676. /// </summary>
  2677. private void SetUpVideoPathName()
  2678. {
  2679. }
  2680. /// <summary>
  2681. /// 开始录制和暂停录制
  2682. /// </summary>
  2683. private void StartRecord()
  2684. {
  2685. if (IsSuspendR)
  2686. {
  2687. if (IsFirstR)//是否第一次录制 初始化录制
  2688. {
  2689. #region 检测麦克风扬声器是否可用
  2690. string audioSpeakerPath = FileToolsCommon.GetFileAbsolutePath("adoS.m");
  2691. string audioMicrophonePath = FileToolsCommon.GetFileAbsolutePath("adoM.m");
  2692. try
  2693. {
  2694. FileToolsCommon.DeleteFile(audioSpeakerPath);
  2695. FileToolsCommon.DeleteFile(audioMicrophonePath);
  2696. }
  2697. catch (Exception)
  2698. {
  2699. }
  2700. //扬声器
  2701. if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
  2702. {
  2703. APP.FFmpeg.StopRecordAudio(2);
  2704. //Thread.Sleep(500);
  2705. //麦克风
  2706. if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
  2707. {
  2708. }
  2709. else
  2710. {
  2711. //无法录制麦克风
  2712. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制麦克风,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  2713. if (Res == MessageBoxResult.Cancel)
  2714. {
  2715. return;
  2716. }
  2717. }
  2718. APP.FFmpeg.StopRecordAudio(1);
  2719. }
  2720. else
  2721. {
  2722. //无法录制扬声器音频
  2723. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制音频,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  2724. if (Res == MessageBoxResult.Cancel)
  2725. {
  2726. return;
  2727. }
  2728. }
  2729. #endregion
  2730. txbTime.Visibility = Visibility.Visible;
  2731. VideoInfo = new Model_Video
  2732. {
  2733. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  2734. WkType = Enum_WKVidetype.RecordingLessons
  2735. };
  2736. ImgPath = APP.WKData.WkPath + "temp/Image/";
  2737. AudioPathName = APP.WKData.WkPath + "temp/audio/";
  2738. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  2739. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  2740. FileToolsCommon.CreateDirectory(ImgPath);
  2741. FileToolsCommon.CreateDirectory(AudioPathName);
  2742. AudioPathName += APP.WKData.WkName + ".MP3";
  2743. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  2744. VideoSynthesisPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn." + VideoInfo.VideoType.ToString();
  2745. int num = 1;
  2746. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  2747. {
  2748. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制_" + num + "." + VideoInfo.VideoType.ToString();
  2749. VideoSynthesisPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn_" + num + "." + VideoInfo.VideoType.ToString();
  2750. num++;
  2751. }
  2752. #region 设置录屏唯一 废弃
  2753. //if (FileToolsCommon.IsExistFile(VideoSavePathName))
  2754. //{
  2755. // MessageBoxResult dr = MessageWindow.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  2756. // if (dr == MessageBoxResult.OK)
  2757. // {
  2758. // try
  2759. // {
  2760. // FileToolsCommon.DeleteFile(VideoSavePathName);
  2761. // APP.VideoList.RemoveAll(x => x.VideoPath == VideoSavePathName);
  2762. // }
  2763. // catch (Exception ex)
  2764. // {
  2765. // LogHelper.WriteErrLog("【录制】(StartRecord)无法移除视频," + ex.Message, ex);
  2766. // }
  2767. // }
  2768. // else
  2769. // {
  2770. // return;
  2771. // }
  2772. //}
  2773. #endregion
  2774. #region 禁用按钮
  2775. ImgPrint.Visibility = Visibility.Collapsed;//录制中不可打印
  2776. ImgPrintTwo.Visibility = Visibility.Visible;
  2777. btnPrint.IsEnabled = false;
  2778. ImgScreenshot.Visibility = Visibility.Collapsed;//录制中不可截图
  2779. ImgScreenshotTwo.Visibility = Visibility.Visible;
  2780. btnScreenshot.IsEnabled = false;
  2781. ImgImport.Visibility = Visibility.Collapsed;//录制中不可导入文档
  2782. ImgImportTwo.Visibility = Visibility.Visible;
  2783. btnImport.IsEnabled = false;
  2784. ImgScreenRecording.Visibility = Visibility.Collapsed;//录制中不可录屏
  2785. ImgScreenRecordingTwo.Visibility = Visibility.Visible;
  2786. btnScreenRecording.IsEnabled = false;
  2787. ImgUpload.Visibility = Visibility.Collapsed;//录制中不可上传
  2788. ImgUploadTwo.Visibility = Visibility.Visible;
  2789. btnUpload.IsEnabled = false;
  2790. ImgSetUp.Visibility = Visibility.Collapsed;//录制中不可设置
  2791. ImgSetUpTwo.Visibility = Visibility.Visible;
  2792. btnSetUp.IsEnabled = false;
  2793. btnLoginType.IsEnabled = false;
  2794. blackboard_canvas.Visibility = Visibility.Visible;//zxyceshi
  2795. //myblackboard = new BlackboardNew(blackboard_canvas);
  2796. //DataContext = APP.pageData;
  2797. //drawingAttributes = new DrawingAttributes();
  2798. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  2799. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  2800. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  2801. //blackboard_canvas.UseCustomCursor = true;
  2802. //drawingAttributes.FitToCurve = true;
  2803. //drawingAttributes.IgnorePressure = false;
  2804. //drawingAttributes.Width = PenSize;
  2805. //drawingAttributes.Height = PenSize;
  2806. //drawingAttributes.Color = Color;
  2807. //blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  2808. #endregion
  2809. #region 设置录制大小
  2810. //gridActWidth = (int)GridMain.ActualWidth==0?1276: (int)GridMain.ActualWidth;
  2811. //gridActHeight = (int)GridMain.ActualHeight==0?898: (int)GridMain.ActualHeight;
  2812. gridActWidth = (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f));
  2813. gridActHeight = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f));
  2814. gridActWidth = gridActWidth % 2 > 0 ? gridActWidth - 1 : gridActWidth;
  2815. gridActHeight = gridActHeight % 2 > 0 ? gridActHeight - 1 : gridActHeight;
  2816. #endregion
  2817. #region 录像倒计时
  2818. if (APP.W_CountdownWindow == null)
  2819. {
  2820. APP.W_CountdownWindow = new CountdownWindow();
  2821. APP.W_CountdownWindow.Initialize();
  2822. //APP.W_CountdownWindow.Topmost = true;
  2823. }
  2824. else
  2825. {
  2826. APP.W_CountdownWindow.Initialize();
  2827. //APP.W_CountdownWindow.Topmost = true;
  2828. }
  2829. APP.W_CountdownWindow.Show();
  2830. #endregion
  2831. IsFirstR = false;
  2832. RsImgName = new List<string>();
  2833. SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
  2834. txbTime.Visibility = Visibility.Visible;
  2835. ///启动截图
  2836. timer = new System.Threading.Timer(new TimerCallback(Timer_Elapsed), null, 0, 20);
  2837. //{
  2838. // AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
  2839. //};//设置执行一次(false)还是一直执行(true)
  2840. //timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
  2841. //timer.Enabled = true; //启动计时器
  2842. }
  2843. //继续录制
  2844. IsSuspendR = false;
  2845. //BtnRecording.Content = "暂停录制";
  2846. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
  2847. TxbRecordingWord.Text = "暂停";
  2848. #region 4秒内不可点击
  2849. //new Thread(new ThreadStart(new Action(() =>
  2850. //{
  2851. // Dispatcher.Invoke(() =>
  2852. // {
  2853. // BtnRecord.IsEnabled = false;
  2854. // btnStop.IsEnabled = false;
  2855. // ImgStop.Visibility = Visibility.Visible;
  2856. // ImgStopTwo.Visibility = Visibility.Collapsed;
  2857. // });
  2858. //}))).Start();
  2859. new Thread(new ThreadStart(new Action(() =>
  2860. {
  2861. //Thread.Sleep(4000);
  2862. Dispatcher.Invoke(() =>
  2863. {
  2864. BtnRecord.IsEnabled = true;
  2865. btnStop.IsEnabled = true;
  2866. ImgStop.Visibility = Visibility.Collapsed;
  2867. ImgStopTwo.Visibility = Visibility.Visible;
  2868. });
  2869. }))).Start();
  2870. #endregion
  2871. try
  2872. {
  2873. new Thread(new ThreadStart(new Action(() =>
  2874. {
  2875. Thread.Sleep(1000);
  2876. IsRecordAudio = APP.FFmpeg.StartRecordingAudio(AudioPathName, out string ErrMessage);
  2877. Thread.Sleep(1000);
  2878. Dispatcher.Invoke(() =>
  2879. {
  2880. if (!IsRecordAudio)
  2881. {
  2882. MessageWindow.Show(ErrMessage);
  2883. }
  2884. Recorddt = DateTime.Now;
  2885. IsStartCount = true;
  2886. //Stack();
  2887. //timer.Start();
  2888. });
  2889. }))).Start();
  2890. }
  2891. catch (Exception ex)
  2892. {
  2893. MessageWindow.Show(ex.Message);
  2894. }
  2895. }
  2896. else
  2897. {
  2898. //暂停
  2899. IsSuspendR = true;
  2900. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  2901. ImgStop.Visibility = Visibility.Collapsed;
  2902. ImgStopTwo.Visibility = Visibility.Visible;
  2903. TxbRecordingWord.Text = "继续";
  2904. //TimeOut();
  2905. #region 2秒内不可点击
  2906. new Thread(new ThreadStart(new Action(() =>
  2907. {
  2908. Dispatcher.Invoke(() =>
  2909. {
  2910. BtnRecord.IsEnabled = false;
  2911. btnStop.IsEnabled = false;
  2912. });
  2913. Thread.Sleep(2000);
  2914. Dispatcher.Invoke(() =>
  2915. {
  2916. BtnRecord.IsEnabled = true;
  2917. btnStop.IsEnabled = true;
  2918. });
  2919. }))).Start();
  2920. #endregion
  2921. try
  2922. {
  2923. APP.FFmpeg.SuspendFFmpeg();
  2924. new Thread(new ThreadStart(new Action(() =>
  2925. {
  2926. while (APP.FFmpeg.myProcess != null)
  2927. {
  2928. Thread.Sleep(100);
  2929. }
  2930. IsStartCount = false;
  2931. }))).Start();
  2932. }
  2933. catch (Exception ex)
  2934. {
  2935. MessageWindow.Show(ex.Message);
  2936. }
  2937. }
  2938. }
  2939. /// <summary>
  2940. /// 记录上次截图时间
  2941. /// </summary>
  2942. private DateTime Recorddt = DateTime.Now;
  2943. /// <summary>
  2944. /// 录制保存图片计时器
  2945. /// </summary>
  2946. /// <param name="sender"></param>
  2947. private void Timer_Elapsed(object sender)
  2948. {
  2949. if (IsStartCount)
  2950. {
  2951. DateTime dt = DateTime.Now;
  2952. TimeSpan ts = dt.Subtract(Recorddt);//时间差
  2953. double tsmi = ts.TotalMilliseconds;
  2954. if (tsmi > 200.0)
  2955. {
  2956. Recorddt = Recorddt.AddMilliseconds(200);
  2957. Thread thread = new Thread(RecordSaveImage);
  2958. //开启线程
  2959. thread.Start();
  2960. }
  2961. }
  2962. }
  2963. /// <summary>
  2964. /// 录制保存图片
  2965. /// </summary>
  2966. private void RecordSaveImage()
  2967. {
  2968. try
  2969. {
  2970. if (IsStartCount)
  2971. {
  2972. string FilePathName = ImgPath + RsImgName.Count + ".png";
  2973. RsImgName.Add(FilePathName);
  2974. #region 设置大小
  2975. double RsW = (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f));
  2976. double RsH = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f));
  2977. if (RsW > 1266)
  2978. {
  2979. double Proportion = RsH / RsW;
  2980. RsW = 1266;
  2981. RsH = RsW * Proportion;
  2982. RsH = ((int)RsH) % 2 > 0 ? (int)RsH - 1 : (int)RsH;
  2983. //RsH = 898;
  2984. }
  2985. #endregion
  2986. //System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Send, new ThreadStart(delegate
  2987. //{
  2988. //}));
  2989. Dispatcher.Invoke(() =>
  2990. {
  2991. //保存图片
  2992. ImageHelper.SaveUIToImage(GridMain, FilePathName, gridActWidth, gridActHeight, (int)RsW, (int)RsH);
  2993. //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f)), 0, 0);
  2994. //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)), (int)RsW, (int)RsH);
  2995. //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)), 1281, 1026);
  2996. SRTime = SRTime.AddMilliseconds(200);
  2997. if (txbTime.Visibility == Visibility.Hidden)
  2998. {
  2999. txbTime.Visibility = Visibility.Visible;
  3000. }
  3001. if (SRTime.Hour > 0)
  3002. {
  3003. //Dispatcher.Invoke(() =>
  3004. //{
  3005. txbTime.Text = SRTime.ToString("HH:mm:ss");
  3006. //});
  3007. }
  3008. else
  3009. {
  3010. //Dispatcher.Invoke(() =>
  3011. //{
  3012. txbTime.Text = SRTime.ToString("mm:ss");
  3013. //});
  3014. }
  3015. });
  3016. }
  3017. }
  3018. catch (Exception ex)
  3019. {
  3020. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  3021. }
  3022. }
  3023. /// <summary>
  3024. /// 停止录制并生成录制文件
  3025. /// </summary>
  3026. private void EndRecord()
  3027. {
  3028. if (!IsFirstR)
  3029. {
  3030. #region 恢复被禁用的按钮
  3031. ImgPrint.Visibility = Visibility.Visible;
  3032. ImgPrintTwo.Visibility = Visibility.Collapsed;
  3033. btnPrint.IsEnabled = true;
  3034. ImgScreenshot.Visibility = Visibility.Visible;
  3035. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  3036. btnScreenshot.IsEnabled = true;
  3037. ImgImport.Visibility = Visibility.Visible;
  3038. ImgImportTwo.Visibility = Visibility.Collapsed;
  3039. btnImport.IsEnabled = true;
  3040. ImgScreenRecording.Visibility = Visibility.Visible;
  3041. ImgScreenRecordingTwo.Visibility = Visibility.Collapsed;
  3042. btnScreenRecording.IsEnabled = true;
  3043. ImgUpload.Visibility = Visibility.Visible;
  3044. ImgUploadTwo.Visibility = Visibility.Collapsed;
  3045. btnUpload.IsEnabled = true;
  3046. ImgSetUp.Visibility = Visibility.Visible;
  3047. ImgSetUpTwo.Visibility = Visibility.Collapsed;
  3048. btnSetUp.IsEnabled = true;
  3049. btnLoginType.IsEnabled = true;
  3050. //btnStop.IsEnabled = false;//停止录制按钮不可点击
  3051. #endregion
  3052. IsSuspendR = true;
  3053. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  3054. ImgStop.Visibility = Visibility.Visible;
  3055. ImgStopTwo.Visibility = Visibility.Collapsed;
  3056. //TimeOut();
  3057. try
  3058. {
  3059. #region 清空画板数据
  3060. APP.pageData.currpage = 0;
  3061. APP.pageData.pagenum = 0;
  3062. myblackboard.clear();
  3063. //myblackboard = new BlackboardNew(blackboard_canvas);
  3064. //DataContext = APP.pageData;
  3065. //drawingAttributes = new DrawingAttributes();
  3066. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  3067. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  3068. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  3069. //blackboard_canvas.UseCustomCursor = true;
  3070. //drawingAttributes.FitToCurve = true;
  3071. //drawingAttributes.IgnorePressure = false;
  3072. //drawingAttributes.Width = PenSize;
  3073. //drawingAttributes.Height = PenSize;
  3074. //drawingAttributes.Color = Color;
  3075. //blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  3076. APP.PageDrawList.Clear();
  3077. imgCanvas.Source = null;
  3078. imgDocumentation.Source = null;
  3079. imgPPT.Source = null;
  3080. gridPage.Visibility = Visibility.Collapsed;
  3081. #endregion
  3082. //根据录制时间长度确定是否保存
  3083. if (SRTime.Hour > 0 || SRTime.Minute > 0 || SRTime.Second > 3)
  3084. {
  3085. #region 2秒内不可点击
  3086. new Thread(new ThreadStart(new Action(() =>
  3087. {
  3088. Dispatcher.Invoke(() =>
  3089. {
  3090. BtnRecord.IsEnabled = false;
  3091. btnStop.IsEnabled = false;
  3092. });
  3093. }))).Start();
  3094. #endregion
  3095. //缩略图
  3096. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  3097. FileToolsCommon.CreateDirectory(ThumbnailPath);
  3098. //缩略图存储位置
  3099. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
  3100. APP.FFmpeg.StopFFmpeg(AudioPathName);
  3101. new Thread(new ThreadStart(new Action(() =>
  3102. {
  3103. IsStartCount = false;
  3104. //停止截图
  3105. while (APP.FFmpeg.myProcess != null)
  3106. {
  3107. Thread.Sleep(100);
  3108. }
  3109. Dispatcher.Invoke(() =>
  3110. {
  3111. timer.Change(-1, 0);
  3112. timer.Dispose();
  3113. //End();
  3114. txbTime.Text = "";
  3115. txbTime.Visibility = Visibility.Hidden;
  3116. txbType.Visibility = Visibility.Visible;
  3117. txbType.Text = "保存中";
  3118. });
  3119. //}))).Start();
  3120. //new Thread(new ThreadStart(new Action(() =>
  3121. //{
  3122. //判断音频是否存在 判断音频临时文件夹是否存在
  3123. if (IsRecordAudio)
  3124. {
  3125. if (!FileToolsCommon.IsExistFile(AudioPathName))
  3126. {
  3127. Thread.Sleep(100);
  3128. }
  3129. if (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(AudioPathName) + "temp/"))
  3130. {
  3131. Thread.Sleep(100);
  3132. }
  3133. }
  3134. else
  3135. {
  3136. //没有录制音频
  3137. AudioPathName = null;
  3138. }
  3139. //合成视频
  3140. bool SynRes = APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSynthesisPathName, 5, gridActWidth, gridActHeight, out string ErrMessage);
  3141. //}))).Start();
  3142. //new Thread(new ThreadStart(new Action(() =>
  3143. //{
  3144. if (!SynRes)
  3145. {
  3146. Dispatcher.Invoke(() =>
  3147. {
  3148. //MessageWindow.Show("视频录制失败,无法保存此视频!");
  3149. MessageWindow.Show("录制失败," + ErrMessage);
  3150. BtnRecord.IsEnabled = true;
  3151. btnStop.IsEnabled = true;
  3152. TxbRecordingWord.Text = "录制";
  3153. txbType.Text = "";
  3154. });
  3155. return;
  3156. }
  3157. Dispatcher.Invoke(() =>
  3158. {
  3159. txbType.Text = "转码中";
  3160. });
  3161. while (!FileToolsCommon.IsExistFile(VideoSynthesisPathName))
  3162. {
  3163. Thread.Sleep(100);
  3164. }
  3165. while (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(VideoSynthesisPathName) + "temp/"))
  3166. {
  3167. Thread.Sleep(100);
  3168. }
  3169. FileToolsCommon.DeleteFile(ThumbnailPathName);
  3170. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  3171. Thread.Sleep(500);
  3172. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  3173. VideoInfo.VideoPath = VideoSavePathName;
  3174. VideoInfo.ThumbnailPath = ThumbnailPathName;
  3175. //生成缩略图
  3176. bool ThuRes = APP.FFmpeg.GenerateThumbnails(VideoSynthesisPathName, ThumbnailPathName, 200, 130);
  3177. Thread.Sleep(500);
  3178. //if (ThuRes)
  3179. //{
  3180. // Bitmap bmp = ImageHelper.ReadBitmapFile(ThumbnailPathName);
  3181. // if (bmp != null)
  3182. // {
  3183. // imgW = bmp.Width + (bmp.Width % 2 > 0 ? 1 : 0);
  3184. // imgH = bmp.Height + (bmp.Height % 2 > 0 ? 1 : 0);
  3185. // }
  3186. //}
  3187. APP.FFmpeg.VideoTranscode(VideoSynthesisPathName, VideoSavePathName, gridActWidth, gridActHeight);
  3188. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  3189. VideoInfo.IsUpload = false;
  3190. VideoInfo.Uploaded = 0;
  3191. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  3192. APP.VideoList.Add(VideoInfo);
  3193. //保存数据
  3194. APP.SaveWkData();
  3195. IsFirstR = true;
  3196. Dispatcher.Invoke(() =>
  3197. {
  3198. BtnRecord.IsEnabled = true;
  3199. btnStop.IsEnabled = true;
  3200. TxbRecordingWord.Text = "录制";
  3201. txbType.Text = "";
  3202. });
  3203. }))).Start();
  3204. }
  3205. else
  3206. {
  3207. APP.FFmpeg.SuspendFFmpeg();
  3208. IsStartCount = false;
  3209. timer.Change(-1, 0);
  3210. timer.Dispose();
  3211. IsFirstR = true;
  3212. BtnRecord.IsEnabled = true;
  3213. btnStop.IsEnabled = true;
  3214. TxbRecordingWord.Text = "录制";
  3215. txbType.Text = "";
  3216. MessageWindow.Show("录制时间过短,请重新录制!");
  3217. Dispatcher.Invoke(() =>
  3218. {
  3219. txbTime.Text = "";
  3220. txbTime.Visibility = Visibility.Hidden;
  3221. });
  3222. }
  3223. //List<Model_Video> VideoList
  3224. }
  3225. catch (Exception ex)
  3226. {
  3227. MessageWindow.Show(ex.Message);
  3228. }
  3229. }
  3230. }
  3231. #endregion
  3232. /// <summary>
  3233. /// 登陆事件
  3234. /// </summary>
  3235. /// <param name="sender"></param>
  3236. /// <param name="e"></param>
  3237. private void BtnLoginType_Click(object sender, RoutedEventArgs e)
  3238. {
  3239. if ("未登录".Equals(txbLoginType.Text))
  3240. {
  3241. Login();
  3242. }
  3243. else
  3244. {
  3245. MessageBoxResult dr = MessageWindow.Show("确定退出登陆?", "提示", MessageBoxButton.OKCancel);
  3246. if (dr == MessageBoxResult.OK)
  3247. {
  3248. LoginType();
  3249. Login();
  3250. }
  3251. }
  3252. }
  3253. /// <summary>
  3254. /// 登陆
  3255. /// </summary>
  3256. private void Login()
  3257. {
  3258. if (APP.W_LoginWindow == null)
  3259. {
  3260. APP.W_LoginWindow = new LoginWindow
  3261. {
  3262. WindowStartupLocation = WindowStartupLocation.CenterOwner,
  3263. Owner = this
  3264. };
  3265. }
  3266. else
  3267. {
  3268. APP.W_LoginWindow.Initialize();
  3269. }
  3270. APP.W_LoginWindow.ShowDialog();
  3271. if (APP.IsLoginType)
  3272. {
  3273. txbLoginType.Text = APP.UserInfo.Username;
  3274. //ImgUpload.Visibility = Visibility.Visible;
  3275. //ImgUploadTwo.Visibility = Visibility.Collapsed;
  3276. }
  3277. else
  3278. {
  3279. txbLoginType.Text = "未登录";
  3280. //ImgUpload.Visibility = Visibility.Collapsed;
  3281. //ImgUploadTwo.Visibility = Visibility.Visible;
  3282. }
  3283. }
  3284. /// <summary>
  3285. /// 状态更改为未登陆
  3286. /// </summary>
  3287. private void LoginType()
  3288. {
  3289. APP.IsLoginType = false;
  3290. txbLoginType.Text = "未登录";
  3291. APP.UserInfo = new Model_UserInfo();
  3292. //ImgUpload.Visibility = Visibility.Collapsed;
  3293. //ImgUploadTwo.Visibility = Visibility.Visible;
  3294. }
  3295. /// <summary>
  3296. /// 获取时间戳
  3297. /// </summary>
  3298. /// <returns></returns>
  3299. public string GetTimeStamp()
  3300. {
  3301. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  3302. return Convert.ToInt64(ts.TotalSeconds).ToString();
  3303. }
  3304. /// <summary>
  3305. /// 返回一个时间戳到毫秒
  3306. /// </summary>
  3307. /// <returns></returns>
  3308. public static long Timestamp()
  3309. {
  3310. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  3311. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  3312. return timestr;
  3313. }
  3314. /// <summary>
  3315. /// 增加事件
  3316. /// </summary>
  3317. /// <param name="sender"></param>
  3318. /// <param name="e"></param>
  3319. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  3320. {
  3321. Record();
  3322. if (APP.pageData.currpage > 0)
  3323. {
  3324. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  3325. }
  3326. if (IsStartCount && blackboard_canvas.Visibility == Visibility.Collapsed)
  3327. {
  3328. blackboard_canvas.Visibility = Visibility.Visible;
  3329. }
  3330. APP.pageData.pagenum += 1;
  3331. HideAngleBorder();
  3332. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  3333. APP.pageData.currpage = APP.pageData.pagenum;
  3334. myblackboard.changepage(APP.pageData.currpage - 1);
  3335. scroMain.ScrollToVerticalOffset(0);
  3336. ///清空页面图片UI
  3337. imgCanvas.Source = null;
  3338. imgDocumentation.Source = null;
  3339. imgPPT.Source = null;
  3340. if (APP.pageData.pagenum == 1)
  3341. {
  3342. APP.PageDrawList = new List<Model_DrawData>();
  3343. }
  3344. ///画板模型增加一页
  3345. Model_DrawData model_DrawData = new Model_DrawData
  3346. {
  3347. PageNum = APP.pageData.currpage
  3348. };
  3349. APP.PageDrawList.Add(model_DrawData);
  3350. ImgPrint.Visibility = Visibility.Visible;//可打印
  3351. ImgPrintTwo.Visibility = Visibility.Collapsed;
  3352. btnPrint.IsEnabled = true;
  3353. //APP.SaveDraw();
  3354. if (btnImport.IsEnabled == true)
  3355. {
  3356. ///截图可用
  3357. ImgScreenshot.Visibility = Visibility.Visible;
  3358. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  3359. btnScreenshot.IsEnabled = true;
  3360. }
  3361. }
  3362. /// <summary>
  3363. /// 打印事件
  3364. /// </summary>
  3365. /// <param name="sender"></param>
  3366. /// <param name="e"></param>
  3367. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  3368. {
  3369. try
  3370. {
  3371. //3种情况 1.文档图片 2.截图图片 3.没有图片
  3372. if (APP.PageDrawList.Count == 0)
  3373. {
  3374. MessageWindow.Show("没有可打印的页,您可以通过加页、截图或导入来增加页!");
  3375. return;
  3376. }
  3377. //iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0);
  3378. ////iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
  3379. //////设置纸张横向
  3380. ////document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
  3381. //string imgPath = FileToolsCommon.GetFileAbsolutePath("temp/");
  3382. //FileToolsCommon.CreateDirectory(imgPath);
  3383. //imgPath += "101.pdf";
  3384. //iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(imgPath, FileMode.Create, FileAccess.ReadWrite));
  3385. //document.Open();
  3386. //iTextSharp.text.Image image;
  3387. //for (int i = 0; i < APP.PageDrawList.Count; i++)
  3388. //{
  3389. // long ii = Timestamp();
  3390. // string directoryPath = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  3391. // string filePathOutPut = Path.Combine(directoryPath, string.Format("print{0}{1}.jpg", ii, i));
  3392. // RectangleF rectangleFs = new RectangleF();
  3393. // MergerImg("", filePathOutPut, rectangleFs, out string errmsg);
  3394. // image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  3395. // if (string.IsNullOrEmpty(APP.PageDrawList[i].PageImagePath))//没有图片
  3396. // {
  3397. // }
  3398. // else if (APP.PageDrawList[i].ImgDocumentation == true&& !APP.PageDrawList[i].Type.Equals("ppt"))
  3399. // {
  3400. // image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  3401. // }
  3402. // else
  3403. // {
  3404. // RectangleF rectangleF = new RectangleF
  3405. // {
  3406. // Width = (float)APP.PageDrawList[i].ImageSizes.CenterX,
  3407. // Height = (float)APP.PageDrawList[i].ImageSizes.CenterY,
  3408. // X = (float)APP.PageDrawList[i].ImageLocation.X,
  3409. // Y = (float)APP.PageDrawList[i].ImageLocation.Y
  3410. // };
  3411. // string msg = string.Empty;
  3412. // bool isImg = MergerImg(APP.PageDrawList[i].PageImagePath, filePathOutPut, rectangleF, out msg);
  3413. // if (isImg)
  3414. // {
  3415. // image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  3416. // }
  3417. // else
  3418. // {
  3419. // image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  3420. // }
  3421. // }
  3422. // if (image.Height > iTextSharp.text.PageSize.A4.Height)
  3423. // {
  3424. // image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  3425. // }
  3426. // else if (image.Width > iTextSharp.text.PageSize.A4.Width)
  3427. // {
  3428. // image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  3429. // }
  3430. // image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
  3431. // document.NewPage();
  3432. // document.Add(image);
  3433. // //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
  3434. // //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
  3435. // //p1.Leading = 150; //行间距
  3436. // //document.Add(p1);
  3437. //}
  3438. //Console.WriteLine("转换成功!");
  3439. //document.Close();
  3440. }
  3441. catch (Exception ex)
  3442. {
  3443. MessageWindow.Show(ex.Message);
  3444. Console.WriteLine("转换失败,原因:" + ex.Message);
  3445. }
  3446. //document.Close();
  3447. ////Console.ReadKey();
  3448. if (APP.W_PrintWindow == null)
  3449. {
  3450. APP.W_PrintWindow = new PrintWindow
  3451. {
  3452. //APP.W_PrintWindow.Topmost = true;
  3453. Owner = this
  3454. };
  3455. }
  3456. if (APP.PageDrawList.Count > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[0].PageImagePath))
  3457. {
  3458. APP.W_PrintWindow.Initialize(APP.PageDrawList[0].PageImagePath, gridM.ActualWidth, gridM.ActualHeight);
  3459. }
  3460. else
  3461. {
  3462. APP.W_PrintWindow.Initialize("", gridM.ActualWidth, gridActHeight);
  3463. }
  3464. APP.W_PrintWindow.ShowDialog();
  3465. //int pr = 1;
  3466. //string msg = string.Empty;
  3467. //string outPut = string.Empty;
  3468. //LatticeFileHelper.GeneratingPDF(@"G:\101.pdf", @"G:\102.TPF",out pr, out msg, out outPut);
  3469. //if(pr==0)
  3470. //{
  3471. // outPut = outPut.Replace("[", "").Replace("]","").Replace("\"","").Trim();
  3472. // APP.OutPut = outPut.Split(',');
  3473. // string defa = string.Empty;
  3474. // List<string>defaList= LatticeFileHelper.GetPrinterList(out defa);
  3475. // int printResult = 1;
  3476. // string standardError = string.Empty;
  3477. // string standardOutput = string.Empty;
  3478. // LatticeFileHelper.PrinterTPFFile(@"G:\102.TPF",1, /*defa*/"导出为WPS PDF", out printResult,out standardError,out standardOutput);
  3479. //}
  3480. }
  3481. /// 上一页
  3482. /// </summary>
  3483. /// <param name="sender"></param>
  3484. /// <param name="e"></param>
  3485. private void last_button_Click(object sender, RoutedEventArgs e)
  3486. {
  3487. if (APP.pageData.currpage > 1)
  3488. {
  3489. mouseDown = false;
  3490. HideAngleBorder();
  3491. //if(!APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  3492. //{
  3493. // ImgWG();
  3494. //}
  3495. APP.pageData.currpage -= 1;
  3496. myblackboard.changepage(APP.pageData.currpage - 1);
  3497. scroMain.ScrollToVerticalOffset(0);
  3498. if (btnImport.IsEnabled == true)
  3499. {
  3500. ///截图可用
  3501. ImgScreenshot.Visibility = Visibility.Visible;
  3502. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  3503. btnScreenshot.IsEnabled = true;
  3504. }
  3505. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  3506. {
  3507. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  3508. {
  3509. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  3510. }
  3511. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  3512. {
  3513. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  3514. if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  3515. {
  3516. if ("ppt".Equals(APP.PageDrawList[APP.pageData.currpage - 1].Type))
  3517. {
  3518. imgCanvas.Source = null;
  3519. imgDocumentation.Source = null;
  3520. imgPPT.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  3521. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  3522. ImgScreenshotTwo.Visibility = Visibility.Visible;
  3523. btnScreenshot.IsEnabled = false;
  3524. }
  3525. else
  3526. {
  3527. imgPPT.Source = null;
  3528. imgCanvas.Source = null;
  3529. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  3530. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  3531. ImgScreenshotTwo.Visibility = Visibility.Visible;
  3532. btnScreenshot.IsEnabled = false;
  3533. }
  3534. }
  3535. else
  3536. {
  3537. imgPPT.Source = null;
  3538. imgDocumentation.Source = null;
  3539. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  3540. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  3541. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  3542. {
  3543. mouseDown = false;
  3544. ImgXY();
  3545. }
  3546. }
  3547. }
  3548. else
  3549. {
  3550. imgPPT.Source = null;
  3551. imgCanvas.Source = null;
  3552. imgDocumentation.Source = null;
  3553. }
  3554. }
  3555. }
  3556. }
  3557. private void ImgXY()
  3558. {
  3559. imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
  3560. imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
  3561. imgCanvas.Margin = new Thickness(APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X, APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y, 0, 0);
  3562. //imgCanvas.Margin.Left= APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  3563. //transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  3564. }
  3565. private void ImgWG()
  3566. {
  3567. mouseDown = false;
  3568. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  3569. {
  3570. X = imgCanvas.Margin.Left,
  3571. Y = imgCanvas.Margin.Top
  3572. };
  3573. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  3574. {
  3575. CenterX = imgCanvas.ActualWidth,
  3576. CenterY = imgCanvas.ActualHeight
  3577. };
  3578. }
  3579. /// <summary>
  3580. /// 下一页
  3581. /// </summary>
  3582. /// <param name="sender"></param>
  3583. /// <param name="e"></param>
  3584. private void next_btn_Click(object sender, RoutedEventArgs e)
  3585. {
  3586. if (APP.pageData.currpage < APP.pageData.pagenum)
  3587. {
  3588. mouseDown = false;
  3589. HideAngleBorder();
  3590. //if (!APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  3591. //{
  3592. // ImgWG();
  3593. //}
  3594. APP.pageData.currpage += 1;
  3595. myblackboard.changepage(APP.pageData.currpage - 1);
  3596. scroMain.ScrollToVerticalOffset(0);
  3597. if (btnImport.IsEnabled == true)
  3598. {
  3599. ///截图可用
  3600. ImgScreenshot.Visibility = Visibility.Visible;
  3601. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  3602. btnScreenshot.IsEnabled = true;
  3603. }
  3604. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  3605. {
  3606. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  3607. {
  3608. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  3609. }
  3610. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  3611. {
  3612. if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  3613. {
  3614. if ("ppt".Equals(APP.PageDrawList[APP.pageData.currpage - 1].Type))
  3615. {
  3616. imgCanvas.Source = null;
  3617. imgDocumentation.Source = null;
  3618. imgPPT.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  3619. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  3620. ImgScreenshotTwo.Visibility = Visibility.Visible;
  3621. btnScreenshot.IsEnabled = false;
  3622. }
  3623. else
  3624. {
  3625. imgPPT.Source = null;
  3626. imgCanvas.Source = null;
  3627. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  3628. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  3629. ImgScreenshotTwo.Visibility = Visibility.Visible;
  3630. btnScreenshot.IsEnabled = false;
  3631. }
  3632. //imgCanvas.Source = null;
  3633. //imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  3634. //ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  3635. //ImgScreenshotTwo.Visibility = Visibility.Visible;
  3636. //btnScreenshot.IsEnabled = false;
  3637. }
  3638. else
  3639. {
  3640. imgPPT.Source = null;
  3641. imgDocumentation.Source = null;
  3642. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  3643. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  3644. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  3645. {
  3646. //var group = IMG.FindResource("Imageview") as TransformGroup;
  3647. //#region 高低 缩放比例
  3648. //if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
  3649. //{
  3650. // var transform1 = group.Children[0] as ScaleTransform;
  3651. // transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
  3652. // transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
  3653. // imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
  3654. // imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
  3655. //}
  3656. //#endregion
  3657. //#region 坐标XY轴
  3658. //var transform = group.Children[1] as TranslateTransform;
  3659. //transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  3660. //transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  3661. //#endregion
  3662. mouseDown = false;
  3663. ImgXY();
  3664. }
  3665. }
  3666. }
  3667. else
  3668. {
  3669. imgPPT.Source = null;
  3670. imgCanvas.Source = null;
  3671. imgDocumentation.Source = null;
  3672. }
  3673. }
  3674. }
  3675. }
  3676. /// <summary>
  3677. /// 生成图片
  3678. /// </summary>
  3679. /// <param name="_path">图片地址</param>
  3680. /// <param name="_saveimg">保存位置</param>
  3681. /// <param name="_rectangle">图片位置</param>
  3682. /// <param name="errmsg">错误消息</param>
  3683. /// <returns></returns>
  3684. private bool MergerImg(string _path, string _saveimg, RectangleF _rectangle, out string errmsg)
  3685. {
  3686. errmsg = null;
  3687. try
  3688. {
  3689. Bitmap bitmap = null;
  3690. //创建要显示的图片对象,根据参数的个数设置宽度
  3691. Bitmap backgroudImg = new Bitmap((int)gridM.ActualWidth, (int)gridM.ActualHeight);
  3692. Graphics g = Graphics.FromImage(backgroudImg);
  3693. //清除画布,背景设置为白色
  3694. g.Clear(System.Drawing.Color.White);
  3695. if (!string.IsNullOrWhiteSpace(_path))
  3696. {
  3697. bitmap = ImageHelper.ReadBitmapFile(_path);
  3698. g.DrawImage(bitmap, _rectangle);
  3699. }
  3700. backgroudImg.Save(_saveimg);
  3701. g.Dispose();
  3702. backgroudImg.Dispose();
  3703. if (bitmap != null)
  3704. {
  3705. bitmap.Dispose();
  3706. }
  3707. GC.Collect();
  3708. return true;
  3709. }
  3710. catch (Exception ex)
  3711. {
  3712. errmsg = ex.Message;
  3713. LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
  3714. return false;
  3715. }
  3716. }
  3717. /// <summary>
  3718. /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法: ConvertPDF2Image("F:\\PdfFile.doc", "F:\\",
  3719. /// "ImageFile", 1, 20, ImageFormat.Png, 256);
  3720. /// </summary>
  3721. /// <param name="pdfInputPath">Word文件路径</param>
  3722. /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
  3723. /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
  3724. /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
  3725. /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
  3726. /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
  3727. /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
  3728. public List<string> ConvertWordToImage(string wordInputPath, string imageOutputPath,
  3729. string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution)
  3730. {
  3731. // 返回的图片绝对路径集合
  3732. List<string> images = new List<string>();
  3733. try
  3734. {
  3735. // open word file
  3736. Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);
  3737. // validate parameter
  3738. if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
  3739. if (imageOutputPath.Trim().Length == 0) { imageOutputPath = System.IO.Path.GetDirectoryName(wordInputPath); }
  3740. if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
  3741. if (imageName.Trim().Length == 0) { imageName = System.IO.Path.GetFileNameWithoutExtension(wordInputPath); }
  3742. if (startPageNum <= 0) { startPageNum = 1; }
  3743. if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
  3744. if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
  3745. if (imageFormat == null) { imageFormat = ImageFormat.Png; }
  3746. if (resolution <= 0) { resolution = 128; }
  3747. ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat))
  3748. {
  3749. Resolution = resolution
  3750. };
  3751. // start to convert each page
  3752. for (int i = startPageNum; i <= endPageNum; i++)
  3753. {
  3754. imageSaveOptions.PageIndex = i - 1;
  3755. doc.Save(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString(), imageSaveOptions);
  3756. images.Add(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString());
  3757. APP.num++;
  3758. }
  3759. imageSaveOptions = null;
  3760. doc = null;
  3761. }
  3762. catch (Exception ex)
  3763. {
  3764. //if(ex.Message.ToString().Equals("{\"The document appears to be corrupted and cannot be loaded.\"}"))
  3765. //{
  3766. // MessageWindow.Show("Word文件无效或者Word文件被加密!");
  3767. //}
  3768. //else
  3769. //{
  3770. MessageWindow.Show("该文件无法使用!");
  3771. //}
  3772. LogHelper.WriteErrLog("【导入方法(ConvertWordToImage)】错误日志:" + ex.Message, ex);
  3773. }
  3774. return images;
  3775. }
  3776. private static SaveFormat GetSaveFormat(ImageFormat imageFormat)
  3777. {
  3778. SaveFormat sf;// = SaveFormat.Unknown;
  3779. if (imageFormat.Equals(ImageFormat.Png))
  3780. {
  3781. sf = SaveFormat.Png;
  3782. }
  3783. else if (imageFormat.Equals(ImageFormat.Jpeg))
  3784. {
  3785. sf = SaveFormat.Jpeg;
  3786. }
  3787. else if (imageFormat.Equals(ImageFormat.Tiff))
  3788. {
  3789. sf = SaveFormat.Tiff;
  3790. }
  3791. else if (imageFormat.Equals(ImageFormat.Bmp))
  3792. {
  3793. sf = SaveFormat.Bmp;
  3794. }
  3795. else
  3796. {
  3797. sf = SaveFormat.Unknown;
  3798. }
  3799. return sf;
  3800. }
  3801. #region 图像缩放,移动
  3802. private bool mouseDown;
  3803. private System.Windows.Point mouseXY;
  3804. private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  3805. {
  3806. ContentControl img = sender as ContentControl;
  3807. if (img == null)
  3808. {
  3809. return;
  3810. }
  3811. img.CaptureMouse();
  3812. mouseDown = true;
  3813. mouseXY = e.GetPosition(img);
  3814. Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
  3815. }
  3816. private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  3817. {
  3818. ContentControl img = sender as ContentControl;
  3819. if (img == null)
  3820. {
  3821. return;
  3822. }
  3823. img.ReleaseMouseCapture();
  3824. mouseDown = false;
  3825. }
  3826. private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  3827. {
  3828. ContentControl img = sender as ContentControl;
  3829. if (img == null)
  3830. {
  3831. return;
  3832. }
  3833. if (mouseDown)
  3834. {
  3835. Domousemove(img, e);
  3836. }
  3837. }
  3838. /// <summary>
  3839. /// x y轴
  3840. /// </summary>
  3841. /// <param name="img"></param>
  3842. /// <param name="e"></param>
  3843. private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
  3844. {
  3845. if (e.LeftButton != MouseButtonState.Pressed)
  3846. {
  3847. return;
  3848. }
  3849. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  3850. {
  3851. return;
  3852. }
  3853. TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
  3854. TranslateTransform transform = group.Children[1] as TranslateTransform;
  3855. System.Windows.Point position = e.GetPosition(img);
  3856. transform.X -= mouseXY.X - position.X;
  3857. transform.Y -= mouseXY.Y - position.Y;
  3858. mouseXY = position;
  3859. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  3860. {
  3861. X = transform.X,
  3862. Y = transform.Y
  3863. };
  3864. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  3865. }
  3866. private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
  3867. {
  3868. ContentControl img = sender as ContentControl;
  3869. if (img == null)
  3870. {
  3871. return;
  3872. }
  3873. System.Windows.Point point = e.GetPosition(img);
  3874. Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
  3875. System.Windows.Point PicLocate = e.GetPosition(imgCanvas);
  3876. Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
  3877. TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
  3878. double delta = e.Delta * 0.001;
  3879. DowheelZoom(group, point, delta);
  3880. }
  3881. private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
  3882. {
  3883. System.Windows.Point pointToContent = group.Inverse.Transform(point);
  3884. ScaleTransform transform = group.Children[0] as ScaleTransform;
  3885. if (transform.ScaleX + delta < 0.1)
  3886. {
  3887. return;
  3888. }
  3889. transform.ScaleX += delta;
  3890. transform.ScaleY += delta;
  3891. TranslateTransform transform1 = group.Children[1] as TranslateTransform;
  3892. transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
  3893. transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
  3894. //LogHelper.WriteInfoLog("【img宽高】" + imgCanvas.ActualWidth.ToString() + ":"
  3895. // + imgCanvas.ActualHeight.ToString() + "百分比:" + transform.ScaleX.ToString() + ":" + transform.ScaleY.ToString()
  3896. // );
  3897. //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
  3898. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize = new ScaleTransform();
  3899. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX = transform.ScaleX;
  3900. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY = transform.ScaleY;
  3901. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  3902. {
  3903. X = transform1.X,
  3904. Y = transform1.Y
  3905. };
  3906. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  3907. {
  3908. CenterX = imgCanvas.ActualWidth,
  3909. CenterY = imgCanvas.ActualHeight
  3910. };
  3911. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  3912. }
  3913. #endregion
  3914. #region 点阵笔相关
  3915. #region 值初始化
  3916. // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
  3917. /// <summary>
  3918. /// A4点阵纸点阵宽度
  3919. /// </summary>
  3920. private const int A4_WIDTH = 5600;
  3921. /// <summary>
  3922. /// A4点阵纸点阵高度
  3923. /// </summary>
  3924. private const int A4_HEIGHT = 7920;
  3925. ///// <summary>
  3926. ///// 画板
  3927. ///// </summary>
  3928. //private Graphics graphics;
  3929. /// <summary>
  3930. /// 笔画坐标数组
  3931. /// </summary>
  3932. private List<System.Drawing.Point> stroke;
  3933. /// <summary>
  3934. /// 笔序列号
  3935. /// </summary>
  3936. private string penSerial;
  3937. /// <summary>
  3938. /// 笔是否在点
  3939. /// </summary>
  3940. private bool isPenDown;
  3941. //当前点阵地址
  3942. private string currentPageSerial = string.Empty;
  3943. //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
  3944. //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
  3945. private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
  3946. #endregion
  3947. public void InitPen()
  3948. {
  3949. stroke = new List<System.Drawing.Point>();
  3950. //获取点阵笔实例,并绑定点阵笔事件
  3951. //将授权文件内容传入,获取点阵笔对象实例
  3952. APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
  3953. //绑定笔连接事件
  3954. APP.digitalPen.PenConnected += OnPenConnect;
  3955. //绑定笔断开事件
  3956. APP.digitalPen.PenDisconnect += OnPenDisconnect;
  3957. //绑定笔书写输出坐标事件
  3958. APP.digitalPen.PenCoordinate += OnPenCoordinate;
  3959. //绑定抬笔事件
  3960. APP.digitalPen.PenUp += OnPenUp;
  3961. //绑定落笔事件
  3962. APP.digitalPen.PenDown += OnPenDown;
  3963. APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
  3964. APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
  3965. //完成初始化点阵笔,开始与点阵笔通信
  3966. ERROR_CODE ER = APP.digitalPen.Start();
  3967. ////绑定笔在新的点阵地址页面书写事件
  3968. //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
  3969. ////绑定笔信息事件
  3970. //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
  3971. //启动接收笔数据,完成初始化工作
  3972. ERROR_CODE rc = APP.digitalPen.Start();
  3973. //判断是否成功
  3974. if (ER != ERROR_CODE.ERROR_OK)
  3975. {
  3976. MessageWindow.Show("初始化失败,授权过期,返回值:" + ER.ToString());
  3977. }
  3978. }
  3979. /// <summary>
  3980. /// 落笔
  3981. /// </summary>
  3982. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  3983. /// <param name="penSerial">点阵笔序列号</param>
  3984. /// <param name="penType">点阵笔型号编号</param>
  3985. private void OnPenDown(ulong time, string penSerial, int penType)
  3986. {
  3987. if (CheckAccess())
  3988. {
  3989. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
  3990. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  3991. }
  3992. else
  3993. {
  3994. //labPenSerial.Text = penSerial;
  3995. //labPenStatus.Text = "PenDown";
  3996. isPenDown = true;
  3997. //Dispatcher.Invoke(new Action(() =>
  3998. //{
  3999. // for (int i = 0; i < APP.PageDrawList.Count; i++)
  4000. // {
  4001. // if (APP.PageDrawList[i].PageCode == penSerial)
  4002. // {
  4003. // if (i < APP.pageData.pagenum)
  4004. // {
  4005. // if (i < APP.pageData.currpage)
  4006. // {
  4007. // int num = APP.pageData.currpage - i;
  4008. // APP.pageData.currpage -= num;
  4009. // myblackboard.changepage(APP.pageData.currpage - 1);
  4010. // if (APP.PageDrawList.Count > 0)
  4011. // {
  4012. // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  4013. // {
  4014. // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  4015. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  4016. // }
  4017. // else
  4018. // {
  4019. // imgCanvas.Source = null;
  4020. // }
  4021. // }
  4022. // }
  4023. // else
  4024. // {
  4025. // int num = i - APP.pageData.currpage;
  4026. // APP.pageData.currpage += num;
  4027. // myblackboard.changepage(APP.pageData.currpage - 1);
  4028. // if (APP.PageDrawList.Count > 0)
  4029. // {
  4030. // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  4031. // {
  4032. // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  4033. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  4034. // }
  4035. // else
  4036. // {
  4037. // imgCanvas.Source = null;
  4038. // }
  4039. // }
  4040. // }
  4041. // }
  4042. // return;
  4043. // }
  4044. // }
  4045. // //myblackboard.changepages(0, 0, true);
  4046. // //myblackboard.changepaget(0, 0, true, blackboard_canvas);
  4047. //}));
  4048. }
  4049. //myblackboard.changepages(0, 0, true);
  4050. }
  4051. /// <summary>
  4052. /// 抬笔
  4053. /// </summary>
  4054. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4055. /// <param name="penSerial">点阵笔序列号</param>
  4056. /// <param name="penType">点阵笔型号编号</param>
  4057. private void OnPenUp(ulong time, string penSerial, int penType)
  4058. {
  4059. if (CheckAccess())
  4060. {
  4061. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
  4062. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  4063. }
  4064. else
  4065. {
  4066. isPenDown = false;
  4067. APP.PenSerial = penSerial;
  4068. //int leftPoints = stroke.Count % 3;
  4069. //if (0 != leftPoints)
  4070. //{
  4071. // int from = stroke.Count - leftPoints - 1;
  4072. // if (from < 0)
  4073. // from = 0;
  4074. // int to = stroke.Count - 1;
  4075. // DrawCoordinates(from, to);
  4076. //}
  4077. stroke.Clear();
  4078. }
  4079. if (APP.pageData.currpage > 0)
  4080. {
  4081. Dispatcher.Invoke(new Action(() =>
  4082. {
  4083. myblackboard.changepages(0, 0, true, Color, PenSize, APP.pageData.currpage - 1);
  4084. }));
  4085. }
  4086. }
  4087. /// <summary>
  4088. /// 笔断开
  4089. /// </summary>
  4090. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4091. /// <param name="penSerial">点阵笔序列号</param>
  4092. /// <param name="penType">点阵笔型号编号</param>
  4093. private void OnPenDisconnect(ulong time, string penSerial, int penType)
  4094. {
  4095. if (CheckAccess())
  4096. {
  4097. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
  4098. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  4099. }
  4100. else
  4101. {
  4102. APP.PenSerial = penSerial;
  4103. APP.PenStatus = false;
  4104. Dispatcher.Invoke(new Action(() =>
  4105. {
  4106. txbNotConnected.Text = "未连接";
  4107. txbNotConnecteds.Text = "未连接";
  4108. }));
  4109. }
  4110. }
  4111. /// <summary>
  4112. /// 笔连接
  4113. /// </summary>
  4114. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4115. /// <param name="penSerial">点阵笔序列号</param>
  4116. /// <param name="penType">点阵笔型号编号</param>
  4117. private void OnPenConnect(ulong time, string penSerial, int penType)
  4118. {
  4119. if (CheckAccess())
  4120. {
  4121. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
  4122. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  4123. }
  4124. else
  4125. {
  4126. APP.PenSerial = penSerial;
  4127. APP.PenStatus = true;
  4128. this.penSerial = penSerial;
  4129. //连接后,在获取笔数据前,可以清除笔内的历史数据
  4130. //APP.digitalPen.ClearMemory(penSerial);
  4131. //开始接收笔数据
  4132. APP.digitalPen.GetPenData(penSerial);
  4133. Dispatcher.Invoke(new Action(() =>
  4134. {
  4135. txbNotConnected.Text = "已连接";
  4136. txbNotConnecteds.Text = "已连接";
  4137. }));
  4138. }
  4139. }
  4140. /// <summary>
  4141. /// 电池电量
  4142. /// </summary>
  4143. /// <param name="time"></param>
  4144. /// <param name="penSerial"></param>
  4145. /// <param name="penType"></param>
  4146. /// <param name="capacity"></param>
  4147. private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
  4148. {
  4149. if (CheckAccess())
  4150. {
  4151. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
  4152. Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
  4153. }
  4154. else
  4155. {
  4156. //System.Windows.MessageWindow.Show("电池电量:" + capacity.ToString());
  4157. }
  4158. }
  4159. /// <summary>
  4160. /// 已用存储
  4161. /// </summary>
  4162. /// <param name="time"></param>
  4163. /// <param name="penSerial"></param>
  4164. /// <param name="penType"></param>
  4165. /// <param name="fillLevel"></param>
  4166. private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
  4167. {
  4168. if (CheckAccess())
  4169. {
  4170. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
  4171. Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
  4172. }
  4173. else
  4174. {
  4175. //System.Windows.MessageWindow.Show("存储:" + fillLevel.ToString());
  4176. }
  4177. }
  4178. /// <summary>
  4179. /// 笔书写,收到坐标
  4180. /// </summary>
  4181. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4182. /// <param name="penSerial">点阵笔序列号</param>
  4183. /// <param name="penType">点阵笔型号编号</param>
  4184. /// <param name="pageSerial">点阵地址</param>
  4185. /// <param name="cx">x坐标</param>
  4186. /// <param name="cy">y坐标</param>
  4187. /// <param name="force">压力值</param>
  4188. private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
  4189. {
  4190. if (CheckAccess())
  4191. {
  4192. Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
  4193. Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
  4194. }
  4195. else
  4196. {
  4197. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  4198. if (!isPenDown)
  4199. {
  4200. return;
  4201. }
  4202. stroke.Add(new System.Drawing.Point(cx, cy));
  4203. double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
  4204. double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
  4205. //点
  4206. double testX = cx * PropW;
  4207. double testY = cy * PropH;
  4208. //pageSerial //点阵IP地址 与打印的页面关联
  4209. if (APP.pageData.currpage > 0)
  4210. {
  4211. Dispatcher.Invoke(new Action(() =>
  4212. {
  4213. //myblackboard.changepages(testX, testY,false);
  4214. myblackboard.changepages(testX, testY, false, Color, PenSize, APP.pageData.currpage - 1);
  4215. #region 设置滚动条位置
  4216. //点在显示页面上方
  4217. if (testY < scroMain.VerticalOffset)
  4218. {
  4219. //滚动条当前位置
  4220. double RollCurrentLocation = scroMain.VerticalOffset;
  4221. //向上滚动至以点为中心需要滚动的距离
  4222. double UpRoll = (RollCurrentLocation - testY) + (scroMain.ActualHeight / 2);
  4223. //如果小于0则等于0
  4224. double RollLocation = RollCurrentLocation - UpRoll;
  4225. if (RollLocation < 0)
  4226. {
  4227. RollLocation = 0;
  4228. }
  4229. ////滚动条实际偏移量
  4230. //double RollOffset = RollCurrentLocation - RollLocation;
  4231. scroMain.ScrollToVerticalOffset(RollLocation);
  4232. }
  4233. //点在显示页面下方
  4234. if (testY > scroMain.VerticalOffset + scroMain.ActualHeight)
  4235. {
  4236. //滚动条当前位置
  4237. double RollCurrentLocation = scroMain.VerticalOffset;
  4238. //向下滚动至以点为中心需要滚动的距离
  4239. double DownRoll = (testY - RollCurrentLocation) - (scroMain.ActualHeight / 2);
  4240. //如果小于0则等于0
  4241. double RollLocation = RollCurrentLocation + DownRoll;
  4242. //滚动条最大滚动值
  4243. double ScrollbarMaxNum = gridM.ActualHeight - scroMain.ActualHeight;
  4244. if (RollLocation > ScrollbarMaxNum)
  4245. {
  4246. RollLocation = ScrollbarMaxNum;
  4247. }
  4248. ////滚动条实际偏移量
  4249. //double RollOffset = RollLocation-RollCurrentLocation;
  4250. scroMain.ScrollToVerticalOffset(RollLocation);
  4251. }
  4252. #endregion
  4253. //gridM.Height //A4高度
  4254. //scroMain.VerticalOffset;//获取滚动条位置
  4255. //scroMain.ActualHeight//A4纸显示高度
  4256. //scroMain.ScrollToHorizontalOffset()//设置滚动条位置
  4257. //Mouse.GetPosition(this)
  4258. if (testX > 0 && testY > 0)
  4259. {
  4260. //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
  4261. System.Windows.Point getP = scroMain.PointToScreen(new System.Windows.Point(testX, testY - scroMain.VerticalOffset));
  4262. SetCursorPos((int)getP.X, (int)getP.Y);
  4263. }
  4264. }));
  4265. }
  4266. ////每3个点画一条曲线
  4267. //if (stroke.Count % 3 == 0)
  4268. //{
  4269. // int from = stroke.Count - 3 - 1;
  4270. // if (from < 0)
  4271. // from = 0;
  4272. // int to = stroke.Count - 1;
  4273. // DrawCoordinates(from, to);
  4274. //}
  4275. }
  4276. }
  4277. /// <summary>
  4278. /// 停止笔
  4279. /// </summary>
  4280. public void StopDigitalPen()
  4281. {
  4282. //停止,释放资源
  4283. APP.digitalPen.Stop();
  4284. }
  4285. /// <summary>
  4286. /// 清空笔内存储
  4287. /// </summary>
  4288. public void ClearPenStorage()
  4289. {
  4290. if (!string.IsNullOrEmpty(penSerial))
  4291. {
  4292. APP.digitalPen.ClearMemory(penSerial);
  4293. }
  4294. }
  4295. /// <summary>
  4296. /// 获取剩余电量
  4297. /// </summary>
  4298. public void GetPenElectricityQuantity()
  4299. {
  4300. if (!string.IsNullOrEmpty(penSerial))
  4301. {
  4302. APP.digitalPen.GetBatteryCapacity(penSerial);
  4303. }
  4304. }
  4305. /// <summary>
  4306. /// 获取存储空间
  4307. /// </summary>
  4308. public void GetUsedStorage()
  4309. {
  4310. if (!string.IsNullOrEmpty(penSerial))
  4311. {
  4312. APP.digitalPen.GetMemoryFillLevel(penSerial);
  4313. }
  4314. }
  4315. /// <summary>
  4316. /// 开启悬浮
  4317. /// </summary>
  4318. public void 开启悬浮()
  4319. {
  4320. if (!string.IsNullOrEmpty(penSerial))
  4321. {
  4322. APP.digitalPen.SetPenHoverMode(true, penSerial);
  4323. }
  4324. }
  4325. /// <summary>
  4326. /// 关闭悬浮
  4327. /// </summary>
  4328. public void 关闭悬浮()
  4329. {
  4330. if (!string.IsNullOrEmpty(penSerial))
  4331. {
  4332. APP.digitalPen.SetPenHoverMode(false, penSerial);
  4333. }
  4334. }
  4335. #endregion
  4336. /// <summary>
  4337. /// 最小化
  4338. /// </summary>
  4339. /// <param name="sender"></param>
  4340. /// <param name="e"></param>
  4341. private void BtnShrink_Click(object sender, RoutedEventArgs e)
  4342. {
  4343. if (WindowState == WindowState.Minimized)
  4344. {
  4345. WindowState = WindowState.Normal;
  4346. }
  4347. else
  4348. {
  4349. WindowState = WindowState.Minimized;
  4350. }
  4351. }
  4352. /// <summary>
  4353. /// 引用user32.dll动态链接库(windows api),
  4354. /// 使用库中定义 API:SetCursorPos
  4355. /// 设置光标位置
  4356. /// </summary>
  4357. [System.Runtime.InteropServices.DllImport("user32.dll")]
  4358. private static extern int SetCursorPos(int x, int y);
  4359. #region 图片拉伸移动
  4360. private System.Windows.Point initialPoint;
  4361. /// <summary>
  4362. /// 隐藏图片四个点和线
  4363. /// </summary>
  4364. private void HideAngleBorder()
  4365. {
  4366. RectLeftUp.Visibility = Visibility.Hidden;
  4367. RectRightUp.Visibility = Visibility.Hidden;
  4368. RectLeftDown.Visibility = Visibility.Hidden;
  4369. RectRightDown.Visibility = Visibility.Hidden;
  4370. RectImgBorder.Visibility = Visibility.Hidden;
  4371. }
  4372. private void ShowAngleBorder()
  4373. {
  4374. PointLocation();
  4375. RectLeftUp.Visibility = Visibility.Visible;
  4376. RectRightUp.Visibility = Visibility.Visible;
  4377. RectLeftDown.Visibility = Visibility.Visible;
  4378. RectRightDown.Visibility = Visibility.Visible;
  4379. RectImgBorder.Visibility = Visibility.Visible;
  4380. }
  4381. /// <summary>
  4382. /// 确定四个点和边框的位置大小
  4383. /// </summary>
  4384. private void PointLocation()
  4385. {
  4386. RectImgBorder.Width = imgCanvas.ActualWidth + 10.0;
  4387. RectImgBorder.Height = imgCanvas.ActualHeight + 10.0;
  4388. RectImgBorder.Margin = new Thickness(imgCanvas.Margin.Left - 5.0, imgCanvas.Margin.Top - 5.0, 0, 0);
  4389. Canvas.SetLeft(RectLeftUp, imgCanvas.Margin.Left - 10.0);
  4390. Canvas.SetTop(RectLeftUp, imgCanvas.Margin.Top - 10.0);
  4391. Canvas.SetLeft(RectRightUp, imgCanvas.Margin.Left + imgCanvas.ActualWidth - 10.0);
  4392. Canvas.SetTop(RectRightUp, imgCanvas.Margin.Top - 10.0);
  4393. Canvas.SetLeft(RectLeftDown, imgCanvas.Margin.Left - 10.0);
  4394. Canvas.SetTop(RectLeftDown, imgCanvas.Margin.Top + imgCanvas.ActualHeight - 10.0);
  4395. Canvas.SetLeft(RectRightDown, imgCanvas.Margin.Left + imgCanvas.ActualWidth - 10.0);
  4396. Canvas.SetTop(RectRightDown, imgCanvas.Margin.Top + imgCanvas.ActualHeight - 10.0);
  4397. }
  4398. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  4399. {
  4400. System.Windows.Point point = e.GetPosition(imgCanvas);
  4401. initialPoint = point;
  4402. //Console.WriteLine("PicEmap.X = " + point.X + "; PicEmap.Y = " + point.Y);
  4403. //if ((point.X - 304) * (point.X - 304) + (point.Y - 86) * (point.Y - 86) < 100)
  4404. //{
  4405. // Console.WriteLine("在范围内");
  4406. //}
  4407. HideAngleBorder();
  4408. }
  4409. private void imgCanvas_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  4410. {
  4411. if (e.LeftButton == MouseButtonState.Pressed && mouseDown)
  4412. {
  4413. System.Windows.Point point = e.GetPosition(imgCanvas);
  4414. imgCanvas.Margin = new Thickness(imgCanvas.Margin.Left + (point.X - initialPoint.X), imgCanvas.Margin.Top + (point.Y - initialPoint.Y), 0, 0);
  4415. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  4416. {
  4417. X = imgCanvas.Margin.Left,
  4418. Y = imgCanvas.Margin.Top
  4419. };
  4420. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  4421. {
  4422. CenterX = imgCanvas.ActualWidth,
  4423. CenterY = imgCanvas.ActualHeight
  4424. };
  4425. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  4426. }
  4427. }
  4428. private void imgCanvas_MouseUp(object sender, MouseButtonEventArgs e)
  4429. {
  4430. if (mouseDown)
  4431. {
  4432. ShowAngleBorder();
  4433. }
  4434. }
  4435. private System.Drawing.PointF imgRightDown;
  4436. /// <summary>
  4437. /// 设置控件最上层
  4438. /// </summary>
  4439. /// <param name="element"></param>
  4440. public void BringToFront(Thumb element)//图片置于最顶层显示
  4441. {
  4442. if (element == null)
  4443. {
  4444. return;
  4445. }
  4446. Canvas parent = element.Parent as Canvas;
  4447. if (parent == null)
  4448. {
  4449. return;
  4450. }
  4451. int maxZ = parent.Children.OfType<UIElement>()//linq语句,取Zindex的最大值
  4452. .Where(x => x != element)
  4453. .Select(x => Canvas.GetZIndex(x))
  4454. .Max();
  4455. Canvas.SetZIndex(element, maxZ + 1);
  4456. }
  4457. private void RectRightUp_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
  4458. {
  4459. try
  4460. {
  4461. Thumb thu = (Thumb)sender;
  4462. BringToFront(thu);
  4463. imgRightDown = new System.Drawing.PointF((float)(imgCanvas.Margin.Left + imgCanvas.ActualWidth), (float)(imgCanvas.Margin.Top + imgCanvas.ActualHeight));
  4464. HideAngleBorder();
  4465. switch (thu.Name)
  4466. {
  4467. case "RectLeftUp":
  4468. RectLeftUp.Visibility = Visibility.Visible;
  4469. break;
  4470. case "RectRightUp":
  4471. RectRightUp.Visibility = Visibility.Visible;
  4472. break;
  4473. case "RectLeftDown":
  4474. RectLeftDown.Visibility = Visibility.Visible;
  4475. break;
  4476. case "RectRightDown":
  4477. RectRightDown.Visibility = Visibility.Visible;
  4478. break;
  4479. default:
  4480. break;
  4481. }
  4482. }
  4483. catch (Exception ex)
  4484. {
  4485. MessageWindow.Show(ex.Message);
  4486. }
  4487. }
  4488. private void RectRightUp_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
  4489. {
  4490. try
  4491. {
  4492. if (mouseDown)
  4493. {
  4494. Thumb thu = (Thumb)sender;
  4495. #region 判断是否超出 暂无
  4496. double plul = Canvas.GetLeft(RectLeftUp);
  4497. double plut = Canvas.GetTop(RectLeftUp);
  4498. double prdl = Canvas.GetLeft(RectRightDown);
  4499. double prdt = Canvas.GetTop(RectRightDown);
  4500. #endregion
  4501. //Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4502. //Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4503. double imgW = 0;
  4504. double imgH = 0;
  4505. double imgX = 0;
  4506. double imgY = 0;
  4507. switch (thu.Name)
  4508. {
  4509. case "RectLeftUp":
  4510. #region 左上
  4511. imgW = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  4512. imgH = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  4513. imgX = 0;
  4514. imgY = 0;
  4515. if (imgW < 50)
  4516. {
  4517. imgCanvas.Width = 50;
  4518. imgX = imgCanvas.Margin.Left;
  4519. Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
  4520. }
  4521. else
  4522. {
  4523. imgCanvas.Width = imgW;
  4524. imgX = Mouse.GetPosition(gridM).X;
  4525. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4526. }
  4527. if (imgH < 50)
  4528. {
  4529. imgCanvas.Height = 50;
  4530. imgY = imgCanvas.Margin.Top;
  4531. Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
  4532. }
  4533. else
  4534. {
  4535. imgCanvas.Height = imgH;
  4536. imgY = Mouse.GetPosition(gridM).Y;
  4537. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4538. }
  4539. imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  4540. #endregion
  4541. //imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  4542. //imgCanvas.Height = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  4543. //imgCanvas.Margin = new Thickness(Mouse.GetPosition(gridM).X, Mouse.GetPosition(gridM).Y, 0, 0);
  4544. break;
  4545. case "RectRightUp":
  4546. #region 右上
  4547. imgW = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
  4548. imgH = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  4549. imgX = 0;
  4550. imgY = 0;
  4551. if (imgW < 50)
  4552. {
  4553. imgCanvas.Width = 50;
  4554. imgX = imgCanvas.Margin.Left;
  4555. Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
  4556. }
  4557. else
  4558. {
  4559. imgCanvas.Width = imgW;
  4560. imgX = imgCanvas.Margin.Left;
  4561. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4562. }
  4563. if (imgH < 50)
  4564. {
  4565. imgCanvas.Height = 50;
  4566. imgY = imgCanvas.Margin.Top;
  4567. Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
  4568. }
  4569. else
  4570. {
  4571. imgCanvas.Height = imgH;
  4572. imgY = Mouse.GetPosition(gridM).Y;
  4573. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4574. }
  4575. imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  4576. //imgCanvas.Width = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
  4577. //imgCanvas.Height = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  4578. //imgCanvas.Margin = new Thickness(imgCanvas.Margin.Left, Mouse.GetPosition(gridM).Y, 0, 0);
  4579. #endregion
  4580. break;
  4581. case "RectLeftDown":
  4582. #region 左下
  4583. imgW = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  4584. imgH = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
  4585. imgX = 0;
  4586. imgY = 0;
  4587. if (imgW < 50)
  4588. {
  4589. imgCanvas.Width = 50;
  4590. imgX = imgCanvas.Margin.Left;
  4591. Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
  4592. }
  4593. else
  4594. {
  4595. imgCanvas.Width = imgW;
  4596. imgX = Mouse.GetPosition(gridM).X;
  4597. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4598. }
  4599. if (imgH < 50)
  4600. {
  4601. imgCanvas.Height = 50;
  4602. imgY = imgCanvas.Margin.Top;
  4603. Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
  4604. }
  4605. else
  4606. {
  4607. imgCanvas.Height = imgH;
  4608. imgY = imgCanvas.Margin.Top;
  4609. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4610. }
  4611. imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  4612. //imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  4613. //imgCanvas.Height = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
  4614. //imgCanvas.Margin = new Thickness(Mouse.GetPosition(gridM).X, imgCanvas.Margin.Top, 0, 0);
  4615. #endregion
  4616. break;
  4617. case "RectRightDown":
  4618. #region 右下
  4619. imgW = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
  4620. imgH = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
  4621. if (imgW < 50)
  4622. {
  4623. imgCanvas.Width = 50;
  4624. Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
  4625. }
  4626. else
  4627. {
  4628. imgCanvas.Width = imgW;
  4629. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4630. }
  4631. if (imgH < 50)
  4632. {
  4633. imgCanvas.Height = 50;
  4634. Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
  4635. }
  4636. else
  4637. {
  4638. imgCanvas.Height = imgH;
  4639. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4640. }
  4641. //imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  4642. //imgCanvas.Width += e.HorizontalChange;
  4643. //imgCanvas.Height += e.VerticalChange;
  4644. #endregion
  4645. break;
  4646. default:
  4647. break;
  4648. }
  4649. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  4650. {
  4651. X = imgCanvas.Margin.Left,
  4652. Y = imgCanvas.Margin.Top
  4653. };
  4654. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  4655. {
  4656. CenterX = imgCanvas.ActualWidth,
  4657. CenterY = imgCanvas.ActualHeight
  4658. };
  4659. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  4660. }
  4661. //lbl1.Content = imgCanvas.Margin.Left + "," + imgCanvas.Margin.Top;
  4662. //lbl2.Content = (imgCanvas.Margin.Left+ imgCanvas.Width) +"," + imgCanvas.Margin.Top;
  4663. //lbl3.Content = imgCanvas.Margin.Left + "," + (imgCanvas.Margin.Top+ imgCanvas.Height);
  4664. //lbl4.Content= (imgCanvas.Margin.Left + imgCanvas.Width )+ "," + (imgCanvas.Margin.Top + imgCanvas.Height);
  4665. }
  4666. catch (Exception)
  4667. {
  4668. MessageWindow.Show("图片过小!");
  4669. }
  4670. }
  4671. private void RectRightUp_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
  4672. {
  4673. ShowAngleBorder();
  4674. }
  4675. #endregion
  4676. #region 方法
  4677. /// <summary>
  4678. /// 录屏 录制 截图 导入文档 增加 主页面显示
  4679. /// </summary>
  4680. private void Record()
  4681. {
  4682. GridMain.Visibility = Visibility.Visible;
  4683. gridSetUp.Visibility = Visibility.Collapsed;
  4684. //gridUpload.Visibility = Visibility.Collapsed;
  4685. GridMyVideo.Visibility = Visibility.Collapsed;
  4686. if (APP.pageData.pagenum > 0)
  4687. {
  4688. gridPage.Visibility = Visibility.Visible;
  4689. }
  4690. DataContext = APP.pageData;
  4691. }
  4692. /// <summary>
  4693. /// 设置页面显示
  4694. /// </summary>
  4695. private void SetUp()
  4696. {
  4697. }
  4698. #endregion
  4699. private void imgCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  4700. {
  4701. mouseDown = true;
  4702. }
  4703. /// <summary>
  4704. /// 点击标题栏 隐藏截图的四个点和线
  4705. /// </summary>
  4706. /// <param name="sender"></param>
  4707. /// <param name="e"></param>
  4708. private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
  4709. {
  4710. HideAngleBorder();
  4711. }
  4712. /// <summary>
  4713. /// 鼠标左键点击事件
  4714. /// </summary>
  4715. /// <param name="sender"></param>
  4716. /// <param name="e"></param>
  4717. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  4718. {
  4719. if (RectImgBorder.Visibility != Visibility.Hidden)
  4720. {
  4721. HideAngleBorder();
  4722. }
  4723. }
  4724. private void Window_Loaded(object sender, RoutedEventArgs e)
  4725. {
  4726. //调整录制区域宽高
  4727. double proportion = 210.0 / 297.0;
  4728. gridM.Height = gridM.ActualWidth / proportion;
  4729. }
  4730. }
  4731. }