Untitled

mail@pastecode.io avatar
unknown
csharp
4 years ago
2.9 kB
17
Indexable
Never
namespace AkayYazilimPersonelTakip
{
    class Veritabani
    {
        public static MySqlConnection baglanti = new MySqlConnection("datasource=localhost;database=akaypersoneltakip;port=3306;username=root;password=171717");
        public static void ESG(MySqlCommand cmd, string sql)
        {
            baglanti.Open();
            cmd.Connection = baglanti;
            cmd.CommandText = sql;
            cmd.ExecuteNonQuery();
            baglanti.Close();

        }

        public static DataTable Listele_Ara(DataGridView gridView, string sql)
        {
            DataTable tbl = new DataTable();

            baglanti.Open();
            MySqlDataAdapter adtr = new MySqlDataAdapter(sql, baglanti);
            adtr.Fill(tbl);
            gridView.DataSource = tbl;
            baglanti.Close();

            return tbl;
        }
        
namespace AkayYazilimPersonelTakip
{
    class Departmanlar
    {

        private int _ID;
        private string _Departman;
        private string _Aciklama;

        public int ID { get => _ID; set => _ID = value; }
        public string Departman { get => _Departman; set => _Departman = value; }
        public string Aciklama { get => _Aciklama; set => _Aciklama = value; }

        public static MySqlDataReader DepartmanGetir(ListView lst)
        {
            lst.Items.Clear();
            
            Veritabani.baglanti.Open();
            MySqlCommand komut = new MySqlCommand("select *from departmanlar", Veritabani.baglanti);
            MySqlDataReader dr = komut.ExecuteReader();
            while (dr.Read())
            {
                ListViewItem ekle = new ListViewItem();
                ekle.Text = dr[0].ToString();
                ekle.SubItems.Add(dr[1].ToString());
                ekle.SubItems.Add(dr[2].ToString());

                lst.Items.Add(ekle);
            }
            Veritabani.baglanti.Close();
            return dr;
        }
    }
}
namespace AkayYazilimPersonelTakip
{
    public partial class frm_AnaSayfa : Form
    {
        public frm_AnaSayfa()
        {
            InitializeComponent();
        }

        private void frm_AnaSayfa_Load(object sender, EventArgs e)
        {
            Departmanlar.DepartmanGetir(listView1);
        }

        private void btn_Ekle_Click(object sender, EventArgs e)
        {
            Departmanlar d = new Departmanlar();

           
            d.Departman = txt_Departman.Text;
            d.Aciklama = txt_Aciklama.Text;


            string sorgu = "insert into departmanlar values('"+ d.Departman +"', '" + d.Aciklama + "')";
            MySqlCommand komut = new MySqlCommand();
            Veritabani.ESG(komut, sorgu);
            MessageBox.Show("Kayit Basarili");

            Departmanlar.DepartmanGetir(listView1);



        }
    }
}