1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953 |
- using Accord.Video.FFMPEG;
-
- using Aspose.Slides;
-
- using ComeCapture;
-
- using Common.system;
-
- using NAudio.Wave;
-
- using NReco.VideoConverter;
-
- using RobotpenGateway;
-
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
-
- //using System.Windows.Forms;
- using System.Windows.Ink;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Threading;
-
- using TmatrixLibrary;
-
- using TStudyDigitalPen.HID;
-
- using XHWK.Model;
- using XHWK.WKTool.Models;
- using XHWK.WKTool.Skin;
- using XHWK.WKTool.UControl;
- using XHWK.WKTool.Utils;
-
- namespace XHWK.WKTool
- {
- /// <summary>
- /// 主页面
- /// </summary>
- public partial class XHMicroLessonSystemWindow : Window
- {
- #region 字段
-
- /// <summary>
- /// 页码下拉列表
- /// </summary>
- private List<PageData> PageData = null;
-
- private System.Windows.Forms.FolderBrowserDialog Ofd;
- private System.Windows.Forms.DialogResult Result;
- public BlackboardNew myblackboard;
- private System.Windows.Forms.DialogResult result;
- private System.Windows.Forms.OpenFileDialog ofd;
-
- //声明一个 DrawingAttributes 类型的变量
- private DrawingAttributes drawingAttributes;
-
- private Model_Video VideoInfo = null;
-
- ////定义事件
- //public event ChangeTextHandler ChangeTextEvent;
- //定义委托
- public delegate void ChangeTextHandler(string text);
-
- //定义委托
- public delegate void ChangeTextHandlers(string text, int i);
-
- /// <summary>
- /// 图片
- /// </summary>
- private string[] ImgPDFPath = new string[300];
-
- /// <summary>
- /// 当前颜色
- /// </summary>
- private System.Windows.Media.Color Color = Colors.Red;
-
- /// <summary>
- /// 笔迹粗细
- /// </summary>
- private int PenSize = 2;
-
- //private DispatcherTimer t = null;
- /// <summary>
- /// 计时器状态
- /// </summary>
- private enum State
- {
- Start,
- Pause,
- End
- }
-
- #region 上传
-
- /// <summary>
- /// 视频模型
- /// </summary>
- private List<Model_Video> model_VideoList = null;
-
- /// <summary>
- /// 数据列表
- /// </summary>
- internal FileDirectoryData pageData = new FileDirectoryData();
-
- /// <summary>
- /// 下标
- /// </summary>
- private int Subscript = 0;
-
- /// <summary>
- /// 是否是修改状态
- /// </summary>
- private bool IsModify = false;
-
- #endregion 上传
-
- /// <summary>
- /// 键盘钩子
- /// </summary>
- private KeyboardHookCommon k_hook;
-
- #endregion 字段
-
- #region 初始化
-
- /// <summary>
- /// 主页面
- /// </summary>
- public XHMicroLessonSystemWindow()
- {
- InitializeComponent();
-
-
- #region 调整文字大小
-
- APP.PageContextData.WordSize20 = 20.00;
- APP.PageContextData.WordSize18 = 18.00;
- APP.PageContextData.WordSize16 = 16.00;
- APP.PageContextData.WordSize14 = 14.00;
- APP.PageContextData.WordSize12 = 12.00;
-
- #endregion 调整文字大小
-
- ResizeMode = ResizeMode.CanMinimize;
- BtnPrint.IsEnabled = false;
-
- myblackboard = new BlackboardNew(blackboard_canvas);
- APP.PageContextData.pagenum = 0;
- APP.PageContextData.currpage = 0;
- DataContext = APP.PageContextData;
-
- //APP.SaveDraw();//画板模型第一页初始化
- APP.PageDrawList = new List<Model_DrawData>();
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageNum = APP.PageContextData.currpage
- };
- APP.PageDrawList.Add(model_DrawData);
- txbv.Text = "v" + FileToolsCommon.GetConfigValue("VersionName");
- txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoType");
-
- txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoSavePath");
- Initialize();
- //拓思德
- //InitPen();
- //罗博手写板
- InitlbPen();
- //腾千里
- InitTQLPPen();
- InitPrint();
-
- SkinSelectInit();
- byte[] license = Convert.FromBase64String("PExpY2Vuc2U+CiAgPERhdGE+CiAgICA8TGljZW5zZWRUbz5TdXpob3UgQXVuYm94IFNvZnR3YXJlIENvLiwgTHRkLjwvTGljZW5zZWRUbz4KICAgIDxFbWFpbFRvPnNhbGVzQGF1bnRlYy5jb208L0VtYWlsVG8+CiAgICA8TGljZW5zZVR5cGU+RGV2ZWxvcGVyIE9FTTwvTGljZW5zZVR5cGU+CiAgICA8TGljZW5zZU5vdGU+TGltaXRlZCB0byAxIGRldmVsb3BlciwgdW5saW1pdGVkIHBoeXNpY2FsIGxvY2F0aW9uczwvTGljZW5zZU5vdGU+CiAgICA8T3JkZXJJRD4xOTA4MjYwODA3NTM8L09yZGVySUQ+CiAgICA8VXNlcklEPjEzNDk3NjAwNjwvVXNlcklEPgogICAgPE9FTT5UaGlzIGlzIGEgcmVkaXN0cmlidXRhYmxlIGxpY2Vuc2U8L09FTT4KICAgIDxQcm9kdWN0cz4KICAgICAgPFByb2R1Y3Q+QXNwb3NlLlRvdGFsIGZvciAuTkVUPC9Qcm9kdWN0PgogICAgPC9Qcm9kdWN0cz4KICAgIDxFZGl0aW9uVHlwZT5FbnRlcnByaXNlPC9FZGl0aW9uVHlwZT4KICAgIDxTZXJpYWxOdW1iZXI+M2U0NGRlMzAtZmNkMi00MTA2LWIzNWQtNDZjNmEzNzE1ZmMyPC9TZXJpYWxOdW1iZXI+CiAgICA8U3Vic2NyaXB0aW9uRXhwaXJ5PjIwMjAwODI3PC9TdWJzY3JpcHRpb25FeHBpcnk+CiAgICA8TGljZW5zZVZlcnNpb24+My4wPC9MaWNlbnNlVmVyc2lvbj4KICAgIDxMaWNlbnNlSW5zdHJ1Y3Rpb25zPmh0dHBzOi8vcHVyY2hhc2UuYXNwb3NlLmNvbS9wb2xpY2llcy91c2UtbGljZW5zZTwvTGljZW5zZUluc3RydWN0aW9ucz4KICA8L0RhdGE+CiAgPFNpZ25hdHVyZT53UGJtNUt3ZTYvRFZXWFNIY1o4d2FiVEFQQXlSR0pEOGI3L00zVkV4YWZpQnd5U2h3YWtrNGI5N2c2eGtnTjhtbUFGY3J0c0cwd1ZDcnp6MytVYk9iQjRYUndTZWxsTFdXeXNDL0haTDNpN01SMC9jZUFxaVZFOU0rWndOQkR4RnlRbE9uYTFQajhQMzhzR1grQ3ZsemJLZFZPZXk1S3A2dDN5c0dqYWtaL1E9PC9TaWduYXR1cmU+CjwvTGljZW5zZT4=");
- new Aspose.Words.License().SetLicense(new MemoryStream(license));
- new Aspose.Pdf.License().SetLicense(new MemoryStream(license));
- new Aspose.Slides.License().SetLicense(new MemoryStream(license));
- }
-
- /// <summary>
- /// 初始化
- /// </summary>
- public void Initialize()
- {
- if (APP.isDebug)
- {
- txbVersion.Text = "测试版:";
- }
- else
- {
- txbVersion.Text = "正式版:";
- }
-
- #region 数据初始化
-
- string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- FileToolsCommon.CreateDirectory(pathTemp);
- APP.PageContextData.pagenum = 0;
- APP.PageContextData.currpage = APP.PageContextData.pagenum;
- BtnStop.IsEnabled = false;//停止录制按钮不可点击
-
- #endregion 数据初始化
-
- k_hook = new KeyboardHookCommon();
- k_hook.KeyDownEvent += K_hook_KeyDownEvent;
- k_hook.Start();//安装键盘钩子
-
- APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
- //创建 DrawingAttributes 类的一个实例
- drawingAttributes = new DrawingAttributes();
- //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
- //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
- blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
- blackboard_canvas.UseCustomCursor = true;
- drawingAttributes.FitToCurve = true;
- drawingAttributes.IgnorePressure = false;
- drawingAttributes.Width = PenSize;
- drawingAttributes.Height = PenSize;
- drawingAttributes.Color = Color;
- blackboard_canvas.Cursor = Cursors.Pen;
- //wfhCamera.Visibility = Visibility.Hidden;
- ImgPDFPath = null;
- ImgPDFPath = new string[300];
- }
-
- /// <summary>
- /// 初始化快捷键
- /// </summary>
- public void InitializeKeyDownEvent()
- {
- k_hook.Start();//安装键盘钩子
- }
-
- /// <summary>
- /// 快捷键
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
- {
- if (e.KeyValue == (int)System.Windows.Forms.Keys.Left)
- {
- if (APP.PageContextData.currpage > 1)
- {
- //上一页
- last_button_Click(null, null);
- }
- }
- if (e.KeyValue == (int)System.Windows.Forms.Keys.Right)
- {
- if (APP.PageContextData.currpage < APP.PageContextData.pagenum)
- {
- //下一页
- next_btn_Click(null, null);
- }
- }
- if (e.KeyValue == (int)System.Windows.Forms.Keys.Delete)
- {
- if (RectImgBorder.Visibility != Visibility.Hidden)
- {
- HideAngleBorder();
- imgCanvas.Source = null;
- APP.PageDrawList[APP.PageContextData.currpage - 1].PdfImagePath = null;
- APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath = null;
- }
- }
- }
-
- /// <summary>
- /// 加载完成后调整录制区域大小
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- //调整录制区域宽高
- double proportion = 210.0 / 297.0;
- GridM.Height = GridM.ActualWidth / proportion;
- }
-
- #endregion 初始化
-
- #region 事件
-
- /// <summary>
- /// 窗体移动
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- DragMove();
- }
-
- private void PageHide()
- {
- //设置
- gridSetUp.Visibility = Visibility.Collapsed;
- ////页码
- //GridPage.Visibility = Visibility.Collapsed;
- //我的
- GridMyVideo.Visibility = Visibility.Collapsed;
- //首页
- GridMain.Visibility = Visibility.Collapsed;
- GridM.IsEnabled = true;
- //打印
- GridPrintContent.Visibility = Visibility.Collapsed;
- //标题 录制
- GridRecordingTitle.Visibility = Visibility.Collapsed;
- //标题 打印
- GridPrintingTitle.Visibility = Visibility.Collapsed;
- }
-
- #region 摄像头
-
- private System.Timers.Timer times;
- private List<string> RbnOpen;
- private bool IsRbnOpen = false;
-
- /// <summary>
- /// 摄像头打开事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void RbnOpen_Click(object sender, RoutedEventArgs e)
- {
- if (!IsRbnOpen)
- {
- #region 防止连击
-
- if (IsPressButton)
- {
- return;
- }
- else
- {
- IsPressButton = true;
- new Thread(new ThreadStart(new Action(() =>
- {
- //Dispatcher.Invoke(new Action(() => { rbnTurnOff.IsEnabled = false; }));
-
- Thread.Sleep(500);
- //Dispatcher.Invoke(new Action(() => { rbnTurnOff.IsEnabled = true; }));
-
- IsPressButton = false;
- }))).Start();
- }
-
- #endregion 防止连击
-
- CameraHelper.UpdateCameraDevices();
- if (CameraHelper.CameraDevices.Count > 0)
- {
- int CameraIndex = 0;
- for (int i = 0; i < CameraHelper.CameraDevices.Count; i++)
- {
- if (CameraHelper.CameraDevices[i].MonikerString == APP.CameraName)
- {
- CameraIndex = i;
- }
- }
- CameraHelper.SetCameraDevice(CameraIndex);
- RbnOpen = new List<string>();
- times = new System.Timers.Timer(200)//初始值为300
- {
- AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
- };//设置执行一次(false)还是一直执行(true)
- times.Elapsed += new System.Timers.ElapsedEventHandler(Times_Elapsed);
- times.Enabled = true; //启动计时器
-
- IsRbnOpen = true;
-
- string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
- FileToolsCommon.CreateDirectory(imgPath);
- }
- }
- }
-
- private int I = 9999;
-
- private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- if (IsRbnOpen)
- {
- try
- {
- Dispatcher.Invoke(() =>
- {
- if (I > 10010)
- {
- long time = Timestamp();
- string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
- //string FilePathName = ImgPath + RsImgName.Count + ".png";
- string path = CameraHelper.CaptureImage(imgPath, time.ToString());
- if (!string.IsNullOrWhiteSpace(path))
- {
- RbnOpen.Add(path);
- imgPlayerRight.Visibility = Visibility.Visible;
- /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
- if ("1".Equals(APP.CameraPosition))
- {
- imgPlayerRight.Visibility = Visibility.Visible;
- imgPlayerLeft.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
- imgPlayerRight.Source = new BitmapImage(new Uri(path));
- }
- else if ("2".Equals(APP.CameraPosition))
- {
- imgPlayerRight.Visibility = Visibility.Collapsed;
- imgPlayerLeft.Visibility = Visibility.Visible;
- imgPlayerRightUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeft.Source = new BitmapImage(new Uri(path));
- }
- else if ("3".Equals(APP.CameraPosition))
- {
- imgPlayerRight.Visibility = Visibility.Collapsed;
- imgPlayerLeft.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Visibility = Visibility.Visible;
- imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Source = new BitmapImage(new Uri(path));
- }
- else if ("4".Equals(APP.CameraPosition))
- {
- imgPlayerRight.Visibility = Visibility.Collapsed;
- imgPlayerLeft.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeftUnder.Visibility = Visibility.Visible;
- imgPlayerLeftUnder.Source = new BitmapImage(new Uri(path));
- }
- else
- {
- imgPlayerLeft.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
- imgPlayerRight.Source = new BitmapImage(new Uri(path));
- }
- }
- }
- I++;
- });
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
- }
- }
- }
-
- /// <summary>
- /// 摄像头关闭事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
- {
- if (IsRbnOpen)
- {
- #region 防止连击
-
- if (IsPressButton)
- {
- return;
- }
- else
- {
- IsPressButton = true;
- new Thread(new ThreadStart(new Action(() =>
- {
- //Dispatcher.Invoke(new Action(() => { rbnOpen.IsEnabled = false; }));
-
- Thread.Sleep(500);
- //Dispatcher.Invoke(new Action(() => { rbnOpen.IsEnabled = true; }));
-
- IsPressButton = false;
- }))).Start();
- }
-
- #endregion 防止连击
-
- IsRbnOpen = false;
- imgPlayerRight.Visibility = Visibility.Collapsed;
- imgPlayerLeft.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
- CameraHelper.CloseDevice();
- I = 9999;
- }
- }
-
- #endregion 摄像头
-
- /// <summary>
- /// 关闭事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnClose_Click(object sender, RoutedEventArgs e)
- {
- if (RecordType == 0)
- {
- try
- {
- MessageBoxResult br = MessageWindow.Show("确定退出系统?", "退出", MessageBoxButton.OKCancel);
- if (br == MessageBoxResult.OK)
- {
- try
- {
- APP.Killffmpeg();
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("获取进程失败," + ex.Message, ex);
- }
- APP.SaveWkData();
- APP.SaveDraw();
-
- TMC.TmatrixUninitialize();
- Environment.Exit(0);
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("关闭微课失败," + ex.Message, ex);
- Close();
- Application.Current.Shutdown();
- TMC.TmatrixUninitialize();
- Environment.Exit(0);
- }
- }
- else
- {
- MessageWindow.Show("当前正在录制,请先停止录制。");
- return;
- }
- }
-
- /// <summary>
- /// 增加事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnAdd_Click(object sender, RoutedEventArgs e)
- {
- Record();
- if (APP.PageContextData.currpage > 0)
- {
- APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = true;
- }
- if (blackboard_canvas.Visibility == Visibility.Collapsed)
- {
- blackboard_canvas.Visibility = Visibility.Visible;
- }
- APP.PageContextData.pagenum += 1;
- HideAngleBorder();
- GridPage.Visibility = Visibility.Visible;//页码大于0 显示
- APP.PageContextData.currpage = APP.PageContextData.pagenum;
- myblackboard.changepage(APP.PageContextData.currpage - 1);
- ScroMain.ScrollToVerticalOffset(0);
- ///清空页面图片UI
- imgCanvas.Source = null;
- imgDocumentation.Source = null;
- imgPPT.Source = null;
- if (APP.PageContextData.pagenum == 1)
- {
- APP.PageDrawList = new List<Model_DrawData>();
- }
- ///画板模型增加一页
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageNum = APP.PageContextData.currpage
- };
- APP.PageDrawList.Add(model_DrawData);
- if (RecordType == 0)
- {
- BtnPrint.IsEnabled = true;
- }
- //APP.SaveDraw();
- if (BtnImport.IsEnabled)
- {
- ///截图可用
- BtnScreenshot.IsEnabled = true;
- }
-
- #region 插入页码
-
- PageData = new List<PageData>();
- for (int i = 1; i <= APP.PageContextData.pagenum; i++)
- {
- PageData pd = new PageData();
- pd.PageName = i.ToString();// + "页";
- pd.PageCode = i;
- PageData.Add(pd);
- }
- CbxPageList.ItemsSource = PageData;
- CbxPageList.SelectedIndex = APP.PageContextData.currpage - 1;
-
- #endregion 插入页码
- }
-
- /// <summary>
- /// 打印事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnPrint_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- //3种情况 1.文档图片 2.截图图片 3.没有图片
- if (APP.PageDrawList.Count == 0)
- {
- MessageWindow.Show("没有可打印的页,您可以通过加页、截图或导入来增加页!");
- return;
- }
- }
- catch (Exception ex)
- {
- MessageWindow.Show(ex.Message);
- Console.WriteLine("转换失败,原因:" + ex.Message);
- }
- if (GridPrintingTitle.Visibility == Visibility.Visible)
- {
- GridPrintingTitle.Visibility = Visibility.Collapsed;
- }
- else
- {
- GridPrintingTitle.Visibility = Visibility.Visible;
- if (APP.PageDrawList.Count > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[0].PageImagePath))
- {
- InitializePrint(APP.PageDrawList[0].PageImagePath, GridM.ActualWidth, GridM.ActualHeight);
- }
- else
- {
- InitializePrint("", GridM.ActualWidth, gridActHeight);
- }
- }
- }
-
- /// <summary>
- /// 最小化
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnShrink_Click(object sender, RoutedEventArgs e)
- {
- if (WindowState == WindowState.Minimized)
- {
- WindowState = WindowState.Normal;
- }
- else
- {
- WindowState = WindowState.Minimized;
- }
- }
-
- #endregion 事件
-
- #region 设置
-
- /// <summary>
- /// 设置事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnSetUp_Click(object sender, RoutedEventArgs e)
- {
- if (gridSetUp.Visibility == Visibility.Collapsed)
- {
- PageHide();
- gridSetUp.Visibility = Visibility.Visible;
- txbStoragePath.Content = APP.WKData.WkPath;
-
- #region 读取用户配置
-
- #region 请求地址 废弃 --2021年7月9日赵耀
-
- ////接口地址
- //if (!File.Exists(APP.DataPath + "interfaceAddress.txt")) //若为空
- //{
- // txbInterfaceAddress.Text = APP.apiUrl.Replace("http://", "").Trim();
- //}
- //else
- //{
- // txbInterfaceAddress.Text = System.IO.File.ReadAllText(APP.DataPath + "interfaceAddress.txt", Encoding.Default).Replace("http://", "").Trim();
- //}
- ////上传地址
- //if (!File.Exists(APP.DataPath + "imageUploadAddress.txt")) //若为空
- //{
- // txbImageUploadAddress.Text = APP.uploadUrl.Replace("http://", "").Replace("/", "").Trim();
- //}
- //else
- //{
- // txbImageUploadAddress.Text = System.IO.File.ReadAllText(APP.DataPath + "imageUploadAddress.txt", Encoding.Default).Replace("http://", "").Replace("/", "").Trim();
- //}
- ////下载地址
- //if (!File.Exists(APP.DataPath + "pictureShowsAddress.txt")) //若为空
- //{
- // txbPictureShowsAddress.Text = APP.showImageUrl.Replace("http://", "").Replace("/static", "").Replace("/", "").Trim();
- //}
- //else
- //{
- // txbPictureShowsAddress.Text = System.IO.File.ReadAllText(APP.DataPath + "pictureShowsAddress.txt", Encoding.Default).Replace("http://", "").Replace("/static", "").Replace("/", "").Trim();
- //}
-
- #endregion 请求地址 废弃 --2021年7月9日赵耀
-
- /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
- if ("1".Equals(APP.CameraPosition))
- {
- rbnRight.IsChecked = true;
- }
- else if ("2".Equals(APP.CameraPosition))
- {
- rbnLeft.IsChecked = true;
- }
- else if ("3".Equals(APP.CameraPosition))
- {
- rbnRightUnder.IsChecked = true;
- }
- else if ("4".Equals(APP.CameraPosition))
- {
- rbnLeftUnder.IsChecked = true;
- }
- string type = FileToolsCommon.GetConfigValue("VideoType");//<!--视频格式 1、MP4 2、FlV 3、AVI-->
- if ("1".Equals(type))
- {
- rbnMP4.IsChecked = true;
- }
- else if ("2".Equals(type))
- {
- rbnFLV.IsChecked = true;
- }
- else if ("3".Equals(type))
- {
- rbnAVI.IsChecked = true;
- }
-
- string isHide = FileToolsCommon.GetConfigValue("IsHideSRTool"); //工具栏是否隐藏
- if (isHide.Equals("1"))
- {
- rbnHide.IsChecked = true;
- }
- else
- {
- rbnvisi.IsChecked = true;
- }
- //string isSound = FileToolsCommon.GetConfigValue("IsSound");//<!--声音 true 有 false 无-->
- //if (isSound == "true")
- //{
- // rbnY.IsChecked = true;
- //}
- //else
- //{
- // rbnN.IsChecked = true;
- //}
- //加载皮肤按钮
- SkinSelectInit();
-
- #endregion 读取用户配置
- }
- else
- {
- GridMain.Visibility = Visibility.Visible;
- GridM.IsEnabled = true;
- GridRecordingTitle.Visibility = Visibility.Visible;
- gridSetUp.Visibility = Visibility.Collapsed;
- //if (APP.pageData.pagenum > 0)
- //{
- // GridPage.Visibility = Visibility.Visible;
- //}
- //DataContext = APP.pageData;
- }
- }
-
- /// <summary>
- /// 设置 保存事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnSave_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- BtnRecord.IsEnabled = true;//设置结束时可录制
-
- if (rbnMP4.IsChecked == true)
- {
- //存储文件
- FileToolsCommon.SetConfigValue("VideoType", "1");
- }
- else if (rbnFLV.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("VideoType", "2");
- }
- else
- {
- FileToolsCommon.SetConfigValue("VideoType", "3");
- }
- //if (rbnY.IsChecked == true)
- //{
- // FileToolsCommon.SetConfigValue("IsSound", "true");
- //}
- //else
- //{
- // FileToolsCommon.SetConfigValue("IsSound", "false");
- //}
-
- UpdateHideSRToolConfig();
-
- /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
- if (rbnRight.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("CameraPosition", "1");
- }
- else if (rbnLeft.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("CameraPosition", "2");
- }
- else if (rbnRightUnder.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("CameraPosition", "3");
- }
- else if (rbnLeftUnder.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("CameraPosition", "4");
- }
- //格式
- if (rbnMP4.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("VideoType", "1");
- }
- else if (rbnFLV.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("VideoType", "2");
- }
- else if (rbnAVI.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("VideoType", "3");
- }
- APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
- GridMain.Visibility = Visibility.Visible;
- GridM.IsEnabled = true;
- GridRecordingTitle.Visibility = Visibility.Visible;
- gridSetUp.Visibility = Visibility.Collapsed;
- imgPlayerRight.Visibility = Visibility.Collapsed;
- imgPlayerLeft.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
- if (!txbStoragePath.Content.ToString().Equals(APP.WKData.WkPath))
- {
- //存储文件
- FileToolsCommon.SetConfigValue("VideoSavePath", txbStoragePath.Content.ToString());
- MessageWindow.Show("路径已变更,下次创建微课时自动生效。");
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("XHMicroLessonSystemWindow(设置保存事件报错:)" + ex.Message, ex);
- }
- }
-
- /// <summary>
- /// 设置 浏览事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnBrowse_Click(object sender, RoutedEventArgs e)
- {
- //System.Diagnostics.Process.Start(APP.WKData.WkPath);
- //string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
- Ofd = new System.Windows.Forms.FolderBrowserDialog();
-
- Result = Ofd.ShowDialog();
- if (Result == System.Windows.Forms.DialogResult.OK)
- {
- if (Ofd.SelectedPath != "")
- {
- txbStoragePath.Content = Ofd.SelectedPath;
- //string ApplicationData = ZConfig.dataPath + "fileStorageAddress.txt";
- //string temp = ofd.SelectedPath;
- //System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
- }
- }
- }
-
- /// <summary>
- /// 打开文件所在位置
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void btnOpen_Click(object sender, RoutedEventArgs e)
- {
- System.Diagnostics.Process.Start(APP.WKData.WkPath);
- }
-
- /// <summary>
- /// 更新隐藏录屏工具栏隐藏状态
- /// </summary>
- private void UpdateHideSRToolConfig()
- {
- if (rbnHide.IsChecked == true)
- {
- //隐藏
- FileToolsCommon.SetConfigValue("IsHideSRTool", "1");
- APP.IsHideSRTool = true;
- }
- else
- {
- //显示
- FileToolsCommon.SetConfigValue("IsHideSRTool", "0");
- APP.IsHideSRTool = false;
- }
- }
-
- #region 切换皮肤
-
- /// <summary>
- /// 加载皮肤选项
- /// </summary>
- private void SkinSelectInit()
- {
- if (APP.SkinStyle == "0")
- {
- HideSkinSelect();
- SkinSelectWhite.Visibility = Visibility.Visible;
- SkinConfig.SwitchSkin(0);
- }
- else if (APP.SkinStyle == "1")
- {
- HideSkinSelect();
- SkinSelectTechnologyBlue.Visibility = Visibility.Visible;
- SkinConfig.SwitchSkin(1);
- }
- else
- {
- HideSkinSelect();
- SkinSelectWhite.Visibility = Visibility.Visible;
- }
- }
-
- /// <summary>
- /// 白色
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnSkinWhite_Click(object sender, RoutedEventArgs e)
- {
- if (APP.SkinStyle != "0")
- {
- HideSkinSelect();
- SkinSelectWhite.Visibility = Visibility.Visible;
- APP.SkinStyle = "0";
- FileToolsCommon.SetConfigValue("SkinStyle", "0");
- SkinConfig.SwitchSkin(0);
- }
- }
-
- /// <summary>
- /// 科技蓝
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnSkinTechnologyBlue_Click(object sender, RoutedEventArgs e)
- {
- if (APP.SkinStyle != "1")
- {
- HideSkinSelect();
- SkinSelectTechnologyBlue.Visibility = Visibility.Visible;
- APP.SkinStyle = "1";
- FileToolsCommon.SetConfigValue("SkinStyle", "1");
- SkinConfig.SwitchSkin(1);
- }
- }
-
- /// <summary>
- /// 隐藏皮肤选择键
- /// </summary>
- private void HideSkinSelect()
- {
- SkinSelectWhite.Visibility = Visibility.Hidden;
- SkinSelectTechnologyBlue.Visibility = Visibility.Hidden;
- }
-
- #endregion 切换皮肤
-
- #endregion 设置
-
- #region 画笔
-
- /// <summary>
- /// 画笔颜色事件 白色
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnWhite_Click(object sender, RoutedEventArgs e)
- {
- ////创建 DrawingAttributes 类的一个实例
- //drawingAttributes = new DrawingAttributes();
- ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
- ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
- //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
- ////设置 DrawingAttributes 的 Color 属性设置颜色
- drawingAttributes.Color = Colors.White;
- Color = Colors.White;
- }
-
- /// <summary>
- /// 画笔颜色事件 红色
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnRed_Click(object sender, RoutedEventArgs e)
- {
- //设置 DrawingAttributes 的 Color 属性设置颜色
- drawingAttributes.Color = Colors.Red;
- Color = Colors.Red;
- imgRed.Visibility = Visibility.Visible;
- imgGray.Visibility = Visibility.Collapsed;
- imgCyanBlue.Visibility = Visibility.Collapsed;
- imgYellow.Visibility = Visibility.Collapsed;
- imgBlue.Visibility = Visibility.Collapsed;
- }
-
- /// <summary>
- /// 画笔颜色事件 黑色
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnGray_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Color = Colors.Black;
- Color = Colors.Black;
- imgRed.Visibility = Visibility.Collapsed;
- imgGray.Visibility = Visibility.Visible;
- imgCyanBlue.Visibility = Visibility.Collapsed;
- imgYellow.Visibility = Visibility.Collapsed;
- imgBlue.Visibility = Visibility.Collapsed;
- }
-
- /// <summary>
- /// 画笔颜色事件 青色
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Color = Colors.LimeGreen;
- Color = Colors.LimeGreen;
- imgRed.Visibility = Visibility.Collapsed;
- imgGray.Visibility = Visibility.Collapsed;
- imgCyanBlue.Visibility = Visibility.Visible;
- imgYellow.Visibility = Visibility.Collapsed;
- imgBlue.Visibility = Visibility.Collapsed;
- }
-
- /// <summary>
- /// 画笔颜色事件 黄色
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnYellow_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Color = Colors.Gold;
- Color = Colors.Gold;
- imgRed.Visibility = Visibility.Collapsed;
- imgGray.Visibility = Visibility.Collapsed;
- imgCyanBlue.Visibility = Visibility.Collapsed;
- imgYellow.Visibility = Visibility.Visible;
- imgBlue.Visibility = Visibility.Collapsed;
- }
-
- /// <summary>
- /// 画笔颜色事件 蓝色
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnBlue_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Color = Colors.DeepSkyBlue;
- Color = Colors.DeepSkyBlue;
- imgRed.Visibility = Visibility.Collapsed;
- imgGray.Visibility = Visibility.Collapsed;
- imgCyanBlue.Visibility = Visibility.Collapsed;
- imgYellow.Visibility = Visibility.Collapsed;
- imgBlue.Visibility = Visibility.Visible;
- }
-
- /// <summary>
- /// 画笔粗细事件 细
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void RbnFine_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Width = 1;
- drawingAttributes.Height = 1;
- PenSize = 1;
- }
-
- /// <summary>
- /// 画笔粗细事件 中
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void RbnIn_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Width = 3;
- drawingAttributes.Height = 3;
- PenSize = 3;
- }
-
- /// <summary>
- /// 画笔粗细事件 粗
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void RbnCrude_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Width = 5;
- drawingAttributes.Height = 5;
- PenSize = 5;
- }
-
- private void imgCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- mouseDown = true;
- }
-
- #endregion 画笔
-
- #region 导入截图
-
- /// <summary>
- /// 截图事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
- {
- double do1 = GridContent.ActualHeight;
- double dou = GridMain.ActualHeight;
- Record();
- HideAngleBorder();
- imgCanvas.Margin = new Thickness(0, 0, 0, 0);
- APP.ImgPath = string.Empty;
- string time = GetTimeStamp();
- string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
- APP.ImgPath = desktopPath;
- ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), desktopPath, false, out BitmapImage bitmap);
- k_hook.Stop();
- if (WindowState == WindowState.Normal)//截图隐藏窗口
- {
- WindowState = WindowState.Minimized;
- }
-
- if (APP.W_JieTuWindow != null)
- {
- APP.W_JieTuWindow.initialization();
- APP.W_JieTuWindow.Screenshot();
- APP.W_JieTuWindow.InitializeKeyDownEvent();
- APP.W_JieTuWindow.WindowState = WindowState.Maximized;
- APP.W_JieTuWindow.Visibility = Visibility.Visible;
- }
- else
- {
- APP.W_JieTuWindow = new JieTuWindow();
- APP.W_JieTuWindow.InitializeKeyDownEvent();
- // 订阅事件
- APP.W_JieTuWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
- APP.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
- APP.W_JieTuWindow.Show();
- }
- }
-
- /// <summary>
- /// 获取时间戳
- /// </summary>
- /// <returns>
- /// </returns>
- public string GetTimeStamp()
- {
- TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
- return Convert.ToInt64(ts.TotalSeconds).ToString();
- }
-
- /// <summary>
- /// 返回一个时间戳到毫秒
- /// </summary>
- /// <returns>
- /// </returns>
- public static long Timestamp()
- {
- TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
- long timestr = Convert.ToInt64(ts.TotalMilliseconds);
- return timestr;
- }
-
- public void WindowType()
- {
- if (WindowState == WindowState.Minimized)//截图完恢复窗口
- {
- Topmost = true;
- WindowState = WindowState.Normal;
- }
- }
-
- /// <summary>
- /// 截图关闭窗口
- /// </summary>
- /// <param name="text">
- /// </param>
- private void frm_ChangeTextEvent(string text)
- {
- if ("关闭窗口".Equals(text))
- {
- if (WindowState == WindowState.Minimized)//截图完恢复窗口
- {
- Topmost = true;
- WindowState = WindowState.Normal;
- }
- InitializeKeyDownEvent();
- if (!string.IsNullOrWhiteSpace(APP.ImgPath) && File.Exists(APP.ImgPath))
- {
- if (APP.PageContextData.currpage == 0)
- {
- APP.PageContextData.pagenum += 1;
- APP.PageContextData.currpage = APP.PageContextData.pagenum;
- myblackboard.changepage(APP.PageContextData.currpage - 1);
- GridPage.Visibility = Visibility.Visible;//页码大于0 显示
-
- #region 插入页码
-
- PageData = new List<PageData>();
- for (int i = 1; i <= APP.PageContextData.pagenum; i++)
- {
- PageData pd = new PageData();
- pd.PageName = i.ToString();// + "页";
- pd.PageCode = i;
- PageData.Add(pd);
- }
- CbxPageList.ItemsSource = PageData;
- CbxPageList.SelectedIndex = APP.PageContextData.currpage - 1;
-
- #endregion 插入页码
- }
- if (APP.PageDrawList.Count >= APP.PageContextData.currpage)
- {
- APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath = APP.ImgPath;//zxycs
- APP.PageDrawList[APP.PageContextData.currpage - 1].PdfImagePath = APP.ImgPath;
- }
- else
- {
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageImagePath = APP.ImgPath,
- PdfImagePath = APP.ImgPath
- };
- APP.PageDrawList.Add(model_DrawData);
- }
- if (APP.PageDrawList.Count >= APP.PageContextData.currpage && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath))
- {
- imgDocumentation.Source = null;
- BitmapImage bitImg = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
- mouseDown = false;
- APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
- {
- X = 0.1,
- Y = 0.1
- };
- APP.PageDrawList[APP.PageContextData.currpage - 1].Type = "截图";
-
- APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = false;
- imgCanvas.Source = bitImg;
- imgCanvas.Width = bitImg.Width;
- imgCanvas.Height = bitImg.Height;
- ScroMain.ScrollToVerticalOffset(0);
- APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
- {
- CenterX = imgCanvas.Width,
- CenterY = imgCanvas.Height
- };
- BtnPrint.IsEnabled = true;
- }
- }
- Topmost = false;
- }
- else if ("取消".Equals(text))
- {
- if (WindowState == WindowState.Minimized)//截图完恢复窗口
- {
- Topmost = true;
- WindowState = WindowState.Normal;
- }
- }
- }
-
- /// <summary>
- /// 截图关闭 非正常关闭截图时,截图清空
- /// </summary>
- private void JietuWindow_click_closeJietuWindowClick()
- {
- if (WindowState == WindowState.Minimized)//截图完恢复窗口
- {
- WindowState = WindowState.Normal;
- }
- APP.W_JieTuWindow = null;
- }
-
- /// 截图的图片鼠标右键事件 </summary> <param name="sender"></param> <param name="e"></param>
- private void imgCanvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
- {
- imgCanvas.Source = null;
- APP.PageDrawList[APP.PageContextData.currpage - 1].PdfImagePath = null;
- APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath = null;
- }
-
- /// <summary>
- /// 导入事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnImport_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- Record();
- HideAngleBorder();
- string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
- ofd = new System.Windows.Forms.OpenFileDialog
- {
- //Filter = "文档|*.docx;*.doc;*.ppt;*.pptx",
- //增加导入图片
- Filter = "文档|*.docx;*.doc;*.ppt;*.pptx;*.pdf|图片|*.jpg;*.jpeg;*.png;*.bmp",
- InitialDirectory = desktopPath,
- Multiselect = false,
- AddExtension = true,
- DereferenceLinks = true
- };
-
- //APP.myloading.Show();
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
-
- //new Thread(
- // o =>
- // {
- // Thread.Sleep(400);
-
- // Dispatcher.Invoke(new Action(() =>
- // {
- // OpenDialog();
- // }
- // ));
- // })
- //{
- // IsBackground = true
- //}.Start();
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
- }
- }
-
- /// <summary>
- /// 导入-开始
- /// </summary>
- /// <returns>
- /// </returns>
- private object InvokeServering()
- {
- Dispatcher.Invoke(new Action(() =>
- {
- result = ofd.ShowDialog();
- }));
- if (result == System.Windows.Forms.DialogResult.OK)
- {
- if (ofd.FileName != "")
- {
- List<string> imagelist = new List<string>() { "jpg", "jpeg", "png", "bmp" };
- Dispatcher.Invoke(new Action(() =>
- {
- APP.myloading.Show();
- myblackboard.changepage(APP.PageContextData.pagenum);
- }));
- string filepath = ofd.FileName;
- string filesuff = filepath.Substring(filepath.LastIndexOf(".") + 1).ToLower();
- string path = ofd.SafeFileName.Replace(".ppt", "").Replace(".pptx", "").Trim();
- string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Replace(".pptx", "typezsygppt").Replace(".pdf", "typepdf").Trim();
- if (type.Contains("typezsygppt"))//ppt
- {
- try
- {
- #region PPT转PDF
-
- string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- path = pathTemp + path + ".pdf";
- FileToolsCommon.CreateDirectory(pathTemp);
-
- //PPT转PDF
- Presentation ppt = new Presentation(filepath);
- ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
-
- #endregion PPT转PDF
-
- #region PDF转图片
-
- // 图片绝对路径集合
- List<string> images = new List<string>();
- string directoryPath = pathTemp;
-
- //定义Jpeg转换设备
- Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
- Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
- //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
- //directoryPath += quality;
- Directory.CreateDirectory(directoryPath);
- //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
- device = new Aspose.Pdf.Devices.JpegDevice(100);
- //遍历每一页转为jpg
- for (int i = 1; i <= document.Pages.Count; i++)
- {
- long ii = Timestamp();
- string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
- images.Add(filePathOutPut);
- FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
- try
- {
- device.Process(document.Pages[i], fs);
- fs.Close();
- }
- catch (Exception)
- {
- fs.Close();
- File.Delete(filePathOutPut);
- }
- }
-
- #endregion PDF转图片
-
- Dispatcher.Invoke(new Action(() =>
- {
- string[] page = images.ToArray();
- int num = 0;
-
- int iStart = APP.PageContextData.pagenum;//导入文档的开始下标
- int iEnd = page.Length + APP.PageContextData.pagenum;//导入文档的结束下标
- for (int i = 0 + APP.PageContextData.pagenum; i < page.Length + APP.PageContextData.pagenum; i++)//给画板模型加图片路径
- {
- if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
- {
- APP.PageDrawList[i].PageImagePath = page[i - APP.PageContextData.pagenum]; //zxycs
- APP.PageDrawList[i].PdfImagePath = page[i - APP.PageContextData.pagenum];
- APP.PageDrawList[i].PageNum = i + 1;
- APP.PageDrawList[i].ImgDocumentation = true;
- APP.PageDrawList[i].Type = "ppt";
- }
- else
- {
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageImagePath = page[i - APP.PageContextData.pagenum],
- PdfImagePath = page[i - APP.PageContextData.pagenum],
- PageNum = i + 1,
- ImgDocumentation = true,
- Type = "ppt"
- };
- APP.PageDrawList.Add(model_DrawData);
- }
-
- BtnPrint.IsEnabled = true;
- APP.SaveDraw();
- num++;
- }
- if (num > 0)
- {
- APP.PageContextData.currpage = APP.PageContextData.pagenum + 1;
- APP.PageContextData.pagenum += num;
- GridPage.Visibility = Visibility.Visible;//页码大于0 显示
- }
- if (APP.PageContextData.currpage > 0 && APP.PageContextData.currpage <= APP.PageDrawList.Count)
- {
- imgCanvas.Source = null;
- BtnScreenshot.IsEnabled = false;
- imgDocumentation.Source = null;
- imgPPT.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
- ScroMain.ScrollToVerticalOffset(0);
- for (int i = iStart; i < iEnd; i++)
- {
- APP.PageDrawList[i].ImageLocation = new TranslateTransform
- {
- X = 0.1,
- Y = 0.1
- };
-
- APP.PageDrawList[i].IsImageLocation = true;
- APP.PageDrawList[i].ImageSizes = new ScaleTransform
- {
- CenterX = imgCanvas.Width,
- CenterY = imgCanvas.Height
- };
- }
- }
- else
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = null;
- imgPPT.Source = null;
- ///截图可用
- BtnScreenshot.IsEnabled = true;
- }
- }));
- }
- catch (Exception ex)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
- }));
-
- LogHelper.WriteErrLog("【打开ppt】(OpenDialog PPT)" + ex.Message, ex);
- }
- }
- else if (type.Contains("typepdf"))
- {
- try
- {
- string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
-
- #region PDF转图片
-
- // 图片绝对路径集合
- List<string> images = new List<string>();
- string directoryPath = pathTemp;
- //aspose许可证
- //Aspose.Pdf.License l = new Aspose.Pdf.License();
- //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
- //l.SetLicense(licenseName);
- //定义Jpeg转换设备
- Aspose.Pdf.Document document = new Aspose.Pdf.Document(filepath);
- Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
- //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
- //directoryPath += quality;
- Directory.CreateDirectory(directoryPath);
- //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
- device = new Aspose.Pdf.Devices.JpegDevice(100);
-
- //遍历每一页转为jpg
- for (int i = 1; i <= document.Pages.Count; i++)
- {
- long ii = Timestamp();
- string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
- images.Add(filePathOutPut);
- FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
- try
- {
- device.Process(document.Pages[i], fs);
- fs.Close();
- }
- catch (Exception)
- {
- fs.Close();
- File.Delete(filePathOutPut);
- }
- }
-
- #endregion PDF转图片
-
- string[] page = images.ToArray();
- int num = 0;
- int iStart = APP.PageContextData.pagenum;//导入文档的开始下标
- int iEnd = page.Length + APP.PageContextData.pagenum;//导入文档的结束下标
- Dispatcher.Invoke(new Action(() =>
- {
- for (int i = APP.PageContextData.pagenum; i < page.Length + APP.PageContextData.pagenum; i++)//给画板模型加图片路径
- {
- if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
- {
- APP.PageDrawList[i].PageImagePath = page[i - APP.PageContextData.pagenum]; //zxycs
- APP.PageDrawList[i].PdfImagePath = page[i - APP.PageContextData.pagenum];
- APP.PageDrawList[i].PageNum = i + 1;
- APP.PageDrawList[i].ImgDocumentation = true;
- APP.PageDrawList[i].Type = "word";
- }
- else
- {
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageImagePath = page[i - APP.PageContextData.pagenum],
- PdfImagePath = page[i - APP.PageContextData.pagenum],
- PageNum = i + 1,
- ImgDocumentation = true,
- Type = "word"
- };
- APP.PageDrawList.Add(model_DrawData);
- }
-
- BtnPrint.IsEnabled = true;
- APP.SaveDraw();
- num++;
- }
- if (num > 0)
- {
- APP.PageContextData.currpage = APP.PageContextData.pagenum + 1;
- APP.PageContextData.pagenum += num;
- GridPage.Visibility = Visibility.Visible;//页码大于0 显示
- }
- if (APP.PageContextData.currpage > 0 && APP.PageContextData.currpage <= APP.PageDrawList.Count)
- {
- imgCanvas.Source = null;
- imgPPT.Source = null;
- BtnScreenshot.IsEnabled = false;
- imgDocumentation.Visibility = Visibility.Visible;
- imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));//给当前页面展示图片
- ScroMain.ScrollToVerticalOffset(0);
- }
- else
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = null;
- imgPPT.Source = null;
- ///截图可用
- BtnScreenshot.IsEnabled = true;
- }
- }));
- }
- catch (Exception ex)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- MessageWindow.Show(ex.Message);
- }));
-
- LogHelper.WriteErrLog("【打开pdf】(OpenDialog pdf)" + ex.Message, ex);
- }
- }
- else if (imagelist.Contains(filesuff))///导入图片
- {
- string imagepath = AppDomain.CurrentDomain.BaseDirectory + "temp";
-
- if (!Directory.Exists(imagepath))
- {
- Directory.CreateDirectory(imagepath);
- }
- TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
- string timestr = Convert.ToInt64(ts.TotalMilliseconds).ToString();
- string filepathCopy = Path.Combine(imagepath, timestr + ofd.SafeFileName);
-
- System.IO.File.Copy(filepath, filepathCopy);
- filepath = filepathCopy;
-
- APP.ImgPath = filepath;
- Dispatcher.Invoke(new Action(() =>
- {
- if (APP.PageContextData.currpage == 0)
- {
- APP.PageContextData.pagenum += 1;
- APP.PageContextData.currpage = APP.PageContextData.pagenum;
- myblackboard.changepage(APP.PageContextData.currpage - 1);
-
- GridPage.Visibility = Visibility.Visible;//页码大于0 显示
-
- #region 插入页码
-
- PageData = new List<PageData>();
- for (int i = 1; i <= APP.PageContextData.pagenum; i++)
- {
- PageData pd = new PageData();
- pd.PageName = i.ToString();// + "页";
- pd.PageCode = i;
- PageData.Add(pd);
- }
- CbxPageList.ItemsSource = PageData;
- CbxPageList.SelectedIndex = APP.PageContextData.currpage - 1;
-
- #endregion 插入页码
- }
- else
- {
- APP.PageContextData.pagenum += 1;
- APP.PageContextData.currpage = APP.PageContextData.pagenum;
- myblackboard.changepage(APP.PageContextData.currpage - 1);
- }
-
- if (APP.PageDrawList.Count >= APP.PageContextData.currpage)
- {
- APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath = APP.ImgPath;//zxycs
- APP.PageDrawList[APP.PageContextData.currpage - 1].PdfImagePath = APP.ImgPath;
- }
- else
- {
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageImagePath = APP.ImgPath,
- PdfImagePath = APP.ImgPath
- };
- APP.PageDrawList.Add(model_DrawData);
- }
- if (APP.PageDrawList.Count >= APP.PageContextData.currpage && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath))
- {
- imgDocumentation.Source = null;
- BitmapImage bitImg = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
- mouseDown = false;
- APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
- {
- X = 0.1,
- Y = 0.1
- };
- APP.PageDrawList[APP.PageContextData.currpage - 1].Type = "截图";
-
- APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = false;
- imgCanvas.Source = bitImg;
- imgCanvas.Width = bitImg.Width;
- imgCanvas.Height = bitImg.Height;
- ScroMain.ScrollToVerticalOffset(0);
- imgCanvas.Margin = new Thickness(APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation.X, APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation.Y, 0, 0);
- APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
- {
- CenterX = imgCanvas.Width,
- CenterY = imgCanvas.Height
- };
-
- BtnPrint.IsEnabled = true;
- }
- }));
- }
- else//word
- {
- try
- {
- string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- WordImgNum += 1;
- string[] page = ZAsposeUtil.ConvertWordToImage(filepath, paths, "" + WordImgNum, 0, 0).ToArray();
- int num = 0;
- Dispatcher.Invoke(new Action(() =>
- {
- for (int i = 0 + APP.PageContextData.pagenum; i < page.Length + APP.PageContextData.pagenum; i++)//给画板模型加图片路径
- {
- if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
- {
- APP.PageDrawList[i].PageImagePath = page[i - APP.PageContextData.pagenum]; //zxycs
- APP.PageDrawList[i].PdfImagePath = page[i - APP.PageContextData.pagenum];
- APP.PageDrawList[i].PageNum = i + 1;
- APP.PageDrawList[i].ImgDocumentation = true;
- APP.PageDrawList[i].Type = "word";
- }
- else
- {
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageImagePath = page[i - APP.PageContextData.pagenum],
- PdfImagePath = page[i - APP.PageContextData.pagenum],
- PageNum = i + 1,
- ImgDocumentation = true,
- Type = "word"
- };
- APP.PageDrawList.Add(model_DrawData);
- }
- BtnPrint.IsEnabled = true;
- APP.SaveDraw();
- num++;
- }
- if (num > 0)
- {
- APP.PageContextData.currpage = APP.PageContextData.pagenum + 1;
- APP.PageContextData.pagenum += num;
- GridPage.Visibility = Visibility.Visible;//页码大于0 显示
- }
- if (APP.PageContextData.currpage > 0 && APP.PageContextData.currpage <= APP.PageDrawList.Count)
- {
- imgCanvas.Source = null;
- imgPPT.Source = null;
- BtnScreenshot.IsEnabled = false;
- imgDocumentation.Visibility = Visibility.Visible;
- imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));//给当前页面展示图片
- ScroMain.ScrollToVerticalOffset(0);
- }
- else
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = null;
- imgPPT.Source = null;
- ///截图可用
- BtnScreenshot.IsEnabled = true;
- }
- }));
- }
- catch (Exception ex)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
- }));
- LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
- }
- }
-
- #region 插入页码
-
- Dispatcher.Invoke(new Action(() =>
- {
- PageData = new List<PageData>();
- for (int i = 1; i <= APP.PageContextData.pagenum; i++)
- {
- PageData pd = new PageData();
- pd.PageName = i.ToString();//+ "页";
- pd.PageCode = i;
- PageData.Add(pd);
- }
- CbxPageList.ItemsSource = PageData;
- CbxPageList.SelectedIndex = APP.PageContextData.currpage - 1;
- }));
-
- #endregion 插入页码
- }
- }
- //OpenDialog();
- return "";
- }
-
- /// <summary>
- /// 导入-结束
- /// </summary>
- /// <returns>
- /// </returns>
- public void InvokeServerCompate(object obj)
- {
- //APP.myloading.Hide();
- APP.myloading.Hide();
- }
-
- /// <summary>
- /// 防止图片地址重复
- /// </summary>
- private long WordImgNum = 9999;
-
- /// <summary>
- /// 导入文档
- /// </summary>
- private void OpenDialog()
- {
- Dispatcher.Invoke(new Action(() =>
- {
- result = ofd.ShowDialog();
- if (result == System.Windows.Forms.DialogResult.OK)
- {
- if (ofd.FileName != "")
- {
- APP.myloading.Show();
-
- myblackboard.changepage(APP.PageContextData.pagenum);
-
- #region PPT转PDF
-
- string filepath = ofd.FileName;
- string path = ofd.SafeFileName.Replace(".ppt", "").Replace(".pptx", "").Trim();
- string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Replace(".pptx", "typezsygppt").Replace(".pdf", "typepdf").Trim();
- if (type.Contains("typezsygppt"))//ppt
- {
- try
- {
- string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- path = pathTemp + path + ".pdf";
- FileToolsCommon.CreateDirectory(pathTemp);
-
- //PPT转PDF
- Presentation ppt = new Presentation(filepath);
- ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
-
- #endregion PPT转PDF
-
- #region PDF转图片
-
- // 图片绝对路径集合
- List<string> images = new List<string>();
- string directoryPath = pathTemp;
- //aspose许可证
- //Aspose.Pdf.License l = new Aspose.Pdf.License();
- //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
- //l.SetLicense(licenseName);
- //定义Jpeg转换设备
- Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
- Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
- //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
- //directoryPath += quality;
- Directory.CreateDirectory(directoryPath);
- //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
- device = new Aspose.Pdf.Devices.JpegDevice(100);
- //遍历每一页转为jpg
- for (int i = 1; i <= document.Pages.Count; i++)
- {
- long ii = Timestamp();
- string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
- images.Add(filePathOutPut);
- FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
- try
- {
- device.Process(document.Pages[i], fs);
- fs.Close();
- }
- catch (Exception)
- {
- fs.Close();
- File.Delete(filePathOutPut);
- }
- }
-
- #endregion PDF转图片
-
- string[] page = images.ToArray();
- int num = 0;
- for (int i = 0 + APP.PageContextData.pagenum; i < page.Length + APP.PageContextData.pagenum; i++)//给画板模型加图片路径
- {
- if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
- {
- APP.PageDrawList[i].PageImagePath = page[i - APP.PageContextData.pagenum]; //zxycs
- APP.PageDrawList[i].PdfImagePath = page[i - APP.PageContextData.pagenum];
- APP.PageDrawList[i].PageNum = i + 1;
- APP.PageDrawList[i].ImgDocumentation = true;
- }
- else
- {
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageImagePath = page[i - APP.PageContextData.pagenum],
- PdfImagePath = page[i - APP.PageContextData.pagenum],
- PageNum = i + 1,
- ImgDocumentation = true
- };
- APP.PageDrawList.Add(model_DrawData);
- }
- BtnPrint.IsEnabled = true;
- APP.SaveDraw();
- num++;
- }
- if (num > 0)
- {
- APP.PageContextData.currpage = APP.PageContextData.pagenum + 1;
- APP.PageContextData.pagenum += num;
- GridPage.Visibility = Visibility.Visible;//页码大于0 显示
- }
- if (APP.PageContextData.currpage > 0 && APP.PageContextData.currpage < APP.PageDrawList.Count)
- {
- imgCanvas.Source = null;
- BtnScreenshot.IsEnabled = false;
- imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));//给当前页面展示图片
- }
- else
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = null;
- ///截图可用
- BtnScreenshot.IsEnabled = true;
- }
- APP.myloading.Hide();
- }
- catch (Exception ex)
- {
- APP.myloading.Hide();
- MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
- LogHelper.WriteErrLog("【打开ppt】(OpenDialog PPT)" + ex.Message, ex);
- }
- }
- else if (type.Contains("typepdf"))
- {
- string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
-
- #region PDF转图片
-
- // 图片绝对路径集合
- List<string> images = new List<string>();
- string directoryPath = pathTemp;
- //aspose许可证
- //Aspose.Pdf.License l = new Aspose.Pdf.License();
- //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
- //l.SetLicense(licenseName);
- //定义Jpeg转换设备
- Aspose.Pdf.Document document = new Aspose.Pdf.Document(filepath);
- Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
- //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
- //directoryPath += quality;
- Directory.CreateDirectory(directoryPath);
- //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
- device = new Aspose.Pdf.Devices.JpegDevice(100);
- //遍历每一页转为jpg
- for (int i = 1; i <= document.Pages.Count; i++)
- {
- long ii = Timestamp();
- string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
- images.Add(filePathOutPut);
- FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
- try
- {
- device.Process(document.Pages[i], fs);
- fs.Close();
- }
- catch (Exception)
- {
- fs.Close();
- File.Delete(filePathOutPut);
- }
- }
-
- #endregion PDF转图片
-
- string[] page = images.ToArray();
- int num = 0;
- for (int i = 0 + APP.PageContextData.pagenum; i < page.Length + APP.PageContextData.pagenum; i++)//给画板模型加图片路径
- {
- if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
- {
- APP.PageDrawList[i].PageImagePath = page[i - APP.PageContextData.pagenum]; //zxycs
- APP.PageDrawList[i].PdfImagePath = page[i - APP.PageContextData.pagenum];
- APP.PageDrawList[i].PageNum = i + 1;
- APP.PageDrawList[i].ImgDocumentation = true;
- }
- else
- {
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageImagePath = page[i - APP.PageContextData.pagenum],
- PdfImagePath = page[i - APP.PageContextData.pagenum],
- PageNum = i + 1,
- ImgDocumentation = true
- };
- APP.PageDrawList.Add(model_DrawData);
- }
- BtnPrint.IsEnabled = true;
- APP.SaveDraw();
- num++;
- }
- if (num > 0)
- {
- APP.PageContextData.currpage = APP.PageContextData.pagenum + 1;
- APP.PageContextData.pagenum += num;
- GridPage.Visibility = Visibility.Visible;//页码大于0 显示
- }
- if (APP.PageContextData.currpage > 0 && APP.PageContextData.currpage < APP.PageDrawList.Count)
- {
- imgCanvas.Source = null;
- BtnScreenshot.IsEnabled = false;
- imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));//给当前页面展示图片
- }
- else
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = null;
- ///截图可用
- BtnScreenshot.IsEnabled = true;
- }
- APP.myloading.Hide();
- }
- else//word
- {
- try
- {
- string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- WordImgNum += 1;
- string[] page = ZAsposeUtil.ConvertWordToImage(filepath, paths, "" + WordImgNum, 0, 0).ToArray();
- int num = 0;
- for (int i = 0 + APP.PageContextData.pagenum; i < page.Length + APP.PageContextData.pagenum; i++)//给画板模型加图片路径
- {
- if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
- {
- APP.PageDrawList[i].PageImagePath = page[i - APP.PageContextData.pagenum]; //zxycs
- APP.PageDrawList[i].PdfImagePath = page[i - APP.PageContextData.pagenum];
- APP.PageDrawList[i].PageNum = i + 1;
- APP.PageDrawList[i].ImgDocumentation = true;
- }
- else
- {
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageImagePath = page[i - APP.PageContextData.pagenum],
- PdfImagePath = page[i - APP.PageContextData.pagenum],
- PageNum = i + 1,
- ImgDocumentation = true
- };
- APP.PageDrawList.Add(model_DrawData);
- }
- BtnPrint.IsEnabled = true;
- APP.SaveDraw();
- num++;
- }
- if (num > 0)
- {
- APP.PageContextData.currpage = APP.PageContextData.pagenum + 1;
- APP.PageContextData.pagenum += num;
- GridPage.Visibility = Visibility.Visible;//页码大于0 显示
- }
- if (APP.PageContextData.currpage > 0 && APP.PageContextData.currpage < APP.PageDrawList.Count)
- {
- imgCanvas.Source = null;
- BtnScreenshot.IsEnabled = false;
- imgDocumentation.Visibility = Visibility.Visible;
- imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));//给当前页面展示图片
- }
- else
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = null;
- ///截图可用
- BtnScreenshot.IsEnabled = true;
- }
- APP.myloading.Hide();
- }
- catch (Exception ex)
- {
- APP.myloading.Hide();
- LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
- }
- }
- }
- }
- }
- ));
- }
-
- #region 导入转换图片
-
- /// <summary>
- /// 生成图片
- /// </summary>
- /// <param name="_path">
- /// 图片地址
- /// </param>
- /// <param name="_saveimg">
- /// 保存位置
- /// </param>
- /// <param name="_rectangle">
- /// 图片位置
- /// </param>
- /// <param name="errmsg">
- /// 错误消息
- /// </param>
- /// <returns>
- /// </returns>
- private bool MergerImg(string _path, string _saveimg, RectangleF _rectangle, out string errmsg)
- {
- errmsg = null;
- try
- {
- Bitmap bitmap = null;
-
- //创建要显示的图片对象,根据参数的个数设置宽度
- Bitmap backgroudImg = new Bitmap((int)GridM.ActualWidth, (int)GridM.ActualHeight);
- Graphics g = Graphics.FromImage(backgroudImg);
- //清除画布,背景设置为白色
- g.Clear(System.Drawing.Color.White);
-
- if (!string.IsNullOrWhiteSpace(_path))
- {
- bitmap = ImageHelper.ReadBitmapFile(_path);
- g.DrawImage(bitmap, _rectangle);
- }
-
- backgroudImg.Save(_saveimg);
-
- g.Dispose();
- backgroudImg.Dispose();
- if (bitmap != null)
- {
- bitmap.Dispose();
- }
-
- GC.Collect();
- return true;
- }
- catch (Exception ex)
- {
- errmsg = ex.Message;
- LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
- return false;
- }
- }
-
- #endregion 导入转换图片
-
- #endregion 导入截图
-
- #region 上传 列表
-
- /// <summary>
- /// 上传事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnUpload_Click(object sender, RoutedEventArgs e)
- {
- if (GridMyVideo.Visibility == Visibility.Visible)
- {
- GridMyVideo.Visibility = Visibility.Collapsed;
- GridMain.Visibility = Visibility.Visible;
- GridM.IsEnabled = true;
- GridRecordingTitle.Visibility = Visibility.Visible;
- }
- else
- {
- PageHide();
- GridMyVideo.Visibility = Visibility.Visible;
- LoadUploadInitData();
- }
- }
-
- /// <summary>
- /// 初始化上传
- /// </summary>
- public void InitializeUpload()
- {
- APP.myloading.Show();
-
- //MouseNumber = 0;
- IsModify = false;
- //加载视频列表
- LoadingVideoList();
-
- Currpage = 0;
- PageNum = 0;
-
- APP.myloading.Hide();
- DataContext = pageData;
- }
-
- /// <summary>
- /// 当前页
- /// </summary>
- private int Currpage = 0;
-
- /// <summary>
- /// 总页码
- /// </summary>
- private int PageNum = 0;
-
- /// <summary>
- /// 加载视频列表
- /// </summary>
- public void LoadingVideoList()
- {
- try
- {
- model_VideoList = new List<Model_Video>();
- foreach (Model_WKData Vdata in APP.WKDataList)
- {
- #region 计时器初始化
-
- if (Vdata.VideoList == null)
- {
- continue;
- }
-
- foreach (Model_Video videoinfo in Vdata.VideoList)
- {
- try
- {
- if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
- {
- continue;
- }
- if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
- {
- videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMB(videoinfo.VideoPath).ToString() + " MB";
- videoinfo.VideoSizebyte = FileToolsCommon.GetFileSize(videoinfo.VideoPath);
- }
- model_VideoList.Add(videoinfo);
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
- }
- }
-
- #endregion 计时器初始化
- }
- //翻转
- if (model_VideoList.Count > 1)
- {
- model_VideoList.Reverse();
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
- }
- }
-
- /// <summary>
- /// 搜索集合匹配的索引
- /// </summary>
- /// <typeparam name="T">
- /// </typeparam>
- /// <param name="parent">
- /// </param>
- /// <param name="childName">
- /// </param>
- /// <returns>
- /// </returns>
- public static List<T> FindChilds<T>(DependencyObject parent, string childName)
- where T : DependencyObject
- {
- List<T> list = new List<T>();
- if (parent == null)
- {
- return list;
- }
-
- int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
- for (int i = 0; i < childrenCount; i++)
- {
- DependencyObject child = VisualTreeHelper.GetChild(parent, i);
- // 如果子控件不是需查找的控件类型
- T childType = child as T;
- if (childType == null)
- {
- // 在下一级控件中递归查找
- List<T> findChildList = FindChilds<T>(child, childName);
- for (int j = 0; j < findChildList.Count; j++)
- {
- }
- list.AddRange(FindChilds<T>(child, childName));
- }
- else if (!string.IsNullOrEmpty(childName))
- {
- FrameworkElement frameworkElement = child as FrameworkElement;
- // 如果控件名称符合参数条件
- if (frameworkElement != null && frameworkElement.Name == childName)
- {
- list.Add((T)child);
- }
- }
- else
- {
- // 查找到了控件
- list.Add((T)child);
- }
- }
-
- return list;
- }
-
- #endregion 上传 列表
-
- #region 新上传 显示缩略图
-
- #region 初始值
-
- /// <summary>
- /// 总页数
- /// </summary>
- private int TotalPage = 0;
-
- /// <summary>
- /// 当前页
- /// </summary>
- private int CurrentPage = 1;
-
- /// <summary>
- /// 每页显示的视频数
- /// </summary>
- private int PageShowNum = 0;
-
- /// <summary>
- /// 视频信息列表
- /// </summary>
- private List<Uc_VideoItem> VideoControlList = new List<Uc_VideoItem>();
-
- /// <summary>
- /// 横向间隔
- /// </summary>
- private double IntervalX = 0;
-
- /// <summary>
- /// 纵向间隔
- /// </summary>
- private double IntervalY = 0;
-
- /// <summary>
- /// 页面宽
- /// </summary>
- private double pageW;
-
- /// <summary>
- /// 页面高
- /// </summary>
- private double pageH;
-
- private double ControlWidth = 250;
- private double ControlHeight = 260;
-
- #endregion 初始值
-
- /// <summary>
- /// 初始化加载上传页面数据
- /// </summary>
- private void LoadUploadInitData()
- {
- APP.myloading.Show();
- //加载视频列表
- LoadingVideoList();
- if (model_VideoList.Count > 0)
- {
- lblVideoMess.Visibility = Visibility.Hidden;
- BtnVideoUpPage.Visibility = Visibility.Visible;
- lblVideoPageNum.Visibility = Visibility.Visible;
- BtnVideoDownPage.Visibility = Visibility.Visible;
-
- if (GridMyVideo.ActualHeight > 0)
- {
- pageW = GridMyVideo.ActualWidth;
- pageH = GridMyVideo.ActualHeight;
- }
- else
- {
- pageW = GridRecordingArea.ActualWidth;
- pageH = GridRecordingArea.ActualHeight;
- }
- //获取设置控件大小 新增 页面原始1061 911
- double PropWid = pageW / 1061.00;
- double PropHei = pageH / 911.00;
- //ControlWidth = 250.00 * PropWid;
- //ControlHeight = 260.00 * PropHei;
- //ControlWidth=
- //ControlHeight=
- //根据页面大小获取每页显示的数量 H260W250
- int videoRow = (int)((pageH - 50) / ControlHeight);
- int videColumn = (int)(pageW / ControlWidth);
- //横向间隔
- IntervalX = (pageW - (videColumn * ControlWidth)) / (videColumn + 1);
- IntervalY = (pageH - 50 - (videoRow * ControlHeight)) / (videoRow + 1);
- PageShowNum = (videoRow == 0 ? 1 : videoRow) * (videColumn == 0 ? 1 : videColumn);
- //获取总页数
- TotalPage = model_VideoList.Count / PageShowNum + (model_VideoList.Count % PageShowNum > 0 ? 1 : 0);
- //如果当前页大于总页数 总页数为当前页
- if (TotalPage < CurrentPage)
- {
- CurrentPage = TotalPage;
- }
- LoadCurrentPageData();
- }
- else
- {
- lblVideoMess.Visibility = Visibility.Visible;
- BtnVideoUpPage.Visibility = Visibility.Hidden;
- lblVideoPageNum.Visibility = Visibility.Hidden;
- BtnVideoDownPage.Visibility = Visibility.Hidden;
- //隐藏显示的控件
- if (VideoControlList.Count > 0)
- {
- foreach (Uc_VideoItem item in VideoControlList)
- {
- if (item.Visibility != Visibility.Hidden)
- {
- item.Visibility = Visibility.Hidden;
- }
- }
- }
- }
- APP.myloading.Hide();
- }
-
- /// <summary>
- /// 加载当前页数据
- /// </summary>
- private void LoadCurrentPageData()
- {
- lblVideoPageNum.Content = CurrentPage + "/" + TotalPage;
- //隐藏显示的控件
- if (VideoControlList.Count > 0)
- {
- foreach (Uc_VideoItem item in VideoControlList)
- {
- if (item.Visibility != Visibility.Hidden)
- {
- item.Visibility = Visibility.Hidden;
- }
- }
- }
- double W = IntervalX;//每次增加250
- double H = IntervalY;//每次增加260
- //加载控件
- for (int i = 0; i < PageShowNum; i++)
- {
- int DataIndex = (CurrentPage - 1) * PageShowNum + i;
- if (DataIndex == model_VideoList.Count)
- {
- return;
- }
- Uc_VideoItem videoItem;
- if (VideoControlList.Exists(x => x.Tag.ToString() == model_VideoList[DataIndex].FileGuid))
- {
- videoItem = VideoControlList.Find(x => x.Tag.ToString() == model_VideoList[DataIndex].FileGuid);
- }
- else
- {
- if (!FileToolsCommon.IsExistFile(model_VideoList[DataIndex].ThumbnailPath))
- {
- continue;
- }
- videoItem = new Uc_VideoItem(model_VideoList[DataIndex])
- {
- Tag = model_VideoList[DataIndex].FileGuid
- };
- videoItem.Click_refreshVideoList += LoadUploadInitData;
- videoItem.Click_UploadLogin += Login;
- videoItem.Width = ControlWidth;
- videoItem.Height = ControlHeight;
- videoItem.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
- videoItem.VerticalAlignment = System.Windows.VerticalAlignment.Top;
- GridMyVideo.Children.Add(videoItem);
- VideoControlList.Add(videoItem);
- }
- videoItem.Margin = new Thickness(W, H, 0, 0);
- videoItem.Visibility = Visibility.Visible;
- if (W + ControlWidth + ControlWidth > pageW)
- {
- W = IntervalX;
- H += ControlHeight + IntervalY;
- }
- else
- {
- W += ControlWidth + IntervalX;
- }
- //Uc_VideoItem videoItem = new Uc_VideoItem();
- //return;
- }
- }
-
- #region 分页
-
- /// <summary>
- /// 上一页
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnVideoUpPage_Click(object sender, RoutedEventArgs e)
- {
- if (CurrentPage > 1)
- {
- CurrentPage--;
- LoadCurrentPageData();
- }
- }
-
- /// <summary>
- /// 下一页
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnVideoDownPage_Click(object sender, RoutedEventArgs e)
- {
- if (CurrentPage < TotalPage)
- {
- CurrentPage++;
- LoadCurrentPageData();
- }
- }
-
- #endregion 分页
-
- #endregion 新上传 显示缩略图
-
- #region 设备检测
-
- /// <summary>
- /// 设备检测
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnDevice_Click(object sender, RoutedEventArgs e)
- {
- rbnTurnOff.IsChecked = true;
- RbnTurnOff_Click(null, null);
- DeviceWindow deviceWin = new DeviceWindow();
- deviceWin.Show();
- }
-
- #endregion 设备检测
-
- #region 录屏
-
- /// <summary>
- /// 录屏事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
- {
- ThreadPool.QueueUserWorkItem(o =>
- {
- bool microphoneGood = ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.microphone);
- bool loudspeakerGood = ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.loudspeaker);
-
- Dispatcher.Invoke(() =>
- {
- if (!microphoneGood)
- {
- MessageWindow.Show("麦克风不可用");
- return;
- }
-
- if (!loudspeakerGood)
- {
- MessageWindow.Show("扬声器不可用");
- return;
- }
-
- Record();
-
- k_hook.Stop();
- if (APP.W_ScreenRecordingToolbarWindow == null)
- {
- APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow
- {
- Topmost = true
- };
- APP.W_ScreenRecordingToolbarWindow.Initialize();
- }
- else
- {
- APP.W_ScreenRecordingToolbarWindow.Initialize();
- }
- APP.W_ScreenRecordingToolbarWindow.Click_stopRecordingScreen += W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen;
- //显示在右下角
- APP.W_ScreenRecordingToolbarWindow.WindowStartupLocation = WindowStartupLocation.Manual;
- Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
- float DIP = graphics.DpiX;
- float DIPY = graphics.DpiY;
- APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.WorkingArea.Width / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Width;
- APP.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.WorkingArea.Height / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Height - 100;
- APP.W_ScreenRecordingToolbarWindow.Topmost = true;
- APP.W_ScreenRecordingToolbarWindow.Show();
- Hide();
- });
- });
- }
-
- /// <summary>
- /// 保存录屏中
- /// </summary>
- private void W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen()
- {
- TxbTime.Text = "00:00";
- //TxbTime.Visibility = Visibility.Hidden;
- //ImgLZImg.Visibility = Visibility.Hidden;
- //TxbType.Visibility = Visibility.Visible;
- TxbType.Text = "保存中";
- BtnScreenRecording.IsEnabled = false;
-
- new Thread(new ThreadStart(new Action(() =>
- {
- while (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath + "temprs/"))
- {
- Thread.Sleep(100);
- }
- Thread.Sleep(100);
- Dispatcher.Invoke(() =>
- {
- BtnScreenRecording.IsEnabled = true;
- TxbType.Text = "准备就绪";
- //TxbType.Visibility = Visibility.Hidden;
- //TxbRecordScreenWord.Text = "录屏";
- });
- }))).Start();
- }
-
- #endregion 录屏
-
- #region 录制窗口
-
- #region 变量
-
- /// <summary>
- /// 视频合成前路径名
- /// </summary>
- private string TempVideoPathName;
-
- /// <summary>
- /// 音频保存路径名
- /// </summary>
- private string TempAudioPathName;
-
- /// <summary>
- /// 视频保存路径名
- /// </summary>
- private string VideoSavePathName;
-
- /// <summary>
- /// 截图定时器
- /// </summary>
- private System.Threading.Timer timer;
-
- /// <summary>
- /// 录制计时
- /// </summary>
- private DateTime SRTime = DateTime.Now;
-
- /// <summary>
- /// 录制大小
- /// </summary>
- private int gridActWidth = 1276;
-
- /// <summary>
- /// 录制大小
- /// </summary>
- private int gridActHeight = 898;
-
- /// <summary>
- /// 录制类型 0停止中,1录制中,2暂停中 3倒计时
- /// </summary>
- private int RecordType = 0;
-
- #endregion 变量
-
- private bool IsPressButton = false;
-
- /// <summary>
- /// 录制窗口内容
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnRecord_Click(object sender, RoutedEventArgs e)
- {
- #region 防止连击
-
- if (IsPressButton)
- {
- return;
- }
- else
- {
- IsPressButton = true;
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(500);
- IsPressButton = false;
- }))).Start();
- }
-
- #endregion 防止连击
-
- if (APP.PageContextData.currpage == 0)
- {
- MessageWindow.Show("请先导入文档或截图!");
- return;
- }
-
- if (RecordType == 0)
- {
- ThreadPool.QueueUserWorkItem(o =>
- {
- bool microphoneGood = ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.microphone);
-
- Dispatcher.Invoke(() =>
- {
- if (!microphoneGood)
- {
- MessageWindow.Show("麦克风不可用");
- return;
- }
-
- //停止中开始录制
- RecordType = 3;
- blackboard_canvas.Visibility = Visibility.Visible;
- if (RectImgBorder.Visibility != Visibility.Hidden)
- {
- HideAngleBorder();
- }
-
- Record();
-
- BtnPrint.IsEnabled = false;
- BtnScreenshot.IsEnabled = false;
- BtnImport.IsEnabled = false;
- BtnScreenRecording.IsEnabled = false;
- BtnUpload.IsEnabled = false;
- BtnSetUp.IsEnabled = false;
- BtnDevice.IsEnabled = false;
-
- BtnLoginType.IsEnabled = false;
- blackboard_canvas.Visibility = Visibility.Visible;
-
- TxbType.Text = "准备录制";
- BtnRecord.Visibility = Visibility.Collapsed;
- BtnRecordSuspend.Visibility = Visibility.Visible;
- BtnRecord.IsEnabled = true;
- BtnStop.IsEnabled = true;
-
- #region 录像倒计时
-
- if (APP.W_CountdownWindow == null)
- {
- APP.W_CountdownWindow = new CountdownWindow();
- APP.W_CountdownWindow.Initialize();
- }
- else
- {
- APP.W_CountdownWindow.Initialize();
- }
- APP.W_CountdownWindow.Show();
-
- #endregion 录像倒计时
-
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(3000);
-
- Dispatcher.Invoke(() =>
- {
- TxbType.Text = "正在录制";
- });
- RecordType = 1;
- StartRecord();
- }))).Start();
- });
- });
- }
- else if (RecordType == 1)
- {
- //录制中暂停
- RecordType = 2;
- }
- else if (RecordType == 2)
- {
- //暂停中继续录制
- RecordType = 1;
- }
-
- if (RecordType == 0)
- {
- TxbType.Text = "准备录制";
- BtnRecord.Visibility = Visibility.Visible;
- BtnRecordSuspend.Visibility = Visibility.Collapsed;
- BtnRecord.IsEnabled = true;
- BtnStop.IsEnabled = false;
- }
- else if (RecordType == 1)
- {
- TxbType.Text = "录制中";
- BtnRecord.Visibility = Visibility.Collapsed;
- BtnRecordSuspend.Visibility = Visibility.Visible;
- }
- else if (RecordType == 2)
- {
- TxbType.Text = "暂停中";
- BtnRecord.Visibility = Visibility.Visible;
- BtnRecordSuspend.Visibility = Visibility.Collapsed;
- }
- else if (RecordType == 3)
- {
- TxbType.Text = "倒计时";
- }
- }
-
- /// <summary>
- /// 停止录制窗口内容
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnStop_Click(object sender, RoutedEventArgs e)
- {
- #region 防止连击
-
- if (IsPressButton)
- {
- return;
- }
- else
- {
- IsPressButton = true;
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(500);
- IsPressButton = false;
- }))).Start();
- }
-
- #endregion 防止连击
-
- if (RecordType != 0)
- {
- RecordType = 0;
- blackboard_canvas.Visibility = Visibility.Collapsed;
-
- new Thread(new ThreadStart(new Action(() =>
- {
- EndRecord();
- }))).Start();
- //鼠标模式
- deviceMouse();
- }
- }
-
- //视频写入
- private VideoFileWriter videoWriter = new VideoFileWriter();
-
- //录制麦克风的声音
- private WaveInEvent waveIn = null; //new WaveInEvent();
-
- //音频写入
- private WaveFileWriter writer = null;
-
- /// <summary>
- /// 开始录制和暂停录制
- /// </summary>
- private void StartRecord()
- {
- //电子版切换笔模式
- deviceHand();
-
- VideoInfo = new Model_Video
- {
- VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
- WkType = Enum_WKVidetype.RecordingLessons
- };
-
- FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
- FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
-
- VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
-
- TempVideoPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn.avi";
- int num = 1;
- while (FileToolsCommon.IsExistFile(VideoSavePathName))
- {
- VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制_" + num + "." + VideoInfo.VideoType.ToString();
- TempVideoPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn_" + num + ".avi";
- num++;
- }
-
- TempAudioPathName = TempVideoPathName.Replace(".avi", ".mp3");
- gridActWidth = (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f) / 2) * 2;
- gridActHeight = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f) / 2) * 2;
-
- lock (this)
- {
- videoWriter.Open(
- TempVideoPathName,
- gridActWidth,
- gridActHeight,
- 5,
- VideoCodec.MPEG4,
- gridActWidth * gridActHeight * 10
- );
-
- waveIn = new WaveInEvent();
- writer = new WaveFileWriter(TempAudioPathName, waveIn.WaveFormat);
- //开始录音,写数据
- waveIn.DataAvailable += (s, a) =>
- {
- if (RecordType == 1)
- {
- writer.Write(a.Buffer, 0, a.BytesRecorded);
- }
- };
-
- //结束录音
- waveIn.RecordingStopped += (s, a) =>
- {
- writer.Dispose();
- writer = null;
- waveIn.Dispose();
- };
-
- waveIn.StartRecording();
- }
- Dispatcher.Invoke(() =>
- {
- SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
- Recorddt = DateTime.Now;
- });
-
- ///启动截图
- timer = new System.Threading.Timer(new TimerCallback(Timer_Elapsed), null, 0, 200);
- }
-
- /// <summary>
- /// 记录上次截图时间
- /// </summary>
- private DateTime Recorddt = DateTime.Now;
-
- /// <summary>
- /// 录制保存图片计时器
- /// </summary>
- /// <param name="sender">
- /// </param>
- private void Timer_Elapsed(object sender)
- {
- if (RecordType == 1)
- {
- Dispatcher.Invoke(() =>
- {
- SRTime = SRTime.AddMilliseconds(200);
-
- if (SRTime.Hour > 0)
- {
- TxbTime.Text = SRTime.ToString("HH:mm:ss");
- }
- else
- {
- TxbTime.Text = SRTime.ToString("mm:ss");
- }
- });
-
- ThreadPool.QueueUserWorkItem(o =>
- {
- RecordSaveImage();
- });
- }
- }
-
- /// <summary>
- /// 录制保存图片
- /// </summary>
- private void RecordSaveImage()
- {
- try
- {
- //保存图片
-
- try
- {
- Dispatcher.Invoke(() =>
- {
- Bitmap bm = ImageHelper.SaveUI2Bitmap(GridMain, gridActWidth, gridActHeight);
-
- videoWriter.WriteVideoFrame(bm);
- bm.Dispose();
- });
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
- }
- }
-
- /// <summary>
- /// 停止录制并生成录制文件
- /// </summary>
- private void EndRecord()
- {
- #region 恢复被禁用的按钮
-
- Dispatcher.Invoke(() =>
- {
- //打印按钮不恢复
- //BtnPrint.IsEnabled = true;
- BtnScreenshot.IsEnabled = true;
- BtnImport.IsEnabled = true;
- BtnScreenRecording.IsEnabled = true;
- BtnUpload.IsEnabled = true;
- BtnSetUp.IsEnabled = true;
- BtnDevice.IsEnabled = true;
- BtnLoginType.IsEnabled = true;
-
- //btnStop.IsEnabled = false;//停止录制按钮不可点击
- });
-
- #endregion 恢复被禁用的按钮
-
- try
- {
- #region 清空画板数据
-
- Dispatcher.Invoke(() =>
- {
- APP.PageContextData.currpage = 0;
- APP.PageContextData.pagenum = 0;
- myblackboard.clear();
-
- APP.PageDrawList.Clear();
- imgCanvas.Source = null;
- imgDocumentation.Source = null;
- imgPPT.Source = null;
- GridPage.Visibility = Visibility.Collapsed;
- });
-
- #endregion 清空画板数据
-
- Dispatcher.Invoke(() =>
- {
- BtnRecord.IsEnabled = false;
- BtnStop.IsEnabled = false;
- BtnScreenRecording.IsEnabled = false;
- });
-
- //缩略图
- string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
- FileToolsCommon.CreateDirectory(ThumbnailPath);
- //缩略图存储位置
- string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
-
- videoWriter.Close();
- waveIn.StopRecording();
- //停止截图
-
- Dispatcher.Invoke(() =>
- {
- timer.Change(-1, 0);
- timer.Dispose();
-
- TxbTime.Text = "00:00";
- TxbType.Text = "保存中";
- });
-
- FileToolsCommon.DeleteFile(ThumbnailPathName);
- VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- VideoInfo.VideoPath = VideoSavePathName;
- VideoInfo.ThumbnailPath = ThumbnailPathName;
- Console.WriteLine("生成缩略图");
-
- Console.WriteLine("合并音视频 gridActWidth:" + gridActWidth + " gridActHeight:" + gridActHeight);
-
- //APP.FFmpeg.VideoAudioMerge(VideoSynthesisPathName, AudioPathName, VideoSavePathName, gridActWidth, gridActHeight);
- FFMpegConverter ffMpeg = new FFMpegConverter();
- //ffMpeg.ConvertProgress += FfMpeg_ConvertProgress;
- FFMpegInput[] input = new FFMpegInput[] {
- new FFMpegInput(TempVideoPathName),
- new FFMpegInput(TempAudioPathName)
- };
-
- // 音视频合并
- ffMpeg.ConvertMedia(
- input,
- VideoSavePathName,
- "mp4",
- new OutputSettings() { }
- );
-
- //生成缩略图
- bool ThuRes = APP.FFmpeg.GenerateThumbnails(TempVideoPathName, ThumbnailPathName, 200, 130);
-
- VideoInfo.FileGuid = Guid.NewGuid().ToString();
- VideoInfo.IsUpload = false;
- VideoInfo.Uploaded = 0;
-
- if (!APP.VideoList.Exists(x => x.FileGuid == VideoInfo.FileGuid) || !APP.VideoList.Exists(x => x.VideoPath == VideoInfo.VideoPath))
- {
- APP.VideoList.Add(VideoInfo);
- //保存数据
- APP.SaveWkData();
- }
-
- FileToolsCommon.DeleteFile(TempVideoPathName);
- FileToolsCommon.DeleteFile(TempAudioPathName);
-
- Dispatcher.Invoke(() =>
- {
- BtnRecord.IsEnabled = true;
- BtnStop.IsEnabled = false;
- BtnPrint.IsEnabled = false;
- BtnScreenRecording.IsEnabled = true;
- TxbType.Text = "准备就绪";
- BtnRecord.Visibility = Visibility.Visible;
- BtnRecordSuspend.Visibility = Visibility.Collapsed;
- });
- }
- catch (Exception ex)
- {
- Dispatcher.Invoke(() =>
- {
- MessageWindow.Show(ex.Message);
- });
- }
- }
-
- #endregion 录制窗口
-
- #region 登录
-
- /// <summary>
- /// 登录事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnLoginType_Click(object sender, RoutedEventArgs e)
- {
- if ("未登录".Equals(TxbLoginType.Text) || ImgHeadImgN.Visibility == Visibility.Visible)
- {
- Login();
- }
- else
- {
- MessageBoxResult dr = MessageWindow.Show("确定退出登录?", "提示", MessageBoxButton.OKCancel);
- if (dr == MessageBoxResult.OK)
- {
- LoginType();
- Login();
- }
- }
- }
-
- /// <summary>
- /// 登录
- /// </summary>
- private void Login()
- {
- if (APP.W_LoginWindow == null)
- {
- APP.W_LoginWindow = new LoginWindow
- {
- WindowStartupLocation = WindowStartupLocation.CenterOwner,
- Owner = this
- };
- }
- else
- {
- APP.W_LoginWindow.Initialize();
- }
- APP.W_LoginWindow.ShowDialog();
- if (APP.IsLoginType)
- {
- string HeadpicPath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + ".png");
- if (FileToolsCommon.IsExistFile(HeadpicPath))
- {
- ImgHead.ImageSource = new BitmapImage(new Uri(HeadpicPath));
- }
- else
- {
- ImgHead.ImageSource = new BitmapImage(new Uri("pack://application:,,,/BlackImages/HM_HeadImg.png"));
- }
- TxbLoginType.Text = APP.UserInfo.Username;
- ImgHeadImgN.Visibility = Visibility.Collapsed;
- ImgHeadImg.Visibility = Visibility.Visible;
- }
- else
- {
- TxbLoginType.Text = "未登录";
- ImgHeadImgN.Visibility = Visibility.Visible;
- ImgHeadImg.Visibility = Visibility.Collapsed;
- }
- }
-
- /// <summary>
- /// 状态更改为未登录
- /// </summary>
- private void LoginType()
- {
- APP.IsLoginType = false;
- TxbLoginType.Text = "未登录";
- ImgHeadImgN.Visibility = Visibility.Visible;
- ImgHeadImg.Visibility = Visibility.Collapsed;
- APP.UserInfo = new Model_UserInfo();
- //ImgUpload.Visibility = Visibility.Collapsed;
- //ImgUploadTwo.Visibility = Visibility.Visible;
- }
-
- #endregion 登录
-
- #region 分页
-
- /// 上一页 </summary> <param name="sender"></param> <param name="e"></param>
- private void last_button_Click(object sender, RoutedEventArgs e)
- {
- if (APP.PageContextData.currpage > 1)
- {
- mouseDown = false;
- HideAngleBorder();
-
- APP.PageContextData.currpage -= 1;
- JumpPageClick();
- }
- }
-
- /// <summary>
- /// 下一页
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void next_btn_Click(object sender, RoutedEventArgs e)
- {
- if (APP.PageContextData.currpage < APP.PageContextData.pagenum)
- {
- mouseDown = false;
- HideAngleBorder();
-
- APP.PageContextData.currpage += 1;
- JumpPageClick();
- }
- }
-
- /// <summary>
- /// 跳转
- /// </summary>
- private void JumpPageClick()
- {
- myblackboard.changepage(APP.PageContextData.currpage - 1);
- ScroMain.ScrollToVerticalOffset(0);
- if (BtnImport.IsEnabled)
- {
- ///截图可用
- BtnScreenshot.IsEnabled = true;
- }
- if (APP.PageContextData.currpage <= APP.PageDrawList.Count)
- {
- if (APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation != null)
- {
- APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = true;
- }
- if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.PageContextData.currpage <= APP.PageDrawList.Count && APP.PageContextData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath))
- {
- if (APP.PageDrawList[APP.PageContextData.currpage - 1].ImgDocumentation)
- {
- if ("ppt".Equals(APP.PageDrawList[APP.PageContextData.currpage - 1].Type))
- {
- imgCanvas.Source = null;
- imgDocumentation.Source = null;
- imgPPT.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
- BtnScreenshot.IsEnabled = false;
- }
- else
- {
- imgPPT.Source = null;
- imgCanvas.Source = null;
- imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
- BtnScreenshot.IsEnabled = false;
- }
- //imgCanvas.Source = null;
- //imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
- //ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
- //ImgScreenshotTwo.Visibility = Visibility.Visible;
- //btnScreenshot.IsEnabled = false;
- }
- else
- {
- imgPPT.Source = null;
- imgDocumentation.Source = null;
- imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.PageContextData.currpage - 1].PageImagePath));
- APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = false;
- if (APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation.X > 0)
- {
- mouseDown = false;
- ImgXY();
- }
- }
- }
- else
- {
- imgPPT.Source = null;
- imgCanvas.Source = null;
- imgDocumentation.Source = null;
- }
-
- #region 修改跳转页码
-
- CbxPageList.SelectedIndex = APP.PageContextData.currpage - 1;
-
- #endregion 修改跳转页码
- }
- }
-
- private void ImgXY()
- {
- imgCanvas.Width = APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes.CenterX;
- imgCanvas.Height = APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes.CenterY;
-
- imgCanvas.Margin = new Thickness(APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation.X, APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation.Y, 0, 0);
- }
-
- #endregion 分页
-
- #region 图像缩放,移动
-
- private bool mouseDown;
- private System.Windows.Point mouseXY;
-
- private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- ContentControl img = sender as ContentControl;
- if (img == null)
- {
- return;
- }
- img.CaptureMouse();
- mouseDown = true;
- mouseXY = e.GetPosition(img);
- //Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
- }
-
- private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- ContentControl img = sender as ContentControl;
- if (img == null)
- {
- return;
- }
- img.ReleaseMouseCapture();
- mouseDown = false;
- }
-
- private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
- {
- ContentControl img = sender as ContentControl;
- if (img == null)
- {
- return;
- }
- if (mouseDown)
- {
- Domousemove(img, e);
- }
- }
-
- /// <summary>
- /// x y轴
- /// </summary>
- /// <param name="img">
- /// </param>
- /// <param name="e">
- /// </param>
- private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
- {
- if (e.LeftButton != MouseButtonState.Pressed)
- {
- return;
- }
- if (APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation)
- {
- return;
- }
- TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
- TranslateTransform transform = group.Children[1] as TranslateTransform;
- System.Windows.Point position = e.GetPosition(img);
- transform.X -= mouseXY.X - position.X;
- transform.Y -= mouseXY.Y - position.Y;
- mouseXY = position;
- APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
- {
- X = transform.X,
- Y = transform.Y
- };
- //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
- }
-
- private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
- {
- ContentControl img = sender as ContentControl;
- if (img == null)
- {
- return;
- }
- System.Windows.Point point = e.GetPosition(img);
- //Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
- System.Windows.Point PicLocate = e.GetPosition(imgCanvas);
- //Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
-
- TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
- double delta = e.Delta * 0.001;
- DowheelZoom(group, point, delta);
- }
-
- private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
- {
- System.Windows.Point pointToContent = group.Inverse.Transform(point);
- ScaleTransform transform = group.Children[0] as ScaleTransform;
- if (transform.ScaleX + delta < 0.1)
- {
- return;
- }
-
- transform.ScaleX += delta;
- transform.ScaleY += delta;
- TranslateTransform transform1 = group.Children[1] as TranslateTransform;
- transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
- transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
- //LogHelper.WriteInfoLog("【img宽高】" + imgCanvas.ActualWidth.ToString() + ":"
- // + imgCanvas.ActualHeight.ToString() + "百分比:" + transform.ScaleX.ToString() + ":" + transform.ScaleY.ToString()
- // );
-
- //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
-
- //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize = new ScaleTransform();
- //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX = transform.ScaleX;
- //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY = transform.ScaleY;
- APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
- {
- X = transform1.X,
- Y = transform1.Y
- };
- APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
- {
- CenterX = imgCanvas.ActualWidth,
- CenterY = imgCanvas.ActualHeight
- };
- APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = false;
- }
-
- #endregion 图像缩放,移动
-
- #region 拓思德点阵笔
-
- #region 值初始化
-
- // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
-
- /// <summary>
- /// A4点阵纸点阵宽度
- /// </summary>
- private const int A4_WIDTH = 5600;
-
- /// <summary>
- /// A4点阵纸点阵高度
- /// </summary>
- private const int A4_HEIGHT = 7920;
-
- ///// <summary>
- ///// 画板
- ///// </summary>
- //private Graphics graphics;
-
- /// <summary>
- /// 笔画坐标数组
- /// </summary>
- //private List<System.Drawing.Point> stroke;
-
- /// <summary>
- /// 笔序列号
- /// </summary>
- private string penSerial;
-
- /// <summary>
- /// 笔是否在点
- /// </summary>
- private bool isPenDown;
-
- //当前点阵地址
- private string currentPageSerial = string.Empty;
-
- //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
- //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
- private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
-
- #endregion 值初始化
-
- public void InitPen()
- {
- //stroke = new List<System.Drawing.Point>();
- //获取点阵笔实例,并绑定点阵笔事件
- //将授权文件内容传入,获取点阵笔对象实例
- APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
- //绑定笔连接事件
- APP.digitalPen.PenConnected += OnPenConnect;
- //绑定笔断开事件
- APP.digitalPen.PenDisconnect += OnPenDisconnect;
- //绑定笔书写输出坐标事件
- APP.digitalPen.PenCoordinate += OnPenCoordinate;
- //绑定抬笔事件
- APP.digitalPen.PenUp += OnPenUp;
- //绑定落笔事件
- APP.digitalPen.PenDown += OnPenDown;
- APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
- APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
- //完成初始化点阵笔,开始与点阵笔通信
- ERROR_CODE ER = APP.digitalPen.Start();
-
- ////绑定笔在新的点阵地址页面书写事件
- //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
- ////绑定笔信息事件
- //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
- //启动接收笔数据,完成初始化工作
- ERROR_CODE rc = APP.digitalPen.Start();
- //判断是否成功
- if (ER != ERROR_CODE.ERROR_OK)
- {
- MessageWindow.Show("初始化失败,授权过期,返回值:" + ER.ToString());
- }
- }
-
- /// <summary>
- /// 落笔
- /// </summary>
- /// <param name="time">
- /// 时间戳,1970年1月1日到现在的总毫秒数
- /// </param>
- /// <param name="penSerial">
- /// 点阵笔序列号
- /// </param>
- /// <param name="penType">
- /// 点阵笔型号编号
- /// </param>
- private void OnPenDown(ulong time, string penSerial, int penType)
- {
- if (CheckAccess())
- {
- Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
- Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
- }
- else
- {
- //labPenSerial.Text = penSerial;
- //labPenStatus.Text = "PenDown";
- isPenDown = true;
-
- //Dispatcher.Invoke(new Action(() =>
- //{
- // for (int i = 0; i < APP.PageDrawList.Count; i++)
- // {
- // if (APP.PageDrawList[i].PageCode == penSerial)
- // {
- // if (i < APP.pageData.pagenum)
- // {
- // if (i < APP.pageData.currpage)
- // {
- // int num = APP.pageData.currpage - i;
- // APP.pageData.currpage -= num;
- // myblackboard.changepage(APP.pageData.currpage - 1);
- // if (APP.PageDrawList.Count > 0)
- // {
- // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
- // {
- // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
-
- // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
- // }
- // else
- // {
- // imgCanvas.Source = null;
- // }
- // }
- // }
- // else
- // {
- // int num = i - APP.pageData.currpage;
- // APP.pageData.currpage += num;
- // myblackboard.changepage(APP.pageData.currpage - 1);
- // if (APP.PageDrawList.Count > 0)
- // {
- // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
- // {
- // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
- // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
- // }
- // else
- // {
- // imgCanvas.Source = null;
- // }
- // }
- // }
- // }
- // return;
- // }
- // }
- // //myblackboard.changepages(0, 0, true);
- // //myblackboard.changepaget(0, 0, true, blackboard_canvas);
- //}));
- }
- //myblackboard.changepages(0, 0, true);
- }
-
- /// <summary>
- /// 抬笔
- /// </summary>
- /// <param name="time">
- /// 时间戳,1970年1月1日到现在的总毫秒数
- /// </param>
- /// <param name="penSerial">
- /// 点阵笔序列号
- /// </param>
- /// <param name="penType">
- /// 点阵笔型号编号
- /// </param>
- private void OnPenUp(ulong time, string penSerial, int penType)
- {
- if (CheckAccess())
- {
- Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
- Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
- }
- else
- {
- isPenDown = false;
- APP.PenSerial = penSerial;
- //int leftPoints = stroke.Count % 3;
- //if (0 != leftPoints)
- //{
- // int from = stroke.Count - leftPoints - 1;
- // if (from < 0)
- // from = 0;
- // int to = stroke.Count - 1;
- // DrawCoordinates(from, to);
- //}
- //stroke.Clear();
- }
- if (APP.PageContextData.currpage > 0)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- myblackboard.changepages(0, 0, true, Color, PenSize, APP.PageContextData.currpage - 1, 0);
- }));
- }
- }
-
- /// <summary>
- /// 笔断开
- /// </summary>
- /// <param name="time">
- /// 时间戳,1970年1月1日到现在的总毫秒数
- /// </param>
- /// <param name="penSerial">
- /// 点阵笔序列号
- /// </param>
- /// <param name="penType">
- /// 点阵笔型号编号
- /// </param>
- private void OnPenDisconnect(ulong time, string penSerial, int penType)
- {
- if (CheckAccess())
- {
- Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
- Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
- }
- else
- {
- APP.PenSerial = penSerial;
- APP.PenStatus = false;
- UpdateDevStatus();
- //Dispatcher.Invoke(new Action(() =>
- //{
- // txbNotConnected.Text = "未连接";
- // txbNotConnecteds.Text = "未连接";
- //}));
- }
- }
-
- /// <summary>
- /// 笔连接
- /// </summary>
- /// <param name="time">
- /// 时间戳,1970年1月1日到现在的总毫秒数
- /// </param>
- /// <param name="penSerial">
- /// 点阵笔序列号
- /// </param>
- /// <param name="penType">
- /// 点阵笔型号编号
- /// </param>
- private void OnPenConnect(ulong time, string penSerial, int penType)
- {
- if (CheckAccess())
- {
- Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
- Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
- }
- else
- {
- APP.PenSerial = penSerial;
- APP.PenStatus = true;
- this.penSerial = penSerial;
- //连接后,在获取笔数据前,可以清除笔内的历史数据
- //APP.digitalPen.ClearMemory(penSerial);
-
- //开始接收笔数据
- APP.digitalPen.GetPenData(penSerial);
- UpdateDevStatus();
- }
- }
-
- /// <summary>
- /// 电池电量
- /// </summary>
- /// <param name="time">
- /// </param>
- /// <param name="penSerial">
- /// </param>
- /// <param name="penType">
- /// </param>
- /// <param name="capacity">
- /// </param>
- private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
- {
- if (CheckAccess())
- {
- Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
- Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
- }
- else
- {
- //System.Windows.MessageWindow.Show("电池电量:" + capacity.ToString());
- }
- }
-
- /// <summary>
- /// 已用存储
- /// </summary>
- /// <param name="time">
- /// </param>
- /// <param name="penSerial">
- /// </param>
- /// <param name="penType">
- /// </param>
- /// <param name="fillLevel">
- /// </param>
- private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
- {
- if (CheckAccess())
- {
- Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
- Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
- }
- else
- {
- //System.Windows.MessageWindow.Show("存储:" + fillLevel.ToString());
- }
- }
-
- /// <summary>
- /// 笔书写,收到坐标
- /// </summary>
- /// <param name="time">
- /// 时间戳,1970年1月1日到现在的总毫秒数
- /// </param>
- /// <param name="penSerial">
- /// 点阵笔序列号
- /// </param>
- /// <param name="penType">
- /// 点阵笔型号编号
- /// </param>
- /// <param name="pageSerial">
- /// 点阵地址
- /// </param>
- /// <param name="cx">
- /// x坐标
- /// </param>
- /// <param name="cy">
- /// y坐标
- /// </param>
- /// <param name="force">
- /// 压力值
- /// </param>
- private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
- {
- if (CheckAccess())
- {
- Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
- Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
- }
- else
- {
- //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
- if (!isPenDown)
- {
- return;
- }
- //stroke.Add(new System.Drawing.Point(cx, cy));
-
- double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
- double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
- //点
- double tempX = cx * PropW;
- double tempY = cy * PropH;
- //pageSerial //点阵IP地址 与打印的页面关联
- if (APP.PageContextData.currpage > 0)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- float Pressure = force / 100f;
- //myblackboard.changepages(testX, testY,false);
- myblackboard.changepages(tempX, tempY, false, Color, PenSize, APP.PageContextData.currpage - 1, Pressure);
-
- #region 设置滚动条位置
-
- //点在显示页面上方
- if (tempY < ScroMain.VerticalOffset)
- {
- //滚动条当前位置
- double RollCurrentLocation = ScroMain.VerticalOffset;
- //向上滚动至以点为中心需要滚动的距离
- double UpRoll = (RollCurrentLocation - tempY) + (ScroMain.ActualHeight / 2);
- //如果小于0则等于0
- double RollLocation = RollCurrentLocation - UpRoll;
- if (RollLocation < 0)
- {
- RollLocation = 0;
- }
- ////滚动条实际偏移量
- //double RollOffset = RollCurrentLocation - RollLocation;
- ScroMain.ScrollToVerticalOffset(RollLocation);
- }
- //点在显示页面下方
- if (tempY > ScroMain.VerticalOffset + ScroMain.ActualHeight)
- {
- //滚动条当前位置
- double RollCurrentLocation = ScroMain.VerticalOffset;
- //向下滚动至以点为中心需要滚动的距离
- double DownRoll = (tempY - RollCurrentLocation) - (ScroMain.ActualHeight / 2);
- //如果小于0则等于0
- double RollLocation = RollCurrentLocation + DownRoll;
- //滚动条最大滚动值
- double ScrollbarMaxNum = GridM.ActualHeight - ScroMain.ActualHeight;
- if (RollLocation > ScrollbarMaxNum)
- {
- RollLocation = ScrollbarMaxNum;
- }
- ////滚动条实际偏移量
- //double RollOffset = RollLocation-RollCurrentLocation;
- ScroMain.ScrollToVerticalOffset(RollLocation);
- }
-
- #endregion 设置滚动条位置
-
- //gridM.Height //A4高度
- //ScroMain.VerticalOffset;//获取滚动条位置
- //ScroMain.ActualHeight//A4纸显示高度
- //ScroMain.ScrollToHorizontalOffset()//设置滚动条位置
-
- //Mouse.GetPosition(this)
- if (tempX > 0 && tempY > 0)
- {
- //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
- System.Windows.Point getP = ScroMain.PointToScreen(new System.Windows.Point(tempX, tempY - ScroMain.VerticalOffset));
- SetCursorPos((int)getP.X, (int)getP.Y);
- }
- }));
- }
-
- ////每3个点画一条曲线
- //if (stroke.Count % 3 == 0)
- //{
- // int from = stroke.Count - 3 - 1;
- // if (from < 0)
- // from = 0;
- // int to = stroke.Count - 1;
- // DrawCoordinates(from, to);
- //}
- }
- }
-
- /// <summary>
- /// 停止笔
- /// </summary>
- public void StopDigitalPen()
- {
- //停止,释放资源
- APP.digitalPen.Stop();
- }
-
- /// <summary>
- /// 清空笔内存储
- /// </summary>
- public void ClearPenStorage()
- {
- if (!string.IsNullOrEmpty(penSerial))
- {
- APP.digitalPen.ClearMemory(penSerial);
- }
- }
-
- /// <summary>
- /// 获取剩余电量
- /// </summary>
- public void GetPenElectricityQuantity()
- {
- if (!string.IsNullOrEmpty(penSerial))
- {
- APP.digitalPen.GetBatteryCapacity(penSerial);
- }
- }
-
- /// <summary>
- /// 获取存储空间
- /// </summary>
- public void GetUsedStorage()
- {
- if (!string.IsNullOrEmpty(penSerial))
- {
- APP.digitalPen.GetMemoryFillLevel(penSerial);
- }
- }
-
- /// <summary>
- /// 开启悬浮
- /// </summary>
- public void 开启悬浮()
- {
- if (!string.IsNullOrEmpty(penSerial))
- {
- APP.digitalPen.SetPenHoverMode(true, penSerial);
- }
- }
-
- /// <summary>
- /// 关闭悬浮
- /// </summary>
- public void 关闭悬浮()
- {
- if (!string.IsNullOrEmpty(penSerial))
- {
- APP.digitalPen.SetPenHoverMode(false, penSerial);
- }
- }
-
- /// <summary>
- /// 引用user32.dll动态链接库(windows api), 使用库中定义 API:SetCursorPos 设置光标位置
- /// </summary>
- [System.Runtime.InteropServices.DllImport("user32.dll")]
- private static extern int SetCursorPos(int x, int y);
-
- #endregion 拓思德点阵笔
-
- #region 写字板模式
-
- #region 值初始化
-
- [System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
- public static extern void OutputDebugString(string message);
-
- public bool usbIsConnected = false;
-
- //Angle angle = Angle._270;
- private eDeviceType deviceType = eDeviceType.Unknow;
-
- ///// <summary>
- ///// 点缩放比例
- ///// </summary>
- //private double m_nCompress = 0;
- //private double m_nCompress_x = 0;
- //private double m_nCompress_y = 0;
-
- ///// <summary>
- ///// 0:画布根据板子适配
- ///// 1:板子根据画布适配
- ///// </summary>
- //private int type = 1;//默认画笔根据板子适配
- //bool bScreenO = false;//判断是否是横屏,默认横屏,true:横屏幕;false:竖屏
- //Drawing drawing;
-
- //List<RobotPoint> plist = new List<RobotPoint>();
-
- //画布宽高
- //private int m_nDeviceW = 21000;
- //private int m_nDeviceH = 29700;
- private int m_nDeviceW = 22600;
-
- private int m_nDeviceH = 16650;
- private RobotpenGateway.robotpenController.returnPointData date = null;
-
- //private int nResource = 0;
- //private ReportRate RR = ReportRate.R_200;
- //string Mac = string.Empty;
-
- //int Recog_create = 0;
- //int Recog_adddate = 0;
- //int Recog_start = 0;
-
- public bool isOpen = true;
-
- //PrintType ptype = PrintType.NoMarkCode_FB2;
- //int pageData = 0;
-
- //bool AreSynchronized = false;
- /// <summary>
- /// 是否为笔模式
- /// </summary>
- private bool IsPen = false;
-
- private bool IsT8 = true;
-
- #endregion 值初始化
-
- #region 罗博智慧笔
-
- /// <summary>
- /// 笔模式
- /// </summary>
- private void deviceHand()
- {
- IsPen = true;
- if (APP.IsOutputInfoLog)
- {
- LogHelper.WriteInfoLog(string.Format("切换笔模式:设备类型:{0}", deviceType.ToString()));
- }
- if (deviceType == eDeviceType.T8B_D2 || deviceType == eDeviceType.T8Y || deviceType == eDeviceType.T8S_LQ || deviceType == eDeviceType.T8C)
- {
- IsT8 = true;
- robotpenController.GetInstance().setDeviceMode(eDeviceMode.DEVICE_HAND);
- if (APP.IsOutputInfoLog)
- {
- LogHelper.WriteInfoLog("使用robotpenController.GetInstance().setDeviceMode(eDeviceMode.DEVICE_HAND)切换");
- }
- }
- else
- {
- IsT8 = false;
- //获取当前设备模式,根据模式切换鼠标和笔
- robotpenController.GetInstance()._Send(cmdId.SearchMode);
- if (APP.IsOutputInfoLog)
- {
- LogHelper.WriteInfoLog("发送(cmdId.SearchMode)");
- }
- }
- }
-
- /// <summary>
- /// 鼠标模式
- /// </summary>
- private void deviceMouse()
- {
- IsPen = false;
- if (deviceType == eDeviceType.T8B_D2 || deviceType == eDeviceType.T8Y || deviceType == eDeviceType.T8S_LQ)
- {
- IsT8 = true;
- robotpenController.GetInstance().setDeviceMode(eDeviceMode.DEVICE_MOUSE);
- if (APP.IsOutputInfoLog)
- {
- LogHelper.WriteInfoLog("使用robotpenController.GetInstance().setDeviceMode(eDeviceMode.DEVICE_MOUSE)切换");
- }
- }
- else
- {
- IsT8 = false;
- //获取当前设备模式,根据模式切换鼠标和笔
- robotpenController.GetInstance()._Send(cmdId.SearchMode);
- if (APP.IsOutputInfoLog)
- {
- LogHelper.WriteInfoLog("发送(cmdId.SearchMode)");
- }
- }
- }
-
- private void Form1_searchModeEvt(int modeType)
- {
- //笔模式
- if (modeType == 1)
- {
- if (APP.IsOutputInfoLog)
- {
- LogHelper.WriteInfoLog("当前为笔模式时,切换回鼠标模式");
- }
- //当前为笔模式时 切换回鼠标模式
- if (!IsPen && !IsT8)
- {
- robotpenController.GetInstance()._Send(cmdId.SwitchMode);
- if (APP.IsOutputInfoLog)
- {
- LogHelper.WriteInfoLog("T7设备切换成鼠标模式._Send(cmdId.SwitchMode)");
- }
- }
- }
- else
- {
- if (APP.IsOutputInfoLog)
- {
- LogHelper.WriteInfoLog("当前为鼠标模式 切换为笔模式");
- }
- //当前为鼠标模式 切换为笔模式
- if (isOpen && !IsT8)
- {
- robotpenController.GetInstance()._Send(cmdId.SwitchMode);
- if (APP.IsOutputInfoLog)
- {
- LogHelper.WriteInfoLog("T7设备切换成笔模式._Send(cmdId.SwitchMode)");
- }
- }
- }
- }
-
- private void Form1_switchModeEvt(int modeType)
- {
- if (modeType == 1)
- {
- if (APP.IsOutputInfoLog)
- {
- LogHelper.WriteInfoLog("当前为笔模式");
- }
- if (!IsPen)
- {
- deviceMouse();
- }
- }
- else
- {
- if (APP.IsOutputInfoLog)
- {
- LogHelper.WriteInfoLog("当前为鼠标模式");
- }
- if (IsPen)
- {
- deviceHand();
- }
- }
- }
-
- //初始化笔服务
- private void InitlbPen()
- {
- try
- {
- robotpenController.GetInstance()._ConnectInitialize(eDeviceType.Gateway, IntPtr.Zero);
- robotpenController.GetInstance().deviceChangeEvt += new robotpenController.DeviceChange(Form1_deviceChangeEvt);
- robotpenController.GetInstance().searchModeEvt += Form1_searchModeEvt;
- robotpenController.GetInstance().switchModeEvt += Form1_switchModeEvt;
-
- //// 所有设备均注册该页码显示消息 目前只有T9设备才会有页码识别功能, 客户代码可以根据设备来判断是否消费该事件
- //robotpenController.GetInstance().showPageEvt += new robotpenController.ShowPage(Form1_showPageEvt);
- // T8A 按键消息 为了适应其他demo也能响应, 所以任何demo都消费此事件, 客户代码可根据设备类型判断是否消费此事件
- robotpenController.GetInstance().keyPressEvt += new robotpenController.KeyPress(Form1_keyPressEvt);
-
- //robotpenController.GetInstance().PageSensorCallback_Evt += Rbtnet__PageSensorEvt_;
-
- date = new robotpenController.returnPointData(Form1_bigDataReportEvt1);
- robotpenController.GetInstance().initDeletgate(ref date);
-
- CheckUsbConnect();
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("设备初始化失败:" + ex.Message, ex);
- }
- }
-
- /// <summary>
- /// 委托实例函数,用于异步修改listview显示的USB连接设备信息
- /// </summary>
- private void SetListView()
- {
- if (usbIsConnected)
- {
- robotpenController.GetInstance()._CloseConnect();
- }
- CheckUsbConnect();
- }
-
- /// <summary>
- /// 设备插拔消息,更新listview
- /// </summary>
- /// <param name="bStatus">
- /// </param>
- /// <param name="uPid">
- /// </param>
- private void Form1_deviceChangeEvt(bool bStatus, ushort uPid)
- {
- //throw new NotImplementedException();
- //Console.WriteLine();
- try
- {
- if (APP.IsOutputInfoLog)
- {
- LogHelper.WriteInfoLog(string.Format("设备状态{0} PID = {1}", bStatus, uPid));
- }
- }
- catch (Exception)
- {
- }
- //SetListView();
- CheckUsbConnect();
- }
-
- /// <summary>
- /// 书写
- /// </summary>
- /// ///
- /// <param name="bIndex">
- /// </param>
- /// <param name="bPenStatus">
- /// </param>
- /// <param name="bx">
- /// </param>
- /// <param name="by">
- /// </param>
- /// <param name="bPress">
- /// </param>
- private void Form1_bigDataReportEvt1(byte bIndex, byte bPenStatus, short bx, short by, short bPress)
- {
- if (bx == 0 && by == 0 && bPenStatus == 0 && bPress == 0)
- {
- return;
- }
- //17是按下,16是抬起
- if (bPenStatus == 16 || bPenStatus == 0)
- {
- //stroke.Clear();
- if (APP.PageContextData.currpage > 0)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- myblackboard.changepages(0, 0, true, Color, PenSize, APP.PageContextData.currpage - 1, 0);
- }));
- }
- }
-
- double PropW = blackboard_canvas.ActualWidth / m_nDeviceH;
- double PropH = blackboard_canvas.ActualHeight / m_nDeviceW;
- //点
- double tempY = (m_nDeviceW - bx) * PropH;
- double tempX = by * PropW;
- //pageSerial //点阵IP地址 与打印的页面关联
- if (APP.PageContextData.currpage > 0)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- float Pressure = bPress / 100f;
- //myblackboard.changepages(testX, testY,false);
-
- if (bPress > 0)
- {
- myblackboard.changepages(tempX, tempY, false, Color, PenSize, APP.PageContextData.currpage - 1, Pressure);
- }
-
- #region 设置滚动条位置
-
- //点在显示页面上方
- if (tempY < ScroMain.VerticalOffset)
- {
- //滚动条当前位置
- double RollCurrentLocation = ScroMain.VerticalOffset;
- //向上滚动至以点为中心需要滚动的距离
- double UpRoll = (RollCurrentLocation - tempY) + (ScroMain.ActualHeight / 2);
- //如果小于0则等于0
- double RollLocation = RollCurrentLocation - UpRoll;
- if (RollLocation < 0)
- {
- RollLocation = 0;
- }
- ////滚动条实际偏移量
- //double RollOffset = RollCurrentLocation - RollLocation;
- ScroMain.ScrollToVerticalOffset(RollLocation);
- }
- //点在显示页面下方
- if (tempY > ScroMain.VerticalOffset + ScroMain.ActualHeight)
- {
- //滚动条当前位置
- double RollCurrentLocation = ScroMain.VerticalOffset;
- //向下滚动至以点为中心需要滚动的距离
- double DownRoll = (tempY - RollCurrentLocation) - (ScroMain.ActualHeight / 2);
- //如果小于0则等于0
- double RollLocation = RollCurrentLocation + DownRoll;
- //滚动条最大滚动值
- double ScrollbarMaxNum = GridM.ActualHeight - ScroMain.ActualHeight;
- if (RollLocation > ScrollbarMaxNum)
- {
- RollLocation = ScrollbarMaxNum;
- }
- ////滚动条实际偏移量
- //double RollOffset = RollLocation-RollCurrentLocation;
- ScroMain.ScrollToVerticalOffset(RollLocation);
- }
-
- #endregion 设置滚动条位置
-
- if (tempX > 0 && tempY > 0)
- {
- //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
- System.Windows.Point getP = ScroMain.PointToScreen(new System.Windows.Point(tempX, tempY - ScroMain.VerticalOffset));
- SetCursorPos((int)getP.X, (int)getP.Y);
- }
- }));
- }
- }
-
- /// <summary>
- /// 判断是否有设备连接
- /// </summary>
- public void CheckUsbConnect()
- {
- usbIsConnected = false;
- Thread.Sleep(200);
- int nDeviceCount = robotpenController.GetInstance()._GetDeviceCount();
- if (APP.IsOutputInfoLog)
- {
- LogHelper.WriteInfoLog(string.Format("当前有 {0} 个设备", nDeviceCount));
- }
- if (nDeviceCount > 0)
- {
- //this.listView1.BeginUpdate();
- for (int i = 0; i < nDeviceCount; ++i)
- {
- ushort npid = 0;
- ushort nvid = 0;
- string strDeviceName = string.Empty;
- eDeviceType dtype = eDeviceType.Unknow;
- if (robotpenController.GetInstance()._GetAvailableDevice(i, ref npid, ref nvid, ref strDeviceName, ref dtype))
- {
- if (!usbIsConnected)
- {
- usbIsConnected = true;
- deviceType = dtype;
- robotpenController.GetInstance()._ConnectInitialize(deviceType, IntPtr.Zero);
- int nRes = robotpenController.GetInstance()._ConnectOpen();
- if (nRes != 0)
- {
- //LogHelper.WriteInfoLog(string.Format(@"x={0},y={1},s={2},p={3}", bx, by, bPenStatus, bPress));
- LogHelper.WriteErrLog("设备自动连接失败,请重新插拔设备或尝试手动连接!", null);
- usbIsConnected = false;
- break;
- }
- //robotpenController.GetInstance()._Send(cmdId.SwitchMode);
- robotpenController.GetInstance()._Send(cmdId.GetConfig);
-
- APP.BoardStatus = true;
- try
- {
- int banWidth = robotpenController.GetInstance().getWidth();
- int banHeight = robotpenController.GetInstance().getHeight();
- if (banWidth > 0 && banHeight > 0)
- {
- if (banWidth > banHeight)
- {
- m_nDeviceW = banWidth;
- m_nDeviceH = banHeight;
- }
- else
- {
- m_nDeviceW = banHeight;
- m_nDeviceH = banWidth;
- }
- }
-
- if (APP.IsOutputInfoLog)
- {
- LogHelper.WriteInfoLog(string.Format("手写板宽度为:{0} 高度为:{1}", m_nDeviceW, m_nDeviceH));
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("手写板大小获取失败:" + ex.Message, ex);
- }
- UpdateDevStatus();
- if (APP.IsOutputInfoLog)
- {
- LogHelper.WriteInfoLog(string.Format("设备类型:{0}", deviceType.ToString()));
- }
-
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(500);
-
- robotpenController.GetInstance()._Send(cmdId.SearchMode);
- }))).Start();
- }
- }
- }
- }
- else
- {
- APP.BoardStatus = false;
- UpdateDevStatus();
- }
- }
-
- /// <summary>
- /// 按键回调函数
- /// </summary>
- /// <param name="Value">
- /// </param>
- private void Form1_keyPressEvt(eKeyPress Value)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- switch (Value)
- {
- case eKeyPress.CLICK:
- break;
-
- case eKeyPress.DBCLICK:
- break;
-
- case eKeyPress.PAGEUP:
- last_button_Click(null, null);
- break;
-
- case eKeyPress.PAGEDOWN:
- next_btn_Click(null, null);
- break;
-
- case eKeyPress.CREATEPAGE://关机键
- break;
-
- case eKeyPress.KEY_A:
- break;
-
- case eKeyPress.KEY_B:
- break;
-
- case eKeyPress.KEY_C:
- break;
-
- case eKeyPress.KEY_D:
- break;
-
- case eKeyPress.KEY_E:
- break;
-
- case eKeyPress.KEY_F:
- break;
-
- case eKeyPress.KEY_UP:
- last_button_Click(null, null);
- break;
-
- case eKeyPress.KEY_DOWN:
- next_btn_Click(null, null);
- break;
-
- case eKeyPress.KEY_YES:
- break;
-
- case eKeyPress.KEY_NO:
- break;
-
- case eKeyPress.KEY_CANCEL:
- break;
-
- case eKeyPress.KEY_OK:
- break;
-
- case eKeyPress.PAGEUPCLICK://上一页
- last_button_Click(null, null);
- break;
-
- case eKeyPress.PAGEUPDBCLICK://双击上一页
- break;
-
- case eKeyPress.PAGEUPPRESS://长按上一页
- break;
-
- case eKeyPress.PAGEDOWNCLICK://下一页
- next_btn_Click(null, null);
- break;
-
- case eKeyPress.PAGEDOWNDBCLICK://双击下一页
- break;
-
- case eKeyPress.PAGEDOWNPRESS://长按下一页
- break;
- }
- }));
- }
-
- #endregion 罗博智慧笔
-
- /// <summary>
- /// 更新设备状态显示
- /// </summary>
- public void UpdateDevStatus()
- {
- if (APP.BoardStatus && (APP.PenStatus || APP.TQLPenStatus))
- {
- Dispatcher.Invoke(new Action(() =>
- {
- txbNotConnected.Text = "笔/板已连接";
- txbNotConnecteds.Text = "笔/板已连接";
- }));
- }
- else if (APP.BoardStatus)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- txbNotConnected.Text = "手写板已连接";
- txbNotConnecteds.Text = "手写板已连接";
- }));
- }
- else if (APP.PenStatus)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- txbNotConnected.Text = "智能笔已连接";
- txbNotConnecteds.Text = "智能笔已连接";
- }));
- }
- else if (APP.TQLPenStatus)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- txbNotConnected.Text = "智能笔已连接";
- txbNotConnecteds.Text = "智能笔已连接";
- }));
- }
- else
- {
- Dispatcher.Invoke(new Action(() =>
- {
- txbNotConnected.Text = "未连接";
- txbNotConnecteds.Text = "未连接";
- }));
- }
- }
-
- #endregion 写字板模式
-
- #region 腾千里手写笔
-
- /// <summary>
- /// 是否在书写
- /// </summary>
- private bool isTQLPenDown = false;
-
- /// <summary>
- /// TQL点阵笔宽高
- /// </summary>
- private static float TQLA4_WIDTH = (float)2480 / (float)300 * (float)25.4 / (float)1.524; //(float)1075 / (float)150 * (float)25.4 / (float)1.524; //OID4
-
- private static float TQLA4_HEIGHT = (float)3509 / (float)300 * (float)25.4 / (float)1.524;//(float)1512 / (float)150 * (float)25.4 / (float)1.524;
-
- /// <summary>
- /// TQL初始化
- /// </summary>
- public void InitTQLPPen()
- {
- if (APP.TQLPenevents == null)
- {
- APP.TQLPenevents = new PenEvents(1);
- }
- else
- {
- APP.TQLPenevents.InToType = 1;
- }
- }
-
- /// <summary>
- /// 笔落下
- /// </summary>
- public void TQLDown()
- {
- isTQLPenDown = true;
-
- if (APP.PageContextData.currpage > 0)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- myblackboard.changepages(0, 0, true, Color, PenSize, APP.PageContextData.currpage - 1, 0);
- }));
- }
- }
-
- /// <summary>
- /// 笔抬起
- /// </summary>
- public void TQLUp()
- {
- isTQLPenDown = false;
- //stroke.Clear();
- if (APP.PageContextData.currpage > 0)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- myblackboard.changepages(0, 0, true, Color, PenSize, APP.PageContextData.currpage - 1, 0);
- }));
- }
- }
-
- /// <summary>
- /// 笔书写
- /// </summary>
- /// <param name="cx">
- /// </param>
- /// <param name="cy">
- /// </param>
- /// <param name="force">
- /// </param>
- public void TQLPenWrite(double cx, double cy, int force)
- {
- //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
- if (!isTQLPenDown)
- {
- return;
- }
- double PropW = blackboard_canvas.ActualWidth / TQLA4_WIDTH;
- double PropH = blackboard_canvas.ActualHeight / TQLA4_HEIGHT;
- //点
- double tempX = cx * PropW;
- double tempY = cy * PropH;
-
- if (APP.PageContextData.currpage > 0)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- //0~1023,亦即有 1024 阶供应用软件后续应用之用,如笔锋笔触,暂无用
- float Pressure = (float)force / 1023f;
- myblackboard.changepages(tempX, tempY, false, Color, PenSize, APP.PageContextData.currpage - 1, Pressure);
-
- #region 设置滚动条位置
-
- //点在显示页面上方
- if (tempY < ScroMain.VerticalOffset)
- {
- //滚动条当前位置
- double RollCurrentLocation = ScroMain.VerticalOffset;
- //向上滚动至以点为中心需要滚动的距离
- double UpRoll = (RollCurrentLocation - tempY) + (ScroMain.ActualHeight / 2);
- //如果小于0则等于0
- double RollLocation = RollCurrentLocation - UpRoll;
- if (RollLocation < 0)
- {
- RollLocation = 0;
- }
- ////滚动条实际偏移量
- //double RollOffset = RollCurrentLocation - RollLocation;
- ScroMain.ScrollToVerticalOffset(RollLocation);
- }
- //点在显示页面下方
- if (tempY > ScroMain.VerticalOffset + ScroMain.ActualHeight)
- {
- //滚动条当前位置
- double RollCurrentLocation = ScroMain.VerticalOffset;
- //向下滚动至以点为中心需要滚动的距离
- double DownRoll = (tempY - RollCurrentLocation) - (ScroMain.ActualHeight / 2);
- //如果小于0则等于0
- double RollLocation = RollCurrentLocation + DownRoll;
- //滚动条最大滚动值
- double ScrollbarMaxNum = GridM.ActualHeight - ScroMain.ActualHeight;
- if (RollLocation > ScrollbarMaxNum)
- {
- RollLocation = ScrollbarMaxNum;
- }
- ////滚动条实际偏移量
- //double RollOffset = RollLocation-RollCurrentLocation;
- ScroMain.ScrollToVerticalOffset(RollLocation);
- }
-
- #endregion 设置滚动条位置
-
- if (tempX > 0 && tempY > 0)
- {
- System.Windows.Point getP = ScroMain.PointToScreen(new System.Windows.Point(tempX, tempY - ScroMain.VerticalOffset));
- SetCursorPos((int)getP.X, (int)getP.Y);
- }
- }));
- }
- }
-
- #endregion 腾千里手写笔
-
- #region 图片拉伸移动
-
- private System.Windows.Point initialPoint;
-
- /// <summary>
- /// 隐藏图片四个点和线
- /// </summary>
- private void HideAngleBorder()
- {
- RectLeftUp.Visibility = Visibility.Hidden;
- RectRightUp.Visibility = Visibility.Hidden;
- RectLeftDown.Visibility = Visibility.Hidden;
- RectRightDown.Visibility = Visibility.Hidden;
- RectImgBorder.Visibility = Visibility.Hidden;
- }
-
- private void ShowAngleBorder()
- {
- PointLocation();
- RectLeftUp.Visibility = Visibility.Visible;
- RectRightUp.Visibility = Visibility.Visible;
- RectLeftDown.Visibility = Visibility.Visible;
- RectRightDown.Visibility = Visibility.Visible;
- RectImgBorder.Visibility = Visibility.Visible;
- }
-
- /// <summary>
- /// 确定四个点和边框的位置大小
- /// </summary>
- private void PointLocation()
- {
- RectImgBorder.Width = imgCanvas.ActualWidth + 10.0;
- RectImgBorder.Height = imgCanvas.ActualHeight + 10.0;
- RectImgBorder.Margin = new Thickness(imgCanvas.Margin.Left - 5.0, imgCanvas.Margin.Top - 5.0, 0, 0);
-
- Canvas.SetLeft(RectLeftUp, imgCanvas.Margin.Left - 10.0);
- Canvas.SetTop(RectLeftUp, imgCanvas.Margin.Top - 10.0);
-
- Canvas.SetLeft(RectRightUp, imgCanvas.Margin.Left + imgCanvas.ActualWidth - 10.0);
- Canvas.SetTop(RectRightUp, imgCanvas.Margin.Top - 10.0);
-
- Canvas.SetLeft(RectLeftDown, imgCanvas.Margin.Left - 10.0);
- Canvas.SetTop(RectLeftDown, imgCanvas.Margin.Top + imgCanvas.ActualHeight - 10.0);
-
- Canvas.SetLeft(RectRightDown, imgCanvas.Margin.Left + imgCanvas.ActualWidth - 10.0);
- Canvas.SetTop(RectRightDown, imgCanvas.Margin.Top + imgCanvas.ActualHeight - 10.0);
- }
-
- private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
- {
- System.Windows.Point point = e.GetPosition(imgCanvas);
- initialPoint = point;
-
- HideAngleBorder();
- }
-
- private void imgCanvas_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
- {
- if (e.LeftButton == MouseButtonState.Pressed && mouseDown)
- {
- System.Windows.Point point = e.GetPosition(imgCanvas);
- imgCanvas.Margin = new Thickness(imgCanvas.Margin.Left + (point.X - initialPoint.X), imgCanvas.Margin.Top + (point.Y - initialPoint.Y), 0, 0);
- APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
- {
- X = imgCanvas.Margin.Left,
- Y = imgCanvas.Margin.Top
- };
- APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
- {
- CenterX = imgCanvas.ActualWidth,
- CenterY = imgCanvas.ActualHeight
- };
-
- APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = false;
- }
- }
-
- private void imgCanvas_MouseUp(object sender, MouseButtonEventArgs e)
- {
- if (mouseDown)
- {
- ShowAngleBorder();
- }
- }
-
- private System.Drawing.PointF imgRightDown;
-
- /// <summary>
- /// 设置控件最上层
- /// </summary>
- /// <param name="element">
- /// </param>
- public void BringToFront(Thumb element)//图片置于最顶层显示
- {
- if (element == null)
- {
- return;
- }
-
- Canvas parent = element.Parent as Canvas;
- if (parent == null)
- {
- return;
- }
-
- int maxZ = parent.Children.OfType<UIElement>()//linq语句,取Zindex的最大值
- .Where(x => x != element)
- .Select(x => Canvas.GetZIndex(x))
- .Max();
- Canvas.SetZIndex(element, maxZ + 1);
- }
-
- private void RectRightUp_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
- {
- try
- {
- Thumb thu = (Thumb)sender;
- BringToFront(thu);
-
- imgRightDown = new System.Drawing.PointF((float)(imgCanvas.Margin.Left + imgCanvas.ActualWidth), (float)(imgCanvas.Margin.Top + imgCanvas.ActualHeight));
- HideAngleBorder();
- switch (thu.Name)
- {
- case "RectLeftUp":
- RectLeftUp.Visibility = Visibility.Visible;
- break;
-
- case "RectRightUp":
- RectRightUp.Visibility = Visibility.Visible;
- break;
-
- case "RectLeftDown":
- RectLeftDown.Visibility = Visibility.Visible;
- break;
-
- case "RectRightDown":
- RectRightDown.Visibility = Visibility.Visible;
- break;
-
- default:
- break;
- }
- }
- catch (Exception ex)
- {
- MessageWindow.Show(ex.Message);
- }
- }
-
- private void RectRightUp_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
- {
- try
- {
- if (mouseDown)
- {
- Thumb thu = (Thumb)sender;
-
- #region 判断是否超出 暂无
-
- double plul = Canvas.GetLeft(RectLeftUp);
- double plut = Canvas.GetTop(RectLeftUp);
- double prdl = Canvas.GetLeft(RectRightDown);
- double prdt = Canvas.GetTop(RectRightDown);
-
- #endregion 判断是否超出 暂无
-
- //Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
- //Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
- double imgW = 0;
- double imgH = 0;
- double imgX = 0;
- double imgY = 0;
- switch (thu.Name)
- {
- case "RectLeftUp":
-
- #region 左上
-
- imgW = imgRightDown.X - (Mouse.GetPosition(GridM).X);
- imgH = imgRightDown.Y - (Mouse.GetPosition(GridM).Y);
- imgX = 0;
- imgY = 0;
- if (imgW < 50)
- {
- imgCanvas.Width = 50;
- imgX = imgCanvas.Margin.Left;
- Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
- }
- else
- {
- imgCanvas.Width = imgW;
- imgX = Mouse.GetPosition(GridM).X;
- Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
- }
- if (imgH < 50)
- {
- imgCanvas.Height = 50;
- imgY = imgCanvas.Margin.Top;
- Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
- }
- else
- {
- imgCanvas.Height = imgH;
- imgY = Mouse.GetPosition(GridM).Y;
- Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
- }
- imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
-
- #endregion 左上
-
- break;
-
- case "RectRightUp":
-
- #region 右上
-
- imgW = Mouse.GetPosition(GridM).X - imgCanvas.Margin.Left;
- imgH = imgRightDown.Y - (Mouse.GetPosition(GridM).Y);
- imgX = 0;
- imgY = 0;
- if (imgW < 50)
- {
- imgCanvas.Width = 50;
- imgX = imgCanvas.Margin.Left;
- Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
- }
- else
- {
- imgCanvas.Width = imgW;
- imgX = imgCanvas.Margin.Left;
- Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
- }
- if (imgH < 50)
- {
- imgCanvas.Height = 50;
- imgY = imgCanvas.Margin.Top;
- Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
- }
- else
- {
- imgCanvas.Height = imgH;
- imgY = Mouse.GetPosition(GridM).Y;
- Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
- }
- imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
-
- #endregion 右上
-
- break;
-
- case "RectLeftDown":
-
- #region 左下
-
- imgW = imgRightDown.X - (Mouse.GetPosition(GridM).X);
- imgH = Mouse.GetPosition(GridM).Y - imgCanvas.Margin.Top;
- imgX = 0;
- imgY = 0;
- if (imgW < 50)
- {
- imgCanvas.Width = 50;
- imgX = imgCanvas.Margin.Left;
- Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
- }
- else
- {
- imgCanvas.Width = imgW;
- imgX = Mouse.GetPosition(GridM).X;
- Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
- }
- if (imgH < 50)
- {
- imgCanvas.Height = 50;
- imgY = imgCanvas.Margin.Top;
- Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
- }
- else
- {
- imgCanvas.Height = imgH;
- imgY = imgCanvas.Margin.Top;
- Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
- }
- imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
- //imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(GridM).X);
- //imgCanvas.Height = Mouse.GetPosition(GridM).Y - imgCanvas.Margin.Top;
- //imgCanvas.Margin = new Thickness(Mouse.GetPosition(GridM).X, imgCanvas.Margin.Top, 0, 0);
-
- #endregion 左下
-
- break;
-
- case "RectRightDown":
-
- #region 右下
-
- imgW = Mouse.GetPosition(GridM).X - imgCanvas.Margin.Left;
- imgH = Mouse.GetPosition(GridM).Y - imgCanvas.Margin.Top;
- if (imgW < 50)
- {
- imgCanvas.Width = 50;
- Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
- }
- else
- {
- imgCanvas.Width = imgW;
- Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
- }
- if (imgH < 50)
- {
- imgCanvas.Height = 50;
- Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
- }
- else
- {
- imgCanvas.Height = imgH;
- Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
- }
- //imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
- //imgCanvas.Width += e.HorizontalChange;
- //imgCanvas.Height += e.VerticalChange;
-
- #endregion 右下
-
- break;
-
- default:
- break;
- }
- APP.PageDrawList[APP.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
- {
- X = imgCanvas.Margin.Left,
- Y = imgCanvas.Margin.Top
- };
- APP.PageDrawList[APP.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
- {
- CenterX = imgCanvas.ActualWidth,
- CenterY = imgCanvas.ActualHeight
- };
- APP.PageDrawList[APP.PageContextData.currpage - 1].IsImageLocation = false;
- }
- //lbl1.Content = imgCanvas.Margin.Left + "," + imgCanvas.Margin.Top;
- //lbl2.Content = (imgCanvas.Margin.Left+ imgCanvas.Width) +"," + imgCanvas.Margin.Top;
- //lbl3.Content = imgCanvas.Margin.Left + "," + (imgCanvas.Margin.Top+ imgCanvas.Height);
- //lbl4.Content= (imgCanvas.Margin.Left + imgCanvas.Width )+ "," + (imgCanvas.Margin.Top + imgCanvas.Height);
- }
- catch (Exception)
- {
- MessageWindow.Show("图片过小!");
- }
- }
-
- private void RectRightUp_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
- {
- ShowAngleBorder();
- }
-
- /// <summary>
- /// 点击标题栏 隐藏截图的四个点和线
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
- {
- HideAngleBorder();
- }
-
- /// <summary>
- /// 鼠标左键点击事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
- {
- if (RectImgBorder.Visibility != Visibility.Hidden)
- {
- HideAngleBorder();
- }
- }
-
- #endregion 图片拉伸移动
-
- #region 方法
-
- /// <summary>
- /// 录屏 录制 截图 导入文档 增加 主页面显示
- /// </summary>
- private void Record()
- {
- PageHide();
- GridMain.Visibility = Visibility.Visible;
- GridRecordingTitle.Visibility = Visibility.Visible;
- if (APP.PageContextData.pagenum > 0)
- {
- GridPage.Visibility = Visibility.Visible;
- }
- DataContext = APP.PageContextData;
- }
-
- #endregion 方法
-
- #region 跳转
-
- /// <summary>
- /// 跳转
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void CbxPageList_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- #region 安全
-
- if (CbxPageList.SelectedValue == null)
- {
- return;
- }
- if (APP.PageContextData.currpage == int.Parse(CbxPageList.SelectedValue.ToString()))
- {
- return;
- }
-
- #endregion 安全
-
- int JumpPage;
- try
- {
- JumpPage = int.Parse(CbxPageList.SelectedValue.ToString());
- }
- catch (Exception)
- {
- MessageWindow.Show("操作有误!请输入有效的页码!");
- return;
- }
- if (JumpPage < 1)
- {
- JumpPage = 1;
- }
- if (JumpPage > int.Parse(txbTotalpage.Text))
- {
- JumpPage = int.Parse(txbTotalpage.Text);
- }
-
- #region 跳转
-
- APP.PageContextData.currpage = JumpPage;
- JumpPageClick();
-
- #endregion 跳转
- }
-
- #endregion 跳转
-
- #region 原跳转
-
- /// <summary>
- /// 确定跳转
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnJumpPage_Click(object sender, RoutedEventArgs e)
- {
- int JumpPage = 0;
- //try
- //{
- // JumpPage = int.Parse(txtJump.Text);
- //}
- //catch (Exception ex)
- //{
- // MessageWindow.Show("操作有误!请输入有效的页码!");
- // return;
- //}
- if (JumpPage < 1)
- {
- JumpPage = 1;
- }
- if (JumpPage > int.Parse(txbTotalpage.Text))
- {
- JumpPage = int.Parse(txbTotalpage.Text);
- }
-
- #region 跳转
-
- APP.PageContextData.currpage = JumpPage;
- JumpPageClick();
-
- #endregion 跳转
-
- //txbCurrpage.Visibility = Visibility.Visible;
- //txtJump.Visibility = Visibility.Hidden;
- //BtnJumpPage.Visibility = Visibility.Hidden;
- }
-
- /// <summary>
- /// 只允许输入数字
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void txtJump_PreviewTextInput(object sender, TextCompositionEventArgs e)
- {
- Regex re = new Regex("[^0-9.-]+");
- e.Handled = re.IsMatch(e.Text);
- }
-
- private void txtJump_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
- {
- if (e.Key == Key.Enter)
- {
- BtnJumpPage_Click(null, null);
- }
- }
-
- #endregion 原跳转
-
- #region TQL打印
-
- /// <summary>
- /// 授权文件位置
- /// </summary>
- private string TQLAuthorizationPath;
-
- /// <summary>
- /// 授权码
- /// </summary>
- private string gKeyStr;
-
- private TmatrixClass TMC = new TmatrixClass();
- public static string gPrintFileName;
-
- private bool gbInitDone = false;
-
- private iTextSharp.text.Document document;
-
- /// <summary>
- /// TQL初始化打印
- /// </summary>
- private void TQLInit()
- {
- ///初始化
- if (TMC.TmatrixInitialize() == false)
- {
- //MessageBox.Show(this, "点阵码初始化失败!", "生成点阵码", MessageBoxButtons.OK, MessageBoxIcon.Error);
- //Close();
- }
- else
- {
- gbInitDone = true;
- }
- document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0);
- try
- {
- TQLAuthorizationPath = FileToolsCommon.GetFileAbsolutePath("/LatticeXML/S0_O000_B0000_P000-255.tmx");
-
- StreamReader gsr = new StreamReader(TQLAuthorizationPath);
- gKeyStr = gsr.ReadLine();
- gsr.Close();
- string KeyCheckResult = TMC.TmatrixKeyCheck_OID4(gKeyStr);
-
- if (KeyCheckResult.Substring(0, 1) == "1")
- {
- MessageWindow.Show("打印服务授权过期,请联系厂家更换授权!");
- LogHelper.WriteErrLog("打印服务授权过期:" + KeyCheckResult, null);
- gbInitDone = false;
- }
- else if (KeyCheckResult.Substring(0, 1) == "0")
- {
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("打印服务授权失败:" + ex.Message, ex);
- MessageWindow.Show("打印服务授权失败,请联系厂家!");
- gbInitDone = false;
- }
- }
-
- /// <summary>
- /// 铺码
- /// </summary>
- private bool GenerateCode(string PDFPath)
- {
- try
- {
- if (gbInitDone == false)
- {
- MessageWindow.Show("打印功能无法使用,无效授权。");
- return false;
- }
- try
- {
- string directoryPath = FileToolsCommon.GetDirectoryName(PDFPath);
- FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Images/");
- FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Vector Images/");
- FileToolsCommon.DeleteDirectory(directoryPath + "Bg without Vector Images/");
- FileToolsCommon.DeleteDirectory(directoryPath + "Vector Images/");
- }
- catch (Exception)
- {
- }
-
- PDFPath = PDFPath.Replace("/", "\\");
-
- //初始页
- bool[] bPublishImageType = new bool[4];
- bPublishImageType[0] = false;
- bPublishImageType[1] = false;
- bPublishImageType[2] = false;
- bPublishImageType[3] = true;
-
- int[] gPointType = { 0, 0, 0, 0, 1 };
- int[] gPointDPI = { 0, 0, 0, 0, 1 };
-
- string sGenerateResult = TMC.GenerateTmatrixCode_OID4(
- gKeyStr,
- PDFPath,
- 0,
- gPointType,
- bPublishImageType,
- gPointDPI
- );
- if (sGenerateResult.Substring(0, 1) == "1")
- {
- Dispatcher.Invoke(() =>
- {
- MessageWindow.Show("打印功能无法使用,无效授权。");
- });
-
- return false;
- }
-
- return true;
- }
- catch (Exception ex)
- {
- Dispatcher.Invoke(() =>
- {
- MessageWindow.Show("打印失败:" + ex.Message);
- });
- return false;
- }
- }
-
- #endregion TQL打印
-
- #region 事件
-
- private void BtnPrintCloseClick(object sender, RoutedEventArgs e)
- {
- GridPrintingTitle.Visibility = Visibility.Collapsed;
- }
-
- /// <summary>
- /// 打印
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnPrint_Print_Click(object sender, RoutedEventArgs e)
- {
- if (string.IsNullOrWhiteSpace(cmbClass.Text))
- {
- MessageWindow.Show("请设置打印机!");
- return;
- }
- BtnPrint.IsEnabled = false;
- Thread myThread = new Thread(StartPrint);
- PrintModel printmodel = new PrintModel();
-
- int ipdf = 102;
- string imgPath = FileToolsCommon.GetFileAbsolutePath("temp/");
- string tempImgPath = imgPath;
- imgPath += "101.pdf";
- while (File.Exists(imgPath))
- {
- imgPath = tempImgPath + ipdf.ToString() + ".pdf";
- ipdf++;
- }
- printmodel.filepath = imgPath;
- //打印数量
- int PrinterNum = 1;
- printmodel.num = PrinterNum;
- //打印机名称
- string PrinterName = cmbClass.Text;
- printmodel.printname = PrinterName;
- PrintMsg = "准备中";
- msgnum = 0;
- num = 0;
- GridPrintMask.Visibility = Visibility.Visible;
- myThread.Start(printmodel);
- timesPrint = new System.Timers.Timer(100);
- timesPrint.Elapsed += Times_ElapsedClick;
- timesPrint.Start();
-
- timesPrintMsg = new System.Timers.Timer(500);
- timesPrintMsg.Elapsed += TimesPrintMsg_Elapsed;
- timesPrintMsg.Start();
-
- GridPrintingTitle.Visibility = Visibility.Collapsed;
- }
-
- /// <summary>
- /// 打印说明
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void btnPrintExplain_Click(object sender, RoutedEventArgs e)
- {
- System.Diagnostics.Process.Start(FileToolsCommon.GetFileAbsolutePath("/星火微课点阵码打印及印刷指导手册.docx"));
- }
-
- #endregion 事件
-
- #region 打印界面
-
- /// <summary>
- /// 下拉框数据源
- /// </summary>
- public DataTable printlist = new DataTable();
-
- private DataTable dtComponentsUniqueNo;
-
- /// <summary>
- /// 打印进度
- /// </summary>
- private System.Timers.Timer timesPrint;
-
- /// <summary>
- /// 打印消息
- /// </summary>
- private System.Timers.Timer timesPrintMsg;
-
- private double wit = 0;
- private double hei = 0;
-
- /// <summary>
- /// 打印状态消息
- /// </summary>
- private string PrintMsg = "打印中";
-
- /// <summary>
- /// 打印初始化
- /// </summary>
- public void InitPrint()
- {
- ResizeMode = ResizeMode.NoResize;
- List<string> defaList = ZPrintUtils.GetLocalPrinters();
- if (defaList.Count > 0)
- {
- printlist.Columns.Add("Value");
- printlist.Columns.Add("Key");
- for (int i = 0; i < defaList.Count; i++)
- {
- //创建一行
- DataRow row = printlist.NewRow();
- //将此行添加到table中
- printlist.Rows.Add(row);
- printlist.Rows[i]["Value"] = defaList[i];
- printlist.Rows[i]["Key"] = i.ToString();
- }
- dtComponentsUniqueNo = printlist.DefaultView.ToTable();
- cmbClass.ItemsSource = dtComponentsUniqueNo.DefaultView;
- cmbClass.SelectedIndex = 0;
- }
-
- TQLInit();
- }
-
- /// <summary>
- /// 初始化页面
- /// </summary>
- /// <param name="_imgPath">
- /// </param>
- /// <param name="_wit">
- /// </param>
- /// <param name="_hei">
- /// </param>
- public void InitializePrint(string _imgPath, double _wit, double _hei)
- {
- wit = _wit;
- hei = _hei;
- if (!string.IsNullOrWhiteSpace(_imgPath))
- {
- imgPri.Source = new BitmapImage(new Uri(_imgPath));
- }
- else
- {
- imgPri.Source = null;
- }
- GridPrintMask.Visibility = Visibility.Collapsed;
- }
-
- private int msgnum = 0;
-
- /// <summary>
- /// 消息
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void TimesPrintMsg_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- if (msgnum > 5)
- msgnum = 0;
- else
- msgnum++;
- string point = "";
- point = point.ToString().PadRight(msgnum, '.');
- Dispatcher.Invoke(() =>
- {
- LabPrintMessage.Content = PrintMsg + point;
- });
- }
-
- private int num = 0;
-
- /// <summary>
- /// 计时器
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void Times_ElapsedClick(object sender, System.Timers.ElapsedEventArgs e)
- {
- Dispatcher.Invoke(() =>
- {
- pgbProcess.Value = num;
- lbProcess.Content = num.ToString() + "%";
- if (num < 99)
- {
- num++;
- timesPrint.Interval += (num / 2);
- }
- else
- {
- timesPrint.Stop();
- }
- });
- }
-
- /// <summary>
- /// 开始打印
- /// </summary>
- private void StartPrint(object obj)
- {
- PrintModel printModel = (PrintModel)obj;
- try
- {
- document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0f, 0f, 0f, 0f);
- PrintMsg = "生成文件";
- msgnum = 0;
-
- string SourcePath1 = printModel.filepath;
- try
- {
- SourcePath1 = SourcePath1.Replace("/", "\\");
- FileStream fs = new FileStream(SourcePath1, FileMode.Create, FileAccess.ReadWrite);
- document.AddAuthor("星火微课");//作者
- document.AddCreationDate();//创建时候
- document.AddCreator("星火微课");//创建者
- document.AddSubject("点阵文件");//主题
- document.AddTitle("PrintTmatrixCode");//标题
- document.AddKeywords("Print");
-
- document.AddHeader("TmatrixCode", "0");
-
- iTextSharp.text.pdf.PdfWriter.GetInstance(document, fs);
- }
- catch (Exception)
- {
- }
- document.Open();
- iTextSharp.text.Image image;
- for (int i = 0; i < APP.PageDrawList.Count; i++)
- {
- long ii = Timestamp();
- string directoryPath = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- string filePathOutPut = Path.Combine(directoryPath, string.Format("print{0}{1}.jpg", ii, i));
- RectangleF rectangleFs = new RectangleF();
- MergerPrintImg("", filePathOutPut, rectangleFs, out string errmsg);
- image = iTextSharp.text.Image.GetInstance(filePathOutPut);
- if (string.IsNullOrEmpty(APP.PageDrawList[i].PageImagePath))//没有图片
- {
- }
- else if (APP.PageDrawList[i].ImgDocumentation == true && !APP.PageDrawList[i].Type.Equals("ppt"))
- {
- image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
- }
- else
- {
- RectangleF rectangleF = new RectangleF(0, 0, 0, 0);
- Dispatcher.Invoke(() =>
- {
- rectangleF = new RectangleF
- {
- Width = (float)APP.PageDrawList[i].ImageSizes.CenterX,
- Height = (float)APP.PageDrawList[i].ImageSizes.CenterY,
- X = (float)APP.PageDrawList[i].ImageLocation.X,
- Y = (float)APP.PageDrawList[i].ImageLocation.Y
- };
- });
- string msgs = string.Empty;
-
- bool isImg = MergerPrintImg(APP.PageDrawList[i].PageImagePath, filePathOutPut, rectangleF, out msgs);
- if (isImg)
- {
- image = iTextSharp.text.Image.GetInstance(filePathOutPut);
- }
- else
- {
- image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
- }
- }
- if (image.Height > iTextSharp.text.PageSize.A4.Height)
- {
- image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
- }
- else if (image.Width > iTextSharp.text.PageSize.A4.Width)
- {
- image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
- }
- image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
- document.NewPage();
- document.Add(image);
- }
-
- document.Close();
- }
- catch (Exception ex)
- {
- Dispatcher.Invoke(() =>
- {
- BtnPrint.IsEnabled = true;
- timesPrint.Stop();
- timesPrintMsg.Stop();
- GridPrintMask.Visibility = Visibility.Collapsed;
- MessageWindow.Show(ex.Message);
- return;
- });
- LogHelper.WriteErrLog("打印转换PDF失败,原因:" + ex.Message, ex);
- }
-
- //PDF位置
- string SourcePath = printModel.filepath;
- int PrinterNum = printModel.num;
- string PrinterName = printModel.printname;
- PrintMsg = "铺码中";
- msgnum = 0;
- Thread.Sleep(500);
-
- //腾千里生成点阵文件
- if (GenerateCode(SourcePath))
- {
- //打印机名称
- string directoryPath = FileToolsCommon.GetDirectoryName(SourcePath) + "Bg with Images/";
- string[] strs = FileToolsCommon.GetFileNames(directoryPath);
-
- try
- {
- // 腾千里会根据原PDF的页数生成多个PDF文件
- for (int i = 0; i < strs.Count(); i++)
- {
- timesPrint.Stop();
- PrintMsg = "正在打印第" + (i + 1) + "/" + strs.Count() + "页中";
- msgnum = 0;
- num = 0;
- timesPrint.Interval = 100;
- timesPrint.Start();
- string fileName = strs[i];
-
- //打印文件
- ZPrintUtils.Print(fileName, PrinterName);
- }
-
- Dispatcher.Invoke(() =>
- {
- BtnPrint.IsEnabled = true;
- num = 99;
- timesPrint.Stop();
- pgbProcess.Value = 100;
- lbProcess.Content = "100%";
- GridPrintMask.Visibility = Visibility.Collapsed;
- //MessageWindow.Show("已加入打印机队列,打印中。");
- });
- }
- catch (Exception ex)
- {
- Dispatcher.Invoke(() =>
- {
- MessageWindow.Show("打印失败:" + ex.Message);
- BtnPrint.IsEnabled = true;
- timesPrint.Stop();
- GridPrintMask.Visibility = Visibility.Collapsed;
- return;
- });
- }
- }
- else
- {
- Dispatcher.Invoke(() =>
- {
- BtnPrint.IsEnabled = true;
- timesPrint.Stop();
- timesPrintMsg.Stop();
- GridPrintMask.Visibility = Visibility.Collapsed;
- return;
- });
- }
-
- #region 拓思德生成点阵文件
-
- ////TPF文件位置
- //string TPFPath = FileToolsCommon.GetFileAbsolutePath("temp/");
- //FileToolsCommon.CreateDirectory(TPFPath);
- //TPFPath += "101.TPF";
- ////生成点阵文件
- //LatticeFileHelper.GeneratingPDF(SourcePath, TPFPath, out int pr, out string msg, out string outPut/*, pyte*/);
- //while (!FileToolsCommon.IsExistFile(TPFPath))
- //{
- // Thread.Sleep(100);
- //}
- //while (string.IsNullOrWhiteSpace(pr.ToString()))
- //{
- // Thread.Sleep(100);
- //}
- //Thread.Sleep(1000);
-
- #endregion 拓思德生成点阵文件
-
- #region 拓思德打印
-
- ////打印
- //LatticeFileHelper.PrinterTPFFile(TPFPath, PrinterNum, PrinterName, out int printResult, out string standardError, out string standardOutput);
- //if (printResult == 0)
- //{
- // Dispatcher.Invoke(() =>
- // {
- // btnClose.IsEnabled = true;
- // btnPrint.IsEnabled = true;
- // num = 99;
- // timesPrint.Stop();
- // pgbProcess.Value = 100;
- // lbProcess.Content = "100%";
- // MessageWindow.Show("打印成功!");
- // GridPrintMask.Visibility = Visibility.Collapsed;
- // });
- //}
- //else
- //{
- // Dispatcher.Invoke(() =>
- // {
- // btnClose.IsEnabled = true;
- // btnPrint.IsEnabled = true;
- // timesPrint.Stop();
- // GridPrintMask.Visibility = Visibility.Collapsed;
- // MessageWindow.Show(standardError);
- // });
- //}
-
- #endregion 拓思德打印
- }
-
- /// <summary>
- /// 生成图片
- /// </summary>
- /// <param name="_path">
- /// 图片地址
- /// </param>
- /// <param name="_saveimg">
- /// 保存位置
- /// </param>
- /// <param name="_rectangle">
- /// 图片位置
- /// </param>
- /// <param name="errmsg">
- /// 错误消息
- /// </param>
- /// <returns>
- /// </returns>
- private bool MergerPrintImg(string _path, string _saveimg, RectangleF _rectangle, out string errmsg)
- {
- errmsg = null;
- try
- {
- Bitmap bitmap = null;
-
- //创建要显示的图片对象,根据参数的个数设置宽度
- Bitmap backgroudImg = new Bitmap((int)/*GridM.ActualWidth*/wit, (int)/*GridM.ActualHeight*/hei);
- Graphics g = Graphics.FromImage(backgroudImg);
- //清除画布,背景设置为白色
- g.Clear(System.Drawing.Color.White);
-
- if (!string.IsNullOrWhiteSpace(_path))
- {
- bitmap = ImageHelper.ReadBitmapFile(_path);
- g.DrawImage(bitmap, _rectangle);
- }
-
- #region 添加箭头
-
- string Str = "↑";
- SolidBrush mybrush = new SolidBrush(System.Drawing.Color.Black); //设置默认画刷颜色
- System.Drawing.Font myfont = new System.Drawing.Font("黑体", 14); //设置默认字体格式
- g.DrawString(Str, myfont, mybrush, new System.Drawing.Rectangle((int)wit - 50, 20, 50, 50));
-
- #endregion 添加箭头
-
- backgroudImg.Save(_saveimg);
-
- g.Dispose();
- backgroudImg.Dispose();
- if (bitmap != null)
- {
- bitmap.Dispose();
- }
-
- GC.Collect();
- return true;
- }
- catch (Exception ex)
- {
- errmsg = ex.Message;
- LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
- return false;
- }
- }
-
- #endregion 打印界面
- }
-
- public class PageData
- {
- public int PageCode { get; set; }
- public string PageName { get; set; }
- }
- }
|