예제 #1
0
        static public string GetTaiwanToday()
        {
            TaiwanCalendar twC = new TaiwanCalendar();

            return(twC.GetYear(DateTime.Today) + "/" + twC.GetMonth(DateTime.Today) + "/" + twC.GetDayOfMonth(DateTime.Today));
            //twC = null;
        }
예제 #2
0
        public static string timeHelper(DateTime tDate)
        {
            TaiwanCalendar twC = new TaiwanCalendar();

            return(twC.GetYear(tDate) +
                   "." + twC.GetMonth(tDate) + "." + twC.GetDayOfMonth(tDate));
        }
예제 #3
0
        public String GetBirthDate(DateType type, DateFormat format)
        {
            string result = "";

            switch (type)
            {
            case DateType.Calendar:
                result = (format == DateFormat.ShortDate) ? this.birthDate.ToString("d") : this.birthDate.ToString("D");
                break;

            case DateType.ChineseCalendar:
                //System.Globalization.TaiwanCalendar
                TaiwanCalendar c1 = new TaiwanCalendar();
                int            y  = c1.GetYear(this.birthDate);
                int            m  = c1.GetMonth(this.birthDate);
                int            d  = c1.GetDayOfMonth(this.birthDate);
                result = (format == DateFormat.ShortDate) ? String.Format("{0:000}/{1:00}/{2:00}", y, m, d) : String.Format("民國{0}年{1}月{2}日", y, m, d);
                break;

            case DateType.ChineseLunisolar:
                //System.Globalization.TaiwanLunisolarCalendar
                TaiwanLunisolarCalendar c2 = new TaiwanLunisolarCalendar();
                int y2 = c2.GetYear(this.birthDate);
                int m2 = c2.GetMonth(this.birthDate);
                int d2 = c2.GetDayOfMonth(this.birthDate);
                result = (format == DateFormat.ShortDate) ? String.Format("{0:000}/{1:00}/{2:00}", y2, m2, d2) : String.Format("農曆{0}年{1}月{2}日", y2, m2, d2);
                break;

            default:
                break;
            }
            return(result);
        }
예제 #4
0
        public void PosTest2()
        {
            System.Globalization.Calendar tc = new TaiwanCalendar();
            DateTime dt = tc.MaxSupportedDateTime;

            Assert.Equal(12, tc.GetMonth(dt));
        }
예제 #5
0
        /// <summary>
        /// Convert the DateTime object to TaiwanCalendar DateTime format.
        /// For example: 2008/1/1 will become 97/1/1
        /// </summary>
        public static DateTime ToTaiwanDateTime(this DateTime d)
        {
            TaiwanCalendar tc = new TaiwanCalendar();

            DateTime result = new DateTime(tc.GetYear(d), tc.GetMonth(d), tc.GetDayOfMonth(d), d.Hour, d.Minute, d.Second, d.Millisecond);

            return(result);
        }
예제 #6
0
        /// <summary>
        /// 取得民國月
        /// </summary>
        /// <param name="datetime"></param>
        /// <returns></returns>
        public string TaiwanDateMonther(DateTime datetime)
        {
            if (datetime == DateTime.MinValue)
            {
                return(" ");
            }
            TaiwanCalendar taiwanCalendar = new TaiwanCalendar();

            return(string.Format("{0:00}", taiwanCalendar.GetMonth(datetime)));
        }
    public static void Main()
    {
        // Create an instance of the calendar.
        TaiwanCalendar myCal = new TaiwanCalendar();

        Console.WriteLine(myCal.ToString());

        // Create an instance of the GregorianCalendar.
        GregorianCalendar myGre = new GregorianCalendar();

        // Display the MinValue and its equivalent in the GregorianCalendar.
        DateTime myMin = myCal.MinSupportedDateTime;

        Console.Write("MinSupportedDateTime: {0:D2}/{1:D2}/{2:D4}", myCal.GetMonth(myMin), myCal.GetDayOfMonth(myMin), myCal.GetYear(myMin));
        Console.WriteLine(" (in Gregorian, {0:D2}/{1:D2}/{2:D4})", myGre.GetMonth(myMin), myGre.GetDayOfMonth(myMin), myGre.GetYear(myMin));

        // Display the MaxValue and its equivalent in the GregorianCalendar.
        DateTime myMax = myCal.MaxSupportedDateTime;

        Console.Write("MaxSupportedDateTime: {0:D2}/{1:D2}/{2:D4}", myCal.GetMonth(myMax), myCal.GetDayOfMonth(myMax), myCal.GetYear(myMax));
        Console.WriteLine(" (in Gregorian, {0:D2}/{1:D2}/{2:D4})", myGre.GetMonth(myMax), myGre.GetDayOfMonth(myMax), myGre.GetYear(myMax));
    }
