Beispiel #1
0
        public void test()
        {
            WeekEnum sunday = WeekEnum.Sunday;

            //枚举类型转换其他类型

            //枚举类型 -> 字符串整数
            Assert.AreEqual(
                "1",
                Enum.Format(typeof(WeekEnum), WeekEnum.Sunday, "d")
                );

            Assert.AreEqual(
                "1",
                sunday.ToString("D")
                );
            //error 格式字符串只能是“G”、“g”、“X”、“x”、“F”、“f”、“D”或“d”
            //Assert.AreEqual("01",sunday.ToString("D2"));

            //枚举类型 --> 整数
            Assert.AreEqual(
                1,
                (int)WeekEnum.Sunday
                );

            //枚举类型 -> 字符串
            Assert.AreEqual(
                "Sunday",
                Enum.GetName(typeof(WeekEnum), sunday)
                );

            Assert.AreEqual(
                "Sunday",
                sunday.ToString()
                );

            //其他类型转枚举类型

            //字符串 -> 枚举类型
            Assert.AreEqual(
                WeekEnum.Sunday,
                Enum.Parse(typeof(WeekEnum), "Sunday")
                );

            //字符串 -> 枚举类型
            Assert.AreEqual(
                WeekEnum.Sunday,
                Enum.Parse(typeof(WeekEnum), "1")
                );


            //获取所有值

            //GetNames 获取枚举类型的名
            Assert.AreEqual(
                "Sunday Monday Tuesday Wednesday Thursday Friday Saturday",
                string.Join(" ",
                            Enum.GetNames(typeof(WeekEnum))
                            )
                );

            //获取所有的值
            Assert.AreEqual(
                WeekEnum.Sunday,
                Enum.GetValues(typeof(WeekEnum)).GetValue(0)
                );
        }
Beispiel #2
0
        public static TrainingScheduleSViewtructure CreateTrainingScheduleSViewtructure(WeekEnum week)
        {
            var model = TrainingScheduleService.GetTrainingSchedule((int)week);

            if (model == null)
            {
                var empty = new TrainingScheduleSViewtructure
                {
                    Week     = (int)week,
                    WeekName = week.ToString(),
                    Off      = false
                };
                return(empty);
            }

            var trainingScheduleStructure =
                JsonConvert.DeserializeObject <TrainingScheduleStructure>(model.TrainingMenu);

            var trainingScheduleViewStructure = new TrainingScheduleSViewtructure
            {
                Week     = (int)week,
                WeekName = week.ToString(),
                Off      = trainingScheduleStructure.Off
            };

            var trainingListViewStructureList = new List <TrainingListViewStructure>();

            int count = 1;

            foreach (var training in trainingScheduleStructure.TrainingContentList)
            {
                var trainingListViewStructure = new TrainingListViewStructure
                {
                    TrainingId       = training.TrainingId,
                    TrainingNo       = count,
                    TrainingName     = TrainingMasterService.GetTrainingMasterData(training.TrainingId).TrainingName,
                    TrainingSetCount = training.TrainingSetCount
                };
                var loadContentViewStructureList = new List <LoadContentViewStructure>();

                foreach (var load in training.LoadContentList)
                {
                    var loadContentViewStructure = new LoadContentViewStructure
                    {
                        LoadId       = load.LoadId,
                        LoadName     = LoadService.GetLoad(load.LoadId).LoadName,
                        Nums         = load.Nums.ToString(),
                        LoadUnitId   = load.LoadUnitId,
                        LoadUnitName = LoadUnitService.GetLoadUnit(load.LoadUnitId).UnitName
                    };
                    loadContentViewStructureList.Add(loadContentViewStructure);
                }

                trainingListViewStructure.LoadContentList = loadContentViewStructureList;

                trainingListViewStructureList.Add(trainingListViewStructure);
                count++;
            }

            trainingScheduleViewStructure.TrainingContentList = trainingListViewStructureList;

            return(trainingScheduleViewStructure);
        }