Global.cpp 126 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070
  1. // Global.cpp : 应用程序的全局变量、函数源文件
  2. //
  3. // 代码生成在 2014年9月25日, 09:55
  4. #include "StdAfx.h"
  5. #include "Global.h"
  6. #include <io.h> // _access_s头文件;
  7. #include <stdio.h>
  8. #include "afxcoll.h"
  9. #include "afxtempl.h"
  10. #include "atlconv.h"
  11. #include "..\\lzari.h"
  12. #include "..\helper\ffsco.h"
  13. #include <WinSock2.h>
  14. #include "..\BasicExcelVC6.h"
  15. using namespace YExcel;
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. //#include <WS2tcpip.h>
  22. //////////////////////////////////////////////////////////////////////////
  23. static const int BEGIN_YEAR = 1901;
  24. static const int NUMBER_YEAR = 199;
  25. static const unsigned int LUNAR_YEARS[199] =
  26. {
  27. 0x04AE53, 0x0A5748, 0x5526BD, 0x0D2650, 0x0D9544, 0x46AAB9, 0x056A4D, 0x09AD42, 0x24AEB6, 0x04AE4A, //1901-1910
  28. 0x6A4DBE, 0x0A4D52, 0x0D2546, 0x5D52BA, 0x0B544E, 0x0D6A43, 0x296D37, 0x095B4B, 0x749BC1, 0x049754, //1911-1920
  29. 0x0A4B48, 0x5B25BC, 0x06A550, 0x06D445, 0x4ADAB8, 0x02B64D, 0x095742, 0x2497B7, 0x04974A, 0x664B3E, //1921-1930
  30. 0x0D4A51, 0x0EA546, 0x56D4BA, 0x05AD4E, 0x02B644, 0x393738, 0x092E4B, 0x7C96BF, 0x0C9553, 0x0D4A48, //1931-1940
  31. 0x6DA53B, 0x0B554F, 0x056A45, 0x4AADB9, 0x025D4D, 0x092D42, 0x2C95B6, 0x0A954A, 0x7B4ABD, 0x06CA51, //1941-1950
  32. 0x0B5546, 0x555ABB, 0x04DA4E, 0x0A5B43, 0x352BB8, 0x052B4C, 0x8A953F, 0x0E9552, 0x06AA48, 0x7AD53C, //1951-1960
  33. 0x0AB54F, 0x04B645, 0x4A5739, 0x0A574D, 0x052642, 0x3E9335, 0x0D9549, 0x75AABE, 0x056A51, 0x096D46, //1961-1970
  34. 0x54AEBB, 0x04AD4F, 0x0A4D43, 0x4D26B7, 0x0D254B, 0x8D52BF, 0x0B5452, 0x0B6A47, 0x696D3C, 0x095B50, //1971-1980
  35. 0x049B45, 0x4A4BB9, 0x0A4B4D, 0xAB25C2, 0x06A554, 0x06D449, 0x6ADA3D, 0x0AB651, 0x093746, 0x5497BB, //1981-1990
  36. 0x04974F, 0x064B44, 0x36A537, 0x0EA54A, 0x86B2BF, 0x05AC53, 0x0AB647, 0x5936BC, 0x092E50, 0x0C9645, //1991-2000
  37. 0x4D4AB8, 0x0D4A4C, 0x0DA541, 0x25AAB6, 0x056A49, 0x7AADBD, 0x025D52, 0x092D47, 0x5C95BA, 0x0A954E, //2001-2010
  38. 0x0B4A43, 0x4B5537, 0x0AD54A, 0x955ABF, 0x04BA53, 0x0A5B48, 0x652BBC, 0x052B50, 0x0A9345, 0x474AB9, //2011-2020
  39. 0x06AA4C, 0x0AD541, 0x24DAB6, 0x04B64A, 0x69573D, 0x0A4E51, 0x0D2646, 0x5E933A, 0x0D534D, 0x05AA43, //2021-2030
  40. 0x36B537, 0x096D4B, 0xB4AEBF, 0x04AD53, 0x0A4D48, 0x6D25BC, 0x0D254F, 0x0D5244, 0x5DAA38, 0x0B5A4C, //2031-2040
  41. 0x056D41, 0x24ADB6, 0x049B4A, 0x7A4BBE, 0x0A4B51, 0x0AA546, 0x5B52BA, 0x06D24E, 0x0ADA42, 0x355B37, //2041-2050
  42. 0x09374B, 0x8497C1, 0x049753, 0x064B48, 0x66A53C, 0x0EA54F, 0x06B244, 0x4AB638, 0x0AAE4C, 0x092E42, //2051-2060
  43. 0x3C9735, 0x0C9649, 0x7D4ABD, 0x0D4A51, 0x0DA545, 0x55AABA, 0x056A4E, 0x0A6D43, 0x452EB7, 0x052D4B, //2061-2070
  44. 0x8A95BF, 0x0A9553, 0x0B4A47, 0x6B553B, 0x0AD54F, 0x055A45, 0x4A5D38, 0x0A5B4C, 0x052B42, 0x3A93B6, //2071-2080
  45. 0x069349, 0x7729BD, 0x06AA51, 0x0AD546, 0x54DABA, 0x04B64E, 0x0A5743, 0x452738, 0x0D264A, 0x8E933E, //2081-2090
  46. 0x0D5252, 0x0DAA47, 0x66B53B, 0x056D4F, 0x04AE45, 0x4A4EB9, 0x0A4D4C, 0x0D1541, 0x2D92B5 //2091-2099
  47. };
  48. //////////////////////////////////////////////////////////////////////////
  49. // 异地选片 [4/1/2015 lyfz]
  50. //////////////////////////////////////////////////////////////////////////
  51. BOOL g_bRemote = FALSE;
  52. //////////////////////////////////////////////////////////////////////////
  53. HMODULE g_hlyfzMicroShareDLL = NULL;
  54. lyfzCreateShare g_lyfzCreateShare = NULL;
  55. // 升级包版本号;
  56. WORD g_arrFileVersion[4] = { 0 };
  57. TCHAR g_szLoginUser[MAX_PATH] = _T(""); // 当前软件的登陆用户名;
  58. TCHAR g_szLoginPsw[MAX_PATH] = _T(""); // 当前软件的登陆密码;
  59. TCHAR g_szModulePath[MAX_PATH] = _T(""); // 软件目录;
  60. TCHAR g_szModuleFileName[MAX_PATH] = _T(""); // 软件全名称;
  61. TCHAR g_szConnectString[MAX_PATH] = _T(""); // DB连接串;
  62. // 主机信息;
  63. TCHAR g_szHostComputerIP[MAX_PATH] = _T(""); // 服务端主机名称;
  64. DWORD g_dwCSPort = 5678; // 服务端主机通信TCP端口;
  65. TCHAR g_szN8ViewUserDir[MAX_PATH] = {0}; // N8选版服务器用户目录(共享目录);
  66. TCHAR g_szN8ViewStsDir[MAX_PATH] = {0}; // N8选版服务器统计数据目录(共享目录);
  67. TCHAR g_szN8ViewProductDir[MAX_PATH] = {0}; // N8选版产品配置目录(共享目录);
  68. DWORD g_dwSoftRunTime = 0; // 软件剩余可运行时间;
  69. // 数据库信息;
  70. TCHAR g_szDBSource[MAX_PATH] = _T(""); // 数据库源(服务所在IP或计算机名);
  71. TCHAR g_szDBSourcePort[MAX_PATH] = _T(""); // 数据库源端口;
  72. DWORD g_dwDBServerPort = 0; // 数据库源端口;
  73. TCHAR g_szDBAccount[MAX_PATH] = _T(""); // 数据库登录用户;
  74. TCHAR g_szDBPassWord[MAX_PATH] = _T(""); // 数据库登录密码;
  75. TCHAR g_szDBName[MAX_PATH] = _T(""); // 数据库名称;
  76. // 相片存储目录;
  77. TCHAR g_szShareHost[MAX_PATH] = _T(""); // 共享主机名;
  78. TCHAR g_szOriginalFolder[MAX_PATH] = _T(""); // 原片目录;
  79. TCHAR g_szOriginalBkFolder[MAX_PATH] = _T(""); // 原片备份目录;
  80. TCHAR g_szEarlyRepairFolder[MAX_PATH] = _T(""); // 初修片目录;
  81. TCHAR g_szEarlyRepairBkFolder[MAX_PATH] = _T(""); // 初修片备份目录;
  82. TCHAR g_szFurtherRepairFolder[MAX_PATH] = _T(""); // 精修片目录;
  83. TCHAR g_szFurtherRepairBkFolder[MAX_PATH] = _T(""); // 精修片备份目录;
  84. TCHAR g_szDesignFolder[MAX_PATH] = _T(""); // 设计片目录;
  85. TCHAR g_szDesignBkFolder[MAX_PATH] = _T(""); // 设计片备份目录;
  86. TCHAR g_szTelRecordingFolder[MAX_PATH] = _T(""); // 电话录音目录;
  87. TCHAR g_szFullDressImageFolder[MAX_PATH] = _T(""); // 礼服图片目录;
  88. TCHAR g_strCPUID[MAX_PATH] = _T(""); //获取CPU ID
  89. TCHAR g_strMacAddr[MAX_PATH] = _T(""); //mac地址
  90. TCHAR g_strHDNum[MAX_PATH] = _T(""); //硬盘ID
  91. TCHAR g_strBIOSNum[MAX_PATH] = _T(""); //主板ID
  92. BOOL g_bRunOnCorruptdb = FALSE; // 在损坏的数据库上运行;
  93. // 软件所用加密狗是否已注册; // Jeff,应该放在SoftKey做为静态变量使用;
  94. BOOL g_bSoftWareReg = FALSE;
  95. // 加密狗中的字符信息S1:如 201409062003558789.ly.com
  96. // 该全局变量在旧软件名称是:g_sdomain;
  97. // 该变量在数据库表字段[path].[path1]中存储;
  98. CString g_strDogMainInfo = "";
  99. // 未知用途;
  100. // 该全局变量在旧软件中名称是:CString g_bMain;
  101. // 与集团版有关联性;
  102. // 有可能是主店名称;
  103. CString g_strMain = "";
  104. // 分店名称数组;旧软件中名称:g_branchnamearray
  105. CStringArray g_strArrayOfBranchName;
  106. // ??
  107. CStringArray g_strArrayOfBranchName2;
  108. // 分店IP地址数组;
  109. CStringArray g_strArrayOfBranchIPAdress;
  110. // 分店的加密狗S1信息数组;
  111. CStringArray g_strArrayOfBranchDogMainInfo;
  112. // 座席版允许连接数(从加密狗中获取);
  113. unsigned int g_nCountOfAllowToConn = 0;
  114. #ifdef USE_KERNEL_DLL
  115. // 本店设置信息;用于集团版连接时,回访本店信息时用;
  116. TblVersion g_ThisShopVersion;
  117. HINSTANCE g_Instance = NULL;
  118. #endif
  119. DWORD g_nLeng = 0;
  120. BYTE *g_pData = NULL;
  121. DWORD g_nLeng2 = 0;
  122. BYTE *g_pData2 = NULL;
  123. SENDHEAD g_sendhead;
  124. BOOL g_bRedSkin = 0;
  125. COLORREF g_gridcol1 = RGB(204, 204, 204);
  126. COLORREF g_gridcol2 = RGB(190, 190, 190);
  127. COLORREF g_bkcol = RGB(184, 184, 184);
  128. CBrush g_dlgBrush;
  129. CString g_date;
  130. CString g_title;
  131. CArray<CStringArray, CStringArray>g_userarray;
  132. CArray<CStringArray, CStringArray>g_cominfoarray;
  133. CArray<CStringArray, CStringArray>g_cominfoarraylocal;
  134. CArray<DWORD, DWORD>g_lengarray;
  135. CArray<DWORD, DWORD>g_btnlengarray;
  136. CArray<BYTE*, BYTE*>g_pointerarray;
  137. CBrush g_editbkbrush;
  138. DWORD g_btnleng[8];
  139. int g_btnlengpos = -1;
  140. int g_nYearpos = -1;
  141. CString g_branchname = ""; // Jeff.集团版:????本分店名称;
  142. CString g_branchip = "";
  143. CString g_branchip2 = "";
  144. BOOL g_bBranchModify = 0;
  145. BOOL g_bShowOK = 0; // 取件OK的订单;
  146. BOOL g_bStaffAchievementShow = 0; // 此机用于员工业绩查看;
  147. BOOL g_bSaveUploadTask1 = 0;
  148. BOOL g_bSaveUploadTask2 = 0;
  149. BOOL g_bSaveUploadTask3 = 0;
  150. BOOL g_bSaveUploadTask4 = 0;
  151. BOOL g_bSearchFilter = 0;
  152. CString g_waiter1;
  153. CString g_waiter2;
  154. CString g_waiter3;
  155. CString g_waiter4;
  156. CString g_waiter5;
  157. CString g_filterdate1;
  158. CString g_filterdate2;
  159. CString g_filterdate3;
  160. CString g_filterdate4;
  161. CString g_filterdate5;
  162. CString g_filterdate6;
  163. CString g_filterbranch;
  164. USER g_user;
  165. CString g_mainpath; // 软件目录
  166. CString g_id; //
  167. CString g_server; // 服务端地址
  168. CStringArray g_serverarray; //
  169. CString g_serverbak; //
  170. CString g_path1; /* 共享目录 <客户原片(管理软件)$> 如:"\\lyfz-pc\客户原片(管理软件)$" */
  171. CString g_path2; /* 共享目录 <修好的片(管理软件)$> 如:"\\lyfz-pc\修好的片(管理软件)$" */
  172. CString g_path3; /* 共享目录 <设计好的片(管理软件$)> 如:""> */
  173. CString g_path4; /* 共享目录 <精修好的片(管理软件$)> 如:""> */
  174. CString g_path5; /* 共享目录 <礼服图片(管理软件$)> 如:""> */
  175. CString g_path6; /* 共享目录 <电话录音(管理软件$)> 如:""> */
  176. CString g_path7; /* 共享目录 <客户原片(管理软件$)\效果图> 如:""> */
  177. CString g_path1bak;
  178. CString g_path2bak;
  179. CString g_path3bak;
  180. CString g_path4bak;
  181. CString g_path5bak;
  182. CString g_path6bak;
  183. CString g_path7bak;
  184. CDatabase g_db;
  185. DWORD g_ncount;
  186. CFont g_titlefont;
  187. DWORD g_nSendCode = 0;
  188. BOOL g_bSendOK = 0;
  189. CString g_temp;
  190. CArray<CStringArray, CStringArray>g_hisyeararray;
  191. CArray<CStringArray, CStringArray>g_brancharray;
  192. CArray<CStringArray, CStringArray>g_oldclientarray;
  193. BOOL g_bNoConnDlg = 0;
  194. BOOL g_bInSkin = 0;
  195. BOOL g_bGenBranchData = 0;
  196. BOOL g_bSortAscending = FALSE;
  197. CFont g_listctrlfont;
  198. float g_fscalex; // x坐标刻度
  199. float g_fscaley; // y坐标刻度
  200. int g_screenwid; // 桌面宽
  201. int g_screenhei; // 桌面高
  202. float g_WidthScale2 = 1;
  203. float g_HeightScale2 = 1;
  204. RESDATA2 g_resdata2;
  205. BOOL g_bAlphaWnd = 0;
  206. BYTE g_bNeedDrawParent = 0;
  207. BOOL g_bAllBranch = 0;
  208. CString g_domain;
  209. CString g_sInfo;
  210. int g_ncot = 0; // Jeff:订单总数(包含历史订单在内),该变量作用是当订单总数大于1000时,向公司服务器发送数据;
  211. int g_conpos = 0;
  212. int g_nAutoShowStaffAchievement = -1;
  213. BOOL g_bShowBar = 1;
  214. int g_bookingtype = 0;
  215. BOOL g_bNoLoginLia = 0;
  216. BOOL g_bConnLYFZ = 0;
  217. BOOL g_bSendLYFZ = 0;
  218. int g_ntimeout = 29000;
  219. float g_WidthScale;
  220. float g_HeightScale;
  221. int g_dx = 0;
  222. int g_dy = 0;
  223. BOOL g_bNeedCoon = 1; // remark by Jeff:是否需要重新连接服务端;
  224. CStringArray g_menubranchname;
  225. CArray<CStringArray, CStringArray>g_List1array;
  226. #if USE_SHARE_FLORD
  227. CArray<CStringArray, CStringArray> g_aryOfSharePathInfo; // NetShareInfo表记录;
  228. #endif
  229. /************************************************************************/
  230. /*
  231. Jeff:g_conntype
  232. g_conntype == 0 :表示正常连接?(或是连接本地服务器?)
  233. g_conntype == 1 :表示连接公司服务器(http://lijiafz.vicp.net)
  234. g_conntype == 2 :http://www.lyfz.net/download/ip.txt
  235. g_conntype == 3 :http://photo.bjlyfz.com/download/ip.txt
  236. g_conntype == 4 :
  237. */
  238. /************************************************************************/
  239. int g_conntype = 0; // 正常;
  240. // 使用系统数字命名;
  241. BOOL g_bOriginal = FALSE;
  242. // 客户端guid值;
  243. TCHAR g_szGuidMark[64] = {0};
  244. // 控制台输出;
  245. BOOL g_bStdOut = FALSE;
  246. // N8安装路径;
  247. TCHAR g_szN8Path[MAX_PATH] = _T("");
  248. // HostInfo.ini的路径;
  249. TCHAR g_szIniPath[MAX_PATH] = _T("");
  250. // N8选版服务器IP地址;
  251. TCHAR g_szN8SvIP[MAX_PATH] = _T("");
  252. // 是否启用云选功能;
  253. BOOL g_bEnableClound = FALSE;
  254. // 是否导出条形码位图;
  255. BOOL g_bExportBarCode = FALSE;
  256. // 侧边栏抽屉数量;
  257. INT g_nDrawerCount = 12;
  258. //0 正常
  259. //1 连接1
  260. //2 连接2
  261. //3 连接3
  262. //4 连接4
  263. //************************************//
  264. // 数据库地址;
  265. // 数据库端口;
  266. // 数据库管理员账号;
  267. // 数据库管理员密码;
  268. // 数据库名称;
  269. //
  270. // [函数]:GetIniInfo
  271. // [描述]:获取指定ini信息;
  272. // [参数]:
  273. // szPath:ini所在目录;
  274. // szIniName:ini名;
  275. // [返回]:void
  276. //************************************//
  277. int GetSysIniInfo(const char *szPath, const char *szIniName)
  278. {
  279. TCHAR szDrive[_MAX_DRIVE] = { 0 };
  280. TCHAR szDir[_MAX_DIR] = { 0 };
  281. TCHAR szFna[_MAX_DIR] = { 0 };
  282. TCHAR szExt[_MAX_DIR] = { 0 };
  283. ::GetModuleFileName(NULL, g_szModuleFileName, sizeof(g_szModuleFileName) / sizeof(TCHAR));
  284. #if defined(VC80) || defined(VC70) || defined(VC60)
  285. sprintf(g_szModulePath, _T("%s"), g_szModuleFileName);
  286. _tsplitpath(g_szModulePath, szDrive, szDir, szFna, szExt);
  287. _tcscpy(g_szModulePath, szDrive);
  288. _tcscat(g_szModulePath, szDir);
  289. #else
  290. _stprintf_s(g_szModulePath, MAX_PATH, _T("%s"), g_szModuleFileName);
  291. _tsplitpath_s(g_szModulePath, szDrive, _MAX_DRIVE, szDir, _MAX_DIR, szFna, _MAX_DIR, szExt, _MAX_DIR);
  292. _tcscpy_s(g_szModulePath, MAX_PATH, szDrive);
  293. _tcscat_s(g_szModulePath, MAX_PATH, szDir);
  294. #endif
  295. // -----------------------------------------------------//
  296. if (szPath != NULL && szIniName != NULL)
  297. {
  298. if ( szPath[strlen(szPath) -1] == '\\' )
  299. wsprintf(g_szIniPath, _T("%s%s"), szPath, szIniName);
  300. else
  301. wsprintf(g_szIniPath, _T("%s\\%s"), szPath, szIniName);
  302. if ( !PathFileExists(g_szIniPath) )
  303. {
  304. wsprintf(g_szIniPath, _T("%sHostInfo.ini"), g_szModulePath);
  305. }
  306. }
  307. else
  308. {
  309. wsprintf(g_szIniPath, _T("%sHostInfo.ini"), g_szModulePath);
  310. }
  311. printf("szFile =%s\n", g_szIniPath);
  312. HANDLE hFile = CreateFile(g_szIniPath, 0/*GENERIC_READ*/, 0, NULL, OPEN_EXISTING, 0, NULL);
  313. if (ERROR_FILE_NOT_FOUND == GetLastError())
  314. {
  315. printf("没有找到配置文件[%s]\n", g_szIniPath);
  316. // 不存在则创建;
  317. CFile fp;
  318. if( fp.Open(g_szIniPath,CFile::modeCreate|CFile::modeWrite) )
  319. {
  320. fp.Close();
  321. }
  322. WritePrivateProfileString(_T("NetWorkInfo"),_T("Host"),_T("127.0.0.1"),g_szIniPath);
  323. WritePrivateProfileString(_T("NetWorkInfo"),_T("CSPort"),_T("5678"),g_szIniPath);
  324. return -1;
  325. }
  326. CloseHandle(hFile);
  327. hFile = NULL;
  328. // 获取服务器端TCP信息;
  329. GetPrivateProfileString(_T("NetWorkInfo"), _T("Host"), _T(""), g_szHostComputerIP, MAX_PATH, g_szIniPath);
  330. // N8选版程序路径;
  331. GetPrivateProfileString(_T("NemoInfo"), _T("N8Path"), _T(""), g_szN8Path, MAX_PATH, g_szIniPath);
  332. // N8选版服务器IP;
  333. //GetPrivateProfileString(_T("NemoInfo"), _T("N8SvIP"), _T(""), g_szN8SvIP, MAX_PATH, g_szIniPath);
  334. g_dwCSPort = GetPrivateProfileInt(_T("NetWorkInfo"), _T("CSPort"), 0, g_szIniPath);
  335. g_ntimeout = GetPrivateProfileInt(_T("NetWorkInfo"), _T("TimeOut"), 30000, g_szIniPath);
  336. g_bRunOnCorruptdb = GetPrivateProfileInt(_T("SystemInfo"), _T("RunOnCorruptdb"), 0, g_szIniPath);
  337. if ( !g_bStdOut )
  338. {
  339. g_bStdOut = GetPrivateProfileInt(_T("NetWorkInfo"), _T("StdOut"), 0, g_szIniPath);
  340. if ( g_bStdOut )
  341. {
  342. AllocConsole(); // 开辟控制台;
  343. SetConsoleTitle(_T("lyfz调试输出")); // 设置控制台窗口标题;
  344. freopen("CONOUT$", "w+t", stdout); // 重定向输出;
  345. freopen("CONIN$", "r+t", stdin); // 重定向输入;
  346. HWND hWnd = NULL;
  347. again:
  348. hWnd = ::FindWindow(NULL, _T("lyfz调试输出"));
  349. if( hWnd )
  350. {
  351. if (!::SetWindowPos(hWnd, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE))
  352. {
  353. printf(_T("前置设置失败\n"));
  354. }
  355. else
  356. {
  357. printf(_T("前置设置成功\n"));
  358. }
  359. }
  360. else
  361. {
  362. goto again;
  363. }
  364. }
  365. }
  366. return 0;
  367. }
  368. //----------------------------------------------------------
  369. // 函数:IsFileExist
  370. // 描述:判断某文件是否存在;
  371. // 参数:
  372. // pFileFullName: 指定的文件名;
  373. // 返回:TRUE表示文件存在;
  374. //----------------------------------------------------------
  375. BOOL IsFileExist(const TCHAR *pFileFullName)
  376. {
  377. int err = 0;
  378. // Check for existence.
  379. if ((err = _access(pFileFullName, 0)) == 0)
  380. {
  381. //printf_s( "File crt_access_s.c exists.\n" );
  382. // Check for write permission.
  383. if ((err = _access(pFileFullName, 2)) == 0)
  384. {
  385. //printf_s( "File crt_access_s.c does have ""write permission.\n" );
  386. }
  387. else
  388. {
  389. //printf_s( "File crt_access_s.c does not have ""write permission.\n" );
  390. }
  391. }
  392. else
  393. {
  394. //printf_s( "File crt_access_s.c does not exist.\n" );
  395. return FALSE;
  396. }
  397. return TRUE;
  398. }
  399. // Pump messages while waiting for event
  400. //----------------------------------------------------------
  401. // 函数:WaitWithMessageLoop
  402. // 描述:等待某内核事件触发;
  403. // 参数:
  404. // hEvent: 被等待响应的内核事件对象;
  405. // nTimeout: 超时值;
  406. // 返回:TRUE返回触发成功;
  407. //----------------------------------------------------------
  408. BOOL WaitWithMessageLoop(HANDLE hEvent, int nTimeout)
  409. {
  410. DWORD dwRet = 0;
  411. while (1)
  412. {
  413. // wait for event or message, if it's a message, process it and return to waiting state
  414. dwRet = MsgWaitForMultipleObjects(1, &hEvent, FALSE, nTimeout, QS_ALLINPUT);
  415. if (dwRet == WAIT_OBJECT_0)
  416. {
  417. TRACE0("WaitWithMessageLoop() event triggered.\n");
  418. return TRUE;
  419. }
  420. else if (dwRet == WAIT_OBJECT_0 + 1)
  421. {
  422. // process window messages
  423. AfxGetApp()->PumpMessage();
  424. }
  425. else if (dwRet == WAIT_TIMEOUT)
  426. {
  427. // timed out !
  428. return FALSE;
  429. }
  430. else
  431. {
  432. // WAIT_ABANDONED_0 ...
  433. return TRUE;
  434. }
  435. }
  436. }
  437. /************************************************************************/
  438. /* 函数:[10/13/2016 IT];
  439. /* 描述:;
  440. /* 参数:;
  441. /* [IN] :;
  442. /* [OUT] :;
  443. /* [IN/OUT] :;
  444. /* 返回:void;
  445. /* 注意:;
  446. /* 示例:;
  447. /*
  448. /* 修改:;
  449. /* 日期:;
  450. /* 内容:;
  451. /************************************************************************/
  452. void DeleteDirectory(IN CString strDirectory)
  453. {
  454. try
  455. {
  456. // 首先删除文件及子文件夹;
  457. CFileFind ff;
  458. BOOL bFound = ff.FindFile(strDirectory + _T("\\*"), 0);
  459. while(bFound)
  460. {
  461. bFound = ff.FindNextFile();
  462. if ( ff.GetFileName() == _T(".") || ff.GetFileName() == _T("..") )
  463. continue;
  464. // 去掉文件(夹)只读等属性;
  465. SetFileAttributes(ff.GetFilePath(), FILE_ATTRIBUTE_NORMAL);
  466. if (ff.IsDirectory())
  467. { // 递归删除子文件夹;
  468. DeleteDirectory(ff.GetFilePath());
  469. //RemoveDirectory(ff.GetFilePath());
  470. }
  471. else
  472. {
  473. DeleteFile(ff.GetFilePath()); // 递归删除文件;
  474. }
  475. }
  476. ff.Close();
  477. // 然后删除该文件夹;
  478. RemoveDirectory(strDirectory);
  479. }
  480. catch (...)
  481. {
  482. //WriteLogin("出错在函数deldir中");
  483. }
  484. // int SHFileOperation( LPSHFILEOPSTRUCT lpFileOp );
  485. }
  486. // Jeff.注册控件函数;2014.09.11
  487. //----------------------------------------------------------
  488. // 函数:RegisterOcx
  489. // 描述:注册指定的组件文件;
  490. // 参数:ocxfile指定要注册的组件文件名;
  491. // 返回:TRUE表示注册成功;
  492. //----------------------------------------------------------
  493. BOOL RegisterOcx(LPCTSTR ocxfile)
  494. {
  495. HKEY hKey;
  496. bool bRet;
  497. USES_CONVERSION;
  498. ITypeLib* pTypeLib;
  499. CString CLSIDStr;
  500. CLSID clsid;
  501. LPOLESTR wRes = NULL;
  502. if (LoadTypeLib(T2OLE(ocxfile), &pTypeLib) == S_OK)
  503. {
  504. TLIBATTR tlibAttr, *ptlibAttr;
  505. ptlibAttr = &tlibAttr;
  506. pTypeLib->GetLibAttr(&ptlibAttr);
  507. clsid = ptlibAttr->guid;
  508. pTypeLib->Release();
  509. }
  510. ::StringFromCLSID(clsid, &wRes);
  511. CLSIDStr = OLE2CT(wRes);
  512. if ((RegOpenKeyEx(HKEY_CLASSES_ROOT, "CLSID\\" + CLSIDStr, 0, KEY_READ, &hKey) == ERROR_SUCCESS) || (RegOpenKeyEx(HKEY_CLASSES_ROOT, "Wow6432Node\\TypeLib\\" + CLSIDStr, 0, KEY_READ, &hKey) == ERROR_SUCCESS))
  513. {
  514. return true;
  515. }
  516. else
  517. {
  518. HINSTANCE hLib = LoadLibrary(ocxfile);
  519. if (hLib < (HINSTANCE)HINSTANCE_ERROR)
  520. {
  521. MessageBox(0, "权限不足,不能载入OCX文件!无法注册控件!", "结果", MB_OK);
  522. bRet = false;
  523. }
  524. else
  525. {
  526. FARPROC lpDllEntryPoint;
  527. lpDllEntryPoint = GetProcAddress(hLib, _T("DllRegisterServer"));
  528. if (lpDllEntryPoint != NULL)
  529. {
  530. if (FAILED((*lpDllEntryPoint)()))
  531. {
  532. MessageBox(0, "调用注册函数(DllRegisterServer)失败!无法注册控件!", "结果", MB_OK);
  533. bRet = false;
  534. }
  535. else
  536. bRet = true;
  537. }
  538. else
  539. {
  540. MessageBox(0, "调用注册函数(DllRegisterServer)失败!无法注册控件!", "结果", MB_OK);
  541. bRet = false;
  542. }
  543. }
  544. FreeLibrary(hLib);
  545. return bRet;
  546. }
  547. }
  548. // Jeff.Hacker. WINDOWS NT 以上的内核需要提权,才能对系统进行高级管理;
  549. //----------------------------------------------------------
  550. // 函数:GetDebugPriv
  551. // 描述:对程序提权;
  552. // 参数:
  553. // 返回:TRUE表示程序提权成功;
  554. //----------------------------------------------------------
  555. BOOL GetDebugPriv()
  556. {
  557. // 返回的访问令牌指针;
  558. HANDLE hToken;
  559. // 接收所返回的制定特权名称的信息;
  560. LUID sedebugnameValue;
  561. // 新特权信息的指针(结构体);
  562. TOKEN_PRIVILEGES tkp;
  563. DWORD dwCurProcId = GetCurrentProcessId();
  564. // 要修改访问权限的进程句柄;
  565. HANDLE hCurProc;
  566. hCurProc = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwCurProcId);
  567. if (!::OpenProcessToken(hCurProc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
  568. {
  569. ShowSystemErrorInfo(CString("提权OpenProcessToken失败。"), GetLastError());
  570. return FALSE;
  571. }
  572. if (!::LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &sedebugnameValue))
  573. {
  574. ShowSystemErrorInfo(CString("提权LookupPrivilegeValue失败。"), GetLastError());
  575. CloseHandle(hToken);
  576. return FALSE;
  577. }
  578. tkp.PrivilegeCount = 1;
  579. tkp.Privileges[0].Luid = sedebugnameValue;
  580. tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  581. if (!::AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof tkp, NULL, NULL))
  582. {
  583. ShowSystemErrorInfo(CString("提权AdjustTokenPrivileges失败。"), GetLastError());
  584. CloseHandle(hToken);
  585. return FALSE;
  586. }
  587. CloseHandle(hCurProc);
  588. CloseHandle(hToken);
  589. return TRUE;
  590. }
  591. //----------------------------------------------------------
  592. // 函数:GetFileVersion
  593. // 描述:获取指定模块的文件版本信息
  594. // 参数:
  595. // hModule: 指定的模块(如果为NULL,表示获取自身文件版本信息);
  596. // pBuffer: 返回的文件版本信息;
  597. //
  598. // 返回:TRUE表示获取模块文件版本信息成功;
  599. //----------------------------------------------------------
  600. bool GetFileVersion(HMODULE hModule, WORD *pBuffer)
  601. {
  602. TCHAR fname[MAX_PATH];
  603. VS_FIXEDFILEINFO *pVi;
  604. DWORD dwHandle;
  605. std::string str;
  606. if (::GetModuleFileName(hModule, fname, MAX_PATH))
  607. {
  608. int size = GetFileVersionInfoSize(fname, &dwHandle);
  609. if (size > 0)
  610. {
  611. BYTE *buffer = new BYTE[size];
  612. memset(buffer, 0, size);
  613. if (GetFileVersionInfo(fname, dwHandle, size, buffer))
  614. {
  615. if (VerQueryValue(buffer, _T("\\"), (LPVOID *)&pVi, (PUINT)&size))
  616. {
  617. pBuffer[0] = HIWORD(pVi->dwFileVersionMS);
  618. pBuffer[1] = LOWORD(pVi->dwFileVersionMS);
  619. pBuffer[2] = HIWORD(pVi->dwFileVersionLS);
  620. pBuffer[3] = LOWORD(pVi->dwFileVersionLS);
  621. delete buffer;
  622. return true;
  623. }
  624. }
  625. delete buffer;
  626. }
  627. }
  628. return false;
  629. }
  630. //----------------------------------------------------------
  631. // GetProductVersion
  632. // 描述:获取指定模块的文件版本信息
  633. // 参数:
  634. // hModule: 指定的模块(如果为NULL,表示获取自身文件版本信息);
  635. // pBuffer: 返回的文件版本信息;
  636. //
  637. // 返回:TRUE表示获取模块文件版本信息成功;
  638. //----------------------------------------------------------
  639. bool GetProductVersion(IN HMODULE hModule, OUT WORD *pBuffer)
  640. {
  641. TCHAR fname[MAX_PATH] = {0};
  642. VS_FIXEDFILEINFO *pVi = NULL;
  643. DWORD dwHandle = 0;
  644. string str;
  645. if (::GetModuleFileName(hModule, fname, MAX_PATH))
  646. {
  647. int size = GetFileVersionInfoSize(fname, &dwHandle);
  648. if (size > 0)
  649. {
  650. BYTE *buffer = new BYTE[size];
  651. memset(buffer,0,size);
  652. if (GetFileVersionInfo(fname, dwHandle, size, buffer))
  653. {
  654. if (VerQueryValue(buffer, _T("\\"), (LPVOID *)&pVi, (PUINT)&size))
  655. {
  656. pBuffer[0] = HIWORD(pVi->dwProductVersionMS);
  657. pBuffer[1] = LOWORD(pVi->dwProductVersionMS);
  658. pBuffer[2] = HIWORD(pVi->dwProductVersionLS);
  659. pBuffer[3] = LOWORD(pVi->dwProductVersionLS);
  660. delete []buffer;
  661. return true;
  662. }
  663. }
  664. delete []buffer;
  665. }
  666. }
  667. return false;
  668. }
  669. //----------------------------------------------------------
  670. // 函数:CheckInternalIP
  671. // 描述:判断IP(网络字节序)地址是否为外网地址;
  672. // 参数:ip_addr:主机IP(必须为网络字节序);
  673. //
  674. // 返回:TRUE表示主机IP为外网IP; FALSE表示内网IP;
  675. //----------------------------------------------------------
  676. BOOL CheckInternalIPV4(const unsigned int &ip_addr)
  677. {
  678. // 三段保留IP段,做为私有地址,不在在公网上使用,只作内网IP;
  679. // A类:10.0.0.0 ~ 10.255.255.255 = 0A.00.00.00 ~ 0A.FF.FF.FF
  680. // B类:172.16.0.0 ~ 172.31.255.255 = AC.10.00.00 ~ AC.1F.FF.FF
  681. // C类:192.168.0.0 ~ 192.168.255.255 = C0.A8.00.00 ~ C0.A8.FF.FF
  682. // D类:127.0.0.0 ~ 127.255.255.255 = 7F.00.00.00 ! 7F.FF.FF.FF (环回地址)
  683. #if 0
  684. //检查3类地址是否属于公网;
  685. if ((ip_addr >= 0x0A000000 && ip_addr <= 0x0AFFFFFF) ||
  686. (ip_addr >= 0xAC100000 && ip_addr <= 0xAC1FFFFF) ||
  687. (ip_addr >= 0xC0A80000 && ip_addr <= 0xC0A8FFFF)
  688. )
  689. {
  690. return FALSE;
  691. }
  692. return TRUE;
  693. #endif
  694. #if 0
  695. //检查3类地址是否属于内网;
  696. // 0xa -- "10.0.0.0">>24;
  697. // 0xc0a8--"192.168.0.0.">>16;
  698. // 0x2b0--"127.17.0.1">>22
  699. if ((ip_addr >> 24 == 0xa) || (ip_addr >> 16 == 0xc0a8) || (ip_addr >> 22 == 0x2b0))
  700. return FALSE;
  701. else
  702. return TRUE;
  703. #endif
  704. #if 1
  705. // 回环地址也算进去!
  706. if ((ip_addr >> 24 == 0x0A) || (ip_addr >> 20 == 0xAC1) || (ip_addr >> 16 == 0xC0A8) || (ip_addr >> 26 == 0x7))
  707. return FALSE;
  708. else
  709. return TRUE;
  710. #endif
  711. }
  712. //----------------------------------------------------------
  713. // 函数:IsValidIPV4
  714. // 描述:判断字符串是否是有效的IPV4;
  715. // 参数:szIP:主机IP;
  716. //
  717. // 返回:TRUE表示字符串为有效的IPV4;
  718. //----------------------------------------------------------
  719. BOOL IsValidIPV4(const TCHAR *szIP)
  720. {
  721. int nIndex = 0;
  722. int nPointCount = 0; // "."IPV4有3个;
  723. int nLen = strlen(szIP);
  724. for (int i = 0; i < nLen; i++)
  725. {
  726. if (szIP[i] == '.')
  727. {
  728. if (i == 0 || i == nLen - 1)
  729. {
  730. return FALSE;
  731. }
  732. else
  733. {
  734. if (++nIndex != i)
  735. {
  736. nIndex = i;
  737. nPointCount++;
  738. }
  739. else
  740. return FALSE;
  741. }
  742. continue;
  743. }
  744. if (isdigit(szIP[i]) == 0)
  745. return FALSE;
  746. }
  747. if (nPointCount != 3)
  748. return FALSE;
  749. return TRUE;
  750. }
  751. //----------------------------------------------------------
  752. // 函数:GetHostAllOfIP
  753. // 描述:返回指定主机名称的所有IPV4地址;
  754. // 参数:
  755. // pHostName: 主机名;
  756. // vtHostIPV4:指定主机名的所有IPV4地址;
  757. //
  758. // 返回:TRUE表示字符串为有效的IPV4;
  759. //----------------------------------------------------------
  760. int GetHostAllOfIP(const TCHAR *pHostName, std::vector<std::string> &vtHostIPV4)
  761. {
  762. #if 0
  763. WSADATA wsa = { 0 };
  764. WSAStartup(MAKEWORD(2, 2), &wsa);
  765. #endif
  766. #if 0 // YLGL项目使用不了,因为包含了旧的系统头文件;
  767. addrinfo hint, *answer, *curr;
  768. memset(&hint, 0, sizeof(addrinfo));
  769. hint.ai_family = AF_INET;
  770. hint.ai_socktype = SOCK_STREAM;
  771. int nRet = GetAddrInfo(pHostName, NULL, &hint, &answer);
  772. //int nRet = GetAddrInfo(pHostName, "5678", &hint, &answer);
  773. if (nRet != 0)
  774. {
  775. DWORD dwError = GetLastError();
  776. return;
  777. }
  778. TCHAR szIP[MAX_PATH];
  779. for (curr = answer; curr != NULL; curr = curr->ai_next)
  780. {
  781. //std::string ipstr;
  782. memset(szIP, 0, MAX_PATH);
  783. _inet_ntop(AF_INET, &(((sockaddr_in*)(curr->ai_addr))->sin_addr), szIP, MAX_PATH);
  784. vtHostIPV4.push_back(szIP);
  785. }
  786. freeaddrinfo(answer);
  787. #endif
  788. return 0;
  789. }
  790. void DataToArray(CArray<CStringArray, CStringArray>*pArrayOfString, int datapos)
  791. {
  792. try
  793. {
  794. pArrayOfString->RemoveAll();
  795. if (g_nLeng == 0)
  796. {
  797. return;
  798. }
  799. // 1.code[0]数组:用作发送时,存储着操作指令;用作接收时,存储着接收数据大小???;
  800. if (g_sendhead.code[0])
  801. {
  802. // 1.1.将g_pData全局变量里保存的数据进行解压,并存储在lpszOut数组里;
  803. BYTE *lpszOut = NULL;
  804. int nOutSize = 0;
  805. LZARI Lzari;
  806. #if defined(VC70) || defined(VC60)
  807. Lzari.UnCompress(g_pData, g_nLeng, lpszOut, nOutSize);
  808. #else
  809. Lzari.UnCompress(g_pData, g_nLeng, (const BYTE*&)lpszOut, nOutSize);
  810. #endif
  811. // 1.2.将解压后的数据lpszOut附加到内存文件里;
  812. CMemFile memfile;
  813. memfile.Attach(lpszOut, nOutSize);
  814. // 1.3.将内存文件序列化保存到CArchive对象里;
  815. CArchive ar(&memfile, CArchive::load);
  816. pArrayOfString->SetSize(g_sendhead.count[0]);
  817. // 1.4.将CArchive对象里的数据,序列化到指定的CArray对象里;
  818. for (int ii = 0; ii < pArrayOfString->GetSize(); ii++)
  819. {
  820. pArrayOfString->ElementAt(ii).Serialize(ar);
  821. }
  822. // 1.5.完成数据的导出任务,释放内存;
  823. ar.Close();
  824. Lzari.Release();
  825. memfile.Detach();
  826. }
  827. else
  828. {
  829. CMemFile memfile;
  830. memfile.Attach(g_pData, g_nLeng);
  831. CArchive ar(&memfile, CArchive::load);
  832. pArrayOfString->SetSize(g_sendhead.count[0]);
  833. for (int ii = 0; ii < pArrayOfString->GetSize(); ii++)
  834. {
  835. pArrayOfString->ElementAt(ii).Serialize(ar);
  836. }
  837. ar.Close();
  838. memfile.Detach();
  839. }
  840. }
  841. catch (...)
  842. {
  843. }
  844. }
  845. void DataToArray(
  846. CArray<CStringArray, CStringArray>*pArrayOfString1,
  847. CArray<CStringArray, CStringArray>*pArrayOfString2,
  848. int datapos)
  849. {
  850. try
  851. {
  852. CArray<CStringArray, CStringArray>*parray[2] = { pArrayOfString1, pArrayOfString2 };
  853. DWORD bytereads = 0;
  854. for (int i = 0; i < 2; i++)
  855. {
  856. parray[i]->RemoveAll();
  857. if (g_sendhead.length[i] == 0)
  858. continue;
  859. if (g_sendhead.code[i])
  860. {
  861. // 1.1.将g_pData全局变量里保存的数据进行解压,并存储在lpszOut数组里;
  862. BYTE *lpszOut = NULL;
  863. int nOutSize = 0;
  864. LZARI Lzari;
  865. #ifdef VC60
  866. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], lpszOut, nOutSize);
  867. #else
  868. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], (const BYTE*&)lpszOut, nOutSize);
  869. #endif
  870. // 1.2.将解压后的数据lpszOut附加到内存文件里;
  871. CMemFile memfile;
  872. memfile.Attach(lpszOut, nOutSize);
  873. // 1.3.将内存文件序列化保存到CArchive对象里;
  874. bytereads += g_sendhead.length[i];
  875. CArchive ar(&memfile, CArchive::load);
  876. parray[i]->SetSize(g_sendhead.count[i]);
  877. // 1.4.将CArchive对象里的数据,序列化到指定的CArray对象里;
  878. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  879. {
  880. parray[i]->ElementAt(ii).Serialize(ar);
  881. }
  882. // 1.5.完成数据的导出任务,释放内存;
  883. ar.Close();
  884. Lzari.Release();
  885. memfile.Detach();
  886. }
  887. else
  888. {
  889. CMemFile memfile;
  890. memfile.Attach(g_pData + bytereads, g_sendhead.length[i]);
  891. bytereads += g_sendhead.length[i];
  892. CArchive ar(&memfile, CArchive::load);
  893. parray[i]->SetSize(g_sendhead.count[i]);
  894. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  895. {
  896. parray[i]->ElementAt(ii).Serialize(ar);
  897. }
  898. ar.Close();
  899. memfile.Detach();
  900. }
  901. }
  902. }
  903. catch (...)
  904. {
  905. }
  906. }
  907. void DataToArray(
  908. CArray<CStringArray, CStringArray>*pArrayOfString1,
  909. CArray<CStringArray, CStringArray>*pArrayOfString2,
  910. CArray<CStringArray, CStringArray>*pArrayOfString3,
  911. int datapos)
  912. {
  913. try
  914. {
  915. CArray<CStringArray, CStringArray>*parray[3] = { pArrayOfString1, pArrayOfString2, pArrayOfString3 };
  916. DWORD bytereads = 0;
  917. for (int i = 0; i < 3; i++)
  918. {
  919. parray[i]->RemoveAll(); if (g_sendhead.length[i] == 0)continue;
  920. if (g_sendhead.code[i])
  921. {
  922. BYTE *lpszOut = NULL;
  923. int nOutSize = 0;
  924. LZARI Lzari;
  925. #ifdef VC60
  926. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], lpszOut, nOutSize);
  927. #else
  928. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], (const BYTE*&)lpszOut, nOutSize);
  929. #endif
  930. CMemFile memfile;
  931. memfile.Attach(lpszOut, nOutSize);
  932. bytereads += g_sendhead.length[i];
  933. CArchive ar(&memfile, CArchive::load);
  934. parray[i]->SetSize(g_sendhead.count[i]);
  935. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  936. {
  937. parray[i]->ElementAt(ii).Serialize(ar);
  938. }
  939. ar.Close();
  940. Lzari.Release();
  941. memfile.Detach();
  942. }
  943. else
  944. {
  945. CMemFile memfile;
  946. memfile.Attach(g_pData + bytereads, g_sendhead.length[i]);
  947. bytereads += g_sendhead.length[i];
  948. CArchive ar(&memfile, CArchive::load);
  949. parray[i]->SetSize(g_sendhead.count[i]);
  950. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  951. {
  952. parray[i]->ElementAt(ii).Serialize(ar);
  953. }
  954. ar.Close();
  955. memfile.Detach();
  956. }
  957. }
  958. }
  959. catch (...)
  960. {
  961. }
  962. }
  963. void DataToArray(
  964. CArray<CStringArray, CStringArray>*pArrayOfString1,
  965. CArray<CStringArray, CStringArray>*pArrayOfString2,
  966. CArray<CStringArray, CStringArray>*pArrayOfString3,
  967. CArray<CStringArray, CStringArray>*pArrayOfString4,
  968. int datapos)
  969. {
  970. try
  971. {
  972. CArray<CStringArray, CStringArray>*parray[4] =
  973. {
  974. pArrayOfString1,
  975. pArrayOfString2,
  976. pArrayOfString3,
  977. pArrayOfString4
  978. };
  979. DWORD bytereads = 0;
  980. for (int i = 0; i < 4; i++)
  981. {
  982. parray[i]->RemoveAll(); if (g_sendhead.length[i] == 0)continue;
  983. if (g_sendhead.code[i])
  984. {
  985. BYTE *lpszOut = NULL;
  986. int nOutSize = 0;
  987. LZARI Lzari;
  988. #ifdef VC60
  989. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], lpszOut, nOutSize);
  990. #else
  991. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], (const BYTE*&)lpszOut, nOutSize);
  992. #endif
  993. CMemFile memfile;
  994. memfile.Attach(lpszOut, nOutSize);
  995. bytereads += g_sendhead.length[i];
  996. CArchive ar(&memfile, CArchive::load);
  997. parray[i]->SetSize(g_sendhead.count[i]);
  998. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  999. {
  1000. parray[i]->ElementAt(ii).Serialize(ar);
  1001. }
  1002. ar.Close();
  1003. Lzari.Release();
  1004. memfile.Detach();
  1005. }
  1006. else
  1007. {
  1008. CMemFile memfile;
  1009. memfile.Attach(g_pData + bytereads, g_sendhead.length[i]);
  1010. bytereads += g_sendhead.length[i];
  1011. CArchive ar(&memfile, CArchive::load);
  1012. parray[i]->SetSize(g_sendhead.count[i]);
  1013. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  1014. {
  1015. parray[i]->ElementAt(ii).Serialize(ar);
  1016. }
  1017. ar.Close();
  1018. memfile.Detach();
  1019. }
  1020. }
  1021. }
  1022. catch (...)
  1023. {
  1024. }
  1025. }
  1026. void DataToArray(
  1027. CArray<CStringArray, CStringArray>*pArrayOfString1,
  1028. CArray<CStringArray, CStringArray>*pArrayOfString2,
  1029. CArray<CStringArray, CStringArray>*pArrayOfString3,
  1030. CArray<CStringArray, CStringArray>*pArrayOfString4,
  1031. CArray<CStringArray, CStringArray>*pArrayOfString5,
  1032. int datapos)
  1033. {
  1034. try
  1035. {
  1036. CArray<CStringArray, CStringArray>*parray[5] =
  1037. {
  1038. pArrayOfString1,
  1039. pArrayOfString2,
  1040. pArrayOfString3,
  1041. pArrayOfString4,
  1042. pArrayOfString5
  1043. };
  1044. DWORD bytereads = 0;
  1045. for (int i = 0; i < 5; i++)
  1046. {
  1047. parray[i]->RemoveAll();
  1048. if (g_sendhead.length[i] == 0)
  1049. continue;
  1050. if (g_sendhead.code[i])
  1051. {
  1052. BYTE *lpszOut = NULL;
  1053. int nOutSize = 0;
  1054. LZARI Lzari;
  1055. #ifdef VC60
  1056. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], lpszOut, nOutSize);
  1057. #else
  1058. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], (const BYTE*&)lpszOut, nOutSize);
  1059. #endif
  1060. CMemFile memfile;
  1061. memfile.Attach(lpszOut, nOutSize);
  1062. bytereads += g_sendhead.length[i];
  1063. CArchive ar(&memfile, CArchive::load);
  1064. parray[i]->SetSize(g_sendhead.count[i]);
  1065. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  1066. {
  1067. parray[i]->ElementAt(ii).Serialize(ar);
  1068. }
  1069. ar.Close();
  1070. Lzari.Release();
  1071. memfile.Detach();
  1072. }
  1073. else
  1074. {
  1075. CMemFile memfile;
  1076. memfile.Attach(g_pData + bytereads, g_sendhead.length[i]);
  1077. bytereads += g_sendhead.length[i];
  1078. CArchive ar(&memfile, CArchive::load);
  1079. parray[i]->SetSize(g_sendhead.count[i]);
  1080. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  1081. {
  1082. parray[i]->ElementAt(ii).Serialize(ar);
  1083. }
  1084. ar.Close();
  1085. memfile.Detach();
  1086. }
  1087. }
  1088. }
  1089. catch (...)
  1090. {
  1091. }
  1092. }
  1093. void DataToArray(
  1094. CArray<CStringArray, CStringArray>*pArrayOfString1,
  1095. CArray<CStringArray, CStringArray>*pArrayOfString2,
  1096. CArray<CStringArray, CStringArray>*pArrayOfString3,
  1097. CArray<CStringArray, CStringArray>*pArrayOfString4,
  1098. CArray<CStringArray, CStringArray>*pArrayOfString5,
  1099. CArray<CStringArray, CStringArray>*pArrayOfString6,
  1100. int datapos)
  1101. {
  1102. try
  1103. {
  1104. CArray<CStringArray, CStringArray>*parray[6] =
  1105. {
  1106. pArrayOfString1,
  1107. pArrayOfString2,
  1108. pArrayOfString3,
  1109. pArrayOfString4,
  1110. pArrayOfString5,
  1111. pArrayOfString6
  1112. };
  1113. DWORD bytereads = 0;
  1114. for (int i = 0; i < 6; i++)
  1115. {
  1116. parray[i]->RemoveAll();
  1117. if (g_sendhead.length[i] == 0)continue;
  1118. if (g_sendhead.code[i])
  1119. {
  1120. BYTE *lpszOut = NULL;
  1121. int nOutSize = 0;
  1122. LZARI Lzari;
  1123. #ifdef VC60
  1124. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], lpszOut, nOutSize);
  1125. #else
  1126. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], (const BYTE*&)lpszOut, nOutSize);
  1127. #endif
  1128. CMemFile memfile;
  1129. memfile.Attach(lpszOut, nOutSize);
  1130. bytereads += g_sendhead.length[i];
  1131. CArchive ar(&memfile, CArchive::load);
  1132. parray[i]->SetSize(g_sendhead.count[i]);
  1133. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  1134. {
  1135. parray[i]->ElementAt(ii).Serialize(ar);
  1136. }
  1137. ar.Close();
  1138. Lzari.Release();
  1139. memfile.Detach();
  1140. }
  1141. else
  1142. {
  1143. CMemFile memfile;
  1144. memfile.Attach(g_pData + bytereads, g_sendhead.length[i]);
  1145. bytereads += g_sendhead.length[i];
  1146. CArchive ar(&memfile, CArchive::load);
  1147. parray[i]->SetSize(g_sendhead.count[i]);
  1148. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  1149. {
  1150. parray[i]->ElementAt(ii).Serialize(ar);
  1151. }
  1152. ar.Close();
  1153. memfile.Detach();
  1154. }
  1155. }
  1156. }
  1157. catch (...)
  1158. {
  1159. }
  1160. }
  1161. void DataToArray(
  1162. CArray<CStringArray, CStringArray>*pArrayOfString1,
  1163. CArray<CStringArray, CStringArray>*pArrayOfString2,
  1164. CArray<CStringArray, CStringArray>*pArrayOfString3,
  1165. CArray<CStringArray, CStringArray>*pArrayOfString4,
  1166. CArray<CStringArray, CStringArray>*pArrayOfString5,
  1167. CArray<CStringArray, CStringArray>*pArrayOfString6,
  1168. CArray<CStringArray, CStringArray>*pArrayOfString7,
  1169. int datapos)
  1170. {
  1171. try
  1172. {
  1173. CArray<CStringArray, CStringArray>*parray[7] =
  1174. {
  1175. pArrayOfString1,
  1176. pArrayOfString2,
  1177. pArrayOfString3,
  1178. pArrayOfString4,
  1179. pArrayOfString5,
  1180. pArrayOfString6,
  1181. pArrayOfString7
  1182. };
  1183. DWORD bytereads = 0;
  1184. for (int i = 0; i < 7; i++)
  1185. {
  1186. parray[i]->RemoveAll();
  1187. if (g_sendhead.length[i] == 0)continue;
  1188. if (g_sendhead.code[i])
  1189. {
  1190. BYTE *lpszOut = NULL;
  1191. int nOutSize = 0;
  1192. LZARI Lzari;
  1193. #ifdef VC60
  1194. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], lpszOut, nOutSize);
  1195. #else
  1196. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], (const BYTE*&)lpszOut, nOutSize);
  1197. #endif
  1198. CMemFile memfile;
  1199. memfile.Attach(lpszOut, nOutSize);
  1200. bytereads += g_sendhead.length[i];
  1201. CArchive ar(&memfile, CArchive::load);
  1202. parray[i]->SetSize(g_sendhead.count[i]);
  1203. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  1204. {
  1205. parray[i]->ElementAt(ii).Serialize(ar);
  1206. }
  1207. ar.Close();
  1208. Lzari.Release();
  1209. memfile.Detach();
  1210. }
  1211. else
  1212. {
  1213. CMemFile memfile;
  1214. memfile.Attach(g_pData + bytereads, g_sendhead.length[i]);
  1215. bytereads += g_sendhead.length[i];
  1216. CArchive ar(&memfile, CArchive::load);
  1217. parray[i]->SetSize(g_sendhead.count[i]);
  1218. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  1219. {
  1220. parray[i]->ElementAt(ii).Serialize(ar);
  1221. }
  1222. ar.Close();
  1223. memfile.Detach();
  1224. }
  1225. }
  1226. }
  1227. catch (...)
  1228. {
  1229. }
  1230. }
  1231. void DataToArray(
  1232. CArray<CStringArray, CStringArray>*pArrayOfString1,
  1233. CArray<CStringArray, CStringArray>*pArrayOfString2,
  1234. CArray<CStringArray, CStringArray>*pArrayOfString3,
  1235. CArray<CStringArray, CStringArray>*pArrayOfString4,
  1236. CArray<CStringArray, CStringArray>*pArrayOfString5,
  1237. CArray<CStringArray, CStringArray>*pArrayOfString6,
  1238. CArray<CStringArray, CStringArray>*pArrayOfString7,
  1239. CArray<CStringArray, CStringArray>*pArrayOfString8,
  1240. int datapos)
  1241. {
  1242. try
  1243. {
  1244. CArray<CStringArray, CStringArray>*parray[8] =
  1245. {
  1246. pArrayOfString1,
  1247. pArrayOfString2,
  1248. pArrayOfString3,
  1249. pArrayOfString4,
  1250. pArrayOfString5,
  1251. pArrayOfString6,
  1252. pArrayOfString7,
  1253. pArrayOfString8
  1254. };
  1255. DWORD bytereads = 0;
  1256. for (int i = 0; i < 8; i++)
  1257. {
  1258. parray[i]->RemoveAll();
  1259. if (g_sendhead.length[i] == 0)continue;
  1260. if (g_sendhead.code[i])
  1261. {
  1262. BYTE *lpszOut = NULL;
  1263. int nOutSize = 0;
  1264. LZARI Lzari;
  1265. #ifdef VC60
  1266. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], lpszOut, nOutSize);
  1267. #else
  1268. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], (const BYTE*&)lpszOut, nOutSize);
  1269. #endif
  1270. CMemFile memfile;
  1271. memfile.Attach(lpszOut, nOutSize);
  1272. bytereads += g_sendhead.length[i];
  1273. CArchive ar(&memfile, CArchive::load);
  1274. parray[i]->SetSize(g_sendhead.count[i]);
  1275. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  1276. {
  1277. parray[i]->ElementAt(ii).Serialize(ar);
  1278. }
  1279. ar.Close();
  1280. Lzari.Release();
  1281. memfile.Detach();
  1282. }
  1283. else
  1284. {
  1285. CMemFile memfile;
  1286. memfile.Attach(g_pData + bytereads, g_sendhead.length[i]);
  1287. bytereads += g_sendhead.length[i];
  1288. CArchive ar(&memfile, CArchive::load);
  1289. parray[i]->SetSize(g_sendhead.count[i]);
  1290. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  1291. {
  1292. parray[i]->ElementAt(ii).Serialize(ar);
  1293. }
  1294. ar.Close();
  1295. memfile.Detach();
  1296. }
  1297. }
  1298. }
  1299. catch (...)
  1300. {
  1301. }
  1302. }
  1303. void DataToArray(
  1304. CArray<CStringArray, CStringArray>*pArrayOfString1,
  1305. CArray<CStringArray, CStringArray>*pArrayOfString2,
  1306. CArray<CStringArray, CStringArray>*pArrayOfString3,
  1307. CArray<CStringArray, CStringArray>*pArrayOfString4,
  1308. CArray<CStringArray, CStringArray>*pArrayOfString5,
  1309. CArray<CStringArray, CStringArray>*pArrayOfString6,
  1310. CArray<CStringArray, CStringArray>*pArrayOfString7,
  1311. CArray<CStringArray, CStringArray>*pArrayOfString8,
  1312. CArray<CStringArray, CStringArray>*pArrayOfString9,
  1313. CArray<CStringArray, CStringArray>*pArrayOfString10,
  1314. int datapos)
  1315. {
  1316. try
  1317. {
  1318. CArray<CStringArray, CStringArray>*parray[10] =
  1319. {
  1320. pArrayOfString1,
  1321. pArrayOfString2,
  1322. pArrayOfString3,
  1323. pArrayOfString4,
  1324. pArrayOfString5,
  1325. pArrayOfString6,
  1326. pArrayOfString7,
  1327. pArrayOfString8,
  1328. pArrayOfString9,
  1329. pArrayOfString10
  1330. };
  1331. DWORD bytereads = 0;
  1332. for (int i = 0; i < 10; i++)
  1333. {
  1334. parray[i]->RemoveAll();
  1335. if (g_sendhead.length[i] == 0)continue;
  1336. if (g_sendhead.code[i])
  1337. {
  1338. BYTE *lpszOut = NULL;
  1339. int nOutSize = 0;
  1340. LZARI Lzari;
  1341. #ifdef VC60
  1342. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], lpszOut, nOutSize);
  1343. #else
  1344. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], (const BYTE*&)lpszOut, nOutSize);
  1345. #endif
  1346. CMemFile memfile;
  1347. memfile.Attach(lpszOut, nOutSize);
  1348. bytereads += g_sendhead.length[i];
  1349. CArchive ar(&memfile, CArchive::load);
  1350. parray[i]->SetSize(g_sendhead.count[i]);
  1351. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  1352. {
  1353. parray[i]->ElementAt(ii).Serialize(ar);
  1354. }
  1355. ar.Close();
  1356. Lzari.Release();
  1357. memfile.Detach();
  1358. }
  1359. else
  1360. {
  1361. CMemFile memfile;
  1362. memfile.Attach(g_pData + bytereads, g_sendhead.length[i]);
  1363. bytereads += g_sendhead.length[i];
  1364. CArchive ar(&memfile, CArchive::load);
  1365. parray[i]->SetSize(g_sendhead.count[i]);
  1366. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  1367. {
  1368. parray[i]->ElementAt(ii).Serialize(ar);
  1369. }
  1370. ar.Close();
  1371. memfile.Detach();
  1372. }
  1373. }
  1374. }
  1375. catch (...)
  1376. {
  1377. }
  1378. }
  1379. //////////////////////////////////////////////////////////////////////////
  1380. // Image版本;
  1381. BOOL LoadImageFromFile(IN Image** pImg, IN CString strPath)
  1382. {
  1383. if ( !PathFileExists(strPath) )
  1384. return FALSE;
  1385. if ( *pImg )
  1386. delete *pImg;
  1387. *pImg = NULL;
  1388. #ifdef UNICODE
  1389. *pImg = Image::FromFile(strPath);
  1390. #else
  1391. BSTR strtmp = _bstr_t(strPath);
  1392. *pImg = Image::FromFile(strtmp);
  1393. SysFreeString(strtmp);
  1394. #endif
  1395. return TRUE;
  1396. }
  1397. BOOL LoadImageFromBuf(IN Image** pImg, IN CString strPath)
  1398. {
  1399. if ( !PathFileExists(strPath) )
  1400. return FALSE;
  1401. if ( *pImg )
  1402. delete *pImg;
  1403. *pImg = NULL;
  1404. CFile fp;
  1405. CFileException e;
  1406. BOOL bRet = FALSE;
  1407. if ( fp.Open(strPath, CFile::modeRead, &e))
  1408. {
  1409. DWORD dwLength = (DWORD)fp.GetLength();
  1410. BYTE *pData = new BYTE[dwLength];
  1411. fp.Read(pData,dwLength);
  1412. fp.Close();
  1413. bRet = LoadImageFromBuf(pImg, pData, dwLength);
  1414. if( pData )
  1415. delete []pData;
  1416. }
  1417. return bRet;
  1418. }
  1419. BOOL LoadImageFromBuf(IN Image** pImg, IN BYTE* pBuffer, IN CONST DWORD& nBufLen)
  1420. {
  1421. if ( pBuffer == NULL )
  1422. return FALSE;
  1423. if ( *pImg )
  1424. delete *pImg;
  1425. *pImg = NULL;
  1426. HGLOBAL hMemery = GlobalAlloc(GMEM_MOVEABLE, nBufLen);
  1427. if ( hMemery == NULL )
  1428. return FALSE;
  1429. BYTE *pMem = (BYTE*)GlobalLock(hMemery);
  1430. memcpy(pMem, pBuffer, nBufLen);
  1431. IStream *pstream = NULL;
  1432. CreateStreamOnHGlobal(hMemery, TRUE, &pstream);
  1433. *pImg = Image::FromStream(pstream);
  1434. GlobalUnlock(hMemery);
  1435. pstream->Release();
  1436. return TRUE;
  1437. }
  1438. //////////////////////////////////////////////////////////////////////////
  1439. // Bitmap版本;
  1440. BOOL LoadImageFromFile(IN Bitmap** pImg, IN CString strPath)
  1441. {
  1442. if ( !PathFileExists(strPath) )
  1443. return FALSE;
  1444. if ( *pImg )
  1445. delete *pImg;
  1446. *pImg = NULL;
  1447. #ifdef UNICODE
  1448. *pImg = Image::FromFile(strPath);
  1449. #else
  1450. BSTR strtmp = _bstr_t(strPath);
  1451. *pImg = Bitmap::FromFile(strtmp);
  1452. SysFreeString(strtmp);
  1453. #endif
  1454. return TRUE;
  1455. }
  1456. BOOL LoadImageFromBuf(IN Bitmap** pImg, IN CString strPath)
  1457. {
  1458. if ( !PathFileExists(strPath) )
  1459. return FALSE;
  1460. if ( *pImg )
  1461. delete *pImg;
  1462. *pImg = NULL;
  1463. CFile fp;
  1464. CFileException e;
  1465. BOOL bRet = FALSE;
  1466. if ( fp.Open(strPath, CFile::modeRead, &e))
  1467. {
  1468. DWORD dwLength = (DWORD)fp.GetLength();
  1469. BYTE *pData = new BYTE[dwLength];
  1470. fp.Read(pData,dwLength);
  1471. fp.Close();
  1472. bRet = LoadImageFromBuf(pImg, pData, dwLength);
  1473. if( pData )
  1474. delete []pData;
  1475. }
  1476. return bRet;
  1477. }
  1478. BOOL LoadImageFromBuf(IN Bitmap** pImg, IN BYTE* pBuffer, IN CONST DWORD& nBufLen)
  1479. {
  1480. if ( pBuffer == NULL )
  1481. return FALSE;
  1482. if ( *pImg )
  1483. delete *pImg;
  1484. *pImg = NULL;
  1485. HGLOBAL hMemery = GlobalAlloc(GMEM_MOVEABLE, nBufLen);
  1486. if ( hMemery == NULL )
  1487. return FALSE;
  1488. BYTE *pMem = (BYTE*)GlobalLock(hMemery);
  1489. memcpy(pMem, pBuffer, nBufLen);
  1490. IStream *pstream = NULL;
  1491. CreateStreamOnHGlobal(hMemery, TRUE, &pstream);
  1492. *pImg = Bitmap::FromStream(pstream);
  1493. GlobalUnlock(hMemery);
  1494. pstream->Release();
  1495. return TRUE;
  1496. }
  1497. //////////////////////////////////////////////////////////////////////////
  1498. void LoadImageFromRes(Image **img, LPCTSTR lpszResourceName, LPCTSTR ResourceType)
  1499. {
  1500. try
  1501. {
  1502. HGLOBAL hGlobal = NULL;
  1503. HRSRC hSource = NULL;
  1504. LPVOID lpVoid = NULL;
  1505. int nSize = 0;
  1506. BOOL bResult = FALSE;
  1507. hSource = FindResource(NULL, lpszResourceName, ResourceType);
  1508. if (hSource == NULL)return;
  1509. hGlobal = LoadResource(NULL, hSource);
  1510. if (hGlobal == NULL)return;
  1511. lpVoid = LockResource(hGlobal);
  1512. if (lpVoid == NULL)return;
  1513. nSize = (UINT)SizeofResource(NULL, hSource);
  1514. LoadImageFromBuf(img, (BYTE*)hGlobal, nSize);
  1515. UnlockResource(hGlobal); // 16Bit Windows Needs This
  1516. FreeResource(hGlobal); // 16Bit Windows Needs This (32Bit - Automatic Release)
  1517. }
  1518. catch (...)
  1519. {
  1520. }
  1521. }
  1522. int GetOrientation(Image *image)
  1523. {
  1524. try
  1525. {
  1526. if (image)
  1527. {
  1528. UINT totalBufferSize;
  1529. UINT numProperties;
  1530. image->GetPropertySize(&totalBufferSize, &numProperties);
  1531. // Allocate the buffer that will receive the property items.
  1532. PropertyItem* pAllItems = (PropertyItem*)malloc(totalBufferSize);
  1533. // Fill the buffer.
  1534. image->GetAllPropertyItems(totalBufferSize, numProperties, pAllItems);
  1535. // Print the id data member of each property item.
  1536. for (UINT j = 0; j < numProperties; ++j)
  1537. {
  1538. if (PropertyTagOrientation == pAllItems[j].id)
  1539. {
  1540. short* ptrLong = (short*)(pAllItems[j].value);
  1541. int ret = (int)*ptrLong;
  1542. free(pAllItems);
  1543. return ret;
  1544. }
  1545. }
  1546. free(pAllItems);
  1547. }
  1548. }
  1549. catch (...)
  1550. {
  1551. }
  1552. return 1;
  1553. }
  1554. int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
  1555. {
  1556. UINT num = 0; // number of image encoders
  1557. UINT size = 0; // size of the image encoder array in bytes
  1558. ImageCodecInfo* pImageCodecInfo = NULL;
  1559. GetImageEncodersSize(&num, &size);
  1560. if (size == 0)
  1561. return -1; // Failure
  1562. pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
  1563. if (pImageCodecInfo == NULL)
  1564. return -1; // Failure
  1565. GetImageEncoders(num, size, pImageCodecInfo);
  1566. for (UINT j = 0; j < num; ++j)
  1567. {
  1568. if (wcscmp(pImageCodecInfo[j].MimeType, format) == 0)
  1569. {
  1570. *pClsid = pImageCodecInfo[j].Clsid;
  1571. free(pImageCodecInfo);
  1572. return j; // Success
  1573. }
  1574. }
  1575. free(pImageCodecInfo);
  1576. return -1; // FailureFailure
  1577. }
  1578. void SaveImageToFile(Image *img, CString path)
  1579. {
  1580. try
  1581. {
  1582. if (img == NULL)return;
  1583. CLSID encoderClsid;
  1584. BSTR bstr = path.AllocSysString();
  1585. path.MakeLower();
  1586. if (path.Right(3) == "bmp")
  1587. {
  1588. GetEncoderClsid(L"image/bmp", &encoderClsid);
  1589. img->Save(bstr, &encoderClsid, NULL);
  1590. }
  1591. else if (path.Right(3) == "png")
  1592. {
  1593. GetEncoderClsid(L"image/png", &encoderClsid);
  1594. img->Save(bstr, &encoderClsid, NULL);
  1595. }
  1596. else// if(path.Right (3)=="jpg")
  1597. {
  1598. GetEncoderClsid(L"image/jpeg", &encoderClsid);
  1599. EncoderParameters encoderParameters;
  1600. ULONG quality;
  1601. encoderParameters.Count = 1;
  1602. encoderParameters.Parameter[0].Guid = EncoderQuality;
  1603. encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
  1604. encoderParameters.Parameter[0].NumberOfValues = 1;
  1605. // Save the image as a JPEG with quality level 100.
  1606. quality = 100;
  1607. encoderParameters.Parameter[0].Value = &quality;
  1608. img->Save(bstr, &encoderClsid, &encoderParameters);
  1609. }
  1610. SysFreeString(bstr);
  1611. }
  1612. catch (...)
  1613. {
  1614. }
  1615. }
  1616. void SaveImageToFile2(Image *img, CString path, ULONG quality)
  1617. {
  1618. try
  1619. {
  1620. if (img == NULL)return;
  1621. CLSID encoderClsid;
  1622. BSTR bstr = path.AllocSysString();
  1623. path.MakeLower();
  1624. if (path.Right(3) == "bmp")
  1625. {
  1626. GetEncoderClsid(L"image/bmp", &encoderClsid);
  1627. img->Save(bstr, &encoderClsid, NULL);
  1628. }
  1629. else if (path.Right(3) == "png")
  1630. {
  1631. GetEncoderClsid(L"image/png", &encoderClsid);
  1632. img->Save(bstr, &encoderClsid, NULL);
  1633. }
  1634. else// if(path.Right (3)=="jpg")
  1635. {
  1636. GetEncoderClsid(L"image/jpeg", &encoderClsid);
  1637. EncoderParameters encoderParameters;
  1638. encoderParameters.Count = 1;
  1639. encoderParameters.Parameter[0].Guid = EncoderQuality;
  1640. encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
  1641. encoderParameters.Parameter[0].NumberOfValues = 1;
  1642. // Save the image as a JPEG with quality level 100.
  1643. encoderParameters.Parameter[0].Value = &quality;
  1644. img->Save(bstr, &encoderClsid, &encoderParameters);
  1645. }
  1646. SysFreeString(bstr);
  1647. }
  1648. catch (...)
  1649. {
  1650. }
  1651. }
  1652. /************************************************************************/
  1653. /* 函数:IsWaiter2[8/10/2016 IT];
  1654. /* 描述:;
  1655. /* 参数:;
  1656. /* [IN] strOrderNum:订单号;
  1657. /* [IN] strStaffName:职员名;
  1658. /* [IN] pAryWaiter:订单表信息(case 60);
  1659. /* [IN] bPhotographer:返回是否摄影师;
  1660. /* [IN] bMakeupArtist:返回是否化妆师/引导师1;
  1661. /* [IN] fscale1:返回摄影师1提成;
  1662. /* [IN] fscale2:返回化妆师/引导师1提成;
  1663. /* [IN] bCheckDate:是否要检测时间;
  1664. /* [IN] date1:开始时间;
  1665. /* [IN] date2:结束时间;
  1666. /* 返回:void;
  1667. /* 注意:;
  1668. /* 示例:;
  1669. /*
  1670. /* 修改:;
  1671. /* 日期:;
  1672. /* 内容:;
  1673. /************************************************************************/
  1674. void IsWaiter2(IN CString strOrderNum, IN CString strStaffName, CArray<CStringArray, CStringArray>*pAryWaiter, IN BOOL &bPhotographer, IN BOOL &bMakeupArtist, float &fscale1, float &fscale2, BOOL bCheckDate, CString date1, CString date2)
  1675. {
  1676. for (int i = 0; i < pAryWaiter->GetSize(); i++)
  1677. {
  1678. // ElementAt(0):订单号;
  1679. if (strOrderNum == pAryWaiter->ElementAt(i).ElementAt(0))
  1680. {
  1681. if (bCheckDate)
  1682. {
  1683. // ElementAt(21):订单拍照完成日期; ElementAt(22):订单拍照状态;
  1684. if (pAryWaiter->ElementAt(i).ElementAt(21) < date1 || pAryWaiter->ElementAt(i).ElementAt(21) > date2 || pAryWaiter->ElementAt(i).ElementAt(22) != "OK")
  1685. //if ( waiterarray->ElementAt(i).ElementAt(21) > date2 || waiterarray->ElementAt(i).ElementAt(22) != "OK")
  1686. {
  1687. bPhotographer = bMakeupArtist = FALSE;
  1688. return;
  1689. }
  1690. }
  1691. // ElementAt(1):摄影师1名称;
  1692. if (strStaffName == pAryWaiter->ElementAt(i).ElementAt(1))
  1693. {
  1694. bPhotographer = TRUE;
  1695. // ElementAt(1):摄影师1折扣;
  1696. fscale1 = atof(pAryWaiter->ElementAt(i).ElementAt(5)) / 100.0;
  1697. if (fscale1 == 0)fscale1 = 1;
  1698. }
  1699. // ElementAt(2):摄影师2名称;
  1700. else if (strStaffName == pAryWaiter->ElementAt(i).ElementAt(2))
  1701. {
  1702. bPhotographer = TRUE;
  1703. // ElementAt(6):摄影师2折扣;
  1704. fscale1 = atof(pAryWaiter->ElementAt(i).ElementAt(6)) / 100.0;
  1705. }
  1706. // ElementAt(3):摄影师3名称;
  1707. else if (strStaffName == pAryWaiter->ElementAt(i).ElementAt(3))
  1708. {
  1709. bPhotographer = TRUE;
  1710. // ElementAt(7):摄影师3折扣;
  1711. fscale1 = atof(pAryWaiter->ElementAt(i).ElementAt(7)) / 100.0;
  1712. }
  1713. // ElementAt(4):摄影师4名称;
  1714. else if (strStaffName == pAryWaiter->ElementAt(i).ElementAt(4))
  1715. {
  1716. bPhotographer = TRUE;
  1717. // ElementAt(8):摄影师4折扣;
  1718. fscale1 = atof(pAryWaiter->ElementAt(i).ElementAt(8)) / 100.0;
  1719. }
  1720. ///////////////////////////////////////////////////////////////////////
  1721. // ElementAt(9):化妆师/引导师1名称;
  1722. if (strStaffName == pAryWaiter->ElementAt(i).ElementAt(9))
  1723. {
  1724. bMakeupArtist = TRUE;
  1725. // ElementAt(13):化妆师/引导师1折扣;
  1726. fscale2 = atof(pAryWaiter->ElementAt(i).ElementAt(13)) / 100.0;
  1727. if (fscale2 == 0)fscale2 = 1;
  1728. }
  1729. // ElementAt(10):化妆师/引导师2名称;
  1730. else if (strStaffName == pAryWaiter->ElementAt(i).ElementAt(10))
  1731. {
  1732. bMakeupArtist = TRUE;
  1733. // ElementAt(14):化妆师/引导师2折扣;
  1734. fscale2 = atof(pAryWaiter->ElementAt(i).ElementAt(14)) / 100.0;
  1735. }
  1736. // ElementAt(11):化妆师/引导师3名称;
  1737. else if (strStaffName == pAryWaiter->ElementAt(i).ElementAt(11))
  1738. {
  1739. bMakeupArtist = TRUE;
  1740. // ElementAt(15):化妆师/引导师3折扣;
  1741. fscale2 = atof(pAryWaiter->ElementAt(i).ElementAt(15)) / 100.0;
  1742. }
  1743. // ElementAt(12):化妆师/引导师4名称;
  1744. else if (strStaffName == pAryWaiter->ElementAt(i).ElementAt(12))
  1745. {
  1746. bMakeupArtist = TRUE;
  1747. // ElementAt(16):化妆师/引导师4折扣;
  1748. fscale2 = atof(pAryWaiter->ElementAt(i).ElementAt(16)) / 100.0;
  1749. }
  1750. return;
  1751. }
  1752. }
  1753. return;
  1754. }
  1755. void IsWaiter3(IN CString strOrderNum, IN CString strStaffName, CArray<CStringArray, CStringArray>*pAryWaiter, IN BOOL &bPhotographer, IN BOOL &bMakeupArtist, float &fscale1, float &fscale2)
  1756. {
  1757. bPhotographer = bMakeupArtist = FALSE;
  1758. for (int i = 0; i < pAryWaiter->GetSize(); i++)
  1759. {
  1760. // ElementAt(0):订单号;
  1761. if (strOrderNum == pAryWaiter->ElementAt(i).ElementAt(0))
  1762. {
  1763. // ElementAt(17):门市1姓名;
  1764. if (strStaffName == pAryWaiter->ElementAt(i).ElementAt(17))
  1765. {
  1766. bPhotographer = TRUE;
  1767. // ElementAt(19):门市1折扣;
  1768. fscale1 = atof(pAryWaiter->ElementAt(i).ElementAt(19)) / 100.0;
  1769. if (fscale1 == 0)fscale1 = 1;
  1770. }
  1771. // ElementAt(18):门市2姓名;
  1772. if (strStaffName == pAryWaiter->ElementAt(i).ElementAt(18))
  1773. {
  1774. bMakeupArtist = TRUE;
  1775. // ElementAt(20):门市1折扣;
  1776. fscale2 = atof(pAryWaiter->ElementAt(i).ElementAt(20)) / 100.0;
  1777. }
  1778. return;
  1779. }
  1780. }
  1781. return;
  1782. }
  1783. //------------------------------------------------------------------------------
  1784. // Remark by Jeff;
  1785. // 函数:CheckPhoneType
  1786. // 描述:判断手机号属于哪个运营商的;
  1787. // 参数:
  1788. // phoneno: 欲判断的手机号;
  1789. //
  1790. // 返回:返回0表示移动; 1表示联通; 2表示电信; 3表示小灵通; -1表示未知的;
  1791. //
  1792. // 注意:
  1793. // 移动:
  1794. // 139, 138, 137, 136, 135, 134, 159, 158, 152, 151, 150, 157, 188, 187, 144
  1795. // 联通:
  1796. // 130, 131, 132, 155, 156, 186, 185
  1797. // 电信 :
  1798. // 133, 153, 189, 180, 181, 173
  1799. //------------------------------------------------------------------------------
  1800. int CheckPhoneType(CString &phoneno)
  1801. {
  1802. if (phoneno.IsEmpty())
  1803. return -1;
  1804. int i = 0;
  1805. for ( i = 0; i < phoneno.GetLength(); i++)
  1806. {
  1807. if (phoneno.GetAt(i) < '0' || phoneno.GetAt(i) > '9')return -1;
  1808. }
  1809. if (phoneno.GetAt(0) == '1')
  1810. {
  1811. if (phoneno.GetLength() != 11)
  1812. return -1;
  1813. int mobile[] = { 139, 138, 137, 136, 135, 134, 159, 158, 152, 151, 150, 157, 188, 187, 144, 182, 147, 183, 184, 178 };
  1814. int unicom[] = { 130, 131, 132, 155, 156, 186, 185, 176 };
  1815. int telecom[] = { 133, 153, 189, 180, 181, 177, 173 };
  1816. int others[] = { 170,171,172,174,175,176,178,179 };
  1817. for (i = 0; i < sizeof(mobile) / sizeof(int); i++)
  1818. {
  1819. if (mobile[i] == atoi(phoneno.Left(3)))
  1820. {
  1821. return 0;
  1822. }
  1823. }
  1824. for (i = 0; i < sizeof(unicom) / sizeof(int); i++)
  1825. {
  1826. if (unicom[i] == atoi(phoneno.Left(3)))
  1827. {
  1828. return 1;
  1829. }
  1830. }
  1831. for (i = 0; i < sizeof(telecom) / sizeof(int); i++)
  1832. {
  1833. if (telecom[i] == atoi(phoneno.Left(3)))
  1834. {
  1835. return 2;
  1836. }
  1837. }
  1838. for (i = 0; i < sizeof(others)/sizeof(int);i++)
  1839. {
  1840. if ( others[i] == atoi((phoneno.Left(3))))
  1841. {
  1842. return 3;
  1843. }
  1844. }
  1845. return -1;
  1846. }
  1847. return -1;
  1848. }
  1849. /************************************************************************/
  1850. /*
  1851. 函数:CheckDateOK
  1852. 描述:判断日期有效性;
  1853. 参数:
  1854. IN: str 要判断的日期;
  1855. IN: bLunanr 是否是农历日期;
  1856. 返回:
  1857. 日期有效返回TRUE;
  1858. 要求:
  1859. 注意:
  1860. 修改:Jeff
  1861. 日期:2015-04-28
  1862. 内容:添加日期有效性判断,同时支持农历日期;
  1863. */
  1864. /************************************************************************/
  1865. BOOL CheckDateOK(IN CString &str, IN CONST BOOL &bLunanr)
  1866. {
  1867. if (str.IsEmpty())return 1;
  1868. CString tip;
  1869. int i;
  1870. CString demo = CTime::GetCurrentTime().Format("%Y-%m-%d");
  1871. if (str.GetLength() != demo.GetLength())
  1872. goto ll;
  1873. //2009-01-01
  1874. if (str.GetAt(4) != '-')
  1875. goto ll;
  1876. if (str.GetAt(7) != '-')
  1877. goto ll;
  1878. for (i = 0; i < str.GetLength(); i++)
  1879. {
  1880. if (i == 4 || i == 7)continue;
  1881. if (str.GetAt(i) < '0' || str.GetAt(i) > '9')
  1882. goto ll;
  1883. }
  1884. #if 1
  1885. if (!bLunanr)
  1886. return IsValidDate(str);
  1887. else
  1888. return IsValidLunanrDate(str);
  1889. #else
  1890. return 1;
  1891. #endif
  1892. ll:
  1893. tip.Format("日期:%s格式错误!\r\n样板:%s", str, demo);
  1894. AfxMessageBox(tip, MB_ICONSTOP);
  1895. return 0;
  1896. }
  1897. BOOL CheckBadWords(CString str, BOOL bMsg)
  1898. {
  1899. CString badwords[165] = { \
  1900. "【call5.me】", \
  1901. "您可拨020", \
  1902. "88btt.com热线400611", \
  1903. "400678165", \
  1904. "海王星", \
  1905. "博天堂", \
  1906. "十八大", \
  1907. "钓鱼岛", \
  1908. "无限次数提款", \
  1909. "广东地和", \
  1910. "利来", \
  1911. "抢劫", \
  1912. "fa lun", \
  1913. "强奸", \
  1914. "dafa", \
  1915. "falun", \
  1916. "SIM卡抽奖", \
  1917. "罢工", \
  1918. "罢课", \
  1919. "暴乱", \
  1920. "婊子", \
  1921. "操你", \
  1922. "操你娘", \
  1923. "蠢猪", \
  1924. "达赖", \
  1925. "打倒", \
  1926. "大法", \
  1927. "大纪元", \
  1928. "弹药", \
  1929. "钓鱼岛", \
  1930. "东突", \
  1931. "东突厥斯坦伊斯兰运动", \
  1932. "发抡", \
  1933. "发仑", \
  1934. "发伦", \
  1935. "发囵", \
  1936. "发沦", \
  1937. "发纶", \
  1938. "发轮", \
  1939. "发论", \
  1940. "法 轮 功", \
  1941. "法.轮.功", \
  1942. "法抡", \
  1943. "法仑", \
  1944. "法伦", \
  1945. "法囵", \
  1946. "法沦", \
  1947. "法纶", \
  1948. "法轮", \
  1949. "法论", \
  1950. "反革命", \
  1951. "反日", \
  1952. "分裂", \
  1953. "干你娘", \
  1954. "功友", \
  1955. "古怪歌", \
  1956. "国研新闻邮件", \
  1957. "黑庄", \
  1958. "宏志", \
  1959. "洪志", \
  1960. "胡锦涛", \
  1961. "鸡巴", \
  1962. "鸡毛信文汇", \
  1963. "妓女", \
  1964. "简鸿章", \
  1965. "江八点", \
  1966. "江独裁", \
  1967. "江泽民", \
  1968. "疆独", \
  1969. "教徒", \
  1970. "锦涛", \
  1971. "靖国神社", \
  1972. "九、评", \
  1973. "九.评", \
  1974. "九码", \
  1975. "九-评", \
  1976. "拉丹", \
  1977. "拉登", \
  1978. "李鹏", \
  1979. "联总之声传单", \
  1980. "灵动卡", \
  1981. "六合彩", \
  1982. "六码", \
  1983. "吕秀莲", \
  1984. "绿色环保手机", \
  1985. "美国之音", \
  1986. "猛料", \
  1987. "迷药", \
  1988. "民运", \
  1989. "民猪", \
  1990. "嫖娼", \
  1991. "迫害", \
  1992. "枪支", \
  1993. "强奸", \
  1994. "窃听器", \
  1995. "人民报", \
  1996. "人民报讯", \
  1997. "人民大众时事参考", \
  1998. "人民内情真相", \
  1999. "人民真实报道", \
  2000. "人权", \
  2001. "日你妈", \
  2002. "日他", \
  2003. "三码", \
  2004. "三陪", \
  2005. "色情", \
  2006. "傻B", \
  2007. "涉日", \
  2008. "十六大", \
  2009. "示威", \
  2010. "他妈的", \
  2011. "台*湾", \
  2012. "特等奖", \
  2013. "天葬", \
  2014. "突厥斯坦", \
  2015. "推翻", \
  2016. "王八蛋", \
  2017. "温家宝", \
  2018. "无能", \
  2019. "香港总部", \
  2020. "小鸡鸡", \
  2021. "新华举报", \
  2022. "新华内情", \
  2023. "新闻封锁", \
  2024. "畜生", \
  2025. "玄`机", \
  2026. "压迫", \
  2027. "淫秽", \
  2028. "银行联合管理局", \
  2029. "印尼伊斯兰祈祷团", \
  2030. "游行", \
  2031. "舆论", \
  2032. "造反", \
  2033. "真善忍", \
  2034. "镇压", \
  2035. "正法", \
  2036. "政变", \
  2037. "政治风波", \
  2038. "中俄边界新约", \
  2039. "中国银联", \
  2040. "中华民国", \
  2041. "中奖", \
  2042. "朱容基", \
  2043. "自焚", \
  2044. "自由运动", \
  2045. "达赖", \
  2046. "套牌", \
  2047. "情妇", \
  2048. "监听", \
  2049. "巴南电信", \
  2050. "合川分公司", \
  2051. "合川电信", \
  2052. "死光", \
  2053. "116114", \
  2054. "北京宝诚", \
  2055. "华盛投资", \
  2056. "名门国际", \
  2057. "利博", \
  2058. "赤橙黄绿", \
  2059. "免佣BJL首发", \
  2060. "洗*码优惠", \
  2061. "【俱乐部】", \
  2062. "18266381922", \
  2063. "回拨卡", \
  2064. "号码百事通推出短信订机票!实时" };
  2065. for (int i = 0; i < 165; i++)
  2066. {
  2067. g_temp = badwords[i];
  2068. if (str.Find(g_temp) != -1)
  2069. {
  2070. // AfxMessageBox("信息服务商禁止的非法字符:("+g_temp+")希望您谅解!");
  2071. return 0;
  2072. }
  2073. }
  2074. return 1;
  2075. }
  2076. ///目录是否存在的检查: 支持网络文件夹
  2077. bool CheckFolderFileExist(CString &strPath)
  2078. {
  2079. CString path = strPath;
  2080. CFile fp;
  2081. if (fp.Open(path, CFile::modeRead))
  2082. {
  2083. fp.Close();
  2084. return 1;
  2085. }
  2086. if (strPath.Right(1) != "\\")
  2087. path += "\\";
  2088. path += "zaqw1234.dat";
  2089. DeleteFile(path); // 删除zaqw1234.dat文件;
  2090. if (fp.Open(path, CFile::modeCreate) == 0)
  2091. return 0;
  2092. fp.Close();
  2093. if (PathFileExists(path)) // Jeff 删除文件前判断文件是否存在;
  2094. ::DeleteFile(path); // 删除zaqw1234.dat文件;
  2095. return 1;
  2096. }
  2097. int FindArray(CStringArray *pArray, const CString &Str)
  2098. {
  2099. for (int i = 0; i < pArray->GetSize(); i++)
  2100. {
  2101. if (pArray->ElementAt(i) == Str)
  2102. return i;
  2103. }
  2104. return -1;
  2105. }
  2106. void FillLength(CString &str, int length)
  2107. {
  2108. while (str.GetLength() < length)
  2109. str += " ";
  2110. }
  2111. // 查找不到年历史数据库则返回-1;
  2112. int GetYearPos(int year)
  2113. {
  2114. for (int i = 0; i < g_hisyeararray.GetSize(); i++)
  2115. {
  2116. if (year == atoi(g_hisyeararray.ElementAt(i).ElementAt(0)))
  2117. return i;
  2118. }
  2119. return -1;
  2120. }
  2121. /************************************************************************/
  2122. /*
  2123. 函数:GIsHalfHZ
  2124. 描述:判断输入的字符串最后一个字符是否是汉字;
  2125. 参数:
  2126. 返回:如果是一个完整的汉字,返回TRUE。否则返回FALSE;
  2127. */
  2128. /************************************************************************/
  2129. BOOL GIsHalfHZ(const CString &str)
  2130. {
  2131. #if 0 // 有问题的判断,当含有一个英文字母时;
  2132. int len = str.GetLength();
  2133. BOOL IsHalf = FALSE;
  2134. for (int i = 0; i < len; i++)
  2135. {
  2136. if (str.GetAt(i) < 0) IsHalf = !IsHalf;
  2137. }
  2138. return IsHalf;
  2139. #else
  2140. #if 1
  2141. INT nLength = str.GetLength();
  2142. BOOL IsHalf = FALSE;
  2143. for ( INT i = 0; i < nLength; )
  2144. {
  2145. if ( str.GetAt(i) < 0 )
  2146. {
  2147. i += 2;
  2148. if ( i > nLength )
  2149. IsHalf = TRUE;
  2150. }
  2151. else
  2152. {
  2153. i++;
  2154. }
  2155. }
  2156. return IsHalf;
  2157. #else
  2158. INT nLength = str.GetLength();
  2159. INT wSize = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
  2160. WCHAR *szStr = new WCHAR[wSize];
  2161. INT nnnnn = 0;
  2162. INT nCount = 0;
  2163. INT convresult = MultiByteToWideChar(CP_ACP, 0, str, -1, szStr, wSize);
  2164. for ( INT i = 0; i < wSize; i++ )
  2165. {
  2166. if ( (szStr[i] >= 0x2E80 && szStr[i] <= 0xFE4F) || ( szStr[i] >= 0xFF00 && szStr[i] <= 0xFFEF) )
  2167. nCount++;
  2168. else
  2169. nnnnn++;
  2170. }
  2171. return !(nCount%2);
  2172. #endif
  2173. #endif
  2174. }
  2175. void WriteTitle(CString str)
  2176. {
  2177. g_title = str;
  2178. CStdioFile fp;
  2179. fp.Open(g_mainpath + "\\title.txt", CFile::modeWrite | CFile::modeCreate);
  2180. fp.WriteString(str);
  2181. fp.Close();
  2182. }
  2183. CString GetIP(CString branch)
  2184. {
  2185. for (int i = 0; i < g_brancharray.GetSize(); i++)
  2186. {
  2187. if (g_domain == g_brancharray.ElementAt(i).ElementAt(2))
  2188. {
  2189. //if(g_serverbak.Find (".ly.com")!=-1)
  2190. return g_server;
  2191. CString ip = g_serverbak;
  2192. MyGetIPByName(ip);
  2193. return ip;
  2194. }
  2195. if (branch == g_brancharray.ElementAt(i).ElementAt(0))
  2196. {
  2197. return g_brancharray.ElementAt(i).ElementAt(1);
  2198. }
  2199. }
  2200. return "";
  2201. }
  2202. CString GetBranchIPbyId( IN LPCTSTR lpStrBranchId )
  2203. {
  2204. if ( g_domain.CompareNoCase(lpStrBranchId) == 0 )
  2205. {
  2206. return g_server;
  2207. }
  2208. CString strBranchIP = _T("");
  2209. INT nCount = g_brancharray.GetSize();
  2210. for ( int i = 0; i < nCount; i++ )
  2211. {
  2212. if ( g_brancharray.ElementAt(i).ElementAt(2).CompareNoCase(lpStrBranchId) == 0 )
  2213. {
  2214. strBranchIP = g_brancharray.ElementAt(i).ElementAt(1);
  2215. break;
  2216. }
  2217. }
  2218. return strBranchIP;
  2219. }
  2220. CString GetBranchNamebyId( IN LPCTSTR lpStrBranchId )
  2221. {
  2222. if ( g_domain.CompareNoCase(lpStrBranchId) == 0 )
  2223. {
  2224. return _T("");
  2225. }
  2226. CString strBranchName = _T("");
  2227. INT nCount = g_brancharray.GetSize();
  2228. for ( int i = 0; i < nCount; i++ )
  2229. {
  2230. if ( g_brancharray.ElementAt(i).ElementAt(2).CompareNoCase(lpStrBranchId) == 0 )
  2231. {
  2232. strBranchName = g_brancharray.ElementAt(i).ElementAt(0);
  2233. break;
  2234. }
  2235. }
  2236. return strBranchName;
  2237. }
  2238. BOOL IsHanZi(CString str)
  2239. {
  2240. TBYTE ucHigh, ucLow;
  2241. for (int i = 0; i < str.GetLength(); i++)
  2242. {
  2243. if ((TBYTE)str[i] < 0x80)
  2244. {
  2245. continue;
  2246. }
  2247. ucHigh = (TBYTE)str[i];
  2248. ucLow = (TBYTE)str[i + 1];
  2249. if (ucHigh < 0xa1 || ucLow < 0xa1)
  2250. {
  2251. continue;
  2252. }
  2253. return 1;
  2254. }
  2255. return 0;
  2256. }
  2257. int GetType(CString str)
  2258. {
  2259. if (IsHanZi(str))return 0;
  2260. BOOL bDigit = 1;
  2261. BOOL bAlpha = 1;
  2262. for (int i = 0; i < str.GetLength(); i++)
  2263. {
  2264. if (!::isdigit(str.GetAt(i)))
  2265. bDigit = 0;
  2266. if (!((str.GetAt(i) <= 'z' && str.GetAt(i) >= 'a') || (str.GetAt(i) <= 'Z' && str.GetAt(i) >= 'A')))
  2267. //else if(!::isalpha ( ((unsigned char)str.GetAt (i))))
  2268. bAlpha = 0;
  2269. if (bDigit == 0 && bAlpha == 0)return 0;
  2270. }
  2271. if (bDigit)
  2272. {
  2273. return 0;
  2274. }
  2275. else if (bAlpha)
  2276. {
  2277. return 2;
  2278. }
  2279. else
  2280. return 0;
  2281. }
  2282. CString FilterBZ(CString &bz)
  2283. {
  2284. bz.Replace("'", "");
  2285. if (bz.GetLength() > 1023)
  2286. {
  2287. AfxMessageBox("文字太长, 字符串将被截取!", MB_ICONSTOP);
  2288. bz = bz.Left(1023);
  2289. }
  2290. return bz;
  2291. }
  2292. // GetWidth()的长度与CRect的长度是不一样的单位值,需要转换适合的比例;(一个是图片的像素尺寸,一个DC的大小尺寸)
  2293. // 将图片尺寸与设备尺寸进行转换适合的比例;
  2294. void RectFitDes(int width, int height, CRect &rc)
  2295. {
  2296. try
  2297. {
  2298. if (width == 0 || height == 0)return;
  2299. // 图片长宽比例;
  2300. float fscale = (float)width / (float)height;
  2301. // 设备长宽比例;
  2302. float rcscale = ((float)rc.Width()) / ((float)rc.Height());
  2303. int rcwid = rc.Width();
  2304. int rchei = rc.Height();
  2305. int dt = 0;
  2306. // Jeff.如果设备长宽比例 < 图片长宽比例;(即相同长度下,高越大比例值越小,所以此时图片尺寸 与 显示设备的尺寸相比,要显得更长)
  2307. if (rcscale < fscale)
  2308. {
  2309. // Jeff.remarks
  2310. // 调整显示设备的大小,以使之能容纳图片尺寸;(即长宽比例上,要大于或等于图片的长宽比例)
  2311. // 所以有两种方法使得 rcscale >= fscale 表达式成立:
  2312. // -----------------------------------------------
  2313. // 方法1:显示设备宽加x值,计算出下面表达式x的值即可
  2314. // (rc.Width()+x) / rc.Height() >= width/height;
  2315. // 方法2:显示设备高减x值,计算出下面表达式x的值即可
  2316. // (rc.Width()) / (rc.Height()-x) >= width/height;
  2317. //------------------------------------------------
  2318. // 两种方法的最后表达式为:
  2319. // x >= rc.Height() - rcWidth()*(height/width);
  2320. // 即 x >= rc.Height() - rcWidth()/fscale;
  2321. //------------------------------------------------
  2322. dt = (rchei - rcwid / fscale) / 2;
  2323. rc.top += dt;
  2324. rc.bottom -= dt;
  2325. }
  2326. else
  2327. {
  2328. dt = (rcwid - rchei*fscale) / 2;
  2329. rc.left += dt;
  2330. rc.right -= dt;
  2331. }
  2332. }
  2333. catch (...)
  2334. {
  2335. }
  2336. }
  2337. BOOL IsHasRights(int pos) // Jeff,无意义的函数;
  2338. {
  2339. return 1;
  2340. if (g_user.rights.GetLength() > pos)
  2341. {
  2342. BOOL ret = atoi(g_user.rights.Mid(pos, 1));
  2343. if (ret == 0)AfxMessageBox("没有相关权限!", MB_ICONINFORMATION);
  2344. return ret;
  2345. }
  2346. AfxMessageBox("没有相关权限!", MB_ICONINFORMATION);
  2347. return 0;
  2348. }
  2349. BOOL IsHasRights2(int pos)// Jeff,无意义的函数;
  2350. {
  2351. return 1;
  2352. if (g_user.rights.GetLength() > pos)
  2353. {
  2354. BOOL ret = atoi(g_user.rights.Mid(pos, 1));
  2355. return ret;
  2356. }
  2357. return 0;
  2358. }
  2359. BOOL IsHasRightsnew(int pos)
  2360. {
  2361. if (g_user.rights.GetLength() > pos)
  2362. {
  2363. BOOL ret = atoi(g_user.rights.Mid(pos, 1));
  2364. if (ret == 0)
  2365. AfxMessageBox("没有相关权限! 请与系统管理员联系!", MB_ICONINFORMATION);
  2366. return ret;
  2367. }
  2368. AfxMessageBox("没有相关权限! 请与系统管理员联系!", MB_ICONINFORMATION);
  2369. return 0;
  2370. }
  2371. BOOL IsHasRights2new(int pos)
  2372. {
  2373. if (g_user.rights.GetLength() > pos)
  2374. {
  2375. BOOL ret = atoi(g_user.rights.Mid(pos, 1));
  2376. return ret;
  2377. }
  2378. return 0;
  2379. }
  2380. BOOL IsHasRightsnew2(int pos, CString rights)
  2381. {
  2382. if (rights.GetLength() > pos)
  2383. {
  2384. BOOL ret = atoi(rights.Mid(pos, 1));
  2385. if (ret == 0)AfxMessageBox("没有相关权限! 请与系统管理员联系!", MB_ICONINFORMATION);
  2386. return ret;
  2387. }
  2388. AfxMessageBox("没有相关权限! 请与系统管理员联系!", MB_ICONINFORMATION);
  2389. return 0;
  2390. }
  2391. /********************************************************************************************
  2392. /* Syntax
  2393. /* void FirstLetter(int nCode, CString& strLetter)
  2394. /* Remarks:
  2395. /* Get the first letter of pinyin according to specified Chinese character code.
  2396. /* Parameters:
  2397. /* nCode - the code of the chinese character.
  2398. /* strLetter - a CString object that is to receive the string of the first letter.
  2399. /* Return Values:
  2400. /* None.
  2401. /* Author:
  2402. /* lixiaosan
  2403. /* Create Date:
  2404. /* 05-26-2006
  2405. /********************************************************************************************/
  2406. void FirstLetter(int nCode, CString& strLetter)
  2407. {
  2408. if (nCode >= 1601 && nCode < 1637) strLetter = _T("A");
  2409. if (nCode >= 1637 && nCode < 1833) strLetter = _T("B");
  2410. if (nCode >= 1833 && nCode < 2078) strLetter = _T("C");
  2411. if (nCode >= 2078 && nCode < 2274) strLetter = _T("D");
  2412. if (nCode >= 2274 && nCode < 2302) strLetter = _T("E");
  2413. if (nCode >= 2302 && nCode < 2433) strLetter = _T("F");
  2414. if (nCode >= 2433 && nCode < 2594) strLetter = _T("G");
  2415. if (nCode >= 2594 && nCode < 2787) strLetter = _T("H");
  2416. if (nCode >= 2787 && nCode < 3106) strLetter = _T("J");
  2417. if (nCode >= 3106 && nCode < 3212) strLetter = _T("K");
  2418. if (nCode >= 3212 && nCode < 3472) strLetter = _T("L");
  2419. if (nCode >= 3472 && nCode < 3635) strLetter = _T("M");
  2420. if (nCode >= 3635 && nCode < 3722) strLetter = _T("N");
  2421. if (nCode >= 3722 && nCode < 3730) strLetter = _T("O");
  2422. if (nCode >= 3730 && nCode < 3858) strLetter = _T("P");
  2423. if (nCode >= 3858 && nCode < 4027) strLetter = _T("Q");
  2424. if (nCode >= 4027 && nCode < 4086) strLetter = _T("R");
  2425. if (nCode >= 4086 && nCode < 4390) strLetter = _T("S");
  2426. if (nCode >= 4390 && nCode < 4558) strLetter = _T("T");
  2427. if (nCode >= 4558 && nCode < 4684) strLetter = _T("W");
  2428. if (nCode >= 4684 && nCode < 4925) strLetter = _T("X");
  2429. if (nCode >= 4925 && nCode < 5249) strLetter = _T("Y");
  2430. if (nCode >= 5249 && nCode < 5590) strLetter = _T("Z");
  2431. }
  2432. /********************************************************************************************
  2433. /* Syntax
  2434. /* GetFirstLetter(CString strName, CString& strFirstLetter)
  2435. /* Remarks:
  2436. /* Get the first letter of pinyin according to specified Chinese character.
  2437. /* Parameters:
  2438. /* strName - a CString object that is to be parsed.
  2439. /* strFirstLetter - a CString object that is to receive the string of the first letter.
  2440. /* Return Values:
  2441. /* None.
  2442. /* Author:
  2443. /* lixiaosan
  2444. /* Create Date:
  2445. /* 05-26-2006
  2446. /********************************************************************************************/
  2447. void GetFirstLetter(CString strName, CString& strFirstLetter)
  2448. {
  2449. TBYTE ucHigh, ucLow;
  2450. int nCode;
  2451. CString strRet;
  2452. strFirstLetter.Empty();
  2453. for (int i = 0; i < strName.GetLength(); i++)
  2454. {
  2455. if ((TBYTE)strName[i] < 0x80)
  2456. {
  2457. strRet = strName.Mid(i, 1);
  2458. strRet.MakeUpper();
  2459. strFirstLetter += strRet;
  2460. continue;
  2461. }
  2462. ucHigh = (TBYTE)strName[i];
  2463. ucLow = (TBYTE)strName[i + 1];
  2464. if (ucHigh < 0xa1 || ucLow < 0xa1)
  2465. continue;
  2466. else
  2467. nCode = (ucHigh - 0xa0) * 100 + ucLow - 0xa0;
  2468. FirstLetter(nCode, strRet);
  2469. strFirstLetter += strRet;
  2470. i++;
  2471. }
  2472. }
  2473. CString newGUID()
  2474. {
  2475. CString str;
  2476. GUID guid;
  2477. CoInitialize(NULL);
  2478. if (S_OK == ::CoCreateGuid(&guid))
  2479. {
  2480. str.Format(
  2481. "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
  2482. guid.Data1,
  2483. guid.Data2,
  2484. guid.Data3,
  2485. guid.Data4[0], guid.Data4[1],
  2486. guid.Data4[2], guid.Data4[3],
  2487. guid.Data4[4], guid.Data4[5],
  2488. guid.Data4[6], guid.Data4[7]);
  2489. }
  2490. CoUninitialize();
  2491. return str.Left(28);
  2492. }
  2493. CString GetNameFromDomain(CString domain)
  2494. {
  2495. for (int i = 0; i < g_brancharray.GetSize(); i++)
  2496. {
  2497. if (domain == g_brancharray.ElementAt(i).ElementAt(2))
  2498. {
  2499. return g_brancharray.ElementAt(i).ElementAt(0);
  2500. }
  2501. }
  2502. return "";
  2503. }
  2504. void ConvertToPrice(CString &str)
  2505. {
  2506. if (str.Find('.') == -1)return;
  2507. str.TrimRight('0');
  2508. str.TrimRight('.');
  2509. }
  2510. int GetLengthEx(CString str)
  2511. {
  2512. wchar_t wstr[500];
  2513. int k = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, strlen(str), wstr, 500);
  2514. return k;
  2515. }
  2516. inline int MultiByteLengthConvertToWideCharLength(/*LPCSTR*/LPCCH lpString)
  2517. {
  2518. return MultiByteToWideChar(CP_ACP, 0, lpString, -1, NULL, 0);
  2519. }
  2520. //判断字符是否是数字(0 – 9)
  2521. BOOL myisdigit(CString str)
  2522. {
  2523. for (int i = 0; i < str.GetLength(); i++)
  2524. {
  2525. if (!::isdigit(str.GetAt(i)))
  2526. return 0;
  2527. }
  2528. return 1;
  2529. }
  2530. DWORD FindAppProcessID(CString path)
  2531. {
  2532. try
  2533. {
  2534. HANDLE handle = ::CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
  2535. PROCESSENTRY32 Info;
  2536. Info.dwSize = sizeof(PROCESSENTRY32);
  2537. path.MakeLower();
  2538. if (::Process32First(handle, &Info))
  2539. {
  2540. do
  2541. {
  2542. CString ss = Info.szExeFile;
  2543. ss.MakeLower();
  2544. if (ss.Find(path) != -1 || (!ss.CompareNoCase(path)))
  2545. {
  2546. ::CloseHandle(handle);
  2547. return Info.th32ProcessID;
  2548. }
  2549. } while (::Process32Next(handle, &Info));
  2550. ::CloseHandle(handle);
  2551. }
  2552. return -1;
  2553. }
  2554. catch (...)
  2555. {
  2556. }
  2557. }
  2558. BOOL isInnerIP(DWORD a_ip) // Jeff.判断是否是内网?
  2559. {
  2560. BOOL bValid = 0;
  2561. if ((a_ip >> 24 == 0xa) || (a_ip >> 16 == 0xc0a8) || (a_ip >> 22 == 0x2b0))
  2562. {
  2563. bValid = 1;
  2564. }
  2565. return bValid;
  2566. }
  2567. void MyGetIPByName2(CString &name)
  2568. {
  2569. CString strIP = name;
  2570. name.Empty();
  2571. DWORD dwServerIP = 0;
  2572. HOSTENT *host = gethostbyname(strIP);
  2573. struct in_addr addr;
  2574. if (host != NULL)
  2575. {
  2576. for (int i = 0; host->h_addr_list[i] != NULL; i++)
  2577. {
  2578. memset(&addr, 0, sizeof(addr));
  2579. memcpy(&addr.S_un.S_addr, host->h_addr_list[i], host->h_length);
  2580. dwServerIP = ntohl(addr.S_un.S_addr);
  2581. BYTE* pIP = (BYTE*)&dwServerIP;
  2582. name.Format(_T("%d.%d.%d.%d"), pIP[3], pIP[2], pIP[1], pIP[0]);
  2583. }
  2584. }
  2585. }
  2586. void MyGetIPByName(CString &name) // Jeff.根据计算机名称获取IP地址;
  2587. {
  2588. g_serverarray.RemoveAll();
  2589. CString strIP = name;
  2590. name.Empty();
  2591. DWORD dwServerIP = 0;
  2592. HOSTENT *host = gethostbyname(strIP); // Jeff.所有本机的网络适配器;
  2593. struct in_addr addr;
  2594. if (host != NULL)
  2595. {
  2596. // Jeff.遍历本机所有适配器的IP地址;
  2597. for (int i = 0; host->h_addr_list[i] != NULL; i++)
  2598. {
  2599. memset(&addr, 0, sizeof(addr));
  2600. memcpy(&addr.S_un.S_addr, host->h_addr_list[i], host->h_length);
  2601. dwServerIP = ntohl(addr.S_un.S_addr);
  2602. BYTE* pIP = (BYTE*)&dwServerIP;
  2603. name.Format(_T("%d.%d.%d.%d"), pIP[3], pIP[2], pIP[1], pIP[0]);
  2604. g_serverarray.Add(name);
  2605. }
  2606. }
  2607. while (g_serverarray.GetSize() > 1)
  2608. {
  2609. CString name;
  2610. BOOL bFind = 0;
  2611. for (int i = 0; i < g_serverarray.GetSize(); i++)
  2612. {
  2613. DWORD dwServerIP = inet_addr(g_serverarray.ElementAt(i));
  2614. dwServerIP = htonl(dwServerIP);//加了才正确
  2615. if (isInnerIP(dwServerIP) == 0)
  2616. {
  2617. g_serverarray.RemoveAt(i);
  2618. bFind = 1;
  2619. break;
  2620. }
  2621. }
  2622. if (bFind == 0)
  2623. {
  2624. break;
  2625. }
  2626. }
  2627. }
  2628. int IsExistFolder(char *szPath)//可判断文件夹和文件的存在;
  2629. {
  2630. if ((_access(szPath, 0)) != -1)
  2631. {
  2632. if ((_access(szPath, 2)) != -1)
  2633. {
  2634. return 1;
  2635. }
  2636. }
  2637. else
  2638. {
  2639. return -1;
  2640. }
  2641. }
  2642. CString GetW(CString str)
  2643. {
  2644. int x = atoi(str);
  2645. if (x > 9999)
  2646. {
  2647. str.Format("%d", x);
  2648. str = str.Right(5);
  2649. str = str.Left(1);
  2650. return str;
  2651. }
  2652. return "";
  2653. }
  2654. CString GetK(CString str)
  2655. {
  2656. int x = atoi(str);
  2657. if (x > 999)
  2658. {
  2659. str.Format("%d", x);
  2660. str = str.Right(4);
  2661. str = str.Left(1);
  2662. return str;
  2663. }
  2664. return "";
  2665. }
  2666. CString GetB(CString str)
  2667. {
  2668. int x = atoi(str);
  2669. if (x > 99)
  2670. {
  2671. str.Format("%d", x);
  2672. str = str.Right(3);
  2673. str = str.Left(1);
  2674. return str;
  2675. }
  2676. return "";
  2677. }
  2678. CString GetS(CString str)
  2679. {
  2680. int x = atoi(str);
  2681. if (x > 9)
  2682. {
  2683. str.Format("%d", x);
  2684. str = str.Right(2);
  2685. str = str.Left(1);
  2686. return str;
  2687. }
  2688. return "";
  2689. }
  2690. CString GetG(CString str)
  2691. {
  2692. int x = atoi(str);
  2693. if (x > 0)
  2694. {
  2695. str.Format("%d", x);
  2696. str = str.Right(1);
  2697. return str;
  2698. }
  2699. return "";
  2700. }
  2701. CString GetHMoney(CString str)
  2702. {
  2703. if (str.IsEmpty())return "";
  2704. if (str == "0")return "零";
  2705. if (atoi(str) < 1 || atoi(str) > 9)return "";
  2706. CString ret[] = { "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
  2707. return ret[atoi(str) - 1];
  2708. }
  2709. BOOL CheckDateOK2(CString str)
  2710. {
  2711. if (str.IsEmpty())return 0;
  2712. CString tip;
  2713. int i;
  2714. CString demo = CTime::GetCurrentTime().Format("%Y-%m-%d");
  2715. if (str.GetLength() != demo.GetLength())
  2716. goto ll;
  2717. //2009-01-01
  2718. if (str.GetAt(4) != '-')
  2719. goto ll;
  2720. if (str.GetAt(7) != '-')
  2721. goto ll;
  2722. for (i = 0; i < str.GetLength(); i++)
  2723. {
  2724. if (i == 4 || i == 7)continue;
  2725. if (str.GetAt(i) < '0' || str.GetAt(i) > '9')
  2726. goto ll;
  2727. }
  2728. return 1;
  2729. ll:
  2730. return 0;
  2731. }
  2732. CString GetDomainFromBranch(CString branch)
  2733. {
  2734. if (branch.IsEmpty())return "";
  2735. for (int i = 0; i < g_brancharray.GetSize(); i++)
  2736. {
  2737. if (branch == g_brancharray.ElementAt(i).ElementAt(0))
  2738. {
  2739. return g_brancharray.ElementAt(i).ElementAt(2);
  2740. }
  2741. }
  2742. return "";
  2743. }
  2744. CString GetBranchPhotoPath(CString branch)
  2745. {
  2746. if (branch.IsEmpty())return "";
  2747. for (int i = 0; i < g_brancharray.GetSize() - 1; i++)
  2748. {
  2749. if (branch == g_brancharray.ElementAt(i).ElementAt(0))
  2750. {
  2751. return "\\" + g_brancharray.ElementAt(i).ElementAt(2);
  2752. }
  2753. }
  2754. return "";
  2755. }
  2756. // 函数未进行参数验证,当date空时,出错;
  2757. CTime GetTmFromStr(CString date)
  2758. {
  2759. if ( date.IsEmpty() )
  2760. date = _T("1990-01-01");
  2761. try
  2762. {
  2763. CTime tm(atoi(date.Mid(0, 4)), atoi(date.Mid(5, 2)), atoi(date.Mid(8, 2)), 0, 0, 0);
  2764. CString ss;
  2765. ss.Format("%d-%d-%d", tm.GetYear(), tm.GetMonth(), tm.GetDay());
  2766. return tm;
  2767. }
  2768. catch (...)
  2769. {
  2770. date = "1980-01-01";
  2771. CTime tm(atoi(date.Mid(0, 4)), atoi(date.Mid(5, 2)), atoi(date.Mid(8, 2)), 0, 0, 0);
  2772. return tm;
  2773. }
  2774. }
  2775. //---------------------------------------------------------------------
  2776. // add by Jeff 2014.10.24
  2777. // 函数:全局函数lyfzCopyFileEx
  2778. // 描述:文件复制。
  2779. // 参数:
  2780. // lpExistingFileName:你要拷贝的源文件名;
  2781. // lpNewFileName: 你要拷贝的目标文件名;
  2782. // bFailIfExists: 如果目标已经存在,不拷贝(True)并重命名,覆盖目标(false)
  2783. // 返回:与CopyFile返回一致;
  2784. //---------------------------------------------------------------------
  2785. BOOL lyfzCopyFileEx(LPCTSTR lpExistingFileName, LPCTSTR lpNewFileName, const BOOL &bFailIfExists)
  2786. {
  2787. // 1.如果是覆盖选项;
  2788. if (!bFailIfExists)
  2789. return CopyFile(lpExistingFileName, lpNewFileName, bFailIfExists);
  2790. // 2.如果不是覆盖选项;
  2791. TCHAR szNewFileName[_MAX_PATH] = { 0 };
  2792. TCHAR szDrive[_MAX_DRIVE] = { 0 };
  2793. TCHAR szDir[_MAX_DIR] = { 0 };
  2794. TCHAR szFna[_MAX_FNAME] = { 0 };
  2795. TCHAR szExt[_MAX_EXT] = { 0 };
  2796. sprintf(szNewFileName, "%s", lpNewFileName);
  2797. _tsplitpath(szNewFileName, szDrive, szDir, szFna, szExt);
  2798. int nIndex = 1;
  2799. while (PathFileExists(szNewFileName))
  2800. {
  2801. sprintf(szNewFileName, "%s%s%s (%d)%s", szDrive, szDir, szFna, nIndex++, szExt);
  2802. }
  2803. return CopyFile(lpExistingFileName, szNewFileName, bFailIfExists);
  2804. }
  2805. //---------------------------------------------------------------------
  2806. // add by Jeff 2014.10.24
  2807. // 函数:全局函数lyfzImportImage,多字节版本,非UNICODE
  2808. // 描述:导入图片。
  2809. // 参数:
  2810. // lpDestDirectory: 文件导入的目标目录;
  2811. // strArrayOfImage: 要导入的图片文件数组;
  2812. // bFailIfExists: 如果目标已经存在,不拷贝(True)并重命名,覆盖目标(false)
  2813. // 返回:
  2814. //
  2815. // 说明:在调用lyfzImportImage前,需要对传递的参数进行有效性验证
  2816. // 1.验证形参lpDestDirectory对应的实参是否是有效的目录(有无创建目录的非法字符存在)
  2817. // 2.验证形参strArrayOfImage对应的实参数组是否大于0;
  2818. // 如果校验没有通过,应该拒绝调lyfzImportImage,以防止错误产生。
  2819. //---------------------------------------------------------------------
  2820. void lyfzImportImage(LPCTSTR lpDestDirectory, CStringArray &strArrayOfImage, const BOOL &bFailIfExists)
  2821. {
  2822. // 传递给lyfzCreateDirectory的参数规范化;
  2823. int nlen = strlen(lpDestDirectory);
  2824. TCHAR szNewFileName[_MAX_PATH] = { 0 };
  2825. TCHAR szTempDirectory[_MAX_PATH] = { 0 };
  2826. if (lpDestDirectory[nlen - 1] != '\\')
  2827. sprintf(szTempDirectory, "%s\\", lpDestDirectory);
  2828. else
  2829. sprintf(szTempDirectory, "%s", lpDestDirectory);
  2830. // 若目录或子目录不存在创建;
  2831. lyfzCreateDirectory(szTempDirectory);
  2832. // 遍历复制;
  2833. CString strImage;
  2834. INT_PTR nSize = strArrayOfImage.GetSize();
  2835. for (INT_PTR i = 0; i < nSize; i++)
  2836. {
  2837. strImage = strArrayOfImage.ElementAt(i);
  2838. strImage = strImage.Mid(strImage.ReverseFind('\\') + 1);
  2839. //strImage = strImage.Left(strImage.ReverseFind('.'));
  2840. sprintf(szNewFileName, "%s%s", szTempDirectory, strImage);
  2841. lyfzCopyFileEx(szNewFileName, strArrayOfImage.ElementAt(i), bFailIfExists);
  2842. }
  2843. }
  2844. //---------------------------------------------------------------------
  2845. // add by Jeff 2014.10.25
  2846. // 函数:全局函数lyfzCreateDirectory,多字节版本,非UNICODE
  2847. // 描述:创建目录及子目录文件夹;
  2848. // 参数:
  2849. // lpDestDirectory:目录,必须是"E:\lyfzdb\数据\"格式,目录最后必须有"\",否则最后一个子目录无法创建!
  2850. // 建议使用系统_tsplitpath来分隔目录,这样会保存最后一个"\"斜杠;
  2851. // 返回:成功创建返回TRUE;
  2852. //---------------------------------------------------------------------
  2853. BOOL lyfzCreateDirectory(LPCTSTR lpDestDirectory)
  2854. {
  2855. BOOL bExists = FALSE;
  2856. TCHAR szNewFileName[_MAX_PATH] = { 0 };
  2857. TCHAR szDrive[_MAX_DRIVE] = { 0 };
  2858. TCHAR szDir[_MAX_DIR] = { 0 };
  2859. TCHAR szFna[_MAX_FNAME] = { 0 };
  2860. TCHAR szExt[_MAX_EXT] = { 0 };
  2861. int nIndex = 0;
  2862. do
  2863. {
  2864. bExists = PathFileExists(lpDestDirectory);
  2865. if (!bExists)
  2866. {
  2867. memset(szDrive, 0, _MAX_DRIVE);
  2868. memset(szDir, 0, _MAX_DIR);
  2869. memset(szFna, 0, _MAX_FNAME);
  2870. memset(szExt, 0, _MAX_EXT);
  2871. lyfzSplitpath(lpDestDirectory, szDrive, szDir, ++nIndex);
  2872. sprintf(szNewFileName, _T("%s%s"), szDrive, szDir);
  2873. CreateDirectory(szNewFileName, NULL);
  2874. //if (FALSE == CreateDirectory(szNewFileName, NULL))
  2875. //{
  2876. //ShowSystemErrorInfo(CString("创建目录出错。"), GetLastError());
  2877. //return FALSE;
  2878. // continue;
  2879. //}
  2880. }
  2881. } while (!bExists);
  2882. return TRUE;
  2883. }
  2884. //---------------------------------------------------------------------
  2885. // add by Jeff 2014.10.24
  2886. // 函数:全局函数tSplitpath,多字节版本,非UNICODE
  2887. // 描述:类系统Windows C++运行库函数_tsplitpath。
  2888. // 参数:
  2889. //
  2890. // 返回:
  2891. //---------------------------------------------------------------------
  2892. void lyfzSplitpath(const char *path, char *drive, char *dir, const int &nTimes)
  2893. {
  2894. int nlen = strlen(path);
  2895. int i = 0;
  2896. int npoint = 0; // '.'
  2897. int nsprit = 0; // '\\'
  2898. int ncolon = 0; // ':'
  2899. int ntimes = -1;
  2900. while (nlen > i++)
  2901. {
  2902. if (path[i] == ':')
  2903. ncolon = i;
  2904. else if (path[i] == '\\')
  2905. {
  2906. if (nTimes == ntimes++) break;
  2907. nsprit = i;
  2908. }
  2909. }
  2910. memcpy(drive, path, ncolon + 1);
  2911. memcpy(dir, &path[ncolon + 1], nsprit - ncolon);
  2912. }
  2913. //---------------------------------------------------------------------
  2914. // Jeff add 2014.06.23;
  2915. // 函数:ShowErrorInfo
  2916. // 描述:
  2917. // 参数:
  2918. // lpszFunction:函数名;
  2919. // dwError:错误码;
  2920. // 返回:
  2921. //---------------------------------------------------------------------
  2922. void ShowSystemErrorInfo(CString &strDescription, const DWORD &dwError)
  2923. {
  2924. #if 0
  2925. LPVOID lpMsgBuf;
  2926. FormatMessage(
  2927. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  2928. FORMAT_MESSAGE_FROM_SYSTEM |
  2929. FORMAT_MESSAGE_IGNORE_INSERTS,
  2930. NULL,
  2931. dwError,
  2932. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  2933. (LPTSTR)&lpMsgBuf,
  2934. 0, NULL);
  2935. // Display the error message and exit the process
  2936. CString strDisplay;
  2937. strDisplay.Format("失败错误码=%d,Windows内部描述:%s", dwError, lpMsgBuf);
  2938. strDescription += strDisplay;
  2939. AfxMessageBox(strDescription);
  2940. LocalFree(lpMsgBuf);
  2941. #endif
  2942. LPVOID lpMsgBuf;
  2943. BOOL fOk = FormatMessage(
  2944. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  2945. FORMAT_MESSAGE_FROM_SYSTEM |
  2946. FORMAT_MESSAGE_IGNORE_INSERTS,
  2947. NULL,
  2948. dwError,
  2949. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  2950. (LPTSTR)&lpMsgBuf,
  2951. 0, NULL);
  2952. if (!fOk)
  2953. {
  2954. // Is it a network-related error?
  2955. HMODULE hDll = LoadLibraryEx(TEXT("netmsg.dll"), NULL, DONT_RESOLVE_DLL_REFERENCES);
  2956. if (hDll != NULL)
  2957. {
  2958. FormatMessage(
  2959. FORMAT_MESSAGE_FROM_HMODULE |
  2960. FORMAT_MESSAGE_FROM_SYSTEM |
  2961. FORMAT_MESSAGE_IGNORE_INSERTS,
  2962. hDll,
  2963. dwError,
  2964. MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
  2965. (LPTSTR)&lpMsgBuf,
  2966. 0,
  2967. NULL);
  2968. FreeLibrary(hDll);
  2969. }
  2970. }
  2971. if (lpMsgBuf != NULL)
  2972. {
  2973. CString strDisplay;
  2974. strDisplay.Format("%s.错误码=%d,Windows描述:%s", strDescription, dwError, (LPCTSTR)LocalLock(lpMsgBuf));
  2975. //WriteLogin(strDisplay);
  2976. AfxMessageBox(strDisplay);
  2977. LocalFree(lpMsgBuf);
  2978. }
  2979. else
  2980. {
  2981. //WriteLogin(strDescription);
  2982. AfxMessageBox("未知道错误");
  2983. }
  2984. }
  2985. /************************************************************************/
  2986. /* 函数:WriteTextLog[7/28/2016 IT];
  2987. /* 描述:写文本日志;
  2988. /* 参数:;
  2989. /* [IN] :;
  2990. /* 返回:void;
  2991. /* 注意:;
  2992. /* 示例:;
  2993. /*
  2994. /* 修改:;
  2995. /* 日期:;
  2996. /* 内容:;
  2997. /************************************************************************/
  2998. void WriteTextLog(const TCHAR *format, ...)
  2999. {
  3000. try
  3001. {
  3002. // 解析出日志路径;
  3003. TCHAR szlogpath[MAX_PATH] = {0};
  3004. static TCHAR szModulePath[MAX_PATH] = {0};
  3005. static TCHAR szFna[_MAX_DIR] = { 0 };
  3006. if ( szModulePath[0] == _T('\0') )
  3007. {
  3008. TCHAR szDrive[_MAX_DRIVE] = { 0 };
  3009. TCHAR szDir[_MAX_DIR] = { 0 };
  3010. TCHAR szExt[_MAX_DIR] = { 0 };
  3011. ::GetModuleFileName(NULL, szModulePath, sizeof(szModulePath) / sizeof(TCHAR));
  3012. _splitpath(szModulePath, szDrive, szDir, szFna, szExt);
  3013. strcpy(szModulePath, szDrive);
  3014. strcat(szModulePath, szDir);
  3015. }
  3016. sprintf(szlogpath, _T("%s客户端日志.txt"), szModulePath);
  3017. // 打开或创建文件;
  3018. CStdioFile fp;
  3019. if (PathFileExists(szlogpath))
  3020. {
  3021. if ( !fp.Open(szlogpath, CFile::modeWrite) )
  3022. {
  3023. return;
  3024. }
  3025. fp.SeekToEnd();
  3026. }
  3027. else
  3028. {
  3029. if ( !fp.Open(szlogpath, CFile::modeCreate | CFile::modeWrite) )
  3030. return;
  3031. }
  3032. // 格式化前设置语言区域;
  3033. TCHAR* old_locale = _tcsdup(_tsetlocale(LC_CTYPE, NULL));
  3034. _tsetlocale(LC_CTYPE, _T("chs"));//设定中文;
  3035. // 格式化日志内容;
  3036. va_list args = NULL;
  3037. int len = 0;
  3038. #if defined(VC70) || defined(VC60)
  3039. static TCHAR buffer[8192] = {0};
  3040. va_start( args, format );
  3041. memset(buffer, 0, 8192);
  3042. vsprintf( buffer, format, args ); // C4996
  3043. // 将日志内容输入到文件中;
  3044. fp.WriteString( CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S ")) );
  3045. fp.WriteString(buffer);
  3046. fp.WriteString(_T("\n"));
  3047. #else
  3048. TCHAR *buffer = NULL;
  3049. va_start( args, format );
  3050. // _vscprintf doesn't count. terminating '\0'
  3051. len = _vsctprintf_p( format, args );
  3052. if ( len == -1 )
  3053. {
  3054. goto clear;
  3055. }
  3056. len++;
  3057. buffer = (TCHAR*)malloc( len * sizeof(TCHAR) );
  3058. _vstprintf_s( buffer, len, format, args ); // C4996
  3059. // Note: vsprintf is deprecated; consider using vsprintf_s instead
  3060. // 将日志内容输入到文件中;
  3061. fp.WriteString( CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S ")) );
  3062. fp.WriteString(buffer);
  3063. fp.WriteString(_T("\n"));
  3064. free( buffer );
  3065. #endif
  3066. // 关闭文件,释放资源并设置回原语言区域;
  3067. //free( buffer );
  3068. clear:
  3069. _tsetlocale(LC_CTYPE, old_locale);
  3070. free(old_locale);//还原区域设定;
  3071. fp.Close();
  3072. }
  3073. catch (CException *e)
  3074. {
  3075. e->ReportError();
  3076. e->Delete();
  3077. }
  3078. }
  3079. //---------------------------------------------------------------------
  3080. // add by Jeff 2014.10.27
  3081. // 函数:全局函数IsDirectoryLegitimate,多字节版本,非UNICODE
  3082. // 描述:判断一个目录路径字符串,是否属于合法的、可创建的目录路径。
  3083. // 参数:strDirectory 被验证的路径字符串;
  3084. //
  3085. // 返回:合法路径返回TRUE;
  3086. //---------------------------------------------------------------------
  3087. BOOL IsDirectoryLegitimate(const CString &strDirectory)
  3088. {
  3089. if (strDirectory.Find('/') != -1 ||
  3090. strDirectory.Find('\\') != -1 ||
  3091. strDirectory.Find(':') != -1 ||
  3092. strDirectory.Find('*') != -1 ||
  3093. strDirectory.Find('?') != -1 ||
  3094. strDirectory.Find('\"') != -1 ||
  3095. strDirectory.Find('>') != -1 ||
  3096. strDirectory.Find('<') != -1 ||
  3097. strDirectory.Find('|') != -1
  3098. )
  3099. return FALSE;
  3100. return TRUE;
  3101. }
  3102. //----------------------------------------------------------------------
  3103. // remark by Jeff 2014.11.08
  3104. // 函数:ExportCutImageToFile
  3105. // 描述:导出裁剪图片到指定目录;
  3106. // 参数:
  3107. // lpOrderCutImageInfo:订单号的裁剪相片信息;
  3108. // lpSrcDirectory:原图片路径;
  3109. // lpOrderCutImageInfo格式:相片名|裁剪方案|原片宽|原片高|裁剪left|裁剪top|裁剪bottom|裁剪rigth
  3110. // 225:5X7,1440,900,88,0,1352,900;228:5X7,1440,900,88,0,1352,900;224:5X7,1440,900,88,0,1352,900;227:10寸,1440,900,56,0,1384,900;229:10寸水晶,1440,900,570,232,870,671;
  3111. // lpSaveDirectory:导出相片的保存路径;
  3112. // 返回:无
  3113. //----------------------------------------------------------------------
  3114. void ExportCutImageToFile(LPCCH lpOrderCutImageInfo, LPCCH lpSrcDirectory, LPCCH lpSaveDirectory)
  3115. {
  3116. if (FALSE == lyfzCreateDirectory(lpSaveDirectory))
  3117. return;
  3118. CStringArray saSrcPhoto;
  3119. GetCountOfOrderFolderPhotoFile(lpSrcDirectory, saSrcPhoto);
  3120. CString strImageName; // 相片名;
  3121. CString strCutScheme; // 裁剪方案;
  3122. CRect rtCut; // 要裁剪的区域;
  3123. CString strTemp;
  3124. CString strImageInfo(lpOrderCutImageInfo);
  3125. int nIndex = -1;
  3126. do
  3127. {
  3128. // 225:5X7,1440,900,88,0,1352,900;
  3129. nIndex = strImageInfo.Find(';');
  3130. strTemp = strImageInfo.Left(nIndex);
  3131. strImageInfo = strImageInfo.Mid(nIndex + 1);
  3132. int SrcImageWid;
  3133. int SrcImageHei;
  3134. int ntempIndex = -1;
  3135. if (nIndex != -1)
  3136. {
  3137. if (FALSE == AnalysisImagInfo(saSrcPhoto,lpSrcDirectory, lpSaveDirectory, strTemp, strImageName, strCutScheme, rtCut))
  3138. continue;
  3139. }
  3140. else
  3141. {
  3142. if (strImageInfo.IsEmpty())
  3143. break;
  3144. AnalysisImagInfo(saSrcPhoto,lpSrcDirectory, lpSaveDirectory, strImageInfo, strImageName, strCutScheme, rtCut);
  3145. break;
  3146. }
  3147. } while (nIndex != -1);
  3148. }
  3149. //----------------------------------------------------------------------
  3150. // remark by Jeff 2014.11.08
  3151. // 函数:AnalysisImagInfo
  3152. // 描述:导出裁剪图片到指定目录;
  3153. // 参数:
  3154. // lpOrderCutImageInfo:订单号的裁剪相片信息;
  3155. // lpSrcDirectory:原图片路径;
  3156. // lpOrderCutImageInfo格式:相片名|裁剪方案|原片宽|原片高|裁剪left|裁剪top|裁剪bottom|裁剪rigth
  3157. // 225:5X7,1440,900,88,0,1352,900;
  3158. // lpSaveDirectory:导出相片的保存路径;
  3159. // 返回:无
  3160. //
  3161. // 说明:未对图片进行缩小,直接在原片上裁剪而得。
  3162. //----------------------------------------------------------------------
  3163. BOOL AnalysisImagInfo(CStringArray &saSrcPhoto, LPCCH lpSrcDirectory, LPCCH lpSaveDirectory, CString &strImageInfo, CString &strImageName, CString &strCutScheme, CRect &rtCut)
  3164. {
  3165. int ntempIndex = -1;
  3166. strImageName = strImageInfo.Left(3); // 裁剪相片名;
  3167. strImageInfo.Delete(0, 4);
  3168. CString strSrcImagePath;
  3169. BOOL bExist = FALSE;
  3170. for (int i = 0; i < saSrcPhoto.GetSize(); i++)
  3171. {
  3172. CString strTemp = saSrcPhoto.ElementAt(i);
  3173. strSrcImagePath = strTemp;
  3174. _splitpath((LPCTSTR)saSrcPhoto.ElementAt(i), NULL, NULL, strTemp.GetBuffer(0), NULL);
  3175. strTemp.ReleaseBuffer();
  3176. if ( strTemp == strImageName)
  3177. {
  3178. bExist = TRUE;
  3179. //saSrcPhoto.RemoveAt(i);
  3180. break;
  3181. }
  3182. }
  3183. if (FALSE == bExist)
  3184. return FALSE;
  3185. ntempIndex = strImageInfo.Find(',');
  3186. strCutScheme = strImageInfo.Left(ntempIndex); // 裁剪方案;
  3187. strImageInfo.Delete(0, ntempIndex + 1);
  3188. // 裁剪原图宽;
  3189. ntempIndex = strImageInfo.Find(',');
  3190. LONG SrcImageWid = _ttol(strImageInfo.Left(ntempIndex));
  3191. strImageInfo.Delete(0, ntempIndex + 1);
  3192. // 裁剪原图高;
  3193. ntempIndex = strImageInfo.Find(',');
  3194. LONG SrcImageHei = _ttol(strImageInfo.Left(ntempIndex));
  3195. strImageInfo.Delete(0, ntempIndex + 1);
  3196. // left坐标值;
  3197. ntempIndex = strImageInfo.Find(',');
  3198. rtCut.left = _ttol(strImageInfo.Left(ntempIndex));
  3199. strImageInfo.Delete(0, ntempIndex + 1);
  3200. // top坐标;
  3201. ntempIndex = strImageInfo.Find(',');
  3202. rtCut.top = _ttol(strImageInfo.Left(ntempIndex));
  3203. strImageInfo.Delete(0, ntempIndex + 1);
  3204. // right坐标;
  3205. ntempIndex = strImageInfo.Find(',');
  3206. rtCut.right = _ttol(strImageInfo.Left(ntempIndex));
  3207. strImageInfo.Delete(0, ntempIndex + 1);
  3208. // bottom坐标;
  3209. rtCut.bottom = _ttol(strImageInfo.Left(ntempIndex));
  3210. // 导出裁剪相片到指定目录;
  3211. // 1.加载原图;
  3212. Image *SrcImage = NULL;
  3213. //if (FALSE == PathFileExists(CString(lpSrcDirectory + strImageName + _T(".jpg"))))
  3214. if (FALSE == PathFileExists(strSrcImagePath))
  3215. {
  3216. AfxMessageBox(_T("相片源文件不存在"));
  3217. return FALSE;
  3218. }
  3219. //LoadImageFromBuf(&SrcImage, CString(lpSrcDirectory + strImageName + _T(".jpg")));
  3220. LoadImageFromBuf(&SrcImage, strSrcImagePath);
  3221. if (SrcImage == NULL)
  3222. {
  3223. AfxMessageBox(_T("加载源图片失败"));
  3224. return FALSE;
  3225. }
  3226. int orientation = GetOrientation(SrcImage);
  3227. if (orientation == 8)
  3228. SrcImage->RotateFlip(Rotate270FlipNone);
  3229. else if (orientation == 6)
  3230. SrcImage->RotateFlip(Rotate90FlipNone);
  3231. if (SrcImage->GetWidth() == 0)
  3232. return FALSE;
  3233. float scale = 1.0;
  3234. scale *= (float)SrcImage->GetWidth() / (float)SrcImageWid;
  3235. rtCut.left *= scale;
  3236. rtCut.right *= scale;
  3237. rtCut.top *= scale;
  3238. rtCut.bottom *= scale;
  3239. #if 0 // 保存在原图上画裁剪区域;
  3240. Graphics graph(SrcImage);
  3241. Pen blackPen(Color(255, 255, 0, 0), 1);
  3242. graph.DrawRectangle(&blackPen, rtCut.left, rtCut.top, rtCut.Width(), rtCut.Height());
  3243. SaveImageToFile(SrcImage, CString(lpSaveDirectory + strImageName + _T(".jpg")));
  3244. delete SrcImage;
  3245. #else // 直接保存裁剪后的图片;
  3246. Bitmap bp(rtCut.Width(), rtCut.Height());
  3247. Graphics *graphic = Graphics::FromImage(&bp);
  3248. graphic->Clear(Color(255, 255, 255, 255));
  3249. graphic->SetInterpolationMode(InterpolationModeHighQualityBicubic);
  3250. graphic->SetSmoothingMode(SmoothingModeHighQuality);//SmoothingModeHighSpeed
  3251. graphic->SetPixelOffsetMode(PixelOffsetModeHighQuality);
  3252. graphic->SetCompositingMode(CompositingModeSourceOver);
  3253. graphic->SetCompositingQuality(CompositingQualityHighQuality);
  3254. graphic->SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);
  3255. graphic->DrawImage(SrcImage, RectF(0, 0, rtCut.Width(), rtCut.Height()), rtCut.left, rtCut.top, rtCut.Width(), rtCut.Height(), UnitPixel);
  3256. delete SrcImage;
  3257. delete graphic;
  3258. //delete graphic;
  3259. //CString strSave;
  3260. //strSave.Format("%s%s:%s.jpg", lpSaveDirectory,strImageName,strCutScheme);
  3261. //SaveImageToFile(&bp, strSave);
  3262. SaveImageToFile(&bp, CString(lpSaveDirectory + strImageName + _T(":") + strCutScheme + _T(".jpg")));
  3263. #endif
  3264. return TRUE;
  3265. }
  3266. // 相片后缀:jpg、raw、cr2、NEF 四种常用后缀
  3267. //--------------------------------------------------------------------------------
  3268. // Remark by Jeff 2014.11.10
  3269. // 函数:GetCountOfOrderFolderPhotoFile
  3270. // 描述:获取订单文件夹下所有相片文件,不含"m"和"s"开头的小图;
  3271. // 参数:pOrderFolder:订单文件路径;
  3272. // 返回:
  3273. //
  3274. //--------------------------------------------------------------------------------
  3275. int GetCountOfOrderFolderPhotoFile( const TCHAR *pOrderFolder, CStringArray &StrPhotoArray)
  3276. {
  3277. CStringArray StrSubFoloderArray;
  3278. using namespace helper_coffs;
  3279. ffsco o;
  3280. o.dirs(1); // Jeff.1:查找子目录;
  3281. o.find(LPCTSTR(pOrderFolder), LPCTSTR(_T("*.*"))); // 可能存在m和s开头的缩略图,需要过滤掉;
  3282. if (o.count() == 0)
  3283. return 0;
  3284. // 获取子目录数;
  3285. ffsco::typeT coo;
  3286. ffsco::typeT::iterator it;
  3287. coo = o.co_dir();
  3288. for (it = coo.begin(); it != coo.end(); it++)
  3289. {
  3290. if (FindArray(&StrSubFoloderArray, (*it).c_str()) == -1)
  3291. StrSubFoloderArray.Add((*it).c_str());
  3292. }
  3293. int nIndex = -1;
  3294. CString strOrderNumberImage;
  3295. // 获取子目录下的文件数;
  3296. //CStringArray StrPhotoArray;
  3297. for (int n = 0; n < StrSubFoloderArray.GetSize(); n++)
  3298. {
  3299. ffsco op;
  3300. op.dirs(0);
  3301. op.find(LPCTSTR(StrSubFoloderArray.ElementAt(n)), LPCTSTR(_T("*.jpg")));
  3302. ffsco::typeT coo;
  3303. ffsco::typeT::iterator itp;
  3304. coo = op.co_file();
  3305. for (itp = coo.begin(); itp != coo.end(); itp++)
  3306. {
  3307. strOrderNumberImage = (*itp).c_str();
  3308. nIndex = strOrderNumberImage.ReverseFind('\\');
  3309. strOrderNumberImage = strOrderNumberImage.Right(strOrderNumberImage.GetLength() - nIndex -1);
  3310. if (strOrderNumberImage.Left(1) != _T("m") && strOrderNumberImage.Left(1) != _T("s"))
  3311. {
  3312. StrPhotoArray.Add((*itp).c_str());
  3313. }
  3314. }
  3315. }
  3316. return 0;
  3317. }
  3318. //---------------------------------------------------------------------
  3319. // Jeff add 2015.03.26;
  3320. // 函数:GetFileNameFromFullPath
  3321. // 描述:从全路径中获取文件名。
  3322. // 参数:
  3323. // lpFullPath:全路径;
  3324. // 返回:
  3325. //---------------------------------------------------------------------
  3326. VOID GetFileNameFromFullPath(CONST CString &strFullPath, CString &strRet)
  3327. {
  3328. // 如果参数空或如果路径不存在;
  3329. if (strFullPath.IsEmpty() || !PathFileExists(strFullPath)) return;
  3330. INT nIndex = strFullPath.ReverseFind(_T('\\'));
  3331. }
  3332. BOOL LoadMicroShareLibrary()
  3333. {
  3334. if (g_hlyfzMicroShareDLL == NULL)
  3335. g_hlyfzMicroShareDLL = LoadLibrary(_T("lyfzMicroShare.dll"));
  3336. if (g_hlyfzMicroShareDLL == NULL)
  3337. {
  3338. AfxMessageBox(_T("加载微共享模块失败!"));
  3339. return FALSE;
  3340. }
  3341. g_lyfzCreateShare = (lyfzCreateShare)::GetProcAddress(g_hlyfzMicroShareDLL, "lyfzCreateShare");
  3342. if (!g_lyfzCreateShare)
  3343. {
  3344. FreeLibrary(g_hlyfzMicroShareDLL);
  3345. g_hlyfzMicroShareDLL = NULL;
  3346. AfxMessageBox(_T("加载导入导出模块接口失败!"));
  3347. return FALSE;
  3348. }
  3349. return TRUE;
  3350. }
  3351. void FreeMicroShareLibrary()
  3352. {
  3353. if (g_hlyfzMicroShareDLL)
  3354. FreeLibrary(g_hlyfzMicroShareDLL);
  3355. g_hlyfzMicroShareDLL = NULL;
  3356. g_lyfzCreateShare = NULL;
  3357. }
  3358. BOOL OpenShareDirectory()
  3359. {
  3360. // 读取remotecfg.dat;
  3361. if (strcmp(g_szModulePath, _T("")) == 0)
  3362. return FALSE;
  3363. TCHAR szdbcfgFile[MAX_PATH] = { _T("") };
  3364. sprintf(szdbcfgFile, _T("%s%s"), g_szModulePath, _T("dbconfig.dat"));
  3365. // 没找到文件;
  3366. if (!PathFileExists(szdbcfgFile)) return FALSE;
  3367. // 打开文件,读取内容;
  3368. CFile cf;
  3369. CFileException e;
  3370. if (!cf.Open(szdbcfgFile, CFile::modeRead, &e))
  3371. {
  3372. // 打开文件失败;
  3373. e.ReportError();
  3374. return FALSE;
  3375. }
  3376. DBSAVE dbcfg;
  3377. // 清空STRemoteInfo结构;
  3378. ZeroMemory(&dbcfg, sizeof(DBSAVE));
  3379. INT nCount = cf.Read(&dbcfg, sizeof(DBSAVE));
  3380. if (nCount != sizeof(DBSAVE))
  3381. {
  3382. cf.Close();
  3383. return FALSE;
  3384. }
  3385. // 清除资源;
  3386. cf.Close();
  3387. // 解析数据;
  3388. TCHAR szHost[51] = {0};
  3389. for (int i = 0; i < 50; i++)
  3390. {
  3391. if (dbcfg.server[i])
  3392. szHost[i] = 500 - dbcfg.server[i];// = 500 - dbcfg.server[i];
  3393. if (dbcfg.user[i])
  3394. dbcfg.user[i] = 500 - dbcfg.user[i];
  3395. if (dbcfg.psw[i])
  3396. dbcfg.psw[i] = 500 - dbcfg.psw[i];
  3397. }
  3398. CString strHost = _T("");
  3399. strHost.Format(_T("%s"),szHost);
  3400. strHost.TrimLeft();
  3401. strHost.TrimRight(".");
  3402. strHost.TrimRight();
  3403. if (strHost.Find(".ly.com") == -1 && strHost.Find("192.168.") == -1)
  3404. MyGetIPByName(strHost);
  3405. // 尝试打开共享目录;
  3406. TCHAR szShareOriginal[MAX_PATH] = {_T("")};
  3407. TCHAR szShareEarly[MAX_PATH] = { _T("") };
  3408. TCHAR szShareFurther[MAX_PATH] = { _T("") };
  3409. TCHAR szShareDesign[MAX_PATH] = { _T("") };
  3410. sprintf(szShareOriginal, _T("\\\\%s\\%s"), strHost, _T("客户原片(管理软件)$"));
  3411. sprintf(szShareEarly, _T("\\\\%s\\%s"), strHost, _T("修好的片(管理软件)$"));
  3412. sprintf(szShareFurther, _T("\\\\%s\\%s"), strHost, _T("精修好的片(管理软件)$"));
  3413. sprintf(szShareDesign, _T("\\\\%s\\%s"), strHost, _T("设计好的片(管理软件)$"));
  3414. if (!PathFileExists(szShareOriginal) || !PathFileExists(szShareEarly) ||
  3415. !PathFileExists(szShareFurther) || !PathFileExists(szShareDesign) )
  3416. return FALSE;
  3417. return TRUE;
  3418. }
  3419. BOOL IsValidDate(LPCTSTR lpDate) // 判断公历;
  3420. {
  3421. if (lpDate == NULL || _tcscmp(lpDate, _T("")) == 0)
  3422. return FALSE;
  3423. CString strDate = lpDate;
  3424. if (strDate.IsEmpty()) return FALSE;
  3425. // 判断日期合法性;
  3426. static int nYear = 0;
  3427. static int nMonth = 0;
  3428. static int nDay = 0;
  3429. nYear = nMonth = nDay = 0;
  3430. nYear = _ttoi(strDate.Left(4));
  3431. nMonth = _ttoi(strDate.Mid(5, 2));
  3432. nDay = _ttoi(strDate.Mid(8, 2));
  3433. CONST static INT nNormalMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  3434. CONST static INT nLeapMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  3435. if ((nDay <= 0) || (nDay > 31) || (nMonth <= 0) || (nMonth > 12)) return FALSE;
  3436. if ((nYear % 400 == 0) || (nYear % 4 == 0 && nYear % 100 != 0))
  3437. {
  3438. if (nDay > nLeapMonth[nMonth - 1]) return FALSE;
  3439. }
  3440. else
  3441. {
  3442. if (nDay > nNormalMonth[nMonth - 1]) return FALSE;
  3443. }
  3444. return TRUE;
  3445. }
  3446. BOOL IsValidLunanrDate(LPCTSTR lpDate) // 判断农历;
  3447. {
  3448. if (lpDate == NULL || _tcscmp(lpDate, _T("")) == 0)
  3449. return FALSE;
  3450. CString strDate = lpDate;
  3451. if (strDate.IsEmpty()) return FALSE;
  3452. static int lunar_year, lunar_month, lunar_day;
  3453. lunar_year = lunar_month = lunar_day = 0;
  3454. lunar_year = _ttoi(strDate.Left(4));
  3455. lunar_month = _ttoi(strDate.Mid(5, 2));
  3456. lunar_day = _ttoi(strDate.Mid(8, 2));
  3457. //越界检查,如果越界,返回无效日期;
  3458. if (lunar_year <= BEGIN_YEAR || lunar_year > BEGIN_YEAR + NUMBER_YEAR - 1)
  3459. return FALSE;
  3460. if (lunar_month < 1 || lunar_month > 12)
  3461. return FALSE;
  3462. // 1.农历年是否有闰月;
  3463. int nYearIndex = lunar_year - BEGIN_YEAR;
  3464. int leap_month = (LUNAR_YEARS[nYearIndex] >> 20) & 0xF;
  3465. // 2.月份大小月天数;
  3466. int month_day = 0;
  3467. if ((LUNAR_YEARS[nYearIndex] >> (7 + 13 - lunar_month)) & 0x1)
  3468. month_day = 30;
  3469. else
  3470. month_day = 29;
  3471. if (lunar_day < 0 || lunar_day > month_day)
  3472. return FALSE;
  3473. return TRUE;
  3474. }
  3475. //************************************//
  3476. // [函数]: IsExistNumInString
  3477. // [描述]: 检查是否有数字
  3478. // [参数]:
  3479. // str 字串
  3480. // [返回]: 1有数字,0没有
  3481. //************************************//
  3482. int IsExistNumInString(const char* str)
  3483. {
  3484. if(str == NULL)
  3485. return 0;
  3486. //字符0~9 对应该 ascii码48~57
  3487. for(int i=0; i<strlen(str); i++)
  3488. {
  3489. if(str[i] >= 48 && str[i] <= 57)
  3490. return 1;
  3491. }
  3492. return 0;
  3493. }
  3494. /************************************************************************/
  3495. /*
  3496. 函数:SaveImg2newfile
  3497. 描述:将Image对象另存为其他格式的文件;
  3498. 参数:
  3499. IN: pImg GDI+ Image对象指针,需要保存的图像对象;
  3500. IN: lpnewfile 其他格式的新文件名(jpg,bmp,png,jpeg);
  3501. IN: uQuality 另存为新文件时的图像质量值;
  3502. 返回:
  3503. 注意:Image::Save 若文件存在,会覆盖存在的文件;
  3504. */
  3505. /************************************************************************/
  3506. BOOL SaveImg2newfile(IN Image* pImg, IN CString strNewfile, IN ULONG uQuality)
  3507. {
  3508. if (pImg == NULL) return FALSE;
  3509. // 需要判断路径是否存在,不存在创建目录;
  3510. int nIndex = strNewfile.ReverseFind(_T('\\'));
  3511. if (nIndex == -1)
  3512. return FALSE;
  3513. if (!PathFileExists(strNewfile.Left(nIndex)))
  3514. {
  3515. // 如果文件夹不存在,创建;
  3516. CreateDirectory(strNewfile.Left(nIndex), NULL);
  3517. }
  3518. nIndex = strNewfile.ReverseFind(_T('.'));
  3519. if (nIndex == -1)
  3520. return FALSE;
  3521. Status stat = GenericError;
  3522. CLSID encoderClsid = { 0 };
  3523. BSTR newfile = strNewfile.AllocSysString();
  3524. strNewfile = strNewfile.Mid(nIndex + 1);
  3525. if (strNewfile.CompareNoCase(_T("bmp")) == 0)
  3526. {
  3527. GetEncoderClsid(L"image/bmp", &encoderClsid);
  3528. stat = pImg->Save(newfile, &encoderClsid, NULL);
  3529. }
  3530. else if (strNewfile.CompareNoCase(_T("png")) == 0)
  3531. {
  3532. GetEncoderClsid(L"image/png", &encoderClsid);
  3533. stat = pImg->Save(newfile, &encoderClsid, NULL);
  3534. }
  3535. else// if ( strNewfile.CompareNoCase(_T("jpeg")) == 0 )
  3536. {
  3537. GetEncoderClsid(L"image/jpeg", &encoderClsid);
  3538. EncoderParameters encoderParameters;
  3539. encoderParameters.Count = 1;
  3540. encoderParameters.Parameter[0].Guid = EncoderQuality;
  3541. encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
  3542. encoderParameters.Parameter[0].NumberOfValues = 1;
  3543. // Save the image as a JPEG with quality level 100.
  3544. encoderParameters.Parameter[0].Value = &uQuality;
  3545. stat = pImg->Save(newfile, &encoderClsid, &encoderParameters);
  3546. }
  3547. SysFreeString(newfile);
  3548. return stat == Ok ? TRUE : FALSE;
  3549. }
  3550. /************************************************************************/
  3551. /*
  3552. 函数:ZoomImg
  3553. 描述:缩放到指定大小的区域中,返回缩放后的尺寸;
  3554. 参数:
  3555. IN: Imgrc 图像的大小;
  3556. IN: dwDisplayPix 图像要显示的区域的大小;
  3557. OUT: dwZoomPix 图像在显示区域内缩放后的尺寸;
  3558. 返回:
  3559. 注意:dwZoomPix的尺寸必须在dwDisplayPix内;
  3560. */
  3561. /************************************************************************/
  3562. int ZoomImg(IN CRect &Imgrc, IN CONST DWORD &dwDisplayPix, OUT DWORD &dwZoomPix)
  3563. {
  3564. double fDisplayWidth = GET_XPIX(dwDisplayPix);
  3565. double fDisplayHeight = GET_YPIX(dwDisplayPix);
  3566. // 显示区域长宽比;
  3567. double fDisplayAspectRatio = fDisplayWidth / fDisplayHeight;
  3568. // 图片长宽比;
  3569. double fImgAspectRatio = ((double)Imgrc.Width()) / ((double)Imgrc.Height());
  3570. double fZoomWidth;
  3571. double fZoomHeight;
  3572. if (fDisplayAspectRatio > fImgAspectRatio)
  3573. {
  3574. fZoomWidth = fDisplayHeight*fImgAspectRatio;
  3575. fZoomHeight = fDisplayHeight;
  3576. }
  3577. else
  3578. {
  3579. fZoomWidth = fDisplayWidth;
  3580. fZoomHeight = fDisplayWidth / fImgAspectRatio;
  3581. }
  3582. dwZoomPix = SET_PIX((int)fZoomWidth, (int)fZoomHeight);
  3583. //////////////////////////////////////////////////////////////////////////
  3584. int nRetval = 0;
  3585. if ((fDisplayWidth == Imgrc.Width()) && (fDisplayHeight == Imgrc.Height()))
  3586. {
  3587. nRetval = ZoomNull;
  3588. }
  3589. else if ((fDisplayWidth > Imgrc.Width()) && (fDisplayHeight > Imgrc.Height()))
  3590. {
  3591. nRetval = ZoomOut;
  3592. }
  3593. else
  3594. {
  3595. nRetval = ZoomIn;
  3596. }
  3597. return nRetval;
  3598. }
  3599. int ZoomImg(IN CONST DWORD &dwImgPix, IN CONST DWORD &dwDisplayPix, OUT DWORD &dwZoomPix)
  3600. {
  3601. double fDisplayWidth = GET_XPIX(dwDisplayPix);
  3602. double fDisplayHeight = GET_YPIX(dwDisplayPix);
  3603. // 显示区域长宽比;
  3604. double fDisplayAspectRatio = fDisplayWidth / fDisplayHeight;
  3605. // 图片长宽比;
  3606. double fImgAspectRatio = ((double)GET_XPIX(dwImgPix)) / ((double)GET_YPIX(dwImgPix));
  3607. double fZoomWidth;
  3608. double fZoomHeight;
  3609. if (fDisplayAspectRatio > fImgAspectRatio)
  3610. {
  3611. fZoomWidth = fDisplayHeight*fImgAspectRatio;
  3612. fZoomHeight = fDisplayHeight;
  3613. }
  3614. else
  3615. {
  3616. fZoomWidth = fDisplayWidth;
  3617. fZoomHeight = fDisplayWidth / fImgAspectRatio;
  3618. }
  3619. dwZoomPix = SET_PIX((int)fZoomWidth, (int)fZoomHeight);
  3620. //////////////////////////////////////////////////////////////////////////
  3621. int nRetval = 0;
  3622. if ((fDisplayWidth == GET_XPIX(dwImgPix)) && (fDisplayHeight == GET_YPIX(dwImgPix)))
  3623. {
  3624. nRetval = ZoomNull;
  3625. }
  3626. else if ((fDisplayWidth > GET_XPIX(dwImgPix)) && (fDisplayHeight > GET_YPIX(dwImgPix)))
  3627. {
  3628. nRetval = ZoomOut;
  3629. }
  3630. else
  3631. {
  3632. nRetval = ZoomIn;
  3633. }
  3634. return nRetval;
  3635. }
  3636. /************************************************************************/
  3637. /*
  3638. 函数:ImgThumbnail
  3639. 描述:生成高质量的图像缩略图;
  3640. 参数:
  3641. IN Image* pImg, 原图指针
  3642. IN CONST DWORD &dwDisplayPix, SET_PIX(100,76) = 100*76大小
  3643. IN CString strNewfile, 新的图片名
  3644. IN ULONG uQuality 缩略图质量0~100
  3645. 返回:
  3646. 注意:为了健壮性,strNewfile的路径可以在函数内再次判断是否有效,防止在函数外没有进行经判断;
  3647. */
  3648. /************************************************************************/
  3649. BOOL ImgThumbnail(IN Image* pImg, IN CONST DWORD &dwDisplayPix, IN CString strNewfile, IN ULONG uQuality)
  3650. {
  3651. if (pImg == NULL) return FALSE;
  3652. DWORD dwZoomPix;
  3653. int retval = ZoomImg(SET_PIX(pImg->GetWidth(), pImg->GetHeight()), dwDisplayPix, dwZoomPix);
  3654. if (retval == ZoomNull)
  3655. {
  3656. return SaveImg2newfile(pImg, strNewfile, uQuality);
  3657. }
  3658. // 绘制缩略图;
  3659. Bitmap bitmap(GET_XPIX(dwZoomPix), GET_YPIX(dwZoomPix));
  3660. Graphics *graphic = Graphics::FromImage(&bitmap);
  3661. graphic->Clear(Color(255, 255, 255, 255));
  3662. graphic->SetInterpolationMode(InterpolationModeHighQualityBicubic);
  3663. graphic->SetSmoothingMode(SmoothingModeHighQuality);//SmoothingModeHighSpeed
  3664. graphic->SetPixelOffsetMode(PixelOffsetModeHighQuality);
  3665. graphic->SetCompositingMode(CompositingModeSourceOver);
  3666. graphic->SetCompositingQuality(CompositingQualityHighQuality);
  3667. graphic->SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);
  3668. graphic->DrawImage(pImg, 0, 0, GET_XPIX(dwZoomPix), GET_YPIX(dwZoomPix));
  3669. delete graphic;
  3670. // 生成缩略图;
  3671. return SaveImg2newfile(&bitmap, strNewfile, uQuality);
  3672. }
  3673. /************************************************************************/
  3674. /*
  3675. 函数:ImgThumbnail
  3676. 描述:生成高质量的图像缩略图;
  3677. 参数:
  3678. IN LPCTSTR lpImgpath,
  3679. IN CONST DWORD &dwDisplayPix,
  3680. IN CString strNewfile,
  3681. IN ULONG uQuality
  3682. 返回:
  3683. 注意:为了健壮性,strNewfile的路径可以在函数内再次判断是否有效,防止在函数外没有进行经判断;
  3684. */
  3685. /************************************************************************/
  3686. BOOL ImgThumbnail(IN LPCTSTR lpImgpath, IN CONST DWORD &dwDisplayPix, IN CString strNewfile, IN ULONG uQuality)
  3687. {
  3688. if (!PathFileExists(lpImgpath))
  3689. return FALSE;
  3690. #ifdef UNICODE
  3691. Image Img(lpImgpath);
  3692. #else
  3693. BSTR strtmp = _bstr_t(lpImgpath);
  3694. Image Img(strtmp);
  3695. SysFreeString(strtmp);
  3696. #endif
  3697. DWORD dwZoomPix;
  3698. int retval = ZoomImg(SET_PIX(Img.GetWidth(), Img.GetHeight()), dwDisplayPix, dwZoomPix);
  3699. if (retval == ZoomNull)
  3700. {
  3701. return SaveImg2newfile(&Img, strNewfile, uQuality);
  3702. }
  3703. // 绘制缩略图;
  3704. Bitmap bitmap(GET_XPIX(dwZoomPix), GET_YPIX(dwZoomPix));
  3705. Graphics *graphic = Graphics::FromImage(&bitmap);
  3706. graphic->Clear(Color(255, 255, 255, 255));
  3707. graphic->SetInterpolationMode(InterpolationModeHighQualityBicubic);
  3708. graphic->SetSmoothingMode(SmoothingModeHighQuality);//SmoothingModeHighSpeed
  3709. graphic->SetPixelOffsetMode(PixelOffsetModeHighQuality);
  3710. graphic->SetCompositingMode(CompositingModeSourceOver);
  3711. graphic->SetCompositingQuality(CompositingQualityHighQuality);
  3712. graphic->SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);
  3713. graphic->DrawImage(&Img, 0, 0, GET_XPIX(dwZoomPix), GET_YPIX(dwZoomPix));
  3714. delete graphic;
  3715. // 生成缩略图;
  3716. return SaveImg2newfile(&bitmap, strNewfile, uQuality);
  3717. }
  3718. /*-----------------------------------DES加密解密 模块 begin--------------------------------------------*/
  3719. DESEncrypt g_DESEncrypt = NULL;
  3720. DESDecrypt g_DESDecrypt = NULL;
  3721. /*-----------------------------------DES加密解密 模块 end--------------------------------------------*/
  3722. /*-----------------------------------读取硬件信息 模块 begin--------------------------------------------*/
  3723. HMODULE g_hHDSerial = NULL;
  3724. GetSeiralNumberOrID g_GetSeiralNumberOrID = NULL;
  3725. GetLocalMacAddr g_GetLocalMacAdd = NULL;
  3726. BOOL LoadHDSerialLibrary()
  3727. {
  3728. if (g_hHDSerial == NULL)
  3729. g_hHDSerial = LoadLibrary(_T("lyfzHDSerial.dll"));
  3730. if (g_hHDSerial == NULL)
  3731. {
  3732. //dwError = GetLastError();
  3733. AfxMessageBox(_T("加载读取硬件信息模块失败!"));
  3734. return FALSE;
  3735. }
  3736. g_GetSeiralNumberOrID = (GetSeiralNumberOrID)::GetProcAddress(g_hHDSerial, "GetSeiralNumberOrID");
  3737. g_GetLocalMacAdd = (GetLocalMacAddr)::GetProcAddress(g_hHDSerial, "GetLocalMacAddr");
  3738. g_DESEncrypt = (DESEncrypt)::GetProcAddress(g_hHDSerial, "DESEncrypt");
  3739. g_DESDecrypt = (DESDecrypt)::GetProcAddress(g_hHDSerial, "DESDecrypt");
  3740. if (!g_GetSeiralNumberOrID || !g_GetLocalMacAdd)
  3741. {
  3742. AfxMessageBox(_T("加载读取硬件信息模块接口失败!"));
  3743. return FALSE;
  3744. }
  3745. if(!g_DESEncrypt || !g_DESDecrypt)
  3746. {
  3747. AfxMessageBox(_T("加载加密解密接口失败!"));
  3748. return FALSE;
  3749. }
  3750. return TRUE;
  3751. }
  3752. void FreeHDSerialLibrary()
  3753. {
  3754. if (g_hHDSerial)
  3755. FreeLibrary(g_hHDSerial);
  3756. g_hHDSerial = NULL;
  3757. g_GetSeiralNumberOrID = NULL;
  3758. g_GetLocalMacAdd = NULL;
  3759. g_DESEncrypt = NULL;
  3760. g_DESDecrypt = NULL;
  3761. }
  3762. /*-----------------------------------读取硬件信息 模块 end--------------------------------------------*/
  3763. #ifdef USE_KERNEL_DLL
  3764. /************************************************************************/
  3765. /* 函数:CreateIMGProcess[3/1/2016 IT];
  3766. /* 描述:创建lyfzIMGProcess.dll模块实例句柄;
  3767. /* 参数:;
  3768. /* 返回:成功返回句柄值,否则返回NULL;
  3769. /* 注意:;
  3770. /* 示例:;
  3771. /*
  3772. /* 修改:;
  3773. /* 日期:;
  3774. /* 内容:;
  3775. /************************************************************************/
  3776. ImgEnvInterface* CreateIMGProcess( )
  3777. {
  3778. //加载动态库;
  3779. DWORD dwError = 0;
  3780. HMODULE hKernelDll = ( HMODULE )LoadLibrary( _T("lyfzIMGProcess.dll") );
  3781. if ( hKernelDll )
  3782. {
  3783. //获取创建接口的函数
  3784. CREATEIMGPROCESS pInstance = (CREATEIMGPROCESS)GetProcAddress( hKernelDll, "CreateIMGProcess" );
  3785. if ( pInstance )
  3786. {
  3787. //创建接口
  3788. ImgEnvInterface * pIMGProcess = pInstance( );
  3789. //返回接口
  3790. return pIMGProcess;
  3791. }
  3792. else
  3793. {
  3794. dwError = GetLastError();
  3795. }
  3796. }
  3797. else
  3798. {
  3799. dwError = GetLastError();
  3800. }
  3801. if ( ERROR_SUCCESS != dwError )
  3802. {// 加载时产生错误;
  3803. CString strError = _T("");
  3804. strError.Format(_T("加载lyfzIMGProcess.dll时出错,出错码=%d"), dwError);
  3805. WriteTextLog(strError);
  3806. }
  3807. return NULL;
  3808. }
  3809. ImgEnvInterface *g_pIMGProcess = NULL;
  3810. /************************************************************************/
  3811. /* 函数:GetOrderpathByImgType[3/1/2016 IT];
  3812. /* 描述:根据域名和相片类型(原片、初修片、精修片、设计片)来获取全部订单的相片保存路径;
  3813. /* 参数:;
  3814. /* [IN] nImgType:相片类型(1 = 原片、2 = 初修片、3 = 精修片、4 = 设计片、5~8备份片);
  3815. /* [IN] lpBranchId:分店域名;
  3816. /* [OUT] AryOrderpath:要返回的所有订单的相片共享目录;
  3817. /* 返回:成功获取目录返回TRUE;
  3818. /* 注意:;
  3819. /* 示例:;
  3820. /*
  3821. /* 修改:;
  3822. /* 日期:;
  3823. /* 内容:;
  3824. /************************************************************************/
  3825. BOOL GetOrderpathByImgType(IN CONST INT& nImgType, IN LPCTSTR lpBranchId, OUT CStringArray& AryOrderpath)
  3826. {
  3827. if ( lpBranchId == NULL || lpBranchId[0] == '\0' || !_tcsstr(lpBranchId, _T(".ly.com")))
  3828. {
  3829. OutputDebugString(lpBranchId);
  3830. OutputDebugString(_T("\n分店域名无效!\n"));
  3831. return FALSE;
  3832. }
  3833. if ( nImgType > DBImgtype || nImgType < OImgtype )
  3834. {
  3835. OutputDebugString(_T("\n该相片类型不存在!\n"));
  3836. return FALSE;
  3837. }
  3838. if ( g_pIMGProcess == NULL )
  3839. return FALSE;
  3840. CString str;
  3841. HGLOBAL hMemery;
  3842. DWORD dwMemSize = 0;
  3843. hMemery = g_pIMGProcess->GetBranchAllOrderDirectory(nImgType, lpBranchId, dwMemSize);
  3844. if ( hMemery )
  3845. {
  3846. BYTE *pData = (BYTE*)GlobalLock(hMemery);
  3847. if ( pData == NULL )
  3848. {
  3849. GlobalUnlock(hMemery);
  3850. GlobalFree(hMemery);
  3851. return FALSE;
  3852. }
  3853. CMemFile mf;
  3854. mf.Attach(pData, dwMemSize);
  3855. CArchive ar(&mf, CArchive::load);
  3856. AryOrderpath.Serialize(ar);
  3857. ar.Close();
  3858. mf.Detach();
  3859. GlobalUnlock(hMemery);
  3860. GlobalFree(hMemery);
  3861. return TRUE;
  3862. }
  3863. return FALSE;
  3864. }
  3865. /************************************************************************/
  3866. /* 函数:GetOrderpathByOrderNum[3/1/2016 IT];
  3867. /* 描述:根据分店域名、相片类型、订单号来获取订单的全部共享目录;
  3868. /* 参数:;
  3869. /* [IN] nImgType:相片类型(1 = 原片、2 = 初修片、3 = 精修片、4 = 设计片、5~8备份片);
  3870. /* [IN] lpBranchId:分店域名;
  3871. /* [IN] lpOrderNum:订单号;
  3872. /* [OUT] AryOrderpath:返回指定订单的相片目录(如果使用多目录共享,结果可能大于1);
  3873. /* 返回:void;
  3874. /* 注意:;
  3875. /* 示例:;
  3876. /*
  3877. /* 修改:;
  3878. /* 日期:;
  3879. /* 内容:;
  3880. /************************************************************************/
  3881. BOOL GetOrderpathByOrderNum(IN CONST INT& nImgType, IN LPCTSTR lpBranchId, IN LPCTSTR lpOrderNum, OUT CStringArray& AryOrderpath)
  3882. {
  3883. if ( lpBranchId == NULL || lpBranchId[0] == '\0' || !_tcsstr(lpBranchId, _T(".ly.com")))
  3884. {
  3885. OutputDebugString(lpBranchId);
  3886. OutputDebugString(_T("\n分店域名无效!\n"));
  3887. return FALSE;
  3888. }
  3889. if ( nImgType > DBImgtype || nImgType < OImgtype )
  3890. {
  3891. OutputDebugString(_T("\n该相片类型不存在!\n"));
  3892. return FALSE;
  3893. }
  3894. if ( g_pIMGProcess == NULL )
  3895. return FALSE;
  3896. CString str;
  3897. HGLOBAL hMemery;
  3898. DWORD dwMemSize = 0;
  3899. hMemery = g_pIMGProcess->GetOrderAllShareDirectory(nImgType, lpBranchId, lpOrderNum, dwMemSize);
  3900. if ( hMemery )
  3901. {
  3902. BYTE *pData = (BYTE*)GlobalLock(hMemery);
  3903. if ( pData == NULL )
  3904. {
  3905. GlobalUnlock(hMemery);
  3906. GlobalFree(hMemery);
  3907. return FALSE;
  3908. }
  3909. CMemFile mf;
  3910. mf.Attach(pData, dwMemSize);
  3911. CArchive ar(&mf, CArchive::load);
  3912. AryOrderpath.Serialize(ar);
  3913. ar.Close();
  3914. mf.Detach();
  3915. GlobalUnlock(hMemery);
  3916. GlobalFree(hMemery);
  3917. return TRUE;
  3918. }
  3919. return FALSE;
  3920. }
  3921. /************************************************************************/
  3922. /* 函数:GetScenerypathByOrderNum[3/1/2016 IT];
  3923. /* 描述:获取指定订单景点名的全部共享目录;
  3924. /* 参数:;
  3925. /* [IN] nImgType:相片类型(1 = 原片、2 = 初修片、3 = 精修片、4 = 设计片、5~8备份片);
  3926. /* [IN] lpBranchId:分店域名;
  3927. /* [IN] lpOrderNum:订单号;
  3928. /* [IN] lpScenery:景点名;
  3929. /* [OUT] AryScenerypath:返回指定订单的相片目录(如果使用多目录共享,结果可能大于1);
  3930. /* 返回:void;
  3931. /* 注意:;
  3932. /* 示例:;
  3933. /*
  3934. /* 修改:;
  3935. /* 日期:;
  3936. /* 内容:;
  3937. /************************************************************************/
  3938. BOOL GetScenerypathByOrderNum(IN CONST INT& nImgType, IN LPCTSTR lpBranchId, IN LPCTSTR lpOrderNum, IN LPCTSTR lpScenery, OUT CStringArray& AryScenerypath)
  3939. {
  3940. if ( lpBranchId == NULL || lpBranchId[0] == '\0' || !_tcsstr(lpBranchId, _T(".ly.com")))
  3941. {
  3942. OutputDebugString(lpBranchId);
  3943. OutputDebugString(_T("\n分店域名无效!\n"));
  3944. return FALSE;
  3945. }
  3946. if ( nImgType > DBImgtype || nImgType < OImgtype )
  3947. {
  3948. OutputDebugString(_T("\n该相片类型不存在!\n"));
  3949. return FALSE;
  3950. }
  3951. if ( g_pIMGProcess == NULL )
  3952. return FALSE;
  3953. CString str;
  3954. HGLOBAL hMemery;
  3955. DWORD dwMemSize = 0;
  3956. hMemery = g_pIMGProcess->GetSceneryAllShareDirectory(nImgType, lpBranchId, lpOrderNum, lpScenery, dwMemSize);
  3957. if ( hMemery )
  3958. {
  3959. BYTE *pData = (BYTE*)GlobalLock(hMemery);
  3960. if ( pData == NULL )
  3961. {
  3962. GlobalUnlock(hMemery);
  3963. GlobalFree(hMemery);
  3964. return FALSE;
  3965. }
  3966. CMemFile mf;
  3967. mf.Attach(pData, dwMemSize);
  3968. CArchive ar(&mf, CArchive::load);
  3969. AryScenerypath.Serialize(ar);
  3970. ar.Close();
  3971. mf.Detach();
  3972. GlobalUnlock(hMemery);
  3973. GlobalFree(hMemery);
  3974. return TRUE;
  3975. }
  3976. return FALSE;
  3977. }
  3978. /************************************************************************/
  3979. /* 函数:GetOrderImgpath[3/1/2016 IT];
  3980. /* 描述:获取指定订单号的全部相片路径;
  3981. /* 参数:;
  3982. /* [IN] nImgType:相片类型(1 = 原片、2 = 初修片、3 = 精修片、4 = 设计片、5~8备份片);
  3983. /* [IN] lpBranchId:分店域名;
  3984. /* [IN] lpOrderNum:订单号;
  3985. /* [OUT] AryImgpath:返回指定订单的全部相片路径;
  3986. /* 返回:void;
  3987. /* 注意:;
  3988. /* 示例:;
  3989. /*
  3990. /* 修改:;
  3991. /* 日期:;
  3992. /* 内容:;
  3993. /************************************************************************/
  3994. BOOL GetOrderImgpath(IN CONST INT& nImgType, IN LPCTSTR lpBranchId, IN LPCTSTR lpOrderNum, OUT CStringArray& AryImgpath)
  3995. {
  3996. if ( lpBranchId == NULL || lpBranchId[0] == '\0' || !_tcsstr(lpBranchId, _T(".ly.com")))
  3997. {
  3998. OutputDebugString(lpBranchId);
  3999. OutputDebugString(_T("\n分店域名无效!\n"));
  4000. return FALSE;
  4001. }
  4002. if ( nImgType > DBImgtype || nImgType < OImgtype )
  4003. {
  4004. OutputDebugString(_T("\n该相片类型不存在!\n"));
  4005. return FALSE;
  4006. }
  4007. if ( g_pIMGProcess == NULL )
  4008. return FALSE;
  4009. CString str;
  4010. DWORD dwMemSize = 0;
  4011. ImgLoadOrderpathInterface *pOrderLoader = NULL;
  4012. g_pIMGProcess->QueryInterface(IID_ImgLoadOrderpathInterface,(void**)&pOrderLoader);
  4013. if ( pOrderLoader )
  4014. {
  4015. HGLOBAL hMemery = pOrderLoader->LoadOrderImages( nImgType, lpBranchId, lpOrderNum, _T("*.jpg|*.jpeg"), dwMemSize);
  4016. if ( hMemery )
  4017. {
  4018. BYTE *pData = (BYTE*)GlobalLock(hMemery);
  4019. if ( pData == NULL )
  4020. {
  4021. GlobalUnlock(hMemery);
  4022. GlobalFree(hMemery);
  4023. return FALSE;
  4024. }
  4025. CMemFile mf;
  4026. mf.Attach(pData, dwMemSize);
  4027. CArchive ar(&mf, CArchive::load);
  4028. AryImgpath.Serialize(ar);
  4029. ar.Close();
  4030. mf.Detach();
  4031. GlobalUnlock(hMemery);
  4032. GlobalFree(hMemery);
  4033. }
  4034. pOrderLoader->Release();
  4035. return TRUE;
  4036. }
  4037. return FALSE;
  4038. }
  4039. /************************************************************************/
  4040. /* 函数:GetOrderImgpathEx[3/1/2016 IT];
  4041. /* 描述:获取指定订单的全部相片路径;
  4042. /* 参数:;
  4043. /* [IN] nImgType:相片类型(1 = 原片、2 = 初修片、3 = 精修片、4 = 设计片、5~8备份片);
  4044. /* [IN] lpBranchId:分店域名;
  4045. /* [IN] lpOrderNum:订单号;
  4046. /* [IN] bLoadInSubfolder:是否加载订单目录下的子目录;
  4047. /* [IN] lpLoadExt:要加载的相片扩展名;
  4048. /* [IN] lpWithExt:要附加的相片扩展名;
  4049. /* [IN] AryLoadExtImgpath:指定加载扩展名的相片路径;
  4050. /* [IN] AryWithExtImgpath:指定附加扩展名的相片路径;
  4051. /* [IN] AryOrderDirectory:指定订单号的相片共享目录(多目录下可能大于1);
  4052. /* 返回:void;
  4053. /* 注意:;
  4054. /* 示例:;
  4055. /*
  4056. /* 修改:;
  4057. /* 日期:;
  4058. /* 内容:;
  4059. /************************************************************************/
  4060. BOOL GetOrderImgpathEx(IN CONST INT& nImgType, IN LPCTSTR lpBranchId, IN LPCTSTR lpOrderNum, IN BOOL bLoadInSubfolder, IN LPCTSTR lpLoadExt, IN LPCTSTR lpWithExt, OUT CStringArray& AryLoadExtImgpath, OUT CStringArray& AryWithExtImgpath, OUT CStringArray& AryOrderDirectory )
  4061. {
  4062. if ( lpBranchId == NULL || lpBranchId[0] == '\0' || !_tcsstr(lpBranchId, _T(".ly.com")))
  4063. {
  4064. OutputDebugString(lpBranchId);
  4065. OutputDebugString(_T("\n分店域名无效!\n"));
  4066. return FALSE;
  4067. }
  4068. if ( nImgType > DBImgtype || nImgType < OImgtype )
  4069. {
  4070. OutputDebugString(_T("\n该相片类型不存在!\n"));
  4071. return FALSE;
  4072. }
  4073. if ( g_pIMGProcess == NULL )
  4074. return FALSE;
  4075. DWORD dwReturnSize = 0;
  4076. ImgLoadOrderpathExInterface *pOrderLoader = NULL;
  4077. g_pIMGProcess->QueryInterface(IID_ImgLoadOrderpathExInterface,(void**)&pOrderLoader);
  4078. if ( pOrderLoader )
  4079. {
  4080. pOrderLoader->Release();
  4081. HGLOBAL hMemery = pOrderLoader->LoadOrderImagesEx(nImgType, lpBranchId, lpOrderNum, TRUE, lpLoadExt, lpWithExt, dwReturnSize);
  4082. if ( hMemery )
  4083. {
  4084. BYTE* pMemery = (BYTE*)GlobalLock(hMemery);
  4085. if ( pMemery == NULL )
  4086. {
  4087. GlobalUnlock(hMemery);
  4088. GlobalFree(hMemery);
  4089. return FALSE;
  4090. }
  4091. DWORD dwSize = 0;
  4092. DWORD dw1 = 0,dw2 = 0,dw3 = 0;
  4093. CMemFile memfile[3];
  4094. memcpy(&dw1, pMemery + dwSize, sizeof(DWORD));
  4095. dwSize += sizeof(DWORD);
  4096. memfile[0].Attach(pMemery+dwSize, dw1);
  4097. dwSize += dw1;
  4098. memcpy(&dw2, pMemery + dwSize, sizeof(DWORD));
  4099. dwSize += sizeof(DWORD);
  4100. memfile[1].Attach(pMemery+dwSize, dw2);
  4101. dwSize += dw2;
  4102. memcpy(&dw3, pMemery + dwSize, sizeof(DWORD));
  4103. dwSize += sizeof(DWORD);
  4104. memfile[2].Attach(pMemery+dwSize, dw3);
  4105. dwSize += dw3;
  4106. CArchive a1(&memfile[0],CArchive::load);
  4107. CArchive a2(&memfile[1],CArchive::load);
  4108. CArchive a3(&memfile[2],CArchive::load);
  4109. AryLoadExtImgpath.Serialize(a1);
  4110. AryWithExtImgpath.Serialize(a2);
  4111. AryOrderDirectory.Serialize(a3);
  4112. a1.Close();
  4113. a2.Close();
  4114. a3.Close();
  4115. memfile[0].Detach();
  4116. memfile[1].Detach();
  4117. memfile[2].Detach();
  4118. if (hMemery)
  4119. {
  4120. GlobalUnlock(hMemery);
  4121. GlobalFree(hMemery);
  4122. }
  4123. return TRUE;
  4124. }
  4125. }
  4126. return FALSE;
  4127. }
  4128. /************************************************************************/
  4129. /* 函数:GetOrderImgpath[3/1/2016 IT];
  4130. /* 描述:获取指定订单号的全部相片路径;
  4131. /* 参数:;
  4132. /* [IN] nImgType:相片类型(1 = 原片、2 = 初修片、3 = 精修片、4 = 设计片、5~8备份片);
  4133. /* [IN] lpBranchId:分店域名;
  4134. /* [IN] lpOrderNum:订单号;
  4135. /* [IN] lpScenery:景点名或套系名;
  4136. /* [OUT] AryImgpath:返回指定订单的全部相片路径;
  4137. /* 返回:void;
  4138. /* 注意:;
  4139. /* 示例:;
  4140. /*
  4141. /* 修改:;
  4142. /* 日期:;
  4143. /* 内容:;
  4144. /************************************************************************/
  4145. BOOL GetSceneryImgpath(IN CONST INT& nImgType, IN LPCTSTR lpBranchId, IN LPCTSTR lpOrderNum, IN LPCTSTR lpScenery, OUT CStringArray& AryImgpath)
  4146. {
  4147. if ( lpBranchId == NULL || lpBranchId[0] == '\0' || !_tcsstr(lpBranchId, _T(".ly.com")))
  4148. {
  4149. OutputDebugString(lpBranchId);
  4150. OutputDebugString(_T("\n分店域名无效!\n"));
  4151. return FALSE;
  4152. }
  4153. if ( nImgType > DBImgtype || nImgType < OImgtype )
  4154. {
  4155. OutputDebugString(_T("\n该相片类型不存在!\n"));
  4156. return FALSE;
  4157. }
  4158. if ( g_pIMGProcess == NULL )
  4159. return FALSE;
  4160. CString str;
  4161. DWORD dwMemSize = 0;
  4162. ImgLoadOrderpathInterface *pOrderLoader = NULL;
  4163. g_pIMGProcess->QueryInterface(IID_ImgLoadOrderpathInterface,(void**)&pOrderLoader);
  4164. if ( pOrderLoader )
  4165. {
  4166. HGLOBAL hMemery = pOrderLoader->LoadSceneryImages( nImgType, lpBranchId, lpOrderNum, lpScenery, _T("*.jpg|*.jpeg"), dwMemSize);
  4167. if ( hMemery )
  4168. {
  4169. BYTE *pData = (BYTE*)GlobalLock(hMemery);
  4170. if ( pData == NULL )
  4171. {
  4172. GlobalUnlock(hMemery);
  4173. GlobalFree(hMemery);
  4174. return FALSE;
  4175. }
  4176. CMemFile mf;
  4177. mf.Attach(pData, dwMemSize);
  4178. CArchive ar(&mf, CArchive::load);
  4179. AryImgpath.Serialize(ar);
  4180. ar.Close();
  4181. mf.Detach();
  4182. GlobalUnlock(hMemery);
  4183. GlobalFree(hMemery);
  4184. }
  4185. pOrderLoader->Release();
  4186. return TRUE;
  4187. }
  4188. return FALSE;
  4189. }
  4190. /************************************************************************/
  4191. /* 函数:GetOrderImgpathEx[3/1/2016 IT];
  4192. /* 描述:获取指定订单的全部相片路径;
  4193. /* 参数:;
  4194. /* [IN] nImgType:相片类型(1 = 原片、2 = 初修片、3 = 精修片、4 = 设计片、5~8备份片);
  4195. /* [IN] lpBranchId:分店域名;
  4196. /* [IN] lpOrderNum:订单号;
  4197. /* [IN] bLoadInSubfolder:是否加载订单目录下的子目录;
  4198. /* [IN] lpLoadExt:要加载的相片扩展名;
  4199. /* [IN] lpWithExt:要附加的相片扩展名;
  4200. /* [IN] AryLoadExtImgpath:指定加载扩展名的相片路径;
  4201. /* [IN] AryWithExtImgpath:指定附加扩展名的相片路径;
  4202. /* [IN] AryOrderDirectory:指定订单号的相片共享目录(多目录下可能大于1);
  4203. /* 返回:void;
  4204. /* 注意:;
  4205. /* 示例:;
  4206. /*
  4207. /* 修改:;
  4208. /* 日期:;
  4209. /* 内容:;
  4210. /************************************************************************/
  4211. BOOL GetSceneryImgpathEx(IN CONST INT& nImgType, IN LPCTSTR lpBranchId, IN LPCTSTR lpOrderNum, IN LPCTSTR lpScenery, IN LPCTSTR lpLoadExt, IN LPCTSTR lpWithExt, OUT CStringArray& AryLoadExtImgpath, OUT CStringArray& AryWithExtImgpath, OUT CStringArray& AryOrderDirectory )
  4212. {
  4213. if ( lpBranchId == NULL || lpBranchId[0] == '\0' || !_tcsstr(lpBranchId, _T(".ly.com")))
  4214. {
  4215. OutputDebugString(lpBranchId);
  4216. OutputDebugString(_T("\n分店域名无效!\n"));
  4217. return FALSE;
  4218. }
  4219. if ( nImgType > DBImgtype || nImgType < OImgtype )
  4220. {
  4221. OutputDebugString(_T("\n该相片类型不存在!\n"));
  4222. return FALSE;
  4223. }
  4224. if ( g_pIMGProcess == NULL )
  4225. return FALSE;
  4226. DWORD dwReturnSize = 0;
  4227. ImgLoadOrderpathExInterface *pOrderLoader = NULL;
  4228. g_pIMGProcess->QueryInterface(IID_ImgLoadOrderpathExInterface,(void**)&pOrderLoader);
  4229. if ( pOrderLoader )
  4230. {
  4231. pOrderLoader->Release();
  4232. HGLOBAL hMemery = pOrderLoader->LoadSceneryImagesEx(nImgType, lpBranchId, lpOrderNum, lpScenery, lpLoadExt, lpWithExt, dwReturnSize);
  4233. if ( hMemery )
  4234. {
  4235. BYTE* pMemery = (BYTE*)GlobalLock(hMemery);
  4236. if ( pMemery == NULL )
  4237. {
  4238. GlobalUnlock(hMemery);
  4239. GlobalFree(hMemery);
  4240. return FALSE;
  4241. }
  4242. DWORD dwSize = 0;
  4243. DWORD dw1 = 0,dw2 = 0,dw3 = 0;
  4244. CMemFile memfile[3];
  4245. memcpy(&dw1, pMemery + dwSize, sizeof(DWORD));
  4246. dwSize += sizeof(DWORD);
  4247. memfile[0].Attach(pMemery+dwSize, dw1);
  4248. dwSize += dw1;
  4249. memcpy(&dw2, pMemery + dwSize, sizeof(DWORD));
  4250. dwSize += sizeof(DWORD);
  4251. memfile[1].Attach(pMemery+dwSize, dw2);
  4252. dwSize += dw2;
  4253. memcpy(&dw3, pMemery + dwSize, sizeof(DWORD));
  4254. dwSize += sizeof(DWORD);
  4255. memfile[2].Attach(pMemery+dwSize, dw3);
  4256. dwSize += dw3;
  4257. CArchive a1(&memfile[0],CArchive::load);
  4258. CArchive a2(&memfile[1],CArchive::load);
  4259. CArchive a3(&memfile[2],CArchive::load);
  4260. AryLoadExtImgpath.Serialize(a1);
  4261. AryWithExtImgpath.Serialize(a2);
  4262. AryOrderDirectory.Serialize(a3);
  4263. a1.Close();
  4264. a2.Close();
  4265. a3.Close();
  4266. memfile[0].Detach();
  4267. memfile[1].Detach();
  4268. memfile[2].Detach();
  4269. if (hMemery)
  4270. {
  4271. GlobalUnlock(hMemery);
  4272. GlobalFree(hMemery);
  4273. }
  4274. return TRUE;
  4275. }
  4276. }
  4277. return FALSE;
  4278. }
  4279. #endif // USE_KERNEL_DLL
  4280. /************************************************************************/
  4281. /* 函数:IsDigitString[3/28/2016 IT];
  4282. /* 描述:;
  4283. /* 参数:;
  4284. /* [IN] :;
  4285. /* 返回:返回2表示浮点型, 返回1表示整型, 返回-1表示不是数字;
  4286. /* 注意:;
  4287. /* 示例:;
  4288. /*
  4289. /* 修改:;
  4290. /* 日期:;
  4291. /* 内容:;
  4292. /************************************************************************/
  4293. int IsDigitString(IN CONST CString& str)
  4294. {
  4295. int npt = 0;
  4296. for (int i = 0; i < str.GetLength(); i++)
  4297. {
  4298. if (!_istdigit(str.GetAt(i)))
  4299. {
  4300. if ( str.GetAt(i) == _T('.') && i != 0)
  4301. {
  4302. if ( npt > 1)
  4303. {
  4304. return -1;
  4305. }
  4306. npt++;
  4307. }
  4308. else
  4309. {
  4310. return -1;
  4311. }
  4312. }
  4313. }
  4314. return npt ? 2 : 1;
  4315. }
  4316. BOOL Import2Excle(IN CListCtrl *pListCtrl, IN LPCTSTR lpExclePath, IN CONST int& nStartColumn, IN CONST int& nStartRow, IN int nEndColumn, IN int nEndRow)
  4317. {
  4318. if ( pListCtrl == NULL ||
  4319. lpExclePath == NULL ||
  4320. nStartColumn < 0 ||
  4321. nStartRow < 0 ||
  4322. (nEndColumn != -1 && nEndColumn <= nStartColumn) ||
  4323. (nEndRow != -1 && nEndRow <= nStartRow) )
  4324. {
  4325. OutputDebugString(_T("参数无效\n"));
  4326. return FALSE;
  4327. }
  4328. if ( pListCtrl->GetItemCount() - nStartRow <= 0 || (nEndRow != -1 && nEndRow >= pListCtrl->GetItemCount()))
  4329. {
  4330. OutputDebugString(_T("无中用的行\n"));
  4331. return FALSE;
  4332. }
  4333. // CListCtrl列头信息;
  4334. CHeaderCtrl* pHeaderCtrl = pListCtrl->GetHeaderCtrl();
  4335. if( !pHeaderCtrl )
  4336. {
  4337. OutputDebugString(_T("获取CListCtrl列头失败\n"));
  4338. return FALSE;
  4339. }
  4340. if ( nStartColumn >= pHeaderCtrl->GetItemCount() ||
  4341. ( nEndColumn != -1 && nEndColumn >= pHeaderCtrl->GetItemCount()) )
  4342. {
  4343. OutputDebugString(_T("所选列超出范围\n"));
  4344. return FALSE;
  4345. }
  4346. if ( nEndRow == -1 )
  4347. {
  4348. nEndRow = pListCtrl->GetItemCount();
  4349. }
  4350. if ( nEndColumn == -1 )
  4351. {
  4352. nEndColumn = pHeaderCtrl->GetItemCount();
  4353. }
  4354. // 获取列头字段信息;
  4355. LVCOLUMN lv;
  4356. TCHAR szText[MAX_PATH];
  4357. lv.mask = LVCF_TEXT;
  4358. lv.cchTextMax = MAX_PATH;
  4359. lv.pszText = szText;
  4360. int i = 0, j = 0;
  4361. BasicExcel e;
  4362. e.New(3);
  4363. e.RenameWorksheet((size_t)0, L"数据1");
  4364. BasicExcelWorksheet* sheet1 = e.GetWorksheet(L"数据1");
  4365. for( i = nStartColumn, j = 0; i < nEndColumn; i++)
  4366. {
  4367. pListCtrl->GetColumn(i, &lv);
  4368. sheet1->Cell(0,j++)->SetWString(lv.pszText);
  4369. }
  4370. // 获取数据内容;
  4371. int nRet;
  4372. CString str;
  4373. int nCurRow = 1, nCurColumn;
  4374. for ( i = nStartRow; i < nEndRow; i++, nCurRow++ )
  4375. {
  4376. nCurColumn = 0;
  4377. for ( j = nStartColumn; j < nEndColumn; j++)
  4378. {
  4379. #if 0
  4380. str = pListCtrl->GetItemText(i, j);
  4381. // 判断是数个还是字符串;
  4382. nRet = IsDigitString(str);
  4383. if ( nRet == 1 )
  4384. {
  4385. nRet = atol(str);
  4386. if ( nRet != -1 && !str.IsEmpty() && str.GetLength() < 6 ) // 6位长度不转为数字;
  4387. sheet1->Cell(nCurRow,nCurColumn++)->SetInteger(nRet);
  4388. else
  4389. sheet1->Cell(nCurRow,nCurColumn++)->SetWString(str);
  4390. }
  4391. else if ( nRet == 2 )
  4392. {
  4393. sheet1->Cell(nCurRow,nCurColumn++)->SetInteger(atof(str));
  4394. }
  4395. else
  4396. {
  4397. sheet1->Cell(nCurRow,nCurColumn++)->SetWString(str);
  4398. }
  4399. #else
  4400. str = pListCtrl->GetItemText(i, j);
  4401. sheet1->Cell(nCurRow,nCurColumn++)->SetWString(str);
  4402. #endif
  4403. }
  4404. }
  4405. e.SaveAs(lpExclePath);
  4406. return TRUE;
  4407. }
  4408. BOOL Import2Xls(IN CListCtrl *pListCtrl, IN LPCTSTR lpExclePath, IN CONST int& nStartColumn, IN CONST int& nStartRow, IN int nEndColumn, IN int nEndRow)
  4409. {
  4410. if ( pListCtrl == NULL ||
  4411. lpExclePath == NULL ||
  4412. nStartColumn < 0 ||
  4413. nStartRow < 0 ||
  4414. (nEndColumn != -1 && nEndColumn <= nStartColumn) ||
  4415. (nEndRow != -1 && nEndRow <= nStartRow) )
  4416. {
  4417. OutputDebugString(_T("参数无效\n"));
  4418. return FALSE;
  4419. }
  4420. if ( pListCtrl->GetItemCount() - nStartRow <= 0 || (nEndRow != -1 && nEndRow >= pListCtrl->GetItemCount()))
  4421. {
  4422. OutputDebugString(_T("无中用的行\n"));
  4423. return FALSE;
  4424. }
  4425. // CListCtrl列头信息;
  4426. CHeaderCtrl* pHeaderCtrl = pListCtrl->GetHeaderCtrl();
  4427. if( !pHeaderCtrl )
  4428. {
  4429. OutputDebugString(_T("获取CListCtrl列头失败\n"));
  4430. return FALSE;
  4431. }
  4432. if ( nStartColumn >= pHeaderCtrl->GetItemCount() ||
  4433. ( nEndColumn != -1 && nEndColumn >= pHeaderCtrl->GetItemCount()) )
  4434. {
  4435. OutputDebugString(_T("所选列超出范围\n"));
  4436. return FALSE;
  4437. }
  4438. if ( nEndRow == -1 )
  4439. {
  4440. nEndRow = pListCtrl->GetItemCount();
  4441. }
  4442. if ( nEndColumn == -1 )
  4443. {
  4444. nEndColumn = pHeaderCtrl->GetItemCount();
  4445. }
  4446. // 获取列头字段信息;
  4447. LVCOLUMN lv;
  4448. TCHAR szText[MAX_PATH];
  4449. lv.mask = LVCF_TEXT;
  4450. lv.cchTextMax = MAX_PATH;
  4451. lv.pszText = szText;
  4452. int i = 0, j = 0;
  4453. CArray<CStringArray,CStringArray> AryData;
  4454. AryData.SetSize(nEndRow - nStartRow + 1);
  4455. //AryData.RemoveAll();
  4456. AryData.ElementAt(0).RemoveAll();
  4457. for( i = nStartColumn, j = 0; i < nEndColumn; i++)
  4458. {
  4459. pListCtrl->GetColumn(i, &lv);
  4460. AryData.ElementAt(0).Add(lv.pszText);
  4461. }
  4462. // 获取数据内容;
  4463. int nRet;
  4464. CString str;
  4465. int nCurRow = 1, nCurColumn;
  4466. for ( i = nStartRow; i < nEndRow; i++, nCurRow++ )
  4467. {
  4468. nCurColumn = 0;
  4469. AryData.ElementAt(nCurRow).RemoveAll();
  4470. for ( j = nStartColumn; j < nEndColumn; j++)
  4471. {
  4472. AryData.ElementAt(nCurRow).Add(pListCtrl->GetItemText(i, j));
  4473. }
  4474. }
  4475. // 将数据序列化到文件中;
  4476. CMemFile Mef;
  4477. CArchive ar(&Mef, CArchive::store);
  4478. for ( i = 0; i < AryData.GetSize(); i++ )
  4479. {
  4480. AryData.ElementAt(i).Serialize(ar);
  4481. }
  4482. ar.Close();
  4483. DWORD fLength = Mef.GetLength();
  4484. PBYTE pData = Mef.Detach();
  4485. CFile fb;
  4486. str.Format(_T("%s.dat"), lpExclePath);
  4487. if (fb.Open(str, CFile::modeCreate|CFile::modeWrite))
  4488. {
  4489. DWORD dwArySize = nEndRow - nStartRow + 1;
  4490. fb.Write(&dwArySize, sizeof(DWORD));
  4491. fb.Write(pData,fLength); // 写入数组内容;
  4492. DWORD dwFlag = 889900;
  4493. fb.Write(&dwFlag,sizeof(DWORD)); // 写入结束标记;
  4494. fb.Close();
  4495. }
  4496. return TRUE;
  4497. }
  4498. TCHAR* GetGuidString()
  4499. {
  4500. GUID guid;
  4501. static TCHAR szBuf[64] = {0};
  4502. memset(szBuf, 0, 64*sizeof(TCHAR));
  4503. CoInitialize(NULL);
  4504. if (S_OK == ::CoCreateGuid(&guid))
  4505. {
  4506. sprintf(szBuf, _T("{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}"),
  4507. guid.Data1,
  4508. guid.Data2,
  4509. guid.Data3,
  4510. guid.Data4[0],
  4511. guid.Data4[1],
  4512. guid.Data4[2],
  4513. guid.Data4[3],
  4514. guid.Data4[4],
  4515. guid.Data4[5],
  4516. guid.Data4[6],
  4517. guid.Data4[7]
  4518. );
  4519. }
  4520. CoUninitialize();
  4521. return szBuf;
  4522. }
  4523. BOOL IsWow64()
  4524. {
  4525. typedef BOOL(WINAPI *LPFN_ISWOW64PROCESS)(HANDLE, PBOOL);
  4526. LPFN_ISWOW64PROCESS fnIsWow64Process;
  4527. BOOL bIsWow64 = FALSE;
  4528. fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
  4529. if (NULL != fnIsWow64Process)
  4530. {
  4531. if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
  4532. {
  4533. // 句柄错误,则系统不是64位;
  4534. }
  4535. }
  4536. return bIsWow64;
  4537. }