Exemplo n.º 1
0
        public static MediaEvent Info(int id)
        {
            //p_info_playlist_details
            MediaEvent m = null;

            try
            {
                using (MySqlConnection conn = new MySqlConnection(App.setting.connectString))
                {
                    conn.Open();
                    string query = "`p_info_playlist_details`";
                    using (MySqlCommand cmd = new MySqlCommand(query, conn))
                    {
                        cmd.Parameters.Add(new MySqlParameter("@_id", MySqlDbType.Int32)
                        {
                            Direction = System.Data.ParameterDirection.Input, Value = id
                        });
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        var tmp = cmd.ExecuteScalar();
                        if (Convert.ToInt32(tmp) > 0)
                        {
                            using (MySqlDataReader reader = cmd.ExecuteReader())
                            {
                                m = reader.toMediaEvent();
                            }
                        }
                    };
                    conn.Close();
                };
            }
            catch (Exception)
            {
            }
            return(m);
        }
Exemplo n.º 2
0
 public static int Insert(MediaEvent media)
 {
     //p_insert_playlist_details
     try
     {
         using (MySqlConnection conn = new MySqlConnection(App.setting.connectString))
         {
             conn.Open();
             string query = "`p_insert_playlist_details`";
             using (MySqlCommand cmd = new MySqlCommand(query, conn))
             {
                 cmd.Parameters.Add(new MySqlParameter("@_playlist_id", MySqlDbType.Int32)
                 {
                     Direction = System.Data.ParameterDirection.Input, Value = media.playlist_id
                 });
                 cmd.Parameters.Add(new MySqlParameter("@_media_id", MySqlDbType.Int32)
                 {
                     Direction = System.Data.ParameterDirection.Input, Value = media.media_id
                 });
                 cmd.Parameters.Add(new MySqlParameter("@_time_begin", MySqlDbType.Time)
                 {
                     Direction = System.Data.ParameterDirection.Input, Value = media.TimeBegin
                 });
                 cmd.Parameters.Add(new MySqlParameter("@_time_end", MySqlDbType.Time)
                 {
                     Direction = System.Data.ParameterDirection.Input, Value = media.TimeEnd
                 });
                 cmd.CommandType = System.Data.CommandType.StoredProcedure;
                 cmd.ExecuteScalar();
             };
             conn.Close();
         };
         return(1);
     }
     catch (Exception)
     {
         return(-1);
     }
 }
 public static List<MediaEvent> toMediaEvents(this MySqlDataReader reader)
 {
     if (reader.HasRows)
     {
         List<MediaEvent> datas = new List<MediaEvent>();
         while (reader.Read())
         {
             if (!reader.IsDBNull(0))
             {
                 MediaEvent d = new MediaEvent();
                 d.ID = reader.GetInt32(Define.detail_id);
                 d.media_id = reader.GetInt32(Define.media_id);
                 d.playlist_id = reader.GetInt32(Define.playlist_id);
                 d.TimeBegin = reader.GetTimeSpan(Define.time_begin);
                 d.TimeEnd = reader.GetTimeSpan(Define.time_end);
                 d.Time = reader.GetDateTime(Define.detail_date);
                 datas.Add(d);
             }
         }
         return datas;
     }
     return null;
 }
 void UIE_DeleteEvent(object sender, MediaEvent e)
 {
     if (e != null)
     {
         if (MessageBox.Show("Bạn có muốn xóa media này không?", "Thông báo", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
         {
             e.delete();
             this.LoadUI(this.playlist);
         }
     }
 }
 void UIE_ViewMediaEvent(object sender, MediaEvent e)
 {
     this.Event = e;
 }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (this.MediaSelect.SelectedItem == null)
            {
                MessageBox.Show("Hãy chọn Media mà bạn muốn thêm.", "Thông báo");
                return;
            }
            if (this.UITimeBegin >= this.UITimeEnd)
            {
                MessageBox.Show("Thời gian bắt đầu phải nhỏ hơn thời gian kết thúc", "Thông báo");
                return;
            }
            #region Validate
            bool validate = true;
            List<MediaEvent> Medias = this.playlist.LoadMediaEvent();
            if (Medias != null)
            {
                foreach (MediaEvent mE in Medias)
                {
                    if (this.Event == null || ((this.Event != null) && this.Event.ID != mE.ID))
                    {
                        if ((mE.TimeBegin <= this.UITimeBegin.Time.TimeOfDay && mE.TimeEnd >= this.UITimeBegin.Time.TimeOfDay) || (mE.TimeBegin <= this.UITimeEnd.Time.TimeOfDay && mE.TimeEnd >= this.UITimeEnd.Time.TimeOfDay) || (mE.TimeBegin >= this.UITimeBegin.Time.TimeOfDay && mE.TimeEnd <= this.UITimeEnd.Time.TimeOfDay))
                        {
                            validate = false;
                            break;
                        }
                    }
                }
            }
            if (validate)
            {
                MediaEvent tmp = new MediaEvent();
                tmp.media_id = Convert.ToInt32(this.MediaSelect.SelectedItem.key);
                tmp.playlist_id = this.playlist.ID;
                tmp.TimeBegin = this.UITimeBegin.Time.TimeOfDay;
                tmp.TimeEnd = this.UITimeEnd.Time.TimeOfDay;
                int result = 0;
                if (this.Event == null)
                {
                    result = MediaEvent.Insert(tmp);
                }
                else
                {
                    tmp.ID = this._event.ID;
                    result =tmp.Save();

                }
                if (result != 1)
                {
                    MessageBox.Show("Lưu dữ liệu không thành công", "Thông báo");
                    return;
                }
                else
                {
                    this.Event = null;
                    this.LoadUI(this.playlist);
                }
            }
            else
            {
                MessageBox.Show("Không thể thêm media trong thời gian này", "Thông báo");
            }
            #endregion

        }
        public static int Insert(MediaEvent media)
        {
            //p_insert_playlist_details
            try
            {
                using (MySqlConnection conn = new MySqlConnection(App.setting.connectString))
                {
                    conn.Open();
                    string query = "`p_insert_playlist_details`";
                    using (MySqlCommand cmd = new MySqlCommand(query, conn))
                    {
                        cmd.Parameters.Add(new MySqlParameter("@_playlist_id", MySqlDbType.Int32) { Direction = System.Data.ParameterDirection.Input, Value = media.playlist_id });
                        cmd.Parameters.Add(new MySqlParameter("@_media_id", MySqlDbType.Int32) { Direction = System.Data.ParameterDirection.Input, Value = media.media_id });
                        cmd.Parameters.Add(new MySqlParameter("@_time_begin", MySqlDbType.Time) { Direction = System.Data.ParameterDirection.Input, Value = media.TimeBegin });
                        cmd.Parameters.Add(new MySqlParameter("@_time_end", MySqlDbType.Time) { Direction = System.Data.ParameterDirection.Input, Value = media.TimeEnd });
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        cmd.ExecuteScalar();

                    };
                    conn.Close();
                };
                return 1;
            }
            catch (Exception)
            {
                return -1;
            }
        }