//--------------------------------------------------------------------------- #include #pragma hdrstop #include #include #include "IterationConfig.h" #include "DataModule.h" #include "Main.h" #include "Utilities.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "Grids_ts" #pragma link "TSDBGrid" #pragma link "TSGrid" #pragma link "AdvGrid" #pragma link "BaseGrid" #pragma link "DBAdvGrd" #pragma link "DBAdvGrid" #pragma link "DBAdvGrd" #pragma link "DBAdvNavigator" #pragma resource "*.dfm" TIterationConfigForm *IterationConfigForm; //--------------------------------------------------------------------------- __fastcall TIterationConfigForm::TIterationConfigForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TIterationConfigForm::CloseBtnClick(TObject *Sender) { IterationsQuery->Post(); IterationsQuery->Close(); Close(); } //--------------------------------------------------------------------------- void __fastcall TIterationConfigForm::ShowForm(const AnsiString &project_code) { m_currentproject = project_code; AnsiString sql_statement; sql_statement.sprintf( "SELECT * FROM ITERATIONS WHERE PROJECT_CODE='%s' ORDER BY ITERATION", Utilities::EscapeString( m_currentproject ).c_str() ); IterationsQuery->SQL->Text = sql_statement; IterationsQuery->Open(); ShowModal(); } //--------------------------------------------------------------------------- const bool __fastcall TIterationConfigForm::getSchemaDetails( AnsiString & schemaVersion, const AnsiString & currentProject, const int & currentIteration ) { int matches = 0; std::string project; std::string majorVersion; std::string minorVersion; std::string patch; std::vector< std::string > schemas; if ( MainForm->XMLSchema->GetSchemas( schemas ) ) { for ( std::vector< std::string >::iterator where = schemas.begin(); where != schemas.end(); ++where ) { if ( where->find( MASSUDWriter ) == 0 ) { if ( MainForm->XMLSchema->GetAttributeProperty( *where, "project", project ) && MainForm->XMLSchema->GetAttributeProperty( *where, "majorversion", majorVersion ) && MainForm->XMLSchema->GetAttributeProperty( *where, "minorversion", minorVersion ) && MainForm->XMLSchema->GetAttributeProperty( *where, "patch", patch ) ) { if ( ( currentProject == AnsiString( project.c_str() ).UpperCase() ) && ( currentIteration == atoi( majorVersion.c_str() ) ) ) { if ( !matches++ ) { schemaVersion.sprintf( "%d.%d.%d.%s", atoi( majorVersion.c_str() ), atoi( minorVersion.c_str() ), atoi( patch.c_str() ), project.c_str() ); } } } } } } if ( matches < 1 ) { std::stringstream stream; stream << "No schema found for \"" << currentProject.c_str() << "\" iteration " << currentIteration << ". " << "Please update \"" << MainForm->XMLSchema->Profile.c_str() << "\" such that exactly one " << MASSUDWriter << " schema is loaded for \"" << currentProject.c_str() << "\" iteration " << currentIteration << '.'; MessageDlg( stream.str().c_str(), mtError, TMsgDlgButtons() << mbOK, 0 ); } else if ( matches > 1 ) { std::stringstream stream; stream << "Found " << matches << " schemas for \"" << currentProject.c_str() << "\" iteration " << currentIteration << ". " << "There may be only one " << MASSUDWriter << " schema for an iteration. " << "Please update \"" << MainForm->XMLSchema->Profile.c_str() << "\" such that exactly one " << MASSUDWriter << " schema is loaded for \"" << currentProject.c_str() << "\" iteration " << currentIteration << '.'; MessageDlg( stream.str().c_str(), mtError, TMsgDlgButtons() << mbOK, 0 ); } return ( matches == 1 ); } //--------------------------------------------------------------------------- const bool __fastcall TIterationConfigForm::getUsername( AnsiString & usename ) { char name[ 256 ]; unsigned long size = sizeof( name ); if ( GetUserName( name, &size ) ) { usename = name; return ( true ); } return ( false ); } //--------------------------------------------------------------------------- void __fastcall TIterationConfigForm::IterationsQueryAfterInsert( TDataSet *DataSet) { DataSet->FieldByName("PROJECT_CODE")->AsString = m_currentproject; AnsiString name; if ( getUsername( name ) ) { DataSet->FieldByName( "USERNAME" )->AsString = name; } } //--------------------------------------------------------------------------- void __fastcall TIterationConfigForm::IterationsQueryBeforeDelete( TDataSet *DataSet) { /* * Delete all the data that exists for this iteration. They will * already have confirmed that they wish to delete this iteration. */ const AnsiString iteration = DataSet->FieldValues[ "ITERATION" ]; const AnsiString projectCode = DataSet->FieldValues[ "PROJECT_CODE" ]; DeleteIterationProcedure->Parameters->ParamValues[ "iteration" ] = iteration; DeleteIterationProcedure->Parameters->ParamValues[ "projectCode" ] = projectCode; DeleteIterationProcedure->ExecProc(); } //--------------------------------------------------------------------------- void __fastcall TIterationConfigForm::FormShow(TObject *Sender) { Apply->Enabled = ( IterationsQuery->State == dsEdit ); } //--------------------------------------------------------------------------- void __fastcall TIterationConfigForm::StoragePathChange(TObject *Sender) { Apply->Enabled = ( IterationsQuery->State == dsEdit ); } //--------------------------------------------------------------------------- void __fastcall TIterationConfigForm::NotesChange(TObject *Sender) { Apply->Enabled = ( IterationsQuery->State == dsEdit ); } //--------------------------------------------------------------------------- void __fastcall TIterationConfigForm::OKClick(TObject *Sender) { if ( IterationsQuery->State == dsEdit ) { IterationsQuery->Post(); } } //--------------------------------------------------------------------------- void __fastcall TIterationConfigForm::ApplyClick(TObject *Sender) { if ( IterationsQuery->State == dsEdit ) { IterationsQuery->Post(); } Apply->Enabled = ( IterationsQuery->State == dsEdit ); } //--------------------------------------------------------------------------- void __fastcall TIterationConfigForm::IterationsDataSourceUpdateData( TObject *Sender) { AnsiString name; if ( getUsername( name ) ) { IterationsQuery->FieldByName( "USERNAME" )->AsString = name; } AnsiString schemaVersion; if ( getSchemaDetails( schemaVersion, m_currentproject.UpperCase(), IterationsQuery->FieldByName( "ITERATION" )->AsInteger ) ) { IterationsQuery->FieldByName( "SCHEMA_VERSION" )->AsString = schemaVersion; } } //---------------------------------------------------------------------------