Skip to content

Commit

Permalink
1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
NureSyvukhaYaroslav committed Aug 20, 2022
1 parent 5bcb65f commit d1c2552
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
3 changes: 2 additions & 1 deletion UI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ListView.View>
</ListView>

<Button x:Name="Update" Content="Update List" Margin="497,0,0,10" Click="Button_Click" HorizontalAlignment="Left" Width="79" Height="50" VerticalAlignment="Bottom"/>
<Button x:Name="Update" Content="Update" Margin="497,0,0,10" Click="Button_Click" HorizontalAlignment="Left" Width="53" Height="50" VerticalAlignment="Bottom"/>
<TextBox x:Name="Input" TextWrapping="Wrap" Width="135" HorizontalAlignment="Left" Margin="357,0,0,10" FontSize="16" TextChanged="Input_TextChanged" Height="50" VerticalAlignment="Bottom" TextAlignment="Center"/>

<ListView x:Name="WatchTasks" Margin="10,10,248,10" SelectionChanged="WatchTasks_SelectionChanged">
Expand All @@ -28,5 +28,6 @@
</GridView>
</ListView.View>
</ListView>
<CheckBox x:Name="Check" Content="" HorizontalAlignment="Left" Margin="556,392,0,0" VerticalAlignment="Top"/>
</Grid>
</Window>
13 changes: 7 additions & 6 deletions UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace UI;

Expand Down Expand Up @@ -63,20 +64,20 @@ private void Input_TextChanged(object sender, System.Windows.Controls.TextChange
UpdateList(true);
}

private void WatchTasks_SelectionChanged(object sender, dynamic e)
private void WatchTasks_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Length > 0)
if (e.AddedItems.Count > 0 && Check.IsChecked == true)
{
taskService.Delete(e.AddedItems[0].Name);
taskService.Delete(((Task)e.AddedItems[0]!).Name);
UpdateList(false);
}
}

private void CurrentTasks_SelectionChanged(object sender, dynamic e)
private void CurrentTasks_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Length > 0)
if (e.AddedItems.Count > 0 && Check.IsChecked == true)
{
taskService.Add(e.AddedItems[0].Name);
taskService.Add(((ProcessDTO)e.AddedItems[0]!).Name);
UpdateList(false);
Input.Text = "";
}
Expand Down
12 changes: 6 additions & 6 deletions UI/TaskService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public TaskService()
try
{
using var sr = new StreamReader(path);
tasks = JsonConvert.DeserializeObject<List<Task>>(sr.ReadToEnd())!;
tasks = JsonConvert.DeserializeObject<List<Task>>(sr.ReadToEnd(), new JsonSerializerSettings() { Formatting = Formatting.Indented })!;

if (tasks.Count == 0)
{
Expand All @@ -35,7 +35,7 @@ public TaskService()
};

using var sw = new StreamWriter(path);
sw.WriteLine(JsonConvert.SerializeObject(tasks));
sw.WriteLine(JsonConvert.SerializeObject(tasks, new JsonSerializerSettings() { Formatting = Formatting.Indented }));
}

System.Threading.Tasks.Task.Run(() =>
Expand Down Expand Up @@ -88,7 +88,7 @@ public void Start()

using (var sw = new StreamWriter(path))
{
sw.WriteLine(JsonConvert.SerializeObject(tasks));
sw.WriteLine(JsonConvert.SerializeObject(tasks, new JsonSerializerSettings() { Formatting = Formatting.Indented }));
}

wait.Wait();
Expand All @@ -113,7 +113,7 @@ public void CheckState()

using (var sw = new StreamWriter(path))
{
sw.WriteLine(JsonConvert.SerializeObject(tasks));
sw.WriteLine(JsonConvert.SerializeObject(tasks, new JsonSerializerSettings() { Formatting = Formatting.Indented }));
}
}

Expand All @@ -133,7 +133,7 @@ public void Add(string name)

using (var sw = new StreamWriter(path))
{
sw.WriteLine(JsonConvert.SerializeObject(tasks));
sw.WriteLine(JsonConvert.SerializeObject(tasks, new JsonSerializerSettings() { Formatting = Formatting.Indented }));
}
}

Expand All @@ -142,6 +142,6 @@ public void Delete(string name)
tasks = tasks.Where(x => x.Name != name).ToList();

using var sw = new StreamWriter(path);
sw.WriteLine(JsonConvert.SerializeObject(tasks));
sw.WriteLine(JsonConvert.SerializeObject(tasks, new JsonSerializerSettings() { Formatting = Formatting.Indented }));
}
}

0 comments on commit d1c2552

Please sign in to comment.