-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbsqlsearch.cs
79 lines (73 loc) · 2.76 KB
/
dbsqlsearch.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
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalProject
{
class DBSQLSearch : DBAccess
{
public DBSQLSearch(string connectionString)
: base(connectionString)
{
}
public Products[] SearchProductsBySupplier(int SupplierID)
{
string Command = "SELECT * FROM Products where Product_id=ANY(Select Product_id From Supplier_Product where Supplier_id=" + SupplierID + ")";
DataSet data_set = new DataSet();
ArrayList ProductArr = new ArrayList();
using (OleDbCommand command = new OleDbCommand(Command))
{
data_set = GetMultipleQuery(command);
}
DataTable data_table = new DataTable();
try
{
data_table = data_set.Tables[0];
}
catch { }
foreach (DataRow tType in data_table.Rows)
{
Products product = new Products();
product.ID = int.Parse(tType[0].ToString());
product.Name = (tType[1].ToString());
product.Description = (tType[2].ToString());
product.Amount = int.Parse(tType[4].ToString());
ProductArr.Add(product);
}
return (Products[])ProductArr.ToArray(typeof(Products));
}
//Search order of customer through the customer id
public Order[] GetOrdersOfCustomer(int CustomerID)
{
string Command = "SELECT * FROM Orders WHERE Customer_id=" + CustomerID;
DataSet data_set = new DataSet();
ArrayList OrderArr = new ArrayList();
using (OleDbCommand command = new OleDbCommand(Command))
{
data_set = GetMultipleQuery(command);
}
DataTable data_table = new DataTable();
try
{
data_table = data_set.Tables[0];
}
catch { }
foreach (DataRow tType in data_table.Rows)
{
Order order = new Order();
order.Customerid = int.Parse(tType[0].ToString());
order.Productid = int.Parse(tType[1].ToString());
order.customerName = tType[2].ToString();
order.productName = tType[3].ToString();
order.price = double.Parse(tType[4].ToString());
order.Amount = int.Parse(tType[5].ToString());
OrderArr.Add(order);
}
return (Order[])OrderArr.ToArray(typeof(Order));
}
}
}