public UserFieldsData GetUser() { var userTableItem = _sboCompany.UserTables.Item(_tableUserName); try { var _user = new UserFieldsData(); if (!userTableItem.GetByKey(_recordId)) { return(_user); } _user.UserName = (string)userTableItem.UserFields.Fields.Item(0).Value; _user.PassWord = _userService.GetDencryptUserPassword((string)userTableItem.UserFields.Fields.Item(1).Value, _installationId); return(_user); } finally { if (userTableItem != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(userTableItem); } } }
public bool TestConnection(UserFieldsData user = null) { try { var connectionClone = Connection.Instance; CreateTableIfNotExists(); user = user ?? _userRepository.GetUser(); connectionClone.ConnectionParameter.DBUser = user.UserName; connectionClone.ConnectionParameter.DBPassword = user.PassWord; connectionClone.ConnectionParameter.Server = _sboCompany.Server; connectionClone.ConnectionParameter.CompanyDb = _sboCompany.CompanyDB; connectionClone.ConnectionParameter.UserName = _sboCompany.UserName; return(connectionClone.Connect()); } catch (Exception ex) { throw new Exception(ex.ToString(), ex); //Debug.Fail("ERRO AO TENTAR LOGAR NO SQL SERVER",ex.ToString()); return(false); } finally { var connectionClone = Connection.Instance; var userSaved = GetParam(null); connectionClone.ConnectionParameter.DBUser = userSaved.DBUser; connectionClone.ConnectionParameter.DBPassword = userSaved.DBPassword; } }
public void Save(UserFieldsData user) { var userTableItem = _sboCompany.UserTables.Item(_tableUserName); try { var isUpdate = userTableItem.GetByKey(_recordId); userTableItem.Code = _recordId; userTableItem.Name = user.UserName; userTableItem.UserFields.Fields.Item("U_{0}".Fmt(_userNameFieldName)).Value = user.UserName; userTableItem.UserFields.Fields.Item("U_{0}".Fmt(_passwordFIeldName)).Value = _userService.GetEncryptUserPassword(user.PassWord, _installationId); var saveResult = isUpdate ? userTableItem.Update() : userTableItem.Add(); if (saveResult == 0) { return; } var message = "Erro ao salvar os dados do usuário. [{0}] - [{1}:{2}]" .Fmt(user.UserName, _sboCompany.GetLastErrorCode(), _sboCompany.GetLastErrorDescription()); throw new Exception(message); } finally { if (userTableItem != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(userTableItem); } } }
public bool ThereIsUserSaved(out UserFieldsData user) { CreateTableIfNotExists(); user = _userRepository.GetUser(); return(!string.IsNullOrEmpty(user.UserName)); }
public UserFieldsDataForm(UserFieldsData user, SqlUserProvider sqlUserProvider) { InitializeComponent(); _user = user; _sqlUserProvider = sqlUserProvider; FillControls(); }
public void UpdateSqlUserLoggin() { var user = new UserFieldsData(); var userFieldDataForm = new UserFieldsDataForm(user, this); if (userFieldDataForm.ShowDialog() != DialogResult.OK) { return; //throw new Exception("Não foi possível alterar os dados de conexão do banco de dados."); } _userRepository.Save(user); }
public ConnectionParameter GetParam(UserFieldsData user = null) { CreateTableIfNotExists(); user = user ?? _userRepository.GetUser(); var param = Connection.Instance.ConnectionParameter; param.Server = _sboCompany.Server; param.DBUser = user.UserName; param.DBPassword = user.PassWord; param.CompanyDb = _sboCompany.CompanyDB; param.UserName = _sboCompany.UserName; return(param); }
public void SetOrCreateSqlUserLoggin() { var user = new UserFieldsData(); if (ThereIsUserSaved(out user) && TestConnection(user)) { return; } var userFieldDataForm = new UserFieldsDataForm(user, this); if (userFieldDataForm.ShowDialog() != DialogResult.OK) { throw new Exception("Não foi possível conectar ao banco de dados."); } _userRepository.Save(user); }
public void SaveUser(UserFieldsData user) { CreateTableIfNotExists(); _userRepository.Save(user); }