using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Data;
using System.Data.SqlTypes;
using SqliteDotNet;
namespace SqliteGUI
{
///
/// Summary description for NewAddTestForm.
///
public class NewAddTestForm : System.Windows.Forms.Form
{
private string testName = "";
private string paramSet = "";
private SqliteDb database;
private DataTable dataTable = null;
private SqliteVm vm;
private System.Windows.Forms.Label newTestNameLabel;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button addTestButton;
private System.Windows.Forms.Button deleteTestButton;
private System.Windows.Forms.TextBox addTestBox;
private System.Windows.Forms.TextBox prerequisite;
private System.Windows.Forms.TextBox executeSequence;
private System.Windows.Forms.Label prerequisiteLabel;
private System.Windows.Forms.Label testDescriptionLabel;
private System.Windows.Forms.Label executeSequenceLabel;
private System.Windows.Forms.ComboBox testNameList;
private System.Windows.Forms.Label testNameLabel;
private System.Windows.Forms.Button DeleteParamSet;
private System.Windows.Forms.Button AddParamSet;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Label sampleResultLabel;
private System.Windows.Forms.Label contentTypeLabel;
private System.Windows.Forms.Label resultDescriptionLabel;
private System.Windows.Forms.TextBox contentType;
private System.Windows.Forms.RichTextBox sampleResult;
private System.Windows.Forms.RichTextBox resultDescription;
private System.Windows.Forms.TextBox paramSetBox;
private System.Windows.Forms.ListBox paramSetsList;
private System.Windows.Forms.Label testTypeLabel;
private System.Windows.Forms.TextBox testType;
private System.Windows.Forms.TextBox testDescription;
private System.Windows.Forms.Button saveButton;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.SaveFileDialog saveFileDialog2;
private TextBox txtFind;
private TextBox txtReplace;
private Label label3;
private Label label4;
private GroupBox groupBox1;
private Button btnReplace;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public NewAddTestForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
//Set up the table for the params
this.SetTable();
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
//If the database is writeable save the data else continue with disposing
if ((null != this.database) && (!Form1.IsReadOnly(this.database.GetName())))
{
this.SaveData(true);
}
this.dataTable.Dispose();
if( disposing )
{
//Finalize the virtual machine
if (this.vm != null)
{
this.vm.SqlFinalize();
}
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.newTestNameLabel = new System.Windows.Forms.Label();
this.DeleteParamSet = new System.Windows.Forms.Button();
this.AddParamSet = new System.Windows.Forms.Button();
this.paramSetBox = new System.Windows.Forms.TextBox();
this.paramSetsList = new System.Windows.Forms.ListBox();
this.label1 = new System.Windows.Forms.Label();
this.addTestButton = new System.Windows.Forms.Button();
this.deleteTestButton = new System.Windows.Forms.Button();
this.addTestBox = new System.Windows.Forms.TextBox();
this.prerequisite = new System.Windows.Forms.TextBox();
this.executeSequence = new System.Windows.Forms.TextBox();
this.prerequisiteLabel = new System.Windows.Forms.Label();
this.testDescriptionLabel = new System.Windows.Forms.Label();
this.executeSequenceLabel = new System.Windows.Forms.Label();
this.testNameList = new System.Windows.Forms.ComboBox();
this.testNameLabel = new System.Windows.Forms.Label();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.sampleResultLabel = new System.Windows.Forms.Label();
this.contentTypeLabel = new System.Windows.Forms.Label();
this.resultDescriptionLabel = new System.Windows.Forms.Label();
this.contentType = new System.Windows.Forms.TextBox();
this.sampleResult = new System.Windows.Forms.RichTextBox();
this.resultDescription = new System.Windows.Forms.RichTextBox();
this.testTypeLabel = new System.Windows.Forms.Label();
this.testType = new System.Windows.Forms.TextBox();
this.testDescription = new System.Windows.Forms.TextBox();
this.saveButton = new System.Windows.Forms.Button();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.saveFileDialog2 = new System.Windows.Forms.SaveFileDialog();
this.txtFind = new System.Windows.Forms.TextBox();
this.txtReplace = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnReplace = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// newTestNameLabel
//
this.newTestNameLabel.Location = new System.Drawing.Point(8, 56);
this.newTestNameLabel.Name = "newTestNameLabel";
this.newTestNameLabel.Size = new System.Drawing.Size(88, 23);
this.newTestNameLabel.TabIndex = 17;
this.newTestNameLabel.Text = "New Test Name";
this.newTestNameLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// DeleteParamSet
//
this.DeleteParamSet.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.DeleteParamSet.Location = new System.Drawing.Point(232, 336);
this.DeleteParamSet.Name = "DeleteParamSet";
this.DeleteParamSet.Size = new System.Drawing.Size(75, 23);
this.DeleteParamSet.TabIndex = 10;
this.DeleteParamSet.Text = "Delete";
this.DeleteParamSet.Click += new System.EventHandler(this.DeleteParamSet_Click);
//
// AddParamSet
//
this.AddParamSet.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.AddParamSet.Location = new System.Drawing.Point(232, 448);
this.AddParamSet.Name = "AddParamSet";
this.AddParamSet.Size = new System.Drawing.Size(75, 23);
this.AddParamSet.TabIndex = 9;
this.AddParamSet.Text = "Add";
this.AddParamSet.Click += new System.EventHandler(this.AddParamSet_Click);
//
// paramSetBox
//
this.paramSetBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.paramSetBox.Location = new System.Drawing.Point(120, 448);
this.paramSetBox.Name = "paramSetBox";
this.paramSetBox.Size = new System.Drawing.Size(100, 20);
this.paramSetBox.TabIndex = 8;
//
// paramSetsList
//
this.paramSetsList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.paramSetsList.Location = new System.Drawing.Point(120, 280);
this.paramSetsList.Name = "paramSetsList";
this.paramSetsList.Size = new System.Drawing.Size(104, 147);
this.paramSetsList.TabIndex = 85;
this.paramSetsList.SelectedIndexChanged += new System.EventHandler(this.paramSetsList_SelectedIndexChanged);
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 280);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 23);
this.label1.TabIndex = 12;
this.label1.Text = "Param Sets";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// addTestButton
//
this.addTestButton.Location = new System.Drawing.Point(432, 56);
this.addTestButton.Name = "addTestButton";
this.addTestButton.Size = new System.Drawing.Size(80, 23);
this.addTestButton.TabIndex = 3;
this.addTestButton.Text = "Add Test";
this.addTestButton.Click += new System.EventHandler(this.addTestButton_Click);
//
// deleteTestButton
//
this.deleteTestButton.Location = new System.Drawing.Point(432, 16);
this.deleteTestButton.Name = "deleteTestButton";
this.deleteTestButton.Size = new System.Drawing.Size(80, 24);
this.deleteTestButton.TabIndex = 19;
this.deleteTestButton.Text = "DeleteTest";
this.deleteTestButton.Click += new System.EventHandler(this.deleteTestButton_Click);
//
// addTestBox
//
this.addTestBox.Location = new System.Drawing.Point(120, 56);
this.addTestBox.Name = "addTestBox";
this.addTestBox.Size = new System.Drawing.Size(288, 20);
this.addTestBox.TabIndex = 2;
//
// prerequisite
//
this.prerequisite.Location = new System.Drawing.Point(120, 208);
this.prerequisite.Name = "prerequisite";
this.prerequisite.Size = new System.Drawing.Size(280, 20);
this.prerequisite.TabIndex = 6;
//
// executeSequence
//
this.executeSequence.Location = new System.Drawing.Point(120, 96);
this.executeSequence.Name = "executeSequence";
this.executeSequence.Size = new System.Drawing.Size(100, 20);
this.executeSequence.TabIndex = 4;
//
// prerequisiteLabel
//
this.prerequisiteLabel.Location = new System.Drawing.Point(16, 208);
this.prerequisiteLabel.Name = "prerequisiteLabel";
this.prerequisiteLabel.Size = new System.Drawing.Size(100, 23);
this.prerequisiteLabel.TabIndex = 5;
this.prerequisiteLabel.Text = "Prerequisite";
this.prerequisiteLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// testDescriptionLabel
//
this.testDescriptionLabel.Location = new System.Drawing.Point(8, 136);
this.testDescriptionLabel.Name = "testDescriptionLabel";
this.testDescriptionLabel.Size = new System.Drawing.Size(88, 16);
this.testDescriptionLabel.TabIndex = 4;
this.testDescriptionLabel.Text = "Test Description";
this.testDescriptionLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// executeSequenceLabel
//
this.executeSequenceLabel.Location = new System.Drawing.Point(8, 96);
this.executeSequenceLabel.Name = "executeSequenceLabel";
this.executeSequenceLabel.Size = new System.Drawing.Size(100, 23);
this.executeSequenceLabel.TabIndex = 3;
this.executeSequenceLabel.Text = "Execute Sequence";
this.executeSequenceLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// testNameList
//
this.testNameList.ItemHeight = 13;
this.testNameList.Location = new System.Drawing.Point(120, 16);
this.testNameList.Name = "testNameList";
this.testNameList.Size = new System.Drawing.Size(288, 21);
this.testNameList.TabIndex = 1;
this.testNameList.SelectedIndexChanged += new System.EventHandler(this.testNameList_SelectedIndexChanged);
//
// testNameLabel
//
this.testNameLabel.Location = new System.Drawing.Point(24, 16);
this.testNameLabel.Name = "testNameLabel";
this.testNameLabel.Size = new System.Drawing.Size(72, 24);
this.testNameLabel.TabIndex = 22;
this.testNameLabel.Text = "Test Name";
this.testNameLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// dataGrid1
//
this.dataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(464, 144);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(408, 224);
this.dataGrid1.TabIndex = 11;
//
// sampleResultLabel
//
this.sampleResultLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.sampleResultLabel.Location = new System.Drawing.Point(368, 464);
this.sampleResultLabel.Name = "sampleResultLabel";
this.sampleResultLabel.Size = new System.Drawing.Size(80, 23);
this.sampleResultLabel.TabIndex = 81;
this.sampleResultLabel.Text = "Sample Result";
this.sampleResultLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// contentTypeLabel
//
this.contentTypeLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.contentTypeLabel.Location = new System.Drawing.Point(376, 432);
this.contentTypeLabel.Name = "contentTypeLabel";
this.contentTypeLabel.Size = new System.Drawing.Size(72, 16);
this.contentTypeLabel.TabIndex = 80;
this.contentTypeLabel.Text = "Content Type";
this.contentTypeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// resultDescriptionLabel
//
this.resultDescriptionLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.resultDescriptionLabel.Location = new System.Drawing.Point(384, 384);
this.resultDescriptionLabel.Name = "resultDescriptionLabel";
this.resultDescriptionLabel.Size = new System.Drawing.Size(72, 23);
this.resultDescriptionLabel.TabIndex = 79;
this.resultDescriptionLabel.Text = "Description";
this.resultDescriptionLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// contentType
//
this.contentType.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.contentType.Location = new System.Drawing.Point(464, 432);
this.contentType.Name = "contentType";
this.contentType.Size = new System.Drawing.Size(120, 20);
this.contentType.TabIndex = 13;
//
// sampleResult
//
this.sampleResult.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.sampleResult.Location = new System.Drawing.Point(464, 464);
this.sampleResult.Name = "sampleResult";
this.sampleResult.Size = new System.Drawing.Size(408, 104);
this.sampleResult.TabIndex = 14;
this.sampleResult.Text = "";
//
// resultDescription
//
this.resultDescription.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.resultDescription.Location = new System.Drawing.Point(464, 384);
this.resultDescription.Name = "resultDescription";
this.resultDescription.Size = new System.Drawing.Size(408, 32);
this.resultDescription.TabIndex = 12;
this.resultDescription.Text = "";
//
// testTypeLabel
//
this.testTypeLabel.Location = new System.Drawing.Point(16, 240);
this.testTypeLabel.Name = "testTypeLabel";
this.testTypeLabel.Size = new System.Drawing.Size(100, 23);
this.testTypeLabel.TabIndex = 82;
this.testTypeLabel.Text = "Test Type";
this.testTypeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// testType
//
this.testType.Location = new System.Drawing.Point(120, 240);
this.testType.Name = "testType";
this.testType.Size = new System.Drawing.Size(104, 20);
this.testType.TabIndex = 7;
//
// testDescription
//
this.testDescription.Location = new System.Drawing.Point(120, 128);
this.testDescription.Multiline = true;
this.testDescription.Name = "testDescription";
this.testDescription.Size = new System.Drawing.Size(280, 56);
this.testDescription.TabIndex = 5;
//
// saveButton
//
this.saveButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.saveButton.Location = new System.Drawing.Point(768, 584);
this.saveButton.Name = "saveButton";
this.saveButton.Size = new System.Drawing.Size(96, 23);
this.saveButton.TabIndex = 15;
this.saveButton.Text = "Save Changes";
this.saveButton.Click += new System.EventHandler(this.saveButton_Click);
//
// txtFind
//
this.txtFind.Location = new System.Drawing.Point(94, 28);
this.txtFind.Name = "txtFind";
this.txtFind.Size = new System.Drawing.Size(188, 20);
this.txtFind.TabIndex = 87;
//
// txtReplace
//
this.txtReplace.Location = new System.Drawing.Point(94, 54);
this.txtReplace.Name = "txtReplace";
this.txtReplace.Size = new System.Drawing.Size(188, 20);
this.txtReplace.TabIndex = 88;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(19, 31);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(67, 13);
this.label3.TabIndex = 89;
this.label3.Text = "Find Content";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(16, 57);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(72, 13);
this.label4.TabIndex = 90;
this.label4.Text = "Replace With";
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.groupBox1.Controls.Add(this.btnReplace);
this.groupBox1.Controls.Add(this.txtFind);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.txtReplace);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Location = new System.Drawing.Point(35, 490);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(302, 117);
this.groupBox1.TabIndex = 91;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Find/Replace content in sample result";
//
// btnReplace
//
this.btnReplace.Location = new System.Drawing.Point(94, 81);
this.btnReplace.Name = "btnReplace";
this.btnReplace.Size = new System.Drawing.Size(75, 23);
this.btnReplace.TabIndex = 91;
this.btnReplace.Text = "Replace";
this.btnReplace.UseVisualStyleBackColor = true;
this.btnReplace.Click += new System.EventHandler(this.btnReplace_Click);
//
// NewAddTestForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(888, 618);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.saveButton);
this.Controls.Add(this.testType);
this.Controls.Add(this.testTypeLabel);
this.Controls.Add(this.sampleResultLabel);
this.Controls.Add(this.contentTypeLabel);
this.Controls.Add(this.resultDescriptionLabel);
this.Controls.Add(this.contentType);
this.Controls.Add(this.sampleResult);
this.Controls.Add(this.resultDescription);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.newTestNameLabel);
this.Controls.Add(this.DeleteParamSet);
this.Controls.Add(this.AddParamSet);
this.Controls.Add(this.paramSetBox);
this.Controls.Add(this.paramSetsList);
this.Controls.Add(this.label1);
this.Controls.Add(this.addTestButton);
this.Controls.Add(this.deleteTestButton);
this.Controls.Add(this.addTestBox);
this.Controls.Add(this.prerequisite);
this.Controls.Add(this.testDescription);
this.Controls.Add(this.executeSequence);
this.Controls.Add(this.prerequisiteLabel);
this.Controls.Add(this.testDescriptionLabel);
this.Controls.Add(this.executeSequenceLabel);
this.Controls.Add(this.testNameList);
this.Controls.Add(this.testNameLabel);
this.Name = "NewAddTestForm";
this.Text = "NewAddTestForm";
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
//Loads the form
public void LoadForm(SqliteDb newDatabase)
{
//Create a new virtual machine
this.database = newDatabase;
int status = Sqlite.Ok;
this.vm = new SqliteVm(newDatabase, true);
//Get all tests from the test case table and add the in the dropdown box
status = this.vm.Execute("Select TestName from TestCase");
while (Sqlite.Row == status)
{
this.testNameList.Items.Add(this.vm.GetString("TestName"));
status = this.vm.NextRow();
}
//If we have any tests in the list select the first one by default
if (this.testNameList.Items.Count > 0)
{
this.testNameList.SelectedIndex = 0;
this.testName = this.testNameList.SelectedItem.ToString();
}
}
//Updates fields related to test case table
private void UpdateTestCaseFields(string testName)
{
//Get all fields for the given test name
int status = Sqlite.Ok;
status = this.vm.Execute("Select * from TestCase where TestName=\""+testName+"\"");
//If that test is in the database update the corresponding fields
//Note: we need to keep track on the current test name to be able to save the data after a new selection
if ((Sqlite.Done == status) || (Sqlite.Row == status))
{
this.executeSequence.Text = this.vm.GetString("ExecuteSequence");
this.testDescription.Text = this.vm.GetString("Description");
this.prerequisite.Text = this.vm.GetString("Prerequisite");
this.testType.Text = this.vm.GetString("TestType");
this.UpdateParamSetsList(this.vm.GetString("ParamSets"));
this.testName = testName;
}
}
//Clears all fields related to the TestCase table
private void ClearTestCaseFields()
{
this.executeSequence.Clear();
this.testDescription.Clear();
this.prerequisite.Clear();
this.testType.Clear();
this.paramSetsList.Items.Clear();
this.paramSet = "";
}
//Called when new test name is selected from the list
private void testNameList_SelectedIndexChanged(object sender, System.EventArgs e)
{
//If the database is writeable save the current form or discard it silently
if ((null != this.database) && (!Form1.IsReadOnly(this.database.GetName())))
{
this.SaveData(true);
}
//Clears the form
this.ClearTestCaseFields();
this.ClearSampleResultFields();
this.ClearDataTableFields();
//If there is a test currently selected update the fields related to the TestCase tables
if (-1 != this.testNameList.SelectedIndex)
{
this.UpdateTestCaseFields(this.testNameList.SelectedItem.ToString());
}
}
//Updates the paramSets list
private void UpdateParamSetsList(string paramSets)
{
string[] setsList;
int i = 0;
this.paramSetsList.Items.Clear();
//Split the string into array
setsList = paramSets.Split(',');
//Do not add blank paramSets
while (i