示例#1
0
        public static Peminjam Get(int id) {
            Peminjam peminjam = null;

            try {
                using (MySqlConnection connection = MySqlConnector.GetConnection()) {
                    string query = String.Format(
                        "SELECT * FROM {0} WHERE {1}={2}",
                        TBL_PEMINJAM,
                        COL_ID_PEMINJAM, PRM_ID_PEMINJAM);

                    MySqlCommand command = new MySqlCommand(query, connection);
                    command.Parameters.AddWithValue(PRM_ID_PEMINJAM, id);

                    connection.Open();
                    using (MySqlDataReader reader = command.ExecuteReader()) {
                        if (reader.Read()) {
                            peminjam = new Peminjam(
                                (int)reader[COL_ID_PEMINJAM],
                                (string)reader[COL_NAMA_PEMINJAM]);
                        }
                    }
                }
            }
            catch (MySqlException e) {
                Console.WriteLine(e.Message);
            }
            
            return peminjam;
        }
示例#2
0
 private Kegiatan(Peminjam peminjam, Ruangan ruangan, string nama, DateTime tanggal, int waktuMulai, int waktuSelesai) {
     this.peminjam = peminjam;
     this.ruangan = ruangan;
     this.nama = nama;
     this.tanggal = tanggal;
     this.waktuMulai = waktuMulai;
     this.waktuSelesai = waktuSelesai;
 }
示例#3
0
        public static bool Delete(Peminjam peminjam, Ruangan ruangan, String nama) {
            bool result = false;

            using (MySqlConnection connection = MySqlConnector.GetConnection()) {
                string query = String.Format(
                    "DELETE FROM {0} WHERE {1}={2} AND {3}={4} AND {5}={6}",
                    TBL_KEGIATAN,
                    COL_ID_PEMINJAM, PRM_ID_PEMINJAM,
                    COL_NAMA_RUANGAN, PRM_NAMA_RUANGAN,
                    COL_NAMA_KEGIATAN, PRM_NAMA_KEGIATAN);

                MySqlCommand command = new MySqlCommand(query, connection);
                command.Parameters.AddWithValue(PRM_ID_PEMINJAM, peminjam.Id);
                command.Parameters.AddWithValue(PRM_NAMA_RUANGAN, ruangan.Nama);
                command.Parameters.AddWithValue(PRM_NAMA_KEGIATAN, nama);

                connection.Open();
                result = command.ExecuteNonQuery() > 0;
            }
            return result;
        }
示例#4
0
        public static Kegiatan Add(Peminjam peminjam, Ruangan ruangan, string namakegiatan,
                                DateTime tanggalkegiatan, int mulaikegiatan, int selesaikegiatan) {
            Kegiatan kegiatan = null;

            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_KEGIATAN,
                    COL_ID_PEMINJAM, COL_NAMA_RUANGAN, COL_NAMA_KEGIATAN,
                    COL_TANGGAL_KEGIATAN, COL_WAKTUMULAI_KEGIATAN, COL_WAKTUSELESAI_KEGIATAN,
                    PRM_ID_PEMINJAM, PRM_NAMA_RUANGAN, PRM_NAMA_KEGIATAN,
                    PRM_TANGGAL_KEGIATAN, PRM_WAKTUMULAI_KEGIATAN, PRM_WAKTUSELESAI_KEGIATAN);

                MySqlCommand command = new MySqlCommand(query, connection);
                command.Parameters.AddWithValue(PRM_ID_PEMINJAM, peminjam.Id);
                command.Parameters.AddWithValue(PRM_NAMA_RUANGAN, ruangan.Nama);
                command.Parameters.AddWithValue(PRM_NAMA_KEGIATAN, namakegiatan);
                command.Parameters.AddWithValue(PRM_TANGGAL_KEGIATAN, tanggalkegiatan.ToString("yyyy-MM-dd"));
                command.Parameters.AddWithValue(PRM_WAKTUMULAI_KEGIATAN, mulaikegiatan);
                command.Parameters.AddWithValue(PRM_WAKTUSELESAI_KEGIATAN, selesaikegiatan);

                connection.Open();
                if (command.ExecuteNonQuery() > 0)
                    kegiatan = new Kegiatan(
                        peminjam, ruangan, namakegiatan,
                        tanggalkegiatan, mulaikegiatan, selesaikegiatan
                    );
            }
            return kegiatan;
        }
