SlideShare a Scribd company logo
CODE SNIPPETS

                                  FOR
                BWM – MOTOR FRANCHISE PROJECT



                                        Created by      Team Members

                                        Reviewed by     Team Members
Module:       Web Services
                                        Created Date    19 April 2012

Assignment:   Team Assignment           Revised Date    27 April 2012

                                        Revision No.    1.2
Team Name:    SPOCK
                                        Document Name   F03-001
DATA VALIDATION




            2
3                               1.VALIDATION BY CONTROLS



         Register User                    Register Vehicle




    Required Field Validators
4                          2.VALIDATION BY CONTROLS


       Validate Price               Validate Price and Mileage




    Price must be number        Price and mileage must more than 0
5                     3.VALIDATION BY CONTROLS




    Validate E-mail          Regular Expression Validator




                          User must fill right format of e-mail
6                                      4. CODE VALIDATION



          Date Validation




Validate Date ex. 31 April 2012 is a
          incorrect date
CONSUMING WEB SERVICES
    FROM BWM SITE




           7
8                 1.REGISTER VEHICLE




                               Consuming Web Services
          '========================================================
          ' 2.2.2) REGISTER VEHICLE TO BWM
          '========================================================
          '========================================================
          ' 2.2.2.1) REGISTER VEHICLE TO BWM (FOR SELL)
          '========================================================
          If SellingStatus = "SELL" Then
             ReturnFunction = MyProxy.RegisterVehicleForSale(BodyStyle, Model,
    MyUtils.ConvertDateForBwmWebService(DateRegistered), RegNumber, Mileage, FuelType,
    CarDescription, Price, DateAdded, "SPOCK-" & UserName)
          End If
          '========================================================
          ' 2.2.2.2) REGISTER VEHICLE TO BWM (FOR NON-SELL)
          '========================================================
          If SellingStatus = "NON-SELL" Then
             ReturnFunction = MyProxy.RegisterNewVehicle(BodyStyle, Model,
    MyUtils.ConvertDateForBwmWebService(DateRegistered), RegNumber, Mileage, FuelType,
    CarDescription, "SPOCK-" & UserName)
          End If
9                                                                    2. UPDATE VEHICLE




      '========================================================
      ' 2.2) UPDATE TO BWM WEBSERVICE
      '========================================================
      ReturnFunction = MyProxy.UpdateAVehicle(BodyStyle, Model,
MyUtils.ConvertDateForBwmWebService(DateRegistered), RegNumber, Mileage,
FuelType, CarDescription, "SPOCK-" & UserName)
3. UPDATE SOLD VEHICLE
10
                                                                       (VEHICLE FOR SALES)




                                                                                         Consuming Web Service



                                                                       '========================================================
*Option if want mark SOLD in garage DB and Delete in BWM website            ' 2.2.1) UPDATE TO BWM WEBSERVICE
                                                                            '========================================================
                                                                            ReturnFunction = MyProxy.SetVehicleAsSold(RegNumber, Price,
                                                                       UserName)
                                                                            '========================================================
                                                                            ' 2.2.2) DELETE VEHICLE FROM SALES TABLE
                                                                            ' DELETE IS OPTION IN SELLING PAGE
                                                                            '========================================================
                                                                            'ReturnFunction = MyProxy.DeleteVehicleFromSalesTable(RegNumber)
11
                     4. DELETE VEHICLE
     (NON-SELL VEHICLE USING SECURED XML)




                                  Consuming Web Service



                   '========================================================
                    ' 2.1) AUTHEN TO BWM SITE
                    '========================================================
                    Dim Auth As New AuthenticationHeader()
                    Auth.UserName = "tutor"
                    Auth.PassWord = "password"
                    MyProxy.AuthenticationHeaderValue = Auth
                    '========================================================
                    ' 2.2) DELETE VEHICLE FROM REGISTER TABLE (CALL WEBSERVICE)
                    '========================================================
                    ReturnFunction = MyProxy.DeleteVehicleFromRegisterTable(RegNumber)
WEB SERVICES
PROVIDED BY GARAGE (SPOCK)




               12
13                         1. GET VEHICLE INFORMATION




                               • Parameter: Vehicle Register No
                               • Return: DataSet (0 or 1 record)




     Only basic vehicle information transferred to BWM website
14        2. GET VEHICLE INFORMATION (ALL)



                       • Parameter: Vehicle Register No
                       • Return: DataSet (0 or 1 record)




     All Information collected in garage database
3. GET ORDER INFORMATION
15
                                            (SOLD CAR)
                          • Parameter: From Date and To Date
                          • Return:    DataSet
                          • Only:      SOLD Vehicle




     This function used for BWM to monitor vehicle sold by garage
CLASSES

  UI (aspx files)
                      We separate data layer from business logic by using three
                      classes: Car, User and Utils
Business Logic (VB
      files)
                      Our design
                      -   SQL queries are used only in classes (Except to quick search feature)
   Data Layer
   (Class files)      -   No SQL queries in VB, aspx, asmx files
                      -   User interfaces (aspx files) are separated from business logic (vb files)
                      -   Data layer is separated from business logic layer
       DB                                                   16
17                        1. CLASS “CAR”




     Variable in class   Functions in class
18                                   2. CLASS “USER”




                                                 Use SQL DataReader
                                                   to collect data




Authentication and account functions   Authentication User
19                                     3. CLASS “UTILS”




Class Utils used for general functions
        Benefits: Reusability
DATA ACCESS (EXAMPLES)




            20
21                                                                                  1. REGISTER VEHICLE
                                                                                          (FUNCTION IN CLASS “CAR”)

 '================================================================                             '=============================================================
    ' FUNCTION#1: REGISTER CAR_INFO TO DB                                                      ' 3) EXECUTE INSERT COMMAND
  '================================================================                            '=============================================================
    Function RegisterCar() As Boolean                                                          Dim cnString As String = Global.Resources.Resource.cnString
       '============================================================                           Dim ds As New SqlDataSource
       ' 1) DECLAR VARIABLE                                                                    Try
       '============================================================                              ds.ConnectionString = cnString
       Dim ReturnFunction As Boolean = True                                                       ds.InsertCommand = SqlCmd
       Dim MyUtils As New Utils                                                                   ds.Insert()
       Dim SqlCmd As String = ""                                                                  ReturnFunction = True
       '============================================================                           Catch
       ' 2) PREPARE INSERT COMMAND                                                                ReturnFunction = False
       '============================================================                           End Try
       SqlCmd = "INSERT INTO TM_CAR "                                                          '============================================================
       SqlCmd = SqlCmd & "(RegNo, BodyStyle, Model, DateRegistered, Mileage,                   ' 4) RETURN VARIABLE
FuelType, CarDescription, IsEnable, DateAdded, AddedBy, DateUpdated,                           '============================================================
UpdatedBy, DateSold, SoldBy, Price, SellingStatus, SynStatus, SynTime,                         Return ReturnFunction
Transmission, Colour, InteriorDetails, AdditionalEquipments, StandardEquipments,             End Function
TechnicalSpecification, CustFullName, CustAddress, CustContactNo, CustEmail,
Comment1, Comment2) "
       SqlCmd = SqlCmd & " VALUES ('" & GetNextRegisterNo() & "' ,'" & BodyStyle &
"' ,'" & Model & "' ,'" & MyUtils.ConvertDateForSQL(DateRegistered) & "' ,"
       SqlCmd = SqlCmd & Mileage & " ,'" & FuelType & "','" & CarDescription & "' ,"
       SqlCmd = SqlCmd & IsEnable & " ,'" &
                                                                                              Use SqlDataSource to register vehicle
MyUtils.ConvertDateForSQL(DateAdded) & "' ,'" & AddedBy & "' ,'"
       SqlCmd = SqlCmd & MyUtils.ConvertDateForSQL(DateUpdated) & "' ,'" &
UpdatedBy & "' ,'" & MyUtils.ConvertDateForSQL(DateSold) & "' ,'" & SoldBy & "' ,"
       SqlCmd = SqlCmd & Price & " ,'" & SellingStatus & "' ,'" & SynStatus & "' ,'" &
SynTime & "' ,'" & Transmission & "' ,'" & Colour & "' ,'" & InteriorDetails & "' ,'" &
AdditionalEquipments & "' ,'" & StandardEquipments & "' ,'" & TechnicalSpecification
& "' ,'" & CustFullName & "' ,'" & CustAddress & "' ,'" & CustContactNo & "' ,'" &
                                                                                                 Register Types (SellingStatus Column)
CustEmail & "' ,'" & Comment1 & "' ,'" & Comment2 & "') "
                                                                                              1. SELL:                       Register For Sales
                                                                                              2. NON-SALES:                  Register a Vehicle
                                                                                              3. SOLD:                       Sold Vehicle
2. UPDATE VEHICLE
          22
                                                                                 (FUNCTION IN CLASS “CAR”)

'================================================================                    '============================================================
  ' FUNCTION#6: UPDATE SELLING_CAR_INFO TO DB                                              ' 2.3) FILL DATA TO DATASET

'================================================================                    '============================================================
   Public Function UpdateSellingCarInfoByDataSet(ByVal RegNumber As String) As             ds.Tables(0).Rows(0).Item("DateUpdated") = Now
Boolean                                                                                    ds.Tables(0).Rows(0).Item("UpdatedBy") = UpdatedBy
     '============================================================                         ds.Tables(0).Rows(0).Item("DateSold") = DateSold
     ' 1) DECLARE VARIABLE                                                                 ds.Tables(0).Rows(0).Item("SoldBy") = SoldBy
     '============================================================                         ds.Tables(0).Rows(0).Item("Price") = Price
     Dim MyUtils As New Utils                                                              ds.Tables(0).Rows(0).Item("SellingStatus") = SellingStatus
     Dim cn As SqlConnection                                                               ds.Tables(0).Rows(0).Item("SynStatus") = SynStatus
     Dim da As SqlDataAdapter                                                              ds.Tables(0).Rows(0).Item("SynTime") = SynTime
     Dim ds As New DataSet                                                                 ds.Tables(0).Rows(0).Item("CustFullName") = CustFullName
     Dim cnString As String = Global.Resources.Resource.cnString                           ds.Tables(0).Rows(0).Item("CustAddress") = CustAddress
     Dim sqlCmd As String = "SELECT * FROM TM_CAR WHERE RegNo = '" &                       ds.Tables(0).Rows(0).Item("CustContactNo") = CustContactNo
RegNumber & "'"                                                                            ds.Tables(0).Rows(0).Item("CustEmail") = CustEmail
     '============================================================                         ds.Tables(0).Rows(0).Item("Comment2") = Comment2
     ' 2) GET DATA AND UPDATE DATA TO DB
     '============================================================                   '============================================================
     Try                                                                                   ' 4) UPDATE DATA IN DB
        '========================================================
        ' 2.1) FILL DATA FROM DATABASE TO DATASET                                    '============================================================
        '========================================================                          Dim cmb As New SqlCommandBuilder(da)
        cn = New SqlConnection(cnString)                                                   da.Update(ds, "TM_CAR")
        da = New SqlDataAdapter(sqlCmd, cn)                                                ds.AcceptChanges()
        da.Fill(ds, "TM_CAR")
        '========================================================                    '============================================================
        ' 2.2) NOT FOUND REG_NO                                                            ' 5) UPDATE SUCCESSFUL
        '========================================================
        If ds.Tables(0).Rows.Count <> 1 Then                                         '============================================================
            Return False                                                                   Return True
        End If                                                                           Catch ex As Exception

                                                                                     '============================================================
                                                                                           ' 6) UPDATE ERROR
       Use DataSet and SQLDataAdaptor to                                             '============================================================

                update database                                                             Return False
                                                                                          End Try
                                                                                        End Function
3. DELETE VEHICLE
       23
                                                                        (FUNCTION IN CLASS “CAR”)


'================================================================          '================================================================
  ' FUNCTION#8: DELETE CAR_INFO FROM DATABASE                                 ' FUNCTION#10: DELETE VEHICLE FROM REGISTER TABLE (CALL WEBSERVICE)
                                                                              '================================================================
  '================================================================
                                                                              Function DeleteVehicleFromRegisterTableAtBwm(ByVal RegNumber As String) As Boolean
  Public Function DeleteCarInfo(ByVal RegNumber As String) As Boolean            '============================================================
     '============================================================               ' 1) RETURN VARIABLE
     ' 1) RETURN VARIABLE                                                        '============================================================
     '============================================================               Dim ReturnFunction As Boolean = False
     Dim ReturnFunction As Boolean = True                                        Dim MyUtils As New Utils
                                                                                 Dim MyProxy = New BMWHOWebService.BMWHOWebService
     Dim MyUtils As New Utils
                                                                                 '============================================================
     '============================================================               ' 2) PREPARE INSERT COMMAND
     ' 2) PREPARE INSERT COMMAND                                                 '============================================================
     '============================================================               Try
     Dim SqlCmd As String = ""                                                      '========================================================
     SqlCmd = "DELETE TM_CAR "                                                      ' 2.1) AUTHEN TO BWM SITE
                                                                                    '========================================================
     SqlCmd = SqlCmd & "WHERE RegNo = '" & RegNumber & "' "
                                                                                    Dim Auth As New AuthenticationHeader()
     '============================================================                  Auth.UserName = "tutor"
     ' 3) EXECUTE DELETE COMMAND                                                    Auth.PassWord = "password"
     '============================================================                  MyProxy.AuthenticationHeaderValue = Auth
     Dim cnString As String = Global.Resources.Resource.cnString                    '========================================================
     Dim ds As New SqlDataSource                                                    ' 2.2) DELETE VEHICLE FROM REGISTER TABLE (CALL WEBSERVICE)
                                                                                    '========================================================
     Try
                                                                                    ReturnFunction = MyProxy.DeleteVehicleFromRegisterTable(RegNumber)
        ds.ConnectionString = cnString                                              '============================================================
        ds.DeleteCommand = SqlCmd                                                   ' 3) UPDATE SYN_STATUS OF UPDATING TO BWM_WEBSERVICE (AYSN)
        ds.Delete()                                                                 '============================================================
        ReturnFunction = True                                                       '============================================================
     Catch                                                                          ' 3.1) MARK "COMPLETED" INTO DB
                                                                                    '============================================================
        ReturnFunction = False
                                                                                    If ReturnFunction = True Then
     End Try                                                                           UpdateSynWebServiceStatus(RegNumber, "COMPLETED")
     '============================================================                  End If
     ' 4) RETURN VARIABLE                                                           '============================================================
     '============================================================                  ' 3.2) MARK "INCOMPLETED" INTO DB
     Return ReturnFunction                                                          '============================================================
                                                                                    If ReturnFunction = False Then
  End Function
                                                                                       UpdateSynWebServiceStatus(RegNumber, "INCOMPLETED")
                                                                                    End If
                                                                                 Catch
                                                                                    '========================================================
                                                                                    ' 2.2) UPDATE TO WS INCOMPLETEED
                                                                                    '========================================================
           Use SQLDataSource and SQL                                                ReturnFunction = False
                                                                                 End Try
                                                                                 '============================================================
            Command to delete data                                               ' 4) RETURN VARIABLE
                                                                                 '============================================================
                                                                                 Return ReturnFunction
4. GET CAR INFORMATION
              24
                                                                                  (FUNCTION IN CLASS “CAR”)

                                                                                                     '=============================================
'================================================================                                    ' B) GET DATA
                                                                                                     '=============================================
   ' FUNCTION#4: GET CAR_INFO FROM DB                                                                While (dr.Read)
   '================================================================                                    RegNo = dr.GetValue(0)
   Public Function GetCarInfo(ByVal RegNumber As String) As Boolean                                     BodyStyle = dr.GetValue(1)
                                                                                                        Model = dr.GetValue(2)
      '============================================================                                     DateRegistered = dr.GetValue(3)
      ' 1) DECLAR VARIABLE                                                                              Mileage = dr.GetValue(4)
      '============================================================                                     FuelType = dr.GetValue(5)
                                                                                                        CarDescription = dr.GetValue(6)
      Dim ReturnFunction As Boolean = True                                                              IsEnable = dr.GetValue(7)
      '============================================================
      ' 2) OPEN DATABASE CONNECTION
                                                                                                        DateAdded = dr.GetValue(8)
                                                                                                        AddedBy = dr.GetValue(9)             Use SQLDataReader
                                                                                                        DateUpdated = dr.GetValue(10)
      '============================================================
      Dim cn As New System.Data.SqlClient.SqlConnection(Global.Resources.Resource.cnString)
                                                                                                        UpdatedBy = dr.GetValue(11)
                                                                                                        DateSold = dr.GetValue(12)             to collect data
      Try                                                                                               SoldBy = dr.GetValue(13)
                                                                                                        Price = dr.GetValue(14)
         '========================================================                                      SellingStatus = dr.GetValue(15)
         ' 3) CONNECT DATA                                                                              SynStatus = dr.GetValue(16)
         '========================================================                                      SynTime = dr.GetValue(17)
                                                                                                        Transmission = dr.GetValue(18)
         Dim sql As String = ""                                                                         Colour = dr.GetValue(19)
         sql = sql & "SELECT * FROM TM_CAR "                                                            InteriorDetails = dr.GetValue(20)
         sql = sql & "WHERE UPPER(RegNo) = UPPER('" & RegNumber.ToString & "') "                        AdditionalEquipments = dr.GetValue(21)
                                                                                                        StandardEquipments = dr.GetValue(22)
         Dim cmd As New System.Data.SqlClient.SqlCommand(sql, cn)                                       TechnicalSpecification = dr.GetValue(23)
         cn.Open()                                                                                      CustFullName = dr.GetValue(24)
         '========================================================                                      CustAddress = dr.GetValue(25)
                                                                                                        CustContactNo = dr.GetValue(26)
         ' 4) RETRIVE DATA                                                                              CustEmail = dr.GetValue(27)
         '========================================================                                      Comment1 = dr.GetValue(28)
         Dim dr As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader                              Comment2 = dr.GetValue(29)
                                                                                                     End While
         '========================================================                                End If
         ' 5.1) NOT FOUND USERID                                                                  '=============================================
         '========================================================                                ' 6) CLOSE DATABASE
                                                                                                  '=============================================
         If Not dr.HasRows Then                                                                   cn.Close()
             ReturnFunction = False                                                               '=============================================
         End If                                                                                   ' 7)RETURN VALUE
                                                                                                  '=============================================
         '========================================================                                Return ReturnFunction
         ' 5.2) FOUND USERID                                                                    Catch ex As Exception
         '========================================================                                '========================================================
                                                                                                  ' RETURN FALSE
         If dr.HasRows Then                                                                       '========================================================
             '===================================================                                 Return False
             ' A) FOUND USER ID                                                                   '========================================================
                                                                                                  ' ANY ERROR CASE, CLOSE DB CONNECTION
             '===================================================                                 '========================================================
             ReturnFunction = True                                                                cn.Close()
                                                                                                End Try
                                                                                                Return True
                                                                                              End Function
5 . U SER A U T HEN IC AT ION & R EG IST ER AT IO N
      25
                                                                      (F U N C T IO N IN C L A SS “ U SER ” )


'================================================================
  ' FUNCTION#1: LOGIN                                                                        '================================================================
  '================================================================                              ' FUNCTION#3: RESGISTER_USER (PERMISSION ONLY ADMIN)
  Function Login(ByVal UserName As String, ByVal UserPassword As String) As Boolean            '================================================================
     '============================================================                               Function RegisterUser() As Boolean
     ' OPEN DATABASE CONNECTION                                                                     '============================================================
     '============================================================
                                                                                                    ' RETURN VARIABLE
     Dim cn As New System.Data.SqlClient.SqlConnection(Global.Resources.Resource.cnString)
     Try
                                                                                                    '============================================================
        '========================================================                                   Dim ReturnFunction As Boolean = True
        ' CONNECT DATA                                                                              '============================================================
        '========================================================                                   ' PREPARE INSERT COMMAND
        Dim sql As String = ""                                                                      '============================================================
        sql = sql & "SELECT * FROM TM_USER "                                                        Dim MyUtils As New Utils
        sql = sql & "WHERE UPPER(UserId) = UPPER('" & UserName.ToString & "') AND "
                                                                                                    Dim SqlCmd As String = ""
        sql = sql & "UPPER(UserPassword) = UPPER('" & UserPassword.ToString & "')"
        Dim cmd As New System.Data.SqlClient.SqlCommand(sql, cn)
                                                                                                    SqlCmd = "INSERT INTO TM_USER "
        cn.Open()                                                                                   SqlCmd = SqlCmd &
        '========================================================                            "(UserId,UserPassword,UserRole,UserFirstName,UserLastName,UserEmail,UserDat
        ' SELECT VALUE                                                                       eRegistered) "
        '========================================================                                   SqlCmd = SqlCmd & " VALUES ('" & UserId & "' ,'" & UserPassword & "' ,'" &
        Dim dr As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader                    UserRole & "' ,'" & UserFirstName & "' ,'" & UserLastName & "' ,'" & UserEmail & "' ,'"
        '========================================================
                                                                                             & MyUtils.ConvertDateForSQL(UserDateRegistered) & "')"
        ' WRONG USER & PASSWORD
        '========================================================
        If Not dr.HasRows Then                                                               '=================================================================
            Return False                                                                         'EXECUTE INSERT COMMAND
        End If
        '========================================================                            '=================================================================
        ' CORRECT USER & PASSWORD                                                                 Dim cnString As String = Global.Resources.Resource.cnString
        '========================================================
                                                                                                  Dim ds As New SqlDataSource
        If dr.HasRows Then
            Return True
                                                                                                  Try
                                                                                                     ds.ConnectionString = cnString
        End If
        cn.Close()
     Catch ex As Exception
                                                                                                     ds.InsertCommand = SqlCmd
                                                                                                     ds.Insert()
                                                                                                                                                       Use
        '========================================================
        ' RETURN FALSE
                                                                     Use                             ReturnFunction = True
                                                                                                  Catch
                                                                                                                                                 SQLDataSoruce
        '========================================================
        Return False
        '========================================================
                                                                 DataReader                          ReturnFunction = False
                                                                                                  End Try                                            and SQL
                                                                                                  '============================================================
        ' ANY ERROR CASE, CLOSE DB CONNECTION
                                                                to collect data
        '========================================================                                 ' RETURN VARIABLE                               Command to
        cn.Close()                                                                                '============================================================
     End Try
     Return True
                                                                                                  Return ReturnFunction
                                                                                                End Function
                                                                                                                                                   insert data
  End Function
CONFIGURATION FILES




            26
27                           WEB.CONFIG




      Connection Strings for
     .net controls in aspx files




     Web Service References
28                                                                   RESOURCE.RESX




       Flexible to change connection String by resource.resx file



                                                             Connection Strings
                                                             for source code in
                                                                   VB files




                                                     Benefit:
Flexible to change variable of connection strings e.g. Server Name, Database Name, DB User and DB Password.
                              The cnString variable is used in Car and User classes

More Related Content

PDF
Jasigsakai12 columbia-customizes-cas
PDF
Beginner’s tutorial (part 2) how to integrate redux-saga in react native app
PDF
Aspnet auth advanced_cs
PPTX
23 gather requirements_web_services_3
PDF
Analyse Marketing Communicatie Plan BMW-i_final (15)
PPT
Advertisment
PPTX
carshroommmrrrrrrrrrrrrrrrrrrrrrrrrrrrr.pptx
PPTX
Online vehicle showroom DB project
Jasigsakai12 columbia-customizes-cas
Beginner’s tutorial (part 2) how to integrate redux-saga in react native app
Aspnet auth advanced_cs
23 gather requirements_web_services_3
Analyse Marketing Communicatie Plan BMW-i_final (15)
Advertisment
carshroommmrrrrrrrrrrrrrrrrrrrrrrrrrrrr.pptx
Online vehicle showroom DB project

Similar to 22 code snippet_web_services_2 (20)

DOC
Documentation Assignment 97 03
PDF
Mongo db meetuppresentation-2014-v5-1
PDF
Online_Car_Rental_System_A_Project_Prese.pdf
PPT
Salesforce and sap integration
PPT
sibsvetofor.ru
PPTX
I haven't received the money yet full course
PDF
An Enhanced User Experience for Automobile Purchases with the WSO2 Mobile Ser...
PPTX
Car Rent System based on PHP,HTMl,CSS,JS and MySQL..pptx
PPTX
Vehicle Tracking System Java
PDF
AutoBooom write up-sample or Details
PDF
Rapid applications development update12-06-14
PPTX
Presentation on Used Car
PPT
Fabricare 2012
PPTX
Fleet Management Solutions - Fastrax
PDF
Car Rental Agency - Database - MySQL
DOC
Gbi exercise sd2 (1)
PPTX
Pss billing overview 1
DOC
Car servicing booking
PPT
Online Car Purchase
PPTX
Wings ERP Auto Dealers
Documentation Assignment 97 03
Mongo db meetuppresentation-2014-v5-1
Online_Car_Rental_System_A_Project_Prese.pdf
Salesforce and sap integration
sibsvetofor.ru
I haven't received the money yet full course
An Enhanced User Experience for Automobile Purchases with the WSO2 Mobile Ser...
Car Rent System based on PHP,HTMl,CSS,JS and MySQL..pptx
Vehicle Tracking System Java
AutoBooom write up-sample or Details
Rapid applications development update12-06-14
Presentation on Used Car
Fabricare 2012
Fleet Management Solutions - Fastrax
Car Rental Agency - Database - MySQL
Gbi exercise sd2 (1)
Pss billing overview 1
Car servicing booking
Online Car Purchase
Wings ERP Auto Dealers
Ad

More from Traitet Thepbandansuk (20)

PDF
IT_FOR_BUSINESS_30NOV15
PDF
06 1 st_honour_award_certification.pdf
PPS
Change attitude change life scg
DOCX
01 dissertation_Restaurant e-menu on iPad
DOCX
MSc Dissertation: Restaurant e-menu software on iPad
PPTX
03 outcome navigator
PPTX
O1 research overview
PPTX
D4 recommendation emenu_development
PPTX
D3 users perceptions_emenu
PPTX
D2 users perceptions_features
PPTX
A30 test functional_requirements
PPTX
A22 functions on_web
PPTX
A21 functions on_ipad
PPTX
A2 annotation approach
PPTX
A1 annotation knowledge
PPTX
A1 analysis design
PPTX
10 wrap around_conclusion
PPTX
02 project plan11_aug12
PPTX
00 how to_test_app
PPTX
R01 all references
IT_FOR_BUSINESS_30NOV15
06 1 st_honour_award_certification.pdf
Change attitude change life scg
01 dissertation_Restaurant e-menu on iPad
MSc Dissertation: Restaurant e-menu software on iPad
03 outcome navigator
O1 research overview
D4 recommendation emenu_development
D3 users perceptions_emenu
D2 users perceptions_features
A30 test functional_requirements
A22 functions on_web
A21 functions on_ipad
A2 annotation approach
A1 annotation knowledge
A1 analysis design
10 wrap around_conclusion
02 project plan11_aug12
00 how to_test_app
R01 all references
Ad

Recently uploaded (20)

PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPT
Teaching material agriculture food technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Machine learning based COVID-19 study performance prediction
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Diabetes mellitus diagnosis method based random forest with bat algorithm
Encapsulation_ Review paper, used for researhc scholars
Understanding_Digital_Forensics_Presentation.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Mobile App Security Testing_ A Comprehensive Guide.pdf
Teaching material agriculture food technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Chapter 3 Spatial Domain Image Processing.pdf
Encapsulation theory and applications.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
The AUB Centre for AI in Media Proposal.docx
Review of recent advances in non-invasive hemoglobin estimation
Machine learning based COVID-19 study performance prediction
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
MYSQL Presentation for SQL database connectivity
Dropbox Q2 2025 Financial Results & Investor Presentation
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton

22 code snippet_web_services_2

  • 1. CODE SNIPPETS FOR BWM – MOTOR FRANCHISE PROJECT Created by Team Members Reviewed by Team Members Module: Web Services Created Date 19 April 2012 Assignment: Team Assignment Revised Date 27 April 2012 Revision No. 1.2 Team Name: SPOCK Document Name F03-001
  • 3. 3 1.VALIDATION BY CONTROLS Register User Register Vehicle Required Field Validators
  • 4. 4 2.VALIDATION BY CONTROLS Validate Price Validate Price and Mileage Price must be number Price and mileage must more than 0
  • 5. 5 3.VALIDATION BY CONTROLS Validate E-mail Regular Expression Validator User must fill right format of e-mail
  • 6. 6 4. CODE VALIDATION Date Validation Validate Date ex. 31 April 2012 is a incorrect date
  • 7. CONSUMING WEB SERVICES FROM BWM SITE 7
  • 8. 8 1.REGISTER VEHICLE Consuming Web Services '======================================================== ' 2.2.2) REGISTER VEHICLE TO BWM '======================================================== '======================================================== ' 2.2.2.1) REGISTER VEHICLE TO BWM (FOR SELL) '======================================================== If SellingStatus = "SELL" Then ReturnFunction = MyProxy.RegisterVehicleForSale(BodyStyle, Model, MyUtils.ConvertDateForBwmWebService(DateRegistered), RegNumber, Mileage, FuelType, CarDescription, Price, DateAdded, "SPOCK-" & UserName) End If '======================================================== ' 2.2.2.2) REGISTER VEHICLE TO BWM (FOR NON-SELL) '======================================================== If SellingStatus = "NON-SELL" Then ReturnFunction = MyProxy.RegisterNewVehicle(BodyStyle, Model, MyUtils.ConvertDateForBwmWebService(DateRegistered), RegNumber, Mileage, FuelType, CarDescription, "SPOCK-" & UserName) End If
  • 9. 9 2. UPDATE VEHICLE '======================================================== ' 2.2) UPDATE TO BWM WEBSERVICE '======================================================== ReturnFunction = MyProxy.UpdateAVehicle(BodyStyle, Model, MyUtils.ConvertDateForBwmWebService(DateRegistered), RegNumber, Mileage, FuelType, CarDescription, "SPOCK-" & UserName)
  • 10. 3. UPDATE SOLD VEHICLE 10 (VEHICLE FOR SALES) Consuming Web Service '======================================================== *Option if want mark SOLD in garage DB and Delete in BWM website ' 2.2.1) UPDATE TO BWM WEBSERVICE '======================================================== ReturnFunction = MyProxy.SetVehicleAsSold(RegNumber, Price, UserName) '======================================================== ' 2.2.2) DELETE VEHICLE FROM SALES TABLE ' DELETE IS OPTION IN SELLING PAGE '======================================================== 'ReturnFunction = MyProxy.DeleteVehicleFromSalesTable(RegNumber)
  • 11. 11 4. DELETE VEHICLE (NON-SELL VEHICLE USING SECURED XML) Consuming Web Service '======================================================== ' 2.1) AUTHEN TO BWM SITE '======================================================== Dim Auth As New AuthenticationHeader() Auth.UserName = "tutor" Auth.PassWord = "password" MyProxy.AuthenticationHeaderValue = Auth '======================================================== ' 2.2) DELETE VEHICLE FROM REGISTER TABLE (CALL WEBSERVICE) '======================================================== ReturnFunction = MyProxy.DeleteVehicleFromRegisterTable(RegNumber)
  • 12. WEB SERVICES PROVIDED BY GARAGE (SPOCK) 12
  • 13. 13 1. GET VEHICLE INFORMATION • Parameter: Vehicle Register No • Return: DataSet (0 or 1 record) Only basic vehicle information transferred to BWM website
  • 14. 14 2. GET VEHICLE INFORMATION (ALL) • Parameter: Vehicle Register No • Return: DataSet (0 or 1 record) All Information collected in garage database
  • 15. 3. GET ORDER INFORMATION 15 (SOLD CAR) • Parameter: From Date and To Date • Return: DataSet • Only: SOLD Vehicle This function used for BWM to monitor vehicle sold by garage
  • 16. CLASSES UI (aspx files) We separate data layer from business logic by using three classes: Car, User and Utils Business Logic (VB files) Our design - SQL queries are used only in classes (Except to quick search feature) Data Layer (Class files) - No SQL queries in VB, aspx, asmx files - User interfaces (aspx files) are separated from business logic (vb files) - Data layer is separated from business logic layer DB 16
  • 17. 17 1. CLASS “CAR” Variable in class Functions in class
  • 18. 18 2. CLASS “USER” Use SQL DataReader to collect data Authentication and account functions Authentication User
  • 19. 19 3. CLASS “UTILS” Class Utils used for general functions Benefits: Reusability
  • 21. 21 1. REGISTER VEHICLE (FUNCTION IN CLASS “CAR”) '================================================================ '============================================================= ' FUNCTION#1: REGISTER CAR_INFO TO DB ' 3) EXECUTE INSERT COMMAND '================================================================ '============================================================= Function RegisterCar() As Boolean Dim cnString As String = Global.Resources.Resource.cnString '============================================================ Dim ds As New SqlDataSource ' 1) DECLAR VARIABLE Try '============================================================ ds.ConnectionString = cnString Dim ReturnFunction As Boolean = True ds.InsertCommand = SqlCmd Dim MyUtils As New Utils ds.Insert() Dim SqlCmd As String = "" ReturnFunction = True '============================================================ Catch ' 2) PREPARE INSERT COMMAND ReturnFunction = False '============================================================ End Try SqlCmd = "INSERT INTO TM_CAR " '============================================================ SqlCmd = SqlCmd & "(RegNo, BodyStyle, Model, DateRegistered, Mileage, ' 4) RETURN VARIABLE FuelType, CarDescription, IsEnable, DateAdded, AddedBy, DateUpdated, '============================================================ UpdatedBy, DateSold, SoldBy, Price, SellingStatus, SynStatus, SynTime, Return ReturnFunction Transmission, Colour, InteriorDetails, AdditionalEquipments, StandardEquipments, End Function TechnicalSpecification, CustFullName, CustAddress, CustContactNo, CustEmail, Comment1, Comment2) " SqlCmd = SqlCmd & " VALUES ('" & GetNextRegisterNo() & "' ,'" & BodyStyle & "' ,'" & Model & "' ,'" & MyUtils.ConvertDateForSQL(DateRegistered) & "' ," SqlCmd = SqlCmd & Mileage & " ,'" & FuelType & "','" & CarDescription & "' ," SqlCmd = SqlCmd & IsEnable & " ,'" & Use SqlDataSource to register vehicle MyUtils.ConvertDateForSQL(DateAdded) & "' ,'" & AddedBy & "' ,'" SqlCmd = SqlCmd & MyUtils.ConvertDateForSQL(DateUpdated) & "' ,'" & UpdatedBy & "' ,'" & MyUtils.ConvertDateForSQL(DateSold) & "' ,'" & SoldBy & "' ," SqlCmd = SqlCmd & Price & " ,'" & SellingStatus & "' ,'" & SynStatus & "' ,'" & SynTime & "' ,'" & Transmission & "' ,'" & Colour & "' ,'" & InteriorDetails & "' ,'" & AdditionalEquipments & "' ,'" & StandardEquipments & "' ,'" & TechnicalSpecification & "' ,'" & CustFullName & "' ,'" & CustAddress & "' ,'" & CustContactNo & "' ,'" & Register Types (SellingStatus Column) CustEmail & "' ,'" & Comment1 & "' ,'" & Comment2 & "') " 1. SELL: Register For Sales 2. NON-SALES: Register a Vehicle 3. SOLD: Sold Vehicle
  • 22. 2. UPDATE VEHICLE 22 (FUNCTION IN CLASS “CAR”) '================================================================ '============================================================ ' FUNCTION#6: UPDATE SELLING_CAR_INFO TO DB ' 2.3) FILL DATA TO DATASET '================================================================ '============================================================ Public Function UpdateSellingCarInfoByDataSet(ByVal RegNumber As String) As ds.Tables(0).Rows(0).Item("DateUpdated") = Now Boolean ds.Tables(0).Rows(0).Item("UpdatedBy") = UpdatedBy '============================================================ ds.Tables(0).Rows(0).Item("DateSold") = DateSold ' 1) DECLARE VARIABLE ds.Tables(0).Rows(0).Item("SoldBy") = SoldBy '============================================================ ds.Tables(0).Rows(0).Item("Price") = Price Dim MyUtils As New Utils ds.Tables(0).Rows(0).Item("SellingStatus") = SellingStatus Dim cn As SqlConnection ds.Tables(0).Rows(0).Item("SynStatus") = SynStatus Dim da As SqlDataAdapter ds.Tables(0).Rows(0).Item("SynTime") = SynTime Dim ds As New DataSet ds.Tables(0).Rows(0).Item("CustFullName") = CustFullName Dim cnString As String = Global.Resources.Resource.cnString ds.Tables(0).Rows(0).Item("CustAddress") = CustAddress Dim sqlCmd As String = "SELECT * FROM TM_CAR WHERE RegNo = '" & ds.Tables(0).Rows(0).Item("CustContactNo") = CustContactNo RegNumber & "'" ds.Tables(0).Rows(0).Item("CustEmail") = CustEmail '============================================================ ds.Tables(0).Rows(0).Item("Comment2") = Comment2 ' 2) GET DATA AND UPDATE DATA TO DB '============================================================ '============================================================ Try ' 4) UPDATE DATA IN DB '======================================================== ' 2.1) FILL DATA FROM DATABASE TO DATASET '============================================================ '======================================================== Dim cmb As New SqlCommandBuilder(da) cn = New SqlConnection(cnString) da.Update(ds, "TM_CAR") da = New SqlDataAdapter(sqlCmd, cn) ds.AcceptChanges() da.Fill(ds, "TM_CAR") '======================================================== '============================================================ ' 2.2) NOT FOUND REG_NO ' 5) UPDATE SUCCESSFUL '======================================================== If ds.Tables(0).Rows.Count <> 1 Then '============================================================ Return False Return True End If Catch ex As Exception '============================================================ ' 6) UPDATE ERROR Use DataSet and SQLDataAdaptor to '============================================================ update database Return False End Try End Function
  • 23. 3. DELETE VEHICLE 23 (FUNCTION IN CLASS “CAR”) '================================================================ '================================================================ ' FUNCTION#8: DELETE CAR_INFO FROM DATABASE ' FUNCTION#10: DELETE VEHICLE FROM REGISTER TABLE (CALL WEBSERVICE) '================================================================ '================================================================ Function DeleteVehicleFromRegisterTableAtBwm(ByVal RegNumber As String) As Boolean Public Function DeleteCarInfo(ByVal RegNumber As String) As Boolean '============================================================ '============================================================ ' 1) RETURN VARIABLE ' 1) RETURN VARIABLE '============================================================ '============================================================ Dim ReturnFunction As Boolean = False Dim ReturnFunction As Boolean = True Dim MyUtils As New Utils Dim MyProxy = New BMWHOWebService.BMWHOWebService Dim MyUtils As New Utils '============================================================ '============================================================ ' 2) PREPARE INSERT COMMAND ' 2) PREPARE INSERT COMMAND '============================================================ '============================================================ Try Dim SqlCmd As String = "" '======================================================== SqlCmd = "DELETE TM_CAR " ' 2.1) AUTHEN TO BWM SITE '======================================================== SqlCmd = SqlCmd & "WHERE RegNo = '" & RegNumber & "' " Dim Auth As New AuthenticationHeader() '============================================================ Auth.UserName = "tutor" ' 3) EXECUTE DELETE COMMAND Auth.PassWord = "password" '============================================================ MyProxy.AuthenticationHeaderValue = Auth Dim cnString As String = Global.Resources.Resource.cnString '======================================================== Dim ds As New SqlDataSource ' 2.2) DELETE VEHICLE FROM REGISTER TABLE (CALL WEBSERVICE) '======================================================== Try ReturnFunction = MyProxy.DeleteVehicleFromRegisterTable(RegNumber) ds.ConnectionString = cnString '============================================================ ds.DeleteCommand = SqlCmd ' 3) UPDATE SYN_STATUS OF UPDATING TO BWM_WEBSERVICE (AYSN) ds.Delete() '============================================================ ReturnFunction = True '============================================================ Catch ' 3.1) MARK "COMPLETED" INTO DB '============================================================ ReturnFunction = False If ReturnFunction = True Then End Try UpdateSynWebServiceStatus(RegNumber, "COMPLETED") '============================================================ End If ' 4) RETURN VARIABLE '============================================================ '============================================================ ' 3.2) MARK "INCOMPLETED" INTO DB Return ReturnFunction '============================================================ If ReturnFunction = False Then End Function UpdateSynWebServiceStatus(RegNumber, "INCOMPLETED") End If Catch '======================================================== ' 2.2) UPDATE TO WS INCOMPLETEED '======================================================== Use SQLDataSource and SQL ReturnFunction = False End Try '============================================================ Command to delete data ' 4) RETURN VARIABLE '============================================================ Return ReturnFunction
  • 24. 4. GET CAR INFORMATION 24 (FUNCTION IN CLASS “CAR”) '============================================= '================================================================ ' B) GET DATA '============================================= ' FUNCTION#4: GET CAR_INFO FROM DB While (dr.Read) '================================================================ RegNo = dr.GetValue(0) Public Function GetCarInfo(ByVal RegNumber As String) As Boolean BodyStyle = dr.GetValue(1) Model = dr.GetValue(2) '============================================================ DateRegistered = dr.GetValue(3) ' 1) DECLAR VARIABLE Mileage = dr.GetValue(4) '============================================================ FuelType = dr.GetValue(5) CarDescription = dr.GetValue(6) Dim ReturnFunction As Boolean = True IsEnable = dr.GetValue(7) '============================================================ ' 2) OPEN DATABASE CONNECTION DateAdded = dr.GetValue(8) AddedBy = dr.GetValue(9) Use SQLDataReader DateUpdated = dr.GetValue(10) '============================================================ Dim cn As New System.Data.SqlClient.SqlConnection(Global.Resources.Resource.cnString) UpdatedBy = dr.GetValue(11) DateSold = dr.GetValue(12) to collect data Try SoldBy = dr.GetValue(13) Price = dr.GetValue(14) '======================================================== SellingStatus = dr.GetValue(15) ' 3) CONNECT DATA SynStatus = dr.GetValue(16) '======================================================== SynTime = dr.GetValue(17) Transmission = dr.GetValue(18) Dim sql As String = "" Colour = dr.GetValue(19) sql = sql & "SELECT * FROM TM_CAR " InteriorDetails = dr.GetValue(20) sql = sql & "WHERE UPPER(RegNo) = UPPER('" & RegNumber.ToString & "') " AdditionalEquipments = dr.GetValue(21) StandardEquipments = dr.GetValue(22) Dim cmd As New System.Data.SqlClient.SqlCommand(sql, cn) TechnicalSpecification = dr.GetValue(23) cn.Open() CustFullName = dr.GetValue(24) '======================================================== CustAddress = dr.GetValue(25) CustContactNo = dr.GetValue(26) ' 4) RETRIVE DATA CustEmail = dr.GetValue(27) '======================================================== Comment1 = dr.GetValue(28) Dim dr As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader Comment2 = dr.GetValue(29) End While '======================================================== End If ' 5.1) NOT FOUND USERID '============================================= '======================================================== ' 6) CLOSE DATABASE '============================================= If Not dr.HasRows Then cn.Close() ReturnFunction = False '============================================= End If ' 7)RETURN VALUE '============================================= '======================================================== Return ReturnFunction ' 5.2) FOUND USERID Catch ex As Exception '======================================================== '======================================================== ' RETURN FALSE If dr.HasRows Then '======================================================== '=================================================== Return False ' A) FOUND USER ID '======================================================== ' ANY ERROR CASE, CLOSE DB CONNECTION '=================================================== '======================================================== ReturnFunction = True cn.Close() End Try Return True End Function
  • 25. 5 . U SER A U T HEN IC AT ION & R EG IST ER AT IO N 25 (F U N C T IO N IN C L A SS “ U SER ” ) '================================================================ ' FUNCTION#1: LOGIN '================================================================ '================================================================ ' FUNCTION#3: RESGISTER_USER (PERMISSION ONLY ADMIN) Function Login(ByVal UserName As String, ByVal UserPassword As String) As Boolean '================================================================ '============================================================ Function RegisterUser() As Boolean ' OPEN DATABASE CONNECTION '============================================================ '============================================================ ' RETURN VARIABLE Dim cn As New System.Data.SqlClient.SqlConnection(Global.Resources.Resource.cnString) Try '============================================================ '======================================================== Dim ReturnFunction As Boolean = True ' CONNECT DATA '============================================================ '======================================================== ' PREPARE INSERT COMMAND Dim sql As String = "" '============================================================ sql = sql & "SELECT * FROM TM_USER " Dim MyUtils As New Utils sql = sql & "WHERE UPPER(UserId) = UPPER('" & UserName.ToString & "') AND " Dim SqlCmd As String = "" sql = sql & "UPPER(UserPassword) = UPPER('" & UserPassword.ToString & "')" Dim cmd As New System.Data.SqlClient.SqlCommand(sql, cn) SqlCmd = "INSERT INTO TM_USER " cn.Open() SqlCmd = SqlCmd & '======================================================== "(UserId,UserPassword,UserRole,UserFirstName,UserLastName,UserEmail,UserDat ' SELECT VALUE eRegistered) " '======================================================== SqlCmd = SqlCmd & " VALUES ('" & UserId & "' ,'" & UserPassword & "' ,'" & Dim dr As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader UserRole & "' ,'" & UserFirstName & "' ,'" & UserLastName & "' ,'" & UserEmail & "' ,'" '======================================================== & MyUtils.ConvertDateForSQL(UserDateRegistered) & "')" ' WRONG USER & PASSWORD '======================================================== If Not dr.HasRows Then '================================================================= Return False 'EXECUTE INSERT COMMAND End If '======================================================== '================================================================= ' CORRECT USER & PASSWORD Dim cnString As String = Global.Resources.Resource.cnString '======================================================== Dim ds As New SqlDataSource If dr.HasRows Then Return True Try ds.ConnectionString = cnString End If cn.Close() Catch ex As Exception ds.InsertCommand = SqlCmd ds.Insert() Use '======================================================== ' RETURN FALSE Use ReturnFunction = True Catch SQLDataSoruce '======================================================== Return False '======================================================== DataReader ReturnFunction = False End Try and SQL '============================================================ ' ANY ERROR CASE, CLOSE DB CONNECTION to collect data '======================================================== ' RETURN VARIABLE Command to cn.Close() '============================================================ End Try Return True Return ReturnFunction End Function insert data End Function
  • 27. 27 WEB.CONFIG Connection Strings for .net controls in aspx files Web Service References
  • 28. 28 RESOURCE.RESX Flexible to change connection String by resource.resx file Connection Strings for source code in VB files Benefit: Flexible to change variable of connection strings e.g. Server Name, Database Name, DB User and DB Password. The cnString variable is used in Car and User classes