-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBufeStok.cs
More file actions
171 lines (136 loc) · 5.1 KB
/
BufeStok.cs
File metadata and controls
171 lines (136 loc) · 5.1 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
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.SQLite;
namespace Kutuphanecsharp
{
public partial class BufeStok : Form
{
public BufeStok()
{
InitializeComponent();
}
SQLiteConnection baglanti = new SQLiteConnection("Data Source=kihmed.db;Version=3");
SQLiteCommand komut;
SQLiteDataAdapter da;
DataSet ds;
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void BufeStok_Load(object sender, EventArgs e)
{
listele();
}
void listele()
{
da = new SQLiteDataAdapter("select ID,urunad,fiyat,adet from bufe", baglanti);
ds = new DataSet();
baglanti.Open();
da.Fill(ds, "kihmed");
dgw1.DataSource = ds.Tables["kihmed"];
baglanti.Close();
}
private void tbxAdd_Click(object sender, EventArgs e)
{
lblad.Visible = false;
lblfiyat.Visible = false;
lbladet.Visible = false;
lblwarning.Visible = false;
if (tbxAd.Text == "" || tbxFiyat.Text == "" || nudAdet.Value == 0)
{
if (tbxAd.Text == "")
{
lblad.Visible = true;
lblwarning.Visible = true;
}
if (tbxFiyat.Text == "")
{
lblfiyat.Visible = true;
lblwarning.Visible = true;
}
if (nudAdet.Value == 0)
{
lbladet.Visible = true;
lblwarning.Visible = true;
}
}
else
{
komut = new SQLiteCommand();
baglanti.Open();
komut.Connection = baglanti;
string fiyat = tbxFiyat.Text;
fiyat = fiyat.Replace(",",".");
tbxFiyat.Text = fiyat;
string ekle = "insert into bufe(urunad,fiyat,adet) values('" + tbxAd.Text + "', '" + tbxFiyat.Text + "', '" + nudAdet.Text + "');";
komut.CommandText = ekle;
komut.ExecuteNonQuery();
baglanti.Close();
tbxAd.Clear();
tbxFiyat.Clear();
nudAdet.Value = 0;
listele();
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
DialogResult secenek = MessageBox.Show("Ürünü silmek istediğinize emin misiniz?", "Silme Onay Penceresi", MessageBoxButtons.YesNo);
if (secenek == DialogResult.Yes)
{
foreach (DataGridViewRow drow in dgw1.SelectedRows) //Seçili Satırları Silme
{
baglanti.Open();
int ID = Convert.ToInt32(drow.Cells[0].Value);
string sql = "DELETE FROM bufe WHERE ID=@ID";
komut = new SQLiteCommand(sql, baglanti);
komut.Parameters.AddWithValue("@ID", ID);
komut.ExecuteNonQuery();
baglanti.Close();
}
listele();
}
else if (secenek == DialogResult.No)
{
}
}
private void btnUpdate_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow dgw in dgw1.SelectedRows)
{
if (dgw1.RowCount >0)
{
baglanti.Open();
int miktar = Convert.ToInt32(nudgAdet.Text);
string guncelle = $"update bufe set urunad=@urunad , fiyat=@fiyat , adet=@adet where ID=@ID";
string fiyat = tbxgFiyat.Text;
fiyat = fiyat.Replace(",",".");
tbxgFiyat.Text = fiyat;
komut = new SQLiteCommand(guncelle, baglanti);
komut.Parameters.AddWithValue("@ID",dgw1.SelectedCells[0].Value);
komut.Parameters.AddWithValue("@urunad", tbxgAd.Text);
komut.Parameters.AddWithValue("@fiyat", tbxgFiyat.Text);
komut.Parameters.AddWithValue("@adet", miktar);
komut.ExecuteNonQuery();
baglanti.Close();
listele();
}
}
}
private void dgw1_CellClick_1(object sender, DataGridViewCellEventArgs e)
{
tbxgAd.Text = dgw1.CurrentRow.Cells["urunad"].Value.ToString();
tbxgFiyat.Text = dgw1.CurrentRow.Cells["fiyat"].Value.ToString();
nudgAdet.Value = Convert.ToInt32(dgw1.CurrentRow.Cells["adet"].Value);
}
private void groupBox2_Enter(object sender, EventArgs e)
{
}
}
}