1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345 |
- /****************************************************************/
- /* */
- /* ApplicationDlg.cpp */
- /* */
- /* Implementation of the CDBServerDlg class. */
- /* This class is a part of the Date Server. */
- /* */
- /* Programmed by LYFZ van der Meer */
- /* Copyright LYFZ Software Solutions 2002 */
- /* http://www.LYFZvandermeer.nl */
- /* */
- /* Last updated: 10 july 2002 */
- /* */
- /****************************************************************/
- //在ApplicationDlg.cpp文件中实现主窗口界面的设计。及其主窗口相应控件的功能和参数的映射。 D4F876E2-w78F-22D5-q98A-Y0B0D07B847C
- #include "stdafx.h"
- #include "DBServer.h"
- #include "theDBServer.h"
- #include "DBServerDlg.h"
- //#include "UserAccountsDlg.h"
- //#include "WizardPages.h"
- #include "AboutDlg.h"
- #include <afxpriv.h>
- #include <process.h>
- //#include "Shlwapi.h"
- #include "ClientCenter.h"
- #include "MyLock.h"
- #include "mysqldata.h"
- #include "./helper/ffsco.h"
- //#include <tlhelp32.h>
- #include "ShowPic3.h"
- #include "my32.h"
- #include "SoftKey.h"
- #include "DogTimeOutDlg.h"
- #include "InputAuthDlg.h"
- #include "AdoImplSvr.h"
- #include "CreateSmallPhoto.h"
- #include "PhotoBackupMgr.h"
- #include <WinSvc.h>
- #include "ConnectThread.h"
- #pragma comment(lib, "NETAPI32.LIB ")
- #include "SelYear.h"
- #include "BranchInfo.h"
- using namespace helper_coffs;
- /*********ErrorExit(...)函数头文件************/
- //#include <strsafe.h>
- /***********************************/
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define LIMITCOUNT 1 //历史数据每次转10个 autorun
- extern BOOL g_bSteal;
- extern BOOL g_bConvertHisAll;
- extern CDBServer theApp;
- extern CtheDBServer theServer;
- #define WM_ICON_NOTIFY WM_USER+12
- CDBServerDlg *g_pMainWnd = NULL;
- //#define IPC_CUSTOM_MSG2 _T("{D4F876E2-w78F-22D5-q98A-Y0B0D07B847C}")
- #define IPC_CUSTOM_MSG2 _T("{E4F876E2-Q78F-22D5-C98A-Y0B0D07B847C}")
- UINT g_wmClose = RegisterWindowMessage(IPC_CUSTOM_MSG2);
- //extern BOOL EncryptFile2(BYTE *buffer, DWORD leng, PCHAR szPassword);
- //extern CStringArray g_conniparray;
- CArray<CDatabase*, CDatabase*>g_pHistoryDBarray[200];
- CDatabase *g_pDB[200];
- CConnectThread *g_pThreadPt[200];
- int g_nDBCount = 0;
- /////////////////////////////////////////////////////////////////////////////
- // CDBServerDlg dialog
- #pragma comment(lib, "Shlwapi.lib")
- extern DWORD g_nSendCode;
- extern BOOL g_bReturned;
- static UINT auIDStatusBar[] =
- {
- ID_SEPARATOR,
- ID_INDICATOR_DATA_RECEIVED,
- ID_INDICATOR_DATA_SEND,
- ID_INDICATOR_ONLINELED,
- ID_INDICATOR_OFFLINELED
- };
- /********************************************************************/
- /* */
- /* Function name : CDBServerDlg::CDBServerDlg */
- /* Description : Constructor */
- /* */
- /********************************************************************/
- CDBServerDlg::CDBServerDlg(CWnd* pParent /*=NULL*/): CDialog(CDBServerDlg::IDD, pParent)
- {
- m_hIcon = AfxGetApp()->LoadIcon(IDI_DBServer);
- m_bTerminate = false;
- m_bRunning = false;
- m_hThread = NULL;
- hInst = NULL;
- CString version = _T("Version 1.0");
- g_bAutoRun = AfxGetApp()->GetProfileInt(version, "brun", 0);
- m_hExitCheckSvc = NULL;
- m_hWaitTimeOut = NULL;
- m_hCheckSvcThread = NULL;
- m_bStartCheckSvc = FALSE;
- for (int i = 0; i < 200; i++)
- {
- g_pDB[i] = NULL;
- g_pThreadPt[i] = NULL;
- }
- }
- /********************************************************************/
- /* */
- /* Function name : CDBServerDlg::~CDBServerDlg */
- /* Description : Destructor */
- /* */
- /********************************************************************/
- CDBServerDlg::~CDBServerDlg()
- {
- for (int i = 0; i < 200; i++)
- {
- CDatabase *db = g_pDB[i];
- if (db)
- {
- db->Close();
- delete db;
- }
- for (int j = 0; j < g_pHistoryDBarray[i].GetSize(); j++)
- {
- CDatabase *db = g_pHistoryDBarray[i].ElementAt(j);
- if (db)
- {
- db->Close();
- delete db;
- }
- }
- g_pHistoryDBarray[i].RemoveAll();
- }
- }
- /********************************************************************/
- /* */
- /* Function name : CDBServerDlg::DoDataExchange */
- /* Description : Called by the framework to exchange and validate */
- /* dialog data. */
- /* */
- /********************************************************************/
- void CDBServerDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDBServerDlg)
- DDX_Control(pDX, IDC_INFOBAR, m_InfobarCtrl);
- DDX_Control(pDX, IDC_OUTLOOKBAR, m_OutlookBar);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDBServerDlg, CDialog)
- //{{AFX_MSG_MAP(CDBServerDlg)
- ON_WM_DESTROY()
- ON_COMMAND(ID_SERVER_START, OnServerStart)
- ON_UPDATE_COMMAND_UI(ID_SERVER_START, OnUpdateServerStart)
- ON_COMMAND(ID_SERVER_STOP, OnServerStop)
- ON_UPDATE_COMMAND_UI(ID_SERVER_STOP, OnUpdateServerStop)
- ON_COMMAND(ID_SERVER_EXIT, OnServerExit)
- ON_NOTIFY(NM_CLICK, IDC_OUTLOOKBAR, OnClickOutlookBar)
- ON_NOTIFY(LVN_KEYDOWN, IDC_OUTLOOKBAR, OnKeydownOutlookBar)
- ON_COMMAND(ID_USER_ACCOUNTS, OnUserAccounts)
- ON_WM_CLOSE()
- ON_COMMAND(IDC_VIEW_TRACE, OnViewTrace)
- ON_COMMAND(IDC_VIEW_ONLINE_USERS, OnViewOnlineUsers)
- ON_COMMAND(IDC_VIEW_CONFIGURATION, OnViewConfiguration)
- ON_UPDATE_COMMAND_UI(IDC_VIEW_TRACE, OnUpdateViewTrace)
- ON_UPDATE_COMMAND_UI(IDC_VIEW_ONLINE_USERS, OnUpdateViewOnlineUsers)
- ON_UPDATE_COMMAND_UI(IDC_VIEW_CONFIGURATION, OnUpdateViewConfiguration)
- ON_COMMAND(IDC_VIEW_STATISTICS, OnViewStatistics)
- ON_UPDATE_COMMAND_UI(IDC_VIEW_STATISTICS, OnUpdateViewStatistics)
- ON_COMMAND(IDC_VIEW_SECURITY, OnViewSecurity)
- ON_UPDATE_COMMAND_UI(IDC_VIEW_SECURITY, OnUpdateViewSecurity)
- ON_COMMAND(ID_ACCOUNT_WIZARD, OnAccountWizard)
- ON_WM_TIMER()
- ON_COMMAND(IDM_OPEN, OnOpen)
- ON_COMMAND(IDM_EXIT, OnExit)
- ON_COMMAND(IDM_AUTORUN, OnAutorun)
- ON_COMMAND(IDM_STARTBAKSVC, OnStartBackupSvc)
- ON_COMMAND(IDM_STARTDELSVC, OnStartDelPhotoSvc)
- ON_COMMAND(IDM_STOPBAKSVC, OnStopBackupSvc)
- ON_COMMAND(IDM_STOPDELSVC, OnStopDelPhotoSvc)
- ON_COMMAND(IDM_AUTOCHECKSVC, OnAutoCheckSvc)
- //}}AFX_MSG_MAP
- ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification)
- ON_REGISTERED_MESSAGE(g_wmClose, OnAbortClose)
- END_MESSAGE_MAP()
- LRESULT CDBServerDlg::OnAbortClose(WPARAM wParam, LPARAM lParam)
- {
- if (wParam == 2)
- {
- WriteTextLog("连接失败,服务将重启");
- OnExit2();
- }
- else if (wParam == 3)//更新分店
- {
- LoadBranchInfo();
- }
- return 1;
- }
- BOOL CDBServerDlg::OnInitDialog()
- {
- g_pMainWnd = this;
- CDialog::OnInitDialog();
- char server[50];
- DWORD leng = 50;
- ::GetComputerName(server, &leng);
- g_localip = server;
- MyGetIPByName(g_localip);
- // setup listview ctrl, so that it looks like the outbar control
- SetupOutlookBar();
- // Add statusbar to the dialog
- CreateStatusbar();
- CRect rect;
- GetDlgItem(IDC_STATIC1)->GetWindowRect(rect);
- ScreenToClient(rect);
- rect.right += 4;
- GetDlgItem(IDC_STATIC1)->MoveWindow(rect);
- // create property pages
- m_TracePage.Create(IDD_PROPPAGE_TRACE, this);
- m_OnlineUsersPage.Create(IDD_PROPPAGE_ONLINE, this);
- m_ConfigurationPage.Create(IDD_PROPPAGE_CONFIGURATION, this);
- m_StatisticsPage.Create(IDD_PROPPAGE_STATISTICS, this);
- m_SecurityPage.Create(IDD_PROPPAGE_SECURITY, this);
- // activate main page
- ActivatePage(0);
- // Set the icon for this dialog.
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- // get registry values
- ENCODE_START
- #ifndef _DEBUG
- #ifdef TIMEDOG_VERSION
- try
- {
- CheckRegCode(); // 检查注册码;
- DWORD id;
- TCHAR HKey[50]="ffffffff",LKey[50]="ffffffff";
- TCHAR OutTime[50];
- TCHAR DevicePath[ 260];
- if(FindPort(0,DevicePath)!=0)
- exit(1);
- //LIBC.LIB,libcp.lib,msvcprt.lib
- TCHAR year[10],month[10],day[10],hour[10],minute[10],second[10];
- ReadTimeAuthFromEprom(HKey,LKey, OutTime, &id, 30128, HKey, LKey, DevicePath);
- CString str=OutTime;
- CString temp="年";
- int pos=str.Find (temp);
- temp=str.Left (pos);
- str=str.Right (str.GetLength ()-pos-2);
- strcpy(year, temp.GetBuffer (0));temp.ReleaseBuffer ();
- temp="月";
- pos=str.Find (temp);
- temp=str.Left (pos);
- str=str.Right (str.GetLength ()-pos-2);
- strcpy(month, temp.GetBuffer (0));temp.ReleaseBuffer ();
- temp="日";
- pos=str.Find (temp);
- temp=str.Left (pos);
- str=str.Right (str.GetLength ()-pos-2);
- strcpy(day, temp.GetBuffer (0));temp.ReleaseBuffer ();
- temp="小时";
- pos=str.Find (temp);
- temp=str.Left (pos);
- str=str.Right (str.GetLength ()-pos-4);
- strcpy(hour, temp.GetBuffer (0));temp.ReleaseBuffer ();
- temp="分钟";
- pos=str.Find (temp);
- temp=str.Left (pos);
- str=str.Right (str.GetLength ()-pos-4);
- strcpy(minute, temp.GetBuffer (0));temp.ReleaseBuffer ();
- temp="0";
- strcpy(second, temp.GetBuffer (0));temp.ReleaseBuffer ();
- long time1=ConvertStringToTimerReal(year, month, day, hour, minute, second);
- GetRunTimer(year, month, day, hour, minute, second, DevicePath);
- long time2=ConvertStringToTimerReal(year, month, day, hour, minute, second);
- // 软件可运行时间;
- g_dwSoftRunTime = time1 - time2;
- if( (time1-time2) <0)
- {
- AfxMessageBox("加密锁已过期, 请与经销商联系!!!");
- InputAuthDlg authdlg;
- authdlg.m_id=id;
- authdlg.m_time1=time1;
- authdlg.m_time2=time2;
- if(authdlg.DoModal ()!=IDOK)
- {
- CDialog::OnCancel ();
- return false;
- }
- }
- else if((time1-time2) < 288000 ) // 10天 = 10*8*3600=360000 能用天数小于10个工作日(8小时一工作日).
- {
- DogTimeOutDlg dlg;
- dlg.hour=(time1-time2)/3600;
- if(dlg.DoModal ()==IDOK)
- {
- InputAuthDlg authdlg;
- authdlg.m_id=id;
- authdlg.m_time1=time1;
- authdlg.m_time2=time2;
- authdlg.DoModal ();
- }
- }
- BOOL bOK=1;
- int d[8];double f[8];
- char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]="";
- //运行自定义函数
- // SoftKey ytSoftKey;
- int ret=0;//ytSoftKey.Ini();
- ret=ytSoftKey.checktime(&d[0],&d[1],&d[2],&d[3],&d[4],&d[5],&d[6],&d[7],
- &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],
- s0,s1,s2,s3,s4,s5,s6,s7);
- if(ret!=0 && ret!=-43)
- {
- bOK=0;
- }
- ////////////////////////写申请码
- if(bOK)
- {
- str=GetRegCode(id, time1, time2);
- char path[MAX_PATH];
- ::GetSystemDirectory (path, MAX_PATH);
- CString sysdir=path;
- sysdir+="\\regcode.txt";
- CStdioFile fp;
- if(fp.Open (sysdir, CFile::modeWrite|CFile::modeCreate))
- {
- fp.WriteString (str);
- fp.Close ();
- }
- }
- /////////////////////////
- }
- catch(...)
- {
- }
- #endif
- #endif
- ENCODE_END
- OnButton1(); // Jeff 初始化服务端,内含定时器1;
- GetFileDate(); // Jeff获取文件信息;
- LoadHistoryDB();//Jeff加载历史数据库;
- SetTimer(4, 1000, NULL);
- #if !USE_POOL
- int aaaa = 15;
- while (aaaa--)
- AddOneConn();//添加数据库连接;
- #endif
- SetTimer(2, 10, NULL);
- //CheckBakState();// 检查相片备份情况
- hInst = LoadLibrary("SENSAPI.DLL"); //加载动态库 ;
- if (hInst)
- {
- typedef BOOL(WINAPI *MYFUNC)(LPDWORD);
- MYFUNC IsNetworkConnect = NULL;
- //取得IsNetworkAlive函数指针;
- IsNetworkConnect = (MYFUNC)GetProcAddress(hInst, "IsNetworkAlive");
- if (IsNetworkConnect)
- {
- DWORD dwActiveWan = 1;
- if (IsNetworkConnect(&dwActiveWan))
- m_bNetWorkOK = 1;
- else
- m_bNetWorkOK = 0;
- SetTimer(5, 10000, NULL);
- }
- else
- m_bNetWorkOK = 0;
- }
- else
- m_bNetWorkOK = 0;
- if ( !CBranchInfo::GetInstance() )
- {
- AfxMessageBox(_T("内存分配错误"));
- return FALSE;
- }
- if ( !CBranchInfo::GetInstance()->InitCatalog(g_dwDBServerPort, g_szDBSource, g_szDBAccount, g_szDBPassWord, g_szDBName) )
- {
- AfxMessageBox(_T("初始化数据库连接对象失败"));
- return FALSE;
- }
- CBranchInfo::GetInstance()->GetTblVersion();
- CBranchInfo::GetInstance()->GetTblCatalogInfo();
- CBranchInfo::GetInstance()->GetTblNetShareInfo();
- // 1小时检测一次自动备份和自动删除服务是否启动
- // 是否自动检查服务
- if(g_bAutoCheckSvc == TRUE)
- {
- m_hExitCheckSvc = CreateEvent(NULL, FALSE, FALSE, NULL);
- m_hWaitTimeOut = CreateEvent(NULL, FALSE, FALSE, NULL);
- SetEvent(m_hWaitTimeOut);
- unsigned int nThreadID = 0;
- m_bStartCheckSvc = TRUE;
- m_hCheckSvcThread = (HANDLE)_beginthreadex(NULL, 0, CheckSvcWork, this, 0, &nThreadID);
- }
- return TRUE;
- }
- /********************************************************************/
- /* */
- /* Function name : OnDestroy */
- /* Description : Handle WM_DESTROY message */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnDestroy()
- {
- OnServerStop();
- KillTimer(1);
- KillTimer(2);
- KillTimer(3);
- KillTimer(4);
- KillTimer(5);
- KillTimer(6);
- KillTimer(7);
- KillTimer(8);
- CDialog::OnDestroy();
- }
- /********************************************************************/
- /* */
- /* Function name : OnServerStart */
- /* Description : Start Date Server -> start listening on port 21 */
- /* */
- /********************************************************************/
- //启动数据服务器,使其在指定端口侦听
- void CDBServerDlg::OnServerStart()
- {
- ServerStart();
- }
- BOOL CDBServerDlg::ServerStart()
- {
- if (theServer.Start())
- {
- m_wndStatusBar.SetPaneText(0, "数据服务已启动", TRUE);
- SetOnlineLed(TRUE);
- SetOfflineLed(FALSE);
- WriteTextLog("启动成功");
- return 1;
- }
- else
- {
- WriteTextLog("启动失败");
- CDialog::OnCancel();
- return 0;
- }
- }
- /********************************************************************/
- /* */
- /* Function name : OnUpdateServerStart */
- /* Description : Update 'Start' status */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnUpdateServerStart(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!theServer.IsActive());
- }
- /********************************************************************/
- /* */
- /* Function name : OnServerStop */
- /* Description : Stop Date Server */
- /* */
- /********************************************************************/
- //停止服务器
- void CDBServerDlg::OnServerStop()
- {
- theServer.Stop();
- m_wndStatusBar.SetPaneText(0, "数据服务已停止", TRUE);
- SetOnlineLed(FALSE);
- SetOfflineLed(TRUE);
- }
- /********************************************************************/
- /* */
- /* Function name : OnUpdateServerStop */
- /* Description : Update 'Stop' status */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnUpdateServerStop(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(theServer.IsActive());
- }
- /********************************************************************/
- /* */
- /* Function name : OnServerExit */
- /* Description : Let's get out of here... */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnServerExit()
- {
- OnCancel();
- }
- /********************************************************************/
- /* */
- /* Function name : CDBServerDlg::SetupOutlookBar */
- /* Description : Initialize listview, change color/iconspacing to */
- /* make it look a little bit like the outlook bar. */
- /* */
- /********************************************************************/
- void CDBServerDlg::SetupOutlookBar()
- {
- m_ImageList.Create(32, 32, ILC_COLOR16 | ILC_MASK, 1, 4);
- HICON hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_LOG));
- m_ImageList.Add(hIcon);
- hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ONLINE_USERS));
- m_ImageList.Add(hIcon);
- hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_CONFIGURATION));
- m_ImageList.Add(hIcon);
- hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_SECURITY));
- m_ImageList.Add(hIcon);
- hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_STATISTICS));
- m_ImageList.Add(hIcon);
- m_OutlookBar.SetImageList(&m_ImageList, LVSIL_NORMAL);
- CRect rc;
- m_OutlookBar.GetClientRect(rc);
- // set new icon spacing
- m_OutlookBar.SetIconSpacing(rc.Width(), 64);
- // change colors
- m_OutlookBar.SetTextColor(RGB(255, 255, 255));
- m_OutlookBar.SetTextBkColor(RGB(128, 128, 128));
- m_OutlookBar.SetBkColor(RGB(128, 128, 128));
- // insert items
- m_OutlookBar.InsertColumn(0, "OutlookBar");
- m_OutlookBar.InsertItem(0, "服务器日志", 0);
- m_OutlookBar.InsertItem(1, "在线用户", 1);
- m_OutlookBar.InsertItem(2, "关于", 2);
- m_OutlookBar.InsertItem(3, "功能区", 3);
- }
- /********************************************************************/
- /* */
- /* Function name : CDBServerDlg::MoveChilds */
- /* Description : Move child windows into place holder area. */
- /* */
- /********************************************************************/
- void CDBServerDlg::MoveChilds()
- {
- // position property pages
- CRect rcDlgs;
- // get dialog area rect
- GetDlgItem(IDC_DIALOG_AREA)->GetWindowRect(rcDlgs);
- ScreenToClient(rcDlgs);
- m_ConfigurationPage.MoveWindow(rcDlgs);
- m_TracePage.MoveWindow(rcDlgs);
- m_OnlineUsersPage.MoveWindow(rcDlgs);
- m_StatisticsPage.MoveWindow(rcDlgs);
- m_SecurityPage.MoveWindow(rcDlgs);
- }
- /********************************************************************/
- /* */
- /* Function name : CDBServerDlg::ActivatePage */
- /* Description : Called when an icon on the outlookbar is pressed.*/
- /* */
- /********************************************************************/
- void CDBServerDlg::ActivatePage(int nIndex)
- {
- switch (nIndex)
- {
- case 0:
- m_OnlineUsersPage.ShowWindow(SW_HIDE);
- m_ConfigurationPage.ShowWindow(SW_HIDE);
- m_StatisticsPage.ShowWindow(SW_HIDE);
- m_SecurityPage.ShowWindow(SW_HIDE);
- m_TracePage.ShowWindow(SW_SHOW);
- m_InfobarCtrl.SetText("服务器日志");
- break;
- case 1:
- m_TracePage.ShowWindow(SW_HIDE);
- m_ConfigurationPage.ShowWindow(SW_HIDE);
- m_StatisticsPage.ShowWindow(SW_HIDE);
- m_SecurityPage.ShowWindow(SW_HIDE);
- m_OnlineUsersPage.RefreshData();
- m_OnlineUsersPage.ShowWindow(SW_SHOW);
- m_InfobarCtrl.SetText("在线用户");
- break;
- case 2:
- m_OnlineUsersPage.ShowWindow(SW_HIDE);
- m_TracePage.ShowWindow(SW_HIDE);
- m_StatisticsPage.ShowWindow(SW_HIDE);
- m_SecurityPage.ShowWindow(SW_HIDE);
- m_ConfigurationPage.ShowWindow(SW_SHOW);
- m_InfobarCtrl.SetText("关于");
- break;
- case 4:
- m_OnlineUsersPage.ShowWindow(SW_HIDE);
- m_TracePage.ShowWindow(SW_HIDE);
- m_ConfigurationPage.ShowWindow(SW_HIDE);
- m_SecurityPage.ShowWindow(SW_HIDE);
- m_StatisticsPage.ShowWindow(SW_SHOW);
- m_InfobarCtrl.SetText("Statistics");
- break;
- case 3:
- m_OnlineUsersPage.ShowWindow(SW_HIDE);
- m_TracePage.ShowWindow(SW_HIDE);
- m_ConfigurationPage.ShowWindow(SW_HIDE);
- m_SecurityPage.ShowWindow(SW_SHOW);
- m_StatisticsPage.ShowWindow(SW_HIDE);
- m_InfobarCtrl.SetText("功能区");
- break;
- default:
- break;
- }
- MoveChilds();
- }
- /********************************************************************/
- /* */
- /* Function name : CDBServerDlg::OnClickOutlookBar */
- /* Description : User clicked on our listview -> activate page. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnClickOutlookBar(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // get index of selected item
- int nIndex = m_OutlookBar.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
- if (nIndex == -1)
- return;
- ActivatePage(nIndex);
- *pResult = 0;
- }
- /********************************************************************/
- /* */
- /* Function name : CDBServerDlg::OnKeydownOutlookBar */
- /* Description : User pressed a key -> activate page. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnKeydownOutlookBar(NMHDR* pNMHDR, LRESULT* pResult)
- {
- LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
- // get index of selected item
- int nIndex = m_OutlookBar.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
- if (nIndex == -1)
- return;
- if (pLVKeyDow->wVKey == VK_DOWN)
- {
- if (m_OutlookBar.GetItemCount() - 1 > nIndex)
- {
- ActivatePage(nIndex + 1);
- }
- }
- else if (pLVKeyDow->wVKey == VK_UP)
- {
- if (nIndex > 0)
- {
- ActivatePage(nIndex - 1);
- }
- }
- else if (pLVKeyDow->wVKey == VK_NEXT)
- {
- ActivatePage(m_OutlookBar.GetItemCount() - 1);
- }
- else if (pLVKeyDow->wVKey == VK_PRIOR)
- {
- ActivatePage(0);
- }
- *pResult = 0;
- }
- /********************************************************************/
- /* */
- /* Function name : CreateStatusbar */
- /* Description : This function creates a statusbar on a dialogbox.*/
- /* */
- /********************************************************************/
- BOOL CDBServerDlg::CreateStatusbar()
- {
- // Create the Toolbar and attach the resource
- if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
- {
- TRACE0("Failed to Create Dialog Toolbar\n");
- return FALSE;
- }
- m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);
- // Make it flat.
- m_wndToolBar.ModifyStyle(0, m_wndToolBar.GetStyle() | TBSTYLE_FLAT);
- // Create status bar at the bottom of the dialog window
- if (m_wndStatusBar.Create(this))
- {
- m_wndStatusBar.SetIndicators(auIDStatusBar, sizeof(auIDStatusBar) / sizeof(UINT));
- m_wndStatusBar.SetPaneText(0, "Date Server is offline", TRUE);
- // Make a sunken or recessed border around the first pane
- m_wndStatusBar.SetPaneInfo(0, m_wndStatusBar.GetItemID(0), SBPS_STRETCH, NULL);
- SetOnlineLed(FALSE);
- SetOfflineLed(FALSE);
- m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), ID_INDICATOR_ONLINELED, SBPS_NOBORDERS, 14);
- // m_wndStatusBar.GetStatusBarCtrl().SetTipText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), "This status light is green when the server is online");
- m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), ID_INDICATOR_OFFLINELED, SBPS_NOBORDERS, 14);
- // m_wndStatusBar.GetStatusBarCtrl().SetTipText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), "This status light is green when the server is online");
- }
- // We need to resize the dialog to make room for control bars.
- // First, figure out how big the control bars are.
- CRect rcClientStart;
- CRect rcClientNow;
- GetClientRect(rcClientStart);
- RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, rcClientNow);
- // Now move all the controls so they are in the same relative
- // position within the remaining client area as they would be
- // with no control bars.
- CPoint ptOffset(rcClientNow.left - rcClientStart.left, rcClientNow.top - rcClientStart.top);
- CRect rcChild;
- CWnd* pwndChild = GetWindow(GW_CHILD);
- while (pwndChild)
- {
- pwndChild->GetWindowRect(rcChild);
- ScreenToClient(rcChild);
- rcChild.OffsetRect(ptOffset);
- pwndChild->MoveWindow(rcChild, FALSE);
- pwndChild = pwndChild->GetNextWindow();
- }
- // Adjust the dialog window dimensions
- CRect rcWindow;
- GetWindowRect(rcWindow);
- rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
- rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
- MoveWindow(rcWindow, FALSE);
- // And position the control bars
- RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
- return TRUE;
- }
- /********************************************************************/
- /* */
- /* Function name : OnUserAccounts */
- /* Description : Show user accounts. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnUserAccounts()
- {
- /*
- CUserAccountsDlg dlg;
- theServer.m_UserManager.GetUserList(dlg.m_UserArray);
- if (dlg.DoModal() == IDOK)
- {
- theServer.m_UserManager.UpdateUserList(dlg.m_UserArray);
- }*/
- }
- /********************************************************************/
- /* */
- /* Function name : OnFTPUserConnected */
- /* Description : A user has connected to our server. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnFTPUserConnected(DWORD nThreadID, LPCTSTR lpszUser, LPCSTR lpszAddress)
- {
- m_OnlineUsersPage.AddUser(nThreadID, lpszUser, lpszAddress);
- }
- /********************************************************************/
- /* */
- /* Function name : OnFTPUserDisconnected */
- /* Description : A user has disconnected from our server. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnFTPUserDisconnected(DWORD nThreadID, LPCTSTR lpszUser)
- {
- m_OnlineUsersPage.RemoveUser(nThreadID);
- }
- /********************************************************************/
- /* */
- /* Function name : OnFTPStatusChange */
- /* Description : FTP Status changed. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnFTPStatusChange(int nType, LPCTSTR lpszText)
- {
- m_TracePage.AddTraceLine(nType, lpszText);
- switch (nType)
- {
- case 3:
- theApp.m_LogFile << error_lvl << date << time << lpszText << endl;
- break;
- default:
- theApp.m_LogFile << trace_lvl << date << time << lpszText << endl;
- break;
- }
- }
- /********************************************************************/
- /* */
- /* Function name : OnFTPReceivedBytesChange */
- /* Description : Number of received bytes has changed. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnFTPReceivedBytesChange(int nBytes)
- {
- m_StatisticsPage.SetValue(6, FormatSize(nBytes, 0));
- CString strStatus;
- strStatus.Format("%s received", FormatSize(nBytes, 0));
- m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_RECEIVED), strStatus, TRUE);
- CClientDC dc(this);
- CSize size = dc.GetTextExtent(strStatus);
- m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_RECEIVED), ID_INDICATOR_DATA_RECEIVED, SBPS_NORMAL, size.cx);
- }
- /********************************************************************/
- /* */
- /* Function name : OnFTPSentBytesChange */
- /* Description : Number of sent bytes has changed. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnFTPSentBytesChange(int nBytes)
- {
- m_StatisticsPage.SetValue(7, FormatSize(nBytes, 0));
- CString strStatus;
- strStatus.Format("%s sent", FormatSize(nBytes, 0));
- m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_SEND), strStatus, TRUE);
- CClientDC dc(this);
- CSize size = dc.GetTextExtent(strStatus);
- m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_SEND), ID_INDICATOR_DATA_SEND, SBPS_NORMAL, size.cx);
- }
- /********************************************************************/
- /* */
- /* Function name : OnViewTrace */
- /* Description : Handle menu selection. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnViewTrace()
- {
- ActivatePage(0);
- }
- /********************************************************************/
- /* */
- /* Function name : OnViewOnlineUsers */
- /* Description : Handle menu selection. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnViewOnlineUsers()
- {
- ActivatePage(1);
- }
- /********************************************************************/
- /* */
- /* Function name : OnViewConfiguration */
- /* Description : Handle menu selection. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnViewConfiguration()
- {
- ActivatePage(2);
- }
- /********************************************************************/
- /* */
- /* Function name : OnViewStatistics */
- /* Description : Handle menu selection. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnViewStatistics()
- {
- ActivatePage(3);
- }
- /********************************************************************/
- /* */
- /* Function name : OnViewSecurity */
- /* Description : Handle menu selection. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnViewSecurity()
- {
- ActivatePage(4);
- }
- /********************************************************************/
- /* */
- /* Function name : OnUpdateViewTrace */
- /* Description : Update menu state of Trace item. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnUpdateViewTrace(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(m_TracePage.IsWindowVisible());
- }
- /********************************************************************/
- /* */
- /* Function name : OnUpdateViewOnlineUsers */
- /* Description : Update menu state of Online Users item. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnUpdateViewOnlineUsers(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(m_OnlineUsersPage.IsWindowVisible());
- }
- /********************************************************************/
- /* */
- /* Function name : OnUpdateViewConfiguration */
- /* Description : Update menu state of Configuration item. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnUpdateViewConfiguration(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(m_ConfigurationPage.IsWindowVisible());
- }
- /********************************************************************/
- /* */
- /* Function name : OnUpdateViewStatistics */
- /* Description : Update menu state of Statistics item. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnUpdateViewStatistics(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(m_StatisticsPage.IsWindowVisible());
- }
- /********************************************************************/
- /* */
- /* Function name : OnUpdateViewSecurity */
- /* Description : Update menu state of Security item. */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnUpdateViewSecurity(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(m_SecurityPage.IsWindowVisible());
- }
- /********************************************************************/
- /* */
- /* Function name : SetOnlineLed */
- /* Description : Turn online LED on/off. */
- /* */
- /********************************************************************/
- void CDBServerDlg::SetOnlineLed(BOOL bOnline)
- {
- HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(),
- bOnline ? MAKEINTRESOURCE(IDI_LED_GREEN) : MAKEINTRESOURCE(IDI_LED_OFF),
- IMAGE_ICON, 16, 16, LR_SHARED);
- m_wndStatusBar.GetStatusBarCtrl().SetIcon(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), hIcon);
- m_wndStatusBar.GetStatusBarCtrl().Invalidate();
- m_wndStatusBar.GetStatusBarCtrl().UpdateWindow();
- DestroyIcon(hIcon);
- }
- /********************************************************************/
- /* */
- /* Function name : SetOfflineLed */
- /* Description : Turn offline LED on/off. */
- /* */
- /********************************************************************/
- void CDBServerDlg::SetOfflineLed(BOOL bOffline)
- {
- HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(),
- bOffline ? MAKEINTRESOURCE(IDI_LED_RED) : MAKEINTRESOURCE(IDI_LED_OFF),
- IMAGE_ICON, 16, 16, LR_SHARED);
- m_wndStatusBar.GetStatusBarCtrl().SetIcon(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), hIcon);
- m_wndStatusBar.GetStatusBarCtrl().Invalidate();
- m_wndStatusBar.GetStatusBarCtrl().UpdateWindow();
- DestroyIcon(hIcon);
- }
- void CDBServerDlg::OnFTPStatisticChange(int nType, int nValue)
- {
- m_StatisticsPage.SetValue(nType, nValue);
- }
- /********************************************************************/
- /* */
- /* Function name : FormatSize */
- /* Description : Format size, the way explorer diplays it */
- /* */
- /********************************************************************/
- char* CDBServerDlg::FormatSize(DWORD dwSizeLow, DWORD dwSizeHigh)
- {
- static char szBuff[100];
- unsigned __int64 nFileSize = ((unsigned __int64)(((DWORD)(dwSizeLow)) |
- ((unsigned __int64)((DWORD)(dwSizeHigh))) << 32));
- unsigned __int64 kb = 0;
- if (nFileSize > 1024)
- {
- kb = nFileSize / 1024;
- if (nFileSize % 1024)
- kb++;
- }
- // make it a string
- _ui64tot(kb, szBuff, 10);
- // add thousand seperators
- int nLength = lstrlen(szBuff);
- if (nLength > 3)
- {
- LPCTSTR ptr = szBuff;
- ptr += (nLength - 1);
- char szTemp[100];
- LPTSTR ptrTemp = szTemp;
- for (int i = 0; i < nLength; i++)
- {
- if (i && ((i % 3) == 0))
- {
- if (*ptrTemp != ',')
- {
- *ptrTemp = ',';
- ptrTemp = _tcsinc(ptrTemp);
- }
- }
- *ptrTemp = *ptr;
- ptrTemp = _tcsinc(ptrTemp);
- ptr = _tcsdec(szBuff, ptr);
- }
- // terminate string
- *ptrTemp = '\0';
- // reverse string
- _tcsrev(szTemp);
- lstrcpy(szBuff, szTemp);
- }
- // add 'KB' to it
- lstrcat(szBuff, " KB");
- return szBuff;
- }
- /********************************************************************/
- /* */
- /* Function name : OnAccountWizard */
- /* Description : Launch New Account Wizard */
- /* */
- /********************************************************************/
- void CDBServerDlg::OnAccountWizard()
- {/*
- CBitmap bmpHeader, bmpWatermark;
- VERIFY(bmpHeader.LoadBitmap(IDB_BANNER));
- VERIFY(bmpWatermark.LoadBitmap(IDB_WATERMARK));
- // show windows 2000-like wizard
- CWizardSheet wizSheet("New Account Wizard", this, 0, bmpWatermark, NULL, bmpHeader);
- wizSheet.m_psh.hInstance = ::GetModuleHandle(NULL);
- if (wizSheet.DoModal() == ID_WIZFINISH)
- {
- CArray<CUser, CUser&> m_UserArray;
- theServer.m_UserManager.GetUserList(m_UserArray);
- int nIndex = -1;
- for (int i = 0; i < m_UserArray.GetSize(); i++)
- {
- // if it already exists -> update it
- if (m_UserArray[i].m_strName.CompareNoCase(wizSheet.m_Page1.m_strAccountName) == 0)
- {
- nIndex = i;
- break;
- }
- }
- // add new account ?
- if (nIndex == -1)
- {
- CUser user;
- nIndex = m_UserArray.Add(user);
- }
- m_UserArray[nIndex].m_bAccountDisabled = FALSE;
- m_UserArray[nIndex].m_strName = wizSheet.m_Page1.m_strAccountName;
- m_UserArray[nIndex].m_strPassword = wizSheet.m_Page2.m_strPassword;
- // add home directory
- CDirectory directory;
- directory.m_strDir = wizSheet.m_Page3.m_strHomeDirectory;
- directory.m_strAlias = "";
- directory.m_bIsHomeDir = TRUE;
- directory.m_bAllowCreateDirectory = wizSheet.m_Page4.m_bAllowCreateDirectory;
- directory.m_bAllowDelete = wizSheet.m_Page4.m_bAllowDelete;
- directory.m_bAllowDownload = wizSheet.m_Page4.m_bAllowDownload;
- directory.m_bAllowRename = wizSheet.m_Page4.m_bAllowRename;
- directory.m_bAllowUpload = wizSheet.m_Page4.m_bAllowUpload;
- directory.m_strAlias = "";
- m_UserArray[nIndex].m_DirectoryArray.Add(directory);
- // update
- theServer.m_UserManager.UpdateUserList(m_UserArray);
- }*/
- }
- void CDBServerDlg::OnCancel()
- {
- }
- void CDBServerDlg::OnOK()
- {
- }
- void CDBServerDlg::OnButton1() // 启动服务;
- {
- // TODO: Add your control notification handler code here
- try
- {
- theServer.Initialize(this);
- if (ServerStart() == 0)
- return;
- if (g_pSkinData == NULL)
- InitLia();
- /////////////////////
- CString logdays;
- //MyLock lock("dbaccessxiao");
- CDatabase *pdb = NULL;
- ODBCConnGuard ConnGuard(pdb, -1, 3000);
- if ( pdb == NULL)
- return;
- CRecordset myset(pdb);
- CString sql = "select logdays from version";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("logdays", logdays);
- myset.Close();
- int days = 180;
- if (logdays == "1个月")
- days = 31;
- else if (logdays == "2个月")
- days = 61;
- else if (logdays == "3个月")
- days = 92;
- else
- days = 183;
- CTime tm = CTime::GetCurrentTime();
- CTimeSpan dt(240, 0, 0, 0); // Jeff 不使用days,固定使用天数;
- tm -= dt;
- CString date = tm.Format("%Y-%m-%d");
- // 删除日志前,取消触发器;2015-06-10
- sql = _T("DROP TRIGGER ON_DELETE_USER_LOGS");
- pdb->ExecuteSQL(sql);
- sql = "delete from [log] where [date]<'" + date + "'";
- pdb->ExecuteSQL(sql);
- // 删除日志后,恢复触发器;2015-06-10
- sql = _T("CREATE TRIGGER ON_DELETE_USER_LOGS ON [dbo].[log] FOR DELETE AS BEGIN rollback; END");
- pdb->ExecuteSQL(sql);
- ///////////////////
- tm = CTime::GetCurrentTime();
- CTimeSpan dt2(183, 0, 0, 0);
- tm -= dt2;
- date = tm.Format("%Y%m%d%H%M%S");
- sql = "delete from sendreg where [status]='OK' and [timestamp]<'" + date + "'";
- pdb->ExecuteSQL(sql);
- //////////////////////////////////
- sql = "select version from version";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("version", sql);
- myset.Close();
- m_ConfigurationPage.m_versionno = sql;
- m_ConfigurationPage.UpdateData(0);
- /////////////////////
- }
- catch (CException *e)
- {
- TCHAR szError[1024] = { 0 };
- e->GetErrorMessage(szError, 1024);
- WriteTextLog(CString(szError));
- e->Delete();
- }
- }
- void CDBServerDlg::OnClose()
- {
- m_TrayIcon.Create(this, WM_ICON_NOTIFY, "影楼管理系统服务器", m_hIcon, IDR_MENUtray); //构造
- ShowWindow(SW_HIDE); //隐藏窗口
- }
- LRESULT CDBServerDlg::OnTrayNotification(WPARAM wParam, LPARAM lParam)
- {
- return m_TrayIcon.OnTrayNotification(wParam, lParam);
- }
- void CDBServerDlg::OnOpen()
- {
- ShowWindow(SW_SHOW);
- }
- void CDBServerDlg::OnExit2()
- {
- try
- {
- TerminateThread();
- m_TrayIcon.RemoveIcon();
- if (g_pSkinData)delete[]g_pSkinData; g_pSkinData = NULL;
- //g_db.Close();
- for (int i = 0; i < g_dbHistoryArray.GetSize(); i++)
- {
- g_dbHistoryArray.ElementAt(i)->Close();
- delete g_dbHistoryArray.ElementAt(i);
- }
- ReleaseBranchDB();
- }
- catch (...)
- {
- WriteTextLog("出错在函数OnExit2中");
- }
- CDialog::OnCancel();
- }
- void CDBServerDlg::OnExit()
- {
- try
- {
- // 结束检查服务线程
- TerminateCheckWork();
- //结束一键生成小图线程
- if(CreateSmallPhoto::GetInstance()->IsCreating())
- {
- if(AfxMessageBox("温馨提示:生成小图还未完成确定要退出程序吗", MB_YESNO|MB_ICONSTOP) == IDNO)
- return;
- CreateSmallPhoto::GetInstance()->TerminateThread();
- }
- TerminateThread();
- DWORD id = FindAppProcessID("AutoRun.exe");
- if (id != -1)
- {
- HANDLE ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, id);
- if (ProcessHandle)TerminateProcess(ProcessHandle, 0);
- }
- m_TrayIcon.RemoveIcon();
- if (g_pSkinData)delete[]g_pSkinData; g_pSkinData = NULL;
- #if !USE_POOL
- g_db.Close();
- #endif
- for (int i = 0; i < g_dbHistoryArray.GetSize(); i++)
- {
- g_dbHistoryArray.ElementAt(i)->Close();
- delete g_dbHistoryArray.ElementAt(i);
- }
- ReleaseBranchDB();
- }
- catch (...)
- {
- WriteTextLog("出错在函数OnExit中");
- }
- CDialog::OnCancel();
- }
- void CDBServerDlg::OnTimer(UINT nIDEvent) //定时器;
- {
- try
- {
- if (nIDEvent == 1)
- {// 生成小图;
- KillTimer(nIDEvent);
- LoadThumbImages();
- }
- else if (nIDEvent == 2)
- {
- KillTimer(nIDEvent);
- OnClose();// 托盘显示;
- try
- {
- CheckHistoryData(); // Jeff:back history db data;
- LoadBranchInfo();
- }
- catch (...)
- {
- }
- SetTimer(1, 2 * 60 * 1000, NULL);
- SetTimer(4, 1000 * 60 * 2, NULL);
- SetTimer(7, 1000 * 60 * 60 * 1, NULL);
- SetTimer(8, 3000, NULL);
- SetTimer(9, 10000, NULL);
- }
- else if (nIDEvent == 3)
- {
- g_pMainWnd->KillTimer(3);
- HANDLE hMutex = ::OpenMutex(NULL, FALSE, _T("lyfzSMSHandle"));
- if (GetLastError() == ERROR_FILE_NOT_FOUND)
- {
- CString autorunpath = g_mainpath + _T("\\SMSHandle.exe");
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- }
- if(hMutex) CloseHandle(hMutex);
- }
- else if (nIDEvent == 4) //Jeff.这里也有自动启动MsgServer.exe服务处理,而且是2分钟/次的频率;
- {
- UpdateDate();
- CheckMemberMsg();
- BakPhoto();
- }
- else if (nIDEvent == 5)
- {
- typedef BOOL(WINAPI *MYFUNC)(LPDWORD);
- MYFUNC IsNetworkConnect = NULL;
- //取得IsNetworkAlive函数指针
- IsNetworkConnect = (MYFUNC)GetProcAddress(hInst, "IsNetworkAlive");
- if (IsNetworkConnect)
- {
- DWORD dwActiveWan = 1;
- BOOL state;
- if (IsNetworkConnect(&dwActiveWan))
- state = 1;
- else
- state = 0;
- if (m_bNetWorkOK != state)
- {
- KillTimer(nIDEvent);
- WriteTextLog("网络断开");
- OnExit2();
- }
- }
- }
- else if (nIDEvent == 6)
- {
- KillTimer(nIDEvent);
- ShutDown();
- }
- else if (nIDEvent == 7)
- {
- //CheckBakState();
- GenUPhoneData();
- }
- else if (nIDEvent == 8)
- {
- CheckConnCount();
- }
- }
- catch (...)
- {
- WriteTextLog("出错在函数Timer中");
- }
- }
- void LoadImageFromBuf(Image **img, BYTE *pData, DWORD leng)//g_bakserver1
- {
- try
- {
- if (pData == NULL)return;
- if (*img)delete *img;
- *img = NULL;
- // Allocate global memory on which to create stream
- HGLOBAL m_hMem = GlobalAlloc(GMEM_MOVEABLE, leng);
- if (m_hMem == NULL)return;
- BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
- memcpy(pmem, pData, leng);
- IStream* pstm;
- CreateStreamOnHGlobal(m_hMem, TRUE, &pstm);
- // load from stream
- *img = Gdiplus::Image::FromStream(pstm);
- // free/release stuff
- GlobalUnlock(m_hMem);
- pstm->Release();
- }
- catch (...)
- {
- }
- }
- void LoadImageFromBuf(Image **img, CString path)
- {
- try
- {
- CFile fp;
- if (fp.Open(path, CFile::modeRead))
- {
- DWORD leng = fp.GetLength();
- BYTE *pData = new BYTE[leng];
- fp.Read(pData, leng);
- fp.Close();
- LoadImageFromBuf(img, pData, leng);
- delete[]pData;
- }
- }
- catch (...)
- {
- }
- }
- void LoadImageFromRes(Image **img, LPCTSTR lpszResourceName, LPCTSTR ResourceType)
- {
- try
- {
- HGLOBAL hGlobal = NULL;
- HRSRC hSource = NULL;
- LPVOID lpVoid = NULL;
- int nSize = 0;
- BOOL bResult = FALSE;
- hSource = FindResource(NULL, lpszResourceName, ResourceType);
- if (hSource == NULL)return;
- hGlobal = LoadResource(NULL, hSource);
- if (hGlobal == NULL)return;
- lpVoid = LockResource(hGlobal);
- if (lpVoid == NULL)return;
- nSize = (UINT)SizeofResource(NULL, hSource);
- LoadImageFromBuf(img, (BYTE*)hGlobal, nSize);
- UnlockResource(hGlobal); // 16Bit Windows Needs This
- FreeResource(hGlobal); // 16Bit Windows Needs This (32Bit - Automatic Release)
- }
- catch (...)
- {
- }
- }
- // ---------------------------------------------------------------------------------------------------------------------------------------------------------------
- // TimeAt: 2014-09-15 AM;
- // Remark: Jeff;
- // 函数:GenSPhoto
- // 描述:对指定文件夹内的相片生成S或M缩略图;
- // 参数:
- // dir: 需要生成缩略图的文件目录;
- // bMPhoto: 是否生成M缩略图;
- // 其它:
- // 在生成缩略图前,记录jpg文件总数nOldCount,每生成一个缩略图nOldCount++;
- // 最后全部图生成完毕,获取新的jpg文件总数nNewCount,if(nOldCount == nNewCount)则表示所有相片已生成缩略图完毕,生成ok文件表示成功生成缩略图;
- //
- // 函数调用全局参数:
- // g_bSteal:意义未明!
- //
- // 注意:该函数非线程安全!
- // 非线程安全:
- // 获取文件总数nOldCount结束后,若有新文件在本函数以外其他函数或进程、线程被添加,则生成缩略图完成后再次获取文件总数nNewCount就不会与nOldCount++后的结果相等;
- // 而实际上本次缩略图已生成完毕。
- // ---------------------------------------------------------------------------------------------------------------------------------------------------------------
- void GenSPhoto(CString dir, BOOL bMPhoto) // 参数:bMPhoto:是否生成M缩略图;
- {
- // 如果是公告附件目录退出;
- if (dir.Find("公告附件") != -1)return;
- // 如果不是客户原片或修好的片目录,设置bMPhoto参数为0,不生成M缩略图;
- if (dir.Find("客户原片(管理软件)$") != -1 || dir.Find("修好的片(管理软件)$") != -1)
- {
- }
- else
- bMPhoto = 0;
- // 对指定文件目录dir进行指定后缀jpg文件遍历;
-
- ffsco o;
- o.dirs(1);
- o.find(LPCSTR(dir), LPCSTR("*.*"));
- ffsco::typeT coo;
- ffsco::typeT::iterator it;
- coo = o.co_file();
- int oldsize = coo.size();
- CString path, temp, spath, mpath;
- for (it = coo.begin(); coo.end() != it; it++)
- {
- try
- {
- if (g_pMainWnd->m_bTerminate)return;
- // 遍历到的jpg文件如果是缩略图则不处理,继续遍历;
- path = (*it).c_str();
- spath = path.Left(path.ReverseFind('\\') + 1);
- mpath = spath;
- spath += "s";
- mpath += "m";
- temp = path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
- if (temp.GetAt(0) == 's')continue;
- if (temp.GetAt(0) == 'm')continue;
- spath += path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
- mpath += path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
- if (g_bSteal)
- {
- Image *pImg = NULL;
- ::LoadImageFromBuf(&pImg, path);
- if (pImg == NULL)continue;
- if (pImg->GetWidth() == 0)continue; // Jeff.continue前未释放pImg;
- delete pImg;
- EncryptFile3(path);
- if (path.Find("客户原片") != -1)
- {
- int pos = path.Find("管理软件)$");
- if (pos != -1)
- {
- path = g_bakserver1 + path.Right(path.GetLength() - pos - 10);
- EncryptFile3(path);
- }
- }
- else if (path.Find("修好的片") != -1)
- {
- int pos = path.Find("管理软件)$");
- if (pos != -1)
- {
- path = g_bakserver2 + path.Right(path.GetLength() - pos - 10);
- EncryptFile3(path);
- }
- }
- else if (path.Find("精修好的片") != -1)
- {
- int pos = path.Find("管理软件)$");
- if (pos != -1)
- {
- path = g_bakserver3 + path.Right(path.GetLength() - pos - 10);
- EncryptFile3(path);
- }
- }
- else if (path.Find("设计好的片") != -1)
- {
- int pos = path.Find("管理软件)$");
- if (pos != -1)
- {
- path = g_bakserver4 + path.Right(path.GetLength() - pos - 10);
- EncryptFile3(path);
- }
- }
- oldsize++;
- }
- else if (!CheckFileExist(spath)) // 没有判断后续是否为jpg或jpeg.
- {
- Image *pImg = NULL;
- ::LoadImageFromBuf(&pImg, path);
- if (pImg == NULL)continue;
- if (pImg->GetWidth() == 0)
- {
- // 由于没有判断spath是否是jpg或jpeg的相片文件,导致这里泄漏;
- if (pImg)
- delete pImg;
- pImg = NULL;
- continue; // Jeff.返回前未释放pImg;
- }
- CRect rc(0, 0, 100, 90);
- RectFitDes(pImg->GetWidth(), pImg->GetHeight(), rc);
- Image *simg = pImg->GetThumbnailImage(rc.Width(), rc.Height(), NULL, NULL);
- if (simg == NULL)
- {
- if (pImg)
- delete pImg;
- pImg = NULL;
- continue;// Jeff.返回前未释放pImg;
- }
- Image *simg2 = NULL;
- if (bMPhoto)
- {
- CRect rc2(0, 0, 2000, 2000);
- RectFitDes(pImg->GetWidth(), pImg->GetHeight(), rc2);
- simg2 = pImg->GetThumbnailImage(rc2.Width(), rc2.Height(), NULL, NULL);
- if (simg2 == NULL)
- {
- if (pImg)
- delete pImg;
- pImg = NULL;
- continue;// Jeff.返回前未释放pImg;
- }
- }
- Graphics graphic(simg);//防止GetThumbnailImage影响质量
- graphic.Clear(Color(255, 255, 255, 255));
- graphic.DrawImage(pImg, 0, 0, simg->GetWidth(), simg->GetHeight());
- if (bMPhoto)
- {
- Graphics graphic2(simg2);//防止GetThumbnailImage影响质量
- graphic2.Clear(Color(255, 255, 255, 255));
- graphic2.DrawImage(pImg, 0, 0, simg2->GetWidth(), simg2->GetHeight());
- }
- ///////////////////////////////
- UINT totalBufferSize;
- UINT numProperties;
- pImg->GetPropertySize(&totalBufferSize, &numProperties);
- // Allocate the buffer that will receive the property items.
- PropertyItem* pAllItems = (PropertyItem*)malloc(totalBufferSize);
- // Fill the buffer.
- pImg->GetAllPropertyItems(totalBufferSize, numProperties, pAllItems);
- // Print the id data member of each property item.
- for (UINT j = 0; j < numProperties; ++j)
- {
- if (PropertyTagOrientation == pAllItems[j].id)
- {
- short* ptrLong = (short*)(pAllItems[j].value);
- int ret = (int)*ptrLong;
- // CString str;
- // str.Format ("%d", ret);
- // AfxMessageBox(str);
- if (ret == 8)
- {
- if (simg2)simg2->RotateFlip(Rotate270FlipNone);
- simg->RotateFlip(Rotate270FlipNone);
- }
- else if (ret == 6)
- {
- if (simg2)simg2->RotateFlip(Rotate90FlipNone);
- simg->RotateFlip(Rotate90FlipNone);
- }
- break;
- }
- }
- free(pAllItems);
- ///////////////////////////////
- ::SaveImageToFile(simg, spath); oldsize++;
- delete simg;
- delete pImg;
- if (bMPhoto)
- {
- ::SaveImageToFile2(simg2, mpath, 100); oldsize++;
- delete simg2;
- }
- }
- }
- catch (...)
- {
- WriteTextLog("出错在函数GenSPhoto中");
- }
- }
- try
- {
- ffsco o;
- o.dirs(1);
- o.find(LPCSTR(dir), LPCSTR("*.*"));
- ffsco::typeT coo;
- ffsco::typeT::iterator it;
- coo = o.co_file();
- int newsize = coo.size();
- if (oldsize == newsize)
- {
- path = dir + "\\ok";
- CFile fp;
- fp.Open(path, CFile::modeCreate | CFile::modeWrite);
- fp.Close();
- }
- }
- catch (...)
- {
- WriteTextLog("出错在函数GenSPhoto2中");
- }
- }
- //--------------------------------------------------------------------------------
- // Remark by Jeff 2014.10.22
- // 函数:LoadThumbNail
- // 描述:S或M缩略图线程
- // 参数:
- // 返回:
- //
- // 调用关系:SetTimer(1);
- // 1.
- // 2.
- // 3.
- //--------------------------------------------------------------------------------
- unsigned __stdcall LoadThumbNail(LPVOID lpParam)
- {
- BOOL bMphoto = 0;
- if (g_bSteal == 0)
- {
- CDatabase *pMaindb = NULL;
- ODBCConnGuard ConnGuard(pMaindb , -1, 3000);
- if ( pMaindb )
- {
- try
- {
- CRecordset myset(pMaindb);
- CString sql = "select * from version";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("setcheck15", sql); // 选片时是否使用m缩略图来代替原片放大使用;
- myset.Close();
- bMphoto = atoi(sql);
- }
- catch (CDBException* e)
- {
- WriteTextLog(_T("LoadThumbNail:%s"),e->m_strError);
- e->Delete();
- }
-
- }
- }
- CString initialPhotoPath = _T("");
- CString initialModifyPath = _T("");
- CString designPhotoPath = _T("");
- CString excellentModifyPath = _T("");
- char server[50] = {0};
- DWORD leng = 50;
- ::GetComputerName(server, &leng);
- initialPhotoPath = initialModifyPath = designPhotoPath = excellentModifyPath = server;
- initialPhotoPath = "\\\\" + initialPhotoPath + "\\客户原片(管理软件)$";
- initialModifyPath = "\\\\" + initialModifyPath + "\\修好的片(管理软件)$";
- designPhotoPath = "\\\\" + designPhotoPath + "\\设计好的片(管理软件)$";
- excellentModifyPath = "\\\\" + excellentModifyPath + "\\精修好的片(管理软件)$";
- GetPathFromNetShareName("客户原片(管理软件)$", initialPhotoPath);
- GetPathFromNetShareName("修好的片(管理软件)$", initialModifyPath);
- GetPathFromNetShareName("设计好的片(管理软件)$", designPhotoPath);
- GetPathFromNetShareName("精修好的片(管理软件)$", excellentModifyPath);
- int i = 0;
- CDBServerDlg *pDlg = (CDBServerDlg*)lpParam;
- try
- {
- CStringArray dirarray;
- // Remark:Jeff.
- // 遍历原片、修好片、设计片、精修片目录,查看是否有ok或ok.dat文件存在;
- // 说明:ok文件在客户端再次导入相片时会被删除;
- // 只有服务端生成小图后,ok才被重新生成;
- if(CBranchInfo::GetInstance()->m_TblNetShareInfo.size() != 0)
- {
- vector<TblNetShareInfo*>::iterator iter = CBranchInfo::GetInstance()->m_TblNetShareInfo.begin();
- for(; iter != CBranchInfo::GetInstance()->m_TblNetShareInfo.end();)
- {
- TblNetShareInfo* p = (*iter);
- if(p != NULL)
- {
- CString strDir = p->szShareDirectory;
- if(strDir.Find(_T("$\\")) != -1)
- strDir = strDir.TrimRight(_T("\\"));
- pDlg->CheckOkFileExistence(strDir, dirarray);
- }
- ++iter;
- }
- CString patharray[2] = { designPhotoPath, excellentModifyPath };
- //int i = 0;
- for (i = 0; i < 2; i++)
- {
- if (pDlg->m_bTerminate)
- break;
- pDlg->CheckOkFileExistence(patharray[i], dirarray);
- }
- }
- else
- {
- CString patharray[4] = { initialPhotoPath, initialModifyPath, designPhotoPath, excellentModifyPath };
- for (i = 0; i < 4; i++)
- {
- if (pDlg->m_bTerminate)
- break;
- pDlg->CheckOkFileExistence(patharray[i], dirarray);
- }
- }
-
- for (i = 0; i < dirarray.GetSize(); i++)
- {
- if (pDlg->m_bTerminate)
- break;
- GenSPhoto(dirarray.ElementAt(i), bMphoto);
- }
- }
- catch (...)
- {
- WriteTextLog("出错在函数GenThumb中");
- }
- pDlg->m_bRunning = false;
- pDlg->m_bTerminate = false;
- pDlg->SetTimer(1, 60 * 1000, NULL);
- _endthreadex(0);
- return 0;
- }
- //--------------------------------------------------------------------------------
- // 函数:CheckOkFileExistence
- // 描述:OK文件是否存在
- // 参数:
- // const CString& strPath 需要搜索的目录
- // CStringArray& arr 返回文件目录
- // 返回:TRUE成功,FALSE失败
- //--------------------------------------------------------------------------------
- BOOL CDBServerDlg::CheckOkFileExistence(const CString& strPath, CStringArray& arr)
- {
- CString path(_T("")), path2(_T(""));
- if(strPath == _T(""))
- return FALSE;
- ffsco o;
- o.dirs(1);
- o.find(LPCSTR(strPath), LPCSTR("*.*"));
- ffsco::typeT coo;
- ffsco::typeT::iterator it;
- coo = o.co_dir();
- it = coo.begin();
- it++;
- for(; coo.end() != it; it++)
- {
- if (m_bTerminate)
- break;
- path = (*it).c_str();
- path.TrimRight("\\");
- path2 = path;
- path2 += "\\ok2.dat";
- path += "\\ok";
- if (CheckFileExist(path2) && path2.Find(".ly.com") == -1)
- {
- ::DeleteFile(path); // 删除ok文件;
- ::DeleteFile(path2); // 删除ok.dat文件;
- }
- // g_bCheckAll g_bSteal的意义???
- // g_bCheckAll没有任何其他赋值的代码,只有最开始初始化值0;下这if不执行;
- if (g_bCheckAll || g_bSteal)
- {
- if (FindArray(&arr, (*it).c_str()) == -1)
- arr.Add((*it).c_str());
- }
- else if (CheckFileExist(path) == 0)
- {
- if (FindArray(&arr, (*it).c_str()) == -1)
- arr.Add((*it).c_str());
- }
- }
- return 1;
- }
- //自动生成小图线程;
- void CDBServerDlg::LoadThumbImages() // 自动生成小图线程;
- {
- if (m_bRunning)return;
- TerminateThread();
- m_bRunning = true;
- m_hThread = (HANDLE)_beginthreadex(NULL, 0, LoadThumbNail, (LPVOID)this, 0/* CREATE_SUSPENDED*/, &m_dwThreadID);
- }
- BOOL CDBServerDlg::TerminateThread()
- {
- try
- {
- if (!m_bRunning)
- return TRUE;
- m_bTerminate = true;
- for (;;)
- {
- if (::WaitForSingleObject(m_hThread, INFINITE) == WAIT_OBJECT_0)
- break;
- }
- ::CloseHandle(m_hThread);
- m_bRunning = false;
- return TRUE;
- }
- catch (...)
- {
- WriteTextLog("出错在函数TerminateThread中");
- }
- return TRUE;
- }
- void CDBServerDlg::InitLia()
- {
- try
- {
- // Jeff:逆天的变量命名!!!局部变量竟然用g_开头!!!
- //BYTE *g_pData=NULL;DWORD g_nLeng; DWORD count2;
- BYTE *pReturnData = NULL;
- DWORD dwReturnLen;
- DWORD count2;
- BYTE byCode = 104;
- CConnectSocket consock;
- #if USE_POOL
- ODBCConnGuard ConnGuard(consock.m_pConndb, -1, 3000);
- if ( consock.m_pConndb == NULL )
- return;
- #else
- consock.m_pConndb = &g_db;
- #endif
- consock.GetDataFromCode(byCode, &pReturnData, dwReturnLen, count2, "");
- if (pReturnData == NULL || dwReturnLen == 0)
- return;
- DWORD readbytes = 0;
- CArray<DWORD, DWORD> ArrayOfLen;
- CArray<DWORD, DWORD> ArrayOfBtnLen;
- BYTE *pArrayPointer = NULL;
- DWORD dwPointerLen = 0;
- DWORD leng;
- memcpy(&leng, pReturnData + readbytes, sizeof(DWORD));
- readbytes += sizeof(DWORD);
- BYTE *pFtData = new BYTE[leng];
- memcpy(pFtData, pReturnData + readbytes, leng);
- readbytes += leng;
- CMemFile memfile;
- memfile.Attach(pFtData, leng);
- CArchive ar(&memfile, CArchive::load);
- ArrayOfLen.Serialize(ar);
- ar.Close();
- memfile.Detach();
- memcpy(&leng, pReturnData + readbytes, sizeof(DWORD));
- readbytes += sizeof(DWORD);
- BYTE *pFtData2 = new BYTE[leng];
- memcpy(pFtData2, pReturnData + readbytes, leng);
- readbytes += leng;
- CMemFile memfile2;
- memfile2.Attach(pFtData2, leng);
- CArchive ar2(&memfile2, CArchive::load);
- ArrayOfBtnLen.Serialize(ar2);
- ar2.Close();
- memfile2.Detach();
- delete[]pFtData;
- delete[]pFtData2;
- DWORD count;
- memcpy(&count, pReturnData + readbytes, sizeof(DWORD));
- readbytes += sizeof(DWORD);
- dwPointerLen = count*sizeof(RESDATA2);
- pArrayPointer = new BYTE[dwPointerLen];
- int i = 0;
- for (i = 0; i < count; i++)
- {
- memcpy(pArrayPointer + i*sizeof(RESDATA2), pReturnData + readbytes, sizeof(RESDATA2));
- readbytes += sizeof(RESDATA2);
- }
- for (i = 0; i < ArrayOfLen.GetSize(); i += 8)
- {
- DWORD leng1, leng2, leng3, leng4, leng5, leng6, leng7, leng8;
- leng1 = ArrayOfLen.ElementAt(i);
- leng2 = ArrayOfLen.ElementAt(i + 1);
- leng3 = ArrayOfLen.ElementAt(i + 2);
- leng4 = ArrayOfLen.ElementAt(i + 3);
- leng5 = ArrayOfLen.ElementAt(i + 4);
- leng6 = ArrayOfLen.ElementAt(i + 5);
- leng7 = ArrayOfLen.ElementAt(i + 6);
- leng8 = ArrayOfLen.ElementAt(i + 7);
- if (i % 4 == 0)
- DeCodelong1((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8);
- else if (i % 4 == 1)
- DeCodelong2((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8);
- else if (i % 4 == 2)
- DeCodelong3((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8);
- else
- DeCodelong4((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8);
- ArrayOfLen.SetAt(i, leng1);
- ArrayOfLen.SetAt(i + 1, leng2);
- ArrayOfLen.SetAt(i + 2, leng3);
- ArrayOfLen.SetAt(i + 3, leng4);
- ArrayOfLen.SetAt(i + 4, leng5);
- ArrayOfLen.SetAt(i + 5, leng6);
- ArrayOfLen.SetAt(i + 6, leng7);
- ArrayOfLen.SetAt(i + 7, leng8);
- }
- delete[]pReturnData;
- if (g_pSkinData)
- delete[]g_pSkinData;
- g_pSkinData = NULL;
- DWORD length;
- BYTE *pData;
- DWORD length2;
- BYTE *pData2;
- CMemFile mStoreFile;
- CArchive arStore(&mStoreFile, CArchive::store);
- ArrayOfLen.Serialize(arStore);
- arStore.Close();
- length = mStoreFile.GetLength();
- pData = mStoreFile.Detach();
- CMemFile mStoreFile1;
- CArchive arStore1(&mStoreFile1, CArchive::store);
- ArrayOfBtnLen.Serialize(arStore1);
- arStore1.Close();
- length2 = mStoreFile1.GetLength();
- pData2 = mStoreFile1.Detach();
- g_SkinLeng = length + length2 + dwPointerLen + 3 * sizeof(DWORD);
- g_pSkinData = new BYTE[g_SkinLeng];
- readbytes = 0;
- memcpy(g_pSkinData + readbytes, &length, sizeof(DWORD));
- readbytes += sizeof(DWORD);
- memcpy(g_pSkinData + readbytes, pData, length);
- readbytes += length;
- memcpy(g_pSkinData + readbytes, &length2, sizeof(DWORD));
- readbytes += sizeof(DWORD);
- memcpy(g_pSkinData + readbytes, pData2, length2);
- readbytes += length2;
- memcpy(g_pSkinData + readbytes, &dwPointerLen, sizeof(DWORD));
- readbytes += sizeof(DWORD);
- memcpy(g_pSkinData + readbytes, pArrayPointer, dwPointerLen);
- readbytes += dwPointerLen;
- delete[]pArrayPointer;
- }
- catch (...)
- {
- WriteTextLog("出错在函数InitLia中");
- }
- }
- BOOL CheckExistDinDan(CString id)
- {
- #if USE_POOL
- CDatabase *pdb = NULL;
- ODBCConnGuard ConnGuard(pdb, -1, 30000);
- if ( pdb == NULL )
- return FALSE;
- CRecordset myset(pdb);
- #else
- CRecordset myset(&g_db);
- #endif
- CString sql = "select count(*) as cot from dindan where id='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- return atol(sql);
- }
- //CString g_nCurConvertDBName="db"; // Jeff.deal
- CString g_nCurConvertDBName(g_szDBName);
- DWORD CDBServerDlg::ThreadCallerElves(LPVOID lpPara)
- {
- CArray<int, int>codearray;
- codearray.Add(80);
- codearray.Add(90);
- codearray.Add(11);
- codearray.Add(138);
- codearray.Add(24);
- codearray.Add(181);
- codearray.Add(65);
- codearray.Add(56);
- codearray.Add(179);
- codearray.Add(53);
- CFile fp;
- CString savepath, strPath1;
- char server[50];
- DWORD leng = 50;
- ::GetComputerName(server, &leng);
- strPath1 = server;
- strPath1 = "\\\\" + strPath1 + "\\电话录音(管理软件)$";
- GetPathFromNetShareName("电话录音(管理软件)$", strPath1);
- if (strPath1.IsEmpty())
- return 0;
- try
- {
- CDatabase *pdb = NULL;
- for ( int i = 0; i < g_dbpool.GetSize(); i++ )
- {
- ODBCConnGuard ConnGuard(pdb, i-1, 3000);
- if ( !pdb )
- continue;
- savepath.Format("%s\\uphonedata%d.dat", strPath1, i);
- ::DeleteFile(savepath); // 删除uphonedata.dat文件;
- if (fp.Open(savepath, CFile::modeCreate | CFile::modeWrite) == 0)
- {
- WriteTextLog("更新来电精灵数据出错");
- return 0;
- }
- CConnectSocket consock;
- consock.m_pConndb = pdb;
- for (int i = 0; i < codearray.GetSize(); i++)
- {
- BYTE code = codearray.ElementAt(i);
- DWORD length, arraysize;
- BYTE *pReturn = NULL;
- consock.GetDataFromCode(code, &pReturn, length, arraysize, "");
- fp.Write(&code, sizeof(BYTE));
- fp.Write(&length, sizeof(DWORD));
- fp.Write(&arraysize, sizeof(DWORD));
- fp.Write(pReturn, length);
- }
- fp.Close();
- }
- }
- catch (CException *e)
- {
- TCHAR szError[1024] = { 0 };
- e->GetErrorMessage(szError, 1024);
- WriteTextLog(CString(szError));
- WriteTextLog("获取来电精灵数据出错1");
- e->Delete();
- }
- return 0;
- }
- /************************************************************************/
- /* [函数]:CheckHistoryData
- /* [描述]:将被检测的数据库已完成的订单数据转到历史数据库中,并删除被检测的数据库已完成的订单;
- /* [参数]:
- /* pSrcdb: 源数据库,用于被转历史的数据库;
- /* nSrcYear: 源数据库的年份;
- /* bMode2: 转储模式:0=年度完成的订单; 1=年度所有订单,包含未完成订单;
- /* [返回]:void
- /*
- /************************************************************************/
- void CDBServerDlg::CheckHistoryData(CDatabase *pSrcdb /* = NULL */, int nSrcYear /* = 0 */, BOOL bMode2 /* = 0*/)//历史备份;
- {
- #if 0
- // 取消转将当前数据库完成订单的记录转到年份数据库中,此步直接返回;
- /////////////////////////生成来电精灵数据
- MyLock lock("processChatMessageRequestxiao");
- CArray<int, int>codearray;
- codearray.Add(80);
- codearray.Add(90);
- codearray.Add(11);
- codearray.Add(138);
- codearray.Add(24);
- codearray.Add(181);
- codearray.Add(65);
- codearray.Add(56);
- codearray.Add(179);
- codearray.Add(53);
- CFile fp;
- CString savepath, g_path1;
- char server[50];
- DWORD leng = 50;
- ::GetComputerName(server, &leng);
- g_path1 = server;
- g_path1 = "\\\\" + g_path1 + "\\电话录音(管理软件)$";
- GetPathFromNetShareName("电话录音(管理软件)$", g_path1);
- if (g_path1.IsEmpty())return;
- try
- {
- CDatabase *pdb = NULL;
- for ( int i = 0; i < g_dbpool.GetSize(); i++ )
- {
- ODBCConnGuard ConnGuard(pdb, i-1, 3000);
- if ( !pdb )
- continue;
- savepath.Format("%s\\uphonedata%d.dat", g_path1, i);
- ::DeleteFile(savepath); // 删除uphonedata.dat文件;
- if (fp.Open(savepath, CFile::modeCreate | CFile::modeWrite) == 0)
- {
- WriteTextLog("更新来电精灵数据出错");
- return;
- }
- CConnectSocket consock;
- consock.m_pConndb = pdb;
- for (int i = 0; i < codearray.GetSize(); i++)
- {
- BYTE code = codearray.ElementAt(i);
- DWORD length, arraysize;
- BYTE *pReturn = NULL;
- consock.GetDataFromCode(code, &pReturn, length, arraysize, "");
- fp.Write(&code, sizeof(BYTE));
- fp.Write(&length, sizeof(DWORD));
- fp.Write(&arraysize, sizeof(DWORD));
- fp.Write(pReturn, length);
- }
- fp.Close();
- }
- }
- catch (CException *e)
- {
- TCHAR szError[1024] = { 0 };
- e->GetErrorMessage(szError, 1024);
- WriteTextLog(CString(szError));
- WriteTextLog("获取来电精灵数据出错1");
- e->Delete();
- }
- #endif
- HANDLE h = CreateThread(NULL, 0, ThreadCallerElves, this, 0, NULL);
- if ( h )CloseHandle(h);
- }
- //------------------------------------------------------------------------------------
- // Jeff remark
- // 函数:CheckYear
- // 描述:
- // 1.检查指定年份的历史数据库mdf文件是否存在,存在则直接附加
- // 2.不存在,则使用null.mdf文件拷贝创建历史年份数据库mdf并附加;
- // 参数:
- // year:被检查年份值;
- // 返回:void
- //------------------------------------------------------------------------------------
- #if JEFF_TEST_ON
- void CDBServerDlg::CheckYear(int year)
- {
- #if USE_POOL
- CDatabase *pdb = NULL;
- ODBCConnGuard ConnGuard(pdb, -1, 3000);
- if ( pdb == NULL )
- return;
- pdb->SetQueryTimeout(6000);
- #endif
- try
- {
- #ifdef SQLSERVER_VERSION
- CString sql;
- // 1.判断年份数据库是否存在;
- CString strPathOfYearmdf;
- CString strPathOfYearldf;
- strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, year);
- strPathOfYearldf.Format("%s\\数据\\%d_log.ldf", g_mainpath, year);
- CString strPathOfnulldbmdf = g_mainpath + "\\数据\\dbnull.mdf";
- CString strPathOfnulldbldf = g_mainpath + "\\数据\\dbnull_log.ldf";
- if (PathFileExists(strPathOfYearmdf) == TRUE)
- {
- if (PathFileExists(strPathOfYearldf) == TRUE)
- {
- sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", year, strPathOfYearmdf, strPathOfYearldf);
- }
- else
- {
- // 此时要删除dbnull_log.ldf文件;
- // 因为如果2015没有对应的ldf文件,在逻辑名仍为dbnull没有改为2015时,他会使用dbnull_log.ldf做为2015数据库的日志文件;
- // 这样造成其他数据库在使用dbnull时会产生错误;
- DeleteFile(strPathOfnulldbldf);//删除dbnull_log.ldf文件;
- sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf);
- }
- try
- {
- pdb->ExecuteSQL(sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- WriteTextLog("历史数据库初始化失败!");
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- return;
- }
- }
- else
- {
- // 判断dbnull.mdf文件是否存在;
- if (PathFileExists(strPathOfnulldbmdf) == FALSE)
- {
- WriteTextLog("空数据库丢失!");
- return;
- }
- // 判断拷贝mdf文件是否失败;
- if (FALSE == CopyFile(strPathOfnulldbmdf, strPathOfYearmdf, 1))
- {
- DWORD dwError = ::GetLastError();
- CString strDescription;
- strDescription.Format("dbnull.mdf拷贝为%d.mdf失败", year);
- ErrorExit(strDescription, dwError);
- return;
- }
- else
- {
- DeleteFile(strPathOfYearldf); // 删除%d_log.LDF文件;
- if (PathFileExists(strPathOfnulldbldf) == TRUE)
- {
- if (FALSE == CopyFile(strPathOfnulldbldf, strPathOfYearldf, 1))
- {
- DWORD dwError = ::GetLastError();
- CString strDescription;
- strDescription.Format("null.mdf拷贝为%d.mdf", year);
- ErrorExit(strDescription, dwError);
- // 此时要删除dbnull_log.ldf文件;
- // 因为如果2015没有对应的ldf文件,在逻辑名仍为dbnull没有改为2015时,他会使用dbnull_log.ldf做为2015数据库的日志文件;
- // 这样造成其他数据库在使用dbnull时会产生错误;
- DeleteFile(strPathOfnulldbldf);//删除dbnull_log.ldf文件;
- sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf);
- }
- else
- {
- sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", year, strPathOfYearmdf, strPathOfYearldf);
- }
- }
- else
- {
- // 此时要删除dbnull_log.ldf文件;
- // 因为如果2015没有对应的ldf文件,在逻辑名仍为dbnull没有改为2015时,他会使用dbnull_log.ldf做为2015数据库的日志文件;
- // 这样造成其他数据库在使用dbnull时会产生错误;
- DeleteFile(strPathOfnulldbldf);//删除dbnull_log.ldf文件;
- sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf);
- }
- try
- {
- pdb->ExecuteSQL(sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- WriteTextLog("历史数据库初始化失败!");
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- return;
- }
- }
- }
- // 附加成功后,修改逻辑名称;
- sql.Format("alter database [%d] modify file(name='dbnull',newname='%d')", year, year);
- try
- {
- pdb->ExecuteSQL(sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- WriteTextLog("修改历史数据库主文件逻辑名失败,请手动修改!");
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- sql.Format("alter database [%d] modify file(name='dbnull_log',newname='%d_log')", year, year);
- try
- {
- pdb->ExecuteSQL(sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- WriteTextLog("修改历史数据库日志文件逻辑名失败,请手动修改!");
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- OnExit2();
- #else
- CString path,sql;
- path.Format ("%s\\数据\\%d.mdb", g_mainpath, year);
- if(::PathFileExists (path)==0)
- {
- CString nulldb=g_mainpath+"\\数据\\dbnull.mdb";
- ::CopyFile (nulldb, path, 1);
- CDatabase *db=new CDatabase;
- CString strCon;
- strCon.Format("DRIVER=Microsoft Access Driver (*.mdb);DSN='';DBQ=%s;PWD=lijialyfz",path);
- if(db->OpenEx(strCon,CDatabase::noOdbcDialog))
- {
- g_nYearArray.Add (year);
- g_dbHistoryArray.Add (db);
- sql.Format ("insert into historydb([year])values('%d')", year);
- MyExecuteSQL(&g_db, sql);
- }
- else
- delete db;
- }
- #endif
- }
- catch (...)
- {
- WriteTextLog("出错在函数CheckYear中");
- }
- }
- #else
- void CDBServerDlg::CheckYear(int year)
- {
- try
- {
- #ifdef SQLSERVER_VERSION
- CString strPathOfYearmdf;
- CString strPathOfYearldf;
- CString sql;
- strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, year);
- strPathOfYearldf.Format("%s\\数据\\%d_log.LDF", g_mainpath, year);
- ::DeleteFile(strPathOfYearldf); // 删除%d_log.LDF文件;
- {
- CString strPathOfnulldbmdf = g_mainpath + "\\数据\\dbnull.mdf";
- CString strPathOfnulldbldf = g_mainpath + "\\数据\\dbnull_log.LDF";
- ::DeleteFile(strPathOfnulldbldf); // 删除%d_log.LDF文件;
- // 1.判断null.mdf文件是否存在;
- if (::PathFileExists(strPathOfnulldbmdf) == 0)
- {
- WriteTextLog("空数据库丢失!");
- return;
- }
- // 2.若年份mdf文件不存在,用null.mdf复制一份年份mdf数据库文件;
- BOOL bCopyed = 0;
- if (::PathFileExists(strPathOfYearmdf) == 0)
- {
- #if 0
- ::CopyFile(nulldb, path, 1);
- bCopyed=1;
- #else // Jeff add:判断拷贝文件失败的原因;
- if (!::CopyFile(strPathOfnulldbmdf, strPathOfYearmdf, 1))
- {
- DWORD dwError = ::GetLastError();
- CString strDescription;
- strDescription.Format("null.mdf拷贝为%d.mdf", year);
- ErrorExit(strDescription, dwError);
- // return;//直接返回;
- }
- else
- {
- bCopyed = 1;
- }
- #endif
- }
- if (::PathFileExists(strPathOfYearmdf) == 0)
- {
- WriteTextLog("拷贝数据库文件失败!");
- return;
- }
- BOOL bLog = 0;
- if (::PathFileExists(strPathOfnulldbldf))
- {
- bLog = 1;
- }
- // .将年份数据库mdf附加到数据库里;
- CString sql;
- if (bCopyed)
- {
- if (bLog)
- sql.Format("exec sp_attach_db '%s',@filename1='%s',@filename2='%s'", "dbnull", strPathOfYearmdf, strPathOfYearldf);
- else
- sql.Format("exec sp_attach_db '%s',@filename1='%s'", "dbnull", strPathOfYearmdf);
- g_db.SetQueryTimeout(600);
- try
- {
- g_db.ExecuteSQL(sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- WriteTextLog("历史数据库初始化失败!");
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- sql.Format("exec sp_renamedb '%s','%d'", "dbnull", year); g_db.ExecuteSQL(sql);
- }
- else // 没有执行CopyFile,年份mdf原本就存在;
- {
- if (bLog)
- sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", year, strPathOfYearmdf, strPathOfYearldf);
- else
- sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf);
- g_db.SetQueryTimeout(600);
- try
- {
- g_db.ExecuteSQL(sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- WriteTextLog("历史数据库初始化失败!");
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- }
- OnExit2();
- /* g_db.SetQueryTimeout(100);
- CDatabase *db=new CDatabase;
- try
- {
- CString strCon;
- strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=%d;%s"), g_sservrename,year,g_sdbpsw);
- db->OpenEx(strCon,CDatabase::noOdbcDialog);
- g_nYearArray.Add (year);
- dbarray.Add (db);
- sql.Format ("insert into [historydb]([year])values('%d')", year);
- MyExecuteSQL(&g_db, sql);
- }
- catch(CDBException * e)
- {
- delete db;
- WriteTextLog(e->m_strError);
- WriteTextLog("历史数据库打开失败!");
- }*/
- }
- #else
- CString path,sql;
- path.Format ("%s\\数据\\%d.mdb", g_mainpath, year);
- if(::PathFileExists (path)==0)
- {
- CString nulldb=g_mainpath+"\\数据\\dbnull.mdb";
- ::CopyFile (nulldb, path, 1);
- CDatabase *db=new CDatabase;
- CString strCon;
- strCon.Format("DRIVER=Microsoft Access Driver (*.mdb);DSN='';DBQ=%s;PWD=lijialyfz",path);
- if(db->OpenEx(strCon,CDatabase::noOdbcDialog))
- {
- g_nYearArray.Add (year);
- g_dbHistoryArray.Add (db);
- sql.Format ("insert into historydb([year])values('%d')", year);
- MyExecuteSQL(&g_db, sql);
- }
- else
- delete db;
- }
- #endif
- }
- catch (...)
- {
- WriteTextLog("出错在函数CheckYear中");
- }
- }
- #endif
- CDatabase* CDBServerDlg::GetDB(int year)
- {
- try
- {
- for (int i = 0; i < g_nYearArray.GetSize(); i++)
- {
- if (g_nYearArray.ElementAt(i) == year)
- {
- return g_dbHistoryArray.ElementAt(i);
- }
- }
- return NULL;
- }
- catch (...)
- {
- WriteTextLog("出错在函数GetDB中");
- }
- return NULL;
- }
- /************************************************************************/
- /* mark by Jeff;
- /* 函数:CheckDinDanExist
- /* 描述:
- /* 参数:
- /* pBeConverted_db:(源)
- /* pToConverted_db:(目标)
- /* strOderNumber:
- /* pRetArray:
- /*
- /* 返回:1表示正常,100及以上表示源数据库里记录 > 目标数据库记录;
- /*
- /************************************************************************/
- BOOL CDBServerDlg::CheckDinDanExist(CDatabase *pBeConverted_db, CDatabase *pToConverted_db, CString strOderNumber, CStringArray *pRetArray)
- {
- try
- {
- pRetArray->RemoveAll();
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from dindan where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from dindan where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//100
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from dindansp where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from dindansp where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//101
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from dindanbukuan where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from dindanbukuan where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//102
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from dindanbukuan2 where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from dindanbukuan2 where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//103
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from photoprint where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from photoprint where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//104
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from client where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from client where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//105
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from burncdreg where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from burncdreg where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//7
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from digitalwork where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from digitalwork where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//8
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from mywork where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from mywork where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//9
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from dindanjd where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from dindanjd where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)//10
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from dindansp2 where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from dindansp2 where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- {
- CRecordset myset(pBeConverted_db);
- sql = "select count(*) as cot from dindansp3 where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pToConverted_db);
- sql = "select count(*) as cot from dindansp3 where id='" + strOderNumber + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)
- pRetArray->Add("0");
- else
- pRetArray->Add("1");
- for (int i = 0; i < pRetArray->GetSize(); i++)
- {
- if (pRetArray->ElementAt(i) == "0")return 100 + i;
- }
- return 1;
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- WriteTextLog("出错在函数check1中");
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- return 100;
- }
- BOOL CDBServerDlg::CheckPayOutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql.Format("select count(*) as cot from gudingfeiyong where [id]=%d", atol(id));
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from gudingfeiyong where [id]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check2中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckIncomeExist(CDatabase *pdb1, CDatabase *pdb2, CString id, CStringArray *pretarray)
- {
- try
- {
- pretarray->RemoveAll();
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql.Format("select count(*) as cot from singleincome where [id]=%d", atol(id));
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from singleincome where [id]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)
- pretarray->Add("0");
- else
- pretarray->Add("1");
- {
- CRecordset myset(pdb1);
- sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id);
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id);
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)
- pretarray->Add("0");
- else
- pretarray->Add("1");
- for (int i = 0; i < pretarray->GetSize(); i++)
- {
- if (pretarray->ElementAt(i) == "0")return 0;
- }
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckIncomeMoneyExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id);
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id);
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- /************************************************************************/
- /* mark by Jeff
- /* 函数:TransDinDan
- /* 描述:
- /* 参数:
- /* pBeConverted_db:被转换的数据库(源);
- /* pToConverted_db:要转到的数据库(目标);
- /* strOrderNumber: 订单号;
- /* nYear: 要转换的年份;
- /*
- /* 返回:
- /************************************************************************/
- int CDBServerDlg::TransDinDan(CDatabase *pBeConverted_db, CDatabase *pToConverted_db, CString strOrderNumber, int nYear)
- {
- int step = 0;
- CStringArray retarray;
- try
- {
- CString sql, str;
- // CheckDinDanExist返回:1表示正常, 100及以上表示源数据库里记录 > 目标数据库记录;
- if (CheckDinDanExist(pBeConverted_db, pToConverted_db, strOrderNumber, &retarray) == 1)
- return 1;
- step = 1;
- int i;
- CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- int ret = 1;
- // 以下全是insert into 到目录数据库中;
- CRecordset myset(pBeConverted_db);
- try
- {
- if (retarray.ElementAt(0) == "0")
- {
- sql.Format("insert into [%d].[dbo].[dindan] select * from [%s].[dbo].[dindan] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step2" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 2;
- }
- step = 2;
- try
- {
- if (retarray.ElementAt(1) == "0")
- {
- sql.Format("insert into [%d].[dbo].[dindansp] select * from [%s].[dbo].[dindansp] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step3" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 3;
- }
- step = 3;
- try
- {
- if (retarray.ElementAt(2) == "0")
- {
- 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);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step4" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 4;
- }
- step = 4;
- try
- {
- if (retarray.ElementAt(3) == "0")
- {
- 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);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step5" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 5;
- }
- step = 5;
- try
- {
- if (retarray.ElementAt(4) == "0")
- {
- sql.Format("insert into [%d].[dbo].[photoprint] select * from [%s].[dbo].[photoprint] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step6" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 6;
- }
- step = 6;
- try
- {
- if (retarray.ElementAt(5) == "0")
- {
- sql.Format("insert into [%d].[dbo].[client] select * from [%s].[dbo].[client] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step7" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 7;
- }
- step = 7;
- try
- {
- if (retarray.ElementAt(6) == "0")
- {
- sql.Format("insert into [%d].[dbo].[burncdreg] select * from [%s].[dbo].[burncdreg] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step8" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 8;
- }
- step = 8;
- try
- {
- if (retarray.ElementAt(7) == "0")
- {
- sql.Format("insert into [%d].[dbo].[digitalwork] select * from [%s].[dbo].[digitalwork] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step9" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 9;
- }
- step = 9;
- try
- {
- if (retarray.ElementAt(8) == "0")
- {
- sql.Format("insert into [%d].[dbo].[mywork] select * from [%s].[dbo].[mywork] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step10" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 10;
- }
- step = 10;
- try
- {
- if (retarray.ElementAt(9) == "0")
- {
- sql.Format("insert into [%d].[dbo].[dindanjd] select * from [%s].[dbo].[dindanjd] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step11" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 11;
- }
- step = 11;
- try
- {
- if (retarray.ElementAt(10) == "0")
- {
- sql.Format("insert into [%d].[dbo].[dindansp2] select * from [%s].[dbo].[dindansp2] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step12" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 12;
- }
- step = 12;
- try
- {
- if (retarray.ElementAt(11) == "0")
- {
- sql.Format("insert into [%d].[dbo].[dindansp3] select * from [%s].[dbo].[dindansp3] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber);
- MyExecuteSQL(pBeConverted_db, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog("step13" + e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 13;
- }
- if (ret != 1)return 200 + ret;
- // 插入到目标数据库后再到目标数据库里查询是否存在;
- return CheckDinDanExist(pBeConverted_db, pToConverted_db, strOrderNumber, &retarray);
- }
- catch (...)
- {
- CString str;
- str.Format("%d size:%d", step, retarray.GetSize());
- WriteTextLog("出错在函数trans1中-" + str);
- }
- return 0;
- }
- BOOL CDBServerDlg::TransPayOut(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckPayOutExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[gudingfeiyong] select * from [%s].[dbo].[gudingfeiyong] where id=%d", year, g_nCurConvertDBName, atol(id));
- MyExecuteSQL(pdb1, sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckPayOutExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans2中");
- }
- return 0;
- }
- //singleincome
- BOOL CDBServerDlg::TransIncome(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- CStringArray retarray;
- if (CheckIncomeExist(pdb1, pdb2, id, &retarray))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- if (retarray.ElementAt(0) == "0")
- {
- sql.Format("insert into [%d].[dbo].[singleincome] select * from [%s].[dbo].[singleincome] where id=%d", year, g_nCurConvertDBName, atol(id));
- MyExecuteSQL(pdb1, sql);
- }
- }
- catch (...)
- {
- ret = 0;
- }
- try
- {
- if (retarray.ElementAt(1) == "0")
- {
- sql.Format("insert into [%d].[dbo].[singleincomemoney] select * from [%s].[dbo].[singleincomemoney] where id='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckIncomeExist(pdb1, pdb2, id, &retarray);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::TransIncomeMoney(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckIncomeMoneyExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[singleincomemoney] select * from [%s].[dbo].[singleincomemoney] where id='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckIncomeMoneyExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Checkclient2phonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from client2phonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from client2phonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transclient2phonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (Checkclient2phonerecordExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[client2phonerecord] select * from [%s].[dbo].[client2phonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return Checkclient2phonerecordExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Checkclient3phonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from client3phonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from client3phonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transclient3phonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (Checkclient3phonerecordExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[client3phonerecord] select * from [%s].[dbo].[client3phonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return Checkclient3phonerecordExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Checkclient2phonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from client2phonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from client2phonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transclient2phonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (Checkclient2phonerecordoutExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[client2phonerecordout] select * from [%s].[dbo].[client2phonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return Checkclient2phonerecordoutExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Checkclient3phonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from client3phonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from client3phonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transclient3phonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (Checkclient3phonerecordoutExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[client3phonerecordout] select * from [%s].[dbo].[client3phonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return Checkclient3phonerecordoutExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckemployeephonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from employeephonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from employeephonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transemployeephonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckemployeephonerecordExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[employeephonerecord] select * from [%s].[dbo].[employeephonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckemployeephonerecordExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckemployeephonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from employeephonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from employeephonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transemployeephonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckemployeephonerecordoutExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[employeephonerecordout] select * from [%s].[dbo].[employeephonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckemployeephonerecordoutExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckphonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from phonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from phonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transphonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckphonerecordExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[phonerecord] select * from [%s].[dbo].[phonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckphonerecordExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckphonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from phonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from phonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transphonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckphonerecordoutExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[phonerecordout] select * from [%s].[dbo].[phonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckphonerecordoutExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckunknownphonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from unknownphonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from unknownphonerecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transunknownphonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckunknownphonerecordExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[unknownphonerecord] select * from [%s].[dbo].[unknownphonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckunknownphonerecordExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckunknownphonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from unknownphonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from unknownphonerecordout where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transunknownphonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckunknownphonerecordoutExist(pdb1, pdb2, id))return 1;
- int i; CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[unknownphonerecordout] select * from [%s].[dbo].[unknownphonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckunknownphonerecordoutExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckmisscallrecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql = "select count(*) as cot from misscallrecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql = "select count(*) as cot from misscallrecord where [datetime]='" + id + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::Transmisscallrecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckmisscallrecordExist(pdb1, pdb2, id))return 1;
- int i;
- CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[misscallrecord] select * from [%s].[dbo].[misscallrecord] where [datetime]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckmisscallrecordExist(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::CheckSendReg(CDatabase *pdb1, CDatabase *pdb2, CString id)
- {
- try
- {
- int count1 = 0;
- int count2 = 0;
- CString sql;
- {
- CRecordset myset(pdb1);
- sql.Format("select count(*) as cot from sendreg where [timestamp]='%s'", id);
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count1 = atoi(sql);
- }
- {
- CRecordset myset(pdb2);
- sql.Format("select count(*) as cot from sendreg where [timestamp]='%s'", id);
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- count2 = atoi(sql);
- }
- if (count1 > count2)return 0;
- return 1;
- }
- catch (...)
- {
- WriteTextLog("出错在函数check3中");
- }
- return 0;
- }
- BOOL CDBServerDlg::TransSendReg(CDatabase *pdb1, CDatabase *pdb2, CString id, int year)
- {
- try
- {
- CString sql;
- if (CheckSendReg(pdb1, pdb2, id))return 1;
- int i;
- CString temp;
- int colcount;
- CODBCFieldInfo fieldinfo;
- BOOL ret = 1;
- CRecordset myset(pdb1);
- try
- {
- sql.Format("insert into [%d].[dbo].[sendreg] select * from [%s].[dbo].[sendreg] where [timestamp]='%s'", year, g_nCurConvertDBName, id);
- MyExecuteSQL(pdb1, sql);
- }
- catch (...)
- {
- ret = 0;
- }
- if (ret == 0)return 0;
- return CheckSendReg(pdb1, pdb2, id);
- }
- catch (...)
- {
- WriteTextLog("出错在函数trans3中");
- }
- return 0;
- }
- void CDBServerDlg::MyExecuteSQL(CDatabase* pdb, CString sql)
- {
- try
- {
- pdb->ExecuteSQL(sql);
- }
- catch ( CDBException *e)
- {
- WriteTextLog(_T("执行SQL语句出错,系统描述:%s"),e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- }
- void CDBServerDlg::MyExecuteSQL(const TCHAR* pfile, const int& nline, const TCHAR* pfunction, CDatabase* pdb, CString sql)
- {
- try
- {
- pdb->ExecuteSQL(sql);
- }
- catch ( CDBException *e)
- {
- WriteTextLog(_T("%s-<%d>-%s,执行SQL语句出错,系统描述:%s"), pfile, nline, pfunction,e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- }
- void CDBServerDlg::UpdateDate()
- {
- try
- {
- HWND hwnd = ::FindWindow(NULL, "AutoRun.exe - 应用程序错误");
- if (hwnd)
- {
- HWND child = ::FindWindowEx(hwnd, 0, NULL, "确定");
- CWnd *pWnd = CWnd::FromHandle(child);
- ::PostMessage(hwnd, WM_COMMAND, pWnd->GetDlgCtrlID(), (LPARAM)child);
- }
- CString autorunpath = g_mainpath + "\\AutoRun.exe";
- if (0 == g_bConvertHisAll)
- ShellExecute(NULL, _T("open"), g_mainpath + "\\AutoRun.exe", NULL, NULL, SW_HIDE);
- HANDLE hMutex = ::OpenMutex(NULL, FALSE, _T("lyfzSMSHandle"));
- if (GetLastError() == ERROR_FILE_NOT_FOUND)
- {
- autorunpath = g_mainpath + "\\SMSHandle.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- }
- if (hMutex) CloseHandle(hMutex);
- #ifdef ENTERPRISE_VERSION
- autorunpath = g_mainpath + "\\DataSyncReceive.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- autorunpath = g_mainpath + "\\DataSyncSend.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- autorunpath = g_mainpath + "\\CPhotoFTPReceive.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- autorunpath = g_mainpath + "\\CPhotoFTPSend.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- #endif
- }
- catch (...)
- {
- WriteTextLog("出错在函数UpdateDate中");
- }
- }
- BOOL CheckDateOK(CString str)
- {
- try
- {
- CString tip;
- int i;
- CString demo = CTime::GetCurrentTime().Format("%Y-%m-%d");
- if (str.GetLength() != demo.GetLength())
- goto ll;
- //2009-01-01
- if (str.GetAt(4) != '-')
- goto ll;
- if (str.GetAt(7) != '-')
- goto ll;
- for (i = 0; i < str.GetLength(); i++)
- {
- if (i == 4 || i == 7)continue;
- if (str.GetAt(i) < '0' || str.GetAt(i) > '9')
- goto ll;
- }
- }
- catch (...)
- {
- WriteTextLog("出错");
- }
- return 1;
- ll:
- return 0;
- }
- //------------------------------------------------------------------
- // Remark by Jeff:2014.10.11
- // 函数:DelPhoto1
- // 描述:删除指定路径下的订单文件夹;
- // 参数:
- // path: 指定要删除文件的根目录;
- // strOrderNumber: 将要删除的订单号文件夹;
- // 返回:
- //-----------------------------------------------------------------
- BOOL CDBServerDlg::DelPhoto1(CString path, CString strOrderNumber)
- {
- if ( path.IsEmpty() || !PathFileExists(path) )
- {
- //WriteTextLog(_T("路径不存在!"));
- return FALSE;
- }
- path += _T("\\") + strOrderNumber;
- if (PathFileExists(path))
- {
- DeleteDirectory(path);
- return TRUE;
- }
- //WriteTextLog(_T("路径不存在!"));
- return FALSE;
- }
- //-----------------------------------------------------------------------
- // Remark by Jeff 2014.10.22
- // 函数:BakPhoto
- // 描述:对影楼相片进行备份和删除取件相片
- // 参数:#
- // 返回:#
- //
- // 调用关系:
- // 1.BakPhoto()由CDBServerDlg::SetTimer(4) 调用,调用频率2分钟,周期数直到程序结束。
- // 2.CDBServerDlg::SetTimer(4) 由 CDBServerDlg::SetTimer(2) 调用,调用频率10毫秒,只有一个周期。
- // 3.CDBServerDlg::SetTimer(2) 由 CDBServerDlg::OnInitDialog() 调用.
- //-----------------------------------------------------------------------
- void CDBServerDlg::BakPhoto() // Jeff:备份相片/删除取件相片;
- {
- try
- {
- CDatabase *pMaindb = NULL;
- ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
- if ( pMaindb == NULL )
- return;
- CString m_bak1, m_bak2, m_bak3, m_bak4, m_bak6, m_baktime; // Jeff:m_bak6自动备份完毕后自动关机;
- CString m_bakserver1, m_bakserver2, m_bakserver3, m_bakserver4;
- CString msgcheck4, msgtime, msgphones, msgphones2, msgcompanyname;
- CString balance, msgaccount;
- {
- MyLock lock("dbaccessxiao");
- CRstversion rsSt;
- rsSt.m_pDatabase = pMaindb;
- rsSt.Open();
- if (!rsSt.IsEOF())
- {
- m_bak1 = rsSt.m_bak1;
- m_bak2 = rsSt.m_bak2;
- m_bak3 = rsSt.m_bak3;
- m_bak4 = rsSt.m_bak4;
- m_bakserver1 = rsSt.m_bakserver1;
- m_bakserver2 = rsSt.m_bakserver2;
- m_bakserver3 = rsSt.m_bakserver3;
- m_bakserver4 = rsSt.m_bakserver4;
- m_bak6 = rsSt.m_bak6;
- m_baktime = rsSt.m_baktime;
- msgcheck4 = rsSt.msgcheck4;
- msgtime = rsSt.msgtime;
- msgphones = rsSt.msgphones;
- msgphones2 = rsSt.msgphones2;
- msgcompanyname = rsSt.msgcompanyname;
- balance = rsSt.msgbalance;
- msgaccount = rsSt.msgaccount;
- }
- rsSt.Close();
- }
- /////////////检测发短信回财务
- if (msgphones2.IsEmpty() == 0)
- {
- MyLock lock("dbaccessxiao");
- CStringArray array, timearray;
- CString timestamp;
- timestamp = CTime::GetCurrentTime().Format("%Y-%m-%d");
- timestamp += "%";
- CRecordset myset(pMaindb);
- CString sql = "select phones,timestamp from sendregreceive where [timestamp] like '" + timestamp + "' and [content]='001' and [status]='OK'";
- myset.Open(CRecordset::forwardOnly, sql);
- CString phones;
- while (!myset.IsEOF())
- {
- myset.GetFieldValue("phones", phones);
- myset.GetFieldValue("timestamp", timestamp);
- if (msgphones2.Find(phones) != -1)
- {
- array.Add(phones);
- timearray.Add(timestamp);
- }
- myset.MoveNext();
- }
- myset.Close();
- if (array.GetSize())
- {
- CString sql;
- int i = 0;
- //for (int i = 0; i < array.GetSize(); i++)
- for ( i = 0; i < array.GetSize(); i++)
- {
- sql = "update sendregreceive set [status]='' where [timestamp]='" + timearray.ElementAt(i) + "'";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- CArray<CStringArray, CStringArray>List11array;
- CArray<CStringArray, CStringArray>List2array;
- CArray<CStringArray, CStringArray>List3array;
- CArray<CStringArray, CStringArray>other2salearray;
- CArray<CStringArray, CStringArray>memberarray;
- CString strdate = CTime::GetCurrentTime().Format("%Y-%m-%d");
- for( int a = g_dbpool.GetSize(); a >= 0 ;a-- )
- {
- CDatabase *pCurdb = NULL;
- ODBCConnGuard ConnGuard1(pCurdb , a - 1, 3000);
- if ( pCurdb == NULL )
- continue;
- CString filter = "[dat]='" + strdate + "'";
- filter = "[dat]='" + strdate + "' and ([sale2type] is null or [sale2type]='')";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from singleincome"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = List2array.GetSize();
- List2array.SetSize(oldsize + count, 1);
- CRstIncomeInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- int ii = 0;
- while (!rsSt.IsEOF())
- {
- List2array.ElementAt(oldsize + ii).RemoveAll();
- List2array.ElementAt(oldsize + ii).Add(rsSt.id);
- List2array.ElementAt(oldsize + ii).Add(rsSt.name);
- List2array.ElementAt(oldsize + ii).Add(rsSt.money);
- List2array.ElementAt(oldsize + ii).Add(rsSt.date);
- List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
- List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan2);
- List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan3);
- List2array.ElementAt(oldsize + ii).Add(rsSt.bz);
- List2array.ElementAt(oldsize + ii).Add(rsSt.sale2type);
- ii++;
- rsSt.MoveNext(); if (List2array.GetSize() <= ii)break;
- }
- rsSt.Close(); List2array.SetSize(oldsize + ii, 1);
- }
- filter = "[dat]='" + strdate + "'";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from gudingfeiyong"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = List3array.GetSize();
- List3array.SetSize(oldsize + count, 1);
- CRstPayOutInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- int ii = 0;
- while (!rsSt.IsEOF())
- {
- List3array.ElementAt(oldsize + ii).RemoveAll();
- List3array.ElementAt(oldsize + ii).Add(rsSt.id);
- List3array.ElementAt(oldsize + ii).Add(rsSt.name);
- List3array.ElementAt(oldsize + ii).Add(rsSt.money);
- List3array.ElementAt(oldsize + ii).Add(rsSt.date);
- List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
- List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan2);
- List3array.ElementAt(oldsize + ii).Add(rsSt.bz);
- ii++;
- rsSt.MoveNext(); if (List3array.GetSize() <= ii)break;
- }
- rsSt.Close(); List3array.SetSize(oldsize + ii, 1);
- }
- filter = "[date]='" + strdate + "'";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from dindanbukuan"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = List11array.GetSize();
- List11array.SetSize(oldsize + count, 1);
- CRstBuKuan rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- int ii = 0;
- while (!rsSt.IsEOF())
- {
- List11array.ElementAt(oldsize + ii).RemoveAll();
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_id);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_ren);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_money);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_bz);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_kind);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_date);
- ii++;
- rsSt.MoveNext(); if (List11array.GetSize() <= ii)break;
- }
- rsSt.Close(); List11array.SetSize(oldsize + ii, 1);
- }
- filter = "[date]='" + strdate + "'";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from singleincomemoneyview"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = other2salearray.GetSize();
- other2salearray.SetSize(oldsize + count, 1);
- CRstsingleincomemoneyview rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- int ii = 0;
- while (!rsSt.IsEOF())
- {
- other2salearray.ElementAt(oldsize + ii).RemoveAll();
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.name);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan3);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.sale2type);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.money);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.date);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.clerk);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.paytype);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.autoid);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.financecheck);
- ii++;
- rsSt.MoveNext(); if (other2salearray.GetSize() <= ii)break;
- }
- rsSt.Close(); other2salearray.SetSize(oldsize + ii, 1);
- }
- filter = "[date]='" + strdate + "'";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from memberview";
- if (!filter.IsEmpty())
- sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = memberarray.GetSize();
- memberarray.SetSize(oldsize + count, 1);
- memberviewReg rsSt;
- rsSt.m_pDatabase = pCurdb;
- if (!filter.IsEmpty())
- rsSt.m_strFilter = filter;
- rsSt.Open();
- DWORD ii = 0;
- while (!rsSt.IsEOF())
- {
- memberarray.ElementAt(oldsize + ii).RemoveAll();
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_id);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_memberno);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_name);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_money);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_date);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_clerk);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_financecheck);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_moneytype);
- ii++;
- rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break;
- }
- rsSt.Close(); memberarray.SetSize(oldsize + ii, 1);
- }
- }//
- CString str;
- int pos = 0;
- int dindanshu = 0;
- float income = 0;
- float incomedd = 0;
- float incomebk = 0;
- float incomehq = 0;
- float incomeqt = 0;
- float payout = 0;
- for (i = 0; i < List11array.GetSize(); i++)
- {
- str = List11array.ElementAt(i).ElementAt(2);
- income += atof(str);
- // income2+=atof(str);
- if (List11array.ElementAt(i).ElementAt(3) == "预约收款")
- {
- incomedd += atof(str);
- dindanshu++;
- }
- else if (List11array.ElementAt(i).ElementAt(3) == "预约补款")
- {
- incomebk += atof(str);
- }
- else
- {
- incomehq += atof(str);
- }
- pos++;
- }
- for (i = 0; i < List2array.GetSize(); i++)
- {
- str = List2array.ElementAt(i).ElementAt(2);
- income += atof(str);
- /* if(List2array.ElementAt (i).ElementAt (8)!="")
- {
- income2+=atof(str);
- }*/
- if (List2array.ElementAt(i).ElementAt(8) == "")
- {
- incomeqt += atof(str);
- }
- pos++;
- }
- for (i = 0; i < List3array.GetSize(); i++)
- {
- str = List3array.ElementAt(i).ElementAt(2);
- payout += atof(str);
- pos++;
- }
- for (i = 0; i < other2salearray.GetSize(); i++)
- {
- str = other2salearray.ElementAt(i).ElementAt(4);
- income += atof(str);
- incomehq += atof(str);
- pos++;
- }
- for (i = 0; i < memberarray.GetSize(); i++)
- {
- str = memberarray.ElementAt(i).ElementAt(3);
- income += atof(str);
- pos++;
- }
- CTime tm = CTime::GetCurrentTime();
- CString content = msgcompanyname + tm.Format("%Y-%m-%d");
- content += "财报:";
- str.Format("%d", (int)income);
- ::ConvertToPrice(str);
- content += "收:" + str;
- str.Format("%d", (int)incomedd);
- ::ConvertToPrice(str);
- content += "定:" + str;
- str.Format("%d", (int)incomebk);
- ::ConvertToPrice(str);
- content += "补:" + str;
- str.Format("%d", (int)incomehq);
- ::ConvertToPrice(str);
- content += "后:" + str;
- str.Format("%d", (int)incomeqt);
- ::ConvertToPrice(str);
- content += "其它:" + str;
- str.Format("%d", (int)payout);
- ::ConvertToPrice(str);
- content += "支出:" + str;
- str.Format("%d", (int)(income - payout));
- ::ConvertToPrice(str);
- content += "净收:" + str;
- str.Format("%d", dindanshu);
- content += "定单:" + str;
- if (msgaccount != "")
- {
- if (atoi(balance) < 200)
- {
- content += "您的余额小于两百条,请及时充值。联系电话4006067068";
- }
- else if (atoi(balance) < 500)
- {
- content += "您的余额小于五百条,请及时充值。联系电话4006067068";
- }
- else if (atoi(balance) < 800)
- {
- content += "您的余额小于八百条,请及时充值。联系电话4006067068";
- }
- else if (atoi(balance) < 1000)
- {
- content += "您的余额小于一千条,请及时充值。联系电话4006067068";
- }
- }
- int count = GetLengthEx(content) / MSG_LENGTH;
- if (GetLengthEx(content) % MSG_LENGTH)
- count++;
- int phonenum = 0;
- phonenum = 1;
- count *= phonenum;
- CString scount;
- scount.Format("%d", count);
- CString timestamp = tm.Format("%Y%m%d%H%M%S");
- for (i = 0; i < 1; i++)
- {
- sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + array.ElementAt(i) + "','" + content + "','" + timestamp + "','" + scount + "','0','0','0','系统自动发送')";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- }
- }
- /////////////
- if (atoi(msgcheck4) && msgphones != "")
- {//发老板短信
- if (atoi(msgtime) <= CTime::GetCurrentTime().GetHour())
- {
- MyLock lock("dbaccessxiao");
- CString timestamp;
- timestamp = CTime::GetCurrentTime().Format("%Y%m%d");
- timestamp += "%";
- CRecordset myset(pMaindb);
- CString sql = "select count(*) as cot from sendreg where [timestamp] like '" + timestamp + "' and [phones]='" + msgphones + "' and [isautosend]='3'";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- if (count == 0)
- {
- CArray<CStringArray, CStringArray>List11array;
- CArray<CStringArray, CStringArray>List2array;
- CArray<CStringArray, CStringArray>List3array;
- CArray<CStringArray, CStringArray>other2salearray;
- CArray<CStringArray, CStringArray>memberarray;
- CString strdate = CTime::GetCurrentTime().Format("%Y-%m-%d");
- for (int a = g_dbpool.GetSize() - 1; a >= 0; a--)
- {
- CDatabase *pCurdb = NULL;
- ODBCConnGuard ConnGuard(pCurdb , a - 1, 3000);
- if ( pCurdb == NULL )
- continue;
- CString filter = "[dat]='" + strdate + "'";
- filter = "[dat]='" + strdate + "' and ([sale2type] is null or [sale2type]='')";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from singleincome"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = List2array.GetSize();
- List2array.SetSize(oldsize + count, 1);
- CRstIncomeInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- int ii = 0;
- while (!rsSt.IsEOF())
- {
- List2array.ElementAt(oldsize + ii).RemoveAll();
- List2array.ElementAt(oldsize + ii).Add(rsSt.id);
- List2array.ElementAt(oldsize + ii).Add(rsSt.name);
- List2array.ElementAt(oldsize + ii).Add(rsSt.money);
- List2array.ElementAt(oldsize + ii).Add(rsSt.date);
- List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
- List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan2);
- List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan3);
- List2array.ElementAt(oldsize + ii).Add(rsSt.bz);
- List2array.ElementAt(oldsize + ii).Add(rsSt.sale2type);
- ii++;
- rsSt.MoveNext(); if (List2array.GetSize() <= ii)break;
- }
- rsSt.Close(); List2array.SetSize(oldsize + ii, 1);
- }
- filter = "[dat]='" + strdate + "'";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from gudingfeiyong"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = List3array.GetSize();
- List3array.SetSize(oldsize + count, 1);
- CRstPayOutInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- int ii = 0;
- while (!rsSt.IsEOF())
- {
- List3array.ElementAt(oldsize + ii).RemoveAll();
- List3array.ElementAt(oldsize + ii).Add(rsSt.id);
- List3array.ElementAt(oldsize + ii).Add(rsSt.name);
- List3array.ElementAt(oldsize + ii).Add(rsSt.money);
- List3array.ElementAt(oldsize + ii).Add(rsSt.date);
- List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
- List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan2);
- List3array.ElementAt(oldsize + ii).Add(rsSt.bz);
- ii++;
- rsSt.MoveNext(); if (List3array.GetSize() <= ii)break;
- }
- rsSt.Close(); List3array.SetSize(oldsize + ii, 1);
- }
- filter = "[date]='" + strdate + "'";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from dindanbukuan"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = List11array.GetSize();
- List11array.SetSize(oldsize + count, 1);
- CRstBuKuan rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- int ii = 0;
- while (!rsSt.IsEOF())
- {
- List11array.ElementAt(oldsize + ii).RemoveAll();
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_id);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_ren);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_money);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_bz);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_kind);
- List11array.ElementAt(oldsize + ii).Add(rsSt.m_date);
- List11array.ElementAt(oldsize + ii).Add(rsSt.paytype);
- ii++;
- rsSt.MoveNext(); if (List11array.GetSize() <= ii)break;
- }
- rsSt.Close(); List11array.SetSize(oldsize + ii, 1);
- }
- filter = "[date]='" + strdate + "'";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from singleincomemoneyview"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = other2salearray.GetSize();
- other2salearray.SetSize(oldsize + count, 1);
- CRstsingleincomemoneyview rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- int ii = 0;
- while (!rsSt.IsEOF())
- {
- other2salearray.ElementAt(oldsize + ii).RemoveAll();
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.name);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan1);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan3);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.sale2type);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.money);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.date);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.clerk);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.paytype);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.autoid);
- other2salearray.ElementAt(oldsize + ii).Add(rsSt.financecheck);
- ii++;
- rsSt.MoveNext(); if (other2salearray.GetSize() <= ii)break;
- }
- rsSt.Close(); other2salearray.SetSize(oldsize + ii, 1);
- }
- filter = "[date]='" + strdate + "'";
- {
- CRecordset myset(pCurdb);
- CString sql = "select count(*) as cot from memberview"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- int oldsize = memberarray.GetSize();
- memberarray.SetSize(oldsize + count, 1);
- memberviewReg rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- DWORD ii = 0;
- while (!rsSt.IsEOF())
- {
- memberarray.ElementAt(oldsize + ii).RemoveAll();
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_id);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_memberno);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_name);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_money);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_date);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_clerk);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_financecheck);
- memberarray.ElementAt(oldsize + ii).Add(rsSt.m_moneytype);
- ii++;
- rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break;
- }
- rsSt.Close(); memberarray.SetSize(oldsize + ii, 1);
- }
- }//
- CString str;
- int pos = 0;
- int dindanshu = 0;
- float income = 0;
- float incomedd = 0;
- float incomebk = 0;
- float incomehq = 0;
- float incomeqt = 0;
- float fStoredCardSpending = 0.0; // 储值卡扣款
- float payout = 0;
- int i = 0;
- for ( i = 0; i < List11array.GetSize(); i++)
- {
- str = List11array.ElementAt(i).ElementAt(2);
- income += atof(str);
- // income2+=atof(str);
- if (List11array.ElementAt(i).ElementAt(3) == "预约收款")
- {
- incomedd += atof(str);
- dindanshu++;
- }
- else if (List11array.ElementAt(i).ElementAt(3) == "预约补款")
- {
- incomebk += atof(str);
- }
- else
- {
- incomehq += atof(str);
- }
- #if JEFF_TEST_ON // 去除储值卡扣费;
- if (List11array.ElementAt(i).ElementAt(6) == "储值卡扣款" || List11array.ElementAt(i).ElementAt(6) == "代金券")
- {
- fStoredCardSpending += atof(str);
- }
- #endif
- pos++;
- }
- for (i = 0; i < List2array.GetSize(); i++)
- {
- str = List2array.ElementAt(i).ElementAt(2);
- income += atof(str);
- /* if(List2array.ElementAt (i).ElementAt (8)!="")
- {
- income2+=atof(str);
- }*/
- if (List2array.ElementAt(i).ElementAt(8) == "")
- {
- incomeqt += atof(str);
- }
- pos++;
- }
- for (i = 0; i < List3array.GetSize(); i++)
- {
- str = List3array.ElementAt(i).ElementAt(2);
- payout += atof(str);
- pos++;
- }
- for (i = 0; i < other2salearray.GetSize(); i++)
- {
- str = other2salearray.ElementAt(i).ElementAt(4);
- income += atof(str);
- incomehq += atof(str);
- pos++;
- }
- for (i = 0; i < memberarray.GetSize(); i++)
- {
- str = memberarray.ElementAt(i).ElementAt(3);
- income += atof(str);
- pos++;
- }
- CTime tm = CTime::GetCurrentTime();
- CString content = msgcompanyname + tm.Format("%Y-%m-%d");
- content += "财报:";
- income -= fStoredCardSpending;
- str.Format("%d", (int)(income)); // 去除储值卡扣款和代金券;
- ::ConvertToPrice(str);
- content += "收:" + str;
- str.Format("%d", (int)incomedd);
- ::ConvertToPrice(str);
- content += "定:" + str;
- str.Format("%d", (int)incomebk);
- ::ConvertToPrice(str);
- content += "补:" + str;
- str.Format("%d", (int)incomehq);
- ::ConvertToPrice(str);
- content += "后:" + str;
- str.Format("%d", (int)incomeqt);
- ::ConvertToPrice(str);
- content += "其它:" + str;
- str.Format("%d", (int)payout);
- ::ConvertToPrice(str);
- content += "支出:" + str;
- str.Format("%d", (int)(income - payout));
- ::ConvertToPrice(str);
- content += "净收:" + str;
- str.Format("%d", dindanshu);
- content += "定单:" + str;
- if (msgaccount != "")
- {
- if (atoi(balance) < 200)
- {
- content += "您的余额小于两百条,请及时充值。联系电话4006067068";
- }
- else if (atoi(balance) < 500)
- {
- content += "您的余额小于五百条,请及时充值。联系电话4006067068";
- }
- else if (atoi(balance) < 800)
- {
- content += "您的余额小于八百条,请及时充值。联系电话4006067068";
- }
- else if (atoi(balance) < 1000)
- {
- content += "您的余额小于一千条,请及时充值。联系电话4006067068";
- }
- }
- int count = GetLengthEx(content) / MSG_LENGTH;
- if (GetLengthEx(content) % MSG_LENGTH)
- count++;
- int phonenum = 0;
- str = msgphones;
- pos = str.Find(",");
- if (pos != -1)
- {
- while (pos != -1)
- {
- phonenum++;
- str = str.Right(str.GetLength() - pos - 1);
- pos = str.Find(",");
- }
- phonenum++;
- }
- else
- phonenum = 1;
- count *= phonenum;
- CString scount;
- scount.Format("%d", count);
- timestamp = tm.Format("%Y%m%d%H%M%S");
- sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + msgphones + "','" + content + "','" + timestamp + "','" + scount + "','0','0','3','系统自动发送')";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- }
- }
- BOOL bcheck1 = atoi(m_bak1);
- BOOL bcheck2 = atoi(m_bak2);
- BOOL bcheck3 = atoi(m_bak3);
- BOOL bcheck4 = atoi(m_bak4);
- }
- catch (CException *e)
- {
- TCHAR szError[1024] = { 0 };
- e->GetErrorMessage(szError, 1024);
- WriteTextLog(CString(szError));
- e->Delete();
- WriteTextLog("出错在函数bakphoto中");
- }
- }
- void CDBServerDlg::ShutDown() //Jeff:备份完毕后执行的关机函数;
- {
- try
- {
- // 结束检查服务线程
- TerminateCheckWork();
- CDatabase *pMaindb = NULL;
- ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
- if ( pMaindb == NULL )
- return;
- CString m_bak6;
- {
- CRecordset myset(pMaindb);
- CString sql = "select * from [version]";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("bak6", m_bak6);
- myset.Close();
- }
- OnServerStop(); // 停止服务;
- // Jeff.关闭数据库连接,若关机前关闭了数据库的连接,则客户端进行订单无法实现数据库的操作;
- // Jeff.在关机前,不能关闭数据库连接;
- for (int i = 0; i < g_dbHistoryArray.GetSize(); i++)
- {
- g_dbHistoryArray.ElementAt(i)->Close();
- delete g_dbHistoryArray.ElementAt(i);
- }
- ReleaseBranchDB();
- WriteTextLog("备份完成");
- ////////////////
- g_tisks = ::GetTickCount() - g_tisks;
- CString str;
- str.Format("耗时:%d分钟", g_tisks / 60000);
- CStdioFile fp;
- fp.Open(g_mainpath + "\\log.txt", CFile::modeCreate | CFile::modeWrite);
- CTime tm = CTime::GetCurrentTime();
- if (0)//tm.GetHour ()<5)
- {
- CTimeSpan sp(1, 0, 0, 0);
- tm -= sp;
- fp.WriteString(tm.Format("%Y-%m-%d"));
- fp.WriteString("\r\n");
- fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S"));
- fp.WriteString(str);
- }
- else
- {
- fp.WriteString(g_bakdate);
- fp.WriteString("\r\n");
- fp.WriteString(tm.Format("%Y-%m-%d %H:%M:%S"));
- fp.WriteString(str);
- }
- fp.WriteString("\r\n");
- fp.WriteString(g_bakinfo);
- fp.WriteString("\r\n");
- fp.WriteString(g_bakphoto);
- fp.Close();
- // OnButton3();
- // Jeff.备份完成后自动关机;
- if (atoi(m_bak6))
- {
- // Jeff.关闭运行中的线程;
- TerminateThread();
- // Jeff.关闭AutoRun.exe程序;
- DWORD id = FindAppProcessID("AutoRun.exe");
- if (id != -1)
- {
- HANDLE ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, id);
- if (ProcessHandle)TerminateProcess(ProcessHandle, 0);
- }
- // Jeff.移除托盘图标;
- m_TrayIcon.RemoveIcon();
- if (g_pSkinData)delete[]g_pSkinData; g_pSkinData = NULL;
- // Jeff.关闭计算机;
- MyExitWindows();
- }
- else//重启
- {
- TerminateThread();
- m_TrayIcon.RemoveIcon();
- if (g_pSkinData)
- delete[]g_pSkinData;
- g_pSkinData = NULL;
- WriteTextLog("备份完成,服务器重启");
- CDialog::OnCancel();
- }
- }
- catch (...)
- {
- WriteTextLog("出错在函数shutdown中");
- }
- }
- void CDBServerDlg::MyExitWindows()
- {
- try
- {
- UINT t = EWX_SHUTDOWN | EWX_FORCE;
- OSVERSIONINFO osv; //定义一个操作系统信息的结构体
- osv.dwOSVersionInfoSize = sizeof OSVERSIONINFO;
- GetVersionEx(&osv); //查询当前操作系统
- if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) //判断是否是2000/NT
- {
- //下面为向操作系统获取权限操作
- HANDLE hProcess, hToken;
- TOKEN_PRIVILEGES Privileges;
- LUID luid;
- hProcess = GetCurrentProcess();
- //下面为打开当前进程对话
- OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken);
- Privileges.PrivilegeCount = 1;
- LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &luid);
- Privileges.Privileges[0].Luid = luid;
- Privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
- AdjustTokenPrivileges(hToken, FALSE, &Privileges, NULL, NULL, NULL);
- ExitWindowsEx(t, 0);
- }
- else
- {
- ExitWindowsEx(t, 0);//调用ExitWindowsEx关闭机器。
- PostQuitMessage(0);
- }
- }
- catch (...)
- {
- WriteTextLog("出错在函数exitwindows中");
- }
- }
- void CDBServerDlg::OnAutorun()
- {
- // TODO: Add your command handler code here
- g_bAutoRun = !g_bAutoRun;
- CString version = _T("Version 1.0");
- AfxGetApp()->WriteProfileInt(version, "brun", g_bAutoRun);
- TCHAR szKey[MAX_PATH];
- HKEY hKey = 0;
- DWORD disp = 0;
- lstrcpy(szKey, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
- if (g_bAutoRun)
- {
- int lResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp);
- if (lResult == ERROR_SUCCESS)
- {
- TCHAR szDir[MAX_PATH];
- ::GetModuleFileName(NULL, szDir, MAX_PATH);
- lResult = RegSetValueEx(hKey, "YLGLDBSERVER", 0, REG_SZ, (const unsigned char*)szDir, lstrlen(szDir));
- RegCloseKey(hKey);
- }
- }
- else
- {
- int lResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp);
- if (lResult == ERROR_SUCCESS)
- {
- RegDeleteValue(hKey, "YLGLDBSERVER");
- RegDeleteKey(hKey, "YLGLDBSERVER");
- RegCloseKey(hKey);
- }
- }
- }
- void CDBServerDlg::GetFileDate()
- {
- CStringArray filesarray;
- CStringArray filesarray2;
- filesarray.Add("AutoUpdate.exe"); // 1.
- filesarray.Add("skin\\1.lia");
- filesarray.Add("skin\\2.lia");
- filesarray.Add("skin\\3.lia");
- filesarray.Add("skin\\4.lia");
- filesarray.Add("skin\\10.lia");
- filesarray.Add("skin\\logo.jpg");
- filesarray.Add("skin\\标题-选片.jpg");
- filesarray.Add("skin\\标题-看设计.jpg");
- filesarray.Add("图片\\欢迎.jpg"); // 10.
- filesarray.Add("图片\\连接.jpg");
- filesarray.Add("图片\\标题.jpg");
- filesarray.Add("图片\\背景.jpg");
- filesarray.Add("图片-红色风格\\欢迎.jpg");
- filesarray.Add("图片-红色风格\\连接.jpg");
- filesarray.Add("图片-红色风格\\标题.jpg");
- filesarray.Add("图片-红色风格\\背景.jpg");
- filesarray.Add("图片-红色风格\\选片.jpg");
- filesarray.Add("图片-红色风格\\看设计.jpg");
- filesarray.Add("skin\\1-red.lia"); // 20.
- filesarray.Add("skin\\2-red.lia");
- filesarray.Add("skin\\10-red.lia");
- filesarray.Add("skin\\6.lia");
- filesarray.Add("图片\\掌中宝.jpg");
- filesarray.Add("regsvr32.exe"); // 25.
- filesarray.Add("MSCHRT20.OCX"); // 26. // Jeff.2014.09.06.添加MSCHRT20.OCX,由服务器传递;
- ///////////////
- filesarray2.Add("AutoUpdate.exe");
- filesarray2.Add("skin\\1.lia");
- filesarray2.Add("skin\\2.lia");
- filesarray2.Add("skin\\3.lia");
- filesarray2.Add("skin\\4.lia");
- filesarray2.Add("skin\\5.lia");
- filesarray2.Add("skin\\10.lia");
- filesarray2.Add("skin\\5-red.lia");
- filesarray2.Add("skin\\10-red.lia");
- filesarray2.Add("图片\\logo.jpg");
- filesarray2.Add("图片\\标题-选片.jpg");
- filesarray2.Add("图片\\标题-看设计.jpg");
- filesarray2.Add("图片\\选片.jpg");
- filesarray2.Add("图片\\看设计.jpg");
- filesarray2.Add("图片\\欢迎.jpg");
- filesarray2.Add("图片\\连接.jpg");
- filesarray2.Add("图片\\标题.jpg");
- filesarray2.Add("图片\\背景.jpg");
- filesarray2.Add("图片-红色风格\\欢迎.jpg");
- filesarray2.Add("图片-红色风格\\连接.jpg");
- filesarray2.Add("图片-红色风格\\标题.jpg");
- filesarray2.Add("图片-红色风格\\背景.jpg");
- filesarray2.Add("skin\\6.lia");
- filesarray2.Add("图片\\掌中宝.jpg");
- filesarray2.Add("regsvr32.exe");
- filesarray2.Add("MSCHRT20.OCX"); // 26. // Jeff.2014.09.06.添加MSCHRT20.OCX,由服务器传递;
- int i = 0;
- //for (int i = 0; i < filesarray.GetSize(); i++)
- for ( i = 0; i < filesarray.GetSize(); i++)
- {
- g_filedatearray.Add(GetModifyTime(g_mainpath + "\\系统文件\\" + filesarray.ElementAt(i)));
- }
- g_filedatearraynew.Copy(filesarray2);
- for (i = 0; i < filesarray2.GetSize(); i++)
- {
- g_filedatearraynew.Add(GetFileSize(g_mainpath + "\\系统文件\\" + filesarray2.ElementAt(i)));
- }
- }
- //extern CString g_sdomain;
- #ifdef ENTERPRISE_VERSION
- CString g_bMain;
- #endif
- void CDBServerDlg::LoadBranchInfo()
- {
- #ifdef ENTERPRISE_VERSION
- try
- {
- ReleaseBranchDB();
- CArray<CStringArray, CStringArray>g_List1array;
- {
- MyLock lock("savebranchinfo");
- CFile fp;
- CString path = g_mainpath + "\\branchinfo.dat";
- if (::PathFileExists(path) == 0)
- return;
- fp.Open(path, CFile::modeRead);
- DWORD leng = fp.GetLength();
- if (leng < sizeof(DWORD) * 2)
- {
- fp.Close();
- return;
- }
- DWORD flag = 0;
- //fp.Seek(-sizeof(DWORD), CFile::end);
- fp.Seek(-(int)sizeof(DWORD), CFile::end);
- fp.Read(&flag, sizeof(DWORD));
- if (flag != 889900)
- {
- fp.Close();
- return;
- }
- fp.SeekToBegin();
- DWORD arraysize;
- fp.Read(&arraysize, sizeof(DWORD));
- if (arraysize > 20)
- {
- fp.Close();
- return;
- }
- BYTE *pData = new BYTE[leng - sizeof(DWORD)];
- fp.Read(pData, leng - sizeof(DWORD));
- fp.Close();
- CMemFile memfile;
- memfile.Attach(pData, leng - sizeof(DWORD));
- CArchive ar(&memfile, CArchive::load);
- g_List1array.SetSize(arraysize, 1);
- for (int ii = 0; ii < g_List1array.GetSize(); ii++)
- g_List1array.ElementAt(ii).Serialize(ar);
- ar.Close();
- memfile.Detach();
- delete[]pData;
- }
- if (g_List1array.GetSize() == 0)
- return;
- // SoftKey ytSoftKey;
- // if(ytSoftKey.Ini()==0)
- {
- int value[8];
- double f[8];
- 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("");
- //运行自定义函数
- int ret = ytSoftKey.getdata(&value[0], &value[1], &value[2], &value[3], &value[4], &value[5], &value[6], &value[7],
- &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
- s0, s1, s2, s3, s4, s5, s6, s7);
- if (ret != 0 && ret != -43)
- {
- g_sdomain = "";
- }
- else
- g_sdomain = s1;
- }
- CString str, str2, localname, rights;
- int i = 0;
- for (/*int*/ i = 0; i < g_List1array.GetSize(); i++)
- {
- if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0))
- {
- if (g_List1array.ElementAt(i).GetSize()>5)
- rights = g_List1array.ElementAt(i).ElementAt(5); break;
- }
- }
- for (i = 0; i < g_List1array.GetSize(); i++)
- {
- CString branchname = g_List1array.ElementAt(i).ElementAt(1);
- CString branchip = g_List1array.ElementAt(i).ElementAt(2);
- CString domain = g_List1array.ElementAt(i).ElementAt(0);
- CString dir = g_mainpath + "\\数据\\" + branchname;
- if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0))
- {
- localname = branchname;
- g_bMain = g_List1array.ElementAt(i).ElementAt(3);
- continue;
- }
- CString branchname2 = "," + branchname + ",";
- if (rights.Find(branchname2) == -1)
- continue;
- #ifdef SQLSERVER_VERSION
- if (1)//::PathFileExists (dir))
- {
- /////////////////////////
- g_branchdbarray.Add(NULL);
- g_branchnamearray.Add(branchname);
- g_branchdb2array.Add(NULL);
- g_branchname2array.Add(branchname);
- g_branchiparray.Add(branchip);
- g_branchdomainarray.Add(domain);
- // WriteTextLog(_T("添加分店:")+branchname);
- }
- #endif
- }
- //WriteTextLog(_T("添加本店:")+localname);
- g_branchdbarray.Add(NULL);
- g_branchnamearray.Add(localname);
- g_branchiparray.Add("xxx");
- g_branchdomainarray.Add(g_sdomain);
- }
- catch (...)
- {
- }
- #endif
- }
- void CDBServerDlg::ReleaseBranchDB()
- {
- #ifdef ENTERPRISE_VERSION
- try
- {
- for (int i = 0; i < g_branchdbarray.GetSize(); i++)
- {
- if (g_branchdbarray.ElementAt(i))
- {
- g_branchdbarray.ElementAt(i)->Close();
- delete g_branchdbarray.ElementAt(i);
- }
- }
- g_branchdbarray.RemoveAll();
- g_branchdb2array.RemoveAll();
- g_branchnamearray.RemoveAll();
- g_branchname2array.RemoveAll();
- g_branchiparray.RemoveAll();
- g_branchdomainarray.RemoveAll();
- }
- catch (...)
- {
- WriteTextLog("ReleaseBranchDB出错");
- }
- #endif
- }
- //savebranchinfo
- void CDBServerDlg::LoadBranchInfo2()
- {
- #ifdef ENTERPRISE_VERSION
- try
- {
- ReleaseBranchDB();
- CArray<CStringArray, CStringArray>g_List1array;
- {
- MyLock lock("savebranchinfo");
- CFile fp;
- CString path = g_mainpath + "\\branchinfo.dat";
- if (::PathFileExists(path) == 0)
- return;
- fp.Open(path, CFile::modeRead);
- DWORD leng = fp.GetLength();
- if (leng < sizeof(DWORD) * 2)
- {
- fp.Close(); return;
- }
- DWORD flag;
- //fp.Seek(-sizeof(DWORD), CFile::end);
- fp.Seek(-(int)sizeof(DWORD), CFile::end);
- fp.Read(&flag, sizeof(DWORD));
- if (flag != 889900)
- {
- fp.Close(); return;
- }
- fp.SeekToBegin();
- DWORD arraysize;
- fp.Read(&arraysize, sizeof(DWORD));
- if (arraysize > 20)
- {
- fp.Close();
- return;
- }
- BYTE *pData = new BYTE[leng - sizeof(DWORD)];
- fp.Read(pData, leng - sizeof(DWORD));
- fp.Close();
- CMemFile memfile;
- memfile.Attach(pData, leng - sizeof(DWORD));
- CArchive ar(&memfile, CArchive::load);
- g_List1array.SetSize(arraysize, 1);
- for (int ii = 0; ii < g_List1array.GetSize(); ii++)
- {
- g_List1array.ElementAt(ii).Serialize(ar);
- }
- ar.Close();
- memfile.Detach();
- delete[]pData;
- }
- if (g_List1array.GetSize() == 0)return;
- // SoftKey ytSoftKey;
- // if(ytSoftKey.Ini()==0)
- {
- int value[8];
- double f[8];
- 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("");
- //运行自定义函数
- int ret = ytSoftKey.getdata(&value[0], &value[1], &value[2], &value[3], &value[4], &value[5], &value[6], &value[7],
- &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
- s0, s1, s2, s3, s4, s5, s6, s7);
- if (ret != 0 && ret != -43)
- {
- g_sdomain = "";
- }
- else
- g_sdomain = s1;
- }
- CString str, str2, localname, rights;
- int i = 0;
- for (/*int*/ i = 0; i < g_List1array.GetSize(); i++)
- {
- if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0))
- {
- if (g_List1array.ElementAt(i).GetSize()>5)
- rights = g_List1array.ElementAt(i).ElementAt(5); break;
- }
- }
- for (i = 0; i < g_List1array.GetSize(); i++)
- {
- CString branchname = g_List1array.ElementAt(i).ElementAt(1);
- CString branchip = g_List1array.ElementAt(i).ElementAt(2);
- CString domain = g_List1array.ElementAt(i).ElementAt(0);
- CString dir = g_mainpath + "\\数据\\" + branchname;
- if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0))
- {
- localname = branchname;
- g_bMain = g_List1array.ElementAt(i).ElementAt(3);
- continue;
- }
- CString branchname2 = "," + branchname + ",";
- if (rights.Find(branchname2) == -1)
- continue;
- #ifdef SQLSERVER_VERSION
- if (1)//::PathFileExists (dir))
- {
- ////////////////////////
- g_branchdbarray.Add(NULL);
- g_branchnamearray.Add(branchname);
- g_branchdb2array.Add(NULL);
- g_branchname2array.Add(branchname);
- g_branchiparray.Add(branchip);
- g_branchdomainarray.Add(domain);
- }
- #endif
- }
- g_branchdbarray.Add(NULL);
- g_branchnamearray.Add(localname);
- g_branchiparray.Add("xxx");
- g_branchdomainarray.Add(g_sdomain);
- }
- catch (...)
- {
- }
- #endif
- }
- int __cdecl CompareByLabel6(const void *elem1, const void *elem2)
- {
- CStringArray *p1 = (CStringArray*)elem1;
- CStringArray *p2 = (CStringArray*)elem2;
- return atoi(p1->ElementAt(5)) > atoi(p2->ElementAt(5));
- }
- //--------------------------------------------------------------
- // Remark by Jeff 2014.12.16
- // 函数:CheckMemberMsg
- // 描述:
- // 参数:
- // 返回:
- //
- // 调用关系:
- // 1.CheckMemberMsg() 只由 CDBServerDlg::SetTimer(4) 调用,调用频率2分钟,周期数直到程序结束。
- // 2.CDBServerDlg::SetTimer(4) 由 CDBServerDlg::SetTimer(2) 调用,调用频率10毫秒,只有一个周期。
- // 3.CDBServerDlg::SetTimer(2) 由 CDBServerDlg::OnInitDialog() 调用.
- //--------------------------------------------------------------
- void CDBServerDlg::CheckMemberMsg() // Jeff.由定时器SetTimer两分钟执行一次
- {
- try
- {
- CDatabase *pMaindb = NULL;
- ODBCConnGuard ConnGuard( pMaindb, -1, 3000);
- if ( pMaindb == NULL )
- return;
- CString sql = "delete from sendreg where [log]='0/0'";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- {
- CStringArray idarray;
- CString timestamp;
- CTime tm = CTime::GetCurrentTime();
- tm -= CTimeSpan(0, 1, 0, 0);
- timestamp = tm.Format("%Y%m%d%H%M%S");
- CRecordset myset(pMaindb);
- CString sql = "select [autoid] from sendregdelay where [timestamp]<'" + timestamp + "'";
- myset.Open(CRecordset::forwardOnly, sql);
- while (!myset.IsEOF())
- {
- myset.GetFieldValue("autoid", sql);
- idarray.Add(sql);
- myset.MoveNext();
- }
- myset.Close();
- for (int i = 0; i < idarray.GetSize(); i++)
- {
- // Jeff.deal
- //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)));
- 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)));
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- sql.Format("delete from sendregdelay where [autoid]=%d", atol(idarray.ElementAt(i)));
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- }
- int covertrate = 100;
- CString spoint;
- {
- CRecordset myset(pMaindb);
- CString sql = "select * from version";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("rate2", sql);
- myset.Close();
- covertrate = atoi(sql);
- if (covertrate == 0)covertrate = 100;
- }
- CString filter;
- CArray<CStringArray, CStringArray>rulearray;
- CArray<CStringArray, CStringArray>memberarray;
- {
- CRecordset myset(pMaindb);
- CString sql = "select count(*) as cot from msgtemp2";
- if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- rulearray.SetSize(count, 1);
- CRstmsgtemp2 rsSt;
- rsSt.m_pDatabase = pMaindb;
- if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- DWORD ii = 0;
- while (!rsSt.IsEOF())
- {
- rulearray.ElementAt(ii).RemoveAll();
- rulearray.ElementAt(ii).Add(rsSt.name);
- rulearray.ElementAt(ii).Add(rsSt.content1);
- rulearray.ElementAt(ii).Add(rsSt.content2);
- rulearray.ElementAt(ii).Add(rsSt.check1);
- rulearray.ElementAt(ii).Add(rsSt.check2);
- rulearray.ElementAt(ii).Add(rsSt.point);
- ii++;
- rsSt.MoveNext();
- if (rulearray.GetSize() <= ii)break;
- }
- rsSt.Close(); rulearray.SetSize(ii, 1);
- }
- if (rulearray.GetSize() == 0)return;
- qsort(static_cast<void*>(&rulearray[0]), rulearray.GetSize(), sizeof(rulearray[0]), CompareByLabel6);
- /////////////
- {
- CRecordset myset(pMaindb);
- CString sql = "select count(*) as cot from membermanage"; if (!filter.IsEmpty())sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- memberarray.SetSize(atol(sql), 1);
- RstMemberReg rsSt;
- rsSt.m_pDatabase = pMaindb;
- if (!filter.IsEmpty())rsSt.m_strFilter = filter;
- rsSt.Open();
- DWORD ii = 0;
- if (covertrate != 100)
- {
- while (!rsSt.IsEOF())
- {
- memberarray.ElementAt(ii).RemoveAll();
- memberarray.ElementAt(ii).Add(rsSt.m_memberno);
- memberarray.ElementAt(ii).Add(rsSt.m_name);
- memberarray.ElementAt(ii).Add(rsSt.m_sex);
- memberarray.ElementAt(ii).Add(rsSt.m_phone);
- spoint.Format("%d", atoi(rsSt.m_money)*covertrate / 100);
- memberarray.ElementAt(ii).Add(spoint);
- memberarray.ElementAt(ii).Add(rsSt.m_sendmark1);
- memberarray.ElementAt(ii).Add(rsSt.m_sendmark2);
- ii++;
- rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break;
- }
- }
- else
- {
- while (!rsSt.IsEOF())
- {
- memberarray.ElementAt(ii).RemoveAll();
- memberarray.ElementAt(ii).Add(rsSt.m_memberno);
- memberarray.ElementAt(ii).Add(rsSt.m_name);
- memberarray.ElementAt(ii).Add(rsSt.m_sex);
- memberarray.ElementAt(ii).Add(rsSt.m_phone);
- memberarray.ElementAt(ii).Add(rsSt.m_money);
- memberarray.ElementAt(ii).Add(rsSt.m_sendmark1);
- memberarray.ElementAt(ii).Add(rsSt.m_sendmark2);
- ii++;
- rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break;
- }
- }
- rsSt.Close(); memberarray.SetSize(ii, 1);
- }
- CString memberno, name, sex, phone, point, mark1, mark2, rulename, rulecheck1, rulecheck2, rulepoint, rulecontent1, rulecontent2;
- for (int i = 0; i < memberarray.GetSize(); i++)
- {
- memberno = memberarray.ElementAt(i).ElementAt(0);
- name = memberarray.ElementAt(i).ElementAt(1);
- sex = memberarray.ElementAt(i).ElementAt(2);
- phone = memberarray.ElementAt(i).ElementAt(3);
- point = memberarray.ElementAt(i).ElementAt(4);
- mark1 = "," + memberarray.ElementAt(i).ElementAt(5) + ",";
- mark2 = "," + memberarray.ElementAt(i).ElementAt(6) + ",";
- if (atoi(point) == 0)continue;
- if (phone.IsEmpty())continue;
- if (-1 == CheckPhoneType(phone))continue;
- int j = 0;
- for (/*int*/ j = 0; j < rulearray.GetSize(); j++)
- {
- if (mark1.GetLength()>4000)break;
- rulename = "," + rulearray.ElementAt(j).ElementAt(0) + ",";
- rulecontent1 = name + rulearray.ElementAt(j).ElementAt(1);
- rulecontent2 = name + rulearray.ElementAt(j).ElementAt(2);
- rulecheck1 = rulearray.ElementAt(j).ElementAt(3);
- rulecheck2 = rulearray.ElementAt(j).ElementAt(4);
- rulepoint = rulearray.ElementAt(j).ElementAt(5);
- if (atoi(rulecheck1) == 0 && atoi(rulecheck2) == 0)continue;
- if (atoi(rulecheck1))
- {
- if (rulecontent1.IsEmpty())continue;
- if (mark1.Find(rulename) != -1)break;
- if (atoi(point) >= atoi(rulepoint))continue;
- if (atoi(point) < atoi(rulepoint) * 80 / 100)continue;
- // if(sex=="男")
- // rulecontent1.Replace ("xxx先生/女士", name+"先生");
- // else
- // rulecontent1.Replace ("xxx先生/女士", name+"女士");
- int count = GetLengthEx(rulecontent1) / MSG_LENGTH;
- if (GetLengthEx(rulecontent1) % MSG_LENGTH)
- count++;
- int phonenum = 1;
- count *= phonenum;
- CString scount;
- scount.Format("%d", count);
- CString timestamp = CTime::GetCurrentTime().Format("%Y%m%d%H%M%S");
- CString sql;
- mark1.TrimLeft(",");
- mark1.TrimRight(",");
- if (mark1.IsEmpty() == 0)
- mark1 += ",";
- rulename.TrimLeft(",");
- rulename.TrimRight(",");
- mark1 += rulename;
- sql = "update membermanage set sendmark1='" + mark1 + "' where memberno='" + memberno + "'";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- mark1 = "," + mark1 + ",";
- sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + phone + "','" + rulecontent1 + "','" + timestamp + "','" + scount + "','0','0','0','系统自动发送')";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- }
- ///////////////////
- BOOL bSended = 0;
- for (j = 0; j < rulearray.GetSize(); j++)
- {
- if (mark2.GetLength() > 4000)break;
- if (bSended)break;
- rulename = "," + rulearray.ElementAt(j).ElementAt(0) + ",";
- rulecontent1 = name + rulearray.ElementAt(j).ElementAt(1);
- rulecontent2 = name + rulearray.ElementAt(j).ElementAt(2);
- rulecheck1 = rulearray.ElementAt(j).ElementAt(3);
- rulecheck2 = rulearray.ElementAt(j).ElementAt(4);
- rulepoint = rulearray.ElementAt(j).ElementAt(5);
- if (atoi(rulecheck1) == 0 && atoi(rulecheck2) == 0)continue;
- if (atoi(rulecheck2))
- {
- if (rulecontent2.IsEmpty())continue;
- if (mark2.Find(rulename) != -1)break;
- if (atoi(point) < atoi(rulepoint))continue;
- // if(sex=="男")
- // rulecontent2.Replace ("xxx先生/女士", name+"先生");
- // else
- // rulecontent2.Replace ("xxx先生/女士", name+"女士");
- int count = GetLengthEx(rulecontent2) / MSG_LENGTH;
- if (GetLengthEx(rulecontent2) % MSG_LENGTH)
- count++;
- int phonenum = 1;
- count *= phonenum;
- CString scount;
- scount.Format("%d", count);
- CString timestamp = CTime::GetCurrentTime().Format("%Y%m%d%H%M%S");
- CString sql;
- mark2.TrimLeft(",");
- mark2.TrimRight(",");
- if (mark2.IsEmpty() == 0)
- mark2 += ",";
- rulename.TrimLeft(",");
- rulename.TrimRight(",");
- mark2 += rulename;
- sql = "update membermanage set sendmark2='" + mark2 + "' where memberno='" + memberno + "'";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- mark2 = "," + mark2 + ",";
- sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + phone + "','" + rulecontent2 + "','" + timestamp + "','" + scount + "','0','0','0','系统自动发送')";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- bSended = 1;
- }
- }
- }
- }
- catch (CDBException *e)
- {
- WriteTextLog(_T("%s-<%d>-%s,%s"), __FILE__, __LINE__, __FUNCTION__, e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- }
- void CDBServerDlg::CheckBakState() // Jeff.检查数据库bakstate表;
- {
- try
- {
- CDatabase* pMaindb = NULL;
- ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
- if ( pMaindb == NULL )
- return;
- CString filter = _T("");
- CArray<CStringArray, CStringArray> strArray;
- CRecordset myset(pMaindb);
- CString sql = "select count(*) as cot from bakstate";
- if (!filter.IsEmpty())
- sql += " where " + filter;
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- strArray.SetSize(count, 1);
- //备份记录
- CRstbakstate rsSt;
- rsSt.m_pDatabase = pMaindb;
- if (!filter.IsEmpty())
- rsSt.m_strFilter = filter;
- rsSt.Open();
- int ii = 0;
- while (!rsSt.IsEOF())
- {
- strArray.ElementAt(ii).RemoveAll();
- strArray.ElementAt(ii).Add(rsSt.date);
- strArray.ElementAt(ii).Add(rsSt.photo);
- strArray.ElementAt(ii).Add(rsSt.info);
- ii++;
- rsSt.MoveNext();
- if (strArray.GetSize() <= ii)
- break;
- }
- rsSt.Close();
- //只保存7天记录
- strArray.SetSize(ii, 1);
- while (strArray.GetSize() > 7)
- {
- CString sql = "delete from bakstate where [date]='" + strArray.ElementAt(0).ElementAt(0) + "'";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- strArray.RemoveAt(0);
- }
- CString path = _T("");
- path.Format("%s\\log.txt", g_mainpath);
- if (::PathFileExists(path))
- {
- CString str;
- CStdioFile fp;
- if (fp.Open(path, CFile::modeRead))
- {
- CString temp;
- fp.ReadString(temp);
- CString date = temp;
- date.TrimRight();
- while(!feof(fp.m_pStream))
- {
- fp.ReadString(temp);
- str += temp;
- }
- fp.Close();
- if (date.GetLength() != 10)
- return;
- BOOL bBak = 0;
- int i = 0;
- for (int i = 0; i < strArray.GetSize(); i++)
- {
- if (date == strArray.ElementAt(i).ElementAt(0))
- {
- bBak = 1;
- break;
- }
- }
- if (bBak == 0)
- {
- CString state1 = "0";
- CString state2 = "0";
- if (str.Find("照片备份成功") != -1)state1 = "1";
- if (str.Find("资料备份成功") != -1)state2 = "1";
- sql = "insert into bakstate([date],[photo],[info])values('" + date + "','" + state1 + "','" + state2 + "')";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- else
- {
- CString state1 = "0";
- CString state2 = "0";
- if (str.Find("照片备份成功") != -1)state1 = "1";
- if (str.Find("资料备份成功") != -1)state2 = "1";
- sql = "update bakstate set [photo]='" + state1 + "',[info]='" + state2 + "' where [date]='" + date + "'";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- //判断昨天
- CTime tm = CTime::GetCurrentTime();
- CTimeSpan dt(1, 0, 0, 0);
- tm -= dt;
- CString yesterday = tm.Format("%Y-%m-%d");
- for (i = 0; i < strArray.GetSize(); i++)
- {
- if (yesterday == strArray.ElementAt(i).ElementAt(0))return;
- }
- if (yesterday == date)return;
- sql = "insert into bakstate([date],[photo],[info])values('" + yesterday + "','0','0')";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- else
- {
- CTime tm = CTime::GetCurrentTime();
- CTimeSpan dt(1, 0, 0, 0);
- tm -= dt;
- sql = "insert into bakstate([date],[photo],[info])values('" + tm.Format("%Y-%m-%d") + "','0','0')";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- }
- else
- {
- //昨天没备份,插入一条没有备份的记录
- CTime tm = CTime::GetCurrentTime();
- CTimeSpan dt(1, 0, 0, 0);
- tm -= dt;
- for (int i = 0; i < strArray.GetSize(); i++)
- {
- if (tm.Format("%Y-%m-%d") == strArray.ElementAt(i).ElementAt(0))
- return;
- }
- sql = "insert into bakstate([date],[photo],[info])values('" + tm.Format("%Y-%m-%d") + "','0','0')";
- MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql);
- }
- }
- catch (...)
- {
- WriteTextLog("出错3");
- }
- }
- //数据备份
- CString CDBServerDlg::GetRegCode(int m_id, int m_time1, int m_time2)
- {
- TCHAR DevicePath[260];
- if (FindPort(0, DevicePath) != 0)
- return "";
- int version;
- GetIDVersion((DWORD*)&m_id, &version, DevicePath);
- int d[8]; double f[8];
- int idtemp = 123456;
- char s0[50] = "", s1[50] = "", s2[50] = "", s3[50] = "", s4[50] = "", s5[50] = "", s6[50] = "", s7[50] = "";
- //运行自定义函数
- // SoftKey ytSoftKey;
- int ret = 0;//ytSoftKey.Ini();
- if (ret != 0)
- {
- return "";
- }
- //////////////////////////////////////////////////////////////////////////
- // timedog1是对d0,d1,d2,d3进行3DES加密;
- // 对锁id加密;
- // 对123456加密;
- // 对m_time1可运行时间加密;
- // 对m_time2已运行时间加密;
- ret = ytSoftKey.timedog1(&m_id, &idtemp, &m_time1, &m_time2, &d[4], &d[5], &d[6], &d[7],
- &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
- s0, s1, s2, s3, s4, s5, s6, s7);
- if (ret != 0 && ret != -43)
- {
- return "";
- }
- CString str = "";
- CString temp, temp2;
- /////////////////////////////////////////
- temp.Format("%d", abs(m_id));
- int leng = temp.GetLength();
- if (m_id < 0)
- temp2 = "1";
- else
- temp2 = "0";
- temp = temp2 + temp;
- temp2.Format("%02d", leng);
- temp = temp2 + temp;
- str += temp;
- //////////////////////////////////两位长度, 1为负, 0为正, 数据区
- temp.Format("%d", abs(m_time1));
- leng = temp.GetLength();
- if (m_time1 < 0)
- temp2 = "1";
- else
- temp2 = "0";
- temp = temp2 + temp;
- temp2.Format("%02d", leng);
- temp = temp2 + temp;
- str += temp;
- //////////////////////////////////两位长度, 1为负, 0为正, 数据区
- temp.Format("%d", abs(m_time2));
- leng = temp.GetLength();
- if (m_time2 < 0)
- temp2 = "1";
- else
- temp2 = "0";
- temp = temp2 + temp;
- temp2.Format("%02d", leng);
- temp = temp2 + temp;
- str += temp;
- //////////////////////////////////两位长度, 1为负, 0为正, 数据区
- temp.Format("%d", abs(idtemp));
- leng = temp.GetLength();
- if (idtemp < 0)
- temp2 = "1";
- else
- temp2 = "0";
- temp = temp2 + temp;
- temp2.Format("%02d", leng);
- temp = temp2 + temp;
- str += temp;
- return str;
- }
- int g_ndogtimes = 0;
- void CDBServerDlg::CheckRegCode() // 检查注册码信息;
- {
- char path[MAX_PATH];
- ::GetSystemDirectory(path, MAX_PATH);
- CString sysdir = path;
- sysdir += "\\authcode.txt";
- CStdioFile fp;
- CString authcode;
- if (fp.Open(sysdir, CFile::modeRead))
- {
- fp.ReadString(authcode);
- fp.Close();
- }
- ::DeleteFile(sysdir); // 删除authcode.txt文件;
- authcode.TrimLeft();
- authcode.TrimRight();
- authcode.Replace("\n", "");
- authcode.Replace("\r", "");
- if (authcode.GetLength() != 240)
- {
- return;
- }
- TCHAR DevicePath[260];
- if (FindPort(0, DevicePath) != 0)
- return;
- DWORD OutID;
- int version;
- GetIDVersion(&OutID, &version, DevicePath);
- CString str1, str2, str3, str4, str5;
- str1 = authcode.Mid(0, 48);
- str2 = authcode.Mid(48, 48);
- str3 = authcode.Mid(96, 48);
- str4 = authcode.Mid(144, 48);
- str5 = authcode.Mid(192, 48);
- // SoftKey ytSoftKey;
- int ret = 0;//ytSoftKey.Ini();
- if (ret != 0)
- {
- return;
- }
- int d[8]; double f[8];
- char s0[50] = "", s1[50] = "", s2[50] = "", s3[50] = "", s4[50] = "", s5[50] = "", s6[50] = "", s7[50] = "";
- //运行自定义函数
- sprintf(s0, "%s", str1);
- sprintf(s1, "%s", str2);
- sprintf(s2, "%s", str3);
- sprintf(s3, "%s", str4);
- sprintf(s4, "%s", str5);
- //运行自定义函数
- ret = ytSoftKey.timedog2(&d[0], &d[1], &d[2], &d[3], &d[4], &d[5], &d[6], &d[7],
- &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
- s0, s1, s2, s3, s4, s5, s6, s7);
- if (ret != 0 && ret != -43)
- {
- return;
- }
- str1 = s0;
- str2 = s1;
- str3 = s2;
- str4 = s3;
- str5 = s4;
- authcode = str1;
- authcode += str2;
- authcode += str3;
- authcode += str4;
- authcode += str5;
- str1 += str2;
- str3 += str4;
- DWORD id = atoi(str5.Right(8));
- str5 = str5.Left(12);
- if (id != OutID)
- {
- return;
- }
- TCHAR HKey[50] = "ffffffff", LKey[50] = "ffffffff";
- TCHAR WHKey[41] = "0", WLKey[41] = "0";
- TCHAR year[10], month[10], day[10], hour[10], minute[10], second[10];
- sprintf(WHKey, "%s", str1);
- sprintf(WLKey, "%s", str3);
- CString temp;
- temp = str5.Left(4);
- str5 = str5.Right(8);
- sprintf(year, "%s", temp);
- temp = str5.Left(2);
- str5 = str5.Right(6);
- sprintf(month, "%s", temp);
- temp = str5.Left(2);
- str5 = str5.Right(4);
- sprintf(day, "%s", temp);
- temp = str5.Left(2);
- str5 = str5.Right(2);
- sprintf(hour, "%s", temp);
- sprintf(minute, "%s", str5);
- sprintf(second, "%s", "0");
- ret = WriteTimeAuthToEprom(30128, HKey, LKey, WHKey, WLKey, id, year, month, day, hour, minute, DevicePath);
- if (ret == 0)
- {
- TCHAR year2[10], month2[10], day2[10], hour2[10], minute2[10], second2[10];
- GetRunTimer(year2, month2, day2, hour2, minute2, second2, DevicePath);
- DWORD time1, time2;
- time1 = ConvertStringToTimerReal(year, month, day, hour, minute, second);
- sprintf(second2, "%s", "0");
- time2 = ConvertStringToTimerReal(year2, month2, day2, hour2, minute2, second2);
- if (time1 > time2)
- ConvertTimerToStringReal(time1 - time2, year, month, day, hour, minute, second);
- else
- {
- sprintf(year, "%s", "0");
- sprintf(month, "%s", "0");
- sprintf(day, "%s", "0");
- sprintf(hour, "%s", "0");
- sprintf(minute, "%s", "0");
- }
- g_ndogtimes++;
- // str1.Format ("写入%d次 %d 年 %d 月 %d 日 %d 小时 %d 分", g_ndogtimes, atoi(year), atoi(month), atoi(day), atoi(hour), atoi(minute));
- // WriteTextLog(str1);
- // AfxMessageBox((str1));
- }
- else
- {
- // AfxMessageBox(("授权申请码错误, 请重新向经销商索取!"));
- return;
- }
- }
- BOOL IsCtrlDown()
- {
- short state = GetKeyState(VK_LCONTROL);
- BYTE sta = (BYTE)(state >> 8);
- state = GetKeyState(VK_RCONTROL);
- BYTE sta2 = (BYTE)(state >> 8);
- if (sta || sta2)
- return 1;
- else
- return 0;
- }
- //extern CTime GetTmFromStr(CString date);
- BOOL CDBServerDlg::PreTranslateMessage(MSG* pMsg)
- {
- if (pMsg->message == WM_KEYDOWN)
- {
- switch (pMsg->wParam)
- {
- case 67:
- AfxMessageBox("c");
- break;
- case VK_F8:
- if (IsCtrlDown())GenYLGL();
- break;
- case VK_F9:
- if (IsCtrlDown())
- {
- CString g_domain;
- CArray<CStringArray, CStringArray>g_List1array;
- CString autorunpath = g_mainpath + "\\branchdindan.dat";
- CFile fp;
- if (fp.Open(autorunpath, CFile::modeRead))
- {
- int nMessageLen = fp.GetLength();
- BYTE *pData = new BYTE[nMessageLen];
- fp.Read(pData, nMessageLen);
- fp.Close();
- BYTE *szChatMessage = pData;
- int count;
- memcpy(&count, szChatMessage + (nMessageLen - sizeof(int)), sizeof(int));
- CMemFile memfile;
- memfile.Attach(szChatMessage, nMessageLen);
- CArchive ar(&memfile, CArchive::load);
- g_List1array.SetSize(count);
- for (int ii = 0; ii < g_List1array.GetSize(); ii++)
- {
- g_List1array.ElementAt(ii).Serialize(ar);
- }
- ar.Close();
- memfile.Detach();
- delete[]pData;
- }
- CString time5, id;
- for (int i = 0; i < g_List1array.GetSize(); i++)
- {
- g_domain = "\\" + g_List1array.ElementAt(i).ElementAt(0);
- id = g_List1array.ElementAt(i).ElementAt(1);
- time5 = g_List1array.ElementAt(i).ElementAt(2);
- WriteTextLog(g_domain + "\\" + id + time5);
- }
- }
- break;
- #ifdef LYFZ_VERSION
- case VK_F7:
- if (IsCtrlDown())
- {
- if (AfxMessageBox("是否继续?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return 1;
- CStringArray array1;
- CRstDindanForm rsSt; rsSt.m_pDatabase = &g_db;
- rsSt.Open();
- while (!rsSt.IsEOF())
- {
- array1.Add(rsSt.id);
- rsSt.MoveNext();
- }
- rsSt.Close();
- CString id, sql;
- sql.Format("update dindan set status5='%s'", "无");
- MyExecuteSQL(&g_db, sql);
- BOOL bHasPhoto = 0;
- for (int i = 0; i < array1.GetSize(); i++)
- {
- id = array1.ElementAt(i);
- bHasPhoto = 0;
- CRstClientPhoto rsSt;
- rsSt.m_strFilter = "id='" + id + "'";
- rsSt.Open();
- if (rsSt.photo.m_dwDataLength>0)
- {
- bHasPhoto = 1;
- }
- rsSt.Close();
- if (bHasPhoto)
- {
- sql.Format("update dindan set status5='%s' where id='%s'", "有", id);
- MyExecuteSQL(&g_db, sql);
- }
- }
- /* CStringArray array1,array2;
- CRstDindanForm rsSt; rsSt.m_pDatabase=&g_db;
- rsSt.Open();
- while(!rsSt.IsEOF())
- {
- array1.Add(rsSt.id) ;
- array2.Add(rsSt.time4) ;
- rsSt.MoveNext();
- }
- rsSt.Close();
- CString id,time4,time2,sql;
- for(int i=0; i<array1.GetSize(); i++)
- {
- id=array1.ElementAt(i);
- time4=array2.ElementAt(i);
- if(time4.GetLength()==10)
- {
- CTime tm=GetTmFromStr(time4);
- CTimeSpan dt(365, 0, 0, 0);
- CTime tm2=tm-dt;
- time2=tm2.Format("%Y-%m-%d");
- sql.Format("update dindan set time2='%s' where id='%s'", time2, id);
- MyExecuteSQL(&g_db, sql);
- }
- }*/
- AfxMessageBox("完成");
- }
- break;
- #endif //#ifdef LYFZ_VERSION
- case VK_F2:
- if (IsCtrlDown())
- {
- SelYear dlg;
- if (dlg.DoModal() != IDOK)return 1;
- int year = dlg.m_year;
- int hisyear = CTime::GetCurrentTime().GetYear() - 1;
- if (year == hisyear)
- {
- AfxMessageBox("不能选该年");
- return 1;
- }
- CString str;
- str.Format("此操作将%d年数据导入%d中, 确认吗?", year, hisyear);
- if (AfxMessageBox(str, MB_YESNO | MB_ICONINFORMATION) != IDYES)return 1;
- CDatabase *pdb = GetDB(year);
- if (pdb == NULL)
- {
- str.Format("没有找到%d, 操作失败", year);
- AfxMessageBox(str); return 1;
- }
- str.Format("开始%d->%d", year, hisyear);
- WriteTextLog(str);
- CheckHistoryData(pdb, year);
- str.Format("%d->%d完成", year, hisyear);
- WriteTextLog(str);
- }
- break;
- case VK_F3:
- if (IsCtrlDown())
- {
- SelYear dlg;
- if (dlg.DoModal() != IDOK)return 1;
- int year = dlg.m_year;
- int hisyear = CTime::GetCurrentTime().GetYear() - 1;
- if (year == hisyear)
- {
- AfxMessageBox("不能选该年");
- return 1;
- }
- CString str;
- str.Format("此操作将%d年数据导入%d中(当前数据库中没有的订单全转), 确认吗?", year, hisyear);
- if (AfxMessageBox(str, MB_YESNO | MB_ICONINFORMATION) != IDYES)return 1;
- CDatabase *pdb = GetDB(year);
- if (pdb == NULL)
- {
- str.Format("没有找到%d, 操作失败", year);
- AfxMessageBox(str); return 1;
- }
- str.Format("开始%d->%d", year, hisyear);
- WriteTextLog(str);
- CheckHistoryData(pdb, year, 1);
- str.Format("%d->%d完成", year, hisyear);
- WriteTextLog(str);
- }
- break;
- case VK_F1:
- CString str;
- if (g_conniparray.GetSize() == 0)str = "当前无客户端连接至服务器!";
- for (int i = 0; i < g_conniparray.GetSize(); i++)
- {
- str += "\r\n连接ip:" + g_conniparray.ElementAt(i);
- }
- AfxMessageBox(str);
- #ifdef CONNCOUNT_VERSION
- // CStringArray g_conniparray;
- #endif //#ifdef CONNCOUNT_VERSION
- return 1;
- }
- }
- return CDialog::PreTranslateMessage(pMsg);
- }
- void CDBServerDlg::GenUPhoneData()
- {
- MyLock lock("processChatMessageRequestxiao");
- CArray<int, int>codearray;
- codearray.Add(80);
- codearray.Add(90);
- codearray.Add(11);
- codearray.Add(138);
- codearray.Add(24);
- codearray.Add(181);
- codearray.Add(65);
- codearray.Add(56);
- codearray.Add(179);
- codearray.Add(53);
- CFile fp;
- CString savepath, g_path1;
- char server[50];
- DWORD leng = 50;
- ::GetComputerName(server, &leng);
- g_path1 = server;
- g_path1 = "\\\\" + g_path1 + "\\电话录音(管理软件)$";
- GetPathFromNetShareName("电话录音(管理软件)$", g_path1);
- if (g_path1.IsEmpty())
- {
- WriteTextLog("获取电精灵数据出错");
- return;
- }
- try
- {
- int aa = 0;
- CDatabase *pMaindb = NULL;
- ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
- if ( pMaindb == NULL )
- return;
- savepath.Format("%s\\uphonedata%d.dat", g_path1, aa);
- ::DeleteFile(savepath); // 删除 uphonedata%d.dat 文件;
- if (fp.Open(savepath, CFile::modeCreate | CFile::modeWrite) == 0)
- {
- WriteTextLog("更新来电精灵数据出错");
- return;
- }
- CConnectSocket consock;
- consock.m_pConndb = pMaindb;
- for (int i = 0; i < codearray.GetSize(); i++)
- {
- BYTE code = codearray.ElementAt(i);
- DWORD length, arraysize;
- BYTE *pReturn = NULL;
- consock.GetDataFromCode(code, &pReturn, length, arraysize, "");
- fp.Write(&code, sizeof(BYTE));
- fp.Write(&length, sizeof(DWORD));
- fp.Write(&arraysize, sizeof(DWORD));
- fp.Write(pReturn, length);
- }
- fp.Close();
- }
- catch (...)
- {
- WriteTextLog("获取来电精灵数据出错2");
- }
- }
- //initlia
- void CDBServerDlg::LoadHistoryDB() // 加载历史数据库;
- {
- CString path;
- CString sql;
- sql = "delete from historydb";
- CDatabase *pdb = NULL;
- ODBCConnGuard ConnGuard(pdb, -1, 3000);
- if ( pdb ) MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pdb, sql);
- CDatabase g_masterdb;
- try
- {
- CString strCon;
- strCon.Format(DB_SS_CONN_WITHOUT_PORT, g_strdbServrename, _T("master"), g_szDBAccount, g_szDBPassWord);
- g_masterdb.OpenEx(strCon, CDatabase::noOdbcDialog);
- }
- catch (CDBException * e)
- {
- #ifdef _DEBUG
- e->ReportError();
- #endif //#ifdef _DEBUG
- e->Delete();
- }
- TCHAR szdbName[MAX_PATH] = {0};
- for (int i = CTime::GetCurrentTime().GetYear() - 1; i >= 2009; i--)
- {
- #if USE_POOL
- _itot_s(i, szdbName, 10);
- CODBCPool *pdbpool = new CODBCPool;
- if ( pdbpool->InitializePool(g_szDBSource, g_dwDBServerPort, g_szDBAccount, g_szDBPassWord, szdbName, g_dwDBPoolDef, g_dwDBPoolMaxCount))
- {
- g_nYearArray.Add(i);
- sql.Format("insert into [historydb]([year])values('%d')", i);
- CDatabase *pdb = NULL;
- ODBCConnGuard ConnGuard(pdb, -1, 3000);
- if ( pdb )MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pdb, sql);
- g_dbpool.Add(pdbpool);
- }
- else
- {
- delete pdbpool;
- pdbpool = NULL;
- CString strPathOfYearmdf;
- CString strPathOfYearldf;
- CString sql;
- strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, i);
- strPathOfYearldf.Format("%s\\数据\\%d_log.LDF", g_mainpath, i);
- if (PathFileExists(strPathOfYearmdf))
- {
- BOOL bLog = 0;
- if (PathFileExists(strPathOfYearldf))
- {
- bLog = 1;
- }
- g_masterdb.SetQueryTimeout(600);
- if (bLog)
- sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", i, strPathOfYearmdf, strPathOfYearldf);
- else
- sql.Format("exec sp_attach_db '%d',@filename1='%s'", i, strPathOfYearmdf);
- try
- {
- g_masterdb.ExecuteSQL(sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog("历史数据库初始化失败,%s",e->m_strError);
- g_masterdb.SetQueryTimeout(100);
- #ifdef _DEBUG
- e->ReportError();
- #endif //#ifdef _DEBUG
- e->Delete();
- break;
- }
- g_masterdb.SetQueryTimeout(100);
- if ( pdbpool->InitializePool(g_szDBSource, g_dwDBServerPort, g_szDBAccount, g_szDBPassWord, szdbName, g_dwDBPoolDef, g_dwDBPoolMaxCount))
- {
- g_nYearArray.Add(i);
- sql.Format("insert into [historydb]([year])values('%d')", i);
- CDatabase *pdb = NULL;
- ODBCConnGuard ConnGuard(pdb, -1, 3000);
- if ( pdb )MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pdb, sql);
- g_dbpool.Add(pdbpool);
- }
- else
- {
- delete pdbpool;
- }
- }
- }
- #else
- CDatabase *db = new CDatabase;
- try
- {
- CString strCon;
- //strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=%d;%s"), g_strdbServrename, i, g_strdbpsw);
- if ( _tcscmp(g_szDBAccount, _T("")) == 0)
- strCon.Format(DB_SW_CONN_WITHOUT_PORT2, g_strdbServrename, i);
- else
- strCon.Format(DB_SS_CONN_WITHOUT_PORT2, g_strdbServrename, i, g_szDBAccount, g_szDBPassWord);
- db->OpenEx(strCon, CDatabase::noOdbcDialog);
- g_nYearArray.Add(i);
- g_dbHistoryArray.Add(db);
- sql.Format("insert into [historydb]([year])values('%d')", i);
- MyExecuteSQL(&g_db, sql);
- }
- catch (CDBException * e)
- {
- #ifdef _DEBUG
- e->ReportError();
- #endif //#ifdef _DEBUG
- CString strPathOfYearmdf;
- CString strPathOfYearldf;
- CString sql;
- strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, i);
- strPathOfYearldf.Format("%s\\数据\\%d_log.LDF", g_mainpath, i);
- if (PathFileExists(strPathOfYearmdf))
- {
- BOOL bLog = 0;
- if (PathFileExists(strPathOfYearldf))
- {
- bLog = 1;
- }
- g_masterdb.SetQueryTimeout(600);
- if (bLog)
- sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", i, strPathOfYearmdf, strPathOfYearldf);
- else
- sql.Format("exec sp_attach_db '%d',@filename1='%s'", i, strPathOfYearmdf);
- try
- {
- g_masterdb.ExecuteSQL(sql);
- }
- catch (CDBException * e)
- {
- WriteTextLog(e->m_strError);
- WriteTextLog("历史数据库初始化失败!!");
- g_masterdb.SetQueryTimeout(100);
- #ifdef _DEBUG
- e->ReportError();
- #endif //#ifdef _DEBUG
- e->Delete();
- break;
- }
- g_masterdb.SetQueryTimeout(100);
- CString strCon;
- //strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=%d;%s"), g_strdbServrename, i, g_strdbpsw);
- if ( _tcscmp(g_szDBAccount, _T("")) == 0)
- strCon.Format(DB_SW_CONN_WITHOUT_PORT2, g_strdbServrename, i);
- else
- strCon.Format(DB_SS_CONN_WITHOUT_PORT2, g_strdbServrename, i, g_szDBAccount, g_szDBPassWord);
- db->OpenEx(strCon, CDatabase::noOdbcDialog);
- g_nYearArray.Add(i);
- g_dbHistoryArray.Add(db);
- sql.Format("insert into [historydb]([year])values('%d')", i);
- MyExecuteSQL(&g_db, sql);
- }
- else
- {
- //e->ReportError();
- e->Delete();
- //break;
- }
- }
- #endif
- }
- g_masterdb.Close();
- }
- void CDBServerDlg::AddOneConn()
- {
- #if 0
- try
- {
- MyLock lock("AddOneConnxiao");
- if (g_nDBCount >= 200)
- {
- WriteTextLog("连接超数!"); return;
- }
- CDatabase *db = new CDatabase;
- //if(AddConn(db, "db")==0)// Jeff.deal;
- if (AddConn(db, g_szDBName) == 0)
- return;
- g_pDB[g_nDBCount] = db;
- CString dbname = _T("");
- for (int i = 0; i < g_nYearArray.GetSize(); i++)
- {
- dbname.Format("%d", g_nYearArray.ElementAt(i));
- CDatabase *db = new CDatabase;
- AddConn(db, dbname);
- g_pHistoryDBarray[g_nDBCount].Add(db);
- }
- AddAdoConn();
- g_nDBCount++;
- }
- catch (CException *e)
- {
- TCHAR szError[1024] = { 0 };
- e->GetErrorMessage(szError, 1024);
- WriteTextLog("AddOneConn error" + CString(szError));
- }
- #endif
- }
- /////////////////////////////////////////////////////////////////////////////////////
- /*
- 函数名: AddAdoConn
- 说明: 添加Logdb数据库连接
- 参数:
- 返回:
- */
- /////////////////////////////////////////////////////////////////////////////////////
- void CDBServerDlg::AddAdoConn()
- {
- }
- void GetOneConn(CDatabase **m_pdb, CArray<CDatabase*, CDatabase*>*m_dbarray, CConnectThread *pThread)
- {
- #if 0
- MyLock lock("GetOneConnxiao");
- ll: for (int i = 0; i < 200; i++)
- {
- if (g_pDB[i] != NULL && g_pThreadPt[i] == NULL)
- {
- *m_pdb = g_pDB[i];
- m_dbarray->Copy(g_pHistoryDBarray[i]);
- g_pThreadPt[i] = pThread;
- return;
- }
- }
- if (g_nDBCount >= 200)
- {
- WriteTextLog("连接超数2!");
- *m_pdb = &g_db;
- m_dbarray->Copy(g_dbHistoryArray);
- return;
- }
- g_pMainWnd->AddOneConn();
- ::Sleep(1000);
- goto ll;
- #endif
- }
- void CDBServerDlg::CheckConnCount()
- {
- int count = 0;
- for (int i = 0; i < 200; i++)
- {
- if (g_pDB[i] != NULL && g_pThreadPt[i] == NULL)
- {
- count++;
- if (count > 9)
- return;
- }
- }
- AddOneConn();
- }
- //delete from 背景.jpg
- void CDBServerDlg::RestoreHQ()
- {
- CString sql;
- CDatabase *pMaindb = NULL;
- ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
- if ( pMaindb == NULL )
- return;
- DWORD ii = 0;
- CArray<CStringArray, CStringArray>g_List1array;
- {
- CRecordset myset(pMaindb);
- CString sql = "select count(*) as cot from dindan";
- myset.Open(CRecordset::forwardOnly, sql);
- myset.GetFieldValue("cot", sql);
- myset.Close();
- int count = atol(sql);
- g_List1array.SetSize(count, 1);
- CRstDindanForm rsSt;
- rsSt.m_pDatabase = pMaindb;
- rsSt.Open();
- ii = 0;
- while (!rsSt.IsEOF())
- {
- g_List1array.ElementAt(ii).RemoveAll();
- g_List1array.ElementAt(ii).Add(rsSt.id);
- ii++;
- rsSt.MoveNext(); if (g_List1array.GetSize() <= ii)break;
- }
- rsSt.Close(); g_List1array.SetSize(ii, 1);
- }
- for (int i = 0; i < g_List1array.GetSize(); i++)
- {
- // int ret=TransDinDan(pdb1, pdb2, g_List1array.ElementAt (i).ElementAt (0), lastyear);
- // Jeff.deal;
- //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));
- 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));
- CRecordset myset(pMaindb);
- myset.Open(CRecordset::forwardOnly, sql);
- CStringArray namearray;
- CStringArray countarray;
- while (!myset.IsEOF())
- {
- sql = "";
- myset.GetFieldValue("name", sql);
- namearray.Add(sql);
- sql = "";
- myset.GetFieldValue("count", sql);
- countarray.Add(sql);
- myset.MoveNext();
- }
- myset.Close();
- for (int j = 0; j < namearray.GetSize(); j++)
- {
- CString spid, spjiage2;
- // WriteTextLog("name:"+namearray.ElementAt (j));
- // Jeff.deal;
- //sql.Format("SELECT [spid],[spjiage2] FROM [db].[dbo].[shangpin] where spname='%s'", namearray.ElementAt (j));
- sql.Format("SELECT [spid],[spjiage2] FROM [dbo].[shangpin] where spname='%s'", namearray.ElementAt(j));
- //WriteTextLog(sql);
- CRecordset myset(pMaindb);
- myset.Open(CRecordset::forwardOnly, sql);
- if (!myset.IsEOF())
- {
- myset.GetFieldValue("spid", spid);
- myset.GetFieldValue("spjiage2", spjiage2);
- }
- myset.Close();
- // Jeff.deal;
- //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));
- 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));
- myset.Open(CRecordset::forwardOnly, sql);
- sql = "";
- if (!myset.IsEOF())
- {
- myset.GetFieldValue("cot", sql);
- }
- myset.Close();
- if (atoi(sql))continue;
- sql.Format("insert into [dindansp]([id],[name],[shuliang],[price],[spid],[kind])values('%s','%s','%s','%s','%s','%s')",
- g_List1array.ElementAt(i).ElementAt(0), namearray.ElementAt(j), countarray.ElementAt(j), spjiage2, spid, "2");
- //WriteTextLog(sql);
- pMaindb->ExecuteSQL(sql);
- }
- }
- }
- void CDBServerDlg::ManagePhoto()
- {
- // CClientCenter dlg1;
- // dlg1.DoModal ();
- ShowPic3 dlg;
- dlg.DoModal();
- }
- //数据备份(管理软件)$
- //10.lia
- //----------------------------------------------------------------------------
- // Remark by Jeff 2014.10.22
- // 函数:GenYLGL
- // 描述:调用本地客户端;
- // 参数:#
- // 返回:#
- //
- // 调用关系:
- // 1.只由AutoDelPhoto()主动调用。
- //
- // 说明:传递genbranchdata给客户端,使客户端能够自动遍历branchinfo.dat里的分店信息,
- // 客户端顺序连接所有分店并获取分店历史订单已完成取件的订单。最终将所有分店历史
- // 订单已完成取件的送回服务端,保存在branchdindan2.dat中.
- //----------------------------------------------------------------------------
- void CDBServerDlg::GenYLGL()
- {
- // 1.Jeff.删除文件,g_mainpath服务器DBServer.exe的目录;
- CString autorunpath = g_mainpath + "\\YLGL.exe";
- ::DeleteFile(autorunpath); // 删除YLGL.exe
- WriteTextLog("命令行启动:" + autorunpath);
- // 2.重新生成YLGL.exe
- CDatabase *pdb = NULL;
- ODBCConnGuard ConnGuard(pdb, -1, 3000);
- if ( pdb = NULL )
- return;
- CRstUpdate rsSt;
- rsSt.m_pDatabase = pdb;
- rsSt.Open();
- if (!rsSt.IsEOF())
- {
- CFile fp;
- if (fp.Open(autorunpath, CFile::modeCreate | CFile::modeWrite))
- {
- void *pData = GlobalLock(rsSt.data.m_hData);
- fp.Write(pData, rsSt.data.m_dwDataLength);
- fp.Close();
- GlobalUnlock(rsSt.data.m_hData);
- }
- }
- rsSt.Close();
- // 3.执行YLGL.exe
- ShellExecute(NULL, _T("open"), autorunpath, "genbranchdata", NULL, SW_HIDE);
- }
- //105
- /************************************************************************/
- /*
- 函数:CheckSvcWork
- 描述:检查服务工作
- 参数:
- LPVOID LPARAM
- 返回:
- */
- /************************************************************************/
- unsigned int CDBServerDlg::CheckSvcWork(LPVOID LPARAM)
- {
- CDBServerDlg* p = (CDBServerDlg*)LPARAM;
- if(p != NULL)
- {
- while(1)
- {
- // 每小时检查一次
- int nRet = WaitForSingleObject(p->m_hWaitTimeOut, 60*60*1000);
- if(nRet != WAIT_OBJECT_0 && nRet != WAIT_TIMEOUT)
- {
- WriteTextLog(_T("检测服务3错误:%d\n"), GetLastError());
- break;
- }
- if(WaitForSingleObject(p->m_hExitCheckSvc, 0) == WAIT_OBJECT_0)
- break;
- CString strPath = _T("");
- DWORD dwID = 0;
- // 自动备份
- dwID = FindAppProcessID(_T("lyfzBackupSvc.exe"));
- if(dwID == 0)
- {
- strPath = g_mainpath + _T("\\lyfzBackupSvc.exe");
- CString strCmd = _T("/startsvc");
- SHELLEXECUTEINFO execinfo;
- memset(&execinfo, 0, sizeof(execinfo));
- execinfo.lpFile = strPath;
- execinfo.cbSize = sizeof(execinfo);
- execinfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
- execinfo.nShow = SW_HIDE;
- execinfo.lpParameters = strCmd;
- if(!ShellExecuteEx(&execinfo))
- {
- CString strError = _T("");
- strError.Format(_T("检测服务1错误:%d\n"), GetLastError());
- OutputDebugString(strError);
- }
- // WaitForSingleObject(execinfo.hProcess,INFINITE);
- }
- // 自动删除
- dwID = FindAppProcessID(_T("lyfzDeletePhotoSvc.exe"));
- if(dwID == 0)
- {
- strPath = g_mainpath + _T("\\lyfzDeletePhotoSvc.exe");
- CString strCmd = _T("/startsvc");
- SHELLEXECUTEINFO execinfo;
- memset(&execinfo, 0, sizeof(execinfo));
- execinfo.lpFile = strPath;
- execinfo.cbSize = sizeof(execinfo);
- execinfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
- execinfo.nShow = SW_HIDE;
- execinfo.lpParameters = strCmd;
- if(!ShellExecuteEx(&execinfo))
- {
- WriteTextLog(_T("检测服务2错误:%d\n"), GetLastError());
- }
- // WaitForSingleObject(execinfo.hProcess,INFINITE);
- }
- }
- }
- _endthreadex(0);
- return 0;
- }
- // 结束检查工作
- void CDBServerDlg::TerminateCheckWork()
- {
- if(m_hExitCheckSvc)
- SetEvent(m_hExitCheckSvc);
- if(m_hWaitTimeOut)
- SetEvent(m_hWaitTimeOut);
- if(m_hCheckSvcThread)
- {
- WaitForSingleObject(m_hCheckSvcThread, INFINITE);
- CloseHandle(m_hCheckSvcThread);
- }
- m_hCheckSvcThread = NULL;
- if(m_hExitCheckSvc)
- CloseHandle(m_hExitCheckSvc);
- m_hExitCheckSvc = NULL;
- if(m_hWaitTimeOut)
- CloseHandle(m_hWaitTimeOut);
- m_hWaitTimeOut = NULL;
- m_bStartCheckSvc = FALSE;
- }
- /************************************************************************/
- /*
- 函数:OnStartBackupSvc
- 描述:启动备份服务
- 参数:
- 返回:
- */
- /************************************************************************/
- void CDBServerDlg::OnStartBackupSvc()
- {
- StartSvc(_T("lyfzBackupSvc.exe"));
- }
- /************************************************************************/
- /*
- 函数:OnStopBackupSvc
- 描述:停止备份服务
- 参数:
- 返回:
- */
- /************************************************************************/
- void CDBServerDlg::OnStopBackupSvc()
- {
- StopSvc(_T("lyfz Backup Service"));
- }
- /************************************************************************/
- /*
- 函数:OnStartDelPhotoSvc
- 描述:启动删除服务
- 参数:
- 返回:
- */
- /************************************************************************/
- void CDBServerDlg::OnStartDelPhotoSvc()
- {
- StartSvc(_T("lyfzDeletePhotoSvc.exe"));
- }
- /************************************************************************/
- /*
- 函数:OnStopDelPhotoSvc
- 描述:停止删除服务
- 参数:
- 返回:
- */
- /************************************************************************/
- void CDBServerDlg::OnStopDelPhotoSvc()
- {
- StopSvc(_T("lyfz Delete Photo Service"));
- }
- /************************************************************************/
- /*
- 函数:StartSvc
- 描述:启动服务
- 参数:
- IN LPCSTR lpExeFile 程序名称
- 返回:1成功,0失败
- */
- /************************************************************************/
- int CDBServerDlg::StartSvc( IN LPCSTR lpExeFile)
- {
- CString strPath = _T("");
- DWORD dwID = 0;
- // 自动备份
- dwID = FindAppProcessID(lpExeFile);
- if(dwID == 0)
- {
- strPath = g_mainpath + _T("\\");
- strPath += lpExeFile;
- CString strCmd = _T("/startsvc");
- SHELLEXECUTEINFO execinfo;
- memset(&execinfo, 0, sizeof(execinfo));
- execinfo.lpFile = strPath;
- execinfo.cbSize = sizeof(execinfo);
- execinfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
- execinfo.nShow = SW_HIDE;
- execinfo.lpParameters = strCmd;
- if(!ShellExecuteEx(&execinfo))
- {
- CString strError = _T("");
- strError.Format(_T("检测服务%s错误:%d\n"), lpExeFile, GetLastError());
- OutputDebugString(strError);
- }
- }
- return 1;
- }
- // 停止服务
- /************************************************************************/
- /*
- 函数:OnStopDelPhotoSvc
- 描述:停止删除服务
- 参数:
- IN LPCSTR lpSvcName 服务名
- 返回:1成功,0失败
- */
- /************************************************************************/
- int CDBServerDlg::StopSvc(IN LPCSTR lpSvcName)
- {
- CString strError = _T("");
- SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
- if (hSCM == NULL)
- return 0;
- SC_HANDLE hService = ::OpenService(hSCM, lpSvcName, SERVICE_STOP | SERVICE_QUERY_STATUS);
- if (hService == NULL)
- {
- strError.Format(_T("打开%s服务失败:%d"), lpSvcName, GetLastError());
- OutputDebugString(strError);
- ::CloseServiceHandle(hSCM);
- return 0;
- }
- SERVICE_STATUS status;
- if(!::QueryServiceStatus(hService, &status))
- {
- strError.Format(_T("获取%s服务状态失败:%d"), lpSvcName, GetLastError());
- OutputDebugString(strError);
- ::CloseServiceHandle(hService);
- ::CloseServiceHandle(hSCM);
- return 0;
- }
- if(status.dwCurrentState == SERVICE_STOPPED)
- {
- ::CloseServiceHandle(hService);
- ::CloseServiceHandle(hSCM);
- return 1;
- }
- ControlService(hService, SERVICE_CONTROL_STOP, &status);
- DWORD dwStartTime = GetTickCount();
- DWORD dwTimeout = 30*1000; // 30-second time-out
- while(1)
- {
- Sleep( status.dwWaitHint );
- if(!::QueryServiceStatus(hService, &status))
- {
- strError.Format(_T("获取%s服务状态失败:%d"), lpSvcName, GetLastError());
- OutputDebugString(strError);
- ::CloseServiceHandle(hService);
- ::CloseServiceHandle(hSCM);
- return 0;
- }
- if ( status.dwCurrentState == SERVICE_STOPPED )
- break;
- if ( GetTickCount() - dwStartTime > dwTimeout )
- {
- strError.Format(_T("停止%s服务超时:%d"), lpSvcName, GetLastError());
- OutputDebugString(strError);
- ::CloseServiceHandle(hService);
- ::CloseServiceHandle(hSCM);
- return 0;
- }
- }
- ::CloseServiceHandle(hService);
- ::CloseServiceHandle(hSCM);
- return 1;
- }
- void CDBServerDlg::OnAutoCheckSvc()
- {
- g_bAutoCheckSvc = !g_bAutoCheckSvc;
- CHAR szFile[MAX_PATH + 1] = "";
- wsprintf(szFile, "%s\\ServiceInfo.ini", g_ModulePath);
- OFSTRUCT ofStruct;
- OpenFile(szFile, &ofStruct, OF_EXIST);
- if (ERROR_FILE_NOT_FOUND == GetLastError())
- return;
- CString strValue = _T("");
- strValue.Format(_T("%d"), g_bAutoCheckSvc);
- WritePrivateProfileString(_T("Back"), _T("AutoCheckSvc"), strValue, szFile);
- if(!g_bAutoCheckSvc)
- {
- TerminateCheckWork();
- }
- else
- {
- // 如果没启动自动检查
- if(!m_bStartCheckSvc)
- {
- m_hExitCheckSvc = CreateEvent(NULL, FALSE, FALSE, NULL);
- m_hWaitTimeOut = CreateEvent(NULL, FALSE, FALSE, NULL);
- SetEvent(m_hWaitTimeOut);
- unsigned int nThreadID = 0;
- m_bStartCheckSvc = TRUE;
- m_hCheckSvcThread = (HANDLE)_beginthreadex(NULL, 0, CheckSvcWork, this, 0, &nThreadID);
- }
- }
- }
|