コード例 #1
0
        private void CreateCustomFields()
        {
            EntityType      entityType          = ProjContext.EntityTypes.ProjectEntity;
            CustomFieldType customFieldType     = CustomFieldType.TEXT;
            LookupTable     selectedLookupTable = null;
            bool            allowMultiSelect    = false;

            CB_EntityType.InvokeIfRequired(cb => entityType = cb.SelectedValue as EntityType);
            CB_Type.InvokeIfRequired(sb => customFieldType  = (CustomFieldType)CB_Type.SelectedValue);
            CB_LookupTable.InvokeIfRequired(cb =>
            {
                if (cb.SelectedIndex <= 0)
                {
                    return;
                }
                selectedLookupTable = cb.SelectedValue as LookupTable;
                if (CBX_AllowMultiSelect.Checked)
                {
                    allowMultiSelect = true;
                }
            });
            for (int customFieldCount = 1; customFieldCount <= Convert.ToInt32(NUD_CFNumber.Value); customFieldCount++)
            {
                CustomFieldCreationInformation cfCi = new CustomFieldCreationInformation
                {
                    Name       = TB_Name.Text + customFieldCount,
                    EntityType = entityType,
                    FieldType  = customFieldType
                };
                Log.WriteVerbose(new SourceInfo(), TB_Status, "Creating custom field with name {0}", cfCi.Name);
                if (selectedLookupTable != null)
                {
                    cfCi.LookupTable = selectedLookupTable;
                    Log.WriteVerbose(new SourceInfo(), TB_Status, "Setting custom field to use lookup table {0}", selectedLookupTable.Name);
                }

                cfCi.LookupAllowMultiSelect = allowMultiSelect;
                ProjContext.CustomFields.Add(cfCi);
            }
            ProjContext.CustomFields.Update();
            ProjContext.ExecuteQuery();
        }
コード例 #2
0
        private void LoadLookupTables()
        {
            IEnumerable <LookupTable> lookupTables1 = ProjContext.LoadQuery(ProjContext.LookupTables);

            ProjContext.ExecuteQuery();
            Dictionary <string, LookupTable> lookupTables = new Dictionary <string, LookupTable> {
                { "Select", null }
            };

            foreach (LookupTable lt in lookupTables1)
            {
                lookupTables.Add(lt.Name, lt);
            }
            CB_LookupTable.InvokeIfRequired(cb =>
            {
                cb.DataSource    = new BindingSource(lookupTables, null);
                cb.DisplayMember = "Key";
                cb.ValueMember   = "Value";
            });
        }