Imports System.IO
Imports System.Windows.Forms
Imports System.Net.Mail
Imports System.Data.OleDb
Imports System.Security.Permissions
Imports System.Text
Imports System.Security.Cryptography

Public Class frmUserENG

    Dim connstring As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|datadirectory|\sis.accdb"
    Dim connect As New OleDbConnection

#Region "Connections"
    Public Sub openconnection()
        If connect.State = ConnectionState.Closed Then
            connect.ConnectionString = connstring
            connect.Open()
        ElseIf connect.State = ConnectionState.Open Then
            Me.Refresh()
        End If
    End Sub

    Public Sub closeconnection()
        If connect.State = ConnectionState.Open Then
            connect.Close()
        ElseIf connect.State = ConnectionState.Closed Then
            Me.Refresh()
        End If
    End Sub
#End Region

#Region "Buttons"
#Region "HOME"
    Private Sub btnHome_Click(sender As System.Object, e As System.EventArgs) Handles btnHome.Click
        enablebtns()
        btnHome.Enabled = False
        hidegb()
        gbHome.Dock = DockStyle.Fill
        gbHome.Show()
        viewnews()
        txthomesearch.Clear()
    End Sub

    Private Sub viewnews()
        Dim selectqry As String = "SELECT * FROM news"
        Dim da As OleDbDataAdapter
        Dim dtset As New DataSet
        Dim dttable As New DataTable
        da = New OleDbDataAdapter(selectqry, connect)
        da.Fill(dtset, "news")
        dttable = dtset.Tables("news")

        dgvHome.DataSource = dttable
        dgvHome.ColumnHeadersDefaultCellStyle.Font = New Font(dgvHome.Font, FontStyle.Bold)
        dgvHome.ForeColor = Color.Black
        dgvHome.Font = New Font(dgvHome.Font, FontStyle.Regular)

        dgvHome.Columns("ID").HeaderText = "News number"
        dgvHome.Columns("ID").Width = 80

        dgvHome.Columns("ntitle").HeaderText = "News Title"
        dgvHome.Columns("ntitle").Width = 180

        dgvHome.Columns("ndescription").HeaderText = "News Description"
        dgvHome.Columns("ndescription").Width = 428

        dgvHome.Columns("ntime").HeaderText = "Time Posted"
        dgvHome.Columns("ntime").Width = 270
    End Sub

    Private Sub btnhomesearch_Click(sender As System.Object, e As System.EventArgs) Handles btnhomesearch.Click
        Dim search As String = txthomesearch.Text.Trim
        If (search = "" Or IsNothing(search) = True) Then
            MsgBox("Please enter something to search", MsgBoxStyle.Information, "Error")
            txthomesearch.Focus()
        Else
            txthomesearch.Clear()
            Dim searchqry As String = "SELECT * FROM news WHERE id LIKE '%" + search + "%' OR ntitle LIKE '%" + search + "%' OR ndescription LIKE '%" + search + "%' OR ntime LIKE '%" + search + "%'"
            Dim da As OleDbDataAdapter
            Dim dtset As New DataSet
            Dim dttable As New DataTable
            da = New OleDbDataAdapter(searchqry, connect)
            da.Fill(dtset, "news")
            dttable = dtset.Tables("news")

            dgvHome.DataSource = dttable
            dgvHome.ColumnHeadersDefaultCellStyle.Font = New Font(dgvHome.Font, FontStyle.Bold)
            dgvHome.ForeColor = Color.Black
            dgvHome.Font = New Font(dgvHome.Font, FontStyle.Regular)

            dgvHome.Columns("ID").HeaderText = "News number"
            dgvHome.Columns("ID").Width = 80

            dgvHome.Columns("ntitle").HeaderText = "News Title"
            dgvHome.Columns("ntitle").Width = 180

            dgvHome.Columns("ndescription").HeaderText = "News Description"
            dgvHome.Columns("ndescription").Width = 428

            dgvHome.Columns("ntime").HeaderText = "Time Posted"
            dgvHome.Columns("ntime").Width = 270

        End If
    End Sub

    Private Sub btnHomerefresh_Click(sender As System.Object, e As System.EventArgs) Handles btnHomerefresh.Click
        viewnews()
    End Sub
#End Region

