Saturday, November 5, 2016

Address Book in C# and Microsoft SQL Server

In this article I would like to share with you a sample program that shows how to create a CRUD application in C# and Microsoft SQL Server I called this program Address Book that save, update, delete and view user records using data view grid. I hope you will find my work useful I work hard in this sample program this is my first time to create my own database application using C# and Microsoft SQL Server 2008 R2.  I am using Visual Studio 2012 in this application. Thank you.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com. 

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 and Procedures To Follow


Program Listing

using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace addressbook
{
    public partial class Form1 : Form
    {
        SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=user;Integrated Security=true;");
        SqlCommand cmd;
        SqlDataAdapter adapt;
      
        int ID = 0;

        public Form1()
        {
            InitializeComponent();
            DisplayData();

        }

        private void DisplayData()
        {
            con.Open();
            DataTable dt = new DataTable();
            adapt = new SqlDataAdapter("SELECT * FROM tbl_users", con);
            adapt.Fill(dt);
            dataGridView1.DataSource = dt;
            con.Close();
        }

        private void ClearData()
        {
            txt_lastname.Text = "";
            txt_firstname.Text = "";
            txt_home.Text = "";
            txt_mobile.Text = "";
            txt_telephone.Text = "";
            txt_email.Text = "";
            ID = 0;
        }


      
        private void btn_quit_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Do you want to exit?", "My Application",
        MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        == DialogResult.Yes)
            {
                Application.Exit();
            }
            else
            {
                txt_lastname.Focus();
            }
        }

        private void btn_about_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Written By: Mr. Jake R. Pomperada, MAED-IT      2016",
            "About This Program", MessageBoxButtons.OK,
          MessageBoxIcon.Information);
            txt_lastname.Focus();
        }

        private void btn_save_Click(object sender, EventArgs e)
        {
            if (txt_lastname.Text != "" && txt_firstname.Text != "" 
                && txt_home.Text != "" && txt_mobile.Text != "" 
                && txt_telephone.Text != "" && txt_email.Text != "")
              {
                cmd = new SqlCommand("INSERT INTO tbl_users(lastname,firstname,address,mobile,telephone,email) VALUES(@lastname,@firstname,@address,@mobile,@telephone,@email)", con);
                con.Open();
                cmd.Parameters.AddWithValue("@lastname", txt_lastname.Text.ToUpper());
                cmd.Parameters.AddWithValue("@firstname", txt_firstname.Text.ToUpper());
                cmd.Parameters.AddWithValue("@address", txt_home.Text.ToUpper());
                cmd.Parameters.AddWithValue("@mobile", txt_mobile.Text.ToUpper());
                cmd.Parameters.AddWithValue("@telephone", txt_telephone.Text.ToUpper());
                cmd.Parameters.AddWithValue("@email", txt_email.Text.ToLower());
                cmd.ExecuteNonQuery();
                con.Close();
                MessageBox.Show("Record Inserted Successfully");
                DisplayData();
                ClearData();
            }
            else
            {
                MessageBox.Show("Please Provide Details!");
            }
        }

        private void btn_update_Click(object sender, EventArgs e)
        {
            if (txt_lastname.Text != "" && txt_firstname.Text != ""
                           && txt_home.Text != "" && txt_mobile.Text != ""
                           && txt_telephone.Text != "" && txt_email.Text != "")
            {
                cmd = new SqlCommand("UPDATE tbl_users SET lastname=@lastname, firstname=@firstname,address=@address,mobile=@mobile,telephone=@telephone,email=@email WHERE id=@id", con);
                con.Open();
                cmd.Parameters.AddWithValue("@id", ID);
                cmd.Parameters.AddWithValue("@lastname", txt_lastname.Text.ToUpper());
                cmd.Parameters.AddWithValue("@firstname", txt_firstname.Text.ToUpper());
                cmd.Parameters.AddWithValue("@address", txt_home.Text.ToUpper());
                cmd.Parameters.AddWithValue("@mobile", txt_mobile.Text.ToUpper());
                cmd.Parameters.AddWithValue("@telephone", txt_telephone.Text.ToUpper());
                cmd.Parameters.AddWithValue("@email", txt_email.Text.ToLower());
                cmd.ExecuteNonQuery();
                con.Close();
                MessageBox.Show("Record Updated Successfully");
                DisplayData();
                ClearData();
            }
            else
            {
                MessageBox.Show("Please Provide Details!");
            }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            ID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
            txt_lastname.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
            txt_firstname.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
            txt_home.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
            txt_mobile.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
            txt_telephone.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
            txt_email.Text = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();   
        }

        private void btn_new_Click(object sender, EventArgs e)
        {
            txt_lastname.Text = "";
            txt_firstname.Text = "";
            txt_home.Text = "";
            txt_mobile.Text = "";
            txt_telephone.Text = "";
            txt_email.Text = "";
            txt_lastname.Focus();
        }

        private void btn_delete_Click(object sender, EventArgs e)
        {
            if (ID != 0)
            {
                cmd = new SqlCommand("DELETE tbl_users WHERE id=@id", con);
                con.Open();
                cmd.Parameters.AddWithValue("@id", ID);
                cmd.ExecuteNonQuery();
                con.Close();
                MessageBox.Show("Record Deleted Successfully!");
                DisplayData();
                ClearData();
            }
            else
            {
                MessageBox.Show("Please Select Record to Delete");
            }
        }
    }
}


