01.
using
System;
02.
using
System.Collections.Generic;
03.
using
System.ComponentModel;
04.
using
System.Data;
05.
using
System.Drawing;
06.
using
System.Linq;
07.
using
System.Text;
08.
using
System.Windows.Forms;
09.
using
System.Data.SqlClient;
10.
using
System.IO;
11.
12.
namespace
LoginFormCS
13.
{
14.
public
partial
class
frmLogin : Form
15.
{
16.
public
frmLogin()
17.
{
18.
InitializeComponent();
19.
}
20.
21.
private
void
btnLogin_Click(
object
sender, EventArgs e)
22.
{
23.
SqlConnection objConn =
new
SqlConnection();
24.
SqlCommand objCmd =
new
SqlCommand();
25.
string
strConnString =
null
;
26.
string
strSQL =
null
;
27.
28.
strConnString =
"Server=localhost;UID=sa;PASSWORD=;Database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
;
29.
objConn.ConnectionString = strConnString;
30.
objConn.Open();
31.
32.
int
intNumRows = 0;
33.
strSQL =
"SELECT COUNT(*) FROM member WHERE Username = '"
+
this
.txtUsername.Text +
"' AND Password = '"
+
this
.txtPassword.Text +
"' "
;
34.
objCmd =
new
SqlCommand(strSQL, objConn);
35.
intNumRows = Convert.ToInt32(objCmd.ExecuteScalar());
36.
37.
if
(intNumRows > 0)
38.
{
39.
frmMain frm =
new
frmMain();
40.
frm._strUser =
this
.txtUsername.Text;
41.
frm.LoadInfor();
42.
frm.Show();
43.
44.
this
.Hide();
45.
}
46.
else
47.
{
48.
MessageBox.Show(
"Username or Password Incorrect"
);
49.
}
50.
51.
objConn.Close();
52.
objConn =
null
;
53.
}
54.
55.
private
void
btnClose_Click(
object
sender, EventArgs e)
56.
{
57.
if
(MessageBox.Show(
"Exit application?"
,
""
, MessageBoxButtons.YesNo) == DialogResult.Yes)
58.
{
59.
Application.Exit();
60.
}
61.
}
62.
63.
64.
}
65.
}