예제 #1
0
        private void loadMedia()
        {
            if (mediaList.Length > 0)
            {
                mediaURI = new System.Uri(mediaList[currentSelection]);
                mElement.Source = mediaURI;
                mElement.Width = this.Width;
                mElement.Height = this.Height;
                mObject = new MediaObject(mElement);

                Uri uri = new Uri(mediaURI.ToString());
                string fileName = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath);
                dbInterface.sayFileName(fileName);

                mObject.playVideoMedia();
            }
            else
            {
                MessageBox.Show("Excuse me, but there seems to be no media items to play at this time. Please add/edit some entries that would play today and try again. Thank you!");
                this.Close();
            }
        }
예제 #2
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;
            }
        }
예제 #3
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;
            }
        }
예제 #4
0
        //btn Upload will upload the media to the database
        private void btnUpload_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (dtPickerEnd.SelectedDate > dtPickerStart.SelectedDate
                   || string.IsNullOrWhiteSpace(dtPickerStart.ToString()) || string.IsNullOrWhiteSpace(dtPickerEnd.ToString()))
                {
                    dbInterface.openConnection();

                    MediaObject mediaObject = new MediaObject(txtUploadPath.Text, dtPickerStart.SelectedDate.Value, dtPickerEnd.SelectedDate.Value);

                    if (dbInterface.insertMedia(mediaObject))
                    {
                        timer.Tick += new EventHandler(eraseLblError);
                        lblStatus.Foreground = Brushes.Green;
                        lblStatus.Content += "Successfully uploaded media.\n";
                        check.Visibility = System.Windows.Visibility.Visible;
                        timer.Start();
                    }
                    else
                    {
                        timer.Tick += new EventHandler(eraseLblError);
                        lblStatus.Foreground = Brushes.Red;
                        lblStatus.Content += "There was an error uploading the media.\n";
                        timer.Start();
                    }

                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Dates cannot be equal or blank");
                }
            }
            catch (UriFormatException ufe)
            {

                lblStatus.Foreground = Brushes.Red;
                lblStatus.Opacity = 1;
                timer.Tick += new EventHandler(eraseLblError);
                lblStatus.Content += "This file path doesn't seem quite right.\n";
                timer.Start();
            }
            catch (InvalidOperationException ioe)
            {
                lblStatus.Foreground = Brushes.Red;
                lblStatus.Opacity = 1;
                timer.Tick += new EventHandler(eraseLblError);
                lblStatus.Content += ioe.Message.Contains("Nullable") ? "Please ensure that you've selected a file and dates.\n" : ioe.Message + "\n";
                timer.Start();
            }

            dbInterface.closeConnection();
        }