Created
October 8, 2019 05:40
-
-
Save shamritskiy3468/09b56a7d8186198f5e3bae5f2e3e6b7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Specialized; | |
using System.IO; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace Student_nagruzka | |
{ | |
public abstract class FileHanlder | |
{ | |
private string FileName; | |
private string CustomDirectory; | |
public FileHanlder(string fileName) | |
{ | |
this.FileName = fileName; | |
this.CustomDirectory = "C:"; | |
} | |
public string[] ExtractData() | |
{ | |
OpenFile(); | |
return ReadData(); | |
} | |
public void WriteData() | |
{ | |
OpenFile(); | |
PrependData(); | |
} | |
public abstract void PrependData(); | |
public abstract void OpenFile(); | |
public abstract string[] ReadData(); | |
public int MyProperty { get; set; } | |
} | |
class TXTHandler : FileHanlder | |
{ | |
public TXTHandler(string fileName) : base (fileName) { } | |
public override void OpenFile() { } | |
public override void PrependData() | |
{ | |
throw new NotImplementedException(); | |
} | |
public override string[] ReadData() | |
{ | |
// System.IO.StreamReader file = new System.IO.StreamReader(@"C:\Users\Dmitry Shamritsky\source\repos\Student_nagruzka\Student_nagruzka\data.txt"); | |
try | |
{ | |
string[] lines = File.ReadAllLines(@"C:/Users/Dmitry Shamritsky/source/repos/Student_nagruzka/Student_nagruzka/data.txt.txt"); | |
return lines; | |
} | |
catch (Exception) | |
{ | |
throw; | |
} | |
} | |
public int MyProperty { get; set; } | |
} | |
class CSVHandler : FileHanlder | |
{ | |
public CSVHandler(string fileName) : base(fileName) { } | |
public override void OpenFile() | |
{ | |
throw new NotImplementedException(); | |
} | |
public override void PrependData() | |
{ | |
throw new NotImplementedException(); | |
} | |
public override string[] ReadData() | |
{ | |
throw new NotImplementedException(); | |
} | |
public override string ToString() | |
{ | |
return base.ToString(); | |
} | |
} | |
class PDFhandler : FileHanlder | |
{ | |
public PDFhandler(string fileName) : base(fileName) { } | |
public override void OpenFile() | |
{ | |
throw new NotImplementedException(); | |
} | |
public override void PrependData() | |
{ | |
throw new NotImplementedException(); | |
} | |
public override string[] ReadData() | |
{ | |
throw new NotImplementedException(); | |
} | |
public override string ToString() | |
{ | |
return base.ToString(); | |
} | |
} | |
class Subject : IComparable | |
{ | |
private string SubjectName; | |
private int StudyHours; | |
private int LectureHours; | |
private int HomeWorkHours; | |
private int LaboratoryHours; | |
private string SubjectTeacherName; | |
public Subject(string SubjectName, int StudyHours, int LectureHours, int HomeWorkHours, int LaboratoryHours, string SubjectTeacherName) | |
{ | |
this.SubjectName = SubjectName; | |
this.StudyHours = StudyHours; | |
this.LectureHours = LectureHours; | |
this.HomeWorkHours = HomeWorkHours; | |
this.LaboratoryHours = LaboratoryHours; | |
this.SubjectTeacherName = SubjectTeacherName; | |
} | |
//public string Properties { get; set; } | |
public string name { get => this.SubjectName; } | |
public int study_hours { get => this.StudyHours; } | |
public int lect_hours { get => this.LectureHours; } | |
public int home_hours { get => this.HomeWorkHours; } | |
public int labo_hours { get => this.LectureHours; } | |
public string teacher { get => this.SubjectTeacherName; } | |
public string getSubjectName() | |
{ | |
return this.SubjectName; | |
} | |
public int CompareTo(object o) | |
{ | |
Subject comparable = o as Subject; | |
if (comparable != null) | |
return this.SubjectName.CompareTo(comparable.SubjectName); | |
else | |
throw new Exception("Imposible to compare!"); | |
} | |
public override string ToString() => this.SubjectName + " | " + this.StudyHours + " | " + this.LectureHours + " | " + this.HomeWorkHours + " | " + this.LaboratoryHours + " | " + this.SubjectTeacherName; | |
} | |
class Program | |
{ | |
public static string PATH = "C:/Users/Dmitry Shamritsky/source/repos/Student_nagruzka/Student_nagruzka/data.txt.txt"; | |
static void Main(string[] args) | |
{ | |
TXTHandler txtHandler = new TXTHandler(PATH); | |
List<Subject> SubjectList = PrepareDataForUsege(); | |
while (true) { | |
switch (Menu()) { | |
case 1: Additional(SubjectList); break; | |
case 2: Deletions(SubjectList); break; | |
case 3: FindRecord(SubjectList); break; | |
case 4: ShowList(SortRecords(SubjectList)); break; | |
case 5: ShowList(SubjectList); break; | |
case 6: return; | |
} | |
} | |
WriteData(SubjectList); | |
return; | |
} | |
static public void ShowList(List<Subject> subjects) | |
{ | |
int i = 1; | |
foreach(Subject subject in subjects) | |
{ | |
Console.WriteLine(i + " - " + subject.ToString()); | |
i++; | |
} | |
} | |
static public void Additional(List<Subject> list_to_add) { | |
int study_hours, lecture_hours, homework_hours, laboratory_hours; | |
string subject_name, subject_teacher_name; | |
Console.Clear(); | |
Console.WriteLine("Add subject name:"); | |
subject_name = Console.ReadLine(); | |
Console.WriteLine("Add study hours: "); | |
try | |
{ | |
study_hours = Int32.Parse(Console.ReadLine()); | |
} | |
catch (FormatException) | |
{ | |
Console.WriteLine("Imposible to convert"); | |
throw; | |
} | |
Console.WriteLine("Add lecture hours: "); | |
try | |
{ | |
lecture_hours = Int32.Parse(Console.ReadLine()); | |
} | |
catch (FormatException) | |
{ | |
Console.WriteLine("Imposible to convert"); | |
throw; | |
} | |
Console.WriteLine("Add homw work hours: "); | |
try | |
{ | |
homework_hours = Int32.Parse(Console.ReadLine()); | |
} | |
catch (FormatException) | |
{ | |
Console.WriteLine("Imposible to convert"); | |
throw; | |
} | |
Console.WriteLine("Add laboratory hours: "); | |
try | |
{ | |
laboratory_hours = Int32.Parse(Console.ReadLine()); | |
} | |
catch (FormatException) | |
{ | |
Console.WriteLine("Imposible to convert"); | |
throw; | |
} | |
Console.WriteLine("Add subject teacher name hours: "); | |
subject_teacher_name = Console.ReadLine(); | |
list_to_add.Add(new Subject(subject_name, study_hours, lecture_hours, homework_hours, laboratory_hours, subject_teacher_name)); | |
return; | |
} | |
static public void Deletions(List<Subject> SubjectList) { | |
Console.WriteLine("Choose what to delete and enter index + enter"); | |
ShowList(SubjectList); | |
int index_to_delete; | |
try | |
{ | |
index_to_delete = Int32.Parse(Console.ReadLine()); | |
if (index_to_delete > SubjectList.Count) | |
{ | |
Console.WriteLine("Fuck you"); | |
} | |
else | |
{ | |
SubjectList.RemoveAt(index_to_delete - 1); | |
} | |
} | |
catch (FormatException) | |
{ | |
throw; | |
} | |
} | |
static public void FindRecord(List<Subject> list) { | |
Console.Clear(); | |
Console.WriteLine("Will search by name, so enter search pattern: \n"); | |
string searchPattern = Console.ReadLine(); | |
Subject SerchResult = list.Find(item => item.name == searchPattern); | |
Console.Clear(); | |
SerchResult.ToString(); | |
//string result = myList.Single(s => s == search); | |
} | |
static public List<Subject> SortRecords(List<Subject> subjectList) { | |
subjectList.Sort(); | |
return subjectList; | |
} | |
static public void WriteData(List<Subject> Subjectlist) | |
{ | |
List<string> linesToWrite = new List<string>(); | |
foreach (Subject subject in Subjectlist) | |
{ | |
linesToWrite.Add(subject.name + " | " + subject.study_hours + " | " + subject.lect_hours + " | " + subject.home_hours + " | " + subject.labo_hours + " | " + subject.teacher); | |
} | |
string[] s_array = linesToWrite.ToArray(); | |
File.WriteAllLines(PATH, s_array, Encoding.UTF8); | |
return; | |
} | |
static public List<Subject> PrepareDataForUsege() | |
{ | |
TXTHandler txtHandler = new TXTHandler(PATH); | |
string[] list = txtHandler.ExtractData(); | |
List<Subject> SubjectList = new List<Subject>(); | |
string subject_name, teacher_name; | |
int study_hours, lecture_hours, home_hours, labs_hours; | |
if (new FileInfo(PATH).Length == 0) | |
{ | |
return new List<Subject>(); | |
} | |
else | |
{ | |
foreach (string line in list) | |
{ | |
string[] fields = line.Split(" | "); | |
subject_name = fields[0]; | |
study_hours = Int32.Parse(fields[1]); | |
lecture_hours = Int32.Parse(fields[2]); | |
home_hours = Int32.Parse(fields[3]); | |
labs_hours = Int32.Parse(fields[4]); | |
teacher_name = fields[5]; | |
Subject obj = new Subject(subject_name, study_hours, lecture_hours, home_hours, labs_hours, teacher_name); | |
SubjectList.Add(obj); | |
} | |
return SubjectList; | |
} | |
} | |
static int Menu() | |
{ | |
Console.WriteLine(" ----------------- MENU -----------------"); | |
Console.WriteLine("1. Add subject information"); | |
Console.WriteLine("2. Delete records"); | |
Console.WriteLine("3. Find Record"); | |
Console.WriteLine("4. Sort and show Records"); | |
Console.WriteLine("5. Show all records"); | |
Console.WriteLine("6. Exit"); | |
Console.WriteLine(" ----------------------------------------"); | |
return Int32.Parse(Console.ReadLine()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment