GetYear() public method

public GetYear ( System.DateTime time ) : int
time System.DateTime
return int
コード例 #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string pUserID   = Session["ID"] + "";
        string pUserName = Session["name"] + "";

        //PostBack後停留在原畫面
        Page.MaintainScrollPositionOnPostBack = true;

        //全區公用↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

        TextUserName.Text = "您好," + pUserName + " " + Session["jobtitle"] + "";
        if (pUserName == "")
        {
            TextUserName.Visible = false;
            SignOut.Visible      = false;
        }

        //全區公用↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

        DateTime data       = DateTime.Now;
        var      taiwanyear = new System.Globalization.TaiwanCalendar();

        LBRPJ001.Text = "PJ" + taiwanyear.GetYear(data) + data.ToString("MM") + 000;

        //selectone();
        //年度
        Year();

        //TXTRPJ007.Attributes.Add("OnKeyPress", "txtkey();");
    }
コード例 #2
0
        //取德
        public void ToChineseDate()
        {
            DateTime dNow = DateTime.Now;

            System.Globalization.TaiwanCalendar tc = new System.Globalization.TaiwanCalendar();
            DateTime d = new DateTime(2010, 8, 18, 1, 0, 0);


            string dateString2 = string.Format("{0:000}.{1:00}.{2:00}-{3:00}", tc.GetYear(d), tc.GetMonth(d), tc.GetDayOfMonth(d), d.Hour + 1);
            string dateString1 = string.Format("民國{0:000}年{1:00}月{2:00}日", tc.GetYear(d), tc.GetMonth(d), tc.GetDayOfMonth(d));
            string dateString3 = string.Format("-{0:00}", d.Hour + 1);


            Console.WriteLine(dateString1);
            Console.WriteLine(dateString2);
            Console.WriteLine(dateString3);
        }
コード例 #3
0
        /// <summary>
        /// 取得現在民國日期時間{yyy.MM.dd-HH}
        /// </summary>
        /// <returns></returns>
        private string GetTaiwanCalendarDateTime()
        {
            System.Globalization.TaiwanCalendar tc = new System.Globalization.TaiwanCalendar();
            DateTime d    = DateTime.Now;
            int      hour = d.Hour;

            if (d.Minute != 0 || d.Second != 0) //判斷非整點無條件進位
            {
                hour++;                         //直接+1 23點多顯示24
            }
            string result = string.Format("{0:000}.{1:00}.{2:00}-{3:00}", tc.GetYear(d), tc.GetMonth(d), tc.GetDayOfMonth(d), hour);

            return(result);
        }
コード例 #4
0
ファイル: DropOutForm.cs プロジェクト: ischoolinc/SH_DropOut
        private string GetServerTimeTW() //取得Server的時間
        {
            QueryHelper Sql        = new QueryHelper();
            DataTable   dtable     = Sql.Select("select now()"); //取得時間
            DateTime    serverdata = DateTime.Now;

            DateTime.TryParse("" + dtable.Rows[0][0], out serverdata); //Parse資料

            //西元年轉換民國年
            string   dataString3    = serverdata.ToString("yyyyMMdd");
            DateTime dt3            = DateTime.ParseExact(dataString3, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
            var      taiwanCalender = new System.Globalization.TaiwanCalendar();
            var      dateTime3      = string.Format("{0} 年 {1} 月 {2} 日", taiwanCalender.GetYear(dt3), dt3.Month, dt3.Day);

            return(dateTime3);
        }
コード例 #5
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 + 1);
            int month = rand.Next(1, 12);
            int day;
            if (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 = new DateTime(year, month, day);

            int actualYear = dt.Year - 1911;
            Assert.Equal(tc.GetYear(dt), actualYear);
        }
