コード例 #1
0
        //http://192.168.0.12:81/HRMail/AbnSendMail?key=89947155
        /// <summary>
        /// 出勤異常通知 寄E-mail事件
        /// </summary>
        public EmptyResult AbnSendMail(string Key, string Company)
        //(string Key)
        {
            try
            {
                if (Key == "89947155")
                {
                    ModelFactory.Company = Company;
                    ThreadStart ts = new ThreadStart(ModelFactory.AbnSendMail);
                    Thread      t  = new Thread(ts);
                    t.Start();

                    RegalLib.LogOutput("已觸發出勤異常通知!", "AbnSendMail");
                }
                else
                {
                    RegalLib.LogOutput("觸發出勤異常通知時,KEY值錯誤!", "AbnSendMail");
                }
            }
            catch (Exception ex)
            {
                RegalLib.LogOutput("觸發出勤異常通知時,發生問題! " + ex.Message, "AbnSendMail");
            }


            return(new EmptyResult());
        }
コード例 #2
0
        /// <summary>
        /// 寄出異常E-Mail
        /// </summary>
        public void AbnSendMail()
        {
            List <AttendanceModel> AttAbnList = GetAttAbnList(Company);

            if (AttAbnList.Count == 0)
            {
                return;
            }

            var tmpList = from tmp in AttAbnList
                          group tmp by new { tmp.EmployeeNo, tmp.EmployeeEName } into g
                select new { EmployeeNo = g.Key.EmployeeNo, EmployeeEName = g.Key.EmployeeEName };

            string Html = "";


            //*** 寄給個人「個人出勤異常通知」  ***
            foreach (var tmp in tmpList)
            {
                DataTable dt = DbAccess.ExecuteDataTable("SELECT mail FROM LDAPUsers WHERE description=@description AND mail <> ''",
                                                         new DbParameter[] {
                    DataAccess.CreateParameter("description", DbType.String, tmp.EmployeeNo.ToString())
                }
                                                         );

                if (dt.Rows.Count == 1)
                {
                    //代表有找到對應的 E-MAIL  - 寄出信件

                    var tmpAttAbnList = (from tmpAttAbn in AttAbnList
                                         where tmpAttAbn.EmployeeNo == tmp.EmployeeNo
                                         select tmpAttAbn).ToList();

                    Html = "<h2>Dear " + tmp.EmployeeEName + " :</h2> ";

                    Html += "<h3>系統寄發時間 : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "</h3> ";
                    Html += "<h3>如對於出勤有任何疑問,請於當日中午前,向財務部提出說明。</h3>";

                    Html += "<table width='100%' border='1'>";
                    Html += "<tr>";
                    Html += "<th align='center'>員工編號</th>";
                    Html += "<th align='center'>部門</th>";
                    Html += "<th align='center'>姓名</th>";
                    Html += "<th align='center'>英文名</th>";
                    Html += "<th align='center'>上班日期</th>";
                    Html += "<th align='center'>上班時間</th>";
                    Html += "<th align='center'>下班時間</th>";
                    Html += "<th align='center'>加班上班</th>";
                    Html += "<th align='center'>加班下班</th>";
                    Html += "<th align='center'>出勤描述(上午)</th>";
                    Html += "<th align='center'>出勤描述(下午)</th>";
                    Html += "<th align='center'>出勤描述(加班)</th>";
                    Html += "<th align='center'>遲到</th>";
                    Html += "</tr>";

                    foreach (var tmp2 in tmpAttAbnList)
                    {
                        Html += "<tr>";
                        Html += "<td align='center'>" + tmp2.EmployeeNo + "</td>";
                        Html += "<td align='center'>" + tmp2.DepartMentName + "</td>";
                        Html += "<td align='center'>" + tmp2.EmployeeName + "</td>";
                        Html += "<td align='center'>" + tmp2.EmployeeEName + "</td>";
                        Html += "<td align='center'>" + tmp2.WorkDay + "</td>";

                        Html += "<td align='center'>" + tmp2.StartWorkTime + "</td>";
                        Html += "<td align='center'>" + tmp2.EndWorkTime + "</td>";
                        Html += "<td align='center'>" + tmp2.StartWorkOvertime + "</td>";
                        Html += "<td align='center'>" + tmp2.EndWorkOvertime + "</td>";
                        //Html += "<td align='center'>" + tmp2.AttendanceDesc + "</td>";

                        // Scott 1129 修改 將出勤欄位 分為 上午、下午、加班 3欄
                        Html += "<td align='center'>" + tmp2.AttendanceDescM + "</td>";
                        Html += "<td align='center'>" + tmp2.AttendanceDescN + "</td>";
                        Html += "<td align='center'>" + tmp2.AttendanceDescOT + "</td>";
                        Html += "<td align='center'>" + tmp2.LateMin + "</td>";
                        Html += "</tr>";
                    }
                    Html += "</table>";

                    try
                    {
                        Mail_Send(new string[] { dt.Rows[0]["mail"].ToString() }, new string[] { }, "個人出勤異常通知!", Html);
                        //Mail_Send(new string[] { "*****@*****.**" }, new string[] { }, "個人出勤異常通知!", Html);
                        RegalLib.LogOutput("個人出勤異常通知-寄出成功! 員工編號:" + tmp.EmployeeNo + ",E-Mail:" + dt.Rows[0]["mail"].ToString(), "AbnSendMail");
                    }
                    catch (Exception ex)
                    {
                        RegalLib.LogOutput("個人出勤異常通知-寄出失敗! 員工編號:" + tmp.EmployeeNo + ",E-Mail:" + dt.Rows[0]["mail"].ToString() + ",ErrMsg:" + ex.Message, "AbnSendMail");
                    }
                }
                else
                {
                    RegalLib.LogOutput("個人出勤異常通知-寄出失敗! 員工編號:" + tmp.EmployeeNo + " E-Mail有誤!", "AbnSendMail");
                } //if end
            }     //foreach end


            //*** 寄給天使「員工出勤異常清單」 ***
            Html = "<h2>Dear Angel:</h2> ";

            Html += "<h3>系統寄發時間 : " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "</h3> ";

            Html += "<table width='100%' border='1'>";

            Html += "<tr>";
            Html += "<th align='center'>員工編號</th>";
            Html += "<th align='center'>部門</th>";
            Html += "<th align='center'>姓名</th>";
            Html += "<th align='center'>英文名</th>";
            Html += "<th align='center'>上班日期</th>";
            Html += "<th align='center'>上班時間</th>";
            Html += "<th align='center'>下班時間</th>";
            Html += "<th align='center'>加班上班</th>";
            Html += "<th align='center'>加班下班</th>";
            Html += "<th align='center'>出勤描述(上午)</th>";
            Html += "<th align='center'>出勤描述(下午)</th>";
            Html += "<th align='center'>出勤描述(加班)</th>";
            Html += "<th align='center'>遲到</th>";
            Html += "</tr>";

            foreach (var tmp in AttAbnList)
            {
                Html += "<tr>";
                Html += "<td align='center'>" + tmp.EmployeeNo + "</td>";
                Html += "<td align='center'>" + tmp.DepartMentName + "</td>";
                Html += "<td align='center'>" + tmp.EmployeeName + "</td>";
                Html += "<td align='center'>" + tmp.EmployeeEName + "</td>";
                Html += "<td align='center'>" + tmp.WorkDay + "</td>";

                Html += "<td align='center'>" + tmp.StartWorkTime + "</td>";
                Html += "<td align='center'>" + tmp.EndWorkTime + "</td>";
                Html += "<td align='center'>" + tmp.StartWorkOvertime + "</td>";
                Html += "<td align='center'>" + tmp.EndWorkOvertime + "</td>";
                //Html += "<td align='center'>" + tmp.AttendanceDesc + "</td>";
                // Scott 1129 修改 將出勤欄位 分為 上午、下午、加班 3欄
                Html += "<td align='center'>" + tmp.AttendanceDescM + "</td>";
                Html += "<td align='center'>" + tmp.AttendanceDescN + "</td>";
                Html += "<td align='center'>" + tmp.AttendanceDescOT + "</td>";
                Html += "<td align='center'>" + tmp.LateMin + "</td>";
                Html += "</tr>";
            }
            Html += "</table>";

            try
            {
                string title = "";
                if (Company == "TPE")
                {
                    title = "台北-";
                }
                if (Company == "TXG")
                {
                    title = "台中-";
                }
                if (Company == "TNN")
                {
                    title = "台南-";
                }
                if (Company == "SU")
                {
                    title = "蘇州-";
                }

                Mail_Send(new string[] { "*****@*****.**" }, new string[] { }, title + "員工出勤異常清單!", Html);
                //Mail_Send(new string[] { "*****@*****.**" }, new string[] { }, title + "員工出勤異常清單!", Html);
                RegalLib.LogOutput("員工出勤異常清單-寄出成功!", "AbnSendMail");
            }
            catch
            {
                RegalLib.LogOutput("員工出勤異常清單-寄出失敗!", "AbnSendMail");
            }
        }