Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2218 sbetterm 1
//---------------------------------------------------------------------------
2
 
3
#pragma warn -com
4
#include <LoggingMacros.h>
5
#pragma warn +com
6
 
7
#include <vcl.h>
8
#pragma hdrstop
9
 
10
#include "stdio.h"
11
#include "io.h"
12
#include "dir.h"
13
#include "RunTests.h"
14
#include "Utilities.h"
15
 
16
#define	MASSUDWriter	"MASSUDWriter"
17
 
18
#define ADV_PROGRESS_BAR
19
//#define STORE_IN_DATABASE
20
#define STORE_PAYLOAD
21
#define INITIALISETXNSTRUCTURE
22
 
23
//---------------------------------------------------------------------------
24
#pragma package(smart_init)
25
#pragma link "Grids_ts"
26
#pragma link "TSDBGrid"
27
#pragma link "TSGrid"
28
#pragma link "AdvProgressBar"
29
#pragma resource "*.dfm"
30
TRunTestsForm *RunTestsForm;
31
 
32
 
33
//---------------------------------------------------------------------------
34
/**
35
 *	Process paint message.
36
 */
37
void ProcessPaintMessages( HWND Handle )
38
{
39
	MSG msg;
40
	while ( PeekMessage( &msg, Handle, WM_PAINT, WM_PAINT, PM_REMOVE ) )
41
	{
42
		DispatchMessage( &msg );
43
	}
44
}
45
 
46
 
47
//---------------------------------------------------------------------------
48
__fastcall TRunTestsForm::TRunTestsForm(TComponent* Owner)
49
	: TForm(Owner)
50
{
51
}
52
//---------------------------------------------------------------------------
53
 
54
/**
55
 *	Get the collection of schemas and find our schema in that collection.
56
 */
57
 
58
const bool TRunTestsForm::findSchema( vector< AnsiString > &	xmlSchemas,
59
									  TXMLSchema &				schema,
60
									  const AnsiString &		currentProject,
61
									  const int &				currentIteration )
62
{
63
	vector< string > schemas;
64
	if ( schema.GetSchemas( schemas ) )
65
	{
66
		AnsiString theSchema;
67
		for ( vector< string >::iterator what = schemas.begin();
68
			  what != schemas.end();
69
			  ++what )
70
		{
71
			theSchema = what->c_str();
72
 
73
			if ( theSchema.Pos( MASSUDWriter ) == 1 )
74
			{
75
				xmlSchemas.push_back( theSchema );
76
			}
77
		}
78
	}
79
 
80
	string handle;
81
	for ( vector< AnsiString >::iterator where = xmlSchemas.begin();
82
		  where != xmlSchemas.end();
83
		  ++where )
84
	{
85
		handle = where->c_str();
86
 
87
		vector< string >	schema_structures;
88
		string				project;
89
		string				majorversion;
90
 
91
		schema.GetAttributeProperty( handle, "project", project );
92
 
93
		if ( currentProject.UpperCase() == AnsiString( project.c_str() ).UpperCase() )
94
		{
95
			schema.GetAttributeProperty( handle, "majorversion", majorversion );
96
 
97
			if ( currentIteration == atoi( majorversion.c_str() ) )
98
			{
99
				return ( true );
100
			}
101
		}
102
	}
103
 
104
	return ( false );
105
}
106
 
107
 
108
//---------------------------------------------------------------------------
109
/**
110
 *	Build the transaction map for faster lookup.
111
 */
112
 
113
void TRunTestsForm::buildTranactionMap( TXNIndexMap &		transactions,
114
										const AnsiString &	currentProject,
115
										const int &			currentIteration )
116
{
117
	TADOQuery *	query = 0;
118
	try
119
	{
120
		query = new TADOQuery( this );
121
		query->Connection = Data_Module->IntegrationDBConnection;
122
 
123
		AnsiString sql_statement;
124
		sql_statement.sprintf(
125
			"SELECT "
126
				"NAME, "
127
				"UDTYPE, "
128
				"UDSUBTYPE "
129
			"FROM "
130
				"MASS_TXNS "
131
			"WHERE "
132
				"PROJECTCODE=\'%s\' AND "
133
				"ITERATION=%d ",
134
			currentProject.c_str(),
135
			currentIteration );
136
 
137
		query->SQL->Text = sql_statement;
138
		query->Open();
139
 
140
		unsigned short	udtype		= 0;
141
		unsigned short	udsubtype	= 0;
142
		unsigned int	udindex		= 0;
143
		while ( !query->Eof )
144
		{
145
			udtype 		= query->FieldByName( "UDTYPE" )->AsInteger;
146
			udsubtype 	= query->FieldByName( "UDSUBTYPE" )->AsInteger;
147
			udindex 	= ( udtype << 16 ) + udsubtype;
148
 
149
			transactions.insert( TXNIndexPair(
150
				udindex,
151
				query->FieldByName( "NAME" )->AsString ) );
152
 
153
			query->Next();
154
		}
155
	}
156
	__finally
157
	{
158
		delete query;
159
		query = 0;
160
	}
161
}
162
 
163
 
164
//---------------------------------------------------------------------------
165
/**
166
 *	Substitute any macros with the appropriate value.
167
 */
168
AnsiString & TRunTestsForm::substituteMacro( AnsiString & value, const unsigned short & udType )
169
{
170
	if ( value == "@ACCOUNTTYPE" )
171
	{
172
		int	accountFormat = 0;
173
		switch ( udType )
174
		{
175
		case 1:	// Card
176
			accountFormat = 2;
177
			break;
178
		case 2:	// Application
179
			accountFormat = 1;
180
			break;
181
		case 3:	// Product
182
			accountFormat = 3;
183
			break;
184
		case 4:	// Other
185
			accountFormat = 4;
186
			break;
187
		case 5:	// Audit
188
			accountFormat = 4;
189
			break;
190
		case 6:	// Event
191
			accountFormat = 4;
192
			break;
193
		case 7:	// Project
194
			accountFormat = 4;
195
			break;
196
		} // switch
197
 
198
		value.sprintf( "%d", accountFormat );
199
	}
200
	return ( value );
201
}
202
 
203
 
204
//---------------------------------------------------------------------------
205
/**
206
 *	Evaluate to true when the given value is a macro, and to false otherwise.
207
 */
208
const bool TRunTestsForm::isMacro( const string & value )
209
{
210
	return ( value == "@ACCOUNTTYPE" );
211
}
212
 
213
 
214
//---------------------------------------------------------------------------
215
/**
216
 *	Build the header that we use as the basis for prefixing each transaction
217
 *	when prefixing is required.
218
 */
219
 
220
void TRunTestsForm::buildHeader( string &							handle,
221
								 TXMLSchema &						schema,
222
								 vector< pair< string, string > > &	macros,
223
								 const AnsiString &					currentProject,
224
								 const int &						currentIteration )
