/// <summary>バッチ更新ボタン</summary> /// <param name="fxEventArgs">イベントハンドラの共通引数</param> /// <returns>URL</returns> protected string UOC_btnBatUpd_Click(FxEventArgs fxEventArgs) { #region Create the instance of classes here // 引数クラスを生成 _3TierParameterValue parameterValue = new _3TierParameterValue( this.ContentPageFileNoEx, fxEventArgs.ButtonID, "BatchUpdate", (string)Session["DAP"], (MyUserInfo)this.UserInfo); //Initialize the data access procedure _3TierReturnValue returnValue = null; // B layer Initialize _3TierEngine b = new _3TierEngine(); //Keep the copy of the table in session because change in the column name causes the problem in the temperory update after batch update. So keep the copy of the table. DataTable dtSession = ((DataTable)Session["SearchResult"]).Copy(); #endregion // ControlComment:LoopStart-JoinTables #region Batch Update for _TableName_ table #region This is much needed to handle the duplicate column issue while udpating _TableName_ using batch update // to change the column names of table as per Table we should have copy of dtSession table. DataTable dt_TableName_ = dtSession.Copy(); foreach (DataColumn dc in dt_TableName_.Columns) { //Remove the '_TableName_.' from column names of _TableName_ only so that update will not have any problem. //Otherwise When two tables are having same column names then we get an error "A column named 'Columname' already belongs to this DataTable." if (dc.ColumnName.Split('.')[0].Trim() == "_TableName_") { dc.ColumnName = dc.ColumnName.Split('.')[1].Trim(); } //Replace "." in column names of other tables with "_". This is needed becuase if columns are having "." then we get sql error, so we need to replace "." with "_" else { dc.ColumnName = dc.ColumnName.Replace('.', '_'); } } #endregion // DataTableを設定 parameterValue.Obj = dt_TableName_; //Reset returnvalue with null; returnValue = null; parameterValue.AndEqualSearchConditions = new Dictionary <string, object>(); //Primary Key Columns // ControlComment:LoopStart-PKColumn parameterValue.AndEqualSearchConditions.Add("_ColumnName_", ""); // ControlComment:LoopEnd-PKColumn //Timestamp column TS_CommentOut_ parameterValue.AndEqualSearchConditions.Add("_TimeStampColName_", ""); // Table Name parameterValue.TableName = "_TableName_"; // Run the Database access process returnValue = (_3TierReturnValue)b.DoBusinessLogic( (BaseParameterValue)parameterValue, DbEnum.IsolationLevelEnum.ReadCommitted); #endregion // ControlComment:LoopEnd-JoinTables // Disable the button this.btnBatUpd.Enabled = false; // Keep the original session table with actual column names. Session["SearchResult"] = dtSession; //No Screen transition return(string.Empty); }
/// <summary>バッチ更新ボタン</summary> /// <param name="fxEventArgs">イベントハンドラの共通引数</param> /// <returns>URL</returns> /// <remarks>In case of deleting from multiple tables and when the tables have dependent relation, the sequence of execution of delete statements for these tables become necessary. /// Developer should decide the sequence of table for the delete operation. /// This can be managed by altering the position of code block present in the region 'Batch Update for [TableName] table' as required</remarks> protected string UOC_btnBatUpd_Click(FxEventArgs fxEventArgs) { #region Create the instance of classes here // 引数クラスを生成 _3TierParameterValue parameterValue = new _3TierParameterValue( this.ContentPageFileNoEx, fxEventArgs.ButtonID, "BatchUpdateDM", (string)Session["DAP"], (MyUserInfo)this.UserInfo); //Initialize the data access procedure _3TierReturnValue returnValue = null; // B layer Initialize _3TierEngine b = new _3TierEngine(); parameterValue.AndEqualSearchConditions = new Dictionary <string, object>(); parameterValue.TargetTableNames = new Dictionary <int, string>(); //Declaring the table counter to add it to TargetTableNames Dictionary int TableCounter = 0; //Keep the copy of the table in session because change in the column name causes the problem in the temperory update after batch update. So keep the copy of the table. DataTable dtSession = ((DataTable)Session["SearchResult"]).Copy(); #endregion // ControlComment:LoopStart-JoinTables #region Batch Update for _TableName_ table #region This is much needed to handle the duplicate column issue while udpating _TableName_ using batch update TableCounter = TableCounter + 1; foreach (DataColumn dc in dtSession.Columns) { //Replace "." in column names of other tables with "_". This is needed becuase if columns are having "." then we get sql error, so we need to replace "." with "_" dc.ColumnName = dc.ColumnName.Replace('.', '_'); } #endregion //Reset returnvalue with null; returnValue = null; //Primary Key Columns // ControlComment:LoopStart-PKColumn if (!parameterValue.AndEqualSearchConditions.ContainsKey("_JoinTextboxColumnName_")) { parameterValue.AndEqualSearchConditions.Add("_JoinTextboxColumnName_", ""); } // ControlComment:LoopEnd-PKColumn //Timestamp column TS_CommentOut_ parameterValue.AndEqualSearchConditions.Add("_TimeStampColName_", ""); // Table Name parameterValue.TargetTableNames.Add(TableCounter, "_TableName_"); #endregion // ControlComment:LoopEnd-JoinTables // DataTableを設定 parameterValue.Obj = dtSession; // Run the Database access process returnValue = (_3TierReturnValue)b.DoBusinessLogic( (BaseParameterValue)parameterValue, DbEnum.IsolationLevelEnum.ReadCommitted); // Disable the button this.btnBatUpd.Enabled = false; //No Screen transition return(string.Empty); }