Example #1
0
        /// <summary>
        /// 130批次作業做完
        /// </summary>
        /// <returns></returns>
        public string Check130Wf()
        {
            DateTime inputDT = _emDateText.AsDateTime();
            string   strRtn  = PbFunc.f_chk_130_wf(_TxnID, inputDT, GetOswGrp());

            if (!string.IsNullOrEmpty(strRtn))
            {
                return($"{_emDateText}-{strRtn},是否要繼續?");
            }
            return(MessageDisplay.MSG_OK);
        }
Example #2
0
        protected override ResultStatus Export()
        {
            try {
                #region export before
                //130批次作業做完
                string ls_rtn = PbFunc.f_chk_130_wf(_ProgramID, txtDate.DateTimeValue, "1");
                if (!string.IsNullOrEmpty(ls_rtn.Trim()))
                {
                    DialogResult liRtn = MessageDisplay.Choose(string.Format("{0}-{1},是否要繼續?", txtDate.Text, ls_rtn), MessageBoxDefaultButton.Button2, GlobalInfo.QuestionText);
                    if (liRtn == DialogResult.No)
                    {
                        labMsg.Visible = false;
                        Cursor.Current = Cursors.Arrow;
                        return(ResultStatus.Fail);
                    }
                }
                #endregion

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

                //1. copy template xls to target path
                string   excelDestinationPath = PbFunc.wf_copy_file(_ProgramID, _ProgramID);
                Workbook workbook             = new Workbook();
                workbook.LoadDocument(excelDestinationPath);

                string ls_logf = "N"; //LOGF記錄每項時間

                if (txtDate.DateTimeValue < DateTime.ParseExact("2010/10/01", "yyyy/MM/dd", null))
                {
                    MessageDisplay.Info("自99年10月1日起,各期貨契約之報酬率改以「當日結算價」及「當日開盤參考價」計算,故產出資料值不會異動至資料庫!", GlobalInfo.WarningText);
                    return(ResultStatus.Fail);
                }

                //2.填資料
                //Sheet:標的現貨收盤價&開盤參考價
                bool result1 = false, result2 = false;

                //資料儲存至Table
                result1 = wf_40021(workbook);
                //if (chkTxt.CheckState == CheckState.Checked) {
                //   result1 = wf_40021(workbook);
                //   if (ls_logf == "Y") {
                //      //wf_logt("40021");

                //      //is_log_time = is_log_time + " - " + string(now())
                //      //f_write_logf(is_txn_id , 'T' , txd_id + ',' + is_log_time)
                //      //is_log_time = string(now())
                //   }
                //}

                //Sheet:Span參數日狀況表(一)(二)(三)
                result2 = wf_40020_7(workbook);

                if (!result1 && !result2)
                {
                    try {
                        workbook = null;
                        File.Delete(excelDestinationPath);
                    } catch (Exception) {
                        //
                    }
                    return(ResultStatus.Fail);
                }

                //存檔
                workbook.SaveDocument(excelDestinationPath);
                labMsg.Visible = false;

                //if (FlagAdmin)
                //   System.Diagnostics.Process.Start(excelDestinationPath);

                return(ResultStatus.Success);
            } catch (Exception ex) {
                WriteLog(ex);
            } finally {
                panFilter.Enabled = true;
                labMsg.Text       = "";
                labMsg.Visible    = false;
                this.Cursor       = Cursors.Arrow;
            }

            return(ResultStatus.Fail);
        }
Example #3
0
        protected override ResultStatus Export()
        {
            try {
                this.Cursor = Cursors.WaitCursor;
                this.Refresh();
                Thread.Sleep(5);
                lblProcessing.Visible = true;
                ShowMsg("開始轉檔...");
                dao42030 = new D42030();
                #region ue_export_before
                //1. 判斷資料已轉入
                int    rtn;
                string ymd = txtSDate.Text.Replace("/", "");
                rtn = dao42030.mgr5Count(ymd);
                if (rtn == 0)
                {
                    DialogResult result = MessageDisplay.Choose(" 當日上市證券保證金適用比例資料未轉入完畢,是否要繼續?");
                    if (result == DialogResult.No)
                    {
                        ShowMsg("");
                        return(ResultStatus.Fail);
                    }
                }
                //2. 130批次作業做完
                string rtnStr;
                rtnStr = PbFunc.f_chk_130_wf(_ProgramID, txtSDate.DateTimeValue, "1");
                if (rtnStr != "")
                {
                    DialogResult result = MessageDisplay.Choose(txtSDate.Text + "-" + rtnStr + ",是否要繼續?");
                    if (result == DialogResult.No)
                    {
                        ShowMsg("");
                        return(ResultStatus.Fail);
                    }
                }
                #endregion

                string rptName, rptId, file;
                int    rowStart;
                rptName = "上市證券保證金概況表";
                rptId   = "42030";

                //1. 讀取資料(保證金適用比例級距)
                DataTable dt42030 = dao42030.d_42030(ymd);
                if (dt42030.Rows.Count == 0)
                {
                    MessageDisplay.Info(txtSDate.Text + "," + rptId + '-' + rptName + ",讀取「當日上市證券保證金適用比例」無任何資料!");
                    ShowMsg("");
                    return(ResultStatus.Fail);
                }

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

                //3. 開啟檔案
                Workbook workbook = new Workbook();
                workbook.LoadDocument(file);
                ShowMsg(rptId + '-' + rptName + " 轉檔中...");

                //4. 切換Sheet
                Worksheet ws42030 = workbook.Worksheets[0];
                ws42030.Cells[0, 0].Value = txtSDate.DateTimeValue.ToString("yyyy年MM月dd日") + ws42030.Cells[0, 0].Value;
                rowStart = 4;

                //5. 從A5開始放資料
                ws42030.Import(dt42030, false, rowStart, 0);

                //6. 刪除空白列
                int rowIndex = dt42030.Rows.Count;
                if (2000 > rowIndex)
                {
                    ws42030.Rows.Remove(rowIndex + rowStart, 2000 - rowIndex);
                }

                //7. 存檔
                ws42030.ScrollToRow(0);
                workbook.SaveDocument(file);
                ShowMsg("轉檔成功");
            }
            catch (Exception ex) {
                MessageDisplay.Error("輸出錯誤");
                ShowMsg("轉檔錯誤");
                throw ex;
            }
            finally {
                this.Cursor = Cursors.Arrow;
                this.Refresh();
                Thread.Sleep(5);
            }
            return(ResultStatus.Success);
        }
Example #4
0
        protected override ResultStatus Export()
        {
            try {
                this.Cursor = Cursors.WaitCursor;
                this.Refresh();
                Thread.Sleep(5);
                lblProcessing.Visible = true;
                ShowMsg("開始轉檔...");
                string rptId = "42011", file, rptName = "股票期貨風險價格係數機動評估指標";

                #region ue_export_before
                //判斷資料已轉入
                daoMGR3 = new MGR3();
                int    rtn;
                string ymd = txtSDate.DateTimeValue.ToString("yyyyMMdd");
                rtn = daoMGR3.mgr3Count(ymd);
                if (rtn == 0)
                {
                    DialogResult result = MessageDisplay.Choose(" 當日保證金適用比例資料未轉入完畢,是否要繼續?");
                    if (result == DialogResult.No)
                    {
                        lblProcessing.Visible = false;
                        return(ResultStatus.Fail);
                    }
                }
                //130批次作業做完
                string rtnStr;
                rtnStr = PbFunc.f_chk_130_wf(_ProgramID, txtSDate.DateTimeValue, "5");
                if (rtnStr != "")
                {
                    DialogResult result = MessageDisplay.Choose(txtSDate.Text + "-" + rtnStr + ",是否要繼續?");
                    if (result == DialogResult.No)
                    {
                        lblProcessing.Visible = false;
                        return(ResultStatus.Fail);
                    }
                }

                //是否勾選任一報表
                if (!cbx1.Checked && !cbx2.Checked && !cbx3.Checked)
                {
                    MessageDisplay.Error("未勾選任何報表!");
                    return(ResultStatus.Fail);
                }
                #endregion

                //取前一交易日
                DateTime lastDate = dao42011.GetLastDate(txtSDate.DateTimeValue);
                if (lastDate == DateTime.MinValue)
                {
                    MessageDisplay.Warning(txtSDate.Text + ",讀取前一交易日失敗!");
                    return(ResultStatus.Fail);
                }

                //讀取資料(保證金適用比例級距)
                DataTable dt42011 = dao42011.d_42011_detl(txtSDate.DateTimeValue, lastDate, txtRange.Text.AsDecimal() / 100,
                                                          txtRate2Ref.Text.AsDecimal() / 100, txtRate3Ref.Text.AsDecimal() / 100, txtRate4Ref.Text.AsDecimal() / 100,
                                                          txtRate1.Text.AsDecimal() / 100, txtRate2.Text.AsDecimal() / 100, txtRate3.Text.AsDecimal() / 100, txtRate4.Text.AsDecimal() / 100);
                if (dt42011.Rows.Count == 0)
                {
                    MessageDisplay.Info(txtSDate.Text + "," + rptId + '-' + rptName + ",無任何資料!");
                    lblProcessing.Visible = false;
                    return(ResultStatus.Fail);
                }
                dt42011.Sort("APDK_KIND_GRP2, APDK_KIND_LEVEL, MGR3_KIND_ID");

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

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

                //切換Sheet
                Worksheet ws = workbook.Worksheets[0];
                ws.Cells[0, 15].Value = txtSDate.DateTimeValue.Year + "年" + txtSDate.DateTimeValue.Month + "月" + txtSDate.DateTimeValue.Day + "日";

                //表1
                ShowMsg(rptId + '-' + rptName + " 轉檔中...");
                int minusRow;
                minusRow = wf_42011_1(ws, dt42011);
                minusRow = wf_42011_2(minusRow, ws, dt42011);
                minusRow = wf_42011_3(minusRow, ws, dt42011);

                //存檔
                ws.ScrollToRow(0);
                workbook.SaveDocument(file);
                ShowMsg("轉檔成功");
            } catch (Exception ex) {
                ShowMsg("轉檔錯誤");
                MessageDisplay.Error("輸出錯誤");
                throw ex;
            } finally {
                this.Cursor = Cursors.Arrow;
                this.Refresh();
                Thread.Sleep(5);
            }
            return(ResultStatus.Success);
        }
Example #5
0
        protected override ResultStatus Export()
        {
            try {
                this.Cursor = Cursors.WaitCursor;
                this.Refresh();
                Thread.Sleep(5);
                lblProcessing.Visible = true;
                ShowMsg("開始轉檔...");
                dao43010 = new D43010();
                dao43020 = new D43020();
                #region ue_export_before
                //130批次作業做完
                string rtnStr, oswGrp;
                oswGrp = dwOswGrp.EditValue + "%";
                rtnStr = PbFunc.f_chk_130_wf(_ProgramID, txtSDate.DateTimeValue, oswGrp);
                if (rtnStr != "")
                {
                    DialogResult result = MessageDisplay.Choose(txtSDate.Text + "-" + rtnStr + ",是否要繼續?");
                    if (result == DialogResult.No)
                    {
                        lblProcessing.Visible = false;
                        return(ResultStatus.Fail);
                    }
                }
                #endregion

                string rptName, rptId, file;
                int    rowStart;
                rptName = "股票期貨保證金狀況表-標的證券為受益憑證";
                rptId   = "43010";
                ShowMsg(rptId + '-' + rptName + " 轉檔中...");

                //1. 讀取檔案
                DataTable dt43010 = dao43010.d_43010(txtSDate.DateTimeValue.ToString("yyyyMMdd"), oswGrp, "S");
                if (dt43010.Rows.Count == 0)
                {
                    MessageDisplay.Info(txtSDate.Text + "," + rptId + '-' + rptName + ",無任何資料!");
                    //return ResultStatus.Fail;
                }
                int rowIndex = dt43010.Rows.Count;

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

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

                //4. 切換Sheet
                Worksheet ws43010  = workbook.Worksheets[0];
                string    dataDate = "資料日期:" + Environment.NewLine + txtSDate.DateTimeValue.Year + "年" + txtSDate.DateTimeValue.Month + "月" + txtSDate.DateTimeValue.Day + "日";
                ws43010.Cells[0, 9].Value    = dataDate;
                ws43010.Cells[35, 14].Value  = dataDate;
                ws43010.Cells[73, 14].Value  = dataDate;
                ws43010.Cells[110, 14].Value = dataDate;

                //5. 填入資料
                int cnt      = 0;
                int f        = 0;
                int rowCount = dt43010.Rows.Count;
                foreach (DataRow dr in dt43010.Rows)
                {
                    //5.1 一、現行收取保證金金額
                    //從B3開始填資料
                    rowStart = 2;
                    cnt      = cnt + 1;
                    ws43010.Cells[rowStart + f, 1].Value = cnt.AsString();
                    ws43010.Cells[rowStart + f, 2].SetValue(dr["MG1_KIND_ID"]);
                    ws43010.Cells[rowStart + f, 3].SetValue(dr["APDK_NAME"]);
                    ws43010.Cells[rowStart + f, 4].SetValue(dr["APDK_STOCK_ID"]);
                    ws43010.Cells[rowStart + f, 5].SetValue(dr["PID_NAME"]);
                    ws43010.Cells[rowStart + f, 6].SetValue(dr["MG1_CUR_CM"]);
                    ws43010.Cells[rowStart + f, 7].SetValue(dr["MG1_CUR_MM"]);
                    ws43010.Cells[rowStart + f, 8].SetValue(dr["MG1_CUR_IM"]);
                    ws43010.Cells[rowStart + f, 9].SetValue(dr["MG1_CUR_CM_RATE"]);
                    ws43010.Cells[rowStart + f, 10].SetValue(dr["MG1_CUR_MM_RATE"]);
                    ws43010.Cells[rowStart + f, 11].SetValue(dr["MG1_CUR_IM_RATE"]);

                    //5.2 二、本日結算保證金計算
                    //SMA 從B41開始填資料
                    rowStart = 40;
                    ws43010.Cells[rowStart + f, 1].Value = cnt.AsString();
                    ws43010.Cells[rowStart + f, 2].SetValue(dr["MG1_KIND_ID"]);
                    ws43010.Cells[rowStart + f, 3].SetValue(dr["APDK_NAME"]);
                    ws43010.Cells[rowStart + f, 4].SetValue(dr["APDK_STOCK_ID"]);
                    ws43010.Cells[rowStart + f, 5].SetValue(dr["PID_NAME"]);

                    ws43010.Cells[rowStart + f, 6].SetValue(dr["MG1_PRICE"]);
                    ws43010.Cells[rowStart + f, 7].SetValue(dr["MG1_XXX"]);
                    ws43010.Cells[rowStart + f, 8].SetValue(dr["MG1_RISK"]);
                    ws43010.Cells[rowStart + f, 9].SetValue(dr["MG1_CP_RISK"]);
                    ws43010.Cells[rowStart + f, 10].SetValue(dr["MG1_MIN_RISK"]);

                    ws43010.Cells[rowStart + f, 11].SetValue(dr["MG1_CP_CM"]);
                    ws43010.Cells[rowStart + f, 12].SetValue(dr["MG1_CUR_CM"]);
                    ws43010.Cells[rowStart + f, 13].SetValue(dr["MG1_CHANGE_RANGE"]);
                    ws43010.Cells[rowStart + f, 14].SetValue(dr["MG1_CHANGE_FLAG"]);
                    f++;
                }//foreach (DataRow dr in dt43010.Rows)
                dt43010 = dao43010.d_43010(txtSDate.DateTimeValue.ToString("yyyyMMdd"), oswGrp, "E");
                cnt     = 0;
                f       = 0;
                foreach (DataRow dr in dt43010.Rows)
                {
                    //EWMA 從B79開始填資料
                    rowStart = 78;
                    cnt      = cnt + 1;
                    ws43010.Cells[rowStart + f, 1].Value = cnt.AsString();
                    ws43010.Cells[rowStart + f, 2].SetValue(dr["MG1_KIND_ID"]);
                    ws43010.Cells[rowStart + f, 3].SetValue(dr["APDK_NAME"]);
                    ws43010.Cells[rowStart + f, 4].SetValue(dr["APDK_STOCK_ID"]);
                    ws43010.Cells[rowStart + f, 5].SetValue(dr["PID_NAME"]);

                    ws43010.Cells[rowStart + f, 6].SetValue(dr["MG1_PRICE"]);
                    ws43010.Cells[rowStart + f, 7].SetValue(dr["MG1_XXX"]);
                    ws43010.Cells[rowStart + f, 8].SetValue(dr["MG1_RISK"]);
                    ws43010.Cells[rowStart + f, 9].SetValue(dr["MG1_CP_RISK"]);
                    ws43010.Cells[rowStart + f, 10].SetValue(dr["MG1_MIN_RISK"]);

                    ws43010.Cells[rowStart + f, 11].SetValue(dr["MG1_CP_CM"]);
                    ws43010.Cells[rowStart + f, 12].SetValue(dr["MG1_CUR_CM"]);
                    ws43010.Cells[rowStart + f, 13].SetValue(dr["MG1_CHANGE_RANGE"]);
                    ws43010.Cells[rowStart + f, 14].SetValue(dr["MG1_CHANGE_FLAG"]);
                    f++;
                }//foreach (DataRow dr in dt43010.Rows)
                dt43010 = dao43010.d_43010(txtSDate.DateTimeValue.ToString("yyyyMMdd"), oswGrp, "M");
                cnt     = 0;
                f       = 0;
                foreach (DataRow dr in dt43010.Rows)
                {
                    //MAX 從B116開始填資料
                    rowStart = 115;
                    cnt      = cnt + 1;
                    ws43010.Cells[rowStart + f, 1].Value = cnt.AsString();
                    ws43010.Cells[rowStart + f, 2].SetValue(dr["MG1_KIND_ID"]);
                    ws43010.Cells[rowStart + f, 3].SetValue(dr["APDK_NAME"]);
                    ws43010.Cells[rowStart + f, 4].SetValue(dr["APDK_STOCK_ID"]);
                    ws43010.Cells[rowStart + f, 5].SetValue(dr["PID_NAME"]);

                    ws43010.Cells[rowStart + f, 6].SetValue(dr["MG1_PRICE"]);
                    ws43010.Cells[rowStart + f, 7].SetValue(dr["MG1_XXX"]);
                    ws43010.Cells[rowStart + f, 8].SetValue(dr["MG1_RISK"]);
                    ws43010.Cells[rowStart + f, 9].SetValue(dr["MG1_CP_RISK"]);
                    ws43010.Cells[rowStart + f, 10].SetValue(dr["MG1_MIN_RISK"]);

                    ws43010.Cells[rowStart + f, 11].SetValue(dr["MG1_CP_CM"]);
                    ws43010.Cells[rowStart + f, 12].SetValue(dr["MG1_CUR_CM"]);
                    ws43010.Cells[rowStart + f, 13].SetValue(dr["MG1_CHANGE_RANGE"]);
                    ws43010.Cells[rowStart + f, 14].SetValue(dr["MG1_CHANGE_FLAG"]);

                    f++;
                }//foreach (DataRow dr in dt43010.Rows)

                //6. 刪除空白列
                int delRowCnt = 30 - rowIndex;
                if (rowIndex < 30)
                {
                    rowStart = 115;
                    ws43010.Rows.Remove(rowIndex + rowStart, delRowCnt);
                    rowStart = 78;
                    ws43010.Rows.Remove(rowIndex + rowStart, delRowCnt);
                    rowStart = 40;
                    ws43010.Rows.Remove(rowIndex + rowStart, delRowCnt);
                    rowStart = 2;
                    ws43010.Rows.Remove(rowIndex + rowStart, delRowCnt);
                }

                #region sheet 2
                rptName = "保證金狀況表";
                rptId   = "40011_stat";
                ShowMsg(rptId + '-' + rptName + " 轉檔中...");

                //1. 讀取檔案
                DataTable dt40011stat = dao43020.d_40011_stat(txtSDate.DateTimeValue.ToString("yyyyMMdd"));
                dt40011stat = dt40011stat.Sort("seq_no, kind_id");
                dt40011stat = dt40011stat.Filter("prod_type ='F' and param_key = 'ETF' and osw_grp like'" + oswGrp + "'");
                if (dt40011stat.Rows.Count == 0)
                {
                    MessageDisplay.Info(txtSDate.Text + "," + rptId + '-' + rptName + ",無任何資料!");
                    //return ResultStatus.Fail;
                }


                //2. 切換Sheet
                ws43010 = workbook.Worksheets["fut_3index"];

                //3. 填入資料
                ws43010.Cells[0, 0].Value = "資料日期:" + Environment.NewLine + txtSDate.DateTimeValue.Year + "年" + txtSDate.DateTimeValue.Month + "月" + txtSDate.DateTimeValue.Day + "日";
                int rowNum = 3 - 1;
                foreach (DataRow dr in dt40011stat.Rows)
                {
                    for (f = 0; f < 37; f++)
                    {
                        ws43010.Cells[rowNum, f].SetValue(dr[f]);
                    }
                    rowNum++;
                }

                #endregion

                //存檔
                ws43010 = workbook.Worksheets[0];
                ws43010.ScrollToRow(0);

                //若所有Sheet皆無資料時,刪除檔案
                if (dt43010.Rows.Count == 0 && dt40011stat.Rows.Count == 0)
                {
                    workbook = null;
                    System.IO.File.Delete(file);
                    return(ResultStatus.Fail);
                }
                workbook.SaveDocument(file);
                ShowMsg("轉檔成功");
            }
            catch (Exception ex) {
                //WriteLog(ex, "", false); 如果不用throw會繼續往下執行(?
                ShowMsg("轉檔錯誤");
                throw ex;
            }
            finally {
                this.Cursor = Cursors.Arrow;
                this.Refresh();
                Thread.Sleep(5);
            }
            return(ResultStatus.Success);
        }
