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

XHMicroLessonSystemWindow.xaml.cs 201KB

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