private void FillDataInGrid() { string Status = ddlStatus.SelectedValue; MediaTypes media_type_obj = new MediaTypes(); List<Media_Types> lst = media_type_obj.GetListByStatus(Status); //if (lst.Rows.Count > 0) //{ GridView1.DataSource = lst; GridView1.DataBind(); //} //else //{ // dt.Rows.Add(dt.NewRow()); // GridView1.DataSource = dt; // GridView1.DataBind(); // int TotalColumns = GridView1.Rows[0].Cells.Count; // GridView1.Rows[0].Cells.Clear(); // GridView1.Rows[0].Cells.Add(new TableCell()); // GridView1.Rows[0].Cells[0].ColumnSpan = TotalColumns; // GridView1.Rows[0].Cells[0].Text = "No Record Found"; //} }
protected void PopulateMediaTypeList2DDL() { MediaTypes media_type_obj = new MediaTypes(); List<Media_Types> lst= media_type_obj.GetListByStatus("1"); ddlMediaTypeList.Items.Clear(); ddlMediaTypeList.DataSource = lst; ddlMediaTypeList.DataTextField = "TypeName"; ddlMediaTypeList.DataValueField = "TypeId"; ddlMediaTypeList.DataBind(); ddlMediaTypeList.AutoPostBack = true; }
public int Delete(string userid, int idx, string photo, string thumbnail, string filename) { // Photo ============================================================================================================================================================= string photo_dir_path = HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["upload_image_dir"]) + "/media_images/photo"; if (photo != string.Empty) { module_obj.deleteFile(photo, photo_dir_path); } // Thumbnail ======================================================================================================================================================== string thumbnail_dir_path = HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["upload_image_dir"]) + "/media_images/thumbnails"; if (thumbnail != string.Empty) { module_obj.deleteFile(thumbnail, thumbnail_dir_path); } //Media File ======================================================================================================================================================== string file_path = string.Empty; MediaFiles media_obj = new MediaFiles(); DataTable dt = media_obj.GetDetailById(idx); if (dt.Rows.Count > 0) { int TypeId = Convert.ToInt32(dt.Rows[0]["TypeId"].ToString()); MediaTypes media_type_obj = new MediaTypes(); string TypePath = media_type_obj.GetTypePathByTypeId(TypeId); file_path = HttpContext.Current.Server.MapPath("~/" + TypePath); } module_obj.deleteFile(filename, file_path); //=================================================================================================================================================================== SqlCommand cmd = new SqlCommand("[Media].[Files_Delete]", con) { CommandType = CommandType.StoredProcedure, CommandTimeout = Settings.CommandTimeout }; cmd.Parameters.AddWithValue("@userid", userid); cmd.Parameters.AddWithValue("@ip", ip); cmd.Parameters.AddWithValue("@idx", idx); cmd.Parameters.Add(new SqlParameter("@o_return", SqlDbType.Int) { Direction = ParameterDirection.Output }); con.Open(); cmd.ExecuteNonQuery(); int retunvalue = (int)cmd.Parameters["@o_return"].Value; con.Close(); return(retunvalue); }
protected void PopulateMediaTypeList2DDL(string selected_value) { MediaTypes media_type_obj = new MediaTypes(); List<Media_Types> lst = media_type_obj.GetListByStatus("1"); ddlMediaTypeList.Items.Clear(); ddlMediaTypeList.DataSource = lst; ddlMediaTypeList.DataTextField = "TypeName"; ddlMediaTypeList.DataValueField = "TypeId"; ddlMediaTypeList.DataBind(); ddlMediaTypeList.SelectedValue = selected_value; ddlMediaTypeList.Enabled = false; }
private void DeleteMediaFile(string file_name) { int TypeId = Convert.ToInt32(ddlMediaTypeList.SelectedValue); MediaTypes media_type_obj = new MediaTypes(); Media_Types type_obj = media_type_obj.GetDetails(TypeId); string TypePath = type_obj.TypePath; string dir_path = Server.MapPath("~" + TypePath + "/" + ViewState["TopicId"].ToString()); if (Directory.Exists(dir_path)) { FileHandleClass file_handle_obj = new FileHandleClass(); file_handle_obj.deleteFile(file_name, dir_path); } }
private int UpdateData() { string userid = Session["UserId"].ToString(); int typeid = Convert.ToInt32(ddlMediaTypeList.SelectedValue); int topicid = Convert.ToInt32(ddlMediaTopicList.SelectedValue); int albumid = Convert.ToInt32(ddlAlbumList.SelectedValue); int artistid = Convert.ToInt32(ddlArtistList.SelectedValue); int composerid = Convert.ToInt32(ddlComposerList.SelectedValue); int playlistid = Convert.ToInt32(ddlPlayList.SelectedValue); string title = txtFileTitle.Text; string description = txtDescription.Value; string dimension =string.Empty; string source = txtSource.Text; string status = "0"; int autostart = 0; int medialoop = 0; if (chkAutoStart.Checked == true) autostart = 1; if (chkMedialoop.Checked == true) medialoop = 1; if (chkIsFilePublished.Checked == true) status = "1"; /*** UPLOAD ************************************************************************************************************/ string[] FileImg = new String[2]; string front_image = string.Empty; string main_image = string.Empty; string front_path = Server.MapPath(upload_front_image_dir); string main_path = Server.MapPath(upload_main_image_dir); string Orginal_front_image = ViewState["Thumbnail"].ToString(); string Orginal_main_image = ViewState["Photo"].ToString(); //if (FileUpload1.HasFile) if (Session["FileUpload1"] != null && Session["FileUpload1"].ToString() != string.Empty) { FileHandleClass file_bj = new FileHandleClass(); FileImg = file_bj.upload_front_main_image(FileUpload1, front_path, main_path, 120, 120); main_image = FileImg[0]; front_image = FileImg[1]; //System.Drawing.Image img1 = System.Drawing.Image.FromFile(front_path+ "/" + front_image); imgPhoto.ImageUrl = upload_front_image_dir + "/" + front_image; DeleteFrontImage(Orginal_front_image); DeleteMainImage(Orginal_main_image); } else { front_image = Orginal_front_image; main_image = Orginal_main_image; } ////======================================================================================================================== /*** UPLOAD FILE*************************************************************************************************************/ string filename = string.Empty; string fileurl = string.Empty, file_ext = string.Empty; string Orginal_File = ViewState["FileName"].ToString(); int TypeId = Convert.ToInt32(ddlMediaTypeList.SelectedValue); MediaTypes media_type_obj = new MediaTypes(); Media_Types type_obj = media_type_obj.GetDetails(TypeId); string TypeExt = type_obj.TypeExt.Trim(); string TypePath = type_obj.TypePath; string dir_path = Server.MapPath("~/" + TypePath + "/" + topicid); string[] arr_list = GetArray(TypeExt); if (rdlFileUpload.SelectedValue == "0") { HttpPostedFile posted_file = File1.PostedFile; if (posted_file.ContentLength > 0) { file_ext = System.IO.Path.GetExtension(posted_file.FileName).ToLower().Trim(); if (!Directory.Exists(dir_path)) Directory.CreateDirectory(dir_path); for (int i = 0; i < arr_list.Length; i++) { if (file_ext == arr_list[i].ToString()) { FileHandleClass file_obj = new FileHandleClass(); filename = file_obj.uploadInputFile(posted_file, dir_path); fileurl = string.Empty; DeleteMediaFile(Orginal_File); } } } else filename = ViewState["FileName"].ToString(); } else if (rdlFileUpload.SelectedValue == "1") { file_ext = System.IO.Path.GetExtension(txtFileUrl.Text).ToLower().Trim(); filename = System.IO.Path.GetFileName(txtFileUrl.Text); for (int i = 0; i < arr_list.Length; i++) { if (file_ext == arr_list[i].ToString()) { fileurl = txtFileUrl.Text; filename = string.Empty; } } if (fileurl.Length <= 0) { fileurl = ViewState["FileUrl"].ToString(); } } if (filename == string.Empty && fileurl == string.Empty) { filename = ViewState["FileName"].ToString(); fileurl = ViewState["FileUrl"].ToString(); } /************************************************************************************************************************/ MediaFiles media_obj = new MediaFiles(); int relust = media_obj.Update(_idx, userid, typeid, topicid, playlistid, albumid, artistid, composerid, filename, fileurl, title, description, autostart, medialoop, dimension, source, main_image, front_image, status); return relust; }
private int UpdateData() { string UserId = Session["UserId"].ToString(); string TypeName = txtTypeName.Text; string TypeExt = txtTypeExt.Text; string TypePath = txtTypePath.Text; string Description = txtDescription.Text; string Status = rdlStatus.SelectedValue; MediaTypes media_type_obj = new MediaTypes(); int i = media_type_obj.Update(_idx, UserId, TypeName, TypeExt, TypePath, Description, Status); return i; }
private void LoadData() { MediaTypes media_type_obj = new MediaTypes(); Media_Types type_obj = media_type_obj.GetDetails(_idx); EditingMediaTypes = type_obj; txtTypeName.Text = type_obj.TypeName; txtTypeExt.Text = type_obj.TypeExt; txtTypePath.Text = type_obj.TypePath; txtDescription.Text = type_obj.Description; string Status = type_obj.Status; PopulateStatus2DDL(Status); }
public string[] GetSelectedVideo() { Uri requestUri = Context.Request.Url; string baseUrl = requestUri.Scheme + Uri.SchemeDelimiter + requestUri.Host + (requestUri.IsDefaultPort ? "" : ":" + requestUri.Port); int typeid = 2; //====MediaType================================================================= MediaTypes media_type_obj = new MediaTypes(); Media_Types type_obj = media_type_obj.GetDetails(typeid); string TypePath = type_obj.TypePath; //============================================================================== int FileId = 0; string Title = string.Empty; string FileName = string.Empty; string FileUrl = string.Empty; string Photo = string.Empty; string Thumbnail = string.Empty; string file_path = string.Empty; string _path = baseUrl + "/" + TypePath + "/"; string dir_image_path = System.Configuration.ConfigurationManager.AppSettings["upload_media_image_dir"]; string image = ""; string[] array_list = new string[3]; MediaFiles media_obj = new MediaFiles(); DataTable dtMedia = media_obj.GetSelectedItem(typeid); for (int i = 0; i < dtMedia.Rows.Count; i++) { FileId = Convert.ToInt32(dtMedia.Rows[i]["FileId"].ToString()); Title = dtMedia.Rows[i]["Title"].ToString(); FileName = dtMedia.Rows[i]["FileName"].ToString(); FileUrl = dtMedia.Rows[i]["FileUrl"].ToString(); Photo = dtMedia.Rows[i]["Photo"].ToString(); Thumbnail = dtMedia.Rows[i]["Photo"].ToString(); file_path = _path + FileName; if (Photo != string.Empty) image = baseUrl + "/" + dir_image_path + "/photo/" + Photo; if (Photo == string.Empty) image = baseUrl + "/" + dir_image_path + "/thumbnails/" + Thumbnail; if (Photo == string.Empty && Thumbnail == string.Empty) image = baseUrl + "/images/no_image.jpg"; array_list[0] = array_list[0] + "," + Title; if (FileName != string.Empty && FileUrl == string.Empty) array_list[1] = array_list[1] + "," + file_path; else array_list[1] = array_list[1] + "," + FileUrl; array_list[2] = array_list[2] + "," + image; } return array_list; }
public string[] GetMediaFile(int FileId) { Uri requestUri = Context.Request.Url; string baseUrl = requestUri.Scheme + Uri.SchemeDelimiter + requestUri.Host + (requestUri.IsDefaultPort ? "" : ":" + requestUri.Port); MediaFiles media_obj = new MediaFiles(); DataTable dt = media_obj.GetDetailById(FileId); string Title = dt.Rows[0]["Title"].ToString(); string FileName = dt.Rows[0]["FileName"].ToString(); string FileUrl = dt.Rows[0]["FileUrl"].ToString(); string Photo = dt.Rows[0]["Photo"].ToString(); string Thumbnail = dt.Rows[0]["Photo"].ToString(); int TypeId = Convert.ToInt32(dt.Rows[0]["TypeId"].ToString()); //====MediaType================================================================= MediaTypes media_type_obj = new MediaTypes(); string TypePath = media_type_obj.GetTypePathByTypeId(TypeId); //============================================================================== //string dir_path = Server.MapPath("~/" + TypePath); string file_path = baseUrl + "/" + TypePath + "/" + FileName; string dir_image_path = System.Configuration.ConfigurationManager.AppSettings["upload_media_image_dir"]; string image = ""; if (Photo != string.Empty) image = baseUrl + "/" + dir_image_path + "/photo/" + Photo; if (Photo == string.Empty) image = baseUrl + "/" + dir_image_path + "/thumbnails/" + Thumbnail; if (Photo == string.Empty && Thumbnail == string.Empty) image = baseUrl + "/images/no_image.jpg"; string[] array_list = new string[3]; array_list[0] = Title; if (FileName != string.Empty && FileUrl == string.Empty) array_list[1] = file_path; else array_list[1] = FileUrl; array_list[2] = image; return array_list; }
public int Delete(string userid, int idx, string photo, string thumbnail, string filename) { // Photo ============================================================================================================================================================= string photo_dir_path = HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["upload_image_dir"]) + "/media_images/photo"; if (photo != string.Empty) module_obj.deleteFile(photo, photo_dir_path); // Thumbnail ======================================================================================================================================================== string thumbnail_dir_path = HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["upload_image_dir"]) + "/media_images/thumbnails"; if (thumbnail != string.Empty) module_obj.deleteFile(thumbnail, thumbnail_dir_path); //Media File ======================================================================================================================================================== string file_path = string.Empty; MediaFiles media_obj = new MediaFiles(); DataTable dt = media_obj.GetDetailById(idx); if (dt.Rows.Count > 0) { int TypeId = Convert.ToInt32(dt.Rows[0]["TypeId"].ToString()); MediaTypes media_type_obj = new MediaTypes(); string TypePath = media_type_obj.GetTypePathByTypeId(TypeId); file_path = HttpContext.Current.Server.MapPath("~/" + TypePath); } module_obj.deleteFile(filename, file_path); //=================================================================================================================================================================== SqlCommand cmd = new SqlCommand("[Media].[Files_Delete]", con) { CommandType = CommandType.StoredProcedure, CommandTimeout = Settings.CommandTimeout }; cmd.Parameters.AddWithValue("@userid", userid); cmd.Parameters.AddWithValue("@ip", ip); cmd.Parameters.AddWithValue("@idx", idx); cmd.Parameters.Add(new SqlParameter("@o_return", SqlDbType.Int) { Direction = ParameterDirection.Output }); con.Open(); cmd.ExecuteNonQuery(); int retunvalue = (int)cmd.Parameters["@o_return"].Value; con.Close(); return retunvalue; }
private int UpdateData() { string userid = Session["UserId"].ToString(); int typeid = Convert.ToInt32(ddlMediaTypeList.SelectedValue); int topicid = Convert.ToInt32(ddlMediaTopicList.SelectedValue); int albumid = Convert.ToInt32(ddlAlbumList.SelectedValue); int artistid = Convert.ToInt32(ddlArtistList.SelectedValue); int composerid = Convert.ToInt32(ddlComposerList.SelectedValue); int playlistid = Convert.ToInt32(ddlPlayList.SelectedValue); string title = txtFileTitle.Text; string description = txtDescription.Value; string dimension = txtDimension.Text; string source = txtSource.Text; string status = "0"; int autostart = 0; int medialoop = 0; if (chkAutoStart.Checked == true) autostart = 1; if (chkMedialoop.Checked == true) medialoop = 1; if (chkIsFilePublished.Checked == true) status = "1"; /*** UPLOAD IMAGE************************************************************************************************************/ string Orginal_Photo = ViewState["Photo"].ToString(); string Orginal_Thumbnail = ViewState["Thumbnail"].ToString(); string[] FileImg = new String[2]; string photo = string.Empty; string thumbnail = string.Empty; string front_path = Server.MapPath(front_image_dir); string main_path = Server.MapPath(main_image_dir); HttpPostedFile myfile = File2.PostedFile; if (chkAutoCreateThumbnail.Checked == true) { if (myfile.ContentLength > 0) { if (System.IO.Directory.Exists(front_path) && System.IO.Directory.Exists(main_path)) { FileHandleClass file_obj = new FileHandleClass(); FileImg = file_obj.uploadFrontMainInputFile(myfile, front_path, main_path, 120, 120); photo = FileImg[0]; thumbnail = FileImg[1]; DeleteFrontImage(Orginal_Photo); DeleteMainImage(Orginal_Thumbnail); } else { string scriptCode = "<script>alert('Đường dẫn không tồn tại.');</script>"; Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "scriptName", scriptCode); } } else { photo = ViewState["Photo"].ToString(); thumbnail = ViewState["Thumbnail"].ToString(); } } else { if (myfile.ContentLength > 0) { FileHandleClass file_handle_obj = new FileHandleClass(); photo = file_handle_obj.uploadFixedInputFile(myfile, front_path, 120, 120); DeleteFrontImage(Orginal_Photo); } else { photo = ViewState["Photo"].ToString(); thumbnail = ViewState["Thumbnail"].ToString(); } } ////======================================================================================================================== /*** UPLOAD FILE*************************************************************************************************************/ string filename = string.Empty; string fileurl = string.Empty, file_ext = string.Empty; int TypeId = Convert.ToInt32(ddlMediaTypeList.SelectedValue); MediaTypes media_type_obj = new MediaTypes(); Media_Types type_obj = media_type_obj.GetDetails(TypeId); string TypeExt = type_obj.TypeExt.Trim(); string TypePath = type_obj.TypePath; string dir_path = Server.MapPath("~/" + TypePath); string[] arr_list = GetArray(TypeExt); if (rdlFileUpload.SelectedValue == "0") { HttpPostedFile posted_file = File1.PostedFile; if (posted_file.ContentLength > 0) { file_ext = System.IO.Path.GetExtension(myfile.FileName).ToLower().Trim(); if (Directory.Exists(dir_path)) { for (int i = 0; i < arr_list.Length; i++) { if (file_ext == arr_list[i].ToString()) { FileHandleClass file_obj = new FileHandleClass(); filename = file_obj.uploadInputFile(posted_file, dir_path); } } } } } else { file_ext = System.IO.Path.GetExtension(txtFileUrl.Text).ToLower().Trim(); filename = System.IO.Path.GetFileName(txtFileUrl.Text); for (int i = 0; i < arr_list.Length; i++) { if (file_ext == arr_list[i].ToString()) { fileurl = txtFileUrl.Text; } } } /************************************************************************************************************************/ MediaFiles media_obj = new MediaFiles(); int relust = media_obj.Update(_idx, userid, typeid, topicid, playlistid, albumid, artistid, composerid, filename, fileurl, title, description, autostart, medialoop, dimension, source, photo, thumbnail, status); return relust; }