public static int Insert(Pisemka pisemka, Database pDb = null) { Database db; if (pDb == null) { db = new Database(); db.Connect(); } else { db = pDb; } SqlCommand command = db.CreateCommand(SQL_INSERT); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@IdZapsanyKurz", pisemka.ZapsanyKurz.IdKurz); command.Parameters.AddWithValue("@DatumTestu", pisemka.DatumPisemky); int ret = db.ExecuteNonQuery(command); if (pDb == null) { db.Close(); } return(ret); }
private static Collection <Pisemka> Read(SqlDataReader reader, bool complete) { Collection <Pisemka> pisemky = new Collection <Pisemka>(); while (reader.Read()) { Pisemka pisemka = new Pisemka(); int i = -1; pisemka.IdPisemka = reader.GetInt32(++i); if (!reader.IsDBNull(++i)) { pisemka.DatumPisemky = reader.GetDateTime(i); } if (complete) { if (!reader.IsDBNull(++i)) { pisemka.Znamka = reader.GetByte(i); } } pisemka.IdZapsanyKurz = reader.GetInt32(++i); pisemka.ZapsanyKurz = new ZapsanyKurz(); pisemka.ZapsanyKurz.IdRegistrace = pisemka.IdZapsanyKurz; pisemka.ZapsanyKurz.DatumZapisu = reader.GetDateTime(++i); pisemka.ZapsanyKurz.IdStudent = reader.GetInt32(++i); pisemka.ZapsanyKurz.IdKurz = reader.GetInt32(++i); pisemky.Add(pisemka); } return(pisemky); }
private static void PrepareCommand(SqlCommand command, Pisemka pisemka) { command.Parameters.AddWithValue("@IdPisemka", pisemka.IdPisemka); command.Parameters.AddWithValue("@DatumTestu", pisemka.DatumPisemky); command.Parameters.AddWithValue("@Znamka", pisemka.Znamka); command.Parameters.AddWithValue("@IdZapsanyKurz", pisemka.IdZapsanyKurz); }
private void CREATE_TEST_Click(object sender, EventArgs e) { Pisemka p = new Pisemka(); p.ZapsanyKurz = new ZapsanyKurz(); p.ZapsanyKurz.IdKurz = this.idSelectedCourse; p.DatumPisemky = TEST_DP.Value; if (p.DatumPisemky > DateTime.Now) { PisemkaTable.Insert(p); } }
public static int Update(Pisemka pisemka) { var db = new Database(); db.Connect(); SqlCommand command = db.CreateCommand(SQL_UPDATE); PrepareCommand(command, pisemka); int ret = db.ExecuteNonQuery(command); db.Close(); return(ret); }
private static Collection <Pisemka> Read2(SqlDataReader reader, bool complete) { Collection <Pisemka> pisemky = new Collection <Pisemka>(); while (reader.Read()) { Pisemka pisemka = new Pisemka(); int i = -1; pisemka.IdPisemka = reader.GetInt32(++i); pisemka.DatumPisemky = reader.GetDateTime(++i); if (complete && !reader.IsDBNull(++i)) { pisemka.Znamka = reader.GetByte(i); } pisemky.Add(pisemka); } return(pisemky); }