星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

XHMicroLessonSystemWindow.xaml.cs 217KB

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