forked from MahmoudAdelkamal/Auction_management_system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Admin_Home.xaml.cs
173 lines (168 loc) · 6.95 KB
/
Admin_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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
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 Admin_Home : Window
{
public Admin_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)
{
Admin_Home home = new Admin_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();
}
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)
{
var btn = (Button)sender;
var x = (product)btn.Tag;
sql_queries query = new sql_queries("Data Source=(local);Initial Catalog=Auction_mangement_system;Integrated Security=True");
query.delete_product(x.Id);
MessageBox.Show("Deleted Successfully");
}
private void Manage_click(object sender, RoutedEventArgs e)
{
Admin_Window admin_Window = new Admin_Window();
admin_Window.Show();
}
}
}