forked from MahmoudAdelkamal/Auction_management_system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Home.xaml.cs
207 lines (200 loc) · 8.14 KB
/
Home.xaml.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Media;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
namespace Auction_Management_system
{
public partial class Home : Window
{
public Home()
{
InitializeComponent();
var products = GetProducts();
if (products.Count > 0)
Listproduct.ItemsSource = products;
sql_queries query = new sql_queries("Data Source=(local);Initial Catalog=Auction_mangement_system;Integrated Security=True");
DataTable dt = new DataTable();
dt = query.Get_categories();
foreach (DataRow dr in dt.Rows)
{
Category_Combobox.Items.Add(dr["category_name"]);
}
}
private void home_Click(object sender, EventArgs e)
{
Home home = new Home();
home.Show();
this.Close();
}
private void Create_session_Click(object sender, EventArgs e)
{
Create_session session = new Create_session();
session.Show();
this.Close();
}
private void account_Click(object sender, EventArgs e)
{
editinformation en = new editinformation();
en.Show();
this.Close();
}
private void Logout_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure you want to log out?", "Log out", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
{
MainWindow mainWindow = new MainWindow();
mainWindow.Show();
this.Close();
}
}
private BitmapImage bytes_to_image(byte[] bytes)
{
MemoryStream ms = new MemoryStream(bytes);
BitmapImage bmp = new BitmapImage();
bmp.BeginInit();
bmp.StreamSource = ms;
bmp.EndInit();
return bmp;
}
private void details_Click(object sender, EventArgs e)
{
var btn = (Button)sender;
var x = (product)btn.Tag;
// MessageBox.Show(x.Winner);
product_details pd = new product_details(x.Title, x.price, x.photo, x.category,x.description,x.start_date,x.end_date);
pd.Show();
this.Close();
}
private List<product> GetProducts()
{
DataTable dt = new DataTable();
sql_queries query = new sql_queries("Data Source=(local);Initial Catalog=Auction_mangement_system;Integrated Security=True");
dt = query.Retrieve_products();
List<product> list = new List<product>();
BitmapImage bmp = new BitmapImage();
foreach (DataRow dr in dt.Rows)
{
byte[] img = null;
img = (byte[])(dr["photo"]);
BitmapImage b = new BitmapImage();
b = bytes_to_image(img);
product p = new product(Convert.ToInt32(dr["ID"]),dr["Winner"].ToString(),dr["seller"].ToString(), dr["Title"].ToString(), Convert.ToDouble(dr["price"]), b, dr["category"].ToString(), dr["start_date"].ToString(), dr["end_date"].ToString(),dr["Descriptions"].ToString());
list.Add(p);
}
return list;
}
private List<product> Get_Product_by_search()
{
DataTable dt = new DataTable();
sql_queries query = new sql_queries("Data Source=(local);Initial Catalog=Auction_mangement_system;Integrated Security=True");
dt = query.search_product(search_textbox.Text,Category_Combobox.Text);
List<product> list = new List<product>();
BitmapImage bmp = new BitmapImage();
foreach (DataRow dr in dt.Rows)
{
byte[] img = null;
img = (byte[])(dr["photo"]);
BitmapImage b = new BitmapImage();
b = bytes_to_image(img);
product p = new product(Convert.ToInt32(dr["ID"]), dr["Winner"].ToString(), dr["seller"].ToString() ,dr["Title"].ToString(), Convert.ToDouble(dr["price"]), b, dr["category"].ToString(), dr["start_date"].ToString(), dr["end_date"].ToString(),dr["Descriptions"].ToString());
list.Add(p);
}
return list;
}
private List<product> Get_products_by_category(string category)
{
DataTable dt = new DataTable();
sql_queries query = new sql_queries("Data Source=(local);Initial Catalog=Auction_mangement_system;Integrated Security=True");
dt = query.Filter_by_category(category);
List<product> list = new List<product>();
BitmapImage bmp = new BitmapImage();
foreach (DataRow dr in dt.Rows)
{
byte[] img = null;
img = (byte[])(dr["photo"]);
BitmapImage b = new BitmapImage();
b = bytes_to_image(img);
product p = new product(Convert.ToInt32(dr["ID"]), dr["Winner"].ToString(), dr["seller"].ToString(), dr["Title"].ToString(),Convert.ToDouble(dr["price"]), b, dr["category"].ToString(),dr["start_date"].ToString(),dr["end_date"].ToString(),dr["Descriptions"].ToString());
list.Add(p);
}
return list;
}
private void search_textbox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
}
private void search_textbox_MouseDoubleClick_1(object sender, MouseButtonEventArgs e)
{
search_textbox.Text = "";
}
private void search_textbox_TextChanged(object sender, TextChangedEventArgs e)
{
var p = Get_Product_by_search();
if (p.Count > 0)
Listproduct.ItemsSource = p;
}
private void Category_Combobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var p = Get_products_by_category(Category_Combobox.SelectedItem.ToString());
if (p.Count > 0)
Listproduct.ItemsSource = p;
}
private void join(object sender, RoutedEventArgs e)
{
sql_queries query = new sql_queries("Data Source=(local);Initial Catalog=Auction_mangement_system;Integrated Security=True");
var btn = (Button)sender;
var x = (product)btn.Tag;
DateTime Start = Convert.ToDateTime(x.start_date);
DateTime End = Convert.ToDateTime(x.end_date);
int t1 = DateTime.Compare(Start, DateTime.Now);
int t2 = DateTime.Compare(DateTime.Now, End);
if (t1 > 0)
{
MessageBox.Show("The session didn't start yet");
}
else if (t2 < 0)
{
if (User.username == x.seller)
MessageBox.Show("The seller can't bid for his product ! ");
else
{
Session session = new Session(x.Id, x.photo, x.Title, x.Winner, x.price);
session.Show();
this.Close();
}
}
else if (t2 > 0)
{
if (x.Winner == "")
MessageBox.Show("No Participants !");
else if (x.Winner == User.username)
{
SoundPlayer soundPlayer = new SoundPlayer("app-30.wav");
soundPlayer.LoadAsync();
soundPlayer.Play();
Result res = new Result(x.photo, x.Title, x.price, x.Winner);
res.Show();
}
else
{
Result res = new Result(x.photo, x.Title, x.price, x.Winner);
res.Show();
}
}
}
}
}