C# Mesajlaşma Programı
Projemiz C# da basit bir mesajlaşma uygulaması.Veri tabanı olarak MySql kullandım.Projemizi ADO.NET ile MySql’le bagladık.Veritabanına baglanmak için Referans bölümünden MySql eklemezseniz Veritabanına baglanamazsınız.Onun içinde Connector yüklemeniz gerekiyor.
Projemizin Giriş Ekranı:Form1
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 |
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 MySql.Data.MySqlClient; namespace WindowsFormsApplication25 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static string login; private void button1_Click(object sender, EventArgs e) { MySqlConnection cnn = new MySqlConnection("Server=localhost;Database=odev;Uid=root;Pwd='';"); int id=-1; try { cnn.Open(); string sql = "SELECT * FROM kullanici WHERE kul_adi=@kad and sifre=@s"; MySqlCommand cmd = new MySqlCommand(sql, cnn); cmd.Parameters.Add(new MySqlParameter("@kad", textBox1.Text)); cmd.Parameters.Add(new MySqlParameter("@s", textBox2.Text)); DataTable dt = new DataTable(); MySqlDataAdapter da = new MySqlDataAdapter(cmd); da.Fill(dt); MySqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { id = Convert.ToInt32(dr["kul_id"].ToString()); } if (dt.Rows.Count > 0) { MessageBox.Show("Hoşgeldin "); } else { MessageBox.Show("Veritabanında böyle bir kullanıcı bulunamadı"); return; } } catch (Exception ex) { MessageBox.Show(ex.Message); } login = "@kad"; this.Visible = false; Form2 form2 = new Form2(id); form2.Show(); } } } |
Giriş yaptıktak sonra görüceginiz ekran:Form2
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 |
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 MySql.Data.MySqlClient; namespace WindowsFormsApplication25 { public partial class Form2 : Form { int kID; public Form2(int gelenid) { InitializeComponent(); kID = gelenid; } int[] idler = new int[100]; int[] secilenID = new int[100]; private void Form2_Load(object sender, EventArgs e) { MySqlConnection cnn = new MySqlConnection("Server=localhost;Database=odev;Uid=root;Pwd='';"); cnn.Open(); MySqlCommand cmd = new MySqlCommand("select * from kullanici", cnn); MySqlDataReader dr = cmd.ExecuteReader(); int say=0; while (dr.Read()) { comboBox1.Items.Add(dr["kul_adi"]); idler[say] = Convert.ToInt32(dr["kul_id"].ToString()); say++; } cnn.Close(); } int eklenen = 0; private void button2_Click(object sender, EventArgs e) { if (eklenen > 0) { textBox2.Text += " , "; } textBox2.Text += comboBox1.SelectedItem.ToString(); secilenID[eklenen] = idler[comboBox1.SelectedIndex]; eklenen++; } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { string sonuc = textBox2.Text; string[] dizi = sonuc.Split(','); MySqlConnection cnn = new MySqlConnection("Server=localhost;Database=odev;Uid=root;Pwd='';"); cnn.Open(); MySqlCommand komut = new MySqlCommand(); komut.Connection = cnn; for (int i = 0; i < dizi.Length; i++) { komut.CommandText = "Insert Into mesaj (tarih,mesaj_icerik,kul_id,gon_kul_id,okundu) VALUES (@tarih,@sonuc,@kul_id,@dizi,false)"; komut.Parameters.AddWithValue("@sonuc", textBox1.Text.ToString()); komut.Parameters.AddWithValue("@kul_id", kID); komut.Parameters.AddWithValue("@tarih", DateTime.Now); komut.Parameters.AddWithValue("@dizi", secilenID[i]); komut.ExecuteNonQuery(); komut.Parameters.Clear(); } cnn.Close(); } private void button3_Click(object sender, EventArgs e) { groupBox1.Visible = true; groupBox2.Visible = false; } private void groupBox2_Enter(object sender, EventArgs e) { } private void button4_Click(object sender, EventArgs e) { groupBox1.Visible = false; groupBox2.Visible = true; MySqlConnection baglanti = new MySqlConnection("Server=localhost;Database=odev;Uid=root;Pwd='';Convert Zero Datetime=True;Allow Zero Datetime=True"); baglanti.Open(); MySqlDataAdapter da = new MySqlDataAdapter("select *from mesaj", baglanti); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; baglanti.Close(); } } } |
Projenin tamamını BURDAN indirebilirsiniz.
Yorum ( 1 )
Hilal hanım bu programın veri tabanı nerede? ben bir mvc uygulaması için mesajlaşma uygulaması yapacağım ama veri tabanını nasıl dizayn edeceğime karar veremiyorum yardımcı olursanız sevinirim