Algoritmik tillar va dasturlash



Yüklə 0,73 Mb.
səhifə9/9
tarix06.07.2023
ölçüsü0,73 Mb.
#128477
1   2   3   4   5   6   7   8   9
sarvinoz.kurs ishi. (4)

ILOVALAR

1-rasm
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.OleDb;
namespace Malika_Qaxramonova
{
public partial class Form1 : Form
{
static string conString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='D:\Kurs ishi\Xodimlar\Xodimlar.accdb'";
OleDbConnection con = new OleDbConnection(conString);
OleDbCommand cmd;
OleDbDataAdapter adapter;
DataTable dt = new DataTable();

public string[] parol = new string[100];


public string[] login = new string[100];
public string[] ism = new string[100];
public string[] familiya = new string[100];
public string[] role = new string[100];

public Form1()


{
InitializeComponent();
this.oqish();
}

private void oqish() {


string sql = "Select * from Foydalanuvchi";
cmd = new OleDbCommand(sql, con);

try
{


con.Open();
adapter = new OleDbDataAdapter(cmd);
adapter.Fill(dt);
int i = 0;
foreach (DataRow row in dt.Rows)
{
login[i] = row[1].ToString();
parol[i] = row[2].ToString();
ism[i] = row[4].ToString();
familiya[i] = row[3].ToString();
role[i] = row[5].ToString();
i++;
}

dt.Rows.Clear();


con.Close();


}
catch (Exception e)
{
MessageBox.Show("Failed");
con.Close();
}
}

private void button1_Click(object sender, EventArgs e)


{
bool top = false;
for (int i = 0; i < login.Length; i++)
{
if (login[i] == textBox1.Text)
{
top = true;
if (parol[i] == textBox2.Text)
{
this.Hide();
Dashboard dash1 = new Dashboard(familiya[i], ism[i], role[i]);
dash1.Show();

}
else {


MessageBox.Show("Parol NoTo`g`ri");
}
break;
}
}
if (top == false)
{
MessageBox.Show("Login mavjud emas");
}
}
}
}

