StdAfx.cpp 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833
  1. // stdafx.cpp : source file that includes just the standard includes
  2. // DataManager.pch will be the pre-compiled header
  3. // stdafx.obj will contain the pre-compiled type information
  4. #include <math.h>
  5. #include "stdafx.h"
  6. #include "EventRaiseActionMgr.h"
  7. int g_nPrecision = 4;
  8. __declspec(dllexport) bool Encrypt(const char szFileOrig[], const char szFileNew[], const char szPwd[])
  9. {
  10. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  11. int nLenPwd = strlen(szPwd);
  12. char *pPwdHere = new char[nLenPwd+1];
  13. strcpy(pPwdHere, szPwd);
  14. for(int i = 0; i < nLenPwd; i++)
  15. pPwdHere[i] ^= 19760807;
  16. char s[] = "工程名";
  17. CFile fileR;
  18. CFile fileW;
  19. if(fileR.Open(szFileOrig, CFile::typeBinary|CFile::modeRead))
  20. {
  21. if(fileW.Open(szFileNew, CFile::typeBinary|CFile::modeCreate|CFile::modeWrite))
  22. {
  23. char c;
  24. i = 0;
  25. while (fileR.Read(&c, 1) == 1)
  26. {
  27. c = c^ pPwdHere[i++];
  28. if(i >= nLenPwd)
  29. i = 0;
  30. fileW.Write(&c, 1);
  31. }
  32. fileW.Close();
  33. }
  34. fileR.Close();
  35. }
  36. delete []pPwdHere;
  37. return false;
  38. }
  39. __declspec(dllexport) CString GetText(UINT uData)
  40. {
  41. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  42. CString strTemp;
  43. strTemp.Format("%u", uData);
  44. return strTemp;
  45. }
  46. //由数据精度获得浮点数的字符串值
  47. __declspec(dllexport) CString GetDoubleText(double d)
  48. {
  49. CString strRtn;
  50. CString strFmt;
  51. if(g_nPrecision == 0)
  52. strFmt = "%g";
  53. else
  54. {
  55. long lV = (long)fabs(d);
  56. if(lV >= 1)
  57. {
  58. int nIntBit = 0;
  59. while(lV >= 1)
  60. {
  61. lV = lV/10;
  62. nIntBit++;
  63. }
  64. if(nIntBit < g_nPrecision)
  65. strFmt.Format("%c%d.%df", '%', nIntBit, (g_nPrecision-nIntBit));
  66. else
  67. strFmt.Format("%c%d.0f", '%', nIntBit);
  68. }
  69. else
  70. {
  71. double dTemp = fabs(d);
  72. if(dTemp > 0.00000000001)
  73. {
  74. int nDot0Bit = 0;
  75. while(dTemp < 0.1)
  76. {
  77. dTemp = dTemp*10;
  78. nDot0Bit++;
  79. }
  80. strFmt.Format("%c1.%df", '%', nDot0Bit + g_nPrecision);
  81. }
  82. else
  83. {
  84. strFmt = "%g";
  85. }
  86. }
  87. }
  88. strRtn.Format(strFmt, d);
  89. return strRtn;
  90. }
  91. __declspec(dllexport) BOOL MyCopyFiles(CString strSource, CString strDest)
  92. {
  93. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  94. BOOL bOK = FALSE;
  95. if(MyCreateDirectory(strDest))
  96. {
  97. bOK = TRUE;
  98. CFileFind fileFind;
  99. BOOL bFound = fileFind.FindFile(strSource + "\\*.*");
  100. while (bFound)
  101. {
  102. bFound = fileFind.FindNextFile();
  103. if(fileFind.IsDots())
  104. continue;
  105. else if(fileFind.IsDirectory())
  106. {
  107. if(!MyCopyFiles(fileFind.GetFilePath(), strDest + "\\" + fileFind.GetFileName()))
  108. bOK = FALSE;
  109. }
  110. else
  111. {
  112. if(!CopyFile(fileFind.GetFilePath(), strDest + "\\" + fileFind.GetFileName(), FALSE))
  113. bOK = FALSE;
  114. }
  115. };
  116. fileFind.Close();
  117. }
  118. return bOK;
  119. }
  120. __declspec(dllexport) BOOL MyCreateDirectory(CString strPath)
  121. {
  122. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  123. strPath += "\\";
  124. BOOL bCreateOK = FALSE;
  125. if(strPath.GetLength() > 4)
  126. {
  127. bCreateOK = TRUE;
  128. CString strTemp =strPath.Mid(1);
  129. while(strTemp.Replace("\\\\", "\\") > 0)
  130. {
  131. //do nothing else
  132. }
  133. strTemp = strPath.Left(1) + strTemp;
  134. if(strTemp.Find("\\\\") == -1 && strTemp.Find(":\\") != 1)
  135. {// 既不是网络路径也不是从盘符开始的磁盘路径视为无效.
  136. bCreateOK = FALSE;
  137. }
  138. else
  139. {
  140. int nPos = 3;
  141. if(strTemp.Find("\\\\") == 0)
  142. {
  143. nPos = strTemp.Find("\\", nPos);
  144. if(nPos != -1)
  145. {
  146. nPos = strTemp.Find("\\", nPos+1);
  147. if(nPos != -1)
  148. {
  149. nPos = strTemp.Find("\\", nPos+1);
  150. }
  151. }
  152. }
  153. nPos = strTemp.Find('\\', nPos);
  154. while(nPos > -1)
  155. {
  156. CString strPathRout = strTemp.Left(nPos);
  157. CFileFind fileFind;
  158. if(!fileFind.FindFile(strPathRout))
  159. {
  160. if(!CreateDirectory(strPathRout, NULL))
  161. {
  162. bCreateOK = FALSE;
  163. break;
  164. }
  165. }
  166. fileFind.Close();
  167. nPos = strTemp.Find('\\', nPos + 1);
  168. }
  169. }
  170. }
  171. return bCreateOK;
  172. }
  173. __declspec(dllexport) BOOL MyDeleteDirectory(CString strPath)//删除任意深度的路径
  174. {
  175. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  176. BOOL bOK = TRUE;
  177. CFileFind fileFind;
  178. BOOL bFound = fileFind.FindFile(strPath + "\\*.*");
  179. while (bFound)
  180. {
  181. bFound = fileFind.FindNextFile();
  182. if(fileFind.IsDots())
  183. continue;
  184. else if(fileFind.IsDirectory())
  185. {
  186. if(!MyDeleteDirectory(fileFind.GetFilePath()))
  187. bOK = FALSE;
  188. }
  189. else
  190. {
  191. if(!DeleteFile(fileFind.GetFilePath()))
  192. {
  193. CFileStatus rStatus;
  194. CFile::GetStatus(fileFind.GetFilePath(), rStatus);
  195. rStatus.m_attribute = CFile::normal;
  196. CFile::SetStatus(fileFind.GetFilePath(), rStatus);
  197. if(!DeleteFile(fileFind.GetFilePath()))
  198. bOK = FALSE;
  199. }
  200. }
  201. }
  202. fileFind.Close();
  203. RemoveDirectory(strPath);
  204. return bOK;
  205. }
  206. __declspec(dllexport) CString GetAppPath()
  207. {
  208. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  209. #ifndef DEMO_VERSION
  210. char szPath[300] = {0};
  211. LoadSting(szPath);
  212. return szPath;
  213. #else
  214. static CString strAppPath;
  215. if(strAppPath.IsEmpty())
  216. {
  217. char szuf[256];
  218. GetModuleFileName(NULL, szuf, 255);
  219. strAppPath = szuf;
  220. int nPos = strAppPath.ReverseFind('\\');
  221. if(nPos > -1)
  222. strAppPath = strAppPath.Left(nPos);
  223. }
  224. return strAppPath;
  225. #endif
  226. }
  227. static CString g_strPrjPath;
  228. __declspec(dllexport) CString SetPrjPath(CString strPrjPath)//设置工程的路径
  229. {
  230. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  231. CString strRtn = g_strPrjPath;
  232. g_strPrjPath = strPrjPath;
  233. theApp.m_bLoadedByMainProg = TRUE;
  234. return strRtn;
  235. }
  236. __declspec(dllexport) CString GetPrjPath()//获取工程的路径
  237. {
  238. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  239. if(g_strPrjPath == "")
  240. return GetAppPath();
  241. return g_strPrjPath;
  242. }
  243. static CDataNodeBase* g_pRoot = NULL;
  244. __declspec(dllexport) void SetPrjRoot(CDataNodeBase* pRoot)//设置工程的根节点,由主程序设置
  245. {
  246. g_pRoot = pRoot;
  247. }
  248. __declspec(dllexport) CDataNodeBase* GetPrjRoot()//获取工程的根节点
  249. {
  250. return g_pRoot;
  251. }
  252. //获取动态库的所在路径
  253. __declspec(dllexport) CString GetDllPath()
  254. {
  255. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  256. CString strAppPath;
  257. char szuf[256];
  258. GetModuleFileName(AfxGetInstanceHandle(), szuf, 255);
  259. strAppPath = szuf;
  260. int nPos = strAppPath.ReverseFind('\\');
  261. if(nPos > -1)
  262. strAppPath = strAppPath.Left(nPos);
  263. return strAppPath;
  264. }
  265. __declspec(dllexport) void FreeObList(CObList &obList)//清除obList内的对象
  266. {
  267. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  268. while(obList.GetCount() > 0)
  269. delete obList.RemoveHead();
  270. }
  271. __declspec(dllexport) CString EncodeString(CString strOld, BYTE cKey)//字符串加密
  272. {
  273. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  274. cKey = min(30, cKey);//异或操作后保证还是字符串,则键值必须小于30,以便不影响高位的值
  275. CString strRtn = strOld;
  276. int nLen = strOld.GetLength();
  277. for(int i = 0; i < nLen; i++)
  278. {
  279. strRtn.SetAt(nLen-1-i, strOld.GetAt(i)^cKey);
  280. }
  281. return strRtn;
  282. }
  283. __declspec(dllexport) BYTE TwoByteToByte(BYTE b1, BYTE b2)//两个字符转换为一个字符
  284. {
  285. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  286. BYTE b = 0;
  287. if(b1 >= 'A' && b1 <= 'F')
  288. b += (b1 - 'A' + 10)*16;
  289. else if(b1 >= 'a' && b1 <= 'f')
  290. b += (b1 - 'a' + 10)*16;
  291. else
  292. b += (b1 - '0')*16;
  293. if(b2 >= 'A' && b2 <= 'F')
  294. b += b2 - 'A' + 10;
  295. else if(b2 >= 'a' && b2 <= 'f')
  296. b += b2 - 'a' + 10;
  297. else
  298. b += b2 - '0';
  299. return b;
  300. }
  301. __declspec(dllexport) void ByteToTwoByte(BYTE b, BYTE b2[])//一个字符转换为两个字符
  302. {
  303. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  304. char szBuf[3];
  305. int nData = b;
  306. sprintf(szBuf, "%02X", nData);
  307. memcpy(b2, szBuf, 2);
  308. }
  309. #define CPH 0
  310. #define CPL 1
  311. static unsigned char tbcrch[] = {
  312. 0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,
  313. 1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65,
  314. 1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65,
  315. 0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,
  316. 1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65,
  317. 0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,
  318. 0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,
  319. 1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65,
  320. 1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65,
  321. 0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,
  322. 0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,
  323. 1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65,
  324. 0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,
  325. 1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65,
  326. 1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65,
  327. 0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,};
  328. static unsigned char tbcrcl[] = {
  329. 0,192,193,1,195,3,2,194,198,6,7,199,5,197,196,4,
  330. 204,12,13,205,15,207,206,14,10,202,203,11,201,9,8,200,
  331. 216,24,25,217,27,219,218,26,30,222,223,31,221,29,28,220,
  332. 20,212,213,21,215,23,22,214,210,18,19,211,17,209,208,16,
  333. 240,48,49,241,51,243,242,50,54,246,247,55,245,53,52,244,
  334. 60,252,253,61,255,63,62,254,250,58,59,251,57,249,248,56,
  335. 40,232,233,41,235,43,42,234,238,46,47,239,45,237,236,44,
  336. 228,36,37,229,39,231,230,38,34,226,227,35,225,33,32,224,
  337. 160,96,97,161,99,163,162,98,102,166,167,103,165,101,100,164,
  338. 108,172,173,109,175,111,110,174,170,106,107,171,105,169,168,104,
  339. 120,184,185,121,187,123,122,186,190,126,127,191,125,189,188,124,
  340. 180,116,117,181,119,183,182,118,114,178,179,115,177,113,112,176,
  341. 80,144,145,81,147,83,82,146,150,86,87,151,85,149,148,84,
  342. 156,92,93,157,95,159,158,94,90,154,155,91,153,89,88,152,
  343. 136,72,73,137,75,139,138,74,78,142,143,79,141,77,76,140,
  344. 68,132,133,69,135,71,70,134,130,66,67,131,65,129,128,64,};
  345. /********************************************************************
  346. * NAME : TwoHexCharToChar
  347. * FUNCTION :
  348. * PROCESS :
  349. * INPUT :
  350. * OUTPUT :
  351. * UPDATE :
  352. * RETURN :
  353. * :
  354. * PROGRAMMED :
  355. * DATE(ORG) :
  356. * CALL :
  357. * SYSTEM :
  358. ********************************************************************/
  359. __declspec(dllexport) char TwoHexCharToChar(char ch1,char ch2)
  360. {
  361. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  362. char Numb1;
  363. char Numb2;
  364. if (ch1 >= 'A')
  365. {
  366. Numb1 = (toupper(ch1)-'0'-7)*16;
  367. }
  368. else
  369. {
  370. Numb1 = (ch1 - '0')*16;
  371. }
  372. if (ch2 >= 'A')
  373. {
  374. Numb2 = (toupper(ch2) - '0' - 7);
  375. }
  376. else
  377. {
  378. Numb2 = (ch2 - '0');
  379. }
  380. return (Numb1 + Numb2);
  381. }
  382. /********************************************************************
  383. * NAME : Str2HexStr
  384. * FUNCTION :
  385. * PROCESS :
  386. * INPUT :
  387. * OUTPUT :
  388. * UPDATE :
  389. * RETURN :
  390. * :
  391. * PROGRAMMED :
  392. * DATE(ORG) :
  393. * CALL :
  394. * SYSTEM :
  395. ********************************************************************/
  396. __declspec(dllexport) void Str2HexStr(char *szHexString,char *szString,int *iHexStringLen)
  397. {
  398. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  399. int iLoop;
  400. int iCount;
  401. iLoop = 0;
  402. iCount = 0;
  403. szHexString[0] = '\0';
  404. while(1)
  405. {
  406. if (szString[iLoop] == '\0' || szString[iLoop + 1] == '\0')
  407. {
  408. break;
  409. }
  410. szHexString[iCount] = (char)TwoHexCharToChar(szString[iLoop ],
  411. szString[iLoop + 1]);
  412. iLoop ++;
  413. iLoop ++;
  414. iCount ++;
  415. }
  416. szHexString[iCount] = '\0';
  417. *iHexStringLen = iCount;
  418. }
  419. /********************************************************************
  420. * NAME : GetCRC
  421. * FUNCTION :
  422. * PROCESS :
  423. * INPUT :
  424. * OUTPUT :
  425. * UPDATE :
  426. * RETURN :
  427. * :
  428. * PROGRAMMED :
  429. * DATE(ORG) :
  430. * CALL :
  431. * SYSTEM :
  432. ********************************************************************/
  433. __declspec(dllexport) void GetCRC(char *CRC_char1,char *CRC_char2,char *szString,int iStrLen)
  434. {
  435. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  436. WORD i;
  437. WORD j;
  438. union
  439. {
  440. WORD ival;
  441. unsigned char cval[2];
  442. } crcal;
  443. crcal.ival = 0xFFFF;
  444. i = 0;
  445. while ( i < iStrLen)
  446. {
  447. j = (WORD)((szString[i] ^ crcal.cval[CPH]) & 0x00FF);
  448. crcal.cval[CPH] = tbcrch[j] ^ crcal.cval[CPL];
  449. crcal.cval[CPL] = tbcrcl[j];
  450. i ++;
  451. }
  452. *CRC_char1 = crcal.cval[CPH];
  453. *CRC_char2 = crcal.cval[CPL];
  454. }
  455. /********************************************************************
  456. * NAME : AddCRC
  457. * FUNCTION :
  458. * PROCESS :
  459. * INPUT :
  460. * OUTPUT :
  461. * UPDATE :
  462. * RETURN :
  463. * :
  464. * PROGRAMMED :
  465. * DATE(ORG) :
  466. * CALL :
  467. * SYSTEM :
  468. ********************************************************************/
  469. __declspec(dllexport) void AddCRC(char *szBuffer,
  470. int iLen) /* the szBuffer length, this means the
  471. szBuffer[iLen] is error data,
  472. perhaps szBuffer[iLen-1] != 0;
  473. also perhaps szBuffer[iLen] != 0; */
  474. {
  475. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  476. char crc_ch1;
  477. char crc_ch2;
  478. GetCRC(&crc_ch1,&crc_ch2,szBuffer,iLen);
  479. szBuffer[iLen] = crc_ch1;
  480. szBuffer[iLen + 1] = crc_ch2;
  481. }
  482. /********************************************************************
  483. * NAME : CheckCRC
  484. * FUNCTION :
  485. * PROCESS :
  486. * INPUT :
  487. * OUTPUT :
  488. * UPDATE :
  489. * RETURN :
  490. * :
  491. * PROGRAMMED :
  492. * DATE(ORG) :
  493. * CALL :
  494. * SYSTEM :
  495. ********************************************************************/
  496. __declspec(dllexport) BOOL CheckCRC (char *szString,int iStrLen)
  497. {
  498. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  499. char crc_ch1;
  500. char crc_ch2;
  501. GetCRC(&crc_ch1,&crc_ch2,szString,iStrLen-2);
  502. if (szString[iStrLen - 2] != crc_ch1)
  503. {
  504. return FALSE;
  505. }
  506. if (szString[iStrLen - 1] != crc_ch2)
  507. {
  508. return FALSE;
  509. }
  510. return TRUE;
  511. }
  512. __declspec(dllexport) int StrToInt(CString strTxt)
  513. {
  514. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  515. int nRtn = 0;
  516. if(strTxt.Find('H') != -1)
  517. {
  518. strTxt.Replace("0X", "");
  519. strTxt.Replace("0x", "");
  520. int nLenStr = strTxt.GetLength();
  521. for(int i = 0; i < nLenStr-1; i+=2)
  522. {
  523. nRtn = nRtn*256+ TwoByteToByte(strTxt.GetAt(i), strTxt.GetAt(i+1));
  524. }
  525. }
  526. else
  527. nRtn = atoi(strTxt);
  528. return nRtn;
  529. }
  530. inline void RemoveOldData()
  531. {
  532. COleDateTime timeNow = COleDateTime::GetCurrentTime();
  533. static int nLastCheckMonth = timeNow.GetMonth();
  534. if(timeNow.GetMonth() != nLastCheckMonth)
  535. {
  536. nLastCheckMonth = timeNow.GetMonth();
  537. COleDateTime timeTwoYearAgo = timeNow - COleDateTimeSpan(365*2, 0, 0, 0);
  538. CString strDir = GetPrjPath() + "\\Curve\\" + timeTwoYearAgo.Format("%Y%m");
  539. MyDeleteDirectory(strDir);
  540. strDir = GetPrjPath() + "\\Curve\\HourCur" + timeTwoYearAgo.Format("%Y");
  541. MyDeleteDirectory(strDir);
  542. }
  543. }
  544. inline void SaveCurve(CDataNodeBase* pSpot, CString strTxtValue, BOOL bStatusChanged)
  545. {
  546. #define CurLastValue "CLV"
  547. #define CurLastTime "CLT"
  548. #define CurLastDay "CLD"
  549. #define CurLastHour "CLH"
  550. #define INIT_VALUE 0.00020041005f
  551. RemoveOldData();
  552. CString strRecCurve;
  553. if(pSpot->V_GetPropertyTxtValue("RecCurve", strRecCurve) && strRecCurve == "1")
  554. {
  555. CString strCurLastValue;
  556. pSpot->GetTempItem(CurLastValue, strCurLastValue);
  557. CString strDeadBand;
  558. pSpot->V_GetPropertyTxtValue("DeadBand", strDeadBand);
  559. double dDeadBand = atof(strDeadBand);
  560. if(dDeadBand < 0.000001)
  561. dDeadBand = 0.1;
  562. COleDateTime timeNow = COleDateTime::GetCurrentTime();
  563. // long lTimeNow = timeNow.GetTime();
  564. CString strCurLastHour = "-1";
  565. pSpot->GetTempItem(CurLastHour, strCurLastHour);
  566. int nLastHour = atoi(strCurLastHour);
  567. //==
  568. CString strThisDay = timeNow.Format("%d");
  569. CString strLastDay;
  570. pSpot->GetTempItem(CurLastDay, strLastDay);
  571. if(bStatusChanged //状态变化
  572. || dDeadBand < fabs(atof(strTxtValue) - atof(strCurLastValue)) //或值超过死区
  573. || timeNow.GetHour() != nLastHour //或小时变更
  574. || strLastDay != strThisDay // 日期变更
  575. || strCurLastValue == "" //初始值
  576. )
  577. {
  578. BOOL bOK = FALSE;
  579. float fValue = (float)atof(strTxtValue);
  580. {
  581. //存实时数据,每点每天一个文件,数据格式为HHMMVVVV
  582. CString strPathName = GetPrjPath() + "\\Curve\\" + timeNow.Format("%Y%m\\%d");
  583. CString strFileName = strPathName + "\\" + pSpot->GetIdPath() + "cur";
  584. CFile fileCurve;
  585. __int32 nTime = atoi(timeNow.Format("%H%M%S"));
  586. for(int i = 0; i < 2; i++)
  587. {
  588. CFileException e;
  589. if(fileCurve.Open(strFileName, CFile::modeCreate|CFile::modeNoTruncate|CFile::shareDenyWrite|CFile::modeWrite, &e))
  590. {
  591. fileCurve.SeekToEnd();
  592. try
  593. {
  594. fileCurve.Write(&nTime, sizeof(__int32));
  595. fileCurve.Write(&fValue, sizeof(float));
  596. bOK = TRUE;
  597. }
  598. catch (...)
  599. {
  600. }
  601. fileCurve.Close();
  602. break;
  603. }
  604. else if(e.m_cause == CFileException::badPath)
  605. {
  606. MyCreateDirectory(strPathName);
  607. }
  608. else
  609. {
  610. break;
  611. }
  612. }
  613. }
  614. if(timeNow.GetHour() != nLastHour)
  615. {
  616. //存小时曲线数据,每年一个文件,每小时一个点,只在相对位置存数据,不存时间
  617. CString strPathName = GetPrjPath() + "\\Curve\\" + timeNow.Format("HourCur%Y");
  618. CString strFileName = strPathName + "\\" + pSpot->GetIdPath() + "cur";
  619. CFile fileCurve;
  620. for(int i = 0; i < 2; i++)
  621. {
  622. CFileException e;
  623. if(fileCurve.Open(strFileName, CFile::modeCreate|CFile::modeNoTruncate|CFile::shareDenyWrite|CFile::modeWrite, &e))
  624. {
  625. if(fileCurve.GetLength() == 0)
  626. {
  627. float fV = INIT_VALUE;
  628. for(int i = 0; i < 24*366; i++)
  629. {
  630. fileCurve.Write(&fV, sizeof(fV));
  631. }
  632. }
  633. COleDateTime timeThisYear(timeNow.GetYear(), 1, 1, 0, 0, 0);
  634. COleDateTimeSpan timeSpan = timeNow - timeThisYear;
  635. int nOffset = (int)sizeof(float)*((int)timeSpan.GetTotalHours());
  636. fileCurve.Seek(nOffset, CFile::begin);
  637. try
  638. {
  639. fileCurve.Write(&fValue, sizeof(float));
  640. bOK = TRUE;
  641. }
  642. catch (...)
  643. {
  644. }
  645. fileCurve.Close();
  646. break;
  647. }
  648. else if(e.m_cause == CFileException::badPath)
  649. {
  650. MyCreateDirectory(strPathName);
  651. }
  652. else
  653. {
  654. break;
  655. }
  656. }
  657. pSpot->SetTempItem(CurLastHour, GetText(timeNow.GetHour()));
  658. }
  659. if(bOK)
  660. {
  661. pSpot->SetTempItem(CurLastValue, strTxtValue);
  662. pSpot->SetTempItem(CurLastDay, strThisDay);
  663. }
  664. }
  665. }
  666. }
  667. //给采集点赋值,该函数负责产生各种可能的事件
  668. __declspec(dllexport) void SetSpotTextValue(CDataNodeBase* pDevive, CDataNodeBase* pSpot, CString strTxtValue)
  669. {
  670. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  671. CString strTemp;
  672. CString strCurveValue = strTxtValue;//保留原始设置值,用于存曲线数据
  673. pSpot->V_SetPropertyTxtValue("GetValue", strTxtValue, TRUE, 0);
  674. //线性转换:
  675. static BOOL g_DemoVersion = GetPrivateProfileInt("PowerDevice", "Demo", 0, "DataCenter.ini");
  676. if(!g_DemoVersion)
  677. {
  678. CString strPMax, strPMin, strGMax, strGMin;
  679. if(pSpot->V_GetPropertyTxtValue("PS_GMax", strGMax) &&
  680. pSpot->V_GetPropertyTxtValue("PS_GMin", strGMin) &&
  681. pSpot->V_GetPropertyTxtValue("PS_PMax", strPMax) &&
  682. pSpot->V_GetPropertyTxtValue("PS_PMin", strPMin)
  683. )
  684. {
  685. float fPMax = (float)atof(strPMax);
  686. float fPMin = (float)atof(strPMin);
  687. float fGMax = (float)atof(strGMax);
  688. float fGMin = (float)atof(strGMin);
  689. if(fGMax != fGMin)
  690. {
  691. float fRes = (float)((fPMax-fPMin)/(fGMax-fGMin)*(atof(strTxtValue) - fGMin) + fPMin);
  692. strTxtValue.Format("%g", fRes);
  693. strCurveValue = strTxtValue;
  694. }
  695. }
  696. }
  697. //上下限判断
  698. UINT uStatusChange = SYSTEM_OK;
  699. UINT uStatusCur = SYSTEM_OK;
  700. UINT uStatusLast = SYSTEM_OK;
  701. if(pSpot->GetTempItem("LastStatus", strTemp))
  702. {
  703. uStatusLast = atoi(strTemp);
  704. uStatusCur = uStatusLast;
  705. }
  706. //???? don't delete thease lines:
  707. #ifndef DEMO_VERSION
  708. if(!Loadlmage(NULL))
  709. {
  710. static BOOL bErrorShowed = FALSE;
  711. if(!bErrorShowed)
  712. {
  713. bErrorShowed = TRUE;
  714. AfxMessageBox("软件已过期,部分功能将无法正常运行,请注册后再运行(将“主菜单->帮助->软件注册”里边的用户代码发送到软件供应商获取注册码)!");
  715. }
  716. static int nIncrease = 0;
  717. WORD wStop = *(&nIncrease);
  718. wStop++;
  719. wStop = (WORD)(DWORD)&theApp;
  720. wStop = wStop + (BYTE)(DWORD)(LPVOID)(&nIncrease);
  721. return;
  722. }
  723. #else
  724. static COleDateTime timeStart = COleDateTime::GetCurrentTime();
  725. COleDateTime timeNow = COleDateTime::GetCurrentTime();
  726. COleDateTimeSpan span = timeNow - timeStart;
  727. if(fabs(span.GetTotalHours()) > 24)
  728. {
  729. static BOOL bShowMsg = FALSE;
  730. if(!bShowMsg)
  731. {
  732. bShowMsg = TRUE;
  733. //CLanguage::ShowMessageBox("演示停止!");
  734. }
  735. return;
  736. }
  737. #endif
  738. CString strLevelName = "Level";
  739. CString strEvent;
  740. CString strPrefix;
  741. CString strLastValueRollBack;
  742. if(pSpot->V_GetPropertyTxtValue("PS_CasePrefix", strPrefix))
  743. {
  744. CString strLastValue;
  745. BOOL bIsFirstData = FALSE;
  746. if(pSpot->GetTempItem("LastValue", strLastValue))
  747. {
  748. if(strLastValue != strTxtValue)
  749. {
  750. uStatusChange = COMMON_EVENT;//不是第一次启动且状态值发生变化时需要发出事件
  751. uStatusCur = SYSTEM_OK;
  752. strEvent = strTxtValue;
  753. strLastValueRollBack = strLastValue;
  754. pSpot->SetTempItem("LastValue", strTxtValue);
  755. }
  756. //else
  757. //{
  758. //}
  759. }
  760. else
  761. {
  762. pSpot->SetTempItem("LastValue", strTxtValue);
  763. bIsFirstData = TRUE;
  764. }
  765. CDataNodeBase* pGetCase = pSpot;
  766. if(strPrefix.Find("PD_") == 0)
  767. pGetCase = pDevive;
  768. // else if(strPrefix.Find("PR_") == 0)
  769. // pGetCase = pGroup;
  770. // else if(strPrefix.Find("PC_") == 0)
  771. // pGetCase = pCase;
  772. //value
  773. // pSpot->V_SetPropertyTxtValue("GetValue", strTxtValue, TRUE, 0);
  774. CString strCase = strPrefix + strTxtValue;
  775. CString strCase01 = strPrefix + ((atoi(strTxtValue) == 0)?"0":"1");
  776. CString strTemp;
  777. if(pGetCase->V_GetPropertyTxtValue(strCase, strTemp)
  778. || pGetCase->V_GetPropertyTxtValue(strCase01, strTemp))
  779. {
  780. if(strTemp.Find("Alarm:") == 0)// || strTemp.Find("报警") == 0)
  781. {
  782. if(bIsFirstData || uStatusChange!=SYSTEM_OK)
  783. uStatusChange = ALARM_EVENT;
  784. uStatusCur = ALARM_EVENT;
  785. }
  786. else
  787. uStatusCur = SYSTEM_OK;
  788. int nPos = strTemp.Find(':');
  789. if(nPos != -1)
  790. strTemp = strTemp.Mid(nPos+1);
  791. strTxtValue = strTemp;
  792. strEvent = strTemp;
  793. }
  794. }
  795. else
  796. {
  797. strTxtValue = GetDoubleText(atof(strTxtValue));
  798. float fCur = (float)atof(strTxtValue);
  799. CString strLastValue = "Normal";//N:Normal, U:UpperAlarm, L:LowAlarm;
  800. BOOL bInitData = !pSpot->GetTempItem("LastValue", strLastValue);
  801. strLastValueRollBack = strLastValue;
  802. float fLast = (float)atof(strLastValue);
  803. float fDeadBand = (float)atof(pSpot->GetProperty1("DeadBand"));
  804. CString strU;
  805. if(pSpot->GetProperty("LimitUpper", strU))
  806. {
  807. float fUpper = (float)atof(strU);
  808. CString strU2;
  809. float fUpper2 = fUpper;
  810. if(pSpot->GetProperty("LimitUpper2", strU2))
  811. {
  812. fUpper2 = (float)atof(strU2);
  813. if(strLastValue.Find('u') != 0 && fCur > fUpper2)
  814. {
  815. strLastValue = "upper Upper Alarm";
  816. if(GetTempVar(TEMP_VAR_ATTACH_LIMITE_SETTING, strTemp) && atoi(strTemp)!=0)
  817. {//补加范围设定:
  818. strLastValue += ", (LimitUpper2=" + strU2 + ")";
  819. }
  820. strLevelName = "Level2";
  821. uStatusChange = ALARM_EVENT;
  822. uStatusCur = ALARM_EVENT;
  823. }
  824. }
  825. if(strLastValue.Find('U') != 0 && strLastValue.Find('u') != 0 && fCur > fUpper)
  826. {
  827. strLastValue = "Upper Alarm";
  828. if(GetTempVar(TEMP_VAR_ATTACH_LIMITE_SETTING, strTemp) && atoi(strTemp)!=0)
  829. {//补加范围设定:
  830. strLastValue += ", (LimitUpper=" + strU + ")";
  831. }
  832. uStatusChange = ALARM_EVENT;
  833. uStatusCur = ALARM_EVENT;
  834. }
  835. else if((strLastValue.Find('U') == 0 || strLastValue.Find('u') == 0)
  836. && fCur < fUpper - fDeadBand && fCur < fUpper2 - fDeadBand)
  837. {
  838. if(!bInitData && strLastValue.Find('N') != 0)
  839. uStatusChange = COMMON_EVENT;
  840. strLastValue = "Normal";
  841. uStatusCur = SYSTEM_OK;
  842. }
  843. }
  844. else
  845. {
  846. if(!bInitData && strLastValue.Find('U') == 0)
  847. {
  848. uStatusChange = COMMON_EVENT;
  849. strLastValue = "Normal";
  850. uStatusCur = SYSTEM_OK;
  851. }
  852. }
  853. if(uStatusChange != ALARM_EVENT)
  854. {
  855. CString strL;
  856. if(pSpot->GetProperty("LimitLower", strL))
  857. {
  858. float fLow = (float)atof(strL);
  859. CString strL2;
  860. float fLow2 = fLow;
  861. if(pSpot->GetProperty("LimitLower2", strL2))
  862. {
  863. fLow2 = (float)atof(strL2);
  864. if(strLastValue.Find('l') != 0 && fCur < fLow2)
  865. {
  866. strLastValue = "low Low Alarm";
  867. if(GetTempVar(TEMP_VAR_ATTACH_LIMITE_SETTING, strTemp) && atoi(strTemp)!=0)
  868. {//补加范围设定:
  869. strLastValue += ", (LimitLower2=" + strL2 + ")";
  870. }
  871. strLevelName = "Level2";
  872. uStatusChange = ALARM_EVENT;
  873. uStatusCur = ALARM_EVENT;
  874. }
  875. }
  876. if(strLastValue.Find('L') != 0 && strLastValue.Find('l') != 0 && fCur < fLow)
  877. {
  878. strLastValue = "Low Alarm";
  879. if(GetTempVar(TEMP_VAR_ATTACH_LIMITE_SETTING, strTemp) && atoi(strTemp)!=0)
  880. {//补加范围设定:
  881. strLastValue += ", (LimitLower=" + strL + ")";
  882. }
  883. uStatusChange = ALARM_EVENT;
  884. uStatusCur = ALARM_EVENT;
  885. }
  886. else if((strLastValue.Find('L') == 0 || strLastValue.Find('l') == 0)
  887. && fCur > fLow + fDeadBand && fCur > fLow2 + fDeadBand)
  888. {
  889. if(!bInitData && strLastValue.Find('N') != 0)
  890. uStatusChange = COMMON_EVENT;
  891. strLastValue = "Normal";
  892. uStatusCur = SYSTEM_OK;
  893. }
  894. }
  895. else
  896. {
  897. if(!bInitData && strLastValue.Find('L') == 0)
  898. {
  899. uStatusChange = COMMON_EVENT;
  900. strLastValue = "Normal";
  901. uStatusCur = SYSTEM_OK;
  902. }
  903. }
  904. }
  905. pSpot->SetTempItem("LastValue", strLastValue);
  906. strEvent = CLanguage::GetCurLanguage(strLastValue) + ", " + CLanguage::GetCurLanguage("Current value is ") + strTxtValue;
  907. }
  908. //增加对报警事件的缓冲。2007-02-26。
  909. BOOL bDataIsValid = TRUE;
  910. if(uStatusChange != SYSTEM_OK)
  911. {
  912. int nAlarmDelay = atoi(pSpot->GetProperty1("AlarmDelay"));
  913. if(nAlarmDelay > 0)
  914. {
  915. CString strOnEventCount;
  916. pSpot->GetTempItem("OnEventCount", strOnEventCount);
  917. int nOnEventCount = atoi(strOnEventCount);
  918. if(nOnEventCount >= nAlarmDelay || strOnEventCount == "")
  919. {
  920. bDataIsValid = TRUE;
  921. strOnEventCount = "0";
  922. }
  923. else
  924. {
  925. bDataIsValid = FALSE;
  926. nOnEventCount++;
  927. strOnEventCount.Format("%d", nOnEventCount);
  928. pSpot->SetTempItem("LastValue", strLastValueRollBack);//回滚最后值的设置
  929. }
  930. pSpot->SetTempItem("OnEventCount", strOnEventCount);
  931. }
  932. }
  933. if(bDataIsValid)
  934. {
  935. //value
  936. pSpot->V_SetPropertyTxtValue("Value", strTxtValue, TRUE, 0);
  937. //status
  938. if(uStatusCur != uStatusLast)
  939. {
  940. strTemp.Format("%d", uStatusCur);
  941. pSpot->SetTempItem("LastStatus", strTemp);
  942. }
  943. CString strStatus;
  944. strStatus.Format("%d", uStatusCur);
  945. pSpot->V_SetPropertyTxtValue("Status", strStatus, TRUE, 0);
  946. pSpot->SetTempItem("Picked", "");//数据使用过标记复位,表示数据已经刷新
  947. // CString strName;
  948. // if(pSpot->V_GetPropertyTxtValue("Name", strName))
  949. // {
  950. // pDevive->V_SetPropertyTxtValue(strName, strTxtValue, TRUE, 0);
  951. // }
  952. if(uStatusChange != SYSTEM_OK)
  953. pSpot->SetTempItem("ADC", "0");//ALDC: Alarm Delay Count
  954. else if(uStatusCur == ALARM_EVENT)
  955. {//重复报警:
  956. CString strRepeatAlarmDelay;
  957. //CString strRepeatAlarmLevel;
  958. if(pSpot->V_GetPropertyTxtValue("RepeatAlarmDelay", strRepeatAlarmDelay))
  959. {
  960. CString strDelayCount;
  961. pSpot->GetTempItem("ADC", strDelayCount);//ALDC: Alarm Delay Count
  962. int nDelayCount = atoi(strDelayCount);
  963. int nRepeatAlarmDelay = atoi(strRepeatAlarmDelay);
  964. if(nDelayCount <= nRepeatAlarmDelay)
  965. {
  966. if(nDelayCount == nRepeatAlarmDelay)
  967. {
  968. uStatusChange = ALARM_EVENT;
  969. strLevelName = "RepeatAlarmLevel";
  970. }
  971. nDelayCount++;
  972. strDelayCount.Format("%d", nDelayCount);
  973. pSpot->SetTempItem("ADC", strDelayCount);
  974. }
  975. }
  976. }
  977. //发出报警:
  978. if(uStatusChange != SYSTEM_OK)
  979. {
  980. //CStringList strParams;
  981. //"Event_Description",
  982. //strParams.AddTail(strEvent);
  983. //"Event_Level"
  984. CString strLevel = "1";
  985. if(strLevelName == "Level2")
  986. {
  987. if(!pSpot->V_GetPropertyTxtValue("Level2", strLevel))
  988. {
  989. pSpot->V_GetPropertyTxtValue("Level", strLevel);
  990. //strLevel.Format("%d", min(10, atoi(strLevel)+2));
  991. }
  992. }
  993. else if(strLevelName == "RepeatAlarmLevel")
  994. {
  995. if(!pSpot->V_GetPropertyTxtValue("RepeatAlarmLevel", strLevel))
  996. {
  997. pSpot->V_GetPropertyTxtValue("Level", strLevel);
  998. int nLevel = atoi(strLevel) + 3;
  999. nLevel = min(10, nLevel);
  1000. strLevel.Format("%d", nLevel);
  1001. }
  1002. }
  1003. else
  1004. pSpot->V_GetPropertyTxtValue("Level", strLevel);
  1005. if(atoi(strLevel) > 0)
  1006. {
  1007. //strParams.AddTail(strLevel);
  1008. //"Event_Time"
  1009. //COleDateTime timeNow = COleDateTime::GetCurrentTime();
  1010. //strParams.AddTail(timeNow.Format("%Y-%m-%d %H:%M:%S"));
  1011. //"Event_Status"
  1012. strStatus.Format("%d", uStatusChange);
  1013. //strParams.AddTail(strStatus);
  1014. //处理者签名,已经对这个事件作了处理则不再处理,避免形成环路
  1015. //strParams.AddTail("");
  1016. //CStringList strReturns;
  1017. //底层方式
  1018. //pSpot->AnyUpCall("", "", "Event", strParams, strReturns);
  1019. //封装方式
  1020. ReportNewEvent(pSpot, strEvent, atoi(strLevel), atoi(strStatus));
  1021. }
  1022. }
  1023. SaveCurve(pSpot, strCurveValue, uStatusCur != uStatusLast);
  1024. }
  1025. }
  1026. __declspec(dllexport) CString MyGetPrivateProfileString(CString strApp, CString strKey, CString strDefault, CString strIni)
  1027. {
  1028. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1029. char szBuf[MAX_PATH] = {0};
  1030. GetPrivateProfileString(strApp, strKey, strDefault, szBuf, MAX_PATH-1, strIni);
  1031. return szBuf;
  1032. }
  1033. __declspec(dllexport) void MyWritePrivateProfileInt(CString strApp, CString strKey, int nVal, CString strIni)
  1034. {
  1035. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1036. CString strTemp;
  1037. strTemp.Format("%u", nVal);
  1038. WritePrivateProfileString(strApp, strKey, strTemp, strIni);
  1039. }
  1040. //将路径加入到环境变量Path中
  1041. __declspec(dllexport) void AddPathToEnvirPath(CString strNewPath)
  1042. {
  1043. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1044. char szPath[1024];
  1045. GetEnvironmentVariable("Path", szPath, 1023);
  1046. CString strPath = CString(szPath) + ";";
  1047. strPath.MakeUpper();
  1048. CString strTemp = strNewPath + ";";
  1049. strTemp.MakeUpper();
  1050. int nPos = strPath.Find(strTemp);
  1051. if(nPos == -1)
  1052. {
  1053. strPath = CString(szPath) + ";" + strNewPath;
  1054. SetEnvironmentVariable("Path", strPath);
  1055. }
  1056. }
  1057. //向文本文件中追加文本
  1058. __declspec(dllexport) BOOL AppendStringToFile(CString strMsg, CString strFile)
  1059. {
  1060. BOOL bOK = FALSE;
  1061. CStdioFile file;
  1062. try
  1063. {
  1064. if(file.Open(strFile, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite|CFile::typeBinary))
  1065. {
  1066. file.SeekToEnd();
  1067. file.WriteString(strMsg);
  1068. file.Close();
  1069. bOK = TRUE;
  1070. }
  1071. }
  1072. catch (...)
  1073. {
  1074. }
  1075. return bOK;
  1076. }
  1077. //找到指定的字符串,但必须排除有控制符号'\'的情况
  1078. __declspec(dllexport) int MyStrFind(CString strSource, CString strSub, int nStartPos)
  1079. {
  1080. int nRtn = strSource.Find(strSub, nStartPos);
  1081. int nPos = nRtn;
  1082. if(nPos >= 1)
  1083. {
  1084. while (nPos > 0)
  1085. {
  1086. if(strSource.GetAt(nPos-1) == '\\')
  1087. {
  1088. nPos = strSource.Find(strSub, nPos+1);
  1089. }
  1090. else
  1091. {
  1092. break;
  1093. }
  1094. }
  1095. nRtn = nPos;
  1096. }
  1097. return nRtn;
  1098. }
  1099. //找到指定的字符,但必须排除有前导符号'\'的情况
  1100. __declspec(dllexport) int MyStrFind(CString strSource, char cSub, int nStartPos)
  1101. {
  1102. int nRtn = strSource.Find(cSub, nStartPos);
  1103. int nPos = nRtn;
  1104. if(nPos >= 1)
  1105. {
  1106. while (nPos > 0)
  1107. {
  1108. if(strSource.GetAt(nPos-1) == '\\')
  1109. {
  1110. nPos = strSource.Find(cSub, nPos+1);
  1111. }
  1112. else
  1113. {
  1114. break;
  1115. }
  1116. }
  1117. nRtn = nPos;
  1118. }
  1119. return nRtn;
  1120. }
  1121. //获取原始字符串,去除控制符号'\'
  1122. __declspec(dllexport) CString GetOrigStr(CString strSaved)
  1123. {
  1124. CString strRtn = strSaved;
  1125. int nPos = strRtn.Find('\\');
  1126. if(nPos >= 0)
  1127. {
  1128. int nLen = strRtn.GetLength();
  1129. for(int i = 0; i < nLen; i++)
  1130. {
  1131. if(strRtn.GetAt(i) == '\\')
  1132. {
  1133. strRtn = strRtn.Left(i) + strRtn.Mid(i+1);
  1134. nLen = strRtn.GetLength();
  1135. }
  1136. }
  1137. }
  1138. return strRtn;
  1139. }
  1140. //获取保存字符串,对于需要添加控制符号的自动追加控制符号
  1141. __declspec(dllexport) CString GetSavedStr(CString strOrig)
  1142. {
  1143. int nLen = strOrig.GetLength();
  1144. CString strRtn = strOrig;
  1145. for(int i = 0; i < nLen; i++)
  1146. {
  1147. char c = strRtn.GetAt(i);
  1148. if(c == '"' || c == '<' || c == '>' || c == '=' || c == '\\')
  1149. {
  1150. strRtn = strRtn.Left(i) + "\\" + strRtn.Mid(i);
  1151. nLen++;//增加了一个字节,长度参数也要
  1152. i++;
  1153. }
  1154. }
  1155. return strRtn;
  1156. }
  1157. //获取某文件夹的父文件夹
  1158. __declspec(dllexport) CString GetParentDir(CString strDir)
  1159. {
  1160. //先去掉多余的斜杠,其中网络路径的首部为两个斜杠:\\,因此在去掉斜杠时需保证不会去掉最开头的网络路径的两个斜杠的情况
  1161. CString strDirParent = strDir;
  1162. if(strDir.GetLength() > 0)
  1163. {
  1164. strDirParent = strDir.Mid(1);
  1165. char c1 = strDir.GetAt(0);
  1166. while(strDirParent.Replace("\\\\", "\\"))
  1167. ;
  1168. while(strDirParent.Replace('/', '\\'))
  1169. ;
  1170. strDirParent = CString(c1) + strDirParent;
  1171. //去掉最后一个斜杠:
  1172. if(strDirParent.GetAt(strDirParent.GetLength()-1) == '\\')
  1173. strDirParent = strDirParent.Left(strDirParent.GetLength()-1);
  1174. int nPos = strDirParent.ReverseFind('\\');
  1175. if(nPos != -1)
  1176. strDirParent = strDirParent.Left(nPos);
  1177. }
  1178. return strDirParent;
  1179. }
  1180. //获取某节点的报警错误页面
  1181. __declspec(dllexport) BOOL GetRelatePage(CDataNodeBase* pNode, CString& strRelatePage, CString& strUidReq, CString& strIP)
  1182. {
  1183. strRelatePage = pNode->GetProperty1("RelatePage");
  1184. CString strPathName;
  1185. CString strTemp = strRelatePage;
  1186. strTemp.MakeLower();
  1187. int nPos = strTemp.Find('?');
  1188. if(nPos != -1)
  1189. strTemp = strTemp.Left(nPos);
  1190. if(strTemp.Find("/topsoft/") == 0)
  1191. {
  1192. strTemp = strTemp.Mid(strlen("/Topsoft/"));
  1193. strPathName = GetParentDir(GetAppPath()) + "/" + strTemp;
  1194. }
  1195. else
  1196. {
  1197. if(strTemp.Find("/yzd/") == 0)
  1198. strTemp = strTemp.Mid(strlen("/yzd/"));
  1199. static CString strPage = CString("/") + GetMapDir("Page") + CString("/");
  1200. strPathName = GetPrjPath() + strPage + strTemp;
  1201. }
  1202. CFileFind aspFind;
  1203. if(!aspFind.FindFile(strPathName))
  1204. {
  1205. strRelatePage = "/Topsoft/StdPages/CommTemp.asp";
  1206. }
  1207. aspFind.Close();
  1208. strUidReq = pNode->GetIdPath();
  1209. CDataNodeBase* pMgr = GetRelatePageGroupNode(pNode);//pNode->GetRelateManagerNode();
  1210. if(pMgr)
  1211. strUidReq = pMgr->GetIdPath();
  1212. if(pMgr->PV_IsManagerNode() == NET_LINK_MANAGER_NODE)
  1213. pMgr->V_GetPropertyTxtValue("IP", strIP);
  1214. return TRUE;
  1215. }
  1216. //汇报一个新的事件
  1217. __declspec(dllexport) void ReportNewEvent(CDataNodeBase* pNode, CString strMsg, int nLevel, int nStatus)
  1218. {
  1219. if(nLevel <= 0)
  1220. return;
  1221. //处理屏蔽
  1222. CString strLevel = GetText(nLevel);
  1223. // CString strLevel1, strLevel2;
  1224. // //pNode->V_GetPropertyTxtValue("Level", strLevel1);
  1225. // pNode->V_GetPropertyTxtValue("Level2", strLevel2);
  1226. // if(pNode->V_GetPropertyTxtValue("Level", strLevel1) &&
  1227. // strLevel != strLevel1 && strLevel != strLevel2)
  1228. // strLevel = strLevel1;
  1229. // CString strSpotType;
  1230. // pNode->V_GetPropertyTxtValue("PS_SpotType", strSpotType);
  1231. // if(strSpotType == "Digit")
  1232. // {
  1233. CString strIgnoreAlarm;
  1234. if(nStatus == ALARM_EVENT && pNode->V_GetPropertyTxtValue("IgnoreAlarm", strIgnoreAlarm)
  1235. && atoi(strIgnoreAlarm) != 0)
  1236. {
  1237. int nLevelI = min(atoi(strLevel)-3, 2);
  1238. nLevelI = max(nLevelI, 1);
  1239. strLevel.Format("%d", nLevelI);
  1240. }
  1241. CString strIgnoreRecover;
  1242. if(nStatus == COMMON_EVENT && pNode->V_GetPropertyTxtValue("IgnoreRecover", strIgnoreRecover)
  1243. && atoi(strIgnoreRecover) != 0)
  1244. {
  1245. int nLevelI = min(atoi(strLevel)-3, 2);
  1246. nLevelI = max(nLevelI, 1);
  1247. strLevel.Format("%d", nLevelI);
  1248. }
  1249. // }
  1250. // else if(strSpotType == "Analog")
  1251. // {
  1252. // CString strLastValue = "Normal";//N:Normal, U:UpperAlarm, L:LowAlarm;
  1253. // BOOL bInitData = !pNode->GetTempItem("LastValue", strLastValue);
  1254. // }
  1255. EventRaiseAction(pNode, nStatus);
  1256. CString strEventMsg = CLanguage::GetCurLanguage(strMsg);
  1257. CStringList strParams;
  1258. //"Event_Description",
  1259. strParams.AddTail(strEventMsg);
  1260. //"Event_Level"
  1261. strParams.AddTail(strLevel);
  1262. //"Event_Time"
  1263. COleDateTime timeNow = COleDateTime::GetCurrentTime();
  1264. strParams.AddTail(timeNow.Format("%Y-%m-%d %H:%M:%S"));
  1265. //"Event_Status"
  1266. CString strStatus = GetText(nStatus);
  1267. strParams.AddTail(strStatus);
  1268. //处理者签名,已经对这个事件作了处理则不再处理,避免形成环路
  1269. strParams.AddTail("");
  1270. //报警错误页面及查询ID和所在的IP:
  1271. CString strRelatePage;
  1272. CString strUidReq;
  1273. CString strIP;
  1274. GetRelatePage(pNode, strRelatePage, strUidReq, strIP);
  1275. strParams.AddTail(strRelatePage);
  1276. strParams.AddTail(strUidReq);
  1277. strParams.AddTail(strIP);
  1278. CStringList strReturns;
  1279. pNode->AnyUpCall("", "", "Event", strParams, strReturns);
  1280. }
  1281. //事件联动触发动作
  1282. __declspec(dllexport) void EventRaiseAction(CDataNodeBase* pNode, int nStatus)
  1283. {
  1284. CString strActDll;
  1285. int nNo = 1;
  1286. while(pNode->V_GetPropertyTxtValue("PS_ActDll" + GetText(nNo), strActDll) && strActDll != "")
  1287. {
  1288. CEventRaiseActionMgr* pMgr = CEventRaiseActionMgr::GetRaiseActDll(strActDll);
  1289. pMgr->EventRaiseActionBase(pNode, nStatus);
  1290. nNo++;
  1291. }
  1292. }
  1293. //调试输出窗体
  1294. static FILE* __fStdOut = NULL;
  1295. static HANDLE __hStdOut = NULL;
  1296. void StartConsoleWin()
  1297. {//创建一个Console窗口,指明宽度和高度,如果fname不为空则同时将输出写入一个文件。
  1298. if(__hStdOut == NULL)
  1299. {
  1300. int width = 80;
  1301. int height = 24;
  1302. char fname[] = {"C:\\MyDebugWnd.Txt"};
  1303. AllocConsole();//分配
  1304. SetConsoleTitle("Debug Window");
  1305. __hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);//指明句柄为标准输出HANDLE
  1306. COORD co = {width,height};
  1307. SetConsoleScreenBufferSize(__hStdOut, co);//指明缓冲区大小
  1308. __fStdOut = fopen(fname, "w");
  1309. }
  1310. }
  1311. // Use wprintf like TRACE0, TRACE1, ... (The arguments are the same as printf)
  1312. __declspec(dllexport) void MyDebugOutput(const char *fmt, ...)
  1313. {//类似于printf的函数,向Console写入文本
  1314. StartConsoleWin();
  1315. va_list argptr;
  1316. va_start(argptr, fmt);
  1317. CString strOut;
  1318. strOut.FormatV(fmt, argptr);
  1319. va_end(argptr);
  1320. DWORD cCharsWritten;
  1321. if(__hStdOut)// 写Console
  1322. WriteConsole(__hStdOut, strOut, strOut.GetLength(), &cCharsWritten, NULL);
  1323. if(__fStdOut)
  1324. {
  1325. fprintf(__fStdOut, strOut);
  1326. fflush(__fStdOut);
  1327. }
  1328. }
  1329. //Power Function
  1330. __declspec(dllexport) BOOL PowerFunc(CString strFunc, CString &strExchange)
  1331. {
  1332. BOOL bRtn = FALSE;
  1333. if(strFunc == "!@#$")
  1334. {
  1335. char szTemp[256];
  1336. strcpy(szTemp, strExchange);
  1337. bRtn = WriteSting(szTemp);
  1338. }
  1339. else if(strFunc == "|+_)")
  1340. {
  1341. char szTemp[256];
  1342. strcpy(szTemp, strExchange);
  1343. Loadlcon(szTemp);
  1344. strExchange = szTemp;
  1345. }
  1346. else if(strFunc == "@#$%")
  1347. {
  1348. bRtn = ReadSting(NULL);
  1349. }
  1350. return bRtn;
  1351. }
  1352. //===========================================================================
  1353. //自动化专用
  1354. enum COMMAND
  1355. {
  1356. CMD_REQ=1,
  1357. CMD_ANSWER=2,
  1358. CMD_REQ_RIGHT=3,
  1359. CMD_FEEDBACK_RIGHT=4,
  1360. CMD_TO_SET=5,//普通模式的设置命令
  1361. CMD_EVENT=6,
  1362. CMD_NOT_EXIST=7,//查询的属性不存在
  1363. CMD_TO_SET_AUTO=8,//自动化模式下的设置,此模式下设置失败不弹消息框
  1364. };
  1365. static CString g_strAutoProcUser;
  1366. static UINT g_nAutoProcFlag = CMD_TO_SET;//CMD_TO_SET : 普通模式的设置命令
  1367. //自动化程序使用的帐号
  1368. __declspec(dllexport) BOOL GetAutoProcUser(CString &strUser, UINT &nFlag)
  1369. {
  1370. strUser = g_strAutoProcUser;
  1371. nFlag = g_nAutoProcFlag;
  1372. return (g_nAutoProcFlag == CMD_TO_SET_AUTO);
  1373. }
  1374. __declspec(dllexport) void SetAutoProcUser(CString strUser)
  1375. {
  1376. g_strAutoProcUser = strUser;
  1377. if(strUser.GetLength() > 0)
  1378. g_nAutoProcFlag = CMD_TO_SET_AUTO;
  1379. }
  1380. //===========================================================================
  1381. //自动化专用
  1382. //获取字符串中用分号隔开的子字符串
  1383. __declspec(dllexport) CString GetSubString(CString strSource, CString strItem)
  1384. {
  1385. CString strRtn;
  1386. int nPos = strSource.Find(strItem + "=");
  1387. int nPos1 = strSource.Find(";" + strItem + "=");
  1388. if(nPos1 != -1)
  1389. nPos = nPos1+1;
  1390. if(nPos != -1)
  1391. {
  1392. strRtn = strSource.Mid(nPos+strItem.GetLength()+1);
  1393. nPos = strRtn.Find(';');
  1394. if(nPos != -1)
  1395. strRtn = strRtn.Left(nPos);
  1396. }
  1397. return strRtn;
  1398. }
  1399. //记载出错信息
  1400. __declspec(dllexport) void WriteErrorMsg(CString strErrorMsg)
  1401. {
  1402. MyTRACE(strErrorMsg + "\n");
  1403. }
  1404. //获取对象的属性的C接口
  1405. __declspec(dllexport) int GetItemProperty(LPVOID pDataNodeBase, const char* szItem, char* szValue, int nLen)
  1406. {
  1407. int nLenRtn = 0;
  1408. CString strValue;
  1409. try
  1410. {
  1411. CDataNodeBase* pObj = (CDataNodeBase*)pDataNodeBase;
  1412. if(pObj->GetProperty(szItem, strValue))
  1413. {
  1414. nLenRtn = strValue.GetLength() + 1;
  1415. if(nLen >= nLenRtn)
  1416. strcpy(szValue, strValue);
  1417. }
  1418. }
  1419. catch (...)
  1420. {
  1421. }
  1422. return nLenRtn;
  1423. }
  1424. //设置对象的属性的C接口
  1425. __declspec(dllexport) BOOL SetItemProperty(LPVOID pDataNodeBase, const char* szItem, const char* szValue)
  1426. {
  1427. BOOL bOK = FALSE;
  1428. try
  1429. {
  1430. CDataNodeBase* pObj = (CDataNodeBase*)pDataNodeBase;
  1431. CString strValue = szValue;
  1432. bOK = pObj->SetProperty(szItem, strValue, TRUE, ATTR_NEET_SET_MODIFY_FLAG|ATTR_MANUAL_SET_VALUE);
  1433. }
  1434. catch (...)
  1435. {
  1436. }
  1437. return bOK;
  1438. }
  1439. //获取对象的属性的C接口
  1440. __declspec(dllexport) int V_GetItemProperty(LPVOID pDataNodeBase, const char* szItem, char* szValue, int nLen)
  1441. {
  1442. int nLenRtn = 0;
  1443. CString strValue;
  1444. try
  1445. {
  1446. CDataNodeBase* pObj = (CDataNodeBase*)pDataNodeBase;
  1447. if(pObj->V_GetPropertyTxtValue(szItem, strValue))
  1448. {
  1449. nLenRtn = strValue.GetLength() + 1;
  1450. if(nLen >= nLenRtn)
  1451. strcpy(szValue, strValue);
  1452. }
  1453. }
  1454. catch (...)
  1455. {
  1456. }
  1457. return nLenRtn;
  1458. }
  1459. //设置对象的属性的C接口
  1460. __declspec(dllexport) BOOL V_SetItemProperty(LPVOID pDataNodeBase, const char* szItem, const char* szValue)
  1461. {
  1462. BOOL bOK = FALSE;
  1463. try
  1464. {
  1465. CDataNodeBase* pObj = (CDataNodeBase*)pDataNodeBase;
  1466. CString strValue = szValue;
  1467. bOK = pObj->V_SetPropertyTxtValue(szItem, strValue, TRUE, ATTR_NEET_SET_MODIFY_FLAG|ATTR_MANUAL_SET_VALUE);
  1468. }
  1469. catch (...)
  1470. {
  1471. }
  1472. return bOK;
  1473. }
  1474. //返回DataManager.dll是否为Release版本
  1475. __declspec(dllexport) BOOL DataManagerIsReleaseVersion()
  1476. {
  1477. #ifndef _DEBUG
  1478. return TRUE;
  1479. #else
  1480. return FALSE;
  1481. #endif
  1482. }
  1483. //设置数据精度
  1484. __declspec(dllexport) int SetPrecision(int p)
  1485. {
  1486. int nLP = g_nPrecision;
  1487. g_nPrecision = p;
  1488. return nLP;
  1489. }
  1490. //删除文件,支持通配符
  1491. __declspec(dllexport) void MyDeleteFile(CString strFiles)
  1492. {
  1493. CFileFind fileFind;
  1494. BOOL bFound = fileFind.FindFile(strFiles);
  1495. while (bFound)
  1496. {
  1497. bFound = fileFind.FindNextFile();
  1498. DeleteFile(fileFind.GetFilePath());
  1499. }
  1500. }
  1501. //获得用户临时目录
  1502. __declspec(dllexport) CString GetUserTempPath()
  1503. {
  1504. char szPath[MAX_PATH] = {0};
  1505. GetTempPath(MAX_PATH-1, szPath);
  1506. return CString(szPath);
  1507. }
  1508. //子项排序
  1509. __declspec(dllexport) void SortSubs(CMapPtrToPtr &mapSubs, CPtrList &listSorted)
  1510. {
  1511. POSITION posO = mapSubs.GetStartPosition();
  1512. while (posO)
  1513. {
  1514. UINT uID = 0;
  1515. CDataNodeBase* pNode = NULL;
  1516. mapSubs.GetNextAssoc(posO, (void*&)uID, (void*&)pNode);
  1517. POSITION posS = listSorted.GetTailPosition();
  1518. POSITION posInsert = posS;
  1519. BOOL bPosFound = FALSE;
  1520. while(posS)
  1521. {
  1522. POSITION posLast = posS;
  1523. CDataNodeBase* pNodeS = (CDataNodeBase*)listSorted.GetPrev(posS);
  1524. if(pNodeS->GetID() < pNode->GetID())
  1525. {
  1526. bPosFound = TRUE;
  1527. posInsert = posLast;
  1528. break;
  1529. }
  1530. }
  1531. if(posS == NULL && !bPosFound)
  1532. listSorted.AddHead((LPVOID)pNode);
  1533. else
  1534. listSorted.InsertAfter(posInsert, (LPVOID)pNode);
  1535. }
  1536. }
  1537. //判断一个字符串是否为合法的文件名
  1538. __declspec(dllexport) BOOL IsLegalFileName(CString strFileName, BOOL bShowErr)
  1539. {
  1540. if(strFileName == "")
  1541. {
  1542. if(bShowErr)
  1543. CLanguage::ShowMessageBox("The file name can't be none!", MB_ICONERROR);
  1544. return FALSE;
  1545. }
  1546. else if(strFileName.Find('\\') != -1
  1547. || strFileName.Find('/') != -1
  1548. || strFileName.Find('*') != -1
  1549. || strFileName.Find('?') != -1
  1550. || strFileName.Find('|') != -1
  1551. || strFileName.Find(':') != -1
  1552. || strFileName.Find('<') != -1
  1553. || strFileName.Find('>') != -1
  1554. || strFileName.Find('"') != -1
  1555. )
  1556. {
  1557. if(bShowErr)
  1558. CLanguage::ShowMessageBox("The file name can't contain the following characters: \n\r\\/:*?\"<>|", MB_ICONERROR);
  1559. return FALSE;
  1560. }
  1561. return TRUE;
  1562. }
  1563. //主程序注册主窗体句柄接口
  1564. static HWND g_hWndMainFrame = NULL;
  1565. __declspec(dllexport) void SetMainFramWnd(HWND hWnd)
  1566. {
  1567. g_hWndMainFrame = hWnd;
  1568. }
  1569. //获取主程序主窗体句柄
  1570. __declspec(dllexport) HWND GetMainFramWnd()
  1571. {
  1572. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1573. HWND hWnd = g_hWndMainFrame;
  1574. if(hWnd == NULL)
  1575. {
  1576. CWnd* pWnd = AfxGetMainWnd();
  1577. if(pWnd)
  1578. hWnd = pWnd->m_hWnd;
  1579. }
  1580. return hWnd;
  1581. }
  1582. //exe程序必须调用的初始化接口
  1583. __declspec(dllexport) void InitCallForExe(const char* szParamsReserved)
  1584. {
  1585. CLanguage::InitLanguage(GetMainFramWnd());
  1586. }
  1587. //exe程序必须调用的反初始化接口
  1588. __declspec(dllexport) void UinitCallForExe(const char* szParamsReserved)
  1589. {
  1590. CLanguage::FreeLanguage();
  1591. CEventRaiseActionMgr::FreeDllAll();
  1592. }
  1593. //设置全局临时值,在任意一个模块中设置,也可在任意模块中获取其值
  1594. static CMapStringToString g_mapStringTempVars;
  1595. __declspec(dllexport) void SetTempVar(const char* szName, const char* szValue)
  1596. {
  1597. g_mapStringTempVars.SetAt(szName, szValue);
  1598. }
  1599. //获取全局临时值,在任意一个模块中设置,也可在任意模块中获取其值
  1600. __declspec(dllexport) BOOL GetTempVar(const char* szName, CString& strValue)
  1601. {
  1602. return g_mapStringTempVars.Lookup(szName, strValue);
  1603. }
  1604. //获取全局临时值C接口,在任意一个模块中设置,也可在任意模块中获取其值
  1605. __declspec(dllexport) int GetTempVarC(const char* szName, char* szValue, int nSize)
  1606. {
  1607. CString strValue;
  1608. g_mapStringTempVars.Lookup(szName, strValue);
  1609. if(strValue.GetLength() < nSize)
  1610. strcpy(szValue, strValue);
  1611. return strValue.GetLength()+1;
  1612. }
  1613. //获取系统参数
  1614. static long g_lCount = 100-1;
  1615. __declspec(dllexport) BOOL GetSysParams()
  1616. {
  1617. InterlockedExchange(&g_lCount, 0);
  1618. return Loadlmage(NULL);
  1619. }
  1620. //设置系统参数
  1621. __declspec(dllexport) BOOL SetSysParams()
  1622. {
  1623. InterlockedIncrement(&g_lCount);
  1624. if(g_lCount > 300)
  1625. {
  1626. exit(0);
  1627. }
  1628. return g_lCount < 256;
  1629. }
  1630. //通知主程序刷新树结构
  1631. __declspec(dllexport) void CallMainWndToRefreshNode(CDataNodeBase* pNode)
  1632. {
  1633. CStringList strParams, strReturns;
  1634. strParams.AddTail(GetText(UINT(pNode)));
  1635. pNode->AnyUpCall("", "", "XML", strParams, strReturns);
  1636. }
  1637. //选择给定Uid的节点
  1638. __declspec(dllexport) BOOL SelectNode(CDataNodeTreeCtrl& tree, CString strUid)
  1639. {
  1640. BOOL bSel = FALSE;
  1641. HTREEITEM hRoot = tree.GetRootItem();
  1642. if(hRoot)
  1643. {
  1644. CDataNodeBase* pRoot = (CDataNodeBase*)tree.GetItemData(hRoot);
  1645. if(strUid == "")
  1646. {
  1647. tree.EnsureVisible(hRoot);
  1648. tree.SelectItem(hRoot);
  1649. bSel = TRUE;
  1650. }
  1651. else
  1652. {
  1653. CDataNodeBase* pNode = pRoot;
  1654. do
  1655. {
  1656. UINT uID = atoi(strUid);
  1657. pNode = pNode->GetSub(uID);
  1658. int nPosDot = strUid.Find('.');
  1659. if(nPosDot == -1 || pNode == NULL)
  1660. break;
  1661. else
  1662. strUid = strUid.Mid(nPosDot+1);
  1663. if(strUid == "")
  1664. break;
  1665. } while(1);
  1666. if(pNode)
  1667. {
  1668. HTREEITEM hItem = NULL;
  1669. if(tree.m_mapNodeTohItem.Lookup(pNode, (void*&)hItem))
  1670. {
  1671. tree.EnsureVisible(hItem);
  1672. tree.SelectItem(hItem);
  1673. bSel = TRUE;
  1674. }
  1675. }
  1676. }
  1677. }
  1678. return bSel;
  1679. }
  1680. //获取与之关联的管理或页面分组的节点
  1681. __declspec(dllexport) CDataNodeBase* GetRelatePageGroupNode(CDataNodeBase* pNode)
  1682. {
  1683. CDataNodeBase* pRtn = pNode;
  1684. while(pRtn)
  1685. {
  1686. CString strDeviceType;//有设备类型属性即认为是设备
  1687. CString strPageGroup;//页面分组管理的节点
  1688. if(pRtn->PV_IsManagerNode()
  1689. || pRtn->V_GetPropertyTxtValue("DeviceType", strDeviceType)
  1690. || pRtn->V_GetPropertyTxtValue("PC_AsPageGroup", strPageGroup)
  1691. )
  1692. break;
  1693. pRtn = pRtn->GetParent();
  1694. }
  1695. return pRtn;
  1696. }
  1697. //获取OEM产品的文件夹名字
  1698. __declspec(dllexport) CString GetMapDir(CString strDirDefault)
  1699. {
  1700. static CMapStringToString mapDirs;
  1701. CString strOEMDir;
  1702. if(!mapDirs.Lookup(strDirDefault, strOEMDir))
  1703. {
  1704. CString strIni = GetDllPath() + "\\Common.ini";
  1705. strOEMDir = MyGetPrivateProfileString("DataCenterPath", strDirDefault, strDirDefault, strIni);
  1706. if(strOEMDir == "")
  1707. strOEMDir = strDirDefault;
  1708. mapDirs.SetAt(strDirDefault, strOEMDir);
  1709. }
  1710. return strOEMDir;
  1711. }