DBServerDlg.cpp 193 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323
  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. //MyLock lock("dbaccessxiao");
  1053. CDatabase *pdb = NULL;
  1054. ODBCConnGuard ConnGuard(pdb, -1, 3000);
  1055. if ( pdb == NULL)
  1056. return;
  1057. CRecordset myset(pdb);
  1058. #if 0
  1059. CString logdays;
  1060. CString sql = "select logdays from version";
  1061. myset.Open(CRecordset::forwardOnly, sql);
  1062. myset.GetFieldValue("logdays", logdays);
  1063. myset.Close();
  1064. int days = 180;
  1065. if (logdays == "1个月")
  1066. days = 31;
  1067. else if (logdays == "2个月")
  1068. days = 61;
  1069. else if (logdays == "3个月")
  1070. days = 92;
  1071. else
  1072. days = 183;
  1073. CTime tm = CTime::GetCurrentTime();
  1074. CTimeSpan dt(240, 0, 0, 0); // Jeff 不使用days,固定使用天数;
  1075. tm -= dt;
  1076. CString date = tm.Format("%Y-%m-%d");
  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. CTime tm = CTime::GetCurrentTime();
  1088. CTimeSpan dt2(183, 0, 0, 0);
  1089. tm -= dt2;
  1090. CString date = tm.Format("%Y%m%d%H%M%S");
  1091. CString 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. }