#Region "SALE"

    Private Sub btnsales_Click(sender As System.Object, e As System.EventArgs) Handles btnSales.Click
        enablebtns()
        btnSales.Enabled = False
        hidegb()
        gbSale.Dock = DockStyle.Fill
        gbSale.Show()
        clearinputs_sale()

        Dim selectqry As String = "SELECT * FROM stock"
        Dim da As OleDbDataAdapter
        da = New OleDbDataAdapter(selectqry, connect)
        Dim dtset As DataSet
        dtset = New DataSet()
        da.Fill(dtset, "stock")
        Dim dttable As DataTable
        dttable = New DataTable
        dttable = dtset.Tables("stock")

        Dim dbname As String
        For Each temprow In dttable.Rows
            dbname = temprow("pname").ToString
            cbName.Items.Add(dbname)
        Next

    End Sub

    Private Sub btnClearaddstock_Click(sender As System.Object, e As System.EventArgs) Handles btnClearaddstock.Click
        clearinputs_sale()
    End Sub

    Private Sub btnSaveaddstock_Click(sender As System.Object, e As System.EventArgs) Handles btnSaleaddstock.Click
        Dim pname As String = cbName.Text
        Dim pcategory As String = cbcategory.Text.Trim
        Dim pquantity As String = txtquantityaddstock.Text.Trim
        Dim pselling As String = txtsellpriceaddstock.Text.Trim
        Dim pinfo As String = txtInfoaddstock.Text.Trim
        Dim ptime As String = lblTime.Text.Trim & " " & lblDate.Text.Trim
        Dim pquantityremain, pprofit As String


        Dim selectqry As String = "SELECT * FROM stock WHERE pname='" + pname + "' AND pcategory='" + pcategory + "'"
        Dim da As OleDbDataAdapter
        da = New OleDbDataAdapter(selectqry, connect)
        Dim dtset As DataSet
        dtset = New DataSet()
        da.Fill(dtset, "stock")
        Dim dttable As DataTable
        dttable = New DataTable
        dttable = dtset.Tables("stock")

        Dim dbquantity, dbbuying As String
        For Each temprow In dttable.Rows
            dbquantity = temprow("pquantity").ToString
            dbbuying = temprow("pbuying").ToString
        Next

        If pname.Length < 2 Then
            MsgBox("Product name can not be less than 2 characters", MessageBoxIcon.Warning, "Error")
            cbName.Focus()
        ElseIf pname.Length > 25 Then
            MsgBox("Product name can not be more than 25 characters", MessageBoxIcon.Warning, "Error")
            cbName.Focus()

        ElseIf cbcategory.Text = "" Then
            MsgBox("Please select product category", MessageBoxIcon.Warning, "Error")
            cbcategory.Focus()

        ElseIf IsNumeric(pquantity) = False Then
            MsgBox("Only numbers are allowed in quantity", MessageBoxIcon.Warning, "Error")
            txtquantityaddstock.Focus()
            Exit Sub
        ElseIf pquantity.Length > 25 Then
            MsgBox("Product quantity can not be more than 25 digits", MessageBoxIcon.Warning, "Error")
            txtquantityaddstock.Focus()
            Exit Sub

        ElseIf IsNumeric(pselling) = False Then
            MsgBox("Only numbers are allowed in selling price", MessageBoxIcon.Warning, "Error")
            txtsellpriceaddstock.Focus()
        ElseIf pselling.Length > 25 Then
            MsgBox("Product selling price can not be more than 25 digits", MessageBoxIcon.Warning, "Error")
            txtsellpriceaddstock.Focus()

        ElseIf pinfo.Length < 2 Then
            MsgBox("Product informations can't be less than 2 characters", MessageBoxIcon.Warning, "Error")
            txtInfoaddstock.Focus()

        ElseIf txtInfoaddstock.Text = "" Then
            MsgBox("Please enter information about the product", MessageBoxIcon.Warning, "Error")
            txtInfoaddstock.Focus()

        Else
            'for log file
            'Dim uname As String =frmlogin.lbluname.text
            Dim uname As String = "cngirwa"
            Dim activity As String = uname + " sold a product with name " + pname
            Dim activitydate As String = lblTime.Text + " " + lblDate.Text
            Dim insertlog As String = "INSERT INTO logfiles VALUES('" + uname + "','" + activity + "','" + activitydate + "')"
            Dim insertlogcmd As New OleDbCommand
            With insertlogcmd
                .CommandText = insertlog
                .Connection = connect
                .ExecuteNonQuery()
            End With

            pquantityremain = dbquantity - pquantity
            pprofit = pselling - dbbuying

            Dim updateqry As String = "UPDATE stock SET pquantity='" + pquantityremain + "' WHERE pname='" + pname + "' AND pcategory='" + pcategory + "' "
            Dim updatecmd As New OleDbCommand
            With updatecmd
                .CommandText = updateqry
                .Connection = connect
                .ExecuteNonQuery()
            End With

            Dim insertqry As String = "INSERT INTO sales(pname,pcategory,pquantitysold,pquantityremain,pselling,pprofit,pinfo,pdate) VALUES('" + pname + "','" + pcategory + "','" + pquantity + "','" + pquantityremain + "','" + pselling + "','" + pprofit + "','" + pinfo + "','" + ptime + "')"
            Dim insertcmd As New OleDbCommand
            With insertcmd
                .CommandText = insertqry
                .Connection = connect
                .ExecuteNonQuery()
            End With
            MsgBox("Product sold", MsgBoxStyle.Information, "Success")
            clearinputs_sale()
        End If
    End Sub

    Private Sub cbName_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cbName.SelectedIndexChanged
        cbcategory.Items.Clear()
        Dim selectqrycat As String = "SELECT * FROM stock WHERE pname='" + cbName.SelectedItem.ToString + "'"
        Dim dacat As OleDbDataAdapter
        dacat = New OleDbDataAdapter(selectqrycat, connect)
        Dim dtsetcat As DataSet
        dtsetcat = New DataSet()
        dacat.Fill(dtsetcat, "stock")
        Dim dttablecat As DataTable
        dttablecat = New DataTable
        dttablecat = dtsetcat.Tables("stock")

        Dim dbcategory As String
        For Each temprow In dttablecat.Rows
            dbcategory = temprow("pcategory").ToString
            cbcategory.Items.Add(dbcategory)
        Next
    End Sub

    Private Sub txtquantityaddstock_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtquantityaddstock.TextChanged
        Dim pquantity As String = txtquantityaddstock.Text.Trim
        If pquantity = "" Then
            txtquantityaddstock.Clear()
            Exit Sub
        ElseIf IsNumeric(pquantity) = False Then
            MsgBox("Only numbers are allowed with no space", MessageBoxIcon.Warning, "Error")
            txtquantityaddstock.Clear()
            txtquantityaddstock.Focus()
            Exit Sub
        ElseIf pquantity.Length > 25 Then
            MsgBox("Product quantity can not be more than 25 digits", MessageBoxIcon.Warning, "Error")
            txtquantityaddstock.Clear()
            txtquantityaddstock.Focus()
            Exit Sub
        End If
    End Sub

    Private Sub txtsellpriceaddstock_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtsellpriceaddstock.TextChanged
        Dim pselling As String = txtsellpriceaddstock.Text.Trim
        If pselling = "" Then
            txtsellpriceaddstock.Clear()
            Exit Sub
        ElseIf IsNumeric(pselling) = False Then
            MsgBox("Only numbers are allowed with no space", MessageBoxIcon.Warning, "Error")
            txtsellpriceaddstock.Clear()
            txtsellpriceaddstock.Focus()
            Exit Sub
        ElseIf pselling.Length > 25 Then
            MsgBox("Product selling price can not be more than 25 digits", MessageBoxIcon.Warning, "Error")
            txtsellpriceaddstock.Clear()
            txtsellpriceaddstock.Focus()
            Exit Sub
        End If
    End Sub

    Private Sub clearinputs_sale()
        txtInfoaddstock.Clear()
        txtquantityaddstock.Clear()
        txtsellpriceaddstock.Clear()
    End Sub
