diff --git a/trayToDB/App.config b/trayToDB/App.config
index 8e15646..66bb211 100644
--- a/trayToDB/App.config
+++ b/trayToDB/App.config
@@ -1,6 +1,30 @@
-
+
+
+
+
+
+
-
+
-
\ No newline at end of file
+
+
+
+ localhost
+
+
+ 3306
+
+
+ sipmtest
+
+
+ sipm
+
+
+
+
+
+
+
diff --git a/trayToDB/Form1.Designer.cs b/trayToDB/Form1.Designer.cs
deleted file mode 100644
index 6a76feb..0000000
--- a/trayToDB/Form1.Designer.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-namespace trayToDB
-{
- partial class Form1
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing)
- {
- if (disposing && (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.components = new System.ComponentModel.Container();
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
- this.Text = "Form1";
- }
-
- #endregion
- }
-}
-
diff --git a/trayToDB/Form1.cs b/trayToDB/Form1.cs
deleted file mode 100644
index c46dfe5..0000000
--- a/trayToDB/Form1.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace trayToDB
-{
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- }
-}
diff --git a/trayToDB/MainWindow.Designer.cs b/trayToDB/MainWindow.Designer.cs
new file mode 100644
index 0000000..0545798
--- /dev/null
+++ b/trayToDB/MainWindow.Designer.cs
@@ -0,0 +1,213 @@
+namespace trayToDB
+{
+ partial class MainWindow
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (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.label1 = new System.Windows.Forms.Label();
+ this.label2 = new System.Windows.Forms.Label();
+ this.label3 = new System.Windows.Forms.Label();
+ this.filenameTextbox = new System.Windows.Forms.TextBox();
+ this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
+ this.browseButton = new System.Windows.Forms.Button();
+ this.uploadButton = new System.Windows.Forms.Button();
+ this.statusTextbox = new System.Windows.Forms.RichTextBox();
+ this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
+ this.menuStrip1 = new System.Windows.Forms.MenuStrip();
+ this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.settingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.menuStrip1.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(12, 38);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(138, 20);
+ this.label1.TabIndex = 0;
+ this.label1.Text = "Open Excel sheet:";
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(12, 85);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(123, 20);
+ this.label2.TabIndex = 1;
+ this.label2.Text = "Pick arrival date:";
+ //
+ // label3
+ //
+ this.label3.AutoSize = true;
+ this.label3.Location = new System.Drawing.Point(12, 115);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(56, 20);
+ this.label3.TabIndex = 2;
+ this.label3.Text = "Status";
+ //
+ // filenameTextbox
+ //
+ this.filenameTextbox.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.filenameTextbox.Location = new System.Drawing.Point(156, 35);
+ this.filenameTextbox.Name = "filenameTextbox";
+ this.filenameTextbox.Size = new System.Drawing.Size(350, 26);
+ this.filenameTextbox.TabIndex = 3;
+ //
+ // dateTimePicker1
+ //
+ this.dateTimePicker1.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.dateTimePicker1.Location = new System.Drawing.Point(156, 78);
+ this.dateTimePicker1.Name = "dateTimePicker1";
+ this.dateTimePicker1.Size = new System.Drawing.Size(350, 26);
+ this.dateTimePicker1.TabIndex = 4;
+ this.dateTimePicker1.Value = new System.DateTime(2019, 3, 15, 0, 0, 0, 0);
+ //
+ // browseButton
+ //
+ this.browseButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.browseButton.Location = new System.Drawing.Point(513, 32);
+ this.browseButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
+ this.browseButton.Name = "browseButton";
+ this.browseButton.Size = new System.Drawing.Size(112, 35);
+ this.browseButton.TabIndex = 5;
+ this.browseButton.Text = "Browse";
+ this.browseButton.UseVisualStyleBackColor = true;
+ this.browseButton.Click += new System.EventHandler(this.browseButton_Click);
+ //
+ // uploadButton
+ //
+ this.uploadButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.uploadButton.Location = new System.Drawing.Point(513, 77);
+ this.uploadButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
+ this.uploadButton.Name = "uploadButton";
+ this.uploadButton.Size = new System.Drawing.Size(112, 35);
+ this.uploadButton.TabIndex = 6;
+ this.uploadButton.Text = "Upload";
+ this.uploadButton.UseVisualStyleBackColor = true;
+ this.uploadButton.Click += new System.EventHandler(this.uploadButton_Click);
+ //
+ // statusTextbox
+ //
+ this.statusTextbox.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.statusTextbox.Location = new System.Drawing.Point(14, 142);
+ this.statusTextbox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
+ this.statusTextbox.Name = "statusTextbox";
+ this.statusTextbox.ReadOnly = true;
+ this.statusTextbox.Size = new System.Drawing.Size(612, 479);
+ this.statusTextbox.TabIndex = 7;
+ this.statusTextbox.Text = "";
+ this.statusTextbox.TextChanged += new System.EventHandler(this.statusTextbox_TextChanged);
+ //
+ // openFileDialog1
+ //
+ this.openFileDialog1.FileName = "openFileDialog1";
+ //
+ // menuStrip1
+ //
+ this.menuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
+ this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.fileToolStripMenuItem});
+ this.menuStrip1.Location = new System.Drawing.Point(0, 0);
+ this.menuStrip1.Name = "menuStrip1";
+ this.menuStrip1.Size = new System.Drawing.Size(638, 33);
+ this.menuStrip1.TabIndex = 8;
+ this.menuStrip1.Text = "menuStrip1";
+ //
+ // fileToolStripMenuItem
+ //
+ this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.settingsToolStripMenuItem,
+ this.exitToolStripMenuItem});
+ this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
+ this.fileToolStripMenuItem.Size = new System.Drawing.Size(50, 29);
+ this.fileToolStripMenuItem.Text = "File";
+ //
+ // settingsToolStripMenuItem
+ //
+ this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem";
+ this.settingsToolStripMenuItem.Size = new System.Drawing.Size(160, 30);
+ this.settingsToolStripMenuItem.Text = "Settings";
+ this.settingsToolStripMenuItem.Click += new System.EventHandler(this.settingsToolStripMenuItem_Click);
+ //
+ // exitToolStripMenuItem
+ //
+ this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
+ this.exitToolStripMenuItem.Size = new System.Drawing.Size(160, 30);
+ this.exitToolStripMenuItem.Text = "Exit";
+ this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
+ //
+ // MainWindow
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(638, 634);
+ this.Controls.Add(this.statusTextbox);
+ this.Controls.Add(this.uploadButton);
+ this.Controls.Add(this.browseButton);
+ this.Controls.Add(this.dateTimePicker1);
+ this.Controls.Add(this.filenameTextbox);
+ this.Controls.Add(this.label3);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.label1);
+ this.Controls.Add(this.menuStrip1);
+ this.MainMenuStrip = this.menuStrip1;
+ this.Name = "MainWindow";
+ this.Text = "Tray sheet to Database";
+ this.Load += new System.EventHandler(this.Form1_Load);
+ this.menuStrip1.ResumeLayout(false);
+ this.menuStrip1.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.Label label2;
+ private System.Windows.Forms.Label label3;
+ private System.Windows.Forms.TextBox filenameTextbox;
+ private System.Windows.Forms.DateTimePicker dateTimePicker1;
+ private System.Windows.Forms.Button browseButton;
+ private System.Windows.Forms.Button uploadButton;
+ private System.Windows.Forms.RichTextBox statusTextbox;
+ private System.Windows.Forms.OpenFileDialog openFileDialog1;
+ private System.Windows.Forms.MenuStrip menuStrip1;
+ private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem settingsToolStripMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
+ }
+}
+
diff --git a/trayToDB/MainWindow.cs b/trayToDB/MainWindow.cs
new file mode 100644
index 0000000..c210422
--- /dev/null
+++ b/trayToDB/MainWindow.cs
@@ -0,0 +1,277 @@
+using MySql.Data.MySqlClient;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using Excel = Microsoft.Office.Interop.Excel;
+
+/*
+ * Author: David Baranyai | 2019.03.13
+ * divaldo95@gmail.com
+ */
+
+namespace trayToDB
+{
+ struct SiPMData
+ {
+ public int trayNo;
+ public double Vopl;
+ public double Voph;
+ public int noOfSipm;
+
+ public string GetValues()
+ {
+ return "Tray number: " + trayNo + "\nVop: " + Vopl + " - " + Voph + "\nNumber of SiPM: " + noOfSipm + "\n";
+ }
+ };
+
+ public partial class MainWindow : Form
+ {
+ private List listOfData;
+ private DateTime shippingDate;
+
+ private static string server = "localhost";
+ private static string user = "sipm";
+ private static string database = "sipmtest";
+ private static string port = "3306";
+ //private static string password = "";
+
+ public MainWindow()
+ {
+ InitializeComponent();
+ uploadButton.Enabled = false;
+ //Set the file extensions to xls and xlsx and turn on warnings if the file not exists
+ openFileDialog1 = new OpenFileDialog();
+ openFileDialog1.Filter = "Excel sheets (*.xls;*.xlsx)|*.xls;*.xlsx";
+ openFileDialog1.Multiselect = false;
+ openFileDialog1.CheckFileExists = true;
+
+ }
+
+ private void Form1_Load(object sender, EventArgs e)
+ {
+
+ }
+
+ private void browseButton_Click(object sender, EventArgs e)
+ {
+ Excel.Application xlApp;
+ Excel.Workbook xlWorkBook;
+ Excel.Worksheet xlWorkSheet;
+ object misValue = System.Reflection.Missing.Value;
+
+ xlApp = new Excel.Application();
+
+ if (openFileDialog1.ShowDialog() == DialogResult.OK)
+ {
+ filenameTextbox.Text = openFileDialog1.FileName;
+ try
+ {
+ xlWorkBook = xlApp.Workbooks.Open(openFileDialog1.FileName, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
+ xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
+
+ Excel.Range currentFind = xlWorkSheet.UsedRange;
+
+ //--------------------------------------TO DO - IF NOT FOUND!-----------------------------------------------
+ //Find cell that contains "Shipping date" and extract the value next to it
+ Excel.Range tempRange = currentFind.Find("Shipping date", LookAt: Excel.XlLookAt.xlWhole);
+ if(tempRange == null)
+ {
+ throw new Exception("Not found any cells that contains 'Shipping date'. Maybe the file structure is changed\n");
+ }
+ int shipdateRow = tempRange.Row;
+ int shipdateColumn = tempRange.Column;
+ shippingDate = DateTime.FromOADate(currentFind.Cells[shipdateRow, shipdateColumn + 1].Value2);
+
+ //Print out the date
+ statusTextbox.AppendText("Shipping date: " + shippingDate.ToLongDateString() + "\n");
+
+ /*Find cell that contains "Tray No."
+ *In the first version the structure is the following:
+ * Tray no | Vop range | Quantum
+ */
+ tempRange = currentFind.Find("Tray No.", LookAt: Excel.XlLookAt.xlWhole);
+ if (tempRange == null)
+ {
+ throw new Exception("Not found any cells that contains 'Tray No.'. Maybe the file structure is changed\n");
+ }
+ int trayNoRow = tempRange.Row;
+ int trayNoColumn = tempRange.Column;
+
+ int iterator = trayNoRow + 1; //the iterator starts from the next row
+
+ listOfData = new List(); //make a list from every row
+ SiPMData data = new SiPMData(); //Helper for inserting into the list
+
+ //Read every row until found an empty one
+ while (currentFind.Cells[iterator, trayNoColumn].Value2 != null)
+ {
+ data.trayNo = Convert.ToInt16(currentFind.Cells[iterator, trayNoColumn].Value2); //Get tray number
+ string Vop = currentFind.Cells[iterator, trayNoColumn + 1].Value2.ToString(); //Get Vops
+ //Split the Vops into low and high
+ //Use dot as decimal point
+ CultureInfo culture = new CultureInfo("en");
+ string[] splittedString = Vop.Split('-');
+ if(splittedString.Length == 2)
+ {
+ data.Vopl = Double.Parse(splittedString[0], culture);
+ data.Voph = Double.Parse(splittedString[1], culture);
+ }
+ else
+ {
+ throw new Exception("Invalid Vop format!");
+ }
+ //double[] doubles = Vop.Split('-').Select(double.Parse).ToArray();
+ /*if(doubles.Length == 2)
+ {
+ data.Vopl = doubles[0];
+ data.Voph = doubles[1];
+ }
+ */
+ data.noOfSipm = Convert.ToInt16(currentFind.Cells[iterator, trayNoColumn + 2].Value2); //Get number of sipms
+ statusTextbox.AppendText(data.GetValues()); //Write the data to the status textbox
+ listOfData.Add(data); //add every row into the list
+ iterator++; //increment the row iterator
+ }
+
+ //Close the excel related things
+ xlWorkBook.Close(true, misValue, misValue);
+ xlApp.Quit();
+
+ releaseObject(xlWorkSheet);
+ releaseObject(xlWorkBook);
+ releaseObject(xlApp);
+
+ uploadButton.Enabled = true;
+ }
+ catch(Exception ex)
+ {
+ statusTextbox.AppendText(ex.Message);
+ uploadButton.Enabled = false;
+ }
+ }
+ }
+
+ private void releaseObject(object obj)
+ {
+ try
+ {
+ System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
+ obj = null;
+ }
+ catch (Exception ex)
+ {
+ obj = null;
+ MessageBox.Show("Unable to release the Object " + ex.ToString());
+ }
+ finally
+ {
+ GC.Collect();
+ }
+ }
+
+ private void uploadButton_Click(object sender, EventArgs e)
+ {
+ string connStr = "server=" + Properties.Settings.Default.server + "; user=" + Properties.Settings.Default.user + "; database=" + Properties.Settings.Default.database + "; port=" + Properties.Settings.Default.port + "; password=" + Settings.Decrypt(Properties.Settings.Default.password);
+ //"server=" + server + "; user=" + user + "; database=" + database + "; port=" + port + "; password=";
+ MySqlConnection conn = new MySqlConnection(connStr);
+ try
+ {
+ statusTextbox.AppendText("Connecting to " + user + "@" + server + ":" + port + "\n");
+ conn.Open();
+ statusTextbox.AppendText("Successfully connected\n");
+ // Perform database operations
+ MySqlCommand cmd = conn.CreateCommand();
+ //Check if row already exists
+ cmd.CommandText = "SELECT COUNT(*) AS numofshippingid FROM hamamatsushippingtable WHERE shipdate = convert(@shipping, DATE) AND arrivedate = convert(@arrival,DATE);";
+ cmd.Parameters.AddWithValue("@arrival", dateTimePicker1.Value);
+ cmd.Parameters.AddWithValue("@shipping", shippingDate);
+ cmd.Parameters.AddWithValue("@numoftrays", listOfData.Count);
+ MySqlDataReader reader = cmd.ExecuteReader();
+ if (reader.Read())
+ {
+ if(reader.GetInt16("numofshippingid") != 0)
+ {
+ throw new Exception("Database contains data with the same dates, check it!");
+ }
+ else
+ {
+ statusTextbox.AppendText("Adding new shipping id!\n");
+ reader.Close();
+ }
+ }
+ else
+ {
+ throw new Exception("Query error!");
+ }
+ cmd.CommandText = "INSERT INTO hamamatsushippingtable (arrivedate, shipdate, ntrays) VALUES (@arrival, @shipping, @numoftrays)";
+ if (cmd.ExecuteNonQuery() == 1) //Affected rows should be one
+ {
+ statusTextbox.AppendText("Succesfully inserted the tray's data\n");
+ }
+ else
+ {
+ statusTextbox.AppendText("Something went wrong!");
+ }
+ for (int i = 0; i < listOfData.Count; i++)
+ {
+ cmd.Parameters.Clear();
+ cmd.CommandText = "INSERT INTO hamamatsutraytable (shippingid, traynumber, vlow, vhigh, nsipms) VALUES ((SELECT MAX(shippingid) AS shippingid FROM hamamatsushippingtable), @trayno, @vl, @vh, @noofsipm)";
+ cmd.Parameters.AddWithValue("@trayno", listOfData[i].trayNo);
+ cmd.Parameters.AddWithValue("@vl", listOfData[i].Vopl);
+ cmd.Parameters.AddWithValue("@vh", listOfData[i].Voph);
+ cmd.Parameters.AddWithValue("@noofsipm", listOfData[i].noOfSipm);
+ if (cmd.ExecuteNonQuery() == 1)
+ {
+ statusTextbox.AppendText("Succesfully inserted! Tray ID: " + listOfData[i].trayNo + "\n");
+ }
+ else
+ {
+ statusTextbox.AppendText("Something went wrong!");
+ }
+ }
+ conn.Close();
+ uploadButton.Enabled = false;
+ }
+ catch (MySqlException ex)
+ {
+ switch (ex.Number)
+ {
+ case 0:
+ //MessageBox.Show("Cannot connect to server. Contact administrator");
+ MessageBox.Show(ex.ToString());
+ break;
+ case 1045:
+ MessageBox.Show("Invalid username/password, please try again");
+ break;
+ }
+ }
+ catch (Exception ex)
+ {
+ statusTextbox.AppendText(ex.Message);
+ }
+ }
+
+ private void statusTextbox_TextChanged(object sender, EventArgs e)
+ {
+ statusTextbox.ScrollToCaret();
+ }
+
+ private void exitToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ Application.Exit();
+ }
+
+ private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ Settings settings = new Settings();
+ settings.Show();
+ }
+ }
+}
diff --git a/trayToDB/MainWindow.resx b/trayToDB/MainWindow.resx
new file mode 100644
index 0000000..94a26ed
--- /dev/null
+++ b/trayToDB/MainWindow.resx
@@ -0,0 +1,126 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ 17, 17
+
+
+ 211, 17
+
+
\ No newline at end of file
diff --git a/trayToDB/PortableSettingsProvider.cs b/trayToDB/PortableSettingsProvider.cs
new file mode 100644
index 0000000..233cd87
--- /dev/null
+++ b/trayToDB/PortableSettingsProvider.cs
@@ -0,0 +1,190 @@
+using System.Linq;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Windows.Forms;
+using System.Collections.Specialized;
+using System.Xml;
+using System.IO;
+
+namespace crdx.Settings
+{
+ public sealed class PortableSettingsProvider : SettingsProvider, IApplicationSettingsProvider
+ {
+ private const string _rootNodeName = "settings";
+ //private const string _localSettingsNodeName = "localSettings";
+ private const string _globalSettingsNodeName = "globalSettings";
+ private const string _className = "PortableSettingsProvider";
+ private XmlDocument _xmlDocument;
+
+ private string _filePath
+ {
+ get
+ {
+ return Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),
+ "settings.conf");
+ }
+ }
+
+ private XmlNode _globalSettingsNode
+ {
+ get { return GetSettingsNode(_globalSettingsNodeName); }
+ }
+
+ private XmlNode _rootNode
+ {
+ get { return _rootDocument.SelectSingleNode(_rootNodeName); }
+ }
+
+ private XmlDocument _rootDocument
+ {
+ get
+ {
+ if (_xmlDocument == null)
+ {
+ try
+ {
+ _xmlDocument = new XmlDocument();
+ _xmlDocument.Load(_filePath);
+ }
+ catch (Exception)
+ {
+
+ }
+
+ if (_xmlDocument.SelectSingleNode(_rootNodeName) != null)
+ return _xmlDocument;
+
+ _xmlDocument = GetBlankXmlDocument();
+ }
+
+ return _xmlDocument;
+ }
+
+ }
+
+ public override string ApplicationName
+ {
+ get { return Path.GetFileNameWithoutExtension(Application.ExecutablePath); }
+ set { }
+ }
+
+ public override string Name
+ {
+ get { return _className; }
+ }
+
+ public override void Initialize(string name, NameValueCollection config)
+ {
+ base.Initialize(Name, config);
+ }
+
+ public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
+ {
+ foreach (SettingsPropertyValue propertyValue in collection)
+ SetValue(propertyValue);
+
+ try
+ {
+ _rootDocument.Save(_filePath);
+ }
+ catch (Exception)
+ {
+ /*
+ * If this is a portable application and the device has been
+ * removed then this will fail, so don't do anything. It's
+ * probably better for the application to stop saving settings
+ * rather than just crashing outright. Probably.
+ */
+ }
+ }
+
+ public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
+ {
+ SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
+
+ foreach (SettingsProperty property in collection)
+ {
+ values.Add(new SettingsPropertyValue(property)
+ {
+ SerializedValue = GetValue(property)
+ });
+ }
+
+ return values;
+ }
+
+ private void SetValue(SettingsPropertyValue propertyValue)
+ {
+ XmlNode targetNode = _globalSettingsNode;
+
+ XmlNode settingNode = targetNode.SelectSingleNode(string.Format("setting[@name='{0}']", propertyValue.Name));
+
+ if (settingNode != null)
+ settingNode.InnerText = propertyValue.SerializedValue.ToString();
+ else
+ {
+ settingNode = _rootDocument.CreateElement("setting");
+
+ XmlAttribute nameAttribute = _rootDocument.CreateAttribute("name");
+ nameAttribute.Value = propertyValue.Name;
+
+ settingNode.Attributes.Append(nameAttribute);
+ settingNode.InnerText = propertyValue.SerializedValue.ToString();
+
+ targetNode.AppendChild(settingNode);
+ }
+ }
+
+ private string GetValue(SettingsProperty property)
+ {
+ XmlNode targetNode = _globalSettingsNode;
+ XmlNode settingNode = targetNode.SelectSingleNode(string.Format("setting[@name='{0}']", property.Name));
+
+ if (settingNode == null)
+ return property.DefaultValue != null ? property.DefaultValue.ToString() : string.Empty;
+
+ return settingNode.InnerText;
+ }
+
+ private XmlNode GetSettingsNode(string name)
+ {
+ XmlNode settingsNode = _rootNode.SelectSingleNode(name);
+
+ if (settingsNode == null)
+ {
+ settingsNode = _rootDocument.CreateElement(name);
+ _rootNode.AppendChild(settingsNode);
+ }
+
+ return settingsNode;
+ }
+
+ public XmlDocument GetBlankXmlDocument()
+ {
+ XmlDocument blankXmlDocument = new XmlDocument();
+ blankXmlDocument.AppendChild(blankXmlDocument.CreateXmlDeclaration("1.0", "utf-8", string.Empty));
+ blankXmlDocument.AppendChild(blankXmlDocument.CreateElement(_rootNodeName));
+
+ return blankXmlDocument;
+ }
+
+ public void Reset(SettingsContext context)
+ {
+ _globalSettingsNode.RemoveAll();
+
+ _xmlDocument.Save(_filePath);
+ }
+
+ public SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property)
+ {
+ // do nothing
+ return new SettingsPropertyValue(property);
+ }
+
+ public void Upgrade(SettingsContext context, SettingsPropertyCollection properties)
+ {
+ }
+ }
+}
\ No newline at end of file
diff --git a/trayToDB/Program.cs b/trayToDB/Program.cs
index af58fcc..3ed0253 100644
--- a/trayToDB/Program.cs
+++ b/trayToDB/Program.cs
@@ -16,7 +16,7 @@ namespace trayToDB
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new Form1());
+ Application.Run(new MainWindow());
}
}
}
diff --git a/trayToDB/Properties/Resources.Designer.cs b/trayToDB/Properties/Resources.Designer.cs
index e2591d9..fb3ddc0 100644
--- a/trayToDB/Properties/Resources.Designer.cs
+++ b/trayToDB/Properties/Resources.Designer.cs
@@ -8,10 +8,10 @@
//
//------------------------------------------------------------------------------
-namespace trayToDB.Properties
-{
-
-
+namespace trayToDB.Properties {
+ using System;
+
+
///
/// A strongly-typed resource class, for looking up localized strings, etc.
///
@@ -19,51 +19,43 @@ namespace trayToDB.Properties
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- internal class Resources
- {
-
+ internal class Resources {
+
private static global::System.Resources.ResourceManager resourceMan;
-
+
private static global::System.Globalization.CultureInfo resourceCulture;
-
+
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal Resources()
- {
+ internal Resources() {
}
-
+
///
/// Returns the cached ResourceManager instance used by this class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Resources.ResourceManager ResourceManager
- {
- get
- {
- if ((resourceMan == null))
- {
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("trayToDB.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
-
+
///
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture
- {
- get
- {
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
return resourceCulture;
}
- set
- {
+ set {
resourceCulture = value;
}
}
diff --git a/trayToDB/Properties/Resources.resx b/trayToDB/Properties/Resources.resx
index af7dbeb..1af7de1 100644
--- a/trayToDB/Properties/Resources.resx
+++ b/trayToDB/Properties/Resources.resx
@@ -46,7 +46,7 @@
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
- : System.Serialization.Formatters.Binary.BinaryFormatter
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
@@ -60,6 +60,7 @@
: and then encoded with base64 encoding.
-->
+
@@ -68,9 +69,10 @@
-
+
+
@@ -85,9 +87,10 @@
-
+
+
@@ -109,9 +112,9 @@
2.0
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
\ No newline at end of file
diff --git a/trayToDB/Properties/Settings.Designer.cs b/trayToDB/Properties/Settings.Designer.cs
index 60379e9..f87e0cb 100644
--- a/trayToDB/Properties/Settings.Designer.cs
+++ b/trayToDB/Properties/Settings.Designer.cs
@@ -8,23 +8,109 @@
//
//------------------------------------------------------------------------------
-namespace trayToDB.Properties
-{
-
-
+namespace trayToDB.Properties {
+
+
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
- internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
- {
-
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
-
- public static Settings Default
- {
- get
- {
+
+ public static Settings Default {
+ get {
return defaultInstance;
}
}
+
+ ///
+ /// MySQL server IP address
+ ///
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Configuration.SettingsProviderAttribute(typeof(crdx.Settings.PortableSettingsProvider))]
+ [global::System.Configuration.SettingsDescriptionAttribute("MySQL server IP address")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("localhost")]
+ [global::System.Configuration.SettingsManageabilityAttribute(global::System.Configuration.SettingsManageability.Roaming)]
+ public string server {
+ get {
+ return ((string)(this["server"]));
+ }
+ set {
+ this["server"] = value;
+ }
+ }
+
+ ///
+ /// MySQL server port
+ ///
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Configuration.SettingsProviderAttribute(typeof(crdx.Settings.PortableSettingsProvider))]
+ [global::System.Configuration.SettingsDescriptionAttribute("MySQL server port")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("3306")]
+ [global::System.Configuration.SettingsManageabilityAttribute(global::System.Configuration.SettingsManageability.Roaming)]
+ public int port {
+ get {
+ return ((int)(this["port"]));
+ }
+ set {
+ this["port"] = value;
+ }
+ }
+
+ ///
+ /// Database name
+ ///
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Configuration.SettingsProviderAttribute(typeof(crdx.Settings.PortableSettingsProvider))]
+ [global::System.Configuration.SettingsDescriptionAttribute("Database name")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("sipmtest")]
+ [global::System.Configuration.SettingsManageabilityAttribute(global::System.Configuration.SettingsManageability.Roaming)]
+ public string database {
+ get {
+ return ((string)(this["database"]));
+ }
+ set {
+ this["database"] = value;
+ }
+ }
+
+ ///
+ /// Username for MySQL
+ ///
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Configuration.SettingsProviderAttribute(typeof(crdx.Settings.PortableSettingsProvider))]
+ [global::System.Configuration.SettingsDescriptionAttribute("Username for MySQL")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("sipm")]
+ [global::System.Configuration.SettingsManageabilityAttribute(global::System.Configuration.SettingsManageability.Roaming)]
+ public string user {
+ get {
+ return ((string)(this["user"]));
+ }
+ set {
+ this["user"] = value;
+ }
+ }
+
+ ///
+ /// Password, do not edit with text editor!
+ ///
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Configuration.SettingsProviderAttribute(typeof(crdx.Settings.PortableSettingsProvider))]
+ [global::System.Configuration.SettingsDescriptionAttribute("Password, do not edit with text editor!")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("")]
+ [global::System.Configuration.SettingsManageabilityAttribute(global::System.Configuration.SettingsManageability.Roaming)]
+ public string password {
+ get {
+ return ((string)(this["password"]));
+ }
+ set {
+ this["password"] = value;
+ }
+ }
}
}
diff --git a/trayToDB/Properties/Settings.settings b/trayToDB/Properties/Settings.settings
index 3964565..9e5012e 100644
--- a/trayToDB/Properties/Settings.settings
+++ b/trayToDB/Properties/Settings.settings
@@ -1,7 +1,21 @@
-
-
-
-
-
-
+
+
+
+
+ localhost
+
+
+ 3306
+
+
+ sipmtest
+
+
+ sipm
+
+
+
+
+
+
\ No newline at end of file
diff --git a/trayToDB/Settings.Designer.cs b/trayToDB/Settings.Designer.cs
new file mode 100644
index 0000000..fba8895
--- /dev/null
+++ b/trayToDB/Settings.Designer.cs
@@ -0,0 +1,235 @@
+namespace trayToDB
+{
+ partial class Settings
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (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.label1 = new System.Windows.Forms.Label();
+ this.label2 = new System.Windows.Forms.Label();
+ this.label3 = new System.Windows.Forms.Label();
+ this.label4 = new System.Windows.Forms.Label();
+ this.passwordTextbox = new System.Windows.Forms.TextBox();
+ this.userTextbox = new System.Windows.Forms.TextBox();
+ this.okButton = new System.Windows.Forms.Button();
+ this.testButton = new System.Windows.Forms.Button();
+ this.cancelButton = new System.Windows.Forms.Button();
+ this.serverSelector = new System.Windows.Forms.ComboBox();
+ this.port = new System.Windows.Forms.NumericUpDown();
+ this.label5 = new System.Windows.Forms.Label();
+ this.databaseTextbox = new System.Windows.Forms.TextBox();
+ ((System.ComponentModel.ISupportInitialize)(this.port)).BeginInit();
+ this.SuspendLayout();
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(16, 23);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(59, 20);
+ this.label1.TabIndex = 0;
+ this.label1.Text = "Server:";
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(16, 63);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(42, 20);
+ this.label2.TabIndex = 1;
+ this.label2.Text = "Port:";
+ //
+ // label3
+ //
+ this.label3.AutoSize = true;
+ this.label3.Location = new System.Drawing.Point(16, 103);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(47, 20);
+ this.label3.TabIndex = 2;
+ this.label3.Text = "User:";
+ //
+ // label4
+ //
+ this.label4.AutoSize = true;
+ this.label4.Location = new System.Drawing.Point(16, 140);
+ this.label4.Name = "label4";
+ this.label4.Size = new System.Drawing.Size(82, 20);
+ this.label4.TabIndex = 3;
+ this.label4.Text = "Password:";
+ //
+ // passwordTextbox
+ //
+ this.passwordTextbox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.passwordTextbox.Location = new System.Drawing.Point(120, 135);
+ this.passwordTextbox.Name = "passwordTextbox";
+ this.passwordTextbox.PasswordChar = '*';
+ this.passwordTextbox.Size = new System.Drawing.Size(254, 26);
+ this.passwordTextbox.TabIndex = 4;
+ //
+ // userTextbox
+ //
+ this.userTextbox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.userTextbox.Location = new System.Drawing.Point(120, 98);
+ this.userTextbox.Name = "userTextbox";
+ this.userTextbox.Size = new System.Drawing.Size(254, 26);
+ this.userTextbox.TabIndex = 3;
+ //
+ // okButton
+ //
+ this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.okButton.Location = new System.Drawing.Point(21, 214);
+ this.okButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
+ this.okButton.Name = "okButton";
+ this.okButton.Size = new System.Drawing.Size(112, 35);
+ this.okButton.TabIndex = 6;
+ this.okButton.Text = "OK";
+ this.okButton.UseVisualStyleBackColor = true;
+ this.okButton.Click += new System.EventHandler(this.okButton_Click);
+ //
+ // testButton
+ //
+ this.testButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
+ this.testButton.Location = new System.Drawing.Point(142, 214);
+ this.testButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
+ this.testButton.Name = "testButton";
+ this.testButton.Size = new System.Drawing.Size(112, 35);
+ this.testButton.TabIndex = 7;
+ this.testButton.Text = "Test";
+ this.testButton.UseVisualStyleBackColor = true;
+ this.testButton.Click += new System.EventHandler(this.testButton_Click);
+ //
+ // cancelButton
+ //
+ this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.cancelButton.Location = new System.Drawing.Point(264, 214);
+ this.cancelButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
+ this.cancelButton.Name = "cancelButton";
+ this.cancelButton.Size = new System.Drawing.Size(112, 35);
+ this.cancelButton.TabIndex = 8;
+ this.cancelButton.Text = "Cancel";
+ this.cancelButton.UseVisualStyleBackColor = true;
+ this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
+ //
+ // serverSelector
+ //
+ this.serverSelector.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.serverSelector.FormattingEnabled = true;
+ this.serverSelector.Items.AddRange(new object[] {
+ "localhost",
+ "141.211.98.143"});
+ this.serverSelector.Location = new System.Drawing.Point(120, 18);
+ this.serverSelector.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
+ this.serverSelector.Name = "serverSelector";
+ this.serverSelector.Size = new System.Drawing.Size(254, 28);
+ this.serverSelector.TabIndex = 1;
+ //
+ // port
+ //
+ this.port.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.port.Location = new System.Drawing.Point(120, 60);
+ this.port.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
+ this.port.Maximum = new decimal(new int[] {
+ 65535,
+ 0,
+ 0,
+ 0});
+ this.port.Name = "port";
+ this.port.Size = new System.Drawing.Size(256, 26);
+ this.port.TabIndex = 2;
+ this.port.Value = new decimal(new int[] {
+ 3306,
+ 0,
+ 0,
+ 0});
+ //
+ // label5
+ //
+ this.label5.AutoSize = true;
+ this.label5.Location = new System.Drawing.Point(16, 178);
+ this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+ this.label5.Name = "label5";
+ this.label5.Size = new System.Drawing.Size(83, 20);
+ this.label5.TabIndex = 16;
+ this.label5.Text = "Database:";
+ //
+ // databaseTextbox
+ //
+ this.databaseTextbox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.databaseTextbox.Location = new System.Drawing.Point(120, 174);
+ this.databaseTextbox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
+ this.databaseTextbox.Name = "databaseTextbox";
+ this.databaseTextbox.Size = new System.Drawing.Size(254, 26);
+ this.databaseTextbox.TabIndex = 5;
+ //
+ // Settings
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(402, 265);
+ this.Controls.Add(this.databaseTextbox);
+ this.Controls.Add(this.label5);
+ this.Controls.Add(this.port);
+ this.Controls.Add(this.serverSelector);
+ this.Controls.Add(this.cancelButton);
+ this.Controls.Add(this.testButton);
+ this.Controls.Add(this.okButton);
+ this.Controls.Add(this.userTextbox);
+ this.Controls.Add(this.passwordTextbox);
+ this.Controls.Add(this.label4);
+ this.Controls.Add(this.label3);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.label1);
+ this.Name = "Settings";
+ this.Text = "Settings";
+ this.Load += new System.EventHandler(this.Settings_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.port)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.Label label2;
+ private System.Windows.Forms.Label label3;
+ private System.Windows.Forms.Label label4;
+ private System.Windows.Forms.TextBox passwordTextbox;
+ private System.Windows.Forms.TextBox userTextbox;
+ private System.Windows.Forms.Button okButton;
+ private System.Windows.Forms.Button testButton;
+ private System.Windows.Forms.Button cancelButton;
+ private System.Windows.Forms.ComboBox serverSelector;
+ private System.Windows.Forms.NumericUpDown port;
+ private System.Windows.Forms.Label label5;
+ private System.Windows.Forms.TextBox databaseTextbox;
+ }
+}
\ No newline at end of file
diff --git a/trayToDB/Settings.cs b/trayToDB/Settings.cs
new file mode 100644
index 0000000..8842eec
--- /dev/null
+++ b/trayToDB/Settings.cs
@@ -0,0 +1,117 @@
+using MySql.Data.MySqlClient;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace trayToDB
+{
+ public partial class Settings : Form
+ {
+ static readonly string PasswordHash = "P@SsW0Rd";
+ static readonly string SaltKey = "s!PmTe$teR";
+ static readonly string VIKey = "@1B2c3D4e5F6g7H8";
+
+ public Settings()
+ {
+ InitializeComponent();
+ }
+
+ public static string Decrypt(string encryptedText)
+ {
+ try
+ {
+ byte[] cipherTextBytes = Convert.FromBase64String(encryptedText);
+ byte[] keyBytes = new Rfc2898DeriveBytes(PasswordHash, Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256 / 8);
+ var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.None };
+
+ var decryptor = symmetricKey.CreateDecryptor(keyBytes, Encoding.ASCII.GetBytes(VIKey));
+ var memoryStream = new MemoryStream(cipherTextBytes);
+ var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read);
+ byte[] plainTextBytes = new byte[cipherTextBytes.Length];
+
+ int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
+ memoryStream.Close();
+ cryptoStream.Close();
+ return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount).TrimEnd("\0".ToCharArray());
+ }
+ catch (System.FormatException)
+ {
+ return null;
+ }
+ }
+
+ public static string Encrypt(string plainText)
+ {
+ byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
+
+ byte[] keyBytes = new Rfc2898DeriveBytes(PasswordHash, Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256 / 8);
+ var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.Zeros };
+ var encryptor = symmetricKey.CreateEncryptor(keyBytes, Encoding.ASCII.GetBytes(VIKey));
+
+ byte[] cipherTextBytes;
+
+ using (var memoryStream = new MemoryStream())
+ {
+ using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
+ {
+ cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
+ cryptoStream.FlushFinalBlock();
+ cipherTextBytes = memoryStream.ToArray();
+ cryptoStream.Close();
+ }
+ memoryStream.Close();
+ }
+ return Convert.ToBase64String(cipherTextBytes);
+ }
+
+ private void Settings_Load(object sender, EventArgs e)
+ {
+ serverSelector.Text = Properties.Settings.Default.server;
+ port.Value = Properties.Settings.Default.port;
+ userTextbox.Text = Properties.Settings.Default.user;
+ passwordTextbox.Text = Decrypt(Properties.Settings.Default.password);
+ databaseTextbox.Text = Properties.Settings.Default.database;
+ }
+
+ private void cancelButton_Click(object sender, EventArgs e)
+ {
+ this.Dispose();
+ }
+
+ private void okButton_Click(object sender, EventArgs e)
+ {
+ Properties.Settings.Default.server = serverSelector.Text;
+ Properties.Settings.Default.port = (int)port.Value;
+ Properties.Settings.Default.user = userTextbox.Text;
+ Properties.Settings.Default.password = Encrypt(passwordTextbox.Text);
+ Properties.Settings.Default.database = databaseTextbox.Text;
+ Properties.Settings.Default.Save();
+
+ this.Dispose();
+ }
+
+ private void testButton_Click(object sender, EventArgs e)
+ {
+ string connStr = "server=" + serverSelector.Text + "; user=" + userTextbox.Text + "; database=" + databaseTextbox.Text + "; port=" + (int)port.Value + "; password=" + passwordTextbox.Text;
+ MySqlConnection conn = new MySqlConnection(connStr);
+ try
+ {
+ conn.Open();
+ MessageBox.Show("Successfully connected to the database!");
+ conn.Close();
+ }
+ catch(MySqlException ex)
+ {
+ MessageBox.Show(ex.Message);
+ }
+ }
+ }
+}
diff --git a/trayToDB/Settings.resx b/trayToDB/Settings.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/trayToDB/Settings.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/trayToDB/trayToDB.csproj b/trayToDB/trayToDB.csproj
index c6492c8..f63311f 100644
--- a/trayToDB/trayToDB.csproj
+++ b/trayToDB/trayToDB.csproj
@@ -8,9 +8,10 @@
WinExe
trayToDB
trayToDB
- v4.5
+ v4.5.2
512
true
+
AnyCPU
@@ -32,7 +33,12 @@
4
+
+ False
+ ..\..\..\..\..\..\Program Files (x86)\MySQL\MySQL Connector Net 8.0.15\Assemblies\v4.5.2\MySql.Data.dll
+
+
@@ -45,14 +51,24 @@
-
+
Form
-
- Form1.cs
+
+ MainWindow.cs
+
+
+ Form
+
+
+ Settings.cs
+
+
+ MainWindow.cs
+
ResXFileCodeGenerator
Resources.Designer.cs
@@ -61,7 +77,11 @@
True
Resources.resx
+ True
+
+ Settings.cs
+
SettingsSingleFileGenerator
Settings.Designer.cs
@@ -75,5 +95,34 @@
+
+
+ {2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}
+ 2
+ 8
+ 0
+ primary
+ False
+ True
+
+
+ {00020813-0000-0000-C000-000000000046}
+ 1
+ 9
+ 0
+ primary
+ False
+ True
+
+
+ {0002E157-0000-0000-C000-000000000046}
+ 5
+ 3
+ 0
+ primary
+ False
+ True
+
+
\ No newline at end of file