'-----------------------------------------------------------------
'<copyright file="BankMaster.aspx.vb" company="Kimaya" >
'   Copyright(c) Kimaya Ltd. All rights reserved.
'</copyright>
'<Desc>
'   Codebehind file for BankMaster.aspx used for Bank_Master
'</Desc>
'<DateOfCreation>
'   18/06/07
'</DateOfCreation>
'<Developer>
'   Rajesh
'</Developer>

'-----------------------------------------------------------------
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.IO
Imports ModCommon
Partial Class _BankMaster
    Inherits System.Web.UI.Page
    Shared Search As Boolean
    Shared g_User As String
    Shared g_Company As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        
        Try
            If (Not IsPostBack) Then        'If IsPostBack is false then
                ClearFields()               'Clear the TextFields
                UnLockTextBox(False)        'Unlock (Enable) TextFields
                g_User = "U1"
                g_Company = "COM1"
                'g_User = Session("g_User").ToString
                'g_Company = Session("g_Company").ToString
                FillGrid("")                  'Fills the DatagGrid with All Records
                Call CancelClick(Me, BtnAdd, BtnSave, BtnEdit, BtnDelete, BtnCancel, BtnSearch)
                Search = False              'Default Value for Search Mode
                Call CheckRights(Me, g_User, "Service Center")
            End If
            txtSS_Code.MaxLength = 20 : txtSS_Code.MaxLength = 50
            txtSS_CenterName.Attributes.Add("onblur", "return CheckNull('txtSS_CenterName');")
            txtSS_CenterName.Attributes.Add("onkeypress", "return BlockNumericValue(event);")
            txtSS_StafffStrength.Attributes.Add("onKeypress", "return CheckNemericValue(event);")
            txtSS_MobileNo.Attributes.Add("onKeypress", "return CheckNemericValue(event);")
            txtSS_PhoneNo.Attributes.Add("onKeypress", "return CheckNemericValue(event);")
            txtSS_PhoneExtNo.Attributes.Add("onKeypress", "return CheckNemericValue(event);")

        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")
        End Try
    End Sub
    Protected Sub _Default_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        If Not IsValidConnectionString() Then CreateMessageAlert(Me, "Check the Connection String !", "StrKeyVal") 'If not a valid ConnectionString then Display the message 
    End Sub
    '----------------------------------------------------------------------------------------------------------------------------
    '<UserDefinedFunction Name="ClearFields">
    '   <Desc> For Clearing the contents of TextFields </Desc>
    '   <Input> Nothing </Input>
    '   <Output> Nothing </Output>
    '   <DateOfCreation> 30/06/06 </DateOfCreation>
    '   <Developer> Rajesh </Developer>
    '</UserDefinedFunction>
    '----------------------------------------------------------------------------------------------------------------------------
    Protected Sub ClearFields()
        txtSS_Code.Text = ""                           'Assign Null to the TextField
        txtSS_CenterName.Text = ""                           'Assign Null to the TextField
        txtSS_ContactPersonName.Text = ""                           'Assign Null to the TextField
        txtSS_StafffStrength.Text = ""                           'Assign Null to the TextField
        txtSS_Designation.Text = ""                           'Assign Null to the TextField
        txtSS_PhoneNo.Text = ""                           'Assign Null to the TextField
        txtSS_PhoneExtNo.Text = ""                           'Assign Null to the TextField
        txtSS_MobileNo.Text = ""                           'Assign Null to the TextField
        txtSS_EmailId.Text = ""                           'Assign Null to the TextField
    End Sub
    '----------------------------------------------------------------------------------------------------------------------------
    '<UserDefinedFunction Name="UnLockTextBox">
    '   <Desc> For Locking & UnLocking the TextFields </Desc>
    '   <Input> 
    '   <Param Name="Action">
    '   True or False
    '   </Param>
    '   </Input>
    '   <Output> Nothing </Output>
    '   <DateOfCreation> 30/06/06 </DateOfCreation>
    '   <Developer> Rajesh </Developer>
    '</UserDefinedFunction>
    '----------------------------------------------------------------------------------------------------------------------------
    Protected Sub UnLockTextBox(ByVal Action As Boolean)
        txtSS_CenterName.Enabled = Action                    'Enable / Disable the TextField
        txtSS_ContactPersonName.Enabled = Action                    'Enable / Disable the TextField
        txtSS_StafffStrength.Enabled = Action                    'Enable / Disable the TextField
        txtSS_Designation.Enabled = Action                    'Enable / Disable the TextField
        txtSS_PhoneNo.Enabled = Action                    'Enable / Disable the TextField
        txtSS_PhoneExtNo.Enabled = Action                    'Enable / Disable the TextField
        txtSS_MobileNo.Enabled = Action                    'Enable / Disable the TextField
        txtSS_EmailId.Enabled = Action                    'Enable / Disable the TextField
    End Sub

    '----------------------------------------------------------------------------------------------------------------------------
    '<UserDefinedFunction Name="FillGrid">
    '   <Desc> To Fill the Grid with All Records </Desc>
    '   <Input> 
    '  <Param Name="PTN">
    '   PartType_Name
    '   </Param>
    '   </Input>
    '   <Output> Nothing </Output>
    '   <DateOfCreation> 30/06/06 </DateOfCreation>
    '   <Developer> Rajesh </Developer>
    '</UserDefinedFunction>
    '----------------------------------------------------------------------------------------------------------------------------
    Protected Sub FillGrid(ByVal PTN As String)
        Try
            Dim qry As String                                   'Define a String Variable for Query
            Dim con As New SqlConnection                        'Define connection variable for connecting to SQL-Server
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")    'Read the ConnectionString from web.config File
            con.Open()                                          'Open the Connection
            gvServiceCenter.Columns(1).Visible = True
           
            If Trim(PTN) = "" Then
                qry = "SELECT distinct SS_Kid,SS_Code, SS_CenterName, SS_ContactPersonName,SS_StafffStrength, SS_Designation, SS_PhoneNo, SS_PhoneExtNo, SS_MobileNo,SS_EmailId FROM ServiceCenter WHERE SS_CompanyId='" & g_Company & "' AND SS_IsDeleted ='0'"
            Else
                qry = "SELECT distinct SS_Kid,SS_Code, SS_CenterName,SS_ContactPersonName,SS_StafffStrength,SS_Designation, SS_PhoneNo, SS_PhoneExtNo, SS_MobileNo,SS_EmailId FROM ServiceCenter WHERE SS_CompanyId='" & g_Company & "' AND SS_IsDeleted ='0' and SS_CenterName like '" & Trim(PTN) & "%'"
            End If
            Dim cmd As New SqlCommand(qry, con)                 'Define command variable to execute the query
            Dim dr As SqlDataReader                             'Define DataReader variable for storing the output of the query
            dr = cmd.ExecuteReader                              'Assign the output of query to DataReader variable
            gvServiceCenter.DataSource = dr                          'Set the DataReader Variable as DataSource for the Grid
            gvServiceCenter.DataBind()                               'Bind the Data to the Grid
            gvServiceCenter.Columns(1).Visible = False
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")     'Display the Error Message
        End Try
    End Sub

    Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
        Try
            'If CBool(Session("Add_Flag").ToString) = False Then
            '    CreateMessageAlert(Me, "You Do Not Have Access Right To Add New Record !", "StrKeyVal")  'Display the Message 
            '    Exit Sub
            'End If
            ClearFields()                                       'Clears the TextFields
            UnLockTextBox(True)                                 'Enable the TextFields
            Call AddClick(Me, BtnAdd, BtnSave, BtnEdit, BtnDelete, BtnCancel, BtnSearch)
            Call GenerateCode()
            txtSS_CenterName.Focus()                                 'Put the Focus to CenterName TextField
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")     'Display the Error Message  
        End Try
    End Sub

    Protected Sub gvServiceCenter_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvServiceCenter.SelectedIndexChanged
        Try
            txtSS_Code.Text = gvServiceCenter.SelectedRow.Cells(2).Text     'Assign the value of cell to the textField
            txtSS_CenterName.Text = gvServiceCenter.SelectedRow.Cells(3).Text     'Assign the value of cell to the textField
            txtSS_ContactPersonName.Text = gvServiceCenter.SelectedRow.Cells(4).Text     'Assign the value of cell to the textField
            txtSS_StafffStrength.Text = gvServiceCenter.SelectedRow.Cells(5).Text     'Assign the value of cell to the textField
            txtSS_Designation.Text = gvServiceCenter.SelectedRow.Cells(6).Text     'Assign the value of cell to the textField
            txtSS_PhoneNo.Text = gvServiceCenter.SelectedRow.Cells(7).Text     'Assign the value of cell to the textField
            txtSS_PhoneExtNo.Text = gvServiceCenter.SelectedRow.Cells(8).Text     'Assign the value of cell to the textField
            txtSS_MobileNo.Text = gvServiceCenter.SelectedRow.Cells(9).Text     'Assign the value of cell to the textField
            txtSS_EmailId.Text = gvServiceCenter.SelectedRow.Cells(10).Text     'Assign the value of cell to the textField

            UnLockTextBox(True)                                             'Enable the TextFields
            Call GridClick(Me, BtnAdd, BtnSave, BtnEdit, BtnDelete, BtnCancel, BtnSearch)
            Search = False
            txtSS_CenterName.Focus()
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")                 'Display the Error Message
        End Try
    End Sub

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        Try
            'If CBool(Session("Add_Flag").ToString) = False Then
            '    CreateMessageAlert(Me, "You Do Not Have Access Right To Add New Record !", "StrKeyVal")  'Display the Message 
            '    Exit Sub
            'End If
            If Trim(txtSS_Code.Text) = "" Then                                           'If txtSS_Code TextField is Null then
                CreateMessageAlert(Me, "Service Code Cannot be Null!", "StrKeyVal")      'Display the Message 
                Exit Sub
            End If
            If Trim(txtSS_CenterName.Text) = "" Then                                         'If txtSS_CenterName.Text TextField is Null then
                CreateMessageAlert(Me, "Service Center Name Cannot be Null !", "StrKeyVal")      'Display the Message
                Exit Sub
            End If

            Dim con As New SqlConnection                                                    'Define connection variable for connecting to SQL-Server
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")    'Read the ConnectionString from web.config File
            con.Open()                                                                       'Open the Connection
            If IsAlreadyPresent("select count(*) from ServiceCenter where SS_Code='" & txtSS_Code.Text.Trim & "'and SS_IsDeleted='0' and SS_CompanyId='" & g_Company & "'") Then  ' To Check Existance of Engineer Code
                CreateMessageAlert(Me, " Service Center Code Already Present !", "StrKeyVal")      'Display the Message
                txtSS_Code.Text = "" : txtSS_Code.Focus()
                Exit Sub
            End If
            If IsAlreadyPresent("select count(*) from ServiceCenter where SS_CenterName='" & txtSS_CenterName.Text.Trim & "'and SS_IsDeleted='0' and SS_CompanyId='" & g_Company & "'") Then  ' To Check Existance of Engineer Code
                CreateMessageAlert(Me, " Service Center Name Already Present !", "StrKeyVal")      'Display the Message
                txtSS_CenterName.Text = "" : txtSS_CenterName.Focus()
                Exit Sub
            End If

            Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
            cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
            cmd.CommandText = "ServiceCenter_Proc"                                        'Assign the Name of Stored Procedure, to Execute
            cmd.Connection = con                                                            'Assign the connection

            cmd.Parameters.Add(New SqlParameter("@SS_Kid", SqlDbType.NVarChar, 20)).Value = NewPrimaryKey(Me)
            cmd.Parameters.Add(New SqlParameter("@SS_Code", SqlDbType.NVarChar, 20)).Value = Trim(txtSS_Code.Text)       'Add Parameter txtSS_Code and assign the value of txtBankCode TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_CenterName", SqlDbType.NVarChar, 25)).Value = Trim(txtSS_CenterName.Text)       'Add Parameter txtSS_CenterName and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_ContactPersonName", SqlDbType.NVarChar, 25)).Value = Trim(txtSS_ContactPersonName.Text)       'Add Parameter txtSS_ContactPersonName and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_StafffStrength", SqlDbType.Decimal, 20)).Value = Convert.ToDecimal(Trim(txtSS_StafffStrength.Text))       'Add Parameter txtSS_StafffStrength and assign the value of txtBankCode TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_Designation", SqlDbType.NVarChar, 25)).Value = Trim(txtSS_Designation.Text)       'Add Parameter txtSS_Designation and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_PhoneNo", SqlDbType.NVarChar, 20)).Value = Trim(txtSS_PhoneNo.Text)       'Add Parameter txtSS_PhoneNo and assign the value of txtBankCode TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_PhoneExtNo", SqlDbType.NVarChar, 25)).Value = Trim(txtSS_PhoneExtNo.Text)       'Add Parameter txtSS_PhoneExtNo and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_MobileNo", SqlDbType.NVarChar, 25)).Value = Trim(txtSS_MobileNo.Text)       'Add Parameter txtSS_MobileNo and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_EmailId", SqlDbType.NVarChar, 20)).Value = Trim(txtSS_EmailId.Text)          'Add Parameter txtSS_EmailId and assign the value of txtBankCode TextField to it

            cmd.Parameters.Add(New SqlParameter("@SS_SupplierMemberId", SqlDbType.NVarChar, 25)).Value = "1"       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_CompanyId", SqlDbType.NVarChar, 20)).Value = Trim(g_Company)       'Add Parameter Company_Code and assign the value of Session("g_Company") to it
            cmd.Parameters.Add(New SqlParameter("@SS_UserId", SqlDbType.NVarChar, 20)).Value = Trim(g_User)             'Add Parameter UserCode and assign the value of Session("g_User").toString to it
            cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 100)).Value = "Service Center"                           'Add Parameter FormName and assign the name of form to it
            cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 50)).Value = "Insert"                                   'Add Parameter Mode and assign the DML Operation to Execute (Insert)
            cmd.ExecuteNonQuery()                                                           'Execute the Query
            FillGrid("")                                                                      'Fill the Grid
            CreateMessageAlert(Me, "Record Saved Successfully...", "StrKeyVal")             'Display the Message
            ClearFields()                                                                   'Clear the TextFields
            UnLockTextBox(False)                                                            'Disable the TextFields
            Call SaveClick(Me, BtnAdd, BtnSave, BtnEdit, BtnDelete, BtnCancel, BtnSearch)
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")                                 'Display the Error Message
        End Try
    End Sub

    Protected Sub btnEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnEdit.Click
        Try
            'If CBool(Session("Modify_Flag").ToString) = False Then
            '    CreateMessageAlert(Me, "You Do Not Have Access Right To Modify An Existing Record !", "StrKeyVal")  'Display the Message 
            '    Exit Sub
            'End If
            If Trim(txtSS_Code.Text) = "" Then                                           'If txtSS_Code TextField is Null then
                CreateMessageAlert(Me, "Service Code Cannot be Null!", "StrKeyVal")      'Display the Message 
                Exit Sub
            End If

            If Trim(txtSS_CenterName.Text) = "" Then                                         'If txtSS_CenterName.Text TextField is Null then
                CreateMessageAlert(Me, "Service Center Name Cannot be Null !", "StrKeyVal")      'Display the Message
                Exit Sub
            End If

            If IsAlreadyPresent("select count(*) from ServiceCenter where SS_Code!='" & Trim(txtSS_Code.Text) & "' and SS_CenterName='" & txtSS_CenterName.Text.Trim & "'and SS_IsDeleted='0' and SS_CompanyId='" & g_Company & "'") Then  ' To Check Existance of Engineer Code
                CreateMessageAlert(Me, " Service Center Name Already Present !", "StrKeyVal")      'Display the Message
                txtSS_CenterName.Text = "" : txtSS_CenterName.Focus()
                Exit Sub
            End If

            Dim con As New SqlConnection                                                    'Define connection variable for connecting to SQL-Server
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")    'Read the ConnectionString from web.config File
            con.Open()                                                                      'Open the Connection
            Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
            cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
            cmd.CommandText = "ServiceCenter_Proc"                                        'Assign the Name of Stored Procedure, to Execute
            cmd.Connection = con                                                            'Assign the connection

            cmd.Parameters.Add(New SqlParameter("@SS_Kid", SqlDbType.NVarChar, 20)).Value = Trim(gvServiceCenter.SelectedRow.Cells(1).Text)
            cmd.Parameters.Add(New SqlParameter("@SS_Code", SqlDbType.NVarChar, 20)).Value = Trim(txtSS_Code.Text)       'Add Parameter txtSS_Code and assign the value of txtBankCode TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_CenterName", SqlDbType.NVarChar, 25)).Value = Trim(txtSS_CenterName.Text)       'Add Parameter txtSS_CenterName and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_ContactPersonName", SqlDbType.NVarChar, 25)).Value = Trim(txtSS_ContactPersonName.Text)       'Add Parameter txtSS_ContactPersonName and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_StafffStrength", SqlDbType.Int, 20)).Value = Convert.ToInt32(Trim(txtSS_StafffStrength.Text))       'Add Parameter txtSS_StafffStrength and assign the value of txtBankCode TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_Designation", SqlDbType.NVarChar, 25)).Value = Trim(txtSS_Designation.Text)       'Add Parameter txtSS_Designation and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_PhoneNo", SqlDbType.NVarChar, 20)).Value = Trim(txtSS_PhoneNo.Text)       'Add Parameter txtSS_PhoneNo and assign the value of txtBankCode TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_PhoneExtNo", SqlDbType.NVarChar, 25)).Value = Trim(txtSS_PhoneExtNo.Text)       'Add Parameter txtSS_PhoneExtNo and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_MobileNo", SqlDbType.NVarChar, 25)).Value = Trim(txtSS_MobileNo.Text)       'Add Parameter txtSS_MobileNo and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_EmailId", SqlDbType.NVarChar, 20)).Value = Trim(txtSS_EmailId.Text)          'Add Parameter txtSS_EmailId and assign the value of txtBankCode TextField to it

            cmd.Parameters.Add(New SqlParameter("@SS_SupplierMemberId", SqlDbType.NVarChar, 25)).Value = "1"       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_CompanyId", SqlDbType.NVarChar, 20)).Value = Trim(g_Company)       'Add Parameter Company_Code and assign the value of Session("g_Company") to it
            cmd.Parameters.Add(New SqlParameter("@SS_UserId", SqlDbType.NVarChar, 20)).Value = Trim(g_User)             'Add Parameter UserCode and assign the value of Session("g_User").toString to it
            cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 100)).Value = "Service Center"
            cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 50)).Value = "Update"                                   'Add Parameter Mode and assign the DML Operation to Execute (Insert)

            cmd.ExecuteNonQuery()                                                           'Execute the Query
            FillGrid("")                                                                      'Fill the Grid
            CreateMessageAlert(Me, "Record Modified Successfully..", "StrKeyVal")             'Display the Message
            ClearFields()                                                                   'Clear the TextFields
            UnLockTextBox(False)                                                            'Disable the TextFields
            Call EditClick(Me, BtnAdd, BtnSave, BtnEdit, BtnDelete, BtnCancel, BtnSearch)
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")                                 'Display the Error Message
        End Try

    End Sub

    Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnDelete.Click
        Try
            'If CBool(Session("Delete_Flag").ToString) = False Then
            '    CreateMessageAlert(Me, "You Do Not Have Access Right To Delete An Existing Record !", "StrKeyVal")  'Display the Message 
            '    Exit Sub
            'End If
            If Trim(txtSS_Code.Text) = "" Then                                           'If txtSS_Code TextField is Null then
                CreateMessageAlert(Me, "Service Code Cannot be Null!", "StrKeyVal")      'Display the Message 
                Exit Sub
            End If

            If Trim(txtSS_CenterName.Text) = "" Then                                         'If txtSS_CenterName.Text TextField is Null then
                CreateMessageAlert(Me, "Service Center Name Cannot be Null !", "StrKeyVal")      'Display the Message
                Exit Sub
            End If

            'If IsAlreadyPresent("select count(*) from FactoryDetails where FactoryDetails_Code='" & Trim(txtFactoryDetails_Code.Text) & "' and FactoryDetails_IsDeleted='0' and FactoryDetails_CompanyId='" & g_Company & "'") Then  ' To Check Existance of Engineer Code
            '    CreateMessageAlert(Me, " Unable to Delete, Referenced to Other Records... !", "StrKeyVal")      'Display the Message
            '    btnCancel_Click(sender, e)
            '    Exit Sub
            'End If
            Dim con As New SqlConnection                                                    'Define connection variable for connecting to SQL-Server
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")    'Read the ConnectionString from web.config File
            con.Open()                                                                      'Open the Connection
            Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
            cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
            cmd.CommandText = "ServiceCenter_Proc"                                        'Assign the Name of Stored Procedure, to Execute
            cmd.Connection = con                                                            'Assign the connection

            cmd.Parameters.Add(New SqlParameter("@SS_Kid", SqlDbType.NVarChar, 20)).Value = Trim(gvServiceCenter.SelectedRow.Cells(1).Text)
            cmd.Parameters.Add(New SqlParameter("@SS_Code", SqlDbType.NVarChar, 20)).Value = Trim(txtSS_Code.Text)       'Add Parameter txtSS_Code and assign the value of txtBankCode TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_CenterName", SqlDbType.NVarChar, 25)).Value = Trim(txtSS_CenterName.Text)       'Add Parameter txtSS_CenterName and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_ContactPersonName", SqlDbType.NVarChar, 25)).Value = Trim(txtSS_ContactPersonName.Text)       'Add Parameter txtSS_ContactPersonName and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_StafffStrength", SqlDbType.Int, 20)).Value = Convert.ToInt32(Trim(txtSS_StafffStrength.Text))       'Add Parameter txtSS_StafffStrength and assign the value of txtBankCode TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_Designation", SqlDbType.NVarChar, 25)).Value = Trim(txtSS_Designation.Text)       'Add Parameter txtSS_Designation and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_PhoneNo", SqlDbType.NVarChar, 20)).Value = Trim(txtSS_PhoneNo.Text)       'Add Parameter txtSS_PhoneNo and assign the value of txtBankCode TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_PhoneExtNo", SqlDbType.NVarChar, 25)).Value = Trim(txtSS_PhoneExtNo.Text)       'Add Parameter txtSS_PhoneExtNo and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_MobileNo", SqlDbType.NVarChar, 25)).Value = Trim(txtSS_MobileNo.Text)       'Add Parameter txtSS_MobileNo and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_EmailId", SqlDbType.NVarChar, 20)).Value = Trim(txtSS_EmailId.Text)          'Add Parameter txtSS_EmailId and assign the value of txtBankCode TextField to it

            cmd.Parameters.Add(New SqlParameter("@SS_SupplierMemberId", SqlDbType.NVarChar, 25)).Value = "1"       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@SS_CompanyId", SqlDbType.NVarChar, 20)).Value = Trim(g_Company)       'Add Parameter Company_Code and assign the value of Session("g_Company") to it
            cmd.Parameters.Add(New SqlParameter("@SS_UserId", SqlDbType.NVarChar, 20)).Value = Trim(g_User)             'Add Parameter UserCode and assign the value of Session("g_User").toString to it
            cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 100)).Value = "Service Center"
            cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 50)).Value = "Delete"                                   'Add Parameter Mode and assign the DML Operation to Execute (Delete)

            cmd.ExecuteNonQuery()                                                           'Execute the Query
            FillGrid("")                                                                      'Fill the Grid
            CreateMessageAlert(Me, "Record Deleted Successfully...", "StrKeyVal")             'Display the Message
            ClearFields()                                                                   'Clear the TextFields
            UnLockTextBox(False)                                                            'Disable the TextFields
            Call DeleteClick(Me, BtnAdd, BtnSave, BtnEdit, BtnDelete, BtnCancel, BtnSearch)
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")                                 'Display the Error Message
        End Try
    End Sub

    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
        Try
            ClearFields()                                       'Clears the TextFields
            UnLockTextBox(False)                                'Disable the TextFields
            Search = False
            txtSS_CenterName.AutoPostBack = False
            Call FillGrid("")
            Call CancelClick(Me, BtnAdd, BtnSave, BtnEdit, BtnDelete, BtnCancel, BtnSearch)
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")     'Display the Error Message
        End Try
    End Sub

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSearch.Click
        Search = True                                       'Set Search Mode True
        Call SearchClick(Me, btnAdd, btnSave, btnEdit, btnDelete, btnCancel, btnSearch)
        txtSS_CenterName.Enabled = True
        txtSS_CenterName.AutoPostBack = True
        txtSS_CenterName.Focus()                             'Set Focus to txtSS_CenterName TextField
    End Sub

    Protected Sub txtFactoryDetails_SupplierName_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSS_CenterName.TextChanged
        If Search = True Then                                       'If Search Mode is true then
            Call FillGrid(Trim(txtSS_CenterName.Text))  'Fill the Grid filtering on txtSS_CenterName
        End If
        If BtnSave.Enabled Then BtnSave.Focus()
    End Sub

    Protected Sub GenerateCode()
        Try
            Dim i As String
            Dim qry As String
            Dim code As String
            txtSS_Code.Text = NewPrimaryKey(Me)
            i = "1"
            i = Format(Val(i), "000")
            While True
                code = "SRC" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/" & i
                qry = "select count(*) from ServiceCenter where SS_Code='" & code & "'"
                If IsAlreadyPresent(qry) Then
                    i = Val(i) + 1
                    i = Format(Val(i), "000")
                Else
                    txtSS_Code.Text = code
                    Exit Sub
                End If
            End While
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")     'Display the Error Message
        End Try
    End Sub


    Sub Node_Populate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs)
        If e.Node.ChildNodes.Count = 0 Then
            Select Case (e.Node.Depth)
                Case 0

                    FillModule(e.Node, "2")

                    Exit Sub
                Case 1

                    FillMenu(e.Node)

                    Exit Sub

                Case 2

                    FillSubMenu(e.Node)

                    Exit Sub

            End Select
        End If
    End Sub


    Protected Sub tvLinks_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tvLinks.SelectedNodeChanged

    End Sub

    
   
End Class