Tolovlar.cs.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Npgsql;
namespace Boqcha1
{
public partial class Tolovlar : MetroFramework.Forms.MetroForm
{
public Tolovlar()
{
InitializeComponent();
}
private static string Host = "localhost";
private static string User = "postgres";
private static string DBname = "Boqcha";
private static string Password = "1234";
private static string Port = "5432";
string connString = String.Format(
"Server={0}; Username={1}; Database={2}; Port={3}; Password={4}; SSLMode=Prefer",
Host,
User,
DBname,
Port,
Password);
private NpgsqlConnection conn;
private NpgsqlCommand cmd;
private string sql = null;
private DataTable dt;
string login = "";
int ind = 0,ind4 = 0,ind3 = 0;
private void tabPage3_Click(object sender, EventArgs e)
{
}
private void metroTabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void tabPage1_Click(object sender, EventArgs e)
{
}
private void label11_Click(object sender, EventArgs e)
{
}
private void Tolovlar_Load(object sender, EventArgs e)
{
conn = new NpgsqlConnection(connString);
// admin1 jadvalini dataGridView1 ga chiqarish
conn.Open();
sql = @"select *from admin1";
cmd = new NpgsqlCommand(sql , conn);
cmd.ExecuteNonQuery();
dt = new DataTable();
dt.Load(cmd.ExecuteReader());
conn.Close();
dataGridView1.DataSource = null;
dataGridView1.DataSource = dt;
// To'lo' tizimi
conn.Open();
sql = @"select ism,familya,ustoz,tolov,tel from boqcha1";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
dt = new DataTable();
dt.Load(cmd.ExecuteReader());
conn.Close();
dataGridView2.DataSource = null;
dataGridView2.DataSource = dt;
// To'lo' tizimi
conn.Open();
sql = @"select *from ustoz";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
dt = new DataTable();
dt.Load(cmd.ExecuteReader());
conn.Close();
dataGridView4.DataSource = null;
dataGridView4.DataSource = dt;
// To'lo'v tizimi
conn.Open();
sql = @"select ism,familya,yosh,ustoz,tel from boqcha1";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
dt = new DataTable();
dt.Load(cmd.ExecuteReader());
conn.Close();
dataGridView3.DataSource = null;
dataGridView3.DataSource = dt;
}
private void button16_Click(object sender, EventArgs e)
{
new Login().Show();
this.Hide();
}
private void button15_Click(object sender, EventArgs e)
{
new Boqcha().Show();
this.Hide();
}
private void button1_Click(object sender, EventArgs e)
{
// qo'shish
string log = textBox1.Text;
string par = textBox2.Text;
try
{
if(!log.Equals("") && !par.Equals(""))
{
conn.Open();
sql = @"insert into admin1(login,parol) values('" + log + "','" + par + "')";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Close();
textBox1.Text = "";
textBox2.Text = "";
conn.Open();
sql = @"select *from admin1";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
dt = new DataTable();
dt.Load(cmd.ExecuteReader());
conn.Close();
dataGridView1.DataSource = null;
dataGridView1.DataSource = dt;
}
else
{
MessageBox.Show("Maydonlarni to'ldiring!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show("Baza bilan bog'lanishda xatolik!!!"+ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
private void dataGridView1_Click(object sender, EventArgs e)
{
// dataGridView1 cklick bo'lganda
int index = dataGridView1.CurrentRow.Index;
if (index > -1)
{
ind = 1;
textBox1.Text = dataGridView1.Rows[index].Cells["login"].Value.ToString();
login = dataGridView1.Rows[index].Cells["login"].Value.ToString();
textBox2.Text = dataGridView1.Rows[index].Cells["parol"].Value.ToString();
button1.Enabled = false;
}
}
private void button2_Click(object sender, EventArgs e)
{
// tahirlash button2
if (ind == 1)
{
button1.Enabled = true;
ind = 0;
conn.Open();
sql = @"update admin1 set login='" + textBox1.Text + "', parol='" + textBox2.Text + "' where login='" + login + "'";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Close();
textBox1.Text = "";
textBox2.Text = "";
conn.Open();
sql = @"select *from admin1";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
dt = new DataTable();
dt.Load(cmd.ExecuteReader());
conn.Close();
dataGridView1.DataSource = null;
dataGridView1.DataSource = dt;
}
else
{
MessageBox.Show("Satrni tanlang!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button3_Click(object sender, EventArgs e)
{
// delete
if (ind == 1)
{
button1.Enabled = true;
ind = 0;
conn.Open();
sql = @"delete from admin1 where login='"+login+"'";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Close();
textBox1.Text = "";
textBox2.Text = "";
conn.Open();
sql = @"select *from admin1";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
dt = new DataTable();
dt.Load(cmd.ExecuteReader());
conn.Close();
dataGridView1.DataSource = null;
dataGridView1.DataSource = dt;
}
else
{
MessageBox.Show("Satrni tanlang!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
}
private void dataGridView2_Click(object sender, EventArgs e)
{
// dataGridView2 cklick bo'lganda
int index = dataGridView2.CurrentRow.Index;
if (index > -1)
{
textBox4.Text = dataGridView2.Rows[index].Cells["ism"].Value.ToString();
textBox3.Text = dataGridView2.Rows[index].Cells["familya"].Value.ToString();
textBox5.Text = dataGridView2.Rows[index].Cells["ustoz"].Value.ToString();
textBox6.Text = dataGridView2.Rows[index].Cells["tolov"].Value.ToString();
textBox15.Text = dataGridView2.Rows[index].Cells["tel"].Value.ToString();
}
}
private void button5_Click(object sender, EventArgs e)
{
textBox4.Text = "";
textBox3.Text = "";
textBox5.Text = "";
textBox6.Text = "";
}
private void button7_Click(object sender, EventArgs e)
{
string ism2 = textBox4.Text;
string fam2 = textBox3.Text;
string ustoz2 = textBox5.Text;
string tolov2 = textBox6.Text;
string tel2 = textBox15.Text;
try
{
if(!ism2.Equals("") && !fam2.Equals("") && !ustoz2.Equals("") && !tolov2.Equals("") && !tel2.Equals(""))
{
conn.Open();
sql = @"update boqcha1 set tolov='" + tolov2 + "' where tel = '"+tel2+"'";
cmd = new NpgsqlCommand(sql,conn);
cmd.ExecuteNonQuery();
conn.Close();
textBox4.Text = "";
textBox3.Text = "";
textBox5.Text = "";
textBox6.Text = "";
conn.Open();
sql = @"select ism,familya,ustoz,tolov from boqcha1";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
dt = new DataTable();
dt.Load(cmd.ExecuteReader());
conn.Close();
dataGridView2.DataSource = null;
dataGridView2.DataSource = dt;
}
}catch(Exception ex)
{
MessageBox.Show("Baza bilan bog'lanishda xatolik!!!" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button12_Click(object sender, EventArgs e)
{
string ism3 = textBox14.Text;
string fam3 = textBox13.Text;
string tel3 = textBox12.Text;
if (ind4 == 1)
{
conn.Open();
sql = @"delete from ustoz where tel='"+tel3+"'";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Close();
textBox14.Text = "";
textBox13.Text = "";
textBox12.Text = "";
conn.Open();
sql = @"select *from ustoz";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
dt = new DataTable();
dt.Load(cmd.ExecuteReader());
conn.Close();
dataGridView4.DataSource = null;
dataGridView4.DataSource = dt;
ind4 = 0;
button14.Enabled = true;
}
else
{
MessageBox.Show("Satrni tanlang!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button14_Click(object sender, EventArgs e)
{
// ustoz qo'shish
string ism3 = textBox14.Text;
string fam3 = textBox13.Text;
string tel3 = textBox12.Text;
try
{
if(!ism3.Equals("") && !fam3.Equals("") && !tel3.Equals(""))
{
conn.Open();
sql = @"insert into ustoz(ism,familya,tel) values('"+ism3+"','"+fam3+"','"+tel3+"')";
cmd = new NpgsqlCommand(sql,conn);
cmd.ExecuteNonQuery();
conn.Close();
textBox14.Text = "";
textBox13.Text = "";
textBox12.Text = "";
conn.Open();
sql = @"select *from ustoz";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
dt = new DataTable();
dt.Load(cmd.ExecuteReader());
conn.Close();
dataGridView4.DataSource = null;
dataGridView4.DataSource = dt;
}
else
{
MessageBox.Show("Maydonlarni to'ldiring!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch(Exception ex)
{
MessageBox.Show("Baza bilna bog'lanishda xatolik!!!" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button11_Click(object sender, EventArgs e)
{
textBox14.Text = "";
textBox13.Text = "";
textBox12.Text = "";
ind4 = 0;
button14.Enabled = true;
}
private void button13_Click(object sender, EventArgs e)
{
string ism3 = textBox14.Text;
string fam3 = textBox13.Text;
string tel3 = textBox12.Text;
try
{
if (!ism3.Equals("") && !fam3.Equals("") && !tel3.Equals(""))
{
conn.Open();
sql = @"update ustoz set ism = '"+ism3+"',familya = '"+fam3+"', tel = '"+tel3+"' where tel='"+tel3+"'";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Close();
textBox14.Text = "";
textBox13.Text = "";
textBox12.Text = "";
conn.Open();
sql = @"select *from ustoz";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
dt = new DataTable();
dt.Load(cmd.ExecuteReader());
conn.Close();
dataGridView4.DataSource = null;
dataGridView4.DataSource = dt;
ind4 = 0;
button14.Enabled = true;
}
else
{
MessageBox.Show("Maydonlarni to'ldiring!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show("Baza bilna bog'lanishda xatolik!!!" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button9_Click(object sender, EventArgs e)
{
string ism3 = textBox8.Text;
string fam3 = textBox7.Text;
string yosh3 = textBox9.Text;
string ustoz3 = textBox10.Text;
string tel3 = textBox11.Text;
try
{
if (!ism3.Equals("") && !fam3.Equals("") )
{
if (ind3 == 1)
{
conn.Open();
sql = @"update boqcha1 set ism = '" + ism3 + "',familya = '" + fam3 + "' where tel='" + tel3 + "'";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Close();
textBox8.Text = "";
textBox7.Text = "";
textBox11.Text = "";
textBox10.Text = "";
textBox9.Text = "";
conn.Open();
sql = @"select ism,familya,yosh,ustoz,tel from boqcha1";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
dt = new DataTable();
dt.Load(cmd.ExecuteReader());
conn.Close();
dataGridView3.DataSource = null;
dataGridView3.DataSource = dt;
}
else
{
MessageBox.Show("Satrni tanlang!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("Maydonlarni to'ldiring!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show("Baza bilna bog'lanishda xatolik!!!" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button8_Click(object sender, EventArgs e)
{
string ism3 = textBox8.Text;
string fam3 = textBox7.Text;
string yosh3 = textBox9.Text;
string ustoz3 = textBox10.Text;
string tel3 = textBox1.Text;
try
{
if (!ism3.Equals("") && !fam3.Equals("") && !yosh3.Equals("") && !ustoz3.Equals("") && !textBox1.Text.Equals(""))
{
conn.Open();
sql = @"delete from boqcha1 where tel='" + tel3 + "'";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Close();
textBox14.Text = "";
textBox13.Text = "";
textBox12.Text = "";
textBox1.Text = "";
conn.Open();
sql = @"select *from ustoz";
cmd = new NpgsqlCommand(sql, conn);
cmd.ExecuteNonQuery();
dt = new DataTable();
dt.Load(cmd.ExecuteReader());
conn.Close();
dataGridView4.DataSource = null;
dataGridView4.DataSource = dt;
ind4 = 0;
button14.Enabled = true;
}
else
{
MessageBox.Show("Satrni tanlang!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show("Baza bilna bog'lanishda xatolik!!!" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void label2_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void dataGridView3_Click(object sender, EventArgs e)
{
// tebil 3
int index = dataGridView3.CurrentRow.Index;
if (index > -1)
{
ind3 = 1;
textBox8.Text = dataGridView3.Rows[index].Cells["ism"].Value.ToString();
textBox7.Text = dataGridView3.Rows[index].Cells["familya"].Value.ToString();
textBox11.Text = dataGridView3.Rows[index].Cells["tel"].Value.ToString();
textBox9.Text = dataGridView3.Rows[index].Cells["yosh"].Value.ToString();
textBox10.Text =
dataGridView3.Rows[index].Cells["ustoz"].Value.ToString();
}
}
private void dataGridView4_Click(object sender, EventArgs e)
{
int index = dataGridView4.CurrentRow.Index;
if (index > -1)
{
button14.Enabled = false;
ind4 = 1;
textBox14.Text = dataGridView4.Rows[index].Cells["ism"].Value.ToString();
textBox13.Text = dataGridView4.Rows[index].Cells["familya"].Value.ToString();
textBox12.Text = dataGridView4.Rows[index].Cells["tel"].Value.ToString();
}
}
}
}
|