• 2.3 Tizimni ishlash jarayoni va undan foydalanish
  • Xulosa
  • II BOB. Amaliy qism 2.1. Tizimda foydalanilgan ma’lumotlar bazasi




    Download 0,49 Mb.
    bet9/10
    Sana26.05.2024
    Hajmi0,49 Mb.
    #254115
    1   2   3   4   5   6   7   8   9   10
    Bog'liq
    Talabalar bilimini baholash uchun test tizimi

    II BOB. Amaliy qism

    2.1. Tizimda foydalanilgan ma’lumotlar bazasi


    Men tizimni qurishda Sqlite ma’lumotlar bazasini boshqarish tizimidan foydalandim. Sababi Sqlite kichik dasturlar uchun samarali hisoblanadi va har qanday dasturlash tili bilan mos kela oladi deb o’ylayman. Sqlite jadvalni hosil qilish ancha oson hisoblanadi. Siz ustun nomalarini yozib ma’lumot turini belgilab saqlaysiz. Shunda sizga kerakli jadval hosil bo’ladi.
    Bu tizimni qurishda bitta jadvaldan foydalandim. Bu jadvalning sql kodi quyidagicha:
    CREATE TABLE "Test" (
    "Id" INTEGER NOT NULL,
    "Turi" VARCHAR(20),
    "Savol" VARCHAR(500),
    "JavobA" VARCHAR(500),
    "JavobB" VARCHAR(500),
    "JavobD" VARCHAR(500),
    "JavobE" VARCHAR(500),
    PRIMARY KEY("Id" AUTOINCREMENT)
    );







    2.2. Tizim interfeysini qurish


    Tizim interfeysini qurish uchun Visual Studio 22 dasturidan foydalanamiz.

    Yangi loyiha yaratamiz.

    Loyihamizga nom beramiz.




    2.3 Tizimni ishlash jarayoni va undan foydalanish


    Dasturda kodi quyidagicha:
    Bosh sahifa 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;
    namespace Talabalar_bilimini_baholash_uchun_test_tizimi
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }
    private void btnyaratish_Click(object sender, EventArgs e)
    {
    Test_yaratish test_Yaratish = new Test_yaratish();
    test_Yaratish.Show();
    this.Hide();
    }
    private void btnishlash_Click(object sender, EventArgs e)
    {
    Test_ishlash test_Ishlash = new Test_ishlash();
    test_Ishlash.Show();
    this.Hide();
    }
    }
    }
    Test yaratish oynasini kodi:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SQLite;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    namespace Talabalar_bilimini_baholash_uchun_test_tizimi
    {
    public partial class Test_yaratish : Form
    {
    int Tid;
    string path = "data_table.db";
    string cs = @"URI=file:" + Application.StartupPath + "\\data_table.db";
    public Test_yaratish()
    {
    InitializeComponent();
    }
    private void data_show(object sender, EventArgs e)
    {
    // DataGridView nomli obyektning ma'lumotlarini tozalash
    dataGridView.DataSource = null;
    dataGridView.Rows.Clear(); // Satrlarni o'chirish
    dataGridView.Columns.Clear(); // Ustunlarni o'chirish
    DataTable dataTable = new DataTable();
    using (SQLiteConnection connection = new SQLiteConnection(cs))
    {
    try
    {
    connection.Open();
    using (SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter("SELECT * FROM Test", connection))
    {
    dataAdapter.Fill(dataTable);
    dataGridView.DataSource = dataTable;
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show("Xatolik" + ex);
    }
    }
    }
    private void Jadval_yaratish()
    {
    if (!System.IO.File.Exists(path))
    {
    SQLiteConnection.CreateFile(path);
    using (var sqlite = new SQLiteConnection(@"Data Source=" + path))
    {
    sqlite.Open();
    string sql = "CREATE TABLE Test (Id INTEGER NOT NULL,Turi VARCHAR(20),Savol VARCHAR(500)," +
    "JavobA VARCHAR(500),JavobB VARCHAR(500),JavobD VARCHAR(500),JavobE VARCHAR(500),PRIMARY KEY(Id AUTOINCREMENT));";
    SQLiteCommand command = new SQLiteCommand(sql, sqlite);
    command.ExecuteNonQuery();
    }
    }
    }
    private void btnchiqish_Click(object sender, EventArgs e)
    {
    DialogResult Exit;
    Exit = MessageBox.Show("Chiqishni xohlasangiz, tasdiqlang!!!", "Talabalar bilimini baholash uchun test tizimi",
    MessageBoxButtons.YesNo, MessageBoxIcon.Information);
    if (Exit == DialogResult.Yes)
    {
    Application.Exit();
    }
    }
    private void btntozalash_Click(object sender, EventArgs e)
    {
    cmbturi.Text = "";
    txtsavol.Clear();
    txtA.Clear();
    txtB.Clear();
    txtD.Clear();
    txtE.Clear();
    }
    private void btnorqaga_Click(object sender, EventArgs e)
    {
    Form1 form1 = new Form1();
    form1.Show();
    this.Hide();
    }
    private void btnsaqlash_Click(object sender, EventArgs e)
    {
    try
    {
    if (txtsavol.Text!="")
    {
    using (var con = new SQLiteConnection(cs))
    {
    con.Open();
    var cmd = new SQLiteCommand(con);
    cmd.CommandText = "INSERT INTO Test (Turi,Savol,JavobA,JavobB,JavobD,JavobE)" +
    "VALUES (@Turi,@Savol,@JavobA,@JavobB,@JavobD,@JavobE)";
    cmd.Parameters.AddWithValue("@Turi",cmbturi.Text);
    cmd.Parameters.AddWithValue("@Savol",txtsavol.Text);
    cmd.Parameters.AddWithValue("@JavobA",txtA.Text);
    cmd.Parameters.AddWithValue("@JavobB", txtB.Text);
    cmd.Parameters.AddWithValue("@JavobD", txtD.Text);
    cmd.Parameters.AddWithValue("@JavobE", txtE.Text);
    cmd.ExecuteNonQuery();
    }
    data_show(null, null);
    btntozalash_Click(btntozalash, null);
    }
    else
    MessageBox.Show("Ma'lumotlar to'liq va to'g'ri kiritilganligini tekshiring!");
    }
    catch (Exception ex)
    {
    // Xatolikni boshqarish (masalan, foydalanuvchiga xabar yuborish orqali)
    MessageBox.Show("Xatolik yuz berdi: " + ex.Message);
    }
    }
    private void btnuchirish_Click(object sender, EventArgs e)
    {
    try
    {
    if (dataGridView.SelectedRows.Count != 1)
    {
    MessageBox.Show("Qatorni tanlang!");
    return;
    }
    using (var con = new SQLiteConnection(cs))
    {
    con.Open();
    var cmd = new SQLiteCommand(con);
    DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
    // "ID" ustunining qiymatini olish (agar "ID" ustuni mavjud bo'lsa)
    int Id = Convert.ToInt32(selectedRow.Cells["Id"].Value);
    cmd.CommandText = "DELETE FROM Test WHERE Id = @Id";
    cmd.Parameters.AddWithValue("@Id", Id);
    cmd.ExecuteNonQuery();
    cmd.Dispose();
    }
    data_show(null, null);
    }
    catch (Exception ex)
    {
    // Xatolikni boshqarish (masalan, foydalanuvchiga xabar yuborish orqali)
    MessageBox.Show("Xatolik yuz berdi: " + ex.Message);
    }
    }
    private void btnyangilash_Click(object sender, EventArgs e)
    {
    try
    {
    if (txtsavol.Text!="")
    {
    using (var con = new SQLiteConnection(cs))
    {
    con.Open();
    var cmd = new SQLiteCommand(con);
    cmd.CommandText = "UPDATE Test SET Turi = @Turi, Savol=@Savol," +
    "JavobA=@JavobA,JavobB=@JavobB,JavobD=@JavobD,JavobE=@JavobE WHERE Id=@Id";
    cmd.Parameters.AddWithValue("@Turi", cmbturi.Text);
    cmd.Parameters.AddWithValue("@Savol", txtsavol.Text);
    cmd.Parameters.AddWithValue("@JavobA", txtA.Text);
    cmd.Parameters.AddWithValue("@JavobB", txtB.Text);
    cmd.Parameters.AddWithValue("@JavobD", txtD.Text);
    cmd.Parameters.AddWithValue("@JavobE", txtE.Text);
    cmd.Parameters.AddWithValue("@Id", Tid);
    cmd.ExecuteNonQuery();
    cmd.Dispose();
    data_show(null, null);
    }
    }
    else
    MessageBox.Show("Ma'lumotlar to'liq va to'g'ri kiritilganligini tekshiring!");
    }
    catch (Exception ex)
    {
    // Xatolikni boshqarish (masalan, foydalanuvchiga xabar yuborish orqali)
    MessageBox.Show("Xatolik yuz berdi: " + ex.Message);
    }
    }
    private void Test_yaratish_Load(object sender, EventArgs e)
    {
    Jadval_yaratish();
    data_show(null,null);
    }
    private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
    if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
    {
    dataGridView.CurrentRow.Selected = true;
    Tid = int.Parse(cmbturi.Text = dataGridView.Rows[e.RowIndex].Cells["Id"].FormattedValue.ToString());
    cmbturi.Text = dataGridView.Rows[e.RowIndex].Cells["Turi"].FormattedValue.ToString();
    txtsavol.Text = dataGridView.Rows[e.RowIndex].Cells["Savol"].FormattedValue.ToString();
    txtA.Text = dataGridView.Rows[e.RowIndex].Cells["JavobA"].FormattedValue.ToString();
    txtB.Text = dataGridView.Rows[e.RowIndex].Cells["JavobB"].FormattedValue.ToString();
    txtD.Text = dataGridView.Rows[e.RowIndex].Cells["JavobD"].FormattedValue.ToString();
    txtE.Text = dataGridView.Rows[e.RowIndex].Cells["JavobE"].FormattedValue.ToString();
    }
    }
    private void cmbturi_SelectedIndexChanged(object sender, EventArgs e)
    {
    if (cmbturi.SelectedIndex == 0)
    {
    labelA.Text = "A javob:";
    txtA.Visible = true;
    labelB.Visible = true;
    txtB.Visible = true;
    labelD.Visible = true;
    txtD.Visible = true;
    labelE.Visible = true;
    txtE.Visible = true;
    }
    if (cmbturi.SelectedIndex==1)
    {
    labelA.Text = "To'g'ri javob:";
    labelB.Visible = false;
    txtB.Visible = false;
    labelD.Visible = false;
    txtD.Visible = false;
    labelE.Visible = false;
    txtE.Visible = false;
    }
    }
    }
    }
    Test ishlash uchun oyna kodi:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Data.SQLite;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    namespace Talabalar_bilimini_baholash_uchun_test_tizimi
    {
    public partial class Test_ishlash : Form
    {
    SQLiteConnection sqlConnection;
    string connectionstring= @"URI=file:" + Application.StartupPath + "\\data_table.db";
    SQLiteDataReader reader;
    string[,] savollar;
    int questNumber = 0;
    public Test_ishlash()
    {
    InitializeComponent();
    sqlConnection = new SQLiteConnection(connectionstring);
    if (sqlConnection.State != ConnectionState.Open)
    sqlConnection.Open();
    ConState.Text = "status: "+sqlConnection.State.ToString();
    savollar = new string[0,0];
    bazadanolish();
    if (savollar.Length > 0)
    SetAnswers();
    else
    MessageBox.Show("SAVOLLAR MAVJUD EMAS YOKI DASTUR XATOLIGI");
    }
    private void button1_Click(object sender, EventArgs e)
    {
    //string[,] a = addrow();
    RadioButton[] answer = { Ajavob, Bjavob, Cjavob, Djavob };
    for(int i = 0;iif (answer[i].Checked)
    if (answer[i].Text == savollar[questNumber,2])
    {
    // to'g'ri javob berilgan
    }
    questNumber++;
    if(questNumber < savollar.Length / 6)
    {
    SetAnswers();
    }
    else
    {
    /// natija chiqarish uchun
    }
    }
    public void bazadanolish()
    {
    using (SQLiteCommand cmd = sqlConnection.CreateCommand())
    {
    string cmdstring = "SELECT * FROM Test;";
    cmd.CommandText = cmdstring;
    reader = cmd.ExecuteReader();
    string[] val=new string[6];
    while (reader.Read())
    {
    if (!reader.IsDBNull(0))
    {
    for (int i = 0; i < val.Length; i++)
    val[i] = reader.GetString(i + 1);
    savollar = addrow(savollar, val);
    }

    else
    break;


    }
    }
    }
    public string[,] addrow(string[,] pre, string[] val)
    {
    int len = pre.Length/6;
    string[,] next = new string[len + 1, 6];
    for (int i = 0; i < len; i++)
    for (int j = 0; j < 6; j++)
    next[i, j] = pre[i, j];
    for (int i = 0; i < 6; i++)
    next[len, i] = val[i];
    return next;
    }
    public void SetAnswers()
    {
    if (savollar[questNumber,0]=="Ochiq test")
    {
    int[] num = { 2, 3, 4, 5 };
    for (int i = 0;i < 10; i++)
    {
    int x=(new Random()).Next(0,4);
    int y = num[x];
    num[x] = num[i%4];
    num[i%4] = y;
    }
    Savol.Text = savollar[questNumber, 1];
    Ajavob.Text = savollar[questNumber, num[0]];
    Bjavob.Text = savollar[questNumber, num[1]];
    Cjavob.Text = savollar[questNumber, num[2]];
    Djavob.Text = savollar[questNumber, num[3]];
    }
    else
    {
    }
    }
    private void Ajavob_CheckedChanged(object sender, EventArgs e)
    {
    button1.Enabled = true;
    }
    private void Test_ishlash_Load(object sender, EventArgs e)
    {
    }
    }
    }


    Xulosa


    Men amaliyot davrida juda ko’plab turli tuman ma’lumotlarga duch keldim. Men o’rganish kerak bo’lgan ma’lumotlarni uchratdim. Men bundan keyin o’z bilimimni boyitib borishga harakat qilaman .Men uzimga berilgan topshiriqlarni bajarish davomida OOP texnalogiyalari haqida ko’nikmaga ega bo’ldim. Men keyinchalik tuzgan dasturimni yanada mukammal qilishga harakat qilaman. Buning uchun men keyingi kurslarda ko’proq ma’lumotlarni ko’proq mukammal o’rganishga harakat qilaman . Ta’lim jarayonida olib boriladigan barcha kompyuter jarayonlari raqamli shaklda amalga oshiriladi, bu turli xil talabalar ma’lumotlari va hujjatlarini kiritish, qayta ishlash va saqlashni ancha osonlashtiradi va samaraliroq qiladi. Masalan, har qanday tayyor hujjatdan kiritilgan ma’lumotlarni turli formatlarda import qilish orqali ma’lumotlarni osongina kiritishingiz mumkin. Hujjatlar va shablonlarni avtomatik ravishda to’ldirish va shakllantirish nafaqat vaqtni bo’shatish, balki turli xil ta’sir omillarini hisobga olgan holda, xodimlardan farqli o’laroq, xatosiz ma’lumotlarni kiritish imkonini beradi. Tezkor qidiruv qog’ozli hujjatlardan farqli o’laroq, kerakli ma’lumotlarni bir necha soniya ichida topishga imkon beradi. Shuni ta’kidlash kerakki, qog’ozlar yaxshi yonadi, siyoh o’chadi va hujjatlar osongina yo’qoladi va raqamli axborot vositalarida ma’lumotlarning saqlanib turishi ma’lumotlarning doimiy zaxirasi tufayli ko’p yillar davomida hujjatlar xavfsizligini ta’minlaydi. Hozirgi kunda mamlakatimizda juda katta tezlik bilan elektron ma’lumotlar bazasi shakllantirilmoqda va shu borada samarali ishlar ham olib borilmoqda. Har bir sohada kompyuter texnologiyalaridan oqilona va to’laqonli foydalanilmoqda. Kurs ishida ‘‘Talabalar bilimini baholash uchun test tizimi’’ dasturi haqida ma’lumot berilgan. Bu dasturni tuzishda men ko’plab bilimlarga ega bo’ldim desam mubolag’a bo’lmaydi. Masalan, ToolBoxda mavjud bo’lmagan ya’ni doim ham bizga ko’rinib turavermaydigan komponentalarni qanday topish va ulardan foydalanish usullarini, Button, TextBox, Label, ComboBox, Panel, RichtextBox, DataGridview va shu kabi ko’plab komponentalardan foydalanishda yaxshigina tajribaga ega bo’ldim. Bundan tashqari C# dasturlash tili tarixi haqida ham

    Download 0,49 Mb.
    1   2   3   4   5   6   7   8   9   10




    Download 0,49 Mb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    II BOB. Amaliy qism 2.1. Tizimda foydalanilgan ma’lumotlar bazasi

    Download 0,49 Mb.