12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322 |
- /****************************************************************/
- /* */
- /* ApplicationDlg.cpp */
- /* */
- /* Implementation of the CDBServerDlg class. */
- /* This class is a part of the Date Server. */
- /* */
- /* Programmed by LYFZ van der Meer */
- /* Copyright LYFZ Software Solutions 2002 */
- /* http://www.LYFZvandermeer.nl */
- /* */
- /* Last updated: 10 july 2002 */
- /* */
- /****************************************************************/
- //在ApplicationDlg.cpp文件中实现主窗口界面的设计。及其主窗口相应控件的功能和参数的映射。 D4F876E2-w78F-22D5-q98A-Y0B0D07B847C
- #include "stdafx.h"
- #include "DBServer.h"
- #include "theDBServer.h"
- #include "DBServerDlg.h"
- //#include "UserAccountsDlg.h"
- //#include "WizardPages.h"
- #include "AboutDlg.h"
- #include <afxpriv.h>
- #include <process.h>
- //#include "Shlwapi.h"
- #include "ClientCenter.h"
- #include "MyLock.h"
- #include "mysqldata.h"
- #include "./helper/ffsco.h"
- //#include <tlhelp32.h>
- #include "ShowPic3.h"
- #include "my32.h"
- #include "SoftKey.h"
- #include "DogTimeOutDlg.h"
- #include "InputAuthDlg.h"
- #include "AdoImplSvr.h"
- #include "CreateSmallPhoto.h"
- #include "PhotoBackupMgr.h"
- #include <WinSvc.h>
- #include "ConnectThread.h"
- #pragma comment(lib, "NETAPI32.LIB ")
- #include "SelYear.h"
- #include "BranchInfo.h"
- using namespace helper_coffs;
- /*********ErrorExit(...)函数头文件************/
- //#include <strsafe.h>
- /***********************************/
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define LIMITCOUNT 1 //历史数据每次转10个 autorun
- extern BOOL g_bSteal;
- extern BOOL g_bConvertHisAll;
- extern CDBServer theApp;
- extern CtheDBServer theServer;
- #define WM_ICON_NOTIFY WM_USER+12
- CDBServerDlg *g_pMainWnd = NULL;
- //#define IPC_CUSTOM_MSG2 _T("{D4F876E2-w78F-22D5-q98A-Y0B0D07B847C}")
- #define IPC_CUSTOM_MSG2 _T("{E4F876E2-Q78F-22D5-C98A-Y0B0D07B847C}")
- UINT g_wmClose = RegisterWindowMessage(IPC_CUSTOM_MSG2);
- //extern BOOL EncryptFile2(BYTE *buffer, DWORD leng, PCHAR szPassword);
- //extern CStringArray g_conniparray;
- CArray<CDatabase*, CDatabase*>g_pHistoryDBarray[200];
- CDatabase *g_pDB[200];
- CConnectThread *g_pThreadPt[200];
- int g_nDBCount = 0;
- /////////////////////////////////////////////////////////////////////////////
- // CDBServerDlg dialog
- #pragma comment(lib, "Shlwapi.lib")
- extern DWORD g_nSendCode;
- extern BOOL g_bReturned;
- static UINT auIDStatusBar[] =
- {
- ID_SEPARATOR,
- ID_INDICATOR_DATA_RECEIVED,
- ID_INDICATOR_DATA_SEND,
- ID_INDICATOR_ONLINELED,
- ID_INDICATOR_OFFLINELED
- };
- /********************************************************************/
- /* */
- /* Function name : CDBServerDlg::CDBServerDlg */
- /* Description : Constructor */
- /* */
- /********************************************************************/
- CDBServerDlg::CDBServerDlg(CWnd* pParent /*=NULL*/): CDialog(CDBServerDlg::IDD, pParent)
- {
- m_hIcon = AfxGetApp()->LoadIcon(IDI_DBServer);
- m_bTerminate = false;
- m_bRunning = false;
- m_hThread = NULL;
- hInst = NULL;
- CString version = _T("Version 1.0");
- g_bAutoRun = AfxGetApp()->GetProfileInt(version, "brun", 0);
- m_hExitCheckSvc = NULL;
- m_hWaitTimeOut = NULL;
- m_hCheckSvcThread = NULL;
- m_bStartCheckSvc = FALSE;
- for (int i = 0; i < 200; i++)
- {
- g_pDB[i] = NULL;
- g_pThreadPt[i] = NULL;
- }
- }
- /********************************************************************/
- /* */
- /* Function name : CDBServerDlg::~CDBServerDlg */
- /* Description : Destructor */
- /* */
- /********************************************************************/
- CDBServerDlg::~CDBServerDlg()
- {
- for (int i = 0; i < 200; i++)
- {
- CDatabase *db = g_pDB[i];
- if (db)
- {
- db->Close();
- delete db;
- }
- for (int j = 0; j < g_pHistoryDBarray[i].GetSize(); j++)
- {
- CDatabase *db = g_pHistoryDBarray[i].ElementAt(j);
- if (db)
- {
- db->Close();
- delete db;
- }
- }
- g_pHistoryDBarray[i].RemoveAll();
- }
- }
- /********************************************************************/
- /* */
- /* Function name : CDBServerDlg::DoDataExchange */
- /* Description : Called by the framework to exchange and validate */
- /* dialog data. */
- /* */
- /********************************************************************/
- void CDBServerDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDBServerDlg)
- DDX_Control(pDX, IDC_INFOBAR, m_InfobarCtrl);
- DDX_Control(pDX, IDC_OUTLOOKBAR, m_OutlookBar);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDBServerDlg, CDialog)
- //{{AFX_MSG_MAP(CDBServerDlg)
- ON_WM_DESTROY()
- ON_COMMAND(ID_SERVER_START, OnServerStart)
- ON_UPDATE_COMMAND_UI(ID_SERVER_START, OnUpdateServerStart)
- ON_COMMAND(ID_SERVER_STOP, OnServerStop)
- ON_UPDATE_COMMAND_UI(ID_SERVER_STOP, OnUpdateServerStop)
- ON_COMMAND(ID_SERVER_EXIT, OnServerExit)
- ON_NOTIFY(NM_CLICK, IDC_OUTLOOKBAR, OnClickOutlookBar)
- ON_NOTIFY(LVN_KEYDOWN, IDC_OUTLOOKBAR, OnKeydownOutlookBar)
- ON_COMMAND(ID_USER_ACCOUNTS, OnUserAccounts)
- ON_WM_CLOSE()
- ON_COMMAND(IDC_VIEW_TRACE, OnViewTrace)
- ON_COMMAND(IDC_VIEW_ONLINE_USERS, OnViewOnlineUsers)
- ON_COMMAND(IDC_VIEW_CONFIGURATION, OnViewConfiguration)
- ON_UPDATE_COMMAND_UI(IDC_VIEW_TRACE, OnUpdateViewTrace)
- ON_UPDATE_COMMAND_UI(IDC_VIEW_ONLINE_USERS, OnUpdateViewOnlineUsers)
- ON_UPDATE_COMMAND_UI(IDC_VIEW_CONFIGURATION, OnUpdateViewConfiguration)
- ON_COMMAND(IDC_VIEW_STATISTICS, OnViewStatistics)
- ON_UPDATE_COMMAND_UI(IDC_VIEW_STATISTICS, OnUpdateViewStatistics)
- ON_COMMAND(IDC_VIEW_SECURITY, OnViewSecurity)
- ON_UPDATE_COMMAND_UI(IDC_VIEW_SECURITY, OnUpdateViewSecurity)
- ON_COMMAND(ID_ACCOUNT_WIZARD, OnAccountWizard)
- ON_WM_TIMER()
- ON_COMMAND(IDM_OPEN, OnOpen)
- ON_COMMAND(IDM_EXIT, OnExit)
- ON_COMMAND(IDM_AUTORUN, OnAutorun)
- ON_COMMAND(IDM_STARTBAKSVC, OnStartBackupSvc)
- ON_COMMAND(IDM_STARTDELSVC, OnStartDelPhotoSvc)
- ON_COMMAND(IDM_STOPBAKSVC, OnStopBackupSvc)
- ON_COMMAND(IDM_STOPDELSVC, OnStopDelPhotoSvc)
- ON_COMMAND(IDM_AUTOCHECKSVC, OnAutoCheckSvc)
- //}}AFX_MSG_MAP
- ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification)
- ON_REGISTERED_MESSAGE(g_wmClose, OnAbortClose)
- END_MESSAGE_MAP()
- LRESULT CDBServerDlg::OnAbortClose(WPARAM wParam, LPARAM lParam)
- {
- if (wParam == 2)
- {
- WriteTextLog("连接失败,服务将重启");
- OnExit2();
- }
- else if (wParam == 3)//更新分店
- {
- LoadBranchInfo();
- }
- return 1;
- }
- BOOL CDBServerDlg::OnInitDialog()
- {
- g_pMainWnd = this;
- CDialog::OnInitDialog();
- char server[50];
- DWORD leng = 50;
- ::GetComputerName(server, &leng);
- g_localip = server;
- MyGetIPByName(g_localip);
- // setup listview ctrl, so that it looks like the outbar control
- SetupOutlookBar();
- // Add statusbar to the dialog
- CreateStatusbar();
- CRect rect;
- GetDlgItem(IDC_STATIC1)->GetWindowRect(rect);
- ScreenToClient(rect);
- rect.right += 4;
- GetDlgItem(IDC_STATIC1)->MoveWindow(rect);
- // create property pages
- m_TracePage.Create(IDD_PROPPAGE_TRACE, this);
- m_OnlineUsersPage.Create(IDD_PROPPAGE_ONLINE, this);
- m_ConfigurationPage.Create(IDD_PROPPAGE_CONFIGURATION, this);
- m_StatisticsPage.Create(IDD_PROPPAGE_STATISTICS, this);
- m_SecurityPage.Create(IDD_PROPPAGE_SECURITY, this);
- // activate main page
- ActivatePage(0);
- // Set the icon for this dialog.
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- // get registry values
- ENCODE_START
- #ifndef _DEBUG
- #ifdef TIMEDOG_VERSION
- try
- {
- CheckRegCode(); // 检查注册码;
- DWORD id;
- TCHAR HKey[50]="ffffffff",LKey[50]="ffffffff";
- TCHAR OutTime[50];
- TCHAR DevicePath[ 260];
- if(FindPort(0,DevicePath)!=0)
- exit(1);
- //LIBC.LIB,libcp.lib,msvcprt.lib
- TCHAR year[10],month[10],day[10],hour[10],minute[10],second[10];
- ReadTimeAuthFromEprom(HKey,LKey, OutTime, &id, 30128, HKey, LKey, DevicePath);
- CString str=OutTime;
- CString temp="年";
- int pos=str.Find (temp);
- temp=str.Left (pos);
- str=str.Right (str.GetLength ()-pos-2);
- strcpy(year, temp.GetBuffer (0));temp.ReleaseBuffer ();
- temp="月";
- pos=str.Find (temp);
- temp=str.Left (pos);
- str=str.Right (str.GetLength ()-pos-2);
- strcpy(month, temp.GetBuffer (0));temp.ReleaseBuffer ();
- temp="日";
- pos=str.Find (temp);
- temp=str.Left (pos);
- str=str.Right (str.GetLength ()-pos-2);
- strcpy(day, temp.GetBuffer (0));temp.ReleaseBuffer ();
- temp="小时";
- pos=str.Find (temp);
- temp=str.Left (pos);
- str=str.Right (str.GetLength ()-pos-4);
- strcpy(hour, temp.GetBuffer (0));temp.ReleaseBuffer ();
- temp="分钟";
- pos=str.Find (temp);
- temp=str.Left (pos);
- str=str.Right (str.GetLength ()-pos-4);
- strcpy(minute, temp.GetBuffer (0));temp.ReleaseBuffer ();
- temp="0";
- strcpy(second, temp.GetBuffer (0));temp.ReleaseBuffer ();
- long time1=ConvertStringToTimerReal(year, month, day, hour, minute, second);
- GetRunTimer(year, month, day, hour, minute, second, DevicePath);
- long time2=ConvertStringToTimerReal(year, month, day, hour, minute, second);
- // 软件可运行时间;
- g_dwSoftRunTime = time1 - time2;
- if( (time1-time2) <0)
- {
- AfxMessageBox("加密锁已过期, 请与经销商联系!!!");
- InputAuthDlg authdlg;
- authdlg.m_id=id;
- authdlg.m_time1=time1;
- authdlg.m_time2=time2;
- if(authdlg.DoModal ()!=IDOK)
- {
- CDialog::OnCancel ();
- return false;
- }
- }
- else if((time1-time2) < 288000 ) // 10天 = 10*8*3600=360000 能用天数小于10个工作日(8小时一工作日).
- {
- DogTimeOutDlg dlg;
- dlg.hour=(time1-time2)/3600;
- if(dlg.DoModal ()==IDOK)
- {
- InputAuthDlg authdlg;
- authdlg.m_id=id;
- authdlg.m_time1=time1;
- authdlg.m_time2=time2;
- authdlg.DoModal ();
- }
- }
- BOOL bOK=1;
- int d[8];double f[8];
- char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]="";
- //运行自定义函数
- // SoftKey ytSoftKey;
- int ret=0;//ytSoftKey.Ini();
- ret=ytSoftKey.checktime(&d[0],&d[1],&d[2],&d[3],&d[4],&d[5],&d[6],&d[7],
- &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],
- s0,s1,s2,s3,s4,s5,s6,s7);
- if(ret!=0 && ret!=-43)
- {
- bOK=0;
- }
- ////////////////////////写申请码
- if(bOK)
- {
- str=GetRegCode(id, time1, time2);
- char path[MAX_PATH];
- ::GetSystemDirectory (path, MAX_PATH);
- CString sysdir=path;
- sysdir+="\\regcode.txt";
- CStdioFile fp;
- if(fp.Open (sysdir, CFile::modeWrite|CFile::modeCreate))
- {
- fp.WriteString (str);
- fp.Close ();
- }
- }
- /////////////////////////
- }
- catch(...)
- {
- }
- #endif
- #endif
- ENCODE_END
- OnButton1(); // Jeff 初始化服务端,内含定时器1;
- GetFileDate(); // Jeff获取文件信息;
- LoadHistoryDB();//Jeff加载历史数据库;
- SetTimer(4, 1000, NULL);
- SetTimer(2, 10, NULL);
- //CheckBakState();// 检查相片备份情况
- hInst = LoadLibrary("SENSAPI.DLL"); //加载动态库 ;
- if (hInst)
- {
- typedef BOOL(WINAPI *MYFUNC)(LPDWORD);
- MYFUNC IsNetworkConnect = NULL;
- //取得IsNetworkAlive函数指针;
- IsNetworkConnect = (MYFUNC)GetProcAddress(hInst, "IsNetworkAlive");
- if (IsNetworkConnect)
- {
- DWORD dwActiveWan = 1;
- if (IsNetworkConnect(&dwActiveWan))
- m_bNetWorkOK = 1;
- else
- m_bNetWorkOK = 0;
- SetTimer(5, 10000, NULL);
- }
- else
- m_bNetWorkOK = 0;
- }
- else
- m_bNetWorkOK = 0;
- if ( !CBranchInfo::GetInstance() )
- {
- AfxMessageBox(_T("内存分配错误"));
- return FALSE;
- }
- if ( !CBranchInfo::GetInstance()->InitCatalog(g_dwDBServerPort, g_szDBSource, g_szDBAccount, g_szDBPassWord, g_szDBName) )
- {
- AfxMessageBox(_T("初始化数据库连接对象失败"));
- return FALSE;
- }
- CBranchInfo::GetInstance()->GetTblVersion();
- CBranchInfo::GetInstance()->GetTblCatalogInfo();
- CBranchInfo::GetInstance()->GetTblNetShareInfo();
- // 1小时检测一次自动备份和自动删除服务是否启动
- // 是否自动检查服务
- if(g_bAutoCheckSvc == TRUE)
- {
- m_hExitCheckSvc = CreateEvent(NULL, FALSE, FALSE, NULL);
- m_hWaitTimeOut = CreateEvent(NULL, FALSE, FALSE, NULL);
- SetEvent(m_hWaitTimeOut);
- unsigned int nThreadID = 0;
- m_bStartCheckSvc = TRUE;
- m_hCheckSvcThread = (HANDLE)_beginthreadex(NULL, 0, CheckSvcWork, this, 0, &nThreadID);
- }
- return TRUE;
- }
- /********************************************************************/
- /* */
- /* Function name : OnDestroy */
- /* Description : Handle WM_DESTROY message */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnDestroy()
- {
- OnServerStop();
- KillTimer(1);
- KillTimer(2);
- KillTimer(3);
- KillTimer(4);
- KillTimer(5);
- KillTimer(6);
- KillTimer(7);
- KillTimer(8);
- CDialog::OnDestroy();
- }
- /********************************************************************/
- /* */
- /* Function name : OnServerStart */
- /* Description : Start Date Server -> start listening on port 21 */
- /* */
- /********************************************************************/
- //启动数据服务器,使其在指定端口侦听
- void CDBServerDlg::OnServerStart()
- {
- ServerStart();
- }
- BOOL CDBServerDlg::ServerStart()
- {
- if (theServer.Start())
- {
- m_wndStatusBar.SetPaneText(0, "数据服务已启动", TRUE);
- SetOnlineLed(TRUE);
- SetOfflineLed(FALSE);
- WriteTextLog("启动成功");
- return 1;
- }
- else
- {
- WriteTextLog("启动失败");
- CDialog::OnCancel();
- return 0;
- }
- }
- /********************************************************************/
- /* */
- /* Function name : OnUpdateServerStart */
- /* Description : Update 'Start' status */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnUpdateServerStart(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!theServer.IsActive());
- }
- /********************************************************************/
- /* */
- /* Function name : OnServerStop */
- /* Description : Stop Date Server */
- /* */
- /********************************************************************/
- //停止服务器
- void CDBServerDlg::OnServerStop()
- {
- theServer.Stop();
- m_wndStatusBar.SetPaneText(0, "数据服务已停止", TRUE);
- SetOnlineLed(FALSE);
- SetOfflineLed(TRUE);
- }
- /********************************************************************/
- /* */
- /* Function name : OnUpdateServerStop */
- /* Description : Update 'Stop' status */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnUpdateServerStop(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(theServer.IsActive());
- }
- /********************************************************************/
- /* */
- /* Function name : OnServerExit */
- /* Description : Let's get out of here... */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnServerExit()
- {
- OnCancel();
- }
- /********************************************************************/
- /* */
- /* Function name : CDBServerDlg::SetupOutlookBar */
- /* Description : Initialize listview, change color/iconspacing to */
- /* make it look a little bit like the outlook bar. */
- /* */
- /********************************************************************/
- void CDBServerDlg::SetupOutlookBar()
- {
- m_ImageList.Create(32, 32, ILC_COLOR16 | ILC_MASK, 1, 4);
- HICON hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_LOG));
- m_ImageList.Add(hIcon);
- hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ONLINE_USERS));
- m_ImageList.Add(hIcon);
- hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_CONFIGURATION));
- m_ImageList.Add(hIcon);
- hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_SECURITY));
- m_ImageList.Add(hIcon);
- hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_STATISTICS));
- m_ImageList.Add(hIcon);
- m_OutlookBar.SetImageList(&m_ImageList, LVSIL_NORMAL);
- CRect rc;
- m_OutlookBar.GetClientRect(rc);
- // set new icon spacing
- m_OutlookBar.SetIconSpacing(rc.Width(), 64);
- // change colors
- m_OutlookBar.SetTextColor(RGB(255, 255, 255));
- m_OutlookBar.SetTextBkColor(RGB(128, 128, 128));
- m_OutlookBar.SetBkColor(RGB(128, 128, 128));
- // insert items
- m_OutlookBar.InsertColumn(0, "OutlookBar");
- m_OutlookBar.InsertItem(0, "服务器日志", 0);
- m_OutlookBar.InsertItem(1, "在线用户", 1);
- m_OutlookBar.InsertItem(2, "关于", 2);
- m_OutlookBar.InsertItem(3, "功能区", 3);
- }
- /********************************************************************/
- /* */
- /* Function name : CDBServerDlg::MoveChilds */
- /* Description : Move child windows into place holder area. */
- /* */
- /********************************************************************/
- void CDBServerDlg::MoveChilds()
- {
- // position property pages
- CRect rcDlgs;
- // get dialog area rect
- GetDlgItem(IDC_DIALOG_AREA)->GetWindowRect(rcDlgs);
- ScreenToClient(rcDlgs);
- m_ConfigurationPage.MoveWindow(rcDlgs);
- m_TracePage.MoveWindow(rcDlgs);
- m_OnlineUsersPage.MoveWindow(rcDlgs);
- m_StatisticsPage.MoveWindow(rcDlgs);
- m_SecurityPage.MoveWindow(rcDlgs);
- }
- /********************************************************************/
- /* */
- /* Function name : CDBServerDlg::ActivatePage */
- /* Description : Called when an icon on the outlookbar is pressed.*/
- /* */
- /********************************************************************/
- void CDBServerDlg::ActivatePage(int nIndex)
- {
- switch (nIndex)
- {
- case 0:
- m_OnlineUsersPage.ShowWindow(SW_HIDE);
- m_ConfigurationPage.ShowWindow(SW_HIDE);
- m_StatisticsPage.ShowWindow(SW_HIDE);
- m_SecurityPage.ShowWindow(SW_HIDE);
- m_TracePage.ShowWindow(SW_SHOW);
- m_InfobarCtrl.SetText("服务器日志");
- break;
- case 1:
- m_TracePage.ShowWindow(SW_HIDE);
- m_ConfigurationPage.ShowWindow(SW_HIDE);
- m_StatisticsPage.ShowWindow(SW_HIDE);
- m_SecurityPage.ShowWindow(SW_HIDE);
- m_OnlineUsersPage.RefreshData();
- m_OnlineUsersPage.ShowWindow(SW_SHOW);
- m_InfobarCtrl.SetText("在线用户");
- break;
- case 2:
- m_OnlineUsersPage.ShowWindow(SW_HIDE);
- m_TracePage.ShowWindow(SW_HIDE);
- m_StatisticsPage.ShowWindow(SW_HIDE);
- m_SecurityPage.ShowWindow(SW_HIDE);
- m_ConfigurationPage.ShowWindow(SW_SHOW);
- m_InfobarCtrl.SetText("关于");
- break;
- case 4:
- m_OnlineUsersPage.ShowWindow(SW_HIDE);
- m_TracePage.ShowWindow(SW_HIDE);
- m_ConfigurationPage.ShowWindow(SW_HIDE);
- m_SecurityPage.ShowWindow(SW_HIDE);
- m_StatisticsPage.ShowWindow(SW_SHOW);
- m_InfobarCtrl.SetText("Statistics");
- break;
- case 3:
- m_OnlineUsersPage.ShowWindow(SW_HIDE);
- m_TracePage.ShowWindow(SW_HIDE);
- m_ConfigurationPage.ShowWindow(SW_HIDE);
- m_SecurityPage.ShowWindow(SW_SHOW);
- m_StatisticsPage.ShowWindow(SW_HIDE);
- m_InfobarCtrl.SetText("功能区");
- break;
- default:
- break;
- }
- MoveChilds();
- }
- /********************************************************************/
- /* */
- /* Function name : CDBServerDlg::OnClickOutlookBar */
- /* Description : User clicked on our listview -> activate page. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnClickOutlookBar(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // get index of selected item
- int nIndex = m_OutlookBar.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
- if (nIndex == -1)
- return;
- ActivatePage(nIndex);
- *pResult = 0;
- }
- /********************************************************************/
- /* */
- /* Function name : CDBServerDlg::OnKeydownOutlookBar */
- /* Description : User pressed a key -> activate page. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnKeydownOutlookBar(NMHDR* pNMHDR, LRESULT* pResult)
- {
- LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
- // get index of selected item
- int nIndex = m_OutlookBar.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
- if (nIndex == -1)
- return;
- if (pLVKeyDow->wVKey == VK_DOWN)
- {
- if (m_OutlookBar.GetItemCount() - 1 > nIndex)
- {
- ActivatePage(nIndex + 1);
- }
- }
- else if (pLVKeyDow->wVKey == VK_UP)
- {
- if (nIndex > 0)
- {
- ActivatePage(nIndex - 1);
- }
- }
- else if (pLVKeyDow->wVKey == VK_NEXT)
- {
- ActivatePage(m_OutlookBar.GetItemCount() - 1);
- }
- else if (pLVKeyDow->wVKey == VK_PRIOR)
- {
- ActivatePage(0);
- }
- *pResult = 0;
- }
- /********************************************************************/
- /* */
- /* Function name : CreateStatusbar */
- /* Description : This function creates a statusbar on a dialogbox.*/
- /* */
- /********************************************************************/
- BOOL CDBServerDlg::CreateStatusbar()
- {
- // Create the Toolbar and attach the resource
- if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
- {
- TRACE0("Failed to Create Dialog Toolbar\n");
- return FALSE;
- }
- m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);
- // Make it flat.
- m_wndToolBar.ModifyStyle(0, m_wndToolBar.GetStyle() | TBSTYLE_FLAT);
- // Create status bar at the bottom of the dialog window
- if (m_wndStatusBar.Create(this))
- {
- m_wndStatusBar.SetIndicators(auIDStatusBar, sizeof(auIDStatusBar) / sizeof(UINT));
- m_wndStatusBar.SetPaneText(0, "Date Server is offline", TRUE);
- // Make a sunken or recessed border around the first pane
- m_wndStatusBar.SetPaneInfo(0, m_wndStatusBar.GetItemID(0), SBPS_STRETCH, NULL);
- SetOnlineLed(FALSE);
- SetOfflineLed(FALSE);
- m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), ID_INDICATOR_ONLINELED, SBPS_NOBORDERS, 14);
- // m_wndStatusBar.GetStatusBarCtrl().SetTipText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), "This status light is green when the server is online");
- m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), ID_INDICATOR_OFFLINELED, SBPS_NOBORDERS, 14);
- // m_wndStatusBar.GetStatusBarCtrl().SetTipText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), "This status light is green when the server is online");
- }
- // We need to resize the dialog to make room for control bars.
- // First, figure out how big the control bars are.
- CRect rcClientStart;
- CRect rcClientNow;
- GetClientRect(rcClientStart);
- RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, rcClientNow);
- // Now move all the controls so they are in the same relative
- // position within the remaining client area as they would be
- // with no control bars.
- CPoint ptOffset(rcClientNow.left - rcClientStart.left, rcClientNow.top - rcClientStart.top);
- CRect rcChild;
- CWnd* pwndChild = GetWindow(GW_CHILD);
- while (pwndChild)
- {
- pwndChild->GetWindowRect(rcChild);
- ScreenToClient(rcChild);
- rcChild.OffsetRect(ptOffset);
- pwndChild->MoveWindow(rcChild, FALSE);
- pwndChild = pwndChild->GetNextWindow();
- }
- // Adjust the dialog window dimensions
- CRect rcWindow;
- GetWindowRect(rcWindow);
- rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
- rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
- MoveWindow(rcWindow, FALSE);
- // And position the control bars
- RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
- return TRUE;
- }
- /********************************************************************/
- /* */
- /* Function name : OnUserAccounts */
- /* Description : Show user accounts. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnUserAccounts()
- {
- /*
- CUserAccountsDlg dlg;
- theServer.m_UserManager.GetUserList(dlg.m_UserArray);
- if (dlg.DoModal() == IDOK)
- {
- theServer.m_UserManager.UpdateUserList(dlg.m_UserArray);
- }*/
- }
- /********************************************************************/
- /* */
- /* Function name : OnFTPUserConnected */
- /* Description : A user has connected to our server. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnFTPUserConnected(DWORD nThreadID, LPCTSTR lpszUser, LPCSTR lpszAddress)
- {
- m_OnlineUsersPage.AddUser(nThreadID, lpszUser, lpszAddress);
- }
- /********************************************************************/
- /* */
- /* Function name : OnFTPUserDisconnected */
- /* Description : A user has disconnected from our server. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnFTPUserDisconnected(DWORD nThreadID, LPCTSTR lpszUser)
- {
- m_OnlineUsersPage.RemoveUser(nThreadID);
- }
- /********************************************************************/
- /* */
- /* Function name : OnFTPStatusChange */
- /* Description : FTP Status changed. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnFTPStatusChange(int nType, LPCTSTR lpszText)
- {
- m_TracePage.AddTraceLine(nType, lpszText);
- switch (nType)
- {
- case 3:
- theApp.m_LogFile << error_lvl << date << time << lpszText << endl;
- break;
- default:
- theApp.m_LogFile << trace_lvl << date << time << lpszText << endl;
- break;
- }
- }
- /********************************************************************/
- /* */
- /* Function name : OnFTPReceivedBytesChange */
- /* Description : Number of received bytes has changed. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnFTPReceivedBytesChange(int nBytes)
- {
- m_StatisticsPage.SetValue(6, FormatSize(nBytes, 0));
- CString strStatus;
- strStatus.Format("%s received", FormatSize(nBytes, 0));
- m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_RECEIVED), strStatus, TRUE);
- CClientDC dc(this);
- CSize size = dc.GetTextExtent(strStatus);
- m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_RECEIVED), ID_INDICATOR_DATA_RECEIVED, SBPS_NORMAL, size.cx);
- }
- /********************************************************************/
- /* */
- /* Function name : OnFTPSentBytesChange */
- /* Description : Number of sent bytes has changed. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnFTPSentBytesChange(int nBytes)
- {
- m_StatisticsPage.SetValue(7, FormatSize(nBytes, 0));
- CString strStatus;
- strStatus.Format("%s sent", FormatSize(nBytes, 0));
- m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_SEND), strStatus, TRUE);
- CClientDC dc(this);
- CSize size = dc.GetTextExtent(strStatus);
- m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_SEND), ID_INDICATOR_DATA_SEND, SBPS_NORMAL, size.cx);
- }
- /********************************************************************/
- /* */
- /* Function name : OnViewTrace */
- /* Description : Handle menu selection. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnViewTrace()
- {
- ActivatePage(0);
- }
- /********************************************************************/
- /* */
- /* Function name : OnViewOnlineUsers */
- /* Description : Handle menu selection. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnViewOnlineUsers()
- {
- ActivatePage(1);
- }
- /********************************************************************/
- /* */
- /* Function name : OnViewConfiguration */
- /* Description : Handle menu selection. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnViewConfiguration()
- {
- ActivatePage(2);
- }
- /********************************************************************/
- /* */
- /* Function name : OnViewStatistics */
- /* Description : Handle menu selection. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnViewStatistics()
- {
- ActivatePage(3);
- }
- /********************************************************************/
- /* */
- /* Function name : OnViewSecurity */
- /* Description : Handle menu selection. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnViewSecurity()
- {
- ActivatePage(4);
- }
- /********************************************************************/
- /* */
- /* Function name : OnUpdateViewTrace */
- /* Description : Update menu state of Trace item. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnUpdateViewTrace(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(m_TracePage.IsWindowVisible());
- }
- /********************************************************************/
- /* */
- /* Function name : OnUpdateViewOnlineUsers */
- /* Description : Update menu state of Online Users item. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnUpdateViewOnlineUsers(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(m_OnlineUsersPage.IsWindowVisible());
- }
- /********************************************************************/
- /* */
- /* Function name : OnUpdateViewConfiguration */
- /* Description : Update menu state of Configuration item. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnUpdateViewConfiguration(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(m_ConfigurationPage.IsWindowVisible());
- }
- /********************************************************************/
- /* */
- /* Function name : OnUpdateViewStatistics */
- /* Description : Update menu state of Statistics item. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnUpdateViewStatistics(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(m_StatisticsPage.IsWindowVisible());
- }
- /********************************************************************/
- /* */
- /* Function name : OnUpdateViewSecurity */
- /* Description : Update menu state of Security item. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnUpdateViewSecurity(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(m_SecurityPage.IsWindowVisible());
- }
- /********************************************************************/
- /* */
- /* Function name : SetOnlineLed */
- /* Description : Turn online LED on/off. */
- /* */
- /********************************************************************/
- void CDBServerDlg::SetOnlineLed(BOOL bOnline)
- {
- HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(),
- bOnline ? MAKEINTRESOURCE(IDI_LED_GREEN) : MAKEINTRESOURCE(IDI_LED_OFF),
- IMAGE_ICON, 16, 16, LR_SHARED);
- m_wndStatusBar.GetStatusBarCtrl().SetIcon(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), hIcon);
- m_wndStatusBar.GetStatusBarCtrl().Invalidate();
- m_wndStatusBar.GetStatusBarCtrl().UpdateWindow();
- DestroyIcon(hIcon);
- }
- /********************************************************************/
- /* */
- /* Function name : SetOfflineLed */
- /* Description : Turn offline LED on/off. */
- /* */
- /********************************************************************/
- void CDBServerDlg::SetOfflineLed(BOOL bOffline)
- {
- HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(),
- bOffline ? MAKEINTRESOURCE(IDI_LED_RED) : MAKEINTRESOURCE(IDI_LED_OFF),
- IMAGE_ICON, 16, 16, LR_SHARED);
- m_wndStatusBar.GetStatusBarCtrl().SetIcon(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), hIcon);
- m_wndStatusBar.GetStatusBarCtrl().Invalidate();
- m_wndStatusBar.GetStatusBarCtrl().UpdateWindow();
- DestroyIcon(hIcon);
- }
- void CDBServerDlg::OnFTPStatisticChange(int nType, int nValue)
- {
- m_StatisticsPage.SetValue(nType, nValue);
- }
- /********************************************************************/
- /* */
- /* Function name : FormatSize */
- /* Description : Format size, the way explorer diplays it */
- /* */
- /********************************************************************/
- char* CDBServerDlg::FormatSize(DWORD dwSizeLow, DWORD dwSizeHigh)
- {
- static char szBuff[100];
- unsigned __int64 nFileSize = ((unsigned __int64)(((DWORD)(dwSizeLow)) |
- ((unsigned __int64)((DWORD)(dwSizeHigh))) << 32));
- unsigned __int64 kb = 0;
- if (nFileSize > 1024)
- {
- kb = nFileSize / 1024;
- if (nFileSize % 1024)
- kb++;
- }
- // make it a string
- _ui64tot(kb, szBuff, 10);
- // add thousand seperators
- int nLength = lstrlen(szBuff);
- if (nLength > 3)
- {
- LPCTSTR ptr = szBuff;
- ptr += (nLength - 1);
- char szTemp[100];
- LPTSTR ptrTemp = szTemp;
- for (int i = 0; i < nLength; i++)
- {
- if (i && ((i % 3) == 0))
- {
- if (*ptrTemp != ',')
- {
- *ptrTemp = ',';
- ptrTemp = _tcsinc(ptrTemp);
- }
- }
- *ptrTemp = *ptr;
- ptrTemp = _tcsinc(ptrTemp);
- ptr = _tcsdec(szBuff, ptr);
- }
- // terminate string
- *ptrTemp = '\0';
- // reverse string
- _tcsrev(szTemp);
- lstrcpy(szBuff, szTemp);
- }
- // add 'KB' to it
- lstrcat(szBuff, " KB");
- return szBuff;
- }
- /********************************************************************/
- /* */
- /* Function name : OnAccountWizard */
- /* Description : Launch New Account Wizard */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnAccountWizard()
- {/*
- CBitmap bmpHeader, bmpWatermark;
- VERIFY(bmpHeader.LoadBitmap(IDB_BANNER));
- VERIFY(bmpWatermark.LoadBitmap(IDB_WATERMARK));
- // show windows 2000-like wizard
- CWizardSheet wizSheet("New Account Wizard", this, 0, bmpWatermark, NULL, bmpHeader);
- wizSheet.m_psh.hInstance = ::GetModuleHandle(NULL);
- if (wizSheet.DoModal() == ID_WIZFINISH)
- {
- CArray<CUser, CUser&> m_UserArray;
- theServer.m_UserManager.GetUserList(m_UserArray);
- int nIndex = -1;
- for (int i = 0; i < m_UserArray.GetSize(); i++)
- {
- // if it already exists -> update it
- if (m_UserArray[i].m_strName.CompareNoCase(wizSheet.m_Page1.m_strAccountName) == 0)
- {
- nIndex = i;
- break;
- }
- }
- // add new account ?
- if (nIndex == -1)
- {
- CUser user;
- nIndex = m_UserArray.Add(user);
- }
- m_UserArray[nIndex].m_bAccountDisabled = FALSE;
- m_UserArray[nIndex].m_strName = wizSheet.m_Page1.m_strAccountName;
- m_UserArray[nIndex].m_strPassword = wizSheet.m_Page2.m_strPassword;
- // add home directory
- CDirectory directory;
- directory.m_strDir = wizSheet.m_Page3.m_strHomeDirectory;
- directory.m_strAlias = "";
- directory.m_bIsHomeDir = TRUE;
- directory.m_bAllowCreateDirectory = wizSheet.m_Page4.m_bAllowCreateDirectory;
- directory.m_bAllowDelete = wizSheet.m_Page4.m_bAllowDelete;
- directory.m_bAllowDownload = wizSheet.m_Page4.m_bAllowDownload;
- directory.m_bAllowRename = wizSheet.m_Page4.m_bAllowRename;
- directory.m_bAllowUpload = wizSheet.m_Page4.m_bAllowUpload;
- directory.m_strAlias = "";
- m_UserArray[nIndex].m_DirectoryArray.Add(directory);
- // update
- theServer.m_UserManager.UpdateUserList(m_UserArray);
- }*/
- }
- void CDBServerDlg::OnCancel()
- {
- }
- void CDBServerDlg::OnOK()
- {
- }
- void CDBServerDlg::OnButton1() // 启动服务;
- {
- // TODO: Add your control notification handler code here
- try
- {
- theServer.Initialize(this);
- if (ServerStart() == 0)
- return;
- if (g_pSkinData == NULL)
- InitLia();
- /////////////////////
- CString logdays;
- //MyLock lock("dbaccessxiao");
- CDatabase *pdb = NULL;
- ODBCConnGuard ConnGuard(pdb, -1, 3000);
- if ( pdb == NULL)
- return;
- CRecordset myset(pdb);
- CString sql = "select logdays from version";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("logdays", logdays);
- myset.Close();
- int days = 180;
- if (logdays == "1个月")
- days = 31;
- else if (logdays == "2个月")
- days = 61;
- else if (logdays == "3个月")
- days = 92;
- else
- days = 183;
- CTime tm = CTime::GetCurrentTime();
- CTimeSpan dt(240, 0, 0, 0); // Jeff 不使用days,固定使用天数;
- tm -= dt;
- CString date = tm.Format("%Y-%m-%d");
- #if 0
- // 删除日志前,取消触发器;2015-06-10
- sql = _T("DROP TRIGGER ON_DELETE_USER_LOGS");
- pdb->ExecuteSQL(sql);
- sql = "delete from [log] where [date]<'" + date + "'";
- pdb->ExecuteSQL(sql);
- // 删除日志后,恢复触发器;2015-06-10
- sql = _T("CREATE TRIGGER ON_DELETE_USER_LOGS ON [dbo].[log] FOR DELETE AS BEGIN rollback; END");
- pdb->ExecuteSQL(sql);
- #endif
- ///////////////////
- tm = CTime::GetCurrentTime();
- CTimeSpan dt2(183, 0, 0, 0);
- tm -= dt2;
- date = tm.Format("%Y%m%d%H%M%S");
- sql = "delete from sendreg where [status]='OK' and [timestamp]<'" + date + "'";
- pdb->ExecuteSQL(sql);
- //////////////////////////////////
- sql = "select version from version";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("version", sql);
- myset.Close();
- m_ConfigurationPage.m_versionno = sql;
- m_ConfigurationPage.UpdateData(0);
- /////////////////////
- }
- catch (CException *e)
- {
- TCHAR szError[1024] = { 0 };
- e->GetErrorMessage(szError, 1024);
- WriteTextLog(CString(szError));
- e->Delete();
- }
- }
- void CDBServerDlg::OnClose()
- {
- m_TrayIcon.Create(this, WM_ICON_NOTIFY, "影楼管理系统服务器", m_hIcon, IDR_MENUtray); //构造
- ShowWindow(SW_HIDE); //隐藏窗口
- }
- LRESULT CDBServerDlg::OnTrayNotification(WPARAM wParam, LPARAM lParam)
- {
- return m_TrayIcon.OnTrayNotification(wParam, lParam);
- }
- void CDBServerDlg::OnOpen()
- {
- ShowWindow(SW_SHOW);
- }
- void CDBServerDlg::OnExit2()
- {
- try
- {
- TerminateThread();
- m_TrayIcon.RemoveIcon();
- if (g_pSkinData)delete[]g_pSkinData; g_pSkinData = NULL;
- //g_db.Close();
- for (int i = 0; i < g_dbHistoryArray.GetSize(); i++)
- {
- g_dbHistoryArray.ElementAt(i)->Close();
- delete g_dbHistoryArray.ElementAt(i);
- }
- ReleaseBranchDB();
- }
- catch (...)
- {
- WriteTextLog("出错在函数OnExit2中");
- }
- CDialog::OnCancel();
- }
- void CDBServerDlg::OnExit()
- {
- try
- {
- // 结束检查服务线程
- TerminateCheckWork();
- //结束一键生成小图线程
- if(CreateSmallPhoto::GetInstance()->IsCreating())
- {
- if(AfxMessageBox("温馨提示:生成小图还未完成确定要退出程序吗", MB_YESNO|MB_ICONSTOP) == IDNO)
- return;
- CreateSmallPhoto::GetInstance()->TerminateThread();
- }
- TerminateThread();
- DWORD id = FindAppProcessID("AutoRun.exe");
- if (id != -1)
- {
- HANDLE ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, id);
- if (ProcessHandle)TerminateProcess(ProcessHandle, 0);
- }
- m_TrayIcon.RemoveIcon();
- if (g_pSkinData)delete[]g_pSkinData; g_pSkinData = NULL;
- ReleaseBranchDB();
- }
- catch (...)
- {
- WriteTextLog("出错在函数OnExit中");
- }
- CDialog::OnCancel();
- }
- void CDBServerDlg::OnTimer(UINT nIDEvent) //定时器;
- {
- try
- {
- if (nIDEvent == 1)
- {// 生成小图;
- KillTimer(nIDEvent);
- LoadThumbImages();
- }
- else if (nIDEvent == 2)
- {
- KillTimer(nIDEvent);
- OnClose();// 托盘显示;
- try
- {
- CheckHistoryData(); // Jeff:back history db data;
- LoadBranchInfo();
- }
- catch (...)
- {
- }
- SetTimer(1, 2 * 60 * 1000, NULL);
- SetTimer(4, 1000 * 60 * 2, NULL);
- SetTimer(7, 1000 * 60 * 60 * 1, NULL);
- SetTimer(8, 3000, NULL);
- SetTimer(9, 10000, NULL);
- }
- else if (nIDEvent == 3)
- {
- g_pMainWnd->KillTimer(3);
- HANDLE hMutex = ::OpenMutex(NULL, FALSE, _T("lyfzSMSHandle"));
- if (GetLastError() == ERROR_FILE_NOT_FOUND)
- {
- CString autorunpath = g_mainpath + _T("\\SMSHandle.exe");
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- }
- if(hMutex) CloseHandle(hMutex);
- }
- else if (nIDEvent == 4) //Jeff.这里也有自动启动MsgServer.exe服务处理,而且是2分钟/次的频率;
- {
- UpdateDate();
- CheckMemberMsg();
- BakPhoto();
- }
- else if (nIDEvent == 5)
- {
- typedef BOOL(WINAPI *MYFUNC)(LPDWORD);
- MYFUNC IsNetworkConnect = NULL;
- //取得IsNetworkAlive函数指针
- IsNetworkConnect = (MYFUNC)GetProcAddress(hInst, "IsNetworkAlive");
- if (IsNetworkConnect)
- {
- DWORD dwActiveWan = 1;
- BOOL state;
- if (IsNetworkConnect(&dwActiveWan))
- state = 1;
- else
- state = 0;
- if (m_bNetWorkOK != state)
- {
- KillTimer(nIDEvent);
- WriteTextLog("网络断开");
- OnExit2();
- }
- }
- }
- else if (nIDEvent == 6)
- {
- KillTimer(nIDEvent);
- ShutDown();
- }
- else if (nIDEvent == 7)
- {
- //CheckBakState();
- GenUPhoneData();
- }
- else if (nIDEvent == 8)
- {
- CheckConnCount();
- }
- }
- catch (...)
- {
- WriteTextLog("出错在函数Timer中");
- }
- }
- void LoadImageFromBuf(Image **img, BYTE *pData, DWORD leng)//g_bakserver1
- {
- try
- {
- if (pData == NULL)return;
- if (*img)delete *img;
- *img = NULL;
- // Allocate global memory on which to create stream
- HGLOBAL m_hMem = GlobalAlloc(GMEM_MOVEABLE, leng);
- if (m_hMem == NULL)return;
- BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
- memcpy(pmem, pData, leng);
- IStream* pstm;
- CreateStreamOnHGlobal(m_hMem, TRUE, &pstm);
- // load from stream
- *img = Gdiplus::Image::FromStream(pstm);
- // free/release stuff
- GlobalUnlock(m_hMem);
- pstm->Release();
- }
- catch (...)
- {
- }
- }
- void LoadImageFromBuf(Image **img, CString path)
- {
- try
- {
- CFile fp;
- if (fp.Open(path, CFile::modeRead))
- {
- DWORD leng = fp.GetLength();
- BYTE *pData = new BYTE[leng];
- fp.Read(pData, leng);
- fp.Close();
- LoadImageFromBuf(img, pData, leng);
- delete[]pData;
- }
- }
- catch (...)
- {
- }
- }
- void LoadImageFromRes(Image **img, LPCTSTR lpszResourceName, LPCTSTR ResourceType)
- {
- try
- {
- HGLOBAL hGlobal = NULL;
- HRSRC hSource = NULL;
- LPVOID lpVoid = NULL;
- int nSize = 0;
- BOOL bResult = FALSE;
- hSource = FindResource(NULL, lpszResourceName, ResourceType);
- if (hSource == NULL)return;
- hGlobal = LoadResource(NULL, hSource);
- if (hGlobal == NULL)return;
- lpVoid = LockResource(hGlobal);
- if (lpVoid == NULL)return;
- nSize = (UINT)SizeofResource(NULL, hSource);
- LoadImageFromBuf(img, (BYTE*)hGlobal, nSize);
- UnlockResource(hGlobal); // 16Bit Windows Needs This
- FreeResource(hGlobal); // 16Bit Windows Needs This (32Bit - Automatic Release)
- }
- catch (...)
- {
- }
- }
- // ---------------------------------------------------------------------------------------------------------------------------------------------------------------
- // TimeAt: 2014-09-15 AM;
- // Remark: Jeff;
- // 函数:GenSPhoto
- // 描述:对指定文件夹内的相片生成S或M缩略图;
- // 参数:
- // dir: 需要生成缩略图的文件目录;
- // bMPhoto: 是否生成M缩略图;
- // 其它:
- // 在生成缩略图前,记录jpg文件总数nOldCount,每生成一个缩略图nOldCount++;
- // 最后全部图生成完毕,获取新的jpg文件总数nNewCount,if(nOldCount == nNewCount)则表示所有相片已生成缩略图完毕,生成ok文件表示成功生成缩略图;
- //
- // 函数调用全局参数:
- // g_bSteal:意义未明!
- //
- // 注意:该函数非线程安全!
- // 非线程安全:
- // 获取文件总数nOldCount结束后,若有新文件在本函数以外其他函数或进程、线程被添加,则生成缩略图完成后再次获取文件总数nNewCount就不会与nOldCount++后的结果相等;
- // 而实际上本次缩略图已生成完毕。
- // ---------------------------------------------------------------------------------------------------------------------------------------------------------------
- void GenSPhoto(CString dir, BOOL bMPhoto) // 参数:bMPhoto:是否生成M缩略图;
- {
- // 如果是公告附件目录退出;
- if (dir.Find("公告附件") != -1)return;
- // 如果不是客户原片或修好的片目录,设置bMPhoto参数为0,不生成M缩略图;
- if (dir.Find("客户原片(管理软件)$") != -1 || dir.Find("修好的片(管理软件)$") != -1)
- {
- }
- else
- bMPhoto = 0;
- // 对指定文件目录dir进行指定后缀jpg文件遍历;
-
- ffsco o;
- o.dirs(1);
- o.find(LPCSTR(dir), LPCSTR("*.*"));
- ffsco::typeT coo;
- ffsco::typeT::iterator it;
- coo = o.co_file();
- int oldsize = coo.size();
- CString path, temp, spath, mpath;
- for (it = coo.begin(); coo.end() != it; it++)
- {
- try
- {
- if (g_pMainWnd->m_bTerminate)return;
- // 遍历到的jpg文件如果是缩略图则不处理,继续遍历;
- path = (*it).c_str();
- spath = path.Left(path.ReverseFind('\\') + 1);
- mpath = spath;
- spath += "s";
- mpath += "m";
- temp = path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
- if (temp.GetAt(0) == 's')continue;
- if (temp.GetAt(0) == 'm')continue;
- spath += path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
- mpath += path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
- if (g_bSteal)
- {
- Image *pImg = NULL;
- ::LoadImageFromBuf(&pImg, path);
- if (pImg == NULL)continue;
- if (pImg->GetWidth() == 0)continue; // Jeff.continue前未释放pImg;
- delete pImg;
- EncryptFile3(path);
- if (path.Find("客户原片") != -1)
- {
- int pos = path.Find("管理软件)$");
- if (pos != -1)
- {
- path = g_bakserver1 + path.Right(path.GetLength() - pos - 10);
- EncryptFile3(path);
- }
- }
- else if (path.Find("修好的片") != -1)
- {
- int pos = path.Find("管理软件)$");
- if (pos != -1)
- {
- path = g_bakserver2 + path.Right(path.GetLength() - pos - 10);
- EncryptFile3(path);
- }
- }
- else if (path.Find("精修好的片") != -1)
- {
- int pos = path.Find("管理软件)$");
- if (pos != -1)
- {
- path = g_bakserver3 + path.Right(path.GetLength() - pos - 10);
- EncryptFile3(path);
- }
- }
- else if (path.Find("设计好的片") != -1)
- {
- int pos = path.Find("管理软件)$");
- if (pos != -1)
- {
- path = g_bakserver4 + path.Right(path.GetLength() - pos - 10);
- EncryptFile3(path);
- }
- }
- oldsize++;
- }
- else if (!CheckFileExist(spath)) // 没有判断后续是否为jpg或jpeg.
- {
- Image *pImg = NULL;
- ::LoadImageFromBuf(&pImg, path);
- if (pImg == NULL)continue;
- if (pImg->GetWidth() == 0)
- {
- // 由于没有判断spath是否是jpg或jpeg的相片文件,导致这里泄漏;
- if (pImg)
- delete pImg;
- pImg = NULL;
- continue; // Jeff.返回前未释放pImg;
- }
- CRect rc(0, 0, 100, 90);
- RectFitDes(pImg->GetWidth(), pImg->GetHeight(), rc);
- Image *simg = pImg->GetThumbnailImage(rc.Width(), rc.Height(), NULL, NULL);
- if (simg == NULL)
- {
- if (pImg)
- delete pImg;
- pImg = NULL;
- continue;// Jeff.返回前未释放pImg;
- }
- Image *simg2 = NULL;
- if (bMPhoto)
- {
- CRect rc2(0, 0, 2000, 2000);
- RectFitDes(pImg->GetWidth(), pImg->GetHeight(), rc2);
- simg2 = pImg->GetThumbnailImage(rc2.Width(), rc2.Height(), NULL, NULL);
- if (simg2 == NULL)
- {
- if (pImg)
- delete pImg;
- pImg = NULL;
- continue;// Jeff.返回前未释放pImg;
- }
- }
- Graphics graphic(simg);//防止GetThumbnailImage影响质量
- graphic.Clear(Color(255, 255, 255, 255));
- graphic.DrawImage(pImg, 0, 0, simg->GetWidth(), simg->GetHeight());
- if (bMPhoto)
- {
- Graphics graphic2(simg2);//防止GetThumbnailImage影响质量
- graphic2.Clear(Color(255, 255, 255, 255));
- graphic2.DrawImage(pImg, 0, 0, simg2->GetWidth(), simg2->GetHeight());
- }
- ///////////////////////////////
- UINT totalBufferSize;
- UINT numProperties;
- pImg->GetPropertySize(&totalBufferSize, &numProperties);
- // Allocate the buffer that will receive the property items.
- PropertyItem* pAllItems = (PropertyItem*)malloc(totalBufferSize);
- // Fill the buffer.
- pImg->GetAllPropertyItems(totalBufferSize, numProperties, pAllItems);
- // Print the id data member of each property item.
- for (UINT j = 0; j < numProperties; ++j)
- {
- if (PropertyTagOrientation == pAllItems[j].id)
- {
- short* ptrLong = (short*)(pAllItems[j].value);
- int ret = (int)*ptrLong;
- // CString str;
- // str.Format ("%d", ret);
- // AfxMessageBox(str);
- if (ret == 8)
- {
- if (simg2)simg2->RotateFlip(Rotate270FlipNone);
- simg->RotateFlip(Rotate270FlipNone);
- }
- else if (ret == 6)
- {
- if (simg2)simg2->RotateFlip(Rotate90FlipNone);
- simg->RotateFlip(Rotate90FlipNone);
- }
- break;
- }
- }
- free(pAllItems);
- ///////////////////////////////
- ::SaveImageToFile(simg, spath); oldsize++;
- delete simg;
- delete pImg;
- if (bMPhoto)
- {
- ::SaveImageToFile2(simg2, mpath, 100); oldsize++;
- delete simg2;
- }
- }
- }
- catch (...)
- {
- WriteTextLog("出错在函数GenSPhoto中");
- }
- }
- try
- {
- ffsco o;
- o.dirs(1);
- o.find(LPCSTR(dir), LPCSTR("*.*"));
- ffsco::typeT coo;
- ffsco::typeT::iterator it;
- coo = o.co_file();
- int newsize = coo.size();
- if (oldsize == newsize)
- {
- path = dir + "\\ok";
- CFile fp;
- fp.Open(path, CFile::modeCreate | CFile::modeWrite);
- fp.Close();
- }
- }
- catch (...)
- {
- WriteTextLog("出错在函数GenSPhoto2中");
- }
- }
- //--------------------------------------------------------------------------------
- // Remark by Jeff 2014.10.22
- // 函数:LoadThumbNail
- // 描述:S或M缩略图线程
- // 参数:
- // 返回:
- //
- // 调用关系:SetTimer(1);
- // 1.
- // 2.
- // 3.
- //--------------------------------------------------------------------------------
- unsigned __stdcall LoadThumbNail(LPVOID lpParam)
- {
- BOOL bMphoto = 0;
- if (g_bSteal == 0)
- {
- CDatabase *pMaindb = NULL;
- ODBCConnGuard ConnGuard(pMaindb , -1, 3000);
- if ( pMaindb )
- {
- try
- {
- CRecordset myset(pMaindb);
- CString sql = "select * from version";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("setcheck15", sql); // 选片时是否使用m缩略图来代替原片放大使用;
- myset.Close();
- bMphoto = atoi(sql);
- }
- catch (CDBException* e)
- {
- WriteTextLog(_T("LoadThumbNail:%s"),e->m_strError);
- e->Delete();
- }
-
- }
- }
- CString initialPhotoPath = _T("");
- CString initialModifyPath = _T("");
- CString designPhotoPath = _T("");
- CString excellentModifyPath = _T("");
- char server[50] = {0};
- DWORD leng = 50;
- ::GetComputerName(server, &leng);
- initialPhotoPath = initialModifyPath = designPhotoPath = excellentModifyPath = server;
- initialPhotoPath = "\\\\" + initialPhotoPath + "\\客户原片(管理软件)$";
- initialModifyPath = "\\\\" + initialModifyPath + "\\修好的片(管理软件)$";
- designPhotoPath = "\\\\" + designPhotoPath + "\\设计好的片(管理软件)$";
- excellentModifyPath = "\\\\" + excellentModifyPath + "\\精修好的片(管理软件)$";
- GetPathFromNetShareName("客户原片(管理软件)$", initialPhotoPath);
- GetPathFromNetShareName("修好的片(管理软件)$", initialModifyPath);
- GetPathFromNetShareName("设计好的片(管理软件)$", designPhotoPath);
- GetPathFromNetShareName("精修好的片(管理软件)$", excellentModifyPath);
- int i = 0;
- CDBServerDlg *pDlg = (CDBServerDlg*)lpParam;
- try
- {
- CStringArray dirarray;
- // Remark:Jeff.
- // 遍历原片、修好片、设计片、精修片目录,查看是否有ok或ok.dat文件存在;
- // 说明:ok文件在客户端再次导入相片时会被删除;
- // 只有服务端生成小图后,ok才被重新生成;
- if(CBranchInfo::GetInstance()->m_TblNetShareInfo.size() != 0)
- {
- vector<TblNetShareInfo*>::iterator iter = CBranchInfo::GetInstance()->m_TblNetShareInfo.begin();
- for(; iter != CBranchInfo::GetInstance()->m_TblNetShareInfo.end();)
- {
- TblNetShareInfo* p = (*iter);
- if(p != NULL)
- {
- CString strDir = p->szShareDirectory;
- if(strDir.Find(_T("$\\")) != -1)
- strDir = strDir.TrimRight(_T("\\"));
- pDlg->CheckOkFileExistence(strDir, dirarray);
- }
- ++iter;
- }
- CString patharray[2] = { designPhotoPath, excellentModifyPath };
- //int i = 0;
- for (i = 0; i < 2; i++)
- {
- if (pDlg->m_bTerminate)
- break;
- pDlg->CheckOkFileExistence(patharray[i], dirarray);
- }
- }
- else
- {
- CString patharray[4] = { initialPhotoPath, initialModifyPath, designPhotoPath, excellentModifyPath };
- for (i = 0; i < 4; i++)
- {
- if (pDlg->m_bTerminate)
- break;
- pDlg->CheckOkFileExistence(patharray[i], dirarray);
- }
- }
-
- for (i = 0; i < dirarray.GetSize(); i++)
- {
- if (pDlg->m_bTerminate)
- break;
- GenSPhoto(dirarray.ElementAt(i), bMphoto);
- }
- }
- catch (...)
- {
- WriteTextLog("出错在函数GenThumb中");
- }
- pDlg->m_bRunning = false;
- pDlg->m_bTerminate = false;
- pDlg->SetTimer(1, 60 * 1000, NULL);
- _endthreadex(0);
- return 0;
- }
- //--------------------------------------------------------------------------------
- // 函数:CheckOkFileExistence
- // 描述:OK文件是否存在
- // 参数:
- // const CString& strPath 需要搜索的目录
- // CStringArray& arr 返回文件目录
- // 返回:TRUE成功,FALSE失败
- //--------------------------------------------------------------------------------
- BOOL CDBServerDlg::CheckOkFileExistence(const CString& strPath, CStringArray& arr)
- {
- CString path(_T("")), path2(_T(""));
- if(strPath == _T(""))
- return FALSE;
- ffsco o;
- o.dirs(1);
- o.find(LPCSTR(strPath), LPCSTR("*.*"));
- ffsco::typeT coo;
- ffsco::typeT::iterator it;
- coo = o.co_dir();
- it = coo.begin();
- it++;
- for(; coo.end() != it; it++)
- {
- if (m_bTerminate)
- break;
- path = (*it).c_str();
- path.TrimRight("\\");
- path2 = path;
- path2 += "\\ok2.dat";
- path += "\\ok";
- if (CheckFileExist(path2) && path2.Find(".ly.com") == -1)
- {
- ::DeleteFile(path); // 删除ok文件;
- ::DeleteFile(path2); // 删除ok.dat文件;
- }
- // g_bCheckAll g_bSteal的意义???
- // g_bCheckAll没有任何其他赋值的代码,只有最开始初始化值0;下这if不执行;
- if (g_bCheckAll || g_bSteal)
- {
- if (FindArray(&arr, (*it).c_str()) == -1)
- arr.Add((*it).c_str());
- }
- else if (CheckFileExist(path) == 0)
- {
- if (FindArray(&arr, (*it).c_str()) == -1)
- arr.Add((*it).c_str());
- }
- }
- return 1;
- }
- //自动生成小图线程;
- void CDBServerDlg::LoadThumbImages() // 自动生成小图线程;
- {
- if (m_bRunning)return;
- TerminateThread();
- m_bRunning = true;
- m_hThread = (HANDLE)_beginthreadex(NULL, 0, LoadThumbNail, (LPVOID)this, 0/* CREATE_SUSPENDED*/, &m_dwThreadID);
- }
- BOOL CDBServerDlg::TerminateThread()
- {
- try
- {
- if (!m_bRunning)
- return TRUE;
- m_bTerminate = true;
- for (;;)
- {
- if (::WaitForSingleObject(m_hThread, INFINITE) == WAIT_OBJECT_0)
- break;
- }
- ::CloseHandle(m_hThread);
- m_bRunning = false;
- return TRUE;
- }
- catch (...)
- {
- WriteTextLog("出错在函数TerminateThread中");
- }
- return TRUE;
- }
- void CDBServerDlg::InitLia()
- {
- try
- {
- // Jeff:逆天的变量命名!!!局部变量竟然用g_开头!!!
- //BYTE *g_pData=NULL;DWORD g_nLeng; DWORD count2;
- BYTE *pReturnData = NULL;
- DWORD dwReturnLen;
- DWORD count2;
- BYTE byCode = 104;
- CConnectSocket consock;
- ODBCConnGuard ConnGuard(consock.m_pConndb, -1, 3000);
- if ( consock.m_pConndb == NULL )
- return;
- consock.GetDataFromCode(byCode, &pReturnData, dwReturnLen, count2, "");
- if (pReturnData == NULL || dwReturnLen == 0)
- return;
- DWORD readbytes = 0;
- CArray<DWORD, DWORD> ArrayOfLen;
- CArray<DWORD, DWORD> ArrayOfBtnLen;
- BYTE *pArrayPointer = NULL;
- DWORD dwPointerLen = 0;
- DWORD leng;
- memcpy(&leng, pReturnData + readbytes, sizeof(DWORD));
- readbytes += sizeof(DWORD);
- BYTE *pFtData = new BYTE[leng];
- memcpy(pFtData, pReturnData + readbytes, leng);
- readbytes += leng;
- CMemFile memfile;
- memfile.Attach(pFtData, leng);
- CArchive ar(&memfile, CArchive::load);
- ArrayOfLen.Serialize(ar);
- ar.Close();
- memfile.Detach();
- memcpy(&leng, pReturnData + readbytes, sizeof(DWORD));
- readbytes += sizeof(DWORD);
- BYTE *pFtData2 = new BYTE[leng];
- memcpy(pFtData2, pReturnData + readbytes, leng);
- readbytes += leng;
- CMemFile memfile2;
- memfile2.Attach(pFtData2, leng);
- CArchive ar2(&memfile2, CArchive::load);
- ArrayOfBtnLen.Serialize(ar2);
- ar2.Close();
- memfile2.Detach();
- delete[]pFtData;
- delete[]pFtData2;
- DWORD count;
- memcpy(&count, pReturnData + readbytes, sizeof(DWORD));
- readbytes += sizeof(DWORD);
- dwPointerLen = count*sizeof(RESDATA2);
- pArrayPointer = new BYTE[dwPointerLen];
- int i = 0;
- for (i = 0; i < count; i++)
- {
- memcpy(pArrayPointer + i*sizeof(RESDATA2), pReturnData + readbytes, sizeof(RESDATA2));
- readbytes += sizeof(RESDATA2);
- }
- for (i = 0; i < ArrayOfLen.GetSize(); i += 8)
- {
- DWORD leng1, leng2, leng3, leng4, leng5, leng6, leng7, leng8;
- leng1 = ArrayOfLen.ElementAt(i);
- leng2 = ArrayOfLen.ElementAt(i + 1);
- leng3 = ArrayOfLen.ElementAt(i + 2);
- leng4 = ArrayOfLen.ElementAt(i + 3);
- leng5 = ArrayOfLen.ElementAt(i + 4);
- leng6 = ArrayOfLen.ElementAt(i + 5);
- leng7 = ArrayOfLen.ElementAt(i + 6);
- leng8 = ArrayOfLen.ElementAt(i + 7);
- if (i % 4 == 0)
- DeCodelong1((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8);
- else if (i % 4 == 1)
- DeCodelong2((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8);
- else if (i % 4 == 2)
- DeCodelong3((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8);
- else
- DeCodelong4((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8);
- ArrayOfLen.SetAt(i, leng1);
- ArrayOfLen.SetAt(i + 1, leng2);
- ArrayOfLen.SetAt(i + 2, leng3);
- ArrayOfLen.SetAt(i + 3, leng4);
- ArrayOfLen.SetAt(i + 4, leng5);
- ArrayOfLen.SetAt(i + 5, leng6);
- ArrayOfLen.SetAt(i + 6, leng7);
- ArrayOfLen.SetAt(i + 7, leng8);
- }
- delete[]pReturnData;
- if (g_pSkinData)
- delete[]g_pSkinData;
- g_pSkinData = NULL;
- DWORD length;
- BYTE *pData;
- DWORD length2;
- BYTE *pData2;
- CMemFile mStoreFile;
- CArchive arStore(&mStoreFile, CArchive::store);
- ArrayOfLen.Serialize(arStore);
- arStore.Close();
- length = mStoreFile.GetLength();
- pData = mStoreFile.Detach();
- CMemFile mStoreFile1;
- CArchive arStore1(&mStoreFile1, CArchive::store);
- ArrayOfBtnLen.Serialize(arStore1);
- arStore1.Close();
- length2 = mStoreFile1.GetLength();
- pData2 = mStoreFile1.Detach();
- g_SkinLeng = length + length2 + dwPointerLen + 3 * sizeof(DWORD);
- g_pSkinData = new BYTE[g_SkinLeng];
- readbytes = 0;
- memcpy(g_pSkinData + readbytes, &length, sizeof(DWORD));
- readbytes += sizeof(DWORD);
- memcpy(g_pSkinData + readbytes, pData, length);
- readbytes += length;
- memcpy(g_pSkinData + readbytes, &length2, sizeof(DWORD));
- readbytes += sizeof(DWORD);
- memcpy(g_pSkinData + readbytes, pData2, length2);
- readbytes += length2;
- memcpy(g_pSkinData + readbytes, &dwPointerLen, sizeof(DWORD));
- readbytes += sizeof(DWORD);
- memcpy(g_pSkinData + readbytes, pArrayPointer, dwPointerLen);
- readbytes += dwPointerLen;
- delete[]pArrayPointer;
- }
- catch (...)
- {
- WriteTextLog("出错在函数InitLia中");
- }
- }
- BOOL CheckExistDinDan(CString id)
- {
- CDatabase *pMaindb = NULL;
- ODBCConnGuard ConnGuard(pMaindb, -1, 30000);
- if ( pMaindb == NULL )
- return FALSE;
- CRecordset myset(pMaindb);
- CString sql = "select count(*) as cot from dindan where id='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- return atol(sql);
- }
- //CString g_nCurConvertDBName="db"; // Jeff.deal
- CString g_nCurConvertDBName(g_szDBName);
- DWORD CDBServerDlg::ThreadCallerElves(LPVOID lpPara)
- {
- CArray<int, int>codearray;
- codearray.Add(80);
- codearray.Add(90);
- codearray.Add(11);
- codearray.Add(138);
- codearray.Add(24);
- codearray.Add(181);
- codearray.Add(65);
- codearray.Add(56);
- codearray.Add(179);
- codearray.Add(53);
- CFile fp;
- CString savepath, strPath1;
- char server[50];
- DWORD leng = 50;
- ::GetComputerName(server, &leng);
- strPath1 = server;
- strPath1 = "\\\\" + strPath1 + "\\电话录音(管理软件)$";
- GetPathFromNetShareName("电话录音(管理软件)$", strPath1);
- if (strPath1.IsEmpty())
- return 0;
- try
- {
- CDatabase *pMaindb = NULL;
- for ( int i = 0; i < g_dbpool.GetSize(); i++ )
- {
- ODBCConnGuard ConnGuard(pMaindb, i-1, 3000);
- if ( !pMaindb )
- continue;
- savepath.Format("%s\\uphonedata%d.dat", strPath1, i);
- ::DeleteFile(savepath); // 删除uphonedata.dat文件;
- if (fp.Open(savepath, CFile::modeCreate | CFile::modeWrite) == 0)
- {
- WriteTextLog("更新来电精灵数据出错");
- return 0;
- }
- CConnectSocket consock;
- consock.m_pConndb = pMaindb;
- for (int i = 0; i < codearray.GetSize(); i++)
- {
- BYTE code = codearray.ElementAt(i);
- DWORD length, arraysize;
- BYTE *pReturn = NULL;
- consock.GetDataFromCode(code, &pReturn, length, arraysize, "");
- fp.Write(&code, sizeof(BYTE));
- fp.Write(&length, sizeof(DWORD));
- fp.Write(&arraysize, sizeof(DWORD));
- fp.Write(pReturn, length);
- }
- fp.Close();
- }
- }
- catch (CException *e)
- {
- TCHAR szError[1024] = { 0 };
- e->GetErrorMessage(szError, 1024);
- WriteTextLog(CString(szError));
- WriteTextLog("获取来电精灵数据出错1");
- e->Delete();
- }
- return 0;
- }
- /************************************************************************/
- /* [函数]:CheckHistoryData
- /* [描述]:将被检测的数据库已完成的订单数据转到历史数据库中,并删除被检测的数据库已完成的订单;
- /* [参数]:
- /* pSrcdb: 源数据库,用于被转历史的数据库;
- /* nSrcYear: 源数据库的年份;
- /* bMode2: 转储模式:0=年度完成的订单; 1=年度所有订单,包含未完成订单;
- /* [返回]:void
- /*
- /************************************************************************/
- void CDBServerDlg::CheckHistoryData(CDatabase *pSrcdb /* = NULL */, int nSrcYear /* = 0 */, BOOL bMode2 /* = 0*/)//历史备份;
- {
- #if 0
- // 取消转将当前数据库完成订单的记录转到年份数据库中,此步直接返回;
- /////////////////////////生成来电精灵数据
- MyLock lock("processChatMessageRequestxiao");
- CArray<int, int>codearray;
- codearray.Add(80);
- codearray.Add(90);
- codearray.Add(11);
- codearray.Add(138);
- codearray.Add(24);
- codearray.Add(181);
- codearray.Add(65);
- codearray.Add(56);
- codearray.Add(179);
- codearray.Add(53);
- CFile fp;
- CString savepath, g_path1;
- char server[50];
- DWORD leng = 50;
- ::GetComputerName(server, &leng);
- g_path1 = server;
- g_path1 = "\\\\" + g_path1 + "\\电话录音(管理软件)$";
- GetPathFromNetShareName("电话录音(管理软件)$", g_path1);
- if (g_path1.IsEmpty())return;
- try
- {
- CDatabase *pdb = NULL;
- for ( int i = 0; i < g_dbpool.GetSize(); i++ )
- {
- ODBCConnGuard ConnGuard(pdb, i-1, 3000);
- if ( !pdb )
- continue;
- savepath.Format("%s\\uphonedata%d.dat", g_path1, i);
- ::DeleteFile(savepath); // 删除uphonedata.dat文件;
- if (fp.Open(savepath, CFile::modeCreate | CFile::modeWrite) == 0)
- {
- WriteTextLog("更新来电精灵数据出错");
- return;
- }
- CConnectSocket consock;
- consock.m_pConndb = pdb;
- for (int i = 0; i < codearray.GetSize(); i++)
- {
- BYTE code = codearray.ElementAt(i);
- DWORD length, arraysize;
- BYTE *pReturn = NULL;
- consock.GetDataFromCode(code, &pReturn, length, arraysize, "");
- fp.Write(&code, sizeof(BYTE));
- fp.Write(&length, sizeof(DWORD));
- fp.Write(&arraysize, sizeof(DWORD));
- fp.Write(pReturn, length);
- }
- fp.Close();
- }
- }
- catch (CException *e)
- {
- TCHAR szError[1024] = { 0 };
- e->GetErrorMessage(szError, 1024);
- WriteTextLog(CString(szError));
- WriteTextLog("获取来电精灵数据出错1");
- e->Delete();
- }
- #endif
- HANDLE h = CreateThread(NULL, 0, ThreadCallerElves, this, 0, NULL);
- if ( h )CloseHandle(h);
- }
- //------------------------------------------------------------------------------------
- // Jeff remark
- // 函数:CheckYear
- // 描述:
- // 1.检查指定年份的历史数据库mdf文件是否存在,存在则直接附加
- // 2.不存在,则使用null.mdf文件拷贝创建历史年份数据库mdf并附加;
- // 参数:
- // year:被检查年份值;
- // 返回:void
- //------------------------------------------------------------------------------------
- #if JEFF_TEST_ON
- void CDBServerDlg::CheckYear(int year)
- {
- CDatabase *pMaindb = NULL;
- ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
- if ( pMaindb == NULL )
- return;
- pMaindb->SetQueryTimeout(6000);
- try
- {
- #ifdef SQLSERVER_VERSION
- CString sql;
- // 1.判断年份数据库是否存在;
- CString strPathOfYearmdf;
- CString strPathOfYearldf;
- strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, year);
- strPathOfYearldf.Format("%s\\数据\\%d_log.ldf", g_mainpath, year);
- CString strPathOfnulldbmdf = g_mainpath + "\\数据\\dbnull.mdf";
- CString strPathOfnulldbldf = g_mainpath + "\\数据\\dbnull_log.ldf";
- if (PathFileExists(strPathOfYearmdf) == TRUE)
- {
- if (PathFileExists(strPathOfYearldf) == TRUE)
- {
- sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", year, strPathOfYearmdf, strPathOfYearldf);
- }
- else
- {
- // 此时要删除dbnull_log.ldf文件;
- // 因为如果2015没有对应的ldf文件,在逻辑名仍为dbnull没有改为2015时,他会使用dbnull_log.ldf做为2015数据库的日志文件;
- // 这样造成其他数据库在使用dbnull时会产生错误;
- DeleteFile(strPathOfnulldbldf);//删除dbnull_log.ldf文件;
- sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf);
- }
- try
- {
- pMaindb->ExecuteSQL(sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- WriteTextLog("历史数据库初始化失败!");
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- return;
- }
- }
- else
- {
- // 判断dbnull.mdf文件是否存在;
- if (PathFileExists(strPathOfnulldbmdf) == FALSE)
- {
- WriteTextLog("空数据库丢失!");
- return;
- }
- // 判断拷贝mdf文件是否失败;
- if (FALSE == CopyFile(strPathOfnulldbmdf, strPathOfYearmdf, 1))
- {
- DWORD dwError = ::GetLastError();
- CString strDescription;
- strDescription.Format("dbnull.mdf拷贝为%d.mdf失败", year);
- ErrorExit(strDescription, dwError);
- return;
- }
- else
- {
- DeleteFile(strPathOfYearldf); // 删除%d_log.LDF文件;
- if (PathFileExists(strPathOfnulldbldf) == TRUE)
- {
- if (FALSE == CopyFile(strPathOfnulldbldf, strPathOfYearldf, 1))
- {
- DWORD dwError = ::GetLastError();
- CString strDescription;
- strDescription.Format("null.mdf拷贝为%d.mdf", year);
- ErrorExit(strDescription, dwError);
- // 此时要删除dbnull_log.ldf文件;
- // 因为如果2015没有对应的ldf文件,在逻辑名仍为dbnull没有改为2015时,他会使用dbnull_log.ldf做为2015数据库的日志文件;
- // 这样造成其他数据库在使用dbnull时会产生错误;
- DeleteFile(strPathOfnulldbldf);//删除dbnull_log.ldf文件;
- sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf);
- }
- else
- {
- sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", year, strPathOfYearmdf, strPathOfYearldf);
- }
- }
- else
- {
- // 此时要删除dbnull_log.ldf文件;
- // 因为如果2015没有对应的ldf文件,在逻辑名仍为dbnull没有改为2015时,他会使用dbnull_log.ldf做为2015数据库的日志文件;
- // 这样造成其他数据库在使用dbnull时会产生错误;
- DeleteFile(strPathOfnulldbldf);//删除dbnull_log.ldf文件;
- sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf);
- }
- try
- {
- pMaindb->ExecuteSQL(sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- WriteTextLog("历史数据库初始化失败!");
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- return;
- }
- }
- }
- // 附加成功后,修改逻辑名称;
- sql.Format("alter database [%d] modify file(name='dbnull',newname='%d')", year, year);
- try
- {
- pMaindb->ExecuteSQL(sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- WriteTextLog("修改历史数据库主文件逻辑名失败,请手动修改!");
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- sql.Format("alter database [%d] modify file(name='dbnull_log',newname='%d_log')", year, year);
- try
- {
- pMaindb->ExecuteSQL(sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- WriteTextLog("修改历史数据库日志文件逻辑名失败,请手动修改!");
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- OnExit2();
- #else
- CString path,sql;
- path.Format ("%s\\数据\\%d.mdb", g_mainpath, year);
- if(::PathFileExists (path)==0)
- {
- CString nulldb=g_mainpath+"\\数据\\dbnull.mdb";
- ::CopyFile (nulldb, path, 1);
- CDatabase *db=new CDatabase;
- CString strCon;
- strCon.Format("DRIVER=Microsoft Access Driver (*.mdb);DSN='';DBQ=%s;PWD=lijialyfz",path);
- if(db->OpenEx(strCon,CDatabase::noOdbcDialog))
- {
- g_nYearArray.Add (year);
- g_dbHistoryArray.Add (db);
- sql.Format ("insert into historydb([year])values('%d')", year);
- MyExecuteSQL(&g_db, sql);
- }
- else
- delete db;
- }
- #endif
- }
- catch (...)
- {
- WriteTextLog("出错在函数CheckYear中");
- }
- }
- #else
- void CDBServerDlg::CheckYear(int year)
- {
- try
- {
- #ifdef SQLSERVER_VERSION
- CString strPathOfYearmdf;
- CString strPathOfYearldf;
- CString sql;
- strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, year);
- strPathOfYearldf.Format("%s\\数据\\%d_log.LDF", g_mainpath, year);
- ::DeleteFile(strPathOfYearldf); // 删除%d_log.LDF文件;
- {
- CString strPathOfnulldbmdf = g_mainpath + "\\数据\\dbnull.mdf";
- CString strPathOfnulldbldf = g_mainpath + "\\数据\\dbnull_log.LDF";
- ::DeleteFile(strPathOfnulldbldf); // 删除%d_log.LDF文件;
- // 1.判断null.mdf文件是否存在;
- if (::PathFileExists(strPathOfnulldbmdf) == 0)
- {
- WriteTextLog("空数据库丢失!");
- return;
- }
- // 2.若年份mdf文件不存在,用null.mdf复制一份年份mdf数据库文件;
- BOOL bCopyed = 0;
- if (::PathFileExists(strPathOfYearmdf) == 0)
- {
- #if 0
- ::CopyFile(nulldb, path, 1);
- bCopyed=1;
- #else // Jeff add:判断拷贝文件失败的原因;
- if (!::CopyFile(strPathOfnulldbmdf, strPathOfYearmdf, 1))
- {
- DWORD dwError = ::GetLastError();
- CString strDescription;
- strDescription.Format("null.mdf拷贝为%d.mdf", year);
- ErrorExit(strDescription, dwError);
- // return;//直接返回;
- }
- else
- {
- bCopyed = 1;
- }
- #endif
- }
- if (::PathFileExists(strPathOfYearmdf) == 0)
- {
- WriteTextLog("拷贝数据库文件失败!");
- return;
- }
- BOOL bLog = 0;
- if (::PathFileExists(strPathOfnulldbldf))
- {
- bLog = 1;
- }
- // .将年份数据库mdf附加到数据库里;
- CString sql;
- if (bCopyed)
- {
- if (bLog)
- sql.Format("exec sp_attach_db '%s',@filename1='%s',@filename2='%s'", "dbnull", strPathOfYearmdf, strPathOfYearldf);
- else
- sql.Format("exec sp_attach_db '%s',@filename1='%s'", "dbnull", strPathOfYearmdf);
- g_db.SetQueryTimeout(600);
- try
- {
- g_db.ExecuteSQL(sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- WriteTextLog("历史数据库初始化失败!");
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- sql.Format("exec sp_renamedb '%s','%d'", "dbnull", year); g_db.ExecuteSQL(sql);
- }
- else // 没有执行CopyFile,年份mdf原本就存在;
- {
- if (bLog)
- sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", year, strPathOfYearmdf, strPathOfYearldf);
- else
- sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf);
- g_db.SetQueryTimeout(600);
- try
- {
- g_db.ExecuteSQL(sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- WriteTextLog("历史数据库初始化失败!");
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- }
- OnExit2();
- /* g_db.SetQueryTimeout(100);
- CDatabase *db=new CDatabase;
- try
- {
- CString strCon;
- strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=%d;%s"), g_sservrename,year,g_sdbpsw);
- db->OpenEx(strCon,CDatabase::noOdbcDialog);
- g_nYearArray.Add (year);
- dbarray.Add (db);
- sql.Format ("insert into [historydb]([year])values('%d')", year);
- MyExecuteSQL(&g_db, sql);
- }
- catch(CDBException * e)
- {
- delete db;
- WriteTextLog(e->m_strError);
- WriteTextLog("历史数据库打开失败!");
- }*/
- }
- #else
- CString path,sql;
- path.Format ("%s\\数据\\%d.mdb", g_mainpath, year);
- if(::PathFileExists (path)==0)
- {
- CString nulldb=g_mainpath+"\\数据\\dbnull.mdb";
- ::CopyFile (nulldb, path, 1);
- CDatabase *db=new CDatabase;
- CString strCon;
- strCon.Format("DRIVER=Microsoft Access Driver (*.mdb);DSN='';DBQ=%s;PWD=lijialyfz",path);
- if(db->OpenEx(strCon,CDatabase::noOdbcDialog))
- {
- g_nYearArray.Add (year);
- g_dbHistoryArray.Add (db);
- sql.Format ("insert into historydb([year])values('%d')", year);
- MyExecuteSQL(&g_db, sql);
- }
- else
- delete db;
- }
- #endif
- }
- catch (...)
- {
- WriteTextLog("出错在函数CheckYear中");
- }
- }
- #endif
- CDatabase* CDBServerDlg::GetDB(int year)
- {
- try
- {
- for (int i = 0; i < g_nYearArray.GetSize(); i++)
- {
- if (g_nYearArray.ElementAt(i) == year)
- {
- return g_dbHistoryArray.ElementAt(i);
- }
- }
- return NULL;
- }
- catch (...)
- {
- WriteTextLog("出错在函数GetDB中");
- }
- return NULL;
- }
- /************************************************************************/
- /* mark by Jeff;
- /* 函数:CheckDinDanExist
- /* 描述:
- /* 参数:
- /* pBeConverted_db:(源)
- /* pToConverted_db:(目标)
- /* strOderNumber:
- /* pRetArray:
- /*
- /* 返回:1表示正常,100及以上表示源数据库里记录 > 目标数据库记录;
- /*
- /************************************************************************/
- BOOL CDBServerDlg::CheckDinDanExist(CDatabase *pBeConverted_db, CDatabase *pToConverted_db, CString strOderNumber, CStringArray *pRetArray)
- {
- try
- {
- pRetArray->RemoveAll();
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from dindan where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from dindan where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//100
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from dindansp where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from dindansp where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//101
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from dindanbukuan where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from dindanbukuan where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//102
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from dindanbukuan2 where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from dindanbukuan2 where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//103
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from photoprint where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from photoprint where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//104
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from client where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from client where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//105
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from burncdreg where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from burncdreg where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//7
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from digitalwork where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from digitalwork where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//8
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from mywork where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from mywork where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//9
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from dindanjd where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from dindanjd where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//10
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from dindansp2 where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from dindansp2 where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from dindansp3 where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from dindansp3 where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- for (int i = 0; i < pRetArray->GetSize(); i++)
- {
- if (pRetArray->ElementAt(i) == "0")return 100 + i;
- }
- return 1;
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- WriteTextLog("出错在函数check1中");
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- return 100;
- }
- BOOL CDBServerDlg::CheckPayOutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql.Format("select count(*) as cot from gudingfeiyong where [id]=%d", atol(id));
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from gudingfeiyong where [id]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check2中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckIncomeExist(CDatabase *pdb1, CDatabase *pdb2, CString id, CStringArray *pretarray)
- {
- try
- {
- pretarray->RemoveAll();
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql.Format("select count(*) as cot from singleincome where [id]=%d", atol(id));
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from singleincome where [id]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)
- pretarray->Add("0");
- else
- pretarray->Add("1");
- {
- CRecordset myset(pdb1);
- sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id);
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id);
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)
- pretarray->Add("0");
- else
- pretarray->Add("1");
- for (int i = 0; i < pretarray->GetSize(); i++)
- {
- if (pretarray->ElementAt(i) == "0")return 0;
- }
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckIncomeMoneyExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id);
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id);
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- /************************************************************************/
- /* mark by Jeff
- /* 函数:TransDinDan
- /* 描述:
- /* 参数:
- /* pBeConverted_db:被转换的数据库(源);
- /* pToConverted_db:要转到的数据库(目标);
- /* strOrderNumber: 订单号;
- /* nYear: 要转换的年份;
- /*
- /* 返回:
- /************************************************************************/
- int CDBServerDlg::TransDinDan(CDatabase *pBeConverted_db, CDatabase *pToConverted_db, CString strOrderNumber, int nYear)
- {
- int step = 0;
- CStringArray retarray;
- try
- {
- CString sql, str;
- // CheckDinDanExist返回:1表示正常, 100及以上表示源数据库里记录 > 目标数据库记录;
- if (CheckDinDanExist(pBeConverted_db, pToConverted_db, strOrderNumber, &retarray) == 1)
- return 1;
- step = 1;
- int i;
- CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- int ret = 1;
- // 以下全是insert into 到目录数据库中;
- CRecordset myset(pBeConverted_db);
- try
- {
- if (retarray.ElementAt(0) == "0")
- {
- sql.Format("insert into [%d].[dbo].[dindan] select * from [%s].[dbo].[dindan] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step2" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 2;
- }
- step = 2;
- try
- {
- if (retarray.ElementAt(1) == "0")
- {
- sql.Format("insert into [%d].[dbo].[dindansp] select * from [%s].[dbo].[dindansp] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step3" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 3;
- }
- step = 3;
- try
- {
- if (retarray.ElementAt(2) == "0")
- {
- sql.Format("insert into [%d].[dbo].[dindanbukuan] ([autoid],[id],[money],[ren],[date],[bz],[kind],[ren2],[item],[paytype],[jdd],[financecheck]) select [autoid],[id],[money],[ren],[date],[bz],[kind],[ren2],[item],[paytype],[jdd],[financecheck] from [%s].[dbo].[dindanbukuan] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step4" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 4;
- }
- step = 4;
- try
- {
- if (retarray.ElementAt(3) == "0")
- {
- sql.Format("insert into [%d].[dbo].[dindanbukuan2] ([autoid],[id],[money],[ren],[date],[bz],[kind],[ren2]) select [autoid],[id],[money],[ren],[date],[bz],[kind],[ren2] from [%s].[dbo].[dindanbukuan2] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step5" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 5;
- }
- step = 5;
- try
- {
- if (retarray.ElementAt(4) == "0")
- {
- sql.Format("insert into [%d].[dbo].[photoprint] select * from [%s].[dbo].[photoprint] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step6" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 6;
- }
- step = 6;
- try
- {
- if (retarray.ElementAt(5) == "0")
- {
- sql.Format("insert into [%d].[dbo].[client] select * from [%s].[dbo].[client] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step7" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 7;
- }
- step = 7;
- try
- {
- if (retarray.ElementAt(6) == "0")
- {
- sql.Format("insert into [%d].[dbo].[burncdreg] select * from [%s].[dbo].[burncdreg] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step8" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 8;
- }
- step = 8;
- try
- {
- if (retarray.ElementAt(7) == "0")
- {
- sql.Format("insert into [%d].[dbo].[digitalwork] select * from [%s].[dbo].[digitalwork] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step9" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 9;
- }
- step = 9;
- try
- {
- if (retarray.ElementAt(8) == "0")
- {
- sql.Format("insert into [%d].[dbo].[mywork] select * from [%s].[dbo].[mywork] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step10" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 10;
- }
- step = 10;
- try
- {
- if (retarray.ElementAt(9) == "0")
- {
- sql.Format("insert into [%d].[dbo].[dindanjd] select * from [%s].[dbo].[dindanjd] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step11" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 11;
- }
- step = 11;
- try
- {
- if (retarray.ElementAt(10) == "0")
- {
- sql.Format("insert into [%d].[dbo].[dindansp2] select * from [%s].[dbo].[dindansp2] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step12" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 12;
- }
- step = 12;
- try
- {
- if (retarray.ElementAt(11) == "0")
- {
- sql.Format("insert into [%d].[dbo].[dindansp3] select * from [%s].[dbo].[dindansp3] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step13" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 13;
- }
- if (ret != 1)return 200 + ret;
- // 插入到目标数据库后再到目标数据库里查询是否存在;
- return CheckDinDanExist(pBeConverted_db, pToConverted_db, strOrderNumber, &retarray);
- }
- catch (...)
- {
- CString str;
- str.Format("%d size:%d", step, retarray.GetSize());
- WriteTextLog("出错在函数trans1中-" + str);
- }
- return 0;
- }
- BOOL CDBServerDlg::TransPayOut(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckPayOutExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[gudingfeiyong] select * from [%s].[dbo].[gudingfeiyong] where id=%d", year, g_nCurConvertDBName, atol(id));
- MyExecuteSQL(pdb1, sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckPayOutExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans2中");
- }
- return 0;
- }
- //singleincome
- BOOL CDBServerDlg::TransIncome(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- CStringArray retarray;
- if (CheckIncomeExist(pdb1, pdb2, id, &retarray))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- if (retarray.ElementAt(0) == "0")
- {
- sql.Format("insert into [%d].[dbo].[singleincome] select * from [%s].[dbo].[singleincome] where id=%d", year, g_nCurConvertDBName, atol(id));
- MyExecuteSQL(pdb1, sql);
- }
- }
- catch (...)
- {
- ret = 0;
- }
- try
- {
- if (retarray.ElementAt(1) == "0")
- {
- sql.Format("insert into [%d].[dbo].[singleincomemoney] select * from [%s].[dbo].[singleincomemoney] where id='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckIncomeExist(pdb1, pdb2, id, &retarray);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::TransIncomeMoney(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckIncomeMoneyExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[singleincomemoney] select * from [%s].[dbo].[singleincomemoney] where id='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckIncomeMoneyExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Checkclient2phonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from client2phonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from client2phonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transclient2phonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (Checkclient2phonerecordExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[client2phonerecord] select * from [%s].[dbo].[client2phonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return Checkclient2phonerecordExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Checkclient3phonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from client3phonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from client3phonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transclient3phonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (Checkclient3phonerecordExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[client3phonerecord] select * from [%s].[dbo].[client3phonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return Checkclient3phonerecordExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Checkclient2phonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from client2phonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from client2phonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transclient2phonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (Checkclient2phonerecordoutExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[client2phonerecordout] select * from [%s].[dbo].[client2phonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return Checkclient2phonerecordoutExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Checkclient3phonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from client3phonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from client3phonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transclient3phonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (Checkclient3phonerecordoutExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[client3phonerecordout] select * from [%s].[dbo].[client3phonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return Checkclient3phonerecordoutExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckemployeephonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from employeephonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from employeephonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transemployeephonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckemployeephonerecordExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[employeephonerecord] select * from [%s].[dbo].[employeephonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckemployeephonerecordExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckemployeephonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from employeephonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from employeephonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transemployeephonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckemployeephonerecordoutExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[employeephonerecordout] select * from [%s].[dbo].[employeephonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckemployeephonerecordoutExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckphonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from phonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from phonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transphonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckphonerecordExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[phonerecord] select * from [%s].[dbo].[phonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckphonerecordExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckphonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from phonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from phonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transphonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckphonerecordoutExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[phonerecordout] select * from [%s].[dbo].[phonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckphonerecordoutExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckunknownphonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from unknownphonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from unknownphonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transunknownphonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckunknownphonerecordExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[unknownphonerecord] select * from [%s].[dbo].[unknownphonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckunknownphonerecordExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckunknownphonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from unknownphonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from unknownphonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transunknownphonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckunknownphonerecordoutExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[unknownphonerecordout] select * from [%s].[dbo].[unknownphonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckunknownphonerecordoutExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckmisscallrecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from misscallrecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from misscallrecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transmisscallrecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckmisscallrecordExist(pdb1, pdb2, id))return 1;
- int i;
- CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[misscallrecord] select * from [%s].[dbo].[misscallrecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckmisscallrecordExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckSendReg(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql.Format("select count(*) as cot from sendreg where [timestamp]='%s'", id);
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql.Format("select count(*) as cot from sendreg where [timestamp]='%s'", id);
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::TransSendReg(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckSendReg(pdb1, pdb2, id))return 1;
- int i;
- CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[sendreg] select * from [%s].[dbo].[sendreg] where [timestamp]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckSendReg(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- void CDBServerDlg::MyExecuteSQL(CDatabase* pdb, CString sql)
- {
- try
- {
- pdb->ExecuteSQL(sql);
- }
- catch ( CDBException *e)
- {
- WriteTextLog(_T("执行SQL语句出错,系统描述:%s"),e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- }
- void CDBServerDlg::MyExecuteSQL(const TCHAR* pfile, const int& nline, const TCHAR* pfunction, CDatabase* pdb, CString sql)
- {
- try
- {
- pdb->ExecuteSQL(sql);
- }
- catch ( CDBException *e)
- {
- WriteTextLog(_T("%s-<%d>-%s,执行SQL语句出错,系统描述:%s"), pfile, nline, pfunction,e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- }
- void CDBServerDlg::UpdateDate()
- {
- try
- {
- HWND hwnd = ::FindWindow(NULL, "AutoRun.exe - 应用程序错误");
- if (hwnd)
- {
- HWND child = ::FindWindowEx(hwnd, 0, NULL, "确定");
- CWnd *pWnd = CWnd::FromHandle(child);
- ::PostMessage(hwnd, WM_COMMAND, pWnd->GetDlgCtrlID(), (LPARAM)child);
- }
- CString autorunpath = g_mainpath + "\\AutoRun.exe";
- if (0 == g_bConvertHisAll)
- ShellExecute(NULL, _T("open"), g_mainpath + "\\AutoRun.exe", NULL, NULL, SW_HIDE);
- HANDLE hMutex = ::OpenMutex(NULL, FALSE, _T("lyfzSMSHandle"));
- if (GetLastError() == ERROR_FILE_NOT_FOUND)
- {
- autorunpath = g_mainpath + "\\SMSHandle.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- }
- if (hMutex) CloseHandle(hMutex);
- #ifdef ENTERPRISE_VERSION
- autorunpath = g_mainpath + "\\DataSyncReceive.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- autorunpath = g_mainpath + "\\DataSyncSend.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- autorunpath = g_mainpath + "\\CPhotoFTPReceive.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- autorunpath = g_mainpath + "\\CPhotoFTPSend.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- #endif
- }
- catch (...)
- {
- WriteTextLog("出错在函数UpdateDate中");
- }
- }
- BOOL CheckDateOK(CString str)
- {
- try
- {
- CString tip;
- int i;
- CString demo = CTime::GetCurrentTime().Format("%Y-%m-%d");
- if (str.GetLength() != demo.GetLength())
- goto ll;
- //2009-01-01
- if (str.GetAt(4) != '-')
- goto ll;
- if (str.GetAt(7) != '-')
- goto ll;
- for (i = 0; i < str.GetLength(); i++)
- {
- if (i == 4 || i == 7)continue;
- if (str.GetAt(i) < '0' || str.GetAt(i) > '9')
- goto ll;
- }
- }
- catch (...)
- {
- WriteTextLog("出错");
- }
- return 1;
- ll:
- return 0;
- }
- //------------------------------------------------------------------
- // Remark by Jeff:2014.10.11
- // 函数:DelPhoto1
- // 描述:删除指定路径下的订单文件夹;
- // 参数:
- // path: 指定要删除文件的根目录;
- // strOrderNumber: 将要删除的订单号文件夹;
- // 返回:
- //-----------------------------------------------------------------
- BOOL CDBServerDlg::DelPhoto1(CString path, CString strOrderNumber)
- {
- if ( path.IsEmpty() || !PathFileExists(path) )
- {
- //WriteTextLog(_T("路径不存在!"));
- return FALSE;
- }
- path += _T("\\") + strOrderNumber;
- if (PathFileExists(path))
- {
- DeleteDirectory(path);
- return TRUE;
- }
- //WriteTextLog(_T("路径不存在!"));
- return FALSE;
- }
- //-----------------------------------------------------------------------
- // Remark by Jeff 2014.10.22
- // 函数:BakPhoto
- // 描述:对影楼相片进行备份和删除取件相片
- // 参数:#
- // 返回:#
- //
- // 调用关系:
- // 1.BakPhoto()由CDBServerDlg::SetTimer(4) 调用,调用频率2分钟,周期数直到程序结束。
- // 2.CDBServerDlg::SetTimer(4) 由 CDBServerDlg::SetTimer(2) 调用,调用频率10毫秒,只有一个周期。
- // 3.CDBServerDlg::SetTimer(2) 由 CDBServerDlg::OnInitDialog() 调用.
- //-----------------------------------------------------------------------
- void CDBServerDlg::BakPhoto() // Jeff:备份相片/删除取件相片;
- {
- try
- {
- CDatabase *pMaindb = NULL;
- ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
- if ( pMaindb == NULL )
- return;
- CString m_bak1, m_bak2, m_bak3, m_bak4, m_bak6, m_baktime; // Jeff:m_bak6自动备份完毕后自动关机;
- CString m_bakserver1, m_bakserver2, m_bakserver3, m_bakserver4;
- CString msgcheck4, msgtime, msgphones, msgphones2, msgcompanyname;
- CString balance, msgaccount;
- {
- MyLock lock("dbaccessxiao");
- CRstversion rsSt;
- rsSt.m_pDatabase = pMaindb;
- rsSt.Open();
- if (!rsSt.IsEOF())
- {
- m_bak1 = rsSt.m_bak1;
- m_bak2 = rsSt.m_bak2;
- m_bak3 = rsSt.m_bak3;
- m_bak4 = rsSt.m_bak4;
- m_bakserver1 = rsSt.m_bakserver1;
- m_bakserver2 = rsSt.m_bakserver2;
- m_bakserver3 = rsSt.m_bakserver3;
- m_bakserver4 = rsSt.m_bakserver4;
- m_bak6 = rsSt.m_bak6;
- m_baktime = rsSt.m_baktime;
- msgcheck4 = rsSt.msgcheck4;
- msgtime = rsSt.msgtime;
- msgphones = rsSt.msgphones;
- msgphones2 = rsSt.msgphones2;
- msgcompanyname = rsSt.msgcompanyname;
- balance = rsSt.msgbalance;
- msgaccount = rsSt.msgaccount;
- }
- rsSt.Close();
- }
- /////////////检测发短信回财务
- if (msgphones2.IsEmpty() == 0)
- {
- MyLock lock("dbaccessxiao");
- CStringArray array, timearray;
- CString timestamp;
- timestamp = CTime::GetCurrentTime().Format("%Y-%m-%d");
- timestamp += "%";
- CRecordset myset(pMaindb);
- CString sql = "select phones,timestamp from sendregreceive where [timestamp] like '" + timestamp + "' and [content]='001' and [status]='OK'";
- myset.Open(CRecordset::forwardOnly, sql);
- CString phones;
- while (!myset.IsEOF())
- {
- myset.GetFieldValue("phones", phones);
- myset.GetFieldValue("timestamp", timestamp);
- if (msgphones2.Find(phones) != -1)
- {
- array.Add(phones);
- timearray.Add(timestamp);
- }
- myset.MoveNext();
- }
- myset.Close();
- if (array.GetSize())
- {
- CString sql;
- int i = 0;
- //for (int i = 0; i < array.GetSize(); i++)
- for ( i = 0; i < array.GetSize(); i++)
- {
- sql = "update sendregreceive set [status]='' where [timestamp]='" + timearray.ElementAt(i) + "'";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- CArray<CStringArray, CStringArray>List11array;
- CArray<CStringArray, CStringArray>List2array;
- CArray<CStringArray, CStringArray>List3array;
- CArray<CStringArray, CStringArray>other2salearray;
- CArray<CStringArray, CStringArray>memberarray;
- CString strdate = CTime::GetCurrentTime().Format("%Y-%m-%d");
- for( int a = g_dbpool.GetSize(); a >= 0 ;a-- )
- {
- CDatabase *pCurdb = NULL;
- ODBCConnGuard ConnGuard1(pCurdb , a - 1, 3000);
- if ( pCurdb == NULL )
- continue;
- CString filter = "[dat]='" + strdate + "'";
- filter = "[dat]='" + strdate + "' and ([sale2type] is null or [sale2type]='')";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from singleincome"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = List2array.GetSize();
- List2array.SetSize(oldsize + count, 1);
- CRstIncomeInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- int ii = 0;
- while (!rsSt.IsEOF())
- {
- List2array.ElementAt(oldsize + ii).RemoveAll();
- List2array.ElementAt(oldsize + ii).Add(rsSt.id);
- List2array.ElementAt(oldsize + ii).Add(rsSt.name);
- List2array.ElementAt(oldsize + ii).Add(rsSt.money);
- List2array.ElementAt(oldsize + ii).Add(rsSt.date);
- List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
- List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan2);
- List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan3);
- List2array.ElementAt(oldsize + ii).Add(rsSt.bz);
- List2array.ElementAt(oldsize + ii).Add(rsSt.sale2type);
- ii++;
- rsSt.MoveNext(); if (List2array.GetSize() <= ii)break;
- }
- rsSt.Close(); List2array.SetSize(oldsize + ii, 1);
- }
- filter = "[dat]='" + strdate + "'";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from gudingfeiyong"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = List3array.GetSize();
- List3array.SetSize(oldsize + count, 1);
- CRstPayOutInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- int ii = 0;
- while (!rsSt.IsEOF())
- {
- List3array.ElementAt(oldsize + ii).RemoveAll();
- List3array.ElementAt(oldsize + ii).Add(rsSt.id);
- List3array.ElementAt(oldsize + ii).Add(rsSt.name);
- List3array.ElementAt(oldsize + ii).Add(rsSt.money);
- List3array.ElementAt(oldsize + ii).Add(rsSt.date);
- List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
- List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan2);
- List3array.ElementAt(oldsize + ii).Add(rsSt.bz);
- ii++;
- rsSt.MoveNext(); if (List3array.GetSize() <= ii)break;
- }
- rsSt.Close(); List3array.SetSize(oldsize + ii, 1);
- }
- filter = "[date]='" + strdate + "'";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from dindanbukuan"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = List11array.GetSize();
- List11array.SetSize(oldsize + count, 1);
- CRstBuKuan rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- int ii = 0;
- while (!rsSt.IsEOF())
- {
- List11array.ElementAt(oldsize + ii).RemoveAll();
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_id);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_ren);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_money);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_bz);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_kind);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_date);
- ii++;
- rsSt.MoveNext(); if (List11array.GetSize() <= ii)break;
- }
- rsSt.Close(); List11array.SetSize(oldsize + ii, 1);
- }
- filter = "[date]='" + strdate + "'";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from singleincomemoneyview"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = other2salearray.GetSize();
- other2salearray.SetSize(oldsize + count, 1);
- CRstsingleincomemoneyview rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- int ii = 0;
- while (!rsSt.IsEOF())
- {
- other2salearray.ElementAt(oldsize + ii).RemoveAll();
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.name);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan3);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.sale2type);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.money);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.date);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.clerk);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.paytype);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.autoid);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.financecheck);
- ii++;
- rsSt.MoveNext(); if (other2salearray.GetSize() <= ii)break;
- }
- rsSt.Close(); other2salearray.SetSize(oldsize + ii, 1);
- }
- filter = "[date]='" + strdate + "'";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from memberview";
- if (!filter.IsEmpty())
- sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = memberarray.GetSize();
- memberarray.SetSize(oldsize + count, 1);
- memberviewReg rsSt;
- rsSt.m_pDatabase = pCurdb;
- if (!filter.IsEmpty())
- rsSt.m_strFilter = filter;
- rsSt.Open();
- DWORD ii = 0;
- while (!rsSt.IsEOF())
- {
- memberarray.ElementAt(oldsize + ii).RemoveAll();
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_id);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_memberno);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_name);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_money);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_date);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_clerk);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_financecheck);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_moneytype);
- ii++;
- rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break;
- }
- rsSt.Close(); memberarray.SetSize(oldsize + ii, 1);
- }
- }//
- CString str;
- int pos = 0;
- int dindanshu = 0;
- float income = 0;
- float incomedd = 0;
- float incomebk = 0;
- float incomehq = 0;
- float incomeqt = 0;
- float payout = 0;
- for (i = 0; i < List11array.GetSize(); i++)
- {
- str = List11array.ElementAt(i).ElementAt(2);
- income += atof(str);
- // income2+=atof(str);
- if (List11array.ElementAt(i).ElementAt(3) == "预约收款")
- {
- incomedd += atof(str);
- dindanshu++;
- }
- else if (List11array.ElementAt(i).ElementAt(3) == "预约补款")
- {
- incomebk += atof(str);
- }
- else
- {
- incomehq += atof(str);
- }
- pos++;
- }
- for (i = 0; i < List2array.GetSize(); i++)
- {
- str = List2array.ElementAt(i).ElementAt(2);
- income += atof(str);
- /* if(List2array.ElementAt (i).ElementAt (8)!="")
- {
- income2+=atof(str);
- }*/
- if (List2array.ElementAt(i).ElementAt(8) == "")
- {
- incomeqt += atof(str);
- }
- pos++;
- }
- for (i = 0; i < List3array.GetSize(); i++)
- {
- str = List3array.ElementAt(i).ElementAt(2);
- payout += atof(str);
- pos++;
- }
- for (i = 0; i < other2salearray.GetSize(); i++)
- {
- str = other2salearray.ElementAt(i).ElementAt(4);
- income += atof(str);
- incomehq += atof(str);
- pos++;
- }
- for (i = 0; i < memberarray.GetSize(); i++)
- {
- str = memberarray.ElementAt(i).ElementAt(3);
- income += atof(str);
- pos++;
- }
- CTime tm = CTime::GetCurrentTime();
- CString content = msgcompanyname + tm.Format("%Y-%m-%d");
- content += "财报:";
- str.Format("%d", (int)income);
- ::ConvertToPrice(str);
- content += "收:" + str;
- str.Format("%d", (int)incomedd);
- ::ConvertToPrice(str);
- content += "定:" + str;
- str.Format("%d", (int)incomebk);
- ::ConvertToPrice(str);
- content += "补:" + str;
- str.Format("%d", (int)incomehq);
- ::ConvertToPrice(str);
- content += "后:" + str;
- str.Format("%d", (int)incomeqt);
- ::ConvertToPrice(str);
- content += "其它:" + str;
- str.Format("%d", (int)payout);
- ::ConvertToPrice(str);
- content += "支出:" + str;
- str.Format("%d", (int)(income - payout));
- ::ConvertToPrice(str);
- content += "净收:" + str;
- str.Format("%d", dindanshu);
- content += "定单:" + str;
- if (msgaccount != "")
- {
- if (atoi(balance) < 200)
- {
- content += "您的余额小于两百条,请及时充值。联系电话4006067068";
- }
- else if (atoi(balance) < 500)
- {
- content += "您的余额小于五百条,请及时充值。联系电话4006067068";
- }
- else if (atoi(balance) < 800)
- {
- content += "您的余额小于八百条,请及时充值。联系电话4006067068";
- }
- else if (atoi(balance) < 1000)
- {
- content += "您的余额小于一千条,请及时充值。联系电话4006067068";
- }
- }
- int count = GetLengthEx(content) / MSG_LENGTH;
- if (GetLengthEx(content) % MSG_LENGTH)
- count++;
- int phonenum = 0;
- phonenum = 1;
- count *= phonenum;
- CString scount;
- scount.Format("%d", count);
- CString timestamp = tm.Format("%Y%m%d%H%M%S");
- for (i = 0; i < 1; i++)
- {
- sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + array.ElementAt(i) + "','" + content + "','" + timestamp + "','" + scount + "','0','0','0','系统自动发送')";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- }
- }
- /////////////
- if (atoi(msgcheck4) && msgphones != "")
- {//发老板短信
- if (atoi(msgtime) <= CTime::GetCurrentTime().GetHour())
- {
- MyLock lock("dbaccessxiao");
- CString timestamp;
- timestamp = CTime::GetCurrentTime().Format("%Y%m%d");
- timestamp += "%";
- CRecordset myset(pMaindb);
- CString sql = "select count(*) as cot from sendreg where [timestamp] like '" + timestamp + "' and [phones]='" + msgphones + "' and [isautosend]='3'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- if (count == 0)
- {
- CArray<CStringArray, CStringArray>List11array;
- CArray<CStringArray, CStringArray>List2array;
- CArray<CStringArray, CStringArray>List3array;
- CArray<CStringArray, CStringArray>other2salearray;
- CArray<CStringArray, CStringArray>memberarray;
- CString strdate = CTime::GetCurrentTime().Format("%Y-%m-%d");
- for (int a = g_dbpool.GetSize() - 1; a >= 0; a--)
- {
- CDatabase *pCurdb = NULL;
- ODBCConnGuard ConnGuard(pCurdb , a - 1, 3000);
- if ( pCurdb == NULL )
- continue;
- CString filter = "[dat]='" + strdate + "'";
- filter = "[dat]='" + strdate + "' and ([sale2type] is null or [sale2type]='')";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from singleincome"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = List2array.GetSize();
- List2array.SetSize(oldsize + count, 1);
- CRstIncomeInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- int ii = 0;
- while (!rsSt.IsEOF())
- {
- List2array.ElementAt(oldsize + ii).RemoveAll();
- List2array.ElementAt(oldsize + ii).Add(rsSt.id);
- List2array.ElementAt(oldsize + ii).Add(rsSt.name);
- List2array.ElementAt(oldsize + ii).Add(rsSt.money);
- List2array.ElementAt(oldsize + ii).Add(rsSt.date);
- List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
- List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan2);
- List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan3);
- List2array.ElementAt(oldsize + ii).Add(rsSt.bz);
- List2array.ElementAt(oldsize + ii).Add(rsSt.sale2type);
- ii++;
- rsSt.MoveNext(); if (List2array.GetSize() <= ii)break;
- }
- rsSt.Close(); List2array.SetSize(oldsize + ii, 1);
- }
- filter = "[dat]='" + strdate + "'";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from gudingfeiyong"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = List3array.GetSize();
- List3array.SetSize(oldsize + count, 1);
- CRstPayOutInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- int ii = 0;
- while (!rsSt.IsEOF())
- {
- List3array.ElementAt(oldsize + ii).RemoveAll();
- List3array.ElementAt(oldsize + ii).Add(rsSt.id);
- List3array.ElementAt(oldsize + ii).Add(rsSt.name);
- List3array.ElementAt(oldsize + ii).Add(rsSt.money);
- List3array.ElementAt(oldsize + ii).Add(rsSt.date);
- List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
- List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan2);
- List3array.ElementAt(oldsize + ii).Add(rsSt.bz);
- ii++;
- rsSt.MoveNext(); if (List3array.GetSize() <= ii)break;
- }
- rsSt.Close(); List3array.SetSize(oldsize + ii, 1);
- }
- filter = "[date]='" + strdate + "'";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from dindanbukuan"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = List11array.GetSize();
- List11array.SetSize(oldsize + count, 1);
- CRstBuKuan rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- int ii = 0;
- while (!rsSt.IsEOF())
- {
- List11array.ElementAt(oldsize + ii).RemoveAll();
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_id);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_ren);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_money);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_bz);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_kind);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_date);
- List11array.ElementAt(oldsize + ii).Add(rsSt.paytype);
- ii++;
- rsSt.MoveNext(); if (List11array.GetSize() <= ii)break;
- }
- rsSt.Close(); List11array.SetSize(oldsize + ii, 1);
- }
- filter = "[date]='" + strdate + "'";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from singleincomemoneyview"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = other2salearray.GetSize();
- other2salearray.SetSize(oldsize + count, 1);
- CRstsingleincomemoneyview rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- int ii = 0;
- while (!rsSt.IsEOF())
- {
- other2salearray.ElementAt(oldsize + ii).RemoveAll();
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.name);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan3);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.sale2type);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.money);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.date);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.clerk);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.paytype);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.autoid);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.financecheck);
- ii++;
- rsSt.MoveNext(); if (other2salearray.GetSize() <= ii)break;
- }
- rsSt.Close(); other2salearray.SetSize(oldsize + ii, 1);
- }
- filter = "[date]='" + strdate + "'";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from memberview"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = memberarray.GetSize();
- memberarray.SetSize(oldsize + count, 1);
- memberviewReg rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- DWORD ii = 0;
- while (!rsSt.IsEOF())
- {
- memberarray.ElementAt(oldsize + ii).RemoveAll();
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_id);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_memberno);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_name);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_money);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_date);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_clerk);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_financecheck);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_moneytype);
- ii++;
- rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break;
- }
- rsSt.Close(); memberarray.SetSize(oldsize + ii, 1);
- }
- }//
- CString str;
- int pos = 0;
- int dindanshu = 0;
- float income = 0;
- float incomedd = 0;
- float incomebk = 0;
- float incomehq = 0;
- float incomeqt = 0;
- float fStoredCardSpending = 0.0; // 储值卡扣款
- float payout = 0;
- int i = 0;
- for ( i = 0; i < List11array.GetSize(); i++)
- {
- str = List11array.ElementAt(i).ElementAt(2);
- income += atof(str);
- // income2+=atof(str);
- if (List11array.ElementAt(i).ElementAt(3) == "预约收款")
- {
- incomedd += atof(str);
- dindanshu++;
- }
- else if (List11array.ElementAt(i).ElementAt(3) == "预约补款")
- {
- incomebk += atof(str);
- }
- else
- {
- incomehq += atof(str);
- }
- #if JEFF_TEST_ON // 去除储值卡扣费;
- if (List11array.ElementAt(i).ElementAt(6) == "储值卡扣款" || List11array.ElementAt(i).ElementAt(6) == "代金券")
- {
- fStoredCardSpending += atof(str);
- }
- #endif
- pos++;
- }
- for (i = 0; i < List2array.GetSize(); i++)
- {
- str = List2array.ElementAt(i).ElementAt(2);
- income += atof(str);
- /* if(List2array.ElementAt (i).ElementAt (8)!="")
- {
- income2+=atof(str);
- }*/
- if (List2array.ElementAt(i).ElementAt(8) == "")
- {
- incomeqt += atof(str);
- }
- pos++;
- }
- for (i = 0; i < List3array.GetSize(); i++)
- {
- str = List3array.ElementAt(i).ElementAt(2);
- payout += atof(str);
- pos++;
- }
- for (i = 0; i < other2salearray.GetSize(); i++)
- {
- str = other2salearray.ElementAt(i).ElementAt(4);
- income += atof(str);
- incomehq += atof(str);
- pos++;
- }
- for (i = 0; i < memberarray.GetSize(); i++)
- {
- str = memberarray.ElementAt(i).ElementAt(3);
- income += atof(str);
- pos++;
- }
- CTime tm = CTime::GetCurrentTime();
- CString content = msgcompanyname + tm.Format("%Y-%m-%d");
- content += "财报:";
- income -= fStoredCardSpending;
- str.Format("%d", (int)(income)); // 去除储值卡扣款和代金券;
- ::ConvertToPrice(str);
- content += "收:" + str;
- str.Format("%d", (int)incomedd);
- ::ConvertToPrice(str);
- content += "定:" + str;
- str.Format("%d", (int)incomebk);
- ::ConvertToPrice(str);
- content += "补:" + str;
- str.Format("%d", (int)incomehq);
- ::ConvertToPrice(str);
- content += "后:" + str;
- str.Format("%d", (int)incomeqt);
- ::ConvertToPrice(str);
- content += "其它:" + str;
- str.Format("%d", (int)payout);
- ::ConvertToPrice(str);
- content += "支出:" + str;
- str.Format("%d", (int)(income - payout));
- ::ConvertToPrice(str);
- content += "净收:" + str;
- str.Format("%d", dindanshu);
- content += "定单:" + str;
- if (msgaccount != "")
- {
- if (atoi(balance) < 200)
- {
- content += "您的余额小于两百条,请及时充值。联系电话4006067068";
- }
- else if (atoi(balance) < 500)
- {
- content += "您的余额小于五百条,请及时充值。联系电话4006067068";
- }
- else if (atoi(balance) < 800)
- {
- content += "您的余额小于八百条,请及时充值。联系电话4006067068";
- }
- else if (atoi(balance) < 1000)
- {
- content += "您的余额小于一千条,请及时充值。联系电话4006067068";
- }
- }
- int count = GetLengthEx(content) / MSG_LENGTH;
- if (GetLengthEx(content) % MSG_LENGTH)
- count++;
- int phonenum = 0;
- str = msgphones;
- pos = str.Find(",");
- if (pos != -1)
- {
- while (pos != -1)
- {
- phonenum++;
- str = str.Right(str.GetLength() - pos - 1);
- pos = str.Find(",");
- }
- phonenum++;
- }
- else
- phonenum = 1;
- count *= phonenum;
- CString scount;
- scount.Format("%d", count);
- timestamp = tm.Format("%Y%m%d%H%M%S");
- sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + msgphones + "','" + content + "','" + timestamp + "','" + scount + "','0','0','3','系统自动发送')";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- }
- }
- BOOL bcheck1 = atoi(m_bak1);
- BOOL bcheck2 = atoi(m_bak2);
- BOOL bcheck3 = atoi(m_bak3);
- BOOL bcheck4 = atoi(m_bak4);
- }
- catch (CException *e)
- {
- TCHAR szError[1024] = { 0 };
- e->GetErrorMessage(szError, 1024);
- WriteTextLog(CString(szError));
- e->Delete();
- WriteTextLog("出错在函数bakphoto中");
- }
- }
- void CDBServerDlg::ShutDown() //Jeff:备份完毕后执行的关机函数;
- {
- try
- {
- // 结束检查服务线程
- TerminateCheckWork();
- CDatabase *pMaindb = NULL;
- ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
- if ( pMaindb == NULL )
- return;
- CString m_bak6;
- {
- CRecordset myset(pMaindb);
- CString sql = "select * from [version]";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("bak6", m_bak6);
- myset.Close();
- }
- OnServerStop(); // 停止服务;
- // Jeff.关闭数据库连接,若关机前关闭了数据库的连接,则客户端进行订单无法实现数据库的操作;
- // Jeff.在关机前,不能关闭数据库连接;
- for (int i = 0; i < g_dbHistoryArray.GetSize(); i++)
- {
- g_dbHistoryArray.ElementAt(i)->Close();
- delete g_dbHistoryArray.ElementAt(i);
- }
- ReleaseBranchDB();
- WriteTextLog("备份完成");
- ////////////////
- g_tisks = ::GetTickCount() - g_tisks;
- CString str;
- str.Format("耗时:%d分钟", g_tisks / 60000);
- CStdioFile fp;
- fp.Open(g_mainpath + "\\log.txt", CFile::modeCreate | CFile::modeWrite);
- CTime tm = CTime::GetCurrentTime();
- if (0)//tm.GetHour ()<5)
- {
- CTimeSpan sp(1, 0, 0, 0);
- tm -= sp;
- fp.WriteString(tm.Format("%Y-%m-%d"));
- fp.WriteString("\r\n");
- fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S"));
- fp.WriteString(str);
- }
- else
- {
- fp.WriteString(g_bakdate);
- fp.WriteString("\r\n");
- fp.WriteString(tm.Format("%Y-%m-%d %H:%M:%S"));
- fp.WriteString(str);
- }
- fp.WriteString("\r\n");
- fp.WriteString(g_bakinfo);
- fp.WriteString("\r\n");
- fp.WriteString(g_bakphoto);
- fp.Close();
- // OnButton3();
- // Jeff.备份完成后自动关机;
- if (atoi(m_bak6))
- {
- // Jeff.关闭运行中的线程;
- TerminateThread();
- // Jeff.关闭AutoRun.exe程序;
- DWORD id = FindAppProcessID("AutoRun.exe");
- if (id != -1)
- {
- HANDLE ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, id);
- if (ProcessHandle)TerminateProcess(ProcessHandle, 0);
- }
- // Jeff.移除托盘图标;
- m_TrayIcon.RemoveIcon();
- if (g_pSkinData)delete[]g_pSkinData; g_pSkinData = NULL;
- // Jeff.关闭计算机;
- MyExitWindows();
- }
- else//重启
- {
- TerminateThread();
- m_TrayIcon.RemoveIcon();
- if (g_pSkinData)
- delete[]g_pSkinData;
- g_pSkinData = NULL;
- WriteTextLog("备份完成,服务器重启");
- CDialog::OnCancel();
- }
- }
- catch (...)
- {
- WriteTextLog("出错在函数shutdown中");
- }
- }
- void CDBServerDlg::MyExitWindows()
- {
- try
- {
- UINT t = EWX_SHUTDOWN | EWX_FORCE;
- OSVERSIONINFO osv; //定义一个操作系统信息的结构体
- osv.dwOSVersionInfoSize = sizeof OSVERSIONINFO;
- GetVersionEx(&osv); //查询当前操作系统
- if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) //判断是否是2000/NT
- {
- //下面为向操作系统获取权限操作
- HANDLE hProcess, hToken;
- TOKEN_PRIVILEGES Privileges;
- LUID luid;
- hProcess = GetCurrentProcess();
- //下面为打开当前进程对话
- OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken);
- Privileges.PrivilegeCount = 1;
- LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &luid);
- Privileges.Privileges[0].Luid = luid;
- Privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
- AdjustTokenPrivileges(hToken, FALSE, &Privileges, NULL, NULL, NULL);
- ExitWindowsEx(t, 0);
- }
- else
- {
- ExitWindowsEx(t, 0);//调用ExitWindowsEx关闭机器。
- PostQuitMessage(0);
- }
- }
- catch (...)
- {
- WriteTextLog("出错在函数exitwindows中");
- }
- }
- void CDBServerDlg::OnAutorun()
- {
- // TODO: Add your command handler code here
- g_bAutoRun = !g_bAutoRun;
- CString version = _T("Version 1.0");
- AfxGetApp()->WriteProfileInt(version, "brun", g_bAutoRun);
- TCHAR szKey[MAX_PATH];
- HKEY hKey = 0;
- DWORD disp = 0;
- lstrcpy(szKey, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
- if (g_bAutoRun)
- {
- int lResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp);
- if (lResult == ERROR_SUCCESS)
- {
- TCHAR szDir[MAX_PATH];
- ::GetModuleFileName(NULL, szDir, MAX_PATH);
- lResult = RegSetValueEx(hKey, "YLGLDBSERVER", 0, REG_SZ, (const unsigned char*)szDir, lstrlen(szDir));
- RegCloseKey(hKey);
- }
- }
- else
- {
- int lResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp);
- if (lResult == ERROR_SUCCESS)
- {
- RegDeleteValue(hKey, "YLGLDBSERVER");
- RegDeleteKey(hKey, "YLGLDBSERVER");
- RegCloseKey(hKey);
- }
- }
- }
- void CDBServerDlg::GetFileDate()
- {
- CStringArray filesarray;
- CStringArray filesarray2;
- filesarray.Add("AutoUpdate.exe"); // 1.
- filesarray.Add("skin\\1.lia");
- filesarray.Add("skin\\2.lia");
- filesarray.Add("skin\\3.lia");
- filesarray.Add("skin\\4.lia");
- filesarray.Add("skin\\10.lia");
- filesarray.Add("skin\\logo.jpg");
- filesarray.Add("skin\\标题-选片.jpg");
- filesarray.Add("skin\\标题-看设计.jpg");
- filesarray.Add("图片\\欢迎.jpg"); // 10.
- filesarray.Add("图片\\连接.jpg");
- filesarray.Add("图片\\标题.jpg");
- filesarray.Add("图片\\背景.jpg");
- filesarray.Add("图片-红色风格\\欢迎.jpg");
- filesarray.Add("图片-红色风格\\连接.jpg");
- filesarray.Add("图片-红色风格\\标题.jpg");
- filesarray.Add("图片-红色风格\\背景.jpg");
- filesarray.Add("图片-红色风格\\选片.jpg");
- filesarray.Add("图片-红色风格\\看设计.jpg");
- filesarray.Add("skin\\1-red.lia"); // 20.
- filesarray.Add("skin\\2-red.lia");
- filesarray.Add("skin\\10-red.lia");
- filesarray.Add("skin\\6.lia");
- filesarray.Add("图片\\掌中宝.jpg");
- filesarray.Add("regsvr32.exe"); // 25.
- filesarray.Add("MSCHRT20.OCX"); // 26. // Jeff.2014.09.06.添加MSCHRT20.OCX,由服务器传递;
- ///////////////
- filesarray2.Add("AutoUpdate.exe");
- filesarray2.Add("skin\\1.lia");
- filesarray2.Add("skin\\2.lia");
- filesarray2.Add("skin\\3.lia");
- filesarray2.Add("skin\\4.lia");
- filesarray2.Add("skin\\5.lia");
- filesarray2.Add("skin\\10.lia");
- filesarray2.Add("skin\\5-red.lia");
- filesarray2.Add("skin\\10-red.lia");
- filesarray2.Add("图片\\logo.jpg");
- filesarray2.Add("图片\\标题-选片.jpg");
- filesarray2.Add("图片\\标题-看设计.jpg");
- filesarray2.Add("图片\\选片.jpg");
- filesarray2.Add("图片\\看设计.jpg");
- filesarray2.Add("图片\\欢迎.jpg");
- filesarray2.Add("图片\\连接.jpg");
- filesarray2.Add("图片\\标题.jpg");
- filesarray2.Add("图片\\背景.jpg");
- filesarray2.Add("图片-红色风格\\欢迎.jpg");
- filesarray2.Add("图片-红色风格\\连接.jpg");
- filesarray2.Add("图片-红色风格\\标题.jpg");
- filesarray2.Add("图片-红色风格\\背景.jpg");
- filesarray2.Add("skin\\6.lia");
- filesarray2.Add("图片\\掌中宝.jpg");
- filesarray2.Add("regsvr32.exe");
- filesarray2.Add("MSCHRT20.OCX"); // 26. // Jeff.2014.09.06.添加MSCHRT20.OCX,由服务器传递;
- int i = 0;
- //for (int i = 0; i < filesarray.GetSize(); i++)
- for ( i = 0; i < filesarray.GetSize(); i++)
- {
- g_filedatearray.Add(GetModifyTime(g_mainpath + "\\系统文件\\" + filesarray.ElementAt(i)));
- }
- g_filedatearraynew.Copy(filesarray2);
- for (i = 0; i < filesarray2.GetSize(); i++)
- {
- g_filedatearraynew.Add(GetFileSize(g_mainpath + "\\系统文件\\" + filesarray2.ElementAt(i)));
- }
- }
- //extern CString g_sdomain;
- #ifdef ENTERPRISE_VERSION
- CString g_bMain;
- #endif
- void CDBServerDlg::LoadBranchInfo()
- {
- #ifdef ENTERPRISE_VERSION
- try
- {
- ReleaseBranchDB();
- CArray<CStringArray, CStringArray>g_List1array;
- {
- MyLock lock("savebranchinfo");
- CFile fp;
- CString path = g_mainpath + "\\branchinfo.dat";
- if (::PathFileExists(path) == 0)
- return;
- fp.Open(path, CFile::modeRead);
- DWORD leng = fp.GetLength();
- if (leng < sizeof(DWORD) * 2)
- {
- fp.Close();
- return;
- }
- DWORD flag = 0;
- //fp.Seek(-sizeof(DWORD), CFile::end);
- fp.Seek(-(int)sizeof(DWORD), CFile::end);
- fp.Read(&flag, sizeof(DWORD));
- if (flag != 889900)
- {
- fp.Close();
- return;
- }
- fp.SeekToBegin();
- DWORD arraysize;
- fp.Read(&arraysize, sizeof(DWORD));
- if (arraysize > 20)
- {
- fp.Close();
- return;
- }
- BYTE *pData = new BYTE[leng - sizeof(DWORD)];
- fp.Read(pData, leng - sizeof(DWORD));
- fp.Close();
- CMemFile memfile;
- memfile.Attach(pData, leng - sizeof(DWORD));
- CArchive ar(&memfile, CArchive::load);
- g_List1array.SetSize(arraysize, 1);
- for (int ii = 0; ii < g_List1array.GetSize(); ii++)
- g_List1array.ElementAt(ii).Serialize(ar);
- ar.Close();
- memfile.Detach();
- delete[]pData;
- }
- if (g_List1array.GetSize() == 0)
- return;
- // SoftKey ytSoftKey;
- // if(ytSoftKey.Ini()==0)
- {
- int value[8];
- double f[8];
- TCHAR s0[50] = _T(""), s1[50] = _T(""), s2[50] = _T(""), s3[50] = _T(""), s4[50] = _T(""), s5[50] = _T(""), s6[50] = _T(""), s7[50] = _T("");
- //运行自定义函数
- int ret = ytSoftKey.getdata(&value[0], &value[1], &value[2], &value[3], &value[4], &value[5], &value[6], &value[7],
- &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
- s0, s1, s2, s3, s4, s5, s6, s7);
- if (ret != 0 && ret != -43)
- {
- g_sdomain = "";
- }
- else
- g_sdomain = s1;
- }
- CString str, str2, localname, rights;
- int i = 0;
- for (/*int*/ i = 0; i < g_List1array.GetSize(); i++)
- {
- if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0))
- {
- if (g_List1array.ElementAt(i).GetSize()>5)
- rights = g_List1array.ElementAt(i).ElementAt(5); break;
- }
- }
- for (i = 0; i < g_List1array.GetSize(); i++)
- {
- CString branchname = g_List1array.ElementAt(i).ElementAt(1);
- CString branchip = g_List1array.ElementAt(i).ElementAt(2);
- CString domain = g_List1array.ElementAt(i).ElementAt(0);
- CString dir = g_mainpath + "\\数据\\" + branchname;
- if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0))
- {
- localname = branchname;
- g_bMain = g_List1array.ElementAt(i).ElementAt(3);
- continue;
- }
- CString branchname2 = "," + branchname + ",";
- if (rights.Find(branchname2) == -1)
- continue;
- #ifdef SQLSERVER_VERSION
- if (1)//::PathFileExists (dir))
- {
- /////////////////////////
- g_branchdbarray.Add(NULL);
- g_branchnamearray.Add(branchname);
- g_branchdb2array.Add(NULL);
- g_branchname2array.Add(branchname);
- g_branchiparray.Add(branchip);
- g_branchdomainarray.Add(domain);
- // WriteTextLog(_T("添加分店:")+branchname);
- }
- #endif
- }
- //WriteTextLog(_T("添加本店:")+localname);
- g_branchdbarray.Add(NULL);
- g_branchnamearray.Add(localname);
- g_branchiparray.Add("xxx");
- g_branchdomainarray.Add(g_sdomain);
- }
- catch (...)
- {
- }
- #endif
- }
- void CDBServerDlg::ReleaseBranchDB()
- {
- #ifdef ENTERPRISE_VERSION
- try
- {
- for (int i = 0; i < g_branchdbarray.GetSize(); i++)
- {
- if (g_branchdbarray.ElementAt(i))
- {
- g_branchdbarray.ElementAt(i)->Close();
- delete g_branchdbarray.ElementAt(i);
- }
- }
- g_branchdbarray.RemoveAll();
- g_branchdb2array.RemoveAll();
- g_branchnamearray.RemoveAll();
- g_branchname2array.RemoveAll();
- g_branchiparray.RemoveAll();
- g_branchdomainarray.RemoveAll();
- }
- catch (...)
- {
- WriteTextLog("ReleaseBranchDB出错");
- }
- #endif
- }
- //savebranchinfo
- void CDBServerDlg::LoadBranchInfo2()
- {
- #ifdef ENTERPRISE_VERSION
- try
- {
- ReleaseBranchDB();
- CArray<CStringArray, CStringArray>g_List1array;
- {
- MyLock lock("savebranchinfo");
- CFile fp;
- CString path = g_mainpath + "\\branchinfo.dat";
- if (::PathFileExists(path) == 0)
- return;
- fp.Open(path, CFile::modeRead);
- DWORD leng = fp.GetLength();
- if (leng < sizeof(DWORD) * 2)
- {
- fp.Close(); return;
- }
- DWORD flag;
- //fp.Seek(-sizeof(DWORD), CFile::end);
- fp.Seek(-(int)sizeof(DWORD), CFile::end);
- fp.Read(&flag, sizeof(DWORD));
- if (flag != 889900)
- {
- fp.Close(); return;
- }
- fp.SeekToBegin();
- DWORD arraysize;
- fp.Read(&arraysize, sizeof(DWORD));
- if (arraysize > 20)
- {
- fp.Close();
- return;
- }
- BYTE *pData = new BYTE[leng - sizeof(DWORD)];
- fp.Read(pData, leng - sizeof(DWORD));
- fp.Close();
- CMemFile memfile;
- memfile.Attach(pData, leng - sizeof(DWORD));
- CArchive ar(&memfile, CArchive::load);
- g_List1array.SetSize(arraysize, 1);
- for (int ii = 0; ii < g_List1array.GetSize(); ii++)
- {
- g_List1array.ElementAt(ii).Serialize(ar);
- }
- ar.Close();
- memfile.Detach();
- delete[]pData;
- }
- if (g_List1array.GetSize() == 0)return;
- // SoftKey ytSoftKey;
- // if(ytSoftKey.Ini()==0)
- {
- int value[8];
- double f[8];
- TCHAR s0[50] = _T(""), s1[50] = _T(""), s2[50] = _T(""), s3[50] = _T(""), s4[50] = _T(""), s5[50] = _T(""), s6[50] = _T(""), s7[50] = _T("");
- //运行自定义函数
- int ret = ytSoftKey.getdata(&value[0], &value[1], &value[2], &value[3], &value[4], &value[5], &value[6], &value[7],
- &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
- s0, s1, s2, s3, s4, s5, s6, s7);
- if (ret != 0 && ret != -43)
- {
- g_sdomain = "";
- }
- else
- g_sdomain = s1;
- }
- CString str, str2, localname, rights;
- int i = 0;
- for (/*int*/ i = 0; i < g_List1array.GetSize(); i++)
- {
- if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0))
- {
- if (g_List1array.ElementAt(i).GetSize()>5)
- rights = g_List1array.ElementAt(i).ElementAt(5); break;
- }
- }
- for (i = 0; i < g_List1array.GetSize(); i++)
- {
- CString branchname = g_List1array.ElementAt(i).ElementAt(1);
- CString branchip = g_List1array.ElementAt(i).ElementAt(2);
- CString domain = g_List1array.ElementAt(i).ElementAt(0);
- CString dir = g_mainpath + "\\数据\\" + branchname;
- if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0))
- {
- localname = branchname;
- g_bMain = g_List1array.ElementAt(i).ElementAt(3);
- continue;
- }
- CString branchname2 = "," + branchname + ",";
- if (rights.Find(branchname2) == -1)
- continue;
- #ifdef SQLSERVER_VERSION
- if (1)//::PathFileExists (dir))
- {
- ////////////////////////
- g_branchdbarray.Add(NULL);
- g_branchnamearray.Add(branchname);
- g_branchdb2array.Add(NULL);
- g_branchname2array.Add(branchname);
- g_branchiparray.Add(branchip);
- g_branchdomainarray.Add(domain);
- }
- #endif
- }
- g_branchdbarray.Add(NULL);
- g_branchnamearray.Add(localname);
- g_branchiparray.Add("xxx");
- g_branchdomainarray.Add(g_sdomain);
- }
- catch (...)
- {
- }
- #endif
- }
- int __cdecl CompareByLabel6(const void *elem1, const void *elem2)
- {
- CStringArray *p1 = (CStringArray*)elem1;
- CStringArray *p2 = (CStringArray*)elem2;
- return atoi(p1->ElementAt(5)) > atoi(p2->ElementAt(5));
- }
- //--------------------------------------------------------------
- // Remark by Jeff 2014.12.16
- // 函数:CheckMemberMsg
- // 描述:
- // 参数:
- // 返回:
- //
- // 调用关系:
- // 1.CheckMemberMsg() 只由 CDBServerDlg::SetTimer(4) 调用,调用频率2分钟,周期数直到程序结束。
- // 2.CDBServerDlg::SetTimer(4) 由 CDBServerDlg::SetTimer(2) 调用,调用频率10毫秒,只有一个周期。
- // 3.CDBServerDlg::SetTimer(2) 由 CDBServerDlg::OnInitDialog() 调用.
- //--------------------------------------------------------------
- void CDBServerDlg::CheckMemberMsg() // Jeff.由定时器SetTimer两分钟执行一次
- {
- try
- {
- CDatabase *pMaindb = NULL;
- ODBCConnGuard ConnGuard( pMaindb, -1, 3000);
- if ( pMaindb == NULL )
- return;
- CString sql = "delete from sendreg where [log]='0/0'";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- {
- CStringArray idarray;
- CString timestamp;
- CTime tm = CTime::GetCurrentTime();
- tm -= CTimeSpan(0, 1, 0, 0);
- timestamp = tm.Format("%Y%m%d%H%M%S");
- CRecordset myset(pMaindb);
- CString sql = "select [autoid] from sendregdelay where [timestamp]<'" + timestamp + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- while (!myset.IsEOF())
- {
- myset.GetFieldValue("autoid", sql);
- idarray.Add(sql);
- myset.MoveNext();
- }
- myset.Close();
- for (int i = 0; i < idarray.GetSize(); i++)
- {
- // Jeff.deal
- //sql.Format("insert into [db].[dbo].sendreg([timestamp],[msgcount],[log],[status],[issended],[isautosend],[phones],[content],[ren]) select [timestamp],[msgcount],[log],[status],[issended],[isautosend],[phones],[content],[ren] from [db].[dbo].sendregdelay where [autoid]=%d", atol(idarray.ElementAt(i)));
- sql.Format("insert into sendreg([msgtype],[timestamp],[msgcount],[log],[status],[issended],[isautosend],[phones],[content],[ren]) select [msgtype],[timestamp],[msgcount],[log],[status],[issended],[isautosend],[phones],[content],[ren] from sendregdelay where [autoid]=%d", atol(idarray.ElementAt(i)));
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- sql.Format("delete from sendregdelay where [autoid]=%d", atol(idarray.ElementAt(i)));
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- }
- int covertrate = 100;
- CString spoint;
- {
- CRecordset myset(pMaindb);
- CString sql = "select * from version";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("rate2", sql);
- myset.Close();
- covertrate = atoi(sql);
- if (covertrate == 0)covertrate = 100;
- }
- CString filter;
- CArray<CStringArray, CStringArray>rulearray;
- CArray<CStringArray, CStringArray>memberarray;
- {
- CRecordset myset(pMaindb);
- CString sql = "select count(*) as cot from msgtemp2";
- if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- rulearray.SetSize(count, 1);
- CRstmsgtemp2 rsSt;
- rsSt.m_pDatabase = pMaindb;
- if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- DWORD ii = 0;
- while (!rsSt.IsEOF())
- {
- rulearray.ElementAt(ii).RemoveAll();
- rulearray.ElementAt(ii).Add(rsSt.name);
- rulearray.ElementAt(ii).Add(rsSt.content1);
- rulearray.ElementAt(ii).Add(rsSt.content2);
- rulearray.ElementAt(ii).Add(rsSt.check1);
- rulearray.ElementAt(ii).Add(rsSt.check2);
- rulearray.ElementAt(ii).Add(rsSt.point);
- ii++;
- rsSt.MoveNext();
- if (rulearray.GetSize() <= ii)break;
- }
- rsSt.Close(); rulearray.SetSize(ii, 1);
- }
- if (rulearray.GetSize() == 0)return;
- qsort(static_cast<void*>(&rulearray[0]), rulearray.GetSize(), sizeof(rulearray[0]), CompareByLabel6);
- /////////////
- {
- CRecordset myset(pMaindb);
- CString sql = "select count(*) as cot from membermanage"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- memberarray.SetSize(atol(sql), 1);
- RstMemberReg rsSt;
- rsSt.m_pDatabase = pMaindb;
- if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- DWORD ii = 0;
- if (covertrate != 100)
- {
- while (!rsSt.IsEOF())
- {
- memberarray.ElementAt(ii).RemoveAll();
- memberarray.ElementAt(ii).Add(rsSt.m_memberno);
- memberarray.ElementAt(ii).Add(rsSt.m_name);
- memberarray.ElementAt(ii).Add(rsSt.m_sex);
- memberarray.ElementAt(ii).Add(rsSt.m_phone);
- spoint.Format("%d", atoi(rsSt.m_money)*covertrate / 100);
- memberarray.ElementAt(ii).Add(spoint);
- memberarray.ElementAt(ii).Add(rsSt.m_sendmark1);
- memberarray.ElementAt(ii).Add(rsSt.m_sendmark2);
- ii++;
- rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break;
- }
- }
- else
- {
- while (!rsSt.IsEOF())
- {
- memberarray.ElementAt(ii).RemoveAll();
- memberarray.ElementAt(ii).Add(rsSt.m_memberno);
- memberarray.ElementAt(ii).Add(rsSt.m_name);
- memberarray.ElementAt(ii).Add(rsSt.m_sex);
- memberarray.ElementAt(ii).Add(rsSt.m_phone);
- memberarray.ElementAt(ii).Add(rsSt.m_money);
- memberarray.ElementAt(ii).Add(rsSt.m_sendmark1);
- memberarray.ElementAt(ii).Add(rsSt.m_sendmark2);
- ii++;
- rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break;
- }
- }
- rsSt.Close(); memberarray.SetSize(ii, 1);
- }
- CString memberno, name, sex, phone, point, mark1, mark2, rulename, rulecheck1, rulecheck2, rulepoint, rulecontent1, rulecontent2;
- for (int i = 0; i < memberarray.GetSize(); i++)
- {
- memberno = memberarray.ElementAt(i).ElementAt(0);
- name = memberarray.ElementAt(i).ElementAt(1);
- sex = memberarray.ElementAt(i).ElementAt(2);
- phone = memberarray.ElementAt(i).ElementAt(3);
- point = memberarray.ElementAt(i).ElementAt(4);
- mark1 = "," + memberarray.ElementAt(i).ElementAt(5) + ",";
- mark2 = "," + memberarray.ElementAt(i).ElementAt(6) + ",";
- if (atoi(point) == 0)continue;
- if (phone.IsEmpty())continue;
- if (-1 == CheckPhoneType(phone))continue;
- int j = 0;
- for (/*int*/ j = 0; j < rulearray.GetSize(); j++)
- {
- if (mark1.GetLength()>4000)break;
- rulename = "," + rulearray.ElementAt(j).ElementAt(0) + ",";
- rulecontent1 = name + rulearray.ElementAt(j).ElementAt(1);
- rulecontent2 = name + rulearray.ElementAt(j).ElementAt(2);
- rulecheck1 = rulearray.ElementAt(j).ElementAt(3);
- rulecheck2 = rulearray.ElementAt(j).ElementAt(4);
- rulepoint = rulearray.ElementAt(j).ElementAt(5);
- if (atoi(rulecheck1) == 0 && atoi(rulecheck2) == 0)continue;
- if (atoi(rulecheck1))
- {
- if (rulecontent1.IsEmpty())continue;
- if (mark1.Find(rulename) != -1)break;
- if (atoi(point) >= atoi(rulepoint))continue;
- if (atoi(point) < atoi(rulepoint) * 80 / 100)continue;
- // if(sex=="男")
- // rulecontent1.Replace ("xxx先生/女士", name+"先生");
- // else
- // rulecontent1.Replace ("xxx先生/女士", name+"女士");
- int count = GetLengthEx(rulecontent1) / MSG_LENGTH;
- if (GetLengthEx(rulecontent1) % MSG_LENGTH)
- count++;
- int phonenum = 1;
- count *= phonenum;
- CString scount;
- scount.Format("%d", count);
- CString timestamp = CTime::GetCurrentTime().Format("%Y%m%d%H%M%S");
- CString sql;
- mark1.TrimLeft(",");
- mark1.TrimRight(",");
- if (mark1.IsEmpty() == 0)
- mark1 += ",";
- rulename.TrimLeft(",");
- rulename.TrimRight(",");
- mark1 += rulename;
- sql = "update membermanage set sendmark1='" + mark1 + "' where memberno='" + memberno + "'";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- mark1 = "," + mark1 + ",";
- sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + phone + "','" + rulecontent1 + "','" + timestamp + "','" + scount + "','0','0','0','系统自动发送')";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- }
- ///////////////////
- BOOL bSended = 0;
- for (j = 0; j < rulearray.GetSize(); j++)
- {
- if (mark2.GetLength() > 4000)break;
- if (bSended)break;
- rulename = "," + rulearray.ElementAt(j).ElementAt(0) + ",";
- rulecontent1 = name + rulearray.ElementAt(j).ElementAt(1);
- rulecontent2 = name + rulearray.ElementAt(j).ElementAt(2);
- rulecheck1 = rulearray.ElementAt(j).ElementAt(3);
- rulecheck2 = rulearray.ElementAt(j).ElementAt(4);
- rulepoint = rulearray.ElementAt(j).ElementAt(5);
- if (atoi(rulecheck1) == 0 && atoi(rulecheck2) == 0)continue;
- if (atoi(rulecheck2))
- {
- if (rulecontent2.IsEmpty())continue;
- if (mark2.Find(rulename) != -1)break;
- if (atoi(point) < atoi(rulepoint))continue;
- // if(sex=="男")
- // rulecontent2.Replace ("xxx先生/女士", name+"先生");
- // else
- // rulecontent2.Replace ("xxx先生/女士", name+"女士");
- int count = GetLengthEx(rulecontent2) / MSG_LENGTH;
- if (GetLengthEx(rulecontent2) % MSG_LENGTH)
- count++;
- int phonenum = 1;
- count *= phonenum;
- CString scount;
- scount.Format("%d", count);
- CString timestamp = CTime::GetCurrentTime().Format("%Y%m%d%H%M%S");
- CString sql;
- mark2.TrimLeft(",");
- mark2.TrimRight(",");
- if (mark2.IsEmpty() == 0)
- mark2 += ",";
- rulename.TrimLeft(",");
- rulename.TrimRight(",");
- mark2 += rulename;
- sql = "update membermanage set sendmark2='" + mark2 + "' where memberno='" + memberno + "'";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- mark2 = "," + mark2 + ",";
- sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + phone + "','" + rulecontent2 + "','" + timestamp + "','" + scount + "','0','0','0','系统自动发送')";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- bSended = 1;
- }
- }
- }
- }
- catch (CDBException *e)
- {
- WriteTextLog(_T("%s-<%d>-%s,%s"), __FILE__, __LINE__, __FUNCTION__, e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- }
- void CDBServerDlg::CheckBakState() // Jeff.检查数据库bakstate表;
- {
- try
- {
- CDatabase* pMaindb = NULL;
- ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
- if ( pMaindb == NULL )
- return;
- CString filter = _T("");
- CArray<CStringArray, CStringArray> strArray;
- CRecordset myset(pMaindb);
- CString sql = "select count(*) as cot from bakstate";
- if (!filter.IsEmpty())
- sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- strArray.SetSize(count, 1);
- //备份记录
- CRstbakstate rsSt;
- rsSt.m_pDatabase = pMaindb;
- if (!filter.IsEmpty())
- rsSt.m_strFilter = filter;
- rsSt.Open();
- int ii = 0;
- while (!rsSt.IsEOF())
- {
- strArray.ElementAt(ii).RemoveAll();
- strArray.ElementAt(ii).Add(rsSt.date);
- strArray.ElementAt(ii).Add(rsSt.photo);
- strArray.ElementAt(ii).Add(rsSt.info);
- ii++;
- rsSt.MoveNext();
- if (strArray.GetSize() <= ii)
- break;
- }
- rsSt.Close();
- //只保存7天记录
- strArray.SetSize(ii, 1);
- while (strArray.GetSize() > 7)
- {
- CString sql = "delete from bakstate where [date]='" + strArray.ElementAt(0).ElementAt(0) + "'";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- strArray.RemoveAt(0);
- }
- CString path = _T("");
- path.Format("%s\\log.txt", g_mainpath);
- if (::PathFileExists(path))
- {
- CString str;
- CStdioFile fp;
- if (fp.Open(path, CFile::modeRead))
- {
- CString temp;
- fp.ReadString(temp);
- CString date = temp;
- date.TrimRight();
- while(!feof(fp.m_pStream))
- {
- fp.ReadString(temp);
- str += temp;
- }
- fp.Close();
- if (date.GetLength() != 10)
- return;
- BOOL bBak = 0;
- int i = 0;
- for (int i = 0; i < strArray.GetSize(); i++)
- {
- if (date == strArray.ElementAt(i).ElementAt(0))
- {
- bBak = 1;
- break;
- }
- }
- if (bBak == 0)
- {
- CString state1 = "0";
- CString state2 = "0";
- if (str.Find("照片备份成功") != -1)state1 = "1";
- if (str.Find("资料备份成功") != -1)state2 = "1";
- sql = "insert into bakstate([date],[photo],[info])values('" + date + "','" + state1 + "','" + state2 + "')";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- else
- {
- CString state1 = "0";
- CString state2 = "0";
- if (str.Find("照片备份成功") != -1)state1 = "1";
- if (str.Find("资料备份成功") != -1)state2 = "1";
- sql = "update bakstate set [photo]='" + state1 + "',[info]='" + state2 + "' where [date]='" + date + "'";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- //判断昨天
- CTime tm = CTime::GetCurrentTime();
- CTimeSpan dt(1, 0, 0, 0);
- tm -= dt;
- CString yesterday = tm.Format("%Y-%m-%d");
- for (i = 0; i < strArray.GetSize(); i++)
- {
- if (yesterday == strArray.ElementAt(i).ElementAt(0))return;
- }
- if (yesterday == date)return;
- sql = "insert into bakstate([date],[photo],[info])values('" + yesterday + "','0','0')";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- else
- {
- CTime tm = CTime::GetCurrentTime();
- CTimeSpan dt(1, 0, 0, 0);
- tm -= dt;
- sql = "insert into bakstate([date],[photo],[info])values('" + tm.Format("%Y-%m-%d") + "','0','0')";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- }
- else
- {
- //昨天没备份,插入一条没有备份的记录
- CTime tm = CTime::GetCurrentTime();
- CTimeSpan dt(1, 0, 0, 0);
- tm -= dt;
- for (int i = 0; i < strArray.GetSize(); i++)
- {
- if (tm.Format("%Y-%m-%d") == strArray.ElementAt(i).ElementAt(0))
- return;
- }
- sql = "insert into bakstate([date],[photo],[info])values('" + tm.Format("%Y-%m-%d") + "','0','0')";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- }
- catch (...)
- {
- WriteTextLog("出错3");
- }
- }
- //数据备份
- CString CDBServerDlg::GetRegCode(int m_id, int m_time1, int m_time2)
- {
- TCHAR DevicePath[260];
- if (FindPort(0, DevicePath) != 0)
- return "";
- int version;
- GetIDVersion((DWORD*)&m_id, &version, DevicePath);
- int d[8]; double f[8];
- int idtemp = 123456;
- char s0[50] = "", s1[50] = "", s2[50] = "", s3[50] = "", s4[50] = "", s5[50] = "", s6[50] = "", s7[50] = "";
- //运行自定义函数
- // SoftKey ytSoftKey;
- int ret = 0;//ytSoftKey.Ini();
- if (ret != 0)
- {
- return "";
- }
- //////////////////////////////////////////////////////////////////////////
- // timedog1是对d0,d1,d2,d3进行3DES加密;
- // 对锁id加密;
- // 对123456加密;
- // 对m_time1可运行时间加密;
- // 对m_time2已运行时间加密;
- ret = ytSoftKey.timedog1(&m_id, &idtemp, &m_time1, &m_time2, &d[4], &d[5], &d[6], &d[7],
- &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
- s0, s1, s2, s3, s4, s5, s6, s7);
- if (ret != 0 && ret != -43)
- {
- return "";
- }
- CString str = "";
- CString temp, temp2;
- /////////////////////////////////////////
- temp.Format("%d", abs(m_id));
- int leng = temp.GetLength();
- if (m_id < 0)
- temp2 = "1";
- else
- temp2 = "0";
- temp = temp2 + temp;
- temp2.Format("%02d", leng);
- temp = temp2 + temp;
- str += temp;
- //////////////////////////////////两位长度, 1为负, 0为正, 数据区
- temp.Format("%d", abs(m_time1));
- leng = temp.GetLength();
- if (m_time1 < 0)
- temp2 = "1";
- else
- temp2 = "0";
- temp = temp2 + temp;
- temp2.Format("%02d", leng);
- temp = temp2 + temp;
- str += temp;
- //////////////////////////////////两位长度, 1为负, 0为正, 数据区
- temp.Format("%d", abs(m_time2));
- leng = temp.GetLength();
- if (m_time2 < 0)
- temp2 = "1";
- else
- temp2 = "0";
- temp = temp2 + temp;
- temp2.Format("%02d", leng);
- temp = temp2 + temp;
- str += temp;
- //////////////////////////////////两位长度, 1为负, 0为正, 数据区
- temp.Format("%d", abs(idtemp));
- leng = temp.GetLength();
- if (idtemp < 0)
- temp2 = "1";
- else
- temp2 = "0";
- temp = temp2 + temp;
- temp2.Format("%02d", leng);
- temp = temp2 + temp;
- str += temp;
- return str;
- }
- int g_ndogtimes = 0;
- void CDBServerDlg::CheckRegCode() // 检查注册码信息;
- {
- char path[MAX_PATH];
- ::GetSystemDirectory(path, MAX_PATH);
- CString sysdir = path;
- sysdir += "\\authcode.txt";
- CStdioFile fp;
- CString authcode;
- if (fp.Open(sysdir, CFile::modeRead))
- {
- fp.ReadString(authcode);
- fp.Close();
- }
- ::DeleteFile(sysdir); // 删除authcode.txt文件;
- authcode.TrimLeft();
- authcode.TrimRight();
- authcode.Replace("\n", "");
- authcode.Replace("\r", "");
- if (authcode.GetLength() != 240)
- {
- return;
- }
- TCHAR DevicePath[260];
- if (FindPort(0, DevicePath) != 0)
- return;
- DWORD OutID;
- int version;
- GetIDVersion(&OutID, &version, DevicePath);
- CString str1, str2, str3, str4, str5;
- str1 = authcode.Mid(0, 48);
- str2 = authcode.Mid(48, 48);
- str3 = authcode.Mid(96, 48);
- str4 = authcode.Mid(144, 48);
- str5 = authcode.Mid(192, 48);
- // SoftKey ytSoftKey;
- int ret = 0;//ytSoftKey.Ini();
- if (ret != 0)
- {
- return;
- }
- int d[8]; double f[8];
- char s0[50] = "", s1[50] = "", s2[50] = "", s3[50] = "", s4[50] = "", s5[50] = "", s6[50] = "", s7[50] = "";
- //运行自定义函数
- sprintf(s0, "%s", str1);
- sprintf(s1, "%s", str2);
- sprintf(s2, "%s", str3);
- sprintf(s3, "%s", str4);
- sprintf(s4, "%s", str5);
- //运行自定义函数
- ret = ytSoftKey.timedog2(&d[0], &d[1], &d[2], &d[3], &d[4], &d[5], &d[6], &d[7],
- &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
- s0, s1, s2, s3, s4, s5, s6, s7);
- if (ret != 0 && ret != -43)
- {
- return;
- }
- str1 = s0;
- str2 = s1;
- str3 = s2;
- str4 = s3;
- str5 = s4;
- authcode = str1;
- authcode += str2;
- authcode += str3;
- authcode += str4;
- authcode += str5;
- str1 += str2;
- str3 += str4;
- DWORD id = atoi(str5.Right(8));
- str5 = str5.Left(12);
- if (id != OutID)
- {
- return;
- }
- TCHAR HKey[50] = "ffffffff", LKey[50] = "ffffffff";
- TCHAR WHKey[41] = "0", WLKey[41] = "0";
- TCHAR year[10], month[10], day[10], hour[10], minute[10], second[10];
- sprintf(WHKey, "%s", str1);
- sprintf(WLKey, "%s", str3);
- CString temp;
- temp = str5.Left(4);
- str5 = str5.Right(8);
- sprintf(year, "%s", temp);
- temp = str5.Left(2);
- str5 = str5.Right(6);
- sprintf(month, "%s", temp);
- temp = str5.Left(2);
- str5 = str5.Right(4);
- sprintf(day, "%s", temp);
- temp = str5.Left(2);
- str5 = str5.Right(2);
- sprintf(hour, "%s", temp);
- sprintf(minute, "%s", str5);
- sprintf(second, "%s", "0");
- ret = WriteTimeAuthToEprom(30128, HKey, LKey, WHKey, WLKey, id, year, month, day, hour, minute, DevicePath);
- if (ret == 0)
- {
- TCHAR year2[10], month2[10], day2[10], hour2[10], minute2[10], second2[10];
- GetRunTimer(year2, month2, day2, hour2, minute2, second2, DevicePath);
- DWORD time1, time2;
- time1 = ConvertStringToTimerReal(year, month, day, hour, minute, second);
- sprintf(second2, "%s", "0");
- time2 = ConvertStringToTimerReal(year2, month2, day2, hour2, minute2, second2);
- if (time1 > time2)
- ConvertTimerToStringReal(time1 - time2, year, month, day, hour, minute, second);
- else
- {
- sprintf(year, "%s", "0");
- sprintf(month, "%s", "0");
- sprintf(day, "%s", "0");
- sprintf(hour, "%s", "0");
- sprintf(minute, "%s", "0");
- }
- g_ndogtimes++;
- // str1.Format ("写入%d次 %d 年 %d 月 %d 日 %d 小时 %d 分", g_ndogtimes, atoi(year), atoi(month), atoi(day), atoi(hour), atoi(minute));
- // WriteTextLog(str1);
- // AfxMessageBox((str1));
- }
- else
- {
- // AfxMessageBox(("授权申请码错误, 请重新向经销商索取!"));
- return;
- }
- }
- BOOL IsCtrlDown()
- {
- short state = GetKeyState(VK_LCONTROL);
- BYTE sta = (BYTE)(state >> 8);
- state = GetKeyState(VK_RCONTROL);
- BYTE sta2 = (BYTE)(state >> 8);
- if (sta || sta2)
- return 1;
- else
- return 0;
- }
- //extern CTime GetTmFromStr(CString date);
- BOOL CDBServerDlg::PreTranslateMessage(MSG* pMsg)
- {
- if (pMsg->message == WM_KEYDOWN)
- {
- switch (pMsg->wParam)
- {
- case 67:
- AfxMessageBox("c");
- break;
- case VK_F8:
- if (IsCtrlDown())GenYLGL();
- break;
- case VK_F9:
- if (IsCtrlDown())
- {
- CString g_domain;
- CArray<CStringArray, CStringArray>g_List1array;
- CString autorunpath = g_mainpath + "\\branchdindan.dat";
- CFile fp;
- if (fp.Open(autorunpath, CFile::modeRead))
- {
- int nMessageLen = fp.GetLength();
- BYTE *pData = new BYTE[nMessageLen];
- fp.Read(pData, nMessageLen);
- fp.Close();
- BYTE *szChatMessage = pData;
- int count;
- memcpy(&count, szChatMessage + (nMessageLen - sizeof(int)), sizeof(int));
- CMemFile memfile;
- memfile.Attach(szChatMessage, nMessageLen);
- CArchive ar(&memfile, CArchive::load);
- g_List1array.SetSize(count);
- for (int ii = 0; ii < g_List1array.GetSize(); ii++)
- {
- g_List1array.ElementAt(ii).Serialize(ar);
- }
- ar.Close();
- memfile.Detach();
- delete[]pData;
- }
- CString time5, id;
- for (int i = 0; i < g_List1array.GetSize(); i++)
- {
- g_domain = "\\" + g_List1array.ElementAt(i).ElementAt(0);
- id = g_List1array.ElementAt(i).ElementAt(1);
- time5 = g_List1array.ElementAt(i).ElementAt(2);
- WriteTextLog(g_domain + "\\" + id + time5);
- }
- }
- break;
- #ifdef LYFZ_VERSION
- case VK_F7:
- if (IsCtrlDown())
- {
- if (AfxMessageBox("是否继续?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return 1;
- CStringArray array1;
- CRstDindanForm rsSt; rsSt.m_pDatabase = &g_db;
- rsSt.Open();
- while (!rsSt.IsEOF())
- {
- array1.Add(rsSt.id);
- rsSt.MoveNext();
- }
- rsSt.Close();
- CString id, sql;
- sql.Format("update dindan set status5='%s'", "无");
- MyExecuteSQL(&g_db, sql);
- BOOL bHasPhoto = 0;
- for (int i = 0; i < array1.GetSize(); i++)
- {
- id = array1.ElementAt(i);
- bHasPhoto = 0;
- CRstClientPhoto rsSt;
- rsSt.m_strFilter = "id='" + id + "'";
- rsSt.Open();
- if (rsSt.photo.m_dwDataLength>0)
- {
- bHasPhoto = 1;
- }
- rsSt.Close();
- if (bHasPhoto)
- {
- sql.Format("update dindan set status5='%s' where id='%s'", "有", id);
- MyExecuteSQL(&g_db, sql);
- }
- }
- /* CStringArray array1,array2;
- CRstDindanForm rsSt; rsSt.m_pDatabase=&g_db;
- rsSt.Open();
- while(!rsSt.IsEOF())
- {
- array1.Add(rsSt.id) ;
- array2.Add(rsSt.time4) ;
- rsSt.MoveNext();
- }
- rsSt.Close();
- CString id,time4,time2,sql;
- for(int i=0; i<array1.GetSize(); i++)
- {
- id=array1.ElementAt(i);
- time4=array2.ElementAt(i);
- if(time4.GetLength()==10)
- {
- CTime tm=GetTmFromStr(time4);
- CTimeSpan dt(365, 0, 0, 0);
- CTime tm2=tm-dt;
- time2=tm2.Format("%Y-%m-%d");
- sql.Format("update dindan set time2='%s' where id='%s'", time2, id);
- MyExecuteSQL(&g_db, sql);
- }
- }*/
- AfxMessageBox("完成");
- }
- break;
- #endif //#ifdef LYFZ_VERSION
- case VK_F2:
- if (IsCtrlDown())
- {
- SelYear dlg;
- if (dlg.DoModal() != IDOK)return 1;
- int year = dlg.m_year;
- int hisyear = CTime::GetCurrentTime().GetYear() - 1;
- if (year == hisyear)
- {
- AfxMessageBox("不能选该年");
- return 1;
- }
- CString str;
- str.Format("此操作将%d年数据导入%d中, 确认吗?", year, hisyear);
- if (AfxMessageBox(str, MB_YESNO | MB_ICONINFORMATION) != IDYES)return 1;
- CDatabase *pdb = GetDB(year);
- if (pdb == NULL)
- {
- str.Format("没有找到%d, 操作失败", year);
- AfxMessageBox(str); return 1;
- }
- str.Format("开始%d->%d", year, hisyear);
- WriteTextLog(str);
- CheckHistoryData(pdb, year);
- str.Format("%d->%d完成", year, hisyear);
- WriteTextLog(str);
- }
- break;
- case VK_F3:
- if (IsCtrlDown())
- {
- SelYear dlg;
- if (dlg.DoModal() != IDOK)return 1;
- int year = dlg.m_year;
- int hisyear = CTime::GetCurrentTime().GetYear() - 1;
- if (year == hisyear)
- {
- AfxMessageBox("不能选该年");
- return 1;
- }
- CString str;
- str.Format("此操作将%d年数据导入%d中(当前数据库中没有的订单全转), 确认吗?", year, hisyear);
- if (AfxMessageBox(str, MB_YESNO | MB_ICONINFORMATION) != IDYES)return 1;
- CDatabase *pdb = GetDB(year);
- if (pdb == NULL)
- {
- str.Format("没有找到%d, 操作失败", year);
- AfxMessageBox(str); return 1;
- }
- str.Format("开始%d->%d", year, hisyear);
- WriteTextLog(str);
- CheckHistoryData(pdb, year, 1);
- str.Format("%d->%d完成", year, hisyear);
- WriteTextLog(str);
- }
- break;
- case VK_F1:
- CString str;
- if (g_conniparray.GetSize() == 0)str = "当前无客户端连接至服务器!";
- for (int i = 0; i < g_conniparray.GetSize(); i++)
- {
- str += "\r\n连接ip:" + g_conniparray.ElementAt(i);
- }
- AfxMessageBox(str);
- #ifdef CONNCOUNT_VERSION
- // CStringArray g_conniparray;
- #endif //#ifdef CONNCOUNT_VERSION
- return 1;
- }
- }
- return CDialog::PreTranslateMessage(pMsg);
- }
- void CDBServerDlg::GenUPhoneData()
- {
- MyLock lock("processChatMessageRequestxiao");
- CArray<int, int>codearray;
- codearray.Add(80);
- codearray.Add(90);
- codearray.Add(11);
- codearray.Add(138);
- codearray.Add(24);
- codearray.Add(181);
- codearray.Add(65);
- codearray.Add(56);
- codearray.Add(179);
- codearray.Add(53);
- CFile fp;
- CString savepath, g_path1;
- char server[50];
- DWORD leng = 50;
- ::GetComputerName(server, &leng);
- g_path1 = server;
- g_path1 = "\\\\" + g_path1 + "\\电话录音(管理软件)$";
- GetPathFromNetShareName("电话录音(管理软件)$", g_path1);
- if (g_path1.IsEmpty())
- {
- WriteTextLog("获取电精灵数据出错");
- return;
- }
- try
- {
- int aa = 0;
- CDatabase *pMaindb = NULL;
- ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
- if ( pMaindb == NULL )
- return;
- savepath.Format("%s\\uphonedata%d.dat", g_path1, aa);
- ::DeleteFile(savepath); // 删除 uphonedata%d.dat 文件;
- if (fp.Open(savepath, CFile::modeCreate | CFile::modeWrite) == 0)
- {
- WriteTextLog("更新来电精灵数据出错");
- return;
- }
- CConnectSocket consock;
- consock.m_pConndb = pMaindb;
- for (int i = 0; i < codearray.GetSize(); i++)
- {
- BYTE code = codearray.ElementAt(i);
- DWORD length, arraysize;
- BYTE *pReturn = NULL;
- consock.GetDataFromCode(code, &pReturn, length, arraysize, "");
- fp.Write(&code, sizeof(BYTE));
- fp.Write(&length, sizeof(DWORD));
- fp.Write(&arraysize, sizeof(DWORD));
- fp.Write(pReturn, length);
- }
- fp.Close();
- }
- catch (...)
- {
- WriteTextLog("获取来电精灵数据出错2");
- }
- }
- //initlia
- void CDBServerDlg::LoadHistoryDB() // 加载历史数据库;
- {
- CString path;
- CString sql;
- sql = "delete from historydb";
- CDatabase *pdb = NULL;
- ODBCConnGuard ConnGuard(pdb, -1, 3000);
- if ( pdb ) MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pdb, sql);
- CDatabase g_masterdb;
- try
- {
- CString strCon;
- strCon.Format(DB_SS_CONN_WITHOUT_PORT, g_strdbServrename, _T("master"), g_szDBAccount, g_szDBPassWord);
- g_masterdb.OpenEx(strCon, CDatabase::noOdbcDialog);
- }
- catch (CDBException * e)
- {
- #ifdef _DEBUG
- e->ReportError();
- #endif //#ifdef _DEBUG
- e->Delete();
- }
- TCHAR szdbName[MAX_PATH] = {0};
- for (int i = CTime::GetCurrentTime().GetYear() - 1; i >= 2009; i--)
- {
- #if USE_POOL
- _itot_s(i, szdbName, 10);
- CODBCPool *pdbpool = new CODBCPool;
- if ( pdbpool->InitializePool(g_szDBSource, g_dwDBServerPort, g_szDBAccount, g_szDBPassWord, szdbName, g_dwDBPoolDef, g_dwDBPoolMaxCount))
- {
- g_nYearArray.Add(i);
- sql.Format("insert into [historydb]([year])values('%d')", i);
- CDatabase *pdb = NULL;
- ODBCConnGuard ConnGuard(pdb, -1, 3000);
- if ( pdb )MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pdb, sql);
- g_dbpool.Add(pdbpool);
- }
- else
- {
- delete pdbpool;
- pdbpool = NULL;
- CString strPathOfYearmdf;
- CString strPathOfYearldf;
- CString sql;
- strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, i);
- strPathOfYearldf.Format("%s\\数据\\%d_log.LDF", g_mainpath, i);
- if (PathFileExists(strPathOfYearmdf))
- {
- BOOL bLog = 0;
- if (PathFileExists(strPathOfYearldf))
- {
- bLog = 1;
- }
- g_masterdb.SetQueryTimeout(600);
- if (bLog)
- sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", i, strPathOfYearmdf, strPathOfYearldf);
- else
- sql.Format("exec sp_attach_db '%d',@filename1='%s'", i, strPathOfYearmdf);
- try
- {
- g_masterdb.ExecuteSQL(sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog("历史数据库初始化失败,%s",e->m_strError);
- g_masterdb.SetQueryTimeout(100);
- #ifdef _DEBUG
- e->ReportError();
- #endif //#ifdef _DEBUG
- e->Delete();
- break;
- }
- g_masterdb.SetQueryTimeout(100);
- if ( pdbpool->InitializePool(g_szDBSource, g_dwDBServerPort, g_szDBAccount, g_szDBPassWord, szdbName, g_dwDBPoolDef, g_dwDBPoolMaxCount))
- {
- g_nYearArray.Add(i);
- sql.Format("insert into [historydb]([year])values('%d')", i);
- CDatabase *pdb = NULL;
- ODBCConnGuard ConnGuard(pdb, -1, 3000);
- if ( pdb )MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pdb, sql);
- g_dbpool.Add(pdbpool);
- }
- else
- {
- delete pdbpool;
- }
- }
- }
- #else
- CDatabase *db = new CDatabase;
- try
- {
- CString strCon;
- //strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=%d;%s"), g_strdbServrename, i, g_strdbpsw);
- if ( _tcscmp(g_szDBAccount, _T("")) == 0)
- strCon.Format(DB_SW_CONN_WITHOUT_PORT2, g_strdbServrename, i);
- else
- strCon.Format(DB_SS_CONN_WITHOUT_PORT2, g_strdbServrename, i, g_szDBAccount, g_szDBPassWord);
- db->OpenEx(strCon, CDatabase::noOdbcDialog);
- g_nYearArray.Add(i);
- g_dbHistoryArray.Add(db);
- sql.Format("insert into [historydb]([year])values('%d')", i);
- MyExecuteSQL(&g_db, sql);
- }
- catch (CDBException * e)
- {
- #ifdef _DEBUG
- e->ReportError();
- #endif //#ifdef _DEBUG
- CString strPathOfYearmdf;
- CString strPathOfYearldf;
- CString sql;
- strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, i);
- strPathOfYearldf.Format("%s\\数据\\%d_log.LDF", g_mainpath, i);
- if (PathFileExists(strPathOfYearmdf))
- {
- BOOL bLog = 0;
- if (PathFileExists(strPathOfYearldf))
- {
- bLog = 1;
- }
- g_masterdb.SetQueryTimeout(600);
- if (bLog)
- sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", i, strPathOfYearmdf, strPathOfYearldf);
- else
- sql.Format("exec sp_attach_db '%d',@filename1='%s'", i, strPathOfYearmdf);
- try
- {
- g_masterdb.ExecuteSQL(sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- WriteTextLog("历史数据库初始化失败!!");
- g_masterdb.SetQueryTimeout(100);
- #ifdef _DEBUG
- e->ReportError();
- #endif //#ifdef _DEBUG
- e->Delete();
- break;
- }
- g_masterdb.SetQueryTimeout(100);
- CString strCon;
- //strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=%d;%s"), g_strdbServrename, i, g_strdbpsw);
- if ( _tcscmp(g_szDBAccount, _T("")) == 0)
- strCon.Format(DB_SW_CONN_WITHOUT_PORT2, g_strdbServrename, i);
- else
- strCon.Format(DB_SS_CONN_WITHOUT_PORT2, g_strdbServrename, i, g_szDBAccount, g_szDBPassWord);
- db->OpenEx(strCon, CDatabase::noOdbcDialog);
- g_nYearArray.Add(i);
- g_dbHistoryArray.Add(db);
- sql.Format("insert into [historydb]([year])values('%d')", i);
- MyExecuteSQL(&g_db, sql);
- }
- else
- {
- //e->ReportError();
- e->Delete();
- //break;
- }
- }
- #endif
- }
- g_masterdb.Close();
- }
- void CDBServerDlg::AddOneConn()
- {
- #if 0
- try
- {
- MyLock lock("AddOneConnxiao");
- if (g_nDBCount >= 200)
- {
- WriteTextLog("连接超数!"); return;
- }
- CDatabase *db = new CDatabase;
- //if(AddConn(db, "db")==0)// Jeff.deal;
- if (AddConn(db, g_szDBName) == 0)
- return;
- g_pDB[g_nDBCount] = db;
- CString dbname = _T("");
- for (int i = 0; i < g_nYearArray.GetSize(); i++)
- {
- dbname.Format("%d", g_nYearArray.ElementAt(i));
- CDatabase *db = new CDatabase;
- AddConn(db, dbname);
- g_pHistoryDBarray[g_nDBCount].Add(db);
- }
- AddAdoConn();
- g_nDBCount++;
- }
- catch (CException *e)
- {
- TCHAR szError[1024] = { 0 };
- e->GetErrorMessage(szError, 1024);
- WriteTextLog("AddOneConn error" + CString(szError));
- }
- #endif
- }
- /////////////////////////////////////////////////////////////////////////////////////
- /*
- 函数名: AddAdoConn
- 说明: 添加Logdb数据库连接
- 参数:
- 返回:
- */
- /////////////////////////////////////////////////////////////////////////////////////
- void CDBServerDlg::AddAdoConn()
- {
- }
- void GetOneConn(CDatabase **m_pdb, CArray<CDatabase*, CDatabase*>*m_dbarray, CConnectThread *pThread)
- {
- #if 0
- MyLock lock("GetOneConnxiao");
- ll: for (int i = 0; i < 200; i++)
- {
- if (g_pDB[i] != NULL && g_pThreadPt[i] == NULL)
- {
- *m_pdb = g_pDB[i];
- m_dbarray->Copy(g_pHistoryDBarray[i]);
- g_pThreadPt[i] = pThread;
- return;
- }
- }
- if (g_nDBCount >= 200)
- {
- WriteTextLog("连接超数2!");
- *m_pdb = &g_db;
- m_dbarray->Copy(g_dbHistoryArray);
- return;
- }
- g_pMainWnd->AddOneConn();
- ::Sleep(1000);
- goto ll;
- #endif
- }
- void CDBServerDlg::CheckConnCount()
- {
- int count = 0;
- for (int i = 0; i < 200; i++)
- {
- if (g_pDB[i] != NULL && g_pThreadPt[i] == NULL)
- {
- count++;
- if (count > 9)
- return;
- }
- }
- AddOneConn();
- }
- //delete from 背景.jpg
- void CDBServerDlg::RestoreHQ()
- {
- CString sql;
- CDatabase *pMaindb = NULL;
- ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
- if ( pMaindb == NULL )
- return;
- DWORD ii = 0;
- CArray<CStringArray, CStringArray>g_List1array;
- {
- CRecordset myset(pMaindb);
- CString sql = "select count(*) as cot from dindan";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- g_List1array.SetSize(count, 1);
- CRstDindanForm rsSt;
- rsSt.m_pDatabase = pMaindb;
- rsSt.Open();
- ii = 0;
- while (!rsSt.IsEOF())
- {
- g_List1array.ElementAt(ii).RemoveAll();
- g_List1array.ElementAt(ii).Add(rsSt.id);
- ii++;
- rsSt.MoveNext(); if (g_List1array.GetSize() <= ii)break;
- }
- rsSt.Close(); g_List1array.SetSize(ii, 1);
- }
- for (int i = 0; i < g_List1array.GetSize(); i++)
- {
- // int ret=TransDinDan(pdb1, pdb2, g_List1array.ElementAt (i).ElementAt (0), lastyear);
- // Jeff.deal;
- //sql.Format("SELECT distinct [name],[count] FROM [db].[dbo].[dindansp2] where id='%s' and name in(select spname from shangpin where splb='婚庆服务')", g_List1array.ElementAt (i).ElementAt (0));
- sql.Format("SELECT distinct [name],[count] FROM [dbo].[dindansp2] where id='%s' and name in(select spname from shangpin where splb='婚庆服务')", g_List1array.ElementAt(i).ElementAt(0));
- CRecordset myset(pMaindb);
- myset.Open(CRecordset::forwardOnly, sql);
- CStringArray namearray;
- CStringArray countarray;
- while (!myset.IsEOF())
- {
- sql = "";
- myset.GetFieldValue("name", sql);
- namearray.Add(sql);
- sql = "";
- myset.GetFieldValue("count", sql);
- countarray.Add(sql);
- myset.MoveNext();
- }
- myset.Close();
- for (int j = 0; j < namearray.GetSize(); j++)
- {
- CString spid, spjiage2;
- // WriteTextLog("name:"+namearray.ElementAt (j));
- // Jeff.deal;
- //sql.Format("SELECT [spid],[spjiage2] FROM [db].[dbo].[shangpin] where spname='%s'", namearray.ElementAt (j));
- sql.Format("SELECT [spid],[spjiage2] FROM [dbo].[shangpin] where spname='%s'", namearray.ElementAt(j));
- //WriteTextLog(sql);
- CRecordset myset(pMaindb);
- myset.Open(CRecordset::forwardOnly, sql);
- if (!myset.IsEOF())
- {
- myset.GetFieldValue("spid", spid);
- myset.GetFieldValue("spjiage2", spjiage2);
- }
- myset.Close();
- // Jeff.deal;
- //sql.Format("SELECT count(*) as cot FROM [db].[dbo].[dindansp] where name='%s' and id='%s' and kind='2'", namearray.ElementAt (j), g_List1array.ElementAt (i).ElementAt (0));
- sql.Format("SELECT count(*) as cot FROM [dbo].[dindansp] where name='%s' and id='%s' and kind='2'", namearray.ElementAt(j), g_List1array.ElementAt(i).ElementAt(0));
- myset.Open(CRecordset::forwardOnly, sql);
- sql = "";
- if (!myset.IsEOF())
- {
- myset.GetFieldValue("cot", sql);
- }
- myset.Close();
- if (atoi(sql))continue;
- sql.Format("insert into [dindansp]([id],[name],[shuliang],[price],[spid],[kind])values('%s','%s','%s','%s','%s','%s')",
- g_List1array.ElementAt(i).ElementAt(0), namearray.ElementAt(j), countarray.ElementAt(j), spjiage2, spid, "2");
- //WriteTextLog(sql);
- pMaindb->ExecuteSQL(sql);
- }
- }
- }
- void CDBServerDlg::ManagePhoto()
- {
- // CClientCenter dlg1;
- // dlg1.DoModal ();
- ShowPic3 dlg;
- dlg.DoModal();
- }
- //数据备份(管理软件)$
- //10.lia
- //----------------------------------------------------------------------------
- // Remark by Jeff 2014.10.22
- // 函数:GenYLGL
- // 描述:调用本地客户端;
- // 参数:#
- // 返回:#
- //
- // 调用关系:
- // 1.只由AutoDelPhoto()主动调用。
- //
- // 说明:传递genbranchdata给客户端,使客户端能够自动遍历branchinfo.dat里的分店信息,
- // 客户端顺序连接所有分店并获取分店历史订单已完成取件的订单。最终将所有分店历史
- // 订单已完成取件的送回服务端,保存在branchdindan2.dat中.
- //----------------------------------------------------------------------------
- void CDBServerDlg::GenYLGL()
- {
- // 1.Jeff.删除文件,g_mainpath服务器DBServer.exe的目录;
- CString autorunpath = g_mainpath + "\\YLGL.exe";
- ::DeleteFile(autorunpath); // 删除YLGL.exe
- WriteTextLog("命令行启动:" + autorunpath);
- // 2.重新生成YLGL.exe
- CDatabase *pdb = NULL;
- ODBCConnGuard ConnGuard(pdb, -1, 3000);
- if ( pdb = NULL )
- return;
- CRstUpdate rsSt;
- rsSt.m_pDatabase = pdb;
- rsSt.Open();
- if (!rsSt.IsEOF())
- {
- CFile fp;
- if (fp.Open(autorunpath, CFile::modeCreate | CFile::modeWrite))
- {
- void *pData = GlobalLock(rsSt.data.m_hData);
- fp.Write(pData, rsSt.data.m_dwDataLength);
- fp.Close();
- GlobalUnlock(rsSt.data.m_hData);
- }
- }
- rsSt.Close();
- // 3.执行YLGL.exe
- ShellExecute(NULL, _T("open"), autorunpath, "genbranchdata", NULL, SW_HIDE);
- }
- //105
- /************************************************************************/
- /*
- 函数:CheckSvcWork
- 描述:检查服务工作
- 参数:
- LPVOID LPARAM
- 返回:
- */
- /************************************************************************/
- unsigned int CDBServerDlg::CheckSvcWork(LPVOID LPARAM)
- {
- CDBServerDlg* p = (CDBServerDlg*)LPARAM;
- if(p != NULL)
- {
- while(1)
- {
- // 每小时检查一次
- int nRet = WaitForSingleObject(p->m_hWaitTimeOut, 60*60*1000);
- if(nRet != WAIT_OBJECT_0 && nRet != WAIT_TIMEOUT)
- {
- WriteTextLog(_T("检测服务3错误:%d\n"), GetLastError());
- break;
- }
- if(WaitForSingleObject(p->m_hExitCheckSvc, 0) == WAIT_OBJECT_0)
- break;
- CString strPath = _T("");
- DWORD dwID = 0;
- // 自动备份
- dwID = FindAppProcessID(_T("lyfzBackupSvc.exe"));
- if(dwID == 0)
- {
- strPath = g_mainpath + _T("\\lyfzBackupSvc.exe");
- CString strCmd = _T("/startsvc");
- SHELLEXECUTEINFO execinfo;
- memset(&execinfo, 0, sizeof(execinfo));
- execinfo.lpFile = strPath;
- execinfo.cbSize = sizeof(execinfo);
- execinfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
- execinfo.nShow = SW_HIDE;
- execinfo.lpParameters = strCmd;
- if(!ShellExecuteEx(&execinfo))
- {
- CString strError = _T("");
- strError.Format(_T("检测服务1错误:%d\n"), GetLastError());
- OutputDebugString(strError);
- }
- // WaitForSingleObject(execinfo.hProcess,INFINITE);
- }
- // 自动删除
- dwID = FindAppProcessID(_T("lyfzDeletePhotoSvc.exe"));
- if(dwID == 0)
- {
- strPath = g_mainpath + _T("\\lyfzDeletePhotoSvc.exe");
- CString strCmd = _T("/startsvc");
- SHELLEXECUTEINFO execinfo;
- memset(&execinfo, 0, sizeof(execinfo));
- execinfo.lpFile = strPath;
- execinfo.cbSize = sizeof(execinfo);
- execinfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
- execinfo.nShow = SW_HIDE;
- execinfo.lpParameters = strCmd;
- if(!ShellExecuteEx(&execinfo))
- {
- WriteTextLog(_T("检测服务2错误:%d\n"), GetLastError());
- }
- // WaitForSingleObject(execinfo.hProcess,INFINITE);
- }
- }
- }
- _endthreadex(0);
- return 0;
- }
- // 结束检查工作
- void CDBServerDlg::TerminateCheckWork()
- {
- if(m_hExitCheckSvc)
- SetEvent(m_hExitCheckSvc);
- if(m_hWaitTimeOut)
- SetEvent(m_hWaitTimeOut);
- if(m_hCheckSvcThread)
- {
- WaitForSingleObject(m_hCheckSvcThread, INFINITE);
- CloseHandle(m_hCheckSvcThread);
- }
- m_hCheckSvcThread = NULL;
- if(m_hExitCheckSvc)
- CloseHandle(m_hExitCheckSvc);
- m_hExitCheckSvc = NULL;
- if(m_hWaitTimeOut)
- CloseHandle(m_hWaitTimeOut);
- m_hWaitTimeOut = NULL;
- m_bStartCheckSvc = FALSE;
- }
- /************************************************************************/
- /*
- 函数:OnStartBackupSvc
- 描述:启动备份服务
- 参数:
- 返回:
- */
- /************************************************************************/
- void CDBServerDlg::OnStartBackupSvc()
- {
- StartSvc(_T("lyfzBackupSvc.exe"));
- }
- /************************************************************************/
- /*
- 函数:OnStopBackupSvc
- 描述:停止备份服务
- 参数:
- 返回:
- */
- /************************************************************************/
- void CDBServerDlg::OnStopBackupSvc()
- {
- StopSvc(_T("lyfz Backup Service"));
- }
- /************************************************************************/
- /*
- 函数:OnStartDelPhotoSvc
- 描述:启动删除服务
- 参数:
- 返回:
- */
- /************************************************************************/
- void CDBServerDlg::OnStartDelPhotoSvc()
- {
- StartSvc(_T("lyfzDeletePhotoSvc.exe"));
- }
- /************************************************************************/
- /*
- 函数:OnStopDelPhotoSvc
- 描述:停止删除服务
- 参数:
- 返回:
- */
- /************************************************************************/
- void CDBServerDlg::OnStopDelPhotoSvc()
- {
- StopSvc(_T("lyfz Delete Photo Service"));
- }
- /************************************************************************/
- /*
- 函数:StartSvc
- 描述:启动服务
- 参数:
- IN LPCSTR lpExeFile 程序名称
- 返回:1成功,0失败
- */
- /************************************************************************/
- int CDBServerDlg::StartSvc( IN LPCSTR lpExeFile)
- {
- CString strPath = _T("");
- DWORD dwID = 0;
- // 自动备份
- dwID = FindAppProcessID(lpExeFile);
- if(dwID == 0)
- {
- strPath = g_mainpath + _T("\\");
- strPath += lpExeFile;
- CString strCmd = _T("/startsvc");
- SHELLEXECUTEINFO execinfo;
- memset(&execinfo, 0, sizeof(execinfo));
- execinfo.lpFile = strPath;
- execinfo.cbSize = sizeof(execinfo);
- execinfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
- execinfo.nShow = SW_HIDE;
- execinfo.lpParameters = strCmd;
- if(!ShellExecuteEx(&execinfo))
- {
- CString strError = _T("");
- strError.Format(_T("检测服务%s错误:%d\n"), lpExeFile, GetLastError());
- OutputDebugString(strError);
- }
- }
- return 1;
- }
- // 停止服务
- /************************************************************************/
- /*
- 函数:OnStopDelPhotoSvc
- 描述:停止删除服务
- 参数:
- IN LPCSTR lpSvcName 服务名
- 返回:1成功,0失败
- */
- /************************************************************************/
- int CDBServerDlg::StopSvc(IN LPCSTR lpSvcName)
- {
- CString strError = _T("");
- SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
- if (hSCM == NULL)
- return 0;
- SC_HANDLE hService = ::OpenService(hSCM, lpSvcName, SERVICE_STOP | SERVICE_QUERY_STATUS);
- if (hService == NULL)
- {
- strError.Format(_T("打开%s服务失败:%d"), lpSvcName, GetLastError());
- OutputDebugString(strError);
- ::CloseServiceHandle(hSCM);
- return 0;
- }
- SERVICE_STATUS status;
- if(!::QueryServiceStatus(hService, &status))
- {
- strError.Format(_T("获取%s服务状态失败:%d"), lpSvcName, GetLastError());
- OutputDebugString(strError);
- ::CloseServiceHandle(hService);
- ::CloseServiceHandle(hSCM);
- return 0;
- }
- if(status.dwCurrentState == SERVICE_STOPPED)
- {
- ::CloseServiceHandle(hService);
- ::CloseServiceHandle(hSCM);
- return 1;
- }
- ControlService(hService, SERVICE_CONTROL_STOP, &status);
- DWORD dwStartTime = GetTickCount();
- DWORD dwTimeout = 30*1000; // 30-second time-out
- while(1)
- {
- Sleep( status.dwWaitHint );
- if(!::QueryServiceStatus(hService, &status))
- {
- strError.Format(_T("获取%s服务状态失败:%d"), lpSvcName, GetLastError());
- OutputDebugString(strError);
- ::CloseServiceHandle(hService);
- ::CloseServiceHandle(hSCM);
- return 0;
- }
- if ( status.dwCurrentState == SERVICE_STOPPED )
- break;
- if ( GetTickCount() - dwStartTime > dwTimeout )
- {
- strError.Format(_T("停止%s服务超时:%d"), lpSvcName, GetLastError());
- OutputDebugString(strError);
- ::CloseServiceHandle(hService);
- ::CloseServiceHandle(hSCM);
- return 0;
- }
- }
- ::CloseServiceHandle(hService);
- ::CloseServiceHandle(hSCM);
- return 1;
- }
- void CDBServerDlg::OnAutoCheckSvc()
- {
- g_bAutoCheckSvc = !g_bAutoCheckSvc;
- CHAR szFile[MAX_PATH + 1] = "";
- wsprintf(szFile, "%s\\ServiceInfo.ini", g_ModulePath);
- OFSTRUCT ofStruct;
- OpenFile(szFile, &ofStruct, OF_EXIST);
- if (ERROR_FILE_NOT_FOUND == GetLastError())
- return;
- CString strValue = _T("");
- strValue.Format(_T("%d"), g_bAutoCheckSvc);
- WritePrivateProfileString(_T("Back"), _T("AutoCheckSvc"), strValue, szFile);
- if(!g_bAutoCheckSvc)
- {
- TerminateCheckWork();
- }
- else
- {
- // 如果没启动自动检查
- if(!m_bStartCheckSvc)
- {
- m_hExitCheckSvc = CreateEvent(NULL, FALSE, FALSE, NULL);
- m_hWaitTimeOut = CreateEvent(NULL, FALSE, FALSE, NULL);
- SetEvent(m_hWaitTimeOut);
- unsigned int nThreadID = 0;
- m_bStartCheckSvc = TRUE;
- m_hCheckSvcThread = (HANDLE)_beginthreadex(NULL, 0, CheckSvcWork, this, 0, &nThreadID);
- }
- }
- }
|