public Collection <Dotace_EU> Select() { XDocument xDoc = XDocument.Load(ConstantsXml.FilePath); List <XElement> elementy = xDoc.Descendants("Dotace_EU").Descendants("Dotace").ToList(); Collection <Dotace_EU> vsechnyDotace = new Collection <Dotace_EU>(); int id; int vyse; DateTime datum; int idStavby; foreach (XElement element in elementy) { Dotace_EU dotace = new Dotace_EU(); int.TryParse(element.Attribute("Id_dotace").Value, out id); int.TryParse(element.Attribute("Vyse_dotace").Value, out vyse); DateTime.TryParse(element.Attribute("Datum_prideleni").Value, out datum); dotace.Zpusob_pouziti = element.Attribute("Zpusob_pouziti").Value; int.TryParse(element.Attribute("Id_stavby").Value, out idStavby); dotace.Id_dotace = id; dotace.Vyse_dotace = vyse; dotace.Datum_prideleni = datum; dotace.Id_stavby = idStavby; vsechnyDotace.Add(dotace); dotace = null; } return(vsechnyDotace); }
/* * 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(Dotace_EU dotace_EU) * { * Database db = new Database(); * db.Connect(); * OracleCommand command = db.CreateCommand(SQL_INSERT); * PrepareCommand(command, dotace_EU); * int ret = db.ExecuteNonQuery(command); * db.Close(); * return ret; * }*/ /* * public static int Update(Dotace_EU dotace_EU) * { * Database db = new Database(); * db.Connect(); * OracleCommand command = db.CreateCommand(SQL_UPDATE); * PrepareCommand(command, dotace_EU); * int ret = db.ExecuteNonQuery(command); * db.Close(); * return ret; * }*/ /* * public static Collection<Dotace_EU> 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<Dotace_EU> VsechnyDotace = Read(reader, false); * reader.Close(); * * if (Db == null) * { * db.Close(); * } * * return VsechnyDotace; * }*/ /* * public static Dotace_EU Select_id(int idDotace, Database Db = null) * { * Database db = new Database(); * db.Connect(); * OracleCommand command = db.CreateCommand(SQL_SELECT_ID); * * command.Parameters.AddWithValue(":id", idDotace); * OracleDataReader reader = db.Select(command); * * Collection<Dotace_EU> vsechnyDotace = Read(reader, true); * Dotace_EU dotace_EU = null; * if (vsechnyDotace.Count == 1) * { * dotace_EU = vsechnyDotace[0]; * } * reader.Close(); * db.Close(); * return dotace_EU; * }*/ private static void PrepareCommand(OracleCommand command, Dotace_EU Dotace_EU) { command.BindByName = true; command.Parameters.AddWithValue(":id", Dotace_EU.Id_dotace); command.Parameters.AddWithValue(":vyse", Dotace_EU.Vyse_dotace); command.Parameters.AddWithValue(":datum_prideleni", Dotace_EU.Datum_prideleni); command.Parameters.AddWithValue(":zpusob_pouziti", Dotace_EU.Zpusob_pouziti); command.Parameters.AddWithValue(":id_stavby", Dotace_EU.Id_stavby); }
public void Update(Dotace_EU dotace_EU) { Database db = new Database(); db.Connect(); OracleCommand command = db.CreateCommand(SQL_UPDATE); PrepareCommand(command, dotace_EU); int ret = db.ExecuteNonQuery(command); db.Close(); }
public void Insert(Dotace_EU dotace_EU) { XDocument xDoc = XDocument.Load(ConstantsXml.FilePath); XElement result = new XElement("Dotace", new XAttribute("Id_dotace", dotace_EU.Id_dotace), new XAttribute("Vyse_dotace", dotace_EU.Vyse_dotace), new XAttribute("Datum_prideleni", dotace_EU.Datum_prideleni.ToShortDateString()), new XAttribute("Zpusob_pouziti", dotace_EU.Zpusob_pouziti), new XAttribute("Id_stavby", dotace_EU.Id_stavby)); xDoc.Root.Element("Dotace_EU").Add(result); xDoc.Save(ConstantsXml.FilePath); }
public Dotace_EU Select_id(int idDotace) { Collection <Dotace_EU> vsechnyDotace = this.Select(); Dotace_EU vybranaDotace = null; foreach (Dotace_EU dotace in vsechnyDotace) { if (dotace.Id_dotace == idDotace) { vybranaDotace = dotace; } } return(vybranaDotace); }
public void Update(Dotace_EU dotace_EU) { XDocument xDoc = XDocument.Load(ConstantsXml.FilePath); var q = from node in xDoc.Descendants("Dotace_EU").Descendants("Dotace") let attr = node.Attribute("Id_dotace") where (attr != null && attr.Value == dotace_EU.Id_dotace.ToString()) select node; q.ToList().ForEach(x => { x.Attribute("Vyse_dotace").Value = dotace_EU.Vyse_dotace.ToString(); x.Attribute("Datum_prideleni").Value = dotace_EU.Datum_prideleni.ToShortDateString(); x.Attribute("Zpusob_pouziti").Value = dotace_EU.Zpusob_pouziti; x.Attribute("Id_stavby").Value = dotace_EU.Id_stavby.ToString(); }); xDoc.Save(ConstantsXml.FilePath); }
private static Collection <Dotace_EU> Read(OracleDataReader reader, bool complete) { Collection <Dotace_EU> VsechnyDotace = new Collection <Dotace_EU>(); while (reader.Read()) { int i = -1; Dotace_EU Dotace_EU = new Dotace_EU(); Dotace_EU.Id_dotace = reader.GetInt32(++i); Dotace_EU.Vyse_dotace = reader.GetInt32(++i); if (complete) { Dotace_EU.Datum_prideleni = reader.GetDateTime(++i); Dotace_EU.Zpusob_pouziti = reader.GetString(++i); } Dotace_EU.Id_stavby = reader.GetInt32(++i); VsechnyDotace.Add(Dotace_EU); } return(VsechnyDotace); }
public Dotace_EU Select_id(int idDotace) { Database db = new Database(); db.Connect(); OracleCommand command = db.CreateCommand(SQL_SELECT_ID); command.Parameters.AddWithValue(":id", idDotace); OracleDataReader reader = db.Select(command); Collection <Dotace_EU> vsechnyDotace = Read(reader, true); Dotace_EU dotace_EU = null; if (vsechnyDotace.Count == 1) { dotace_EU = vsechnyDotace[0]; } reader.Close(); db.Close(); return(dotace_EU); }