Ejemplo n.º 1
0
        public Collection <Stavba> Select()
        {
            XDocument xDoc = XDocument.Load(ConstantsXml.FilePath);

            List <XElement> elementy = xDoc.Descendants("Stavby").Descendants("Stavba").ToList();

            Collection <Stavba> vsechnyStavby = new Collection <Stavba>();
            int      id;
            int      cislo_popisne;
            int      cislo_stavby;
            DateTime datum;

            foreach (XElement element in elementy)
            {
                Stavba stavba = new Stavba();

                int.TryParse(element.Attribute("Id_stavby").Value, out id);
                stavba.Typ_stavby = element.Attribute("Typ_stavby").Value;
                stavba.Ulice      = element.Attribute("Ulice").Value;
                int.TryParse(element.Attribute("Cislo_popisne").Value, out cislo_popisne);
                int.TryParse(element.Attribute("Cislo_stavby_na_KU").Value, out cislo_stavby);
                stavba.Nazev_KU = element.Attribute("Nazev_KU").Value;
                DateTime.TryParse(element.Attribute("Datum_kolaudace").Value, out datum);

                stavba.Id_stavby          = id;
                stavba.Cislo_popisne      = cislo_popisne;
                stavba.Cislo_stavby_na_KU = cislo_stavby;
                stavba.Datum_kolaudace    = datum;

                vsechnyStavby.Add(stavba);
                stavba = null;
            }

            return(vsechnyStavby);
        }
Ejemplo n.º 2
0
        protected void btnVybrat_Click(object sender, EventArgs e)
        {
            Literal stavbaLiteral = (sender as Button).NamingContainer.FindControl("ltrIdStavby") as Literal;
            Literal zpusobLiteral = (sender as Button).NamingContainer.FindControl("ltrTypVytapeni") as Literal;

            if (stavbaLiteral != null && zpusobLiteral != null)
            {
                int.TryParse(stavbaLiteral.Text.ToString(), out stavbaId);
                zpusobTyp = zpusobLiteral.Text.ToString();
            }
            else
            {
                stavbaId  = -1;
                zpusobTyp = "";
            }

            konkretniZpusob = zpusob.Select_id(stavbaId, zpusobTyp);
            konkretniStavba = stavba.Select_id(konkretniZpusob.Id_stavby);
            object stavbaZpusob = new { konkretniStavba.Id_stavby, konkretniStavba.Typ_stavby, konkretniStavba.Ulice, konkretniStavba.Cislo_popisne, konkretniZpusob.Typ_vytapeni, konkretniZpusob.Platnost_od, konkretniZpusob.Platnost_do };

            stavbyZpusoby.Clear();
            stavbyZpusoby.Add(stavbaZpusob);
            DetailsViewZpusobu.DataSource = stavbyZpusoby;
            DetailsViewZpusobu.DataBind();
        }
Ejemplo n.º 3
0
 private void nactiStavbyZpusoby()
 {
     foreach (Zpusob_vytapeni zpusobV in zpusoby)
     {
         konkretniStavba = stavba.Select_id(zpusobV.Id_stavby);
         object stavbaZpusob = new { konkretniStavba.Id_stavby, konkretniStavba.Typ_stavby, konkretniStavba.Ulice, konkretniStavba.Cislo_popisne, zpusobV.Typ_vytapeni, zpusobV.Platnost_od, zpusobV.Platnost_do };
         stavbyZpusoby.Add(stavbaZpusob);
     }
 }
Ejemplo n.º 4
0
 private void nahraniDetailsView()
 {
     konkretniStavba = stavba.Select_id(stavbaId);
     //vymazani kolekce vlastniku
     stavby.Clear();
     //pridani vybraneho zaznamu
     stavby.Add(konkretniStavba);
     DetailsViewStavby.DataSource = stavby;
     DetailsViewStavby.DataBind();
 }
