Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class BillingPL
    Inherits BillingModule

    '***************************************** Multiple Shipping Table ****************************************
    Public Sub chkQty(ByVal dg As DataGrid, ByVal dt As DataTable, _
                      ByVal ddlE As DropDownList, ByVal strID As String)

        Dim i, j As Int32
        Dim drRow As DataRow
        Dim dttemp As New DataTable()
        dttemp = dt.Copy()
        dt.Clear()
        If dt.Columns("TOS") Is Nothing Then
            dt.Columns.Add("TOS")
            dt.Columns.Add("Exemp")
        End If
        For i = 0 To dttemp.Rows.Count - 1
            If Val(dttemp.Rows(i).Item("pi_SellQty")) > 1 Then
                For j = 1 To dttemp.Rows(i).Item("pi_SellQty")
                    drRow = dt.NewRow
                    FillData(drRow, dttemp.Rows(i))
                    dt.Rows.Add(drRow)
                Next
            Else
                drRow = dt.NewRow
                FillData(drRow, dttemp.Rows(i))
                dt.Rows.Add(drRow)
            End If
        Next
        dg.DataSource = Nothing
        dg.DataSource = dt
        dg.DataBind()
        getGridData(strID, dg, ddlE)
        dg.Columns(7).Visible = True
        dg.Columns(8).Visible = True
        dttemp.Clear()
        dttemp.Dispose()
    End Sub

    '************************************ Fill the Given DataRow *********************************************
    Private Sub FillData(ByVal dr As DataRow, ByVal drData As DataRow)
        dr.Item("UserID") = drData.Item("UserID")
        dr.Item("pi_Image") = drData.Item("pi_Image")
        dr.Item("pi_spcode") = drData.Item("pi_spcode")
        dr.Item("ProdID") = drData.Item("ProdID")
        dr.Item("ShipQty") = drData.Item("ShipQty")
        dr.Item("pi_SellQty") = 1
        dr.Item("PCode") = drData.Item("PCode")
        dr.Item("pi_price") = drData.Item("pi_price")
        dr.Item("SID") = drData.Item("SID")
        dr.Item("amount") = 1 * drData.Item("pi_price")
    End Sub

    Public Sub getGridValues(ByVal dg As DataGrid, ByVal dt As DataTable)
        Dim dgitm As DataGridItem
        Dim i As Int32 = 0
        Dim ddl As DropDownList
        For Each dgitm In dg.Items
            ddl = CType(dgitm.FindControl("Address"), DropDownList)
            dt.Rows(i).Item("TOS") = ddl.SelectedItem.Value
            ddl = CType(dgitm.FindControl("ddlExemp"), DropDownList)
            dt.Rows(i).Item("Exemp") = ddl.SelectedItem.Value.ToString.Trim
            i += 1
        Next
    End Sub

    Public Sub getGridData(ByVal strId As String, ByVal dg As DataGrid, ByVal ddlE As DropDownList)
        Dim hash As Hashtable
        hash = getcmbadd(strId)
        If hash.Count > 0 Then
            Dim dgitm As DataGridItem
            Dim ddl As DropDownList
            For Each dgitm In dg.Items
                ddl = CType(dgitm.FindControl("Address"), DropDownList)
                ddl.Visible = True
                ddl.DataSource = hash
                ddl.DataTextField = "Value"
                ddl.DataValueField = "Key"
                ddl.DataBind()
                ddl = CType(dgitm.FindControl("ddlExemp"), DropDownList)
                ddl.Visible = True
                ddl.DataSource = ddlE.Items
                ddl.DataTextField = "Text"
                ddl.DataValueField = "Value"
                ddl.DataBind()
            Next
        End If
        hash.Clear()
    End Sub

    Protected Function getGridDisplay(ByVal dg As DataGrid) As Boolean
        Dim boolfind As Boolean
        Dim dgitm As DataGridItem
        For Each dgitm In dg.Items
            Dim rdb As RadioButton = CType(dgitm.FindControl("rdbSID"), RadioButton)
            If rdb.Checked = True Then
                Dim lbl As Label = CType(dgitm.FindControl("lblPStatus"), Label)
                lbl.Text = "Processed"
                rdb.Checked = False
                rdb.Visible = False
                boolfind = True
                Exit For
            End If
        Next
        dg.Visible = True
        For Each dgitm In dg.Items
            Dim rdb As RadioButton = CType(dgitm.FindControl("rdbSID"), RadioButton)
            If rdb.Visible = True Then
                boolfind = True
                Exit For
            Else
                boolfind = False
            End If
        Next
        Return boolfind
    End Function

    Protected Function MessageBox(ByVal str As String) As Label
        Dim lbl As New Label()
        Dim str1 As String = ""
        If str.Trim = "S" Then
            str1 = "Check the RadioButtion for further Processing of Order"
        ElseIf str.Trim = "P" Then
            str1 = "Check the RadioButtion for Processing of Order"
        End If
        lbl.Text = "<script language='javascript'>" & Environment.NewLine & _
               "window.alert('" + str1 + "')</script>"
        Return lbl
    End Function

    Protected Sub BindData(ByVal intvalue As Integer, ByVal dg As DataGrid, ByVal strvalue As String, ByVal str As String)
        Dim view As DataView
        If strvalue.Trim = "" Then
            view = ds.Tables("PD").DefaultView
            If intvalue = 0 Then
                view.RowFilter = "Status like'" & "%Pending%" & "'"
            ElseIf intvalue = 1 Then
                view.RowFilter = "Status like'" & "%Credited%" & "'"
            ElseIf intvalue = 2 Then
                view.RowFilter = "Status like'" & "%Processed%" & "'"
            End If
        ElseIf str.Trim = "D" Then

            view = ds.Tables("Details").DefaultView
            view.RowFilter = "BillNo='" & strvalue.Trim & "'"
        ElseIf str.Trim = "P" Then
            view = ds.Tables("PD").DefaultView
            view.RowFilter = "BillNo='" & strvalue.Trim & "'"
        End If
        dg.Visible = True
        view.RowStateFilter = DataViewRowState.CurrentRows
        dg.DataSource = view
        dg.DataBind()
        If str.Trim = "P" Then
            If view.Item(0).Item(4).TOUPPER = "CHQ" Then
                HideColumns(True, dg)
            ElseIf view.Item(0).Item(4).TOUPPER = "DD" Then
                HideColumns(False, dg)
            End If
        End If
        getvalue(intvalue, dg)
    End Sub

    Private Sub getvalue(ByVal intstatus As Int16, ByVal dg As DataGrid)
        If intstatus > 1 Then
            Exit Sub
        End If
        Dim dgitm As DataGridItem
        For Each dgitm In dg.Items
            Dim lbtn As LinkButton = CType(dgitm.FindControl("lbtnMode"), LinkButton)
            If lbtn.Text.Trim = "Chq" Then
                lbtn.Text = "Cheque"
            ElseIf lbtn.Text.Trim = "DD" Then
                lbtn.Text = "Demand Draft"
            End If
            If intstatus = 1 Then
                Dim rdb As RadioButton = CType(dgitm.FindControl("chkprocess"), RadioButton)
                rdb.Visible = True
            End If
        Next
    End Sub

    Private Sub HideColumns(ByVal bool As Boolean, ByVal dgPayDetails As DataGrid)
        dgPayDetails.Columns(5).Visible = bool
        dgPayDetails.Columns(6).Visible = bool
        dgPayDetails.Columns(7).Visible = bool
        dgPayDetails.Columns(8).Visible = Not bool
        dgPayDetails.Columns(9).Visible = Not bool
        dgPayDetails.Columns(10).Visible = Not bool
    End Sub


    Public Function UpdateData(ByVal intUserId As String, ByVal strTOS As String, ByVal intDA As String, _
                           ByVal GvShopCart As GridView, ByVal gvvat As GridView, ByVal GvTax As GridView, ByVal GvOctroi As GridView) As Integer
        Return CalTax(intUserId, strTOS.Trim, intDA, GvShopCart, gvvat, GvTax, GvOctroi)
    End Function

    Public Function Updata(ByVal intUserId As String, ByVal strTos As String, ByVal GvMultipleShip As GridView, ByVal gvvat As GridView, ByVal GvTax As GridView, ByVal GvOctroi As GridView, ByVal aspxpage As System.Web.UI.Page)


        Return CalTax1(intUserId, strTos, GvMultipleShip, gvvat, GvTax, GvOctroi, aspxpage)
    End Function

End Class
