Вы находитесь на странице: 1из 9

Ex No : 4 Date : 18/07/2012

GUI programming (GAMBAS)

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 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).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).

3.2 Procedure : Steps To Create A New Project in Gambas : 1. 2. 3. 4. 5. 6. Start Gambas. Click New Project and Click Next. Select Create a Graphical Project and Clikc Next. In the Select Name of the Project , insert Student(application name). For title also , insert Student. 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 the label. 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 for each 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

( 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 Connection PUBLIC PROCEDURE Connect() $Con.Type = "MySQL" $Con.Host = "localhost" $Con.Login = "root" $Con.Port = "3306" $Con.Name = "db" $Con.Password = "saranya" $Con.Open() END

' Type of connection ' Name of the server ' User's name for the connection ' Port to use in the connection, usually 3306 ' Name of the database we want to use ' User's password ' Open the connection

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 :

PUBLIC PROCEDURE insert() DIM $Result AS Result DIM $m1 AS Integer DIM $m2 AS Integer DIM $m3 AS Integer DIM $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 + $m3 mark.Text = $tot $Result!mark = mark.Text $Result!m1 = m1.Text $Result!m2 = m2.Text $Result!m3 = m3.Text Message.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 String DIM $mark AS String DIM $Query AS String DIM $Result AS Result DIM $m1 AS Integer DIM $m2 AS Integer DIM $m3 AS Integer $Query = "SELECT * FROM student WHERE roll = '" & roll.Text & "'" $Result = dbcon.$Con.Exec($Query) $name = $Result!name $mark = $Result!mark

$m1 = $Result!m1 $m2 = $Result!m2 $m3 = $Result!m3 name.Text = $name mark.Text = $mark m1.Text = $m1 m2.Text = $m2 m3.Text = $m3 searchstud.Text = "Ok" Message.Info($name) Message.Info($mark) Message.Info("Student Info was Displayed Successfully!!") END PUBLIC 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 String DIM $Result AS Result $Query = "DELETE FROM student WHERE roll = '" & roll.Text & "'" $Result = dbcon.$Con.Exec($Query) Message.Info("Student Deleted Successfully from 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 :

PUBLIC $Result AS Integer PUBLIC PROCEDURE update1() DIM $name AS String DIM $mark AS String DIM $Query AS String DIM $Query1 AS String DIM $Query2 AS String DIM $Query3 AS String DIM $m1 AS Integer DIM $m2 AS Integer DIM $m3 AS Integer DIM $tot AS Integer $m1 = m1.Text $m2 = m2.Text $m3 = m3.Text $tot = $m1 + $m2 + $m3 mark.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

DATABASE OUTPUT :

SAMPLE INPUT AND OUTPUT : Enrollment Of A Student Detail :

Database Output After the Enrollment of a Student Detail :

Searching for a Student Detail :

Updating A Student Detail :

Database Output After Updating the Student Detail :

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 created in the form , the properties are set like changing the text, font , color, height , etc. Those properties are studied and modified. MYSQL connection is enabled and connection is made and for every click action on the button , changes are applied in the form and also in the database using gambas code.

Вам также может понравиться