Monday, June 26, 2017

Addition of Two Numbers Using Model View Controller in PHP

A program that demonstrate how to use the MVC or Model View Controller in PHP to add the sum of two numbers the code is very short and easy to understand. Thank you for visiting the site.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

<?php
/**
 * Created by PhpStorm.
 * User: Jacob Pomperada
 * Date: 6/26/2017
 * Time: 8:24 AM
 */


class Model {
    public $a;
    public $b;

    public function __construct() {
        $this->a=5;
        $this->b=5;
    }
}

class View {
    private $model;

    public function __construct(Model $model) {
        $this->model = $model;
    }

    public function output() {
        echo "<body bgcolor='lightgreen'>";
        echo "<font-face='arial'>";
        echo "<br><br>";
        echo "<span style=\"font-size: 20px !important; font-weight:bold; font-family: arial; color: blue;\">";
        echo "Sum of Two Numbers Using Model View Controller Concepts in PHP </span>";
        echo "<br><br><br>";

        $sum = ($this->model->a + $this->model->b);

        $c = $this->model->a;
        $d = $this->model->b;

        echo "<span style=\"font-size: 20px !important; font-family: arial; font-weight:bold; color: blue;\">";
        echo " The sum of $c and $c is $sum. </span>";
        echo "</font></body>";
    }

}

class Controller {
    private $model;

    public function __construct(Model $model) {
        $this->model = $model;
    }

}

$model = new Model();
$controller = new Controller($model);
$view = new View($model);
if (isset($_GET['action'])) $controller->{$_GET['action']}();
echo $view->output();

?>

Hello World Using Model View Controller Concept in PHP

Here is a program that I wrote using PHP to demonstrate the concept of MVC or Model View Controller this program will display hello world message on the screen. The code is very easy to understand and use. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

hello.php

<?php

class Model {
    public $text;

    public function __construct() {
        $this->text = 'Click Me';
    }
}

class View {
    private $model;

    public function __construct(Model $model) {
        $this->model = $model;
    }

    public function output() {
        echo "<body bgcolor='lightgreen'>";
        echo "<font-face='arial'>";
        echo "<br><br>";
        echo "<h1> Hello World Using Model View Controller Concepts in PHP </h1>";
        echo "<br>";
        return '<a href="demo.php?action=pressme">' . $this->model->text . '</a>';
        echo "</font></body>";
    }

}

class Controller {
    private $model;

    public function __construct(Model $model) {
        $this->model = $model;
    }

    public function pressme() {
        $this->model->text = 'Hello World Mr. Jake Pomperada !!!!';
    }
}


$model = new Model();
$controller = new Controller($model);
$view = new View($model);
if (isset($_GET['action'])) $controller->{$_GET['action']}();
echo $view->output();
?>


Saturday, June 24, 2017

Viewing of User Profile Using Bootstrap, MySQL and PHP

Here is a sample program that I wrote using Twitter Bootstrap, PHP and MySQL which allows that user to view the profile of the user in a company for example the code is very easy to understand and user. I hope you will find my work useful thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.










Sample Program Output






Sunday, June 18, 2017

Address Book in Visual Basic NET and MS Access

Here is my first time to create a complete CRUD application written in Microsoft Visual Basic NET and Microsoft Access I called this program Address Book application to store information and contact numbers of the persons.  The code is very easy to understand and use. I use Microsoft Visual Studio 2012 Ultimate Edition and Microsoft Access 2010.  I hope you will find my work useful. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.





Sample Program Output


Program Listing

Imports System.Data.OleDb
Imports System.IO

