Imports System.Data
Imports System.Data.SqlClient
Partial Class BusinessAssociates_SSA_ViewCustomer
    Inherits System.Web.UI.Page
    Dim QueryStr As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Not IsPostBack) Then
            txtVCompanyID.Text = "f6b59677-9946-489c-8628-465872369428"
            txtSSAID.Text = Session("SSAID").ToString
            lblCustomer.Visible = False
            tblCustomer.Visible = False
            lblQuotationBank.Visible = False
            gvQuotationBank.Visible = False
            tblCustomerStatus.Visible = False
            lblDiscussionThread.Visible = False
            gvDiscussionThread.Visible = False
            tblDiscussion.Visible = False
        End If
    End Sub

    Public Sub FillGrid()
        Dim cn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings("Connection4Voffice"))
        Dim objAdapter As SqlDataAdapter
        Dim ObjDS As DataSet

        cn.Open()

        Try
            objAdapter = New SqlDataAdapter("Select_CRMCustomerBySSAIDAndModeAndDateRange_Proc", cn)
            objAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CustomerMode", SqlDbType.Int))
            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CompanyID", SqlDbType.VarChar))
            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@DateFrom", SqlDbType.DateTime))
            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@DateTo", SqlDbType.DateTime))
            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@SSAID", SqlDbType.VarChar))

            objAdapter.SelectCommand.Parameters("@CustomerMode").Value = 2
            objAdapter.SelectCommand.Parameters("@CompanyID").Value = txtVCompanyID.Text.Trim
            objAdapter.SelectCommand.Parameters("@DateFrom").Value = txtDateFrom.Text
            objAdapter.SelectCommand.Parameters("@DateTo").Value = txtDateTo.Text
            objAdapter.SelectCommand.Parameters("@SSAID").Value = txtSSAID.Text.Trim

            ObjDS = New DataSet
            objAdapter.Fill(ObjDS, "CustomerDetails")

            gvCustomer.DataSource = ObjDS
            gvCustomer.DataBind()

            ObjDS.Clear()
            ObjDS.Dispose()

            Dim J As Integer

            For J = 0 To gvCustomer.Rows.Count - 1
                If gvCustomer.Rows(J).Cells(3).Text = "1" Then
                    gvCustomer.Rows(J).Cells(4).Text = "Government"
                ElseIf gvCustomer.Rows(J).Cells(3).Text = "2" Then
                    gvCustomer.Rows(J).Cells(4).Text = "Private"
                End If
            Next

        Catch ex As Exception

        Finally
            cn.Close()
            cn.Dispose()
        End Try
    End Sub

    Public Function FillAssignedTarget(ByVal Year As Integer, ByVal Month1 As Integer, ByVal Month2 As Integer) As Decimal

        Dim TargetAmt As Decimal

        TargetAmt = 0
        Dim cn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings("Connection4Voffice"))
        Dim objAdapter As SqlDataAdapter
        Dim ObjDS As DataSet

        cn.Open()

        Try
            objAdapter = New SqlDataAdapter("Select_CRMAssignedTargetBySSAIDAndDateRange_Proc", cn)
            objAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@SSAID", SqlDbType.VarChar))
            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Year", SqlDbType.Int))
            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Month1", SqlDbType.Int))
            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Month2", SqlDbType.Int))
            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CompanyID", SqlDbType.VarChar))


            objAdapter.SelectCommand.Parameters("@SSAID").Value = txtSSAID.Text.Trim
            objAdapter.SelectCommand.Parameters("@Year").Value = Year
            objAdapter.SelectCommand.Parameters("@Month1").Value = Month1
            objAdapter.SelectCommand.Parameters("@Month2").Value = Month2
            objAdapter.SelectCommand.Parameters("@CompanyID").Value = txtVCompanyID.Text.Trim

            ObjDS = New DataSet
            objAdapter.Fill(ObjDS, "CustomerStatus")

            If ObjDS.Tables(0).Rows.Count > 0 Then
                TargetAmt = IIf(IsDBNull(ObjDS.Tables(0).Rows(0).Item("TargetAmount")), 0, ObjDS.Tables(0).Rows(0).Item("TargetAmount"))
            End If

        Catch ex As Exception

        Finally
            cn.Close()
            cn.Dispose()
        End Try

        Return TargetAmt

    End Function

    Public Sub FillStatus()
        Dim cn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings("Connection4Voffice"))
        Dim objAdapter As SqlDataAdapter
        Dim ObjDS As DataSet

        cn.Open()

        Try
            objAdapter = New SqlDataAdapter("Select_CRMCustomerStatusBySSAIDAndDateRange_Proc", cn)
            objAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@SSAID", SqlDbType.VarChar))
            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@DateFrom", SqlDbType.DateTime))
            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@DateTo", SqlDbType.DateTime))
            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CompanyID", SqlDbType.VarChar))

            objAdapter.SelectCommand.Parameters("@SSAID").Value = txtSSAID.Text.Trim
            objAdapter.SelectCommand.Parameters("@DateFrom").Value = txtDateFrom.Text
            objAdapter.SelectCommand.Parameters("@DateTo").Value = txtDateTo.Text
            objAdapter.SelectCommand.Parameters("@CompanyID").Value = txtVCompanyID.Text.Trim

            ObjDS = New DataSet
            objAdapter.Fill(ObjDS, "CustomerStatus")

            If ObjDS.Tables(0).Rows.Count > 0 Then
                lblQuotAmtRecd.Text = IIf(IsDBNull(ObjDS.Tables(0).Rows(0).Item("ReceivedAmt")), 0, ObjDS.Tables(0).Rows(0).Item("ReceivedAmt"))
                lblClosedAmt.Text = IIf(IsDBNull(ObjDS.Tables(0).Rows(0).Item("ClosedAmt")), 0, ObjDS.Tables(0).Rows(0).Item("ClosedAmt"))
                lblInProcessAmt.Text = IIf(IsDBNull(ObjDS.Tables(0).Rows(0).Item("InProcessAmt")), 0, ObjDS.Tables(0).Rows(0).Item("InProcessAmt"))
                lblFailedAmt.Text = IIf(IsDBNull(ObjDS.Tables(0).Rows(0).Item("FailedAmt")), 0, ObjDS.Tables(0).Rows(0).Item("FailedAmt"))
            End If

        Catch ex As Exception

        Finally
            cn.Close()
            cn.Dispose()
        End Try
    End Sub

    Protected Sub gvCustomer_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)
        gvCustomer.PageIndex = e.NewPageIndex
        FillGrid()
    End Sub

    Protected Sub gvCustomer_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        lblCustomer.Visible = True
        tblCustomer.Visible = True
        lblQuotationBank.Visible = False
        gvQuotationBank.Visible = False
        lblDiscussionThread.Visible = False
        gvDiscussionThread.Visible = False
        tblDiscussion.Visible = False

        txtLeadID.Text = gvCustomer.SelectedRow.Cells(1).Text
        txtAdminID.Text = gvCustomer.SelectedRow.Cells(16).Text
        lblCompanyName.Text = gvCustomer.SelectedRow.Cells(2).Text
        lblType.Text = gvCustomer.SelectedRow.Cells(4).Text
        lblCity.Text = gvCustomer.SelectedRow.Cells(7).Text
        lblContactPerson.Text = gvCustomer.SelectedRow.Cells(5).Text
        lblAddress.Text = IIf(gvCustomer.SelectedRow.Cells(11).Text = "&nbsp;", "", gvCustomer.SelectedRow.Cells(11).Text)
        lblEmailAddress.Text = IIf(gvCustomer.SelectedRow.Cells(10).Text = "&nbsp;", "", gvCustomer.SelectedRow.Cells(10).Text)
        lblPhone.Text = IIf(gvCustomer.SelectedRow.Cells(9).Text = "&nbsp;", "", gvCustomer.SelectedRow.Cells(9).Text)
        lblRemarks.Text = IIf(gvCustomer.SelectedRow.Cells(13).Text = "&nbsp;", "", gvCustomer.SelectedRow.Cells(13).Text)
        lblRequirement.Text = IIf(gvCustomer.SelectedRow.Cells(12).Text = "&nbsp;", "", gvCustomer.SelectedRow.Cells(12).Text)
        Dim dob As Date
        dob = gvCustomer.SelectedRow.Cells(8).Text

    End Sub

    Protected Sub cmdGo_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        lblErrorData.Text = ""
        lblErrorData.Visible = False

        If txtDateFrom.Text.Trim = "" Then
            showmessage("Please Enter Date From.", lblErrorData)
            txtDateFrom.Focus()
            Exit Sub
        End If

        If txtDateTo.Text.Trim = "" Then
            showmessage("Please Enter Date To.", lblErrorData)
            txtDateTo.Focus()
            Exit Sub
        End If

        If DateDiff(DateInterval.Day, CDate(txtDateFrom.Text), CDate(txtDateTo.Text)) < 0 Then
            showmessage("Date To Must Be Greater Than Date From.", lblErrorData)
            txtDateTo.Focus()
            Exit Sub
        End If

        lblCustomer.Visible = False
        tblCustomer.Visible = False
        lblQuotationBank.Visible = False
        gvQuotationBank.Visible = False
        lblDiscussionThread.Visible = False
        gvDiscussionThread.Visible = False
        tblCustomerStatus.Visible = True
        tblDiscussion.Visible = False

        Dim I As Integer

        lblQuotationBankAmt.Text = 0

        If Year(txtDateFrom.Text) = Year(txtDateTo.Text) Then
            lblQuotationBankAmt.Text = FillAssignedTarget(Year(txtDateFrom.Text), Month(txtDateFrom.Text), Month(txtDateTo.Text))
        Else
            If (Year(txtDateTo.Text) - Year(txtDateFrom.Text)) > 1 Then
                lblQuotationBankAmt.Text += FillAssignedTarget(Year(txtDateFrom.Text), Month(txtDateFrom.Text), 12)

                For I = (Year(txtDateFrom.Text) + 1) To (Year(txtDateTo.Text) - 1)
                    lblQuotationBankAmt.Text += FillAssignedTarget(I, 1, 12)
                Next

                lblQuotationBankAmt.Text += FillAssignedTarget(Year(txtDateTo.Text), 1, Month(txtDateTo.Text))
            Else
                lblQuotationBankAmt.Text += FillAssignedTarget(Year(txtDateFrom.Text), Month(txtDateFrom.Text), 12)
                lblQuotationBankAmt.Text += FillAssignedTarget(Year(txtDateTo.Text), 1, Month(txtDateTo.Text))
            End If
        End If
        FillGrid()
        FillStatus()
    End Sub

    Public Sub FillQuotation()
        Dim cn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings("Connection4Voffice"))
        Dim objAdapter As SqlDataAdapter
        Dim ObjDS As New DataSet

        If txtDateFrom.Text = "" And txtDateTo.Text = "" Then

            cn.Open()

            Try
                objAdapter = New SqlDataAdapter("Select_CRMQuotationByCustomerIDAndMode_Proc", cn)
                objAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

                objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CompanyID", SqlDbType.VarChar))
                objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CustomerID", SqlDbType.VarChar))
                objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@UserMode", SqlDbType.Int))

                objAdapter.SelectCommand.Parameters("@CustomerID").Value = txtLeadID.Text.Trim
                objAdapter.SelectCommand.Parameters("@CompanyID").Value = txtVCompanyID.Text.Trim
                objAdapter.SelectCommand.Parameters("@UserMode").Value = 1

                objAdapter.Fill(ObjDS, "QuotationBank")

                gvQuotationBank.DataSource = ObjDS
                gvQuotationBank.DataBind()

                ObjDS.Clear()
                ObjDS.Dispose()

            Catch ex As Exception

            Finally
                cn.Close()
                cn.Dispose()
            End Try
        Else

            cn.Open()

            Try
                objAdapter = New SqlDataAdapter("Select_CRMQuotationByCustomerIDAndModeAndDateRange_Proc", cn)
                objAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

                objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CompanyID", SqlDbType.VarChar))
                objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CustomerID", SqlDbType.VarChar))
                objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@UserMode", SqlDbType.Int))
                objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@DateFrom", SqlDbType.DateTime))
                objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Dateto", SqlDbType.DateTime))

                objAdapter.SelectCommand.Parameters("@CustomerID").Value = txtLeadID.Text.Trim
                objAdapter.SelectCommand.Parameters("@CompanyID").Value = txtVCompanyID.Text.Trim
                objAdapter.SelectCommand.Parameters("@UserMode").Value = 1
                objAdapter.SelectCommand.Parameters("@DateFrom").Value = txtDateFrom.Text
                objAdapter.SelectCommand.Parameters("@Dateto").Value = txtDateTo.Text

                objAdapter.Fill(ObjDS, "QuotationBank")

                gvQuotationBank.DataSource = ObjDS
                gvQuotationBank.DataBind()

                ObjDS.Clear()
                ObjDS.Dispose()

            Catch ex As Exception

            Finally
                cn.Close()
                cn.Dispose()
            End Try
        End If

    End Sub

    Protected Sub gvQuotationBank_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvQuotationBank.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            e.Row.Cells(2).Text = Format$(Convert.ToDateTime(e.Row.Cells(2).Text), "MMM-dd-yyyy")
        End If
    End Sub

    Protected Sub gvQuotationBank_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)
        gvQuotationBank.PageIndex = e.NewPageIndex
        FillQuotation()
    End Sub

    Protected Sub lnkQuotation_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim KID As String
        Dim lnk As LinkButton
        lnk = CType(sender, LinkButton)
        Kid = lnk.CommandArgument

        txtLeadID.Text = KID

        lblCustomer.Visible = False
        tblCustomer.Visible = False
        lblQuotationBank.Visible = True
        gvQuotationBank.Visible = True
        lblDiscussionThread.Visible = False
        gvDiscussionThread.Visible = False
        tblDiscussion.Visible = False
        SelectCustomerByCustomerID(txtLeadID.Text)
        FillQuotation()
    End Sub

    Public Sub FillDiscussion()
        Dim cn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings("Connection4Voffice"))
        Dim objAdapter As SqlDataAdapter
        Dim ObjDS As DataSet

        cn.Open()

        Try
            objAdapter = New SqlDataAdapter("Select_CRMDiscussionThreadByLeadIDAndDiscussionMode_Proc", cn)
            objAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@DiscussionMode", SqlDbType.Int))
            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CompanyID", SqlDbType.VarChar))
            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CustomerID", SqlDbType.VarChar))

            objAdapter.SelectCommand.Parameters("@DiscussionMode").Value = -1
            objAdapter.SelectCommand.Parameters("@CompanyID").Value = txtVCompanyID.Text.Trim
            objAdapter.SelectCommand.Parameters("@CustomerID").Value = txtLeadID.Text.Trim

            ObjDS = New DataSet
            objAdapter.Fill(ObjDS, "DiscussionThread")

            gvDiscussionThread.DataSource = ObjDS
            gvDiscussionThread.DataBind()

            ObjDS.Clear()
            ObjDS.Dispose()

            Dim J As Integer

            For J = 0 To gvDiscussionThread.Rows.Count - 1

                If gvDiscussionThread.Rows(J).Cells(3).Text = "1" Then
                    gvDiscussionThread.Rows(J).Cells(4).Text = "Email"
                ElseIf gvDiscussionThread.Rows(J).Cells(3).Text = "2" Then
                    gvDiscussionThread.Rows(J).Cells(4).Text = "Phone"
                ElseIf gvDiscussionThread.Rows(J).Cells(3).Text = "3" Then
                    gvDiscussionThread.Rows(J).Cells(4).Text = "Personal Visit"
                End If

                If gvDiscussionThread.Rows(J).Cells(6).Text = "00000000-0000-0000-0000-000000000000" Then
                    gvDiscussionThread.Rows(J).Cells(8).Text = FillAdminDetails(gvDiscussionThread.Rows(J).Cells(7).Text.ToString) & " (Admin)"
                ElseIf gvDiscussionThread.Rows(J).Cells(7).Text = "00000000-0000-0000-0000-000000000000" Then
                    gvDiscussionThread.Rows(J).Cells(8).Text = FillSSADetails(gvDiscussionThread.Rows(J).Cells(6).Text.ToString) & " (SSA)"
                End If
            Next

        Catch ex As Exception

        Finally
            cn.Close()
            cn.Dispose()
        End Try
    End Sub

    Protected Sub gvDiscussionThread_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs)
        gvDiscussionThread.PageIndex = e.NewPageIndex
        FillDiscussion()
    End Sub

    Protected Sub gvDiscussionThread_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvDiscussionThread.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            e.Row.Cells(1).Text = Format$(Convert.ToDateTime(e.Row.Cells(1).Text), "MMM-dd-yyyy")
            e.Row.Cells(2).Text = Format$(Convert.ToDateTime(e.Row.Cells(2).Text), "hh:mm:ss tt")
        End If
    End Sub

    Protected Sub lnkDiscussion_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim KID As String
        Dim lnk As LinkButton
        lnk = CType(sender, LinkButton)
        KID = lnk.CommandArgument
        txtLeadID.Text = KID

        lblCustomer.Visible = False
        tblCustomer.Visible = False
        lblQuotationBank.Visible = False
        gvQuotationBank.Visible = False
        lblDiscussionThread.Visible = True
        gvDiscussionThread.Visible = True
        tblDiscussion.Visible = True
        lblErrorData1.Visible = False

        SelectCustomerByCustomerID(txtLeadID.Text)
        FillDiscussion()
    End Sub

    Public Sub SelectCustomerByCustomerID(ByVal CustomerID As String)
        Dim cn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings("Connection4Voffice"))
        Dim objAdapter As SqlDataAdapter
        Dim ObjDS As DataSet

        cn.Open()

        Try
            objAdapter = New SqlDataAdapter("Select_CRMCustomerByCustomerID_Proc", cn)
            objAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CustomerID", SqlDbType.VarChar))

            objAdapter.SelectCommand.Parameters("@CustomerID").Value = CustomerID.ToString

            ObjDS = New DataSet
            objAdapter.Fill(ObjDS, "CustomerDetails")

            If ObjDS.Tables(0).Rows.Count > 0 Then
                lblQuotationBank.Text = "Quotation Bank of : " & ObjDS.Tables(0).Rows(0).Item("V_CRM_CompanyName")
                lblDiscussionThread.Text = "Discussion Thread of : " & ObjDS.Tables(0).Rows(0).Item("V_CRM_CompanyName")
            End If

        Catch ex As Exception

        Finally
            cn.Close()
            cn.Dispose()
        End Try
    End Sub

    Public Function FillAdminDetails(ByVal AdminID As String) As String

        Dim Name As String

        Name = ""

        Dim Dr As DataRow
        Dim cn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings("Connection4Voffice"))
        Dim objAdapter As SqlDataAdapter
        Dim ObjDS As DataSet

        cn.Open()

        Try
            objAdapter = New SqlDataAdapter("Select_EmployeeByAdminID_Proc", cn)
            objAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@AdminID", SqlDbType.VarChar))
            objAdapter.SelectCommand.Parameters.Add(New SqlParameter("@CompanyID", SqlDbType.VarChar))

            objAdapter.SelectCommand.Parameters("@AdminID").Value = AdminID.ToString
            objAdapter.SelectCommand.Parameters("@CompanyID").Value = txtVCompanyID.Text.ToString

            ObjDS = New DataSet
            objAdapter.Fill(ObjDS, "EmployeeDetails")

            If ObjDS.Tables(0).Rows.Count > 0 Then
                Dr = ObjDS.Tables(0).Rows(0)
                Name = Dr("V_Emp_Name")
            End If

        Catch ex As Exception

        Finally
            cn.Close()
            cn.Dispose()
        End Try

        Return Name

        ObjDS.Clear()
        ObjDS.Dispose()

    End Function

    Public Function FillSSADetails(ByVal SSAID As String) As String

        Dim Name As String

        Name = ""
        Dim cmd As New Data.SqlClient.SqlCommand()
        Dim con As New Data.SqlClient.SqlConnection
        con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")

        Dim Str As String
        Str = "select * From SSA_Master Where SSA_KID='" & SSAID.ToString & "'"
        If con.State = Data.ConnectionState.Open Then
            con.Close()
        End If
        con.Open()
        cmd = New SqlCommand(Str, con)
        Dim adp As New SqlDataAdapter
        Dim ds As New DataSet
        Dim Dr As DataRow
        adp.SelectCommand = cmd
        adp.Fill(ds)

        If ds.Tables(0).Rows.Count > 0 Then
            Dr = ds.Tables(0).Rows(0)
            Name = Dr("SSA_FirstName") & "  " & Dr("SSA_LastName")
        End If

        Return Name
        ds.Clear()
        ds.Dispose()

        con.Close()
        con.Dispose()

    End Function

    Protected Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)

        Dim cmd As New Data.SqlClient.SqlCommand()
        Dim cmdQuotation As New Data.SqlClient.SqlCommand()
        Dim con As New Data.SqlClient.SqlConnection
        con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("Connection4Voffice")

        Try
            cmdQuotation.CommandText = "Insert_CRMDiscussionThread_Proc"
            cmdQuotation.CommandType = Data.CommandType.StoredProcedure
            cmdQuotation.Connection = con

            con.Open()

            cmdQuotation.Parameters.Add("@DiscussionID", Data.SqlDbType.VarChar).Value = System.Guid.NewGuid.ToString
            cmdQuotation.Parameters.Add("@CustomerID", SqlDbType.VarChar).Value = txtLeadID.Text.Trim
            cmdQuotation.Parameters.Add("@DiscussionMode", SqlDbType.Decimal).Value = ddlDiscussionMode.SelectedValue
            cmdQuotation.Parameters.Add("@DiscussionDateTime", SqlDbType.DateTime).Value = System.DateTime.Now
            cmdQuotation.Parameters.Add("@Discussion", SqlDbType.Text).Value = txtDiscussion.Text.Trim
            cmdQuotation.Parameters.Add("@CompanyID", SqlDbType.VarChar).Value = txtVCompanyID.Text.Trim
            cmdQuotation.Parameters.Add("@SSAID", SqlDbType.VarChar).Value = txtSSAID.Text.Trim
            cmdQuotation.Parameters.Add("@AdminID", SqlDbType.VarChar).Value = "00000000-0000-0000-0000-000000000000"
            cmdQuotation.Parameters.Add("@FormName", SqlDbType.NVarChar, 50).Value = "DiscussionThread"
            cmdQuotation.Parameters.Add("@Mode", SqlDbType.VarChar, 10).Value = "Insert"

            cmdQuotation.ExecuteNonQuery()

            con.Close()
            con.Dispose()
            showmessage("Record Added Successfully.", lblErrorData1)

            ddlDiscussionMode.SelectedValue = -1
            txtDiscussion.Text = ""

            FillDiscussion()

        Catch ex As Exception
            showmessage("Please try again later.", lblErrorData1)
        Finally
            con.Close()
            con.Dispose()
        End Try
    End Sub
End Class
