SlideShare una empresa de Scribd logo
1 de 28
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

Más contenido relacionado

Similar a CODE SNIPPETS FOR BWM MOTOR FRANCHISE PROJECT

Dynamic_UI_Concepts_version_2.pdf
Dynamic_UI_Concepts_version_2.pdfDynamic_UI_Concepts_version_2.pdf
Dynamic_UI_Concepts_version_2.pdfJoeRodriguez477329
 
Examples of-tca-apis
Examples of-tca-apisExamples of-tca-apis
Examples of-tca-apisMihai Fildan
 
Warranty processing recall bbp
Warranty processing recall bbpWarranty processing recall bbp
Warranty processing recall bbpvinayk_35919
 
FEATRURE BRIEF▶ NetBackup 7.6 - Direct virtual machine creation from backup w...
FEATRURE BRIEF▶ NetBackup 7.6 - Direct virtual machine creation from backup w...FEATRURE BRIEF▶ NetBackup 7.6 - Direct virtual machine creation from backup w...
FEATRURE BRIEF▶ NetBackup 7.6 - Direct virtual machine creation from backup w...Symantec
 
Warranty processing recall bbp
Warranty processing recall bbpWarranty processing recall bbp
Warranty processing recall bbpvinayk_35919
 
Workshop 27: Isomorphic web apps with ReactJS
Workshop 27: Isomorphic web apps with ReactJSWorkshop 27: Isomorphic web apps with ReactJS
Workshop 27: Isomorphic web apps with ReactJSVisual Engineering
 
Kubernetes and Istio
Kubernetes and IstioKubernetes and Istio
Kubernetes and IstioKetan Gote
 
Microsoft identity platform and device authorization flow to use azure servic...
Microsoft identity platform and device authorization flow to use azure servic...Microsoft identity platform and device authorization flow to use azure servic...
Microsoft identity platform and device authorization flow to use azure servic...Sunil kumar Mohanty
 
Redux. From twitter hype to production
Redux. From twitter hype to productionRedux. From twitter hype to production
Redux. From twitter hype to productionFDConf
 
Redux. From twitter hype to production
Redux. From twitter hype to productionRedux. From twitter hype to production
Redux. From twitter hype to productionJenya Terpil
 
Ansible Automation Inside Cloudforms ( Embedded Ansible)
Ansible Automation Inside Cloudforms ( Embedded Ansible)Ansible Automation Inside Cloudforms ( Embedded Ansible)
Ansible Automation Inside Cloudforms ( Embedded Ansible)Prasad Mukhedkar
 
FOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device MessagingFOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device MessagingJohan Nilsson
 
Quick Help in Vistex Technical
Quick Help in Vistex TechnicalQuick Help in Vistex Technical
Quick Help in Vistex TechnicalSAPYard
 
PyData Berlin 2023 - Mythical ML Pipeline.pdf
PyData Berlin 2023 - Mythical ML Pipeline.pdfPyData Berlin 2023 - Mythical ML Pipeline.pdf
PyData Berlin 2023 - Mythical ML Pipeline.pdfJim Dowling
 
VMworld 2013: ESXi Native Networking Driver Model - Delivering on Simplicity ...
VMworld 2013: ESXi Native Networking Driver Model - Delivering on Simplicity ...VMworld 2013: ESXi Native Networking Driver Model - Delivering on Simplicity ...
VMworld 2013: ESXi Native Networking Driver Model - Delivering on Simplicity ...VMworld
 
Professional Services Insights into Improving Sitecore XP
Professional Services Insights into Improving Sitecore XPProfessional Services Insights into Improving Sitecore XP
Professional Services Insights into Improving Sitecore XPSeanHolmesby1
 
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...OdessaJS Conf
 

Similar a CODE SNIPPETS FOR BWM MOTOR FRANCHISE PROJECT (20)

Dynamic_UI_Concepts_version_2.pdf
Dynamic_UI_Concepts_version_2.pdfDynamic_UI_Concepts_version_2.pdf
Dynamic_UI_Concepts_version_2.pdf
 
Examples of-tca-apis
Examples of-tca-apisExamples of-tca-apis
Examples of-tca-apis
 
Warranty processing recall bbp
Warranty processing recall bbpWarranty processing recall bbp
Warranty processing recall bbp
 
FEATRURE BRIEF▶ NetBackup 7.6 - Direct virtual machine creation from backup w...
FEATRURE BRIEF▶ NetBackup 7.6 - Direct virtual machine creation from backup w...FEATRURE BRIEF▶ NetBackup 7.6 - Direct virtual machine creation from backup w...
FEATRURE BRIEF▶ NetBackup 7.6 - Direct virtual machine creation from backup w...
 
Warranty processing recall bbp
Warranty processing recall bbpWarranty processing recall bbp
Warranty processing recall bbp
 
argocd-sso.pdf
argocd-sso.pdfargocd-sso.pdf
argocd-sso.pdf
 
Workshop 27: Isomorphic web apps with ReactJS
Workshop 27: Isomorphic web apps with ReactJSWorkshop 27: Isomorphic web apps with ReactJS
Workshop 27: Isomorphic web apps with ReactJS
 
Unit Testing 101
Unit Testing 101Unit Testing 101
Unit Testing 101
 
Kubernetes and Istio
Kubernetes and IstioKubernetes and Istio
Kubernetes and Istio
 
