-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShapeStorageManagement.cs
More file actions
339 lines (251 loc) · 15 KB
/
ShapeStorageManagement.cs
File metadata and controls
339 lines (251 loc) · 15 KB
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ObjectList;
namespace SQLManagement
{
public class values
{
public static void CheckIfAnotherRow(int iteration)
{
string connectionString = "Data Source=ShapeHistory.db;Version=3;";
SQLiteConnection connection = new SQLiteConnection(connectionString);
connection.Open();
int lastValue = LastValue();
int newValue = lastValue + 1;
string sqlCommand;
SQLiteCommand command;
while (newValue <= iteration)
{
sqlCommand = "INSERT INTO Main (id) VALUES (" + newValue + ");";
command = new SQLiteCommand(sqlCommand, connection);
command.ExecuteNonQuery();
newValue++;
}
}
public static int LastValue()
{
// create a connection to the SQLite database
string connectionString = "Data Source=ShapeHistory.db;Version=3;";
SQLiteConnection connection = new SQLiteConnection(connectionString);
connection.Open();
// create a SQL command to get the last value of a column
string sqlCommand = "SELECT id FROM Main ORDER BY ROWID DESC LIMIT 1;";
SQLiteCommand command = new SQLiteCommand(sqlCommand, connection);
// execute the SQL command and retrieve the last value of the column
object result = command.ExecuteScalar();
int lastValue = Convert.ToInt32(result); // convert the result to the appropriate data type
connection.Close();
return lastValue;
}
public class Add
{
public static void Text(int iteration, Text text)
{
CheckIfAnotherRow(iteration);
string connectionString = @"Data Source=ShapeHistory.db;Version=3;";
SQLiteConnection connection = new SQLiteConnection(connectionString);
connection.Open();
string query = "UPDATE Main SET Shape = 'Text' WHERE id = '" + iteration.ToString() + "'";
SQLiteCommand command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
query = "UPDATE Main SET ParamOne = '" + text.OriginPoint.Item1.ToString() + "' WHERE id = '" + iteration.ToString() + "'";
command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
query = "UPDATE Main SET ParamTwo = '" + text.OriginPoint.Item2.ToString() + "' WHERE id = '" + iteration.ToString() + "'";
command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
query = "UPDATE Main SET Content = '" + text.Content + "' WHERE id = '" + iteration.ToString() + "'";
command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
connection.Close();
}
public static void Square(int Iteration, Square Square)
{
CheckIfAnotherRow(Iteration);
string ConnectionString = @"Data Source=ShapeHistory.db;Version=3;";
SQLiteConnection Connection = new SQLiteConnection(ConnectionString);
Connection.Open();
string Query = "UPDATE Main SET Shape = 'Square' WHERE id = '" + Iteration.ToString() + "'";
SQLiteCommand Command = new SQLiteCommand(Query, Connection);
Command.ExecuteNonQuery();
Query = "UPDATE Main SET ParamOne = '" + Square.Width.ToString() + "' WHERE id = '" + Iteration.ToString() + "'";
Command = new SQLiteCommand(Query, Connection);
Command.ExecuteNonQuery();
Query = "UPDATE Main SET ParamTwo = '" + Square.Height.ToString() + "' WHERE id = '" + Iteration.ToString() + "'";
Command = new SQLiteCommand(Query, Connection);
Command.ExecuteNonQuery();
Query = "UPDATE Main SET ParamThree = '" + Square.OriginPoint.Item1.ToString() + "' WHERE id = '" + Iteration.ToString() + "'";
Command = new SQLiteCommand(Query, Connection);
Command.ExecuteNonQuery();
Query = "UPDATE Main SET ParamFour = '" + Square.OriginPoint.Item2.ToString() + "' WHERE id = '" + Iteration.ToString() + "'";
Command = new SQLiteCommand(Query, Connection);
Command.ExecuteNonQuery();
Connection.Close();
}
public static void Circle(int Iteration, Circle Circle)
{
CheckIfAnotherRow(Iteration);
string ConnectionString = @"Data Source=ShapeHistory.db;Version=3;";
SQLiteConnection Connection = new SQLiteConnection(ConnectionString);
Connection.Open();
string Query = "UPDATE Main SET Shape = 'Circle' WHERE id = '" + Iteration.ToString() + "'";
SQLiteCommand Command = new SQLiteCommand(Query, Connection);
Command.ExecuteNonQuery();
Query = "UPDATE Main SET ParamOne = '" + Circle.Radius.ToString() + "' WHERE id = '" + Iteration.ToString() + "'";
Command = new SQLiteCommand(Query, Connection);
Command.ExecuteNonQuery();
Query = "UPDATE Main SET ParamTwo = '" + Circle.OriginPoint.Item1.ToString() + "' WHERE id = '" + Iteration.ToString() + "'";
Command = new SQLiteCommand(Query, Connection);
Command.ExecuteNonQuery();
Query = "UPDATE Main SET ParamThree = '" + Circle.OriginPoint.Item2.ToString() + "' WHERE id = '" + Iteration.ToString() + "'";
Command = new SQLiteCommand(Query, Connection);
Command.ExecuteNonQuery();
Connection.Close();
}
public static void Triangle(int iteration, Triangle triangle)
{
CheckIfAnotherRow(iteration);
string connectionString = @"Data Source=ShapeHistory.db;Version=3;";
SQLiteConnection connection = new SQLiteConnection(connectionString);
connection.Open();
string query = "UPDATE Main SET Shape = 'Triangle' WHERE id = '" + iteration.ToString() + "'";
SQLiteCommand command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
query = "UPDATE Main SET ParamOne = '" + triangle.PointOne.Item1.ToString() + "' WHERE id = '" + iteration.ToString() + "'";
command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
query = "UPDATE Main SET ParamTwo = '" + triangle.PointOne.Item2.ToString() + "' WHERE id = '" + iteration.ToString() + "'";
command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
query = "UPDATE Main SET ParamThree = '" + triangle.PointTwo.Item1.ToString() + "' WHERE id = '" + iteration.ToString() + "'";
command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
query = "UPDATE Main SET ParamFour = '" + triangle.PointTwo.Item2.ToString() + "' WHERE id = '" + iteration.ToString() + "'";
command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
query = "UPDATE Main SET ParamFive = '" + triangle.PointThree.Item1.ToString() + "' WHERE id = '" + iteration.ToString() + "'";
command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
query = "UPDATE Main SET ParamSix = '" + triangle.PointThree.Item2.ToString() + "' WHERE id = '" + iteration.ToString() + "'";
command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
connection.Close();
}
public static void Line(int iteration, Line line)
{
CheckIfAnotherRow(iteration);
string connectionString = @"Data Source=ShapeHistory.db;Version=3;";
SQLiteConnection connection = new SQLiteConnection(connectionString);
connection.Open();
string query = "UPDATE Main SET Shape = 'Line' WHERE id = '" + iteration.ToString() + "'";
SQLiteCommand command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
query = "UPDATE Main SET ParamOne = '" + line.pointOne.Item1.ToString() + "' WHERE id = '" + iteration.ToString() + "'";
command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
query = "UPDATE Main SET ParamTwo = '" + line.pointOne.Item2.ToString() + "' WHERE id = '" + iteration.ToString() + "'";
command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
query = "UPDATE Main SET ParamThree = '" + line.pointTwo.Item1.ToString() + "' WHERE id = '" + iteration.ToString() + "'";
command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
query = "UPDATE Main SET ParamFour = '" + line.pointTwo.Item2.ToString() + "' WHERE id = '" + iteration.ToString() + "'";
command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
connection.Close();
}
public static void Board(int iteration, int width, int height)
{
CheckIfAnotherRow(iteration);
string connectionString = @"Data Source=ShapeHistory.db;Version=3;";
SQLiteConnection connection = new SQLiteConnection(connectionString);
connection.Open();
string query = "UPDATE Main SET Shape = 'Board' WHERE id = '" + iteration.ToString() + "'";
SQLiteCommand command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
query = "UPDATE Main SET ParamOne = '" + width.ToString() + "' WHERE id = '" + iteration.ToString() + "'";
command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
query = "UPDATE Main SET ParamTwo = '" + height.ToString() + "' WHERE id = '" + iteration.ToString() + "'";
command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
connection.Close();
}
}
public static void CheckIfFile()
{
if (!System.IO.File.Exists("ShapeHistory.db"))
{
string connectionString = @"Data Source=ShapeHistory.db;Version=3;";
SQLiteConnection connection = new SQLiteConnection(connectionString);
connection.Open();
string query = "CREATE TABLE Main (id INTEGER, Shape TEXT, " +
"ParamOne INTEGER, ParamTwo INTEGER, ParamThree INTEGER, " +
"ParamFour INTEGER, ParamFive INTEGER, ParamSix INTEGER, Content TEXT)";
SQLiteCommand command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
connection.Close();
}
}
public static Tuple<string, Tuple<int, int, int, int, int, int>, string> RetrieveRow(int iteration)
{
Tuple<string, Tuple<int, int, int, int, int, int>, string> values = new Tuple<string, Tuple<int, int, int, int, int, int>, string>("NULL", new Tuple<int, int, int, int, int, int>(-1, -1, -1, -1, -1, -1), "NULL");
string connectionString = @"Data Source=ShapeHistory.db;Version=3;";
SQLiteConnection connection = new SQLiteConnection(connectionString);
connection.Open();
SQLiteCommand query = new SQLiteCommand(connection);
query.CommandText = "SELECT * FROM Main WHERE id = '" + iteration.ToString() + "'";
SQLiteDataReader reader = query.ExecuteReader();
while (reader.Read())
{
values = new Tuple<string, Tuple<int, int, int, int, int, int>, string>(
reader.IsDBNull(1) ? "NULL" : reader.GetString(1),
new Tuple<int, int, int, int, int, int>(
reader.IsDBNull(2) ? -1 : reader.GetInt32(2),
reader.IsDBNull(3) ? -1 : reader.GetInt32(3),
reader.IsDBNull(4) ? -1 : reader.GetInt32(4),
reader.IsDBNull(5) ? -1 : reader.GetInt32(5),
reader.IsDBNull(6) ? -1 : reader.GetInt32(6),
reader.IsDBNull(7) ? -1 : reader.GetInt32(7)
),
reader.IsDBNull(8) ? "NULL" : reader.GetString(8)
);
//values = Tuple.Create(reader.GetString(1), values.Item2, values.Item3, values.Item4, values.Item5, values.Item6, values.Item7);
//values = Tuple.Create(values.Item1, reader.GetInt32(2), values.Item3, values.Item4, values.Item5, values.Item6, values.Item7);
//values = Tuple.Create(values.Item1, values.Item2, reader.GetInt32(3), values.Item4, values.Item5, values.Item6, values.Item7);
//values = Tuple.Create(values.Item1, values.Item2, values.Item3, reader.GetInt32(4), values.Item5, values.Item6, values.Item7);
//values = Tuple.Create(values.Item1, values.Item2, values.Item3, values.Item4, reader.GetInt32(5), values.Item6, values.Item7);
//values = Tuple.Create(values.Item1, values.Item2, values.Item3, values.Item4, values.Item5, reader.GetInt32(6), values.Item7);
//values = Tuple.Create(values.Item1, values.Item2, values.Item3, values.Item4, values.Item5, values.Item6, reader.GetInt32(7));
}
connection.Close();
return values;
}
//public static string[] RetrieveDirectories()
//{
//}
/*connectionString = @"Data Source=data\GameDirectories.db;Version=3;";
connection = new SQLiteConnection(connectionString);
connection.Open();*/
/*for(int i = 0; i < list.Length; i++)
{
string query = "UPDATE " + whichLibrary[0] + " SET " + whichLibrary[1] + " = '" + list[i] + "' WHERE id ='%'";
SQLiteCommand command = new SQLiteCommand(query, connection);
command.ExecuteNonQuery();
}*/
/*
for (int i = 0; i < list.Length; i++)
{
command.Parameters.Add(new SQLiteParameter("@" + whichLibrary[1], list[i]));
command.Parameters.Add(new SQLiteParameter("@id", i + 1));
command.ExecuteNonQuery();
command.Parameters.Clear();
}
*/
}
}