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

XHMicroLessonSystemWindow.xaml.cs 202KB

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