protected override ResultStatus Save(PokeBall poke) { gvMain.CloseEditor(); gvMain.UpdateCurrentRow(); DataTable dt = (DataTable)gcMain.DataSource; DataTable dtChange = dt.GetChanges(); DataTable dtDeleteChange = dt.GetChanges(DataRowState.Deleted); int getDeleteCount = dtDeleteChange != null ? dtDeleteChange.Rows.Count : 0; //存檔前檢查 if (getDeleteCount == 0 && dtChange != null)//無法經由資料列存取已刪除的資料列資訊。 { //更新變動日期與使用者ID foreach (DataRow dr in dt.Rows) { if (dr.RowState == DataRowState.Modified) { dr["PLS4_W_USER_ID"] = GlobalInfo.USER_ID; dr["PLS4_W_TIME"] = DateTime.Now; dr["PLS4_PDK_YMD"] = _IsPdkYMD; } } } if (dtChange != null) { try { // 寫入DB ResultData myResultData = dao20231.UpdatePLS4(dt); //產出txt檔案 Common.Helper.ExportHelper.ToText(dt, Path.Combine(GlobalInfo.DEFAULT_REPORT_DIRECTORY_PATH, "20231.txt")); } catch (Exception ex) { WriteLog(ex); } return(ResultStatus.Success); } else { MessageBox.Show("沒有變更資料,不需要存檔!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(ResultStatus.Success); }
protected override ResultStatus Save(PokeBall poke) { gvMain.CloseEditor(); gvMain.UpdateCurrentRow(); DataTable dt = (DataTable)gcMain.DataSource; DataTable dtChange = dt.GetChanges(); DataTable dtAdd = dt.GetChanges(DataRowState.Added); DataTable dtDeleteChange = 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); } if (dtChange != null) { //更新變動日期與使用者ID foreach (DataRow dr in dt.Rows) { if (dr.RowState == DataRowState.Modified) { dr["PLS4_W_USER_ID"] = GlobalInfo.USER_ID; dr["PLS4_W_TIME"] = DateTime.Now; dr["PLS4_PDK_YMD"] = _IsPdkYMD; } if (dr.RowState == DataRowState.Added) { dr["PLS4_W_USER_ID"] = GlobalInfo.USER_ID; dr["PLS4_W_TIME"] = DateTime.Now; dr["PLS4_PDK_YMD"] = _IsPdkYMD; if (string.IsNullOrEmpty(dr["PLS4_SID"].AsString()) || string.IsNullOrEmpty(dr["PLS4_KIND_ID2"].AsString()) || string.IsNullOrEmpty(dr["PLS4_PID"].AsString())) { MessageDisplay.Info("資料尚未填寫完成!"); return(ResultStatus.FailButNext); } } if (dr.RowState == DataRowState.Deleted) { continue; } } try { // 寫入DB ResultData myResultData = dao20231.UpdatePLS4(dt); //產出txt檔案 Common.Helper.ExportHelper.ToText(dt, Path.Combine(GlobalInfo.DEFAULT_REPORT_DIRECTORY_PATH, "20231.txt")); } catch (Exception ex) { WriteLog(ex); return(ResultStatus.Fail); } } return(ResultStatus.Success); }