Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO
- private static int Цена;
- object Current { get; private set; }
- static void Show() //функция вывода БД в виде таблицы
- {
- string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) +
- Path.DirectorySeparatorChar + "Catalog.txt";
- if (System.IO.File.Exists(path))
- {
- System.IO.StreamReader sr = new StreamReader(path);
- List<TCompParts> Catalog = new List<TCompParts>();
- TCompParts { Current};
- while (!sr.EndOfStream)
- {
- Current.Name = sr.ReadLine();
- Current.Obom = sr.ReadLine();
- Current.Prise = sr.ReadLine();
- Current.Tipsoed = sr.ReadLine();
- Catalog.Add(Current);
- string gap = sr.ReadLine();
- }
- sr.Close();
- Console.WriteLine("1 - отображение базы данных:\n№ Название
- Объём Цена Тип - соед. ");
- for (int i = 0; i < Catalog.Count; i++)
- {
- Console.WriteLine("{0,0}{1,5}{2,20}{3,25}{4,30}", i + 1,
- Catalog[i].Name,
- Catalog[i].Obom, Catalog[i].Prise, Catalog[i].Tipsoed);
- }
- }
- else
- {
- Console.WriteLine("Ошибка кода. Файл не найден.");
- }
- Console.WriteLine("\nPress any key to proceed...");
- int ch = Console.Read();
- }
- static void Add() //функция добавления записей в БД
- {
- string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) +
- Path.DirectorySeparatorChar + "Catalog.txt";
- if (System.IO.File.Exists(path))
- {
- bool mode = false;
- Console.Write("Добавлить запись? (да/нет) -> ");
- string agreement = Console.ReadLine(); //переменная для записи БД
- if (String.Compare(agreement.ToLower(), "нет") == 0)
- {
- mode = true;
- Console.WriteLine("В БД не будет добавлена запись.");
- }
- else if (String.Compare(agreement.ToLower(), "да") == 0)
- {
- Console.WriteLine("В БД будет добавлена запись.");
- }
- else
- {
- Console.WriteLine("Ответ не может быть прочит");
- }
- System.IO.StreamWriter sw = new StreamWriter(path, mode);
- string Input;
- float Cost;
- int number = 0;
- Console.WriteLine("\nЗапись в каталог:");
- do
- {
- Console.Write("\nБД {0}. Название >> ", number + 1);
- Input = Console.ReadLine();
- if (Input.Length != 0)
- {
- sw.WriteLine(Input);
- Console.Write("Объём >> ");
- Input = Console.ReadLine();
- sw.WriteLine(Input);
- Console.Write("Цена >> ");
- Input = Console.ReadLine();
- sw.WriteLine(Input);
- Console.Write("Тип-соед.>> ");
- Input = Console.ReadLine();
- Cost = Convert.ToSingle(Input);
- sw.WriteLine(Cost);
- number++;
- sw.WriteLine();
- }
- }
- while (Input.Length != 0);
- sw.Close();
- }
- else
- {
- Console.WriteLine("Ошибка кода. Файл не найден.");
- }
- Console.WriteLine("\nPress any key to proceed...");
- int ch = Console.Read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement