Ejemplo n.º 1
0
        private QueIndex GetQueIndex(CachLayQue cachLayQue, AmLich amLich)
        {
            var queIndex = new QueIndex();

            switch (cachLayQue)
            {
            case CachLayQue.None:
                break;

            case CachLayQue.MaiHoaTienThien1:
                queIndex = _layQueService.GetQueIndexByTime(amLich, txtSoHoacChu.Text);
                break;

            case CachLayQue.MaiHoaTienThien2:
                queIndex = _layQueService.GetQueIndexBySoAndTime(amLich, txtQueNgoai1.Text);
                break;

            case CachLayQue.MaiHoaTienThien3:
                queIndex = _layQueService.GetQueIndexBySoAndSo(txtQueNgoai2.Text, txtQueNoi2.Text, amLich, chkCongChiGio.Checked);
                break;

            default:
                break;
            }

            return(queIndex);
        }
Ejemplo n.º 2
0
        public QueIndex GetQueIndexByTime(AmLich amLich, string extraText = "")
        {
            int soHoacChu     = GetTongCuaQuai(extraText);
            int tongNgoaiQuai = GetTongNamThangNgay(amLich) + soHoacChu;
            int tongNoiQuai   = GetTongNamThangNgayGio(amLich) + soHoacChu;

            var queIndex = new QueIndex
            {
                NgoaiQuaiIndex = (tongNgoaiQuai - 1 + 8) % 8,
                NoiQuaiIndex   = (tongNoiQuai - 1 + 8) % 8,
                HaoDongIndex   = tongNoiQuai % 6,
            };

            var sb = new StringBuilder();

            sb.AppendLine($"1. Ngoại quái: năm {amLich.NamAm.Chi.Name} {amLich.NamAm.Chi.Id} + tháng {amLich.LunarMonth} + ngày {amLich.LunarDay} + số {soHoacChu} = {tongNgoaiQuai} % 8 = {queIndex.NgoaiQuaiIndex + 1} = quẻ {BatQuai.All[queIndex.NgoaiQuaiIndex].Name}");
            sb.AppendLine();
            sb.AppendLine($"2. Nội quái:   năm {amLich.NamAm.Chi.Name} {amLich.NamAm.Chi.Id} + tháng {amLich.LunarMonth} + ngày {amLich.LunarDay} + số {soHoacChu} + giờ {amLich.GioAm.Chi.Name} {amLich.GioAm.Chi.Id} = {tongNoiQuai} % 8 = {queIndex.NoiQuaiIndex + 1} = quẻ {BatQuai.All[queIndex.NoiQuaiIndex].Name}");
            sb.AppendLine();
            sb.AppendLine($"3. Động hào:   tổng nội quái {tongNoiQuai} % 6 = {queIndex.HaoDongNumber}");

            queIndex.Desc = sb.ToString();

            return(queIndex);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Form load event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Main_Load(object sender, EventArgs e)
        {
            ucQueDich.DisableAllControls();

            ucQueDich.HideAllControls();

            AmLich = DateTime.Now.ToAmLich();
        }
Ejemplo n.º 4
0
        private void btnLayQueMaiHoa_Click(object sender, EventArgs e)
        {
            _formQueThoiGian.IsDone = false;
            _formQueThoiGian.ShowDialog(this);

            if (_formQueThoiGian.IsDone)
            {
                AmLich = _formQueThoiGian.AmLich;
                LoadQue(_formQueThoiGian);
                radVietDich.Checked = true;
            }
        }
Ejemplo n.º 5
0
        public void TestThangAm()
        {
            DateTime duongLich = new DateTime(2018, 8, 28);
            AmLich   amLich    = Calendar.ConvertSolar2Lunar(duongLich);

            Assert.AreEqual(amLich.ThangAm.Can, Canh);
            Assert.AreEqual(amLich.ThangAm.Chi, Than);

            duongLich = new DateTime(1983, 3, 13);
            amLich    = Calendar.ConvertSolar2Lunar(duongLich);
            Assert.AreEqual(amLich.ThangAm.Can, Giap);
            Assert.AreEqual(amLich.ThangAm.Chi, Dan);
        }
Ejemplo n.º 6
0
        public void TestSolarLunar()
        {
            DateTime duongLich = new DateTime(1983, 3, 13);
            AmLich   amlich    = Calendar.ConvertSolar2Lunar(duongLich.Year, duongLich.Month, duongLich.Day, 7);

            Assert.AreEqual(amlich.LunarMonth, 1);
            Assert.AreEqual(amlich.LunarDay, 29);

            duongLich = new DateTime(2016, 8, 16);
            amlich    = Calendar.ConvertSolar2Lunar(duongLich, 7);
            Assert.AreEqual(amlich.LunarMonth, 7);
            Assert.AreEqual(amlich.LunarDay, 14);
        }
Ejemplo n.º 7
0
        private void btnTungXuLayQue_Click(object sender, EventArgs e)
        {
            var formLayQue = new FormQueTungXu();

            formLayQue.ShowDialog(this);

            if (formLayQue.IsDone)
            {
                AmLich = formLayQue.AmLich;
                LoadQue(formLayQue);
                radLucHao.Checked = true;
            }
        }
Ejemplo n.º 8
0
        public void TestNgayAm()
        {
            DateTime duongLich = new DateTime(2018, 8, 28);
            AmLich   amLich    = Calendar.ConvertSolar2Lunar(duongLich);

            Assert.AreEqual(amLich.NgayAm.Can, Nham);
            Assert.AreEqual(amLich.NgayAm.Chi, Thin);

            duongLich = new DateTime(1983, 3, 13);
            amLich    = Calendar.ConvertSolar2Lunar(duongLich);
            Assert.AreEqual(amLich.NgayAm.Can, Canh);
            Assert.AreEqual(amLich.NgayAm.Chi, Ti);
        }
Ejemplo n.º 9
0
        public List <QueIndex> GetAllQueIndexesForADay(AmLich amLich, string extraText = "")
        {
            var queIndexes = new List <QueIndex>();

            for (int i = 0; i < DiaChi.All.Count; i++)
            {
                var solarDate = amLich.SolarDate.Date.AddHours(i * 2);
                var amLichNew = solarDate.ToAmLich();

                queIndexes.Add(GetQueIndexByTime(amLichNew, extraText));
            }

            return(queIndexes);
        }
Ejemplo n.º 10
0
        public void TestDoiNgayDoGioTi()
        {
            DateTime duongLichGoc = new DateTime(2018, 8, 30);
            AmLich   amLichGoc    = duongLichGoc.ToAmLich();

            DateTime duongLichCuoiNgay = duongLichGoc.AddHours(23);
            AmLich   amLichPlus1       = duongLichCuoiNgay.ToAmLich();

            Assert.AreEqual(amLichGoc.NgayAm.Can, Nham);
            Assert.AreEqual(amLichGoc.NgayAm.Chi, Thin);

            // Do đã qua giờ Tí nên phải ra âm lịch của ngày kế tiếp.
            Assert.AreEqual(amLichPlus1.NgayAm.Can, Quy);
            Assert.AreEqual(amLichPlus1.NgayAm.Chi, Ty);
        }
Ejemplo n.º 11
0
        private void SetNoiQuaiNgoaiQuai(AmLich amLich)
        {
            QueIndex queIndex = GetQueIndex(CachLayQue, amLich);

            txtDesc.Text = queIndex.Desc;

            ucQueDich.uiNgoaiQuai.SelectedIndex = queIndex.NgoaiQuaiIndex;
            ucQueDich.uiNoiQuai.SelectedIndex   = queIndex.NoiQuaiIndex;

            ucQueDich.ResetHaoDong();
            ucQueDich.uiIsHao1Dong.Checked = queIndex.HaoDongIndex == 1;
            ucQueDich.uiIsHao2Dong.Checked = queIndex.HaoDongIndex == 2;
            ucQueDich.uiIsHao3Dong.Checked = queIndex.HaoDongIndex == 3;
            ucQueDich.uiIsHao4Dong.Checked = queIndex.HaoDongIndex == 4;
            ucQueDich.uiIsHao5Dong.Checked = queIndex.HaoDongIndex == 5;
            ucQueDich.uiIsHao6Dong.Checked = queIndex.HaoDongIndex == 0;
        }
Ejemplo n.º 12
0
        public void TestNamAm()
        {
            DateTime duongLich = new DateTime(1992, 7, 1);
            AmLich   amLich    = Calendar.ConvertSolar2Lunar(duongLich);

            Assert.AreEqual(amLich.NamAm.Can, Nham);
            Assert.AreEqual(amLich.NamAm.Chi, Than);

            duongLich = new DateTime(1983, 3, 13);
            amLich    = Calendar.ConvertSolar2Lunar(duongLich);
            Assert.AreEqual(amLich.NamAm.Can, Quy);
            Assert.AreEqual(amLich.NamAm.Chi, Hoi);

            duongLich = new DateTime(1986, 4, 14);
            amLich    = Calendar.ConvertSolar2Lunar(duongLich);
            Assert.AreEqual(amLich.NamAm.Can, Binh);
            Assert.AreEqual(amLich.NamAm.Chi, Dan);
        }
Ejemplo n.º 13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // for Examle here:
            int dd = DateTime.Now.Day;
            int mm = DateTime.Now.Month;
            int yy = DateTime.Now.Year;

            int[] listAL = VietCalendar.convertSolar2Lunar(dd, mm, yy, 7);
            Response.Write("Ngay Am lich: " + listAL[0] + "/" + listAL[1] + "/" + listAL[2]);
            AmLich a = new AmLich();

            int mAL = Convert.ToInt32("" + listAL[1]);
            int yAL = Convert.ToInt32("" + listAL[2]);

            Response.Write("<br />Nam _ " + a.getCanNam(yy) + " " + a.getChiNam(yy));
            Response.Write("<br />Thang _" + a.getCanThang(mAL, yAL));
            Response.Write("<br />Ngay _ " + a.getCanNgay(dd, mm, yy));
        }