Microsoft identity platform and device authorization flow to use azure servic...
Microsoft identity platform and device authorization flow to use azure servic...Microsoft identity platform and device authorization flow to use azure servic...
Microsoft identity platform and device authorization flow to use azure servic...
 
Redux. From twitter hype to production
Redux. From twitter hype to productionRedux. From twitter hype to production
Redux. From twitter hype to production
 
Redux. From twitter hype to production
Redux. From twitter hype to productionRedux. From twitter hype to production
Redux. From twitter hype to production
 
Ansible Automation Inside Cloudforms ( Embedded Ansible)
Ansible Automation Inside Cloudforms ( Embedded Ansible)Ansible Automation Inside Cloudforms ( Embedded Ansible)
Ansible Automation Inside Cloudforms ( Embedded Ansible)
 
FOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device MessagingFOSS STHLM Android Cloud to Device Messaging
FOSS STHLM Android Cloud to Device Messaging
 
Payments On Rails
Payments On RailsPayments On Rails
Payments On Rails
 
Quick Help in Vistex Technical
Quick Help in Vistex TechnicalQuick Help in Vistex Technical
Quick Help in Vistex Technical
 
PyData Berlin 2023 - Mythical ML Pipeline.pdf
PyData Berlin 2023 - Mythical ML Pipeline.pdfPyData Berlin 2023 - Mythical ML Pipeline.pdf
PyData Berlin 2023 - Mythical ML Pipeline.pdf
 
VMworld 2013: ESXi Native Networking Driver Model - Delivering on Simplicity ...
VMworld 2013: ESXi Native Networking Driver Model - Delivering on Simplicity ...VMworld 2013: ESXi Native Networking Driver Model - Delivering on Simplicity ...
VMworld 2013: ESXi Native Networking Driver Model - Delivering on Simplicity ...
 
Professional Services Insights into Improving Sitecore XP
Professional Services Insights into Improving Sitecore XPProfessional Services Insights into Improving Sitecore XP
Professional Services Insights into Improving Sitecore XP
 
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
Maciej Treder ''Angular Universal - a medicine for the Angular + SEO/CDN issu...
 

Más de Traitet Thepbandansuk

06 1 st_honour_award_certification.pdf
06 1 st_honour_award_certification.pdf06 1 st_honour_award_certification.pdf
06 1 st_honour_award_certification.pdfTraitet Thepbandansuk
 
01 dissertation_Restaurant e-menu on iPad
01 dissertation_Restaurant e-menu on iPad01 dissertation_Restaurant e-menu on iPad
01 dissertation_Restaurant e-menu on iPadTraitet Thepbandansuk
 
MSc Dissertation: Restaurant e-menu software on iPad
MSc Dissertation: Restaurant e-menu software on iPadMSc Dissertation: Restaurant e-menu software on iPad
MSc Dissertation: Restaurant e-menu software on iPadTraitet Thepbandansuk
 

Más de Traitet Thepbandansuk (20)

IT_FOR_BUSINESS_30NOV15
IT_FOR_BUSINESS_30NOV15IT_FOR_BUSINESS_30NOV15
IT_FOR_BUSINESS_30NOV15
 
06 1 st_honour_award_certification.pdf
06 1 st_honour_award_certification.pdf06 1 st_honour_award_certification.pdf
06 1 st_honour_award_certification.pdf
 
Change attitude change life scg
Change attitude change life scgChange attitude change life scg
Change attitude change life scg
 
01 dissertation_Restaurant e-menu on iPad
01 dissertation_Restaurant e-menu on iPad01 dissertation_Restaurant e-menu on iPad
01 dissertation_Restaurant e-menu on iPad
 
MSc Dissertation: Restaurant e-menu software on iPad
MSc Dissertation: Restaurant e-menu software on iPadMSc Dissertation: Restaurant e-menu software on iPad
MSc Dissertation: Restaurant e-menu software on iPad
 
03 outcome navigator
03 outcome navigator03 outcome navigator
03 outcome navigator
 
O1 research overview
O1 research overviewO1 research overview
O1 research overview
 
D4 recommendation emenu_development
D4 recommendation emenu_developmentD4 recommendation emenu_development
D4 recommendation emenu_development
 
D3 users perceptions_emenu
D3 users perceptions_emenuD3 users perceptions_emenu
D3 users perceptions_emenu
 
D2 users perceptions_features
D2 users perceptions_featuresD2 users perceptions_features
D2 users perceptions_features
 
A30 test functional_requirements
A30 test functional_requirementsA30 test functional_requirements
A30 test functional_requirements
 
A22 functions on_web
A22 functions on_webA22 functions on_web
A22 functions on_web
 
A21 functions on_ipad
A21 functions on_ipadA21 functions on_ipad
A21 functions on_ipad
 
A2 annotation approach
A2 annotation approachA2 annotation approach
A2 annotation approach
 
A1 annotation knowledge
A1 annotation knowledgeA1 annotation knowledge
A1 annotation knowledge
 
A1 analysis design
A1 analysis designA1 analysis design
A1 analysis design
 
10 wrap around_conclusion
10 wrap around_conclusion10 wrap around_conclusion
10 wrap around_conclusion
 
02 project plan11_aug12
02 project plan11_aug1202 project plan11_aug12
02 project plan11_aug12
 
00 how to_test_app
00 how to_test_app00 how to_test_app
00 how to_test_app
 
R01 all references
R01 all referencesR01 all references
R01 all references
 

Último

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 

Último (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 

CODE SNIPPETS FOR BWM MOTOR FRANCHISE PROJECT

  • 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