// recursive tree loader. Passes back in a node to retireve its childre // until there are no more children for this node. private string getChildren(CV_CatNew node) { bool tagcover = false; string rt = ""; foreach (CV_CatNew cat in ltCat) // locate all children of this category { if (cat.ParentID.HasValue && cat.ParentID.Value == node.CatID) // found a child { if (!tagcover) { rt += "<ul>"; } rt += (CatIDSelect != cat.CatID) ? "<li>" : "<li class=\"ctselected\">"; rt += "<a href=\"" + WriteUrlCat(TabForward, "catnews=" + cat.CatID.ToString()) + "\">" + cat.CatName + "</a></li>"; rt += getChildren(cat); // find this child's children if (!tagcover) { rt += "</ul>"; tagcover = true; } } } return(rt); }
/// <summary> /// Thêm mới hoặc cập nhật danh mục /// Yêu cầu : /// 1 - Tên danh mục không trùng /// 2 - Khi cập nhật danh mục phải cập nhật cả tabpath của các danh mục con /// 3 - Khi thêm mới thiết lập catpath từ tên danh mục /// 4 - Không thuộc mục nào thì có parentid = null /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void SaveCatNews_Click(object sender, EventArgs e) { int? catparent; string rewriteName = "//" + WriteString(txtCatNewsName.Text.Trim()); string catpath = rewriteName; if (int.Parse(ddlCatNews.SelectedValue) != -1) { catparent = int.Parse(ddlCatNews.SelectedValue); var catparentObj = (from c in Data.CV_CatNews where catparent == c.CatID select c).FirstOrDefault(); if (catparentObj != null) { catpath = catparentObj.CatPath + "//" + WriteString(txtCatNewsName.Text.Trim()); } } else { catparent = null; } if (Request["catid"] != null) { //cap nhat tin tuc int catid = 0; if (int.TryParse(Request["catid"].ToString(), out catid)) { //kiem tra co doi ten danh muc trung voi ten danh muc nao khong var _CatCheck = from c in Data.CV_CatNews where (c.CatPath.Contains(rewriteName) && c.CatID != catid)&&c.PortalID==PortalId select c; var catnews = (from c in Data.CV_CatNews where c.CatID == catid && c.PortalID==PortalId select c).FirstOrDefault(); if (_CatCheck.Count() > 0) { //thong bao trung ten ltr.Text = "\""+txtCatNewsName.Text+"\" đã có vui lòng chọn tên khác"; txtCatNewsName.Text = catnews.CatName; } else { //cap nhat thay doi vao co so dl string tabpathOlder = ""; tabpathOlder = catnews.CatPath; if (catnews != null) { catnews.CatName = txtCatNewsName.Text.Trim(); catnews.ParentID = catparent; catnews.CatPath = catpath; //cap nhat cat danh muc con var cats = from c in Data.CV_CatNews where c.CatPath.Contains(tabpathOlder) && c.PortalID==PortalId select c; foreach (var c in cats) { c.CatPath = c.CatPath.Replace(tabpathOlder, catpath); } Data.SubmitChanges(); Response.Redirect(EditUrl("CatNews")); } } } } else { //kiem tra da ton tai danh mucj nao trong he thong chua var _CatCheck = from c in Data.CV_CatNews where c.CatPath.Contains(rewriteName) && c.PortalID==PortalId select c; if (_CatCheck.Count() > 0) { //thong bao trung ten ltr.Text = "\"" + txtCatNewsName.Text + "\" đã có vui lòng chọn tên khác"; } else { //them moi ti var catnews = new CV_CatNew { CatName = txtCatNewsName.Text.Trim(), ParentID = catparent, CatPath = catpath, PortalID = PortalId }; Data.CV_CatNews.InsertOnSubmit(catnews); Data.SubmitChanges(); Response.Redirect(EditUrl("CatNews")); } } }
// recursive tree loader. Passes back in a node to retireve its childre // until there are no more children for this node. private string getChildren(CV_CatNew node) { bool tagcover = false; string rt = ""; foreach (CV_CatNew cat in ltCat) // locate all children of this category { if (cat.ParentID.HasValue && cat.ParentID.Value == node.CatID) // found a child { if (!tagcover) { rt += "<ul>"; } rt += (CatIDSelect != cat.CatID) ? "<li>" : "<li class=\"ctselected\">"; rt += "<a href=\"" + WriteUrlCat(TabForward, "catnews=" + cat.CatID.ToString()) + "\">" + cat.CatName + "</a></li>"; rt += getChildren(cat); // find this child's children if (!tagcover) { rt += "</ul>"; tagcover = true; } } } return rt; }
/// <summary> /// Thêm mới hoặc cập nhật danh mục /// Yêu cầu : /// 1 - Tên danh mục không trùng /// 2 - Khi cập nhật danh mục phải cập nhật cả tabpath của các danh mục con /// 3 - Khi thêm mới thiết lập catpath từ tên danh mục /// 4 - Không thuộc mục nào thì có parentid = null /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void SaveCatNews_Click(object sender, EventArgs e) { int? catparent; string rewriteName = "//" + WriteString(txtCatNewsName.Text.Trim()); string catpath = rewriteName; if (int.Parse(ddlCatNews.SelectedValue) != -1) { catparent = int.Parse(ddlCatNews.SelectedValue); var catparentObj = (from c in Data.CV_CatNews where catparent == c.CatID select c).FirstOrDefault(); if (catparentObj != null) { catpath = catparentObj.CatPath + "//" + WriteString(txtCatNewsName.Text.Trim()); } } else { catparent = null; } if (Request["catid"] != null) { //cap nhat tin tuc int catid = 0; if (int.TryParse(Request["catid"].ToString(), out catid)) { //kiem tra co doi ten danh muc trung voi ten danh muc nao khong var _CatCheck = from c in Data.CV_CatNews where (c.CatPath.Contains(rewriteName) && c.CatID != catid) && c.PortalID == PortalId select c; var catnews = (from c in Data.CV_CatNews where c.CatID == catid && c.PortalID == PortalId select c).FirstOrDefault(); if (_CatCheck.Count() > 0) { //thong bao trung ten ltr.Text = "\"" + txtCatNewsName.Text + "\" đã có vui lòng chọn tên khác"; txtCatNewsName.Text = catnews.CatName; } else { //cap nhat thay doi vao co so dl string tabpathOlder = ""; tabpathOlder = catnews.CatPath; if (catnews != null) { catnews.CatName = txtCatNewsName.Text.Trim(); catnews.ParentID = catparent; catnews.CatPath = catpath; //cap nhat cat danh muc con var cats = from c in Data.CV_CatNews where c.CatPath.Contains(tabpathOlder) && c.PortalID == PortalId select c; foreach (var c in cats) { c.CatPath = c.CatPath.Replace(tabpathOlder, catpath); } Data.SubmitChanges(); Response.Redirect(EditUrl("CatNews")); } } } } else { //kiem tra da ton tai danh mucj nao trong he thong chua var _CatCheck = from c in Data.CV_CatNews where c.CatPath.Contains(rewriteName) && c.PortalID == PortalId select c; if (_CatCheck.Count() > 0) { //thong bao trung ten ltr.Text = "\"" + txtCatNewsName.Text + "\" đã có vui lòng chọn tên khác"; } else { //them moi ti var catnews = new CV_CatNew { CatName = txtCatNewsName.Text.Trim(), ParentID = catparent, CatPath = catpath, PortalID = PortalId }; Data.CV_CatNews.InsertOnSubmit(catnews); Data.SubmitChanges(); Response.Redirect(EditUrl("CatNews")); } } }