示例#5
0
        public static Kegiatan Get(Peminjam peminjam, Ruangan ruangan, string nama) {
            Kegiatan kegiatan = null;

            using (MySqlConnection connection = MySqlConnector.GetConnection()) {
                string query = String.Format(
                    "SELECT * FROM {0} WHERE {1}={2} AND {3}={4}",
                    TBL_KEGIATAN,
                    COL_ID_PEMINJAM, PRM_ID_PEMINJAM,
                    COL_NAMA_RUANGAN, PRM_NAMA_RUANGAN,
                    COL_NAMA_KEGIATAN, PRM_NAMA_KEGIATAN);

                MySqlCommand command = new MySqlCommand(query, connection);
                command.Parameters.AddWithValue(PRM_ID_PEMINJAM, peminjam.Id);
                command.Parameters.AddWithValue(PRM_NAMA_RUANGAN, ruangan.Nama);
                command.Parameters.AddWithValue(PRM_NAMA_KEGIATAN, nama);

                connection.Open();
                using (MySqlDataReader reader = command.ExecuteReader()) {
                    if (reader.Read()) {
                        Peminjam peminjamIni = Peminjam.Get((int)reader[COL_ID_PEMINJAM]);
                        Ruangan ruanganIni = Ruangan.Get((string)reader[COL_NAMA_RUANGAN]);
                        kegiatan = new Kegiatan(
                            peminjamIni,
                            ruanganIni,
                            (string)reader[COL_NAMA_KEGIATAN],
                            (DateTime)reader[COL_TANGGAL_KEGIATAN],
                            (int)reader[COL_WAKTUMULAI_KEGIATAN],
                            (int)reader[COL_WAKTUSELESAI_KEGIATAN]
                        );
                    }
                }
            }
            return kegiatan;
        }
示例#6
0
        public static bool Delete(Peminjam peminjam) {
            bool result = false;

            try {
                using (MySqlConnection connection = MySqlConnector.GetConnection()) {
                    string query = String.Format(
                        "DELETE FROM {0} WHERE {1}={2}",
                        TBL_PEMINJAM,
                        COL_ID_PEMINJAM, PRM_ID_PEMINJAM);

                    MySqlCommand command = new MySqlCommand(query, connection);
                    command.Parameters.AddWithValue(PRM_ID_PEMINJAM, peminjam.id);

                    connection.Open();
                    result = command.ExecuteNonQuery() > 0;
                }
            }
            catch (MySqlException e) {
                Console.WriteLine(e.Message);
            }
            
            return result;
        }
示例#7
0
        public static Peminjam Add(string nama) {
            Peminjam peminjam = null;

            try {
                using (MySqlConnection connection = MySqlConnector.GetConnection()) {
                    Peminjam peminjamNama = Get(nama);
                    if (peminjamNama != null)
                        return peminjamNama;

                    string query = String.Format(
                        "INSERT INTO {0} ({1}) VALUES ({2})",
                        TBL_PEMINJAM,
                        COL_NAMA_PEMINJAM, PRM_NAMA_PEMINJAM);

                    MySqlCommand command = new MySqlCommand(query, connection);
                    command.Parameters.AddWithValue(PRM_NAMA_PEMINJAM, nama);

                    connection.Open();
                    if (command.ExecuteNonQuery() > 0)
                        peminjam = new Peminjam((int)command.LastInsertedId, nama);
                }
            }
            catch (MySqlException e) {
                Console.WriteLine(e.Message);
            }
            
            return peminjam;
        }