Пример #1
0
        protected override ResultStatus Open()
        {
            base.Open();
            //設定日期和全域變數
            txtSDate.DateTimeValue = DateTime.Now;
#if DEBUG
            txtSDate.EditValue = "2019/02/27";
#endif
            ymd       = txtSDate.DateTimeValue.ToString("yyyyMMdd");
            isAdjType = "2";

            //取得table的schema,因為程式開啟會預設插入一筆空資料列
            DataTable dtMGD2 = dao40071.d_40071();
            gcMain.DataSource = dtMGD2;

            #region  拉選單設定
            //調整倍數下拉選單
            //List<LookupItem> rateList = new List<LookupItem>(){
            //                               new LookupItem() { ValueMember = "1.5", DisplayMember = "1.5"},
            //                               new LookupItem() { ValueMember = "2", DisplayMember = "2"},
            //                               new LookupItem() { ValueMember = "3", DisplayMember = "3" }};

            DataTable dtRateList = new CODW().ListLookUpEdit("40072", "RATE");
            rateLookUpEdit = new RepositoryItemLookUpEdit();
            rateLookUpEdit.SetColumnLookUp(dtRateList, "CODW_ID", "CODW_DESC", TextEditStyles.DisableTextEditor, null);
            gcMain.RepositoryItems.Add(rateLookUpEdit);
            RATE_INPUT.ColumnEdit = rateLookUpEdit;

            //級距下拉選單
            //期貨
            prodTypeLookUpEdit1 = new RepositoryItemLookUpEdit();
            prodTypeLookUpEdit1.SetColumnLookUp(dtFLevel, "MGRT1_LEVEL", "MGRT1_LEVEL_NAME", TextEditStyles.DisableTextEditor, null);
            gcDetail.RepositoryItems.Add(prodTypeLookUpEdit1);
            //選擇權
            prodTypeLookUpEdit2 = new RepositoryItemLookUpEdit();
            prodTypeLookUpEdit2.SetColumnLookUp(dtOLevel, "MGRT1_LEVEL", "MGRT1_LEVEL_NAME", TextEditStyles.DisableTextEditor, null);
            gcDetail.RepositoryItems.Add(prodTypeLookUpEdit2);
            #endregion

            //預設新增一筆設定資料
            InsertRow();


            //txtSDate.Focus();
            return(ResultStatus.Success);
        }
