Exemplo n.º 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;
            }
        }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
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));
        }