Initial working version

This commit is contained in:
David Baranyai 2019-03-16 19:08:55 -04:00
parent 6c90254581
commit e39160b2fa
16 changed files with 1504 additions and 118 deletions

View File

@ -1,6 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="trayToDB.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
</configuration>
<userSettings>
<trayToDB.Properties.Settings>
<setting name="server" serializeAs="String">
<value>localhost</value>
</setting>
<setting name="port" serializeAs="String">
<value>3306</value>
</setting>
<setting name="database" serializeAs="String">
<value>sipmtest</value>
</setting>
<setting name="user" serializeAs="String">
<value>sipm</value>
</setting>
<setting name="password" serializeAs="String">
<value />
</setting>
</trayToDB.Properties.Settings>
</userSettings>
</configuration>

View File

@ -1,40 +0,0 @@
namespace trayToDB
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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
}
}

View File

@ -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();
}
}
}

213
trayToDB/MainWindow.Designer.cs generated Normal file
View File

@ -0,0 +1,213 @@
namespace trayToDB
{
partial class MainWindow
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

277
trayToDB/MainWindow.cs Normal file
View File

@ -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<SiPMData> 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<SiPMData>(); //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();
}
}
}

126
trayToDB/MainWindow.resx Normal file
View File

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>211, 17</value>
</metadata>
</root>

View File

@ -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)
{
}
}
}

View File

@ -16,7 +16,7 @@ namespace trayToDB
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new MainWindow());
}
}
}

View File

@ -8,10 +8,10 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace trayToDB.Properties
{
namespace trayToDB.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
@ -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() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[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;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[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;
}
}

View File

@ -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.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
@ -68,9 +69,10 @@
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
@ -85,9 +87,10 @@
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
@ -109,9 +112,9 @@
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -8,23 +8,109 @@
// </auto-generated>
//------------------------------------------------------------------------------
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;
}
}
/// <summary>
/// MySQL server IP address
/// </summary>
[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;
}
}
/// <summary>
/// MySQL server port
/// </summary>
[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;
}
}
/// <summary>
/// Database name
/// </summary>
[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;
}
}
/// <summary>
/// Username for MySQL
/// </summary>
[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;
}
}
/// <summary>
/// Password, do not edit with text editor!
/// </summary>
[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;
}
}
}
}

View File

@ -1,7 +1,21 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="trayToDB.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="server" Description="MySQL server IP address" Provider="crdx.Settings.PortableSettingsProvider" Roaming="true" Type="System.String" Scope="User">
<Value Profile="(Default)">localhost</Value>
</Setting>
<Setting Name="port" Description="MySQL server port" Provider="crdx.Settings.PortableSettingsProvider" Roaming="true" Type="System.Int32" Scope="User">
<Value Profile="(Default)">3306</Value>
</Setting>
<Setting Name="database" Description="Database name" Provider="crdx.Settings.PortableSettingsProvider" Roaming="true" Type="System.String" Scope="User">
<Value Profile="(Default)">sipmtest</Value>
</Setting>
<Setting Name="user" Description="Username for MySQL" Provider="crdx.Settings.PortableSettingsProvider" Roaming="true" Type="System.String" Scope="User">
<Value Profile="(Default)">sipm</Value>
</Setting>
<Setting Name="password" Description="Password, do not edit with text editor!" Provider="crdx.Settings.PortableSettingsProvider" Roaming="true" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>

235
trayToDB/Settings.Designer.cs generated Normal file
View File

@ -0,0 +1,235 @@
namespace trayToDB
{
partial class Settings
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

117
trayToDB/Settings.cs Normal file
View File

@ -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);
}
}
}
}

120
trayToDB/Settings.resx Normal file
View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -8,9 +8,10 @@
<OutputType>WinExe</OutputType>
<RootNamespace>trayToDB</RootNamespace>
<AssemblyName>trayToDB</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -32,7 +33,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="MySql.Data, Version=8.0.15.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\Program Files (x86)\MySQL\MySQL Connector Net 8.0.15\Assemblies\v4.5.2\MySql.Data.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
@ -45,14 +51,24 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<Compile Include="MainWindow.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
<Compile Include="MainWindow.Designer.cs">
<DependentUpon>MainWindow.cs</DependentUpon>
</Compile>
<Compile Include="PortableSettingsProvider.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Settings.Designer.cs">
<DependentUpon>Settings.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="MainWindow.resx">
<DependentUpon>MainWindow.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
@ -61,7 +77,11 @@
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="Settings.resx">
<DependentUpon>Settings.cs</DependentUpon>
</EmbeddedResource>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@ -75,5 +95,34 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<COMReference Include="Microsoft.Office.Core">
<Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid>
<VersionMajor>2</VersionMajor>
<VersionMinor>8</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>primary</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
<COMReference Include="Microsoft.Office.Interop.Excel">
<Guid>{00020813-0000-0000-C000-000000000046}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>9</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>primary</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
<COMReference Include="VBIDE">
<Guid>{0002E157-0000-0000-C000-000000000046}</Guid>
<VersionMajor>5</VersionMajor>
<VersionMinor>3</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>primary</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>