Example #1
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);
        }
Example #2
0
        protected override ResultStatus Import()
        {
            base.Import(gcMain);

            //1.讀檔並寫入DataTable
            try {
                Stream openFile = PbFunc.wf_getfileopenname("56090.txt", "*.txt (*.txt)|*.txt");

                //選擇取消時, 不做處理
                if (openFile == null)
                {
                    return(ResultStatus.FailButNext);
                }

                ImportShow.Text = "開始轉檔...";
                ImportShow.Show();

                using (TextReader tr = new StreamReader(openFile)) {
                    string line;
                    while ((line = tr.ReadLine()) != null)
                    {
                        DataRow d         = dtReadTxt.NewRow();
                        float   DISC_RATE = float.Parse(line.SubStr(32, 9)) == 0 ? 0 :
                                            float.Parse(line.SubStr(32, 9)) / 100000000;
                        d[0]  = line.SubStr(0, 6);
                        d[1]  = line.SubStr(6, 7);
                        d[2]  = line.SubStr(13, 7);
                        d[3]  = line.SubStr(20, 4);
                        d[4]  = line.SubStr(24, 8);
                        d[5]  = DISC_RATE == 0 ? "0" : DISC_RATE.ToString("##.##");
                        d[6]  = line.SubStr(41, 10);
                        d[7]  = line.SubStr(51, 10);
                        d[8]  = GlobalInfo.USER_ID;
                        d[9]  = DateTime.Now;
                        d[10] = line.SubStr(61, 2);

                        dtReadTxt.Rows.Add(d);
                    }
                }

                //2.確認資料日期&畫面日期(讀取資料)
                string datadate = dtReadTxt.Rows[0][0].ToString();
                if (datadate != txtYM.Text.Replace("/", ""))
                {
                    DialogResult result = MessageBox.Show("資料年月(" + datadate + ")與畫面年月不同,是否將畫面改為資料年月?", "注意", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.No)
                    {
                        return(ResultStatus.Fail);
                    }
                    else
                    {
                        txtYM.Text = datadate.SubStr(0, 4) + "/" + datadate.SubStr(4, 2);
                    }
                }
                //3.刪除舊有資料
                if (dao56090.DeleteByYM(datadate) < 0)
                {
                    MessageDisplay.Error("刪除失敗");
                    return(ResultStatus.Fail);
                }
                //4.轉入資料即PB的wf_importfile()→wf_importfile_extra()
                if (Save(new PokeBall()) == ResultStatus.Success)
                {
                    ImportShow.Text = "轉檔完成!";
                    Retrieve();
                }
                else
                {
                    throw new Exception("轉檔失敗");
                }
            } catch (Exception ex) {
                throw ex;
            }
            return(ResultStatus.Success);
        }