int IComparer.Compare(object ob1, object ob2) { StorageAuto p1 = (StorageAuto)ob1; StorageAuto p2 = (StorageAuto)ob2; if (p1.Quantity > p2.Quantity) { return(1); } if (p1.Quantity < p2.Quantity) { return(-1); } return(0); }
int IComparer.Compare(object ob1, object ob2) { StorageAuto p1 = (StorageAuto)ob1; StorageAuto p2 = (StorageAuto)ob2; if (p1.Price > p2.Price) { return(1); } if (p1.Price < p2.Price) { return(-1); } return(0); }
int IComparer.Compare(object ob1, object ob2) { StorageAuto p1 = (StorageAuto)ob1; StorageAuto p2 = (StorageAuto)ob2; if (p1.Marka != " " && p2.Marka != " ") { if (p1.Marka.Length > p2.Marka.Length) { return(1); } if (p1.Marka.Length < p2.Marka.Length) { return(-1); } } return(0); }
int IComparer.Compare(object ob1, object ob2) { StorageAuto p1 = (StorageAuto)ob1; StorageAuto p2 = (StorageAuto)ob2; if (p1.Name != " " && p2.Name != " ") { i++; Console.WriteLine(i); if (p1.Name.Length > p2.Name.Length) { return(1); } if (p1.Name.Length < p2.Name.Length) { return(-1); } } return(0); }
static void Main(string[] args) { List <StorageAuto> list = new List <StorageAuto>(); int n = 0; StreamReader f = new StreamReader("dbase.txt"); string s; int i = 0; int j = 0; try { while ((s = f.ReadLine()) != null) { list.Add(new StorageAuto(s)); ++i; } n = i - 1; foreach (var element in list) { Console.WriteLine(element); j++; } f.Close(); } catch (FileNotFoundException e) { Console.WriteLine(e.Message); Console.WriteLine("Check the correct name and path to the file!"); return; } catch (IndexOutOfRangeException) { Console.WriteLine("Very large file!"); return; } catch (Exception e) { Console.WriteLine("Error: " + e.Message); return; } StorageAuto[] group = new StorageAuto[10]; for (int ij = 0; ij < j; ij++) { group[ij] = list[ij]; } string namesse; Console.WriteLine("Enter it function next, write it is sort: "); while ((namesse = Console.ReadLine()) != "") { Console.WriteLine("Write word(code, price, quantity, name, marka) you want to sort:"); string sortt = Console.ReadLine(); if (sortt == "code") { Console.WriteLine("sort is Code:"); Array.Sort(group, new StorageAuto.SortByCode()); foreach (StorageAuto elem in group) { elem.ToString(); } foreach (var element in group) { Console.WriteLine(element); } } else if (sortt == "name") { Console.WriteLine("sort is Name:"); Array.Sort(group, new StorageAuto.SortByName()); foreach (StorageAuto elem in group) { elem.ToString(); } foreach (var element in group) { Console.WriteLine(element); } } else if (sortt == "marka") { Console.WriteLine("sort is Marka:"); Array.Sort(group, new StorageAuto.SortByMarka()); foreach (StorageAuto elem in group) { elem.ToString(); } foreach (var element in group) { Console.WriteLine(element); } } else if (sortt == "price") { Console.WriteLine("sort is Price:"); Array.Sort(group, new StorageAuto.SortByPrice()); foreach (StorageAuto elem in group) { elem.ToString(); } foreach (var element in group) { Console.WriteLine(element); } } else if (sortt == "quantity") { Console.WriteLine("sort is Quantity:"); Array.Sort(group, new StorageAuto.SortByQuantity()); foreach (StorageAuto elem in group) { elem.ToString(); } foreach (var element in group) { Console.WriteLine(element); } } } Console.WriteLine("Enter the text if you want play in remote in list: "); string nama; while ((nama = Console.ReadLine()) != "") { Console.WriteLine("Write remote if you want remote in list: "); string m = Console.ReadLine(); if (m == "remote") { Console.WriteLine("Enter number if you want to delete a line in LIST"); int number = Convert.ToInt32(Console.ReadLine()); list.Remove(list[number]); j--; foreach (var element in list) { Console.WriteLine(element); } } } Console.WriteLine("Enter text if you want to add a line in database: "); string names; while ((names = Console.ReadLine()) != "") { StorageAuto add = new StorageAuto(); Console.WriteLine("Enter the line you want to add: "); string numberOfLineToAdd = Console.ReadLine(); add.AppendAllText("dbase.txt", numberOfLineToAdd); } Console.WriteLine("Enter text if you want to delete a line in database: "); string nam; while ((nam = Console.ReadLine()) != "") { StorageAuto del = new StorageAuto(); Console.WriteLine("Enter the line you want to delete: "); int numberOfLineToDelete = Convert.ToInt32(Console.ReadLine()); del.Delete("dbase.txt", numberOfLineToDelete); } Console.WriteLine("Enter text if you want redahuvaty line in database(file): "); string namess; while ((namess = Console.ReadLine()) != "") { StorageAuto del = new StorageAuto(); Console.WriteLine("Enter the line you want to delete in file: "); int numberOfLineToDelete = Convert.ToInt32(Console.ReadLine()); del.Delete("dbase.txt", numberOfLineToDelete); Console.WriteLine("-------------redahuvannya-----------------------"); StorageAuto add = new StorageAuto(); Console.WriteLine("Enter the line you want to add in file: "); string numberOfLineToAdd = Console.ReadLine(); add.AppendAllText("dbase.txt", numberOfLineToAdd); } }