//---------------------------------------------------------
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 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 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());
}
bool CCombineGrids::On_Execute(void){
	
	int x,y;
	int i;
	int iCellValue1, iCellValue2;
	int iTableValue1, iTableValue2;
	int iResultValue;
	
	CSG_Grid *pGrid1 = Parameters("GRID1")->asGrid(); 
	CSG_Grid *pGrid2 = Parameters("GRID2")->asGrid(); 
	CSG_Grid *pResult = Parameters("RESULT")->asGrid(); ;
	CSG_Table			*pLookup;
	CSG_Table_Record	*pRecord;

	pLookup	= Parameters("LOOKUP")->asTable();

	for(y=0; y<Get_NY() && Set_Progress(y); y++){		
		for(x=0; x<Get_NX(); x++){
			iCellValue1 = pGrid1->asInt(x,y);
			iCellValue2 = pGrid2->asInt(x,y);
			for (i = 0; i < pLookup->Get_Record_Count(); i++){
				pRecord = pLookup->Get_Record(i);
				iTableValue1 = pRecord->asInt(0);
				iTableValue2 = pRecord->asInt(1);
				if (iTableValue1 == iCellValue1){
					if (iTableValue2 == iCellValue2){
						iResultValue = pRecord->asInt(2);
						pResult->Set_Value(x,y,iResultValue);
						break;
					}//if
				}//if				
			}//for
			if (i >= pLookup->Get_Record_Count()){
				pResult->Set_NoData(x,y);
			}//if
		}//for
	}//for
	return true;

}//method
예제 #5
0
//---------------------------------------------------------
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 );
}
예제 #6
0
//---------------------------------------------------------
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 );
}