// stdafx.cpp : source file that includes just the standard includes // DataManager.pch will be the pre-compiled header // stdafx.obj will contain the pre-compiled type information #include #include "stdafx.h" #include "EventRaiseActionMgr.h" int g_nPrecision = 4; __declspec(dllexport) bool Encrypt(const char szFileOrig[], const char szFileNew[], const char szPwd[]) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); int nLenPwd = strlen(szPwd); char *pPwdHere = new char[nLenPwd+1]; strcpy(pPwdHere, szPwd); for(int i = 0; i < nLenPwd; i++) pPwdHere[i] ^= 19760807; char s[] = "工程名"; CFile fileR; CFile fileW; if(fileR.Open(szFileOrig, CFile::typeBinary|CFile::modeRead)) { if(fileW.Open(szFileNew, CFile::typeBinary|CFile::modeCreate|CFile::modeWrite)) { char c; i = 0; while (fileR.Read(&c, 1) == 1) { c = c^ pPwdHere[i++]; if(i >= nLenPwd) i = 0; fileW.Write(&c, 1); } fileW.Close(); } fileR.Close(); } delete []pPwdHere; return false; } __declspec(dllexport) CString GetText(UINT uData) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strTemp; strTemp.Format("%u", uData); return strTemp; } //由数据精度获得浮点数的字符串值 __declspec(dllexport) CString GetDoubleText(double d) { CString strRtn; CString strFmt; if(g_nPrecision == 0) strFmt = "%g"; else { long lV = (long)fabs(d); if(lV >= 1) { int nIntBit = 0; while(lV >= 1) { lV = lV/10; nIntBit++; } if(nIntBit < g_nPrecision) strFmt.Format("%c%d.%df", '%', nIntBit, (g_nPrecision-nIntBit)); else strFmt.Format("%c%d.0f", '%', nIntBit); } else { double dTemp = fabs(d); if(dTemp > 0.00000000001) { int nDot0Bit = 0; while(dTemp < 0.1) { dTemp = dTemp*10; nDot0Bit++; } strFmt.Format("%c1.%df", '%', nDot0Bit + g_nPrecision); } else { strFmt = "%g"; } } } strRtn.Format(strFmt, d); return strRtn; } __declspec(dllexport) BOOL MyCopyFiles(CString strSource, CString strDest) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); BOOL bOK = FALSE; if(MyCreateDirectory(strDest)) { bOK = TRUE; CFileFind fileFind; BOOL bFound = fileFind.FindFile(strSource + "\\*.*"); while (bFound) { bFound = fileFind.FindNextFile(); if(fileFind.IsDots()) continue; else if(fileFind.IsDirectory()) { if(!MyCopyFiles(fileFind.GetFilePath(), strDest + "\\" + fileFind.GetFileName())) bOK = FALSE; } else { if(!CopyFile(fileFind.GetFilePath(), strDest + "\\" + fileFind.GetFileName(), FALSE)) bOK = FALSE; } }; fileFind.Close(); } return bOK; } __declspec(dllexport) BOOL MyCreateDirectory(CString strPath) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); strPath += "\\"; BOOL bCreateOK = FALSE; if(strPath.GetLength() > 4) { bCreateOK = TRUE; CString strTemp =strPath.Mid(1); while(strTemp.Replace("\\\\", "\\") > 0) { //do nothing else } strTemp = strPath.Left(1) + strTemp; if(strTemp.Find("\\\\") == -1 && strTemp.Find(":\\") != 1) {// 既不是网络路径也不是从盘符开始的磁盘路径视为无效. bCreateOK = FALSE; } else { int nPos = 3; if(strTemp.Find("\\\\") == 0) { nPos = strTemp.Find("\\", nPos); if(nPos != -1) { nPos = strTemp.Find("\\", nPos+1); if(nPos != -1) { nPos = strTemp.Find("\\", nPos+1); } } } nPos = strTemp.Find('\\', nPos); while(nPos > -1) { CString strPathRout = strTemp.Left(nPos); CFileFind fileFind; if(!fileFind.FindFile(strPathRout)) { if(!CreateDirectory(strPathRout, NULL)) { bCreateOK = FALSE; break; } } fileFind.Close(); nPos = strTemp.Find('\\', nPos + 1); } } } return bCreateOK; } __declspec(dllexport) BOOL MyDeleteDirectory(CString strPath)//删除任意深度的路径 { AFX_MANAGE_STATE(AfxGetStaticModuleState()); BOOL bOK = TRUE; CFileFind fileFind; BOOL bFound = fileFind.FindFile(strPath + "\\*.*"); while (bFound) { bFound = fileFind.FindNextFile(); if(fileFind.IsDots()) continue; else if(fileFind.IsDirectory()) { if(!MyDeleteDirectory(fileFind.GetFilePath())) bOK = FALSE; } else { if(!DeleteFile(fileFind.GetFilePath())) { CFileStatus rStatus; CFile::GetStatus(fileFind.GetFilePath(), rStatus); rStatus.m_attribute = CFile::normal; CFile::SetStatus(fileFind.GetFilePath(), rStatus); if(!DeleteFile(fileFind.GetFilePath())) bOK = FALSE; } } } fileFind.Close(); RemoveDirectory(strPath); return bOK; } __declspec(dllexport) CString GetAppPath() { AFX_MANAGE_STATE(AfxGetStaticModuleState()); #ifndef DEMO_VERSION char szPath[300] = {0}; LoadSting(szPath); return szPath; #else static CString strAppPath; if(strAppPath.IsEmpty()) { char szuf[256]; GetModuleFileName(NULL, szuf, 255); strAppPath = szuf; int nPos = strAppPath.ReverseFind('\\'); if(nPos > -1) strAppPath = strAppPath.Left(nPos); } return strAppPath; #endif } static CString g_strPrjPath; __declspec(dllexport) CString SetPrjPath(CString strPrjPath)//设置工程的路径 { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strRtn = g_strPrjPath; g_strPrjPath = strPrjPath; theApp.m_bLoadedByMainProg = TRUE; return strRtn; } __declspec(dllexport) CString GetPrjPath()//获取工程的路径 { AFX_MANAGE_STATE(AfxGetStaticModuleState()); if(g_strPrjPath == "") return GetAppPath(); return g_strPrjPath; } static CDataNodeBase* g_pRoot = NULL; __declspec(dllexport) void SetPrjRoot(CDataNodeBase* pRoot)//设置工程的根节点,由主程序设置 { g_pRoot = pRoot; } __declspec(dllexport) CDataNodeBase* GetPrjRoot()//获取工程的根节点 { return g_pRoot; } //获取动态库的所在路径 __declspec(dllexport) CString GetDllPath() { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strAppPath; char szuf[256]; GetModuleFileName(AfxGetInstanceHandle(), szuf, 255); strAppPath = szuf; int nPos = strAppPath.ReverseFind('\\'); if(nPos > -1) strAppPath = strAppPath.Left(nPos); return strAppPath; } __declspec(dllexport) void FreeObList(CObList &obList)//清除obList内的对象 { AFX_MANAGE_STATE(AfxGetStaticModuleState()); while(obList.GetCount() > 0) delete obList.RemoveHead(); } __declspec(dllexport) CString EncodeString(CString strOld, BYTE cKey)//字符串加密 { AFX_MANAGE_STATE(AfxGetStaticModuleState()); cKey = min(30, cKey);//异或操作后保证还是字符串,则键值必须小于30,以便不影响高位的值 CString strRtn = strOld; int nLen = strOld.GetLength(); for(int i = 0; i < nLen; i++) { strRtn.SetAt(nLen-1-i, strOld.GetAt(i)^cKey); } return strRtn; } __declspec(dllexport) BYTE TwoByteToByte(BYTE b1, BYTE b2)//两个字符转换为一个字符 { AFX_MANAGE_STATE(AfxGetStaticModuleState()); BYTE b = 0; if(b1 >= 'A' && b1 <= 'F') b += (b1 - 'A' + 10)*16; else if(b1 >= 'a' && b1 <= 'f') b += (b1 - 'a' + 10)*16; else b += (b1 - '0')*16; if(b2 >= 'A' && b2 <= 'F') b += b2 - 'A' + 10; else if(b2 >= 'a' && b2 <= 'f') b += b2 - 'a' + 10; else b += b2 - '0'; return b; } __declspec(dllexport) void ByteToTwoByte(BYTE b, BYTE b2[])//一个字符转换为两个字符 { AFX_MANAGE_STATE(AfxGetStaticModuleState()); char szBuf[3]; int nData = b; sprintf(szBuf, "%02X", nData); memcpy(b2, szBuf, 2); } #define CPH 0 #define CPL 1 static unsigned char tbcrch[] = { 0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64, 1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65, 1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65, 0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64, 1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65, 0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64, 0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64, 1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65, 1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65, 0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64, 0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64, 1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65, 0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64, 1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65, 1,192,128,65,0,193,129,64,0,193,129,64,1,192,128,65, 0,193,129,64,1,192,128,65,1,192,128,65,0,193,129,64,}; static unsigned char tbcrcl[] = { 0,192,193,1,195,3,2,194,198,6,7,199,5,197,196,4, 204,12,13,205,15,207,206,14,10,202,203,11,201,9,8,200, 216,24,25,217,27,219,218,26,30,222,223,31,221,29,28,220, 20,212,213,21,215,23,22,214,210,18,19,211,17,209,208,16, 240,48,49,241,51,243,242,50,54,246,247,55,245,53,52,244, 60,252,253,61,255,63,62,254,250,58,59,251,57,249,248,56, 40,232,233,41,235,43,42,234,238,46,47,239,45,237,236,44, 228,36,37,229,39,231,230,38,34,226,227,35,225,33,32,224, 160,96,97,161,99,163,162,98,102,166,167,103,165,101,100,164, 108,172,173,109,175,111,110,174,170,106,107,171,105,169,168,104, 120,184,185,121,187,123,122,186,190,126,127,191,125,189,188,124, 180,116,117,181,119,183,182,118,114,178,179,115,177,113,112,176, 80,144,145,81,147,83,82,146,150,86,87,151,85,149,148,84, 156,92,93,157,95,159,158,94,90,154,155,91,153,89,88,152, 136,72,73,137,75,139,138,74,78,142,143,79,141,77,76,140, 68,132,133,69,135,71,70,134,130,66,67,131,65,129,128,64,}; /******************************************************************** * NAME : TwoHexCharToChar * FUNCTION : * PROCESS : * INPUT : * OUTPUT : * UPDATE : * RETURN : * : * PROGRAMMED : * DATE(ORG) : * CALL : * SYSTEM : ********************************************************************/ __declspec(dllexport) char TwoHexCharToChar(char ch1,char ch2) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); char Numb1; char Numb2; if (ch1 >= 'A') { Numb1 = (toupper(ch1)-'0'-7)*16; } else { Numb1 = (ch1 - '0')*16; } if (ch2 >= 'A') { Numb2 = (toupper(ch2) - '0' - 7); } else { Numb2 = (ch2 - '0'); } return (Numb1 + Numb2); } /******************************************************************** * NAME : Str2HexStr * FUNCTION : * PROCESS : * INPUT : * OUTPUT : * UPDATE : * RETURN : * : * PROGRAMMED : * DATE(ORG) : * CALL : * SYSTEM : ********************************************************************/ __declspec(dllexport) void Str2HexStr(char *szHexString,char *szString,int *iHexStringLen) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); int iLoop; int iCount; iLoop = 0; iCount = 0; szHexString[0] = '\0'; while(1) { if (szString[iLoop] == '\0' || szString[iLoop + 1] == '\0') { break; } szHexString[iCount] = (char)TwoHexCharToChar(szString[iLoop ], szString[iLoop + 1]); iLoop ++; iLoop ++; iCount ++; } szHexString[iCount] = '\0'; *iHexStringLen = iCount; } /******************************************************************** * NAME : GetCRC * FUNCTION : * PROCESS : * INPUT : * OUTPUT : * UPDATE : * RETURN : * : * PROGRAMMED : * DATE(ORG) : * CALL : * SYSTEM : ********************************************************************/ __declspec(dllexport) void GetCRC(char *CRC_char1,char *CRC_char2,char *szString,int iStrLen) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); WORD i; WORD j; union { WORD ival; unsigned char cval[2]; } crcal; crcal.ival = 0xFFFF; i = 0; while ( i < iStrLen) { j = (WORD)((szString[i] ^ crcal.cval[CPH]) & 0x00FF); crcal.cval[CPH] = tbcrch[j] ^ crcal.cval[CPL]; crcal.cval[CPL] = tbcrcl[j]; i ++; } *CRC_char1 = crcal.cval[CPH]; *CRC_char2 = crcal.cval[CPL]; } /******************************************************************** * NAME : AddCRC * FUNCTION : * PROCESS : * INPUT : * OUTPUT : * UPDATE : * RETURN : * : * PROGRAMMED : * DATE(ORG) : * CALL : * SYSTEM : ********************************************************************/ __declspec(dllexport) void AddCRC(char *szBuffer, int iLen) /* the szBuffer length, this means the szBuffer[iLen] is error data, perhaps szBuffer[iLen-1] != 0; also perhaps szBuffer[iLen] != 0; */ { AFX_MANAGE_STATE(AfxGetStaticModuleState()); char crc_ch1; char crc_ch2; GetCRC(&crc_ch1,&crc_ch2,szBuffer,iLen); szBuffer[iLen] = crc_ch1; szBuffer[iLen + 1] = crc_ch2; } /******************************************************************** * NAME : CheckCRC * FUNCTION : * PROCESS : * INPUT : * OUTPUT : * UPDATE : * RETURN : * : * PROGRAMMED : * DATE(ORG) : * CALL : * SYSTEM : ********************************************************************/ __declspec(dllexport) BOOL CheckCRC (char *szString,int iStrLen) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); char crc_ch1; char crc_ch2; GetCRC(&crc_ch1,&crc_ch2,szString,iStrLen-2); if (szString[iStrLen - 2] != crc_ch1) { return FALSE; } if (szString[iStrLen - 1] != crc_ch2) { return FALSE; } return TRUE; } __declspec(dllexport) int StrToInt(CString strTxt) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); int nRtn = 0; if(strTxt.Find('H') != -1) { strTxt.Replace("0X", ""); strTxt.Replace("0x", ""); int nLenStr = strTxt.GetLength(); for(int i = 0; i < nLenStr-1; i+=2) { nRtn = nRtn*256+ TwoByteToByte(strTxt.GetAt(i), strTxt.GetAt(i+1)); } } else nRtn = atoi(strTxt); return nRtn; } inline void RemoveOldData() { COleDateTime timeNow = COleDateTime::GetCurrentTime(); static int nLastCheckMonth = timeNow.GetMonth(); if(timeNow.GetMonth() != nLastCheckMonth) { nLastCheckMonth = timeNow.GetMonth(); COleDateTime timeTwoYearAgo = timeNow - COleDateTimeSpan(365*2, 0, 0, 0); CString strDir = GetPrjPath() + "\\Curve\\" + timeTwoYearAgo.Format("%Y%m"); MyDeleteDirectory(strDir); strDir = GetPrjPath() + "\\Curve\\HourCur" + timeTwoYearAgo.Format("%Y"); MyDeleteDirectory(strDir); } } inline void SaveCurve(CDataNodeBase* pSpot, CString strTxtValue, BOOL bStatusChanged) { #define CurLastValue "CLV" #define CurLastTime "CLT" #define CurLastDay "CLD" #define CurLastHour "CLH" #define INIT_VALUE 0.00020041005f RemoveOldData(); CString strRecCurve; if(pSpot->V_GetPropertyTxtValue("RecCurve", strRecCurve) && strRecCurve == "1") { CString strCurLastValue; pSpot->GetTempItem(CurLastValue, strCurLastValue); CString strDeadBand; pSpot->V_GetPropertyTxtValue("DeadBand", strDeadBand); double dDeadBand = atof(strDeadBand); if(dDeadBand < 0.000001) dDeadBand = 0.1; COleDateTime timeNow = COleDateTime::GetCurrentTime(); // long lTimeNow = timeNow.GetTime(); CString strCurLastHour = "-1"; pSpot->GetTempItem(CurLastHour, strCurLastHour); int nLastHour = atoi(strCurLastHour); //== CString strThisDay = timeNow.Format("%d"); CString strLastDay; pSpot->GetTempItem(CurLastDay, strLastDay); if(bStatusChanged //状态变化 || dDeadBand < fabs(atof(strTxtValue) - atof(strCurLastValue)) //或值超过死区 || timeNow.GetHour() != nLastHour //或小时变更 || strLastDay != strThisDay // 日期变更 || strCurLastValue == "" //初始值 ) { BOOL bOK = FALSE; float fValue = (float)atof(strTxtValue); { //存实时数据,每点每天一个文件,数据格式为HHMMVVVV CString strPathName = GetPrjPath() + "\\Curve\\" + timeNow.Format("%Y%m\\%d"); CString strFileName = strPathName + "\\" + pSpot->GetIdPath() + "cur"; CFile fileCurve; __int32 nTime = atoi(timeNow.Format("%H%M%S")); for(int i = 0; i < 2; i++) { CFileException e; if(fileCurve.Open(strFileName, CFile::modeCreate|CFile::modeNoTruncate|CFile::shareDenyWrite|CFile::modeWrite, &e)) { fileCurve.SeekToEnd(); try { fileCurve.Write(&nTime, sizeof(__int32)); fileCurve.Write(&fValue, sizeof(float)); bOK = TRUE; } catch (...) { } fileCurve.Close(); break; } else if(e.m_cause == CFileException::badPath) { MyCreateDirectory(strPathName); } else { break; } } } if(timeNow.GetHour() != nLastHour) { //存小时曲线数据,每年一个文件,每小时一个点,只在相对位置存数据,不存时间 CString strPathName = GetPrjPath() + "\\Curve\\" + timeNow.Format("HourCur%Y"); CString strFileName = strPathName + "\\" + pSpot->GetIdPath() + "cur"; CFile fileCurve; for(int i = 0; i < 2; i++) { CFileException e; if(fileCurve.Open(strFileName, CFile::modeCreate|CFile::modeNoTruncate|CFile::shareDenyWrite|CFile::modeWrite, &e)) { if(fileCurve.GetLength() == 0) { float fV = INIT_VALUE; for(int i = 0; i < 24*366; i++) { fileCurve.Write(&fV, sizeof(fV)); } } COleDateTime timeThisYear(timeNow.GetYear(), 1, 1, 0, 0, 0); COleDateTimeSpan timeSpan = timeNow - timeThisYear; int nOffset = (int)sizeof(float)*((int)timeSpan.GetTotalHours()); fileCurve.Seek(nOffset, CFile::begin); try { fileCurve.Write(&fValue, sizeof(float)); bOK = TRUE; } catch (...) { } fileCurve.Close(); break; } else if(e.m_cause == CFileException::badPath) { MyCreateDirectory(strPathName); } else { break; } } pSpot->SetTempItem(CurLastHour, GetText(timeNow.GetHour())); } if(bOK) { pSpot->SetTempItem(CurLastValue, strTxtValue); pSpot->SetTempItem(CurLastDay, strThisDay); } } } } //给采集点赋值,该函数负责产生各种可能的事件 __declspec(dllexport) void SetSpotTextValue(CDataNodeBase* pDevive, CDataNodeBase* pSpot, CString strTxtValue) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strTemp; CString strCurveValue = strTxtValue;//保留原始设置值,用于存曲线数据 pSpot->V_SetPropertyTxtValue("GetValue", strTxtValue, TRUE, 0); //线性转换: static BOOL g_DemoVersion = GetPrivateProfileInt("PowerDevice", "Demo", 0, "DataCenter.ini"); if(!g_DemoVersion) { CString strPMax, strPMin, strGMax, strGMin; if(pSpot->V_GetPropertyTxtValue("PS_GMax", strGMax) && pSpot->V_GetPropertyTxtValue("PS_GMin", strGMin) && pSpot->V_GetPropertyTxtValue("PS_PMax", strPMax) && pSpot->V_GetPropertyTxtValue("PS_PMin", strPMin) ) { float fPMax = (float)atof(strPMax); float fPMin = (float)atof(strPMin); float fGMax = (float)atof(strGMax); float fGMin = (float)atof(strGMin); if(fGMax != fGMin) { float fRes = (float)((fPMax-fPMin)/(fGMax-fGMin)*(atof(strTxtValue) - fGMin) + fPMin); strTxtValue.Format("%g", fRes); strCurveValue = strTxtValue; } } } //上下限判断 UINT uStatusChange = SYSTEM_OK; UINT uStatusCur = SYSTEM_OK; UINT uStatusLast = SYSTEM_OK; if(pSpot->GetTempItem("LastStatus", strTemp)) { uStatusLast = atoi(strTemp); uStatusCur = uStatusLast; } //???? don't delete thease lines: #ifndef DEMO_VERSION if(!Loadlmage(NULL)) { static BOOL bErrorShowed = FALSE; if(!bErrorShowed) { bErrorShowed = TRUE; AfxMessageBox("软件已过期,部分功能将无法正常运行,请注册后再运行(将“主菜单->帮助->软件注册”里边的用户代码发送到软件供应商获取注册码)!"); } static int nIncrease = 0; WORD wStop = *(&nIncrease); wStop++; wStop = (WORD)(DWORD)&theApp; wStop = wStop + (BYTE)(DWORD)(LPVOID)(&nIncrease); return; } #else static COleDateTime timeStart = COleDateTime::GetCurrentTime(); COleDateTime timeNow = COleDateTime::GetCurrentTime(); COleDateTimeSpan span = timeNow - timeStart; if(fabs(span.GetTotalHours()) > 24) { static BOOL bShowMsg = FALSE; if(!bShowMsg) { bShowMsg = TRUE; //CLanguage::ShowMessageBox("演示停止!"); } return; } #endif CString strLevelName = "Level"; CString strEvent; CString strPrefix; CString strLastValueRollBack; if(pSpot->V_GetPropertyTxtValue("PS_CasePrefix", strPrefix)) { CString strLastValue; BOOL bIsFirstData = FALSE; if(pSpot->GetTempItem("LastValue", strLastValue)) { if(strLastValue != strTxtValue) { uStatusChange = COMMON_EVENT;//不是第一次启动且状态值发生变化时需要发出事件 uStatusCur = SYSTEM_OK; strEvent = strTxtValue; strLastValueRollBack = strLastValue; pSpot->SetTempItem("LastValue", strTxtValue); } //else //{ //} } else { pSpot->SetTempItem("LastValue", strTxtValue); bIsFirstData = TRUE; } CDataNodeBase* pGetCase = pSpot; if(strPrefix.Find("PD_") == 0) pGetCase = pDevive; // else if(strPrefix.Find("PR_") == 0) // pGetCase = pGroup; // else if(strPrefix.Find("PC_") == 0) // pGetCase = pCase; //value // pSpot->V_SetPropertyTxtValue("GetValue", strTxtValue, TRUE, 0); CString strCase = strPrefix + strTxtValue; CString strCase01 = strPrefix + ((atoi(strTxtValue) == 0)?"0":"1"); CString strTemp; if(pGetCase->V_GetPropertyTxtValue(strCase, strTemp) || pGetCase->V_GetPropertyTxtValue(strCase01, strTemp)) { if(strTemp.Find("Alarm:") == 0)// || strTemp.Find("报警") == 0) { if(bIsFirstData || uStatusChange!=SYSTEM_OK) uStatusChange = ALARM_EVENT; uStatusCur = ALARM_EVENT; } else uStatusCur = SYSTEM_OK; int nPos = strTemp.Find(':'); if(nPos != -1) strTemp = strTemp.Mid(nPos+1); strTxtValue = strTemp; strEvent = strTemp; } } else { strTxtValue = GetDoubleText(atof(strTxtValue)); float fCur = (float)atof(strTxtValue); CString strLastValue = "Normal";//N:Normal, U:UpperAlarm, L:LowAlarm; BOOL bInitData = !pSpot->GetTempItem("LastValue", strLastValue); strLastValueRollBack = strLastValue; float fLast = (float)atof(strLastValue); float fDeadBand = (float)atof(pSpot->GetProperty1("DeadBand")); CString strU; if(pSpot->GetProperty("LimitUpper", strU)) { float fUpper = (float)atof(strU); CString strU2; float fUpper2 = fUpper; if(pSpot->GetProperty("LimitUpper2", strU2)) { fUpper2 = (float)atof(strU2); if(strLastValue.Find('u') != 0 && fCur > fUpper2) { strLastValue = "upper Upper Alarm"; if(GetTempVar(TEMP_VAR_ATTACH_LIMITE_SETTING, strTemp) && atoi(strTemp)!=0) {//补加范围设定: strLastValue += ", (LimitUpper2=" + strU2 + ")"; } strLevelName = "Level2"; uStatusChange = ALARM_EVENT; uStatusCur = ALARM_EVENT; } } if(strLastValue.Find('U') != 0 && strLastValue.Find('u') != 0 && fCur > fUpper) { strLastValue = "Upper Alarm"; if(GetTempVar(TEMP_VAR_ATTACH_LIMITE_SETTING, strTemp) && atoi(strTemp)!=0) {//补加范围设定: strLastValue += ", (LimitUpper=" + strU + ")"; } uStatusChange = ALARM_EVENT; uStatusCur = ALARM_EVENT; } else if((strLastValue.Find('U') == 0 || strLastValue.Find('u') == 0) && fCur < fUpper - fDeadBand && fCur < fUpper2 - fDeadBand) { if(!bInitData && strLastValue.Find('N') != 0) uStatusChange = COMMON_EVENT; strLastValue = "Normal"; uStatusCur = SYSTEM_OK; } } else { if(!bInitData && strLastValue.Find('U') == 0) { uStatusChange = COMMON_EVENT; strLastValue = "Normal"; uStatusCur = SYSTEM_OK; } } if(uStatusChange != ALARM_EVENT) { CString strL; if(pSpot->GetProperty("LimitLower", strL)) { float fLow = (float)atof(strL); CString strL2; float fLow2 = fLow; if(pSpot->GetProperty("LimitLower2", strL2)) { fLow2 = (float)atof(strL2); if(strLastValue.Find('l') != 0 && fCur < fLow2) { strLastValue = "low Low Alarm"; if(GetTempVar(TEMP_VAR_ATTACH_LIMITE_SETTING, strTemp) && atoi(strTemp)!=0) {//补加范围设定: strLastValue += ", (LimitLower2=" + strL2 + ")"; } strLevelName = "Level2"; uStatusChange = ALARM_EVENT; uStatusCur = ALARM_EVENT; } } if(strLastValue.Find('L') != 0 && strLastValue.Find('l') != 0 && fCur < fLow) { strLastValue = "Low Alarm"; if(GetTempVar(TEMP_VAR_ATTACH_LIMITE_SETTING, strTemp) && atoi(strTemp)!=0) {//补加范围设定: strLastValue += ", (LimitLower=" + strL + ")"; } uStatusChange = ALARM_EVENT; uStatusCur = ALARM_EVENT; } else if((strLastValue.Find('L') == 0 || strLastValue.Find('l') == 0) && fCur > fLow + fDeadBand && fCur > fLow2 + fDeadBand) { if(!bInitData && strLastValue.Find('N') != 0) uStatusChange = COMMON_EVENT; strLastValue = "Normal"; uStatusCur = SYSTEM_OK; } } else { if(!bInitData && strLastValue.Find('L') == 0) { uStatusChange = COMMON_EVENT; strLastValue = "Normal"; uStatusCur = SYSTEM_OK; } } } pSpot->SetTempItem("LastValue", strLastValue); strEvent = CLanguage::GetCurLanguage(strLastValue) + ", " + CLanguage::GetCurLanguage("Current value is ") + strTxtValue; } //增加对报警事件的缓冲。2007-02-26。 BOOL bDataIsValid = TRUE; if(uStatusChange != SYSTEM_OK) { int nAlarmDelay = atoi(pSpot->GetProperty1("AlarmDelay")); if(nAlarmDelay > 0) { CString strOnEventCount; pSpot->GetTempItem("OnEventCount", strOnEventCount); int nOnEventCount = atoi(strOnEventCount); if(nOnEventCount >= nAlarmDelay || strOnEventCount == "") { bDataIsValid = TRUE; strOnEventCount = "0"; } else { bDataIsValid = FALSE; nOnEventCount++; strOnEventCount.Format("%d", nOnEventCount); pSpot->SetTempItem("LastValue", strLastValueRollBack);//回滚最后值的设置 } pSpot->SetTempItem("OnEventCount", strOnEventCount); } } if(bDataIsValid) { //value pSpot->V_SetPropertyTxtValue("Value", strTxtValue, TRUE, 0); //status if(uStatusCur != uStatusLast) { strTemp.Format("%d", uStatusCur); pSpot->SetTempItem("LastStatus", strTemp); } CString strStatus; strStatus.Format("%d", uStatusCur); pSpot->V_SetPropertyTxtValue("Status", strStatus, TRUE, 0); pSpot->SetTempItem("Picked", "");//数据使用过标记复位,表示数据已经刷新 // CString strName; // if(pSpot->V_GetPropertyTxtValue("Name", strName)) // { // pDevive->V_SetPropertyTxtValue(strName, strTxtValue, TRUE, 0); // } if(uStatusChange != SYSTEM_OK) pSpot->SetTempItem("ADC", "0");//ALDC: Alarm Delay Count else if(uStatusCur == ALARM_EVENT) {//重复报警: CString strRepeatAlarmDelay; //CString strRepeatAlarmLevel; if(pSpot->V_GetPropertyTxtValue("RepeatAlarmDelay", strRepeatAlarmDelay)) { CString strDelayCount; pSpot->GetTempItem("ADC", strDelayCount);//ALDC: Alarm Delay Count int nDelayCount = atoi(strDelayCount); int nRepeatAlarmDelay = atoi(strRepeatAlarmDelay); if(nDelayCount <= nRepeatAlarmDelay) { if(nDelayCount == nRepeatAlarmDelay) { uStatusChange = ALARM_EVENT; strLevelName = "RepeatAlarmLevel"; } nDelayCount++; strDelayCount.Format("%d", nDelayCount); pSpot->SetTempItem("ADC", strDelayCount); } } } //发出报警: if(uStatusChange != SYSTEM_OK) { //CStringList strParams; //"Event_Description", //strParams.AddTail(strEvent); //"Event_Level" CString strLevel = "1"; if(strLevelName == "Level2") { if(!pSpot->V_GetPropertyTxtValue("Level2", strLevel)) { pSpot->V_GetPropertyTxtValue("Level", strLevel); //strLevel.Format("%d", min(10, atoi(strLevel)+2)); } } else if(strLevelName == "RepeatAlarmLevel") { if(!pSpot->V_GetPropertyTxtValue("RepeatAlarmLevel", strLevel)) { pSpot->V_GetPropertyTxtValue("Level", strLevel); int nLevel = atoi(strLevel) + 3; nLevel = min(10, nLevel); strLevel.Format("%d", nLevel); } } else pSpot->V_GetPropertyTxtValue("Level", strLevel); if(atoi(strLevel) > 0) { //strParams.AddTail(strLevel); //"Event_Time" //COleDateTime timeNow = COleDateTime::GetCurrentTime(); //strParams.AddTail(timeNow.Format("%Y-%m-%d %H:%M:%S")); //"Event_Status" strStatus.Format("%d", uStatusChange); //strParams.AddTail(strStatus); //处理者签名,已经对这个事件作了处理则不再处理,避免形成环路 //strParams.AddTail(""); //CStringList strReturns; //底层方式 //pSpot->AnyUpCall("", "", "Event", strParams, strReturns); //封装方式 ReportNewEvent(pSpot, strEvent, atoi(strLevel), atoi(strStatus)); } } SaveCurve(pSpot, strCurveValue, uStatusCur != uStatusLast); } } __declspec(dllexport) CString MyGetPrivateProfileString(CString strApp, CString strKey, CString strDefault, CString strIni) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); char szBuf[MAX_PATH] = {0}; GetPrivateProfileString(strApp, strKey, strDefault, szBuf, MAX_PATH-1, strIni); return szBuf; } __declspec(dllexport) void MyWritePrivateProfileInt(CString strApp, CString strKey, int nVal, CString strIni) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CString strTemp; strTemp.Format("%u", nVal); WritePrivateProfileString(strApp, strKey, strTemp, strIni); } //将路径加入到环境变量Path中 __declspec(dllexport) void AddPathToEnvirPath(CString strNewPath) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); char szPath[1024]; GetEnvironmentVariable("Path", szPath, 1023); CString strPath = CString(szPath) + ";"; strPath.MakeUpper(); CString strTemp = strNewPath + ";"; strTemp.MakeUpper(); int nPos = strPath.Find(strTemp); if(nPos == -1) { strPath = CString(szPath) + ";" + strNewPath; SetEnvironmentVariable("Path", strPath); } } //向文本文件中追加文本 __declspec(dllexport) BOOL AppendStringToFile(CString strMsg, CString strFile) { BOOL bOK = FALSE; CStdioFile file; try { if(file.Open(strFile, CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite|CFile::typeBinary)) { file.SeekToEnd(); file.WriteString(strMsg); file.Close(); bOK = TRUE; } } catch (...) { } return bOK; } //找到指定的字符串,但必须排除有控制符号'\'的情况 __declspec(dllexport) int MyStrFind(CString strSource, CString strSub, int nStartPos) { int nRtn = strSource.Find(strSub, nStartPos); int nPos = nRtn; if(nPos >= 1) { while (nPos > 0) { if(strSource.GetAt(nPos-1) == '\\') { nPos = strSource.Find(strSub, nPos+1); } else { break; } } nRtn = nPos; } return nRtn; } //找到指定的字符,但必须排除有前导符号'\'的情况 __declspec(dllexport) int MyStrFind(CString strSource, char cSub, int nStartPos) { int nRtn = strSource.Find(cSub, nStartPos); int nPos = nRtn; if(nPos >= 1) { while (nPos > 0) { if(strSource.GetAt(nPos-1) == '\\') { nPos = strSource.Find(cSub, nPos+1); } else { break; } } nRtn = nPos; } return nRtn; } //获取原始字符串,去除控制符号'\' __declspec(dllexport) CString GetOrigStr(CString strSaved) { CString strRtn = strSaved; int nPos = strRtn.Find('\\'); if(nPos >= 0) { int nLen = strRtn.GetLength(); for(int i = 0; i < nLen; i++) { if(strRtn.GetAt(i) == '\\') { strRtn = strRtn.Left(i) + strRtn.Mid(i+1); nLen = strRtn.GetLength(); } } } return strRtn; } //获取保存字符串,对于需要添加控制符号的自动追加控制符号 __declspec(dllexport) CString GetSavedStr(CString strOrig) { int nLen = strOrig.GetLength(); CString strRtn = strOrig; for(int i = 0; i < nLen; i++) { char c = strRtn.GetAt(i); if(c == '"' || c == '<' || c == '>' || c == '=' || c == '\\') { strRtn = strRtn.Left(i) + "\\" + strRtn.Mid(i); nLen++;//增加了一个字节,长度参数也要 i++; } } return strRtn; } //获取某文件夹的父文件夹 __declspec(dllexport) CString GetParentDir(CString strDir) { //先去掉多余的斜杠,其中网络路径的首部为两个斜杠:\\,因此在去掉斜杠时需保证不会去掉最开头的网络路径的两个斜杠的情况 CString strDirParent = strDir; if(strDir.GetLength() > 0) { strDirParent = strDir.Mid(1); char c1 = strDir.GetAt(0); while(strDirParent.Replace("\\\\", "\\")) ; while(strDirParent.Replace('/', '\\')) ; strDirParent = CString(c1) + strDirParent; //去掉最后一个斜杠: if(strDirParent.GetAt(strDirParent.GetLength()-1) == '\\') strDirParent = strDirParent.Left(strDirParent.GetLength()-1); int nPos = strDirParent.ReverseFind('\\'); if(nPos != -1) strDirParent = strDirParent.Left(nPos); } return strDirParent; } //获取某节点的报警错误页面 __declspec(dllexport) BOOL GetRelatePage(CDataNodeBase* pNode, CString& strRelatePage, CString& strUidReq, CString& strIP) { strRelatePage = pNode->GetProperty1("RelatePage"); CString strPathName; CString strTemp = strRelatePage; strTemp.MakeLower(); int nPos = strTemp.Find('?'); if(nPos != -1) strTemp = strTemp.Left(nPos); if(strTemp.Find("/topsoft/") == 0) { strTemp = strTemp.Mid(strlen("/Topsoft/")); strPathName = GetParentDir(GetAppPath()) + "/" + strTemp; } else { if(strTemp.Find("/yzd/") == 0) strTemp = strTemp.Mid(strlen("/yzd/")); static CString strPage = CString("/") + GetMapDir("Page") + CString("/"); strPathName = GetPrjPath() + strPage + strTemp; } CFileFind aspFind; if(!aspFind.FindFile(strPathName)) { strRelatePage = "/Topsoft/StdPages/CommTemp.asp"; } aspFind.Close(); strUidReq = pNode->GetIdPath(); CDataNodeBase* pMgr = GetRelatePageGroupNode(pNode);//pNode->GetRelateManagerNode(); if(pMgr) strUidReq = pMgr->GetIdPath(); if(pMgr->PV_IsManagerNode() == NET_LINK_MANAGER_NODE) pMgr->V_GetPropertyTxtValue("IP", strIP); return TRUE; } //汇报一个新的事件 __declspec(dllexport) void ReportNewEvent(CDataNodeBase* pNode, CString strMsg, int nLevel, int nStatus) { if(nLevel <= 0) return; //处理屏蔽 CString strLevel = GetText(nLevel); // CString strLevel1, strLevel2; // //pNode->V_GetPropertyTxtValue("Level", strLevel1); // pNode->V_GetPropertyTxtValue("Level2", strLevel2); // if(pNode->V_GetPropertyTxtValue("Level", strLevel1) && // strLevel != strLevel1 && strLevel != strLevel2) // strLevel = strLevel1; // CString strSpotType; // pNode->V_GetPropertyTxtValue("PS_SpotType", strSpotType); // if(strSpotType == "Digit") // { CString strIgnoreAlarm; if(nStatus == ALARM_EVENT && pNode->V_GetPropertyTxtValue("IgnoreAlarm", strIgnoreAlarm) && atoi(strIgnoreAlarm) != 0) { int nLevelI = min(atoi(strLevel)-3, 2); nLevelI = max(nLevelI, 1); strLevel.Format("%d", nLevelI); } CString strIgnoreRecover; if(nStatus == COMMON_EVENT && pNode->V_GetPropertyTxtValue("IgnoreRecover", strIgnoreRecover) && atoi(strIgnoreRecover) != 0) { int nLevelI = min(atoi(strLevel)-3, 2); nLevelI = max(nLevelI, 1); strLevel.Format("%d", nLevelI); } // } // else if(strSpotType == "Analog") // { // CString strLastValue = "Normal";//N:Normal, U:UpperAlarm, L:LowAlarm; // BOOL bInitData = !pNode->GetTempItem("LastValue", strLastValue); // } EventRaiseAction(pNode, nStatus); CString strEventMsg = CLanguage::GetCurLanguage(strMsg); CStringList strParams; //"Event_Description", strParams.AddTail(strEventMsg); //"Event_Level" strParams.AddTail(strLevel); //"Event_Time" COleDateTime timeNow = COleDateTime::GetCurrentTime(); strParams.AddTail(timeNow.Format("%Y-%m-%d %H:%M:%S")); //"Event_Status" CString strStatus = GetText(nStatus); strParams.AddTail(strStatus); //处理者签名,已经对这个事件作了处理则不再处理,避免形成环路 strParams.AddTail(""); //报警错误页面及查询ID和所在的IP: CString strRelatePage; CString strUidReq; CString strIP; GetRelatePage(pNode, strRelatePage, strUidReq, strIP); strParams.AddTail(strRelatePage); strParams.AddTail(strUidReq); strParams.AddTail(strIP); CStringList strReturns; pNode->AnyUpCall("", "", "Event", strParams, strReturns); } //事件联动触发动作 __declspec(dllexport) void EventRaiseAction(CDataNodeBase* pNode, int nStatus) { CString strActDll; int nNo = 1; while(pNode->V_GetPropertyTxtValue("PS_ActDll" + GetText(nNo), strActDll) && strActDll != "") { CEventRaiseActionMgr* pMgr = CEventRaiseActionMgr::GetRaiseActDll(strActDll); pMgr->EventRaiseActionBase(pNode, nStatus); nNo++; } } //调试输出窗体 static FILE* __fStdOut = NULL; static HANDLE __hStdOut = NULL; void StartConsoleWin() {//创建一个Console窗口,指明宽度和高度,如果fname不为空则同时将输出写入一个文件。 if(__hStdOut == NULL) { int width = 80; int height = 24; char fname[] = {"C:\\MyDebugWnd.Txt"}; AllocConsole();//分配 SetConsoleTitle("Debug Window"); __hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);//指明句柄为标准输出HANDLE COORD co = {width,height}; SetConsoleScreenBufferSize(__hStdOut, co);//指明缓冲区大小 __fStdOut = fopen(fname, "w"); } } // Use wprintf like TRACE0, TRACE1, ... (The arguments are the same as printf) __declspec(dllexport) void MyDebugOutput(const char *fmt, ...) {//类似于printf的函数,向Console写入文本 StartConsoleWin(); va_list argptr; va_start(argptr, fmt); CString strOut; strOut.FormatV(fmt, argptr); va_end(argptr); DWORD cCharsWritten; if(__hStdOut)// 写Console WriteConsole(__hStdOut, strOut, strOut.GetLength(), &cCharsWritten, NULL); if(__fStdOut) { fprintf(__fStdOut, strOut); fflush(__fStdOut); } } //Power Function __declspec(dllexport) BOOL PowerFunc(CString strFunc, CString &strExchange) { BOOL bRtn = FALSE; if(strFunc == "!@#$") { char szTemp[256]; strcpy(szTemp, strExchange); bRtn = WriteSting(szTemp); } else if(strFunc == "|+_)") { char szTemp[256]; strcpy(szTemp, strExchange); Loadlcon(szTemp); strExchange = szTemp; } else if(strFunc == "@#$%") { bRtn = ReadSting(NULL); } return bRtn; } //=========================================================================== //自动化专用 enum COMMAND { CMD_REQ=1, CMD_ANSWER=2, CMD_REQ_RIGHT=3, CMD_FEEDBACK_RIGHT=4, CMD_TO_SET=5,//普通模式的设置命令 CMD_EVENT=6, CMD_NOT_EXIST=7,//查询的属性不存在 CMD_TO_SET_AUTO=8,//自动化模式下的设置,此模式下设置失败不弹消息框 }; static CString g_strAutoProcUser; static UINT g_nAutoProcFlag = CMD_TO_SET;//CMD_TO_SET : 普通模式的设置命令 //自动化程序使用的帐号 __declspec(dllexport) BOOL GetAutoProcUser(CString &strUser, UINT &nFlag) { strUser = g_strAutoProcUser; nFlag = g_nAutoProcFlag; return (g_nAutoProcFlag == CMD_TO_SET_AUTO); } __declspec(dllexport) void SetAutoProcUser(CString strUser) { g_strAutoProcUser = strUser; if(strUser.GetLength() > 0) g_nAutoProcFlag = CMD_TO_SET_AUTO; } //=========================================================================== //自动化专用 //获取字符串中用分号隔开的子字符串 __declspec(dllexport) CString GetSubString(CString strSource, CString strItem) { CString strRtn; int nPos = strSource.Find(strItem + "="); int nPos1 = strSource.Find(";" + strItem + "="); if(nPos1 != -1) nPos = nPos1+1; if(nPos != -1) { strRtn = strSource.Mid(nPos+strItem.GetLength()+1); nPos = strRtn.Find(';'); if(nPos != -1) strRtn = strRtn.Left(nPos); } return strRtn; } //记载出错信息 __declspec(dllexport) void WriteErrorMsg(CString strErrorMsg) { MyTRACE(strErrorMsg + "\n"); } //获取对象的属性的C接口 __declspec(dllexport) int GetItemProperty(LPVOID pDataNodeBase, const char* szItem, char* szValue, int nLen) { int nLenRtn = 0; CString strValue; try { CDataNodeBase* pObj = (CDataNodeBase*)pDataNodeBase; if(pObj->GetProperty(szItem, strValue)) { nLenRtn = strValue.GetLength() + 1; if(nLen >= nLenRtn) strcpy(szValue, strValue); } } catch (...) { } return nLenRtn; } //设置对象的属性的C接口 __declspec(dllexport) BOOL SetItemProperty(LPVOID pDataNodeBase, const char* szItem, const char* szValue) { BOOL bOK = FALSE; try { CDataNodeBase* pObj = (CDataNodeBase*)pDataNodeBase; CString strValue = szValue; bOK = pObj->SetProperty(szItem, strValue, TRUE, ATTR_NEET_SET_MODIFY_FLAG|ATTR_MANUAL_SET_VALUE); } catch (...) { } return bOK; } //获取对象的属性的C接口 __declspec(dllexport) int V_GetItemProperty(LPVOID pDataNodeBase, const char* szItem, char* szValue, int nLen) { int nLenRtn = 0; CString strValue; try { CDataNodeBase* pObj = (CDataNodeBase*)pDataNodeBase; if(pObj->V_GetPropertyTxtValue(szItem, strValue)) { nLenRtn = strValue.GetLength() + 1; if(nLen >= nLenRtn) strcpy(szValue, strValue); } } catch (...) { } return nLenRtn; } //设置对象的属性的C接口 __declspec(dllexport) BOOL V_SetItemProperty(LPVOID pDataNodeBase, const char* szItem, const char* szValue) { BOOL bOK = FALSE; try { CDataNodeBase* pObj = (CDataNodeBase*)pDataNodeBase; CString strValue = szValue; bOK = pObj->V_SetPropertyTxtValue(szItem, strValue, TRUE, ATTR_NEET_SET_MODIFY_FLAG|ATTR_MANUAL_SET_VALUE); } catch (...) { } return bOK; } //返回DataManager.dll是否为Release版本 __declspec(dllexport) BOOL DataManagerIsReleaseVersion() { #ifndef _DEBUG return TRUE; #else return FALSE; #endif } //设置数据精度 __declspec(dllexport) int SetPrecision(int p) { int nLP = g_nPrecision; g_nPrecision = p; return nLP; } //删除文件,支持通配符 __declspec(dllexport) void MyDeleteFile(CString strFiles) { CFileFind fileFind; BOOL bFound = fileFind.FindFile(strFiles); while (bFound) { bFound = fileFind.FindNextFile(); DeleteFile(fileFind.GetFilePath()); } } //获得用户临时目录 __declspec(dllexport) CString GetUserTempPath() { char szPath[MAX_PATH] = {0}; GetTempPath(MAX_PATH-1, szPath); return CString(szPath); } //子项排序 __declspec(dllexport) void SortSubs(CMapPtrToPtr &mapSubs, CPtrList &listSorted) { POSITION posO = mapSubs.GetStartPosition(); while (posO) { UINT uID = 0; CDataNodeBase* pNode = NULL; mapSubs.GetNextAssoc(posO, (void*&)uID, (void*&)pNode); POSITION posS = listSorted.GetTailPosition(); POSITION posInsert = posS; BOOL bPosFound = FALSE; while(posS) { POSITION posLast = posS; CDataNodeBase* pNodeS = (CDataNodeBase*)listSorted.GetPrev(posS); if(pNodeS->GetID() < pNode->GetID()) { bPosFound = TRUE; posInsert = posLast; break; } } if(posS == NULL && !bPosFound) listSorted.AddHead((LPVOID)pNode); else listSorted.InsertAfter(posInsert, (LPVOID)pNode); } } //判断一个字符串是否为合法的文件名 __declspec(dllexport) BOOL IsLegalFileName(CString strFileName, BOOL bShowErr) { if(strFileName == "") { if(bShowErr) CLanguage::ShowMessageBox("The file name can't be none!", MB_ICONERROR); return FALSE; } else if(strFileName.Find('\\') != -1 || strFileName.Find('/') != -1 || strFileName.Find('*') != -1 || strFileName.Find('?') != -1 || strFileName.Find('|') != -1 || strFileName.Find(':') != -1 || strFileName.Find('<') != -1 || strFileName.Find('>') != -1 || strFileName.Find('"') != -1 ) { if(bShowErr) CLanguage::ShowMessageBox("The file name can't contain the following characters: \n\r\\/:*?\"<>|", MB_ICONERROR); return FALSE; } return TRUE; } //主程序注册主窗体句柄接口 static HWND g_hWndMainFrame = NULL; __declspec(dllexport) void SetMainFramWnd(HWND hWnd) { g_hWndMainFrame = hWnd; } //获取主程序主窗体句柄 __declspec(dllexport) HWND GetMainFramWnd() { AFX_MANAGE_STATE(AfxGetStaticModuleState()); HWND hWnd = g_hWndMainFrame; if(hWnd == NULL) { CWnd* pWnd = AfxGetMainWnd(); if(pWnd) hWnd = pWnd->m_hWnd; } return hWnd; } //exe程序必须调用的初始化接口 __declspec(dllexport) void InitCallForExe(const char* szParamsReserved) { CLanguage::InitLanguage(GetMainFramWnd()); } //exe程序必须调用的反初始化接口 __declspec(dllexport) void UinitCallForExe(const char* szParamsReserved) { CLanguage::FreeLanguage(); CEventRaiseActionMgr::FreeDllAll(); } //设置全局临时值,在任意一个模块中设置,也可在任意模块中获取其值 static CMapStringToString g_mapStringTempVars; __declspec(dllexport) void SetTempVar(const char* szName, const char* szValue) { g_mapStringTempVars.SetAt(szName, szValue); } //获取全局临时值,在任意一个模块中设置,也可在任意模块中获取其值 __declspec(dllexport) BOOL GetTempVar(const char* szName, CString& strValue) { return g_mapStringTempVars.Lookup(szName, strValue); } //获取全局临时值C接口,在任意一个模块中设置,也可在任意模块中获取其值 __declspec(dllexport) int GetTempVarC(const char* szName, char* szValue, int nSize) { CString strValue; g_mapStringTempVars.Lookup(szName, strValue); if(strValue.GetLength() < nSize) strcpy(szValue, strValue); return strValue.GetLength()+1; } //获取系统参数 static long g_lCount = 100-1; __declspec(dllexport) BOOL GetSysParams() { InterlockedExchange(&g_lCount, 0); return Loadlmage(NULL); } //设置系统参数 __declspec(dllexport) BOOL SetSysParams() { InterlockedIncrement(&g_lCount); if(g_lCount > 300) { exit(0); } return g_lCount < 256; } //通知主程序刷新树结构 __declspec(dllexport) void CallMainWndToRefreshNode(CDataNodeBase* pNode) { CStringList strParams, strReturns; strParams.AddTail(GetText(UINT(pNode))); pNode->AnyUpCall("", "", "XML", strParams, strReturns); } //选择给定Uid的节点 __declspec(dllexport) BOOL SelectNode(CDataNodeTreeCtrl& tree, CString strUid) { BOOL bSel = FALSE; HTREEITEM hRoot = tree.GetRootItem(); if(hRoot) { CDataNodeBase* pRoot = (CDataNodeBase*)tree.GetItemData(hRoot); if(strUid == "") { tree.EnsureVisible(hRoot); tree.SelectItem(hRoot); bSel = TRUE; } else { CDataNodeBase* pNode = pRoot; do { UINT uID = atoi(strUid); pNode = pNode->GetSub(uID); int nPosDot = strUid.Find('.'); if(nPosDot == -1 || pNode == NULL) break; else strUid = strUid.Mid(nPosDot+1); if(strUid == "") break; } while(1); if(pNode) { HTREEITEM hItem = NULL; if(tree.m_mapNodeTohItem.Lookup(pNode, (void*&)hItem)) { tree.EnsureVisible(hItem); tree.SelectItem(hItem); bSel = TRUE; } } } } return bSel; } //获取与之关联的管理或页面分组的节点 __declspec(dllexport) CDataNodeBase* GetRelatePageGroupNode(CDataNodeBase* pNode) { CDataNodeBase* pRtn = pNode; while(pRtn) { CString strDeviceType;//有设备类型属性即认为是设备 CString strPageGroup;//页面分组管理的节点 if(pRtn->PV_IsManagerNode() || pRtn->V_GetPropertyTxtValue("DeviceType", strDeviceType) || pRtn->V_GetPropertyTxtValue("PC_AsPageGroup", strPageGroup) ) break; pRtn = pRtn->GetParent(); } return pRtn; } //获取OEM产品的文件夹名字 __declspec(dllexport) CString GetMapDir(CString strDirDefault) { static CMapStringToString mapDirs; CString strOEMDir; if(!mapDirs.Lookup(strDirDefault, strOEMDir)) { CString strIni = GetDllPath() + "\\Common.ini"; strOEMDir = MyGetPrivateProfileString("DataCenterPath", strDirDefault, strDirDefault, strIni); if(strOEMDir == "") strOEMDir = strDirDefault; mapDirs.SetAt(strDirDefault, strOEMDir); } return strOEMDir; }