private void frmKullaniciPaneli_FormClosing(object sender, FormClosingEventArgs e) { Form1 form1 = new Form1(); this.Hide(); form1.Show(); frmKullaniciPaneli panel1 = (frmKullaniciPaneli)Application.OpenForms["frmKullaniciPaneli"]; panel1.Hide(); }
private void girisButton_Click(object sender, EventArgs e) { if (girisKullanici.Text.Trim() != "" && girisSifre.Text.Trim() != "") { string kullanici = girisKullanici.Text.Trim(), sifre = MD5Sifrele(girisSifre.Text.Trim()); MySqlConnection con = baglantiYap(); MySqlCommand oku = new MySqlCommand("SELECT * FROM " + users + " WHERE kullanici='" + kullanici + "' AND sifre='" + sifre + "'", con); MySqlDataReader okuyucu = oku.ExecuteReader(); if (okuyucu.Read()) { if (!Convert.ToBoolean(okuyucu["yasakli"])) { frmKullaniciPaneli panel = new frmKullaniciPaneli(); panel.kendiID = Convert.ToInt32(okuyucu["id"]); panel.kendiKullanici = okuyucu["kullanici"].ToString(); panel.kendiSifre = okuyucu["sifre"].ToString(); panel.kendiPosta = okuyucu["posta"].ToString(); panel.gYonetici = false; panel.label1.Text = "Hoşgeldiniz sayın " + kullanici; panel.Show(); this.Hide(); } else { MessageBox.Show("Sayın " + kullanici + ", yönetici tarafında yasaklandınız.\nSisteme artık giriş yapamazsınız.\nLütfen yöneticiye başvurun.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { oku.Dispose(); okuyucu.Dispose(); MySqlCommand readadmin = new MySqlCommand("SELECT * FROM " + admins + " WHERE kullanici='" + kullanici + "' AND sifre='" + sifre + "'", con); MySqlDataReader reader = readadmin.ExecuteReader(); if (reader.Read()) { if (!Convert.ToBoolean(reader["yasakli"])) { frmKullaniciPaneli panel = new frmKullaniciPaneli(); panel.label1.Text = "Hoşgeldiniz sayın " + kullanici; panel.ekleButton.Visible = true; panel.silButton.Visible = true; panel.duzenleButton.Visible = true; panel.yasaklaButton.Visible = true; panel.dokuButton.Visible = true; panel.listView1.Visible = true; panel.kendiID = Convert.ToInt32(reader["id"]); panel.kendiKullanici = reader["kullanici"].ToString(); panel.kendiSifre = reader["sifre"].ToString(); panel.kendiPosta = reader["posta"].ToString(); panel.gDoku = Convert.ToBoolean(reader["doku"]); if (Convert.ToBoolean(reader["doku"])) { panel.menuStrip1.Visible = true; } panel.gAs = Convert.ToBoolean(reader["asyonetici"]); panel.gYonetici = true; panel.Show(); this.Hide(); } else { MessageBox.Show("Sayın " + kullanici + " yöneticimiz, maalesef yasaklandınız.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Kullanıcı adınız veya şifreniz yanlış.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void button1_Click(object sender, EventArgs e) { if (button1.Text == "Ekle") { string kullanici = kullaniciText.Text.Trim(), sifre = MD5Sifrele(sifreText.Text.Trim()), posta = postaText.Text.Trim(); bool yasakli = Convert.ToBoolean(yasakliText.Text), doku = Convert.ToBoolean(dokuText.Text); if (kullanici != "" && sifre != "" && EmailIsValid(posta) && !(Convert.ToBoolean(varMi(kullanici, sifre)[0]))) { string table = ""; if (comboBox1.Text == "Üye") { table = users; } else if (comboBox1.Text == "Yönetici") { table = admins; } MySqlConnection con = baglantiYap(); MySqlCommand komut = new MySqlCommand(); if (table == users) { komut.CommandText = "INSERT INTO " + table + " (kullanici, sifre, posta, yasakli) VALUES ('" + kullanici + "', '" + sifre + "', '" + posta + "', " + yasakli + ")"; } else if (table == admins) { komut.CommandText = "INSERT INTO " + table + " (kullanici, sifre, posta, yasakli, doku) VALUES ('" + kullanici + "', '" + sifre + "', '" + posta + "', " + yasakli + ", " + doku + ")"; } komut.Connection = con; komut.ExecuteNonQuery(); komut.Dispose(); con.Close(); frmKullaniciPaneli panel = (frmKullaniciPaneli)Application.OpenForms["frmKullaniciPaneli"]; panel.yenile(); MessageBox.Show("\"" + kullanici + "\" adlı kullanıcı başarıyla eklendi.", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); } } else if (button1.Text == "Düzenle") { string kullanici = kullaniciText.Text.Trim(), sifre = sifreText.Text.Trim(), posta = postaText.Text.Trim(); int id = Convert.ToInt32(idText.Text); bool yasakli = Convert.ToBoolean(yasakliText.Text), doku = Convert.ToBoolean(dokuText.Text); if (kullanici != "" && EmailIsValid(posta) && !(Convert.ToBoolean(varMi(kullanici, sifre)[0])) || Convert.ToInt32(varMi(kullanici, sifre)[1]) == id) { sifre = MD5Sifrele(sifre); string table = ""; if (comboBox1.Text == "Üye") { table = users; } else if (comboBox1.Text == "Yönetici") { table = admins; } MySqlConnection con = baglantiYap(); MySqlCommand komut = new MySqlCommand(); if (sifreText.Text.Trim() == "") { if (table == users) { komut.CommandText = "UPDATE " + table + " SET kullanici='" + kullanici + "', posta='" + posta + "', yasakli=" + yasakli + " WHERE id=" + id + ""; } else if (table == admins) { komut.CommandText = "UPDATE " + table + " SET kullanici='" + kullanici + "', posta='" + posta + "', yasakli=" + yasakli + ", doku=" + doku + " WHERE id=" + id + ""; } } else { if (table == users) { komut.CommandText = "UPDATE " + table + " SET kullanici='" + kullanici + "', sifre='" + sifre + "', posta='" + posta + "', yasakli=" + yasakli + " WHERE id=" + id + ""; } else if (table == admins) { komut.CommandText = "UPDATE " + table + " SET kullanici='" + kullanici + "', sifre='" + sifre + "', posta='" + posta + "', yasakli=" + yasakli + ", doku=" + doku + " WHERE id=" + id + ""; } } komut.Connection = con; komut.ExecuteNonQuery(); komut.Dispose(); con.Close(); frmKullaniciPaneli panel = (frmKullaniciPaneli)Application.OpenForms["frmKullaniciPaneli"]; panel.yenile(); MessageBox.Show("\"" + kullanici + "\" adlı kullanıcı başarıyla güncellendi.", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); } } }