星火微课系统客户端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

XHMicroLessonSystemWindow.xaml.cs 307KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163
  1. using Aspose.Slides;
  2. using Aspose.Words.Saving;
  3. using ComeCapture;
  4. using Common.system;
  5. using RobotpenGateway;
  6. using Spire.Pdf;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Diagnostics;
  11. using System.Drawing;
  12. using System.Drawing.Imaging;
  13. using System.Drawing.Printing;
  14. using System.IO;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Text.RegularExpressions;
  18. using System.Threading;
  19. using System.Windows;
  20. using System.Windows.Controls;
  21. using System.Windows.Controls.Primitives;
  22. //using System.Windows.Forms;
  23. using System.Windows.Ink;
  24. using System.Windows.Input;
  25. using System.Windows.Media;
  26. using System.Windows.Media.Imaging;
  27. using System.Windows.Threading;
  28. using TmatrixLibrary;
  29. using TStudyDigitalPen.HID;
  30. using XHWK.Model;
  31. using XHWK.WKTool.DAL;
  32. using XHWK.WKTool.UControl;
  33. namespace XHWK.WKTool
  34. {
  35. /// <summary>
  36. /// 主页面
  37. /// </summary>
  38. public partial class XHMicroLessonSystemWindow : Window
  39. {
  40. #region 字段
  41. /// <summary>
  42. /// 页码下拉列表
  43. /// </summary>
  44. List<PageData> PageData = null;
  45. private System.Windows.Forms.FolderBrowserDialog Ofd;
  46. private System.Windows.Forms.DialogResult Result;
  47. public BlackboardNew myblackboard;
  48. private System.Windows.Forms.DialogResult result;
  49. private System.Windows.Forms.OpenFileDialog ofd;
  50. //声明一个 DrawingAttributes 类型的变量
  51. private DrawingAttributes drawingAttributes;
  52. private Model_Video VideoInfo = null;
  53. ////定义事件
  54. //public event ChangeTextHandler ChangeTextEvent;
  55. //定义委托
  56. public delegate void ChangeTextHandler(string text);
  57. //定义委托
  58. public delegate void ChangeTextHandlers(string text, int i);
  59. /// <summary>
  60. /// 图片
  61. /// </summary>
  62. private string[] ImgPDFPath = new string[300];
  63. /// <summary>
  64. /// 当前颜色
  65. /// </summary>
  66. private System.Windows.Media.Color Color = System.Windows.Media.Colors.Red;
  67. /// <summary>
  68. /// 笔迹粗细
  69. /// </summary>
  70. private int PenSize = 2;
  71. //private DispatcherTimer t = null;
  72. /// <summary>
  73. /// 计时器状态
  74. /// </summary>
  75. private enum State
  76. {
  77. Start,
  78. Pause,
  79. End
  80. }
  81. ///// <summary>
  82. ///// 状态
  83. ///// </summary>
  84. //private State _state = State.End;
  85. ///// <summary>
  86. ///// 计时用
  87. ///// </summary>
  88. //private TimeSpan _timeSpan = new TimeSpan(0, 0, 0, 0, 0);
  89. #region 上传
  90. /// <summary>
  91. /// 视频模型
  92. /// </summary>
  93. private List<Model_Video> model_VideoList = null;
  94. /// <summary>
  95. /// 数据列表
  96. /// </summary>
  97. internal FileDirectoryData pageData = new FileDirectoryData();
  98. /// <summary>
  99. /// 下标
  100. /// </summary>
  101. private int Subscript = 0;
  102. /// <summary>
  103. /// 是否是修改状态
  104. /// </summary>
  105. private bool IsModify = false;
  106. #endregion
  107. //private double screeHeight = SystemParameters.FullPrimaryScreenHeight;
  108. //private double screeWidth = SystemParameters.FullPrimaryScreenWidth;
  109. /// <summary>
  110. /// 键盘钩子
  111. /// </summary>
  112. private KeyboardHookCommon k_hook;
  113. #endregion
  114. #region 初始化
  115. /// <summary>
  116. /// 主页面
  117. /// </summary>
  118. public XHMicroLessonSystemWindow()
  119. {
  120. 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=")));
  121. 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=")));
  122. 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=")));
  123. InitializeComponent();
  124. //Blue蓝 Black黑色
  125. if (APP.SkinStyle == "Blue")
  126. {
  127. GridToolbars_Blue.Visibility = Visibility.Visible;
  128. GridToolbars_Black.Visibility = Visibility.Collapsed;
  129. GridTitle_Black.Visibility = Visibility.Collapsed;
  130. //Colum1.Width = new GridLength(0);
  131. }
  132. else if (APP.SkinStyle == "Black")
  133. {
  134. GridToolbars_Blue.Visibility = Visibility.Collapsed;
  135. GridToolbars_Black.Visibility = Visibility.Visible;
  136. GridTitle_Black.Visibility = Visibility.Visible;
  137. //Colum1.Width = new GridLength(72); //GridLength.Auto;
  138. }
  139. else
  140. {
  141. GridToolbars_Blue.Visibility = Visibility.Visible;
  142. GridToolbars_Black.Visibility = Visibility.Collapsed;
  143. GridTitle_Black.Visibility = Visibility.Collapsed;
  144. }
  145. float WorkW = PrimaryScreen.ScaleWorkingAreaSize.Width;
  146. float WorkH = PrimaryScreen.ScaleWorkingAreaSize.Height;
  147. double proportion = 1036.0 / 1290.0;
  148. //限制大小 确保大屏幕下录制不会卡死 暂时
  149. if (WorkW > 1920.0)
  150. {
  151. Width = 1920;
  152. Height = 1036;
  153. }
  154. else
  155. {
  156. Width = (PrimaryScreen.ScaleWorkingAreaSize.Height) / proportion - (BorderThickness.Left + BorderThickness.Right);
  157. Height = PrimaryScreen.ScaleWorkingAreaSize.Height - (BorderThickness.Top + BorderThickness.Bottom);
  158. }
  159. GridContent.Width = Width - 14;
  160. GridContent.Height = Height;
  161. #region 读取本地配置
  162. if (File.Exists(APP.dataPath + "interfaceAddress.txt")) //若不为空
  163. {
  164. APP.apiUrl = System.IO.File.ReadAllText(APP.dataPath + "interfaceAddress.txt", Encoding.Default);
  165. }
  166. if (File.Exists(APP.dataPath + "imageUploadAddress.txt")) //若不为空
  167. {
  168. APP.uploadUrl = System.IO.File.ReadAllText(APP.dataPath + "imageUploadAddress.txt", Encoding.Default);
  169. }
  170. if (File.Exists(APP.dataPath + "pictureShowsAddress.txt")) //若不为空
  171. {
  172. APP.showImageUrl = System.IO.File.ReadAllText(APP.dataPath + "pictureShowsAddress.txt", Encoding.Default);
  173. }
  174. #endregion
  175. //GridMain.Height= PrimaryScreen.ScaleScreenSize().Height - 40;
  176. //this.Top = (screeHeight - this.Height) / 2;
  177. //this.Left = (screeWidth - this.Width) / 2;
  178. ResizeMode = System.Windows.ResizeMode.CanMinimize;
  179. btnPrint.IsEnabled = false;
  180. btnPrint_Black.IsEnabled = false;
  181. myblackboard = new BlackboardNew(blackboard_canvas);
  182. APP.pageData.pagenum = 0;
  183. APP.pageData.currpage = 0;
  184. DataContext = APP.pageData;
  185. //APP.SaveDraw();//画板模型第一页初始化
  186. APP.PageDrawList = new List<Model_DrawData>();
  187. Model_DrawData model_DrawData = new Model_DrawData
  188. {
  189. PageNum = APP.pageData.currpage
  190. };
  191. APP.PageDrawList.Add(model_DrawData);
  192. txbv.Text = "v" + FileToolsCommon.GetConfigValue("VersionName");
  193. txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoType");
  194. if (FileToolsCommon.GetConfigValue("IsSound").Equals("true"))
  195. {
  196. rbnY.IsChecked = true;
  197. }
  198. else
  199. {
  200. rbnN.IsChecked = true;
  201. }
  202. txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoSavePath");
  203. Initialize();
  204. InitPen();
  205. InitlbPen();
  206. InitTQLPPen();
  207. InitPrint();
  208. }
  209. /// <summary>
  210. /// 初始化
  211. /// </summary>
  212. public void Initialize()
  213. {
  214. if (APP.isDebug)
  215. {
  216. txbVersion.Text = "测试版:";
  217. }
  218. else
  219. {
  220. txbVersion.Text = "正式版:";
  221. }
  222. #region 数据初始化
  223. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  224. FileToolsCommon.CreateDirectory(pathTemp);
  225. APP.pageData.pagenum = 0;
  226. APP.pageData.currpage = APP.pageData.pagenum;
  227. btnStop.IsEnabled = false;//停止录制按钮不可点击
  228. btnStop_Black.IsEnabled = false;
  229. #endregion
  230. k_hook = new KeyboardHookCommon();
  231. k_hook.KeyDownEvent += K_hook_KeyDownEvent;
  232. k_hook.Start();//安装键盘钩子
  233. APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  234. //创建 DrawingAttributes 类的一个实例
  235. drawingAttributes = new DrawingAttributes();
  236. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  237. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  238. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  239. blackboard_canvas.UseCustomCursor = true;
  240. drawingAttributes.FitToCurve = true;
  241. drawingAttributes.IgnorePressure = false;
  242. drawingAttributes.Width = PenSize;
  243. drawingAttributes.Height = PenSize;
  244. drawingAttributes.Color = Color;
  245. blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  246. //wfhCamera.Visibility = Visibility.Hidden;
  247. ImgPDFPath = null;
  248. ImgPDFPath = new string[300];
  249. //gridM.Height = gridM.ActualWidth / proportion;
  250. //gridM.Height = gridM.Width / proportion;
  251. }
  252. /// <summary>
  253. /// 初始化快捷键
  254. /// </summary>
  255. public void InitializeKeyDownEvent()
  256. {
  257. k_hook.Start();//安装键盘钩子
  258. }
  259. /// <summary>
  260. /// 快捷键
  261. /// </summary>
  262. /// <param name="sender"></param>
  263. /// <param name="e"></param>
  264. private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
  265. {
  266. if (e.KeyValue == (int)System.Windows.Forms.Keys.Left)
  267. {
  268. if (APP.pageData.currpage > 1)
  269. {
  270. //上一页
  271. last_button_Click(null, null);
  272. }
  273. }
  274. if (e.KeyValue == (int)System.Windows.Forms.Keys.Right)
  275. {
  276. if (APP.pageData.currpage < APP.pageData.pagenum)
  277. {
  278. //下一页
  279. next_btn_Click(null, null);
  280. }
  281. }
  282. if (e.KeyValue == (int)System.Windows.Forms.Keys.Delete)
  283. {
  284. if (RectImgBorder.Visibility != Visibility.Hidden)
  285. {
  286. HideAngleBorder();
  287. imgCanvas.Source = null;
  288. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = null;
  289. APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath = null;
  290. }
  291. }
  292. }
  293. /// <summary>
  294. /// 加载完成后调整录制区域大小
  295. /// </summary>
  296. /// <param name="sender"></param>
  297. /// <param name="e"></param>
  298. private void Window_Loaded(object sender, RoutedEventArgs e)
  299. {
  300. //调整录制区域宽高
  301. double proportion = 210.0 / 297.0;
  302. gridM.Height = gridM.ActualWidth / proportion;
  303. }
  304. #endregion
  305. #region 事件
  306. /// <summary>
  307. /// 窗体移动
  308. /// </summary>
  309. /// <param name="sender"></param>
  310. /// <param name="e"></param>
  311. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  312. {
  313. DragMove();
  314. }
  315. void PageHide()
  316. {
  317. //设置
  318. gridSetUp.Visibility = Visibility.Collapsed;
  319. //上传-无用
  320. gridUpload.Visibility = Visibility.Collapsed;
  321. //页码
  322. gridPage.Visibility = Visibility.Collapsed;
  323. //我的
  324. GridMyVideo.Visibility = Visibility.Collapsed;
  325. //首页
  326. GridMain.Visibility = Visibility.Collapsed;
  327. //打印
  328. GridPrintContent.Visibility = Visibility.Collapsed;
  329. }
  330. #region 摄像头
  331. private System.Timers.Timer times;
  332. private List<string> RbnOpen;
  333. private bool IsRbnOpen = false;
  334. /// <summary>
  335. /// 摄像头打开事件
  336. /// </summary>
  337. /// <param name="sender"></param>
  338. /// <param name="e"></param>
  339. private void RbnOpen_Click(object sender, RoutedEventArgs e)
  340. {
  341. if (!IsRbnOpen)
  342. {
  343. #region 防止连击
  344. if (IsPressButton)
  345. {
  346. return;
  347. }
  348. else
  349. {
  350. IsPressButton = true;
  351. new Thread(new ThreadStart(new Action(() =>
  352. {
  353. //Dispatcher.Invoke(new Action(() => { rbnTurnOff.IsEnabled = false; }));
  354. Thread.Sleep(500);
  355. //Dispatcher.Invoke(new Action(() => { rbnTurnOff.IsEnabled = true; }));
  356. IsPressButton = false;
  357. }))).Start();
  358. }
  359. #endregion
  360. CameraHelper.UpdateCameraDevices();
  361. if (CameraHelper.CameraDevices.Count > 0)
  362. {
  363. int CameraIndex = 0;
  364. for (int i = 0; i < CameraHelper.CameraDevices.Count; i++)
  365. {
  366. if (CameraHelper.CameraDevices[i].MonikerString == APP.CameraName)
  367. {
  368. CameraIndex = i;
  369. }
  370. }
  371. CameraHelper.SetCameraDevice(CameraIndex);
  372. RbnOpen = new List<string>();
  373. times = new System.Timers.Timer(200)//初始值为300
  374. {
  375. AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
  376. };//设置执行一次(false)还是一直执行(true)
  377. times.Elapsed += new System.Timers.ElapsedEventHandler(Times_Elapsed);
  378. times.Enabled = true; //启动计时器
  379. IsRbnOpen = true;
  380. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  381. FileToolsCommon.CreateDirectory(imgPath);
  382. }
  383. }
  384. }
  385. private int I = 9999;
  386. private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  387. {
  388. if (IsRbnOpen)
  389. {
  390. try
  391. {
  392. Dispatcher.Invoke(() =>
  393. {
  394. if (I > 10010)
  395. {
  396. long time = Timestamp();
  397. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  398. //string FilePathName = ImgPath + RsImgName.Count + ".png";
  399. string path = CameraHelper.CaptureImage(imgPath, time.ToString());
  400. if (!string.IsNullOrWhiteSpace(path))
  401. {
  402. RbnOpen.Add(path);
  403. imgPlayerRight.Visibility = Visibility.Visible;
  404. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  405. if ("1".Equals(APP.CameraPosition))
  406. {
  407. imgPlayerRight.Visibility = Visibility.Visible;
  408. imgPlayerLeft.Visibility = Visibility.Collapsed;
  409. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  410. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  411. imgPlayerRight.Source = new BitmapImage(new Uri(path));
  412. }
  413. else if ("2".Equals(APP.CameraPosition))
  414. {
  415. imgPlayerRight.Visibility = Visibility.Collapsed;
  416. imgPlayerLeft.Visibility = Visibility.Visible;
  417. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  418. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  419. imgPlayerLeft.Source = new BitmapImage(new Uri(path));
  420. }
  421. else if ("3".Equals(APP.CameraPosition))
  422. {
  423. imgPlayerRight.Visibility = Visibility.Collapsed;
  424. imgPlayerLeft.Visibility = Visibility.Collapsed;
  425. imgPlayerRightUnder.Visibility = Visibility.Visible;
  426. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  427. imgPlayerRightUnder.Source = new BitmapImage(new Uri(path));
  428. }
  429. else if ("4".Equals(APP.CameraPosition))
  430. {
  431. imgPlayerRight.Visibility = Visibility.Collapsed;
  432. imgPlayerLeft.Visibility = Visibility.Collapsed;
  433. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  434. imgPlayerLeftUnder.Visibility = Visibility.Visible;
  435. imgPlayerLeftUnder.Source = new BitmapImage(new Uri(path));
  436. }
  437. else
  438. {
  439. imgPlayerLeft.Visibility = Visibility.Collapsed;
  440. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  441. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  442. imgPlayerRight.Source = new BitmapImage(new Uri(path));
  443. }
  444. }
  445. }
  446. I++;
  447. });
  448. }
  449. catch (Exception ex)
  450. {
  451. LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
  452. }
  453. }
  454. }
  455. /// <summary>
  456. /// 摄像头关闭事件
  457. /// </summary>
  458. /// <param name="sender"></param>
  459. /// <param name="e"></param>
  460. private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
  461. {
  462. if (IsRbnOpen)
  463. {
  464. #region 防止连击
  465. if (IsPressButton)
  466. {
  467. return;
  468. }
  469. else
  470. {
  471. IsPressButton = true;
  472. new Thread(new ThreadStart(new Action(() =>
  473. {
  474. //Dispatcher.Invoke(new Action(() => { rbnOpen.IsEnabled = false; }));
  475. Thread.Sleep(500);
  476. //Dispatcher.Invoke(new Action(() => { rbnOpen.IsEnabled = true; }));
  477. IsPressButton = false;
  478. }))).Start();
  479. }
  480. #endregion
  481. IsRbnOpen = false;
  482. imgPlayerRight.Visibility = Visibility.Collapsed;
  483. imgPlayerLeft.Visibility = Visibility.Collapsed;
  484. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  485. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  486. CameraHelper.CloseDevice();
  487. I = 9999;
  488. }
  489. }
  490. #endregion
  491. /// <summary>
  492. /// 关闭事件
  493. /// </summary>
  494. /// <param name="sender"></param>
  495. /// <param name="e"></param>
  496. private void BtnDown_Click(object sender, RoutedEventArgs e)
  497. {
  498. if (IsFirstR)
  499. {
  500. try
  501. {
  502. MessageBoxResult br = MessageWindow.Show("确定退出系统?", "退出", MessageBoxButton.OKCancel);
  503. if (br == MessageBoxResult.OK)
  504. {
  505. try
  506. {
  507. APP.Killffmpeg();
  508. }
  509. catch (Exception ex)
  510. {
  511. LogHelper.WriteErrLog("获取进程失败," + ex.Message, ex);
  512. }
  513. APP.SaveWkData();
  514. APP.SaveDraw();
  515. //Thread.Sleep(100);
  516. //Close();
  517. //System.Windows.
  518. //Application.Current.Shutdown();
  519. TMC.TmatrixUninitialize();
  520. Environment.Exit(0);
  521. }
  522. }
  523. catch (Exception ex)
  524. {
  525. LogHelper.WriteErrLog("关闭微课失败," + ex.Message, ex);
  526. Close();
  527. Application.Current.Shutdown();
  528. TMC.TmatrixUninitialize();
  529. Environment.Exit(0);
  530. }
  531. }
  532. else
  533. {
  534. MessageWindow.Show("当前正在录制,请先停止录制。");
  535. return;
  536. //MessageBoxResult dr = MessageWindow.Show("当前正在录制,是否停止录制?", "提示", MessageBoxButton.OKCancel);
  537. //if (dr == MessageBoxResult.OK)
  538. //{
  539. // APP.SaveWkData();
  540. // APP.SaveDraw();
  541. // BtnStop_Click(null, null);
  542. // while (!IsFirstR)
  543. // {
  544. // Thread.Sleep(100);
  545. // }
  546. // System.Environment.Exit(0);
  547. //}
  548. //else
  549. //{
  550. // return;
  551. //}
  552. }
  553. }
  554. /// <summary>
  555. /// 增加事件
  556. /// </summary>
  557. /// <param name="sender"></param>
  558. /// <param name="e"></param>
  559. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  560. {
  561. Record();
  562. if (APP.pageData.currpage > 0)
  563. {
  564. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  565. }
  566. if (IsStartCount && blackboard_canvas.Visibility == Visibility.Collapsed)
  567. {
  568. blackboard_canvas.Visibility = Visibility.Visible;
  569. }
  570. APP.pageData.pagenum += 1;
  571. HideAngleBorder();
  572. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  573. APP.pageData.currpage = APP.pageData.pagenum;
  574. myblackboard.changepage(APP.pageData.currpage - 1);
  575. scroMain.ScrollToVerticalOffset(0);
  576. ///清空页面图片UI
  577. imgCanvas.Source = null;
  578. imgDocumentation.Source = null;
  579. imgPPT.Source = null;
  580. if (APP.pageData.pagenum == 1)
  581. {
  582. APP.PageDrawList = new List<Model_DrawData>();
  583. }
  584. ///画板模型增加一页
  585. Model_DrawData model_DrawData = new Model_DrawData
  586. {
  587. PageNum = APP.pageData.currpage
  588. };
  589. APP.PageDrawList.Add(model_DrawData);
  590. ImgPrint.Visibility = Visibility.Visible;//可打印
  591. ImgPrintTwo.Visibility = Visibility.Collapsed;
  592. btnPrint.IsEnabled = true;
  593. btnPrint_Black.IsEnabled = true;
  594. //APP.SaveDraw();
  595. if (btnImport.IsEnabled || btnImport_Black.IsEnabled)
  596. {
  597. ///截图可用
  598. ImgScreenshot.Visibility = Visibility.Visible;
  599. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  600. btnScreenshot.IsEnabled = true;
  601. btnScreenshot_Black.IsEnabled = true;
  602. }
  603. #region 插入页码
  604. PageData = new List<PageData>();
  605. for (int i = 1; i <= APP.pageData.pagenum; i++)
  606. {
  607. PageData pd = new PageData();
  608. pd.PageName = i.ToString();// + "页";
  609. pd.PageCode = i;
  610. PageData.Add(pd);
  611. }
  612. CbxPageList.ItemsSource = PageData;
  613. CbxPageList.SelectedIndex = APP.pageData.currpage - 1;
  614. #endregion
  615. }
  616. /// <summary>
  617. /// 打印事件
  618. /// </summary>
  619. /// <param name="sender"></param>
  620. /// <param name="e"></param>
  621. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  622. {
  623. try
  624. {
  625. //3种情况 1.文档图片 2.截图图片 3.没有图片
  626. if (APP.PageDrawList.Count == 0)
  627. {
  628. MessageWindow.Show("没有可打印的页,您可以通过加页、截图或导入来增加页!");
  629. return;
  630. }
  631. }
  632. catch (Exception ex)
  633. {
  634. MessageWindow.Show(ex.Message);
  635. Console.WriteLine("转换失败,原因:" + ex.Message);
  636. }
  637. if (GridPrintContent.Visibility == Visibility.Visible)
  638. {
  639. GridPrintContent.Visibility = Visibility.Collapsed;
  640. GridMain.Visibility = Visibility.Visible;
  641. if (APP.pageData.pagenum > 0)
  642. {
  643. gridPage.Visibility = Visibility.Visible;
  644. }
  645. DataContext = APP.pageData;
  646. }
  647. else
  648. {
  649. PageHide();
  650. GridPrintContent.Visibility = Visibility.Visible;
  651. if (APP.PageDrawList.Count > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[0].PageImagePath))
  652. {
  653. InitializePrint(APP.PageDrawList[0].PageImagePath, gridM.ActualWidth, gridM.ActualHeight);
  654. }
  655. else
  656. {
  657. InitializePrint("", gridM.ActualWidth, gridActHeight);
  658. }
  659. }
  660. //if (APP.W_PrintWindow == null)
  661. //{
  662. // APP.W_PrintWindow = new PrintWindow
  663. // {
  664. // Owner = this
  665. // };
  666. //}
  667. //if (APP.PageDrawList.Count > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[0].PageImagePath))
  668. //{
  669. // APP.W_PrintWindow.Initialize(APP.PageDrawList[0].PageImagePath, gridM.ActualWidth, gridM.ActualHeight);
  670. //}
  671. //else
  672. //{
  673. // APP.W_PrintWindow.Initialize("", gridM.ActualWidth, gridActHeight);
  674. //}
  675. //APP.W_PrintWindow.ShowDialog();
  676. }
  677. /// <summary>
  678. /// 最小化
  679. /// </summary>
  680. /// <param name="sender"></param>
  681. /// <param name="e"></param>
  682. private void BtnShrink_Click(object sender, RoutedEventArgs e)
  683. {
  684. if (WindowState == WindowState.Minimized)
  685. {
  686. WindowState = WindowState.Normal;
  687. }
  688. else
  689. {
  690. WindowState = WindowState.Minimized;
  691. }
  692. }
  693. #endregion
  694. #region 设置
  695. /// <summary>
  696. /// 设置事件
  697. /// </summary>
  698. /// <param name="sender"></param>
  699. /// <param name="e"></param>
  700. private void BtnSetUp_Click(object sender, RoutedEventArgs e)
  701. {
  702. if (!TxbRecordingWord.Text.Equals("暂停"))
  703. {
  704. if (gridSetUp.Visibility == Visibility.Collapsed)
  705. {
  706. PageHide();
  707. gridSetUp.Visibility = Visibility.Visible;
  708. txbStoragePath.Content = APP.WKData.WkPath;
  709. #region 读取用户配置
  710. //接口地址
  711. if (!File.Exists(APP.dataPath + "interfaceAddress.txt")) //若为空
  712. {
  713. txbInterfaceAddress.Text = APP.apiUrl.Replace("http://", "").Trim();
  714. }
  715. else
  716. {
  717. txbInterfaceAddress.Text = System.IO.File.ReadAllText(APP.dataPath + "interfaceAddress.txt", Encoding.Default).Replace("http://", "").Trim();
  718. }
  719. //上传地址
  720. if (!File.Exists(APP.dataPath + "imageUploadAddress.txt")) //若为空
  721. {
  722. txbImageUploadAddress.Text = APP.uploadUrl.Replace("http://", "").Replace("/", "").Trim();
  723. }
  724. else
  725. {
  726. txbImageUploadAddress.Text = System.IO.File.ReadAllText(APP.dataPath + "imageUploadAddress.txt", Encoding.Default).Replace("http://", "").Replace("/", "").Trim();
  727. }
  728. //下载地址
  729. if (!File.Exists(APP.dataPath + "pictureShowsAddress.txt")) //若为空
  730. {
  731. txbPictureShowsAddress.Text = APP.showImageUrl.Replace("http://", "").Replace("/static", "").Replace("/", "").Trim();
  732. }
  733. else
  734. {
  735. txbPictureShowsAddress.Text = System.IO.File.ReadAllText(APP.dataPath + "pictureShowsAddress.txt", Encoding.Default).Replace("http://", "").Replace("/static", "").Replace("/", "").Trim();
  736. }
  737. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  738. if ("1".Equals(APP.CameraPosition))
  739. {
  740. rbnRight.IsChecked = true;
  741. }
  742. else if ("2".Equals(APP.CameraPosition))
  743. {
  744. rbnLeft.IsChecked = true;
  745. }
  746. else if ("3".Equals(APP.CameraPosition))
  747. {
  748. rbnRightUnder.IsChecked = true;
  749. }
  750. else if ("4".Equals(APP.CameraPosition))
  751. {
  752. rbnLeftUnder.IsChecked = true;
  753. }
  754. string type = FileToolsCommon.GetConfigValue("VideoType");//<!--视频格式 1、MP4 2、FlV 3、AVI-->
  755. if ("1".Equals(type))
  756. {
  757. rbnMP4.IsChecked = true;
  758. }
  759. else if ("2".Equals(type))
  760. {
  761. rbnFLV.IsChecked = true;
  762. }
  763. else if ("3".Equals(type))
  764. {
  765. rbnAVI.IsChecked = true;
  766. }
  767. string isHide = FileToolsCommon.GetConfigValue("IsHideSRTool"); //工具栏是否隐藏
  768. if (isHide.Equals("1"))
  769. {
  770. rbnHide.IsChecked = true;
  771. }
  772. else
  773. {
  774. rbnvisi.IsChecked = true;
  775. }
  776. string isSound = FileToolsCommon.GetConfigValue("IsSound");//<!--声音 true 有 false 无-->
  777. if (isSound == "true")
  778. {
  779. rbnY.IsChecked = true;
  780. }
  781. else
  782. {
  783. rbnN.IsChecked = true;
  784. }
  785. string Skin = FileToolsCommon.GetConfigValue("SkinStyle");
  786. if (Skin == "Blue")
  787. {
  788. rbnBlue.IsChecked = true;
  789. }
  790. else if (Skin == "Black")
  791. {
  792. rbnBlack.IsChecked = true;
  793. }
  794. else
  795. {
  796. rbnBlue.IsChecked = true;
  797. }
  798. #endregion
  799. }
  800. else
  801. {
  802. GridMain.Visibility = Visibility.Visible;
  803. gridSetUp.Visibility = Visibility.Collapsed;
  804. if (APP.pageData.pagenum > 0)
  805. {
  806. gridPage.Visibility = Visibility.Visible;
  807. }
  808. DataContext = APP.pageData;
  809. }
  810. }
  811. }
  812. /// <summary>
  813. /// 设置 保存事件
  814. /// </summary>
  815. /// <param name="sender"></param>
  816. /// <param name="e"></param>
  817. private void BtnSave_Click(object sender, RoutedEventArgs e)
  818. {
  819. try
  820. {
  821. ImgRecord.Visibility = Visibility.Visible;//设置结束时可录制
  822. ImgRecordTwo.Visibility = Visibility.Collapsed;//设置结束时可录制
  823. BtnRecord.IsEnabled = true;//设置结束时可录制
  824. BtnRecord_Black.IsEnabled = true;
  825. if (!string.IsNullOrWhiteSpace(txbInterfaceAddress.Text))
  826. {
  827. string ApplicationData = APP.dataPath + "interfaceAddress.txt";
  828. string temp = "http://" + txbInterfaceAddress.Text;
  829. System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  830. }
  831. else
  832. {
  833. MessageWindow.Show("请输入接口地址");
  834. return;
  835. }
  836. if (!string.IsNullOrWhiteSpace(txbImageUploadAddress.Text))//图片上传地址
  837. {
  838. string ApplicationData = APP.dataPath + "imageUploadAddress.txt";
  839. string temp = "http://" + txbImageUploadAddress.Text + "/";
  840. System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  841. }
  842. else
  843. {
  844. MessageWindow.Show("请输入上传地址");
  845. return;
  846. }
  847. if (!string.IsNullOrWhiteSpace(txbPictureShowsAddress.Text))
  848. {
  849. string ApplicationData = APP.dataPath + "pictureShowsAddress.txt";
  850. string temp = "http://" + txbPictureShowsAddress.Text + "/static/";
  851. System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  852. }
  853. else
  854. {
  855. MessageWindow.Show("请输入下载地址");
  856. return;
  857. }
  858. if (!APP.apiUrl.Equals("http://" + txbInterfaceAddress.Text))
  859. {
  860. APP.apiUrl = "http://" + txbInterfaceAddress.Text;
  861. if (!txbLoginType.Text.Equals("未登录") || ImgHeadImg.Visibility == Visibility.Visible)
  862. {
  863. LoginType();
  864. MessageWindow.Show("接口地址已修改,请重新登录!");
  865. }
  866. }
  867. if (!APP.uploadUrl.Equals(txbImageUploadAddress.Text))
  868. {
  869. APP.uploadUrl = "http://" + txbImageUploadAddress.Text + "/";
  870. }
  871. if (!APP.showImageUrl.Equals(txbPictureShowsAddress.Text))
  872. {
  873. APP.showImageUrl = "http://" + txbPictureShowsAddress.Text + "/static/";
  874. }
  875. if (rbnMP4.IsChecked == true)
  876. {
  877. //存储文件
  878. FileToolsCommon.SetConfigValue("VideoType", "1");
  879. }
  880. else if (rbnFLV.IsChecked == true)
  881. {
  882. FileToolsCommon.SetConfigValue("VideoType", "2");
  883. }
  884. else
  885. {
  886. FileToolsCommon.SetConfigValue("VideoType", "3");
  887. }
  888. if (rbnY.IsChecked == true)
  889. {
  890. FileToolsCommon.SetConfigValue("IsSound", "true");
  891. }
  892. else
  893. {
  894. FileToolsCommon.SetConfigValue("IsSound", "false");
  895. }
  896. UpdateHideSRToolConfig();
  897. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  898. if (rbnRight.IsChecked == true)
  899. {
  900. FileToolsCommon.SetConfigValue("CameraPosition", "1");
  901. }
  902. else if (rbnLeft.IsChecked == true)
  903. {
  904. FileToolsCommon.SetConfigValue("CameraPosition", "2");
  905. }
  906. else if (rbnRightUnder.IsChecked == true)
  907. {
  908. FileToolsCommon.SetConfigValue("CameraPosition", "3");
  909. }
  910. else if (rbnLeftUnder.IsChecked == true)
  911. {
  912. FileToolsCommon.SetConfigValue("CameraPosition", "4");
  913. }
  914. //格式
  915. if (rbnMP4.IsChecked == true)
  916. {
  917. FileToolsCommon.SetConfigValue("VideoType", "1");
  918. }
  919. else if (rbnFLV.IsChecked == true)
  920. {
  921. FileToolsCommon.SetConfigValue("VideoType", "2");
  922. }
  923. else if (rbnAVI.IsChecked == true)
  924. {
  925. FileToolsCommon.SetConfigValue("VideoType", "3");
  926. }
  927. //样式
  928. if (rbnBlue.IsChecked == true)
  929. {
  930. FileToolsCommon.SetConfigValue("SkinStyle", "Blue");
  931. if (APP.SkinStyle == "Black")
  932. {
  933. MessageWindow.Show("皮肤设置完成,下次启动程序时自动生效。");
  934. }
  935. }
  936. else if (rbnBlack.IsChecked == true)
  937. {
  938. FileToolsCommon.SetConfigValue("SkinStyle", "Black");
  939. if (APP.SkinStyle == "Blue")
  940. {
  941. MessageWindow.Show("皮肤设置完成,下次启动程序时自动生效。");
  942. }
  943. }
  944. APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  945. GridMain.Visibility = Visibility.Visible;
  946. gridSetUp.Visibility = Visibility.Collapsed;
  947. imgPlayerRight.Visibility = Visibility.Collapsed;
  948. imgPlayerLeft.Visibility = Visibility.Collapsed;
  949. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  950. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  951. if (!txbStoragePath.Content.ToString().Equals(APP.WKData.WkPath))
  952. {
  953. //存储文件
  954. FileToolsCommon.SetConfigValue("VideoSavePath", txbStoragePath.Content.ToString());
  955. MessageWindow.Show("路径已变更,下次创建微课时自动生效。");
  956. }
  957. }
  958. catch (Exception ex)
  959. {
  960. LogHelper.WriteErrLog("XHMicroLessonSystemWindow(设置保存事件报错:)" + ex.Message, ex);
  961. }
  962. }
  963. /// <summary>
  964. /// 设置 浏览事件
  965. /// </summary>
  966. /// <param name="sender"></param>
  967. /// <param name="e"></param>
  968. private void BtnBrowse_Click(object sender, RoutedEventArgs e)
  969. {
  970. //System.Diagnostics.Process.Start(APP.WKData.WkPath);
  971. //string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  972. Ofd = new System.Windows.Forms.FolderBrowserDialog();
  973. Result = Ofd.ShowDialog();
  974. if (Result == System.Windows.Forms.DialogResult.OK)
  975. {
  976. if (Ofd.SelectedPath != "")
  977. {
  978. txbStoragePath.Content = Ofd.SelectedPath;
  979. //string ApplicationData = ZConfig.dataPath + "fileStorageAddress.txt";
  980. //string temp = ofd.SelectedPath;
  981. //System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  982. }
  983. }
  984. }
  985. /// <summary>
  986. /// 打开文件所在位置
  987. /// </summary>
  988. /// <param name="sender"></param>
  989. /// <param name="e"></param>
  990. private void btnOpen_Click(object sender, RoutedEventArgs e)
  991. {
  992. System.Diagnostics.Process.Start(APP.WKData.WkPath);
  993. }
  994. /// <summary>
  995. /// 更新隐藏录屏工具栏隐藏状态
  996. /// </summary>
  997. void UpdateHideSRToolConfig()
  998. {
  999. if (rbnHide.IsChecked == true)
  1000. {
  1001. //隐藏
  1002. FileToolsCommon.SetConfigValue("IsHideSRTool", "1");
  1003. APP.IsHideSRTool = true;
  1004. }
  1005. else
  1006. {
  1007. //显示
  1008. FileToolsCommon.SetConfigValue("IsHideSRTool", "0");
  1009. APP.IsHideSRTool = false;
  1010. }
  1011. }
  1012. #endregion
  1013. #region 画笔
  1014. /// <summary>
  1015. /// 画笔颜色事件 白色
  1016. /// </summary>
  1017. /// <param name="sender"></param>
  1018. /// <param name="e"></param>
  1019. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  1020. {
  1021. ////创建 DrawingAttributes 类的一个实例
  1022. //drawingAttributes = new DrawingAttributes();
  1023. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  1024. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  1025. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  1026. ////设置 DrawingAttributes 的 Color 属性设置颜色
  1027. drawingAttributes.Color = Colors.White;
  1028. Color = Colors.White;
  1029. }
  1030. /// <summary>
  1031. /// 画笔颜色事件 红色
  1032. /// </summary>
  1033. /// <param name="sender"></param>
  1034. /// <param name="e"></param>
  1035. private void BtnRed_Click(object sender, RoutedEventArgs e)
  1036. {
  1037. //设置 DrawingAttributes 的 Color 属性设置颜色
  1038. drawingAttributes.Color = Colors.Red;
  1039. Color = Colors.Red;
  1040. imgRed.Visibility = Visibility.Visible;
  1041. imgGray.Visibility = Visibility.Collapsed;
  1042. imgCyanBlue.Visibility = Visibility.Collapsed;
  1043. imgYellow.Visibility = Visibility.Collapsed;
  1044. imgBlue.Visibility = Visibility.Collapsed;
  1045. }
  1046. /// <summary>
  1047. /// 画笔颜色事件 黑色
  1048. /// </summary>
  1049. /// <param name="sender"></param>
  1050. /// <param name="e"></param>
  1051. private void BtnGray_Click(object sender, RoutedEventArgs e)
  1052. {
  1053. drawingAttributes.Color = Colors.Black;
  1054. Color = Colors.Black;
  1055. imgRed.Visibility = Visibility.Collapsed;
  1056. imgGray.Visibility = Visibility.Visible;
  1057. imgCyanBlue.Visibility = Visibility.Collapsed;
  1058. imgYellow.Visibility = Visibility.Collapsed;
  1059. imgBlue.Visibility = Visibility.Collapsed;
  1060. }
  1061. /// <summary>
  1062. /// 画笔颜色事件 青色
  1063. /// </summary>
  1064. /// <param name="sender"></param>
  1065. /// <param name="e"></param>
  1066. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  1067. {
  1068. drawingAttributes.Color = Colors.LimeGreen;
  1069. Color = Colors.LimeGreen;
  1070. imgRed.Visibility = Visibility.Collapsed;
  1071. imgGray.Visibility = Visibility.Collapsed;
  1072. imgCyanBlue.Visibility = Visibility.Visible;
  1073. imgYellow.Visibility = Visibility.Collapsed;
  1074. imgBlue.Visibility = Visibility.Collapsed;
  1075. }
  1076. /// <summary>
  1077. /// 画笔颜色事件 黄色
  1078. /// </summary>
  1079. /// <param name="sender"></param>
  1080. /// <param name="e"></param>
  1081. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  1082. {
  1083. drawingAttributes.Color = Colors.Gold;
  1084. Color = Colors.Gold;
  1085. imgRed.Visibility = Visibility.Collapsed;
  1086. imgGray.Visibility = Visibility.Collapsed;
  1087. imgCyanBlue.Visibility = Visibility.Collapsed;
  1088. imgYellow.Visibility = Visibility.Visible;
  1089. imgBlue.Visibility = Visibility.Collapsed;
  1090. }
  1091. /// <summary>
  1092. /// 画笔颜色事件 蓝色
  1093. /// </summary>
  1094. /// <param name="sender"></param>
  1095. /// <param name="e"></param>
  1096. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  1097. {
  1098. drawingAttributes.Color = Colors.DeepSkyBlue;
  1099. Color = Colors.DeepSkyBlue;
  1100. imgRed.Visibility = Visibility.Collapsed;
  1101. imgGray.Visibility = Visibility.Collapsed;
  1102. imgCyanBlue.Visibility = Visibility.Collapsed;
  1103. imgYellow.Visibility = Visibility.Collapsed;
  1104. imgBlue.Visibility = Visibility.Visible;
  1105. }
  1106. /// <summary>
  1107. /// 画笔粗细事件 细
  1108. /// </summary>
  1109. /// <param name="sender"></param>
  1110. /// <param name="e"></param>
  1111. private void RbnFine_Click(object sender, RoutedEventArgs e)
  1112. {
  1113. drawingAttributes.Width = 1;
  1114. drawingAttributes.Height = 1;
  1115. PenSize = 1;
  1116. }
  1117. /// <summary>
  1118. /// 画笔粗细事件 中
  1119. /// </summary>
  1120. /// <param name="sender"></param>
  1121. /// <param name="e"></param>
  1122. private void RbnIn_Click(object sender, RoutedEventArgs e)
  1123. {
  1124. drawingAttributes.Width = 3;
  1125. drawingAttributes.Height = 3;
  1126. PenSize = 3;
  1127. }
  1128. /// <summary>
  1129. /// 画笔粗细事件 粗
  1130. /// </summary>
  1131. /// <param name="sender"></param>
  1132. /// <param name="e"></param>
  1133. private void RbnCrude_Click(object sender, RoutedEventArgs e)
  1134. {
  1135. drawingAttributes.Width = 5;
  1136. drawingAttributes.Height = 5;
  1137. PenSize = 5;
  1138. }
  1139. private void imgCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1140. {
  1141. mouseDown = true;
  1142. }
  1143. #endregion
  1144. #region 导入截图
  1145. /// <summary>
  1146. /// 截图事件
  1147. /// </summary>
  1148. /// <param name="sender"></param>
  1149. /// <param name="e"></param>
  1150. private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
  1151. {
  1152. double do1 = GridContent.ActualHeight;
  1153. double dou = GridMain.ActualHeight;
  1154. Record();
  1155. HideAngleBorder();
  1156. imgCanvas.Margin = new Thickness(0, 0, 0, 0);
  1157. APP.ImgPath = string.Empty;
  1158. string time = GetTimeStamp();
  1159. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
  1160. APP.ImgPath = desktopPath;
  1161. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), desktopPath, false, out BitmapImage bitmap);
  1162. k_hook.Stop();
  1163. if (WindowState == WindowState.Normal)//截图隐藏窗口
  1164. {
  1165. WindowState = WindowState.Minimized;
  1166. }
  1167. if (APP.W_JieTuWindow != null)
  1168. {
  1169. APP.W_JieTuWindow.initialization();
  1170. APP.W_JieTuWindow.Screenshot();
  1171. APP.W_JieTuWindow.InitializeKeyDownEvent();
  1172. APP.W_JieTuWindow.WindowState = WindowState.Maximized;
  1173. APP.W_JieTuWindow.Visibility = Visibility.Visible;
  1174. }
  1175. else
  1176. {
  1177. APP.W_JieTuWindow = new JieTuWindow();
  1178. APP.W_JieTuWindow.InitializeKeyDownEvent();
  1179. // 订阅事件
  1180. APP.W_JieTuWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
  1181. APP.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
  1182. APP.W_JieTuWindow.Show();
  1183. }
  1184. //imgCanvas.Source = new BitmapImage(new Uri(desktopPath));
  1185. }
  1186. /// <summary>
  1187. /// 获取时间戳
  1188. /// </summary>
  1189. /// <returns></returns>
  1190. public string GetTimeStamp()
  1191. {
  1192. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  1193. return Convert.ToInt64(ts.TotalSeconds).ToString();
  1194. }
  1195. /// <summary>
  1196. /// 返回一个时间戳到毫秒
  1197. /// </summary>
  1198. /// <returns></returns>
  1199. public static long Timestamp()
  1200. {
  1201. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  1202. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  1203. return timestr;
  1204. }
  1205. public void WindowType()
  1206. {
  1207. if (WindowState == WindowState.Minimized)//截图完恢复窗口
  1208. {
  1209. Topmost = true;
  1210. WindowState = WindowState.Normal;
  1211. }
  1212. }
  1213. /// <summary>
  1214. /// 截图关闭窗口
  1215. /// </summary>
  1216. /// <param name="text"></param>
  1217. private void frm_ChangeTextEvent(string text)
  1218. {
  1219. if ("关闭窗口".Equals(text))
  1220. {
  1221. if (WindowState == WindowState.Minimized)//截图完恢复窗口
  1222. {
  1223. Topmost = true;
  1224. WindowState = WindowState.Normal;
  1225. }
  1226. InitializeKeyDownEvent();
  1227. if (!string.IsNullOrWhiteSpace(APP.ImgPath) && File.Exists(APP.ImgPath))
  1228. {
  1229. if (APP.pageData.currpage == 0)
  1230. {
  1231. APP.pageData.pagenum += 1;
  1232. APP.pageData.currpage = APP.pageData.pagenum;
  1233. myblackboard.changepage(APP.pageData.currpage - 1);
  1234. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1235. #region 插入页码
  1236. PageData = new List<PageData>();
  1237. for (int i = 1; i <= APP.pageData.pagenum; i++)
  1238. {
  1239. PageData pd = new PageData();
  1240. pd.PageName = i.ToString();// + "页";
  1241. pd.PageCode = i;
  1242. PageData.Add(pd);
  1243. }
  1244. CbxPageList.ItemsSource = PageData;
  1245. CbxPageList.SelectedIndex = APP.pageData.currpage - 1;
  1246. #endregion
  1247. }
  1248. if (APP.PageDrawList.Count >= APP.pageData.currpage)
  1249. {
  1250. APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath = APP.ImgPath;//zxycs
  1251. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = APP.ImgPath;
  1252. }
  1253. else
  1254. {
  1255. Model_DrawData model_DrawData = new Model_DrawData
  1256. {
  1257. PageImagePath = APP.ImgPath,
  1258. PdfImagePath = APP.ImgPath
  1259. };
  1260. APP.PageDrawList.Add(model_DrawData);
  1261. }
  1262. if (APP.PageDrawList.Count >= APP.pageData.currpage && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1263. {
  1264. imgDocumentation.Source = null;
  1265. BitmapImage bitImg = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1266. mouseDown = false;
  1267. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  1268. {
  1269. X = 0.1,
  1270. Y = 0.1
  1271. };
  1272. APP.PageDrawList[APP.pageData.currpage - 1].Type = "截图";
  1273. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  1274. imgCanvas.Source = bitImg;
  1275. imgCanvas.Width = bitImg.Width;
  1276. imgCanvas.Height = bitImg.Height;
  1277. scroMain.ScrollToVerticalOffset(0);
  1278. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  1279. {
  1280. CenterX = imgCanvas.Width,
  1281. CenterY = imgCanvas.Height
  1282. };
  1283. ImgPrint.Visibility = Visibility.Visible;//截图成功可打印
  1284. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1285. btnPrint.IsEnabled = true;
  1286. btnPrint_Black.IsEnabled = true;
  1287. }
  1288. }
  1289. Topmost = false;
  1290. }
  1291. }
  1292. /// <summary>
  1293. /// 截图关闭 非正常关闭截图时,截图清空
  1294. /// </summary>
  1295. private void JietuWindow_click_closeJietuWindowClick()
  1296. {
  1297. if (WindowState == WindowState.Minimized)//截图完恢复窗口
  1298. {
  1299. WindowState = WindowState.Normal;
  1300. }
  1301. APP.W_JieTuWindow = null;
  1302. }
  1303. /// 截图的图片鼠标右键事件
  1304. /// </summary>
  1305. /// <param name="sender"></param>
  1306. /// <param name="e"></param>
  1307. private void imgCanvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
  1308. {
  1309. imgCanvas.Source = null;
  1310. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = null;
  1311. APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath = null;
  1312. }
  1313. /// <summary>
  1314. /// 导入事件
  1315. /// </summary>
  1316. /// <param name="sender"></param>
  1317. /// <param name="e"></param>
  1318. private void BtnImport_Click(object sender, RoutedEventArgs e)
  1319. {
  1320. try
  1321. {
  1322. Record();
  1323. HideAngleBorder();
  1324. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  1325. ofd = new System.Windows.Forms.OpenFileDialog
  1326. {
  1327. //Filter = "文档|*.docx;*.doc;*.ppt;*.pptx",
  1328. //增加导入图片
  1329. Filter = "文档|*.docx;*.doc;*.ppt;*.pptx;*.pdf|图片|*.jpg;*.jpeg;*.png;*.bmp",
  1330. InitialDirectory = desktopPath,
  1331. Multiselect = false,
  1332. AddExtension = true,
  1333. DereferenceLinks = true
  1334. };
  1335. //APP.myloading.Show();
  1336. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
  1337. //new Thread(
  1338. // o =>
  1339. // {
  1340. // Thread.Sleep(400);
  1341. // Dispatcher.Invoke(new Action(() =>
  1342. // {
  1343. // OpenDialog();
  1344. // }
  1345. // ));
  1346. // })
  1347. //{
  1348. // IsBackground = true
  1349. //}.Start();
  1350. }
  1351. catch (Exception ex)
  1352. {
  1353. LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
  1354. }
  1355. }
  1356. /// <summary>
  1357. /// 导入-开始
  1358. /// </summary>
  1359. /// <returns></returns>
  1360. private object InvokeServering()
  1361. {
  1362. Dispatcher.Invoke(new Action(() =>
  1363. {
  1364. result = ofd.ShowDialog();
  1365. }));
  1366. if (result == System.Windows.Forms.DialogResult.OK)
  1367. {
  1368. if (ofd.FileName != "")
  1369. {
  1370. List<string> imagelist = new List<string>() { "jpg", "jpeg", "png", "bmp" };
  1371. Dispatcher.Invoke(new Action(() =>
  1372. {
  1373. APP.myloading.Show();
  1374. myblackboard.changepage(APP.pageData.pagenum);
  1375. }));
  1376. string filepath = ofd.FileName;
  1377. string filesuff = filepath.Substring(filepath.LastIndexOf(".") + 1).ToLower();
  1378. string path = ofd.SafeFileName.Replace(".ppt", "").Replace(".pptx", "").Trim();
  1379. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Replace(".pptx", "typezsygppt").Replace(".pdf", "typepdf").Trim();
  1380. if (type.Contains("typezsygppt"))//ppt
  1381. {
  1382. try
  1383. {
  1384. #region PPT转PDF
  1385. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1386. path = pathTemp + path + ".pdf";
  1387. FileToolsCommon.CreateDirectory(pathTemp);
  1388. //PPT转PDF
  1389. Presentation ppt = new Presentation(filepath);
  1390. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  1391. #endregion
  1392. #region PDF转图片
  1393. // 图片绝对路径集合
  1394. List<string> images = new List<string>();
  1395. string directoryPath = pathTemp;
  1396. //aspose许可证
  1397. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1398. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1399. //l.SetLicense(licenseName);
  1400. //定义Jpeg转换设备
  1401. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  1402. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1403. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1404. //directoryPath += quality;
  1405. Directory.CreateDirectory(directoryPath);
  1406. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1407. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1408. //遍历每一页转为jpg
  1409. for (int i = 1; i <= document.Pages.Count; i++)
  1410. {
  1411. long ii = Timestamp();
  1412. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1413. images.Add(filePathOutPut);
  1414. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1415. try
  1416. {
  1417. device.Process(document.Pages[i], fs);
  1418. fs.Close();
  1419. }
  1420. catch (Exception)
  1421. {
  1422. fs.Close();
  1423. File.Delete(filePathOutPut);
  1424. }
  1425. }
  1426. #endregion
  1427. Dispatcher.Invoke(new Action(() =>
  1428. {
  1429. string[] page = images.ToArray();
  1430. int num = 0;
  1431. int iStart = APP.pageData.pagenum;//导入文档的开始下标
  1432. int iEnd = page.Length + APP.pageData.pagenum;//导入文档的结束下标
  1433. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1434. {
  1435. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1436. {
  1437. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1438. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1439. APP.PageDrawList[i].PageNum = i + 1;
  1440. APP.PageDrawList[i].ImgDocumentation = true;
  1441. APP.PageDrawList[i].Type = "ppt";
  1442. }
  1443. else
  1444. {
  1445. Model_DrawData model_DrawData = new Model_DrawData
  1446. {
  1447. PageImagePath = page[i - APP.pageData.pagenum],
  1448. PdfImagePath = page[i - APP.pageData.pagenum],
  1449. PageNum = i + 1,
  1450. ImgDocumentation = true,
  1451. Type = "ppt"
  1452. };
  1453. APP.PageDrawList.Add(model_DrawData);
  1454. }
  1455. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1456. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1457. btnPrint.IsEnabled = true;
  1458. btnPrint_Black.IsEnabled = true;
  1459. APP.SaveDraw();
  1460. num++;
  1461. }
  1462. if (num > 0)
  1463. {
  1464. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1465. APP.pageData.pagenum += num;
  1466. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1467. }
  1468. if (APP.pageData.currpage > 0 && APP.pageData.currpage <= APP.PageDrawList.Count)
  1469. {
  1470. imgCanvas.Source = null;
  1471. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1472. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1473. btnScreenshot.IsEnabled = false;
  1474. btnScreenshot_Black.IsEnabled = false;
  1475. imgDocumentation.Source = null;
  1476. imgPPT.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1477. scroMain.ScrollToVerticalOffset(0);
  1478. for (int i = iStart; i < iEnd; i++)
  1479. {
  1480. APP.PageDrawList[i].ImageLocation = new TranslateTransform
  1481. {
  1482. X = 0.1,
  1483. Y = 0.1
  1484. };
  1485. APP.PageDrawList[i].IsImageLocation = true;
  1486. APP.PageDrawList[i].ImageSizes = new ScaleTransform
  1487. {
  1488. CenterX = imgCanvas.Width,
  1489. CenterY = imgCanvas.Height
  1490. };
  1491. }
  1492. }
  1493. else
  1494. {
  1495. imgDocumentation.Source = null;
  1496. imgCanvas.Source = null;
  1497. imgPPT.Source = null;
  1498. ///截图可用
  1499. ImgScreenshot.Visibility = Visibility.Visible;
  1500. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1501. btnScreenshot.IsEnabled = true;
  1502. btnScreenshot_Black.IsEnabled = true;
  1503. }
  1504. }));
  1505. }
  1506. catch (Exception ex)
  1507. {
  1508. Dispatcher.Invoke(new Action(() =>
  1509. {
  1510. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1511. }));
  1512. LogHelper.WriteErrLog("【打开ppt】(OpenDialog PPT)" + ex.Message, ex);
  1513. }
  1514. }
  1515. else if (type.Contains("typepdf"))
  1516. {
  1517. try
  1518. {
  1519. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1520. #region PDF转图片
  1521. // 图片绝对路径集合
  1522. List<string> images = new List<string>();
  1523. string directoryPath = pathTemp;
  1524. //aspose许可证
  1525. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1526. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1527. //l.SetLicense(licenseName);
  1528. //定义Jpeg转换设备
  1529. Aspose.Pdf.Document document = new Aspose.Pdf.Document(filepath);
  1530. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1531. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1532. //directoryPath += quality;
  1533. Directory.CreateDirectory(directoryPath);
  1534. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1535. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1536. //遍历每一页转为jpg
  1537. for (int i = 1; i <= document.Pages.Count; i++)
  1538. {
  1539. long ii = Timestamp();
  1540. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1541. images.Add(filePathOutPut);
  1542. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1543. try
  1544. {
  1545. device.Process(document.Pages[i], fs);
  1546. fs.Close();
  1547. }
  1548. catch (Exception)
  1549. {
  1550. fs.Close();
  1551. File.Delete(filePathOutPut);
  1552. }
  1553. }
  1554. #endregion
  1555. string[] page = images.ToArray();
  1556. int num = 0;
  1557. int iStart = APP.pageData.pagenum;//导入文档的开始下标
  1558. int iEnd = page.Length + APP.pageData.pagenum;//导入文档的结束下标
  1559. Dispatcher.Invoke(new Action(() =>
  1560. {
  1561. for (int i = APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1562. {
  1563. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1564. {
  1565. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1566. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1567. APP.PageDrawList[i].PageNum = i + 1;
  1568. APP.PageDrawList[i].ImgDocumentation = true;
  1569. APP.PageDrawList[i].Type = "word";
  1570. }
  1571. else
  1572. {
  1573. Model_DrawData model_DrawData = new Model_DrawData
  1574. {
  1575. PageImagePath = page[i - APP.pageData.pagenum],
  1576. PdfImagePath = page[i - APP.pageData.pagenum],
  1577. PageNum = i + 1,
  1578. ImgDocumentation = true,
  1579. Type = "word"
  1580. };
  1581. APP.PageDrawList.Add(model_DrawData);
  1582. }
  1583. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1584. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1585. btnPrint.IsEnabled = true;
  1586. btnPrint_Black.IsEnabled = true;
  1587. APP.SaveDraw();
  1588. num++;
  1589. }
  1590. if (num > 0)
  1591. {
  1592. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1593. APP.pageData.pagenum += num;
  1594. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1595. }
  1596. if (APP.pageData.currpage > 0 && APP.pageData.currpage <= APP.PageDrawList.Count)
  1597. {
  1598. imgCanvas.Source = null;
  1599. imgPPT.Source = null;
  1600. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1601. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1602. btnScreenshot.IsEnabled = false;
  1603. btnScreenshot_Black.IsEnabled = false;
  1604. imgDocumentation.Visibility = Visibility.Visible;
  1605. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  1606. scroMain.ScrollToVerticalOffset(0);
  1607. }
  1608. else
  1609. {
  1610. imgDocumentation.Source = null;
  1611. imgCanvas.Source = null;
  1612. imgPPT.Source = null;
  1613. ///截图可用
  1614. ImgScreenshot.Visibility = Visibility.Visible;
  1615. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1616. btnScreenshot.IsEnabled = true;
  1617. btnScreenshot_Black.IsEnabled = true;
  1618. }
  1619. }));
  1620. }
  1621. catch (Exception ex)
  1622. {
  1623. Dispatcher.Invoke(new Action(() =>
  1624. {
  1625. MessageWindow.Show(ex.Message);
  1626. }));
  1627. LogHelper.WriteErrLog("【打开pdf】(OpenDialog pdf)" + ex.Message, ex);
  1628. }
  1629. }
  1630. else if (imagelist.Contains(filesuff))///导入图片
  1631. {
  1632. string imagepath = AppDomain.CurrentDomain.BaseDirectory + "temp";
  1633. if (!Directory.Exists(imagepath))
  1634. {
  1635. Directory.CreateDirectory(imagepath);
  1636. }
  1637. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  1638. string timestr = Convert.ToInt64(ts.TotalMilliseconds).ToString();
  1639. string filepathCopy = Path.Combine(imagepath, timestr + ofd.SafeFileName);
  1640. System.IO.File.Copy(filepath, filepathCopy);
  1641. filepath = filepathCopy;
  1642. APP.ImgPath = filepath;
  1643. Dispatcher.Invoke(new Action(() =>
  1644. {
  1645. if (APP.pageData.currpage == 0)
  1646. {
  1647. APP.pageData.pagenum += 1;
  1648. APP.pageData.currpage = APP.pageData.pagenum;
  1649. myblackboard.changepage(APP.pageData.currpage - 1);
  1650. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1651. #region 插入页码
  1652. PageData = new List<PageData>();
  1653. for (int i = 1; i <= APP.pageData.pagenum; i++)
  1654. {
  1655. PageData pd = new PageData();
  1656. pd.PageName = i.ToString();// + "页";
  1657. pd.PageCode = i;
  1658. PageData.Add(pd);
  1659. }
  1660. CbxPageList.ItemsSource = PageData;
  1661. CbxPageList.SelectedIndex = APP.pageData.currpage - 1;
  1662. #endregion
  1663. }
  1664. else
  1665. {
  1666. APP.pageData.pagenum += 1;
  1667. APP.pageData.currpage = APP.pageData.pagenum;
  1668. myblackboard.changepage(APP.pageData.currpage - 1);
  1669. }
  1670. if (APP.PageDrawList.Count >= APP.pageData.currpage)
  1671. {
  1672. APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath = APP.ImgPath;//zxycs
  1673. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = APP.ImgPath;
  1674. }
  1675. else
  1676. {
  1677. Model_DrawData model_DrawData = new Model_DrawData
  1678. {
  1679. PageImagePath = APP.ImgPath,
  1680. PdfImagePath = APP.ImgPath
  1681. };
  1682. APP.PageDrawList.Add(model_DrawData);
  1683. }
  1684. if (APP.PageDrawList.Count >= APP.pageData.currpage && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1685. {
  1686. imgDocumentation.Source = null;
  1687. BitmapImage bitImg = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1688. mouseDown = false;
  1689. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  1690. {
  1691. X = 0.1,
  1692. Y = 0.1
  1693. };
  1694. APP.PageDrawList[APP.pageData.currpage - 1].Type = "截图";
  1695. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  1696. imgCanvas.Source = bitImg;
  1697. imgCanvas.Width = bitImg.Width;
  1698. imgCanvas.Height = bitImg.Height;
  1699. scroMain.ScrollToVerticalOffset(0);
  1700. imgCanvas.Margin = new Thickness(APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X, APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y, 0, 0);
  1701. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  1702. {
  1703. CenterX = imgCanvas.Width,
  1704. CenterY = imgCanvas.Height
  1705. };
  1706. ImgPrint.Visibility = Visibility.Visible;//截图成功可打印
  1707. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1708. btnPrint.IsEnabled = true;
  1709. btnPrint_Black.IsEnabled = true;
  1710. }
  1711. }));
  1712. }
  1713. else//word
  1714. {
  1715. try
  1716. {
  1717. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1718. string[] page = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
  1719. int num = 0;
  1720. Dispatcher.Invoke(new Action(() =>
  1721. {
  1722. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1723. {
  1724. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1725. {
  1726. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1727. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1728. APP.PageDrawList[i].PageNum = i + 1;
  1729. APP.PageDrawList[i].ImgDocumentation = true;
  1730. APP.PageDrawList[i].Type = "word";
  1731. }
  1732. else
  1733. {
  1734. Model_DrawData model_DrawData = new Model_DrawData
  1735. {
  1736. PageImagePath = page[i - APP.pageData.pagenum],
  1737. PdfImagePath = page[i - APP.pageData.pagenum],
  1738. PageNum = i + 1,
  1739. ImgDocumentation = true,
  1740. Type = "word"
  1741. };
  1742. APP.PageDrawList.Add(model_DrawData);
  1743. }
  1744. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1745. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1746. btnPrint.IsEnabled = true;
  1747. btnPrint_Black.IsEnabled = true;
  1748. APP.SaveDraw();
  1749. num++;
  1750. }
  1751. if (num > 0)
  1752. {
  1753. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1754. APP.pageData.pagenum += num;
  1755. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1756. }
  1757. if (APP.pageData.currpage > 0 && APP.pageData.currpage <= APP.PageDrawList.Count)
  1758. {
  1759. imgCanvas.Source = null;
  1760. imgPPT.Source = null;
  1761. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1762. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1763. btnScreenshot.IsEnabled = false;
  1764. btnScreenshot_Black.IsEnabled = false;
  1765. imgDocumentation.Visibility = Visibility.Visible;
  1766. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  1767. scroMain.ScrollToVerticalOffset(0);
  1768. }
  1769. else
  1770. {
  1771. imgDocumentation.Source = null;
  1772. imgCanvas.Source = null;
  1773. imgPPT.Source = null;
  1774. ///截图可用
  1775. ImgScreenshot.Visibility = Visibility.Visible;
  1776. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1777. btnScreenshot.IsEnabled = true;
  1778. btnScreenshot_Black.IsEnabled = true;
  1779. }
  1780. }));
  1781. }
  1782. catch (Exception ex)
  1783. {
  1784. Dispatcher.Invoke(new Action(() =>
  1785. {
  1786. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1787. }));
  1788. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
  1789. }
  1790. }
  1791. #region 插入页码
  1792. Dispatcher.Invoke(new Action(() =>
  1793. {
  1794. PageData = new List<PageData>();
  1795. for (int i = 1; i <= APP.pageData.pagenum; i++)
  1796. {
  1797. PageData pd = new PageData();
  1798. pd.PageName = i.ToString();//+ "页";
  1799. pd.PageCode = i;
  1800. PageData.Add(pd);
  1801. }
  1802. CbxPageList.ItemsSource = PageData;
  1803. CbxPageList.SelectedIndex = APP.pageData.currpage - 1;
  1804. }));
  1805. #endregion
  1806. }
  1807. }
  1808. //OpenDialog();
  1809. return "";
  1810. }
  1811. /// <summary>
  1812. /// 导入-结束
  1813. /// </summary>
  1814. /// <returns></returns>
  1815. public void InvokeServerCompate(object obj)
  1816. {
  1817. //APP.myloading.Hide();
  1818. APP.myloading.Hide();
  1819. }
  1820. /// <summary>
  1821. /// 导入文档
  1822. /// </summary>
  1823. private void OpenDialog()
  1824. {
  1825. Dispatcher.Invoke(new Action(() =>
  1826. {
  1827. result = ofd.ShowDialog();
  1828. if (result == System.Windows.Forms.DialogResult.OK)
  1829. {
  1830. if (ofd.FileName != "")
  1831. {
  1832. APP.myloading.Show();
  1833. myblackboard.changepage(APP.pageData.pagenum);
  1834. #region PPT转PDF
  1835. string filepath = ofd.FileName;
  1836. string path = ofd.SafeFileName.Replace(".ppt", "").Replace(".pptx", "").Trim();
  1837. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Replace(".pptx", "typezsygppt").Replace(".pdf", "typepdf").Trim();
  1838. if (type.Contains("typezsygppt"))//ppt
  1839. {
  1840. try
  1841. {
  1842. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1843. path = pathTemp + path + ".pdf";
  1844. FileToolsCommon.CreateDirectory(pathTemp);
  1845. //PPT转PDF
  1846. Presentation ppt = new Presentation(filepath);
  1847. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  1848. #endregion
  1849. #region PDF转图片
  1850. // 图片绝对路径集合
  1851. List<string> images = new List<string>();
  1852. string directoryPath = pathTemp;
  1853. //aspose许可证
  1854. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1855. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1856. //l.SetLicense(licenseName);
  1857. //定义Jpeg转换设备
  1858. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  1859. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1860. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1861. //directoryPath += quality;
  1862. Directory.CreateDirectory(directoryPath);
  1863. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1864. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1865. //遍历每一页转为jpg
  1866. for (int i = 1; i <= document.Pages.Count; i++)
  1867. {
  1868. long ii = Timestamp();
  1869. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1870. images.Add(filePathOutPut);
  1871. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1872. try
  1873. {
  1874. device.Process(document.Pages[i], fs);
  1875. fs.Close();
  1876. }
  1877. catch (Exception)
  1878. {
  1879. fs.Close();
  1880. File.Delete(filePathOutPut);
  1881. }
  1882. }
  1883. #endregion
  1884. string[] page = images.ToArray();
  1885. int num = 0;
  1886. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1887. {
  1888. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1889. {
  1890. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1891. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1892. APP.PageDrawList[i].PageNum = i + 1;
  1893. APP.PageDrawList[i].ImgDocumentation = true;
  1894. }
  1895. else
  1896. {
  1897. Model_DrawData model_DrawData = new Model_DrawData
  1898. {
  1899. PageImagePath = page[i - APP.pageData.pagenum],
  1900. PdfImagePath = page[i - APP.pageData.pagenum],
  1901. PageNum = i + 1,
  1902. ImgDocumentation = true
  1903. };
  1904. APP.PageDrawList.Add(model_DrawData);
  1905. }
  1906. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1907. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1908. btnPrint.IsEnabled = true;
  1909. btnPrint_Black.IsEnabled = true;
  1910. APP.SaveDraw();
  1911. num++;
  1912. }
  1913. if (num > 0)
  1914. {
  1915. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1916. APP.pageData.pagenum += num;
  1917. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1918. }
  1919. if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
  1920. {
  1921. imgCanvas.Source = null;
  1922. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1923. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1924. btnScreenshot.IsEnabled = false;
  1925. btnScreenshot_Black.IsEnabled = false;
  1926. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  1927. }
  1928. else
  1929. {
  1930. imgDocumentation.Source = null;
  1931. imgCanvas.Source = null;
  1932. ///截图可用
  1933. ImgScreenshot.Visibility = Visibility.Visible;
  1934. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1935. btnScreenshot.IsEnabled = true;
  1936. btnScreenshot_Black.IsEnabled = true;
  1937. }
  1938. APP.myloading.Hide();
  1939. }
  1940. catch (Exception ex)
  1941. {
  1942. APP.myloading.Hide();
  1943. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1944. LogHelper.WriteErrLog("【打开ppt】(OpenDialog PPT)" + ex.Message, ex);
  1945. }
  1946. }
  1947. else if (type.Contains("typepdf"))
  1948. {
  1949. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1950. #region PDF转图片
  1951. // 图片绝对路径集合
  1952. List<string> images = new List<string>();
  1953. string directoryPath = pathTemp;
  1954. //aspose许可证
  1955. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1956. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1957. //l.SetLicense(licenseName);
  1958. //定义Jpeg转换设备
  1959. Aspose.Pdf.Document document = new Aspose.Pdf.Document(filepath);
  1960. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1961. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1962. //directoryPath += quality;
  1963. Directory.CreateDirectory(directoryPath);
  1964. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1965. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1966. //遍历每一页转为jpg
  1967. for (int i = 1; i <= document.Pages.Count; i++)
  1968. {
  1969. long ii = Timestamp();
  1970. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1971. images.Add(filePathOutPut);
  1972. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1973. try
  1974. {
  1975. device.Process(document.Pages[i], fs);
  1976. fs.Close();
  1977. }
  1978. catch (Exception)
  1979. {
  1980. fs.Close();
  1981. File.Delete(filePathOutPut);
  1982. }
  1983. }
  1984. #endregion
  1985. string[] page = images.ToArray();
  1986. int num = 0;
  1987. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1988. {
  1989. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1990. {
  1991. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1992. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1993. APP.PageDrawList[i].PageNum = i + 1;
  1994. APP.PageDrawList[i].ImgDocumentation = true;
  1995. }
  1996. else
  1997. {
  1998. Model_DrawData model_DrawData = new Model_DrawData
  1999. {
  2000. PageImagePath = page[i - APP.pageData.pagenum],
  2001. PdfImagePath = page[i - APP.pageData.pagenum],
  2002. PageNum = i + 1,
  2003. ImgDocumentation = true
  2004. };
  2005. APP.PageDrawList.Add(model_DrawData);
  2006. }
  2007. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  2008. ImgPrintTwo.Visibility = Visibility.Collapsed;
  2009. btnPrint.IsEnabled = true;
  2010. btnPrint_Black.IsEnabled = true;
  2011. APP.SaveDraw();
  2012. num++;
  2013. }
  2014. if (num > 0)
  2015. {
  2016. APP.pageData.currpage = APP.pageData.pagenum + 1;
  2017. APP.pageData.pagenum += num;
  2018. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  2019. }
  2020. if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
  2021. {
  2022. imgCanvas.Source = null;
  2023. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  2024. ImgScreenshotTwo.Visibility = Visibility.Visible;
  2025. btnScreenshot.IsEnabled = false;
  2026. btnScreenshot_Black.IsEnabled = false;
  2027. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  2028. }
  2029. else
  2030. {
  2031. imgDocumentation.Source = null;
  2032. imgCanvas.Source = null;
  2033. ///截图可用
  2034. ImgScreenshot.Visibility = Visibility.Visible;
  2035. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  2036. btnScreenshot.IsEnabled = true;
  2037. btnScreenshot_Black.IsEnabled = true;
  2038. }
  2039. APP.myloading.Hide();
  2040. }
  2041. else//word
  2042. {
  2043. try
  2044. {
  2045. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  2046. string[] page = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
  2047. int num = 0;
  2048. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  2049. {
  2050. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  2051. {
  2052. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  2053. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  2054. APP.PageDrawList[i].PageNum = i + 1;
  2055. APP.PageDrawList[i].ImgDocumentation = true;
  2056. }
  2057. else
  2058. {
  2059. Model_DrawData model_DrawData = new Model_DrawData
  2060. {
  2061. PageImagePath = page[i - APP.pageData.pagenum],
  2062. PdfImagePath = page[i - APP.pageData.pagenum],
  2063. PageNum = i + 1,
  2064. ImgDocumentation = true
  2065. };
  2066. APP.PageDrawList.Add(model_DrawData);
  2067. }
  2068. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  2069. ImgPrintTwo.Visibility = Visibility.Collapsed;
  2070. btnPrint.IsEnabled = true;
  2071. btnPrint_Black.IsEnabled = true;
  2072. APP.SaveDraw();
  2073. num++;
  2074. }
  2075. if (num > 0)
  2076. {
  2077. APP.pageData.currpage = APP.pageData.pagenum + 1;
  2078. APP.pageData.pagenum += num;
  2079. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  2080. }
  2081. if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
  2082. {
  2083. imgCanvas.Source = null;
  2084. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  2085. ImgScreenshotTwo.Visibility = Visibility.Visible;
  2086. btnScreenshot.IsEnabled = false;
  2087. btnScreenshot_Black.IsEnabled = false;
  2088. imgDocumentation.Visibility = Visibility.Visible;
  2089. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  2090. }
  2091. else
  2092. {
  2093. imgDocumentation.Source = null;
  2094. imgCanvas.Source = null;
  2095. ///截图可用
  2096. ImgScreenshot.Visibility = Visibility.Visible;
  2097. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  2098. btnScreenshot.IsEnabled = true;
  2099. btnScreenshot_Black.IsEnabled = true;
  2100. }
  2101. APP.myloading.Hide();
  2102. }
  2103. catch (Exception ex)
  2104. {
  2105. APP.myloading.Hide();
  2106. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
  2107. }
  2108. }
  2109. }
  2110. }
  2111. }
  2112. ));
  2113. }
  2114. #region 导入转换图片
  2115. /// <summary>
  2116. /// 生成图片
  2117. /// </summary>
  2118. /// <param name="_path">图片地址</param>
  2119. /// <param name="_saveimg">保存位置</param>
  2120. /// <param name="_rectangle">图片位置</param>
  2121. /// <param name="errmsg">错误消息</param>
  2122. /// <returns></returns>
  2123. private bool MergerImg(string _path, string _saveimg, RectangleF _rectangle, out string errmsg)
  2124. {
  2125. errmsg = null;
  2126. try
  2127. {
  2128. Bitmap bitmap = null;
  2129. //创建要显示的图片对象,根据参数的个数设置宽度
  2130. Bitmap backgroudImg = new Bitmap((int)gridM.ActualWidth, (int)gridM.ActualHeight);
  2131. Graphics g = Graphics.FromImage(backgroudImg);
  2132. //清除画布,背景设置为白色
  2133. g.Clear(System.Drawing.Color.White);
  2134. if (!string.IsNullOrWhiteSpace(_path))
  2135. {
  2136. bitmap = ImageHelper.ReadBitmapFile(_path);
  2137. g.DrawImage(bitmap, _rectangle);
  2138. }
  2139. backgroudImg.Save(_saveimg);
  2140. g.Dispose();
  2141. backgroudImg.Dispose();
  2142. if (bitmap != null)
  2143. {
  2144. bitmap.Dispose();
  2145. }
  2146. GC.Collect();
  2147. return true;
  2148. }
  2149. catch (Exception ex)
  2150. {
  2151. errmsg = ex.Message;
  2152. LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
  2153. return false;
  2154. }
  2155. }
  2156. /// <summary>
  2157. /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法: ConvertPDF2Image("F:\\PdfFile.doc", "F:\\",
  2158. /// "ImageFile", 1, 20, ImageFormat.Png, 256);
  2159. /// </summary>
  2160. /// <param name="pdfInputPath">Word文件路径</param>
  2161. /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
  2162. /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
  2163. /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
  2164. /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
  2165. /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
  2166. /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
  2167. public List<string> ConvertWordToImage(string wordInputPath, string imageOutputPath,
  2168. string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution)
  2169. {
  2170. // 返回的图片绝对路径集合
  2171. List<string> images = new List<string>();
  2172. try
  2173. {
  2174. // open word file
  2175. Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);
  2176. // validate parameter
  2177. if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
  2178. if (imageOutputPath.Trim().Length == 0) { imageOutputPath = System.IO.Path.GetDirectoryName(wordInputPath); }
  2179. if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
  2180. if (imageName.Trim().Length == 0) { imageName = System.IO.Path.GetFileNameWithoutExtension(wordInputPath); }
  2181. if (startPageNum <= 0) { startPageNum = 1; }
  2182. if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
  2183. if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
  2184. if (imageFormat == null) { imageFormat = ImageFormat.Png; }
  2185. if (resolution <= 0) { resolution = 128; }
  2186. ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat))
  2187. {
  2188. Resolution = resolution
  2189. };
  2190. // start to convert each page
  2191. for (int i = startPageNum; i <= endPageNum; i++)
  2192. {
  2193. imageSaveOptions.PageIndex = i - 1;
  2194. doc.Save(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString(), imageSaveOptions);
  2195. images.Add(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString());
  2196. APP.num++;
  2197. }
  2198. imageSaveOptions = null;
  2199. doc = null;
  2200. }
  2201. catch (Exception ex)
  2202. {
  2203. //if(ex.Message.ToString().Equals("{\"The document appears to be corrupted and cannot be loaded.\"}"))
  2204. //{
  2205. // MessageWindow.Show("Word文件无效或者Word文件被加密!");
  2206. //}
  2207. //else
  2208. //{
  2209. MessageWindow.Show("该文件无法使用!");
  2210. //}
  2211. LogHelper.WriteErrLog("【导入方法(ConvertWordToImage)】错误日志:" + ex.Message, ex);
  2212. }
  2213. return images;
  2214. }
  2215. private static Aspose.Words.SaveFormat GetSaveFormat(ImageFormat imageFormat)
  2216. {
  2217. Aspose.Words.SaveFormat sf;// = SaveFormat.Unknown;
  2218. if (imageFormat.Equals(ImageFormat.Png))
  2219. {
  2220. sf = Aspose.Words.SaveFormat.Png;
  2221. }
  2222. else if (imageFormat.Equals(ImageFormat.Jpeg))
  2223. {
  2224. sf = Aspose.Words.SaveFormat.Jpeg;
  2225. }
  2226. else if (imageFormat.Equals(ImageFormat.Tiff))
  2227. {
  2228. sf = Aspose.Words.SaveFormat.Tiff;
  2229. }
  2230. else if (imageFormat.Equals(ImageFormat.Bmp))
  2231. {
  2232. sf = Aspose.Words.SaveFormat.Bmp;
  2233. }
  2234. else
  2235. {
  2236. sf = Aspose.Words.SaveFormat.Unknown;
  2237. }
  2238. return sf;
  2239. }
  2240. #endregion
  2241. #endregion
  2242. #region 上传 列表
  2243. /// <summary>
  2244. /// 上传事件
  2245. /// </summary>
  2246. /// <param name="sender"></param>
  2247. /// <param name="e"></param>
  2248. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  2249. {
  2250. //if (gridUpload.Visibility == Visibility.Visible)
  2251. //{
  2252. // gridUpload.Visibility = Visibility.Collapsed;
  2253. // GridMain.Visibility = Visibility.Visible;
  2254. // //ImgRecord.Visibility = Visibility.Visible;//上传结束时可录制
  2255. // //ImgRecordTwo.Visibility = Visibility.Collapsed;//上传结束时可录制
  2256. // //BtnRecord.IsEnabled = true;//设置结束时可录制
  2257. // if (APP.pageData.pagenum > 0)
  2258. // {
  2259. // gridPage.Visibility = Visibility.Visible;
  2260. // }
  2261. // DataContext = APP.pageData;
  2262. //}
  2263. //else
  2264. //{
  2265. // gridPage.Visibility = Visibility.Collapsed;
  2266. // gridUpload.Visibility = Visibility.Visible;
  2267. // GridMain.Visibility = Visibility.Collapsed;
  2268. // //ImgRecord.Visibility = Visibility.Collapsed;//上传时不可录制
  2269. // //ImgRecordTwo.Visibility = Visibility.Visible;//上传时不可录制
  2270. // //BtnRecord.IsEnabled = false;//上传时不可录制
  2271. // InitializeUpload();
  2272. //}
  2273. if (GridMyVideo.Visibility == Visibility.Visible)
  2274. {
  2275. GridMyVideo.Visibility = Visibility.Collapsed;
  2276. GridMain.Visibility = Visibility.Visible;
  2277. if (APP.pageData.pagenum > 0)
  2278. {
  2279. gridPage.Visibility = Visibility.Visible;
  2280. }
  2281. DataContext = APP.pageData;
  2282. }
  2283. else
  2284. {
  2285. PageHide();
  2286. GridMyVideo.Visibility = Visibility.Visible;
  2287. LoadUploadInitData();
  2288. }
  2289. //btnStop.IsEnabled = true;//停止录制按钮可点击
  2290. }
  2291. /// <summary>
  2292. /// 初始化上传
  2293. /// </summary>
  2294. public void InitializeUpload()
  2295. {
  2296. APP.myloading.Show();
  2297. //MouseNumber = 0;
  2298. IsModify = false;
  2299. //加载视频列表
  2300. LoadingVideoList();
  2301. int i = 1;
  2302. bool isColour = true;
  2303. pageData.menuList.Clear();
  2304. //显示视频
  2305. foreach (Model_Video videoinfo in model_VideoList)
  2306. {
  2307. //是否已上传
  2308. //videoinfo.IsUpload;
  2309. //录制时间
  2310. //videoinfo.RSTime;
  2311. //文件大小
  2312. //videoinfo.VideoSize;
  2313. //文件缩略图路径
  2314. //videoinfo.ThumbnailPath;
  2315. //文件唯一标示 上传事件筛选需要上传的视频
  2316. //videoinfo.FileGuid;
  2317. //文件存储路径
  2318. //videoinfo.VidePath;
  2319. string colour = "#FFFFFF";
  2320. if (isColour == true)
  2321. {
  2322. colour = "#FFFFFF";
  2323. isColour = false;
  2324. }
  2325. else
  2326. {
  2327. colour = "#E6F1FF";
  2328. isColour = true;
  2329. }
  2330. string vis = "Visible";
  2331. string cos = "Collapsed";
  2332. if (!videoinfo.IsUpload)
  2333. {
  2334. vis = "Collapsed";
  2335. cos = "Visible";
  2336. }
  2337. //if(i==1)//ceshi
  2338. //{
  2339. // vis = "Visible";
  2340. // cos = "Collapsed";
  2341. //}
  2342. if (i <= 16)
  2343. {
  2344. pageData.menuList.Add(new FileDirectoryModel()
  2345. {
  2346. SerialNumber = i,
  2347. VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2348. Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2349. FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
  2350. VideoDuration = 0,
  2351. VideoSize = videoinfo.VideoSize,
  2352. VideoTime = videoinfo.RSTime,
  2353. IsEnabled = false,
  2354. Path = videoinfo.VideoPath,
  2355. Colour = colour,
  2356. Visi = vis,
  2357. Coll = cos,
  2358. FileGuid = videoinfo.FileGuid,
  2359. VideoType = videoinfo.VideoType.ToString(),
  2360. VideoSizes = videoinfo.VideoSizebyte
  2361. }); ;
  2362. }
  2363. i++;
  2364. }
  2365. Currpage = 0;
  2366. PageNum = 0;
  2367. if (pageData.menuList.Count > 0)
  2368. {
  2369. Currpage = 1;
  2370. txbCurrpageTwo.Text = Currpage.ToString();
  2371. stpUp.Visibility = Visibility.Visible;
  2372. }
  2373. else
  2374. {
  2375. stpUp.Visibility = Visibility.Hidden;
  2376. }
  2377. PageNum = model_VideoList.Count;
  2378. if (PageNum > 0)
  2379. {
  2380. int t = 1;
  2381. while (PageNum > 16 * t)
  2382. {
  2383. t++;
  2384. }
  2385. PageNum = t;
  2386. }
  2387. else
  2388. {
  2389. PageNum = 0;
  2390. }
  2391. txbPageNumTwo.Text = PageNum.ToString();
  2392. APP.myloading.Hide();
  2393. DataContext = pageData;
  2394. }
  2395. /// <summary>
  2396. /// 当前页
  2397. /// </summary>
  2398. private int Currpage = 0;
  2399. /// <summary>
  2400. /// 总页码
  2401. /// </summary>
  2402. private int PageNum = 0;
  2403. /// <summary>
  2404. /// 加载视频列表
  2405. /// </summary>
  2406. public void LoadingVideoList()
  2407. {
  2408. try
  2409. {
  2410. model_VideoList = new List<Model_Video>();
  2411. foreach (Model_WKData Vdata in APP.WKDataList)
  2412. {
  2413. #region 计时器初始化
  2414. if (Vdata.VideoList == null)
  2415. {
  2416. continue;
  2417. }
  2418. foreach (Model_Video videoinfo in Vdata.VideoList)
  2419. {
  2420. try
  2421. {
  2422. if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
  2423. {
  2424. continue;
  2425. }
  2426. if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
  2427. {
  2428. videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMB(videoinfo.VideoPath).ToString() + " MB";
  2429. videoinfo.VideoSizebyte = FileToolsCommon.GetFileSize(videoinfo.VideoPath);
  2430. }
  2431. model_VideoList.Add(videoinfo);
  2432. }
  2433. catch (Exception ex)
  2434. {
  2435. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  2436. }
  2437. }
  2438. #endregion
  2439. }
  2440. //翻转
  2441. if (model_VideoList.Count > 1)
  2442. {
  2443. model_VideoList.Reverse();
  2444. }
  2445. }
  2446. catch (Exception ex)
  2447. {
  2448. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  2449. }
  2450. }
  2451. ////定义事件
  2452. //public event ChangeTextHandler ChangeTextEvents;
  2453. /// <summary>
  2454. /// 上传
  2455. /// </summary>
  2456. /// <param name="sender"></param>
  2457. /// <param name="e"></param>
  2458. private void BtnUploads_Click(object sender, RoutedEventArgs e)
  2459. {
  2460. if (APP.IsLoginType == false)
  2461. {
  2462. Login();
  2463. return;
  2464. }
  2465. pageData.menuList[Subscript].IsEnabled = false;
  2466. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnUpload");
  2467. for (int i = 0; i < buttons.Count; i++)
  2468. {
  2469. if (buttons[i] == sender)
  2470. {
  2471. DAL_Upload dAL_Upload = new DAL_Upload();
  2472. if (dAL_Upload.UploadVideo(pageData.menuList[i].FileGuid, out string ErrMessage))
  2473. {
  2474. //MessageWindow.Show("视频上传服务器成功!");
  2475. if (APP.W_UploadWindow == null)
  2476. {
  2477. APP.W_UploadWindow = new UploadWindow
  2478. {
  2479. Owner = this
  2480. };
  2481. APP.W_UploadWindow.ChangeTextEvents += new ChangeTextHandlers(frm_ChangeTextEvents);
  2482. }
  2483. //long size = Convert.ToInt64(FileToolsCommon.GetFileSizeByMB(pageData.menuList[i].FilePath));
  2484. APP.W_UploadWindow.Initialize(pageData.menuList[i].VideoName, pageData.menuList[i].VideoSizes, pageData.menuList[i].VideoType, pageData.menuList[i].FileGuid, i);
  2485. APP.W_UploadWindow.ShowDialog();
  2486. }
  2487. else
  2488. {
  2489. MessageWindow.Show(ErrMessage);
  2490. }
  2491. }
  2492. }
  2493. }
  2494. /// <summary>
  2495. /// 上传返回事件
  2496. /// </summary>
  2497. /// <param name="text"></param>
  2498. private void frm_ChangeTextEvents(string text, int i)
  2499. {
  2500. if ("上传成功".Equals(text))
  2501. {
  2502. pageData.menuList[i].Visi = "Visible";
  2503. pageData.menuList[i].Coll = "Collapsed";
  2504. DataContext = pageData;
  2505. }
  2506. }
  2507. /// <summary>
  2508. /// 删除
  2509. /// </summary>
  2510. /// <param name="sender"></param>
  2511. /// <param name="e"></param>
  2512. private void BtnDelete_Click(object sender, RoutedEventArgs e)
  2513. {
  2514. MessageBoxResult dr = MessageWindow.Show("确定删除该视频?", "提示", MessageBoxButton.OKCancel);
  2515. if (dr == MessageBoxResult.OK)
  2516. {
  2517. pageData.menuList[Subscript].IsEnabled = false;
  2518. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnDelete");
  2519. for (int i = 0; i < buttons.Count; i++)
  2520. {
  2521. if (buttons[i] == sender)
  2522. {
  2523. //if (APP.W_PromptWindow == null)
  2524. //{
  2525. // APP.W_PromptWindow = new PromptWindow();
  2526. // APP.W_PromptWindow.Owner = this;
  2527. //}
  2528. //APP.W_PromptWindow.Initialize(pageData.menuList[i].VideoName);
  2529. //APP.W_PromptWindow.ShowDialog();
  2530. foreach (Model_WKData wKData in APP.WKDataList)
  2531. {
  2532. if (wKData.VideoList == null)
  2533. {
  2534. continue;
  2535. }
  2536. if (wKData.VideoList.Exists(x => x.FileGuid == pageData.menuList[i].FileGuid))
  2537. {
  2538. try
  2539. {
  2540. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).VideoPath);
  2541. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).ThumbnailPath);
  2542. wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid));
  2543. InitializeUpload();
  2544. return;
  2545. }
  2546. catch (Exception ex)
  2547. {
  2548. MessageWindow.Show("无法删除视频!" + ex.Message);
  2549. return;
  2550. }
  2551. }
  2552. }
  2553. }
  2554. }
  2555. }
  2556. }
  2557. /// <summary>
  2558. /// 播放
  2559. /// </summary>
  2560. /// <param name="sender"></param>
  2561. /// <param name="e"></param>
  2562. private void BtnPlay_Click(object sender, RoutedEventArgs e)
  2563. {
  2564. pageData.menuList[Subscript].IsEnabled = false;
  2565. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnPlay");
  2566. for (int i = 0; i < buttons.Count; i++)
  2567. {
  2568. if (buttons[i] == sender)
  2569. {
  2570. try
  2571. {
  2572. ProcessStartInfo psi = new ProcessStartInfo(pageData.menuList[i].Path);
  2573. Process pro = new Process
  2574. {
  2575. StartInfo = psi
  2576. };
  2577. pro.Start();
  2578. }
  2579. catch (Exception ex)
  2580. {
  2581. LogHelper.WriteErrLog("FileDirectoryWindow【BtnPlay_Click】" + ex.Message, ex);
  2582. System.Windows.MessageBox.Show(ex.Message);
  2583. return;
  2584. }
  2585. }
  2586. }
  2587. }
  2588. /// <summary>
  2589. /// 搜索集合匹配的索引
  2590. /// </summary>
  2591. /// <typeparam name="T"></typeparam>
  2592. /// <param name="parent"></param>
  2593. /// <param name="childName"></param>
  2594. /// <returns></returns>
  2595. public static List<T> FindChilds<T>(DependencyObject parent, string childName)
  2596. where T : DependencyObject
  2597. {
  2598. List<T> list = new List<T>();
  2599. if (parent == null)
  2600. {
  2601. return list;
  2602. }
  2603. int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
  2604. for (int i = 0; i < childrenCount; i++)
  2605. {
  2606. DependencyObject child = VisualTreeHelper.GetChild(parent, i);
  2607. // 如果子控件不是需查找的控件类型
  2608. T childType = child as T;
  2609. if (childType == null)
  2610. {
  2611. // 在下一级控件中递归查找
  2612. List<T> findChildList = FindChilds<T>(child, childName);
  2613. for (int j = 0; j < findChildList.Count; j++)
  2614. {
  2615. }
  2616. list.AddRange(FindChilds<T>(child, childName));
  2617. }
  2618. else if (!string.IsNullOrEmpty(childName))
  2619. {
  2620. FrameworkElement frameworkElement = child as FrameworkElement;
  2621. // 如果控件名称符合参数条件
  2622. if (frameworkElement != null && frameworkElement.Name == childName)
  2623. {
  2624. list.Add((T)child);
  2625. }
  2626. }
  2627. else
  2628. {
  2629. // 查找到了控件
  2630. list.Add((T)child);
  2631. }
  2632. }
  2633. return list;
  2634. }
  2635. /// <summary>
  2636. /// 修改
  2637. /// </summary>
  2638. /// <param name="sender"></param>
  2639. /// <param name="e"></param>
  2640. private void BtnModify_Click(object sender, RoutedEventArgs e)
  2641. {
  2642. if (IsModify)
  2643. {
  2644. try
  2645. {
  2646. string newName = pageData.menuList[Subscript].VideoName + "." + pageData.menuList[Subscript].VideoType;
  2647. bool isName = ModifyPathName(pageData.menuList[Subscript].FileGuid, newName, out string Errmessage);
  2648. if (!isName)
  2649. {
  2650. MessageWindow.Show(Errmessage);
  2651. }
  2652. }
  2653. catch (Exception ex)
  2654. {
  2655. LogHelper.WriteErrLog("XHMicroLessonSystemWindow(BtnModify_Click)" + ex.Message, ex);
  2656. }
  2657. IsModify = false;
  2658. pageData.menuList[Subscript].IsEnabled = false;
  2659. listView1.DataContext = pageData;
  2660. }
  2661. else
  2662. {
  2663. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnModify");
  2664. for (int i = 0; i < buttons.Count; i++)
  2665. {
  2666. if (buttons[i] == sender)
  2667. {
  2668. pageData.menuList[i].IsEnabled = true;
  2669. Subscript = i;
  2670. IsModify = true;
  2671. }
  2672. }
  2673. }
  2674. }
  2675. //private int MouseNumber = 0;
  2676. /// <summary>
  2677. /// 上传 上页
  2678. /// </summary>
  2679. /// <param name="sender"></param>
  2680. /// <param name="e"></param>
  2681. private void BtnLastPage_Click(object sender, RoutedEventArgs e)
  2682. {
  2683. if (Currpage > 1)
  2684. {
  2685. Currpage -= 1;
  2686. txbCurrpageTwo.Text = Currpage.ToString();
  2687. int i = 1;
  2688. bool isColour = true;
  2689. pageData.menuList.Clear();
  2690. //显示视频
  2691. foreach (Model_Video videoinfo in model_VideoList)
  2692. {
  2693. //是否已上传
  2694. //videoinfo.IsUpload;
  2695. //录制时间
  2696. //videoinfo.RSTime;
  2697. //文件大小
  2698. //videoinfo.VideoSize;
  2699. //文件缩略图路径
  2700. //videoinfo.ThumbnailPath;
  2701. //文件唯一标示 上传事件筛选需要上传的视频
  2702. //videoinfo.FileGuid;
  2703. //文件存储路径
  2704. //videoinfo.VidePath;
  2705. string colour = "#FFFFFF";
  2706. if (isColour == true)
  2707. {
  2708. colour = "#FFFFFF";
  2709. isColour = false;
  2710. }
  2711. else
  2712. {
  2713. colour = "#E6F1FF";
  2714. isColour = true;
  2715. }
  2716. string vis = "Visible";
  2717. string cos = "Collapsed";
  2718. if (!videoinfo.IsUpload)
  2719. {
  2720. vis = "Collapsed";
  2721. cos = "Visible";
  2722. }
  2723. if (i <= Currpage * 16 && i >= (Currpage - 1) * 16)
  2724. {
  2725. pageData.menuList.Add(new FileDirectoryModel()
  2726. {
  2727. SerialNumber = i,
  2728. VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2729. Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2730. FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
  2731. VideoDuration = 0,
  2732. VideoSize = videoinfo.VideoSize,
  2733. VideoTime = videoinfo.RSTime,
  2734. IsEnabled = false,
  2735. Path = videoinfo.VideoPath,
  2736. Colour = colour,
  2737. Visi = vis,
  2738. Coll = cos,
  2739. FileGuid = videoinfo.FileGuid,
  2740. VideoType = videoinfo.VideoType.ToString()
  2741. }); ;
  2742. }
  2743. i++;
  2744. }
  2745. APP.myloading.Hide();
  2746. }
  2747. }
  2748. /// <summary>
  2749. /// 上传 下页
  2750. /// </summary>
  2751. /// <param name="sender"></param>
  2752. /// <param name="e"></param>
  2753. private void BtnNextPage_Click(object sender, RoutedEventArgs e)
  2754. {
  2755. if (Currpage < PageNum)
  2756. {
  2757. Currpage += 1;
  2758. txbCurrpageTwo.Text = Currpage.ToString();
  2759. int i = 1;
  2760. bool isColour = true;
  2761. pageData.menuList.Clear();
  2762. //显示视频
  2763. foreach (Model_Video videoinfo in model_VideoList)
  2764. {
  2765. //是否已上传
  2766. //videoinfo.IsUpload;
  2767. //录制时间
  2768. //videoinfo.RSTime;
  2769. //文件大小
  2770. //videoinfo.VideoSize;
  2771. //文件缩略图路径
  2772. //videoinfo.ThumbnailPath;
  2773. //文件唯一标示 上传事件筛选需要上传的视频
  2774. //videoinfo.FileGuid;
  2775. //文件存储路径
  2776. //videoinfo.VidePath;
  2777. string colour = "#FFFFFF";
  2778. if (isColour == true)
  2779. {
  2780. colour = "#FFFFFF";
  2781. isColour = false;
  2782. }
  2783. else
  2784. {
  2785. colour = "#E6F1FF";
  2786. isColour = true;
  2787. }
  2788. string vis = "Visible";
  2789. string cos = "Collapsed";
  2790. if (!videoinfo.IsUpload)
  2791. {
  2792. vis = "Collapsed";
  2793. cos = "Visible";
  2794. }
  2795. if (i <= Currpage * 16 && i > (Currpage - 1) * 16)
  2796. {
  2797. pageData.menuList.Add(new FileDirectoryModel()
  2798. {
  2799. SerialNumber = i,
  2800. VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2801. Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2802. FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
  2803. VideoDuration = 0,
  2804. VideoSize = videoinfo.VideoSize,
  2805. VideoTime = videoinfo.RSTime,
  2806. IsEnabled = false,
  2807. Path = videoinfo.VideoPath,
  2808. Colour = colour,
  2809. Visi = vis,
  2810. Coll = cos,
  2811. FileGuid = videoinfo.FileGuid,
  2812. VideoType = videoinfo.VideoType.ToString()
  2813. }); ;
  2814. }
  2815. i++;
  2816. }
  2817. APP.myloading.Hide();
  2818. }
  2819. }
  2820. /// <summary>
  2821. /// 修改文件名
  2822. /// </summary>
  2823. /// <param name="Guid">唯一编号</param>
  2824. /// <param name="NewName">新文件名带后缀 不带路径</param>
  2825. /// <param name="Errmessage">错误信息</param>
  2826. /// <returns></returns>
  2827. private bool ModifyPathName(string FileGuid, string NewName, out string Errmessage)
  2828. {
  2829. Errmessage = "";
  2830. foreach (Model_WKData WKData in APP.WKDataList)
  2831. {
  2832. if (WKData.VideoList.Exists(x => x.FileGuid == FileGuid))
  2833. {
  2834. Model_Video model_Video = WKData.VideoList.Find(x => x.FileGuid == FileGuid);
  2835. string filePathName = model_Video.VideoPath;
  2836. string filePath = FileToolsCommon.GetDirectoryName(filePathName);
  2837. string newFilePathName = filePath + NewName;
  2838. //缩略图
  2839. string ThumbnailPath = filePath + "ThumbnailPath/";
  2840. FileToolsCommon.CreateDirectory(ThumbnailPath);
  2841. //缩略图存储位置
  2842. string ThumbnailPathName = ThumbnailPath + NewName.Replace(".", "") + ".JPG";
  2843. if (FileToolsCommon.IsExistFile(newFilePathName))
  2844. {
  2845. Errmessage = "文件已存在,请重新修改文件名!";
  2846. return false;
  2847. }
  2848. else
  2849. {
  2850. //修改文件名
  2851. FileToolsCommon.Copy(filePathName, newFilePathName);
  2852. model_Video.VideoPath = newFilePathName;
  2853. //修改缩略图名
  2854. FileToolsCommon.DeleteFile(ThumbnailPathName);
  2855. FileToolsCommon.Copy(model_Video.ThumbnailPath, ThumbnailPathName);
  2856. model_Video.ThumbnailPath = ThumbnailPathName;
  2857. APP.SaveWkData();
  2858. return true;
  2859. }
  2860. }
  2861. else
  2862. {
  2863. continue;
  2864. }
  2865. }
  2866. Errmessage = "视频文件有改动,当前文件不存在,请关闭后重新打开“我的”";
  2867. return false;
  2868. }
  2869. #endregion
  2870. #region 新上传 显示缩略图
  2871. #region 初始值
  2872. /// <summary>
  2873. /// 总页数
  2874. /// </summary>
  2875. private int TotalPage = 0;
  2876. /// <summary>
  2877. /// 当前页
  2878. /// </summary>
  2879. private int CurrentPage = 1;
  2880. /// <summary>
  2881. /// 每页显示的视频数
  2882. /// </summary>
  2883. private int PageShowNum = 0;
  2884. /// <summary>
  2885. /// 视频信息列表
  2886. /// </summary>
  2887. private List<Uc_VideoItem> VideoControlList = new List<Uc_VideoItem>();
  2888. /// <summary>
  2889. /// 横向间隔
  2890. /// </summary>
  2891. private double IntervalX = 0;
  2892. /// <summary>
  2893. /// 纵向间隔
  2894. /// </summary>
  2895. private double IntervalY = 0;
  2896. #endregion
  2897. /// <summary>
  2898. /// 初始化加载上传页面数据
  2899. /// </summary>
  2900. private void LoadUploadInitData()
  2901. {
  2902. APP.myloading.Show();
  2903. //加载视频列表
  2904. LoadingVideoList();
  2905. if (model_VideoList.Count > 0)
  2906. {
  2907. lblVideoMess.Visibility = Visibility.Hidden;
  2908. BtnVideoUpPage.Visibility = Visibility.Visible;
  2909. lblVideoPageNum.Visibility = Visibility.Visible;
  2910. BtnVideoDownPage.Visibility = Visibility.Visible;
  2911. //根据页面大小获取每页显示的数量 H300W250
  2912. int videoRow = (int)((GridMyVideo.ActualHeight - 50) / 300);
  2913. int videColumn = (int)(GridMyVideo.ActualWidth / 250);
  2914. PageShowNum = (videoRow == 0 ? 1 : videoRow) * (videColumn == 0 ? 1 : videColumn);
  2915. //获取总页数
  2916. TotalPage = model_VideoList.Count / PageShowNum + (model_VideoList.Count % PageShowNum > 0 ? 1 : 0);
  2917. //如果当前页大于总页数 总页数为当前页
  2918. if (TotalPage < CurrentPage)
  2919. {
  2920. CurrentPage = TotalPage;
  2921. }
  2922. //横向间隔
  2923. IntervalX = (GridMyVideo.ActualWidth - (videColumn * 250)) / (videColumn + 1);
  2924. IntervalY = (GridMyVideo.ActualHeight - 50 - (videoRow * 300)) / (videoRow + 1);
  2925. LoadCurrentPageData();
  2926. }
  2927. else
  2928. {
  2929. lblVideoMess.Visibility = Visibility.Visible;
  2930. BtnVideoUpPage.Visibility = Visibility.Hidden;
  2931. lblVideoPageNum.Visibility = Visibility.Hidden;
  2932. BtnVideoDownPage.Visibility = Visibility.Hidden;
  2933. //隐藏显示的控件
  2934. if (VideoControlList.Count > 0)
  2935. {
  2936. foreach (Uc_VideoItem item in VideoControlList)
  2937. {
  2938. if (item.Visibility != Visibility.Hidden)
  2939. {
  2940. item.Visibility = Visibility.Hidden;
  2941. }
  2942. }
  2943. }
  2944. }
  2945. APP.myloading.Hide();
  2946. }
  2947. /// <summary>
  2948. /// 加载当前页数据
  2949. /// </summary>
  2950. private void LoadCurrentPageData()
  2951. {
  2952. lblVideoPageNum.Content = CurrentPage + "/" + TotalPage;
  2953. //隐藏显示的控件
  2954. if (VideoControlList.Count > 0)
  2955. {
  2956. foreach (Uc_VideoItem item in VideoControlList)
  2957. {
  2958. if (item.Visibility != Visibility.Hidden)
  2959. {
  2960. item.Visibility = Visibility.Hidden;
  2961. }
  2962. }
  2963. }
  2964. double W = IntervalX;//每次增加250
  2965. double H = IntervalY;//每次增加300
  2966. //加载控件
  2967. for (int i = 0; i < PageShowNum; i++)
  2968. {
  2969. int DataIndex = (CurrentPage - 1) * PageShowNum + i;
  2970. if (DataIndex == model_VideoList.Count)
  2971. {
  2972. return;
  2973. }
  2974. Uc_VideoItem videoItem;
  2975. if (VideoControlList.Exists(x => x.Tag.ToString() == model_VideoList[DataIndex].FileGuid))
  2976. {
  2977. videoItem = VideoControlList.Find(x => x.Tag.ToString() == model_VideoList[DataIndex].FileGuid);
  2978. }
  2979. else
  2980. {
  2981. if (!FileToolsCommon.IsExistFile(model_VideoList[DataIndex].ThumbnailPath))
  2982. {
  2983. continue;
  2984. }
  2985. videoItem = new Uc_VideoItem(model_VideoList[DataIndex])
  2986. {
  2987. Tag = model_VideoList[DataIndex].FileGuid
  2988. };
  2989. videoItem.Click_refreshVideoList += LoadUploadInitData;
  2990. videoItem.Click_UploadLogin += Login;
  2991. videoItem.Width = 250;
  2992. videoItem.Height = 300;
  2993. videoItem.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
  2994. videoItem.VerticalAlignment = System.Windows.VerticalAlignment.Top;
  2995. GridMyVideo.Children.Add(videoItem);
  2996. VideoControlList.Add(videoItem);
  2997. }
  2998. videoItem.Margin = new Thickness(W, H, 0, 0);
  2999. videoItem.Visibility = Visibility.Visible;
  3000. if (W + 250 + 250 > GridMyVideo.ActualWidth)
  3001. {
  3002. W = IntervalX;
  3003. H += 300 + IntervalY;
  3004. }
  3005. else
  3006. {
  3007. W += 250 + IntervalX;
  3008. }
  3009. //Uc_VideoItem videoItem = new Uc_VideoItem();
  3010. //return;
  3011. }
  3012. }
  3013. #region 分页
  3014. /// <summary>
  3015. /// 上一页
  3016. /// </summary>
  3017. /// <param name="sender"></param>
  3018. /// <param name="e"></param>
  3019. private void BtnVideoUpPage_Click(object sender, RoutedEventArgs e)
  3020. {
  3021. if (CurrentPage > 1)
  3022. {
  3023. CurrentPage--;
  3024. LoadCurrentPageData();
  3025. }
  3026. }
  3027. /// <summary>
  3028. /// 下一页
  3029. /// </summary>
  3030. /// <param name="sender"></param>
  3031. /// <param name="e"></param>
  3032. private void BtnVideoDownPage_Click(object sender, RoutedEventArgs e)
  3033. {
  3034. if (CurrentPage < TotalPage)
  3035. {
  3036. CurrentPage++;
  3037. LoadCurrentPageData();
  3038. }
  3039. }
  3040. #endregion
  3041. #endregion
  3042. #region 录制窗口
  3043. #region 变量
  3044. /// <summary>
  3045. /// 视频保存路径
  3046. /// </summary>
  3047. //string RecordingPath;
  3048. /// <summary>
  3049. /// 图片保存路径
  3050. /// </summary>
  3051. private string ImgPath;
  3052. /// <summary>
  3053. /// 音频保存路径名
  3054. /// </summary>
  3055. private string AudioPathName;
  3056. /// <summary>
  3057. /// 视频保存路径名
  3058. /// </summary>
  3059. private string VideoSavePathName;
  3060. /// <summary>
  3061. /// 视频合成路径名
  3062. /// </summary>
  3063. private string VideoSynthesisPathName;
  3064. ///// <summary>
  3065. ///// 暂停录制
  3066. ///// </summary>
  3067. //private bool IsSuspendR = true;
  3068. /// <summary>
  3069. /// 录制是否已停止
  3070. /// </summary>
  3071. private bool IsFirstR = true;
  3072. /// <summary>
  3073. /// 图片
  3074. /// </summary>
  3075. private List<string> RsImgName = null;
  3076. /// <summary>
  3077. /// 是否开始截图计数
  3078. /// </summary>
  3079. private bool IsStartCount = false;
  3080. /// <summary>
  3081. /// 是否录制了音频
  3082. /// </summary>
  3083. private bool IsRecordAudio = false;
  3084. /// <summary>
  3085. /// 截图定时器
  3086. /// </summary>
  3087. private System.Threading.Timer timer;
  3088. /// <summary>
  3089. /// 录制计时
  3090. /// </summary>
  3091. private DateTime SRTime = DateTime.Now;
  3092. /// <summary>
  3093. /// 录制大小
  3094. /// </summary>
  3095. private int gridActWidth = 1276;
  3096. /// <summary>
  3097. /// 录制大小
  3098. /// </summary>
  3099. private int gridActHeight = 898;
  3100. /// <summary>
  3101. /// 录制类型 0停止中,1录制中,2暂停中
  3102. /// </summary>
  3103. int RecordType = 0;
  3104. #endregion
  3105. #region 录屏
  3106. /// <summary>
  3107. /// 录屏事件
  3108. /// </summary>
  3109. /// <param name="sender"></param>
  3110. /// <param name="e"></param>
  3111. private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
  3112. {
  3113. Record();
  3114. if (!APP.CheckScreenCapturerRecorder())
  3115. {
  3116. MessageWindow.Show("使用此功能需安装环境,请在确定后依次点击“OK-Next>-Next>Install”完成安装!");
  3117. APP.InstallScreenCapturerRecorder();
  3118. return;
  3119. }
  3120. #region 限制只允许录制一个录屏 废弃
  3121. //string RecordScreenPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  3122. //if (FileToolsCommon.IsExistFile(RecordScreenPathName))
  3123. //{
  3124. // MessageBoxResult dr = MessageWindow.Show("已存在录屏,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  3125. // if (dr == MessageBoxResult.OK)
  3126. // {
  3127. // try
  3128. // {
  3129. // FileToolsCommon.DeleteFile(RecordScreenPathName);
  3130. // APP.VideoList.RemoveAll(x => x.VideoPath == RecordScreenPathName);
  3131. // }
  3132. // catch (Exception ex)
  3133. // {
  3134. // LogHelper.WriteErrLog("【录屏】(BtnRecordingScreen_Click)无法移除视频," + ex.Message, ex);
  3135. // }
  3136. // }
  3137. // else
  3138. // {
  3139. // return;
  3140. // }
  3141. //}
  3142. #endregion
  3143. k_hook.Stop();
  3144. if (APP.W_ScreenRecordingToolbarWindow == null)
  3145. {
  3146. APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow
  3147. {
  3148. Topmost = true
  3149. };
  3150. APP.W_ScreenRecordingToolbarWindow.Initialize();
  3151. }
  3152. else
  3153. {
  3154. APP.W_ScreenRecordingToolbarWindow.Initialize();
  3155. }
  3156. APP.W_ScreenRecordingToolbarWindow.Click_stopRecordingScreen += W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen;
  3157. //显示在右下角
  3158. APP.W_ScreenRecordingToolbarWindow.WindowStartupLocation = WindowStartupLocation.Manual;
  3159. Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
  3160. float DIP = graphics.DpiX;
  3161. float DIPY = graphics.DpiY;
  3162. APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.WorkingArea.Width / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Width + 10;
  3163. APP.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.WorkingArea.Height / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Height - 30;
  3164. APP.W_ScreenRecordingToolbarWindow.Topmost = true;
  3165. APP.W_ScreenRecordingToolbarWindow.Show();
  3166. Hide();
  3167. }
  3168. /// <summary>
  3169. /// 保存录屏中
  3170. /// </summary>
  3171. private void W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen()
  3172. {
  3173. txbTime_Black.Text = "";
  3174. txbTime.Text = "";
  3175. txbTime.Visibility = Visibility.Hidden;
  3176. txbType.Visibility = Visibility.Visible;
  3177. txbType.Text = "保存中";
  3178. txbType_Black.Text = "保存中";
  3179. btnScreenRecording.IsEnabled = false;
  3180. btnScreenRecording_Black.IsEnabled = false;
  3181. new Thread(new ThreadStart(new Action(() =>
  3182. {
  3183. while (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath + "temprs/"))
  3184. {
  3185. Thread.Sleep(100);
  3186. }
  3187. Thread.Sleep(100);
  3188. Dispatcher.Invoke(() =>
  3189. {
  3190. btnScreenRecording.IsEnabled = true;
  3191. btnScreenRecording_Black.IsEnabled = true;
  3192. txbType.Visibility = Visibility.Hidden;
  3193. txbType_Black.Text = "";
  3194. //TxbRecordScreenWord.Text = "录屏";
  3195. });
  3196. }))).Start();
  3197. }
  3198. #endregion
  3199. private bool IsPressButton = false;
  3200. /// <summary>
  3201. /// 录制窗口内容
  3202. /// </summary>
  3203. /// <param name="sender"></param>
  3204. /// <param name="e"></param>
  3205. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  3206. {
  3207. #region 防止连击
  3208. if (IsPressButton)
  3209. {
  3210. return;
  3211. }
  3212. else
  3213. {
  3214. IsPressButton = true;
  3215. new Thread(new ThreadStart(new Action(() =>
  3216. {
  3217. Thread.Sleep(500);
  3218. IsPressButton = false;
  3219. }))).Start();
  3220. }
  3221. #endregion
  3222. Record();
  3223. if (!APP.CheckScreenCapturerRecorder())
  3224. {
  3225. MessageWindow.Show("使用此功能需安装环境,请在确定后依次点击“OK-Next>-Next>Install”完成安装!");
  3226. APP.InstallScreenCapturerRecorder();
  3227. return;
  3228. }
  3229. if (APP.pageData.currpage > 0)
  3230. {
  3231. blackboard_canvas.Visibility = Visibility.Visible;
  3232. }
  3233. else
  3234. {
  3235. MessageWindow.Show("请先导入文档或截图!");
  3236. return;
  3237. }
  3238. if (RectImgBorder.Visibility != Visibility.Hidden)
  3239. {
  3240. HideAngleBorder();
  3241. }
  3242. //btnStop.IsEnabled = true;//停止录制按钮可点击
  3243. if (RecordType == 0)
  3244. {
  3245. //停止中开始录制
  3246. RecordType = 1;
  3247. #region 检测麦克风扬声器是否可用
  3248. string AudioPath = FileToolsCommon.GetFileAbsolutePath("/temp/audio/");
  3249. FileToolsCommon.CreateDirectory(AudioPath);
  3250. string audioSpeakerPath = AudioPath + "adoS" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".m";
  3251. string audioMicrophonePath = AudioPath + "adoM" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".m";
  3252. try
  3253. {
  3254. FileToolsCommon.DeleteFile(audioSpeakerPath);
  3255. FileToolsCommon.DeleteFile(audioMicrophonePath);
  3256. }
  3257. catch (Exception)
  3258. {
  3259. }
  3260. //扬声器
  3261. if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
  3262. {
  3263. APP.FFmpeg.StopRecordAudio(2);
  3264. //Thread.Sleep(500);
  3265. //麦克风
  3266. if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
  3267. {
  3268. }
  3269. else
  3270. {
  3271. //无法录制麦克风
  3272. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制麦克风,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  3273. if (Res == MessageBoxResult.Cancel)
  3274. {
  3275. return;
  3276. }
  3277. }
  3278. APP.FFmpeg.StopRecordAudio(1);
  3279. }
  3280. else
  3281. {
  3282. //无法录制扬声器音频
  3283. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制音频,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  3284. if (Res == MessageBoxResult.Cancel)
  3285. {
  3286. return;
  3287. }
  3288. }
  3289. #endregion
  3290. }
  3291. else if (RecordType == 1)
  3292. {
  3293. //录制中暂停
  3294. RecordType = 2;
  3295. }
  3296. else if (RecordType == 2)
  3297. {
  3298. //暂停中继续录制
  3299. RecordType = 1;
  3300. }
  3301. new Thread(new ThreadStart(new Action(() =>
  3302. {
  3303. StartRecord(RecordType);
  3304. }))).Start();
  3305. }
  3306. /// <summary>
  3307. /// 停止录制窗口内容
  3308. /// </summary>
  3309. /// <param name="sender"></param>
  3310. /// <param name="e"></param>
  3311. private void BtnStop_Click(object sender, RoutedEventArgs e)
  3312. {
  3313. #region 防止连击
  3314. if (IsPressButton)
  3315. {
  3316. return;
  3317. }
  3318. else
  3319. {
  3320. IsPressButton = true;
  3321. new Thread(new ThreadStart(new Action(() =>
  3322. {
  3323. Thread.Sleep(500);
  3324. IsPressButton = false;
  3325. }))).Start();
  3326. }
  3327. #endregion
  3328. if (RecordType != 0)
  3329. {
  3330. RecordType = 0;
  3331. blackboard_canvas.Visibility = Visibility.Collapsed;
  3332. new Thread(new ThreadStart(new Action(() =>
  3333. {
  3334. EndRecord();
  3335. }))).Start();
  3336. //鼠标模式
  3337. deviceMouse();
  3338. }
  3339. }
  3340. /// <summary>
  3341. /// 设置录屏文件地址
  3342. /// </summary>
  3343. private void SetUpVideoPathName()
  3344. {
  3345. }
  3346. /// <summary>
  3347. /// 开始录制和暂停录制
  3348. /// </summary>
  3349. private void StartRecord(int Type)
  3350. {
  3351. if (Type == 1)
  3352. {
  3353. if (IsFirstR)//是否第一次录制 初始化录制
  3354. {
  3355. //电子版切换笔模式
  3356. deviceHand();
  3357. VideoInfo = new Model_Video
  3358. {
  3359. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  3360. WkType = Enum_WKVidetype.RecordingLessons
  3361. };
  3362. ImgPath = APP.WKData.WkPath + "temp/Image/";
  3363. AudioPathName = APP.WKData.WkPath + "temp/audio/";
  3364. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  3365. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  3366. FileToolsCommon.CreateDirectory(ImgPath);
  3367. FileToolsCommon.CreateDirectory(AudioPathName);
  3368. AudioPathName += APP.WKData.WkName + ".MP3";
  3369. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  3370. VideoSynthesisPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn." + VideoInfo.VideoType.ToString();
  3371. int num = 1;
  3372. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  3373. {
  3374. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制_" + num + "." + VideoInfo.VideoType.ToString();
  3375. VideoSynthesisPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn_" + num + "." + VideoInfo.VideoType.ToString();
  3376. num++;
  3377. }
  3378. #region 禁用按钮
  3379. Dispatcher.Invoke(() =>
  3380. {
  3381. txbTime.Visibility = Visibility.Visible;
  3382. ImgPrint.Visibility = Visibility.Collapsed;//录制中不可打印
  3383. ImgPrintTwo.Visibility = Visibility.Visible;
  3384. btnPrint.IsEnabled = false;
  3385. btnPrint_Black.IsEnabled = false;
  3386. ImgScreenshot.Visibility = Visibility.Collapsed;//录制中不可截图
  3387. ImgScreenshotTwo.Visibility = Visibility.Visible;
  3388. btnScreenshot.IsEnabled = false;
  3389. btnScreenshot_Black.IsEnabled = false;
  3390. ImgImport.Visibility = Visibility.Collapsed;//录制中不可导入文档
  3391. ImgImportTwo.Visibility = Visibility.Visible;
  3392. btnImport.IsEnabled = false;
  3393. btnImport_Black.IsEnabled = false;
  3394. ImgScreenRecording.Visibility = Visibility.Collapsed;//录制中不可录屏
  3395. ImgScreenRecordingTwo.Visibility = Visibility.Visible;
  3396. btnScreenRecording.IsEnabled = false;
  3397. btnScreenRecording_Black.IsEnabled = false;
  3398. ImgUpload.Visibility = Visibility.Collapsed;//录制中不可上传
  3399. ImgUploadTwo.Visibility = Visibility.Visible;
  3400. btnUpload.IsEnabled = false;
  3401. btnUpload_Black.IsEnabled = false;
  3402. ImgSetUp.Visibility = Visibility.Collapsed;//录制中不可设置
  3403. ImgSetUpTwo.Visibility = Visibility.Visible;
  3404. btnSetUp.IsEnabled = false;
  3405. btnSetUp_Black.IsEnabled = false;
  3406. btnDevice_Black.IsEnabled = false;
  3407. btnLoginType.IsEnabled = false;
  3408. btnLoginType_Black.IsEnabled = false;
  3409. blackboard_canvas.Visibility = Visibility.Visible;//zxyceshi
  3410. });
  3411. #endregion
  3412. #region 设置录制大小
  3413. gridActWidth = (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f));
  3414. gridActHeight = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f));
  3415. gridActWidth = gridActWidth % 2 > 0 ? gridActWidth - 1 : gridActWidth;
  3416. gridActHeight = gridActHeight % 2 > 0 ? gridActHeight - 1 : gridActHeight;
  3417. #endregion
  3418. #region 录像倒计时
  3419. Dispatcher.Invoke(() =>
  3420. {
  3421. if (APP.W_CountdownWindow == null)
  3422. {
  3423. APP.W_CountdownWindow = new CountdownWindow();
  3424. APP.W_CountdownWindow.Initialize();
  3425. //APP.W_CountdownWindow.Topmost = true;
  3426. }
  3427. else
  3428. {
  3429. APP.W_CountdownWindow.Initialize();
  3430. //APP.W_CountdownWindow.Topmost = true;
  3431. }
  3432. APP.W_CountdownWindow.Show();
  3433. });
  3434. #endregion
  3435. IsFirstR = false;
  3436. RsImgName = new List<string>();
  3437. SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
  3438. ///启动截图
  3439. timer = new System.Threading.Timer(new TimerCallback(Timer_Elapsed), null, 0, 20);
  3440. }
  3441. //继续录制
  3442. //IsSuspendR = false;
  3443. //BtnRecording.Content = "暂停录制";
  3444. Dispatcher.Invoke(() =>
  3445. {
  3446. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
  3447. TxbRecordingWord.Text = "暂停";
  3448. txbType_Black.Text = "准备录制";
  3449. BtnRecord_Black.Visibility = Visibility.Collapsed;
  3450. BtnRecordSuspend_Black.Visibility = Visibility.Visible;
  3451. BtnRecord.IsEnabled = true;
  3452. BtnRecord_Black.IsEnabled = true;
  3453. btnStop.IsEnabled = true;
  3454. btnStop_Black.IsEnabled = true;
  3455. ImgStop.Visibility = Visibility.Collapsed;
  3456. ImgStopTwo.Visibility = Visibility.Visible;
  3457. });
  3458. try
  3459. {
  3460. Thread.Sleep(1000);
  3461. IsRecordAudio = APP.FFmpeg.StartRecordingAudio(AudioPathName, out string ErrMessage);
  3462. Thread.Sleep(1000);
  3463. Dispatcher.Invoke(() =>
  3464. {
  3465. txbType_Black.Text = "正在录制";
  3466. if (!IsRecordAudio)
  3467. {
  3468. MessageWindow.Show(ErrMessage);
  3469. }
  3470. Recorddt = DateTime.Now;
  3471. IsStartCount = true;
  3472. //Stack();
  3473. //timer.Start();
  3474. });
  3475. }
  3476. catch (Exception ex)
  3477. {
  3478. MessageWindow.Show(ex.Message);
  3479. }
  3480. }
  3481. else if (Type == 2)
  3482. {
  3483. //暂停
  3484. //IsSuspendR = true;
  3485. Dispatcher.Invoke(() =>
  3486. {
  3487. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  3488. ImgStop.Visibility = Visibility.Collapsed;
  3489. ImgStopTwo.Visibility = Visibility.Visible;
  3490. TxbRecordingWord.Text = "继续";
  3491. txbType_Black.Text = "暂停中";
  3492. BtnRecord_Black.Visibility = Visibility.Visible;
  3493. BtnRecordSuspend_Black.Visibility = Visibility.Collapsed;
  3494. });
  3495. //TimeOut();
  3496. #region 2秒内不可点击
  3497. //new Thread(new ThreadStart(new Action(() =>
  3498. //{
  3499. Dispatcher.Invoke(() =>
  3500. {
  3501. BtnRecord.IsEnabled = false;
  3502. BtnRecord_Black.IsEnabled = false;
  3503. btnStop.IsEnabled = false;
  3504. btnStop_Black.IsEnabled = false;
  3505. });
  3506. Thread.Sleep(2000);
  3507. Dispatcher.Invoke(() =>
  3508. {
  3509. BtnRecord.IsEnabled = true;
  3510. BtnRecord_Black.IsEnabled = true;
  3511. btnStop.IsEnabled = true;
  3512. btnStop_Black.IsEnabled = true;
  3513. });
  3514. //}))).Start();
  3515. #endregion
  3516. try
  3517. {
  3518. APP.FFmpeg.SuspendFFmpeg();
  3519. //new Thread(new ThreadStart(new Action(() =>
  3520. //{
  3521. while (APP.FFmpeg.myProcess != null)
  3522. {
  3523. Thread.Sleep(100);
  3524. }
  3525. IsStartCount = false;
  3526. //}))).Start();
  3527. }
  3528. catch (Exception ex)
  3529. {
  3530. Dispatcher.Invoke(() =>
  3531. {
  3532. MessageWindow.Show(ex.Message);
  3533. });
  3534. }
  3535. }
  3536. }
  3537. /// <summary>
  3538. /// 开始录制和暂停录制
  3539. /// </summary>
  3540. private void StartRecordOld(int Type)
  3541. {
  3542. if (Type == 1)
  3543. {
  3544. if (IsFirstR)//是否第一次录制 初始化录制
  3545. {
  3546. #region 检测麦克风扬声器是否可用
  3547. string AudioPath = FileToolsCommon.GetFileAbsolutePath("/temp/audio/");
  3548. FileToolsCommon.CreateDirectory(AudioPath);
  3549. string audioSpeakerPath = AudioPath + "adoS" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".m";
  3550. string audioMicrophonePath = AudioPath + "adoM" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".m";
  3551. try
  3552. {
  3553. FileToolsCommon.DeleteFile(audioSpeakerPath);
  3554. FileToolsCommon.DeleteFile(audioMicrophonePath);
  3555. }
  3556. catch (Exception)
  3557. {
  3558. }
  3559. //扬声器
  3560. if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
  3561. {
  3562. APP.FFmpeg.StopRecordAudio(2);
  3563. //Thread.Sleep(500);
  3564. //麦克风
  3565. if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
  3566. {
  3567. }
  3568. else
  3569. {
  3570. //无法录制麦克风
  3571. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制麦克风,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  3572. if (Res == MessageBoxResult.Cancel)
  3573. {
  3574. return;
  3575. }
  3576. }
  3577. APP.FFmpeg.StopRecordAudio(1);
  3578. }
  3579. else
  3580. {
  3581. //无法录制扬声器音频
  3582. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制音频,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  3583. if (Res == MessageBoxResult.Cancel)
  3584. {
  3585. return;
  3586. }
  3587. }
  3588. #endregion
  3589. //电子版切换笔模式
  3590. deviceHand();
  3591. txbTime.Visibility = Visibility.Visible;
  3592. VideoInfo = new Model_Video
  3593. {
  3594. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  3595. WkType = Enum_WKVidetype.RecordingLessons
  3596. };
  3597. ImgPath = APP.WKData.WkPath + "temp/Image/";
  3598. AudioPathName = APP.WKData.WkPath + "temp/audio/";
  3599. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  3600. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  3601. FileToolsCommon.CreateDirectory(ImgPath);
  3602. FileToolsCommon.CreateDirectory(AudioPathName);
  3603. AudioPathName += APP.WKData.WkName + ".MP3";
  3604. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  3605. VideoSynthesisPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn." + VideoInfo.VideoType.ToString();
  3606. int num = 1;
  3607. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  3608. {
  3609. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制_" + num + "." + VideoInfo.VideoType.ToString();
  3610. VideoSynthesisPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn_" + num + "." + VideoInfo.VideoType.ToString();
  3611. num++;
  3612. }
  3613. #region 设置录屏唯一 废弃
  3614. //if (FileToolsCommon.IsExistFile(VideoSavePathName))
  3615. //{
  3616. // MessageBoxResult dr = MessageWindow.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  3617. // if (dr == MessageBoxResult.OK)
  3618. // {
  3619. // try
  3620. // {
  3621. // FileToolsCommon.DeleteFile(VideoSavePathName);
  3622. // APP.VideoList.RemoveAll(x => x.VideoPath == VideoSavePathName);
  3623. // }
  3624. // catch (Exception ex)
  3625. // {
  3626. // LogHelper.WriteErrLog("【录制】(StartRecord)无法移除视频," + ex.Message, ex);
  3627. // }
  3628. // }
  3629. // else
  3630. // {
  3631. // return;
  3632. // }
  3633. //}
  3634. #endregion
  3635. #region 禁用按钮
  3636. ImgPrint.Visibility = Visibility.Collapsed;//录制中不可打印
  3637. ImgPrintTwo.Visibility = Visibility.Visible;
  3638. btnPrint.IsEnabled = false;
  3639. btnPrint_Black.IsEnabled = false;
  3640. ImgScreenshot.Visibility = Visibility.Collapsed;//录制中不可截图
  3641. ImgScreenshotTwo.Visibility = Visibility.Visible;
  3642. btnScreenshot.IsEnabled = false;
  3643. btnScreenshot_Black.IsEnabled = false;
  3644. ImgImport.Visibility = Visibility.Collapsed;//录制中不可导入文档
  3645. ImgImportTwo.Visibility = Visibility.Visible;
  3646. btnImport.IsEnabled = false;
  3647. btnImport_Black.IsEnabled = false;
  3648. ImgScreenRecording.Visibility = Visibility.Collapsed;//录制中不可录屏
  3649. ImgScreenRecordingTwo.Visibility = Visibility.Visible;
  3650. btnScreenRecording.IsEnabled = false;
  3651. btnScreenRecording_Black.IsEnabled = false;
  3652. ImgUpload.Visibility = Visibility.Collapsed;//录制中不可上传
  3653. ImgUploadTwo.Visibility = Visibility.Visible;
  3654. btnUpload.IsEnabled = false;
  3655. btnUpload_Black.IsEnabled = false;
  3656. ImgSetUp.Visibility = Visibility.Collapsed;//录制中不可设置
  3657. ImgSetUpTwo.Visibility = Visibility.Visible;
  3658. btnSetUp.IsEnabled = false;
  3659. btnSetUp_Black.IsEnabled = false;
  3660. btnDevice_Black.IsEnabled = false;
  3661. btnLoginType.IsEnabled = false;
  3662. btnLoginType_Black.IsEnabled = false;
  3663. blackboard_canvas.Visibility = Visibility.Visible;//zxyceshi
  3664. //myblackboard = new BlackboardNew(blackboard_canvas);
  3665. //DataContext = APP.pageData;
  3666. //drawingAttributes = new DrawingAttributes();
  3667. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  3668. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  3669. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  3670. //blackboard_canvas.UseCustomCursor = true;
  3671. //drawingAttributes.FitToCurve = true;
  3672. //drawingAttributes.IgnorePressure = false;
  3673. //drawingAttributes.Width = PenSize;
  3674. //drawingAttributes.Height = PenSize;
  3675. //drawingAttributes.Color = Color;
  3676. //blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  3677. #endregion
  3678. #region 设置录制大小
  3679. //gridActWidth = (int)GridMain.ActualWidth==0?1276: (int)GridMain.ActualWidth;
  3680. //gridActHeight = (int)GridMain.ActualHeight==0?898: (int)GridMain.ActualHeight;
  3681. gridActWidth = (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f));
  3682. gridActHeight = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f));
  3683. gridActWidth = gridActWidth % 2 > 0 ? gridActWidth - 1 : gridActWidth;
  3684. gridActHeight = gridActHeight % 2 > 0 ? gridActHeight - 1 : gridActHeight;
  3685. #endregion
  3686. #region 录像倒计时
  3687. if (APP.W_CountdownWindow == null)
  3688. {
  3689. APP.W_CountdownWindow = new CountdownWindow();
  3690. APP.W_CountdownWindow.Initialize();
  3691. //APP.W_CountdownWindow.Topmost = true;
  3692. }
  3693. else
  3694. {
  3695. APP.W_CountdownWindow.Initialize();
  3696. //APP.W_CountdownWindow.Topmost = true;
  3697. }
  3698. APP.W_CountdownWindow.Show();
  3699. #endregion
  3700. IsFirstR = false;
  3701. RsImgName = new List<string>();
  3702. SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
  3703. txbTime.Visibility = Visibility.Visible;
  3704. ///启动截图
  3705. timer = new System.Threading.Timer(new TimerCallback(Timer_Elapsed), null, 0, 20);
  3706. //{
  3707. // AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
  3708. //};//设置执行一次(false)还是一直执行(true)
  3709. //timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
  3710. //timer.Enabled = true; //启动计时器
  3711. }
  3712. //继续录制
  3713. //IsSuspendR = false;
  3714. //BtnRecording.Content = "暂停录制";
  3715. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
  3716. TxbRecordingWord.Text = "暂停";
  3717. txbType_Black.Text = "准备录制";
  3718. BtnRecord_Black.Visibility = Visibility.Collapsed;
  3719. BtnRecordSuspend_Black.Visibility = Visibility.Visible;
  3720. #region 4秒内不可点击
  3721. //new Thread(new ThreadStart(new Action(() =>
  3722. //{
  3723. // Dispatcher.Invoke(() =>
  3724. // {
  3725. // BtnRecord.IsEnabled = false;
  3726. // btnStop.IsEnabled = false;
  3727. // ImgStop.Visibility = Visibility.Visible;
  3728. // ImgStopTwo.Visibility = Visibility.Collapsed;
  3729. // });
  3730. //}))).Start();
  3731. new Thread(new ThreadStart(new Action(() =>
  3732. {
  3733. //Thread.Sleep(4000);
  3734. Dispatcher.Invoke(() =>
  3735. {
  3736. BtnRecord.IsEnabled = true;
  3737. BtnRecord_Black.IsEnabled = true;
  3738. btnStop.IsEnabled = true;
  3739. btnStop_Black.IsEnabled = true;
  3740. ImgStop.Visibility = Visibility.Collapsed;
  3741. ImgStopTwo.Visibility = Visibility.Visible;
  3742. });
  3743. }))).Start();
  3744. #endregion
  3745. try
  3746. {
  3747. new Thread(new ThreadStart(new Action(() =>
  3748. {
  3749. Thread.Sleep(1000);
  3750. IsRecordAudio = APP.FFmpeg.StartRecordingAudio(AudioPathName, out string ErrMessage);
  3751. Thread.Sleep(1000);
  3752. Dispatcher.Invoke(() =>
  3753. {
  3754. txbType_Black.Text = "正在录制";
  3755. if (!IsRecordAudio)
  3756. {
  3757. MessageWindow.Show(ErrMessage);
  3758. }
  3759. Recorddt = DateTime.Now;
  3760. IsStartCount = true;
  3761. //Stack();
  3762. //timer.Start();
  3763. });
  3764. }))).Start();
  3765. }
  3766. catch (Exception ex)
  3767. {
  3768. MessageWindow.Show(ex.Message);
  3769. }
  3770. }
  3771. else if (Type == 2)
  3772. {
  3773. //暂停
  3774. //IsSuspendR = true;
  3775. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  3776. ImgStop.Visibility = Visibility.Collapsed;
  3777. ImgStopTwo.Visibility = Visibility.Visible;
  3778. TxbRecordingWord.Text = "继续";
  3779. txbType_Black.Text = "暂停中";
  3780. BtnRecord_Black.Visibility = Visibility.Visible;
  3781. BtnRecordSuspend_Black.Visibility = Visibility.Collapsed;
  3782. //TimeOut();
  3783. #region 2秒内不可点击
  3784. new Thread(new ThreadStart(new Action(() =>
  3785. {
  3786. Dispatcher.Invoke(() =>
  3787. {
  3788. BtnRecord.IsEnabled = false;
  3789. BtnRecord_Black.IsEnabled = false;
  3790. btnStop.IsEnabled = false;
  3791. btnStop_Black.IsEnabled = false;
  3792. });
  3793. Thread.Sleep(2000);
  3794. Dispatcher.Invoke(() =>
  3795. {
  3796. BtnRecord.IsEnabled = true;
  3797. BtnRecord_Black.IsEnabled = true;
  3798. btnStop.IsEnabled = true;
  3799. btnStop_Black.IsEnabled = true;
  3800. });
  3801. }))).Start();
  3802. #endregion
  3803. try
  3804. {
  3805. APP.FFmpeg.SuspendFFmpeg();
  3806. new Thread(new ThreadStart(new Action(() =>
  3807. {
  3808. while (APP.FFmpeg.myProcess != null)
  3809. {
  3810. Thread.Sleep(100);
  3811. }
  3812. IsStartCount = false;
  3813. }))).Start();
  3814. }
  3815. catch (Exception ex)
  3816. {
  3817. MessageWindow.Show(ex.Message);
  3818. }
  3819. }
  3820. }
  3821. /// <summary>
  3822. /// 记录上次截图时间
  3823. /// </summary>
  3824. private DateTime Recorddt = DateTime.Now;
  3825. /// <summary>
  3826. /// 录制保存图片计时器
  3827. /// </summary>
  3828. /// <param name="sender"></param>
  3829. private void Timer_Elapsed(object sender)
  3830. {
  3831. if (IsStartCount)
  3832. {
  3833. DateTime dt = DateTime.Now;
  3834. TimeSpan ts = dt.Subtract(Recorddt);//时间差
  3835. double tsmi = ts.TotalMilliseconds;
  3836. if (tsmi > 200.0)
  3837. {
  3838. Recorddt = Recorddt.AddMilliseconds(200);
  3839. Thread thread = new Thread(RecordSaveImage);
  3840. //开启线程
  3841. thread.Start();
  3842. }
  3843. }
  3844. }
  3845. /// <summary>
  3846. /// 录制保存图片
  3847. /// </summary>
  3848. private void RecordSaveImage()
  3849. {
  3850. try
  3851. {
  3852. if (IsStartCount)
  3853. {
  3854. string FilePathName = ImgPath + RsImgName.Count + ".png";
  3855. RsImgName.Add(FilePathName);
  3856. #region 设置大小
  3857. double RsW = (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f));
  3858. double RsH = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f));
  3859. if (RsW > 1266)
  3860. {
  3861. double Proportion = RsH / RsW;
  3862. RsW = 1266;
  3863. RsH = RsW * Proportion;
  3864. RsH = ((int)RsH) % 2 > 0 ? (int)RsH - 1 : (int)RsH;
  3865. //RsH = 898;
  3866. }
  3867. #endregion
  3868. //System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Send, new ThreadStart(delegate
  3869. //{
  3870. //}));
  3871. Dispatcher.Invoke(() =>
  3872. {
  3873. //保存图片
  3874. ImageHelper.SaveUI(GridMain, FilePathName, gridActWidth, gridActHeight, (int)RsW, (int)RsH);
  3875. //ImageHelper.SaveUIToImage(GridMain, FilePathName, gridActWidth, gridActHeight, (int)RsW, (int)RsH);
  3876. //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f)), 0, 0);
  3877. //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)), (int)RsW, (int)RsH);
  3878. //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)), 1281, 1026);
  3879. SRTime = SRTime.AddMilliseconds(200);
  3880. if (txbTime.Visibility == Visibility.Hidden)
  3881. {
  3882. txbTime.Visibility = Visibility.Visible;
  3883. }
  3884. if (SRTime.Hour > 0)
  3885. {
  3886. //Dispatcher.Invoke(() =>
  3887. //{
  3888. txbTime.Text = SRTime.ToString("HH:mm:ss");
  3889. txbTime_Black.Text = SRTime.ToString("HH:mm:ss");
  3890. //});
  3891. }
  3892. else
  3893. {
  3894. //Dispatcher.Invoke(() =>
  3895. //{
  3896. txbTime.Text = SRTime.ToString("mm:ss");
  3897. txbTime_Black.Text = SRTime.ToString("HH:mm:ss");
  3898. //});
  3899. }
  3900. });
  3901. }
  3902. }
  3903. catch (Exception ex)
  3904. {
  3905. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  3906. }
  3907. }
  3908. /// <summary>
  3909. /// 停止录制并生成录制文件
  3910. /// </summary>
  3911. private void EndRecord()
  3912. {
  3913. if (!IsFirstR)
  3914. {
  3915. #region 恢复被禁用的按钮
  3916. Dispatcher.Invoke(() =>
  3917. {
  3918. ImgPrint.Visibility = Visibility.Visible;
  3919. ImgPrintTwo.Visibility = Visibility.Collapsed;
  3920. btnPrint.IsEnabled = true;
  3921. btnPrint_Black.IsEnabled = true;
  3922. ImgScreenshot.Visibility = Visibility.Visible;
  3923. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  3924. btnScreenshot.IsEnabled = true;
  3925. btnScreenshot_Black.IsEnabled = true;
  3926. ImgImport.Visibility = Visibility.Visible;
  3927. ImgImportTwo.Visibility = Visibility.Collapsed;
  3928. btnImport.IsEnabled = true;
  3929. btnImport_Black.IsEnabled = true;
  3930. ImgScreenRecording.Visibility = Visibility.Visible;
  3931. ImgScreenRecordingTwo.Visibility = Visibility.Collapsed;
  3932. btnScreenRecording.IsEnabled = true;
  3933. btnScreenRecording_Black.IsEnabled = true;
  3934. ImgUpload.Visibility = Visibility.Visible;
  3935. ImgUploadTwo.Visibility = Visibility.Collapsed;
  3936. btnUpload.IsEnabled = true;
  3937. btnUpload_Black.IsEnabled = true;
  3938. ImgSetUp.Visibility = Visibility.Visible;
  3939. ImgSetUpTwo.Visibility = Visibility.Collapsed;
  3940. btnSetUp.IsEnabled = true;
  3941. btnSetUp_Black.IsEnabled = true;
  3942. btnDevice_Black.IsEnabled = true;
  3943. btnLoginType.IsEnabled = true;
  3944. btnLoginType_Black.IsEnabled = true;
  3945. //btnStop.IsEnabled = false;//停止录制按钮不可点击
  3946. });
  3947. #endregion
  3948. //IsSuspendR = true;
  3949. Dispatcher.Invoke(() =>
  3950. {
  3951. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  3952. ImgStop.Visibility = Visibility.Visible;
  3953. ImgStopTwo.Visibility = Visibility.Collapsed;
  3954. });
  3955. try
  3956. {
  3957. #region 清空画板数据
  3958. Dispatcher.Invoke(() =>
  3959. {
  3960. APP.pageData.currpage = 0;
  3961. APP.pageData.pagenum = 0;
  3962. myblackboard.clear();
  3963. APP.PageDrawList.Clear();
  3964. imgCanvas.Source = null;
  3965. imgDocumentation.Source = null;
  3966. imgPPT.Source = null;
  3967. gridPage.Visibility = Visibility.Collapsed;
  3968. });
  3969. #endregion
  3970. //根据录制时间长度确定是否保存
  3971. if (SRTime.Hour > 0 || SRTime.Minute > 0 || SRTime.Second > 3)
  3972. {
  3973. #region 2秒内不可点击
  3974. Dispatcher.Invoke(() =>
  3975. {
  3976. BtnRecord.IsEnabled = false;
  3977. BtnRecord_Black.IsEnabled = false;
  3978. btnStop.IsEnabled = false;
  3979. btnStop_Black.IsEnabled = false;
  3980. btnScreenRecording.IsEnabled = false;
  3981. btnScreenRecording_Black.IsEnabled = false;
  3982. });
  3983. #endregion
  3984. //缩略图
  3985. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  3986. FileToolsCommon.CreateDirectory(ThumbnailPath);
  3987. //缩略图存储位置
  3988. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
  3989. APP.FFmpeg.StopFFmpeg(AudioPathName);
  3990. IsStartCount = false;
  3991. //停止截图
  3992. while (APP.FFmpeg.myProcess != null)
  3993. {
  3994. Thread.Sleep(100);
  3995. }
  3996. Dispatcher.Invoke(() =>
  3997. {
  3998. timer.Change(-1, 0);
  3999. timer.Dispose();
  4000. //End();
  4001. txbTime_Black.Text = "";
  4002. txbTime.Text = "";
  4003. txbTime.Visibility = Visibility.Hidden;
  4004. txbType.Visibility = Visibility.Visible;
  4005. txbType.Text = "保存中";
  4006. txbType_Black.Text = "保存中";
  4007. });
  4008. //new Thread(new ThreadStart(new Action(() =>
  4009. //{
  4010. //判断音频是否存在 判断音频临时文件夹是否存在
  4011. if (IsRecordAudio)
  4012. {
  4013. if (!FileToolsCommon.IsExistFile(AudioPathName))
  4014. {
  4015. Thread.Sleep(100);
  4016. }
  4017. if (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(AudioPathName) + "temp/"))
  4018. {
  4019. Thread.Sleep(100);
  4020. }
  4021. }
  4022. else
  4023. {
  4024. //没有录制音频
  4025. AudioPathName = null;
  4026. }
  4027. //合成视频
  4028. bool SynRes = APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSynthesisPathName, 5, gridActWidth, gridActHeight, out string ErrMessage);
  4029. //}))).Start();
  4030. //new Thread(new ThreadStart(new Action(() =>
  4031. //{
  4032. if (!SynRes)
  4033. {
  4034. Dispatcher.Invoke(() =>
  4035. {
  4036. MessageWindow.Show("录制失败," + ErrMessage);
  4037. BtnRecord.IsEnabled = true;
  4038. BtnRecord_Black.IsEnabled = true;
  4039. btnStop.IsEnabled = false;
  4040. btnStop_Black.IsEnabled = false;
  4041. btnPrint.IsEnabled = false;
  4042. btnPrint_Black.IsEnabled = false;
  4043. btnScreenRecording.IsEnabled = true;
  4044. btnScreenRecording_Black.IsEnabled = true;
  4045. TxbRecordingWord.Text = "录制";
  4046. txbType.Text = "";
  4047. txbType_Black.Text = "";
  4048. BtnRecord_Black.Visibility = Visibility.Visible;
  4049. BtnRecordSuspend_Black.Visibility = Visibility.Collapsed;
  4050. });
  4051. return;
  4052. }
  4053. Dispatcher.Invoke(() =>
  4054. {
  4055. txbType.Text = "转码中";
  4056. txbType_Black.Text = "转码中";
  4057. });
  4058. while (!FileToolsCommon.IsExistFile(VideoSynthesisPathName))
  4059. {
  4060. Thread.Sleep(100);
  4061. }
  4062. while (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(VideoSynthesisPathName) + "temp/"))
  4063. {
  4064. Thread.Sleep(100);
  4065. }
  4066. FileToolsCommon.DeleteFile(ThumbnailPathName);
  4067. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  4068. Thread.Sleep(500);
  4069. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  4070. VideoInfo.VideoPath = VideoSavePathName;
  4071. VideoInfo.ThumbnailPath = ThumbnailPathName;
  4072. //生成缩略图
  4073. bool ThuRes = APP.FFmpeg.GenerateThumbnails(VideoSynthesisPathName, ThumbnailPathName, 200, 130);
  4074. Thread.Sleep(500);
  4075. APP.FFmpeg.VideoTranscode(VideoSynthesisPathName, VideoSavePathName, gridActWidth, gridActHeight);
  4076. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  4077. VideoInfo.IsUpload = false;
  4078. VideoInfo.Uploaded = 0;
  4079. //VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  4080. if (!APP.VideoList.Exists(x => x.FileGuid == VideoInfo.FileGuid) || !APP.VideoList.Exists(x => x.VideoPath == VideoInfo.VideoPath))
  4081. {
  4082. APP.VideoList.Add(VideoInfo);
  4083. //保存数据
  4084. APP.SaveWkData();
  4085. }
  4086. IsFirstR = true;
  4087. Dispatcher.Invoke(() =>
  4088. {
  4089. BtnRecord.IsEnabled = true;
  4090. BtnRecord_Black.IsEnabled = true;
  4091. btnStop.IsEnabled = false;
  4092. btnStop_Black.IsEnabled = false;
  4093. btnPrint.IsEnabled = false;
  4094. btnPrint_Black.IsEnabled = false;
  4095. btnScreenRecording.IsEnabled = true;
  4096. btnScreenRecording_Black.IsEnabled = true;
  4097. TxbRecordingWord.Text = "录制";
  4098. txbType.Text = "";
  4099. txbType_Black.Text = "";
  4100. BtnRecord_Black.Visibility = Visibility.Visible;
  4101. BtnRecordSuspend_Black.Visibility = Visibility.Collapsed;
  4102. });
  4103. }
  4104. else
  4105. {
  4106. APP.FFmpeg.SuspendFFmpeg();
  4107. IsStartCount = false;
  4108. timer.Change(-1, 0);
  4109. timer.Dispose();
  4110. IsFirstR = true;
  4111. IsStartCount = false;
  4112. //停止截图
  4113. while (APP.FFmpeg.myProcess != null)
  4114. {
  4115. Thread.Sleep(100);
  4116. }
  4117. Dispatcher.Invoke(() =>
  4118. {
  4119. BtnRecord.IsEnabled = true;
  4120. BtnRecord_Black.IsEnabled = true;
  4121. btnStop.IsEnabled = false;
  4122. btnStop_Black.IsEnabled = false;
  4123. btnPrint.IsEnabled = false;
  4124. btnPrint_Black.IsEnabled = false;
  4125. btnScreenRecording.IsEnabled = true;
  4126. btnScreenRecording_Black.IsEnabled = true;
  4127. MessageWindow.Show("录制时间过短,请重新录制!");
  4128. TxbRecordingWord.Text = "录制";
  4129. txbType.Text = "";
  4130. txbType_Black.Text = "";
  4131. BtnRecord_Black.Visibility = Visibility.Visible;
  4132. BtnRecordSuspend_Black.Visibility = Visibility.Collapsed;
  4133. txbTime_Black.Text = "";
  4134. txbTime.Text = "";
  4135. txbTime.Visibility = Visibility.Hidden;
  4136. });
  4137. }
  4138. //List<Model_Video> VideoList
  4139. }
  4140. catch (Exception ex)
  4141. {
  4142. Dispatcher.Invoke(() =>
  4143. {
  4144. MessageWindow.Show(ex.Message);
  4145. });
  4146. }
  4147. }
  4148. }
  4149. #endregion
  4150. #region 登录
  4151. /// <summary>
  4152. /// 登录事件
  4153. /// </summary>
  4154. /// <param name="sender"></param>
  4155. /// <param name="e"></param>
  4156. private void BtnLoginType_Click(object sender, RoutedEventArgs e)
  4157. {
  4158. if ("未登录".Equals(txbLoginType.Text) || ImgHeadImgN.Visibility == Visibility.Visible)
  4159. {
  4160. Login();
  4161. }
  4162. else
  4163. {
  4164. MessageBoxResult dr = MessageWindow.Show("确定退出登录?", "提示", MessageBoxButton.OKCancel);
  4165. if (dr == MessageBoxResult.OK)
  4166. {
  4167. LoginType();
  4168. Login();
  4169. }
  4170. }
  4171. }
  4172. /// <summary>
  4173. /// 登录
  4174. /// </summary>
  4175. private void Login()
  4176. {
  4177. if (APP.W_LoginWindow == null)
  4178. {
  4179. APP.W_LoginWindow = new LoginWindow
  4180. {
  4181. WindowStartupLocation = WindowStartupLocation.CenterOwner,
  4182. Owner = this
  4183. };
  4184. }
  4185. else
  4186. {
  4187. APP.W_LoginWindow.Initialize();
  4188. }
  4189. APP.W_LoginWindow.ShowDialog();
  4190. if (APP.IsLoginType)
  4191. {
  4192. txbLoginType.Text = APP.UserInfo.Username;
  4193. ImgHeadImgN.Visibility = Visibility.Collapsed;
  4194. ImgHeadImg.Visibility = Visibility.Visible;
  4195. //txbLoginType_Black.Text = APP.UserInfo.Username;
  4196. //APP.UserInfo.Userphone
  4197. //ImgUpload.Visibility = Visibility.Visible;
  4198. //ImgUploadTwo.Visibility = Visibility.Collapsed;
  4199. }
  4200. else
  4201. {
  4202. txbLoginType.Text = "未登录";
  4203. ImgHeadImgN.Visibility = Visibility.Visible;
  4204. ImgHeadImg.Visibility = Visibility.Collapsed;
  4205. //txbLoginType_Black.Text = "未登录";
  4206. //ImgUpload.Visibility = Visibility.Collapsed;
  4207. //ImgUploadTwo.Visibility = Visibility.Visible;
  4208. }
  4209. }
  4210. /// <summary>
  4211. /// 状态更改为未登录
  4212. /// </summary>
  4213. private void LoginType()
  4214. {
  4215. APP.IsLoginType = false;
  4216. txbLoginType.Text = "未登录";
  4217. ImgHeadImgN.Visibility = Visibility.Visible;
  4218. ImgHeadImg.Visibility = Visibility.Collapsed;
  4219. //txbLoginType_Black.Text = "未登录";
  4220. APP.UserInfo = new Model_UserInfo();
  4221. //ImgUpload.Visibility = Visibility.Collapsed;
  4222. //ImgUploadTwo.Visibility = Visibility.Visible;
  4223. }
  4224. #endregion
  4225. #region 分页
  4226. /// 上一页
  4227. /// </summary>
  4228. /// <param name="sender"></param>
  4229. /// <param name="e"></param>
  4230. private void last_button_Click(object sender, RoutedEventArgs e)
  4231. {
  4232. if (APP.pageData.currpage > 1)
  4233. {
  4234. mouseDown = false;
  4235. HideAngleBorder();
  4236. //隐藏跳转
  4237. //txbCurrpage.Visibility = Visibility.Visible;
  4238. //txtJump.Visibility = Visibility.Hidden;
  4239. //BtnJumpPage.Visibility = Visibility.Hidden;
  4240. //if(!APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  4241. //{
  4242. // ImgWG();
  4243. //}
  4244. APP.pageData.currpage -= 1;
  4245. JumpPageClick();
  4246. }
  4247. }
  4248. /// <summary>
  4249. /// 下一页
  4250. /// </summary>
  4251. /// <param name="sender"></param>
  4252. /// <param name="e"></param>
  4253. private void next_btn_Click(object sender, RoutedEventArgs e)
  4254. {
  4255. if (APP.pageData.currpage < APP.pageData.pagenum)
  4256. {
  4257. mouseDown = false;
  4258. HideAngleBorder();
  4259. //隐藏跳转
  4260. //txbCurrpage.Visibility = Visibility.Visible;
  4261. //txtJump.Visibility = Visibility.Hidden;
  4262. //BtnJumpPage.Visibility = Visibility.Hidden;
  4263. //if (!APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  4264. //{
  4265. // ImgWG();
  4266. //}
  4267. APP.pageData.currpage += 1;
  4268. JumpPageClick();
  4269. }
  4270. }
  4271. /// <summary>
  4272. /// 跳转
  4273. /// </summary>
  4274. void JumpPageClick()
  4275. {
  4276. myblackboard.changepage(APP.pageData.currpage - 1);
  4277. scroMain.ScrollToVerticalOffset(0);
  4278. if (btnImport.IsEnabled || btnImport_Black.IsEnabled)
  4279. {
  4280. ///截图可用
  4281. ImgScreenshot.Visibility = Visibility.Visible;
  4282. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  4283. btnScreenshot.IsEnabled = true;
  4284. btnScreenshot_Black.IsEnabled = true;
  4285. }
  4286. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  4287. {
  4288. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  4289. {
  4290. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  4291. }
  4292. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  4293. {
  4294. if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  4295. {
  4296. if ("ppt".Equals(APP.PageDrawList[APP.pageData.currpage - 1].Type))
  4297. {
  4298. imgCanvas.Source = null;
  4299. imgDocumentation.Source = null;
  4300. imgPPT.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  4301. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  4302. ImgScreenshotTwo.Visibility = Visibility.Visible;
  4303. btnScreenshot.IsEnabled = false;
  4304. btnScreenshot_Black.IsEnabled = false;
  4305. }
  4306. else
  4307. {
  4308. imgPPT.Source = null;
  4309. imgCanvas.Source = null;
  4310. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  4311. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  4312. ImgScreenshotTwo.Visibility = Visibility.Visible;
  4313. btnScreenshot.IsEnabled = false;
  4314. btnScreenshot_Black.IsEnabled = false;
  4315. }
  4316. //imgCanvas.Source = null;
  4317. //imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  4318. //ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  4319. //ImgScreenshotTwo.Visibility = Visibility.Visible;
  4320. //btnScreenshot.IsEnabled = false;
  4321. }
  4322. else
  4323. {
  4324. imgPPT.Source = null;
  4325. imgDocumentation.Source = null;
  4326. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  4327. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  4328. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  4329. {
  4330. //var group = IMG.FindResource("Imageview") as TransformGroup;
  4331. //#region 高低 缩放比例
  4332. //if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
  4333. //{
  4334. // var transform1 = group.Children[0] as ScaleTransform;
  4335. // transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
  4336. // transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
  4337. // imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
  4338. // imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
  4339. //}
  4340. //#endregion
  4341. //#region 坐标XY轴
  4342. //var transform = group.Children[1] as TranslateTransform;
  4343. //transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  4344. //transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  4345. //#endregion
  4346. mouseDown = false;
  4347. ImgXY();
  4348. }
  4349. }
  4350. }
  4351. else
  4352. {
  4353. imgPPT.Source = null;
  4354. imgCanvas.Source = null;
  4355. imgDocumentation.Source = null;
  4356. }
  4357. #region 修改跳转页码
  4358. CbxPageList.SelectedIndex = APP.pageData.currpage - 1;
  4359. #endregion
  4360. }
  4361. }
  4362. private void ImgXY()
  4363. {
  4364. imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
  4365. imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
  4366. imgCanvas.Margin = new Thickness(APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X, APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y, 0, 0);
  4367. //imgCanvas.Margin.Left= APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  4368. //transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  4369. }
  4370. private void ImgWG()
  4371. {
  4372. mouseDown = false;
  4373. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  4374. {
  4375. X = imgCanvas.Margin.Left,
  4376. Y = imgCanvas.Margin.Top
  4377. };
  4378. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  4379. {
  4380. CenterX = imgCanvas.ActualWidth,
  4381. CenterY = imgCanvas.ActualHeight
  4382. };
  4383. }
  4384. #endregion
  4385. #region 图像缩放,移动
  4386. private bool mouseDown;
  4387. private System.Windows.Point mouseXY;
  4388. private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  4389. {
  4390. ContentControl img = sender as ContentControl;
  4391. if (img == null)
  4392. {
  4393. return;
  4394. }
  4395. img.CaptureMouse();
  4396. mouseDown = true;
  4397. mouseXY = e.GetPosition(img);
  4398. //Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
  4399. }
  4400. private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  4401. {
  4402. ContentControl img = sender as ContentControl;
  4403. if (img == null)
  4404. {
  4405. return;
  4406. }
  4407. img.ReleaseMouseCapture();
  4408. mouseDown = false;
  4409. }
  4410. private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  4411. {
  4412. ContentControl img = sender as ContentControl;
  4413. if (img == null)
  4414. {
  4415. return;
  4416. }
  4417. if (mouseDown)
  4418. {
  4419. Domousemove(img, e);
  4420. }
  4421. }
  4422. /// <summary>
  4423. /// x y轴
  4424. /// </summary>
  4425. /// <param name="img"></param>
  4426. /// <param name="e"></param>
  4427. private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
  4428. {
  4429. if (e.LeftButton != MouseButtonState.Pressed)
  4430. {
  4431. return;
  4432. }
  4433. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  4434. {
  4435. return;
  4436. }
  4437. TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
  4438. TranslateTransform transform = group.Children[1] as TranslateTransform;
  4439. System.Windows.Point position = e.GetPosition(img);
  4440. transform.X -= mouseXY.X - position.X;
  4441. transform.Y -= mouseXY.Y - position.Y;
  4442. mouseXY = position;
  4443. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  4444. {
  4445. X = transform.X,
  4446. Y = transform.Y
  4447. };
  4448. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  4449. }
  4450. private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
  4451. {
  4452. ContentControl img = sender as ContentControl;
  4453. if (img == null)
  4454. {
  4455. return;
  4456. }
  4457. System.Windows.Point point = e.GetPosition(img);
  4458. //Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
  4459. System.Windows.Point PicLocate = e.GetPosition(imgCanvas);
  4460. //Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
  4461. TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
  4462. double delta = e.Delta * 0.001;
  4463. DowheelZoom(group, point, delta);
  4464. }
  4465. private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
  4466. {
  4467. System.Windows.Point pointToContent = group.Inverse.Transform(point);
  4468. ScaleTransform transform = group.Children[0] as ScaleTransform;
  4469. if (transform.ScaleX + delta < 0.1)
  4470. {
  4471. return;
  4472. }
  4473. transform.ScaleX += delta;
  4474. transform.ScaleY += delta;
  4475. TranslateTransform transform1 = group.Children[1] as TranslateTransform;
  4476. transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
  4477. transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
  4478. //LogHelper.WriteInfoLog("【img宽高】" + imgCanvas.ActualWidth.ToString() + ":"
  4479. // + imgCanvas.ActualHeight.ToString() + "百分比:" + transform.ScaleX.ToString() + ":" + transform.ScaleY.ToString()
  4480. // );
  4481. //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
  4482. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize = new ScaleTransform();
  4483. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX = transform.ScaleX;
  4484. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY = transform.ScaleY;
  4485. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  4486. {
  4487. X = transform1.X,
  4488. Y = transform1.Y
  4489. };
  4490. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  4491. {
  4492. CenterX = imgCanvas.ActualWidth,
  4493. CenterY = imgCanvas.ActualHeight
  4494. };
  4495. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  4496. }
  4497. #endregion
  4498. #region 点阵笔相关
  4499. #region 值初始化
  4500. // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
  4501. /// <summary>
  4502. /// A4点阵纸点阵宽度
  4503. /// </summary>
  4504. private const int A4_WIDTH = 5600;
  4505. /// <summary>
  4506. /// A4点阵纸点阵高度
  4507. /// </summary>
  4508. private const int A4_HEIGHT = 7920;
  4509. ///// <summary>
  4510. ///// 画板
  4511. ///// </summary>
  4512. //private Graphics graphics;
  4513. /// <summary>
  4514. /// 笔画坐标数组
  4515. /// </summary>
  4516. //private List<System.Drawing.Point> stroke;
  4517. /// <summary>
  4518. /// 笔序列号
  4519. /// </summary>
  4520. private string penSerial;
  4521. /// <summary>
  4522. /// 笔是否在点
  4523. /// </summary>
  4524. private bool isPenDown;
  4525. //当前点阵地址
  4526. private string currentPageSerial = string.Empty;
  4527. //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
  4528. //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
  4529. private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
  4530. #endregion
  4531. public void InitPen()
  4532. {
  4533. //stroke = new List<System.Drawing.Point>();
  4534. //获取点阵笔实例,并绑定点阵笔事件
  4535. //将授权文件内容传入,获取点阵笔对象实例
  4536. APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
  4537. //绑定笔连接事件
  4538. APP.digitalPen.PenConnected += OnPenConnect;
  4539. //绑定笔断开事件
  4540. APP.digitalPen.PenDisconnect += OnPenDisconnect;
  4541. //绑定笔书写输出坐标事件
  4542. APP.digitalPen.PenCoordinate += OnPenCoordinate;
  4543. //绑定抬笔事件
  4544. APP.digitalPen.PenUp += OnPenUp;
  4545. //绑定落笔事件
  4546. APP.digitalPen.PenDown += OnPenDown;
  4547. APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
  4548. APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
  4549. //完成初始化点阵笔,开始与点阵笔通信
  4550. ERROR_CODE ER = APP.digitalPen.Start();
  4551. ////绑定笔在新的点阵地址页面书写事件
  4552. //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
  4553. ////绑定笔信息事件
  4554. //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
  4555. //启动接收笔数据,完成初始化工作
  4556. ERROR_CODE rc = APP.digitalPen.Start();
  4557. //判断是否成功
  4558. if (ER != ERROR_CODE.ERROR_OK)
  4559. {
  4560. MessageWindow.Show("初始化失败,授权过期,返回值:" + ER.ToString());
  4561. }
  4562. }
  4563. /// <summary>
  4564. /// 落笔
  4565. /// </summary>
  4566. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4567. /// <param name="penSerial">点阵笔序列号</param>
  4568. /// <param name="penType">点阵笔型号编号</param>
  4569. private void OnPenDown(ulong time, string penSerial, int penType)
  4570. {
  4571. if (CheckAccess())
  4572. {
  4573. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
  4574. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  4575. }
  4576. else
  4577. {
  4578. //labPenSerial.Text = penSerial;
  4579. //labPenStatus.Text = "PenDown";
  4580. isPenDown = true;
  4581. //Dispatcher.Invoke(new Action(() =>
  4582. //{
  4583. // for (int i = 0; i < APP.PageDrawList.Count; i++)
  4584. // {
  4585. // if (APP.PageDrawList[i].PageCode == penSerial)
  4586. // {
  4587. // if (i < APP.pageData.pagenum)
  4588. // {
  4589. // if (i < APP.pageData.currpage)
  4590. // {
  4591. // int num = APP.pageData.currpage - i;
  4592. // APP.pageData.currpage -= num;
  4593. // myblackboard.changepage(APP.pageData.currpage - 1);
  4594. // if (APP.PageDrawList.Count > 0)
  4595. // {
  4596. // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  4597. // {
  4598. // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  4599. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  4600. // }
  4601. // else
  4602. // {
  4603. // imgCanvas.Source = null;
  4604. // }
  4605. // }
  4606. // }
  4607. // else
  4608. // {
  4609. // int num = i - APP.pageData.currpage;
  4610. // APP.pageData.currpage += num;
  4611. // myblackboard.changepage(APP.pageData.currpage - 1);
  4612. // if (APP.PageDrawList.Count > 0)
  4613. // {
  4614. // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  4615. // {
  4616. // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  4617. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  4618. // }
  4619. // else
  4620. // {
  4621. // imgCanvas.Source = null;
  4622. // }
  4623. // }
  4624. // }
  4625. // }
  4626. // return;
  4627. // }
  4628. // }
  4629. // //myblackboard.changepages(0, 0, true);
  4630. // //myblackboard.changepaget(0, 0, true, blackboard_canvas);
  4631. //}));
  4632. }
  4633. //myblackboard.changepages(0, 0, true);
  4634. }
  4635. /// <summary>
  4636. /// 抬笔
  4637. /// </summary>
  4638. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4639. /// <param name="penSerial">点阵笔序列号</param>
  4640. /// <param name="penType">点阵笔型号编号</param>
  4641. private void OnPenUp(ulong time, string penSerial, int penType)
  4642. {
  4643. if (CheckAccess())
  4644. {
  4645. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
  4646. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  4647. }
  4648. else
  4649. {
  4650. isPenDown = false;
  4651. APP.PenSerial = penSerial;
  4652. //int leftPoints = stroke.Count % 3;
  4653. //if (0 != leftPoints)
  4654. //{
  4655. // int from = stroke.Count - leftPoints - 1;
  4656. // if (from < 0)
  4657. // from = 0;
  4658. // int to = stroke.Count - 1;
  4659. // DrawCoordinates(from, to);
  4660. //}
  4661. //stroke.Clear();
  4662. }
  4663. if (APP.pageData.currpage > 0)
  4664. {
  4665. Dispatcher.Invoke(new Action(() =>
  4666. {
  4667. myblackboard.changepages(0, 0, true, Color, PenSize, APP.pageData.currpage - 1, 0);
  4668. }));
  4669. }
  4670. }
  4671. /// <summary>
  4672. /// 笔断开
  4673. /// </summary>
  4674. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4675. /// <param name="penSerial">点阵笔序列号</param>
  4676. /// <param name="penType">点阵笔型号编号</param>
  4677. private void OnPenDisconnect(ulong time, string penSerial, int penType)
  4678. {
  4679. if (CheckAccess())
  4680. {
  4681. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
  4682. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  4683. }
  4684. else
  4685. {
  4686. APP.PenSerial = penSerial;
  4687. APP.PenStatus = false;
  4688. UpdateDevStatus();
  4689. //Dispatcher.Invoke(new Action(() =>
  4690. //{
  4691. // txbNotConnected.Text = "未连接";
  4692. // txbNotConnecteds.Text = "未连接";
  4693. //}));
  4694. }
  4695. }
  4696. /// <summary>
  4697. /// 笔连接
  4698. /// </summary>
  4699. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4700. /// <param name="penSerial">点阵笔序列号</param>
  4701. /// <param name="penType">点阵笔型号编号</param>
  4702. private void OnPenConnect(ulong time, string penSerial, int penType)
  4703. {
  4704. if (CheckAccess())
  4705. {
  4706. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
  4707. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  4708. }
  4709. else
  4710. {
  4711. APP.PenSerial = penSerial;
  4712. APP.PenStatus = true;
  4713. this.penSerial = penSerial;
  4714. //连接后,在获取笔数据前,可以清除笔内的历史数据
  4715. //APP.digitalPen.ClearMemory(penSerial);
  4716. //开始接收笔数据
  4717. APP.digitalPen.GetPenData(penSerial);
  4718. UpdateDevStatus();
  4719. //Dispatcher.Invoke(new Action(() =>
  4720. //{
  4721. // txbNotConnected.Text = "已连接";
  4722. // txbNotConnecteds.Text = "已连接";
  4723. //}));
  4724. }
  4725. }
  4726. /// <summary>
  4727. /// 电池电量
  4728. /// </summary>
  4729. /// <param name="time"></param>
  4730. /// <param name="penSerial"></param>
  4731. /// <param name="penType"></param>
  4732. /// <param name="capacity"></param>
  4733. private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
  4734. {
  4735. if (CheckAccess())
  4736. {
  4737. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
  4738. Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
  4739. }
  4740. else
  4741. {
  4742. //System.Windows.MessageWindow.Show("电池电量:" + capacity.ToString());
  4743. }
  4744. }
  4745. /// <summary>
  4746. /// 已用存储
  4747. /// </summary>
  4748. /// <param name="time"></param>
  4749. /// <param name="penSerial"></param>
  4750. /// <param name="penType"></param>
  4751. /// <param name="fillLevel"></param>
  4752. private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
  4753. {
  4754. if (CheckAccess())
  4755. {
  4756. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
  4757. Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
  4758. }
  4759. else
  4760. {
  4761. //System.Windows.MessageWindow.Show("存储:" + fillLevel.ToString());
  4762. }
  4763. }
  4764. /// <summary>
  4765. /// 笔书写,收到坐标
  4766. /// </summary>
  4767. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4768. /// <param name="penSerial">点阵笔序列号</param>
  4769. /// <param name="penType">点阵笔型号编号</param>
  4770. /// <param name="pageSerial">点阵地址</param>
  4771. /// <param name="cx">x坐标</param>
  4772. /// <param name="cy">y坐标</param>
  4773. /// <param name="force">压力值</param>
  4774. private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
  4775. {
  4776. if (CheckAccess())
  4777. {
  4778. Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
  4779. Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
  4780. }
  4781. else
  4782. {
  4783. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  4784. if (!isPenDown)
  4785. {
  4786. return;
  4787. }
  4788. //stroke.Add(new System.Drawing.Point(cx, cy));
  4789. double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
  4790. double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
  4791. //点
  4792. double tempX = cx * PropW;
  4793. double tempY = cy * PropH;
  4794. //pageSerial //点阵IP地址 与打印的页面关联
  4795. if (APP.pageData.currpage > 0)
  4796. {
  4797. Dispatcher.Invoke(new Action(() =>
  4798. {
  4799. float Pressure = force / 100f;
  4800. //myblackboard.changepages(testX, testY,false);
  4801. myblackboard.changepages(tempX, tempY, false, Color, PenSize, APP.pageData.currpage - 1, Pressure);
  4802. #region 设置滚动条位置
  4803. //点在显示页面上方
  4804. if (tempY < scroMain.VerticalOffset)
  4805. {
  4806. //滚动条当前位置
  4807. double RollCurrentLocation = scroMain.VerticalOffset;
  4808. //向上滚动至以点为中心需要滚动的距离
  4809. double UpRoll = (RollCurrentLocation - tempY) + (scroMain.ActualHeight / 2);
  4810. //如果小于0则等于0
  4811. double RollLocation = RollCurrentLocation - UpRoll;
  4812. if (RollLocation < 0)
  4813. {
  4814. RollLocation = 0;
  4815. }
  4816. ////滚动条实际偏移量
  4817. //double RollOffset = RollCurrentLocation - RollLocation;
  4818. scroMain.ScrollToVerticalOffset(RollLocation);
  4819. }
  4820. //点在显示页面下方
  4821. if (tempY > scroMain.VerticalOffset + scroMain.ActualHeight)
  4822. {
  4823. //滚动条当前位置
  4824. double RollCurrentLocation = scroMain.VerticalOffset;
  4825. //向下滚动至以点为中心需要滚动的距离
  4826. double DownRoll = (tempY - RollCurrentLocation) - (scroMain.ActualHeight / 2);
  4827. //如果小于0则等于0
  4828. double RollLocation = RollCurrentLocation + DownRoll;
  4829. //滚动条最大滚动值
  4830. double ScrollbarMaxNum = gridM.ActualHeight - scroMain.ActualHeight;
  4831. if (RollLocation > ScrollbarMaxNum)
  4832. {
  4833. RollLocation = ScrollbarMaxNum;
  4834. }
  4835. ////滚动条实际偏移量
  4836. //double RollOffset = RollLocation-RollCurrentLocation;
  4837. scroMain.ScrollToVerticalOffset(RollLocation);
  4838. }
  4839. #endregion
  4840. //gridM.Height //A4高度
  4841. //scroMain.VerticalOffset;//获取滚动条位置
  4842. //scroMain.ActualHeight//A4纸显示高度
  4843. //scroMain.ScrollToHorizontalOffset()//设置滚动条位置
  4844. //Mouse.GetPosition(this)
  4845. if (tempX > 0 && tempY > 0)
  4846. {
  4847. //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
  4848. System.Windows.Point getP = scroMain.PointToScreen(new System.Windows.Point(tempX, tempY - scroMain.VerticalOffset));
  4849. SetCursorPos((int)getP.X, (int)getP.Y);
  4850. }
  4851. }));
  4852. }
  4853. ////每3个点画一条曲线
  4854. //if (stroke.Count % 3 == 0)
  4855. //{
  4856. // int from = stroke.Count - 3 - 1;
  4857. // if (from < 0)
  4858. // from = 0;
  4859. // int to = stroke.Count - 1;
  4860. // DrawCoordinates(from, to);
  4861. //}
  4862. }
  4863. }
  4864. /// <summary>
  4865. /// 停止笔
  4866. /// </summary>
  4867. public void StopDigitalPen()
  4868. {
  4869. //停止,释放资源
  4870. APP.digitalPen.Stop();
  4871. }
  4872. /// <summary>
  4873. /// 清空笔内存储
  4874. /// </summary>
  4875. public void ClearPenStorage()
  4876. {
  4877. if (!string.IsNullOrEmpty(penSerial))
  4878. {
  4879. APP.digitalPen.ClearMemory(penSerial);
  4880. }
  4881. }
  4882. /// <summary>
  4883. /// 获取剩余电量
  4884. /// </summary>
  4885. public void GetPenElectricityQuantity()
  4886. {
  4887. if (!string.IsNullOrEmpty(penSerial))
  4888. {
  4889. APP.digitalPen.GetBatteryCapacity(penSerial);
  4890. }
  4891. }
  4892. /// <summary>
  4893. /// 获取存储空间
  4894. /// </summary>
  4895. public void GetUsedStorage()
  4896. {
  4897. if (!string.IsNullOrEmpty(penSerial))
  4898. {
  4899. APP.digitalPen.GetMemoryFillLevel(penSerial);
  4900. }
  4901. }
  4902. /// <summary>
  4903. /// 开启悬浮
  4904. /// </summary>
  4905. public void 开启悬浮()
  4906. {
  4907. if (!string.IsNullOrEmpty(penSerial))
  4908. {
  4909. APP.digitalPen.SetPenHoverMode(true, penSerial);
  4910. }
  4911. }
  4912. /// <summary>
  4913. /// 关闭悬浮
  4914. /// </summary>
  4915. public void 关闭悬浮()
  4916. {
  4917. if (!string.IsNullOrEmpty(penSerial))
  4918. {
  4919. APP.digitalPen.SetPenHoverMode(false, penSerial);
  4920. }
  4921. }
  4922. /// <summary>
  4923. /// 引用user32.dll动态链接库(windows api),
  4924. /// 使用库中定义 API:SetCursorPos
  4925. /// 设置光标位置
  4926. /// </summary>
  4927. [System.Runtime.InteropServices.DllImport("user32.dll")]
  4928. private static extern int SetCursorPos(int x, int y);
  4929. #endregion
  4930. #region 写字板模式
  4931. #region 值初始化
  4932. [System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
  4933. public static extern void OutputDebugString(string message);
  4934. public bool usbIsConnected = false;
  4935. //Angle angle = Angle._270;
  4936. eDeviceType deviceType = eDeviceType.Unknow;
  4937. ///// <summary>
  4938. ///// 点缩放比例
  4939. ///// </summary>
  4940. //private double m_nCompress = 0;
  4941. //private double m_nCompress_x = 0;
  4942. //private double m_nCompress_y = 0;
  4943. ///// <summary>
  4944. ///// 0:画布根据板子适配
  4945. ///// 1:板子根据画布适配
  4946. ///// </summary>
  4947. //private int type = 1;//默认画笔根据板子适配
  4948. //bool bScreenO = false;//判断是否是横屏,默认横屏,true:横屏幕;false:竖屏
  4949. //Drawing drawing;
  4950. //List<RobotPoint> plist = new List<RobotPoint>();
  4951. //画布宽高
  4952. //private int m_nDeviceW = 21000;
  4953. //private int m_nDeviceH = 29700;
  4954. private int m_nDeviceW = 22600;
  4955. private int m_nDeviceH = 16650;
  4956. private RobotpenGateway.robotpenController.returnPointData date = null;
  4957. //private int nResource = 0;
  4958. //private ReportRate RR = ReportRate.R_200;
  4959. //string Mac = string.Empty;
  4960. //int Recog_create = 0;
  4961. //int Recog_adddate = 0;
  4962. //int Recog_start = 0;
  4963. public bool isOpen = true;
  4964. //PrintType ptype = PrintType.NoMarkCode_FB2;
  4965. //int pageData = 0;
  4966. //bool AreSynchronized = false;
  4967. /// <summary>
  4968. /// 是否为笔模式
  4969. /// </summary>
  4970. bool IsPen = false;
  4971. bool IsT8 = true;
  4972. #endregion
  4973. #region 罗博智慧笔
  4974. /// <summary>
  4975. /// 笔模式
  4976. /// </summary>
  4977. private void deviceHand()
  4978. {
  4979. IsPen = true;
  4980. if (APP.IsOutputInfoLog)
  4981. {
  4982. LogHelper.WriteInfoLog(string.Format("切换笔模式:设备类型:{0}", deviceType.ToString()));
  4983. }
  4984. if (deviceType == eDeviceType.T8B_D2 || deviceType == eDeviceType.T8Y || deviceType == eDeviceType.T8S_LQ)
  4985. {
  4986. IsT8 = true;
  4987. robotpenController.GetInstance().setDeviceMode(eDeviceMode.DEVICE_HAND);
  4988. if (APP.IsOutputInfoLog)
  4989. {
  4990. LogHelper.WriteInfoLog("使用robotpenController.GetInstance().setDeviceMode(eDeviceMode.DEVICE_HAND)切换");
  4991. }
  4992. }
  4993. else
  4994. {
  4995. IsT8 = false;
  4996. //获取当前设备模式,根据模式切换鼠标和笔
  4997. robotpenController.GetInstance()._Send(cmdId.SearchMode);
  4998. if (APP.IsOutputInfoLog)
  4999. {
  5000. LogHelper.WriteInfoLog("发送(cmdId.SearchMode)");
  5001. }
  5002. }
  5003. }
  5004. /// <summary>
  5005. /// 鼠标模式
  5006. /// </summary>
  5007. private void deviceMouse()
  5008. {
  5009. IsPen = false;
  5010. if (deviceType == eDeviceType.T8B_D2 || deviceType == eDeviceType.T8Y || deviceType == eDeviceType.T8S_LQ)
  5011. {
  5012. IsT8 = true;
  5013. robotpenController.GetInstance().setDeviceMode(eDeviceMode.DEVICE_MOUSE);
  5014. if (APP.IsOutputInfoLog)
  5015. {
  5016. LogHelper.WriteInfoLog("使用robotpenController.GetInstance().setDeviceMode(eDeviceMode.DEVICE_MOUSE)切换");
  5017. }
  5018. }
  5019. else
  5020. {
  5021. IsT8 = false;
  5022. //获取当前设备模式,根据模式切换鼠标和笔
  5023. robotpenController.GetInstance()._Send(cmdId.SearchMode);
  5024. if (APP.IsOutputInfoLog)
  5025. {
  5026. LogHelper.WriteInfoLog("发送(cmdId.SearchMode)");
  5027. }
  5028. }
  5029. }
  5030. private void Form1_searchModeEvt(int modeType)
  5031. {
  5032. //笔模式
  5033. if (modeType == 1)
  5034. {
  5035. if (APP.IsOutputInfoLog)
  5036. {
  5037. LogHelper.WriteInfoLog("当前为笔模式时,切换回鼠标模式");
  5038. }
  5039. //当前为笔模式时 切换回鼠标模式
  5040. if (!IsPen && !IsT8)
  5041. {
  5042. robotpenController.GetInstance()._Send(cmdId.SwitchMode);
  5043. if (APP.IsOutputInfoLog)
  5044. {
  5045. LogHelper.WriteInfoLog("T7设备切换成鼠标模式._Send(cmdId.SwitchMode)");
  5046. }
  5047. }
  5048. }
  5049. else
  5050. {
  5051. if (APP.IsOutputInfoLog)
  5052. {
  5053. LogHelper.WriteInfoLog("当前为鼠标模式 切换为笔模式");
  5054. }
  5055. //当前为鼠标模式 切换为笔模式
  5056. if (isOpen && !IsT8)
  5057. {
  5058. robotpenController.GetInstance()._Send(cmdId.SwitchMode);
  5059. if (APP.IsOutputInfoLog)
  5060. {
  5061. LogHelper.WriteInfoLog("T7设备切换成笔模式._Send(cmdId.SwitchMode)");
  5062. }
  5063. }
  5064. }
  5065. }
  5066. private void Form1_switchModeEvt(int modeType)
  5067. {
  5068. if (modeType == 1)
  5069. {
  5070. if (APP.IsOutputInfoLog)
  5071. {
  5072. LogHelper.WriteInfoLog("当前为笔模式");
  5073. }
  5074. if (!IsPen)
  5075. {
  5076. deviceMouse();
  5077. }
  5078. ////当前为笔模式时 切换回鼠标模式
  5079. //if (!IsPen && !IsT8)
  5080. //{
  5081. // robotpenController.GetInstance()._Send(cmdId.SwitchMode);
  5082. // if (APP.IsOutputInfoLog)
  5083. // {
  5084. // LogHelper.WriteInfoLog("T7设备切换成鼠标模式._Send(cmdId.SwitchMode)");
  5085. // }
  5086. //}
  5087. }
  5088. else
  5089. {
  5090. if (APP.IsOutputInfoLog)
  5091. {
  5092. LogHelper.WriteInfoLog("当前为鼠标模式");
  5093. }
  5094. if (IsPen)
  5095. {
  5096. deviceHand();
  5097. }
  5098. ////当前为鼠标模式 切换为笔模式
  5099. //if (isOpen && !IsT8)
  5100. //{
  5101. // robotpenController.GetInstance()._Send(cmdId.SwitchMode);
  5102. // if (APP.IsOutputInfoLog)
  5103. // {
  5104. // LogHelper.WriteInfoLog("T7设备切换成笔模式._Send(cmdId.SwitchMode)");
  5105. // }
  5106. //}
  5107. }
  5108. }
  5109. //初始化笔服务
  5110. private void InitlbPen()
  5111. {
  5112. try
  5113. {
  5114. robotpenController.GetInstance()._ConnectInitialize(eDeviceType.Gateway, IntPtr.Zero);
  5115. robotpenController.GetInstance().deviceChangeEvt += new robotpenController.DeviceChange(Form1_deviceChangeEvt);
  5116. robotpenController.GetInstance().searchModeEvt += Form1_searchModeEvt;
  5117. robotpenController.GetInstance().switchModeEvt += Form1_switchModeEvt;
  5118. //robotpenController.GetInstance().deviceChangeEvt += new robotpenController.DeviceChange(Form1_deviceChangeEvt);
  5119. //robotpenController.GetInstance().gatewatVersionEvt += Form1_gatewatVersionEvt;
  5120. //robotpenController.GetInstance().nodeStatusEvt += Form1_nodeStatusEvt;
  5121. //// 所有设备均注册该页码显示消息 目前只有T9设备才会有页码识别功能, 客户代码可以根据设备来判断是否消费该事件
  5122. //robotpenController.GetInstance().showPageEvt += new robotpenController.ShowPage(Form1_showPageEvt);
  5123. // T8A 按键消息 为了适应其他demo也能响应, 所以任何demo都消费此事件, 客户代码可根据设备类型判断是否消费此事件
  5124. robotpenController.GetInstance().keyPressEvt += new robotpenController.KeyPress(Form1_keyPressEvt);
  5125. //robotpenController.GetInstance().PageSensorCallback_Evt += Rbtnet__PageSensorEvt_;
  5126. date = new RobotpenGateway.robotpenController.returnPointData(Form1_bigDataReportEvt1);
  5127. robotpenController.GetInstance().initDeletgate(ref date);
  5128. CheckUsbConnect();
  5129. ////robotpenController.GetInstance().returnOptimizePointDataEvt += new robotpenController.returnOptimizePointData(Form1_returnOptimizePointDataEvt);
  5130. //robotpenController.GetInstance().startSyncNoteDataEvt += new robotpenController.startSyncNoteData(Form1_startSyncNoteDataEvt);
  5131. //robotpenController.GetInstance().startSyncNoteData_kzEvt += Form1_startSyncNoteData_kzEvt;
  5132. //robotpenController.GetInstance().syncNoteDataEvt += new robotpenController.syncNoteData(Form1_syncNoteDataEvt);
  5133. //robotpenController.GetInstance().endSyncNoteDataEvt += new robotpenController.endSyncNoteData(Form1_endSyncNoteDataEvt);
  5134. //robotpenController.GetInstance().getOfflineNoteDataEvt += new robotpenController.getOfflineNoteData(Form1_getOfflineNoteDataEvt);
  5135. }
  5136. catch (Exception ex)
  5137. {
  5138. LogHelper.WriteErrLog("设备初始化失败:" + ex.Message, ex);
  5139. }
  5140. }
  5141. /// <summary>
  5142. /// 委托实例函数,用于异步修改listview显示的USB连接设备信息
  5143. /// </summary>
  5144. private void SetListView()
  5145. {
  5146. if (usbIsConnected)
  5147. {
  5148. robotpenController.GetInstance()._CloseConnect();
  5149. }
  5150. CheckUsbConnect();
  5151. }
  5152. /// <summary>
  5153. /// 设备插拔消息,更新listview
  5154. /// </summary>
  5155. /// <param name="bStatus"></param>
  5156. /// <param name="uPid"></param>
  5157. void Form1_deviceChangeEvt(bool bStatus, ushort uPid)
  5158. {
  5159. //throw new NotImplementedException();
  5160. //Console.WriteLine();
  5161. try
  5162. {
  5163. if (APP.IsOutputInfoLog)
  5164. {
  5165. LogHelper.WriteInfoLog(string.Format("设备状态{0} PID = {1}", bStatus, uPid));
  5166. }
  5167. }
  5168. catch (Exception)
  5169. {
  5170. }
  5171. //SetListView();
  5172. CheckUsbConnect();
  5173. }
  5174. /// <summary>
  5175. /// 书写
  5176. /// </summary>
  5177. /// /// <param name="bIndex"></param>
  5178. /// <param name="bPenStatus"></param>
  5179. /// <param name="bx"></param>
  5180. /// <param name="by"></param>
  5181. /// <param name="bPress"></param>
  5182. private void Form1_bigDataReportEvt1(byte bIndex, byte bPenStatus, short bx, short by, short bPress)
  5183. {
  5184. if (bx == 0 && by == 0 && bPenStatus == 0 && bPress == 0)
  5185. {
  5186. return;
  5187. }
  5188. //17是按下,16是抬起
  5189. if (bPenStatus == 16 || bPenStatus == 0)
  5190. {
  5191. //stroke.Clear();
  5192. if (APP.pageData.currpage > 0)
  5193. {
  5194. Dispatcher.Invoke(new Action(() =>
  5195. {
  5196. myblackboard.changepages(0, 0, true, Color, PenSize, APP.pageData.currpage - 1, 0);
  5197. }));
  5198. }
  5199. }
  5200. ////按下
  5201. //if (bPenStatus == 17)
  5202. //{
  5203. //}
  5204. //if (APP.IsOutputInfoLog)
  5205. //{
  5206. // LogHelper.WriteInfoLog(string.Format(@"x={0},y={1},s={2},p={3}", bx, by, bPenStatus, bPress));
  5207. //}
  5208. //stroke.Add(new System.Drawing.Point(by, bx));
  5209. double PropW = blackboard_canvas.ActualWidth / m_nDeviceH;
  5210. double PropH = blackboard_canvas.ActualHeight / m_nDeviceW;
  5211. //点
  5212. double tempY = (m_nDeviceW - bx) * PropH;
  5213. double tempX = by * PropW;
  5214. //pageSerial //点阵IP地址 与打印的页面关联
  5215. if (APP.pageData.currpage > 0)
  5216. {
  5217. Dispatcher.Invoke(new Action(() =>
  5218. {
  5219. float Pressure = bPress / 100f;
  5220. //myblackboard.changepages(testX, testY,false);
  5221. if (bPress > 0)
  5222. {
  5223. myblackboard.changepages(tempX, tempY, false, Color, PenSize, APP.pageData.currpage - 1, Pressure);
  5224. }
  5225. #region 设置滚动条位置
  5226. //点在显示页面上方
  5227. if (tempY < scroMain.VerticalOffset)
  5228. {
  5229. //滚动条当前位置
  5230. double RollCurrentLocation = scroMain.VerticalOffset;
  5231. //向上滚动至以点为中心需要滚动的距离
  5232. double UpRoll = (RollCurrentLocation - tempY) + (scroMain.ActualHeight / 2);
  5233. //如果小于0则等于0
  5234. double RollLocation = RollCurrentLocation - UpRoll;
  5235. if (RollLocation < 0)
  5236. {
  5237. RollLocation = 0;
  5238. }
  5239. ////滚动条实际偏移量
  5240. //double RollOffset = RollCurrentLocation - RollLocation;
  5241. scroMain.ScrollToVerticalOffset(RollLocation);
  5242. }
  5243. //点在显示页面下方
  5244. if (tempY > scroMain.VerticalOffset + scroMain.ActualHeight)
  5245. {
  5246. //滚动条当前位置
  5247. double RollCurrentLocation = scroMain.VerticalOffset;
  5248. //向下滚动至以点为中心需要滚动的距离
  5249. double DownRoll = (tempY - RollCurrentLocation) - (scroMain.ActualHeight / 2);
  5250. //如果小于0则等于0
  5251. double RollLocation = RollCurrentLocation + DownRoll;
  5252. //滚动条最大滚动值
  5253. double ScrollbarMaxNum = gridM.ActualHeight - scroMain.ActualHeight;
  5254. if (RollLocation > ScrollbarMaxNum)
  5255. {
  5256. RollLocation = ScrollbarMaxNum;
  5257. }
  5258. ////滚动条实际偏移量
  5259. //double RollOffset = RollLocation-RollCurrentLocation;
  5260. scroMain.ScrollToVerticalOffset(RollLocation);
  5261. }
  5262. #endregion
  5263. if (tempX > 0 && tempY > 0)
  5264. {
  5265. //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
  5266. System.Windows.Point getP = scroMain.PointToScreen(new System.Windows.Point(tempX, tempY - scroMain.VerticalOffset));
  5267. SetCursorPos((int)getP.X, (int)getP.Y);
  5268. }
  5269. }));
  5270. }
  5271. }
  5272. /// <summary>
  5273. /// 判断是否有设备连接
  5274. /// </summary>
  5275. public void CheckUsbConnect()
  5276. {
  5277. usbIsConnected = false;
  5278. Thread.Sleep(200);
  5279. int nDeviceCount = robotpenController.GetInstance()._GetDeviceCount();
  5280. if (APP.IsOutputInfoLog)
  5281. {
  5282. LogHelper.WriteInfoLog(string.Format("当前有 {0} 个设备", nDeviceCount));
  5283. }
  5284. if (nDeviceCount > 0)
  5285. {
  5286. //this.listView1.BeginUpdate();
  5287. for (int i = 0; i < nDeviceCount; ++i)
  5288. {
  5289. ushort npid = 0;
  5290. ushort nvid = 0;
  5291. string strDeviceName = string.Empty;
  5292. eDeviceType dtype = eDeviceType.Unknow;
  5293. if (robotpenController.GetInstance()._GetAvailableDevice(i, ref npid, ref nvid, ref strDeviceName, ref dtype))
  5294. {
  5295. if (!usbIsConnected)
  5296. {
  5297. usbIsConnected = true;
  5298. deviceType = dtype;
  5299. robotpenController.GetInstance()._ConnectInitialize(deviceType, IntPtr.Zero);
  5300. int nRes = robotpenController.GetInstance()._ConnectOpen();
  5301. if (nRes != 0)
  5302. {
  5303. //LogHelper.WriteInfoLog(string.Format(@"x={0},y={1},s={2},p={3}", bx, by, bPenStatus, bPress));
  5304. LogHelper.WriteErrLog("设备自动连接失败,请重新插拔设备或尝试手动连接!", null);
  5305. usbIsConnected = false;
  5306. break;
  5307. }
  5308. //robotpenController.GetInstance()._Send(cmdId.SwitchMode);
  5309. robotpenController.GetInstance()._Send(cmdId.GetConfig);
  5310. APP.BoardStatus = true;
  5311. try
  5312. {
  5313. int banWidth = robotpenController.GetInstance().getWidth();
  5314. int banHeight = robotpenController.GetInstance().getHeight();
  5315. if (banWidth > 0 && banHeight > 0)
  5316. {
  5317. if (banWidth > banHeight)
  5318. {
  5319. m_nDeviceW = banWidth;
  5320. m_nDeviceH = banHeight;
  5321. }
  5322. else
  5323. {
  5324. m_nDeviceW = banHeight;
  5325. m_nDeviceH = banWidth;
  5326. }
  5327. }
  5328. if (APP.IsOutputInfoLog)
  5329. {
  5330. LogHelper.WriteInfoLog(string.Format("手写板宽度为:{0} 高度为:{1}", m_nDeviceW, m_nDeviceH));
  5331. }
  5332. }
  5333. catch (Exception ex)
  5334. {
  5335. LogHelper.WriteErrLog("手写板大小获取失败:" + ex.Message, ex);
  5336. }
  5337. UpdateDevStatus();
  5338. if (APP.IsOutputInfoLog)
  5339. {
  5340. LogHelper.WriteInfoLog(string.Format("设备类型:{0}", deviceType.ToString()));
  5341. }
  5342. //Dispatcher.Invoke(new Action(() =>
  5343. //{
  5344. // txbNotConnected.Text = "手写板";
  5345. // txbNotConnecteds.Text = "手写板";
  5346. //}));
  5347. new Thread(new ThreadStart(new Action(() =>
  5348. {
  5349. Thread.Sleep(1500);
  5350. //Dispatcher.Invoke(() =>
  5351. //{
  5352. //获取当前设备状态
  5353. robotpenController.GetInstance()._Send(cmdId.SearchMode);
  5354. //});
  5355. }))).Start();
  5356. }
  5357. }
  5358. }
  5359. }
  5360. else
  5361. {
  5362. APP.BoardStatus = false;
  5363. UpdateDevStatus();
  5364. }
  5365. }
  5366. /// <summary>
  5367. /// 按键回调函数
  5368. /// </summary>
  5369. /// <param name="Value"></param>
  5370. private void Form1_keyPressEvt(eKeyPress Value)
  5371. {
  5372. Dispatcher.Invoke(new Action(() =>
  5373. {
  5374. switch (Value)
  5375. {
  5376. case eKeyPress.CLICK:
  5377. break;
  5378. case eKeyPress.DBCLICK:
  5379. break;
  5380. case eKeyPress.PAGEUP:
  5381. last_button_Click(null, null);
  5382. break;
  5383. case eKeyPress.PAGEDOWN:
  5384. next_btn_Click(null, null);
  5385. break;
  5386. case eKeyPress.CREATEPAGE://关机键
  5387. break;
  5388. case eKeyPress.KEY_A:
  5389. break;
  5390. case eKeyPress.KEY_B:
  5391. break;
  5392. case eKeyPress.KEY_C:
  5393. break;
  5394. case eKeyPress.KEY_D:
  5395. break;
  5396. case eKeyPress.KEY_E:
  5397. break;
  5398. case eKeyPress.KEY_F:
  5399. break;
  5400. case eKeyPress.KEY_UP:
  5401. last_button_Click(null, null);
  5402. break;
  5403. case eKeyPress.KEY_DOWN:
  5404. next_btn_Click(null, null);
  5405. break;
  5406. case eKeyPress.KEY_YES:
  5407. break;
  5408. case eKeyPress.KEY_NO:
  5409. break;
  5410. case eKeyPress.KEY_CANCEL:
  5411. break;
  5412. case eKeyPress.KEY_OK:
  5413. break;
  5414. case eKeyPress.PAGEUPCLICK://上一页
  5415. last_button_Click(null, null);
  5416. break;
  5417. case eKeyPress.PAGEUPDBCLICK://双击上一页
  5418. break;
  5419. case eKeyPress.PAGEUPPRESS://长按上一页
  5420. break;
  5421. case eKeyPress.PAGEDOWNCLICK://下一页
  5422. next_btn_Click(null, null);
  5423. break;
  5424. case eKeyPress.PAGEDOWNDBCLICK://双击下一页
  5425. break;
  5426. case eKeyPress.PAGEDOWNPRESS://长按下一页
  5427. break;
  5428. }
  5429. }));
  5430. }
  5431. #endregion
  5432. /// <summary>
  5433. /// 更新设备状态显示
  5434. /// </summary>
  5435. public void UpdateDevStatus()
  5436. {
  5437. if (APP.BoardStatus && (APP.PenStatus || APP.TQLPenStatus))
  5438. {
  5439. Dispatcher.Invoke(new Action(() =>
  5440. {
  5441. txbNotConnected.Text = "笔/板";
  5442. txbNotConnecteds.Text = "笔/板";
  5443. }));
  5444. }
  5445. else if (APP.BoardStatus)
  5446. {
  5447. Dispatcher.Invoke(new Action(() =>
  5448. {
  5449. txbNotConnected.Text = "手写板";
  5450. txbNotConnecteds.Text = "手写板";
  5451. }));
  5452. }
  5453. else if (APP.PenStatus)
  5454. {
  5455. Dispatcher.Invoke(new Action(() =>
  5456. {
  5457. txbNotConnected.Text = "智能笔";
  5458. txbNotConnecteds.Text = "智能笔";
  5459. }));
  5460. }
  5461. else if (APP.TQLPenStatus)
  5462. {
  5463. Dispatcher.Invoke(new Action(() =>
  5464. {
  5465. txbNotConnected.Text = "点阵笔";
  5466. txbNotConnecteds.Text = "点阵笔";
  5467. }));
  5468. }
  5469. else
  5470. {
  5471. Dispatcher.Invoke(new Action(() =>
  5472. {
  5473. txbNotConnected.Text = "未连接";
  5474. txbNotConnecteds.Text = "未连接";
  5475. }));
  5476. }
  5477. }
  5478. #endregion
  5479. #region 腾千里手写笔
  5480. /// <summary>
  5481. /// 是否在书写
  5482. /// </summary>
  5483. bool isTQLPenDown = false;
  5484. /// <summary>
  5485. /// TQL点阵笔宽高
  5486. /// </summary>
  5487. static float TQLA4_WIDTH = (float)2480 / (float)300 * (float)25.4 / (float)1.524; //(float)1075 / (float)150 * (float)25.4 / (float)1.524; //OID4
  5488. static float TQLA4_HEIGHT = (float)3509 / (float)300 * (float)25.4 / (float)1.524;//(float)1512 / (float)150 * (float)25.4 / (float)1.524;
  5489. /// <summary>
  5490. /// TQL初始化
  5491. /// </summary>
  5492. public void InitTQLPPen()
  5493. {
  5494. if (APP.TQLPenevents == null)
  5495. {
  5496. APP.TQLPenevents = new PenEvents(1);
  5497. }
  5498. else
  5499. {
  5500. APP.TQLPenevents.InToType = 1;
  5501. }
  5502. }
  5503. /// <summary>
  5504. /// 笔落下
  5505. /// </summary>
  5506. public void TQLDown()
  5507. {
  5508. isTQLPenDown = true;
  5509. if (APP.pageData.currpage > 0)
  5510. {
  5511. Dispatcher.Invoke(new Action(() =>
  5512. {
  5513. myblackboard.changepages(0, 0, true, Color, PenSize, APP.pageData.currpage - 1, 0);
  5514. }));
  5515. }
  5516. }
  5517. /// <summary>
  5518. /// 笔抬起
  5519. /// </summary>
  5520. public void TQLUp()
  5521. {
  5522. isTQLPenDown = false;
  5523. //stroke.Clear();
  5524. if (APP.pageData.currpage > 0)
  5525. {
  5526. Dispatcher.Invoke(new Action(() =>
  5527. {
  5528. myblackboard.changepages(0, 0, true, Color, PenSize, APP.pageData.currpage - 1, 0);
  5529. }));
  5530. }
  5531. }
  5532. /// <summary>
  5533. /// 笔书写
  5534. /// </summary>
  5535. /// <param name="cx"></param>
  5536. /// <param name="cy"></param>
  5537. /// <param name="force"></param>
  5538. public void TQLPenWrite(double cx, double cy, int force)
  5539. {
  5540. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  5541. if (!isTQLPenDown)
  5542. {
  5543. return;
  5544. }
  5545. double PropW = blackboard_canvas.ActualWidth / TQLA4_WIDTH;
  5546. double PropH = blackboard_canvas.ActualHeight / TQLA4_HEIGHT;
  5547. //点
  5548. double tempX = cx * PropW;
  5549. double tempY = cy * PropH;
  5550. if (APP.pageData.currpage > 0)
  5551. {
  5552. Dispatcher.Invoke(new Action(() =>
  5553. {
  5554. //0~1023,亦即有 1024 阶供应用软件后续应用之用,如笔锋笔触,暂无用
  5555. float Pressure = (float)force / 1023f;
  5556. myblackboard.changepages(tempX, tempY, false, Color, PenSize, APP.pageData.currpage - 1, Pressure);
  5557. #region 设置滚动条位置
  5558. //点在显示页面上方
  5559. if (tempY < scroMain.VerticalOffset)
  5560. {
  5561. //滚动条当前位置
  5562. double RollCurrentLocation = scroMain.VerticalOffset;
  5563. //向上滚动至以点为中心需要滚动的距离
  5564. double UpRoll = (RollCurrentLocation - tempY) + (scroMain.ActualHeight / 2);
  5565. //如果小于0则等于0
  5566. double RollLocation = RollCurrentLocation - UpRoll;
  5567. if (RollLocation < 0)
  5568. {
  5569. RollLocation = 0;
  5570. }
  5571. ////滚动条实际偏移量
  5572. //double RollOffset = RollCurrentLocation - RollLocation;
  5573. scroMain.ScrollToVerticalOffset(RollLocation);
  5574. }
  5575. //点在显示页面下方
  5576. if (tempY > scroMain.VerticalOffset + scroMain.ActualHeight)
  5577. {
  5578. //滚动条当前位置
  5579. double RollCurrentLocation = scroMain.VerticalOffset;
  5580. //向下滚动至以点为中心需要滚动的距离
  5581. double DownRoll = (tempY - RollCurrentLocation) - (scroMain.ActualHeight / 2);
  5582. //如果小于0则等于0
  5583. double RollLocation = RollCurrentLocation + DownRoll;
  5584. //滚动条最大滚动值
  5585. double ScrollbarMaxNum = gridM.ActualHeight - scroMain.ActualHeight;
  5586. if (RollLocation > ScrollbarMaxNum)
  5587. {
  5588. RollLocation = ScrollbarMaxNum;
  5589. }
  5590. ////滚动条实际偏移量
  5591. //double RollOffset = RollLocation-RollCurrentLocation;
  5592. scroMain.ScrollToVerticalOffset(RollLocation);
  5593. }
  5594. #endregion
  5595. if (tempX > 0 && tempY > 0)
  5596. {
  5597. System.Windows.Point getP = scroMain.PointToScreen(new System.Windows.Point(tempX, tempY - scroMain.VerticalOffset));
  5598. SetCursorPos((int)getP.X, (int)getP.Y);
  5599. }
  5600. }));
  5601. }
  5602. }
  5603. #endregion
  5604. #region 图片拉伸移动
  5605. private System.Windows.Point initialPoint;
  5606. /// <summary>
  5607. /// 隐藏图片四个点和线
  5608. /// </summary>
  5609. private void HideAngleBorder()
  5610. {
  5611. RectLeftUp.Visibility = Visibility.Hidden;
  5612. RectRightUp.Visibility = Visibility.Hidden;
  5613. RectLeftDown.Visibility = Visibility.Hidden;
  5614. RectRightDown.Visibility = Visibility.Hidden;
  5615. RectImgBorder.Visibility = Visibility.Hidden;
  5616. }
  5617. private void ShowAngleBorder()
  5618. {
  5619. PointLocation();
  5620. RectLeftUp.Visibility = Visibility.Visible;
  5621. RectRightUp.Visibility = Visibility.Visible;
  5622. RectLeftDown.Visibility = Visibility.Visible;
  5623. RectRightDown.Visibility = Visibility.Visible;
  5624. RectImgBorder.Visibility = Visibility.Visible;
  5625. }
  5626. /// <summary>
  5627. /// 确定四个点和边框的位置大小
  5628. /// </summary>
  5629. private void PointLocation()
  5630. {
  5631. RectImgBorder.Width = imgCanvas.ActualWidth + 10.0;
  5632. RectImgBorder.Height = imgCanvas.ActualHeight + 10.0;
  5633. RectImgBorder.Margin = new Thickness(imgCanvas.Margin.Left - 5.0, imgCanvas.Margin.Top - 5.0, 0, 0);
  5634. Canvas.SetLeft(RectLeftUp, imgCanvas.Margin.Left - 10.0);
  5635. Canvas.SetTop(RectLeftUp, imgCanvas.Margin.Top - 10.0);
  5636. Canvas.SetLeft(RectRightUp, imgCanvas.Margin.Left + imgCanvas.ActualWidth - 10.0);
  5637. Canvas.SetTop(RectRightUp, imgCanvas.Margin.Top - 10.0);
  5638. Canvas.SetLeft(RectLeftDown, imgCanvas.Margin.Left - 10.0);
  5639. Canvas.SetTop(RectLeftDown, imgCanvas.Margin.Top + imgCanvas.ActualHeight - 10.0);
  5640. Canvas.SetLeft(RectRightDown, imgCanvas.Margin.Left + imgCanvas.ActualWidth - 10.0);
  5641. Canvas.SetTop(RectRightDown, imgCanvas.Margin.Top + imgCanvas.ActualHeight - 10.0);
  5642. }
  5643. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  5644. {
  5645. System.Windows.Point point = e.GetPosition(imgCanvas);
  5646. initialPoint = point;
  5647. //Console.WriteLine("PicEmap.X = " + point.X + "; PicEmap.Y = " + point.Y);
  5648. //if ((point.X - 304) * (point.X - 304) + (point.Y - 86) * (point.Y - 86) < 100)
  5649. //{
  5650. // Console.WriteLine("在范围内");
  5651. //}
  5652. HideAngleBorder();
  5653. }
  5654. private void imgCanvas_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  5655. {
  5656. if (e.LeftButton == MouseButtonState.Pressed && mouseDown)
  5657. {
  5658. System.Windows.Point point = e.GetPosition(imgCanvas);
  5659. imgCanvas.Margin = new Thickness(imgCanvas.Margin.Left + (point.X - initialPoint.X), imgCanvas.Margin.Top + (point.Y - initialPoint.Y), 0, 0);
  5660. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  5661. {
  5662. X = imgCanvas.Margin.Left,
  5663. Y = imgCanvas.Margin.Top
  5664. };
  5665. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  5666. {
  5667. CenterX = imgCanvas.ActualWidth,
  5668. CenterY = imgCanvas.ActualHeight
  5669. };
  5670. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  5671. }
  5672. }
  5673. private void imgCanvas_MouseUp(object sender, MouseButtonEventArgs e)
  5674. {
  5675. if (mouseDown)
  5676. {
  5677. ShowAngleBorder();
  5678. }
  5679. }
  5680. private System.Drawing.PointF imgRightDown;
  5681. /// <summary>
  5682. /// 设置控件最上层
  5683. /// </summary>
  5684. /// <param name="element"></param>
  5685. public void BringToFront(Thumb element)//图片置于最顶层显示
  5686. {
  5687. if (element == null)
  5688. {
  5689. return;
  5690. }
  5691. Canvas parent = element.Parent as Canvas;
  5692. if (parent == null)
  5693. {
  5694. return;
  5695. }
  5696. int maxZ = parent.Children.OfType<UIElement>()//linq语句,取Zindex的最大值
  5697. .Where(x => x != element)
  5698. .Select(x => Canvas.GetZIndex(x))
  5699. .Max();
  5700. Canvas.SetZIndex(element, maxZ + 1);
  5701. }
  5702. private void RectRightUp_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
  5703. {
  5704. try
  5705. {
  5706. Thumb thu = (Thumb)sender;
  5707. BringToFront(thu);
  5708. imgRightDown = new System.Drawing.PointF((float)(imgCanvas.Margin.Left + imgCanvas.ActualWidth), (float)(imgCanvas.Margin.Top + imgCanvas.ActualHeight));
  5709. HideAngleBorder();
  5710. switch (thu.Name)
  5711. {
  5712. case "RectLeftUp":
  5713. RectLeftUp.Visibility = Visibility.Visible;
  5714. break;
  5715. case "RectRightUp":
  5716. RectRightUp.Visibility = Visibility.Visible;
  5717. break;
  5718. case "RectLeftDown":
  5719. RectLeftDown.Visibility = Visibility.Visible;
  5720. break;
  5721. case "RectRightDown":
  5722. RectRightDown.Visibility = Visibility.Visible;
  5723. break;
  5724. default:
  5725. break;
  5726. }
  5727. }
  5728. catch (Exception ex)
  5729. {
  5730. MessageWindow.Show(ex.Message);
  5731. }
  5732. }
  5733. private void RectRightUp_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
  5734. {
  5735. try
  5736. {
  5737. if (mouseDown)
  5738. {
  5739. Thumb thu = (Thumb)sender;
  5740. #region 判断是否超出 暂无
  5741. double plul = Canvas.GetLeft(RectLeftUp);
  5742. double plut = Canvas.GetTop(RectLeftUp);
  5743. double prdl = Canvas.GetLeft(RectRightDown);
  5744. double prdt = Canvas.GetTop(RectRightDown);
  5745. #endregion
  5746. //Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  5747. //Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  5748. double imgW = 0;
  5749. double imgH = 0;
  5750. double imgX = 0;
  5751. double imgY = 0;
  5752. switch (thu.Name)
  5753. {
  5754. case "RectLeftUp":
  5755. #region 左上
  5756. imgW = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  5757. imgH = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  5758. imgX = 0;
  5759. imgY = 0;
  5760. if (imgW < 50)
  5761. {
  5762. imgCanvas.Width = 50;
  5763. imgX = imgCanvas.Margin.Left;
  5764. Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
  5765. }
  5766. else
  5767. {
  5768. imgCanvas.Width = imgW;
  5769. imgX = Mouse.GetPosition(gridM).X;
  5770. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  5771. }
  5772. if (imgH < 50)
  5773. {
  5774. imgCanvas.Height = 50;
  5775. imgY = imgCanvas.Margin.Top;
  5776. Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
  5777. }
  5778. else
  5779. {
  5780. imgCanvas.Height = imgH;
  5781. imgY = Mouse.GetPosition(gridM).Y;
  5782. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  5783. }
  5784. imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  5785. #endregion
  5786. //imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  5787. //imgCanvas.Height = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  5788. //imgCanvas.Margin = new Thickness(Mouse.GetPosition(gridM).X, Mouse.GetPosition(gridM).Y, 0, 0);
  5789. break;
  5790. case "RectRightUp":
  5791. #region 右上
  5792. imgW = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
  5793. imgH = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  5794. imgX = 0;
  5795. imgY = 0;
  5796. if (imgW < 50)
  5797. {
  5798. imgCanvas.Width = 50;
  5799. imgX = imgCanvas.Margin.Left;
  5800. Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
  5801. }
  5802. else
  5803. {
  5804. imgCanvas.Width = imgW;
  5805. imgX = imgCanvas.Margin.Left;
  5806. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  5807. }
  5808. if (imgH < 50)
  5809. {
  5810. imgCanvas.Height = 50;
  5811. imgY = imgCanvas.Margin.Top;
  5812. Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
  5813. }
  5814. else
  5815. {
  5816. imgCanvas.Height = imgH;
  5817. imgY = Mouse.GetPosition(gridM).Y;
  5818. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  5819. }
  5820. imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  5821. //imgCanvas.Width = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
  5822. //imgCanvas.Height = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  5823. //imgCanvas.Margin = new Thickness(imgCanvas.Margin.Left, Mouse.GetPosition(gridM).Y, 0, 0);
  5824. #endregion
  5825. break;
  5826. case "RectLeftDown":
  5827. #region 左下
  5828. imgW = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  5829. imgH = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
  5830. imgX = 0;
  5831. imgY = 0;
  5832. if (imgW < 50)
  5833. {
  5834. imgCanvas.Width = 50;
  5835. imgX = imgCanvas.Margin.Left;
  5836. Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
  5837. }
  5838. else
  5839. {
  5840. imgCanvas.Width = imgW;
  5841. imgX = Mouse.GetPosition(gridM).X;
  5842. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  5843. }
  5844. if (imgH < 50)
  5845. {
  5846. imgCanvas.Height = 50;
  5847. imgY = imgCanvas.Margin.Top;
  5848. Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
  5849. }
  5850. else
  5851. {
  5852. imgCanvas.Height = imgH;
  5853. imgY = imgCanvas.Margin.Top;
  5854. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  5855. }
  5856. imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  5857. //imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  5858. //imgCanvas.Height = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
  5859. //imgCanvas.Margin = new Thickness(Mouse.GetPosition(gridM).X, imgCanvas.Margin.Top, 0, 0);
  5860. #endregion
  5861. break;
  5862. case "RectRightDown":
  5863. #region 右下
  5864. imgW = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
  5865. imgH = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
  5866. if (imgW < 50)
  5867. {
  5868. imgCanvas.Width = 50;
  5869. Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
  5870. }
  5871. else
  5872. {
  5873. imgCanvas.Width = imgW;
  5874. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  5875. }
  5876. if (imgH < 50)
  5877. {
  5878. imgCanvas.Height = 50;
  5879. Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
  5880. }
  5881. else
  5882. {
  5883. imgCanvas.Height = imgH;
  5884. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  5885. }
  5886. //imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  5887. //imgCanvas.Width += e.HorizontalChange;
  5888. //imgCanvas.Height += e.VerticalChange;
  5889. #endregion
  5890. break;
  5891. default:
  5892. break;
  5893. }
  5894. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  5895. {
  5896. X = imgCanvas.Margin.Left,
  5897. Y = imgCanvas.Margin.Top
  5898. };
  5899. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  5900. {
  5901. CenterX = imgCanvas.ActualWidth,
  5902. CenterY = imgCanvas.ActualHeight
  5903. };
  5904. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  5905. }
  5906. //lbl1.Content = imgCanvas.Margin.Left + "," + imgCanvas.Margin.Top;
  5907. //lbl2.Content = (imgCanvas.Margin.Left+ imgCanvas.Width) +"," + imgCanvas.Margin.Top;
  5908. //lbl3.Content = imgCanvas.Margin.Left + "," + (imgCanvas.Margin.Top+ imgCanvas.Height);
  5909. //lbl4.Content= (imgCanvas.Margin.Left + imgCanvas.Width )+ "," + (imgCanvas.Margin.Top + imgCanvas.Height);
  5910. }
  5911. catch (Exception)
  5912. {
  5913. MessageWindow.Show("图片过小!");
  5914. }
  5915. }
  5916. private void RectRightUp_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
  5917. {
  5918. ShowAngleBorder();
  5919. }
  5920. /// <summary>
  5921. /// 点击标题栏 隐藏截图的四个点和线
  5922. /// </summary>
  5923. /// <param name="sender"></param>
  5924. /// <param name="e"></param>
  5925. private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
  5926. {
  5927. HideAngleBorder();
  5928. }
  5929. /// <summary>
  5930. /// 鼠标左键点击事件
  5931. /// </summary>
  5932. /// <param name="sender"></param>
  5933. /// <param name="e"></param>
  5934. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  5935. {
  5936. if (RectImgBorder.Visibility != Visibility.Hidden)
  5937. {
  5938. HideAngleBorder();
  5939. }
  5940. }
  5941. #endregion
  5942. #region 方法
  5943. /// <summary>
  5944. /// 录屏 录制 截图 导入文档 增加 主页面显示
  5945. /// </summary>
  5946. private void Record()
  5947. {
  5948. PageHide();
  5949. GridMain.Visibility = Visibility.Visible;
  5950. if (APP.pageData.pagenum > 0)
  5951. {
  5952. gridPage.Visibility = Visibility.Visible;
  5953. }
  5954. DataContext = APP.pageData;
  5955. }
  5956. /// <summary>
  5957. /// 设置页面显示
  5958. /// </summary>
  5959. private void SetUp()
  5960. {
  5961. }
  5962. #endregion
  5963. #region 跳转
  5964. /// <summary>
  5965. /// 跳转
  5966. /// </summary>
  5967. /// <param name="sender"></param>
  5968. /// <param name="e"></param>
  5969. private void CbxPageList_SelectionChanged(object sender, SelectionChangedEventArgs e)
  5970. {
  5971. #region 安全
  5972. if (CbxPageList.SelectedValue == null)
  5973. {
  5974. return;
  5975. }
  5976. if (APP.pageData.currpage == int.Parse(CbxPageList.SelectedValue.ToString()))
  5977. {
  5978. return;
  5979. }
  5980. #endregion
  5981. int JumpPage;
  5982. try
  5983. {
  5984. JumpPage = int.Parse(CbxPageList.SelectedValue.ToString());
  5985. }
  5986. catch (Exception)
  5987. {
  5988. MessageWindow.Show("操作有误!请输入有效的页码!");
  5989. return;
  5990. }
  5991. if (JumpPage < 1)
  5992. {
  5993. JumpPage = 1;
  5994. }
  5995. if (JumpPage > int.Parse(txbTotalpage.Text))
  5996. {
  5997. JumpPage = int.Parse(txbTotalpage.Text);
  5998. }
  5999. #region 跳转
  6000. APP.pageData.currpage = JumpPage;
  6001. JumpPageClick();
  6002. #endregion
  6003. }
  6004. #endregion
  6005. #region 原跳转
  6006. /// <summary>
  6007. /// 跳转页
  6008. /// </summary>
  6009. /// <param name="sender"></param>
  6010. /// <param name="e"></param>
  6011. private void txbCurrpage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  6012. {
  6013. if (e.ClickCount == 2)
  6014. {
  6015. try
  6016. {
  6017. if (int.Parse(txbCurrpage.Text) > 0)
  6018. {
  6019. //txtJump.Text = txbCurrpage.Text;
  6020. //txbCurrpage.Visibility = Visibility.Hidden;
  6021. //txtJump.Visibility = Visibility.Visible;
  6022. //BtnJumpPage.Visibility = Visibility.Visible;
  6023. //txtJump.Focus();
  6024. //txtJump.SelectAll();
  6025. }
  6026. }
  6027. catch (Exception)
  6028. {
  6029. }
  6030. }
  6031. }
  6032. /// <summary>
  6033. /// 确定跳转
  6034. /// </summary>
  6035. /// <param name="sender"></param>
  6036. /// <param name="e"></param>
  6037. private void BtnJumpPage_Click(object sender, RoutedEventArgs e)
  6038. {
  6039. int JumpPage = 0;
  6040. //try
  6041. //{
  6042. // JumpPage = int.Parse(txtJump.Text);
  6043. //}
  6044. //catch (Exception ex)
  6045. //{
  6046. // MessageWindow.Show("操作有误!请输入有效的页码!");
  6047. // return;
  6048. //}
  6049. if (JumpPage < 1)
  6050. {
  6051. JumpPage = 1;
  6052. }
  6053. if (JumpPage > int.Parse(txbTotalpage.Text))
  6054. {
  6055. JumpPage = int.Parse(txbTotalpage.Text);
  6056. }
  6057. #region 跳转
  6058. APP.pageData.currpage = JumpPage;
  6059. JumpPageClick();
  6060. #endregion
  6061. //txbCurrpage.Visibility = Visibility.Visible;
  6062. //txtJump.Visibility = Visibility.Hidden;
  6063. //BtnJumpPage.Visibility = Visibility.Hidden;
  6064. }
  6065. /// <summary>
  6066. /// 只允许输入数字
  6067. /// </summary>
  6068. /// <param name="sender"></param>
  6069. /// <param name="e"></param>
  6070. private void txtJump_PreviewTextInput(object sender, TextCompositionEventArgs e)
  6071. {
  6072. Regex re = new Regex("[^0-9.-]+");
  6073. e.Handled = re.IsMatch(e.Text);
  6074. }
  6075. private void txtJump_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  6076. {
  6077. if (e.Key == Key.Enter)
  6078. {
  6079. BtnJumpPage_Click(null, null);
  6080. }
  6081. }
  6082. #endregion
  6083. #region 打印
  6084. /// <summary>
  6085. /// 下拉框数据源
  6086. /// </summary>
  6087. public DataTable data = new DataTable();
  6088. private DataTable dtComponentsUniqueNo;
  6089. /// <summary>
  6090. /// 打印进度
  6091. /// </summary>
  6092. private System.Timers.Timer timesPrint;
  6093. /// <summary>
  6094. /// 打印消息
  6095. /// </summary>
  6096. private System.Timers.Timer timesPrintMsg;
  6097. private double wit = 0;
  6098. private double hei = 0;
  6099. /// <summary>
  6100. /// 打印状态消息
  6101. /// </summary>
  6102. string PrintMsg = "打印中";
  6103. /// <summary>
  6104. /// 打印初始化
  6105. /// </summary>
  6106. public void InitPrint()
  6107. {
  6108. ResizeMode = ResizeMode.NoResize;
  6109. List<string> defaList = LatticeFileHelper.GetPrinterList(out string defa);
  6110. if (defaList.Count > 0)
  6111. {
  6112. data.Columns.Add("Value");
  6113. data.Columns.Add("Key");
  6114. for (int i = 0; i < defaList.Count; i++)
  6115. {
  6116. //创建一行
  6117. DataRow row = data.NewRow();
  6118. //将此行添加到table中
  6119. data.Rows.Add(row);
  6120. data.Rows[i]["Value"] = defaList[i];
  6121. data.Rows[i]["Key"] = i.ToString();
  6122. }
  6123. dtComponentsUniqueNo = data.DefaultView.ToTable();
  6124. cmbClass.ItemsSource = dtComponentsUniqueNo.DefaultView;
  6125. cmbClass.SelectedIndex = 0;
  6126. }
  6127. Dictionary<int, int> dicItem = new Dictionary<int, int>();
  6128. dicItem.Add(0, 600);
  6129. dicItem.Add(1, 1200);
  6130. CbxDpi.ItemsSource = dicItem;
  6131. CbxDpi.SelectedIndex = 0;
  6132. Dictionary<int, string> dictypeItem = new Dictionary<int, string>();
  6133. dictypeItem.Add(0, "2x2");
  6134. dictypeItem.Add(1, "3x3");
  6135. dictypeItem.Add(2, "4x4");
  6136. CbxType.ItemsSource = dictypeItem;
  6137. CbxType.SelectedIndex = 0;
  6138. TQLInit();
  6139. }
  6140. /// <summary>
  6141. /// 初始化页面
  6142. /// </summary>
  6143. /// <param name="_imgPath"></param>
  6144. /// <param name="_wit"></param>
  6145. /// <param name="_hei"></param>
  6146. public void InitializePrint(string _imgPath, double _wit, double _hei)
  6147. {
  6148. wit = _wit;
  6149. hei = _hei;
  6150. if (!string.IsNullOrWhiteSpace(_imgPath))
  6151. {
  6152. imgPri.Source = new BitmapImage(new Uri(_imgPath));
  6153. }
  6154. else
  6155. {
  6156. imgPri.Source = null;
  6157. }
  6158. GridPrintMask.Visibility = Visibility.Collapsed;
  6159. }
  6160. #region TQL打印
  6161. /// <summary>
  6162. /// 授权文件位置
  6163. /// </summary>
  6164. string TQLAuthorizationPath;
  6165. /// <summary>
  6166. /// 授权码
  6167. /// </summary>
  6168. string gKeyStr;
  6169. TmatrixClass TMC = new TmatrixClass();
  6170. public static string gPrintFileName;
  6171. //string gDirectory = Application.StartupPath;
  6172. //string gFileName = "";
  6173. bool gbInitDone = false;
  6174. //string gUserName = "";
  6175. //string gPassword = "";
  6176. //private string gEKeyStr;
  6177. iTextSharp.text.Document document;
  6178. enum TMATRIX_POINT_TYPE
  6179. {
  6180. TmatrixPointType_2x2 = 0, // 2x2 Point Type
  6181. TmatrixPointType_3x3 = 1, // 3x3 Point Type
  6182. };
  6183. enum TMATRIX_OBJECT_TYPE
  6184. {
  6185. TMATRIX_OT_ElementCode = 0, // 此类型对象的Index范围是:75497472~83886079(十六进制为:0x04800000~0x04ffffff)
  6186. TMATRIX_OT_PositionCode, // 此类型对象没有Index
  6187. };
  6188. /// <summary>
  6189. /// TQL初始化打印
  6190. /// </summary>
  6191. void TQLInit()
  6192. {
  6193. ///初始化
  6194. if (TMC.TmatrixInitialize() == false)
  6195. {
  6196. //MessageBox.Show(this, "点阵码初始化失败!", "生成点阵码", MessageBoxButtons.OK, MessageBoxIcon.Error);
  6197. //Close();
  6198. }
  6199. else
  6200. {
  6201. gbInitDone = true;
  6202. }
  6203. document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0);
  6204. try
  6205. {
  6206. TQLAuthorizationPath = FileToolsCommon.GetFileAbsolutePath("/LatticeXML/S0_O000_B0000_P000-255.tmx");
  6207. StreamReader gsr = new StreamReader(TQLAuthorizationPath);
  6208. gKeyStr = gsr.ReadLine();
  6209. gsr.Close();
  6210. string KeyCheckResult = TMC.TmatrixKeyCheck_OID4(gKeyStr);
  6211. if (KeyCheckResult.Substring(0, 1) == "1")
  6212. {
  6213. MessageWindow.Show("打印服务授权过期,请联系厂家更换授权!");
  6214. LogHelper.WriteErrLog("打印服务授权过期:" + KeyCheckResult, null);
  6215. gbInitDone = false;
  6216. }
  6217. else if (KeyCheckResult.Substring(0, 1) == "0")
  6218. {
  6219. }
  6220. }
  6221. catch (Exception ex)
  6222. {
  6223. LogHelper.WriteErrLog("打印服务授权失败:" + ex.Message, ex);
  6224. MessageWindow.Show("打印服务授权失败,请联系厂家!");
  6225. gbInitDone = false;
  6226. }
  6227. }
  6228. /// <summary>
  6229. /// 铺码
  6230. /// </summary>
  6231. private bool GenerateCode(string PDFPath)
  6232. {
  6233. try
  6234. {
  6235. if (gbInitDone == false)
  6236. {
  6237. MessageWindow.Show("打印功能无法使用,无效授权。");
  6238. return false;
  6239. }
  6240. try
  6241. {
  6242. string directoryPath = FileToolsCommon.GetDirectoryName(PDFPath);
  6243. FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Images/");
  6244. FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Vector Images/");
  6245. FileToolsCommon.DeleteDirectory(directoryPath + "Bg without Vector Images/");
  6246. FileToolsCommon.DeleteDirectory(directoryPath + "Vector Images/");
  6247. }
  6248. catch (Exception)
  6249. {
  6250. }
  6251. int i;
  6252. for (i = 0; i < 4; i++)
  6253. {
  6254. int DPIValue = 0;
  6255. int TypeValue = 0;
  6256. try
  6257. {
  6258. DPIValue = CbxDpi.SelectedIndex;
  6259. //TypeValue = CbxType.SelectedIndex;
  6260. }
  6261. catch (Exception)
  6262. {
  6263. }
  6264. APP.gPointType[i] = TypeValue;
  6265. APP.gPointDPI[i] = DPIValue;
  6266. }
  6267. APP.gbGenerateBGWithVImage = false;
  6268. APP.gbGenerateVImage = false;
  6269. APP.gbGenerateBGWithoutVImage = false;
  6270. APP.gbGenerateBGWithImage = true;
  6271. //初始页
  6272. int SPID = 0;
  6273. //int PointType = (int)(TMATRIX_POINT_TYPE.TmatrixPointType_3x3);
  6274. //string sGenerateResult = TMC.GenerateTmatrixCode(gKeyStr, PDFFileName, SPID, PointType, GlobalClass.gbGenerateBGWithVImage, GlobalClass.gbGenerateVImage, GlobalClass.gbGenerateBGWithoutVImage, GlobalClass.gbGenerateBGWithImage);
  6275. bool[] bPublishImageType = new bool[4];
  6276. bPublishImageType[0] = APP.gbGenerateBGWithVImage;
  6277. bPublishImageType[1] = APP.gbGenerateVImage;
  6278. bPublishImageType[2] = APP.gbGenerateBGWithoutVImage;
  6279. bPublishImageType[3] = APP.gbGenerateBGWithImage;
  6280. PDFPath = PDFPath.Replace("/", "\\");
  6281. string sGenerateResult = TMC.GenerateTmatrixCode_OID4(gKeyStr, PDFPath, SPID, APP.gPointType, bPublishImageType, APP.gPointDPI);
  6282. if (sGenerateResult.Substring(0, 1) == "1")
  6283. {
  6284. Dispatcher.Invoke(() =>
  6285. {
  6286. MessageWindow.Show("打印功能无法使用,无效授权。");
  6287. });
  6288. return false;
  6289. }
  6290. else if (sGenerateResult.Substring(0, 1) == "0")
  6291. {
  6292. //生成成功
  6293. //打印
  6294. //Dispatcher.Invoke(() =>
  6295. //{
  6296. //});
  6297. }
  6298. return true;
  6299. }
  6300. catch (Exception ex)
  6301. {
  6302. Dispatcher.Invoke(() =>
  6303. {
  6304. MessageWindow.Show("打印失败:" + ex.Message);
  6305. });
  6306. return false;
  6307. }
  6308. }
  6309. #endregion
  6310. /// <summary>
  6311. /// 打印
  6312. /// </summary>
  6313. /// <param name="sender"></param>
  6314. /// <param name="e"></param>
  6315. private void BtnPrint_Print_Click(object sender, RoutedEventArgs e)
  6316. {
  6317. if (string.IsNullOrWhiteSpace(cmbClass.Text))
  6318. {
  6319. MessageWindow.Show("请设置打印机!");
  6320. return;
  6321. }
  6322. btnPrint.IsEnabled = false;
  6323. Thread myThread = new Thread(StartPrint);
  6324. List<string> StrList = new List<string>();
  6325. int ipdf = 102;
  6326. string imgPath = FileToolsCommon.GetFileAbsolutePath("temp/");
  6327. string tempImgPath = imgPath;
  6328. imgPath += "101.pdf";
  6329. while (File.Exists(imgPath))
  6330. {
  6331. imgPath = tempImgPath + ipdf.ToString() + ".pdf";
  6332. ipdf++;
  6333. }
  6334. StrList.Add(imgPath);
  6335. //打印数量
  6336. int PrinterNum = Convert.ToInt32(txbNumberOfCopies.Text);
  6337. StrList.Add(PrinterNum.ToString());
  6338. //打印机名称
  6339. string PrinterName = cmbClass.Text;
  6340. StrList.Add(PrinterName);
  6341. PrintMsg = "准备中";
  6342. msgnum = 0;
  6343. num = 0;
  6344. GridPrintMask.Visibility = Visibility.Visible;
  6345. myThread.Start(StrList);
  6346. timesPrint = new System.Timers.Timer(100);
  6347. timesPrint.Elapsed += Times_ElapsedClick;
  6348. timesPrint.Start();
  6349. timesPrintMsg = new System.Timers.Timer(500);
  6350. timesPrintMsg.Elapsed += TimesPrintMsg_Elapsed;
  6351. timesPrintMsg.Start();
  6352. }
  6353. int msgnum = 0;
  6354. /// <summary>
  6355. /// 消息
  6356. /// </summary>
  6357. /// <param name="sender"></param>
  6358. /// <param name="e"></param>
  6359. private void TimesPrintMsg_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  6360. {
  6361. if (msgnum > 5)
  6362. msgnum = 0;
  6363. else
  6364. msgnum++;
  6365. string point = "";
  6366. point = point.ToString().PadRight(msgnum, '.');
  6367. Dispatcher.Invoke(() =>
  6368. {
  6369. LabPrintMessage.Content = PrintMsg + point;
  6370. });
  6371. }
  6372. private int num = 0;
  6373. /// <summary>
  6374. /// 计时器
  6375. /// </summary>
  6376. /// <param name="sender"></param>
  6377. /// <param name="e"></param>
  6378. private void Times_ElapsedClick(object sender, System.Timers.ElapsedEventArgs e)
  6379. {
  6380. Dispatcher.Invoke(() =>
  6381. {
  6382. pgbProcess.Value = num;
  6383. lbProcess.Content = num.ToString() + "%";
  6384. if (num < 99)
  6385. {
  6386. num++;
  6387. timesPrint.Interval += (num / 2);
  6388. }
  6389. else
  6390. {
  6391. timesPrint.Stop();
  6392. }
  6393. });
  6394. }
  6395. /// <summary>
  6396. /// 开始打印
  6397. /// </summary>
  6398. private void StartPrint(object obj)
  6399. {
  6400. try
  6401. {
  6402. document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0f, 0f, 0f, 0f);
  6403. PrintMsg = "生成文件";
  6404. msgnum = 0;
  6405. List<string> objStr1 = (List<string>)obj;
  6406. string SourcePath1 = objStr1[0];
  6407. try
  6408. {
  6409. SourcePath1 = SourcePath1.Replace("/", "\\");
  6410. FileStream fs = new FileStream(SourcePath1, FileMode.Create, FileAccess.ReadWrite);
  6411. document.AddAuthor("星火微课");//作者
  6412. document.AddCreationDate();//创建时候
  6413. document.AddCreator("星火微课");//创建者
  6414. document.AddSubject("点阵文件");//主题
  6415. document.AddTitle("PrintTmatrixCode");//标题
  6416. document.AddKeywords("Print");
  6417. document.AddHeader("TmatrixCode", "0");
  6418. Thread.Sleep(300);
  6419. iTextSharp.text.pdf.PdfWriter.GetInstance(document, fs);
  6420. }
  6421. catch (Exception)
  6422. {
  6423. }
  6424. document.Open();
  6425. iTextSharp.text.Image image;
  6426. for (int i = 0; i < APP.PageDrawList.Count; i++)
  6427. {
  6428. long ii = Timestamp();
  6429. string directoryPath = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  6430. string filePathOutPut = Path.Combine(directoryPath, string.Format("print{0}{1}.jpg", ii, i));
  6431. RectangleF rectangleFs = new RectangleF();
  6432. MergerPrintImg("", filePathOutPut, rectangleFs, out string errmsg);
  6433. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  6434. if (string.IsNullOrEmpty(APP.PageDrawList[i].PageImagePath))//没有图片
  6435. {
  6436. }
  6437. else if (APP.PageDrawList[i].ImgDocumentation == true && !APP.PageDrawList[i].Type.Equals("ppt"))
  6438. {
  6439. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  6440. }
  6441. else
  6442. {
  6443. RectangleF rectangleF = new RectangleF(0, 0, 0, 0);
  6444. Dispatcher.Invoke(() =>
  6445. {
  6446. rectangleF = new RectangleF
  6447. {
  6448. Width = (float)APP.PageDrawList[i].ImageSizes.CenterX,
  6449. Height = (float)APP.PageDrawList[i].ImageSizes.CenterY,
  6450. X = (float)APP.PageDrawList[i].ImageLocation.X,
  6451. Y = (float)APP.PageDrawList[i].ImageLocation.Y
  6452. };
  6453. });
  6454. string msgs = string.Empty;
  6455. bool isImg = MergerPrintImg(APP.PageDrawList[i].PageImagePath, filePathOutPut, rectangleF, out msgs);
  6456. if (isImg)
  6457. {
  6458. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  6459. }
  6460. else
  6461. {
  6462. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  6463. }
  6464. }
  6465. if (image.Height > iTextSharp.text.PageSize.A4.Height)
  6466. {
  6467. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  6468. }
  6469. else if (image.Width > iTextSharp.text.PageSize.A4.Width)
  6470. {
  6471. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  6472. }
  6473. image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
  6474. document.NewPage();
  6475. document.Add(image);
  6476. //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
  6477. //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
  6478. //p1.Leading = 150; //行间距
  6479. //document.Add(p1);
  6480. }
  6481. //Console.WriteLine("转换成功!");
  6482. document.Close();
  6483. }
  6484. catch (Exception ex)
  6485. {
  6486. Dispatcher.Invoke(() =>
  6487. {
  6488. btnPrint.IsEnabled = true;
  6489. timesPrint.Stop();
  6490. timesPrintMsg.Stop();
  6491. GridPrintMask.Visibility = Visibility.Collapsed;
  6492. MessageWindow.Show(ex.Message);
  6493. return;
  6494. });
  6495. LogHelper.WriteErrLog("打印转换PDF失败,原因:" + ex.Message, ex);
  6496. }
  6497. List<string> objStr = (List<string>)obj;
  6498. //PDF位置
  6499. string SourcePath = objStr[0];
  6500. int PrinterNum = int.Parse(objStr[1]);
  6501. string PrinterName = objStr[2];
  6502. PrintMsg = "铺码中";
  6503. msgnum = 0;
  6504. Thread.Sleep(500);
  6505. //腾千里生成点阵文件
  6506. if (GenerateCode(SourcePath))
  6507. {
  6508. //打印机名称
  6509. string directoryPath = FileToolsCommon.GetDirectoryName(SourcePath) + "Bg with Images/";
  6510. string[] strs = FileToolsCommon.GetFileNames(directoryPath);
  6511. try
  6512. {
  6513. for (int i = 0; i < strs.Count(); i++)
  6514. {
  6515. timesPrint.Stop();
  6516. PrintMsg = "正在打印第" + (i + 1) + "/" + strs.Count() + "页中";
  6517. msgnum = 0;
  6518. num = 0;
  6519. timesPrint.Interval = 100;
  6520. timesPrint.Start();
  6521. string fileName = strs[i];
  6522. Print(fileName, PrinterName, (short)PrinterNum);
  6523. }
  6524. //foreach (string fileName in strs)
  6525. //{
  6526. // Print(fileName, PrinterName, (short)PrinterNum);
  6527. //}
  6528. }
  6529. catch (Exception ex)
  6530. {
  6531. Dispatcher.Invoke(() =>
  6532. {
  6533. MessageWindow.Show("打印失败:" + ex.Message);
  6534. btnPrint.IsEnabled = true;
  6535. timesPrint.Stop();
  6536. GridPrintMask.Visibility = Visibility.Collapsed;
  6537. return;
  6538. });
  6539. }
  6540. Dispatcher.Invoke(() =>
  6541. {
  6542. btnPrint.IsEnabled = true;
  6543. num = 99;
  6544. timesPrint.Stop();
  6545. pgbProcess.Value = 100;
  6546. lbProcess.Content = "100%";
  6547. GridPrintMask.Visibility = Visibility.Collapsed;
  6548. MessageWindow.Show("已加入打印机队列,打印中。");
  6549. ////打印机名称
  6550. //string directoryPath = FileToolsCommon.GetDirectoryName(SourcePath) + "Bg with Images/";
  6551. //string[] strs = FileToolsCommon.GetFileNames(directoryPath);
  6552. //foreach (string fileName in strs)
  6553. //{
  6554. // pdfPrint(directoryPath, PrinterName);
  6555. //}
  6556. //MessageWindow.Show("生成点阵文件成功!");
  6557. //string TPFPath = FileToolsCommon.GetFileAbsolutePath("temp/");
  6558. //FileToolsCommon.CreateDirectory(TPFPath);
  6559. });
  6560. }
  6561. else
  6562. {
  6563. Dispatcher.Invoke(() =>
  6564. {
  6565. btnPrint.IsEnabled = true;
  6566. timesPrint.Stop();
  6567. timesPrintMsg.Stop();
  6568. GridPrintMask.Visibility = Visibility.Collapsed;
  6569. return;
  6570. });
  6571. }
  6572. #region 拓思德生成点阵文件
  6573. ////TPF文件位置
  6574. //string TPFPath = FileToolsCommon.GetFileAbsolutePath("temp/");
  6575. //FileToolsCommon.CreateDirectory(TPFPath);
  6576. //TPFPath += "101.TPF";
  6577. ////生成点阵文件
  6578. //LatticeFileHelper.GeneratingPDF(SourcePath, TPFPath, out int pr, out string msg, out string outPut/*, pyte*/);
  6579. //while (!FileToolsCommon.IsExistFile(TPFPath))
  6580. //{
  6581. // Thread.Sleep(100);
  6582. //}
  6583. //while (string.IsNullOrWhiteSpace(pr.ToString()))
  6584. //{
  6585. // Thread.Sleep(100);
  6586. //}
  6587. //Thread.Sleep(1000);
  6588. #endregion
  6589. #region 拓思德打印
  6590. ////打印
  6591. //LatticeFileHelper.PrinterTPFFile(TPFPath, PrinterNum, PrinterName, out int printResult, out string standardError, out string standardOutput);
  6592. //if (printResult == 0)
  6593. //{
  6594. // Dispatcher.Invoke(() =>
  6595. // {
  6596. // btnClose.IsEnabled = true;
  6597. // btnPrint.IsEnabled = true;
  6598. // num = 99;
  6599. // timesPrint.Stop();
  6600. // pgbProcess.Value = 100;
  6601. // lbProcess.Content = "100%";
  6602. // MessageWindow.Show("打印成功!");
  6603. // GridPrintMask.Visibility = Visibility.Collapsed;
  6604. // });
  6605. //}
  6606. //else
  6607. //{
  6608. // Dispatcher.Invoke(() =>
  6609. // {
  6610. // btnClose.IsEnabled = true;
  6611. // btnPrint.IsEnabled = true;
  6612. // timesPrint.Stop();
  6613. // GridPrintMask.Visibility = Visibility.Collapsed;
  6614. // MessageWindow.Show(standardError);
  6615. // });
  6616. //}
  6617. #endregion
  6618. }
  6619. /// <summary>
  6620. /// 调用打印机打印
  6621. /// </summary>
  6622. /// <param name="PDFPath">PDF文件路径</param>
  6623. /// <param name="PrinterName">打印机名称</param>
  6624. void Print(string PDFPath, string PrinterName, short PrinterNum = 1)
  6625. {
  6626. //加载PDF文档
  6627. PdfDocument doc = new PdfDocument();
  6628. doc.LoadFromFile(PDFPath);
  6629. //指定打印机
  6630. doc.PrintSettings.PrinterName = PrinterName;
  6631. //静默打印PDF文档
  6632. doc.PrintSettings.PrintController = new StandardPrintController();
  6633. ////设置文档打印页码范围
  6634. //doc.PrintSettings.SelectPageRange(1, 5);
  6635. //打印不连续的页面
  6636. //doc.PrintSettings.SelectSomePages(new int[] { 1, 3, 5, 7 });
  6637. //设置打印份数为2份
  6638. doc.PrintSettings.Copies = PrinterNum;
  6639. //打印PDF文档
  6640. doc.Print();
  6641. }
  6642. /// <summary>
  6643. /// 生成图片
  6644. /// </summary>
  6645. /// <param name="_path">图片地址</param>
  6646. /// <param name="_saveimg">保存位置</param>
  6647. /// <param name="_rectangle">图片位置</param>
  6648. /// <param name="errmsg">错误消息</param>
  6649. /// <returns></returns>
  6650. private bool MergerPrintImg(string _path, string _saveimg, RectangleF _rectangle, out string errmsg)
  6651. {
  6652. errmsg = null;
  6653. try
  6654. {
  6655. Bitmap bitmap = null;
  6656. //创建要显示的图片对象,根据参数的个数设置宽度
  6657. Bitmap backgroudImg = new Bitmap((int)/*gridM.ActualWidth*/wit, (int)/*gridM.ActualHeight*/hei);
  6658. Graphics g = Graphics.FromImage(backgroudImg);
  6659. //清除画布,背景设置为白色
  6660. g.Clear(System.Drawing.Color.White);
  6661. if (!string.IsNullOrWhiteSpace(_path))
  6662. {
  6663. bitmap = ImageHelper.ReadBitmapFile(_path);
  6664. g.DrawImage(bitmap, _rectangle);
  6665. }
  6666. #region 添加箭头
  6667. string Str = "↑";
  6668. SolidBrush mybrush = new SolidBrush(System.Drawing.Color.Black); //设置默认画刷颜色
  6669. System.Drawing.Font myfont = new System.Drawing.Font("黑体", 14); //设置默认字体格式
  6670. g.DrawString(Str, myfont, mybrush, new System.Drawing.Rectangle((int)wit - 50, 20, 50, 50));
  6671. #endregion
  6672. backgroudImg.Save(_saveimg);
  6673. g.Dispose();
  6674. backgroudImg.Dispose();
  6675. if (bitmap != null)
  6676. {
  6677. bitmap.Dispose();
  6678. }
  6679. GC.Collect();
  6680. return true;
  6681. }
  6682. catch (Exception ex)
  6683. {
  6684. errmsg = ex.Message;
  6685. LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
  6686. return false;
  6687. }
  6688. }
  6689. /// <summary>
  6690. /// 减
  6691. /// </summary>
  6692. /// <param name="sender"></param>
  6693. /// <param name="e"></param>
  6694. private void BtnPrintLess_Click(object sender, RoutedEventArgs e)
  6695. {
  6696. int num = Convert.ToInt32(txbNumberOfCopies.Text);
  6697. if (num > 1)
  6698. {
  6699. num--;
  6700. txbNumberOfCopies.Text = num.ToString();
  6701. }
  6702. }
  6703. /// <summary>
  6704. /// 新增
  6705. /// </summary>
  6706. /// <param name="sender"></param>
  6707. /// <param name="e"></param>
  6708. private void BtnPrintAdd_Click(object sender, RoutedEventArgs e)
  6709. {
  6710. int num = Convert.ToInt32(txbNumberOfCopies.Text);
  6711. if (num > 0)
  6712. {
  6713. num++;
  6714. txbNumberOfCopies.Text = num.ToString();
  6715. }
  6716. }
  6717. /// <summary>
  6718. /// 打印说明
  6719. /// </summary>
  6720. /// <param name="sender"></param>
  6721. /// <param name="e"></param>
  6722. private void btnPrintExplain_Click(object sender, RoutedEventArgs e)
  6723. {
  6724. System.Diagnostics.Process.Start(FileToolsCommon.GetFileAbsolutePath("/星火微课点阵码打印及印刷指导手册.docx"));
  6725. }
  6726. #endregion
  6727. #region 设备检测
  6728. /// <summary>
  6729. /// 设备检测
  6730. /// </summary>
  6731. /// <param name="sender"></param>
  6732. /// <param name="e"></param>
  6733. private void btnDevice_Black_Click(object sender, RoutedEventArgs e)
  6734. {
  6735. if (APP.W_DeviceWindow == null)
  6736. {
  6737. APP.W_DeviceWindow = new DeviceWindow();
  6738. APP.W_DeviceWindow.Owner = this;
  6739. }
  6740. APP.W_DeviceWindow.Initialize();
  6741. APP.W_DeviceWindow.ShowDialog();
  6742. }
  6743. #endregion
  6744. }
  6745. public class PageData
  6746. {
  6747. public int PageCode { get; set; }
  6748. public string PageName { get; set; }
  6749. }
  6750. public enum ReportRate
  6751. {
  6752. R_200,
  6753. R_160,
  6754. R_120,
  6755. R_80,
  6756. R_40
  6757. }
  6758. public class RobotPoint
  6759. {
  6760. public int bIndex { get; set; }
  6761. public int bPenStatus { get; set; }
  6762. public float bx { get; set; }
  6763. public float by { get; set; }
  6764. public float bPress { get; set; }
  6765. public float bWidth { get; set; }
  6766. public float bSpeed { get; set; }
  6767. public bool isOptimize { get; set; }
  6768. }
  6769. }