protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["adminid"] != null)
            {
                if (!IsPostBack)
                {
                    string id = this.Page.RouteData.Values["id"].ToString();
                    if (!String.IsNullOrEmpty(id))
                    {
                        SliderRepository repSr = new SliderRepository();

                        Slider oldSlider = repSr.FindSlider(id.ToInt());
                        oldBimg.Src = oldSlider.BackgroundImg;
                        if (oldSlider.thumbnail != null)
                        {
                            Rimg.InnerHtml = "<img src='" + oldSlider.thumbnail + "' class='img-responsive'/>";
                        }
                        else
                        {
                            Rimg.InnerHtml = "عکسی وجود نداشته !";
                        }
                        text.Text    = oldSlider.Text;
                        tbxLink.Text = oldSlider.Link;
                    }
                    else
                    {
                        Response.Redirect("/Admin/ManageFirstPage");
                    }
                }
            }
            else
            {
                Response.Redirect("/AdminLogin");
            }
        }
Example #2
0
        private void LoadSliders()
        {
            SliderRepository repSlider = new SliderRepository();
            Slider           slide1    = repSlider.FindSlider(1);
            Slider           slide2    = repSlider.FindSlider(2);
            Slider           slide3    = repSlider.FindSlider(3);

            bImg1.Src = slide1.BackgroundImg;
            bImg2.Src = slide2.BackgroundImg;
            bImg3.Src = slide3.BackgroundImg;

            divText1.InnerHtml = slide1.Text;
            divText2.InnerHtml = slide2.Text;
            divText3.InnerHtml = slide3.Text;

            if (slide1.thumbnail != null)
            {
                rightPic.InnerHtml = "<img src='" + slide1.thumbnail + "' alt='عکس'/>";
            }
            if (slide2.thumbnail != null)
            {
                rightPic2.InnerHtml = "<img src='" + slide2.thumbnail + "' alt='عکس'/>";
            }
            if (slide3.thumbnail != null)
            {
                rightPic3.InnerHtml = "<img src='" + slide3.thumbnail + "' alt='عکس'/>";
            }

            if (slide1.Link != null)
            {
                diva1.InnerHtml = "<a type='button' href='" + slide1.Link + "' class='btn btn-default'>بیشتر بدانید</a>";
            }
            if (slide2.Link != null)
            {
                diva2.InnerHtml = "<a type='button' href='" + slide2.Link + "' class='btn btn-default'>بیشتر بدانید</a>";
            }
            if (slide3.Link != null)
            {
                diva3.InnerHtml = "<a type='button' href='" + slide3.Link + "' class='btn btn-default'>بیشتر بدانید</a>";
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string id = this.Page.RouteData.Values["id"].ToString();

            if (!String.IsNullOrEmpty(id))
            {
                SliderRepository repSlider = new SliderRepository();
                Slider           slider    = repSlider.FindSlider(id.ToInt());

                //slider.SlideID = id.ToInt();
                if (FileUpload1.HasFile)
                {
                    if (FileUpload1.FileBytes.Length > 1024 * 1024)
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(' حجم عکس بیشتر از 1 مگابایت است ! ');", true);

                        return;
                    }
                    string ext = Path.GetExtension(FileUpload1.FileName).ToLower();
                    if ((ext != ".jpg") && (ext != ".png"))
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(' فرمت png یا jpg kdsj ! ');", true);

                        return;
                    }
                    string filename = Path.GetFileName(FileUpload1.FileName);
                    string rand     = DBManager.CurrentTimeWithoutColons() + DBManager.CurrentPersianDateWithoutSlash();
                    filename = rand + filename;
                    string ps = Server.MapPath(@"~\img\") + filename;
                    FileUpload1.SaveAs(ps);
                    FileInfo fi = new FileInfo(Server.MapPath(@"~\img\") + slider.BackgroundImg.Substring(5));
                    fi.Delete();
                    slider.BackgroundImg = "/img/" + filename;
                }

                if (FileUpload2.HasFile)
                {
                    if (FileUpload2.FileBytes.Length > 1024 * 1024)
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(' حجم عکس بیشتر از 1 مگابایت است ! ');", true);

                        return;
                    }
                    string ext = Path.GetExtension(FileUpload2.FileName).ToLower();
                    if ((ext != ".jpg") && (ext != ".png"))
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(' فرمت png یا jpg kdsj ! ');", true);

                        return;
                    }
                    string filename = Path.GetFileName(FileUpload2.FileName);
                    string rand     = DBManager.CurrentTimeWithoutColons() + DBManager.CurrentPersianDateWithoutSlash();
                    filename = rand + filename;
                    string ps = Server.MapPath(@"~\img\") + filename;
                    FileUpload2.SaveAs(ps);
                    FileInfo fi = new FileInfo(slider.thumbnail);
                    fi.Delete();
                    slider.thumbnail = "/img/" + filename;
                }
                if (CheckBox1.Checked == true)
                {
                    slider.thumbnail = null;
                }

                if (tbxLink.Text != "")
                {
                    slider.Link = tbxLink.Text;
                }
                else
                {
                    slider.Link = null;
                }
                if (text.Text != "")
                {
                    slider.Text = text.Text;
                }
                else
                {
                    slider.Text = "";
                }

                if (repSlider.SaveSlider(slider))
                {
                    Response.Redirect("/Admin/ManageFirstPage");
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert' ثبت تغییرات با خطا مواجه شد !  ');", true);
                }
            }
        }