Formun Tamamı İçin Tıklayınız.
#
Class İçi #
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsFormsApplication46
{
class Class1
{
OleDbConnection con = new
OleDbConnection("provider=microsoft.ace.oledb.12.0;data
source=okul.accdb");
public void kaydet(Form1
olcan)
{
try
{
int m = 0;
int n = 0;
con.Open();
OleDbDataAdapter da = new OleDbDataAdapter("select * from sinif", con);
DataSet de = new
DataSet();
da.Fill(de, "remzi");
int a = de.Tables[0].Rows.Count;
for (int
i = 0; i < a; i++)
{
if (olcan.textBox1.Text
== de.Tables[0].Rows[i][0].ToString())
{
MessageBox.Show("Başka okul no
giriniz...");
}
else
{
m = 1;
}
}
if (olcan.textBox2.Text == "")
{
MessageBox.Show("Boş olamaz...");
}
else
{
n = 1;
}
if (m == 1 || n == 1)
{
OleDbCommand cmd = new OleDbCommand("insert into sinif(okulno,ad,yuz) values('"
+ olcan.textBox1.Text + "','" +
olcan.textBox2.Text + "','0')",
con);
cmd.ExecuteNonQuery();
}
con.Close();
}
catch (Exception)
{
MessageBox.Show("Kodlarda hata var mühendis kontrol etmeli");
}
}
public void listele(Form1
betül)
{
betül.listBox1.Items.Clear();
con.Open();
int m = 0;
OleDbDataAdapter da = new
OleDbDataAdapter("select * from sinif order by yuz desc",
con);
DataSet de = new
DataSet();
da.Fill(de, "remzi");
int a = de.Tables[0].Rows.Count;
for (int i = 0;
i < a; i++)
{
betül.listBox1.Items.Add(++m + ")"
+ de.Tables[0].Rows[i][0].ToString() + "
" + de.Tables[0].Rows[i][1].ToString() + "
" + de.Tables[0].Rows[i][2].ToString());
}
con.Close();
}
public void index(Form1
gonca)
{
try
{
int g = gonca.listBox1.SelectedIndex;
con.Open();
OleDbDataAdapter da = new OleDbDataAdapter("select * from sinif order by yuz desc",
con);
DataSet de = new
DataSet();
da.Fill(de, "remzi");
gonca.label3.Text = de.Tables[0].Rows[g][0].ToString();
gonca.label4.Text = de.Tables[0].Rows[g][1].ToString();
gonca.label5.Text = de.Tables[0].Rows[g][2].ToString();
int p = Convert.ToInt32(gonca.label5.Text);
int k = Convert.ToInt32(de.Tables[0].Rows[0][2].ToString());
double sonuc = (double)(p * 100) / k;
gonca.label6.Text = String.Format("Notu = {0:f2}", sonuc);
con.Close();
}
catch
{
MessageBox.Show("Dikkat");
con.Close();
}
}
public void yuzekle(Form1
berk)
{
try
{
con.Open();
int r = Convert.ToInt32(berk.label5.Text);
if (berk.textBox3.Text == "")
{
r += 1;
}
else
{
int girilen = Convert.ToInt32(berk.textBox3.Text);
r = r + girilen;
berk.textBox3.Clear();
}
OleDbDataAdapter da = new OleDbDataAdapter("select * from sinif order by yuz desc",
con);
DataSet de = new
DataSet();
da.Fill(de, "remzi");
OleDbCommand cmd = new OleDbCommand("update sinif set yuz='" + r + "' where okulno='" + berk.label3.Text + "'", con);
cmd.ExecuteNonQuery();
berk.label5.Text = r.ToString();
int p = Convert.ToInt32(berk.label5.Text);
int k = Convert.ToInt32(de.Tables[0].Rows[0][2].ToString());
double sonuc = (double)(p * 100) / k;
berk.label6.Text = String.Format("Notu = {0:f2}", sonuc);
con.Close();
}
catch
{
MessageBox.Show("Kodlarda sorun olabilir");
}
}
}
}
#
Buton İçi #
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication46
{
public partial class Form1
: Form
{
public Form1()
{
InitializeComponent();
}
Class1 ezgi = new
Class1();
private void button1_Click(object sender, EventArgs e)
{
ezgi.kaydet(this);
}
private void button3_Click(object sender, EventArgs e)
{
ezgi.listele(this);
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs
e)
{
ezgi.index(this);
}
private void button2_Click(object sender, EventArgs e)
{
ezgi.yuzekle(this);
}
}
}
Hiç yorum yok:
Yorum Gönder