public void TxtWriteToDataTableTest()
        {
            Stream    openFile  = FileToStream(Path.Combine(Environment.CurrentDirectory, "Excel_Template", "20231.txt"));
            DataTable dtReadTxt = new D20231().List20231("20180329").Clone();
            DataTable dataTable = new B20231().TxtWriteToDataTable(openFile, dtReadTxt);

            Assert.IsNotNull(dataTable);
        }
Esempio n. 2
0
        /// <summary>
        /// 這功能user沒什麼在使用 用pb測試也發現這功能怪怪的 所以邏輯就照pb翻
        /// </summary>
        /// <returns></returns>
        protected override ResultStatus Import()
        {
            Stream openFile = PbFunc.wf_getfileopenname("20231.txt", "*.txt (*.txt)|*.txt");

            if (openFile == null)
            {
                return(ResultStatus.Fail);
            }

            DataTable dtReadTxt = dao20231.List20231(emDate.Text.Replace("/", "")).Clone();
            DataTable dt        = new B20231().TxtWriteToDataTable(openFile, dtReadTxt);

            if (dt.Rows.Count > 0)
            {
                DateTime dateTime = dt.Rows[0][0].AsDateTime("yyyyMMdd");
                if (dateTime != DateTime.MinValue)
                {
                    emProdDate.Text = dateTime.ToString("yyyy/MM/dd");
                }
            }

            ShowMsg("開始轉檔...");

            string IsDone = "";

            IsDone = WfChkDate();
            DataTable chkData = dao20231.List20231(emDate.Text.Replace("/", ""));

            if (chkData.Rows.Count <= 0)
            {
                MessageDisplay.Info("轉入筆數為0!");
                return(ResultStatus.Fail);
            }
            //確認
            if (!string.IsNullOrEmpty(IsDone))
            {
                return(ResultStatus.Fail);
            }
            //if (IsDone) {
            //   //TODO PB確認階段以後的邏輯有問題 需要等期交所確認真正需求
            //   return ResultStatus.Success;
            //}
            //轉入資料
            ResultData myResultData = dao20231.UpdatePLS4(dt);

            //期貨/選擇權
            gcMain.BeginUpdate();
            string    lsymd    = emDate.Text.Replace("/", "");
            string    lspdkymd = emProdDate.Text.Replace("/", "");
            DataTable dtHPDK   = dao20231.ListHpdkData(lspdkymd);

            foreach (DataRow dr in chkData.Rows)
            {
                dr["PLS4_YMD"]       = lsymd;
                dr["PLS4_PDK_YMD"]   = lspdkymd;
                dr["PLS4_W_USER_ID"] = GlobalInfo.USER_ID;
                dr["PLS4_W_TIME"]    = DateTime.Now;
                int lirtn = dtHPDK.Rows.IndexOf(dtHPDK.Select($"PLS4_KIND_ID2='{dr["PLS4_KIND_ID2"].AsString()}'")[0]);
                if (lirtn > -1)
                {
                    dr["PLS4_FUT"] = dtHPDK.Rows[lirtn]["PLS4_FUT"];
                    dr["PLS4_OPT"] = dtHPDK.Rows[lirtn]["PLS4_OPT"];
                }
                else
                {
                    dr["PLS4_FUT"] = "";
                    dr["PLS4_OPT"] = "";
                }
            }
            gcMain.DataSource = chkData;
            gcMain.EndUpdate();

            //匯入之後股票代號和個股商品2碼為可編輯狀態
            PLS4_SID.AppearanceCell.BackColor      = Color.White;
            PLS4_SID.OptionsColumn.AllowEdit       = true;
            PLS4_KIND_ID2.AppearanceCell.BackColor = Color.White;

            //存檔 這段也怪怪的 PB 根本就沒有寫入任何路徑在is_save_file這個變數
            string filepath = Path.Combine(GlobalInfo.DEFAULT_REPORT_DIRECTORY_PATH, "");

            if (string.IsNullOrEmpty(filepath))
            {
                return(ResultStatus.Fail);
            }
            gvMain.ExportToXlsx(filepath);
            //Write LOGF
            WriteLog("轉出檔案:" + filepath, "E");
            EndExport();
            return(ResultStatus.Success);
        }