예제 #8
0
        /// <summary>
        /// change datetime to Taiwan Datetime
        /// </summary>
        /// <param name="dateTime"></param>
        /// <param name="format">string format like "中華民國{0}年{1}月{2}日"</param>
        /// <param name="padLeftCount">年份要預留幾位數 像是 99年 或 099 年</param>
        /// <param name="padchar">補齊位數符號 default = 0</param>
        /// <param name="defaultDateTime"></param>
        /// <returns></returns>
        public static string AsTaiwanDateTime(this DateTime dateTime, string format, int padLeftCount, char padchar = '0',
                                              DateTime defaultDateTime = default(DateTime))
        {
            if (dateTime == null)
            {
                return(defaultDateTime.ToShortDateString());
            }

            DateTime       result = defaultDateTime;
            TaiwanCalendar tai    = new TaiwanCalendar();
            string         tmp    = string.Format(format,
                                                  tai.GetYear(dateTime).AsString().PadLeft(padLeftCount, padchar),
                                                  tai.GetMonth(dateTime),
                                                  dateTime.Day);

            return(tmp);
        }
예제 #9
0
        /// <summary>
        /// 102年11-12
        /// </summary>
        protected string GetMonth()
        {
            TaiwanCalendar tc = new TaiwanCalendar();

            string monFmt = string.Empty;

            switch (tc.GetMonth(ViewGUITrans.Current.GUIDate.Value))
            {
            case 1:
            case 2:
                monFmt = "01-02";
                break;

            case 3:
            case 4:
                monFmt = "03-04";
                break;

            case 5:
            case 6:
                monFmt = "05-06";
                break;

            case 7:
            case 8:
                monFmt = "07-08";
                break;

            case 9:
            case 10:
                monFmt = "09-10";
                break;

            case 11:
            case 12:
                monFmt = "11-12";
                break;
            }

            return(string.Format("{0}年{1}月", tc.GetYear(ViewGUITrans.Current.GUIDate.Value), monFmt));
        }
예제 #10
0
        public void PosTest1()
        {
            System.Globalization.Calendar tc = new TaiwanCalendar();
            Random rand  = new Random(-55);
            int    year  = rand.Next(tc.MinSupportedDateTime.Year, tc.MaxSupportedDateTime.Year - 1911);
            int    month = rand.Next(1, 12);
            int    day;

            if (tc.IsLeapYear(year))
            {
                day = rand.Next(1, _DAYS_PER_MONTHS_IN_LEAP_YEAR[month] + 1);
            }
            else
            {
                day = rand.Next(1, _DAYS_PER_MONTHS_IN_NO_LEAP_YEAR[month] + 1);
            }

            DateTime dt          = tc.ToDateTime(year, month, day, 0, 0, 0, 0);
            int      actualMonth = dt.Month;

            Assert.Equal(tc.GetMonth(dt), actualMonth);
        }
