Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions CommandParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Text.Json;
namespace SectTask;

public class CommandParser
{
public void Commands(string?[] args)
{
Methods td = new Methods();
for (int i = 0; i < args.Length - 1; ++i)
{
try
{
switch (args[i])
{
case "/add":
SubTask sub = new SubTask(Convert.ToBoolean(args[i + 1]), args[i + 2], args [i + 3]);
td.AddTask(Convert.ToInt32(args[i + 4]), sub,Convert.ToDateTime(args[i + 5]),Convert.ToBoolean(args[i + 6]));
break;
case "/all":
td.ShowTasks();
break;
case "/delete":
td.DeleteTask(Convert.ToInt32(args[i + 1]));
break;
case "/save":
td.toFile(args[i + 1]);
break;
case "/load":
td.fromFile(args[i + 1]);
break;
case "/completed":
td.ChangeStatus(Convert.ToInt32(args[i + 1]));
break;
case "/create-group":
td.CreateGroup(Convert.ToInt32(args[i + 1]));
break;
case "/delete-group":
td.DeleteGroup(Convert.ToInt32(args[i + 1]));
break;
case "/add-to-group":
td.AddToGroup(Convert.ToInt32(args[i + 1]), Convert.ToInt32(args[i + 2]));
break;
case "/delete-from-group":
td.DeleteFromGroup(Convert.ToInt32(args[i + 1]), Convert.ToInt32(args[i + 2]));
break;
case "/add-subtask":
SubTask sub1 = new SubTask(Convert.ToBoolean(args[i + 1]), args[i + 2], args [i + 3]);
td.AddSubTask(Convert.ToInt32(args[i + 2]), sub1 );
break;
case "/change-sub-status":
td.ChangeSubStatus(Convert.ToInt32(args[i + 1]));
break;
case "/today":
td.DayCheck();
break;
}
}
catch (ArgumentException ep)
{
Console.WriteLine(ep.Message);
}
}
}
}
197 changes: 197 additions & 0 deletions Methods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
namespace SectTask;
using System.Text.Json;

