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

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