星火微课系统客户端
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

XHMicroLessonSystemWindow.xaml.cs 221KB

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