120-20-guruh talabasi G’affarov Mirzabekning Avtosalon bo’yicha topshirig’i(login,parol qismi)
-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace avto
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
ruyhat();
panel1.BackColor = Color.FromArgb(100, 0, 0, 0);
fm2.Show();
}
static string path = Environment.CurrentDirectory.Remove(Environment.CurrentDirectory.Length - 10);
SqlConnection con = new SqlConnection($@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename={path}\Avto.mdf;Integrated Security=True");
register fm2 = new register();
public string[] name = new string[9999];
public string[] pas = new string[9999];
public string[] us = new string[9999];
public int l = 0;
public int i = 0;
public bool oyna = false;
public void ruyhat()
{
con.Close();
con.Open();
var cmd = new SqlCommand("select *from dbo.Users",con);
var da = new SqlDataAdapter(cmd);
var dt = new DataTable();
da.Fill(dt);
foreach(DataRow row in dt.Rows)
{
name[i] = row[1].ToString();
us[i] = row[2].ToString();
pas[i] = row[3].ToString();
i++;
}
dt.Columns.Clear();
dt.Rows.Clear();
con.Close();
}
private void gunaButton2_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void gunaButton1_Click(object sender, EventArgs e)
{
Application.Exit();
}
bool a=false, b=false;
private void text1_TextChanged(object sender, EventArgs e)
{
if (!a && text1.Text!="")
{
text1.Clear();
a = true;
}
}
private void gunaButton4_Click(object sender, EventArgs e)
{
if (fm2 != null) timer1.Start();
else fm2.Show();
}
private void timer1_Tick(object sender, EventArgs e)
{
fm2.Left += 10;
if (fm2.Left>=1180)
{
timer1.Stop();
this.TopMost = false;
fm2.TopMost = true;
timer2.Start();
}
}
private void timer2_Tick(object sender, EventArgs e)
{
fm2.Left -= 10;
if (fm2.Left<=765)
{
timer2.Stop();
}
if (fm2.Left==760)
{
this.Hide();
}
}
private void gunaButton3_Click(object sender, EventArgs e)
{
try
{
for (int i = 0; i < us.Length; i++)
{
if (text1.Text == us[i] && text2.Text == pas[i])
{
l = i;
oyna = true;
break;
}
}
if (text1.Text=="Avto" && text2.Text=="123")
{
new Dashbord_Admin().Show();
fm2.Hide();
this.Hide();
}
else
{
if (oyna)
{
new Dashbord_User(name[l]).Show();
fm2.Hide();
this.Hide();
}
else
{
MessageBox.Show("Login yo parol xato", "Xabar", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"Xabar",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
private void Login_Load(object sender, EventArgs e)
{
}
private void text2_TextChanged(object sender, EventArgs e)
{
if (!b)
{
text2.Clear();
text2.PasswordChar = '*';
b = true;
}
}
}
}
|