星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

XHMicroLessonSystemWindow.xaml.cs 229KB

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