Example #1
0
 public ServicePrefix1()
 {
     daoTXF     = new TXF();
     daoLOGSP   = new LOGSP();
     daoLOGS    = new LOGS();
     daoTXEMAIL = new TXEMAIL();
     daoTXF1    = new TXF1();
     daoTXF2    = new TXF2();
     daoJRF     = new JRF();
     daoOCF     = new OCF();
 }
Example #2
0
 public ServicePrefix1()
 {
     daoTXF         = new TXF();
     daoLOGSP       = new LOGSP();
     daoLOGS        = new LOGS();
     daoTXEMAIL     = new TXEMAIL();
     daoTXF1        = new TXF1();
     daoTXF2        = new TXF2();
     daoJRF         = new JRF();
     daoOCF         = new OCF();
     serviceCommon  = new ServiceCommon();
     daoFutAHOCFUPD = new OCFUPD("futAH");
     daoOptAHOCFUPD = new OCFUPD("optAH");
 }
Example #3
0
        protected override ResultStatus Export()
        {
            string flowStepDesc = "1.開始轉出資料";

            try {
                //1.開始轉出資料
                panFilter.Enabled = false;
                gcMsg.DataSource  = null;
                gcMsg.Refresh();
                gcMsg.Visible  = true;
                labMsg.Visible = true;
                labMsg.Text    = "訊息:資料轉出中........";
                this.Refresh();

                //1.1 ready some value
                DateTime tradeDate     = txtSDate.DateTimeValue;                       //當日
                DateTime lastTradeDate = ai2.GetLastDate(tradeDate, "D", "TXF%", "%"); //找到前一日期
                bool     haveTradeTxw  = amif.haveTradeTxw(tradeDate);                 //判斷當日有無TXW
                decimal  closePrice    = amif.GetClosePrice(tradeDate);                //現貨收盤指數
                if (closePrice == 0)
                {
                    closePrice = new AMIFU().GetClosePrice(tradeDate);
                }
                if (closePrice == 0)
                {
                    MessageDisplay.Error("讀取現貨收盤指數無資料,請確認20110作業中有今天資料!", GlobalInfo.ErrorText);
                    return(ResultStatus.Fail);
                }

                //1.2 copy template xls to target path
                //string tempOutputDate = (ddlType.Text == "全部收盤" ? "全部收盤" : "16時15分收盤");//ken,檔名不能有冒號,所以無法直接用下拉選單text
                string tempOutputDate = "全部收盤";
                string targetFileName = string.Format("{0}新版行情表({1}).xlsx", tradeDate.ToString("yyyyMMdd"), tempOutputDate);
                //string reportId = "30055_" + (ddlType.ItemIndex + 1).ToString();//後面還會用到
                string reportId             = "30055_2";
                string excelDestinationPath = wf_copy_file(reportId, targetFileName);
                if (excelDestinationPath == "")
                {
                    return(ResultStatus.Fail);                       //當copy file發生錯誤,直接離開(這裡檔案名稱會重複,所以容易造成檔案開始時無法move造成失敗)
                }
                //1.3 open excel
                Workbook workbook = new Workbook();
                workbook.LoadDocument(excelDestinationPath);
                Worksheet ws = workbook.Worksheets[0];
                flag = 0;

                //2.1 今日台指期收盤指數
                flowStepDesc = "2.1 今日台指期收盤指數";
                //if (!wf_30055_a(ws , tradeDate , closePrice)) return showEmailMsg(cbxNews.Checked);
                if (is_chk == "Y")
                {
                    wf_30055_a(ws, tradeDate, closePrice);
                }

                //2.2 主要指數期貨商品行情表
                flowStepDesc = "2.2 主要指數期貨商品行情表";
                //if (!wf_30055_b(ws , tradeDate , lastTradeDate)) return showEmailMsg(cbxNews.Checked);
                if (is_chk == "Y")
                {
                    wf_30055_b(ws, tradeDate, lastTradeDate);
                }

                //2.3 台指選擇權(近月及一週到期)主要序列行情表
                flowStepDesc = "2.3 台指選擇權(近月及一週到期)主要序列行情表";
                //if (!wf_30055_tx(ws , tradeDate , haveTradeTxw , closePrice)) return showEmailMsg(cbxNews.Checked);
                if (is_chk == "Y")
                {
                    wf_30055_tx(ws, tradeDate, haveTradeTxw, closePrice);
                }


                //2.4 主要指數期貨大額交易人未平倉部位一覽表 (三大法人=外商/投信/自營商)
                //2.4 台指選擇權十大交易人未平倉部位一覽表 (三大法人=外商/投信/自營商)
                flowStepDesc = "2.4 主要指數期貨大額交易人未平倉部位一覽表 (三大法人)";
                //if (!wf_30055_three_keep(ws , tradeDate , lastTradeDate)) return showEmailMsg(cbxNews.Checked);
                if (is_chk == "Y")
                {
                    wf_30055_three_keep(ws, tradeDate, lastTradeDate);
                }


                //2.5 主要指數期貨大額交易人未平倉部位一覽表 (大額交易人=十大交易人(近月)+十大交易人(所有月份))
                //2.5 台指選擇權十大交易人未平倉部位一覽表 (大額交易人=十大交易人(近月)+十大交易人(所有月份))
                flowStepDesc = "2.5 主要指數期貨大額交易人未平倉部位一覽表 (大額交易人)";
                //if (!wf_30055_big_keep(ws , tradeDate , lastTradeDate)) return showEmailMsg(cbxNews.Checked);
                if (is_chk == "Y")
                {
                    wf_30055_big_keep(ws, tradeDate, lastTradeDate);
                }



                //2.6 主要股票(不含ETF)期貨行情表(依未平倉量) = STF
                //2.6 主要ETF期貨行情表(依未平倉量)= ETF
                flowStepDesc = "2.6 主要股票 期貨/ETF 商品行情表(依未平倉量)";
                //if (!wf_30055_stf(ws , tradeDate , lastTradeDate , "STF")) return showEmailMsg(cbxNews.Checked);
                if (is_chk == "Y")
                {
                    wf_30055_stf(ws, tradeDate, lastTradeDate, "STF");
                }
                //if (!wf_30055_stf(ws , tradeDate , lastTradeDate , "ETF")) return showEmailMsg(cbxNews.Checked);
                if (is_chk == "Y")
                {
                    wf_30055_stf(ws, tradeDate, lastTradeDate, "ETF");
                }

                //2.7 主要ETF選擇權(近月價平)序列行情表
                flowStepDesc = "2.7 主要ETF選擇權(近月價平)序列行情表";
                //if (!wf_30055_etc(ws , tradeDate , "ETC")) return showEmailMsg(cbxNews.Checked);
                if (is_chk == "Y")
                {
                    wf_30055_etc(ws, tradeDate, "ETC");
                }


                //2.8 匯率期貨行情表
                flowStepDesc = "2.8 匯率期貨行情表";
                //if (!wf_30055_prod_subtype(ws , tradeDate , "E")) return showEmailMsg(cbxNews.Checked);
                if (is_chk == "Y")
                {
                    wf_30055_prod_subtype(ws, tradeDate, "E");
                }

                //2.9 人民幣匯率選擇權主要序列行情表(依成交量) RHF,RTF
                //ken,template是隱藏的grid,嗯
                flowStepDesc = "2.9 人民幣匯率選擇權主要序列行情表(依成交量) RHF,RTF";
                //if (!wf_30055_rho(ws , tradeDate)) return showEmailMsg(cbxNews.Checked);
                if (is_chk == "Y")
                {
                    wf_30055_rho(ws, tradeDate);
                }

                //2.10 商品期貨行情表 GDF,TGF,BRF
                flowStepDesc = "2.10 商品期貨行情表 (美元黃金期貨/臺幣黃金期貨/布蘭特原油期貨)GDF,TGF,BRF";
                //if (!wf_30055_prod_subtype(ws , tradeDate , "C")) return showEmailMsg(cbxNews.Checked);
                if (is_chk == "Y")
                {
                    wf_30055_prod_subtype(ws, tradeDate, "C");
                }

                //2.11 刪除列
                flowStepDesc = "2.11 刪除列";
                wf_del_row(ws, haveTradeTxw);

                //2.12 股票期貨週
                flowStepDesc = "2.12 股票期貨週";
                ws           = workbook.Worksheets[1];//切換到第二個sheet
                //if (!wf_30055_weekly(ws , tradeDate)) return showEmailMsg(cbxNews.Checked);
                if (is_chk == "Y")
                {
                    wf_30055_weekly(ws, tradeDate);
                }

                //2.13 先存檔
                if (flag <= 0)
                {
                    File.Delete(excelDestinationPath);
                }
                else
                {
                    flowStepDesc = "2.13 Save file";
                    ws           = workbook.Worksheets[0];
                    ws.Range["A1"].Select();
                    ws.ScrollToRow(0);
                    workbook.SaveDocument(excelDestinationPath);
                }

                //2.14 email news
                flowStepDesc = "2.14 email news";
                if (cbxNews.Checked)
                {
                    DataTable dtTxemail = new TXEMAIL().ListData(reportId, 1);

                    if (dtTxemail.Rows.Count != 0)
                    {
                        string TXEMAIL_SENDER     = dtTxemail.Rows[0]["TXEMAIL_SENDER"].AsString();
                        string TXEMAIL_RECIPIENTS = dtTxemail.Rows[0]["TXEMAIL_RECIPIENTS"].AsString();
                        string TXEMAIL_CC         = dtTxemail.Rows[0]["TXEMAIL_CC"].AsString();
                        string TXEMAIL_TITLE      = dtTxemail.Rows[0]["TXEMAIL_TITLE"].AsString();
                        string TXEMAIL_TEXT       = dtTxemail.Rows[0]["TXEMAIL_TEXT"].AsString();
                        try {
                            TXEMAIL_TITLE = txtSDate.DateTimeValue.ToString("yyyyMMdd") + TXEMAIL_TITLE;
                            MailHelper.SendEmail(TXEMAIL_SENDER, TXEMAIL_RECIPIENTS, TXEMAIL_CC, TXEMAIL_TITLE, TXEMAIL_TEXT, excelDestinationPath);
                        } catch (Exception ex) {
                            is_chk = "E";
                            MessageDisplay.Warning("產出檔案有異常資訊,請通知系統負責人!");
                            return(ResultStatus.Fail);
                        }
                    }
                }

                #region //3.產生TJF檔案

                //3.1複製檔案
                targetFileName       = string.Format("{0}_TJF.xlsx", tradeDate.ToString("yyyy.MM.dd"));
                reportId             = "30055_TJF";
                excelDestinationPath = wf_copy_file(reportId, targetFileName);
                workbook.LoadDocument(excelDestinationPath);
                ws = workbook.Worksheets[0];

                //3.2
                //if (!wf_30055_tjf(ws , tradeDate , lastTradeDate)) return showEmailMsg(cbxNews.Checked);
                bool result = false;
                if (is_chk == "Y")
                {
                    result = wf_30055_tjf(ws, tradeDate, lastTradeDate);
                }

                //3.3 儲存及關閉檔案
                if (!result)
                {
                    File.Delete(excelDestinationPath);
                }
                else
                {
                    workbook.SaveDocument(excelDestinationPath);
                }

                //3.4 email
                if (cbxTJF.Checked)
                {
                    string    txnId     = "30055";
                    DataTable dtTxemail = new TXEMAIL().ListData(txnId, 1);

                    if (dtTxemail.Rows.Count != 0)
                    {
                        string TXEMAIL_SENDER     = dtTxemail.Rows[0]["TXEMAIL_SENDER"].AsString();
                        string TXEMAIL_RECIPIENTS = dtTxemail.Rows[0]["TXEMAIL_RECIPIENTS"].AsString();
                        string TXEMAIL_CC         = dtTxemail.Rows[0]["TXEMAIL_CC"].AsString();
                        string TXEMAIL_TITLE      = dtTxemail.Rows[0]["TXEMAIL_TITLE"].AsString();
                        string TXEMAIL_TEXT       = dtTxemail.Rows[0]["TXEMAIL_TEXT"].AsString();

                        TXEMAIL_TITLE = txtSDate.DateTimeValue.ToString("yyyyMMdd") + TXEMAIL_TITLE;
                        try {
                            MailHelper.SendEmail(TXEMAIL_SENDER, TXEMAIL_RECIPIENTS, TXEMAIL_CC, TXEMAIL_TITLE, TXEMAIL_TEXT, excelDestinationPath);
                        } catch (Exception ex) {
                            is_chk = "E";
                            MessageDisplay.Warning("產出檔案有異常資訊,請通知系統負責人!");
                            return(ResultStatus.Fail);
                        }
                    }
                }
                #endregion


                return(ResultStatus.Success);
            } catch (Exception ex) {
                WriteLog(ex, flowStepDesc);
            } finally {
                this.Cursor       = Cursors.Arrow;
                panFilter.Enabled = true;
                labMsg.Text       = "";
                labMsg.Visible    = false;
                this.Refresh();
                Thread.Sleep(5);
            }
            return(ResultStatus.Fail);
        }
 public ServicePrefix5()
 {
     daoTXF     = new TXF();
     daoLOGSP   = new LOGSP();
     daoTXEMAIL = new TXEMAIL();
 }
