gambas_ex2

9
Ex No : 4 GUI programming (GAMBAS) Date : 18/07/2012 1. Objec tive: To Develop a GUI application in GAMBAS for Student Maintenance System and to use MYSQL for Database Activity . GAMBAS : (Linux Free IDE) Gambas is a basic language with object extensions. A program written with Gambas is a set of files. Each file describes a class in terms of object programming.  2. Installation procedure : 2.1 Gambas installation: yum install gambas2 2.2 MySQL installation: Command to install mysql: #yum install mysql mysql-server . Location of mysql: Filesystem/usr/share/mysql. To start mysql service: #/etc/init.d/mysqld start. (or) #service mysqld start. To login to mysql: #mysql -u root -p Enter password: Syntax for mysql connection in php: mysql_connect(servername,username,password) To exit from mysql: exit To stop mysql service: #/etc/init.d/mysqld stop. (or) #service mysqld stop. To reset password in mysql: 1).Stop the mysql service. 2).Restart mysql in safe mode: #mysqld_safe –skip-grant-tables& 3).Login to mysql at the command line: #mysqld -u root. 4).T o create new password: >> update u ser set password=PASSWORD( “new_password”) where user='root'. 5).Exit from mysql. To unistall mysql: #yum remove mysql 3. Application: 3.1 Descrip tion: Application Chosen : STUDENT MAINTENANCE SYSTEM A GUI appli cation, Student Maintenance System is used to maintain students detail. In this system , you can enroll a student detail , search for a student detail , update students detail and delete a student detail given registration number. Mysql is used to store the students detail like name, reg. no. , marks in 3 subjects and total marks. Database is updated for each operations (enroll, update , dele te).

Upload: mahisella

Post on 14-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Gambas_ex2

7/27/2019 Gambas_ex2

http://slidepdf.com/reader/full/gambasex2 1/9

Ex No : 4 GUI programming (GAMBAS)Date : 18/07/2012

1. Objective:

To Develop a GUI application in GAMBAS for Student Maintenance System and to use MYSQL

for Database Activity.

GAMBAS : (Linux Free IDE)

Gambas is a basic language with object extensions. A program written with Gambas is a set offiles. Each file describes a class in terms of object programming.

  2. Installation procedure :

2.1 Gambas installation:

● yum install gambas2

2.2 MySQL installation:

● Command to install mysql:#yum install mysql mysql-server.

● Location of mysql:Filesystem/usr/share/mysql.

● To start mysql service:#/etc/init.d/mysqld start. (or)#service mysqld start.

● To login to mysql:#mysql -u root -p

Enter password:● Syntax for mysql connection in php:mysql_connect(servername,username,password)

● To exit from mysql:exit

● To stop mysql service:#/etc/init.d/mysqld stop. (or) #service mysqld stop.

● To reset password in mysql:1).Stop the mysql service.2).Restart mysql in safe mode:

#mysqld_safe –skip-grant-tables&3).Login to mysql at the command line:

#mysqld -u root.4).To create new password:

>> update user set password=PASSWORD(“new_password”) where user='root'.5).Exit from mysql.

● To unistall mysql:#yum remove mysql

3. Application:

3.1 Description:Application Chosen : STUDENT MAINTENANCE SYSTEM● A GUI application, Student Maintenance System is used to maintain students detail.● In this system , you can enroll a student detail , search for a student detail , update students

detail and delete a student detail given registration number.● Mysql is used to store the students detail like name, reg. no. , marks in 3 subjects and total

marks. Database is updated for each operations (enroll, update , delete).

Page 2: Gambas_ex2

7/27/2019 Gambas_ex2

http://slidepdf.com/reader/full/gambasex2 2/9

3.2 Procedure :

• Steps To Create A New Project in Gambas :

1. Start Gambas.2. Click New Project and Click Next.

3. Select Create a Graphical Project and Clikc Next.4. In the “Select Name of the Project” , insert “Student(application name)”.5. For title also , insert “Student”.6. Click “OK” to create the Project.

• Steps To Create A Form :

1. On your left side, you will see a tree view, right click on the Forms folder,choose New->Form and click ok in the create form dialog box.

