From 4556c7fa803750bd2c4eeb2ecc6a5da746516978 Mon Sep 17 00:00:00 2001 From: Bas Visscher Date: Sat, 7 Nov 2020 15:39:50 +0100 Subject: [PATCH] Fixed import and export --- .../StuffDatabase/CTRL_Component.Designer.cs | 52 ++----- StuffDatabase/StuffDatabase/CTRL_Component.cs | 144 +++++++++++++++++- .../StuffDatabase/Components/BaseComponent.cs | 3 - StuffDatabase/StuffDatabase/Form1.Designer.cs | 83 +++++++++- StuffDatabase/StuffDatabase/Form1.cs | 85 +++++++++++ StuffDatabase/StuffDatabase/Form1.resx | 3 + .../StuffDatabase/Frm_Import.Designer.cs | 103 +++++++++++++ StuffDatabase/StuffDatabase/Frm_Import.cs | 54 +++++++ StuffDatabase/StuffDatabase/Frm_Import.resx | 120 +++++++++++++++ .../StuffDatabase/StuffDatabase.csproj | 12 ++ 10 files changed, 605 insertions(+), 54 deletions(-) create mode 100644 StuffDatabase/StuffDatabase/Frm_Import.Designer.cs create mode 100644 StuffDatabase/StuffDatabase/Frm_Import.cs create mode 100644 StuffDatabase/StuffDatabase/Frm_Import.resx diff --git a/StuffDatabase/StuffDatabase/CTRL_Component.Designer.cs b/StuffDatabase/StuffDatabase/CTRL_Component.Designer.cs index aafc4eb..7a91351 100644 --- a/StuffDatabase/StuffDatabase/CTRL_Component.Designer.cs +++ b/StuffDatabase/StuffDatabase/CTRL_Component.Designer.cs @@ -34,16 +34,14 @@ private void InitializeComponent() this.btn_New = new System.Windows.Forms.Button(); this.treeView1 = new System.Windows.Forms.TreeView(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.btn_Import = new System.Windows.Forms.Button(); this.btn_Edit = new System.Windows.Forms.Button(); this.btn_Print = new System.Windows.Forms.Button(); this.btn_Delete = new System.Windows.Forms.Button(); this.btn_Cancel = new System.Windows.Forms.Button(); this.btn_Save = new System.Windows.Forms.Button(); this.splitContainer2 = new System.Windows.Forms.SplitContainer(); - this.btn_Import = new System.Windows.Forms.Button(); this.propertyGrid1 = new System.Windows.Forms.PropertyGrid(); - this.textBox1 = new System.Windows.Forms.TextBox(); - this.label1 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); @@ -106,9 +104,9 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.treeView1.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.treeView1.Location = new System.Drawing.Point(3, 29); + this.treeView1.Location = new System.Drawing.Point(3, 0); this.treeView1.Name = "treeView1"; - this.treeView1.Size = new System.Drawing.Size(359, 476); + this.treeView1.Size = new System.Drawing.Size(359, 505); this.treeView1.TabIndex = 15; this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect); // @@ -122,8 +120,6 @@ private void InitializeComponent() // // splitContainer1.Panel1 // - this.splitContainer1.Panel1.Controls.Add(this.label1); - this.splitContainer1.Panel1.Controls.Add(this.textBox1); this.splitContainer1.Panel1.Controls.Add(this.btn_Import); this.splitContainer1.Panel1.Controls.Add(this.btn_Edit); this.splitContainer1.Panel1.Controls.Add(this.btn_New); @@ -140,6 +136,16 @@ private void InitializeComponent() this.splitContainer1.SplitterDistance = 365; this.splitContainer1.TabIndex = 16; // + // btn_Import + // + this.btn_Import.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btn_Import.Location = new System.Drawing.Point(295, 511); + this.btn_Import.Name = "btn_Import"; + this.btn_Import.Size = new System.Drawing.Size(67, 34); + this.btn_Import.TabIndex = 17; + this.btn_Import.Text = "Fetch\r\nTOR\r\n"; + this.btn_Import.UseVisualStyleBackColor = true; + // // btn_Edit // this.btn_Edit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); @@ -217,16 +223,6 @@ private void InitializeComponent() this.splitContainer2.SplitterDistance = 317; this.splitContainer2.TabIndex = 14; // - // btn_Import - // - this.btn_Import.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.btn_Import.Location = new System.Drawing.Point(295, 511); - this.btn_Import.Name = "btn_Import"; - this.btn_Import.Size = new System.Drawing.Size(67, 34); - this.btn_Import.TabIndex = 17; - this.btn_Import.Text = "Fetch\r\nTOR\r\n"; - this.btn_Import.UseVisualStyleBackColor = true; - // // propertyGrid1 // this.propertyGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -237,25 +233,6 @@ private void InitializeComponent() this.propertyGrid1.Size = new System.Drawing.Size(327, 314); this.propertyGrid1.TabIndex = 13; // - // textBox1 - // - this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.textBox1.Location = new System.Drawing.Point(262, 3); - this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(100, 20); - this.textBox1.TabIndex = 18; - this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); - // - // label1 - // - this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(215, 6); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(41, 13); - this.label1.TabIndex = 19; - this.label1.Text = "Search"; - // // CTRL_Component // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -266,7 +243,6 @@ private void InitializeComponent() this.Load += new System.EventHandler(this.CTRL_Components_Load); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.splitContainer1.Panel1.ResumeLayout(false); - this.splitContainer1.Panel1.PerformLayout(); this.splitContainer1.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); @@ -293,7 +269,5 @@ private void InitializeComponent() private System.Windows.Forms.Button btn_Delete; private System.Windows.Forms.Button btn_Cancel; private System.Windows.Forms.Button btn_Save; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.TextBox textBox1; } } diff --git a/StuffDatabase/StuffDatabase/CTRL_Component.cs b/StuffDatabase/StuffDatabase/CTRL_Component.cs index 34775bc..37611f0 100644 --- a/StuffDatabase/StuffDatabase/CTRL_Component.cs +++ b/StuffDatabase/StuffDatabase/CTRL_Component.cs @@ -11,6 +11,7 @@ using System.IO; using System.Collections.ObjectModel; using StuffDatabase.Components; +using System.Reflection; namespace StuffDatabase { @@ -23,6 +24,7 @@ public partial class CTRL_Component : UserControl string TemplateFolder { get { return CreatePathIfNotExist(Path.Combine(Settings.ComponentData, ComponentType.Name, "Templates")); } } string DatasheetFolder { get { return CreatePathIfNotExist(Path.Combine(Settings.ComponentData, ComponentType.Name, "Datasheets")); } } + public bool ChangePending { get; set; } = false; string CreatePathIfNotExist(string path) { @@ -52,6 +54,7 @@ private void CTRL_Components_Load(object sender, EventArgs e) private void Components_ListChanged(object sender, ListChangedEventArgs e) { + ChangePending = true; switch (e.ListChangedType) { case ListChangedType.ItemAdded: @@ -117,7 +120,6 @@ void StopEditComponent(bool saveChanges) EditCompOrigional.Populate(EditCompNew); if(!Components.Contains(EditCompOrigional)) Components.Add(EditCompOrigional); - Components.Save(); } SetUIEditMode(false); Render(EditCompOrigional); @@ -205,7 +207,6 @@ private void btn_Delete_Click(object sender, EventArgs e) if (selectedComponent != null) { Components.Remove(selectedComponent); - Components.Save(); } } @@ -219,17 +220,148 @@ private void btn_Print_Click(object sender, EventArgs e) } } - private void textBox1_TextChanged(object sender, EventArgs e) + + public void Search(string searchString) { - if(textBox1.Text == "") + if (searchString == "") Filter = (a) => a.GetType() == ComponentType; else - Filter = (a) => a.GetType() == ComponentType && a.Name.ToLower().Contains(textBox1.Text.ToLower()); + Filter = (a) => a.GetType() == ComponentType && a.Name.ToLower().Contains(searchString.ToLower()); RePopulateList(true); } - } + public void Export(string file) + { + + using (StreamWriter writer = new StreamWriter(file)) + { + PropertyInfo[] pis = ComponentType.GetProperties(); + foreach (PropertyInfo pi in pis) + { + writer.Write($"\"{pi.Name}\"" + ((pi == pis.Last())?"\r\n":",")); + } + + foreach (BaseComponent component in Components) + { + if (Filter(component)) + { + foreach (PropertyInfo pi in pis) + { + object val = pi.GetValue(component); + switch (val) + { + case double v: + writer.Write($"\"{v.ToString("E")}\"" + ((pi == pis.Last()) ? "\r\n" : ",")); + break; + + default: + writer.Write($"\"{val}\"" + ((pi == pis.Last()) ? "\r\n" : ",")); + break; + } + } + } + } + } + } + + public void Import(string file) + { + List props = new List(); + SaveableBindingList comps = new SaveableBindingList(); + + using (StreamReader reader = new StreamReader(file)) + { + //Read header + string header = reader.ReadLine(); + foreach(string propName in header.Split(',')) + { + PropertyInfo pi = ComponentType.GetProperty(propName.Trim('"')); + if (pi == null) + throw new Exception("Property not found."); + props.Add(pi); + } + + while(!reader.EndOfStream) + { + List values = new List(); + string line = reader.ReadLine(); + + string val = ""; + bool b = false; + foreach(char c in line) + { + if (c == '"') + b = !b; + else + { + if (b) + val += c; + else + { + if (c == ',') + { + values.Add(val); + val = ""; + } + + else + val += c; + } + } + + } + + + + BaseComponent comp = (BaseComponent)Activator.CreateInstance(ComponentType); + + for (int i = 0; i < values.Count; i++) + { + if(props[i].PropertyType == typeof(double)) + { + props[i].SetValue(comp, double.Parse(values[i])); + } + else + { + props[i].SetValue(comp, values[i]); + } + + + } + comps.Add(comp); + } + + } + + Frm_Import frm = new Frm_Import(comps, ComponentType); + + if (frm.ShowDialog() == DialogResult.OK) + { + bool overrideExisting = frm.OverrideExisting; + foreach(BaseComponent comp in comps) + { + int ind = Components.IndexOf(Components.FirstOrDefault(c => c.Name == comp.Name && c.Function == comp.Function)); + if(ind == -1) + { + Components.Add(comp); //Add new component + } + else + { + if(overrideExisting) + { + Components.RemoveAt(ind); //Override existing + Components.Add(comp); + } + else + { + //TODO ask??? + } + } + } + } + } + } } diff --git a/StuffDatabase/StuffDatabase/Components/BaseComponent.cs b/StuffDatabase/StuffDatabase/Components/BaseComponent.cs index 077051e..160a613 100644 --- a/StuffDatabase/StuffDatabase/Components/BaseComponent.cs +++ b/StuffDatabase/StuffDatabase/Components/BaseComponent.cs @@ -20,8 +20,6 @@ public abstract class BaseComponent : PropertySensitive [Browsable(false)] public string Datasheet { get { return GetPar(""); } set { SetPar(value); } } - - private static int MaxNameLength { get; set; } public override string ToString() { @@ -56,5 +54,4 @@ public void Populate(BaseComponent comp) pi.SetValue(this, pi.GetValue(comp)); } } - } diff --git a/StuffDatabase/StuffDatabase/Form1.Designer.cs b/StuffDatabase/StuffDatabase/Form1.Designer.cs index cfc8a22..51226bd 100644 --- a/StuffDatabase/StuffDatabase/Form1.Designer.cs +++ b/StuffDatabase/StuffDatabase/Form1.Designer.cs @@ -32,10 +32,17 @@ private void InitializeComponent() this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.tabControl2 = new System.Windows.Forms.TabControl(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.importToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.exportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripTextBox1 = new System.Windows.Forms.ToolStripTextBox(); this.ctrL_Chemical1 = new StuffDatabase.CTRL_Chemical(); + this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.tabPage2.SuspendLayout(); this.tabControl1.SuspendLayout(); this.tabPage1.SuspendLayout(); + this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // // tabPage2 @@ -45,7 +52,7 @@ private void InitializeComponent() this.tabPage2.Location = new System.Drawing.Point(4, 22); this.tabPage2.Name = "tabPage2"; this.tabPage2.Padding = new System.Windows.Forms.Padding(3); - this.tabPage2.Size = new System.Drawing.Size(719, 486); + this.tabPage2.Size = new System.Drawing.Size(719, 562); this.tabPage2.TabIndex = 1; this.tabPage2.Text = "Chemicals"; // @@ -54,10 +61,10 @@ private void InitializeComponent() this.tabControl1.Controls.Add(this.tabPage1); this.tabControl1.Controls.Add(this.tabPage2); this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill; - this.tabControl1.Location = new System.Drawing.Point(0, 0); + this.tabControl1.Location = new System.Drawing.Point(0, 27); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; - this.tabControl1.Size = new System.Drawing.Size(727, 618); + this.tabControl1.Size = new System.Drawing.Size(727, 591); this.tabControl1.TabIndex = 0; // // tabPage1 @@ -67,7 +74,7 @@ private void InitializeComponent() this.tabPage1.Location = new System.Drawing.Point(4, 22); this.tabPage1.Name = "tabPage1"; this.tabPage1.Padding = new System.Windows.Forms.Padding(3); - this.tabPage1.Size = new System.Drawing.Size(719, 592); + this.tabPage1.Size = new System.Drawing.Size(719, 565); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "Components"; // @@ -77,17 +84,70 @@ private void InitializeComponent() this.tabControl2.Location = new System.Drawing.Point(3, 3); this.tabControl2.Name = "tabControl2"; this.tabControl2.SelectedIndex = 0; - this.tabControl2.Size = new System.Drawing.Size(713, 586); + this.tabControl2.Size = new System.Drawing.Size(713, 559); this.tabControl2.TabIndex = 0; // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.fileToolStripMenuItem, + this.toolStripTextBox1}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(727, 27); + this.menuStrip1.TabIndex = 1; + this.menuStrip1.Text = "menuStrip1"; + // + // fileToolStripMenuItem + // + this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.saveToolStripMenuItem, + this.importToolStripMenuItem, + this.exportToolStripMenuItem}); + this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; + this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 23); + this.fileToolStripMenuItem.Text = "&File"; + // + // importToolStripMenuItem + // + this.importToolStripMenuItem.Name = "importToolStripMenuItem"; + this.importToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.importToolStripMenuItem.Text = "Import"; + this.importToolStripMenuItem.Click += new System.EventHandler(this.importToolStripMenuItem_Click); + // + // exportToolStripMenuItem + // + this.exportToolStripMenuItem.Name = "exportToolStripMenuItem"; + this.exportToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.exportToolStripMenuItem.Text = "Export"; + this.exportToolStripMenuItem.Click += new System.EventHandler(this.exportToolStripMenuItem_Click); + // + // toolStripTextBox1 + // + this.toolStripTextBox1.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right; + this.toolStripTextBox1.Font = new System.Drawing.Font("Segoe UI", 9F); + this.toolStripTextBox1.ForeColor = System.Drawing.SystemColors.ControlDarkDark; + this.toolStripTextBox1.Name = "toolStripTextBox1"; + this.toolStripTextBox1.Size = new System.Drawing.Size(100, 23); + this.toolStripTextBox1.Text = "Search"; + this.toolStripTextBox1.Enter += new System.EventHandler(this.toolStripTextBox1_Enter); + this.toolStripTextBox1.TextChanged += new System.EventHandler(this.toolStripTextBox1_TextChanged); + // // ctrL_Chemical1 // this.ctrL_Chemical1.Dock = System.Windows.Forms.DockStyle.Fill; this.ctrL_Chemical1.Location = new System.Drawing.Point(3, 3); this.ctrL_Chemical1.Name = "ctrL_Chemical1"; - this.ctrL_Chemical1.Size = new System.Drawing.Size(713, 480); + this.ctrL_Chemical1.Size = new System.Drawing.Size(713, 556); this.ctrL_Chemical1.TabIndex = 0; // + // saveToolStripMenuItem + // + this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; + this.saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.saveToolStripMenuItem.Text = "Save"; + this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click); + // // Form1 // this.AllowDrop = true; @@ -95,6 +155,8 @@ private void InitializeComponent() this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(727, 618); this.Controls.Add(this.tabControl1); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; this.Name = "Form1"; this.Text = "Form1"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); @@ -102,7 +164,10 @@ private void InitializeComponent() this.tabPage2.ResumeLayout(false); this.tabControl1.ResumeLayout(false); this.tabPage1.ResumeLayout(false); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); this.ResumeLayout(false); + this.PerformLayout(); } @@ -113,6 +178,12 @@ private void InitializeComponent() private System.Windows.Forms.TabPage tabPage1; private CTRL_Chemical ctrL_Chemical1; private System.Windows.Forms.TabControl tabControl2; + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; + private System.Windows.Forms.ToolStripTextBox toolStripTextBox1; + private System.Windows.Forms.ToolStripMenuItem importToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem exportToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem; } } diff --git a/StuffDatabase/StuffDatabase/Form1.cs b/StuffDatabase/StuffDatabase/Form1.cs index cd7bf1f..cbb5c9d 100644 --- a/StuffDatabase/StuffDatabase/Form1.cs +++ b/StuffDatabase/StuffDatabase/Form1.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using DYMO.Label.Framework; using STDLib.Saveable; using StuffDatabase.Components; @@ -38,12 +39,35 @@ private void Form1_Load(object sender, EventArgs e) ctrl.Components = componentDB; ctrl.Dock = DockStyle.Fill; tabPage.Controls.Add(ctrl); + tabPage.Tag = ctrl; } } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { + + + bool save = false; + foreach (TabPage tp in tabControl2.TabPages) + { + CTRL_Component ctrl = tp.Tag as CTRL_Component; + if (ctrl.ChangePending) + { + if (MessageBox.Show("Do you want to save changes to your text?", "My Application", MessageBoxButtons.YesNo) == DialogResult.Yes) + { + e.Cancel = true; + save = true; + } + break; + } + } + + if (save) + componentDB.Save(); + + Settings.Save("Settings.json"); + e.Cancel = false; } public IEnumerable FindSubClassesOf() @@ -53,6 +77,67 @@ public IEnumerable FindSubClassesOf() return assembly.GetTypes().Where(t => t.IsSubclassOf(baseType)); } + + private void toolStripTextBox1_Enter(object sender, EventArgs e) + { + ToolStripTextBox tb = sender as ToolStripTextBox; + + if (tb.Text == "Search") + { + tb.Text = ""; + tb.ForeColor = System.Drawing.Color.Black; + } + } + + private void toolStripTextBox1_TextChanged(object sender, EventArgs e) + { + ToolStripTextBox tb = sender as ToolStripTextBox; + if (GetSelectedControl() is CTRL_Component ctrl) + ctrl.Search(tb.Text); + } + + + + object GetSelectedControl() + { + if (tabControl1.SelectedIndex == 0) + { + if (tabControl2.SelectedTab?.Tag is CTRL_Component comp) + return comp; + } + return null; + } + + private void importToolStripMenuItem_Click(object sender, EventArgs e) + { + + OpenFileDialog diag = new OpenFileDialog(); + diag.Filter = "CSV file (*.csv)|*.csv"; + if (diag.ShowDialog() == DialogResult.OK) + { + ToolStripTextBox tb = sender as ToolStripTextBox; + if (GetSelectedControl() is CTRL_Component ctrl) + ctrl.Import(diag.FileName); + } + } + + private void exportToolStripMenuItem_Click(object sender, EventArgs e) + { + SaveFileDialog diag = new SaveFileDialog(); + diag.Filter = "CSV file (*.csv)|*.csv"; + if (diag.ShowDialog() == DialogResult.OK) + { + ToolStripTextBox tb = sender as ToolStripTextBox; + if (GetSelectedControl() is CTRL_Component ctrl) + ctrl.Export(diag.FileName); + } + } + + private void saveToolStripMenuItem_Click(object sender, EventArgs e) + { + componentDB.Save(); + + } } } diff --git a/StuffDatabase/StuffDatabase/Form1.resx b/StuffDatabase/StuffDatabase/Form1.resx index 1af7de1..d5494e3 100644 --- a/StuffDatabase/StuffDatabase/Form1.resx +++ b/StuffDatabase/StuffDatabase/Form1.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/StuffDatabase/StuffDatabase/Frm_Import.Designer.cs b/StuffDatabase/StuffDatabase/Frm_Import.Designer.cs new file mode 100644 index 0000000..99d0932 --- /dev/null +++ b/StuffDatabase/StuffDatabase/Frm_Import.Designer.cs @@ -0,0 +1,103 @@ +namespace StuffDatabase +{ + partial class Frm_Import + { + /// + /// 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.panel1 = new System.Windows.Forms.Panel(); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.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.panel1.Location = new System.Drawing.Point(12, 12); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(842, 570); + this.panel1.TabIndex = 0; + // + // button1 + // + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.button1.Location = new System.Drawing.Point(12, 588); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(188, 23); + this.button1.TabIndex = 1; + this.button1.Text = "Save and override existing"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // button2 + // + this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.button2.Location = new System.Drawing.Point(206, 588); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(188, 23); + this.button2.TabIndex = 2; + this.button2.Text = "Save and ignore existing"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // button3 + // + this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.button3.Location = new System.Drawing.Point(400, 588); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(188, 23); + this.button3.TabIndex = 3; + this.button3.Text = "Cancel"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // Frm_Import + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(866, 623); + this.Controls.Add(this.button3); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Controls.Add(this.panel1); + this.Name = "Frm_Import"; + this.Text = "Frm_Import"; + this.Load += new System.EventHandler(this.Frm_Import_Load); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button3; + } +} \ No newline at end of file diff --git a/StuffDatabase/StuffDatabase/Frm_Import.cs b/StuffDatabase/StuffDatabase/Frm_Import.cs new file mode 100644 index 0000000..cf9c1a4 --- /dev/null +++ b/StuffDatabase/StuffDatabase/Frm_Import.cs @@ -0,0 +1,54 @@ +using STDLib.Saveable; +using StuffDatabase.Components; +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 StuffDatabase +{ + public partial class Frm_Import : Form + { + SaveableBindingList Components { get; set; } + Type CompType { get; set; } + public bool OverrideExisting = false; + + public Frm_Import(SaveableBindingList components, Type compType) + { + InitializeComponent(); + Components = components; + CompType = compType; + } + + private void Frm_Import_Load(object sender, EventArgs e) + { + CTRL_Component comp = new CTRL_Component(CompType); + panel1.Controls.Add(comp); + comp.Dock = DockStyle.Fill; + comp.Components = Components; + + } + + private void button3_Click(object sender, EventArgs e) + { + this.DialogResult = DialogResult.Cancel; + } + + private void button1_Click(object sender, EventArgs e) + { + OverrideExisting = true; + this.DialogResult = DialogResult.OK; + } + + private void button2_Click(object sender, EventArgs e) + { + OverrideExisting = false; + this.DialogResult = DialogResult.OK; + } + } +} diff --git a/StuffDatabase/StuffDatabase/Frm_Import.resx b/StuffDatabase/StuffDatabase/Frm_Import.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/StuffDatabase/StuffDatabase/Frm_Import.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/StuffDatabase/StuffDatabase/StuffDatabase.csproj b/StuffDatabase/StuffDatabase/StuffDatabase.csproj index a1bdb56..f9058af 100644 --- a/StuffDatabase/StuffDatabase/StuffDatabase.csproj +++ b/StuffDatabase/StuffDatabase/StuffDatabase.csproj @@ -75,6 +75,12 @@ Form1.cs + + Form + + + Frm_Import.cs + Form @@ -95,6 +101,9 @@ Form1.cs + + Frm_Import.cs + Frm_ImportAllTransistors.cs @@ -130,5 +139,8 @@ + + + \ No newline at end of file