DBServerDlg.cpp 193 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322
  1. /****************************************************************/
  2. /* */
  3. /* ApplicationDlg.cpp */
  4. /* */
  5. /* Implementation of the CDBServerDlg class. */
  6. /* This class is a part of the Date Server. */
  7. /* */
  8. /* Programmed by LYFZ van der Meer */
  9. /* Copyright LYFZ Software Solutions 2002 */
  10. /* http://www.LYFZvandermeer.nl */
  11. /* */
  12. /* Last updated: 10 july 2002 */
  13. /* */
  14. /****************************************************************/
  15. //在ApplicationDlg.cpp文件中实现主窗口界面的设计。及其主窗口相应控件的功能和参数的映射。 D4F876E2-w78F-22D5-q98A-Y0B0D07B847C
  16. #include "stdafx.h"
  17. #include "DBServer.h"
  18. #include "theDBServer.h"
  19. #include "DBServerDlg.h"
  20. //#include "UserAccountsDlg.h"
  21. //#include "WizardPages.h"
  22. #include "AboutDlg.h"
  23. #include <afxpriv.h>
  24. #include <process.h>
  25. //#include "Shlwapi.h"
  26. #include "ClientCenter.h"
  27. #include "MyLock.h"
  28. #include "mysqldata.h"
  29. #include "./helper/ffsco.h"
  30. //#include <tlhelp32.h>
  31. #include "ShowPic3.h"
  32. #include "my32.h"
  33. #include "SoftKey.h"
  34. #include "DogTimeOutDlg.h"
  35. #include "InputAuthDlg.h"
  36. #include "AdoImplSvr.h"
  37. #include "CreateSmallPhoto.h"
  38. #include "PhotoBackupMgr.h"
  39. #include <WinSvc.h>
  40. #include "ConnectThread.h"
  41. #pragma comment(lib, "NETAPI32.LIB ")
  42. #include "SelYear.h"
  43. #include "BranchInfo.h"
  44. using namespace helper_coffs;
  45. /*********ErrorExit(...)函数头文件************/
  46. //#include <strsafe.h>
  47. /***********************************/
  48. #ifdef _DEBUG
  49. #define new DEBUG_NEW
  50. #undef THIS_FILE
  51. static char THIS_FILE[] = __FILE__;
  52. #endif
  53. #define LIMITCOUNT 1 //历史数据每次转10个 autorun
  54. extern BOOL g_bSteal;
  55. extern BOOL g_bConvertHisAll;
  56. extern CDBServer theApp;
  57. extern CtheDBServer theServer;
  58. #define WM_ICON_NOTIFY WM_USER+12
  59. CDBServerDlg *g_pMainWnd = NULL;
  60. //#define IPC_CUSTOM_MSG2 _T("{D4F876E2-w78F-22D5-q98A-Y0B0D07B847C}")
  61. #define IPC_CUSTOM_MSG2 _T("{E4F876E2-Q78F-22D5-C98A-Y0B0D07B847C}")
  62. UINT g_wmClose = RegisterWindowMessage(IPC_CUSTOM_MSG2);
  63. //extern BOOL EncryptFile2(BYTE *buffer, DWORD leng, PCHAR szPassword);
  64. //extern CStringArray g_conniparray;
  65. CArray<CDatabase*, CDatabase*>g_pHistoryDBarray[200];
  66. CDatabase *g_pDB[200];
  67. CConnectThread *g_pThreadPt[200];
  68. int g_nDBCount = 0;
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CDBServerDlg dialog
  71. #pragma comment(lib, "Shlwapi.lib")
  72. extern DWORD g_nSendCode;
  73. extern BOOL g_bReturned;
  74. static UINT auIDStatusBar[] =
  75. {
  76. ID_SEPARATOR,
  77. ID_INDICATOR_DATA_RECEIVED,
  78. ID_INDICATOR_DATA_SEND,
  79. ID_INDICATOR_ONLINELED,
  80. ID_INDICATOR_OFFLINELED
  81. };
  82. /********************************************************************/
  83. /* */
  84. /* Function name : CDBServerDlg::CDBServerDlg */
  85. /* Description : Constructor */
  86. /* */
  87. /********************************************************************/
  88. CDBServerDlg::CDBServerDlg(CWnd* pParent /*=NULL*/): CDialog(CDBServerDlg::IDD, pParent)
  89. {
  90. m_hIcon = AfxGetApp()->LoadIcon(IDI_DBServer);
  91. m_bTerminate = false;
  92. m_bRunning = false;
  93. m_hThread = NULL;
  94. hInst = NULL;
  95. CString version = _T("Version 1.0");
  96. g_bAutoRun = AfxGetApp()->GetProfileInt(version, "brun", 0);
  97. m_hExitCheckSvc = NULL;
  98. m_hWaitTimeOut = NULL;
  99. m_hCheckSvcThread = NULL;
  100. m_bStartCheckSvc = FALSE;
  101. for (int i = 0; i < 200; i++)
  102. {
  103. g_pDB[i] = NULL;
  104. g_pThreadPt[i] = NULL;
  105. }
  106. }
  107. /********************************************************************/
  108. /* */
  109. /* Function name : CDBServerDlg::~CDBServerDlg */
  110. /* Description : Destructor */
  111. /* */
  112. /********************************************************************/
  113. CDBServerDlg::~CDBServerDlg()
  114. {
  115. for (int i = 0; i < 200; i++)
  116. {
  117. CDatabase *db = g_pDB[i];
  118. if (db)
  119. {
  120. db->Close();
  121. delete db;
  122. }
  123. for (int j = 0; j < g_pHistoryDBarray[i].GetSize(); j++)
  124. {
  125. CDatabase *db = g_pHistoryDBarray[i].ElementAt(j);
  126. if (db)
  127. {
  128. db->Close();
  129. delete db;
  130. }
  131. }
  132. g_pHistoryDBarray[i].RemoveAll();
  133. }
  134. }
  135. /********************************************************************/
  136. /* */
  137. /* Function name : CDBServerDlg::DoDataExchange */
  138. /* Description : Called by the framework to exchange and validate */
  139. /* dialog data. */
  140. /* */
  141. /********************************************************************/
  142. void CDBServerDlg::DoDataExchange(CDataExchange* pDX)
  143. {
  144. CDialog::DoDataExchange(pDX);
  145. //{{AFX_DATA_MAP(CDBServerDlg)
  146. DDX_Control(pDX, IDC_INFOBAR, m_InfobarCtrl);
  147. DDX_Control(pDX, IDC_OUTLOOKBAR, m_OutlookBar);
  148. //}}AFX_DATA_MAP
  149. }
  150. BEGIN_MESSAGE_MAP(CDBServerDlg, CDialog)
  151. //{{AFX_MSG_MAP(CDBServerDlg)
  152. ON_WM_DESTROY()
  153. ON_COMMAND(ID_SERVER_START, OnServerStart)
  154. ON_UPDATE_COMMAND_UI(ID_SERVER_START, OnUpdateServerStart)
  155. ON_COMMAND(ID_SERVER_STOP, OnServerStop)
  156. ON_UPDATE_COMMAND_UI(ID_SERVER_STOP, OnUpdateServerStop)
  157. ON_COMMAND(ID_SERVER_EXIT, OnServerExit)
  158. ON_NOTIFY(NM_CLICK, IDC_OUTLOOKBAR, OnClickOutlookBar)
  159. ON_NOTIFY(LVN_KEYDOWN, IDC_OUTLOOKBAR, OnKeydownOutlookBar)
  160. ON_COMMAND(ID_USER_ACCOUNTS, OnUserAccounts)
  161. ON_WM_CLOSE()
  162. ON_COMMAND(IDC_VIEW_TRACE, OnViewTrace)
  163. ON_COMMAND(IDC_VIEW_ONLINE_USERS, OnViewOnlineUsers)
  164. ON_COMMAND(IDC_VIEW_CONFIGURATION, OnViewConfiguration)
  165. ON_UPDATE_COMMAND_UI(IDC_VIEW_TRACE, OnUpdateViewTrace)
  166. ON_UPDATE_COMMAND_UI(IDC_VIEW_ONLINE_USERS, OnUpdateViewOnlineUsers)
  167. ON_UPDATE_COMMAND_UI(IDC_VIEW_CONFIGURATION, OnUpdateViewConfiguration)
  168. ON_COMMAND(IDC_VIEW_STATISTICS, OnViewStatistics)
  169. ON_UPDATE_COMMAND_UI(IDC_VIEW_STATISTICS, OnUpdateViewStatistics)
  170. ON_COMMAND(IDC_VIEW_SECURITY, OnViewSecurity)
  171. ON_UPDATE_COMMAND_UI(IDC_VIEW_SECURITY, OnUpdateViewSecurity)
  172. ON_COMMAND(ID_ACCOUNT_WIZARD, OnAccountWizard)
  173. ON_WM_TIMER()
  174. ON_COMMAND(IDM_OPEN, OnOpen)
  175. ON_COMMAND(IDM_EXIT, OnExit)
  176. ON_COMMAND(IDM_AUTORUN, OnAutorun)
  177. ON_COMMAND(IDM_STARTBAKSVC, OnStartBackupSvc)
  178. ON_COMMAND(IDM_STARTDELSVC, OnStartDelPhotoSvc)
  179. ON_COMMAND(IDM_STOPBAKSVC, OnStopBackupSvc)
  180. ON_COMMAND(IDM_STOPDELSVC, OnStopDelPhotoSvc)
  181. ON_COMMAND(IDM_AUTOCHECKSVC, OnAutoCheckSvc)
  182. //}}AFX_MSG_MAP
  183. ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification)
  184. ON_REGISTERED_MESSAGE(g_wmClose, OnAbortClose)
  185. END_MESSAGE_MAP()
  186. LRESULT CDBServerDlg::OnAbortClose(WPARAM wParam, LPARAM lParam)
  187. {
  188. if (wParam == 2)
  189. {
  190. WriteTextLog("连接失败,服务将重启");
  191. OnExit2();
  192. }
  193. else if (wParam == 3)//更新分店
  194. {
  195. LoadBranchInfo();
  196. }
  197. return 1;
  198. }
  199. BOOL CDBServerDlg::OnInitDialog()
  200. {
  201. g_pMainWnd = this;
  202. CDialog::OnInitDialog();
  203. char server[50];
  204. DWORD leng = 50;
  205. ::GetComputerName(server, &leng);
  206. g_localip = server;
  207. MyGetIPByName(g_localip);
  208. // setup listview ctrl, so that it looks like the outbar control
  209. SetupOutlookBar();
  210. // Add statusbar to the dialog
  211. CreateStatusbar();
  212. CRect rect;
  213. GetDlgItem(IDC_STATIC1)->GetWindowRect(rect);
  214. ScreenToClient(rect);
  215. rect.right += 4;
  216. GetDlgItem(IDC_STATIC1)->MoveWindow(rect);
  217. // create property pages
  218. m_TracePage.Create(IDD_PROPPAGE_TRACE, this);
  219. m_OnlineUsersPage.Create(IDD_PROPPAGE_ONLINE, this);
  220. m_ConfigurationPage.Create(IDD_PROPPAGE_CONFIGURATION, this);
  221. m_StatisticsPage.Create(IDD_PROPPAGE_STATISTICS, this);
  222. m_SecurityPage.Create(IDD_PROPPAGE_SECURITY, this);
  223. // activate main page
  224. ActivatePage(0);
  225. // Set the icon for this dialog.
  226. SetIcon(m_hIcon, TRUE); // Set big icon
  227. SetIcon(m_hIcon, FALSE); // Set small icon
  228. // get registry values
  229. ENCODE_START
  230. #ifndef _DEBUG
  231. #ifdef TIMEDOG_VERSION
  232. try
  233. {
  234. CheckRegCode(); // 检查注册码;
  235. DWORD id;
  236. TCHAR HKey[50]="ffffffff",LKey[50]="ffffffff";
  237. TCHAR OutTime[50];
  238. TCHAR DevicePath[ 260];
  239. if(FindPort(0,DevicePath)!=0)
  240. exit(1);
  241. //LIBC.LIB,libcp.lib,msvcprt.lib
  242. TCHAR year[10],month[10],day[10],hour[10],minute[10],second[10];
  243. ReadTimeAuthFromEprom(HKey,LKey, OutTime, &id, 30128, HKey, LKey, DevicePath);
  244. CString str=OutTime;
  245. CString temp="年";
  246. int pos=str.Find (temp);
  247. temp=str.Left (pos);
  248. str=str.Right (str.GetLength ()-pos-2);
  249. strcpy(year, temp.GetBuffer (0));temp.ReleaseBuffer ();
  250. temp="月";
  251. pos=str.Find (temp);
  252. temp=str.Left (pos);
  253. str=str.Right (str.GetLength ()-pos-2);
  254. strcpy(month, temp.GetBuffer (0));temp.ReleaseBuffer ();
  255. temp="日";
  256. pos=str.Find (temp);
  257. temp=str.Left (pos);
  258. str=str.Right (str.GetLength ()-pos-2);
  259. strcpy(day, temp.GetBuffer (0));temp.ReleaseBuffer ();
  260. temp="小时";
  261. pos=str.Find (temp);
  262. temp=str.Left (pos);
  263. str=str.Right (str.GetLength ()-pos-4);
  264. strcpy(hour, temp.GetBuffer (0));temp.ReleaseBuffer ();
  265. temp="分钟";
  266. pos=str.Find (temp);
  267. temp=str.Left (pos);
  268. str=str.Right (str.GetLength ()-pos-4);
  269. strcpy(minute, temp.GetBuffer (0));temp.ReleaseBuffer ();
  270. temp="0";
  271. strcpy(second, temp.GetBuffer (0));temp.ReleaseBuffer ();
  272. long time1=ConvertStringToTimerReal(year, month, day, hour, minute, second);
  273. GetRunTimer(year, month, day, hour, minute, second, DevicePath);
  274. long time2=ConvertStringToTimerReal(year, month, day, hour, minute, second);
  275. // 软件可运行时间;
  276. g_dwSoftRunTime = time1 - time2;
  277. if( (time1-time2) <0)
  278. {
  279. AfxMessageBox("加密锁已过期, 请与经销商联系!!!");
  280. InputAuthDlg authdlg;
  281. authdlg.m_id=id;
  282. authdlg.m_time1=time1;
  283. authdlg.m_time2=time2;
  284. if(authdlg.DoModal ()!=IDOK)
  285. {
  286. CDialog::OnCancel ();
  287. return false;
  288. }
  289. }
  290. else if((time1-time2) < 288000 ) // 10天 = 10*8*3600=360000 能用天数小于10个工作日(8小时一工作日).
  291. {
  292. DogTimeOutDlg dlg;
  293. dlg.hour=(time1-time2)/3600;
  294. if(dlg.DoModal ()==IDOK)
  295. {
  296. InputAuthDlg authdlg;
  297. authdlg.m_id=id;
  298. authdlg.m_time1=time1;
  299. authdlg.m_time2=time2;
  300. authdlg.DoModal ();
  301. }
  302. }
  303. BOOL bOK=1;
  304. int d[8];double f[8];
  305. char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]="";
  306. //运行自定义函数
  307. // SoftKey ytSoftKey;
  308. int ret=0;//ytSoftKey.Ini();
  309. ret=ytSoftKey.checktime(&d[0],&d[1],&d[2],&d[3],&d[4],&d[5],&d[6],&d[7],
  310. &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],
  311. s0,s1,s2,s3,s4,s5,s6,s7);
  312. if(ret!=0 && ret!=-43)
  313. {
  314. bOK=0;
  315. }
  316. ////////////////////////写申请码
  317. if(bOK)
  318. {
  319. str=GetRegCode(id, time1, time2);
  320. char path[MAX_PATH];
  321. ::GetSystemDirectory (path, MAX_PATH);
  322. CString sysdir=path;
  323. sysdir+="\\regcode.txt";
  324. CStdioFile fp;
  325. if(fp.Open (sysdir, CFile::modeWrite|CFile::modeCreate))
  326. {
  327. fp.WriteString (str);
  328. fp.Close ();
  329. }
  330. }
  331. /////////////////////////
  332. }
  333. catch(...)
  334. {
  335. }
  336. #endif
  337. #endif
  338. ENCODE_END
  339. OnButton1(); // Jeff 初始化服务端,内含定时器1;
  340. GetFileDate(); // Jeff获取文件信息;
  341. LoadHistoryDB();//Jeff加载历史数据库;
  342. SetTimer(4, 1000, NULL);
  343. SetTimer(2, 10, NULL);
  344. //CheckBakState();// 检查相片备份情况
  345. hInst = LoadLibrary("SENSAPI.DLL"); //加载动态库 ;
  346. if (hInst)
  347. {
  348. typedef BOOL(WINAPI *MYFUNC)(LPDWORD);
  349. MYFUNC IsNetworkConnect = NULL;
  350. //取得IsNetworkAlive函数指针;
  351. IsNetworkConnect = (MYFUNC)GetProcAddress(hInst, "IsNetworkAlive");
  352. if (IsNetworkConnect)
  353. {
  354. DWORD dwActiveWan = 1;
  355. if (IsNetworkConnect(&dwActiveWan))
  356. m_bNetWorkOK = 1;
  357. else
  358. m_bNetWorkOK = 0;
  359. SetTimer(5, 10000, NULL);
  360. }
  361. else
  362. m_bNetWorkOK = 0;
  363. }
  364. else
  365. m_bNetWorkOK = 0;
  366. if ( !CBranchInfo::GetInstance() )
  367. {
  368. AfxMessageBox(_T("内存分配错误"));
  369. return FALSE;
  370. }
  371. if ( !CBranchInfo::GetInstance()->InitCatalog(g_dwDBServerPort, g_szDBSource, g_szDBAccount, g_szDBPassWord, g_szDBName) )
  372. {
  373. AfxMessageBox(_T("初始化数据库连接对象失败"));
  374. return FALSE;
  375. }
  376. CBranchInfo::GetInstance()->GetTblVersion();
  377. CBranchInfo::GetInstance()->GetTblCatalogInfo();
  378. CBranchInfo::GetInstance()->GetTblNetShareInfo();
  379. // 1小时检测一次自动备份和自动删除服务是否启动
  380. // 是否自动检查服务
  381. if(g_bAutoCheckSvc == TRUE)
  382. {
  383. m_hExitCheckSvc = CreateEvent(NULL, FALSE, FALSE, NULL);
  384. m_hWaitTimeOut = CreateEvent(NULL, FALSE, FALSE, NULL);
  385. SetEvent(m_hWaitTimeOut);
  386. unsigned int nThreadID = 0;
  387. m_bStartCheckSvc = TRUE;
  388. m_hCheckSvcThread = (HANDLE)_beginthreadex(NULL, 0, CheckSvcWork, this, 0, &nThreadID);
  389. }
  390. return TRUE;
  391. }
  392. /********************************************************************/
  393. /* */
  394. /* Function name : OnDestroy */
  395. /* Description : Handle WM_DESTROY message */
  396. /* */
  397. /********************************************************************/
  398. void CDBServerDlg::OnDestroy()
  399. {
  400. OnServerStop();
  401. KillTimer(1);
  402. KillTimer(2);
  403. KillTimer(3);
  404. KillTimer(4);
  405. KillTimer(5);
  406. KillTimer(6);
  407. KillTimer(7);
  408. KillTimer(8);
  409. CDialog::OnDestroy();
  410. }
  411. /********************************************************************/
  412. /* */
  413. /* Function name : OnServerStart */
  414. /* Description : Start Date Server -> start listening on port 21 */
  415. /* */
  416. /********************************************************************/
  417. //启动数据服务器,使其在指定端口侦听
  418. void CDBServerDlg::OnServerStart()
  419. {
  420. ServerStart();
  421. }
  422. BOOL CDBServerDlg::ServerStart()
  423. {
  424. if (theServer.Start())
  425. {
  426. m_wndStatusBar.SetPaneText(0, "数据服务已启动", TRUE);
  427. SetOnlineLed(TRUE);
  428. SetOfflineLed(FALSE);
  429. WriteTextLog("启动成功");
  430. return 1;
  431. }
  432. else
  433. {
  434. WriteTextLog("启动失败");
  435. CDialog::OnCancel();
  436. return 0;
  437. }
  438. }
  439. /********************************************************************/
  440. /* */
  441. /* Function name : OnUpdateServerStart */
  442. /* Description : Update 'Start' status */
  443. /* */
  444. /********************************************************************/
  445. void CDBServerDlg::OnUpdateServerStart(CCmdUI* pCmdUI)
  446. {
  447. pCmdUI->Enable(!theServer.IsActive());
  448. }
  449. /********************************************************************/
  450. /* */
  451. /* Function name : OnServerStop */
  452. /* Description : Stop Date Server */
  453. /* */
  454. /********************************************************************/
  455. //停止服务器
  456. void CDBServerDlg::OnServerStop()
  457. {
  458. theServer.Stop();
  459. m_wndStatusBar.SetPaneText(0, "数据服务已停止", TRUE);
  460. SetOnlineLed(FALSE);
  461. SetOfflineLed(TRUE);
  462. }
  463. /********************************************************************/
  464. /* */
  465. /* Function name : OnUpdateServerStop */
  466. /* Description : Update 'Stop' status */
  467. /* */
  468. /********************************************************************/
  469. void CDBServerDlg::OnUpdateServerStop(CCmdUI* pCmdUI)
  470. {
  471. pCmdUI->Enable(theServer.IsActive());
  472. }
  473. /********************************************************************/
  474. /* */
  475. /* Function name : OnServerExit */
  476. /* Description : Let's get out of here... */
  477. /* */
  478. /********************************************************************/
  479. void CDBServerDlg::OnServerExit()
  480. {
  481. OnCancel();
  482. }
  483. /********************************************************************/
  484. /* */
  485. /* Function name : CDBServerDlg::SetupOutlookBar */
  486. /* Description : Initialize listview, change color/iconspacing to */
  487. /* make it look a little bit like the outlook bar. */
  488. /* */
  489. /********************************************************************/
  490. void CDBServerDlg::SetupOutlookBar()
  491. {
  492. m_ImageList.Create(32, 32, ILC_COLOR16 | ILC_MASK, 1, 4);
  493. HICON hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_LOG));
  494. m_ImageList.Add(hIcon);
  495. hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ONLINE_USERS));
  496. m_ImageList.Add(hIcon);
  497. hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_CONFIGURATION));
  498. m_ImageList.Add(hIcon);
  499. hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_SECURITY));
  500. m_ImageList.Add(hIcon);
  501. hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_STATISTICS));
  502. m_ImageList.Add(hIcon);
  503. m_OutlookBar.SetImageList(&m_ImageList, LVSIL_NORMAL);
  504. CRect rc;
  505. m_OutlookBar.GetClientRect(rc);
  506. // set new icon spacing
  507. m_OutlookBar.SetIconSpacing(rc.Width(), 64);
  508. // change colors
  509. m_OutlookBar.SetTextColor(RGB(255, 255, 255));
  510. m_OutlookBar.SetTextBkColor(RGB(128, 128, 128));
  511. m_OutlookBar.SetBkColor(RGB(128, 128, 128));
  512. // insert items
  513. m_OutlookBar.InsertColumn(0, "OutlookBar");
  514. m_OutlookBar.InsertItem(0, "服务器日志", 0);
  515. m_OutlookBar.InsertItem(1, "在线用户", 1);
  516. m_OutlookBar.InsertItem(2, "关于", 2);
  517. m_OutlookBar.InsertItem(3, "功能区", 3);
  518. }
  519. /********************************************************************/
  520. /* */
  521. /* Function name : CDBServerDlg::MoveChilds */
  522. /* Description : Move child windows into place holder area. */
  523. /* */
  524. /********************************************************************/
  525. void CDBServerDlg::MoveChilds()
  526. {
  527. // position property pages
  528. CRect rcDlgs;
  529. // get dialog area rect
  530. GetDlgItem(IDC_DIALOG_AREA)->GetWindowRect(rcDlgs);
  531. ScreenToClient(rcDlgs);
  532. m_ConfigurationPage.MoveWindow(rcDlgs);
  533. m_TracePage.MoveWindow(rcDlgs);
  534. m_OnlineUsersPage.MoveWindow(rcDlgs);
  535. m_StatisticsPage.MoveWindow(rcDlgs);
  536. m_SecurityPage.MoveWindow(rcDlgs);
  537. }
  538. /********************************************************************/
  539. /* */
  540. /* Function name : CDBServerDlg::ActivatePage */
  541. /* Description : Called when an icon on the outlookbar is pressed.*/
  542. /* */
  543. /********************************************************************/
  544. void CDBServerDlg::ActivatePage(int nIndex)
  545. {
  546. switch (nIndex)
  547. {
  548. case 0:
  549. m_OnlineUsersPage.ShowWindow(SW_HIDE);
  550. m_ConfigurationPage.ShowWindow(SW_HIDE);
  551. m_StatisticsPage.ShowWindow(SW_HIDE);
  552. m_SecurityPage.ShowWindow(SW_HIDE);
  553. m_TracePage.ShowWindow(SW_SHOW);
  554. m_InfobarCtrl.SetText("服务器日志");
  555. break;
  556. case 1:
  557. m_TracePage.ShowWindow(SW_HIDE);
  558. m_ConfigurationPage.ShowWindow(SW_HIDE);
  559. m_StatisticsPage.ShowWindow(SW_HIDE);
  560. m_SecurityPage.ShowWindow(SW_HIDE);
  561. m_OnlineUsersPage.RefreshData();
  562. m_OnlineUsersPage.ShowWindow(SW_SHOW);
  563. m_InfobarCtrl.SetText("在线用户");
  564. break;
  565. case 2:
  566. m_OnlineUsersPage.ShowWindow(SW_HIDE);
  567. m_TracePage.ShowWindow(SW_HIDE);
  568. m_StatisticsPage.ShowWindow(SW_HIDE);
  569. m_SecurityPage.ShowWindow(SW_HIDE);
  570. m_ConfigurationPage.ShowWindow(SW_SHOW);
  571. m_InfobarCtrl.SetText("关于");
  572. break;
  573. case 4:
  574. m_OnlineUsersPage.ShowWindow(SW_HIDE);
  575. m_TracePage.ShowWindow(SW_HIDE);
  576. m_ConfigurationPage.ShowWindow(SW_HIDE);
  577. m_SecurityPage.ShowWindow(SW_HIDE);
  578. m_StatisticsPage.ShowWindow(SW_SHOW);
  579. m_InfobarCtrl.SetText("Statistics");
  580. break;
  581. case 3:
  582. m_OnlineUsersPage.ShowWindow(SW_HIDE);
  583. m_TracePage.ShowWindow(SW_HIDE);
  584. m_ConfigurationPage.ShowWindow(SW_HIDE);
  585. m_SecurityPage.ShowWindow(SW_SHOW);
  586. m_StatisticsPage.ShowWindow(SW_HIDE);
  587. m_InfobarCtrl.SetText("功能区");
  588. break;
  589. default:
  590. break;
  591. }
  592. MoveChilds();
  593. }
  594. /********************************************************************/
  595. /* */
  596. /* Function name : CDBServerDlg::OnClickOutlookBar */
  597. /* Description : User clicked on our listview -> activate page. */
  598. /* */
  599. /********************************************************************/
  600. void CDBServerDlg::OnClickOutlookBar(NMHDR* pNMHDR, LRESULT* pResult)
  601. {
  602. // get index of selected item
  603. int nIndex = m_OutlookBar.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  604. if (nIndex == -1)
  605. return;
  606. ActivatePage(nIndex);
  607. *pResult = 0;
  608. }
  609. /********************************************************************/
  610. /* */
  611. /* Function name : CDBServerDlg::OnKeydownOutlookBar */
  612. /* Description : User pressed a key -> activate page. */
  613. /* */
  614. /********************************************************************/
  615. void CDBServerDlg::OnKeydownOutlookBar(NMHDR* pNMHDR, LRESULT* pResult)
  616. {
  617. LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
  618. // get index of selected item
  619. int nIndex = m_OutlookBar.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  620. if (nIndex == -1)
  621. return;
  622. if (pLVKeyDow->wVKey == VK_DOWN)
  623. {
  624. if (m_OutlookBar.GetItemCount() - 1 > nIndex)
  625. {
  626. ActivatePage(nIndex + 1);
  627. }
  628. }
  629. else if (pLVKeyDow->wVKey == VK_UP)
  630. {
  631. if (nIndex > 0)
  632. {
  633. ActivatePage(nIndex - 1);
  634. }
  635. }
  636. else if (pLVKeyDow->wVKey == VK_NEXT)
  637. {
  638. ActivatePage(m_OutlookBar.GetItemCount() - 1);
  639. }
  640. else if (pLVKeyDow->wVKey == VK_PRIOR)
  641. {
  642. ActivatePage(0);
  643. }
  644. *pResult = 0;
  645. }
  646. /********************************************************************/
  647. /* */
  648. /* Function name : CreateStatusbar */
  649. /* Description : This function creates a statusbar on a dialogbox.*/
  650. /* */
  651. /********************************************************************/
  652. BOOL CDBServerDlg::CreateStatusbar()
  653. {
  654. // Create the Toolbar and attach the resource
  655. if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
  656. {
  657. TRACE0("Failed to Create Dialog Toolbar\n");
  658. return FALSE;
  659. }
  660. m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);
  661. // Make it flat.
  662. m_wndToolBar.ModifyStyle(0, m_wndToolBar.GetStyle() | TBSTYLE_FLAT);
  663. // Create status bar at the bottom of the dialog window
  664. if (m_wndStatusBar.Create(this))
  665. {
  666. m_wndStatusBar.SetIndicators(auIDStatusBar, sizeof(auIDStatusBar) / sizeof(UINT));
  667. m_wndStatusBar.SetPaneText(0, "Date Server is offline", TRUE);
  668. // Make a sunken or recessed border around the first pane
  669. m_wndStatusBar.SetPaneInfo(0, m_wndStatusBar.GetItemID(0), SBPS_STRETCH, NULL);
  670. SetOnlineLed(FALSE);
  671. SetOfflineLed(FALSE);
  672. m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), ID_INDICATOR_ONLINELED, SBPS_NOBORDERS, 14);
  673. // m_wndStatusBar.GetStatusBarCtrl().SetTipText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), "This status light is green when the server is online");
  674. m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), ID_INDICATOR_OFFLINELED, SBPS_NOBORDERS, 14);
  675. // m_wndStatusBar.GetStatusBarCtrl().SetTipText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), "This status light is green when the server is online");
  676. }
  677. // We need to resize the dialog to make room for control bars.
  678. // First, figure out how big the control bars are.
  679. CRect rcClientStart;
  680. CRect rcClientNow;
  681. GetClientRect(rcClientStart);
  682. RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, rcClientNow);
  683. // Now move all the controls so they are in the same relative
  684. // position within the remaining client area as they would be
  685. // with no control bars.
  686. CPoint ptOffset(rcClientNow.left - rcClientStart.left, rcClientNow.top - rcClientStart.top);
  687. CRect rcChild;
  688. CWnd* pwndChild = GetWindow(GW_CHILD);
  689. while (pwndChild)
  690. {
  691. pwndChild->GetWindowRect(rcChild);
  692. ScreenToClient(rcChild);
  693. rcChild.OffsetRect(ptOffset);
  694. pwndChild->MoveWindow(rcChild, FALSE);
  695. pwndChild = pwndChild->GetNextWindow();
  696. }
  697. // Adjust the dialog window dimensions
  698. CRect rcWindow;
  699. GetWindowRect(rcWindow);
  700. rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
  701. rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
  702. MoveWindow(rcWindow, FALSE);
  703. // And position the control bars
  704. RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
  705. return TRUE;
  706. }
  707. /********************************************************************/
  708. /* */
  709. /* Function name : OnUserAccounts */
  710. /* Description : Show user accounts. */
  711. /* */
  712. /********************************************************************/
  713. void CDBServerDlg::OnUserAccounts()
  714. {
  715. /*
  716. CUserAccountsDlg dlg;
  717. theServer.m_UserManager.GetUserList(dlg.m_UserArray);
  718. if (dlg.DoModal() == IDOK)
  719. {
  720. theServer.m_UserManager.UpdateUserList(dlg.m_UserArray);
  721. }*/
  722. }
  723. /********************************************************************/
  724. /* */
  725. /* Function name : OnFTPUserConnected */
  726. /* Description : A user has connected to our server. */
  727. /* */
  728. /********************************************************************/
  729. void CDBServerDlg::OnFTPUserConnected(DWORD nThreadID, LPCTSTR lpszUser, LPCSTR lpszAddress)
  730. {
  731. m_OnlineUsersPage.AddUser(nThreadID, lpszUser, lpszAddress);
  732. }
  733. /********************************************************************/
  734. /* */
  735. /* Function name : OnFTPUserDisconnected */
  736. /* Description : A user has disconnected from our server. */
  737. /* */
  738. /********************************************************************/
  739. void CDBServerDlg::OnFTPUserDisconnected(DWORD nThreadID, LPCTSTR lpszUser)
  740. {
  741. m_OnlineUsersPage.RemoveUser(nThreadID);
  742. }
  743. /********************************************************************/
  744. /* */
  745. /* Function name : OnFTPStatusChange */
  746. /* Description : FTP Status changed. */
  747. /* */
  748. /********************************************************************/
  749. void CDBServerDlg::OnFTPStatusChange(int nType, LPCTSTR lpszText)
  750. {
  751. m_TracePage.AddTraceLine(nType, lpszText);
  752. switch (nType)
  753. {
  754. case 3:
  755. theApp.m_LogFile << error_lvl << date << time << lpszText << endl;
  756. break;
  757. default:
  758. theApp.m_LogFile << trace_lvl << date << time << lpszText << endl;
  759. break;
  760. }
  761. }
  762. /********************************************************************/
  763. /* */
  764. /* Function name : OnFTPReceivedBytesChange */
  765. /* Description : Number of received bytes has changed. */
  766. /* */
  767. /********************************************************************/
  768. void CDBServerDlg::OnFTPReceivedBytesChange(int nBytes)
  769. {
  770. m_StatisticsPage.SetValue(6, FormatSize(nBytes, 0));
  771. CString strStatus;
  772. strStatus.Format("%s received", FormatSize(nBytes, 0));
  773. m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_RECEIVED), strStatus, TRUE);
  774. CClientDC dc(this);
  775. CSize size = dc.GetTextExtent(strStatus);
  776. m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_RECEIVED), ID_INDICATOR_DATA_RECEIVED, SBPS_NORMAL, size.cx);
  777. }
  778. /********************************************************************/
  779. /* */
  780. /* Function name : OnFTPSentBytesChange */
  781. /* Description : Number of sent bytes has changed. */
  782. /* */
  783. /********************************************************************/
  784. void CDBServerDlg::OnFTPSentBytesChange(int nBytes)
  785. {
  786. m_StatisticsPage.SetValue(7, FormatSize(nBytes, 0));
  787. CString strStatus;
  788. strStatus.Format("%s sent", FormatSize(nBytes, 0));
  789. m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_SEND), strStatus, TRUE);
  790. CClientDC dc(this);
  791. CSize size = dc.GetTextExtent(strStatus);
  792. m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_SEND), ID_INDICATOR_DATA_SEND, SBPS_NORMAL, size.cx);
  793. }
  794. /********************************************************************/
  795. /* */
  796. /* Function name : OnViewTrace */
  797. /* Description : Handle menu selection. */
  798. /* */
  799. /********************************************************************/
  800. void CDBServerDlg::OnViewTrace()
  801. {
  802. ActivatePage(0);
  803. }
  804. /********************************************************************/
  805. /* */
  806. /* Function name : OnViewOnlineUsers */
  807. /* Description : Handle menu selection. */
  808. /* */
  809. /********************************************************************/
  810. void CDBServerDlg::OnViewOnlineUsers()
  811. {
  812. ActivatePage(1);
  813. }
  814. /********************************************************************/
  815. /* */
  816. /* Function name : OnViewConfiguration */
  817. /* Description : Handle menu selection. */
  818. /* */
  819. /********************************************************************/
  820. void CDBServerDlg::OnViewConfiguration()
  821. {
  822. ActivatePage(2);
  823. }
  824. /********************************************************************/
  825. /* */
  826. /* Function name : OnViewStatistics */
  827. /* Description : Handle menu selection. */
  828. /* */
  829. /********************************************************************/
  830. void CDBServerDlg::OnViewStatistics()
  831. {
  832. ActivatePage(3);
  833. }
  834. /********************************************************************/
  835. /* */
  836. /* Function name : OnViewSecurity */
  837. /* Description : Handle menu selection. */
  838. /* */
  839. /********************************************************************/
  840. void CDBServerDlg::OnViewSecurity()
  841. {
  842. ActivatePage(4);
  843. }
  844. /********************************************************************/
  845. /* */
  846. /* Function name : OnUpdateViewTrace */
  847. /* Description : Update menu state of Trace item. */
  848. /* */
  849. /********************************************************************/
  850. void CDBServerDlg::OnUpdateViewTrace(CCmdUI* pCmdUI)
  851. {
  852. pCmdUI->SetRadio(m_TracePage.IsWindowVisible());
  853. }
  854. /********************************************************************/
  855. /* */
  856. /* Function name : OnUpdateViewOnlineUsers */
  857. /* Description : Update menu state of Online Users item. */
  858. /* */
  859. /********************************************************************/
  860. void CDBServerDlg::OnUpdateViewOnlineUsers(CCmdUI* pCmdUI)
  861. {
  862. pCmdUI->SetRadio(m_OnlineUsersPage.IsWindowVisible());
  863. }
  864. /********************************************************************/
  865. /* */
  866. /* Function name : OnUpdateViewConfiguration */
  867. /* Description : Update menu state of Configuration item. */
  868. /* */
  869. /********************************************************************/
  870. void CDBServerDlg::OnUpdateViewConfiguration(CCmdUI* pCmdUI)
  871. {
  872. pCmdUI->SetRadio(m_ConfigurationPage.IsWindowVisible());
  873. }
  874. /********************************************************************/
  875. /* */
  876. /* Function name : OnUpdateViewStatistics */
  877. /* Description : Update menu state of Statistics item. */
  878. /* */
  879. /********************************************************************/
  880. void CDBServerDlg::OnUpdateViewStatistics(CCmdUI* pCmdUI)
  881. {
  882. pCmdUI->SetRadio(m_StatisticsPage.IsWindowVisible());
  883. }
  884. /********************************************************************/
  885. /* */
  886. /* Function name : OnUpdateViewSecurity */
  887. /* Description : Update menu state of Security item. */
  888. /* */
  889. /********************************************************************/
  890. void CDBServerDlg::OnUpdateViewSecurity(CCmdUI* pCmdUI)
  891. {
  892. pCmdUI->SetRadio(m_SecurityPage.IsWindowVisible());
  893. }
  894. /********************************************************************/
  895. /* */
  896. /* Function name : SetOnlineLed */
  897. /* Description : Turn online LED on/off. */
  898. /* */
  899. /********************************************************************/
  900. void CDBServerDlg::SetOnlineLed(BOOL bOnline)
  901. {
  902. HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(),
  903. bOnline ? MAKEINTRESOURCE(IDI_LED_GREEN) : MAKEINTRESOURCE(IDI_LED_OFF),
  904. IMAGE_ICON, 16, 16, LR_SHARED);
  905. m_wndStatusBar.GetStatusBarCtrl().SetIcon(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), hIcon);
  906. m_wndStatusBar.GetStatusBarCtrl().Invalidate();
  907. m_wndStatusBar.GetStatusBarCtrl().UpdateWindow();
  908. DestroyIcon(hIcon);
  909. }
  910. /********************************************************************/
  911. /* */
  912. /* Function name : SetOfflineLed */
  913. /* Description : Turn offline LED on/off. */
  914. /* */
  915. /********************************************************************/
  916. void CDBServerDlg::SetOfflineLed(BOOL bOffline)
  917. {
  918. HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(),
  919. bOffline ? MAKEINTRESOURCE(IDI_LED_RED) : MAKEINTRESOURCE(IDI_LED_OFF),
  920. IMAGE_ICON, 16, 16, LR_SHARED);
  921. m_wndStatusBar.GetStatusBarCtrl().SetIcon(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), hIcon);
  922. m_wndStatusBar.GetStatusBarCtrl().Invalidate();
  923. m_wndStatusBar.GetStatusBarCtrl().UpdateWindow();
  924. DestroyIcon(hIcon);
  925. }
  926. void CDBServerDlg::OnFTPStatisticChange(int nType, int nValue)
  927. {
  928. m_StatisticsPage.SetValue(nType, nValue);
  929. }
  930. /********************************************************************/
  931. /* */
  932. /* Function name : FormatSize */
  933. /* Description : Format size, the way explorer diplays it */
  934. /* */
  935. /********************************************************************/
  936. char* CDBServerDlg::FormatSize(DWORD dwSizeLow, DWORD dwSizeHigh)
  937. {
  938. static char szBuff[100];
  939. unsigned __int64 nFileSize = ((unsigned __int64)(((DWORD)(dwSizeLow)) |
  940. ((unsigned __int64)((DWORD)(dwSizeHigh))) << 32));
  941. unsigned __int64 kb = 0;
  942. if (nFileSize > 1024)
  943. {
  944. kb = nFileSize / 1024;
  945. if (nFileSize % 1024)
  946. kb++;
  947. }
  948. // make it a string
  949. _ui64tot(kb, szBuff, 10);
  950. // add thousand seperators
  951. int nLength = lstrlen(szBuff);
  952. if (nLength > 3)
  953. {
  954. LPCTSTR ptr = szBuff;
  955. ptr += (nLength - 1);
  956. char szTemp[100];
  957. LPTSTR ptrTemp = szTemp;
  958. for (int i = 0; i < nLength; i++)
  959. {
  960. if (i && ((i % 3) == 0))
  961. {
  962. if (*ptrTemp != ',')
  963. {
  964. *ptrTemp = ',';
  965. ptrTemp = _tcsinc(ptrTemp);
  966. }
  967. }
  968. *ptrTemp = *ptr;
  969. ptrTemp = _tcsinc(ptrTemp);
  970. ptr = _tcsdec(szBuff, ptr);
  971. }
  972. // terminate string
  973. *ptrTemp = '\0';
  974. // reverse string
  975. _tcsrev(szTemp);
  976. lstrcpy(szBuff, szTemp);
  977. }
  978. // add 'KB' to it
  979. lstrcat(szBuff, " KB");
  980. return szBuff;
  981. }
  982. /********************************************************************/
  983. /* */
  984. /* Function name : OnAccountWizard */
  985. /* Description : Launch New Account Wizard */
  986. /* */
  987. /********************************************************************/
  988. void CDBServerDlg::OnAccountWizard()
  989. {/*
  990. CBitmap bmpHeader, bmpWatermark;
  991. VERIFY(bmpHeader.LoadBitmap(IDB_BANNER));
  992. VERIFY(bmpWatermark.LoadBitmap(IDB_WATERMARK));
  993. // show windows 2000-like wizard
  994. CWizardSheet wizSheet("New Account Wizard", this, 0, bmpWatermark, NULL, bmpHeader);
  995. wizSheet.m_psh.hInstance = ::GetModuleHandle(NULL);
  996. if (wizSheet.DoModal() == ID_WIZFINISH)
  997. {
  998. CArray<CUser, CUser&> m_UserArray;
  999. theServer.m_UserManager.GetUserList(m_UserArray);
  1000. int nIndex = -1;
  1001. for (int i = 0; i < m_UserArray.GetSize(); i++)
  1002. {
  1003. // if it already exists -> update it
  1004. if (m_UserArray[i].m_strName.CompareNoCase(wizSheet.m_Page1.m_strAccountName) == 0)
  1005. {
  1006. nIndex = i;
  1007. break;
  1008. }
  1009. }
  1010. // add new account ?
  1011. if (nIndex == -1)
  1012. {
  1013. CUser user;
  1014. nIndex = m_UserArray.Add(user);
  1015. }
  1016. m_UserArray[nIndex].m_bAccountDisabled = FALSE;
  1017. m_UserArray[nIndex].m_strName = wizSheet.m_Page1.m_strAccountName;
  1018. m_UserArray[nIndex].m_strPassword = wizSheet.m_Page2.m_strPassword;
  1019. // add home directory
  1020. CDirectory directory;
  1021. directory.m_strDir = wizSheet.m_Page3.m_strHomeDirectory;
  1022. directory.m_strAlias = "";
  1023. directory.m_bIsHomeDir = TRUE;
  1024. directory.m_bAllowCreateDirectory = wizSheet.m_Page4.m_bAllowCreateDirectory;
  1025. directory.m_bAllowDelete = wizSheet.m_Page4.m_bAllowDelete;
  1026. directory.m_bAllowDownload = wizSheet.m_Page4.m_bAllowDownload;
  1027. directory.m_bAllowRename = wizSheet.m_Page4.m_bAllowRename;
  1028. directory.m_bAllowUpload = wizSheet.m_Page4.m_bAllowUpload;
  1029. directory.m_strAlias = "";
  1030. m_UserArray[nIndex].m_DirectoryArray.Add(directory);
  1031. // update
  1032. theServer.m_UserManager.UpdateUserList(m_UserArray);
  1033. }*/
  1034. }
  1035. void CDBServerDlg::OnCancel()
  1036. {
  1037. }
  1038. void CDBServerDlg::OnOK()
  1039. {
  1040. }
  1041. void CDBServerDlg::OnButton1() // 启动服务;
  1042. {
  1043. // TODO: Add your control notification handler code here
  1044. try
  1045. {
  1046. theServer.Initialize(this);
  1047. if (ServerStart() == 0)
  1048. return;
  1049. if (g_pSkinData == NULL)
  1050. InitLia();
  1051. /////////////////////
  1052. CString logdays;
  1053. //MyLock lock("dbaccessxiao");
  1054. CDatabase *pdb = NULL;
  1055. ODBCConnGuard ConnGuard(pdb, -1, 3000);
  1056. if ( pdb == NULL)
  1057. return;
  1058. CRecordset myset(pdb);
  1059. CString sql = "select logdays from version";
  1060. myset.Open(CRecordset::forwardOnly, sql);
  1061. myset.GetFieldValue("logdays", logdays);
  1062. myset.Close();
  1063. int days = 180;
  1064. if (logdays == "1个月")
  1065. days = 31;
  1066. else if (logdays == "2个月")
  1067. days = 61;
  1068. else if (logdays == "3个月")
  1069. days = 92;
  1070. else
  1071. days = 183;
  1072. CTime tm = CTime::GetCurrentTime();
  1073. CTimeSpan dt(240, 0, 0, 0); // Jeff 不使用days,固定使用天数;
  1074. tm -= dt;
  1075. CString date = tm.Format("%Y-%m-%d");
  1076. #if 0
  1077. // 删除日志前,取消触发器;2015-06-10
  1078. sql = _T("DROP TRIGGER ON_DELETE_USER_LOGS");
  1079. pdb->ExecuteSQL(sql);
  1080. sql = "delete from [log] where [date]<'" + date + "'";
  1081. pdb->ExecuteSQL(sql);
  1082. // 删除日志后,恢复触发器;2015-06-10
  1083. sql = _T("CREATE TRIGGER ON_DELETE_USER_LOGS ON [dbo].[log] FOR DELETE AS BEGIN rollback; END");
  1084. pdb->ExecuteSQL(sql);
  1085. #endif
  1086. ///////////////////
  1087. tm = CTime::GetCurrentTime();
  1088. CTimeSpan dt2(183, 0, 0, 0);
  1089. tm -= dt2;
  1090. date = tm.Format("%Y%m%d%H%M%S");
  1091. sql = "delete from sendreg where [status]='OK' and [timestamp]<'" + date + "'";
  1092. pdb->ExecuteSQL(sql);
  1093. //////////////////////////////////
  1094. sql = "select version from version";
  1095. myset.Open(CRecordset::forwardOnly, sql);
  1096. myset.GetFieldValue("version", sql);
  1097. myset.Close();
  1098. m_ConfigurationPage.m_versionno = sql;
  1099. m_ConfigurationPage.UpdateData(0);
  1100. /////////////////////
  1101. }
  1102. catch (CException *e)
  1103. {
  1104. TCHAR szError[1024] = { 0 };
  1105. e->GetErrorMessage(szError, 1024);
  1106. WriteTextLog(CString(szError));
  1107. e->Delete();
  1108. }
  1109. }
  1110. void CDBServerDlg::OnClose()
  1111. {
  1112. m_TrayIcon.Create(this, WM_ICON_NOTIFY, "影楼管理系统服务器", m_hIcon, IDR_MENUtray); //构造
  1113. ShowWindow(SW_HIDE); //隐藏窗口
  1114. }
  1115. LRESULT CDBServerDlg::OnTrayNotification(WPARAM wParam, LPARAM lParam)
  1116. {
  1117. return m_TrayIcon.OnTrayNotification(wParam, lParam);
  1118. }
  1119. void CDBServerDlg::OnOpen()
  1120. {
  1121. ShowWindow(SW_SHOW);
  1122. }
  1123. void CDBServerDlg::OnExit2()
  1124. {
  1125. try
  1126. {
  1127. TerminateThread();
  1128. m_TrayIcon.RemoveIcon();
  1129. if (g_pSkinData)delete[]g_pSkinData; g_pSkinData = NULL;
  1130. //g_db.Close();
  1131. for (int i = 0; i < g_dbHistoryArray.GetSize(); i++)
  1132. {
  1133. g_dbHistoryArray.ElementAt(i)->Close();
  1134. delete g_dbHistoryArray.ElementAt(i);
  1135. }
  1136. ReleaseBranchDB();
  1137. }
  1138. catch (...)
  1139. {
  1140. WriteTextLog("出错在函数OnExit2中");
  1141. }
  1142. CDialog::OnCancel();
  1143. }
  1144. void CDBServerDlg::OnExit()
  1145. {
  1146. try
  1147. {
  1148. // 结束检查服务线程
  1149. TerminateCheckWork();
  1150. //结束一键生成小图线程
  1151. if(CreateSmallPhoto::GetInstance()->IsCreating())
  1152. {
  1153. if(AfxMessageBox("温馨提示:生成小图还未完成确定要退出程序吗", MB_YESNO|MB_ICONSTOP) == IDNO)
  1154. return;
  1155. CreateSmallPhoto::GetInstance()->TerminateThread();
  1156. }
  1157. TerminateThread();
  1158. DWORD id = FindAppProcessID("AutoRun.exe");
  1159. if (id != -1)
  1160. {
  1161. HANDLE ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, id);
  1162. if (ProcessHandle)TerminateProcess(ProcessHandle, 0);
  1163. }
  1164. m_TrayIcon.RemoveIcon();
  1165. if (g_pSkinData)delete[]g_pSkinData; g_pSkinData = NULL;
  1166. ReleaseBranchDB();
  1167. }
  1168. catch (...)
  1169. {
  1170. WriteTextLog("出错在函数OnExit中");
  1171. }
  1172. CDialog::OnCancel();
  1173. }
  1174. void CDBServerDlg::OnTimer(UINT nIDEvent) //定时器;
  1175. {
  1176. try
  1177. {
  1178. if (nIDEvent == 1)
  1179. {// 生成小图;
  1180. KillTimer(nIDEvent);
  1181. LoadThumbImages();
  1182. }
  1183. else if (nIDEvent == 2)
  1184. {
  1185. KillTimer(nIDEvent);
  1186. OnClose();// 托盘显示;
  1187. try
  1188. {
  1189. CheckHistoryData(); // Jeff:back history db data;
  1190. LoadBranchInfo();
  1191. }
  1192. catch (...)
  1193. {
  1194. }
  1195. SetTimer(1, 2 * 60 * 1000, NULL);
  1196. SetTimer(4, 1000 * 60 * 2, NULL);
  1197. SetTimer(7, 1000 * 60 * 60 * 1, NULL);
  1198. SetTimer(8, 3000, NULL);
  1199. SetTimer(9, 10000, NULL);
  1200. }
  1201. else if (nIDEvent == 3)
  1202. {
  1203. g_pMainWnd->KillTimer(3);
  1204. HANDLE hMutex = ::OpenMutex(NULL, FALSE, _T("lyfzSMSHandle"));
  1205. if (GetLastError() == ERROR_FILE_NOT_FOUND)
  1206. {
  1207. CString autorunpath = g_mainpath + _T("\\SMSHandle.exe");
  1208. ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
  1209. }
  1210. if(hMutex) CloseHandle(hMutex);
  1211. }
  1212. else if (nIDEvent == 4) //Jeff.这里也有自动启动MsgServer.exe服务处理,而且是2分钟/次的频率;
  1213. {
  1214. UpdateDate();
  1215. CheckMemberMsg();
  1216. BakPhoto();
  1217. }
  1218. else if (nIDEvent == 5)
  1219. {
  1220. typedef BOOL(WINAPI *MYFUNC)(LPDWORD);
  1221. MYFUNC IsNetworkConnect = NULL;
  1222. //取得IsNetworkAlive函数指针
  1223. IsNetworkConnect = (MYFUNC)GetProcAddress(hInst, "IsNetworkAlive");
  1224. if (IsNetworkConnect)
  1225. {
  1226. DWORD dwActiveWan = 1;
  1227. BOOL state;
  1228. if (IsNetworkConnect(&dwActiveWan))
  1229. state = 1;
  1230. else
  1231. state = 0;
  1232. if (m_bNetWorkOK != state)
  1233. {
  1234. KillTimer(nIDEvent);
  1235. WriteTextLog("网络断开");
  1236. OnExit2();
  1237. }
  1238. }
  1239. }
  1240. else if (nIDEvent == 6)
  1241. {
  1242. KillTimer(nIDEvent);
  1243. ShutDown();
  1244. }
  1245. else if (nIDEvent == 7)
  1246. {
  1247. //CheckBakState();
  1248. GenUPhoneData();
  1249. }
  1250. else if (nIDEvent == 8)
  1251. {
  1252. CheckConnCount();
  1253. }
  1254. }
  1255. catch (...)
  1256. {
  1257. WriteTextLog("出错在函数Timer中");
  1258. }
  1259. }
  1260. void LoadImageFromBuf(Image **img, BYTE *pData, DWORD leng)//g_bakserver1
  1261. {
  1262. try
  1263. {
  1264. if (pData == NULL)return;
  1265. if (*img)delete *img;
  1266. *img = NULL;
  1267. // Allocate global memory on which to create stream
  1268. HGLOBAL m_hMem = GlobalAlloc(GMEM_MOVEABLE, leng);
  1269. if (m_hMem == NULL)return;
  1270. BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
  1271. memcpy(pmem, pData, leng);
  1272. IStream* pstm;
  1273. CreateStreamOnHGlobal(m_hMem, TRUE, &pstm);
  1274. // load from stream
  1275. *img = Gdiplus::Image::FromStream(pstm);
  1276. // free/release stuff
  1277. GlobalUnlock(m_hMem);
  1278. pstm->Release();
  1279. }
  1280. catch (...)
  1281. {
  1282. }
  1283. }
  1284. void LoadImageFromBuf(Image **img, CString path)
  1285. {
  1286. try
  1287. {
  1288. CFile fp;
  1289. if (fp.Open(path, CFile::modeRead))
  1290. {
  1291. DWORD leng = fp.GetLength();
  1292. BYTE *pData = new BYTE[leng];
  1293. fp.Read(pData, leng);
  1294. fp.Close();
  1295. LoadImageFromBuf(img, pData, leng);
  1296. delete[]pData;
  1297. }
  1298. }
  1299. catch (...)
  1300. {
  1301. }
  1302. }
  1303. void LoadImageFromRes(Image **img, LPCTSTR lpszResourceName, LPCTSTR ResourceType)
  1304. {
  1305. try
  1306. {
  1307. HGLOBAL hGlobal = NULL;
  1308. HRSRC hSource = NULL;
  1309. LPVOID lpVoid = NULL;
  1310. int nSize = 0;
  1311. BOOL bResult = FALSE;
  1312. hSource = FindResource(NULL, lpszResourceName, ResourceType);
  1313. if (hSource == NULL)return;
  1314. hGlobal = LoadResource(NULL, hSource);
  1315. if (hGlobal == NULL)return;
  1316. lpVoid = LockResource(hGlobal);
  1317. if (lpVoid == NULL)return;
  1318. nSize = (UINT)SizeofResource(NULL, hSource);
  1319. LoadImageFromBuf(img, (BYTE*)hGlobal, nSize);
  1320. UnlockResource(hGlobal); // 16Bit Windows Needs This
  1321. FreeResource(hGlobal); // 16Bit Windows Needs This (32Bit - Automatic Release)
  1322. }
  1323. catch (...)
  1324. {
  1325. }
  1326. }
  1327. // ---------------------------------------------------------------------------------------------------------------------------------------------------------------
  1328. // TimeAt: 2014-09-15 AM;
  1329. // Remark: Jeff;
  1330. // 函数:GenSPhoto
  1331. // 描述:对指定文件夹内的相片生成S或M缩略图;
  1332. // 参数:
  1333. // dir: 需要生成缩略图的文件目录;
  1334. // bMPhoto: 是否生成M缩略图;
  1335. // 其它:
  1336. // 在生成缩略图前,记录jpg文件总数nOldCount,每生成一个缩略图nOldCount++;
  1337. // 最后全部图生成完毕,获取新的jpg文件总数nNewCount,if(nOldCount == nNewCount)则表示所有相片已生成缩略图完毕,生成ok文件表示成功生成缩略图;
  1338. //
  1339. // 函数调用全局参数:
  1340. // g_bSteal:意义未明!
  1341. //
  1342. // 注意:该函数非线程安全!
  1343. // 非线程安全:
  1344. // 获取文件总数nOldCount结束后,若有新文件在本函数以外其他函数或进程、线程被添加,则生成缩略图完成后再次获取文件总数nNewCount就不会与nOldCount++后的结果相等;
  1345. // 而实际上本次缩略图已生成完毕。
  1346. // ---------------------------------------------------------------------------------------------------------------------------------------------------------------
  1347. void GenSPhoto(CString dir, BOOL bMPhoto) // 参数:bMPhoto:是否生成M缩略图;
  1348. {
  1349. // 如果是公告附件目录退出;
  1350. if (dir.Find("公告附件") != -1)return;
  1351. // 如果不是客户原片或修好的片目录,设置bMPhoto参数为0,不生成M缩略图;
  1352. if (dir.Find("客户原片(管理软件)$") != -1 || dir.Find("修好的片(管理软件)$") != -1)
  1353. {
  1354. }
  1355. else
  1356. bMPhoto = 0;
  1357. // 对指定文件目录dir进行指定后缀jpg文件遍历;
  1358. ffsco o;
  1359. o.dirs(1);
  1360. o.find(LPCSTR(dir), LPCSTR("*.*"));
  1361. ffsco::typeT coo;
  1362. ffsco::typeT::iterator it;
  1363. coo = o.co_file();
  1364. int oldsize = coo.size();
  1365. CString path, temp, spath, mpath;
  1366. for (it = coo.begin(); coo.end() != it; it++)
  1367. {
  1368. try
  1369. {
  1370. if (g_pMainWnd->m_bTerminate)return;
  1371. // 遍历到的jpg文件如果是缩略图则不处理,继续遍历;
  1372. path = (*it).c_str();
  1373. spath = path.Left(path.ReverseFind('\\') + 1);
  1374. mpath = spath;
  1375. spath += "s";
  1376. mpath += "m";
  1377. temp = path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
  1378. if (temp.GetAt(0) == 's')continue;
  1379. if (temp.GetAt(0) == 'm')continue;
  1380. spath += path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
  1381. mpath += path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
  1382. if (g_bSteal)
  1383. {
  1384. Image *pImg = NULL;
  1385. ::LoadImageFromBuf(&pImg, path);
  1386. if (pImg == NULL)continue;
  1387. if (pImg->GetWidth() == 0)continue; // Jeff.continue前未释放pImg;
  1388. delete pImg;
  1389. EncryptFile3(path);
  1390. if (path.Find("客户原片") != -1)
  1391. {
  1392. int pos = path.Find("管理软件)$");
  1393. if (pos != -1)
  1394. {
  1395. path = g_bakserver1 + path.Right(path.GetLength() - pos - 10);
  1396. EncryptFile3(path);
  1397. }
  1398. }
  1399. else if (path.Find("修好的片") != -1)
  1400. {
  1401. int pos = path.Find("管理软件)$");
  1402. if (pos != -1)
  1403. {
  1404. path = g_bakserver2 + path.Right(path.GetLength() - pos - 10);
  1405. EncryptFile3(path);
  1406. }
  1407. }
  1408. else if (path.Find("精修好的片") != -1)
  1409. {
  1410. int pos = path.Find("管理软件)$");
  1411. if (pos != -1)
  1412. {
  1413. path = g_bakserver3 + path.Right(path.GetLength() - pos - 10);
  1414. EncryptFile3(path);
  1415. }
  1416. }
  1417. else if (path.Find("设计好的片") != -1)
  1418. {
  1419. int pos = path.Find("管理软件)$");
  1420. if (pos != -1)
  1421. {
  1422. path = g_bakserver4 + path.Right(path.GetLength() - pos - 10);
  1423. EncryptFile3(path);
  1424. }
  1425. }
  1426. oldsize++;
  1427. }
  1428. else if (!CheckFileExist(spath)) // 没有判断后续是否为jpg或jpeg.
  1429. {
  1430. Image *pImg = NULL;
  1431. ::LoadImageFromBuf(&pImg, path);
  1432. if (pImg == NULL)continue;
  1433. if (pImg->GetWidth() == 0)
  1434. {
  1435. // 由于没有判断spath是否是jpg或jpeg的相片文件,导致这里泄漏;
  1436. if (pImg)
  1437. delete pImg;
  1438. pImg = NULL;
  1439. continue; // Jeff.返回前未释放pImg;
  1440. }
  1441. CRect rc(0, 0, 100, 90);
  1442. RectFitDes(pImg->GetWidth(), pImg->GetHeight(), rc);
  1443. Image *simg = pImg->GetThumbnailImage(rc.Width(), rc.Height(), NULL, NULL);
  1444. if (simg == NULL)
  1445. {
  1446. if (pImg)
  1447. delete pImg;
  1448. pImg = NULL;
  1449. continue;// Jeff.返回前未释放pImg;
  1450. }
  1451. Image *simg2 = NULL;
  1452. if (bMPhoto)
  1453. {
  1454. CRect rc2(0, 0, 2000, 2000);
  1455. RectFitDes(pImg->GetWidth(), pImg->GetHeight(), rc2);
  1456. simg2 = pImg->GetThumbnailImage(rc2.Width(), rc2.Height(), NULL, NULL);
  1457. if (simg2 == NULL)
  1458. {
  1459. if (pImg)
  1460. delete pImg;
  1461. pImg = NULL;
  1462. continue;// Jeff.返回前未释放pImg;
  1463. }
  1464. }
  1465. Graphics graphic(simg);//防止GetThumbnailImage影响质量
  1466. graphic.Clear(Color(255, 255, 255, 255));
  1467. graphic.DrawImage(pImg, 0, 0, simg->GetWidth(), simg->GetHeight());
  1468. if (bMPhoto)
  1469. {
  1470. Graphics graphic2(simg2);//防止GetThumbnailImage影响质量
  1471. graphic2.Clear(Color(255, 255, 255, 255));
  1472. graphic2.DrawImage(pImg, 0, 0, simg2->GetWidth(), simg2->GetHeight());
  1473. }
  1474. ///////////////////////////////
  1475. UINT totalBufferSize;
  1476. UINT numProperties;
  1477. pImg->GetPropertySize(&totalBufferSize, &numProperties);
  1478. // Allocate the buffer that will receive the property items.
  1479. PropertyItem* pAllItems = (PropertyItem*)malloc(totalBufferSize);
  1480. // Fill the buffer.
  1481. pImg->GetAllPropertyItems(totalBufferSize, numProperties, pAllItems);
  1482. // Print the id data member of each property item.
  1483. for (UINT j = 0; j < numProperties; ++j)
  1484. {
  1485. if (PropertyTagOrientation == pAllItems[j].id)
  1486. {
  1487. short* ptrLong = (short*)(pAllItems[j].value);
  1488. int ret = (int)*ptrLong;
  1489. // CString str;
  1490. // str.Format ("%d", ret);
  1491. // AfxMessageBox(str);
  1492. if (ret == 8)
  1493. {
  1494. if (simg2)simg2->RotateFlip(Rotate270FlipNone);
  1495. simg->RotateFlip(Rotate270FlipNone);
  1496. }
  1497. else if (ret == 6)
  1498. {
  1499. if (simg2)simg2->RotateFlip(Rotate90FlipNone);
  1500. simg->RotateFlip(Rotate90FlipNone);
  1501. }
  1502. break;
  1503. }
  1504. }
  1505. free(pAllItems);
  1506. ///////////////////////////////
  1507. ::SaveImageToFile(simg, spath); oldsize++;
  1508. delete simg;
  1509. delete pImg;
  1510. if (bMPhoto)
  1511. {
  1512. ::SaveImageToFile2(simg2, mpath, 100); oldsize++;
  1513. delete simg2;
  1514. }
  1515. }
  1516. }
  1517. catch (...)
  1518. {
  1519. WriteTextLog("出错在函数GenSPhoto中");
  1520. }
  1521. }
  1522. try
  1523. {
  1524. ffsco o;
  1525. o.dirs(1);
  1526. o.find(LPCSTR(dir), LPCSTR("*.*"));
  1527. ffsco::typeT coo;
  1528. ffsco::typeT::iterator it;
  1529. coo = o.co_file();
  1530. int newsize = coo.size();
  1531. if (oldsize == newsize)
  1532. {
  1533. path = dir + "\\ok";
  1534. CFile fp;
  1535. fp.Open(path, CFile::modeCreate | CFile::modeWrite);
  1536. fp.Close();
  1537. }
  1538. }
  1539. catch (...)
  1540. {
  1541. WriteTextLog("出错在函数GenSPhoto2中");
  1542. }
  1543. }
  1544. //--------------------------------------------------------------------------------
  1545. // Remark by Jeff 2014.10.22
  1546. // 函数:LoadThumbNail
  1547. // 描述:S或M缩略图线程
  1548. // 参数:
  1549. // 返回:
  1550. //
  1551. // 调用关系:SetTimer(1);
  1552. // 1.
  1553. // 2.
  1554. // 3.
  1555. //--------------------------------------------------------------------------------
  1556. unsigned __stdcall LoadThumbNail(LPVOID lpParam)
  1557. {
  1558. BOOL bMphoto = 0;
  1559. if (g_bSteal == 0)
  1560. {
  1561. CDatabase *pMaindb = NULL;
  1562. ODBCConnGuard ConnGuard(pMaindb , -1, 3000);
  1563. if ( pMaindb )
  1564. {
  1565. try
  1566. {
  1567. CRecordset myset(pMaindb);
  1568. CString sql = "select * from version";
  1569. myset.Open(CRecordset::forwardOnly, sql);
  1570. myset.GetFieldValue("setcheck15", sql); // 选片时是否使用m缩略图来代替原片放大使用;
  1571. myset.Close();
  1572. bMphoto = atoi(sql);
  1573. }
  1574. catch (CDBException* e)
  1575. {
  1576. WriteTextLog(_T("LoadThumbNail:%s"),e->m_strError);
  1577. e->Delete();
  1578. }
  1579. }
  1580. }
  1581. CString initialPhotoPath = _T("");
  1582. CString initialModifyPath = _T("");
  1583. CString designPhotoPath = _T("");
  1584. CString excellentModifyPath = _T("");
  1585. char server[50] = {0};
  1586. DWORD leng = 50;
  1587. ::GetComputerName(server, &leng);
  1588. initialPhotoPath = initialModifyPath = designPhotoPath = excellentModifyPath = server;
  1589. initialPhotoPath = "\\\\" + initialPhotoPath + "\\客户原片(管理软件)$";
  1590. initialModifyPath = "\\\\" + initialModifyPath + "\\修好的片(管理软件)$";
  1591. designPhotoPath = "\\\\" + designPhotoPath + "\\设计好的片(管理软件)$";
  1592. excellentModifyPath = "\\\\" + excellentModifyPath + "\\精修好的片(管理软件)$";
  1593. GetPathFromNetShareName("客户原片(管理软件)$", initialPhotoPath);
  1594. GetPathFromNetShareName("修好的片(管理软件)$", initialModifyPath);
  1595. GetPathFromNetShareName("设计好的片(管理软件)$", designPhotoPath);
  1596. GetPathFromNetShareName("精修好的片(管理软件)$", excellentModifyPath);
  1597. int i = 0;
  1598. CDBServerDlg *pDlg = (CDBServerDlg*)lpParam;
  1599. try
  1600. {
  1601. CStringArray dirarray;
  1602. // Remark:Jeff.
  1603. // 遍历原片、修好片、设计片、精修片目录,查看是否有ok或ok.dat文件存在;
  1604. // 说明:ok文件在客户端再次导入相片时会被删除;
  1605. // 只有服务端生成小图后,ok才被重新生成;
  1606. if(CBranchInfo::GetInstance()->m_TblNetShareInfo.size() != 0)
  1607. {
  1608. vector<TblNetShareInfo*>::iterator iter = CBranchInfo::GetInstance()->m_TblNetShareInfo.begin();
  1609. for(; iter != CBranchInfo::GetInstance()->m_TblNetShareInfo.end();)
  1610. {
  1611. TblNetShareInfo* p = (*iter);
  1612. if(p != NULL)
  1613. {
  1614. CString strDir = p->szShareDirectory;
  1615. if(strDir.Find(_T("$\\")) != -1)
  1616. strDir = strDir.TrimRight(_T("\\"));
  1617. pDlg->CheckOkFileExistence(strDir, dirarray);
  1618. }
  1619. ++iter;
  1620. }
  1621. CString patharray[2] = { designPhotoPath, excellentModifyPath };
  1622. //int i = 0;
  1623. for (i = 0; i < 2; i++)
  1624. {
  1625. if (pDlg->m_bTerminate)
  1626. break;
  1627. pDlg->CheckOkFileExistence(patharray[i], dirarray);
  1628. }
  1629. }
  1630. else
  1631. {
  1632. CString patharray[4] = { initialPhotoPath, initialModifyPath, designPhotoPath, excellentModifyPath };
  1633. for (i = 0; i < 4; i++)
  1634. {
  1635. if (pDlg->m_bTerminate)
  1636. break;
  1637. pDlg->CheckOkFileExistence(patharray[i], dirarray);
  1638. }
  1639. }
  1640. for (i = 0; i < dirarray.GetSize(); i++)
  1641. {
  1642. if (pDlg->m_bTerminate)
  1643. break;
  1644. GenSPhoto(dirarray.ElementAt(i), bMphoto);
  1645. }
  1646. }
  1647. catch (...)
  1648. {
  1649. WriteTextLog("出错在函数GenThumb中");
  1650. }
  1651. pDlg->m_bRunning = false;
  1652. pDlg->m_bTerminate = false;
  1653. pDlg->SetTimer(1, 60 * 1000, NULL);
  1654. _endthreadex(0);
  1655. return 0;
  1656. }
  1657. //--------------------------------------------------------------------------------
  1658. // 函数:CheckOkFileExistence
  1659. // 描述:OK文件是否存在
  1660. // 参数:
  1661. // const CString& strPath 需要搜索的目录
  1662. // CStringArray& arr 返回文件目录
  1663. // 返回:TRUE成功,FALSE失败
  1664. //--------------------------------------------------------------------------------
  1665. BOOL CDBServerDlg::CheckOkFileExistence(const CString& strPath, CStringArray& arr)
  1666. {
  1667. CString path(_T("")), path2(_T(""));
  1668. if(strPath == _T(""))
  1669. return FALSE;
  1670. ffsco o;
  1671. o.dirs(1);
  1672. o.find(LPCSTR(strPath), LPCSTR("*.*"));
  1673. ffsco::typeT coo;
  1674. ffsco::typeT::iterator it;
  1675. coo = o.co_dir();
  1676. it = coo.begin();
  1677. it++;
  1678. for(; coo.end() != it; it++)
  1679. {
  1680. if (m_bTerminate)
  1681. break;
  1682. path = (*it).c_str();
  1683. path.TrimRight("\\");
  1684. path2 = path;
  1685. path2 += "\\ok2.dat";
  1686. path += "\\ok";
  1687. if (CheckFileExist(path2) && path2.Find(".ly.com") == -1)
  1688. {
  1689. ::DeleteFile(path); // 删除ok文件;
  1690. ::DeleteFile(path2); // 删除ok.dat文件;
  1691. }
  1692. // g_bCheckAll g_bSteal的意义???
  1693. // g_bCheckAll没有任何其他赋值的代码,只有最开始初始化值0;下这if不执行;
  1694. if (g_bCheckAll || g_bSteal)
  1695. {
  1696. if (FindArray(&arr, (*it).c_str()) == -1)
  1697. arr.Add((*it).c_str());
  1698. }
  1699. else if (CheckFileExist(path) == 0)
  1700. {
  1701. if (FindArray(&arr, (*it).c_str()) == -1)
  1702. arr.Add((*it).c_str());
  1703. }
  1704. }
  1705. return 1;
  1706. }
  1707. //自动生成小图线程;
  1708. void CDBServerDlg::LoadThumbImages() // 自动生成小图线程;
  1709. {
  1710. if (m_bRunning)return;
  1711. TerminateThread();
  1712. m_bRunning = true;
  1713. m_hThread = (HANDLE)_beginthreadex(NULL, 0, LoadThumbNail, (LPVOID)this, 0/* CREATE_SUSPENDED*/, &m_dwThreadID);
  1714. }
  1715. BOOL CDBServerDlg::TerminateThread()
  1716. {
  1717. try
  1718. {
  1719. if (!m_bRunning)
  1720. return TRUE;
  1721. m_bTerminate = true;
  1722. for (;;)
  1723. {
  1724. if (::WaitForSingleObject(m_hThread, INFINITE) == WAIT_OBJECT_0)
  1725. break;
  1726. }
  1727. ::CloseHandle(m_hThread);
  1728. m_bRunning = false;
  1729. return TRUE;
  1730. }
  1731. catch (...)
  1732. {
  1733. WriteTextLog("出错在函数TerminateThread中");
  1734. }
  1735. return TRUE;
  1736. }
  1737. void CDBServerDlg::InitLia()
  1738. {
  1739. try
  1740. {
  1741. // Jeff:逆天的变量命名!!!局部变量竟然用g_开头!!!
  1742. //BYTE *g_pData=NULL;DWORD g_nLeng; DWORD count2;
  1743. BYTE *pReturnData = NULL;
  1744. DWORD dwReturnLen;
  1745. DWORD count2;
  1746. BYTE byCode = 104;
  1747. CConnectSocket consock;
  1748. ODBCConnGuard ConnGuard(consock.m_pConndb, -1, 3000);
  1749. if ( consock.m_pConndb == NULL )
  1750. return;
  1751. consock.GetDataFromCode(byCode, &pReturnData, dwReturnLen, count2, "");
  1752. if (pReturnData == NULL || dwReturnLen == 0)
  1753. return;
  1754. DWORD readbytes = 0;
  1755. CArray<DWORD, DWORD> ArrayOfLen;
  1756. CArray<DWORD, DWORD> ArrayOfBtnLen;
  1757. BYTE *pArrayPointer = NULL;
  1758. DWORD dwPointerLen = 0;
  1759. DWORD leng;
  1760. memcpy(&leng, pReturnData + readbytes, sizeof(DWORD));
  1761. readbytes += sizeof(DWORD);
  1762. BYTE *pFtData = new BYTE[leng];
  1763. memcpy(pFtData, pReturnData + readbytes, leng);
  1764. readbytes += leng;
  1765. CMemFile memfile;
  1766. memfile.Attach(pFtData, leng);
  1767. CArchive ar(&memfile, CArchive::load);
  1768. ArrayOfLen.Serialize(ar);
  1769. ar.Close();
  1770. memfile.Detach();
  1771. memcpy(&leng, pReturnData + readbytes, sizeof(DWORD));
  1772. readbytes += sizeof(DWORD);
  1773. BYTE *pFtData2 = new BYTE[leng];
  1774. memcpy(pFtData2, pReturnData + readbytes, leng);
  1775. readbytes += leng;
  1776. CMemFile memfile2;
  1777. memfile2.Attach(pFtData2, leng);
  1778. CArchive ar2(&memfile2, CArchive::load);
  1779. ArrayOfBtnLen.Serialize(ar2);
  1780. ar2.Close();
  1781. memfile2.Detach();
  1782. delete[]pFtData;
  1783. delete[]pFtData2;
  1784. DWORD count;
  1785. memcpy(&count, pReturnData + readbytes, sizeof(DWORD));
  1786. readbytes += sizeof(DWORD);
  1787. dwPointerLen = count*sizeof(RESDATA2);
  1788. pArrayPointer = new BYTE[dwPointerLen];
  1789. int i = 0;
  1790. for (i = 0; i < count; i++)
  1791. {
  1792. memcpy(pArrayPointer + i*sizeof(RESDATA2), pReturnData + readbytes, sizeof(RESDATA2));
  1793. readbytes += sizeof(RESDATA2);
  1794. }
  1795. for (i = 0; i < ArrayOfLen.GetSize(); i += 8)
  1796. {
  1797. DWORD leng1, leng2, leng3, leng4, leng5, leng6, leng7, leng8;
  1798. leng1 = ArrayOfLen.ElementAt(i);
  1799. leng2 = ArrayOfLen.ElementAt(i + 1);
  1800. leng3 = ArrayOfLen.ElementAt(i + 2);
  1801. leng4 = ArrayOfLen.ElementAt(i + 3);
  1802. leng5 = ArrayOfLen.ElementAt(i + 4);
  1803. leng6 = ArrayOfLen.ElementAt(i + 5);
  1804. leng7 = ArrayOfLen.ElementAt(i + 6);
  1805. leng8 = ArrayOfLen.ElementAt(i + 7);
  1806. if (i % 4 == 0)
  1807. DeCodelong1((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8);
  1808. else if (i % 4 == 1)
  1809. DeCodelong2((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8);
  1810. else if (i % 4 == 2)
  1811. DeCodelong3((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8);
  1812. else
  1813. DeCodelong4((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8);
  1814. ArrayOfLen.SetAt(i, leng1);
  1815. ArrayOfLen.SetAt(i + 1, leng2);
  1816. ArrayOfLen.SetAt(i + 2, leng3);
  1817. ArrayOfLen.SetAt(i + 3, leng4);
  1818. ArrayOfLen.SetAt(i + 4, leng5);
  1819. ArrayOfLen.SetAt(i + 5, leng6);
  1820. ArrayOfLen.SetAt(i + 6, leng7);
  1821. ArrayOfLen.SetAt(i + 7, leng8);
  1822. }
  1823. delete[]pReturnData;
  1824. if (g_pSkinData)
  1825. delete[]g_pSkinData;
  1826. g_pSkinData = NULL;
  1827. DWORD length;
  1828. BYTE *pData;
  1829. DWORD length2;
  1830. BYTE *pData2;
  1831. CMemFile mStoreFile;
  1832. CArchive arStore(&mStoreFile, CArchive::store);
  1833. ArrayOfLen.Serialize(arStore);
  1834. arStore.Close();
  1835. length = mStoreFile.GetLength();
  1836. pData = mStoreFile.Detach();
  1837. CMemFile mStoreFile1;
  1838. CArchive arStore1(&mStoreFile1, CArchive::store);
  1839. ArrayOfBtnLen.Serialize(arStore1);
  1840. arStore1.Close();
  1841. length2 = mStoreFile1.GetLength();
  1842. pData2 = mStoreFile1.Detach();
  1843. g_SkinLeng = length + length2 + dwPointerLen + 3 * sizeof(DWORD);
  1844. g_pSkinData = new BYTE[g_SkinLeng];
  1845. readbytes = 0;
  1846. memcpy(g_pSkinData + readbytes, &length, sizeof(DWORD));
  1847. readbytes += sizeof(DWORD);
  1848. memcpy(g_pSkinData + readbytes, pData, length);
  1849. readbytes += length;
  1850. memcpy(g_pSkinData + readbytes, &length2, sizeof(DWORD));
  1851. readbytes += sizeof(DWORD);
  1852. memcpy(g_pSkinData + readbytes, pData2, length2);
  1853. readbytes += length2;
  1854. memcpy(g_pSkinData + readbytes, &dwPointerLen, sizeof(DWORD));
  1855. readbytes += sizeof(DWORD);
  1856. memcpy(g_pSkinData + readbytes, pArrayPointer, dwPointerLen);
  1857. readbytes += dwPointerLen;
  1858. delete[]pArrayPointer;
  1859. }
  1860. catch (...)
  1861. {
  1862. WriteTextLog("出错在函数InitLia中");
  1863. }
  1864. }
  1865. BOOL CheckExistDinDan(CString id)
  1866. {
  1867. CDatabase *pMaindb = NULL;
  1868. ODBCConnGuard ConnGuard(pMaindb, -1, 30000);
  1869. if ( pMaindb == NULL )
  1870. return FALSE;
  1871. CRecordset myset(pMaindb);
  1872. CString sql = "select count(*) as cot from dindan where id='" + id + "'";
  1873. myset.Open(CRecordset::forwardOnly, sql);
  1874. myset.GetFieldValue("cot", sql);
  1875. myset.Close();
  1876. return atol(sql);
  1877. }
  1878. //CString g_nCurConvertDBName="db"; // Jeff.deal
  1879. CString g_nCurConvertDBName(g_szDBName);
  1880. DWORD CDBServerDlg::ThreadCallerElves(LPVOID lpPara)
  1881. {
  1882. CArray<int, int>codearray;
  1883. codearray.Add(80);
  1884. codearray.Add(90);
  1885. codearray.Add(11);
  1886. codearray.Add(138);
  1887. codearray.Add(24);
  1888. codearray.Add(181);
  1889. codearray.Add(65);
  1890. codearray.Add(56);
  1891. codearray.Add(179);
  1892. codearray.Add(53);
  1893. CFile fp;
  1894. CString savepath, strPath1;
  1895. char server[50];
  1896. DWORD leng = 50;
  1897. ::GetComputerName(server, &leng);
  1898. strPath1 = server;
  1899. strPath1 = "\\\\" + strPath1 + "\\电话录音(管理软件)$";
  1900. GetPathFromNetShareName("电话录音(管理软件)$", strPath1);
  1901. if (strPath1.IsEmpty())
  1902. return 0;
  1903. try
  1904. {
  1905. CDatabase *pMaindb = NULL;
  1906. for ( int i = 0; i < g_dbpool.GetSize(); i++ )
  1907. {
  1908. ODBCConnGuard ConnGuard(pMaindb, i-1, 3000);
  1909. if ( !pMaindb )
  1910. continue;
  1911. savepath.Format("%s\\uphonedata%d.dat", strPath1, i);
  1912. ::DeleteFile(savepath); // 删除uphonedata.dat文件;
  1913. if (fp.Open(savepath, CFile::modeCreate | CFile::modeWrite) == 0)
  1914. {
  1915. WriteTextLog("更新来电精灵数据出错");
  1916. return 0;
  1917. }
  1918. CConnectSocket consock;
  1919. consock.m_pConndb = pMaindb;
  1920. for (int i = 0; i < codearray.GetSize(); i++)
  1921. {
  1922. BYTE code = codearray.ElementAt(i);
  1923. DWORD length, arraysize;
  1924. BYTE *pReturn = NULL;
  1925. consock.GetDataFromCode(code, &pReturn, length, arraysize, "");
  1926. fp.Write(&code, sizeof(BYTE));
  1927. fp.Write(&length, sizeof(DWORD));
  1928. fp.Write(&arraysize, sizeof(DWORD));
  1929. fp.Write(pReturn, length);
  1930. }
  1931. fp.Close();
  1932. }
  1933. }
  1934. catch (CException *e)
  1935. {
  1936. TCHAR szError[1024] = { 0 };
  1937. e->GetErrorMessage(szError, 1024);
  1938. WriteTextLog(CString(szError));
  1939. WriteTextLog("获取来电精灵数据出错1");
  1940. e->Delete();
  1941. }
  1942. return 0;
  1943. }
  1944. /************************************************************************/
  1945. /* [函数]:CheckHistoryData
  1946. /* [描述]:将被检测的数据库已完成的订单数据转到历史数据库中,并删除被检测的数据库已完成的订单;
  1947. /* [参数]:
  1948. /* pSrcdb: 源数据库,用于被转历史的数据库;
  1949. /* nSrcYear: 源数据库的年份;
  1950. /* bMode2: 转储模式:0=年度完成的订单; 1=年度所有订单,包含未完成订单;
  1951. /* [返回]:void
  1952. /*
  1953. /************************************************************************/
  1954. void CDBServerDlg::CheckHistoryData(CDatabase *pSrcdb /* = NULL */, int nSrcYear /* = 0 */, BOOL bMode2 /* = 0*/)//历史备份;
  1955. {
  1956. #if 0
  1957. // 取消转将当前数据库完成订单的记录转到年份数据库中,此步直接返回;
  1958. /////////////////////////生成来电精灵数据
  1959. MyLock lock("processChatMessageRequestxiao");
  1960. CArray<int, int>codearray;
  1961. codearray.Add(80);
  1962. codearray.Add(90);
  1963. codearray.Add(11);
  1964. codearray.Add(138);
  1965. codearray.Add(24);
  1966. codearray.Add(181);
  1967. codearray.Add(65);
  1968. codearray.Add(56);
  1969. codearray.Add(179);
  1970. codearray.Add(53);
  1971. CFile fp;
  1972. CString savepath, g_path1;
  1973. char server[50];
  1974. DWORD leng = 50;
  1975. ::GetComputerName(server, &leng);
  1976. g_path1 = server;
  1977. g_path1 = "\\\\" + g_path1 + "\\电话录音(管理软件)$";
  1978. GetPathFromNetShareName("电话录音(管理软件)$", g_path1);
  1979. if (g_path1.IsEmpty())return;
  1980. try
  1981. {
  1982. CDatabase *pdb = NULL;
  1983. for ( int i = 0; i < g_dbpool.GetSize(); i++ )
  1984. {
  1985. ODBCConnGuard ConnGuard(pdb, i-1, 3000);
  1986. if ( !pdb )
  1987. continue;
  1988. savepath.Format("%s\\uphonedata%d.dat", g_path1, i);
  1989. ::DeleteFile(savepath); // 删除uphonedata.dat文件;
  1990. if (fp.Open(savepath, CFile::modeCreate | CFile::modeWrite) == 0)
  1991. {
  1992. WriteTextLog("更新来电精灵数据出错");
  1993. return;
  1994. }
  1995. CConnectSocket consock;
  1996. consock.m_pConndb = pdb;
  1997. for (int i = 0; i < codearray.GetSize(); i++)
  1998. {
  1999. BYTE code = codearray.ElementAt(i);
  2000. DWORD length, arraysize;
  2001. BYTE *pReturn = NULL;
  2002. consock.GetDataFromCode(code, &pReturn, length, arraysize, "");
  2003. fp.Write(&code, sizeof(BYTE));
  2004. fp.Write(&length, sizeof(DWORD));
  2005. fp.Write(&arraysize, sizeof(DWORD));
  2006. fp.Write(pReturn, length);
  2007. }
  2008. fp.Close();
  2009. }
  2010. }
  2011. catch (CException *e)
  2012. {
  2013. TCHAR szError[1024] = { 0 };
  2014. e->GetErrorMessage(szError, 1024);
  2015. WriteTextLog(CString(szError));
  2016. WriteTextLog("获取来电精灵数据出错1");
  2017. e->Delete();
  2018. }
  2019. #endif
  2020. HANDLE h = CreateThread(NULL, 0, ThreadCallerElves, this, 0, NULL);
  2021. if ( h )CloseHandle(h);
  2022. }
  2023. //------------------------------------------------------------------------------------
  2024. // Jeff remark
  2025. // 函数:CheckYear
  2026. // 描述:
  2027. // 1.检查指定年份的历史数据库mdf文件是否存在,存在则直接附加
  2028. // 2.不存在,则使用null.mdf文件拷贝创建历史年份数据库mdf并附加;
  2029. // 参数:
  2030. // year:被检查年份值;
  2031. // 返回:void
  2032. //------------------------------------------------------------------------------------
  2033. #if JEFF_TEST_ON
  2034. void CDBServerDlg::CheckYear(int year)
  2035. {
  2036. CDatabase *pMaindb = NULL;
  2037. ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
  2038. if ( pMaindb == NULL )
  2039. return;
  2040. pMaindb->SetQueryTimeout(6000);
  2041. try
  2042. {
  2043. #ifdef SQLSERVER_VERSION
  2044. CString sql;
  2045. // 1.判断年份数据库是否存在;
  2046. CString strPathOfYearmdf;
  2047. CString strPathOfYearldf;
  2048. strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, year);
  2049. strPathOfYearldf.Format("%s\\数据\\%d_log.ldf", g_mainpath, year);
  2050. CString strPathOfnulldbmdf = g_mainpath + "\\数据\\dbnull.mdf";
  2051. CString strPathOfnulldbldf = g_mainpath + "\\数据\\dbnull_log.ldf";
  2052. if (PathFileExists(strPathOfYearmdf) == TRUE)
  2053. {
  2054. if (PathFileExists(strPathOfYearldf) == TRUE)
  2055. {
  2056. sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", year, strPathOfYearmdf, strPathOfYearldf);
  2057. }
  2058. else
  2059. {
  2060. // 此时要删除dbnull_log.ldf文件;
  2061. // 因为如果2015没有对应的ldf文件,在逻辑名仍为dbnull没有改为2015时,他会使用dbnull_log.ldf做为2015数据库的日志文件;
  2062. // 这样造成其他数据库在使用dbnull时会产生错误;
  2063. DeleteFile(strPathOfnulldbldf);//删除dbnull_log.ldf文件;
  2064. sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf);
  2065. }
  2066. try
  2067. {
  2068. pMaindb->ExecuteSQL(sql);
  2069. }
  2070. catch (CDBException * e)
  2071. {
  2072. WriteTextLog(e->m_strError);
  2073. WriteTextLog("历史数据库初始化失败!");
  2074. #ifdef _DEBUG
  2075. e->ReportError();
  2076. #endif
  2077. e->Delete();
  2078. return;
  2079. }
  2080. }
  2081. else
  2082. {
  2083. // 判断dbnull.mdf文件是否存在;
  2084. if (PathFileExists(strPathOfnulldbmdf) == FALSE)
  2085. {
  2086. WriteTextLog("空数据库丢失!");
  2087. return;
  2088. }
  2089. // 判断拷贝mdf文件是否失败;
  2090. if (FALSE == CopyFile(strPathOfnulldbmdf, strPathOfYearmdf, 1))
  2091. {
  2092. DWORD dwError = ::GetLastError();
  2093. CString strDescription;
  2094. strDescription.Format("dbnull.mdf拷贝为%d.mdf失败", year);
  2095. ErrorExit(strDescription, dwError);
  2096. return;
  2097. }
  2098. else
  2099. {
  2100. DeleteFile(strPathOfYearldf); // 删除%d_log.LDF文件;
  2101. if (PathFileExists(strPathOfnulldbldf) == TRUE)
  2102. {
  2103. if (FALSE == CopyFile(strPathOfnulldbldf, strPathOfYearldf, 1))
  2104. {
  2105. DWORD dwError = ::GetLastError();
  2106. CString strDescription;
  2107. strDescription.Format("null.mdf拷贝为%d.mdf", year);
  2108. ErrorExit(strDescription, dwError);
  2109. // 此时要删除dbnull_log.ldf文件;
  2110. // 因为如果2015没有对应的ldf文件,在逻辑名仍为dbnull没有改为2015时,他会使用dbnull_log.ldf做为2015数据库的日志文件;
  2111. // 这样造成其他数据库在使用dbnull时会产生错误;
  2112. DeleteFile(strPathOfnulldbldf);//删除dbnull_log.ldf文件;
  2113. sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf);
  2114. }
  2115. else
  2116. {
  2117. sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", year, strPathOfYearmdf, strPathOfYearldf);
  2118. }
  2119. }
  2120. else
  2121. {
  2122. // 此时要删除dbnull_log.ldf文件;
  2123. // 因为如果2015没有对应的ldf文件,在逻辑名仍为dbnull没有改为2015时,他会使用dbnull_log.ldf做为2015数据库的日志文件;
  2124. // 这样造成其他数据库在使用dbnull时会产生错误;
  2125. DeleteFile(strPathOfnulldbldf);//删除dbnull_log.ldf文件;
  2126. sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf);
  2127. }
  2128. try
  2129. {
  2130. pMaindb->ExecuteSQL(sql);
  2131. }
  2132. catch (CDBException * e)
  2133. {
  2134. WriteTextLog(e->m_strError);
  2135. WriteTextLog("历史数据库初始化失败!");
  2136. #ifdef _DEBUG
  2137. e->ReportError();
  2138. #endif
  2139. e->Delete();
  2140. return;
  2141. }
  2142. }
  2143. }
  2144. // 附加成功后,修改逻辑名称;
  2145. sql.Format("alter database [%d] modify file(name='dbnull',newname='%d')", year, year);
  2146. try
  2147. {
  2148. pMaindb->ExecuteSQL(sql);
  2149. }
  2150. catch (CDBException * e)
  2151. {
  2152. WriteTextLog(e->m_strError);
  2153. WriteTextLog("修改历史数据库主文件逻辑名失败,请手动修改!");
  2154. #ifdef _DEBUG
  2155. e->ReportError();
  2156. #endif
  2157. e->Delete();
  2158. }
  2159. sql.Format("alter database [%d] modify file(name='dbnull_log',newname='%d_log')", year, year);
  2160. try
  2161. {
  2162. pMaindb->ExecuteSQL(sql);
  2163. }
  2164. catch (CDBException * e)
  2165. {
  2166. WriteTextLog(e->m_strError);
  2167. WriteTextLog("修改历史数据库日志文件逻辑名失败,请手动修改!");
  2168. #ifdef _DEBUG
  2169. e->ReportError();
  2170. #endif
  2171. e->Delete();
  2172. }
  2173. OnExit2();
  2174. #else
  2175. CString path,sql;
  2176. path.Format ("%s\\数据\\%d.mdb", g_mainpath, year);
  2177. if(::PathFileExists (path)==0)
  2178. {
  2179. CString nulldb=g_mainpath+"\\数据\\dbnull.mdb";
  2180. ::CopyFile (nulldb, path, 1);
  2181. CDatabase *db=new CDatabase;
  2182. CString strCon;
  2183. strCon.Format("DRIVER=Microsoft Access Driver (*.mdb);DSN='';DBQ=%s;PWD=lijialyfz",path);
  2184. if(db->OpenEx(strCon,CDatabase::noOdbcDialog))
  2185. {
  2186. g_nYearArray.Add (year);
  2187. g_dbHistoryArray.Add (db);
  2188. sql.Format ("insert into historydb([year])values('%d')", year);
  2189. MyExecuteSQL(&g_db, sql);
  2190. }
  2191. else
  2192. delete db;
  2193. }
  2194. #endif
  2195. }
  2196. catch (...)
  2197. {
  2198. WriteTextLog("出错在函数CheckYear中");
  2199. }
  2200. }
  2201. #else
  2202. void CDBServerDlg::CheckYear(int year)
  2203. {
  2204. try
  2205. {
  2206. #ifdef SQLSERVER_VERSION
  2207. CString strPathOfYearmdf;
  2208. CString strPathOfYearldf;
  2209. CString sql;
  2210. strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, year);
  2211. strPathOfYearldf.Format("%s\\数据\\%d_log.LDF", g_mainpath, year);
  2212. ::DeleteFile(strPathOfYearldf); // 删除%d_log.LDF文件;
  2213. {
  2214. CString strPathOfnulldbmdf = g_mainpath + "\\数据\\dbnull.mdf";
  2215. CString strPathOfnulldbldf = g_mainpath + "\\数据\\dbnull_log.LDF";
  2216. ::DeleteFile(strPathOfnulldbldf); // 删除%d_log.LDF文件;
  2217. // 1.判断null.mdf文件是否存在;
  2218. if (::PathFileExists(strPathOfnulldbmdf) == 0)
  2219. {
  2220. WriteTextLog("空数据库丢失!");
  2221. return;
  2222. }
  2223. // 2.若年份mdf文件不存在,用null.mdf复制一份年份mdf数据库文件;
  2224. BOOL bCopyed = 0;
  2225. if (::PathFileExists(strPathOfYearmdf) == 0)
  2226. {
  2227. #if 0
  2228. ::CopyFile(nulldb, path, 1);
  2229. bCopyed=1;
  2230. #else // Jeff add:判断拷贝文件失败的原因;
  2231. if (!::CopyFile(strPathOfnulldbmdf, strPathOfYearmdf, 1))
  2232. {
  2233. DWORD dwError = ::GetLastError();
  2234. CString strDescription;
  2235. strDescription.Format("null.mdf拷贝为%d.mdf", year);
  2236. ErrorExit(strDescription, dwError);
  2237. // return;//直接返回;
  2238. }
  2239. else
  2240. {
  2241. bCopyed = 1;
  2242. }
  2243. #endif
  2244. }
  2245. if (::PathFileExists(strPathOfYearmdf) == 0)
  2246. {
  2247. WriteTextLog("拷贝数据库文件失败!");
  2248. return;
  2249. }
  2250. BOOL bLog = 0;
  2251. if (::PathFileExists(strPathOfnulldbldf))
  2252. {
  2253. bLog = 1;
  2254. }
  2255. // .将年份数据库mdf附加到数据库里;
  2256. CString sql;
  2257. if (bCopyed)
  2258. {
  2259. if (bLog)
  2260. sql.Format("exec sp_attach_db '%s',@filename1='%s',@filename2='%s'", "dbnull", strPathOfYearmdf, strPathOfYearldf);
  2261. else
  2262. sql.Format("exec sp_attach_db '%s',@filename1='%s'", "dbnull", strPathOfYearmdf);
  2263. g_db.SetQueryTimeout(600);
  2264. try
  2265. {
  2266. g_db.ExecuteSQL(sql);
  2267. }
  2268. catch (CDBException * e)
  2269. {
  2270. WriteTextLog(e->m_strError);
  2271. WriteTextLog("历史数据库初始化失败!");
  2272. #ifdef _DEBUG
  2273. e->ReportError();
  2274. #endif
  2275. e->Delete();
  2276. }
  2277. sql.Format("exec sp_renamedb '%s','%d'", "dbnull", year); g_db.ExecuteSQL(sql);
  2278. }
  2279. else // 没有执行CopyFile,年份mdf原本就存在;
  2280. {
  2281. if (bLog)
  2282. sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", year, strPathOfYearmdf, strPathOfYearldf);
  2283. else
  2284. sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf);
  2285. g_db.SetQueryTimeout(600);
  2286. try
  2287. {
  2288. g_db.ExecuteSQL(sql);
  2289. }
  2290. catch (CDBException * e)
  2291. {
  2292. WriteTextLog(e->m_strError);
  2293. WriteTextLog("历史数据库初始化失败!");
  2294. #ifdef _DEBUG
  2295. e->ReportError();
  2296. #endif
  2297. e->Delete();
  2298. }
  2299. }
  2300. OnExit2();
  2301. /* g_db.SetQueryTimeout(100);
  2302. CDatabase *db=new CDatabase;
  2303. try
  2304. {
  2305. CString strCon;
  2306. strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=%d;%s"), g_sservrename,year,g_sdbpsw);
  2307. db->OpenEx(strCon,CDatabase::noOdbcDialog);
  2308. g_nYearArray.Add (year);
  2309. dbarray.Add (db);
  2310. sql.Format ("insert into [historydb]([year])values('%d')", year);
  2311. MyExecuteSQL(&g_db, sql);
  2312. }
  2313. catch(CDBException * e)
  2314. {
  2315. delete db;
  2316. WriteTextLog(e->m_strError);
  2317. WriteTextLog("历史数据库打开失败!");
  2318. }*/
  2319. }
  2320. #else
  2321. CString path,sql;
  2322. path.Format ("%s\\数据\\%d.mdb", g_mainpath, year);
  2323. if(::PathFileExists (path)==0)
  2324. {
  2325. CString nulldb=g_mainpath+"\\数据\\dbnull.mdb";
  2326. ::CopyFile (nulldb, path, 1);
  2327. CDatabase *db=new CDatabase;
  2328. CString strCon;
  2329. strCon.Format("DRIVER=Microsoft Access Driver (*.mdb);DSN='';DBQ=%s;PWD=lijialyfz",path);
  2330. if(db->OpenEx(strCon,CDatabase::noOdbcDialog))
  2331. {
  2332. g_nYearArray.Add (year);
  2333. g_dbHistoryArray.Add (db);
  2334. sql.Format ("insert into historydb([year])values('%d')", year);
  2335. MyExecuteSQL(&g_db, sql);
  2336. }
  2337. else
  2338. delete db;
  2339. }
  2340. #endif
  2341. }
  2342. catch (...)
  2343. {
  2344. WriteTextLog("出错在函数CheckYear中");
  2345. }
  2346. }
  2347. #endif
  2348. CDatabase* CDBServerDlg::GetDB(int year)
  2349. {
  2350. try
  2351. {
  2352. for (int i = 0; i < g_nYearArray.GetSize(); i++)
  2353. {
  2354. if (g_nYearArray.ElementAt(i) == year)
  2355. {
  2356. return g_dbHistoryArray.ElementAt(i);
  2357. }
  2358. }
  2359. return NULL;
  2360. }
  2361. catch (...)
  2362. {
  2363. WriteTextLog("出错在函数GetDB中");
  2364. }
  2365. return NULL;
  2366. }
  2367. /************************************************************************/
  2368. /* mark by Jeff;
  2369. /* 函数:CheckDinDanExist
  2370. /* 描述:
  2371. /* 参数:
  2372. /* pBeConverted_db:(源)
  2373. /* pToConverted_db:(目标)
  2374. /* strOderNumber:
  2375. /* pRetArray:
  2376. /*
  2377. /* 返回:1表示正常,100及以上表示源数据库里记录 > 目标数据库记录;
  2378. /*
  2379. /************************************************************************/
  2380. BOOL CDBServerDlg::CheckDinDanExist(CDatabase *pBeConverted_db, CDatabase *pToConverted_db, CString strOderNumber, CStringArray *pRetArray)
  2381. {
  2382. try
  2383. {
  2384. pRetArray->RemoveAll();
  2385. int count1 = 0;
  2386. int count2 = 0;
  2387. CString sql;
  2388. {
  2389. CRecordset myset(pBeConverted_db);
  2390. sql = "select count(*) as cot from dindan where id='" + strOderNumber + "'";
  2391. myset.Open(CRecordset::forwardOnly, sql);
  2392. myset.GetFieldValue("cot", sql);
  2393. myset.Close();
  2394. count1 = atoi(sql);
  2395. }
  2396. {
  2397. CRecordset myset(pToConverted_db);
  2398. sql = "select count(*) as cot from dindan where id='" + strOderNumber + "'";
  2399. myset.Open(CRecordset::forwardOnly, sql);
  2400. myset.GetFieldValue("cot", sql);
  2401. myset.Close();
  2402. count2 = atoi(sql);
  2403. }
  2404. if (count1 > count2)//100
  2405. pRetArray->Add("0");
  2406. else
  2407. pRetArray->Add("1");
  2408. {
  2409. CRecordset myset(pBeConverted_db);
  2410. sql = "select count(*) as cot from dindansp where id='" + strOderNumber + "'";
  2411. myset.Open(CRecordset::forwardOnly, sql);
  2412. myset.GetFieldValue("cot", sql);
  2413. myset.Close();
  2414. count1 = atoi(sql);
  2415. }
  2416. {
  2417. CRecordset myset(pToConverted_db);
  2418. sql = "select count(*) as cot from dindansp where id='" + strOderNumber + "'";
  2419. myset.Open(CRecordset::forwardOnly, sql);
  2420. myset.GetFieldValue("cot", sql);
  2421. myset.Close();
  2422. count2 = atoi(sql);
  2423. }
  2424. if (count1 > count2)//101
  2425. pRetArray->Add("0");
  2426. else
  2427. pRetArray->Add("1");
  2428. {
  2429. CRecordset myset(pBeConverted_db);
  2430. sql = "select count(*) as cot from dindanbukuan where id='" + strOderNumber + "'";
  2431. myset.Open(CRecordset::forwardOnly, sql);
  2432. myset.GetFieldValue("cot", sql);
  2433. myset.Close();
  2434. count1 = atoi(sql);
  2435. }
  2436. {
  2437. CRecordset myset(pToConverted_db);
  2438. sql = "select count(*) as cot from dindanbukuan where id='" + strOderNumber + "'";
  2439. myset.Open(CRecordset::forwardOnly, sql);
  2440. myset.GetFieldValue("cot", sql);
  2441. myset.Close();
  2442. count2 = atoi(sql);
  2443. }
  2444. if (count1 > count2)//102
  2445. pRetArray->Add("0");
  2446. else
  2447. pRetArray->Add("1");
  2448. {
  2449. CRecordset myset(pBeConverted_db);
  2450. sql = "select count(*) as cot from dindanbukuan2 where id='" + strOderNumber + "'";
  2451. myset.Open(CRecordset::forwardOnly, sql);
  2452. myset.GetFieldValue("cot", sql);
  2453. myset.Close();
  2454. count1 = atoi(sql);
  2455. }
  2456. {
  2457. CRecordset myset(pToConverted_db);
  2458. sql = "select count(*) as cot from dindanbukuan2 where id='" + strOderNumber + "'";
  2459. myset.Open(CRecordset::forwardOnly, sql);
  2460. myset.GetFieldValue("cot", sql);
  2461. myset.Close();
  2462. count2 = atoi(sql);
  2463. }
  2464. if (count1 > count2)//103
  2465. pRetArray->Add("0");
  2466. else
  2467. pRetArray->Add("1");
  2468. {
  2469. CRecordset myset(pBeConverted_db);
  2470. sql = "select count(*) as cot from photoprint where id='" + strOderNumber + "'";
  2471. myset.Open(CRecordset::forwardOnly, sql);
  2472. myset.GetFieldValue("cot", sql);
  2473. myset.Close();
  2474. count1 = atoi(sql);
  2475. }
  2476. {
  2477. CRecordset myset(pToConverted_db);
  2478. sql = "select count(*) as cot from photoprint where id='" + strOderNumber + "'";
  2479. myset.Open(CRecordset::forwardOnly, sql);
  2480. myset.GetFieldValue("cot", sql);
  2481. myset.Close();
  2482. count2 = atoi(sql);
  2483. }
  2484. if (count1 > count2)//104
  2485. pRetArray->Add("0");
  2486. else
  2487. pRetArray->Add("1");
  2488. {
  2489. CRecordset myset(pBeConverted_db);
  2490. sql = "select count(*) as cot from client where id='" + strOderNumber + "'";
  2491. myset.Open(CRecordset::forwardOnly, sql);
  2492. myset.GetFieldValue("cot", sql);
  2493. myset.Close();
  2494. count1 = atoi(sql);
  2495. }
  2496. {
  2497. CRecordset myset(pToConverted_db);
  2498. sql = "select count(*) as cot from client where id='" + strOderNumber + "'";
  2499. myset.Open(CRecordset::forwardOnly, sql);
  2500. myset.GetFieldValue("cot", sql);
  2501. myset.Close();
  2502. count2 = atoi(sql);
  2503. }
  2504. if (count1 > count2)//105
  2505. pRetArray->Add("0");
  2506. else
  2507. pRetArray->Add("1");
  2508. {
  2509. CRecordset myset(pBeConverted_db);
  2510. sql = "select count(*) as cot from burncdreg where id='" + strOderNumber + "'";
  2511. myset.Open(CRecordset::forwardOnly, sql);
  2512. myset.GetFieldValue("cot", sql);
  2513. myset.Close();
  2514. count1 = atoi(sql);
  2515. }
  2516. {
  2517. CRecordset myset(pToConverted_db);
  2518. sql = "select count(*) as cot from burncdreg where id='" + strOderNumber + "'";
  2519. myset.Open(CRecordset::forwardOnly, sql);
  2520. myset.GetFieldValue("cot", sql);
  2521. myset.Close();
  2522. count2 = atoi(sql);
  2523. }
  2524. if (count1 > count2)//7
  2525. pRetArray->Add("0");
  2526. else
  2527. pRetArray->Add("1");
  2528. {
  2529. CRecordset myset(pBeConverted_db);
  2530. sql = "select count(*) as cot from digitalwork where id='" + strOderNumber + "'";
  2531. myset.Open(CRecordset::forwardOnly, sql);
  2532. myset.GetFieldValue("cot", sql);
  2533. myset.Close();
  2534. count1 = atoi(sql);
  2535. }
  2536. {
  2537. CRecordset myset(pToConverted_db);
  2538. sql = "select count(*) as cot from digitalwork where id='" + strOderNumber + "'";
  2539. myset.Open(CRecordset::forwardOnly, sql);
  2540. myset.GetFieldValue("cot", sql);
  2541. myset.Close();
  2542. count2 = atoi(sql);
  2543. }
  2544. if (count1 > count2)//8
  2545. pRetArray->Add("0");
  2546. else
  2547. pRetArray->Add("1");
  2548. {
  2549. CRecordset myset(pBeConverted_db);
  2550. sql = "select count(*) as cot from mywork where id='" + strOderNumber + "'";
  2551. myset.Open(CRecordset::forwardOnly, sql);
  2552. myset.GetFieldValue("cot", sql);
  2553. myset.Close();
  2554. count1 = atoi(sql);
  2555. }
  2556. {
  2557. CRecordset myset(pToConverted_db);
  2558. sql = "select count(*) as cot from mywork where id='" + strOderNumber + "'";
  2559. myset.Open(CRecordset::forwardOnly, sql);
  2560. myset.GetFieldValue("cot", sql);
  2561. myset.Close();
  2562. count2 = atoi(sql);
  2563. }
  2564. if (count1 > count2)//9
  2565. pRetArray->Add("0");
  2566. else
  2567. pRetArray->Add("1");
  2568. {
  2569. CRecordset myset(pBeConverted_db);
  2570. sql = "select count(*) as cot from dindanjd where id='" + strOderNumber + "'";
  2571. myset.Open(CRecordset::forwardOnly, sql);
  2572. myset.GetFieldValue("cot", sql);
  2573. myset.Close();
  2574. count1 = atoi(sql);
  2575. }
  2576. {
  2577. CRecordset myset(pToConverted_db);
  2578. sql = "select count(*) as cot from dindanjd where id='" + strOderNumber + "'";
  2579. myset.Open(CRecordset::forwardOnly, sql);
  2580. myset.GetFieldValue("cot", sql);
  2581. myset.Close();
  2582. count2 = atoi(sql);
  2583. }
  2584. if (count1 > count2)//10
  2585. pRetArray->Add("0");
  2586. else
  2587. pRetArray->Add("1");
  2588. {
  2589. CRecordset myset(pBeConverted_db);
  2590. sql = "select count(*) as cot from dindansp2 where id='" + strOderNumber + "'";
  2591. myset.Open(CRecordset::forwardOnly, sql);
  2592. myset.GetFieldValue("cot", sql);
  2593. myset.Close();
  2594. count1 = atoi(sql);
  2595. }
  2596. {
  2597. CRecordset myset(pToConverted_db);
  2598. sql = "select count(*) as cot from dindansp2 where id='" + strOderNumber + "'";
  2599. myset.Open(CRecordset::forwardOnly, sql);
  2600. myset.GetFieldValue("cot", sql);
  2601. myset.Close();
  2602. count2 = atoi(sql);
  2603. }
  2604. if (count1 > count2)
  2605. pRetArray->Add("0");
  2606. else
  2607. pRetArray->Add("1");
  2608. {
  2609. CRecordset myset(pBeConverted_db);
  2610. sql = "select count(*) as cot from dindansp3 where id='" + strOderNumber + "'";
  2611. myset.Open(CRecordset::forwardOnly, sql);
  2612. myset.GetFieldValue("cot", sql);
  2613. myset.Close();
  2614. count1 = atoi(sql);
  2615. }
  2616. {
  2617. CRecordset myset(pToConverted_db);
  2618. sql = "select count(*) as cot from dindansp3 where id='" + strOderNumber + "'";
  2619. myset.Open(CRecordset::forwardOnly, sql);
  2620. myset.GetFieldValue("cot", sql);
  2621. myset.Close();
  2622. count2 = atoi(sql);
  2623. }
  2624. if (count1 > count2)
  2625. pRetArray->Add("0");
  2626. else
  2627. pRetArray->Add("1");
  2628. for (int i = 0; i < pRetArray->GetSize(); i++)
  2629. {
  2630. if (pRetArray->ElementAt(i) == "0")return 100 + i;
  2631. }
  2632. return 1;
  2633. }
  2634. catch (CDBException * e)
  2635. {
  2636. WriteTextLog(e->m_strError);
  2637. WriteTextLog("出错在函数check1中");
  2638. #ifdef _DEBUG
  2639. e->ReportError();
  2640. #endif
  2641. e->Delete();
  2642. }
  2643. return 100;
  2644. }
  2645. BOOL CDBServerDlg::CheckPayOutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  2646. {
  2647. try
  2648. {
  2649. int count1 = 0;
  2650. int count2 = 0;
  2651. CString sql;
  2652. {
  2653. CRecordset myset(pdb1);
  2654. sql.Format("select count(*) as cot from gudingfeiyong where [id]=%d", atol(id));
  2655. myset.Open(CRecordset::forwardOnly, sql);
  2656. myset.GetFieldValue("cot", sql);
  2657. myset.Close();
  2658. count1 = atoi(sql);
  2659. }
  2660. {
  2661. CRecordset myset(pdb2);
  2662. sql = "select count(*) as cot from gudingfeiyong where [id]='" + id + "'";
  2663. myset.Open(CRecordset::forwardOnly, sql);
  2664. myset.GetFieldValue("cot", sql);
  2665. myset.Close();
  2666. count2 = atoi(sql);
  2667. }
  2668. if (count1 > count2)return 0;
  2669. return 1;
  2670. }
  2671. catch (...)
  2672. {
  2673. WriteTextLog("出错在函数check2中");
  2674. }
  2675. return 0;
  2676. }
  2677. BOOL CDBServerDlg::CheckIncomeExist(CDatabase *pdb1, CDatabase *pdb2, CString id, CStringArray *pretarray)
  2678. {
  2679. try
  2680. {
  2681. pretarray->RemoveAll();
  2682. int count1 = 0;
  2683. int count2 = 0;
  2684. CString sql;
  2685. {
  2686. CRecordset myset(pdb1);
  2687. sql.Format("select count(*) as cot from singleincome where [id]=%d", atol(id));
  2688. myset.Open(CRecordset::forwardOnly, sql);
  2689. myset.GetFieldValue("cot", sql);
  2690. myset.Close();
  2691. count1 = atoi(sql);
  2692. }
  2693. {
  2694. CRecordset myset(pdb2);
  2695. sql = "select count(*) as cot from singleincome where [id]='" + id + "'";
  2696. myset.Open(CRecordset::forwardOnly, sql);
  2697. myset.GetFieldValue("cot", sql);
  2698. myset.Close();
  2699. count2 = atoi(sql);
  2700. }
  2701. if (count1 > count2)
  2702. pretarray->Add("0");
  2703. else
  2704. pretarray->Add("1");
  2705. {
  2706. CRecordset myset(pdb1);
  2707. sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id);
  2708. myset.Open(CRecordset::forwardOnly, sql);
  2709. myset.GetFieldValue("cot", sql);
  2710. myset.Close();
  2711. count1 = atoi(sql);
  2712. }
  2713. {
  2714. CRecordset myset(pdb2);
  2715. sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id);
  2716. myset.Open(CRecordset::forwardOnly, sql);
  2717. myset.GetFieldValue("cot", sql);
  2718. myset.Close();
  2719. count2 = atoi(sql);
  2720. }
  2721. if (count1 > count2)
  2722. pretarray->Add("0");
  2723. else
  2724. pretarray->Add("1");
  2725. for (int i = 0; i < pretarray->GetSize(); i++)
  2726. {
  2727. if (pretarray->ElementAt(i) == "0")return 0;
  2728. }
  2729. return 1;
  2730. }
  2731. catch (...)
  2732. {
  2733. WriteTextLog("出错在函数check3中");
  2734. }
  2735. return 0;
  2736. }
  2737. BOOL CDBServerDlg::CheckIncomeMoneyExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  2738. {
  2739. try
  2740. {
  2741. int count1 = 0;
  2742. int count2 = 0;
  2743. CString sql;
  2744. {
  2745. CRecordset myset(pdb1);
  2746. sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id);
  2747. myset.Open(CRecordset::forwardOnly, sql);
  2748. myset.GetFieldValue("cot", sql);
  2749. myset.Close();
  2750. count1 = atoi(sql);
  2751. }
  2752. {
  2753. CRecordset myset(pdb2);
  2754. sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id);
  2755. myset.Open(CRecordset::forwardOnly, sql);
  2756. myset.GetFieldValue("cot", sql);
  2757. myset.Close();
  2758. count2 = atoi(sql);
  2759. }
  2760. if (count1 > count2)return 0;
  2761. return 1;
  2762. }
  2763. catch (...)
  2764. {
  2765. WriteTextLog("出错在函数check3中");
  2766. }
  2767. return 0;
  2768. }
  2769. /************************************************************************/
  2770. /* mark by Jeff
  2771. /* 函数:TransDinDan
  2772. /* 描述:
  2773. /* 参数:
  2774. /* pBeConverted_db:被转换的数据库(源);
  2775. /* pToConverted_db:要转到的数据库(目标);
  2776. /* strOrderNumber: 订单号;
  2777. /* nYear: 要转换的年份;
  2778. /*
  2779. /* 返回:
  2780. /************************************************************************/
  2781. int CDBServerDlg::TransDinDan(CDatabase *pBeConverted_db, CDatabase *pToConverted_db, CString strOrderNumber, int nYear)
  2782. {
  2783. int step = 0;
  2784. CStringArray retarray;
  2785. try
  2786. {
  2787. CString sql, str;
  2788. // CheckDinDanExist返回:1表示正常, 100及以上表示源数据库里记录 > 目标数据库记录;
  2789. if (CheckDinDanExist(pBeConverted_db, pToConverted_db, strOrderNumber, &retarray) == 1)
  2790. return 1;
  2791. step = 1;
  2792. int i;
  2793. CString temp;
  2794. int colcount;
  2795. CODBCFieldInfo fieldinfo;
  2796. int ret = 1;
  2797. // 以下全是insert into 到目录数据库中;
  2798. CRecordset myset(pBeConverted_db);
  2799. try
  2800. {
  2801. if (retarray.ElementAt(0) == "0")
  2802. {
  2803. sql.Format("insert into [%d].[dbo].[dindan] select * from [%s].[dbo].[dindan] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2804. MyExecuteSQL(pBeConverted_db, sql);
  2805. }
  2806. }
  2807. catch (CDBException * e)
  2808. {
  2809. WriteTextLog("step2" + e->m_strError);
  2810. #ifdef _DEBUG
  2811. e->ReportError();
  2812. #endif
  2813. e->Delete();
  2814. ret = 2;
  2815. }
  2816. step = 2;
  2817. try
  2818. {
  2819. if (retarray.ElementAt(1) == "0")
  2820. {
  2821. sql.Format("insert into [%d].[dbo].[dindansp] select * from [%s].[dbo].[dindansp] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2822. MyExecuteSQL(pBeConverted_db, sql);
  2823. }
  2824. }
  2825. catch (CDBException * e)
  2826. {
  2827. WriteTextLog("step3" + e->m_strError);
  2828. #ifdef _DEBUG
  2829. e->ReportError();
  2830. #endif
  2831. e->Delete();
  2832. ret = 3;
  2833. }
  2834. step = 3;
  2835. try
  2836. {
  2837. if (retarray.ElementAt(2) == "0")
  2838. {
  2839. 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);
  2840. MyExecuteSQL(pBeConverted_db, sql);
  2841. }
  2842. }
  2843. catch (CDBException * e)
  2844. {
  2845. WriteTextLog("step4" + e->m_strError);
  2846. #ifdef _DEBUG
  2847. e->ReportError();
  2848. #endif
  2849. e->Delete();
  2850. ret = 4;
  2851. }
  2852. step = 4;
  2853. try
  2854. {
  2855. if (retarray.ElementAt(3) == "0")
  2856. {
  2857. 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);
  2858. MyExecuteSQL(pBeConverted_db, sql);
  2859. }
  2860. }
  2861. catch (CDBException * e)
  2862. {
  2863. WriteTextLog("step5" + e->m_strError);
  2864. #ifdef _DEBUG
  2865. e->ReportError();
  2866. #endif
  2867. e->Delete();
  2868. ret = 5;
  2869. }
  2870. step = 5;
  2871. try
  2872. {
  2873. if (retarray.ElementAt(4) == "0")
  2874. {
  2875. sql.Format("insert into [%d].[dbo].[photoprint] select * from [%s].[dbo].[photoprint] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2876. MyExecuteSQL(pBeConverted_db, sql);
  2877. }
  2878. }
  2879. catch (CDBException * e)
  2880. {
  2881. WriteTextLog("step6" + e->m_strError);
  2882. #ifdef _DEBUG
  2883. e->ReportError();
  2884. #endif
  2885. e->Delete();
  2886. ret = 6;
  2887. }
  2888. step = 6;
  2889. try
  2890. {
  2891. if (retarray.ElementAt(5) == "0")
  2892. {
  2893. sql.Format("insert into [%d].[dbo].[client] select * from [%s].[dbo].[client] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2894. MyExecuteSQL(pBeConverted_db, sql);
  2895. }
  2896. }
  2897. catch (CDBException * e)
  2898. {
  2899. WriteTextLog("step7" + e->m_strError);
  2900. #ifdef _DEBUG
  2901. e->ReportError();
  2902. #endif
  2903. e->Delete();
  2904. ret = 7;
  2905. }
  2906. step = 7;
  2907. try
  2908. {
  2909. if (retarray.ElementAt(6) == "0")
  2910. {
  2911. sql.Format("insert into [%d].[dbo].[burncdreg] select * from [%s].[dbo].[burncdreg] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2912. MyExecuteSQL(pBeConverted_db, sql);
  2913. }
  2914. }
  2915. catch (CDBException * e)
  2916. {
  2917. WriteTextLog("step8" + e->m_strError);
  2918. #ifdef _DEBUG
  2919. e->ReportError();
  2920. #endif
  2921. e->Delete();
  2922. ret = 8;
  2923. }
  2924. step = 8;
  2925. try
  2926. {
  2927. if (retarray.ElementAt(7) == "0")
  2928. {
  2929. sql.Format("insert into [%d].[dbo].[digitalwork] select * from [%s].[dbo].[digitalwork] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2930. MyExecuteSQL(pBeConverted_db, sql);
  2931. }
  2932. }
  2933. catch (CDBException * e)
  2934. {
  2935. WriteTextLog("step9" + e->m_strError);
  2936. #ifdef _DEBUG
  2937. e->ReportError();
  2938. #endif
  2939. e->Delete();
  2940. ret = 9;
  2941. }
  2942. step = 9;
  2943. try
  2944. {
  2945. if (retarray.ElementAt(8) == "0")
  2946. {
  2947. sql.Format("insert into [%d].[dbo].[mywork] select * from [%s].[dbo].[mywork] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2948. MyExecuteSQL(pBeConverted_db, sql);
  2949. }
  2950. }
  2951. catch (CDBException * e)
  2952. {
  2953. WriteTextLog("step10" + e->m_strError);
  2954. #ifdef _DEBUG
  2955. e->ReportError();
  2956. #endif
  2957. e->Delete();
  2958. ret = 10;
  2959. }
  2960. step = 10;
  2961. try
  2962. {
  2963. if (retarray.ElementAt(9) == "0")
  2964. {
  2965. sql.Format("insert into [%d].[dbo].[dindanjd] select * from [%s].[dbo].[dindanjd] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2966. MyExecuteSQL(pBeConverted_db, sql);
  2967. }
  2968. }
  2969. catch (CDBException * e)
  2970. {
  2971. WriteTextLog("step11" + e->m_strError);
  2972. #ifdef _DEBUG
  2973. e->ReportError();
  2974. #endif
  2975. e->Delete();
  2976. ret = 11;
  2977. }
  2978. step = 11;
  2979. try
  2980. {
  2981. if (retarray.ElementAt(10) == "0")
  2982. {
  2983. sql.Format("insert into [%d].[dbo].[dindansp2] select * from [%s].[dbo].[dindansp2] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2984. MyExecuteSQL(pBeConverted_db, sql);
  2985. }
  2986. }
  2987. catch (CDBException * e)
  2988. {
  2989. WriteTextLog("step12" + e->m_strError);
  2990. #ifdef _DEBUG
  2991. e->ReportError();
  2992. #endif
  2993. e->Delete();
  2994. ret = 12;
  2995. }
  2996. step = 12;
  2997. try
  2998. {
  2999. if (retarray.ElementAt(11) == "0")
  3000. {
  3001. sql.Format("insert into [%d].[dbo].[dindansp3] select * from [%s].[dbo].[dindansp3] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  3002. MyExecuteSQL(pBeConverted_db, sql);
  3003. }
  3004. }
  3005. catch (CDBException * e)
  3006. {
  3007. WriteTextLog("step13" + e->m_strError);
  3008. #ifdef _DEBUG
  3009. e->ReportError();
  3010. #endif
  3011. e->Delete();
  3012. ret = 13;
  3013. }
  3014. if (ret != 1)return 200 + ret;
  3015. // 插入到目标数据库后再到目标数据库里查询是否存在;
  3016. return CheckDinDanExist(pBeConverted_db, pToConverted_db, strOrderNumber, &retarray);
  3017. }
  3018. catch (...)
  3019. {
  3020. CString str;
  3021. str.Format("%d size:%d", step, retarray.GetSize());
  3022. WriteTextLog("出错在函数trans1中-" + str);
  3023. }
  3024. return 0;
  3025. }
  3026. BOOL CDBServerDlg::TransPayOut(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3027. {
  3028. try
  3029. {
  3030. CString sql;
  3031. if (CheckPayOutExist(pdb1, pdb2, id))return 1;
  3032. int i; CString temp;
  3033. int colcount;
  3034. CODBCFieldInfo fieldinfo;
  3035. BOOL ret = 1;
  3036. CRecordset myset(pdb1);
  3037. try
  3038. {
  3039. sql.Format("insert into [%d].[dbo].[gudingfeiyong] select * from [%s].[dbo].[gudingfeiyong] where id=%d", year, g_nCurConvertDBName, atol(id));
  3040. MyExecuteSQL(pdb1, sql);
  3041. }
  3042. catch (CDBException * e)
  3043. {
  3044. WriteTextLog(e->m_strError);
  3045. #ifdef _DEBUG
  3046. e->ReportError();
  3047. #endif
  3048. e->Delete();
  3049. ret = 0;
  3050. }
  3051. if (ret == 0)return 0;
  3052. return CheckPayOutExist(pdb1, pdb2, id);
  3053. }
  3054. catch (...)
  3055. {
  3056. WriteTextLog("出错在函数trans2中");
  3057. }
  3058. return 0;
  3059. }
  3060. //singleincome
  3061. BOOL CDBServerDlg::TransIncome(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3062. {
  3063. try
  3064. {
  3065. CString sql;
  3066. CStringArray retarray;
  3067. if (CheckIncomeExist(pdb1, pdb2, id, &retarray))return 1;
  3068. int i; CString temp;
  3069. int colcount;
  3070. CODBCFieldInfo fieldinfo;
  3071. BOOL ret = 1;
  3072. CRecordset myset(pdb1);
  3073. try
  3074. {
  3075. if (retarray.ElementAt(0) == "0")
  3076. {
  3077. sql.Format("insert into [%d].[dbo].[singleincome] select * from [%s].[dbo].[singleincome] where id=%d", year, g_nCurConvertDBName, atol(id));
  3078. MyExecuteSQL(pdb1, sql);
  3079. }
  3080. }
  3081. catch (...)
  3082. {
  3083. ret = 0;
  3084. }
  3085. try
  3086. {
  3087. if (retarray.ElementAt(1) == "0")
  3088. {
  3089. sql.Format("insert into [%d].[dbo].[singleincomemoney] select * from [%s].[dbo].[singleincomemoney] where id='%s'", year, g_nCurConvertDBName, id);
  3090. MyExecuteSQL(pdb1, sql);
  3091. }
  3092. }
  3093. catch (CDBException * e)
  3094. {
  3095. WriteTextLog(e->m_strError);
  3096. #ifdef _DEBUG
  3097. e->ReportError();
  3098. #endif
  3099. e->Delete();
  3100. ret = 0;
  3101. }
  3102. if (ret == 0)return 0;
  3103. return CheckIncomeExist(pdb1, pdb2, id, &retarray);
  3104. }
  3105. catch (...)
  3106. {
  3107. WriteTextLog("出错在函数trans3中");
  3108. }
  3109. return 0;
  3110. }
  3111. BOOL CDBServerDlg::TransIncomeMoney(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3112. {
  3113. try
  3114. {
  3115. CString sql;
  3116. if (CheckIncomeMoneyExist(pdb1, pdb2, id))return 1;
  3117. int i; CString temp;
  3118. int colcount;
  3119. CODBCFieldInfo fieldinfo;
  3120. BOOL ret = 1;
  3121. CRecordset myset(pdb1);
  3122. try
  3123. {
  3124. sql.Format("insert into [%d].[dbo].[singleincomemoney] select * from [%s].[dbo].[singleincomemoney] where id='%s'", year, g_nCurConvertDBName, id);
  3125. MyExecuteSQL(pdb1, sql);
  3126. }
  3127. catch (CDBException * e)
  3128. {
  3129. WriteTextLog(e->m_strError);
  3130. #ifdef _DEBUG
  3131. e->ReportError();
  3132. #endif
  3133. e->Delete();
  3134. ret = 0;
  3135. }
  3136. if (ret == 0)return 0;
  3137. return CheckIncomeMoneyExist(pdb1, pdb2, id);
  3138. }
  3139. catch (...)
  3140. {
  3141. WriteTextLog("出错在函数trans3中");
  3142. }
  3143. return 0;
  3144. }
  3145. BOOL CDBServerDlg::Checkclient2phonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3146. {
  3147. try
  3148. {
  3149. int count1 = 0;
  3150. int count2 = 0;
  3151. CString sql;
  3152. {
  3153. CRecordset myset(pdb1);
  3154. sql = "select count(*) as cot from client2phonerecord where [datetime]='" + id + "'";
  3155. myset.Open(CRecordset::forwardOnly, sql);
  3156. myset.GetFieldValue("cot", sql);
  3157. myset.Close();
  3158. count1 = atoi(sql);
  3159. }
  3160. {
  3161. CRecordset myset(pdb2);
  3162. sql = "select count(*) as cot from client2phonerecord where [datetime]='" + id + "'";
  3163. myset.Open(CRecordset::forwardOnly, sql);
  3164. myset.GetFieldValue("cot", sql);
  3165. myset.Close();
  3166. count2 = atoi(sql);
  3167. }
  3168. if (count1 > count2)return 0;
  3169. return 1;
  3170. }
  3171. catch (...)
  3172. {
  3173. WriteTextLog("出错在函数check3中");
  3174. }
  3175. return 0;
  3176. }
  3177. BOOL CDBServerDlg::Transclient2phonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3178. {
  3179. try
  3180. {
  3181. CString sql;
  3182. if (Checkclient2phonerecordExist(pdb1, pdb2, id))return 1;
  3183. int i; CString temp;
  3184. int colcount;
  3185. CODBCFieldInfo fieldinfo;
  3186. BOOL ret = 1;
  3187. CRecordset myset(pdb1);
  3188. try
  3189. {
  3190. sql.Format("insert into [%d].[dbo].[client2phonerecord] select * from [%s].[dbo].[client2phonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3191. MyExecuteSQL(pdb1, sql);
  3192. }
  3193. catch (...)
  3194. {
  3195. ret = 0;
  3196. }
  3197. if (ret == 0)return 0;
  3198. return Checkclient2phonerecordExist(pdb1, pdb2, id);
  3199. }
  3200. catch (...)
  3201. {
  3202. WriteTextLog("出错在函数trans3中");
  3203. }
  3204. return 0;
  3205. }
  3206. BOOL CDBServerDlg::Checkclient3phonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3207. {
  3208. try
  3209. {
  3210. int count1 = 0;
  3211. int count2 = 0;
  3212. CString sql;
  3213. {
  3214. CRecordset myset(pdb1);
  3215. sql = "select count(*) as cot from client3phonerecord where [datetime]='" + id + "'";
  3216. myset.Open(CRecordset::forwardOnly, sql);
  3217. myset.GetFieldValue("cot", sql);
  3218. myset.Close();
  3219. count1 = atoi(sql);
  3220. }
  3221. {
  3222. CRecordset myset(pdb2);
  3223. sql = "select count(*) as cot from client3phonerecord where [datetime]='" + id + "'";
  3224. myset.Open(CRecordset::forwardOnly, sql);
  3225. myset.GetFieldValue("cot", sql);
  3226. myset.Close();
  3227. count2 = atoi(sql);
  3228. }
  3229. if (count1 > count2)return 0;
  3230. return 1;
  3231. }
  3232. catch (...)
  3233. {
  3234. WriteTextLog("出错在函数check3中");
  3235. }
  3236. return 0;
  3237. }
  3238. BOOL CDBServerDlg::Transclient3phonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3239. {
  3240. try
  3241. {
  3242. CString sql;
  3243. if (Checkclient3phonerecordExist(pdb1, pdb2, id))return 1;
  3244. int i; CString temp;
  3245. int colcount;
  3246. CODBCFieldInfo fieldinfo;
  3247. BOOL ret = 1;
  3248. CRecordset myset(pdb1);
  3249. try
  3250. {
  3251. sql.Format("insert into [%d].[dbo].[client3phonerecord] select * from [%s].[dbo].[client3phonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3252. MyExecuteSQL(pdb1, sql);
  3253. }
  3254. catch (...)
  3255. {
  3256. ret = 0;
  3257. }
  3258. if (ret == 0)return 0;
  3259. return Checkclient3phonerecordExist(pdb1, pdb2, id);
  3260. }
  3261. catch (...)
  3262. {
  3263. WriteTextLog("出错在函数trans3中");
  3264. }
  3265. return 0;
  3266. }
  3267. BOOL CDBServerDlg::Checkclient2phonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3268. {
  3269. try
  3270. {
  3271. int count1 = 0;
  3272. int count2 = 0;
  3273. CString sql;
  3274. {
  3275. CRecordset myset(pdb1);
  3276. sql = "select count(*) as cot from client2phonerecordout where [datetime]='" + id + "'";
  3277. myset.Open(CRecordset::forwardOnly, sql);
  3278. myset.GetFieldValue("cot", sql);
  3279. myset.Close();
  3280. count1 = atoi(sql);
  3281. }
  3282. {
  3283. CRecordset myset(pdb2);
  3284. sql = "select count(*) as cot from client2phonerecordout where [datetime]='" + id + "'";
  3285. myset.Open(CRecordset::forwardOnly, sql);
  3286. myset.GetFieldValue("cot", sql);
  3287. myset.Close();
  3288. count2 = atoi(sql);
  3289. }
  3290. if (count1 > count2)return 0;
  3291. return 1;
  3292. }
  3293. catch (...)
  3294. {
  3295. WriteTextLog("出错在函数check3中");
  3296. }
  3297. return 0;
  3298. }
  3299. BOOL CDBServerDlg::Transclient2phonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3300. {
  3301. try
  3302. {
  3303. CString sql;
  3304. if (Checkclient2phonerecordoutExist(pdb1, pdb2, id))return 1;
  3305. int i; CString temp;
  3306. int colcount;
  3307. CODBCFieldInfo fieldinfo;
  3308. BOOL ret = 1;
  3309. CRecordset myset(pdb1);
  3310. try
  3311. {
  3312. sql.Format("insert into [%d].[dbo].[client2phonerecordout] select * from [%s].[dbo].[client2phonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3313. MyExecuteSQL(pdb1, sql);
  3314. }
  3315. catch (...)
  3316. {
  3317. ret = 0;
  3318. }
  3319. if (ret == 0)return 0;
  3320. return Checkclient2phonerecordoutExist(pdb1, pdb2, id);
  3321. }
  3322. catch (...)
  3323. {
  3324. WriteTextLog("出错在函数trans3中");
  3325. }
  3326. return 0;
  3327. }
  3328. BOOL CDBServerDlg::Checkclient3phonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3329. {
  3330. try
  3331. {
  3332. int count1 = 0;
  3333. int count2 = 0;
  3334. CString sql;
  3335. {
  3336. CRecordset myset(pdb1);
  3337. sql = "select count(*) as cot from client3phonerecordout where [datetime]='" + id + "'";
  3338. myset.Open(CRecordset::forwardOnly, sql);
  3339. myset.GetFieldValue("cot", sql);
  3340. myset.Close();
  3341. count1 = atoi(sql);
  3342. }
  3343. {
  3344. CRecordset myset(pdb2);
  3345. sql = "select count(*) as cot from client3phonerecordout where [datetime]='" + id + "'";
  3346. myset.Open(CRecordset::forwardOnly, sql);
  3347. myset.GetFieldValue("cot", sql);
  3348. myset.Close();
  3349. count2 = atoi(sql);
  3350. }
  3351. if (count1 > count2)return 0;
  3352. return 1;
  3353. }
  3354. catch (...)
  3355. {
  3356. WriteTextLog("出错在函数check3中");
  3357. }
  3358. return 0;
  3359. }
  3360. BOOL CDBServerDlg::Transclient3phonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3361. {
  3362. try
  3363. {
  3364. CString sql;
  3365. if (Checkclient3phonerecordoutExist(pdb1, pdb2, id))return 1;
  3366. int i; CString temp;
  3367. int colcount;
  3368. CODBCFieldInfo fieldinfo;
  3369. BOOL ret = 1;
  3370. CRecordset myset(pdb1);
  3371. try
  3372. {
  3373. sql.Format("insert into [%d].[dbo].[client3phonerecordout] select * from [%s].[dbo].[client3phonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3374. MyExecuteSQL(pdb1, sql);
  3375. }
  3376. catch (...)
  3377. {
  3378. ret = 0;
  3379. }
  3380. if (ret == 0)return 0;
  3381. return Checkclient3phonerecordoutExist(pdb1, pdb2, id);
  3382. }
  3383. catch (...)
  3384. {
  3385. WriteTextLog("出错在函数trans3中");
  3386. }
  3387. return 0;
  3388. }
  3389. BOOL CDBServerDlg::CheckemployeephonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3390. {
  3391. try
  3392. {
  3393. int count1 = 0;
  3394. int count2 = 0;
  3395. CString sql;
  3396. {
  3397. CRecordset myset(pdb1);
  3398. sql = "select count(*) as cot from employeephonerecord where [datetime]='" + id + "'";
  3399. myset.Open(CRecordset::forwardOnly, sql);
  3400. myset.GetFieldValue("cot", sql);
  3401. myset.Close();
  3402. count1 = atoi(sql);
  3403. }
  3404. {
  3405. CRecordset myset(pdb2);
  3406. sql = "select count(*) as cot from employeephonerecord where [datetime]='" + id + "'";
  3407. myset.Open(CRecordset::forwardOnly, sql);
  3408. myset.GetFieldValue("cot", sql);
  3409. myset.Close();
  3410. count2 = atoi(sql);
  3411. }
  3412. if (count1 > count2)return 0;
  3413. return 1;
  3414. }
  3415. catch (...)
  3416. {
  3417. WriteTextLog("出错在函数check3中");
  3418. }
  3419. return 0;
  3420. }
  3421. BOOL CDBServerDlg::Transemployeephonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3422. {
  3423. try
  3424. {
  3425. CString sql;
  3426. if (CheckemployeephonerecordExist(pdb1, pdb2, id))return 1;
  3427. int i; CString temp;
  3428. int colcount;
  3429. CODBCFieldInfo fieldinfo;
  3430. BOOL ret = 1;
  3431. CRecordset myset(pdb1);
  3432. try
  3433. {
  3434. sql.Format("insert into [%d].[dbo].[employeephonerecord] select * from [%s].[dbo].[employeephonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3435. MyExecuteSQL(pdb1, sql);
  3436. }
  3437. catch (...)
  3438. {
  3439. ret = 0;
  3440. }
  3441. if (ret == 0)return 0;
  3442. return CheckemployeephonerecordExist(pdb1, pdb2, id);
  3443. }
  3444. catch (...)
  3445. {
  3446. WriteTextLog("出错在函数trans3中");
  3447. }
  3448. return 0;
  3449. }
  3450. BOOL CDBServerDlg::CheckemployeephonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3451. {
  3452. try
  3453. {
  3454. int count1 = 0;
  3455. int count2 = 0;
  3456. CString sql;
  3457. {
  3458. CRecordset myset(pdb1);
  3459. sql = "select count(*) as cot from employeephonerecordout where [datetime]='" + id + "'";
  3460. myset.Open(CRecordset::forwardOnly, sql);
  3461. myset.GetFieldValue("cot", sql);
  3462. myset.Close();
  3463. count1 = atoi(sql);
  3464. }
  3465. {
  3466. CRecordset myset(pdb2);
  3467. sql = "select count(*) as cot from employeephonerecordout where [datetime]='" + id + "'";
  3468. myset.Open(CRecordset::forwardOnly, sql);
  3469. myset.GetFieldValue("cot", sql);
  3470. myset.Close();
  3471. count2 = atoi(sql);
  3472. }
  3473. if (count1 > count2)return 0;
  3474. return 1;
  3475. }
  3476. catch (...)
  3477. {
  3478. WriteTextLog("出错在函数check3中");
  3479. }
  3480. return 0;
  3481. }
  3482. BOOL CDBServerDlg::Transemployeephonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3483. {
  3484. try
  3485. {
  3486. CString sql;
  3487. if (CheckemployeephonerecordoutExist(pdb1, pdb2, id))return 1;
  3488. int i; CString temp;
  3489. int colcount;
  3490. CODBCFieldInfo fieldinfo;
  3491. BOOL ret = 1;
  3492. CRecordset myset(pdb1);
  3493. try
  3494. {
  3495. sql.Format("insert into [%d].[dbo].[employeephonerecordout] select * from [%s].[dbo].[employeephonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3496. MyExecuteSQL(pdb1, sql);
  3497. }
  3498. catch (...)
  3499. {
  3500. ret = 0;
  3501. }
  3502. if (ret == 0)return 0;
  3503. return CheckemployeephonerecordoutExist(pdb1, pdb2, id);
  3504. }
  3505. catch (...)
  3506. {
  3507. WriteTextLog("出错在函数trans3中");
  3508. }
  3509. return 0;
  3510. }
  3511. BOOL CDBServerDlg::CheckphonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3512. {
  3513. try
  3514. {
  3515. int count1 = 0;
  3516. int count2 = 0;
  3517. CString sql;
  3518. {
  3519. CRecordset myset(pdb1);
  3520. sql = "select count(*) as cot from phonerecord where [datetime]='" + id + "'";
  3521. myset.Open(CRecordset::forwardOnly, sql);
  3522. myset.GetFieldValue("cot", sql);
  3523. myset.Close();
  3524. count1 = atoi(sql);
  3525. }
  3526. {
  3527. CRecordset myset(pdb2);
  3528. sql = "select count(*) as cot from phonerecord where [datetime]='" + id + "'";
  3529. myset.Open(CRecordset::forwardOnly, sql);
  3530. myset.GetFieldValue("cot", sql);
  3531. myset.Close();
  3532. count2 = atoi(sql);
  3533. }
  3534. if (count1 > count2)return 0;
  3535. return 1;
  3536. }
  3537. catch (...)
  3538. {
  3539. WriteTextLog("出错在函数check3中");
  3540. }
  3541. return 0;
  3542. }
  3543. BOOL CDBServerDlg::Transphonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3544. {
  3545. try
  3546. {
  3547. CString sql;
  3548. if (CheckphonerecordExist(pdb1, pdb2, id))return 1;
  3549. int i; CString temp;
  3550. int colcount;
  3551. CODBCFieldInfo fieldinfo;
  3552. BOOL ret = 1;
  3553. CRecordset myset(pdb1);
  3554. try
  3555. {
  3556. sql.Format("insert into [%d].[dbo].[phonerecord] select * from [%s].[dbo].[phonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3557. MyExecuteSQL(pdb1, sql);
  3558. }
  3559. catch (...)
  3560. {
  3561. ret = 0;
  3562. }
  3563. if (ret == 0)return 0;
  3564. return CheckphonerecordExist(pdb1, pdb2, id);
  3565. }
  3566. catch (...)
  3567. {
  3568. WriteTextLog("出错在函数trans3中");
  3569. }
  3570. return 0;
  3571. }
  3572. BOOL CDBServerDlg::CheckphonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3573. {
  3574. try
  3575. {
  3576. int count1 = 0;
  3577. int count2 = 0;
  3578. CString sql;
  3579. {
  3580. CRecordset myset(pdb1);
  3581. sql = "select count(*) as cot from phonerecordout where [datetime]='" + id + "'";
  3582. myset.Open(CRecordset::forwardOnly, sql);
  3583. myset.GetFieldValue("cot", sql);
  3584. myset.Close();
  3585. count1 = atoi(sql);
  3586. }
  3587. {
  3588. CRecordset myset(pdb2);
  3589. sql = "select count(*) as cot from phonerecordout where [datetime]='" + id + "'";
  3590. myset.Open(CRecordset::forwardOnly, sql);
  3591. myset.GetFieldValue("cot", sql);
  3592. myset.Close();
  3593. count2 = atoi(sql);
  3594. }
  3595. if (count1 > count2)return 0;
  3596. return 1;
  3597. }
  3598. catch (...)
  3599. {
  3600. WriteTextLog("出错在函数check3中");
  3601. }
  3602. return 0;
  3603. }
  3604. BOOL CDBServerDlg::Transphonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3605. {
  3606. try
  3607. {
  3608. CString sql;
  3609. if (CheckphonerecordoutExist(pdb1, pdb2, id))return 1;
  3610. int i; CString temp;
  3611. int colcount;
  3612. CODBCFieldInfo fieldinfo;
  3613. BOOL ret = 1;
  3614. CRecordset myset(pdb1);
  3615. try
  3616. {
  3617. sql.Format("insert into [%d].[dbo].[phonerecordout] select * from [%s].[dbo].[phonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3618. MyExecuteSQL(pdb1, sql);
  3619. }
  3620. catch (...)
  3621. {
  3622. ret = 0;
  3623. }
  3624. if (ret == 0)return 0;
  3625. return CheckphonerecordoutExist(pdb1, pdb2, id);
  3626. }
  3627. catch (...)
  3628. {
  3629. WriteTextLog("出错在函数trans3中");
  3630. }
  3631. return 0;
  3632. }
  3633. BOOL CDBServerDlg::CheckunknownphonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3634. {
  3635. try
  3636. {
  3637. int count1 = 0;
  3638. int count2 = 0;
  3639. CString sql;
  3640. {
  3641. CRecordset myset(pdb1);
  3642. sql = "select count(*) as cot from unknownphonerecord where [datetime]='" + id + "'";
  3643. myset.Open(CRecordset::forwardOnly, sql);
  3644. myset.GetFieldValue("cot", sql);
  3645. myset.Close();
  3646. count1 = atoi(sql);
  3647. }
  3648. {
  3649. CRecordset myset(pdb2);
  3650. sql = "select count(*) as cot from unknownphonerecord where [datetime]='" + id + "'";
  3651. myset.Open(CRecordset::forwardOnly, sql);
  3652. myset.GetFieldValue("cot", sql);
  3653. myset.Close();
  3654. count2 = atoi(sql);
  3655. }
  3656. if (count1 > count2)return 0;
  3657. return 1;
  3658. }
  3659. catch (...)
  3660. {
  3661. WriteTextLog("出错在函数check3中");
  3662. }
  3663. return 0;
  3664. }
  3665. BOOL CDBServerDlg::Transunknownphonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3666. {
  3667. try
  3668. {
  3669. CString sql;
  3670. if (CheckunknownphonerecordExist(pdb1, pdb2, id))return 1;
  3671. int i; CString temp;
  3672. int colcount;
  3673. CODBCFieldInfo fieldinfo;
  3674. BOOL ret = 1;
  3675. CRecordset myset(pdb1);
  3676. try
  3677. {
  3678. sql.Format("insert into [%d].[dbo].[unknownphonerecord] select * from [%s].[dbo].[unknownphonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3679. MyExecuteSQL(pdb1, sql);
  3680. }
  3681. catch (...)
  3682. {
  3683. ret = 0;
  3684. }
  3685. if (ret == 0)return 0;
  3686. return CheckunknownphonerecordExist(pdb1, pdb2, id);
  3687. }
  3688. catch (...)
  3689. {
  3690. WriteTextLog("出错在函数trans3中");
  3691. }
  3692. return 0;
  3693. }
  3694. BOOL CDBServerDlg::CheckunknownphonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3695. {
  3696. try
  3697. {
  3698. int count1 = 0;
  3699. int count2 = 0;
  3700. CString sql;
  3701. {
  3702. CRecordset myset(pdb1);
  3703. sql = "select count(*) as cot from unknownphonerecordout where [datetime]='" + id + "'";
  3704. myset.Open(CRecordset::forwardOnly, sql);
  3705. myset.GetFieldValue("cot", sql);
  3706. myset.Close();
  3707. count1 = atoi(sql);
  3708. }
  3709. {
  3710. CRecordset myset(pdb2);
  3711. sql = "select count(*) as cot from unknownphonerecordout where [datetime]='" + id + "'";
  3712. myset.Open(CRecordset::forwardOnly, sql);
  3713. myset.GetFieldValue("cot", sql);
  3714. myset.Close();
  3715. count2 = atoi(sql);
  3716. }
  3717. if (count1 > count2)return 0;
  3718. return 1;
  3719. }
  3720. catch (...)
  3721. {
  3722. WriteTextLog("出错在函数check3中");
  3723. }
  3724. return 0;
  3725. }
  3726. BOOL CDBServerDlg::Transunknownphonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3727. {
  3728. try
  3729. {
  3730. CString sql;
  3731. if (CheckunknownphonerecordoutExist(pdb1, pdb2, id))return 1;
  3732. int i; CString temp;
  3733. int colcount;
  3734. CODBCFieldInfo fieldinfo;
  3735. BOOL ret = 1;
  3736. CRecordset myset(pdb1);
  3737. try
  3738. {
  3739. sql.Format("insert into [%d].[dbo].[unknownphonerecordout] select * from [%s].[dbo].[unknownphonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3740. MyExecuteSQL(pdb1, sql);
  3741. }
  3742. catch (...)
  3743. {
  3744. ret = 0;
  3745. }
  3746. if (ret == 0)return 0;
  3747. return CheckunknownphonerecordoutExist(pdb1, pdb2, id);
  3748. }
  3749. catch (...)
  3750. {
  3751. WriteTextLog("出错在函数trans3中");
  3752. }
  3753. return 0;
  3754. }
  3755. BOOL CDBServerDlg::CheckmisscallrecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3756. {
  3757. try
  3758. {
  3759. int count1 = 0;
  3760. int count2 = 0;
  3761. CString sql;
  3762. {
  3763. CRecordset myset(pdb1);
  3764. sql = "select count(*) as cot from misscallrecord where [datetime]='" + id + "'";
  3765. myset.Open(CRecordset::forwardOnly, sql);
  3766. myset.GetFieldValue("cot", sql);
  3767. myset.Close();
  3768. count1 = atoi(sql);
  3769. }
  3770. {
  3771. CRecordset myset(pdb2);
  3772. sql = "select count(*) as cot from misscallrecord where [datetime]='" + id + "'";
  3773. myset.Open(CRecordset::forwardOnly, sql);
  3774. myset.GetFieldValue("cot", sql);
  3775. myset.Close();
  3776. count2 = atoi(sql);
  3777. }
  3778. if (count1 > count2)return 0;
  3779. return 1;
  3780. }
  3781. catch (...)
  3782. {
  3783. WriteTextLog("出错在函数check3中");
  3784. }
  3785. return 0;
  3786. }
  3787. BOOL CDBServerDlg::Transmisscallrecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3788. {
  3789. try
  3790. {
  3791. CString sql;
  3792. if (CheckmisscallrecordExist(pdb1, pdb2, id))return 1;
  3793. int i;
  3794. CString temp;
  3795. int colcount;
  3796. CODBCFieldInfo fieldinfo;
  3797. BOOL ret = 1;
  3798. CRecordset myset(pdb1);
  3799. try
  3800. {
  3801. sql.Format("insert into [%d].[dbo].[misscallrecord] select * from [%s].[dbo].[misscallrecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3802. MyExecuteSQL(pdb1, sql);
  3803. }
  3804. catch (...)
  3805. {
  3806. ret = 0;
  3807. }
  3808. if (ret == 0)return 0;
  3809. return CheckmisscallrecordExist(pdb1, pdb2, id);
  3810. }
  3811. catch (...)
  3812. {
  3813. WriteTextLog("出错在函数trans3中");
  3814. }
  3815. return 0;
  3816. }
  3817. BOOL CDBServerDlg::CheckSendReg(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3818. {
  3819. try
  3820. {
  3821. int count1 = 0;
  3822. int count2 = 0;
  3823. CString sql;
  3824. {
  3825. CRecordset myset(pdb1);
  3826. sql.Format("select count(*) as cot from sendreg where [timestamp]='%s'", id);
  3827. myset.Open(CRecordset::forwardOnly, sql);
  3828. myset.GetFieldValue("cot", sql);
  3829. myset.Close();
  3830. count1 = atoi(sql);
  3831. }
  3832. {
  3833. CRecordset myset(pdb2);
  3834. sql.Format("select count(*) as cot from sendreg where [timestamp]='%s'", id);
  3835. myset.Open(CRecordset::forwardOnly, sql);
  3836. myset.GetFieldValue("cot", sql);
  3837. myset.Close();
  3838. count2 = atoi(sql);
  3839. }
  3840. if (count1 > count2)return 0;
  3841. return 1;
  3842. }
  3843. catch (...)
  3844. {
  3845. WriteTextLog("出错在函数check3中");
  3846. }
  3847. return 0;
  3848. }
  3849. BOOL CDBServerDlg::TransSendReg(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3850. {
  3851. try
  3852. {
  3853. CString sql;
  3854. if (CheckSendReg(pdb1, pdb2, id))return 1;
  3855. int i;
  3856. CString temp;
  3857. int colcount;
  3858. CODBCFieldInfo fieldinfo;
  3859. BOOL ret = 1;
  3860. CRecordset myset(pdb1);
  3861. try
  3862. {
  3863. sql.Format("insert into [%d].[dbo].[sendreg] select * from [%s].[dbo].[sendreg] where [timestamp]='%s'", year, g_nCurConvertDBName, id);
  3864. MyExecuteSQL(pdb1, sql);
  3865. }
  3866. catch (...)
  3867. {
  3868. ret = 0;
  3869. }
  3870. if (ret == 0)return 0;
  3871. return CheckSendReg(pdb1, pdb2, id);
  3872. }
  3873. catch (...)
  3874. {
  3875. WriteTextLog("出错在函数trans3中");
  3876. }
  3877. return 0;
  3878. }
  3879. void CDBServerDlg::MyExecuteSQL(CDatabase* pdb, CString sql)
  3880. {
  3881. try
  3882. {
  3883. pdb->ExecuteSQL(sql);
  3884. }
  3885. catch ( CDBException *e)
  3886. {
  3887. WriteTextLog(_T("执行SQL语句出错,系统描述:%s"),e->m_strError);
  3888. #ifdef _DEBUG
  3889. e->ReportError();
  3890. #endif
  3891. e->Delete();
  3892. }
  3893. }
  3894. void CDBServerDlg::MyExecuteSQL(const TCHAR* pfile, const int& nline, const TCHAR* pfunction, CDatabase* pdb, CString sql)
  3895. {
  3896. try
  3897. {
  3898. pdb->ExecuteSQL(sql);
  3899. }
  3900. catch ( CDBException *e)
  3901. {
  3902. WriteTextLog(_T("%s-<%d>-%s,执行SQL语句出错,系统描述:%s"), pfile, nline, pfunction,e->m_strError);
  3903. #ifdef _DEBUG
  3904. e->ReportError();
  3905. #endif
  3906. e->Delete();
  3907. }
  3908. }
  3909. void CDBServerDlg::UpdateDate()
  3910. {
  3911. try
  3912. {
  3913. HWND hwnd = ::FindWindow(NULL, "AutoRun.exe - 应用程序错误");
  3914. if (hwnd)
  3915. {
  3916. HWND child = ::FindWindowEx(hwnd, 0, NULL, "确定");
  3917. CWnd *pWnd = CWnd::FromHandle(child);
  3918. ::PostMessage(hwnd, WM_COMMAND, pWnd->GetDlgCtrlID(), (LPARAM)child);
  3919. }
  3920. CString autorunpath = g_mainpath + "\\AutoRun.exe";
  3921. if (0 == g_bConvertHisAll)
  3922. ShellExecute(NULL, _T("open"), g_mainpath + "\\AutoRun.exe", NULL, NULL, SW_HIDE);
  3923. HANDLE hMutex = ::OpenMutex(NULL, FALSE, _T("lyfzSMSHandle"));
  3924. if (GetLastError() == ERROR_FILE_NOT_FOUND)
  3925. {
  3926. autorunpath = g_mainpath + "\\SMSHandle.exe";
  3927. ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
  3928. }
  3929. if (hMutex) CloseHandle(hMutex);
  3930. #ifdef ENTERPRISE_VERSION
  3931. autorunpath = g_mainpath + "\\DataSyncReceive.exe";
  3932. ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
  3933. autorunpath = g_mainpath + "\\DataSyncSend.exe";
  3934. ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
  3935. autorunpath = g_mainpath + "\\CPhotoFTPReceive.exe";
  3936. ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
  3937. autorunpath = g_mainpath + "\\CPhotoFTPSend.exe";
  3938. ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
  3939. #endif
  3940. }
  3941. catch (...)
  3942. {
  3943. WriteTextLog("出错在函数UpdateDate中");
  3944. }
  3945. }
  3946. BOOL CheckDateOK(CString str)
  3947. {
  3948. try
  3949. {
  3950. CString tip;
  3951. int i;
  3952. CString demo = CTime::GetCurrentTime().Format("%Y-%m-%d");
  3953. if (str.GetLength() != demo.GetLength())
  3954. goto ll;
  3955. //2009-01-01
  3956. if (str.GetAt(4) != '-')
  3957. goto ll;
  3958. if (str.GetAt(7) != '-')
  3959. goto ll;
  3960. for (i = 0; i < str.GetLength(); i++)
  3961. {
  3962. if (i == 4 || i == 7)continue;
  3963. if (str.GetAt(i) < '0' || str.GetAt(i) > '9')
  3964. goto ll;
  3965. }
  3966. }
  3967. catch (...)
  3968. {
  3969. WriteTextLog("出错");
  3970. }
  3971. return 1;
  3972. ll:
  3973. return 0;
  3974. }
  3975. //------------------------------------------------------------------
  3976. // Remark by Jeff:2014.10.11
  3977. // 函数:DelPhoto1
  3978. // 描述:删除指定路径下的订单文件夹;
  3979. // 参数:
  3980. // path: 指定要删除文件的根目录;
  3981. // strOrderNumber: 将要删除的订单号文件夹;
  3982. // 返回:
  3983. //-----------------------------------------------------------------
  3984. BOOL CDBServerDlg::DelPhoto1(CString path, CString strOrderNumber)
  3985. {
  3986. if ( path.IsEmpty() || !PathFileExists(path) )
  3987. {
  3988. //WriteTextLog(_T("路径不存在!"));
  3989. return FALSE;
  3990. }
  3991. path += _T("\\") + strOrderNumber;
  3992. if (PathFileExists(path))
  3993. {
  3994. DeleteDirectory(path);
  3995. return TRUE;
  3996. }
  3997. //WriteTextLog(_T("路径不存在!"));
  3998. return FALSE;
  3999. }
  4000. //-----------------------------------------------------------------------
  4001. // Remark by Jeff 2014.10.22
  4002. // 函数:BakPhoto
  4003. // 描述:对影楼相片进行备份和删除取件相片
  4004. // 参数:#
  4005. // 返回:#
  4006. //
  4007. // 调用关系:
  4008. // 1.BakPhoto()由CDBServerDlg::SetTimer(4) 调用,调用频率2分钟,周期数直到程序结束。
  4009. // 2.CDBServerDlg::SetTimer(4) 由 CDBServerDlg::SetTimer(2) 调用,调用频率10毫秒,只有一个周期。
  4010. // 3.CDBServerDlg::SetTimer(2) 由 CDBServerDlg::OnInitDialog() 调用.
  4011. //-----------------------------------------------------------------------
  4012. void CDBServerDlg::BakPhoto() // Jeff:备份相片/删除取件相片;
  4013. {
  4014. try
  4015. {
  4016. CDatabase *pMaindb = NULL;
  4017. ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
  4018. if ( pMaindb == NULL )
  4019. return;
  4020. CString m_bak1, m_bak2, m_bak3, m_bak4, m_bak6, m_baktime; // Jeff:m_bak6自动备份完毕后自动关机;
  4021. CString m_bakserver1, m_bakserver2, m_bakserver3, m_bakserver4;
  4022. CString msgcheck4, msgtime, msgphones, msgphones2, msgcompanyname;
  4023. CString balance, msgaccount;
  4024. {
  4025. MyLock lock("dbaccessxiao");
  4026. CRstversion rsSt;
  4027. rsSt.m_pDatabase = pMaindb;
  4028. rsSt.Open();
  4029. if (!rsSt.IsEOF())
  4030. {
  4031. m_bak1 = rsSt.m_bak1;
  4032. m_bak2 = rsSt.m_bak2;
  4033. m_bak3 = rsSt.m_bak3;
  4034. m_bak4 = rsSt.m_bak4;
  4035. m_bakserver1 = rsSt.m_bakserver1;
  4036. m_bakserver2 = rsSt.m_bakserver2;
  4037. m_bakserver3 = rsSt.m_bakserver3;
  4038. m_bakserver4 = rsSt.m_bakserver4;
  4039. m_bak6 = rsSt.m_bak6;
  4040. m_baktime = rsSt.m_baktime;
  4041. msgcheck4 = rsSt.msgcheck4;
  4042. msgtime = rsSt.msgtime;
  4043. msgphones = rsSt.msgphones;
  4044. msgphones2 = rsSt.msgphones2;
  4045. msgcompanyname = rsSt.msgcompanyname;
  4046. balance = rsSt.msgbalance;
  4047. msgaccount = rsSt.msgaccount;
  4048. }
  4049. rsSt.Close();
  4050. }
  4051. /////////////检测发短信回财务
  4052. if (msgphones2.IsEmpty() == 0)
  4053. {
  4054. MyLock lock("dbaccessxiao");
  4055. CStringArray array, timearray;
  4056. CString timestamp;
  4057. timestamp = CTime::GetCurrentTime().Format("%Y-%m-%d");
  4058. timestamp += "%";
  4059. CRecordset myset(pMaindb);
  4060. CString sql = "select phones,timestamp from sendregreceive where [timestamp] like '" + timestamp + "' and [content]='001' and [status]='OK'";
  4061. myset.Open(CRecordset::forwardOnly, sql);
  4062. CString phones;
  4063. while (!myset.IsEOF())
  4064. {
  4065. myset.GetFieldValue("phones", phones);
  4066. myset.GetFieldValue("timestamp", timestamp);
  4067. if (msgphones2.Find(phones) != -1)
  4068. {
  4069. array.Add(phones);
  4070. timearray.Add(timestamp);
  4071. }
  4072. myset.MoveNext();
  4073. }
  4074. myset.Close();
  4075. if (array.GetSize())
  4076. {
  4077. CString sql;
  4078. int i = 0;
  4079. //for (int i = 0; i < array.GetSize(); i++)
  4080. for ( i = 0; i < array.GetSize(); i++)
  4081. {
  4082. sql = "update sendregreceive set [status]='' where [timestamp]='" + timearray.ElementAt(i) + "'";
  4083. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  4084. }
  4085. CArray<CStringArray, CStringArray>List11array;
  4086. CArray<CStringArray, CStringArray>List2array;
  4087. CArray<CStringArray, CStringArray>List3array;
  4088. CArray<CStringArray, CStringArray>other2salearray;
  4089. CArray<CStringArray, CStringArray>memberarray;
  4090. CString strdate = CTime::GetCurrentTime().Format("%Y-%m-%d");
  4091. for( int a = g_dbpool.GetSize(); a >= 0 ;a-- )
  4092. {
  4093. CDatabase *pCurdb = NULL;
  4094. ODBCConnGuard ConnGuard1(pCurdb , a - 1, 3000);
  4095. if ( pCurdb == NULL )
  4096. continue;
  4097. CString filter = "[dat]='" + strdate + "'";
  4098. filter = "[dat]='" + strdate + "' and ([sale2type] is null or [sale2type]='')";
  4099. {
  4100. CRecordset myset(pCurdb);
  4101. CString sql = "select count(*) as cot from singleincome"; if (!filter.IsEmpty())sql += " where " + filter;
  4102. myset.Open(CRecordset::forwardOnly, sql);
  4103. myset.GetFieldValue("cot", sql);
  4104. myset.Close();
  4105. int count = atol(sql);
  4106. int oldsize = List2array.GetSize();
  4107. List2array.SetSize(oldsize + count, 1);
  4108. CRstIncomeInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  4109. rsSt.Open();
  4110. int ii = 0;
  4111. while (!rsSt.IsEOF())
  4112. {
  4113. List2array.ElementAt(oldsize + ii).RemoveAll();
  4114. List2array.ElementAt(oldsize + ii).Add(rsSt.id);
  4115. List2array.ElementAt(oldsize + ii).Add(rsSt.name);
  4116. List2array.ElementAt(oldsize + ii).Add(rsSt.money);
  4117. List2array.ElementAt(oldsize + ii).Add(rsSt.date);
  4118. List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
  4119. List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan2);
  4120. List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan3);
  4121. List2array.ElementAt(oldsize + ii).Add(rsSt.bz);
  4122. List2array.ElementAt(oldsize + ii).Add(rsSt.sale2type);
  4123. ii++;
  4124. rsSt.MoveNext(); if (List2array.GetSize() <= ii)break;
  4125. }
  4126. rsSt.Close(); List2array.SetSize(oldsize + ii, 1);
  4127. }
  4128. filter = "[dat]='" + strdate + "'";
  4129. {
  4130. CRecordset myset(pCurdb);
  4131. CString sql = "select count(*) as cot from gudingfeiyong"; if (!filter.IsEmpty())sql += " where " + filter;
  4132. myset.Open(CRecordset::forwardOnly, sql);
  4133. myset.GetFieldValue("cot", sql);
  4134. myset.Close();
  4135. int count = atol(sql);
  4136. int oldsize = List3array.GetSize();
  4137. List3array.SetSize(oldsize + count, 1);
  4138. CRstPayOutInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  4139. rsSt.Open();
  4140. int ii = 0;
  4141. while (!rsSt.IsEOF())
  4142. {
  4143. List3array.ElementAt(oldsize + ii).RemoveAll();
  4144. List3array.ElementAt(oldsize + ii).Add(rsSt.id);
  4145. List3array.ElementAt(oldsize + ii).Add(rsSt.name);
  4146. List3array.ElementAt(oldsize + ii).Add(rsSt.money);
  4147. List3array.ElementAt(oldsize + ii).Add(rsSt.date);
  4148. List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
  4149. List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan2);
  4150. List3array.ElementAt(oldsize + ii).Add(rsSt.bz);
  4151. ii++;
  4152. rsSt.MoveNext(); if (List3array.GetSize() <= ii)break;
  4153. }
  4154. rsSt.Close(); List3array.SetSize(oldsize + ii, 1);
  4155. }
  4156. filter = "[date]='" + strdate + "'";
  4157. {
  4158. CRecordset myset(pCurdb);
  4159. CString sql = "select count(*) as cot from dindanbukuan"; if (!filter.IsEmpty())sql += " where " + filter;
  4160. myset.Open(CRecordset::forwardOnly, sql);
  4161. myset.GetFieldValue("cot", sql);
  4162. myset.Close();
  4163. int count = atol(sql);
  4164. int oldsize = List11array.GetSize();
  4165. List11array.SetSize(oldsize + count, 1);
  4166. CRstBuKuan rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  4167. rsSt.Open();
  4168. int ii = 0;
  4169. while (!rsSt.IsEOF())
  4170. {
  4171. List11array.ElementAt(oldsize + ii).RemoveAll();
  4172. List11array.ElementAt(oldsize + ii).Add(rsSt.m_id);
  4173. List11array.ElementAt(oldsize + ii).Add(rsSt.m_ren);
  4174. List11array.ElementAt(oldsize + ii).Add(rsSt.m_money);
  4175. List11array.ElementAt(oldsize + ii).Add(rsSt.m_bz);
  4176. List11array.ElementAt(oldsize + ii).Add(rsSt.m_kind);
  4177. List11array.ElementAt(oldsize + ii).Add(rsSt.m_date);
  4178. ii++;
  4179. rsSt.MoveNext(); if (List11array.GetSize() <= ii)break;
  4180. }
  4181. rsSt.Close(); List11array.SetSize(oldsize + ii, 1);
  4182. }
  4183. filter = "[date]='" + strdate + "'";
  4184. {
  4185. CRecordset myset(pCurdb);
  4186. CString sql = "select count(*) as cot from singleincomemoneyview"; if (!filter.IsEmpty())sql += " where " + filter;
  4187. myset.Open(CRecordset::forwardOnly, sql);
  4188. myset.GetFieldValue("cot", sql);
  4189. myset.Close();
  4190. int count = atol(sql);
  4191. int oldsize = other2salearray.GetSize();
  4192. other2salearray.SetSize(oldsize + count, 1);
  4193. CRstsingleincomemoneyview rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  4194. rsSt.Open();
  4195. int ii = 0;
  4196. while (!rsSt.IsEOF())
  4197. {
  4198. other2salearray.ElementAt(oldsize + ii).RemoveAll();
  4199. other2salearray.ElementAt(oldsize + ii).Add(rsSt.name);
  4200. other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
  4201. other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan3);
  4202. other2salearray.ElementAt(oldsize + ii).Add(rsSt.sale2type);
  4203. other2salearray.ElementAt(oldsize + ii).Add(rsSt.money);
  4204. other2salearray.ElementAt(oldsize + ii).Add(rsSt.date);
  4205. other2salearray.ElementAt(oldsize + ii).Add(rsSt.clerk);
  4206. other2salearray.ElementAt(oldsize + ii).Add(rsSt.paytype);
  4207. other2salearray.ElementAt(oldsize + ii).Add(rsSt.autoid);
  4208. other2salearray.ElementAt(oldsize + ii).Add(rsSt.financecheck);
  4209. ii++;
  4210. rsSt.MoveNext(); if (other2salearray.GetSize() <= ii)break;
  4211. }
  4212. rsSt.Close(); other2salearray.SetSize(oldsize + ii, 1);
  4213. }
  4214. filter = "[date]='" + strdate + "'";
  4215. {
  4216. CRecordset myset(pCurdb);
  4217. CString sql = "select count(*) as cot from memberview";
  4218. if (!filter.IsEmpty())
  4219. sql += " where " + filter;
  4220. myset.Open(CRecordset::forwardOnly, sql);
  4221. myset.GetFieldValue("cot", sql);
  4222. myset.Close();
  4223. int count = atol(sql);
  4224. int oldsize = memberarray.GetSize();
  4225. memberarray.SetSize(oldsize + count, 1);
  4226. memberviewReg rsSt;
  4227. rsSt.m_pDatabase = pCurdb;
  4228. if (!filter.IsEmpty())
  4229. rsSt.m_strFilter = filter;
  4230. rsSt.Open();
  4231. DWORD ii = 0;
  4232. while (!rsSt.IsEOF())
  4233. {
  4234. memberarray.ElementAt(oldsize + ii).RemoveAll();
  4235. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_id);
  4236. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_memberno);
  4237. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_name);
  4238. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_money);
  4239. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_date);
  4240. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_clerk);
  4241. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_financecheck);
  4242. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_moneytype);
  4243. ii++;
  4244. rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break;
  4245. }
  4246. rsSt.Close(); memberarray.SetSize(oldsize + ii, 1);
  4247. }
  4248. }//
  4249. CString str;
  4250. int pos = 0;
  4251. int dindanshu = 0;
  4252. float income = 0;
  4253. float incomedd = 0;
  4254. float incomebk = 0;
  4255. float incomehq = 0;
  4256. float incomeqt = 0;
  4257. float payout = 0;
  4258. for (i = 0; i < List11array.GetSize(); i++)
  4259. {
  4260. str = List11array.ElementAt(i).ElementAt(2);
  4261. income += atof(str);
  4262. // income2+=atof(str);
  4263. if (List11array.ElementAt(i).ElementAt(3) == "预约收款")
  4264. {
  4265. incomedd += atof(str);
  4266. dindanshu++;
  4267. }
  4268. else if (List11array.ElementAt(i).ElementAt(3) == "预约补款")
  4269. {
  4270. incomebk += atof(str);
  4271. }
  4272. else
  4273. {
  4274. incomehq += atof(str);
  4275. }
  4276. pos++;
  4277. }
  4278. for (i = 0; i < List2array.GetSize(); i++)
  4279. {
  4280. str = List2array.ElementAt(i).ElementAt(2);
  4281. income += atof(str);
  4282. /* if(List2array.ElementAt (i).ElementAt (8)!="")
  4283. {
  4284. income2+=atof(str);
  4285. }*/
  4286. if (List2array.ElementAt(i).ElementAt(8) == "")
  4287. {
  4288. incomeqt += atof(str);
  4289. }
  4290. pos++;
  4291. }
  4292. for (i = 0; i < List3array.GetSize(); i++)
  4293. {
  4294. str = List3array.ElementAt(i).ElementAt(2);
  4295. payout += atof(str);
  4296. pos++;
  4297. }
  4298. for (i = 0; i < other2salearray.GetSize(); i++)
  4299. {
  4300. str = other2salearray.ElementAt(i).ElementAt(4);
  4301. income += atof(str);
  4302. incomehq += atof(str);
  4303. pos++;
  4304. }
  4305. for (i = 0; i < memberarray.GetSize(); i++)
  4306. {
  4307. str = memberarray.ElementAt(i).ElementAt(3);
  4308. income += atof(str);
  4309. pos++;
  4310. }
  4311. CTime tm = CTime::GetCurrentTime();
  4312. CString content = msgcompanyname + tm.Format("%Y-%m-%d");
  4313. content += "财报:";
  4314. str.Format("%d", (int)income);
  4315. ::ConvertToPrice(str);
  4316. content += "收:" + str;
  4317. str.Format("%d", (int)incomedd);
  4318. ::ConvertToPrice(str);
  4319. content += "定:" + str;
  4320. str.Format("%d", (int)incomebk);
  4321. ::ConvertToPrice(str);
  4322. content += "补:" + str;
  4323. str.Format("%d", (int)incomehq);
  4324. ::ConvertToPrice(str);
  4325. content += "后:" + str;
  4326. str.Format("%d", (int)incomeqt);
  4327. ::ConvertToPrice(str);
  4328. content += "其它:" + str;
  4329. str.Format("%d", (int)payout);
  4330. ::ConvertToPrice(str);
  4331. content += "支出:" + str;
  4332. str.Format("%d", (int)(income - payout));
  4333. ::ConvertToPrice(str);
  4334. content += "净收:" + str;
  4335. str.Format("%d", dindanshu);
  4336. content += "定单:" + str;
  4337. if (msgaccount != "")
  4338. {
  4339. if (atoi(balance) < 200)
  4340. {
  4341. content += "您的余额小于两百条,请及时充值。联系电话4006067068";
  4342. }
  4343. else if (atoi(balance) < 500)
  4344. {
  4345. content += "您的余额小于五百条,请及时充值。联系电话4006067068";
  4346. }
  4347. else if (atoi(balance) < 800)
  4348. {
  4349. content += "您的余额小于八百条,请及时充值。联系电话4006067068";
  4350. }
  4351. else if (atoi(balance) < 1000)
  4352. {
  4353. content += "您的余额小于一千条,请及时充值。联系电话4006067068";
  4354. }
  4355. }
  4356. int count = GetLengthEx(content) / MSG_LENGTH;
  4357. if (GetLengthEx(content) % MSG_LENGTH)
  4358. count++;
  4359. int phonenum = 0;
  4360. phonenum = 1;
  4361. count *= phonenum;
  4362. CString scount;
  4363. scount.Format("%d", count);
  4364. CString timestamp = tm.Format("%Y%m%d%H%M%S");
  4365. for (i = 0; i < 1; i++)
  4366. {
  4367. sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + array.ElementAt(i) + "','" + content + "','" + timestamp + "','" + scount + "','0','0','0','系统自动发送')";
  4368. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  4369. }
  4370. }
  4371. }
  4372. /////////////
  4373. if (atoi(msgcheck4) && msgphones != "")
  4374. {//发老板短信
  4375. if (atoi(msgtime) <= CTime::GetCurrentTime().GetHour())
  4376. {
  4377. MyLock lock("dbaccessxiao");
  4378. CString timestamp;
  4379. timestamp = CTime::GetCurrentTime().Format("%Y%m%d");
  4380. timestamp += "%";
  4381. CRecordset myset(pMaindb);
  4382. CString sql = "select count(*) as cot from sendreg where [timestamp] like '" + timestamp + "' and [phones]='" + msgphones + "' and [isautosend]='3'";
  4383. myset.Open(CRecordset::forwardOnly, sql);
  4384. myset.GetFieldValue("cot", sql);
  4385. myset.Close();
  4386. int count = atol(sql);
  4387. if (count == 0)
  4388. {
  4389. CArray<CStringArray, CStringArray>List11array;
  4390. CArray<CStringArray, CStringArray>List2array;
  4391. CArray<CStringArray, CStringArray>List3array;
  4392. CArray<CStringArray, CStringArray>other2salearray;
  4393. CArray<CStringArray, CStringArray>memberarray;
  4394. CString strdate = CTime::GetCurrentTime().Format("%Y-%m-%d");
  4395. for (int a = g_dbpool.GetSize() - 1; a >= 0; a--)
  4396. {
  4397. CDatabase *pCurdb = NULL;
  4398. ODBCConnGuard ConnGuard(pCurdb , a - 1, 3000);
  4399. if ( pCurdb == NULL )
  4400. continue;
  4401. CString filter = "[dat]='" + strdate + "'";
  4402. filter = "[dat]='" + strdate + "' and ([sale2type] is null or [sale2type]='')";
  4403. {
  4404. CRecordset myset(pCurdb);
  4405. CString sql = "select count(*) as cot from singleincome"; if (!filter.IsEmpty())sql += " where " + filter;
  4406. myset.Open(CRecordset::forwardOnly, sql);
  4407. myset.GetFieldValue("cot", sql);
  4408. myset.Close();
  4409. int count = atol(sql);
  4410. int oldsize = List2array.GetSize();
  4411. List2array.SetSize(oldsize + count, 1);
  4412. CRstIncomeInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  4413. rsSt.Open();
  4414. int ii = 0;
  4415. while (!rsSt.IsEOF())
  4416. {
  4417. List2array.ElementAt(oldsize + ii).RemoveAll();
  4418. List2array.ElementAt(oldsize + ii).Add(rsSt.id);
  4419. List2array.ElementAt(oldsize + ii).Add(rsSt.name);
  4420. List2array.ElementAt(oldsize + ii).Add(rsSt.money);
  4421. List2array.ElementAt(oldsize + ii).Add(rsSt.date);
  4422. List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
  4423. List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan2);
  4424. List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan3);
  4425. List2array.ElementAt(oldsize + ii).Add(rsSt.bz);
  4426. List2array.ElementAt(oldsize + ii).Add(rsSt.sale2type);
  4427. ii++;
  4428. rsSt.MoveNext(); if (List2array.GetSize() <= ii)break;
  4429. }
  4430. rsSt.Close(); List2array.SetSize(oldsize + ii, 1);
  4431. }
  4432. filter = "[dat]='" + strdate + "'";
  4433. {
  4434. CRecordset myset(pCurdb);
  4435. CString sql = "select count(*) as cot from gudingfeiyong"; if (!filter.IsEmpty())sql += " where " + filter;
  4436. myset.Open(CRecordset::forwardOnly, sql);
  4437. myset.GetFieldValue("cot", sql);
  4438. myset.Close();
  4439. int count = atol(sql);
  4440. int oldsize = List3array.GetSize();
  4441. List3array.SetSize(oldsize + count, 1);
  4442. CRstPayOutInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  4443. rsSt.Open();
  4444. int ii = 0;
  4445. while (!rsSt.IsEOF())
  4446. {
  4447. List3array.ElementAt(oldsize + ii).RemoveAll();
  4448. List3array.ElementAt(oldsize + ii).Add(rsSt.id);
  4449. List3array.ElementAt(oldsize + ii).Add(rsSt.name);
  4450. List3array.ElementAt(oldsize + ii).Add(rsSt.money);
  4451. List3array.ElementAt(oldsize + ii).Add(rsSt.date);
  4452. List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
  4453. List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan2);
  4454. List3array.ElementAt(oldsize + ii).Add(rsSt.bz);
  4455. ii++;
  4456. rsSt.MoveNext(); if (List3array.GetSize() <= ii)break;
  4457. }
  4458. rsSt.Close(); List3array.SetSize(oldsize + ii, 1);
  4459. }
  4460. filter = "[date]='" + strdate + "'";
  4461. {
  4462. CRecordset myset(pCurdb);
  4463. CString sql = "select count(*) as cot from dindanbukuan"; if (!filter.IsEmpty())sql += " where " + filter;
  4464. myset.Open(CRecordset::forwardOnly, sql);
  4465. myset.GetFieldValue("cot", sql);
  4466. myset.Close();
  4467. int count = atol(sql);
  4468. int oldsize = List11array.GetSize();
  4469. List11array.SetSize(oldsize + count, 1);
  4470. CRstBuKuan rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  4471. rsSt.Open();
  4472. int ii = 0;
  4473. while (!rsSt.IsEOF())
  4474. {
  4475. List11array.ElementAt(oldsize + ii).RemoveAll();
  4476. List11array.ElementAt(oldsize + ii).Add(rsSt.m_id);
  4477. List11array.ElementAt(oldsize + ii).Add(rsSt.m_ren);
  4478. List11array.ElementAt(oldsize + ii).Add(rsSt.m_money);
  4479. List11array.ElementAt(oldsize + ii).Add(rsSt.m_bz);
  4480. List11array.ElementAt(oldsize + ii).Add(rsSt.m_kind);
  4481. List11array.ElementAt(oldsize + ii).Add(rsSt.m_date);
  4482. List11array.ElementAt(oldsize + ii).Add(rsSt.paytype);
  4483. ii++;
  4484. rsSt.MoveNext(); if (List11array.GetSize() <= ii)break;
  4485. }
  4486. rsSt.Close(); List11array.SetSize(oldsize + ii, 1);
  4487. }
  4488. filter = "[date]='" + strdate + "'";
  4489. {
  4490. CRecordset myset(pCurdb);
  4491. CString sql = "select count(*) as cot from singleincomemoneyview"; if (!filter.IsEmpty())sql += " where " + filter;
  4492. myset.Open(CRecordset::forwardOnly, sql);
  4493. myset.GetFieldValue("cot", sql);
  4494. myset.Close();
  4495. int count = atol(sql);
  4496. int oldsize = other2salearray.GetSize();
  4497. other2salearray.SetSize(oldsize + count, 1);
  4498. CRstsingleincomemoneyview rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  4499. rsSt.Open();
  4500. int ii = 0;
  4501. while (!rsSt.IsEOF())
  4502. {
  4503. other2salearray.ElementAt(oldsize + ii).RemoveAll();
  4504. other2salearray.ElementAt(oldsize + ii).Add(rsSt.name);
  4505. other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
  4506. other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan3);
  4507. other2salearray.ElementAt(oldsize + ii).Add(rsSt.sale2type);
  4508. other2salearray.ElementAt(oldsize + ii).Add(rsSt.money);
  4509. other2salearray.ElementAt(oldsize + ii).Add(rsSt.date);
  4510. other2salearray.ElementAt(oldsize + ii).Add(rsSt.clerk);
  4511. other2salearray.ElementAt(oldsize + ii).Add(rsSt.paytype);
  4512. other2salearray.ElementAt(oldsize + ii).Add(rsSt.autoid);
  4513. other2salearray.ElementAt(oldsize + ii).Add(rsSt.financecheck);
  4514. ii++;
  4515. rsSt.MoveNext(); if (other2salearray.GetSize() <= ii)break;
  4516. }
  4517. rsSt.Close(); other2salearray.SetSize(oldsize + ii, 1);
  4518. }
  4519. filter = "[date]='" + strdate + "'";
  4520. {
  4521. CRecordset myset(pCurdb);
  4522. CString sql = "select count(*) as cot from memberview"; if (!filter.IsEmpty())sql += " where " + filter;
  4523. myset.Open(CRecordset::forwardOnly, sql);
  4524. myset.GetFieldValue("cot", sql);
  4525. myset.Close();
  4526. int count = atol(sql);
  4527. int oldsize = memberarray.GetSize();
  4528. memberarray.SetSize(oldsize + count, 1);
  4529. memberviewReg rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  4530. rsSt.Open();
  4531. DWORD ii = 0;
  4532. while (!rsSt.IsEOF())
  4533. {
  4534. memberarray.ElementAt(oldsize + ii).RemoveAll();
  4535. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_id);
  4536. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_memberno);
  4537. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_name);
  4538. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_money);
  4539. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_date);
  4540. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_clerk);
  4541. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_financecheck);
  4542. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_moneytype);
  4543. ii++;
  4544. rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break;
  4545. }
  4546. rsSt.Close(); memberarray.SetSize(oldsize + ii, 1);
  4547. }
  4548. }//
  4549. CString str;
  4550. int pos = 0;
  4551. int dindanshu = 0;
  4552. float income = 0;
  4553. float incomedd = 0;
  4554. float incomebk = 0;
  4555. float incomehq = 0;
  4556. float incomeqt = 0;
  4557. float fStoredCardSpending = 0.0; // 储值卡扣款
  4558. float payout = 0;
  4559. int i = 0;
  4560. for ( i = 0; i < List11array.GetSize(); i++)
  4561. {
  4562. str = List11array.ElementAt(i).ElementAt(2);
  4563. income += atof(str);
  4564. // income2+=atof(str);
  4565. if (List11array.ElementAt(i).ElementAt(3) == "预约收款")
  4566. {
  4567. incomedd += atof(str);
  4568. dindanshu++;
  4569. }
  4570. else if (List11array.ElementAt(i).ElementAt(3) == "预约补款")
  4571. {
  4572. incomebk += atof(str);
  4573. }
  4574. else
  4575. {
  4576. incomehq += atof(str);
  4577. }
  4578. #if JEFF_TEST_ON // 去除储值卡扣费;
  4579. if (List11array.ElementAt(i).ElementAt(6) == "储值卡扣款" || List11array.ElementAt(i).ElementAt(6) == "代金券")
  4580. {
  4581. fStoredCardSpending += atof(str);
  4582. }
  4583. #endif
  4584. pos++;
  4585. }
  4586. for (i = 0; i < List2array.GetSize(); i++)
  4587. {
  4588. str = List2array.ElementAt(i).ElementAt(2);
  4589. income += atof(str);
  4590. /* if(List2array.ElementAt (i).ElementAt (8)!="")
  4591. {
  4592. income2+=atof(str);
  4593. }*/
  4594. if (List2array.ElementAt(i).ElementAt(8) == "")
  4595. {
  4596. incomeqt += atof(str);
  4597. }
  4598. pos++;
  4599. }
  4600. for (i = 0; i < List3array.GetSize(); i++)
  4601. {
  4602. str = List3array.ElementAt(i).ElementAt(2);
  4603. payout += atof(str);
  4604. pos++;
  4605. }
  4606. for (i = 0; i < other2salearray.GetSize(); i++)
  4607. {
  4608. str = other2salearray.ElementAt(i).ElementAt(4);
  4609. income += atof(str);
  4610. incomehq += atof(str);
  4611. pos++;
  4612. }
  4613. for (i = 0; i < memberarray.GetSize(); i++)
  4614. {
  4615. str = memberarray.ElementAt(i).ElementAt(3);
  4616. income += atof(str);
  4617. pos++;
  4618. }
  4619. CTime tm = CTime::GetCurrentTime();
  4620. CString content = msgcompanyname + tm.Format("%Y-%m-%d");
  4621. content += "财报:";
  4622. income -= fStoredCardSpending;
  4623. str.Format("%d", (int)(income)); // 去除储值卡扣款和代金券;
  4624. ::ConvertToPrice(str);
  4625. content += "收:" + str;
  4626. str.Format("%d", (int)incomedd);
  4627. ::ConvertToPrice(str);
  4628. content += "定:" + str;
  4629. str.Format("%d", (int)incomebk);
  4630. ::ConvertToPrice(str);
  4631. content += "补:" + str;
  4632. str.Format("%d", (int)incomehq);
  4633. ::ConvertToPrice(str);
  4634. content += "后:" + str;
  4635. str.Format("%d", (int)incomeqt);
  4636. ::ConvertToPrice(str);
  4637. content += "其它:" + str;
  4638. str.Format("%d", (int)payout);
  4639. ::ConvertToPrice(str);
  4640. content += "支出:" + str;
  4641. str.Format("%d", (int)(income - payout));
  4642. ::ConvertToPrice(str);
  4643. content += "净收:" + str;
  4644. str.Format("%d", dindanshu);
  4645. content += "定单:" + str;
  4646. if (msgaccount != "")
  4647. {
  4648. if (atoi(balance) < 200)
  4649. {
  4650. content += "您的余额小于两百条,请及时充值。联系电话4006067068";
  4651. }
  4652. else if (atoi(balance) < 500)
  4653. {
  4654. content += "您的余额小于五百条,请及时充值。联系电话4006067068";
  4655. }
  4656. else if (atoi(balance) < 800)
  4657. {
  4658. content += "您的余额小于八百条,请及时充值。联系电话4006067068";
  4659. }
  4660. else if (atoi(balance) < 1000)
  4661. {
  4662. content += "您的余额小于一千条,请及时充值。联系电话4006067068";
  4663. }
  4664. }
  4665. int count = GetLengthEx(content) / MSG_LENGTH;
  4666. if (GetLengthEx(content) % MSG_LENGTH)
  4667. count++;
  4668. int phonenum = 0;
  4669. str = msgphones;
  4670. pos = str.Find(",");
  4671. if (pos != -1)
  4672. {
  4673. while (pos != -1)
  4674. {
  4675. phonenum++;
  4676. str = str.Right(str.GetLength() - pos - 1);
  4677. pos = str.Find(",");
  4678. }
  4679. phonenum++;
  4680. }
  4681. else
  4682. phonenum = 1;
  4683. count *= phonenum;
  4684. CString scount;
  4685. scount.Format("%d", count);
  4686. timestamp = tm.Format("%Y%m%d%H%M%S");
  4687. sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + msgphones + "','" + content + "','" + timestamp + "','" + scount + "','0','0','3','系统自动发送')";
  4688. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  4689. }
  4690. }
  4691. }
  4692. BOOL bcheck1 = atoi(m_bak1);
  4693. BOOL bcheck2 = atoi(m_bak2);
  4694. BOOL bcheck3 = atoi(m_bak3);
  4695. BOOL bcheck4 = atoi(m_bak4);
  4696. }
  4697. catch (CException *e)
  4698. {
  4699. TCHAR szError[1024] = { 0 };
  4700. e->GetErrorMessage(szError, 1024);
  4701. WriteTextLog(CString(szError));
  4702. e->Delete();
  4703. WriteTextLog("出错在函数bakphoto中");
  4704. }
  4705. }
  4706. void CDBServerDlg::ShutDown() //Jeff:备份完毕后执行的关机函数;
  4707. {
  4708. try
  4709. {
  4710. // 结束检查服务线程
  4711. TerminateCheckWork();
  4712. CDatabase *pMaindb = NULL;
  4713. ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
  4714. if ( pMaindb == NULL )
  4715. return;
  4716. CString m_bak6;
  4717. {
  4718. CRecordset myset(pMaindb);
  4719. CString sql = "select * from [version]";
  4720. myset.Open(CRecordset::forwardOnly, sql);
  4721. myset.GetFieldValue("bak6", m_bak6);
  4722. myset.Close();
  4723. }
  4724. OnServerStop(); // 停止服务;
  4725. // Jeff.关闭数据库连接,若关机前关闭了数据库的连接,则客户端进行订单无法实现数据库的操作;
  4726. // Jeff.在关机前,不能关闭数据库连接;
  4727. for (int i = 0; i < g_dbHistoryArray.GetSize(); i++)
  4728. {
  4729. g_dbHistoryArray.ElementAt(i)->Close();
  4730. delete g_dbHistoryArray.ElementAt(i);
  4731. }
  4732. ReleaseBranchDB();
  4733. WriteTextLog("备份完成");
  4734. ////////////////
  4735. g_tisks = ::GetTickCount() - g_tisks;
  4736. CString str;
  4737. str.Format("耗时:%d分钟", g_tisks / 60000);
  4738. CStdioFile fp;
  4739. fp.Open(g_mainpath + "\\log.txt", CFile::modeCreate | CFile::modeWrite);
  4740. CTime tm = CTime::GetCurrentTime();
  4741. if (0)//tm.GetHour ()<5)
  4742. {
  4743. CTimeSpan sp(1, 0, 0, 0);
  4744. tm -= sp;
  4745. fp.WriteString(tm.Format("%Y-%m-%d"));
  4746. fp.WriteString("\r\n");
  4747. fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S"));
  4748. fp.WriteString(str);
  4749. }
  4750. else
  4751. {
  4752. fp.WriteString(g_bakdate);
  4753. fp.WriteString("\r\n");
  4754. fp.WriteString(tm.Format("%Y-%m-%d %H:%M:%S"));
  4755. fp.WriteString(str);
  4756. }
  4757. fp.WriteString("\r\n");
  4758. fp.WriteString(g_bakinfo);
  4759. fp.WriteString("\r\n");
  4760. fp.WriteString(g_bakphoto);
  4761. fp.Close();
  4762. // OnButton3();
  4763. // Jeff.备份完成后自动关机;
  4764. if (atoi(m_bak6))
  4765. {
  4766. // Jeff.关闭运行中的线程;
  4767. TerminateThread();
  4768. // Jeff.关闭AutoRun.exe程序;
  4769. DWORD id = FindAppProcessID("AutoRun.exe");
  4770. if (id != -1)
  4771. {
  4772. HANDLE ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, id);
  4773. if (ProcessHandle)TerminateProcess(ProcessHandle, 0);
  4774. }
  4775. // Jeff.移除托盘图标;
  4776. m_TrayIcon.RemoveIcon();
  4777. if (g_pSkinData)delete[]g_pSkinData; g_pSkinData = NULL;
  4778. // Jeff.关闭计算机;
  4779. MyExitWindows();
  4780. }
  4781. else//重启
  4782. {
  4783. TerminateThread();
  4784. m_TrayIcon.RemoveIcon();
  4785. if (g_pSkinData)
  4786. delete[]g_pSkinData;
  4787. g_pSkinData = NULL;
  4788. WriteTextLog("备份完成,服务器重启");
  4789. CDialog::OnCancel();
  4790. }
  4791. }
  4792. catch (...)
  4793. {
  4794. WriteTextLog("出错在函数shutdown中");
  4795. }
  4796. }
  4797. void CDBServerDlg::MyExitWindows()
  4798. {
  4799. try
  4800. {
  4801. UINT t = EWX_SHUTDOWN | EWX_FORCE;
  4802. OSVERSIONINFO osv; //定义一个操作系统信息的结构体
  4803. osv.dwOSVersionInfoSize = sizeof OSVERSIONINFO;
  4804. GetVersionEx(&osv); //查询当前操作系统
  4805. if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) //判断是否是2000/NT
  4806. {
  4807. //下面为向操作系统获取权限操作
  4808. HANDLE hProcess, hToken;
  4809. TOKEN_PRIVILEGES Privileges;
  4810. LUID luid;
  4811. hProcess = GetCurrentProcess();
  4812. //下面为打开当前进程对话
  4813. OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken);
  4814. Privileges.PrivilegeCount = 1;
  4815. LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &luid);
  4816. Privileges.Privileges[0].Luid = luid;
  4817. Privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  4818. AdjustTokenPrivileges(hToken, FALSE, &Privileges, NULL, NULL, NULL);
  4819. ExitWindowsEx(t, 0);
  4820. }
  4821. else
  4822. {
  4823. ExitWindowsEx(t, 0);//调用ExitWindowsEx关闭机器。
  4824. PostQuitMessage(0);
  4825. }
  4826. }
  4827. catch (...)
  4828. {
  4829. WriteTextLog("出错在函数exitwindows中");
  4830. }
  4831. }
  4832. void CDBServerDlg::OnAutorun()
  4833. {
  4834. // TODO: Add your command handler code here
  4835. g_bAutoRun = !g_bAutoRun;
  4836. CString version = _T("Version 1.0");
  4837. AfxGetApp()->WriteProfileInt(version, "brun", g_bAutoRun);
  4838. TCHAR szKey[MAX_PATH];
  4839. HKEY hKey = 0;
  4840. DWORD disp = 0;
  4841. lstrcpy(szKey, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
  4842. if (g_bAutoRun)
  4843. {
  4844. int lResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp);
  4845. if (lResult == ERROR_SUCCESS)
  4846. {
  4847. TCHAR szDir[MAX_PATH];
  4848. ::GetModuleFileName(NULL, szDir, MAX_PATH);
  4849. lResult = RegSetValueEx(hKey, "YLGLDBSERVER", 0, REG_SZ, (const unsigned char*)szDir, lstrlen(szDir));
  4850. RegCloseKey(hKey);
  4851. }
  4852. }
  4853. else
  4854. {
  4855. int lResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp);
  4856. if (lResult == ERROR_SUCCESS)
  4857. {
  4858. RegDeleteValue(hKey, "YLGLDBSERVER");
  4859. RegDeleteKey(hKey, "YLGLDBSERVER");
  4860. RegCloseKey(hKey);
  4861. }
  4862. }
  4863. }
  4864. void CDBServerDlg::GetFileDate()
  4865. {
  4866. CStringArray filesarray;
  4867. CStringArray filesarray2;
  4868. filesarray.Add("AutoUpdate.exe"); // 1.
  4869. filesarray.Add("skin\\1.lia");
  4870. filesarray.Add("skin\\2.lia");
  4871. filesarray.Add("skin\\3.lia");
  4872. filesarray.Add("skin\\4.lia");
  4873. filesarray.Add("skin\\10.lia");
  4874. filesarray.Add("skin\\logo.jpg");
  4875. filesarray.Add("skin\\标题-选片.jpg");
  4876. filesarray.Add("skin\\标题-看设计.jpg");
  4877. filesarray.Add("图片\\欢迎.jpg"); // 10.
  4878. filesarray.Add("图片\\连接.jpg");
  4879. filesarray.Add("图片\\标题.jpg");
  4880. filesarray.Add("图片\\背景.jpg");
  4881. filesarray.Add("图片-红色风格\\欢迎.jpg");
  4882. filesarray.Add("图片-红色风格\\连接.jpg");
  4883. filesarray.Add("图片-红色风格\\标题.jpg");
  4884. filesarray.Add("图片-红色风格\\背景.jpg");
  4885. filesarray.Add("图片-红色风格\\选片.jpg");
  4886. filesarray.Add("图片-红色风格\\看设计.jpg");
  4887. filesarray.Add("skin\\1-red.lia"); // 20.
  4888. filesarray.Add("skin\\2-red.lia");
  4889. filesarray.Add("skin\\10-red.lia");
  4890. filesarray.Add("skin\\6.lia");
  4891. filesarray.Add("图片\\掌中宝.jpg");
  4892. filesarray.Add("regsvr32.exe"); // 25.
  4893. filesarray.Add("MSCHRT20.OCX"); // 26. // Jeff.2014.09.06.添加MSCHRT20.OCX,由服务器传递;
  4894. ///////////////
  4895. filesarray2.Add("AutoUpdate.exe");
  4896. filesarray2.Add("skin\\1.lia");
  4897. filesarray2.Add("skin\\2.lia");
  4898. filesarray2.Add("skin\\3.lia");
  4899. filesarray2.Add("skin\\4.lia");
  4900. filesarray2.Add("skin\\5.lia");
  4901. filesarray2.Add("skin\\10.lia");
  4902. filesarray2.Add("skin\\5-red.lia");
  4903. filesarray2.Add("skin\\10-red.lia");
  4904. filesarray2.Add("图片\\logo.jpg");
  4905. filesarray2.Add("图片\\标题-选片.jpg");
  4906. filesarray2.Add("图片\\标题-看设计.jpg");
  4907. filesarray2.Add("图片\\选片.jpg");
  4908. filesarray2.Add("图片\\看设计.jpg");
  4909. filesarray2.Add("图片\\欢迎.jpg");
  4910. filesarray2.Add("图片\\连接.jpg");
  4911. filesarray2.Add("图片\\标题.jpg");
  4912. filesarray2.Add("图片\\背景.jpg");
  4913. filesarray2.Add("图片-红色风格\\欢迎.jpg");
  4914. filesarray2.Add("图片-红色风格\\连接.jpg");
  4915. filesarray2.Add("图片-红色风格\\标题.jpg");
  4916. filesarray2.Add("图片-红色风格\\背景.jpg");
  4917. filesarray2.Add("skin\\6.lia");
  4918. filesarray2.Add("图片\\掌中宝.jpg");
  4919. filesarray2.Add("regsvr32.exe");
  4920. filesarray2.Add("MSCHRT20.OCX"); // 26. // Jeff.2014.09.06.添加MSCHRT20.OCX,由服务器传递;
  4921. int i = 0;
  4922. //for (int i = 0; i < filesarray.GetSize(); i++)
  4923. for ( i = 0; i < filesarray.GetSize(); i++)
  4924. {
  4925. g_filedatearray.Add(GetModifyTime(g_mainpath + "\\系统文件\\" + filesarray.ElementAt(i)));
  4926. }
  4927. g_filedatearraynew.Copy(filesarray2);
  4928. for (i = 0; i < filesarray2.GetSize(); i++)
  4929. {
  4930. g_filedatearraynew.Add(GetFileSize(g_mainpath + "\\系统文件\\" + filesarray2.ElementAt(i)));
  4931. }
  4932. }
  4933. //extern CString g_sdomain;
  4934. #ifdef ENTERPRISE_VERSION
  4935. CString g_bMain;
  4936. #endif
  4937. void CDBServerDlg::LoadBranchInfo()
  4938. {
  4939. #ifdef ENTERPRISE_VERSION
  4940. try
  4941. {
  4942. ReleaseBranchDB();
  4943. CArray<CStringArray, CStringArray>g_List1array;
  4944. {
  4945. MyLock lock("savebranchinfo");
  4946. CFile fp;
  4947. CString path = g_mainpath + "\\branchinfo.dat";
  4948. if (::PathFileExists(path) == 0)
  4949. return;
  4950. fp.Open(path, CFile::modeRead);
  4951. DWORD leng = fp.GetLength();
  4952. if (leng < sizeof(DWORD) * 2)
  4953. {
  4954. fp.Close();
  4955. return;
  4956. }
  4957. DWORD flag = 0;
  4958. //fp.Seek(-sizeof(DWORD), CFile::end);
  4959. fp.Seek(-(int)sizeof(DWORD), CFile::end);
  4960. fp.Read(&flag, sizeof(DWORD));
  4961. if (flag != 889900)
  4962. {
  4963. fp.Close();
  4964. return;
  4965. }
  4966. fp.SeekToBegin();
  4967. DWORD arraysize;
  4968. fp.Read(&arraysize, sizeof(DWORD));
  4969. if (arraysize > 20)
  4970. {
  4971. fp.Close();
  4972. return;
  4973. }
  4974. BYTE *pData = new BYTE[leng - sizeof(DWORD)];
  4975. fp.Read(pData, leng - sizeof(DWORD));
  4976. fp.Close();
  4977. CMemFile memfile;
  4978. memfile.Attach(pData, leng - sizeof(DWORD));
  4979. CArchive ar(&memfile, CArchive::load);
  4980. g_List1array.SetSize(arraysize, 1);
  4981. for (int ii = 0; ii < g_List1array.GetSize(); ii++)
  4982. g_List1array.ElementAt(ii).Serialize(ar);
  4983. ar.Close();
  4984. memfile.Detach();
  4985. delete[]pData;
  4986. }
  4987. if (g_List1array.GetSize() == 0)
  4988. return;
  4989. // SoftKey ytSoftKey;
  4990. // if(ytSoftKey.Ini()==0)
  4991. {
  4992. int value[8];
  4993. double f[8];
  4994. 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("");
  4995. //运行自定义函数
  4996. int ret = ytSoftKey.getdata(&value[0], &value[1], &value[2], &value[3], &value[4], &value[5], &value[6], &value[7],
  4997. &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
  4998. s0, s1, s2, s3, s4, s5, s6, s7);
  4999. if (ret != 0 && ret != -43)
  5000. {
  5001. g_sdomain = "";
  5002. }
  5003. else
  5004. g_sdomain = s1;
  5005. }
  5006. CString str, str2, localname, rights;
  5007. int i = 0;
  5008. for (/*int*/ i = 0; i < g_List1array.GetSize(); i++)
  5009. {
  5010. if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0))
  5011. {
  5012. if (g_List1array.ElementAt(i).GetSize()>5)
  5013. rights = g_List1array.ElementAt(i).ElementAt(5); break;
  5014. }
  5015. }
  5016. for (i = 0; i < g_List1array.GetSize(); i++)
  5017. {
  5018. CString branchname = g_List1array.ElementAt(i).ElementAt(1);
  5019. CString branchip = g_List1array.ElementAt(i).ElementAt(2);
  5020. CString domain = g_List1array.ElementAt(i).ElementAt(0);
  5021. CString dir = g_mainpath + "\\数据\\" + branchname;
  5022. if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0))
  5023. {
  5024. localname = branchname;
  5025. g_bMain = g_List1array.ElementAt(i).ElementAt(3);
  5026. continue;
  5027. }
  5028. CString branchname2 = "," + branchname + ",";
  5029. if (rights.Find(branchname2) == -1)
  5030. continue;
  5031. #ifdef SQLSERVER_VERSION
  5032. if (1)//::PathFileExists (dir))
  5033. {
  5034. /////////////////////////
  5035. g_branchdbarray.Add(NULL);
  5036. g_branchnamearray.Add(branchname);
  5037. g_branchdb2array.Add(NULL);
  5038. g_branchname2array.Add(branchname);
  5039. g_branchiparray.Add(branchip);
  5040. g_branchdomainarray.Add(domain);
  5041. // WriteTextLog(_T("添加分店:")+branchname);
  5042. }
  5043. #endif
  5044. }
  5045. //WriteTextLog(_T("添加本店:")+localname);
  5046. g_branchdbarray.Add(NULL);
  5047. g_branchnamearray.Add(localname);
  5048. g_branchiparray.Add("xxx");
  5049. g_branchdomainarray.Add(g_sdomain);
  5050. }
  5051. catch (...)
  5052. {
  5053. }
  5054. #endif
  5055. }
  5056. void CDBServerDlg::ReleaseBranchDB()
  5057. {
  5058. #ifdef ENTERPRISE_VERSION
  5059. try
  5060. {
  5061. for (int i = 0; i < g_branchdbarray.GetSize(); i++)
  5062. {
  5063. if (g_branchdbarray.ElementAt(i))
  5064. {
  5065. g_branchdbarray.ElementAt(i)->Close();
  5066. delete g_branchdbarray.ElementAt(i);
  5067. }
  5068. }
  5069. g_branchdbarray.RemoveAll();
  5070. g_branchdb2array.RemoveAll();
  5071. g_branchnamearray.RemoveAll();
  5072. g_branchname2array.RemoveAll();
  5073. g_branchiparray.RemoveAll();
  5074. g_branchdomainarray.RemoveAll();
  5075. }
  5076. catch (...)
  5077. {
  5078. WriteTextLog("ReleaseBranchDB出错");
  5079. }
  5080. #endif
  5081. }
  5082. //savebranchinfo
  5083. void CDBServerDlg::LoadBranchInfo2()
  5084. {
  5085. #ifdef ENTERPRISE_VERSION
  5086. try
  5087. {
  5088. ReleaseBranchDB();
  5089. CArray<CStringArray, CStringArray>g_List1array;
  5090. {
  5091. MyLock lock("savebranchinfo");
  5092. CFile fp;
  5093. CString path = g_mainpath + "\\branchinfo.dat";
  5094. if (::PathFileExists(path) == 0)
  5095. return;
  5096. fp.Open(path, CFile::modeRead);
  5097. DWORD leng = fp.GetLength();
  5098. if (leng < sizeof(DWORD) * 2)
  5099. {
  5100. fp.Close(); return;
  5101. }
  5102. DWORD flag;
  5103. //fp.Seek(-sizeof(DWORD), CFile::end);
  5104. fp.Seek(-(int)sizeof(DWORD), CFile::end);
  5105. fp.Read(&flag, sizeof(DWORD));
  5106. if (flag != 889900)
  5107. {
  5108. fp.Close(); return;
  5109. }
  5110. fp.SeekToBegin();
  5111. DWORD arraysize;
  5112. fp.Read(&arraysize, sizeof(DWORD));
  5113. if (arraysize > 20)
  5114. {
  5115. fp.Close();
  5116. return;
  5117. }
  5118. BYTE *pData = new BYTE[leng - sizeof(DWORD)];
  5119. fp.Read(pData, leng - sizeof(DWORD));
  5120. fp.Close();
  5121. CMemFile memfile;
  5122. memfile.Attach(pData, leng - sizeof(DWORD));
  5123. CArchive ar(&memfile, CArchive::load);
  5124. g_List1array.SetSize(arraysize, 1);
  5125. for (int ii = 0; ii < g_List1array.GetSize(); ii++)
  5126. {
  5127. g_List1array.ElementAt(ii).Serialize(ar);
  5128. }
  5129. ar.Close();
  5130. memfile.Detach();
  5131. delete[]pData;
  5132. }
  5133. if (g_List1array.GetSize() == 0)return;
  5134. // SoftKey ytSoftKey;
  5135. // if(ytSoftKey.Ini()==0)
  5136. {
  5137. int value[8];
  5138. double f[8];
  5139. 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("");
  5140. //运行自定义函数
  5141. int ret = ytSoftKey.getdata(&value[0], &value[1], &value[2], &value[3], &value[4], &value[5], &value[6], &value[7],
  5142. &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
  5143. s0, s1, s2, s3, s4, s5, s6, s7);
  5144. if (ret != 0 && ret != -43)
  5145. {
  5146. g_sdomain = "";
  5147. }
  5148. else
  5149. g_sdomain = s1;
  5150. }
  5151. CString str, str2, localname, rights;
  5152. int i = 0;
  5153. for (/*int*/ i = 0; i < g_List1array.GetSize(); i++)
  5154. {
  5155. if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0))
  5156. {
  5157. if (g_List1array.ElementAt(i).GetSize()>5)
  5158. rights = g_List1array.ElementAt(i).ElementAt(5); break;
  5159. }
  5160. }
  5161. for (i = 0; i < g_List1array.GetSize(); i++)
  5162. {
  5163. CString branchname = g_List1array.ElementAt(i).ElementAt(1);
  5164. CString branchip = g_List1array.ElementAt(i).ElementAt(2);
  5165. CString domain = g_List1array.ElementAt(i).ElementAt(0);
  5166. CString dir = g_mainpath + "\\数据\\" + branchname;
  5167. if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0))
  5168. {
  5169. localname = branchname;
  5170. g_bMain = g_List1array.ElementAt(i).ElementAt(3);
  5171. continue;
  5172. }
  5173. CString branchname2 = "," + branchname + ",";
  5174. if (rights.Find(branchname2) == -1)
  5175. continue;
  5176. #ifdef SQLSERVER_VERSION
  5177. if (1)//::PathFileExists (dir))
  5178. {
  5179. ////////////////////////
  5180. g_branchdbarray.Add(NULL);
  5181. g_branchnamearray.Add(branchname);
  5182. g_branchdb2array.Add(NULL);
  5183. g_branchname2array.Add(branchname);
  5184. g_branchiparray.Add(branchip);
  5185. g_branchdomainarray.Add(domain);
  5186. }
  5187. #endif
  5188. }
  5189. g_branchdbarray.Add(NULL);
  5190. g_branchnamearray.Add(localname);
  5191. g_branchiparray.Add("xxx");
  5192. g_branchdomainarray.Add(g_sdomain);
  5193. }
  5194. catch (...)
  5195. {
  5196. }
  5197. #endif
  5198. }
  5199. int __cdecl CompareByLabel6(const void *elem1, const void *elem2)
  5200. {
  5201. CStringArray *p1 = (CStringArray*)elem1;
  5202. CStringArray *p2 = (CStringArray*)elem2;
  5203. return atoi(p1->ElementAt(5)) > atoi(p2->ElementAt(5));
  5204. }
  5205. //--------------------------------------------------------------
  5206. // Remark by Jeff 2014.12.16
  5207. // 函数:CheckMemberMsg
  5208. // 描述:
  5209. // 参数:
  5210. // 返回:
  5211. //
  5212. // 调用关系:
  5213. // 1.CheckMemberMsg() 只由 CDBServerDlg::SetTimer(4) 调用,调用频率2分钟,周期数直到程序结束。
  5214. // 2.CDBServerDlg::SetTimer(4) 由 CDBServerDlg::SetTimer(2) 调用,调用频率10毫秒,只有一个周期。
  5215. // 3.CDBServerDlg::SetTimer(2) 由 CDBServerDlg::OnInitDialog() 调用.
  5216. //--------------------------------------------------------------
  5217. void CDBServerDlg::CheckMemberMsg() // Jeff.由定时器SetTimer两分钟执行一次
  5218. {
  5219. try
  5220. {
  5221. CDatabase *pMaindb = NULL;
  5222. ODBCConnGuard ConnGuard( pMaindb, -1, 3000);
  5223. if ( pMaindb == NULL )
  5224. return;
  5225. CString sql = "delete from sendreg where [log]='0/0'";
  5226. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5227. {
  5228. CStringArray idarray;
  5229. CString timestamp;
  5230. CTime tm = CTime::GetCurrentTime();
  5231. tm -= CTimeSpan(0, 1, 0, 0);
  5232. timestamp = tm.Format("%Y%m%d%H%M%S");
  5233. CRecordset myset(pMaindb);
  5234. CString sql = "select [autoid] from sendregdelay where [timestamp]<'" + timestamp + "'";
  5235. myset.Open(CRecordset::forwardOnly, sql);
  5236. while (!myset.IsEOF())
  5237. {
  5238. myset.GetFieldValue("autoid", sql);
  5239. idarray.Add(sql);
  5240. myset.MoveNext();
  5241. }
  5242. myset.Close();
  5243. for (int i = 0; i < idarray.GetSize(); i++)
  5244. {
  5245. // Jeff.deal
  5246. //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)));
  5247. 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)));
  5248. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5249. sql.Format("delete from sendregdelay where [autoid]=%d", atol(idarray.ElementAt(i)));
  5250. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5251. }
  5252. }
  5253. int covertrate = 100;
  5254. CString spoint;
  5255. {
  5256. CRecordset myset(pMaindb);
  5257. CString sql = "select * from version";
  5258. myset.Open(CRecordset::forwardOnly, sql);
  5259. myset.GetFieldValue("rate2", sql);
  5260. myset.Close();
  5261. covertrate = atoi(sql);
  5262. if (covertrate == 0)covertrate = 100;
  5263. }
  5264. CString filter;
  5265. CArray<CStringArray, CStringArray>rulearray;
  5266. CArray<CStringArray, CStringArray>memberarray;
  5267. {
  5268. CRecordset myset(pMaindb);
  5269. CString sql = "select count(*) as cot from msgtemp2";
  5270. if (!filter.IsEmpty())sql += " where " + filter;
  5271. myset.Open(CRecordset::forwardOnly, sql);
  5272. myset.GetFieldValue("cot", sql);
  5273. myset.Close();
  5274. int count = atol(sql);
  5275. rulearray.SetSize(count, 1);
  5276. CRstmsgtemp2 rsSt;
  5277. rsSt.m_pDatabase = pMaindb;
  5278. if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  5279. rsSt.Open();
  5280. DWORD ii = 0;
  5281. while (!rsSt.IsEOF())
  5282. {
  5283. rulearray.ElementAt(ii).RemoveAll();
  5284. rulearray.ElementAt(ii).Add(rsSt.name);
  5285. rulearray.ElementAt(ii).Add(rsSt.content1);
  5286. rulearray.ElementAt(ii).Add(rsSt.content2);
  5287. rulearray.ElementAt(ii).Add(rsSt.check1);
  5288. rulearray.ElementAt(ii).Add(rsSt.check2);
  5289. rulearray.ElementAt(ii).Add(rsSt.point);
  5290. ii++;
  5291. rsSt.MoveNext();
  5292. if (rulearray.GetSize() <= ii)break;
  5293. }
  5294. rsSt.Close(); rulearray.SetSize(ii, 1);
  5295. }
  5296. if (rulearray.GetSize() == 0)return;
  5297. qsort(static_cast<void*>(&rulearray[0]), rulearray.GetSize(), sizeof(rulearray[0]), CompareByLabel6);
  5298. /////////////
  5299. {
  5300. CRecordset myset(pMaindb);
  5301. CString sql = "select count(*) as cot from membermanage"; if (!filter.IsEmpty())sql += " where " + filter;
  5302. myset.Open(CRecordset::forwardOnly, sql);
  5303. myset.GetFieldValue("cot", sql);
  5304. myset.Close();
  5305. memberarray.SetSize(atol(sql), 1);
  5306. RstMemberReg rsSt;
  5307. rsSt.m_pDatabase = pMaindb;
  5308. if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  5309. rsSt.Open();
  5310. DWORD ii = 0;
  5311. if (covertrate != 100)
  5312. {
  5313. while (!rsSt.IsEOF())
  5314. {
  5315. memberarray.ElementAt(ii).RemoveAll();
  5316. memberarray.ElementAt(ii).Add(rsSt.m_memberno);
  5317. memberarray.ElementAt(ii).Add(rsSt.m_name);
  5318. memberarray.ElementAt(ii).Add(rsSt.m_sex);
  5319. memberarray.ElementAt(ii).Add(rsSt.m_phone);
  5320. spoint.Format("%d", atoi(rsSt.m_money)*covertrate / 100);
  5321. memberarray.ElementAt(ii).Add(spoint);
  5322. memberarray.ElementAt(ii).Add(rsSt.m_sendmark1);
  5323. memberarray.ElementAt(ii).Add(rsSt.m_sendmark2);
  5324. ii++;
  5325. rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break;
  5326. }
  5327. }
  5328. else
  5329. {
  5330. while (!rsSt.IsEOF())
  5331. {
  5332. memberarray.ElementAt(ii).RemoveAll();
  5333. memberarray.ElementAt(ii).Add(rsSt.m_memberno);
  5334. memberarray.ElementAt(ii).Add(rsSt.m_name);
  5335. memberarray.ElementAt(ii).Add(rsSt.m_sex);
  5336. memberarray.ElementAt(ii).Add(rsSt.m_phone);
  5337. memberarray.ElementAt(ii).Add(rsSt.m_money);
  5338. memberarray.ElementAt(ii).Add(rsSt.m_sendmark1);
  5339. memberarray.ElementAt(ii).Add(rsSt.m_sendmark2);
  5340. ii++;
  5341. rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break;
  5342. }
  5343. }
  5344. rsSt.Close(); memberarray.SetSize(ii, 1);
  5345. }
  5346. CString memberno, name, sex, phone, point, mark1, mark2, rulename, rulecheck1, rulecheck2, rulepoint, rulecontent1, rulecontent2;
  5347. for (int i = 0; i < memberarray.GetSize(); i++)
  5348. {
  5349. memberno = memberarray.ElementAt(i).ElementAt(0);
  5350. name = memberarray.ElementAt(i).ElementAt(1);
  5351. sex = memberarray.ElementAt(i).ElementAt(2);
  5352. phone = memberarray.ElementAt(i).ElementAt(3);
  5353. point = memberarray.ElementAt(i).ElementAt(4);
  5354. mark1 = "," + memberarray.ElementAt(i).ElementAt(5) + ",";
  5355. mark2 = "," + memberarray.ElementAt(i).ElementAt(6) + ",";
  5356. if (atoi(point) == 0)continue;
  5357. if (phone.IsEmpty())continue;
  5358. if (-1 == CheckPhoneType(phone))continue;
  5359. int j = 0;
  5360. for (/*int*/ j = 0; j < rulearray.GetSize(); j++)
  5361. {
  5362. if (mark1.GetLength()>4000)break;
  5363. rulename = "," + rulearray.ElementAt(j).ElementAt(0) + ",";
  5364. rulecontent1 = name + rulearray.ElementAt(j).ElementAt(1);
  5365. rulecontent2 = name + rulearray.ElementAt(j).ElementAt(2);
  5366. rulecheck1 = rulearray.ElementAt(j).ElementAt(3);
  5367. rulecheck2 = rulearray.ElementAt(j).ElementAt(4);
  5368. rulepoint = rulearray.ElementAt(j).ElementAt(5);
  5369. if (atoi(rulecheck1) == 0 && atoi(rulecheck2) == 0)continue;
  5370. if (atoi(rulecheck1))
  5371. {
  5372. if (rulecontent1.IsEmpty())continue;
  5373. if (mark1.Find(rulename) != -1)break;
  5374. if (atoi(point) >= atoi(rulepoint))continue;
  5375. if (atoi(point) < atoi(rulepoint) * 80 / 100)continue;
  5376. // if(sex=="男")
  5377. // rulecontent1.Replace ("xxx先生/女士", name+"先生");
  5378. // else
  5379. // rulecontent1.Replace ("xxx先生/女士", name+"女士");
  5380. int count = GetLengthEx(rulecontent1) / MSG_LENGTH;
  5381. if (GetLengthEx(rulecontent1) % MSG_LENGTH)
  5382. count++;
  5383. int phonenum = 1;
  5384. count *= phonenum;
  5385. CString scount;
  5386. scount.Format("%d", count);
  5387. CString timestamp = CTime::GetCurrentTime().Format("%Y%m%d%H%M%S");
  5388. CString sql;
  5389. mark1.TrimLeft(",");
  5390. mark1.TrimRight(",");
  5391. if (mark1.IsEmpty() == 0)
  5392. mark1 += ",";
  5393. rulename.TrimLeft(",");
  5394. rulename.TrimRight(",");
  5395. mark1 += rulename;
  5396. sql = "update membermanage set sendmark1='" + mark1 + "' where memberno='" + memberno + "'";
  5397. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5398. mark1 = "," + mark1 + ",";
  5399. sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + phone + "','" + rulecontent1 + "','" + timestamp + "','" + scount + "','0','0','0','系统自动发送')";
  5400. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5401. }
  5402. }
  5403. ///////////////////
  5404. BOOL bSended = 0;
  5405. for (j = 0; j < rulearray.GetSize(); j++)
  5406. {
  5407. if (mark2.GetLength() > 4000)break;
  5408. if (bSended)break;
  5409. rulename = "," + rulearray.ElementAt(j).ElementAt(0) + ",";
  5410. rulecontent1 = name + rulearray.ElementAt(j).ElementAt(1);
  5411. rulecontent2 = name + rulearray.ElementAt(j).ElementAt(2);
  5412. rulecheck1 = rulearray.ElementAt(j).ElementAt(3);
  5413. rulecheck2 = rulearray.ElementAt(j).ElementAt(4);
  5414. rulepoint = rulearray.ElementAt(j).ElementAt(5);
  5415. if (atoi(rulecheck1) == 0 && atoi(rulecheck2) == 0)continue;
  5416. if (atoi(rulecheck2))
  5417. {
  5418. if (rulecontent2.IsEmpty())continue;
  5419. if (mark2.Find(rulename) != -1)break;
  5420. if (atoi(point) < atoi(rulepoint))continue;
  5421. // if(sex=="男")
  5422. // rulecontent2.Replace ("xxx先生/女士", name+"先生");
  5423. // else
  5424. // rulecontent2.Replace ("xxx先生/女士", name+"女士");
  5425. int count = GetLengthEx(rulecontent2) / MSG_LENGTH;
  5426. if (GetLengthEx(rulecontent2) % MSG_LENGTH)
  5427. count++;
  5428. int phonenum = 1;
  5429. count *= phonenum;
  5430. CString scount;
  5431. scount.Format("%d", count);
  5432. CString timestamp = CTime::GetCurrentTime().Format("%Y%m%d%H%M%S");
  5433. CString sql;
  5434. mark2.TrimLeft(",");
  5435. mark2.TrimRight(",");
  5436. if (mark2.IsEmpty() == 0)
  5437. mark2 += ",";
  5438. rulename.TrimLeft(",");
  5439. rulename.TrimRight(",");
  5440. mark2 += rulename;
  5441. sql = "update membermanage set sendmark2='" + mark2 + "' where memberno='" + memberno + "'";
  5442. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5443. mark2 = "," + mark2 + ",";
  5444. sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + phone + "','" + rulecontent2 + "','" + timestamp + "','" + scount + "','0','0','0','系统自动发送')";
  5445. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5446. bSended = 1;
  5447. }
  5448. }
  5449. }
  5450. }
  5451. catch (CDBException *e)
  5452. {
  5453. WriteTextLog(_T("%s-<%d>-%s,%s"), __FILE__, __LINE__, __FUNCTION__, e->m_strError);
  5454. #ifdef _DEBUG
  5455. e->ReportError();
  5456. #endif
  5457. e->Delete();
  5458. }
  5459. }
  5460. void CDBServerDlg::CheckBakState() // Jeff.检查数据库bakstate表;
  5461. {
  5462. try
  5463. {
  5464. CDatabase* pMaindb = NULL;
  5465. ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
  5466. if ( pMaindb == NULL )
  5467. return;
  5468. CString filter = _T("");
  5469. CArray<CStringArray, CStringArray> strArray;
  5470. CRecordset myset(pMaindb);
  5471. CString sql = "select count(*) as cot from bakstate";
  5472. if (!filter.IsEmpty())
  5473. sql += " where " + filter;
  5474. myset.Open(CRecordset::forwardOnly, sql);
  5475. myset.GetFieldValue("cot", sql);
  5476. myset.Close();
  5477. int count = atol(sql);
  5478. strArray.SetSize(count, 1);
  5479. //备份记录
  5480. CRstbakstate rsSt;
  5481. rsSt.m_pDatabase = pMaindb;
  5482. if (!filter.IsEmpty())
  5483. rsSt.m_strFilter = filter;
  5484. rsSt.Open();
  5485. int ii = 0;
  5486. while (!rsSt.IsEOF())
  5487. {
  5488. strArray.ElementAt(ii).RemoveAll();
  5489. strArray.ElementAt(ii).Add(rsSt.date);
  5490. strArray.ElementAt(ii).Add(rsSt.photo);
  5491. strArray.ElementAt(ii).Add(rsSt.info);
  5492. ii++;
  5493. rsSt.MoveNext();
  5494. if (strArray.GetSize() <= ii)
  5495. break;
  5496. }
  5497. rsSt.Close();
  5498. //只保存7天记录
  5499. strArray.SetSize(ii, 1);
  5500. while (strArray.GetSize() > 7)
  5501. {
  5502. CString sql = "delete from bakstate where [date]='" + strArray.ElementAt(0).ElementAt(0) + "'";
  5503. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5504. strArray.RemoveAt(0);
  5505. }
  5506. CString path = _T("");
  5507. path.Format("%s\\log.txt", g_mainpath);
  5508. if (::PathFileExists(path))
  5509. {
  5510. CString str;
  5511. CStdioFile fp;
  5512. if (fp.Open(path, CFile::modeRead))
  5513. {
  5514. CString temp;
  5515. fp.ReadString(temp);
  5516. CString date = temp;
  5517. date.TrimRight();
  5518. while(!feof(fp.m_pStream))
  5519. {
  5520. fp.ReadString(temp);
  5521. str += temp;
  5522. }
  5523. fp.Close();
  5524. if (date.GetLength() != 10)
  5525. return;
  5526. BOOL bBak = 0;
  5527. int i = 0;
  5528. for (int i = 0; i < strArray.GetSize(); i++)
  5529. {
  5530. if (date == strArray.ElementAt(i).ElementAt(0))
  5531. {
  5532. bBak = 1;
  5533. break;
  5534. }
  5535. }
  5536. if (bBak == 0)
  5537. {
  5538. CString state1 = "0";
  5539. CString state2 = "0";
  5540. if (str.Find("照片备份成功") != -1)state1 = "1";
  5541. if (str.Find("资料备份成功") != -1)state2 = "1";
  5542. sql = "insert into bakstate([date],[photo],[info])values('" + date + "','" + state1 + "','" + state2 + "')";
  5543. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5544. }
  5545. else
  5546. {
  5547. CString state1 = "0";
  5548. CString state2 = "0";
  5549. if (str.Find("照片备份成功") != -1)state1 = "1";
  5550. if (str.Find("资料备份成功") != -1)state2 = "1";
  5551. sql = "update bakstate set [photo]='" + state1 + "',[info]='" + state2 + "' where [date]='" + date + "'";
  5552. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5553. }
  5554. //判断昨天
  5555. CTime tm = CTime::GetCurrentTime();
  5556. CTimeSpan dt(1, 0, 0, 0);
  5557. tm -= dt;
  5558. CString yesterday = tm.Format("%Y-%m-%d");
  5559. for (i = 0; i < strArray.GetSize(); i++)
  5560. {
  5561. if (yesterday == strArray.ElementAt(i).ElementAt(0))return;
  5562. }
  5563. if (yesterday == date)return;
  5564. sql = "insert into bakstate([date],[photo],[info])values('" + yesterday + "','0','0')";
  5565. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5566. }
  5567. else
  5568. {
  5569. CTime tm = CTime::GetCurrentTime();
  5570. CTimeSpan dt(1, 0, 0, 0);
  5571. tm -= dt;
  5572. sql = "insert into bakstate([date],[photo],[info])values('" + tm.Format("%Y-%m-%d") + "','0','0')";
  5573. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5574. }
  5575. }
  5576. else
  5577. {
  5578. //昨天没备份,插入一条没有备份的记录
  5579. CTime tm = CTime::GetCurrentTime();
  5580. CTimeSpan dt(1, 0, 0, 0);
  5581. tm -= dt;
  5582. for (int i = 0; i < strArray.GetSize(); i++)
  5583. {
  5584. if (tm.Format("%Y-%m-%d") == strArray.ElementAt(i).ElementAt(0))
  5585. return;
  5586. }
  5587. sql = "insert into bakstate([date],[photo],[info])values('" + tm.Format("%Y-%m-%d") + "','0','0')";
  5588. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5589. }
  5590. }
  5591. catch (...)
  5592. {
  5593. WriteTextLog("出错3");
  5594. }
  5595. }
  5596. //数据备份
  5597. CString CDBServerDlg::GetRegCode(int m_id, int m_time1, int m_time2)
  5598. {
  5599. TCHAR DevicePath[260];
  5600. if (FindPort(0, DevicePath) != 0)
  5601. return "";
  5602. int version;
  5603. GetIDVersion((DWORD*)&m_id, &version, DevicePath);
  5604. int d[8]; double f[8];
  5605. int idtemp = 123456;
  5606. char s0[50] = "", s1[50] = "", s2[50] = "", s3[50] = "", s4[50] = "", s5[50] = "", s6[50] = "", s7[50] = "";
  5607. //运行自定义函数
  5608. // SoftKey ytSoftKey;
  5609. int ret = 0;//ytSoftKey.Ini();
  5610. if (ret != 0)
  5611. {
  5612. return "";
  5613. }
  5614. //////////////////////////////////////////////////////////////////////////
  5615. // timedog1是对d0,d1,d2,d3进行3DES加密;
  5616. // 对锁id加密;
  5617. // 对123456加密;
  5618. // 对m_time1可运行时间加密;
  5619. // 对m_time2已运行时间加密;
  5620. ret = ytSoftKey.timedog1(&m_id, &idtemp, &m_time1, &m_time2, &d[4], &d[5], &d[6], &d[7],
  5621. &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
  5622. s0, s1, s2, s3, s4, s5, s6, s7);
  5623. if (ret != 0 && ret != -43)
  5624. {
  5625. return "";
  5626. }
  5627. CString str = "";
  5628. CString temp, temp2;
  5629. /////////////////////////////////////////
  5630. temp.Format("%d", abs(m_id));
  5631. int leng = temp.GetLength();
  5632. if (m_id < 0)
  5633. temp2 = "1";
  5634. else
  5635. temp2 = "0";
  5636. temp = temp2 + temp;
  5637. temp2.Format("%02d", leng);
  5638. temp = temp2 + temp;
  5639. str += temp;
  5640. //////////////////////////////////两位长度, 1为负, 0为正, 数据区
  5641. temp.Format("%d", abs(m_time1));
  5642. leng = temp.GetLength();
  5643. if (m_time1 < 0)
  5644. temp2 = "1";
  5645. else
  5646. temp2 = "0";
  5647. temp = temp2 + temp;
  5648. temp2.Format("%02d", leng);
  5649. temp = temp2 + temp;
  5650. str += temp;
  5651. //////////////////////////////////两位长度, 1为负, 0为正, 数据区
  5652. temp.Format("%d", abs(m_time2));
  5653. leng = temp.GetLength();
  5654. if (m_time2 < 0)
  5655. temp2 = "1";
  5656. else
  5657. temp2 = "0";
  5658. temp = temp2 + temp;
  5659. temp2.Format("%02d", leng);
  5660. temp = temp2 + temp;
  5661. str += temp;
  5662. //////////////////////////////////两位长度, 1为负, 0为正, 数据区
  5663. temp.Format("%d", abs(idtemp));
  5664. leng = temp.GetLength();
  5665. if (idtemp < 0)
  5666. temp2 = "1";
  5667. else
  5668. temp2 = "0";
  5669. temp = temp2 + temp;
  5670. temp2.Format("%02d", leng);
  5671. temp = temp2 + temp;
  5672. str += temp;
  5673. return str;
  5674. }
  5675. int g_ndogtimes = 0;
  5676. void CDBServerDlg::CheckRegCode() // 检查注册码信息;
  5677. {
  5678. char path[MAX_PATH];
  5679. ::GetSystemDirectory(path, MAX_PATH);
  5680. CString sysdir = path;
  5681. sysdir += "\\authcode.txt";
  5682. CStdioFile fp;
  5683. CString authcode;
  5684. if (fp.Open(sysdir, CFile::modeRead))
  5685. {
  5686. fp.ReadString(authcode);
  5687. fp.Close();
  5688. }
  5689. ::DeleteFile(sysdir); // 删除authcode.txt文件;
  5690. authcode.TrimLeft();
  5691. authcode.TrimRight();
  5692. authcode.Replace("\n", "");
  5693. authcode.Replace("\r", "");
  5694. if (authcode.GetLength() != 240)
  5695. {
  5696. return;
  5697. }
  5698. TCHAR DevicePath[260];
  5699. if (FindPort(0, DevicePath) != 0)
  5700. return;
  5701. DWORD OutID;
  5702. int version;
  5703. GetIDVersion(&OutID, &version, DevicePath);
  5704. CString str1, str2, str3, str4, str5;
  5705. str1 = authcode.Mid(0, 48);
  5706. str2 = authcode.Mid(48, 48);
  5707. str3 = authcode.Mid(96, 48);
  5708. str4 = authcode.Mid(144, 48);
  5709. str5 = authcode.Mid(192, 48);
  5710. // SoftKey ytSoftKey;
  5711. int ret = 0;//ytSoftKey.Ini();
  5712. if (ret != 0)
  5713. {
  5714. return;
  5715. }
  5716. int d[8]; double f[8];
  5717. char s0[50] = "", s1[50] = "", s2[50] = "", s3[50] = "", s4[50] = "", s5[50] = "", s6[50] = "", s7[50] = "";
  5718. //运行自定义函数
  5719. sprintf(s0, "%s", str1);
  5720. sprintf(s1, "%s", str2);
  5721. sprintf(s2, "%s", str3);
  5722. sprintf(s3, "%s", str4);
  5723. sprintf(s4, "%s", str5);
  5724. //运行自定义函数
  5725. ret = ytSoftKey.timedog2(&d[0], &d[1], &d[2], &d[3], &d[4], &d[5], &d[6], &d[7],
  5726. &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
  5727. s0, s1, s2, s3, s4, s5, s6, s7);
  5728. if (ret != 0 && ret != -43)
  5729. {
  5730. return;
  5731. }
  5732. str1 = s0;
  5733. str2 = s1;
  5734. str3 = s2;
  5735. str4 = s3;
  5736. str5 = s4;
  5737. authcode = str1;
  5738. authcode += str2;
  5739. authcode += str3;
  5740. authcode += str4;
  5741. authcode += str5;
  5742. str1 += str2;
  5743. str3 += str4;
  5744. DWORD id = atoi(str5.Right(8));
  5745. str5 = str5.Left(12);
  5746. if (id != OutID)
  5747. {
  5748. return;
  5749. }
  5750. TCHAR HKey[50] = "ffffffff", LKey[50] = "ffffffff";
  5751. TCHAR WHKey[41] = "0", WLKey[41] = "0";
  5752. TCHAR year[10], month[10], day[10], hour[10], minute[10], second[10];
  5753. sprintf(WHKey, "%s", str1);
  5754. sprintf(WLKey, "%s", str3);
  5755. CString temp;
  5756. temp = str5.Left(4);
  5757. str5 = str5.Right(8);
  5758. sprintf(year, "%s", temp);
  5759. temp = str5.Left(2);
  5760. str5 = str5.Right(6);
  5761. sprintf(month, "%s", temp);
  5762. temp = str5.Left(2);
  5763. str5 = str5.Right(4);
  5764. sprintf(day, "%s", temp);
  5765. temp = str5.Left(2);
  5766. str5 = str5.Right(2);
  5767. sprintf(hour, "%s", temp);
  5768. sprintf(minute, "%s", str5);
  5769. sprintf(second, "%s", "0");
  5770. ret = WriteTimeAuthToEprom(30128, HKey, LKey, WHKey, WLKey, id, year, month, day, hour, minute, DevicePath);
  5771. if (ret == 0)
  5772. {
  5773. TCHAR year2[10], month2[10], day2[10], hour2[10], minute2[10], second2[10];
  5774. GetRunTimer(year2, month2, day2, hour2, minute2, second2, DevicePath);
  5775. DWORD time1, time2;
  5776. time1 = ConvertStringToTimerReal(year, month, day, hour, minute, second);
  5777. sprintf(second2, "%s", "0");
  5778. time2 = ConvertStringToTimerReal(year2, month2, day2, hour2, minute2, second2);
  5779. if (time1 > time2)
  5780. ConvertTimerToStringReal(time1 - time2, year, month, day, hour, minute, second);
  5781. else
  5782. {
  5783. sprintf(year, "%s", "0");
  5784. sprintf(month, "%s", "0");
  5785. sprintf(day, "%s", "0");
  5786. sprintf(hour, "%s", "0");
  5787. sprintf(minute, "%s", "0");
  5788. }
  5789. g_ndogtimes++;
  5790. // str1.Format ("写入%d次 %d 年 %d 月 %d 日 %d 小时 %d 分", g_ndogtimes, atoi(year), atoi(month), atoi(day), atoi(hour), atoi(minute));
  5791. // WriteTextLog(str1);
  5792. // AfxMessageBox((str1));
  5793. }
  5794. else
  5795. {
  5796. // AfxMessageBox(("授权申请码错误, 请重新向经销商索取!"));
  5797. return;
  5798. }
  5799. }
  5800. BOOL IsCtrlDown()
  5801. {
  5802. short state = GetKeyState(VK_LCONTROL);
  5803. BYTE sta = (BYTE)(state >> 8);
  5804. state = GetKeyState(VK_RCONTROL);
  5805. BYTE sta2 = (BYTE)(state >> 8);
  5806. if (sta || sta2)
  5807. return 1;
  5808. else
  5809. return 0;
  5810. }
  5811. //extern CTime GetTmFromStr(CString date);
  5812. BOOL CDBServerDlg::PreTranslateMessage(MSG* pMsg)
  5813. {
  5814. if (pMsg->message == WM_KEYDOWN)
  5815. {
  5816. switch (pMsg->wParam)
  5817. {
  5818. case 67:
  5819. AfxMessageBox("c");
  5820. break;
  5821. case VK_F8:
  5822. if (IsCtrlDown())GenYLGL();
  5823. break;
  5824. case VK_F9:
  5825. if (IsCtrlDown())
  5826. {
  5827. CString g_domain;
  5828. CArray<CStringArray, CStringArray>g_List1array;
  5829. CString autorunpath = g_mainpath + "\\branchdindan.dat";
  5830. CFile fp;
  5831. if (fp.Open(autorunpath, CFile::modeRead))
  5832. {
  5833. int nMessageLen = fp.GetLength();
  5834. BYTE *pData = new BYTE[nMessageLen];
  5835. fp.Read(pData, nMessageLen);
  5836. fp.Close();
  5837. BYTE *szChatMessage = pData;
  5838. int count;
  5839. memcpy(&count, szChatMessage + (nMessageLen - sizeof(int)), sizeof(int));
  5840. CMemFile memfile;
  5841. memfile.Attach(szChatMessage, nMessageLen);
  5842. CArchive ar(&memfile, CArchive::load);
  5843. g_List1array.SetSize(count);
  5844. for (int ii = 0; ii < g_List1array.GetSize(); ii++)
  5845. {
  5846. g_List1array.ElementAt(ii).Serialize(ar);
  5847. }
  5848. ar.Close();
  5849. memfile.Detach();
  5850. delete[]pData;
  5851. }
  5852. CString time5, id;
  5853. for (int i = 0; i < g_List1array.GetSize(); i++)
  5854. {
  5855. g_domain = "\\" + g_List1array.ElementAt(i).ElementAt(0);
  5856. id = g_List1array.ElementAt(i).ElementAt(1);
  5857. time5 = g_List1array.ElementAt(i).ElementAt(2);
  5858. WriteTextLog(g_domain + "\\" + id + time5);
  5859. }
  5860. }
  5861. break;
  5862. #ifdef LYFZ_VERSION
  5863. case VK_F7:
  5864. if (IsCtrlDown())
  5865. {
  5866. if (AfxMessageBox("是否继续?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return 1;
  5867. CStringArray array1;
  5868. CRstDindanForm rsSt; rsSt.m_pDatabase = &g_db;
  5869. rsSt.Open();
  5870. while (!rsSt.IsEOF())
  5871. {
  5872. array1.Add(rsSt.id);
  5873. rsSt.MoveNext();
  5874. }
  5875. rsSt.Close();
  5876. CString id, sql;
  5877. sql.Format("update dindan set status5='%s'", "无");
  5878. MyExecuteSQL(&g_db, sql);
  5879. BOOL bHasPhoto = 0;
  5880. for (int i = 0; i < array1.GetSize(); i++)
  5881. {
  5882. id = array1.ElementAt(i);
  5883. bHasPhoto = 0;
  5884. CRstClientPhoto rsSt;
  5885. rsSt.m_strFilter = "id='" + id + "'";
  5886. rsSt.Open();
  5887. if (rsSt.photo.m_dwDataLength>0)
  5888. {
  5889. bHasPhoto = 1;
  5890. }
  5891. rsSt.Close();
  5892. if (bHasPhoto)
  5893. {
  5894. sql.Format("update dindan set status5='%s' where id='%s'", "有", id);
  5895. MyExecuteSQL(&g_db, sql);
  5896. }
  5897. }
  5898. /* CStringArray array1,array2;
  5899. CRstDindanForm rsSt; rsSt.m_pDatabase=&g_db;
  5900. rsSt.Open();
  5901. while(!rsSt.IsEOF())
  5902. {
  5903. array1.Add(rsSt.id) ;
  5904. array2.Add(rsSt.time4) ;
  5905. rsSt.MoveNext();
  5906. }
  5907. rsSt.Close();
  5908. CString id,time4,time2,sql;
  5909. for(int i=0; i<array1.GetSize(); i++)
  5910. {
  5911. id=array1.ElementAt(i);
  5912. time4=array2.ElementAt(i);
  5913. if(time4.GetLength()==10)
  5914. {
  5915. CTime tm=GetTmFromStr(time4);
  5916. CTimeSpan dt(365, 0, 0, 0);
  5917. CTime tm2=tm-dt;
  5918. time2=tm2.Format("%Y-%m-%d");
  5919. sql.Format("update dindan set time2='%s' where id='%s'", time2, id);
  5920. MyExecuteSQL(&g_db, sql);
  5921. }
  5922. }*/
  5923. AfxMessageBox("完成");
  5924. }
  5925. break;
  5926. #endif //#ifdef LYFZ_VERSION
  5927. case VK_F2:
  5928. if (IsCtrlDown())
  5929. {
  5930. SelYear dlg;
  5931. if (dlg.DoModal() != IDOK)return 1;
  5932. int year = dlg.m_year;
  5933. int hisyear = CTime::GetCurrentTime().GetYear() - 1;
  5934. if (year == hisyear)
  5935. {
  5936. AfxMessageBox("不能选该年");
  5937. return 1;
  5938. }
  5939. CString str;
  5940. str.Format("此操作将%d年数据导入%d中, 确认吗?", year, hisyear);
  5941. if (AfxMessageBox(str, MB_YESNO | MB_ICONINFORMATION) != IDYES)return 1;
  5942. CDatabase *pdb = GetDB(year);
  5943. if (pdb == NULL)
  5944. {
  5945. str.Format("没有找到%d, 操作失败", year);
  5946. AfxMessageBox(str); return 1;
  5947. }
  5948. str.Format("开始%d->%d", year, hisyear);
  5949. WriteTextLog(str);
  5950. CheckHistoryData(pdb, year);
  5951. str.Format("%d->%d完成", year, hisyear);
  5952. WriteTextLog(str);
  5953. }
  5954. break;
  5955. case VK_F3:
  5956. if (IsCtrlDown())
  5957. {
  5958. SelYear dlg;
  5959. if (dlg.DoModal() != IDOK)return 1;
  5960. int year = dlg.m_year;
  5961. int hisyear = CTime::GetCurrentTime().GetYear() - 1;
  5962. if (year == hisyear)
  5963. {
  5964. AfxMessageBox("不能选该年");
  5965. return 1;
  5966. }
  5967. CString str;
  5968. str.Format("此操作将%d年数据导入%d中(当前数据库中没有的订单全转), 确认吗?", year, hisyear);
  5969. if (AfxMessageBox(str, MB_YESNO | MB_ICONINFORMATION) != IDYES)return 1;
  5970. CDatabase *pdb = GetDB(year);
  5971. if (pdb == NULL)
  5972. {
  5973. str.Format("没有找到%d, 操作失败", year);
  5974. AfxMessageBox(str); return 1;
  5975. }
  5976. str.Format("开始%d->%d", year, hisyear);
  5977. WriteTextLog(str);
  5978. CheckHistoryData(pdb, year, 1);
  5979. str.Format("%d->%d完成", year, hisyear);
  5980. WriteTextLog(str);
  5981. }
  5982. break;
  5983. case VK_F1:
  5984. CString str;
  5985. if (g_conniparray.GetSize() == 0)str = "当前无客户端连接至服务器!";
  5986. for (int i = 0; i < g_conniparray.GetSize(); i++)
  5987. {
  5988. str += "\r\n连接ip:" + g_conniparray.ElementAt(i);
  5989. }
  5990. AfxMessageBox(str);
  5991. #ifdef CONNCOUNT_VERSION
  5992. // CStringArray g_conniparray;
  5993. #endif //#ifdef CONNCOUNT_VERSION
  5994. return 1;
  5995. }
  5996. }
  5997. return CDialog::PreTranslateMessage(pMsg);
  5998. }
  5999. void CDBServerDlg::GenUPhoneData()
  6000. {
  6001. MyLock lock("processChatMessageRequestxiao");
  6002. CArray<int, int>codearray;
  6003. codearray.Add(80);
  6004. codearray.Add(90);
  6005. codearray.Add(11);
  6006. codearray.Add(138);
  6007. codearray.Add(24);
  6008. codearray.Add(181);
  6009. codearray.Add(65);
  6010. codearray.Add(56);
  6011. codearray.Add(179);
  6012. codearray.Add(53);
  6013. CFile fp;
  6014. CString savepath, g_path1;
  6015. char server[50];
  6016. DWORD leng = 50;
  6017. ::GetComputerName(server, &leng);
  6018. g_path1 = server;
  6019. g_path1 = "\\\\" + g_path1 + "\\电话录音(管理软件)$";
  6020. GetPathFromNetShareName("电话录音(管理软件)$", g_path1);
  6021. if (g_path1.IsEmpty())
  6022. {
  6023. WriteTextLog("获取电精灵数据出错");
  6024. return;
  6025. }
  6026. try
  6027. {
  6028. int aa = 0;
  6029. CDatabase *pMaindb = NULL;
  6030. ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
  6031. if ( pMaindb == NULL )
  6032. return;
  6033. savepath.Format("%s\\uphonedata%d.dat", g_path1, aa);
  6034. ::DeleteFile(savepath); // 删除 uphonedata%d.dat 文件;
  6035. if (fp.Open(savepath, CFile::modeCreate | CFile::modeWrite) == 0)
  6036. {
  6037. WriteTextLog("更新来电精灵数据出错");
  6038. return;
  6039. }
  6040. CConnectSocket consock;
  6041. consock.m_pConndb = pMaindb;
  6042. for (int i = 0; i < codearray.GetSize(); i++)
  6043. {
  6044. BYTE code = codearray.ElementAt(i);
  6045. DWORD length, arraysize;
  6046. BYTE *pReturn = NULL;
  6047. consock.GetDataFromCode(code, &pReturn, length, arraysize, "");
  6048. fp.Write(&code, sizeof(BYTE));
  6049. fp.Write(&length, sizeof(DWORD));
  6050. fp.Write(&arraysize, sizeof(DWORD));
  6051. fp.Write(pReturn, length);
  6052. }
  6053. fp.Close();
  6054. }
  6055. catch (...)
  6056. {
  6057. WriteTextLog("获取来电精灵数据出错2");
  6058. }
  6059. }
  6060. //initlia
  6061. void CDBServerDlg::LoadHistoryDB() // 加载历史数据库;
  6062. {
  6063. CString path;
  6064. CString sql;
  6065. sql = "delete from historydb";
  6066. CDatabase *pdb = NULL;
  6067. ODBCConnGuard ConnGuard(pdb, -1, 3000);
  6068. if ( pdb ) MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pdb, sql);
  6069. CDatabase g_masterdb;
  6070. try
  6071. {
  6072. CString strCon;
  6073. strCon.Format(DB_SS_CONN_WITHOUT_PORT, g_strdbServrename, _T("master"), g_szDBAccount, g_szDBPassWord);
  6074. g_masterdb.OpenEx(strCon, CDatabase::noOdbcDialog);
  6075. }
  6076. catch (CDBException * e)
  6077. {
  6078. #ifdef _DEBUG
  6079. e->ReportError();
  6080. #endif //#ifdef _DEBUG
  6081. e->Delete();
  6082. }
  6083. TCHAR szdbName[MAX_PATH] = {0};
  6084. for (int i = CTime::GetCurrentTime().GetYear() - 1; i >= 2009; i--)
  6085. {
  6086. #if USE_POOL
  6087. _itot_s(i, szdbName, 10);
  6088. CODBCPool *pdbpool = new CODBCPool;
  6089. if ( pdbpool->InitializePool(g_szDBSource, g_dwDBServerPort, g_szDBAccount, g_szDBPassWord, szdbName, g_dwDBPoolDef, g_dwDBPoolMaxCount))
  6090. {
  6091. g_nYearArray.Add(i);
  6092. sql.Format("insert into [historydb]([year])values('%d')", i);
  6093. CDatabase *pdb = NULL;
  6094. ODBCConnGuard ConnGuard(pdb, -1, 3000);
  6095. if ( pdb )MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pdb, sql);
  6096. g_dbpool.Add(pdbpool);
  6097. }
  6098. else
  6099. {
  6100. delete pdbpool;
  6101. pdbpool = NULL;
  6102. CString strPathOfYearmdf;
  6103. CString strPathOfYearldf;
  6104. CString sql;
  6105. strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, i);
  6106. strPathOfYearldf.Format("%s\\数据\\%d_log.LDF", g_mainpath, i);
  6107. if (PathFileExists(strPathOfYearmdf))
  6108. {
  6109. BOOL bLog = 0;
  6110. if (PathFileExists(strPathOfYearldf))
  6111. {
  6112. bLog = 1;
  6113. }
  6114. g_masterdb.SetQueryTimeout(600);
  6115. if (bLog)
  6116. sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", i, strPathOfYearmdf, strPathOfYearldf);
  6117. else
  6118. sql.Format("exec sp_attach_db '%d',@filename1='%s'", i, strPathOfYearmdf);
  6119. try
  6120. {
  6121. g_masterdb.ExecuteSQL(sql);
  6122. }
  6123. catch (CDBException * e)
  6124. {
  6125. WriteTextLog("历史数据库初始化失败,%s",e->m_strError);
  6126. g_masterdb.SetQueryTimeout(100);
  6127. #ifdef _DEBUG
  6128. e->ReportError();
  6129. #endif //#ifdef _DEBUG
  6130. e->Delete();
  6131. break;
  6132. }
  6133. g_masterdb.SetQueryTimeout(100);
  6134. if ( pdbpool->InitializePool(g_szDBSource, g_dwDBServerPort, g_szDBAccount, g_szDBPassWord, szdbName, g_dwDBPoolDef, g_dwDBPoolMaxCount))
  6135. {
  6136. g_nYearArray.Add(i);
  6137. sql.Format("insert into [historydb]([year])values('%d')", i);
  6138. CDatabase *pdb = NULL;
  6139. ODBCConnGuard ConnGuard(pdb, -1, 3000);
  6140. if ( pdb )MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pdb, sql);
  6141. g_dbpool.Add(pdbpool);
  6142. }
  6143. else
  6144. {
  6145. delete pdbpool;
  6146. }
  6147. }
  6148. }
  6149. #else
  6150. CDatabase *db = new CDatabase;
  6151. try
  6152. {
  6153. CString strCon;
  6154. //strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=%d;%s"), g_strdbServrename, i, g_strdbpsw);
  6155. if ( _tcscmp(g_szDBAccount, _T("")) == 0)
  6156. strCon.Format(DB_SW_CONN_WITHOUT_PORT2, g_strdbServrename, i);
  6157. else
  6158. strCon.Format(DB_SS_CONN_WITHOUT_PORT2, g_strdbServrename, i, g_szDBAccount, g_szDBPassWord);
  6159. db->OpenEx(strCon, CDatabase::noOdbcDialog);
  6160. g_nYearArray.Add(i);
  6161. g_dbHistoryArray.Add(db);
  6162. sql.Format("insert into [historydb]([year])values('%d')", i);
  6163. MyExecuteSQL(&g_db, sql);
  6164. }
  6165. catch (CDBException * e)
  6166. {
  6167. #ifdef _DEBUG
  6168. e->ReportError();
  6169. #endif //#ifdef _DEBUG
  6170. CString strPathOfYearmdf;
  6171. CString strPathOfYearldf;
  6172. CString sql;
  6173. strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, i);
  6174. strPathOfYearldf.Format("%s\\数据\\%d_log.LDF", g_mainpath, i);
  6175. if (PathFileExists(strPathOfYearmdf))
  6176. {
  6177. BOOL bLog = 0;
  6178. if (PathFileExists(strPathOfYearldf))
  6179. {
  6180. bLog = 1;
  6181. }
  6182. g_masterdb.SetQueryTimeout(600);
  6183. if (bLog)
  6184. sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", i, strPathOfYearmdf, strPathOfYearldf);
  6185. else
  6186. sql.Format("exec sp_attach_db '%d',@filename1='%s'", i, strPathOfYearmdf);
  6187. try
  6188. {
  6189. g_masterdb.ExecuteSQL(sql);
  6190. }
  6191. catch (CDBException * e)
  6192. {
  6193. WriteTextLog(e->m_strError);
  6194. WriteTextLog("历史数据库初始化失败!!");
  6195. g_masterdb.SetQueryTimeout(100);
  6196. #ifdef _DEBUG
  6197. e->ReportError();
  6198. #endif //#ifdef _DEBUG
  6199. e->Delete();
  6200. break;
  6201. }
  6202. g_masterdb.SetQueryTimeout(100);
  6203. CString strCon;
  6204. //strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=%d;%s"), g_strdbServrename, i, g_strdbpsw);
  6205. if ( _tcscmp(g_szDBAccount, _T("")) == 0)
  6206. strCon.Format(DB_SW_CONN_WITHOUT_PORT2, g_strdbServrename, i);
  6207. else
  6208. strCon.Format(DB_SS_CONN_WITHOUT_PORT2, g_strdbServrename, i, g_szDBAccount, g_szDBPassWord);
  6209. db->OpenEx(strCon, CDatabase::noOdbcDialog);
  6210. g_nYearArray.Add(i);
  6211. g_dbHistoryArray.Add(db);
  6212. sql.Format("insert into [historydb]([year])values('%d')", i);
  6213. MyExecuteSQL(&g_db, sql);
  6214. }
  6215. else
  6216. {
  6217. //e->ReportError();
  6218. e->Delete();
  6219. //break;
  6220. }
  6221. }
  6222. #endif
  6223. }
  6224. g_masterdb.Close();
  6225. }
  6226. void CDBServerDlg::AddOneConn()
  6227. {
  6228. #if 0
  6229. try
  6230. {
  6231. MyLock lock("AddOneConnxiao");
  6232. if (g_nDBCount >= 200)
  6233. {
  6234. WriteTextLog("连接超数!"); return;
  6235. }
  6236. CDatabase *db = new CDatabase;
  6237. //if(AddConn(db, "db")==0)// Jeff.deal;
  6238. if (AddConn(db, g_szDBName) == 0)
  6239. return;
  6240. g_pDB[g_nDBCount] = db;
  6241. CString dbname = _T("");
  6242. for (int i = 0; i < g_nYearArray.GetSize(); i++)
  6243. {
  6244. dbname.Format("%d", g_nYearArray.ElementAt(i));
  6245. CDatabase *db = new CDatabase;
  6246. AddConn(db, dbname);
  6247. g_pHistoryDBarray[g_nDBCount].Add(db);
  6248. }
  6249. AddAdoConn();
  6250. g_nDBCount++;
  6251. }
  6252. catch (CException *e)
  6253. {
  6254. TCHAR szError[1024] = { 0 };
  6255. e->GetErrorMessage(szError, 1024);
  6256. WriteTextLog("AddOneConn error" + CString(szError));
  6257. }
  6258. #endif
  6259. }
  6260. /////////////////////////////////////////////////////////////////////////////////////
  6261. /*
  6262. 函数名: AddAdoConn
  6263. 说明: 添加Logdb数据库连接
  6264. 参数:
  6265. 返回:
  6266. */
  6267. /////////////////////////////////////////////////////////////////////////////////////
  6268. void CDBServerDlg::AddAdoConn()
  6269. {
  6270. }
  6271. void GetOneConn(CDatabase **m_pdb, CArray<CDatabase*, CDatabase*>*m_dbarray, CConnectThread *pThread)
  6272. {
  6273. #if 0
  6274. MyLock lock("GetOneConnxiao");
  6275. ll: for (int i = 0; i < 200; i++)
  6276. {
  6277. if (g_pDB[i] != NULL && g_pThreadPt[i] == NULL)
  6278. {
  6279. *m_pdb = g_pDB[i];
  6280. m_dbarray->Copy(g_pHistoryDBarray[i]);
  6281. g_pThreadPt[i] = pThread;
  6282. return;
  6283. }
  6284. }
  6285. if (g_nDBCount >= 200)
  6286. {
  6287. WriteTextLog("连接超数2!");
  6288. *m_pdb = &g_db;
  6289. m_dbarray->Copy(g_dbHistoryArray);
  6290. return;
  6291. }
  6292. g_pMainWnd->AddOneConn();
  6293. ::Sleep(1000);
  6294. goto ll;
  6295. #endif
  6296. }
  6297. void CDBServerDlg::CheckConnCount()
  6298. {
  6299. int count = 0;
  6300. for (int i = 0; i < 200; i++)
  6301. {
  6302. if (g_pDB[i] != NULL && g_pThreadPt[i] == NULL)
  6303. {
  6304. count++;
  6305. if (count > 9)
  6306. return;
  6307. }
  6308. }
  6309. AddOneConn();
  6310. }
  6311. //delete from 背景.jpg
  6312. void CDBServerDlg::RestoreHQ()
  6313. {
  6314. CString sql;
  6315. CDatabase *pMaindb = NULL;
  6316. ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
  6317. if ( pMaindb == NULL )
  6318. return;
  6319. DWORD ii = 0;
  6320. CArray<CStringArray, CStringArray>g_List1array;
  6321. {
  6322. CRecordset myset(pMaindb);
  6323. CString sql = "select count(*) as cot from dindan";
  6324. myset.Open(CRecordset::forwardOnly, sql);
  6325. myset.GetFieldValue("cot", sql);
  6326. myset.Close();
  6327. int count = atol(sql);
  6328. g_List1array.SetSize(count, 1);
  6329. CRstDindanForm rsSt;
  6330. rsSt.m_pDatabase = pMaindb;
  6331. rsSt.Open();
  6332. ii = 0;
  6333. while (!rsSt.IsEOF())
  6334. {
  6335. g_List1array.ElementAt(ii).RemoveAll();
  6336. g_List1array.ElementAt(ii).Add(rsSt.id);
  6337. ii++;
  6338. rsSt.MoveNext(); if (g_List1array.GetSize() <= ii)break;
  6339. }
  6340. rsSt.Close(); g_List1array.SetSize(ii, 1);
  6341. }
  6342. for (int i = 0; i < g_List1array.GetSize(); i++)
  6343. {
  6344. // int ret=TransDinDan(pdb1, pdb2, g_List1array.ElementAt (i).ElementAt (0), lastyear);
  6345. // Jeff.deal;
  6346. //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));
  6347. 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));
  6348. CRecordset myset(pMaindb);
  6349. myset.Open(CRecordset::forwardOnly, sql);
  6350. CStringArray namearray;
  6351. CStringArray countarray;
  6352. while (!myset.IsEOF())
  6353. {
  6354. sql = "";
  6355. myset.GetFieldValue("name", sql);
  6356. namearray.Add(sql);
  6357. sql = "";
  6358. myset.GetFieldValue("count", sql);
  6359. countarray.Add(sql);
  6360. myset.MoveNext();
  6361. }
  6362. myset.Close();
  6363. for (int j = 0; j < namearray.GetSize(); j++)
  6364. {
  6365. CString spid, spjiage2;
  6366. // WriteTextLog("name:"+namearray.ElementAt (j));
  6367. // Jeff.deal;
  6368. //sql.Format("SELECT [spid],[spjiage2] FROM [db].[dbo].[shangpin] where spname='%s'", namearray.ElementAt (j));
  6369. sql.Format("SELECT [spid],[spjiage2] FROM [dbo].[shangpin] where spname='%s'", namearray.ElementAt(j));
  6370. //WriteTextLog(sql);
  6371. CRecordset myset(pMaindb);
  6372. myset.Open(CRecordset::forwardOnly, sql);
  6373. if (!myset.IsEOF())
  6374. {
  6375. myset.GetFieldValue("spid", spid);
  6376. myset.GetFieldValue("spjiage2", spjiage2);
  6377. }
  6378. myset.Close();
  6379. // Jeff.deal;
  6380. //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));
  6381. 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));
  6382. myset.Open(CRecordset::forwardOnly, sql);
  6383. sql = "";
  6384. if (!myset.IsEOF())
  6385. {
  6386. myset.GetFieldValue("cot", sql);
  6387. }
  6388. myset.Close();
  6389. if (atoi(sql))continue;
  6390. sql.Format("insert into [dindansp]([id],[name],[shuliang],[price],[spid],[kind])values('%s','%s','%s','%s','%s','%s')",
  6391. g_List1array.ElementAt(i).ElementAt(0), namearray.ElementAt(j), countarray.ElementAt(j), spjiage2, spid, "2");
  6392. //WriteTextLog(sql);
  6393. pMaindb->ExecuteSQL(sql);
  6394. }
  6395. }
  6396. }
  6397. void CDBServerDlg::ManagePhoto()
  6398. {
  6399. // CClientCenter dlg1;
  6400. // dlg1.DoModal ();
  6401. ShowPic3 dlg;
  6402. dlg.DoModal();
  6403. }
  6404. //数据备份(管理软件)$
  6405. //10.lia
  6406. //----------------------------------------------------------------------------
  6407. // Remark by Jeff 2014.10.22
  6408. // 函数:GenYLGL
  6409. // 描述:调用本地客户端;
  6410. // 参数:#
  6411. // 返回:#
  6412. //
  6413. // 调用关系:
  6414. // 1.只由AutoDelPhoto()主动调用。
  6415. //
  6416. // 说明:传递genbranchdata给客户端,使客户端能够自动遍历branchinfo.dat里的分店信息,
  6417. // 客户端顺序连接所有分店并获取分店历史订单已完成取件的订单。最终将所有分店历史
  6418. // 订单已完成取件的送回服务端,保存在branchdindan2.dat中.
  6419. //----------------------------------------------------------------------------
  6420. void CDBServerDlg::GenYLGL()
  6421. {
  6422. // 1.Jeff.删除文件,g_mainpath服务器DBServer.exe的目录;
  6423. CString autorunpath = g_mainpath + "\\YLGL.exe";
  6424. ::DeleteFile(autorunpath); // 删除YLGL.exe
  6425. WriteTextLog("命令行启动:" + autorunpath);
  6426. // 2.重新生成YLGL.exe
  6427. CDatabase *pdb = NULL;
  6428. ODBCConnGuard ConnGuard(pdb, -1, 3000);
  6429. if ( pdb = NULL )
  6430. return;
  6431. CRstUpdate rsSt;
  6432. rsSt.m_pDatabase = pdb;
  6433. rsSt.Open();
  6434. if (!rsSt.IsEOF())
  6435. {
  6436. CFile fp;
  6437. if (fp.Open(autorunpath, CFile::modeCreate | CFile::modeWrite))
  6438. {
  6439. void *pData = GlobalLock(rsSt.data.m_hData);
  6440. fp.Write(pData, rsSt.data.m_dwDataLength);
  6441. fp.Close();
  6442. GlobalUnlock(rsSt.data.m_hData);
  6443. }
  6444. }
  6445. rsSt.Close();
  6446. // 3.执行YLGL.exe
  6447. ShellExecute(NULL, _T("open"), autorunpath, "genbranchdata", NULL, SW_HIDE);
  6448. }
  6449. //105
  6450. /************************************************************************/
  6451. /*
  6452. 函数:CheckSvcWork
  6453. 描述:检查服务工作
  6454. 参数:
  6455. LPVOID LPARAM
  6456. 返回:
  6457. */
  6458. /************************************************************************/
  6459. unsigned int CDBServerDlg::CheckSvcWork(LPVOID LPARAM)
  6460. {
  6461. CDBServerDlg* p = (CDBServerDlg*)LPARAM;
  6462. if(p != NULL)
  6463. {
  6464. while(1)
  6465. {
  6466. // 每小时检查一次
  6467. int nRet = WaitForSingleObject(p->m_hWaitTimeOut, 60*60*1000);
  6468. if(nRet != WAIT_OBJECT_0 && nRet != WAIT_TIMEOUT)
  6469. {
  6470. WriteTextLog(_T("检测服务3错误:%d\n"), GetLastError());
  6471. break;
  6472. }
  6473. if(WaitForSingleObject(p->m_hExitCheckSvc, 0) == WAIT_OBJECT_0)
  6474. break;
  6475. CString strPath = _T("");
  6476. DWORD dwID = 0;
  6477. // 自动备份
  6478. dwID = FindAppProcessID(_T("lyfzBackupSvc.exe"));
  6479. if(dwID == 0)
  6480. {
  6481. strPath = g_mainpath + _T("\\lyfzBackupSvc.exe");
  6482. CString strCmd = _T("/startsvc");
  6483. SHELLEXECUTEINFO execinfo;
  6484. memset(&execinfo, 0, sizeof(execinfo));
  6485. execinfo.lpFile = strPath;
  6486. execinfo.cbSize = sizeof(execinfo);
  6487. execinfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
  6488. execinfo.nShow = SW_HIDE;
  6489. execinfo.lpParameters = strCmd;
  6490. if(!ShellExecuteEx(&execinfo))
  6491. {
  6492. CString strError = _T("");
  6493. strError.Format(_T("检测服务1错误:%d\n"), GetLastError());
  6494. OutputDebugString(strError);
  6495. }
  6496. // WaitForSingleObject(execinfo.hProcess,INFINITE);
  6497. }
  6498. // 自动删除
  6499. dwID = FindAppProcessID(_T("lyfzDeletePhotoSvc.exe"));
  6500. if(dwID == 0)
  6501. {
  6502. strPath = g_mainpath + _T("\\lyfzDeletePhotoSvc.exe");
  6503. CString strCmd = _T("/startsvc");
  6504. SHELLEXECUTEINFO execinfo;
  6505. memset(&execinfo, 0, sizeof(execinfo));
  6506. execinfo.lpFile = strPath;
  6507. execinfo.cbSize = sizeof(execinfo);
  6508. execinfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
  6509. execinfo.nShow = SW_HIDE;
  6510. execinfo.lpParameters = strCmd;
  6511. if(!ShellExecuteEx(&execinfo))
  6512. {
  6513. WriteTextLog(_T("检测服务2错误:%d\n"), GetLastError());
  6514. }
  6515. // WaitForSingleObject(execinfo.hProcess,INFINITE);
  6516. }
  6517. }
  6518. }
  6519. _endthreadex(0);
  6520. return 0;
  6521. }
  6522. // 结束检查工作
  6523. void CDBServerDlg::TerminateCheckWork()
  6524. {
  6525. if(m_hExitCheckSvc)
  6526. SetEvent(m_hExitCheckSvc);
  6527. if(m_hWaitTimeOut)
  6528. SetEvent(m_hWaitTimeOut);
  6529. if(m_hCheckSvcThread)
  6530. {
  6531. WaitForSingleObject(m_hCheckSvcThread, INFINITE);
  6532. CloseHandle(m_hCheckSvcThread);
  6533. }
  6534. m_hCheckSvcThread = NULL;
  6535. if(m_hExitCheckSvc)
  6536. CloseHandle(m_hExitCheckSvc);
  6537. m_hExitCheckSvc = NULL;
  6538. if(m_hWaitTimeOut)
  6539. CloseHandle(m_hWaitTimeOut);
  6540. m_hWaitTimeOut = NULL;
  6541. m_bStartCheckSvc = FALSE;
  6542. }
  6543. /************************************************************************/
  6544. /*
  6545. 函数:OnStartBackupSvc
  6546. 描述:启动备份服务
  6547. 参数:
  6548. 返回:
  6549. */
  6550. /************************************************************************/
  6551. void CDBServerDlg::OnStartBackupSvc()
  6552. {
  6553. StartSvc(_T("lyfzBackupSvc.exe"));
  6554. }
  6555. /************************************************************************/
  6556. /*
  6557. 函数:OnStopBackupSvc
  6558. 描述:停止备份服务
  6559. 参数:
  6560. 返回:
  6561. */
  6562. /************************************************************************/
  6563. void CDBServerDlg::OnStopBackupSvc()
  6564. {
  6565. StopSvc(_T("lyfz Backup Service"));
  6566. }
  6567. /************************************************************************/
  6568. /*
  6569. 函数:OnStartDelPhotoSvc
  6570. 描述:启动删除服务
  6571. 参数:
  6572. 返回:
  6573. */
  6574. /************************************************************************/
  6575. void CDBServerDlg::OnStartDelPhotoSvc()
  6576. {
  6577. StartSvc(_T("lyfzDeletePhotoSvc.exe"));
  6578. }
  6579. /************************************************************************/
  6580. /*
  6581. 函数:OnStopDelPhotoSvc
  6582. 描述:停止删除服务
  6583. 参数:
  6584. 返回:
  6585. */
  6586. /************************************************************************/
  6587. void CDBServerDlg::OnStopDelPhotoSvc()
  6588. {
  6589. StopSvc(_T("lyfz Delete Photo Service"));
  6590. }
  6591. /************************************************************************/
  6592. /*
  6593. 函数:StartSvc
  6594. 描述:启动服务
  6595. 参数:
  6596. IN LPCSTR lpExeFile 程序名称
  6597. 返回:1成功,0失败
  6598. */
  6599. /************************************************************************/
  6600. int CDBServerDlg::StartSvc( IN LPCSTR lpExeFile)
  6601. {
  6602. CString strPath = _T("");
  6603. DWORD dwID = 0;
  6604. // 自动备份
  6605. dwID = FindAppProcessID(lpExeFile);
  6606. if(dwID == 0)
  6607. {
  6608. strPath = g_mainpath + _T("\\");
  6609. strPath += lpExeFile;
  6610. CString strCmd = _T("/startsvc");
  6611. SHELLEXECUTEINFO execinfo;
  6612. memset(&execinfo, 0, sizeof(execinfo));
  6613. execinfo.lpFile = strPath;
  6614. execinfo.cbSize = sizeof(execinfo);
  6615. execinfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
  6616. execinfo.nShow = SW_HIDE;
  6617. execinfo.lpParameters = strCmd;
  6618. if(!ShellExecuteEx(&execinfo))
  6619. {
  6620. CString strError = _T("");
  6621. strError.Format(_T("检测服务%s错误:%d\n"), lpExeFile, GetLastError());
  6622. OutputDebugString(strError);
  6623. }
  6624. }
  6625. return 1;
  6626. }
  6627. // 停止服务
  6628. /************************************************************************/
  6629. /*
  6630. 函数:OnStopDelPhotoSvc
  6631. 描述:停止删除服务
  6632. 参数:
  6633. IN LPCSTR lpSvcName 服务名
  6634. 返回:1成功,0失败
  6635. */
  6636. /************************************************************************/
  6637. int CDBServerDlg::StopSvc(IN LPCSTR lpSvcName)
  6638. {
  6639. CString strError = _T("");
  6640. SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
  6641. if (hSCM == NULL)
  6642. return 0;
  6643. SC_HANDLE hService = ::OpenService(hSCM, lpSvcName, SERVICE_STOP | SERVICE_QUERY_STATUS);
  6644. if (hService == NULL)
  6645. {
  6646. strError.Format(_T("打开%s服务失败:%d"), lpSvcName, GetLastError());
  6647. OutputDebugString(strError);
  6648. ::CloseServiceHandle(hSCM);
  6649. return 0;
  6650. }
  6651. SERVICE_STATUS status;
  6652. if(!::QueryServiceStatus(hService, &status))
  6653. {
  6654. strError.Format(_T("获取%s服务状态失败:%d"), lpSvcName, GetLastError());
  6655. OutputDebugString(strError);
  6656. ::CloseServiceHandle(hService);
  6657. ::CloseServiceHandle(hSCM);
  6658. return 0;
  6659. }
  6660. if(status.dwCurrentState == SERVICE_STOPPED)
  6661. {
  6662. ::CloseServiceHandle(hService);
  6663. ::CloseServiceHandle(hSCM);
  6664. return 1;
  6665. }
  6666. ControlService(hService, SERVICE_CONTROL_STOP, &status);
  6667. DWORD dwStartTime = GetTickCount();
  6668. DWORD dwTimeout = 30*1000; // 30-second time-out
  6669. while(1)
  6670. {
  6671. Sleep( status.dwWaitHint );
  6672. if(!::QueryServiceStatus(hService, &status))
  6673. {
  6674. strError.Format(_T("获取%s服务状态失败:%d"), lpSvcName, GetLastError());
  6675. OutputDebugString(strError);
  6676. ::CloseServiceHandle(hService);
  6677. ::CloseServiceHandle(hSCM);
  6678. return 0;
  6679. }
  6680. if ( status.dwCurrentState == SERVICE_STOPPED )
  6681. break;
  6682. if ( GetTickCount() - dwStartTime > dwTimeout )
  6683. {
  6684. strError.Format(_T("停止%s服务超时:%d"), lpSvcName, GetLastError());
  6685. OutputDebugString(strError);
  6686. ::CloseServiceHandle(hService);
  6687. ::CloseServiceHandle(hSCM);
  6688. return 0;
  6689. }
  6690. }
  6691. ::CloseServiceHandle(hService);
  6692. ::CloseServiceHandle(hSCM);
  6693. return 1;
  6694. }
  6695. void CDBServerDlg::OnAutoCheckSvc()
  6696. {
  6697. g_bAutoCheckSvc = !g_bAutoCheckSvc;
  6698. CHAR szFile[MAX_PATH + 1] = "";
  6699. wsprintf(szFile, "%s\\ServiceInfo.ini", g_ModulePath);
  6700. OFSTRUCT ofStruct;
  6701. OpenFile(szFile, &ofStruct, OF_EXIST);
  6702. if (ERROR_FILE_NOT_FOUND == GetLastError())
  6703. return;
  6704. CString strValue = _T("");
  6705. strValue.Format(_T("%d"), g_bAutoCheckSvc);
  6706. WritePrivateProfileString(_T("Back"), _T("AutoCheckSvc"), strValue, szFile);
  6707. if(!g_bAutoCheckSvc)
  6708. {
  6709. TerminateCheckWork();
  6710. }
  6711. else
  6712. {
  6713. // 如果没启动自动检查
  6714. if(!m_bStartCheckSvc)
  6715. {
  6716. m_hExitCheckSvc = CreateEvent(NULL, FALSE, FALSE, NULL);
  6717. m_hWaitTimeOut = CreateEvent(NULL, FALSE, FALSE, NULL);
  6718. SetEvent(m_hWaitTimeOut);
  6719. unsigned int nThreadID = 0;
  6720. m_bStartCheckSvc = TRUE;
  6721. m_hCheckSvcThread = (HANDLE)_beginthreadex(NULL, 0, CheckSvcWork, this, 0, &nThreadID);
  6722. }
  6723. }
  6724. }