Skip to content

Commit

Permalink
Create asm
Browse files Browse the repository at this point in the history
  • Loading branch information
khiem205 authored Dec 13, 2024
1 parent 0e8980e commit dc7f02c
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace SalesManagementSystem
{
public partial class Login : Form
{
private string connectionString = @"Server=DINHKHIEM\SQLEXPRESS01;Database=hoangdinhkhiem;Trusted_Connection=True;";

public Login()
{
InitializeComponent();
}

// Executes when the login button is clicked
private void btnLogin_Click(object sender, EventArgs e)
{
string username = txtUsername.Text.Trim();
string password = txtPassword.Text;

if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
{
MessageBox.Show("Please enter your username and password!", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}

try
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
string query = "SELECT COUNT(*) FROM Account WHERE Username = @Username AND Password = @Password";
using (SqlCommand cmd = new SqlCommand(query, conn))
{
cmd.Parameters.Add("@Username", SqlDbType.NVarChar).Value = username;
cmd.Parameters.Add("@Password", SqlDbType.NVarChar).Value = password;

int result = (int)cmd.ExecuteScalar();

if (result > 0)
{
MessageBox.Show("Login successful!", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information);
MainForm mainForm = new MainForm();
this.Hide();
mainForm.Show();
}
else
{
MessageBox.Show("Username or password is incorrect!", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
catch (SqlException sqlEx)
{
MessageBox.Show("Database error: " + sqlEx.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception ex)
{
MessageBox.Show("Unexpected error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

// Open the registration form
private void btnRegister_Click(object sender, EventArgs e)
{
this.Hide();
Register registerForm = new Register();
registerForm.Show();
}

// Close the application
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}

0 comments on commit dc7f02c

Please sign in to comment.