Example #1
0
 public ArrayList ReadChelov(string path)
 {
     StreamReader fileChelov = new StreamReader(path, Encoding.Default);
     Pasajir chel = new Pasajir();
     Regex fiof = new Regex(@"\D*", RegexOptions.None);//(([A-Z],[А-Я])-любой язык и Заглавные ?-один иили ноль раз(.)-единичный символ ?-один иили ноль раз([a-z],[а-я])-буквы строчные любой язык *-любое количество\s- один пробел ){3,}- три и более повторений
     Regex kolf = new Regex(@"\s[0-9]{1,3}\s", RegexOptions.None);
     Regex vesf1 = new Regex(@"\s[0-9]{1,3}[^ ][0-9]{1,3}", RegexOptions.None);
     Regex vesf2 = new Regex(@"[.,][0-9]{1,3}", RegexOptions.None);
     ArrayList spisChelov = new ArrayList();
     string line;
     for (int i = 0; ; i++)
     {
         chel.fio = new StringBuilder();
         line = fileChelov.ReadLine();// != null) ? fileChelov.ReadLine() : null;
         if (line == null) break;
         Match tempFio = fiof.Match(line);
         Match tempKol = kolf.Match(line);
         Match tempVes1 = vesf1.Match(line);
         Match tempVes2 = vesf2.Match(line);
         string tempVes = tempVes1.ToString().Substring(0, tempVes1.ToString().Length - 1) + tempVes2.ToString().Substring(1);
         //Console.WriteLine("tempFio={0} \n tempKol={1}\n tempVes={2}",  tempFio, tempKol, tempVes);
         if (tempFio.Success) chel.fio.Append(tempFio.ToString());
         else throw new Exception("В файле " + path + ", в строке №" + i + 1 + " отсутствует ФИО");
         if (tempKol.Success)
             chel.kolSumok = int.Parse(tempKol.ToString());
         else throw new Exception("В файле " + path + ", в строке №" + i+1 + " отсутствует количество багажа");
         if (tempKol.Success)
             chel.vesBagaja = Convert.ToDouble(tempVes);
         else throw new Exception("В файле " + path + ", в строке №" + i+1 + " отсутствует суммарный вес багажа");
         spisChelov.Add(chel);
     }
     fileChelov.Close();
     Console.WriteLine("Считано:\n");
     foreach (Pasajir p in spisChelov)
         Console.WriteLine(p.fio + ":" + p.kolSumok + ":" + p.vesBagaja);
     return spisChelov;
 }
Example #2
0
 public BagznajaVedomost(Pasajir rabChel)
 {
     Pasajir chel = rabChel;
 }