Exemplo n.º 1
0
        /// <summary>
        /// 可以没有天干,但必须有地支。
        /// </summary>
        /// <param name="gan"></param>
        /// <param name="zhi"></param>
        public GanZhi(string gan, string zhi)
        {
            this.Gan = Gan.Get(gan);
            this.Zhi = Zhi.Get(zhi);

            this.ValidCheck();
        }
Exemplo n.º 2
0
        private BaZiList <GanZhi> InitBaZiFromDateTime(DateTime date, bool 确定时辰)
        {
            this.datetime = new LnDate(date);
            this.time     = 确定时辰 ? date.TimeOfDay : TimeSpan.Zero;

            GanZhi 年 = new GanZhi(this.datetime.YearGZ);
            GanZhi 月 = new GanZhi(this.datetime.MonthGZ);
            GanZhi 日 = new GanZhi(this.datetime.DayGZ);

            LnDate 明天 = this.datetime.Add(1);

            if (date.Hour >= 23)
            {
                日 = 日.Add(1);
                年 = new GanZhi(明天.YearGZ);
                月 = new GanZhi(明天.MonthGZ);
            }

            GanZhi 时 = GanZhi.Zero;

            if (确定时辰)
            {
                Zhi 时支 = Zhi.Get((int)((date.Hour + 1) / 2) % 12);
                时 = 日.Gan.起月时(时支, 柱位.时);
            }

            return(BaZiList.Create(年, 月, 日, 时));
        }
Exemplo n.º 3
0
        public GanZhi(int gan, int zhi)
        {
            this.Gan = Gan.Get(gan);
            this.Zhi = Zhi.Get(zhi);

            this.ValidCheck();
        }
Exemplo n.º 4
0
        static Zhi()
        {
            instances = new Zhi[BaseDef.Zhis.Length];

            for (int idx = 0; idx < instances.Length; idx++)
            {
                instances[idx] = new Zhi(idx, BaseDef.Zhis[idx]);
            }
        }
Exemplo n.º 5
0
 internal string[] Calc(GanZhi gz)
 {
     if (this.CalcSpec == null)
     {
         return(new string[] { Zhi.Get(this.Pattern[this.Fetch(gz)]).Name });
     }
     else
     {
         return(this.CalcSpec(gz));
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// 寅月以寅日为建日,卯月以卯日为建日,
        /// 當推算出「建日」後,以後跟隨的日支,便繼續配上 除、滿、平、定、執、破、危、成、收、開、閉等十二神
        /// </summary>
        /// <returns></returns>
        public static JianChu Get(Zhi 月, Zhi 日)
        {
            if (instances == null)
            {
                JianChu.Init();
            }

            var index = (日.Index - 月.Index + 12) % 12;

            return(instances[index]);
        }
Exemplo n.º 7
0
        internal static string[] 贵人(GanZhi gz)
        {
            int[,] pattern = new int[10, 2] {
                { 1, 7 }, { 8, 0 }, { 11, 9 }, { 11, 9 }, { 1, 7 }, { 8, 0 }, { 2, 6 }, { 2, 6 }, { 3, 5 }, { 3, 5 }
            };

            List <int> res = new List <int>();

            res.Add(pattern[gz.Gan.Index, 0]);
            res.Add(pattern[gz.Gan.Index, 1]);

            return(res.Select(i => Zhi.Get(i).Name).ToArray());
        }
Exemplo n.º 8
0
        public GanZhi 起月时(Zhi zhi, 柱位 location)
        {
            if (location == 柱位.月)
            {
                var start = (this.Index % 5) * 2;
                start = (start + 2) % 10;

                var diff = (zhi.Index - 2 + 12) % 12; //减去寅月
                var g    = (start + diff + 10) % 10;

                return(new GanZhi(g, zhi.Index));
            }
            else
            {
                var start = (this.Index % 5) * 2;
                var g     = (start + zhi.Index + 10) % 10;
                return(new GanZhi(g, zhi.Index));
            }
        }
Exemplo n.º 9
0
        public GanZhi(string name)
        {
            string g = string.Empty;
            string z = string.Empty;

            if (string.IsNullOrEmpty(name) || name.Length > 2)
            {
                this.Gan = Gan.Zero;
                this.Zhi = Zhi.Zero;
            }
            else if (name.Length == 1)
            {
                this.Gan = Gan.Zero;
                this.Zhi = Zhi.Get(name);
            }
            else
            {
                this.Gan = Gan.Get(name.Substring(0, 1));
                this.Zhi = Zhi.Get(name.Substring(1, 1));
            }

            this.ValidCheck();
        }
Exemplo n.º 10
0
        internal static string[] 旬空(GanZhi gz)
        {
            var index = 10 - (int)(gz.Index / 10) * 2;

            return(new string[] { Zhi.Get(index).Name, Zhi.Get(index + 1).Name });
        }
Exemplo n.º 11
0
 internal static string[] 天医(GanZhi gz)
 {
     return(new string[] { Zhi.Get((gz.Zhi.Index - 1 + 12) % 12).Name });
 }