星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XHMicroLessonSystemWindow.xaml.cs 295KB

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