NYP-2 2016 10. Hafta Uygulamaları-1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
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(); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
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 { } } } } |