Imports System
Imports System.Data
Imports System.Data.SqlClient
Partial Class SupplierPaymentDisbursed
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("SupplierID") = Nothing Then
            Response.Redirect("supplier-transaction-login.aspx")
        End If
        If Not IsPostBack Then
            fillgridview(gvpaymentdisbursed)
            rowcourier.Visible = False
            rowpayment.Visible = False
        End If

    End Sub

    Function fillgridview(ByVal gv As GridView)
        If con.State = ConnectionState.Open Then
            con.Close()
        End If
        Dim str As String = "SELECT   SupplierInv.SupplierInv_Kid,  SupplierDispatchProductDetails.SupplierDispatchProductDetails_Kid AS sdpd_kid,PaymentsToSupplier.PaymentsToSupplier_PaymentDate AS PaymentDate, SupplierInv.SupplierInv_code, PaymentsToSupplier.PaymentsToSupplier_Amount AS amt, SupplierDispatchProductDetails.SupplierDispatchProductDetails_BuyerShippingAddressId AS shippid,PaymentsToSupplier.PaymentsToSupplier_Kid  FROM   PaymentsToSupplier INNER JOIN SupplierDispatchProductDetails ON  PaymentsToSupplier.PaymentsToSupplier_SupplierDispatchDetailsId = SupplierDispatchProductDetails.SupplierDispatchProductDetails_Kid INNER JOIN  SupplierInv ON PaymentsToSupplier.PaymentsToSupplier_SupplierDispatchDetailsId = SupplierInv.SupplierInv_SupplierDispatchProdDetailId  where PaymentsToSupplier.PaymentsToSupplier_SupplierId='" & Session("SupplierID") & "'"
        Dim da As New SqlDataAdapter(str, con)
        Dim ds As New DataSet
        da.Fill(ds)
        gv.DataSource = ds.Tables(0)
        gv.DataBind()
        con.Close()

    End Function
    Protected Sub lnksuppinvno_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        rowcourier.Visible = True
        rowpayment.Visible = False

        Dim lnk As LinkButton = CType(sender, LinkButton)
        Dim str As String = "SELECT  SupplierDispatchProductDetails.SupplierDispatchProductDetails_CourierId as CourierId, SupplierDispatchProductDetails.SupplierDispatchProductDetails_CourierNo as CourierNo ,  SupplierDispatchProductDetails.SupplierDispatchProductDetails_CourierDate as CourierDate,  SupplierDispatchProductDetails.SupplierDispatchProductDetails_BuyerShippingAddressId as BuyerShippingAddressId,Courier_Master.Courier_Name,SupplierDispatchDetails.SupplierDispatchDetails_Code as sddcode FROM SupplierDispatchProductDetails INNER JOIN SupplierInv ON SupplierDispatchProductDetails.SupplierDispatchProductDetails_Kid = SupplierInv.SupplierInv_SupplierDispatchProdDetailId  INNER JOIN  Courier_Master ON  SupplierDispatchProductDetails.SupplierDispatchProductDetails_CourierId = dbo.Courier_Master.Courier_Kid INNER JOIN  SupplierDispatchDetails ON  SupplierDispatchProductDetails.SupplierDispatchProductDetails_SupplierDispatchDetailsId = SupplierDispatchDetails.SupplierDispatchDetails_Kid  where SupplierInv.SupplierInv_Kid='" & lnk.CommandArgument & "'"
        Dim dt As DataTable = getTable(str.Trim, "CourierDetails")
        lblcourierdetails.Text = "<b>Dipatched Order No :</b> " & dt.Rows(0).Item("sddcode").ToString & "<br><b>Courier Name:</b> " & dt.Rows(0).Item("Courier_Name").ToString & "<br><b>Courier No:</b>" & dt.Rows(0).Item("CourierNo").ToString & "<br><b>Courier Date:</b>" & dt.Rows(0).Item("CourierDate").ToString
        lblcourierdetails.Visible = True
        Dim shipid As String = dt.Rows(0).Item("BuyerShippingAddressId").ToString
        str = "SELECT     BillingAddress.BillingAddress_AddID, AddressBook.AddressBook_UserName, AddressBook.AddressBook_Add1, AddressBook.AddressBook_Zipcode, " & _
                     " AddressBook.AddressBook_TelNumber, AddressBook.AddressBook_TelExtn, AddressBook.AddressBook_MobNumber, " & _
        " AddressBook.AddressBook_Email, City_Master.City_Name, State_Master.State_Name, Country_Master.Country_Name" & _
        " FROM BillingAddress INNER JOIN  AddressBook ON BillingAddress.BillingAddress_ShipAddID = AddressBook.AddressBook_Kid INNER JOIN" & _
                      " City_Master ON AddressBook.AddressBook_CityID = City_Master.City_Kid INNER JOIN" & _
                      " State_Master ON AddressBook.AddressBook_StateID = State_Master.State_Kid INNER JOIN" & _
                      " Country_Master ON AddressBook.AddressBook_CountryID = Country_Master.Country_Kid where   BillingAddress.BillingAddress_ShipAddID='" & shipid & "'"

        '= OrderRequestToSupplierProduct.OrderRequestToSupplierProduct_Address"
        dt = getTable(str.Trim, "ShippingDetails")
        lblshipaddress.Text = "<b>Name:</b> " & dt.Rows(0).Item(1).ToString & "<br><b>Address:</b>" & dt.Rows(0).Item(2).ToString & "<br><b>PinCode:</b>" & dt.Rows(0).Item(3).ToString & "<br>" & dt.Rows(0).Item(8).ToString & "<br>" & dt.Rows(0).Item(9).ToString & "," & dt.Rows(0).Item(10).ToString & "<br><b>Telephone:</b>" & dt.Rows(0).Item(4).ToString & ",<b>Ext No:</b> " & dt.Rows(0).Item(5).ToString & "<br><b>Mobile:</b>" & dt.Rows(0).Item(6).ToString & "<br><b>EmailId:</b>" & dt.Rows(0).Item(7).ToString
        lblshipaddress.Visible = True

    End Sub

    Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim lnk As LinkButton = CType(sender, LinkButton)
        Dim str As String = "SELECT     PaymentsToSupplier.PaymentsToSupplier_Cheque, PaymentsToSupplier.PaymentsToSupplier_Amount,PaymentsToSupplier.PaymentsToSupplier_ChequeDate, Bank_Master.Bank_Name,Branch_Master.Branch_Name  FROM     PaymentsToSupplier INNER JOIN  Bank_Master ON PaymentsToSupplier.PaymentsToSupplier_BankId = Bank_Master.Bank_Kid INNER JOIN  Branch_Master ON PaymentsToSupplier.PaymentsToSupplier_BranchId = Branch_Master.Branch_Kid  where  PaymentsToSupplier.PaymentsToSupplier_Kid='" & lnk.CommandArgument & "'"
        Dim dt As DataTable = getTable(str.Trim, "PaymentDetails")
        lblpayment.Text = "<b>Cheque No:</b> " & dt.Rows(0).Item("PaymentsToSupplier_Cheque").ToString & "<br><b>Amount:</b>" & dt.Rows(0).Item("PaymentsToSupplier_Amount").ToString & "<br><b>ChequeDate:</b>" & dt.Rows(0).Item("PaymentsToSupplier_ChequeDate").ToString & "<br><b>Bank Name:</b>" & dt.Rows(0).Item("Bank_Name").ToString & "<br><b>Branch Name:</b>" & dt.Rows(0).Item("Branch_Name").ToString
        lblpayment.Visible = True
        rowpayment.Visible = True
        rowcourier.Visible = False

    End Sub

    Protected Sub gvpaymentdisbursed_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvpaymentdisbursed.PageIndexChanging
        gvpaymentdisbursed.PageIndex = e.NewPageIndex
        fillgridview(gvpaymentdisbursed)
    End Sub

    Protected Sub gvpaymentdisbursed_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvpaymentdisbursed.SelectedIndexChanged

    End Sub
End Class