public class Methods
{
private List<Task?> _taskData = new List<Task?>();
Comment thread
Var-S marked this conversation as resolved.
Outdated
private List<Group?> _groupData = new List<Group?>();
private List<SubTask?> _subData = new List<SubTask?>();

public void AddTask(int id, SubTask sub, DateTime deadline, bool complete)
{
_taskData.Add(new Task() {TaskId = id, Sub = sub, DeadLine = deadline, TaskStatus = complete} );
Comment thread
Var-S marked this conversation as resolved.
Outdated
Console.WriteLine("Task Created!");
}

public void AddSubTask(int Taskid, SubTask sub)
{
foreach (var t in _taskData.Where(t => t!.TaskId == Taskid))
Comment thread
Var-S marked this conversation as resolved.
Outdated
{
t!.Sub = sub;
}

Console.WriteLine("SubTask Created!");
Comment thread
Var-S marked this conversation as resolved.
Outdated
}

public void ChangeSubStatus(int id)
{
foreach (var t in _subData.Where(t => t!.SubStatus == false))
{
t!.SubStatus = true;
Comment thread
Var-S marked this conversation as resolved.
Outdated
}
Console.WriteLine("Status Changed!");
}
public void ShowTasks()
{
foreach (var t in _taskData)
{
Console.WriteLine(t!.TaskId);
Console.WriteLine(t!.TaskStatus);
var json = JsonSerializer.Serialize(t?.Sub);
var json1 = JsonSerializer.Serialize(t?.DeadLine);
Console.WriteLine(json);
Console.WriteLine(json1);
}
}

public void ShowTasks(int id)
{
foreach (var t in _taskData)
{
if (t!.TaskId == id){
Console.WriteLine(t!.TaskId);
Console.WriteLine(t!.TaskStatus);
var json = JsonSerializer.Serialize(t?.Sub);
var json1 = JsonSerializer.Serialize(t?.DeadLine);
Console.WriteLine(json);
Console.WriteLine(json1);
Comment thread
Var-S marked this conversation as resolved.
Outdated
}
else
{
Console.WriteLine("Wrong Id");
}
Comment thread
Var-S marked this conversation as resolved.
Outdated
}
}

public void DeleteTask(int id)
{
for (var i = 0; i < _taskData.Count; ++i)
{
if (_taskData[i]!.TaskId == id)
{
_taskData.Remove(_taskData[i]);
}
}
}

public void ChangeStatus(int id)
{
foreach (var t in _taskData.Where(t => t!.TaskStatus == false))
{
t!.TaskStatus = true;
}
Console.WriteLine("Status Changed!");
}

public void toFile(string? ph)
{
var str = new StreamWriter(ph!);
foreach (var t in _taskData)
{
str.WriteLine(t!.TaskId);
str.WriteLine(t!.TaskStatus);
var json = JsonSerializer.Serialize(t?.Sub);
var json1 = JsonSerializer.Serialize(t?.DeadLine);
str.WriteLine(json);
str.WriteLine(json1);
}
str.Close();
}

public void fromFile(string? ph)
{
if (File.Exists(ph))
{
using StreamReader reader = new StreamReader(ph);
_taskData.Clear();
for (int i = 0; i < System.IO.File.ReadAllLines(ph).Length; ++i)
{
string? json = reader.ReadLine();
if (json != null) _taskData.Add(JsonSerializer.Deserialize<Task>(json));
}
}
else
{
Console.WriteLine("File not found");
}
Comment thread
Var-S marked this conversation as resolved.
}

public void DayCheck()
{
foreach (var json in from t in _taskData where t!.DeadLine.Day == DateTime.Now.Day select JsonSerializer.Serialize(t))
{
Console.WriteLine(json);
}
}
Comment thread
Var-S marked this conversation as resolved.
Outdated

public void CreateGroup(int id)
{
_groupData.Add(new Group(){GroupId = id,Tasks = null});
}

public void AddToGroup(int Taskid, int Groupid)
{
foreach (var t in _taskData.Where(t => t!.TaskId == Taskid))
Comment thread
Var-S marked this conversation as resolved.
Outdated
{
foreach (var t1 in _groupData.Where(t1 => t1!.GroupId == Groupid))
{
t1!.Tasks = t;
}
}
}

public void ShowGroup()
{
foreach (var t in _groupData)
{
var json = JsonSerializer.Serialize(t!.GroupId);
var json1 = JsonSerializer.Serialize(t!.Tasks);
if (json == "null")
{
Console.Write("");
}
else
{
Console.WriteLine(json);
}
if (json1 == "null")
{
Console.Write("");
}
Comment thread
Var-S marked this conversation as resolved.
Outdated
else
{
Console.WriteLine(json1);
}
}
}

public void DeleteGroup(int id)
{
foreach (var t in _groupData)
{
if (t!.GroupId == id)
{
t.Tasks = null;
t.GroupId = null;
}
}
}

public void DeleteFromGroup(int Groupid, int Taskid)
{
for (int i = 0; i < _groupData.Count; ++i)
{
if (_groupData[i]!.GroupId == Groupid)
{
for (int j = 0; j < _taskData.Count; ++j)
{
if (_taskData[j]!.TaskId == Taskid)
{
_groupData[i]!.Tasks = null;
}
}
}
}
}

}
12 changes: 12 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.ComponentModel.Design.Serialization;

namespace SectTask;

static class Program
{
static void Main(string?[] args)
{
CommandParser input = new CommandParser();
input.Commands(args);
}
}
43 changes: 43 additions & 0 deletions Task.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace SectTask;

public class SubTask
Comment thread
Var-S marked this conversation as resolved.
Outdated
{
public bool SubStatus { get; set; }

public string? Name { get; set; }

public string? Description { get; set; }

public SubTask(bool complete, string? name, string? description)
{
SubStatus = complete;
Name = name;
Description = description;
}

}

public class Task
{
public SubTask Sub;
Comment thread
Var-S marked this conversation as resolved.
Outdated
public int TaskId { get; set; }

public bool TaskStatus { get; set; }
public DateTime DeadLine { get; set; } // 01.01.0001 0:00:00

public Task(int id, SubTask sub, DateTime deadline, bool status)
{
TaskId = id;
Sub = sub;
DeadLine = deadline;
TaskStatus = status;
}

public Task() { }
}

public class Group
Comment thread
Var-S marked this conversation as resolved.
Outdated
{
public Task? Tasks;
public int? GroupId { get; set; }
}
10 changes: 10 additions & 0 deletions sectreborn.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>