Day 12
This is some of the code I am working on at work using c#.
This is a small app used to verify a database structure.
#CodingPhase #TheCodingWay #365CodingPhaseChallenge
**********
using System;
using System.IO;
using System.Data.OleDb;
using System.Windows.Forms;
namespace VerChange
{
public partial class Form1 : Form
{
OpenFileDialog odb = new OpenFileDialog();
// private OleDbConnection connection = new OleDbConnection(); // This line sets up connecting to DB files
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
lbl_DefDB2.Text = Properties.Settings.Default.DB_Default; // This line populates the Default DB
lbl_CurDB2.Text = Properties.Settings.Default.DB_Current; // This line populates the Current / Last DB used
// This block populates the DB histories
lbl_DB11.Text = Properties.Settings.Default.DB1;
lbl_DB22.Text = Properties.Settings.Default.DB2;
lbl_DB33.Text = Properties.Settings.Default.DB3;
lbl_DB44.Text = Properties.Settings.Default.DB4;
lbl_DB55.Text = Properties.Settings.Default.DB5;
lbl_DB66.Text = Properties.Settings.Default.DB6;
lbl_DB77.Text = Properties.Settings.Default.DB7;
lbl_DB88.Text = Properties.Settings.Default.DB8;
lbl_DB99.Text = Properties.Settings.Default.DB9;
lbl_DB00.Text = Properties.Settings.Default.DB0;
DB_Read();
// End histories block
}
public void DB_Read()
{
try
{
string location = Properties.Settings.Default.DB_Current;
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + location + ";Persist Security Info=False;";
OleDbConnection conn = new OleDbConnection(connectionString); // This line sets up connecting to DB files
string sql_read = "SELECT * FROM ENO_METADATA";
conn.Open();
OleDbCommand cmd = new OleDbCommand(sql_read, conn);
OleDbDataReader reader;
reader = cmd.ExecuteReader();
while (reader.Read())
{
lbl_CurDBVer2.Text = reader.GetString(0).ToString();
}
reader.Close();
conn.Close();
}
catch
{
//MessageBox.Show("There is no active database connection. Please select a database to connect to.");
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")]
public void DB_Update(string DBVer)
{
string location = Properties.Settings.Default.DB_Current;
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + location + ";Persist Security Info=False;";
OleDbConnection conn = new OleDbConnection(connectionString); // This line sets up connecting to DB files
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
string sql_update = "update ENO_METADATA set DB_Version = '" + DBVer + "'";
cmd.CommandText = sql_update;
cmd.ExecuteNonQuery();
conn.Close();
}
private void btn_Open_Click(object sender, EventArgs e)
{
odb.Filter = "mdr|*.mdr";
if (odb.ShowDialog() == DialogResult.OK)
{
lbl_CurDB2.Text = odb.FileName;
Properties.Settings.Default.DB_Current = lbl_CurDB2.Text;
if (lbl_DB99.Text != null)
{
lbl_DB00.Text = lbl_DB99.Text;
Properties.Settings.Default.DB0 = lbl_DB00.Text;
}
if (lbl_DB88.Text != null)
{
lbl_DB99.Text = lbl_DB88.Text;
Properties.Settings.Default.DB9 = lbl_DB99.Text;
}
if (lbl_DB77.Text != null)
{
lbl_DB88.Text = lbl_DB77.Text;
Properties.Settings.Default.DB8 = lbl_DB88.Text;
}
if (lbl_DB66.Text != null)
{
lbl_DB77.Text = lbl_DB66.Text;
Properties.Settings.Default.DB7 = lbl_DB77.Text;
}
if (lbl_DB55.Text != null)
{
lbl_DB66.Text = lbl_DB55.Text;
Properties.Settings.Default.DB6 = lbl_DB66.Text;
}
if (lbl_DB44.Text != null)
{
lbl_DB55.Text = lbl_DB44.Text;
Properties.Settings.Default.DB5 = lbl_DB55.Text;
}
if (lbl_DB33.Text != null)
{
lbl_DB44.Text = lbl_DB33.Text;
Properties.Settings.Default.DB4 = lbl_DB44.Text;
}
if (lbl_DB22.Text != null)
{
lbl_DB33.Text = lbl_DB22.Text;
Properties.Settings.Default.DB3 = lbl_DB33.Text;
}
if (lbl_DB11.Text != null)
{
lbl_DB22.Text = lbl_DB11.Text;
Properties.Settings.Default.DB2 = lbl_DB22.Text;
lbl_DB11.Text = lbl_CurDB2.Text;
Properties.Settings.Default.DB1 = lbl_DB11.Text;
}
else
{
lbl_DB11.Text = lbl_CurDB2.Text;
Properties.Settings.Default.DB1 = lbl_DB11.Text;
}
Properties.Settings.Default.Save();
DB_Read();
}
}
private void btn_SetDefDB_Click(object sender, EventArgs e)
{
odb.Filter = "mdr|*.mdr";
if (odb.ShowDialog() == DialogResult.OK)
{
lbl_DefDB2.Text = odb.FileName;
Properties.Settings.Default.DB_Default = lbl_DefDB2.Text;
Properties.Settings.Default.Save();
}
}
private void btn_UseDefDB_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = Properties.Settings.Default.DB_Default;
Properties.Settings.Default.DB_Current = Properties.Settings.Default.DB_Default;
Properties.Settings.Default.Save();
DB_Read();
}
private void lbl_DB11_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB11.Text;
DB_Read();
Properties.Settings.Default.DB1 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void lbl_DB22_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB22.Text;
DB_Read();
Properties.Settings.Default.DB2 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void lbl_DB33_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB33.Text;
DB_Read();
Properties.Settings.Default.DB3 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void lbl_DB44_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB44.Text;
DB_Read();
Properties.Settings.Default.DB4 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void lbl_DB55_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB55.Text;
DB_Read();
Properties.Settings.Default.DB5 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void lbl_DB66_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB66.Text;
DB_Read();
Properties.Settings.Default.DB6 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void lbl_DB77_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB77.Text;
DB_Read();
Properties.Settings.Default.DB7 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void lbl_DB88_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB88.Text;
DB_Read();
Properties.Settings.Default.DB8 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void lbl_DB99_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB99.Text;
DB_Read();
Properties.Settings.Default.DB9 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void lbl_DB00_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB00.Text;
DB_Read();
Properties.Settings.Default.DB0 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void btn_7000_Click(object sender, EventArgs e)
{
try
{
DB_Update("7000");
DB_Read();
}
catch
{
MessageBox.Show("Please select a database file before attempting to change the version.");
}
}
private void btn_7021_Click(object sender, EventArgs e)
{
try
{
DB_Update("7021");
DB_Read();
}
catch
{
MessageBox.Show("Please select a database file before attempting to change the version.");
}
}
private void btn_7030_Click(object sender, EventArgs e)
{
try
{
DB_Update("7030");
DB_Read();
}
catch
{
MessageBox.Show("Please select a database file before attempting to change the version.");
}
}
private void btn_7050_Click(object sender, EventArgs e)
{
try
{
DB_Update("7050");
DB_Read();
}
catch
{
MessageBox.Show("Please select a database file before attempting to change the version.");
}
}
private void btn_Exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnClrHist_Click(object sender, EventArgs e)
{
lbl_DB11.Text = "";
lbl_DB22.Text = "";
lbl_DB33.Text = "";
lbl_DB44.Text = "";
lbl_DB55.Text = "";
lbl_DB66.Text = "";
lbl_DB77.Text = "";
lbl_DB88.Text = "";
lbl_DB99.Text = "";
lbl_DB00.Text = "";
lbl_CurDB2.Text = "";
Properties.Settings.Default.DB1 = lbl_DB11.Text;
Properties.Settings.Default.DB2 = lbl_DB22.Text;
Properties.Settings.Default.DB3 = lbl_DB33.Text;
Properties.Settings.Default.DB4 = lbl_DB44.Text;
Properties.Settings.Default.DB5 = lbl_DB55.Text;
Properties.Settings.Default.DB6 = lbl_DB66.Text;
Properties.Settings.Default.DB7 = lbl_DB77.Text;
Properties.Settings.Default.DB8 = lbl_DB88.Text;
Properties.Settings.Default.DB9 = lbl_DB99.Text;
Properties.Settings.Default.DB0 = lbl_DB00.Text;
Properties.Settings.Default.DB_Current = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
}
}
This is a small app used to verify a database structure.
#CodingPhase #TheCodingWay #365CodingPhaseChallenge
**********
using System;
using System.IO;
using System.Data.OleDb;
using System.Windows.Forms;
namespace VerChange
{
public partial class Form1 : Form
{
OpenFileDialog odb = new OpenFileDialog();
// private OleDbConnection connection = new OleDbConnection(); // This line sets up connecting to DB files
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
lbl_DefDB2.Text = Properties.Settings.Default.DB_Default; // This line populates the Default DB
lbl_CurDB2.Text = Properties.Settings.Default.DB_Current; // This line populates the Current / Last DB used
// This block populates the DB histories
lbl_DB11.Text = Properties.Settings.Default.DB1;
lbl_DB22.Text = Properties.Settings.Default.DB2;
lbl_DB33.Text = Properties.Settings.Default.DB3;
lbl_DB44.Text = Properties.Settings.Default.DB4;
lbl_DB55.Text = Properties.Settings.Default.DB5;
lbl_DB66.Text = Properties.Settings.Default.DB6;
lbl_DB77.Text = Properties.Settings.Default.DB7;
lbl_DB88.Text = Properties.Settings.Default.DB8;
lbl_DB99.Text = Properties.Settings.Default.DB9;
lbl_DB00.Text = Properties.Settings.Default.DB0;
DB_Read();
// End histories block
}
public void DB_Read()
{
try
{
string location = Properties.Settings.Default.DB_Current;
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + location + ";Persist Security Info=False;";
OleDbConnection conn = new OleDbConnection(connectionString); // This line sets up connecting to DB files
string sql_read = "SELECT * FROM ENO_METADATA";
conn.Open();
OleDbCommand cmd = new OleDbCommand(sql_read, conn);
OleDbDataReader reader;
reader = cmd.ExecuteReader();
while (reader.Read())
{
lbl_CurDBVer2.Text = reader.GetString(0).ToString();
}
reader.Close();
conn.Close();
}
catch
{
//MessageBox.Show("There is no active database connection. Please select a database to connect to.");
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")]
public void DB_Update(string DBVer)
{
string location = Properties.Settings.Default.DB_Current;
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + location + ";Persist Security Info=False;";
OleDbConnection conn = new OleDbConnection(connectionString); // This line sets up connecting to DB files
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
string sql_update = "update ENO_METADATA set DB_Version = '" + DBVer + "'";
cmd.CommandText = sql_update;
cmd.ExecuteNonQuery();
conn.Close();
}
private void btn_Open_Click(object sender, EventArgs e)
{
odb.Filter = "mdr|*.mdr";
if (odb.ShowDialog() == DialogResult.OK)
{
lbl_CurDB2.Text = odb.FileName;
Properties.Settings.Default.DB_Current = lbl_CurDB2.Text;
if (lbl_DB99.Text != null)
{
lbl_DB00.Text = lbl_DB99.Text;
Properties.Settings.Default.DB0 = lbl_DB00.Text;
}
if (lbl_DB88.Text != null)
{
lbl_DB99.Text = lbl_DB88.Text;
Properties.Settings.Default.DB9 = lbl_DB99.Text;
}
if (lbl_DB77.Text != null)
{
lbl_DB88.Text = lbl_DB77.Text;
Properties.Settings.Default.DB8 = lbl_DB88.Text;
}
if (lbl_DB66.Text != null)
{
lbl_DB77.Text = lbl_DB66.Text;
Properties.Settings.Default.DB7 = lbl_DB77.Text;
}
if (lbl_DB55.Text != null)
{
lbl_DB66.Text = lbl_DB55.Text;
Properties.Settings.Default.DB6 = lbl_DB66.Text;
}
if (lbl_DB44.Text != null)
{
lbl_DB55.Text = lbl_DB44.Text;
Properties.Settings.Default.DB5 = lbl_DB55.Text;
}
if (lbl_DB33.Text != null)
{
lbl_DB44.Text = lbl_DB33.Text;
Properties.Settings.Default.DB4 = lbl_DB44.Text;
}
if (lbl_DB22.Text != null)
{
lbl_DB33.Text = lbl_DB22.Text;
Properties.Settings.Default.DB3 = lbl_DB33.Text;
}
if (lbl_DB11.Text != null)
{
lbl_DB22.Text = lbl_DB11.Text;
Properties.Settings.Default.DB2 = lbl_DB22.Text;
lbl_DB11.Text = lbl_CurDB2.Text;
Properties.Settings.Default.DB1 = lbl_DB11.Text;
}
else
{
lbl_DB11.Text = lbl_CurDB2.Text;
Properties.Settings.Default.DB1 = lbl_DB11.Text;
}
Properties.Settings.Default.Save();
DB_Read();
}
}
private void btn_SetDefDB_Click(object sender, EventArgs e)
{
odb.Filter = "mdr|*.mdr";
if (odb.ShowDialog() == DialogResult.OK)
{
lbl_DefDB2.Text = odb.FileName;
Properties.Settings.Default.DB_Default = lbl_DefDB2.Text;
Properties.Settings.Default.Save();
}
}
private void btn_UseDefDB_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = Properties.Settings.Default.DB_Default;
Properties.Settings.Default.DB_Current = Properties.Settings.Default.DB_Default;
Properties.Settings.Default.Save();
DB_Read();
}
private void lbl_DB11_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB11.Text;
DB_Read();
Properties.Settings.Default.DB1 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void lbl_DB22_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB22.Text;
DB_Read();
Properties.Settings.Default.DB2 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void lbl_DB33_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB33.Text;
DB_Read();
Properties.Settings.Default.DB3 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void lbl_DB44_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB44.Text;
DB_Read();
Properties.Settings.Default.DB4 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void lbl_DB55_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB55.Text;
DB_Read();
Properties.Settings.Default.DB5 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void lbl_DB66_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB66.Text;
DB_Read();
Properties.Settings.Default.DB6 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void lbl_DB77_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB77.Text;
DB_Read();
Properties.Settings.Default.DB7 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void lbl_DB88_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB88.Text;
DB_Read();
Properties.Settings.Default.DB8 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void lbl_DB99_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB99.Text;
DB_Read();
Properties.Settings.Default.DB9 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void lbl_DB00_Click(object sender, EventArgs e)
{
lbl_CurDB2.Text = lbl_DB00.Text;
DB_Read();
Properties.Settings.Default.DB0 = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
private void btn_7000_Click(object sender, EventArgs e)
{
try
{
DB_Update("7000");
DB_Read();
}
catch
{
MessageBox.Show("Please select a database file before attempting to change the version.");
}
}
private void btn_7021_Click(object sender, EventArgs e)
{
try
{
DB_Update("7021");
DB_Read();
}
catch
{
MessageBox.Show("Please select a database file before attempting to change the version.");
}
}
private void btn_7030_Click(object sender, EventArgs e)
{
try
{
DB_Update("7030");
DB_Read();
}
catch
{
MessageBox.Show("Please select a database file before attempting to change the version.");
}
}
private void btn_7050_Click(object sender, EventArgs e)
{
try
{
DB_Update("7050");
DB_Read();
}
catch
{
MessageBox.Show("Please select a database file before attempting to change the version.");
}
}
private void btn_Exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnClrHist_Click(object sender, EventArgs e)
{
lbl_DB11.Text = "";
lbl_DB22.Text = "";
lbl_DB33.Text = "";
lbl_DB44.Text = "";
lbl_DB55.Text = "";
lbl_DB66.Text = "";
lbl_DB77.Text = "";
lbl_DB88.Text = "";
lbl_DB99.Text = "";
lbl_DB00.Text = "";
lbl_CurDB2.Text = "";
Properties.Settings.Default.DB1 = lbl_DB11.Text;
Properties.Settings.Default.DB2 = lbl_DB22.Text;
Properties.Settings.Default.DB3 = lbl_DB33.Text;
Properties.Settings.Default.DB4 = lbl_DB44.Text;
Properties.Settings.Default.DB5 = lbl_DB55.Text;
Properties.Settings.Default.DB6 = lbl_DB66.Text;
Properties.Settings.Default.DB7 = lbl_DB77.Text;
Properties.Settings.Default.DB8 = lbl_DB88.Text;
Properties.Settings.Default.DB9 = lbl_DB99.Text;
Properties.Settings.Default.DB0 = lbl_DB00.Text;
Properties.Settings.Default.DB_Current = lbl_CurDB2.Text;
Properties.Settings.Default.Save();
}
}
}
Comments
Post a Comment