partial void UpdateHelpDesk_Category(HelpDesk_Category instance);
 partial void DeleteHelpDesk_Category(HelpDesk_Category instance);
 partial void InsertHelpDesk_Category(HelpDesk_Category instance);
예제 #4
0
        private void AddChildren(ListItemCollection colListItemCollection, HelpDesk_Category objHelpDesk_Category, int BranchNotToShow)
        {

            // Get the children of the current item
            // This method may be called from the top level or recuresively by one of the child items
            var ChildResults = from WebserverCategories in EntireTable
                               where WebserverCategories.ParentCategoryID == objHelpDesk_Category.CategoryID
                               where WebserverCategories.CategoryID != BranchNotToShow
                               select WebserverCategories;

            // Loop thru each item
            foreach (HelpDesk_Category objCategory in ChildResults)
            {
                // Create a new list item to add to the collection
                ListItem objChildListItem = new ListItem();
                // AddDots method is used to add the dots to indicate the item is a sub item
                objChildListItem.Text = String.Format("{0}{1}", AddDots(objCategory.Level), objCategory.CategoryName);
                objChildListItem.Value = objCategory.CategoryID.ToString();
                colListItemCollection.Add(objChildListItem);

                //Recursively call the AddChildren method adding all children
                AddChildren(colListItemCollection, objCategory, BranchNotToShow);
            }
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            HelpDeskDALDataContext objHelpDeskDALDataContext = new HelpDeskDALDataContext();

            // Get the node
            var result = (from HelpDesk_Categories in objHelpDeskDALDataContext.HelpDesk_Categories
                          where HelpDesk_Categories.CategoryID == Convert.ToInt32(txtCategoryID.Text)
                          select HelpDesk_Categories).FirstOrDefault();

            // Make a Temp object to use to update the child nodes
            HelpDesk_Category TmpHelpDesk_Category = new HelpDesk_Category();
            TmpHelpDesk_Category.CategoryID = result.CategoryID;
            if (result.ParentCategoryID == null)
            {
                TmpHelpDesk_Category.Level = 0;
            }
            else
            {
                TmpHelpDesk_Category.Level = GetLevelOfParent(result.ParentCategoryID);
            }

            // Get all TaskCategories that use the Node
            var colTaskCategories = from HelpDesk_TaskCategories in objHelpDeskDALDataContext.HelpDesk_TaskCategories
                                    where HelpDesk_TaskCategories.CategoryID == Convert.ToInt32(txtCategoryID.Text)
                                    select HelpDesk_TaskCategories;

            // Delete them
            objHelpDeskDALDataContext.HelpDesk_TaskCategories.DeleteAllOnSubmit(colTaskCategories);
            objHelpDeskDALDataContext.SubmitChanges();

            // Delete the node
            objHelpDeskDALDataContext.HelpDesk_Categories.DeleteOnSubmit(result);
            objHelpDeskDALDataContext.SubmitChanges();

            // Update levels of all the Children            
            UpdateLevelOfChildren(TmpHelpDesk_Category);

            // Update all the children nodes to give them a new parent
            var CategoryChildren = from HelpDesk_Categories in objHelpDeskDALDataContext.HelpDesk_Categories
                                   where HelpDesk_Categories.ParentCategoryID == result.CategoryID
                                   select HelpDesk_Categories;

            // Loop thru each item
            foreach (var objCategory in CategoryChildren)
            {
                objCategory.ParentCategoryID = result.ParentCategoryID;
                objHelpDeskDALDataContext.SubmitChanges();
            }

            // Delete the Catagory from any Ticket that uses it
            var DeleteHelpDesk_TaskCategories = from HelpDesk_TaskCategories in objHelpDeskDALDataContext.HelpDesk_TaskCategories
                                                where HelpDesk_TaskCategories.CategoryID == TmpHelpDesk_Category.CategoryID
                                                select HelpDesk_TaskCategories;

            objHelpDeskDALDataContext.HelpDesk_TaskCategories.DeleteAllOnSubmit(DeleteHelpDesk_TaskCategories);
            objHelpDeskDALDataContext.SubmitChanges();

            RefreshCache();

            // Set the CategoryID
            txtCategoryID.Text = (result.ParentCategoryID == null) ? "" : result.ParentCategoryID.ToString();

            DisplayHelpDesk();
            SelectTreeNode();
        }
        private void UpdateLevelOfChildren(HelpDesk_Category result)
        {
            int? intStartingLevel = result.Level;

            if (colProcessedCategoryIDs == null)
            {
                colProcessedCategoryIDs = new List<int>();
            }

            HelpDeskDALDataContext objHelpDeskDALDataContext = new HelpDeskDALDataContext();

            // Get the children of the current item
            // This method may be called from the top level or recuresively by one of the child items
            var CategoryChildren = from HelpDesk_Categories in objHelpDeskDALDataContext.HelpDesk_Categories
                                   where HelpDesk_Categories.ParentCategoryID == result.CategoryID
                                   where !colProcessedCategoryIDs.Contains(result.CategoryID)
                                   select HelpDesk_Categories;

            // Loop thru each item
            foreach (var objCategory in CategoryChildren)
            {
                colProcessedCategoryIDs.Add(objCategory.CategoryID);

                objCategory.Level = ((intStartingLevel) ?? 0) + 1;
                objHelpDeskDALDataContext.SubmitChanges();

                //Recursively call the UpdateLevelOfChildren method adding all children
                UpdateLevelOfChildren(objCategory);
            }
        }
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            HelpDeskDALDataContext objHelpDeskDALDataContext = new HelpDeskDALDataContext();

            if (btnUpdate.CommandName == "Update")
            {
                var result = (from HelpDesk_Categories in objHelpDeskDALDataContext.HelpDesk_Categories
                              where HelpDesk_Categories.CategoryID == Convert.ToInt32(txtCategoryID.Text)
                              select HelpDesk_Categories).FirstOrDefault();

                result.CategoryName = txtCategory.Text.Trim();

                result.ParentCategoryID = (GetParentCategoryID(ddlParentCategory.SelectedValue) == "0") ? (int?)null : Convert.ToInt32(ddlParentCategory.SelectedValue);
                txtParentCategoryID.Text = (ddlParentCategory.SelectedValue == "0") ? "" : ddlParentCategory.SelectedValue;

                result.Level = (ddlParentCategory.SelectedValue == "0") ? 1 : GetLevelOfParent(Convert.ToInt32(ddlParentCategory.SelectedValue)) + 1;
                result.RequestorVisible = chkRequesterVisible.Checked;
                result.Selectable = chkSelectable.Checked;

                objHelpDeskDALDataContext.SubmitChanges();

                // Update levels off all the Children
                colProcessedCategoryIDs = new List<int>();
                UpdateLevelOfChildren(result);
            }
            else
            {
                // This is a Save for a new Node                

                HelpDesk_Category objHelpDesk_Category = new HelpDesk_Category();
                objHelpDesk_Category.PortalID = PortalId;
                objHelpDesk_Category.CategoryName = txtCategory.Text.Trim();
                objHelpDesk_Category.ParentCategoryID = (GetParentCategoryID(ddlParentCategory.SelectedValue) == "0") ? (int?)null : Convert.ToInt32(ddlParentCategory.SelectedValue);
                objHelpDesk_Category.Level = (ddlParentCategory.SelectedValue == "0") ? 1 : GetLevelOfParent(Convert.ToInt32(ddlParentCategory.SelectedValue)) + 1;
                objHelpDesk_Category.RequestorVisible = chkRequesterVisible.Checked;
                objHelpDesk_Category.Selectable = chkSelectable.Checked;

                objHelpDeskDALDataContext.HelpDesk_Categories.InsertOnSubmit(objHelpDesk_Category);
                objHelpDeskDALDataContext.SubmitChanges();

                // Set the Hidden CategoryID
                txtParentCategoryID.Text = (objHelpDesk_Category.ParentCategoryID == null) ? "" : ddlParentCategory.SelectedValue;
                txtCategoryID.Text = objHelpDesk_Category.CategoryID.ToString();
                ResetForm();
            }

            RefreshCache();
            DisplayHelpDesk();

            // Set the Parent drop-down
            if (txtParentCategoryID.Text != "")
            {
                ddlParentCategory.SelectedValue = txtParentCategoryID.Text;
            }
        }