Пример #2
0
        protected override ResultStatus Save(PokeBall pokeBall)
        {
            string ShowMsg = "儲存錯誤";

            try {
                if (gvMain.RowCount == 0)
                {
                    MessageDisplay.Info("沒有變更資料,不需要存檔!");
                    return(ResultStatus.Fail);
                }
                dao40071 = new D40071();
                daoMGD2  = new MGD2();
                daoMGD2L = new MGD2L();
                #region ue_save_before
                gvMain.CloseEditor();
                gvMain.UpdateCurrentRow();
                string  ymd, issueBeginYmd, kindID, adjTypeName, tradeYmd, adjRsn, adjType;
                decimal cm = 0, curCm;
                int     count;

                /***************************
                 * 調整類型:
                 * 0一般
                 * 1長假
                 * 2處置股票
                 * 3股票
                 ****************************/
                adjType = "0";

                ymd = txtSDate.DateTimeValue.ToString("yyyyMMdd");

                DataTable dtGrid = (DataTable)gcMain.DataSource;
                DataView  dv     = dtGrid.AsDataView();
                dv.RowFilter = " ab_type in ('-','A')";
                DataTable dtFiltered = dv.ToTable(); //dw_1

                cbxCodeY.Checked = true;
                cbxCodeN.Checked = true;
                cbxCode.Checked  = true;

                foreach (DataRow dr in dtFiltered.Rows)
                {
                    if (dr.RowState == DataRowState.Deleted)
                    {
                        continue;
                    }
                    kindID        = dr["KIND_ID"].AsString();
                    issueBeginYmd = dr["ISSUE_BEGIN_YMD"].AsString();
                    adjRsn        = dr["ADJ_RSN"].AsString();
                    curCm         = dr["CUR_CM"].AsDecimal();
                    if (adjRsn == "S")
                    {
                        cm = dr["SMA_CM"].AsDecimal();
                    }
                    if (adjRsn == "E")
                    {
                        cm = dr["EWMA_CM"].AsDecimal();
                    }
                    if (adjRsn == "M")
                    {
                        cm = dr["MAXV_CM"].AsDecimal();
                    }
                    if (adjRsn == "s")
                    {
                        cm = dr["FUT_SMA_CM"].AsDecimal();
                    }
                    if (adjRsn == "e")
                    {
                        cm = dr["FUT_EWMA_CM"].AsDecimal();
                    }
                    if (adjRsn == "m")
                    {
                        cm = dr["FUT_MAXV_CM"].AsDecimal();
                    }
                    if (adjRsn == "U")
                    {
                        cm = dr["USER_CM"].AsDecimal();
                    }
                    if (dr["ADJ_CODE"].AsString() == "Y")
                    {
                        /******************************************
                        *  確認商品是否在同一交易日不同情境下設定過
                        ******************************************/
                        DataTable dtCheck = daoMGD2.IsProdSetOnSameDay(kindID, ymd, adjType);
                        count       = dtCheck.Rows[0]["LI_COUNT"].AsInt();
                        adjTypeName = dtCheck.Rows[0]["LS_ADJ_TYPE_NAME"].AsString();
                        if (count > 0)
                        {
                            MessageDisplay.Error(kindID + ",交易日(" + ymd + ")在" + adjTypeName + "已有資料");
                            return(ResultStatus.FailButNext);
                        }

                        /*********************************
                         * 確認商品是否在同一生效日區間設定過
                         * 生效起日若與生效迄日相同,不重疊
                         * ex: 10/11的至10/31一般交易時段結束止,10/30的從10/31一般交易時段結束後始>>應不重疊
                         *************************************/
                        dtCheck     = daoMGD2.IsProdSetInSameInterval(kindID, ymd, issueBeginYmd);
                        count       = dtCheck.Rows[0]["LI_COUNT"].AsInt();
                        adjTypeName = dtCheck.Rows[0]["LS_ADJ_TYPE_NAME"].AsString();
                        tradeYmd    = dtCheck.Rows[0]["LS_TRADE_YMD"].AsString();
                        if (count > 0)
                        {
                            MessageDisplay.Error(kindID + "," + adjTypeName + ",交易日(" + tradeYmd + ")在同一生效日區間內已有資料");
                            return(ResultStatus.FailButNext);
                        }
                        if (cm == curCm)
                        {
                            MessageDisplay.Error(kindID + ",調整前後保證金一致,請重新輸入");
                            return(ResultStatus.FailButNext);
                        }
                    }//if (dr["ADJ_CODE"].AsString() == "Y")

                    /**************************************
                    *  判斷調整前後值不同,相同則警示且無法存檔
                    **************************************/
                    if (adjRsn == "U")
                    {
                        if (cm == 0)
                        {
                            MessageDisplay.Error(kindID + ",請輸入保證金金額");
                            return(ResultStatus.FailButNext);
                        }
                    }
                    if (cm == 0)
                    {
                        MessageDisplay.Error(kindID + ",保證金計算值為空,請選擇其他模型");
                        return(ResultStatus.FailButNext);
                    }
                }
                #endregion

                DateTime wTime, date;
                date = txtSDate.DateTimeValue;
                int     found, colIndex, found2, currRow;
                string  dbname;
                decimal curMM = 0, curIM = 0, MM = 0, IM = 0, rate = 0;

                wTime = DateTime.Now;

                DataTable dtMGD2    = dao40071.d_40071(ymd, adjType); //ids_mgd2
                DataTable dtMGD2Log = dao40071.d_40071_log();         //ids_old
                dtMGD2Log.Clear();                                    //只取schema
                                                                      //再產生一張空的 d_40071 table
                DataTable dtEmpty = dao40071.d_40071(ymd, adjType);   //dw_3
                dtEmpty.Clear();
                dtEmpty.Columns.Remove(dtEmpty.Columns["CPSORT"]);    //刪除排序用的運算欄位

                foreach (DataRow dr in dtFiltered.Rows)
                {
                    if (dr.RowState == DataRowState.Deleted)
                    {
                        continue;
                    }
                    kindID        = dr["KIND_ID"].ToString();
                    issueBeginYmd = dr["ISSUE_BEGIN_YMD"].AsString();
                    adjRsn        = dr["ADJ_RSN"].AsString();

                    dv           = dtMGD2.AsDataView();
                    dv.RowFilter = "MGD2_KIND_ID = '" + kindID + "'";
                    DataTable dtMGD2Filtered = dv.ToTable();

                    if (dtMGD2Filtered.Rows.Count > 0)
                    {
                        foreach (DataRow drMGD2 in dtMGD2Filtered.Rows)
                        {
                            currRow = dtMGD2Log.Rows.Count;
                            dtMGD2Log.Rows.Add();
                            for (colIndex = 0; colIndex < dtMGD2.Columns.Count; colIndex++)
                            {
                                //先取欄位名稱,因為兩張table欄位順序不一致
                                dbname = dtMGD2.Columns[colIndex].ColumnName;
                                if (dbname == "CPSORT")
                                {
                                    continue;             //這個欄位是拿來排序用的,故無需複製
                                }
                                dtMGD2Log.Rows[currRow][dbname] = drMGD2[colIndex];
                            }
                            if (dr["ADJ_CODE"].AsString() == "N")
                            {
                                dtMGD2Log.Rows[currRow]["MGD2_L_TYPE"] = "D";
                            }
                            else
                            {
                                dtMGD2Log.Rows[currRow]["MGD2_L_TYPE"] = "U";
                            }
                            dtMGD2Log.Rows[currRow]["MGD2_L_USER_ID"] = GlobalInfo.USER_ID;
                            dtMGD2Log.Rows[currRow]["MGD2_L_TIME"]    = wTime;
                        }//foreach (DataRow drMGD2 in dtMGD2.Rows)

                        //刪除已存在資料
                        ShowMsg = "MGD2資料刪除失敗";
                        if (daoMGD2.DeleteMGD2(ymd, adjType, kindID) < 0)
                        {
                            MessageDisplay.Error("MGD2資料刪除失敗");
                            return(ResultStatus.FailButNext);
                        }
                    }
                    //判斷是否重新塞入新資料
                    count = daoMGD2.IsInsertNeeded(ymd, adjType, kindID);
                    if (count == 0)
                    {
                        dtEmpty.Rows.Add();
                        found = dtEmpty.Rows.Count - 1;
                        dtEmpty.Rows[found]["MGD2_YMD"]       = ymd;
                        dtEmpty.Rows[found]["MGD2_PROD_TYPE"] = dr["PROD_TYPE"];
                        dtEmpty.Rows[found]["MGD2_KIND_ID"]   = kindID;
                        dtEmpty.Rows[found]["MGD2_ADJ_TYPE"]  = adjType;

                        curCm = dr["CUR_CM"].AsDecimal();
                        curMM = dr["CUR_MM"].AsDecimal();
                        curIM = dr["CUR_IM"].AsDecimal();

                        dtEmpty.Rows[found]["MGD2_CUR_CM"] = curCm;
                        dtEmpty.Rows[found]["MGD2_CUR_MM"] = curMM;
                        dtEmpty.Rows[found]["MGD2_CUR_IM"] = curIM;

                        if (adjRsn == "S")
                        {
                            rate = dr["SMA_ADJ_RATE"].AsDecimal();
                            cm   = dr["SMA_CM"].AsDecimal();
                            MM   = dr["SMA_MM"].AsDecimal();
                            IM   = dr["SMA_IM"].AsDecimal();
                        }
                        if (adjRsn == "E")
                        {
                            rate = dr["EWMA_ADJ_RATE"].AsDecimal();
                            cm   = dr["EWMA_CM"].AsDecimal();
                            MM   = dr["EWMA_MM"].AsDecimal();
                            IM   = dr["EWMA_IM"].AsDecimal();
                        }
                        if (adjRsn == "M")
                        {
                            rate = dr["MAXV_ADJ_RATE"].AsDecimal();
                            cm   = dr["MAXV_CM"].AsDecimal();
                            MM   = dr["MAXV_MM"].AsDecimal();
                            IM   = dr["MAXV_IM"].AsDecimal();
                        }
                        if (adjRsn == "s")
                        {
                            rate = dr["FUT_SMA_ADJ_RATE"].AsDecimal();
                            cm   = dr["FUT_SMA_CM"].AsDecimal();
                            MM   = dr["FUT_SMA_MM"].AsDecimal();
                            IM   = dr["FUT_SMA_IM"].AsDecimal();
                        }
                        if (adjRsn == "e")
                        {
                            rate = dr["FUT_EWMA_ADJ_RATE"].AsDecimal();
                            cm   = dr["FUT_EWMA_CM"].AsDecimal();
                            MM   = dr["FUT_EWMA_MM"].AsDecimal();
                            IM   = dr["FUT_EWMA_IM"].AsDecimal();
                        }
                        if (adjRsn == "m")
                        {
                            rate = dr["FUT_MAXV_ADJ_RATE"].AsDecimal();
                            cm   = dr["FUT_MAXV_CM"].AsDecimal();
                            MM   = dr["FUT_MAXV_MM"].AsDecimal();
                            IM   = dr["FUT_MAXV_IM"].AsDecimal();
                        }
                        if (adjRsn == "U")
                        {
                            if (kindID == "MXF")
                            {
                                found2 = dtFiltered.Rows.IndexOf(dtFiltered.Select("kind_id = 'TXF'").FirstOrDefault());
                                cm     = dtFiltered.Rows[found2]["USER_CM"].AsDecimal();
                                MM     = dao40070.GetMarginVal("TXF", cm, 0, "MM");
                                MM     = dao40070.GetMarginVal(kindID, MM, 0, "MTX_MM");
                                IM     = dao40070.GetMarginVal("TXF", cm, 0, "IM");
                                IM     = dao40070.GetMarginVal(kindID, IM, 0, "MTX_IM");
                                cm     = dr["USER_CM"].AsDecimal();
                            }
                            else
                            {
                                cm = dr["USER_CM"].AsDecimal();
                                MM = dao40070.GetMarginVal(kindID, cm, 0, "MM");
                                IM = dao40070.GetMarginVal(kindID, cm, 0, "IM");
                            }
                            rate = dao40070.GetMarginVal(kindID, cm, curCm, "ADJ");
                        }

                        dtEmpty.Rows[found]["MGD2_ADJ_RATE"] = rate;
                        dtEmpty.Rows[found]["MGD2_CM"]       = cm;
                        dtEmpty.Rows[found]["MGD2_MM"]       = MM;
                        dtEmpty.Rows[found]["MGD2_IM"]       = IM;
                        dtEmpty.Rows[found]["MGD2_ADJ_RSN"]  = adjRsn;

                        dtEmpty.Rows[found]["MGD2_ADJ_CODE"]        = dr["ADJ_CODE"];
                        dtEmpty.Rows[found]["MGD2_ISSUE_BEGIN_YMD"] = issueBeginYmd;
                        dtEmpty.Rows[found]["MGD2_STOCK_ID"]        = " ";
                        dtEmpty.Rows[found]["MGD2_PROD_SUBTYPE"]    = dr["PROD_SUBTYPE"];
                        dtEmpty.Rows[found]["MGD2_PARAM_KEY"]       = dr["PARAM_KEY"];

                        dtEmpty.Rows[found]["MGD2_AB_TYPE"]       = dr["AB_TYPE"];
                        dtEmpty.Rows[found]["MGD2_CURRENCY_TYPE"] = dr["CURRENCY_TYPE"];
                        dtEmpty.Rows[found]["MGD2_SEQ_NO"]        = dr["SEQ_NO"];
                        dtEmpty.Rows[found]["MGD2_OSW_GRP"]       = dr["OSW_GRP"];
                        dtEmpty.Rows[found]["MGD2_AMT_TYPE"]      = dr["AMT_TYPE"];

                        dtEmpty.Rows[found]["MGD2_W_TIME"]    = wTime;
                        dtEmpty.Rows[found]["MGD2_W_USER_ID"] = GlobalInfo.USER_ID;

                        //type 有AB值分兩筆存
                        if (dr["AB_TYPE"].AsString() == "A")
                        {
                            //DataRow drA = dtEmpty.Rows[found];
                            //dtEmpty.Rows.InsertAt(drA, found - 1);
                            dtEmpty.ImportRow(dtEmpty.Rows[found]);
                            found2 = dtTemp.Rows.IndexOf(dtTemp.Select("kind_id = '" + kindID + "' and ab_type = 'B'").FirstOrDefault());
                            if (found2 < 0)
                            {
                                MessageDisplay.Error(kindID + "無保證金B值資料!");
                                return(ResultStatus.FailButNext);
                            }

                            found = dtEmpty.Rows.Count - 1;
                            dtEmpty.Rows[found]["MGD2_AB_TYPE"] = "B";
                            dtEmpty.Rows[found]["MGD2_CUR_CM"]  = dtTemp.Rows[found2]["CUR_CM"];
                            dtEmpty.Rows[found]["MGD2_CUR_MM"]  = dtTemp.Rows[found2]["CUR_MM"];
                            dtEmpty.Rows[found]["MGD2_CUR_IM"]  = dtTemp.Rows[found2]["CUR_IM"];

                            if (adjRsn == "S")
                            {
                                dtEmpty.Rows[found]["MGD2_CM"] = dtTemp.Rows[found2]["SMA_CM"];
                                dtEmpty.Rows[found]["MGD2_MM"] = dtTemp.Rows[found2]["SMA_MM"];
                                dtEmpty.Rows[found]["MGD2_IM"] = dtTemp.Rows[found2]["SMA_IM"];
                            }
                            if (adjRsn == "E")
                            {
                                dtEmpty.Rows[found]["MGD2_CM"] = dtTemp.Rows[found2]["EWMA_CM"];
                                dtEmpty.Rows[found]["MGD2_MM"] = dtTemp.Rows[found2]["EWMA_MM"];
                                dtEmpty.Rows[found]["MGD2_IM"] = dtTemp.Rows[found2]["EWMA_IM"];
                            }
                            if (adjRsn == "M")
                            {
                                dtEmpty.Rows[found]["MGD2_CM"] = dtTemp.Rows[found2]["MAXV_CM"];
                                dtEmpty.Rows[found]["MGD2_MM"] = dtTemp.Rows[found2]["MAXV_MM"];
                                dtEmpty.Rows[found]["MGD2_IM"] = dtTemp.Rows[found2]["MAXV_IM"];
                            }
                            if (adjRsn == "s")
                            {
                                dtEmpty.Rows[found]["MGD2_CM"] = dtTemp.Rows[found2]["FUT_SMA_CM"];
                                dtEmpty.Rows[found]["MGD2_MM"] = dtTemp.Rows[found2]["FUT_SMA_MM"];
                                dtEmpty.Rows[found]["MGD2_IM"] = dtTemp.Rows[found2]["FUT_SMA_IM"];
                            }
                            if (adjRsn == "e")
                            {
                                dtEmpty.Rows[found]["MGD2_CM"] = dtTemp.Rows[found2]["FUT_EWMA_CM"];
                                dtEmpty.Rows[found]["MGD2_MM"] = dtTemp.Rows[found2]["FUT_EWMA_MM"];
                                dtEmpty.Rows[found]["MGD2_IM"] = dtTemp.Rows[found2]["FUT_EWMA_IM"];
                            }
                            if (adjRsn == "m")
                            {
                                dtEmpty.Rows[found]["MGD2_CM"] = dtTemp.Rows[found2]["FUT_MAXV_CM"];
                                dtEmpty.Rows[found]["MGD2_MM"] = dtTemp.Rows[found2]["FUT_MAXV_MM"];
                                dtEmpty.Rows[found]["MGD2_IM"] = dtTemp.Rows[found2]["FUT_MAXV_IM"];
                            }
                            if (adjRsn == "U")
                            {
                                cm = dao40070.GetMarginVal(kindID, cm, 0, "CM_B");
                                dtEmpty.Rows[found]["MGD2_CM"] = cm;
                                dtEmpty.Rows[found]["MGD2_MM"] = dao40070.GetMarginVal(kindID, MM, cm, "MM_B");
                                dtEmpty.Rows[found]["MGD2_IM"] = dao40070.GetMarginVal(kindID, IM, cm, "IM_B");
                            }
                        } //if (dr["AB_TYPE"].AsString() == "A")
                    }     //if (count == 0)
                }         //foreach (DataRow dr in dtFiltered.Rows)

                //if    ib_print = True then
                //      ids_1.dataobject = dw_1.dataobject
                //      ids_1.reset()
                //      dw_1.RowsCopy(1, dw_1.rowcount(), primary!, ids_1, 1, primary!)
                //end   if

                //dw_3.update()
                ShowMsg = "更新資料庫MGD2錯誤! ";
                if (dtEmpty.Rows.Count > 0)
                {
                    ResultData myResultData = daoMGD2.UpdateMGD2(dtEmpty);
                    if (myResultData.Status == ResultStatus.Fail)
                    {
                        MessageDisplay.Error("更新資料庫MGD2錯誤! ");
                        return(ResultStatus.FailButNext);
                    }
                }
                //ids_old.update()
                ShowMsg = "更新資料庫MGD2L錯誤! ";
                if (dtMGD2Log.Rows.Count > 0)
                {
                    ResultData myResultData = daoMGD2L.UpdateMGD2L(dtMGD2Log);
                    if (myResultData.Status == ResultStatus.Fail)
                    {
                        MessageDisplay.Error("更新資料庫MGD2L錯誤! ");
                        return(ResultStatus.FailButNext);
                    }
                }

                ReportHelper            _ReportHelper   = new ReportHelper(gcMain, _ProgramID, this.Text);
                CommonReportLandscapeA3 reportLandscape = new CommonReportLandscapeA3();//設定為橫向列印
                reportLandscape.printableComponentContainerMain.PrintableComponent = gcMain;
                reportLandscape.IsHandlePersonVisible = false;
                reportLandscape.IsManagerVisible      = false;
                _ReportHelper.Create(reportLandscape);
                _ReportHelper.Export(FileType.PDF, _ReportHelper.FilePath);
                MessageDisplay.Info("報表儲存完成!");
            } catch (Exception ex) {
                MessageDisplay.Error(ShowMsg);
                WriteLog(ex, "", false);
                //throw ex;
            }
            return(ResultStatus.Success);
        }
