Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
some fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Step1532 committed Jan 12, 2019
1 parent dd69af0 commit 0325b58
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 68 deletions.
12 changes: 10 additions & 2 deletions LimpStats.Client/CustomControls/Blocks/StudentGroupBlock.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@ public StudentGroupBlock(IViewNavigateService navigateService)

public void AddGroupToPanel(object sender, RoutedEventArgs e)
{
GroupListPanel.Children.Add(new StudentGroupPreview(this, FilePath.Text, _navigateService));
var cards = JsonBackupManager.LoadCardName();
if (cards.Contains(FilePath.Text))
{
MessageBox.Show($"The name of group must be unique!");
}
else
{
GroupListPanel.Children.Add(new StudentGroupPreview(this, FilePath.Text, _navigateService));

FilePath.Text = string.Empty;
FilePath.Text = string.Empty;
}
}

private void FilePath_OnGotFocus(object sender, RoutedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public StudentPackBlock(StudyGroup users, string groupTitle, IViewNavigateServic

public void OnClick_UpdatePanel(object sender, RoutedEventArgs e)
{
foreach (var pack in _users.ProblemPackList)
{
if (pack.PackTitle == PackTitleInput.Text)
{
MessageBox.Show($"The name of group must be unique!");
return;
}
}
var packWindow = new ProblemPackWindow(PackTitleInput.Text, _users, this, _groupTitle, _navigateService);
packWindow.Show();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using LimpStats.Client.Tools;
using LimpStats.Core.Parsers;

namespace LimpStats.Client.CustomControls
Expand All @@ -18,18 +21,28 @@ public ProblemTaskPreview(ProblemPackWindow problemPackWindow, string number)
_problemPackWindow.PanelViewer.ScrollToEnd();
textbox.Focus();
}


private void FilePath_OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
IsEnabled = false;
string num = Core.Tools.Tools.GenerateNextNumber(NumberTask.Content.ToString());
_problemPackWindow.Panel.Children.Add(new ProblemTaskPreview(_problemPackWindow, num));
//TODO: add try-catch
TaskName.Content = Parser.GetTitleTask(number: int.Parse(textbox.Text));
try
{
var n = int.Parse(textbox.Text);
TaskName.Content = Parser.GetTitleTask(n);
}
catch (Exception exception)
{
MessageBox.Show($"{exception}");
}

}
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

<ScrollViewer
Name="PanelViewer"
MaxWidth="600"
MaxWidth="560"
Margin="0,0,0,34"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Visible">
<StackPanel
x:Name="Panel"
Width="492"
Height="569"
Height="535"
MinWidth="300"
MinHeight="400"
HorizontalAlignment="Left"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ public ProblemPackWindow(string packTitle, StudyGroup group, StudentPackBlock bl

private void ButtonAddPack(object sender, RoutedEventArgs e)
{
var taskList = new List<int>();

foreach (ProblemTaskPreview task in Panel.Children.OfType<ProblemTaskPreview>())
{
taskList.Add(int.Parse(task.textbox.Text == "" ? "0" : task.textbox.Text));
}
var taskList = Panel
.Children
.OfType<ProblemTaskPreview>()
.Where(text => text.textbox.Text != "")
.Select(task => int.Parse(task.textbox.Text))
.ToList();


_group.ProblemPackList.Add(new ProblemPackInfo(_packTitle, taskList));
JsonBackupManager.SaveCardUserList(_group, _groupTitle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,23 @@
Name="UpdateButton"
Canvas.Right="0"
Width="25"
Height="25"
Height="33"
HorizontalAlignment="Left"
Click="ButtonClick_Update"
Content="🔄" Background="#FF993333" Foreground="#FFE8E8E8" />
Content="🔄" Background="#FF993333" Foreground="#FFE8E8E8" Canvas.Left="175" />
<Button
Name="CardTitle"
Width="159"
Height="25"
Width="160"
Height="33"
Background="#FF993333"
Click="CardTitle_OnClick"
DataContext="PackTitle" Foreground="#FFE8E8E8" Style="{DynamicResource packtitlestyle}" FontFamily="Century Gothic" />
<Button
Canvas.Top="25"
Width="200"
Height="19"
Click="AddUserButton_OnClick"
Content="AddUser" Background="#FF993333" Foreground="#FFE8E8E8" />
<ListBox
Name="StudentList"
SelectionChanged="LimpUserStatistic"
Canvas.Top="44"
Canvas.Top="33"
Width="200"
Height="206"
Height="217"
MinHeight="50" Background="#FF4F7BBA" Style="{DynamicResource ListBoxStyle1}" ItemContainerStyle="{DynamicResource ListBoxItemStyle1}" ItemTemplate="{DynamicResource DataTemplate1}"
/>
<Menu
Expand All @@ -148,8 +142,8 @@
Height="25"
VerticalAlignment="Top">
<MenuItem
Width="18"
Height="25"
Width="15"
Height="32"
Header=""
RenderTransformOrigin="0.05,0.56" Background="#FF993333" Foreground="#FFE8E8E8">
<MenuItem Header="Rename" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,25 @@ public ProblemTasksPreview(StudentPackBlock studentPackBlock, StudyGroup users,

_studentPackBlock = studentPackBlock;
_group = users;
GroupTitle = packTitle;
this.packTitle = packTitle;
CardTitle.DataContext = packTitle;
if (_group == null)
{
_group = new StudyGroup
{
UserList = new List<LimpUser>(),
ProblemPackList = new List<ProblemPackInfo>
{
new ProblemPackInfo(packTitle, TaskPackStorage.TasksAGroup)
}
};
}
//if (_group == null)
//{
// _group = new StudyGroup
// {
// UserList = new List<LimpUser>(),
// ProblemPackList = new List<ProblemPackInfo>
// {
// new ProblemPackInfo(packTitle, TaskPackStorage.TasksAGroup)
// }
// };
//}
var studentsData = ProfilePreviewData.GetProfilePackPreview(_group, packTitle);
ThreadingTools.ExecuteUiThread(() => StudentList.ItemsSource = studentsData);

}

//TODO: check this. GroupTitle? Or packTitle?
public string GroupTitle { get; }
public string packTitle { get; }

private void ButtonClick_Update(object sender, RoutedEventArgs e)
{
Expand All @@ -63,7 +65,7 @@ public void Update()
MultiThreadParser.LoadProfiles(_group);
IEnumerable<ProfilePreviewData> studentsData = new List<ProfilePreviewData>();

studentsData = ProfilePreviewData.GetProfilePackPreview(_group, GroupTitle);
studentsData = ProfilePreviewData.GetProfilePackPreview(_group, packTitle);

ThreadingTools.ExecuteUiThread(() => StudentList.ItemsSource = studentsData);
ThreadingTools.ExecuteUiThread(() => UpdateButton.IsEnabled = true);
Expand All @@ -80,10 +82,6 @@ private void LimpUserStatistic(object sender, SelectionChangedEventArgs e)
}
}

private void AddUserButton_OnClick(object sender, RoutedEventArgs e)
{
//TODO:
}

private void ButtonDeleteCard(object sender, RoutedEventArgs e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@ public StudentGroupPreview(StudentGroupBlock studentGroupBlock, string studentGr
CardTitle.DataContext = _studentGroupTitle;
_studentGroupBlock = studentGroupBlock;

//TODO: remove saving?
JsonBackupManager.SaveCardName(studentGroupTitle);
_group = JsonBackupManager.LoadCardUserList(studentGroupTitle);

var studentsData = ProfilePreviewData.GetProfilePreview(_group);
ThreadingTools.ExecuteUiThread(() => StudentList.ItemsSource = studentsData);


AddAnimation();

//TODO: temp solution, remove
Expand All @@ -55,6 +52,9 @@ public StudentGroupPreview(StudentGroupBlock studentGroupBlock, string studentGr
};
}

var studentsData = ProfilePreviewData.GetProfilePreview(_group);
ThreadingTools.ExecuteUiThread(() => StudentList.ItemsSource = studentsData);

StudentList.SelectionChanged += LimpUserStatistic;
}

Expand Down Expand Up @@ -100,6 +100,7 @@ private void Update()

ThreadingTools.ExecuteUiThread(() => StudentList.ItemsSource = studentsData);
ThreadingTools.ExecuteUiThread(() => UpdateButton.IsEnabled = true);
JsonBackupManager.SaveCardUserList(_group, _studentGroupTitle);
}

private void LimpUserStatistic(object sender, SelectionChangedEventArgs e)
Expand Down
5 changes: 4 additions & 1 deletion LimpStats.Client/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="250"
Grid.Row="0"/>
Grid.Row="0">
<Button Height="30" Content = "Clear Cache" Click="ButtonCleanCache_OnClick"/>
<Button Height="30" Content = "Home" Click="ButtonHome_OnClick"/>
</StackPanel>
<UserControl
x:Name="MainWindowContent"
Grid.Column="1"
Expand Down
14 changes: 13 additions & 1 deletion LimpStats.Client/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
using LimpStats.Client.CustomControls;
using LimpStats.Client.CustomControls.Blocks;
using LimpStats.Client.Tools;
using LimpStats.Database;

namespace LimpStats.Client
{
public partial class MainWindow : Window, IViewNavigateService
{
private StudentGroupBlock _block;
public MainWindow()
{
InitializeComponent();
var studentGroupBlock = new StudentGroupBlock(this);
AddToViewList("Main", studentGroupBlock);
OpenView(studentGroupBlock);
_block = studentGroupBlock;
}

public void RemoveButton(NavigateButton button)
Expand All @@ -31,5 +33,15 @@ public void OpenView(UserControl view)
{
MainWindowContent.Content = view.Content;
}

private void ButtonHome_OnClick(object sender, RoutedEventArgs e)
{
OpenView(_block);
}

private void ButtonCleanCache_OnClick(object sender, RoutedEventArgs e)
{
JsonBackupManager.ClearCache();
}
}
}
4 changes: 1 addition & 3 deletions LimpStats.Core/Parsers/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,15 @@ private static int TaskIdFromLink(string link)
return int.Parse(stringRes);
}

//TODO: Прееместить в .Core.Parsers
public static string GetTitleTask(int number)
{
//TODO загрузка названия задачи
string url = $"https://www.e-olymp.com/ru/problems/{number}";
var Webget = new HtmlWeb();
HtmlDocument doc = Webget.Load(url);

foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//*[contains(@class,'eo-title__header')]"))
{
//TODO:
//TODO: wtf
if(node.ChildNodes[0].InnerHtml != "Задачи")
return node.ChildNodes[0].InnerHtml;
}
Expand Down
24 changes: 12 additions & 12 deletions LimpStats.Core/Tools/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ namespace LimpStats.Core.Tools
{
public static class Tools
{
public static string ToStringAddress(int position)
{
const int size = 26;
string res = "";
do
{
res += (char)('A' + position % size);
position /= size;
} while (position > size);
//public static string GenerateNextNumber(int position)
//{
//
// const int size = 26;
// string res = "";
// do
// {
// res += (char)('A' + position % size);
// position /= size;
// } while (position > size);

return res;
}
// return res;
//}

//TODO: replace with ToStringAddress
public static string GenerateNextNumber(string number)
{
//Todo: работает, но если есть варик попроще надо его юзать
Expand Down
15 changes: 14 additions & 1 deletion LimpStats.Database/JsonBackupManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ private static void CheckFileExist(string filePath)
}
}

public static void ClearCache()
{
var names = LoadCardName();
foreach (var cardTitle in names)
{
string filePath = $"card_{cardTitle}.json";
File.Delete(filePath);
}
File.Delete(CardsName);
}

public static void SaveToJson(List<LimpUser> users)
{
CheckFileExist(FilePath);
Expand All @@ -48,7 +59,9 @@ public static StudyGroup LoadCardUserList(string cardTitle)
CheckFileExist(filePath);
string jsonData = File.ReadAllText(filePath);
var group = JsonConvert.DeserializeObject<StudyGroup>(jsonData);
return group ?? new StudyGroup();
return group;
// var group = JsonConvert.DeserializeObject<StudyGroup>(jsonData);
// return group ?? new StudyGroup();
}
public static void SaveCardName(string cardTitle)
{
Expand Down

0 comments on commit 0325b58

Please sign in to comment.