Example #1
0
        public void Update(User user)
        {
            using (connection = factory.CreateDbConnection())
            {
                try
                {
                    DbCommand cmd = connection.CreateCommand();

                    cmd.CommandText = "UPDATE [" + TABLENAME + @"]       
                                       SET    [ContactId] = @contactId ,
                                              [Login] = @login ,       
                                              [Password] = @password ,             
                                              [Admin] = @isAdmin           
                                       WHERE  [Id] = @Id";
                    FactoryUtility.AddParameterWithValue(cmd, "@Id", user.Id);
                    FactoryUtility.AddParameterWithValue(cmd, "@contactId", user.ContactId);
                    FactoryUtility.AddParameterWithValue(cmd, "@login", user.Login);
                    FactoryUtility.AddParameterWithValue(cmd, "@password", user.Password);
                    FactoryUtility.AddParameterWithValue(cmd, "@isAdmin", user.IsAdmin);
                    cmd.Connection = connection;
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #2
0
        public void Delete(User user)
        {
            using (connection = factory.CreateDbConnection())
            {
                try
                {
                    DbCommand cmd = connection.CreateCommand();

                    cmd.CommandText = "DELETE FROM [" + TABLENAME + @"]
                                       WHERE    [ContactId] like @contactId AND 
                                                [Login] like @login AND       
                                                [Password] like @password AND               
                                                [Admin] like @isAdmin";
                    FactoryUtility.AddParameterWithValue(cmd, "@contactId", user.Contact.Id);
                    FactoryUtility.AddParameterWithValue(cmd, "@login", user.Login);
                    FactoryUtility.AddParameterWithValue(cmd, "@password", user.Password);
                    FactoryUtility.AddParameterWithValue(cmd, "@isAdmin", user.IsAdmin);
                    cmd.Connection = connection;

                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #3
0
        public bool isLoginExists(User user)
        {
            using (connection = factory.CreateDbConnection())
            {
                try
                {
                    if (isTableExists() == true)
                    {
                        DbCommand cmd = connection.CreateCommand();
                        cmd.CommandText = "SELECT COUNT( *) from [" + TABLENAME + "] where [Login] like @login";
                        FactoryUtility.AddParameterWithValue(cmd, "@login", user.Login);
                        cmd.Connection = connection;

                        int loginCount = ( int )cmd.ExecuteScalar();
                        if (loginCount > 0)
                        {
                            return(true);
                        }
                        return(false);
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return(true);
                }
            }
        }
Example #4
0
        private int getExistingId(User user)
        {
            try
            {
                DbCommand cmd = connection.CreateCommand();
                cmd.CommandText = "SELECT [ID] from [" + TABLENAME + @"] where               
                        [ContactId] like @contactId AND 
                        [Login] like @login AND       
                        [Password] like @password AND               
                        [Admin] like @isAdmin";
                FactoryUtility.AddParameterWithValue(cmd, "@contactId", user.Contact.Id);
                FactoryUtility.AddParameterWithValue(cmd, "@login", user.Login);
                FactoryUtility.AddParameterWithValue(cmd, "@password", user.Password);
                FactoryUtility.AddParameterWithValue(cmd, "@isAdmin", user.IsAdmin);
                cmd.Connection = connection;

                int personID = ( int )cmd.ExecuteScalar();
                if (personID > 0)
                {
                    return(personID);
                }
                return(-1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(-1);
            }
        }
Example #5
0
        private bool isUserExists(User user)
        {
            try
            {
                DbCommand cmd = connection.CreateCommand();
                cmd.CommandText = "SELECT COUNT( *) from [" + TABLENAME + @"] where 
                        [ContactId] like @contactId AND 
                        [Login] like @login AND       
                        [Password] like @password AND               
                        [Admin] like @isAdmin";
                FactoryUtility.AddParameterWithValue(cmd, "@contactId", user.Contact.Id);
                FactoryUtility.AddParameterWithValue(cmd, "@login", user.Login);
                FactoryUtility.AddParameterWithValue(cmd, "@password", user.Password);
                FactoryUtility.AddParameterWithValue(cmd, "@isAdmin", user.IsAdmin);
                cmd.Connection = connection;

                int userCount = ( int )cmd.ExecuteScalar();
                if (userCount > 0)
                {
                    user.Id = getExistingId(user);
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(true);
            }
        }
        protected override void InstantiateComponents()
        {
            _block = new AutoResetEvent(false);
            _utility = new FactoryUtility();

            LoadWaitSeconds();

            _engine = base.Application.GetService<IAdvancedEngineFactory>().GetEngine(
                new EngineCreationContext()
                {
                    Name = "SwiftPaymentStatusUpdateFactory",
                    Description = "SWIFT Payment Status Update Factory"
                });
            _engine.Scheduler = SwiftPaymentStatus;
        }
Example #7
0
        private void insertUser(User user)
        {
            DbCommand cmd = connection.CreateCommand();

            cmd.CommandText = (@"INSERT INTO [" + TABLENAME + @"] 
                                            ( [ContactId], [Login],[Password],[Admin])
                                            VALUES (
                                               @contactId, @login, @password, @isAdmin)");

            FactoryUtility.AddParameterWithValue(cmd, "@contactId", user.Contact.Id);
            FactoryUtility.AddParameterWithValue(cmd, "@login", user.Login);
            FactoryUtility.AddParameterWithValue(cmd, "@password", user.Password);
            FactoryUtility.AddParameterWithValue(cmd, "@isAdmin", user.IsAdmin);
            cmd.Connection = connection;
            cmd.ExecuteNonQuery();

            user.Id = getLastId();
        }
Example #8
0
        public int ReferenceToThisContact(User user)
        {
            using (connection = factory.CreateDbConnection())
            {
                try
                {
                    DbCommand cmd = connection.CreateCommand();
                    cmd.CommandText = "SELECT COUNT( *) from [" + TABLENAME + @"] where [ContactId] like @contactId";
                    FactoryUtility.AddParameterWithValue(cmd, "@contactId", user.ContactId);
                    cmd.Connection = connection;

                    return(( int )cmd.ExecuteScalar());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return(10);
                }
            }
        }
Example #9
0
        private bool isTableExists()
        {
            bool result = false;

            try
            {
                DbCommand cmd = connection.CreateCommand();
                cmd.CommandText = @"IF EXISTS (SELECT 1 
                                                    FROM INFORMATION_SCHEMA.TABLES  
                                                    WHERE TABLE_TYPE = 'BASE TABLE'
                                                    AND TABLE_NAME = @tableName) 
                                            SELECT 1 AS res ELSE SELECT 0 AS res; ";
                cmd.Connection  = connection;
                FactoryUtility.AddParameterWithValue(cmd, "@tableName", TABLENAME);

                result = ( int )cmd.ExecuteScalar() == 1;
                return(result);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(result);
            }
        }