public void Update(IDatabase DataDB, List <DbParameter> param, ref string fullqry, ref string _extqry, ref int i) { ParameterizeCtrl_Params args = new ParameterizeCtrl_Params(DataDB, param, i, _extqry); foreach (EbWebForm WebForm in this) { args.SetFormRelated(WebForm.TableName, WebForm.UserObj, WebForm); WebForm.DoRequiredCheck(WebForm == MasterForm); foreach (TableSchema _table in WebForm.FormSchema.Tables.FindAll(e => e.TableType != WebFormTableTypes.Review && !e.DoNotPersist)) { if (!WebForm.FormData.MultipleTables.ContainsKey(_table.TableName)) { continue; } foreach (SingleRow row in WebForm.FormData.MultipleTables[_table.TableName]) { args.ResetColVals(); if (row.RowId > 0) { SingleRow bkup_Row = WebForm.FormDataBackup.MultipleTables[_table.TableName].Find(e => e.RowId == row.RowId); if (bkup_Row == null) { Console.WriteLine($"Row edit request ignored(Row not in backup table). \nTable name: {_table.TableName}, RowId: {row.RowId}, RefId: {WebForm.RefId}"); continue; } string t = string.Empty; if (!row.IsDelete) { foreach (SingleColumn cField in row.Columns) { if (cField.Control != null) { SingleColumn ocF = bkup_Row.Columns.Find(e => e.Name.Equals(cField.Name)); args.UpdateSet(cField, ocF); cField.Control.ParameterizeControl(args, WebForm.CrudContext); } else { args.UpdateSet(cField); WebForm.ParameterizeUnknown(args); } } } else if (WebForm.DataPusherConfig == null && !_table.TableName.Equals(WebForm.TableName)) { List <TableSchema> _tables = WebForm.FormSchema.Tables.FindAll(e => e.IsDynamic && e.TableType == WebFormTableTypes.Grid); foreach (TableSchema _tbl in _tables) { t += $@"UPDATE {_tbl.TableName} SET eb_del = 'T', eb_lastmodified_by = @eb_modified_by, eb_lastmodified_at = {DataDB.EB_CURRENT_TIMESTAMP} WHERE {_table.TableName}_id = @{_table.TableName}_id_{args.i} AND {WebForm.TableName}_id = @{WebForm.TableName}_id AND COALESCE(eb_del, 'F') = 'F'; "; param.Add(DataDB.GetNewParameter(_table.TableName + "_id_" + args.i, EbDbTypes.Int32, row.RowId)); args.i++; } } string _qry = QueryGetter.GetUpdateQuery(WebForm, DataDB, _table.TableName, row.IsDelete); fullqry += string.Format(_qry, args._colvals, row.RowId); fullqry += t; } else { args.ResetColsAndVals(); foreach (SingleColumn cField in row.Columns) { args.InsertSet(cField); if (cField.Control != null) { cField.Control.ParameterizeControl(args, WebForm.CrudContext); } else { WebForm.ParameterizeUnknown(args); } } string _qry = QueryGetter.GetInsertQuery(WebForm, DataDB, _table.TableName, WebForm.TableRowId == 0); fullqry += string.Format(_qry, args._cols, args._vals); } fullqry += WebForm.InsertUpdateLines(_table.TableName, row, args); } } string IdParamName = WebForm.TableName + FormConstants._id + (WebForm.DataPusherConfig != null ? WebForm.CrudContext : string.Empty); param.Add(DataDB.GetNewParameter(IdParamName, EbDbTypes.Int32, WebForm.TableRowId)); if (!param.Exists(e => e.ParameterName == WebForm.TableName + FormConstants._eb_ver_id)) { param.Add(DataDB.GetNewParameter(WebForm.TableName + FormConstants._eb_ver_id, EbDbTypes.Int32, WebForm.RefId.Split(CharConstants.DASH)[4])); param.Add(DataDB.GetNewParameter(WebForm.TableName + FormConstants._refid, EbDbTypes.String, WebForm.RefId)); } } args.CopyBack(ref _extqry, ref i); }
public void Insert(IDatabase DataDB, List <DbParameter> param, ref string fullqry, ref string _extqry, ref int i, bool pushAuditTrail) { ParameterizeCtrl_Params args = new ParameterizeCtrl_Params(DataDB, param, i, _extqry); foreach (EbWebForm WebForm in this) { args.SetFormRelated(WebForm.TableName, WebForm.UserObj, WebForm); if (WebForm.DataPusherConfig?.AllowPush == false) { continue; } WebForm.DoRequiredCheck(WebForm == MasterForm); if (!(WebForm.FormData.MultipleTables.ContainsKey(WebForm.FormSchema.MasterTable) && WebForm.FormData.MultipleTables[WebForm.FormSchema.MasterTable].Count > 0)) { string _q = QueryGetter.GetInsertQuery(WebForm, DataDB, WebForm.FormSchema.MasterTable, true); fullqry += string.Format(_q, string.Empty, string.Empty); } foreach (TableSchema _table in WebForm.FormSchema.Tables.FindAll(e => e.TableType != WebFormTableTypes.Review && !e.DoNotPersist)) { if (!WebForm.FormData.MultipleTables.ContainsKey(_table.TableName)) { continue; } foreach (SingleRow row in WebForm.FormData.MultipleTables[_table.TableName]) { args.ResetColsAndVals(); foreach (SingleColumn cField in row.Columns) { args.InsertSet(cField); if (cField.Control != null) { cField.Control.ParameterizeControl(args, WebForm.CrudContext); } else { WebForm.ParameterizeUnknown(args); } } string _qry = QueryGetter.GetInsertQuery(WebForm, DataDB, _table.TableName, true); fullqry += string.Format(_qry, args._cols, args._vals); fullqry += WebForm.InsertUpdateLines(_table.TableName, row, args); } } if (!param.Exists(e => e.ParameterName == WebForm.TableName + FormConstants._eb_ver_id)) { param.Add(DataDB.GetNewParameter(WebForm.TableName + FormConstants._eb_ver_id, EbDbTypes.Int32, WebForm.RefId.Split(CharConstants.DASH)[4])); param.Add(DataDB.GetNewParameter(WebForm.TableName + FormConstants._refid, EbDbTypes.String, WebForm.RefId)); } if (pushAuditTrail) { fullqry += EbAuditTrail.GetInsertModeQuery(DataDB, WebForm.RefId, WebForm.TableName); } } args.CopyBack(ref _extqry, ref i); }