コード例 #1
0
 /// <summary>
 /// Sets the color AttributeId used for updating attributes for setting colors with stages
 /// </summary>
 private void SetColorAttributeId()
 {
     if (!Page.IsPostBack)
     {
         LookupCodeDa da             = new LookupCodeDa();
         DataView     colorAttibutes = da.GetLookupAttributeByName("Color").DefaultView;
         if (colorAttibutes.Count > 0)
         {
             int attId = int.Parse(colorAttibutes[0][LookupAttribute.AttributeId].ToString());
             ColorAttributeId.Value = attId.ToString();
             int attributeId = int.Parse(ColorAttributeId.Value);
             stageColorCodeAttributes = da.GetLookupCodeAttributesByAttributeId(attributeId);
         }
     }
     else
     {
         int attributeId = int.Parse(ColorAttributeId.Value);
         stageColorCodeAttributes = da.GetLookupCodeAttributesByAttributeId(attributeId);
     }
 }
コード例 #2
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);
                    }
                }
            }
        }