/// <summary> /// Insert, Update, or Delete data via stored procedure /// </summary> /// <param name="parameters">Parameters to send to database</param> /// <param name="procedureName">Stored procedure to call</param> /// <returns>Result object send from database</returns> public ReturnObj ModifyData(SqlDataAccessParameter[] parameters, string procedureName) { DtoDataSet infoDataSet = new DtoDataSet(); SqlDataAccessContainer dac = new SqlDataAccessContainer(); foreach (SqlDataAccessParameter parameter in parameters) { dac.Add(parameter); } string error = string.Empty; ReturnObj objReturn = new ReturnObj(); try { long returnValue; returnValue = SqlDataConnect.UpdateData(procedureName, ref error, dac); if (returnValue <= 0) { objReturn.Error = error; } objReturn.Result = returnValue; } catch (Exception ex) { //log this error objReturn.Result = 0; objReturn.Error = ex.Message; Logger.Log.Error(ex); } return(objReturn); }
/// <summary> /// Gets a dataset back from a stored procedure that modifies data and sends any NULL parameters to database /// </summary> /// <param name="parameters">Parameters to send to database</param> /// <param name="procedureName">Stored procedure to call</param> /// <param name="encryptedToken">Encrypted token value coming from client</param> /// <param name="unencryptedToken">Unencrypted token value from web.config</param> /// <returns></returns> public DtoDataSet ModifyDataReturnTableKeepNullParameters(SqlDataAccessParameter[] parameters, string procedureName, string encryptedToken, string unencryptedToken) { DtoDataSet infoDataSet = new DtoDataSet(); SqlDataAccessContainer dac = new SqlDataAccessContainer(); if (TokenGenerator.CompareTokens(encryptedToken, unencryptedToken)) { if (parameters != null) { foreach (SqlDataAccessParameter parameter in parameters) { if (parameter != null && parameter.Value != null && parameter.Value.Length > 0) { dac.Add(parameter); } else if (parameter != null && parameter.ObjectValue != null) { dac.Add(parameter); } else { dac.Add(new SqlDataAccessParameter(parameter.Name, parameter.DataType, DBNull.Value)); } } } infoDataSet.Ds = null; infoDataSet.Error = ""; DataSet localDs = null; try { if (SqlDataConnect.GetData(ref localDs, procedureName, ref _Error, dac) == false) { infoDataSet.Error = _Error; infoDataSet.Ds = null; } infoDataSet.Ds = localDs; } catch (Exception ex) { infoDataSet.Error = ex.Message; Logger.LogError(procedureName, parameters, ex); } } else { infoDataSet.Error = "Security token validation failed. Access to service is denied."; } return(infoDataSet); }
public SearchResults(DtoDataSet results, string tableId = "", int recordsPerPage = 50, int recordLimit = int.MaxValue, int currentPage = 1, int tableIndex = 0, string tableCaption = "Search Results", PagerPosition pagerPosition = PagerPosition.Top, Dictionary <string, string> specialColumnAliases = null) : this() { //OverWrite Default Values From Default Constructor Value If Need To TableIndex = tableIndex; RecordsPerPage = recordsPerPage; RecordLimit = recordLimit; TableCaption = tableCaption; PagerPosition = pagerPosition; SpecialColumnAliases = specialColumnAliases; //If user doesn't specify an Id field stick with the random generated Id if its provided. Else generate another unique id if (!string.IsNullOrWhiteSpace(tableId)) { TableId = tableId; } //If its null want to set it to new object to display error messages if (results == null) { Results = new DtoDataSet(); } else { Results = results; } if (string.IsNullOrWhiteSpace(Results.Error) && Results.Ds.Tables != null && Results.Ds.Tables.Count != 0 && Results.Ds.Tables[TableIndex].Rows.Count != 0) { if (Results.Ds.Tables[TableIndex].Rows.Count > RecordLimit) { Results.Ds = ReplaceTable(Results.Ds, TableIndex, GetNRows(Results.Ds.Tables[TableIndex], RecordLimit)); } RecordCount = Results.Ds.Tables[TableIndex].Rows.Count; TotalPages = CountPages(RecordCount, RecordsPerPage); } if (CurrentPage != currentPage && currentPage > 0 && currentPage <= TotalPages) { CurrentPage = currentPage; } }
/// <summary> /// Gets data from stored procedure with multiple parameters. Any null values will be sent to stored procedure. /// </summary> /// <param name="parameters">Array of parameters to send to database</param> /// <param name="procedureName">Stored procedure to call</param> /// <returns>DtoDataSet filled with data from database</returns> public DtoDataSet GetDataKeepNullParameters(SqlDataAccessParameter[] parameters, string procedureName) { DtoDataSet infoDataSet = new DtoDataSet(); SqlDataAccessContainer dac = new SqlDataAccessContainer(); if (parameters != null) { foreach (SqlDataAccessParameter parameter in parameters) { if (parameter != null && parameter.Value != null && parameter.Value.Length > 0) { dac.Add(parameter); } else if (parameter != null && parameter.ObjectValue != null) { dac.Add(parameter); } else { dac.Add(new SqlDataAccessParameter(parameter.Name, parameter.DataType, DBNull.Value)); } } } infoDataSet.Ds = null; infoDataSet.Error = ""; DataSet localDs = null; try { if (SqlDataConnect.GetData(ref localDs, procedureName, ref _Error, dac) == false) { infoDataSet.Error = _Error; infoDataSet.Ds = null; } infoDataSet.Ds = localDs; } catch (Exception ex) { infoDataSet.Error = ex.Message; Logger.LogError(procedureName, parameters, ex); } return(infoDataSet); }
public SearchResults() { //Random Number for Table Id Random randomNum = new Random(); Results = new DtoDataSet(); RecordsPerPage = 50; RecordLimit = int.MaxValue; CurrentPage = 1; TableIndex = 0; TotalPages = 1; RecordCount = 0; TableCaption = "Search Results"; TableId = "SmartGrid" + randomNum.Next(0, 1000); PagerPosition = PagerPosition.Top; SpecialColumnAliases = null; }
/// <summary> /// Insert, Update, or Delete data via stored procedure. Any null values will be sent to stored procedure. /// </summary> /// <param name="parameters">Parameters to send to database</param> /// <param name="procedureName">Stored procedure to call</param> /// <returns>Result object send from database</returns> public ReturnObj ModifyDataKeepNullParameters(SqlDataAccessParameter[] parameters, string procedureName) { DtoDataSet infoDataSet = new DtoDataSet(); SqlDataAccessContainer dac = new SqlDataAccessContainer(); foreach (SqlDataAccessParameter parameter in parameters) { if (parameter != null && parameter.Value != null && parameter.Value.Length > 0) { dac.Add(parameter); } else if (parameter != null && parameter.ObjectValue != null) { dac.Add(parameter); } else { dac.Add(new SqlDataAccessParameter(parameter.Name, parameter.DataType, DBNull.Value)); } } string error = string.Empty; ReturnObj objReturn = new ReturnObj(); try { long returnValue; returnValue = SqlDataConnect.UpdateData(procedureName, ref error, dac); if (returnValue <= 0) { objReturn.Error = error; } objReturn.Result = returnValue; } catch (Exception ex) { //log this error objReturn.Result = 0; objReturn.Error = ex.Message; Logger.Log.Error(ex); } return(objReturn); }