コード例 #1
0
        private void fillGrid()
        {
            ArticleRepository artRep = new ArticleRepository();

            gvPosts.DataSource = artRep.AllArticles();
            gvPosts.DataBind();
        }
コード例 #2
0
ファイル: Blogs.aspx.cs プロジェクト: sasan0512/construction
        protected void ddlGroups_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlGroups.SelectedValue != "-2")
            {
                GroupsRepository Groupsrepo = new GroupsRepository();
                DataTable        DT         = new DataTable();
                DT = Groupsrepo.LoadSubGroup(ddlGroups.SelectedValue.ToInt());

                if ((DT.Rows.Count > 0))
                {
                    ddlSubGroups.Enabled = true;

                    ddlSubGroups.DataSource     = DT;
                    ddlSubGroups.DataTextField  = "Title";
                    ddlSubGroups.DataValueField = "GroupID";
                    ddlSubGroups.DataBind();
                    ddlSubGroups.Items.Insert(0, new ListItem("همه زیر گروه ها", "-2"));
                }
                else
                {
                    ddlSubGroups.Enabled = false;
                    ddlSubGroups.Items.Clear();
                    ddlSubGroups.Items.Insert(0, new ListItem("گروه : " + ddlGroups.SelectedItem.ToString(), ddlGroups.SelectedValue.ToString()));
                }
                //load posts
                List <int>        subgroupsid = Groupsrepo.getSubGroupsIDByFatherID(ddlGroups.SelectedValue.ToInt());
                ArticleRepository artrep      = new ArticleRepository();
                List <Article>    articles    = artrep.ReturnArticlesByCategory(subgroupsid);
                if (articles.Count != 0)
                {
                    fillUl(articles);
                }
                else
                {
                    UlArticles.InnerHtml       = " <li class='danger'>در این بخش مقاله ای وجود ندارد!</li> ";
                    ddlSubGroups.SelectedIndex = 0;
                    ddlSubGroups.Enabled       = false;
                    ddlSubGroups.Items.Insert(0, new ListItem("همه زیرگروه ها", "-2"));
                }
            }
            else
            {
                ddlSubGroups.Items.Clear();
                ddlSubGroups.Items.Insert(0, new ListItem("همه زیرگروه ها", "-2"));
                ArticleRepository ArtRep   = new ArticleRepository();
                List <Article>    Articles = ArtRep.AllArticles();
                fillUl(Articles);
                ddlSubGroups.Enabled = false;
            }

            ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "run()", true);
            ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "myFunction()", true);
        }
コード例 #3
0
ファイル: Blogs.aspx.cs プロジェクト: sasan0512/construction
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (this.Page.RouteData.Values["gid"] != null)
                {
                    //load posts
                    GroupsRepository  Groupsrepo  = new GroupsRepository();
                    List <int>        subgroupsid = Groupsrepo.getSubGroupsIDByFatherID(this.Page.RouteData.Values["gid"].ToString().ToInt());
                    ArticleRepository artrep      = new ArticleRepository();
                    List <Article>    articles    = artrep.ReturnArticlesByCategory(subgroupsid);
                    if (articles.Count != 0)
                    {
                        DataTable DT = new DataTable();
                        DT = Groupsrepo.LoadSubGroup(this.Page.RouteData.Values["gid"].ToString().ToInt());
                        ddlSubGroups.Enabled = true;

                        ddlSubGroups.DataSource     = DT;
                        ddlSubGroups.DataTextField  = "Title";
                        ddlSubGroups.DataValueField = "GroupID";
                        ddlSubGroups.DataBind();
                        ddlSubGroups.Items.Insert(0, new ListItem("همه زیر گروه ها", "-2"));

                        fillUl(articles);
                        GroupsRepository repo = new GroupsRepository();
                        ddlGroups.DataSource     = repo.LoadAllGroups();
                        ddlGroups.DataTextField  = "Title";
                        ddlGroups.DataValueField = "GroupID";
                        ddlGroups.DataBind();
                        ddlGroups.Items.Insert(0, new ListItem("همه گروه ها", "-2"));
                        ddlGroups.SelectedValue = this.Page.RouteData.Values["gid"].ToString();
                    }
                    else
                    {
                        UlArticles.InnerHtml       = " <li class='danger'>در این بخش مقاله ای وجود ندارد!</li> ";
                        ddlSubGroups.SelectedIndex = 0;
                        GroupsRepository repo = new GroupsRepository();
                        ddlGroups.DataSource     = repo.LoadAllGroups();
                        ddlGroups.DataTextField  = "Title";
                        ddlGroups.DataValueField = "GroupID";
                        ddlGroups.DataBind();
                        ddlGroups.Items.Insert(0, new ListItem("همه گروه ها", "-2"));
                        ddlGroups.SelectedValue = this.Page.RouteData.Values["gid"].ToString();
                        ddlSubGroups.Enabled    = false;
                        ddlSubGroups.Items.Insert(0, new ListItem("همه زیرگروه ها", "-2"));
                    }
                }
                if (this.Page.RouteData.Values["sid"] != null)
                {
                    //load posts
                    GroupsRepository  Groupsrepo  = new GroupsRepository();
                    List <int>        subgroupsid = Groupsrepo.getSubGroupsIDByFatherID(this.Page.RouteData.Values["sid"].ToString().ToInt());
                    ArticleRepository artrep      = new ArticleRepository();
                    List <Article>    articles    = artrep.ReturnArticlesByCategory(subgroupsid);
                    if (articles.Count != 0)
                    {
                        fillUl(articles);
                        GroupsRepository repo = new GroupsRepository();
                        ddlGroups.DataSource     = repo.LoadAllGroups();
                        ddlGroups.DataTextField  = "Title";
                        ddlGroups.DataValueField = "GroupID";
                        ddlGroups.DataBind();
                        ddlGroups.Items.Insert(0, new ListItem("همه گروه ها", "-2"));
                        int?fatherid = repo.FindGroup(this.Page.RouteData.Values["sid"].ToString().ToInt()).FatherID;
                        ddlGroups.SelectedValue = fatherid.ToString();
                        DataTable DT = new DataTable();
                        DT = Groupsrepo.LoadSubGroup(fatherid.ToString().ToInt());


                        ddlSubGroups.Enabled = true;

                        ddlSubGroups.DataSource     = DT;
                        ddlSubGroups.DataTextField  = "Title";
                        ddlSubGroups.DataValueField = "GroupID";
                        ddlSubGroups.DataBind();
                        ddlSubGroups.Items.Insert(0, new ListItem("همه زیر گروه ها", "-2"));
                        ddlSubGroups.SelectedValue = this.Page.RouteData.Values["sid"].ToString();
                    }
                    else
                    {
                        GroupsRepository repo = new GroupsRepository();
                        int fatherid          = repo.FindGroup(this.Page.RouteData.Values["sid"].ToString().ToInt()).FatherID.ToString().ToInt();
                        UlArticles.InnerHtml = " <li class='danger'>در این بخش مقاله ای وجود ندارد!</li> ";

                        ddlGroups.DataSource     = repo.LoadAllGroups();
                        ddlGroups.DataTextField  = "Title";
                        ddlGroups.DataValueField = "GroupID";
                        ddlGroups.DataBind();
                        ddlGroups.Items.Insert(0, new ListItem("همه گروه ها", "-2"));
                        ddlGroups.SelectedValue = fatherid.ToString();
                        DataTable DT = new DataTable();
                        DT = Groupsrepo.LoadSubGroup(fatherid);


                        ddlSubGroups.Enabled = true;

                        ddlSubGroups.DataSource     = DT;
                        ddlSubGroups.DataTextField  = "Title";
                        ddlSubGroups.DataValueField = "GroupID";
                        ddlSubGroups.DataBind();
                        ddlSubGroups.Items.Insert(0, new ListItem("همه زیر گروه ها", "-2"));
                        ddlSubGroups.SelectedValue = this.Page.RouteData.Values["sid"].ToString();
                    }
                }
                if (this.Page.RouteData.Values["gid"] == null && this.Page.RouteData.Values["sid"] == null)
                {
                    //load posts

                    ArticleRepository ArtRep   = new ArticleRepository();
                    List <Article>    Articles = ArtRep.AllArticles();
                    fillUl(Articles);

                    //load ddls
                    ddlSubGroups.Enabled = false;

                    GroupsRepository repo = new GroupsRepository();
                    ddlGroups.DataSource     = repo.LoadAllGroups();
                    ddlGroups.DataTextField  = "Title";
                    ddlGroups.DataValueField = "GroupID";
                    ddlGroups.DataBind();
                    ddlGroups.Items.Insert(0, new ListItem("همه گروه ها", "-2"));
                    ddlSubGroups.Items.Insert(0, new ListItem("همه زیرگروه ها", "-2"));
                }
            }
        }
