星火微课系统客户端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

XHMicroLessonSystemWindow.xaml.cs 233KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274
  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 AudioPath = FileToolsCommon.GetFileAbsolutePath("/temp/audio/");
  3184. FileToolsCommon.CreateDirectory(AudioPath);
  3185. string audioSpeakerPath = AudioPath + "adoS" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".m";
  3186. string audioMicrophonePath = AudioPath + "adoM" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".m";
  3187. try
  3188. {
  3189. FileToolsCommon.DeleteFile(audioSpeakerPath);
  3190. FileToolsCommon.DeleteFile(audioMicrophonePath);
  3191. }
  3192. catch (Exception)
  3193. {
  3194. }
  3195. //扬声器
  3196. if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
  3197. {
  3198. APP.FFmpeg.StopRecordAudio(2);
  3199. //Thread.Sleep(500);
  3200. //麦克风
  3201. if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
  3202. {
  3203. }
  3204. else
  3205. {
  3206. //无法录制麦克风
  3207. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制麦克风,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  3208. if (Res == MessageBoxResult.Cancel)
  3209. {
  3210. return;
  3211. }
  3212. }
  3213. APP.FFmpeg.StopRecordAudio(1);
  3214. }
  3215. else
  3216. {
  3217. //无法录制扬声器音频
  3218. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制音频,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  3219. if (Res == MessageBoxResult.Cancel)
  3220. {
  3221. return;
  3222. }
  3223. }
  3224. #endregion
  3225. txbTime.Visibility = Visibility.Visible;
  3226. VideoInfo = new Model_Video
  3227. {
  3228. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  3229. WkType = Enum_WKVidetype.RecordingLessons
  3230. };
  3231. ImgPath = APP.WKData.WkPath + "temp/Image/";
  3232. AudioPathName = APP.WKData.WkPath + "temp/audio/";
  3233. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  3234. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  3235. FileToolsCommon.CreateDirectory(ImgPath);
  3236. FileToolsCommon.CreateDirectory(AudioPathName);
  3237. AudioPathName += APP.WKData.WkName + ".MP3";
  3238. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  3239. VideoSynthesisPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn." + VideoInfo.VideoType.ToString();
  3240. int num = 1;
  3241. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  3242. {
  3243. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制_" + num + "." + VideoInfo.VideoType.ToString();
  3244. VideoSynthesisPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn_" + num + "." + VideoInfo.VideoType.ToString();
  3245. num++;
  3246. }
  3247. #region 设置录屏唯一 废弃
  3248. //if (FileToolsCommon.IsExistFile(VideoSavePathName))
  3249. //{
  3250. // MessageBoxResult dr = MessageWindow.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  3251. // if (dr == MessageBoxResult.OK)
  3252. // {
  3253. // try
  3254. // {
  3255. // FileToolsCommon.DeleteFile(VideoSavePathName);
  3256. // APP.VideoList.RemoveAll(x => x.VideoPath == VideoSavePathName);
  3257. // }
  3258. // catch (Exception ex)
  3259. // {
  3260. // LogHelper.WriteErrLog("【录制】(StartRecord)无法移除视频," + ex.Message, ex);
  3261. // }
  3262. // }
  3263. // else
  3264. // {
  3265. // return;
  3266. // }
  3267. //}
  3268. #endregion
  3269. #region 禁用按钮
  3270. ImgPrint.Visibility = Visibility.Collapsed;//录制中不可打印
  3271. ImgPrintTwo.Visibility = Visibility.Visible;
  3272. btnPrint.IsEnabled = false;
  3273. ImgScreenshot.Visibility = Visibility.Collapsed;//录制中不可截图
  3274. ImgScreenshotTwo.Visibility = Visibility.Visible;
  3275. btnScreenshot.IsEnabled = false;
  3276. ImgImport.Visibility = Visibility.Collapsed;//录制中不可导入文档
  3277. ImgImportTwo.Visibility = Visibility.Visible;
  3278. btnImport.IsEnabled = false;
  3279. ImgScreenRecording.Visibility = Visibility.Collapsed;//录制中不可录屏
  3280. ImgScreenRecordingTwo.Visibility = Visibility.Visible;
  3281. btnScreenRecording.IsEnabled = false;
  3282. ImgUpload.Visibility = Visibility.Collapsed;//录制中不可上传
  3283. ImgUploadTwo.Visibility = Visibility.Visible;
  3284. btnUpload.IsEnabled = false;
  3285. ImgSetUp.Visibility = Visibility.Collapsed;//录制中不可设置
  3286. ImgSetUpTwo.Visibility = Visibility.Visible;
  3287. btnSetUp.IsEnabled = false;
  3288. btnLoginType.IsEnabled = false;
  3289. blackboard_canvas.Visibility = Visibility.Visible;//zxyceshi
  3290. //myblackboard = new BlackboardNew(blackboard_canvas);
  3291. //DataContext = APP.pageData;
  3292. //drawingAttributes = new DrawingAttributes();
  3293. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  3294. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  3295. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  3296. //blackboard_canvas.UseCustomCursor = true;
  3297. //drawingAttributes.FitToCurve = true;
  3298. //drawingAttributes.IgnorePressure = false;
  3299. //drawingAttributes.Width = PenSize;
  3300. //drawingAttributes.Height = PenSize;
  3301. //drawingAttributes.Color = Color;
  3302. //blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  3303. #endregion
  3304. #region 设置录制大小
  3305. //gridActWidth = (int)GridMain.ActualWidth==0?1276: (int)GridMain.ActualWidth;
  3306. //gridActHeight = (int)GridMain.ActualHeight==0?898: (int)GridMain.ActualHeight;
  3307. gridActWidth = (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f));
  3308. gridActHeight = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f));
  3309. gridActWidth = gridActWidth % 2 > 0 ? gridActWidth - 1 : gridActWidth;
  3310. gridActHeight = gridActHeight % 2 > 0 ? gridActHeight - 1 : gridActHeight;
  3311. #endregion
  3312. #region 录像倒计时
  3313. if (APP.W_CountdownWindow == null)
  3314. {
  3315. APP.W_CountdownWindow = new CountdownWindow();
  3316. APP.W_CountdownWindow.Initialize();
  3317. //APP.W_CountdownWindow.Topmost = true;
  3318. }
  3319. else
  3320. {
  3321. APP.W_CountdownWindow.Initialize();
  3322. //APP.W_CountdownWindow.Topmost = true;
  3323. }
  3324. APP.W_CountdownWindow.Show();
  3325. #endregion
  3326. IsFirstR = false;
  3327. RsImgName = new List<string>();
  3328. SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
  3329. txbTime.Visibility = Visibility.Visible;
  3330. ///启动截图
  3331. timer = new System.Threading.Timer(new TimerCallback(Timer_Elapsed), null, 0, 20);
  3332. //{
  3333. // AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
  3334. //};//设置执行一次(false)还是一直执行(true)
  3335. //timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
  3336. //timer.Enabled = true; //启动计时器
  3337. }
  3338. //继续录制
  3339. IsSuspendR = false;
  3340. //BtnRecording.Content = "暂停录制";
  3341. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
  3342. TxbRecordingWord.Text = "暂停";
  3343. #region 4秒内不可点击
  3344. //new Thread(new ThreadStart(new Action(() =>
  3345. //{
  3346. // Dispatcher.Invoke(() =>
  3347. // {
  3348. // BtnRecord.IsEnabled = false;
  3349. // btnStop.IsEnabled = false;
  3350. // ImgStop.Visibility = Visibility.Visible;
  3351. // ImgStopTwo.Visibility = Visibility.Collapsed;
  3352. // });
  3353. //}))).Start();
  3354. new Thread(new ThreadStart(new Action(() =>
  3355. {
  3356. //Thread.Sleep(4000);
  3357. Dispatcher.Invoke(() =>
  3358. {
  3359. BtnRecord.IsEnabled = true;
  3360. btnStop.IsEnabled = true;
  3361. ImgStop.Visibility = Visibility.Collapsed;
  3362. ImgStopTwo.Visibility = Visibility.Visible;
  3363. });
  3364. }))).Start();
  3365. #endregion
  3366. try
  3367. {
  3368. new Thread(new ThreadStart(new Action(() =>
  3369. {
  3370. Thread.Sleep(1000);
  3371. IsRecordAudio = APP.FFmpeg.StartRecordingAudio(AudioPathName, out string ErrMessage);
  3372. Thread.Sleep(1000);
  3373. Dispatcher.Invoke(() =>
  3374. {
  3375. if (!IsRecordAudio)
  3376. {
  3377. MessageWindow.Show(ErrMessage);
  3378. }
  3379. Recorddt = DateTime.Now;
  3380. IsStartCount = true;
  3381. //Stack();
  3382. //timer.Start();
  3383. });
  3384. }))).Start();
  3385. }
  3386. catch (Exception ex)
  3387. {
  3388. MessageWindow.Show(ex.Message);
  3389. }
  3390. }
  3391. else
  3392. {
  3393. //暂停
  3394. IsSuspendR = true;
  3395. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  3396. ImgStop.Visibility = Visibility.Collapsed;
  3397. ImgStopTwo.Visibility = Visibility.Visible;
  3398. TxbRecordingWord.Text = "继续";
  3399. //TimeOut();
  3400. #region 2秒内不可点击
  3401. new Thread(new ThreadStart(new Action(() =>
  3402. {
  3403. Dispatcher.Invoke(() =>
  3404. {
  3405. BtnRecord.IsEnabled = false;
  3406. btnStop.IsEnabled = false;
  3407. });
  3408. Thread.Sleep(2000);
  3409. Dispatcher.Invoke(() =>
  3410. {
  3411. BtnRecord.IsEnabled = true;
  3412. btnStop.IsEnabled = true;
  3413. });
  3414. }))).Start();
  3415. #endregion
  3416. try
  3417. {
  3418. APP.FFmpeg.SuspendFFmpeg();
  3419. new Thread(new ThreadStart(new Action(() =>
  3420. {
  3421. while (APP.FFmpeg.myProcess != null)
  3422. {
  3423. Thread.Sleep(100);
  3424. }
  3425. IsStartCount = false;
  3426. }))).Start();
  3427. }
  3428. catch (Exception ex)
  3429. {
  3430. MessageWindow.Show(ex.Message);
  3431. }
  3432. }
  3433. }
  3434. /// <summary>
  3435. /// 记录上次截图时间
  3436. /// </summary>
  3437. private DateTime Recorddt = DateTime.Now;
  3438. /// <summary>
  3439. /// 录制保存图片计时器
  3440. /// </summary>
  3441. /// <param name="sender"></param>
  3442. private void Timer_Elapsed(object sender)
  3443. {
  3444. if (IsStartCount)
  3445. {
  3446. DateTime dt = DateTime.Now;
  3447. TimeSpan ts = dt.Subtract(Recorddt);//时间差
  3448. double tsmi = ts.TotalMilliseconds;
  3449. if (tsmi > 200.0)
  3450. {
  3451. Recorddt = Recorddt.AddMilliseconds(200);
  3452. Thread thread = new Thread(RecordSaveImage);
  3453. //开启线程
  3454. thread.Start();
  3455. }
  3456. }
  3457. }
  3458. /// <summary>
  3459. /// 录制保存图片
  3460. /// </summary>
  3461. private void RecordSaveImage()
  3462. {
  3463. try
  3464. {
  3465. if (IsStartCount)
  3466. {
  3467. string FilePathName = ImgPath + RsImgName.Count + ".png";
  3468. RsImgName.Add(FilePathName);
  3469. #region 设置大小
  3470. double RsW = (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f));
  3471. double RsH = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f));
  3472. if (RsW > 1266)
  3473. {
  3474. double Proportion = RsH / RsW;
  3475. RsW = 1266;
  3476. RsH = RsW * Proportion;
  3477. RsH = ((int)RsH) % 2 > 0 ? (int)RsH - 1 : (int)RsH;
  3478. //RsH = 898;
  3479. }
  3480. #endregion
  3481. //System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Send, new ThreadStart(delegate
  3482. //{
  3483. //}));
  3484. Dispatcher.Invoke(() =>
  3485. {
  3486. //保存图片
  3487. ImageHelper.SaveUI(GridMain, FilePathName, gridActWidth, gridActHeight, (int)RsW, (int)RsH);
  3488. //ImageHelper.SaveUIToImage(GridMain, FilePathName, gridActWidth, gridActHeight, (int)RsW, (int)RsH);
  3489. //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f)), 0, 0);
  3490. //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)), (int)RsW, (int)RsH);
  3491. //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)), 1281, 1026);
  3492. SRTime = SRTime.AddMilliseconds(200);
  3493. if (txbTime.Visibility == Visibility.Hidden)
  3494. {
  3495. txbTime.Visibility = Visibility.Visible;
  3496. }
  3497. if (SRTime.Hour > 0)
  3498. {
  3499. //Dispatcher.Invoke(() =>
  3500. //{
  3501. txbTime.Text = SRTime.ToString("HH:mm:ss");
  3502. //});
  3503. }
  3504. else
  3505. {
  3506. //Dispatcher.Invoke(() =>
  3507. //{
  3508. txbTime.Text = SRTime.ToString("mm:ss");
  3509. //});
  3510. }
  3511. });
  3512. }
  3513. }
  3514. catch (Exception ex)
  3515. {
  3516. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  3517. }
  3518. }
  3519. /// <summary>
  3520. /// 停止录制并生成录制文件
  3521. /// </summary>
  3522. private void EndRecord()
  3523. {
  3524. if (!IsFirstR)
  3525. {
  3526. #region 恢复被禁用的按钮
  3527. ImgPrint.Visibility = Visibility.Visible;
  3528. ImgPrintTwo.Visibility = Visibility.Collapsed;
  3529. btnPrint.IsEnabled = true;
  3530. ImgScreenshot.Visibility = Visibility.Visible;
  3531. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  3532. btnScreenshot.IsEnabled = true;
  3533. ImgImport.Visibility = Visibility.Visible;
  3534. ImgImportTwo.Visibility = Visibility.Collapsed;
  3535. btnImport.IsEnabled = true;
  3536. ImgScreenRecording.Visibility = Visibility.Visible;
  3537. ImgScreenRecordingTwo.Visibility = Visibility.Collapsed;
  3538. btnScreenRecording.IsEnabled = true;
  3539. ImgUpload.Visibility = Visibility.Visible;
  3540. ImgUploadTwo.Visibility = Visibility.Collapsed;
  3541. btnUpload.IsEnabled = true;
  3542. ImgSetUp.Visibility = Visibility.Visible;
  3543. ImgSetUpTwo.Visibility = Visibility.Collapsed;
  3544. btnSetUp.IsEnabled = true;
  3545. btnLoginType.IsEnabled = true;
  3546. //btnStop.IsEnabled = false;//停止录制按钮不可点击
  3547. #endregion
  3548. IsSuspendR = true;
  3549. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  3550. ImgStop.Visibility = Visibility.Visible;
  3551. ImgStopTwo.Visibility = Visibility.Collapsed;
  3552. //TimeOut();
  3553. try
  3554. {
  3555. #region 清空画板数据
  3556. APP.pageData.currpage = 0;
  3557. APP.pageData.pagenum = 0;
  3558. myblackboard.clear();
  3559. //myblackboard = new BlackboardNew(blackboard_canvas);
  3560. //DataContext = APP.pageData;
  3561. //drawingAttributes = new DrawingAttributes();
  3562. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  3563. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  3564. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  3565. //blackboard_canvas.UseCustomCursor = true;
  3566. //drawingAttributes.FitToCurve = true;
  3567. //drawingAttributes.IgnorePressure = false;
  3568. //drawingAttributes.Width = PenSize;
  3569. //drawingAttributes.Height = PenSize;
  3570. //drawingAttributes.Color = Color;
  3571. //blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  3572. APP.PageDrawList.Clear();
  3573. imgCanvas.Source = null;
  3574. imgDocumentation.Source = null;
  3575. imgPPT.Source = null;
  3576. gridPage.Visibility = Visibility.Collapsed;
  3577. #endregion
  3578. //根据录制时间长度确定是否保存
  3579. if (SRTime.Hour > 0 || SRTime.Minute > 0 || SRTime.Second > 3)
  3580. {
  3581. #region 2秒内不可点击
  3582. new Thread(new ThreadStart(new Action(() =>
  3583. {
  3584. Dispatcher.Invoke(() =>
  3585. {
  3586. BtnRecord.IsEnabled = false;
  3587. btnStop.IsEnabled = false;
  3588. });
  3589. }))).Start();
  3590. #endregion
  3591. //缩略图
  3592. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  3593. FileToolsCommon.CreateDirectory(ThumbnailPath);
  3594. //缩略图存储位置
  3595. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
  3596. APP.FFmpeg.StopFFmpeg(AudioPathName);
  3597. new Thread(new ThreadStart(new Action(() =>
  3598. {
  3599. IsStartCount = false;
  3600. //停止截图
  3601. while (APP.FFmpeg.myProcess != null)
  3602. {
  3603. Thread.Sleep(100);
  3604. }
  3605. Dispatcher.Invoke(() =>
  3606. {
  3607. timer.Change(-1, 0);
  3608. timer.Dispose();
  3609. //End();
  3610. txbTime.Text = "";
  3611. txbTime.Visibility = Visibility.Hidden;
  3612. txbType.Visibility = Visibility.Visible;
  3613. txbType.Text = "保存中";
  3614. });
  3615. //}))).Start();
  3616. //new Thread(new ThreadStart(new Action(() =>
  3617. //{
  3618. //判断音频是否存在 判断音频临时文件夹是否存在
  3619. if (IsRecordAudio)
  3620. {
  3621. if (!FileToolsCommon.IsExistFile(AudioPathName))
  3622. {
  3623. Thread.Sleep(100);
  3624. }
  3625. if (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(AudioPathName) + "temp/"))
  3626. {
  3627. Thread.Sleep(100);
  3628. }
  3629. }
  3630. else
  3631. {
  3632. //没有录制音频
  3633. AudioPathName = null;
  3634. }
  3635. //合成视频
  3636. bool SynRes = APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSynthesisPathName, 5, gridActWidth, gridActHeight, out string ErrMessage);
  3637. //}))).Start();
  3638. //new Thread(new ThreadStart(new Action(() =>
  3639. //{
  3640. if (!SynRes)
  3641. {
  3642. Dispatcher.Invoke(() =>
  3643. {
  3644. //MessageWindow.Show("视频录制失败,无法保存此视频!");
  3645. MessageWindow.Show("录制失败," + ErrMessage);
  3646. BtnRecord.IsEnabled = true;
  3647. btnStop.IsEnabled = true;
  3648. TxbRecordingWord.Text = "录制";
  3649. txbType.Text = "";
  3650. });
  3651. return;
  3652. }
  3653. Dispatcher.Invoke(() =>
  3654. {
  3655. txbType.Text = "转码中";
  3656. });
  3657. while (!FileToolsCommon.IsExistFile(VideoSynthesisPathName))
  3658. {
  3659. Thread.Sleep(100);
  3660. }
  3661. while (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(VideoSynthesisPathName) + "temp/"))
  3662. {
  3663. Thread.Sleep(100);
  3664. }
  3665. FileToolsCommon.DeleteFile(ThumbnailPathName);
  3666. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  3667. Thread.Sleep(500);
  3668. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  3669. VideoInfo.VideoPath = VideoSavePathName;
  3670. VideoInfo.ThumbnailPath = ThumbnailPathName;
  3671. //生成缩略图
  3672. bool ThuRes = APP.FFmpeg.GenerateThumbnails(VideoSynthesisPathName, ThumbnailPathName, 200, 130);
  3673. Thread.Sleep(500);
  3674. //if (ThuRes)
  3675. //{
  3676. // Bitmap bmp = ImageHelper.ReadBitmapFile(ThumbnailPathName);
  3677. // if (bmp != null)
  3678. // {
  3679. // imgW = bmp.Width + (bmp.Width % 2 > 0 ? 1 : 0);
  3680. // imgH = bmp.Height + (bmp.Height % 2 > 0 ? 1 : 0);
  3681. // }
  3682. //}
  3683. APP.FFmpeg.VideoTranscode(VideoSynthesisPathName, VideoSavePathName, gridActWidth, gridActHeight);
  3684. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  3685. VideoInfo.IsUpload = false;
  3686. VideoInfo.Uploaded = 0;
  3687. //VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  3688. APP.VideoList.Add(VideoInfo);
  3689. //保存数据
  3690. APP.SaveWkData();
  3691. IsFirstR = true;
  3692. Dispatcher.Invoke(() =>
  3693. {
  3694. BtnRecord.IsEnabled = true;
  3695. btnStop.IsEnabled = true;
  3696. TxbRecordingWord.Text = "录制";
  3697. txbType.Text = "";
  3698. });
  3699. }))).Start();
  3700. }
  3701. else
  3702. {
  3703. APP.FFmpeg.SuspendFFmpeg();
  3704. IsStartCount = false;
  3705. timer.Change(-1, 0);
  3706. timer.Dispose();
  3707. IsFirstR = true;
  3708. BtnRecord.IsEnabled = true;
  3709. btnStop.IsEnabled = true;
  3710. TxbRecordingWord.Text = "录制";
  3711. txbType.Text = "";
  3712. MessageWindow.Show("录制时间过短,请重新录制!");
  3713. Dispatcher.Invoke(() =>
  3714. {
  3715. txbTime.Text = "";
  3716. txbTime.Visibility = Visibility.Hidden;
  3717. });
  3718. }
  3719. //List<Model_Video> VideoList
  3720. }
  3721. catch (Exception ex)
  3722. {
  3723. MessageWindow.Show(ex.Message);
  3724. }
  3725. }
  3726. }
  3727. #endregion
  3728. #region 登陆
  3729. /// <summary>
  3730. /// 登陆事件
  3731. /// </summary>
  3732. /// <param name="sender"></param>
  3733. /// <param name="e"></param>
  3734. private void BtnLoginType_Click(object sender, RoutedEventArgs e)
  3735. {
  3736. if ("未登录".Equals(txbLoginType.Text))
  3737. {
  3738. Login();
  3739. }
  3740. else
  3741. {
  3742. MessageBoxResult dr = MessageWindow.Show("确定退出登陆?", "提示", MessageBoxButton.OKCancel);
  3743. if (dr == MessageBoxResult.OK)
  3744. {
  3745. LoginType();
  3746. Login();
  3747. }
  3748. }
  3749. }
  3750. /// <summary>
  3751. /// 登陆
  3752. /// </summary>
  3753. private void Login()
  3754. {
  3755. if (APP.W_LoginWindow == null)
  3756. {
  3757. APP.W_LoginWindow = new LoginWindow
  3758. {
  3759. WindowStartupLocation = WindowStartupLocation.CenterOwner,
  3760. Owner = this
  3761. };
  3762. }
  3763. else
  3764. {
  3765. APP.W_LoginWindow.Initialize();
  3766. }
  3767. APP.W_LoginWindow.ShowDialog();
  3768. if (APP.IsLoginType)
  3769. {
  3770. txbLoginType.Text = APP.UserInfo.Username;
  3771. //ImgUpload.Visibility = Visibility.Visible;
  3772. //ImgUploadTwo.Visibility = Visibility.Collapsed;
  3773. }
  3774. else
  3775. {
  3776. txbLoginType.Text = "未登录";
  3777. //ImgUpload.Visibility = Visibility.Collapsed;
  3778. //ImgUploadTwo.Visibility = Visibility.Visible;
  3779. }
  3780. }
  3781. /// <summary>
  3782. /// 状态更改为未登陆
  3783. /// </summary>
  3784. private void LoginType()
  3785. {
  3786. APP.IsLoginType = false;
  3787. txbLoginType.Text = "未登录";
  3788. APP.UserInfo = new Model_UserInfo();
  3789. //ImgUpload.Visibility = Visibility.Collapsed;
  3790. //ImgUploadTwo.Visibility = Visibility.Visible;
  3791. }
  3792. #endregion
  3793. #region 分页
  3794. /// 上一页
  3795. /// </summary>
  3796. /// <param name="sender"></param>
  3797. /// <param name="e"></param>
  3798. private void last_button_Click(object sender, RoutedEventArgs e)
  3799. {
  3800. if (APP.pageData.currpage > 1)
  3801. {
  3802. mouseDown = false;
  3803. HideAngleBorder();
  3804. //隐藏跳转
  3805. //txbCurrpage.Visibility = Visibility.Visible;
  3806. //txtJump.Visibility = Visibility.Hidden;
  3807. //BtnJumpPage.Visibility = Visibility.Hidden;
  3808. //if(!APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  3809. //{
  3810. // ImgWG();
  3811. //}
  3812. APP.pageData.currpage -= 1;
  3813. JumpPageClick();
  3814. }
  3815. }
  3816. /// <summary>
  3817. /// 下一页
  3818. /// </summary>
  3819. /// <param name="sender"></param>
  3820. /// <param name="e"></param>
  3821. private void next_btn_Click(object sender, RoutedEventArgs e)
  3822. {
  3823. if (APP.pageData.currpage < APP.pageData.pagenum)
  3824. {
  3825. mouseDown = false;
  3826. HideAngleBorder();
  3827. //隐藏跳转
  3828. //txbCurrpage.Visibility = Visibility.Visible;
  3829. //txtJump.Visibility = Visibility.Hidden;
  3830. //BtnJumpPage.Visibility = Visibility.Hidden;
  3831. //if (!APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  3832. //{
  3833. // ImgWG();
  3834. //}
  3835. APP.pageData.currpage += 1;
  3836. JumpPageClick();
  3837. }
  3838. }
  3839. /// <summary>
  3840. /// 跳转
  3841. /// </summary>
  3842. void JumpPageClick()
  3843. {
  3844. myblackboard.changepage(APP.pageData.currpage - 1);
  3845. scroMain.ScrollToVerticalOffset(0);
  3846. if (btnImport.IsEnabled == true)
  3847. {
  3848. ///截图可用
  3849. ImgScreenshot.Visibility = Visibility.Visible;
  3850. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  3851. btnScreenshot.IsEnabled = true;
  3852. }
  3853. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  3854. {
  3855. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  3856. {
  3857. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  3858. }
  3859. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  3860. {
  3861. if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  3862. {
  3863. if ("ppt".Equals(APP.PageDrawList[APP.pageData.currpage - 1].Type))
  3864. {
  3865. imgCanvas.Source = null;
  3866. imgDocumentation.Source = null;
  3867. imgPPT.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  3868. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  3869. ImgScreenshotTwo.Visibility = Visibility.Visible;
  3870. btnScreenshot.IsEnabled = false;
  3871. }
  3872. else
  3873. {
  3874. imgPPT.Source = null;
  3875. imgCanvas.Source = null;
  3876. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  3877. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  3878. ImgScreenshotTwo.Visibility = Visibility.Visible;
  3879. btnScreenshot.IsEnabled = false;
  3880. }
  3881. //imgCanvas.Source = null;
  3882. //imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  3883. //ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  3884. //ImgScreenshotTwo.Visibility = Visibility.Visible;
  3885. //btnScreenshot.IsEnabled = false;
  3886. }
  3887. else
  3888. {
  3889. imgPPT.Source = null;
  3890. imgDocumentation.Source = null;
  3891. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  3892. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  3893. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  3894. {
  3895. //var group = IMG.FindResource("Imageview") as TransformGroup;
  3896. //#region 高低 缩放比例
  3897. //if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
  3898. //{
  3899. // var transform1 = group.Children[0] as ScaleTransform;
  3900. // transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
  3901. // transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
  3902. // imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
  3903. // imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
  3904. //}
  3905. //#endregion
  3906. //#region 坐标XY轴
  3907. //var transform = group.Children[1] as TranslateTransform;
  3908. //transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  3909. //transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  3910. //#endregion
  3911. mouseDown = false;
  3912. ImgXY();
  3913. }
  3914. }
  3915. }
  3916. else
  3917. {
  3918. imgPPT.Source = null;
  3919. imgCanvas.Source = null;
  3920. imgDocumentation.Source = null;
  3921. }
  3922. #region 修改跳转页码
  3923. CbxPageList.SelectedIndex = APP.pageData.currpage - 1;
  3924. #endregion
  3925. }
  3926. }
  3927. private void ImgXY()
  3928. {
  3929. imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
  3930. imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
  3931. imgCanvas.Margin = new Thickness(APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X, APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y, 0, 0);
  3932. //imgCanvas.Margin.Left= APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  3933. //transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  3934. }
  3935. private void ImgWG()
  3936. {
  3937. mouseDown = false;
  3938. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  3939. {
  3940. X = imgCanvas.Margin.Left,
  3941. Y = imgCanvas.Margin.Top
  3942. };
  3943. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  3944. {
  3945. CenterX = imgCanvas.ActualWidth,
  3946. CenterY = imgCanvas.ActualHeight
  3947. };
  3948. }
  3949. #endregion
  3950. #region 图像缩放,移动
  3951. private bool mouseDown;
  3952. private System.Windows.Point mouseXY;
  3953. private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  3954. {
  3955. ContentControl img = sender as ContentControl;
  3956. if (img == null)
  3957. {
  3958. return;
  3959. }
  3960. img.CaptureMouse();
  3961. mouseDown = true;
  3962. mouseXY = e.GetPosition(img);
  3963. //Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
  3964. }
  3965. private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  3966. {
  3967. ContentControl img = sender as ContentControl;
  3968. if (img == null)
  3969. {
  3970. return;
  3971. }
  3972. img.ReleaseMouseCapture();
  3973. mouseDown = false;
  3974. }
  3975. private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  3976. {
  3977. ContentControl img = sender as ContentControl;
  3978. if (img == null)
  3979. {
  3980. return;
  3981. }
  3982. if (mouseDown)
  3983. {
  3984. Domousemove(img, e);
  3985. }
  3986. }
  3987. /// <summary>
  3988. /// x y轴
  3989. /// </summary>
  3990. /// <param name="img"></param>
  3991. /// <param name="e"></param>
  3992. private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
  3993. {
  3994. if (e.LeftButton != MouseButtonState.Pressed)
  3995. {
  3996. return;
  3997. }
  3998. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  3999. {
  4000. return;
  4001. }
  4002. TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
  4003. TranslateTransform transform = group.Children[1] as TranslateTransform;
  4004. System.Windows.Point position = e.GetPosition(img);
  4005. transform.X -= mouseXY.X - position.X;
  4006. transform.Y -= mouseXY.Y - position.Y;
  4007. mouseXY = position;
  4008. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  4009. {
  4010. X = transform.X,
  4011. Y = transform.Y
  4012. };
  4013. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  4014. }
  4015. private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
  4016. {
  4017. ContentControl img = sender as ContentControl;
  4018. if (img == null)
  4019. {
  4020. return;
  4021. }
  4022. System.Windows.Point point = e.GetPosition(img);
  4023. //Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
  4024. System.Windows.Point PicLocate = e.GetPosition(imgCanvas);
  4025. //Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
  4026. TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
  4027. double delta = e.Delta * 0.001;
  4028. DowheelZoom(group, point, delta);
  4029. }
  4030. private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
  4031. {
  4032. System.Windows.Point pointToContent = group.Inverse.Transform(point);
  4033. ScaleTransform transform = group.Children[0] as ScaleTransform;
  4034. if (transform.ScaleX + delta < 0.1)
  4035. {
  4036. return;
  4037. }
  4038. transform.ScaleX += delta;
  4039. transform.ScaleY += delta;
  4040. TranslateTransform transform1 = group.Children[1] as TranslateTransform;
  4041. transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
  4042. transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
  4043. //LogHelper.WriteInfoLog("【img宽高】" + imgCanvas.ActualWidth.ToString() + ":"
  4044. // + imgCanvas.ActualHeight.ToString() + "百分比:" + transform.ScaleX.ToString() + ":" + transform.ScaleY.ToString()
  4045. // );
  4046. //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
  4047. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize = new ScaleTransform();
  4048. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX = transform.ScaleX;
  4049. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY = transform.ScaleY;
  4050. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  4051. {
  4052. X = transform1.X,
  4053. Y = transform1.Y
  4054. };
  4055. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  4056. {
  4057. CenterX = imgCanvas.ActualWidth,
  4058. CenterY = imgCanvas.ActualHeight
  4059. };
  4060. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  4061. }
  4062. #endregion
  4063. #region 点阵笔相关
  4064. #region 值初始化
  4065. // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
  4066. /// <summary>
  4067. /// A4点阵纸点阵宽度
  4068. /// </summary>
  4069. private const int A4_WIDTH = 5600;
  4070. /// <summary>
  4071. /// A4点阵纸点阵高度
  4072. /// </summary>
  4073. private const int A4_HEIGHT = 7920;
  4074. ///// <summary>
  4075. ///// 画板
  4076. ///// </summary>
  4077. //private Graphics graphics;
  4078. /// <summary>
  4079. /// 笔画坐标数组
  4080. /// </summary>
  4081. private List<System.Drawing.Point> stroke;
  4082. /// <summary>
  4083. /// 笔序列号
  4084. /// </summary>
  4085. private string penSerial;
  4086. /// <summary>
  4087. /// 笔是否在点
  4088. /// </summary>
  4089. private bool isPenDown;
  4090. //当前点阵地址
  4091. private string currentPageSerial = string.Empty;
  4092. //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
  4093. //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
  4094. private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
  4095. #endregion
  4096. public void InitPen()
  4097. {
  4098. stroke = new List<System.Drawing.Point>();
  4099. //获取点阵笔实例,并绑定点阵笔事件
  4100. //将授权文件内容传入,获取点阵笔对象实例
  4101. APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
  4102. //绑定笔连接事件
  4103. APP.digitalPen.PenConnected += OnPenConnect;
  4104. //绑定笔断开事件
  4105. APP.digitalPen.PenDisconnect += OnPenDisconnect;
  4106. //绑定笔书写输出坐标事件
  4107. APP.digitalPen.PenCoordinate += OnPenCoordinate;
  4108. //绑定抬笔事件
  4109. APP.digitalPen.PenUp += OnPenUp;
  4110. //绑定落笔事件
  4111. APP.digitalPen.PenDown += OnPenDown;
  4112. APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
  4113. APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
  4114. //完成初始化点阵笔,开始与点阵笔通信
  4115. ERROR_CODE ER = APP.digitalPen.Start();
  4116. ////绑定笔在新的点阵地址页面书写事件
  4117. //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
  4118. ////绑定笔信息事件
  4119. //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
  4120. //启动接收笔数据,完成初始化工作
  4121. ERROR_CODE rc = APP.digitalPen.Start();
  4122. //判断是否成功
  4123. if (ER != ERROR_CODE.ERROR_OK)
  4124. {
  4125. MessageWindow.Show("初始化失败,授权过期,返回值:" + ER.ToString());
  4126. }
  4127. }
  4128. /// <summary>
  4129. /// 落笔
  4130. /// </summary>
  4131. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4132. /// <param name="penSerial">点阵笔序列号</param>
  4133. /// <param name="penType">点阵笔型号编号</param>
  4134. private void OnPenDown(ulong time, string penSerial, int penType)
  4135. {
  4136. if (CheckAccess())
  4137. {
  4138. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
  4139. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  4140. }
  4141. else
  4142. {
  4143. //labPenSerial.Text = penSerial;
  4144. //labPenStatus.Text = "PenDown";
  4145. isPenDown = true;
  4146. //Dispatcher.Invoke(new Action(() =>
  4147. //{
  4148. // for (int i = 0; i < APP.PageDrawList.Count; i++)
  4149. // {
  4150. // if (APP.PageDrawList[i].PageCode == penSerial)
  4151. // {
  4152. // if (i < APP.pageData.pagenum)
  4153. // {
  4154. // if (i < APP.pageData.currpage)
  4155. // {
  4156. // int num = APP.pageData.currpage - i;
  4157. // APP.pageData.currpage -= num;
  4158. // myblackboard.changepage(APP.pageData.currpage - 1);
  4159. // if (APP.PageDrawList.Count > 0)
  4160. // {
  4161. // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  4162. // {
  4163. // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  4164. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  4165. // }
  4166. // else
  4167. // {
  4168. // imgCanvas.Source = null;
  4169. // }
  4170. // }
  4171. // }
  4172. // else
  4173. // {
  4174. // int num = i - APP.pageData.currpage;
  4175. // APP.pageData.currpage += num;
  4176. // myblackboard.changepage(APP.pageData.currpage - 1);
  4177. // if (APP.PageDrawList.Count > 0)
  4178. // {
  4179. // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  4180. // {
  4181. // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  4182. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  4183. // }
  4184. // else
  4185. // {
  4186. // imgCanvas.Source = null;
  4187. // }
  4188. // }
  4189. // }
  4190. // }
  4191. // return;
  4192. // }
  4193. // }
  4194. // //myblackboard.changepages(0, 0, true);
  4195. // //myblackboard.changepaget(0, 0, true, blackboard_canvas);
  4196. //}));
  4197. }
  4198. //myblackboard.changepages(0, 0, true);
  4199. }
  4200. /// <summary>
  4201. /// 抬笔
  4202. /// </summary>
  4203. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4204. /// <param name="penSerial">点阵笔序列号</param>
  4205. /// <param name="penType">点阵笔型号编号</param>
  4206. private void OnPenUp(ulong time, string penSerial, int penType)
  4207. {
  4208. if (CheckAccess())
  4209. {
  4210. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
  4211. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  4212. }
  4213. else
  4214. {
  4215. isPenDown = false;
  4216. APP.PenSerial = penSerial;
  4217. //int leftPoints = stroke.Count % 3;
  4218. //if (0 != leftPoints)
  4219. //{
  4220. // int from = stroke.Count - leftPoints - 1;
  4221. // if (from < 0)
  4222. // from = 0;
  4223. // int to = stroke.Count - 1;
  4224. // DrawCoordinates(from, to);
  4225. //}
  4226. stroke.Clear();
  4227. }
  4228. if (APP.pageData.currpage > 0)
  4229. {
  4230. Dispatcher.Invoke(new Action(() =>
  4231. {
  4232. myblackboard.changepages(0, 0, true, Color, PenSize, APP.pageData.currpage - 1);
  4233. }));
  4234. }
  4235. }
  4236. /// <summary>
  4237. /// 笔断开
  4238. /// </summary>
  4239. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4240. /// <param name="penSerial">点阵笔序列号</param>
  4241. /// <param name="penType">点阵笔型号编号</param>
  4242. private void OnPenDisconnect(ulong time, string penSerial, int penType)
  4243. {
  4244. if (CheckAccess())
  4245. {
  4246. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
  4247. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  4248. }
  4249. else
  4250. {
  4251. APP.PenSerial = penSerial;
  4252. APP.PenStatus = false;
  4253. Dispatcher.Invoke(new Action(() =>
  4254. {
  4255. txbNotConnected.Text = "未连接";
  4256. txbNotConnecteds.Text = "未连接";
  4257. }));
  4258. }
  4259. }
  4260. /// <summary>
  4261. /// 笔连接
  4262. /// </summary>
  4263. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4264. /// <param name="penSerial">点阵笔序列号</param>
  4265. /// <param name="penType">点阵笔型号编号</param>
  4266. private void OnPenConnect(ulong time, string penSerial, int penType)
  4267. {
  4268. if (CheckAccess())
  4269. {
  4270. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
  4271. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  4272. }
  4273. else
  4274. {
  4275. APP.PenSerial = penSerial;
  4276. APP.PenStatus = true;
  4277. this.penSerial = penSerial;
  4278. //连接后,在获取笔数据前,可以清除笔内的历史数据
  4279. //APP.digitalPen.ClearMemory(penSerial);
  4280. //开始接收笔数据
  4281. APP.digitalPen.GetPenData(penSerial);
  4282. Dispatcher.Invoke(new Action(() =>
  4283. {
  4284. txbNotConnected.Text = "已连接";
  4285. txbNotConnecteds.Text = "已连接";
  4286. }));
  4287. }
  4288. }
  4289. /// <summary>
  4290. /// 电池电量
  4291. /// </summary>
  4292. /// <param name="time"></param>
  4293. /// <param name="penSerial"></param>
  4294. /// <param name="penType"></param>
  4295. /// <param name="capacity"></param>
  4296. private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
  4297. {
  4298. if (CheckAccess())
  4299. {
  4300. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
  4301. Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
  4302. }
  4303. else
  4304. {
  4305. //System.Windows.MessageWindow.Show("电池电量:" + capacity.ToString());
  4306. }
  4307. }
  4308. /// <summary>
  4309. /// 已用存储
  4310. /// </summary>
  4311. /// <param name="time"></param>
  4312. /// <param name="penSerial"></param>
  4313. /// <param name="penType"></param>
  4314. /// <param name="fillLevel"></param>
  4315. private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
  4316. {
  4317. if (CheckAccess())
  4318. {
  4319. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
  4320. Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
  4321. }
  4322. else
  4323. {
  4324. //System.Windows.MessageWindow.Show("存储:" + fillLevel.ToString());
  4325. }
  4326. }
  4327. /// <summary>
  4328. /// 笔书写,收到坐标
  4329. /// </summary>
  4330. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4331. /// <param name="penSerial">点阵笔序列号</param>
  4332. /// <param name="penType">点阵笔型号编号</param>
  4333. /// <param name="pageSerial">点阵地址</param>
  4334. /// <param name="cx">x坐标</param>
  4335. /// <param name="cy">y坐标</param>
  4336. /// <param name="force">压力值</param>
  4337. private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
  4338. {
  4339. if (CheckAccess())
  4340. {
  4341. Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
  4342. Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
  4343. }
  4344. else
  4345. {
  4346. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  4347. if (!isPenDown)
  4348. {
  4349. return;
  4350. }
  4351. stroke.Add(new System.Drawing.Point(cx, cy));
  4352. double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
  4353. double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
  4354. //点
  4355. double testX = cx * PropW;
  4356. double testY = cy * PropH;
  4357. //pageSerial //点阵IP地址 与打印的页面关联
  4358. if (APP.pageData.currpage > 0)
  4359. {
  4360. Dispatcher.Invoke(new Action(() =>
  4361. {
  4362. //myblackboard.changepages(testX, testY,false);
  4363. myblackboard.changepages(testX, testY, false, Color, PenSize, APP.pageData.currpage - 1);
  4364. #region 设置滚动条位置
  4365. //点在显示页面上方
  4366. if (testY < scroMain.VerticalOffset)
  4367. {
  4368. //滚动条当前位置
  4369. double RollCurrentLocation = scroMain.VerticalOffset;
  4370. //向上滚动至以点为中心需要滚动的距离
  4371. double UpRoll = (RollCurrentLocation - testY) + (scroMain.ActualHeight / 2);
  4372. //如果小于0则等于0
  4373. double RollLocation = RollCurrentLocation - UpRoll;
  4374. if (RollLocation < 0)
  4375. {
  4376. RollLocation = 0;
  4377. }
  4378. ////滚动条实际偏移量
  4379. //double RollOffset = RollCurrentLocation - RollLocation;
  4380. scroMain.ScrollToVerticalOffset(RollLocation);
  4381. }
  4382. //点在显示页面下方
  4383. if (testY > scroMain.VerticalOffset + scroMain.ActualHeight)
  4384. {
  4385. //滚动条当前位置
  4386. double RollCurrentLocation = scroMain.VerticalOffset;
  4387. //向下滚动至以点为中心需要滚动的距离
  4388. double DownRoll = (testY - RollCurrentLocation) - (scroMain.ActualHeight / 2);
  4389. //如果小于0则等于0
  4390. double RollLocation = RollCurrentLocation + DownRoll;
  4391. //滚动条最大滚动值
  4392. double ScrollbarMaxNum = gridM.ActualHeight - scroMain.ActualHeight;
  4393. if (RollLocation > ScrollbarMaxNum)
  4394. {
  4395. RollLocation = ScrollbarMaxNum;
  4396. }
  4397. ////滚动条实际偏移量
  4398. //double RollOffset = RollLocation-RollCurrentLocation;
  4399. scroMain.ScrollToVerticalOffset(RollLocation);
  4400. }
  4401. #endregion
  4402. //gridM.Height //A4高度
  4403. //scroMain.VerticalOffset;//获取滚动条位置
  4404. //scroMain.ActualHeight//A4纸显示高度
  4405. //scroMain.ScrollToHorizontalOffset()//设置滚动条位置
  4406. //Mouse.GetPosition(this)
  4407. if (testX > 0 && testY > 0)
  4408. {
  4409. //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
  4410. System.Windows.Point getP = scroMain.PointToScreen(new System.Windows.Point(testX, testY - scroMain.VerticalOffset));
  4411. SetCursorPos((int)getP.X, (int)getP.Y);
  4412. }
  4413. }));
  4414. }
  4415. ////每3个点画一条曲线
  4416. //if (stroke.Count % 3 == 0)
  4417. //{
  4418. // int from = stroke.Count - 3 - 1;
  4419. // if (from < 0)
  4420. // from = 0;
  4421. // int to = stroke.Count - 1;
  4422. // DrawCoordinates(from, to);
  4423. //}
  4424. }
  4425. }
  4426. /// <summary>
  4427. /// 停止笔
  4428. /// </summary>
  4429. public void StopDigitalPen()
  4430. {
  4431. //停止,释放资源
  4432. APP.digitalPen.Stop();
  4433. }
  4434. /// <summary>
  4435. /// 清空笔内存储
  4436. /// </summary>
  4437. public void ClearPenStorage()
  4438. {
  4439. if (!string.IsNullOrEmpty(penSerial))
  4440. {
  4441. APP.digitalPen.ClearMemory(penSerial);
  4442. }
  4443. }
  4444. /// <summary>
  4445. /// 获取剩余电量
  4446. /// </summary>
  4447. public void GetPenElectricityQuantity()
  4448. {
  4449. if (!string.IsNullOrEmpty(penSerial))
  4450. {
  4451. APP.digitalPen.GetBatteryCapacity(penSerial);
  4452. }
  4453. }
  4454. /// <summary>
  4455. /// 获取存储空间
  4456. /// </summary>
  4457. public void GetUsedStorage()
  4458. {
  4459. if (!string.IsNullOrEmpty(penSerial))
  4460. {
  4461. APP.digitalPen.GetMemoryFillLevel(penSerial);
  4462. }
  4463. }
  4464. /// <summary>
  4465. /// 开启悬浮
  4466. /// </summary>
  4467. public void 开启悬浮()
  4468. {
  4469. if (!string.IsNullOrEmpty(penSerial))
  4470. {
  4471. APP.digitalPen.SetPenHoverMode(true, penSerial);
  4472. }
  4473. }
  4474. /// <summary>
  4475. /// 关闭悬浮
  4476. /// </summary>
  4477. public void 关闭悬浮()
  4478. {
  4479. if (!string.IsNullOrEmpty(penSerial))
  4480. {
  4481. APP.digitalPen.SetPenHoverMode(false, penSerial);
  4482. }
  4483. }
  4484. /// <summary>
  4485. /// 引用user32.dll动态链接库(windows api),
  4486. /// 使用库中定义 API:SetCursorPos
  4487. /// 设置光标位置
  4488. /// </summary>
  4489. [System.Runtime.InteropServices.DllImport("user32.dll")]
  4490. private static extern int SetCursorPos(int x, int y);
  4491. #endregion
  4492. #region 图片拉伸移动
  4493. private System.Windows.Point initialPoint;
  4494. /// <summary>
  4495. /// 隐藏图片四个点和线
  4496. /// </summary>
  4497. private void HideAngleBorder()
  4498. {
  4499. RectLeftUp.Visibility = Visibility.Hidden;
  4500. RectRightUp.Visibility = Visibility.Hidden;
  4501. RectLeftDown.Visibility = Visibility.Hidden;
  4502. RectRightDown.Visibility = Visibility.Hidden;
  4503. RectImgBorder.Visibility = Visibility.Hidden;
  4504. }
  4505. private void ShowAngleBorder()
  4506. {
  4507. PointLocation();
  4508. RectLeftUp.Visibility = Visibility.Visible;
  4509. RectRightUp.Visibility = Visibility.Visible;
  4510. RectLeftDown.Visibility = Visibility.Visible;
  4511. RectRightDown.Visibility = Visibility.Visible;
  4512. RectImgBorder.Visibility = Visibility.Visible;
  4513. }
  4514. /// <summary>
  4515. /// 确定四个点和边框的位置大小
  4516. /// </summary>
  4517. private void PointLocation()
  4518. {
  4519. RectImgBorder.Width = imgCanvas.ActualWidth + 10.0;
  4520. RectImgBorder.Height = imgCanvas.ActualHeight + 10.0;
  4521. RectImgBorder.Margin = new Thickness(imgCanvas.Margin.Left - 5.0, imgCanvas.Margin.Top - 5.0, 0, 0);
  4522. Canvas.SetLeft(RectLeftUp, imgCanvas.Margin.Left - 10.0);
  4523. Canvas.SetTop(RectLeftUp, imgCanvas.Margin.Top - 10.0);
  4524. Canvas.SetLeft(RectRightUp, imgCanvas.Margin.Left + imgCanvas.ActualWidth - 10.0);
  4525. Canvas.SetTop(RectRightUp, imgCanvas.Margin.Top - 10.0);
  4526. Canvas.SetLeft(RectLeftDown, imgCanvas.Margin.Left - 10.0);
  4527. Canvas.SetTop(RectLeftDown, imgCanvas.Margin.Top + imgCanvas.ActualHeight - 10.0);
  4528. Canvas.SetLeft(RectRightDown, imgCanvas.Margin.Left + imgCanvas.ActualWidth - 10.0);
  4529. Canvas.SetTop(RectRightDown, imgCanvas.Margin.Top + imgCanvas.ActualHeight - 10.0);
  4530. }
  4531. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  4532. {
  4533. System.Windows.Point point = e.GetPosition(imgCanvas);
  4534. initialPoint = point;
  4535. //Console.WriteLine("PicEmap.X = " + point.X + "; PicEmap.Y = " + point.Y);
  4536. //if ((point.X - 304) * (point.X - 304) + (point.Y - 86) * (point.Y - 86) < 100)
  4537. //{
  4538. // Console.WriteLine("在范围内");
  4539. //}
  4540. HideAngleBorder();
  4541. }
  4542. private void imgCanvas_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  4543. {
  4544. if (e.LeftButton == MouseButtonState.Pressed && mouseDown)
  4545. {
  4546. System.Windows.Point point = e.GetPosition(imgCanvas);
  4547. imgCanvas.Margin = new Thickness(imgCanvas.Margin.Left + (point.X - initialPoint.X), imgCanvas.Margin.Top + (point.Y - initialPoint.Y), 0, 0);
  4548. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  4549. {
  4550. X = imgCanvas.Margin.Left,
  4551. Y = imgCanvas.Margin.Top
  4552. };
  4553. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  4554. {
  4555. CenterX = imgCanvas.ActualWidth,
  4556. CenterY = imgCanvas.ActualHeight
  4557. };
  4558. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  4559. }
  4560. }
  4561. private void imgCanvas_MouseUp(object sender, MouseButtonEventArgs e)
  4562. {
  4563. if (mouseDown)
  4564. {
  4565. ShowAngleBorder();
  4566. }
  4567. }
  4568. private System.Drawing.PointF imgRightDown;
  4569. /// <summary>
  4570. /// 设置控件最上层
  4571. /// </summary>
  4572. /// <param name="element"></param>
  4573. public void BringToFront(Thumb element)//图片置于最顶层显示
  4574. {
  4575. if (element == null)
  4576. {
  4577. return;
  4578. }
  4579. Canvas parent = element.Parent as Canvas;
  4580. if (parent == null)
  4581. {
  4582. return;
  4583. }
  4584. int maxZ = parent.Children.OfType<UIElement>()//linq语句,取Zindex的最大值
  4585. .Where(x => x != element)
  4586. .Select(x => Canvas.GetZIndex(x))
  4587. .Max();
  4588. Canvas.SetZIndex(element, maxZ + 1);
  4589. }
  4590. private void RectRightUp_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
  4591. {
  4592. try
  4593. {
  4594. Thumb thu = (Thumb)sender;
  4595. BringToFront(thu);
  4596. imgRightDown = new System.Drawing.PointF((float)(imgCanvas.Margin.Left + imgCanvas.ActualWidth), (float)(imgCanvas.Margin.Top + imgCanvas.ActualHeight));
  4597. HideAngleBorder();
  4598. switch (thu.Name)
  4599. {
  4600. case "RectLeftUp":
  4601. RectLeftUp.Visibility = Visibility.Visible;
  4602. break;
  4603. case "RectRightUp":
  4604. RectRightUp.Visibility = Visibility.Visible;
  4605. break;
  4606. case "RectLeftDown":
  4607. RectLeftDown.Visibility = Visibility.Visible;
  4608. break;
  4609. case "RectRightDown":
  4610. RectRightDown.Visibility = Visibility.Visible;
  4611. break;
  4612. default:
  4613. break;
  4614. }
  4615. }
  4616. catch (Exception ex)
  4617. {
  4618. MessageWindow.Show(ex.Message);
  4619. }
  4620. }
  4621. private void RectRightUp_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
  4622. {
  4623. try
  4624. {
  4625. if (mouseDown)
  4626. {
  4627. Thumb thu = (Thumb)sender;
  4628. #region 判断是否超出 暂无
  4629. double plul = Canvas.GetLeft(RectLeftUp);
  4630. double plut = Canvas.GetTop(RectLeftUp);
  4631. double prdl = Canvas.GetLeft(RectRightDown);
  4632. double prdt = Canvas.GetTop(RectRightDown);
  4633. #endregion
  4634. //Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4635. //Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4636. double imgW = 0;
  4637. double imgH = 0;
  4638. double imgX = 0;
  4639. double imgY = 0;
  4640. switch (thu.Name)
  4641. {
  4642. case "RectLeftUp":
  4643. #region 左上
  4644. imgW = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  4645. imgH = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  4646. imgX = 0;
  4647. imgY = 0;
  4648. if (imgW < 50)
  4649. {
  4650. imgCanvas.Width = 50;
  4651. imgX = imgCanvas.Margin.Left;
  4652. Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
  4653. }
  4654. else
  4655. {
  4656. imgCanvas.Width = imgW;
  4657. imgX = Mouse.GetPosition(gridM).X;
  4658. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4659. }
  4660. if (imgH < 50)
  4661. {
  4662. imgCanvas.Height = 50;
  4663. imgY = imgCanvas.Margin.Top;
  4664. Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
  4665. }
  4666. else
  4667. {
  4668. imgCanvas.Height = imgH;
  4669. imgY = Mouse.GetPosition(gridM).Y;
  4670. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4671. }
  4672. imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  4673. #endregion
  4674. //imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  4675. //imgCanvas.Height = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  4676. //imgCanvas.Margin = new Thickness(Mouse.GetPosition(gridM).X, Mouse.GetPosition(gridM).Y, 0, 0);
  4677. break;
  4678. case "RectRightUp":
  4679. #region 右上
  4680. imgW = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
  4681. imgH = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  4682. imgX = 0;
  4683. imgY = 0;
  4684. if (imgW < 50)
  4685. {
  4686. imgCanvas.Width = 50;
  4687. imgX = imgCanvas.Margin.Left;
  4688. Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
  4689. }
  4690. else
  4691. {
  4692. imgCanvas.Width = imgW;
  4693. imgX = imgCanvas.Margin.Left;
  4694. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4695. }
  4696. if (imgH < 50)
  4697. {
  4698. imgCanvas.Height = 50;
  4699. imgY = imgCanvas.Margin.Top;
  4700. Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
  4701. }
  4702. else
  4703. {
  4704. imgCanvas.Height = imgH;
  4705. imgY = Mouse.GetPosition(gridM).Y;
  4706. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4707. }
  4708. imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  4709. //imgCanvas.Width = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
  4710. //imgCanvas.Height = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  4711. //imgCanvas.Margin = new Thickness(imgCanvas.Margin.Left, Mouse.GetPosition(gridM).Y, 0, 0);
  4712. #endregion
  4713. break;
  4714. case "RectLeftDown":
  4715. #region 左下
  4716. imgW = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  4717. imgH = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
  4718. imgX = 0;
  4719. imgY = 0;
  4720. if (imgW < 50)
  4721. {
  4722. imgCanvas.Width = 50;
  4723. imgX = imgCanvas.Margin.Left;
  4724. Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
  4725. }
  4726. else
  4727. {
  4728. imgCanvas.Width = imgW;
  4729. imgX = Mouse.GetPosition(gridM).X;
  4730. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4731. }
  4732. if (imgH < 50)
  4733. {
  4734. imgCanvas.Height = 50;
  4735. imgY = imgCanvas.Margin.Top;
  4736. Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
  4737. }
  4738. else
  4739. {
  4740. imgCanvas.Height = imgH;
  4741. imgY = imgCanvas.Margin.Top;
  4742. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4743. }
  4744. imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  4745. //imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  4746. //imgCanvas.Height = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
  4747. //imgCanvas.Margin = new Thickness(Mouse.GetPosition(gridM).X, imgCanvas.Margin.Top, 0, 0);
  4748. #endregion
  4749. break;
  4750. case "RectRightDown":
  4751. #region 右下
  4752. imgW = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
  4753. imgH = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
  4754. if (imgW < 50)
  4755. {
  4756. imgCanvas.Width = 50;
  4757. Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
  4758. }
  4759. else
  4760. {
  4761. imgCanvas.Width = imgW;
  4762. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4763. }
  4764. if (imgH < 50)
  4765. {
  4766. imgCanvas.Height = 50;
  4767. Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
  4768. }
  4769. else
  4770. {
  4771. imgCanvas.Height = imgH;
  4772. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4773. }
  4774. //imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  4775. //imgCanvas.Width += e.HorizontalChange;
  4776. //imgCanvas.Height += e.VerticalChange;
  4777. #endregion
  4778. break;
  4779. default:
  4780. break;
  4781. }
  4782. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  4783. {
  4784. X = imgCanvas.Margin.Left,
  4785. Y = imgCanvas.Margin.Top
  4786. };
  4787. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  4788. {
  4789. CenterX = imgCanvas.ActualWidth,
  4790. CenterY = imgCanvas.ActualHeight
  4791. };
  4792. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  4793. }
  4794. //lbl1.Content = imgCanvas.Margin.Left + "," + imgCanvas.Margin.Top;
  4795. //lbl2.Content = (imgCanvas.Margin.Left+ imgCanvas.Width) +"," + imgCanvas.Margin.Top;
  4796. //lbl3.Content = imgCanvas.Margin.Left + "," + (imgCanvas.Margin.Top+ imgCanvas.Height);
  4797. //lbl4.Content= (imgCanvas.Margin.Left + imgCanvas.Width )+ "," + (imgCanvas.Margin.Top + imgCanvas.Height);
  4798. }
  4799. catch (Exception)
  4800. {
  4801. MessageWindow.Show("图片过小!");
  4802. }
  4803. }
  4804. private void RectRightUp_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
  4805. {
  4806. ShowAngleBorder();
  4807. }
  4808. /// <summary>
  4809. /// 点击标题栏 隐藏截图的四个点和线
  4810. /// </summary>
  4811. /// <param name="sender"></param>
  4812. /// <param name="e"></param>
  4813. private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
  4814. {
  4815. HideAngleBorder();
  4816. }
  4817. /// <summary>
  4818. /// 鼠标左键点击事件
  4819. /// </summary>
  4820. /// <param name="sender"></param>
  4821. /// <param name="e"></param>
  4822. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  4823. {
  4824. if (RectImgBorder.Visibility != Visibility.Hidden)
  4825. {
  4826. HideAngleBorder();
  4827. }
  4828. }
  4829. #endregion
  4830. #region 方法
  4831. /// <summary>
  4832. /// 录屏 录制 截图 导入文档 增加 主页面显示
  4833. /// </summary>
  4834. private void Record()
  4835. {
  4836. GridMain.Visibility = Visibility.Visible;
  4837. gridSetUp.Visibility = Visibility.Collapsed;
  4838. //gridUpload.Visibility = Visibility.Collapsed;
  4839. GridMyVideo.Visibility = Visibility.Collapsed;
  4840. if (APP.pageData.pagenum > 0)
  4841. {
  4842. gridPage.Visibility = Visibility.Visible;
  4843. }
  4844. DataContext = APP.pageData;
  4845. }
  4846. /// <summary>
  4847. /// 设置页面显示
  4848. /// </summary>
  4849. private void SetUp()
  4850. {
  4851. }
  4852. #endregion
  4853. #region 跳转
  4854. /// <summary>
  4855. /// 跳转
  4856. /// </summary>
  4857. /// <param name="sender"></param>
  4858. /// <param name="e"></param>
  4859. private void CbxPageList_SelectionChanged(object sender, SelectionChangedEventArgs e)
  4860. {
  4861. #region 安全
  4862. if(CbxPageList.SelectedValue==null)
  4863. {
  4864. return;
  4865. }
  4866. if (APP.pageData.currpage == int.Parse(CbxPageList.SelectedValue.ToString()))
  4867. {
  4868. return;
  4869. }
  4870. #endregion
  4871. int JumpPage = 0;
  4872. try
  4873. {
  4874. JumpPage = int.Parse(CbxPageList.SelectedValue.ToString());
  4875. }
  4876. catch (Exception)
  4877. {
  4878. MessageWindow.Show("操作有误!请输入有效的页码!");
  4879. return;
  4880. }
  4881. if (JumpPage < 1)
  4882. {
  4883. JumpPage = 1;
  4884. }
  4885. if (JumpPage > int.Parse(txbTotalpage.Text))
  4886. {
  4887. JumpPage = int.Parse(txbTotalpage.Text);
  4888. }
  4889. #region 跳转
  4890. APP.pageData.currpage = JumpPage;
  4891. JumpPageClick();
  4892. #endregion
  4893. }
  4894. #endregion
  4895. #region 原跳转
  4896. /// <summary>
  4897. /// 跳转页
  4898. /// </summary>
  4899. /// <param name="sender"></param>
  4900. /// <param name="e"></param>
  4901. private void txbCurrpage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  4902. {
  4903. if (e.ClickCount == 2)
  4904. {
  4905. try
  4906. {
  4907. if (int.Parse(txbCurrpage.Text) > 0)
  4908. {
  4909. //txtJump.Text = txbCurrpage.Text;
  4910. //txbCurrpage.Visibility = Visibility.Hidden;
  4911. //txtJump.Visibility = Visibility.Visible;
  4912. //BtnJumpPage.Visibility = Visibility.Visible;
  4913. //txtJump.Focus();
  4914. //txtJump.SelectAll();
  4915. }
  4916. }
  4917. catch (Exception)
  4918. {
  4919. }
  4920. }
  4921. }
  4922. /// <summary>
  4923. /// 确定跳转
  4924. /// </summary>
  4925. /// <param name="sender"></param>
  4926. /// <param name="e"></param>
  4927. private void BtnJumpPage_Click(object sender, RoutedEventArgs e)
  4928. {
  4929. int JumpPage = 0;
  4930. //try
  4931. //{
  4932. // JumpPage = int.Parse(txtJump.Text);
  4933. //}
  4934. //catch (Exception ex)
  4935. //{
  4936. // MessageWindow.Show("操作有误!请输入有效的页码!");
  4937. // return;
  4938. //}
  4939. if (JumpPage < 1)
  4940. {
  4941. JumpPage = 1;
  4942. }
  4943. if (JumpPage > int.Parse(txbTotalpage.Text))
  4944. {
  4945. JumpPage = int.Parse(txbTotalpage.Text);
  4946. }
  4947. #region 跳转
  4948. APP.pageData.currpage = JumpPage;
  4949. JumpPageClick();
  4950. #endregion
  4951. //txbCurrpage.Visibility = Visibility.Visible;
  4952. //txtJump.Visibility = Visibility.Hidden;
  4953. //BtnJumpPage.Visibility = Visibility.Hidden;
  4954. }
  4955. /// <summary>
  4956. /// 只允许输入数字
  4957. /// </summary>
  4958. /// <param name="sender"></param>
  4959. /// <param name="e"></param>
  4960. private void txtJump_PreviewTextInput(object sender, TextCompositionEventArgs e)
  4961. {
  4962. Regex re = new Regex("[^0-9.-]+");
  4963. e.Handled = re.IsMatch(e.Text);
  4964. }
  4965. private void txtJump_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  4966. {
  4967. if (e.Key == Key.Enter)
  4968. {
  4969. BtnJumpPage_Click(null, null);
  4970. }
  4971. }
  4972. #endregion
  4973. }
  4974. public class PageData
  4975. {
  4976. public int PageCode { get; set; }
  4977. public string PageName { get; set; }
  4978. }
  4979. }