//--------------------------------------------------------------------------- #include #pragma hdrstop #include "AppGlobalF.h" #include "ITSDbF.h" #include "ITSUtilF.h" #include "ITSLogF.h" #include //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- String CenterCd = ""; // Áö¿ª¼¾ÅÍ ÄÚµå String CenterId = ""; // Áö¿ª¼¾ÅÍ ¾ÆÀ̵ð String CenterName = ""; // Áö¿ª¼¾ÅÍ ¸íĪ int g_nPid = -1; // Application Process ID String g_sAppDir = ""; // Application Directory String g_sAppName= ""; // Program name String g_sCfgDir = ""; // Config File Directory String g_sLogDir = ""; // Program Log Directory String g_sTempDir = ""; // Program Temp Directory String g_sFormsDir = ""; // Program Forms Directory String g_sLangDir = ""; APP_CONFIG g_AppCfg; LOGININFO *g_pLOGIN = NULL; LOG_INFO g_LogCfg; TITSLog *ITSLog = NULL; //--------------------------------------------------------------------------- bool LoadDefaultConfigInfo(String ACfgFile/*=""*/) { String sCfgFile; TIniFile *pIniFile = NULL; String sIniFile = ChangeFileExt(ExtractFileName(Application->ExeName), ".ini"); if (!ACfgFile.IsEmpty()) sIniFile = ACfgFile + ".ini"; sCfgFile = g_sCfgDir + sIniFile; g_AppCfg.sConfigFile = sCfgFile; g_AppCfg.thr.pThread = NULL; g_AppCfg.thr.dwThreadId = 0; g_AppCfg.thr.nHandle = 0; g_AppCfg.thr.bRunning = false; g_AppCfg.bAppClose = false; pIniFile = new TIniFile(sCfgFile); try { g_AppCfg.sTitle = pIniFile->ReadString("APPLICATION", "TITLE", "±³ÅëÁ¤º¸½Ã½ºÅÛ ÅëÇÕ ¿î¿µ´Ü¸»"); g_AppCfg.sProcessId = pIniFile->ReadString("APPLICATION", "PROCESSID", "OPER01"); g_AppCfg.sLogDay = pIniFile->ReadString("APPLICATION", "LOGDAY", ""); g_AppCfg.sAppPath = pIniFile->ReadString("APPLICATION", "APP_PATH", ""); g_AppCfg.sSkinName = pIniFile->ReadString("APPLICATION", "SKINNAME", "Blue"); g_AppCfg.bSaveForm = pIniFile->ReadString("APPLICATION", "SAVEFORM", "1").ToIntDef(1) == 1 ? true : false; g_AppCfg.bLoginPrompt = pIniFile->ReadString("APPLICATION", "LOGINPROMPT", "1").ToIntDef(1) == 1 ? true : false; g_AppCfg.bDebug = pIniFile->ReadString("APPLICATION", "DEBUG", "0").ToIntDef(0) == 1 ? true : false; g_AppCfg.sDefUseId = pIniFile->ReadString("APPLICATION", "LASTUSER", ""); g_AppCfg.sLang = pIniFile->ReadString("APPLICATION", "LANGUAGE", "kr").LowerCase(); if (g_AppCfg.sLang != "en" && g_AppCfg.sLang != "kr") g_AppCfg.sLang = "kr"; g_AppCfg.itsdb.bSqlLog = pIniFile->ReadString("ITSDB", "SQLLOG", "0").ToIntDef(0) == 1 ? true : false; g_AppCfg.itsdb.sConnectStr = pIniFile->ReadString("ITSDB", "CONNECTSTR", ""); if (g_AppCfg.itsdb.sConnectStr == "") { g_AppCfg.itsdb.sProvider = pIniFile->ReadString("ITSDB", "PROVIDER", "OraOLEDB.Oracle.1"); g_AppCfg.itsdb.sServerName = pIniFile->ReadString("ITSDB", "SERVERNAME", "HANTE"); g_AppCfg.itsdb.sUserName = pIniFile->ReadString("ITSDB", "USERNAME", "hnits"); g_AppCfg.itsdb.sPassword = pIniFile->ReadString("ITSDB", "PASSWORD", "hnits"); } //½Ã¼³¹° ¿Âµµ¾Ë¶÷À» »ç¿ëÇÏÁö ¾Ê´Â°æ¿ì 100µµ°¡ µÇ±â¶§¹®¿¡ ½ÇÁ¦ÀûÀ¸·Î ¾Ë¶÷ÀÌ ¹ß»ýÇÏÁö ¾Ê´Â È¿°ú°¡ ÀÖÀ½ //Áï, ¿ÂµµÀÌ»ó¾Ë¶÷À» ¿øÇÏ´Â °æ¿ì¿¡¸¸ ¾Ë¶÷°ªÀ» ¼³Á¤ÇÏ¿© »ç¿ëÇÏ¸é µÊ g_AppCfg.Temp.AlarmValue = pIniFile->ReadString("TEMPERATURE", "ALARMVALUE", "100").ToIntDef(100); //45 } __finally { if (pIniFile) delete pIniFile; pIniFile = NULL; } return true; } //--------------------------------------------------------------------------- bool CMM_InsertLoginHist(PLOGININFO pLogin, bool ALogin) { String sQry; bool bResult= false; TADOQuery *adoQry = NULL; if (!pLogin) return false; if (ALogin) { sQry = "INSERT INTO TB_USERCNNC_HS ( \r\n" " LOGIN_HMS, \r\n" " USER_ID, \r\n" " LOGOUT_HMS \r\n" " ) \r\n" "VALUES ( \r\n" " :p01, \r\n" " :p02, \r\n" " NULL \r\n" " ) \r\n"; } else { sQry = "UPDATE TB_USERCNNC_HS SET \r\n" " LOGOUT_HMS = TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS') \r\n" " WHERE LOGIN_HMS = :p01 \r\n" " AND USER_ID = :p02 \r\n"; } try { try { adoQry = new TADOQuery(NULL); adoQry->Connection = ITSDb_GetConnection(); ITSDb_GetConnection()->BeginTrans(); adoQry->Close(); adoQry->SQL->Text = sQry; adoQry->Parameters->ParamByName("p01")->Value = pLogin->sLoginTime; adoQry->Parameters->ParamByName("p02")->Value = pLogin->sUserId; int nRowCnt = adoQry->ExecSQL(); ITSDb_GetConnection()->CommitTrans(); bResult = nRowCnt > 1 ? true : false; } catch (Exception &exception) { ITSDb_GetConnection()->RollbackTrans(); throw Exception(String(exception.ClassName()) + exception.Message); } catch (...) { ITSDb_GetConnection()->RollbackTrans(); } } __finally { if (adoQry) { adoQry->Close(); delete adoQry; } } return bResult; } //--------------------------------------------------------------------------- /* * ȯ°æ¼³Á¤ Á¤º¸¸¦ ÀúÀåÇÏ´Â ÇÔ¼ö. * arguments * String : RegisterKey ¶Ç´Â ÆÄÀÏÀ̸§ * return * bool : ½ÇÆÐÇϸé false */ bool WriteConfigInfo(String sCfgFile, String sTitle, String sItem, String sValue) { String ConfigFile; TIniFile *pIniFile = NULL; ConfigFile = sCfgFile; try { pIniFile = new TIniFile(ConfigFile); if (pIniFile == NULL) { return false; } pIniFile->WriteString(sTitle, sItem, sValue); } catch(...) { } if (pIniFile) { pIniFile->Free(); pIniFile = NULL; } return true; } //--------------------------------------------------------------------------- /* * ȯ°æ¼³Á¤ Á¤º¸¸¦ Àоî¿À´Â ÇÔ¼ö. * arguments * String : RegisterKey ¶Ç´Â ÆÄÀÏÀ̸§ * return * bool : ½ÇÆÐÇϸé false */ bool ReadConfigInfo(String sCfgFile, String sTitle, String sItem, String &sValue) { bool bRes; String ConfigFile; TIniFile *pIniFile = NULL; bRes = false; ConfigFile = sCfgFile; try { pIniFile = new TIniFile(ConfigFile); if (pIniFile == NULL) { return bRes; } sValue = pIniFile->ReadString(sTitle, sItem, ""); if (sValue != "") { bRes = true; } } catch(...) { } if (pIniFile) { pIniFile->Free(); pIniFile = NULL; } return bRes; } //--------------------------------------------------------------------------- void ShowErrorMsg(String ATitle, String AErrMsg) { Application->NormalizeTopMosts(); Application->MessageBox(AErrMsg.c_str(), ATitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL); Application->RestoreTopMosts(); } //---------------------------------------------------------------------------- String APP_GetCode(TcxComboBox *ACombo) { String sReturn = ""; if (ACombo->ItemIndex >= 0) { String sDesc = ACombo->Properties->Items->Strings[ACombo->ItemIndex]; String sCode = sDesc.SubString(sDesc.Pos("[") + 1, sDesc.Pos("]") - (sDesc.Pos("[") + 1)); sReturn = sCode; } return sReturn; } //---------------------------------------------------------------------------- String APP_GetCodeDesc(TcxComboBox *ACombo, String ACode) { String sReturn = ""; for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++) { String sDesc = ACombo->Properties->Items->Strings[ii]; String sCode = sDesc.SubString(sDesc.Pos("[") + 1, sDesc.Pos("]") - (sDesc.Pos("[") + 1)); if (ACode == sCode) { sReturn = sDesc; break; } } return sReturn; } //---------------------------------------------------------------------------- String APP_GetCodeName(TcxComboBox *ACombo, String ACode) { String sReturn = ""; for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++) { String sDesc = ACombo->Properties->Items->Strings[ii]; String sName = sDesc.SubString(sDesc.Pos("]") + 1, sDesc.Length()); String sCode = sDesc.SubString(sDesc.Pos("[") + 1, sDesc.Pos("]") - (sDesc.Pos("[") + 1)); if (ACode == sCode) { sReturn = sName.Trim(); break; } } return sReturn; } //---------------------------------------------------------------------------- String APP_GetCodeIdByName(TcxComboBox *ACombo, String AName) { String sReturn = "3"; for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++) { String sDesc = ACombo->Properties->Items->Strings[ii]; String sName = sDesc.SubString(sDesc.Pos("]") + 1, sDesc.Length()); String sCode = sDesc.SubString(sDesc.Pos("[") + 1, sDesc.Pos("]") - (sDesc.Pos("[") + 1)); if (sName.Trim() == AName.Trim()) { sReturn = sCode; break; } } return sReturn; } //---------------------------------------------------------------------------- String APP_GetCodeDefCode(TcxComboBox *ACombo) { String sReturn = ""; if (ACombo->Properties->Items->Count > 0) { String sDesc = ACombo->Properties->Items->Strings[0]; String sCode = sDesc.SubString(sDesc.Pos("[") + 1, sDesc.Pos("]") - (sDesc.Pos("[") + 1)); sReturn = sCode; } return sReturn; } //---------------------------------------------------------------------------- String APP_GetCodeDefDesc(TcxComboBox *ACombo) { String sReturn = ""; if (ACombo->Properties->Items->Count > 0) { String sDesc = ACombo->Properties->Items->Strings[0]; sReturn = sDesc; } return sReturn; } //---------------------------------------------------------------------------- int APP_SetCode(TcxComboBox *ACombo, String ACode) { int nItemIndex = -1; for (int ii = 0; ii < ACombo->Properties->Items->Count; ii++) { String sDesc = ACombo->Properties->Items->Strings[ii]; String sCode = sDesc.SubString(sDesc.Pos("[") + 1, sDesc.Pos("]") - (sDesc.Pos("[") + 1)); if (ACode == sCode) { nItemIndex = ii; break; } } ACombo->ItemIndex = nItemIndex; return nItemIndex; } //---------------------------------------------------------------------------- ULONG ProcIDFromWnd(HWND hwnd) // À©µµ¿ì ÇÚµé·Î ÇÁ·Î¼¼½º ¾ÆÀ̵ð ¾ò±â { ULONG idProc; GetWindowThreadProcessId( hwnd, &idProc ); return idProc; } //---------------------------------------------------------------------------- HWND GetWinHandle(ULONG pid) // ÇÁ·Î¼¼½º ¾ÆÀ̵ð·Î À©µµ¿ì ÇÚµé ¾ò±â { HWND tempHwnd = FindWindow(NULL,NULL); // ÃÖ»óÀ§ À©µµ¿ì ÇÚµé ã±â while( tempHwnd != NULL ) { if( GetParent(tempHwnd) == NULL ) // ÃÖ»óÀ§ ÇÚµéÀÎÁö üũ, ¹öư µîµµ ÇÚµéÀ» °¡Áú ¼ö ÀÖÀ¸¹Ç·Î ¹«½ÃÇϱâ À§ÇØ if( pid == ProcIDFromWnd(tempHwnd) ) return tempHwnd; tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT); // ´ÙÀ½ À©µµ¿ì ÇÚµé ã±â } return NULL; } //---------------------------------------------------------------------------- String ITSUtil_FormatStr(String AStrDateTime, String AFormat) { #define SYEAR "-" #define STIME ":" #define SPACE " " String sDateTime = ""; String sInData = AnsiString(AStrDateTime); //ShowMessage("IN: " + AStrDateTime + " " + sInData + " " + AFormat); if (sInData.IsEmpty()) return sInData; //sDateTime = sInData; try { if (AFormat == STR_DATETIME) { if (sInData.Length() < 14) return sInData; sDateTime = sInData.SubString( 1, 4) + SYEAR + sInData.SubString( 5, 2) + SYEAR + sInData.SubString( 7, 2) + SPACE + sInData.SubString( 9, 2) + STIME + sInData.SubString(11, 2) + STIME + sInData.SubString(13, 2); } else if (AFormat == STR_HHNN) { if (sInData.Length() < 12) return sInData; sDateTime = sInData.SubString( 1, 4) + SYEAR + sInData.SubString( 5, 2) + SYEAR + sInData.SubString( 7, 2) + SPACE + sInData.SubString( 9, 2) + STIME + sInData.SubString(11, 2); } else if (AFormat == STR_DATEHOUR) { if (sInData.Length() < 10) return sInData; sDateTime = sInData.SubString( 1, 4) + SYEAR + sInData.SubString( 5, 2) + SYEAR + sInData.SubString( 7, 2) + SPACE + sInData.SubString( 9, 2); } else if (AFormat == STR_DATE) { if (sInData.Length() < 8) return sInData; sDateTime = sInData.SubString( 1, 4) + SYEAR + sInData.SubString( 5, 2) + SYEAR + sInData.SubString( 7, 2); } else if (AFormat == STR_MM) { if (sInData.Length() < 6) return sInData; sDateTime = sInData.SubString( 1, 4) + SYEAR + sInData.SubString( 5, 2); } else { sDateTime = sInData; } } catch(...) { } //ShowMessage("OUT: " + sDateTime); return sDateTime; } //--------------------------------------------------------------------------- TColor g_DispColor[MAX_DISPCOLOR]; void APP_InitDisplayColor() { g_DispColor[ 0] = Graphics::clBlue; g_DispColor[ 1] = Graphics::clRed; g_DispColor[ 2] = Graphics::clLime; g_DispColor[ 3] = Graphics::clMaroon; g_DispColor[ 4] = Graphics::clGreen; g_DispColor[ 5] = Graphics::clMenuHighlight; g_DispColor[ 6] = Graphics::clBackground; g_DispColor[ 7] = Graphics::clPurple; g_DispColor[ 8] = Graphics::clTeal; g_DispColor[ 9] = Graphics::clYellow; g_DispColor[10] = Graphics::clFuchsia; g_DispColor[11] = Graphics::clAqua; g_DispColor[12] = Graphics::clMoneyGreen; g_DispColor[13] = Graphics::clSkyBlue; g_DispColor[14] = Graphics::clRed; g_DispColor[15] = Graphics::clLime; g_DispColor[16] = Graphics::clYellow; g_DispColor[17] = Graphics::clBlue; g_DispColor[18] = Graphics::clFuchsia; g_DispColor[19] = Graphics::clAqua; g_DispColor[20] = Graphics::clMoneyGreen; g_DispColor[21] = Graphics::clActiveCaption; } //--------------------------------------------------------------------------- TColor APP_GetDisplayColor(int ASeq) { return g_DispColor[ASeq % MAX_DISPCOLOR]; } //--------------------------------------------------------------------------- void APP_DelVmsSizeCombo(TcxComboBox *cboBox) { TStrings *pStrItems; TVmsSizeType *Ov; pStrItems = ((TcxComboBox *)cboBox)->Properties->Items; for (int ii = pStrItems->Count-1; ii >= 0; ii--) { Ov = (TVmsSizeType *)pStrItems->Objects[ii]; if (Ov != NULL) { delete Ov; Ov = NULL; } } } //--------------------------------------------------------------------------- TVmsSizeType* APP_GetVmsSizeTypeObject(TcxComboBox *cboBox) { TStrings *pStrItems; TVmsSizeType *Ov = NULL; int nItemIndex; pStrItems = ((TcxComboBox *)cboBox)->Properties->Items; nItemIndex= ((TcxComboBox *)cboBox)->ItemIndex; if (nItemIndex < 0) { return Ov; } Ov = (TVmsSizeType *)pStrItems->Objects[nItemIndex]; if (Ov == NULL) { Ov = NULL; } return Ov; } //--------------------------------------------------------------------------- void APP_ImageClear(TCanvas *c, int offX, int offY, int w, int h, TColor color) { try { c->Pen->Color = clWhite; c->Pen->Width = 0; c->Pen->Style = psClear; c->Brush->Style = bsSolid; c->Brush->Color = color; c->Rectangle(offX, offY, w+offX+2, h+offY+2); } catch(...) { } } //--------------------------------------------------------------------------- #include TDateTime APP_StrToDateTime(String AStrDateTime) { TDateTime dtReturnValue = NULL; if (AStrDateTime.IsEmpty()) return dtReturnValue; if (AStrDateTime.Length() != 14) return dtReturnValue; AnsiString sDateTime = AnsiString(AStrDateTime); try { #if 0 sDateTime.printf(L"%s-%s-%s %s:%s:%s", AStrDateTime.SubString( 1, 4).c_str(), AStrDateTime.SubString( 5, 2).c_str(), AStrDateTime.SubString( 7, 2).c_str(), AStrDateTime.SubString( 9, 2).c_str(), AStrDateTime.SubString(11, 2).c_str(), AStrDateTime.SubString(13, 2).c_str()); dtReturnValue = StrToDateTime(sDateTime); #endif // swscanf(sRgb.c_str(), L"%d,%d,%d", &r, &g, &b); int year, month, day, hour, minute, second; sscanf(sDateTime.c_str(), "%4d%2d%2d%2d%2d%2d", &year, &month, &day, &hour, &minute, &second); dtReturnValue = EncodeDateTime(year, month, day, hour, minute, second, 0); } catch(...) { } return dtReturnValue; } //---------------------------------------------------------------------------