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

XHMicroLessonSystemWindow.xaml.cs 285KB

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