-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormAccounts.cs
198 lines (174 loc) · 6.7 KB
/
FormAccounts.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
/***************************************************************************************
* Copyright (C) 2021 Fran Vojković, Martina Gaćina, Matea Čotić, Mirna Keser *
* *
* This file is part of the RP3_Projekt project. *
* *
***************************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CaffeBar
{
/// <summary>
/// Sorage display form.
/// </summary>
public partial class FormAccounts : Form
{
DataTable table;
SqlDataAdapter adapter;
public FormAccounts()
{
InitializeComponent();
}
private void button4_Click(object sender, EventArgs e)
{
this.Close();
}
private void FormAccounts_Load(object sender, EventArgs e)
{
SuspendLayout();
//dataGridView1.AllowUserToAddRows = true;
dataGridView1.AllowUserToDeleteRows = true;
adapter =
new SqlDataAdapter("SELECT * FROM [User] WHERE Deleted = 0",
DB.connection_string);
//////SqlCommandBuilder()
////SqlCommand command = new SqlCommand("INSERT INTO [User] (Username,Password) VALUES (@Username,@Password)", DB.getConnection());
////command.Parameters.Add("@Username", SqlDbType.NChar, 20, "Username");
////command.Parameters.Add("@Password", SqlDbType.NVarChar, 20, "Password");
//////command.Parameters.Add("@Authorisation", SqlDbType.NChar, 10, "Authorisation");
////adapter.InsertCommand = command;
////command = new SqlCommand("UPDATE [User] SET Deleted = 1 WHERE Id=@Id)");
////command.Parameters.Add("@Id", SqlDbType.Int, sizeof(int), "Id");
////adapter.DeleteCommand = command;
table = new DataTable();
adapter.Fill(table);
this.dataGridView1.DataSource = table;
//LoadData();
ResumeLayout();
}
private void LoadData()
{
SqlConnection connection = DB.getConnection();
DataSet dataset = new DataSet();
using (
SqlDataAdapter adapter =
new SqlDataAdapter("SELECT * FROM [User] WHERE Deleted = 0",
connection)
)
{
adapter.Fill(dataset); //, "Storage");
}
var dv = dataset.Tables[0].DefaultView;
//dv.RowFilter = filter;
dataGridView1.DataSource = dv;
// postavljamo da se editati može samo cooler i backstorage
//dataGridView1.ReadOnly = true;
//dataGridView1.Columns[0].ReadOnly = true;
//dataGridView1.Columns[1].ReadOnly = true;
//dataGridView1.Columns[2].ReadOnly = true;
//dataGridView1.Columns["Deleted"].Visible = false;
dataGridView1.AllowUserToAddRows = true;
DB.closeConnection();
}
private void nodeletedToolStripButton_Click(object sender, EventArgs e)
{
//try
//{
// this.userTableAdapter.Nodeleted(this.caffeBarDatabaseDataSet.User);
//}
//catch (System.Exception ex)
//{
// System.Windows.Forms.MessageBox.Show(ex.Message);
//}
}
private void dataGridView1_UserDeletingRow(
object sender,
DataGridViewRowCancelEventArgs e
)
{
e.Cancel = true;
SqlConnection connection = DB.getConnection();
SqlCommand command3 =
new SqlCommand("UPDATE [User] SET Deleted = 1 WHERE Id=@id",
connection);
command3.Parameters.AddWithValue("@id", (int)e.Row.Cells[0].Value);
try
{
command3.ExecuteNonQuery();
e.Row.Dispose();
DataSet dataset = new DataSet();
adapter.Fill(dataset);
dataGridView1.DataSource = dataset.Tables[0].DefaultView;
}
catch (Exception ex)
{
MessageBox.Show("ERROR: Database error! " + ex.Message);
}
finally
{
DB.closeConnection();
}
//LoadData();
//adapter.Update(table);
}
private void FormAccounts_FormClosed(
object sender,
FormClosedEventArgs e
)
{
adapter.Dispose();
}
private void dataGridView1_UserAddedRow(
object sender,
DataGridViewRowEventArgs e
)
{
}
private void dataGridView1_RowEnter(
object sender,
DataGridViewCellEventArgs e
)
{
//if (dataGridView1.NewRowIndex == e.RowIndex && (e.ColumnIndex == 1 || e.ColumnIndex == 2))
// dataGridView1[e.ColumnIndex, e.RowIndex].ReadOnly = false;
//else
// dataGridView1[e.ColumnIndex, e.RowIndex].ReadOnly = true;
}
private void dataGridView1_CellEndEdit(
object sender,
DataGridViewCellEventArgs e
)
{
// check if username and pass are entered
////if(dataGridView1[1,e.RowIndex].Value.ToString() != "" && dataGridView1[2, e.RowIndex].Value.ToString() !="" && dataGridView1[3, e.RowIndex].Value.ToString() != "")
////{
//// // validate ..
//// try
//// {
//// MessageBox.Show(dataGridView1[1, e.RowIndex].Value.ToString() + "|" + dataGridView1[2, e.RowIndex].Value.ToString() + "|" + dataGridView1[3, e.RowIndex].Value.ToString());
//// MessageBox.Show(adapter.Update(table).ToString());
//// }
//// catch (Exception ex)
//// {
//// MessageBox.Show(ex.Message);
//// }
////}
}
private void buttonAddUser_Click(object sender, EventArgs e)
{
FormAddUser form = new FormAddUser();
form.ShowDialog();
DataSet dataset = new DataSet();
adapter.Fill(dataset);
dataGridView1.DataSource = dataset.Tables[0].DefaultView;
}
}
}