コード例 #4
0
        protected void group()
        {
            diverror.InnerHtml = "";
            if (ddlGroups.SelectedValue != "-2")
            {
                GroupsRepository Groupsrepo = new GroupsRepository();
                DataTable        DT         = new DataTable();
                DT = Groupsrepo.LoadSubGroup(ddlGroups.SelectedValue.ToInt());

                if ((DT.Rows.Count > 0))
                {
                    ddlSubGroups.Enabled = true;

                    ddlSubGroups.DataSource     = DT;
                    ddlSubGroups.DataTextField  = "Title";
                    ddlSubGroups.DataValueField = "GroupID";
                    ddlSubGroups.DataBind();
                    ddlSubGroups.Items.Insert(0, new ListItem("همه زیر گروه ها", "-2"));
                }
                else
                {
                    ddlSubGroups.Enabled = false;
                    ddlSubGroups.Items.Clear();
                    ddlSubGroups.Items.Insert(0, new ListItem("گروه : " + ddlGroups.SelectedItem.ToString(), ddlGroups.SelectedValue.ToString()));
                }
                //load posts
                List <int>        subgroupsid = Groupsrepo.getSubGroupsIDByFatherID(ddlGroups.SelectedValue.ToInt());
                ArticleRepository artrep      = new ArticleRepository();
                List <Article>    articles    = artrep.ReturnArticlesByCategory(subgroupsid);
                if (articles.Count != 0)
                {
                    gvPosts.DataSource = null;
                    gvPosts.DataSource = OnlineTools.ToDataTable(articles);
                    gvPosts.DataBind();
                }
                else
                {
                    gvPosts.DataSource = null;
                    gvPosts.DataBind();
                    diverror.InnerHtml         = " در این بخش مقاله ای وجود ندارد! ";
                    ddlSubGroups.SelectedIndex = 0;
                    ddlSubGroups.Enabled       = false;
                }
            }
            else
            {
                ArticleRepository artRep = new ArticleRepository();
                DataTable         DT     = new DataTable();
                DT = OnlineTools.ToDataTable(artRep.AllArticles());
                if (DT.Rows.Count != 0)
                {
                    gvPosts.DataSource = DT;
                    gvPosts.DataBind();
                    ddlSubGroups.SelectedIndex = 0;
                    ddlSubGroups.Enabled       = false;
                }
                else
                {
                    diverror.InnerHtml = " در این بخش مقاله ای وجود ندارد! ";
                    gvPosts.DataSource = null;
                    gvPosts.DataBind();
                }
            }
        }