Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new stage record
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void CreateOrganizationStageRecord(object sender, EventArgs e)
        {
            CaisisCheckBox eventCheckBox = sender as CaisisCheckBox;

            // Only need to save if checked
            if (eventCheckBox.Checked)
            {
                ProjectStage biz = new ProjectStage();

                RepeaterItem rptrItem       = eventCheckBox.NamingContainer as RepeaterItem;
                HiddenField  orgIdField     = rptrItem.FindControl("OrgIdField") as HiddenField;
                HiddenField  stageIdField   = rptrItem.FindControl("OrgStageIdField") as HiddenField;
                HiddenField  projectStageId = rptrItem.NamingContainer.NamingContainer.FindControl("ProjectStageId") as HiddenField;
                Label        sName          = rptrItem.NamingContainer.NamingContainer.FindControl("StageLabel") as Label;
                HiddenField  sColor         = rptrItem.NamingContainer.NamingContainer.FindControl("StageColor") as HiddenField;
                // Only save a new stage record if one doesn't exist
                if (string.IsNullOrEmpty(stageIdField.Value))
                {
                    int    orgId       = int.Parse(orgIdField.Value);
                    int    projStageId = int.Parse(projectStageId.Value);
                    string stageName   = sName.Text;

                    ProjectStage stageBiz = new ProjectStage();
                    stageBiz[ProjectStage.ProjectId]      = projectId;
                    stageBiz[ProjectStage.OrganizationId] = orgId;
                    stageBiz[ProjectStage.Name]           = stageName;
                    stageBiz[ProjectStage.ColorCode]      = sColor.Value;
                    stageBiz.Save();

                    int orgStageId = int.Parse(stageBiz[ProjectStage.StageId].ToString());
                    stageIdField.Value = orgStageId.ToString();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the Stage record as well as child events and their atttibutes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void UpdateStageRecord(object sender, EventArgs e)
        {
            // Register script must be called here, as no stage id has been assinged,i.e., new record
            RegisterUpdateScript(sender, e);

            // Determine if an insert/update
            ProjectStage stageBiz = new ProjectStage();

            // Only do update/insert on Stage record if dirty
            if (recordIsDirty)
            {
                if (recordIsDirty && !string.IsNullOrEmpty(StageId.Value))
                {
                    stageBiz.Get(int.Parse(StageId.Value));
                }
                // Set stage fields
                stageBiz[ProjectStage.ProjectId] = projectId;
                if (!string.IsNullOrEmpty(OrganizationId))
                {
                    stageBiz[ProjectStage.OrganizationId] = OrganizationId;
                }
                stageBiz[ProjectStage.Name]      = StageName.Value;
                stageBiz[ProjectStage.ColorCode] = ColorCode.Value;
                stageBiz.Save();

                string bizStageId = stageBiz[ProjectStage.StageId].ToString();
                StageId.Value = bizStageId;
            }
            // Run save on Events and Details grid only if a parent stage record exits
            if (!string.IsNullOrEmpty(StageId.Value))
            {
                int stageId = int.Parse(StageId.Value);
                EventsGrid.Save(stageId);
                BindStageRecord();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates child ProjectStage, ProjectStageEvents and ProjectEventAttributes records
        /// based off of child/parent Lookup scheme.
        /// NOTE: Child records will not be created if any ProjectStage records exists.
        /// </summary>
        /// <param name="biz"></param>
        /// <param name="dt"></param>
        public static void CreateProjectStagesRecords(Project biz, DataTable dt)
        {
            // bas: Does a Project have existing children (ProjectStages)?
            var criteria = new Dictionary <string, object>()
            {
                { Project.ProjectId, (int)biz[Project.ProjectId] }
            };
            bool childRecordsExist = BusinessObject.Exists <ProjectStage>(criteria);

            //BusinessObject parentBiz = biz;
            //BusinessObject childBiz = new ProjectStage();
            //ProjectStage projectStage = new ProjectStage();
            //projectStage.GetByParent(int.Parse(biz[Project.ProjectId].ToString()));

            //if (projectStage.DataSourceView.Count == 0)

            if (!childRecordsExist)
            {
                LookupCodeDa da                = new LookupCodeDa();
                string       projectType       = biz[Project.Type].ToString();
                DataTable    projectCodes      = da.GetLookupsByFieldName("ProjectType").Tables[0];
                DataRow[]    projectTypesFound = projectCodes.Select(LookupCode.LkpCode + " = '" + projectType.Replace("'", "''") + "'");
                if (projectTypesFound.Length > 0)
                {
                    int       projectTypeLkpId = int.Parse(projectTypesFound[0][LookupCode.LookupCodeId].ToString());
                    DataRow[] stagesCodes      = da.GetChildCodesByLookupIdAndChildLookupName(projectTypeLkpId, PROJECT_STAGE_TYPE_CODE).Select("", LKP_SORT_ORDER);

                    // Get Color Attribute (should be 1 row)
                    DataTable colorAttributes  = da.GetLookupAttributeByName("Color");
                    DataTable allStagesColors  = null;
                    int       colorAttributeId = -1;
                    if (colorAttributes.Rows.Count > 0)
                    {
                        colorAttributeId = int.Parse(colorAttributes.Rows[0][LookupAttribute.AttributeId].ToString());
                        allStagesColors  = da.GetLookupCodeAttributesByAttributeId(colorAttributeId);
                    }

                    foreach (DataRow stageCode in stagesCodes)
                    {
                        ProjectStage stageBiz = new ProjectStage();
                        stageBiz[ProjectStage.ProjectId] = biz[Project.ProjectId].ToString();
                        stageBiz[ProjectStage.Name]      = stageCode[LookupCode.LkpCode].ToString();

                        // Get color atttibute for this Stage lookup code, if any
                        int stageLkpId = int.Parse(stageCode[LookupCode.LookupCodeId].ToString());
                        if (colorAttributeId > -1 && allStagesColors != null)
                        {
                            // See if there is a color attribute value for this by attribute id and lookup code id
                            DataRow[] stageColors = allStagesColors.Select(LookupCodeAttribute.AttributeId + " = " + colorAttributeId + " AND LookupCodeId = " + stageLkpId);
                            if (stageColors.Length > 0)
                            {
                                stageBiz[ProjectStage.ColorCode] = stageColors[0][LookupCodeAttribute.AttributeValue].ToString();
                            }
                        }

                        stageBiz.Save();
                        CreateProjectStageEvents(stageBiz);
                    }
                }
            }
        }