/*! \fn void add_music(string sql_statement,MusicCD musicCD) * \brief A adding musiccd function. * \details It is used to add musiccd value to database. * \param sql_statement (string) it holds sql statement. * \param musicCD (MusicCD) it holds MusicCD object. * \return void */ public void add_musiccd(string sql_statement, MusicCD musicCD) { using (SQLiteConnection connection = new SQLiteConnection(path)) { SQLiteCommand sql_command = new SQLiteCommand(); sql_command.CommandText = sql_statement; sql_command.Connection = connection; //bağlantı kuruluyor. sql_command.Parameters.AddWithValue("@Id", musicCD.getId()); sql_command.Parameters.AddWithValue("@Name", musicCD.getName()); sql_command.Parameters.AddWithValue("@Price", musicCD.getPrice()); sql_command.Parameters.AddWithValue("@Image", musicCD.image_path); sql_command.Parameters.AddWithValue("@Singer", musicCD.singer); sql_command.Parameters.AddWithValue("@Type", musicCD.type); sql_command.Parameters.AddWithValue("@Stock", musicCD.Stok); connection.Open(); //connnection açılır. try { sql_command.ExecuteNonQuery(); MessageBox.Show("Production has been added"); } catch (Exception ex) { MessageBox.Show("Production could not be added"); throw new Exception(ex.Message); } connection.Close(); } }
/*! \fn List<MusicCD> read_musiccd(string value) * \brief A reading data function. * \details It is used to read data from musicCD table in database. * \param value (string) table name. * \return List<Customer> */ public List <MusicCD> read_musiccd(string value) { MusicCD m = new MusicCD(0, null, 0, null, null, MusicCD.Type.Country, 0); m.setTotalCd(1); MusicCDList.Clear(); using (connection = new SQLiteConnection(path)) { connection.Open(); string stm = "SELECT * FROM " + value; using (sql_command = new SQLiteCommand(stm, connection)) { using (SQLiteDataReader sdr = sql_command.ExecuteReader()) { while (sdr.Read()) { MusicCD mymusicCD = new MusicCD(sdr.GetInt32(0), sdr.GetString(1), sdr.GetDouble(2), null, sdr.GetString(4), (MusicCD.Type)sdr.GetInt32(5), sdr.GetInt32(6)); MusicCDList.Add(mymusicCD); } sdr.Close(); connection.Close(); } } connection.Close(); } return(MusicCDList); }
/*! \fn void addNewMusicCD(int id,string nm, double prc ,string img,string Singer, MusicCD.Type type,int stok) * \brief A void function. * \details It is used to add musiccd into musiccd table in database. * \param id (int) id of musiccd * \param nm (string) name of musiccd * \param prc (double) price of musiccd * \param img (string) Cover Page Picture's directory of musiccd * \param type (MusicCD.Type) type of musiccd * \param stok (int) Stock Information of musiccd * \return void */ public void addNewMusicCD(int id, string nm, double prc, string img, string Singer, MusicCD.Type type, int stok) { MusicCD musicCD = new MusicCD(id, nm, prc, img, Singer, type, stok); Database database = Database.get_instance(); database.add_musiccd("INSERT INTO MusicCDTable(Id,Name,Price,Image,Singer,Type,Stock) values(@Id,@Name,@Price,@Image,@Singer,@Type,@Stock)", musicCD); }