This post shows you How to Create a Metro Login Form with SQL Database using Metro Framework, Dapper ORM in C# .NET Windows Forms Application.
The login form is a must-have feature in any software management. It helps users protect their data or authorize used functions corresponding to the permissions. To practice demo you should create a new windows forms project as the following.
To play the demo, you should create a new windows forms project. Next, right click on your project, then select Manage NuGet Packages -> Search metro framework, dapper -> Install it on your project.
If you don't see the metro framework in your toolbox, you can view How to download and install metro framework
As you know, The Metro Framework is a library that supports multiple control for windows forms and Dapper ORM is a high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird ...etc.
Drag the MetroTextBox, MetroButton, MetroCheckBox and Panel controls, then design a simple metro login form as shown below.
![metro login form](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzE9rWvYPuHnNlI6tJzPGcjMl5_z2h2DQt4KWRgb4ok4QcEqb7scMjwqx6AbNWXjH_pkSKeXPmVnY-gaVZcXAiHe1oUmjkIYtKrAIOwNHXUnyeJyuIZy93H5vcOvdzK-k8y5v6lutxpwo/s1600/metro-login.png)
Create the User class allows you to map your data return from user table in sql server.
1
2
3
4
5
| public class User { public string UserName { get ; set ; } public string Password { get ; set ; } } |
You can copy the sql script below to create a new database.
1
2
3
4
5
6
7
8
| USE [master] GO CREATE DATABASE [dbuser] CONTAINMENT = NONE ON PRIMARY ( NAME = N 'dbuser' , FILENAME = N 'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\dbuser.mdf' , SIZE = 4096KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) LOG ON ( NAME = N 'dbuser_log' , FILENAME = N 'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\dbuser_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%) |
Next, Run the script below to create the User table
video
video
tham khảo tại đây.