protected override ResultStatus Retrieve() { try { #region 輸入&日期檢核 if (string.Compare(txtStartDate.Text, txtEndDate.Text) > 0) { MessageDisplay.Error(CheckDate.Datedif, GlobalInfo.ErrorText); return(ResultStatus.Fail); } #endregion DataTable dt = new MG8().ListData(StartDate, EndDate); if (dt.Rows.Count <= 0) { MessageDisplay.Info(MessageDisplay.MSG_NO_DATA, GlobalInfo.ResultText); } else { retDt = dt.Clone(); foreach (DataRow r in dt.Rows) { retDt.ImportRow(r); } //設定grid裡的 date format RepositoryItemTextEdit effectYmd = new RepositoryItemTextEdit(); effectYmd.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.RegEx; effectYmd.Mask.EditMask = "[0-9]{4}/(((0[13578]|(10|12))/(0[1-9]|[1-2][0-9]|3[0-1]))|(02/(0[1-9]|[1-2][0-9]))|((0[469]|11)/(0[1-9]|[1-2][0-9]|30)))"; effectYmd.Mask.UseMaskAsDisplayFormat = true; gcMain.RepositoryItems.Add(effectYmd); gvMain.Columns["MG8_EFFECT_YMD"].ColumnEdit = effectYmd; RepositoryItemTextEdit issueYmd = new RepositoryItemTextEdit(); issueYmd.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.RegEx; issueYmd.Mask.EditMask = "[0-9]{4}/(((0[13578]|(10|12))/(0[1-9]|[1-2][0-9]|3[0-1]))|(02/(0[1-9]|[1-2][0-9]))|((0[469]|11)/(0[1-9]|[1-2][0-9]|30)))"; issueYmd.Mask.UseMaskAsDisplayFormat = true; gcMain.RepositoryItems.Add(issueYmd); gvMain.Columns["MG8_ISSUE_YMD"].ColumnEdit = issueYmd; } //設定gvMain gcMain.Visible = true; //gvMain.Columns.Clear(); gcMain.DataSource = dt; //gvMain.BestFitColumns(); GridHelper.SetCommonGrid(gvMain); gcMain.Focus(); return(ResultStatus.Success); } catch (Exception ex) { WriteLog(ex); } return(ResultStatus.Fail); }
protected override ResultStatus Save(PokeBall pokeBall) { try { if (gcMain.DataSource == null) { MessageDisplay.Info(MessageDisplay.MSG_NO_DATA, GlobalInfo.ResultText); return(ResultStatus.FailButNext); } DataTable dt = (DataTable)gcMain.DataSource; //mg8 gvMain.CloseEditor(); gvMain.UpdateCurrentRow(); DataTable dtChange = dt.GetChanges(); DataTable dtForAdd = dt.GetChanges(DataRowState.Added); DataTable dtForModified = dt.GetChanges(DataRowState.Modified); DataTable dtForDeleted = dt.GetChanges(DataRowState.Deleted); if (dtChange == null) { MessageDisplay.Warning("沒有變更資料,不需要存檔!", GlobalInfo.WarningText); return(ResultStatus.Fail); } if (dtChange.Rows.Count == 0) { MessageDisplay.Warning("沒有變更資料,不需要存檔!", GlobalInfo.WarningText); return(ResultStatus.Fail); } #region save foreach (DataRow dr in dt.Rows) { switch (dr.RowState) { case DataRowState.Added: case DataRowState.Modified: dr["MG8_W_TIME"] = DateTime.Now; dr["MG8_W_USER_ID"] = GlobalInfo.USER_ID; dr["MG8_EFFECT_YMD"] = dr["MG8_EFFECT_YMD"].AsString().Replace("/", ""); dr["MG8_ISSUE_YMD"] = dr["MG8_ISSUE_YMD"].AsString().Replace("/", ""); break; case DataRowState.Unchanged: if (dr["MG8_W_TIME"] == null) { dr["MG8_W_TIME"] = " "; } if (dr["MG8_W_USER_ID"] == null) { dr["MG8_W_USER_ID"] = " "; } break; } } dtChange = dt.GetChanges(); ResultData res = new MG8().UpdateData(dtChange); if (res.Status == ResultStatus.Fail) { MessageDisplay.Error("儲存失敗", GlobalInfo.ErrorText); return(ResultStatus.Fail); } else { //save成功才寫異動LOG: 紀錄異動前後的值 foreach (DataRow dr in dt.Rows) { if (dr.RowState == DataRowState.Modified) { string effectYmd = dr["MG8_EFFECT_YMD"].AsString().Replace("/", ""); string fId = dr["MG8_F_ID"].AsString(); DataView dv = retDt.AsDataView(); dv.Sort = "MG8_EFFECT_YMD,MG8_F_ID"; object[] filter = new object[2]; filter[0] = effectYmd; filter[1] = fId; int found = dv.Find(filter); if (found < 0) { continue; } for (int w = 2; w <= 5; w++) { if (dr[w].AsString() != retDt.Rows[found][w].AsString()) //沒有轉string比對會變成true(?) { string befChange = dr[w].AsString(); string aftChange = retDt.Rows[found][w].AsString(); WriteLog(string.Format("變更後:{0},原始:{1}", aftChange, befChange), "Info", "U"); } } } }//foreach (DataRow dr in dt.Rows) { } #endregion //呼叫SP foreach (DataRow dr in dt.Rows) { int pos = 0; if (dr.RowState != DataRowState.Added) { continue; } string effectYmd = dr["MG8_EFFECT_YMD"].AsString(); string fId = dr["MG8_F_ID"].AsString(); #region 寫txt檔(for insert) DataTable dtTxt = dao49060.GetTxtDataById(effectYmd, fId); DataRow drTxt = dtTxt.Rows[pos]; string fExchange = drTxt["MGT8_F_EXCHANGE"].AsString(); string issueYmd = dr["MG8_ISSUE_YMD"].AsDateTime("yyyyMMdd").ToString("yyyy/MM/dd"); decimal mg8Im_1 = drTxt["MG8_IM"].AsDecimal(); //decimal mg8Im_2 = dtTxt.Rows[pos + 1]["mg8_im"].AsDecimal(); string fName = drTxt["MGT8_F_NAME"].AsString(); string currencyName = drTxt["COD_CURRENCY_NAME"].AsString(); string amtType = drTxt["MGT8_AMT_TYPE"].AsString(); decimal imRate = drTxt["IM_RATE"].AsDecimal(); string txt = string.Format("{0}於{1}公告", fExchange, issueYmd); string flag = ""; if (dtTxt.Rows.Count == 2) { if (mg8Im_1 < dtTxt.Rows[1]["MG8_IM"].AsDecimal()) { flag = "調降"; } else { flag = "調升"; } } txt += string.Format("{0}{1}保證金,原始保證金", flag, fName); if (!string.IsNullOrEmpty(flag)) { txt += string.Format("由{0}", currencyName); if (amtType == "A") { txt += string.Format("{0:N0}{1}至{2:N0}", dtTxt.Rows[1]["MG8_IM"].AsDecimal(), flag, mg8Im_1); } else { txt += string.Format("{0:0.00%}{1}至{2:0.00%}", dtTxt.Rows[1]["MG8_IM"].AsDecimal(), flag, mg8Im_1); } txt += string.Format(",調幅{0:0.00%},", imRate); } else { txt += currencyName; if (amtType == "A") { txt += string.Format("{0:N0}", mg8Im_1); } else { txt += string.Format("{0:0.00%}", mg8Im_1); } txt += ","; } txt += string.Format("自{0}起生效。{1}", effectYmd, Environment.NewLine); string fileName = _ProgramID + "_" + DateTime.Now.ToString("yyyy.MM.dd-HH.mm.ss") + ".txt"; string filePath = Path.Combine(GlobalInfo.DEFAULT_REPORT_DIRECTORY_PATH, fileName); bool IsSuccess = ToText(txt, filePath, System.Text.Encoding.GetEncoding(950)); if (!IsSuccess) { MessageDisplay.Error("文字檔「" + filePath + "」Open檔案錯誤!", GlobalInfo.ErrorText); return(ResultStatus.Fail); } #endregion //轉ci.MG8D (執行ci.sp_H_stt_MG8D) string resInsert = dao49060.ExecuteStoredProcedure(effectYmd, fId, "I"); if (resInsert != "0") { MessageDisplay.Error("執行SP(ci.sp_H_stt_MG8D)錯誤!", GlobalInfo.ErrorText); WriteLog("執行SP(ci.sp_H_stt_MG8D)-(I)錯誤!", "Error", "Z", false); } WriteLog("執行ci.sp_H_stt_MG8D(I)", "Info", "X", false); }//foreach (DataRow dr in dt.Rows) //刪除資料 if (dtForDeleted != null) { foreach (DataRow dr in dtForDeleted.Rows) { //轉ci.MG8D string effectYmd = dr["MG8_EFFECT_YMD", DataRowVersion.Original].AsString(); string fId = dr["MG8_F_ID", DataRowVersion.Original].AsString(); string resDelete = dao49060.ExecuteStoredProcedure(effectYmd, fId, "D"); if (resDelete != "0") { MessageDisplay.Error("執行SP(ci.sp_H_stt_MG8D)錯誤!", GlobalInfo.ErrorText); WriteLog("執行SP(ci.sp_H_stt_MG8D)-(D)錯誤!", "Error", "Z", false); } WriteLog("執行ci.sp_H_stt_MG8D(D)", "Info", "X", false); } }//if (dtForDeleted != null) AfterSaveForPrint(gcMain, dtForAdd, dtForDeleted, dtForModified); } catch (Exception ex) { WriteLog(ex); } _IsPreventFlowPrint = true; //不要自動列印 return(ResultStatus.Success); }