-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmCalisan.cs
125 lines (107 loc) · 5.18 KB
/
frmCalisan.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
using Npgsql;
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;
namespace otelRez
{
public partial class frmCalisan : Form
{
public frmCalisan()
{
InitializeComponent();
}
NpgsqlConnection baglanti = new NpgsqlConnection("server=localHost; port=5432; Database=otelRez; user ID=postgres; password=Ethem.2151");
private void frmCalisan_Load(object sender, EventArgs e)
{
baglanti.Open();
string sorgu = "select * from otel";
NpgsqlDataAdapter da = new NpgsqlDataAdapter(sorgu, baglanti);
DataSet ds = new DataSet();
da.Fill(ds);
datagridOteller.DataSource = ds.Tables[0];
string sorgu1 = "select * from oda";
NpgsqlDataAdapter da1 = new NpgsqlDataAdapter(sorgu1, baglanti);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
datagridOdalar.DataSource = ds1.Tables[0];
string sorgu2 = "select * from rezervasyon";
NpgsqlDataAdapter da2 = new NpgsqlDataAdapter(sorgu2, baglanti);
DataSet ds2 = new DataSet();
da2.Fill(ds2);
datagridRez.DataSource = ds2.Tables[0];
string sorgu4 = "select * from makbuz";
NpgsqlDataAdapter da4 = new NpgsqlDataAdapter(sorgu4, baglanti);
DataSet ds4 = new DataSet();
da4.Fill(ds4);
datagridMakbuz.DataSource = ds4.Tables[0];
baglanti.Close();
}
private void btnOtelEkle_Click(object sender, EventArgs e)
{
baglanti.Open();
NpgsqlCommand komut1 = new NpgsqlCommand("insert into otel (otelAdi,otelKonum,odasayisi,gorsel,telno) values (@p2,@p3,@p4,@p5,@p6)", baglanti);
//komut1.Parameters.AddWithValue("@p1", int.Parse(txtID.Text));
komut1.Parameters.AddWithValue("@p2", txtAd.Text);
komut1.Parameters.AddWithValue("@p3", txtKonum.Text);
komut1.Parameters.AddWithValue("@p4", int.Parse(txtOdaSayisi.Text));
komut1.Parameters.AddWithValue("@p5", txtGorsel.Text);
komut1.Parameters.AddWithValue("@p6", txtTel.Text);
komut1.ExecuteNonQuery();
string sorgu = "select * from otel";
NpgsqlDataAdapter da = new NpgsqlDataAdapter(sorgu, baglanti);
DataSet ds = new DataSet();
da.Fill(ds);
datagridOteller.DataSource = ds.Tables[0];
baglanti.Close();
MessageBox.Show("Otel Başarı İle Kaydeilmiştir.");
}
private void datagridOteller_CellClick(object sender, DataGridViewCellEventArgs e)
{
txtID.Text = datagridOteller.Rows[e.RowIndex].Cells[0].Value.ToString();
txtAd.Text = datagridOteller.Rows[e.RowIndex].Cells[1].Value.ToString();
txtKonum.Text = datagridOteller.Rows[e.RowIndex].Cells[2].Value.ToString();
txtGorsel.Text = datagridOteller.Rows[e.RowIndex].Cells[4].Value.ToString();
txtOdaSayisi.Text = datagridOteller.Rows[e.RowIndex].Cells[3].Value.ToString();
txtTel.Text = datagridOteller.Rows[e.RowIndex].Cells[5].Value.ToString();
}
private void btnOtelGuncelle_Click(object sender, EventArgs e)
{
baglanti.Open();
NpgsqlCommand komut3 = new NpgsqlCommand("update otel set otelAdi=@p1,otelKonum=@p2,odasayisi=@p3,gorsel=@p4,telno=@p5 where(id=@p6)", baglanti);
komut3.Parameters.AddWithValue("@p1", txtAd.Text.Trim());
komut3.Parameters.AddWithValue("@p2", txtKonum.Text.Trim());
komut3.Parameters.AddWithValue("@p3", int.Parse(txtOdaSayisi.Text));
komut3.Parameters.AddWithValue("@p4", txtGorsel.Text.Trim());
komut3.Parameters.AddWithValue("@p5", txtTel.Text.Trim());
komut3.Parameters.AddWithValue("@p6", int.Parse(txtID.Text.Trim()));
komut3.ExecuteNonQuery();
string sorgu = "select * from otel";
NpgsqlDataAdapter da = new NpgsqlDataAdapter(sorgu, baglanti);
DataSet ds = new DataSet();
da.Fill(ds);
datagridOteller.DataSource = ds.Tables[0];
baglanti.Close();
MessageBox.Show("Otel Başarı İle Güncellenmiştir.");
}
private void btnOtelSil_Click(object sender, EventArgs e)
{
baglanti.Open();
NpgsqlCommand komut4 = new NpgsqlCommand("delete from otel where id=@p1", baglanti);
komut4.Parameters.AddWithValue("@p1", int.Parse(txtID.Text.Trim()));
komut4.ExecuteNonQuery();
string sorgu = "select * from otel";
NpgsqlDataAdapter da = new NpgsqlDataAdapter(sorgu, baglanti);
DataSet ds = new DataSet();
da.Fill(ds);
datagridOteller.DataSource = ds.Tables[0];
baglanti.Close();
MessageBox.Show("Otel Başarı İle Silinmiştir.");
}
}
}