Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO
  4. private static int Цена;
  5.  
  6. object Current { get; private set; }
  7.  
  8. static void Show() //функция вывода БД в виде таблицы
  9. {
  10. string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) +
  11. Path.DirectorySeparatorChar + "Catalog.txt";
  12. if (System.IO.File.Exists(path))
  13. {
  14. System.IO.StreamReader sr = new StreamReader(path);
  15. List<TCompParts> Catalog = new List<TCompParts>();
  16. TCompParts { Current};
  17. while (!sr.EndOfStream)
  18. {
  19. Current.Name = sr.ReadLine();
  20. Current.Obom = sr.ReadLine();
  21. Current.Prise = sr.ReadLine();
  22. Current.Tipsoed = sr.ReadLine();
  23. Catalog.Add(Current);
  24. string gap = sr.ReadLine();
  25. }
  26. sr.Close();
  27. Console.WriteLine("1 - отображение базы данных:\n№ Название
  28. Объём Цена Тип - соед. ");
  29. for (int i = 0; i < Catalog.Count; i++)
  30. {
  31. Console.WriteLine("{0,0}{1,5}{2,20}{3,25}{4,30}", i + 1,
  32. Catalog[i].Name,
  33. Catalog[i].Obom, Catalog[i].Prise, Catalog[i].Tipsoed);
  34. }
  35. }
  36. else
  37. {
  38. Console.WriteLine("Ошибка кода. Файл не найден.");
  39. }
  40. Console.WriteLine("\nPress any key to proceed...");
  41. int ch = Console.Read();
  42. }
  43. static void Add() //функция добавления записей в БД
  44. {
  45. string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) +
  46. Path.DirectorySeparatorChar + "Catalog.txt";
  47. if (System.IO.File.Exists(path))
  48. {
  49. bool mode = false;
  50. Console.Write("Добавлить запись? (да/нет) -> ");
  51. string agreement = Console.ReadLine(); //переменная для записи БД
  52. if (String.Compare(agreement.ToLower(), "нет") == 0)
  53. {
  54. mode = true;
  55. Console.WriteLine("В БД не будет добавлена запись.");
  56. }
  57. else if (String.Compare(agreement.ToLower(), "да") == 0)
  58. {
  59. Console.WriteLine("В БД будет добавлена запись.");
  60. }
  61. else
  62. {
  63. Console.WriteLine("Ответ не может быть прочит");
  64. }
  65. System.IO.StreamWriter sw = new StreamWriter(path, mode);
  66. string Input;
  67. float Cost;
  68. int number = 0;
  69. Console.WriteLine("\nЗапись в каталог:");
  70. do
  71. {
  72. Console.Write("\nБД {0}. Название >> ", number + 1);
  73. Input = Console.ReadLine();
  74. if (Input.Length != 0)
  75. {
  76. sw.WriteLine(Input);
  77. Console.Write("Объём >> ");
  78. Input = Console.ReadLine();
  79. sw.WriteLine(Input);
  80. Console.Write("Цена >> ");
  81. Input = Console.ReadLine();
  82. sw.WriteLine(Input);
  83. Console.Write("Тип-соед.>> ");
  84. Input = Console.ReadLine();
  85. Cost = Convert.ToSingle(Input);
  86. sw.WriteLine(Cost);
  87. number++;
  88. sw.WriteLine();
  89. }
  90. }
  91. while (Input.Length != 0);
  92. sw.Close();
  93. }
  94. else
  95. {
  96. Console.WriteLine("Ошибка кода. Файл не найден.");
  97. }
  98. Console.WriteLine("\nPress any key to proceed...");
  99. int ch = Console.Read();
  100. }
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement