Algoritmik tillar va dasturlash


Bosh oyna forma kodi. Panelga kerakli formani chaqirish



Yüklə 1,81 Mb.
səhifə7/7
tarix27.07.2023
ölçüsü1,81 Mb.
#137677
1   2   3   4   5   6   7
boldidaaaaa

Bosh oyna forma kodi. Panelga kerakli formani chaqirish
//panelda boshqa bo'limini ko'rish u-n cod
private Form activeForm = null;
//kerakli tugma bosilganda panelga yangi formani chaqirish f-yasi
private void openchildForm(Form ChildForm)
{
if (activeForm != null)
activeForm.Close();
activeForm = ChildForm;
ChildForm.TopLevel = false;
ChildForm.FormBorderStyle = FormBorderStyle.None;
ChildForm.Dock = DockStyle.Fill;
panel_main.Controls.Add(ChildForm);
panel_main.Tag = ChildForm;
ChildForm.BringToFront();
ChildForm.Show();

}
//O'qituvchilar formasini ochish tugmasi


private void button_teacher_Click(object sender, EventArgs e)
{
//tugam bosiolganda qaysi oynani ochish kodi
openchildForm(new Teach_Form()); }


DataGridView ga malumot chiqaruvchi funksiya
public void yuklash()
{
try
{
Con.Open();
string query = "select * from [Teacher] ";
SqlDataAdapter da = new SqlDataAdapter(query, Con);
SqlCommandBuilder builder = new SqlCommandBuilder(da);
var ds = new DataSet();
da.Fill(ds);
DGV_teacher.DataSource = ds.Tables[0];
Con.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//saqlash tugmasi
private void button_saqla_Click(object sender, EventArgs e)
{
try
{
if (textBox1_Ism.Text == "" && textBox_mut.Text == "" && S=="" && textBox_Oy.Text == "" && textBox_Raz.Text == "" && textBox_yosh.Text == "")
{
MessageBox.Show(" Ma'lumotlar to'liq emas !!!!!! ");
}
else
{

Con.Open();


SqlCommand cmd = new SqlCommand("insert into [Teacher] values(@Id,@FISH,@Jins,@yosh,@oylik,@Razryad,@Mut_nom) ", Con);
cmd.Parameters.AddWithValue("@Id", Convert.ToInt32(textBox_Id.Text));
cmd.Parameters.AddWithValue("@FISH", textBox1_Ism.Text);
cmd.Parameters.AddWithValue("@Jins", S);
cmd.Parameters.AddWithValue("@yosh", Convert.ToInt32(textBox_yosh.Text));
cmd.Parameters.AddWithValue("@oylik", textBox_Oy.Text);
cmd.Parameters.AddWithValue("@Razryad", textBox_Raz.Text);
cmd.Parameters.AddWithValue("@Mut_nom", textBox_mut.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("Ma'lumotlar saqlandi");
Con.Close();
yuklash();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
Con.Close();
}
}

//O'chirish tugmasi


private void button_ochir_Click(object sender, EventArgs e)
{
try
{
if (MessageBox.Show("Xaqiqatdan Ham shu malumotni O'chirishni hohlaysizmi","Diqqat", MessageBoxButtons.OKCancel)==DialogResult.OK)
{
kfdelete();
Con.Open();
string query = "delete from [Teacher] where Id=" + key + ";";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show(" O'qituvchi ma'lumotlari o'chirildi");
Con.Close();
yuklash();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
Con.Close();
}
}
//taxrirlash tugmasi
private void button_taxrir_Click(object sender, EventArgs e)
{
try
{
Con.Open();
string query = "UPDATE Teacher SET FISH=@FISH, Jins=@Jins, yosh=@yosh, oylik=@oylik, Razryad=@Razryad,Mut_nom=@Mut_nom Where Id="+key+"";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.Parameters.AddWithValue("@Id", Convert.ToInt32(textBox_Id.Text));
cmd.Parameters.AddWithValue("@FISH", textBox1_Ism.Text);
cmd.Parameters.AddWithValue("@Jins", S);
cmd.Parameters.AddWithValue("@yosh", Convert.ToInt32(textBox_yosh.Text));
cmd.Parameters.AddWithValue("@oylik", textBox_Oy.Text);
cmd.Parameters.AddWithValue("@Razryad", textBox_Raz.Text);
cmd.Parameters.AddWithValue("@Mut_nom", textBox_mut.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("Ma'lumotlar Taxrirlandi");
Con.Close();
yuklash();

}
catch (Exception ex)


{
MessageBox.Show(ex.Message);
}
}

private void Teach_Form_Load(object sender, EventArgs e)


{
yuklash();
}
//DGV jadvalidagi malumot ustiga bosilsa textboxlarga malumotlarni berish
string ism = "";
private void DGV_teacher_CellClick(object sender, DataGridViewCellEventArgs e)
{
try
{
//tanlangan qiymat IDsini keyga o'shlashtiradi
if (DGV_teacher.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
{
key = int.Parse(DGV_teacher.Rows[e.RowIndex].Cells[0].Value.ToString());
ism = DGV_teacher.Rows[e.RowIndex].Cells[1].Value.ToString();
}
//tanlangan id dagi shaxsni qiymatarini textboxlarga o'zlashtiradi
SqlCommand cmd = new SqlCommand();
cmd.Connection = Con;
cmd.CommandText = "select * from Teacher where Id=" + key + "";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
textBox_Id.Text = ds.Tables[0].Rows[0][0].ToString();
textBox1_Ism.Text = ds.Tables[0].Rows[0][1].ToString();
textBox_yosh.Text = ds.Tables[0].Rows[0][3].ToString();
textBox_Oy.Text = ds.Tables[0].Rows[0][4].ToString();
textBox_Raz.Text = ds.Tables[0].Rows[0][5].ToString();
textBox_mut.Text = ds.Tables[0].Rows[0][6].ToString();
}
catch
{
MessageBox.Show("Tanlovda Xatolik Bor");
}
}
//O'qituvchi ma'lumotlari o'chirilganda kafedrada shu fish dagi malumotlar o'chiriladi
public void kfdelete()
{
try
{
Con.Open();
string query = "delete from [Kafedra] where KTfish='" + ism + "';";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
Con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Con.Close();
}
}
}
}

fan nomi comboboxsiga FanDb jadvalidagi fanlar nomlarini o'zlashtirib beruvchi f-ya public void KFanlar(){


try{
Con.Open();
SqlCommand cmd = new SqlCommand("select Fnom from FanDb ", Con);
SqlDataReader rdr;
rdr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("Fnom", typeof(string));
dt.Load(rdr);
comboBox_Fnom.ValueMember = "Fnom";
comboBox_Fnom.DataSource = dt;
Con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Con.Close();
}
}
//Gr Nomeri comboxsiga Guruh jadvalidagi bor guruh nomerlarini o'zlashtiruvchi f-ya
private void KGuruh(){
try{
Con.Open();
SqlCommand cmd = new SqlCommand("select GrNum from Guruh ", Con);
SqlDataReader rdr;
rdr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("GrNum", typeof(int));
dt.Load(rdr);
comboBox_grnum.ValueMember = "GrNum";
comboBox_grnum.DataSource = dt;
Con.Close();}
catch (Exception ex){
MessageBox.Show(ex.Message);
Con.Close();}
// TFish comboboxsiga Teacherjadvalidagi bor o'qituvchilar FISH larini o'zlashtiruvchi
private void KOqituvchi(){
try{
Con.Open();
SqlCommand cmd = new SqlCommand("select FISH from Teacher where Id>" + 0 + "", Con);
SqlDataReader rdr;
rdr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("FISH", typeof(string));
dt.Load(rdr);
comboBox_Tfish.ValueMember = "FISH";
comboBox_Tfish.DataSource = dt;
Con.Close();}
catch (Exception ex)}
MessageBox.Show(ex.Message);
Con.Close();}}

//texboxlarga o'ziga tegishli fannomiga mos qiymatlarni o'zlashtiruvchi f-ya


private void KFan_item(){
try{
Con.Open();
string query = " select * from FanDb where Fnom ='" + comboBox_Fnom.SelectedValue.ToString() + "'";
SqlCommand cmd = new SqlCommand(query, Con);
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
foreach (DataRow dr in dt.Rows){
textBox1_Maruza.Text = dr["Maruza"].ToString();
textBox_Amaliy.Text = dr["Amaliy"].ToString();
textBox_kurs.Text = dr["Kurs"].ToString();
textBox_Mtalim.Text = dr["M_talim"].ToString();
textBox_Lab.Text = dr["Lab"].ToString();}
Con.Close();}
catch (Exception ex){
MessageBox.Show(ex.Message);
Con.Close();}}}
private void KafedraForm_Load(object sender, EventArgs e){
yuklash();
UmumiyYuk();
KFanlar();
KGuruh();
KOqituvchi();
KFan_item();}
//Umumiy yuklamani hisoblash va chiqarish
private void UmumiyYuk()
{
DGV_Kafedra[0, DGV_Kafedra.Rows.Count - 1].Value = 0;
DGV_Kafedra[1, DGV_Kafedra.Rows.Count - 1].Value = "Fanlar";
DGV_Kafedra[2, DGV_Kafedra.Rows.Count - 1].Value = "Guruh num";
DGV_Kafedra[3, DGV_Kafedra.Rows.Count - 1].Value = "O'qituvchilar";
DGV_Kafedra.Rows[DGV_Kafedra.Rows.Count - 1].Cells[0].Style.BackColor = Color.Green;
DGV_Kafedra.Rows[DGV_Kafedra.Rows.Count - 1].Cells[1].Style.BackColor = Color.Green;
DGV_Kafedra.Rows[DGV_Kafedra.Rows.Count - 1].Cells[2].Style.BackColor = Color.Green;
DGV_Kafedra.Rows[DGV_Kafedra.Rows.Count - 1].Cells[3].Style.BackColor = Color.Green;
DGV_Kafedra.Rows[DGV_Kafedra.Rows.Count - 1].Cells[4].Style.BackColor = Color.Green;
DGV_Kafedra.Rows[DGV_Kafedra.Rows.Count - 1].Cells[5].Style.BackColor = Color.Green;
DGV_Kafedra.Rows[DGV_Kafedra.Rows.Count - 1].Cells[6].Style.BackColor = Color.Green;
DGV_Kafedra.Rows[DGV_Kafedra.Rows.Count - 1].Cells[7].Style.BackColor = Color.Green;
DGV_Kafedra.Rows[DGV_Kafedra.Rows.Count - 1].Cells[8].Style.BackColor = Color.Green;
DGV_Kafedra.Rows[DGV_Kafedra.Rows.Count - 1].Cells[9].Style.BackColor = Color.Green;
DGV_Kafedra.Rows[DGV_Kafedra.Rows.Count - 1].Cells[10].Style.BackColor = Color.Green;
decimal totalK = 0;
for (int a = 0; a < DGV_Kafedra.Rows.Count - 1; a++)
{
var valueK = DGV_Kafedra.Rows[a].Cells[4].Value.ToString();
if (valueK != DBNull.Value.ToString())
{
totalK += Convert.ToDecimal(valueK);
}
}
DGV_Kafedra.Rows[DGV_Kafedra.Rows.Count - 1].Cells[4].Value ="Kurs ishi:"+ totalK.ToString();
decimal totalM = 0;
for (int a = 0; a < DGV_Kafedra.Rows.Count - 1; a++)
{
var valueM = DGV_Kafedra.Rows[a].Cells[5].Value.ToString();
if (valueM != DBNull.Value.ToString())
{
totalM += Convert.ToDecimal(valueM);
}
}
DGV_Kafedra.Rows[DGV_Kafedra.Rows.Count - 1].Cells[5].Value ="Maruzalar:"+ totalM.ToString();
decimal totalA = 0;
for (int a = 0; a < DGV_Kafedra.Rows.Count - 1; a++)
{
var valueA = DGV_Kafedra.Rows[a].Cells[6].Value.ToString();
if (valueA != DBNull.Value.ToString())
{
totalA += Convert.ToDecimal(valueA);
}
}
DGV_Kafedra.Rows[DGV_Kafedra.Rows.Count - 1].Cells[6].Value ="Amaliylar:"+ totalA.ToString();
decimal totalMt = 0;
for (int a = 0; a < DGV_Kafedra.Rows.Count - 1; a++)
{
var valueMt = DGV_Kafedra.Rows[a].Cells[7].Value.ToString();
if (valueMt != DBNull.Value.ToString())
{
totalMt += Convert.ToDecimal(valueMt);
}
}
DGV_Kafedra.Rows[DGV_Kafedra.Rows.Count - 1].Cells[7].Value ="Mustqil T:"+ totalMt.ToString();
decimal totalL = 0;
for (int a = 0; a < DGV_Kafedra.Rows.Count - 1; a++)
{
var valueL = DGV_Kafedra.Rows[a].Cells[8].Value.ToString();
if (valueL != DBNull.Value.ToString())
{
totalL += Convert.ToDecimal(valueL);
}
}
DGV_Kafedra.Rows[DGV_Kafedra.Rows.Count - 1].Cells[8].Value ="Labarat'oriya:"+ totalL.ToString();
decimal totalUY = 0;
for (int a = 0; a < DGV_Kafedra.Rows.Count - 1; a++)
{
var valueUY = DGV_Kafedra.Rows[a].Cells[9].Value.ToString();
if (valueUY != DBNull.Value.ToString())
{
totalUY += Convert.ToDecimal(valueUY);
}
}
DGV_Kafedra.Rows[DGV_Kafedra.Rows.Count - 1].Cells[9].Value ="Jami:"+ totalUY.ToString();
//auditoriya soatlarini hisoblash va joylash
decimal totalAs = 0;
for (int a = 0; a < DGV_Kafedra.Rows.Count - 1; a++)
{
var valueAs = DGV_Kafedra.Rows[a].Cells[10].Value.ToString();
if (valueAs != DBNull.Value.ToString())
{
totalAs += Convert.ToDecimal(valueAs);
}
}
DGV_Kafedra.Rows[DGV_Kafedra.Rows.Count - 1].Cells[10].Value ="Auditoriya:"+totalAs.ToString();
}
//malumotlarni excelga jo'natish tugmasi
private void button2_Click(object sender, EventArgs e)
{
DGV_Kafedra.SelectAll();
DataObject copydata = DGV_Kafedra.GetClipboardContent();
if (copydata != null) Clipboard.SetDataObject(copydata);
Microsoft.Office.Interop.Excel.Application xlapp = new Microsoft.Office.Interop.Excel.Application();
xlapp.Visible = true;
Microsoft.Office.Interop.Excel.Workbook xlwbook;
Microsoft.Office.Interop.Excel.Worksheet xlsheet;
Object miseddata = System.Reflection.Missing.Value;
xlwbook = xlapp.Workbooks.Add(miseddata);
xlsheet = (Microsoft.Office.Interop.Excel.Worksheet)xlwbook.Worksheets.get_Item(1);
Microsoft.Office.Interop.Excel.Range xlr = (Microsoft.Office.Interop.Excel.Range)xlsheet.Cells[1, 1];
xlr.Select();
xlsheet.PasteSpecial(xlr, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true);
}
}
}



Yüklə 1,81 Mb.

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




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

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin