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); }
/// <summary> /// 依checkbox的勾選決定export的內容 /// </summary> /// <param name="type">N=New,O=Old,V=???</param> /// <param name="filePath">檔名(.csv)</param> /// <param name="fileTile">功能title</param> /// <param name="tableName"></param> private int wfExport(string type, string filePath, string fileTile, string tableName) { string fileName; //報表名稱 try { if (type == "N") { fileName = "新"; } else if (type == "O") { fileName = "舊"; } else //V { fileName = ""; } fileName += fileTile; labMsg.Text = _ProgramID + "-" + fileName + " 轉檔中..."; //讀取資料 DataTable dtData = new DataTable(); switch (tableName) { case "chkNewVixs": case "chkOldVixs": dtData = daoVIXS.GetDataByDate(type, StartDate, EndDate, "Y"); break; case "chkNewVix": case "chkOldVix": dtData = daoVIX.GetDataByDate(type, StartDate, EndDate, "Y"); break; case "chkNewVols": dtData = daoVOLS.GetDataByDate(StartDate, EndDate, type, "Y"); break; case "chkNewVold": dtData = daoVOLD.GetDataByDate(StartDate, EndDate, type, "Y"); break; } if (dtData.Rows.Count <= 0) { labMsg.Text = string.Format("{0},{1}-{2},無任何資料!", StartDate.SubStr(0, 6), _ProgramID, fileName); MessageDisplay.Info(string.Format("{0},{1}-{2},無任何資料!", StartDate.SubStr(0, 6), _ProgramID, fileName), GlobalInfo.ResultText); return(0); } //存CSV (ps:輸出csv 都用ascii) filePath = Path.Combine(GlobalInfo.DEFAULT_REPORT_DIRECTORY_PATH, filePath); ExportOptions csvref = new ExportOptions(); csvref.HasHeader = true; csvref.Encoding = System.Text.Encoding.GetEncoding(950);//ASCII Common.Helper.ExportHelper.ToCsv(dtData, filePath, csvref); return(1); } catch (Exception ex) { WriteLog(ex); } return(0); }