Exemple #1
0
 void Add_poezd()
 {
     Random realRnd = new Random();
     List<Passanger> passangers = new List<Passanger>();
     string nomer = textBox1.Text, type = comboBox1.Text,id=comboBox4.Text;
     int i = 0;
     for (i = 0; i < Glades.marshruti.Count; i++) {
         if (id == Glades.marshruti[i].ID) {
             count_stops = Glades.marshruti[i].Ostanovki.Count;
         }
     }
     string[] time1 = textBox2.Text.Split(':');
     string[] time2 = textBox3.Text.Split(':');
     int avarage = (int.Parse(time2[0]) * 60 + int.Parse(time2[1])) - (int.Parse(time1[0]) * 60 + int.Parse(time1[1]));
     int current_time = (int.Parse(time1[0]) * 60 + int.Parse(time1[1]));
     for (int j = 0; j < count_stops; j++) {
         if (j != 0)
         {
             if (j == count_stops - 1)
             {
                 current_time = (int.Parse(time2[0]) * 60 + int.Parse(time2[1]));
             } else
             current_time += (realRnd.Next(avarage/8-20, avarage / 8));
         }else current_time += 0;
         DateTime dt = new DateTime();
         int Hour = ((current_time) / 60);
         int Min = ((current_time) % 60);
         dt = dt.AddHours(Hour);
         dt = dt.AddMinutes(Min);
         Time.Add(dt);
     }
     Train t = new Train(nomer, type, id, Time,passangers);
     Glades.trains.Add(t);
 }
Exemple #2
0
 public void PoiskVsexPoezdov()
 {
     XmlDocument Doc = new XmlDocument();
     Doc.Load("Poezd.xml");
     XmlElement Root = Doc.DocumentElement;
     string nomer = "", type = "", id = "";
     int Hour, Min;
     foreach (XmlNode node in Root)
     {
         List<string> distance = new List<string>();
         List<DateTime> time = new List<DateTime>();
         List<Passanger> passangers = new List<Passanger>();
         if (node.Attributes.Count > 0)
         {
             XmlNode attr = node.Attributes.GetNamedItem("name");
             if (attr != null)
                 nomer = attr.Value;
         }
         foreach (XmlNode childnode in node.ChildNodes)
         {
             if (childnode.Name == "type")
             {
                 type = childnode.InnerText;
             }
             if (childnode.Name == "distanation")
             {
                 id = childnode.InnerText;
             }
             if (childnode.Name == "time")
             {
                 string[] info = childnode.InnerText.Split(' ');
                 for (int i = 0; i < info.Length; i++)
                 {
                     string[] info1 = (info[i].Split(':'));
                     Hour = int.Parse(info1[0]);
                     Min = int.Parse(info1[1]);
                     DateTime dt = new DateTime();
                     dt = dt.AddHours(Hour);
                     dt = dt.AddMinutes(Min);
                     time.Add(dt);
                 }
             }
         }
         passangers = PoiskVsexPasagirov(nomer);
         t = new Train(nomer, type, id, time, passangers);
         trains.Add(t);
         distance = null;
         time = null;
         passangers = null;
     }
 }
Exemple #3
0
 private void Receive_data1_Click(object sender, EventArgs e)
 {
     Train train = new Train();
     string str = textNomer.Text;
     List<string> collection = new List<string>();
     bool flag = true;
     if (str == "")
     {
         flag = false;
         collection = Train.PoiskVsexPoezdov();
         for (int i = 0; i < collection.Count; i++)
         {
             info = collection[i].Split('{');
             Vivod_data.Items.Add(info[0]);
         }
     }
     if (flag == true)
     {
         collection = Train.PoiskPoezda(str);
         if (collection[0].Contains("null"))
         {
             MessageBox.Show("Не найденно совпадений");
             Vivod_data.Items.Add("Совпадений не найдено");
         }
         else
         {
             info = collection[i].Split('{');
             Vivod_data.Items.Add(info[0]);
             MMT.Visible = true;
         }
         // string s = Properties.Resources.Base;
     }
     Vivod_data.Visible = true;
 }