Exemplo n.º 1
0
        protected override ResultStatus Export()
        {
            dao30220 = new D30220();
            string rptId, file;

            rptId = "30220";

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

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

            workbook.LoadDocument(file);

            int rowNum = 1;

            #region wf_30220
            string rptName, stkYmd, lsStr;
            int    rowTol;
            rptName = "個股類歷史交易量及流通在外股數";
            rptId   = "30220";
            rowTol  = 500;
            rowNum  = 3;
            //讀取資料
            stkYmd = txtStkoutDate.Text.Replace("/", "");
            DataTable dt30220 = dao30220.d_30220(txtDate.Text.Replace("/", ""), txtSMonth.Text.Replace("/", ""), txtEMonth.Text.Replace("/", ""), stkYmd);
            if (dt30220.Rows.Count == 0)
            {
                MessageDisplay.Info(txtEMonth.Text.Replace("/", "") + "," + rptId + '-' + rptName + ",無任何資料!");
                //若所有Sheet皆無資料時,刪除檔案
                workbook = null;
                System.IO.File.Delete(file);
                return(ResultStatus.Fail);
            }

            //切換sheet
            Worksheet ws30220 = workbook.Worksheets[0];

            //填入資料
            rowNum = 0;
            if (dt30220.Rows.Count > 0)
            {
                string pls3ymd = "";
                if (dt30220.Rows[0]["PLS3_YM3"] != DBNull.Value)
                {
                    pls3ymd = dt30220.Rows[0]["PLS3_YM3"].AsDateTime("yyyyMM").ToString("yyyy/MM");
                }
                if (dt30220.Rows[0]["PLS3_YM1"] != DBNull.Value)
                {
                    ws30220.Cells[0, 4].Value = dt30220.Rows[0]["PLS3_YM1"].AsDateTime("yyyyMM").ToString("yyyy/MM");
                }
                if (dt30220.Rows[0]["PLS3_YM2"] != DBNull.Value)
                {
                    ws30220.Cells[0, 5].Value = dt30220.Rows[0]["PLS3_YM2"].AsDateTime("yyyyMM").ToString("yyyy/MM");
                }
                if (dt30220.Rows[0]["PLS3_YM3"] != DBNull.Value)
                {
                    ws30220.Cells[0, 6].Value = dt30220.Rows[0]["PLS3_YM3"].AsDateTime("yyyyMM").ToString("yyyy/MM");
                }
                if (dt30220.Rows[0]["PLS3_YM1"] != DBNull.Value)
                {
                    ws30220.Cells[0, 7].Value = dt30220.Rows[0]["PLS3_YM1"].AsDateTime("yyyyMM").ToString("yyyy/MM") +
                                                "-" + pls3ymd + "\r" + "\n" + ws30220.Cells[0, 7].Value.AsString();
                }
                ws30220.Cells[0, 8].Value = txtStkoutDate.Text + "\r" + "\n" + ws30220.Cells[0, 8].Value.AsString();
            }

            foreach (DataRow dr in dt30220.Rows)
            {
                rowNum = rowNum + 1;
                if (dr["PLS4_KIND_ID2"] != DBNull.Value)
                {
                    ws30220.Cells[rowNum, 1].Value = dr["PLS4_KIND_ID2"].AsString();
                }
                if (dr["APDK_STOCK_ID"] != DBNull.Value)
                {
                    ws30220.Cells[rowNum, 2].Value = dr["APDK_STOCK_ID"].AsString();
                }
                lsStr = dr["APDK_NAME"].AsString();
                if (PbFunc.Pos(lsStr, "期貨") >= 0)
                {
                    lsStr = lsStr.SubStr(0, lsStr.IndexOf("期貨") + 1);
                }
                if (PbFunc.Pos(lsStr, "選擇權") >= 0)
                {
                    lsStr = lsStr.SubStr(0, lsStr.IndexOf("選擇權") + 1);
                }
                ws30220.Cells[rowNum, 3].Value = lsStr;
                if (dr["PLS3_TOT_QNTY1"] != DBNull.Value)
                {
                    ws30220.Cells[rowNum, 4].Value = dr["PLS3_TOT_QNTY1"].AsDecimal();
                }
                if (dr["PLS3_TOT_QNTY2"] != DBNull.Value)
                {
                    ws30220.Cells[rowNum, 5].Value = dr["PLS3_TOT_QNTY2"].AsDecimal();
                }
                if (dr["PLS3_TOT_QNTY3"] != DBNull.Value)
                {
                    ws30220.Cells[rowNum, 6].Value = dr["PLS3_TOT_QNTY3"].AsDecimal();
                }
                ws30220.Cells[rowNum, 7].Value = dr["PLS3_TOT_QNTY1"].AsDecimal() + dr["PLS3_TOT_QNTY2"].AsDecimal() + dr["PLS3_TOT_QNTY3"].AsDecimal();
                if (dr["STKOUT_B"] != DBNull.Value)
                {
                    ws30220.Cells[rowNum, 8].Value = dr["STKOUT_B"].AsDecimal();
                }
            }
            #endregion

            //存檔
            ws30220.ScrollToRow(0);
            workbook.SaveDocument(file);

            return(ResultStatus.Success);
        }