星火微课系统客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

XHMicroLessonSystemWindow.xaml.cs 224KB

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