示例#1
0
        public HourStemAndBranchChart Step8(List <HourStemAndBranchChart> chart, Stems stem)
        {
            HourStemAndBranchChart hourStemAndBranchChart = new HourStemAndBranchChart();

            foreach (HourStemAndBranchChart c in chart)
            {
                if (c.DayStems.Contains(stem))
                {
                    hourStemAndBranchChart = c;
                    break;
                }
            }

            return(hourStemAndBranchChart);
        }
示例#2
0
        public BaZiCalculator(DateTime birthDate, long birthTime)
        {
            FourPillarsResult = new FourPillarsTable();
            BirthDate         = birthDate;
            BirthTime         = birthTime;
            BirthYear         = BirthDate.Year;
            BirthMonth        = BirthDate.Month;
            BirthDay          = BirthDate.Day;

            DataLoad dataLoad = new DataLoad();
            List <TwelveStageGrowthCycleChart> twelveStageGrowthCycleChart = dataLoad.LoadTwelveStageGrowthCycleChartData();
            List <ChineseCalendarChart>        chineseCalendarChart        = dataLoad.LoadChineseCalendarChartData();
            List <DayBinomialsChart>           dayBinomialsChart           = dataLoad.LoadDayBinomialsChartData();
            List <HourStemAndBranchChart>      hourStemAndBranchChart      = dataLoad.LoadHourStemAndBranchChartData();
            List <HiddenElementsChart>         hiddenElementsChart         = dataLoad.LoadHiddenElementsChartData();
            List <LeapYearMonthBinomialChart>  leapYearMonthBinomialChart  = dataLoad.LoadLeapYearMonthBinomialChartData();
            List <MonthBinomialChart>          monthBinomialChart          = dataLoad.LoadMonthBinomialChartData();
            List <StemsAndBranchesCycleOf60>   stemsAndBranchesCycleOf60   = dataLoad.LoadStemsAndBranchesCycleOf60Data();
            List <YinYangMeridianChart>        yinYangMeridianChart        = dataLoad.LoadYinYangMeridianChartData();

            //step 2
            int yearNum = chineseCalendarChart.Find((ChineseCalendarChart obj) => obj.Year.Year == BirthYear).Year.Number;

            //step 3
            FourPillarsResult.YearStem   = stemsAndBranchesCycleOf60.Find((obj) => obj.Number == yearNum).Stem;
            FourPillarsResult.YearBranch = stemsAndBranchesCycleOf60.Find((obj) => obj.Number == yearNum).Branch;

            //step 4
            int monthNum = Step4(chineseCalendarChart.Find((obj) => obj.Year.Year == BirthYear));

            //step 5
            FourPillarsResult.MonthStem   = stemsAndBranchesCycleOf60.Find((obj) => obj.Number == monthNum).Stem;
            FourPillarsResult.MonthBranch = stemsAndBranchesCycleOf60.Find((obj) => obj.Number == monthNum).Branch;

            //step 6
            int dayBinomial = Step6(dayBinomialsChart.Find((obj) => obj.Year == BirthYear), monthBinomialChart.Find((obj) => obj.Month == BirthMonth));

            //step 7
            FourPillarsResult.DayStem   = stemsAndBranchesCycleOf60.Find((obj) => obj.Number == dayBinomial).Stem;
            FourPillarsResult.DayBranch = stemsAndBranchesCycleOf60.Find((obj) => obj.Number == dayBinomial).Branch;

            //step 8
            HourStemAndBranchChart hsbc = Step8(hourStemAndBranchChart, FourPillarsResult.DayStem);

            FourPillarsResult.HourStem   = hsbc.HourStems.Find((obj) => obj.TimeOfBirth.TimeStart <= BirthTime && obj.TimeOfBirth.TimeEnd >= BirthTime).Stem;
            FourPillarsResult.HourBranch = hsbc.HourStems.Find((obj) => obj.TimeOfBirth.TimeStart <= BirthTime && obj.TimeOfBirth.TimeEnd >= BirthTime).Animal;

            //step 9
            HiddenElementsChart hiddenElements = new HiddenElementsChart();

            hiddenElements = hiddenElementsChart.Find((obj) => obj.Animal == FourPillarsResult.YearBranch);
            FourPillarsResult.YearHiddenElements = new HiddenElementsChart();
            FourPillarsResult.YearHiddenElements.HiddenElement       = hiddenElements.MainElement;
            FourPillarsResult.YearHiddenElements.HiddenElementValue  = hiddenElements.MainElementValue;
            FourPillarsResult.YearHiddenElements.HiddenElement2      = hiddenElements.HiddenElement;
            FourPillarsResult.YearHiddenElements.HiddenElement2Value = hiddenElements.HiddenElementValue;
            FourPillarsResult.YearHiddenElements.HiddenElement3      = hiddenElements.HiddenElement2;
            FourPillarsResult.YearHiddenElements.HiddenElement3Value = hiddenElements.HiddenElement2Value;

            hiddenElements = hiddenElementsChart.Find((obj) => obj.Animal == FourPillarsResult.MonthBranch);
            FourPillarsResult.MonthHiddenElements = new HiddenElementsChart();
            FourPillarsResult.MonthHiddenElements.HiddenElement       = hiddenElements.MainElement;
            FourPillarsResult.MonthHiddenElements.HiddenElementValue  = hiddenElements.MainElementValue;
            FourPillarsResult.MonthHiddenElements.HiddenElement2      = hiddenElements.HiddenElement;
            FourPillarsResult.MonthHiddenElements.HiddenElement2Value = hiddenElements.HiddenElementValue;
            FourPillarsResult.MonthHiddenElements.HiddenElement3      = hiddenElements.HiddenElement2;
            FourPillarsResult.MonthHiddenElements.HiddenElement3Value = hiddenElements.HiddenElement2Value;

            hiddenElements = hiddenElementsChart.Find((obj) => obj.Animal == FourPillarsResult.DayBranch);
            FourPillarsResult.DayHiddenElements = new HiddenElementsChart();
            FourPillarsResult.DayHiddenElements.HiddenElement       = hiddenElements.MainElement;
            FourPillarsResult.DayHiddenElements.HiddenElementValue  = hiddenElements.MainElementValue;
            FourPillarsResult.DayHiddenElements.HiddenElement2      = hiddenElements.HiddenElement;
            FourPillarsResult.DayHiddenElements.HiddenElement2Value = hiddenElements.HiddenElementValue;
            FourPillarsResult.DayHiddenElements.HiddenElement3      = hiddenElements.HiddenElement2;
            FourPillarsResult.DayHiddenElements.HiddenElement3Value = hiddenElements.HiddenElement2Value;

            hiddenElements = hiddenElementsChart.Find((obj) => obj.Animal == FourPillarsResult.HourBranch);
            FourPillarsResult.HourHiddenElements = new HiddenElementsChart();
            FourPillarsResult.HourHiddenElements.HiddenElement       = hiddenElements.MainElement;
            FourPillarsResult.HourHiddenElements.HiddenElementValue  = hiddenElements.MainElementValue;
            FourPillarsResult.HourHiddenElements.HiddenElement2      = hiddenElements.HiddenElement;
            FourPillarsResult.HourHiddenElements.HiddenElement2Value = hiddenElements.HiddenElementValue;
            FourPillarsResult.HourHiddenElements.HiddenElement3      = hiddenElements.HiddenElement2;
            FourPillarsResult.HourHiddenElements.HiddenElement3Value = hiddenElements.HiddenElement2Value;

            //step 10
            FourPillarsResult.YearStemValue  = 100;
            FourPillarsResult.MonthStemValue = 100;
            FourPillarsResult.DayStemValue   = 100;
            FourPillarsResult.HourStemValue  = 100;

            //step 11
            ElementTotals            = new ElementTotal();
            ElementTotals.WoodTotal  = Step11(FourPillarsResult, Stems.YangWood) + Step11(FourPillarsResult, Stems.YinWood);
            ElementTotals.FireTotal  = Step11(FourPillarsResult, Stems.YangFire) + Step11(FourPillarsResult, Stems.YinFire);
            ElementTotals.EarthTotal = Step11(FourPillarsResult, Stems.YangEarth) + Step11(FourPillarsResult, Stems.YinEarth);
            ElementTotals.MetalTotal = Step11(FourPillarsResult, Stems.YangMetal) + Step11(FourPillarsResult, Stems.YinMetal);
            ElementTotals.WaterTotal = Step11(FourPillarsResult, Stems.YangWater) + Step11(FourPillarsResult, Stems.YinWater);

            //step 12
            TwelveStageGrowthCycleChart twelveStage = twelveStageGrowthCycleChart.Find((obj) => obj.Wood.Animal == FourPillarsResult.MonthBranch);

            ElementTotals.WoodTotal  = ElementTotals.WoodTotal * twelveStage.Wood.Percent / 100;
            ElementTotals.FireTotal  = ElementTotals.FireTotal * twelveStage.Fire.Percent / 100;
            ElementTotals.EarthTotal = ElementTotals.EarthTotal * twelveStage.Earth.Percent / 100;
            ElementTotals.MetalTotal = ElementTotals.MetalTotal * twelveStage.Metal.Percent / 100;
            ElementTotals.WaterTotal = ElementTotals.WaterTotal * twelveStage.Water.Percent / 100;

            //step 13
            double elementTotals = ElementTotals.WoodTotal + ElementTotals.FireTotal + ElementTotals.EarthTotal + ElementTotals.MetalTotal + ElementTotals.WaterTotal;

            ElementTotals.WoodPercent  = (int)(ElementTotals.WoodTotal / elementTotals * 100);
            ElementTotals.FirePercent  = (int)(ElementTotals.FireTotal / elementTotals * 100);
            ElementTotals.EarthPercent = (int)(ElementTotals.EarthTotal / elementTotals * 100);
            ElementTotals.MetalPercent = (int)(ElementTotals.MetalTotal / elementTotals * 100);
            ElementTotals.WaterPercent = (int)(ElementTotals.WaterTotal / elementTotals * 100);

            // Step 14
            FourPillarsResult.DayMasterLabel = Step14(FourPillarsResult.DayStem);

            //step 16
            Step16(FourPillarsResult, yinYangMeridianChart);
            YinYangMeridianResult = yinYangMeridianChart;
        }