Пример #3
0
        protected override ResultStatus Retrieve()
        {
            try {
                //清空Grid
                gcMain.DataSource = null;
                SetSaveFlagValue();
                //日期檢核
                if (txtSDate.Text == "1901/01/01")
                {
                    MessageDisplay.Error("請輸入交易日期");
                    return(ResultStatus.Fail);
                }

                int    currRow = 0, prodSeq = 0;
                string kindID = "", abType, stockID, prodSubtype;
                //讀取資料
                ymd = txtSDate.DateTimeValue.ToString("yyyyMMdd");
                DataTable dtMGD2 = dao40071.d_40071(ymd, isAdjType);
                if (dtMGD2.Rows.Count == 0)
                {
                    MessageDisplay.Info("無任何資料!");
                    gcMain.DataSource = dao40074.d_40074();
                    //若無資料,預設新增一筆設定資料
                    InsertRow();
                    return(ResultStatus.Fail);
                }
                //準備空的table給grid
                DataTable dtGrid = dao40074.d_40074();

                txtSDate.Text = dtMGD2.Rows[0]["MGD2_YMD"].AsDateTime("yyyyMMdd").ToString("yyyy/MM/dd");
                foreach (DataRow dr in dtMGD2.Rows)
                {
                    if (kindID != dr["MGD2_KIND_ID"].AsString())
                    {
                        kindID      = dr["MGD2_KIND_ID"].AsString();
                        prodSubtype = dr["MGD2_PROD_SUBTYPE"].AsString();
                        currRow     = dtGrid.Rows.Count;
                        dtGrid.Rows.Add();
                        dtGrid.Rows[currRow]["PROD_TYPE"]    = dr["MGD2_PROD_TYPE"];
                        dtGrid.Rows[currRow]["KIND_ID"]      = kindID;
                        dtGrid.Rows[currRow]["STOCK_ID"]     = dr["MGD2_STOCK_ID"];
                        dtGrid.Rows[currRow]["PROD_SUBTYPE"] = prodSubtype;
                        dtGrid.Rows[currRow]["PARAM_KEY"]    = dr["MGD2_PARAM_KEY"];

                        dtGrid.Rows[currRow]["M_LEVEL"]       = dr["MGD2_LEVEL"];;
                        dtGrid.Rows[currRow]["CURRENCY_TYPE"] = dr["MGD2_CURRENCY_TYPE"];
                        dtGrid.Rows[currRow]["SEQ_NO"]        = dr["MGD2_SEQ_NO"];
                        dtGrid.Rows[currRow]["OSW_GRP"]       = dr["MGD2_OSW_GRP"].AsString();
                        dtGrid.Rows[currRow]["AMT_TYPE"]      = dr["MGD2_AMT_TYPE"];

                        dtGrid.Rows[currRow]["ADJ_CODE"] = dr["MGD2_ADJ_CODE"];
                        dtGrid.Rows[currRow]["PUB_YMD"]  = dr["MGD2_PUB_YMD"];
                        dtGrid.Rows[currRow]["OP_TYPE"]  = " "; //預設為空格

                        prodSeq = dao40074.getProd(kindID, prodSubtype);
                    }
                    dtGrid.Rows[currRow]["PROD_SEQ_NO"] = prodSeq;
                    if (dr["MGD2_AB_TYPE"].AsString() == "B")
                    {
                        dtGrid.Rows[currRow]["CM_B"] = dr["MGD2_CM"];
                        dtGrid.Rows[currRow]["MM_B"] = dr["MGD2_MM"];
                        dtGrid.Rows[currRow]["IM_B"] = dr["MGD2_IM"];
                    }
                    else
                    {
                        dtGrid.Rows[currRow]["CM_A"] = dr["MGD2_CM"];
                        dtGrid.Rows[currRow]["MM_A"] = dr["MGD2_MM"];
                        dtGrid.Rows[currRow]["IM_A"] = dr["MGD2_IM"];
                    }
                }//foreach (DataRow dr in dtMGD2.Rows)

                //排序
                if (dtGrid.Rows.Count != 0)
                {
                    dtGrid = dtGrid.AsEnumerable().OrderBy(x => x.Field <Int32>("SEQ_NO"))
                             .ThenBy(x => x.Field <string>("KIND_ID"))
                             .CopyToDataTable();
                }

                //資料繫結
                gcMain.DataSource = dtGrid;

                //若無資料,預設新增一筆設定資料
                if (gvMain.RowCount == 0)
                {
                    InsertRow();
                }
            } catch (Exception ex) {
                MessageDisplay.Error("讀取錯誤");
                throw ex;
            }
            return(ResultStatus.Success);
        }
