Sunday, January 20, 2013

DBHelper Class

Lately, I've been busy doing some of the codes for the system that we're working with my team at the office. I just wanted to share this VB.NET class that I made and is being used as the SQL Connection Helper Class for the project that I am into. Enjoy!., comments are welcome.. :)


Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlClient
''' <summary>
''' DBHelper Class
''' </summary>
''' <remarks></remarks>
Public Class DBHelper
    Implements IDisposable
    
    Private _SQLConnectionString As New SqlConnectionStringBuilder
    Private _SQLConnection As New SqlConnection
    Private _SQLCommand As SqlCommand
    Private _DataAdapter As SqlDataAdapter
    Private _DataSet As DataSet
    Private _SQLParameters As SqlParameterCollection = New SqlCommand().Parameters
    Private _AffectedRows As Integer

    ''' <summary>

    ''' SQL Connection string builder for an instance of this class
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property ConnectionStringBuilder() As SqlConnectionStringBuilder
        Get
            Return _SQLConnectionString
        End Get
    End Property

    ''' <summary>

    ''' Row count of affected rows from executing an SQL query
    ''' </summary>
    ''' <value></value>
    ''' <returns>returns an integer value</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property AffectedRows() As Integer
        Get
            Return _AffectedRows
        End Get
    End Property

    ''' <summary>

    ''' Result dataset from a query
    ''' </summary>
    ''' <value></value>
    ''' <returns>returns DataSet object</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property ReturnedDataSet() As DataSet
        Get
            Return _DataSet
        End Get
    End Property

    ''' <summary>

    ''' DBHelper Constructor
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()
        With _SQLConnectionString
            .DataSource = "(local)\sqlexpress"
            .InitialCatalog = "PacificPOS_db_yhan"
            .UserID = "sa"
            .Password = "password01"
        End With
        _SQLConnection.ConnectionString = _SQLConnectionString.ConnectionString
    End Sub

    ''' <summary>

    ''' DBHelper Constructor
    ''' </summary>
    ''' <param name="connectionString">SQL Connection String</param>
    ''' <remarks></remarks>
    Public Sub New(ByVal connectionString As String)
        _SQLConnection.ConnectionString = connectionString
    End Sub

    ''' <summary>

    ''' Method for adding SQL Parameters
    ''' </summary>
    ''' <param name="parameterName"></param>
    ''' <param name="value"></param>
    ''' <remarks></remarks>
    Public Sub AddParameter(ByVal parameterName As String, ByVal value As Object)
        _SQLParameters.AddWithValue(parameterName, value)
    End Sub

    ''' <summary>

    ''' Method for exectution of SQL Queries
    ''' </summary>
    ''' <param name="query">SQL query string</param>
    ''' <param name="hasResult">if this method will have a DataSet result</param>
    ''' <param name="sqlCommandType">type of sql command</param>
    ''' <remarks></remarks>
    Public Sub ExecuteQuery(ByVal query As String, _
                                 ByVal hasResult As GlobalDeclaration.HasDSResult, _
                                 ByVal sqlCommandType As CommandType)
        Try
            _SQLConnection.Open()

            _SQLCommand = New SqlCommand

            _SQLCommand.Connection = _SQLConnection
            _SQLCommand.CommandType = sqlCommandType
            _SQLCommand.CommandText = query

            For Each sqlParam As SqlParameter In _SQLParameters

                _SQLCommand.Parameters.AddWithValue(sqlParam.ParameterName, sqlParam.Value)
            Next

            If hasResult = GlobalDeclaration.HasDSResult.Yes Then

                _DataAdapter = New SqlDataAdapter(_SQLCommand)
                _DataSet = New DataSet
                _DataAdapter.Fill(_DataSet)
            Else
                _AffectedRows = _SQLCommand.ExecuteNonQuery()
            End If

            'Reset parameters

            _SQLParameters = Nothing
            _SQLParameters = New SqlCommand().Parameters

            _SQLConnection.Close()

        Catch ex As Exception
            'Reset parameters
            If _SQLParameters IsNot Nothing Then
                _SQLParameters = Nothing
                _SQLParameters = New SqlCommand().Parameters
            End If

            _SQLConnection.Close()

            Throw
        End Try
    End Sub

    Public Shared ReadOnly Property GetDataSources() As DataTable

        Get
            Return SqlDataSourceEnumerator.Instance.GetDataSources
        End Get
    End Property

    ' IDisposable

    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        Dispose()
        Me._SQLCommand.Dispose()
        Me._SQLConnection.Dispose()
        Me._DataAdapter.Dispose()
        Me._DataSet.Dispose()
    End Sub

#Region " IDisposable Support "

    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region

End Class


Saturday, October 13, 2012

Busy with my First Job

Lately, I haven't been posting here in my blog account. I have been busy with my first job being a VB.NET Developer. As of now I am working with a consolidator and Head Office application project for a Points-of-Sales System. Maybe next time I will be posting code snippets of what I am into... :)

Saturday, October 22, 2011

Client-Server Class E-Commerce Site

This is a website made for our client-server course. The design was made by my partner Ed Garcillanosa and the coding part was made by me.
HERE'S THE LINK >> http://khian545.xtreemhost.com/page.php?action=home

Monday, October 17, 2011

MY FIRST FLASH-BASED PORTFOLIO


Lately, I was able to upload my first ever flash-based portfolio on the net. Well, the portfolio is still in progress. I think it's on its 10% as of now. So i'm looking forward into finishing this project. Here's the link if you want to take a look at my unfinished portfolio >> http://khian545.xtreemhost.com/flashportfolio/

Tuesday, September 6, 2011

Nothing to do, then try Gaming

 Now, I'm into this game... I find it awesome because of its strategic gameplay...
I've been into this game the past few days. Just for pass time purposes. It's actually for stress relief. It's my way of saying relax and enjoy!














Exploring Android App Development

Recently, I've been into java coding again. I've watched some video tutorials for me to be able to cope up with the android dev environment. If I would be lucky with my exploration of the android application development, I'd be posting some of my works.

Wednesday, June 15, 2011

FORGOT TO POST MY PORTFOLIO

Well, i recently have this online portfolio which was personally coded and designed by me. It just so happened that I haven't updated this blog lately. So now here's the time... This post is all about my online portfolio, I've used some of the scripting languages and frameworks that I know such as javascript and jquery in order for this portfolio to be functional. For now I'm still learning and studying some innovations to further improve this.... ^_^ http://khianzxq.zxq.net/

Wednesday, June 1, 2011

BLOG WALK

when i was in middle of searching for computer blogs, i just noticed this site and thought of a subject of mine. It was my subject in my 3rd year at the University of Nueva Caceres, the subject was Structured Programming Languages. So what with the site that I've found lately?... yah right.. it was a blog for computer languages evolution and was taught to us when we were in our 3rd year class. I just wanted to share this site for future reference..... ^_^ http://www.rackspace.com/cloud/blog/2011/05/17/infographic-evolution-of-computer-languages/

Sunday, January 30, 2011

FLASH ATM



Update:
I've already finished and submitted my exercise... but still it is subject to errors and modifications... i've provided a link for the finish exercise and is now available for download... DOWNLOAD

Update:
I've been thinking of the transactions that I will incorporate to the simulator and I'm still thinking if I will animate the releasing of bills.

Been working for this project... actually this is not a project, it's just an exercise... after I finish working with this... i'll upload the source code...
Freelance Jobs