SQL Dumb File

USE [user]
GO
/****** Object:  Table [dbo].[tbl_users]    Script Date: 11/05/2016 15:49:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tbl_users](
[id] [int] IDENTITY(1,1) NOT NULL,
[lastname] [nchar](100) NULL,
[firstname] [nchar](100) NULL,
[address] [nchar](200) NULL,
[mobile] [nchar](15) NULL,
[telephone] [nchar](15) NULL,
[email] [nchar](100) NULL,
 CONSTRAINT [PK_tbl_users] PRIMARY KEY CLUSTERED 
(
[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[tbl_users] ON
INSERT [dbo].[tbl_users] ([id], [lastname], [firstname], [address], [mobile], [telephone], [email]) VALUES (4, N'POMPERADA                                                                                           ', N'JACOB                                                                                               ', N'ERORECO SUBD, BACOLOD CITY                                                                                                                                                                              ', N'09173084360    ', N'4335675        ', N'jacob_pomperada@gmail.com                                                                           ')
INSERT [dbo].[tbl_users] ([id], [lastname], [firstname], [address], [mobile], [telephone], [email]) VALUES (5, N'BRYANT                                                                                              ', N'KOBE                                                                                                ', N'LOS ANGELES CALIFORNIA, USA                                                                                                                                                                             ', N'1234567890     ', N'4563423        ', N'kobe@la_lakers.com                                                                                  ')
INSERT [dbo].[tbl_users] ([id], [lastname], [firstname], [address], [mobile], [telephone], [email]) VALUES (6, N'POMPERADA                                                                                           ', N'ALLIE                                                                                               ', N'BACOLOD CITY                                                                                                                                                                                            ', N'0912345623     ', N'4335675        ', N'allie_pomperada@yahoo.com.ph                                                                        ')
INSERT [dbo].[tbl_users] ([id], [lastname], [firstname], [address], [mobile], [telephone], [email]) VALUES (7, N'POMPERADA                                                                                           ', N'JULIANNA RAE                                                                                        ', N'BACOLOD CITY, NEGROS OCCIDENTAL                                                                                                                                                                         ', N'121212121212   ', N'4335081        ', N'iya_pomperada@gmail.com                                                                             ')
INSERT [dbo].[tbl_users] ([id], [lastname], [firstname], [address], [mobile], [telephone], [email]) VALUES (8, N'GATES                                                                                               ', N'BILL                                                                                                ', N'ONE MICROSOFT WAY, USA                                                                                                                                                                                  ', N'1212123434343  ', N'34343434       ', N'bill_gates@microsoft.com                                                                            ')
INSERT [dbo].[tbl_users] ([id], [lastname], [firstname], [address], [mobile], [telephone], [email]) VALUES (10, N'POMPERADA                                                                                           ', N'JAKE                                                                                                ', N'ALIJIS BACOLOD CITY                                                                                                                                                                                     ', N'09173084360    ', N'4335675        ', N'jakerpomperada@yahoo.com                                                                            ')
SET IDENTITY_INSERT [dbo].[tbl_users] OFF


Friday, November 4, 2016

Student Grade Solver Using Two Dimensional Array in C++

Here is a simple program that I wrote using C++ that will compute and evaluate the grades of the students using two dimensional array in C++ as our data structure. I hope you will find my work useful I am using Dev C++ as my C++ compiler and CodeBlocks as my C++ text editor in writing this program. Thank you.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com. 

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

My mobile number here in the Philippines is 09173084360.



Program Listing

#include <iostream>
#include <iomanip>

using namespace std;

main() {
     int grades[5][1],pass=0,failed=0,out_range=0;
     int row=0, col=0;
     string remarks;
     char letter_grade;

     cout << "\t Grades Evaluator Version 1.0";
     cout << "\n\n Created By: Mr. Jake Rodriguez Pomperada,MAED-IT";
     cout << "\n\n";
     
     for ( row=0; row < 5; row++) {
       for  (col=0; col < 1; col++) {
         cout << "Enter grade : " ;
         cin >> grades[row][col];
     }
}
    
  // Code to check for remarks
cout <<"\n" << setw(5) << "GRADES" <<
               setw(7) << " EQUIV " <<
               setw(10) << "REMARKS";
    cout << "\n\n";

     for ( row=0; row < 5; row++) {
       for (col=0; col < 1; col++) {

         if (grades[row][col] >= 75) {
             remarks = "PASSED";
             pass++;
         }
         else if (grades[row][col] < 50)
         {
           remarks= " Error Out of Range ";
           out_range++;
         }

         else  if (grades[row][col] < 75){
                 remarks = "FAILED";
                 failed++;
         }
 


  // Letter Grade Equivalent

     if (grades[row][col] >= 90 &&  grades[row][col] <= 100  ) {
           letter_grade = 'A';
         }
         else if (grades[row][col] >= 80 && grades[row][col] <= 89  ) {
           letter_grade = 'B';
         }
         else if (grades[row][col] >= 70 && grades[row][col] <= 79  ) {
           letter_grade = 'C';
         }
         else if (grades[row][col] >= 60 && grades[row][col] <= 69  ) {
           letter_grade = 'D';
         }
        else if (grades[row][col] >= 50 && grades[row][col] <= 59  ) {
           letter_grade = 'F';
         }
        else if (grades[row][col] < 50) {
            letter_grade = 'X';

         }

        cout <<"\n" << setw(5) << grades[row][col]
              << setw(6) << letter_grade << setw(12)
              << remarks;  
     } 
 }
      

     cout << "\n\n";
     cout << "\nNumber of Passed Grades " << pass << ".";
     cout << "\nNumber of Failed Grades " << failed << ".";
     cout << "\nNumber of Out of Range Grades "<< out_range << ".";
     cout << "\n\n";
     system("PAUSE"); 
 
}

Highest and Lowest Numbers Using Two Dimensional Array in C++

This sample program that I wrote a long time ago will ask the user to give a series of numbers and then our program will check which of the given number by our user is the highest and lowest using two dimensional array in C++ programming language. I hope you will find my work useful. Thank you.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com. 

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

My mobile number here in the Philippines is 09173084360.


Program Listing

/* Checks Highest and Lowest From 10 numbers*/
// Date Modified : November 29, 2009
// Sunday

// Created By: Mr. Jake Rodriguez Pomperada, MAED-Instructioanl Technology
// Email Address : jakerpomperada@yahoo.com

#include <iostream>
#include <cctype>

using namespace std;

 main()
{
char reply;

do {
int values[5][2],high=0,low=0, sum=0;

cout<<"\n\n";
cout<<"\t\tHighest and Lowest Number Checker 3.0";
cout<<"\n\n\t      Created By: Mr. Jake R. Pomperada,MAED-IT";
cout<<"\n\n";


       for (int row=0; row <5; row++) {
         for ( int col=0; col <2; col++) {
{

cout<<"Enter a value : ";

cin>>values[row] [col];
     sum+=values[row][col];
}
     }

high=values[0][0];
  for (int row=0; row <5; row++) {
         for ( int col=0; col <2; col++) {

if(high<values[row][col])
{
high=values[row][col];
}
}
  }
low=high;

for (int row=0; row <5; row++) {
         for (int col=0; col <2; col++) {

if(low>values[row][col])
{
low=values[row][col];
}
}

     }


} // check for highest value
cout<<"\nThe highest number is = "<<high;
cout<<"\n";
cout<<"The lowest number is = "<<low;
cout<<"\n";
cout<<"The Total Sum of Values is = "<<sum;
cout<<"\n\n";
cout<<"Do You want to Continue y/n :=> ";
cin>>reply;

} while (toupper(reply) == 'Y');
if (toupper(reply)== 'N')
{
      cout << "\n\n";
      cout << "\t Thank You for Using This Program";
      cout << "\n\n";
}
 system("PAUSE");
}

Product Price Solver Using Two Dimensional Array

This simple program will solve the price of a certain product using two dimensional array as our data structure in C++. I hope you will find my work useful in learning C++ programming. Thank you.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com. 

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

My mobile number here in the Philippines is 09173084360.


Program Listing

#include <iostream>

using namespace std;