225
{
226
	const char * headerStructure = "SysHdr_t";
227
 
228
	TADOQuery *	query = 0;
229
	try
230
	{
231
		try
232
		{
233
			if ( schema.Create( headerStructure, currentIteration, handle, 0 ) )
234
			{
235
				query = new TADOQuery( this );
236
				query->Connection = Data_Module->IntegrationDBConnection;
237
 
238
				AnsiString sqlStatement;
239
				sqlStatement.sprintf(
240
					"SELECT "
241
						"* "
242
					"FROM "
243
						"TXNHDR_VALUES "
244
					"WHERE "
245
						"PROJECT_CODE=\'%s\' AND "
246
						"ITERATION=%d ",
247
					currentProject.c_str(),
248
					currentIteration );
249
 
250
				query->SQL->Text = sqlStatement;
251
				query->Open();
252
 
253
				string fieldName;
254
				string fieldValue;
255
				string attributePath;
256
				string valuemap;
257
 
258
				while ( !query->Eof )
259
				{
260
					fieldName	= query->FieldByName( "FIELDNAME" )->AsString.c_str();
261
					fieldValue	= query->FieldByName( "FIELDVALUE" )->AsString.c_str();
262
 
263
					if ( !isMacro( fieldValue ) )
264
					{
265
						attributePath = handle + "." + fieldName;
266
						m_XMLSchema->GetAttributeProperty( attributePath, "valuemap", valuemap );
267
 
268
						if ( valuemap.empty() )
269
						{
270
//							string fieldDatatype;
271
//							schema.GetAttributeProperty( attributePath, "datatype", fieldDatatype );
272
 
273
							if ( fieldValue[ 0 ] == '-' )
274
							{
275
								schema.SetAttributeValue( handle, fieldName.c_str(), atoi( fieldValue.c_str() ) );
276
							}
277
							else
278
							{
279
								schema.SetAttributeValue( handle, fieldName.c_str(), fieldValue.c_str());
280
							}
281
						}
282
						else
283
						{
284
							if ( ( fieldValue[ 0 ] >= '0' && fieldValue[ 0 ] <= '9' ) ||
285
								 ( fieldValue[ 0 ] == '-' && fieldValue[ 1 ] >= '0' && fieldValue[ 1 ] <= '9' ) )
286
							{
287
								schema.SetAttributeValue( handle, fieldName.c_str(), atoi( fieldValue.c_str() ) );
288
							}
289
							else
290
							{
291
								schema.SetAttributeValue( handle, fieldName.c_str(), fieldValue.c_str());
292
							}
293
						}
294
					}
295
					else
296
					{
297
						macros.push_back( std::pair< std::string, std::string >(
298
							fieldName,
299
							fieldValue ) );
300
					}
301
 
302
					query->Next();
303
				}
304
 
305
				query->Close();
306
			}
307
			else
308
			{
309
				MessageDlg( "Failed to create header structure",
310
					mtError,
311
					TMsgDlgButtons() << mbOK,
312
 
313
				MTHROW( std::runtime_error, \
314
					"Cannot create \"" \
315
					<< headerStructure \
316
					<< "\", version " \
317
					<< currentIteration \
318
					<< '.' );
319
			}
320
		}
321
		catch ( ... )
322
		{
323
			if ( !handle.empty() )
324
			{
325
				schema.Destroy( handle );
326
				handle = "";
327
			}
328
			throw;
329
		}
330
	}
331
	__finally
332
	{
333
		delete query;
334
		query = 0;
335
	}
336
}
337
 
338
 
339
//---------------------------------------------------------------------------
340
/**
341
 *	Replace the given macros.
342
 */
343
void TRunTestsForm::substituteMacros(
344
		string &									handle,
345
		TXMLSchema &								schema,
346
		const vector< pair< string, string > > &	macros,
347
		const unsigned short &						udType )
348
{
349
	AnsiString value;
350
	for ( vector< pair< string, string > >::const_iterator
351
			where = macros.begin();
352
		  where != macros.end();
353
		  ++where )
354
	{
355
		schema.SetAttributeValue(
356
			handle,
357
			where->first.c_str(),
358
			substituteMacro( value = where->second.c_str(), udType ).c_str() );
359
	}
360
}
361
 
362
 
363
 
364
//---------------------------------------------------------------------------
365
/**
366
 *	Load transaction parameters.
367
 */
368
void TRunTestsForm::loadParameters( IterationParams &	parameters,
369
									const int &			testScenario,
370
									const int &			transactionSpecification )
371
{
372
	TADOQuery * query = 0;
373
 
374
	try
375
	{
376
		AnsiString sql_statement;
377
		sql_statement.sprintf(
378
			"SELECT "
379
				"FIELDNAME, "
380
				"SUBSCRIPT, "
381
				"FIELDVALUE "
382
			"FROM "
383
				"TXNSPEC_VALUES "
384
			"WHERE "
385
				"TESTSCENARIO_NO=%d AND "
386
				"TXNSPEC_NO=%d AND "
387
				"( FIELDVALUE IS NOT NULL OR FIELDVALUE<>\'\')",
388
			testScenario,
389
			transactionSpecification );
390
 
391
 
392
		query = new TADOQuery( 0 );
393
		query->Connection = Data_Module->IntegrationDBConnection;
394
		query->SQL->Text = sql_statement;
395
 
396
		query->Open();
397
		AnsiString field;
398
		while ( !query->Eof )
399
		{
400
 
401
			if ( query->FieldByName( "SUBSCRIPT" )->AsInteger == 0 )
402
			{
403
				field = query->FieldByName( "FIELDNAME" )->AsString;
404
			}
405
			else
406
			{
407
				field.sprintf( "%s.%d",
408
								 query->FieldByName( "FIELDNAME" )->AsString.c_str(),
409
								 query->FieldByName( "SUBSCRIPT" )->AsInteger );
410
			}
411
 
412
			parameters.insert(
413
				IterationParamsPair(
414
					field.c_str(),
415
					query->FieldByName( "FIELDVALUE" )->AsString.c_str() ) );
416
 
417
			query->Next();
418
		}
419
	}
420
	__finally
421
	{
422
		delete query;
423
		query = 0;
424
	}
425
}
426
 
427
 
428
//---------------------------------------------------------------------------
429
/**
430
 *	Get the value of the key assigned last to the named table.
431
 */
432
const unsigned int getLastAssignedSk( TADOConnection * database, const char * tableName )
433
{
434
    unsigned int	value	= 0;
435
    AnsiString		sqlQuery;
436
    TADOQuery *		query	= 0;
437
 
438
    try
439
    {
440
        query = new TADOQuery( 0 );
441
        query->Connection = database;
442
 
443
        AnsiString sequenceName;
444
        sequenceName.sprintf( "%s_SK", tableName );
445
 
446
        sqlQuery.sprintf(
447
			"SELECT FN_SEQ_CURRVAL( \'%s\' ) FROM DUAL",
448
			sequenceName );
449
        query->SQL->Text = sqlQuery;
450
        query->Open();
451
        value = query->Fields->Fields[ 0 ]->AsInteger;
452
    }
453
    __finally
454
    {
455
        query->Close();
456
        delete query;
457
    }
458
 
459
    return value;
460
}
461
 
462
 
463
//---------------------------------------------------------------------------
464
/**
465
 *	Create an instance of the given scenario, and evaluate to its key.
466
 */
467
void createScenario( TADOConnection * database, int & key, const unsigned int & testScenario )
468
{
469
	TADOQuery *	query = 0;
470
 
471
	try
472
	{
473
		query = new TADOQuery( 0 );
474
		query->Connection = database;
475
 
476
		AnsiString sqlQuery;
477
		sqlQuery.sprintf(
478
			"INSERT INTO GENERATED_SCENARIO( TEST_SCENARIO_FK ) VALUES ( %u )",
479
			testScenario );
480
 
481
		query->SQL->Text = sqlQuery;
482
		query->ExecSQL();
483
 
484
		key = getLastAssignedSk( database, "GENERATED_SCENARIO" );
485
    }
486
    __finally
487
    {
488
        query->Close();
489
        delete query;
490
    }
491
}
492
 
493
 
494
//---------------------------------------------------------------------------
495
/**
496
 *	Create a batch for the given scenario instance, and evaluate to its key.
497
 */
498
void createBatch( TADOConnection * database, int & key, const unsigned int & number, const int & scenario )
499
{
500
	TADOQuery *	query = 0;
501
 
502
	try
503
	{
504
		query = new TADOQuery( 0 );
505
		query->Connection = database;
506
 
507
		AnsiString sqlQuery;
508
		sqlQuery.sprintf(
509
			"INSERT INTO GENERATED_BATCH( GENERATED_SCENARIO_FK, SEQUENCE_NUMBER ) VALUES ( %d, %u )",
510
			scenario,
511
			number );
512
 
513
		query->SQL->Text = sqlQuery;
514
		query->ExecSQL();
515
 
516
		key = getLastAssignedSk( database, "GENERATED_BATCH" );
517
    }
518
    __finally
519
    {
520
        query->Close();
521
        delete query;
522
    }
523
}
524
 
525
 
526
//---------------------------------------------------------------------------
527
/**
528
 *	Create a transaction for the given batch and transaction specification,
529
 *	and evaluate to its key.
530
 */
531
void createTransaction( TADOConnection *		database,
532
						int &					key,
533
						const int &				batch,
534
						const int &				transactionSpecification,
535
						TMemoryStream *			payload )
536
{
537
	TADOQuery *	query = 0;
538
 
539
	try
540
	{
541
		query = new TADOQuery( 0 );
542
		query->Connection = database;
543
 
544
		/**
545
		 *	This is a strange way of going about inserting a row, but it 
546
		 *	seems to be the only one that works with Oracle.
547
		 */
548
		query->SQL->Text = "SELECT * FROM GENERATED_TRANSACTION";
549
		query->Open();
550
		query->Append();
551
 
552
		query->FieldByName( "GENERATED_BATCH_FK" )->AsInteger = batch;
553
		query->FieldByName( "TRANSACTION_SPECIFICATION_FK" )->AsInteger = transactionSpecification;
554
 
555
		TBlobField *blob = dynamic_cast< TBlobField * >( query->FieldByName( "PAYLOAD" ) );
556
		if ( blob )
557
		{
558
			blob->LoadFromStream( payload );
559
		}
560
 
561
		query->Post();
562
 
563
		key = getLastAssignedSk( database, "GENERATED_TRANSACTION" );
564
	}
565
	__finally
566
	{
567
		query->Close();
568
        delete query;
569
    }
570
}
571
 
572
 
573
//---------------------------------------------------------------------------
574
/**
575
 *	Generate the given transaction.
576
 */
577
void TRunTestsForm::generateScenario( const unsigned int &						testscenario_no,
578
									  TXNIndexMap &								mass_txns,
579
									  const bool &								isTds,
580
									  string &									headerHandle,
581
									  TransactionSchedule &						transactionSchedule,
582
									  const vector< pair< string, string > > &	macros,
583
									  const unsigned int &						repeatCount,
584
									  const unsigned int &						total,
585
									  const int &								batchSk )
586
{
587
	TMemoryStream *	payload	= 0;
588
 
589
	try
590
	{
591
		payload = new TMemoryStream();
592
 
593
		bool	txngen_error	= false;
594
#ifdef STORE_IN_DATABASE
595
		int		transactionSk	= 0;
596
#endif
597
		for ( TransactionSchedule::iterator
598
				transaction = transactionSchedule.begin();
599
			  !txngen_error && transaction != transactionSchedule.end();
600
			  ++transaction )
601
		{
602
			payload->Clear();
603
#if 1
604
			// If this is a TDS then prefix with a SysHdr_t
605
			if ( isTds )	// TDS
606
			{
607
				substituteMacros( headerHandle, *m_XMLSchema, macros, transaction->second->getUdType() );
608
 
609
				const string	streamtype	= "XDR";
610
				const string	stream_args;
611
				void *			stream		= 0;
612
				unsigned int	stream_size	= 0;
613
 
614
				if ( m_XMLSchema->Serialise( headerHandle, streamtype, stream_args, stream, stream_size, 0, 0 ) )
615
				{
616
					payload->Write( stream, stream_size );
617
				}
618
			}
619
 
620
#ifdef INITIALISETXNSTRUCTURE
621
			// Initialise our transaction artefact with its parameters
622
			if ( InitialiseTxnStructure(
623
					transaction->second->getHandle(),
624
					0,
625
					transaction->second->getIterationParameters() ) )
626
#endif
627
			{
628
				// If we have initialised the Txn successfully then Serialise the outcome
629
 
630
				const string	streamtype = "XDR";
631
				const string	stream_args;
632
				void *			stream = 0;
633
				unsigned int	stream_size = 0;
634
 
635
				if ( m_XMLSchema->Serialise(
636
						transaction->second->getHandle(),
637
						streamtype,
638
						stream_args,
639
						stream,
640
						stream_size,
641
						0,
642
 
643
				{
644
					payload->Write( stream, stream_size );
645
#ifdef STORE_IN_DATABASE
646
					createTransaction(
647
						Data_Module->IntegrationDBConnection,
648
						transactionSk,
649
						batchSk,
650
						transaction->first,
651
						payload );
652
#endif
653
					}
654
				else
655
				{
656
					AnsiString	msg;
657
					msg.sprintf(
658
						"Failed to serialise txn \'%s\' for \'%s\'",
659
						transaction->second->getName().c_str(),
660
						m_testcase.c_str() );
661
 
662
					MessageDlg(msg, mtError, TMsgDlgButtons() << mbOK, 0);
663
 
664
					txngen_error = true;
665
				}
666
			}
667
#ifdef INITIALISETXNSTRUCTURE
668
			else
669
			{
670
				txngen_error = true;
671
			}
672
#endif
673
#endif
674
		} // while
675
	}
676
	__finally
677
	{
678
		delete payload;
679
		payload = 0;
680
	}
681
}
682
 
683
 
684
//---------------------------------------------------------------------------
685
/**
686
 *	Read the transaction schedule for the given test scenario.
687
 */
688
void TRunTestsForm::readTransactionSchedule( TADOConnection *		database,
689
											 TXMLSchema &			schema,
690
											 const int &			currentIteration,
691
											 TXNIndexMap &			massTransactions,
692
											 const int &			testScenario,
693
											 TransactionSchedule &	transactionSchedule )
694
{
695
	TADOQuery *	query = 0;
696
	try
697
	{
698
		query = new TADOQuery( 0 );
699
		query->Connection = database;
700
 
701
		AnsiString sqlQuery;
702
		sqlQuery.sprintf(
703
			"SELECT "
704
				"TXNSPEC_NO, "
705
				"UDTYPE, "
706
				"UDSUBTYPE "
707
			"FROM "
708
				"TRANSACTION_SPECIFICATION "
709
			"WHERE "
710
				"TESTSCENARIO_NO=%d "
711
			"ORDER BY "
712
				"SEQ_NO",
713
			testScenario );
714
 
715
		query->SQL->Text = sqlQuery;
716
 
717
		pair< TransactionSchedule::iterator, bool > where;
718
		int						transactionSpecification	= 0;
719
		unsigned short			udType						= 0;
720
		unsigned short			udSubtype					= 0;
721
		TransactionArtefact *	transactionArtefact			= 0;
722
		string					handle;
723
		TXNIndexMap::iterator	transaction;
724
		string					structureName;
725
 
726
		for ( query->Open(); !query->Eof; query->Next() )
727
		{
728
			transactionSpecification	= query->FieldByName( "TXNSPEC_NO" )->AsInteger;
729
			udType						= query->FieldByName( "UDTYPE" )->AsInteger;
730
			udSubtype					= query->FieldByName( "UDSUBTYPE" )->AsInteger;
731
 
732
			// Resolve the UD type and subtype into a structure name.
733
			transaction = massTransactions.find( ( udType << 16 ) + udSubtype );
734
			if ( transaction != massTransactions.end() )
735
			{
736
				structureName = transaction->second.c_str();
737
 
738
				where = transactionSchedule.insert(
739
					TransactionSchedule::value_type( transactionSpecification, 0 ) );
740
				if ( where.second )
741
				{
742
					try
743
					{
744
						transactionArtefact = new TransactionArtefact(
745
							schema,
746
							structureName,
747
							udType );
748
 
749
						if ( schema.Create( "",
750
											structureName.c_str(),
751
											currentIteration,
752
											handle,
753
 
754
						{
755
							where.first->second = transactionArtefact;
756
							transactionArtefact->setHandle( handle );
757
						}
758
						else
759
						{
760
							MTHROW( std::runtime_error, \
761
								"Cannot create structure \"" \
762
								<< structureName \
763
								<< "\" for iteration " \
764
								<< currentIteration \
765
								<< '.' );
766
						}
767
 
768
						loadParameters(
769
							transactionArtefact->getIterationParameters(),
770
							testScenario,
771
							transactionSpecification );
772
					}
773
					catch ( ... )
774
					{
775
						delete transactionArtefact;
776
						transactionArtefact = 0;
777
 
778
						transactionSchedule.erase( where.first );
779
 
780
						throw;
781
					}
782
				}
783
				else
784
				{
785
					MTHROW( std::runtime_error, \
786
						"Cannot cache handle for structure \"" \
787
						<< structureName \
788
						<< "\"." );
789
				}
790
			}
791
			else
792
			{
793
				MTHROW( std::runtime_error, \
794
					"Cannot find structure for UD type " \
795
					<< udType \
796
					<< ", subtype " \
797
					<< udSubtype \
798
					<< '.' );
799
			}
800
		}
801
    }
802
    __finally
803
    {
804
        query->Close();
805
        delete query;
806
    }
807
}
808
 
809
 
810
//---------------------------------------------------------------------------
811
/**
812
 *	Generate the given test case.
813
 */
814
void TRunTestsForm::generateTestCase( void )
815
{
816
#ifdef ADV_PROGRESS_BAR
817
	m_progressBar->Show();
818
	m_progressBar->Position = 0;
819
#else
820
	m_progressBarOld->Show();
821
	m_progressBarOld->Position = 0;
822
#endif
823
 
824
	const bool isTds = ( GenerationTargetComboBox->ItemIndex == 1 );
825
 
826
	TransactionSchedule	transactionSchedule;
827
 
828
	TADOQuery * query = 0;
829
	try
830
	{
831
		const bool foundSchema = findSchema(
832
			m_xml_schemas,
833
			*m_XMLSchema,
834
			m_currentproject,
835
			m_currentiteration );
836
 
837
		// Did we find the Target XML Writer Schema ?
838
		if ( foundSchema )
839
		{
840
			/**
841
			 *	When we need a header, then create the header that we'll 
842
			 *	prepend to every transaction.  Macros are evaluated later,
843
			 *	so we need to remember them until then.
844
			 */
845
			string headerHandle;
846
			vector< pair< string, string > > macros;
847
			if ( isTds )
848
			{
849
				buildHeader(
850
					headerHandle,
851
					*m_XMLSchema,
852
					macros,
853
					m_currentproject,
854
					m_currentiteration );
855
			}
856
 
857
			Data_Module->IntegrationDBConnection->BeginTrans();
858
 
859
			AnsiString	sql_statement;
860
 
861
			query = new TADOQuery( this );
862
			query->Connection = Data_Module->IntegrationDBConnection;
863
 
864
			// Build a MASS Txn Map for fast lookup
865
			TXNIndexMap mass_txns;
866
			buildTranactionMap( mass_txns, m_currentproject, m_currentiteration );
867
 
868
			// Process ALL TestScenarios, in order, for this TestCase
869
 
870
			bool	txngen_error = false;
871
 
872
			sql_statement="";
873
			sql_statement.sprintf("select testscenario_no,testcase_seqno,name,repeat_count,batch_size "
874
								  "from test_scenarios "
875
								  "where project_code='%s' and iteration=%d "
876
								  "and testcase_id='%s' "
877
								  "order by testcase_seqno",
878
								  m_currentproject.c_str(),
879
								  m_currentiteration,
880
								  m_testcase.c_str());
881
 
882
			query->SQL->Text = sql_statement;
883
 
884
			/**
885
			 *	First, we traverse the result set to scope out the work that
886
			 *	we're about to embark upon.  We use this as an indication of
887
			 *	progress.
888
			 */
889
			query->Open();
890
			unsigned int total = 0;
891
			unsigned int count = 0;
892
			while ( !query->Eof )
893
			{
894
				total += ( !query->FieldByName("REPEAT_COUNT")->IsNull
895
					? query->FieldByName("REPEAT_COUNT")->AsInteger
896
					: 1 );
897
				query->Next();
898
			}
899
			query->Close();
900
 
901
			/**
902
			 *	Now we traverse the result set to actually do the work.
903
			 */
904
			query->Open();
905
			TDateTime beginning	= TDateTime::CurrentDateTime();
906
			TDateTime now		= TDateTime::CurrentDateTime();
907
			TDateTime update	= TDateTime::CurrentDateTime();
908
			const TDateTime step( 0, 0, 2, 500 );
909
			double duration;
910
			double estimate;
911
			double scale = 0.0;
912
			AnsiString progress;
913
 
914
#ifdef STORE_IN_DATABASE
915
			int scenarioSk	= 0;
916
#endif
917
			int batchSk		= 0;
918
			int batchNumber	= 0;
919
			unsigned int batchLength	= 0;
920
			while ( !txngen_error && !query->Eof )
921
			{
922
				const unsigned int testscenario_no	= query->FieldByName( "TESTSCENARIO_NO" )->AsInteger;
923
				const unsigned int repeatCount		= ( !query->FieldByName( "REPEAT_COUNT" )->IsNull
924
					? query->FieldByName("REPEAT_COUNT")->AsInteger
925
					: 1 );
926
				const unsigned int batchSize		= ( !query->FieldByName( "BATCH_SIZE" )->IsNull
927
					? query->FieldByName("batch_size")->AsInteger
928
					: 1 );
929
				const AnsiString name				= query->FieldByName("NAME")->AsString.c_str();
930
 
931
				AnsiString	testcase_desc;
932
				testcase_desc.sprintf("(%d) %s",
933
									  query->FieldByName("TESTCASE_SEQNO")->AsInteger,
934
									  name.c_str()
935
									  );
936
 
937
				readTransactionSchedule(
938
					Data_Module->IntegrationDBConnection,
939
					*m_XMLSchema,
940
					m_currentiteration,
941
					mass_txns,
942
					testscenario_no,
943
					transactionSchedule );
944
				batchNumber	= 1;
945
				batchLength	= 0;
946
#ifdef STORE_IN_DATABASE
947
				createScenario(
948
					Data_Module->IntegrationDBConnection,
949
					scenarioSk,
950
					testscenario_no );
951
				createBatch(
952
					Data_Module->IntegrationDBConnection,
953
					batchSk,
954
					batchNumber,
955
					scenarioSk );
956
#endif
957
//				TTreeNode *testcase_node = TestCaseTxnTreeView->Items->AddObject(NULL, testcase_desc, (void *)testscenario_no);
958
 
959
				/**
960
				 *	Determine the set of Transaction Specifications for the ordered
961
				 *	set of test scenarios
962
				 */
963
				for ( unsigned int i=0; i<repeatCount; ++i )
964
				{
965
					if ( batchLength >= batchSize )
966
					{
967
						++batchNumber;
968
						batchLength = 1;
969
 
970
#ifdef STORE_IN_DATABASE
971
						createBatch(
972
							Data_Module->IntegrationDBConnection,
973
							batchSk,
974
							batchNumber,
975
							scenarioSk );
976
#endif
977
					}
978
					else
979
					{
980
						++batchLength;
981
					}
982
					generateScenario(
983
						testscenario_no,
984
						mass_txns,
985
						isTds,
986
						headerHandle,
987
						transactionSchedule,
988
						macros,
989
						repeatCount,
990
						total,
991
						batchSk );
992
					++count;
993
 
994
					now = TDateTime::CurrentDateTime();
995
					if ( now - update >= step )
996
					{
997
						scale = double( total ) / double( count );
998
						duration = now - beginning;
999
						estimate = ( duration * scale ) - duration;
1000
						StatusBar->Panels->Items[0]->Text = "Estimated Time Remaining: " + TDateTime( estimate ).FormatString( "tt" );
1001
 
1002
						progress.sprintf( "Count: %d, avg: %f ms/t",
1003
							count,
1004
							( duration / count ) * 24 * 60 * 60 * 1000 );
1005
						StatusBar->Panels->Items[1]->Text = progress;
1006
 
1007
						ProcessPaintMessages( StatusBar->Handle );
1008
 
1009
						update = now;
1010
					}
1011
#ifdef ADV_PROGRESS_BAR
1012
					if ( m_progressBar->Position != int( count / double( total ) * 100.0 ) )
1013
					{
1014
						m_progressBar->Position = int( count / double( total ) * 100.0 );
1015
					}
1016
#else
1017
					m_progressBarOld->Position = count / double( total ) * 100.0;
1018
#endif
1019
				}
1020
 
1021
				query->Next();
1022
			} // while
1023
 
1024
			StatusBar->Panels->Items[0]->Text = "";
1025
			StatusBar->Panels->Items[1]->Text = "";
1026
 
1027
			if (!txngen_error)
1028
			{
1029
				Data_Module->IntegrationDBConnection->CommitTrans();
1030
			}
1031
		}
1032
		else
1033
		{
1034
			AnsiString	msg;
1035
 
1036
			msg.sprintf("Failed to locate XML for %s (%s) Iteration: %d\nPlease verify XMLSchema.ini",
1037
						MASSUDWriter,
1038
						m_currentproject.c_str(),
1039
						m_currentiteration
1040
						);
1041
 
1042
        	MessageDlg(msg.c_str(),
1043
            		   mtError, TMsgDlgButtons() << mbOK, 0);
1044
        }
1045
    }
1046
    __finally
1047
    {
1048
		delete query;
1049
		query = 0;
1050
 
1051
    	if (Data_Module->IntegrationDBConnection->InTransaction)
1052
        {
1053
			Data_Module->IntegrationDBConnection->RollbackTrans();
1054
		}
1055
 
1056
		// Clear the transaction schedule.
1057
		for ( TransactionSchedule::iterator where = transactionSchedule.begin();
1058
			  where != transactionSchedule.end();
1059
			  ++where )
1060
		{
1061
			delete where->second;
1062
			where->second = 0;
1063
		}
1064
		transactionSchedule.clear();
1065
 
1066
#ifdef ADV_PROGRESS_BAR
1067
		m_progressBar->Hide();
1068
#else
1069
		m_progressBarOld->Hide();
1070
#endif
1071
	}
1072
}
1073
 
1074
 
1075
//---------------------------------------------------------------------------
1076
void __fastcall TRunTestsForm::GenerateTransactionsClick(TObject *Sender)
1077
{
1078
	const TCursor Save_Cursor = Screen->Cursor;
1079
	Screen->Cursor = crHourGlass;
1080
 
1081
	try
1082
	{
1083
		TestCaseTxnTreeView->Items->Clear();
1084
		generateTestCase();
1085
		MWARNING( "TODO: rebuild tree view." );
1086
	}
1087
	__finally
1088
	{
1089
		Screen->Cursor = Save_Cursor;
1090
	}
1091
}
1092
 
1093
 
1094
//---------------------------------------------------------------------------
1095
bool __fastcall TRunTestsForm::InitialiseTxnStructure(const string &structure_handle, int subscript, IterationParams &structure_params)
1096
{
1097
    vector<string>				structure_attributes;
1098
    vector<string>::iterator	s_itr;
1099
//	AnsiString					sql_statement;
1100
    bool						noerror = true;
1101
 
1102
    m_XMLSchema->GetAttributes(structure_handle, structure_attributes);
1103
 
1104
    s_itr = structure_attributes.begin();
1105
    while ( noerror && (s_itr != structure_attributes.end()) )
1106
    {
1107
    	string	elementtype;
1108
        string	attr_handle = (*s_itr);
1109
 
1110
        m_XMLSchema->GetAttributeProperty(attr_handle, "type", elementtype);
1111
 
1112
        if (elementtype == "field")
1113
        {
1114
            string	datatype;
1115
 
1116
            m_XMLSchema->GetAttributeProperty(attr_handle, "datatype", datatype);
1117
 
1118
            if (datatype == "Struct")
1119
            {
1120
	            noerror = InitialiseTxnStructure(attr_handle, subscript, structure_params);
1121
            }
1122
            else
1123
            {
1124
            	string	fieldname;
1125
                string	tagvalue;
1126
                string	xpath;
1127
 
1128
                m_XMLSchema->GetAttributeProperty(attr_handle, "tag", tagvalue);
1129
 
1130
                if (tagvalue.length() > 0)
1131
                {
1132
                    m_XMLSchema->GetAttributeProperty(attr_handle, "name", fieldname);
1133
 
1134
                    AnsiString	fieldid;
1135
 
1136
                    if (subscript == 0)
1137
                    {
1138
                    	fieldid = fieldname.c_str();
1139
                    }
1140
                    else
1141
                    {
1142
	                    fieldid.sprintf("%s.%d", fieldname.c_str(), subscript);
1143
                    }
1144
 
1145
                    IterationParams::iterator	f_itr = structure_params.find(fieldid.c_str());
1146
 
1147
					if (f_itr != structure_params.end())
1148
                    {
1149
                    	string	fieldvalue = (*f_itr).second;
1150
                        string	valuemap;
1151
 
1152
                        m_XMLSchema->GetAttributeProperty(attr_handle, "valuemap", valuemap);
1153
                        if (valuemap.empty())
1154
                        {
1155
                        	if (fieldvalue[0] == '-')
1156
                            {
1157
                            	int	int_value = atoi( fieldvalue.c_str() );
1158
 
1159
                                m_XMLSchema->SetAttributeValue(attr_handle, "", int_value);
1160
                            }
1161
                            else
1162
                            if (m_XMLSchema->SetAttributeValue(attr_handle, "", fieldvalue.c_str()) == false)
1163
                            {
1164
                                AnsiString	msg;
1165
                                msg.sprintf("Failed to initialise attribute '%s' to (%s) DataType: %s\n"
1166
                                			"Continue ?",
1167
                                            fieldname.c_str(), fieldvalue.c_str(),
1168
                                            datatype.c_str());
1169
 
1170
                                if (MessageDlg(msg, mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0) == mrNo)
1171
                                {
1172
	                                noerror = false;
1173
                                }
1174
                            }
1175
                        }
1176
                        else
1177
						{
1178
                            if ( (fieldvalue[0] == '-') || (fieldvalue[0] >='0' && fieldvalue[0] <='9') )
1179
                            {
1180
                                int	int_value = atoi( fieldvalue.c_str() );
1181
 
1182
                                if (m_XMLSchema->SetAttributeValue(attr_handle, "", int_value) == false)
1183
                                {
1184
                                    AnsiString	msg;
1185
                                    msg.sprintf("Failed to initialise attribute '%s' to (%s) DataType: %s\n"
1186
                                                "Continue ?",
1187
                                                fieldname.c_str(), fieldvalue.c_str(),
1188
                                                datatype.c_str());
1189
 
1190
                                    if (MessageDlg(msg, mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0) == mrNo)
1191
                                    {
1192
                                        noerror = false;
1193
                                    }
1194
                                }
1195
                            }
1196
                            else
1197
                            {
1198
                                if (m_XMLSchema->SetAttributeValue(attr_handle, "", fieldvalue.c_str()) == false)
1199
                                {
1200
                                    AnsiString	msg;
1201
                                    msg.sprintf("Failed to initialise attribute '%s' to (%s) DataType: %s\n"
1202
                                                "Continue ?",
1203
                                                fieldname.c_str(), fieldvalue.c_str(),
1204
                                                datatype.c_str());
1205
 
1206
                                    if (MessageDlg(msg, mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0) == mrNo)
1207
									{
1208
                                        noerror = false;
1209
                                    }
1210
                                }
1211
                            }
1212
                        }
1213
                    }
1214
                }
1215
	        }
1216
		}
1217
        else
1218
        if (elementtype == "repeat")
1219
        {
1220
	        string	refcountfield;
1221
        	string	maxOccursStr;
1222
            string	refcountAttribute;
1223
 
1224
            m_XMLSchema->GetAttributeProperty(attr_handle, "refcountfield", refcountfield);
1225
 
1226
            if (!refcountfield.empty())
1227
            {
1228
	            string		refcountAttribute = structure_handle+"."+refcountfield;
1229
 
1230
                m_XMLSchema->GetAttributeProperty(refcountAttribute, "max", maxOccursStr);
1231
            }
1232
 
1233
            if (maxOccursStr.empty())
1234
            {
1235
	            m_XMLSchema->GetAttributeProperty(attr_handle, "maxOccurs", maxOccursStr);
1236
            }
1237
 
1238
            int maxOccurs = atoi(maxOccursStr.c_str());
1239
 
1240
            // Limit to 100 elements
1241
            if (maxOccurs > 100)
1242
            {
1243
	            maxOccurs = 100;
1244
            }
1245
 
1246
            string	refcount_value;
1247
            m_XMLSchema->GetAttributeValue(structure_handle, refcountfield, refcount_value);
1248
 
1249
            string	repeat_name;
1250
            m_XMLSchema->GetAttributeProperty(attr_handle, "name", repeat_name);
1251
 
1252
            if (!refcount_value.empty())
1253
            {
1254
            	maxOccurs = atoi(refcount_value.c_str());
1255
            }
1256
            m_XMLSchema->SetAttributeValue(structure_handle, refcountfield, maxOccurs);
1257
 
1258
            for (int occurrence=1; occurrence<=maxOccurs; occurrence++)
1259
            {
1260
                string		repeat_attribute_handle;
1261
                AnsiString	temp;
1262
 
1263
                temp.sprintf("%s.%d",
1264
                             attr_handle.c_str(),
1265
                             occurrence);
1266
 
1267
				repeat_attribute_handle = temp.c_str();
1268
 
1269
                noerror = InitialiseTxnStructure(repeat_attribute_handle, occurrence, structure_params);
1270
            } // for (int i=1; i<=occurrence; i++)
1271
        }
1272
 
1273
        s_itr++;
1274
    } // while
1275
 
1276
    return noerror;
1277
}
1278
 
1279
//---------------------------------------------------------------------------
1280
 
1281
 
1282
void TRunTestsForm::ShowForm(const AnsiString &testcase, const AnsiString &testname, const AnsiString &project, int currentiteration, const AnsiString &user_gen_dir, TXMLSchema *XMLSchema)
1283
{
1284
    m_currentproject = project;
1285
    m_currentiteration = currentiteration;
1286
	m_XMLSchema = XMLSchema;
1287
    m_testcase = testcase;
1288
    m_user_gen_dir = user_gen_dir;
1289
 
1290
	TestCaseTitle->Caption = testname;
1291
 
1292
	ShowModal();
1293
}
1294
 
1295
//---------------------------------------------------------------------------
1296
 
1297
void __fastcall TRunTestsForm::TestCaseTxnTreeViewChange(TObject *Sender,
1298
      TTreeNode *Node)
1299
{
1300
	if (Node->Level == 1)
1301
    {
1302
        TADOQuery	*query = new TADOQuery(this);
1303
        query->Connection = Data_Module->IntegrationDBConnection;
1304
 
1305
        int	testscenario_no	= (int)(Node->Parent->Data);
1306
        int	txnspec_no		= (int)(Node->Data);
1307
 
1308
        AnsiString	sql_statement;
1309
 
1310
        sql_statement.sprintf("SELECT PAYLOAD FROM TRANSACTION_SPECIFICATION "
1311
        					  "WHERE TESTSCENARIO_NO=%d AND TXNSPEC_NO=%d",
1312
                              testscenario_no,
1313
                              txnspec_no);
1314
 
1315
        query->SQL->Text = sql_statement;
1316
        query->Open();
1317
 
1318
        if (query->RecordCount == 1)
1319
        {
1320
			TStream* 		payload_stream = query->CreateBlobStream(query->FieldByName("PAYLOAD"), bmRead);
1321
            unsigned int 	payload_size = payload_stream->Size;
1322
            void*       	payload = malloc(payload_size);
1323
 
1324
            payload_stream->ReadBuffer(payload, payload_stream->Size);
1325
 
1326
            PayloadGrid->Rows = (payload_size+15)/16;
1327
 
1328
            unsigned char *p = (unsigned char *)payload;
1329
			for (unsigned row=0; row<(payload_size+15)/16; row++)
1330
			{
1331
            	for (unsigned col=0; col<16; col++)
1332
                {
1333
                	AnsiString	abyte;
1334
                    abyte.sprintf("%02X", *p);
1335
 
1336
                    PayloadGrid->Cell[col+1][row+1] = abyte;
1337
 
1338
                    p++;
1339
                }
1340
            }
1341
 
1342
            free(payload);
1343
        }
1344
 
1345
        delete query;
1346
    }
1347
//	PayloadGrid
1348
 
1349
}
1350
//---------------------------------------------------------------------------
1351
 
1352
void __fastcall TRunTestsForm::SaveTxnsToFileClick(TObject *Sender)
1353
{
1354
    TCursor Save_Cursor = Screen->Cursor;
1355
    Screen->Cursor = crHourGlass;    // Show hourglass cursor
1356
 
1357
    try
1358
    {
1359
            AnsiString	sql_statement;
1360
 
1361
            TADOQuery	*query = new TADOQuery(this);
1362
            query->Connection = Data_Module->IntegrationDBConnection;
1363
 
1364
            TADOQuery	*query2 = new TADOQuery(this);
1365
            query2->Connection = Data_Module->IntegrationDBConnection;
1366
 
1367
            sql_statement="";
1368
            sql_statement.sprintf("SELECT TXNSTORAGE_PATH "
1369
                                  "FROM ITERATIONS "
1370
                                  "WHERE PROJECT_CODE='%s' "
1371
                                  "AND	 ITERATION=%d ",
1372
                                  m_currentproject.c_str(),
1373
                                  m_currentiteration);
1374
 
1375
            query->SQL->Text = sql_statement;
1376
			query->Open();
1377
 
1378
            AnsiString	txnstorage_path = query->FieldByName("TXNSTORAGE_PATH")->AsString;
1379
 
1380
			AnsiString	target_path;
1381
 
1382
            if (!m_user_gen_dir.IsEmpty() && (txnstorage_path[2] != ':') )
1383
            {
1384
            	target_path  = m_user_gen_dir;
1385
                target_path += "\\";
1386
                target_path += txnstorage_path;
1387
            }
1388
            else
1389
            {
1390
            	target_path = txnstorage_path;
1391
            }
1392
 
1393
            if (access(target_path.c_str(), 0) == 0)
1394
            {
1395
                // Build a MASS Txn Map for fast lookup
1396
 
1397
                TXNIndexMap					mass_txns;
1398
 
1399
                sql_statement="";
1400
                sql_statement.sprintf("SELECT NAME,UDTYPE,UDSUBTYPE "
1401
                                      "FROM MASS_TXNS "
1402
                                      "WHERE PROJECTCODE='%s' "
1403
                                      "AND	 ITERATION=%d ",
1404
                                      m_currentproject.c_str(),
1405
                                      m_currentiteration);
1406
 
1407
                query->SQL->Text = sql_statement;
1408
                query->Open();
1409
                while (!query->Eof)
1410
				{
1411
                    unsigned short	udtype 		= query->FieldByName("UDTYPE")->AsInteger;
1412
                    unsigned short	udsubtype 	= query->FieldByName("UDSUBTYPE")->AsInteger;
1413
                    unsigned int	udindex 	= (udtype << 16) + udsubtype;
1414
 
1415
                    TXNIndexPair	pair(udindex, query->FieldByName("NAME")->AsString);
1416
 
1417
                    mass_txns.insert(pair);
1418
 
1419
                    query->Next();
1420
                }
1421
 
1422
                sql_statement="";
1423
                sql_statement.sprintf("select testscenario_no,testcase_seqno,name "
1424
                                      "from test_scenarios "
1425
                                      "where project_code='%s' and iteration=%d "
1426
                                      "and testcase_id='%s' "
1427
                                      "order by testcase_seqno",
1428
									  m_currentproject.c_str(),
1429
    	                              m_currentiteration,
1430
                                      m_testcase.c_str());
1431
                query->SQL->Text = sql_statement;
1432
                query->Open();
1433
                while ( !query->Eof )
1434
                {
1435
                    unsigned int	testscenario_no = query->FieldByName("TESTSCENARIO_NO")->AsInteger;
1436
 
1437
                    // Determine the set of Transaction Specifications for the ordered
1438
                    // set of test scenarios
1439
 
1440
					sql_statement="";
1441
                    sql_statement.sprintf("select txnspec_no,seq_no,udtype,udsubtype,payload "
1442
                                          "from transaction_specification "
1443
                                          "where testscenario_no=%d "
1444
                                          "order by seq_no",
1445
                                          testscenario_no);
1446
                    query2->SQL->Text = sql_statement;
1447
                    query2->Open();
1448
                    while (!query2->Eof)
1449
                    {
1450
                        TBlobField		*payload_field = dynamic_cast<TBlobField *>(query2->FieldByName("PAYLOAD"));
1451
 
1452
                        if (!payload_field->IsNull)
1453
                        {
1454
                            AnsiString	filename;
1455
 
1456
                            unsigned short  udtype		= query2->FieldByName("UDTYPE")->AsInteger;
1457
                            unsigned short  udsubtype	= query2->FieldByName("UDSUBTYPE")->AsInteger;
1458
                            unsigned int	udindex 	= (udtype << 16) + udsubtype;
1459
 
1460
                            // Locate the MASS Txn based on UD Type and SubType
1461
 
1462
                            TXNIndexMap::iterator	txn_itr = mass_txns.find(udindex);
1463
 
1464
                            if (txn_itr != mass_txns.end())
1465
							{
1466
                                string structure_name	= (*txn_itr).second.c_str();
1467
 
1468
                                AnsiString	target_directory;
1469
								target_directory.sprintf("%s/%s", target_path.c_str(), m_testcase.c_str());
1470
 
1471
                                if (access(target_directory.c_str(), 0) != 0)
1472
                                {
1473
                                	mkdir(target_directory.c_str());
1474
                                }
1475
 
1476
                                if (access(target_directory.c_str(), 0) == 0)
1477
                                {
1478
                                    filename.sprintf("%s/%s/%s_%03d_%02d_%s.xdr",
1479
                                                     target_path.c_str(),
1480
                                                     m_testcase.c_str(),
1481
                                                     m_testcase.c_str(),
1482
                                                     query->FieldByName("TESTCASE_SEQNO")->AsInteger,
1483
                                                     query2->FieldByName("SEQ_NO")->AsInteger,
1484
                                                     structure_name.c_str()
1485
                                                     );
1486
 
1487
									payload_field->SaveToFile(filename);
1488
                                } // Found Target Directory
1489
                            } // Found MASS Txn
1490
                        } // if (!payload_field->IsNull)
1491
 
1492
                        query2->Next();
1493
                    }
1494
 
1495
					query->Next();
1496
                }
1497
 
1498
                delete query;
1499
				delete query2;
1500
 
1501
                AnsiString	msg;
1502
                msg.sprintf("Generated Transactions to: %s" , target_path.c_str());
1503
 
1504
                MessageDlg(msg, mtInformation, TMsgDlgButtons() << mbOK, 0);
1505
            }
1506
            else
1507
            {
1508
                AnsiString	msg;
1509
                msg.sprintf("Directory '%s' Not Found or Not Accessible", target_path.c_str());
1510
 
1511
	            MessageDlg(msg, mtInformation, TMsgDlgButtons() << mbOK, 0);
1512
            }
1513
    }
1514
	__finally
1515
	{
1516
		Screen->Cursor = Save_Cursor;
1517
	}
1518
}
1519
//---------------------------------------------------------------------------
1520
 
1521
 
1522
void __fastcall TRunTestsForm::FormCreate(TObject *Sender)
1523
{
1524
#ifdef ADV_PROGRESS_BAR
1525
	m_progressBar = new TAdvProgressBar( StatusBar );
1526
	m_progressBar->Parent				= StatusBar;
1527
	m_progressBar->Steps				= 10;
1528
	m_progressBar->Position				= 0;
1529
	m_progressBar->ShowBorder			= false;
1530
	m_progressBar->ShowGradient			= true;
1531
	m_progressBar->ShowPercentage		= true;
1532
	m_progressBar->Stacked				= false;
1533
	m_progressBar->CompletionSmooth		= false;
1534
	m_progressBar->Visible				= false;
1535
 
1536
//	m_progressBar->Level0Color			= Graphics::TColor( 0x006AA676 );
1537
//	m_progressBar->Level0ColorTo		= Graphics::TColor( 0x00BAE3C3 );
1538
	m_progressBar->Level0Color			= Graphics::TColor( 0x00C961AD );
1539
	m_progressBar->Level0ColorTo		= Graphics::TColor( 0x00FFBCEF );
1540
	m_progressBar->Level1Color			= Graphics::TColor( 0x00C961AD );
1541
	m_progressBar->Level1ColorTo		= Graphics::TColor( 0x00FFBCEF );
1542
	m_progressBar->Level2Color			= Graphics::TColor( 0x00C961AD );
1543
	m_progressBar->Level2ColorTo		= Graphics::TColor( 0x00FFBCEF );
1544
	m_progressBar->Level3Color			= Graphics::TColor( 0x00C961AD );
1545
	m_progressBar->Level3ColorTo		= Graphics::TColor( 0x00FFBCEF );
1546
#else
1547
	m_progressBarOld = new TProgressBar ( StatusBar );
1548
	m_progressBarOld->Parent = StatusBar;
1549
	m_progressBarOld->Step     = 10;
1550
	m_progressBarOld->Max      = 100;
1551
	m_progressBarOld->Position = 0;
1552
	m_progressBarOld->Visible = false;
1553
#endif
1554
}
1555
//---------------------------------------------------------------------------
1556
 
1557
void __fastcall TRunTestsForm::StatusBarResize(TObject *Sender)
1558
{
1559
	RECT Rect;
1560
	StatusBar->Perform( SB_GETRECT, 0, (LPARAM)&Rect );
1561
 
1562
	const int progressPanel = 2;
1563
	int offset = 0;
1564
	for ( int i = 0; i < progressPanel; i++ )
1565
	{
1566
		offset += StatusBar->Panels->Items[ i ]->Width;
1567
	}
1568
 
1569
#ifdef ADV_PROGRESS_BAR
1570
	m_progressBar->Top = Rect.top + 2;
1571
	m_progressBar->Left = Rect.left + offset + 4;
1572
	m_progressBar->Width = StatusBar->Panels->Items[ progressPanel ]->Width - 6;
1573
	m_progressBar->Height = Rect.bottom - Rect.top - 4;
1574
#else
1575
	m_progressBarOld->Top = Rect.top;
1576
	m_progressBarOld->Left = Rect.left + offset + 2;
1577
	m_progressBarOld->Width = StatusBar->Panels->Items[ progressPanel ]->Width - 2;
1578
	m_progressBarOld->Height = Rect.bottom - Rect.top;
1579
#endif
1580
}
1581
//---------------------------------------------------------------------------
1582