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 Currency_Master
    Inherits System.Web.UI.Page
    Shared Search As Boolean
    Shared g_User As String
    Shared g_Company As String
    Shared g_FinYear As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If Session("AdminID") Is Nothing Then
                Response.Redirect("AdminLogin.aspx?sesn=expire")
                Exit Sub
            End If
            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
                g_FinYear = Session("g_FinYear").ToString()
                FillCombo()
                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, "Bank Master")
            End If
            txtCurrencyCode.MaxLength = 20 : txtCurrencyName.MaxLength = 50
            txtCurrencyName.Attributes.Add("onblur", "return CheckNull('txtCurrencyName');")
            'txtBankName.Attributes.Add("onkeypress", "return BlockNumericValue(event);")
            '  txtBankName.Attributes.Add("onblur", "return toUpper('txtBankName');")
        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> 31/07/07 </DateOfCreation>
    '   <Developer> Neeta </Developer>
    '</UserDefinedFunction>
    '----------------------------------------------------------------------------------------------------------------------------
    Protected Sub ClearFields()
        Try
            txtCurrencyCode.Text = ""                           'Assign Null to the TextField
            txtCurrencyName.Text = ""                           'Assign Null to the TextField
            ddlCountryName.SelectedIndex = 0
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")     'Display the Error Message
        End Try
    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> 31/07/07 </DateOfCreation>
    '   <Developer> Neeta </Developer>
    '</UserDefinedFunction>
    '----------------------------------------------------------------------------------------------------------------------------
    Protected Sub UnLockTextBox(ByVal Action As Boolean)
        Try
            'txtBankCode.Enabled = Action                    'Enable / Disable the TextField
            txtCurrencyName.Enabled = Action                    'Enable / Disable the TextField
            ddlCountryName.Enabled = Action
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")     'Display the Error Message
        End Try
    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> 31/07/07</DateOfCreation>
    '   <Developer> Neeta </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
            gvCurrency.Columns(1).Visible = True
            If Trim(PTN) = "" Then
                qry = "select distinct Currency_Kid,Currency_Code,Currency_Name from Currency_Master where Currency_isdeleted='0' and Currency_companyId='" & g_Company & "'"
            Else
                qry = "select distinct Currency_Kid,Currency_Code,Currency_Name from Currency_Master where Currency_isdeleted='0' and Currency_companyId='" & g_Company & "' and Currency_Name 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
            gvCurrency.DataSource = dr                          'Set the DataReader Variable as DataSource for the Grid
            gvCurrency.DataBind()                               'Bind the Data to the Grid
            gvCurrency.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 GenerateBankCode()
            txtCurrencyName.Focus()                                 'Put the Focus to BankCode TextField
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")     'Display the Error Message
        End Try
    End Sub

    Protected Sub gvCurrency_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvCurrency.SelectedIndexChanged
        Try
            Dim CountryId As String
            txtCurrencyId.Text = gvCurrency.SelectedRow.Cells(1).Text     'Assign the value of cell to the textField
            txtCurrencyCode.Text = gvCurrency.SelectedRow.Cells(2).Text     'Assign the value of cell to the textField
            txtCurrencyName.Text = gvCurrency.SelectedRow.Cells(3).Text     'Assign the value of cell to the textField
            CountryId = ReturnValue("select Currency_CountryId from Currency_Master where Currency_Kid='" & txtCurrencyId.Text & "'")
            ddlCountryName.ClearSelection()
            ddlCountryName.Items.FindByValue(CountryId.Trim).Selected = True  '= CountryId
            UnLockTextBox(True)                                             'Enable the TextFields
            Call GridClick(Me, BtnAdd, BtnSave, BtnEdit, BtnDelete, BtnCancel, BtnSearch)
            Search = False
            txtCurrencyName.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(txtCurrencyCode.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "Currency Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                Exit Sub
            End If
            If Trim(txtCurrencyName.Text) = "" Then                                         'If txtPartTypeName TextField is Null then
                CreateMessageAlert(Me, "Currency Name Cannot be Null !", "StrKeyVal")      'Display the Message
                Exit Sub
            End If

            If Trim(ddlCountryName.SelectedValue) = "Select" Then                                         'If txtPartTypeName TextField is Null then
                CreateMessageAlert(Me, "Country 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 Currency_Master where Currency_Code='" & txtCurrencyCode.Text.Trim & "'and Currency_isdeleted='0' and Currency_CompanyId='" & g_Company & "'") Then  ' To Check Existance of Engineer Code
                CreateMessageAlert(Me, " Currency Code Already Present !", "StrKeyVal")      'Display the Message
                txtCurrencyCode.Text = "" : txtCurrencyCode.Focus()
                Exit Sub
            End If
            If IsAlreadyPresent("select count(*) from Currency_Master where Currency_Name='" & txtCurrencyName.Text.Trim & "'and Currency_isdeleted='0' and Currency_CompanyId='" & g_Company & "'") Then  ' To Check Existance of Engineer Code
                CreateMessageAlert(Me, " Currency Name Already Present !", "StrKeyVal")      'Display the Message
                txtCurrencyName.Text = "" : txtCurrencyName.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 = "Currency_Master_Proc"                                        'Assign the Name of Stored Procedure, to Execute
            cmd.Connection = con                                                            'Assign the connection
            cmd.Parameters.Add(New SqlParameter("@Currency_Kid", SqlDbType.NVarChar, 20)).Value = Trim(txtCurrencyId.Text)       'Add Parameter Banke_Kid and assign the value  to it
            cmd.Parameters.Add(New SqlParameter("@Currency_Code", SqlDbType.NVarChar, 20)).Value = Trim(txtCurrencyCode.Text)       'Add Parameter Banke_Code and assign the value of txtBankCode TextField to it
            cmd.Parameters.Add(New SqlParameter("@Currency_Name", SqlDbType.NVarChar, 25)).Value = Trim(txtCurrencyName.Text)      'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@Currency_CountryId", SqlDbType.NVarChar, 20)).Value = Trim(ddlCountryName.SelectedValue)       'Add Parameter Company_Code and assign the value of Session("g_Company") to it
            cmd.Parameters.Add(New SqlParameter("@Currency_FinancialYearId", SqlDbType.NVarChar, 20)).Value = g_FinYear              'Add Parameter UserCode and assign the value of Session("g_User").toString to it
            cmd.Parameters.Add(New SqlParameter("@Currency_CompanyId", SqlDbType.NVarChar, 20)).Value = Trim(g_Company)           'Add Parameter UserCode and assign the value of Session("g_User").toString to it
            cmd.Parameters.Add(New SqlParameter("@Currency_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 = "Currency Master"                           '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(txtCurrencyCode.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "Currency Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                Exit Sub
            End If
            If Trim(txtCurrencyName.Text) = "" Then                                         'If txtPartTypeName TextField is Null then
                CreateMessageAlert(Me, "Currency Name Cannot be Null !", "StrKeyVal")      'Display the Message
                Exit Sub
            End If

            If Trim(ddlCountryName.SelectedValue) = "" Then                                         'If txtPartTypeName TextField is Null then
                CreateMessageAlert(Me, "Currenty Name Cannot be Null !", "StrKeyVal")      'Display the Message
                Exit Sub
            End If
            If IsAlreadyPresent("select count(*) from Currency_Master where Currency_Code!='" & Trim(txtCurrencyCode.Text) & "' and  Currency_Name='" & txtCurrencyName.Text.Trim & "'  and Currency_isdeleted='0' and Currency_CompanyId='" & g_Company & "'") Then  ' To Check Existance of Engineer Code
                CreateMessageAlert(Me, " Currency Name Already Present !", "StrKeyVal")      'Display the Message
                txtCurrencyName.Text = "" : txtCurrencyName.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 = "Currency_Master_Proc"                                        'Assign the Name of Stored Procedure, to Execute
            cmd.Connection = con                                                            'Assign the connection
            cmd.Parameters.Add(New SqlParameter("@Currency_Kid", SqlDbType.NVarChar, 20)).Value = Trim(txtCurrencyId.Text)       'Add Parameter Banke_Kid and assign the value  to it
            cmd.Parameters.Add(New SqlParameter("@Currency_Code", SqlDbType.NVarChar, 20)).Value = Trim(txtCurrencyCode.Text)       'Add Parameter Banke_Code and assign the value of txtBankCode TextField to it
            cmd.Parameters.Add(New SqlParameter("@Currency_Name", SqlDbType.NVarChar, 25)).Value = Trim(txtCurrencyName.Text)       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@Currency_CountryId", SqlDbType.NVarChar, 20)).Value = Trim(ddlCountryName.SelectedValue)       'Add Parameter Company_Code and assign the value of Session("g_Company") to it
            cmd.Parameters.Add(New SqlParameter("@Currency_FinancialYearId", SqlDbType.NVarChar, 20)).Value = Trim(g_FinYear)              'Add Parameter UserCode and assign the value of Session("g_User").toString to it
            cmd.Parameters.Add(New SqlParameter("@Currency_CompanyId", SqlDbType.NVarChar, 20)).Value = Trim(g_Company)           'Add Parameter UserCode and assign the value of Session("g_User").toString to it
            cmd.Parameters.Add(New SqlParameter("@Currency_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 = "Currency Master"                           'Add Parameter FormName and assign the name of form to it
            cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 50)).Value = "Update"                                   'Add Parameter Mode and assign the DML Operation to Execute (Update)
            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(txtCurrencyCode.Text) = "" Then                                         'If txtPartTypeCode TextField is Null then
                CreateMessageAlert(Me, "Currency Code Cannot be Null !", "StrKeyVal")      'Display the Message 
                Exit Sub
            End If
            If Trim(txtCurrencyName.Text) = "" Then                                         'If txtPartTypeName TextField is Null then
                CreateMessageAlert(Me, "Currency Name Cannot be Null !", "StrKeyVal")      'Display the Message
                Exit Sub
            End If

            If Trim(ddlCountryName.SelectedValue) = "" Then                                         'If txtPartTypeName TextField is Null then
                CreateMessageAlert(Me, "Currenty Name Cannot be Null !", "StrKeyVal")      'Display the Message
                Exit Sub
            End If
            'If IsAlreadyPresent("select count(*) from Currency_Master where Currency_Code='" & txtCurrencyCode.Text.Trim & "'and Currency_isdeleted='0' and Currency_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 = "Currency_Master_Proc"                                        'Assign the Name of Stored Procedure, to Execute
            cmd.Connection = con                                                            'Assign the connection

            cmd.Parameters.Add(New SqlParameter("@Currency_Kid", SqlDbType.NVarChar, 20)).Value = Trim(txtCurrencyId.Text)       'Add Parameter Banke_Kid and assign the value  to it
            cmd.Parameters.Add(New SqlParameter("@Currency_Code", SqlDbType.NVarChar, 20)).Value = Trim(txtCurrencyCode.Text)       'Add Parameter Banke_Code and assign the value of txtBankCode TextField to it
            cmd.Parameters.Add(New SqlParameter("@Currency_Name", SqlDbType.NVarChar, 25)).Value = Trim(txtCurrencyName.Text)       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
            cmd.Parameters.Add(New SqlParameter("@Currency_CountryId", SqlDbType.NVarChar, 20)).Value = Trim(ddlCountryName.SelectedValue)       'Add Parameter Company_Code and assign the value of Session("g_Company") to it
            cmd.Parameters.Add(New SqlParameter("@Currency_FinancialYearId", SqlDbType.NVarChar, 20)).Value = Trim(g_FinYear)             'Add Parameter UserCode and assign the value of Session("g_User").toString to it
            cmd.Parameters.Add(New SqlParameter("@Currency_CompanyId", SqlDbType.NVarChar, 20)).Value = Trim(g_Company)           'Add Parameter UserCode and assign the value of Session("g_User").toString to it
            cmd.Parameters.Add(New SqlParameter("@Currency_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 = "Currency Master"                           'Add Parameter FormName and assign the name of form to it
            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
            txtCurrencyName.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)
        txtCurrencyName.Enabled = True
        txtCurrencyName.AutoPostBack = True
        'Enable txtPartTypeName TextField
        'Call txtBankName_TextChanged(sender, e)
        txtCurrencyName.Focus()                             'Set Focus to txtPartTypeName TextField
    End Sub

    Protected Sub txtCurrencyName_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCurrencyName.TextChanged
        If Search = True Then                               'If Search Mode is true then
            Call FillGrid(Trim(txtCurrencyName.Text))  'Fill the Grid filtering on txtStockLocationName 
        End If
        If BtnSave.Enabled Then BtnSave.Focus()
    End Sub
    Protected Sub GenerateBankCode()
        Try
            Dim i As String
            Dim qry As String
            Dim code As String
            txtCurrencyId.Text = NewPrimaryKey(Me)
            i = "1"
            i = Format(Val(i), "000")
            While True
                code = "CNY" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/" & i
                qry = "select count(*) from Currency_Master where Currency_Code='" & code & "'"
                If IsAlreadyPresent(qry) Then
                    i = Val(i) + 1
                    i = Format(Val(i), "000")
                Else
                    txtCurrencyCode.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
    Private Sub FillCombo()
        Fill_Combo("Select Country_Kid,Country_Name from Country_Master where Country_IsDeleted='0'and Country_CompanyID='" & g_Company & "' order by Country_Name", ddlCountryName)
    End Sub
End Class