Esempio n. 1
0
        private void BindValues()
        {
            ddlTemplate.DataSource     = ProjectTemplate.GetListProjectTemplate();
            ddlTemplate.DataTextField  = "TemplateName";
            ddlTemplate.DataValueField = "TemplateId";
            ddlTemplate.DataBind();
            ddlTemplate.Items.Insert(0, new ListItem(LocRM.GetString("NotSet"), "0"));
            if (Request["TemplateId"] != null)
            {
                CommonHelper.SafeSelect(ddlTemplate, Request["TemplateId"].ToString());
            }

            ddlStatus.DataSource     = Project.GetListProjectStatus();
            ddlStatus.DataTextField  = "StatusName";
            ddlStatus.DataValueField = "StatusId";
            ddlStatus.DataBind();

            ddPrjPhases.DataSource     = Project.GetListProjectPhases();
            ddPrjPhases.DataTextField  = "PhaseName";
            ddPrjPhases.DataValueField = "PhaseId";
            ddPrjPhases.DataBind();

            ddInitialPhase.DataSource     = Project.GetListProjectPhases();
            ddInitialPhase.DataTextField  = "PhaseName";
            ddInitialPhase.DataValueField = "PhaseId";
            ddInitialPhase.DataBind();

            ddlType.DataValueField = "TypeId";
            ddlType.DataTextField  = "TypeName";
            ddlType.DataSource     = Project.GetListProjectTypes();
            ddlType.DataBind();

            ddlBlockType.DataTextField  = "Title";
            ddlBlockType.DataValueField = "primaryKeyId";
            ddlBlockType.DataSource     = Mediachase.IbnNext.TimeTracking.TimeTrackingBlockType.List(Mediachase.Ibn.Data.FilterElement.EqualElement("IsProject", "1"));
            ddlBlockType.DataBind();

            ddlOverallStatus.Items.Clear();
            for (int i = 0; i <= 100; i++)
            {
                ddlOverallStatus.Items.Add(new ListItem(i.ToString() + " %", i.ToString()));
            }

            BindGeneralCategories();
            BindProjectCategories();
            BindPortfolios();

            ddlCalendar.DataTextField  = "CalendarName";
            ddlCalendar.DataValueField = "CalendarId";
            ddlCalendar.DataSource     = Project.GetListCalendars(PID);
            ddlCalendar.DataBind();

            ddlPriority.DataTextField  = "PriorityName";
            ddlPriority.DataValueField = "PriorityId";
            ddlPriority.DataSource     = Project.GetListPriorities();
            ddlPriority.DataBind();

            ddlRiskLevel.DataTextField  = "RiskLevelName";
            ddlRiskLevel.DataValueField = "RiskLevelId";
            ddlRiskLevel.DataSource     = Project.GetListRiskLevels();
            ddlRiskLevel.DataBind();

            dtcTargetStartDate.SelectedDate = UserDateTime.UserToday;
            dtcTargetEndDate.SelectedDate   = UserDateTime.UserToday.AddMonths(1);

            ddCurrency.DataTextField  = "CurrencySymbol";
            ddCurrency.DataValueField = "CurrencyId";
            ddCurrency.DataSource     = Project.GetListCurrency();
            ddCurrency.DataBind();

            // Managers
            ListItem  li;
            ArrayList alManagers = new ArrayList();

            using (IDataReader iManagers = SecureGroup.GetListAllUsersInGroup((int)InternalSecureGroups.ProjectManager))
            {
                while (iManagers.Read())
                {
                    li = new ListItem(iManagers["LastName"].ToString() + " " + iManagers["FirstName"].ToString(), iManagers["UserId"].ToString());
                    alManagers.Add(li);
                }
            }

            if (Security.IsUserInGroup(InternalSecureGroups.PowerProjectManager))
            {
                int CurrentUserID = Security.UserID;
                for (int i = 0; i < alManagers.Count; i++)
                {
                    ddlManager.Items.Add((ListItem)alManagers[i]);
                }

                li = ddlManager.Items.FindByValue(CurrentUserID.ToString());
                if (li != null)
                {
                    li.Selected = true;
                }
            }
            else
            {
                lblManager.Visible = true;
                ddlManager.Visible = false;
                lblManager.Text    = CommonHelper.GetUserStatus((Security.CurrentUser.UserID));
                iManagerId.Value   = Security.CurrentUser.UserID.ToString();
            }

            // Exec Managers
            li = new ListItem(LocRM.GetString("NotSet"), "0");
            ddlExecManager.Items.Add(li);

            using (IDataReader iManagers = SecureGroup.GetListAllUsersIn2Group((int)InternalSecureGroups.ProjectManager, (int)InternalSecureGroups.ExecutiveManager))
            {
                while (iManagers.Read())
                {
                    ddlExecManager.Items.Add(new ListItem(iManagers["LastName"].ToString() + " " + iManagers["FirstName"].ToString(), iManagers["UserId"].ToString()));
                }
            }


            if (PID != 0)
            {
                //				ddlBlockType.Enabled = false;

                using (IDataReader reader = Project.GetProject(PID))
                {
                    if (reader.Read())
                    {
                        if (reader["OrgUid"] != DBNull.Value)
                        {
                            ClientControl.ObjectType = OrganizationEntity.GetAssignedMetaClassName();
                            ClientControl.ObjectId   = PrimaryKeyId.Parse(reader["OrgUid"].ToString());
                        }
                        else if (reader["ContactUid"] != DBNull.Value)
                        {
                            ClientControl.ObjectType = ContactEntity.GetAssignedMetaClassName();
                            ClientControl.ObjectId   = PrimaryKeyId.Parse(reader["ContactUid"].ToString());
                        }

                        txtTitle.Text        = HttpUtility.HtmlDecode(reader["Title"].ToString());
                        txtGoals.Text        = HttpUtility.HtmlDecode(reader["Goals"].ToString());
                        txtScope.Text        = HttpUtility.HtmlDecode(reader["Scope"].ToString());
                        txtDescription.Text  = HttpUtility.HtmlDecode(reader["Description"].ToString());
                        txtDeliverables.Text = HttpUtility.HtmlDecode(reader["Deliverables"].ToString());

                        CommonHelper.SafeSelect(ddlType, reader["TypeId"].ToString());
                        CommonHelper.SafeSelect(ddlCalendar, reader["CalendarId"].ToString());
                        CommonHelper.SafeSelect(ddCurrency, reader["CurrencyId"].ToString());
                        CommonHelper.SafeSelect(ddlPriority, reader["PriorityId"].ToString());
                        CommonHelper.SafeSelect(ddlRiskLevel, reader["RiskLevelId"].ToString());
                        CommonHelper.SafeSelect(ddlOverallStatus, reader["PercentCompleted"].ToString());
                        if (reader["BlockTypeId"] != DBNull.Value)
                        {
                            CommonHelper.SafeSelect(ddlBlockType, reader["BlockTypeId"].ToString());
                        }

                        ddlExecManager.Items.FindByText(LocRM.GetString("NotSet")).Selected = true;
                        if (reader["ExecutiveManagerId"] != DBNull.Value)
                        {
                            string str = "";
                            str = reader["ExecutiveManagerId"].ToString();
                            ListItem liExec = ddlExecManager.Items.FindByValue(reader["ExecutiveManagerId"].ToString());
                            if (liExec != null)
                            {
                                ddlExecManager.ClearSelection();
                                liExec.Selected = true;
                            }
                        }

                        if (reader["ManagerId"] != DBNull.Value)
                        {
                            if (ddlManager.Visible)
                            {
                                ListItem liClient = ddlManager.Items.FindByValue(reader["ManagerId"].ToString());
                                if (liClient != null)
                                {
                                    ddlManager.ClearSelection();
                                    liClient.Selected = true;
                                }
                            }
                            else
                            {
                                int iManager = (int)reader["ManagerId"];
                                iManagerId.Value = iManager.ToString();
                                lblManager.Text  = CommonHelper.GetUserStatus(iManager);
                            }
                        }
                        if (reader["StatusId"] != DBNull.Value)
                        {
                            ListItem liStatus = ddlStatus.Items.FindByValue(reader["StatusId"].ToString());
                            if (liStatus != null)
                            {
                                ddlStatus.ClearSelection();
                                liStatus.Selected = true;
                            }
                        }

                        if (reader["PhaseId"] != DBNull.Value)
                        {
                            ListItem liPhase = ddPrjPhases.Items.FindByValue(reader["PhaseId"].ToString());
                            if (liPhase != null)
                            {
                                ddPrjPhases.ClearSelection();
                                liPhase.Selected = true;
                            }
                        }

                        if (reader["InitialPhaseId"] != DBNull.Value)
                        {
                            ListItem liPhase = ddInitialPhase.Items.FindByValue(reader["InitialPhaseId"].ToString());
                            if (liPhase != null)
                            {
                                ddInitialPhase.ClearSelection();
                                liPhase.Selected = true;
                            }
                        }

                        dtcTargetStartDate.SelectedDate = (DateTime)reader["TargetStartDate"];
                        dtcTargetEndDate.SelectedDate   = (DateTime)reader["TargetFinishDate"];

                        if (reader["ActualStartDate"] != DBNull.Value && reader["ActualStartDate"].ToString() != "")
                        {
                            dtcActualStartDate.SelectedDate = (DateTime)reader["ActualStartDate"];
                        }
                        if (reader["ActualFinishDate"] != DBNull.Value && reader["ActualFinishDate"].ToString() != "")
                        {
                            dtcActualFinishDate.SelectedDate = (DateTime)reader["ActualFinishDate"];
                        }
                    }
                }

                using (IDataReader reader = Project.GetListCategories(PID))
                {
                    while (reader.Read())
                    {
                        for (int i = 0; i < lbCategory.Items.Count; i++)
                        {
                            ListItem lItem = lbCategory.Items.FindByText(reader["CategoryName"].ToString());
                            if (lItem != null)
                            {
                                lItem.Selected = true;
                            }
                        }
                    }
                }

                using (IDataReader reader = Project.GetListProjectCategoriesByProject(PID))
                {
                    while (reader.Read())
                    {
                        for (int i = 0; i < lbProjectCategory.Items.Count; i++)
                        {
                            ListItem lItem = lbProjectCategory.Items.FindByText(reader["CategoryName"].ToString());
                            if (lItem != null)
                            {
                                lItem.Selected = true;
                            }
                        }
                    }
                }

                using (IDataReader reader = ProjectGroup.ProjectGroupsGetByProject(PID))
                {
                    while (reader.Read())
                    {
                        for (int i = 0; i < lbPortfolios.Items.Count; i++)
                        {
                            ListItem lItem = lbPortfolios.Items.FindByValue(reader["ProjectGroupId"].ToString());
                            if (lItem != null)
                            {
                                lItem.Selected = true;
                            }
                        }
                    }
                }
            }
            else
            {
                // Client
                PrimaryKeyId org_id     = PrimaryKeyId.Empty;
                PrimaryKeyId contact_id = PrimaryKeyId.Empty;
                Common.GetDefaultClient(PortalConfig.ProjectDefaultValueClientField, out contact_id, out org_id);
                if (contact_id != PrimaryKeyId.Empty)
                {
                    ClientControl.ObjectType = ContactEntity.GetAssignedMetaClassName();
                    ClientControl.ObjectId   = contact_id;
                }
                else if (org_id != PrimaryKeyId.Empty)
                {
                    ClientControl.ObjectType = OrganizationEntity.GetAssignedMetaClassName();
                    ClientControl.ObjectId   = org_id;
                }

                // Priority
                Util.CommonHelper.SafeSelect(ddlPriority, PortalConfig.ProjectDefaultValuePriorityField);

                // Currency
                Util.CommonHelper.SafeSelect(ddCurrency, PortalConfig.ProjectDefaultValueCurrencyField);

                // Categories
                ArrayList list = Common.StringToArrayList(PortalConfig.ProjectDefaultValueGeneralCategoriesField);
                foreach (int i in list)
                {
                    CommonHelper.SafeMultipleSelect(lbCategory, i.ToString());
                }
                list = Common.StringToArrayList(PortalConfig.ProjectDefaultValueProjectCategoriesField);
                foreach (int i in list)
                {
                    CommonHelper.SafeMultipleSelect(lbProjectCategory, i.ToString());
                }

                // texts
                txtGoals.Text        = PortalConfig.ProjectDefaultValueGoalsField;
                txtDeliverables.Text = PortalConfig.ProjectDefaultValueDeliverablesField;
                txtScope.Text        = PortalConfig.ProjectDefaultValueScopeField;
            }

            if (PID > 0)
            {
                EditControl.ObjectId = PID;
            }
            EditControl.MetaClassName = String.Concat("ProjectsEx_", ddlType.SelectedValue);
            EditControl.BindData();

            trPriority.Visible          = PortalConfig.CommonProjectAllowEditPriorityField;
            trClient.Visible            = PortalConfig.CommonProjectAllowEditClientField;
            trCategories.Visible        = PortalConfig.CommonProjectAllowEditGeneralCategoriesField;
            trProjectCategories.Visible = PortalConfig.ProjectAllowEditProjectCategoriesField;
            GoalsRow.Visible            = PortalConfig.ProjectAllowEditGoalsField;
            DeleverablesRow.Visible     = PortalConfig.ProjectAllowEditDeliverablesField;
            ScopeRow.Visible            = PortalConfig.ProjectAllowEditScopeField;
            LeftTextCell.Visible        = GoalsRow.Visible || DeleverablesRow.Visible;
        }