DBServerDlg.cpp 192 KB

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