Example #1
0
    // 函數清單 GetChDay(int)
    // 傳入參數	int		日期數字
    // 傳回參數	string	農曆日期
    public string GetChDay(int iDay)
    {
        String_Func sfc = new String_Func();

        string cDay = "";

        if (iDay < 1 || iDay > 31)
        {
            cDay = "不明";
        }
        else
        {
            cDay = sfc.GetChNumber((ulong)iDay);

            if (iDay < 10)
            {
                cDay = "初" + sfc.Left(cDay, 1);
            }
            else if (iDay == 10)
            {
                cDay = "初十";
            }
            else if (iDay > 10 && iDay < 20)
            {
                cDay = cDay.Replace("一十", "十");
            }
            else if (iDay > 20 && iDay < 30)
            {
                cDay = cDay.Replace("二十", "廿");
            }
            else if (iDay > 30)
                cDay = cDay.Replace("三十", "卅");
        }

        return cDay;
    }
Example #2
0
    // 函數清單 GetChMonth(int)
    // 傳入參數	int		順序
    // 傳回參數	string	月份
    public string GetChMonth(int iMonth)
    {
        String_Func sfc = new String_Func();

        string cMonth = "";

        if (iMonth < 1 || iMonth > 12)
        {
            cMonth = "?";
        }
        else
        {
            if (iMonth == 1)
            {
                cMonth = "正";
            }
            else
            {
                cMonth = sfc.GetChNumber(iMonth);

                if (iMonth < 11)
                {
                    cMonth = sfc.Right(cMonth, 1);
                }
                else
                {
                    cMonth = sfc.Right(cMonth, 2);
                }
            }
        }

        return cMonth;
    }
Example #3
0
    public string GetLunarDate(DateTime mdate, string mtype)
    {
        String_Func sfc = new String_Func();
        TaiwanLunisolarCalendar tlc = new TaiwanLunisolarCalendar();

        string ldate = "";
        int LunarYear = 0;										// 農曆年
        int LunarMonth = 0;										// 月份
        int LunarDay = 0;										// 日期
        int LunarHour = 0;										// 時
        int LunarMin = 0;										// 分
        int LunarSec = 0;										// 秒
        int LeapMonth = 0;										// 潤月

        LunarYear = tlc.GetSexagenaryYear(mdate);				// 取得西元年

        #region 農曆年
        if (mtype.Contains("y"))
        {
            ldate = GetHeavenlyStem(tlc.GetCelestialStem(LunarYear));					// 年 - 天干
            ldate += GetEarthlyBranch(tlc.GetTerrestrialBranch(LunarYear)) + "年";		// 年 - 地支
        }
        #endregion

        #region 農曆月
        if (mtype.Contains("M"))
        {
            LunarMonth = tlc.GetMonth(mdate);						// 取得月份
            LeapMonth = tlc.GetLeapMonth(tlc.GetYear(mdate));		// 取得潤月

            if (LeapMonth > 0)
            {
                // 當年有潤月,月份會出現13個月,在潤月之後的月分要減一。
                if (LeapMonth == LunarMonth)
                {
                    ldate += "閏" + GetChMonth(LeapMonth - 1) + "月";
                }
                else if (LunarMonth > LeapMonth)
                {
                    ldate += GetChMonth(LunarMonth - 1) + "月";
                }
                else
                    ldate += GetChMonth(LunarMonth) + "月";
            }
            else
                ldate += GetChMonth(LunarMonth) + "月";
        }
        #endregion

        #region 農曆日
        if (mtype.Contains("d"))
        {
            LunarDay = tlc.GetDayOfMonth(mdate);

            ldate += GetChDay(LunarDay) + "日";
        }
        #endregion

        #region 農曆時 (子、丑...)
        if (mtype.Contains("H"))
        {
            LunarHour = tlc.GetHour(mdate);
            ldate += GetChHour(LunarHour) + "時";
        }
        #endregion

        #region 中文數字時 (五、十一...)
        if (mtype.Contains("h"))
        {
            LunarHour = tlc.GetHour(mdate);
            ldate += GetChNHour(LunarHour) + "時";
        }
        #endregion

        #region 農曆分
        if (mtype.Contains("m"))
        {
            LunarMin = tlc.GetMinute(mdate);
            ldate += sfc.GetChNumber((ulong)LunarMin).Replace("一十", "十") + "分";
        }
        #endregion

        #region 農曆秒
        if (mtype.Contains("s"))
        {
            LunarSec = tlc.GetSecond(mdate);
            if (LunarSec == 0)
            {
                ldate += "整";
            }
            else
            {
                ldate += sfc.GetChNumber((ulong)LunarSec).Replace("一十", "十") + "秒";
            }
        }
        #endregion

        return ldate;
    }
Example #4
0
    // 函數清單 GetChNHour(int)
    // 傳入參數	int		順序
    // 傳回參數	string	月份
    public string GetChNHour(int iHour)
    {
        String_Func sfc = new String_Func();

        string cHour = "";

        if (iHour < 0 || iHour > 23)
        {
            cHour = "?";
        }
        else
        {
            cHour = sfc.GetChNumber(iHour);
            cHour.Replace("一十","十");
        }

        return cHour;
    }
Example #5
0
    // 整數轉中文數字
    protected void bn_GetChNumber_Click(object sender, EventArgs e)
    {
        String_Func sfc = new String_Func();

        lb_GetChNumber.Text = sfc.GetChNumber(tb_GetChNumber_int.Text);
    }