Ejemplo n.º 14
0
        private void SetUIControls(AmLich amLich)
        {
            CanChi ngayAm  = amLich.NgayAm;
            CanChi thangAm = amLich.ThangAm;
            CanChi namAm   = amLich.NamAm;

            cbxNgayCan.SelectedIndex  = ngayAm.Can.Id - 1;
            cbxNgayChi.SelectedIndex  = ngayAm.Chi.Id - 1;
            cbxThangCan.SelectedIndex = thangAm.Can.Id - 1;
            cbxThangChi.SelectedIndex = thangAm.Chi.Id - 1;
            cbxNamCan.SelectedIndex   = namAm.Can.Id - 1;
            cbxNamChi.SelectedIndex   = namAm.Chi.Id - 1;

            DiaChi   gioChi = DiaChi.All[cbxGioChi.SelectedIndex];
            ThienCan gioCan = amLich.GetCanCuaGio(gioChi);

            cbxGioCan.SelectedIndex = gioCan.Id - 1;

            labelNgayDuongLich.Text = $"Ngày dương lịch: {amLich.SolarDate.Year}-{amLich.SolarDate.Month}-{amLich.SolarDate.Day}";
            labelNgayAmLich.Text    = $"Ngày âm lịch: {amLich.LunarYear}-{amLich.LunarMonth}-{amLich.LunarDay}";
        }