Example #5
0
        protected override ResultStatus Export()
        {
            try {
                this.Cursor = Cursors.WaitCursor;
                this.Refresh();
                Thread.Sleep(5);
                lblProcessing.Visible = true;
                ShowMsg("開始轉檔...");
                string rptId, file, rptName = "";
                date = txtSDate.DateTimeValue.Year + "年" + txtSDate.DateTimeValue.Month + "月" + txtSDate.DateTimeValue.Day + "日";

                #region ue_export_before
                //判斷盤別
                int    rtnInt, seq;
                string rtnStr, grp;
                if (ddlType.Text == "16:15收盤")
                {
                    grp = "1";
                }
                else
                {
                    grp = "2";
                }

                //判斷統計資料轉檔已完成
                for (int f = 1; f <= 2; f++)
                {
                    if (grp == "1")
                    {
                        if (f == 1)
                        {
                            seq = 13;
                        }
                        else
                        {
                            seq = 23;
                        }
                    }
                    else
                    {
                        seq = 17;
                        f   = 2;
                    }
                    //check JSW
                    rtnStr = PbFunc.f_get_jsw_seq(_ProgramID, "E", seq, txtSDate.DateTimeValue, "0");
                    if (rtnStr != "")
                    {
                        DialogResult result = MessageDisplay.Choose(txtSDate.Text +
                                                                    "統計資料未轉入完畢,請確認監視批次「AIG5402」執行完成,再按「是」繼續,若選「否」則會跳過作業不執行。",
                                                                    MessageBoxDefaultButton.Button2, GlobalInfo.QuestionText);

                        if (result == DialogResult.No)
                        {
                            lblProcessing.Visible = false;
                            return(ResultStatus.Fail);
                        }
                    }
                }
                #endregion

                rptId = "30053";

                //複製檔案
                file = wfCopy30053(rptId, grp);
                if (file == "")
                {
                    return(ResultStatus.Fail);
                }

                //開啟檔案
                Workbook workbook = new Workbook();
                workbook.LoadDocument(file);

                //切換Sheet
                Worksheet ws = workbook.Worksheets["期貨"];

                #region 11張報表

                int rowIndex = 1;
                //1.期貨
                if (!wf30053f(grp, rowIndex, ws))
                {
                    return(showEmailMsg(cbxNews.Checked));
                }

                //2.選擇權
                rowIndex = rowIndex + 3;
                ws       = workbook.Worksheets["選擇權"];
                if (!wf30053o(rowIndex, ws))
                {
                    return(showEmailMsg(cbxNews.Checked));
                }

                //3.股票選擇權
                rowIndex = rowIndex + 3;
                ws       = workbook.Worksheets["股票選擇權"];
                if (!wf30053stc(rowIndex, ws))
                {
                    return(showEmailMsg(cbxNews.Checked));
                }

                //4.股票期貨(For工商時報)
                //5.股票期貨(For工商時報)50
                rowIndex = rowIndex + 3;
                ws       = workbook.Worksheets["股票期貨(For工商時報)"];
                if (!wf30053stfNear(ws))
                {
                    return(showEmailMsg(cbxNews.Checked));
                }
                ws = workbook.Worksheets["股票期貨(For工商時報) 50大"];
                if (!wfCtee50(ws))
                {
                    return(showEmailMsg(cbxNews.Checked));
                }

                //6.股票期貨Top10檔(For聯合晚報)
                ws = workbook.Worksheets["股票期貨Top10檔(For經濟日報)"];
                if (!wf30053stfTop10(ws))
                {
                    return(showEmailMsg(cbxNews.Checked));
                }

                //7.ETF期貨Top10檔
                ws = workbook.Worksheets["ETF期貨Top10檔"];
                if (!wf30053etfTop10(ws))
                {
                    return(showEmailMsg(cbxNews.Checked));
                }

                //8.股票選擇權TOP10檔(For聯合晚報)
                ws = workbook.Worksheets["股票選擇權TOP10檔(For聯合晚報)"];
                if (!wf30053stcTop10(ws))
                {
                    return(showEmailMsg(cbxNews.Checked));
                }

                //9.ETF選擇權前20大行情表
                ws = workbook.Worksheets["ETF選擇權TOP20檔"];
                if (!wf30053etcTop20(ws))
                {
                    return(showEmailMsg(cbxNews.Checked));
                }

                //10.美元兌人民幣選擇權前20大行情表
                ws = workbook.Worksheets["美元兌人民幣選擇權(RHO)TOP20檔"];
                if (!wf30053rhoTop20(ws))
                {
                    return(showEmailMsg(cbxNews.Checked));
                }

                //11.小型美元兌人民幣選擇權前20大行情表
                ws = workbook.Worksheets["小型美元兌人民幣選擇權(RTO)TOP20檔"];
                if (!wf30053rtoTop20(ws))
                {
                    return(showEmailMsg(cbxNews.Checked));
                }

                #endregion

                //存檔
                workbook.SaveDocument(file);
                ShowMsg("轉檔完成");

                //email
                rptId = "30053_" + grp;
                if (cbxNews.Checked)
                {
                    DataTable dtTxemail = new TXEMAIL().ListData(rptId, 1);

                    if (dtTxemail.Rows.Count != 0)
                    {
                        string TXEMAIL_SENDER     = dtTxemail.Rows[0]["TXEMAIL_SENDER"].AsString();
                        string TXEMAIL_RECIPIENTS = dtTxemail.Rows[0]["TXEMAIL_RECIPIENTS"].AsString();
                        string TXEMAIL_CC         = dtTxemail.Rows[0]["TXEMAIL_CC"].AsString();
                        string TXEMAIL_TITLE      = dtTxemail.Rows[0]["TXEMAIL_TITLE"].AsString();
                        string TXEMAIL_TEXT       = dtTxemail.Rows[0]["TXEMAIL_TEXT"].AsString();

                        TXEMAIL_TITLE = txtSDate.DateTimeValue.ToString("yyyyMMdd") + TXEMAIL_TITLE;
                        MailHelper.SendEmail(TXEMAIL_SENDER, TXEMAIL_RECIPIENTS, TXEMAIL_CC, TXEMAIL_TITLE, TXEMAIL_TEXT, file);
                    }
                }
            } catch (Exception ex) {
                MessageDisplay.Error("輸出錯誤");
                throw ex;
            } finally {
                this.Cursor = Cursors.Arrow;
                this.Refresh();
                Thread.Sleep(5);
            }
            return(ResultStatus.Success);
        }