-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserBooks.cs
105 lines (78 loc) · 3.18 KB
/
UserBooks.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
using MySql.Data.MySqlClient;
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 CS322___Projektni_zadatak___Bojana___Stajić___4596
{
public partial class UserBooks : Form
{
MySqlConnection mycon;
string con = "datasource=localhost;port=3306;username=root;password='';database=cs322_pz";
DataTable dt = new DataTable();
public UserBooks()
{
InitializeComponent();
}
private void dgvBooks_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void UserBooks_Load(object sender, EventArgs e)
{
mycon = new MySqlConnection(con);
mycon.Open();
MySqlCommand cmd = new MySqlCommand("SELECT books.title, books.isbn, books.author, books.price, books.genre FROM books " +
"JOIN cart_items ON cart_items.book_id = books.id WHERE user_id=@user_id AND flag=2;", mycon);
cmd.Parameters.AddWithValue("@user_id", Shared.user_id);
cmd.ExecuteScalar();
MySqlDataAdapter adapter = new MySqlDataAdapter();
adapter.SelectCommand = cmd;
DataTable dt = new DataTable();
adapter.Fill(dt);
BindingSource bind = new BindingSource();
bind.DataSource = dt;
dgvBooks.DataSource = bind;
adapter.Update(dt);
dgvBooks.Columns[0].Visible = false;
dgvBooks.AutoResizeColumns();
}
private void btnRefresh_Click(object sender, EventArgs e)
{
mycon = new MySqlConnection(con);
mycon.Open();
MySqlCommand cmd = new MySqlCommand("SELECT books.title, books.isbn, books.author, books.price, books.genre FROM books " +
"JOIN cart_items ON cart_items.book_id = books.id WHERE user_id=@user_id AND flag=2;", mycon);
cmd.Parameters.AddWithValue("@user_id", Shared.user_id);
cmd.ExecuteScalar();
MySqlDataAdapter adapter = new MySqlDataAdapter();
adapter.SelectCommand = cmd;
DataTable dt = new DataTable();
adapter.Fill(dt);
BindingSource bind = new BindingSource();
bind.DataSource = dt;
dgvBooks.DataSource = bind;
adapter.Update(dt);
dgvBooks.Columns[0].Visible = true;
dgvBooks.AutoResizeColumns();
}
private void UserBooks_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
private void dgvBooks_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
this.Hide();
UserPanel userPanelForm = new UserPanel();
userPanelForm.Show();
userPanelForm.FormClosed += (s, args) => this.Close();
}
}
}