Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2265 kivins 1
//---------------------------------------------------------------------------
2
 
3
#include <vcl.h>
4
#pragma hdrstop
5
 
6
#include <vector>
7
#include <sstream>
8
#include "IterationConfig.h"
9
#include "DataModule.h"
10
#include "Main.h"
11
#include "Utilities.h"
12
//---------------------------------------------------------------------------
13
#pragma package(smart_init)
14
#pragma link "Grids_ts"
15
#pragma link "TSDBGrid"
16
#pragma link "TSGrid"
17
#pragma link "AdvGrid"
18
#pragma link "BaseGrid"
19
#pragma link "DBAdvGrd"
20
#pragma link "DBAdvGrid"
21
#pragma link "DBAdvGrd"
22
#pragma link "DBAdvNavigator"
23
#pragma resource "*.dfm"
24
TIterationConfigForm *IterationConfigForm;
25
//---------------------------------------------------------------------------
26
__fastcall TIterationConfigForm::TIterationConfigForm(TComponent* Owner)
27
	: TForm(Owner)
28
{
29
}
30
//---------------------------------------------------------------------------
31
void __fastcall TIterationConfigForm::CloseBtnClick(TObject *Sender)
32
{
33
	IterationsQuery->Post();
34
	IterationsQuery->Close();
35
 
36
	Close();
37
}
38
//---------------------------------------------------------------------------
39
 
40
void __fastcall TIterationConfigForm::ShowForm(const AnsiString &project_code)
41
{
42
	m_currentproject = project_code;
43
 
44
    AnsiString sql_statement;
45
	sql_statement.sprintf(
46
		"SELECT * FROM ITERATIONS WHERE PROJECT_CODE='%s' ORDER BY ITERATION",
47
		Utilities::EscapeString( m_currentproject ).c_str() );
48
	IterationsQuery->SQL->Text = sql_statement;
49
 
50
    IterationsQuery->Open();
51
 
52
    ShowModal();
53
}
54
//---------------------------------------------------------------------------
55
 
56
const bool __fastcall TIterationConfigForm::getSchemaDetails(
57
						AnsiString & schemaVersion,
58
						const AnsiString &	currentProject,
59
						const int &			currentIteration )
60
{
61
	int matches = 0;
62
 
63
	std::string project;
64
	std::string majorVersion;
65
	std::string minorVersion;
66
	std::string patch;
67
 
68
	std::vector< std::string > schemas;
69
 
70
	if ( MainForm->XMLSchema->GetSchemas( schemas ) )
71
	{
72
		for ( std::vector< std::string >::iterator where = schemas.begin();
73
			  where != schemas.end();
74
			  ++where )
75
		{
76
			if ( where->find( MASSUDWriter ) == 0 )
77
			{
78
				if ( MainForm->XMLSchema->GetAttributeProperty( *where, "project", project ) &&
79
					 MainForm->XMLSchema->GetAttributeProperty( *where, "majorversion", majorVersion ) &&
80
					 MainForm->XMLSchema->GetAttributeProperty( *where, "minorversion", minorVersion ) &&
81
					 MainForm->XMLSchema->GetAttributeProperty( *where, "patch", patch ) )
82
				{
83
					if ( ( currentProject == AnsiString( project.c_str() ).UpperCase() ) &&
84
						 ( currentIteration == atoi( majorVersion.c_str() ) ) )
85
					{
86
						if ( !matches++ )
87
						{
88
							schemaVersion.sprintf( "%d.%d.%d.%s",
89
								atoi( majorVersion.c_str() ),
90
								atoi( minorVersion.c_str() ),
91
								atoi( patch.c_str() ),
92
								project.c_str() );
93
						}
94
					}
95
				}
96
			}
97
		}
98
	}
99
 
100
	if ( matches < 1 )
101
	{
102
		std::stringstream stream;
103
		stream
104
			<< "No schema found for \"" << currentProject.c_str() << "\" iteration " << currentIteration << ".  "
105
			<< "Please update \"" << MainForm->XMLSchema->Profile.c_str() << "\" such that exactly one " << MASSUDWriter << " schema is loaded for \"" << currentProject.c_str() << "\" iteration " << currentIteration << '.';
106
		MessageDlg(
107
			stream.str().c_str(),
108
			mtError, TMsgDlgButtons() << mbOK, 0 );
109
	}
110
	else if ( matches > 1 )
111
	{
112
		std::stringstream stream;
113
		stream
114
			<< "Found " << matches << " schemas for \"" << currentProject.c_str() << "\" iteration " << currentIteration << ".  "
115
			<< "There may be only one " << MASSUDWriter << " schema for an iteration.  "
116
			<< "Please update \"" << MainForm->XMLSchema->Profile.c_str() << "\" such that exactly one " << MASSUDWriter << " schema is loaded for \"" << currentProject.c_str() << "\" iteration " << currentIteration << '.';
117
		MessageDlg(
118
			stream.str().c_str(),
119
			mtError, TMsgDlgButtons() << mbOK, 0 );
120
	}
121
 
122
	return ( matches == 1 );
123
}
124
//---------------------------------------------------------------------------
125
 