Ejemplo n.º 5
0
        /*
         * public static int Sequence(Database Db = null)
         * {
         *  Database db;
         *  if (Db == null)
         *  {
         *      db = new Database();
         *      db.Connect();
         *  }
         *  else
         *  {
         *      db = (Database)Db;
         *  }
         *
         *  OracleCommand command = db.CreateCommand(SQL_SEQUENCE);
         *  OracleDataReader reader = db.Select(command);
         *
         *  int hodnota = 0;
         *  while (reader.Read() != false)
         *  {
         *      hodnota = reader.GetInt32(0);
         *  }
         *
         *  reader.Close();
         *
         *  if (Db == null)
         *  {
         *      db.Close();
         *  }
         *
         *  return hodnota;
         * }*/

        /*
         * public static int Insert(Stavba stavba)
         * {
         *  Database db = new Database();
         *  db.Connect();
         *  OracleCommand command = db.CreateCommand(SQL_INSERT);
         *  PrepareCommand(command, stavba);
         *  int ret = db.ExecuteNonQuery(command);
         *  db.Close();
         *  return ret;
         * }*/

        /*
         * public static int Update(Stavba stavba)
         * {
         *  Database db = new Database();
         *  db.Connect();
         *  OracleCommand command = db.CreateCommand(SQL_UPDATE);
         *  PrepareCommand(command, stavba);
         *  int ret = db.ExecuteNonQuery(command);
         *  db.Close();
         *  return ret;
         * }*/

        /*
         * public static Collection<Stavba> Select(Database Db = null)
         * {
         *  Database db;
         *  if (Db == null)
         *  {
         *      db = new Database();
         *      db.Connect();
         *  }
         *  else
         *  {
         *      db = (Database)Db;
         *  }
         *
         *  OracleCommand command = db.CreateCommand(SQL_SELECT);
         *  OracleDataReader reader = db.Select(command);
         *
         *  Collection<Stavba> Stavby = Read(reader, false);
         *  reader.Close();
         *
         *  if (Db == null)
         *  {
         *      db.Close();
         *  }
         *
         *  return Stavby;
         * }*/

        /*
         * public static Stavba Select_id(int idStavba, Database Db = null)
         * {
         *  Database db = new Database();
         *  db.Connect();
         *  OracleCommand command = db.CreateCommand(SQL_SELECT_ID);
         *
         *  command.Parameters.AddWithValue(":id", idStavba);
         *  OracleDataReader reader = db.Select(command);
         *
         *  Collection<Stavba> stavby = Read(reader, true);
         *  Stavba stavba = null;
         *  if (stavby.Count == 1)
         *  {
         *      stavba = stavby[0];
         *  }
         *  reader.Close();
         *  db.Close();
         *  return stavba;
         * }*/

        private static void PrepareCommand(OracleCommand command, Stavba Stavba)
        {
            command.BindByName = true;
            command.Parameters.AddWithValue(":id", Stavba.Id_stavby);
            command.Parameters.AddWithValue(":typ", Stavba.Typ_stavby);
            command.Parameters.AddWithValue(":ulice", Stavba.Ulice);
            command.Parameters.AddWithValue(":cislo_popisne", Stavba.Cislo_popisne);
            command.Parameters.AddWithValue(":cislo_stavby", Stavba.Cislo_stavby_na_KU);
            command.Parameters.AddWithValue(":nazev_KU", Stavba.Nazev_KU);
            command.Parameters.AddWithValue(":datum_kolaudace", Stavba.Datum_kolaudace);
        }
Ejemplo n.º 6
0
        public void Update(Stavba stavba)
        {
            Database db = new Database();

            db.Connect();
            OracleCommand command = db.CreateCommand(SQL_UPDATE);

            PrepareCommand(command, stavba);
            int ret = db.ExecuteNonQuery(command);

            db.Close();
        }
Ejemplo n.º 7
0
        private List <object> nactiStavbyVlastniky()
        {
            List <object> list = new List <object>();

            foreach (StavbaVlastnik stavbaVlastnik in stavbyVlastnici)
            {
                konkretniStavba   = stavba.Select_id(stavbaVlastnik.Id_stavby);
                konkretniVlastnik = vlastnik.Select_id(stavbaVlastnik.Id_vlastnika);
                object obj = new { konkretniStavba.Typ_stavby, konkretniStavba.Ulice, konkretniStavba.Cislo_popisne, konkretniVlastnik.Jmeno, konkretniVlastnik.Prijmeni, konkretniVlastnik.Datum_narozeni };
                list.Add(obj);
            }

            return(list);
        }
Ejemplo n.º 8
0
        public void Insert(Stavba stavba)
        {
            XDocument xDoc = XDocument.Load(ConstantsXml.FilePath);

            XElement result = new XElement("Stavba",
                                           new XAttribute("Id_stavby", stavba.Id_stavby),
                                           new XAttribute("Typ_stavby", stavba.Typ_stavby),
                                           new XAttribute("Ulice", stavba.Ulice),
                                           new XAttribute("Cislo_popisne", stavba.Cislo_popisne),
                                           new XAttribute("Cislo_stavby_na_KU", stavba.Cislo_stavby_na_KU),
                                           new XAttribute("Nazev_KU", stavba.Nazev_KU),
                                           new XAttribute("Datum_kolaudace", stavba.Datum_kolaudace.ToShortDateString()));

            xDoc.Root.Element("Stavby").Add(result);
            xDoc.Save(ConstantsXml.FilePath);
        }
        protected void btnVybrat_Click(object sender, EventArgs e)
        {
            Literal stavbaLiteral = (sender as Button).NamingContainer.FindControl("ltrId") as Literal;

            if (stavbaLiteral != null)
            {
                int.TryParse(stavbaLiteral.Text.ToString(), out stavbaId);
            }
            else
            {
                stavbaId = -1;
            }

            konkretniStavba = stavba.Select_id(stavbaId);
            stavby.Clear();
            stavby.Add(konkretniStavba);
            DetailsViewStavby.DataSource = stavby;
            DetailsViewStavby.DataBind();
        }
