SensusOracle.Database: TestBenchId added, working on queries.

This commit is contained in:
Milan Hanajik
2015-08-20 18:14:22 +02:00
parent a0c3ffd01a
commit be1344034e
4 changed files with 118 additions and 34 deletions
@@ -74,10 +74,15 @@ namespace TBF.BenchControl.DB.SensusOracle
{
string oradb = "Data Source=STARA_TEST.WORLD;User Id=deltachef;Password=deltachef;";
conn = new OracleConnection(oradb); // C#
///
/// Do something with the database to see if the connection works well
///
conn.Open();
OracleCommand cmd = new OracleCommand("select Standort from ANBIETER_SD where ANBID = 4", conn);
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = string.Format("select Standort from ANBIETER_SD where ANBID = 4");
OracleDataReader dr = cmd.ExecuteReader();
dr.Read();
@@ -86,14 +91,15 @@ namespace TBF.BenchControl.DB.SensusOracle
{
rslt = dr.GetString(0);
}
}
conn.Dispose();
}
public void RunDeviceBefore() {}
public void RunDeviceAfter() {}
public void StopDevice()
{
conn.Dispose();
}
/// <summary>
@@ -255,26 +261,63 @@ namespace TBF.BenchControl.DB.SensusOracle
///--------
if (combined)
{
for (int wmNr = 0; wmNr < Program.CompoundWMsCount; wmNr++) WriteCombinedWM(wmNr + 1); /// wmNr is 0-based
for (int wmNr = 0; wmNr < Program.CompoundWMsCount; wmNr++) WriteCombinedWM(wmNr + 1); /// wmNr is 0-based
}
else
{
conn.Open(); /// Open the Oracle database
for (int wmNr = 0; wmNr < Program.WMsCount; wmNr++) /// wmNr is 0-based
{
if (!unsortedResults[0].Meters[wmNr].Disabled)
WriteSingleWM(wmNr, wmNr + 1);
{
IList<Entities.TestResult> results = Utils.GetSortedTestResults(procedure, unsortedResults, Utils.PartNr(wmNr + 1, combined));
WriteSingleWM(wmNr, wmNr + 1, results);
SaveSingleWM2DB(wmNr, results);
}
}
conn.Dispose(); /// Close the Oracle database
}
}
/// <summary>
/// Write one water meter results
/// Write one meter results into the database
/// </summary>
/// <param name="wmNr"></param>
/// <param name="results"></param>
void SaveSingleWM2DB(int wmNr, IList<Entities.TestResult> results)
{
if (string.IsNullOrEmpty(unsortedResults[0].Meters[wmNr].SerialNr)) return; /// No database activity possible w/o PCB number
string pcbNr = unsortedResults[0].Meters[wmNr].SerialNr;
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = string.Format("select MAX_Pruefindex from VT_ZAHLER_PD where VT_Fernum = {0}", pcbNr);
OracleDataReader dr = cmd.ExecuteReader();
dr.Read();
string rslt;
if (dr.VisibleFieldCount > 0)
{
rslt = dr.GetString(0);
}
}
/// <summary>
/// Write one water meter results into a file
/// </summary>
/// <param name="wmNr">Water meter number (0-based)</param>
void WriteSingleWM(int wmNr, int printedWMNr)
void WriteSingleWM(int wmNr, int printedWMNr, IList<Entities.TestResult> results)
{
IList<Entities.TestResult> results = Utils.GetSortedTestResults(procedure, unsortedResults, Utils.PartNr(wmNr + 1, combined));
/// Determine column widths
int[] columnWidths = new int[resultItems.Count];
int totalWidth = 0;
@@ -26,6 +26,7 @@ namespace TBF.BenchControl.DB.SensusOracle
public IComponentCfgCtrl GetControl() { return new DatabaseCfgCtrl(); }
public int TestBenchId;
public string DestinationPath; /// Directory path into which the results will be saved
public bool YearFolders;
public bool MonthFolders;
@@ -37,8 +38,9 @@ namespace TBF.BenchControl.DB.SensusOracle
/// Private parameterless constructor invoked by all other (public) constructors
DatabaseCfg()
{
Name = "Sensus-Oracle-Database";
Name = "Sensus-Oracle-DB";
ParentName = string.Empty;
TestBenchId = 1;
DestinationPath = Program.HomeDir + "Results\\";
YearFolders = true;
MonthFolders = true;
@@ -55,8 +57,9 @@ namespace TBF.BenchControl.DB.SensusOracle
public string ToString(int i)
{
return string.Format("Name={0}, Path={1}, Y={2}, M={3}, D={4}, Elim.Spaces={5}, Separator={6}",
return string.Format("Name={0}, BenchId={1}, Path={2}, Y={3}, M={4}, D={5}, Elim.Spaces={6}, Separator={7}",
Name,
TestBenchId,
DestinationPath,
YearFolders,
MonthFolders,
@@ -49,6 +49,7 @@ namespace TBF.BenchControl.DB.SensusOracle
if (config == null) return; /// Control was not loaded, settings were not changed
classNameLabel.Text = config.Factory.ClassName;
nameTextBox.Text = config.Name;
benchIdTextBox.Text = config.TestBenchId.ToString();
destinationTextBox.Text = config.DestinationPath;
yearFoldersCheckBox.Checked = config.YearFolders;
monthFoldersCheckBox.Checked = config.MonthFolders;
@@ -60,6 +61,7 @@ namespace TBF.BenchControl.DB.SensusOracle
public void Unlock()
{
nameTextBox.Enabled = true;
benchIdTextBox.Enabled = true;
destinationTextBox.Enabled = true;
destinationButton.Enabled = true;
yearFoldersCheckBox.Enabled = true;
@@ -73,6 +75,13 @@ namespace TBF.BenchControl.DB.SensusOracle
{
CfgUpdateFlags flags = CfgUpdateFlags.None;
int benchId;
if (!int.TryParse(benchIdTextBox.Text, out benchId) || benchId <= 0)
{
flags |= CfgUpdateFlags.Error;
message += Environment.NewLine + "Invalid 'Test bench ID'";
}
if (!separatorComboBox.Items.Contains(separatorComboBox.Text))
{
flags |= CfgUpdateFlags.Error;
@@ -89,6 +98,12 @@ namespace TBF.BenchControl.DB.SensusOracle
if (config.Name != nameTextBox.Text) { config.Name = nameTextBox.Text; flags = CfgUpdateFlags.RestartRqrd; }
int benchId;
if (int.TryParse(benchIdTextBox.Text, out benchId) && benchId > 0)
{
config.TestBenchId = benchId;
}
if (config.DestinationPath != destinationTextBox.Text)
{
config.DestinationPath = destinationTextBox.Text;
@@ -44,12 +44,14 @@ namespace TBF.BenchControl.DB.SensusOracle
this.eliminateSpacesCheckBox = new System.Windows.Forms.CheckBox();
this.separatorLabel = new System.Windows.Forms.Label();
this.separatorComboBox = new System.Windows.Forms.ComboBox();
this.benchIdTextBox = new System.Windows.Forms.TextBox();
this.benchIdLabel = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// nameTextBox
//
this.nameTextBox.Enabled = false;
this.nameTextBox.Location = new System.Drawing.Point(110, 39);
this.nameTextBox.Location = new System.Drawing.Point(110, 36);
this.nameTextBox.Name = "nameTextBox";
this.nameTextBox.Size = new System.Drawing.Size(146, 20);
this.nameTextBox.TabIndex = 2;
@@ -57,7 +59,7 @@ namespace TBF.BenchControl.DB.SensusOracle
// nameLabel
//
this.nameLabel.AutoSize = true;
this.nameLabel.Location = new System.Drawing.Point(19, 42);
this.nameLabel.Location = new System.Drawing.Point(19, 39);
this.nameLabel.Name = "nameLabel";
this.nameLabel.Size = new System.Drawing.Size(35, 13);
this.nameLabel.TabIndex = 1;
@@ -66,7 +68,7 @@ namespace TBF.BenchControl.DB.SensusOracle
// classNameLabel
//
this.classNameLabel.AutoSize = true;
this.classNameLabel.Location = new System.Drawing.Point(107, 15);
this.classNameLabel.Location = new System.Drawing.Point(107, 12);
this.classNameLabel.Name = "classNameLabel";
this.classNameLabel.Size = new System.Drawing.Size(83, 13);
this.classNameLabel.TabIndex = 0;
@@ -75,38 +77,38 @@ namespace TBF.BenchControl.DB.SensusOracle
// destinationTextBox
//
this.destinationTextBox.Enabled = false;
this.destinationTextBox.Location = new System.Drawing.Point(110, 65);
this.destinationTextBox.Location = new System.Drawing.Point(110, 92);
this.destinationTextBox.Name = "destinationTextBox";
this.destinationTextBox.Size = new System.Drawing.Size(146, 20);
this.destinationTextBox.TabIndex = 4;
this.destinationTextBox.TabIndex = 6;
//
// destinationLabel
//
this.destinationLabel.AutoSize = true;
this.destinationLabel.Location = new System.Drawing.Point(19, 68);
this.destinationLabel.Location = new System.Drawing.Point(19, 95);
this.destinationLabel.Name = "destinationLabel";
this.destinationLabel.Size = new System.Drawing.Size(60, 13);
this.destinationLabel.TabIndex = 3;
this.destinationLabel.TabIndex = 5;
this.destinationLabel.Text = "Destination";
//
// dayFoldersCheckBox
//
this.dayFoldersCheckBox.AutoSize = true;
this.dayFoldersCheckBox.Enabled = false;
this.dayFoldersCheckBox.Location = new System.Drawing.Point(111, 136);
this.dayFoldersCheckBox.Location = new System.Drawing.Point(111, 157);
this.dayFoldersCheckBox.Name = "dayFoldersCheckBox";
this.dayFoldersCheckBox.Size = new System.Drawing.Size(79, 17);
this.dayFoldersCheckBox.TabIndex = 8;
this.dayFoldersCheckBox.TabIndex = 10;
this.dayFoldersCheckBox.Text = "Day folders";
this.dayFoldersCheckBox.UseVisualStyleBackColor = true;
//
// destinationButton
//
this.destinationButton.Enabled = false;
this.destinationButton.Location = new System.Drawing.Point(261, 65);
this.destinationButton.Location = new System.Drawing.Point(261, 92);
this.destinationButton.Name = "destinationButton";
this.destinationButton.Size = new System.Drawing.Size(30, 20);
this.destinationButton.TabIndex = 5;
this.destinationButton.TabIndex = 7;
this.destinationButton.Text = "...";
this.destinationButton.UseVisualStyleBackColor = true;
this.destinationButton.Click += new System.EventHandler(this.destinationButton_Click);
@@ -115,10 +117,10 @@ namespace TBF.BenchControl.DB.SensusOracle
//
this.yearFoldersCheckBox.AutoSize = true;
this.yearFoldersCheckBox.Enabled = false;
this.yearFoldersCheckBox.Location = new System.Drawing.Point(111, 94);
this.yearFoldersCheckBox.Location = new System.Drawing.Point(111, 119);
this.yearFoldersCheckBox.Name = "yearFoldersCheckBox";
this.yearFoldersCheckBox.Size = new System.Drawing.Size(82, 17);
this.yearFoldersCheckBox.TabIndex = 6;
this.yearFoldersCheckBox.TabIndex = 8;
this.yearFoldersCheckBox.Text = "Year folders";
this.yearFoldersCheckBox.UseVisualStyleBackColor = true;
//
@@ -126,10 +128,10 @@ namespace TBF.BenchControl.DB.SensusOracle
//
this.monthFoldersCheckBox.AutoSize = true;
this.monthFoldersCheckBox.Enabled = false;
this.monthFoldersCheckBox.Location = new System.Drawing.Point(111, 115);
this.monthFoldersCheckBox.Location = new System.Drawing.Point(111, 138);
this.monthFoldersCheckBox.Name = "monthFoldersCheckBox";
this.monthFoldersCheckBox.Size = new System.Drawing.Size(90, 17);
this.monthFoldersCheckBox.TabIndex = 7;
this.monthFoldersCheckBox.TabIndex = 9;
this.monthFoldersCheckBox.Text = "Month folders";
this.monthFoldersCheckBox.UseVisualStyleBackColor = true;
//
@@ -137,35 +139,54 @@ namespace TBF.BenchControl.DB.SensusOracle
//
this.eliminateSpacesCheckBox.AutoSize = true;
this.eliminateSpacesCheckBox.Enabled = false;
this.eliminateSpacesCheckBox.Location = new System.Drawing.Point(111, 194);
this.eliminateSpacesCheckBox.Location = new System.Drawing.Point(111, 205);
this.eliminateSpacesCheckBox.Name = "eliminateSpacesCheckBox";
this.eliminateSpacesCheckBox.Size = new System.Drawing.Size(165, 17);
this.eliminateSpacesCheckBox.TabIndex = 11;
this.eliminateSpacesCheckBox.TabIndex = 13;
this.eliminateSpacesCheckBox.Text = "Eliminate spaces in each field";
this.eliminateSpacesCheckBox.UseVisualStyleBackColor = true;
//
// separatorLabel
//
this.separatorLabel.AutoSize = true;
this.separatorLabel.Location = new System.Drawing.Point(19, 168);
this.separatorLabel.Location = new System.Drawing.Point(19, 181);
this.separatorLabel.Name = "separatorLabel";
this.separatorLabel.Size = new System.Drawing.Size(53, 13);
this.separatorLabel.TabIndex = 9;
this.separatorLabel.TabIndex = 11;
this.separatorLabel.Text = "Separator";
//
// separatorComboBox
//
this.separatorComboBox.Enabled = false;
this.separatorComboBox.FormattingEnabled = true;
this.separatorComboBox.Location = new System.Drawing.Point(110, 165);
this.separatorComboBox.Location = new System.Drawing.Point(110, 178);
this.separatorComboBox.Name = "separatorComboBox";
this.separatorComboBox.Size = new System.Drawing.Size(146, 21);
this.separatorComboBox.TabIndex = 10;
this.separatorComboBox.TabIndex = 12;
//
// WriterCfgCtrl
// benchIdTextBox
//
this.benchIdTextBox.Enabled = false;
this.benchIdTextBox.Location = new System.Drawing.Point(111, 64);
this.benchIdTextBox.Name = "benchIdTextBox";
this.benchIdTextBox.Size = new System.Drawing.Size(57, 20);
this.benchIdTextBox.TabIndex = 4;
//
// benchIdLabel
//
this.benchIdLabel.AutoSize = true;
this.benchIdLabel.Location = new System.Drawing.Point(19, 67);
this.benchIdLabel.Name = "benchIdLabel";
this.benchIdLabel.Size = new System.Drawing.Size(76, 13);
this.benchIdLabel.TabIndex = 3;
this.benchIdLabel.Text = "Test Bench ID";
//
// DatabaseCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.benchIdTextBox);
this.Controls.Add(this.benchIdLabel);
this.Controls.Add(this.separatorComboBox);
this.Controls.Add(this.separatorLabel);
this.Controls.Add(this.eliminateSpacesCheckBox);
@@ -178,7 +199,7 @@ namespace TBF.BenchControl.DB.SensusOracle
this.Controls.Add(this.nameTextBox);
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.classNameLabel);
this.Name = "WriterCfgCtrl";
this.Name = "DatabaseCfgCtrl";
this.Size = new System.Drawing.Size(300, 230);
this.Load += new System.EventHandler(this.WriterCfgCtrl_Load);
this.ResumeLayout(false);
@@ -200,5 +221,7 @@ namespace TBF.BenchControl.DB.SensusOracle
private System.Windows.Forms.CheckBox eliminateSpacesCheckBox;
private System.Windows.Forms.Label separatorLabel;
private System.Windows.Forms.ComboBox separatorComboBox;
private System.Windows.Forms.TextBox benchIdTextBox;
private System.Windows.Forms.Label benchIdLabel;
}
}