Exemplo n.º 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if ((String.IsNullOrEmpty(editor1.Text) == false) &&
                (Abstract.Text.Length >= 130) &&
                (FileUpload1.HasFile) &&
                (String.IsNullOrEmpty(title.Text) == false) &&
                (String.IsNullOrEmpty(Abstract.Text) == false) &&
                (String.IsNullOrEmpty(Tags.Text) == false) &&
                (String.IsNullOrEmpty(KeyWords.Text) == false))
            {
                if (FileUpload1.FileBytes.Length > 1024 * 1024)
                {
                    diverror.InnerHtml = "حجم فایل بارگذاری شده بیشتر از 1 مگابایت است!";
                    return;
                }
                string ext = Path.GetExtension(FileUpload1.FileName).ToLower();
                if ((ext != ".jpg") && (ext != ".png"))
                {
                    diverror.InnerHtml = "فرمت فایل بارگذاری شده باید .jpg  یا .png  باشد!";
                    return;
                }

                Article ART = new Article();
                ART.Title   = title.Text;
                ART.Content = editor1.Text;

                string filename = Path.GetFileName(FileUpload1.FileName);
                string rand     = DBManager.CurrentTimeWithoutColons() + DBManager.CurrentPersianDateWithoutSlash();
                filename = rand + filename;
                string ps = Server.MapPath(@"~\img\") + filename;
                FileUpload1.SaveAs(ps);

                FileStream fStream  = File.OpenRead(ps);
                byte[]     contents = new byte[fStream.Length];
                fStream.Read(contents, 0, (int)fStream.Length);
                fStream.Close();

                ART.Image = "/img/" + filename;
                System.Drawing.Image img   = imgResize.ToImage(contents);
                System.Drawing.Image image = imgResize.Resize(img, 358, 358);

                string stream = Server.MapPath(@"~\img\") + "s" + filename;
                switch (FileUpload1.FileName.Substring(FileUpload1.FileName.IndexOf('.') + 1).ToLower())
                {
                case "jpg":
                    image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    break;

                case "jpeg":
                    image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    break;

                case "png":
                    image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                    break;
                }

                ART.ImgFirstPage = "/img/" + "s" + filename;

                ART.Abstract     = Abstract.Text;
                ART.PostDateTime = OnlineTools.persianFormatedDate();
                ART.Visits       = 0;
                ART.Tags         = Tags.Text;
                ART.KeyWords     = KeyWords.Text;
                ArticleRepository ARTRep = new ArticleRepository();
                if (ARTRep.SaveArticle(ART))
                {
                    bool result = true;
                    GroupsConRepository GRConRepo = new GroupsConRepository();

                    int lastid = ARTRep.GetLastArticleID();
                    int count  = SelectedSubGroups.Items.Count;
                    if (count > 0)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            GroupConnection GC = new GroupConnection();
                            GC.ArticleID = lastid;
                            GC.GroupID   = SelectedSubGroups.Items[i].Value.ToInt();
                            if (!GRConRepo.SaveGroupCon(GC))
                            {
                                result = false;
                            }
                        }
                    }
                    else
                    {
                        diverror.InnerText = "هیچ زیر گروهی انتخاب نشده است!";
                    }

                    if (!result)
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('مشکلی در زمان ثبت به وجود آمد،لطفا دوباره سعی کنید یا با پشتیبانی تماس بگیرید ! ');window.location ='/Admin/ManageBlogs'", true);
                    }
                    else
                    {
                        Response.Redirect("/Admin/ManageBlogs");
                    }
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('مشکلی در زمان ثبت به وجود آمد،لطفا دوباره سعی کنید یا با پشتیبانی تماس بگیرید ! ');window.location ='/Admin/ManageBlogs'", true);
                }
            }
        }
