
Here is Form(2) ~ This is also called Sign in From ~ In there you must input the user name, password and your professional .. It connects with SQL server and it checks that user input all are right ..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient; //this needs for sql server connection
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Manager_project
{
public partial class Form2 : Form
{
string connString= "server=ZAYYAROO; database=manager; uid=sa; pwd=123;"; //for sqlconnection
private SqlConnection conn;
private SqlCommand cmd;
public string myusername; //variable for input username
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e) //* paw say yan
{
textBox2.Text = "**********";
}
private void button1_Click(object sender, EventArgs e) //password sit yan
{
string commandString = "SELECT * FROM userdata " + "WHERE userdata.uname='"+myusername+"'"; //for sqlcommand
conn = new SqlConnection(connString);
cmd = new SqlCommand(commandString, conn);
SqlDataReader reader; //new sql data reader
try
{
conn.Open();
reader = cmd.ExecuteReader(); //in there 3 types of command ..ExecuteReader/ExecuteScalar/ExecuteNonQuery
reader.Read();
string username = reader.GetString(1).Trim(); //Read from table column(1)
string realpass = reader.GetString(2).Trim(); //Table starts with column(0)
string prof = reader.GetString(6).Trim();
if ((textBox1.Text == username) && (textBox2.Text == realpass) && (textBox3.Text == prof)) //check
{
Form6 s = new Form6();
s.Show();
}
else if ((textBox1.Text == username) && (textBox3.Text == realpass))
{
MessageBox.Show("Incorrect password!");
}
else
{
MessageBox.Show("Loading failed!");
}
}
catch (Exception er)
{
MessageBox.Show(er.ToString());
}
finally
{
conn.Close();
}
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Form3 f = new Form3();
f.Show();
}
private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Form5 g = new Form5();
g.Show();
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Form4 d = new Form4();
d.Show();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
myusername = textBox1.Text;
}
}
}
No comments:
Post a Comment