II. Asosiy qism - Kompyuter injiniringi” fakulteti,,Kompyuter injiniring at-servis” yo'nalishi 106-21 guruh talabasi...

|
Kompyuter injiniringi” fakulteti,,Kompyuter injiniring at-servis” yo'nalishi 106-21 guruh talabasi Saparbaev Azizbekning
|
bet | 6/9 | Sana | 02.06.2024 | Hajmi | 1,82 Mb. | | #259242 |
Bog'liq SapaII. Asosiy qism
Bu loyihada eng avvalo jamiyat uchun yangicha talqin hisoblanadi. Jamiyatdagi xalq uchun yangilik desak ham bo’ladi. Chunkiy oldinlari biror joyga borish uchun bilet olish uchun vakzalga borib kassaga uchrak kerak edi. Bundan tashqari u yerda navbat kutish kerak bo’lardi. Bu sayt shunday qulayliklarga egaki,bu saytdan siz ham bilet bron qilibgina qomasdan, uydan chiqmagan holda qayerga qachon bilet borligini, bilet narxlarini qandayligini bilishiz mumkin.
Bu loyiha asosan vakzaldagi kassachilarni ishini ancha yengillashtiradi, vaqtini tejaydi va asosiysi ortiqcha qog`ozbozlikka chek qo`yadi.
Dasturga kirganimizda birinchi bo`lib maxfiylikni ta’minlash va begona shaxslar dasturga kirib ma’lumotlarni o`zgartirishiga yo`l qo`ymaslik maqsadida bizdan login va parol so`raladi:
Login va parolni kiritamiz hamda Kirish tugmasini bosamiz. Parolni ham maxfiy saqlash maqsadida Textboxning UseSystemPasportChar xususiyatidan foydalanildi. Agar login yoki parolni xato kiritsak quyidagi oyna paydo bo`ladi:
Shundan so`ng bizda ma’lumotlarni kiritsh oynasi paydo bo`ladi..
Bu oynada ma’lumotlari kiritamiz. Barcha ma’lumotlarni kiritib bo`lgach Saqlash tugmasini bosamiz. Shunda barcha ma`lumotlar bazada saqlanadi va DataGridView da paydo bo`ladi. Buning uchun Saqlash tugmasiga quyidagicha kod yozdim:
public partial class PassengerMaster : Form
{
public PassengerMaster()
{
InitializeComponent();
populate();
}
private SqlConnection Con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\User\Documents\RailwaysDb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
private void populate()
{
Con.Open();
string query = "select * from PASSENGERTBL";
SqlDataAdapter sda = new SqlDataAdapter(query, Con);
var ds = new DataSet();
sda.Fill(ds);
PassengerDGV.DataSource = ds.Tables[0];
Con.Close();
}
private void button1_Click(object sender, EventArgs e)
{
string Gender = "";
if (PnameTb.Text == "" || PPhoneTb.Text == ""||PaddressTb.Text == "")
{
MessageBox.Show("Missing information");
}
else
{
if (MaleRd.Checked == true)
{
Gender = "Male";
}
else if (FemaleRd.Checked == true)
{
Gender = "Female";
}
try
{
Con.Open();
string Query = "insert into PASSENGERTBL values('" + PnameTb.Text + "'," + PaddressTb.Text + ",'" + Gender + "','"+NatCb.SelectedItem.ToString()+"','"+PPhoneTb.Text+"')";
SqlCommand cmd = new SqlCommand(Query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Passenger Added Successfully");
Con.Close();
populate();
Reset();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
}
int key = 0;
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
textBox1.Text = PassengerDGV.SelectedRows[0].Cells[1].Value.ToString();
textBox2.Text = PassengerDGV.SelectedRows[0].Cells[2].Value.ToString();
NatCb.SelectedItem = PassengerDGV.SelectedRows[0].Cells[4].Value.ToString();
textBox3.Text = PassengerDGV.SelectedRows[0].Cells[5].Value.ToString();
if (PnameTb.Text == "")
{
key = 0;
}
else
{
key = Convert.ToInt32(PassengerDGV.SelectedRows[0].Cells[0].Value.ToString());
}
}
private void Reset()
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
MaleRd.Checked = false;
FemaleRd.Checked = false;
NatCb.SelectedIndex = -1;
key = 0;
}
private void button4_Click(object sender, EventArgs e)
{
Reset();
}
private void button3_Click(object sender, EventArgs e)
{
if (key == 0)
{
MessageBox.Show("Select The Passenger To Be Deleted");
}
else
{
try
{
Con.Open();
string Query = "Delete from PASSENGERTBL where PId=" + key + "";
SqlCommand cmd = new SqlCommand(Query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Passenger Deleted Successfully");
Con.Close();
populate();
Reset();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
}
private void button2_Click(object sender, EventArgs e)
{
string Gender = "";
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
{
MessageBox.Show("Missing information");
}
else
{
if (MaleRd.Checked == true)
{
Gender = "Male";
}
else if (FemaleRd.Checked == true)
{
Gender = "Female";
}
try
{
Con.Open();
string Query = "update PASSENGERTBL set Pname='" + textBox1.Text + "',PAdd="+textBox2.Text + ", PGender='" + Gender + "',PNat='"+NatCb.SelectedItem.ToString()+"',PPhone ='"+textBox3.Text+"' where PId=" + key + ";";
SqlCommand cmd = new SqlCommand(Query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Passenger Updated Successfully");
Con.Close();
populate();
Reset();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}
}
private void MaleRd_CheckedChanged(object sender, EventArgs e)
{
}
private void label7_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button5_Click(object sender, EventArgs e)
{
Form2 Main = new Form2();
Main.Show();
this.Hide();
}
}
}
|
|
Bosh sahifa
Aloqalar
Bosh sahifa
Kompyuter injiniringi” fakulteti,,Kompyuter injiniring at-servis” yo'nalishi 106-21 guruh talabasi Saparbaev Azizbekning
|