Ejemplo n.º 10
0
        public void Update(Stavba stavba)
        {
            XDocument xDoc = XDocument.Load(ConstantsXml.FilePath);

            var q = from node in xDoc.Descendants("Stavby").Descendants("Stavba")
                    let attr = node.Attribute("Id_stavby")
                               where (attr != null && attr.Value == stavba.Id_stavby.ToString())
                               select node;

            q.ToList().ForEach(x => {
                x.Attribute("Typ_stavby").Value         = stavba.Typ_stavby;
                x.Attribute("Ulice").Value              = stavba.Ulice;
                x.Attribute("Cislo_popisne").Value      = stavba.Cislo_popisne.ToString();
                x.Attribute("Cislo_stavby_na_KU").Value = stavba.Cislo_stavby_na_KU.ToString();
                x.Attribute("Nazev_KU").Value           = stavba.Nazev_KU;
                x.Attribute("Datum_kolaudace").Value    = stavba.Datum_kolaudace.ToShortDateString();
            });

            xDoc.Save(ConstantsXml.FilePath);
        }
Ejemplo n.º 11
0
        public Stavba Select_id(int idStavba)
        {
            XDocument xDoc = XDocument.Load(ConstantsXml.FilePath);

            List <XElement> elementy = xDoc.Descendants("Stavby").Descendants("Stavba").ToList();

            Stavba vybranaStavba = new Stavba();

            foreach (XElement element in elementy)
            {
                if (int.Parse(element.Attribute("Id_stavby").Value) == idStavba)
                {
                    vybranaStavba.Id_stavby          = idStavba;
                    vybranaStavba.Typ_stavby         = element.Attribute("Typ_stavby").Value;
                    vybranaStavba.Ulice              = element.Attribute("Ulice").Value;
                    vybranaStavba.Cislo_popisne      = int.Parse(element.Attribute("Cislo_popisne").Value);
                    vybranaStavba.Cislo_stavby_na_KU = int.Parse(element.Attribute("Cislo_stavby_na_KU").Value);
                    vybranaStavba.Nazev_KU           = element.Attribute("Nazev_KU").Value;
                    vybranaStavba.Datum_kolaudace    = DateTime.Parse(element.Attribute("Datum_kolaudace").Value);
                }
            }

            return(vybranaStavba);

            /*
             * Collection<Stavba> vsechnyStavby = this.Select();
             * Stavba vybranaStavba = null;
             *
             * foreach (Stavba stavba in vsechnyStavby)
             * {
             *  if (stavba.Id_stavby == idStavba)
             *  {
             *      vybranaStavba = stavba;
             *  }
             * }
             *
             * return vybranaStavba;
             */
        }
Ejemplo n.º 12
0
        public Stavba Select_id(int idStavba)
        {
            Database db = new Database();

            db.Connect();
            OracleCommand command = db.CreateCommand(SQL_SELECT_ID);

            command.Parameters.AddWithValue(":id", idStavba);
            OracleDataReader reader = db.Select(command);

            Collection <Stavba> stavby = Read(reader, true);
            Stavba stavba = null;

            if (stavby.Count == 1)
            {
                stavba = stavby[0];
            }

            reader.Close();
            db.Close();

            return(stavba);
        }
