//////////////////////////////////////////////////////////////// // Technomaint 2004 (c) SofTech di Germinara Francesco 2000,2004 // www.germinara.it info@germinara.it // Story: // //////////////////////////////////////////////////////////////// // Checked Version: 6/5/2004 //////////////////////////////////////////////////////////////// #include"stdafx.h" #include"CFGRecord.h" CFGRecord::CFGRecord(){ m_nIndex =0; memset(m_recBuffer,0x00,_FPMAXRECLEN); InitializeFields(); } //Virtuale pura void CFGRecord::InitializeFields(){ // Example: //m_fld[m_nIndex++].SetDataField("FLGESEGUITO","Stato di elaborazione del record","",eFGTypeFields::eFieldTypeAlfaNumeric,1); //m_fld[m_nIndex++].SetDataField("FLGTIPOFLUSSO","Tipologia del flusso","B",eFGTypeFields::eFieldTypeAlfaNumeric,1); //m_fld[m_nIndex++].SetDataField("NUMEROSOTTORIGA","Non usato","",eFGTypeFields::eFieldTypeNumeric,3,0,true); } //Return number of fields int CFGRecord::GetCount(){ return m_nIndex; } //Return Record Length int CFGRecord::GetRecordSize(){ int nIndex=0; strcpy(m_recBuffer,""); for(nIndex=0; nIndex < m_nIndex; nIndex++) strcat(m_recBuffer,m_fld[nIndex].GetDataBuffer()); return strlen(m_recBuffer); } //Fill RowData void CFGRecord::BuildRowData(){ int nIndex=0; strcpy(m_recBuffer,""); for(nIndex=0; nIndex < m_nIndex; nIndex++) strcat(m_recBuffer,m_fld[nIndex].GetDataBuffer()); } //Write Data To File void CFGRecord::WriteData(CStdioFile& idFile){ CString newLine; newLine="\n"; if(idFile.m_hFile != NULL){ BuildRowData(); idFile.WriteString(m_recBuffer); idFile.WriteString(newLine); } } //Read Data To File BOOL CFGRecord::ReadData(CStdioFile& idFile){ BOOL sts=0; if(idFile.m_hFile != NULL){ if(idFile.ReadString(m_recBuffer,_FPMAXRECLEN)!=NULL){ BuildFieldsData(); sts=TRUE; }else sts=FALSE; } return sts; } //Builds Data Fields from row data buffer record void CFGRecord::BuildFieldsData(){ int nIndex=0; CString tmpData,tmpBuffer,tmpDec,tmpInt; int pos=0; int len=0; int ndec=0; tmpBuffer = (const char *) m_recBuffer; //Ripulisco Buffer Temporaneo ResetRecordBuffer(); for(nIndex=0; nIndex < m_nIndex; nIndex++){ len = m_fld[nIndex].GetLen(); ndec=m_fld[nIndex].GetDec(); if(pos+len <=tmpBuffer.GetLength()){ tmpData = tmpBuffer.Mid(pos,len); pos+=len; if(ndec > 1){ //Controllo se c'e' già il puntino di separazione dei decimali o no.. int posPuntoDec=tmpData.Find("."); if(posPuntoDec == -1){ //Non esiste, quindi lo aggiungo... tmpInt = tmpData.Mid(0, len - ndec); tmpDec = tmpData.Mid(len - ndec); tmpData = tmpInt; tmpData += "."; tmpData += tmpDec; } } m_fld[nIndex].SetDataField(tmpData); }else break; } } CString CFGRecord::GetStringValueFromFieldName(CString strName){ int nIndex=SearchField(strName); return GetStringValueFromField(nIndex); } CString CFGRecord::GetStringValueFromField(int nIndex){ if(nIndex <0 || nIndex > m_nIndex) return ""; //ERRORE! return m_fld[nIndex].GetStringValue(); } double CFGRecord::GetNumericValueFromFieldName(CString strName){ int nIndex=SearchField(strName); return GetNumericValueFromField(nIndex); } double CFGRecord::GetNumericValueFromField(int nIndex){ if(nIndex <0 || nIndex > m_nIndex) return 0.0; //ERRORE! return m_fld[nIndex].GetNumericValue(); } CString CFGRecord::StrGetNumericValueFromFieldName(CString strName){ int nIndex=SearchField(strName); return StrGetNumericValueFromField(nIndex); } CString CFGRecord::StrGetNumericValueFromField(int nIndex){ if(nIndex <0 || nIndex > m_nIndex) return ""; //ERRORE! return m_fld[nIndex].StrGetNumericValue(); } int CFGRecord::GetFieldTypeByName(CString strName){ int nIndex=SearchField(strName); return GetFieldTypeByIndex(nIndex); } int CFGRecord::GetFieldTypeByIndex(int nIndex){ if(nIndex <0 || nIndex > m_nIndex) return -1; //ERRORE! return m_fld[nIndex].GetType(); } int CFGRecord::SearchField(CString strName){ int nElement=0; CString fldName; strName.MakeUpper(); for(nElement=0; nElement < m_nIndex; nElement++){ fldName = m_fld[nElement].GetName(); fldName.MakeUpper(); if(fldName == strName) return nElement; } return -1; //Non trovato. } //Set String Data by Field Name void CFGRecord::SetStringValueToFieldName(CString strName,CString strValue){ int nIndex=SearchField(strName); if(nIndex>=0){ m_fld[nIndex].SetDataField(strValue); } } //Set Numeric Data by Field Name void CFGRecord::SetNumericValueToFieldName(CString strName,double dValue){ int nIndex=SearchField(strName); if(nIndex>=0){ m_fld[nIndex].SetDataField(dValue); } } //Ripulisco Buffer Temporaneo void CFGRecord::ResetRecordBuffer(){ for(int nIndex=0; nIndex < m_nIndex; nIndex++){ m_fld[nIndex].SetDataField(""); } } CString CFGRecord::GetFieldDescrByName(CString strName){ int nIndex=SearchField(strName); return GetFieldDescrByIndex(nIndex); } CString CFGRecord::GetFieldDescrByIndex(int nIndex){ if(nIndex <0 || nIndex > m_nIndex) return ""; //ERRORE! return m_fld[nIndex].GetDescr(); } CString CFGRecord::GetFieldNameByIndex(int nIndex){ if(nIndex <0 || nIndex > m_nIndex) return ""; //ERRORE! return m_fld[nIndex].GetName(); } //Fine