protected void gvItems_DataBinding(object sender, EventArgs e) { string type = Request["type"]; TermTypes termType = TermTypes.Category; if (!String.IsNullOrEmpty(type)) { termType = BSTerm.GetTermType(type); } List <BSTerm> categories = BSTerm.GetTermsBySubID(termType, 0); List <string> lstNames = new List <string>(); for (int i = 0; i < categories.Count; i++) { string strParents = string.Empty; BSTerm category = categories[i]; while (category.SubID != 0) { BSTerm subCategory = BSTerm.GetTerm(category.SubID); strParents = subCategory.Name + " > " + strParents; } lstNames.Add(strParents + category.Name); } ((GridView)sender).DataSource = categories; if (!IsPostBack) { ddlParentCategory.Items.Insert(0, new ListItem(Language.Admin["None"], "0")); } }
private void SaveTags(int iPostID) { string[] strTags = txtPostTags.Text.Split(','); for (int i = 0; i < strTags.Length; i++) { if (strTags[i].Trim() != "") { string code = BSHelper.CreateCode(strTags[i].Trim()); string name = strTags[i].Trim(); BSTerm bsTerm = BSTerm.GetTerm(code, TermTypes.Tag); if (bsTerm == null) { bsTerm = new BSTerm(); bsTerm.Name = name; bsTerm.Code = code; bsTerm.Type = TermTypes.Tag; bsTerm.Save(); } bsTerm.Objects.Add(iPostID); bsTerm.Save(); } } }
protected void Page_Load(object sender, EventArgs e) { GenerateHeaderButtons(); if (!Page.IsPostBack) { HideAll(); int iTermID = 0; int.TryParse(Request["TermID"], out iTermID); if (iTermID != 0) { divEditTerm.Visible = true; divSideEditTerm.Visible = true; BSTerm bsTerm = BSTerm.GetTerm(iTermID); if (bsTerm != null) { txtCatName.Text = bsTerm.Name; } else { Response.Redirect("Links.aspx"); } } else { divPosts.Visible = true; divAddTerm.Visible = true; gvItems.DataBind(); } } }
protected void btnSave_Click(object sender, EventArgs e) { string TermID = Request.QueryString["TermID"]; int iTermID = 0; int.TryParse(TermID, out iTermID); if (!String.IsNullOrEmpty(txtCatName.Text.Trim()) && iTermID > 0) { BSTerm bsTerm = BSTerm.GetTerm(iTermID); bsTerm.Name = txtCatName.Text; bsTerm.Description = txtCatDescription.Text; bsTerm.Code = BSHelper.CreateCode(txtCatName.Text); //term.SubID = int.Parse(ddlParentCategory.SelectedValue); if (bsTerm.Save()) { MessageBox1.Message = Language.Admin["CategorySaved"]; MessageBox1.Type = MessageBox.ShowType.Information; gvItems.DataBind(); txtName.Text = string.Empty; txtDescription.Text = string.Empty; } else { MessageBox1.Message = Language.Admin["CategoryError"]; } } else { Response.Redirect("Categories.aspx"); } }
protected void btnDelete_Click(object sender, EventArgs e) { bool bRemoved = false; for (int i = 0; i < gvItems.Rows.Count; i++) { CheckBox cb = gvItems.Rows[i].FindControl("cb") as CheckBox; if (cb.Checked) { Literal literal = gvItems.Rows[i].FindControl("TermID") as Literal; if (literal != null) { int iTermID = 0; int.TryParse(literal.Text, out iTermID); BSTerm bsTerm = BSTerm.GetTerm(iTermID); if (bsTerm != null) { bRemoved = bsTerm.Remove(); } } } } if (bRemoved) { MessageBox1.Message = Language.Admin["TagDeleted"]; MessageBox1.Type = MessageBox.ShowType.Information; MessageBox1.Visible = true; gvItems.DataBind(); } }
protected void btnSave_Click(object sender, EventArgs e) { int iTermID = 0; int.TryParse(Request["TermID"], out iTermID); if (iTermID > 0) { BSTerm bsTerm = BSTerm.GetTerm(iTermID); bsTerm.Name = txtCatName.Text; bsTerm.Code = BSHelper.CreateCode(txtCatName.Text); if (bsTerm.Save()) { MessageBox1.Message = Language.Admin["TagSaved"]; MessageBox1.Type = MessageBox.ShowType.Information; gvItems.DataBind(); txtName.Text = string.Empty; } else { MessageBox1.Message = "Error"; } } else { Response.Redirect("Categories.aspx"); } }
protected void btnAdd_Click(object sender, EventArgs e) { if (txtName.Text.Trim() != "") { string code = BSHelper.CreateCode(txtName.Text); BSTerm bsTerm = BSTerm.GetTerm(code, TermTypes.Tag); if (bsTerm == null) { bsTerm = new BSTerm(); bsTerm.Name = txtName.Text; bsTerm.Type = TermTypes.Tag; bsTerm.Code = code; } bsTerm.Save(); if (bsTerm.Save()) { MessageBox1.Message = Language.Admin["TagSaved"]; MessageBox1.Type = MessageBox.ShowType.Information; gvItems.DataBind(); txtName.Text = string.Empty; } else { MessageBox1.Message = "Error"; } } }
public void SaveTags(int ObjectID) { string strTags = txtTags.Value; Regex rex = new Regex("\\{(.*?)\\}"); BSTerm.RemoveTo(TermTypes.Tag, ObjectID); foreach (Match item in rex.Matches(strTags)) { Regex rx = new Regex("'(.*?)'"); string strText = rx.Matches(item.Value)[1].Value; string strValue = rx.Matches(item.Value)[0].Value; strText = strText.Substring(1, strText.Length - 2); strValue = strValue.Substring(1, strValue.Length - 2); string code = BSHelper.CreateCode(strText); BSTerm bsTerm = BSTerm.GetTerm(code, TermTypes.Tag); if (bsTerm == null) { bsTerm = new BSTerm(); bsTerm.Name = strText; bsTerm.Code = code; bsTerm.Type = TermTypes.Tag; bsTerm.Objects.Add(ObjectID); bsTerm.Save(); } else { bsTerm.Objects.Add(ObjectID); bsTerm.Save(); } } }
public void SaveData(int ObjectID) { using (DataProcess dp = new DataProcess()) { BSTerm.RemoveTo(TermTypes.Category, ObjectID); for (int i = 0; i < cblCats.Items.Count; i++) { if (cblCats.Items[i].Selected == true) { BSTerm bsTerm = BSTerm.GetTerm(Convert.ToInt32(cblCats.Items[i].Value)); bsTerm.Objects.Add(ObjectID); bsTerm.Save(); } } } }
public static List <BSPost> GetPostsByTerm(int termId, string code, TermTypes termType, PostTypes postType, PostStates postState) { List <BSPost> posts = new List <BSPost>(); using (DataProcess dp = new DataProcess()) { BSTerm bsTerm = null; bsTerm = termId != 0 ? BSTerm.GetTerm(termId) : BSTerm.GetTerm(code, termType); if (bsTerm != null) { dp.AddParameter("TermID", bsTerm.TermID); if (postState != PostStates.All) { dp.AddParameter("State", (short)postState); dp.ExecuteReader("SELECT * FROM Posts WHERE [PostID] IN (SELECT [ObjectID] FROM TermsTo WHERE [TermID]=@TermID) AND [State]=@State ORDER By [CreateDate] DESC"); } else { dp.ExecuteReader("SELECT * FROM Posts WHERE [PostID] IN (SELECT [ObjectID] FROM TermsTo WHERE [TermID]=@TermID) AND [Type]=@Type ORDER By [CreateDate] DESC"); } } else { return(posts); } if (dp.Return.Status == DataProcessState.Success) { using (IDataReader dr = dp.Return.Value as IDataReader) { while (dr != null && dr.Read()) { BSPost bsPost = new BSPost(); FillPost(dr, bsPost); posts.Add(bsPost); } } } } return(posts); }
protected void btnDelete_Click(object sender, EventArgs e) { bool bSomeOne = false; bool bCategoriesRemoved = false; for (int i = 0; i < gvItems.Rows.Count; i++) { CheckBox cb = gvItems.Rows[i].FindControl("cb") as CheckBox; if (cb.Checked) { string TermID = (gvItems.Rows[i].FindControl("TermID") as Literal).Text; int iTermID = int.Parse(TermID); List <BSTerm> categories = BSTerm.GetTermsBySubID(TermTypes.Category, iTermID); if (categories.Count == 0) { BSTerm bsTerm = BSTerm.GetTerm(iTermID); if (bsTerm != null) { bsTerm.Remove(); } bCategoriesRemoved = true; } else { bSomeOne = true; } } } if (bSomeOne) { MessageBox1.Message = Language.Admin["CategoryHaveSub"]; MessageBox1.Type = MessageBox.ShowType.Information; } else if (bCategoriesRemoved) { MessageBox1.Message = Language.Admin["CategoryDeleted"]; MessageBox1.Type = MessageBox.ShowType.Information; MessageBox1.Visible = true; gvItems.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { GenerateHeaderButtons(); if (!Page.IsPostBack) { HideAll(); ddlParentCategory.DataTextField = "Name"; ddlParentCategory.DataValueField = "TermID"; ddlParentCategory.DataSource = BSTerm.GetTerms(TermTypes.Category); ddlParentCategory.DataBind(); string TermID = Request.QueryString["TermID"]; int iTermID = 0; int.TryParse(TermID, out iTermID); if (iTermID > 0) { divEditTerm.Visible = true; divSideEditTerm.Visible = true; BSTerm bsTerm = BSTerm.GetTerm(iTermID); if (bsTerm != null) { txtCatName.Text = bsTerm.Name; txtCatDescription.Text = bsTerm.Description; } else { Response.Redirect("Links.aspx"); } } else { divPosts.Visible = true; divAddTerm.Visible = true; gvItems.DataBind(); } } }
private static void FillMenu(IDataReader dr, BSMenu menu) { menu.Description = (string)dr["Description"]; menu.MenuGroupID = (int)dr["MenuGroupID"]; menu.MenuID = (int)dr["MenuID"]; menu.MenuType = (MenuTypes)dr["MenuType"]; menu.ObjectID = (int)dr["ObjectID"]; menu.ObjectType = (ObjectTypes)dr["ObjectType"]; menu.ParentID = (int)dr["ParentID"]; menu.Sort = (short)dr["Sort"]; menu.Target = (string)dr["Target"]; menu.Title = (string)dr["Title"]; menu.Url = (string)dr["Url"]; if (menu.Url.StartsWith("~/")) { menu.Url = Blogsa.Url + menu.Url.Substring(2); } switch (menu.ObjectType) { case ObjectTypes.Article: BSPost article = BSPost.GetPost(menu.ObjectID); if (article != null) { menu.Title = article.Title; menu.Url = article.Link; } break; case ObjectTypes.Page: BSPost page = BSPost.GetPost(menu.ObjectID); if (page != null) { menu.Title = page.Title; menu.Url = page.Link; } break; case ObjectTypes.File: BSPost file = BSPost.GetPost(menu.ObjectID); if (file != null) { menu.Title = file.Title; menu.Url = file.Link; } break; case ObjectTypes.Link: BSLink link = BSLink.GetLink(menu.ObjectID); if (link != null) { menu.Title = link.Name; menu.Url = link.Url; } break; case ObjectTypes.Term: BSTerm term = BSTerm.GetTerm(menu.ObjectID); if (term != null) { menu.Title = term.Name; menu.Url = term.Link; } break; case ObjectTypes.Comment: BSComment comment = BSComment.GetComment(menu.ObjectID); if (comment != null) { menu.Title = comment.Content; menu.Url = comment.Link; } break; default: break; } }