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

XHMicroLessonSystemWindow.xaml.cs 223KB

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