Public Class Form1

    Dim strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\vbnet_address\addressbook.accdb;Persist Security Info=False;"
    Dim con As New OleDbConnection
    Dim cmd As New OleDbCommand
    Dim da As New OleDbDataAdapter
    Dim dt As New DataTable
    Dim save_tag As String

    Sub Fill_Grid(grid As Windows.Forms.DataGridView)
        Dim x As Integer

        If grid.Rows.Count > 0 Then
            While x < grid.Rows.Count
                grid.Rows.RemoveAt(x)
            End While
        End If

        With grid
            .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
            .RowHeadersVisible = False
            .SelectionMode = DataGridViewSelectionMode.FullRowSelect
        End With

        con.ConnectionString = strConn
        con.Open()

        With cmd
            .Connection = con
            .CommandType = CommandType.Text
            .CommandText = "SELECT * FROM addressbook"
        End With
        da.SelectCommand = cmd
        grid.DataSource = dt
        da.Fill(dt)

        For i As Integer = 0 To 0
            grid.Columns(i).Visible = False
        Next
        grid.Columns(0).Visible = False

        con.Dispose()
        con.Close()

    End Sub
    Sub save(ByVal tag As String)

        Dim cmdtxt As String = Nothing
        If tag = "new" Then
            cmdtxt = "INSERT INTO addressbook ([personsname], [address], [telephone], [mobile], [email]) " & _
                     "Values('" & UCase(TextBox1.Text) & "','" & UCase(TextBox2.Text) & "','" & UCase(TextBox3.Text) & "','" & UCase(TextBox4.Text) & "','" & LCase(TextBox5.Text) & "' ) "

        ElseIf tag = "edit" Then
            cmdtxt = "UPDATE addressbook SET " & _
                     "[personsname] = '" & UCase(TextBox1.Text.ToString) & "',[address] = '" & UCase(TextBox2.Text) & "', [telephone] = '" & UCase(TextBox3.Text) & "' , [mobile] ='" & UCase(TextBox4.Text) & "' ,[email]='" & LCase(TextBox5.Text) & "' " & _
                     "WHERE ID = " & TextBox6.Text & ""
        End If

        Try

            con.ConnectionString = strConn
            con.Open()

            With cmd
                .Connection = con
                .CommandType = CommandType.Text
                .CommandText = cmdtxt
            End With

            cmd.ExecuteNonQuery()

        Catch ex As Exception
            MsgBox(ex.Message, vbCritical)
        Finally
            con.Dispose()
            con.Close()
        End Try



    End Sub

    Sub delete(ByVal id As Integer)
        Dim cmdtxt As String = Nothing

        cmdtxt = "DELETE FROM addressbook WHERE ID = " & id & ""

        Try
            con.ConnectionString = strConn
            con.Open()

            With cmd
                .Connection = con
                .CommandType = CommandType.Text
                .CommandText = cmdtxt
            End With

            cmd.ExecuteNonQuery()

        Catch ex As Exception
            MsgBox(ex.Message, vbCritical)
        Finally
            con.Dispose()
            con.Close()
        End Try
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label8.Text = DateTime.Now.ToString()
        TextBox6.Visible = False
        save_tag = "new"
        Fill_Grid(DataGridView1)
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TextBox1.Text = String.Empty
        TextBox2.Text = String.Empty
        TextBox3.Text = String.Empty
        TextBox4.Text = String.Empty
        TextBox5.Text = String.Empty
        TextBox1.Focus()

        save_tag = "new"
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        save(save_tag)
        Button1.PerformClick()
        Fill_Grid(DataGridView1)

    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim id As Integer
        id = Val(TextBox6.Text)
        delete(id)
        Button1.PerformClick()
        Fill_Grid(DataGridView1)
    End Sub

    Private Sub DataGridView1_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
        TextBox1.Text = DataGridView1.Rows(e.RowIndex).Cells(1).Value.ToString
        TextBox2.Text = DataGridView1.Rows(e.RowIndex).Cells(2).Value.ToString
        TextBox3.Text = DataGridView1.Rows(e.RowIndex).Cells(3).Value.ToString
        TextBox4.Text = DataGridView1.Rows(e.RowIndex).Cells(4).Value.ToString
        TextBox5.Text = DataGridView1.Rows(e.RowIndex).Cells(5).Value.ToString
        TextBox6.Text = DataGridView1.Rows(e.RowIndex).Cells(0).Value.ToString

        save_tag = "edit"

    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Button1.PerformClick()
    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        If MsgBox("Are you sure you want to quit?", MsgBoxStyle.YesNo Or MsgBoxStyle.DefaultButton2, "Close application") = Windows.Forms.DialogResult.Yes Then
            Me.Close()
        End If
        TextBox1.Focus()
    End Sub
