Add project files.
This commit is contained in:
32
Challenges/formAddChallenges.xaml
Normal file
32
Challenges/formAddChallenges.xaml
Normal file
@@ -0,0 +1,32 @@
|
||||
<Window x:Class="SportsTrainingApp.Challenges.formAddChallenges"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:SportsTrainingApp.Challenges"
|
||||
mc:Ignorable="d"
|
||||
Title="Добавить испытание" Height="150" Width="800" ResizeMode="NoResize" Icon="/free-icon-fitness-4729328.png" WindowStartupLocation="CenterScreen">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="0.5*"></RowDefinition>
|
||||
<RowDefinition ></RowDefinition>
|
||||
<RowDefinition ></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBox x:Name="tbName" Grid.Row="1" Grid.Column="0" Height="25" Margin="10"/>
|
||||
<TextBox x:Name="tbDescription" Grid.Row="1" Grid.Column="1" Height="25" Margin="10"/>
|
||||
<DatePicker x:Name="dtStart" Grid.Row="1" Grid.Column="2" Height="25" Margin="10"/>
|
||||
<DatePicker x:Name="dtEnd" Grid.Row="1" Grid.Column="3" Height="25" Margin="10"/>
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Text="Название" VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Center"/>
|
||||
<TextBlock Grid.Row="0" Grid.Column="1" Text="Описание" VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Center"/>
|
||||
<TextBlock Grid.Row="0" Grid.Column="2" Text="Дата начала" VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Center"/>
|
||||
<TextBlock Grid.Row="0" Grid.Column="3" Text="Дата окончания" VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Center"/>
|
||||
<Button Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" Height="25" Width="200" Content="Добавить" Click="Button_Click_1"/>
|
||||
<Button Grid.Column="2" Grid.Row="2" Grid.ColumnSpan="2" Height="25" Width="200" Content="Отмена" Click="Button_Click_2"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
46
Challenges/formAddChallenges.xaml.cs
Normal file
46
Challenges/formAddChallenges.xaml.cs
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
45
Challenges/formChallenges.xaml
Normal file
45
Challenges/formChallenges.xaml
Normal file
@@ -0,0 +1,45 @@
|
||||
<Window x:Class="SportsTrainingApp.Challenges.formChallenges"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:SportsTrainingApp.Challenges"
|
||||
mc:Ignorable="d"
|
||||
Title="Испытание" Height="450" Width="800" Icon="/free-icon-fitness-4729328.png" WindowStartupLocation="CenterScreen">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="0.2*"></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<DataGrid Grid.Column="0" Grid.Row="3" x:Name="gridChallenges" AutoGenerateColumns="False"
|
||||
ColumnWidth="*" Grid.ColumnSpan="3" Margin="10" IsReadOnly="True">
|
||||
<DataGrid.Resources>
|
||||
<Style TargetType="TextBlock" x:Key="WrapText">
|
||||
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
|
||||
</Style>
|
||||
<Style TargetType="DataGridColumnHeader">
|
||||
<Setter Property="HorizontalContentAlignment" Value="Center" />
|
||||
</Style>
|
||||
<Style TargetType="DataGridCell">
|
||||
<Setter Property="HorizontalContentAlignment" Value="Center" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Center" />
|
||||
</Style>
|
||||
</DataGrid.Resources>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="id" Binding="{Binding ID}" Visibility="Hidden" />
|
||||
<DataGridTextColumn Header="Название" Binding="{Binding Name}" />
|
||||
<DataGridTextColumn Header="Описание" Binding="{Binding Description}" ElementStyle="{StaticResource WrapText}"/>
|
||||
<DataGridTextColumn Header="Дата начала" Binding="{Binding Start_date}" ElementStyle="{StaticResource WrapText}"/>
|
||||
<DataGridTextColumn Header="Дата окончания" Binding="{Binding End_date}" ElementStyle="{StaticResource WrapText}"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<Button x:Name="btAddChallenges" Grid.Column="0" Grid.Row="0" Content="Добавить" Margin="10" Click="btAddChallenges_Click"/>
|
||||
<Button x:Name="btUpdChallenges" Grid.Column="1" Grid.Row="0" Content="Изменить" Margin="10" Click="btUpdChallenges_Click"/>
|
||||
<Button x:Name="btDelChallenges" Grid.Column="2" Grid.Row="0" Content="Удалить" Margin="10" Click="btDelChallenges_Click"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
96
Challenges/formChallenges.xaml.cs
Normal file
96
Challenges/formChallenges.xaml.cs
Normal file
@@ -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<Challenges>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
32
Challenges/formUpdChallenges.xaml
Normal file
32
Challenges/formUpdChallenges.xaml
Normal file
@@ -0,0 +1,32 @@
|
||||
<Window x:Class="SportsTrainingApp.Challenges.formUpdChallenges"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:SportsTrainingApp.Challenges"
|
||||
mc:Ignorable="d"
|
||||
Title="Изменить испытание" Height="150" Width="800" ResizeMode="NoResize" Icon="/free-icon-fitness-4729328.png" WindowStartupLocation="CenterScreen">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
<ColumnDefinition></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="0.5*"></RowDefinition>
|
||||
<RowDefinition ></RowDefinition>
|
||||
<RowDefinition ></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBox x:Name="tbName" Grid.Row="1" Grid.Column="0" Height="25" Margin="10"/>
|
||||
<TextBox x:Name="tbDescription" Grid.Row="1" Grid.Column="1" Height="25" Margin="10"/>
|
||||
<DatePicker x:Name="dtStart" Grid.Row="1" Grid.Column="2" Height="25" Margin="10"/>
|
||||
<DatePicker x:Name="dtEnd" Grid.Row="1" Grid.Column="3" Height="25" Margin="10"/>
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Text="Название" VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Center"/>
|
||||
<TextBlock Grid.Row="0" Grid.Column="1" Text="Описание" VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Center"/>
|
||||
<TextBlock Grid.Row="0" Grid.Column="2" Text="Дата начала" VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Center"/>
|
||||
<TextBlock Grid.Row="0" Grid.Column="3" Text="Дата окончания" VerticalAlignment="Center" HorizontalAlignment="Center" TextAlignment="Center"/>
|
||||
<Button Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" Height="25" Width="200" Content="Изменить" Click="Button_Click_1"/>
|
||||
<Button Grid.Column="2" Grid.Row="2" Grid.ColumnSpan="2" Height="25" Width="200" Content="Отмена" Click="Button_Click_2"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
49
Challenges/formUpdChallenges.xaml.cs
Normal file
49
Challenges/formUpdChallenges.xaml.cs
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user