Global.cpp 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005
  1. #include "StdAfx.h"
  2. #include "Global.h"
  3. #include "./helper/ffsco.h"
  4. #define BAKDB_FORMAT _T("BACKUP DATABASE [%s] TO DISK='%s' WITH FORMAT")
  5. TCHAR g_szHostName[MAX_PATH] = {0}; // 本机名称;
  6. TCHAR g_ModulePath[MAX_PATH] = _T(""); // 软件目录;
  7. TCHAR g_ModuleFileName[MAX_PATH] = _T(""); // 软件名称;
  8. TCHAR g_szConnectString[MAX_PATH] = _T(""); // DB连接串;
  9. // 服务器信息;
  10. TCHAR g_szDBSource[MAX_PATH] = _T(""); // 数据库源(服务所在IP或计算机名);
  11. TCHAR g_szDBSourcePort[MAX_PATH] = _T(""); // 数据库源端口;
  12. DWORD g_dwDBServerPort = 0; // 数据库源端口;
  13. TCHAR g_szDBAccount[MAX_PATH] = _T(""); // 数据库登录用户;
  14. TCHAR g_szDBPassWord[MAX_PATH] = _T(""); // 数据库登录密码;
  15. TCHAR g_szDBName[MAX_PATH] = _T(""); // 数据库名称;
  16. TCHAR g_szLogDBName[MAX_PATH] = _T(""); // Log数据库名称;
  17. DWORD g_dwCSPort = 0;
  18. TCHAR g_szShareAccount[MAX_PATH] = {0};
  19. TCHAR g_szSharePasswd[MAX_PATH] = {0};
  20. TCHAR g_szN8ViewSvrIP[MAX_PATH] = {0}; // N8选版服务器IP;
  21. TCHAR g_szN8ViewUserDir[MAX_PATH] = {0}; // N8选版服务器用户目录(共享目录);
  22. TCHAR g_szN8ViewStsDir[MAX_PATH] = {0}; // N8选版服务器统计数据目录(共享目录);
  23. TCHAR g_szN8ViewProductDir[MAX_PATH] = {0}; // N8选版产品配置目录(共享目录);
  24. TCHAR g_szN8ViewShareDir[MAX_PATH] = {0}; // N8选版共享目录;
  25. TCHAR g_szN8ViewShareName[MAX_PATH] = {0};
  26. BOOL g_bEnableClound = FALSE; // 是否启用云选功能;
  27. BOOL g_bExportBarCode = FALSE; // 是否导出条形码位图;
  28. DWORD g_dwSoftRunTime = 0; // 软件剩余可运行时间;
  29. TCHAR g_szCloundDiskAccount[MAX_PATH] ={0}; // 云盘账号;
  30. TCHAR g_szCloundDiskPsw[MAX_PATH] = {0}; // 云盘密码(保存时需要加密);
  31. // start+------------------------------------------------------------------
  32. // Jeff:以下为原本程序全局变量;
  33. #if THE_PRIMARY_GLOBAL_VARIABLE
  34. int g_TCPport = 5678; // Jeff.通信端口;
  35. BOOL g_bReg = 0;
  36. CString g_strdbpsw; // 数据库账号、密码;
  37. CString g_strdbServrename; // 数据库服务名(地址)8
  38. CString g_bakinfo;
  39. CString g_bakphoto;
  40. CString g_mainpath;
  41. SoftKey ytSoftKey;
  42. CString g_localname; // 本地计算机名;
  43. CDatabase g_db; // 名为"db"的数据库,本年度使用的数据库;
  44. CArray<int, int> g_nYearArray; // 年份(用于命名历史数据库)
  45. //CArray<CDatabase*,CDatabase*>g_dbArray; // 历史数据库;
  46. CArray<CDatabase*, CDatabase*>g_dbHistoryArray; // 历史数据库;
  47. CArray<CDatabase*, CDatabase*>g_branchdbarray;
  48. CArray<CDatabase*, CDatabase*>g_branchdb2array;//除历史年度的分店DB
  49. CStringArray g_branchnamearray;
  50. CStringArray g_branchname2array;
  51. CStringArray g_branchiparray;
  52. CStringArray g_branchdomainarray;
  53. CDatabase *g_curdb = NULL;
  54. int g_conncount = -1; // Jeff.加密狗中的座席版数量;
  55. CString g_sdomain;
  56. CStringArray g_conniparray;
  57. CStringArray g_connidarray;
  58. BOOL g_bCheckAll = 0;
  59. BYTE *g_pSkinData = NULL;
  60. DWORD g_SkinLeng;
  61. BOOL g_bAutoRun = 0;
  62. CStringArray g_filedatearray;
  63. CStringArray g_filedatearraynew;
  64. CString g_bakdate;
  65. CString g_localip;
  66. BOOL g_bSteal = 0;
  67. CString g_bakserver1;
  68. CString g_bakserver2;
  69. CString g_bakserver3;
  70. CString g_bakserver4;
  71. DWORD g_tisks = 0;
  72. #if 0
  73. int g_nBakDays = 10; // 备份几天前的时间设置(单位:天数)
  74. int g_nBackupModel = 1;
  75. #endif //#if 0
  76. int g_bAutoCheckSvc = 1; // (1是/0否)自动检查服务(次/小时)
  77. HINSTANCE g_hDllInst = NULL;
  78. HINSTANCE g_Instance = NULL;
  79. #endif
  80. // endof+------------------------------------------------------------------
  81. /************************************************************************/
  82. /* 函数:InitSocketLibrary[2/29/2016 IT];
  83. /* 描述:Initialize Winsock library. This function calls WSAStartup;
  84. /* 参数:;
  85. /* [IN] wVersion:Winsock version use MAKEWORD macro if possible (e.g.: MAKEWORD(2,2));
  86. /* 返回:return true if successful;
  87. /* 注意:关联ReleaseSocketLibrary;
  88. /* 示例:;
  89. /*
  90. /* 修改:;
  91. /* 日期:;
  92. /* 内容:;
  93. /************************************************************************/
  94. bool InitSocketLibrary(IN WORD wVersion)
  95. {
  96. WSADATA WSAData = { 0 };
  97. return ( 0 == WSAStartup( wVersion, &WSAData ) );
  98. }
  99. /************************************************************************/
  100. /* 函数:ReleaseSocketLibrary[2/29/2016 IT];
  101. /* 描述:Release Winsock library;
  102. /* 参数:;
  103. /* 返回:return true if successful;
  104. /* 注意:关联InitSocketLibrary;
  105. /* 示例:;
  106. /*
  107. /* 修改:;
  108. /* 日期:;
  109. /* 内容:;
  110. /************************************************************************/
  111. bool ReleaseSocketLibrary()
  112. {
  113. return ( 0 == WSACleanup() );
  114. }
  115. /************************************************************************/
  116. /* 函数:[5/20/2016 IT];
  117. /* 描述:;
  118. /* 参数:;
  119. /* [IN] :;
  120. /* [OUT] :;
  121. /* [IN/OUT] :;
  122. /* 返回:void;
  123. /* 注意:;
  124. /* 示例:;
  125. /*
  126. /* 修改:;
  127. /* 日期:;
  128. /* 内容:;
  129. /************************************************************************/
  130. int GetIniInfo(const char *szPath, const char *szIniName)
  131. {
  132. TCHAR szDrive[_MAX_DRIVE];
  133. TCHAR szDir[_MAX_DIR];
  134. ::GetModuleFileName(NULL, g_ModulePath, sizeof(g_ModulePath) / sizeof(TCHAR));
  135. sprintf(g_ModuleFileName, "%s", g_ModulePath);
  136. _tsplitpath(g_ModulePath, szDrive, szDir, NULL, NULL);
  137. _tcscpy(g_ModulePath, szDrive);
  138. _tcscat(g_ModulePath, szDir);
  139. // -----------------------------------------------------//
  140. CHAR szFile[MAX_PATH + 1] = "";
  141. if (szPath != NULL && szIniName != NULL)
  142. wsprintf(szFile, "%s\\%s", szPath, szIniName);
  143. else
  144. wsprintf(szFile, "%s\\ServiceInfo.ini", g_ModulePath);
  145. TRACE("szFile =%s\n", szFile);
  146. HANDLE hFile = CreateFile(szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
  147. if (ERROR_FILE_NOT_FOUND == GetLastError())
  148. {
  149. return -1;
  150. }
  151. CloseHandle(hFile);
  152. hFile = NULL;
  153. // 获取服务器端信息;
  154. GetPrivateProfileString("DatabaseInfo", "dbSource", "", g_szDBSource, MAX_PATH, szFile);
  155. g_dwDBServerPort = GetPrivateProfileInt("DatabaseInfo", "dbServerPort", 0, szFile);
  156. GetPrivateProfileString("DatabaseInfo", "dbAccount", "", g_szDBAccount, MAX_PATH, szFile);
  157. GetPrivateProfileString("DatabaseInfo", "dbPassWord", "", g_szDBPassWord, MAX_PATH, szFile);
  158. GetPrivateProfileString("DatabaseInfo", "dbName", "", g_szDBName, MAX_PATH, szFile);
  159. #if USE_ADO_OPT_DB
  160. GetPrivateProfileString("DatabaseInfo", "LogdbName", "", g_szLogDBName, MAX_PATH, szFile);
  161. #endif//#if USE_ADO_OPT_DB
  162. g_dwCSPort = GetPrivateProfileInt("NetWorkInfo", "TCPChatPort", 5678, szFile);
  163. if (g_dwDBServerPort != 0)
  164. {
  165. if ( _tcscmp(g_szDBAccount, _T("")) == 0 )
  166. sprintf(g_szConnectString, DB_SW_CONN_WITH_PORT, g_szDBSource, g_dwDBServerPort,g_szDBName);
  167. else
  168. sprintf(g_szConnectString, DB_SS_CONN_WITH_PORT,g_szDBSource, g_dwDBServerPort, g_szDBName, g_szDBAccount, g_szDBPassWord);
  169. }
  170. else
  171. {
  172. if ( _tcscmp(g_szDBAccount, _T("")) == 0 )
  173. sprintf(g_szConnectString, DB_SW_CONN_WITHOUT_PORT, g_szDBSource, g_szDBName);
  174. else
  175. sprintf(g_szConnectString, DB_SS_CONN_WITHOUT_PORT,g_szDBSource, g_szDBName, g_szDBAccount, g_szDBPassWord);
  176. }
  177. #if 0
  178. g_nBakDays = GetPrivateProfileInt("Back", "uBakDays", 10, szFile);
  179. g_nBackupModel = GetPrivateProfileInt("Back", "uBackupModel", 1, szFile);
  180. #endif //#if 0
  181. g_bAutoCheckSvc = GetPrivateProfileInt("Back", "AutoCheckSvc", 1, szFile);
  182. // 局域网共享账号和密码;
  183. GetPrivateProfileString("NetWorkInfo", "ShareAccount", "", g_szShareAccount, MAX_PATH, szFile);
  184. GetPrivateProfileString("NetWorkInfo", "SharePasswd", "", g_szSharePasswd, MAX_PATH, szFile);
  185. // NemoInfo;
  186. GetPrivateProfileString("NemoInfo", "N8ViewSvr", "", g_szN8ViewSvrIP, MAX_PATH, szFile);
  187. GetPrivateProfileString("NemoInfo", "N8ViewUserDir", "", g_szN8ViewUserDir, MAX_PATH, szFile);
  188. GetPrivateProfileString("NemoInfo", "N8ViewStsDir", "", g_szN8ViewStsDir, MAX_PATH, szFile);
  189. GetPrivateProfileString("NemoInfo", "N8ViewProductDir", "", g_szN8ViewProductDir, MAX_PATH, szFile);
  190. GetPrivateProfileString("NemoInfo", "N8ViewShareDir", "", g_szN8ViewShareDir, MAX_PATH, szFile);
  191. GetPrivateProfileString("NemoInfo", "N8ViewShareName", "", g_szN8ViewShareName, MAX_PATH, szFile);
  192. // SystemInfo;
  193. g_bExportBarCode = GetPrivateProfileInt(_T("SystemInfo"), _T("ExportBarCode"), 0, szFile);
  194. g_bEnableClound = GetPrivateProfileInt(_T("SystemInfo"), _T("EnableClound"), 0, szFile);
  195. // 云盘账号;
  196. GetPrivateProfileString(_T("SystemInfo"), _T("CloundDiskAccount"), _T(""), g_szCloundDiskAccount, MAX_PATH, szFile);
  197. // 云盘密码;
  198. GetPrivateProfileString(_T("SystemInfo"), _T("CloundDiskPsw"), _T(""), g_szCloundDiskPsw, MAX_PATH, szFile);
  199. // 解密云盘密码;
  200. CString strResult;
  201. des_crypt((CString)g_szCloundDiskPsw, strResult, DES_DECRYPT);
  202. _stprintf_s(g_szCloundDiskPsw, MAX_PATH, _T("%s"), strResult);
  203. return 0;
  204. }
  205. //------------------------------------------------------------
  206. // 以下全局函数为原程序所有;
  207. #if THE_PRIMARY_GLOBAL_FUNCTION
  208. BOOL AddConn(CDatabase *m_conndb, CString dbname)
  209. {
  210. try {
  211. CString strCon;
  212. strCon.Format(DB_SS_CONN_WITHOUT_PORT, g_strdbServrename, dbname, g_szDBAccount, g_szDBPassWord);
  213. m_conndb->OpenEx(strCon, CDatabase::noOdbcDialog);
  214. }
  215. catch (CDBException * e)
  216. {
  217. WriteLogin("新建连接时出错:" + e->m_strError);
  218. #ifdef _DEBUG
  219. e->ReportError();
  220. #endif
  221. e->Delete();
  222. return 0;
  223. }
  224. return 1;
  225. }
  226. void WriteError(CString str)
  227. {
  228. MyLock lock("DBServerWriteError");
  229. CStdioFile fp;
  230. CString path = g_mainpath + "\\MsgError.txt";
  231. if (::PathFileExists(path))
  232. {
  233. fp.Open(path, CFile::modeWrite);
  234. int length = fp.GetLength();
  235. if (length > 1024 * 1024)
  236. {
  237. fp.Close();
  238. ::DeleteFile(path); // 删除MsgError.txt
  239. return;
  240. }
  241. fp.SeekToEnd();
  242. }
  243. else
  244. fp.Open(path, CFile::modeCreate | CFile::modeWrite);
  245. fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S ") + str + "\n");
  246. fp.Close();
  247. }
  248. void WritePswWrong(CString str)
  249. {
  250. MyLock lock("DBServerWritePswWrong");
  251. CStdioFile fp;
  252. CString path = g_mainpath + "\\PswWrong.txt";
  253. if (::PathFileExists(path))
  254. {
  255. fp.Open(path, CFile::modeWrite);
  256. int length = fp.GetLength();
  257. if (length > 1024 * 1024)
  258. {
  259. fp.Close();
  260. ::DeleteFile(path); // 删除PswWrong.txt
  261. return;
  262. }
  263. fp.SeekToEnd();
  264. }
  265. else
  266. fp.Open(path, CFile::modeCreate | CFile::modeWrite);
  267. fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S ") + str + "\n");
  268. fp.Close();
  269. }
  270. void WriteNullBalance(CString str)
  271. {
  272. MyLock lock("DBServerWriteNullBalance");
  273. CStdioFile fp;
  274. CString path = g_mainpath + "\\NullBalance.txt";
  275. if (::PathFileExists(path))
  276. {
  277. fp.Open(path, CFile::modeWrite);
  278. int length = fp.GetLength();
  279. if (length > 1024 * 1024)
  280. {
  281. fp.Close();
  282. ::DeleteFile(path); // 删除NullBalance.txt
  283. return;
  284. }
  285. fp.SeekToEnd();
  286. }
  287. else
  288. fp.Open(path, CFile::modeCreate | CFile::modeWrite);
  289. fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S ") + str + "\n");
  290. fp.Close();
  291. }
  292. void WriteUnallowIP(CString str)
  293. {
  294. CStdioFile fp;
  295. CString path = g_mainpath + "\\UnallowIP.txt";
  296. if (::PathFileExists(path))
  297. {
  298. fp.Open(path, CFile::modeWrite);
  299. int length = fp.GetLength();
  300. if (length > 1024 * 1024)
  301. {
  302. fp.Close();
  303. ::DeleteFile(path); // 删除UnallowIP.txt
  304. return;
  305. }
  306. fp.SeekToEnd();
  307. }
  308. else
  309. fp.Open(path, CFile::modeCreate | CFile::modeWrite);
  310. fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S ") + str + "\n");
  311. fp.Close();
  312. }
  313. int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
  314. {
  315. UINT num = 0; // number of image encoders
  316. UINT size = 0; // size of the image encoder array in bytes CheckFolderFileExist
  317. ImageCodecInfo* pImageCodecInfo = NULL;
  318. GetImageEncodersSize(&num, &size);
  319. if (size == 0)
  320. return -1; // Failure
  321. pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
  322. if (pImageCodecInfo == NULL)
  323. return -1; // Failure
  324. GetImageEncoders(num, size, pImageCodecInfo);
  325. for (UINT j = 0; j < num; ++j)
  326. {
  327. if (wcscmp(pImageCodecInfo[j].MimeType, format) == 0)
  328. {
  329. *pClsid = pImageCodecInfo[j].Clsid;
  330. free(pImageCodecInfo);
  331. return j; // Success
  332. }
  333. }
  334. free(pImageCodecInfo);
  335. return -1; // Failure
  336. }
  337. void SaveImageToFile(Image *img, CString path)
  338. {
  339. try
  340. {
  341. if (img == NULL)return;
  342. CLSID encoderClsid;
  343. BSTR bstr = path.AllocSysString();
  344. path.MakeLower();
  345. if (path.Right(3) == "bmp")
  346. {
  347. GetEncoderClsid(L"image/bmp", &encoderClsid);
  348. img->Save(bstr, &encoderClsid, NULL);
  349. }
  350. else if (path.Right(3) == "png")
  351. {
  352. GetEncoderClsid(L"image/png", &encoderClsid);
  353. img->Save(bstr, &encoderClsid, NULL);
  354. }
  355. else// if(path.Right (3)=="jpg")
  356. {
  357. GetEncoderClsid(L"image/jpeg", &encoderClsid);
  358. EncoderParameters encoderParameters;
  359. ULONG quality;
  360. encoderParameters.Count = 1;
  361. encoderParameters.Parameter[0].Guid = EncoderQuality;
  362. encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
  363. encoderParameters.Parameter[0].NumberOfValues = 1;
  364. // Save the image as a JPEG with quality level 100.
  365. quality = 100;
  366. encoderParameters.Parameter[0].Value = &quality;
  367. img->Save(bstr, &encoderClsid, &encoderParameters);
  368. }
  369. SysFreeString(bstr);
  370. }
  371. catch (...)
  372. {
  373. }
  374. }
  375. void SaveImageToFile2(Image *img, CString path, ULONG quality)
  376. {
  377. try
  378. {
  379. if (img == NULL)return;
  380. CLSID encoderClsid;
  381. BSTR bstr = path.AllocSysString();
  382. path.MakeLower();
  383. if (path.Right(3) == "bmp")
  384. {
  385. GetEncoderClsid(L"image/bmp", &encoderClsid);
  386. img->Save(bstr, &encoderClsid, NULL);
  387. }
  388. else if (path.Right(3) == "png")
  389. {
  390. GetEncoderClsid(L"image/png", &encoderClsid);
  391. img->Save(bstr, &encoderClsid, NULL);
  392. }
  393. else// if(path.Right (3)=="jpg")
  394. {
  395. GetEncoderClsid(L"image/jpeg", &encoderClsid);
  396. EncoderParameters encoderParameters;
  397. encoderParameters.Count = 1;
  398. encoderParameters.Parameter[0].Guid = EncoderQuality;
  399. encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
  400. encoderParameters.Parameter[0].NumberOfValues = 1;
  401. // Save the image as a JPEG with quality level 100.
  402. encoderParameters.Parameter[0].Value = &quality;
  403. img->Save(bstr, &encoderClsid, &encoderParameters);
  404. }
  405. SysFreeString(bstr);
  406. }
  407. catch (...)
  408. {
  409. }
  410. }
  411. void RectFitDes(int width, int height, CRect &rc)
  412. {
  413. float fscale = (float)width / (float)height;
  414. float rcscale = ((float)rc.Width()) / ((float)rc.Height());
  415. int rcwid = rc.Width();
  416. int rchei = rc.Height();
  417. int dt = 0;
  418. if (rcscale < fscale)
  419. {
  420. dt = (rchei - rcwid / fscale) / 2;
  421. rc.top += dt;
  422. rc.bottom -= dt;
  423. }
  424. else
  425. {
  426. dt = (rcwid - rchei*fscale) / 2;
  427. rc.left += dt;
  428. rc.right -= dt;
  429. }
  430. }
  431. ///目录是否存在的检查: 支持网络文件,判断文件时有漏洞
  432. bool CheckFolderFileExist(CString &strPath)
  433. {
  434. strPath.MakeLower();
  435. /*
  436. if (strPath.Find("c:\\") != -1 || strPath.Find("d:\\") != -1 || strPath.Find("e:\\") != -1 || strPath.Find("f:\\") != -1 || strPath.Find("g:\\") != -1 || strPath.Find("h:\\") != -1 || strPath.Find("i:\\") != -1 || strPath.Find("j:\\") != -1 || strPath.Find("k:\\") != -1 || strPath.Find("l:\\") != -1 || strPath.Find("m:\\") != -1)
  437. {
  438. return ::PathFileExists(strPath);
  439. }
  440. */
  441. if(!PathFileExists(strPath))
  442. return 0;
  443. CString path = strPath;
  444. CFile fp;
  445. if (fp.Open(path, CFile::modeRead))
  446. {
  447. fp.Close();
  448. return 1;
  449. }
  450. if (strPath.Right(1) != "\\")
  451. path += "\\";
  452. path += "zaqw1234.dat";
  453. ::DeleteFile(path);// 删除zaqw1234.dat文件;
  454. if (fp.Open(path, CFile::modeCreate) == 0)
  455. return 0;
  456. fp.Close();
  457. ::DeleteFile(path); // 删除zaqw1234.dat文件;
  458. return 1;
  459. }
  460. bool CheckFileExist(CString &strPath)
  461. {
  462. strPath.MakeLower();
  463. if (strPath.Find("c:\\") != -1 || strPath.Find("d:\\") != -1 || strPath.Find("e:\\") != -1 || strPath.Find("f:\\") != -1 || strPath.Find("g:\\") != -1 || strPath.Find("h:\\") != -1 || strPath.Find("i:\\") != -1 || strPath.Find("j:\\") != -1 || strPath.Find("k:\\") != -1 || strPath.Find("l:\\") != -1 || strPath.Find("m:\\") != -1)
  464. {
  465. return ::PathFileExists(strPath);
  466. }
  467. CString path = strPath;
  468. CFile fp;
  469. if (fp.Open(path, CFile::modeRead))
  470. {
  471. fp.Close();
  472. return 1;
  473. }
  474. return 0;
  475. }
  476. BOOL EncryptFile2(BYTE *buffer, DWORD leng, PCHAR szPassword)
  477. {
  478. try
  479. {
  480. HCRYPTPROV hCryptProv;
  481. HCRYPTKEY hKey;
  482. HCRYPTHASH hHash;
  483. PBYTE pbBuffer;
  484. DWORD dwBlockLen;
  485. DWORD dwBufferLen;
  486. DWORD dwCount;
  487. //以下获得一个CSP句柄
  488. if (CryptAcquireContext(
  489. &hCryptProv,
  490. NULL, //NULL表示使用默认密钥容器,默认密钥容器名为用户登陆名
  491. NULL,
  492. PROV_RSA_FULL,
  493. 0))
  494. {
  495. printf("A cryptographic provider has been acquired. \n");
  496. }
  497. else//密钥容器不存在
  498. {
  499. if (CryptAcquireContext(
  500. &hCryptProv,
  501. NULL,
  502. NULL,
  503. PROV_RSA_FULL,
  504. CRYPT_NEWKEYSET))//创建密钥容器
  505. {
  506. //创建密钥容器成功,并得到CSP句柄
  507. printf("A new key container has been created.\n");
  508. }
  509. else
  510. {
  511. return 0;
  512. }
  513. }
  514. //--------------------------------------------------------------------
  515. // 创建一个会话密钥(session key)
  516. // 会话密钥也叫对称密钥,用于对称加密算法。
  517. // (注: 一个Session是指从调用函数CryptAcquireContext到调用函数
  518. // CryptReleaseContext 期间的阶段。)
  519. //--------------------------------------------------------------------
  520. // Create a hash object.
  521. if (CryptCreateHash(
  522. hCryptProv,
  523. CALG_MD5,
  524. 0,
  525. 0,
  526. &hHash))
  527. {
  528. printf("A hash object has been created. \n");
  529. }
  530. else
  531. {
  532. return 0;
  533. }
  534. //--------------------------------------------------------------------
  535. // 用输入的密码产生一个散列
  536. if (CryptHashData(
  537. hHash,
  538. (BYTE *)szPassword,
  539. strlen(szPassword),
  540. 0))
  541. {
  542. printf("The password has been added to the hash. \n");
  543. }
  544. else
  545. {
  546. return 0;
  547. }
  548. //--------------------------------------------------------------------
  549. // 通过散列生成会话密钥(session key)
  550. if (CryptDeriveKey(
  551. hCryptProv,
  552. ENCRYPT_ALGORITHM,
  553. hHash,
  554. KEYLENGTH,
  555. &hKey))
  556. {
  557. printf("An encryption key is derived from the password hash. \n");
  558. }
  559. else
  560. {
  561. return 0;
  562. }
  563. //--------------------------------------------------------------------
  564. // Destroy the hash object.
  565. CryptDestroyHash(hHash);
  566. hHash = NULL;
  567. //--------------------------------------------------------------------
  568. // The session key is now ready.
  569. //--------------------------------------------------------------------
  570. // 因为加密算法是按ENCRYPT_BLOCK_SIZE 大小的块加密的,所以被加密的
  571. // 数据长度必须是ENCRYPT_BLOCK_SIZE 的整数倍。下面计算一次加密的
  572. // 数据长度。
  573. dwBlockLen = 1000 - 1000 % ENCRYPT_BLOCK_SIZE;
  574. //--------------------------------------------------------------------
  575. // Determine the block size. If a block cipher is used,
  576. // it must have room for an extra block.
  577. if (ENCRYPT_BLOCK_SIZE > 1)
  578. dwBufferLen = dwBlockLen + ENCRYPT_BLOCK_SIZE;
  579. else
  580. dwBufferLen = dwBlockLen;
  581. dwCount = dwBufferLen;
  582. //--------------------------------------------------------------------
  583. // In a do loop, encrypt the source file and write to the source file.
  584. int count;
  585. // if(leng%dwBlockLen==0)
  586. count = leng / dwBufferLen;
  587. // else
  588. // count=leng/dwBlockLen+1;
  589. int i = 0;
  590. for (i = 0; i < count; i++)
  591. {
  592. pbBuffer = buffer + i*dwBufferLen;
  593. // 加密数据
  594. if (!CryptEncrypt(
  595. hKey, //密钥
  596. 0, //如果数据同时进行散列和加密,这里传入一个散列对象
  597. 0, //如果是最后一个被加密的块,输入TRUE.如果不是输入FALSE.
  598. //这里通过判断是否到文件尾来决定是否为最后一块。
  599. 0, //保留
  600. pbBuffer, //输入被加密数据,输出加密后的数据
  601. &dwCount, //输入被加密数据实际长度,输出加密后数据长度
  602. dwBufferLen)) //pbBuffer的大小。
  603. {
  604. return 0;
  605. }
  606. }
  607. if (leng%dwBlockLen)
  608. {
  609. pbBuffer = buffer + i*dwBufferLen;
  610. dwCount = leng - i*dwBufferLen;
  611. if (!CryptEncrypt(
  612. hKey, //密钥
  613. 0, //如果数据同时进行散列和加密,这里传入一个散列对象
  614. TRUE, //如果是最后一个被加密的块,输入TRUE.如果不是输入FALSE.
  615. //这里通过判断是否到文件尾来决定是否为最后一块。
  616. 0, //保留
  617. pbBuffer, //输入被加密数据,输出加密后的数据
  618. &dwCount, //输入被加密数据实际长度,输出加密后数据长度
  619. dwBufferLen)) //pbBuffer的大小。
  620. {
  621. return 0;
  622. }
  623. }
  624. //--------------------------------------------------------------------
  625. // Destroy session key.
  626. if (hKey)
  627. CryptDestroyKey(hKey);
  628. //--------------------------------------------------------------------
  629. // Destroy hash object.
  630. if (hHash)
  631. CryptDestroyHash(hHash);
  632. //--------------------------------------------------------------------
  633. // Release provider handle.
  634. if (hCryptProv)
  635. CryptReleaseContext(hCryptProv, 0);
  636. return(TRUE);
  637. }
  638. catch (...)
  639. {
  640. }
  641. }
  642. /************************************************************************/
  643. /* 函数:[3/15/2016 IT];
  644. /* 描述:;
  645. /* 参数:;
  646. /* [IN] strBackupDir:数据库的备份路径;
  647. /* [IN] bBackupToday: 是否备份今天的数据库;
  648. /* [IN] bBackupHistory:是否备份历史数据库;
  649. /* 返回:void;
  650. /* 注意:;
  651. /* 示例:;
  652. /*
  653. /* 修改:;
  654. /* 日期:;
  655. /* 内容:;
  656. /************************************************************************/
  657. void BackupDatabase( IN CString strBackupDir, IN BOOL bBackupToday, IN BOOL bBackupHistory )
  658. {
  659. // 1.使用master系统数据库来备份;
  660. CDatabase tagMaster;
  661. try
  662. {
  663. TCHAR szConnectString[MAX_PATH] = _T("");
  664. if( g_dwDBServerPort != 0)
  665. {
  666. if ( _tcscmp(g_szDBAccount, _T("")) == 0 )
  667. sprintf(szConnectString,DB_SW_CONN_WITH_PORT, g_szDBSource,g_dwDBServerPort, _T("master"), g_szDBName);
  668. else
  669. sprintf(szConnectString,DB_SS_CONN_WITH_PORT,g_szDBSource,g_dwDBServerPort, _T("master"), g_szDBAccount,g_szDBPassWord);
  670. }
  671. else
  672. {
  673. if ( _tcscmp(g_szDBAccount, _T("")) == 0 )
  674. sprintf(szConnectString,DB_SW_CONN_WITHOUT_PORT, g_szDBSource, _T("master"), g_szDBName);
  675. else
  676. sprintf(szConnectString,DB_SS_CONN_WITHOUT_PORT,g_szDBSource, _T("master"), g_szDBAccount,g_szDBPassWord);
  677. }
  678. tagMaster.OpenEx(szConnectString, CDatabase::noOdbcDialog);
  679. }
  680. catch (CDBException *e)
  681. {
  682. #ifdef _DEBUG
  683. e->ReportError();
  684. #endif
  685. e->Delete();
  686. }
  687. try
  688. {
  689. // 2.获取昨天的日期tm2;
  690. CTime tToday = CTime::GetCurrentTime();
  691. CTimeSpan tSpan(1, 0, 0, 0);
  692. CTime tYesterday;
  693. if (bBackupToday)
  694. tYesterday = tToday;
  695. else
  696. tYesterday = tToday - tSpan;
  697. CString savepath;
  698. savepath.Format(_T("%s\\%s(sql).bak"), strBackupDir, tYesterday.Format(_T("%Y%m%d")));
  699. BOOL bBak = 0; // 是否备份成功;
  700. BOOL bBak2 = 0; // 是否备份历史年限数据库成功;
  701. // 3.如果没找到<昨天>备份数据库,则进行备份;
  702. if (!PathFileExists(savepath))
  703. {
  704. tagMaster.SetQueryTimeout(600);
  705. {
  706. CString sql;
  707. sql.Format(_T("BACKUP DATABASE [%s] TO DISK='%s' WITH FORMAT"), g_szDBName, savepath);
  708. try
  709. {
  710. tagMaster.ExecuteSQL(sql);
  711. bBak = 1;
  712. g_bakinfo = _T("资料备份成功");
  713. }
  714. catch (CDBException * e)
  715. {
  716. #ifdef _DEBUG
  717. e->ReportError();
  718. #endif
  719. WriteLogin(e->m_strError);
  720. WriteLogin(_T("备份失败!"));
  721. e->Delete();
  722. }
  723. }
  724. tagMaster.SetQueryTimeout(100);
  725. }
  726. // 4.Jeff.是否备份历史数据库;
  727. if (bBackupHistory)
  728. {
  729. for (int i = CTime::GetCurrentTime().GetYear() - 1; i >= 2009; i--)
  730. {
  731. tagMaster.SetQueryTimeout(600);
  732. {
  733. CString savepath2;
  734. savepath2.Format(_T("%s\\%s-%d(sql).bak"), strBackupDir, tYesterday.Format(_T("%Y%m%d")), i);
  735. CString sql;
  736. sql.Format(_T("BACKUP DATABASE [%d] TO DISK='%s' WITH FORMAT"), i, savepath2);
  737. try
  738. {
  739. tagMaster.ExecuteSQL(sql);
  740. bBak2 = 1;
  741. }
  742. catch (CDBException * e)
  743. {
  744. #ifdef _DEBUG
  745. e->ReportError();
  746. #endif
  747. e->Delete();
  748. break;
  749. }
  750. }
  751. tagMaster.SetQueryTimeout(100);
  752. }
  753. }
  754. // 5.昨天的数据库备份是否备份成功;
  755. if (bBak)
  756. {
  757. CTimeSpan dt2(31, 0, 0, 0);
  758. CTimeSpan dt3(365, 0, 0, 0);
  759. // tm:今天, tm3:1个月前, tm4:1年前;
  760. CTime tm3 = tToday - dt2;
  761. CTime tm4 = tToday - dt3;
  762. // 6.循环删除数据库备份;
  763. while (tm3 > tm4)
  764. {
  765. savepath.Format(_T("%s\\%s.bak"), strBackupDir, tm3.Format(_T("%Y%m%d")));
  766. #ifdef SQLSERVER_VERSION
  767. savepath.Format(_T("%s\\%s(sql).bak"), strBackupDir, tm3.Format(_T("%Y%m%d")));
  768. #endif
  769. // Jeff.删除一个月前的数据库备份;
  770. if (!CheckFileExist(savepath))
  771. break;
  772. ::DeleteFile(savepath); // 删除备份的数据库文件*.bak;
  773. tm3 -= tSpan; // dt 1天的间隔;
  774. }
  775. }
  776. if (bBak2)
  777. {
  778. CTimeSpan dt2(15, 0, 0, 0);
  779. CTimeSpan dt3(365, 0, 0, 0);
  780. for (int i = tToday.GetYear() - 1; i >= 2009; i--)
  781. {
  782. CTime tm3 = tToday - dt2;
  783. CTime tm4 = tToday - dt3;
  784. while (tm3 > tm4)
  785. {
  786. savepath.Format(_T("%s\\%s-%d.bak"), strBackupDir, tm3.Format(_T("%Y%m%d")), i);
  787. #ifdef SQLSERVER_VERSION
  788. savepath.Format(_T("%s\\%s-%d(sql).bak"), strBackupDir, tm3.Format(_T("%Y%m%d")), i);
  789. #endif
  790. if (!CheckFileExist(savepath))
  791. break;
  792. ::DeleteFile(savepath); // 删除备份的数据库文件*.bak;
  793. tm3 -= tSpan;
  794. }
  795. }
  796. }
  797. }
  798. catch (...)
  799. {
  800. WriteLogin("出错在函数BackupDatabase中");
  801. }
  802. tagMaster.Close();
  803. }
  804. void BakData(CString savedir, BOOL bToday, BOOL bBakHis)// back data
  805. {
  806. #ifdef SQLSERVER_VERSION
  807. BackupDatabase(savedir, bToday, bBakHis);
  808. return;
  809. #endif
  810. try
  811. {
  812. CTime tm = CTime::GetCurrentTime();
  813. CTimeSpan dt(1, 0, 0, 0);
  814. CTime tm2;
  815. if (bToday)
  816. tm2 = tm;
  817. else
  818. tm2 = tm - dt;
  819. CString savepath;
  820. savepath.Format("%s\\%s.bak", savedir, tm2.Format("%Y%m%d"));
  821. #ifdef SQLSERVER_VERSION
  822. savepath.Format("%s\\%s(sql).bak", savedir, tm2.Format("%Y%m%d"));
  823. #endif
  824. BOOL bBak = 0;
  825. BOOL bBak2 = 0;
  826. {
  827. TCHAR szDBFile[MAX_PATH] = _T(""); // Jeff.add
  828. #ifdef SQLSERVER_VERSION
  829. _stprintf_s(szDBFile, _T("%s\\数据\\%s.mdf"), g_ModulePath, g_szDBName);
  830. //if(::CopyFile (g_mainpath+"\\数据\\db.mdf", savepath, 0))
  831. #else
  832. sprintf(szDBFile, "%s\\数据\\%s.mdb", g_ModulePath, g_szDBName);
  833. //if(::CopyFile (g_mainpath+"\\数据\\db.mdb", savepath, 0))
  834. #endif
  835. if (::CopyFile(szDBFile, savepath, 0))
  836. {
  837. bBak = 1;
  838. g_bakinfo = "资料备份成功";
  839. }
  840. }
  841. if (bBak)
  842. {
  843. CTimeSpan dt2(15, 0, 0, 0);
  844. CTimeSpan dt3(365, 0, 0, 0);
  845. CTime tm3 = tm - dt2;
  846. CTime tm4 = tm - dt3;
  847. while (tm3 > tm4)
  848. {
  849. savepath.Format("%s\\%s.bak", savedir, tm3.Format("%Y%m%d"));
  850. #ifdef SQLSERVER_VERSION
  851. savepath.Format("%s\\%s(sql).bak", savedir, tm3.Format("%Y%m%d"));
  852. #endif
  853. if (!CheckFileExist(savepath))
  854. break;
  855. ::DeleteFile(savepath); // 删除备份的数据库文件*.bak;
  856. tm3 -= dt;
  857. }
  858. }
  859. //备份历史数据
  860. for (int i = tm.GetYear() - 1; i >= 1900; i--)
  861. {
  862. #ifdef SQLSERVER_VERSION
  863. savepath.Format("%s\\数据\\%d.mdf", g_mainpath, i);
  864. #else
  865. savepath.Format("%s\\数据\\%d.mdb", g_mainpath, i);
  866. #endif
  867. if (CheckFileExist(savepath) == 0)
  868. break;
  869. CString savepath2 = _T("");
  870. savepath2.Format("%s\\%s-%d.bak", savedir, tm2.Format("%Y%m%d"), i);
  871. #ifdef SQLSERVER_VERSION
  872. savepath2.Format("%s\\%s-%d(sql).bak", savedir, tm2.Format("%Y%m%d"), i);
  873. #endif
  874. if (::CopyFile(savepath, savepath2, 0))
  875. bBak2 = 1;
  876. }
  877. if (bBak2)
  878. {
  879. CTimeSpan dt2(7, 0, 0, 0);
  880. CTimeSpan dt3(365, 0, 0, 0);
  881. for (int i = tm.GetYear() - 1; i >= 1900; i--)
  882. {
  883. #ifdef SQLSERVER_VERSION
  884. savepath.Format("%s\\数据\\%d.mdf", g_mainpath, i);
  885. #else
  886. savepath.Format("%s\\数据\\%d.mdb", g_mainpath, i);
  887. #endif
  888. if (CheckFileExist(savepath) == 0)break;
  889. CTime tm3 = tm - dt2;
  890. CTime tm4 = tm - dt3;
  891. while (tm3 > tm4)
  892. {
  893. savepath.Format("%s\\%s-%d.bak", savedir, tm3.Format("%Y%m%d"), i);
  894. #ifdef SQLSERVER_VERSION
  895. savepath.Format("%s\\%s-%d(sql).bak", savedir, tm3.Format("%Y%m%d"), i);
  896. #endif
  897. if (!CheckFileExist(savepath))
  898. break;
  899. ::DeleteFile(savepath); // 删除备份的数据库文件*.bak;
  900. tm3 -= dt;
  901. }
  902. }
  903. }
  904. }
  905. catch (...)
  906. {
  907. WriteLogin("出错在函数BakData中");
  908. }
  909. }
  910. DWORD FindAppProcessID(CString path)
  911. {
  912. try
  913. {
  914. HANDLE handle = ::CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
  915. PROCESSENTRY32 Info;
  916. Info.dwSize = sizeof(PROCESSENTRY32);
  917. path.MakeLower();
  918. if (::Process32First(handle, &Info))
  919. {
  920. do
  921. {
  922. CString ss = Info.szExeFile;
  923. ss.MakeLower();
  924. if (ss == path)
  925. {
  926. ::CloseHandle(handle);
  927. return Info.th32ProcessID;
  928. }
  929. } while (::Process32Next(handle, &Info));
  930. ::CloseHandle(handle);
  931. }
  932. return 0;
  933. }
  934. catch (...)
  935. {
  936. }
  937. return 0;
  938. }
  939. BOOL lyfzCopyFileEx(LPCTSTR lpExistingFileName, LPCTSTR lpNewFileName, const BOOL &bFailIfExists)
  940. {
  941. // 1.如果是覆盖选项;
  942. if (!bFailIfExists)
  943. return CopyFile(lpExistingFileName, lpNewFileName, bFailIfExists);
  944. // 2.如果不是覆盖选项;
  945. TCHAR szNewFileName[1024] = { 0 };
  946. TCHAR szDrive[_MAX_DRIVE] = { 0 };
  947. TCHAR szDir[_MAX_DIR] = { 0 };
  948. TCHAR szFna[_MAX_FNAME] = { 0 };
  949. TCHAR szExt[_MAX_EXT] = { 0 };
  950. sprintf(szNewFileName, _T("%s"), lpNewFileName);
  951. _tsplitpath(szNewFileName, szDrive, szDir, szFna, szExt);
  952. int nIndex = 1;
  953. while (PathFileExists(szNewFileName))
  954. {
  955. sprintf(szNewFileName, _T("%s%s%s (%d)%s"), szDrive, szDir, szFna, nIndex++, szExt);
  956. }
  957. return CopyFile(lpExistingFileName, szNewFileName, bFailIfExists);
  958. }
  959. void WriteLogin(CString str) // 线程安全问题,如果同时有两个线程同时访问,可能存在线程安全问题;
  960. {
  961. MyLock lock("CDBServerDlgWriteLogin");
  962. try
  963. {
  964. CStdioFile fp;
  965. CString path = g_mainpath + "\\日志.txt";
  966. if (CheckFileExist(path))
  967. {
  968. fp.Open(path, CFile::modeWrite);
  969. int length = fp.GetLength();
  970. if (length > 5 * 1024 * 1024)
  971. {
  972. fp.Close();
  973. lyfzCopyFileEx(path,g_mainpath + _T("\\日志\\日志.txt"),TRUE);
  974. ::DeleteFile(path); // 删除备份的 日志.txt;
  975. return;
  976. }
  977. fp.SeekToEnd();
  978. }
  979. else
  980. fp.Open(path, CFile::modeCreate | CFile::modeWrite);
  981. fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S") + " " + str + "\n");
  982. fp.Close();
  983. }
  984. catch (...)
  985. {
  986. }
  987. }
  988. void GetPathFromNetShareName(CString name, CString &sRet)
  989. {
  990. if (sRet.Find(":") != -1)return;
  991. NET_API_STATUS res;
  992. SHARE_INFO_502 * psi = NULL;
  993. WCHAR wszShareName[255];
  994. TCHAR szPathName[255];
  995. TCHAR path[255];
  996. memset(path, 0, 255);
  997. //转换成宽字符
  998. MultiByteToWideChar(CP_ACP, 0, name, -1, wszShareName, 255);
  999. #if 0
  1000. res = NetShareGetInfo(NULL, (char *)wszShareName, 502, (LPBYTE *)&psi);
  1001. #else
  1002. res = NetShareGetInfo(NULL, wszShareName, 502, (LPBYTE *)&psi);
  1003. #endif
  1004. if (res == NERR_Success)
  1005. {
  1006. wsprintf((char*)szPathName, "%S ", psi->shi502_path);
  1007. sRet = szPathName;
  1008. sRet.TrimRight();
  1009. }
  1010. else
  1011. {
  1012. CString str;
  1013. #if 0 // Jeff delete;
  1014. str.Format("转换路径失败-%d", res);
  1015. ::WriteLogin(str);//Jeff delete,此处使用了系统域符号,其实完全没作用.
  1016. #else
  1017. str.Format("转换路径失败(\"%s\"),", sRet);
  1018. ErrorExit(str, res);
  1019. #endif
  1020. }
  1021. //释放缓冲
  1022. NetApiBufferFree(psi);
  1023. }
  1024. CString GetModifyTime2(CString path)
  1025. {
  1026. try
  1027. {
  1028. CFileFind finder;
  1029. BOOL bWorking = finder.FindFile(path);
  1030. if (bWorking)
  1031. {
  1032. finder.FindNextFile();
  1033. CTime tm;
  1034. finder.GetLastWriteTime(tm);
  1035. CString stime;
  1036. stime.Format("%d%02d%02d", tm.GetYear(), tm.GetMonth(), tm.GetDay());
  1037. return stime;
  1038. }
  1039. return "";
  1040. }
  1041. #if JEFF_TEST_ON
  1042. catch (CFileException *e)
  1043. {
  1044. CString strError;
  1045. strError.Format("2.读文件[%s]修改时间出错:%d", e->m_strFileName, e->m_lOsError);
  1046. WriteLogin(strError);
  1047. e->Delete();
  1048. }
  1049. #else
  1050. catch (...)
  1051. {
  1052. WriteLogin("出错");
  1053. }
  1054. #endif
  1055. return _T("");
  1056. }
  1057. CString GetModifyTime(CString path)
  1058. {
  1059. try
  1060. {
  1061. HANDLE hFile;
  1062. WIN32_FIND_DATA wfd;
  1063. // SYSTEMTIME systime;
  1064. FILETIME localtime;
  1065. CString stime; //输出时间
  1066. memset(&wfd, 0, sizeof(wfd));
  1067. if ((hFile = FindFirstFile(path, &wfd)) == INVALID_HANDLE_VALUE)
  1068. return "";
  1069. //ok,转换时间
  1070. FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localtime);
  1071. stime.Format("%16d%16d", localtime.dwHighDateTime, localtime.dwLowDateTime);
  1072. return stime;
  1073. }
  1074. #if JEFF_TEST_ON
  1075. catch (CFileException *e)
  1076. {
  1077. CString strError;
  1078. strError.Format("读文件[%s]修改时间出错:%d", e->m_strFileName, e->m_lOsError);
  1079. WriteLogin(strError);
  1080. e->Delete();
  1081. }
  1082. #else catch (...)
  1083. {
  1084. WriteLogin("出错");
  1085. }
  1086. #endif
  1087. return _T("");
  1088. }
  1089. //--------------------------------------------------------------------------------
  1090. // Jeff add 2014.06.23;
  1091. // 函数:ErrorExit
  1092. // 描述:
  1093. // 参数:
  1094. // lpszFunction:函数名;
  1095. // dwError:错误码;
  1096. //
  1097. //--------------------------------------------------------------------------------
  1098. void ErrorExit(CString strDescription, const DWORD &dwError)
  1099. {
  1100. #if 1
  1101. LPVOID lpMsgBuf;
  1102. BOOL fOk = FormatMessage(
  1103. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  1104. FORMAT_MESSAGE_FROM_SYSTEM |
  1105. FORMAT_MESSAGE_IGNORE_INSERTS,
  1106. NULL,
  1107. dwError,
  1108. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  1109. (LPTSTR)&lpMsgBuf,
  1110. 0, NULL);
  1111. if (!fOk)
  1112. {
  1113. // Is it a network-related error?
  1114. HMODULE hDll = LoadLibraryEx(TEXT("netmsg.dll"), NULL, DONT_RESOLVE_DLL_REFERENCES);
  1115. if (hDll != NULL)
  1116. {
  1117. FormatMessage(
  1118. FORMAT_MESSAGE_FROM_HMODULE |
  1119. FORMAT_MESSAGE_FROM_SYSTEM |
  1120. FORMAT_MESSAGE_IGNORE_INSERTS,
  1121. hDll,
  1122. dwError,
  1123. MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
  1124. (LPTSTR)&lpMsgBuf,
  1125. 0,
  1126. NULL);
  1127. FreeLibrary(hDll);
  1128. }
  1129. }
  1130. if (lpMsgBuf != NULL)
  1131. {
  1132. CString strDisplay;
  1133. strDisplay.Format("%s.错误码=%d,Windows描述:%s", strDescription, dwError, (LPCTSTR)LocalLock(lpMsgBuf));
  1134. WriteLogin(strDisplay);
  1135. LocalFree(lpMsgBuf);
  1136. }
  1137. else
  1138. {
  1139. WriteLogin(strDescription);
  1140. }
  1141. #else
  1142. HLOCAL hlocal = NULL; // Buffer that gets the error message string
  1143. // Get the error code's textual description
  1144. BOOL fOk = FormatMessage(
  1145. FORMAT_MESSAGE_FROM_SYSTEM |
  1146. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  1147. FORMAT_MESSAGE_IGNORE_INSERTS,
  1148. NULL,
  1149. dwError,
  1150. MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
  1151. (PTSTR)&hlocal,
  1152. 0,
  1153. NULL);
  1154. if (!fOk)
  1155. {
  1156. // Is it a network-related error?
  1157. HMODULE hDll = LoadLibraryEx(TEXT("netmsg.dll"), NULL, DONT_RESOLVE_DLL_REFERENCES);
  1158. if (hDll != NULL)
  1159. {
  1160. FormatMessage(
  1161. FORMAT_MESSAGE_FROM_HMODULE |
  1162. FORMAT_MESSAGE_FROM_SYSTEM |
  1163. FORMAT_MESSAGE_IGNORE_INSERTS,
  1164. hDll,
  1165. dwError,
  1166. MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
  1167. (PTSTR)&hlocal,
  1168. 0,
  1169. NULL);
  1170. FreeLibrary(hDll);
  1171. }
  1172. }
  1173. if (hlocal != NULL)
  1174. {
  1175. CString strDisplay;
  1176. strDisplay.Format("%s 失败错误码=%d,Windows系统描述:%s", strDescription, dwError, (PCTSTR)LocalLock(hlocal));
  1177. WriteLogin(strDisplay);
  1178. LocalFree(hlocal);
  1179. }
  1180. else
  1181. {
  1182. WriteLogin("Error number not found.");
  1183. }
  1184. #endif
  1185. }
  1186. void MyGetIPByName(CString &name)
  1187. {
  1188. CString strIP = name;
  1189. name.Empty();
  1190. DWORD dwServerIP = 0;
  1191. HOSTENT *host = gethostbyname(strIP);
  1192. struct in_addr addr;
  1193. if (host != NULL)
  1194. {
  1195. for (int i = 0; host->h_addr_list[i] != NULL; i++)
  1196. {
  1197. memset(&addr, 0, sizeof(addr));
  1198. memcpy(&addr.S_un.S_addr, host->h_addr_list[i], host->h_length);
  1199. dwServerIP = ntohl(addr.S_un.S_addr);
  1200. }
  1201. BYTE* pIP = (BYTE*)&dwServerIP;
  1202. name.Format(_T("%d.%d.%d.%d"), pIP[3], pIP[2], pIP[1], pIP[0]);
  1203. }
  1204. }
  1205. void EncryptFile3(CString path)
  1206. {
  1207. CFile fp;
  1208. if (fp.Open(path, CFile::modeRead) == 0)return;
  1209. DWORD leng = fp.GetLength();
  1210. BYTE *pData = new BYTE[leng];
  1211. fp.Read(pData, leng);
  1212. fp.Close();
  1213. EncryptFile2(pData, leng, "z9871234abcd");
  1214. fp.Open(path, CFile::modeWrite);
  1215. fp.Write(pData, leng);
  1216. fp.Close();
  1217. delete[]pData;
  1218. }
  1219. int FindArray(CStringArray *pArray, CString Str)
  1220. {
  1221. for (int i = 0; i < pArray->GetSize(); i++)
  1222. {
  1223. if (pArray->ElementAt(i) == Str)
  1224. return i;
  1225. }
  1226. return -1;
  1227. }
  1228. BOOL isInnerIP(DWORD a_ip)
  1229. {
  1230. BOOL bValid = 0;
  1231. if ((a_ip >> 24 == 0xa) || (a_ip >> 16 == 0xc0a8) || (a_ip >> 22 == 0x2b0))
  1232. {
  1233. bValid = 1;
  1234. }
  1235. return bValid;
  1236. }
  1237. BOOL CompareIP(CString name1, CString name2)
  1238. {
  1239. CStringArray g_serverarray1;
  1240. CStringArray g_serverarray2;
  1241. CString strIP = name1;
  1242. DWORD dwServerIP = 0;
  1243. HOSTENT *host = gethostbyname(strIP);
  1244. struct in_addr addr;
  1245. if (host != NULL)
  1246. {
  1247. for (int i = 0; host->h_addr_list[i] != NULL; i++)
  1248. {
  1249. memset(&addr, 0, sizeof(addr));
  1250. memcpy(&addr.S_un.S_addr, host->h_addr_list[i], host->h_length);
  1251. dwServerIP = ntohl(addr.S_un.S_addr);
  1252. BYTE* pIP = (BYTE*)&dwServerIP;
  1253. strIP.Format(_T("%d.%d.%d.%d"), pIP[3], pIP[2], pIP[1], pIP[0]);
  1254. g_serverarray1.Add(strIP);
  1255. }
  1256. }
  1257. while (g_serverarray1.GetSize() > 1)
  1258. {
  1259. CString name;
  1260. BOOL bFind = 0;
  1261. for (int i = 0; i < g_serverarray1.GetSize(); i++)
  1262. {
  1263. DWORD dwServerIP = inet_addr(g_serverarray1.ElementAt(i));
  1264. dwServerIP = htonl(dwServerIP);//加了才正确
  1265. if (isInnerIP(dwServerIP) == 0)
  1266. {
  1267. g_serverarray1.RemoveAt(i);
  1268. bFind = 1;
  1269. break;
  1270. }
  1271. }
  1272. if (bFind == 0)
  1273. {
  1274. break;
  1275. }
  1276. }
  1277. //////////
  1278. {
  1279. CString strIP = name2;
  1280. DWORD dwServerIP = 0;
  1281. HOSTENT *host = gethostbyname(strIP);
  1282. struct in_addr addr;
  1283. if (host != NULL)
  1284. {
  1285. for (int i = 0; host->h_addr_list[i] != NULL; i++)
  1286. {
  1287. memset(&addr, 0, sizeof(addr));
  1288. memcpy(&addr.S_un.S_addr, host->h_addr_list[i], host->h_length);
  1289. dwServerIP = ntohl(addr.S_un.S_addr);
  1290. BYTE* pIP = (BYTE*)&dwServerIP;
  1291. strIP.Format(_T("%d.%d.%d.%d"), pIP[3], pIP[2], pIP[1], pIP[0]);
  1292. g_serverarray2.Add(strIP);
  1293. }
  1294. }
  1295. while (g_serverarray2.GetSize() > 1)
  1296. {
  1297. CString name;
  1298. BOOL bFind = 0;
  1299. for (int i = 0; i < g_serverarray2.GetSize(); i++)
  1300. {
  1301. DWORD dwServerIP = inet_addr(g_serverarray2.ElementAt(i));
  1302. dwServerIP = htonl(dwServerIP);//加了才正确
  1303. if (isInnerIP(dwServerIP) == 0)
  1304. {
  1305. g_serverarray2.RemoveAt(i);
  1306. bFind = 1;
  1307. break;
  1308. }
  1309. }
  1310. if (bFind == 0)
  1311. {
  1312. break;
  1313. }
  1314. }
  1315. }
  1316. if (g_serverarray1.GetSize() == 0 || g_serverarray2.GetSize() == 0)return 1;
  1317. for (int i = 0; i < g_serverarray1.GetSize(); i++)
  1318. {
  1319. for (int j = 0; j < g_serverarray2.GetSize(); j++)
  1320. {
  1321. if (g_serverarray1.ElementAt(i) == g_serverarray2.ElementAt(j))return 0;
  1322. }
  1323. }
  1324. return 1;
  1325. }
  1326. void DeleteDirectory(CString strDir)
  1327. {
  1328. if ( strDir.IsEmpty() || !PathFileExists(strDir) )
  1329. {
  1330. WriteLogin(_T("DeleteDirectory:路径无效!"));
  1331. return;
  1332. }
  1333. try
  1334. {
  1335. // 首先删除文件及子文件夹;
  1336. CFileFind ff;
  1337. BOOL bFound = ff.FindFile(strDir + _T("\\*"), 0);
  1338. while (bFound)
  1339. {
  1340. bFound = ff.FindNextFile();
  1341. if (ff.GetFileName() == _T(".") || ff.GetFileName() == _T(".."))
  1342. continue;
  1343. // 去掉文件(夹)只读等属性;
  1344. if ( SetFileAttributes(ff.GetFilePath(), FILE_ATTRIBUTE_NORMAL) )
  1345. {
  1346. if (ff.IsDirectory())
  1347. { // 递归删除子文件夹;
  1348. DeleteDirectory(ff.GetFilePath());
  1349. RemoveDirectory(ff.GetFilePath());
  1350. }
  1351. else
  1352. {
  1353. DeleteFile(ff.GetFilePath()); // Jeff:删除某文件夹下的所有子文件;
  1354. WriteLogin(ff.GetFilePath());
  1355. }
  1356. }
  1357. else
  1358. {
  1359. DWORD dwError = GetLastError();
  1360. CString strError = _T("");
  1361. strError.Format(_T("设置文件[%s]属性失败:%d"), ff.GetFilePath(), dwError);
  1362. }
  1363. }
  1364. ff.Close();
  1365. // 然后删除该文件夹;
  1366. RemoveDirectory(strDir);
  1367. }
  1368. catch (...)
  1369. {
  1370. WriteLogin(_T("出错在函数deldir中"));
  1371. }
  1372. }
  1373. int GetLengthEx(CString str)
  1374. {
  1375. wchar_t wstr[500];
  1376. int k = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, strlen(str), wstr, 500);
  1377. return k;
  1378. }
  1379. CString GetFileSize(CString path)
  1380. {
  1381. CString str = "0";
  1382. try
  1383. {
  1384. CFile fp;
  1385. fp.Open(path, CFile::modeRead);
  1386. str.Format("%d", fp.GetLength());
  1387. fp.Close();
  1388. }
  1389. catch (...)
  1390. {
  1391. }
  1392. return str;
  1393. }
  1394. void SortArray(CStringArray &datearray)
  1395. {
  1396. try
  1397. {
  1398. CString strtemp;
  1399. float ftemp;
  1400. int last = datearray.GetSize() - 1;
  1401. bool sorted = true;
  1402. do {
  1403. sorted = true;
  1404. for (int i = 0; i < last; i++)
  1405. {
  1406. if (datearray[i] < datearray[i + 1])
  1407. {
  1408. strtemp = datearray[i];
  1409. datearray[i] = datearray[i + 1];
  1410. datearray[i + 1] = strtemp;
  1411. sorted = false;
  1412. }
  1413. }
  1414. last--;
  1415. } while (!sorted);
  1416. }
  1417. catch (...)
  1418. {
  1419. WriteLogin("SortArray出错");
  1420. }
  1421. }
  1422. int CheckPhoneType(CString phoneno)//移动:0 联通:1 电信:2 小灵通:3 未知:-1
  1423. {
  1424. if (phoneno.IsEmpty())return -1;
  1425. int i = 0;
  1426. for (i = 0; i < phoneno.GetLength(); i++)
  1427. {
  1428. if (phoneno.GetAt(i) < '0' || phoneno.GetAt(i) > '9')return -1;
  1429. }
  1430. if (phoneno.GetAt(0) == '1')
  1431. {
  1432. if (phoneno.GetLength() != 11)
  1433. return -1;
  1434. int mobile[] = { 139, 138, 137, 136, 135, 134, 159, 158, 152, 151, 150, 157, 188, 187, 144, 182, 147, 183, 184 };
  1435. int unicom[] = { 130, 131, 132, 155, 156, 186, 185 };
  1436. int telecom[] = { 133, 153, 189, 180, 181 };
  1437. for (i = 0; i < sizeof(mobile) / sizeof(int); i++)
  1438. {
  1439. if (mobile[i] == atoi(phoneno.Left(3)))
  1440. {
  1441. return 0;
  1442. }
  1443. }
  1444. for (i = 0; i < sizeof(unicom) / sizeof(int); i++)
  1445. {
  1446. if (unicom[i] == atoi(phoneno.Left(3)))
  1447. {
  1448. return 1;
  1449. }
  1450. }
  1451. for (i = 0; i < sizeof(telecom) / sizeof(int); i++)
  1452. {
  1453. if (telecom[i] == atoi(phoneno.Left(3)))
  1454. {
  1455. return 2;
  1456. }
  1457. }
  1458. return -1;
  1459. }
  1460. /* else if(phoneno.GetAt (0)=='0')
  1461. {
  1462. if(phoneno.GetLength ()>=10 && phoneno.GetLength ()<=12)
  1463. {
  1464. return 3;
  1465. }
  1466. }*/
  1467. return -1;
  1468. }
  1469. CTime GetTmFromStr(CString date)
  1470. {
  1471. try
  1472. {
  1473. CTime tm(atoi(date.Mid(0, 4)), atoi(date.Mid(5, 2)), atoi(date.Mid(8, 2)), 0, 0, 0);
  1474. CString ss;
  1475. ss.Format("%d-%d-%d", tm.GetYear(), tm.GetMonth(), tm.GetDay());
  1476. return tm;
  1477. }
  1478. catch (...)
  1479. {
  1480. date = "1980-01-01";
  1481. CTime tm(atoi(date.Mid(0, 4)), atoi(date.Mid(5, 2)), atoi(date.Mid(8, 2)), 0, 0, 0);
  1482. return tm;
  1483. }
  1484. }
  1485. void ConvertToPrice(CString &str)
  1486. {
  1487. if (str.Find('.') == -1)return;
  1488. str.TrimRight('0');
  1489. str.TrimRight('.');
  1490. }
  1491. void SortArray(CArray<CStringArray, CStringArray>*List1array, int pos)
  1492. {
  1493. CString stemp;
  1494. int last = List1array->GetSize() - 1;
  1495. int ret = last;
  1496. bool sorted = true;
  1497. do
  1498. {
  1499. sorted = true;
  1500. for (int i = 0; i < last; i++)
  1501. {
  1502. if (List1array->ElementAt(i).ElementAt(pos) < List1array->ElementAt(i + 1).ElementAt(pos))
  1503. {
  1504. for (int a = 0; a < List1array->ElementAt(i).GetSize(); a++)
  1505. {
  1506. stemp = List1array->ElementAt(i).ElementAt(a);
  1507. List1array->ElementAt(i).SetAt(a, List1array->ElementAt(i + 1).ElementAt(a));
  1508. List1array->ElementAt(i + 1).SetAt(a, stemp);
  1509. }
  1510. sorted = false;
  1511. }
  1512. }
  1513. last--;
  1514. } while (!sorted);
  1515. }
  1516. void DeCodePicCount(int &value1, int &value2)
  1517. {
  1518. // SoftKey ytSoftKey;
  1519. int ret = 0;//ytSoftKey.Ini();
  1520. if (ret != 0)
  1521. {
  1522. return;
  1523. }
  1524. int d[8]; double f[8];
  1525. TCHAR s0[50] = _T(""), s1[50] = _T(""), s2[50] = _T(""), s3[50] = _T(""), s4[50] = _T(""), s5[50] = _T(""), s6[50] = _T(""), s7[50] = _T("");
  1526. //运行自定义函数
  1527. ret = ytSoftKey.decryptpiccount(&value1, &value2, &d[2], &d[3], &d[4], &d[5], &d[6], &d[7],
  1528. &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
  1529. s0, s1, s2, s3, s4, s5, s6, s7);
  1530. if (ret != 0 && ret != -43)
  1531. {
  1532. exit(0);
  1533. }
  1534. }
  1535. void DeCodelong1(int &value1, int &value2, int &value3, int &value4, int &value5, int &value6, int &value7, int &value8)
  1536. {
  1537. // SoftKey ytSoftKey;
  1538. int ret = 0;//ytSoftKey.Ini();
  1539. if (ret != 0)
  1540. {
  1541. return;
  1542. }
  1543. double f[8];
  1544. TCHAR s0[50] = _T(""), s1[50] = _T(""), s2[50] = _T(""), s3[50] = _T(""), s4[50] = _T(""), s5[50] = _T(""), s6[50] = _T(""), s7[50] = _T("");
  1545. //运行自定义函数
  1546. ret = ytSoftKey.decryptlong1(&value1, &value2, &value3, &value4, &value5, &value6, &value7, &value8,
  1547. &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
  1548. s0, s1, s2, s3, s4, s5, s6, s7);
  1549. if (ret != 0 && ret != -43)
  1550. {
  1551. exit(0);
  1552. }
  1553. }
  1554. void DeCodelong2(int &value1, int &value2, int &value3, int &value4, int &value5, int &value6, int &value7, int &value8)
  1555. {
  1556. // SoftKey ytSoftKey;
  1557. int ret = 0;//ytSoftKey.Ini();
  1558. if (ret != 0)
  1559. {
  1560. return;
  1561. }
  1562. double f[8];
  1563. TCHAR s0[50] = _T(""), s1[50] = _T(""), s2[50] = _T(""), s3[50] = _T(""), s4[50] = _T(""), s5[50] = _T(""), s6[50] = _T(""), s7[50] = _T("");
  1564. //运行自定义函数
  1565. ret = ytSoftKey.decryptlong2(&value1, &value2, &value3, &value4, &value5, &value6, &value7, &value8,
  1566. &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
  1567. s0, s1, s2, s3, s4, s5, s6, s7);
  1568. if (ret != 0 && ret != -43)
  1569. {
  1570. exit(0);
  1571. }
  1572. }
  1573. void DeCodelong3(int &value1, int &value2, int &value3, int &value4, int &value5, int &value6, int &value7, int &value8)
  1574. {
  1575. // SoftKey ytSoftKey;
  1576. int ret = 0;//ytSoftKey.Ini();
  1577. if (ret != 0)
  1578. {
  1579. return;
  1580. }
  1581. double f[8];
  1582. TCHAR s0[50] = _T(""), s1[50] = _T(""), s2[50] = _T(""), s3[50] = _T(""), s4[50] = _T(""), s5[50] = _T(""), s6[50] = _T(""), s7[50] = _T("");
  1583. //运行自定义函数
  1584. ret = ytSoftKey.decryptlong3(&value1, &value2, &value3, &value4, &value5, &value6, &value7, &value8,
  1585. &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
  1586. s0, s1, s2, s3, s4, s5, s6, s7);
  1587. if (ret != 0 && ret != -43)
  1588. {
  1589. exit(0);
  1590. }
  1591. }
  1592. void DeCodelong4(int &value1, int &value2, int &value3, int &value4, int &value5, int &value6, int &value7, int &value8)
  1593. {
  1594. // SoftKey ytSoftKey;
  1595. int ret = 0;//ytSoftKey.Ini();
  1596. if (ret != 0)
  1597. {
  1598. exit(0);
  1599. }
  1600. double f[8];
  1601. TCHAR s0[50] = _T(""), s1[50] = _T(""), s2[50] = _T(""), s3[50] = _T(""), s4[50] = _T(""), s5[50] = _T(""), s6[50] = _T(""), s7[50] = _T("");
  1602. //运行自定义函数
  1603. ret = ytSoftKey.decryptlong4(&value1, &value2, &value3, &value4, &value5, &value6, &value7, &value8,
  1604. &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7],
  1605. s0, s1, s2, s3, s4, s5, s6, s7);
  1606. if (ret != 0 && ret != -43)
  1607. {
  1608. exit(0);
  1609. }
  1610. }
  1611. #endif
  1612. #if JEFF_TEST_ON
  1613. /************************************************************************/
  1614. /*
  1615. 函数:IsValidDate
  1616. 描述:判断输入的公历日期是否有效;
  1617. 参数:
  1618. IN: lpDate 要判断的日期字符串;
  1619. 返回:日期有效返回TRUE,否则返回FALSE;
  1620. 要求:
  1621. 注意:
  1622. 示例:
  1623. */
  1624. /************************************************************************/
  1625. BOOL IsValidDate(IN LPCTSTR lpDate)
  1626. {
  1627. if (lpDate == NULL || _tcscmp(lpDate, _T("")) == 0)
  1628. return FALSE;
  1629. CString strDate = lpDate;
  1630. if (strDate.IsEmpty()) return FALSE;
  1631. // 判断日期合法性;
  1632. static int nYear = 0;
  1633. static int nMonth = 0;
  1634. static int nDay = 0;
  1635. nYear = nMonth = nDay = 0;
  1636. nYear = _ttoi(strDate.Left(4));
  1637. nMonth = _ttoi(strDate.Mid(5, 2));
  1638. nDay = _ttoi(strDate.Mid(8, 2));
  1639. CONST static INT nNormalMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  1640. CONST static INT nLeapMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  1641. if ((nDay <= 0) || (nDay > 31) || (nMonth <= 0) || (nMonth > 12)) return FALSE;
  1642. if ((nYear % 400 == 0) || (nYear % 4 == 0 && nYear % 100 != 0))
  1643. {
  1644. if (nDay > nLeapMonth[nMonth - 1]) return FALSE;
  1645. }
  1646. else
  1647. {
  1648. if (nDay > nNormalMonth[nMonth - 1]) return FALSE;
  1649. }
  1650. return TRUE;
  1651. }
  1652. #endif
  1653. /************************************************************************/
  1654. /*
  1655. 函数:LoadBackupModuleDll
  1656. 描述:加载备份模块
  1657. 参数:
  1658. IN CONST CString strDll 文件全路径
  1659. 返回:1成功,0失败
  1660. */
  1661. /************************************************************************/
  1662. int LoadBackupModuleDll(IN CONST CString strDll)
  1663. {
  1664. if (!::PathFileExists(strDll))
  1665. return 0;
  1666. HRESULT hr = NULL;
  1667. if(g_hDllInst)
  1668. return 1;
  1669. if(g_hDllInst == NULL)
  1670. {
  1671. g_hDllInst = LoadLibrary(strDll);
  1672. if(g_hDllInst == NULL)
  1673. {
  1674. WriteLogin(_T("加载") + strDll + _T("失败\n"));
  1675. return 0;
  1676. }
  1677. }
  1678. WriteLogin(_T("加载") + strDll + _T("成功\n"));
  1679. return 1;
  1680. }
  1681. /************************************************************************/
  1682. /*
  1683. 函数:FreeBackupModuleDll
  1684. 描述:卸载备份模块
  1685. 参数:
  1686. 返回:
  1687. */
  1688. /************************************************************************/
  1689. void FreeBackupModuleDll()
  1690. {
  1691. if(g_hDllInst != NULL)
  1692. FreeLibrary(g_hDllInst);
  1693. g_hDllInst = NULL;
  1694. }
  1695. static INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData)
  1696. {
  1697. switch (uMsg)
  1698. {
  1699. case BFFM_INITIALIZED:
  1700. SendMessage(hwnd, BFFM_SETSELECTION, TRUE, NULL);
  1701. break;
  1702. case BFFM_SELCHANGED:
  1703. {
  1704. TCHAR szFileName[MAX_PATH];
  1705. LPITEMIDLIST pidlCurrent = (LPITEMIDLIST)lp;
  1706. SHGetPathFromIDList(pidlCurrent, szFileName);
  1707. SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szFileName);
  1708. }
  1709. break;
  1710. // 这个不能让默认目录为桌面;
  1711. // case BFFM_INITIALIZED:
  1712. // {
  1713. // // WParam is TRUE since you are passing a path.
  1714. // // It would be FALSE if you were passing a pidl.
  1715. // TCHAR szDir[MAX_PATH] = { 0 };
  1716. // GetCurrentDirectory(sizeof(szDir) / sizeof(TCHAR), szDir);
  1717. // SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)szDir);
  1718. // }
  1719. // break;
  1720. }
  1721. return 0;
  1722. }
  1723. BOOL GetFilePath(OUT TCHAR *FilePath, IN HWND hParentWnd, IN TCHAR* InstructionString, IN UINT ulFlags)
  1724. {
  1725. BROWSEINFO bInfo;
  1726. LPITEMIDLIST pidl, pidlDesktop;
  1727. ZeroMemory((PVOID)&bInfo, sizeof(BROWSEINFO));
  1728. HRESULT hr = SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidlDesktop);
  1729. if ( hr != S_OK )
  1730. {
  1731. //WriteClientLog(_T("获取打开目录路径失败"));
  1732. return FALSE;
  1733. }
  1734. bInfo.pidlRoot = pidlDesktop;
  1735. bInfo.hwndOwner = hParentWnd;
  1736. bInfo.pszDisplayName = FilePath;
  1737. bInfo.lpszTitle = InstructionString;
  1738. bInfo.ulFlags = ulFlags;
  1739. bInfo.lpfn = BrowseCallbackProc;
  1740. bInfo.lParam = 0;
  1741. if ((pidl = ::SHBrowseForFolder(&bInfo)) == NULL)
  1742. {
  1743. //WriteClientLog(_T("获取打开目录路径失败1"));
  1744. return FALSE;
  1745. }
  1746. if (::SHGetPathFromIDList(pidl, FilePath) == FALSE)
  1747. {
  1748. //WriteClientLog(_T("获取打开目录路径失败2"));
  1749. return FALSE;
  1750. }
  1751. return TRUE;
  1752. }
  1753. TCHAR* GetGuidString()
  1754. {
  1755. GUID guid;
  1756. static TCHAR szBuf[64] = {0};
  1757. memset(szBuf, 0, 64*sizeof(TCHAR));
  1758. CoInitialize(NULL);
  1759. if (S_OK == ::CoCreateGuid(&guid))
  1760. {
  1761. sprintf(szBuf, _T("{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}"),
  1762. guid.Data1,
  1763. guid.Data2,
  1764. guid.Data3,
  1765. guid.Data4[0],
  1766. guid.Data4[1],
  1767. guid.Data4[2],
  1768. guid.Data4[3],
  1769. guid.Data4[4],
  1770. guid.Data4[5],
  1771. guid.Data4[6],
  1772. guid.Data4[7]
  1773. );
  1774. }
  1775. CoUninitialize();
  1776. return szBuf;
  1777. }
  1778. DWORD GetSoftRunTime()
  1779. {
  1780. DWORD id;
  1781. TCHAR HKey[50] = "ffffffff",LKey[50]="ffffffff";
  1782. TCHAR OutTime[50];
  1783. TCHAR DevicePath[ 260];
  1784. if(FindPort(0,DevicePath)!=0)
  1785. return 0;
  1786. //LIBC.LIB,libcp.lib,msvcprt.lib
  1787. TCHAR year[10],month[10],day[10],hour[10],minute[10],second[10];
  1788. ReadTimeAuthFromEprom(HKey,LKey, OutTime, &id, 30128, HKey, LKey, DevicePath);
  1789. CString str=OutTime;
  1790. CString temp="年";
  1791. int pos=str.Find (temp);
  1792. temp=str.Left (pos);
  1793. str=str.Right (str.GetLength ()-pos-2);
  1794. strcpy(year, temp.GetBuffer (0));temp.ReleaseBuffer ();
  1795. temp="月";
  1796. pos=str.Find (temp);
  1797. temp=str.Left (pos);
  1798. str=str.Right (str.GetLength ()-pos-2);
  1799. strcpy(month, temp.GetBuffer (0));temp.ReleaseBuffer ();
  1800. temp="日";
  1801. pos=str.Find (temp);
  1802. temp=str.Left (pos);
  1803. str=str.Right (str.GetLength ()-pos-2);
  1804. strcpy(day, temp.GetBuffer (0));temp.ReleaseBuffer ();
  1805. temp="小时";
  1806. pos=str.Find (temp);
  1807. temp=str.Left (pos);
  1808. str=str.Right (str.GetLength ()-pos-4);
  1809. strcpy(hour, temp.GetBuffer (0));temp.ReleaseBuffer ();
  1810. temp="分钟";
  1811. pos=str.Find (temp);
  1812. temp=str.Left (pos);
  1813. str=str.Right (str.GetLength ()-pos-4);
  1814. strcpy(minute, temp.GetBuffer (0));temp.ReleaseBuffer ();
  1815. temp="0";
  1816. strcpy(second, temp.GetBuffer (0));temp.ReleaseBuffer ();
  1817. long time1=ConvertStringToTimerReal(year, month, day, hour, minute, second);
  1818. GetRunTimer(year, month, day, hour, minute, second, DevicePath);
  1819. long time2=ConvertStringToTimerReal(year, month, day, hour, minute, second);
  1820. // 软件可运行时间;
  1821. return time1 - time2;
  1822. }