Пример #1
0
        //Removes an entry from the media table and returns true if deletion is successful, false otherwise.
        public Boolean removeMedia(MediaObject mObject)
        {
            string removeQuery;
            string url, fileName, fileExt;

            url = mObject.getUrl();
            fileName = url.Split('\\').Last();
            fileExt = fileName.Split('.').Last();
            fileName = fileName.Split('.').First();

            removeQuery = "DELETE FROM Media WHERE url = '" + url + "' AND filename = '" + fileName + "' AND file_extension = '" + fileExt + "'";

            try
            {
                sqlCmd = new SqlCeCommand(removeQuery, sc);
                sqlRdr = sqlCmd.ExecuteReader();
                sqlRdr.Close();
                return true;
            }
            catch (SqlCeException sqlEx)
            {
                MessageBox.Show(sqlEx.Errors.ToString());
                return false;
            }
        }
Пример #2
0
        //Inserts an entry into the media table and returns true if insertion is successful, and false otherwise.
        public Boolean insertMedia(MediaObject mObject)
        {
            string insertQuery;
            string url, fileName, fileExt, fileType;
            int typeID, width, height;
            DateTime dateStart, dateEnd;

            url = mObject.getUrl();
            fileName = url.Split('\\').Last();
            fileExt = fileName.Split('.').Last();
            fileName = fileName.Split('.').First();
            typeID = MediaFileUtilities.getFileTypeID(fileExt);
            fileType = MediaFileUtilities.getFileType(fileExt);
            MediaElement thisMediaFile = new MediaElement();
            thisMediaFile.Source = new Uri(url);
            width = (int)thisMediaFile.Width;
            height = (int)thisMediaFile.Height;
            dateStart = mObject.getStartDate();
            dateEnd = mObject.getEndDate();

            insertQuery = "INSERT INTO Media([url],[filename],[file_extension],[type_id],[width],[height],[date_start],[date_end])"
                    + "VALUES ('" + url + "','" + fileName + "','" + fileExt + "','" + typeID + "','" + width + "','"
                    + height + "','" + dateStart + "','" + dateEnd + "');";

            try
            {
                sqlCmd = new SqlCeCommand(insertQuery, sc);
                sqlRdr = sqlCmd.ExecuteReader();
                sqlRdr.Close();
                return true;
            }
            catch (SqlCeException sqlEx)
            {
                MessageBox.Show(sqlEx.Errors.ToString());
                return false;
            }
        }