Exemplo n.º 1
0
    protected void SegregateProperties(bool fStripDefault = false)
    {
        List <CustomPropertyType> lstRemainingProps = new List <CustomPropertyType>();

        ActiveProperties.Clear();
        ActivePropTypes.Clear();

        PropertyTemplate ptMerged = PropertyTemplate.MergedTemplate(ActiveTemplates);

        // this is cached so we can do it on every call, postback or not
        CustomPropertyType[] rgCptAll = CustomPropertyType.GetCustomPropertyTypes(Page.User.Identity.IsAuthenticated ? Username : string.Empty);

        foreach (CustomPropertyType cpt in rgCptAll)
        {
            // see if this either has a value or is in one of the active templates.
            // if it doesn't have a value but is in a template, give it a value.
            CustomFlightProperty fp = Properties.Find(cfp => cfp.PropTypeID == cpt.PropTypeID);

            // To be included, it must be EITHER
            // a) in the merged set of templates OR
            // b) in the set of properties with a non-default value (fp != null && !fp.IsDefaultValue) OR
            // c) in the set of properties with a default value (fp != null && (!fStripDefault && fp.IsDefaultValue)
            bool fInclude = ptMerged.ContainsProperty(cpt.PropTypeID) || (fp != null && (!fStripDefault || !fp.IsDefaultValue));
            if (fp == null)
            {
                fp = new CustomFlightProperty(cpt);
            }

            if (!fInclude)
            {
                lstRemainingProps.Add(cpt);
            }
            else
            {
                ActiveProperties.Add(fp);
                ActivePropTypes.Add(fp.PropTypeID);
            }
        }

        ActiveProperties.Sort((cfp1, cfp2) => { return(cfp1.PropertyType.SortKey.CompareCurrentCultureIgnoreCase(cfp2.PropertyType.SortKey)); });

        ListItem li = cmbPropsToAdd.Items[0];

        cmbPropsToAdd.Items.Clear();
        cmbPropsToAdd.Items.Add(li);
        cmbPropsToAdd.SelectedValue = string.Empty;    // reset the selection
        cmbPropsToAdd.DataSource    = lstRemainingProps;
        cmbPropsToAdd.DataBind();
    }
    protected void SegregateProperties()
    {
        List <CustomPropertyType> lstRemainingProps = new List <CustomPropertyType>();

        ActiveProperties.Clear();
        ActivePropTypes.Clear();

        // this is cached so we can do it on every call, postback or not
        CustomPropertyType[] rgCptAll = CustomPropertyType.GetCustomPropertyTypes(Page.User.Identity.IsAuthenticated ? Page.User.Identity.Name : string.Empty);

        foreach (CustomPropertyType cpt in rgCptAll)
        {
            CustomFlightProperty fp = Properties.Find(cfp => cfp.PropTypeID == cpt.PropTypeID);
            if (fp == null && cpt.IsFavorite)
            {
                fp = new CustomFlightProperty(cpt);
            }
            if (fp == null)
            {
                lstRemainingProps.Add(cpt);
            }
            else
            {
                ActiveProperties.Add(fp);
                ActivePropTypes.Add(fp.PropTypeID);
            }
        }

        ActiveProperties.Sort((cfp1, cfp2) => { return(cfp1.PropertyType.SortKey.CompareCurrentCultureIgnoreCase(cfp2.PropertyType.SortKey)); });

        ListItem li = cmbPropsToAdd.Items[0];

        cmbPropsToAdd.Items.Clear();
        cmbPropsToAdd.Items.Add(li);
        cmbPropsToAdd.SelectedValue = string.Empty;    // reset the selection
        cmbPropsToAdd.DataSource    = lstRemainingProps;
        cmbPropsToAdd.DataBind();
    }