2. The gray form will be displayed where you place the objects in it.3. To your right, you should see the “ToolBox” where you choose what objects you

want in the form and also set the properties to the object you create.

• Designing GUI For An Application (Form Design) :

1. The required Labels and the textfields are created using the toolbox.2. For Creating a label, Select [A] from properties and drag it to the form. In the

properties, you can set properties like changing the text, name , font, etc for thelabel.

3. Create textbox similarly by selecting [abc] textbox.4. To give action to each button, double click on the button to open the Fmain.class

• To Open A Code Editor :  Buttons such as “Enroll” , “Search” , “Update” , “Delete” and “Exit” are created for

each of the four operations using button toolbox. There are 4 Forms foreach button.  Double click over the button for which the code is to be written.

▪ Creating Event Procedure :

• Code is divided in small blocks which is known as procedures.

• Write the code between PUBLIC SUB AND END SUB.

• Running the Application :

1. Inorder to run the application , select Debug->Run from the Menu Bar (or)click over the start icon on the Tool Box.

2. For enabling the Database Access and MYSQL DB driver,

-> Go to --> Project --> Properties-> Go to --> Component Tab-> Select gb.db.mysql , gb.db-> Click ok

3.3 MySQL commands:

--->Create database:create database db;

--->To drop the database:drop database db;

--->To use the mydb database:use db;--->To create table:

create table student

Page 3: Gambas_ex2

7/27/2019 Gambas_ex2

http://slidepdf.com/reader/full/gambasex2 3/9

(name varchar(50) NOT NULL,roll int(20) NOT NULL,m1 int(3),m2 int(3),m3 int(3),mark int(3),

CONSTRAINT name_roll UNIQUE(name,roll));

3.4 PROGRAM CODING :

DB Connection :(Gambas module file)

PUBLIC $Con AS NEW ConnectionPUBLIC PROCEDURE Connect()

$Con.Type = "MySQL" ' Type of connection$Con.Host = "localhost" ' Name of the server$Con.Login = "root" ' User's name for the connection

$Con.Port = "3306" ' Port to use in the connection, usually 3306$Con.Name = "db" ' Name of the database we want to use$Con.Password = "saranya" ' User's password$Con.Open() ' Open the connection

END

Main Form : (STUDENTS MARK MAINTENANCE SYSTEM FORM)

PUBLIC SUB enroll_Click()Form2.Show()FMain.Hide()END

PUBLIC SUB search_Click()Form1.Show()FMain.Hide()END

PUBLIC SUB delete_Click()Form3.Show()FMain.Hide()END

PUBLIC SUB exit_Click()FMain.Hide()END

PUBLIC SUB update_Click()Form4.Show()FMain.Hide()END

Enrolling a Student Detail Form :

Page 4: Gambas_ex2

7/27/2019 Gambas_ex2

http://slidepdf.com/reader/full/gambasex2 4/9

PUBLIC PROCEDURE insert()DIM $Result AS ResultDIM $m1 AS IntegerDIM $m2 AS IntegerDIM $m3 AS IntegerDIM $tot AS Integer$Result = dbcon.$Con.Create("student")

$Result!roll = roll.Text$Result!name = name.Text$m1 = m1.Text$m2 = m2.Text$m3 = m3.Text$tot = $m1 + $m2 + $m3mark.Text = $tot$Result!mark = mark.Text$Result!m1 = m1.Text$Result!m2 = m2.Text$Result!m3 = m3.TextMessage.Info("Student Enrolled Successfully !!")$Result.Update()dbcon.$Con.Commit()add.Text = "Ok"

END

PUBLIC SUB add_Click()dbcon.Connect()insert()Clear_Click()Form2.Hide()FMain.Show()

END

PUBLIC SUB Clear_Click()roll.Text = ""name.Text = ""m1.Text = ""m2.Text = ""m3.Text = ""mark.Text = ""END 

Searching for a Student Mark Form :

PUBLIC PROCEDURE SearchName()DIM $name AS StringDIM $mark AS StringDIM $Query AS StringDIM $Result AS ResultDIM $m1 AS IntegerDIM $m2 AS IntegerDIM $m3 AS Integer$Query = "SELECT * FROM student WHERE roll = '" & roll.Text & "'"

