protected override ResultStatus Save(PokeBall pokeBall) { try { #region ue_save_before gvMain.CloseEditor(); gvMain.UpdateCurrentRow(); string stockID, ymd, kindID, adjTypeName, opType, dbname, stockIDCk; string issueBeginYmd, tradeYmd, mocfYmd, nextYmd, level, currencyType; int currRow, found, count, row, col, prodSeq; decimal ldblRate; DateTime ldtWTIME = DateTime.Now; DataTable dtGrid = (DataTable)gcMain.DataSource; found = dtGrid.Rows.IndexOf(dtGrid.Select("OP_TYPE <> ' '").FirstOrDefault()); if (found + dtDel.Rows.Count == -1) { MessageDisplay.Warning("沒有變更資料,不需要存檔!"); return(ResultStatus.FailButNext); } DataTable dtMGD2; //ids_mgd2 DataTable dtMGD2Log = dao40071.d_40071_log(); //ids_old dtMGD2Log.Clear(); //只取schema this.ymd = txtSDate.DateTimeValue.ToString("yyyyMMdd"); issueBeginYmd = this.ymd; dtMGD2 = dao40071.d_40071(this.ymd, isAdjType); foreach (DataRow dr in dtGrid.Rows) { if (dr.RowState == DataRowState.Deleted) { continue; } opType = dr["OP_TYPE"].ToString(); stockID = dr["STOCK_ID"].AsString(); kindID = dr["KIND_ID"].AsString(); level = dr["M_LEVEL"].AsString(); //檢查調整後級距為從其高且商品類別為選擇權時,是否有輸入保證金B值 if (level == "Z" && dr["PROD_TYPE"].AsString() == "O") { if (dr["CM_B"] == DBNull.Value || dr["MM_B"] == DBNull.Value || dr["IM_B"] == DBNull.Value) { MessageDisplay.Error(stockID + "," + kindID + "的保證金B值未輸入完成"); return(ResultStatus.FailButNext); } } //檢查有異動的資料 if (opType != " ") { //資料修改,將修改前舊資料寫入log if (opType == "U") { dtMGD2.Filter("mgd2_kind_id = '" + kindID + "'"); foreach (DataRow drU in dtMGD2.Rows) { currRow = dtMGD2Log.Rows.Count; dtMGD2Log.Rows.Add(); for (col = 0; col < dtMGD2.Columns.Count; col++) { //先取欄位名稱,因為兩張table欄位順序不一致 dbname = dtMGD2.Columns[col].ColumnName; if (dbname == "CPSORT") { continue; //這個欄位是拿來排序用的,故無需複製 } dtMGD2Log.Rows[currRow][dbname] = drU[col]; } dtMGD2Log.Rows[currRow]["MGD2_L_TYPE"] = "U"; dtMGD2Log.Rows[currRow]["MGD2_L_USER_ID"] = GlobalInfo.USER_ID; dtMGD2Log.Rows[currRow]["MGD2_L_TIME"] = ldtWTIME; } } /******************************************* * 檢查商品與類別是否符合 *******************************************/ prodSeq = dao40074.getProd(kindID, dr["PROD_SUBTYPE"].AsString()); if (prodSeq != dr["PROD_SEQ_NO"].AsInt()) { MessageDisplay.Error(kindID + "與商品類別不符,請確認"); return(ResultStatus.FailButNext); } /***************************************** * 檢查商品代號是否存在及相關資料是否正確 ******************************************/ DataTable dtCheck = dao40074.checkProd(kindID); if (dtCheck.Rows.Count == 0) { MessageDisplay.Error(kindID + "不存在,請重新設定商品代號"); return(ResultStatus.FailButNext); } count = dtCheck.Rows[0]["LI_COUNT"].AsInt(); currencyType = dtCheck.Rows[0]["LS_CURRENCY_TYPE"].AsString(); stockIDCk = dtCheck.Rows[0]["LS_STOCK_ID_CK"].AsString(); if (count == 0) { MessageDisplay.Error(kindID + "不存在,請重新設定商品代號"); return(ResultStatus.FailButNext); } else { if (dr["CURRENCY_TYPE"].AsString() != currencyType) { MessageDisplay.Error(kindID + "的幣別設定錯誤,請重新設定填寫"); return(ResultStatus.FailButNext); } if (dr["prod_subtype"].AsString() == "S" && stockID != stockIDCk) { MessageDisplay.Error(kindID + "的股票代號設定錯誤,請重新設定填寫"); return(ResultStatus.FailButNext); } } /****************************************** * 確認商品是否在同一交易日不同情境下設定過 ******************************************/ DataTable dtSet = dao40071.IsSetOnSameDay(kindID, this.ymd, isAdjType); if (dtSet.Rows.Count == 0) { MessageDisplay.Info("MGD2 " + kindID + " 無任何資料!"); return(ResultStatus.FailButNext); } count = dtSet.Rows[0]["LI_COUNT"].AsInt(); adjTypeName = dtSet.Rows[0]["LS_ADJ_TYPE_NAME"].AsString(); if (count > 0) { MessageDisplay.Error(kindID + ",交易日(" + this.ymd + ")在" + adjTypeName + "已有資料"); return(ResultStatus.FailButNext); } /********************************* * 確認商品是否在同一生效日區間設定過 * 生效起日若與生效迄日相同,不重疊 * ex: 10/11的至10/31一般交易時段結束止,10/30的從10/31一般交易時段結束後始>>應不重疊 *************************************/ dtSet = dao40071.IsSetInSameSession(kindID, this.ymd, issueBeginYmd); count = dtSet.Rows[0]["LI_COUNT"].AsInt(); adjTypeName = dtSet.Rows[0]["LS_ADJ_TYPE_NAME"].AsString(); tradeYmd = dtSet.Rows[0]["LS_TRADE_YMD"].AsString(); if (count > 0) { MessageDisplay.Error(kindID + "," + adjTypeName + ",交易日(" + tradeYmd + ")在同一生效日區間內已有資料"); return(ResultStatus.FailButNext); } } //if (ls_op_type != " ") } //foreach (DataRow dr in dtGrid.Rows) //把刪除的資料寫進log foreach (DataRow drDel in dtDel.Rows) { kindID = drDel["KIND_ID"].AsString(); dtMGD2.Filter("mgd2_kind_id = '" + kindID + "'"); foreach (DataRow drD in dtMGD2.Rows) { currRow = dtMGD2Log.Rows.Count; dtMGD2Log.Rows.Add(); for (col = 0; col < dtMGD2.Columns.Count; col++) { //先取欄位名稱,因為兩張table欄位順序不一致 dbname = dtMGD2.Columns[col].ColumnName; if (dbname == "CPSORT") { continue; //這個欄位是拿來排序用的,故無需複製 } dtMGD2Log.Rows[currRow][dbname] = drD[col]; } dtMGD2Log.Rows[currRow]["MGD2_L_TYPE"] = "D"; dtMGD2Log.Rows[currRow]["MGD2_L_USER_ID"] = GlobalInfo.USER_ID; dtMGD2Log.Rows[currRow]["MGD2_L_TIME"] = ldtWTIME; } } #endregion string prodType; DataTable dtTemp = dao40072.d_40072(); //ids_tmp foreach (DataRow dr in dtGrid.Rows) { if (dr.RowState == DataRowState.Deleted) { continue; } opType = dr["OP_TYPE"].ToString(); //只更新有異動的資料 if (opType != " ") { kindID = dr["KIND_ID"].AsString(); //stockID = dr["KIND_ID"].AsString(); stockID = dr["STOCK_ID"].ToString(); //刪除已存在資料 if (daoMGD2.DeleteMGD2(this.ymd, isAdjType, stockID, kindID) < 0) { MessageDisplay.Error("MGD2資料刪除失敗"); return(ResultStatus.FailButNext); } currRow = dtTemp.Rows.Count; prodType = dr["PROD_TYPE"].AsString(); dtTemp.Rows.Add(); dtTemp.Rows[currRow]["MGD2_YMD"] = this.ymd; dtTemp.Rows[currRow]["MGD2_PROD_TYPE"] = prodType; dtTemp.Rows[currRow]["MGD2_KIND_ID"] = kindID; dtTemp.Rows[currRow]["MGD2_STOCK_ID"] = stockID; dtTemp.Rows[currRow]["MGD2_ADJ_TYPE"] = isAdjType; dtTemp.Rows[currRow]["MGD2_ADJ_CODE"] = dr["ADJ_CODE"]; dtTemp.Rows[currRow]["MGD2_PUB_YMD"] = dr["PUB_YMD"]; dtTemp.Rows[currRow]["MGD2_ISSUE_BEGIN_YMD"] = issueBeginYmd; dtTemp.Rows[currRow]["MGD2_PROD_SUBTYPE"] = dr["PROD_SUBTYPE"].AsString(); dtTemp.Rows[currRow]["MGD2_PARAM_KEY"] = dr["PARAM_KEY"]; dtTemp.Rows[currRow]["MGD2_CUR_CM"] = 0; dtTemp.Rows[currRow]["MGD2_CUR_MM"] = 0; dtTemp.Rows[currRow]["MGD2_CUR_IM"] = 0; dtTemp.Rows[currRow]["MGD2_CUR_LEVEL"] = 0; dtTemp.Rows[currRow]["MGD2_CM"] = dr["CM_A"]; dtTemp.Rows[currRow]["MGD2_MM"] = dr["MM_A"]; dtTemp.Rows[currRow]["MGD2_IM"] = dr["IM_A"]; dtTemp.Rows[currRow]["MGD2_LEVEL"] = dr["M_LEVEL"]; dtTemp.Rows[currRow]["MGD2_CURRENCY_TYPE"] = dr["CURRENCY_TYPE"]; dtTemp.Rows[currRow]["MGD2_SEQ_NO"] = dr["SEQ_NO"]; dtTemp.Rows[currRow]["MGD2_OSW_GRP"] = dr["OSW_GRP"]; dtTemp.Rows[currRow]["MGD2_AMT_TYPE"] = dr["AMT_TYPE"]; dtTemp.Rows[currRow]["MGD2_W_TIME"] = ldtWTIME; dtTemp.Rows[currRow]["MGD2_W_USER_ID"] = GlobalInfo.USER_ID; /****************************** * AB TYTPE: -期貨 * A選擇權A值 * B選擇權B值 *******************************/ if (prodType == "F") { dtTemp.Rows[currRow]["MGD2_AB_TYPE"] = "-"; } else { dtTemp.Rows[currRow]["MGD2_AB_TYPE"] = "A"; //複製一筆一樣的,AB Type分開存 dtTemp.ImportRow(dtTemp.Rows[currRow]); //dtTemp.Rows.Add(dtTemp.Rows[ii_curr_row]);//會跳錯 currRow = dtTemp.Rows.Count - 1; dtTemp.Rows[currRow]["MGD2_AB_TYPE"] = "B"; dtTemp.Rows[currRow]["MGD2_CM"] = dr["CM_B"]; dtTemp.Rows[currRow]["MGD2_MM"] = dr["MM_B"]; dtTemp.Rows[currRow]["MGD2_IM"] = dr["IM_B"]; } } //if (ls_op_type != " ") } //foreach (DataRow dr in dtGrid.Rows) //刪除資料 foreach (DataRow drDel in dtDel.Rows) { kindID = drDel["KIND_ID"].AsString(); stockID = drDel["STOCK_ID"].ToString(); if (daoMGD2.DeleteMGD2(this.ymd, isAdjType, stockID, kindID) < 0) { MessageDisplay.Error("MGD2資料刪除失敗"); return(ResultStatus.FailButNext); } } //Update DB //ids_tmp.update() if (dtTemp.Rows.Count > 0) { ResultData myResultData = daoMGD2.UpdateMGD2(dtTemp); if (myResultData.Status == ResultStatus.Fail) { MessageDisplay.Error("更新資料庫MGD2錯誤! "); return(ResultStatus.FailButNext); } } //ids_old.update() if (dtMGD2Log.Rows.Count > 0) { ResultData myResultData = daoMGD2L.UpdateMGD2L(dtMGD2Log); if (myResultData.Status == ResultStatus.Fail) { MessageDisplay.Error("更新資料庫MGD2L錯誤! "); return(ResultStatus.FailButNext); } } //Write LOGF WriteLog("變更資料 ", "Info", "I"); //報表儲存pdf 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) { SetSaveFlagValue(); MessageDisplay.Error("儲存錯誤"); throw ex; } SetSaveFlagValue(); return(ResultStatus.Success); }
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); }
protected override ResultStatus Save(PokeBall pokeBall) { try { if (gvDetail.RowCount == 0) { MessageDisplay.Info("沒有變更資料,不需要存檔!"); return(ResultStatus.Fail); } #region ue_save_before gvMain.CloseEditor(); gvMain.UpdateCurrentRow(); gvDetail.CloseEditor(); gvDetail.UpdateCurrentRow(); string stockID, ymd, kindID, adjTypeName, opType, dbname, flag; string issueBeginYmd, issueEndYmd, implBeginYmd, implEndYmd, pubYmd, tradeYmd, mocfYmd, nextYmd; int found, count, row, col, currRow; decimal ldblRate; DateTime ldtWTIME = DateTime.Now; DataTable dtGrid = (DataTable)gcDetail.DataSource; found = dtGrid.Rows.IndexOf(dtGrid.Select("OP_TYPE <> ' '").FirstOrDefault()); if (found == -1) { MessageDisplay.Warning("沒有變更資料,不需要存檔!"); return(ResultStatus.Fail); } if (dtGrid.Rows.Count == 0) { MessageDisplay.Warning("無明細資料,請重新產生明細"); return(ResultStatus.FailButNext); } DataTable dtMGD2; //ids_mgd2 DataTable dtMGD2Log = dao40071.d_40071_log(); //ids_old dtMGD2Log.Clear(); //只取schema for (int f = 0; f < dtGrid.Rows.Count; f++) { if (dtGrid.Rows[f].RowState == DataRowState.Deleted) { continue; } DataRow dr = dtGrid.Rows[f]; opType = dr["OP_TYPE"].ToString(); flag = dr["DATA_FLAG"].AsString(); stockID = dr["STOCK_ID"].AsString(); //檢查同一標的的級距是否一致 if ((f + 1) < dtGrid.Rows.Count) { if (stockID == dtGrid.Rows[f + 1]["STOCK_ID"].AsString() && dr["M_CUR_LEVEL"].AsString() != dtGrid.Rows[f + 1]["M_CUR_LEVEL"].AsString()) { MessageDisplay.Error(stockID + "的級距不一致"); return(ResultStatus.FailButNext); } } //檢查有異動的資料 if (opType != " ") { kindID = dr["KIND_ID"].AsString(); ymd = dr["YMD"].ToString(); issueBeginYmd = dr["ISSUE_BEGIN_YMD"].ToString(); //issueEndYmd = dr["ISSUE_END_YMD"].ToString(); by tom //implBeginYmd = dr["IMPL_BEGIN_YMD"].ToString(); //implEndYmd = dr["IMPL_END_YMD"].ToString(); //pubYmd = dr["PUB_YMD"].ToString(); issueEndYmd = dr["ISSUE_END_YMD"].AsString().Replace("/", ""); implBeginYmd = dr["IMPL_BEGIN_YMD"].AsString().Replace("/", ""); implEndYmd = dr["IMPL_END_YMD"].AsString().Replace("/", ""); pubYmd = dr["PUB_YMD"].AsString().Replace("/", ""); if (ymd != implBeginYmd) { DialogResult result = MessageDisplay.Choose(stockID + "," + kindID + "交易日不等於處置起日,請問是否更新"); if (result == DialogResult.No) { return(ResultStatus.FailButNext); } } if (issueEndYmd != implEndYmd) { DialogResult result = MessageDisplay.Choose(stockID + "," + kindID + "生效迄日不等於處置迄日,請問是否更新"); if (result == DialogResult.No) { return(ResultStatus.FailButNext); } } //處置期間首日+1個月 mocfYmd = PbFunc.relativedate(implBeginYmd.AsDateTime("yyyyMMdd"), 30).ToString("yyyyMMdd"); /*次一營業日*/ nextYmd = daoMOCF.GetNextTradeDay(implBeginYmd, mocfYmd); if (issueBeginYmd != nextYmd) { DialogResult result = MessageDisplay.Choose(stockID + "," + kindID + "生效起日不等於處置起日之次一營業日,請問是否更新"); if (result == DialogResult.No) { return(ResultStatus.FailButNext); } } dtMGD2 = dao40072.d_40072(ymd, isAdjType, stockID); //資料修改,將修改前舊資料寫入log if (opType == "U") { dtMGD2.Filter("mgd2_kind_id = '" + kindID + "'"); foreach (DataRow drU in dtMGD2.Rows) { currRow = dtMGD2Log.Rows.Count; dtMGD2Log.Rows.Add(); for (col = 0; col < dtMGD2.Columns.Count; col++) { //先取欄位名稱,因為兩張table欄位順序不一致 dbname = dtMGD2.Columns[col].ColumnName; if (dbname == "CPSORT") { continue; //這個欄位是拿來排序用的,故無需複製 } dtMGD2Log.Rows[currRow][dbname] = drU[col]; } if (flag == "Y") { dtMGD2Log.Rows[currRow]["MGD2_L_TYPE"] = "U"; } if (flag == "N") { dtMGD2Log.Rows[currRow]["MGD2_L_TYPE"] = "D"; } dtMGD2Log.Rows[currRow]["MGD2_L_USER_ID"] = GlobalInfo.USER_ID; dtMGD2Log.Rows[currRow]["MGD2_L_TIME"] = ldtWTIME; } } /****************************************** * 確認商品是否在同一交易日不同情境下設定過 ******************************************/ DataTable dtSet = dao40071.IsSetOnSameDay(kindID, ymd, isAdjType); if (dtSet.Rows.Count == 0) { MessageDisplay.Info("MGD2 " + kindID + " 無任何資料!"); return(ResultStatus.FailButNext); } count = dtSet.Rows[0]["LI_COUNT"].AsInt(); adjTypeName = dtSet.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一般交易時段結束後始>>應不重疊 *************************************/ dtSet = dao40071.IsSetInSameSession(kindID, ymd, issueBeginYmd, issueEndYmd); count = dtSet.Rows[0]["LI_COUNT"].AsInt(); adjTypeName = dtSet.Rows[0]["LS_ADJ_TYPE_NAME"].AsString(); tradeYmd = dtSet.Rows[0]["LS_TRADE_YMD"].AsString(); if (count > 0) { MessageDisplay.Error(kindID + "," + adjTypeName + ",交易日(" + tradeYmd + ")在同一生效日區間內已有資料"); return(ResultStatus.FailButNext); } //判斷調整幅度是否為0 //ldblRate = dr["ADJ_RATE"].AsDecimal(); by tom ldblRate = dr["ADJ_RATE"].AsDecimal() - 1; if (ldblRate == 0) { MessageDisplay.Error("商品調整幅度不可為0"); return(ResultStatus.FailButNext); } } //if (ls_op_type != " ") } //for (int f = 0; f < dtGrid.Rows.Count; f++) #endregion string prodType; DataTable dtTemp = dao40072.d_40072(); //ids_tmp foreach (DataRow dr in dtGrid.Rows) { if (dr.RowState == DataRowState.Deleted) { continue; } opType = dr["OP_TYPE"].ToString(); //只更新有異動的資料 if (opType != " ") { kindID = dr["KIND_ID"].AsString(); stockID = dr["STOCK_ID"].AsString(); issueBeginYmd = dr["ISSUE_BEGIN_YMD"].ToString(); //issueEndYmd = dr["ISSUE_END_YMD"].ToString(); by tom //implBeginYmd = dr["IMPL_BEGIN_YMD"].ToString(); //implEndYmd = dr["IMPL_END_YMD"].ToString(); //pubYmd = dr["PUB_YMD"].ToString(); issueEndYmd = dr["ISSUE_END_YMD"].AsString().Replace("/", ""); implBeginYmd = dr["IMPL_BEGIN_YMD"].AsString().Replace("/", ""); implEndYmd = dr["IMPL_END_YMD"].AsString().Replace("/", ""); pubYmd = dr["PUB_YMD"].AsString().Replace("/", ""); ymd = dr["YMD"].ToString(); //ldblRate = dr["ADJ_RATE"].AsDecimal(); ldblRate = dr["ADJ_RATE"].AsDecimal() - 1; //刪除已存在資料 if (daoMGD2.DeleteMGD2(ymd, isAdjType, stockID, kindID) < 0) { MessageDisplay.Error("MGD2資料刪除失敗"); return(ResultStatus.FailButNext); } if (dr["DATA_FLAG"].AsString() == "Y") { currRow = dtTemp.Rows.Count; prodType = dr["PROD_TYPE"].AsString(); dtTemp.Rows.Add(); dtTemp.Rows[currRow]["MGD2_YMD"] = ymd; dtTemp.Rows[currRow]["MGD2_PROD_TYPE"] = prodType; dtTemp.Rows[currRow]["MGD2_KIND_ID"] = kindID; dtTemp.Rows[currRow]["MGD2_STOCK_ID"] = stockID; dtTemp.Rows[currRow]["MGD2_ADJ_TYPE"] = isAdjType; dtTemp.Rows[currRow]["MGD2_ADJ_RATE"] = ldblRate; dtTemp.Rows[currRow]["MGD2_ADJ_CODE"] = "Y"; dtTemp.Rows[currRow]["MGD2_ISSUE_BEGIN_YMD"] = issueBeginYmd; dtTemp.Rows[currRow]["MGD2_ISSUE_END_YMD"] = issueEndYmd; dtTemp.Rows[currRow]["MGD2_IMPL_BEGIN_YMD"] = implBeginYmd; dtTemp.Rows[currRow]["MGD2_IMPL_END_YMD"] = implEndYmd; dtTemp.Rows[currRow]["MGD2_PUB_YMD"] = pubYmd; dtTemp.Rows[currRow]["MGD2_PROD_SUBTYPE"] = dr["PROD_SUBTYPE"]; dtTemp.Rows[currRow]["MGD2_PARAM_KEY"] = dr["PARAM_KEY"]; dtTemp.Rows[currRow]["MGD2_CUR_CM"] = dr["CM_CUR_A"]; dtTemp.Rows[currRow]["MGD2_CUR_MM"] = dr["MM_CUR_A"]; dtTemp.Rows[currRow]["MGD2_CUR_IM"] = dr["IM_CUR_A"]; dtTemp.Rows[currRow]["MGD2_CUR_LEVEL"] = dr["M_CUR_LEVEL"]; dtTemp.Rows[currRow]["MGD2_CM"] = dr["CM_A"]; dtTemp.Rows[currRow]["MGD2_MM"] = dr["MM_A"]; dtTemp.Rows[currRow]["MGD2_IM"] = dr["IM_A"]; dtTemp.Rows[currRow]["MGD2_CURRENCY_TYPE"] = dr["CURRENCY_TYPE"]; dtTemp.Rows[currRow]["MGD2_SEQ_NO"] = dr["SEQ_NO"]; dtTemp.Rows[currRow]["MGD2_OSW_GRP"] = dr["OSW_GRP"]; dtTemp.Rows[currRow]["MGD2_AMT_TYPE"] = dr["AMT_TYPE"]; dtTemp.Rows[currRow]["MGD2_W_TIME"] = ldtWTIME; dtTemp.Rows[currRow]["MGD2_W_USER_ID"] = GlobalInfo.USER_ID; /****************************** * AB TYTPE: -期貨 * A選擇權A值 * B選擇權B值 *******************************/ if (prodType == "F") { dtTemp.Rows[currRow]["MGD2_AB_TYPE"] = "-"; } else { dtTemp.Rows[currRow]["MGD2_AB_TYPE"] = "A"; //複製一筆一樣的,AB Type分開存 dtTemp.ImportRow(dtTemp.Rows[currRow]); //dtTemp.Rows.Add(dtTemp.Rows[ii_curr_row]);//會跳錯 currRow = dtTemp.Rows.Count - 1; dtTemp.Rows[currRow]["MGD2_AB_TYPE"] = "B"; dtTemp.Rows[currRow]["MGD2_CUR_CM"] = dr["CM_CUR_B"]; dtTemp.Rows[currRow]["MGD2_CUR_MM"] = dr["MM_CUR_B"]; dtTemp.Rows[currRow]["MGD2_CUR_IM"] = dr["IM_CUR_B"]; dtTemp.Rows[currRow]["MGD2_CM"] = dr["CM_B"]; dtTemp.Rows[currRow]["MGD2_MM"] = dr["MM_B"]; dtTemp.Rows[currRow]["MGD2_IM"] = dr["IM_B"]; } } //if (dr["DATA_FLAG"].AsString()=="Y") } //if (ls_op_type != " ") } //foreach (DataRow dr in dtGrid.Rows) //Update DB //ids_tmp.update() if (dtTemp.Rows.Count > 0) { ResultData myResultData = daoMGD2.UpdateMGD2(dtTemp); if (myResultData.Status == ResultStatus.Fail) { MessageDisplay.Error("更新資料庫MGD2錯誤! "); return(ResultStatus.FailButNext); } } //ids_old.update() if (dtMGD2Log.Rows.Count > 0) { ResultData myResultData = daoMGD2L.UpdateMGD2L(dtMGD2Log); if (myResultData.Status == ResultStatus.Fail) { MessageDisplay.Error("更新資料庫MGD2L錯誤! "); return(ResultStatus.FailButNext); } } //Write LOGF WriteLog("變更資料 ", "Info", "I"); //報表儲存pdf ReportHelper _ReportHelper = new ReportHelper(gcDetail, _ProgramID, this.Text); CommonReportLandscapeA3 reportLandscape = new CommonReportLandscapeA3();//設定為橫向列印 reportLandscape.printableComponentContainerMain.PrintableComponent = gcDetail; reportLandscape.IsHandlePersonVisible = false; reportLandscape.IsManagerVisible = false; _ReportHelper.Create(reportLandscape); _ReportHelper.Export(FileType.PDF, _ReportHelper.FilePath); MessageDisplay.Info("報表儲存完成!"); } catch (Exception ex) { MessageDisplay.Error("儲存錯誤"); throw ex; } return(ResultStatus.Success); }