#End Region

#Region "VIEW STORE"
    Private Sub btnViewstock_Click(sender As System.Object, e As System.EventArgs) Handles btnViewstock.Click
        enablebtns()
        btnViewstock.Enabled = False
        hidegb()
        gbViewstock.Dock = DockStyle.Fill
        gbViewstock.Show()
        viewstock()
    End Sub

    Private Sub btnViewstorerefresh_Click(sender As System.Object, e As System.EventArgs) Handles btnViewstorerefresh.Click
        viewstock()
    End Sub

    Private Sub viewstock()
        'for log file
        'Dim uname As String =frmlogin.lbluname.text
        Dim uname As String = "cngirwa"
        Dim activity As String = uname + " viewed stock "
        Dim activitydate As String = lblTime.Text + " " + lblDate.Text
        Dim insertlog As String = "INSERT INTO logfiles VALUES('" + uname + "','" + activity + "','" + activitydate + "')"
        Dim insertlogcmd As New OleDbCommand
        With insertlogcmd
            .CommandText = insertlog
            .Connection = connect
            .ExecuteNonQuery()
        End With

        Dim selectqry As String = "SELECT id,pname,pcategory,pquantity,pselling,pinfo,pdate FROM stock"
        Dim da As OleDbDataAdapter
        Dim dtset As DataSet
        Dim dttable As New DataTable

        da = New OleDbDataAdapter(selectqry, connect)
        dtset = New DataSet
        da.Fill(dtset, "stock")
        dttable = dtset.Tables("stock")

        dgvViewstore.DataSource = dttable
        dgvViewstore.ColumnHeadersDefaultCellStyle.Font = New Font(dgvViewstore.Font, FontStyle.Bold)
        dgvViewstore.Font = New Font(dgvViewstore.Font, FontStyle.Regular)
        dgvViewstore.ForeColor = Color.Black

        dgvViewstore.Columns("ID").HeaderText = "S/N"
        dgvViewstore.Columns("ID").Width = 35

        dgvViewstore.Columns("pname").HeaderText = "Product name"
        dgvViewstore.Columns("pname").Width = 160

        dgvViewstore.Columns("pcategory").HeaderText = "Category"
        dgvViewstore.Columns("pcategory").Width = 90

        dgvViewstore.Columns("pquantity").HeaderText = "Quantity Remain"
        dgvViewstore.Columns("pquantity").Width = 70

        dgvViewstore.Columns("pselling").HeaderText = "Selling Price"
        dgvViewstore.Columns("pselling").Width = 70

        dgvViewstore.Columns("pinfo").HeaderText = "Description of Product"
        dgvViewstore.Columns("pinfo").Width = 270

        dgvViewstore.Columns("pdate").HeaderText = "Date"
        dgvViewstore.Columns("pdate").Width = 270

    End Sub

    Private Sub btnViewstoresearch_Click(sender As System.Object, e As System.EventArgs) Handles btnViewstoresearch.Click
        Dim search As String = txtViewstoresearch.Text.Trim
        If (search = "" Or IsNothing(search) = True) Then
            MsgBox("Please enter something to search", MsgBoxStyle.Information, "Error")
            txtViewstoresearch.Focus()
        Else
            txtViewstoresearch.Clear()
            Dim searchqry As String = "SELECT id,pname,pcategory,pquantity,pselling,pinfo,pdate FROM stock WHERE id LIKE '%" + search + "%' OR pname LIKE '%" + search + "%' OR pcategory LIKE '%" + search + "%' OR pquantity LIKE '%" + search + "%' OR pselling LIKE '%" + search + "%' OR pinfo LIKE '%" + search + "%' OR pdate LIKE '%" + search + "%'"
            Dim da As OleDbDataAdapter
            Dim dtset As DataSet
            Dim dttable As New DataTable

            da = New OleDbDataAdapter(searchqry, connect)
            dtset = New DataSet
            da.Fill(dtset, "stock")
            dttable = dtset.Tables("stock")

            dgvViewstore.DataSource = dttable
            dgvViewstore.ColumnHeadersDefaultCellStyle.Font = New Font(dgvViewstore.Font, FontStyle.Bold)
            dgvViewstore.Font = New Font(dgvViewstore.Font, FontStyle.Regular)
            dgvViewstore.ForeColor = Color.Black

            dgvViewstore.Columns("ID").HeaderText = "S/N"
            dgvViewstore.Columns("ID").Width = 35

            dgvViewstore.Columns("pname").HeaderText = "Product Name"
            dgvViewstore.Columns("pname").Width = 160

            dgvViewstore.Columns("pcategory").HeaderText = "Category"
            dgvViewstore.Columns("pcategory").Width = 90

            dgvViewstore.Columns("pquantity").HeaderText = "Quantity Remain"
            dgvViewstore.Columns("pquantity").Width = 70

            dgvViewstore.Columns("pselling").HeaderText = "Selling Price"
            dgvViewstore.Columns("pselling").Width = 70

            dgvViewstore.Columns("pinfo").HeaderText = "Description of Product"
            dgvViewstore.Columns("pinfo").Width = 270

            dgvViewstore.Columns("pdate").HeaderText = "Date"
            dgvViewstore.Columns("pdate").Width = 270
        End If
    End Sub
