Exemple #1
0
        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);
                }
            }
        }
Exemple #2
0
        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;
            }
        }
Exemple #3
0
        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);
                }
            }
        }
Exemple #4
0
        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();
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        public void SaveUser(UserFieldsData user)
        {
            CreateTableIfNotExists();

            _userRepository.Save(user);
        }