DBServerDlg.cpp 193 KB

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