#End Region

#Region "SETTING"

    Private Sub btnSettings_Click(sender As System.Object, e As System.EventArgs) Handles btnSettings.Click
        enablebtns()
        btnSettings.Enabled = False
        hidegb()
        gbSetting.Dock = DockStyle.Fill
        gbSetting.Show()
        clearinputs_settings()
    End Sub

    Private Sub btnChangepass_Click(sender As System.Object, e As System.EventArgs) Handles btnChangepass.Click
        Dim oldpass As String = txtOldpass.Text.Trim
        Dim newpass As String = txtNewpass.Text.Trim
        Dim repeat As String = txtRepeat.Text.Trim
        'Dim uname As String =frmlogin.lbluname.text
        Dim uname As String = "cngirwa"

        Dim Ueold As New UnicodeEncoding()
        Dim ByteSourceTextold() As Byte = Ueold.GetBytes(oldpass)
        Dim Md5old As New MD5CryptoServiceProvider()
        Dim ByteHashold() As Byte = Md5old.ComputeHash(ByteSourceTextold)
        Convert.ToBase64String(ByteHashold)
        Dim hashPwdold As String
        hashPwdold = Convert.ToBase64String(ByteHashold)

        Dim selectqry As String = "SELECT * FROM users WHERE uname='" + uname + "'"
        Dim da As OleDbDataAdapter
        da = New OleDbDataAdapter(selectqry, connect)
        Dim dtset As DataSet
        dtset = New DataSet()
        da.Fill(dtset, "users")
        Dim dttable As DataTable
        dttable = New DataTable
        dttable = dtset.Tables("users")

        Dim dbuname, dbpass As String
        For Each temprow In dttable.Rows
            dbuname = temprow("uname").ToString
            dbpass = temprow("upass").ToString
        Next

        Dim Uenew As New UnicodeEncoding()
        Dim ByteSourceTextnew() As Byte = Uenew.GetBytes(newpass)
        Dim Md5new As New MD5CryptoServiceProvider()
        Dim ByteHashnew() As Byte = Md5new.ComputeHash(ByteSourceTextnew)
        Convert.ToBase64String(ByteHashnew)
        Dim hashPwdnew As String
        hashPwdnew = Convert.ToBase64String(ByteHashnew)

        If (oldpass = "" Or IsNothing(oldpass) = True) Then
            MsgBox("Please enter old password", MessageBoxIcon.Warning, "Error")
            txtOldpass.Focus()
        ElseIf (newpass = "" Or IsNothing(newpass) = True) Then
            MsgBox("Please enter new password", MessageBoxIcon.Warning, "Error")
            txtNewpass.Focus()
        ElseIf (repeat = "" Or IsNothing(repeat) = True) Then
            MsgBox("Please enter new password again", MessageBoxIcon.Warning, "Error")
            txtRepeat.Focus()
        ElseIf (dbpass <> hashPwdold) Then
            MsgBox("Old password did not match", MessageBoxIcon.Warning, "Error")
            txtOldpass.Focus()
        ElseIf (newpass <> repeat) Then
            MsgBox("New password did not match", MessageBoxIcon.Warning, "Error")
            txtNewpass.Focus()
        ElseIf (hashPwdnew = dbpass) Then
            MsgBox("New password is the same as old password. Please enter new password", MessageBoxIcon.Warning, "Error")
            txtNewpass.Focus()
        Else
            'for log file
            Dim activity As String = uname + " changed password "
            Dim activitydate As String = lblTime.Text + " " + lblDate.Text
            Dim insertlog As String = "INSERT INTO logfiles VALUES('" + uname + "','" + activity + "','" + activitydate + "')"
            Dim insertlogcmd As New OleDbCommand
            With insertlogcmd
                .CommandText = insertlog
                .Connection = connect
                .ExecuteNonQuery()
            End With

            Dim updateqry As String = "UPDATE users SET upass='" + hashPwdnew + "' WHERE uname='" + uname + "'"
            Dim updatecmd As New OleDbCommand
            With updatecmd
                .CommandText = updateqry
                .Connection = connect
                .ExecuteNonQuery()
            End With
            MsgBox("Password updated", MsgBoxStyle.Information, "Success")
            clearinputs_settings()
        End If
    End Sub

    Private Sub clearinputs_settings()
        txtOldpass.Clear()
        txtNewpass.Clear()
        txtRepeat.Clear()
    End Sub
