public void DeleteSoutez(Soutez soutez) { if (soutez.ID_Souteze != 0) { _isoutez.Delete(soutez); } }
/// <summary> /// Insert the record. /// </summary> public static int Prihlas(Dvojice dvojice, Soutez soutez, Database pDb = null) { Database db; if (pDb == null) { db = new Database(); db.Connect(); } else { db = (Database)pDb; } SqlCommand command = db.CreateCommand(SQL_PRIHLAS); command.Parameters.AddWithValue("@did", dvojice.did); command.Parameters.AddWithValue("@cid", soutez.cid); int ret = db.ExecuteNonQuery(command); //int dvojice = DvojiceTable.Select(kun.cislo_licence, jezdec.cislo_licence, db); if (pDb == null) { db.Close(); } return(ret); }
public Soutez SelectId(int id) { Soutez a = null; var args = new Dictionary <string, string> { { "@id_souteze", id.ToString() } }; using (var table = TableData.Querry(SqlSelectId, args)) { if (table.Rows.Count != 0) { a = new Soutez { ID_Souteze = (int)table.Rows[0]["id_klubu"], Nazev = (string)table.Rows[0]["nazev"], Kdy = DateTime.Parse(table.Rows[0]["kdy"].ToString()), Startovne = (int)table.Rows[0]["startovne"], Adresa_ID_Adresy = (int)table.Rows[0]["adresa_id_adresy"], Organizator_ID_Organizatora = (int)table.Rows[0]["organizator_id_organizatora"], }; } } return(a); }
/// <summary> /// Update the record. /// </summary> public static int Update(Soutez soutez, 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, soutez); int ret = db.ExecuteNonQuery(command); if (pDb == null) { db.Close(); } return(ret); }
/// <summary> /// Prepare a command. /// </summary> private static void PrepareCommand(SqlCommand command, Soutez soutez) { command.Parameters.AddWithValue("@cid", soutez.cid); command.Parameters.AddWithValue("@zid", soutez.zid); command.Parameters.AddWithValue("@obtiznost", soutez.obtiznost); command.Parameters.AddWithValue("@limit", soutez.limit); }
/// <summary> /// Insert the record. /// </summary> /// public static int Insert(Soutez soutez, Database pDb = null) { Database db; if (pDb == null) { db = new Database(); db.Connect(); } else { db = (Database)pDb; } SqlCommand command = db.CreateCommand(SQL_SELECT_MAX); SqlDataReader reader = db.Select(command); reader.Read(); soutez.cid = reader.GetInt32(0) + 1; reader.Close(); command = db.CreateCommand(SQL_INSERT); PrepareCommand(command, soutez); db.ExecuteNonQuery(command); if (pDb == null) { db.Close(); } return(soutez.cid); }
/// <summary> /// Select the record. /// </summary> /// <param name="id">soutez id</param> public static Soutez Select(int id, 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", id); SqlDataReader reader = db.Select(command); Collection <Soutez> souteze = Read(reader); Soutez soutez = null; if (souteze.Count == 1) { soutez = souteze[0]; } reader.Close(); if (pDb == null) { db.Close(); } return(soutez); }
public void InsertSoutez(Soutez soutez) { if (soutez.ID_Souteze == 0) { _isoutez.Insert(soutez); } else { _isoutez.Update(soutez); } }
private Soutez LoadSoutez(Soutez soutez) { Soutez tempSoutez = new Soutez(); tempSoutez.ID_Souteze = soutez.ID_Souteze; tempSoutez.Nazev = soutez.Nazev; tempSoutez.Kdy = soutez.Kdy; tempSoutez.Startovne = soutez.Startovne; tempSoutez.Organizator_ID_Organizatora = soutez.Organizator_ID_Organizatora; tempSoutez.Adresa_ID_Adresy = soutez.Adresa_ID_Adresy; return(tempSoutez); }
public NovaSoutezF(Soutez soute, ISoutez isoutez) { InitializeComponent(); _isoutez = isoutez; _soutezDomain = new SoutezDomain(_isoutez); soutez = LoadSoutez(soute); tb_nezev.Text = soutez.Nazev; tb_startovne.Text = soutez.Startovne.ToString(); dtp_datum.Value = soutez.Kdy; tb_organizator.Text = soutez.Organizator_ID_Organizatora.ToString(); tb_adresa.Text = soutez.Adresa_ID_Adresy.ToString(); }
private static Collection <Soutez> Read(SqlDataReader reader) { Collection <Soutez> souteze = new Collection <Soutez>(); while (reader.Read()) { int i = -1; Soutez soutez = new Soutez(); soutez.cid = reader.GetInt32(++i); soutez.zid = reader.GetInt32(++i); soutez.obtiznost = reader.GetString(++i); soutez.limit = reader.GetTimeSpan(++i); souteze.Add(soutez); } return(souteze); }
private void DataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { DataGridView table = (DataGridView)sender; if (e.RowIndex == -1) { return; } Soutez a = _soutez.SelectId((int)table.Rows[e.RowIndex].Cells["id_souteze"].Value); using (NovaSoutezF detail = new NovaSoutezF(a, _soutez)) { if (detail.ShowDialog() == DialogResult.OK) { RefreshList(); } } }
public IEnumerable <Soutez> SelectArray() { List <Soutez> Souteze = new List <Soutez>(); using (var table = TableData.Querry(SqlSelect)) { foreach (DataRow tablerow in table.Rows) { Soutez sout = new Soutez(); sout.ID_Souteze = int.Parse(tablerow[0].ToString()); sout.Nazev = tablerow[1].ToString(); sout.Kdy = DateTime.Parse(tablerow[2].ToString()); sout.Startovne = int.Parse(tablerow[3].ToString()); sout.Adresa_ID_Adresy = int.Parse(tablerow[4].ToString()); sout.Organizator_ID_Organizatora = int.Parse(tablerow[5].ToString()); Souteze.Add(sout); } } return(Souteze); }
private void button4_Click(object sender, EventArgs e) { Soutez soutez = new Soutez(); soutez.obtiznost = textObtiznost.Text; TimeSpan j; if (TimeSpan.TryParse(textLimit.Text, out j)) { soutez.limit = j; } else { errorProvider1.SetError(textLimit, "Špatná hodnota, zadejte čas ve formátu hh:mm:ss"); return; } model.newSouteze.Add(soutez); BindingList <Soutez> bindingList = new BindingList <Soutez>(model.newSouteze); dataGridView3.AutoGenerateColumns = false; dataGridView3.DataSource = bindingList; }