星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

XHMicroLessonSystemWindow.xaml.cs 220KB

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