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

XHMicroLessonSystemWindow.xaml.cs 232KB

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