Skip to content

Instantly share code, notes, and snippets.

@KrutNA
Last active February 5, 2018 23:04
Show Gist options
  • Save KrutNA/1a0d848f7a8c9cf01ae94e708580379f to your computer and use it in GitHub Desktop.
Save KrutNA/1a0d848f7a8c9cf01ae94e708580379f to your computer and use it in GitHub Desktop.
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CS_Lab_1
{
class MusicList
{
private static string path = AppDomain.CurrentDomain.BaseDirectory + "\\MusicList";
public class Music : MusicList
{
public string MusicAuthor;
public string MusicName;
public string FullMusicName;
}
public static Music[] Musics;
public static void CreateFile()
{
if (!File.Exists(path))
{
using (FileStream FS = File.Create(path));
}
}
public static void OutAllMusicTracks()
{
string[] TempArray;
using (FileStream FS = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))
{
TempArray = File.ReadAllLines(path);
Console.WriteLine("Musics:");
foreach (string TempString in TempArray)
{
Console.WriteLine("\t" + TempString);
}
}
}
public static void SearchInMusicList()
{
string InputString;
string[] TempArray;
bool isFoinded = false;
using (FileStream FS = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))
{
Console.Write("Input something: ");
TempArray = File.ReadAllLines(path);
if (!String.IsNullOrWhiteSpace(InputString = Console.ReadLine()))
{
foreach (string TempString in TempArray)
{
if (TempString.Contains(InputString))
{
if (!isFoinded) {
Console.WriteLine("Founded:");
isFoinded = true;
}
Console.WriteLine("\t" + TempString + "");
}
}
}
if (!isFoinded)
{
Console.WriteLine("Not Founded =(");
return;
}
}
}
public static void AddToMusicList()
{
Music AddingMusic = new Music();
string TempString;
Console.Write("Input autor\'s name: ");
if (!String.IsNullOrWhiteSpace(TempString = Console.ReadLine()))
{
AddingMusic.MusicAuthor = TempString;
Console.Write("Input the composition\'s name: ");
TempString = null;
if (!String.IsNullOrWhiteSpace(TempString = Console.ReadLine()))
{
AddingMusic.MusicName = TempString;
AddingMusic.FullMusicName = AddingMusic.MusicAuthor + " - " + AddingMusic.MusicName + "\n";
File.AppendAllText(path, AddingMusic.FullMusicName);
return;
}
}
Console.WriteLine("Input something!");
return;
}
public static void DeleteFromMusicList()
{
string InputString;
string[] TempArray;
int Counter = 0;
Console.Write("Input the full name of the track: ");
if (!String.IsNullOrWhiteSpace(InputString = Console.ReadLine()))
{
TempArray = File.ReadAllLines(path);
foreach (string TempString in TempArray)
{
if (TempString.Equals(InputString))
{
File.WriteAllText(path, "");
for (int i = 0; i < TempArray.Length; i++)
{
if (i != Counter)
{
File.AppendAllText(path, TempArray[i] + "\n");
}
}
return;
}
if (Counter == TempArray.Length - 1)
{
Console.WriteLine("Not founded =(");
}
Counter++;
}
}
else
{
Console.WriteLine("Input something!");
}
return;
}
}
class Program
{
static void Main(string[] args)
{
bool isExit = false;
string commandName;
MusicList Musics = new MusicList();
MusicList.CreateFile();
Console.WriteLine("Usage:" +
"\t\"list\" - to display all items of catalog"+
"\t\"search\" - to go find ites in catalog" +
"\t\"add\" - to add new item" +
"\t\"del\" - to remove some item from list" +
"\t\"quit\" - to exit");
while (!isExit)
{
Console.Write("Input the command: ");
commandName = Console.ReadLine();
if (String.IsNullOrEmpty(commandName))
{
Console.WriteLine("Input somthing!");
continue;
}
switch (commandName)
{
case "list":
MusicList.OutAllMusicTracks();
break;
case "search":
MusicList.SearchInMusicList();
break;
case "add":
MusicList.AddToMusicList();
break;
case "del":
MusicList.DeleteFromMusicList();
break;
case "quit":
isExit = true;
break;
default:
Console.WriteLine("Input is wrong, please try again!");
break;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment