Imports System
Imports System.Data
Imports System.Data.SqlClient
Partial Class Admin_supplier_register_report
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then

        End If


    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Try
            Dim datef, datet As DateTime
            datef = Format$(Convert.ToDateTime(txtfDate.Text.Trim), "")
            datet = Format$(Convert.ToDateTime(txttDate.Text.Trim), "")

            'Dim i As String = DateDiff(DateInterval.Day, datef, datet)
            Dim dt As New DataTable
            If DateDiff(DateInterval.Day, datef, datet) >= 0 Then


                'Dim sqlCmd As New SqlCommand
                'Dim sqlCon As SqlConnection
                'Dim adp As SqlDataAdapter
                'sqlCon = New SqlConnection(ConfigurationManager.AppSettings("ConnectionString"))
                'sqlCon.Open()
                'With sqlCmd
                '    .CommandText = "Sp_QualityCheck"
                '    .CommandType = Data.CommandType.StoredProcedure
                '    .Connection = sqlCon
                '    .Parameters.AddWithValue("@Mode", "Select_SupplierMaster")
                '    .Parameters.AddWithValue("@FormName", Me.Title)
                '    .Parameters.AddWithValue("@FromDate", txtfDate.Text)
                '    .Parameters.AddWithValue("@ToDate", txttDate.Text)
                '    .Parameters.AddWithValue("@UserId", Session("AdminID").ToString)
                '    '.ExecuteNonQuery()
                '    adp = New SqlDataAdapter(sqlCmd)
                'End With

                'adp.Fill(dt)
                'gvDailyWork.DataSource = dt
                'gvDailyWork.DataBind()
                'Dim strTest As String
                'strTest = datef.Date.ToString
                fillgrid(datef.ToString, datet.ToString)


            Else
                CreateMessageAlert(Me, "To Date should be granter than or equal to From Date.!", "strkeyval")
                Exit Sub
            End If

            'gvProduct.DataSource = Nothing
            'gvProduct.DataBind()

            Dim str As String
            str = ""
        Catch ex As Exception
            CreateMessageAlert(Me, "Please Select Proper Date.!", "strKeyval")

        End Try



    End Sub
    Public Sub fillgrid(ByVal fdate As String, ByVal tdate As String)
        Dim dt As New DataTable
        If fdate = "" And tdate = "" Then
            'dt = ReturnDataTable("SELECT Supplier_Name, Supplier_Kid FROM Supplier_Master WHERE (Supplier_Kid IN (SELECT DISTINCT Product_SupplierId AS Expr1 FROM Product_Master  WHERE (Product_UserId = N'" & RemoveLiterals(Session("AdminID").ToString) & "') AND (Product_IsDeleted = N'0'))) order by Supplier_Name")
            dt = ReturnDataTable("Select Suepplier_Name, Supplier_Kid from Supplier_Master where Supplier_Isdeleted='0'")
        Else
            'dt = ReturnDataTable("SELECT Supplier_Name, supplier_kid FROM Supplier_Master WHERE (Supplier_Kid IN (SELECT distinct Product_SupplierID FROM Product_Master WHERE (Product_UserId = N'" & RemoveLiterals(Session("AdminID").ToString) & "') AND (Product_IsDeleted = N'0') and  convert(nvarchar,Product_RegDate,101) <= '" & tdate.ToString.Trim & "' and convert(nvarchar,Product_RegDate,101) >= '" & fdate.ToString.Trim & "'))")
            Dim sqlCmd As New SqlCommand
            Dim sqlCon As SqlConnection
            Dim adp As SqlDataAdapter
            sqlCon = New SqlConnection(ConfigurationManager.AppSettings("ConnectionString"))
            sqlCon.Open()
            With sqlCmd
                .CommandText = "Sp_QualityCheck"
                .CommandType = Data.CommandType.StoredProcedure
                .Connection = sqlCon
                .Parameters.AddWithValue("@Mode", "Select_DateSupplierMaster")
                .Parameters.AddWithValue("@FormName", Me.Title)
                .Parameters.AddWithValue("@FromDate", txtfDate.Text)
                .Parameters.AddWithValue("@ToDate", txttDate.Text)
                '.Parameters.AddWithValue("@UserId", Session("AdminID").ToString)
                '.ExecuteNonQuery()
                adp = New SqlDataAdapter(sqlCmd)
            End With

            adp.Fill(dt)
        End If
        gvDailyWork.DataSource = dt
        gvDailyWork.DataBind()


    End Sub

End Class
