Example #1
0
        protected override ResultStatus Export()
        {
            try
            {
                #region 輸入&日期檢核
                if (string.Compare(txtStartDate.Text, txtEndDate.Text) > 0)
                {
                    MessageDisplay.Error(CheckDate.Datedif, GlobalInfo.ErrorText);
                    return(ResultStatus.Fail);
                }
                #endregion

                //ready
                panFilter.Enabled = false;
                labMsg.Visible    = true;
                labMsg.Text       = "開始轉檔...";
                this.Cursor       = Cursors.WaitCursor;
                this.Refresh();
                Thread.Sleep(5);

                string    rptName;
                DataTable dt;

                //撈資料
                if (gbType.EditValue.AsString() == "rbCBOE")
                {
                    #region CBOE
                    rptName = "CBOE";
                    DataTable dtContent = daoVPR.ListByMarket(StartDate, EndDate, 'C', 'C');
                    if (dtContent.Rows.Count <= 0)
                    {
                        labMsg.Visible = false;
                        MessageDisplay.Info(string.Format("{0},{1},{2},無任何資料!", txtStartDate.Text + "-" + txtEndDate.Text, this.Text, rptName), GlobalInfo.ResultText);
                        return(ResultStatus.Fail);
                    }

                    //處理資料型態
                    dt = dtContent.Clone();                                //轉型別用的datatable
                    dt.Columns["VPR_DATA_TIME"].DataType = typeof(string); //將原DataType(datetime)轉為string
                    foreach (DataRow row in dtContent.Rows)
                    {
                        dt.ImportRow(row);
                    }

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        dt.Rows[i]["VPR_DATA_TIME"] = Convert.ToDateTime(dtContent.Rows[i]["VPR_DATA_TIME"]).ToString("yyyy/MM/dd HH:mm:ss:fff");
                    }
                    #endregion
                }
                else
                {
                    #region VIX
                    if (gbReport.EditValue.AsString() == "rbStatistics")
                    {
                        rptName = "JVVIXVolAvg";
                        dt      = daoVOLS.GetDataByDate(StartDate, EndDate, "J", "Y");
                    }
                    else
                    {
                        rptName = "JVVIXVolDetail";
                        dt      = daoVOLD.GetDataByDate(StartDate, EndDate, "J", "Y");
                    }
                    if (dt.Rows.Count <= 0)
                    {
                        labMsg.Visible = false;
                        MessageDisplay.Info(string.Format("{0},{1},{2}無任何資料!", txtStartDate.Text + "-" + txtEndDate.Text, this.Text, rptName), GlobalInfo.ResultText);
                        return(ResultStatus.Fail);
                    }
                    #endregion
                }

                //存Csv
                string etfFileName = "30685_" + rptName + "_" + DateTime.Now.ToString("yyyy.MM.dd-HH.mm.ss") + ".csv";
                etfFileName = Path.Combine(GlobalInfo.DEFAULT_REPORT_DIRECTORY_PATH, etfFileName);
                ExportOptions csvref = new ExportOptions();
                csvref.HasHeader = true;
                csvref.Encoding  = System.Text.Encoding.GetEncoding(950); //ASCII
                Common.Helper.ExportHelper.ToCsv(dt, etfFileName, csvref);

                labMsg.Text  = "轉檔成功!";
                exportStatus = ResultStatus.Success;
                return(ResultStatus.Success);
            }
            catch (Exception ex)
            {
                WriteLog(ex);
                labMsg.Text = "轉檔失敗";
            }
            finally
            {
                panFilter.Enabled = true;
                labMsg.Text       = "";
                labMsg.Visible    = false;
                this.Cursor       = Cursors.Arrow;
            }
            return(ResultStatus.Fail);
        }
Example #2
0
        protected override ResultStatus Export()
        {
            try {
                #region 輸入&日期檢核
                if (string.Compare(txtStartDate.Text, txtEndDate.Text) > 0)
                {
                    MessageDisplay.Error(CheckDate.Datedif, GlobalInfo.ErrorText);
                    return(ResultStatus.Fail);
                }
                #endregion

                //0. ready
                panFilter.Enabled = false;
                labMsg.Visible    = true;
                labMsg.Text       = "開始轉檔...";
                this.Cursor       = Cursors.WaitCursor;
                this.Refresh();
                Thread.Sleep(5);

                //1.撈資料
                DataTable dtContent = daoVPR.ListByMarket(StartDate, EndDate, 'S', 'S');
                if (dtContent.Rows.Count <= 0)
                {
                    labMsg.Hide();
                    MessageDisplay.Info(string.Format("{0},{1},無任何資料!", txtStartDate.Text + "-" + txtEndDate.Text, this.Text), GlobalInfo.ResultText);
                    return(ResultStatus.Fail);
                }

                //1.1處理資料型態
                DataTable dt = dtContent.Clone();                      //轉型別用的datatable
                dt.Columns["VPR_DATA_TIME"].DataType = typeof(string); //將原DataType(datetime)轉為string
                foreach (DataRow row in dtContent.Rows)
                {
                    dt.ImportRow(row);
                }

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    dt.Rows[i]["VPR_DATA_TIME"] = Convert.ToDateTime(dtContent.Rows[i]["VPR_DATA_TIME"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
                }

                //2.存Txt
                string etfFileName = "30684_" + DateTime.Now.ToString("yyyy.MM.dd-HH.mm.ss") + ".txt";
                etfFileName = Path.Combine(GlobalInfo.DEFAULT_REPORT_DIRECTORY_PATH, etfFileName);
                ExportOptions txtref = new ExportOptions();
                txtref.HasHeader = true;
                txtref.Encoding  = System.Text.Encoding.GetEncoding(950);//ASCII
                Common.Helper.ExportHelper.ToText(dt, etfFileName, txtref);

                labMsg.Text  = "轉檔成功!";
                exportStatus = ResultStatus.Success;
                return(ResultStatus.Success);
            } catch (Exception ex) {
                WriteLog(ex);
                labMsg.Text = "轉檔失敗";
            } finally {
                panFilter.Enabled = true;
                labMsg.Text       = "";
                labMsg.Visible    = false;
                this.Cursor       = Cursors.Arrow;
            }
            return(ResultStatus.Fail);
        }