public void CreateRdbms(RdbmsDto rdbmsDto) { // Todo: 验证 DB 是否能链接 var rdbms = new Rdbms(rdbmsDto.Name, rdbmsDto.Description, rdbmsDto.Server, rdbmsDto.Catalog, rdbmsDto.UserId, rdbmsDto.Password, rdbmsDto.ReadOnly, rdbmsDto.Provider); this._rdbmsRepository.Add(rdbms); }
public void UpdateRdbms(RdbmsDto rdbmsDto) { var rdbms = this._rdbmsRepository.GetByKey(rdbmsDto.ID); if (rdbms == null) return; // Todo: 验证 DB 是否能链接 rdbms.Update(rdbmsDto.Name, rdbmsDto.Description, rdbmsDto.Server, rdbmsDto.Catalog, rdbmsDto.UserId, rdbmsDto.Password, rdbmsDto.ReadOnly, rdbmsDto.Provider); this._rdbmsRepository.Update(rdbms); }
public ActionResult Edit(RdbmsDto model) { try { using (var service = ServiceLocator.Instance.Resolve<IRdbmsService>()) { service.UpdateRdbms(model); } return Json(true); } catch (Exception) { return Json(false, "Modify the RDBMS failure."); } }
public ActionResult Create(RdbmsDto model) { if (!this.TestConnection(model)) return Json(false, "Connect the RDBMS failure, please check your database server account."); try { using (var service = ServiceLocator.Instance.Resolve<IRdbmsService>()) { service.CreateRdbms(model); } return Json(true); } catch (Exception) { return Json(false, "Create the RDBMS failure."); } }
// 显示 Table / View 的信息(字段名及类型等) private IEnumerable<TableSchemaDto> GetTableSchema(RdbmsDto rdbms, string table) { var connOpt = new ConnectionOptions { DataSource = rdbms.Server, InitialCatalog = rdbms.Catalog, UserId = CryptoFactory.AES.Decrypt(rdbms.UserId), Password = CryptoFactory.AES.Decrypt(rdbms.Password), ReadOnly = rdbms.ReadOnly }; var schemaService = ServiceLocator.Instance.Resolve<IReportSchemaQueryService>(); return schemaService.GetTableSchema(connOpt, rdbms.Provider, "dbo", table); }
private bool TestConnection(RdbmsDto rdbms) { var connectionOpt = new ConnectionOptions { DataSource = rdbms.Server, InitialCatalog = rdbms.Catalog, UserId = rdbms.UserId, Password = rdbms.Password, ReadOnly = rdbms.ReadOnly }; var connTest = StorageManager.ConnectionTest(connectionOpt, rdbms.Provider); return connTest.Test(); }