/SpeakPunchComfort
Created 1 year, 5 months ago...
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 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Packaging;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Media.Media3D;
namespace NEA___Fitness_Tracker
{
public partial class ongoing : Form
{
public string username;
private int hours = 0;
private int minutes = 0;
private int seconds = 0;
public int WorkoutID;
public string workout_name;
public string exercise_name = "";
public string added_exercise = "";
string _sSqlString;
public List<string> exercises = new List<string>();
List<Dictionary<string, object>> exerciseData = new List<Dictionary<string, object>>();
public ongoing(string username2)
{
InitializeComponent();
username = username2;
vScrollBar1.Value = flowLayoutPanel1.VerticalScroll.Value;
vScrollBar1.Minimum = flowLayoutPanel1.VerticalScroll.Minimum;
vScrollBar1.Maximum = flowLayoutPanel1.VerticalScroll.Maximum;
DurationTimer.Start();
}
private void ongoing_Load(object sender, EventArgs e)
{
}
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
flowLayoutPanel1.VerticalScroll.Value = vScrollBar1.Value;
}
private bool DataEntryCheck(List<object> weights_lifted, List<object> reps_completed)
{
try
{
for(int i = 0; i<weights_lifted.Count; i++)
{
if ((weights_lifted[i].ToString() != "" && reps_completed[i].ToString() == "") || (weights_lifted[i].ToString() == "" && reps_completed[i].ToString() != ""))
{
return false;
}
}
for (int i = 0; i < reps_completed.Count; i++)
{
if ((weights_lifted[i].ToString() != "" && reps_completed[i].ToString() == "") || (weights_lifted[i].ToString() == "" && reps_completed[i].ToString() != ""))
{
return false;
}
}
return true;
}
catch
{
return true;
}
}
private bool check_dataInt(List<object> weights_lifted, List<object> reps_completed)
{
foreach(object weight in weights_lifted)
{
if (weight.ToString() != "")
{
try
{
int.Parse(weight.ToString());
}
catch (Exception e)
{
return false;
}
}
}
foreach (object reps in reps_completed)
{
if (reps.ToString() != "")
{
try
{
int.Parse(reps.ToString());
}
catch (Exception e)
{
return false;
}
}
}
return true;
}
private int TotalSetsCompleted(List<object> weights_lifted)
{
int count = 0;
foreach(object item in weights_lifted)
{
if (item.ToString() != "")
{
count++;
}
}
return count;
}
private int total_weight(List<object> weights_lifted)
{
int total_weight = 0;
foreach(object item in weights_lifted)
{
try
{
total_weight += int.Parse(item.ToString());
}
catch(Exception e)
{
continue;
}
}
return total_weight;
}
private double calc_1repmax(List<object> weights_lifted, List<object> reps_completed)
{
List<int> weights_lifted_int = new List<int>();
double onerepmax = 0;
double multiplier = 1;
foreach(object item in weights_lifted)
{
try
{
weights_lifted_int.Add(int.Parse(item.ToString()));
}
catch(Exception E)
{
continue;
}
}
int highest_weight = weights_lifted_int.Max();
int position = weights_lifted_int.FindIndex(a => a==highest_weight);
int reps_completed_for_set = int.Parse((reps_completed[position]).ToString());
if (reps_completed_for_set == 1)
{
onerepmax = highest_weight;
}
else if(reps_completed_for_set > 1 && reps_completed_for_set <= 10)
{
multiplier = (0.0278 + ((0.002) * reps_completed_for_set));
}
else if(reps_completed_for_set > 10)
{
multiplier = (0.0278 + ((0.002) * 10));
}
onerepmax = (highest_weight / ((1.0278 - (multiplier * reps_completed_for_set))));
return onerepmax;
}
private string ConvertToString(List<Dictionary<string, object>> dataValues)
{
string final = "[";
bool first = true;
foreach(var data in dataValues)
{
if (!first)
{
final += ",";
}
final += "{";
foreach(var data2 in data)
{
final += $"\"{data2.Key}\": \"{data2.Value}\",";
}
if (data.Count > 0)
{
final = final.Remove(final.Length - 1);
}
final += "},";
}
if(dataValues.Count > 0)
{
final = final.Remove(final.Length - 1);
}
final += "]";
return final;
}
private async void button5_Click(object sender, EventArgs e)
{
DateTime today = DateTime.Today;
string date_today = today.ToString("dd/MM/yy");
string duration = label2.Text;
bool complete = false;
foreach (System.Windows.Forms.Control flowpanel in this.Controls)
{
if(flowpanel is System.Windows.Forms.FlowLayoutPanel)
{
int count = 0;
List<List<object>> data = DatabaseUtils.ReadData("SELECT * FROM HistoricalWorkouts");
if (data.Count == 0)
{
WorkoutID = 0;
}
else
{
data = DatabaseUtils.ReadData("SELECT MAX(WorkoutID) FROM HistoricalWorkouts");
WorkoutID = Convert.ToInt32(data[0][0]) + 1;
}
workout_name = (Controls.Find("workoutName", true).FirstOrDefault() as System.Windows.Forms.TextBox).Text;
_sSqlString = "INSERT INTO HistoricalWorkouts(WorkoutID, Username, WorkoutName, DateOf, Duration) " + "Values('" + WorkoutID + "','" + username + "', '" + workout_name + "', '" + date_today + "', '" + duration + "')";
DatabaseUtils.ExecuteSqlNonQuery(_sSqlString);
foreach (System.Windows.Forms.Control usercontrol in flowpanel.Controls)
{
count += 1;
}
if (count == 0)
{
warning.Text = "No workouts added detected, workout is being cancelled";
warning.Location = new System.Drawing.Point(23, 551);
warning.Font = new Font("Bauhaus 93", 9);
warning.Visible = true;
await Task.Delay(3000);
warning.Visible = false;
this.Close();
}
else
{
foreach (System.Windows.Forms.Control usercontrol in flowpanel.Controls)
{
List<object> weights_lifted = new List<object>();
List<object> reps_completed = new List<object>();
int count3 = 1;
bool continue1 = true;
while(continue1 == true)
{
string name1 = "KG" + count3.ToString();
System.Windows.Forms.TextBox KG_find = usercontrol.Controls.Find(name1, true).FirstOrDefault() as System.Windows.Forms.TextBox;
if(KG_find == null){
continue1 = false;
}
else
{
weights_lifted.Add(KG_find.Text);
}
count3++;
}
for(int i = 0; i<weights_lifted.Count; i++)
{
string name1 = "Reps" + (i + 1).ToString();
System.Windows.Forms.TextBox Reps = usercontrol.Controls.Find(name1, true).FirstOrDefault() as System.Windows.Forms.TextBox;
reps_completed.Add(Reps.Text);
}
bool data_check = check_dataInt(weights_lifted, reps_completed);
if (data_check == false)
{
warning.Text = "Check data entry, one may not be an integer";
warning.Location = new System.Drawing.Point(25, 551);
warning.Font = new Font("Bauhaus 93", 9);
warning.Visible = true;
await Task.Delay(3000);
warning.Visible = false;
break;
}
else if (data_check == true)
{
exercise_name = (usercontrol.Controls.Find("excName", true).FirstOrDefault() as System.Windows.Forms.Label).Text;
bool sets_completed = DataEntryCheck(weights_lifted, reps_completed);
if (sets_completed == false)
{
warning.Text = "Missing values detected, check data entries";
warning.Location = new System.Drawing.Point(25, 551);
warning.Font = new Font("Bauhaus 93", 9);
warning.Visible = true;
await Task.Delay(3000);
warning.Visible = false;
}
else
{
int totalsets = TotalSetsCompleted(weights_lifted);
int total_weightcalc = total_weight(weights_lifted);
double onerepmax = calc_1repmax(weights_lifted, reps_completed);
Dictionary <string, object> exerciseinfo = new Dictionary<string, object>()
{
{"Exercise Name",exercise_name },
{"Total Sets",totalsets },
{"Reps", reps_completed },
{"Weights", weights_lifted },
{"Total Weight", total_weightcalc },
{"1REPMAX", onerepmax }
};
exerciseData.Add(exerciseinfo);
List<Dictionary<string, object>> reps_completed2 = new List<Dictionary<string, object>>();
Dictionary<string, object> reps_completed3 = new Dictionary<string, object>();
for(int i = 0; i<reps_completed.Count; i++)
{
string name = "Set" + (i + 1).ToString();
reps_completed3.Add(name, reps_completed[i]);
}
reps_completed2.Add(reps_completed3);
List<Dictionary<string, object>> weights_lifted2 = new List<Dictionary<string, object>>();
Dictionary<string, object> weights_lifted3 = new Dictionary<string, object>();
for (int i = 0; i < reps_completed.Count; i++)
{
string name = "Set" + (i + 1).ToString();
weights_lifted3.Add(name, weights_lifted[i]);
}
weights_lifted2.Add(weights_lifted3);
_sSqlString = "INSERT INTO ExerciseInfo(WorkoutID, ExcName, TotalSets, Reps, Weights, TotalWeight, [1REPMAX]) " + "VALUES('" + WorkoutID + "', '" + exercise_name + "', '" + totalsets + "', '" + ConvertToString(reps_completed2) + "', '" + ConvertToString(weights_lifted2) + "', '" + total_weightcalc + "', '" + onerepmax + "')";
DatabaseUtils.ExecuteSqlNonQuery(_sSqlString);
_sSqlString = $"UPDATE UserProfile SET TotalWorkouts = TotalWorkouts + 1 WHERE username = '{username}';";
DatabaseUtils.ExecuteSqlNonQuery(_sSqlString);
complete = true;
}
}
}
}
}
}
if(complete == true)
{
warning.Text = "Workout successfully saved";
warning.Location = new System.Drawing.Point(25, 551);
warning.Font = new Font("Bauhaus 93", 15);
warning.Visible = true;
await Task.Delay(3000);
warning.Visible = false;
}
this.Close();
}
private void button4_Click(object sender, EventArgs e)
{
var confirmation = new confirmation(username);
confirmation.Show();
}
private void button3_Click(object sender, EventArgs e)
{
addexercise add = new addexercise(username);
add.DataTransferred += ongoing_datareceived;
add.Show();
}
private void UserControl_DeleteClicked(object sender, string exercise)
{
exercises.Remove(exercise);
}
private async void ongoing_datareceived(object sender, string data)
{
added_exercise = data;
int index = exercises.IndexOf(added_exercise);
if (index == -1)
{
ongoing_control control = new ongoing_control(added_exercise);
control.DeleteClicked += UserControl_DeleteClicked;
control.Name = added_exercise.ToString();
exercises.Add(added_exercise);
flowLayoutPanel1.Controls.Add(control);
Form addexercise = System.Windows.Forms.Application.OpenForms["addexercise"];
if (addexercise != null)
{
addexercise.Close();
}
}
else
{
warning.Text = "EXERCISE ALREADY EXISTS";
warning.Location = new System.Drawing.Point(25, 551);
warning.Font = new Font("Bauhaus 93", 15);
warning.Visible = true;
await Task.Delay(3000);
warning.Visible = false;
}
}
private void DurationTimer_Tick(object sender, EventArgs e)
{
seconds++;
if(seconds >= 60)
{
seconds = 0;
minutes++;
if(minutes >= 60)
{
minutes = 0;
hours++;
}
}
label2.Text = $"{hours:D2}:{minutes:D2}:{seconds:D2}";
}
private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
}
}