示例#3
0
        public BaZiCalculator(DateTime birthDate, long birthTime, bool noBirthTime)
        {
            FourPillarsResult = new FourPillarsTable();
            BirthDate         = birthDate;
            BirthTime         = birthTime;
            NoBirthTime       = noBirthTime;
            BirthYear         = BirthDate.Year;
            BirthMonth        = BirthDate.Month;
            BirthDay          = BirthDate.Day;

            DataLoad dataLoad = new DataLoad();
            List <TwelveStageGrowthCycleChart> twelveStageGrowthCycleChart = dataLoad.LoadTwelveStageGrowthCycleChartData();
            List <ChineseCalendarChart>        chineseCalendarChart        = dataLoad.LoadChineseCalendarChartData();
            List <DayBinomialsChart>           dayBinomialsChart           = dataLoad.LoadDayBinomialsChartData();
            List <HourStemAndBranchChart>      hourStemAndBranchChart      = dataLoad.LoadHourStemAndBranchChartData();
            List <HiddenElementsChart>         hiddenElementsChart         = dataLoad.LoadHiddenElementsChartData();
            List <LeapYearMonthBinomialChart>  leapYearMonthBinomialChart  = dataLoad.LoadLeapYearMonthBinomialChartData();
            List <MonthBinomialChart>          monthBinomialChart          = dataLoad.LoadMonthBinomialChartData();
            List <StemsAndBranchesCycleOf60>   stemsAndBranchesCycleOf60   = dataLoad.LoadStemsAndBranchesCycleOf60Data();
            List <YinYangMeridianChart>        yinYangMeridianChart        = dataLoad.LoadYinYangMeridianChartData();

            //step 2
            ChineseCalendarChart cal = chineseCalendarChart.Find((obj) => obj.Year.Year == BirthYear);
            int yearNum = 0;

            if (BirthDate < cal.MonthNumberChart[1].Month)
            {
                yearNum = chineseCalendarChart.Find((ChineseCalendarChart obj) => obj.Year.Year == BirthYear - 1).Year.Number;
            }
            else
            {
                yearNum = chineseCalendarChart.Find((ChineseCalendarChart obj) => obj.Year.Year == BirthYear).Year.Number;
            }
            //step 3
            FourPillarsResult.YearStem   = stemsAndBranchesCycleOf60.Find((obj) => obj.Number == yearNum).Stem;
            FourPillarsResult.YearBranch = stemsAndBranchesCycleOf60.Find((obj) => obj.Number == yearNum).Branch;

            //step 4



            DateTime monthDay = BirthDate;

            if (BirthDate < cal.MonthNumberChart[1].Month)
            {
                //monthDay = monthDay.AddYears(-1);
                cal = chineseCalendarChart.Find((obj) => obj.Year.Year == BirthYear - 1);
            }
            int monthNum = Step4(cal, monthDay);

            //step 5
            FourPillarsResult.MonthStem   = stemsAndBranchesCycleOf60.Find((obj) => obj.Number == monthNum).Stem;
            FourPillarsResult.MonthBranch = stemsAndBranchesCycleOf60.Find((obj) => obj.Number == monthNum).Branch;

            //step 6
            DayBinomialsChart   dbc = dayBinomialsChart.Find((obj) => obj.Year == BirthYear);
            IMonthBinomialChart bc;

            if (dbc.LeapYear)
            {
                bc = leapYearMonthBinomialChart.Find((obj) => obj.Month == BirthMonth);
            }
            else
            {
                bc = monthBinomialChart.Find((obj) => obj.Month == BirthMonth);
            }
            int dayBinomial = Step6(dbc, bc);

            //step 7
            FourPillarsResult.DayStem   = stemsAndBranchesCycleOf60.Find((obj) => obj.Number == dayBinomial).Stem;
            FourPillarsResult.DayBranch = stemsAndBranchesCycleOf60.Find((obj) => obj.Number == dayBinomial).Branch;

            //step 8
            HourStemAndBranchChart hsbc = Step8(hourStemAndBranchChart, FourPillarsResult.DayStem);
            HourStem hs = new HourStem();

            if (!NoBirthTime)
            {
                if (BirthTime < 2300 && BirthTime >= 100)
                {
                    hs = hsbc.HourStems.Find((obj) => obj.TimeOfBirth.TimeStart <= BirthTime && obj.TimeOfBirth.TimeEnd >= BirthTime);
                }
                else
                {
                    if (BirthTime >= 2300)
                    {
                        hs = hsbc.HourStems.Find((obj) => obj.TimeOfBirth.TimeStart >= 2300 && obj.TimeOfBirth.TimeEnd < 100);
                    }
                    else
                    {
                        hs = hsbc.HourStems.Find((obj) => obj.TimeOfBirth.TimeStart >= 2300 && BirthTime <= obj.TimeOfBirth.TimeEnd);
                    }
                }

                FourPillarsResult.HourStem   = hs.Stem;   // hsbc.HourStems.Find((obj) => obj.TimeOfBirth.TimeStart <= BirthTime && obj.TimeOfBirth.TimeEnd >= BirthTime).Stem;
                FourPillarsResult.HourBranch = hs.Animal; // hsbc.HourStems.Find((obj) => obj.TimeOfBirth.TimeStart <= BirthTime && obj.TimeOfBirth.TimeEnd >= BirthTime).Animal;
            }
            else
            {
                FourPillarsResult.HourStem   = Stems.Empty;
                FourPillarsResult.HourBranch = Animals.Empty;
            }
            //step 9
            HiddenElementsChart hiddenElements = new HiddenElementsChart();

            hiddenElements = hiddenElementsChart.Find((obj) => obj.Animal == FourPillarsResult.YearBranch);
            FourPillarsResult.YearHiddenElements = new HiddenElementsChart();
            FourPillarsResult.YearHiddenElements.HiddenElement       = hiddenElements.MainElement;
            FourPillarsResult.YearHiddenElements.HiddenElementValue  = hiddenElements.MainElementValue;
            FourPillarsResult.YearHiddenElements.HiddenElement2      = hiddenElements.HiddenElement;
            FourPillarsResult.YearHiddenElements.HiddenElement2Value = hiddenElements.HiddenElementValue;
            FourPillarsResult.YearHiddenElements.HiddenElement3      = hiddenElements.HiddenElement2;
            FourPillarsResult.YearHiddenElements.HiddenElement3Value = hiddenElements.HiddenElement2Value;

            hiddenElements = hiddenElementsChart.Find((obj) => obj.Animal == FourPillarsResult.MonthBranch);
            FourPillarsResult.MonthHiddenElements = new HiddenElementsChart();
            FourPillarsResult.MonthHiddenElements.HiddenElement       = hiddenElements.MainElement;
            FourPillarsResult.MonthHiddenElements.HiddenElementValue  = hiddenElements.MainElementValue;
            FourPillarsResult.MonthHiddenElements.HiddenElement2      = hiddenElements.HiddenElement;
            FourPillarsResult.MonthHiddenElements.HiddenElement2Value = hiddenElements.HiddenElementValue;
            FourPillarsResult.MonthHiddenElements.HiddenElement3      = hiddenElements.HiddenElement2;
            FourPillarsResult.MonthHiddenElements.HiddenElement3Value = hiddenElements.HiddenElement2Value;

            hiddenElements = hiddenElementsChart.Find((obj) => obj.Animal == FourPillarsResult.DayBranch);
            FourPillarsResult.DayHiddenElements = new HiddenElementsChart();
            FourPillarsResult.DayHiddenElements.HiddenElement       = hiddenElements.MainElement;
            FourPillarsResult.DayHiddenElements.HiddenElementValue  = hiddenElements.MainElementValue;
            FourPillarsResult.DayHiddenElements.HiddenElement2      = hiddenElements.HiddenElement;
            FourPillarsResult.DayHiddenElements.HiddenElement2Value = hiddenElements.HiddenElementValue;
            FourPillarsResult.DayHiddenElements.HiddenElement3      = hiddenElements.HiddenElement2;
            FourPillarsResult.DayHiddenElements.HiddenElement3Value = hiddenElements.HiddenElement2Value;

            if (!NoBirthTime)
            {
                hiddenElements = hiddenElementsChart.Find((obj) => obj.Animal == FourPillarsResult.HourBranch);
                FourPillarsResult.HourHiddenElements = new HiddenElementsChart();
                FourPillarsResult.HourHiddenElements.HiddenElement       = hiddenElements.MainElement;
                FourPillarsResult.HourHiddenElements.HiddenElementValue  = hiddenElements.MainElementValue;
                FourPillarsResult.HourHiddenElements.HiddenElement2      = hiddenElements.HiddenElement;
                FourPillarsResult.HourHiddenElements.HiddenElement2Value = hiddenElements.HiddenElementValue;
                FourPillarsResult.HourHiddenElements.HiddenElement3      = hiddenElements.HiddenElement2;
                FourPillarsResult.HourHiddenElements.HiddenElement3Value = hiddenElements.HiddenElement2Value;
            }
            //step 10
            FourPillarsResult.YearStemValue  = 100;
            FourPillarsResult.MonthStemValue = 100;
            FourPillarsResult.DayStemValue   = 100;
            FourPillarsResult.HourStemValue  = 100;

            //step 11
            ElementTotals            = new ElementTotal();
            ElementTotals.WoodTotal  = Step11(FourPillarsResult, Stems.YangWood) + Step11(FourPillarsResult, Stems.YinWood);
            ElementTotals.FireTotal  = Step11(FourPillarsResult, Stems.YangFire) + Step11(FourPillarsResult, Stems.YinFire);
            ElementTotals.EarthTotal = Step11(FourPillarsResult, Stems.YangEarth) + Step11(FourPillarsResult, Stems.YinEarth);
            ElementTotals.MetalTotal = Step11(FourPillarsResult, Stems.YangMetal) + Step11(FourPillarsResult, Stems.YinMetal);
            ElementTotals.WaterTotal = Step11(FourPillarsResult, Stems.YangWater) + Step11(FourPillarsResult, Stems.YinWater);

            //step 12
            TwelveStageGrowthCycleChart twelveStage = twelveStageGrowthCycleChart.Find((obj) => obj.Wood.Animal == FourPillarsResult.MonthBranch);

            ElementTotals.WoodTotal  = ElementTotals.WoodTotal * twelveStage.Wood.Percent / 100;
            twelveStage              = twelveStageGrowthCycleChart.Find((obj) => obj.Fire.Animal == FourPillarsResult.MonthBranch);
            ElementTotals.FireTotal  = ElementTotals.FireTotal * twelveStage.Fire.Percent / 100;
            twelveStage              = twelveStageGrowthCycleChart.Find((obj) => obj.Earth.Animal == FourPillarsResult.MonthBranch);
            ElementTotals.EarthTotal = ElementTotals.EarthTotal * twelveStage.Earth.Percent / 100;
            twelveStage              = twelveStageGrowthCycleChart.Find((obj) => obj.Metal.Animal == FourPillarsResult.MonthBranch);
            ElementTotals.MetalTotal = ElementTotals.MetalTotal * twelveStage.Metal.Percent / 100;
            twelveStage              = twelveStageGrowthCycleChart.Find((obj) => obj.Water.Animal == FourPillarsResult.MonthBranch);
            ElementTotals.WaterTotal = ElementTotals.WaterTotal * twelveStage.Water.Percent / 100;

            //step 13
            double elementTotals = ElementTotals.WoodTotal + ElementTotals.FireTotal + ElementTotals.EarthTotal + ElementTotals.MetalTotal + ElementTotals.WaterTotal;

            ElementTotals.WoodPercent  = (int)Math.Round(ElementTotals.WoodTotal / elementTotals * 100);
            ElementTotals.FirePercent  = (int)Math.Round(ElementTotals.FireTotal / elementTotals * 100);
            ElementTotals.EarthPercent = (int)Math.Round(ElementTotals.EarthTotal / elementTotals * 100);
            ElementTotals.MetalPercent = (int)Math.Round(ElementTotals.MetalTotal / elementTotals * 100);
            ElementTotals.WaterPercent = (int)Math.Round(ElementTotals.WaterTotal / elementTotals * 100);

            // Step 14
            FourPillarsResult.DayMasterLabel = Step14(FourPillarsResult.DayStem);


            //step 16
            Step16(FourPillarsResult, yinYangMeridianChart);
            YinYangMeridianResult = yinYangMeridianChart;
        }