//[ScriptMethod(UseHttpGet = true)] public static List <Group> getSubgroups(string Id) { DataTable dt = new DataTable(); List <Group> objDept = new List <Group>(); GroupsRepository jg = new GroupsRepository(); try { //Page page = (Page)HttpContext.Current.Handler; //DropDownList DDLGroups = (DropDownList)page.FindControl("DDLGroups"); dt = jg.LoadSubGroup(Id.ToInt()); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { objDept.Add(new Group { GroupID = Convert.ToInt32(dt.Rows[i][0]), Title = dt.Rows[i][1].ToString(), }); } } else { Group gg = jg.FindGroup(Id.ToInt()); objDept.Add(new Group { GroupID = gg.GroupID, Title = gg.Title } ); } return(objDept); } catch (Exception e) { Debug.Unindent(); Debug.Print(e.ToString()); Debug.Indent(); Debug.WriteLine(e.ToString()); Debug.Flush(); Show(e.ToString()); } return(objDept); }
protected void btnSaveSubGroupChane_Click(object sender, EventArgs e) { GroupsRepository repgp = new GroupsRepository(); if (!String.IsNullOrEmpty(SubNewName.Text)) { Group ngr = new Group(); ngr = repgp.FindGroup(SubIDHolder.Text.ToInt()); ngr.Title = SubNewName.Text; if (repgp.Savegp(ngr)) { gvSubGroups.DataSource = null; gvSubGroups.DataBind(); if (ddlGroups.SelectedValue != "-2") { gvSubGroups.DataSource = repgp.LoadSubGroup(ddlGroups.SelectedValue.ToInt()); } else { gvSubGroups.DataSource = repgp.LoadAllSubGroups(); } gvSubGroups.DataBind(); System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(@"<script type='text/javascript'>"); sb.Append("$('#modalShowGroupDetails').modal('hide');"); sb.Append(@"</script>"); ScriptManager.RegisterStartupScript(this, this.GetType(), "ModalScript", sb.ToString(), false); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('ثبت با موفقیت انجام شد');", true); SubNewName.Text = ""; } else { SubNewName.Text = ""; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(@"<script type='text/javascript'>"); sb.Append("$('#modalShowGroupDetails').modal('hide');"); sb.Append(@"</script>"); ScriptManager.RegisterStartupScript(this, this.GetType(), "ModalScript", sb.ToString(), false); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('ثبت با خطا مواجه شد !');", true); } } }
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")); } } }