-
Notifications
You must be signed in to change notification settings - Fork 5
/
frmProducts.cs
154 lines (142 loc) · 5.34 KB
/
frmProducts.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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 RestoranOtomasyonu
{
public partial class frmProducts : Form
{
cDataController Controller = new cDataController();
BindingSource bs = new BindingSource();
bool YeniKayit = false;
int KayitliPozisyon = 1;
public frmProducts()
{
InitializeComponent();
}
private void frmProducts_Load(object sender, EventArgs e)
{
Fields(false);
Controller.Select_Urun();
Controller.Select_Kategori();
bs.DataSource = Controller.ds.Tables["Ürünler"];
dataGridView1.DataSource = bs;
dataGridView1.Columns["UrunKodu"].Visible = false;
dataGridView1.Columns["KategoriKodu"].Visible = false;
cbCategory.DataSource = Controller.ds.Tables["Kategoriler"];
cbCategory.ValueMember = "KategoriKodu";
cbCategory.DisplayMember = "Kategori Adı";
lblUrunKodu.DataBindings.Add("Text", bs, "UrunKodu");
cbCategory.DataBindings.Add("SelectedValue", bs, "KategoriKodu");
txtProName.DataBindings.Add("Text", bs, "Ürün Adı");
txtProDesc.DataBindings.Add("Text", bs, "Açıklama");
nupPrice.DataBindings.Add("Value", bs, "Fiyat");
}
void Fields(bool State)
{
txtProName.ReadOnly = !State;
txtProDesc.ReadOnly = !State;
nupPrice.ReadOnly = !State;
nupPrice.Enabled = State;
cbCategory.Enabled = State;
btnProSave.Enabled = State;
btnProCancel.Enabled = State;
btnNew.Enabled = !State;
btnEdit.Enabled = !State;
btnDelete.Enabled = !State;
}
void DisabledColorChange(object sender, EventArgs e)
{
Button btn = sender as Button;
if (btn.Enabled) btn.BackColor = Color.FromArgb(0, 173, 181);
else btn.BackColor = Color.FromArgb(2, 82, 86);
}
#region Butonların Fonksiyonları
private void btnNew_Click(object sender, EventArgs e)
{
Fields(true);
YeniKayit = true;
txtProName.Text = "";
txtProDesc.Text = "";
nupPrice.Value = 0;
} // Yeni butonu
private void btnEdit_Click(object sender, EventArgs e)
{
KayitliPozisyon = bs.Position;
Fields(true);
YeniKayit = false;
} // Düzenle butonu
private void btnDelete_Click(object sender, EventArgs e)
{
if (Controller.Connection.State == ConnectionState.Closed) Controller.Connection.Open();
DialogResult dR = MessageBox.Show("Bu ürünü gerçekten silmek istiyor musunuz?", "Uyarı", MessageBoxButtons.YesNo);
if (dR == DialogResult.Yes)
{
Controller.Delete_Urun(int.Parse(lblUrunKodu.Text));
MessageBox.Show("Seçilmiş olan ürün silindi!", "Bilgilendirme");
Controller.Select_Urun();
}
} // Sil butonu
private void btnProSave_Click(object sender, EventArgs e)
{
int KategoriKodu = int.Parse(cbCategory.SelectedValue.ToString());
int UrunKodu = int.Parse(lblUrunKodu.Text);
if (txtProName.Text.Trim() == "" || txtProDesc.Text.Trim() == "")
{
MessageBox.Show("Alanlar boş olamaz!", "Hata");
}
else
{
if (YeniKayit)
{
Controller.Insert_Urun(KategoriKodu, txtProName.Text, txtProDesc.Text, nupPrice.Value);
MessageBox.Show("Ürün başarıyla eklendi.", "Bilgilendirme");
Controller.Select_Urun();
bs.Position = bs.List.Count;
}
else
{
Controller.Update_Urun(KategoriKodu, txtProName.Text, txtProDesc.Text, nupPrice.Value, UrunKodu);
MessageBox.Show("Ürün başarıyla düzenlendi.", "Bilgilendirme");
Controller.Select_Urun();
bs.Position = KayitliPozisyon;
}
Fields(false);
}
} // Kaydet butonu
private void btnProCancel_Click(object sender, EventArgs e)
{
Fields(false);
Controller.Select_Urun();
bs.Position = KayitliPozisyon;
} // İptal butonu
private void btnGoBack_Click(object sender, EventArgs e)
{
frmMain main = new frmMain();
main.Show();
this.Hide();
} // Ana Menü butonu
#endregion
private void txtSearch_TextChanged(object sender, EventArgs e)
{
Controller.Select_Urun(txtSearch.Text);
if (dataGridView1.Rows.Count == 0)
{
btnNew.Enabled = false;
btnEdit.Enabled = false;
btnDelete.Enabled = false;
}
else
{
btnNew.Enabled = true;
btnEdit.Enabled = true;
btnDelete.Enabled = true;
}
}
}
}