diff --git a/Activity/formActivity.xaml b/Activity/formActivity.xaml
new file mode 100644
index 0000000..c7fe170
--- /dev/null
+++ b/Activity/formActivity.xaml
@@ -0,0 +1,58 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Activity/formActivity.xaml.cs b/Activity/formActivity.xaml.cs
new file mode 100644
index 0000000..ee74f00
--- /dev/null
+++ b/Activity/formActivity.xaml.cs
@@ -0,0 +1,141 @@
+using System.Windows;
+using System.Windows.Data;
+using Npgsql;
+using SportsTrainingApp.Activity;
+using SportsTrainingApp.Challenges;
+using SportsTrainingApp.Nutrition;
+
+namespace SportsTrainingApp
+{
+ ///
+ /// Interaction logic for formActivity.xaml
+ ///
+ public partial class formActivity : Window
+ {
+ int user_id = -1;
+ public formActivity(int _user_id)
+ {
+ InitializeComponent();
+ user_id = _user_id;
+ ShowCurUser(user_id);
+ FillDataGrid(user_id);
+ }
+
+ public class Workout
+ {
+ public int ID { get; set; }
+ public string? Name { get; set; }
+ public DateTime Date { get; set; }
+ public int Duration { get; set; }
+ public string? Intensity { get; set; }
+ public string? Notes { get; set; }
+ }
+
+ private void ShowCurUser(int _user_id)
+ {
+ using (var conn = new NpgsqlConnection(formMain.connectionString))
+ {
+ conn.Open();
+ using (var cmd = new NpgsqlCommand($@"SELECT
+ CONCAT(USERNAME, ' (email - ', EMAIL, ')')
+ FROM
+ DBO.USERS
+ WHERE
+ ID = {_user_id}", conn))
+ {
+ var reader = cmd.ExecuteReader();
+ if (reader.Read())
+ {
+ tbCurUser.Text += reader.GetString(0);
+ }
+ }
+ }
+ }
+
+ public void FillDataGrid(int _user_id)
+ {
+ using (var conn = new NpgsqlConnection(formMain.connectionString))
+ {
+ conn.Open();
+ using (var cmd = new NpgsqlCommand($@"SELECT
+ WORKOUTS.ID,
+ S.NAME,
+ DATE,
+ DURATION,
+ INTENSITY,
+ NOTES
+ FROM
+ DBO.WORKOUTS
+ LEFT JOIN DBO.SPORTS S ON S.ID = WORKOUTS.SPORT_ID
+ WHERE
+ USER_ID = {_user_id}
+ ORDER BY DATE", conn))
+ {
+ var reader = cmd.ExecuteReader();
+ var workouts = new List();
+ while (reader.Read())
+ {
+ workouts.Add(new Workout
+ {
+ ID = reader.GetInt32(0),
+ Name = reader.GetString(1),
+ Date = reader.GetDateTime(2),
+ Duration = reader.GetInt32(3),
+ Intensity = reader.GetString(4),
+ Notes = reader.GetString(5)
+ });
+ }
+ gridActivity.ItemsSource = workouts;
+ }
+ }
+ }
+
+ private void btnAddActivity_Click(object sender, RoutedEventArgs e)
+ {
+ new formAddActivity(user_id).ShowDialog();
+ FillDataGrid(user_id);
+ }
+
+ private void btnDelActivity_Click(object sender, RoutedEventArgs e)
+ {
+ var selectedItem = (Workout)gridActivity.SelectedItem;
+
+ if (selectedItem == null)
+ return;
+
+ using (var conn = new NpgsqlConnection(formMain.connectionString))
+ {
+ conn.Open();
+ using (var cmd = new NpgsqlCommand(@$"DELETE FROM DBO.WORKOUTS
+ WHERE
+ ID = {selectedItem.ID}",conn))
+ {
+ cmd.ExecuteNonQuery();
+ }
+ }
+ FillDataGrid(user_id);
+ }
+
+ private void btnUpdActivity_Click(object sender, RoutedEventArgs e)
+ {
+ var selectedItem = (Workout)gridActivity.SelectedItem;
+
+ if (selectedItem == null)
+ return;
+
+ new formUpdActivity(selectedItem).ShowDialog();
+
+ FillDataGrid(user_id);
+ }
+
+ private void btNutrition_Click(object sender, RoutedEventArgs e)
+ {
+ new formNutrition(user_id).ShowDialog();
+ }
+
+ private void btChallenges_Click(object sender, RoutedEventArgs e)
+ {
+ new formChallenges().ShowDialog();
+ }
+ }
+}
diff --git a/Activity/formAddActivity.xaml b/Activity/formAddActivity.xaml
new file mode 100644
index 0000000..ec13383
--- /dev/null
+++ b/Activity/formAddActivity.xaml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Activity/formAddActivity.xaml.cs b/Activity/formAddActivity.xaml.cs
new file mode 100644
index 0000000..b2debb5
--- /dev/null
+++ b/Activity/formAddActivity.xaml.cs
@@ -0,0 +1,93 @@
+using System.Windows;
+using System.Windows.Controls;
+using Npgsql;
+using static System.Runtime.InteropServices.JavaScript.JSType;
+
+namespace SportsTrainingApp.Activity
+{
+ ///
+ /// Interaction logic for formAddActivity.xaml
+ ///
+ public partial class formAddActivity : Window
+ {
+ int user_id = -1;
+ public formAddActivity(int _user_id)
+ {
+ InitializeComponent();
+ user_id = _user_id;
+ FillCbSports(cbSports);
+ dtPicker.SelectedDate = DateTime.Now;
+ }
+
+ public class SportType
+ {
+ public int id { get; set; }
+ public string name { get; set; }
+ }
+
+ public void FillCbSports(ComboBox cb)
+ {
+ var items = GetData();
+ cbSports.ItemsSource = items;
+ cbSports.DisplayMemberPath = "name";
+ cbSports.SelectedValuePath = "id";
+ cbSports.SelectedIndex = 0;
+ }
+
+ private List GetData()
+ {
+ var items = new List();
+ string query = "SELECT id, name FROM dbo.sports";
+
+ using (var connection = new NpgsqlConnection(formMain.connectionString))
+ {
+ connection.Open();
+ using (var command = new NpgsqlCommand(query, connection))
+ using (var reader = command.ExecuteReader())
+ {
+ while (reader.Read())
+ {
+ items.Add(new SportType
+ {
+ id = reader.GetInt32(0),
+ name = reader.GetString(1)
+ });
+ }
+ }
+ }
+ return items;
+ }
+
+ private void Button_Click_2(object sender, RoutedEventArgs e)
+ {
+ this.Close();
+ }
+
+ private void Button_Click_1(object sender, RoutedEventArgs e)
+ {
+ AddActivity();
+ }
+
+ private void AddActivity()
+ {
+ using (var conn = new NpgsqlConnection(formMain.connectionString))
+ {
+ conn.Open();
+
+ using (var cmd = new NpgsqlCommand("INSERT INTO dbo.workouts(user_id, sport_id, date, duration, intensity, notes) " +
+ "VALUES(@user_id, @sport_id, @date, @duration, @intensity, @note); ", conn))
+ {
+ cmd.Parameters.AddWithValue("user_id", user_id);
+ cmd.Parameters.AddWithValue("date", dtPicker.SelectedDate.Value);
+ cmd.Parameters.AddWithValue("sport_id", cbSports.SelectedValue);
+ cmd.Parameters.AddWithValue("duration", Convert.ToInt32(tbDuration.Text));
+ cmd.Parameters.AddWithValue("intensity", tbIntensivity.Text);
+ cmd.Parameters.AddWithValue("note", tbNote.Text);
+ cmd.ExecuteNonQuery();
+ }
+ this.Close();
+ }
+ }
+ }
+}
+
diff --git a/Activity/formUpdActivity.xaml b/Activity/formUpdActivity.xaml
new file mode 100644
index 0000000..915fab7
--- /dev/null
+++ b/Activity/formUpdActivity.xaml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Activity/formUpdActivity.xaml.cs b/Activity/formUpdActivity.xaml.cs
new file mode 100644
index 0000000..4bdecec
--- /dev/null
+++ b/Activity/formUpdActivity.xaml.cs
@@ -0,0 +1,102 @@
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using Npgsql;
+
+namespace SportsTrainingApp.Activity
+{
+ ///
+ /// Interaction logic for formUpdActivity.xaml
+ ///
+ public partial class formUpdActivity : Window
+ {
+ formActivity.Workout item;
+
+ public formUpdActivity(formActivity.Workout _item)
+ {
+ InitializeComponent();
+ item = _item;
+ FillFormFields(item);
+ }
+
+ private void FillFormFields(formActivity.Workout _item)
+ {
+ FillCbSports(cbSports);
+ for (int i = 0; i < cbSports.Items.Count; i++)
+ {
+ var sport = cbSports.Items[i] as SportType;
+ if (_item.Name == sport?.name.ToString())
+ {
+ cbSports.SelectedIndex = i;
+ }
+ }
+ dtPicker.SelectedDate = _item.Date;
+ tbDuration.Text = _item.Duration.ToString();
+ tbIntensivity.Text = _item.Intensity?.ToString();
+ tbNote.Text = _item.Notes?.ToString();
+ }
+
+ public class SportType
+ {
+ public int id { get; set; }
+ public string name { get; set; }
+ }
+
+ public void FillCbSports(ComboBox cb)
+ {
+ var items = GetData();
+ cbSports.ItemsSource = items;
+ cbSports.DisplayMemberPath = "name";
+ cbSports.SelectedValuePath = "id";
+ }
+
+ private List GetData()
+ {
+ var items = new List();
+ string query = "SELECT id, name FROM dbo.sports";
+
+ using (var connection = new NpgsqlConnection(formMain.connectionString))
+ {
+ connection.Open();
+ using (var command = new NpgsqlCommand(query, connection))
+ using (var reader = command.ExecuteReader())
+ {
+ while (reader.Read())
+ {
+ items.Add(new SportType
+ {
+ id = reader.GetInt32(0),
+ name = reader.GetString(1)
+ });
+ }
+ }
+ }
+ return items;
+ }
+
+ private void ButtonCancel_Click(object sender, RoutedEventArgs e)
+ {
+ this.Close();
+ }
+
+ private void ButtonUpd_Click(object sender, RoutedEventArgs e)
+ {
+ using (var conn = new NpgsqlConnection(formMain.connectionString))
+ {
+ conn.Open();
+ using(var cmd = new NpgsqlCommand(@$"UPDATE dbo.workouts
+ SET sport_id=@sport_id, date=@date, duration=@dur, intensity=@intensity, notes=@notes
+ WHERE id = {item.ID};", conn))
+ {
+ cmd.Parameters.AddWithValue("date", dtPicker.SelectedDate.Value);
+ cmd.Parameters.AddWithValue("sport_id", cbSports.SelectedValue);
+ cmd.Parameters.AddWithValue("dur", Convert.ToInt32(tbDuration.Text));
+ cmd.Parameters.AddWithValue("intensity", tbIntensivity.Text);
+ cmd.Parameters.AddWithValue("notes", tbNote.Text);
+ cmd.ExecuteNonQuery();
+ }
+ }
+ this.Close();
+ }
+ }
+}
diff --git a/App.xaml b/App.xaml
new file mode 100644
index 0000000..0320465
--- /dev/null
+++ b/App.xaml
@@ -0,0 +1,9 @@
+
+
+
+
+
diff --git a/App.xaml.cs b/App.xaml.cs
new file mode 100644
index 0000000..0b89c7a
--- /dev/null
+++ b/App.xaml.cs
@@ -0,0 +1,13 @@
+using System.Configuration;
+using System.Data;
+using System.Windows;
+
+namespace SportsTrainingApp;
+
+///
+/// Interaction logic for App.xaml
+///
+public partial class App : Application
+{
+}
+
diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs
new file mode 100644
index 0000000..cc29e7f
--- /dev/null
+++ b/AssemblyInfo.cs
@@ -0,0 +1,10 @@
+using System.Windows;
+
+[assembly:ThemeInfo(
+ ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
+ //(used if a resource is not found in the page,
+ // or application resource dictionaries)
+ ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
+ //(used if a resource is not found in the page,
+ // app, or any theme specific resource dictionaries)
+)]
diff --git a/Challenges/formAddChallenges.xaml b/Challenges/formAddChallenges.xaml
new file mode 100644
index 0000000..bd2b7df
--- /dev/null
+++ b/Challenges/formAddChallenges.xaml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Challenges/formAddChallenges.xaml.cs b/Challenges/formAddChallenges.xaml.cs
new file mode 100644
index 0000000..3525a0c
--- /dev/null
+++ b/Challenges/formAddChallenges.xaml.cs
@@ -0,0 +1,46 @@
+using System.Windows;
+using Npgsql;
+
+namespace SportsTrainingApp.Challenges
+{
+
+ public partial class formAddChallenges : Window
+ {
+
+ public formAddChallenges()
+ {
+ InitializeComponent();
+ dtStart.SelectedDate = DateTime.Now;
+ dtEnd.SelectedDate = DateTime.Now.AddDays(1);
+ }
+
+ private void AddChallenges()
+ {
+ using (var conn = new NpgsqlConnection(formMain.connectionString))
+ {
+ conn.Open();
+ using (var cmd = new NpgsqlCommand($@"INSERT INTO dbo.challenges(
+ name, description, start_date, end_date)
+ VALUES (@name, @description, @start_date, @end_date);", conn))
+ {
+ cmd.Parameters.AddWithValue("name", tbName.Text);
+ cmd.Parameters.AddWithValue("description", tbDescription.Text);
+ cmd.Parameters.AddWithValue("start_date", dtStart.SelectedDate);
+ cmd.Parameters.AddWithValue("end_date", dtEnd.SelectedDate);
+ cmd.ExecuteNonQuery();
+ }
+ this.Close();
+ }
+ }
+
+ private void Button_Click_1(object sender, RoutedEventArgs e)
+ {
+ AddChallenges();
+ }
+
+ private void Button_Click_2(object sender, RoutedEventArgs e)
+ {
+ this.Close();
+ }
+ }
+}
diff --git a/Challenges/formChallenges.xaml b/Challenges/formChallenges.xaml
new file mode 100644
index 0000000..44d596a
--- /dev/null
+++ b/Challenges/formChallenges.xaml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Challenges/formChallenges.xaml.cs b/Challenges/formChallenges.xaml.cs
new file mode 100644
index 0000000..c11711b
--- /dev/null
+++ b/Challenges/formChallenges.xaml.cs
@@ -0,0 +1,96 @@
+using Npgsql;
+using System.Windows;
+
+namespace SportsTrainingApp.Challenges
+{
+ public partial class formChallenges : Window
+ {
+
+ public formChallenges()
+ {
+ InitializeComponent();
+ FillDataGrid();
+ }
+
+ public class Challenges
+ {
+ public int ID { get; set; }
+ public string Name { get; set; }
+ public string Description { get; set; }
+ public DateTime Start_date { get; set; }
+ public DateTime End_date { get; set; }
+ }
+
+ public void FillDataGrid()
+ {
+ using (var conn = new NpgsqlConnection(formMain.connectionString))
+ {
+ conn.Open();
+ using (var cmd = new NpgsqlCommand($@"SELECT
+ ID,
+ NAME,
+ DESCRIPTION,
+ START_DATE,
+ END_DATE
+ FROM
+ DBO.CHALLENGES
+ ORDER BY
+ START_DATE", conn))
+ {
+ var reader = cmd.ExecuteReader();
+ var challenges = new List();
+ while (reader.Read())
+ {
+ challenges.Add(new Challenges
+ {
+ ID = reader.GetInt32(0),
+ Name = reader.GetString(1),
+ Description = reader.GetString(2),
+ Start_date = reader.GetDateTime(3),
+ End_date = reader.GetDateTime(4)
+ });
+ }
+ gridChallenges.ItemsSource = challenges;
+ }
+ }
+ }
+
+ private void btAddChallenges_Click(object sender, RoutedEventArgs e)
+ {
+ new formAddChallenges().ShowDialog();
+ FillDataGrid();
+ }
+
+ private void btDelChallenges_Click(object sender, RoutedEventArgs e)
+ {
+ var selectedItem = (Challenges)gridChallenges.SelectedItem;
+
+ if (selectedItem == null)
+ return;
+
+ using (var conn = new NpgsqlConnection(formMain.connectionString))
+ {
+ conn.Open();
+ using (var cmd = new NpgsqlCommand(@$"DELETE FROM DBO.CHALLENGES
+ WHERE
+ ID = {selectedItem.ID}", conn))
+ {
+ cmd.ExecuteNonQuery();
+ }
+ }
+ FillDataGrid();
+ }
+
+ private void btUpdChallenges_Click(object sender, RoutedEventArgs e)
+ {
+ var selectedItem = (Challenges)gridChallenges.SelectedItem;
+
+ if (selectedItem == null)
+ return;
+
+ new formUpdChallenges(selectedItem).ShowDialog();
+
+ FillDataGrid();
+ }
+ }
+}
diff --git a/Challenges/formUpdChallenges.xaml b/Challenges/formUpdChallenges.xaml
new file mode 100644
index 0000000..c88a833
--- /dev/null
+++ b/Challenges/formUpdChallenges.xaml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Challenges/formUpdChallenges.xaml.cs b/Challenges/formUpdChallenges.xaml.cs
new file mode 100644
index 0000000..b2358cc
--- /dev/null
+++ b/Challenges/formUpdChallenges.xaml.cs
@@ -0,0 +1,49 @@
+using System.Windows;
+using Npgsql;
+
+namespace SportsTrainingApp.Challenges
+{
+
+ public partial class formUpdChallenges : Window
+ {
+ formChallenges.Challenges item;
+ public formUpdChallenges(formChallenges.Challenges _item)
+ {
+ InitializeComponent();
+ item = _item;
+ FillFormFields(item);
+ }
+
+ private void FillFormFields(formChallenges.Challenges _item)
+ {
+ tbName.Text = _item.Name;
+ tbDescription.Text = _item.Description;
+ dtEnd.SelectedDate = _item.End_date.Date;
+ dtStart.SelectedDate = _item.Start_date.Date;
+ }
+
+ private void Button_Click_2(object sender, RoutedEventArgs e)
+ {
+ this.Close();
+ }
+
+ private void Button_Click_1(object sender, RoutedEventArgs e)
+ {
+ using (var conn = new NpgsqlConnection(formMain.connectionString))
+ {
+ conn.Open();
+ using (var cmd = new NpgsqlCommand(@$"UPDATE dbo.challenges
+ SET name=@name, description=@description, start_date=@start_date, end_date=@end_date
+ WHERE id = {item.ID};", conn))
+ {
+ cmd.Parameters.AddWithValue("name", tbName.Text);
+ cmd.Parameters.AddWithValue("description", tbDescription.Text);
+ cmd.Parameters.AddWithValue("start_date", dtStart.SelectedDate);
+ cmd.Parameters.AddWithValue("end_date", dtEnd.SelectedDate);
+ cmd.ExecuteNonQuery();
+ }
+ }
+ this.Close();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Nutrition/formAddNutrition.xaml b/Nutrition/formAddNutrition.xaml
new file mode 100644
index 0000000..6f18f19
--- /dev/null
+++ b/Nutrition/formAddNutrition.xaml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Nutrition/formAddNutrition.xaml.cs b/Nutrition/formAddNutrition.xaml.cs
new file mode 100644
index 0000000..5ec797a
--- /dev/null
+++ b/Nutrition/formAddNutrition.xaml.cs
@@ -0,0 +1,50 @@
+using System.Windows;
+using Npgsql;
+
+namespace SportsTrainingApp.Nutrition
+{
+ ///
+ /// Interaction logic for formAddNutrition.xaml
+ ///
+ public partial class formAddNutrition : Window
+ {
+ int user_id = -1;
+ public formAddNutrition(int _user_id)
+ {
+ InitializeComponent();
+ user_id = _user_id;
+ dtPicker.SelectedDate = DateTime.Now;
+ }
+
+ private void AddNutrition()
+ {
+ using (var conn = new NpgsqlConnection(formMain.connectionString))
+ {
+ conn.Open();
+ using (var cmd = new NpgsqlCommand($@"INSERT INTO dbo.nutrition(
+ user_id, date, calories, protein, carbs, fats)
+ VALUES (@user_id, @date, @calories, @protein, @carbs, @fats);", conn))
+ {
+ cmd.Parameters.AddWithValue("user_id", user_id);
+ cmd.Parameters.AddWithValue("date", dtPicker.SelectedDate.Value);
+ cmd.Parameters.AddWithValue("calories", Convert.ToInt32(tbCalories.Text));
+ cmd.Parameters.AddWithValue("protein", Convert.ToDouble(tbProtein.Text));
+ cmd.Parameters.AddWithValue("carbs", Convert.ToDouble(tbCarbs.Text));
+ cmd.Parameters.AddWithValue("fats", Convert.ToDouble(tbFats.Text));
+ cmd.ExecuteNonQuery();
+ }
+ this.Close();
+ }
+ }
+
+ private void Button_Click_1(object sender, RoutedEventArgs e)
+ {
+ AddNutrition();
+ }
+
+ private void Button_Click_2(object sender, RoutedEventArgs e)
+ {
+ this.Close();
+ }
+ }
+}
diff --git a/Nutrition/formNutrition.xaml b/Nutrition/formNutrition.xaml
new file mode 100644
index 0000000..5b2c799
--- /dev/null
+++ b/Nutrition/formNutrition.xaml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Nutrition/formNutrition.xaml.cs b/Nutrition/formNutrition.xaml.cs
new file mode 100644
index 0000000..e5178a4
--- /dev/null
+++ b/Nutrition/formNutrition.xaml.cs
@@ -0,0 +1,107 @@
+using Npgsql;
+using System.Windows;
+
+namespace SportsTrainingApp.Nutrition
+{
+ ///
+ /// Interaction logic for fromNutrition.xaml
+ ///
+ public partial class formNutrition : Window
+ {
+ int user_id = -1;
+ public formNutrition(int _user_id)
+ {
+ InitializeComponent();
+ user_id = _user_id;
+ FillDataGrid(user_id);
+
+ }
+ public class Nutrition
+ {
+ public int ID { get; set; }
+ public int User_id { get; set; }
+ public DateTime Date { get; set; }
+ public int Calories { get; set; }
+ public double Protein { get; set; }
+ public double Carbs { get; set; }
+ public double Fats { get; set; }
+ }
+
+ public void FillDataGrid(int _user_id)
+ {
+ using (var conn = new NpgsqlConnection(formMain.connectionString))
+ {
+ conn.Open();
+ using (var cmd = new NpgsqlCommand($@"SELECT
+ ID,
+ USER_ID,
+ DATE,
+ CALORIES,
+ PROTEIN,
+ CARBS,
+ FATS
+ FROM
+ DBO.NUTRITION
+ WHERE
+ USER_ID = {_user_id}
+ ORDER BY DATE", conn))
+ {
+ var reader = cmd.ExecuteReader();
+ var nutrition = new List();
+ while (reader.Read())
+ {
+ nutrition.Add(new Nutrition
+ {
+ ID = reader.GetInt32(0),
+ User_id = reader.GetInt32(1),
+ Date = reader.GetDateTime(2),
+ Calories = reader.GetInt32(3),
+ Protein = reader.GetDouble(4),
+ Carbs = reader.GetDouble(5),
+ Fats = reader.GetDouble(6)
+ });
+ }
+ gridNutrition.ItemsSource = nutrition;
+ }
+ }
+ }
+
+ private void btAddNutrition_Click(object sender, RoutedEventArgs e)
+ {
+ new formAddNutrition(user_id).ShowDialog();
+ FillDataGrid(user_id);
+ }
+
+ private void btDelNutrition_Click(object sender, RoutedEventArgs e)
+ {
+ var selectedItem = (Nutrition)gridNutrition.SelectedItem;
+
+ if (selectedItem == null)
+ return;
+
+ using (var conn = new NpgsqlConnection(formMain.connectionString))
+ {
+ conn.Open();
+ using (var cmd = new NpgsqlCommand(@$"DELETE FROM DBO.NUTRITION
+ WHERE
+ ID = {selectedItem.ID}", conn))
+ {
+ cmd.ExecuteNonQuery();
+ }
+ }
+ FillDataGrid(user_id);
+ }
+
+ private void btUpdNutrution_Click(object sender, RoutedEventArgs e)
+ {
+ var selectedItem = (Nutrition)gridNutrition.SelectedItem;
+
+ if (selectedItem == null)
+ return;
+
+ new formUpdNutrition(selectedItem).ShowDialog();
+
+ FillDataGrid(user_id);
+ }
+ }
+}
diff --git a/Nutrition/formUpdNutrition.xaml b/Nutrition/formUpdNutrition.xaml
new file mode 100644
index 0000000..bda1f34
--- /dev/null
+++ b/Nutrition/formUpdNutrition.xaml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Nutrition/formUpdNutrition.xaml.cs b/Nutrition/formUpdNutrition.xaml.cs
new file mode 100644
index 0000000..3b19392
--- /dev/null
+++ b/Nutrition/formUpdNutrition.xaml.cs
@@ -0,0 +1,54 @@
+using System.Windows;
+using Npgsql;
+
+namespace SportsTrainingApp.Nutrition
+{
+ ///
+ /// Interaction logic for formUpdNutrition.xaml
+ ///
+ public partial class formUpdNutrition : Window
+ {
+ formNutrition.Nutrition item;
+ public formUpdNutrition(formNutrition.Nutrition _item)
+ {
+ InitializeComponent();
+ item = _item;
+ FillFormFields(item);
+ }
+
+ private void FillFormFields(formNutrition.Nutrition _item)
+ {
+ dtPicker.SelectedDate = _item.Date;
+ tbCalories.Text = _item.Calories.ToString();
+ tbCarbs.Text = _item.Carbs.ToString();
+ tbProtein.Text = _item.Protein.ToString();
+ tbFats.Text = _item.Fats.ToString();
+ }
+
+ private void Button_Click_2(object sender, RoutedEventArgs e)
+ {
+ this.Close();
+ }
+
+ private void Button_Click_1(object sender, RoutedEventArgs e)
+ {
+ using (var conn = new NpgsqlConnection(formMain.connectionString))
+ {
+ conn.Open();
+ using (var cmd = new NpgsqlCommand(@$"UPDATE dbo.nutrition
+ SET user_id=@user_id, date=@date, calories=@calories, protein=@protein, carbs=@carbs, fats=@fats
+ WHERE id = {item.ID};", conn))
+ {
+ cmd.Parameters.AddWithValue("user_id", item.User_id);
+ cmd.Parameters.AddWithValue("date", dtPicker.SelectedDate.Value);
+ cmd.Parameters.AddWithValue("calories", Convert.ToInt32(tbCalories.Text));
+ cmd.Parameters.AddWithValue("protein", Convert.ToDouble(tbProtein.Text));
+ cmd.Parameters.AddWithValue("carbs", Convert.ToDouble(tbCarbs.Text));
+ cmd.Parameters.AddWithValue("fats", Convert.ToDouble(tbFats.Text));
+ cmd.ExecuteNonQuery();
+ }
+ }
+ this.Close();
+ }
+ }
+}
\ No newline at end of file
diff --git a/SportsTrainingApp.csproj b/SportsTrainingApp.csproj
new file mode 100644
index 0000000..993c9f2
--- /dev/null
+++ b/SportsTrainingApp.csproj
@@ -0,0 +1,41 @@
+
+
+
+ WinExe
+ net8.0-windows
+ enable
+ enable
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Code
+
+
+ Code
+
+
+ Code
+
+
+ Code
+
+
+
+
diff --git a/SportsTrainingApp.sln b/SportsTrainingApp.sln
new file mode 100644
index 0000000..e3c48b4
--- /dev/null
+++ b/SportsTrainingApp.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.13.35828.75 d17.13
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SportsTrainingApp", "SportsTrainingApp.csproj", "{76018E6A-7200-4E33-A2AE-152867198A3B}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {76018E6A-7200-4E33-A2AE-152867198A3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {76018E6A-7200-4E33-A2AE-152867198A3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {76018E6A-7200-4E33-A2AE-152867198A3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {76018E6A-7200-4E33-A2AE-152867198A3B}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {A06D3EF8-E3D3-4284-8150-A4FE3B0CCCEE}
+ EndGlobalSection
+EndGlobal
diff --git a/formLogin.xaml b/formLogin.xaml
new file mode 100644
index 0000000..6f0b804
--- /dev/null
+++ b/formLogin.xaml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/formLogin.xaml.cs b/formLogin.xaml.cs
new file mode 100644
index 0000000..02f7a4e
--- /dev/null
+++ b/formLogin.xaml.cs
@@ -0,0 +1,59 @@
+using System.Windows;
+using System;
+using Npgsql;
+
+namespace SportsTrainingApp
+{
+
+ public partial class formLogin : Window
+ {
+ formMain formMain;
+ public formLogin(formMain _formMain)
+ {
+ InitializeComponent();
+ formMain = _formMain;
+ }
+
+ private void Button_Click_2(object sender, RoutedEventArgs e)
+ {
+ this.Close();
+ }
+
+ private void Button_Click_1(object sender, RoutedEventArgs e)
+ {
+ int user_id = CheckUser(loginBox.Text, passwordBox.Password);
+ if (user_id != -1)
+ {
+ new formActivity(user_id).Show();
+ this.Close();
+ formMain.Close();
+ }
+ else
+ MessageBox.Show("Неверный логин/пароль!");
+ }
+
+ public static int CheckUser(string username, string password)
+ {
+ using (var conn = new NpgsqlConnection(formMain.connectionString))
+ {
+ conn.Open();
+
+ using (var cmd = new NpgsqlCommand("SELECT id FROM dbo.users WHERE username = @username " +
+ "AND password_hash = dbo.crypt(@password, password_hash)", conn))
+ {
+ cmd.Parameters.AddWithValue("username", username);
+ cmd.Parameters.AddWithValue("password", password);
+
+ using (var reader = cmd.ExecuteReader())
+ {
+ if (reader.Read())
+ {
+ return reader.GetInt32(0);
+ }
+ }
+ return -1;
+ }
+ }
+ }
+ }
+}
diff --git a/formMain.xaml b/formMain.xaml
new file mode 100644
index 0000000..d4a6a1b
--- /dev/null
+++ b/formMain.xaml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/formMain.xaml.cs b/formMain.xaml.cs
new file mode 100644
index 0000000..a9eadee
--- /dev/null
+++ b/formMain.xaml.cs
@@ -0,0 +1,26 @@
+using System.Windows;
+
+namespace SportsTrainingApp;
+
+///
+/// Interaction logic for MainWindow.xaml
+///
+public partial class formMain : Window
+{
+ public const string connectionString = "Host=192.168.0.110:5432;Username=KhasanovAM;Password=Admin123;Database=SportsTrainingApp";
+ public formMain()
+ {
+ InitializeComponent();
+ }
+
+ private void Button_Click_1(object sender, RoutedEventArgs e)
+ {
+ var formLogin = new formLogin(this);
+ formLogin.ShowDialog();
+ }
+
+ private void Button_Click_2(object sender, RoutedEventArgs e)
+ {
+ new formRegistration().ShowDialog();
+ }
+}
\ No newline at end of file
diff --git a/formRegistration.xaml b/formRegistration.xaml
new file mode 100644
index 0000000..ba1cabc
--- /dev/null
+++ b/formRegistration.xaml
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/formRegistration.xaml.cs b/formRegistration.xaml.cs
new file mode 100644
index 0000000..788cd4d
--- /dev/null
+++ b/formRegistration.xaml.cs
@@ -0,0 +1,53 @@
+using System.Windows;
+using Npgsql;
+
+namespace SportsTrainingApp
+{
+
+ public partial class formRegistration : Window
+ {
+ public formRegistration()
+ {
+ InitializeComponent();
+ }
+
+ private void Button_Click_ShowPass(object sender, RoutedEventArgs e)
+ {
+ MessageBox.Show($"Ваш пароль: {passwordBox.Password}");
+ }
+
+ private void Button_Click_Cancel(object sender, RoutedEventArgs e)
+ {
+ this.Close();
+ }
+
+ private void Button_Click_OK(object sender, RoutedEventArgs e)
+ {
+ if (loginBox.Text == "" || passwordBox.Password == "" || emailBox.Text == "")
+ {
+ MessageBox.Show("Введены не все данные.");
+ return;
+ }
+ CreateUser(loginBox.Text, passwordBox.Password, emailBox.Text);
+ this.Close();
+ }
+
+ private static void CreateUser(string username, string password, string email)
+ {
+ using (var conn = new NpgsqlConnection(formMain.connectionString))
+ {
+ conn.Open();
+
+ using (var cmd = new NpgsqlCommand("INSERT INTO dbo.users (username, email, password_hash) " +
+ "VALUES (@username, @email, dbo.crypt(@password, dbo.gen_salt('bf')))", conn))
+ {
+ cmd.Parameters.AddWithValue("username", username);
+ cmd.Parameters.AddWithValue("email", email);
+ cmd.Parameters.AddWithValue("password", password);
+ cmd.ExecuteNonQuery();
+ }
+ }
+ MessageBox.Show("Пользователь создан!");
+ }
+ }
+}
diff --git a/free-icon-fitness-4729328.png b/free-icon-fitness-4729328.png
new file mode 100644
index 0000000..cd1070f
Binary files /dev/null and b/free-icon-fitness-4729328.png differ