Merge branch 'master' of git.alex.lol:Alex/CSharpFagskolen

This commit is contained in:
Alex Thomassen 2019-03-21 11:30:12 +01:00
commit ef4dee2f4c
Signed by: Alex
GPG Key ID: 10BD786B5F6FF5DE
23 changed files with 1426 additions and 3 deletions

View File

@ -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}") = "ExceptionHandling", "ExceptionHandling\ExceptionHandling.csproj", "{830E9E45-F036-4DB4-8492-6EED4EADEFA5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{830E9E45-F036-4DB4-8492-6EED4EADEFA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{830E9E45-F036-4DB4-8492-6EED4EADEFA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{830E9E45-F036-4DB4-8492-6EED4EADEFA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{830E9E45-F036-4DB4-8492-6EED4EADEFA5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {841BBAE6-75CB-46F1-B364-657DA3BB140F}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{830E9E45-F036-4DB4-8492-6EED4EADEFA5}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ExceptionHandling</RootNamespace>
<AssemblyName>ExceptionHandling</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ExceptionHandling
{
class Program
{
static void Main(string[] args)
{
Division();
Console.ReadKey();
}
static void Division()
{
try
{
Console.BackgroundColor = ConsoleColor.Black;
Console.WriteLine("Division. Type the first number:");
string numberOne = Console.ReadLine();
Console.WriteLine("Type the second number:");
string numberTwo = Console.ReadLine();
Console.WriteLine($"Result: {Convert.ToInt32(numberOne) / Convert.ToInt32(numberTwo)}");
}
catch (DivideByZeroException ex)
{
Console.WriteLine("Du kænn itte dele på null ama:\n" + ex.GetType());
}
catch (FormatException ex)
{
Console.WriteLine("Du må skrive inn tal ama\n:" + ex.StackTrace);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
Division();
}
}
}
}

View File

@ -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("ExceptionHandling")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ExceptionHandling")]
[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("830e9e45-f036-4db4-8492-6eed4eadefa5")]
// 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")]

View File

@ -0,0 +1,182 @@
CREATE DATABASE IF NOT EXISTS `books` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */;
USE `books`;
-- MySQL dump 10.13 Distrib 8.0.15, for Win64 (x86_64)
--
-- Host: localhost Database: books
-- ------------------------------------------------------
-- Server version 8.0.15
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
SET NAMES utf8 ;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `books`
--
DROP TABLE IF EXISTS `books`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
SET character_set_client = utf8mb4 ;
CREATE TABLE `books` (
`BookId` int(11) NOT NULL AUTO_INCREMENT,
`BookName` varchar(45) DEFAULT NULL,
`BookAuthor` varchar(45) DEFAULT NULL,
`BookDescription` varchar(255) DEFAULT NULL,
PRIMARY KEY (`BookId`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `books`
--
LOCK TABLES `books` WRITE;
/*!40000 ALTER TABLE `books` DISABLE KEYS */;
INSERT INTO `books` VALUES (1,'Mora di','Stian Larsen','jåa mordi jå væ LUT DÆ VÆ'),(5,'xD',':DDDDD','???????????????????????????????????????????????????????????');
/*!40000 ALTER TABLE `books` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Dumping events for database 'books'
--
--
-- Dumping routines for database 'books'
--
/*!50003 DROP PROCEDURE IF EXISTS `BookAddOrEdit` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `BookAddOrEdit`(
_BookId INT,
_BookName VARCHAR(45),
_BookAuthor VARCHAR(45),
_BookDescription VARCHAR(255)
)
BEGIN
if _BookId = 0 then
INSERT INTO books(BookName, BookAuthor, BookDescription)
VALUES(_BookName, _BookAuthor, _BookDescription);
else
UPDATE books
SET
BookName = _BookName,
BookAuthor = _BookAuthor,
BookDescription = _BookDescription
WHERE
BookId = _BookId;
end if;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `BookDeleteById` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `BookDeleteById`(
_BookId INT
)
BEGIN
DELETE FROM books WHERE BookId = _BookId;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `BookSearchByValue` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `BookSearchByValue`(
_SearchText VARCHAR(45)
)
BEGIN
SELECT * FROM books
WHERE
BookName LIKE CONCAT('%', _SearchText, '%')
OR
BookAuthor LIKE CONCAT('%', _SearchText, '%');
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `BookViewAll` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `BookViewAll`()
BEGIN
SELECT * FROM books;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `BookViewById` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_0900_ai_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `BookViewById`(_BookId INT)
BEGIN
SELECT * FROM books WHERE BookId = _BookId;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-03-14 9:48:13

View File

@ -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

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>

View File

@ -0,0 +1,195 @@
namespace MySQLBookAppCRUD
{
partial class BookSearchApp
{
/// <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.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;
}
}

View File

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

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

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{FBB677BF-2293-47A3-97B8-A6F0F7D1D06F}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>MySQLBookAppCRUD</RootNamespace>
<AssemblyName>MySQLBookAppCRUD</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<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\Connector NET 8.0\Assemblies\v4.5.2\MySql.Data.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -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
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new BookSearchApp());
}
}
}

View File

@ -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")]

View File

@ -0,0 +1,71 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
namespace MySQLBookAppCRUD.Properties
{
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// 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()
{
}
/// <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))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MySQLBookAppCRUD.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
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}

View File

@ -0,0 +1,117 @@
<?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.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: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" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</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" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</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=2.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>
</resheader>
</root>

View File

@ -0,0 +1,30 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
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;
}
}
}
}

View File

@ -0,0 +1,7 @@
<?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>

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using System.Data;
namespace MySQLDatabaseTilkobling
{
@ -27,5 +28,24 @@ namespace MySQLDatabaseTilkobling
{
connectionString.Close();
}
public DataTable GetTableValues()
{
// Lag et variabel som holder et midlertidig "DataTable"
var table = new DataTable();
// MySqlDataAdapter lar oss sende SQL-kode til serveren og hente ut
// dataen vi vil ha fra databasen.
// `student` er navnet på tabellen som bruker i MySQL. Dette bør oppdateres om du bruker noe annet.
var data = new MySqlDataAdapter($"select * from student", connectionString);
// Fyller opp det midlertidige "DataTable"-variabelet med data
// fra MySQL-databasen som vi akkurat hentet ut.
data.Fill(table);
// Returnerer dataen som en "DataTable"-verdi
// Dette er ment til å brukes i "DataGridView" i form'et.
return table;
}
}
}

View File

@ -28,20 +28,47 @@
/// </summary>
private void InitializeComponent()
{
this.tableView = new System.Windows.Forms.DataGridView();
this.refreshButton = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.tableView)).BeginInit();
this.SuspendLayout();
//
// tableView
//
this.tableView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.tableView.Location = new System.Drawing.Point(13, 13);
this.tableView.Name = "tableView";
this.tableView.Size = new System.Drawing.Size(775, 389);
this.tableView.TabIndex = 0;
//
// refreshButton
//
this.refreshButton.Location = new System.Drawing.Point(316, 408);
this.refreshButton.Name = "refreshButton";
this.refreshButton.Size = new System.Drawing.Size(137, 23);
this.refreshButton.TabIndex = 1;
this.refreshButton.Text = "Oppdater tabell";
this.refreshButton.UseVisualStyleBackColor = true;
this.refreshButton.Click += new System.EventHandler(this.refreshButton_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.refreshButton);
this.Controls.Add(this.tableView);
this.Name = "Form1";
this.Text = "MySQLDatabaseTilkobling";
((System.ComponentModel.ISupportInitialize)(this.tableView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataGridView tableView;
private System.Windows.Forms.Button refreshButton;
}
}

View File

@ -16,5 +16,19 @@ namespace MySQLDatabaseTilkobling
{
InitializeComponent();
}
private void refreshButton_Click(object sender, EventArgs e)
{
DatabaseConnection database = new DatabaseConnection();
// Åpne en tilkobling til MySQL
database.OpenConnection();
// Hent ut data og sett dette inn i programvindu
tableView.DataSource = database.GetTableValues();
// Lukk tilkoblingen til MySQL
database.CloseConnection();
}
}
}

View File

@ -62,6 +62,15 @@
this.btnBmi = new System.Windows.Forms.Button();
this.lblBmi = new System.Windows.Forms.Label();
this.txtBmi = new System.Windows.Forms.TextBox();
this.lblExceptionOppgaveOne = new System.Windows.Forms.Label();
this.btnExceptionToArray = new System.Windows.Forms.Button();
this.lblExceptionIndexNum = new System.Windows.Forms.Label();
this.txtExceptionIndexNum = new System.Windows.Forms.TextBox();
this.txtExceptionValueOne = new System.Windows.Forms.TextBox();
this.lblExceptionValueOne = new System.Windows.Forms.Label();
this.lblExceptionArrayValues = new System.Windows.Forms.Label();
this.txtExceptionArrayValues = new System.Windows.Forms.TextBox();
this.resetArrayException = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// txtExVat
@ -350,11 +359,103 @@
this.txtBmi.Size = new System.Drawing.Size(100, 20);
this.txtBmi.TabIndex = 32;
//
// lblExceptionOppgaveOne
//
this.lblExceptionOppgaveOne.AutoSize = true;
this.lblExceptionOppgaveOne.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblExceptionOppgaveOne.Location = new System.Drawing.Point(13, 315);
this.lblExceptionOppgaveOne.Name = "lblExceptionOppgaveOne";
this.lblExceptionOppgaveOne.Size = new System.Drawing.Size(129, 13);
this.lblExceptionOppgaveOne.TabIndex = 33;
this.lblExceptionOppgaveOne.Text = "Exception Oppgave 1";
//
// btnExceptionToArray
//
this.btnExceptionToArray.Location = new System.Drawing.Point(16, 341);
this.btnExceptionToArray.Name = "btnExceptionToArray";
this.btnExceptionToArray.Size = new System.Drawing.Size(75, 23);
this.btnExceptionToArray.TabIndex = 34;
this.btnExceptionToArray.Text = "Til array";
this.btnExceptionToArray.UseVisualStyleBackColor = true;
this.btnExceptionToArray.Click += new System.EventHandler(this.btnExceptionToArray_Click);
//
// lblExceptionIndexNum
//
this.lblExceptionIndexNum.AutoSize = true;
this.lblExceptionIndexNum.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblExceptionIndexNum.ForeColor = System.Drawing.Color.Blue;
this.lblExceptionIndexNum.Location = new System.Drawing.Point(107, 346);
this.lblExceptionIndexNum.Name = "lblExceptionIndexNum";
this.lblExceptionIndexNum.Size = new System.Drawing.Size(92, 13);
this.lblExceptionIndexNum.TabIndex = 35;
this.lblExceptionIndexNum.Text = "Indeksnummer:";
//
// txtExceptionIndexNum
//
this.txtExceptionIndexNum.Location = new System.Drawing.Point(205, 343);
this.txtExceptionIndexNum.Name = "txtExceptionIndexNum";
this.txtExceptionIndexNum.Size = new System.Drawing.Size(100, 20);
this.txtExceptionIndexNum.TabIndex = 36;
//
// txtExceptionValueOne
//
this.txtExceptionValueOne.Location = new System.Drawing.Point(522, 343);
this.txtExceptionValueOne.Name = "txtExceptionValueOne";
this.txtExceptionValueOne.Size = new System.Drawing.Size(100, 20);
this.txtExceptionValueOne.TabIndex = 38;
//
// lblExceptionValueOne
//
this.lblExceptionValueOne.AutoSize = true;
this.lblExceptionValueOne.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblExceptionValueOne.ForeColor = System.Drawing.Color.Blue;
this.lblExceptionValueOne.Location = new System.Drawing.Point(318, 346);
this.lblExceptionValueOne.Name = "lblExceptionValueOne";
this.lblExceptionValueOne.Size = new System.Drawing.Size(198, 13);
this.lblExceptionValueOne.TabIndex = 37;
this.lblExceptionValueOne.Text = "Oppgi tall som skal legges i array:";
//
// lblExceptionArrayValues
//
this.lblExceptionArrayValues.AutoSize = true;
this.lblExceptionArrayValues.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblExceptionArrayValues.Location = new System.Drawing.Point(13, 407);
this.lblExceptionArrayValues.Name = "lblExceptionArrayValues";
this.lblExceptionArrayValues.Size = new System.Drawing.Size(85, 13);
this.lblExceptionArrayValues.TabIndex = 39;
this.lblExceptionArrayValues.Text = "Array-innhold:";
//
// txtExceptionArrayValues
//
this.txtExceptionArrayValues.Location = new System.Drawing.Point(105, 407);
this.txtExceptionArrayValues.Name = "txtExceptionArrayValues";
this.txtExceptionArrayValues.Size = new System.Drawing.Size(517, 20);
this.txtExceptionArrayValues.TabIndex = 40;
//
// resetArrayException
//
this.resetArrayException.Location = new System.Drawing.Point(16, 370);
this.resetArrayException.Name = "resetArrayException";
this.resetArrayException.Size = new System.Drawing.Size(75, 23);
this.resetArrayException.TabIndex = 41;
this.resetArrayException.Text = "Reset array";
this.resetArrayException.UseVisualStyleBackColor = true;
this.resetArrayException.Click += new System.EventHandler(this.resetArrayException_Click);
//
// OvingsOppgave
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.resetArrayException);
this.Controls.Add(this.txtExceptionArrayValues);
this.Controls.Add(this.lblExceptionArrayValues);
this.Controls.Add(this.txtExceptionValueOne);
this.Controls.Add(this.lblExceptionValueOne);
this.Controls.Add(this.txtExceptionIndexNum);
this.Controls.Add(this.lblExceptionIndexNum);
this.Controls.Add(this.btnExceptionToArray);
this.Controls.Add(this.lblExceptionOppgaveOne);
this.Controls.Add(this.txtBmi);
this.Controls.Add(this.lblBmi);
this.Controls.Add(this.btnBmi);
@ -434,6 +535,15 @@
private System.Windows.Forms.Button btnBmi;
private System.Windows.Forms.Label lblBmi;
private System.Windows.Forms.TextBox txtBmi;
private System.Windows.Forms.Label lblExceptionOppgaveOne;
private System.Windows.Forms.Button btnExceptionToArray;
private System.Windows.Forms.Label lblExceptionIndexNum;
private System.Windows.Forms.TextBox txtExceptionIndexNum;
private System.Windows.Forms.TextBox txtExceptionValueOne;
private System.Windows.Forms.Label lblExceptionValueOne;
private System.Windows.Forms.Label lblExceptionArrayValues;
private System.Windows.Forms.TextBox txtExceptionArrayValues;
private System.Windows.Forms.Button resetArrayException;
}
}

View File

@ -22,11 +22,16 @@ namespace OvingsOppgaveTre
double exVat;
string exVatText = txtExVat.Text;
if (double.TryParse(exVatText, out exVat))
try
{
exVat = Convert.ToDouble(exVatText);
double incVat = exVat * 1.25;
txtIncVat.Text = incVat.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void txtIncVat_TextChanged(object sender, EventArgs e)
@ -36,8 +41,6 @@ namespace OvingsOppgaveTre
if (double.TryParse(incVatText, out incVat))
{
// Husker ikke om det er noen lettere måte å regne tilbake lol
// ¯\_(ツ)_/¯
double exVat = (incVat / 125) * 100;
txtExVat.Text = exVat.ToString();
}
@ -93,5 +96,48 @@ namespace OvingsOppgaveTre
txtBmi.Text = bmi.ToString();
}
}
// Definer array utenfor metoden slik at den ikke overskrives
// hver gang man trykker på knappen.
private byte[] byteArray = new byte[6];
private void btnExceptionToArray_Click(object sender, EventArgs e)
{
// Tekstboks: "Inndeksnummer"
var indexText = txtExceptionIndexNum.Text;
// Tekstbox: "Oppgi tall som skal legges i array"
var arrayValueText = txtExceptionValueOne.Text;
try
{
var indexNum = Convert.ToInt16(indexText);
var arrayValue = Convert.ToByte(arrayValueText);
byteArray[indexNum] = arrayValue;
txtExceptionArrayValues.Text = string.Join("\t", byteArray);
}
catch (IndexOutOfRangeException ex)
{
MessageBox.Show($"Ugyldig inndeks spesifisert i array: {indexText}\n{ex.GetType()}");
}
catch (OverflowException ex)
{
MessageBox.Show(
$"Tallet du spesifiserte er for høyt for typen `byte`: {arrayValueText}\n{ex.GetType()}");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
MessageBox.Show("Test utført.");
}
}
private void resetArrayException_Click(object sender, EventArgs e)
{
byteArray = new byte[6];
}
}
}