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

XHMicroLessonSystemWindow.xaml.cs 225KB

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