Example #6
0
        protected override ResultStatus Export()
        {
            try {
                lblProcessing.Text    = "轉檔中...";
                lblProcessing.Visible = true;
                dao42020 = new D42020();
                #region ue_export_before
                //1. 判斷資料已轉入
                int    rtn;
                string ymd = txtSDate.Text.Replace("/", "");
                rtn = dao42020.mgr3Count(ymd);
                if (rtn == 0)
                {
                    DialogResult result = MessageDisplay.Choose(" 當日保證金適用比例資料未轉入完畢,是否要繼續?");
                    if (result == DialogResult.No)
                    {
                        lblProcessing.Visible = false;
                        return(ResultStatus.Fail);
                    }
                }
                //2. 130批次作業做完
                string rtnStr;
                rtnStr = PbFunc.f_chk_130_wf(_ProgramID, txtSDate.DateTimeValue, "1");
                if (rtnStr != "")
                {
                    DialogResult result = MessageDisplay.Choose(txtSDate.Text + "-" + rtnStr + ",是否要繼續?");
                    if (result == DialogResult.No)
                    {
                        lblProcessing.Visible = false;
                        return(ResultStatus.Fail);
                    }
                }
                #endregion

                string rptName, rptId, prodType, status, file;
                int    f, rowStart, chgCnt, spaceRow;
                rptName            = "股票選擇權保證金概況表";
                rptId              = "42020";
                lblProcessing.Text = rptId + '-' + rptName + " 轉檔中...";
                prodType           = "O";

                //1. 讀取資料(保證金適用比例級距)
                DataTable dt42020Mgrt1 = dao42020.d_42020_mgrt1("O");
                if (dt42020Mgrt1.Rows.Count == 0)
                {
                    ShowMsg("轉檔失敗");
                    MessageDisplay.Info(txtSDate.Text + "," + rptId + '-' + rptName + ",讀取「保證金適用比例級距」無任何資料!");
                    return(ResultStatus.Fail);
                }

                //2. 讀取資料(當日保證金適用比例)
                DataTable dt42020 = dao42020.d_42020(ymd, prodType);
                if (dt42020.Rows.Count == 0)
                {
                    ShowMsg("轉檔失敗");
                    MessageDisplay.Info(txtSDate.Text + "," + rptId + '-' + rptName + ",讀取「當日保證金適用比例」無任何資料!");
                    return(ResultStatus.Fail);
                }

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

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

                //5. 切換Sheet
                Worksheet ws42020 = workbook.Worksheets[0];
                ws42020.Cells[1, 7].Value = "資料日期:" + txtSDate.DateTimeValue.ToString("yyyy年MM月dd日");
                rowStart = 7;

                //6. 從B8 開始放資料
                ws42020.Import(dt42020Mgrt1, false, rowStart, 1);

                rowStart = 21;
                spaceRow = 200;
                chgCnt   = 0;

                //7. 從B22 開始放資料
                ws42020.Import(dt42020, false, rowStart, 1);

                //8. 2015.06.01 需10400043
                DataTable dt42020Compute = dao42020.d_42020Compute(ymd, prodType);
                if (dt42020Compute.Rows.Count == 0)
                {
                    MessageDisplay.Info(txtSDate.Text + "," + rptId + '-' + rptName + ",讀取「當日保證金適用比例」無任何資料!");
                    return(ResultStatus.Fail);
                }
                for (f = 0; f < dt42020Compute.Rows.Count; f++)
                {
                    status = "";
                    DataRow dr = dt42020Compute.Rows[f];
                    if (dr["MGR3_CM"].AsDecimal() != dr["MGR3_CUR_CM"].AsDecimal())
                    {
                        chgCnt = chgCnt + 1;
                        status = "由";
                        if (dr["MGR3_CUR_LEVEL"].AsString() == "Z")
                        {
                            status = status + (dr["MGR3_CUR_CM"].AsDecimal() * 100).AsString() + "%";
                        }
                        else
                        {
                            status = status + dr["MGRT1_LAST_LEVEL_NAME"].AsString();
                        }
                        status = status + "調整為";
                        if (dr["MGR3_LEVEL"].AsString() == "Z")
                        {
                            status = status + (dr["MGR3_CM"].AsDecimal() * 100).AsString() + "%";
                        }
                        else
                        {
                            status = status + dr["MGRT1_LEVEL_NAME"].AsString();
                        }
                    }
                    ws42020.Cells[f + rowStart, 9].Value = status;
                    switch (dr["MGR3_STATUS"].AsString())
                    {
                    case "P":
                        status = "暫停交易";
                        break;

                    default:
                        status = "";
                        break;
                    }
                    ws42020.Cells[f + rowStart, 10].Value = status;
                }
                if (chgCnt > 0)
                {
                    ws42020.Cells[rowStart + spaceRow + 1, 1].Value = "本日級距變動檔數:" + chgCnt.ToString("##0");
                }

                //9. 刪除空白列
                int rowIndex = dt42020.Rows.Count;
                if (spaceRow > rowIndex)
                {
                    ws42020.Rows.Remove(rowIndex + rowStart, spaceRow - rowIndex);
                }

                //10. 存檔
                ws42020.ScrollToRow(0);
                workbook.SaveDocument(file);
            }
            catch (Exception ex) {
                //WriteLog(ex, "", false); 如果不用throw會繼續往下執行(?
                lblProcessing.Text = "轉檔失敗";
                throw ex;
            }
            lblProcessing.Text = "轉檔成功";

            return(ResultStatus.Success);
        }