예제 #11
0
        protected override ResultStatus Export()
        {
            ExportShow.Text = "轉檔中...";
            ExportShow.Show();

            Workbook  workbook = new Workbook();
            DataTable dtAM2    = new DataTable();
            DataTable dtRPT    = new DataTable();
            DataTable dtAi2    = new DataTable();
            DataTable dtRamm1  = new DataTable();

            string   destinationFilePath = PbFunc.wf_copy_file(_ProgramID, _ProgramID);
            DateTime date       = txtDate.DateTimeValue;
            string   asParamKey = "TXO";
            int      oleRow     = 1;

            try {
                int noData = 0;
                workbook.LoadDocument(destinationFilePath);

                #region Get AM2 Data
                dtAM2 = daoAM2.ListAm2DataByYmd(date.ToString("yyyyMM"), asParamKey);

                if (dtAM2.Rows.Count <= 0)
                {
                    ExportShow.Hide();
                    MessageDisplay.Info(date + "," + _ProgramID + '-' + _ProgramName + ",無任何資料!");
                    noData += 1;
                    File.Delete(destinationFilePath);
                    return(ResultStatus.Fail);
                }
                #endregion

                Worksheet worksheet = workbook.Worksheets["30720"];

                #region Get RPT
                dtRPT = daoRPT.ListData("%" + _ProgramID + "%");

                if (dtRPT.Rows.Count <= 0)
                {
                    MessageDisplay.Info(_ProgramID + '-' + "RPT無任何資料!");
                    noData += 1;
                }
                //填寫日期
                TaiwanCalendar tai = new TaiwanCalendar();
                worksheet.Cells[0, 6].Value = tai.GetYear(date).ToString() + "年" + tai.GetMonth(date) + "月" + worksheet.Cells[0, 6].Value;
                worksheet.Cells[1, 4].Value = date.ToString("MMM", CultureInfo.CreateSpecificCulture("en-US")) + "." + date.Year.ToString() + worksheet.Cells[1, 4].Value;

                string paramKey = "";
                foreach (DataRow r in dtAM2.Rows)
                {
                    if (paramKey != (r["am2_param_key"].ToString().Trim()))
                    {
                        paramKey = r["am2_param_key"].ToString().Trim();
                        oleRow   = dtRPT.Rows.IndexOf(dtRPT.Select("trim(rpt_value) = '" + paramKey + "'")[0]);
                        if (oleRow >= 0)
                        {
                            oleRow = dtRPT.Rows[oleRow]["rpt_seq_no"].AsInt();
                        }
                    }

                    int oleCol = GetCol(r["am2_idfg_type"].AsInt(), r["am2_bs_code"].AsString());
                    if (oleRow > 0 && oleCol > 0)
                    {
                        worksheet.Cells[oleRow - 1, oleCol - 1].Value = r["am2_m_qnty"].AsInt();
                    }
                }
                #endregion

                #region Get AI2
                dtAi2 = daoAI2.ListAI2ByYmd(date.ToString("yyyyMM"), date.ToString("yyyyMM"), asParamKey);

                if (dtAi2.Rows.Count <= 0)
                {
                    MessageDisplay.Info(_ProgramID + '-' + "AI2無任何資料!");
                    noData += 1;
                }
                //切換sheet
                paramKey = "";
                foreach (DataRow r in dtAi2.Rows)
                {
                    if (paramKey != (r["ai2_param_key"].ToString().Trim()))
                    {
                        paramKey = r["ai2_param_key"].ToString().Trim();
                        oleRow   = dtRPT.Rows.IndexOf(dtRPT.Select("trim(rpt_value) = '" + paramKey + "'")[0]);
                        if (oleRow >= 0)
                        {
                            oleRow = dtRPT.Rows[oleRow]["rpt_seq_no"].AsInt();
                        }
                    }
                    if (oleRow > 0)
                    {
                        worksheet.Cells[oleRow - 1, 2].Value = r["ai2_m_qnty"].AsInt();
                        worksheet.Cells[oleRow - 1, 3].Value = r["ai2_oi"].AsInt();
                    }
                }
                #endregion

                #region Get Ramm1
                dtRamm1 = daoRamm1.ListRamm1Ymd(date.ToString("yyyyMM") + "01", date.ToString("yyyyMM") + "31", asParamKey);

                if (dtRamm1.Rows.Count <= 0)
                {
                    MessageDisplay.Info(_ProgramID + '-' + "Ramm1無任何資料!");
                    noData += 1;
                }

                paramKey = "";
                foreach (DataRow r in dtRamm1.Rows)
                {
                    if (paramKey != (r["param_key"].ToString().Trim()))
                    {
                        paramKey = r["param_key"].ToString().Trim();
                        oleRow   = dtRPT.Rows.IndexOf(dtRPT.Select("trim(rpt_value) = '" + paramKey + "'")[0]);
                        if (oleRow >= 0)
                        {
                            oleRow = dtRPT.Rows[oleRow]["rpt_seq_no"].AsInt();
                        }
                    }
                    if (oleRow > 0)
                    {
                        worksheet.Cells[oleRow - 1, 16].Value = r["bo"].AsInt();
                        worksheet.Cells[oleRow - 1, 17].Value = r["bq"].AsInt();
                        worksheet.Cells[oleRow - 1, 18].Value = r["so"].AsInt();
                        worksheet.Cells[oleRow - 1, 19].Value = r["sq"].AsInt();
                    }
                }
                #endregion

                workbook.SaveDocument(destinationFilePath);

                //全查無資料時, 刪除檔案
                if (noData == 4)
                {
                    File.Delete(destinationFilePath);
                }
            } catch (Exception ex) {
                ExportShow.Text = "轉檔失敗";
                throw ex;
            }
            ExportShow.Text = "轉檔成功!";
            return(ResultStatus.Success);
        }
예제 #12
0
        /// <summary>
        /// 取得民國年月日 (100年10月10日)
        /// </summary>
        public static string GetTaiwanChiDate(this DateTime dt)
        {
            TaiwanCalendar tc = new TaiwanCalendar();

            return(tc.GetYear(dt) + "年" + tc.GetMonth(dt) + "月" + tc.GetDayOfMonth(dt) + "日");
        }