Global.cpp 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501
  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 "afxcoll.h"
  8. #include "afxtempl.h"
  9. #include "atlconv.h"
  10. #include <tlhelp32.h>
  11. #include <WinSock.h>
  12. #include "..\\lzari.h"
  13. #include "..\helper\ffsco.h"
  14. //#include <WS2tcpip.h>
  15. //////////////////////////////////////////////////////////////////////////
  16. static const int BEGIN_YEAR = 1901;
  17. static const int NUMBER_YEAR = 199;
  18. static const unsigned int LUNAR_YEARS[199] =
  19. {
  20. 0x04AE53, 0x0A5748, 0x5526BD, 0x0D2650, 0x0D9544, 0x46AAB9, 0x056A4D, 0x09AD42, 0x24AEB6, 0x04AE4A, //1901-1910
  21. 0x6A4DBE, 0x0A4D52, 0x0D2546, 0x5D52BA, 0x0B544E, 0x0D6A43, 0x296D37, 0x095B4B, 0x749BC1, 0x049754, //1911-1920
  22. 0x0A4B48, 0x5B25BC, 0x06A550, 0x06D445, 0x4ADAB8, 0x02B64D, 0x095742, 0x2497B7, 0x04974A, 0x664B3E, //1921-1930
  23. 0x0D4A51, 0x0EA546, 0x56D4BA, 0x05AD4E, 0x02B644, 0x393738, 0x092E4B, 0x7C96BF, 0x0C9553, 0x0D4A48, //1931-1940
  24. 0x6DA53B, 0x0B554F, 0x056A45, 0x4AADB9, 0x025D4D, 0x092D42, 0x2C95B6, 0x0A954A, 0x7B4ABD, 0x06CA51, //1941-1950
  25. 0x0B5546, 0x555ABB, 0x04DA4E, 0x0A5B43, 0x352BB8, 0x052B4C, 0x8A953F, 0x0E9552, 0x06AA48, 0x7AD53C, //1951-1960
  26. 0x0AB54F, 0x04B645, 0x4A5739, 0x0A574D, 0x052642, 0x3E9335, 0x0D9549, 0x75AABE, 0x056A51, 0x096D46, //1961-1970
  27. 0x54AEBB, 0x04AD4F, 0x0A4D43, 0x4D26B7, 0x0D254B, 0x8D52BF, 0x0B5452, 0x0B6A47, 0x696D3C, 0x095B50, //1971-1980
  28. 0x049B45, 0x4A4BB9, 0x0A4B4D, 0xAB25C2, 0x06A554, 0x06D449, 0x6ADA3D, 0x0AB651, 0x093746, 0x5497BB, //1981-1990
  29. 0x04974F, 0x064B44, 0x36A537, 0x0EA54A, 0x86B2BF, 0x05AC53, 0x0AB647, 0x5936BC, 0x092E50, 0x0C9645, //1991-2000
  30. 0x4D4AB8, 0x0D4A4C, 0x0DA541, 0x25AAB6, 0x056A49, 0x7AADBD, 0x025D52, 0x092D47, 0x5C95BA, 0x0A954E, //2001-2010
  31. 0x0B4A43, 0x4B5537, 0x0AD54A, 0x955ABF, 0x04BA53, 0x0A5B48, 0x652BBC, 0x052B50, 0x0A9345, 0x474AB9, //2011-2020
  32. 0x06AA4C, 0x0AD541, 0x24DAB6, 0x04B64A, 0x69573D, 0x0A4E51, 0x0D2646, 0x5E933A, 0x0D534D, 0x05AA43, //2021-2030
  33. 0x36B537, 0x096D4B, 0xB4AEBF, 0x04AD53, 0x0A4D48, 0x6D25BC, 0x0D254F, 0x0D5244, 0x5DAA38, 0x0B5A4C, //2031-2040
  34. 0x056D41, 0x24ADB6, 0x049B4A, 0x7A4BBE, 0x0A4B51, 0x0AA546, 0x5B52BA, 0x06D24E, 0x0ADA42, 0x355B37, //2041-2050
  35. 0x09374B, 0x8497C1, 0x049753, 0x064B48, 0x66A53C, 0x0EA54F, 0x06B244, 0x4AB638, 0x0AAE4C, 0x092E42, //2051-2060
  36. 0x3C9735, 0x0C9649, 0x7D4ABD, 0x0D4A51, 0x0DA545, 0x55AABA, 0x056A4E, 0x0A6D43, 0x452EB7, 0x052D4B, //2061-2070
  37. 0x8A95BF, 0x0A9553, 0x0B4A47, 0x6B553B, 0x0AD54F, 0x055A45, 0x4A5D38, 0x0A5B4C, 0x052B42, 0x3A93B6, //2071-2080
  38. 0x069349, 0x7729BD, 0x06AA51, 0x0AD546, 0x54DABA, 0x04B64E, 0x0A5743, 0x452738, 0x0D264A, 0x8E933E, //2081-2090
  39. 0x0D5252, 0x0DAA47, 0x66B53B, 0x056D4F, 0x04AE45, 0x4A4EB9, 0x0A4D4C, 0x0D1541, 0x2D92B5 //2091-2099
  40. };
  41. //////////////////////////////////////////////////////////////////////////
  42. // 异地选片 [4/1/2015 lyfz]
  43. //////////////////////////////////////////////////////////////////////////
  44. BOOL g_bRemote = FALSE;
  45. //////////////////////////////////////////////////////////////////////////
  46. HMODULE g_hlyfzMicroShareDLL = NULL;
  47. lyfzCreateShare g_lyfzCreateShare = NULL;
  48. // 升级包版本号;
  49. WORD g_arrFileVersion[4] = { 0 };
  50. TCHAR g_szLoginUser[MAX_PATH] = _T(""); // 当前软件的登陆用户名;
  51. TCHAR g_szLoginPsw[MAX_PATH] = _T(""); // 当前软件的登陆密码;
  52. TCHAR g_szModulePath[MAX_PATH] = _T(""); // 软件目录;
  53. TCHAR g_szModuleFileName[MAX_PATH] = _T(""); // 软件全名称;
  54. TCHAR g_szConnectString[MAX_PATH] = _T(""); // DB连接串;
  55. // 主机信息;
  56. TCHAR g_szHostComputerIP[MAX_PATH] = _T(""); // 服务端主机名称;
  57. DWORD g_dwTCPChatPort; // 服务端主机通信TCP端口;
  58. // 数据库信息;
  59. TCHAR g_szDBSource[MAX_PATH] = _T(""); // 数据库源(服务所在IP或计算机名);
  60. TCHAR g_szDBSourcePort[MAX_PATH] = _T(""); // 数据库源端口;
  61. DWORD g_dwDBServerPort = 0; // 数据库源端口;
  62. TCHAR g_szDBAccount[MAX_PATH] = _T(""); // 数据库登录用户;
  63. TCHAR g_szDBPassWord[MAX_PATH] = _T(""); // 数据库登录密码;
  64. TCHAR g_szDBName[MAX_PATH] = _T(""); // 数据库名称;
  65. // 相片存储目录;
  66. TCHAR g_szShareHost[MAX_PATH] = _T(""); // 共享主机名;
  67. TCHAR g_szOriginalFolder[MAX_PATH] = _T(""); // 原片目录;
  68. TCHAR g_szOriginalBkFolder[MAX_PATH] = _T(""); // 原片备份目录;
  69. TCHAR g_szEarlyRepairFolder[MAX_PATH] = _T(""); // 初修片目录;
  70. TCHAR g_szEarlyRepairBkFolder[MAX_PATH] = _T(""); // 初修片备份目录;
  71. TCHAR g_szFurtherRepairFolder[MAX_PATH] = _T(""); // 精修片目录;
  72. TCHAR g_szFurtherRepairBkFolder[MAX_PATH] = _T(""); // 精修片备份目录;
  73. TCHAR g_szDesignFolder[MAX_PATH] = _T(""); // 设计片目录;
  74. TCHAR g_szDesignBkFolder[MAX_PATH] = _T(""); // 设计片备份目录;
  75. TCHAR g_szTelRecordingFolder[MAX_PATH] = _T(""); // 电话录音目录;
  76. TCHAR g_szFullDressImageFolder[MAX_PATH] = _T(""); // 礼服图片目录;
  77. // 软件所用加密狗是否已注册; // Jeff,应该放在SoftKey做为静态变量使用;
  78. BOOL g_bSoftWareReg = FALSE;
  79. // 加密狗中的字符信息S1:如 201409062003558789.ly.com
  80. // 该全局变量在旧软件名称是:g_sdomain;
  81. // 该变量在数据库表字段[path].[path1]中存储;
  82. CString g_strDogMainInfo = "";
  83. // 未知用途;
  84. // 该全局变量在旧软件中名称是:CString g_bMain;
  85. // 与集团版有关联性;
  86. // 有可能是主店名称;
  87. CString g_strMain = "";
  88. // 分店名称数组;旧软件中名称:g_branchnamearray
  89. CStringArray g_strArrayOfBranchName;
  90. // ??
  91. CStringArray g_strArrayOfBranchName2;
  92. // 分店IP地址数组;
  93. CStringArray g_strArrayOfBranchIPAdress;
  94. // 分店的加密狗S1信息数组;
  95. CStringArray g_strArrayOfBranchDogMainInfo;
  96. // 座席版允许连接数(从加密狗中获取);
  97. unsigned int g_nCountOfAllowToConn = 0;
  98. DWORD g_nLeng = 0;
  99. BYTE *g_pData = NULL;
  100. DWORD g_nLeng2 = 0;
  101. BYTE *g_pData2 = NULL;
  102. SENDHEAD g_sendhead;
  103. BOOL g_bRedSkin = 0;
  104. COLORREF g_gridcol1 = RGB(204, 204, 204);
  105. COLORREF g_gridcol2 = RGB(190, 190, 190);
  106. COLORREF g_bkcol = RGB(184, 184, 184);
  107. CString g_date;
  108. CString g_title;
  109. CArray<CStringArray, CStringArray>g_userarray;
  110. CArray<CStringArray, CStringArray>g_cominfoarray;
  111. CArray<CStringArray, CStringArray>g_cominfoarraylocal;
  112. CArray<DWORD, DWORD>g_lengarray;
  113. CArray<DWORD, DWORD>g_btnlengarray;
  114. CArray<BYTE*, BYTE*>g_pointerarray;
  115. CBrush g_editbkbrush;
  116. DWORD g_btnleng[8];
  117. int g_btnlengpos = -1;
  118. int g_nYearpos = -1;
  119. CString g_branchname = ""; // Jeff.集团版:????本分店名称;
  120. CString g_branchip = "";
  121. CString g_branchip2 = "";
  122. BOOL g_bBranchModify = 0;
  123. BOOL g_bShowOK = 0; // Jeff:?
  124. BOOL g_bStaffAchievementShow = 0; // 此机用于员工业绩查看;
  125. BOOL g_bSaveUploadTask1 = 0;
  126. BOOL g_bSaveUploadTask2 = 0;
  127. BOOL g_bSaveUploadTask3 = 0;
  128. BOOL g_bSaveUploadTask4 = 0;
  129. BOOL g_bSearchFilter = 0;
  130. CString g_waiter1;
  131. CString g_waiter2;
  132. CString g_waiter3;
  133. CString g_waiter4;
  134. CString g_waiter5;
  135. CString g_filterdate1;
  136. CString g_filterdate2;
  137. CString g_filterdate3;
  138. CString g_filterdate4;
  139. CString g_filterdate5;
  140. CString g_filterdate6;
  141. CString g_filterbranch;
  142. USER g_user;
  143. CString g_mainpath; // 软件目录
  144. CString g_id; //
  145. CString g_server; // 服务端地址
  146. CStringArray g_serverarray; //
  147. CString g_serverbak; //
  148. CString g_path1; /* 共享目录 <客户原片(管理软件)$> 如:"\\lyfz-pc\客户原片(管理软件)$" */
  149. CString g_path2; /* 共享目录 <修好的片(管理软件)$> 如:"\\lyfz-pc\修好的片(管理软件)$" */
  150. CString g_path3; /* 共享目录 <设计好的片(管理软件$)> 如:""> */
  151. CString g_path4; /* 共享目录 <精修好的片(管理软件$)> 如:""> */
  152. CString g_path5; /* 共享目录 <礼服图片(管理软件$)> 如:""> */
  153. CString g_path6; /* 共享目录 <电话录音(管理软件$)> 如:""> */
  154. CString g_path7; /* 共享目录 <客户原片(管理软件$)\效果图> 如:""> */
  155. CString g_path1bak;
  156. CString g_path2bak;
  157. CString g_path3bak;
  158. CString g_path4bak;
  159. CString g_path5bak;
  160. CString g_path6bak;
  161. CString g_path7bak;
  162. CDatabase g_db;
  163. DWORD g_ncount;
  164. CFont g_titlefont;
  165. DWORD g_nSendCode = 0;
  166. BOOL g_bSendOK = 0;
  167. CString g_temp;
  168. CArray<CStringArray, CStringArray>g_hisyeararray;
  169. CArray<CStringArray, CStringArray>g_brancharray;
  170. CArray<CStringArray, CStringArray>g_oldclientarray;
  171. BOOL g_bNoConnDlg = 0;
  172. BOOL g_bInSkin = 0;
  173. BOOL g_bGenBranchData = 0;
  174. BOOL g_bSortAscending = FALSE;
  175. CFont g_listctrlfont;
  176. float g_fscalex; // x坐标刻度
  177. float g_fscaley; // y坐标刻度
  178. int g_screenwid; // 桌面宽
  179. int g_screenhei; // 桌面高
  180. float g_WidthScale2 = 1;
  181. float g_HeightScale2 = 1;
  182. RESDATA2 g_resdata2;
  183. BOOL g_bAlphaWnd = 0;
  184. BYTE g_bNeedDrawParent = 0;
  185. BOOL g_bAllBranch = 0;
  186. CString g_domain;
  187. CString g_sInfo;
  188. int g_ncot = 0; // Jeff:订单总数(包含历史订单在内),该变量作用是当订单总数大于1000时,向公司服务器发送数据;
  189. int g_conpos = 0;
  190. int g_nAutoShowStaffAchievement = -1;
  191. BOOL g_bShowBar = 1;
  192. int g_bookingtype = 0;
  193. BOOL g_bNoLoginLia = 0;
  194. BOOL g_bConnLYFZ = 0;
  195. BOOL g_bSendLYFZ = 0;
  196. int g_ntimeout = 29000;
  197. float g_WidthScale;
  198. float g_HeightScale;
  199. int g_dx = 0;
  200. int g_dy = 0;
  201. BOOL g_bNeedCoon = 1; // remark by Jeff:是否需要重新连接服务端;
  202. CStringArray g_menubranchname;
  203. CArray<CStringArray, CStringArray>g_List1array;
  204. /************************************************************************/
  205. /*
  206. Jeff:g_conntype
  207. g_conntype == 0 :表示正常连接?(或是连接本地服务器?)
  208. g_conntype == 1 :表示连接公司服务器(http://lijiafz.vicp.net)
  209. g_conntype == 2 :http://www.lyfz.net/download/ip.txt
  210. g_conntype == 3 :http://photo.bjlyfz.com/download/ip.txt
  211. g_conntype == 4 :
  212. */
  213. /************************************************************************/
  214. int g_conntype = 0;//正常
  215. //0 正常
  216. //1 连接1
  217. //2 连接2
  218. //3 连接3
  219. //4 连接4
  220. //************************************//
  221. // 数据库地址;
  222. // 数据库端口;
  223. // 数据库管理员账号;
  224. // 数据库管理员密码;
  225. // 数据库名称;
  226. //
  227. // [函数]:GetIniInfo
  228. // [描述]:获取指定ini信息;
  229. // [参数]:
  230. // szPath:ini所在目录;
  231. // szIniName:ini名;
  232. // [返回]:void
  233. //************************************//
  234. int GetSysIniInfo(const char *szPath, const char *szIniName)
  235. {
  236. TCHAR szDrive[_MAX_DRIVE] = { 0 };
  237. TCHAR szDir[_MAX_DIR] = { 0 };
  238. TCHAR szFna[_MAX_DIR] = { 0 };
  239. TCHAR szExt[_MAX_DIR] = { 0 };
  240. ::GetModuleFileName(NULL, g_szModuleFileName, sizeof(g_szModuleFileName) / sizeof(TCHAR));
  241. sprintf(g_szModulePath, _T("%s"), g_szModuleFileName);
  242. _tsplitpath(g_szModulePath, szDrive, szDir, szFna, szExt);
  243. _tcscpy(g_szModulePath, szDrive);
  244. _tcscat(g_szModulePath, szDir);
  245. // -----------------------------------------------------//
  246. TCHAR szFile[MAX_PATH + 1] = "";
  247. if (szPath != NULL && szIniName != NULL)
  248. wsprintf(szFile, _T("%s\\%s"), szPath, szIniName);
  249. else
  250. wsprintf(szFile, _T("%s\\HostInfo.ini"), g_szModulePath);
  251. TRACE("szFile =%s\n", szFile);
  252. OFSTRUCT ofStruct;
  253. OpenFile(szFile, &ofStruct, OF_EXIST); // Jeff 这是为了兼容16位系统遗留的函数,不应该使用;
  254. if (ERROR_FILE_NOT_FOUND == GetLastError())
  255. {
  256. // 如果没找到,使用默认连接;
  257. strcpy(g_szHostComputerIP, _T("."));
  258. g_dwTCPChatPort = 5678;
  259. return -1;
  260. }
  261. // 获取服务器端TCP信息;
  262. GetPrivateProfileString(_T("HostComputerInfo"), _T("HostIP"), _T(""), g_szHostComputerIP, MAX_PATH, szFile);
  263. g_dwTCPChatPort = GetPrivateProfileInt(_T("HostComputerInfo"), _T("HostChatPort"), 0, szFile);
  264. return 0;
  265. }
  266. //----------------------------------------------------------
  267. // 函数:IsFileExist
  268. // 描述:判断某文件是否存在;
  269. // 参数:
  270. // pFileFullName: 指定的文件名;
  271. // 返回:TRUE表示文件存在;
  272. //----------------------------------------------------------
  273. BOOL IsFileExist(const TCHAR *pFileFullName)
  274. {
  275. int err = 0;
  276. // Check for existence.
  277. if ((err = _access(pFileFullName, 0)) == 0)
  278. {
  279. //printf_s( "File crt_access_s.c exists.\n" );
  280. // Check for write permission.
  281. if ((err = _access(pFileFullName, 2)) == 0)
  282. {
  283. //printf_s( "File crt_access_s.c does have ""write permission.\n" );
  284. }
  285. else
  286. {
  287. //printf_s( "File crt_access_s.c does not have ""write permission.\n" );
  288. }
  289. }
  290. else
  291. {
  292. //printf_s( "File crt_access_s.c does not exist.\n" );
  293. return FALSE;
  294. }
  295. return TRUE;
  296. }
  297. // Pump messages while waiting for event
  298. //----------------------------------------------------------
  299. // 函数:WaitWithMessageLoop
  300. // 描述:等待某内核事件触发;
  301. // 参数:
  302. // hEvent: 被等待响应的内核事件对象;
  303. // nTimeout: 超时值;
  304. // 返回:TRUE返回触发成功;
  305. //----------------------------------------------------------
  306. BOOL WaitWithMessageLoop(HANDLE hEvent, int nTimeout)
  307. {
  308. DWORD dwRet = 0;
  309. while (1)
  310. {
  311. // wait for event or message, if it's a message, process it and return to waiting state
  312. dwRet = MsgWaitForMultipleObjects(1, &hEvent, FALSE, nTimeout, QS_ALLINPUT);
  313. if (dwRet == WAIT_OBJECT_0)
  314. {
  315. TRACE0("WaitWithMessageLoop() event triggered.\n");
  316. return TRUE;
  317. }
  318. else
  319. if (dwRet == WAIT_OBJECT_0 + 1)
  320. {
  321. // process window messages
  322. AfxGetApp()->PumpMessage();
  323. }
  324. else
  325. if (dwRet == WAIT_TIMEOUT)
  326. {
  327. // timed out !
  328. return FALSE;
  329. }
  330. else
  331. {
  332. // WAIT_ABANDONED_0 ...
  333. return TRUE;
  334. }
  335. }
  336. }
  337. //----------------------------------------------------------
  338. // 函数:DeleteDirectory
  339. // 描述:删除指定目录下的所有文件;
  340. // 参数:strDir:指定要删除的文件目录;
  341. // 返回:;
  342. //----------------------------------------------------------
  343. void DeleteDirectory(CString strDir)
  344. {
  345. try
  346. {
  347. // 首先删除文件及子文件夹
  348. CFileFind ff;
  349. BOOL bFound = ff.FindFile(strDir + "\\*", 0);
  350. while (bFound)
  351. {
  352. bFound = ff.FindNextFile();
  353. if (ff.GetFileName() == "." || ff.GetFileName() == "..")
  354. continue;
  355. // 去掉文件(夹)只读等属性
  356. SetFileAttributes(ff.GetFilePath(), FILE_ATTRIBUTE_NORMAL);
  357. if (ff.IsDirectory())
  358. { // 递归删除子文件夹
  359. DeleteDirectory(ff.GetFilePath());
  360. RemoveDirectory(ff.GetFilePath());
  361. }
  362. else
  363. {
  364. DeleteFile(ff.GetFilePath()); // 递归 删除文件
  365. }
  366. }
  367. ff.Close();
  368. // 然后删除该文件夹
  369. RemoveDirectory(strDir);
  370. }
  371. catch (...)
  372. {
  373. //WriteLogin("出错在函数deldir中");
  374. }
  375. // int SHFileOperation( LPSHFILEOPSTRUCT lpFileOp );
  376. }
  377. // Jeff.注册控件函数;2014.09.11
  378. //----------------------------------------------------------
  379. // 函数:RegisterOcx
  380. // 描述:注册指定的组件文件;
  381. // 参数:ocxfile指定要注册的组件文件名;
  382. // 返回:TRUE表示注册成功;
  383. //----------------------------------------------------------
  384. BOOL RegisterOcx(LPCTSTR ocxfile)
  385. {
  386. HKEY hKey;
  387. bool bRet;
  388. USES_CONVERSION;
  389. ITypeLib* pTypeLib;
  390. CString CLSIDStr;
  391. CLSID clsid;
  392. LPOLESTR wRes = NULL;
  393. if (LoadTypeLib(T2OLE(ocxfile), &pTypeLib) == S_OK)
  394. {
  395. TLIBATTR tlibAttr, *ptlibAttr;
  396. ptlibAttr = &tlibAttr;
  397. pTypeLib->GetLibAttr(&ptlibAttr);
  398. clsid = ptlibAttr->guid;
  399. pTypeLib->Release();
  400. }
  401. ::StringFromCLSID(clsid, &wRes);
  402. CLSIDStr = OLE2CT(wRes);
  403. 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))
  404. {
  405. return true;
  406. }
  407. else
  408. {
  409. HINSTANCE hLib = LoadLibrary(ocxfile);
  410. if (hLib < (HINSTANCE)HINSTANCE_ERROR)
  411. {
  412. MessageBox(0, "权限不足,不能载入OCX文件!无法注册控件!", "结果", MB_OK);
  413. bRet = false;
  414. }
  415. else
  416. {
  417. FARPROC lpDllEntryPoint;
  418. lpDllEntryPoint = GetProcAddress(hLib, _T("DllRegisterServer"));
  419. if (lpDllEntryPoint != NULL)
  420. {
  421. if (FAILED((*lpDllEntryPoint)()))
  422. {
  423. MessageBox(0, "调用注册函数(DllRegisterServer)失败!无法注册控件!", "结果", MB_OK);
  424. bRet = false;
  425. }
  426. else
  427. bRet = true;
  428. }
  429. else
  430. {
  431. MessageBox(0, "调用注册函数(DllRegisterServer)失败!无法注册控件!", "结果", MB_OK);
  432. bRet = false;
  433. }
  434. }
  435. FreeLibrary(hLib);
  436. return bRet;
  437. }
  438. }
  439. // Jeff.Hacker. WINDOWS NT 以上的内核需要提权,才能对系统进行高级管理;
  440. //----------------------------------------------------------
  441. // 函数:GetDebugPriv
  442. // 描述:对程序提权;
  443. // 参数:
  444. // 返回:TRUE表示程序提权成功;
  445. //----------------------------------------------------------
  446. BOOL GetDebugPriv()
  447. {
  448. // 返回的访问令牌指针;
  449. HANDLE hToken;
  450. // 接收所返回的制定特权名称的信息;
  451. LUID sedebugnameValue;
  452. // 新特权信息的指针(结构体);
  453. TOKEN_PRIVILEGES tkp;
  454. DWORD dwCurProcId = GetCurrentProcessId();
  455. // 要修改访问权限的进程句柄;
  456. HANDLE hCurProc;
  457. hCurProc = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwCurProcId);
  458. if (!::OpenProcessToken(hCurProc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
  459. {
  460. ShowSystemErrorInfo(CString("提权OpenProcessToken失败。"), GetLastError());
  461. return FALSE;
  462. }
  463. if (!::LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &sedebugnameValue))
  464. {
  465. ShowSystemErrorInfo(CString("提权LookupPrivilegeValue失败。"), GetLastError());
  466. CloseHandle(hToken);
  467. return FALSE;
  468. }
  469. tkp.PrivilegeCount = 1;
  470. tkp.Privileges[0].Luid = sedebugnameValue;
  471. tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  472. if (!::AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof tkp, NULL, NULL))
  473. {
  474. ShowSystemErrorInfo(CString("提权AdjustTokenPrivileges失败。"), GetLastError());
  475. CloseHandle(hToken);
  476. return FALSE;
  477. }
  478. CloseHandle(hCurProc);
  479. CloseHandle(hToken);
  480. return TRUE;
  481. }
  482. //----------------------------------------------------------
  483. // 函数:GetFileVersion
  484. // 描述:获取指定模块的文件版本信息
  485. // 参数:
  486. // hModule: 指定的模块(如果为NULL,表示获取自身文件版本信息);
  487. // pBuffer: 返回的文件版本信息;
  488. //
  489. // 返回:TRUE表示获取模块文件版本信息成功;
  490. //----------------------------------------------------------
  491. bool GetFileVersion(HMODULE hModule, WORD *pBuffer)
  492. {
  493. TCHAR fname[MAX_PATH];
  494. VS_FIXEDFILEINFO *pVi;
  495. DWORD dwHandle;
  496. std::string str;
  497. if (::GetModuleFileName(hModule, fname, MAX_PATH))
  498. {
  499. int size = GetFileVersionInfoSize(fname, &dwHandle);
  500. if (size > 0)
  501. {
  502. BYTE *buffer = new BYTE[size];
  503. memset(buffer, 0, size);
  504. if (GetFileVersionInfo(fname, dwHandle, size, buffer))
  505. {
  506. if (VerQueryValue(buffer, _T("\\"), (LPVOID *)&pVi, (PUINT)&size))
  507. {
  508. pBuffer[0] = HIWORD(pVi->dwFileVersionMS);
  509. pBuffer[1] = LOWORD(pVi->dwFileVersionMS);
  510. pBuffer[2] = HIWORD(pVi->dwFileVersionLS);
  511. pBuffer[3] = LOWORD(pVi->dwFileVersionLS);
  512. delete buffer;
  513. return true;
  514. }
  515. }
  516. delete buffer;
  517. }
  518. }
  519. return false;
  520. }
  521. //----------------------------------------------------------
  522. // 函数:CheckInternalIP
  523. // 描述:判断IP(网络字节序)地址是否为外网地址;
  524. // 参数:ip_addr:主机IP(必须为网络字节序);
  525. //
  526. // 返回:TRUE表示主机IP为外网IP; FALSE表示内网IP;
  527. //----------------------------------------------------------
  528. BOOL CheckInternalIPV4(const unsigned int &ip_addr)
  529. {
  530. // 三段保留IP段,做为私有地址,不在在公网上使用,只作内网IP;
  531. // A类:10.0.0.0 ~ 10.255.255.255 = 0A.00.00.00 ~ 0A.FF.FF.FF
  532. // B类:172.16.0.0 ~ 172.31.255.255 = AC.10.00.00 ~ AC.1F.FF.FF
  533. // C类:192.168.0.0 ~ 192.168.255.255 = C0.A8.00.00 ~ C0.A8.FF.FF
  534. // D类:127.0.0.0 ~ 127.255.255.255 = 7F.00.00.00 ! 7F.FF.FF.FF (环回地址)
  535. #if 0
  536. //检查3类地址是否属于公网;
  537. if ((ip_addr >= 0x0A000000 && ip_addr <= 0x0AFFFFFF) ||
  538. (ip_addr >= 0xAC100000 && ip_addr <= 0xAC1FFFFF) ||
  539. (ip_addr >= 0xC0A80000 && ip_addr <= 0xC0A8FFFF)
  540. )
  541. {
  542. return FALSE;
  543. }
  544. return TRUE;
  545. #endif
  546. #if 0
  547. //检查3类地址是否属于内网;
  548. // 0xa -- "10.0.0.0">>24;
  549. // 0xc0a8--"192.168.0.0.">>16;
  550. // 0x2b0--"127.17.0.1">>22
  551. if ((ip_addr >> 24 == 0xa) || (ip_addr >> 16 == 0xc0a8) || (ip_addr >> 22 == 0x2b0))
  552. return FALSE;
  553. else
  554. return TRUE;
  555. #endif
  556. #if 1
  557. // 回环地址也算进去!
  558. if ((ip_addr >> 24 == 0x0A) || (ip_addr >> 20 == 0xAC1) || (ip_addr >> 16 == 0xC0A8) || (ip_addr >> 26 == 0x7))
  559. return FALSE;
  560. else
  561. return TRUE;
  562. #endif
  563. }
  564. //----------------------------------------------------------
  565. // 函数:IsValidIPV4
  566. // 描述:判断字符串是否是有效的IPV4;
  567. // 参数:szIP:主机IP;
  568. //
  569. // 返回:TRUE表示字符串为有效的IPV4;
  570. //----------------------------------------------------------
  571. BOOL IsValidIPV4(const TCHAR *szIP)
  572. {
  573. int nIndex = 0;
  574. int nPointCount = 0; // "."IPV4有3个;
  575. int nLen = strlen(szIP);
  576. for (int i = 0; i < nLen; i++)
  577. {
  578. if (szIP[i] == '.')
  579. {
  580. if (i == 0 || i == nLen - 1)
  581. {
  582. return FALSE;
  583. }
  584. else
  585. {
  586. if (++nIndex != i)
  587. {
  588. nIndex = i;
  589. nPointCount++;
  590. }
  591. else
  592. return FALSE;
  593. }
  594. continue;
  595. }
  596. if (isdigit(szIP[i]) == 0)
  597. return FALSE;
  598. }
  599. if (nPointCount != 3)
  600. return FALSE;
  601. return TRUE;
  602. }
  603. //----------------------------------------------------------
  604. // 函数:GetHostAllOfIP
  605. // 描述:返回指定主机名称的所有IPV4地址;
  606. // 参数:
  607. // pHostName: 主机名;
  608. // vtHostIPV4:指定主机名的所有IPV4地址;
  609. //
  610. // 返回:TRUE表示字符串为有效的IPV4;
  611. //----------------------------------------------------------
  612. int GetHostAllOfIP(const TCHAR *pHostName, std::vector<std::string> &vtHostIPV4)
  613. {
  614. #if 0
  615. WSADATA wsa = { 0 };
  616. WSAStartup(MAKEWORD(2, 2), &wsa);
  617. #endif
  618. #if 0 // YLGL项目使用不了,因为包含了旧的系统头文件;
  619. addrinfo hint, *answer, *curr;
  620. memset(&hint, 0, sizeof(addrinfo));
  621. hint.ai_family = AF_INET;
  622. hint.ai_socktype = SOCK_STREAM;
  623. int nRet = GetAddrInfo(pHostName, NULL, &hint, &answer);
  624. //int nRet = GetAddrInfo(pHostName, "5678", &hint, &answer);
  625. if (nRet != 0)
  626. {
  627. DWORD dwError = GetLastError();
  628. return;
  629. }
  630. TCHAR szIP[MAX_PATH];
  631. for (curr = answer; curr != NULL; curr = curr->ai_next)
  632. {
  633. //std::string ipstr;
  634. memset(szIP, 0, MAX_PATH);
  635. inet_ntop(AF_INET, &(((sockaddr_in*)(curr->ai_addr))->sin_addr), szIP, MAX_PATH);
  636. vtHostIPV4.push_back(szIP);
  637. }
  638. freeaddrinfo(answer);
  639. #endif
  640. return 0;
  641. }
  642. void DataToArray(CArray<CStringArray, CStringArray>*pArrayOfString, int datapos)
  643. {
  644. try
  645. {
  646. pArrayOfString->RemoveAll();
  647. if (g_nLeng == 0)
  648. {
  649. return;
  650. }
  651. // 1.code[0]数组:用作发送时,存储着操作指令;用作接收时,存储着接收数据大小???;
  652. if (g_sendhead.code[0])
  653. {
  654. // 1.1.将g_pData全局变量里保存的数据进行解压,并存储在lpszOut数组里;
  655. BYTE *lpszOut = NULL;
  656. int nOutSize = 0;
  657. LZARI Lzari;
  658. Lzari.UnCompress(g_pData, g_nLeng, lpszOut, nOutSize);
  659. // 1.2.将解压后的数据lpszOut附加到内存文件里;
  660. CMemFile memfile;
  661. memfile.Attach(lpszOut, nOutSize);
  662. Lzari.Release();
  663. // 1.3.将内存文件序列化保存到CArchive对象里;
  664. CArchive ar(&memfile, CArchive::load);
  665. pArrayOfString->SetSize(g_sendhead.count[0]);
  666. // 1.4.将CArchive对象里的数据,序列化到指定的CArray对象里;
  667. for (int ii = 0; ii < pArrayOfString->GetSize(); ii++)
  668. {
  669. pArrayOfString->ElementAt(ii).Serialize(ar);
  670. }
  671. // 1.5.完成数据的导出任务,释放内存;
  672. ar.Close();
  673. memfile.Detach();
  674. }
  675. else
  676. {
  677. CMemFile memfile;
  678. memfile.Attach(g_pData, g_nLeng);
  679. CArchive ar(&memfile, CArchive::load);
  680. pArrayOfString->SetSize(g_sendhead.count[0]);
  681. for (int ii = 0; ii < pArrayOfString->GetSize(); ii++)
  682. {
  683. pArrayOfString->ElementAt(ii).Serialize(ar);
  684. }
  685. ar.Close();
  686. memfile.Detach();
  687. }
  688. }
  689. catch (...)
  690. {
  691. }
  692. }
  693. void DataToArray(
  694. CArray<CStringArray, CStringArray>*pArrayOfString1,
  695. CArray<CStringArray, CStringArray>*pArrayOfString2,
  696. int datapos)
  697. {
  698. try
  699. {
  700. CArray<CStringArray, CStringArray>*parray[2] = { pArrayOfString1, pArrayOfString2 };
  701. DWORD bytereads = 0;
  702. for (int i = 0; i < 2; i++)
  703. {
  704. parray[i]->RemoveAll();
  705. if (g_sendhead.length[i] == 0)
  706. continue;
  707. if (g_sendhead.code[i])
  708. {
  709. // 1.1.将g_pData全局变量里保存的数据进行解压,并存储在lpszOut数组里;
  710. BYTE *lpszOut = NULL;
  711. int nOutSize = 0;
  712. LZARI Lzari;
  713. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], lpszOut, nOutSize);
  714. // 1.2.将解压后的数据lpszOut附加到内存文件里;
  715. CMemFile memfile;
  716. memfile.Attach(lpszOut, nOutSize);
  717. Lzari.Release();
  718. // 1.3.将内存文件序列化保存到CArchive对象里;
  719. bytereads += g_sendhead.length[i];
  720. CArchive ar(&memfile, CArchive::load);
  721. parray[i]->SetSize(g_sendhead.count[i]);
  722. // 1.4.将CArchive对象里的数据,序列化到指定的CArray对象里;
  723. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  724. {
  725. parray[i]->ElementAt(ii).Serialize(ar);
  726. }
  727. // 1.5.完成数据的导出任务,释放内存;
  728. ar.Close();
  729. memfile.Detach();
  730. }
  731. else
  732. {
  733. CMemFile memfile;
  734. memfile.Attach(g_pData + bytereads, g_sendhead.length[i]);
  735. bytereads += g_sendhead.length[i];
  736. CArchive ar(&memfile, CArchive::load);
  737. parray[i]->SetSize(g_sendhead.count[i]);
  738. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  739. {
  740. parray[i]->ElementAt(ii).Serialize(ar);
  741. }
  742. ar.Close();
  743. memfile.Detach();
  744. }
  745. }
  746. }
  747. catch (...)
  748. {
  749. }
  750. }
  751. void DataToArray(
  752. CArray<CStringArray, CStringArray>*pArrayOfString1,
  753. CArray<CStringArray, CStringArray>*pArrayOfString2,
  754. CArray<CStringArray, CStringArray>*pArrayOfString3,
  755. int datapos)
  756. {
  757. try
  758. {
  759. CArray<CStringArray, CStringArray>*parray[3] = { pArrayOfString1, pArrayOfString2, pArrayOfString3 };
  760. DWORD bytereads = 0;
  761. for (int i = 0; i < 3; i++)
  762. {
  763. parray[i]->RemoveAll(); if (g_sendhead.length[i] == 0)continue;
  764. if (g_sendhead.code[i])
  765. {
  766. BYTE *lpszOut = NULL;
  767. int nOutSize = 0;
  768. LZARI Lzari;
  769. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], lpszOut, nOutSize);
  770. CMemFile memfile;
  771. memfile.Attach(lpszOut, nOutSize);
  772. Lzari.Release();
  773. bytereads += g_sendhead.length[i];
  774. CArchive ar(&memfile, CArchive::load);
  775. parray[i]->SetSize(g_sendhead.count[i]);
  776. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  777. {
  778. parray[i]->ElementAt(ii).Serialize(ar);
  779. }
  780. ar.Close();
  781. memfile.Detach();
  782. }
  783. else
  784. {
  785. CMemFile memfile;
  786. memfile.Attach(g_pData + bytereads, g_sendhead.length[i]);
  787. bytereads += g_sendhead.length[i];
  788. CArchive ar(&memfile, CArchive::load);
  789. parray[i]->SetSize(g_sendhead.count[i]);
  790. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  791. {
  792. parray[i]->ElementAt(ii).Serialize(ar);
  793. }
  794. ar.Close();
  795. memfile.Detach();
  796. }
  797. }
  798. }
  799. catch (...)
  800. {
  801. }
  802. }
  803. void DataToArray(
  804. CArray<CStringArray, CStringArray>*pArrayOfString1,
  805. CArray<CStringArray, CStringArray>*pArrayOfString2,
  806. CArray<CStringArray, CStringArray>*pArrayOfString3,
  807. CArray<CStringArray, CStringArray>*pArrayOfString4,
  808. int datapos)
  809. {
  810. try
  811. {
  812. CArray<CStringArray, CStringArray>*parray[4] =
  813. {
  814. pArrayOfString1,
  815. pArrayOfString2,
  816. pArrayOfString3,
  817. pArrayOfString4
  818. };
  819. DWORD bytereads = 0;
  820. for (int i = 0; i < 4; i++)
  821. {
  822. parray[i]->RemoveAll(); if (g_sendhead.length[i] == 0)continue;
  823. if (g_sendhead.code[i])
  824. {
  825. BYTE *lpszOut = NULL;
  826. int nOutSize = 0;
  827. LZARI Lzari;
  828. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], lpszOut, nOutSize);
  829. CMemFile memfile;
  830. memfile.Attach(lpszOut, nOutSize);
  831. Lzari.Release();
  832. bytereads += g_sendhead.length[i];
  833. CArchive ar(&memfile, CArchive::load);
  834. parray[i]->SetSize(g_sendhead.count[i]);
  835. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  836. {
  837. parray[i]->ElementAt(ii).Serialize(ar);
  838. }
  839. ar.Close();
  840. memfile.Detach();
  841. }
  842. else
  843. {
  844. CMemFile memfile;
  845. memfile.Attach(g_pData + bytereads, g_sendhead.length[i]);
  846. bytereads += g_sendhead.length[i];
  847. CArchive ar(&memfile, CArchive::load);
  848. parray[i]->SetSize(g_sendhead.count[i]);
  849. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  850. {
  851. parray[i]->ElementAt(ii).Serialize(ar);
  852. }
  853. ar.Close();
  854. memfile.Detach();
  855. }
  856. }
  857. }
  858. catch (...)
  859. {
  860. }
  861. }
  862. void DataToArray(
  863. CArray<CStringArray, CStringArray>*pArrayOfString1,
  864. CArray<CStringArray, CStringArray>*pArrayOfString2,
  865. CArray<CStringArray, CStringArray>*pArrayOfString3,
  866. CArray<CStringArray, CStringArray>*pArrayOfString4,
  867. CArray<CStringArray, CStringArray>*pArrayOfString5,
  868. int datapos)
  869. {
  870. try
  871. {
  872. CArray<CStringArray, CStringArray>*parray[5] =
  873. {
  874. pArrayOfString1,
  875. pArrayOfString2,
  876. pArrayOfString3,
  877. pArrayOfString4,
  878. pArrayOfString5
  879. };
  880. DWORD bytereads = 0;
  881. for (int i = 0; i < 5; i++)
  882. {
  883. parray[i]->RemoveAll();
  884. if (g_sendhead.length[i] == 0)
  885. continue;
  886. if (g_sendhead.code[i])
  887. {
  888. BYTE *lpszOut = NULL;
  889. int nOutSize = 0;
  890. LZARI Lzari;
  891. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], lpszOut, nOutSize);
  892. CMemFile memfile;
  893. memfile.Attach(lpszOut, nOutSize);
  894. Lzari.Release();
  895. bytereads += g_sendhead.length[i];
  896. CArchive ar(&memfile, CArchive::load);
  897. parray[i]->SetSize(g_sendhead.count[i]);
  898. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  899. {
  900. parray[i]->ElementAt(ii).Serialize(ar);
  901. }
  902. ar.Close();
  903. memfile.Detach();
  904. }
  905. else
  906. {
  907. CMemFile memfile;
  908. memfile.Attach(g_pData + bytereads, g_sendhead.length[i]);
  909. bytereads += g_sendhead.length[i];
  910. CArchive ar(&memfile, CArchive::load);
  911. parray[i]->SetSize(g_sendhead.count[i]);
  912. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  913. {
  914. parray[i]->ElementAt(ii).Serialize(ar);
  915. }
  916. ar.Close();
  917. memfile.Detach();
  918. }
  919. }
  920. }
  921. catch (...)
  922. {
  923. }
  924. }
  925. void DataToArray(
  926. CArray<CStringArray, CStringArray>*pArrayOfString1,
  927. CArray<CStringArray, CStringArray>*pArrayOfString2,
  928. CArray<CStringArray, CStringArray>*pArrayOfString3,
  929. CArray<CStringArray, CStringArray>*pArrayOfString4,
  930. CArray<CStringArray, CStringArray>*pArrayOfString5,
  931. CArray<CStringArray, CStringArray>*pArrayOfString6,
  932. int datapos)
  933. {
  934. try
  935. {
  936. CArray<CStringArray, CStringArray>*parray[6] =
  937. {
  938. pArrayOfString1,
  939. pArrayOfString2,
  940. pArrayOfString3,
  941. pArrayOfString4,
  942. pArrayOfString5,
  943. pArrayOfString6
  944. };
  945. DWORD bytereads = 0;
  946. for (int i = 0; i < 6; i++)
  947. {
  948. parray[i]->RemoveAll();
  949. if (g_sendhead.length[i] == 0)continue;
  950. if (g_sendhead.code[i])
  951. {
  952. BYTE *lpszOut = NULL;
  953. int nOutSize = 0;
  954. LZARI Lzari;
  955. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], lpszOut, nOutSize);
  956. CMemFile memfile;
  957. memfile.Attach(lpszOut, nOutSize);
  958. Lzari.Release();
  959. bytereads += g_sendhead.length[i];
  960. CArchive ar(&memfile, CArchive::load);
  961. parray[i]->SetSize(g_sendhead.count[i]);
  962. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  963. {
  964. parray[i]->ElementAt(ii).Serialize(ar);
  965. }
  966. ar.Close();
  967. memfile.Detach();
  968. }
  969. else
  970. {
  971. CMemFile memfile;
  972. memfile.Attach(g_pData + bytereads, g_sendhead.length[i]);
  973. bytereads += g_sendhead.length[i];
  974. CArchive ar(&memfile, CArchive::load);
  975. parray[i]->SetSize(g_sendhead.count[i]);
  976. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  977. {
  978. parray[i]->ElementAt(ii).Serialize(ar);
  979. }
  980. ar.Close();
  981. memfile.Detach();
  982. }
  983. }
  984. }
  985. catch (...)
  986. {
  987. }
  988. }
  989. void DataToArray(
  990. CArray<CStringArray, CStringArray>*pArrayOfString1,
  991. CArray<CStringArray, CStringArray>*pArrayOfString2,
  992. CArray<CStringArray, CStringArray>*pArrayOfString3,
  993. CArray<CStringArray, CStringArray>*pArrayOfString4,
  994. CArray<CStringArray, CStringArray>*pArrayOfString5,
  995. CArray<CStringArray, CStringArray>*pArrayOfString6,
  996. CArray<CStringArray, CStringArray>*pArrayOfString7,
  997. int datapos)
  998. {
  999. try
  1000. {
  1001. CArray<CStringArray, CStringArray>*parray[7] =
  1002. {
  1003. pArrayOfString1,
  1004. pArrayOfString2,
  1005. pArrayOfString3,
  1006. pArrayOfString4,
  1007. pArrayOfString5,
  1008. pArrayOfString6,
  1009. pArrayOfString7
  1010. };
  1011. DWORD bytereads = 0;
  1012. for (int i = 0; i < 7; i++)
  1013. {
  1014. parray[i]->RemoveAll();
  1015. if (g_sendhead.length[i] == 0)continue;
  1016. if (g_sendhead.code[i])
  1017. {
  1018. BYTE *lpszOut = NULL;
  1019. int nOutSize = 0;
  1020. LZARI Lzari;
  1021. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], lpszOut, nOutSize);
  1022. CMemFile memfile;
  1023. memfile.Attach(lpszOut, nOutSize);
  1024. Lzari.Release();
  1025. bytereads += g_sendhead.length[i];
  1026. CArchive ar(&memfile, CArchive::load);
  1027. parray[i]->SetSize(g_sendhead.count[i]);
  1028. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  1029. {
  1030. parray[i]->ElementAt(ii).Serialize(ar);
  1031. }
  1032. ar.Close();
  1033. memfile.Detach();
  1034. }
  1035. else
  1036. {
  1037. CMemFile memfile;
  1038. memfile.Attach(g_pData + bytereads, g_sendhead.length[i]);
  1039. bytereads += g_sendhead.length[i];
  1040. CArchive ar(&memfile, CArchive::load);
  1041. parray[i]->SetSize(g_sendhead.count[i]);
  1042. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  1043. {
  1044. parray[i]->ElementAt(ii).Serialize(ar);
  1045. }
  1046. ar.Close();
  1047. memfile.Detach();
  1048. }
  1049. }
  1050. }
  1051. catch (...)
  1052. {
  1053. }
  1054. }
  1055. void DataToArray(
  1056. CArray<CStringArray, CStringArray>*pArrayOfString1,
  1057. CArray<CStringArray, CStringArray>*pArrayOfString2,
  1058. CArray<CStringArray, CStringArray>*pArrayOfString3,
  1059. CArray<CStringArray, CStringArray>*pArrayOfString4,
  1060. CArray<CStringArray, CStringArray>*pArrayOfString5,
  1061. CArray<CStringArray, CStringArray>*pArrayOfString6,
  1062. CArray<CStringArray, CStringArray>*pArrayOfString7,
  1063. CArray<CStringArray, CStringArray>*pArrayOfString8,
  1064. int datapos)
  1065. {
  1066. try
  1067. {
  1068. CArray<CStringArray, CStringArray>*parray[8] =
  1069. {
  1070. pArrayOfString1,
  1071. pArrayOfString2,
  1072. pArrayOfString3,
  1073. pArrayOfString4,
  1074. pArrayOfString5,
  1075. pArrayOfString6,
  1076. pArrayOfString7,
  1077. pArrayOfString8
  1078. };
  1079. DWORD bytereads = 0;
  1080. for (int i = 0; i < 8; i++)
  1081. {
  1082. parray[i]->RemoveAll();
  1083. if (g_sendhead.length[i] == 0)continue;
  1084. if (g_sendhead.code[i])
  1085. {
  1086. BYTE *lpszOut = NULL;
  1087. int nOutSize = 0;
  1088. LZARI Lzari;
  1089. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], lpszOut, nOutSize);
  1090. CMemFile memfile;
  1091. memfile.Attach(lpszOut, nOutSize);
  1092. Lzari.Release();
  1093. bytereads += g_sendhead.length[i];
  1094. CArchive ar(&memfile, CArchive::load);
  1095. parray[i]->SetSize(g_sendhead.count[i]);
  1096. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  1097. {
  1098. parray[i]->ElementAt(ii).Serialize(ar);
  1099. }
  1100. ar.Close();
  1101. memfile.Detach();
  1102. }
  1103. else
  1104. {
  1105. CMemFile memfile;
  1106. memfile.Attach(g_pData + bytereads, g_sendhead.length[i]);
  1107. bytereads += g_sendhead.length[i];
  1108. CArchive ar(&memfile, CArchive::load);
  1109. parray[i]->SetSize(g_sendhead.count[i]);
  1110. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  1111. {
  1112. parray[i]->ElementAt(ii).Serialize(ar);
  1113. }
  1114. ar.Close();
  1115. memfile.Detach();
  1116. }
  1117. }
  1118. }
  1119. catch (...)
  1120. {
  1121. }
  1122. }
  1123. void DataToArray(
  1124. CArray<CStringArray, CStringArray>*pArrayOfString1,
  1125. CArray<CStringArray, CStringArray>*pArrayOfString2,
  1126. CArray<CStringArray, CStringArray>*pArrayOfString3,
  1127. CArray<CStringArray, CStringArray>*pArrayOfString4,
  1128. CArray<CStringArray, CStringArray>*pArrayOfString5,
  1129. CArray<CStringArray, CStringArray>*pArrayOfString6,
  1130. CArray<CStringArray, CStringArray>*pArrayOfString7,
  1131. CArray<CStringArray, CStringArray>*pArrayOfString8,
  1132. CArray<CStringArray, CStringArray>*pArrayOfString9,
  1133. CArray<CStringArray, CStringArray>*pArrayOfString10,
  1134. int datapos)
  1135. {
  1136. try
  1137. {
  1138. CArray<CStringArray, CStringArray>*parray[10] =
  1139. {
  1140. pArrayOfString1,
  1141. pArrayOfString2,
  1142. pArrayOfString3,
  1143. pArrayOfString4,
  1144. pArrayOfString5,
  1145. pArrayOfString6,
  1146. pArrayOfString7,
  1147. pArrayOfString8,
  1148. pArrayOfString9,
  1149. pArrayOfString10
  1150. };
  1151. DWORD bytereads = 0;
  1152. for (int i = 0; i < 10; i++)
  1153. {
  1154. parray[i]->RemoveAll();
  1155. if (g_sendhead.length[i] == 0)continue;
  1156. if (g_sendhead.code[i])
  1157. {
  1158. BYTE *lpszOut = NULL;
  1159. int nOutSize = 0;
  1160. LZARI Lzari;
  1161. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], lpszOut, nOutSize);
  1162. CMemFile memfile;
  1163. memfile.Attach(lpszOut, nOutSize);
  1164. Lzari.Release();
  1165. bytereads += g_sendhead.length[i];
  1166. CArchive ar(&memfile, CArchive::load);
  1167. parray[i]->SetSize(g_sendhead.count[i]);
  1168. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  1169. {
  1170. parray[i]->ElementAt(ii).Serialize(ar);
  1171. }
  1172. ar.Close();
  1173. memfile.Detach();
  1174. }
  1175. else
  1176. {
  1177. CMemFile memfile;
  1178. memfile.Attach(g_pData + bytereads, g_sendhead.length[i]);
  1179. bytereads += g_sendhead.length[i];
  1180. CArchive ar(&memfile, CArchive::load);
  1181. parray[i]->SetSize(g_sendhead.count[i]);
  1182. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  1183. {
  1184. parray[i]->ElementAt(ii).Serialize(ar);
  1185. }
  1186. ar.Close();
  1187. memfile.Detach();
  1188. }
  1189. }
  1190. }
  1191. catch (...)
  1192. {
  1193. }
  1194. }
  1195. // 从缓存中加载图片;
  1196. void LoadImageFromBuf(Bitmap **img, BYTE *pData, DWORD leng)
  1197. {
  1198. try
  1199. {
  1200. if (pData == NULL)return;
  1201. if (*img)delete *img;
  1202. *img = NULL;
  1203. // Allocate global memory on which to create stream
  1204. HGLOBAL m_hMem = GlobalAlloc(GMEM_MOVEABLE, leng);
  1205. if (m_hMem == NULL)return;
  1206. BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
  1207. memcpy(pmem, pData, leng);
  1208. IStream* pstm;
  1209. CreateStreamOnHGlobal(m_hMem, TRUE, &pstm);
  1210. // load from stream
  1211. *img = Gdiplus::Bitmap::FromStream(pstm);
  1212. // free/release stuff
  1213. GlobalUnlock(m_hMem);
  1214. pstm->Release();
  1215. }
  1216. catch (...)
  1217. {
  1218. }
  1219. }
  1220. void LoadImageFromFile(Image **img, CString path)
  1221. {
  1222. try
  1223. {
  1224. if (!PathFileExists(path))return;
  1225. if (*img)delete *img;
  1226. *img = NULL;
  1227. BSTR bstr = path.AllocSysString();
  1228. *img = Image::FromFile(bstr);
  1229. SysFreeString(bstr);
  1230. }
  1231. catch (...)
  1232. {
  1233. }
  1234. }
  1235. void LoadImageFromFile(Bitmap **img, CString path)
  1236. {
  1237. try
  1238. {
  1239. if (!PathFileExists(path))return;
  1240. if (*img)delete *img;
  1241. *img = NULL;
  1242. BSTR bstr = path.AllocSysString();
  1243. *img = Bitmap::FromFile(bstr);
  1244. SysFreeString(bstr);
  1245. }
  1246. catch (...)
  1247. {
  1248. }
  1249. }
  1250. void LoadImageFromBuf(Image **img, BYTE *pData, DWORD leng)
  1251. {
  1252. try
  1253. {
  1254. if (pData == NULL)return;
  1255. if (*img)delete *img;
  1256. *img = NULL;
  1257. // Allocate global memory on which to create stream
  1258. HGLOBAL m_hMem = GlobalAlloc(GMEM_MOVEABLE, leng);
  1259. if (m_hMem == NULL)return;
  1260. BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
  1261. memcpy(pmem, pData, leng);
  1262. IStream* pstm;
  1263. CreateStreamOnHGlobal(m_hMem, TRUE, &pstm);
  1264. // load from stream
  1265. *img = Gdiplus::Image::FromStream(pstm);
  1266. // free/release stuff
  1267. GlobalUnlock(m_hMem);
  1268. pstm->Release();
  1269. }
  1270. catch (...)
  1271. {
  1272. }
  1273. }
  1274. void LoadImageFromBuf(Image **img, CString path)
  1275. {
  1276. try
  1277. {
  1278. CFile fp;
  1279. if (fp.Open(path, CFile::modeRead))
  1280. {
  1281. DWORD leng = fp.GetLength();
  1282. BYTE *pData = new BYTE[leng];
  1283. fp.Read(pData, leng);
  1284. fp.Close();
  1285. LoadImageFromBuf(img, pData, leng);
  1286. delete[]pData;
  1287. }
  1288. }
  1289. catch (...)
  1290. {
  1291. }
  1292. }
  1293. void LoadImageFromBuf(Bitmap **img, CString path)
  1294. {
  1295. try
  1296. {
  1297. CFile fp;
  1298. if (fp.Open(path, CFile::modeRead))
  1299. {
  1300. DWORD leng = fp.GetLength();
  1301. BYTE *pData = new BYTE[leng];
  1302. fp.Read(pData, leng);
  1303. fp.Close();
  1304. LoadImageFromBuf(img, pData, leng);
  1305. delete[]pData;
  1306. }
  1307. }
  1308. catch (...)
  1309. {
  1310. }
  1311. }
  1312. void LoadImageFromRes(Image **img, LPCTSTR lpszResourceName, LPCTSTR ResourceType)
  1313. {
  1314. try
  1315. {
  1316. HGLOBAL hGlobal = NULL;
  1317. HRSRC hSource = NULL;
  1318. LPVOID lpVoid = NULL;
  1319. int nSize = 0;
  1320. BOOL bResult = FALSE;
  1321. hSource = FindResource(NULL, lpszResourceName, ResourceType);
  1322. if (hSource == NULL)return;
  1323. hGlobal = LoadResource(NULL, hSource);
  1324. if (hGlobal == NULL)return;
  1325. lpVoid = LockResource(hGlobal);
  1326. if (lpVoid == NULL)return;
  1327. nSize = (UINT)SizeofResource(NULL, hSource);
  1328. LoadImageFromBuf(img, (BYTE*)hGlobal, nSize);
  1329. UnlockResource(hGlobal); // 16Bit Windows Needs This
  1330. FreeResource(hGlobal); // 16Bit Windows Needs This (32Bit - Automatic Release)
  1331. }
  1332. catch (...)
  1333. {
  1334. }
  1335. }
  1336. int GetOrientation(Image *image)
  1337. {
  1338. try
  1339. {
  1340. if (image)
  1341. {
  1342. UINT totalBufferSize;
  1343. UINT numProperties;
  1344. image->GetPropertySize(&totalBufferSize, &numProperties);
  1345. // Allocate the buffer that will receive the property items.
  1346. PropertyItem* pAllItems = (PropertyItem*)malloc(totalBufferSize);
  1347. // Fill the buffer.
  1348. image->GetAllPropertyItems(totalBufferSize, numProperties, pAllItems);
  1349. // Print the id data member of each property item.
  1350. for (UINT j = 0; j < numProperties; ++j)
  1351. {
  1352. if (PropertyTagOrientation == pAllItems[j].id)
  1353. {
  1354. short* ptrLong = (short*)(pAllItems[j].value);
  1355. int ret = (int)*ptrLong;
  1356. free(pAllItems);
  1357. return ret;
  1358. }
  1359. }
  1360. free(pAllItems);
  1361. }
  1362. }
  1363. catch (...)
  1364. {
  1365. }
  1366. return 1;
  1367. }
  1368. int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
  1369. {
  1370. UINT num = 0; // number of image encoders
  1371. UINT size = 0; // size of the image encoder array in bytes
  1372. ImageCodecInfo* pImageCodecInfo = NULL;
  1373. GetImageEncodersSize(&num, &size);
  1374. if (size == 0)
  1375. return -1; // Failure
  1376. pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
  1377. if (pImageCodecInfo == NULL)
  1378. return -1; // Failure
  1379. GetImageEncoders(num, size, pImageCodecInfo);
  1380. for (UINT j = 0; j < num; ++j)
  1381. {
  1382. if (wcscmp(pImageCodecInfo[j].MimeType, format) == 0)
  1383. {
  1384. *pClsid = pImageCodecInfo[j].Clsid;
  1385. free(pImageCodecInfo);
  1386. return j; // Success
  1387. }
  1388. }
  1389. free(pImageCodecInfo);
  1390. return -1; // FailureFailure
  1391. }
  1392. void SaveImageToFile(Image *img, CString path)
  1393. {
  1394. try
  1395. {
  1396. if (img == NULL)return;
  1397. CLSID encoderClsid;
  1398. BSTR bstr = path.AllocSysString();
  1399. path.MakeLower();
  1400. if (path.Right(3) == "bmp")
  1401. {
  1402. GetEncoderClsid(L"image/bmp", &encoderClsid);
  1403. img->Save(bstr, &encoderClsid, NULL);
  1404. }
  1405. else if (path.Right(3) == "png")
  1406. {
  1407. GetEncoderClsid(L"image/png", &encoderClsid);
  1408. img->Save(bstr, &encoderClsid, NULL);
  1409. }
  1410. else// if(path.Right (3)=="jpg")
  1411. {
  1412. GetEncoderClsid(L"image/jpeg", &encoderClsid);
  1413. EncoderParameters encoderParameters;
  1414. ULONG quality;
  1415. encoderParameters.Count = 1;
  1416. encoderParameters.Parameter[0].Guid = EncoderQuality;
  1417. encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
  1418. encoderParameters.Parameter[0].NumberOfValues = 1;
  1419. // Save the image as a JPEG with quality level 100.
  1420. quality = 100;
  1421. encoderParameters.Parameter[0].Value = &quality;
  1422. img->Save(bstr, &encoderClsid, &encoderParameters);
  1423. }
  1424. SysFreeString(bstr);
  1425. }
  1426. catch (...)
  1427. {
  1428. }
  1429. }
  1430. void SaveImageToFile2(Image *img, CString path, ULONG quality)
  1431. {
  1432. try
  1433. {
  1434. if (img == NULL)return;
  1435. CLSID encoderClsid;
  1436. BSTR bstr = path.AllocSysString();
  1437. path.MakeLower();
  1438. if (path.Right(3) == "bmp")
  1439. {
  1440. GetEncoderClsid(L"image/bmp", &encoderClsid);
  1441. img->Save(bstr, &encoderClsid, NULL);
  1442. }
  1443. else if (path.Right(3) == "png")
  1444. {
  1445. GetEncoderClsid(L"image/png", &encoderClsid);
  1446. img->Save(bstr, &encoderClsid, NULL);
  1447. }
  1448. else// if(path.Right (3)=="jpg")
  1449. {
  1450. GetEncoderClsid(L"image/jpeg", &encoderClsid);
  1451. EncoderParameters encoderParameters;
  1452. encoderParameters.Count = 1;
  1453. encoderParameters.Parameter[0].Guid = EncoderQuality;
  1454. encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
  1455. encoderParameters.Parameter[0].NumberOfValues = 1;
  1456. // Save the image as a JPEG with quality level 100.
  1457. encoderParameters.Parameter[0].Value = &quality;
  1458. img->Save(bstr, &encoderClsid, &encoderParameters);
  1459. }
  1460. SysFreeString(bstr);
  1461. }
  1462. catch (...)
  1463. {
  1464. }
  1465. }
  1466. void IsWaiter2(CString id, CString name, CArray<CStringArray, CStringArray>*waiterarray, BOOL &bWait1, BOOL &bWait2, float &fscale1, float &fscale2, BOOL bCheckDate, CString date1, CString date2)
  1467. {
  1468. for (int i = 0; i < waiterarray->GetSize(); i++)
  1469. {
  1470. if (id == waiterarray->ElementAt(i).ElementAt(0))
  1471. {
  1472. if (bCheckDate)
  1473. {
  1474. if (waiterarray->ElementAt(i).ElementAt(21) < date1 || waiterarray->ElementAt(i).ElementAt(21) > date2 || waiterarray->ElementAt(i).ElementAt(22) != "OK")
  1475. {
  1476. bWait1 = bWait2 = 0;
  1477. return;
  1478. }
  1479. }
  1480. if (name == waiterarray->ElementAt(i).ElementAt(1))
  1481. {
  1482. bWait1 = 1;
  1483. fscale1 = atof(waiterarray->ElementAt(i).ElementAt(5)) / 100.0;
  1484. if (fscale1 == 0)fscale1 = 1;
  1485. }
  1486. else if (name == waiterarray->ElementAt(i).ElementAt(2))
  1487. {
  1488. bWait1 = 1;
  1489. fscale1 = atof(waiterarray->ElementAt(i).ElementAt(6)) / 100.0;
  1490. }
  1491. else if (name == waiterarray->ElementAt(i).ElementAt(3))
  1492. {
  1493. bWait1 = 1;
  1494. fscale1 = atof(waiterarray->ElementAt(i).ElementAt(7)) / 100.0;
  1495. }
  1496. else if (name == waiterarray->ElementAt(i).ElementAt(4))
  1497. {
  1498. bWait1 = 1;
  1499. fscale1 = atof(waiterarray->ElementAt(i).ElementAt(8)) / 100.0;
  1500. }
  1501. ///////////////////////////////////////////////////////////////////////
  1502. if (name == waiterarray->ElementAt(i).ElementAt(9))
  1503. {
  1504. bWait2 = 1;
  1505. fscale2 = atof(waiterarray->ElementAt(i).ElementAt(13)) / 100.0;
  1506. if (fscale2 == 0)fscale2 = 1;
  1507. }
  1508. else if (name == waiterarray->ElementAt(i).ElementAt(10))
  1509. {
  1510. bWait2 = 1;
  1511. fscale2 = atof(waiterarray->ElementAt(i).ElementAt(14)) / 100.0;
  1512. }
  1513. else if (name == waiterarray->ElementAt(i).ElementAt(11))
  1514. {
  1515. bWait2 = 1;
  1516. fscale2 = atof(waiterarray->ElementAt(i).ElementAt(15)) / 100.0;
  1517. }
  1518. else if (name == waiterarray->ElementAt(i).ElementAt(12))
  1519. {
  1520. bWait2 = 1;
  1521. fscale2 = atof(waiterarray->ElementAt(i).ElementAt(16)) / 100.0;
  1522. }
  1523. return;
  1524. }
  1525. }
  1526. return;
  1527. }
  1528. void IsWaiter3(CString id, CString name, CArray<CStringArray, CStringArray>*waiterarray, BOOL &bWait1, BOOL &bWait2, float &fscale1, float &fscale2)
  1529. {
  1530. bWait1 = bWait2 = 0;
  1531. for (int i = 0; i < waiterarray->GetSize(); i++)
  1532. {
  1533. if (id == waiterarray->ElementAt(i).ElementAt(0))
  1534. {
  1535. if (name == waiterarray->ElementAt(i).ElementAt(17))
  1536. {
  1537. bWait1 = 1;
  1538. fscale1 = atof(waiterarray->ElementAt(i).ElementAt(19)) / 100.0;
  1539. if (fscale1 == 0)fscale1 = 1;
  1540. }
  1541. ///////////////////////////////////////////////////////////////////////
  1542. if (name == waiterarray->ElementAt(i).ElementAt(18))
  1543. {
  1544. bWait2 = 1;
  1545. fscale2 = atof(waiterarray->ElementAt(i).ElementAt(20)) / 100.0;
  1546. }
  1547. return;
  1548. }
  1549. }
  1550. return;
  1551. }
  1552. //------------------------------------------------------------------------------
  1553. // Remark by Jeff;
  1554. // 函数:CheckPhoneType
  1555. // 描述:判断手机号属于哪个运营商的;
  1556. // 参数:
  1557. // phoneno: 欲判断的手机号;
  1558. //
  1559. // 返回:返回0表示移动; 1表示联通; 2表示电信; 3表示小灵通; -1表示未知的;
  1560. //
  1561. // 注意:
  1562. // 移动:
  1563. // 139, 138, 137, 136, 135, 134, 159, 158, 152, 151, 150, 157, 188, 187, 144
  1564. // 联通:
  1565. // 130, 131, 132, 155, 156, 186, 185
  1566. // 电信 :
  1567. // 133, 153, 189, 180, 181
  1568. //------------------------------------------------------------------------------
  1569. int CheckPhoneType(CString &phoneno)
  1570. {
  1571. if (phoneno.IsEmpty())
  1572. return -1;
  1573. for (int i = 0; i < phoneno.GetLength(); i++)
  1574. {
  1575. if (phoneno.GetAt(i) < '0' || phoneno.GetAt(i) > '9')return -1;
  1576. }
  1577. if (phoneno.GetAt(0) == '1')
  1578. {
  1579. if (phoneno.GetLength() != 11)
  1580. return -1;
  1581. int mobile[] = { 139, 138, 137, 136, 135, 134, 159, 158, 152, 151, 150, 157, 188, 187, 144, 182, 147, 183, 184, 178 };
  1582. int unicom[] = { 130, 131, 132, 155, 156, 186, 185, 176 };
  1583. int telecom[] = { 133, 153, 189, 180, 181, 177 };
  1584. int others[] = { 170 };
  1585. for (i = 0; i < sizeof(mobile) / sizeof(int); i++)
  1586. {
  1587. if (mobile[i] == atoi(phoneno.Left(3)))
  1588. {
  1589. return 0;
  1590. }
  1591. }
  1592. for (i = 0; i < sizeof(unicom) / sizeof(int); i++)
  1593. {
  1594. if (unicom[i] == atoi(phoneno.Left(3)))
  1595. {
  1596. return 1;
  1597. }
  1598. }
  1599. for (i = 0; i < sizeof(telecom) / sizeof(int); i++)
  1600. {
  1601. if (telecom[i] == atoi(phoneno.Left(3)))
  1602. {
  1603. return 2;
  1604. }
  1605. }
  1606. for (i = 0; i < sizeof(others)/sizeof(int);i++)
  1607. {
  1608. if ( others[i] == atoi((phoneno.Left(3))))
  1609. {
  1610. return 3;
  1611. }
  1612. }
  1613. return -1;
  1614. }
  1615. return -1;
  1616. }
  1617. /************************************************************************/
  1618. /*
  1619. 函数:CheckDateOK
  1620. 描述:判断日期有效性;
  1621. 参数:
  1622. IN: str 要判断的日期;
  1623. IN: bLunanr 是否是农历日期;
  1624. 返回:
  1625. 日期有效返回TRUE;
  1626. 要求:
  1627. 注意:
  1628. 修改:Jeff
  1629. 日期:2015-04-28
  1630. 内容:添加日期有效性判断,同时支持农历日期;
  1631. */
  1632. /************************************************************************/
  1633. BOOL CheckDateOK(IN CString &str, IN CONST BOOL &bLunanr)
  1634. {
  1635. if (str.IsEmpty())return 1;
  1636. CString tip;
  1637. int i;
  1638. CString demo = CTime::GetCurrentTime().Format("%Y-%m-%d");
  1639. if (str.GetLength() != demo.GetLength())
  1640. goto ll;
  1641. //2009-01-01
  1642. if (str.GetAt(4) != '-')
  1643. goto ll;
  1644. if (str.GetAt(7) != '-')
  1645. goto ll;
  1646. for (i = 0; i < str.GetLength(); i++)
  1647. {
  1648. if (i == 4 || i == 7)continue;
  1649. if (str.GetAt(i) < '0' || str.GetAt(i) > '9')
  1650. goto ll;
  1651. }
  1652. #if 1
  1653. if (!bLunanr)
  1654. return IsValidDate(str);
  1655. else
  1656. return IsValidLunanrDate(str);
  1657. #else
  1658. return 1;
  1659. #endif
  1660. ll:
  1661. tip.Format("日期:%s格式错误!\r\n样板:%s", str, demo);
  1662. AfxMessageBox(tip, MB_ICONSTOP);
  1663. return 0;
  1664. }
  1665. BOOL CheckBadWords(CString str, BOOL bMsg)
  1666. {
  1667. CString badwords[165] = { \
  1668. "【call5.me】", \
  1669. "您可拨020", \
  1670. "88btt.com热线400611", \
  1671. "400678165", \
  1672. "海王星", \
  1673. "博天堂", \
  1674. "十八大", \
  1675. "钓鱼岛", \
  1676. "无限次数提款", \
  1677. "广东地和", \
  1678. "利来", \
  1679. "抢劫", \
  1680. "fa lun", \
  1681. "强奸", \
  1682. "dafa", \
  1683. "falun", \
  1684. "SIM卡抽奖", \
  1685. "罢工", \
  1686. "罢课", \
  1687. "暴乱", \
  1688. "婊子", \
  1689. "操你", \
  1690. "操你娘", \
  1691. "蠢猪", \
  1692. "达赖", \
  1693. "打倒", \
  1694. "大法", \
  1695. "大纪元", \
  1696. "弹药", \
  1697. "钓鱼岛", \
  1698. "东突", \
  1699. "东突厥斯坦伊斯兰运动", \
  1700. "发抡", \
  1701. "发仑", \
  1702. "发伦", \
  1703. "发囵", \
  1704. "发沦", \
  1705. "发纶", \
  1706. "发轮", \
  1707. "发论", \
  1708. "法 轮 功", \
  1709. "法.轮.功", \
  1710. "法抡", \
  1711. "法仑", \
  1712. "法伦", \
  1713. "法囵", \
  1714. "法沦", \
  1715. "法纶", \
  1716. "法轮", \
  1717. "法论", \
  1718. "反革命", \
  1719. "反日", \
  1720. "分裂", \
  1721. "干你娘", \
  1722. "功友", \
  1723. "古怪歌", \
  1724. "国研新闻邮件", \
  1725. "黑庄", \
  1726. "宏志", \
  1727. "洪志", \
  1728. "胡锦涛", \
  1729. "鸡巴", \
  1730. "鸡毛信文汇", \
  1731. "妓女", \
  1732. "简鸿章", \
  1733. "江八点", \
  1734. "江独裁", \
  1735. "江泽民", \
  1736. "疆独", \
  1737. "教徒", \
  1738. "锦涛", \
  1739. "靖国神社", \
  1740. "九、评", \
  1741. "九.评", \
  1742. "九码", \
  1743. "九-评", \
  1744. "拉丹", \
  1745. "拉登", \
  1746. "李鹏", \
  1747. "联总之声传单", \
  1748. "灵动卡", \
  1749. "六合彩", \
  1750. "六码", \
  1751. "吕秀莲", \
  1752. "绿色环保手机", \
  1753. "美国之音", \
  1754. "猛料", \
  1755. "迷药", \
  1756. "民运", \
  1757. "民猪", \
  1758. "嫖娼", \
  1759. "迫害", \
  1760. "枪支", \
  1761. "强奸", \
  1762. "窃听器", \
  1763. "人民报", \
  1764. "人民报讯", \
  1765. "人民大众时事参考", \
  1766. "人民内情真相", \
  1767. "人民真实报道", \
  1768. "人权", \
  1769. "日你妈", \
  1770. "日他", \
  1771. "三码", \
  1772. "三陪", \
  1773. "色情", \
  1774. "傻B", \
  1775. "涉日", \
  1776. "十六大", \
  1777. "示威", \
  1778. "他妈的", \
  1779. "台*湾", \
  1780. "特等奖", \
  1781. "天葬", \
  1782. "突厥斯坦", \
  1783. "推翻", \
  1784. "王八蛋", \
  1785. "温家宝", \
  1786. "无能", \
  1787. "香港总部", \
  1788. "小鸡鸡", \
  1789. "新华举报", \
  1790. "新华内情", \
  1791. "新闻封锁", \
  1792. "畜生", \
  1793. "玄`机", \
  1794. "压迫", \
  1795. "淫秽", \
  1796. "银行联合管理局", \
  1797. "印尼伊斯兰祈祷团", \
  1798. "游行", \
  1799. "舆论", \
  1800. "造反", \
  1801. "真善忍", \
  1802. "镇压", \
  1803. "正法", \
  1804. "政变", \
  1805. "政治风波", \
  1806. "中俄边界新约", \
  1807. "中国银联", \
  1808. "中华民国", \
  1809. "中奖", \
  1810. "朱容基", \
  1811. "自焚", \
  1812. "自由运动", \
  1813. "达赖", \
  1814. "套牌", \
  1815. "情妇", \
  1816. "监听", \
  1817. "巴南电信", \
  1818. "合川分公司", \
  1819. "合川电信", \
  1820. "死光", \
  1821. "116114", \
  1822. "北京宝诚", \
  1823. "华盛投资", \
  1824. "名门国际", \
  1825. "利博", \
  1826. "赤橙黄绿", \
  1827. "免佣BJL首发", \
  1828. "洗*码优惠", \
  1829. "【俱乐部】", \
  1830. "18266381922", \
  1831. "回拨卡", \
  1832. "号码百事通推出短信订机票!实时" };
  1833. for (int i = 0; i < 165; i++)
  1834. {
  1835. g_temp = badwords[i];
  1836. if (str.Find(g_temp) != -1)
  1837. {
  1838. // AfxMessageBox("信息服务商禁止的非法字符:("+g_temp+")希望您谅解!");
  1839. return 0;
  1840. }
  1841. }
  1842. return 1;
  1843. }
  1844. ///目录是否存在的检查: 支持网络文件夹
  1845. bool CheckFolderFileExist(CString &strPath)
  1846. {
  1847. CString path = strPath;
  1848. CFile fp;
  1849. if (fp.Open(path, CFile::modeRead))
  1850. {
  1851. fp.Close();
  1852. return 1;
  1853. }
  1854. if (strPath.Right(1) != "\\")
  1855. path += "\\";
  1856. path += "zaqw1234.dat";
  1857. // 所有文件删除前先判断是否存在,不存在则退出删除;
  1858. #if JEFF_TEST_ON
  1859. if (PathFileExists(path))
  1860. {
  1861. ::DeleteFile(path); // 删除zaqw1234.dat文件;
  1862. }
  1863. #else
  1864. ::DeleteFile(path); // 删除zaqw1234.dat文件;
  1865. #endif
  1866. if (fp.Open(path, CFile::modeCreate) == 0)
  1867. return 0;
  1868. fp.Close();
  1869. if (PathFileExists(path)) // Jeff 删除文件前判断文件是否存在;
  1870. ::DeleteFile(path); // 删除zaqw1234.dat文件;
  1871. return 1;
  1872. }
  1873. int FindArray(CStringArray *pArray, const CString &Str)
  1874. {
  1875. for (int i = 0; i < pArray->GetSize(); i++)
  1876. {
  1877. if (pArray->ElementAt(i) == Str)
  1878. return i;
  1879. }
  1880. return -1;
  1881. }
  1882. void FillLength(CString &str, int length)
  1883. {
  1884. while (str.GetLength() < length)
  1885. str += " ";
  1886. }
  1887. // 查找不到年历史数据库则返回-1;
  1888. int GetYearPos(int year)
  1889. {
  1890. for (int i = 0; i < g_hisyeararray.GetSize(); i++)
  1891. {
  1892. if (year == atoi(g_hisyeararray.ElementAt(i).ElementAt(0)))
  1893. return i;
  1894. }
  1895. return -1;
  1896. }
  1897. BOOL GIsHalfHZ(const CString &str)
  1898. {
  1899. int len = str.GetLength();
  1900. BOOL IsHalf = FALSE;
  1901. for (int i = 0; i < len; i++)
  1902. {
  1903. if (str.GetAt(i) < 0) IsHalf = !IsHalf;
  1904. }
  1905. return IsHalf;
  1906. }
  1907. void WriteTitle(CString str)
  1908. {
  1909. g_title = str;
  1910. CStdioFile fp;
  1911. fp.Open(g_mainpath + "\\title.txt", CFile::modeWrite | CFile::modeCreate);
  1912. fp.WriteString(str);
  1913. fp.Close();
  1914. }
  1915. CString GetIP(CString branch)
  1916. {
  1917. for (int i = 0; i < g_brancharray.GetSize(); i++)
  1918. {
  1919. if (g_domain == g_brancharray.ElementAt(i).ElementAt(2))
  1920. {
  1921. //if(g_serverbak.Find (".ly.com")!=-1)
  1922. return g_server;
  1923. CString ip = g_serverbak;
  1924. MyGetIPByName(ip);
  1925. return ip;
  1926. }
  1927. if (branch == g_brancharray.ElementAt(i).ElementAt(0))
  1928. {
  1929. return g_brancharray.ElementAt(i).ElementAt(1);
  1930. }
  1931. }
  1932. return "";
  1933. }
  1934. BOOL IsHanZi(CString str)
  1935. {
  1936. TBYTE ucHigh, ucLow;
  1937. for (int i = 0; i < str.GetLength(); i++)
  1938. {
  1939. if ((TBYTE)str[i] < 0x80)
  1940. {
  1941. continue;
  1942. }
  1943. ucHigh = (TBYTE)str[i];
  1944. ucLow = (TBYTE)str[i + 1];
  1945. if (ucHigh < 0xa1 || ucLow < 0xa1)
  1946. {
  1947. continue;
  1948. }
  1949. return 1;
  1950. }
  1951. return 0;
  1952. }
  1953. int GetType(CString str)
  1954. {
  1955. if (IsHanZi(str))return 0;
  1956. BOOL bDigit = 1;
  1957. BOOL bAlpha = 1;
  1958. for (int i = 0; i < str.GetLength(); i++)
  1959. {
  1960. if (!::isdigit(str.GetAt(i)))
  1961. //if(! ((str.GetAt (i)<='0' && str.GetAt (i)>='9' ) ))
  1962. bDigit = 0;
  1963. if (!((str.GetAt(i) <= 'z' && str.GetAt(i) >= 'a') || (str.GetAt(i) <= 'Z' && str.GetAt(i) >= 'A')))
  1964. //else if(!::isalpha ( ((unsigned char)str.GetAt (i))))
  1965. bAlpha = 0;
  1966. if (bDigit == 0 && bAlpha == 0)return 0;
  1967. }
  1968. if (bDigit)
  1969. {
  1970. /*#ifdef SUNRAIN_VERSION
  1971. return 0;
  1972. #else*/
  1973. return 0;
  1974. //#endif
  1975. }
  1976. else if (bAlpha)
  1977. {
  1978. return 2;
  1979. }
  1980. else
  1981. return 0;
  1982. }
  1983. CString FilterBZ(CString &bz)
  1984. {
  1985. bz.Replace("'", "");
  1986. /* int i=bz.GetLength ()-1;
  1987. char c;
  1988. for(;i>=0;i--)
  1989. {
  1990. c=bz.GetAt (i);
  1991. if(c<32)// && c!=10 && c!=13)
  1992. bz.Delete (i);
  1993. }*/
  1994. if (bz.GetLength() > 1023)
  1995. {
  1996. AfxMessageBox("文字太长, 字符串将被截取!", MB_ICONSTOP);
  1997. bz = bz.Left(1023);
  1998. }
  1999. return bz;
  2000. }
  2001. // GetWidth()的长度与CRect的长度是不一样的单位值,需要转换适合的比例;(一个是图片的像素尺寸,一个DC的大小尺寸)
  2002. // 将图片尺寸与设备尺寸进行转换适合的比例;
  2003. void RectFitDes(int width, int height, CRect &rc)
  2004. {
  2005. try
  2006. {
  2007. if (width == 0 || height == 0)return;
  2008. // 图片长宽比例;
  2009. float fscale = (float)width / (float)height;
  2010. // 设备长宽比例;
  2011. float rcscale = ((float)rc.Width()) / ((float)rc.Height());
  2012. int rcwid = rc.Width();
  2013. int rchei = rc.Height();
  2014. int dt = 0;
  2015. // Jeff.如果设备长宽比例 < 图片长宽比例;(即相同长度下,高越大比例值越小,所以此时图片尺寸 与 显示设备的尺寸相比,要显得更长)
  2016. if (rcscale < fscale)
  2017. {
  2018. // Jeff.remarks
  2019. // 调整显示设备的大小,以使之能容纳图片尺寸;(即长宽比例上,要大于或等于图片的长宽比例)
  2020. // 所以有两种方法使得 rcscale >= fscale 表达式成立:
  2021. // -----------------------------------------------
  2022. // 方法1:显示设备宽加x值,计算出下面表达式x的值即可
  2023. // (rc.Width()+x) / rc.Height() >= width/height;
  2024. // 方法2:显示设备高减x值,计算出下面表达式x的值即可
  2025. // (rc.Width()) / (rc.Height()-x) >= width/height;
  2026. //------------------------------------------------
  2027. // 两种方法的最后表达式为:
  2028. // x >= rc.Height() - rcWidth()*(height/width);
  2029. // 即 x >= rc.Height() - rcWidth()/fscale;
  2030. //------------------------------------------------
  2031. dt = (rchei - rcwid / fscale) / 2;
  2032. rc.top += dt;
  2033. rc.bottom -= dt;
  2034. }
  2035. else
  2036. {
  2037. dt = (rcwid - rchei*fscale) / 2;
  2038. rc.left += dt;
  2039. rc.right -= dt;
  2040. }
  2041. }
  2042. catch (...)
  2043. {
  2044. }
  2045. }
  2046. BOOL IsHasRights(int pos) // Jeff,无意义的函数;
  2047. {
  2048. return 1;
  2049. if (g_user.rights.GetLength() > pos)
  2050. {
  2051. BOOL ret = atoi(g_user.rights.Mid(pos, 1));
  2052. if (ret == 0)AfxMessageBox("没有相关权限!", MB_ICONINFORMATION);
  2053. return ret;
  2054. }
  2055. AfxMessageBox("没有相关权限!", MB_ICONINFORMATION);
  2056. return 0;
  2057. }
  2058. BOOL IsHasRights2(int pos)// Jeff,无意义的函数;
  2059. {
  2060. return 1;
  2061. if (g_user.rights.GetLength() > pos)
  2062. {
  2063. BOOL ret = atoi(g_user.rights.Mid(pos, 1));
  2064. return ret;
  2065. }
  2066. return 0;
  2067. }
  2068. BOOL IsHasRightsnew(int pos)
  2069. {
  2070. #if JEFF_TEST_OFF
  2071. CString strTest = _T("");
  2072. strTest.Format(_T("%d"), pos);
  2073. AfxMessageBox(strTest);
  2074. return TRUE;
  2075. #else
  2076. if (g_user.rights.GetLength() > pos)
  2077. {
  2078. BOOL ret = atoi(g_user.rights.Mid(pos, 1));
  2079. if (ret == 0)AfxMessageBox("没有相关权限! 请与系统管理员联系!", MB_ICONINFORMATION);
  2080. return ret;
  2081. }
  2082. AfxMessageBox("没有相关权限! 请与系统管理员联系!", MB_ICONINFORMATION);
  2083. #endif
  2084. return 0;
  2085. }
  2086. BOOL IsHasRights2new(int pos)
  2087. {
  2088. #if JEFF_TEST_OFF
  2089. CString strTest = _T("");
  2090. strTest.Format(_T("%d"), pos);
  2091. AfxMessageBox(strTest);
  2092. return TRUE;
  2093. #else
  2094. if (g_user.rights.GetLength() > pos)
  2095. {
  2096. BOOL ret = atoi(g_user.rights.Mid(pos, 1));
  2097. return ret;
  2098. }
  2099. #endif
  2100. return 0;
  2101. }
  2102. BOOL IsHasRightsnew2(int pos, CString rights)
  2103. {
  2104. #if JEFF_TEST_OFF
  2105. CString strTest = _T("");
  2106. strTest.Format(_T("%d,%s"), pos, rights);
  2107. AfxMessageBox(strTest);
  2108. return TRUE;
  2109. #else
  2110. if (rights.GetLength() > pos)
  2111. {
  2112. BOOL ret = atoi(rights.Mid(pos, 1));
  2113. if (ret == 0)AfxMessageBox("没有相关权限! 请与系统管理员联系!", MB_ICONINFORMATION);
  2114. return ret;
  2115. }
  2116. AfxMessageBox("没有相关权限! 请与系统管理员联系!", MB_ICONINFORMATION);
  2117. #endif
  2118. return 0;
  2119. }
  2120. /********************************************************************************************
  2121. /* Syntax
  2122. /* void FirstLetter(int nCode, CString& strLetter)
  2123. /* Remarks:
  2124. /* Get the first letter of pinyin according to specified Chinese character code.
  2125. /* Parameters:
  2126. /* nCode - the code of the chinese character.
  2127. /* strLetter - a CString object that is to receive the string of the first letter.
  2128. /* Return Values:
  2129. /* None.
  2130. /* Author:
  2131. /* lixiaosan
  2132. /* Create Date:
  2133. /* 05-26-2006
  2134. /********************************************************************************************/
  2135. void FirstLetter(int nCode, CString& strLetter)
  2136. {
  2137. if (nCode >= 1601 && nCode < 1637) strLetter = _T("A");
  2138. if (nCode >= 1637 && nCode < 1833) strLetter = _T("B");
  2139. if (nCode >= 1833 && nCode < 2078) strLetter = _T("C");
  2140. if (nCode >= 2078 && nCode < 2274) strLetter = _T("D");
  2141. if (nCode >= 2274 && nCode < 2302) strLetter = _T("E");
  2142. if (nCode >= 2302 && nCode < 2433) strLetter = _T("F");
  2143. if (nCode >= 2433 && nCode < 2594) strLetter = _T("G");
  2144. if (nCode >= 2594 && nCode < 2787) strLetter = _T("H");
  2145. if (nCode >= 2787 && nCode < 3106) strLetter = _T("J");
  2146. if (nCode >= 3106 && nCode < 3212) strLetter = _T("K");
  2147. if (nCode >= 3212 && nCode < 3472) strLetter = _T("L");
  2148. if (nCode >= 3472 && nCode < 3635) strLetter = _T("M");
  2149. if (nCode >= 3635 && nCode < 3722) strLetter = _T("N");
  2150. if (nCode >= 3722 && nCode < 3730) strLetter = _T("O");
  2151. if (nCode >= 3730 && nCode < 3858) strLetter = _T("P");
  2152. if (nCode >= 3858 && nCode < 4027) strLetter = _T("Q");
  2153. if (nCode >= 4027 && nCode < 4086) strLetter = _T("R");
  2154. if (nCode >= 4086 && nCode < 4390) strLetter = _T("S");
  2155. if (nCode >= 4390 && nCode < 4558) strLetter = _T("T");
  2156. if (nCode >= 4558 && nCode < 4684) strLetter = _T("W");
  2157. if (nCode >= 4684 && nCode < 4925) strLetter = _T("X");
  2158. if (nCode >= 4925 && nCode < 5249) strLetter = _T("Y");
  2159. if (nCode >= 5249 && nCode < 5590) strLetter = _T("Z");
  2160. }
  2161. /********************************************************************************************
  2162. /* Syntax
  2163. /* GetFirstLetter(CString strName, CString& strFirstLetter)
  2164. /* Remarks:
  2165. /* Get the first letter of pinyin according to specified Chinese character.
  2166. /* Parameters:
  2167. /* strName - a CString object that is to be parsed.
  2168. /* strFirstLetter - a CString object that is to receive the string of the first letter.
  2169. /* Return Values:
  2170. /* None.
  2171. /* Author:
  2172. /* lixiaosan
  2173. /* Create Date:
  2174. /* 05-26-2006
  2175. /********************************************************************************************/
  2176. void GetFirstLetter(CString strName, CString& strFirstLetter)
  2177. {
  2178. TBYTE ucHigh, ucLow;
  2179. int nCode;
  2180. CString strRet;
  2181. strFirstLetter.Empty();
  2182. for (int i = 0; i < strName.GetLength(); i++)
  2183. {
  2184. if ((TBYTE)strName[i] < 0x80)
  2185. {
  2186. strRet = strName.Mid(i, 1);
  2187. strRet.MakeUpper();
  2188. strFirstLetter += strRet;
  2189. continue;
  2190. }
  2191. ucHigh = (TBYTE)strName[i];
  2192. ucLow = (TBYTE)strName[i + 1];
  2193. if (ucHigh < 0xa1 || ucLow < 0xa1)
  2194. continue;
  2195. else
  2196. // Treat code by section-position as an int type parameter,
  2197. // so make following change to nCode.
  2198. nCode = (ucHigh - 0xa0) * 100 + ucLow - 0xa0;
  2199. FirstLetter(nCode, strRet);
  2200. strFirstLetter += strRet;
  2201. i++;
  2202. }
  2203. }
  2204. CString newGUID()
  2205. {
  2206. CString str;
  2207. GUID guid;
  2208. CoInitialize(NULL);
  2209. if (S_OK == ::CoCreateGuid(&guid))
  2210. {
  2211. str.Format(
  2212. "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
  2213. guid.Data1,
  2214. guid.Data2,
  2215. guid.Data3,
  2216. guid.Data4[0], guid.Data4[1],
  2217. guid.Data4[2], guid.Data4[3],
  2218. guid.Data4[4], guid.Data4[5],
  2219. guid.Data4[6], guid.Data4[7]);
  2220. }
  2221. CoUninitialize();
  2222. return str.Left(28);
  2223. }
  2224. CString GetNameFromDomain(CString domain)
  2225. {
  2226. for (int i = 0; i < g_brancharray.GetSize(); i++)
  2227. {
  2228. if (domain == g_brancharray.ElementAt(i).ElementAt(2))
  2229. {
  2230. return g_brancharray.ElementAt(i).ElementAt(0);
  2231. }
  2232. }
  2233. return "";
  2234. }
  2235. void ConvertToPrice(CString &str)
  2236. {
  2237. if (str.Find('.') == -1)return;
  2238. str.TrimRight('0');
  2239. str.TrimRight('.');
  2240. }
  2241. int GetLengthEx(CString str)
  2242. {
  2243. wchar_t wstr[500];
  2244. int k = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, strlen(str), wstr, 500);
  2245. return k;
  2246. }
  2247. inline int MultiByteLengthConvertToWideCharLength(/*LPCSTR*/LPCCH lpString)
  2248. {
  2249. return MultiByteToWideChar(CP_ACP, 0, lpString, -1, NULL, 0);
  2250. }
  2251. BOOL myisdigit(CString str)
  2252. {
  2253. for (int i = 0; i < str.GetLength(); i++)
  2254. {
  2255. if (!::isdigit(str.GetAt(i)))
  2256. return 0;
  2257. }
  2258. return 1;
  2259. }
  2260. DWORD FindAppProcessID(CString path)
  2261. {
  2262. try
  2263. {
  2264. HANDLE handle = ::CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
  2265. PROCESSENTRY32 Info;
  2266. Info.dwSize = sizeof(PROCESSENTRY32);
  2267. path.MakeLower();
  2268. if (::Process32First(handle, &Info))
  2269. {
  2270. do
  2271. {
  2272. CString ss = Info.szExeFile;
  2273. ss.MakeLower();
  2274. if (ss.Find(path) != -1 || (!ss.CompareNoCase(path)))
  2275. {
  2276. ::CloseHandle(handle);
  2277. return Info.th32ProcessID;
  2278. }
  2279. } while (::Process32Next(handle, &Info));
  2280. ::CloseHandle(handle);
  2281. }
  2282. return -1;
  2283. }
  2284. catch (...)
  2285. {
  2286. }
  2287. }
  2288. BOOL isInnerIP(DWORD a_ip) // Jeff.判断是否是内网?
  2289. {
  2290. BOOL bValid = 0;
  2291. if ((a_ip >> 24 == 0xa) || (a_ip >> 16 == 0xc0a8) || (a_ip >> 22 == 0x2b0))
  2292. {
  2293. bValid = 1;
  2294. }
  2295. return bValid;
  2296. }
  2297. void MyGetIPByName2(CString &name)
  2298. {
  2299. CString strIP = name;
  2300. name.Empty();
  2301. DWORD dwServerIP = 0;
  2302. HOSTENT *host = gethostbyname(strIP);
  2303. struct in_addr addr;
  2304. if (host != NULL)
  2305. {
  2306. for (int i = 0; host->h_addr_list[i] != NULL; i++)
  2307. {
  2308. memset(&addr, 0, sizeof(addr));
  2309. memcpy(&addr.S_un.S_addr, host->h_addr_list[i], host->h_length);
  2310. dwServerIP = ntohl(addr.S_un.S_addr);
  2311. BYTE* pIP = (BYTE*)&dwServerIP;
  2312. name.Format(_T("%d.%d.%d.%d"), pIP[3], pIP[2], pIP[1], pIP[0]);
  2313. }
  2314. }
  2315. }
  2316. void MyGetIPByName(CString &name) // Jeff.根据计算机名称获取IP地址;
  2317. {
  2318. g_serverarray.RemoveAll();
  2319. CString strIP = name;
  2320. name.Empty();
  2321. DWORD dwServerIP = 0;
  2322. HOSTENT *host = gethostbyname(strIP); // Jeff.所有本机的网络适配器;
  2323. struct in_addr addr;
  2324. if (host != NULL)
  2325. {
  2326. // Jeff.遍历本机所有适配器的IP地址;
  2327. for (int i = 0; host->h_addr_list[i] != NULL; i++)
  2328. {
  2329. memset(&addr, 0, sizeof(addr));
  2330. memcpy(&addr.S_un.S_addr, host->h_addr_list[i], host->h_length);
  2331. dwServerIP = ntohl(addr.S_un.S_addr);
  2332. BYTE* pIP = (BYTE*)&dwServerIP;
  2333. name.Format(_T("%d.%d.%d.%d"), pIP[3], pIP[2], pIP[1], pIP[0]);
  2334. g_serverarray.Add(name);
  2335. }
  2336. }
  2337. while (g_serverarray.GetSize() > 1)
  2338. {
  2339. CString name;
  2340. BOOL bFind = 0;
  2341. for (int i = 0; i < g_serverarray.GetSize(); i++)
  2342. {
  2343. DWORD dwServerIP = inet_addr(g_serverarray.ElementAt(i));
  2344. dwServerIP = htonl(dwServerIP);//加了才正确
  2345. if (isInnerIP(dwServerIP) == 0)
  2346. {
  2347. // AfxMessageBox("外部IP");
  2348. g_serverarray.RemoveAt(i);
  2349. bFind = 1;
  2350. break;
  2351. }
  2352. // else
  2353. // AfxMessageBox("内部IP");
  2354. }
  2355. if (bFind == 0)
  2356. {
  2357. break;
  2358. }
  2359. }
  2360. }
  2361. int IsExistFolder(char *szPath)//可判断文件夹和文件的存在;
  2362. {
  2363. if ((_access(szPath, 0)) != -1)
  2364. {
  2365. //printf("Jeff:File %s \t exists \n",szPath );
  2366. /* Check for write permission */
  2367. if ((_access(szPath, 2)) != -1)
  2368. {
  2369. //printf("Jeff:File %s \t has write permission \n",szPath );
  2370. CString str;
  2371. str.Format("共享文件夹<%s>: 存在!\n", szPath);
  2372. WriteClientLog(str);
  2373. return 1;
  2374. }
  2375. // else // 只能判断文件权限,不能判断目录;
  2376. // {
  2377. // CString str;
  2378. // str.Format("共享文件夹<%s>:\t存在,不可写!■■■■■■■\n",szPath);
  2379. // WriteClientLog(str);
  2380. //
  2381. // return 0;
  2382. // }
  2383. }
  2384. else
  2385. {
  2386. //printf("Jeff:\t File %s no exists \n",szPath );
  2387. CString str;
  2388. str.Format("◆共享文件夹<%s>: 不存在,请设置共享或访问权限!◆\n", szPath);
  2389. WriteClientLog(str);
  2390. return -1;
  2391. }
  2392. }
  2393. CString GetW(CString str)
  2394. {
  2395. int x = atoi(str);
  2396. if (x > 9999)
  2397. {
  2398. str.Format("%d", x);
  2399. str = str.Right(5);
  2400. str = str.Left(1);
  2401. return str;
  2402. }
  2403. return "";
  2404. }
  2405. CString GetK(CString str)
  2406. {
  2407. int x = atoi(str);
  2408. if (x > 999)
  2409. {
  2410. str.Format("%d", x);
  2411. str = str.Right(4);
  2412. str = str.Left(1);
  2413. return str;
  2414. }
  2415. return "";
  2416. }
  2417. CString GetB(CString str)
  2418. {
  2419. int x = atoi(str);
  2420. if (x > 99)
  2421. {
  2422. str.Format("%d", x);
  2423. str = str.Right(3);
  2424. str = str.Left(1);
  2425. return str;
  2426. }
  2427. return "";
  2428. }
  2429. CString GetS(CString str)
  2430. {
  2431. int x = atoi(str);
  2432. if (x > 9)
  2433. {
  2434. str.Format("%d", x);
  2435. str = str.Right(2);
  2436. str = str.Left(1);
  2437. return str;
  2438. }
  2439. return "";
  2440. }
  2441. CString GetG(CString str)
  2442. {
  2443. int x = atoi(str);
  2444. if (x > 0)
  2445. {
  2446. str.Format("%d", x);
  2447. str = str.Right(1);
  2448. return str;
  2449. }
  2450. return "";
  2451. }
  2452. CString GetHMoney(CString str)
  2453. {
  2454. if (str.IsEmpty())return "";
  2455. if (str == "0")return "零";
  2456. if (atoi(str) < 1 || atoi(str) > 9)return "";
  2457. CString ret[] = { "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
  2458. return ret[atoi(str) - 1];
  2459. }
  2460. BOOL CheckDateOK2(CString str)
  2461. {
  2462. if (str.IsEmpty())return 0;
  2463. CString tip;
  2464. int i;
  2465. CString demo = CTime::GetCurrentTime().Format("%Y-%m-%d");
  2466. if (str.GetLength() != demo.GetLength())
  2467. goto ll;
  2468. //2009-01-01
  2469. if (str.GetAt(4) != '-')
  2470. goto ll;
  2471. if (str.GetAt(7) != '-')
  2472. goto ll;
  2473. for (i = 0; i < str.GetLength(); i++)
  2474. {
  2475. if (i == 4 || i == 7)continue;
  2476. if (str.GetAt(i) < '0' || str.GetAt(i) > '9')
  2477. goto ll;
  2478. }
  2479. return 1;
  2480. ll:
  2481. return 0;
  2482. }
  2483. CString GetDomainFromBranch(CString branch)
  2484. {
  2485. if (branch.IsEmpty())return "";
  2486. for (int i = 0; i < g_brancharray.GetSize(); i++)
  2487. {
  2488. if (branch == g_brancharray.ElementAt(i).ElementAt(0))
  2489. {
  2490. return g_brancharray.ElementAt(i).ElementAt(2);
  2491. }
  2492. }
  2493. return "";
  2494. }
  2495. CString GetBranchPhotoPath(CString branch)
  2496. {
  2497. if (branch.IsEmpty())return "";
  2498. for (int i = 0; i < g_brancharray.GetSize() - 1; i++)
  2499. {
  2500. if (branch == g_brancharray.ElementAt(i).ElementAt(0))
  2501. {
  2502. return "\\" + g_brancharray.ElementAt(i).ElementAt(2);
  2503. }
  2504. }
  2505. return "";
  2506. }
  2507. CTime GetTmFromStr(CString date)
  2508. {
  2509. try
  2510. {
  2511. CTime tm(atoi(date.Mid(0, 4)), atoi(date.Mid(5, 2)), atoi(date.Mid(8, 2)), 0, 0, 0);
  2512. CString ss;
  2513. ss.Format("%d-%d-%d", tm.GetYear(), tm.GetMonth(), tm.GetDay());
  2514. return tm;
  2515. }
  2516. catch (...)
  2517. {
  2518. date = "1980-01-01";
  2519. CTime tm(atoi(date.Mid(0, 4)), atoi(date.Mid(5, 2)), atoi(date.Mid(8, 2)), 0, 0, 0);
  2520. return tm;
  2521. }
  2522. }
  2523. //---------------------------------------------------------------------
  2524. // add by Jeff 2014.10.24
  2525. // 函数:全局函数lyfzCopyFileEx
  2526. // 描述:文件复制。
  2527. // 参数:
  2528. // lpExistingFileName:你要拷贝的源文件名;
  2529. // lpNewFileName: 你要拷贝的目标文件名;
  2530. // bFailIfExists: 如果目标已经存在,不拷贝(True)并重命名,覆盖目标(false)
  2531. // 返回:与CopyFile返回一致;
  2532. //---------------------------------------------------------------------
  2533. BOOL lyfzCopyFileEx(LPCTSTR lpExistingFileName, LPCTSTR lpNewFileName, const BOOL &bFailIfExists)
  2534. {
  2535. // 1.如果是覆盖选项;
  2536. if (!bFailIfExists)
  2537. return CopyFile(lpExistingFileName, lpNewFileName, bFailIfExists);
  2538. // 2.如果不是覆盖选项;
  2539. TCHAR szNewFileName[_MAX_PATH] = { 0 };
  2540. TCHAR szDrive[_MAX_DRIVE] = { 0 };
  2541. TCHAR szDir[_MAX_DIR] = { 0 };
  2542. TCHAR szFna[_MAX_FNAME] = { 0 };
  2543. TCHAR szExt[_MAX_EXT] = { 0 };
  2544. sprintf(szNewFileName, "%s", lpNewFileName);
  2545. _tsplitpath(szNewFileName, szDrive, szDir, szFna, szExt);
  2546. int nIndex = 1;
  2547. while (PathFileExists(szNewFileName))
  2548. {
  2549. sprintf(szNewFileName, "%s%s%s (%d)%s", szDrive, szDir, szFna, nIndex++, szExt);
  2550. }
  2551. return CopyFile(lpExistingFileName, szNewFileName, bFailIfExists);
  2552. }
  2553. //---------------------------------------------------------------------
  2554. // add by Jeff 2014.10.24
  2555. // 函数:全局函数lyfzImportImage,多字节版本,非UNICODE
  2556. // 描述:导入图片。
  2557. // 参数:
  2558. // lpDestDirectory: 文件导入的目标目录;
  2559. // strArrayOfImage: 要导入的图片文件数组;
  2560. // bFailIfExists: 如果目标已经存在,不拷贝(True)并重命名,覆盖目标(false)
  2561. // 返回:
  2562. //
  2563. // 说明:在调用lyfzImportImage前,需要对传递的参数进行有效性验证
  2564. // 1.验证形参lpDestDirectory对应的实参是否是有效的目录(有无创建目录的非法字符存在)
  2565. // 2.验证形参strArrayOfImage对应的实参数组是否大于0;
  2566. // 如果校验没有通过,应该拒绝调lyfzImportImage,以防止错误产生。
  2567. //---------------------------------------------------------------------
  2568. void lyfzImportImage(LPCTSTR lpDestDirectory, CStringArray &strArrayOfImage, const BOOL &bFailIfExists)
  2569. {
  2570. // 传递给lyfzCreateDirectory的参数规范化;
  2571. int nlen = strlen(lpDestDirectory);
  2572. TCHAR szNewFileName[_MAX_PATH] = { 0 };
  2573. TCHAR szTempDirectory[_MAX_PATH] = { 0 };
  2574. if (lpDestDirectory[nlen - 1] != '\\')
  2575. sprintf(szTempDirectory, "%s\\", lpDestDirectory);
  2576. else
  2577. sprintf(szTempDirectory, "%s", lpDestDirectory);
  2578. // 若目录或子目录不存在创建;
  2579. lyfzCreateDirectory(szTempDirectory);
  2580. // 遍历复制;
  2581. CString strImage;
  2582. INT_PTR nSize = strArrayOfImage.GetSize();
  2583. for (INT_PTR i = 0; i < nSize; i++)
  2584. {
  2585. strImage = strArrayOfImage.ElementAt(i);
  2586. strImage = strImage.Mid(strImage.ReverseFind('\\') + 1);
  2587. //strImage = strImage.Left(strImage.ReverseFind('.'));
  2588. sprintf(szNewFileName, "%s%s", szTempDirectory, strImage);
  2589. lyfzCopyFileEx(szNewFileName, strArrayOfImage.ElementAt(i), bFailIfExists);
  2590. }
  2591. }
  2592. //---------------------------------------------------------------------
  2593. // add by Jeff 2014.10.25
  2594. // 函数:全局函数lyfzCreateDirectory,多字节版本,非UNICODE
  2595. // 描述:创建目录及子目录文件夹;
  2596. // 参数:
  2597. // lpDestDirectory:目录,必须是"E:\lyfzdb\数据\"格式,目录最后必须有"\",否则最后一个子目录无法创建!
  2598. // 建议使用系统_tsplitpath来分隔目录,这样会保存最后一个"\"斜杠;
  2599. // 返回:成功创建返回TRUE;
  2600. //---------------------------------------------------------------------
  2601. BOOL lyfzCreateDirectory(LPCTSTR lpDestDirectory)
  2602. {
  2603. BOOL bExists = FALSE;
  2604. TCHAR szNewFileName[_MAX_PATH] = { 0 };
  2605. TCHAR szDrive[_MAX_DRIVE] = { 0 };
  2606. TCHAR szDir[_MAX_DIR] = { 0 };
  2607. TCHAR szFna[_MAX_FNAME] = { 0 };
  2608. TCHAR szExt[_MAX_EXT] = { 0 };
  2609. int nIndex = 0;
  2610. do
  2611. {
  2612. bExists = PathFileExists(lpDestDirectory);
  2613. if (!bExists)
  2614. {
  2615. memset(szDrive, 0, _MAX_DRIVE);
  2616. memset(szDir, 0, _MAX_DIR);
  2617. memset(szFna, 0, _MAX_FNAME);
  2618. memset(szExt, 0, _MAX_EXT);
  2619. lyfzSplitpath(lpDestDirectory, szDrive, szDir, ++nIndex);
  2620. sprintf(szNewFileName, _T("%s%s"), szDrive, szDir);
  2621. CreateDirectory(szNewFileName, NULL);
  2622. //if (FALSE == CreateDirectory(szNewFileName, NULL))
  2623. //{
  2624. //ShowSystemErrorInfo(CString("创建目录出错。"), GetLastError());
  2625. //return FALSE;
  2626. // continue;
  2627. //}
  2628. }
  2629. } while (!bExists);
  2630. return TRUE;
  2631. }
  2632. //---------------------------------------------------------------------
  2633. // add by Jeff 2014.10.24
  2634. // 函数:全局函数tSplitpath,多字节版本,非UNICODE
  2635. // 描述:类系统Windows C++运行库函数_tsplitpath。
  2636. // 参数:
  2637. //
  2638. // 返回:
  2639. //---------------------------------------------------------------------
  2640. void lyfzSplitpath(const char *path, char *drive, char *dir, const int &nTimes)
  2641. {
  2642. int nlen = strlen(path);
  2643. int i = 0;
  2644. int npoint = 0; // '.'
  2645. int nsprit = 0; // '\\'
  2646. int ncolon = 0; // ':'
  2647. int ntimes = -1;
  2648. while (nlen > i++)
  2649. {
  2650. if (path[i] == ':')
  2651. ncolon = i;
  2652. else if (path[i] == '\\')
  2653. {
  2654. if (nTimes == ntimes++) break;
  2655. nsprit = i;
  2656. }
  2657. }
  2658. memcpy(drive, path, ncolon + 1);
  2659. memcpy(dir, &path[ncolon + 1], nsprit - ncolon);
  2660. }
  2661. //---------------------------------------------------------------------
  2662. // Jeff add 2014.06.23;
  2663. // 函数:ShowErrorInfo
  2664. // 描述:
  2665. // 参数:
  2666. // lpszFunction:函数名;
  2667. // dwError:错误码;
  2668. // 返回:
  2669. //---------------------------------------------------------------------
  2670. void ShowSystemErrorInfo(CString &strDescription, const DWORD &dwError)
  2671. {
  2672. #if 0
  2673. LPVOID lpMsgBuf;
  2674. FormatMessage(
  2675. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  2676. FORMAT_MESSAGE_FROM_SYSTEM |
  2677. FORMAT_MESSAGE_IGNORE_INSERTS,
  2678. NULL,
  2679. dwError,
  2680. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  2681. (LPTSTR)&lpMsgBuf,
  2682. 0, NULL);
  2683. // Display the error message and exit the process
  2684. CString strDisplay;
  2685. strDisplay.Format("失败错误码=%d,Windows内部描述:%s", dwError, lpMsgBuf);
  2686. strDescription += strDisplay;
  2687. AfxMessageBox(strDescription);
  2688. LocalFree(lpMsgBuf);
  2689. #endif
  2690. LPVOID lpMsgBuf;
  2691. BOOL fOk = FormatMessage(
  2692. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  2693. FORMAT_MESSAGE_FROM_SYSTEM |
  2694. FORMAT_MESSAGE_IGNORE_INSERTS,
  2695. NULL,
  2696. dwError,
  2697. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  2698. (LPTSTR)&lpMsgBuf,
  2699. 0, NULL);
  2700. if (!fOk)
  2701. {
  2702. // Is it a network-related error?
  2703. HMODULE hDll = LoadLibraryEx(TEXT("netmsg.dll"), NULL, DONT_RESOLVE_DLL_REFERENCES);
  2704. if (hDll != NULL)
  2705. {
  2706. FormatMessage(
  2707. FORMAT_MESSAGE_FROM_HMODULE |
  2708. FORMAT_MESSAGE_FROM_SYSTEM |
  2709. FORMAT_MESSAGE_IGNORE_INSERTS,
  2710. hDll,
  2711. dwError,
  2712. MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
  2713. (LPTSTR)&lpMsgBuf,
  2714. 0,
  2715. NULL);
  2716. FreeLibrary(hDll);
  2717. }
  2718. }
  2719. if (lpMsgBuf != NULL)
  2720. {
  2721. CString strDisplay;
  2722. strDisplay.Format("%s.错误码=%d,Windows描述:%s", strDescription, dwError, (LPCTSTR)LocalLock(lpMsgBuf));
  2723. //WriteLogin(strDisplay);
  2724. AfxMessageBox(strDisplay);
  2725. LocalFree(lpMsgBuf);
  2726. }
  2727. else
  2728. {
  2729. //WriteLogin(strDescription);
  2730. AfxMessageBox("未知道错误");
  2731. }
  2732. }
  2733. //---------------------------------------------------------------------
  2734. // Jeff add 2014.06.23;
  2735. // 函数:WriteClientLog
  2736. // 描述:写客户端程序日志。
  2737. // 参数:
  2738. // str:日志内容;
  2739. // 返回:
  2740. //---------------------------------------------------------------------
  2741. void WriteClientLog(const CString &strLogContent)
  2742. {
  2743. try
  2744. {
  2745. CStdioFile fp;
  2746. CString path = g_mainpath + "\\客户端日志.txt";
  2747. if (PathFileExists(path))
  2748. {
  2749. fp.Open(path, CFile::modeWrite);
  2750. int length = fp.GetLength();
  2751. if (length > 5 * 1024 * 1024)
  2752. {
  2753. fp.Close();
  2754. ::DeleteFile(path); // 删除客户端日志.txt;
  2755. return;
  2756. }
  2757. fp.SeekToEnd();
  2758. }
  2759. else
  2760. fp.Open(path, CFile::modeCreate | CFile::modeWrite);
  2761. fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S") + " " + strLogContent + "\n");
  2762. fp.Close();
  2763. }
  2764. catch (...)
  2765. {
  2766. }
  2767. }
  2768. //---------------------------------------------------------------------
  2769. // add by Jeff 2014.10.27
  2770. // 函数:全局函数IsDirectoryLegitimate,多字节版本,非UNICODE
  2771. // 描述:判断一个目录路径字符串,是否属于合法的、可创建的目录路径。
  2772. // 参数:strDirectory 被验证的路径字符串;
  2773. //
  2774. // 返回:合法路径返回TRUE;
  2775. //---------------------------------------------------------------------
  2776. BOOL IsDirectoryLegitimate(const CString &strDirectory)
  2777. {
  2778. if (strDirectory.Find('/') != -1 ||
  2779. strDirectory.Find('\\') != -1 ||
  2780. strDirectory.Find(':') != -1 ||
  2781. strDirectory.Find('*') != -1 ||
  2782. strDirectory.Find('?') != -1 ||
  2783. strDirectory.Find('\"') != -1 ||
  2784. strDirectory.Find('>') != -1 ||
  2785. strDirectory.Find('<') != -1 ||
  2786. strDirectory.Find('|') != -1
  2787. )
  2788. return FALSE;
  2789. return TRUE;
  2790. }
  2791. //----------------------------------------------------------------------
  2792. // remark by Jeff 2014.11.08
  2793. // 函数:ExportCutImageToFile
  2794. // 描述:导出裁剪图片到指定目录;
  2795. // 参数:
  2796. // lpOrderCutImageInfo:订单号的裁剪相片信息;
  2797. // lpSrcDirectory:原图片路径;
  2798. // lpOrderCutImageInfo格式:相片名|裁剪方案|原片宽|原片高|裁剪left|裁剪top|裁剪bottom|裁剪rigth
  2799. // 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;
  2800. // lpSaveDirectory:导出相片的保存路径;
  2801. // 返回:无
  2802. //----------------------------------------------------------------------
  2803. void ExportCutImageToFile(LPCCH lpOrderCutImageInfo, LPCCH lpSrcDirectory, LPCCH lpSaveDirectory)
  2804. {
  2805. if (FALSE == lyfzCreateDirectory(lpSaveDirectory))
  2806. return;
  2807. CStringArray saSrcPhoto;
  2808. GetCountOfOrderFolderPhotoFile(lpSrcDirectory, saSrcPhoto);
  2809. CString strImageName; // 相片名;
  2810. CString strCutScheme; // 裁剪方案;
  2811. CRect rtCut; // 要裁剪的区域;
  2812. CString strTemp;
  2813. CString strImageInfo(lpOrderCutImageInfo);
  2814. int nIndex = -1;
  2815. do
  2816. {
  2817. // 225:5X7,1440,900,88,0,1352,900;
  2818. nIndex = strImageInfo.Find(';');
  2819. strTemp = strImageInfo.Left(nIndex);
  2820. strImageInfo = strImageInfo.Mid(nIndex + 1);
  2821. int SrcImageWid;
  2822. int SrcImageHei;
  2823. int ntempIndex = -1;
  2824. if (nIndex != -1)
  2825. {
  2826. if (FALSE == AnalysisImagInfo(saSrcPhoto,lpSrcDirectory, lpSaveDirectory, strTemp, strImageName, strCutScheme, rtCut))
  2827. continue;
  2828. }
  2829. else
  2830. {
  2831. if (strImageInfo.IsEmpty())
  2832. break;
  2833. AnalysisImagInfo(saSrcPhoto,lpSrcDirectory, lpSaveDirectory, strImageInfo, strImageName, strCutScheme, rtCut);
  2834. break;
  2835. }
  2836. } while (nIndex != -1);
  2837. }
  2838. //----------------------------------------------------------------------
  2839. // remark by Jeff 2014.11.08
  2840. // 函数:AnalysisImagInfo
  2841. // 描述:导出裁剪图片到指定目录;
  2842. // 参数:
  2843. // lpOrderCutImageInfo:订单号的裁剪相片信息;
  2844. // lpSrcDirectory:原图片路径;
  2845. // lpOrderCutImageInfo格式:相片名|裁剪方案|原片宽|原片高|裁剪left|裁剪top|裁剪bottom|裁剪rigth
  2846. // 225:5X7,1440,900,88,0,1352,900;
  2847. // lpSaveDirectory:导出相片的保存路径;
  2848. // 返回:无
  2849. //
  2850. // 说明:未对图片进行缩小,直接在原片上裁剪而得。
  2851. //----------------------------------------------------------------------
  2852. BOOL AnalysisImagInfo(CStringArray &saSrcPhoto, LPCCH lpSrcDirectory, LPCCH lpSaveDirectory, CString &strImageInfo, CString &strImageName, CString &strCutScheme, CRect &rtCut)
  2853. {
  2854. int ntempIndex = -1;
  2855. strImageName = strImageInfo.Left(3); // 裁剪相片名;
  2856. strImageInfo.Delete(0, 4);
  2857. CString strSrcImagePath;
  2858. BOOL bExist = FALSE;
  2859. for (int i = 0; i < saSrcPhoto.GetSize(); i++)
  2860. {
  2861. CString strTemp = saSrcPhoto.ElementAt(i);
  2862. strSrcImagePath = strTemp;
  2863. _splitpath((LPCTSTR)saSrcPhoto.ElementAt(i), NULL, NULL, strTemp.GetBuffer(0), NULL);
  2864. strTemp.ReleaseBuffer();
  2865. if ( strTemp == strImageName)
  2866. {
  2867. bExist = TRUE;
  2868. //saSrcPhoto.RemoveAt(i);
  2869. break;
  2870. }
  2871. }
  2872. if (FALSE == bExist)
  2873. return FALSE;
  2874. ntempIndex = strImageInfo.Find(',');
  2875. strCutScheme = strImageInfo.Left(ntempIndex); // 裁剪方案;
  2876. strImageInfo.Delete(0, ntempIndex + 1);
  2877. // 裁剪原图宽;
  2878. ntempIndex = strImageInfo.Find(',');
  2879. LONG SrcImageWid = _ttol(strImageInfo.Left(ntempIndex));
  2880. strImageInfo.Delete(0, ntempIndex + 1);
  2881. // 裁剪原图高;
  2882. ntempIndex = strImageInfo.Find(',');
  2883. LONG SrcImageHei = _ttol(strImageInfo.Left(ntempIndex));
  2884. strImageInfo.Delete(0, ntempIndex + 1);
  2885. // left坐标值;
  2886. ntempIndex = strImageInfo.Find(',');
  2887. rtCut.left = _ttol(strImageInfo.Left(ntempIndex));
  2888. strImageInfo.Delete(0, ntempIndex + 1);
  2889. // top坐标;
  2890. ntempIndex = strImageInfo.Find(',');
  2891. rtCut.top = _ttol(strImageInfo.Left(ntempIndex));
  2892. strImageInfo.Delete(0, ntempIndex + 1);
  2893. // right坐标;
  2894. ntempIndex = strImageInfo.Find(',');
  2895. rtCut.right = _ttol(strImageInfo.Left(ntempIndex));
  2896. strImageInfo.Delete(0, ntempIndex + 1);
  2897. // bottom坐标;
  2898. rtCut.bottom = _ttol(strImageInfo.Left(ntempIndex));
  2899. // 导出裁剪相片到指定目录;
  2900. // 1.加载原图;
  2901. Image *SrcImage = NULL;
  2902. //if (FALSE == PathFileExists(CString(lpSrcDirectory + strImageName + _T(".jpg"))))
  2903. if (FALSE == PathFileExists(strSrcImagePath))
  2904. {
  2905. AfxMessageBox(_T("相片源文件不存在"));
  2906. return FALSE;
  2907. }
  2908. //LoadImageFromBuf(&SrcImage, CString(lpSrcDirectory + strImageName + _T(".jpg")));
  2909. LoadImageFromBuf(&SrcImage, strSrcImagePath);
  2910. if (SrcImage == NULL)
  2911. {
  2912. AfxMessageBox(_T("加载源图片失败"));
  2913. return FALSE;
  2914. }
  2915. int orientation = GetOrientation(SrcImage);
  2916. if (orientation == 8)
  2917. SrcImage->RotateFlip(Rotate270FlipNone);
  2918. else if (orientation == 6)
  2919. SrcImage->RotateFlip(Rotate90FlipNone);
  2920. if (SrcImage->GetWidth() == 0)
  2921. return FALSE;
  2922. float scale = 1.0;
  2923. scale *= (float)SrcImage->GetWidth() / (float)SrcImageWid;
  2924. rtCut.left *= scale;
  2925. rtCut.right *= scale;
  2926. rtCut.top *= scale;
  2927. rtCut.bottom *= scale;
  2928. #if 0 // 保存在原图上画裁剪区域;
  2929. Graphics graph(SrcImage);
  2930. Pen blackPen(Color(255, 255, 0, 0), 1);
  2931. graph.DrawRectangle(&blackPen, rtCut.left, rtCut.top, rtCut.Width(), rtCut.Height());
  2932. SaveImageToFile(SrcImage, CString(lpSaveDirectory + strImageName + _T(".jpg")));
  2933. delete SrcImage;
  2934. #else // 直接保存裁剪后的图片;
  2935. Bitmap bp(rtCut.Width(), rtCut.Height());
  2936. Graphics *graphic = Graphics::FromImage(&bp);
  2937. graphic->Clear(Color(255, 255, 255, 255));
  2938. graphic->SetInterpolationMode(InterpolationModeHighQualityBicubic);
  2939. graphic->SetSmoothingMode(SmoothingModeHighQuality);//SmoothingModeHighSpeed
  2940. graphic->SetPixelOffsetMode(PixelOffsetModeHighQuality);
  2941. graphic->SetCompositingMode(CompositingModeSourceOver);
  2942. graphic->SetCompositingQuality(CompositingQualityHighQuality);
  2943. graphic->SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);
  2944. graphic->DrawImage(SrcImage, RectF(0, 0, rtCut.Width(), rtCut.Height()), rtCut.left, rtCut.top, rtCut.Width(), rtCut.Height(), UnitPixel);
  2945. delete SrcImage;
  2946. delete graphic;
  2947. //delete graphic;
  2948. //CString strSave;
  2949. //strSave.Format("%s%s:%s.jpg", lpSaveDirectory,strImageName,strCutScheme);
  2950. //SaveImageToFile(&bp, strSave);
  2951. SaveImageToFile(&bp, CString(lpSaveDirectory + strImageName + _T(":") + strCutScheme + _T(".jpg")));
  2952. #endif
  2953. return TRUE;
  2954. }
  2955. // 相片后缀:jpg、raw、cr2、NEF 四种常用后缀
  2956. //--------------------------------------------------------------------------------
  2957. // Remark by Jeff 2014.11.10
  2958. // 函数:GetCountOfOrderFolderPhotoFile
  2959. // 描述:获取订单文件夹下所有相片文件,不含"m"和"s"开头的小图;
  2960. // 参数:pOrderFolder:订单文件路径;
  2961. // 返回:
  2962. //
  2963. //--------------------------------------------------------------------------------
  2964. int GetCountOfOrderFolderPhotoFile( const TCHAR *pOrderFolder, CStringArray &StrPhotoArray)
  2965. {
  2966. CStringArray StrSubFoloderArray;
  2967. using namespace helper_coffs;
  2968. ffsco o;
  2969. o.dirs(1); // Jeff.1:查找子目录;
  2970. o.find(LPCTSTR(pOrderFolder), LPCTSTR(_T("*.*"))); // 可能存在m和s开头的缩略图,需要过滤掉;
  2971. if (o.count() == 0)
  2972. return 0;
  2973. // 获取子目录数;
  2974. ffsco::typeT coo;
  2975. ffsco::typeT::iterator it;
  2976. coo = o.co_dir();
  2977. for (it = coo.begin(); it != coo.end(); it++)
  2978. {
  2979. if (FindArray(&StrSubFoloderArray, (*it).c_str()) == -1)
  2980. StrSubFoloderArray.Add((*it).c_str());
  2981. }
  2982. int nIndex = -1;
  2983. CString strOrderNumberImage;
  2984. // 获取子目录下的文件数;
  2985. //CStringArray StrPhotoArray;
  2986. for (int n = 0; n < StrSubFoloderArray.GetSize(); n++)
  2987. {
  2988. ffsco op;
  2989. op.dirs(0);
  2990. op.find(LPCTSTR(StrSubFoloderArray.ElementAt(n)), LPCTSTR(_T("*.jpg")));
  2991. ffsco::typeT coo;
  2992. ffsco::typeT::iterator itp;
  2993. coo = op.co_file();
  2994. for (itp = coo.begin(); itp != coo.end(); itp++)
  2995. {
  2996. strOrderNumberImage = (*itp).c_str();
  2997. nIndex = strOrderNumberImage.ReverseFind('\\');
  2998. strOrderNumberImage = strOrderNumberImage.Right(strOrderNumberImage.GetLength() - nIndex -1);
  2999. if (strOrderNumberImage.Left(1) != _T("m") && strOrderNumberImage.Left(1) != _T("s"))
  3000. {
  3001. StrPhotoArray.Add((*itp).c_str());
  3002. }
  3003. }
  3004. }
  3005. return 0;
  3006. }
  3007. //---------------------------------------------------------------------
  3008. // Jeff add 2015.03.26;
  3009. // 函数:GetFileNameFromFullPath
  3010. // 描述:从全路径中获取文件名。
  3011. // 参数:
  3012. // lpFullPath:全路径;
  3013. // 返回:
  3014. //---------------------------------------------------------------------
  3015. VOID GetFileNameFromFullPath(CONST CString &strFullPath, CString &strRet)
  3016. {
  3017. // 如果参数空或如果路径不存在;
  3018. if (strFullPath.IsEmpty() || !PathFileExists(strFullPath)) return;
  3019. INT nIndex = strFullPath.ReverseFind(_T('\\'));
  3020. }
  3021. BOOL LoadMicroShareLibrary()
  3022. {
  3023. if (g_hlyfzMicroShareDLL == NULL)
  3024. g_hlyfzMicroShareDLL = LoadLibrary(_T("lyfzMicroShare.dll"));
  3025. if (g_hlyfzMicroShareDLL == NULL)
  3026. {
  3027. AfxMessageBox(_T("加载微共享模块失败!"));
  3028. return FALSE;
  3029. }
  3030. g_lyfzCreateShare = (lyfzCreateShare)::GetProcAddress(g_hlyfzMicroShareDLL, "lyfzCreateShare");
  3031. if (!g_lyfzCreateShare)
  3032. {
  3033. FreeLibrary(g_hlyfzMicroShareDLL);
  3034. g_hlyfzMicroShareDLL = NULL;
  3035. AfxMessageBox(_T("加载导入导出模块接口失败!"));
  3036. return FALSE;
  3037. }
  3038. return TRUE;
  3039. }
  3040. void FreeMicroShareLibrary()
  3041. {
  3042. if (g_hlyfzMicroShareDLL)
  3043. FreeLibrary(g_hlyfzMicroShareDLL);
  3044. g_hlyfzMicroShareDLL = NULL;
  3045. g_lyfzCreateShare = NULL;
  3046. }
  3047. // BOOL GetRemoteConfig()
  3048. // {
  3049. // // 读取remotecfg.dat;
  3050. // if (strcmp(g_szModulePath, _T("")) == 0)
  3051. // return FALSE;
  3052. //
  3053. // TCHAR szRemoteFile[MAX_PATH] = {_T("")};
  3054. // //_stprintf_s(szRemoteFile,_T("%s%s"),g_szModulePath,_T("remotecfg.dat"));
  3055. // sprintf(szRemoteFile, _T("%s%s"), g_szModulePath, _T("remotecfg.dat"));
  3056. //
  3057. // // 没找到文件;
  3058. // if (!PathFileExists(szRemoteFile)) return FALSE;
  3059. //
  3060. // // 打开文件,读取内容;
  3061. // CFile cf;
  3062. // CFileException e;
  3063. // if (!cf.Open(szRemoteFile, CFile::modeRead, &e))
  3064. // {
  3065. // // 打开文件失败;
  3066. // //e.ReportError();
  3067. // return FALSE;
  3068. // }
  3069. //
  3070. // // 清空STRemoteInfo结构;
  3071. // ZeroMemory(&g_STRemoteInfo,sizeof(STRemoteInfo));
  3072. //
  3073. // INT nCount = cf.Read(&g_STRemoteInfo, sizeof(STRemoteInfo));
  3074. // if (nCount != sizeof(STRemoteInfo))
  3075. // {
  3076. // cf.Close();
  3077. // return FALSE;
  3078. // }
  3079. //
  3080. // // 清除资源;
  3081. // cf.Close();
  3082. //
  3083. // return TRUE;
  3084. // }
  3085. BOOL OpenShareDirectory()
  3086. {
  3087. // 读取remotecfg.dat;
  3088. if (strcmp(g_szModulePath, _T("")) == 0)
  3089. return FALSE;
  3090. TCHAR szdbcfgFile[MAX_PATH] = { _T("") };
  3091. sprintf(szdbcfgFile, _T("%s%s"), g_szModulePath, _T("dbconfig.dat"));
  3092. // 没找到文件;
  3093. if (!PathFileExists(szdbcfgFile)) return FALSE;
  3094. // 打开文件,读取内容;
  3095. CFile cf;
  3096. CFileException e;
  3097. if (!cf.Open(szdbcfgFile, CFile::modeRead, &e))
  3098. {
  3099. // 打开文件失败;
  3100. e.ReportError();
  3101. return FALSE;
  3102. }
  3103. DBSAVE dbcfg;
  3104. // 清空STRemoteInfo结构;
  3105. ZeroMemory(&dbcfg, sizeof(DBSAVE));
  3106. INT nCount = cf.Read(&dbcfg, sizeof(DBSAVE));
  3107. if (nCount != sizeof(DBSAVE))
  3108. {
  3109. cf.Close();
  3110. return FALSE;
  3111. }
  3112. // 清除资源;
  3113. cf.Close();
  3114. // 解析数据;
  3115. TCHAR szHost[51] = {0};
  3116. for (int i = 0; i < 50; i++)
  3117. {
  3118. if (dbcfg.server[i])
  3119. szHost[i] = 500 - dbcfg.server[i];// = 500 - dbcfg.server[i];
  3120. if (dbcfg.user[i])
  3121. dbcfg.user[i] = 500 - dbcfg.user[i];
  3122. if (dbcfg.psw[i])
  3123. dbcfg.psw[i] = 500 - dbcfg.psw[i];
  3124. }
  3125. CString strHost = _T("");
  3126. strHost.Format(_T("%s"),szHost);
  3127. strHost.TrimLeft();
  3128. strHost.TrimRight(".");
  3129. strHost.TrimRight();
  3130. if (strHost.Find(".ly.com") == -1 && strHost.Find("192.168.") == -1)
  3131. MyGetIPByName(strHost);
  3132. // 尝试打开共享目录;
  3133. TCHAR szShareOriginal[MAX_PATH] = {_T("")};
  3134. TCHAR szShareEarly[MAX_PATH] = { _T("") };
  3135. TCHAR szShareFurther[MAX_PATH] = { _T("") };
  3136. TCHAR szShareDesign[MAX_PATH] = { _T("") };
  3137. sprintf(szShareOriginal, _T("\\\\%s\\%s"), strHost, _T("客户原片(管理软件)$"));
  3138. sprintf(szShareEarly, _T("\\\\%s\\%s"), strHost, _T("修好的片(管理软件)$"));
  3139. sprintf(szShareFurther, _T("\\\\%s\\%s"), strHost, _T("精修好的片(管理软件)$"));
  3140. sprintf(szShareDesign, _T("\\\\%s\\%s"), strHost, _T("设计好的片(管理软件)$"));
  3141. if (!PathFileExists(szShareOriginal) || !PathFileExists(szShareEarly) ||
  3142. !PathFileExists(szShareFurther) || !PathFileExists(szShareDesign) )
  3143. return FALSE;
  3144. return TRUE;
  3145. }
  3146. BOOL IsValidDate(LPCTSTR lpDate)
  3147. {
  3148. if (lpDate == NULL || _tcscmp(lpDate, _T("")) == 0)
  3149. return FALSE;
  3150. CString strDate = lpDate;
  3151. if (strDate.IsEmpty()) return FALSE;
  3152. // 判断日期合法性;
  3153. static int nYear = 0;
  3154. static int nMonth = 0;
  3155. static int nDay = 0;
  3156. nYear = nMonth = nDay = 0;
  3157. nYear = _ttoi(strDate.Left(4));
  3158. nMonth = _ttoi(strDate.Mid(5, 2));
  3159. nDay = _ttoi(strDate.Mid(8, 2));
  3160. CONST static INT nNormalMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  3161. CONST static INT nLeapMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  3162. if ((nDay <= 0) || (nDay > 31) || (nMonth <= 0) || (nMonth > 12)) return FALSE;
  3163. if ((nYear % 400 == 0) || (nYear % 4 == 0 && nYear % 100 != 0))
  3164. {
  3165. if (nDay > nLeapMonth[nMonth - 1]) return FALSE;
  3166. }
  3167. else
  3168. {
  3169. if (nDay > nNormalMonth[nMonth - 1]) return FALSE;
  3170. }
  3171. return TRUE;
  3172. }
  3173. BOOL IsValidLunanrDate(LPCTSTR lpDate)
  3174. {
  3175. if (lpDate == NULL || _tcscmp(lpDate, _T("")) == 0)
  3176. return FALSE;
  3177. CString strDate = lpDate;
  3178. if (strDate.IsEmpty()) return FALSE;
  3179. static int lunar_year, lunar_month, lunar_day;
  3180. lunar_year = lunar_month = lunar_day = 0;
  3181. lunar_year = _ttoi(strDate.Left(4));
  3182. lunar_month = _ttoi(strDate.Mid(5, 2));
  3183. lunar_day = _ttoi(strDate.Mid(8, 2));
  3184. //越界检查,如果越界,返回无效日期;
  3185. if (lunar_year <= BEGIN_YEAR || lunar_year > BEGIN_YEAR + NUMBER_YEAR - 1)
  3186. return FALSE;
  3187. if (lunar_month < 1 || lunar_month > 12)
  3188. return FALSE;
  3189. // 1.农历年是否有闰月;
  3190. int nYearIndex = lunar_year - BEGIN_YEAR;
  3191. int leap_month = (LUNAR_YEARS[nYearIndex] >> 20) & 0xF;
  3192. // 2.月份大小月天数;
  3193. int month_day = 0;
  3194. if ((LUNAR_YEARS[nYearIndex] >> (7 + 13 - lunar_month)) & 0x1)
  3195. month_day = 30;
  3196. else
  3197. month_day = 29;
  3198. if (lunar_day < 0 || lunar_day > month_day)
  3199. return FALSE;
  3200. return TRUE;
  3201. }