main() {
    string product[4] = {"Nido","Bear Brand",
                       "Anchor Milk", "Milo"};
    int price[4][1];
    int solve=0;
    int add=0,change=0, pay=0;
    cout << "Product Price Solver";
     cout << "\n\n";
     for (int a=0; a<4; a++) {
       for (int b=0; b<1; b++)
       {

        cout << "Enter " <<product[a]
         << " price : ";
        cin >> price[a][b];
        add+=price[a][b];
       }
     solve= add;
     }
    cout << "\n\n";
    cout << "Total Amount Cost :=>" << solve;
    cout << "\n\n";
    cout << "Amount Payed : ";
    cin >> pay;
    change = (pay-solve);
    cout << "Your change is P " << change
        << ".";
    cout << "\n\n";
    system("pause");
 }

Running Sum Using Two Dimensional Array in C++

A very simple program that I wrote using C++ that shows how to use two dimensional array. What the program does it accept a series of number provided by the user and then it sum up the values dynamically. The program code is very easy to understand and very short. I hope you will find my work useful. Thank you.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com. 

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

My mobile number here in the Philippines is 09173084360.



Program Listing

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int values[3][2], running_sum=0;
    
     cout << "\t\t RUNNING SUM VERSION 1.0";
     cout << "\n";
     cout << "\tCreated By: Mr. Jake R. Pomperada, MAED-IT"; 
          cout << "\n";
      for (int row=0; row< 3; row++) {
           for (int col=0; col< 2; col++) {

            cout << "\nEnter a Number :=> ";
            cin >> values[row][col];
          
            running_sum+=values[row][col];
            cout << "\nThe running sum is " <<       
                    running_sum << ".";
             }
             }
         cout << "\n\n";                     
    system("PAUSE");
    return EXIT_SUCCESS;
}

Saturday, October 29, 2016

OOP CRUD in PHP and MySQL

A simple object oriented programming CRUD application that I wrote a very long time ago in PHP and MySQL. I hope you will find my work useful. Thank you.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com. 

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




Time Monitoring System System in PHP and MySQL

A very simple time monitoring system in PHP and MySQL that I wrote a long time ago to monitor daily attendance of the employees in the company. 

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com. 

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

My mobile number here in the Philippines is 09173084360.





Multiplication Table in Java

One of my friend and fellow software engineer named Mr. Alfel Benvic G. Go write and share to us his version of multiplication table using Java programming language. He is using NetBeans as his text editor to wrote this program. I am very grateful and thankful because he share his talent with this program.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com. 

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

My mobile number here in the Philippines is 09173084360.





Thursday, October 27, 2016

Summation in C#

Here is a very simple program that I wrote using C# programming language using console application that will ask the user to give a series of numbers and then it will perform summation of values based on the given  number by the user. The code is very short and easy to understand.  Thank you.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com. 

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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace running_sum
{
    class running_sum
    {
        static void Main(string[] args)
        {
            int[] values = new int[6];
            int sum = 0;
            Console.Write("Running Sum Program");
            Console.Write("\n\n");

            for (int a = 1; a <= 5; a++)
            {
                Console.Write("\n");
                Console.Write("Enter value in item no. {0} : ", a);
                values[a] = Convert.ToInt32(Console.ReadLine());
                sum += values[a];
                Console.Write("\n");
                Console.Write("The running sum of values is {0}.", sum);
                Console.Write("\n");
            }
             
            Console.Write("\n\n");
            Console.Write("End of Program.");
            Console.Write("\n\n");
            Console.ReadLine();
        }
    }
}


Year Level Checker Using Switch Statement in C#

Here is a simple program that I wrote using C# programming language that will ask the user's name and year level using Switch statement in C#. The code is very easy to understand and use.  Thank you.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com. 

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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace year_level
{
    class year_level
    {
        static void Main(string[] args)
        {
            int year_level = 0;
            string user;

            Console.Clear();
            Console.Write("\n\n");
            Console.Write("Year Level Checker Using Switch Statement ");
            Console.Write("\n\n");
            Console.Write("What is your name     : ");
            user = Console.ReadLine();
            Console.Write("\n\n");
            Console.Write("Enter Your Year Level : ");
            year_level = Convert.ToInt32(Console.ReadLine());
            Console.Write("\n\n");

            switch (year_level)
            {

                case 1: Console.Write("Hello {0} you are belong to Freshmen. ", user);
                    break;

                case 2: Console.Write("Hello {0} you are belong to Sophomore. ", user);
                    break;

                case 3: Console.Write("Hello {0} you are belong to Juniors. ", user);
                    break;

                case 4: Console.Write("Hello {0} you are belong to Seniors. ", user);
                    break;
             
                default: Console.Write("Invalid Year Level. Please Try Again.");
                    break;
            }
            Console.Write("\n\n");
            Console.Write("End of Program.");
            Console.Write("\n\n");
            Console.ReadLine();
        }
    }
}