126
const bool __fastcall TIterationConfigForm::getUsername( AnsiString & usename )
127
{
128
	char name[ 256 ];
129
	unsigned long size = sizeof( name );
130
	if ( GetUserName( name, &size ) )
131
	{
132
		usename = name;
133
		return ( true );
134
	}
135
 
136
	return ( false );
137
}
138
//---------------------------------------------------------------------------
139
 
140
void __fastcall TIterationConfigForm::IterationsQueryAfterInsert(
141
	  TDataSet *DataSet)
142
{
143
	DataSet->FieldByName("PROJECT_CODE")->AsString = m_currentproject;
144
 
145
	AnsiString name;
146
	if ( getUsername( name ) )
147
	{
148
		DataSet->FieldByName( "USERNAME" )->AsString = name;
149
	}
150
}
151
//---------------------------------------------------------------------------
152
 
153
 
154
void __fastcall TIterationConfigForm::IterationsQueryBeforeDelete(
155
	  TDataSet *DataSet)
156
{
157
	/*
158
	 *	Delete all the data that exists for this iteration.  They will
159
	 *	already have confirmed that they wish to delete this iteration.
160
	 */
161
 
162
	const AnsiString iteration		= DataSet->FieldValues[ "ITERATION" ];
163
	const AnsiString projectCode	= DataSet->FieldValues[ "PROJECT_CODE" ];
164
 
165
	DeleteIterationProcedure->Parameters->ParamValues[ "iteration" ] = iteration;
166
	DeleteIterationProcedure->Parameters->ParamValues[ "projectCode" ] = projectCode;
167
	DeleteIterationProcedure->ExecProc();
168
}
169
//---------------------------------------------------------------------------
170
 
171
void __fastcall TIterationConfigForm::FormShow(TObject *Sender)
172
{
173
	Apply->Enabled = ( IterationsQuery->State == dsEdit );
174
}
175
//---------------------------------------------------------------------------
176
 
177
void __fastcall TIterationConfigForm::StoragePathChange(TObject *Sender)
178
{
179
	Apply->Enabled = ( IterationsQuery->State == dsEdit );
180
}
181
//---------------------------------------------------------------------------
182
 
183
void __fastcall TIterationConfigForm::NotesChange(TObject *Sender)
184
{
185
	Apply->Enabled = ( IterationsQuery->State == dsEdit );
186
}
187
//---------------------------------------------------------------------------
188
 
189
void __fastcall TIterationConfigForm::OKClick(TObject *Sender)
190
{
191
	if ( IterationsQuery->State == dsEdit )
192
	{
193
		IterationsQuery->Post();
194
	}
195
}
196
//---------------------------------------------------------------------------
197
 
198
void __fastcall TIterationConfigForm::ApplyClick(TObject *Sender)
199
{
200
	if ( IterationsQuery->State == dsEdit )
201
	{
202
		IterationsQuery->Post();
203
	}
204
 
205
	Apply->Enabled = ( IterationsQuery->State == dsEdit );
206
}
207
//---------------------------------------------------------------------------
208
 
209
void __fastcall TIterationConfigForm::IterationsDataSourceUpdateData(
210
	  TObject *Sender)
211
{
212
	AnsiString name;
213
	if ( getUsername( name ) )
214
	{
215
		IterationsQuery->FieldByName( "USERNAME" )->AsString = name;
216
	}
217
 
218
	AnsiString schemaVersion;
219
	if ( getSchemaDetails(
220
			schemaVersion,
221
			m_currentproject.UpperCase(),
222
			IterationsQuery->FieldByName( "ITERATION" )->AsInteger ) )
223
	{
224
		IterationsQuery->FieldByName( "SCHEMA_VERSION" )->AsString = schemaVersion;
225
	}
226
}
227
//---------------------------------------------------------------------------
228