28-03-2012, 12:17 PM
SERVER APPLICATION
SERVER APPLICATION.docx (Size: 3.88 MB / Downloads: 45)
CODE:
using System.Data.SqlClient;
using System.Data.SqlServerCe;
namespace PocketPC
{
public partial class frmLogin : Form
{
string str;
SqlCeConnection con;
SqlCeCommand com;
SqlCeDataReader rdr;
public frmLogin()
{
InitializeComponent();
}
private void LOGIN_Load(object sender, EventArgs e)
{
con = new SqlCeConnection(@"Data Source=E:\Event Management\PocketPC\PocketPC\Database1.sdf");
txtusrname.Focus();
}
private void btnOk_Click(object sender, EventArgs e)
{
if (txtusrname.Text == "")
{
MessageBox.Show("Enter Username..", "ALERT", MessageBoxButtons.OK, MessageBoxIcon.Question);
txtusrname.Focus();
}
else if (txtpwd.Text == "")
{
MessageBox.Show("Enter Password..", "ALERT", MessageBoxButtons.OK, MessageBoxIcon.Question);
txtpwd.Focus();
}
else
{
str = "select * from Login where user_name='" + txtusrname.Text + "' and password='" + txtpwd.Text + "'";
com = new SqlCeCommand(str, con);
con.Open();
rdr = com.ExecuteReader();
if (rdr.Read())
{
frmMain obj = new frmMain();
obj.Show();
Visible = false;
}
else
{
MessageBox.Show("Incorrect login details.. Login Failed","INVALID",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
txtusrname.Clear();
txtpwd.Clear();
txtusrname.Focus();
}
rdr.Close();
con.Close();
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void txtusrname_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void txtusrname_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
txtpwd.Focus();
}
private void txtpwd_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
btnOk.Focus();
}
}
}