Пример #4
0
        protected override ResultStatus Retrieve()
        {
            try {
                //清空Grid
                gcMain.DataSource   = null;
                gcDetail.DataSource = null;

                //日期檢核
                if (txtSDate.Text == "1901/01/01")
                {
                    MessageDisplay.Error("請輸入交易日期");
                    return(ResultStatus.Fail);
                }
                int    currRow = 0;
                string kindID = "", abType, stockID = "";
                //讀取資料
                ymd = txtSDate.DateTimeValue.ToString("yyyyMMdd");
                DataTable dtMGD2 = dao40071.d_40071(ymd, isAdjType);
                if (dtMGD2.Rows.Count == 0)
                {
                    MessageDisplay.Info("無任何資料!");
                    gcMain.DataSource = dao40071.d_40073();
                    //若無資料,預設新增一筆設定資料
                    InsertRow();
                    return(ResultStatus.Fail);
                }
                dtMGD2 = dtMGD2.Sort("mgd2_stock_id,mgd2_kind_id");
                //重設生效日期
                txtEffectiveSDate.Text = "1901/01/01";

                //準備兩個空的table給兩個grid
                DataTable dtInput  = dao40071.d_40073();
                DataTable dtDetail = dao40071.d_40071_detail();
                dtDetail.Columns["ADJ_TYPE"].ColumnName = "OP_TYPE";
                dtDetail.Columns["DATA_YMD"].ColumnName = "YMD";

                //依條件將讀取來的資料分配給兩個grid
                foreach (DataRow dr in dtMGD2.Rows)
                {
                    if (stockID != dr["MGD2_STOCK_ID"].AsString())
                    {
                        stockID = dr["MGD2_STOCK_ID"].AsString();
                        currRow = dtInput.Rows.Count;
                        dtInput.Rows.Add();
                        dtInput.Rows[currRow]["STOCK_ID"] = stockID;
                        dtInput.Rows[currRow]["M_LEVEL"]  = dr["MGD2_LEVEL"];
                        dtInput.Rows[currRow]["ADJ_RSN"]  = dr["MGD2_ADJ_RSN"];
                    }
                    if (kindID != dr["MGD2_KIND_ID"].AsString())
                    {
                        kindID  = dr["MGD2_KIND_ID"].AsString();
                        currRow = dtDetail.Rows.Count;
                        dtDetail.Rows.Add();
                        dtDetail.Rows[currRow]["PROD_TYPE"] = dr["MGD2_PROD_TYPE"];
                        dtDetail.Rows[currRow]["KIND_ID"]   = dr["MGD2_KIND_ID"];
                        dtDetail.Rows[currRow]["STOCK_ID"]  = dr["MGD2_STOCK_ID"];
                        dtDetail.Rows[currRow]["ADJ_RATE"]  = dr["MGD2_ADJ_RATE"];
                        dtDetail.Rows[currRow]["DATA_FLAG"] = "Y";

                        dtDetail.Rows[currRow]["PROD_SUBTYPE"]  = dr["MGD2_PROD_SUBTYPE"];
                        dtDetail.Rows[currRow]["PARAM_KEY"]     = dr["MGD2_PARAM_KEY"];
                        dtDetail.Rows[currRow]["M_CUR_LEVEL"]   = dr["MGD2_CUR_LEVEL"];
                        dtDetail.Rows[currRow]["M_LEVEL"]       = dr["MGD2_LEVEL"];
                        dtDetail.Rows[currRow]["CURRENCY_TYPE"] = dr["MGD2_CURRENCY_TYPE"];

                        dtDetail.Rows[currRow]["SEQ_NO"]          = dr["MGD2_SEQ_NO"];
                        dtDetail.Rows[currRow]["OSW_GRP"]         = dr["MGD2_OSW_GRP"];
                        dtDetail.Rows[currRow]["AMT_TYPE"]        = dr["MGD2_AMT_TYPE"];
                        dtDetail.Rows[currRow]["ISSUE_BEGIN_YMD"] = dr["MGD2_ISSUE_BEGIN_YMD"];
                        dtDetail.Rows[currRow]["YMD"]             = dr["MGD2_YMD"];

                        dtDetail.Rows[currRow]["ADJ_RSN"] = dr["MGD2_ADJ_RSN"];
                        dtDetail.Rows[currRow]["OP_TYPE"] = " "; //預設為空格
                    }
                    if (dr["MGD2_AB_TYPE"].AsString() == "B")
                    {
                        dtDetail.Rows[currRow]["CM_CUR_B"] = dr["MGD2_CUR_CM"];
                        dtDetail.Rows[currRow]["MM_CUR_B"] = dr["MGD2_CUR_MM"];
                        dtDetail.Rows[currRow]["IM_CUR_B"] = dr["MGD2_CUR_IM"];
                        dtDetail.Rows[currRow]["CM_B"]     = dr["MGD2_CM"];
                        dtDetail.Rows[currRow]["MM_B"]     = dr["MGD2_MM"];

                        dtDetail.Rows[currRow]["IM_B"] = dr["MGD2_IM"];
                        dtInput.Rows[dtInput.Rows.Count - 1]["CM_B"] = dr["MGD2_CM"];
                        dtInput.Rows[dtInput.Rows.Count - 1]["MM_B"] = dr["MGD2_MM"];
                        dtInput.Rows[dtInput.Rows.Count - 1]["IM_B"] = dr["MGD2_IM"];
                    }
                    else
                    {
                        dtDetail.Rows[currRow]["CM_CUR_A"] = dr["MGD2_CUR_CM"];
                        dtDetail.Rows[currRow]["MM_CUR_A"] = dr["MGD2_CUR_MM"];
                        dtDetail.Rows[currRow]["IM_CUR_A"] = dr["MGD2_CUR_IM"];
                        dtDetail.Rows[currRow]["CM_A"]     = dr["MGD2_CM"];
                        dtDetail.Rows[currRow]["MM_A"]     = dr["MGD2_MM"];

                        dtDetail.Rows[currRow]["IM_A"] = dr["MGD2_IM"];
                        dtInput.Rows[dtInput.Rows.Count - 1]["CM_A"] = dr["MGD2_CM"];
                        dtInput.Rows[dtInput.Rows.Count - 1]["MM_A"] = dr["MGD2_MM"];
                        dtInput.Rows[dtInput.Rows.Count - 1]["IM_A"] = dr["MGD2_IM"];
                    }
                }//foreach (DataRow dr in dtMGD2.Rows)

                //空值補0
                foreach (DataRow drInput in dtInput.Rows)
                {
                    if (drInput["CM_B"] == DBNull.Value)
                    {
                        drInput["CM_B"] = 0;
                    }
                    if (drInput["MM_B"] == DBNull.Value)
                    {
                        drInput["MM_B"] = 0;
                    }
                    if (drInput["IM_B"] == DBNull.Value)
                    {
                        drInput["IM_B"] = 0;
                    }
                }

                //資料繫結
                gcMain.DataSource   = dtInput;
                gcDetail.DataSource = dtDetail;

                //若無資料,預設新增一筆設定資料
                if (gvDetail.RowCount == 0)
                {
                    InsertRow();
                }
            } catch (Exception ex) {
                MessageDisplay.Error("讀取錯誤");
                throw ex;
            }

            return(ResultStatus.Success);
        }