diff --git a/MySQLBookAppCRUD/MySQLBookAppCRUD.sln b/MySQLBookAppCRUD/MySQLBookAppCRUD.sln new file mode 100644 index 0000000..7bc6f13 --- /dev/null +++ b/MySQLBookAppCRUD/MySQLBookAppCRUD.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.271 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MySQLBookAppCRUD", "MySQLBookAppCRUD\MySQLBookAppCRUD.csproj", "{FBB677BF-2293-47A3-97B8-A6F0F7D1D06F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FBB677BF-2293-47A3-97B8-A6F0F7D1D06F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FBB677BF-2293-47A3-97B8-A6F0F7D1D06F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FBB677BF-2293-47A3-97B8-A6F0F7D1D06F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FBB677BF-2293-47A3-97B8-A6F0F7D1D06F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EA9F5849-91FA-4AAB-AA30-1C009C371BD9} + EndGlobalSection +EndGlobal diff --git a/MySQLBookAppCRUD/MySQLBookAppCRUD/App.config b/MySQLBookAppCRUD/MySQLBookAppCRUD/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/MySQLBookAppCRUD/MySQLBookAppCRUD/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MySQLBookAppCRUD/MySQLBookAppCRUD/Form1.Designer.cs b/MySQLBookAppCRUD/MySQLBookAppCRUD/Form1.Designer.cs new file mode 100644 index 0000000..02863f7 --- /dev/null +++ b/MySQLBookAppCRUD/MySQLBookAppCRUD/Form1.Designer.cs @@ -0,0 +1,195 @@ +namespace MySQLBookAppCRUD +{ + partial class BookSearchApp + { + /// + /// 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.lblBookName = new System.Windows.Forms.Label(); + this.txtBookName = new System.Windows.Forms.TextBox(); + this.lblBookAuthor = new System.Windows.Forms.Label(); + this.txtBookAuthor = new System.Windows.Forms.TextBox(); + this.lblBookDescription = new System.Windows.Forms.Label(); + this.txtBookDescription = new System.Windows.Forms.TextBox(); + this.txtSearchText = new System.Windows.Forms.TextBox(); + this.btnSave = new System.Windows.Forms.Button(); + this.btnDelete = new System.Windows.Forms.Button(); + this.btnCancel = new System.Windows.Forms.Button(); + this.btnSearch = new System.Windows.Forms.Button(); + this.gridTableData = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.gridTableData)).BeginInit(); + this.SuspendLayout(); + // + // lblBookName + // + this.lblBookName.AutoSize = true; + this.lblBookName.Location = new System.Drawing.Point(13, 52); + this.lblBookName.Name = "lblBookName"; + this.lblBookName.Size = new System.Drawing.Size(64, 13); + this.lblBookName.TabIndex = 0; + this.lblBookName.Text = "Book name:"; + // + // txtBookName + // + this.txtBookName.Location = new System.Drawing.Point(87, 52); + this.txtBookName.Name = "txtBookName"; + this.txtBookName.Size = new System.Drawing.Size(315, 20); + this.txtBookName.TabIndex = 1; + // + // lblBookAuthor + // + this.lblBookAuthor.AutoSize = true; + this.lblBookAuthor.Location = new System.Drawing.Point(13, 78); + this.lblBookAuthor.Name = "lblBookAuthor"; + this.lblBookAuthor.Size = new System.Drawing.Size(68, 13); + this.lblBookAuthor.TabIndex = 0; + this.lblBookAuthor.Text = "Book author:"; + // + // txtBookAuthor + // + this.txtBookAuthor.Location = new System.Drawing.Point(87, 78); + this.txtBookAuthor.Name = "txtBookAuthor"; + this.txtBookAuthor.Size = new System.Drawing.Size(315, 20); + this.txtBookAuthor.TabIndex = 2; + // + // lblBookDescription + // + this.lblBookDescription.AutoSize = true; + this.lblBookDescription.Location = new System.Drawing.Point(13, 104); + this.lblBookDescription.Name = "lblBookDescription"; + this.lblBookDescription.Size = new System.Drawing.Size(89, 13); + this.lblBookDescription.TabIndex = 0; + this.lblBookDescription.Text = "Book description:"; + // + // txtBookDescription + // + this.txtBookDescription.Location = new System.Drawing.Point(108, 104); + this.txtBookDescription.Multiline = true; + this.txtBookDescription.Name = "txtBookDescription"; + this.txtBookDescription.Size = new System.Drawing.Size(294, 70); + this.txtBookDescription.TabIndex = 3; + // + // txtSearchText + // + this.txtSearchText.Location = new System.Drawing.Point(408, 12); + this.txtSearchText.Name = "txtSearchText"; + this.txtSearchText.Size = new System.Drawing.Size(525, 20); + this.txtSearchText.TabIndex = 7; + // + // btnSave + // + this.btnSave.ForeColor = System.Drawing.SystemColors.ActiveCaptionText; + this.btnSave.Location = new System.Drawing.Point(16, 199); + this.btnSave.Name = "btnSave"; + this.btnSave.Size = new System.Drawing.Size(142, 23); + this.btnSave.TabIndex = 4; + this.btnSave.Text = "Save"; + this.btnSave.UseVisualStyleBackColor = true; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); + // + // btnDelete + // + this.btnDelete.Location = new System.Drawing.Point(164, 199); + this.btnDelete.Name = "btnDelete"; + this.btnDelete.Size = new System.Drawing.Size(85, 23); + this.btnDelete.TabIndex = 5; + this.btnDelete.Text = "Delete"; + this.btnDelete.UseVisualStyleBackColor = true; + this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click); + // + // btnCancel + // + this.btnCancel.Location = new System.Drawing.Point(255, 199); + this.btnCancel.Name = "btnCancel"; + this.btnCancel.Size = new System.Drawing.Size(147, 23); + this.btnCancel.TabIndex = 6; + this.btnCancel.Text = "Cancel"; + this.btnCancel.UseVisualStyleBackColor = true; + this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); + // + // btnSearch + // + this.btnSearch.Location = new System.Drawing.Point(939, 12); + this.btnSearch.Name = "btnSearch"; + this.btnSearch.Size = new System.Drawing.Size(75, 23); + this.btnSearch.TabIndex = 8; + this.btnSearch.Text = "Search"; + this.btnSearch.UseVisualStyleBackColor = true; + this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click); + // + // gridTableData + // + this.gridTableData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.gridTableData.Location = new System.Drawing.Point(408, 52); + this.gridTableData.Name = "gridTableData"; + this.gridTableData.Size = new System.Drawing.Size(606, 386); + this.gridTableData.TabIndex = 7; + this.gridTableData.DoubleClick += new System.EventHandler(this.gridTableData_DoubleClick); + // + // BookSearchApp + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1026, 450); + this.Controls.Add(this.gridTableData); + this.Controls.Add(this.btnSearch); + this.Controls.Add(this.btnCancel); + this.Controls.Add(this.btnDelete); + this.Controls.Add(this.btnSave); + this.Controls.Add(this.txtSearchText); + this.Controls.Add(this.txtBookDescription); + this.Controls.Add(this.lblBookDescription); + this.Controls.Add(this.txtBookAuthor); + this.Controls.Add(this.lblBookAuthor); + this.Controls.Add(this.txtBookName); + this.Controls.Add(this.lblBookName); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.Name = "BookSearchApp"; + this.Text = "Book Search App"; + ((System.ComponentModel.ISupportInitialize)(this.gridTableData)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label lblBookName; + private System.Windows.Forms.TextBox txtBookName; + private System.Windows.Forms.Label lblBookAuthor; + private System.Windows.Forms.TextBox txtBookAuthor; + private System.Windows.Forms.Label lblBookDescription; + private System.Windows.Forms.TextBox txtBookDescription; + private System.Windows.Forms.TextBox txtSearchText; + private System.Windows.Forms.Button btnSave; + private System.Windows.Forms.Button btnDelete; + private System.Windows.Forms.Button btnCancel; + private System.Windows.Forms.Button btnSearch; + private System.Windows.Forms.DataGridView gridTableData; + } +} + diff --git a/MySQLBookAppCRUD/MySQLBookAppCRUD/Form1.cs b/MySQLBookAppCRUD/MySQLBookAppCRUD/Form1.cs new file mode 100644 index 0000000..02ede28 --- /dev/null +++ b/MySQLBookAppCRUD/MySQLBookAppCRUD/Form1.cs @@ -0,0 +1,138 @@ +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; +using MySql.Data.MySqlClient; + +namespace MySQLBookAppCRUD +{ + public partial class BookSearchApp : Form + { + private string _connectionString = "Server=localhost;User=root;Password=root123;Database=books;"; + private MySqlConnection _connection = null; + + private int _bookId = 0; + + public BookSearchApp() + { + InitializeComponent(); + _connection = new MySqlConnection(_connectionString); + _connection.Open(); + + GridFill(); + ClearFields(); + } + + private void btnSave_Click(object sender, EventArgs e) + { + var command = new MySqlCommand("BookAddOrEdit", _connection); + command.CommandType = CommandType.StoredProcedure; + + var bookName = txtBookName.Text.Trim(); + command.Parameters.AddWithValue("_BookId", _bookId); + command.Parameters.AddWithValue("_BookName", bookName); + command.Parameters.AddWithValue("_BookAuthor", txtBookAuthor.Text.Trim()); + command.Parameters.AddWithValue("_BookDescription", txtBookDescription.Text.Trim()); + command.ExecuteNonQuery(); + + MessageBox.Show($"Successfully updated book: {bookName}"); + GridFill(); + ClearFields(); + } + + private void GridFill() + { + var command = new MySqlDataAdapter("BookViewAll", _connection); + command.SelectCommand.CommandType = CommandType.StoredProcedure; + + var dataTable = new DataTable(); + command.Fill(dataTable); + + gridTableData.DataSource = dataTable; + gridTableData.Columns[0].Visible = false; + } + + private void ClearFields() + { + txtBookName.Clear(); + txtBookAuthor.Clear(); + txtBookDescription.Clear(); + + _bookId = 0; + + btnSave.Text = "Save"; + btnDelete.Enabled = false; + } + + private void gridTableData_DoubleClick(object sender, EventArgs e) + { + var row = gridTableData.CurrentRow; + if (row != null && row.Index > -1) + { + try + { + var cells = row.Cells; + txtBookName.Text = cells[1].Value.ToString(); + txtBookAuthor.Text = cells[2].Value.ToString(); + txtBookDescription.Text = cells[3].Value.ToString(); + + _bookId = Convert.ToInt32(cells[0].Value.ToString()); + btnSave.Text = "Update"; + btnDelete.Enabled = true; + } + catch (Exception ex) + { + MessageBox.Show("Error, please try selecting a different row."); + } + } + } + + private void btnDelete_Click(object sender, EventArgs e) + { + if (_bookId > 0) + { + var command = new MySqlCommand("BookDeleteById", _connection); + command.CommandType = CommandType.StoredProcedure; + + command.Parameters.AddWithValue("_BookId", _bookId); + command.ExecuteNonQuery(); + + MessageBox.Show($"Deleted book: {txtBookName.Text.Trim()}"); + GridFill(); + ClearFields(); + } + } + + private void btnSearch_Click(object sender, EventArgs e) + { + var searchText = txtSearchText.Text.Trim(); + + if (!string.IsNullOrEmpty(searchText)) + { + var command = new MySqlDataAdapter("BookSearchByValue", _connection); + command.SelectCommand.CommandType = CommandType.StoredProcedure; + + command.SelectCommand.Parameters.AddWithValue("_SearchText", searchText); + + var dataTable = new DataTable(); + command.Fill(dataTable); + gridTableData.DataSource = dataTable; + gridTableData.Columns[0].Visible = false; + } + else + { + GridFill(); + } + } + + private void btnCancel_Click(object sender, EventArgs e) + { + ClearFields(); + } + } +} diff --git a/MySQLBookAppCRUD/MySQLBookAppCRUD/Form1.resx b/MySQLBookAppCRUD/MySQLBookAppCRUD/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/MySQLBookAppCRUD/MySQLBookAppCRUD/Form1.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/MySQLBookAppCRUD/MySQLBookAppCRUD/MySQLBookAppCRUD.csproj b/MySQLBookAppCRUD/MySQLBookAppCRUD/MySQLBookAppCRUD.csproj new file mode 100644 index 0000000..ba83746 --- /dev/null +++ b/MySQLBookAppCRUD/MySQLBookAppCRUD/MySQLBookAppCRUD.csproj @@ -0,0 +1,87 @@ + + + + + Debug + AnyCPU + {FBB677BF-2293-47A3-97B8-A6F0F7D1D06F} + WinExe + MySQLBookAppCRUD + MySQLBookAppCRUD + v4.6.1 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\Program Files (x86)\MySQL\Connector NET 8.0\Assemblies\v4.5.2\MySql.Data.dll + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/MySQLBookAppCRUD/MySQLBookAppCRUD/Program.cs b/MySQLBookAppCRUD/MySQLBookAppCRUD/Program.cs new file mode 100644 index 0000000..6fafecf --- /dev/null +++ b/MySQLBookAppCRUD/MySQLBookAppCRUD/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace MySQLBookAppCRUD +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new BookSearchApp()); + } + } +} diff --git a/MySQLBookAppCRUD/MySQLBookAppCRUD/Properties/AssemblyInfo.cs b/MySQLBookAppCRUD/MySQLBookAppCRUD/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..51dd67c --- /dev/null +++ b/MySQLBookAppCRUD/MySQLBookAppCRUD/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MySQLBookAppCRUD")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MySQLBookAppCRUD")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("fbb677bf-2293-47a3-97b8-a6f0f7d1d06f")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MySQLBookAppCRUD/MySQLBookAppCRUD/Properties/Resources.Designer.cs b/MySQLBookAppCRUD/MySQLBookAppCRUD/Properties/Resources.Designer.cs new file mode 100644 index 0000000..891794b --- /dev/null +++ b/MySQLBookAppCRUD/MySQLBookAppCRUD/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace MySQLBookAppCRUD.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // 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.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + 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() + { + } + + /// + /// 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)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MySQLBookAppCRUD.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 + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/MySQLBookAppCRUD/MySQLBookAppCRUD/Properties/Resources.resx b/MySQLBookAppCRUD/MySQLBookAppCRUD/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/MySQLBookAppCRUD/MySQLBookAppCRUD/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/MySQLBookAppCRUD/MySQLBookAppCRUD/Properties/Settings.Designer.cs b/MySQLBookAppCRUD/MySQLBookAppCRUD/Properties/Settings.Designer.cs new file mode 100644 index 0000000..56e146f --- /dev/null +++ b/MySQLBookAppCRUD/MySQLBookAppCRUD/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace MySQLBookAppCRUD.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 + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/MySQLBookAppCRUD/MySQLBookAppCRUD/Properties/Settings.settings b/MySQLBookAppCRUD/MySQLBookAppCRUD/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/MySQLBookAppCRUD/MySQLBookAppCRUD/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + +