public IEnumerable <LookupMask> CreateLookupMask(LookupTableModel model)
        {
            LookupTableMaskSequence maskType = LookupTableMaskSequence.CHARACTERS;

            switch (model.Type.ToLower())
            {
            case "text":
                maskType = LookupTableMaskSequence.CHARACTERS;
                break;

            case "number":
                maskType = LookupTableMaskSequence.NUMBER_DECIMAL;
                break;

            case "cost":
                maskType = LookupTableMaskSequence.COST;
                break;

            case "duration":
                maskType = LookupTableMaskSequence.DURATION;
                break;

            case "date":
                maskType = LookupTableMaskSequence.DATE;
                break;

            default:
                throw new ArgumentException("The type of lookup table is illegal.");
            }

            List <LookupMask> lstLookupMask = new List <LookupMask>();

            if (model.Type.ToLower() == "text")
            {
                for (int i = 0; i < model.OutlineLevels; i++)
                {
                    LookupMask mask = new LookupMask()
                    {
                        MaskType  = maskType,
                        Separator = ".",
                    };
                    lstLookupMask.Add(mask);
                }
            }
            else
            {
                LookupMask mask = new LookupMask()
                {
                    Length    = 0,
                    Separator = ".",
                    MaskType  = maskType
                };
                lstLookupMask.Add(mask);
            }
            return(lstLookupMask);
        }
Example #2
0
        private void CreateLookupTables()
        {
            for (int lookupTableCount = 1; lookupTableCount <= Convert.ToInt32(NUD_LTNumber.Value); lookupTableCount++)
            {
                List <LookupMask> masks = new List <LookupMask>();
                for (int levelCount = 0; levelCount <= Convert.ToInt32(NUD_Levels.Value); levelCount++)
                {
                    LookupMask lkm = new LookupMask
                    {
                        Length    = 0,
                        MaskType  = LookupTableMaskSequence.CHARACTERS,
                        Separator = "."
                    };
                    masks.Add(lkm);
                }

                List <LookupEntryCreationInformation> lookupEntry = new List <LookupEntryCreationInformation>();
                for (int levelCount = 1; levelCount <= Convert.ToInt32(NUD_Levels.Value); levelCount++)
                {
                    //creating the parent level
                    LookupEntryCreationInformation parentCi = new LookupEntryCreationInformation
                    {
                        Id        = Guid.NewGuid(),
                        SortIndex = 0,
                        Value     =
                            new LookupEntryValue {
                            TextValue = RandomEx.RandomString(Convert.ToInt32(NUD_Length.Value))
                        }
                    };
                    lookupEntry.Add(parentCi);

                    //creating the child levels
                    for (int subLevel = 1; subLevel <= Convert.ToInt32(NUD_ValuePerLevel.Value); subLevel++)
                    {
                        LookupEntryCreationInformation childCi = new LookupEntryCreationInformation
                        {
                            Id        = Guid.NewGuid(),
                            ParentId  = parentCi.Id,
                            SortIndex = 0,
                            Value     =
                                new LookupEntryValue
                            {
                                TextValue = RandomEx.RandomString(Convert.ToInt32(NUD_Length.Value))
                            }
                        };
                        lookupEntry.Add(childCi);
                    }
                }

                LookupTableSortOrder lookupTableSortOrder = LookupTableSortOrder.Ascending;
                CB_Sort.InvokeIfRequired(cb => lookupTableSortOrder = (LookupTableSortOrder)cb.SelectedValue);

                LookupTableCreationInformation ltCi = new LookupTableCreationInformation
                {
                    Name      = TB_Name.Text + lookupTableCount,
                    Masks     = masks,
                    SortOrder = lookupTableSortOrder,
                    Entries   = lookupEntry
                };
                Log.WriteVerbose(new SourceInfo(), TB_Status, "Creating lookup field with name {0}", ltCi.Name);
                ProjContext.LookupTables.Add(ltCi);
            }
            ProjContext.LookupTables.Update();
            ProjContext.ExecuteQuery();
        }
        private void CreateLookupTables()
        {
            for (int lookupTableCount = 1; lookupTableCount <= Convert.ToInt32(NUD_LTNumber.Value); lookupTableCount++)
            {
                List<LookupMask> masks = new List<LookupMask>();
                for (int levelCount = 0; levelCount <= Convert.ToInt32(NUD_Levels.Value); levelCount++)
                {
                    LookupMask lkm = new LookupMask
                    {
                        Length = 0,
                        MaskType = LookupTableMaskSequence.CHARACTERS,
                        Separator = "."
                    };
                    masks.Add(lkm);
                }

                List<LookupEntryCreationInformation> lookupEntry = new List<LookupEntryCreationInformation>();
                for (int levelCount = 1; levelCount <= Convert.ToInt32(NUD_Levels.Value); levelCount++)
                {
                    //creating the parent level
                    LookupEntryCreationInformation parentCi = new LookupEntryCreationInformation
                    {
                        Id = Guid.NewGuid(),
                        SortIndex = 0,
                        Value =
                            new LookupEntryValue { TextValue = RandomEx.RandomString(Convert.ToInt32(NUD_Length.Value)) }
                    };
                    lookupEntry.Add(parentCi);

                    //creating the child levels
                    for (int subLevel = 1; subLevel <= Convert.ToInt32(NUD_ValuePerLevel.Value); subLevel++)
                    {
                        LookupEntryCreationInformation childCi = new LookupEntryCreationInformation
                        {
                            Id = Guid.NewGuid(),
                            ParentId = parentCi.Id,
                            SortIndex = 0,
                            Value =
                                new LookupEntryValue
                                {
                                    TextValue = RandomEx.RandomString(Convert.ToInt32(NUD_Length.Value))
                                }
                        };
                        lookupEntry.Add(childCi);
                    }
                }

                LookupTableSortOrder lookupTableSortOrder = LookupTableSortOrder.Ascending;
                CB_Sort.InvokeIfRequired(cb => lookupTableSortOrder = (LookupTableSortOrder)cb.SelectedValue);

                LookupTableCreationInformation ltCi = new LookupTableCreationInformation
                {
                    Name = TB_Name.Text + lookupTableCount,
                    Masks = masks,
                    SortOrder = lookupTableSortOrder,
                    Entries = lookupEntry
                };
                Log.WriteVerbose(new SourceInfo(), TB_Status, "Creating lookup field with name {0}", ltCi.Name);
                ProjContext.LookupTables.Add(ltCi);
            }
            ProjContext.LookupTables.Update();
            ProjContext.ExecuteQuery();
        }