星火微课系统客户端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

XHMicroLessonSystemWindow.xaml.cs 248KB

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