Beispiel #1
0
 private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
 {
     DBRepositoriesManager.CloseAirCompanyDB();
 }
 protected override void OnClosing(CancelEventArgs e)
 {
     DBRepositoriesManager.CloseAirCompanyDB();
     base.OnClosing(e);
 }
        public void CitesteRuteXML()
        {
            if (!DBRepositoriesManager.OpenAirCompanyDB())
            {
                System.Windows.Forms.MessageBox.Show("Eroare la deschiderea bazei de date", "Eroare deschidere baza de date",
                                                     System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }


            XmlDocument document = new XmlDocument();

            try
            {
                document.Load(@Properties.Settings.Default.SerializationFilesPath + "RuteAeriene.xml");
            }
            catch (FileNotFoundException)
            {
                System.Windows.Forms.MessageBox.Show("Unnable to open rute.xml");
                return;
            }

            this.rute.Clear();
            RutaAeriana ruta;
            Hashtable   TabelaRezervari;
            SortedDictionary <DateTime, SortedDictionary <Zbor, Hashtable> > DicInfoRute;
            DateTime data;
            SortedDictionary <Zbor, Hashtable> DicZboruri;

            //nivelul cu rute
            foreach (XmlNode rutaNode in document.DocumentElement.ChildNodes)
            {
                //alocare dictionar pentru ruta
                DicInfoRute = new SortedDictionary <DateTime, SortedDictionary <Zbor, Hashtable> >();
                //alocare ruta
                ruta = new RutaAeriana(new Aeroport(rutaNode.Attributes["numeAeropDec"]?.InnerText,
                                                    rutaNode.Attributes["orasDec"]?.InnerText, rutaNode.Attributes["taraDec"]?.InnerText,
                                                    rutaNode.Attributes["codIATAAeropDec"]?.InnerText, rutaNode.Attributes["codICAOAeropDec"]?.InnerText),
                                       new Aeroport(rutaNode.Attributes["numeAeropAter"]?.InnerText, rutaNode.Attributes["orasAter"]?.InnerText,
                                                    rutaNode.Attributes["taraAter"]?.InnerText, rutaNode.Attributes["codIATAAeropAter"]?.InnerText,
                                                    rutaNode.Attributes["codICAOAeropAter"]?.InnerText));
                //nivelul cu zboruri pentru o data anumita
                foreach (XmlNode dataNode in rutaNode.ChildNodes)
                {
                    //alocare data
                    data = DateTime.ParseExact(dataNode.Attributes["data"]?.InnerText, "dd/MM/yyyy",
                                               System.Globalization.CultureInfo.InvariantCulture);
                    DicZboruri = new SortedDictionary <Zbor, Hashtable>();
                    //nivelul cu zboruri
                    foreach (XmlNode zborNode in dataNode.ChildNodes)
                    {
                        //alocam tabela de rezervari pentru zborul curent
                        TabelaRezervari = new Hashtable();

                        Zbor zbor = new Zbor(DateTime.ParseExact(zborNode.Attributes["dataPlecare"]?.InnerText,
                                                                 "dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture)
                                             , DateTime.ParseExact(zborNode.Attributes["dataSosire"]?.InnerText,
                                                                   "dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture)
                                             , float.Parse(zborNode.Attributes["cost"]?.InnerText),
                                             int.Parse(zborNode.Attributes["nrLocuriDisponibile"]?.InnerText));
                        zbor.NumarLocuri = int.Parse(zborNode.Attributes["nrLocuriTotal"]?.InnerText);
                        foreach (XmlNode rezervareNode in zborNode.ChildNodes)
                        {
                            var rezervare = new Rezervare(
                                ruta, zbor, int.Parse(rezervareNode.Attributes["nrBilete"]?.InnerText),
                                //new Persoana(rezervareNode.Attributes["persoana"]?.InnerText));
                                DBRepositoriesManager.AirCompanyDBGetPersoana(rezervareNode.Attributes["persoana"]?.InnerText));
                            TabelaRezervari.Add(rezervare.Rezervant.CNP, rezervare);
                        }
                        DicZboruri.Add(zbor, TabelaRezervari);
                    }
                    DicInfoRute.Add(data, DicZboruri);
                }
                //adauga ruta cu dictionarul ei in Rutele Companiei
                this.rute.Add(ruta, DicInfoRute);
            }

            DBRepositoriesManager.CloseAirCompanyDB();
        }