End Class





Saturday, June 17, 2017

Login System in Microsoft Visual Basic NET and Microsoft Access

Hi there in this article I started learning how to create a login system using Microsoft Visual Basic NET and Microsoft Access as my database. The code will ask the user to give the username and password and then our program will check if the username and password is really existing in our database if it is true it will display the second windows and greet the user. If the username and password does not exist in the database it will not allow the user to enter in the system. The code is very easy to understand and use. I use Microsoft Visual Studio 2012 Ultimate Edition and Microsoft Access 2010 to write this sample login system. I hope you will find my work useful. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.









Sample Program Output


Program Listing

' Login System in Visual Basic NET
' Written By Mr. Jake R. Pomperada, MAED-IT
' Date: June 17, 2017 Saturday
' Tool : Microsoft Visual Studio Ultimate Edition 2012
' Country of Origin :  Mandaluyong City, Metro Manila Philippines

Imports System.Data.OleDb


Public Class Form1

    Dim provider As String
    Dim dataFile As String
    Dim FirstName As String
    Dim LastName As String
    Dim connString As String
    Dim myConnection As OleDbConnection = New OleDbConnection


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = "
        dataFile = "D:\login_vbnet\login.accdb"


        connString = provider & dataFile

        myConnection.ConnectionString = connString

        myConnection.Open()


        Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [login] WHERE [username] = '" & TextBox1.Text & "' AND [password] = '" & TextBox2.Text & "'", myConnection)

        Dim dr As OleDbDataReader = cmd.ExecuteReader


        Dim userFound As Boolean = False

        While dr.Read

            userFound = True

            FirstName = dr("firstname").ToString

            LastName = dr("lastname").ToString

        End While


        If userFound = True Then

            Form2.Show()

            Form2.Label1.Text = "Welcome " & FirstName & " " & LastName

        Else

            MsgBox("Sorry,username or password not found ", MsgBoxStyle.OkOnly, "Invalid Login")

        End If

        myConnection.Close()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        End
    End Sub
End Class





Wednesday, June 14, 2017

Roman Numeral To Decimal Converter in Visual Basic 6

Here is a sample program that I wrote that will ask the user to give a value in Roman Numeral and then it will be converted into its Decimal Equivalent in Visual Basic 6.  Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.







Sample Program Output


Program Listing

Option Explicit
Dim Rm As String

Public Function ConvertToDecimal(Rm) As Integer
Dim TB
Dim Arab As Integer
Dim i As Byte, A As Integer, Utb As Integer

ReDim TB(0)
    i = 1: Utb = 1
    Rm = Replace(Rm, " ", "") '
    Rm = UCase(Rm) '
    While i <= Len(Rm)
        
        ReDim Preserve TB(Utb)
        A = NBlettre(i)
        TB(Utb) = A * ValueLetters(Mid(Rm, i, 1))
        Debug.Print TB(Utb)
        i = i + A
        Utb = Utb + 1
    Wend
    ReDim Preserve TB(Utb): i = 1
    While i < UBound(TB)
        If TB(i) < TB(i + 1) Then
             Arab = Arab + TB(i + 1) - TB(i)
            i = i + 2
        Else
            Arab = Arab + TB(i)
            i = i + 1
        End If
        Debug.Print Arab
    Wend
    ConvertToDecimal = Arab
End Function
Private Function NBlettre(Deb As Byte) As Byte
Dim i As Integer, L As String
    NBlettre = 1
    L = Mid(Rm, Deb, 1)
    For i = Deb + 1 To Len(Rm)
        If Mid(Rm, i, 1) = L Then
            NBlettre = NBlettre + 1
        Else
            Exit Function
        End If
    Next