2-rasm
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.OleDb;
namespace Malika_Qaxramonova
{
public partial class Dashboard : Form
{
public string familya, ism, role, bolim = "";
public string[] bolim_id = new string[20];
public string[] bolim_nomi = new string[20];
public string qidiruv = "";

static string conString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='D:\Kurs ishi\Xodimlar\Xodimlar.accdb'";


OleDbConnection con = new OleDbConnection(conString);
OleDbCommand cmd;
OleDbDataAdapter adapter;
DataTable dt = new DataTable();

public Dashboard(string familya, string ism, string role)


{
InitializeComponent();
this.familya = familya;
this.ism = ism;
this.role = role;
if (role == "2") {
button1.Visible = false;
button2.Visible = false;
button3.Visible = false;
button8.Visible = false;
}
}

private void Dashboard_Load(object sender, EventArgs e)


{
AllPanel();
bolim = "0";
bolim_data_read();
yozish_datagrid();
}

private void bolim_data_read() {


string sql = "Select * from Bolim";
cmd = new OleDbCommand(sql, con);
try
{
con.Open();
adapter = new OleDbDataAdapter(cmd);
adapter.Fill(dt);
int i = 0;
foreach (DataRow row in dt.Rows)
{
bolim_id[i] = row[0].ToString();
bolim_nomi[i] = row[1].ToString();
i++;
}

dt.Rows.Clear();


dt.Columns.Clear();
con.Close();
}
catch (Exception e)
{
MessageBox.Show("Failed");
con.Close();
}
}

private void yozish_datagrid() {


comboBox1.Text = "Barcha Kafedralar";
comboBox1.Visible = false;
dataGridView1.Rows.Clear();
dataGridView1.Columns.Clear();
dataGridView1.ColumnCount = 5;
dataGridView1.Columns[0].Name = "Id";
dataGridView1.Columns[1].Name = "Familya";
dataGridView1.Columns[2].Name = "Ism";
dataGridView1.Columns[3].Name = "Bo`lim";
dataGridView1.Columns[4].Name = "Lavozimi";

dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;


dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;


dataGridView1.MultiSelect = false;
dataGridView1.Rows.Clear();
string sql = "";
if (bolim == "0")
{
sql = "Select * from Xodim";
if (this.qidiruv != "")
{
sql += " where [familya]='" + this.qidiruv + "' or [ism]='" + this.qidiruv + "'";
}
}else
if (bolim != "kafedra")
{
sql = "Select * from Xodim where [Bolim_id]='" + bolim + "'";
if (this.qidiruv != "")
{
sql += " and ([familya]='" + this.qidiruv + "' or [ism]='" + this.qidiruv + "')";
}
}
else
if(bolim == "kafedra"){
sql = "Select * from Xodim where Int([Bolim_id]) > 5";
if (this.qidiruv != "")
{
sql += " and ([familya]='" + this.qidiruv + "' or [ism]='" + this.qidiruv + "')";
}
comboBox1.Visible = true;
}

cmd = new OleDbCommand(sql, con);


try
{


con.Open();
adapter = new OleDbDataAdapter(cmd);
adapter.Fill(dt);
string qwer = "";
foreach (DataRow row in dt.Rows)
{
for (int i = 0; i < bolim_id.Length; i++) {
if (row[3].ToString() == bolim_id[i]) {
qwer = bolim_nomi[i];
}
}
bool tre = true;
if (bolim == "kafedra") {
for (int i = 0; i < comboBox1.Items.Count; i++) {
if (qwer == comboBox1.Items[i])
{
tre = false;
break;
}
}
if (tre) {
comboBox1.Items.Add(qwer);
}
}
dataGridView1.Rows.Add(row[0].ToString(), row[1], row[2], qwer, row[4]);
}

dt.Rows.Clear();


dt.Columns.Clear();
con.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
con.Close();
}
}

private void All_Xodim_Pnl_MouseClick(object sender, MouseEventArgs e)


{
AllPanel();
}

private void All_Xodim_Lbl_MouseClick(object sender, MouseEventArgs e)


{
AllPanel();
}

private void AllPanel() {


All_Xodim_Pnl.BackColor = System.Drawing.Color.Green;
Rahbariyat_Pnl.BackColor = System.Drawing.Color.Lime;
Ilm_Blm_Pnl.BackColor = System.Drawing.Color.Lime;
Bxl_Pnl.BackColor = System.Drawing.Color.Lime;
Kfd_Pnl.BackColor = System.Drawing.Color.Lime;
bolim = "0";
yozish_datagrid();
}

private void Rahbariyat_Pnl_MouseClick(object sender, MouseEventArgs e)


{
RahbariyatPanel();
}

private void Rahbariyat_Lbl_MouseClick(object sender, MouseEventArgs e)


{
RahbariyatPanel();
}
private void RahbariyatPanel()
{
All_Xodim_Pnl.BackColor = System.Drawing.Color.Lime;
Rahbariyat_Pnl.BackColor = System.Drawing.Color.Green;
Ilm_Blm_Pnl.BackColor = System.Drawing.Color.Lime;
Bxl_Pnl.BackColor = System.Drawing.Color.Lime;
Kfd_Pnl.BackColor = System.Drawing.Color.Lime;
bolim = "1";
yozish_datagrid();
}

private void Ilm_Blm_Pnl_MouseClick(object sender, MouseEventArgs e)


{
IlmPanel();
}

private void Ilm_Blm_Lbl_Click(object sender, EventArgs e)


{
IlmPanel();
}

private void IlmPanel()


{
All_Xodim_Pnl.BackColor = System.Drawing.Color.Lime;
Rahbariyat_Pnl.BackColor = System.Drawing.Color.Lime;
Ilm_Blm_Pnl.BackColor = System.Drawing.Color.Green;
Bxl_Pnl.BackColor = System.Drawing.Color.Lime;
Kfd_Pnl.BackColor = System.Drawing.Color.Lime;
bolim = "2";
yozish_datagrid();
}

private void Bxl_Pnl_MouseClick(object sender, MouseEventArgs e)


{
BxbPanel();
}

private void Bxl_Lbl_Click(object sender, EventArgs e)


{
BxbPanel();
}
private void BxbPanel()
{
All_Xodim_Pnl.BackColor = System.Drawing.Color.Lime;
Rahbariyat_Pnl.BackColor = System.Drawing.Color.Lime;
Ilm_Blm_Pnl.BackColor = System.Drawing.Color.Lime;
Bxl_Pnl.BackColor = System.Drawing.Color.Green;
Kfd_Pnl.BackColor = System.Drawing.Color.Lime;
bolim = "4";
yozish_datagrid();
}

private void Kfd_Pnl_Paint(object sender, PaintEventArgs e)


{

}


private void Kfd_Pnl_MouseClick(object sender, MouseEventArgs e)
{
kfdPanel();
}

private void Kfd_Lbl_Click(object sender, EventArgs e)


{
kfdPanel();
}
private void kfdPanel()
{
All_Xodim_Pnl.BackColor = System.Drawing.Color.Lime;
Rahbariyat_Pnl.BackColor = System.Drawing.Color.Lime;
Ilm_Blm_Pnl.BackColor = System.Drawing.Color.Lime;
Bxl_Pnl.BackColor = System.Drawing.Color.Lime;
Kfd_Pnl.BackColor = System.Drawing.Color.Green;
bolim = "kafedra";
yozish_datagrid();
}

private void button4_Click(object sender, EventArgs e)


{
this.qidiruv = textBox1.Text;
this.yozish_datagrid();
}

private void button5_Click(object sender, EventArgs e)


{
textBox1.Text = "";
this.qidiruv = textBox1.Text;
this.yozish_datagrid();
}

private void button6_Click(object sender, EventArgs e)


{
string familya = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
string ism = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
string bol = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
string lav = dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
View vw = new View(familya, ism, bol, lav);
vw.Show();
}

private void button7_Click(object sender, EventArgs e)


{
Form1 fr = new Form1();
fr.Show();
this.Hide();
}

private void button1_Click(object sender, EventArgs e)


{
New_User nw = new New_User(this.bolim_id, this.bolim_nomi);
nw.Show();
}

private void button8_Click(object sender, EventArgs e)


{
this.yozish_datagrid();
}

private void button2_Click(object sender, EventArgs e)


{
string id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
Edit_User eu = new Edit_User(id, bolim_id, bolim_nomi);
eu.Show();
}

private void button3_Click(object sender, EventArgs e)


{
string id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
if (MessageBox.Show("Aniq Shu Ma`lumotni o`chirmoqchimisiz?", "O`chirish", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
{
string sql = "delete from Xodim where id=" + id;
cmd = new OleDbCommand(sql, con);
try
{
con.Open();
if (cmd.ExecuteNonQuery() > 0)
{
MessageBox.Show("Success");
}
con.Close();
this.yozish_datagrid();

}
catch (Exception button3_Click_e)


{
MessageBox.Show("Xatolik");
con.Close();
}
}
}

private void Rahbariyat_Lbl_Click(object sender, EventArgs e)


{

}


private void Rahbariyat_Pnl_Paint(object sender, PaintEventArgs e)
{

}


private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
dataGridView1.Rows.Clear();
if (comboBox1.Text == "Barcha Kafedralar")
{
yozish_datagrid();
}
else {
string Bolim_id_s = "";
for (int i = 0; i < bolim_id.Length; i++)
{
if (comboBox1.Text == bolim_nomi[i])
{
Bolim_id_s = bolim_id[i];
}
}
string sql = "Select * from Xodim where [Bolim_id] = '" + Bolim_id_s + "'";
if (this.qidiruv != "")
{
sql += " and ([familya]='" + this.qidiruv + "' or [ism]='" + this.qidiruv + "')";
}
cmd = new OleDbCommand(sql, con);

try
{


con.Open();
adapter = new OleDbDataAdapter(cmd);
adapter.Fill(dt);
string qwer = "";
foreach (DataRow row in dt.Rows)
{
for (int i = 0; i < bolim_id.Length; i++)
{
if (row[3].ToString() == bolim_id[i])
{
qwer = bolim_nomi[i];
}
}

dataGridView1.Rows.Add(row[0].ToString(), row[1], row[2], qwer, row[4]);


}

dt.Rows.Clear();


dt.Columns.Clear();
con.Close();
}
catch (Exception e3)
{
MessageBox.Show(e3.ToString());
con.Close();
}
}
}

private void comboBox1_TextChanged(object sender, EventArgs e)


{

}
}
}



3-rasm
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.OleDb;
namespace Malika_Qaxramonova
{
public partial class View : Form
{
static string conString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='D:\Kurs ishi\Xodimlar\Xodimlar.accdb'";
OleDbConnection con = new OleDbConnection(conString);
OleDbCommand cmd;
OleDbDataAdapter adapter;
DataTable dt = new DataTable();
public string fam = "", ism="";
public View(string familya, string ism, string bolim, string lavozimi)
{
InitializeComponent();
this.fam = familya;
this.ism = ism;
label1.Text += familya;
label2.Text += ism;
label3.Text += bolim;
label4.Text += lavozimi;
}

private void View_Load(object sender, EventArgs e)


{
string sql = "Select * from Xodim where [familya]='" + this.fam + "' and [ism]='" + this.ism + "' ";
cmd = new OleDbCommand(sql, con);
try
{
con.Open();
adapter = new OleDbDataAdapter(cmd);
adapter.Fill(dt);
int i = 0;
foreach (DataRow row in dt.Rows)
{
label5.Text += row[5].ToString();
label6.Text += row[6].ToString();
label7.Text += row[7].ToString();
label8.Text += row[8].ToString();
label9.Text += row[9].ToString();
label10.Text += row[10].ToString();
label11.Text += row[11].ToString();
break;
}

dt.Rows.Clear();


con.Close();


}
catch (Exception View_Load_e)
{
MessageBox.Show("Failed");
con.Close();
}
}
}
}



4-rasm
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.OleDb;
namespace Malika_Qaxramonova
{
public partial class New_User : Form
{
static string conString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='D:\Kurs ishi\Xodimlar\Xodimlar.accdb'";
OleDbConnection con = new OleDbConnection(conString);
OleDbCommand cmd;
OleDbDataAdapter adapter;
DataTable dt = new DataTable();

public string[] bolim_id = new string[20];


public string[] bolim_nomi = new string[20];
public New_User(string[] bolim_id, string[] bolim_nomi)
{
InitializeComponent();
this.bolim_id = bolim_id;
this.bolim_nomi = bolim_nomi;
for (int i = 0; i < this.bolim_id.Length; i++) {
try
{
comboBox1.Items.Add(this.bolim_nomi[i]);
}
catch (Exception er1) {
break;
}
}

}


private void New_User_Load(object sender, EventArgs e)
{
}

private void button1_Click(object sender, EventArgs e)


{
string sql = "insert into Xodim([familya], [ism], [Bolim_id], [lavozimi], [dushanba], [seshanba],[chorshanba],[payshanba],[juma],[shanba],[yakshanba]) values(@familya, @ism, @Bolim_id, @lavozimi, @dushanba, @seshanba, @chorshanba, @payshanba, @juma, @shanba, @yakshanba)";
cmd = new OleDbCommand(sql, con);
cmd.Parameters.AddWithValue("@familya", textBox1.Text);
cmd.Parameters.AddWithValue("@ism", textBox2.Text);
for (int i = 0; i < this.bolim_id.Length; i++)
{
if (this.bolim_nomi[i] == comboBox1.Text)
{
cmd.Parameters.AddWithValue("@Bolim_id", (this.bolim_id[i]));
break;
}
}
cmd.Parameters.AddWithValue("@lavozimi", textBox3.Text);
cmd.Parameters.AddWithValue("@dushanba", textBox4.Text);
cmd.Parameters.AddWithValue("@seshanba", textBox5.Text);
cmd.Parameters.AddWithValue("@chorshanba", textBox6.Text);
cmd.Parameters.AddWithValue("@payshanba", textBox7.Text);
cmd.Parameters.AddWithValue("@juma", textBox8.Text);
cmd.Parameters.AddWithValue("@shanba", textBox9.Text);
cmd.Parameters.AddWithValue("@yakshanba", textBox10.Text);

try
{


con.Open();

if (cmd.ExecuteNonQuery() > 0)


{
MessageBox.Show("Bazaga qo`shildi");
}

con.Close();


}
catch (Exception button1_Click_e)
{
MessageBox.Show(button1_Click_e.ToString());
con.Close();
}
this.tozalash();
}

private void button2_Click(object sender, EventArgs e)


{
this.tozalash();
this.Hide();
}

private void tozalash(){


textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
textBox10.Text = "";
comboBox1.Text = "";
}
}
}



5-rasm
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.OleDb;

namespace Malika_Qaxramonova


{
public partial class Edit_User : Form
{
static string conString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='D:\Kurs ishi\Xodimlar\Xodimlar.accdb'";
OleDbConnection con = new OleDbConnection(conString);
OleDbCommand cmd;
OleDbDataAdapter adapter;
DataTable dt = new DataTable();

public string id;


public string[] bolim_id = new string[20];
public string[] bolim_nomi = new string[20];
public string bolim_idsi = "";

private void read_xodim(){


string sql = "Select * from Xodim where [id]=" + this.id + "";
cmd = new OleDbCommand(sql, con);

try
{


con.Open();
adapter = new OleDbDataAdapter(cmd);
adapter.Fill(dt);
foreach (DataRow row in dt.Rows)
{
for (int i = 0; i < bolim_id.Length; i++)
{
if (row[3].ToString() == bolim_id[i])
{
comboBox1.Text = bolim_nomi[i];
break;
}
}
textBox1.Text = row[1].ToString();
textBox2.Text = row[2].ToString();
textBox3.Text = row[4].ToString();
textBox4.Text = row[5].ToString();
textBox5.Text = row[6].ToString();
textBox6.Text = row[7].ToString();
textBox7.Text = row[8].ToString();
textBox8.Text = row[9].ToString();
textBox9.Text = row[10].ToString();
textBox10.Text = row[11].ToString();
}

dt.Rows.Clear();


dt.Columns.Clear();
con.Close();
}
catch (Exception e1)
{
MessageBox.Show(e1.ToString());
con.Close();
}
}

public Edit_User(string id, string[] bolim_id, string[] bolim_nomi)


{
InitializeComponent();
this.id = id;
this.bolim_id = bolim_id;
this.bolim_nomi = bolim_nomi;
for (int i = 0; i < bolim_id.Length; i++)
{
try
{
comboBox1.Items.Add(this.bolim_nomi[i]);
}
catch (Exception Kitob_edit_e1)
{
break;
}
}
}

private void Edit_User_Load(object sender, EventArgs e)


{
this.read_xodim();
}

private void button1_Click(object sender, EventArgs e)


{
for (int i = 0; i < bolim_id.Length; i++)
{
try
{
if (this.bolim_nomi[i] == comboBox1.Text)
{
bolim_idsi = this.bolim_id[i];
break;
}
}
catch (Exception Kitob_edit_e1)
{
break;
}
}

string sql = "update Xodim set [familya]='" + textBox1.Text + "',[ism]='" + textBox2.Text + "',[Bolim_id]='" + bolim_idsi + "',[lavozimi]='" + textBox3.Text + "',[dushanba]='" + textBox4.Text + "',[seshanba]='" + textBox5.Text + "',[chorshanba]='" + textBox6.Text + "',[payshanba]='" + textBox7.Text + "',[juma]='" + textBox8.Text + "',[shanba]='" + textBox9.Text + "',[yakshanba]='" + textBox10.Text + "' where id=" + this.id + " ";


cmd = new OleDbCommand(sql, con);
try
{
con.Open();
if (cmd.ExecuteNonQuery() > 0)
{
MessageBox.Show("Muvaffaqiyatli");
}
con.Close();
}
catch (Exception button1_Click_e)
{
MessageBox.Show(button1_Click_e.ToString());
con.Close();
}
this.tozalash();
}

private void button2_Click(object sender, EventArgs e)


{
this.tozalash();
this.Hide();
}
private void tozalash()
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
textBox10.Text = "";
comboBox1.Text = "";
}
}
}


Yüklə 0,73 Mb.

Dostları ilə paylaş:
1   2   3   4   5   6   7   8   9




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©muhaz.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin