示例#1
0
        private void cmbDayCalendar_Lunar_Month_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                lblDayCalendar_Error.Visible        = false;
                btnDayCalendar_PreviousDate.Enabled = true;
                btnDayCalendar_NextDate.Enabled     = true;

                currentLunarMonth = int.Parse(cmbDayCalendar_Lunar_Month.Text.Substring(0, 2));
                if (cmbDayCalendar_Lunar_Month.Text.Length > 2)
                {
                    currentLunarIsLeapMonth = true;
                }
                DayCalendar_ModifySelectedDate_Lunar();
                LunarDate currentLunarDate = new LunarDate(currentLunarDay, currentLunarMonth, currentLunarIsLeapMonth, currentLunarYear, timeZone);
                SolarDate currentSolarDate = currentLunarDate.ToSolarDate();
                currentSolarYear  = currentSolarDate.Year;
                currentSolarMonth = currentSolarDate.Month;
                currentSolarDay   = currentSolarDate.Day;
                cldLunarDayCalendar.SelectedDate = new DateTime(currentSolarYear, currentSolarMonth, currentSolarDay);
            }
            catch (Exception exc)
            {
                lblDayCalendar_Error.Text           = "Lỗi: " + exc.Message;
                lblDayCalendar_Error.Visible        = true;
                btnDayCalendar_PreviousDate.Enabled = false;
                btnDayCalendar_NextDate.Enabled     = false;
            }
        }
示例#2
0
        public static ArrayList GetMonths(int year, int timeZone)
        {
            ArrayList months     = new ArrayList();
            LunarDate lunarDate1 = new LunarDate(1, 1, false, year, timeZone);

            LunarDate newMoonDay = lunarDate1;
            SolarDate testDate_Solar;
            LunarDate testDate_Lunar;

            do
            {
                string month = newMoonDay.Month.ToString("00");
                if (newMoonDay.IsLeapMonth)
                {
                    month += " nhuận";
                }
                months.Add(month);

                if (year == 9999 && month == "12")
                {
                    break;
                }
                testDate_Solar = new SolarDate(newMoonDay.JulianDayNumber + 32);
                testDate_Lunar = testDate_Solar.ToLunarDate(timeZone);

                newMoonDay = new LunarDate(1, testDate_Lunar.Month, testDate_Lunar.isLeapMonth, year, timeZone);
            }while (testDate_Lunar.Year == year);

            return(months);
        }
示例#3
0
        private void txtDayCalendar_Lunar_Year_Validated(object sender, EventArgs e)
        {
            try
            {
                lblDayCalendar_Error.Visible        = false;
                btnDayCalendar_PreviousDate.Enabled = true;
                btnDayCalendar_NextDate.Enabled     = true;

                currentLunarYear = int.Parse(txtDayCalendar_Lunar_Year.Text);
                DayCalendar_ModifySelectedDate_Lunar();
                LunarDate currentLunarDate = new LunarDate(currentLunarDay, currentLunarMonth, currentLunarIsLeapMonth, currentLunarYear, timeZone);
                SolarDate currentSolarDate = currentLunarDate.ToSolarDate();
                currentSolarYear  = currentSolarDate.Year;
                currentSolarMonth = currentSolarDate.Month;
                currentSolarDay   = currentSolarDate.Day;
                cldLunarDayCalendar.SelectedDate = new DateTime(currentSolarYear, currentSolarMonth, currentSolarDay);
            }
            catch (Exception exc)
            {
                lblDayCalendar_Error.Text           = "Lỗi: " + exc.Message;
                lblDayCalendar_Error.Visible        = true;
                btnDayCalendar_PreviousDate.Enabled = false;
                btnDayCalendar_NextDate.Enabled     = false;
            }
        }
示例#4
0
        private void cmbDayCalendar_Lunar_Day_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbDayCalendar_Lunar_Day.SelectedIndex == -1)
            {
                return;
            }

            try
            {
                lblDayCalendar_Error.Visible        = false;
                btnDayCalendar_PreviousDate.Enabled = true;
                btnDayCalendar_NextDate.Enabled     = true;

                int currentLunarDay = int.Parse(cmbDayCalendar_Lunar_Day.Text);
                currentLunarDate = new LunarDate(currentLunarDay, currentLunarDate.Month, currentLunarDate.IsLeapMonth, currentLunarDate.Year, timeZone);
                currentSolarDate = currentLunarDate.ToSolarDate();
                cldLunarDayCalendar.SelectedDate = new DateTime(currentSolarDate.Year, currentSolarDate.Month, currentSolarDate.Day);
            }
            catch (Exception exc)
            {
                lblDayCalendar_Error.Text           = "Lỗi: " + exc.Message;
                lblDayCalendar_Error.Visible        = true;
                btnDayCalendar_PreviousDate.Enabled = false;
                btnDayCalendar_NextDate.Enabled     = false;
            }
        }
示例#5
0
        private void cldLunarDayCalendar_SelectedDateChanged(object sender, EventArgs e)
        {
            currentSolarYear  = cldLunarDayCalendar.SelectedDate.Year;
            currentSolarMonth = cldLunarDayCalendar.SelectedDate.Month;
            currentSolarDay   = cldLunarDayCalendar.SelectedDate.Day;
            SolarDate solarDate = new SolarDate(currentSolarDay, currentSolarMonth, currentSolarYear);
            LunarDate lunarDate = solarDate.ToLunarDate(timeZone);

            currentLunarYear        = lunarDate.Year;
            currentLunarMonth       = lunarDate.Month;
            currentLunarIsLeapMonth = lunarDate.IsLeapMonth;
            currentLunarDay         = lunarDate.Day;

            DayCalendar_UpdateValue();

            if (solarDate == SolarDate.MinValue)
            {
                btnDayCalendar_PreviousDate.Enabled = false;
            }
            else
            {
                btnDayCalendar_PreviousDate.Enabled = true;
            }

            if (solarDate == SolarDate.MaxValue)
            {
                btnDayCalendar_NextDate.Enabled = false;
            }
            else
            {
                btnDayCalendar_NextDate.Enabled = true;
            }
        }
示例#6
0
        private void cldLunarMonthCalendar_SelectedMonthChanged(object sender, EventArgs e)
        {
            currentMonth = cldLunarMonthCalendar.SelectedMonth.Month;
            currentYear  = cldLunarMonthCalendar.SelectedMonth.Year;

            txtMonthCalendar_Year.Text  = cldLunarMonthCalendar.SelectedMonth.Year.ToString("0000");
            cmbMonthCalendar_Month.Text = cldLunarMonthCalendar.SelectedMonth.Month.ToString("00");

            if (currentSolarYear == 1 && currentMonth == 1)
            {
                btnMonthCalendar_PreviousMonth.Enabled = false;
            }
            else
            {
                btnMonthCalendar_PreviousMonth.Enabled = true;
            }

            if (currentYear == 9999 && currentMonth == 12)
            {
                btnMonthCalendar_NextMonth.Enabled = false;
            }
            else
            {
                btnMonthCalendar_NextMonth.Enabled = true;
            }

            SolarDate sd = new SolarDate(cldLunarMonthCalendar.SelectedMonth);
            LunarDate ld = sd.ToLunarDate(timeZone);
        }
示例#7
0
        private void cldLunarDayCalendar_SelectedDateChanged(object sender, EventArgs e)
        {
            currentSolarDate = new SolarDate(cldLunarDayCalendar.SelectedDate);
            currentLunarDate = currentSolarDate.ToLunarDate(timeZone);

            DayCalendar_UpdateValue();

            if (currentSolarDate == SolarDate.MinValue)
            {
                btnDayCalendar_PreviousDate.Enabled = false;
            }
            else
            {
                btnDayCalendar_PreviousDate.Enabled = true;
            }

            if (currentSolarDate == SolarDate.MaxValue)
            {
                btnDayCalendar_NextDate.Enabled = false;
            }
            else
            {
                btnDayCalendar_NextDate.Enabled = true;
            }
        }
示例#8
0
        private void DayCalendar_ModifySelectedDate_Solar()
        {
            //Day
            int n = SolarDate.GetNumberOfDaysInMonth(currentSolarMonth, currentSolarYear);

            if (currentSolarDay > n)
            {
                currentSolarDay = n;
            }
        }
示例#9
0
        private void DayCalendar_ModifySelectedDate_Solar(int solarMonth, int solarYear)
        {
            //Day
            int n = SolarDate.GetNumberOfDaysInMonth(solarMonth, solarYear);

            if (currentSolarDate.Day > n)
            {
                currentSolarDate = new SolarDate(n, solarMonth, solarYear);
            }
        }
示例#10
0
        private void DayCalendar_ModifySelectedDate_Lunar(int lunarMonth, bool lunarIsLeapMonth, int lunarYear)
        {
            //Check mininum value
            if (lunarYear == 0)
            {
                if (currentLunarDate.Month < 11)
                {
                    currentLunarDate = new LunarDate(19, 11, false, 0, timeZone);
                }
                else if (currentLunarDate.Month == 11)
                {
                    if (currentLunarDate.Day < 19)
                    {
                        currentLunarDate = new LunarDate(19, 11, false, 0, timeZone);
                    }
                    else
                    {
                        currentLunarDate = new LunarDate(currentLunarDate.Day, 11, false, 0, timeZone);
                    }
                }
            }

            //Month
            ArrayList months = LunarDate.GetMonths(lunarYear, timeZone);

            if (lunarIsLeapMonth)
            {
                bool flag = false;
                foreach (string month in months)
                {
                    if (month.Length > 2 && month.Substring(0, 2) == lunarMonth.ToString("00"))
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    currentLunarDate = new LunarDate(currentLunarDate.Day, lunarMonth, false, lunarYear, timeZone);
                }
            }

            //Day
            int n = LunarDate.GetNumberOfDaysInMonth(lunarMonth, lunarIsLeapMonth, lunarYear, timeZone);

            if (currentLunarDate.Day > n)
            {
                currentLunarDate = new LunarDate(n, lunarMonth, lunarIsLeapMonth, lunarYear, timeZone);
            }
            else
            {
                currentLunarDate = new LunarDate(currentLunarDate.Day, lunarMonth, lunarIsLeapMonth, lunarYear, timeZone);
            }
            currentSolarDate = currentLunarDate.ToSolarDate();
        }
示例#11
0
        public override bool Equals(object obj)
        {
            if (obj.GetType() != typeof(SolarDate))
            {
                return(false);
            }

            SolarDate solarDate = (SolarDate)obj;

            return(solarDate.Year != year || solarDate.Month != month || solarDate.Day != day);
        }
        public static LunarDate ConvertSolarDateToLunarDate(SolarDate solarDate, int timeZone)
        {
            long dayNumber  = solarDate.JulianDayNumber;
            long k          = (long)Math.Floor((dayNumber - 2415021.076998695) / 29.530588853);
            long monthStart = GetNewMoonDay(k + 1, timeZone);

            if (monthStart > dayNumber)
            {
                monthStart = GetNewMoonDay(k, timeZone);
            }
            long a11       = GetLunarMonth11(solarDate.Year, timeZone);
            long b11       = a11;
            int  lunarYear = 0;

            if (a11 >= monthStart)
            {
                lunarYear = solarDate.Year;
                a11       = GetLunarMonth11(solarDate.Year - 1, timeZone);
            }
            else
            {
                lunarYear = solarDate.Year + 1;
                b11       = GetLunarMonth11(solarDate.Year + 1, timeZone);
            }
            int  lunarDay   = (int)(dayNumber - monthStart + 1);
            int  diff       = (int)Math.Floor((double)((monthStart - a11) / 29));
            bool lunarLeap  = false;
            int  lunarMonth = diff + 11;

            if (b11 - a11 > 365)
            {
                int leapMonthDiff = GetLeapMonthOffset(a11, timeZone);
                if (diff >= leapMonthDiff)
                {
                    lunarMonth = diff + 10;
                    if (diff == leapMonthDiff)
                    {
                        lunarLeap = true;
                    }
                }
            }
            if (lunarMonth > 12)
            {
                lunarMonth = lunarMonth - 12;
            }
            if (lunarMonth >= 11 && diff < 4)
            {
                lunarYear -= 1;
            }
            return(new LunarDate(lunarDay, lunarMonth, lunarLeap, lunarYear, timeZone));
        }
        //Đông chí thường nằm vào khoảng 19/12-22/12, như vậy trước hết ta tìm ngày Sóc trước ngày 31/12 (trả về số ngày Julius).
        //Nếu tháng bắt đầu vào ngày đó không chứa Đông chí thì ta phải lùi lại 1 tháng nữa.
        private static long GetLunarMonth11(int year, int timeZone)
        {
            SolarDate solarDate = new SolarDate(31, 12, year);
            double    off       = solarDate.JulianDayNumber - 2415021.076998695;
            long      k         = (long)Math.Floor(off / 29.530588853);
            long      nm        = GetNewMoonDay(k, timeZone);
            double    sunLong   = GetSunLongitude(nm, timeZone); // sun longitude at local midnight

            if (sunLong >= 9)
            {
                nm = GetNewMoonDay(k - 1, timeZone);
            }
            return(nm);
        }
示例#14
0
        public Main()
        {
            InitializeComponent();

            currentSolarDate = new SolarDate(DateTime.Today);
            currentLunarDate = currentSolarDate.ToLunarDate(timeZone);
            currentMonth     = DateTime.Today.Month;
            currentYear      = DateTime.Today.Year;

            DayCalendar_FillValue();
            MonthCalendar_FillValue();

            cldLunarDayCalendar.SelectedDate    = DateTime.Today;
            cldLunarMonthCalendar.SelectedMonth = DateTime.Today;
        }
示例#15
0
        public static int GetNumberOfDaysInMonth(int month, bool isLeapMonth, int year, int timeZone)
        {
            if (year == 9999 && month == 12)
            {
                return(29);
            }

            LunarDate newMoonDay_Lunar = new LunarDate(1, month, isLeapMonth, year, timeZone);
            SolarDate newMoonDay_Solar = newMoonDay_Lunar.ToSolarDate();

            SolarDate testDate_Solar = new SolarDate(newMoonDay_Solar.JulianDayNumber + 32);
            LunarDate testDate_Lunar = testDate_Solar.ToLunarDate(timeZone);

            LunarDate nextNewMoonDay_Lunar = new LunarDate(1, testDate_Lunar.Month, testDate_Lunar.isLeapMonth, testDate_Lunar.Year, timeZone);
            SolarDate nextNewMoonDay_Solar = nextNewMoonDay_Lunar.ToSolarDate();

            return((int)(nextNewMoonDay_Solar.JulianDayNumber - newMoonDay_Solar.JulianDayNumber));
        }
示例#16
0
        private void DayCalendar_FillValue()
        {
            //Solar Date
            //Year
            txtDayCalendar_Solar_Year.Text = currentSolarYear.ToString("0000");
            //Month
            cmbDayCalendar_Solar_Month.Text = currentSolarMonth.ToString("00");
            //Day
            cmbDayCalendar_Solar_Day.Items.Clear();
            int n = SolarDate.GetNumberOfDaysInMonth(currentSolarMonth, currentSolarYear);

            for (int i = 1; i <= n; i++)
            {
                cmbDayCalendar_Solar_Day.Items.Add((i).ToString("00"));
            }
            cmbDayCalendar_Solar_Day.Text = currentSolarDay.ToString("00");

            //Lunar Date
            //Year
            txtDayCalendar_Lunar_Year.Text = currentLunarYear.ToString("0000");
            //Month
            cmbDayCalendar_Lunar_Month.Items.Clear();
            foreach (string month in LunarDate.GetMonths(currentLunarYear, timeZone))
            {
                cmbDayCalendar_Lunar_Month.Items.Add(month);
            }
            string str = currentLunarMonth.ToString("00");

            if (currentLunarIsLeapMonth)
            {
                str += " nhuận";
            }
            cmbDayCalendar_Lunar_Month.Text = str;
            //Day
            cmbDayCalendar_Lunar_Day.Items.Clear();
            int m = LunarDate.GetNumberOfDaysInMonth(currentLunarMonth, currentLunarIsLeapMonth, currentLunarYear, timeZone);

            for (int i = 1; i <= m; i++)
            {
                cmbDayCalendar_Lunar_Day.Items.Add(i.ToString("00"));
            }
            cmbDayCalendar_Lunar_Day.Text = currentLunarDay.ToString("00");
        }
示例#17
0
        //Khởi tạo
        public frmMain()
        {
            InitializeComponent();

            currentSolarYear  = DateTime.Today.Year;
            currentSolarMonth = DateTime.Today.Month;
            currentSolarDay   = DateTime.Today.Day;
            SolarDate today_Solar = new SolarDate(currentSolarDay, currentSolarMonth, currentSolarYear);
            LunarDate today_Lunar = today_Solar.ToLunarDate(timeZone);

            currentLunarYear        = today_Lunar.Year;
            currentLunarMonth       = today_Lunar.Month;
            currentLunarIsLeapMonth = today_Lunar.IsLeapMonth;
            currentLunarDay         = today_Lunar.Day;

            DayCalendar_FillValue();
            MonthCalendar_FillValue();

            cldLunarDayCalendar.SelectedDate    = DateTime.Today;
            cldLunarMonthCalendar.SelectedMonth = DateTime.Today;
        }
示例#18
0
        private void DayCalendar_UpdateValue() //Modify the Selected Date and Update Value
        {
            //Solar Date
            //Year
            txtDayCalendar_Solar_Year.Text = currentSolarYear.ToString("0000");
            //Month
            cmbDayCalendar_Solar_Month.Text = currentSolarMonth.ToString("00");
            //Day
            int n = SolarDate.GetNumberOfDaysInMonth(currentSolarMonth, currentSolarYear);

            if (n != cmbDayCalendar_Solar_Day.Items.Count)
            {
                if (n > cmbDayCalendar_Solar_Day.Items.Count)
                {
                    for (int i = cmbDayCalendar_Solar_Day.Items.Count + 1; i <= n; i++)
                    {
                        cmbDayCalendar_Solar_Day.Items.Add(i.ToString("00"));
                    }
                }
                else
                {
                    if (int.Parse(cmbDayCalendar_Solar_Day.Text) > n)
                    {
                        cmbDayCalendar_Solar_Day.Text = currentSolarDay.ToString("00");
                    }
                    for (int i = cmbDayCalendar_Solar_Day.Items.Count - 1; i >= n; i--)
                    {
                        cmbDayCalendar_Solar_Day.Items.RemoveAt(i);
                    }
                }
            }
            cmbDayCalendar_Solar_Day.Text = currentSolarDay.ToString("00");

            //Lunar Date
            //Year
            txtDayCalendar_Lunar_Year.Text = currentLunarYear.ToString("0000");
            //Month
            ArrayList months = months = LunarDate.GetMonths(currentLunarYear, timeZone);

            for (int i = cmbDayCalendar_Lunar_Month.Items.Count - 1; i >= 0; i--)
            {
                string month = (string)cmbDayCalendar_Lunar_Month.Items[i];
                if (month.Length > 2)
                {
                    bool flag = false;
                    foreach (string month1 in months)
                    {
                        if (month1 == month)
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        cmbDayCalendar_Lunar_Month.Items.RemoveAt(i);
                    }
                }
            }
            foreach (string month in months)
            {
                if (month.Length > 2)
                {
                    bool flag = false;
                    foreach (string month1 in cmbDayCalendar_Lunar_Month.Items)
                    {
                        if (month1 == month)
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        cmbDayCalendar_Lunar_Month.Items.Add(month);
                    }
                }
            }
            string str = currentLunarMonth.ToString("00");

            if (currentLunarIsLeapMonth)
            {
                str += " nhuận";
            }
            cmbDayCalendar_Lunar_Month.Text = str;
            //Day
            int m = LunarDate.GetNumberOfDaysInMonth(currentLunarMonth, currentLunarIsLeapMonth, currentSolarYear, timeZone);

            if (m != cmbDayCalendar_Lunar_Day.Items.Count)
            {
                if (m > cmbDayCalendar_Lunar_Day.Items.Count)
                {
                    for (int i = cmbDayCalendar_Lunar_Day.Items.Count + 1; i <= m; i++)
                    {
                        cmbDayCalendar_Lunar_Day.Items.Add((i).ToString("00"));
                    }
                }
                else
                {
                    if (int.Parse(cmbDayCalendar_Lunar_Day.Text) > m)
                    {
                        cmbDayCalendar_Lunar_Day.Text = currentLunarDay.ToString("00");
                    }
                    for (int i = cmbDayCalendar_Lunar_Day.Items.Count - 1; i >= m; i--)
                    {
                        cmbDayCalendar_Lunar_Day.Items.RemoveAt(i);
                    }
                }
            }

            cmbDayCalendar_Lunar_Day.Text = currentLunarDay.ToString("00");
        }
示例#19
0
        private void DayCalendar_UpdateValue()
        {
            //Solar Date
            //Year
            txtDayCalendar_Solar_Year.Text = currentSolarDate.Year.ToString("0000");
            //Month
            cmbDayCalendar_Solar_Month.Text = currentSolarDate.Month.ToString("00");
            //Day
            cmbDayCalendar_Solar_Day.Items.Clear();
            int n = SolarDate.GetNumberOfDaysInMonth(currentSolarDate.Month, currentSolarDate.Year);

            for (int i = 1; i <= n; i++)
            {
                cmbDayCalendar_Solar_Day.Items.Add(i.ToString("00"));
            }
            cmbDayCalendar_Solar_Day.Text = currentSolarDate.Day.ToString("00");

            //Lunar Date
            //Year
            txtDayCalendar_Lunar_Year.Text = currentLunarDate.Year.ToString("0000");
            //Month
            if (currentLunarDate.Year > 0)
            {
                cmbDayCalendar_Lunar_Month.Items.Clear();
                ArrayList months = months = LunarDate.GetMonths(currentLunarDate.Year, timeZone);
                foreach (string month in months)
                {
                    cmbDayCalendar_Lunar_Month.Items.Add(month);
                }
                string str = currentLunarDate.Month.ToString("00");
                if (currentLunarDate.IsLeapMonth)
                {
                    str += " nhuận";
                }
                cmbDayCalendar_Lunar_Month.Text = str;
            }
            else if (currentLunarDate.Year == 0)
            {
                cmbDayCalendar_Lunar_Month.Items.Clear();
                cmbDayCalendar_Lunar_Month.Items.Add("11");
                cmbDayCalendar_Lunar_Month.Items.Add("12");
                cmbDayCalendar_Lunar_Month.Text = currentLunarDate.Month.ToString("00");
            }

            //Day
            if (currentLunarDate.Year > 0 || (currentLunarDate.Year == 0 && currentLunarDate.Month > 11))
            {
                cmbDayCalendar_Lunar_Day.Items.Clear();
                int m = LunarDate.GetNumberOfDaysInMonth(currentLunarDate.Month, currentLunarDate.IsLeapMonth, currentLunarDate.Year, timeZone);
                for (int i = 1; i <= m; i++)
                {
                    cmbDayCalendar_Lunar_Day.Items.Add((i).ToString("00"));
                }
                cmbDayCalendar_Lunar_Day.Text = currentLunarDate.Day.ToString("00");
            }
            else if (currentLunarDate.Year == 0 && currentLunarDate.Month == 11)
            {
                cmbDayCalendar_Lunar_Day.Items.Clear();
                for (int i = 19; i <= 30; i++)
                {
                    cmbDayCalendar_Lunar_Day.Items.Add(i.ToString());
                }
                cmbDayCalendar_Lunar_Day.Text = currentLunarDate.Day.ToString("00");
            }
        }