NW Lab Experiments
-
Upload
bala-subramanian -
Category
Documents
-
view
227 -
download
0
Transcript of NW Lab Experiments
-
8/6/2019 NW Lab Experiments
1/52
Ex. No. 1
Implementation of TCP Using SocketsDate :
Aim :
Write a Java program to Implementation of TCP Sockets
Program:
tcpclient.java
import java.io.*;
import java.net.*;
class tcpclient
{
public static void main(String s[]) throws Exception
{
Socket soc=new Socket(InetAddress.getLocalHost(),5000);
OutputStream os=soc.getOutputStream();
DataOutputStream dos=new DataOutputStream(os);
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
InputStream is=soc.getInputStream();
DataInputStream dis=new DataInputStream(is);
while(true)
{
System.out.println("Send : ");
4
-
8/6/2019 NW Lab Experiments
2/52
dos.writeUTF(br.readLine());
System.out.println("Received: "+dis.readUTF(dis));
}
}
}
tcpserver.java
import java.io.*;
import java.net.*;
class tcpserver
{
public static void main(String s[]) throws Exception
{
ServerSocket sersoc=new ServerSocket(5000);
Socket soc=sersoc.accept();
InputStream is=soc.getInputStream();
DataInputStream dis=new DataInputStream(is);
OutputStream os=soc.getOutputStream();
DataOutputStream dos=new DataOutputStream(os);
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
while(true)
{
System.out.println("Received: "+dis.readUTF(dis));
System.out.println("Send : ");
dos.writeUTF(br.readLine());
}}}
5
-
8/6/2019 NW Lab Experiments
3/52
Output :
tcp server:
C:\Program Files\Java\jdk1.6.0\bin>javac tcpserver.java
C:\Program Files\Java\jdk1.6.0\bin>java tcpserver
Received: mohamed
Send :
Sathak
tcp client:
C:\Program Files\Java\jdk1.6.0\bin>javac tcpclient.java
C:\Program Files\Java\jdk1.6.0\bin>java tcpclient
Send :
mohamed
Received: sathak
Send :
Result :
Thus the given java program was executed and output was verified.
6
-
8/6/2019 NW Lab Experiments
4/52
Ex. No. 2
Implementation of File TransferDate :
Aim :Write a Java program to Implementation of file transfer
Program:
ftpclient.java
import java.io.*;
import java.net.*;
public class ftpc
{
public static int serport=1666;
public static int clientport=1999;
public static DatagramSocket dss;
public static byte buff[]=new byte[1024];public static byte buff1[]= new byte[5000];
public static DatagramPacket dp,dp1;
public static void client() throws Exception
{
int pos=0;
String msg=" ";
System.out.println("Client started");
while(true)
{
7
-
8/6/2019 NW Lab Experiments
5/52
int c=System.in.read();
switch(c)
{
case '1':
System.out.println("Client quits");
return;
case '\n':
String bye=new String(buff);
InetAddress addr=InetAddress.getByName("localhost");
System.out.println(addr);
while(true)
{
dss.send(new DatagramPacket(buff,pos,addr,serport));
dp1=new DatagramPacket(buff1,buff1.length);
dss.receive(dp1);
System.out.println("File Length is"+dp1.getLength());
if(dp1.getLength()>1)
{
for(int j=0;j
-
8/6/2019 NW Lab Experiments
6/52
break;
}
case '\r':
break;
default:
buff[pos++]=(byte)c;
}
}
}
public static void main(String args[]) throws Exception
{
dss=new DatagramSocket(clientport);
client();
}
}
ftpserver.java
import java.io.*;
import java.net.*;
public class ftpserver
{
public static int serport=1666;
public static int clientport=1999;
public static DatagramSocket dss;
public static byte buff[]=new byte[1024];
public static byte buff1[]=new byte[5000];
9
-
8/6/2019 NW Lab Experiments
7/52
public static DatagramPacket dp,dp1;
public static void server() throws Exception
{
InetAddress addr=InetAddress.getByName("localhost");
System.out.println(addr);
while(true)
{
try
{
DatagramPacket dp=new DatagramPacket (buff,buff.length);
dss.receive(dp);
String str=new String(dp.getData(),0,dp.getLength());
if(str.equals("bye"))
{
System.out.println("Server quits");
System.exit(0);
}
System.out.println("Filename server received "+str);
InputStream fis= new FileInputStream(str);
int size=fis.available();
System.out.println(size);
for(int i=0;i
-
8/6/2019 NW Lab Experiments
8/52
System.err.println(fe);
dss.send(new DatagramPacket(buff1,0,addr,clientport));
}
}
}
public static void main(String args[])throws Exception
{
System.out.println("Server started");
dss=new DatagramSocket(serport);
server();
}
}
11
-
8/6/2019 NW Lab Experiments
9/52
Output :
ftp client:
C:\Program Files\Java\jdk1.6.0\bin>javac ftpclient.java
C:\Program Files\Java\jdk1.6.0\bin>java ftpclient
Client started
murali.txt
localhost/127.0.0.1
File Length is 9
ftp server:
C:\Program Files\Java\jdk1.6.0\bin>javac ftpserver.java
C:\Program Files\Java\jdk1.6.0\bin>java ftpserver
Server started
localhost/127.0.0.1
Filename server received murali.txt
9
Result :
Thus the given java program was executed and output was verified.
12
-
8/6/2019 NW Lab Experiments
10/52
Ex. No. 3
Implementation of Chat ApplicationDate :
Aim :Write a Java program to Implementation of chat application
Program:
chat.java
import java.net.*;
import java.io.*;
public class chat
{
public static void main(String args[])throws Exception
{
DatagramSocket ioSocket;
String toName="localhost";String userIn;
byte sendBuffer[]=new byte[65535];
DatagramPacket sendPacket=new DatagramPacket(sendBuffer,128);
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
int ioPort=111,receiverPort=ioPort;
if(args.length>0)toName=args[0];
else
toName="localhost";
if(toName.equals("localhost"))
receiverPort=222;
13
-
8/6/2019 NW Lab Experiments
11/52
try
{
ioSocket=new DatagramSocket(ioPort);
}
catch(Exception e )
{
System.out.println("Exception:"+e);
ioPort=222;
receiverPort=111;
ioSocket=new DatagramSocket(ioPort);
}
System.out.println("chat on port"+ioPort+".Ctrl Z to quit");
new receiver(ioSocket);
while((userIn=in.readLine())!=null)
{
sendBuffer=userIn.getBytes();
sendPacket=new
DatagramPacket(sendBuffer,sendBuffer.length,InetAddress.getByName(toName),rec
eiverPort);
ioSocket.send(sendPacket);
}
System.exit(0);
}
}
class receiver implements Runnable
{
14
-
8/6/2019 NW Lab Experiments
12/52
DatagramSocket rsSocket;
receiver(DatagramSocket rsSocket)
{
this.rsSocket=rsSocket;
new Thread(this).start();
}
public void run()
{
System.out.println("Calling run");
byte receiveBuffer[]=new byte[65535];
DatagramPacket receivePacket=new DatagramPacket(receiveBuffer,128);
while(true)
{
try
{
rsSocket.receive(receivePacket);
}
catch(Exception e)
{
}
System.out.println("Received:"+new
String(receivePacket.getData(),0,receivePacket.getLength()));
}
}
}
15
-
8/6/2019 NW Lab Experiments
13/52
Output :
Port 111:
C:\Program Files\Java\jdk1.6.0\bin>javac chat.java
C:\Program Files\Java\jdk1.6.0\bin>java chat
chat on port111.Ctrl Z to quit
Calling run
Received:aaaaa
bbbbb
Received:ccccc
ddddd
Port 222:
C:\Program Files\Java\jdk1.6.0\bin>javac chat.java
C:\Program Files\Java\jdk1.6.0\bin>java chat
chat on port222.Ctrl Z to quit
Calling run
aaaaa
Received:bbbbb
ccccc
Received:ddddd
Result :
Thus the given java program was executed and output was verified.
16
-
8/6/2019 NW Lab Experiments
14/52
Ex. No. 4
Simulation of Routing ProtocolsDate :
Aim :
Write a Java program to Implementation of Routing Protocols
Program:
routing.java
import java.io.*;import java.lang.*;
class routing
{
public static void main(String args[])throws IOException
{
int n,i,j,k;
int[][] b=new int[100][100];
int[][] a=new int[100][100];
String n1;
String s1;
System.out.println("enter the number of nodes\n");
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
n1=br.readLine();
n=Integer.parseInt(n1);
17
-
8/6/2019 NW Lab Experiments
15/52
InputStreamReader isr1=new InputStreamReader(System.in);
BufferedReader br1=new BufferedReader(isr);
for(i=0;i
-
8/6/2019 NW Lab Experiments
16/52
for(j=0;ja[i][k]+a[k][j])
a[i][j]=a[i][k]+a[k][j];
}
}
}
for(i=0;i
-
8/6/2019 NW Lab Experiments
17/52
}
}
}
}
Output :
C:\Program Files\Java\jdk1.6.0\bin>javac routing.java
C:\Program Files\Java\jdk1.6.0\bin>java routing
enter the number of nodes
3
Enter the distance between the host 1 1 : 2
Enter the distance between the host 1 2 : 4
Enter the distance between the host 1 3 : 6
Enter the distance between the host 2 1 : 8
Enter the distance between the host 2 2 : 10
Enter the distance between the host 2 3 : 12
20
-
8/6/2019 NW Lab Experiments
18/52
Enter the distance between the host 3 1 : 14
Enter the distance between the host 3 2 : 16
Enter the distance between the host 3 3 : 18
2 4 6
8 10 12
14 16 18
the output matrix is:
0 4 6
8 0 12
14 16 0
Result :
Thus the given java program was executed and output was verified.
21
-
8/6/2019 NW Lab Experiments
19/52
Ex. No. 5
Study of All SQL CommandsDate :
Aim :Study of all SQL Commands
1.Data Definition Language
2.Data Manipulation Language
3.Transaction Control Language
Codings:
CREATE TABLE:
SQL>
create table msec_student_inf
(
s_roll_no varchar2(15) primary key , student_name varchar2(100) not null,
course_id number(4) , batch_inf varchar2(10) , address_inf varchar2(100) ,
contact_inf varchar2(100) , remark varchar2(100));
Table created.
SQL>
create table msec_course_inf ( course_id number(4) primary key,
course_name varchar2(30) not null , course_duration varchar2(30),
univ_regulation varchar2(100) , remark varchar2(100));
Table created.
22
-
8/6/2019 NW Lab Experiments
20/52
CREATE INDEX:
SQL> CREATE INDEX emp_idx1 ON emp (ename, job);
Index created.
DROP INDEX:
SQL>DROP INDEX emp_idx1;
Index dropped.
CREATE VIEW:
SQL>CREATE VIEW EMP_DEPT_VIEW AS SELECT e.empno, e.ename,
d.deptno, d.loc FROM emp e, dept d WHERE e.deptno = d.deptno
View created
ALTER TABLE:
SQL>alter table msec_student_inf modify batch_inf varchar2(50)
Table altered.
23
-
8/6/2019 NW Lab Experiments
21/52
DESC COMMAND:
SQL> desc msec_student_inf
Name Null? Type
----------------------------------------------------- -------- ------------
S_ROLL_NO NOT NULL VARCHAR2(15)
STUDENT_NAME NOT NULL VARCHAR2(100)
COURSE_ID NUMBER(4)
BATCH_INF VARCHAR2(50)
ADDRESS_INF VARCHAR2(100)
CONTACT_INF VARCHAR2(100)
REMARK VARCHAR2(100)
INSERT COMMAND:
SQL>insert into msec_course_inf
Values
(1,'M.E. CSE','2010-2012','ANNA UNIVERSITY OF TECHNOLOGY MADURAI
R2010','REGULAR COURSE');
1 row created.
24
-
8/6/2019 NW Lab Experiments
22/52
COMMIT/SAVEPOINT/ROLLBACK TRANSACTION COMMAND:
SQL>COMMIT;
SQL>SAVEPOINT SP5;
SQL>ROLLBACK TO SAVEPOINT sp5;
SELECT CLAUSE:
SQL>SELECT COURSE_ID,COURSE_NAME,COURSE_DURATION FROM
MSEC_COURSE_INF;
COURSE_ID COURSE_NAME COURSE_DURATION
---------------- ---------------------- ------------------------------
1 M.E. CSE 2010-2012
2 B.E. CSE 2010-2014
3 B.TECH IT 2010-2014
4 M.C.A. 2010-2013
5 M.B.A. 2010-2012
SQL>SELECT COURSE_ID,COURSE_NAME,COURSE_DURATION FROM
MSEC_COURSE_INF WHERE COURSE_ID = 5;
COURSE_ID COURSE_NAME COURSE_DURATION
----------- -------- ------------------------ ------------------------------
5 M.B.A. 2010-2012
25
-
8/6/2019 NW Lab Experiments
23/52
SQL>SELECT COURSE_ID,COURSE_NAME,COURSE_DURATION FROM
MSEC_COURSE_INF WHERE COURSE_ID < 5;
COURSE_ID COURSE_NAME COURSE_DURATION
----------------- ------------------------------ ------------------------------
1 M.E. CSE 2010-2012
2 B.E. CSE 2010-2014
3 B.TECH IT 2010-2014
4 M.C.A. 2010-2013
SQL>SELECT COURSE_ID,COURSE_NAME,COURSE_DURATION FROM
MSEC_COURSE_INF WHERE COURSE_ID BETWEEN 2 AND 5
COURSE_ID COURSE_NAME COURSE_DURATION
----------------- ------------------------------ ------------------------------
2 B.E. CSE 2010-2014
3 B.TECH IT 2010-2014
4 M.C.A. 2010-2013
5 M.B.A. 2010-2012
ORDER BY CLAUSE:
SQL>SELECT * FROM emp WHERE job = 'SALESMAN' ORDER BY comm
DESC;
26
-
8/6/2019 NW Lab Experiments
24/52
AGGREGATE FUNCTION (MIN, MAX, GROUP BY, HAVING):
SQL> SELECT deptno, MIN(sal), MAX (sal) FROM emp WHERE job = 'CLERK'
GROUP BY deptno HAVING MIN(sal) < 1000;
DEPTNO MIN(SAL) MAX(SAL)
--------- --------- ---------
20 800 1100
30 950 950
JOIN CONDITION:
SQL> SELECT ename, job, dept.deptno, dname FROM emp, dept
WHERE emp.deptno = dept.deptno AND job = 'CLERK';
ENAME JOB DEPTNO DNAME
---------- --------- -------------------------
SMITH CLERK 20 RESEARCH
ADAMS CLERK 20 RESEARCH
JAMES CLERK 30 SALES
MILLER CLERK 10 ACCOUNTING
OUTER JOIN CONDITION:
SQL>SELECT ename, job, dept.deptno, dname FROM emp, dept
WHERE emp.deptno (+) = dept.deptno;
27
-
8/6/2019 NW Lab Experiments
25/52
ENAME JOB DEPTNO DNA
---------- --------- -----------------------
CLARK MANAGER 10 ACCOUNTING
KING PRESIDENT 10 ACCOUN
MILLER CLERK 10 ACCOUNTING
SMITH CLERK 20 RESEARCH
ADAMS CLERK 20 RESEARCH
FORD ANALYST 20 RESEARCH
SCOTT ANALYST 20 RESEARCH
JONES MANAGER 20 RESEARCH
ALLEN SALESMAN 30 SALES
BLAKE MANAGER 30 SALES
MARTIN SALESMAN 30 SALES
JAMES CLERK 30 SALES
TURNER SALESMAN 30 SALES
WARD SALESMAN 30 SALES
15 rows selected.
UPDATE RECORD:
SQL>update msec_course_inf set univ_regulation='ANNA UNIVERSITY -
TIRUCHIRAPPALLI' where course_id=5
1 row updated.
28
-
8/6/2019 NW Lab Experiments
26/52
COURSE_ID COURSE_NAME UNIV_REGULATION
----------------- ---------------------- ----------------------------------------
1 M.E. CSE ANNA UNIV OF TECH MADURAI R2010
2 B.E. CSE ANNA UNIV OF TECH MADURAI R2010
3 B.TECH IT ANNA UNIV OF TECH MADURAI R2010
4 M.C.A. ANNA UNIV OF TECHN MADURAI R2010
5 M.B.A. ANNA UNIVERSITY - TIRUCHIRAPPALLI R2009
DELETE CLAUSE:
SQL>delete from msec_course_inf where course_id=1;
1 rows deleted.
COURSE_ID COURSE_NAME UNIV_REGULATION
----------------- ---------------------- ----------------------------------------
2 B.E. CSE ANNA UNIV OF TECH MADURAI R2010
3 B.TECH IT ANNA UNIV OF TECH MADURAI R2010
4 M.C.A. ANNA UNIV OF TECHN MADURAI R2010
5 M.B.A. ANNA UNIVERSITY - TIRUCHIRAPPALLI R2009
Result :
Thus the given SQL commands were studied and output was verified.
29
-
8/6/2019 NW Lab Experiments
27/52
Ex. No. 6
Implementing The Concept of NormalizationDate :
Aim :
Implement the concept of Normalization (1NF,2NF and 3NF), From the given
data elements for customer Invoices.
Normalization:
Normalization is a method for organizing data elements in a
database, into tables. Normalization avoids duplication of data.
Consider the following invoice information that was maintained in Excel.
30
-
8/6/2019 NW Lab Experiments
28/52
Here if we analyze the spread sheet, rows 2,3 and 4 are representing the data for
invoice no=125, which has the data redundancy for customer information. By
implement the normalization, we can identify the required tables from the given set
of data elements by which we can implement coding.
FIRST NORMAL FORM :
No Repeating Elements Or Group Of Elements
Confirms Automicity For Data Elements And Identification Of Primary Keys
Thus the above data elements can be represented as follows, using 1NF.
INVOICES
INVOICE_NO
(PK)
INVOICE_DATE
CUST_ID
CUST_NAME
CUST_ADDR
CUST_CITY
CUST_STATE
ITEM_ID (PK)
ITEM_DESC
ITEM_QTY
ITEM_PRICE
TOTAL_PRICE
31
-
8/6/2019 NW Lab Experiments
29/52
SECOND NORMAL FORM:
No Partial Dependencies On A Concatenated Key(S)
PHASE-I:
Invoice Information And Invoice Item Information Can Be Seperated Into Tables
PHASE II:
Invoice- Item Table Can Be Further Seperated As Item Information And Put Into
Separate Table
32
-
8/6/2019 NW Lab Experiments
30/52
THIRD NORMAL FORM:
No Dependencies On Non-Key Attributes
Here the problem of repeating customer information has to be separated in a table
because if the customer places more number of orders then these information will
be entered again and again.
Codings:
SQL> CREATE TABLE INVOICES
2 (
33
-
8/6/2019 NW Lab Experiments
31/52
3 INVOICE_NO NUMBER(6) PRIMARY KEY,
4 INVOICE_DATE DATE,
5 CUST_ID NUMBER(6));
TABLE CREATED.
SQL> CREATE TABLE INVOICE_ITEM
2 (
3 ITEM_ID NUMBER(6) PRIMARY KEY,
4 INVOICE_NO NUMBER(6),
5 ITEM_DESC VARCHAR2(50) UNIQUE,
6* ITEM_PRICE NUMBER(10,2));
TABLE CREATED.
SQL> CREATE TABLE CUSTOMER
2 (
34
-
8/6/2019 NW Lab Experiments
32/52
3 CUST_ID NUMBER(6) PRIMARY KEY,
4 CUST_NAME VARCHAR2(50) UNIQUE,
5 CUST_ADDR VARCHAR2(50),
6 CUST_CITY VARCHAR2(50),
7 CUST_STATE VARCHAR2(50));
TABLE CREATED.
SQL> CREATE TABLE ITEMS
2 (
3 ITEM_ID NUMBER(6) PRIMARY KEY,
4 ITEM_DESC VARCHAR2(50) UNIQUE,
5 ITEM_PRICE NUMBER(10,2));
TABLE CREATED.
Result :
Thus the given normalization concepts was executed and output was
verified.
Ex. No. 7
Develop A Package To Maintain Its Customer DetailsDate :
Aim :
35
-
8/6/2019 NW Lab Experiments
33/52
Develop a Package for Bank to maintain its Customers detail
Customer Account Opening Form:
Business Rules:
1. Customer Account number is system generated and unique
2. Opening balance is set according to the account type as
Savings bank a/c Rs.5000
Current a/c Rs.1000
Recurring depositRs.100
NRE a/c Rs.250003. Set current bal = opening balance at the opening time
4. All other deposits through transaction only
Transaction Table:
1. Transaction id is system generated
2. Transaction date is system date
3. Transaction is made upon the user input values for transaction type and
transaction amount
4. if trans_type=deposit then amount will be credited
5. if trans_type=withdraw then amount will be debited from main balance.
Table Creation :
Customer Information :
create table bank_cust_inf
(
36
-
8/6/2019 NW Lab Experiments
34/52
cust_acno number(10) primary key,
cust_name varchar2(50) not null,
cust_addr varchar2(50) not null,
cust_phno varchar2(50) not null,
cust_mail varchar2(50) not null,
account_type number(1),
open_bal number(15,2),
current_bal number(15,2),
open_date varchar2(10));
Bank Transaction Information :
create table bank_trans
(
trans_slno number(8) primary key,
trans_date varchar2(10),
cust_acno number(10),
avl_bal number(15,2),
trans_type number(1),
trans_amt number(15,2),
new_bal number(15,2),
remark varchar2(50));
Form design time codings:
Form level triggers:
When-tabpage-changed:
37
-
8/6/2019 NW Lab Experiments
35/52
IF :SYSTEM.TAB_NEW_PAGE='CUST' THEN
GO_BLOCK('BANK_CUST_INF');
EXECUTE_QUERY;
ELSIF :SYSTEM.TAB_NEW_PAGE='TRANS' THEN
GO_BLOCK('BANK_CUST_INF1');
EXECUTE_QUERY;
END IF;
ON-INSERT on customer account opening:
declare
n number;
begin
select count(*) into n from BANK_CUST_INF;
if n>0 then
select max(CUST_ACNO)+1 into :BANK_CUST_INF.CUST_ACNO from
BANK_CUST_INF;
else
:BANK_CUST_INF.CUST_ACNO:=1001;
end if;
insert_record;
end;
TRANSACTION TABLE CODINGS:
BEGIN
SELECT CURRENT_BAL INTO :BANK_TRANS.AVL_BAL FROM
BANK_CUST_INF
38
-
8/6/2019 NW Lab Experiments
36/52
WHERE CUST_ACNO=:BANK_CUST_INF1.CUST_ACNO;
IF :BANK_TRANS.TRANS_TYPE=1 THEN
:
BANK_TRANS.NEW_BAL:=:BANK_TRANS.AVL_BAL+:BANK_TRANS.TRA
NS_AMT;
ELSIF :BANK_TRANS.TRANS_TYPE=2 THEN
:BANK_TRANS.NEW_BAL:=:BANK_TRANS.AVL_BAL -
:BANK_TRANS.TRANS_AMT;
IF :BANK_TRANS.NEW_BAL < :BANK_CUST_INF.OPEN_BAL THEN
:BANK_TRANS.TRANS_AMT:=:BANK_TRANS.TRANS_AMT -
:BANK_CUST_INF.OPEN_BAL;
:BANK_TRANS.NEW_BAL:=:BANK_TRANS.AVL_BAL -
:BANK_TRANS.TRANS_AMT;
END IF;
END IF;
UPDATE BANK_CUST_INF
SET CURRENT_BAL = :BANK_TRANS.NEW_BAL
WHERE CUST_ACNO=:BANK_CUST_INF1.CUST_ACNO;
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
WHEN OTHERS THEN NULL;
END;
39
-
8/6/2019 NW Lab Experiments
37/52
POST-QUERY ON TRANSACTION TABLE:
if :bank_cust_inf1.account_type=1 then
:bank_cust_inf1.DSP_AC_TYPE:='Savings Bank Account';
elsif :bank_cust_inf1.account_type=2 then
:bank_cust_inf1.DSP_AC_TYPE:='Current Account';
elsif :bank_cust_inf1.account_type=3 then
:bank_cust_inf1.DSP_AC_TYPE:='Recurring Deposit';
elsif :bank_cust_inf1.account_type=4 then
:bank_cust_inf1.DSP_AC_TYPE:='NRE/NRO Savings Account';
end if;
Run time Screen Shot(s) Customer Account Opening Form:
40
-
8/6/2019 NW Lab Experiments
38/52
Customer Account Transaction Screen:
Result :
Thus the given package was executed and output was verified.
Ex. No. 8
41
-
8/6/2019 NW Lab Experiments
39/52
Develop A Package For The Payroll of A CompanyDate :
Aim :
Develop a package for the Pay-Roll of a Company
Employee Detail:
1. Empno is system generated and unique
2. Deptno, job title id is lookup field from concerned sub tables
3. Net salary is calculated field as
Net salary= (Basic salary+Overtimepay+Bouns)-Deduction.
4. Over time pay = 1.5 time of Basic pay / hr
Table creation:
Employee information:
SQL>
create table employee_inf
(
empno number(5) primary key,
empname varchar2(100) not null,
join_date varchar2(10) not null,
job_title_id number(2),
deptno number(2),
basic_sal number(10,2),
over_time number(9,2),
bonus number(9,2),
deduction number(9,2),
net_salary number(9,2),
42
-
8/6/2019 NW Lab Experiments
40/52
remark varchar2(100)
);
Table created.
Employee department information:
create table emp_dept
(
deptno number(4) primary key,
dname varchar2(50) unique
);
Table created.
Employee job title informaton:
create table emp_job_title
(
job_title_id number(2) primary key,
job_desc varchar2(50) not null
);
Table created.
Employee overtime information:
SQL>
43
-
8/6/2019 NW Lab Experiments
41/52
create table emp_overtime
(
empno number(5),
ot_date varchar2(10),
ot_hrs number(2),
ot_pay number(10,2),
ot_amt number(10,2)
);
Table created.
SQL>
SQL> INSERT INTO emp_job_title
2 VALUES (1,'MANAGER');
1 row created.
SQL> INSERT INTO emp_dept
2 VALUES (1,'ADMIN');
1 row created.
Form Design Codings:
Form level triggers WHEN-NEW-FORM-INSTANCE:
44
-
8/6/2019 NW Lab Experiments
42/52
set_window_property(forms_mdi_window,window_state,MAXIMIZE);
set_window_property('MAIN',window_state,MAXIMIZE);
declare
n number;
begin
n:=POPULATE_GROUP('RG_EMP');
POPULATE_LIST('EMPLOYEE_INF.EMPNO','RG_EMP');
n:=POPULATE_GROUP('RG_DEPT');
POPULATE_LIST('EMPLOYEE_INF.DEPTNO','RG_DEPT');
n:=POPULATE_GROUP('RG_TITLE');
POPULATE_LIST('EMPLOYEE_INF.JOB_TITLE_ID','RG_TITLE');
END;
WHEN-TAB-PAGE-CHANGED:
IF :SYSTEM.TAB_NEW_PAGE='EMP' THEN
GO_BLOCK('EMPLOYEE_INF');
EXECUTE_QUERY;
ELSIF :SYSTEM.TAB_NEW_PAGE='DEPT' THEN
GO_BLOCK('EMP_DEPT');
EXECUTE_QUERY;
ELSIF :SYSTEM.TAB_NEW_PAGE='JOB' THEN
GO_BLOCK('EMP_JOB_TITLE');EXECUTE_QUERY;
ELSIF :SYSTEM.TAB_NEW_PAGE='OT' THEN
GO_BLOCK('EMPLOYEE_INF1');
45
-
8/6/2019 NW Lab Experiments
43/52
EXECUTE_QUERY;
END IF;
BLOCK LEVEL TRIGGERS ON INSERT:
declare
n number;
begin
select count(*) into n from EMPLOYEE_INF;
if n>0 then
select max(EMPNO)+1 into :EMPLOYEE_INF.EMPNO from employee_inf;
else
:EMPLOYEE_INF.EMPNO:=1001;
end if;
end
insert_record;
Field Level Triggers KEY-NEXT-ITEM (all calculation fields):
:EMPLOYEE_INF.NET_SALARY:=
(NVL(:EMPLOYEE_INF.basic_sal,0)+
NVL(:EMPLOYEE_INF.over_time,0)+NVL(:EMPLOYEE_INF.bonus,0))-
(NVL(:EMPLOYEE_INF.deduction,0));
Employee overtime pay per hour based on basic salary:
:EMP_OVERTIME.ot_pay:=
ROUND((((:EMPLOYEE_INF1.basic_sal*:EMP_OVERTIME.ot_hrs)/208)*1.5),2);
46
-
8/6/2019 NW Lab Experiments
44/52
:
EMP_OVERTIME.ot_amt:=:EMP_OVERTIME.ot_hrs*:EMP_OVERTIME.ot_pay;
Screen Shot:
Search Module :
47
-
8/6/2019 NW Lab Experiments
45/52
Overtime Calculation :
Monthly Pay-Roll Preperation :
48
-
8/6/2019 NW Lab Experiments
46/52
Result :
Thus the given package was executed and output was verified.
49
-
8/6/2019 NW Lab Experiments
47/52
Ex. No. 9
Implement The Inventory Control System With A
Reorder LevelDate :
Aim :
Implement the Inventory Control System with Re-order level
Inventory Master:
Business Rules:
1. Min Qty = 10 and Max Qty = 100
2. New item can be inserted through this module but update through transaction
only
3. Delete operation is not allowed until all transaction entries are cleared, to
maintain integrity constraints.
4. Re-Order level condition : if avl_qty=max_qty;
Inventory Transaction:
1. Check for the item availability
2. if the item is available, then check for re-order level
3. if the item can be issued, allow transaction
4. update master file with the current avl qty
5. no transaction could be modified from transaction screen
50
-
8/6/2019 NW Lab Experiments
48/52
Create table:
Master Information:
create table inventory_master
(
item_code number(5) primary key,
item_name varchar2(30) not null,
unit_price number(7,2),
avl_qty number(5),
min_qty number(3),
max_qty number(5),
supp_inf varchar2(100),
remark varchar2(100));
Transaction Information
create table inventory_trans
(
trans_slno number(8) primary key,
trans_date varchar2(10) default to_char(sysdate,'dd/mm/yyyy'),
item_code number(5),
trans_qty number(5),
trans_amt number(7,2),
remark varchar2(100));
51
-
8/6/2019 NW Lab Experiments
49/52
Design time Codings:
Form level triggers when new form instance:
set_window_property(forms_mdi_window,window_state,MAXIMIZE);
set_window_property('MAIN',window_state,MAXIMIZE);
declare
n number;
begin
n:=POPULATE_GROUP('RG_ITEM');
POPULATE_LIST('INVENTORY_TRANS.ITEM_CODE','RG_ITEM');
END;
IF :SYSTEM.MODE='NORMAL' THEN
:INVENTORY_MASTER.MIN_QTY:=10;
:INVENTORY_MASTER.MAX_QTY:=100;
END IF;
When tab page changed:
IF :SYSTEM.TAB_NEW_PAGE='MASTER' THEN
GO_BLOCK('INVENTORY_MASTER');
EXECUTE_QUERY;
ELSIF :SYSTEM.TAB_NEW_PAGE='TRANS' THEN
GO_BLOCK('INVENTORY_TRANS');
EXECUTE_QUERY;
END IF;
52
-
8/6/2019 NW Lab Experiments
50/52
On Insert trigger on inventory master (item code):
declare
n number;
begin
select count(*) into n from inventory_master;
if n>0 then
select max(item_code)+1 into :inventory_master.item_code from inventory_master;
else
:inventory_master.item_code:=1;
end if;
insert_record;
end;
Transaction module codings:
begin
select unit_price,avl_qty into :inventory_trans.dsp_up,:inventory_trans.dsp_avl from
inventory_master
where item_code=:inventory_trans.item_code;
exception when no_data_found then null;
when others then null;
end;
:inventory_trans.trans_amt:=:inventory_trans.trans_qty*:inventory_trans.dsp_up;
53
-
8/6/2019 NW Lab Experiments
51/52
On delete entry
UPDATE INVENTORY_MASTER
SET AVL_QTY=AVL_QTY+:INVENTORY_TRANS.TRANS_QTY
WHERE ITEM_CODE=:INVENTORY_TRANS.ITEM_CODE;
delete_record;
Post insert:
UPDATE INVENTORY_MASTER
SET AVL_QTY=AVL_QTY-:INVENTORY_TRANS.TRANS_QTY
WHERE ITEM_CODE=:INVENTORY_TRANS.ITEM_CODE;
Post Query:
begin
select unit_price,avl_Qty
into :inventory_trans.dsp_up, :inventory_trans.dsp_avl
from inventory_master where item_code = :inventory_trans.item_code;
exception
when no_data_found then null;
when others then null;
end;
54
-
8/6/2019 NW Lab Experiments
52/52
Runtime Screen Shot(s):