Example #1
0
        private void UploadMediaObject(string fileName, string type, string title, string obj_value)
        {
            // Copy file sang thu muc Media Object
            fileName = fileName.Replace("/", "\\");
            if (fileName.StartsWith("\\"))
            {
                fileName = fileName.Substring(1);
            }

            if (fileName.ToLower().IndexOf("common") == 0 || fileName.ToLower().IndexOf(HttpContext.Current.User.Identity.Name.ToLower()) == 0)
            {
                int    pos  = fileName.LastIndexOf(@"\");
                string name = "";

                if (pos > 0)
                {
                    name = fileName.Substring(pos + 1);
                }
                else
                {
                    name = fileName;
                }

                string destinationFile = Server.MapPath("~/Images2018/Uploaded/Share");
                if (type == "1")
                {
                    destinationFile += "/Media/Picture/" + name;
                }
                else
                {
                    destinationFile += "/Media/Video/" + name;
                }

                if (!Directory.Exists(Server.MapPath("~/Images2018/Uploaded/Share") + @"/Media/Picture/"))
                {
                    Directory.CreateDirectory(Server.MapPath("~/Images2018/Uploaded/Share") + "/Media/Picture/");
                }

                string sourceFile = Server.MapPath("~/Images/Uploaded") + "/" + fileName;

                if (File.Exists(sourceFile) && !File.Exists(destinationFile))
                {
                    File.Copy(sourceFile, destinationFile);
                }

                destinationFile = destinationFile.Replace("\\", "/");

                fileName = destinationFile.Substring(destinationFile.IndexOf("Share/"));

                // Insert vao DB
                objNewsMediaSource.InsertParameters[0].DefaultValue           = fileName;
                objNewsMediaSource.InsertParameters[1].DefaultValue           = type;
                objNewsMediaSource.InsertParameters[2].DefaultValue           = title;
                objNewsMediaSource.InsertParameters[3].DefaultValue           = ChannelUsers.GetUserName();
                objNewsMediaSource.InsertParameters["obj_value"].DefaultValue = obj_value;
                objNewsMediaSource.Insert();

                isCapNhap = "ok";
            }
        }
Example #2
0
        private void ShowSelectedMedia()
        {
            string strNewsId  = Request.QueryString["newsid"] != null ? Request.QueryString["newsid"] : "";
            string str_FilmId = Request.QueryString["pid"] != null ? Request.QueryString["pid"].ToString().Trim() : "";
            string str_Type   = Request.QueryString["type"] != null ? Request.QueryString["type"].ToString().Trim() : "";
            string strWhere   = "";

            if (str_Type.ToLower() == "ShowAll".ToLower())
            {
                strWhere = " AND 1=1";
                //lnkAddMedia.Visible = false;
                //ltrAddMedia.Visible = false;
            }
            else if (strNewsId.Trim() != "")
            {
                string strObject_Id = NewsMediaHelper.Get_ObjectId_By_NewsId(Convert.ToInt64(strNewsId));
                if (strObject_Id.Trim() != "")
                {
                    strWhere = " AND News_Media.Object_ID IN (" + strObject_Id + ")";
                }

                ShowGridCol(5);
            }
            else if (str_FilmId.Trim() != "")
            {
                string strObject_Id = NewsMediaHelper.Get_ObjectId_By_FilmId(str_FilmId);
                if (strObject_Id.Trim() != "")
                {
                    strWhere = " AND News_Media.Object_ID IN (" + strObject_Id + ")";
                }

                ShowGridCol(5);
            }
            else if (Session["Object_Id"] != null && Session["Object_Id"].ToString() != "")
            {
                // Neu Tao Bai viet moi hay tao film moi
                strWhere = " AND News_Media.Object_ID IN (" + Session["Object_Id"].ToString().Substring(1) + ")";
            }
            else
            {
                // Neu Tao moi Film va News Thi khong hien thi Media nao ca
                strWhere = " And News_Media.Object_ID = -2 ";
            }

            if (strWhere.Trim() != "")
            {
                objNewsMediaSource.SelectParameters[0].DefaultValue = "UserID='" + ChannelUsers.GetUserName() + "'" + strWhere;
            }
            else
            {
                objNewsMediaSource.SelectParameters[0].DefaultValue = "UserID='" + ChannelUsers.GetUserName() + "'" + " AND News_Media.Object_ID = -1 ";
            }
        }
        private void WriteCookie(string path)
        {
            HttpCookie myCookie = new HttpCookie("fl");
            DateTime   now      = DateTime.Now;

            string userName = ChannelUsers.GetUserName();

            if (path.Contains(userName))
            {
                path = path.Substring(path.IndexOf(userName) + userName.Length);
            }
            else
            {
                path = "Common";
            }

            // Set the cookie value.
            myCookie.Value = Crypto.EncryptForHTML(path);
            // Set the cookie expiration date.
            myCookie.Expires = now.AddMonths(1);

            // Add the cookie.
            Response.Cookies.Add(myCookie);
        }
Example #4
0
 protected void lnkShowAllMedia_Click(object sender, EventArgs e)
 {
     objNewsMediaSource.SelectParameters[0].DefaultValue = "UserID='" + ChannelUsers.GetUserName() + "' ";
 }
Example #5
0
        protected void grdMedia_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.ToLower() == "NewMediaObject".ToLower())
            {
                GridViewRow grdrow = this.grdMedia.FooterRow;
                if (grdrow != null)
                {
                    TextBox      txtINote = grdrow.FindControl("txtINote") as TextBox;
                    DropDownList cboType  = grdrow.FindControl("cboIType") as DropDownList;
                    FileUpload   flObject = grdrow.FindControl("flObject") as FileUpload;
                    if (cboType != null)
                    {
                        if (flObject.FileName != "")
                        {
                            objNewsMediaSource.InsertParameters[0].DefaultValue = flObject.FileName;
                            objNewsMediaSource.InsertParameters[1].DefaultValue = cboType.SelectedValue;
                            objNewsMediaSource.InsertParameters[2].DefaultValue = txtINote.Text;
                            objNewsMediaSource.InsertParameters[3].DefaultValue = ChannelUsers.GetUserName();
                            objNewsMediaSource.Insert();
                            //thuc hien upload anh vao thu muc Share

                            if (DFISYS.FileHelper.isFileMediaObject(flObject.FileName))
                            {
                                //duong dan den thu muc upload1
                                string strFolder = "Images2018/Uploaded/";
                                string strType   = "Picture";
                                if (cboType.SelectedValue != "1")
                                {
                                    strType = "Video";
                                }
                                string strFileUploaded = DFISYS.FileHelper.UploadMediaObject(strFolder, "Share/Media/" + strType, flObject.PostedFile, 125);
                            }
                        }

                        //ShowSelectedMedia();
                        //grdMedia.DataBind();
                    }
                }
            }

            if (e.CommandName.ToLower() == "DeleteMedia".ToLower())
            {
                string str_MediaId = e.CommandArgument.ToString().Trim();
                string str_Newsid  = Request.QueryString["newsid"] != null ? Request.QueryString["newsid"].ToString().Trim() : "";
                string str_FilmId  = Request.QueryString["filmid"] != null ? Request.QueryString["filmid"].ToString().Trim() : "";

                /*
                 * if (str_Newsid.Trim() != "")
                 * {
                 *  NewsMediaHelper.Delete_News_Media_ByNewsIdAndObjectId(Convert.ToInt64(str_Newsid), str_MediaId);
                 *
                 * }
                 * else
                 * if (str_FilmId.Trim() != "")
                 * {
                 *  NewsMediaHelper.DeleteNews_Media_Film_Object_By_FilmIdAndObjectId(Convert.ToInt32(str_FilmId), Convert.ToInt32(str_MediaId));
                 *
                 *
                 * }
                 */

                if (NewsMediaHelper.Check_Exist_News_Media_ByObjectId(str_MediaId))
                {
                    Page.RegisterClientScriptBlock("CannotDeleteImage", "<script language='javascript'>alert('Có một số image bạn không thể xóa được !');</script>");
                }
                else
                {
                    // Neu khong dc su dung thi co the xoa di duoc
                    objNewsMediaSource.DeleteParameters[0].DefaultValue = str_MediaId;
                    objNewsMediaSource.Delete();
                }

                grdMedia.DataBind();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string userName = ChannelUsers.GetUserName();

                if (!string.IsNullOrEmpty(userName))
                {
                    string toDayFolder = userName + string.Format("{0:/yyyy/MM}", DateTime.Now);

                    if (!Directory.Exists(Server.MapPath("~/Images2018/Uploaded/" + toDayFolder)))
                    {
                        Directory.CreateDirectory(Server.MapPath("~/Images2018/Uploaded/" + toDayFolder));
                    }

                    if (!Directory.Exists(Server.MapPath("~/Images2018/Uploaded/Common")))
                    {
                        Directory.CreateDirectory(Server.MapPath("~/Images2018/Uploaded/Common"));
                    }

                    // bind treeview
                    ltrFolder.Text  = getFolder();
                    ltrFolder.Text += getFolder(Server.MapPath("~/Images2018/Uploaded/Common"));//string.Format("<li>{0}</li>", buildNode("Common", "Common"));

                    // bind gridview
                    string    startup = string.Empty;
                    DataTable tbl     = null;
                    if (Request.QueryString["fl"] != null)
                    {
                        try
                        {
                            startup = Crypto.DecryptFromHTML(Request.QueryString["fl"]);
                            if (startup.ToLower().Equals("common"))
                            {
                                tbl = getTableData(Request.QueryString["fl"], string.Empty, 0);
                            }
                            else if (Directory.Exists(Server.MapPath("~/Images2018/Uploaded/" + userName + startup)))
                            {
                                tbl = getTableData(Crypto.EncryptForHTML(userName + startup), string.Empty, 0);
                            }
                        }
                        catch
                        {
                            tbl = getTableData(Crypto.EncryptForHTML(toDayFolder), string.Empty, 0);
                        }
                    }
                    else if (Request.Cookies["fl"] != null)
                    {
                        try
                        {
                            startup = Crypto.DecryptFromHTML(Request.Cookies["fl"].Value);
                            if (startup.ToLower().Equals("common"))
                            {
                                tbl = getTableData(Request.Cookies["fl"].Value, string.Empty, 0);
                            }
                            else if (Directory.Exists(Server.MapPath("~/Images2018/Uploaded/" + userName + startup)))
                            {
                                tbl = getTableData(Crypto.EncryptForHTML(userName + startup), string.Empty, 0);
                            }
                        }
                        catch
                        {
                            tbl = getTableData(Crypto.EncryptForHTML(toDayFolder), string.Empty, 0);
                        }
                    }
                    else
                    {
                        tbl = getTableData(Crypto.EncryptForHTML(toDayFolder), string.Empty, 0);
                    }


                    Repeater1.DataSource = tbl;
                    Repeater1.DataBind();
                }
            }
        }
        private string getFolder()
        {
            string userName = ChannelUsers.GetUserName();

            return(getFolder(Server.MapPath("~/Images2018/Uploaded/" + userName)));
        }