Ejemplo n.º 1
0
        public static async Task <Dimension> GetNewDimension()
        {
            AddDimension d  = new AddDimension();
            var          vm = new AddDimensionViewModel();

            d.DataContext = vm;

            var result = d.ShowDialog();

            if (result ?? true)
            {
                switch (vm.DimensionType)
                {
                case DimensionType.Names:
                    return(await GetNamesDimension(vm));

                case DimensionType.Date:
                    return(GetDateDimension(vm));

                case DimensionType.Id:
                    return(GetIdDimension(vm));
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        static Dimension GetIdDimension(AddDimensionViewModel vm)
        {
            Dimension dim = new Dimension(vm.DimensionName);

            DataTable dt = dim.DataTable = new DataTable();

            if (vm.Name)
            {
                dt.Columns.Add("id");
            }


            dt.BeginLoadData();

            for (int from = vm.fromId; from < vm.toId; from++)
            {
                var row = dt.NewRow();
                row["id"] = from;
                dt.Rows.Add(row);
            }

            dt.EndLoadData();

            return(dim);
        }
Ejemplo n.º 3
0
        static async Task <Dimension> GetNamesDimension(AddDimensionViewModel vm)
        {
            List <NameEntry> names = await GetRandomNames(vm.NamesCount);

            if (names == null || names.Count == 0)
            {
                return(null);
            }

            Dimension dim = new Dimension(vm.DimensionName);

            DataTable dt = dim.DataTable = new DataTable();

            if (vm.Name)
            {
                dt.Columns.Add("Имя");
            }
            if (vm.SurName)
            {
                dt.Columns.Add("Фамилия");
            }
            if (vm.Gender)
            {
                dt.Columns.Add("Пол");
            }
            if (vm.FullName)
            {
                dt.Columns.Add("Полное имя");
            }
            if (vm.UID)
            {
                dt.Columns.Add("UID");
            }

            dt.BeginLoadData();

            foreach (var name in names)
            {
                var row = dt.NewRow();
                if (vm.Name)
                {
                    row["Имя"] = name.Name;
                }
                if (vm.SurName)
                {
                    row["Фамилия"] = name.SurName;
                }
                if (vm.Gender)
                {
                    row["Пол"] = name.Gender.ToString();
                }
                if (vm.FullName)
                {
                    row["Полное имя"] = name.FullName;
                }
                if (vm.UID)
                {
                    row["UID"] = System.Guid.NewGuid().ToString("N").ToUpper();
                }

                dt.Rows.Add(row);
            }

            dt.EndLoadData();

            return(dim);
        }
Ejemplo n.º 4
0
        static Dimension GetDateDimension(AddDimensionViewModel vm)
        {
            //set starting params
            DateTime from = vm.DateFrom;
            DateTime to   = vm.DateTo;
            Func <DateTime, DateTime> IncDate = (ind) => ind.AddDays(1);

            Dimension dim = new Dimension(vm.DimensionName);
            DataTable dt  = dim.DataTable = new DataTable();

            DateFields df = vm.DateFields;

            //add field to table for each selected field
            foreach (string fieldName in Enum.GetNames(typeof(DateFields)))
            {
                var field = (DateFields)Enum.Parse(typeof(DateFields), fieldName);
                if (df.HasFlag(field) && field != DateFields.None)
                {
                    dt.Columns.Add(fieldName);
                }
            }

            //set start and end dates
            switch (vm.DateLevel)
            {
            case DateDetailLevel.Month:
                from    = new DateTime(from.Year, from.Month, 1);
                to      = new DateTime(to.Year, to.Month, 1);
                IncDate = (ind) => ind.AddMonths(1);
                break;

            case DateDetailLevel.Year:
                from    = new DateTime(from.Year, 1, 1);
                to      = new DateTime(to.Year, 1, 1);
                IncDate = (ind) => ind.AddYears(1);
                break;
            }

            //create records and fill with values
            dt.BeginLoadData();
            while (from < to)
            {
                var row = dt.NewRow();

                if (df.HasFlag(DateFields.DateKey))
                {
                    row["DateKey"] = from.ToShortDateString();
                }
                if (df.HasFlag(DateFields.DayNum))
                {
                    row["DayNum"] = from.Day;
                }
                if (df.HasFlag(DateFields.MonthNum))
                {
                    row["MonthNum"] = from.Month;
                }
                if (df.HasFlag(DateFields.YearNum))
                {
                    row["YearNum"] = from.Year;
                }

                dt.Rows.Add(row);

                from = IncDate(from);
            }
            dt.EndLoadData();

            return(dim);
        }