$Result = dbcon.$Con.Exec($Query)$name = $Result!name$mark = $Result!mark

Page 5: Gambas_ex2

7/27/2019 Gambas_ex2

http://slidepdf.com/reader/full/gambasex2 5/9

$m1 = $Result!m1$m2 = $Result!m2$m3 = $Result!m3name.Text = $namemark.Text = $markm1.Text = $m1m2.Text = $m2

m3.Text = $m3searchstud.Text = "Ok"Message.Info($name)Message.Info($mark)Message.Info("Student Info was Displayed Successfully!!")

ENDPUBLIC SUB searchstud_Click()SearchName()Clear_Click()Form1.Hide()FMain.Show()END

PUBLIC SUB Clear_Click()roll.Text = ""name.Text = ""m1.Text = ""m2.Text = ""m3.Text = ""mark.Text = ""END

Deleting a Student Detail Form :

PUBLIC PROCEDURE delete()DIM $Query AS StringDIM $Result AS Result

$Query = "DELETE FROM student WHERE roll = '" & roll.Text & "'"$Result = dbcon.$Con.Exec($Query)Message.Info("StudentDeleted Successfullyfrom the Record!!")END

PUBLIC SUB del_Click()delete()Clear_Click()Form3.Hide()FMain.Show()END

PUBLIC SUB Clear_Click()roll.Text = ""END

Updating a Student Detail Form :

Page 6: Gambas_ex2

7/27/2019 Gambas_ex2

http://slidepdf.com/reader/full/gambasex2 6/9

PUBLIC $Result AS IntegerPUBLIC PROCEDURE update1()

DIM $name AS StringDIM $mark AS StringDIM $Query AS StringDIM $Query1 AS StringDIM $Query2 AS String

DIM $Query3 AS StringDIM $m1 AS IntegerDIM $m2 AS IntegerDIM $m3 AS IntegerDIM $tot AS Integer$m1 = m1.Text$m2 = m2.Text$m3 = m3.Text$tot = $m1 + $m2 + $m3mark.Text = $tot$Query1 = "update student set m1 = '" & m1.Text & "' where roll = '" & roll.Text & "'"$Query2 = "update student set m2 = '" & m2.Text & "' where roll = '" & roll.Text & "'"$Query3 = "update student set m3 = '" & m3.Text & "' where roll = '" & roll.Text & "'"$Query = "update student set mark = '" & mark.Text & "' where roll = '" & roll.Text & "'"dbcon.$Con.Exec($Query)dbcon.$Con.Exec($Query1)dbcon.$Con.Exec($Query2)dbcon.$Con.Exec($Query3)Message.Info("Student Mark Updated Successfully !!")update.Text = "Ok"

END

PUBLIC SUB update_Click()

update1()Clear_Click()Form4.Hide()FMain.Show()END

PUBLIC SUB Clear_Click()roll.Text = ""m1.Text = ""m2.Text = ""m3.Text = ""mark.Text = ""

END

Page 7: Gambas_ex2

7/27/2019 Gambas_ex2

http://slidepdf.com/reader/full/gambasex2 7/9

DATABASE OUTPUT :

SAMPLE INPUT AND OUTPUT :

• Enrollment Of A Student Detail :

• Database Output After the Enrollment of a Student Detail :

Page 8: Gambas_ex2

7/27/2019 Gambas_ex2

http://slidepdf.com/reader/full/gambasex2 8/9

• Searching for a Student Detail :

• Updating A Student Detail :

• Database Output After Updating the Student Detail :

Page 9: Gambas_ex2

7/27/2019 Gambas_ex2

http://slidepdf.com/reader/full/gambasex2 9/9

• Deleting A Student Detail :

• Database Output After Deleting a Student Detail :

4. Conclusion :

The System Student Maintenance System Application is created using GAMBAS 2(Graphical User Interface) and the form is disgned using labels,textbox and buttons. For each objects createdin the form , the properties are set like changing the text, font , color, height , etc. Those properties arestudied and modified. MYSQL connection is enabled and connection is made and for every click action onthe button , changes are applied in the form and also in the database using gambas code.