-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrmPersonel.cs
140 lines (110 loc) · 4.31 KB
/
FrmPersonel.cs
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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 System.Data.SqlClient;
namespace YurtKayitSistemi
{
public partial class FrmPersonel : Form
{
public FrmPersonel()
{
InitializeComponent();
}
SqlBaglantim bgl = new SqlBaglantim();
public void PersonelGetir()
{
SqlDataAdapter dt = new SqlDataAdapter("Select * from Personel", bgl.baglanti());
DataTable ds = new DataTable();
dt.Fill(ds);
dataGridView1.DataSource = ds;
}
private void FrmPersonel_Load(object sender, EventArgs e)
{
PersonelGetir();
}
private void BtnKaydet_Click(object sender, EventArgs e)
{
try
{
// Personel Ekleme
SqlCommand komut = new SqlCommand("insert into Personel (PersonelAdSoyad, PersonelDepartman) values (@p1,@p2)", bgl.baglanti());
komut.Parameters.AddWithValue("@p1", TxtPersonelAd.Text);
komut.Parameters.AddWithValue("@P2", TxtPersonelDepartman.Text);
komut.ExecuteNonQuery();
bgl.baglanti().Close();
PersonelGetir();
MessageBox.Show("Personel Kaydedildi");
}
catch (Exception)
{
MessageBox.Show("Hatalı Ekleme İşlemi");
}
}
private void BtnSil_Click(object sender, EventArgs e)
{
try
{
// Personel silme
SqlCommand komut = new SqlCommand("Delete from Personel where Personelid=@p1", bgl.baglanti());
komut.Parameters.AddWithValue("@p1", TxtPersonelId.Text);
komut.ExecuteNonQuery();
TxtPersonelId.Clear();
TxtPersonelAd.Clear();
TxtPersonelDepartman.Clear();
TxtPersonelAd.Focus();
bgl.baglanti().Close();
PersonelGetir();
MessageBox.Show("Personel Silme İşlemi Gerçekleşti");
}
catch (Exception)
{
MessageBox.Show("Hatalı Silme İşlemi");
}
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
// Datagridde seçilen verileri Textboxlarda listeleme
int secilen;
secilen = dataGridView1.SelectedCells[0].RowIndex;
string id, ad, departman;
id = dataGridView1.Rows[secilen].Cells[0].Value.ToString();
ad = dataGridView1.Rows[secilen].Cells[1].Value.ToString();
departman = dataGridView1.Rows[secilen].Cells[2].Value.ToString();
TxtPersonelId.Text = id;
TxtPersonelAd.Text = ad;
TxtPersonelDepartman.Text = departman;
}
private void BtnGuncelle_Click(object sender, EventArgs e)
{
// Personel Güncelleme
try
{
SqlCommand komut = new SqlCommand("Update Personel set PersonelAdSoyad=@p1, PersonelDepartman=@p2 where Personelid=@p3", bgl.baglanti());
komut.Parameters.AddWithValue("@p3", TxtPersonelId.Text);
komut.Parameters.AddWithValue("@p1", TxtPersonelAd.Text);
komut.Parameters.AddWithValue("@p2", TxtPersonelDepartman.Text);
komut.ExecuteNonQuery();
PersonelGetir();
bgl.baglanti().Close();
MessageBox.Show("Güncelleme işlemi Gerçekleşti");
}
catch (Exception)
{
MessageBox.Show("Hatalı Güncelleme İşlemi");
}
}
private void button1_Click(object sender, EventArgs e)
{
TxtPersonelId.Clear();
TxtPersonelAd.Clear();
TxtPersonelDepartman.Clear();
TxtPersonelAd.Focus();
}
}
}