Exemplo n.º 2
0
        protected void gvPosts_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            diverror.InnerHtml = "";

            if (e.CommandName == "Edit")
            {
                // Retrieve the row index stored in the
                // CommandArgument property.
                int index = Convert.ToInt32(e.CommandArgument);

                // Retrieve the row that contains the button
                // from the Rows collection.
                GridViewRow row = gvPosts.Rows[index];
                Session.Add("PostIDForEdit", row.Cells[0].Text);

                Response.Redirect("/Admin/EditBlog");
            }
            if (e.CommandName == "Show")
            {
                // Retrieve the row index stored in the
                // CommandArgument property.
                int index = Convert.ToInt32(e.CommandArgument);

                // Retrieve the row that contains the button
                // from the Rows collection.
                GridViewRow row = gvPosts.Rows[index];

                string id = row.Cells[0].Text;

                Response.Redirect("/Blogs/" + id + "/" + row.Cells[1].Text.Replace(' ', '-'));
            }
            if (e.CommandName == "Delet")
            {
                // Retrieve the row index stored in the
                // CommandArgument property.
                int index = Convert.ToInt32(e.CommandArgument);

                // Retrieve the row that contains the button
                // from the Rows collection.
                GridViewRow         row      = gvPosts.Rows[index];
                int                 id       = row.Cells[0].Text.ToInt();
                ArticleRepository   repart   = new ArticleRepository();
                GroupsConRepository repgpCon = new GroupsConRepository();
                string              img      = "";
                string              fimg     = "";

                Article pr = repart.FindeArticleByID(id);
                if (pr != null)
                {
                    img  = pr.Image;
                    fimg = pr.ImgFirstPage;
                }
                if (repgpCon.DeletArticleConnections(id) && repart.DeletArticleByID(id))
                {
                    subgroup();
                    FileInfo fi = new FileInfo(Server.MapPath(@"~\img\") + img.Substring(5));
                    fi.Delete();
                    FileInfo fil = new FileInfo(Server.MapPath(@"~\img\") + fimg.Substring(5));
                    fil.Delete();
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('حذف با موفقیت انجام شد ');", true);
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('حذف با خطا مواجه شد ، بعدا سعی کنید یا با پشتیبانی تماس بگیرید!');", true);
                }
            }
        }
Exemplo n.º 3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!(String.IsNullOrEmpty(editor1.Text) ||
                  String.IsNullOrEmpty(title.Text) ||
                  String.IsNullOrEmpty(Abstract.Text) ||
                  String.IsNullOrEmpty(Tags.Text) ||
                  String.IsNullOrEmpty(KeyWords.Text) || SelectedSubGroups.Items.Count == 0 || Abstract.Text.Count() < 130))
            {
                if (Session["newPostIDForEdit"] != null)
                {
                    int id = Session["newPostIDForEdit"].ToString().ToInt();
                    Session.Remove("newPostIDForEdit");
                    ArticleRepository repArt = new ArticleRepository();
                    GroupsRepository  repo   = new GroupsRepository();
                    Article           art    = repArt.FindeArticleByID(id);

                    art.Title   = title.Text;
                    art.Content = editor1.Text;

                    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('فرمت فایل بارگذاری شده باید .jpg  یا .png  باشد!')", 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);
                        FileStream fStream  = File.OpenRead(ps);
                        byte[]     contents = new byte[fStream.Length];
                        fStream.Read(contents, 0, (int)fStream.Length);
                        fStream.Close();
                        FileInfo fi = new FileInfo(Server.MapPath(@"~\img\") + art.Image.Substring(5));
                        fi.Delete();
                        FileInfo fil = new FileInfo(Server.MapPath(@"~\img\") + art.ImgFirstPage.Substring(5));
                        fil.Delete();
                        art.Image = "/img/" + filename;
                        System.Drawing.Image img   = imgResize.ToImage(contents);
                        System.Drawing.Image image = imgResize.Resize(img, 358, 358);



                        string stream = Server.MapPath(@"~\img\") + "s" + filename;
                        switch (FileUpload1.FileName.Substring(FileUpload1.FileName.IndexOf('.') + 1).ToLower())
                        {
                        case "jpg":
                            image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            break;

                        case "jpeg":
                            image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            break;

                        case "png":
                            image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                            break;
                        }

                        art.ImgFirstPage = "/img/" + "s" + filename;
                    }


                    art.Abstract = Abstract.Text;
                    art.Visits   = 0;
                    art.Tags     = Tags.Text;
                    art.KeyWords = KeyWords.Text;
                    ArticleRepository ARTRep = new ArticleRepository();
                    if (ARTRep.SaveArticle(art))
                    {
                        bool result = true;
                        GroupsConRepository GRConRepo = new GroupsConRepository();
                        GRConRepo.DeletArticleConnections(id);
                        List <int> SelectedSubGroupsList = new List <int>();

                        int lastid = id;
                        int count  = SelectedSubGroups.Items.Count;
                        if (count > 0)
                        {
                            for (int i = 0; i < count; i++)
                            {
                                GroupConnection GC = new GroupConnection();
                                GC.ArticleID = lastid;
                                GC.GroupID   = SelectedSubGroups.Items[i].Value.ToInt();
                                if (!GRConRepo.SaveGroupCon(GC))
                                {
                                    result = false;
                                }
                                else
                                {
                                    Response.Redirect("/Admin/ManageBlogs");
                                }
                            }
                        }
                        else
                        {
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('هیچ زیر گروهی انتخاب نشده است!')", true);
                        }

                        if (!result)
                        {
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('مشکلی در زمان ثبت به وجود آمد،لطفا دوباره سعی کنید یا با پشتیبانی تماس بگیرید ! ');window.location ='/Admin/ManageBlogs'", true);
                        }
                        else
                        {
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('ثبت با موفقیت انجام شد!');window.location ='/Admin/ManageBlogs'", true);
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('مشکلی در زمان ثبت به وجود آمد،لطفا دوباره سعی کنید یا با پشتیبانی تماس بگیرید ! ');window.location ='/Admin/ManageBlogs'", true);
                    }
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(' مشکلی در زمان لود کردن به وجود آمد دوباره سعی کنید ! ');window.location ='/Admin/ManageBlogs'", true);
                }
            }
        }
Exemplo n.º 4
0
        protected void gvGroups_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "EditRow")
            {
                //Retrieve the row index stored in the
                //CommandArgument property.
                int index = Convert.ToInt32(e.CommandArgument);

                // Retrieve the row that contains the button
                // from the Rows collection.
                GridViewRow row = gvGroups.Rows[index];

                IDholder.Text        = row.Cells[0].Text;
                tbxOldName.InnerText = row.Cells[1].Text;

                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.Append(@"<script type='text/javascript'>");
                sb.Append("$('#modalShowGroupDetails').modal('show');");
                sb.Append(@"</script>");
                ScriptManager.RegisterStartupScript(this, this.GetType(),
                                                    "ModalScript", sb.ToString(), false);
            }

            if (e.CommandName == "Delet")
            {
                GroupsConRepository repgpCon = new GroupsConRepository();
                GroupsRepository    repgp    = new GroupsRepository();

                // Retrieve the row index stored in the
                // CommandArgument property.
                int index = Convert.ToInt32(e.CommandArgument);

                // Retrieve the row that contains the button
                // from the Rows collection.
                GridViewRow row    = gvGroups.Rows[index];
                int         id     = row.Cells[0].Text.ToInt();
                List <int>  subIDs = repgp.getSubGroupsIDByFatherID(id).ToList();
                if (repgpCon.DeleteConsBySubGroupIdList(subIDs))
                {
                    if (repgp.DelSubGruop(subIDs))
                    {
                        if (repgp.DelGruop(id))
                        {
                            gvGroups.DataSource = null;
                            gvGroups.DataBind();
                            ddlGroups.DataSource = null;
                            ddlGroups.DataBind();
                            gvSubGroups.DataSource = null;
                            gvSubGroups.DataBind();
                            DataTable allGroups = new DataTable();
                            allGroups = repgp.LoadAllGroups();
                            ddlgroupsForModal.DataSource     = allGroups;
                            ddlgroupsForModal.DataTextField  = "Title";
                            ddlgroupsForModal.DataValueField = "GroupID";
                            ddlgroupsForModal.DataBind();
                            ddlgroupsForModal.Items.Insert(0, new ListItem("یکی از گروه ها را انتخاب کنید", "-2"));
                            gvGroups.DataSource = allGroups;
                            gvGroups.DataBind();
                            ddlGroups.DataSource     = allGroups;
                            ddlGroups.DataTextField  = "Title";
                            ddlGroups.DataValueField = "GroupID";
                            ddlGroups.DataBind();
                            ddlGroups.Items.Insert(0, new ListItem("همه زیر گروه ها", "-2"));
                            gvSubGroups.DataSource = repgp.LoadAllSubGroups();
                            gvSubGroups.DataBind();
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('حذف با موفقیت انجام شد');", true);
                        }
                        else
                        {
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('حذف با خطا مواجه شد ، بعدا سعی کنید یا با پشتیبانی تماس بگیرید!');", true);
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('حذف با خطا مواجه شد ، بعدا سعی کنید یا با پشتیبانی تماس بگیرید!');", true);
                    }
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('حذف با خطا مواجه شد ، بعدا سعی کنید یا با پشتیبانی تماس بگیرید!');", true);
                }
            }
        }