//--------------------------------------------------------- void CActive_Attributes_Control::On_Field_Open(wxCommandEvent &event) { int iField = m_Field_Offset + GetGridCursorCol(); int iRecord = GetGridCursorRow(); if( iField >= 0 && iField<m_pTable->Get_Field_Count() && iRecord >= 0 && iRecord < m_pTable->Get_Count() ) { CSG_Table_Record *pRecord = m_pTable->Get_Record(iRecord); if( event.GetId() == ID_CMD_TABLE_FIELD_OPEN_APP ) { Open_Application(pRecord->asString(iField)); } if( event.GetId() == ID_CMD_TABLE_FIELD_OPEN_DATA ) { wxString Value = pRecord->asString(iField); if( _Get_DataSource(Value) ) { g_pData->Open (Value); } } } }
//--------------------------------------------------------- bool CActive_Attributes_Control::_Set_Record(int iRecord) { CSG_Table_Record *pRecord = m_pTable->Get_Record(iRecord); if( m_Field_Offset ) // feature attributes { SetRowLabelValue(iRecord, pRecord->asString(0)); } else // grid cell values { SetRowLabelValue(iRecord, wxString::Format("%d", 1 + iRecord)); } for(int iCol=0, iField=m_Field_Offset; iField<m_pTable->Get_Field_Count(); iCol++, iField++) { switch( m_pTable->Get_Field_Type(iField) ) { default: SetCellValue(iRecord, iCol, pRecord->is_NoData(iField) ? SG_T("") : pRecord->asString(iField)); break; case SG_DATATYPE_Color: SetCellBackgroundColour(iRecord, iCol, Get_Color_asWX(pRecord->asInt(iField))); break; } } if( pRecord->is_Selected() ) { SelectRow(iRecord, true); } return( true ); }
//--------------------------------------------------------- void CVIEW_Table_Control::On_LClick(wxGridEvent &event) { int iField = m_Field_Offset + event.GetCol(); CSG_Table_Record *pRecord = m_pRecords[event.GetRow()]; //----------------------------------------------------- if( event.AltDown() ) { if( m_pTable->Get_Field_Type(iField) == SG_DATATYPE_String ) { if( event.ControlDown() ) { g_pData->Open (pRecord->asString(iField)); } else { Open_Application(pRecord->asString(iField)); } } } //----------------------------------------------------- else if( event.ControlDown() ) { m_pTable->Select(pRecord, true); Update_Selection(); } else if( event.ShiftDown() ) { SelectBlock(event.GetRow(), 0, GetGridCursorRow(), GetNumberCols(), false); } else { SelectRow(event.GetRow(), false); if( pRecord && iField >= m_Field_Offset && iField < m_pTable->Get_Field_Count() && m_pTable->Get_Field_Type(iField) == SG_DATATYPE_Color ) { long lValue; if( DLG_Color(lValue = pRecord->asInt(iField)) ) { pRecord->Set_Value(iField, lValue); SetCellBackgroundColour(event.GetRow(), event.GetCol(), Get_Color_asWX(pRecord->asInt(iField))); ForceRefresh(); } } } //----------------------------------------------------- SetGridCursor(event.GetRow(), event.GetCol()); }
//--------------------------------------------------------- bool CTable_Enumerate::On_Execute(void) { int iField, iField_ID, iID, iRecord, old_Field; TSG_Table_Index_Order old_Order; CSG_String Value; CSG_Table *pTable, *pOutput; CSG_Table_Record *pRecord; //----------------------------------------------------- pTable = Parameters("INPUT") ->asTable(); pOutput = Parameters("OUTPUT") ->asTable(); iField = Parameters("FIELD") ->asInt(); //----------------------------------------------------- if( iField >= 0 && iField < pTable->Get_Field_Count() && pTable->Get_Record_Count() > 0 ) { if( pOutput != NULL && pOutput != pTable ) { pOutput->Create (*pTable); pOutput->Set_Name ( pTable->Get_Name()); pTable = pOutput; } //------------------------------------------------- pTable->Add_Field(_TL("ENUM_ID"), SG_DATATYPE_Int); iField_ID = pTable->Get_Field_Count() - 1; old_Order = pTable->Get_Index_Order(0); old_Field = pTable->Get_Index_Field(0); pTable->Set_Index(iField, TABLE_INDEX_Descending); Value = pTable->Get_Record_byIndex(0)->asString(iField); for(iRecord=0, iID=1; iRecord<pTable->Get_Record_Count(); iRecord++) { pRecord = pTable->Get_Record_byIndex(iRecord); if( Value.Cmp(pRecord->asString(iField)) ) { Value = pRecord->asString(iField); iID++; } pRecord->Set_Value(iField_ID, iID); } pTable->Set_Index(old_Field, old_Order); return( true ); } return( false ); }
//--------------------------------------------------------- bool CSG_Translator::Create(class CSG_Table *pTranslations, int iText, int iTranslation, bool bCmpNoCase) { SG_UI_Msg_Lock(true); Destroy(); if( iText != iTranslation && pTranslations && pTranslations->Get_Field_Count() > iText && pTranslations->Get_Field_Count() > iTranslation && pTranslations->Get_Record_Count() > 0 ) { int i; m_bCmpNoCase = bCmpNoCase; if( m_bCmpNoCase ) { for(i=0; i<pTranslations->Get_Record_Count(); i++) { CSG_Table_Record *pRecord = pTranslations->Get_Record(i); CSG_String s = pRecord->asString(iText); pRecord->Set_Value(iText, s.Make_Lower().c_str()); } } pTranslations->Set_Index(iText, TABLE_INDEX_Ascending); m_Translations = (CSG_Translation **)SG_Malloc(pTranslations->Get_Record_Count() * sizeof(CSG_Translation *)); for(i=0; i<pTranslations->Get_Record_Count(); i++) { CSG_Table_Record *pRecord = pTranslations->Get_Record_byIndex(i); if( *pRecord->asString(iText) && *pRecord->asString(iTranslation) ) { m_Translations[m_nTranslations++] = new CSG_Translation(pRecord->asString(iText), pRecord->asString(iTranslation)); } } if( m_nTranslations < pTranslations->Get_Record_Count() ) { m_Translations = (CSG_Translation **)SG_Realloc(m_Translations, m_nTranslations * sizeof(CSG_Translation *)); } } SG_UI_Msg_Lock(false); return( m_nTranslations > 0 ); }
//--------------------------------------------------------- bool CWKSP_Shapes::Edit_Set_Index(int Index) { m_Edit_Attributes.Del_Records(); if( Index > Get_Shapes()->Get_Selection_Count() ) { Index = Get_Shapes()->Get_Selection_Count(); } CSG_Table_Record *pSelection = Get_Shapes()->Get_Selection(Index); if( pSelection ) { m_Edit_Index = Index; for(int i=0; i<Get_Shapes()->Get_Field_Count(); i++) { CSG_Table_Record *pRecord = m_Edit_Attributes.Add_Record(); pRecord->Set_Value(0, pSelection->Get_Table()->Get_Field_Name(i)); pRecord->Set_Value(1, pSelection->asString(i)); } } else { m_Edit_Index = 0; } return( true ); }
//--------------------------------------------------------- bool CActive_Attributes_Control::_ToClipboard(void) { if( wxTheClipboard->Open() ) { wxString Data; for(int i=0; i<m_pTable->Get_Count(); i++) { CSG_Table_Record *pRecord = m_pTable->Get_Record(i); for(int j=0; j<m_pTable->Get_Field_Count(); j++) { Data += pRecord->asString(j); Data += j + 1 < m_pTable->Get_Field_Count() ? '\t' : '\n'; } } wxTheClipboard->SetData(new wxTextDataObject(Data)); wxTheClipboard->Close(); return( true ); } return( false ); }
//--------------------------------------------------------- bool CShapes_Split_by_Attribute::On_Execute(void) { int iField; CSG_Table *pTable; //----------------------------------------------------- pTable = Parameters("TABLE") ->asTable(); iField = Parameters("FIELD") ->asInt(); Parameters("CUTS")->asTableList()->Del_Items(); //----------------------------------------------------- if( pTable->is_Valid() && pTable->Set_Index(iField, TABLE_INDEX_Ascending) ) { CSG_String sValue; CSG_Table *pCut = NULL; for(int iRecord=0; iRecord<pTable->Get_Count() && Set_Progress(iRecord, pTable->Get_Count()); iRecord++) { CSG_Table_Record *pRecord = pTable->Get_Record_byIndex(iRecord); if( !pCut || sValue.Cmp(pRecord->asString(iField)) ) { pCut = pTable->Get_ObjectType() == DATAOBJECT_TYPE_Shapes ? SG_Create_Shapes(((CSG_Shapes *)pTable)->Get_Type(), SG_T(""), pTable) : SG_Create_Table(pTable); pCut->Set_Name(CSG_String::Format(SG_T("%s [%s = %s]"), pTable->Get_Name(), pTable->Get_Field_Name(iField), pRecord->asString(iField) )); Parameters("CUTS")->asTableList()->Add_Item(pCut); sValue = pRecord->asString(iField); } pCut->Add_Record(pRecord); } return( pCut != NULL ); } return( false ); }
//--------------------------------------------------------- void CActive_Attributes_Control::On_LClick(wxGridEvent &event) { int iField = m_Field_Offset + event.GetCol(); CSG_Table_Record *pRecord = m_pTable->Get_Record(event.GetRow()); //----------------------------------------------------- if( event.AltDown() ) { if( m_pTable->Get_Field_Type(iField) == SG_DATATYPE_String ) { Open_Application(pRecord->asString(iField)); } } //----------------------------------------------------- if( event.ControlDown() ) { if( m_pTable->Get_Field_Type(iField) == SG_DATATYPE_String ) { g_pData->Open (pRecord->asString(iField)); } } //----------------------------------------------------- else { if( pRecord && iField >= m_Field_Offset && iField < m_pTable->Get_Field_Count() && m_pTable->Get_Field_Type(iField) == SG_DATATYPE_Color ) { long lValue; if( DLG_Color(lValue = pRecord->asInt(iField)) ) { pRecord->Set_Value(iField, lValue); SetCellBackgroundColour(event.GetRow(), event.GetCol(), Get_Color_asWX(pRecord->asInt(iField))); ForceRefresh(); } } } //----------------------------------------------------- SetGridCursor(event.GetRow(), event.GetCol()); }
//--------------------------------------------------------- void CVIEW_Table_Control::On_Field_Open(wxCommandEvent &event) { int iField = m_Field_Offset + GetGridCursorCol(); int iRecord = GetGridCursorRow(); if( iField >= 0 && iField<m_pTable->Get_Field_Count() && iRecord >= 0 && iRecord < m_pTable->Get_Count() ) { CSG_Table_Record *pRecord = m_pRecords[iRecord]; if( event.GetId() == ID_CMD_TABLE_FIELD_OPEN_APP ) { Open_Application(pRecord->asString(iField)); } if( event.GetId() == ID_CMD_TABLE_FIELD_OPEN_DATA ) { g_pData->Open (pRecord->asString(iField)); } } }
//--------------------------------------------------------- void CVIEW_Table_Control::On_Changed(wxGridEvent &event) { CSG_Table_Record *pRecord = m_pRecords[event.GetRow()]; if( pRecord ) { int iField = m_Field_Offset + event.GetCol(); if( iField >= m_Field_Offset && iField < m_pTable->Get_Field_Count() ) { pRecord->Set_Value(iField, GetCellValue(event.GetRow(), event.GetCol()).wx_str()); SetCellValue(event.GetRow(), event.GetCol(), pRecord->asString(iField)); } } }
//--------------------------------------------------------- bool CWKSP_Shapes::Edit_Set_Attributes(void) { CSG_Table_Record *pSelection = Get_Shapes()->Get_Selection(m_Edit_Index); if( pSelection ) { for(int i=0; i<m_Edit_Attributes.Get_Record_Count(); i++) { if( !pSelection->Set_Value(i, m_Edit_Attributes.Get_Record(i)->asString(1)) ) { m_Edit_Attributes.Get_Record(i)->Set_Value(1, pSelection->asString(i)); } } Update_Views(false); return( true ); } return( false ); }
//--------------------------------------------------------- bool CSG_ODBC_Connection::Table_Insert(const CSG_String &Table_Name, const CSG_Table &Table, bool bCommit) { //----------------------------------------------------- if( !is_Connected() ) { _Error_Message(_TL("no database connection")); return( false ); } if( !Table_Exists(Table_Name) ) { return( false ); } CSG_Table Fields = Get_Field_Desc(Table_Name); if( Fields.Get_Count() != Table.Get_Field_Count() ) { return( false ); } //----------------------------------------------------- try { bool bLOB = false; int iField, iRecord; CSG_String Insert; otl_stream Stream; //------------------------------------------------- Insert.Printf(SG_T("INSERT INTO %s VALUES("), Table_Name.c_str()); for(iField=0; iField<Table.Get_Field_Count(); iField++) { if( iField > 0 ) { Insert += SG_T(","); } Insert += CSG_String::Format(SG_T(":f%d"), 1 + iField); switch( Table.Get_Field_Type(iField) ) { default: case SG_DATATYPE_String: Insert += SG_T("<varchar>"); break; case SG_DATATYPE_Date: Insert += SG_T("<char[12]>"); break; case SG_DATATYPE_Char: Insert += SG_T("<char>"); break; case SG_DATATYPE_Short: Insert += SG_T("<short>"); break; case SG_DATATYPE_Int: Insert += SG_T("<int>"); break; case SG_DATATYPE_Color: Insert += SG_T("<long>"); break; case SG_DATATYPE_Long: Insert += SG_T("<long>"); break; case SG_DATATYPE_Float: Insert += SG_T("<float>"); break; case SG_DATATYPE_Double: Insert += SG_T("<double>"); break; } } Insert += SG_T(")"); Stream.set_all_column_types(otl_all_date2str); Stream.set_lob_stream_mode(bLOB); Stream.open(bLOB ? 1 : m_Size_Buffer, Insert, m_Connection); std_string valString; //------------------------------------------------- for(iRecord=0; iRecord<Table.Get_Count() && SG_UI_Process_Set_Progress(iRecord, Table.Get_Count()); iRecord++) { CSG_Table_Record *pRecord = Table.Get_Record(iRecord); for(iField=0; iField<Table.Get_Field_Count(); iField++) { if( pRecord->is_NoData(iField) ) { Stream << otl_null(); } else switch( Table.Get_Field_Type(iField) ) { default: case SG_DATATYPE_String: case SG_DATATYPE_Date: valString = CSG_String(pRecord->asString(iField)); Stream << valString; break; case SG_DATATYPE_Char: Stream << (char)pRecord->asChar (iField); break; case SG_DATATYPE_Short: Stream << pRecord->asShort (iField); break; case SG_DATATYPE_Int: Stream << pRecord->asInt (iField); break; case SG_DATATYPE_Color: case SG_DATATYPE_Long: Stream << (long)pRecord->asInt (iField); break; case SG_DATATYPE_Float: Stream << pRecord->asFloat (iField); break; case SG_DATATYPE_Double: Stream << pRecord->asDouble(iField); break; } } } } //----------------------------------------------------- catch( otl_exception &e ) { _Error_Message(e); return( false ); } return( true ); }
//--------------------------------------------------------- bool CSG_Table::_Save_DBase(const CSG_String &File_Name) { int iField, iRecord, nBytes; CSG_Table_DBase dbf; //----------------------------------------------------- CSG_Table_DBase::TFieldDesc *dbfFields = new CSG_Table_DBase::TFieldDesc[Get_Field_Count()]; for(iField=0; iField<Get_Field_Count(); iField++) { strncpy(dbfFields[iField].Name, SG_STR_SGTOMB(Get_Field_Name(iField)), 11); switch( Get_Field_Type(iField) ) { case SG_DATATYPE_String: default: dbfFields[iField].Type = DBF_FT_CHARACTER; dbfFields[iField].Width = (BYTE)((nBytes = Get_Field_Length(iField)) > 255 ? 255 : nBytes); break; case SG_DATATYPE_Date: dbfFields[iField].Type = DBF_FT_DATE; dbfFields[iField].Width = (BYTE)8; break; case SG_DATATYPE_Char: dbfFields[iField].Type = DBF_FT_CHARACTER; dbfFields[iField].Width = (BYTE)1; break; case SG_DATATYPE_Short: case SG_DATATYPE_Int: case SG_DATATYPE_Long: case SG_DATATYPE_Color: dbfFields[iField].Type = DBF_FT_NUMERIC; dbfFields[iField].Width = (BYTE)16; dbfFields[iField].Decimals = (BYTE)0; break; case SG_DATATYPE_Float: case SG_DATATYPE_Double: dbfFields[iField].Type = DBF_FT_NUMERIC; dbfFields[iField].Width = (BYTE)16; dbfFields[iField].Decimals = (BYTE)8; break; } } if( !dbf.Open(File_Name, Get_Field_Count(), dbfFields) ) { delete[](dbfFields); SG_UI_Msg_Add_Error(LNG("[ERR] dbase file could not be opened")); return( false ); } delete[](dbfFields); //----------------------------------------------------- for(iRecord=0; iRecord<Get_Record_Count() && SG_UI_Process_Set_Progress(iRecord, Get_Record_Count()); iRecord++) { CSG_Table_Record *pRecord = Get_Record(iRecord); dbf.Add_Record(); for(iField=0; iField<Get_Field_Count(); iField++) { switch( dbf.Get_FieldType(iField) ) { case DBF_FT_DATE: case DBF_FT_CHARACTER: dbf.Set_Value(iField, SG_STR_SGTOMB(pRecord->asString(iField))); break; case DBF_FT_NUMERIC: dbf.Set_Value(iField, pRecord->asDouble(iField)); break; } } dbf.Flush_Record(); } SG_UI_Process_Set_Ready(); return( true ); }
//--------------------------------------------------------- bool CTable_Text_Export::On_Execute(void) { CSG_String StrFormat, Separator; CSG_File Stream; CSG_Table *pTable; //----------------------------------------------------- pTable = Parameters("TABLE" )->asTable(); StrFormat = Parameters("STRQUOTA")->asBool() ? SG_T("\"%s\"") : SG_T("%s"); switch( Parameters("SEPARATOR")->asInt() ) { case 0: Separator = "\t"; break; case 1: Separator = ";"; break; case 2: Separator = ","; break; case 3: Separator = " "; break; default: Separator = Parameters("SEP_OTHER")->asString(); break; } //----------------------------------------------------- if( !Stream.Open(Parameters("FILENAME")->asString(), SG_FILE_W, false) ) { Message_Add(_TL("file could not be opened.")); } //----------------------------------------------------- else { if( Parameters("HEADLINE")->asBool() ) { for(int iField=0; iField<pTable->Get_Field_Count(); iField++) { Stream.Printf(StrFormat.c_str(), pTable->Get_Field_Name(iField)); Stream.Printf(iField < pTable->Get_Field_Count() - 1 ? Separator.c_str() : SG_T("\n")); } } //------------------------------------------------- for(int iRecord=0; iRecord<pTable->Get_Record_Count() && Set_Progress(iRecord, pTable->Get_Record_Count()); iRecord++) { CSG_Table_Record *pRecord = pTable->Get_Record(iRecord); for(int iField=0; iField<pTable->Get_Field_Count(); iField++) { switch( pTable->Get_Field_Type(iField) ) { default: case SG_DATATYPE_Char: case SG_DATATYPE_String: case SG_DATATYPE_Date: Stream.Printf(StrFormat.c_str(), pRecord->asString(iField)); break; case SG_DATATYPE_Short: case SG_DATATYPE_Int: case SG_DATATYPE_Color: Stream.Printf(SG_T("%d") , pRecord->asInt(iField)); break; case SG_DATATYPE_Long: Stream.Printf(SG_T("%ld") , (long)pRecord->asDouble(iField)); break; case SG_DATATYPE_ULong: Stream.Printf(SG_T("%lu") , (unsigned long)pRecord->asDouble(iField)); break; case SG_DATATYPE_Float: case SG_DATATYPE_Double: Stream.Printf(SG_T("%f") , pRecord->asDouble(iField)); break; } Stream.Printf(iField < pTable->Get_Field_Count() - 1 ? Separator.c_str() : SG_T("\n")); } } //------------------------------------------------- Stream.Close(); return( true ); } return( false ); }