星火微课系统客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

XHMicroLessonSystemWindow.xaml.cs 223KB

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