private Queue <DataTable> MultipleSelectQuery(SqlConnectionService connectionService, string query, SqlTransaction transaction) { Queue <DataTable> result; using (var dataSet = new DataSet()) { using (var connection = connectionService.Create()) { using (var sqlCommand = connection.CreateCommand()) { sqlCommand.CommandText = query; sqlCommand.Transaction = transaction; using (var adapter = new SqlDataAdapter(sqlCommand)) { adapter.Fill(dataSet); } } } result = new Queue <DataTable>(); foreach (DataTable table in dataSet.Tables) { result.Enqueue(table); } } return(result); }
public bool SetNewPassword(ResetPassword model) { try { ISqlConnectionService _sqlConnService = new SqlConnectionService(); SqlCommand cmd; try { _sqlConnService.OpenConnection(); cmd = new SqlCommand("SP_SetNewPassword", _sqlConnService.CreateConnection()); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID", model.UserID); cmd.Parameters.AddWithValue("@Password", Utility.MD5(model.Password)); cmd.Parameters.AddWithValue("@StatementType", model.UserType); cmd.ExecuteNonQuery(); } catch (Exception ex) { string message = ex.InnerException != null ? ex.InnerException.InnerException.Message : ex.Message; throw new Exception(message); } finally { _sqlConnService.CloseConnection(); } } catch (Exception ex) { throw new Exception(ex.Message); } return(true); }
public ViewModel_AddDataManually() { _db = new DatabaseService(); _connService = new SqlConnectionService(); _qService = new DatabaseQueryService(_connService); _modService = new DatabaseModificationService(_connService); this.DisplayName = "Add Data Manually To Database"; }
public static IServices GetServices(DirectoryInfo exportRoot, OrgUnit orgUnit, Process process) { var metaObjectService = new MetaObjectService(exportRoot, orgUnit, process); var mappingService = new MappingService(metaObjectService); var connectionService = new SqlConnectionService(metaObjectService); var services = new Services(); return(services.Register <ICompressionService>(new CompressionService()) .Register <IDataService>(new DataService(metaObjectService, connectionService, mappingService)) .Register <IEmailService>(new EmailService()) .Register <IEncryptionService>(new EncryptionService()) .Register <IDocumentService>(new DocumentService(metaObjectService)) .Register <ILoggingService>(new LoggingService()) .Register <IMappingService>(mappingService) .Register <IMetaObjectService>(metaObjectService) .Register <ISftpService>(new SftpService()) as IServices); }
public GenericDataService(string connStr = null) : base(SqlConnectionService.FromConnectionString(connStr)) { }
public GenericDataService(SqlConnectionService connectionManager = null) : base(connectionManager) { }
public DatabaseModificationService(SqlConnectionService connService) { this._connService = connService; }
public DatabaseIntegrityService(SqlConnectionService connService, DatabaseQueryService _qService, DatabaseModificationService modService) { this._connService = connService; this._qService = _qService; this._modService = modService; }
static void Main(string[] args) { Console.WriteLine(ConsoleHelpers.GetSlackerHeaderText()); if (args.Length < 4 || args[0].ToLower() != "export") { Console.WriteLine("Invalid command syntax: " + EXPORT_SYNTAX); Console.Read(); return; } // Get Connection String var connectionString = ConfigurationManager.ConnectionStrings .Cast <ConnectionStringSettings>().FirstOrDefault( connStr => connStr.Name == args[1] ) ?.ConnectionString; // Initialize DataService var dataService = new GenericDataService <InformationSchemaColumn>( SqlConnectionService.FromConnectionString(connectionString) ); // Get Information Schema var informationSchema = dataService.Select(new QueryProps() { WhereSql = "TABLE_CATALOG LIKE @Catalog", WhereParams = new { Catalog = args[2] } }); if (!informationSchema.Any()) { Console.WriteLine("Could not find any results matching information schema target."); Console.Read(); return; } // Get Output Directory var catalogName = DataModelTemplate.GetPropertyName(informationSchema.First().TableCatalog); var catalogDir = !Path.IsPathRooted(args[3]) ? Path.Combine(Environment.CurrentDirectory, args[3], catalogName) : Path.Combine(args[3], catalogName); // Create Catalog Directory if not exists if (!Directory.Exists(catalogDir)) { Directory.CreateDirectory(catalogDir); } // Create output schema delegate void OutputSchema(IGrouping <string, InformationSchemaColumn> schemaGroup) { var schemaName = DataModelTemplate.GetPropertyName(schemaGroup.First().TableSchema); var schemaDir = Path.Combine(catalogDir, schemaName); // Create Schema Directory if not exists if (!Directory.Exists(schemaDir)) { Directory.CreateDirectory(schemaDir); } // Create output file delegate void OutputFile(DataModelTemplate dataModelTemplate) { var tableName = DataModelTemplate.GetPropertyName(dataModelTemplate.TableName); var filePath = Path.Combine(schemaDir, tableName + ".cs"); if (File.Exists(filePath)) { File.Delete(filePath); } Console.WriteLine($"Generating Model: {catalogName}\\{schemaName}\\{tableName}.cs"); File.WriteAllText(filePath, dataModelTemplate.TransformText()); } // Output files schemaGroup.GroupBy( infoSchemaCol => infoSchemaCol.TableName ).Select( infoSchemaCols => new DataModelTemplate(infoSchemaCols.ToList()) ).ToList().ForEach( OutputFile ); } // Build Models informationSchema.GroupBy( infoSchemaCol => infoSchemaCol.TableSchema ).ToList().ForEach(OutputSchema); Console.WriteLine("Done"); Console.Read(); }
public TransproLanguagePriceService() { _sqlConnService = new SqlConnectionService(); _sqlConnService2 = new SqlConnectionService(); }
public ModifyDatabase_InputValues(SqlConnectionService sqlService, ExcelFileParsingService parser) { _sqlService = sqlService; _parser = parser; }
internal void ReflectionTableViewModelsMapping(SqlConnectionService connectionService, SelectQuery query, Type type, SqlTransaction transaction = null) { var dataTables = MultipleSelectQuery(connectionService, query.Query, transaction); var viewModel = GetDataTableReflectedList(type, dataTables); query.Root.ViewModelDic = new Dictionary <object, object>(); foreach (var row in viewModel) { var key = PropertyReflectionHelper.GetPrimaryKeyNameAndValue(row); query.Root.ViewModelDic.Add(key.Value, row); } var stack = new Stack <SelectStackItem>(); if (query.Root.JoinTables != null) { foreach (var joinTable in query.Root.JoinTables) { stack.Push(new SelectStackItem() { Table = joinTable }); } } while (stack.Any()) { var item = stack.Pop(); Type childType = item.Table.Property.PropertyType; if (item.Table.IsOneToMany) { childType = childType.GetGenericArguments()[0]; } viewModel = GetDataTableReflectedList(childType, dataTables); item.Table.ReflectionTable.ViewModelDic = new Dictionary <object, object>(); var dic = item.Table.ReflectionTable.ViewModelDic; foreach (var row in viewModel) { if (!item.Table.IsInverse) { var key = PropertyReflectionHelper.GetPrimaryKeyNameAndValue(row); dic.Add(key.Value, row); } else { var id = PropertyReflectionHelper.GetPropValue(row, item.Table.ForeignKey); if (!item.Table.IsOneToMany) { if (!dic.Contains(id)) { dic.Add(id, row); } } else { if (!dic.Contains(id)) { var list = (IList)Activator.CreateInstance( item.Table.Property.PropertyType); list.Add(row); dic.Add(id, list); } else { var list = (IList)dic[id]; list.Add(row); } } } } if (item.Table.ReflectionTable.JoinTables != null) { foreach (var joinTable in item.Table.ReflectionTable.JoinTables) { stack.Push(new SelectStackItem() { Table = joinTable }); } } } }
public DatabaseQueryService(SqlConnectionService connService) { _connService = connService; }