DBServerDlg.cpp 193 KB

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