DBServerDlg.cpp 190 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241
  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. /*
  1224. void LoadImageFromBuf(Image **img, BYTE *pData, DWORD leng)//g_bakserver1
  1225. {
  1226. try
  1227. {
  1228. if (pData == NULL)return;
  1229. if (*img)delete *img;
  1230. *img = NULL;
  1231. // Allocate global memory on which to create stream
  1232. HGLOBAL m_hMem = GlobalAlloc(GMEM_MOVEABLE, leng);
  1233. if (m_hMem == NULL)return;
  1234. BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
  1235. memcpy(pmem, pData, leng);
  1236. IStream* pstm;
  1237. CreateStreamOnHGlobal(m_hMem, TRUE, &pstm);
  1238. // load from stream
  1239. *img = Gdiplus::Image::FromStream(pstm);
  1240. // free/release stuff
  1241. GlobalUnlock(m_hMem);
  1242. pstm->Release();
  1243. }
  1244. catch (...)
  1245. {
  1246. }
  1247. }
  1248. void LoadImageFromBuf(Image **img, CString path)
  1249. {
  1250. try
  1251. {
  1252. CFile fp;
  1253. if (fp.Open(path, CFile::modeRead))
  1254. {
  1255. DWORD leng = fp.GetLength();
  1256. BYTE *pData = new BYTE[leng];
  1257. fp.Read(pData, leng);
  1258. fp.Close();
  1259. LoadImageFromBuf(img, pData, leng);
  1260. delete[]pData;
  1261. }
  1262. }
  1263. catch (...)
  1264. {
  1265. }
  1266. }
  1267. void LoadImageFromRes(Image **img, LPCTSTR lpszResourceName, LPCTSTR ResourceType)
  1268. {
  1269. try
  1270. {
  1271. HGLOBAL hGlobal = NULL;
  1272. HRSRC hSource = NULL;
  1273. LPVOID lpVoid = NULL;
  1274. int nSize = 0;
  1275. BOOL bResult = FALSE;
  1276. hSource = FindResource(NULL, lpszResourceName, ResourceType);
  1277. if (hSource == NULL)return;
  1278. hGlobal = LoadResource(NULL, hSource);
  1279. if (hGlobal == NULL)return;
  1280. lpVoid = LockResource(hGlobal);
  1281. if (lpVoid == NULL)return;
  1282. nSize = (UINT)SizeofResource(NULL, hSource);
  1283. LoadImageFromBuf(img, (BYTE*)hGlobal, nSize);
  1284. UnlockResource(hGlobal); // 16Bit Windows Needs This
  1285. FreeResource(hGlobal); // 16Bit Windows Needs This (32Bit - Automatic Release)
  1286. }
  1287. catch (...)
  1288. {
  1289. }
  1290. }
  1291. */
  1292. // ---------------------------------------------------------------------------------------------------------------------------------------------------------------
  1293. // TimeAt: 2014-09-15 AM;
  1294. // Remark: Jeff;
  1295. // 函数:GenSPhoto
  1296. // 描述:对指定文件夹内的相片生成S或M缩略图;
  1297. // 参数:
  1298. // dir: 需要生成缩略图的文件目录;
  1299. // bMPhoto: 是否生成M缩略图;
  1300. // 其它:
  1301. // 在生成缩略图前,记录jpg文件总数nOldCount,每生成一个缩略图nOldCount++;
  1302. // 最后全部图生成完毕,获取新的jpg文件总数nNewCount,if(nOldCount == nNewCount)则表示所有相片已生成缩略图完毕,生成ok文件表示成功生成缩略图;
  1303. //
  1304. // 函数调用全局参数:
  1305. // g_bSteal:意义未明!
  1306. //
  1307. // 注意:该函数非线程安全!
  1308. // 非线程安全:
  1309. // 获取文件总数nOldCount结束后,若有新文件在本函数以外其他函数或进程、线程被添加,则生成缩略图完成后再次获取文件总数nNewCount就不会与nOldCount++后的结果相等;
  1310. // 而实际上本次缩略图已生成完毕。
  1311. // ---------------------------------------------------------------------------------------------------------------------------------------------------------------
  1312. void GenSPhoto(CString dir, BOOL bMPhoto) // 参数:bMPhoto:是否生成M缩略图;
  1313. {
  1314. // 如果是公告附件目录退出;
  1315. if (dir.Find("公告附件") != -1)return;
  1316. // 如果不是客户原片或修好的片目录,设置bMPhoto参数为0,不生成M缩略图;
  1317. if (dir.Find("客户原片(管理软件)$") != -1 || dir.Find("修好的片(管理软件)$") != -1)
  1318. {
  1319. }
  1320. else
  1321. bMPhoto = 0;
  1322. // 对指定文件目录dir进行指定后缀jpg文件遍历;
  1323. ffsco o;
  1324. o.dirs(1);
  1325. o.find(LPCSTR(dir), LPCSTR("*.*"));
  1326. ffsco::typeT coo;
  1327. ffsco::typeT::iterator it;
  1328. coo = o.co_file();
  1329. int oldsize = coo.size();
  1330. CString path, temp, spath, mpath;
  1331. for (it = coo.begin(); coo.end() != it; it++)
  1332. {
  1333. try
  1334. {
  1335. if (g_pMainWnd->m_bTerminate)return;
  1336. // 遍历到的jpg文件如果是缩略图则不处理,继续遍历;
  1337. path = (*it).c_str();
  1338. spath = path.Left(path.ReverseFind('\\') + 1);
  1339. mpath = spath;
  1340. spath += "s";
  1341. mpath += "m";
  1342. temp = path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
  1343. if (temp.GetAt(0) == 's')continue;
  1344. if (temp.GetAt(0) == 'm')continue;
  1345. spath += path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
  1346. mpath += path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
  1347. if (g_bSteal)
  1348. {
  1349. Image *pImg = NULL;
  1350. IMGCommon::LoadImgFromFile(&pImg, path);
  1351. if (pImg == NULL)continue;
  1352. if (pImg->GetWidth() == 0)
  1353. {
  1354. if (pImg)
  1355. delete pImg;
  1356. pImg = NULL;
  1357. continue;
  1358. }
  1359. if (pImg)
  1360. delete pImg;
  1361. pImg = NULL;
  1362. EncryptFile3(path);
  1363. if (path.Find("客户原片") != -1)
  1364. {
  1365. int pos = path.Find("管理软件)$");
  1366. if (pos != -1)
  1367. {
  1368. path = g_bakserver1 + path.Right(path.GetLength() - pos - 10);
  1369. EncryptFile3(path);
  1370. }
  1371. }
  1372. else if (path.Find("修好的片") != -1)
  1373. {
  1374. int pos = path.Find("管理软件)$");
  1375. if (pos != -1)
  1376. {
  1377. path = g_bakserver2 + path.Right(path.GetLength() - pos - 10);
  1378. EncryptFile3(path);
  1379. }
  1380. }
  1381. else if (path.Find("精修好的片") != -1)
  1382. {
  1383. int pos = path.Find("管理软件)$");
  1384. if (pos != -1)
  1385. {
  1386. path = g_bakserver3 + path.Right(path.GetLength() - pos - 10);
  1387. EncryptFile3(path);
  1388. }
  1389. }
  1390. else if (path.Find("设计好的片") != -1)
  1391. {
  1392. int pos = path.Find("管理软件)$");
  1393. if (pos != -1)
  1394. {
  1395. path = g_bakserver4 + path.Right(path.GetLength() - pos - 10);
  1396. EncryptFile3(path);
  1397. }
  1398. }
  1399. oldsize++;
  1400. }
  1401. else if (!CheckFileExist(spath)) // 没有判断后续是否为jpg或jpeg.
  1402. {
  1403. Image *pImg = NULL;
  1404. IMGCommon::LoadImgFromFile(&pImg, path);
  1405. if (pImg == NULL)continue;
  1406. if (pImg->GetWidth() == 0)
  1407. {
  1408. // 由于没有判断spath是否是jpg或jpeg的相片文件,导致这里泄漏;
  1409. if (pImg)
  1410. delete pImg;
  1411. pImg = NULL;
  1412. continue;
  1413. }
  1414. IMGCommon::ImgThumbnail(pImg,SET_PIX(100,100), spath, 100);
  1415. if (bMPhoto)
  1416. IMGCommon::ImgThumbnail(pImg,SET_PIX(2000,2000), mpath, 100);
  1417. if (pImg)
  1418. delete pImg;
  1419. pImg = NULL;
  1420. }
  1421. }
  1422. catch (...)
  1423. {
  1424. WriteTextLog("出错在函数GenSPhoto中");
  1425. }
  1426. }
  1427. try
  1428. {
  1429. ffsco o;
  1430. o.dirs(1);
  1431. o.find(LPCSTR(dir), LPCSTR("*.*"));
  1432. ffsco::typeT coo;
  1433. ffsco::typeT::iterator it;
  1434. coo = o.co_file();
  1435. int newsize = coo.size();
  1436. if (oldsize == newsize)
  1437. {
  1438. path = dir + "\\ok";
  1439. CFile fp;
  1440. if ( fp.Open(path, CFile::modeCreate | CFile::modeWrite) )
  1441. fp.Close();
  1442. }
  1443. }
  1444. catch (...)
  1445. {
  1446. WriteTextLog("出错在函数GenSPhoto2中");
  1447. }
  1448. }
  1449. //--------------------------------------------------------------------------------
  1450. // Remark by Jeff 2014.10.22
  1451. // 函数:LoadThumbNail
  1452. // 描述:S或M缩略图线程
  1453. // 参数:
  1454. // 返回:
  1455. //
  1456. // 调用关系:SetTimer(1);
  1457. // 1.
  1458. // 2.
  1459. // 3.
  1460. //--------------------------------------------------------------------------------
  1461. unsigned __stdcall LoadThumbNail(LPVOID lpParam)
  1462. {
  1463. BOOL bMphoto = 0;
  1464. if (g_bSteal == 0)
  1465. {
  1466. CDatabase *pMaindb = NULL;
  1467. ODBCConnGuard ConnGuard(pMaindb , -1, 3000);
  1468. if ( pMaindb )
  1469. {
  1470. try
  1471. {
  1472. CRecordset myset(pMaindb);
  1473. CString sql = "select * from version";
  1474. myset.Open(CRecordset::forwardOnly, sql);
  1475. myset.GetFieldValue("setcheck15", sql); // 选片时是否使用m缩略图来代替原片放大使用;
  1476. myset.Close();
  1477. bMphoto = atoi(sql);
  1478. }
  1479. catch (CDBException* e)
  1480. {
  1481. WriteTextLog(_T("LoadThumbNail:%s"),e->m_strError);
  1482. e->Delete();
  1483. }
  1484. }
  1485. }
  1486. CString initialPhotoPath = _T("");
  1487. CString initialModifyPath = _T("");
  1488. CString designPhotoPath = _T("");
  1489. CString excellentModifyPath = _T("");
  1490. char server[50] = {0};
  1491. DWORD leng = 50;
  1492. ::GetComputerName(server, &leng);
  1493. initialPhotoPath = initialModifyPath = designPhotoPath = excellentModifyPath = server;
  1494. initialPhotoPath = "\\\\" + initialPhotoPath + "\\客户原片(管理软件)$";
  1495. initialModifyPath = "\\\\" + initialModifyPath + "\\修好的片(管理软件)$";
  1496. designPhotoPath = "\\\\" + designPhotoPath + "\\设计好的片(管理软件)$";
  1497. excellentModifyPath = "\\\\" + excellentModifyPath + "\\精修好的片(管理软件)$";
  1498. GetPathFromNetShareName("客户原片(管理软件)$", initialPhotoPath);
  1499. GetPathFromNetShareName("修好的片(管理软件)$", initialModifyPath);
  1500. GetPathFromNetShareName("设计好的片(管理软件)$", designPhotoPath);
  1501. GetPathFromNetShareName("精修好的片(管理软件)$", excellentModifyPath);
  1502. int i = 0;
  1503. CStringArray dirarray;
  1504. CDBServerDlg *pDlg = (CDBServerDlg*)lpParam;
  1505. try
  1506. {
  1507. // Remark:Jeff.
  1508. // 遍历原片、修好片、设计片、精修片目录,查看是否有ok或ok.dat文件存在;
  1509. // 说明:ok文件在客户端再次导入相片时会被删除;
  1510. // 只有服务端生成小图后,ok才被重新生成;
  1511. if(CBranchInfo::GetInstance()->m_TblNetShareInfo.size() != 0)
  1512. {
  1513. vector<TblNetShareInfo*>::iterator iter = CBranchInfo::GetInstance()->m_TblNetShareInfo.begin();
  1514. for(; iter != CBranchInfo::GetInstance()->m_TblNetShareInfo.end();)
  1515. {
  1516. TblNetShareInfo* p = (*iter);
  1517. if(p != NULL)
  1518. {
  1519. CString strDir = p->szShareDirectory;
  1520. if(strDir.Find(_T("$\\")) != -1)
  1521. strDir = strDir.TrimRight(_T("\\"));
  1522. pDlg->CheckOkFileExistence(strDir, dirarray);
  1523. }
  1524. ++iter;
  1525. }
  1526. CString patharray[2] = { designPhotoPath, excellentModifyPath };
  1527. //int i = 0;
  1528. for (i = 0; i < 2; i++)
  1529. {
  1530. if (pDlg->m_bTerminate)
  1531. break;
  1532. pDlg->CheckOkFileExistence(patharray[i], dirarray);
  1533. }
  1534. }
  1535. else
  1536. {
  1537. CString patharray[4] = { initialPhotoPath, initialModifyPath, designPhotoPath, excellentModifyPath };
  1538. for (i = 0; i < 4; i++)
  1539. {
  1540. if (pDlg->m_bTerminate)
  1541. break;
  1542. pDlg->CheckOkFileExistence(patharray[i], dirarray);
  1543. }
  1544. }
  1545. }
  1546. catch (CException *e)
  1547. {
  1548. TCHAR szError[1024] = { 0 };
  1549. e->GetErrorMessage(szError, 1024);
  1550. e->Delete();
  1551. WriteTextLog(_T("出错在函数GenThumb中: %s"), szError);
  1552. }
  1553. for (i = 0; i < dirarray.GetSize(); i++)
  1554. {
  1555. if (pDlg->m_bTerminate)
  1556. break;
  1557. GenSPhoto(dirarray.ElementAt(i), bMphoto);
  1558. }
  1559. pDlg->m_bRunning = false;
  1560. pDlg->m_bTerminate = false;
  1561. pDlg->SetTimer(1, 60 * 1000, NULL);
  1562. _endthreadex(0);
  1563. return 0;
  1564. }
  1565. //--------------------------------------------------------------------------------
  1566. // 函数:CheckOkFileExistence
  1567. // 描述:OK文件是否存在
  1568. // 参数:
  1569. // const CString& strPath 需要搜索的目录
  1570. // CStringArray& arr 返回文件目录
  1571. // 返回:TRUE成功,FALSE失败
  1572. //--------------------------------------------------------------------------------
  1573. BOOL CDBServerDlg::CheckOkFileExistence(const CString& strPath, CStringArray& arr)
  1574. {
  1575. CString path(_T("")), path2(_T(""));
  1576. if(strPath == _T(""))
  1577. return FALSE;
  1578. ffsco o;
  1579. o.dirs(1);
  1580. o.find(LPCSTR(strPath), LPCSTR("*.*"));
  1581. ffsco::typeT coo;
  1582. ffsco::typeT::iterator it;
  1583. coo = o.co_dir();
  1584. it = coo.begin();
  1585. it++;
  1586. for(; coo.end() != it; it++)
  1587. {
  1588. if (m_bTerminate)
  1589. break;
  1590. path = (*it).c_str();
  1591. path.TrimRight("\\");
  1592. path2 = path;
  1593. path2 += "\\ok2.dat";
  1594. path += "\\ok";
  1595. if (CheckFileExist(path2) && path2.Find(".ly.com") == -1)
  1596. {
  1597. ::DeleteFile(path); // 删除ok文件;
  1598. ::DeleteFile(path2); // 删除ok.dat文件;
  1599. }
  1600. // g_bCheckAll g_bSteal的意义???
  1601. // g_bCheckAll没有任何其他赋值的代码,只有最开始初始化值0;下这if不执行;
  1602. if (g_bCheckAll || g_bSteal)
  1603. {
  1604. if (FindArray(&arr, (*it).c_str()) == -1)
  1605. arr.Add((*it).c_str());
  1606. }
  1607. else if (CheckFileExist(path) == 0)
  1608. {
  1609. if (FindArray(&arr, (*it).c_str()) == -1)
  1610. arr.Add((*it).c_str());
  1611. }
  1612. }
  1613. return 1;
  1614. }
  1615. //自动生成小图线程;
  1616. void CDBServerDlg::LoadThumbImages() // 自动生成小图线程;
  1617. {
  1618. if (m_bRunning)return;
  1619. TerminateThread();
  1620. m_bRunning = true;
  1621. m_hThread = (HANDLE)_beginthreadex(NULL, 0, LoadThumbNail, (LPVOID)this, 0/* CREATE_SUSPENDED*/, &m_dwThreadID);
  1622. }
  1623. BOOL CDBServerDlg::TerminateThread()
  1624. {
  1625. try
  1626. {
  1627. if (!m_bRunning)
  1628. return TRUE;
  1629. m_bTerminate = true;
  1630. for (;;)
  1631. {
  1632. if (::WaitForSingleObject(m_hThread, INFINITE) == WAIT_OBJECT_0)
  1633. break;
  1634. }
  1635. ::CloseHandle(m_hThread);
  1636. m_bRunning = false;
  1637. return TRUE;
  1638. }
  1639. catch (...)
  1640. {
  1641. WriteTextLog("出错在函数TerminateThread中");
  1642. }
  1643. return TRUE;
  1644. }
  1645. void CDBServerDlg::InitLia()
  1646. {
  1647. try
  1648. {
  1649. // Jeff:逆天的变量命名!!!局部变量竟然用g_开头!!!
  1650. //BYTE *g_pData=NULL;DWORD g_nLeng; DWORD count2;
  1651. BYTE *pReturnData = NULL;
  1652. DWORD dwReturnLen;
  1653. DWORD count2;
  1654. BYTE byCode = 104;
  1655. CConnectSocket consock;
  1656. ODBCConnGuard ConnGuard(consock.m_pConndb, -1, 3000);
  1657. if ( consock.m_pConndb == NULL )
  1658. return;
  1659. consock.GetDataFromCode(byCode, &pReturnData, dwReturnLen, count2, "");
  1660. if (pReturnData == NULL || dwReturnLen == 0)
  1661. return;
  1662. DWORD readbytes = 0;
  1663. CArray<DWORD, DWORD> ArrayOfLen;
  1664. CArray<DWORD, DWORD> ArrayOfBtnLen;
  1665. BYTE *pArrayPointer = NULL;
  1666. DWORD dwPointerLen = 0;
  1667. DWORD leng;
  1668. memcpy(&leng, pReturnData + readbytes, sizeof(DWORD));
  1669. readbytes += sizeof(DWORD);
  1670. BYTE *pFtData = new BYTE[leng];
  1671. memcpy(pFtData, pReturnData + readbytes, leng);
  1672. readbytes += leng;
  1673. CMemFile memfile;
  1674. memfile.Attach(pFtData, leng);
  1675. CArchive ar(&memfile, CArchive::load);
  1676. ArrayOfLen.Serialize(ar);
  1677. ar.Close();
  1678. memfile.Detach();
  1679. memcpy(&leng, pReturnData + readbytes, sizeof(DWORD));
  1680. readbytes += sizeof(DWORD);
  1681. BYTE *pFtData2 = new BYTE[leng];
  1682. memcpy(pFtData2, pReturnData + readbytes, leng);
  1683. readbytes += leng;
  1684. CMemFile memfile2;
  1685. memfile2.Attach(pFtData2, leng);
  1686. CArchive ar2(&memfile2, CArchive::load);
  1687. ArrayOfBtnLen.Serialize(ar2);
  1688. ar2.Close();
  1689. memfile2.Detach();
  1690. delete[]pFtData;
  1691. delete[]pFtData2;
  1692. DWORD count;
  1693. memcpy(&count, pReturnData + readbytes, sizeof(DWORD));
  1694. readbytes += sizeof(DWORD);
  1695. dwPointerLen = count*sizeof(RESDATA2);
  1696. pArrayPointer = new BYTE[dwPointerLen];
  1697. int i = 0;
  1698. for (i = 0; i < count; i++)
  1699. {
  1700. memcpy(pArrayPointer + i*sizeof(RESDATA2), pReturnData + readbytes, sizeof(RESDATA2));
  1701. readbytes += sizeof(RESDATA2);
  1702. }
  1703. for (i = 0; i < ArrayOfLen.GetSize(); i += 8)
  1704. {
  1705. DWORD leng1, leng2, leng3, leng4, leng5, leng6, leng7, leng8;
  1706. leng1 = ArrayOfLen.ElementAt(i);
  1707. leng2 = ArrayOfLen.ElementAt(i + 1);
  1708. leng3 = ArrayOfLen.ElementAt(i + 2);
  1709. leng4 = ArrayOfLen.ElementAt(i + 3);
  1710. leng5 = ArrayOfLen.ElementAt(i + 4);
  1711. leng6 = ArrayOfLen.ElementAt(i + 5);
  1712. leng7 = ArrayOfLen.ElementAt(i + 6);
  1713. leng8 = ArrayOfLen.ElementAt(i + 7);
  1714. if (i % 4 == 0)
  1715. DeCodelong1((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8);
  1716. else if (i % 4 == 1)
  1717. DeCodelong2((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8);
  1718. else if (i % 4 == 2)
  1719. DeCodelong3((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8);
  1720. else
  1721. DeCodelong4((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8);
  1722. ArrayOfLen.SetAt(i, leng1);
  1723. ArrayOfLen.SetAt(i + 1, leng2);
  1724. ArrayOfLen.SetAt(i + 2, leng3);
  1725. ArrayOfLen.SetAt(i + 3, leng4);
  1726. ArrayOfLen.SetAt(i + 4, leng5);
  1727. ArrayOfLen.SetAt(i + 5, leng6);
  1728. ArrayOfLen.SetAt(i + 6, leng7);
  1729. ArrayOfLen.SetAt(i + 7, leng8);
  1730. }
  1731. delete[]pReturnData;
  1732. if (g_pSkinData)
  1733. delete[]g_pSkinData;
  1734. g_pSkinData = NULL;
  1735. DWORD length;
  1736. BYTE *pData;
  1737. DWORD length2;
  1738. BYTE *pData2;
  1739. CMemFile mStoreFile;
  1740. CArchive arStore(&mStoreFile, CArchive::store);
  1741. ArrayOfLen.Serialize(arStore);
  1742. arStore.Close();
  1743. length = mStoreFile.GetLength();
  1744. pData = mStoreFile.Detach();
  1745. CMemFile mStoreFile1;
  1746. CArchive arStore1(&mStoreFile1, CArchive::store);
  1747. ArrayOfBtnLen.Serialize(arStore1);
  1748. arStore1.Close();
  1749. length2 = mStoreFile1.GetLength();
  1750. pData2 = mStoreFile1.Detach();
  1751. g_SkinLeng = length + length2 + dwPointerLen + 3 * sizeof(DWORD);
  1752. g_pSkinData = new BYTE[g_SkinLeng];
  1753. readbytes = 0;
  1754. memcpy(g_pSkinData + readbytes, &length, sizeof(DWORD));
  1755. readbytes += sizeof(DWORD);
  1756. memcpy(g_pSkinData + readbytes, pData, length);
  1757. readbytes += length;
  1758. memcpy(g_pSkinData + readbytes, &length2, sizeof(DWORD));
  1759. readbytes += sizeof(DWORD);
  1760. memcpy(g_pSkinData + readbytes, pData2, length2);
  1761. readbytes += length2;
  1762. memcpy(g_pSkinData + readbytes, &dwPointerLen, sizeof(DWORD));
  1763. readbytes += sizeof(DWORD);
  1764. memcpy(g_pSkinData + readbytes, pArrayPointer, dwPointerLen);
  1765. readbytes += dwPointerLen;
  1766. delete[]pArrayPointer;
  1767. }
  1768. catch (...)
  1769. {
  1770. WriteTextLog("出错在函数InitLia中");
  1771. }
  1772. }
  1773. BOOL CheckExistDinDan(CString id)
  1774. {
  1775. CDatabase *pMaindb = NULL;
  1776. ODBCConnGuard ConnGuard(pMaindb, -1, 30000);
  1777. if ( pMaindb == NULL )
  1778. return FALSE;
  1779. CRecordset myset(pMaindb);
  1780. CString sql = "select count(*) as cot from dindan where id='" + id + "'";
  1781. myset.Open(CRecordset::forwardOnly, sql);
  1782. myset.GetFieldValue("cot", sql);
  1783. myset.Close();
  1784. return atol(sql);
  1785. }
  1786. //CString g_nCurConvertDBName="db"; // Jeff.deal
  1787. CString g_nCurConvertDBName(g_szDBName);
  1788. DWORD CDBServerDlg::ThreadCallerElves(LPVOID lpPara)
  1789. {
  1790. CArray<int, int>codearray;
  1791. codearray.Add(80);
  1792. codearray.Add(90);
  1793. codearray.Add(11);
  1794. codearray.Add(138);
  1795. codearray.Add(24);
  1796. codearray.Add(181);
  1797. codearray.Add(65);
  1798. codearray.Add(56);
  1799. codearray.Add(179);
  1800. codearray.Add(53);
  1801. CFile fp;
  1802. CString savepath, strPath1;
  1803. char server[50];
  1804. DWORD leng = 50;
  1805. ::GetComputerName(server, &leng);
  1806. strPath1 = server;
  1807. strPath1 = "\\\\" + strPath1 + "\\电话录音(管理软件)$";
  1808. GetPathFromNetShareName("电话录音(管理软件)$", strPath1);
  1809. if (strPath1.IsEmpty())
  1810. return 0;
  1811. try
  1812. {
  1813. CDatabase *pMaindb = NULL;
  1814. for ( int i = 0; i < g_dbpool.GetSize(); i++ )
  1815. {
  1816. ODBCConnGuard ConnGuard(pMaindb, i-1, 3000);
  1817. if ( !pMaindb )
  1818. continue;
  1819. savepath.Format("%s\\uphonedata%d.dat", strPath1, i);
  1820. ::DeleteFile(savepath); // 删除uphonedata.dat文件;
  1821. if (fp.Open(savepath, CFile::modeCreate | CFile::modeWrite) == 0)
  1822. {
  1823. WriteTextLog("更新来电精灵数据出错");
  1824. return 0;
  1825. }
  1826. CConnectSocket consock;
  1827. consock.m_pConndb = pMaindb;
  1828. for (int i = 0; i < codearray.GetSize(); i++)
  1829. {
  1830. BYTE code = codearray.ElementAt(i);
  1831. DWORD length, arraysize;
  1832. BYTE *pReturn = NULL;
  1833. consock.GetDataFromCode(code, &pReturn, length, arraysize, "");
  1834. fp.Write(&code, sizeof(BYTE));
  1835. fp.Write(&length, sizeof(DWORD));
  1836. fp.Write(&arraysize, sizeof(DWORD));
  1837. fp.Write(pReturn, length);
  1838. }
  1839. fp.Close();
  1840. }
  1841. }
  1842. catch (CException *e)
  1843. {
  1844. TCHAR szError[1024] = { 0 };
  1845. e->GetErrorMessage(szError, 1024);
  1846. WriteTextLog(CString(szError));
  1847. WriteTextLog("获取来电精灵数据出错1");
  1848. e->Delete();
  1849. }
  1850. return 0;
  1851. }
  1852. /************************************************************************/
  1853. /* [函数]:CheckHistoryData
  1854. /* [描述]:将被检测的数据库已完成的订单数据转到历史数据库中,并删除被检测的数据库已完成的订单;
  1855. /* [参数]:
  1856. /* pSrcdb: 源数据库,用于被转历史的数据库;
  1857. /* nSrcYear: 源数据库的年份;
  1858. /* bMode2: 转储模式:0=年度完成的订单; 1=年度所有订单,包含未完成订单;
  1859. /* [返回]:void
  1860. /*
  1861. /************************************************************************/
  1862. void CDBServerDlg::CheckHistoryData(CDatabase *pSrcdb /* = NULL */, int nSrcYear /* = 0 */, BOOL bMode2 /* = 0*/)//历史备份;
  1863. {
  1864. #if 0
  1865. // 取消转将当前数据库完成订单的记录转到年份数据库中,此步直接返回;
  1866. /////////////////////////生成来电精灵数据
  1867. MyLock lock("processChatMessageRequestxiao");
  1868. CArray<int, int>codearray;
  1869. codearray.Add(80);
  1870. codearray.Add(90);
  1871. codearray.Add(11);
  1872. codearray.Add(138);
  1873. codearray.Add(24);
  1874. codearray.Add(181);
  1875. codearray.Add(65);
  1876. codearray.Add(56);
  1877. codearray.Add(179);
  1878. codearray.Add(53);
  1879. CFile fp;
  1880. CString savepath, g_path1;
  1881. char server[50];
  1882. DWORD leng = 50;
  1883. ::GetComputerName(server, &leng);
  1884. g_path1 = server;
  1885. g_path1 = "\\\\" + g_path1 + "\\电话录音(管理软件)$";
  1886. GetPathFromNetShareName("电话录音(管理软件)$", g_path1);
  1887. if (g_path1.IsEmpty())return;
  1888. try
  1889. {
  1890. CDatabase *pdb = NULL;
  1891. for ( int i = 0; i < g_dbpool.GetSize(); i++ )
  1892. {
  1893. ODBCConnGuard ConnGuard(pdb, i-1, 3000);
  1894. if ( !pdb )
  1895. continue;
  1896. savepath.Format("%s\\uphonedata%d.dat", g_path1, i);
  1897. ::DeleteFile(savepath); // 删除uphonedata.dat文件;
  1898. if (fp.Open(savepath, CFile::modeCreate | CFile::modeWrite) == 0)
  1899. {
  1900. WriteTextLog("更新来电精灵数据出错");
  1901. return;
  1902. }
  1903. CConnectSocket consock;
  1904. consock.m_pConndb = pdb;
  1905. for (int i = 0; i < codearray.GetSize(); i++)
  1906. {
  1907. BYTE code = codearray.ElementAt(i);
  1908. DWORD length, arraysize;
  1909. BYTE *pReturn = NULL;
  1910. consock.GetDataFromCode(code, &pReturn, length, arraysize, "");
  1911. fp.Write(&code, sizeof(BYTE));
  1912. fp.Write(&length, sizeof(DWORD));
  1913. fp.Write(&arraysize, sizeof(DWORD));
  1914. fp.Write(pReturn, length);
  1915. }
  1916. fp.Close();
  1917. }
  1918. }
  1919. catch (CException *e)
  1920. {
  1921. TCHAR szError[1024] = { 0 };
  1922. e->GetErrorMessage(szError, 1024);
  1923. WriteTextLog(CString(szError));
  1924. WriteTextLog("获取来电精灵数据出错1");
  1925. e->Delete();
  1926. }
  1927. #endif
  1928. HANDLE h = CreateThread(NULL, 0, ThreadCallerElves, this, 0, NULL);
  1929. if ( h )CloseHandle(h);
  1930. }
  1931. //------------------------------------------------------------------------------------
  1932. // Jeff remark
  1933. // 函数:CheckYear
  1934. // 描述:
  1935. // 1.检查指定年份的历史数据库mdf文件是否存在,存在则直接附加
  1936. // 2.不存在,则使用null.mdf文件拷贝创建历史年份数据库mdf并附加;
  1937. // 参数:
  1938. // year:被检查年份值;
  1939. // 返回:void
  1940. //------------------------------------------------------------------------------------
  1941. #if JEFF_TEST_ON
  1942. void CDBServerDlg::CheckYear(int year)
  1943. {
  1944. CDatabase *pMaindb = NULL;
  1945. ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
  1946. if ( pMaindb == NULL )
  1947. return;
  1948. pMaindb->SetQueryTimeout(6000);
  1949. try
  1950. {
  1951. #ifdef SQLSERVER_VERSION
  1952. CString sql;
  1953. // 1.判断年份数据库是否存在;
  1954. CString strPathOfYearmdf;
  1955. CString strPathOfYearldf;
  1956. strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, year);
  1957. strPathOfYearldf.Format("%s\\数据\\%d_log.ldf", g_mainpath, year);
  1958. CString strPathOfnulldbmdf = g_mainpath + "\\数据\\dbnull.mdf";
  1959. CString strPathOfnulldbldf = g_mainpath + "\\数据\\dbnull_log.ldf";
  1960. if (PathFileExists(strPathOfYearmdf) == TRUE)
  1961. {
  1962. if (PathFileExists(strPathOfYearldf) == TRUE)
  1963. {
  1964. sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", year, strPathOfYearmdf, strPathOfYearldf);
  1965. }
  1966. else
  1967. {
  1968. // 此时要删除dbnull_log.ldf文件;
  1969. // 因为如果2015没有对应的ldf文件,在逻辑名仍为dbnull没有改为2015时,他会使用dbnull_log.ldf做为2015数据库的日志文件;
  1970. // 这样造成其他数据库在使用dbnull时会产生错误;
  1971. DeleteFile(strPathOfnulldbldf);//删除dbnull_log.ldf文件;
  1972. sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf);
  1973. }
  1974. try
  1975. {
  1976. pMaindb->ExecuteSQL(sql);
  1977. }
  1978. catch (CDBException * e)
  1979. {
  1980. WriteTextLog(e->m_strError);
  1981. WriteTextLog("历史数据库初始化失败!");
  1982. #ifdef _DEBUG
  1983. e->ReportError();
  1984. #endif
  1985. e->Delete();
  1986. return;
  1987. }
  1988. }
  1989. else
  1990. {
  1991. // 判断dbnull.mdf文件是否存在;
  1992. if (PathFileExists(strPathOfnulldbmdf) == FALSE)
  1993. {
  1994. WriteTextLog("空数据库丢失!");
  1995. return;
  1996. }
  1997. // 判断拷贝mdf文件是否失败;
  1998. if (FALSE == CopyFile(strPathOfnulldbmdf, strPathOfYearmdf, 1))
  1999. {
  2000. DWORD dwError = ::GetLastError();
  2001. CString strDescription;
  2002. strDescription.Format("dbnull.mdf拷贝为%d.mdf失败", year);
  2003. ErrorExit(strDescription, dwError);
  2004. return;
  2005. }
  2006. else
  2007. {
  2008. DeleteFile(strPathOfYearldf); // 删除%d_log.LDF文件;
  2009. if (PathFileExists(strPathOfnulldbldf) == TRUE)
  2010. {
  2011. if (FALSE == CopyFile(strPathOfnulldbldf, strPathOfYearldf, 1))
  2012. {
  2013. DWORD dwError = ::GetLastError();
  2014. CString strDescription;
  2015. strDescription.Format("null.mdf拷贝为%d.mdf", year);
  2016. ErrorExit(strDescription, dwError);
  2017. // 此时要删除dbnull_log.ldf文件;
  2018. // 因为如果2015没有对应的ldf文件,在逻辑名仍为dbnull没有改为2015时,他会使用dbnull_log.ldf做为2015数据库的日志文件;
  2019. // 这样造成其他数据库在使用dbnull时会产生错误;
  2020. DeleteFile(strPathOfnulldbldf);//删除dbnull_log.ldf文件;
  2021. sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf);
  2022. }
  2023. else
  2024. {
  2025. sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", year, strPathOfYearmdf, strPathOfYearldf);
  2026. }
  2027. }
  2028. else
  2029. {
  2030. // 此时要删除dbnull_log.ldf文件;
  2031. // 因为如果2015没有对应的ldf文件,在逻辑名仍为dbnull没有改为2015时,他会使用dbnull_log.ldf做为2015数据库的日志文件;
  2032. // 这样造成其他数据库在使用dbnull时会产生错误;
  2033. DeleteFile(strPathOfnulldbldf);//删除dbnull_log.ldf文件;
  2034. sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf);
  2035. }
  2036. try
  2037. {
  2038. pMaindb->ExecuteSQL(sql);
  2039. }
  2040. catch (CDBException * e)
  2041. {
  2042. WriteTextLog(e->m_strError);
  2043. WriteTextLog("历史数据库初始化失败!");
  2044. #ifdef _DEBUG
  2045. e->ReportError();
  2046. #endif
  2047. e->Delete();
  2048. return;
  2049. }
  2050. }
  2051. }
  2052. // 附加成功后,修改逻辑名称;
  2053. sql.Format("alter database [%d] modify file(name='dbnull',newname='%d')", year, year);
  2054. try
  2055. {
  2056. pMaindb->ExecuteSQL(sql);
  2057. }
  2058. catch (CDBException * e)
  2059. {
  2060. WriteTextLog(e->m_strError);
  2061. WriteTextLog("修改历史数据库主文件逻辑名失败,请手动修改!");
  2062. #ifdef _DEBUG
  2063. e->ReportError();
  2064. #endif
  2065. e->Delete();
  2066. }
  2067. sql.Format("alter database [%d] modify file(name='dbnull_log',newname='%d_log')", year, year);
  2068. try
  2069. {
  2070. pMaindb->ExecuteSQL(sql);
  2071. }
  2072. catch (CDBException * e)
  2073. {
  2074. WriteTextLog(e->m_strError);
  2075. WriteTextLog("修改历史数据库日志文件逻辑名失败,请手动修改!");
  2076. #ifdef _DEBUG
  2077. e->ReportError();
  2078. #endif
  2079. e->Delete();
  2080. }
  2081. OnExit2();
  2082. #else
  2083. CString path,sql;
  2084. path.Format ("%s\\数据\\%d.mdb", g_mainpath, year);
  2085. if(::PathFileExists (path)==0)
  2086. {
  2087. CString nulldb=g_mainpath+"\\数据\\dbnull.mdb";
  2088. ::CopyFile (nulldb, path, 1);
  2089. CDatabase *db=new CDatabase;
  2090. CString strCon;
  2091. strCon.Format("DRIVER=Microsoft Access Driver (*.mdb);DSN='';DBQ=%s;PWD=lijialyfz",path);
  2092. if(db->OpenEx(strCon,CDatabase::noOdbcDialog))
  2093. {
  2094. g_nYearArray.Add (year);
  2095. g_dbHistoryArray.Add (db);
  2096. sql.Format ("insert into historydb([year])values('%d')", year);
  2097. MyExecuteSQL(&g_db, sql);
  2098. }
  2099. else
  2100. delete db;
  2101. }
  2102. #endif
  2103. }
  2104. catch (...)
  2105. {
  2106. WriteTextLog("出错在函数CheckYear中");
  2107. }
  2108. }
  2109. #else
  2110. void CDBServerDlg::CheckYear(int year)
  2111. {
  2112. try
  2113. {
  2114. #ifdef SQLSERVER_VERSION
  2115. CString strPathOfYearmdf;
  2116. CString strPathOfYearldf;
  2117. CString sql;
  2118. strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, year);
  2119. strPathOfYearldf.Format("%s\\数据\\%d_log.LDF", g_mainpath, year);
  2120. ::DeleteFile(strPathOfYearldf); // 删除%d_log.LDF文件;
  2121. {
  2122. CString strPathOfnulldbmdf = g_mainpath + "\\数据\\dbnull.mdf";
  2123. CString strPathOfnulldbldf = g_mainpath + "\\数据\\dbnull_log.LDF";
  2124. ::DeleteFile(strPathOfnulldbldf); // 删除%d_log.LDF文件;
  2125. // 1.判断null.mdf文件是否存在;
  2126. if (::PathFileExists(strPathOfnulldbmdf) == 0)
  2127. {
  2128. WriteTextLog("空数据库丢失!");
  2129. return;
  2130. }
  2131. // 2.若年份mdf文件不存在,用null.mdf复制一份年份mdf数据库文件;
  2132. BOOL bCopyed = 0;
  2133. if (::PathFileExists(strPathOfYearmdf) == 0)
  2134. {
  2135. #if 0
  2136. ::CopyFile(nulldb, path, 1);
  2137. bCopyed=1;
  2138. #else // Jeff add:判断拷贝文件失败的原因;
  2139. if (!::CopyFile(strPathOfnulldbmdf, strPathOfYearmdf, 1))
  2140. {
  2141. DWORD dwError = ::GetLastError();
  2142. CString strDescription;
  2143. strDescription.Format("null.mdf拷贝为%d.mdf", year);
  2144. ErrorExit(strDescription, dwError);
  2145. // return;//直接返回;
  2146. }
  2147. else
  2148. {
  2149. bCopyed = 1;
  2150. }
  2151. #endif
  2152. }
  2153. if (::PathFileExists(strPathOfYearmdf) == 0)
  2154. {
  2155. WriteTextLog("拷贝数据库文件失败!");
  2156. return;
  2157. }
  2158. BOOL bLog = 0;
  2159. if (::PathFileExists(strPathOfnulldbldf))
  2160. {
  2161. bLog = 1;
  2162. }
  2163. // .将年份数据库mdf附加到数据库里;
  2164. CString sql;
  2165. if (bCopyed)
  2166. {
  2167. if (bLog)
  2168. sql.Format("exec sp_attach_db '%s',@filename1='%s',@filename2='%s'", "dbnull", strPathOfYearmdf, strPathOfYearldf);
  2169. else
  2170. sql.Format("exec sp_attach_db '%s',@filename1='%s'", "dbnull", strPathOfYearmdf);
  2171. g_db.SetQueryTimeout(600);
  2172. try
  2173. {
  2174. g_db.ExecuteSQL(sql);
  2175. }
  2176. catch (CDBException * e)
  2177. {
  2178. WriteTextLog(e->m_strError);
  2179. WriteTextLog("历史数据库初始化失败!");
  2180. #ifdef _DEBUG
  2181. e->ReportError();
  2182. #endif
  2183. e->Delete();
  2184. }
  2185. sql.Format("exec sp_renamedb '%s','%d'", "dbnull", year); g_db.ExecuteSQL(sql);
  2186. }
  2187. else // 没有执行CopyFile,年份mdf原本就存在;
  2188. {
  2189. if (bLog)
  2190. sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", year, strPathOfYearmdf, strPathOfYearldf);
  2191. else
  2192. sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf);
  2193. g_db.SetQueryTimeout(600);
  2194. try
  2195. {
  2196. g_db.ExecuteSQL(sql);
  2197. }
  2198. catch (CDBException * e)
  2199. {
  2200. WriteTextLog(e->m_strError);
  2201. WriteTextLog("历史数据库初始化失败!");
  2202. #ifdef _DEBUG
  2203. e->ReportError();
  2204. #endif
  2205. e->Delete();
  2206. }
  2207. }
  2208. OnExit2();
  2209. /* g_db.SetQueryTimeout(100);
  2210. CDatabase *db=new CDatabase;
  2211. try
  2212. {
  2213. CString strCon;
  2214. strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=%d;%s"), g_sservrename,year,g_sdbpsw);
  2215. db->OpenEx(strCon,CDatabase::noOdbcDialog);
  2216. g_nYearArray.Add (year);
  2217. dbarray.Add (db);
  2218. sql.Format ("insert into [historydb]([year])values('%d')", year);
  2219. MyExecuteSQL(&g_db, sql);
  2220. }
  2221. catch(CDBException * e)
  2222. {
  2223. delete db;
  2224. WriteTextLog(e->m_strError);
  2225. WriteTextLog("历史数据库打开失败!");
  2226. }*/
  2227. }
  2228. #else
  2229. CString path,sql;
  2230. path.Format ("%s\\数据\\%d.mdb", g_mainpath, year);
  2231. if(::PathFileExists (path)==0)
  2232. {
  2233. CString nulldb=g_mainpath+"\\数据\\dbnull.mdb";
  2234. ::CopyFile (nulldb, path, 1);
  2235. CDatabase *db=new CDatabase;
  2236. CString strCon;
  2237. strCon.Format("DRIVER=Microsoft Access Driver (*.mdb);DSN='';DBQ=%s;PWD=lijialyfz",path);
  2238. if(db->OpenEx(strCon,CDatabase::noOdbcDialog))
  2239. {
  2240. g_nYearArray.Add (year);
  2241. g_dbHistoryArray.Add (db);
  2242. sql.Format ("insert into historydb([year])values('%d')", year);
  2243. MyExecuteSQL(&g_db, sql);
  2244. }
  2245. else
  2246. delete db;
  2247. }
  2248. #endif
  2249. }
  2250. catch (...)
  2251. {
  2252. WriteTextLog("出错在函数CheckYear中");
  2253. }
  2254. }
  2255. #endif
  2256. CDatabase* CDBServerDlg::GetDB(int year)
  2257. {
  2258. try
  2259. {
  2260. for (int i = 0; i < g_nYearArray.GetSize(); i++)
  2261. {
  2262. if (g_nYearArray.ElementAt(i) == year)
  2263. {
  2264. return g_dbHistoryArray.ElementAt(i);
  2265. }
  2266. }
  2267. return NULL;
  2268. }
  2269. catch (...)
  2270. {
  2271. WriteTextLog("出错在函数GetDB中");
  2272. }
  2273. return NULL;
  2274. }
  2275. /************************************************************************/
  2276. /* mark by Jeff;
  2277. /* 函数:CheckDinDanExist
  2278. /* 描述:
  2279. /* 参数:
  2280. /* pBeConverted_db:(源)
  2281. /* pToConverted_db:(目标)
  2282. /* strOderNumber:
  2283. /* pRetArray:
  2284. /*
  2285. /* 返回:1表示正常,100及以上表示源数据库里记录 > 目标数据库记录;
  2286. /*
  2287. /************************************************************************/
  2288. BOOL CDBServerDlg::CheckDinDanExist(CDatabase *pBeConverted_db, CDatabase *pToConverted_db, CString strOderNumber, CStringArray *pRetArray)
  2289. {
  2290. try
  2291. {
  2292. pRetArray->RemoveAll();
  2293. int count1 = 0;
  2294. int count2 = 0;
  2295. CString sql;
  2296. {
  2297. CRecordset myset(pBeConverted_db);
  2298. sql = "select count(*) as cot from dindan where id='" + strOderNumber + "'";
  2299. myset.Open(CRecordset::forwardOnly, sql);
  2300. myset.GetFieldValue("cot", sql);
  2301. myset.Close();
  2302. count1 = atoi(sql);
  2303. }
  2304. {
  2305. CRecordset myset(pToConverted_db);
  2306. sql = "select count(*) as cot from dindan where id='" + strOderNumber + "'";
  2307. myset.Open(CRecordset::forwardOnly, sql);
  2308. myset.GetFieldValue("cot", sql);
  2309. myset.Close();
  2310. count2 = atoi(sql);
  2311. }
  2312. if (count1 > count2)//100
  2313. pRetArray->Add("0");
  2314. else
  2315. pRetArray->Add("1");
  2316. {
  2317. CRecordset myset(pBeConverted_db);
  2318. sql = "select count(*) as cot from dindansp where id='" + strOderNumber + "'";
  2319. myset.Open(CRecordset::forwardOnly, sql);
  2320. myset.GetFieldValue("cot", sql);
  2321. myset.Close();
  2322. count1 = atoi(sql);
  2323. }
  2324. {
  2325. CRecordset myset(pToConverted_db);
  2326. sql = "select count(*) as cot from dindansp where id='" + strOderNumber + "'";
  2327. myset.Open(CRecordset::forwardOnly, sql);
  2328. myset.GetFieldValue("cot", sql);
  2329. myset.Close();
  2330. count2 = atoi(sql);
  2331. }
  2332. if (count1 > count2)//101
  2333. pRetArray->Add("0");
  2334. else
  2335. pRetArray->Add("1");
  2336. {
  2337. CRecordset myset(pBeConverted_db);
  2338. sql = "select count(*) as cot from dindanbukuan where id='" + strOderNumber + "'";
  2339. myset.Open(CRecordset::forwardOnly, sql);
  2340. myset.GetFieldValue("cot", sql);
  2341. myset.Close();
  2342. count1 = atoi(sql);
  2343. }
  2344. {
  2345. CRecordset myset(pToConverted_db);
  2346. sql = "select count(*) as cot from dindanbukuan where id='" + strOderNumber + "'";
  2347. myset.Open(CRecordset::forwardOnly, sql);
  2348. myset.GetFieldValue("cot", sql);
  2349. myset.Close();
  2350. count2 = atoi(sql);
  2351. }
  2352. if (count1 > count2)//102
  2353. pRetArray->Add("0");
  2354. else
  2355. pRetArray->Add("1");
  2356. {
  2357. CRecordset myset(pBeConverted_db);
  2358. sql = "select count(*) as cot from dindanbukuan2 where id='" + strOderNumber + "'";
  2359. myset.Open(CRecordset::forwardOnly, sql);
  2360. myset.GetFieldValue("cot", sql);
  2361. myset.Close();
  2362. count1 = atoi(sql);
  2363. }
  2364. {
  2365. CRecordset myset(pToConverted_db);
  2366. sql = "select count(*) as cot from dindanbukuan2 where id='" + strOderNumber + "'";
  2367. myset.Open(CRecordset::forwardOnly, sql);
  2368. myset.GetFieldValue("cot", sql);
  2369. myset.Close();
  2370. count2 = atoi(sql);
  2371. }
  2372. if (count1 > count2)//103
  2373. pRetArray->Add("0");
  2374. else
  2375. pRetArray->Add("1");
  2376. {
  2377. CRecordset myset(pBeConverted_db);
  2378. sql = "select count(*) as cot from photoprint where id='" + strOderNumber + "'";
  2379. myset.Open(CRecordset::forwardOnly, sql);
  2380. myset.GetFieldValue("cot", sql);
  2381. myset.Close();
  2382. count1 = atoi(sql);
  2383. }
  2384. {
  2385. CRecordset myset(pToConverted_db);
  2386. sql = "select count(*) as cot from photoprint where id='" + strOderNumber + "'";
  2387. myset.Open(CRecordset::forwardOnly, sql);
  2388. myset.GetFieldValue("cot", sql);
  2389. myset.Close();
  2390. count2 = atoi(sql);
  2391. }
  2392. if (count1 > count2)//104
  2393. pRetArray->Add("0");
  2394. else
  2395. pRetArray->Add("1");
  2396. {
  2397. CRecordset myset(pBeConverted_db);
  2398. sql = "select count(*) as cot from client where id='" + strOderNumber + "'";
  2399. myset.Open(CRecordset::forwardOnly, sql);
  2400. myset.GetFieldValue("cot", sql);
  2401. myset.Close();
  2402. count1 = atoi(sql);
  2403. }
  2404. {
  2405. CRecordset myset(pToConverted_db);
  2406. sql = "select count(*) as cot from client where id='" + strOderNumber + "'";
  2407. myset.Open(CRecordset::forwardOnly, sql);
  2408. myset.GetFieldValue("cot", sql);
  2409. myset.Close();
  2410. count2 = atoi(sql);
  2411. }
  2412. if (count1 > count2)//105
  2413. pRetArray->Add("0");
  2414. else
  2415. pRetArray->Add("1");
  2416. {
  2417. CRecordset myset(pBeConverted_db);
  2418. sql = "select count(*) as cot from burncdreg where id='" + strOderNumber + "'";
  2419. myset.Open(CRecordset::forwardOnly, sql);
  2420. myset.GetFieldValue("cot", sql);
  2421. myset.Close();
  2422. count1 = atoi(sql);
  2423. }
  2424. {
  2425. CRecordset myset(pToConverted_db);
  2426. sql = "select count(*) as cot from burncdreg where id='" + strOderNumber + "'";
  2427. myset.Open(CRecordset::forwardOnly, sql);
  2428. myset.GetFieldValue("cot", sql);
  2429. myset.Close();
  2430. count2 = atoi(sql);
  2431. }
  2432. if (count1 > count2)//7
  2433. pRetArray->Add("0");
  2434. else
  2435. pRetArray->Add("1");
  2436. {
  2437. CRecordset myset(pBeConverted_db);
  2438. sql = "select count(*) as cot from digitalwork where id='" + strOderNumber + "'";
  2439. myset.Open(CRecordset::forwardOnly, sql);
  2440. myset.GetFieldValue("cot", sql);
  2441. myset.Close();
  2442. count1 = atoi(sql);
  2443. }
  2444. {
  2445. CRecordset myset(pToConverted_db);
  2446. sql = "select count(*) as cot from digitalwork where id='" + strOderNumber + "'";
  2447. myset.Open(CRecordset::forwardOnly, sql);
  2448. myset.GetFieldValue("cot", sql);
  2449. myset.Close();
  2450. count2 = atoi(sql);
  2451. }
  2452. if (count1 > count2)//8
  2453. pRetArray->Add("0");
  2454. else
  2455. pRetArray->Add("1");
  2456. {
  2457. CRecordset myset(pBeConverted_db);
  2458. sql = "select count(*) as cot from mywork where id='" + strOderNumber + "'";
  2459. myset.Open(CRecordset::forwardOnly, sql);
  2460. myset.GetFieldValue("cot", sql);
  2461. myset.Close();
  2462. count1 = atoi(sql);
  2463. }
  2464. {
  2465. CRecordset myset(pToConverted_db);
  2466. sql = "select count(*) as cot from mywork where id='" + strOderNumber + "'";
  2467. myset.Open(CRecordset::forwardOnly, sql);
  2468. myset.GetFieldValue("cot", sql);
  2469. myset.Close();
  2470. count2 = atoi(sql);
  2471. }
  2472. if (count1 > count2)//9
  2473. pRetArray->Add("0");
  2474. else
  2475. pRetArray->Add("1");
  2476. {
  2477. CRecordset myset(pBeConverted_db);
  2478. sql = "select count(*) as cot from dindanjd where id='" + strOderNumber + "'";
  2479. myset.Open(CRecordset::forwardOnly, sql);
  2480. myset.GetFieldValue("cot", sql);
  2481. myset.Close();
  2482. count1 = atoi(sql);
  2483. }
  2484. {
  2485. CRecordset myset(pToConverted_db);
  2486. sql = "select count(*) as cot from dindanjd where id='" + strOderNumber + "'";
  2487. myset.Open(CRecordset::forwardOnly, sql);
  2488. myset.GetFieldValue("cot", sql);
  2489. myset.Close();
  2490. count2 = atoi(sql);
  2491. }
  2492. if (count1 > count2)//10
  2493. pRetArray->Add("0");
  2494. else
  2495. pRetArray->Add("1");
  2496. {
  2497. CRecordset myset(pBeConverted_db);
  2498. sql = "select count(*) as cot from dindansp2 where id='" + strOderNumber + "'";
  2499. myset.Open(CRecordset::forwardOnly, sql);
  2500. myset.GetFieldValue("cot", sql);
  2501. myset.Close();
  2502. count1 = atoi(sql);
  2503. }
  2504. {
  2505. CRecordset myset(pToConverted_db);
  2506. sql = "select count(*) as cot from dindansp2 where id='" + strOderNumber + "'";
  2507. myset.Open(CRecordset::forwardOnly, sql);
  2508. myset.GetFieldValue("cot", sql);
  2509. myset.Close();
  2510. count2 = atoi(sql);
  2511. }
  2512. if (count1 > count2)
  2513. pRetArray->Add("0");
  2514. else
  2515. pRetArray->Add("1");
  2516. {
  2517. CRecordset myset(pBeConverted_db);
  2518. sql = "select count(*) as cot from dindansp3 where id='" + strOderNumber + "'";
  2519. myset.Open(CRecordset::forwardOnly, sql);
  2520. myset.GetFieldValue("cot", sql);
  2521. myset.Close();
  2522. count1 = atoi(sql);
  2523. }
  2524. {
  2525. CRecordset myset(pToConverted_db);
  2526. sql = "select count(*) as cot from dindansp3 where id='" + strOderNumber + "'";
  2527. myset.Open(CRecordset::forwardOnly, sql);
  2528. myset.GetFieldValue("cot", sql);
  2529. myset.Close();
  2530. count2 = atoi(sql);
  2531. }
  2532. if (count1 > count2)
  2533. pRetArray->Add("0");
  2534. else
  2535. pRetArray->Add("1");
  2536. for (int i = 0; i < pRetArray->GetSize(); i++)
  2537. {
  2538. if (pRetArray->ElementAt(i) == "0")return 100 + i;
  2539. }
  2540. return 1;
  2541. }
  2542. catch (CDBException * e)
  2543. {
  2544. WriteTextLog(e->m_strError);
  2545. WriteTextLog("出错在函数check1中");
  2546. #ifdef _DEBUG
  2547. e->ReportError();
  2548. #endif
  2549. e->Delete();
  2550. }
  2551. return 100;
  2552. }
  2553. BOOL CDBServerDlg::CheckPayOutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  2554. {
  2555. try
  2556. {
  2557. int count1 = 0;
  2558. int count2 = 0;
  2559. CString sql;
  2560. {
  2561. CRecordset myset(pdb1);
  2562. sql.Format("select count(*) as cot from gudingfeiyong where [id]=%d", atol(id));
  2563. myset.Open(CRecordset::forwardOnly, sql);
  2564. myset.GetFieldValue("cot", sql);
  2565. myset.Close();
  2566. count1 = atoi(sql);
  2567. }
  2568. {
  2569. CRecordset myset(pdb2);
  2570. sql = "select count(*) as cot from gudingfeiyong where [id]='" + id + "'";
  2571. myset.Open(CRecordset::forwardOnly, sql);
  2572. myset.GetFieldValue("cot", sql);
  2573. myset.Close();
  2574. count2 = atoi(sql);
  2575. }
  2576. if (count1 > count2)return 0;
  2577. return 1;
  2578. }
  2579. catch (...)
  2580. {
  2581. WriteTextLog("出错在函数check2中");
  2582. }
  2583. return 0;
  2584. }
  2585. BOOL CDBServerDlg::CheckIncomeExist(CDatabase *pdb1, CDatabase *pdb2, CString id, CStringArray *pretarray)
  2586. {
  2587. try
  2588. {
  2589. pretarray->RemoveAll();
  2590. int count1 = 0;
  2591. int count2 = 0;
  2592. CString sql;
  2593. {
  2594. CRecordset myset(pdb1);
  2595. sql.Format("select count(*) as cot from singleincome where [id]=%d", atol(id));
  2596. myset.Open(CRecordset::forwardOnly, sql);
  2597. myset.GetFieldValue("cot", sql);
  2598. myset.Close();
  2599. count1 = atoi(sql);
  2600. }
  2601. {
  2602. CRecordset myset(pdb2);
  2603. sql = "select count(*) as cot from singleincome where [id]='" + id + "'";
  2604. myset.Open(CRecordset::forwardOnly, sql);
  2605. myset.GetFieldValue("cot", sql);
  2606. myset.Close();
  2607. count2 = atoi(sql);
  2608. }
  2609. if (count1 > count2)
  2610. pretarray->Add("0");
  2611. else
  2612. pretarray->Add("1");
  2613. {
  2614. CRecordset myset(pdb1);
  2615. sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id);
  2616. myset.Open(CRecordset::forwardOnly, sql);
  2617. myset.GetFieldValue("cot", sql);
  2618. myset.Close();
  2619. count1 = atoi(sql);
  2620. }
  2621. {
  2622. CRecordset myset(pdb2);
  2623. sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id);
  2624. myset.Open(CRecordset::forwardOnly, sql);
  2625. myset.GetFieldValue("cot", sql);
  2626. myset.Close();
  2627. count2 = atoi(sql);
  2628. }
  2629. if (count1 > count2)
  2630. pretarray->Add("0");
  2631. else
  2632. pretarray->Add("1");
  2633. for (int i = 0; i < pretarray->GetSize(); i++)
  2634. {
  2635. if (pretarray->ElementAt(i) == "0")return 0;
  2636. }
  2637. return 1;
  2638. }
  2639. catch (...)
  2640. {
  2641. WriteTextLog("出错在函数check3中");
  2642. }
  2643. return 0;
  2644. }
  2645. BOOL CDBServerDlg::CheckIncomeMoneyExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  2646. {
  2647. try
  2648. {
  2649. int count1 = 0;
  2650. int count2 = 0;
  2651. CString sql;
  2652. {
  2653. CRecordset myset(pdb1);
  2654. sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id);
  2655. myset.Open(CRecordset::forwardOnly, sql);
  2656. myset.GetFieldValue("cot", sql);
  2657. myset.Close();
  2658. count1 = atoi(sql);
  2659. }
  2660. {
  2661. CRecordset myset(pdb2);
  2662. sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id);
  2663. myset.Open(CRecordset::forwardOnly, sql);
  2664. myset.GetFieldValue("cot", sql);
  2665. myset.Close();
  2666. count2 = atoi(sql);
  2667. }
  2668. if (count1 > count2)return 0;
  2669. return 1;
  2670. }
  2671. catch (...)
  2672. {
  2673. WriteTextLog("出错在函数check3中");
  2674. }
  2675. return 0;
  2676. }
  2677. /************************************************************************/
  2678. /* mark by Jeff
  2679. /* 函数:TransDinDan
  2680. /* 描述:
  2681. /* 参数:
  2682. /* pBeConverted_db:被转换的数据库(源);
  2683. /* pToConverted_db:要转到的数据库(目标);
  2684. /* strOrderNumber: 订单号;
  2685. /* nYear: 要转换的年份;
  2686. /*
  2687. /* 返回:
  2688. /************************************************************************/
  2689. int CDBServerDlg::TransDinDan(CDatabase *pBeConverted_db, CDatabase *pToConverted_db, CString strOrderNumber, int nYear)
  2690. {
  2691. int step = 0;
  2692. CStringArray retarray;
  2693. try
  2694. {
  2695. CString sql, str;
  2696. // CheckDinDanExist返回:1表示正常, 100及以上表示源数据库里记录 > 目标数据库记录;
  2697. if (CheckDinDanExist(pBeConverted_db, pToConverted_db, strOrderNumber, &retarray) == 1)
  2698. return 1;
  2699. step = 1;
  2700. int i;
  2701. CString temp;
  2702. int colcount;
  2703. CODBCFieldInfo fieldinfo;
  2704. int ret = 1;
  2705. // 以下全是insert into 到目录数据库中;
  2706. CRecordset myset(pBeConverted_db);
  2707. try
  2708. {
  2709. if (retarray.ElementAt(0) == "0")
  2710. {
  2711. sql.Format("insert into [%d].[dbo].[dindan] select * from [%s].[dbo].[dindan] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2712. MyExecuteSQL(pBeConverted_db, sql);
  2713. }
  2714. }
  2715. catch (CDBException * e)
  2716. {
  2717. WriteTextLog("step2" + e->m_strError);
  2718. #ifdef _DEBUG
  2719. e->ReportError();
  2720. #endif
  2721. e->Delete();
  2722. ret = 2;
  2723. }
  2724. step = 2;
  2725. try
  2726. {
  2727. if (retarray.ElementAt(1) == "0")
  2728. {
  2729. sql.Format("insert into [%d].[dbo].[dindansp] select * from [%s].[dbo].[dindansp] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2730. MyExecuteSQL(pBeConverted_db, sql);
  2731. }
  2732. }
  2733. catch (CDBException * e)
  2734. {
  2735. WriteTextLog("step3" + e->m_strError);
  2736. #ifdef _DEBUG
  2737. e->ReportError();
  2738. #endif
  2739. e->Delete();
  2740. ret = 3;
  2741. }
  2742. step = 3;
  2743. try
  2744. {
  2745. if (retarray.ElementAt(2) == "0")
  2746. {
  2747. 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);
  2748. MyExecuteSQL(pBeConverted_db, sql);
  2749. }
  2750. }
  2751. catch (CDBException * e)
  2752. {
  2753. WriteTextLog("step4" + e->m_strError);
  2754. #ifdef _DEBUG
  2755. e->ReportError();
  2756. #endif
  2757. e->Delete();
  2758. ret = 4;
  2759. }
  2760. step = 4;
  2761. try
  2762. {
  2763. if (retarray.ElementAt(3) == "0")
  2764. {
  2765. 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);
  2766. MyExecuteSQL(pBeConverted_db, sql);
  2767. }
  2768. }
  2769. catch (CDBException * e)
  2770. {
  2771. WriteTextLog("step5" + e->m_strError);
  2772. #ifdef _DEBUG
  2773. e->ReportError();
  2774. #endif
  2775. e->Delete();
  2776. ret = 5;
  2777. }
  2778. step = 5;
  2779. try
  2780. {
  2781. if (retarray.ElementAt(4) == "0")
  2782. {
  2783. sql.Format("insert into [%d].[dbo].[photoprint] select * from [%s].[dbo].[photoprint] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2784. MyExecuteSQL(pBeConverted_db, sql);
  2785. }
  2786. }
  2787. catch (CDBException * e)
  2788. {
  2789. WriteTextLog("step6" + e->m_strError);
  2790. #ifdef _DEBUG
  2791. e->ReportError();
  2792. #endif
  2793. e->Delete();
  2794. ret = 6;
  2795. }
  2796. step = 6;
  2797. try
  2798. {
  2799. if (retarray.ElementAt(5) == "0")
  2800. {
  2801. sql.Format("insert into [%d].[dbo].[client] select * from [%s].[dbo].[client] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2802. MyExecuteSQL(pBeConverted_db, sql);
  2803. }
  2804. }
  2805. catch (CDBException * e)
  2806. {
  2807. WriteTextLog("step7" + e->m_strError);
  2808. #ifdef _DEBUG
  2809. e->ReportError();
  2810. #endif
  2811. e->Delete();
  2812. ret = 7;
  2813. }
  2814. step = 7;
  2815. try
  2816. {
  2817. if (retarray.ElementAt(6) == "0")
  2818. {
  2819. sql.Format("insert into [%d].[dbo].[burncdreg] select * from [%s].[dbo].[burncdreg] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2820. MyExecuteSQL(pBeConverted_db, sql);
  2821. }
  2822. }
  2823. catch (CDBException * e)
  2824. {
  2825. WriteTextLog("step8" + e->m_strError);
  2826. #ifdef _DEBUG
  2827. e->ReportError();
  2828. #endif
  2829. e->Delete();
  2830. ret = 8;
  2831. }
  2832. step = 8;
  2833. try
  2834. {
  2835. if (retarray.ElementAt(7) == "0")
  2836. {
  2837. sql.Format("insert into [%d].[dbo].[digitalwork] select * from [%s].[dbo].[digitalwork] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2838. MyExecuteSQL(pBeConverted_db, sql);
  2839. }
  2840. }
  2841. catch (CDBException * e)
  2842. {
  2843. WriteTextLog("step9" + e->m_strError);
  2844. #ifdef _DEBUG
  2845. e->ReportError();
  2846. #endif
  2847. e->Delete();
  2848. ret = 9;
  2849. }
  2850. step = 9;
  2851. try
  2852. {
  2853. if (retarray.ElementAt(8) == "0")
  2854. {
  2855. sql.Format("insert into [%d].[dbo].[mywork] select * from [%s].[dbo].[mywork] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2856. MyExecuteSQL(pBeConverted_db, sql);
  2857. }
  2858. }
  2859. catch (CDBException * e)
  2860. {
  2861. WriteTextLog("step10" + e->m_strError);
  2862. #ifdef _DEBUG
  2863. e->ReportError();
  2864. #endif
  2865. e->Delete();
  2866. ret = 10;
  2867. }
  2868. step = 10;
  2869. try
  2870. {
  2871. if (retarray.ElementAt(9) == "0")
  2872. {
  2873. sql.Format("insert into [%d].[dbo].[dindanjd] select * from [%s].[dbo].[dindanjd] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2874. MyExecuteSQL(pBeConverted_db, sql);
  2875. }
  2876. }
  2877. catch (CDBException * e)
  2878. {
  2879. WriteTextLog("step11" + e->m_strError);
  2880. #ifdef _DEBUG
  2881. e->ReportError();
  2882. #endif
  2883. e->Delete();
  2884. ret = 11;
  2885. }
  2886. step = 11;
  2887. try
  2888. {
  2889. if (retarray.ElementAt(10) == "0")
  2890. {
  2891. sql.Format("insert into [%d].[dbo].[dindansp2] select * from [%s].[dbo].[dindansp2] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2892. MyExecuteSQL(pBeConverted_db, sql);
  2893. }
  2894. }
  2895. catch (CDBException * e)
  2896. {
  2897. WriteTextLog("step12" + e->m_strError);
  2898. #ifdef _DEBUG
  2899. e->ReportError();
  2900. #endif
  2901. e->Delete();
  2902. ret = 12;
  2903. }
  2904. step = 12;
  2905. try
  2906. {
  2907. if (retarray.ElementAt(11) == "0")
  2908. {
  2909. sql.Format("insert into [%d].[dbo].[dindansp3] select * from [%s].[dbo].[dindansp3] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
  2910. MyExecuteSQL(pBeConverted_db, sql);
  2911. }
  2912. }
  2913. catch (CDBException * e)
  2914. {
  2915. WriteTextLog("step13" + e->m_strError);
  2916. #ifdef _DEBUG
  2917. e->ReportError();
  2918. #endif
  2919. e->Delete();
  2920. ret = 13;
  2921. }
  2922. if (ret != 1)return 200 + ret;
  2923. // 插入到目标数据库后再到目标数据库里查询是否存在;
  2924. return CheckDinDanExist(pBeConverted_db, pToConverted_db, strOrderNumber, &retarray);
  2925. }
  2926. catch (...)
  2927. {
  2928. CString str;
  2929. str.Format("%d size:%d", step, retarray.GetSize());
  2930. WriteTextLog("出错在函数trans1中-" + str);
  2931. }
  2932. return 0;
  2933. }
  2934. BOOL CDBServerDlg::TransPayOut(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  2935. {
  2936. try
  2937. {
  2938. CString sql;
  2939. if (CheckPayOutExist(pdb1, pdb2, id))return 1;
  2940. int i; CString temp;
  2941. int colcount;
  2942. CODBCFieldInfo fieldinfo;
  2943. BOOL ret = 1;
  2944. CRecordset myset(pdb1);
  2945. try
  2946. {
  2947. sql.Format("insert into [%d].[dbo].[gudingfeiyong] select * from [%s].[dbo].[gudingfeiyong] where id=%d", year, g_nCurConvertDBName, atol(id));
  2948. MyExecuteSQL(pdb1, sql);
  2949. }
  2950. catch (CDBException * e)
  2951. {
  2952. WriteTextLog(e->m_strError);
  2953. #ifdef _DEBUG
  2954. e->ReportError();
  2955. #endif
  2956. e->Delete();
  2957. ret = 0;
  2958. }
  2959. if (ret == 0)return 0;
  2960. return CheckPayOutExist(pdb1, pdb2, id);
  2961. }
  2962. catch (...)
  2963. {
  2964. WriteTextLog("出错在函数trans2中");
  2965. }
  2966. return 0;
  2967. }
  2968. //singleincome
  2969. BOOL CDBServerDlg::TransIncome(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  2970. {
  2971. try
  2972. {
  2973. CString sql;
  2974. CStringArray retarray;
  2975. if (CheckIncomeExist(pdb1, pdb2, id, &retarray))return 1;
  2976. int i; CString temp;
  2977. int colcount;
  2978. CODBCFieldInfo fieldinfo;
  2979. BOOL ret = 1;
  2980. CRecordset myset(pdb1);
  2981. try
  2982. {
  2983. if (retarray.ElementAt(0) == "0")
  2984. {
  2985. sql.Format("insert into [%d].[dbo].[singleincome] select * from [%s].[dbo].[singleincome] where id=%d", year, g_nCurConvertDBName, atol(id));
  2986. MyExecuteSQL(pdb1, sql);
  2987. }
  2988. }
  2989. catch (...)
  2990. {
  2991. ret = 0;
  2992. }
  2993. try
  2994. {
  2995. if (retarray.ElementAt(1) == "0")
  2996. {
  2997. sql.Format("insert into [%d].[dbo].[singleincomemoney] select * from [%s].[dbo].[singleincomemoney] where id='%s'", year, g_nCurConvertDBName, id);
  2998. MyExecuteSQL(pdb1, sql);
  2999. }
  3000. }
  3001. catch (CDBException * e)
  3002. {
  3003. WriteTextLog(e->m_strError);
  3004. #ifdef _DEBUG
  3005. e->ReportError();
  3006. #endif
  3007. e->Delete();
  3008. ret = 0;
  3009. }
  3010. if (ret == 0)return 0;
  3011. return CheckIncomeExist(pdb1, pdb2, id, &retarray);
  3012. }
  3013. catch (...)
  3014. {
  3015. WriteTextLog("出错在函数trans3中");
  3016. }
  3017. return 0;
  3018. }
  3019. BOOL CDBServerDlg::TransIncomeMoney(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3020. {
  3021. try
  3022. {
  3023. CString sql;
  3024. if (CheckIncomeMoneyExist(pdb1, pdb2, id))return 1;
  3025. int i; CString temp;
  3026. int colcount;
  3027. CODBCFieldInfo fieldinfo;
  3028. BOOL ret = 1;
  3029. CRecordset myset(pdb1);
  3030. try
  3031. {
  3032. sql.Format("insert into [%d].[dbo].[singleincomemoney] select * from [%s].[dbo].[singleincomemoney] where id='%s'", year, g_nCurConvertDBName, id);
  3033. MyExecuteSQL(pdb1, sql);
  3034. }
  3035. catch (CDBException * e)
  3036. {
  3037. WriteTextLog(e->m_strError);
  3038. #ifdef _DEBUG
  3039. e->ReportError();
  3040. #endif
  3041. e->Delete();
  3042. ret = 0;
  3043. }
  3044. if (ret == 0)return 0;
  3045. return CheckIncomeMoneyExist(pdb1, pdb2, id);
  3046. }
  3047. catch (...)
  3048. {
  3049. WriteTextLog("出错在函数trans3中");
  3050. }
  3051. return 0;
  3052. }
  3053. BOOL CDBServerDlg::Checkclient2phonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3054. {
  3055. try
  3056. {
  3057. int count1 = 0;
  3058. int count2 = 0;
  3059. CString sql;
  3060. {
  3061. CRecordset myset(pdb1);
  3062. sql = "select count(*) as cot from client2phonerecord where [datetime]='" + id + "'";
  3063. myset.Open(CRecordset::forwardOnly, sql);
  3064. myset.GetFieldValue("cot", sql);
  3065. myset.Close();
  3066. count1 = atoi(sql);
  3067. }
  3068. {
  3069. CRecordset myset(pdb2);
  3070. sql = "select count(*) as cot from client2phonerecord where [datetime]='" + id + "'";
  3071. myset.Open(CRecordset::forwardOnly, sql);
  3072. myset.GetFieldValue("cot", sql);
  3073. myset.Close();
  3074. count2 = atoi(sql);
  3075. }
  3076. if (count1 > count2)return 0;
  3077. return 1;
  3078. }
  3079. catch (...)
  3080. {
  3081. WriteTextLog("出错在函数check3中");
  3082. }
  3083. return 0;
  3084. }
  3085. BOOL CDBServerDlg::Transclient2phonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3086. {
  3087. try
  3088. {
  3089. CString sql;
  3090. if (Checkclient2phonerecordExist(pdb1, pdb2, id))return 1;
  3091. int i; CString temp;
  3092. int colcount;
  3093. CODBCFieldInfo fieldinfo;
  3094. BOOL ret = 1;
  3095. CRecordset myset(pdb1);
  3096. try
  3097. {
  3098. sql.Format("insert into [%d].[dbo].[client2phonerecord] select * from [%s].[dbo].[client2phonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3099. MyExecuteSQL(pdb1, sql);
  3100. }
  3101. catch (...)
  3102. {
  3103. ret = 0;
  3104. }
  3105. if (ret == 0)return 0;
  3106. return Checkclient2phonerecordExist(pdb1, pdb2, id);
  3107. }
  3108. catch (...)
  3109. {
  3110. WriteTextLog("出错在函数trans3中");
  3111. }
  3112. return 0;
  3113. }
  3114. BOOL CDBServerDlg::Checkclient3phonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3115. {
  3116. try
  3117. {
  3118. int count1 = 0;
  3119. int count2 = 0;
  3120. CString sql;
  3121. {
  3122. CRecordset myset(pdb1);
  3123. sql = "select count(*) as cot from client3phonerecord where [datetime]='" + id + "'";
  3124. myset.Open(CRecordset::forwardOnly, sql);
  3125. myset.GetFieldValue("cot", sql);
  3126. myset.Close();
  3127. count1 = atoi(sql);
  3128. }
  3129. {
  3130. CRecordset myset(pdb2);
  3131. sql = "select count(*) as cot from client3phonerecord where [datetime]='" + id + "'";
  3132. myset.Open(CRecordset::forwardOnly, sql);
  3133. myset.GetFieldValue("cot", sql);
  3134. myset.Close();
  3135. count2 = atoi(sql);
  3136. }
  3137. if (count1 > count2)return 0;
  3138. return 1;
  3139. }
  3140. catch (...)
  3141. {
  3142. WriteTextLog("出错在函数check3中");
  3143. }
  3144. return 0;
  3145. }
  3146. BOOL CDBServerDlg::Transclient3phonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3147. {
  3148. try
  3149. {
  3150. CString sql;
  3151. if (Checkclient3phonerecordExist(pdb1, pdb2, id))return 1;
  3152. int i; CString temp;
  3153. int colcount;
  3154. CODBCFieldInfo fieldinfo;
  3155. BOOL ret = 1;
  3156. CRecordset myset(pdb1);
  3157. try
  3158. {
  3159. sql.Format("insert into [%d].[dbo].[client3phonerecord] select * from [%s].[dbo].[client3phonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3160. MyExecuteSQL(pdb1, sql);
  3161. }
  3162. catch (...)
  3163. {
  3164. ret = 0;
  3165. }
  3166. if (ret == 0)return 0;
  3167. return Checkclient3phonerecordExist(pdb1, pdb2, id);
  3168. }
  3169. catch (...)
  3170. {
  3171. WriteTextLog("出错在函数trans3中");
  3172. }
  3173. return 0;
  3174. }
  3175. BOOL CDBServerDlg::Checkclient2phonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3176. {
  3177. try
  3178. {
  3179. int count1 = 0;
  3180. int count2 = 0;
  3181. CString sql;
  3182. {
  3183. CRecordset myset(pdb1);
  3184. sql = "select count(*) as cot from client2phonerecordout where [datetime]='" + id + "'";
  3185. myset.Open(CRecordset::forwardOnly, sql);
  3186. myset.GetFieldValue("cot", sql);
  3187. myset.Close();
  3188. count1 = atoi(sql);
  3189. }
  3190. {
  3191. CRecordset myset(pdb2);
  3192. sql = "select count(*) as cot from client2phonerecordout where [datetime]='" + id + "'";
  3193. myset.Open(CRecordset::forwardOnly, sql);
  3194. myset.GetFieldValue("cot", sql);
  3195. myset.Close();
  3196. count2 = atoi(sql);
  3197. }
  3198. if (count1 > count2)return 0;
  3199. return 1;
  3200. }
  3201. catch (...)
  3202. {
  3203. WriteTextLog("出错在函数check3中");
  3204. }
  3205. return 0;
  3206. }
  3207. BOOL CDBServerDlg::Transclient2phonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3208. {
  3209. try
  3210. {
  3211. CString sql;
  3212. if (Checkclient2phonerecordoutExist(pdb1, pdb2, id))return 1;
  3213. int i; CString temp;
  3214. int colcount;
  3215. CODBCFieldInfo fieldinfo;
  3216. BOOL ret = 1;
  3217. CRecordset myset(pdb1);
  3218. try
  3219. {
  3220. sql.Format("insert into [%d].[dbo].[client2phonerecordout] select * from [%s].[dbo].[client2phonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3221. MyExecuteSQL(pdb1, sql);
  3222. }
  3223. catch (...)
  3224. {
  3225. ret = 0;
  3226. }
  3227. if (ret == 0)return 0;
  3228. return Checkclient2phonerecordoutExist(pdb1, pdb2, id);
  3229. }
  3230. catch (...)
  3231. {
  3232. WriteTextLog("出错在函数trans3中");
  3233. }
  3234. return 0;
  3235. }
  3236. BOOL CDBServerDlg::Checkclient3phonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3237. {
  3238. try
  3239. {
  3240. int count1 = 0;
  3241. int count2 = 0;
  3242. CString sql;
  3243. {
  3244. CRecordset myset(pdb1);
  3245. sql = "select count(*) as cot from client3phonerecordout where [datetime]='" + id + "'";
  3246. myset.Open(CRecordset::forwardOnly, sql);
  3247. myset.GetFieldValue("cot", sql);
  3248. myset.Close();
  3249. count1 = atoi(sql);
  3250. }
  3251. {
  3252. CRecordset myset(pdb2);
  3253. sql = "select count(*) as cot from client3phonerecordout where [datetime]='" + id + "'";
  3254. myset.Open(CRecordset::forwardOnly, sql);
  3255. myset.GetFieldValue("cot", sql);
  3256. myset.Close();
  3257. count2 = atoi(sql);
  3258. }
  3259. if (count1 > count2)return 0;
  3260. return 1;
  3261. }
  3262. catch (...)
  3263. {
  3264. WriteTextLog("出错在函数check3中");
  3265. }
  3266. return 0;
  3267. }
  3268. BOOL CDBServerDlg::Transclient3phonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3269. {
  3270. try
  3271. {
  3272. CString sql;
  3273. if (Checkclient3phonerecordoutExist(pdb1, pdb2, id))return 1;
  3274. int i; CString temp;
  3275. int colcount;
  3276. CODBCFieldInfo fieldinfo;
  3277. BOOL ret = 1;
  3278. CRecordset myset(pdb1);
  3279. try
  3280. {
  3281. sql.Format("insert into [%d].[dbo].[client3phonerecordout] select * from [%s].[dbo].[client3phonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3282. MyExecuteSQL(pdb1, sql);
  3283. }
  3284. catch (...)
  3285. {
  3286. ret = 0;
  3287. }
  3288. if (ret == 0)return 0;
  3289. return Checkclient3phonerecordoutExist(pdb1, pdb2, id);
  3290. }
  3291. catch (...)
  3292. {
  3293. WriteTextLog("出错在函数trans3中");
  3294. }
  3295. return 0;
  3296. }
  3297. BOOL CDBServerDlg::CheckemployeephonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3298. {
  3299. try
  3300. {
  3301. int count1 = 0;
  3302. int count2 = 0;
  3303. CString sql;
  3304. {
  3305. CRecordset myset(pdb1);
  3306. sql = "select count(*) as cot from employeephonerecord where [datetime]='" + id + "'";
  3307. myset.Open(CRecordset::forwardOnly, sql);
  3308. myset.GetFieldValue("cot", sql);
  3309. myset.Close();
  3310. count1 = atoi(sql);
  3311. }
  3312. {
  3313. CRecordset myset(pdb2);
  3314. sql = "select count(*) as cot from employeephonerecord where [datetime]='" + id + "'";
  3315. myset.Open(CRecordset::forwardOnly, sql);
  3316. myset.GetFieldValue("cot", sql);
  3317. myset.Close();
  3318. count2 = atoi(sql);
  3319. }
  3320. if (count1 > count2)return 0;
  3321. return 1;
  3322. }
  3323. catch (...)
  3324. {
  3325. WriteTextLog("出错在函数check3中");
  3326. }
  3327. return 0;
  3328. }
  3329. BOOL CDBServerDlg::Transemployeephonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3330. {
  3331. try
  3332. {
  3333. CString sql;
  3334. if (CheckemployeephonerecordExist(pdb1, pdb2, id))return 1;
  3335. int i; CString temp;
  3336. int colcount;
  3337. CODBCFieldInfo fieldinfo;
  3338. BOOL ret = 1;
  3339. CRecordset myset(pdb1);
  3340. try
  3341. {
  3342. sql.Format("insert into [%d].[dbo].[employeephonerecord] select * from [%s].[dbo].[employeephonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3343. MyExecuteSQL(pdb1, sql);
  3344. }
  3345. catch (...)
  3346. {
  3347. ret = 0;
  3348. }
  3349. if (ret == 0)return 0;
  3350. return CheckemployeephonerecordExist(pdb1, pdb2, id);
  3351. }
  3352. catch (...)
  3353. {
  3354. WriteTextLog("出错在函数trans3中");
  3355. }
  3356. return 0;
  3357. }
  3358. BOOL CDBServerDlg::CheckemployeephonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3359. {
  3360. try
  3361. {
  3362. int count1 = 0;
  3363. int count2 = 0;
  3364. CString sql;
  3365. {
  3366. CRecordset myset(pdb1);
  3367. sql = "select count(*) as cot from employeephonerecordout where [datetime]='" + id + "'";
  3368. myset.Open(CRecordset::forwardOnly, sql);
  3369. myset.GetFieldValue("cot", sql);
  3370. myset.Close();
  3371. count1 = atoi(sql);
  3372. }
  3373. {
  3374. CRecordset myset(pdb2);
  3375. sql = "select count(*) as cot from employeephonerecordout where [datetime]='" + id + "'";
  3376. myset.Open(CRecordset::forwardOnly, sql);
  3377. myset.GetFieldValue("cot", sql);
  3378. myset.Close();
  3379. count2 = atoi(sql);
  3380. }
  3381. if (count1 > count2)return 0;
  3382. return 1;
  3383. }
  3384. catch (...)
  3385. {
  3386. WriteTextLog("出错在函数check3中");
  3387. }
  3388. return 0;
  3389. }
  3390. BOOL CDBServerDlg::Transemployeephonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3391. {
  3392. try
  3393. {
  3394. CString sql;
  3395. if (CheckemployeephonerecordoutExist(pdb1, pdb2, id))return 1;
  3396. int i; CString temp;
  3397. int colcount;
  3398. CODBCFieldInfo fieldinfo;
  3399. BOOL ret = 1;
  3400. CRecordset myset(pdb1);
  3401. try
  3402. {
  3403. sql.Format("insert into [%d].[dbo].[employeephonerecordout] select * from [%s].[dbo].[employeephonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3404. MyExecuteSQL(pdb1, sql);
  3405. }
  3406. catch (...)
  3407. {
  3408. ret = 0;
  3409. }
  3410. if (ret == 0)return 0;
  3411. return CheckemployeephonerecordoutExist(pdb1, pdb2, id);
  3412. }
  3413. catch (...)
  3414. {
  3415. WriteTextLog("出错在函数trans3中");
  3416. }
  3417. return 0;
  3418. }
  3419. BOOL CDBServerDlg::CheckphonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3420. {
  3421. try
  3422. {
  3423. int count1 = 0;
  3424. int count2 = 0;
  3425. CString sql;
  3426. {
  3427. CRecordset myset(pdb1);
  3428. sql = "select count(*) as cot from phonerecord where [datetime]='" + id + "'";
  3429. myset.Open(CRecordset::forwardOnly, sql);
  3430. myset.GetFieldValue("cot", sql);
  3431. myset.Close();
  3432. count1 = atoi(sql);
  3433. }
  3434. {
  3435. CRecordset myset(pdb2);
  3436. sql = "select count(*) as cot from phonerecord where [datetime]='" + id + "'";
  3437. myset.Open(CRecordset::forwardOnly, sql);
  3438. myset.GetFieldValue("cot", sql);
  3439. myset.Close();
  3440. count2 = atoi(sql);
  3441. }
  3442. if (count1 > count2)return 0;
  3443. return 1;
  3444. }
  3445. catch (...)
  3446. {
  3447. WriteTextLog("出错在函数check3中");
  3448. }
  3449. return 0;
  3450. }
  3451. BOOL CDBServerDlg::Transphonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3452. {
  3453. try
  3454. {
  3455. CString sql;
  3456. if (CheckphonerecordExist(pdb1, pdb2, id))return 1;
  3457. int i; CString temp;
  3458. int colcount;
  3459. CODBCFieldInfo fieldinfo;
  3460. BOOL ret = 1;
  3461. CRecordset myset(pdb1);
  3462. try
  3463. {
  3464. sql.Format("insert into [%d].[dbo].[phonerecord] select * from [%s].[dbo].[phonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3465. MyExecuteSQL(pdb1, sql);
  3466. }
  3467. catch (...)
  3468. {
  3469. ret = 0;
  3470. }
  3471. if (ret == 0)return 0;
  3472. return CheckphonerecordExist(pdb1, pdb2, id);
  3473. }
  3474. catch (...)
  3475. {
  3476. WriteTextLog("出错在函数trans3中");
  3477. }
  3478. return 0;
  3479. }
  3480. BOOL CDBServerDlg::CheckphonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3481. {
  3482. try
  3483. {
  3484. int count1 = 0;
  3485. int count2 = 0;
  3486. CString sql;
  3487. {
  3488. CRecordset myset(pdb1);
  3489. sql = "select count(*) as cot from phonerecordout where [datetime]='" + id + "'";
  3490. myset.Open(CRecordset::forwardOnly, sql);
  3491. myset.GetFieldValue("cot", sql);
  3492. myset.Close();
  3493. count1 = atoi(sql);
  3494. }
  3495. {
  3496. CRecordset myset(pdb2);
  3497. sql = "select count(*) as cot from phonerecordout where [datetime]='" + id + "'";
  3498. myset.Open(CRecordset::forwardOnly, sql);
  3499. myset.GetFieldValue("cot", sql);
  3500. myset.Close();
  3501. count2 = atoi(sql);
  3502. }
  3503. if (count1 > count2)return 0;
  3504. return 1;
  3505. }
  3506. catch (...)
  3507. {
  3508. WriteTextLog("出错在函数check3中");
  3509. }
  3510. return 0;
  3511. }
  3512. BOOL CDBServerDlg::Transphonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3513. {
  3514. try
  3515. {
  3516. CString sql;
  3517. if (CheckphonerecordoutExist(pdb1, pdb2, id))return 1;
  3518. int i; CString temp;
  3519. int colcount;
  3520. CODBCFieldInfo fieldinfo;
  3521. BOOL ret = 1;
  3522. CRecordset myset(pdb1);
  3523. try
  3524. {
  3525. sql.Format("insert into [%d].[dbo].[phonerecordout] select * from [%s].[dbo].[phonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3526. MyExecuteSQL(pdb1, sql);
  3527. }
  3528. catch (...)
  3529. {
  3530. ret = 0;
  3531. }
  3532. if (ret == 0)return 0;
  3533. return CheckphonerecordoutExist(pdb1, pdb2, id);
  3534. }
  3535. catch (...)
  3536. {
  3537. WriteTextLog("出错在函数trans3中");
  3538. }
  3539. return 0;
  3540. }
  3541. BOOL CDBServerDlg::CheckunknownphonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3542. {
  3543. try
  3544. {
  3545. int count1 = 0;
  3546. int count2 = 0;
  3547. CString sql;
  3548. {
  3549. CRecordset myset(pdb1);
  3550. sql = "select count(*) as cot from unknownphonerecord where [datetime]='" + id + "'";
  3551. myset.Open(CRecordset::forwardOnly, sql);
  3552. myset.GetFieldValue("cot", sql);
  3553. myset.Close();
  3554. count1 = atoi(sql);
  3555. }
  3556. {
  3557. CRecordset myset(pdb2);
  3558. sql = "select count(*) as cot from unknownphonerecord where [datetime]='" + id + "'";
  3559. myset.Open(CRecordset::forwardOnly, sql);
  3560. myset.GetFieldValue("cot", sql);
  3561. myset.Close();
  3562. count2 = atoi(sql);
  3563. }
  3564. if (count1 > count2)return 0;
  3565. return 1;
  3566. }
  3567. catch (...)
  3568. {
  3569. WriteTextLog("出错在函数check3中");
  3570. }
  3571. return 0;
  3572. }
  3573. BOOL CDBServerDlg::Transunknownphonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3574. {
  3575. try
  3576. {
  3577. CString sql;
  3578. if (CheckunknownphonerecordExist(pdb1, pdb2, id))return 1;
  3579. int i; CString temp;
  3580. int colcount;
  3581. CODBCFieldInfo fieldinfo;
  3582. BOOL ret = 1;
  3583. CRecordset myset(pdb1);
  3584. try
  3585. {
  3586. sql.Format("insert into [%d].[dbo].[unknownphonerecord] select * from [%s].[dbo].[unknownphonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3587. MyExecuteSQL(pdb1, sql);
  3588. }
  3589. catch (...)
  3590. {
  3591. ret = 0;
  3592. }
  3593. if (ret == 0)return 0;
  3594. return CheckunknownphonerecordExist(pdb1, pdb2, id);
  3595. }
  3596. catch (...)
  3597. {
  3598. WriteTextLog("出错在函数trans3中");
  3599. }
  3600. return 0;
  3601. }
  3602. BOOL CDBServerDlg::CheckunknownphonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3603. {
  3604. try
  3605. {
  3606. int count1 = 0;
  3607. int count2 = 0;
  3608. CString sql;
  3609. {
  3610. CRecordset myset(pdb1);
  3611. sql = "select count(*) as cot from unknownphonerecordout where [datetime]='" + id + "'";
  3612. myset.Open(CRecordset::forwardOnly, sql);
  3613. myset.GetFieldValue("cot", sql);
  3614. myset.Close();
  3615. count1 = atoi(sql);
  3616. }
  3617. {
  3618. CRecordset myset(pdb2);
  3619. sql = "select count(*) as cot from unknownphonerecordout where [datetime]='" + id + "'";
  3620. myset.Open(CRecordset::forwardOnly, sql);
  3621. myset.GetFieldValue("cot", sql);
  3622. myset.Close();
  3623. count2 = atoi(sql);
  3624. }
  3625. if (count1 > count2)return 0;
  3626. return 1;
  3627. }
  3628. catch (...)
  3629. {
  3630. WriteTextLog("出错在函数check3中");
  3631. }
  3632. return 0;
  3633. }
  3634. BOOL CDBServerDlg::Transunknownphonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3635. {
  3636. try
  3637. {
  3638. CString sql;
  3639. if (CheckunknownphonerecordoutExist(pdb1, pdb2, id))return 1;
  3640. int i; CString temp;
  3641. int colcount;
  3642. CODBCFieldInfo fieldinfo;
  3643. BOOL ret = 1;
  3644. CRecordset myset(pdb1);
  3645. try
  3646. {
  3647. sql.Format("insert into [%d].[dbo].[unknownphonerecordout] select * from [%s].[dbo].[unknownphonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3648. MyExecuteSQL(pdb1, sql);
  3649. }
  3650. catch (...)
  3651. {
  3652. ret = 0;
  3653. }
  3654. if (ret == 0)return 0;
  3655. return CheckunknownphonerecordoutExist(pdb1, pdb2, id);
  3656. }
  3657. catch (...)
  3658. {
  3659. WriteTextLog("出错在函数trans3中");
  3660. }
  3661. return 0;
  3662. }
  3663. BOOL CDBServerDlg::CheckmisscallrecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3664. {
  3665. try
  3666. {
  3667. int count1 = 0;
  3668. int count2 = 0;
  3669. CString sql;
  3670. {
  3671. CRecordset myset(pdb1);
  3672. sql = "select count(*) as cot from misscallrecord where [datetime]='" + id + "'";
  3673. myset.Open(CRecordset::forwardOnly, sql);
  3674. myset.GetFieldValue("cot", sql);
  3675. myset.Close();
  3676. count1 = atoi(sql);
  3677. }
  3678. {
  3679. CRecordset myset(pdb2);
  3680. sql = "select count(*) as cot from misscallrecord where [datetime]='" + id + "'";
  3681. myset.Open(CRecordset::forwardOnly, sql);
  3682. myset.GetFieldValue("cot", sql);
  3683. myset.Close();
  3684. count2 = atoi(sql);
  3685. }
  3686. if (count1 > count2)return 0;
  3687. return 1;
  3688. }
  3689. catch (...)
  3690. {
  3691. WriteTextLog("出错在函数check3中");
  3692. }
  3693. return 0;
  3694. }
  3695. BOOL CDBServerDlg::Transmisscallrecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3696. {
  3697. try
  3698. {
  3699. CString sql;
  3700. if (CheckmisscallrecordExist(pdb1, pdb2, id))return 1;
  3701. int i;
  3702. CString temp;
  3703. int colcount;
  3704. CODBCFieldInfo fieldinfo;
  3705. BOOL ret = 1;
  3706. CRecordset myset(pdb1);
  3707. try
  3708. {
  3709. sql.Format("insert into [%d].[dbo].[misscallrecord] select * from [%s].[dbo].[misscallrecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
  3710. MyExecuteSQL(pdb1, sql);
  3711. }
  3712. catch (...)
  3713. {
  3714. ret = 0;
  3715. }
  3716. if (ret == 0)return 0;
  3717. return CheckmisscallrecordExist(pdb1, pdb2, id);
  3718. }
  3719. catch (...)
  3720. {
  3721. WriteTextLog("出错在函数trans3中");
  3722. }
  3723. return 0;
  3724. }
  3725. BOOL CDBServerDlg::CheckSendReg(CDatabase *pdb1, CDatabase *pdb2, CString id)
  3726. {
  3727. try
  3728. {
  3729. int count1 = 0;
  3730. int count2 = 0;
  3731. CString sql;
  3732. {
  3733. CRecordset myset(pdb1);
  3734. sql.Format("select count(*) as cot from sendreg where [timestamp]='%s'", id);
  3735. myset.Open(CRecordset::forwardOnly, sql);
  3736. myset.GetFieldValue("cot", sql);
  3737. myset.Close();
  3738. count1 = atoi(sql);
  3739. }
  3740. {
  3741. CRecordset myset(pdb2);
  3742. sql.Format("select count(*) as cot from sendreg where [timestamp]='%s'", id);
  3743. myset.Open(CRecordset::forwardOnly, sql);
  3744. myset.GetFieldValue("cot", sql);
  3745. myset.Close();
  3746. count2 = atoi(sql);
  3747. }
  3748. if (count1 > count2)return 0;
  3749. return 1;
  3750. }
  3751. catch (...)
  3752. {
  3753. WriteTextLog("出错在函数check3中");
  3754. }
  3755. return 0;
  3756. }
  3757. BOOL CDBServerDlg::TransSendReg(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
  3758. {
  3759. try
  3760. {
  3761. CString sql;
  3762. if (CheckSendReg(pdb1, pdb2, id))return 1;
  3763. int i;
  3764. CString temp;
  3765. int colcount;
  3766. CODBCFieldInfo fieldinfo;
  3767. BOOL ret = 1;
  3768. CRecordset myset(pdb1);
  3769. try
  3770. {
  3771. sql.Format("insert into [%d].[dbo].[sendreg] select * from [%s].[dbo].[sendreg] where [timestamp]='%s'", year, g_nCurConvertDBName, id);
  3772. MyExecuteSQL(pdb1, sql);
  3773. }
  3774. catch (...)
  3775. {
  3776. ret = 0;
  3777. }
  3778. if (ret == 0)return 0;
  3779. return CheckSendReg(pdb1, pdb2, id);
  3780. }
  3781. catch (...)
  3782. {
  3783. WriteTextLog("出错在函数trans3中");
  3784. }
  3785. return 0;
  3786. }
  3787. void CDBServerDlg::MyExecuteSQL(CDatabase* pdb, CString sql)
  3788. {
  3789. try
  3790. {
  3791. pdb->ExecuteSQL(sql);
  3792. }
  3793. catch ( CDBException *e)
  3794. {
  3795. WriteTextLog(_T("执行SQL语句出错,系统描述:%s"),e->m_strError);
  3796. #ifdef _DEBUG
  3797. e->ReportError();
  3798. #endif
  3799. e->Delete();
  3800. }
  3801. }
  3802. void CDBServerDlg::MyExecuteSQL(const TCHAR* pfile, const int& nline, const TCHAR* pfunction, CDatabase* pdb, CString sql)
  3803. {
  3804. try
  3805. {
  3806. pdb->ExecuteSQL(sql);
  3807. }
  3808. catch ( CDBException *e)
  3809. {
  3810. WriteTextLog(_T("%s-<%d>-%s,执行SQL语句出错,系统描述:%s"), pfile, nline, pfunction,e->m_strError);
  3811. #ifdef _DEBUG
  3812. e->ReportError();
  3813. #endif
  3814. e->Delete();
  3815. }
  3816. }
  3817. void CDBServerDlg::UpdateDate()
  3818. {
  3819. try
  3820. {
  3821. HWND hwnd = ::FindWindow(NULL, "AutoRun.exe - 应用程序错误");
  3822. if (hwnd)
  3823. {
  3824. HWND child = ::FindWindowEx(hwnd, 0, NULL, "确定");
  3825. CWnd *pWnd = CWnd::FromHandle(child);
  3826. ::PostMessage(hwnd, WM_COMMAND, pWnd->GetDlgCtrlID(), (LPARAM)child);
  3827. }
  3828. CString autorunpath = g_mainpath + "\\AutoRun.exe";
  3829. if (0 == g_bConvertHisAll)
  3830. ShellExecute(NULL, _T("open"), g_mainpath + "\\AutoRun.exe", NULL, NULL, SW_HIDE);
  3831. HANDLE hMutex = ::OpenMutex(NULL, FALSE, _T("lyfzSMSHandle"));
  3832. if (GetLastError() == ERROR_FILE_NOT_FOUND)
  3833. {
  3834. autorunpath = g_mainpath + "\\SMSHandle.exe";
  3835. ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
  3836. }
  3837. if (hMutex) CloseHandle(hMutex);
  3838. #ifdef ENTERPRISE_VERSION
  3839. autorunpath = g_mainpath + "\\DataSyncReceive.exe";
  3840. ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
  3841. autorunpath = g_mainpath + "\\DataSyncSend.exe";
  3842. ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
  3843. autorunpath = g_mainpath + "\\CPhotoFTPReceive.exe";
  3844. ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
  3845. autorunpath = g_mainpath + "\\CPhotoFTPSend.exe";
  3846. ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
  3847. #endif
  3848. }
  3849. catch (...)
  3850. {
  3851. WriteTextLog("出错在函数UpdateDate中");
  3852. }
  3853. }
  3854. BOOL CheckDateOK(CString str)
  3855. {
  3856. try
  3857. {
  3858. CString tip;
  3859. int i;
  3860. CString demo = CTime::GetCurrentTime().Format("%Y-%m-%d");
  3861. if (str.GetLength() != demo.GetLength())
  3862. goto ll;
  3863. //2009-01-01
  3864. if (str.GetAt(4) != '-')
  3865. goto ll;
  3866. if (str.GetAt(7) != '-')
  3867. goto ll;
  3868. for (i = 0; i < str.GetLength(); i++)
  3869. {
  3870. if (i == 4 || i == 7)continue;
  3871. if (str.GetAt(i) < '0' || str.GetAt(i) > '9')
  3872. goto ll;
  3873. }
  3874. }
  3875. catch (...)
  3876. {
  3877. WriteTextLog("出错");
  3878. }
  3879. return 1;
  3880. ll:
  3881. return 0;
  3882. }
  3883. //------------------------------------------------------------------
  3884. // Remark by Jeff:2014.10.11
  3885. // 函数:DelPhoto1
  3886. // 描述:删除指定路径下的订单文件夹;
  3887. // 参数:
  3888. // path: 指定要删除文件的根目录;
  3889. // strOrderNumber: 将要删除的订单号文件夹;
  3890. // 返回:
  3891. //-----------------------------------------------------------------
  3892. BOOL CDBServerDlg::DelPhoto1(CString path, CString strOrderNumber)
  3893. {
  3894. if ( path.IsEmpty() || !PathFileExists(path) )
  3895. {
  3896. //WriteTextLog(_T("路径不存在!"));
  3897. return FALSE;
  3898. }
  3899. path += _T("\\") + strOrderNumber;
  3900. if (PathFileExists(path))
  3901. {
  3902. DeleteDirectory(path);
  3903. return TRUE;
  3904. }
  3905. //WriteTextLog(_T("路径不存在!"));
  3906. return FALSE;
  3907. }
  3908. //-----------------------------------------------------------------------
  3909. // Remark by Jeff 2014.10.22
  3910. // 函数:BakPhoto
  3911. // 描述:对影楼相片进行备份和删除取件相片
  3912. // 参数:#
  3913. // 返回:#
  3914. //
  3915. // 调用关系:
  3916. // 1.BakPhoto()由CDBServerDlg::SetTimer(4) 调用,调用频率2分钟,周期数直到程序结束。
  3917. // 2.CDBServerDlg::SetTimer(4) 由 CDBServerDlg::SetTimer(2) 调用,调用频率10毫秒,只有一个周期。
  3918. // 3.CDBServerDlg::SetTimer(2) 由 CDBServerDlg::OnInitDialog() 调用.
  3919. //-----------------------------------------------------------------------
  3920. void CDBServerDlg::BakPhoto() // Jeff:备份相片/删除取件相片;
  3921. {
  3922. try
  3923. {
  3924. CDatabase *pMaindb = NULL;
  3925. ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
  3926. if ( pMaindb == NULL )
  3927. return;
  3928. CString m_bak1, m_bak2, m_bak3, m_bak4, m_bak6, m_baktime; // Jeff:m_bak6自动备份完毕后自动关机;
  3929. CString m_bakserver1, m_bakserver2, m_bakserver3, m_bakserver4;
  3930. CString msgcheck4, msgtime, msgphones, msgphones2, msgcompanyname;
  3931. CString balance, msgaccount;
  3932. {
  3933. MyLock lock("dbaccessxiao");
  3934. CRstversion rsSt;
  3935. rsSt.m_pDatabase = pMaindb;
  3936. rsSt.Open();
  3937. if (!rsSt.IsEOF())
  3938. {
  3939. m_bak1 = rsSt.m_bak1;
  3940. m_bak2 = rsSt.m_bak2;
  3941. m_bak3 = rsSt.m_bak3;
  3942. m_bak4 = rsSt.m_bak4;
  3943. m_bakserver1 = rsSt.m_bakserver1;
  3944. m_bakserver2 = rsSt.m_bakserver2;
  3945. m_bakserver3 = rsSt.m_bakserver3;
  3946. m_bakserver4 = rsSt.m_bakserver4;
  3947. m_bak6 = rsSt.m_bak6;
  3948. m_baktime = rsSt.m_baktime;
  3949. msgcheck4 = rsSt.msgcheck4;
  3950. msgtime = rsSt.msgtime;
  3951. msgphones = rsSt.msgphones;
  3952. msgphones2 = rsSt.msgphones2;
  3953. msgcompanyname = rsSt.msgcompanyname;
  3954. balance = rsSt.msgbalance;
  3955. msgaccount = rsSt.msgaccount;
  3956. }
  3957. rsSt.Close();
  3958. }
  3959. /////////////检测发短信回财务
  3960. if (msgphones2.IsEmpty() == 0)
  3961. {
  3962. MyLock lock("dbaccessxiao");
  3963. CStringArray array, timearray;
  3964. CString timestamp;
  3965. timestamp = CTime::GetCurrentTime().Format("%Y-%m-%d");
  3966. timestamp += "%";
  3967. CRecordset myset(pMaindb);
  3968. CString sql = "select phones,timestamp from sendregreceive where [timestamp] like '" + timestamp + "' and [content]='001' and [status]='OK'";
  3969. myset.Open(CRecordset::forwardOnly, sql);
  3970. CString phones;
  3971. while (!myset.IsEOF())
  3972. {
  3973. myset.GetFieldValue("phones", phones);
  3974. myset.GetFieldValue("timestamp", timestamp);
  3975. if (msgphones2.Find(phones) != -1)
  3976. {
  3977. array.Add(phones);
  3978. timearray.Add(timestamp);
  3979. }
  3980. myset.MoveNext();
  3981. }
  3982. myset.Close();
  3983. if (array.GetSize())
  3984. {
  3985. CString sql;
  3986. int i = 0;
  3987. //for (int i = 0; i < array.GetSize(); i++)
  3988. for ( i = 0; i < array.GetSize(); i++)
  3989. {
  3990. sql = "update sendregreceive set [status]='' where [timestamp]='" + timearray.ElementAt(i) + "'";
  3991. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  3992. }
  3993. CArray<CStringArray, CStringArray>List11array;
  3994. CArray<CStringArray, CStringArray>List2array;
  3995. CArray<CStringArray, CStringArray>List3array;
  3996. CArray<CStringArray, CStringArray>other2salearray;
  3997. CArray<CStringArray, CStringArray>memberarray;
  3998. CString strdate = CTime::GetCurrentTime().Format("%Y-%m-%d");
  3999. for( int a = g_dbpool.GetSize(); a >= 0 ;a-- )
  4000. {
  4001. CDatabase *pCurdb = NULL;
  4002. ODBCConnGuard ConnGuard1(pCurdb , a - 1, 3000);
  4003. if ( pCurdb == NULL )
  4004. continue;
  4005. CString filter = "[dat]='" + strdate + "'";
  4006. filter = "[dat]='" + strdate + "' and ([sale2type] is null or [sale2type]='')";
  4007. {
  4008. CRecordset myset(pCurdb);
  4009. CString sql = "select count(*) as cot from singleincome"; if (!filter.IsEmpty())sql += " where " + filter;
  4010. myset.Open(CRecordset::forwardOnly, sql);
  4011. myset.GetFieldValue("cot", sql);
  4012. myset.Close();
  4013. int count = atol(sql);
  4014. int oldsize = List2array.GetSize();
  4015. List2array.SetSize(oldsize + count, 1);
  4016. CRstIncomeInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  4017. rsSt.Open();
  4018. int ii = 0;
  4019. while (!rsSt.IsEOF())
  4020. {
  4021. List2array.ElementAt(oldsize + ii).RemoveAll();
  4022. List2array.ElementAt(oldsize + ii).Add(rsSt.id);
  4023. List2array.ElementAt(oldsize + ii).Add(rsSt.name);
  4024. List2array.ElementAt(oldsize + ii).Add(rsSt.money);
  4025. List2array.ElementAt(oldsize + ii).Add(rsSt.date);
  4026. List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
  4027. List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan2);
  4028. List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan3);
  4029. List2array.ElementAt(oldsize + ii).Add(rsSt.bz);
  4030. List2array.ElementAt(oldsize + ii).Add(rsSt.sale2type);
  4031. ii++;
  4032. rsSt.MoveNext(); if (List2array.GetSize() <= ii)break;
  4033. }
  4034. rsSt.Close(); List2array.SetSize(oldsize + ii, 1);
  4035. }
  4036. filter = "[dat]='" + strdate + "'";
  4037. {
  4038. CRecordset myset(pCurdb);
  4039. CString sql = "select count(*) as cot from gudingfeiyong"; if (!filter.IsEmpty())sql += " where " + filter;
  4040. myset.Open(CRecordset::forwardOnly, sql);
  4041. myset.GetFieldValue("cot", sql);
  4042. myset.Close();
  4043. int count = atol(sql);
  4044. int oldsize = List3array.GetSize();
  4045. List3array.SetSize(oldsize + count, 1);
  4046. CRstPayOutInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  4047. rsSt.Open();
  4048. int ii = 0;
  4049. while (!rsSt.IsEOF())
  4050. {
  4051. List3array.ElementAt(oldsize + ii).RemoveAll();
  4052. List3array.ElementAt(oldsize + ii).Add(rsSt.id);
  4053. List3array.ElementAt(oldsize + ii).Add(rsSt.name);
  4054. List3array.ElementAt(oldsize + ii).Add(rsSt.money);
  4055. List3array.ElementAt(oldsize + ii).Add(rsSt.date);
  4056. List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
  4057. List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan2);
  4058. List3array.ElementAt(oldsize + ii).Add(rsSt.bz);
  4059. ii++;
  4060. rsSt.MoveNext(); if (List3array.GetSize() <= ii)break;
  4061. }
  4062. rsSt.Close(); List3array.SetSize(oldsize + ii, 1);
  4063. }
  4064. filter = "[date]='" + strdate + "'";
  4065. {
  4066. CRecordset myset(pCurdb);
  4067. CString sql = "select count(*) as cot from dindanbukuan"; if (!filter.IsEmpty())sql += " where " + filter;
  4068. myset.Open(CRecordset::forwardOnly, sql);
  4069. myset.GetFieldValue("cot", sql);
  4070. myset.Close();
  4071. int count = atol(sql);
  4072. int oldsize = List11array.GetSize();
  4073. List11array.SetSize(oldsize + count, 1);
  4074. CRstBuKuan rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  4075. rsSt.Open();
  4076. int ii = 0;
  4077. while (!rsSt.IsEOF())
  4078. {
  4079. List11array.ElementAt(oldsize + ii).RemoveAll();
  4080. List11array.ElementAt(oldsize + ii).Add(rsSt.m_id);
  4081. List11array.ElementAt(oldsize + ii).Add(rsSt.m_ren);
  4082. List11array.ElementAt(oldsize + ii).Add(rsSt.m_money);
  4083. List11array.ElementAt(oldsize + ii).Add(rsSt.m_bz);
  4084. List11array.ElementAt(oldsize + ii).Add(rsSt.m_kind);
  4085. List11array.ElementAt(oldsize + ii).Add(rsSt.m_date);
  4086. ii++;
  4087. rsSt.MoveNext(); if (List11array.GetSize() <= ii)break;
  4088. }
  4089. rsSt.Close(); List11array.SetSize(oldsize + ii, 1);
  4090. }
  4091. filter = "[date]='" + strdate + "'";
  4092. {
  4093. CRecordset myset(pCurdb);
  4094. CString sql = "select count(*) as cot from singleincomemoneyview"; if (!filter.IsEmpty())sql += " where " + filter;
  4095. myset.Open(CRecordset::forwardOnly, sql);
  4096. myset.GetFieldValue("cot", sql);
  4097. myset.Close();
  4098. int count = atol(sql);
  4099. int oldsize = other2salearray.GetSize();
  4100. other2salearray.SetSize(oldsize + count, 1);
  4101. CRstsingleincomemoneyview rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  4102. rsSt.Open();
  4103. int ii = 0;
  4104. while (!rsSt.IsEOF())
  4105. {
  4106. other2salearray.ElementAt(oldsize + ii).RemoveAll();
  4107. other2salearray.ElementAt(oldsize + ii).Add(rsSt.name);
  4108. other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
  4109. other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan3);
  4110. other2salearray.ElementAt(oldsize + ii).Add(rsSt.sale2type);
  4111. other2salearray.ElementAt(oldsize + ii).Add(rsSt.money);
  4112. other2salearray.ElementAt(oldsize + ii).Add(rsSt.date);
  4113. other2salearray.ElementAt(oldsize + ii).Add(rsSt.clerk);
  4114. other2salearray.ElementAt(oldsize + ii).Add(rsSt.paytype);
  4115. other2salearray.ElementAt(oldsize + ii).Add(rsSt.autoid);
  4116. other2salearray.ElementAt(oldsize + ii).Add(rsSt.financecheck);
  4117. ii++;
  4118. rsSt.MoveNext(); if (other2salearray.GetSize() <= ii)break;
  4119. }
  4120. rsSt.Close(); other2salearray.SetSize(oldsize + ii, 1);
  4121. }
  4122. filter = "[date]='" + strdate + "'";
  4123. {
  4124. CRecordset myset(pCurdb);
  4125. CString sql = "select count(*) as cot from memberview";
  4126. if (!filter.IsEmpty())
  4127. sql += " where " + filter;
  4128. myset.Open(CRecordset::forwardOnly, sql);
  4129. myset.GetFieldValue("cot", sql);
  4130. myset.Close();
  4131. int count = atol(sql);
  4132. int oldsize = memberarray.GetSize();
  4133. memberarray.SetSize(oldsize + count, 1);
  4134. memberviewReg rsSt;
  4135. rsSt.m_pDatabase = pCurdb;
  4136. if (!filter.IsEmpty())
  4137. rsSt.m_strFilter = filter;
  4138. rsSt.Open();
  4139. DWORD ii = 0;
  4140. while (!rsSt.IsEOF())
  4141. {
  4142. memberarray.ElementAt(oldsize + ii).RemoveAll();
  4143. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_id);
  4144. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_memberno);
  4145. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_name);
  4146. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_money);
  4147. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_date);
  4148. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_clerk);
  4149. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_financecheck);
  4150. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_moneytype);
  4151. ii++;
  4152. rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break;
  4153. }
  4154. rsSt.Close(); memberarray.SetSize(oldsize + ii, 1);
  4155. }
  4156. }//
  4157. CString str;
  4158. int pos = 0;
  4159. int dindanshu = 0;
  4160. float income = 0;
  4161. float incomedd = 0;
  4162. float incomebk = 0;
  4163. float incomehq = 0;
  4164. float incomeqt = 0;
  4165. float payout = 0;
  4166. for (i = 0; i < List11array.GetSize(); i++)
  4167. {
  4168. str = List11array.ElementAt(i).ElementAt(2);
  4169. income += atof(str);
  4170. // income2+=atof(str);
  4171. if (List11array.ElementAt(i).ElementAt(3) == "预约收款")
  4172. {
  4173. incomedd += atof(str);
  4174. dindanshu++;
  4175. }
  4176. else if (List11array.ElementAt(i).ElementAt(3) == "预约补款")
  4177. {
  4178. incomebk += atof(str);
  4179. }
  4180. else
  4181. {
  4182. incomehq += atof(str);
  4183. }
  4184. pos++;
  4185. }
  4186. for (i = 0; i < List2array.GetSize(); i++)
  4187. {
  4188. str = List2array.ElementAt(i).ElementAt(2);
  4189. income += atof(str);
  4190. /* if(List2array.ElementAt (i).ElementAt (8)!="")
  4191. {
  4192. income2+=atof(str);
  4193. }*/
  4194. if (List2array.ElementAt(i).ElementAt(8) == "")
  4195. {
  4196. incomeqt += atof(str);
  4197. }
  4198. pos++;
  4199. }
  4200. for (i = 0; i < List3array.GetSize(); i++)
  4201. {
  4202. str = List3array.ElementAt(i).ElementAt(2);
  4203. payout += atof(str);
  4204. pos++;
  4205. }
  4206. for (i = 0; i < other2salearray.GetSize(); i++)
  4207. {
  4208. str = other2salearray.ElementAt(i).ElementAt(4);
  4209. income += atof(str);
  4210. incomehq += atof(str);
  4211. pos++;
  4212. }
  4213. for (i = 0; i < memberarray.GetSize(); i++)
  4214. {
  4215. str = memberarray.ElementAt(i).ElementAt(3);
  4216. income += atof(str);
  4217. pos++;
  4218. }
  4219. CTime tm = CTime::GetCurrentTime();
  4220. CString content = msgcompanyname + tm.Format("%Y-%m-%d");
  4221. content += "财报:";
  4222. str.Format("%d", (int)income);
  4223. ::ConvertToPrice(str);
  4224. content += "收:" + str;
  4225. str.Format("%d", (int)incomedd);
  4226. ::ConvertToPrice(str);
  4227. content += "定:" + str;
  4228. str.Format("%d", (int)incomebk);
  4229. ::ConvertToPrice(str);
  4230. content += "补:" + str;
  4231. str.Format("%d", (int)incomehq);
  4232. ::ConvertToPrice(str);
  4233. content += "后:" + str;
  4234. str.Format("%d", (int)incomeqt);
  4235. ::ConvertToPrice(str);
  4236. content += "其它:" + str;
  4237. str.Format("%d", (int)payout);
  4238. ::ConvertToPrice(str);
  4239. content += "支出:" + str;
  4240. str.Format("%d", (int)(income - payout));
  4241. ::ConvertToPrice(str);
  4242. content += "净收:" + str;
  4243. str.Format("%d", dindanshu);
  4244. content += "定单:" + str;
  4245. if (msgaccount != "")
  4246. {
  4247. if (atoi(balance) < 200)
  4248. {
  4249. content += "您的余额小于两百条,请及时充值。联系电话4006067068";
  4250. }
  4251. else if (atoi(balance) < 500)
  4252. {
  4253. content += "您的余额小于五百条,请及时充值。联系电话4006067068";
  4254. }
  4255. else if (atoi(balance) < 800)
  4256. {
  4257. content += "您的余额小于八百条,请及时充值。联系电话4006067068";
  4258. }
  4259. else if (atoi(balance) < 1000)
  4260. {
  4261. content += "您的余额小于一千条,请及时充值。联系电话4006067068";
  4262. }
  4263. }
  4264. int count = GetLengthEx(content) / MSG_LENGTH;
  4265. if (GetLengthEx(content) % MSG_LENGTH)
  4266. count++;
  4267. int phonenum = 0;
  4268. phonenum = 1;
  4269. count *= phonenum;
  4270. CString scount;
  4271. scount.Format("%d", count);
  4272. CString timestamp = tm.Format("%Y%m%d%H%M%S");
  4273. for (i = 0; i < 1; i++)
  4274. {
  4275. sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + array.ElementAt(i) + "','" + content + "','" + timestamp + "','" + scount + "','0','0','0','系统自动发送')";
  4276. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  4277. }
  4278. }
  4279. }
  4280. /////////////
  4281. if (atoi(msgcheck4) && msgphones != "")
  4282. {//发老板短信
  4283. if (atoi(msgtime) <= CTime::GetCurrentTime().GetHour())
  4284. {
  4285. MyLock lock("dbaccessxiao");
  4286. CString timestamp;
  4287. timestamp = CTime::GetCurrentTime().Format("%Y%m%d");
  4288. timestamp += "%";
  4289. CRecordset myset(pMaindb);
  4290. CString sql = "select count(*) as cot from sendreg where [timestamp] like '" + timestamp + "' and [phones]='" + msgphones + "' and [isautosend]='3'";
  4291. myset.Open(CRecordset::forwardOnly, sql);
  4292. myset.GetFieldValue("cot", sql);
  4293. myset.Close();
  4294. int count = atol(sql);
  4295. if (count == 0)
  4296. {
  4297. CArray<CStringArray, CStringArray>List11array;
  4298. CArray<CStringArray, CStringArray>List2array;
  4299. CArray<CStringArray, CStringArray>List3array;
  4300. CArray<CStringArray, CStringArray>other2salearray;
  4301. CArray<CStringArray, CStringArray>memberarray;
  4302. CString strdate = CTime::GetCurrentTime().Format("%Y-%m-%d");
  4303. for (int a = g_dbpool.GetSize() - 1; a >= 0; a--)
  4304. {
  4305. CDatabase *pCurdb = NULL;
  4306. ODBCConnGuard ConnGuard(pCurdb , a - 1, 3000);
  4307. if ( pCurdb == NULL )
  4308. continue;
  4309. CString filter = "[dat]='" + strdate + "'";
  4310. filter = "[dat]='" + strdate + "' and ([sale2type] is null or [sale2type]='')";
  4311. {
  4312. CRecordset myset(pCurdb);
  4313. CString sql = "select count(*) as cot from singleincome"; if (!filter.IsEmpty())sql += " where " + filter;
  4314. myset.Open(CRecordset::forwardOnly, sql);
  4315. myset.GetFieldValue("cot", sql);
  4316. myset.Close();
  4317. int count = atol(sql);
  4318. int oldsize = List2array.GetSize();
  4319. List2array.SetSize(oldsize + count, 1);
  4320. CRstIncomeInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  4321. rsSt.Open();
  4322. int ii = 0;
  4323. while (!rsSt.IsEOF())
  4324. {
  4325. List2array.ElementAt(oldsize + ii).RemoveAll();
  4326. List2array.ElementAt(oldsize + ii).Add(rsSt.id);
  4327. List2array.ElementAt(oldsize + ii).Add(rsSt.name);
  4328. List2array.ElementAt(oldsize + ii).Add(rsSt.money);
  4329. List2array.ElementAt(oldsize + ii).Add(rsSt.date);
  4330. List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
  4331. List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan2);
  4332. List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan3);
  4333. List2array.ElementAt(oldsize + ii).Add(rsSt.bz);
  4334. List2array.ElementAt(oldsize + ii).Add(rsSt.sale2type);
  4335. ii++;
  4336. rsSt.MoveNext(); if (List2array.GetSize() <= ii)break;
  4337. }
  4338. rsSt.Close(); List2array.SetSize(oldsize + ii, 1);
  4339. }
  4340. filter = "[dat]='" + strdate + "'";
  4341. {
  4342. CRecordset myset(pCurdb);
  4343. CString sql = "select count(*) as cot from gudingfeiyong"; if (!filter.IsEmpty())sql += " where " + filter;
  4344. myset.Open(CRecordset::forwardOnly, sql);
  4345. myset.GetFieldValue("cot", sql);
  4346. myset.Close();
  4347. int count = atol(sql);
  4348. int oldsize = List3array.GetSize();
  4349. List3array.SetSize(oldsize + count, 1);
  4350. CRstPayOutInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  4351. rsSt.Open();
  4352. int ii = 0;
  4353. while (!rsSt.IsEOF())
  4354. {
  4355. List3array.ElementAt(oldsize + ii).RemoveAll();
  4356. List3array.ElementAt(oldsize + ii).Add(rsSt.id);
  4357. List3array.ElementAt(oldsize + ii).Add(rsSt.name);
  4358. List3array.ElementAt(oldsize + ii).Add(rsSt.money);
  4359. List3array.ElementAt(oldsize + ii).Add(rsSt.date);
  4360. List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
  4361. List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan2);
  4362. List3array.ElementAt(oldsize + ii).Add(rsSt.bz);
  4363. ii++;
  4364. rsSt.MoveNext(); if (List3array.GetSize() <= ii)break;
  4365. }
  4366. rsSt.Close(); List3array.SetSize(oldsize + ii, 1);
  4367. }
  4368. filter = "[date]='" + strdate + "'";
  4369. {
  4370. CRecordset myset(pCurdb);
  4371. CString sql = "select count(*) as cot from dindanbukuan"; if (!filter.IsEmpty())sql += " where " + filter;
  4372. myset.Open(CRecordset::forwardOnly, sql);
  4373. myset.GetFieldValue("cot", sql);
  4374. myset.Close();
  4375. int count = atol(sql);
  4376. int oldsize = List11array.GetSize();
  4377. List11array.SetSize(oldsize + count, 1);
  4378. CRstBuKuan rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  4379. rsSt.Open();
  4380. int ii = 0;
  4381. while (!rsSt.IsEOF())
  4382. {
  4383. List11array.ElementAt(oldsize + ii).RemoveAll();
  4384. List11array.ElementAt(oldsize + ii).Add(rsSt.m_id);
  4385. List11array.ElementAt(oldsize + ii).Add(rsSt.m_ren);
  4386. List11array.ElementAt(oldsize + ii).Add(rsSt.m_money);
  4387. List11array.ElementAt(oldsize + ii).Add(rsSt.m_bz);
  4388. List11array.ElementAt(oldsize + ii).Add(rsSt.m_kind);
  4389. List11array.ElementAt(oldsize + ii).Add(rsSt.m_date);
  4390. List11array.ElementAt(oldsize + ii).Add(rsSt.paytype);
  4391. ii++;
  4392. rsSt.MoveNext(); if (List11array.GetSize() <= ii)break;
  4393. }
  4394. rsSt.Close(); List11array.SetSize(oldsize + ii, 1);
  4395. }
  4396. filter = "[date]='" + strdate + "'";
  4397. {
  4398. CRecordset myset(pCurdb);
  4399. CString sql = "select count(*) as cot from singleincomemoneyview"; if (!filter.IsEmpty())sql += " where " + filter;
  4400. myset.Open(CRecordset::forwardOnly, sql);
  4401. myset.GetFieldValue("cot", sql);
  4402. myset.Close();
  4403. int count = atol(sql);
  4404. int oldsize = other2salearray.GetSize();
  4405. other2salearray.SetSize(oldsize + count, 1);
  4406. CRstsingleincomemoneyview rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  4407. rsSt.Open();
  4408. int ii = 0;
  4409. while (!rsSt.IsEOF())
  4410. {
  4411. other2salearray.ElementAt(oldsize + ii).RemoveAll();
  4412. other2salearray.ElementAt(oldsize + ii).Add(rsSt.name);
  4413. other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
  4414. other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan3);
  4415. other2salearray.ElementAt(oldsize + ii).Add(rsSt.sale2type);
  4416. other2salearray.ElementAt(oldsize + ii).Add(rsSt.money);
  4417. other2salearray.ElementAt(oldsize + ii).Add(rsSt.date);
  4418. other2salearray.ElementAt(oldsize + ii).Add(rsSt.clerk);
  4419. other2salearray.ElementAt(oldsize + ii).Add(rsSt.paytype);
  4420. other2salearray.ElementAt(oldsize + ii).Add(rsSt.autoid);
  4421. other2salearray.ElementAt(oldsize + ii).Add(rsSt.financecheck);
  4422. ii++;
  4423. rsSt.MoveNext(); if (other2salearray.GetSize() <= ii)break;
  4424. }
  4425. rsSt.Close(); other2salearray.SetSize(oldsize + ii, 1);
  4426. }
  4427. filter = "[date]='" + strdate + "'";
  4428. {
  4429. CRecordset myset(pCurdb);
  4430. CString sql = "select count(*) as cot from memberview"; if (!filter.IsEmpty())sql += " where " + filter;
  4431. myset.Open(CRecordset::forwardOnly, sql);
  4432. myset.GetFieldValue("cot", sql);
  4433. myset.Close();
  4434. int count = atol(sql);
  4435. int oldsize = memberarray.GetSize();
  4436. memberarray.SetSize(oldsize + count, 1);
  4437. memberviewReg rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  4438. rsSt.Open();
  4439. DWORD ii = 0;
  4440. while (!rsSt.IsEOF())
  4441. {
  4442. memberarray.ElementAt(oldsize + ii).RemoveAll();
  4443. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_id);
  4444. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_memberno);
  4445. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_name);
  4446. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_money);
  4447. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_date);
  4448. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_clerk);
  4449. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_financecheck);
  4450. memberarray.ElementAt(oldsize + ii).Add(rsSt.m_moneytype);
  4451. ii++;
  4452. rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break;
  4453. }
  4454. rsSt.Close(); memberarray.SetSize(oldsize + ii, 1);
  4455. }
  4456. }//
  4457. CString str;
  4458. int pos = 0;
  4459. int dindanshu = 0;
  4460. float income = 0;
  4461. float incomedd = 0;
  4462. float incomebk = 0;
  4463. float incomehq = 0;
  4464. float incomeqt = 0;
  4465. float fStoredCardSpending = 0.0; // 储值卡扣款
  4466. float payout = 0;
  4467. int i = 0;
  4468. for ( i = 0; i < List11array.GetSize(); i++)
  4469. {
  4470. str = List11array.ElementAt(i).ElementAt(2);
  4471. income += atof(str);
  4472. // income2+=atof(str);
  4473. if (List11array.ElementAt(i).ElementAt(3) == "预约收款")
  4474. {
  4475. incomedd += atof(str);
  4476. dindanshu++;
  4477. }
  4478. else if (List11array.ElementAt(i).ElementAt(3) == "预约补款")
  4479. {
  4480. incomebk += atof(str);
  4481. }
  4482. else
  4483. {
  4484. incomehq += atof(str);
  4485. }
  4486. #if JEFF_TEST_ON // 去除储值卡扣费;
  4487. if (List11array.ElementAt(i).ElementAt(6) == "储值卡扣款" || List11array.ElementAt(i).ElementAt(6) == "代金券")
  4488. {
  4489. fStoredCardSpending += atof(str);
  4490. }
  4491. #endif
  4492. pos++;
  4493. }
  4494. for (i = 0; i < List2array.GetSize(); i++)
  4495. {
  4496. str = List2array.ElementAt(i).ElementAt(2);
  4497. income += atof(str);
  4498. /* if(List2array.ElementAt (i).ElementAt (8)!="")
  4499. {
  4500. income2+=atof(str);
  4501. }*/
  4502. if (List2array.ElementAt(i).ElementAt(8) == "")
  4503. {
  4504. incomeqt += atof(str);
  4505. }
  4506. pos++;
  4507. }
  4508. for (i = 0; i < List3array.GetSize(); i++)
  4509. {
  4510. str = List3array.ElementAt(i).ElementAt(2);
  4511. payout += atof(str);
  4512. pos++;
  4513. }
  4514. for (i = 0; i < other2salearray.GetSize(); i++)
  4515. {
  4516. str = other2salearray.ElementAt(i).ElementAt(4);
  4517. income += atof(str);
  4518. incomehq += atof(str);
  4519. pos++;
  4520. }
  4521. for (i = 0; i < memberarray.GetSize(); i++)
  4522. {
  4523. str = memberarray.ElementAt(i).ElementAt(3);
  4524. income += atof(str);
  4525. pos++;
  4526. }
  4527. CTime tm = CTime::GetCurrentTime();
  4528. CString content = msgcompanyname + tm.Format("%Y-%m-%d");
  4529. content += "财报:";
  4530. income -= fStoredCardSpending;
  4531. str.Format("%d", (int)(income)); // 去除储值卡扣款和代金券;
  4532. ::ConvertToPrice(str);
  4533. content += "收:" + str;
  4534. str.Format("%d", (int)incomedd);
  4535. ::ConvertToPrice(str);
  4536. content += "定:" + str;
  4537. str.Format("%d", (int)incomebk);
  4538. ::ConvertToPrice(str);
  4539. content += "补:" + str;
  4540. str.Format("%d", (int)incomehq);
  4541. ::ConvertToPrice(str);
  4542. content += "后:" + str;
  4543. str.Format("%d", (int)incomeqt);
  4544. ::ConvertToPrice(str);
  4545. content += "其它:" + str;
  4546. str.Format("%d", (int)payout);
  4547. ::ConvertToPrice(str);
  4548. content += "支出:" + str;
  4549. str.Format("%d", (int)(income - payout));
  4550. ::ConvertToPrice(str);
  4551. content += "净收:" + str;
  4552. str.Format("%d", dindanshu);
  4553. content += "定单:" + str;
  4554. if (msgaccount != "")
  4555. {
  4556. if (atoi(balance) < 200)
  4557. {
  4558. content += "您的余额小于两百条,请及时充值。联系电话4006067068";
  4559. }
  4560. else if (atoi(balance) < 500)
  4561. {
  4562. content += "您的余额小于五百条,请及时充值。联系电话4006067068";
  4563. }
  4564. else if (atoi(balance) < 800)
  4565. {
  4566. content += "您的余额小于八百条,请及时充值。联系电话4006067068";
  4567. }
  4568. else if (atoi(balance) < 1000)
  4569. {
  4570. content += "您的余额小于一千条,请及时充值。联系电话4006067068";
  4571. }
  4572. }
  4573. int count = GetLengthEx(content) / MSG_LENGTH;
  4574. if (GetLengthEx(content) % MSG_LENGTH)
  4575. count++;
  4576. int phonenum = 0;
  4577. str = msgphones;
  4578. pos = str.Find(",");
  4579. if (pos != -1)
  4580. {
  4581. while (pos != -1)
  4582. {
  4583. phonenum++;
  4584. str = str.Right(str.GetLength() - pos - 1);
  4585. pos = str.Find(",");
  4586. }
  4587. phonenum++;
  4588. }
  4589. else
  4590. phonenum = 1;
  4591. count *= phonenum;
  4592. CString scount;
  4593. scount.Format("%d", count);
  4594. timestamp = tm.Format("%Y%m%d%H%M%S");
  4595. sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + msgphones + "','" + content + "','" + timestamp + "','" + scount + "','0','0','3','系统自动发送')";
  4596. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  4597. }
  4598. }
  4599. }
  4600. BOOL bcheck1 = atoi(m_bak1);
  4601. BOOL bcheck2 = atoi(m_bak2);
  4602. BOOL bcheck3 = atoi(m_bak3);
  4603. BOOL bcheck4 = atoi(m_bak4);
  4604. }
  4605. catch (CException *e)
  4606. {
  4607. TCHAR szError[1024] = { 0 };
  4608. e->GetErrorMessage(szError, 1024);
  4609. WriteTextLog(CString(szError));
  4610. e->Delete();
  4611. WriteTextLog("出错在函数bakphoto中");
  4612. }
  4613. }
  4614. void CDBServerDlg::ShutDown() //Jeff:备份完毕后执行的关机函数;
  4615. {
  4616. try
  4617. {
  4618. // 结束检查服务线程
  4619. TerminateCheckWork();
  4620. CDatabase *pMaindb = NULL;
  4621. ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
  4622. if ( pMaindb == NULL )
  4623. return;
  4624. CString m_bak6;
  4625. {
  4626. CRecordset myset(pMaindb);
  4627. CString sql = "select * from [version]";
  4628. myset.Open(CRecordset::forwardOnly, sql);
  4629. myset.GetFieldValue("bak6", m_bak6);
  4630. myset.Close();
  4631. }
  4632. OnServerStop(); // 停止服务;
  4633. // Jeff.关闭数据库连接,若关机前关闭了数据库的连接,则客户端进行订单无法实现数据库的操作;
  4634. // Jeff.在关机前,不能关闭数据库连接;
  4635. for (int i = 0; i < g_dbHistoryArray.GetSize(); i++)
  4636. {
  4637. g_dbHistoryArray.ElementAt(i)->Close();
  4638. delete g_dbHistoryArray.ElementAt(i);
  4639. }
  4640. ReleaseBranchDB();
  4641. WriteTextLog("备份完成");
  4642. ////////////////
  4643. g_tisks = ::GetTickCount() - g_tisks;
  4644. CString str;
  4645. str.Format("耗时:%d分钟", g_tisks / 60000);
  4646. CStdioFile fp;
  4647. fp.Open(g_mainpath + "\\log.txt", CFile::modeCreate | CFile::modeWrite);
  4648. CTime tm = CTime::GetCurrentTime();
  4649. if (0)//tm.GetHour ()<5)
  4650. {
  4651. CTimeSpan sp(1, 0, 0, 0);
  4652. tm -= sp;
  4653. fp.WriteString(tm.Format("%Y-%m-%d"));
  4654. fp.WriteString("\r\n");
  4655. fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S"));
  4656. fp.WriteString(str);
  4657. }
  4658. else
  4659. {
  4660. fp.WriteString(g_bakdate);
  4661. fp.WriteString("\r\n");
  4662. fp.WriteString(tm.Format("%Y-%m-%d %H:%M:%S"));
  4663. fp.WriteString(str);
  4664. }
  4665. fp.WriteString("\r\n");
  4666. fp.WriteString(g_bakinfo);
  4667. fp.WriteString("\r\n");
  4668. fp.WriteString(g_bakphoto);
  4669. fp.Close();
  4670. // OnButton3();
  4671. // Jeff.备份完成后自动关机;
  4672. if (atoi(m_bak6))
  4673. {
  4674. // Jeff.关闭运行中的线程;
  4675. TerminateThread();
  4676. // Jeff.关闭AutoRun.exe程序;
  4677. DWORD id = FindAppProcessID("AutoRun.exe");
  4678. if (id != -1)
  4679. {
  4680. HANDLE ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, id);
  4681. if (ProcessHandle)TerminateProcess(ProcessHandle, 0);
  4682. }
  4683. // Jeff.移除托盘图标;
  4684. m_TrayIcon.RemoveIcon();
  4685. if (g_pSkinData)delete[]g_pSkinData; g_pSkinData = NULL;
  4686. // Jeff.关闭计算机;
  4687. MyExitWindows();
  4688. }
  4689. else//重启
  4690. {
  4691. TerminateThread();
  4692. m_TrayIcon.RemoveIcon();
  4693. if (g_pSkinData)
  4694. delete[]g_pSkinData;
  4695. g_pSkinData = NULL;
  4696. WriteTextLog("备份完成,服务器重启");
  4697. CDialog::OnCancel();
  4698. }
  4699. }
  4700. catch (...)
  4701. {
  4702. WriteTextLog("出错在函数shutdown中");
  4703. }
  4704. }
  4705. void CDBServerDlg::MyExitWindows()
  4706. {
  4707. try
  4708. {
  4709. UINT t = EWX_SHUTDOWN | EWX_FORCE;
  4710. OSVERSIONINFO osv; //定义一个操作系统信息的结构体
  4711. osv.dwOSVersionInfoSize = sizeof OSVERSIONINFO;
  4712. GetVersionEx(&osv); //查询当前操作系统
  4713. if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) //判断是否是2000/NT
  4714. {
  4715. //下面为向操作系统获取权限操作
  4716. HANDLE hProcess, hToken;
  4717. TOKEN_PRIVILEGES Privileges;
  4718. LUID luid;
  4719. hProcess = GetCurrentProcess();
  4720. //下面为打开当前进程对话
  4721. OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken);
  4722. Privileges.PrivilegeCount = 1;
  4723. LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &luid);
  4724. Privileges.Privileges[0].Luid = luid;
  4725. Privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  4726. AdjustTokenPrivileges(hToken, FALSE, &Privileges, NULL, NULL, NULL);
  4727. ExitWindowsEx(t, 0);
  4728. }
  4729. else
  4730. {
  4731. ExitWindowsEx(t, 0);//调用ExitWindowsEx关闭机器。
  4732. PostQuitMessage(0);
  4733. }
  4734. }
  4735. catch (...)
  4736. {
  4737. WriteTextLog("出错在函数exitwindows中");
  4738. }
  4739. }
  4740. void CDBServerDlg::OnAutorun()
  4741. {
  4742. // TODO: Add your command handler code here
  4743. g_bAutoRun = !g_bAutoRun;
  4744. CString version = _T("Version 1.0");
  4745. AfxGetApp()->WriteProfileInt(version, "brun", g_bAutoRun);
  4746. TCHAR szKey[MAX_PATH];
  4747. HKEY hKey = 0;
  4748. DWORD disp = 0;
  4749. lstrcpy(szKey, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
  4750. if (g_bAutoRun)
  4751. {
  4752. int lResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp);
  4753. if (lResult == ERROR_SUCCESS)
  4754. {
  4755. TCHAR szDir[MAX_PATH];
  4756. ::GetModuleFileName(NULL, szDir, MAX_PATH);
  4757. lResult = RegSetValueEx(hKey, "YLGLDBSERVER", 0, REG_SZ, (const unsigned char*)szDir, lstrlen(szDir));
  4758. RegCloseKey(hKey);
  4759. }
  4760. }
  4761. else
  4762. {
  4763. int lResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp);
  4764. if (lResult == ERROR_SUCCESS)
  4765. {
  4766. RegDeleteValue(hKey, "YLGLDBSERVER");
  4767. RegDeleteKey(hKey, "YLGLDBSERVER");
  4768. RegCloseKey(hKey);
  4769. }
  4770. }
  4771. }
  4772. void CDBServerDlg::GetFileDate()
  4773. {
  4774. CStringArray filesarray;
  4775. CStringArray filesarray2;
  4776. filesarray.Add("AutoUpdate.exe"); // 1.
  4777. filesarray.Add("skin\\1.lia");
  4778. filesarray.Add("skin\\2.lia");
  4779. filesarray.Add("skin\\3.lia");
  4780. filesarray.Add("skin\\4.lia");
  4781. filesarray.Add("skin\\10.lia");
  4782. filesarray.Add("skin\\logo.jpg");
  4783. filesarray.Add("skin\\标题-选片.jpg");
  4784. filesarray.Add("skin\\标题-看设计.jpg");
  4785. filesarray.Add("图片\\欢迎.jpg"); // 10.
  4786. filesarray.Add("图片\\连接.jpg");
  4787. filesarray.Add("图片\\标题.jpg");
  4788. filesarray.Add("图片\\背景.jpg");
  4789. filesarray.Add("图片-红色风格\\欢迎.jpg");
  4790. filesarray.Add("图片-红色风格\\连接.jpg");
  4791. filesarray.Add("图片-红色风格\\标题.jpg");
  4792. filesarray.Add("图片-红色风格\\背景.jpg");
  4793. filesarray.Add("图片-红色风格\\选片.jpg");
  4794. filesarray.Add("图片-红色风格\\看设计.jpg");
  4795. filesarray.Add("skin\\1-red.lia"); // 20.
  4796. filesarray.Add("skin\\2-red.lia");
  4797. filesarray.Add("skin\\10-red.lia");
  4798. filesarray.Add("skin\\6.lia");
  4799. filesarray.Add("图片\\掌中宝.jpg");
  4800. filesarray.Add("regsvr32.exe"); // 25.
  4801. filesarray.Add("MSCHRT20.OCX"); // 26. // Jeff.2014.09.06.添加MSCHRT20.OCX,由服务器传递;
  4802. ///////////////
  4803. filesarray2.Add("AutoUpdate.exe");
  4804. filesarray2.Add("skin\\1.lia");
  4805. filesarray2.Add("skin\\2.lia");
  4806. filesarray2.Add("skin\\3.lia");
  4807. filesarray2.Add("skin\\4.lia");
  4808. filesarray2.Add("skin\\5.lia");
  4809. filesarray2.Add("skin\\10.lia");
  4810. filesarray2.Add("skin\\5-red.lia");
  4811. filesarray2.Add("skin\\10-red.lia");
  4812. filesarray2.Add("图片\\logo.jpg");
  4813. filesarray2.Add("图片\\标题-选片.jpg");
  4814. filesarray2.Add("图片\\标题-看设计.jpg");
  4815. filesarray2.Add("图片\\选片.jpg");
  4816. filesarray2.Add("图片\\看设计.jpg");
  4817. filesarray2.Add("图片\\欢迎.jpg");
  4818. filesarray2.Add("图片\\连接.jpg");
  4819. filesarray2.Add("图片\\标题.jpg");
  4820. filesarray2.Add("图片\\背景.jpg");
  4821. filesarray2.Add("图片-红色风格\\欢迎.jpg");
  4822. filesarray2.Add("图片-红色风格\\连接.jpg");
  4823. filesarray2.Add("图片-红色风格\\标题.jpg");
  4824. filesarray2.Add("图片-红色风格\\背景.jpg");
  4825. filesarray2.Add("skin\\6.lia");
  4826. filesarray2.Add("图片\\掌中宝.jpg");
  4827. filesarray2.Add("regsvr32.exe");
  4828. filesarray2.Add("MSCHRT20.OCX"); // 26. // Jeff.2014.09.06.添加MSCHRT20.OCX,由服务器传递;
  4829. int i = 0;
  4830. //for (int i = 0; i < filesarray.GetSize(); i++)
  4831. for ( i = 0; i < filesarray.GetSize(); i++)
  4832. {
  4833. g_filedatearray.Add(GetModifyTime(g_mainpath + "\\系统文件\\" + filesarray.ElementAt(i)));
  4834. }
  4835. g_filedatearraynew.Copy(filesarray2);
  4836. for (i = 0; i < filesarray2.GetSize(); i++)
  4837. {
  4838. g_filedatearraynew.Add(GetFileSize(g_mainpath + "\\系统文件\\" + filesarray2.ElementAt(i)));
  4839. }
  4840. }
  4841. //extern CString g_sdomain;
  4842. #ifdef ENTERPRISE_VERSION
  4843. CString g_bMain;
  4844. #endif
  4845. void CDBServerDlg::LoadBranchInfo()
  4846. {
  4847. #ifdef ENTERPRISE_VERSION
  4848. try
  4849. {
  4850. ReleaseBranchDB();
  4851. CArray<CStringArray, CStringArray>g_List1array;
  4852. {
  4853. MyLock lock("savebranchinfo");
  4854. CFile fp;
  4855. CString path = g_mainpath + "\\branchinfo.dat";
  4856. if (::PathFileExists(path) == 0)
  4857. return;
  4858. fp.Open(path, CFile::modeRead);
  4859. DWORD leng = fp.GetLength();
  4860. if (leng < sizeof(DWORD) * 2)
  4861. {
  4862. fp.Close();
  4863. return;
  4864. }
  4865. DWORD flag = 0;
  4866. //fp.Seek(-sizeof(DWORD), CFile::end);
  4867. fp.Seek(-(int)sizeof(DWORD), CFile::end);
  4868. fp.Read(&flag, sizeof(DWORD));
  4869. if (flag != 889900)
  4870. {
  4871. fp.Close();
  4872. return;
  4873. }
  4874. fp.SeekToBegin();
  4875. DWORD arraysize;
  4876. fp.Read(&arraysize, sizeof(DWORD));
  4877. if (arraysize > 20)
  4878. {
  4879. fp.Close();
  4880. return;
  4881. }
  4882. BYTE *pData = new BYTE[leng - sizeof(DWORD)];
  4883. fp.Read(pData, leng - sizeof(DWORD));
  4884. fp.Close();
  4885. CMemFile memfile;
  4886. memfile.Attach(pData, leng - sizeof(DWORD));
  4887. CArchive ar(&memfile, CArchive::load);
  4888. g_List1array.SetSize(arraysize, 1);
  4889. for (int ii = 0; ii < g_List1array.GetSize(); ii++)
  4890. g_List1array.ElementAt(ii).Serialize(ar);
  4891. ar.Close();
  4892. memfile.Detach();
  4893. delete[]pData;
  4894. }
  4895. if (g_List1array.GetSize() == 0)
  4896. return;
  4897. // SoftKey ytSoftKey;
  4898. // if(ytSoftKey.Ini()==0)
  4899. {
  4900. int value[8];
  4901. double f[8];
  4902. 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("");
  4903. //运行自定义函数
  4904. int ret = SoftKey::GetInstance()->getdata(&value[0], &value[1], &value[2], &value[3], &value[4], &value[5], &value[6], &value[7],
  4905. &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
  4906. s0, s1, s2, s3, s4, s5, s6, s7);
  4907. if (ret != 0 && ret != -43)
  4908. {
  4909. g_sdomain = "";
  4910. }
  4911. else
  4912. g_sdomain = s1;
  4913. }
  4914. CString str, str2, localname, rights;
  4915. int i = 0;
  4916. for (/*int*/ i = 0; i < g_List1array.GetSize(); i++)
  4917. {
  4918. if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0))
  4919. {
  4920. if (g_List1array.ElementAt(i).GetSize()>5)
  4921. rights = g_List1array.ElementAt(i).ElementAt(5); break;
  4922. }
  4923. }
  4924. for (i = 0; i < g_List1array.GetSize(); i++)
  4925. {
  4926. CString branchname = g_List1array.ElementAt(i).ElementAt(1);
  4927. CString branchip = g_List1array.ElementAt(i).ElementAt(2);
  4928. CString domain = g_List1array.ElementAt(i).ElementAt(0);
  4929. CString dir = g_mainpath + "\\数据\\" + branchname;
  4930. if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0))
  4931. {
  4932. localname = branchname;
  4933. g_bMain = g_List1array.ElementAt(i).ElementAt(3);
  4934. continue;
  4935. }
  4936. CString branchname2 = "," + branchname + ",";
  4937. if (rights.Find(branchname2) == -1)
  4938. continue;
  4939. #ifdef SQLSERVER_VERSION
  4940. if (1)//::PathFileExists (dir))
  4941. {
  4942. /////////////////////////
  4943. g_branchdbarray.Add(NULL);
  4944. g_branchnamearray.Add(branchname);
  4945. g_branchdb2array.Add(NULL);
  4946. g_branchname2array.Add(branchname);
  4947. g_branchiparray.Add(branchip);
  4948. g_branchdomainarray.Add(domain);
  4949. // WriteTextLog(_T("添加分店:")+branchname);
  4950. }
  4951. #endif
  4952. }
  4953. //WriteTextLog(_T("添加本店:")+localname);
  4954. g_branchdbarray.Add(NULL);
  4955. g_branchnamearray.Add(localname);
  4956. g_branchiparray.Add("xxx");
  4957. g_branchdomainarray.Add(g_sdomain);
  4958. }
  4959. catch (...)
  4960. {
  4961. }
  4962. #endif
  4963. }
  4964. void CDBServerDlg::ReleaseBranchDB()
  4965. {
  4966. #ifdef ENTERPRISE_VERSION
  4967. try
  4968. {
  4969. for (int i = 0; i < g_branchdbarray.GetSize(); i++)
  4970. {
  4971. if (g_branchdbarray.ElementAt(i))
  4972. {
  4973. g_branchdbarray.ElementAt(i)->Close();
  4974. delete g_branchdbarray.ElementAt(i);
  4975. }
  4976. }
  4977. g_branchdbarray.RemoveAll();
  4978. g_branchdb2array.RemoveAll();
  4979. g_branchnamearray.RemoveAll();
  4980. g_branchname2array.RemoveAll();
  4981. g_branchiparray.RemoveAll();
  4982. g_branchdomainarray.RemoveAll();
  4983. }
  4984. catch (...)
  4985. {
  4986. WriteTextLog("ReleaseBranchDB出错");
  4987. }
  4988. #endif
  4989. }
  4990. //savebranchinfo
  4991. void CDBServerDlg::LoadBranchInfo2()
  4992. {
  4993. #ifdef ENTERPRISE_VERSION
  4994. try
  4995. {
  4996. ReleaseBranchDB();
  4997. CArray<CStringArray, CStringArray>g_List1array;
  4998. {
  4999. MyLock lock("savebranchinfo");
  5000. CFile fp;
  5001. CString path = g_mainpath + "\\branchinfo.dat";
  5002. if (::PathFileExists(path) == 0)
  5003. return;
  5004. fp.Open(path, CFile::modeRead);
  5005. DWORD leng = fp.GetLength();
  5006. if (leng < sizeof(DWORD) * 2)
  5007. {
  5008. fp.Close(); return;
  5009. }
  5010. DWORD flag;
  5011. //fp.Seek(-sizeof(DWORD), CFile::end);
  5012. fp.Seek(-(int)sizeof(DWORD), CFile::end);
  5013. fp.Read(&flag, sizeof(DWORD));
  5014. if (flag != 889900)
  5015. {
  5016. fp.Close(); return;
  5017. }
  5018. fp.SeekToBegin();
  5019. DWORD arraysize;
  5020. fp.Read(&arraysize, sizeof(DWORD));
  5021. if (arraysize > 20)
  5022. {
  5023. fp.Close();
  5024. return;
  5025. }
  5026. BYTE *pData = new BYTE[leng - sizeof(DWORD)];
  5027. fp.Read(pData, leng - sizeof(DWORD));
  5028. fp.Close();
  5029. CMemFile memfile;
  5030. memfile.Attach(pData, leng - sizeof(DWORD));
  5031. CArchive ar(&memfile, CArchive::load);
  5032. g_List1array.SetSize(arraysize, 1);
  5033. for (int ii = 0; ii < g_List1array.GetSize(); ii++)
  5034. {
  5035. g_List1array.ElementAt(ii).Serialize(ar);
  5036. }
  5037. ar.Close();
  5038. memfile.Detach();
  5039. delete[]pData;
  5040. }
  5041. if (g_List1array.GetSize() == 0)return;
  5042. // SoftKey ytSoftKey;
  5043. // if(ytSoftKey.Ini()==0)
  5044. {
  5045. int value[8];
  5046. double f[8];
  5047. 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("");
  5048. //运行自定义函数
  5049. int ret = SoftKey::GetInstance()->getdata(&value[0], &value[1], &value[2], &value[3], &value[4], &value[5], &value[6], &value[7],
  5050. &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
  5051. s0, s1, s2, s3, s4, s5, s6, s7);
  5052. if (ret != 0 && ret != -43)
  5053. {
  5054. g_sdomain = "";
  5055. }
  5056. else
  5057. g_sdomain = s1;
  5058. }
  5059. CString str, str2, localname, rights;
  5060. int i = 0;
  5061. for (/*int*/ i = 0; i < g_List1array.GetSize(); i++)
  5062. {
  5063. if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0))
  5064. {
  5065. if (g_List1array.ElementAt(i).GetSize()>5)
  5066. rights = g_List1array.ElementAt(i).ElementAt(5); break;
  5067. }
  5068. }
  5069. for (i = 0; i < g_List1array.GetSize(); i++)
  5070. {
  5071. CString branchname = g_List1array.ElementAt(i).ElementAt(1);
  5072. CString branchip = g_List1array.ElementAt(i).ElementAt(2);
  5073. CString domain = g_List1array.ElementAt(i).ElementAt(0);
  5074. CString dir = g_mainpath + "\\数据\\" + branchname;
  5075. if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0))
  5076. {
  5077. localname = branchname;
  5078. g_bMain = g_List1array.ElementAt(i).ElementAt(3);
  5079. continue;
  5080. }
  5081. CString branchname2 = "," + branchname + ",";
  5082. if (rights.Find(branchname2) == -1)
  5083. continue;
  5084. #ifdef SQLSERVER_VERSION
  5085. if (1)//::PathFileExists (dir))
  5086. {
  5087. ////////////////////////
  5088. g_branchdbarray.Add(NULL);
  5089. g_branchnamearray.Add(branchname);
  5090. g_branchdb2array.Add(NULL);
  5091. g_branchname2array.Add(branchname);
  5092. g_branchiparray.Add(branchip);
  5093. g_branchdomainarray.Add(domain);
  5094. }
  5095. #endif
  5096. }
  5097. g_branchdbarray.Add(NULL);
  5098. g_branchnamearray.Add(localname);
  5099. g_branchiparray.Add("xxx");
  5100. g_branchdomainarray.Add(g_sdomain);
  5101. }
  5102. catch (...)
  5103. {
  5104. }
  5105. #endif
  5106. }
  5107. int __cdecl CompareByLabel6(const void *elem1, const void *elem2)
  5108. {
  5109. CStringArray *p1 = (CStringArray*)elem1;
  5110. CStringArray *p2 = (CStringArray*)elem2;
  5111. return atoi(p1->ElementAt(5)) > atoi(p2->ElementAt(5));
  5112. }
  5113. //--------------------------------------------------------------
  5114. // Remark by Jeff 2014.12.16
  5115. // 函数:CheckMemberMsg
  5116. // 描述:
  5117. // 参数:
  5118. // 返回:
  5119. //
  5120. // 调用关系:
  5121. // 1.CheckMemberMsg() 只由 CDBServerDlg::SetTimer(4) 调用,调用频率2分钟,周期数直到程序结束。
  5122. // 2.CDBServerDlg::SetTimer(4) 由 CDBServerDlg::SetTimer(2) 调用,调用频率10毫秒,只有一个周期。
  5123. // 3.CDBServerDlg::SetTimer(2) 由 CDBServerDlg::OnInitDialog() 调用.
  5124. //--------------------------------------------------------------
  5125. void CDBServerDlg::CheckMemberMsg() // Jeff.由定时器SetTimer两分钟执行一次
  5126. {
  5127. try
  5128. {
  5129. CDatabase *pMaindb = NULL;
  5130. ODBCConnGuard ConnGuard( pMaindb, -1, 3000);
  5131. if ( pMaindb == NULL )
  5132. return;
  5133. CString sql = "delete from sendreg where [log]='0/0'";
  5134. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5135. {
  5136. CStringArray idarray;
  5137. CString timestamp;
  5138. CTime tm = CTime::GetCurrentTime();
  5139. tm -= CTimeSpan(0, 1, 0, 0);
  5140. timestamp = tm.Format("%Y%m%d%H%M%S");
  5141. CRecordset myset(pMaindb);
  5142. CString sql = "select [autoid] from sendregdelay where [timestamp]<'" + timestamp + "'";
  5143. myset.Open(CRecordset::forwardOnly, sql);
  5144. while (!myset.IsEOF())
  5145. {
  5146. myset.GetFieldValue("autoid", sql);
  5147. idarray.Add(sql);
  5148. myset.MoveNext();
  5149. }
  5150. myset.Close();
  5151. for (int i = 0; i < idarray.GetSize(); i++)
  5152. {
  5153. // Jeff.deal
  5154. //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)));
  5155. 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)));
  5156. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5157. sql.Format("delete from sendregdelay where [autoid]=%d", atol(idarray.ElementAt(i)));
  5158. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5159. }
  5160. }
  5161. int covertrate = 100;
  5162. CString spoint;
  5163. {
  5164. CRecordset myset(pMaindb);
  5165. CString sql = "select * from version";
  5166. myset.Open(CRecordset::forwardOnly, sql);
  5167. myset.GetFieldValue("rate2", sql);
  5168. myset.Close();
  5169. covertrate = atoi(sql);
  5170. if (covertrate == 0)covertrate = 100;
  5171. }
  5172. CString filter;
  5173. CArray<CStringArray, CStringArray>rulearray;
  5174. CArray<CStringArray, CStringArray>memberarray;
  5175. {
  5176. CRecordset myset(pMaindb);
  5177. CString sql = "select count(*) as cot from msgtemp2";
  5178. if (!filter.IsEmpty())sql += " where " + filter;
  5179. myset.Open(CRecordset::forwardOnly, sql);
  5180. myset.GetFieldValue("cot", sql);
  5181. myset.Close();
  5182. int count = atol(sql);
  5183. rulearray.SetSize(count, 1);
  5184. CRstmsgtemp2 rsSt;
  5185. rsSt.m_pDatabase = pMaindb;
  5186. if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  5187. rsSt.Open();
  5188. DWORD ii = 0;
  5189. while (!rsSt.IsEOF())
  5190. {
  5191. rulearray.ElementAt(ii).RemoveAll();
  5192. rulearray.ElementAt(ii).Add(rsSt.name);
  5193. rulearray.ElementAt(ii).Add(rsSt.content1);
  5194. rulearray.ElementAt(ii).Add(rsSt.content2);
  5195. rulearray.ElementAt(ii).Add(rsSt.check1);
  5196. rulearray.ElementAt(ii).Add(rsSt.check2);
  5197. rulearray.ElementAt(ii).Add(rsSt.point);
  5198. ii++;
  5199. rsSt.MoveNext();
  5200. if (rulearray.GetSize() <= ii)break;
  5201. }
  5202. rsSt.Close(); rulearray.SetSize(ii, 1);
  5203. }
  5204. if (rulearray.GetSize() == 0)return;
  5205. qsort(static_cast<void*>(&rulearray[0]), rulearray.GetSize(), sizeof(rulearray[0]), CompareByLabel6);
  5206. /////////////
  5207. {
  5208. CRecordset myset(pMaindb);
  5209. CString sql = "select count(*) as cot from membermanage"; if (!filter.IsEmpty())sql += " where " + filter;
  5210. myset.Open(CRecordset::forwardOnly, sql);
  5211. myset.GetFieldValue("cot", sql);
  5212. myset.Close();
  5213. memberarray.SetSize(atol(sql), 1);
  5214. RstMemberReg rsSt;
  5215. rsSt.m_pDatabase = pMaindb;
  5216. if (!filter.IsEmpty())rsSt.m_strFilter = filter;
  5217. rsSt.Open();
  5218. DWORD ii = 0;
  5219. if (covertrate != 100)
  5220. {
  5221. while (!rsSt.IsEOF())
  5222. {
  5223. memberarray.ElementAt(ii).RemoveAll();
  5224. memberarray.ElementAt(ii).Add(rsSt.m_memberno);
  5225. memberarray.ElementAt(ii).Add(rsSt.m_name);
  5226. memberarray.ElementAt(ii).Add(rsSt.m_sex);
  5227. memberarray.ElementAt(ii).Add(rsSt.m_phone);
  5228. spoint.Format("%d", atoi(rsSt.m_money)*covertrate / 100);
  5229. memberarray.ElementAt(ii).Add(spoint);
  5230. memberarray.ElementAt(ii).Add(rsSt.m_sendmark1);
  5231. memberarray.ElementAt(ii).Add(rsSt.m_sendmark2);
  5232. ii++;
  5233. rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break;
  5234. }
  5235. }
  5236. else
  5237. {
  5238. while (!rsSt.IsEOF())
  5239. {
  5240. memberarray.ElementAt(ii).RemoveAll();
  5241. memberarray.ElementAt(ii).Add(rsSt.m_memberno);
  5242. memberarray.ElementAt(ii).Add(rsSt.m_name);
  5243. memberarray.ElementAt(ii).Add(rsSt.m_sex);
  5244. memberarray.ElementAt(ii).Add(rsSt.m_phone);
  5245. memberarray.ElementAt(ii).Add(rsSt.m_money);
  5246. memberarray.ElementAt(ii).Add(rsSt.m_sendmark1);
  5247. memberarray.ElementAt(ii).Add(rsSt.m_sendmark2);
  5248. ii++;
  5249. rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break;
  5250. }
  5251. }
  5252. rsSt.Close(); memberarray.SetSize(ii, 1);
  5253. }
  5254. CString memberno, name, sex, phone, point, mark1, mark2, rulename, rulecheck1, rulecheck2, rulepoint, rulecontent1, rulecontent2;
  5255. for (int i = 0; i < memberarray.GetSize(); i++)
  5256. {
  5257. memberno = memberarray.ElementAt(i).ElementAt(0);
  5258. name = memberarray.ElementAt(i).ElementAt(1);
  5259. sex = memberarray.ElementAt(i).ElementAt(2);
  5260. phone = memberarray.ElementAt(i).ElementAt(3);
  5261. point = memberarray.ElementAt(i).ElementAt(4);
  5262. mark1 = "," + memberarray.ElementAt(i).ElementAt(5) + ",";
  5263. mark2 = "," + memberarray.ElementAt(i).ElementAt(6) + ",";
  5264. if (atoi(point) == 0)continue;
  5265. if (phone.IsEmpty())continue;
  5266. if (-1 == CheckPhoneType(phone))continue;
  5267. int j = 0;
  5268. for (/*int*/ j = 0; j < rulearray.GetSize(); j++)
  5269. {
  5270. if (mark1.GetLength()>4000)break;
  5271. rulename = "," + rulearray.ElementAt(j).ElementAt(0) + ",";
  5272. rulecontent1 = name + rulearray.ElementAt(j).ElementAt(1);
  5273. rulecontent2 = name + rulearray.ElementAt(j).ElementAt(2);
  5274. rulecheck1 = rulearray.ElementAt(j).ElementAt(3);
  5275. rulecheck2 = rulearray.ElementAt(j).ElementAt(4);
  5276. rulepoint = rulearray.ElementAt(j).ElementAt(5);
  5277. if (atoi(rulecheck1) == 0 && atoi(rulecheck2) == 0)continue;
  5278. if (atoi(rulecheck1))
  5279. {
  5280. if (rulecontent1.IsEmpty())continue;
  5281. if (mark1.Find(rulename) != -1)break;
  5282. if (atoi(point) >= atoi(rulepoint))continue;
  5283. if (atoi(point) < atoi(rulepoint) * 80 / 100)continue;
  5284. // if(sex=="男")
  5285. // rulecontent1.Replace ("xxx先生/女士", name+"先生");
  5286. // else
  5287. // rulecontent1.Replace ("xxx先生/女士", name+"女士");
  5288. int count = GetLengthEx(rulecontent1) / MSG_LENGTH;
  5289. if (GetLengthEx(rulecontent1) % MSG_LENGTH)
  5290. count++;
  5291. int phonenum = 1;
  5292. count *= phonenum;
  5293. CString scount;
  5294. scount.Format("%d", count);
  5295. CString timestamp = CTime::GetCurrentTime().Format("%Y%m%d%H%M%S");
  5296. CString sql;
  5297. mark1.TrimLeft(",");
  5298. mark1.TrimRight(",");
  5299. if (mark1.IsEmpty() == 0)
  5300. mark1 += ",";
  5301. rulename.TrimLeft(",");
  5302. rulename.TrimRight(",");
  5303. mark1 += rulename;
  5304. sql = "update membermanage set sendmark1='" + mark1 + "' where memberno='" + memberno + "'";
  5305. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5306. mark1 = "," + mark1 + ",";
  5307. sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + phone + "','" + rulecontent1 + "','" + timestamp + "','" + scount + "','0','0','0','系统自动发送')";
  5308. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5309. }
  5310. }
  5311. ///////////////////
  5312. BOOL bSended = 0;
  5313. for (j = 0; j < rulearray.GetSize(); j++)
  5314. {
  5315. if (mark2.GetLength() > 4000)break;
  5316. if (bSended)break;
  5317. rulename = "," + rulearray.ElementAt(j).ElementAt(0) + ",";
  5318. rulecontent1 = name + rulearray.ElementAt(j).ElementAt(1);
  5319. rulecontent2 = name + rulearray.ElementAt(j).ElementAt(2);
  5320. rulecheck1 = rulearray.ElementAt(j).ElementAt(3);
  5321. rulecheck2 = rulearray.ElementAt(j).ElementAt(4);
  5322. rulepoint = rulearray.ElementAt(j).ElementAt(5);
  5323. if (atoi(rulecheck1) == 0 && atoi(rulecheck2) == 0)continue;
  5324. if (atoi(rulecheck2))
  5325. {
  5326. if (rulecontent2.IsEmpty())continue;
  5327. if (mark2.Find(rulename) != -1)break;
  5328. if (atoi(point) < atoi(rulepoint))continue;
  5329. // if(sex=="男")
  5330. // rulecontent2.Replace ("xxx先生/女士", name+"先生");
  5331. // else
  5332. // rulecontent2.Replace ("xxx先生/女士", name+"女士");
  5333. int count = GetLengthEx(rulecontent2) / MSG_LENGTH;
  5334. if (GetLengthEx(rulecontent2) % MSG_LENGTH)
  5335. count++;
  5336. int phonenum = 1;
  5337. count *= phonenum;
  5338. CString scount;
  5339. scount.Format("%d", count);
  5340. CString timestamp = CTime::GetCurrentTime().Format("%Y%m%d%H%M%S");
  5341. CString sql;
  5342. mark2.TrimLeft(",");
  5343. mark2.TrimRight(",");
  5344. if (mark2.IsEmpty() == 0)
  5345. mark2 += ",";
  5346. rulename.TrimLeft(",");
  5347. rulename.TrimRight(",");
  5348. mark2 += rulename;
  5349. sql = "update membermanage set sendmark2='" + mark2 + "' where memberno='" + memberno + "'";
  5350. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5351. mark2 = "," + mark2 + ",";
  5352. sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + phone + "','" + rulecontent2 + "','" + timestamp + "','" + scount + "','0','0','0','系统自动发送')";
  5353. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5354. bSended = 1;
  5355. }
  5356. }
  5357. }
  5358. }
  5359. catch (CDBException *e)
  5360. {
  5361. WriteTextLog(_T("%s-<%d>-%s,%s"), __FILE__, __LINE__, __FUNCTION__, e->m_strError);
  5362. #ifdef _DEBUG
  5363. e->ReportError();
  5364. #endif
  5365. e->Delete();
  5366. }
  5367. }
  5368. void CDBServerDlg::CheckBakState() // Jeff.检查数据库bakstate表;
  5369. {
  5370. try
  5371. {
  5372. CDatabase* pMaindb = NULL;
  5373. ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
  5374. if ( pMaindb == NULL )
  5375. return;
  5376. CString filter = _T("");
  5377. CArray<CStringArray, CStringArray> strArray;
  5378. CRecordset myset(pMaindb);
  5379. CString sql = "select count(*) as cot from bakstate";
  5380. if (!filter.IsEmpty())
  5381. sql += " where " + filter;
  5382. myset.Open(CRecordset::forwardOnly, sql);
  5383. myset.GetFieldValue("cot", sql);
  5384. myset.Close();
  5385. int count = atol(sql);
  5386. strArray.SetSize(count, 1);
  5387. //备份记录
  5388. CRstbakstate rsSt;
  5389. rsSt.m_pDatabase = pMaindb;
  5390. if (!filter.IsEmpty())
  5391. rsSt.m_strFilter = filter;
  5392. rsSt.Open();
  5393. int ii = 0;
  5394. while (!rsSt.IsEOF())
  5395. {
  5396. strArray.ElementAt(ii).RemoveAll();
  5397. strArray.ElementAt(ii).Add(rsSt.date);
  5398. strArray.ElementAt(ii).Add(rsSt.photo);
  5399. strArray.ElementAt(ii).Add(rsSt.info);
  5400. ii++;
  5401. rsSt.MoveNext();
  5402. if (strArray.GetSize() <= ii)
  5403. break;
  5404. }
  5405. rsSt.Close();
  5406. //只保存7天记录
  5407. strArray.SetSize(ii, 1);
  5408. while (strArray.GetSize() > 7)
  5409. {
  5410. CString sql = "delete from bakstate where [date]='" + strArray.ElementAt(0).ElementAt(0) + "'";
  5411. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5412. strArray.RemoveAt(0);
  5413. }
  5414. CString path = _T("");
  5415. path.Format("%s\\log.txt", g_mainpath);
  5416. if (::PathFileExists(path))
  5417. {
  5418. CString str;
  5419. CStdioFile fp;
  5420. if (fp.Open(path, CFile::modeRead))
  5421. {
  5422. CString temp;
  5423. fp.ReadString(temp);
  5424. CString date = temp;
  5425. date.TrimRight();
  5426. while(!feof(fp.m_pStream))
  5427. {
  5428. fp.ReadString(temp);
  5429. str += temp;
  5430. }
  5431. fp.Close();
  5432. if (date.GetLength() != 10)
  5433. return;
  5434. BOOL bBak = 0;
  5435. int i = 0;
  5436. for (int i = 0; i < strArray.GetSize(); i++)
  5437. {
  5438. if (date == strArray.ElementAt(i).ElementAt(0))
  5439. {
  5440. bBak = 1;
  5441. break;
  5442. }
  5443. }
  5444. if (bBak == 0)
  5445. {
  5446. CString state1 = "0";
  5447. CString state2 = "0";
  5448. if (str.Find("照片备份成功") != -1)state1 = "1";
  5449. if (str.Find("资料备份成功") != -1)state2 = "1";
  5450. sql = "insert into bakstate([date],[photo],[info])values('" + date + "','" + state1 + "','" + state2 + "')";
  5451. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5452. }
  5453. else
  5454. {
  5455. CString state1 = "0";
  5456. CString state2 = "0";
  5457. if (str.Find("照片备份成功") != -1)state1 = "1";
  5458. if (str.Find("资料备份成功") != -1)state2 = "1";
  5459. sql = "update bakstate set [photo]='" + state1 + "',[info]='" + state2 + "' where [date]='" + date + "'";
  5460. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5461. }
  5462. //判断昨天
  5463. CTime tm = CTime::GetCurrentTime();
  5464. CTimeSpan dt(1, 0, 0, 0);
  5465. tm -= dt;
  5466. CString yesterday = tm.Format("%Y-%m-%d");
  5467. for (i = 0; i < strArray.GetSize(); i++)
  5468. {
  5469. if (yesterday == strArray.ElementAt(i).ElementAt(0))return;
  5470. }
  5471. if (yesterday == date)return;
  5472. sql = "insert into bakstate([date],[photo],[info])values('" + yesterday + "','0','0')";
  5473. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5474. }
  5475. else
  5476. {
  5477. CTime tm = CTime::GetCurrentTime();
  5478. CTimeSpan dt(1, 0, 0, 0);
  5479. tm -= dt;
  5480. sql = "insert into bakstate([date],[photo],[info])values('" + tm.Format("%Y-%m-%d") + "','0','0')";
  5481. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5482. }
  5483. }
  5484. else
  5485. {
  5486. //昨天没备份,插入一条没有备份的记录
  5487. CTime tm = CTime::GetCurrentTime();
  5488. CTimeSpan dt(1, 0, 0, 0);
  5489. tm -= dt;
  5490. for (int i = 0; i < strArray.GetSize(); i++)
  5491. {
  5492. if (tm.Format("%Y-%m-%d") == strArray.ElementAt(i).ElementAt(0))
  5493. return;
  5494. }
  5495. sql = "insert into bakstate([date],[photo],[info])values('" + tm.Format("%Y-%m-%d") + "','0','0')";
  5496. MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
  5497. }
  5498. }
  5499. catch (...)
  5500. {
  5501. WriteTextLog("出错3");
  5502. }
  5503. }
  5504. //数据备份
  5505. CString CDBServerDlg::GetRegCode(int m_id, int m_time1, int m_time2)
  5506. {
  5507. TCHAR DevicePath[260];
  5508. if (FindPort(0, DevicePath) != 0)
  5509. return "";
  5510. int version;
  5511. GetIDVersion((DWORD*)&m_id, &version, DevicePath);
  5512. int d[8]; double f[8];
  5513. int idtemp = 123456;
  5514. char s0[50] = "", s1[50] = "", s2[50] = "", s3[50] = "", s4[50] = "", s5[50] = "", s6[50] = "", s7[50] = "";
  5515. //运行自定义函数
  5516. // SoftKey ytSoftKey;
  5517. int ret = 0;//ytSoftKey.Ini();
  5518. if (ret != 0)
  5519. {
  5520. return "";
  5521. }
  5522. //////////////////////////////////////////////////////////////////////////
  5523. // timedog1是对d0,d1,d2,d3进行3DES加密;
  5524. // 对锁id加密;
  5525. // 对123456加密;
  5526. // 对m_time1可运行时间加密;
  5527. // 对m_time2已运行时间加密;
  5528. ret = SoftKey::GetInstance()->timedog1(&m_id, &idtemp, &m_time1, &m_time2, &d[4], &d[5], &d[6], &d[7],
  5529. &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
  5530. s0, s1, s2, s3, s4, s5, s6, s7);
  5531. if (ret != 0 && ret != -43)
  5532. {
  5533. return "";
  5534. }
  5535. CString str = "";
  5536. CString temp, temp2;
  5537. /////////////////////////////////////////
  5538. temp.Format("%d", abs(m_id));
  5539. int leng = temp.GetLength();
  5540. if (m_id < 0)
  5541. temp2 = "1";
  5542. else
  5543. temp2 = "0";
  5544. temp = temp2 + temp;
  5545. temp2.Format("%02d", leng);
  5546. temp = temp2 + temp;
  5547. str += temp;
  5548. //////////////////////////////////两位长度, 1为负, 0为正, 数据区
  5549. temp.Format("%d", abs(m_time1));
  5550. leng = temp.GetLength();
  5551. if (m_time1 < 0)
  5552. temp2 = "1";
  5553. else
  5554. temp2 = "0";
  5555. temp = temp2 + temp;
  5556. temp2.Format("%02d", leng);
  5557. temp = temp2 + temp;
  5558. str += temp;
  5559. //////////////////////////////////两位长度, 1为负, 0为正, 数据区
  5560. temp.Format("%d", abs(m_time2));
  5561. leng = temp.GetLength();
  5562. if (m_time2 < 0)
  5563. temp2 = "1";
  5564. else
  5565. temp2 = "0";
  5566. temp = temp2 + temp;
  5567. temp2.Format("%02d", leng);
  5568. temp = temp2 + temp;
  5569. str += temp;
  5570. //////////////////////////////////两位长度, 1为负, 0为正, 数据区
  5571. temp.Format("%d", abs(idtemp));
  5572. leng = temp.GetLength();
  5573. if (idtemp < 0)
  5574. temp2 = "1";
  5575. else
  5576. temp2 = "0";
  5577. temp = temp2 + temp;
  5578. temp2.Format("%02d", leng);
  5579. temp = temp2 + temp;
  5580. str += temp;
  5581. return str;
  5582. }
  5583. int g_ndogtimes = 0;
  5584. void CDBServerDlg::CheckRegCode() // 检查注册码信息;
  5585. {
  5586. char path[MAX_PATH];
  5587. ::GetSystemDirectory(path, MAX_PATH);
  5588. CString sysdir = path;
  5589. sysdir += "\\authcode.txt";
  5590. CStdioFile fp;
  5591. CString authcode;
  5592. if (fp.Open(sysdir, CFile::modeRead))
  5593. {
  5594. fp.ReadString(authcode);
  5595. fp.Close();
  5596. }
  5597. ::DeleteFile(sysdir); // 删除authcode.txt文件;
  5598. authcode.TrimLeft();
  5599. authcode.TrimRight();
  5600. authcode.Replace("\n", "");
  5601. authcode.Replace("\r", "");
  5602. if (authcode.GetLength() != 240)
  5603. {
  5604. return;
  5605. }
  5606. TCHAR DevicePath[260];
  5607. if (FindPort(0, DevicePath) != 0)
  5608. return;
  5609. DWORD OutID;
  5610. int version;
  5611. GetIDVersion(&OutID, &version, DevicePath);
  5612. CString str1, str2, str3, str4, str5;
  5613. str1 = authcode.Mid(0, 48);
  5614. str2 = authcode.Mid(48, 48);
  5615. str3 = authcode.Mid(96, 48);
  5616. str4 = authcode.Mid(144, 48);
  5617. str5 = authcode.Mid(192, 48);
  5618. // SoftKey ytSoftKey;
  5619. int ret = 0;//ytSoftKey.Ini();
  5620. if (ret != 0)
  5621. {
  5622. return;
  5623. }
  5624. int d[8]; double f[8];
  5625. char s0[50] = "", s1[50] = "", s2[50] = "", s3[50] = "", s4[50] = "", s5[50] = "", s6[50] = "", s7[50] = "";
  5626. //运行自定义函数
  5627. sprintf(s0, "%s", str1);
  5628. sprintf(s1, "%s", str2);
  5629. sprintf(s2, "%s", str3);
  5630. sprintf(s3, "%s", str4);
  5631. sprintf(s4, "%s", str5);
  5632. //运行自定义函数
  5633. ret = SoftKey::GetInstance()->timedog2(&d[0], &d[1], &d[2], &d[3], &d[4], &d[5], &d[6], &d[7],
  5634. &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
  5635. s0, s1, s2, s3, s4, s5, s6, s7);
  5636. if (ret != 0 && ret != -43)
  5637. {
  5638. return;
  5639. }
  5640. str1 = s0;
  5641. str2 = s1;
  5642. str3 = s2;
  5643. str4 = s3;
  5644. str5 = s4;
  5645. authcode = str1;
  5646. authcode += str2;
  5647. authcode += str3;
  5648. authcode += str4;
  5649. authcode += str5;
  5650. str1 += str2;
  5651. str3 += str4;
  5652. DWORD id = atoi(str5.Right(8));
  5653. str5 = str5.Left(12);
  5654. if (id != OutID)
  5655. {
  5656. return;
  5657. }
  5658. TCHAR HKey[50] = "ffffffff", LKey[50] = "ffffffff";
  5659. TCHAR WHKey[41] = "0", WLKey[41] = "0";
  5660. TCHAR year[10], month[10], day[10], hour[10], minute[10], second[10];
  5661. sprintf(WHKey, "%s", str1);
  5662. sprintf(WLKey, "%s", str3);
  5663. CString temp;
  5664. temp = str5.Left(4);
  5665. str5 = str5.Right(8);
  5666. sprintf(year, "%s", temp);
  5667. temp = str5.Left(2);
  5668. str5 = str5.Right(6);
  5669. sprintf(month, "%s", temp);
  5670. temp = str5.Left(2);
  5671. str5 = str5.Right(4);
  5672. sprintf(day, "%s", temp);
  5673. temp = str5.Left(2);
  5674. str5 = str5.Right(2);
  5675. sprintf(hour, "%s", temp);
  5676. sprintf(minute, "%s", str5);
  5677. sprintf(second, "%s", "0");
  5678. ret = WriteTimeAuthToEprom(30128, HKey, LKey, WHKey, WLKey, id, year, month, day, hour, minute, DevicePath);
  5679. if (ret == 0)
  5680. {
  5681. TCHAR year2[10], month2[10], day2[10], hour2[10], minute2[10], second2[10];
  5682. GetRunTimer(year2, month2, day2, hour2, minute2, second2, DevicePath);
  5683. DWORD time1, time2;
  5684. time1 = ConvertStringToTimerReal(year, month, day, hour, minute, second);
  5685. sprintf(second2, "%s", "0");
  5686. time2 = ConvertStringToTimerReal(year2, month2, day2, hour2, minute2, second2);
  5687. if (time1 > time2)
  5688. ConvertTimerToStringReal(time1 - time2, year, month, day, hour, minute, second);
  5689. else
  5690. {
  5691. sprintf(year, "%s", "0");
  5692. sprintf(month, "%s", "0");
  5693. sprintf(day, "%s", "0");
  5694. sprintf(hour, "%s", "0");
  5695. sprintf(minute, "%s", "0");
  5696. }
  5697. g_ndogtimes++;
  5698. // str1.Format ("写入%d次 %d 年 %d 月 %d 日 %d 小时 %d 分", g_ndogtimes, atoi(year), atoi(month), atoi(day), atoi(hour), atoi(minute));
  5699. // WriteTextLog(str1);
  5700. // AfxMessageBox((str1));
  5701. }
  5702. else
  5703. {
  5704. // AfxMessageBox(("授权申请码错误, 请重新向经销商索取!"));
  5705. return;
  5706. }
  5707. }
  5708. BOOL IsCtrlDown()
  5709. {
  5710. short state = GetKeyState(VK_LCONTROL);
  5711. BYTE sta = (BYTE)(state >> 8);
  5712. state = GetKeyState(VK_RCONTROL);
  5713. BYTE sta2 = (BYTE)(state >> 8);
  5714. if (sta || sta2)
  5715. return 1;
  5716. else
  5717. return 0;
  5718. }
  5719. //extern CTime GetTmFromStr(CString date);
  5720. BOOL CDBServerDlg::PreTranslateMessage(MSG* pMsg)
  5721. {
  5722. if (pMsg->message == WM_KEYDOWN)
  5723. {
  5724. switch (pMsg->wParam)
  5725. {
  5726. case 67:
  5727. AfxMessageBox("c");
  5728. break;
  5729. case VK_F8:
  5730. if (IsCtrlDown())GenYLGL();
  5731. break;
  5732. case VK_F9:
  5733. if (IsCtrlDown())
  5734. {
  5735. CString g_domain;
  5736. CArray<CStringArray, CStringArray>g_List1array;
  5737. CString autorunpath = g_mainpath + "\\branchdindan.dat";
  5738. CFile fp;
  5739. if (fp.Open(autorunpath, CFile::modeRead))
  5740. {
  5741. int nMessageLen = fp.GetLength();
  5742. BYTE *pData = new BYTE[nMessageLen];
  5743. fp.Read(pData, nMessageLen);
  5744. fp.Close();
  5745. BYTE *szChatMessage = pData;
  5746. int count;
  5747. memcpy(&count, szChatMessage + (nMessageLen - sizeof(int)), sizeof(int));
  5748. CMemFile memfile;
  5749. memfile.Attach(szChatMessage, nMessageLen);
  5750. CArchive ar(&memfile, CArchive::load);
  5751. g_List1array.SetSize(count);
  5752. for (int ii = 0; ii < g_List1array.GetSize(); ii++)
  5753. {
  5754. g_List1array.ElementAt(ii).Serialize(ar);
  5755. }
  5756. ar.Close();
  5757. memfile.Detach();
  5758. delete[]pData;
  5759. }
  5760. CString time5, id;
  5761. for (int i = 0; i < g_List1array.GetSize(); i++)
  5762. {
  5763. g_domain = "\\" + g_List1array.ElementAt(i).ElementAt(0);
  5764. id = g_List1array.ElementAt(i).ElementAt(1);
  5765. time5 = g_List1array.ElementAt(i).ElementAt(2);
  5766. WriteTextLog(g_domain + "\\" + id + time5);
  5767. }
  5768. }
  5769. break;
  5770. #ifdef LYFZ_VERSION
  5771. case VK_F7:
  5772. if (IsCtrlDown())
  5773. {
  5774. if (AfxMessageBox("是否继续?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return 1;
  5775. CStringArray array1;
  5776. CRstDindanForm rsSt; rsSt.m_pDatabase = &g_db;
  5777. rsSt.Open();
  5778. while (!rsSt.IsEOF())
  5779. {
  5780. array1.Add(rsSt.id);
  5781. rsSt.MoveNext();
  5782. }
  5783. rsSt.Close();
  5784. CString id, sql;
  5785. sql.Format("update dindan set status5='%s'", "无");
  5786. MyExecuteSQL(&g_db, sql);
  5787. BOOL bHasPhoto = 0;
  5788. for (int i = 0; i < array1.GetSize(); i++)
  5789. {
  5790. id = array1.ElementAt(i);
  5791. bHasPhoto = 0;
  5792. CRstClientPhoto rsSt;
  5793. rsSt.m_strFilter = "id='" + id + "'";
  5794. rsSt.Open();
  5795. if (rsSt.photo.m_dwDataLength>0)
  5796. {
  5797. bHasPhoto = 1;
  5798. }
  5799. rsSt.Close();
  5800. if (bHasPhoto)
  5801. {
  5802. sql.Format("update dindan set status5='%s' where id='%s'", "有", id);
  5803. MyExecuteSQL(&g_db, sql);
  5804. }
  5805. }
  5806. /* CStringArray array1,array2;
  5807. CRstDindanForm rsSt; rsSt.m_pDatabase=&g_db;
  5808. rsSt.Open();
  5809. while(!rsSt.IsEOF())
  5810. {
  5811. array1.Add(rsSt.id) ;
  5812. array2.Add(rsSt.time4) ;
  5813. rsSt.MoveNext();
  5814. }
  5815. rsSt.Close();
  5816. CString id,time4,time2,sql;
  5817. for(int i=0; i<array1.GetSize(); i++)
  5818. {
  5819. id=array1.ElementAt(i);
  5820. time4=array2.ElementAt(i);
  5821. if(time4.GetLength()==10)
  5822. {
  5823. CTime tm=GetTmFromStr(time4);
  5824. CTimeSpan dt(365, 0, 0, 0);
  5825. CTime tm2=tm-dt;
  5826. time2=tm2.Format("%Y-%m-%d");
  5827. sql.Format("update dindan set time2='%s' where id='%s'", time2, id);
  5828. MyExecuteSQL(&g_db, sql);
  5829. }
  5830. }*/
  5831. AfxMessageBox("完成");
  5832. }
  5833. break;
  5834. #endif //#ifdef LYFZ_VERSION
  5835. case VK_F2:
  5836. if (IsCtrlDown())
  5837. {
  5838. SelYear dlg;
  5839. if (dlg.DoModal() != IDOK)return 1;
  5840. int year = dlg.m_year;
  5841. int hisyear = CTime::GetCurrentTime().GetYear() - 1;
  5842. if (year == hisyear)
  5843. {
  5844. AfxMessageBox("不能选该年");
  5845. return 1;
  5846. }
  5847. CString str;
  5848. str.Format("此操作将%d年数据导入%d中, 确认吗?", year, hisyear);
  5849. if (AfxMessageBox(str, MB_YESNO | MB_ICONINFORMATION) != IDYES)return 1;
  5850. CDatabase *pdb = GetDB(year);
  5851. if (pdb == NULL)
  5852. {
  5853. str.Format("没有找到%d, 操作失败", year);
  5854. AfxMessageBox(str); return 1;
  5855. }
  5856. str.Format("开始%d->%d", year, hisyear);
  5857. WriteTextLog(str);
  5858. CheckHistoryData(pdb, year);
  5859. str.Format("%d->%d完成", year, hisyear);
  5860. WriteTextLog(str);
  5861. }
  5862. break;
  5863. case VK_F3:
  5864. if (IsCtrlDown())
  5865. {
  5866. SelYear dlg;
  5867. if (dlg.DoModal() != IDOK)return 1;
  5868. int year = dlg.m_year;
  5869. int hisyear = CTime::GetCurrentTime().GetYear() - 1;
  5870. if (year == hisyear)
  5871. {
  5872. AfxMessageBox("不能选该年");
  5873. return 1;
  5874. }
  5875. CString str;
  5876. str.Format("此操作将%d年数据导入%d中(当前数据库中没有的订单全转), 确认吗?", year, hisyear);
  5877. if (AfxMessageBox(str, MB_YESNO | MB_ICONINFORMATION) != IDYES)return 1;
  5878. CDatabase *pdb = GetDB(year);
  5879. if (pdb == NULL)
  5880. {
  5881. str.Format("没有找到%d, 操作失败", year);
  5882. AfxMessageBox(str); return 1;
  5883. }
  5884. str.Format("开始%d->%d", year, hisyear);
  5885. WriteTextLog(str);
  5886. CheckHistoryData(pdb, year, 1);
  5887. str.Format("%d->%d完成", year, hisyear);
  5888. WriteTextLog(str);
  5889. }
  5890. break;
  5891. case VK_F1:
  5892. CString str;
  5893. if (g_conniparray.GetSize() == 0)str = "当前无客户端连接至服务器!";
  5894. for (int i = 0; i < g_conniparray.GetSize(); i++)
  5895. {
  5896. str += "\r\n连接ip:" + g_conniparray.ElementAt(i);
  5897. }
  5898. AfxMessageBox(str);
  5899. #ifdef CONNCOUNT_VERSION
  5900. // CStringArray g_conniparray;
  5901. #endif //#ifdef CONNCOUNT_VERSION
  5902. return 1;
  5903. }
  5904. }
  5905. return CDialog::PreTranslateMessage(pMsg);
  5906. }
  5907. void CDBServerDlg::GenUPhoneData()
  5908. {
  5909. MyLock lock("processChatMessageRequestxiao");
  5910. CArray<int, int>codearray;
  5911. codearray.Add(80);
  5912. codearray.Add(90);
  5913. codearray.Add(11);
  5914. codearray.Add(138);
  5915. codearray.Add(24);
  5916. codearray.Add(181);
  5917. codearray.Add(65);
  5918. codearray.Add(56);
  5919. codearray.Add(179);
  5920. codearray.Add(53);
  5921. CFile fp;
  5922. CString savepath, g_path1;
  5923. char server[50];
  5924. DWORD leng = 50;
  5925. ::GetComputerName(server, &leng);
  5926. g_path1 = server;
  5927. g_path1 = "\\\\" + g_path1 + "\\电话录音(管理软件)$";
  5928. GetPathFromNetShareName("电话录音(管理软件)$", g_path1);
  5929. if (g_path1.IsEmpty())
  5930. {
  5931. WriteTextLog("获取电精灵数据出错");
  5932. return;
  5933. }
  5934. try
  5935. {
  5936. int aa = 0;
  5937. CDatabase *pMaindb = NULL;
  5938. ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
  5939. if ( pMaindb == NULL )
  5940. return;
  5941. savepath.Format("%s\\uphonedata%d.dat", g_path1, aa);
  5942. ::DeleteFile(savepath); // 删除 uphonedata%d.dat 文件;
  5943. if (fp.Open(savepath, CFile::modeCreate | CFile::modeWrite) == 0)
  5944. {
  5945. WriteTextLog("更新来电精灵数据出错");
  5946. return;
  5947. }
  5948. CConnectSocket consock;
  5949. consock.m_pConndb = pMaindb;
  5950. for (int i = 0; i < codearray.GetSize(); i++)
  5951. {
  5952. BYTE code = codearray.ElementAt(i);
  5953. DWORD length, arraysize;
  5954. BYTE *pReturn = NULL;
  5955. consock.GetDataFromCode(code, &pReturn, length, arraysize, "");
  5956. fp.Write(&code, sizeof(BYTE));
  5957. fp.Write(&length, sizeof(DWORD));
  5958. fp.Write(&arraysize, sizeof(DWORD));
  5959. fp.Write(pReturn, length);
  5960. }
  5961. fp.Close();
  5962. }
  5963. catch (...)
  5964. {
  5965. WriteTextLog("获取来电精灵数据出错2");
  5966. }
  5967. }
  5968. //initlia
  5969. void CDBServerDlg::LoadHistoryDB() // 加载历史数据库;
  5970. {
  5971. CString path;
  5972. CString sql;
  5973. sql = "delete from historydb";
  5974. CDatabase *pdb = NULL;
  5975. ODBCConnGuard ConnGuard(pdb, -1, 3000);
  5976. if ( pdb ) MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pdb, sql);
  5977. CDatabase g_masterdb;
  5978. try
  5979. {
  5980. CString strCon;
  5981. strCon.Format(DB_SS_CONN_WITHOUT_PORT, g_strdbServrename, _T("master"), g_szDBAccount, g_szDBPassWord);
  5982. g_masterdb.OpenEx(strCon, CDatabase::noOdbcDialog);
  5983. }
  5984. catch (CDBException * e)
  5985. {
  5986. #ifdef _DEBUG
  5987. e->ReportError();
  5988. #endif //#ifdef _DEBUG
  5989. e->Delete();
  5990. }
  5991. GetAllCatalogName();
  5992. BOOL bExistCatalog = FALSE;
  5993. TCHAR szdbName[MAX_PATH] = {0};
  5994. for (int i = CTime::GetCurrentTime().GetYear() - 1; i >= 2009; i--)
  5995. {
  5996. #if USE_POOL
  5997. _itot_s(i, szdbName, 10);
  5998. bExistCatalog = FALSE;
  5999. for (int k = 0; k < g_AryAllCatalogName.GetSize(); k++)
  6000. {
  6001. if (g_AryAllCatalogName.ElementAt(k).CompareNoCase(szdbName) == 0)
  6002. {
  6003. bExistCatalog = TRUE;
  6004. break;
  6005. }
  6006. }
  6007. if (bExistCatalog)
  6008. {
  6009. CODBCPool *pdbpool = new CODBCPool;
  6010. if (pdbpool->InitializePool(g_szDBSource, g_dwDBServerPort, g_szDBAccount, g_szDBPassWord, szdbName, g_dwDBPoolDef, g_dwDBPoolMaxCount))
  6011. {
  6012. g_nYearArray.Add(i);
  6013. sql.Format("insert into [historydb]([year])values('%d')", i);
  6014. CDatabase *pdb = NULL;
  6015. ODBCConnGuard ConnGuard(pdb, -1, 3000);
  6016. if (pdb)MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pdb, sql);
  6017. g_dbpool.Add(pdbpool);
  6018. }
  6019. else
  6020. {
  6021. delete pdbpool;
  6022. pdbpool = NULL;
  6023. }
  6024. }
  6025. else
  6026. {
  6027. CString strPathOfYearmdf;
  6028. CString strPathOfYearldf;
  6029. CString sql;
  6030. strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, i);
  6031. strPathOfYearldf.Format("%s\\数据\\%d_log.LDF", g_mainpath, i);
  6032. if (PathFileExists(strPathOfYearmdf))
  6033. {
  6034. BOOL bLog = 0;
  6035. if (PathFileExists(strPathOfYearldf))
  6036. {
  6037. bLog = 1;
  6038. }
  6039. g_masterdb.SetQueryTimeout(600);
  6040. if (bLog)
  6041. sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", i, strPathOfYearmdf, strPathOfYearldf);
  6042. else
  6043. sql.Format("exec sp_attach_db '%d',@filename1='%s'", i, strPathOfYearmdf);
  6044. try
  6045. {
  6046. g_masterdb.ExecuteSQL(sql);
  6047. }
  6048. catch (CDBException * e)
  6049. {
  6050. WriteTextLog("历史数据库初始化失败,%s",e->m_strError);
  6051. g_masterdb.SetQueryTimeout(100);
  6052. #ifdef _DEBUG
  6053. e->ReportError();
  6054. #endif //#ifdef _DEBUG
  6055. e->Delete();
  6056. break;
  6057. }
  6058. g_masterdb.SetQueryTimeout(100);
  6059. CODBCPool *pdbpool = new CODBCPool;
  6060. if ( pdbpool->InitializePool(g_szDBSource, g_dwDBServerPort, g_szDBAccount, g_szDBPassWord, szdbName, g_dwDBPoolDef, g_dwDBPoolMaxCount))
  6061. {
  6062. g_nYearArray.Add(i);
  6063. sql.Format("insert into [historydb]([year])values('%d')", i);
  6064. CDatabase *pdb = NULL;
  6065. ODBCConnGuard ConnGuard(pdb, -1, 3000);
  6066. if ( pdb )MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pdb, sql);
  6067. g_dbpool.Add(pdbpool);
  6068. }
  6069. else
  6070. {
  6071. delete pdbpool;
  6072. }
  6073. }
  6074. }
  6075. #else
  6076. CDatabase *db = new CDatabase;
  6077. try
  6078. {
  6079. CString strCon;
  6080. //strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=%d;%s"), g_strdbServrename, i, g_strdbpsw);
  6081. if ( _tcscmp(g_szDBAccount, _T("")) == 0)
  6082. strCon.Format(DB_SW_CONN_WITHOUT_PORT2, g_strdbServrename, i);
  6083. else
  6084. strCon.Format(DB_SS_CONN_WITHOUT_PORT2, g_strdbServrename, i, g_szDBAccount, g_szDBPassWord);
  6085. db->OpenEx(strCon, CDatabase::noOdbcDialog);
  6086. g_nYearArray.Add(i);
  6087. g_dbHistoryArray.Add(db);
  6088. sql.Format("insert into [historydb]([year])values('%d')", i);
  6089. MyExecuteSQL(&g_db, sql);
  6090. }
  6091. catch (CDBException * e)
  6092. {
  6093. #ifdef _DEBUG
  6094. e->ReportError();
  6095. #endif //#ifdef _DEBUG
  6096. CString strPathOfYearmdf;
  6097. CString strPathOfYearldf;
  6098. CString sql;
  6099. strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, i);
  6100. strPathOfYearldf.Format("%s\\数据\\%d_log.LDF", g_mainpath, i);
  6101. if (PathFileExists(strPathOfYearmdf))
  6102. {
  6103. BOOL bLog = 0;
  6104. if (PathFileExists(strPathOfYearldf))
  6105. {
  6106. bLog = 1;
  6107. }
  6108. g_masterdb.SetQueryTimeout(600);
  6109. if (bLog)
  6110. sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", i, strPathOfYearmdf, strPathOfYearldf);
  6111. else
  6112. sql.Format("exec sp_attach_db '%d',@filename1='%s'", i, strPathOfYearmdf);
  6113. try
  6114. {
  6115. g_masterdb.ExecuteSQL(sql);
  6116. }
  6117. catch (CDBException * e)
  6118. {
  6119. WriteTextLog(e->m_strError);
  6120. WriteTextLog("历史数据库初始化失败!!");
  6121. g_masterdb.SetQueryTimeout(100);
  6122. #ifdef _DEBUG
  6123. e->ReportError();
  6124. #endif //#ifdef _DEBUG
  6125. e->Delete();
  6126. break;
  6127. }
  6128. g_masterdb.SetQueryTimeout(100);
  6129. CString strCon;
  6130. //strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=%d;%s"), g_strdbServrename, i, g_strdbpsw);
  6131. if ( _tcscmp(g_szDBAccount, _T("")) == 0)
  6132. strCon.Format(DB_SW_CONN_WITHOUT_PORT2, g_strdbServrename, i);
  6133. else
  6134. strCon.Format(DB_SS_CONN_WITHOUT_PORT2, g_strdbServrename, i, g_szDBAccount, g_szDBPassWord);
  6135. db->OpenEx(strCon, CDatabase::noOdbcDialog);
  6136. g_nYearArray.Add(i);
  6137. g_dbHistoryArray.Add(db);
  6138. sql.Format("insert into [historydb]([year])values('%d')", i);
  6139. MyExecuteSQL(&g_db, sql);
  6140. }
  6141. else
  6142. {
  6143. //e->ReportError();
  6144. e->Delete();
  6145. //break;
  6146. }
  6147. }
  6148. #endif
  6149. }
  6150. g_masterdb.Close();
  6151. }
  6152. void CDBServerDlg::AddOneConn()
  6153. {
  6154. #if 0
  6155. try
  6156. {
  6157. MyLock lock("AddOneConnxiao");
  6158. if (g_nDBCount >= 200)
  6159. {
  6160. WriteTextLog("连接超数!"); return;
  6161. }
  6162. CDatabase *db = new CDatabase;
  6163. //if(AddConn(db, "db")==0)// Jeff.deal;
  6164. if (AddConn(db, g_szDBName) == 0)
  6165. return;
  6166. g_pDB[g_nDBCount] = db;
  6167. CString dbname = _T("");
  6168. for (int i = 0; i < g_nYearArray.GetSize(); i++)
  6169. {
  6170. dbname.Format("%d", g_nYearArray.ElementAt(i));
  6171. CDatabase *db = new CDatabase;
  6172. AddConn(db, dbname);
  6173. g_pHistoryDBarray[g_nDBCount].Add(db);
  6174. }
  6175. AddAdoConn();
  6176. g_nDBCount++;
  6177. }
  6178. catch (CException *e)
  6179. {
  6180. TCHAR szError[1024] = { 0 };
  6181. e->GetErrorMessage(szError, 1024);
  6182. WriteTextLog("AddOneConn error" + CString(szError));
  6183. }
  6184. #endif
  6185. }
  6186. /////////////////////////////////////////////////////////////////////////////////////
  6187. /*
  6188. 函数名: AddAdoConn
  6189. 说明: 添加Logdb数据库连接
  6190. 参数:
  6191. 返回:
  6192. */
  6193. /////////////////////////////////////////////////////////////////////////////////////
  6194. void CDBServerDlg::AddAdoConn()
  6195. {
  6196. }
  6197. void GetOneConn(CDatabase **m_pdb, CArray<CDatabase*, CDatabase*>*m_dbarray, CConnectThread *pThread)
  6198. {
  6199. #if 0
  6200. MyLock lock("GetOneConnxiao");
  6201. ll: for (int i = 0; i < 200; i++)
  6202. {
  6203. if (g_pDB[i] != NULL && g_pThreadPt[i] == NULL)
  6204. {
  6205. *m_pdb = g_pDB[i];
  6206. m_dbarray->Copy(g_pHistoryDBarray[i]);
  6207. g_pThreadPt[i] = pThread;
  6208. return;
  6209. }
  6210. }
  6211. if (g_nDBCount >= 200)
  6212. {
  6213. WriteTextLog("连接超数2!");
  6214. *m_pdb = &g_db;
  6215. m_dbarray->Copy(g_dbHistoryArray);
  6216. return;
  6217. }
  6218. g_pMainWnd->AddOneConn();
  6219. ::Sleep(1000);
  6220. goto ll;
  6221. #endif
  6222. }
  6223. void CDBServerDlg::CheckConnCount()
  6224. {
  6225. int count = 0;
  6226. for (int i = 0; i < 200; i++)
  6227. {
  6228. if (g_pDB[i] != NULL && g_pThreadPt[i] == NULL)
  6229. {
  6230. count++;
  6231. if (count > 9)
  6232. return;
  6233. }
  6234. }
  6235. AddOneConn();
  6236. }
  6237. //delete from 背景.jpg
  6238. void CDBServerDlg::RestoreHQ()
  6239. {
  6240. CString sql;
  6241. CDatabase *pMaindb = NULL;
  6242. ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
  6243. if ( pMaindb == NULL )
  6244. return;
  6245. DWORD ii = 0;
  6246. CArray<CStringArray, CStringArray>g_List1array;
  6247. {
  6248. CRecordset myset(pMaindb);
  6249. CString sql = "select count(*) as cot from dindan";
  6250. myset.Open(CRecordset::forwardOnly, sql);
  6251. myset.GetFieldValue("cot", sql);
  6252. myset.Close();
  6253. int count = atol(sql);
  6254. g_List1array.SetSize(count, 1);
  6255. CRstDindanForm rsSt;
  6256. rsSt.m_pDatabase = pMaindb;
  6257. rsSt.Open();
  6258. ii = 0;
  6259. while (!rsSt.IsEOF())
  6260. {
  6261. g_List1array.ElementAt(ii).RemoveAll();
  6262. g_List1array.ElementAt(ii).Add(rsSt.id);
  6263. ii++;
  6264. rsSt.MoveNext(); if (g_List1array.GetSize() <= ii)break;
  6265. }
  6266. rsSt.Close(); g_List1array.SetSize(ii, 1);
  6267. }
  6268. for (int i = 0; i < g_List1array.GetSize(); i++)
  6269. {
  6270. // int ret=TransDinDan(pdb1, pdb2, g_List1array.ElementAt (i).ElementAt (0), lastyear);
  6271. // Jeff.deal;
  6272. //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));
  6273. 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));
  6274. CRecordset myset(pMaindb);
  6275. myset.Open(CRecordset::forwardOnly, sql);
  6276. CStringArray namearray;
  6277. CStringArray countarray;
  6278. while (!myset.IsEOF())
  6279. {
  6280. sql = "";
  6281. myset.GetFieldValue("name", sql);
  6282. namearray.Add(sql);
  6283. sql = "";
  6284. myset.GetFieldValue("count", sql);
  6285. countarray.Add(sql);
  6286. myset.MoveNext();
  6287. }
  6288. myset.Close();
  6289. for (int j = 0; j < namearray.GetSize(); j++)
  6290. {
  6291. CString spid, spjiage2;
  6292. // WriteTextLog("name:"+namearray.ElementAt (j));
  6293. // Jeff.deal;
  6294. //sql.Format("SELECT [spid],[spjiage2] FROM [db].[dbo].[shangpin] where spname='%s'", namearray.ElementAt (j));
  6295. sql.Format("SELECT [spid],[spjiage2] FROM [dbo].[shangpin] where spname='%s'", namearray.ElementAt(j));
  6296. //WriteTextLog(sql);
  6297. CRecordset myset(pMaindb);
  6298. myset.Open(CRecordset::forwardOnly, sql);
  6299. if (!myset.IsEOF())
  6300. {
  6301. myset.GetFieldValue("spid", spid);
  6302. myset.GetFieldValue("spjiage2", spjiage2);
  6303. }
  6304. myset.Close();
  6305. // Jeff.deal;
  6306. //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));
  6307. 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));
  6308. myset.Open(CRecordset::forwardOnly, sql);
  6309. sql = "";
  6310. if (!myset.IsEOF())
  6311. {
  6312. myset.GetFieldValue("cot", sql);
  6313. }
  6314. myset.Close();
  6315. if (atoi(sql))continue;
  6316. sql.Format("insert into [dindansp]([id],[name],[shuliang],[price],[spid],[kind])values('%s','%s','%s','%s','%s','%s')",
  6317. g_List1array.ElementAt(i).ElementAt(0), namearray.ElementAt(j), countarray.ElementAt(j), spjiage2, spid, "2");
  6318. //WriteTextLog(sql);
  6319. pMaindb->ExecuteSQL(sql);
  6320. }
  6321. }
  6322. }
  6323. void CDBServerDlg::ManagePhoto()
  6324. {
  6325. // CClientCenter dlg1;
  6326. // dlg1.DoModal ();
  6327. ShowPic3 dlg;
  6328. dlg.DoModal();
  6329. }
  6330. //数据备份(管理软件)$
  6331. //10.lia
  6332. //----------------------------------------------------------------------------
  6333. // Remark by Jeff 2014.10.22
  6334. // 函数:GenYLGL
  6335. // 描述:调用本地客户端;
  6336. // 参数:#
  6337. // 返回:#
  6338. //
  6339. // 调用关系:
  6340. // 1.只由AutoDelPhoto()主动调用。
  6341. //
  6342. // 说明:传递genbranchdata给客户端,使客户端能够自动遍历branchinfo.dat里的分店信息,
  6343. // 客户端顺序连接所有分店并获取分店历史订单已完成取件的订单。最终将所有分店历史
  6344. // 订单已完成取件的送回服务端,保存在branchdindan2.dat中.
  6345. //----------------------------------------------------------------------------
  6346. void CDBServerDlg::GenYLGL()
  6347. {
  6348. // 1.Jeff.删除文件,g_mainpath服务器DBServer.exe的目录;
  6349. CString autorunpath = g_mainpath + "\\YLGL.exe";
  6350. ::DeleteFile(autorunpath); // 删除YLGL.exe
  6351. WriteTextLog("命令行启动:" + autorunpath);
  6352. // 2.重新生成YLGL.exe
  6353. CDatabase *pdb = NULL;
  6354. ODBCConnGuard ConnGuard(pdb, -1, 3000);
  6355. if ( pdb = NULL )
  6356. return;
  6357. CRstUpdate rsSt;
  6358. rsSt.m_pDatabase = pdb;
  6359. rsSt.Open();
  6360. if (!rsSt.IsEOF())
  6361. {
  6362. CFile fp;
  6363. if (fp.Open(autorunpath, CFile::modeCreate | CFile::modeWrite))
  6364. {
  6365. void *pData = GlobalLock(rsSt.data.m_hData);
  6366. fp.Write(pData, rsSt.data.m_dwDataLength);
  6367. fp.Close();
  6368. GlobalUnlock(rsSt.data.m_hData);
  6369. }
  6370. }
  6371. rsSt.Close();
  6372. // 3.执行YLGL.exe
  6373. ShellExecute(NULL, _T("open"), autorunpath, "genbranchdata", NULL, SW_HIDE);
  6374. }
  6375. //105
  6376. /************************************************************************/
  6377. /*
  6378. 函数:CheckSvcWork
  6379. 描述:检查服务工作
  6380. 参数:
  6381. LPVOID LPARAM
  6382. 返回:
  6383. */
  6384. /************************************************************************/
  6385. unsigned int CDBServerDlg::CheckSvcWork(LPVOID LPARAM)
  6386. {
  6387. CDBServerDlg* p = (CDBServerDlg*)LPARAM;
  6388. if(p != NULL)
  6389. {
  6390. while(1)
  6391. {
  6392. // 每小时检查一次
  6393. int nRet = WaitForSingleObject(p->m_hWaitTimeOut, 60*60*1000);
  6394. if(nRet != WAIT_OBJECT_0 && nRet != WAIT_TIMEOUT)
  6395. {
  6396. WriteTextLog(_T("检测服务3错误:%d\n"), GetLastError());
  6397. break;
  6398. }
  6399. if(WaitForSingleObject(p->m_hExitCheckSvc, 0) == WAIT_OBJECT_0)
  6400. break;
  6401. CString strPath = _T("");
  6402. DWORD dwID = 0;
  6403. // 自动备份
  6404. dwID = FindAppProcessID(_T("lyfzBackupSvc.exe"));
  6405. if(dwID == 0)
  6406. {
  6407. strPath = g_mainpath + _T("\\lyfzBackupSvc.exe");
  6408. CString strCmd = _T("/startsvc");
  6409. SHELLEXECUTEINFO execinfo;
  6410. memset(&execinfo, 0, sizeof(execinfo));
  6411. execinfo.lpFile = strPath;
  6412. execinfo.cbSize = sizeof(execinfo);
  6413. execinfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
  6414. execinfo.nShow = SW_HIDE;
  6415. execinfo.lpParameters = strCmd;
  6416. if(!ShellExecuteEx(&execinfo))
  6417. {
  6418. CString strError = _T("");
  6419. strError.Format(_T("检测服务1错误:%d\n"), GetLastError());
  6420. OutputDebugString(strError);
  6421. }
  6422. // WaitForSingleObject(execinfo.hProcess,INFINITE);
  6423. }
  6424. // 自动删除
  6425. dwID = FindAppProcessID(_T("lyfzDeletePhotoSvc.exe"));
  6426. if(dwID == 0)
  6427. {
  6428. strPath = g_mainpath + _T("\\lyfzDeletePhotoSvc.exe");
  6429. CString strCmd = _T("/startsvc");
  6430. SHELLEXECUTEINFO execinfo;
  6431. memset(&execinfo, 0, sizeof(execinfo));
  6432. execinfo.lpFile = strPath;
  6433. execinfo.cbSize = sizeof(execinfo);
  6434. execinfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
  6435. execinfo.nShow = SW_HIDE;
  6436. execinfo.lpParameters = strCmd;
  6437. if(!ShellExecuteEx(&execinfo))
  6438. {
  6439. WriteTextLog(_T("检测服务2错误:%d\n"), GetLastError());
  6440. }
  6441. // WaitForSingleObject(execinfo.hProcess,INFINITE);
  6442. }
  6443. }
  6444. }
  6445. _endthreadex(0);
  6446. return 0;
  6447. }
  6448. // 结束检查工作
  6449. void CDBServerDlg::TerminateCheckWork()
  6450. {
  6451. if(m_hExitCheckSvc)
  6452. SetEvent(m_hExitCheckSvc);
  6453. if(m_hWaitTimeOut)
  6454. SetEvent(m_hWaitTimeOut);
  6455. if(m_hCheckSvcThread)
  6456. {
  6457. WaitForSingleObject(m_hCheckSvcThread, INFINITE);
  6458. CloseHandle(m_hCheckSvcThread);
  6459. }
  6460. m_hCheckSvcThread = NULL;
  6461. if(m_hExitCheckSvc)
  6462. CloseHandle(m_hExitCheckSvc);
  6463. m_hExitCheckSvc = NULL;
  6464. if(m_hWaitTimeOut)
  6465. CloseHandle(m_hWaitTimeOut);
  6466. m_hWaitTimeOut = NULL;
  6467. m_bStartCheckSvc = FALSE;
  6468. }
  6469. /************************************************************************/
  6470. /*
  6471. 函数:OnStartBackupSvc
  6472. 描述:启动备份服务
  6473. 参数:
  6474. 返回:
  6475. */
  6476. /************************************************************************/
  6477. void CDBServerDlg::OnStartBackupSvc()
  6478. {
  6479. StartSvc(_T("lyfzBackupSvc.exe"));
  6480. }
  6481. /************************************************************************/
  6482. /*
  6483. 函数:OnStopBackupSvc
  6484. 描述:停止备份服务
  6485. 参数:
  6486. 返回:
  6487. */
  6488. /************************************************************************/
  6489. void CDBServerDlg::OnStopBackupSvc()
  6490. {
  6491. StopSvc(_T("lyfz Backup Service"));
  6492. }
  6493. /************************************************************************/
  6494. /*
  6495. 函数:OnStartDelPhotoSvc
  6496. 描述:启动删除服务
  6497. 参数:
  6498. 返回:
  6499. */
  6500. /************************************************************************/
  6501. void CDBServerDlg::OnStartDelPhotoSvc()
  6502. {
  6503. StartSvc(_T("lyfzDeletePhotoSvc.exe"));
  6504. }
  6505. /************************************************************************/
  6506. /*
  6507. 函数:OnStopDelPhotoSvc
  6508. 描述:停止删除服务
  6509. 参数:
  6510. 返回:
  6511. */
  6512. /************************************************************************/
  6513. void CDBServerDlg::OnStopDelPhotoSvc()
  6514. {
  6515. StopSvc(_T("lyfz Delete Photo Service"));
  6516. }
  6517. /************************************************************************/
  6518. /*
  6519. 函数:StartSvc
  6520. 描述:启动服务
  6521. 参数:
  6522. IN LPCSTR lpExeFile 程序名称
  6523. 返回:1成功,0失败
  6524. */
  6525. /************************************************************************/
  6526. int CDBServerDlg::StartSvc( IN LPCSTR lpExeFile)
  6527. {
  6528. CString strPath = _T("");
  6529. DWORD dwID = 0;
  6530. // 自动备份
  6531. dwID = FindAppProcessID(lpExeFile);
  6532. if(dwID == 0)
  6533. {
  6534. strPath = g_mainpath + _T("\\");
  6535. strPath += lpExeFile;
  6536. CString strCmd = _T("/startsvc");
  6537. SHELLEXECUTEINFO execinfo;
  6538. memset(&execinfo, 0, sizeof(execinfo));
  6539. execinfo.lpFile = strPath;
  6540. execinfo.cbSize = sizeof(execinfo);
  6541. execinfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
  6542. execinfo.nShow = SW_HIDE;
  6543. execinfo.lpParameters = strCmd;
  6544. if(!ShellExecuteEx(&execinfo))
  6545. {
  6546. CString strError = _T("");
  6547. strError.Format(_T("检测服务%s错误:%d\n"), lpExeFile, GetLastError());
  6548. OutputDebugString(strError);
  6549. }
  6550. }
  6551. return 1;
  6552. }
  6553. // 停止服务
  6554. /************************************************************************/
  6555. /*
  6556. 函数:OnStopDelPhotoSvc
  6557. 描述:停止删除服务
  6558. 参数:
  6559. IN LPCSTR lpSvcName 服务名
  6560. 返回:1成功,0失败
  6561. */
  6562. /************************************************************************/
  6563. int CDBServerDlg::StopSvc(IN LPCSTR lpSvcName)
  6564. {
  6565. CString strError = _T("");
  6566. SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
  6567. if (hSCM == NULL)
  6568. return 0;
  6569. SC_HANDLE hService = ::OpenService(hSCM, lpSvcName, SERVICE_STOP | SERVICE_QUERY_STATUS);
  6570. if (hService == NULL)
  6571. {
  6572. strError.Format(_T("打开%s服务失败:%d"), lpSvcName, GetLastError());
  6573. OutputDebugString(strError);
  6574. ::CloseServiceHandle(hSCM);
  6575. return 0;
  6576. }
  6577. SERVICE_STATUS status;
  6578. if(!::QueryServiceStatus(hService, &status))
  6579. {
  6580. strError.Format(_T("获取%s服务状态失败:%d"), lpSvcName, GetLastError());
  6581. OutputDebugString(strError);
  6582. ::CloseServiceHandle(hService);
  6583. ::CloseServiceHandle(hSCM);
  6584. return 0;
  6585. }
  6586. if(status.dwCurrentState == SERVICE_STOPPED)
  6587. {
  6588. ::CloseServiceHandle(hService);
  6589. ::CloseServiceHandle(hSCM);
  6590. return 1;
  6591. }
  6592. ControlService(hService, SERVICE_CONTROL_STOP, &status);
  6593. DWORD dwStartTime = GetTickCount();
  6594. DWORD dwTimeout = 30*1000; // 30-second time-out
  6595. while(1)
  6596. {
  6597. Sleep( status.dwWaitHint );
  6598. if(!::QueryServiceStatus(hService, &status))
  6599. {
  6600. strError.Format(_T("获取%s服务状态失败:%d"), lpSvcName, GetLastError());
  6601. OutputDebugString(strError);
  6602. ::CloseServiceHandle(hService);
  6603. ::CloseServiceHandle(hSCM);
  6604. return 0;
  6605. }
  6606. if ( status.dwCurrentState == SERVICE_STOPPED )
  6607. break;
  6608. if ( GetTickCount() - dwStartTime > dwTimeout )
  6609. {
  6610. strError.Format(_T("停止%s服务超时:%d"), lpSvcName, GetLastError());
  6611. OutputDebugString(strError);
  6612. ::CloseServiceHandle(hService);
  6613. ::CloseServiceHandle(hSCM);
  6614. return 0;
  6615. }
  6616. }
  6617. ::CloseServiceHandle(hService);
  6618. ::CloseServiceHandle(hSCM);
  6619. return 1;
  6620. }
  6621. void CDBServerDlg::OnAutoCheckSvc()
  6622. {
  6623. g_bAutoCheckSvc = !g_bAutoCheckSvc;
  6624. CHAR szFile[MAX_PATH + 1] = "";
  6625. wsprintf(szFile, "%s\\ServiceInfo.ini", g_ModulePath);
  6626. OFSTRUCT ofStruct;
  6627. OpenFile(szFile, &ofStruct, OF_EXIST);
  6628. if (ERROR_FILE_NOT_FOUND == GetLastError())
  6629. return;
  6630. CString strValue = _T("");
  6631. strValue.Format(_T("%d"), g_bAutoCheckSvc);
  6632. WritePrivateProfileString(_T("Back"), _T("AutoCheckSvc"), strValue, szFile);
  6633. if(!g_bAutoCheckSvc)
  6634. {
  6635. TerminateCheckWork();
  6636. }
  6637. else
  6638. {
  6639. // 如果没启动自动检查
  6640. if(!m_bStartCheckSvc)
  6641. {
  6642. m_hExitCheckSvc = CreateEvent(NULL, FALSE, FALSE, NULL);
  6643. m_hWaitTimeOut = CreateEvent(NULL, FALSE, FALSE, NULL);
  6644. SetEvent(m_hWaitTimeOut);
  6645. unsigned int nThreadID = 0;
  6646. m_bStartCheckSvc = TRUE;
  6647. m_hCheckSvcThread = (HANDLE)_beginthreadex(NULL, 0, CheckSvcWork, this, 0, &nThreadID);
  6648. }
  6649. }
  6650. }