/
IlanVer.cs
276 lines (247 loc) · 10.2 KB
/
IlanVer.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Documents;
using System.Windows.Forms;
namespace Petilan.Sayfalar
{
public partial class IlanVer : Form
{
public static string KullaniciAdi { get; set; }
public void ilanKontrol()
{
string resimKontrol = pbImageUpload.ImageLocation;
if (cbHayvanYasi.SelectedIndex != 0 && cbHayvanYasi.SelectedIndex != 1 &&
cbHayvanYasi.SelectedIndex != 2 && cbHayvanYasi.SelectedIndex != 3 &&
cbHayvanYasi.SelectedIndex != 4)
{
MessageBox.Show("Hayvan Yaşı seçmediniz tekrar kontrol ediniz.");
}
else
{
if (cbHayvanCinsiyeti.SelectedIndex != 0 && cbHayvanCinsiyeti.SelectedIndex != 1)
{
MessageBox.Show("Hayvan Cinsiyeti seçmediniz tekrar kontrol ediniz.");
}
else
{
if (cbIlanDurumu.SelectedIndex != 0)
{
MessageBox.Show("Lütfen ilan durumunu aktif olarak (A) işaretleyiniz.");
}
else
{
if (File.Exists(resimKontrol) == false)
{
MessageBox.Show("Resim eklemeyi unuttunuz tekrar kontrol ediniz.");
}
else
{
try
{
SqlConnection baglanti = new SqlConnection("Data Source=BURAK\\SQLEXPRESS;Initial Catalog=PETILAN_YDK;Integrated Security=True");
if (baglanti.State == ConnectionState.Closed)
baglanti.Open();
string kullaniciNo = "select * from tbl_Kullanici where KullaniciAdi = '" + KullaniciAdi + "'";
SqlCommand command2 = new SqlCommand(kullaniciNo, baglanti);
SqlDataReader reader = command2.ExecuteReader();
var id = 0;
while (reader.Read())
{
id = Convert.ToInt32(reader[0]);
}
reader.Close();
try
{
string veriEkle = "insert into tbl_Ilanlar(IlanBaslik,HayvanAdi,HayvanTuru,HayvanIrk,HayvanYas,HayvanCinsiyet,IlanDurumu,KullaniciNo,ResimKonumu) values ('" + tbIlanBaslik.Text + "','" + tbHayvanIsmi.Text + "','" + cbHayvanTuru.Text + "','" + cbHayvanIrki.Text + "','" + cbHayvanYasi.Text + "','" + cbHayvanCinsiyeti.Text + "','" + cbIlanDurumu.Text + "','" + id + "','" + imageUplGlb + "')";
SqlCommand command = new SqlCommand(veriEkle, baglanti);
command.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
MessageBox.Show("İlan yayınlama işlemi başarılı.");
baglanti.Close();
}
catch (Exception ex)
{
MessageBox.Show("İşlem sırasında hata oluştu. " + ex);
}
}
}
}
}
}
public IlanVer()
{
InitializeComponent();
}
string imageUplGlb;
private void btResimEkle_Click(object sender, EventArgs e)
{
String imageLocation = "";
try
{
OpenFileDialog imageUpload = new OpenFileDialog();
imageUpload.Filter = "jpg files(*.jpg)|*.jpg| PNG files(*.png)|*.png| All Files(*.*)|*.*";
if (imageUpload.ShowDialog() == DialogResult.OK)
{
imageLocation = imageUpload.FileName;
pbImageUpload.ImageLocation = imageLocation;
imageUplGlb = imageLocation;
}
}
catch (Exception)
{
MessageBox.Show("Resim eklenirken bir hata oluştu.");
}
pictureBox1.Hide();
}
private void btIlanVer_Click(object sender, EventArgs e)
{
if (tbIlanBaslik.Text == "")
{
MessageBox.Show("İlan başlığını boş bıraktınız tekrar kontrol ediniz.");
}
else if (tbHayvanIsmi.Text == "")
{
MessageBox.Show("Evcil hayvanınızın ismini boş bıraktınız tekrar kontrol ediniz.");
}
else if (cbHayvanTuru.SelectedIndex != 0 && cbHayvanTuru.SelectedIndex != 1 &&
cbHayvanTuru.SelectedIndex != 2 && cbHayvanTuru.SelectedIndex != 3 &&
cbHayvanTuru.SelectedIndex != 4 && cbHayvanTuru.SelectedIndex != 5)
{
MessageBox.Show("Hayvan Türü seçmediniz tekrar kontrol ediniz.");
}
else if (cbHayvanIrki.SelectedIndex == 0 || cbHayvanIrki.SelectedIndex == 13
|| cbHayvanIrki.SelectedIndex == 25 || cbHayvanIrki.SelectedIndex == 31
|| cbHayvanIrki.SelectedIndex == 36 || cbHayvanIrki.SelectedIndex == 41)
{
MessageBox.Show("Hayvan Irkı seçiminde bir terslik var tekrar kontrol ediniz.");
}
else if (cbHayvanIrki.SelectedItem == null)
{
MessageBox.Show("Hayvan Irkı seçmediniz lütfen tekrar kontrol ediniz.");
}
else if (cbHayvanTuru.SelectedIndex == 0)
{
if (!(cbHayvanIrki.SelectedIndex >= 14 && cbHayvanIrki.SelectedIndex <= 24))
{
MessageBox.Show("Lütfen bir kedi ırkı seçiniz.");
}
else
{
ilanKontrol();
}
}
else if (cbHayvanTuru.SelectedIndex == 1)
{
if (!(cbHayvanIrki.SelectedIndex >= 1 && cbHayvanIrki.SelectedIndex <= 12))
{
MessageBox.Show("Lütfen bir köpek ırkı seçiniz.");
}
else
{
ilanKontrol();
}
}
else if (cbHayvanTuru.SelectedIndex == 2)
{
if (!(cbHayvanIrki.SelectedIndex >= 26 && cbHayvanIrki.SelectedIndex <= 30))
{
MessageBox.Show("Lütfen bir kuş ırkı seçiniz.");
}
else
{
ilanKontrol();
}
}
else if (cbHayvanTuru.SelectedIndex == 3)
{
if (!(cbHayvanIrki.SelectedIndex >= 32 && cbHayvanIrki.SelectedIndex <= 35))
{
MessageBox.Show("Lütfen bir sürüngen ırkı seçiniz.");
}
else
{
ilanKontrol();
}
}
else if (cbHayvanTuru.SelectedIndex == 4)
{
if (!(cbHayvanIrki.SelectedIndex >= 37 && cbHayvanIrki.SelectedIndex <= 40))
{
MessageBox.Show("Lütfen bir kemirgen ırkı seçiniz.");
}
else
{
ilanKontrol();
}
}
else if (cbHayvanTuru.SelectedIndex == 5)
{
if (!(cbHayvanIrki.SelectedIndex >= 42 && cbHayvanIrki.SelectedIndex <= 50))
{
MessageBox.Show("Lütfen bir su canlısı ırkı seçiniz.");
}
else
{
ilanKontrol();
}
}
}
private void pbPetIlanLogo_Click(object sender, EventArgs e)
{
}
private void btHesapIlanVer_Click(object sender, EventArgs e)
{
cmHesap.Show(Cursor.Position.X, Cursor.Position.Y);
}
private void cmHesap_Opening(object sender, CancelEventArgs e)
{
}
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
MessageBox.Show("Zaten İlan Ver sayfasındasınız.");
}
private void cikisYap_Click(object sender, EventArgs e)
{
this.Hide();
Anasayfa anasayfa = new Anasayfa();
anasayfa.ShowDialog();
}
private void ilanlarımToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Hide();
Ilanlarim ilanlarim = new Ilanlarim();
ilanlarim.btIlanlarimHesap.Text = btHesapIlanVer.Text;
ilanlarim.ShowDialog();
}
private void IlanVer_Load(object sender, EventArgs e)
{
KullaniciAdi = Anasayfa.KullaniciAdi;
btHesapIlanVer.Text = KullaniciAdi;
}
private void gelenIstekler_Click(object sender, EventArgs e)
{
this.Hide();
GelenIstekler gi = new GelenIstekler();
gi.ShowDialog();
}
private void btAnasayfa_Click(object sender, EventArgs e)
{
AnasayfaListele.KullaniciAdi = KullaniciAdi;
this.Hide();
AnasayfaListele ansyflst = new AnasayfaListele();
ansyflst.ShowDialog();
}
}
}