Iv modul uchun topshiriq


Download 278.43 Kb.
Sana06.05.2023
Hajmi278.43 Kb.
#1434109
Bog'liq
Algoritm amaliy4 (2)


IV modul uchun topshiriq.
Har bir talaba kurs ishi mavzusidan kelib chiqqan holda amaliy topshiriq bajaradi. Ushbu topshiriq bo‘yicha quyidagi ko‘rsatmalar bajarilishi kerak:
1.Ma’lumotlar bazasini yaratish. 2.Ma’lumotlar bazasida 4 tadan kam bo‘lmagan jadvallar yaratish(jadvallar o‘zaro bir biri bilan bog‘lanish hosil qilishi uchun ularni tuzilishiga e’tibor qarating).
Topshiriq bajarilishi davomida loyihangiz videotavsifini tayyorlang va o‘qituvchiga topshiring. Tayyorlagan videotavsif video darlik sifatida xizmat qilsin. Loyiha skreenshotlarini pdf shakliga keltirib HEMIS tizimiga yuklang.
Dastur kodi:
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 Amaliy_creade
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}


SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\hp\source\repos\Amaliy_creade\Amaliy_creade\Database1.mdf;Integrated Security=True");


private void Form1_Load(object sender, EventArgs e)
{
Display();
}
private void Display()
{
conn.Open();
string query = "SELECT * FROM Person LEFT JOIN Viloyat ON Viloyat.Id=Person.Viloyat.Id LEFT JOIN Tuman ON Tuman.Id=Person.Tuman.Id";
SqlDataAdapter sda = new SqlDataAdapter(query, conn);
SqlCommandBuilder build = new SqlCommandBuilder(sda);
var ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
conn.Close();
}
private void button1_Click(object sender, EventArgs e)
{
}
int id;
private void button2_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value);
textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
textBox2.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
textBox3.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
}
void Clear()
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}


private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{


}


private void button1_Click_1(object sender, EventArgs e)
{
conn.Open();
string query = "INSERT INTO Person (Name,Age,Number) VALUES ('" + textBox1.Text + "','" + textBox2.Text + "','"+ textBox3.Text+ "')";
SqlCommand cmd = new SqlCommand(query, conn);


cmd.ExecuteNonQuery();
MessageBox.Show("Ma'lumot kiritildi", "Insert");
conn.Close();
Display();
Clear();
}


private void button2_Click_1(object sender, EventArgs e)
{
conn.Open();
string query = "UPDATE Person SET Name='" + textBox1.Text + "', Age='" + textBox2.Text + "'+ Number='"+textBox3.Text+"' where id='" + id + "'";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
MessageBox.Show("Ma'lumot tahrirlandi", "Update");
conn.Close();
Display();
Clear();
}


private void button3_Click_1(object sender, EventArgs e)
{
conn.Open();
string query = "DELETE FROM Person WHERE id='" + id + "'";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
MessageBox.Show("Ma'lumot o'chirildi", "Delete");
conn.Close();
Display();
Clear();
}






Download 278.43 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling