Gam Bus
Gam Bus
Objective:
To Develop a GUI application in GAMBAS for customer 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 Chosen : BANKING SYSTEM 3.1 Description: A GUI application, Banking System is used to maintain Customer detail. In this system , you can enroll a sustomerdetail , search for a customer detail , update customer detail and delete a customer detail given card number. Mysql is used to store the customer detail like name, card. no. ,Branch and balance. Database is updated for each operations (enroll, update , delete). 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 customer(application name). 5. For title also , insert customer. 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 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 user ( accno int(20) constraint pk PRIMARY KEY, name varchar(20) NOT NULL, branch varchar(20), amt int(20) CHECK(amt>0), CONSTRAINT name_roll UNIQUE(name,accno) );
3.4 PROGRAM CODING : SERVER: Gambas class file Obj[10] As Socket i As Integer sBuf As String Public $Con As New Connection Public Sub _new() End Public Sub Form_Open() i=0 End //CODE FOR DATABASE CONNECTION Public Procedure Connect() $Con.Close() ' Close the connection $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 = "test" ' Name of the database we want to use $Con.Password = "ssn" ' User's password $Con.Open() ' Open the connection Print $Con.Opened End Public Sub Button1_Click() MyServerSocket.Type = Net.Internet ' The port to listen to MyServerSocket.Port = "34540" ' we start listening MyServerSocket.Listen(3) Connect() End
Public Sub MyServerSocket_Connection(sHost As String) Obj[i] = MyServerSocket.Accept() Obj[i].Blocking = False i=i+1 Print "received req" End Public Sub Socket_Read() 'Dim sBuf As String ' Dim iInd As Integer '****************************** ' When some data arrives to ' our server, we respond with ' an echo '***************************** Dim Elt As String[] Dim Sb As String Dim rs As Result Dim reg As String Dim all_reg As String Dim stud As String Dim id1 As String Dim nos As String Dim no As Integer stud = "values" If Last.Status <> Net.Connected Then Return Read #Last, sBuf, Lof(Last) Print sBuf Elt = Split(sBuf, "/") For Each Sb In Elt Print "("; Sb; ") "; Next Print "*****" If Elt[0] = "add" Then Print "----add" $Con.Begin() no = CInteger(Val(Elt[4])) $Con.Exec("INSERT INTO user VALUES(&1,&2,&3,&4)", Elt[1], Elt[2], Elt[3], no) $Con.Commit()
Message("You have successfully registered for the system") Else If Elt[0] = "del" Then Print "----del" $Con.Begin() rs = $Con.Exec("select accno from user where accno='" & Elt[1] & "'") '$Con.Commit() id1 = "" & rs["accno"] Print "ID1 " Print id1 rs.MoveNext $Con.Exec("DELETE FROM user where accno='" & id1 & "'") $Con.Commit() Message("You have de registered from the system ") Else If Elt[0] = "del" Then Print "----del" $Con.Begin() rs = $Con.Exec("select accno from user where accno='" & Elt[1] & "'") '$Con.Commit() id1 = "" & rs["accno"] Print "ID1 " Print id1 rs.MoveNext $Con.Exec("DELETE FROM user where accno='" & id1 & "'") $Con.Commit() Message("You have de registered from the system ") Else If Elt[0] = "get" Then Print "----getdetails" $Con.Begin() rs = $Con.Exec("select * from user where accno='" & Elt[1] & "'") 'rs.MoveNext nos = rs["amt"] id1 = "val" &/ "accno" &/ rs["name"] &/ rs["branch"] &/ nos 'id1 = rs["name"] Write #Last, id1, Len(id1)
Print id1 'Message("New Student has beenu[dated]") Else If Elt[0] = "upd" Then Print "----updation" $Con.Begin() no = CInteger(Val(Elt[2])) rs = $Con.Exec("select * from user where accno='" & Elt[1] & "'") 'rs.MoveNext nos = rs["amt"] ' no = Cinteger(Val(Elt[4])) no = nos - no $Con.Exec("update user set amt='" & no & "' where accno='" & Elt[1] & "'") ' id1 = "upd" &/ "accno" &/ rs["name"] &/ rs["branch"] &/ nos 'id1 = rs["name"] Write #Last, id1, Len(id1) Print id1 $Con.Commit() Message("You have successfully withdrawn ") End If End CLIENT : Main class: ' Gambas class file Public Sub Form_Open() MySocket.Connect("localhost", 34540) End Public Sub Form_Close() '********************* ' Close possible Stablished connections '********************* If MySocket.Status > 0 Then Close #MySocket End
Public Sub MySocket_Ready() '*********************************** ' When connection proccess has finished ' successfully, "Connected" event will raise '*********************************** Print "connected" Print Net.Connected ' Write #MySocket, "hello", 5 End Public Sub Button1_Click() fadd.Show FMain.close End Public Sub Button2_Click() fdel.show FMain.close End Public Sub Button3_Click() update.show FMain.close End ENROLL CLASS : ' Gambas class file details As String r1 As String r2 As String r3 As String r4 As String Public Sub Form_Open() asocket.Connect("127.0.0.1", 34540) End
Public Sub asocket_Ready() '*********************************** ' When connection proccess has finished ' successfully, "Connected" event will raise '*********************************** Print "connected" End Public Sub Button1_Click() r1 = TextBox1.Text r2 = TextBox2.Text r3 = TextBox3.Text r4 = TextBox4.Text details = "add" &/ r1 &/ r2 &/ r3 &/ r4 ' Print combo 'Print details ' Write #asocket, "add", 3 Write #asocket, details, Len(details) End Public Sub Button2_Click() FMain.Show fadd.close End UPDATE CLASS: ' Gambas class file sb As String r1 As String details As String id1 As String elt As String[] Public Sub Form_Open() usocket.Connect("127.0.0.1", 34540) End
Public Sub Button1_Click() r1 = TextBox1.Text details = "get" &/ r1 ' Print r1 ' Print combo 'Print details ' Write #asocket, "add", 3 Write #usocket, details, Len(details) 'For Each sb In elt ' Print " " 'Print sb 'Next End Public Sub usocket_Read() If usocket.Status <> Net.Connected Then Return Read #usocket, id1, Lof(usocket) Print id1 Elt = Split(id1, "/") If Elt[0] = "val" Then TextBox2.Text = Elt[2] TextBox3.Text = Elt[3] TextBox4.Text = Elt[4] End If End Public Sub Button2_Click() details = "upd" &/ TextBox1.Text &/ TextBox4.Text ' Print r1 ' Print combo 'Print details ' Write #asocket, "add", 3 Write #usocket, details, Len(details) End
Public Sub Button3_Click() update.Close FMain.show End DELETE CLASS: ' Gambas class file r1 As String details As String Public Sub Form_Open() dsocket.Connect("127.0.0.1", 34540) End Public Sub Button1_Click() r1 = TextBox1.Text details = "del" &/ r1 Print r1 ' Print combo 'Print details ' Write #asocket, "add", 3 Write #dsocket, details, Len(details) End Public Sub asocket_Ready() '*********************************** ' When connection proccess has finished ' successfully, "Connected" event will raise '*********************************** Print "connected" End Public Sub Button2_Click() FMain.Show fdel.close End
SERVER:
CLIENT:
4. Conclusion : The Banking 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.