예제 #1
0
        public void doWork()
        {
            string smtpHost   = string.Empty;
            string smtpUserId = string.Empty;
            string smtpPasswd = string.Empty;
            string smtpSender = string.Empty;

            smtpHost   = FtdConfigService.Instance.getAppSettingValue("SmtpHost");
            smtpUserId = FtdConfigService.Instance.getAppSettingValue("SmtpUserId");
            smtpPasswd = FtdConfigService.Instance.getAppSettingValue("SmtpPasswd");
            smtpSender = FtdConfigService.Instance.getAppSettingValue("SmtpSender");

            StringBuilder          sb           = new StringBuilder();
            string                 errorMsg     = string.Empty;
            SY_NewsDataTable       dtNews       = new SY_NewsDataTable();
            SY_NewsObjectDataTable dtNewsObject = new SY_NewsObjectDataTable();

            AppAgentLog.writeLog(string.Format("排程開始同步資料[{0}] : {1}", "", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")));
            DateTime DT = DateTime.Now;

            try
            {
                #region //查詢系統日之前未寄出的通知
                var dt = NsDmHelper.SY_MailList
                         .selectAll(t => t.AllPhysical)
                         .where (t => t.SYML_EventTime.tostring(NsDataFormat.DATE_YYYYMMDD) <= DateTime.Now.ToString("yyyyMMdd")
                                 & t.SYML_IsSent == "N"
                                 & t.SYML_NotifyWay == "A"
                                 & t.SYML_Target != null
                                 ).query();

                foreach (var row in dt.TypeRows)
                {
                    string email = row.SYML_Target;
                    try
                    {
                        //信件內容控制
                        StringBuilder sb1   = new StringBuilder();
                        string        tBody = string.Empty;
                        sb1.Append("<font size=3 color=\"black\">" + row.SYML_Message + "</font><br>");
                        tBody = "<html><body><tr><td>" + sb1.ToString() + "</td></tr></body></html>";

                        MailMessage message = new MailMessage(smtpSender, email, row.SYML_MsgTypeName_XX, tBody);

                        message.IsBodyHtml = true;
                        SmtpClient client = new SmtpClient(smtpHost);
                        client.Credentials = new NetworkCredential(smtpUserId, smtpPasswd);
                        client.Send(message);

                        row.SYML_IsSent       = "Y";
                        row.SYML_RealSentTime = DateTime.Now;

                        var scope = new FdbTransScope(FdbTransScopeOption.Required);
                        using (scope.Use)
                        {
                            dt.ns_update();
                            scope.complete();
                            dt.AcceptChanges();
                        }
                    }
                    catch (Exception e)
                    {
                        sb.Append("發送mail失敗, 訊息 : " + e.Message + Environment.NewLine);
                    }
                }
                #endregion

                AppAgentLog.writeLog(string.Format("完成同步資料[{0}] : {1}", GetType().Name, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")));
                string split = new string('-', 30);
                AppAgentLog.writeLog(split);
            }
            catch (Exception ex)
            {
                AppAgentLog.writeLog(ex.Message);
            }
            finally
            {
            }
        }
예제 #2
0
        public void doWork()
        {
            AppAgentLog.writeLog(string.Format("報表排程[{0}]開始", GetType().Name));

            try
            {
                var dtRptTask = NsDmHelper.SY_ReportTask
                                .selectAll(t => t.AllExt)
                                .where (t =>
                                        t.SYRT_TaskStatus == "N"
                                        & (t.SYRT_ScheduleDate <= DateTime.Now | t.SYRT_ScheduleDate == null)
                                        )
                                .orderby(t => new[] {
                    t.SYRT_ScheduleDate.Asc,
                    t.SYRT_CreateDate.Asc
                })
                                .query();

                //KM Web Service
                var kmUrl = FtdConfigService.Instance.getAppSettingValue("URL_KMWS", "");
                if (kmUrl.isNullOrEmpty())
                {
                    AppAgentLog.writeLog("KM Web Service Invalid");
                    return;
                }

                var reportId = "";
                foreach (var task in dtRptTask)
                {
                    AppAgentLog.writeLog(string.Format("處理報表-開始, TaskId:{0},ReportId:{1}", task.SYRT_ReportTaskId, task.SYRT_ReportId));
                    try
                    {
                        task.SYRT_ExecuteStartTime = DateTime.Now;

                        Type tService = Type.GetType(task.SYRT_ServiceClass_XX);
                        Type tModel   = Type.GetType(task.SYRT_QueryModelClass_XX);

                        var rptService = Activator.CreateInstance(tService) as AppReportService;
                        var rptModel   = Activator.CreateInstance(tModel) as AppQryModel;

                        JavaScriptSerializer json_serializer = new JavaScriptSerializer();
                        rptModel = json_serializer.Deserialize(task.SYRT_Conditions, tModel) as AppQryModel;

                        if (rptService == null || rptModel == null)
                        {
                            task.SYRT_ExecuteEndTime = DateTime.Now;
                            task.SYRT_TaskStatus     = "F";
                            task.SYRT_ExecuteResult  = "服務類別或參數類別定義錯誤";

                            task.ns_update();
                            dtRptTask.AcceptChanges();
                            continue;
                        }

                        //處理中
                        task.SYRT_TaskStatus = "P";
                        task.ns_update();

                        reportId = rptModel.ReportId;
                        //產製報表
                        var rawData = rptService.processReport(rptModel);

                        //空值
                        if (rawData == null || rawData.Length == 0)
                        {
                            task.SYRT_ExecuteEndTime = DateTime.Now;
                            task.SYRT_TaskStatus     = "Y";
                            task.SYRT_ExecuteResult  = "無資料";

                            task.ns_update();
                            dtRptTask.AcceptChanges();
                            continue;
                        }

                        // Save to KM System
                        try
                        {
                            var kmWS = new KmWebService.AcceptFromFinance();
                            kmWS.Url     = kmUrl;
                            kmWS.Timeout = 1000 * 60 * 10; //ms
                            var fileId = kmWS.UploadFile(task.SYRT_OrganId, task.SYRT_CreatorCode_XX, rptModel.ExportName, rawData);

                            task.SYRT_ExecuteEndTime = DateTime.Now;
                            task.SYRT_TaskStatus     = "Y";
                            task.SYRT_ExecuteResult  = "成功";
                            task.SYRT_FileId         = fileId;
                        }
                        catch (Exception ex2)
                        {
                            task.SYRT_ExecuteEndTime = DateTime.Now;
                            task.SYRT_TaskStatus     = "F";
                            task.SYRT_ExecuteResult  = "存檔至 KM 失敗";
                            AppAgentLog.writeLog(string.Format("產製報表發生錯誤:存檔至 KM 失敗, ReportId:{0}\r\n{1}", reportId, ex2.ToString()));
                        }

                        task.ns_update();
                        dtRptTask.AcceptChanges();
                    }
                    catch (Exception ex1)
                    {
                        task.SYRT_ExecuteEndTime = DateTime.Now;
                        task.SYRT_TaskStatus     = "F";
                        task.SYRT_ExecuteResult  = "產製報表發生錯誤";

                        task.ns_update();
                        dtRptTask.AcceptChanges();

                        AppAgentLog.writeLog(string.Format("產製報表發生錯誤, ReportId:{0}\r\n{1}", reportId, ex1.ToString()));
                    }
                    finally
                    {
                        var timeSpan = task.SYRT_ExecuteEndTime.Value.Subtract(task.SYRT_ExecuteStartTime.Value);
                        AppAgentLog.writeLog(string.Format("處理報表-結束, TaskId:{0},ReportId:{1},耗時:{2}秒", task.SYRT_ReportTaskId, task.SYRT_ReportId, timeSpan.TotalSeconds));
                    }
                }
            }
            catch (Exception ex)
            {
                AppAgentLog.writeLog(string.Format("產製報表發生錯誤, \r\n{0}", ex.ToString()));
            }
            finally
            {
                AppAgentLog.writeLog(string.Format("報表排程[{0}]結束", GetType().Name));
                string split = new string('-', 50);
                AppAgentLog.writeLog(split);
            }
        }
예제 #3
0
        public void doWork()
        {
            string                 errorMsg     = string.Empty;
            SY_NewsDataTable       dtNews       = new SY_NewsDataTable();
            SY_NewsObjectDataTable dtNewsObject = new SY_NewsObjectDataTable();

            AppAgentLog.writeLog(string.Format("排程開始同步資料[{0}] : {1}", "", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")));
            DateTime DT = DateTime.Now;

            try
            {
                var dtNotice2 = NsDmHelper.SY_Notice2
                                .selectAll(t => t.AllPhysical)
                                .where (t =>
                                        t.SYN2_NewsId == null
                                        & t.SYN2_StartTime.tostring(NsDataFormat.DATE_YYYYMMDD) == Convert.ToDateTime(DT).ToString("yyyyMMdd")
                                        )
                                .query();

                if (dtNotice2 != null && dtNotice2.Rows.Count > 0)
                {
                    var    drNotice2 = dtNotice2.FirstRow;
                    string year      = drNotice2.SYN2_Year;
                    string season    = drNotice2.SYN2_Season;
                    string strDT     = string.Empty;

                    var dtReportMaster = NsDmHelper.PP_ReportMaster
                                         .selectAll(t => t.AllPhysical)
                                         .where (t =>
                                                 t.PPRM_Year == year & t.PPRM_Season == season
                                                 & t.PPRM_ReportDate == null // 尚未送件
                                                 )
                                         .query();

                    #region //有需要公告對象時產生
                    if (dtReportMaster != null && dtReportMaster.Rows.Count > 0)
                    {
                        #region //公告增加一筆
                        var drNews = dtNews.newTypedRow();
                        drNews.ns_AssignNewId();
                        drNews.SYN_Type = "B";
                        if (!string.IsNullOrEmpty(drNotice2.SYN2_StartTime))
                        {
                            strDT = (Convert.ToInt32(drNotice2.SYN2_StartTime.Substring(0, 3)) + 1911).ToString() + "/" + drNotice2.SYN2_StartTime.Substring(3, 2).PadLeft(2, '0') + "/" + drNotice2.SYN2_StartTime.Substring(5, 2).PadLeft(2, '0');
                        }
                        drNews.SYN_StartTime = Convert.ToDateTime(strDT);
                        if (!string.IsNullOrEmpty(drNotice2.SYN2_EndTime))
                        {
                            strDT = (Convert.ToInt32(drNotice2.SYN2_EndTime.Substring(0, 3)) + 1911).ToString() + "/" + drNotice2.SYN2_EndTime.Substring(3, 2).PadLeft(2, '0') + "/" + drNotice2.SYN2_EndTime.Substring(5, 2).PadLeft(2, '0');
                        }
                        drNews.SYN_EndTime = Convert.ToDateTime(strDT);
                        drNews.SYN_Subject = drNotice2.SYN2_Subject;
                        drNews.SYN_Message = drNotice2.SYN2_Content;
                        dtNews.addTypedRow(drNews);
                        #endregion

                        #region //公告明細增加多筆
                        string newsid = drNews.SYN_NewsId;
                        foreach (var dr in dtReportMaster.TypeRows)
                        {
                            var drNewsObject = dtNewsObject.newTypedRow();
                            drNewsObject.ns_AssignNewId();
                            drNewsObject.SYNO_NewsId   = newsid;
                            drNewsObject.SYNO_ObjectId = dr.PPRM_ManageOrgId;
                            dtNewsObject.addTypedRow(drNewsObject);
                        }
                        #endregion

                        drNotice2.SYN2_NewsId = newsid;
                    }
                    #endregion

                    //確認無誤一起更新
                    var scope = new FdbTransScope(FdbTransScopeOption.RequiresNew);
                    using (scope.Use)
                    {
                        drNotice2.ns_update();
                        dtNews.ns_update();
                        dtNewsObject.ns_update();
                        scope.complete();
                        drNotice2.AcceptChanges();
                        dtNews.AcceptChanges();
                        dtNewsObject.AcceptChanges();
                    }
                }

                AppAgentLog.writeLog(string.Format("完成同步資料[{0}] : {1}", GetType().Name, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")));
                string split = new string('-', 30);
                AppAgentLog.writeLog(split);
            }
            catch (Exception ex)
            {
                AppAgentLog.writeLog(ex.Message);
            }
            finally
            {
            }
        }