Beispiel #1
0
    /// <summary>
    /// Saves control with actual data.
    /// </summary>
    public bool Save()
    {
        if (!CheckPermissions("CMS.ProjectManagement", CMSAdminControl.PERMISSION_MANAGE))
        {
            return(false);
        }

        // Validate the form
        if (Validate())
        {
            // Indicates whether project is new
            bool isNew = false;

            int progress = 0;

            // Ensure the info object
            if (this.ProjectObj == null)
            {
                // New project

                ProjectInfo pi = new ProjectInfo();
                // First initialization of the Access propery - allow authenticated users
                pi.ProjectAccess      = 1222;
                pi.ProjectCreatedByID = CMSContext.CurrentUser.UserID;

                pi.ProjectOwner = 0;

                if (CommunityGroupID != 0)
                {
                    pi.ProjectGroupID = CommunityGroupID;
                    // Set default access to the group
                    pi.ProjectAccess = 3333;
                }

                mProjectObj = pi;
                isNew       = true;
            }
            else
            {
                // Existing project

                // Reset ProjectOrder if checkbox was unchecked
                if ((this.ProjectObj.ProjectAllowOrdering) &&
                    (!this.chkProjectAllowOrdering.Checked))
                {
                    ProjectInfoProvider.ResetProjectOrder(this.ProjectObj.ProjectID);
                }

                // Clear the hashtables if the codename has been changed
                if ((this.ProjectObj.ProjectGroupID > 0) &&
                    this.ProjectObj.ProjectName != this.txtProjectName.Text)
                {
                    ProjectInfoProvider.Clear(true);
                }

                progress = ProjectInfoProvider.GetProjectProgress(this.ProjectObj.ProjectID);
            }

            this.ltrProjectProgress.Text = ProjectTaskInfoProvider.GenerateProgressHtml(progress, true);

            // Initialize object
            this.ProjectObj.ProjectSiteID = CMSContext.CurrentSiteID;

            if (DisplayMode == ControlDisplayModeEnum.Simple)
            {
                if (isNew)
                {
                    this.ProjectObj.ProjectName = ValidationHelper.GetCodeName(txtProjectDisplayName.Text, 50) + ((CommunityGroupID > 0) ? "_group_" : "_general_") + this.CodenameGUID;
                }
            }
            else
            {
                this.ProjectObj.ProjectName = this.txtProjectName.Text.Trim();
            }
            this.ProjectObj.ProjectDisplayName   = this.txtProjectDisplayName.Text.Trim();
            this.ProjectObj.ProjectDescription   = this.txtProjectDescription.Text.Trim();
            this.ProjectObj.ProjectStartDate     = this.dtpProjectStartDate.SelectedDateTime;
            this.ProjectObj.ProjectDeadline      = this.dtpProjectDeadline.SelectedDateTime;
            this.ProjectObj.ProjectOwner         = ValidationHelper.GetInteger(userSelector.UniSelector.Value, 0);
            this.ProjectObj.ProjectStatusID      = ValidationHelper.GetInteger(drpProjectStatus.SelectedValue, 0);
            this.ProjectObj.ProjectAllowOrdering = this.chkProjectAllowOrdering.Checked;

            // Set ProjectNodeID
            if (!this.ShowPageSelector)
            {
                // Set current node id for new project
                if (isNew && (CMSContext.CurrentDocument != null))
                {
                    this.ProjectObj.ProjectNodeID = CMSContext.CurrentDocument.NodeID;
                }
            }
            else
            {
                TreeProvider treeProvider = new TreeProvider();
                TreeNode     node         = treeProvider.SelectSingleNode(ValidationHelper.GetGuid(this.pageSelector.Value, Guid.Empty), TreeProvider.ALL_CULTURES, CMSContext.CurrentSiteName);
                if (node != null)
                {
                    this.ProjectObj.ProjectNodeID = node.NodeID;
                }
                else
                {
                    this.ProjectObj.ProjectNodeID = 0;
                }
            }

            // Use try/catch due to license check
            try
            {
                // Save object data to database
                ProjectInfoProvider.SetProjectInfo(this.ProjectObj);
                this.ProjectID = this.ProjectObj.ProjectID;

                this.ItemID = this.ProjectObj.ProjectID;
                this.RaiseOnSaved();

                // Set the info message
                this.lblInfo.Text = GetString("general.changessaved");
                return(true);
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text    = ex.Message;
            }
        }
        return(false);
    }