End Function

Private Function ValueLetters(L As String) As Integer
Dim Romain, Arabe, i As Byte
    Romain = Array("I", "V", "X", "L", "C", "D", "M")
    Arabe = Array(1, 5, 10, 50, 100, 500, 1000)
    For i = 0 To 6
        If L = Romain(i) Then
            ValueLetters = Arabe(i)
            Exit Function
        End If
    Next i
End Function

Private Sub Command1_Click()
Label2.Caption = "The Decimal Equivalent of " & Text1.Text & " is " & ConvertToDecimal(Text1.Text) & "."
End Sub

Private Sub Command2_Click()
Text1.Text = ""
Label2.Caption = ""
Text1.SetFocus
End Sub

Private Sub Command3_Click()
End
End Sub


Decimal To Roman Numeral in VB.NET

Here a sample program that I wrote in VB.NET to accept a decimal input value and then it will convert it to roman numeral equivalent the code is very simple and easy to understand. I hope you will learn from it. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.





Sample Program Output


Program Listing

Public Class Form1

    Private Function ConvertToRoman(ByVal input As Integer) As String
        Dim numeral As String = String.Empty

        If input < 1 OrElse input > 4000 Then

            Throw New ArgumentOutOfRangeException("input", input.ToString, "Value must be greater than 0 and less than 4,001.")
        Else

            Dim numeralDic As Dictionary(Of Integer, String) = New Dictionary(Of Integer, String)
            With numeralDic
                .Add(1, "I")
                .Add(4, "IV")
                .Add(5, "V")
                .Add(9, "IX")
                .Add(10, "X")
                .Add(40, "XL")
                .Add(50, "L")
                .Add(90, "XC")
                .Add(100, "C")
                .Add(400, "CD")
                .Add(500, "D")
                .Add(900, "CM")
            End With


            For x As Integer = 0 To input.ToString.Length - 1
                Dim currentValue As Integer = CInt(input.ToString.Substring(x, 1))

                If x = input.ToString.Length - 1 Then

                    If numeralDic.ContainsKey(currentValue) Then

                        numeral &= numeralDic(currentValue)
                    ElseIf currentValue < 4 Then
                    
                        For y As Integer = 1 To currentValue
                            numeral &= "I"
                        Next
                    ElseIf currentValue > 5 Then

                        numeral &= "V"
                        For y As Integer = 6 To currentValue
                            numeral &= "I"
                        Next
                    End If
                ElseIf x = input.ToString.Length - 2 Then
                   
                    currentValue = currentValue * 10
                    If numeralDic.ContainsKey(currentValue) Then
                        numeral &= numeralDic(currentValue)
                    ElseIf currentValue < 4 Then
                        For y As Integer = 1 To currentValue
                            numeral &= "X"
                        Next
                    ElseIf currentValue > 5 Then
                        numeral &= "L"
                        For y As Integer = 6 To currentValue
                            numeral &= "X"
                        Next
                    End If
                ElseIf x = input.ToString.Length - 3 Then
                    currentValue = currentValue * 100
                    If numeralDic.ContainsKey(currentValue) Then
                        numeral &= numeralDic(currentValue)
                    ElseIf currentValue < 4 Then
                        For y As Integer = 1 To currentValue
                            numeral &= "C"
                        Next
                    ElseIf currentValue > 5 Then
                        numeral &= "D"
                        For y As Integer = 6 To currentValue
                            numeral &= "C"
                        Next
                    End If
                Else

                    For y As Integer = 1 To currentValue
                        numeral &= "M"
                    Next
                End If
            Next
        End If


        Return numeral
    End Function
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        End
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label3.Text = "The Roman Numeral Equivalent of " & Val(TextBox1.Text) & " is " & ConvertToRoman(Val(TextBox1.Text)) & "."


    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = ""
        Label3.Text = ""
        TextBox1.Focus()

    End Sub
End Class