private Perkuliahan( Kuliah kuliah, Ruangan ruangan, int hariPerkuliahan, int waktuMulai, int waktuSelesai, string penanggungJawab) { this.kuliah = kuliah; this.ruangan = ruangan; this.hariPerkuliahan = hariPerkuliahan; this.waktuMulai = waktuMulai; this.waktuSelesai = waktuSelesai; this.penanggungJawab = penanggungJawab; }
public static Perkuliahan Add( Kuliah kuliah, Ruangan ruangan, int hariPerkuliahan, int waktuMulai, int waktuSelesai, string penanggungJawab) { Perkuliahan perkuliahan = null; try { using (MySqlConnection connection = MySqlConnector.GetConnection()) { string query = String.Format( "INSERT INTO {0} ({1}, {2}, {3}, {4}, {5}, {6}) " + "VALUES ({7}, {8}, {9}, {10}, {11}, {12})", TBL_PERKULIAHAN, COL_KODE_KULIAH, COL_NAMA_RUANGAN, COL_HARI_PERKULIAHAN, COL_WAKTU_MULAI, COL_WAKTU_SELESAI, COL_PENANGGUNG_JAWAB, PRM_KODE, PRM_NAMA, PRM_HARI_PERKULIAHAN, PRM_WAKTU_MULAI, PRM_WAKTU_SELESAI, PRM_TANGGUNG); MySqlCommand command = new MySqlCommand(query, connection); command.Parameters.AddWithValue(PRM_KODE, kuliah.Kode); command.Parameters.AddWithValue(PRM_NAMA, ruangan.Nama); command.Parameters.AddWithValue(PRM_HARI_PERKULIAHAN, hariPerkuliahan); command.Parameters.AddWithValue(PRM_WAKTU_MULAI, waktuMulai); command.Parameters.AddWithValue(PRM_WAKTU_SELESAI, waktuSelesai); command.Parameters.AddWithValue(PRM_TANGGUNG, penanggungJawab); connection.Open(); if (command.ExecuteNonQuery() > 0) perkuliahan = new Perkuliahan(kuliah, ruangan, hariPerkuliahan, waktuMulai, waktuSelesai, penanggungJawab); } } catch (MySqlException) { } return perkuliahan; }
public bool Equals(Kuliah kuliah) { if ((object)kuliah == null) return false; return this.kode.Equals(kuliah.kode); }
public static Kuliah Get(string kode) { Kuliah kuliah = null; try { using (MySqlConnection connection = MySqlConnector.GetConnection()) { string query = String.Format( "SELECT * FROM {0} WHERE {1}={2}", TBL_KULIAH, COL_KODE_KULIAH, PRM_KODE_KULIAH); MySqlCommand command = new MySqlCommand(query, connection); command.Parameters.AddWithValue(PRM_KODE_KULIAH, kode); if (connection.State != System.Data.ConnectionState.Open) connection.Open(); using (MySqlDataReader reader = command.ExecuteReader()) { if (reader.Read()) { kuliah = new Kuliah( (string)reader[COL_NAMA_KULIAH], (string)reader[COL_KODE_KULIAH], (int)reader[COL_PESERTA]); } } } } catch (MySqlException) { } return kuliah; }
public static Kuliah Add(string nama, string kode, int peserta) { Kuliah kuliah = null; try { using (MySqlConnection connection = MySqlConnector.GetConnection()) { string query = String.Format( "INSERT INTO {0} ({1}, {2}, {3}) VALUES ({4}, {5}, {6})", TBL_KULIAH, COL_NAMA_KULIAH, COL_KODE_KULIAH, COL_PESERTA, PRM_NAMA_KULIAH, PRM_KODE_KULIAH, PRM_PESERTA); MySqlCommand command = new MySqlCommand(query, connection); command.Parameters.AddWithValue(PRM_NAMA_KULIAH, nama.Trim()); command.Parameters.AddWithValue(PRM_KODE_KULIAH, kode.Trim().ToUpper()); command.Parameters.AddWithValue(PRM_PESERTA, peserta); connection.Open(); if (command.ExecuteNonQuery() > 0) kuliah = new Kuliah(nama, kode, peserta); } } catch (MySqlException) { } return kuliah; }