Ejemplo n.º 15
0
        public void TestCanGioAm()
        {
            DateTime duongLich = new DateTime(2018, 8, 30);
            AmLich   amLich    = duongLich.ToAmLich();

            ThienCan canGioTi = amLich.GetCanGioTi();

            ThienCan can = amLich.GetCanCuaGio(Ti);

            Assert.AreEqual(canGioTi, can);

            can = amLich.GetCanCuaGio(Suu);
            Assert.AreEqual(can, At);

            can = amLich.GetCanCuaGio(Ngo);
            Assert.AreEqual(can, Canh);

            can = amLich.GetCanCuaGio(Dau);
            Assert.AreEqual(can, Quy);

            can = amLich.GetCanCuaGio(Hoi);
            Assert.AreEqual(can, At);
        }
Ejemplo n.º 16
0
        public QueIndex GetQueIndexBySoAndTime(AmLich amLich, string textCuaQuai)
        {
            int tongNgoaiQuai = GetTongNamThangNgayGio(amLich);
            int tongNoiQuai   = GetTongCuaQuai(textCuaQuai);

            var queIndex = new QueIndex
            {
                NgoaiQuaiIndex = (tongNgoaiQuai - 1 + 8) % 8,
                NoiQuaiIndex   = (tongNoiQuai - 1 + 8) % 8,
                HaoDongIndex   = (tongNgoaiQuai + tongNoiQuai) % 6,
            };

            var sb = new StringBuilder();

            sb.AppendLine($"1. Ngoại quái: năm {amLich.NamAm.Chi.Name} {amLich.NamAm.Chi.Id} + tháng {amLich.LunarMonth} + ngày {amLich.LunarDay} + giờ {amLich.GioAm.Chi.Name} {amLich.GioAm.Chi.Id} = {tongNgoaiQuai} % 8 = {queIndex.NgoaiQuaiIndex + 1} = quẻ {BatQuai.All[queIndex.NgoaiQuaiIndex].Name}");
            sb.AppendLine();
            sb.AppendLine($"2. Nội quái:   số {tongNoiQuai} % 8 = {queIndex.NoiQuaiIndex + 1} = quẻ {BatQuai.All[queIndex.NoiQuaiIndex].Name}");
            sb.AppendLine();
            sb.AppendLine($"3. Động hào:   ngoại quái {tongNgoaiQuai} + nội quái {tongNoiQuai} = {tongNgoaiQuai + tongNoiQuai} % 6 = {queIndex.HaoDongNumber}");

            queIndex.Desc = sb.ToString();

            return(queIndex);
        }