#End Region

#Region "HELP"
    Private Sub btnHelp_Click(sender As System.Object, e As System.EventArgs) Handles btnHelp.Click
        enablebtns()
        btnHelp.Enabled = False
        hidegb()
        gbHelp.Dock = DockStyle.Fill
        gbHelp.Show()
    End Sub
#End Region

#Region "LOGOUT"
    Private Sub btnLogout_Click(sender As System.Object, e As System.EventArgs) Handles btnLogout.Click
        Dim logout As String
        logout = MessageBox.Show("Are you sure you want to logout?", "Stationary Information System", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
        If logout = MsgBoxResult.No Then
            Me.Refresh()
            enablebtns()
            btnHome.Enabled = False
            hidegb()
            gbHome.Dock = DockStyle.Fill
            gbHome.Show()
        Else
            'for log file
            Dim uname As String = frmLogin.lbluname.Text
            Dim unamelog As String = uname
            Dim activity As String = unamelog + " logged out "
            Dim activitydate As String = lblTime.Text + " " + lblDate.Text
            Dim insertlog As String = "INSERT INTO logfiles VALUES('" + unamelog + "','" + activity + "','" + activitydate + "')"
            Dim insertlogcmd As New OleDbCommand
            With insertlogcmd
                .CommandText = insertlog
                .Connection = connect
                .ExecuteNonQuery()
            End With

            Dim updateqry As String = "UPDATE users SET access='LOGOUT' WHERE uname='" + uname + "'"
            Dim updatecmd As New OleDbCommand
            With updatecmd
                .CommandText = updateqry
                .Connection = connect
                .ExecuteNonQuery()
            End With

            frmLogin.Show()
            Me.Dispose()
            closeconnection()
        End If
    End Sub
#End Region
#End Region

#Region "Form actions"
    Private Sub frmuserENG_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        openconnection()
        Dim close As String
        close = MessageBox.Show("Are you sure you want to close?", "Stationary Information System", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
        If close = MsgBoxResult.No Then
            Me.Refresh()
            e.Cancel = True
        Else
            Dim uname As String = frmLogin.lbluname.Text
            Dim unamelog As String = uname
            Dim activity As String = unamelog + " logged out "
            Dim activitydate As String = lblTime.Text + " " + lblDate.Text
            Dim insertlog As String = "INSERT INTO logfiles VALUES('" + unamelog + "','" + activity + "','" + activitydate + "')"
            Dim insertlogcmd As New OleDbCommand
            With insertlogcmd
                .CommandText = insertlog
                .Connection = connect
                .ExecuteNonQuery()
            End With

            Dim updateqry As String = "UPDATE users SET access='LOGOUT' WHERE uname='" + uname + "'"
            Dim updatecmd As New OleDbCommand
            With updatecmd
                .CommandText = updateqry
                .Connection = connect
                .ExecuteNonQuery()
            End With

            frmLogin.Show()
            Me.Dispose()
            closeconnection()
        End If
    End Sub

    Private Sub frmuserENG_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TimerDate.Start()
        hidegb()
        gbHome.Dock = DockStyle.Fill
        gbHome.Show()
        enablebtns()
        btnHome.Enabled = False
        openconnection()
        viewnews()
    End Sub

#End Region

#Region "Time, Date and Zone"
    Private Sub TimerDate_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerDate.Tick
        lblTime.Text = TimeOfDay
        lblDate.Text = Today.Date.ToString("dddd, dd MMMM yyyy")
        lblZone.Text = TimeZone.CurrentTimeZone.StandardName
    End Sub
#End Region

#Region "Hide all gb"
    Private Sub hidegb()
        gbHome.Hide()
        gbSale.Hide()
        gbViewstock.Hide()
        gbSetting.Hide()
        gbHelp.Hide()
    End Sub
#End Region

#Region "Enable all Buttons"
    Private Sub enablebtns()
        btnHome.Enabled = True
        btnSales.Enabled = True
        btnViewstock.Enabled = True
        btnSettings.Enabled = True
        btnHelp.Enabled = True
    End Sub
#End Region

#Region "notification icon"
    Private Sub frmuserENG_Move(sender As Object, e As System.EventArgs) Handles Me.Move
        If Me.WindowState = FormWindowState.Minimized Then
            Me.Hide()
            niSIS.ShowBalloonTip(4600, "Stationary Information System", "Stationary Information System have been minimized. Click this icon to maximise it", ToolTipIcon.Info)
        End If
    End Sub

    Private Sub niSIS_MouseDoubleClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles niSIS.MouseDoubleClick
        Me.Show()
        Me.WindowState = FormWindowState.Normal
    End Sub
#End Region

End Class