public ObservableCollection <Kelompok> GetKelompok(Perlombaan perlombaan) { ObservableCollection <Kelompok> listKelompok = new ObservableCollection <Kelompok>(); try { connection.Open(); string query = string.Format("select * from `kelompok` where id_perlombaan = '{0}'", perlombaan.IdPerlombaan); MySqlCommand command = new MySqlCommand(query, connection); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { listKelompok.Add(new Kelompok() { KodeKelompok = reader.GetString("kode_kelompok"), NamaKelompok = reader.GetString("nama_kelompok") }); } connection.Close(); } catch (Exception e) { MessageBox.Show("Error Retreiving Data Kelompok!\nDetail :" + e.Message); } foreach (Kelompok kelompok in listKelompok) { kelompok.ListAcara = GetAcara(perlombaan.IdPerlombaan, kelompok); } return(listKelompok); }
public void InsertLomba(Perlombaan perlombaanInput) { try { connection.Open(); string query = "SELECT count(tanggal_perlombaan) AS jumlah FROM `perlombaan` WHERE tanggal_perlombaan = '" + perlombaanInput.TanggalPerlombaan.ToString("yyyy-MM-dd") + "'"; MySqlCommand command = new MySqlCommand(query, connection); //making key for lomba string kodePerlombaan = perlombaanInput.TanggalPerlombaan.ToString("ddMMyyyy"); Int64 keyLastPieceInt = (Int64)command.ExecuteScalar() + 1; string keyLastPiece = keyLastPieceInt.ToString("D2"); kodePerlombaan = kodePerlombaan + keyLastPiece; //end making key query = string.Format("insert into `perlombaan`(id_perlombaan, nama_perlombaan, tanggal_perlombaan) values('{0}','{1}','{2}')", kodePerlombaan, perlombaanInput.NamaPerlombaan, perlombaanInput.TanggalPerlombaan.ToString("yyyy-MM-dd")); command.CommandText = query; command.ExecuteNonQuery(); if (perlombaanInput.ListKelompok.Count > 0) { foreach (Kelompok kelompok in perlombaanInput.ListKelompok) { query = string.Format("insert into `kelompok`(id_perlombaan, kode_kelompok, nama_kelompok) values('{0}','{1}','{2}')", kodePerlombaan, kelompok.KodeKelompok, kelompok.NamaKelompok); command.CommandText = query; command.ExecuteNonQuery(); } } connection.Close(); } catch (Exception e) { MessageBox.Show("Error Inserting Perlombaan!\nKeterangan :" + e.Message); } }
public void SubmitAcara(Perlombaan perlombaanInput) { try { connection.Open(); string query = string.Format("delete from `acara` where id_perlombaan = {0}", perlombaanInput.IdPerlombaan); MySqlCommand command = new MySqlCommand(query, connection); command.ExecuteNonQuery(); int i = 0; foreach (Kelompok kelompok in perlombaanInput.ListKelompok) { foreach (Acara acara in kelompok.ListAcara) { query = string.Format("insert into `acara`(id_perlombaan, id_acara, id_gaya, kode_kelompok, jarak, jenis_acara, no_acara) values('{0}', {1}, {2}, '{3}', {4}, {5}, {6})", perlombaanInput.IdPerlombaan, i, acara.Gaya.IdGaya, kelompok.KodeKelompok, acara.Jarak, (byte)acara.JenisAcara, i); Console.WriteLine(query); command = new MySqlCommand(query, connection); command.ExecuteNonQuery(); i++; } } connection.Close(); } catch (Exception e) { MessageBox.Show("Error Submitting Acara!\nDetail :" + e.Message); } }
public void HapusPerlombaan(Perlombaan perlombaanHapus) { try { connection.Open(); string query = string.Format("delete from `perlombaan` where id_perlombaan = '{0}'", perlombaanHapus.IdPerlombaan); MySqlCommand command = new MySqlCommand(query, connection); command.ExecuteNonQuery(); connection.Close(); } catch (Exception e) { MessageBox.Show("Error Inserting Perlombaan!\nKeterangan :" + e.Message); } }
public void UpdatePerlombaan(Perlombaan perlombaanEdit) { try { connection.Open(); string query = string.Format("update `perlombaan` set nama_perlombaan='{0}', tanggal_perlombaan='{1}' where id_perlombaan = '{2}'", perlombaanEdit.NamaPerlombaan, perlombaanEdit.TanggalPerlombaan.ToString("yyyy-MM-dd"), perlombaanEdit.IdPerlombaan); MySqlCommand command = new MySqlCommand(query, connection); command.ExecuteNonQuery(); connection.Close(); } catch (Exception e) { MessageBox.Show("Error Inserting Perlombaan!\nKeterangan :" + e.Message); } }