コード例 #6
0
 public void PosTest3()
 {
     System.Globalization.Calendar tc = new TaiwanCalendar();
     DateTime dt = tc.MinSupportedDateTime;
     Assert.Equal(tc.GetYear(dt), 1);
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: RickNcyu/ConsoleApp13
        //static string connectionString = @"Server=localhost;Database=postgres;User ID=postgres;Password=1234;";
        static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();


            DateTime date           = DateTime.Today;
            var      taiwanCalendar = new System.Globalization.TaiwanCalendar();
            var      datetime       = string.Format("{0}{1}{2}", taiwanCalendar.GetYear(date), date.Month.ToString("00"), date.Day.ToString("00"));
            string   path           = @"C:\PosSystem\data\" + datetime + "_bkp_c#.sql";
            string   pathdes        = @"C:/down/need.txt";

            string pathlast = @"C:/down/last.txt";
            //確認stack是不是空的
            int top = 0;

            /*
             *  while (true)
             *  {
             *  using (var file = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite))
             *  {
             *
             *      var reader = new StreamReader(file);
             *      var line = reader.ReadToEnd();
             *      Console.WriteLine(line);
             *      using (var wrfile = new FileStream(pathdes, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
             *      {
             *
             *
             *          var writer = new StreamWriter(wrfile);
             *          writer.Write(line);
             *          writer.Flush();
             *      }
             *  }
             *
             *      Thread.Sleep(2000);
             *  }
             */
            while (true)
            {
                //sql如果不存在==>12點過後還沒有產生最新一筆交易
                if (File.Exists(path))
                {
                    /*//沒有交易 空白的
                     * if (File.ReadAllText(pathdes) == "") {
                     *
                     *  System.Environment.Exit(0);
                     * }*/

                    //讀取集點設定值
                    //File.Copy(path, pathdes, true);
                    //Console.WriteLine(File.ReadAllText(path));

                    using (var file = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite))
                    {
                        var reader = new StreamReader(file);
                        var line   = reader.ReadToEnd();
                        Console.WriteLine(line);
                        using (var wrfile = new FileStream(pathdes, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
                        {
                            var writer = new StreamWriter(wrfile);
                            writer.Write(line);
                            writer.Flush();
                        }
                    }


                    Stack temp = new Stack();
                    Stack last = new Stack();



                    //判斷有沒有last
                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:/down/last.txt", true, System.Text.Encoding.Default))
                    {
                        last.Push("null");
                        file.Close();
                    };
                    //上一筆最新資料
                    foreach (var line in File.ReadLines(pathlast).Reverse())
                    {
                        last.Push(line);
                    }
                    //最新資料比對
                    foreach (var line in File.ReadLines(pathdes).Reverse())
                    {
                        if (line.Contains("tran_detl_tmp"))
                        {
                            temp.Push(line);
                            top++;
                        }

                        if (line.Contains("tran_tmp"))
                        {
                            temp.Push(line);
                            top++;
                            break;
                        }
                    }


                    using (StreamWriter svw = new StreamWriter(pathlast))
                    {
                        foreach (string str in temp)
                        {
                            svw.WriteLine(str);
                        }
                    }
                    if (top == 0)
                    { //Console.WriteLine("空的");
                        System.Environment.Exit(0);
                    }
                    //Console.Read();
                    string ls1, ls2;
                    ls1 = temp.Peek().ToString();
                    Console.WriteLine(ls1);
                    ls2 = last.Peek().ToString();
                    Console.WriteLine(ls2);
                    Console.WriteLine(string.Compare(ls1, ls2));

                    //與上一筆資料不同 有新資料
                    if (string.Compare(ls1, ls2) != 0)
                    {
                        Console.WriteLine("yes");


                        //Stack存放最新一筆資料
                        //PrintValues(temp);
                        double Ans = 0;
                        Ans = PointCheck(temp);
                        //Console.WriteLine(Ans);

                        Console.WriteLine(Global.name);

                        /*
                         * string WT1 = "Test Print";
                         * string B1 = DateTime.Now.ToString("yyyy/MM/dd  HH:mm:ss", CultureInfo.InvariantCulture);
                         * byte[] result_unicode = System.Text.Encoding.GetEncoding("utf-16").GetBytes("unicode test");
                         * byte[] result_utf8 = System.Text.Encoding.UTF8.GetBytes("TEXT 40,620,\"ARIAL.TTF\",0,12,12,\"utf8 test Wörter auf Deutsch\"");
                         * System.Diagnostics.Debug.WriteLine(B1);
                         * //TSCLIB_DLL.about();
                         * byte status = TSCLIB_DLL.usbportqueryprinter();//0 = idle, 1 = head open, 16 = pause, following <ESC>!? command of TSPL manual
                         * TSCLIB_DLL.openport("TSC TTP-243E Pro");
                         * TSCLIB_DLL.sendcommand("SIZE 40 mm, 20 mm");
                         * TSCLIB_DLL.sendcommand("SPEED 4");
                         * TSCLIB_DLL.sendcommand("DENSITY 12");
                         * TSCLIB_DLL.sendcommand("DIRECTION 1");
                         * TSCLIB_DLL.sendcommand("SET TEAR ON");
                         * TSCLIB_DLL.sendcommand("CODEPAGE UTF-8");
                         *
                         * TSCLIB_DLL.clearbuffer();
                         * //TSCLIB_DLL.downloadpcx("UL.PCX", "UL.PCX");
                         * TSCLIB_DLL.windowsfont(0, 0, 40, 0, 0, 0, "Arial", Global.name);
                         * TSCLIB_DLL.windowsfont(10, 40, 30, 0, 0, 0, "Arial", DateTime.Now.ToString("yyyy/MM/dd  HH:mm:ss"));
                         *
                         * //TSCLIB_DLL.windowsfontUnicode(40, 550, 48, 0, 0, 0, "Arial", result_unicode);
                         * //TSCLIB_DLL.sendcommand("PUTPCX 40,40,\"UL.PCX\"");
                         * //TSCLIB_DLL.sendBinaryData(result_utf8, result_utf8.Length);
                         * TSCLIB_DLL.barcode("10", "70", "128", "35", "0", "0", "1", "1", B1);
                         * TSCLIB_DLL.windowsfont(10, 110, 50, 0, 0, 0, "Arial", "點數" + Ans.ToString() + "點");
                         * //TSCLIB_DLL.printerfont("20", "40", "0", "0", "15", "15", WT1);
                         * TSCLIB_DLL.printlabel("1", "1");
                         * TSCLIB_DLL.closeport();
                         */
                        sw.Stop();
                        TimeSpan ts2 = sw.Elapsed;
                        Console.WriteLine("Stopwatch總共花費{0}ms.", ts2.TotalMilliseconds);
                    }
                    //Thread.Sleep(2000);
                }
            }
            //Console.Read();
        }
コード例 #8
0
        private void button2_Click(object sender, EventArgs e)
        {

            label3.Text = "";
            /*test*/
            System.Globalization.CultureInfo tc = new System.Globalization.CultureInfo("zh-TW");
            //tc.DateTimeFormat.Calendar = new System.Globalization.TaiwanLunisolarCalendar();
            DateTime dt2 = DateTime.Now;
            //label5.Text = dt2.ToString(tc); ;
            /*test2*/
            CultureInfo m_ciTaiwan = new CultureInfo("zh-TW");
            m_ciTaiwan.DateTimeFormat.Calendar = m_ciTaiwan.OptionalCalendars[2];

            string strDate = DateTime.Now.Date.ToString("yyyyMMdd", m_ciTaiwan);

           // label4.Text=strDate;//output:1000512

            DateTime dtNow = DateTime.ParseExact(strDate.PadLeft(8, '0'), "yyyyMMdd", m_ciTaiwan);


            /*test3*/
           
            /**/
            string dd = dateTimePicker1.Text;
            dd = dd.Replace("年", ",").Replace("月", ",").Replace("日", ",");
            string[] ddd = { " ", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", "二十一", "二十二", "二十三", "二十四", "二十五", "二十六", "二十七", "二十八", "二十九", "三十", "三十一" };
            string[] ss = { "", "秦廣王", "楚江王", "宋帝王", "伍官王", "閻羅王", "變成王", "泰山王", "平等王", "都市王", "輪轉王" };
            string[] arrday = { "", "首七", "二七", "三七", "四七", "五七", "六七", "滿七", "百日", "對年" };
            string[] arr = dd.Split(",".ToCharArray());
            Dictionary<int,int> lsCalendar = new Dictionary<int,int>() { {2020,4 } }
            int a = (int)decimal.Parse(arr[0]);
            int b = (int)decimal.Parse(arr[1]);
            int c = (int)decimal.Parse(arr[2]);

            DateTime dtObj = new DateTime(2018, 6, 11);

            //以 月份 日, 年 的格式輸出
            string outputDate = dtObj.ToString("MMMM dd, yyyy", new CultureInfo("zh-tw"));
            //label7.Text = outputDate;
            DateTime dt = new DateTime(a, b, c);
            Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-tw");
            System.Globalization.TaiwanCalendar TC = new System.Globalization.TaiwanCalendar();
            System.Globalization.TaiwanLunisolarCalendar TA = new System.Globalization.TaiwanLunisolarCalendar();
            label1.Text = string.Format("民國:{0}/{1}/{2}", TC.GetYear(dt), TC.GetMonth(dt), TC.GetDayOfMonth(dt)) ;
            
            // label2.Text = string.Format("農歷:{0}<br>", TA.AddDays(dt, 99));
            //label4.Text = string.Format("民國:{0}/{1}/{2}",TA.GetYear(), )

            int count = 4;

            for (int i = 1; i <= 7; i++)
            {
                //做七
                int d = 7 * i;
                int dn;
                //  label3.Text += arrday[i] + " " + dt.AddDays(d - 1).ToString("MMMM dd, yyyy", new CultureInfo("zh-tw")) + Environment.NewLine;
                if (i == 2) {
                    dn = int.Parse(dt.AddDays((d/2) - 1).ToString("dd"));
                    label3.Text += "地方風俗 " +"      " + dt.AddDays((d/2) - 2).ToString("MM 月dd", new CultureInfo("zh-tw")) + "日" + Environment.NewLine;
                }
                dn = int.Parse(dt.AddDays(d - 1).ToString("dd"));
                label3.Text += ss[i].PadRight(4,' ') + " " + arrday[i] + " " + dt.AddDays(d - 1).ToString("MM 月dd", new CultureInfo("zh-tw")) +"日"+Environment.NewLine;
               
                count += 1;
            }
            //百日
            label6.Text = dt.AddDays(99).ToString("yyyy年MM月dd日 ", new CultureInfo("zh-tw"));
            //對年
            string result = string.Empty;
            System.Globalization.TaiwanLunisolarCalendar tls = new System.Globalization.TaiwanLunisolarCalendar();
            DateTime begin = tls.AddDays(DateTime.Now, 0);

            Boolean leap = tls.IsLeapYear(TA.GetYear(dt));
            DateTime dtt = tls.ToDateTime(TA.GetYear(dt), TA.GetMonth(dt), TA.GetDayOfMonth(dt), 0, 0, 0, 0);
            
            if (leap)
              {
                //label5.Text = "適逢"+ TA.GetYear(dt.AddYears(1) )+ "年閏月,因而農曆月份須提前一個月";
                System.Diagnostics.Debug.WriteLine(a);
                if (TA.GetMonth(dtt) > lsCalendar[(int)a])
                {
                    
                    dtt = tls.AddMonths(dtt,-1);
                }

            }
            label2.Text = string.Format("農曆:{0}/{1}/{2}", TA.GetYear(dtt), TA.GetMonth(dtt), TA.GetDayOfMonth(dtt));
            dtt = tls.AddYears(dtt, 1);

            TimeSpan tss = dtt - begin;
            int day = tls.GetDayOfMonth(dtt);
            int month = tls.GetMonth(dtt);
            int year = tls.GetYear(dtt);
           
            label4.Text = string.Format("國歷{3}\n農曆{0}年{1}月{2}日", year, month, day, DateTime.Now.Add(tss).ToString("yyyy/MM/dd"));
            

        }
コード例 #9
0
ファイル: GBClass001.cs プロジェクト: audreyt/SWCWeb
    public string DateView(string gValue, string oType)
    {
        //00:2017-12-12
        //01:
        //02:106.12.12
        //03:2016年04月13日
        //04:106-12-12

        string rValue = "";

        try
        {
            switch (oType)
            {
            case "00":
                rValue = Convert.ToDateTime(gValue).ToString("yyyy-MM-dd");
                break;

            case "01":
                System.Globalization.TaiwanCalendar tc = new System.Globalization.TaiwanCalendar();
                DateTime d;
                if (DateTime.TryParse(gValue, out d))
                {
                    d      = Convert.ToDateTime(gValue);
                    rValue = String.Format("{0}年{1}月{2}日", tc.GetYear(d), tc.GetMonth(d), tc.GetDayOfMonth(d));
                }
                break;

            case "02":
                System.Globalization.TaiwanCalendar tc2 = new System.Globalization.TaiwanCalendar();
                DateTime d2;
                if (DateTime.TryParse(gValue, out d2))
                {
                    d2     = Convert.ToDateTime(gValue);
                    rValue = String.Format("{0}.{1:00}.{2:00}", tc2.GetYear(d2), tc2.GetMonth(d2), tc2.GetDayOfMonth(d2));
                }
                break;

            case "03":
                rValue = Convert.ToDateTime(gValue).ToString("yyyy年MM月dd日");
                break;

            case "04":
                System.Globalization.TaiwanCalendar tc4 = new System.Globalization.TaiwanCalendar();
                DateTime d4;
                if (DateTime.TryParse(gValue, out d2))
                {
                    d2     = Convert.ToDateTime(gValue);
                    rValue = String.Format("{0}-{1:00}-{2:00}", tc4.GetYear(d2), tc4.GetMonth(d2), tc4.GetDayOfMonth(d2));
                }
                break;
            }
        }
        catch
        {
            rValue = gValue;
        }

        if (gValue != "")
        {
            if (gValue.Substring(0, 4) == "1900")
            {
                rValue = "";
            }
        }
        return(rValue);
    }
コード例 #10
0
ファイル: WebMonthPicker.cs プロジェクト: san90279/UK_OAS
 private void InitialItems(string selectedValue)
 {
     DateTime SelectedDate = DateTime.Today;
     if (!string.IsNullOrEmpty(selectedValue))
     {
         if (!DateTime.TryParseExact(selectedValue, "yyyyMM", new CultureInfo("en-us"), DateTimeStyles.None, out SelectedDate))
         {
             throw new FormatException(string.Format("{0} can not recgonized as yyyyMM", selectedValue));
         }
     }
     string format = RocYear ? "{0:000}" + Separator + "{1:00}" : "{0:0000}" + Separator + "{1:00}";
     this.Items.Clear();
     TaiwanCalendar twCalendar = new TaiwanCalendar();
     this.Items.Add(new ListItem(RocYear ? string.Format(format, twCalendar.GetYear(SelectedDate), twCalendar.GetMonth(SelectedDate))
         : string.Format(format, SelectedDate.Year, SelectedDate.Month), SelectedDate.ToString("yyyyMM", new CultureInfo("en-us"))));
     for (int i = 1; i <= MonthScope; i++)
     {
         DateTime date = SelectedDate.AddMonths(-i);
         this.Items.Insert(0, new ListItem(RocYear ? string.Format(format, twCalendar.GetYear(date), twCalendar.GetMonth(date))
             : string.Format(format, date.Year, date.Month), date.ToString("yyyyMM", new CultureInfo("en-us"))));
         date = SelectedDate.AddMonths(i);
         this.Items.Add(new ListItem(RocYear ? string.Format(format, twCalendar.GetYear(date), twCalendar.GetMonth(date))
             : string.Format(format, date.Year, date.Month), date.ToString("yyyyMM", new CultureInfo("en-us"))));
     }
     base.SelectedValue = SelectedDate.ToString("yyyyMM", new CultureInfo("en-us"));
 }
コード例 #11
0
ファイル: WebMonthPicker.cs プロジェクト: san90279/UK_OAS
 protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
 {
     if (this.DesignMode)
     {
         writer.AddAttribute(HtmlTextWriterAttribute.Selected, "selected");
         writer.AddAttribute(HtmlTextWriterAttribute.Value, DateTime.Today.ToString("yyyyMM", new CultureInfo("en-us")));
         writer.RenderBeginTag(HtmlTextWriterTag.Option);
         TaiwanCalendar twCalendar = new TaiwanCalendar();
         string format = RocYear ? "{0:000}" + Separator + "{1:00}" : "{0:0000}" + Separator + "{1:00}";
         writer.Write(RocYear ? string.Format(format, twCalendar.GetYear(DateTime.Today), twCalendar.GetMonth(DateTime.Today))
         : string.Format(format, DateTime.Today.Year, DateTime.Today.Month));
         writer.RenderEndTag();
     }
     else
     {
         base.RenderContents(writer);
     }
 }
コード例 #12
0
ファイル: DropOutForm.cs プロジェクト: ischoolinc/SH_DropOut
        private void _bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Document doc      = new Document();
            Document template = null;

            if (radioButton1.Checked == true)
            {
                //選擇預設範本時的動作
                template = new Document(new MemoryStream(defalutTemplate));
            }
            else if (radioButton2.Checked == true)
            {            //選擇自訂範本時的動作
                //School.Configuration.Remove(cd);
                //return;
                string str = cd["CustomizeTemplate"];

                if (template == null)
                {
                    try
                    {
                        template = (new Document(new MemoryStream(Convert.FromBase64String(str)))).Clone();
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidOperationException("尚未上傳自訂樣板");
                        //MsgBox.Show("尚未上傳自訂樣板");
                        //return;
                    }

                    //template = new Document(new MemoryStream(defalutTemplate));
                }
            }
            else
            {
                MsgBox.Show("");
                return;
            }
            //取得文號、字號、學年度學期取得
            string No1        = textBoxX1.Text;
            string No2        = textBoxX2.Text;
            int    schoolYear = int.Parse(K12.Data.School.DefaultSchoolYear);
            int    semester   = int.Parse(K12.Data.School.DefaultSemester);
            //取得學校名稱
            string DSNSName  = SHSchool.Data.SHSchoolInfo.ChineseName;
            string Principal = K12.Data.School.Configuration["學校資訊"].PreviousData.SelectSingleNode("ChancellorChineseName").InnerText;



            string dataString1 = dateTimeInput1.Value.ToString("yyyyMMdd");
            string dataString2 = dateTimeInput2.Value.ToString("yyyyMMdd");

            DateTime dt1            = DateTime.ParseExact(dataString1, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
            DateTime dt2            = DateTime.ParseExact(dataString2, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
            var      taiwanCalender = new System.Globalization.TaiwanCalendar();
            var      dateTime1      = string.Format("{0} 年 {1} 月 {2} 日", taiwanCalender.GetYear(dt1), dt1.Month, dt1.Day);
            var      dateTime2      = string.Format("{0} 年 {1} 月 {2} 日", taiwanCalender.GetYear(dt2), dt2.Month, dt2.Day);



            #region 取得選取學生
            List <SHStudentRecord>      studentAll   = SHStudent.SelectByIDs(studentIds);
            List <SHUpdateRecordRecord> updateRecord = SHUpdateRecord.SelectByStudentIDs(studentIds);

            Dictionary <string, StudentObj> dic = new Dictionary <string, StudentObj>();
            foreach (SHUpdateRecordRecord urr in updateRecord)
            {
                if (dic.ContainsKey(urr.StudentID))
                {
                    SHUpdateRecordRecord old = dic[urr.StudentID].URR;
                    int newSchoolYear        = urr.SchoolYear.HasValue ? urr.SchoolYear.Value : 0;
                    int newSemester          = urr.Semester.HasValue ? urr.Semester.Value : 0;
                    int oldSchoolYear        = old.SchoolYear.HasValue ? old.SchoolYear.Value : 0;
                    int oldSemester          = old.Semester.HasValue ? old.Semester.Value : 0;

                    if (newSchoolYear > oldSchoolYear)
                    {
                        dic[urr.StudentID].URR = urr;
                    }
                    else if (newSchoolYear == oldSchoolYear)
                    {
                        if (newSemester > oldSemester)
                        {
                            dic[urr.StudentID].URR = urr;
                        }
                    }
                }
                if (updateCode.Contains(urr.UpdateCode) && !dic.ContainsKey(urr.StudentID))
                {
                    dic.Add(urr.StudentID, new StudentObj());
                    dic[urr.StudentID].URR = urr;
                }
            }
            foreach (SHStudentRecord sr in studentAll)
            {
                if (dic.ContainsKey(sr.ID))
                {
                    dic[sr.ID].Student = sr;
                }
            }
            #endregion
            Dictionary <string, object> merge = new Dictionary <string, object>();
            string serverTime   = GetServerTime();
            string serverTimeTW = GetServerTimeTW();

            foreach (StudentObj obj in dic.Values)
            {
                Document perPage = template.Clone();
                merge.Clear();

                merge.Add("起始時間", dateTimeInput1.Value.ToString("yyyy年MM月dd日"));
                merge.Add("訖末時間", dateTimeInput2.Value.ToString("yyyy年MM月dd日"));
                merge.Add("起始時間(民國)", dateTime1);
                merge.Add("訖末時間(民國)", dateTime2);
                merge.Add("編字", No1);
                merge.Add("編號", No2);
                merge.Add("年級", schoolYear);
                merge.Add("學期", semester);
                merge.Add("學校名稱", DSNSName);
                merge.Add("校長姓名", Principal);
                merge.Add("列印日期", serverTime);
                merge.Add("列印日期(民國)", serverTimeTW);
                merge.Add("學生姓名", obj.Student.Name);
                merge.Add("學號", obj.Student.StudentNumber);
                merge.Add("休學年級", obj.URR.GradeYear);
                merge.Add("休學學期", obj.URR.Semester);
                merge.Add("科系", obj.URR == null ? string.Empty : obj.URR.Department);
                merge.Add("休學事由", obj.URR == null ? string.Empty : obj.URR.UpdateDescription);


                perPage.MailMerge.Execute(merge.Keys.ToArray <string>(), merge.Values.ToArray <object>());
                perPage.MailMerge.RemoveEmptyParagraphs = true;
                perPage.MailMerge.DeleteFields();

                doc.Sections.Add(doc.ImportNode(perPage.Sections[0], true));
            }
            doc.Sections.RemoveAt(0);
            e.Result = doc;
        }