/* * /// <summary> * /// Select records. * /// </summary> * public Collection<Typ_platby> select() * { * Database db; * if (pDb == null) * { * db = new Database(); * db.Connect(); * } * else * { * db = (Database)pDb; * } * SqlCommand command = db.CreateCommand(SQL_SELECT); * SqlDataReader reader = db.Select(command); * * Collection<Typ_platby> Typ_platbys = Read(reader, true); * reader.Close(); * db.Close(); * return Typ_platbys; * } */ /// <summary> /// Select records for typ_platby. /// </summary> public Typ_platby select(int id_typ_platby, Database pDb = null) { Database db; if (pDb == null) { db = new Database(); db.Connect(); } else { db = (Database)pDb; } SqlCommand command = db.CreateCommand(SQL_SELECT_ID); command.Parameters.AddWithValue("@id_typ_platby", id_typ_platby); SqlDataReader reader = db.Select(command); Collection <Typ_platby> typ_platbys = Read(reader); Typ_platby typ_platby = null; if (typ_platbys.Count == 1) { typ_platby = typ_platbys[0]; } reader.Close(); if (pDb == null) { db.Close(); } return(typ_platby); }
private static Collection <Typ_platby> Read(SqlDataReader reader, bool withItemsCount = false) { Collection <Typ_platby> typ_platbys = new Collection <Typ_platby>(); while (reader.Read()) { Typ_platby typ_platby = new Typ_platby(); int i = -1; typ_platby.id_typ_platby = reader.GetInt32(++i); typ_platby.zpusob_platby = reader.GetString(++i); typ_platbys.Add(typ_platby); } return(typ_platbys); }
/// <summary> /// Update the record. /// </summary> /// <param nazev="typ_platby"></param> /// <returns></returns> public static int update(Typ_platby typ_platby, Database pDb = null) { Database db; if (pDb == null) { db = new Database(); db.Connect(); } else { db = (Database)pDb; } SqlCommand command = db.CreateCommand(SQL_UPDATE); PrepareCommand(command, typ_platby); int ret = db.ExecuteNonQuery(command); if (pDb == null) { db.Close(); } return(ret); }
/// <summary> /// Prepare a command. /// </summary> private static void PrepareCommand(SqlCommand command, Typ_platby typ_platby) { command.Parameters.AddWithValue("@id_typ_platby", typ_platby.id_typ_platby); command.Parameters.AddWithValue("@nazev", typ_platby.zpusob_platby); }