NYP-2 2016 10. Hafta Uygulamaları-1

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 MySql.Data.MySqlClient;
namespace notgirisi
{
    public partial class Form1 : Form
    {
        MySqlDataAdapter da;
        DataTable dt;

        public Form1()
        {
            InitializeComponent();
            MySqlConnectionStringBuilder bag = new MySqlConnectionStringBuilder();
            bag.Server = "localhost";
            bag.UserID = "root";
            bag.Password = "123456";
            bag.Database = "hafta10_16_2";

            MySqlConnection conn = new MySqlConnection(bag.ToString());

            MySqlCommand cmd_sel = 
                new MySqlCommand("select id,ogrno,adsoyad,vize,final from ogrenci;", conn);

            MySqlCommand cmd_ins =
                new MySqlCommand("insert into ogrenci(ogrno,adsoyad,vize,final) values(@ogrno,@adsoyad,@vize,@final)", conn);
            cmd_ins.Parameters.Add("@ogrno", MySqlDbType.VarChar, 15, "ogrno");
            cmd_ins.Parameters.Add("@adsoyad", MySqlDbType.VarChar, 45, "adsoyad");
            cmd_ins.Parameters.Add("@vize", MySqlDbType.Int32, 11, "vize");
            cmd_ins.Parameters.Add("@final", MySqlDbType.Int32, 11, "final");

            MySqlCommand cmd_del = 
                new MySqlCommand("delete from ogrenci where id=@id;",conn);
            cmd_del.Parameters.Add("@id", MySqlDbType.Int32, 11, "id");

            MySqlCommand cmd_upd = 
                new MySqlCommand("update ogrenci set ogrno=@ogrno, adsoyad=@adsoyad, vize=@vize, final=@final where id=@id;", conn);
            cmd_upd.Parameters.Add("@id", MySqlDbType.Int32, 11, "id");
            cmd_upd.Parameters.Add("@ogrno", MySqlDbType.VarChar, 15, "ogrno");
            cmd_upd.Parameters.Add("@adsoyad", MySqlDbType.VarChar, 45, "adsoyad");
            cmd_upd.Parameters.Add("@vize", MySqlDbType.Int32, 11, "vize");
            cmd_upd.Parameters.Add("@final", MySqlDbType.Int32, 11, "final");

            da = new MySqlDataAdapter();
            da.SelectCommand = cmd_sel;
            da.InsertCommand = cmd_ins;
            da.DeleteCommand = cmd_del;
            da.UpdateCommand = cmd_upd;

            listedoldur();

        }

        private void listedoldur()
        {
            try
            {
                dt = new DataTable();
                da.Fill(dt);

                logrno.Items.Clear();
                ladsoyad.Items.Clear();
                lort.Items.Clear();
                lharf.Items.Clear();


                int satir = dt.Rows.Count;

                for (int ogr = 0; ogr < satir; ogr++)
                {
                    int ort = (int)Math.Round((int)dt.Rows[ogr]["vize"] * 0.4 + (int)dt.Rows[ogr]["final"] * 0.6);
                    logrno.Items.Add(dt.Rows[ogr]["ogrno"]);
                    ladsoyad.Items.Add(dt.Rows[ogr]["adsoyad"]);
                    lort.Items.Add(ort);
                    lharf.Items.Add(harfhesap(ort));

                }

            }
            catch
            { }
        

        
        }

        private string harfhesap(int ort)
        {
            String[] harf = { "AA", "BA", "BB", "CB", "CC", "DC", "DD", "FD" };
            int[] sinir = { 90, 80, 70, 60, 50, 40, 35, 30 };

            for (int i = 0; i < sinir.Length; i++)
            {
                if (ort >= sinir[i])
                    return harf[i];
            }

            return "FF";
        }

        private void bverigirisi_Click(object sender, EventArgs e)
        {
            fverigirisi frm = new fverigirisi(da);
            frm.ShowDialog();
            listedoldur();
        }
    }
}
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 MySql.Data.MySqlClient;

namespace notgirisi
{
    public partial class fverigirisi : Form
    {
        MySqlDataAdapter da;
        DataTable dt;
        public fverigirisi(MySqlDataAdapter _da)
        {
            InitializeComponent();
            da = _da;
            verigetir();
        }

        private void verigetir()
        {
            try
            {
                dt = new DataTable();
                da.Fill(dt);
                dataGridView1.DataSource = dt;
                dataGridView1.Columns["id"].Visible = false;
                //dataGridView1.Columns[0].Visible = false;
                dataGridView1.Columns[1].HeaderText = "Öğrenci No";
                dataGridView1.Columns[2].HeaderText = "Ad Soyad";
                dataGridView1.Columns[3].HeaderText = "Vize";
                dataGridView1.Columns[4].HeaderText = "Final";

            }
            catch { }

        
        }

        private void bkapat_Click(object sender, EventArgs e)
        {
            try
            {
                da.Update(dt); // hata olusmasi durumunda kapatma
                this.Close();
            }
            catch { }


        }
    }
}

NYP-2 2016 Hafta-8 – 1

Share