Exemple #1
0
        public static List <TaxAvto> Write(List <TaxAvto> taxi)
        {
            TaxAvto objTaxAvto = new TaxAvto(); //object for writing

            Console.WriteLine("Enter name of file :");
            String nameofFile = Console.ReadLine() + ".txt";

            int i = 0;

            if (nameofFile == ".txt")
            {
                Console.WriteLine("Enter correct name of File!");
            }
            else
            {
                FileInfo file = new FileInfo("C:\\Users\\[email protected]\\Documents\\Visual Studio 2015\\Projects\\" + nameofFile);

                if (file.Exists == false)
                {
                    file.Create();
                    Console.WriteLine("File is created");
                }

                Console.WriteLine("Model: ");
                objTaxAvto.model = Console.ReadLine();

                Console.WriteLine("Type: ");
                objTaxAvto.type = Console.ReadLine();

                Console.WriteLine("FuelType: ");
                objTaxAvto.fueltype = Console.ReadLine();

                Console.WriteLine("FuelConsumption: ");
                objTaxAvto.fuelConsumption = Double.Parse(Console.ReadLine());

                Console.WriteLine("Price: ");
                objTaxAvto.price = Int32.Parse(Console.ReadLine());

                Console.WriteLine("SeatCount: ");
                objTaxAvto.seatCount = Int32.Parse(Console.ReadLine());

                Read(nameofFile);


                StreamWriter sw;

                sw = file.AppendText();
                sw.Write(objTaxAvto.model + " ");
                sw.Write(objTaxAvto.type + " ");
                sw.Write(objTaxAvto.fueltype + " ");
                sw.Write(objTaxAvto.fuelConsumption + " ");
                sw.Write(objTaxAvto.price + " ");
                sw.WriteLine(objTaxAvto.seatCount);
                sw.Close();
                taxi.Add(objTaxAvto);
            }
            return(taxi);
        }
Exemple #2
0
 public static void SearchShow(TaxAvto taxi, int i)
 {
     Console.WriteLine(i + 1 + ":");
     Console.WriteLine("Name: " + taxi.model);
     Console.WriteLine("Type: " + taxi.type);
     Console.WriteLine("Fuel: " + taxi.fueltype);
     Console.WriteLine("Fuel Cunsumption: " + taxi.fuelConsumption);
     Console.WriteLine("Price: " + taxi.price);
     Console.WriteLine("Seat Count: " + taxi.seatCount);
 }
Exemple #3
0
        public static List<TaxAvto> Read(string nameofFile)
        {
            List<TaxAvto> ListFromFile = new List<TaxAvto>();

            try {
                StreamReader sr = new StreamReader("C:\\Users\\[email protected]\\Documents\\Visual Studio 2015\\Projects\\" + nameofFile);

                List<string> listTax = new List<string>();//list of rows in file

                int i = 0;
                while (!sr.EndOfStream)
                {
                    listTax.Add(sr.ReadLine());
                }
                for (int j = 0; j < listTax.Count; j++)
                {
                    TaxAvto ta = new TaxAvto();
                    string[] str;
                    str = listTax[j].Split(' ');

                    for (i = 0; i < str.Length -1 ; i++)
                    {
                        ta.model = str[i++];
                        ta.type = str[i++];
                        ta.fueltype = str[i++];
                        ta.fuelConsumption = double.Parse(str[i++]);
                        ta.price = Int32.Parse(str[i++]);
                        ta.seatCount = Int32.Parse(str[i++]);
                        ListFromFile.Add(ta);
                    }

                }
                sr.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("File is not exsist!");

            }

            return ListFromFile;
        }
Exemple #4
0
        public static List <TaxAvto> Read(string nameofFile)
        {
            List <TaxAvto> ListFromFile = new List <TaxAvto>();

            try {
                StreamReader sr = new StreamReader("C:\\Users\\[email protected]\\Documents\\Visual Studio 2015\\Projects\\" + nameofFile);


                List <string> listTax = new List <string>();//list of rows in file

                int i = 0;
                while (!sr.EndOfStream)
                {
                    listTax.Add(sr.ReadLine());
                }
                for (int j = 0; j < listTax.Count; j++)
                {
                    TaxAvto  ta = new TaxAvto();
                    string[] str;
                    str = listTax[j].Split(' ');

                    for (i = 0; i < str.Length - 1; i++)
                    {
                        ta.model           = str[i++];
                        ta.type            = str[i++];
                        ta.fueltype        = str[i++];
                        ta.fuelConsumption = double.Parse(str[i++]);
                        ta.price           = Int32.Parse(str[i++]);
                        ta.seatCount       = Int32.Parse(str[i++]);
                        ListFromFile.Add(ta);
                    }
                }
                sr.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("File is not exsist!");
            }

            return(ListFromFile);
        }
Exemple #5
0
        public static List<TaxAvto> Write(List<TaxAvto> taxi)
        {
            TaxAvto objTaxAvto = new TaxAvto() ;//object for writing

            Console.WriteLine("Enter name of file :");
            String nameofFile = Console.ReadLine()+".txt";

            int i = 0;
            if (nameofFile == ".txt")
            {
                Console.WriteLine("Enter correct name of File!");

            }
            else
            {
                FileInfo file = new FileInfo("C:\\Users\\[email protected]\\Documents\\Visual Studio 2015\\Projects\\" + nameofFile);

                if (file.Exists == false)
                {
                    file.Create();
                    Console.WriteLine("File is created");
                }

                Console.WriteLine("Model: ");
                objTaxAvto.model = Console.ReadLine();

                Console.WriteLine("Type: ");
                objTaxAvto.type = Console.ReadLine();

                Console.WriteLine("FuelType: ");
                objTaxAvto.fueltype = Console.ReadLine();

                Console.WriteLine("FuelConsumption: ");
                objTaxAvto.fuelConsumption = Double.Parse(Console.ReadLine());

                Console.WriteLine("Price: ");
                objTaxAvto.price = Int32.Parse(Console.ReadLine());

                Console.WriteLine("SeatCount: ");
                objTaxAvto.seatCount = Int32.Parse(Console.ReadLine());

                Read(nameofFile);

                StreamWriter sw;

                    sw = file.AppendText();
                    sw.Write(objTaxAvto.model + " ");
                    sw.Write(objTaxAvto.type + " ");
                    sw.Write(objTaxAvto.fueltype + " ");
                    sw.Write(objTaxAvto.fuelConsumption + " ");
                    sw.Write(objTaxAvto.price + " ");
                    sw.WriteLine(objTaxAvto.seatCount);
                    sw.Close();
                taxi.Add(objTaxAvto);

            }
            return taxi;
        }
Exemple #6
0
 public static void SearchShow(TaxAvto taxi,int i)
 {
     Console.WriteLine(i+1 + ":");
     Console.WriteLine("Name: " + taxi.model);
     Console.WriteLine("Type: " + taxi.type);
     Console.WriteLine("Fuel: " + taxi.fueltype);
     Console.WriteLine("Fuel Cunsumption: " + taxi.fuelConsumption);
     Console.WriteLine("Price: " + taxi.price);
     Console.WriteLine("Seat Count: " + taxi.seatCount);
 }