?
This commit is contained in:
commit
2633d93ee7
@ -19,6 +19,8 @@ namespace StudentManager
|
||||
protected override void RegisterTypes(IContainerRegistry containerRegistry)
|
||||
{
|
||||
containerRegistry.RegisterForNavigation<MainEditor, Students>();
|
||||
containerRegistry.RegisterForNavigation<StudentsView>();
|
||||
containerRegistry.RegisterForNavigation<QuestionsView>();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,14 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StudentManager.Common
|
||||
{
|
||||
static class Tables
|
||||
{
|
||||
static public string UserTable { get; } = "users";
|
||||
static public string QuesTable { get; } = "questions";
|
||||
static public string UQTable { get; } = "user_data";
|
||||
}
|
||||
|
||||
|
||||
public static class SQLMapping
|
||||
{
|
||||
public static void Mapping<T>(MySqlDataReader reader)
|
||||
@ -22,7 +30,6 @@ namespace StudentManager.Common
|
||||
{
|
||||
if (typeof(T) == typeof(StudentData))
|
||||
{
|
||||
|
||||
(data as StudentData).UID = (int)reader[0];
|
||||
(data as StudentData).Name = reader[1].ToString();
|
||||
(data as StudentData).Gender = reader[2].ToString();
|
||||
@ -30,9 +37,21 @@ namespace StudentManager.Common
|
||||
(data as StudentData).Address = reader[4].ToString();
|
||||
(data as StudentData).Grade = (int)reader[5];
|
||||
}
|
||||
else
|
||||
else if(typeof(T) == typeof(QuestionData))
|
||||
{
|
||||
|
||||
DifficultyLevel dLevel = DifficultyLevel.easy;
|
||||
QStatus qStatus = QStatus.published;
|
||||
(data as QuestionData).Id = (int)reader[0];
|
||||
(data as QuestionData).Type = reader[1].ToString();
|
||||
(data as QuestionData).Stem = reader[2].ToString();
|
||||
(data as QuestionData).Answer = reader[3].ToString();
|
||||
Enum.TryParse(reader[4].ToString(), true, out dLevel);
|
||||
(data as QuestionData).DifficultyLevel = dLevel;
|
||||
(data as QuestionData).Category = reader[5].ToString();
|
||||
(data as QuestionData).Tags = reader[6].ToString();
|
||||
(data as QuestionData).Source = reader[7].ToString();
|
||||
Enum.TryParse(reader[8].ToString(), true, out qStatus);
|
||||
(data as QuestionData).Status = qStatus;
|
||||
}
|
||||
|
||||
|
||||
@ -62,28 +81,81 @@ namespace StudentManager.Common
|
||||
// update ** set ** = '**',... where ** = **;
|
||||
// insert into ** values('**','**'...);
|
||||
// delete from ** where ** = **;
|
||||
public static List<T> Query<T>(string tableName, params string[] queryParams) where T : IDataCommon, new()
|
||||
public static List<T> Query<T>(string tableName, int id = -1, params string[] queryParams) where T : IDataCommon, new()
|
||||
{
|
||||
connection = new MySqlConnection(config);
|
||||
|
||||
List<T> result = new List<T>();
|
||||
|
||||
string idName = typeof(T) == typeof(StudentData) ? Tables.UserTable : Tables.QuesTable;
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
string queryStr = "";
|
||||
if (queryParams.Length > 0)
|
||||
queryStr = $"select * from {tableName};";
|
||||
{
|
||||
string filedList = string.Join(",", queryParams);
|
||||
queryStr = $"select {filedList} from {tableName};";
|
||||
|
||||
if (id != -1)
|
||||
queryStr = $@"select {filedList} from {tableName} WHERE {idName} = {id};";
|
||||
}
|
||||
else
|
||||
{
|
||||
queryStr = $"select * from {tableName};";
|
||||
if (id != -1)
|
||||
queryStr = $@"select * from {tableName} WHERE {idName} = {id};";
|
||||
}
|
||||
|
||||
cmd = new MySqlCommand(queryStr, connection);
|
||||
MySqlDataReader reader = cmd.ExecuteReader();
|
||||
|
||||
|
||||
T row = new T();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
T row = new T();
|
||||
SQLMapping.Mapping(row, reader);
|
||||
result.Add(row);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Dispose();
|
||||
connection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<T> UnionQuery<T>(int id = -1, string tableName = "questions", string otherTable = "user_data") where T : IDataCommon, new()
|
||||
{
|
||||
connection = new MySqlConnection(config);
|
||||
|
||||
List<T> result = new List<T>();
|
||||
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
string queryStr = "";
|
||||
if(id == -1)
|
||||
queryStr = $@"SELECT u.user_id, q.* FROM {otherTable} u JOIN {tableName} q ON u.problem_id = q.problem_id";
|
||||
else
|
||||
queryStr = $@"SELECT q.* FROM {tableName} q JOIN {otherTable} u ON q.problem_id = u.problem_id WHERE u.user_id = {id}";
|
||||
|
||||
cmd = new MySqlCommand(queryStr, connection);
|
||||
MySqlDataReader reader = cmd.ExecuteReader();
|
||||
|
||||
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
T row = new T();
|
||||
SQLMapping.Mapping(row, reader);
|
||||
result.Add(row);
|
||||
}
|
||||
|
38
StudentManager/Data/QuestionData.cs
Normal file
38
StudentManager/Data/QuestionData.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StudentManager.Data
|
||||
{
|
||||
public enum DifficultyLevel
|
||||
{
|
||||
easy,
|
||||
medium,
|
||||
hard,
|
||||
}
|
||||
|
||||
public enum QStatus
|
||||
{
|
||||
published,
|
||||
pending_review,
|
||||
deprecated,
|
||||
}
|
||||
|
||||
public class QuestionData : IDataCommon
|
||||
{
|
||||
public int Id { get; set; } = 0;
|
||||
public string Type { get; set; } = string.Empty;
|
||||
public string Stem { get; set; } = string.Empty;
|
||||
public string Answer { get; set; } = String.Empty;
|
||||
public DifficultyLevel DifficultyLevel { get; set; } = DifficultyLevel.easy;
|
||||
public string Category { get; set; } = string.Empty;
|
||||
public string Tags { get; set; } = string.Empty;
|
||||
public string Source { get; set; } = string.Empty;
|
||||
public QStatus Status { get; set; } = QStatus.published;
|
||||
|
||||
|
||||
public string TableName { get => "questions"; set => throw new NotImplementedException(); }
|
||||
}
|
||||
}
|
@ -14,6 +14,8 @@ namespace StudentManager.Data
|
||||
public string Contact { get; set; } = "Contact";
|
||||
public string Address { get; set; } = "Address";
|
||||
public int Grade { get; set; } = 1;
|
||||
public int TotalsQuestions { get; set; } = 0;
|
||||
public int CorrectionCount { get; set; } = 0;
|
||||
|
||||
|
||||
|
||||
|
@ -4,32 +4,25 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:StudentManager.Editor"
|
||||
xmlns:prism="http://prismlibrary.com/"
|
||||
xmlns:extent="clr-namespace:StudentManager.Extensions"
|
||||
mc:Ignorable="d"
|
||||
Title="MainEditor" Height="450" Width="800">
|
||||
<Window.Resources>
|
||||
<Style x:Key="TextStyle" TargetType="{x:Type TextBlock}">
|
||||
<Setter Property="Margin" Value="10,5"/>
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
|
||||
<Grid>
|
||||
<ListBox ItemsSource="{Binding StudentDatas}">
|
||||
<!--<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="SelectionChanged">
|
||||
<i:InvokeCommandAction x:Name="menuTrigger" Command="{Binding navigateCommand}" CommandParameter="{Binding ElementName=menu, Path=SelectedItem}"/>
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>-->
|
||||
<ListBox.ItemTemplate>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="200"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<ItemsControl ItemsSource="{Binding MenuBars}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding UID}"/>
|
||||
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding Name}"/>
|
||||
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding Gender}"/>
|
||||
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding Contact}"/>
|
||||
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding Address}"/>
|
||||
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding Grade}"/>
|
||||
</StackPanel>
|
||||
<Button Content="{Binding Title}" Command="{Binding DataContext.RegionTo, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
|
||||
CommandParameter="{Binding NameSpace}"/>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<ContentControl Grid.Column="1" prism:RegionManager.RegionName="{x:Static extent:PrismManager.MainRegionName}"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
38
StudentManager/Editor/QuestionsView.xaml
Normal file
38
StudentManager/Editor/QuestionsView.xaml
Normal file
@ -0,0 +1,38 @@
|
||||
<UserControl x:Class="StudentManager.Editor.QuestionsView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:StudentManager.Editor"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<UserControl.Resources>
|
||||
<Style x:Key="TextStyle" TargetType="{x:Type TextBlock}">
|
||||
<Setter Property="Margin" Value="10,5"/>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<ListBox ItemsSource="{Binding QuestionDatas}">
|
||||
<!--<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="SelectionChanged">
|
||||
<i:InvokeCommandAction x:Name="menuTrigger" Command="{Binding navigateCommand}" CommandParameter="{Binding ElementName=menu, Path=SelectedItem}"/>
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>-->
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Id}"/>
|
||||
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Type}"/>
|
||||
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Stem}"/>
|
||||
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Answer}"/>
|
||||
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding DifficultyLevel}"/>
|
||||
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Category}"/>
|
||||
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Tags}"/>
|
||||
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Source}"/>
|
||||
<TextBlock Width="50" Style="{StaticResource TextStyle}" Text="{Binding Status}"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</Grid>
|
||||
</UserControl>
|
28
StudentManager/Editor/QuestionsView.xaml.cs
Normal file
28
StudentManager/Editor/QuestionsView.xaml.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace StudentManager.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// QuestionsView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class QuestionsView : UserControl
|
||||
{
|
||||
public QuestionsView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
37
StudentManager/Editor/StudentsView.xaml
Normal file
37
StudentManager/Editor/StudentsView.xaml
Normal file
@ -0,0 +1,37 @@
|
||||
<UserControl x:Class="StudentManager.Editor.StudentsView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:StudentManager.Editor"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<UserControl.Resources>
|
||||
<Style x:Key="TextStyle" TargetType="{x:Type TextBlock}">
|
||||
<Setter Property="Margin" Value="10,5"/>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<ListBox ItemsSource="{Binding StudentDatas}">
|
||||
<!--<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="SelectionChanged">
|
||||
<i:InvokeCommandAction x:Name="menuTrigger" Command="{Binding navigateCommand}" CommandParameter="{Binding ElementName=menu, Path=SelectedItem}"/>
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>-->
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding UID}"/>
|
||||
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding Name}"/>
|
||||
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding Gender}"/>
|
||||
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding Contact}"/>
|
||||
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding Address}"/>
|
||||
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding Grade}"/>
|
||||
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding TotalsQuestions}"/>
|
||||
<TextBlock Style="{StaticResource TextStyle}" Text="{Binding CorrectionCount}"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</Grid>
|
||||
</UserControl>
|
28
StudentManager/Editor/StudentsView.xaml.cs
Normal file
28
StudentManager/Editor/StudentsView.xaml.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace StudentManager.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// StudentsView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class StudentsView : UserControl
|
||||
{
|
||||
public StudentsView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
13
StudentManager/Extensions/PrismManager.cs
Normal file
13
StudentManager/Extensions/PrismManager.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StudentManager.Extensions
|
||||
{
|
||||
public static class PrismManager
|
||||
{
|
||||
public static readonly string MainRegionName = "MainRegion";
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
using StudentManager.Common;
|
||||
using Mysqlx.Crud;
|
||||
using StudentManager.Common;
|
||||
using StudentManager.Data;
|
||||
using StudentManager.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@ -9,26 +11,98 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StudentManager.Model
|
||||
{
|
||||
public class Students
|
||||
class MenuBar : BindableBase
|
||||
{
|
||||
private string icon;
|
||||
/// <summary>
|
||||
/// Icon
|
||||
/// </summary>
|
||||
public string Icon
|
||||
{
|
||||
get { return icon; }
|
||||
set { icon = value; }
|
||||
}
|
||||
|
||||
private string title;
|
||||
|
||||
public string Title
|
||||
{
|
||||
get { return title; }
|
||||
set { title = value; }
|
||||
}
|
||||
|
||||
|
||||
private string nameSpace;
|
||||
|
||||
public string NameSpace
|
||||
{
|
||||
get { return nameSpace; }
|
||||
set { nameSpace = value; }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class Students : BindableBase
|
||||
{
|
||||
|
||||
private ObservableCollection<StudentData> studentDatas = new ObservableCollection<StudentData>();
|
||||
public ReadOnlyObservableCollection<StudentData> StudentDatas { get; private set; }
|
||||
|
||||
private ObservableCollection<QuestionData> questionDatas = new ObservableCollection<QuestionData>();
|
||||
public ReadOnlyObservableCollection<QuestionData> QuestionDatas { get; private set; }
|
||||
|
||||
Students()
|
||||
private ObservableCollection<MenuBar> menuBars = new ObservableCollection<MenuBar>();
|
||||
public ReadOnlyObservableCollection<MenuBar> MenuBars { get; private set; }
|
||||
|
||||
private readonly IRegionManager regionManager;
|
||||
|
||||
public DelegateCommand<string> RegionTo { get; set; }
|
||||
|
||||
Students(IRegionManager regionManager)
|
||||
{
|
||||
StudentDatas = new ReadOnlyObservableCollection<StudentData>(studentDatas);
|
||||
CreateMenuBar();
|
||||
|
||||
RegionTo = new DelegateCommand<string>((x) => {
|
||||
regionManager.Regions[PrismManager.MainRegionName].RequestNavigate(x.ToString());
|
||||
RegionToStudents();
|
||||
});
|
||||
|
||||
|
||||
StudentDatas = new ReadOnlyObservableCollection<StudentData>(studentDatas);
|
||||
QuestionDatas = new ReadOnlyObservableCollection<QuestionData>(questionDatas);
|
||||
MenuBars = new ReadOnlyObservableCollection<MenuBar>(menuBars);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
this.regionManager = regionManager;
|
||||
|
||||
QueryAll();
|
||||
|
||||
Query();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void Query()
|
||||
private void RegionToStudents()
|
||||
{
|
||||
SQLHelper.Query<StudentData>("users").ForEach(x => studentDatas.Add(x));
|
||||
|
||||
}
|
||||
|
||||
void CreateMenuBar()
|
||||
{
|
||||
menuBars.Add(new MenuBar() { Icon = "ForumPlusOutline", Title = "学生", NameSpace = "StudentsView" });
|
||||
menuBars.Add(new MenuBar() { Icon = "CodeGreaterThanOrEqual", Title = "题库", NameSpace = "QuestionsView" });
|
||||
}
|
||||
|
||||
|
||||
private void QueryAll()
|
||||
{
|
||||
studentDatas.Clear();
|
||||
questionDatas.Clear();
|
||||
SQLHelper.Query<StudentData>(Tables.UserTable).ForEach(x => studentDatas.Add(x));
|
||||
SQLHelper.Query<QuestionData>(Tables.QuesTable).ForEach(x => questionDatas.Add(x));
|
||||
//SQLHelper.UnionQuery<QuestionData>(1).ForEach(x => questionDatas.Add(x));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,22 @@
|
||||
<Compile Update="Editor\MainEditor.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="Editor\QuestionsView.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="Editor\StudentsView.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="Editor\MainEditor.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Update="Editor\QuestionsView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Update="Editor\StudentsView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user