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

XHMicroLessonSystemWindow.xaml.cs 268KB

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