public void DeleteFile(string Orginal_FileName, string upload_dir_path)
 {
     string[] result = new string[2];
     result = getDirectionFromFile(Orginal_FileName);
     string dir_path = upload_dir_path + "/" + result[0];
     string filename = result[1].ToString();            
     if (Directory.Exists(upload_dir_path))
     {
         FileHandleClass file_handle_obj = new FileHandleClass();
         file_handle_obj.deleteFile(filename, upload_dir_path);
     }
 }
 private void DeleteFile(string file_name, string dir_path)
 {            
     if (Directory.Exists(dir_path))
     {
         FileHandleClass file_handle_obj = new FileHandleClass();
         file_handle_obj.deleteFile(file_name, dir_path);
     }
 }
 private bool UpdateData()
 {
     int CollectionId = Convert.ToInt32(ddlCollection.SelectedValue);
     int CollectionFileId = Convert.ToInt32(ViewState["CollectionFileId"].ToString());
     int ListOrder = Convert.ToInt32(ViewState["ListOrder"].ToString());
     DateTime CreatedOnDate = Convert.ToDateTime(ViewState["CreatedOnDate"].ToString());
     string IPLog = ViewState["IPLog"].ToString();
     string UserLog = ViewState["UserLog"].ToString();
     string Description = txtDescription.Text;
     string UserLastUpdate = Session["UserId"].ToString();
     string Status = rdlStatus.SelectedValue;
     string Tags = txtTags.Text;            
     
     string FileName = string.Empty, FileUrl = string.Empty;        
     if (rdlFileUpload.SelectedValue == "0")
     {
         HttpPostedFile posted_file = File1.PostedFile;
         if (posted_file.ContentLength > 0)
         {
             string dir_path = Server.MapPath("~/" + upload_gallery_content_image_dir);
            if (!Directory.Exists(dir_path))
                 Directory.CreateDirectory(dir_path);         
             FileHandleClass file_obj = new FileHandleClass();
             FileName = file_obj.uploadInputFile(posted_file, dir_path);
             if (FileName != string.Empty)
                 DeleteFile(ltrFileName.Text, dir_path);
         }
         else
             ShowMessageBox("Vui lòng chọn File.");
     }
     else{           
         if (txtFileUrl.Text != string.Empty)
             FileUrl = txtFileUrl.Text;
         else
             ShowMessageBox("Vui lòng chọn File.");
     }
     bool i = gallery_obj.UpdateData(_idx, CollectionFileId, CollectionId, FileName, FileUrl,
                             ListOrder, Description, Tags, Status, CreatedOnDate, IPLog, UserLog, UserLastUpdate);           
     return i;
 }
        private bool AddData()
        {
            int CollectionId = Convert.ToInt32(ddlCollection.SelectedValue);
            string Description = txtDescription.Text;
            string User = Session["UserId"].ToString();
            string Status = rdlStatus.SelectedValue;
            string Tags = txtTags.Text;
            string FileName = string.Empty; string FileUrl = string.Empty;

            if (rdlFileUpload.SelectedValue == "0")
            {
                HttpPostedFile posted_file = File1.PostedFile;
                if (posted_file.ContentLength > 0)
                {
                    string dir_path = Server.MapPath("~/" + upload_gallery_content_image_dir);
                    if (!Directory.Exists(dir_path))
                        Directory.CreateDirectory(dir_path);
                    FileHandleClass file_obj = new FileHandleClass();
                    FileName = file_obj.uploadInputFile(posted_file, dir_path);
                }
                else
                    ShowMessageBox("Vui lòng chọn File.");
            }
            else
            {
                if(txtFileUrl.Text !=string.Empty)
                    FileUrl = txtFileUrl.Text;
                else
                    ShowMessageBox("Vui lòng chọn File.");
            }
            
            bool i = gallery_obj.InsertData(CollectionId, FileName, FileUrl, Description, User, Status, Tags);
            return i;
        }
 private void DeleteMainImage(string file_name)
 {
     string _main_dir_img_path = Server.MapPath(main_image_dir);
     if (Directory.Exists(_main_dir_img_path))
     {
         FileHandleClass file_handle_obj = new FileHandleClass();
         file_handle_obj.deleteFile(file_name, _main_dir_img_path);
     }
 }
 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);
     }
 }
        public static int WriteFileRouter(int PortalId, int ContentItemId, string CultureCode, bool Discontinued, string HomeDirectory, string RouterPath, string RouterFile)
        {
            List<aspnet_Routes> lst = RouteController.GetListByPortalIdCultureCodeStatus(PortalId, ContentItemId, CultureCode, Discontinued);

            if (!Directory.Exists(HomeDirectory))
                Directory.CreateDirectory(HomeDirectory);

            if (!Directory.Exists(RouterPath))
                Directory.CreateDirectory(RouterPath);

            string FileRouterPath = Path.Combine(RouterPath, RouterFile);
            if (!System.IO.File.Exists(FileRouterPath))
                System.IO.File.Create(FileRouterPath);

            GC.Collect();
            GC.WaitForPendingFinalizers();

            FileHandleClass file_obj = new FileHandleClass();
            FileInfo fileInfo = new FileInfo(FileRouterPath);
            string n = file_obj.ReadFile(fileInfo.FullName);
            int start = 0; int end = 0;

            if (n.IndexOf("//start") > -1)
                start = n.IndexOf("//start");

            if (n.IndexOf("//end") > -1)
                end = n.IndexOf("//end");

            string content = n.Replace(n.Substring(start + 7, end - start - 7), "\r\n            ");
            file_obj.UpDateFile(fileInfo.FullName, content);
            n = file_obj.ReadFile(fileInfo.FullName);
            string optionparams = string.Empty;
            for (int i = 0; i < lst.Count; i++)
            {
                string RouteName = lst[i].RouteName;
                string RouteUrl = lst[i].RouteUrl;
                string PhysicalFile = lst[i].PhysicalFile;
                bool CheckPhysicalUrlAccess = lst[i].CheckPhysicalUrlAccess;
                string RouteValueDictionary = StringDirectionProcess(lst[i].RouteValueDictionary);
                if (RouteValueDictionary != "")
                    RouteValueDictionary = ", new System.Web.Routing.RouteValueDictionary { " + RouteValueDictionary + " })";
                else
                    RouteValueDictionary = ")";
                string newrow = "routes.MapPageRoute(\"" + RouteName + "\", \"" + RouteUrl + "\", \"" + PhysicalFile + "\"," + CheckPhysicalUrlAccess.ToString().ToLower() + RouteValueDictionary + ";";
                n = n.Replace("//end", newrow + System.Environment.NewLine + "            //end");
                file_obj.UpDateFile(fileInfo.FullName, n);
            }

            return 1;
        }
        private int AddData()
        {
            string user_id = Session["UserId"].ToString();
            string composer_name = txtComposerName.Text;
            string description = txtDescription.Text;
            string status = rdlStatus.SelectedValue;

            /*** 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);

            if (FileUpload1.HasFile)
            {
                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;
            }
            ////========================================================================================================================

            MediaComposers artist_obj = new MediaComposers();
            int i = artist_obj.Insert(user_id, composer_name, front_image, main_image, description, status);
            return i;
        }
 public int Delete(int Document_ID, string document_dir_path)
 {
     string dir_path = HttpContext.Current.Server.MapPath(document_dir_path);
     if (System.IO.Directory.Exists(dir_path))
     {
         string _file = GetFile(Document_ID);
         if (_file != null || _file != string.Empty)
         {
             string file_path = dir_path + "/" + _file;
             if (System.IO.File.Exists(file_path))
             {
                 FileHandleClass file_handle = new FileHandleClass();
                 file_handle.deleteFile(_file, dir_path);
             }
         }
     }
     SqlCommand cmd = new SqlCommand("[Production].[Product_Documents_Delete]", con) { CommandType = CommandType.StoredProcedure, CommandTimeout = Settings.CommandTimeout };
     cmd.Parameters.AddWithValue("@Document_ID", Document_ID);
     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 bool AddData()
        {
            string IconFile=string.Empty;            
            int TopicId = Convert.ToInt32(ddlTreeNode_Topics.SelectedValue);
            string Title = txtTitle.Text;
            string Description = txtDescription.Text;
            string Status = rdlStatus.SelectedValue;
            string Tags = txtTags.Text;
            string Url = txtUrl.Text;
            string UserLog = Session["UserId"].ToString();
            
            HttpPostedFile posted_file = File1.PostedFile;
            if (posted_file.ContentLength > 0)
            {
                string dir_path = Server.MapPath("~/" + upload_gallery_collection_image_dir);
                if (Directory.Exists(dir_path))
                    Directory.CreateDirectory(dir_path);             

                FileHandleClass collection_obj = new FileHandleClass();
                IconFile = collection_obj.uploadInputFile(posted_file, dir_path);              
            }           
            bool i = gallery_collection_obj.InsertData(TopicId, Title, IconFile, Description, Tags, Url, UserLog, Status);
            return i;
        }
        private bool UpdateData()
        {
            string IconFile = string.Empty;
            string dir_path = Server.MapPath("~/" + upload_gallery_collection_image_dir);
            HttpPostedFile posted_file = File1.PostedFile;
            if (posted_file.ContentLength > 0)
            {
                if (!Directory.Exists(dir_path))
                    Directory.CreateDirectory(dir_path);    
                FileHandleClass collection_obj = new FileHandleClass();
                IconFile = collection_obj.uploadInputFile(posted_file, dir_path);               
                DeleteFile(ltrFileName.Text, dir_path);                
            }
            else
                IconFile = ltrFileName.Text;
            int TopicId = Convert.ToInt32(ddlTreeNode_Topics.SelectedValue);
            string Title = txtTitle.Text;            
            string Status = rdlStatus.SelectedValue;
            string Tags = txtTags.Text;
            string Url = txtUrl.Text;
            string UserLastUpdate = Session["UserId"].ToString();
            string Description = txtDescription.Text;
            int ListOrder = Convert.ToInt32(ViewState["ListOrder"].ToString());
            string IPLog = ViewState["IPLog"].ToString();
            DateTime CreatedOnDate = Convert.ToDateTime(ViewState["CreatedOnDate"].ToString());
            string UserLog = ViewState["UserLog"].ToString();

            bool i = gallery_collection_obj.UpdateData(_idx, TopicId, Title, IconFile, Description, ListOrder, Tags, Url,
                                                    UserLog, UserLastUpdate, CreatedOnDate, IPLog, Status);
            return i;
        }
        private int AddData()
        {
            string culturecode = ddlCultureList.SelectedValue;
            int vendorid = Convert.ToInt32(VendorId);
            int height = Convert.ToInt32(txtHeight.Text);
            int width = Convert.ToInt32(txtWidth.Text);
            string title = txtTitle.Text;
            string url = txtUrl.Text;
            int position =Convert.ToInt32(ddlPosition.SelectedValue);
            string description = txtDescription.Text;
            string tags = txtTags.Text;
           
            /*** UPLOAD ****************************************************************************************************************************************/
            string thumb_image = "", main_image = "";
            HttpPostedFile myfile = FileInput.PostedFile;
            if (myfile.FileName != string.Empty)
            {
                string front_img_path = Server.MapPath(thumb_banner_dir_path);
                string main_img_path = Server.MapPath(main_banner_dir_path);

                if (!Directory.Exists(banner_dir_path))
                    Directory.CreateDirectory(banner_dir_path);

                if (!Directory.Exists(front_img_path))
                    Directory.CreateDirectory(front_img_path);

                if (!Directory.Exists(main_img_path))
                    Directory.CreateDirectory(main_img_path);

                FileHandleClass file_handle_obj = new FileHandleClass();
                string[] FileImg = new String[2];
                FileImg = file_handle_obj.uploadFrontMainInputFile(myfile, front_img_path, main_img_path, 120, 120);
                main_image = FileImg[0].ToString();
                thumb_image = FileImg[1].ToString();
            }
            /*************************************************************************************************************************************************/

            #region xu ly thoi gian  ====================================================================================
            System.Globalization.DateTimeFormatInfo MyDateTimeFormatInfo = new System.Globalization.DateTimeFormatInfo();
            MyDateTimeFormatInfo.ShortDatePattern = "dd/MM/yyyy";

            string start_date = null, end_date = null;
            if (txtStartDate.Text != string.Empty)
            {
                DateTime _start_date = DateTime.Parse(txtStartDate.Text, MyDateTimeFormatInfo);
                start_date = _start_date.ToString("yyyy-MM-dd");
            }
            if (txtEndDate.Text != string.Empty)
            {
                DateTime _end_date = DateTime.Parse(txtEndDate.Text, MyDateTimeFormatInfo);
                end_date = _end_date.ToString("yyyy-MM-dd");
            }
            if (txtStartDate.Text != string.Empty && txtEndDate.Text != string.Empty)
            {
                DateTime _start_date = DateTime.Parse(txtStartDate.Text, MyDateTimeFormatInfo);
                DateTime _end_date = DateTime.Parse(txtEndDate.Text, MyDateTimeFormatInfo);

                if (DateTime.Compare(_start_date, _end_date) > 0)
                {
                    string scriptCode = "<script>alert('Thời điểm bắt đầu phải nhỏ hơn thời điểm kết thúc');</script>";
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "scriptName", scriptCode);
                }
            }
            #endregion ================================================================================================

            bool bStatus = ChkBoxStatus.Checked;
            string status = string.Empty;
            if (bStatus == true)           
                status = "1";           
            else           
                status = "0";
            
            BannerController banner_obj = new BannerController();
            int i = banner_obj.Insert(vendorid, culturecode, title, main_image, thumb_image, url, position, description, tags, width, height, start_date, end_date, status);
            return i;            
        }
        private int UpdateData()
        {
            string UserId = Session["UserId"].ToString();
            int TypeId = Convert.ToInt32(ddlMediaTypeList.SelectedValue);
            string TopicName = txtTopicName.Text;
            string Description = txtDescription.Text;
            string Status = rdlStatus.SelectedValue;
            int ParentId = Convert.ToInt32(ddlMediaTopicList.SelectedValue);

            /*** UPLOAD ************************************************************************************************************/
            string[] FileImg = new String[2];
            string Photo = string.Empty;
            string front_path = Server.MapPath(upload_front_image_dir);
            string orginal_filename = ViewState["Photo"].ToString();
            HttpPostedFile myfile = myFile.PostedFile;
            if (myfile.ContentLength > 0)
            {
                if (System.IO.Directory.Exists(front_path))
                {
                    FileHandleClass file_obj = new FileHandleClass();
                    Photo = file_obj.uploadFixedInputFile(myfile, front_path, 120, 120);
                    file_obj.deleteFile(orginal_filename, front_path);
                }
                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();
            }
            ////========================================================================================================================

            MediaTopics media_topic_obj = new MediaTopics();            
            int i = media_topic_obj.Update(UserId,TypeId, _idx, ParentId, TopicName, Photo, Description, Status);
            return i;
        }
        private int AddData()
        {
            string UserId = Session["UserId"].ToString();
            int TypeId = Convert.ToInt32(ddlMediaTypeList.SelectedValue);
            string Description = txtDescription.Text;
            string TopicName = txtTopicName.Text;
            string Status = rdlStatus.SelectedValue;
            int ParentId = Convert.ToInt32(ddlMediaTopicList.SelectedValue);

            /*** UPLOAD ************************************************************************************************************/
            string[] FileImg = new String[2];
            string Photo = string.Empty;
            string front_path = Server.MapPath(upload_front_image_dir);
            HttpPostedFile myfile = myFile.PostedFile;
            if (myfile.ContentLength > 0)
            {
                if (!System.IO.Directory.Exists(front_path))
                    System.IO.Directory.CreateDirectory(front_path);

                FileHandleClass file_obj = new FileHandleClass();
                Photo = file_obj.uploadFixedInputFile(myfile, front_path, 120, 120);
            }
            ////========================================================================================================================

            MediaTopics media_topic_obj = new MediaTopics();
            int i = media_topic_obj.Insert(UserId,TypeId, ParentId, TopicName, Photo, Description, Status);
            return i;
        }
        public int Delete(string userid, int idx, string front_dir_path, string main_dir_path)
        {
            string MainImage = string.Empty, ThumbImage = string.Empty;
            string[] array_list = new string[2];
            array_list = GetFrontMainImages(idx);
            MainImage = array_list[0];
            ThumbImage = array_list[1];
            FileHandleClass file_obj = new FileHandleClass();
            if (ThumbImage != string.Empty)
                file_obj.deleteFile(ThumbImage, front_dir_path);
            if (MainImage != string.Empty)
                file_obj.deleteFile(MainImage, main_dir_path);


            SqlCommand cmd = new SqlCommand("[Articles].[sp_Articles_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 AddData()
        {
            string userid = Session["UserId"].ToString();
            int portalid = Convert.ToInt32(ddlPortalList.SelectedValue);
            string culturecode = ddlCultureList.SelectedValue;
            string code = ddlTreeNode_Category.SelectedValue;
            string title = txtTitle.Text;
            string headline = txtHeadline.Text;
            string abstract_info = txtAbstract.Text;
            string contents = FCKeditorContent.Value;
            string source = txtSource.Text;
            string status = rdlStatus.SelectedValue;
            string navigateurl = txtNavigateUrl.Text;
            /*** UPLOAD ****************************************************************************************************************************************/
            string front_img = "", main_img = "";
            HttpPostedFile myfile = FileInput.PostedFile;
            if (myfile.FileName != string.Empty)
            {
                string front_img_path = Server.MapPath("~/" + System.Configuration.ConfigurationManager.AppSettings["upload_image_dir"] + "/article_images/front_images");
                string main_img_path = Server.MapPath("~/" + System.Configuration.ConfigurationManager.AppSettings["upload_image_dir"] + "/article_images/main_images");

                FileHandleClass file_handle_obj = new FileHandleClass();
                string[] FileImg = new String[2];
                FileImg = file_handle_obj.uploadFrontMainInputFile(myfile, front_img_path, main_img_path, 120, 120);
                main_img = FileImg[0].ToString();
                front_img = FileImg[1].ToString();
            }
            /*************************************************************************************************************************************************/
            ArticleController article_obj = new ArticleController();
            int i = article_obj.Insert(userid, portalid, culturecode, code, title, headline, abstract_info, front_img, main_img, contents, source, navigateurl, status);
            return i;
        }
        private int UpdateData()
        {
            string ApplicationId = ddlApplicationList.SelectedValue;
            string PortalName = txtPortalName.Text;           
            string Currency = ddlCurrencyTypeList.SelectedValue;
            string HostFee = txtHostFee.Text;
            int HostSpace = Convert.ToInt32(txtHostSpace.Text);          
            string DefaultLanguage = ddlLanguageList.Text;
            string HomeDirectory = txtHomeDirectory.Text;
            string Url = txtUrl.Text;
            string KeyWords = txtKeyWords.Text;
            string FooterText = txtFooterText.Text;
            string Description = txtDescription.Text;
            string LastModifiedByUserId = Session["UserId"].ToString(); ;

            #region UPLOAD ************************************************************************************************************/            
            string logo_dir_path = HttpContext.Current.Server.MapPath("~/" + System.Configuration.ConfigurationManager.AppSettings["upload_image_dir"] + "/portal_images/logo");
            string background_dir_path = HttpContext.Current.Server.MapPath("~/" + System.Configuration.ConfigurationManager.AppSettings["upload_image_dir"] + "/portal_images/backgrounds");
            string LogoFile = string.Empty; string BackgroundFile = string.Empty;            
            FileHandleClass file_handle_obj = new FileHandleClass();

            HttpPostedFile _logo_file = InputLogoFile.PostedFile;
            if (_logo_file.ContentLength > 0)
            {
                string logo_file_path = logo_dir_path + "/" + HiddenLogoFile.Value;
                if (File.Exists(logo_file_path))
                {
                    File.Delete(logo_file_path);
                }
                LogoFile = file_handle_obj.uploadInputFile(_logo_file, logo_dir_path);
            }
            else
            {
                LogoFile = HiddenLogoFile.Value;
            }

            HttpPostedFile _background_file = InputBackgroundFile.PostedFile;
            if (_background_file.ContentLength > 0)
            {
                string background_file_path = background_dir_path + "/" + HiddenLogoFile.Value;
                if (File.Exists(background_file_path))
                {
                    File.Delete(background_file_path);
                }
                BackgroundFile = file_handle_obj.uploadInputFile(_background_file, background_dir_path);
            }
            else
            {
                BackgroundFile = HiddenBackgroundFile.Value;
            }
            #endregion ================================================================================

            #region xu ly thoi gian  =====================================================================================
            System.Globalization.DateTimeFormatInfo MyDateTimeFormatInfo = new System.Globalization.DateTimeFormatInfo();
            MyDateTimeFormatInfo.ShortDatePattern = "dd/MM/yyyy";
            string ExpiryDate = null;

            if (txtExpiryDate.Text != string.Empty)
            {
                DateTime _ExpiryDate = DateTime.Parse(txtExpiryDate.Text, MyDateTimeFormatInfo);
                ExpiryDate = _ExpiryDate.ToString("yyyy-MM-dd");
            }
            #endregion ====================================================================================================

            PortalController portal_obj = new PortalController();
            int i = portal_obj.Update(_idx, ApplicationId, PortalName, ExpiryDate, Currency, HostFee, HostSpace, DefaultLanguage,
                 HomeDirectory, Url, LogoFile, BackgroundFile, KeyWords, FooterText, Description, LastModifiedByUserId);
            return i;
        }
        protected int UpdateData()
        {
            string userid = Session["UserId"].ToString();
            int portalid = Convert.ToInt32(ddlPortalList.SelectedValue);
            string culturecode = ddlCultureList.SelectedValue;
            string code = ddlTreeNode_Category.SelectedValue;
            string title = txtTitle.Text;
            string headline = txtHeadline.Text;
            string abstract_info = txtAbstract.Text;
            string contents = FCKeditorContent.Value;
            string source = txtSource.Text;
            string status = rdlStatus.SelectedValue;
            string navigateurl = txtNavigateUrl.Text;
            /*** UPLOAD ****************************************************************************************************************************************/
            string front_img = "", main_img = "";
            HttpPostedFile myfile = FileInput.PostedFile;
            if (myfile.FileName != string.Empty)
            {
                string front_img_path = Server.MapPath(upload_front_image_dir);
                string main_img_path = Server.MapPath(upload_main_image_dir);

                FileHandleClass file_handle_obj = new FileHandleClass();
                string[] FileImg = new String[2];
                FileImg = file_handle_obj.uploadFrontMainInputFile(myfile, front_img_path, main_img_path, 120, 120);
                main_img = FileImg[0].ToString();
                front_img = FileImg[1].ToString();
                front_Img.ImageUrl = upload_front_image_dir + "/" + front_img;

                string Orginal_front_image = ViewState["FrontImage"].ToString();
                string Orginal_main_image = ViewState["MainImage"].ToString();
                file_handle_obj.DeleteFile(Orginal_front_image, front_img_path);
                file_handle_obj.DeleteFile(Orginal_main_image, main_img_path);
            }
            else
            {
                main_img = ViewState["MainImage"].ToString();
                front_img = ViewState["FrontImage"].ToString();
            }
            /*************************************************************************************************************************************************/

            int i = article_obj.Update(userid, portalid, culturecode, _idx, code, title, headline, abstract_info, front_img, main_img, contents, source, navigateurl, status);

            return i;
        }
        private int UpdateData()
        {
            string user_id = Session["UserId"].ToString();
            string composer_name = txtComposerName.Text;
            string description = txtDescription.Text;
            string status = rdlStatus.SelectedValue;

            /*** 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["FrontImage"].ToString();
            string Orginal_main_image = ViewState["MainImage"].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;
                string folderchild = Orginal_front_image.Substring(0, 10);
                DeleteFrontImage(Orginal_front_image);
                DeleteMainImage(Orginal_main_image);
            }
            else
            {
                front_image = Orginal_front_image;
                main_image = Orginal_main_image;
            }
            ////========================================================================================================================


            MediaComposers artist_obj = new MediaComposers();
            int i = artist_obj.Update(_idx, user_id, composer_name, front_image, main_image, description, status);
            return i;
        }
        private int AddData()
        {        
            int parentid = Convert.ToInt32(lstTreeNode.SelectedValue);
            int portalid = Convert.ToInt32(ddlPortalList.SelectedValue);
            string culturecode = ddlCultureList.SelectedValue;
            string code = txtCode.Text;
            string cate_name = txtName.Text;
            string description = txtDescription.Text;            
            string status = rdlStatus.SelectedValue;           

            /*** UPLOAD ****************************************************************************************************************************************/
            HttpPostedFile myfile = FileInput.PostedFile;   
            string file_name = null;
            if (myfile != null)
            {
                if (myfile.ContentLength > 0)
                {
                    string dir_img_path = Server.MapPath("~/" + System.Configuration.ConfigurationManager.AppSettings["upload_image_dir"] + "/article_category_images");
                    FileHandleClass file_handle_obj = new FileHandleClass();
                    file_name = file_handle_obj.uploadInputFile(myfile, dir_img_path);
                }
            }
            /***************************************************************************************************************************************************/

            string userid = Session["UserId"].ToString();
            int i = category_obj.Insert(userid, portalid, culturecode, parentid, code, cate_name, file_name, description, status);
            return i;
        }
        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;
        }
        protected int UpdateData()
        {         
            string strParentID = null;
            if (lstTreeNode.SelectedValue == _idx.ToString())
            {
                strParentID = ViewState["parentid"].ToString();
            }
            else
            {
                strParentID = lstTreeNode.SelectedValue;
            }
            int parentid = Convert.ToInt32(strParentID);
            int portalid = Convert.ToInt32(ddlPortalList.SelectedValue);
            string culturecode = ddlCultureList.SelectedValue;
            string code = txtCode.Text;
            string name = txtName.Text;
            string description = txtDescription.Text;
            string status = rdlStatus.SelectedValue;             

            HttpPostedFile myfile = FileInput.PostedFile;
            string file_name = null;
            if (myfile.FileName != string.Empty)
            {
                string dir_img_path = Server.MapPath("~/" + System.Configuration.ConfigurationManager.AppSettings["upload_image_dir"] + "/article_category_images");
                FileHandleClass file_handle_obj = new FileHandleClass();
                file_name = file_handle_obj.uploadInputFile(myfile, dir_img_path);
            }
            else
            {
                file_name = ViewState["image"].ToString();
            }
            string userid = Session["UserId"].ToString();
            int i = category_obj.Update(userid, portalid, culturecode, _idx, parentid, code, name, file_name, description, status);            
            return i;
        }
 private void DeleteMainImage(string Orginal_main_image)
 {
     string[] result = new string[2];
     result = getDirectionFromFile(Orginal_main_image);
     string main_image = upload_main_image_dir + "/" + result[0];
     string filename = result[1].ToString();
     string _main_dir_img_path = Server.MapPath(main_image);
     if (Directory.Exists(_main_dir_img_path))
     {
         FileHandleClass file_handle_obj = new FileHandleClass();
         file_handle_obj.deleteFile(filename, _main_dir_img_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 = 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;
        }