コード例 #1
0
        private void UpdateLevelOfChildren(ITILServiceDesk_Category result)
        {
            int?intStartingLevel = result.Level;

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

            ServiceDeskDALDataContext objServiceDeskDALDataContext = new ServiceDeskDALDataContext();

            // 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 ITILServiceDesk_Categories in objServiceDeskDALDataContext.ITILServiceDesk_Categories
                                   where ITILServiceDesk_Categories.ParentCategoryID == result.CategoryID
                                   where !colProcessedCategoryIDs.Contains(result.CategoryID)
                                   select ITILServiceDesk_Categories;

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

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

                //Recursively call the UpdateLevelOfChildren method adding all children
                UpdateLevelOfChildren(objCategory);
            }
        }
コード例 #2
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            ServiceDeskDALDataContext objServiceDeskDALDataContext = new ServiceDeskDALDataContext();

            if (btnUpdate.CommandName == "Update")
            {
                var result = (from ITILServiceDesk_Categories in objServiceDeskDALDataContext.ITILServiceDesk_Categories
                              where ITILServiceDesk_Categories.CategoryID == Convert.ToInt32(txtCategoryID.Text)
                              select ITILServiceDesk_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;

                objServiceDeskDALDataContext.SubmitChanges();

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

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

                objServiceDeskDALDataContext.ITILServiceDesk_Categories.InsertOnSubmit(objITILServiceDesk_Category);
                objServiceDeskDALDataContext.SubmitChanges();

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

            RefreshCache();
            DisplayCatagories();

            // Set the Parent drop-down
            if (txtParentCategoryID.Text != "")
            {
                ddlParentCategory.SelectedValue = txtParentCategoryID.Text;
            }
        }
コード例 #3
0
        private void AddChildren(ListItemCollection colListItemCollection, ITILServiceDesk_Category objITILServiceDesk_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 ServiceDeskCategories in EntireTable
                               where ServiceDeskCategories.ParentCategoryID == objITILServiceDesk_Category.CategoryID
                               where ServiceDeskCategories.CategoryID != BranchNotToShow
                               select ServiceDeskCategories;

            // Loop thru each item
            foreach (ITILServiceDesk_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);
            }
        }
コード例 #4
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            ServiceDeskDALDataContext objServiceDeskDALDataContext = new ServiceDeskDALDataContext();

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

            // Make a Temp object to use to update the child nodes
            ITILServiceDesk_Category TmpITILServiceDesk_Category = new ITILServiceDesk_Category();

            TmpITILServiceDesk_Category.CategoryID = result.CategoryID;
            if (result.ParentCategoryID == null)
            {
                TmpITILServiceDesk_Category.Level = 0;
            }
            else
            {
                TmpITILServiceDesk_Category.Level = GetLevelOfParent(result.ParentCategoryID);
            }

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

            // Delete them
            objServiceDeskDALDataContext.ITILServiceDesk_TaskCategories.DeleteAllOnSubmit(colTaskCategories);
            objServiceDeskDALDataContext.SubmitChanges();

            // Delete the node
            objServiceDeskDALDataContext.ITILServiceDesk_Categories.DeleteOnSubmit(result);
            objServiceDeskDALDataContext.SubmitChanges();

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

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

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

            // Delete the Catagory from any Ticket that uses it
            var DeleteHelpDesk_TaskCategories = from ITILServiceDesk_TaskCategories in objServiceDeskDALDataContext.ITILServiceDesk_TaskCategories
                                                where ITILServiceDesk_TaskCategories.CategoryID == TmpITILServiceDesk_Category.CategoryID
                                                select ITILServiceDesk_TaskCategories;

            objServiceDeskDALDataContext.ITILServiceDesk_TaskCategories.DeleteAllOnSubmit(DeleteHelpDesk_TaskCategories);
            objServiceDeskDALDataContext.SubmitChanges();

            RefreshCache();

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

            DisplayCatagories();
            SelectTreeNode();
        }