Ejemplo n.º 17
0
 private void SetQueDefault()
 {
     AmLich = _formQueThoiGian.AmLich;
     LoadQue(_formQueThoiGian);
     radVietDich.Checked = true;
 }
Ejemplo n.º 18
0
        public QueIndex GetQueIndexBySoAndSo(string textCuaNgoaiQuai, string textCuaNoiQuai, AmLich amLich, bool batThuong)
        {
            int tongNgoaiQuai = GetTongCuaQuai(textCuaNgoaiQuai);
            int tongNoiQuai   = GetTongCuaQuai(textCuaNoiQuai);

            // Tiên thiên đoán bằng số nên không cần giờ. Hậu thiên đoán bằng bát quái nên cần thêm giờ vào để tìm hào động.
            int chiNumber = batThuong ? amLich.GioAm.Chi.Id : 0;

            var queIndex = new QueIndex
            {
                NgoaiQuaiIndex = (tongNgoaiQuai - 1 + 8) % 8,
                NoiQuaiIndex   = (tongNoiQuai - 1 + 8) % 8,
                HaoDongIndex   = (tongNgoaiQuai + tongNoiQuai + chiNumber) % 6,
            };

            var sb = new StringBuilder();

            sb.AppendLine($"1. Ngoại quái: số {tongNgoaiQuai} % 8 = {queIndex.NgoaiQuaiIndex + 1} = quẻ {BatQuai.All[queIndex.NgoaiQuaiIndex].Name}");
            sb.AppendLine();
            sb.AppendLine($"2. Nội quái:   số {tongNoiQuai} % 8 = {queIndex.NoiQuaiIndex + 1} = quẻ {BatQuai.All[queIndex.NoiQuaiIndex].Name}");
            sb.AppendLine();
            sb.AppendLine($"3. Động hào:   ngoại quái {tongNgoaiQuai} + nội quái {tongNoiQuai}{GetGioDescChoCongThucBatThuong(amLich.GioAm, batThuong)} = {tongNgoaiQuai + tongNoiQuai + chiNumber} % 6 = {queIndex.HaoDongNumber}");

            queIndex.Desc = sb.ToString();

            return(queIndex);
        }
Ejemplo n.º 19
0
        private int GetTongNamThangNgayGio(AmLich amLich)
        {
            DiaChi gioChi = DiaChi.All[amLich.GioAm.Chi.Id - 1];

            return(GetTongNamThangNgay(amLich) + gioChi.Id);
        }
Ejemplo n.º 20
0
        private int GetTongNamThangNgay(AmLich amLich)
        {
            var tongNamThangNgay = amLich.NamAm.Chi.Id + amLich.LunarMonth + amLich.LunarDay;

            return(tongNamThangNgay);
        }