// 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_CatProduct node)
        {
            bool   tagcover = false;
            string rt       = "";

            foreach (CV_CatProduct 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, "catproduct=" + cat.CatID.ToString()) + "\">" + cat.CatName + "</a></li>";
                    rt += getChildren(cat); // find this child's children
                    if (!tagcover)
                    {
                        rt      += "</ul>";
                        tagcover = true;
                    }
                }
            }

            return(rt);
        }
        // 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_CatProduct node)
        {
            bool tagcover = false;
            string rt = "";
            foreach (CV_CatProduct 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, "catproduct=" + 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 SaveCatProduct_Click(object sender, EventArgs e)
        {
            int? catparent;
            string _writeName = "//" + WriteString(txtCatProductsName.Text.Trim());
            string catpath = _writeName;

            if (int.Parse(ddlCatPrd.SelectedValue) != -1)
            {
                catparent = int.Parse(ddlCatPrd.SelectedValue);

                var catparentObj = (from c in Data.CV_CatProducts
                                    where catparent == c.CatID && c.PortalID==PortalId
                                    select c).FirstOrDefault();

                if (catparentObj != null)
                {
                    catpath = catparentObj.CatPath + "//" + WriteString(txtCatProductsName.Text.Trim());
                }
            }
            else
            {
                catparent = null;
            }

            if (Request["catid"] != null)
            {
                //cap nhat tin tuc
                int catid = 0;
                if (int.TryParse(Request["catid"].ToString(), out catid))
                {

                    var _catCheck = from c in Data.CV_CatProducts
                                    where c.CatPath.Contains(_writeName) && c.CatID != catid && c.PortalID==PortalId
                                    select c;

                    var catprd = (from c in Data.CV_CatProducts
                                  where c.CatID == catid
                                  select c).FirstOrDefault();

                    if (_catCheck.Count() > 0)
                    {
                        //thong bao trung ten
                        ltr.Text = "\"" + txtCatProductsName.Text + "\" đã có vui lòng chọn tên khác";
                        txtCatProductsName.Text = catprd.CatName;
                    }
                    else
                    {
                        string tabpathOlder = "";

                        tabpathOlder = catprd.CatPath;
                        if (catprd != null)
                        {
                            catprd.CatName = txtCatProductsName.Text.Trim();
                            catprd.ParentID = catparent;
                            catprd.CatPath = catpath;

                            var catchild = from c in Data.CV_CatProducts
                                           where c.CatPath.Contains(tabpathOlder) && c.PortalID==PortalId
                                           select c;
                            //cap nhat catpath con
                            foreach (CV_CatProduct cp in catchild)
                            {
                                cp.CatPath = cp.CatPath.Replace(tabpathOlder, catpath);
                            }
                            Data.SubmitChanges();
                            Response.Redirect(EditUrl("CatProduct"));
                        }
                    }
                }
            }
            else
            {
                //kiem tra trung ten danh muc hay khong
                var _catCheck = from c in Data.CV_CatProducts
                                where c.CatPath.Contains(_writeName) && c.PortalID==PortalId
                                select c;
                if (_catCheck.Count() > 0)
                {
                    //thong bao trung ten
                    ltr.Text = "\"" + txtCatProductsName.Text + "\" đã có vui lòng chọn tên khác";
                }
                else
                {
                    //them moi ti
                    var catprd = new CV_CatProduct
                    {
                        CatName = txtCatProductsName.Text.Trim(),
                        ParentID = catparent,
                        CatPath = catpath,
                        PortalID = PortalId
                    };
                    Data.CV_CatProducts.InsertOnSubmit(catprd);
                    Data.SubmitChanges();
                    Response.Redirect(EditUrl("CatProduct"));
                }
            }
        }
示例#4
0
        /// <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 SaveCatProduct_Click(object sender, EventArgs e)
        {
            int?   catparent;
            string _writeName = "//" + WriteString(txtCatProductsName.Text.Trim());
            string catpath    = _writeName;

            if (int.Parse(ddlCatPrd.SelectedValue) != -1)
            {
                catparent = int.Parse(ddlCatPrd.SelectedValue);

                var catparentObj = (from c in Data.CV_CatProducts
                                    where catparent == c.CatID && c.PortalID == PortalId
                                    select c).FirstOrDefault();

                if (catparentObj != null)
                {
                    catpath = catparentObj.CatPath + "//" + WriteString(txtCatProductsName.Text.Trim());
                }
            }
            else
            {
                catparent = null;
            }

            if (Request["catid"] != null)
            {
                //cap nhat tin tuc
                int catid = 0;
                if (int.TryParse(Request["catid"].ToString(), out catid))
                {
                    var _catCheck = from c in Data.CV_CatProducts
                                    where c.CatPath.Contains(_writeName) && c.CatID != catid && c.PortalID == PortalId
                                    select c;

                    var catprd = (from c in Data.CV_CatProducts
                                  where c.CatID == catid
                                  select c).FirstOrDefault();

                    if (_catCheck.Count() > 0)
                    {
                        //thong bao trung ten
                        ltr.Text = "\"" + txtCatProductsName.Text + "\" đã có vui lòng chọn tên khác";
                        txtCatProductsName.Text = catprd.CatName;
                    }
                    else
                    {
                        string tabpathOlder = "";

                        tabpathOlder = catprd.CatPath;
                        if (catprd != null)
                        {
                            catprd.CatName  = txtCatProductsName.Text.Trim();
                            catprd.ParentID = catparent;
                            catprd.CatPath  = catpath;

                            var catchild = from c in Data.CV_CatProducts
                                           where c.CatPath.Contains(tabpathOlder) && c.PortalID == PortalId
                                           select c;
                            //cap nhat catpath con
                            foreach (CV_CatProduct cp in catchild)
                            {
                                cp.CatPath = cp.CatPath.Replace(tabpathOlder, catpath);
                            }
                            Data.SubmitChanges();
                            Response.Redirect(EditUrl("CatProduct"));
                        }
                    }
                }
            }
            else
            {
                //kiem tra trung ten danh muc hay khong
                var _catCheck = from c in Data.CV_CatProducts
                                where c.CatPath.Contains(_writeName) && c.PortalID == PortalId
                                select c;
                if (_catCheck.Count() > 0)
                {
                    //thong bao trung ten
                    ltr.Text = "\"" + txtCatProductsName.Text + "\" đã có vui lòng chọn tên khác";
                }
                else
                {
                    //them moi ti
                    var catprd = new CV_CatProduct
                    {
                        CatName  = txtCatProductsName.Text.Trim(),
                        ParentID = catparent,
                        CatPath  = catpath,
                        PortalID = PortalId
                    };
                    Data.CV_CatProducts.InsertOnSubmit(catprd);
                    Data.SubmitChanges();
                    Response.Redirect(EditUrl("CatProduct"));
                }
            }
        }