Ejemplo n.º 13
0
        private static Collection <Stavba> Read(OracleDataReader reader, bool complete)
        {
            Collection <Stavba> Stavby = new Collection <Stavba>();

            while (reader.Read())
            {
                int    i      = -1;
                Stavba Stavba = new Stavba();
                Stavba.Id_stavby     = reader.GetInt32(++i);
                Stavba.Typ_stavby    = reader.GetString(++i);
                Stavba.Ulice         = reader.GetString(++i);
                Stavba.Cislo_popisne = reader.GetInt32(++i);

                if (complete)
                {
                    Stavba.Cislo_stavby_na_KU = reader.GetInt32(++i);
                    Stavba.Nazev_KU           = reader.GetString(++i);
                    Stavba.Datum_kolaudace    = reader.GetDateTime(++i);
                }

                Stavby.Add(Stavba);
            }
            return(Stavby);
        }
        public void Update(StavbaVlastnik stavbaVlastnik)
        {
            //XDocument xDoc = XDocument.Load(Constants.FilePath);

            //List<XElement> elementy = xDoc.Descendants("StavbyVlastnici").Descendants("StavbaVlastnik").ToList();

            //vytvoreni DTO pro praci s daty
            Stavba   vybranaStavba     = new Stavba();
            Vlastnik vlastnikProUpravu = new Vlastnik();

            //pristup k jinym tridam
            Stavba_XmlMapper          stavbaGateway         = new Stavba_XmlMapper();
            Historie_stavby_XmlMapper historieStavbyGateway = new Historie_stavby_XmlMapper();
            Vlastnik_XmlMapper        vlastnikGateway       = new Vlastnik_XmlMapper();

            //nahrani vsech informaci o stavbe, ktera je aktualizovana
            vybranaStavba = stavbaGateway.Select_id(stavbaVlastnik.Id_stavby);

            //vyber vsech vlastniku staveb
            Collection <StavbaVlastnik> stavbyVlastnici = this.Select();

            foreach (StavbaVlastnik vlastnik in stavbyVlastnici)
            {
                //vyber vlastniku, kteri vlastni upravovanou stavbu
                if (vlastnik.Id_stavby == stavbaVlastnik.Id_stavby)
                {
                    //nacitani z xml a hledani polozky s id upravovane stavby a id vlastniku, kteri ji vlastni, pro mozne smazani
                    XDocument xDoc = XDocument.Load(ConstantsXml.FilePath);
                    var       q    = from node in xDoc.Descendants("StavbyVlastnici").Descendants("StavbaVlastnik")
                                     let attr                         = node.Attribute("Id_stavby")
                                                            let attr1 = node.Attribute("Id_vlastnika")
                                                                        where (attr != null && attr.Value == stavbaVlastnik.Id_stavby.ToString()) && (attr1 != null && attr1.Value == vlastnik.Id_vlastnika.ToString())
                                                                        select node;
                    q.ToList().ForEach(x => x.Remove());
                    xDoc.Save(ConstantsXml.FilePath);

                    Historie_stavby historieStavby = new Historie_stavby();

                    historieStavby.Id_zmeny             = historieStavbyGateway.Sequence();
                    historieStavby.Typ_stavby           = vybranaStavba.Typ_stavby;
                    historieStavby.Ulice                = vybranaStavba.Ulice;
                    historieStavby.Cislo_popisne        = vybranaStavba.Cislo_popisne;
                    historieStavby.Cislo_stavby_na_KU   = vybranaStavba.Cislo_stavby_na_KU;
                    historieStavby.Nazev_KU             = vybranaStavba.Nazev_KU;
                    historieStavby.Datum_kolaudace      = vybranaStavba.Datum_kolaudace;
                    historieStavby.Casovy_okamzik_zmeny = DateTime.Now;
                    historieStavby.Id_vlastnika         = vlastnik.Id_vlastnika;
                    historieStavby.Id_stavby            = stavbaVlastnik.Id_stavby;

                    //vlozeni smazaneho zaznamu do archivace
                    historieStavbyGateway.Insert(historieStavby);

                    //znovunacteni vsech vlastniku staveb
                    Collection <StavbaVlastnik> upraveniStavbyVlastnici = this.Select();
                    int pocetZaznamuVlastnika = 0;
                    foreach (StavbaVlastnik stavbyVlastnik in upraveniStavbyVlastnici)
                    {
                        //kontrola, jestli odstraneny vlastnik vlastni jeste nejakou stavbu nebo uz ne
                        if (stavbyVlastnik.Id_vlastnika == vlastnik.Id_vlastnika)
                        {
                            pocetZaznamuVlastnika++;
                        }
                    }

                    //pokud nevlastni uz zadnou stavbu, pak se zrusi jeho aktualnost
                    if (pocetZaznamuVlastnika == 0)
                    {
                        vlastnikProUpravu.Id_vlastnika      = vlastnik.Id_vlastnika;
                        vlastnikProUpravu.Aktualni_vlastnik = "N";

                        vlastnikGateway.Delete(vlastnikProUpravu);
                    }
                }
            }

            //vlozeni noveho upraveneho zaznamu
            this.Insert(stavbaVlastnik);

            //nastaveni aktualniho vlastnika
            vlastnikProUpravu.Id_vlastnika      = stavbaVlastnik.Id_vlastnika;
            vlastnikProUpravu.Aktualni_vlastnik = "A";
            vlastnikGateway.Delete(vlastnikProUpravu);
        }