使用From:date和To:date将日期搜索到折线图的x轴

时间:2014-06-17 01:50:00

标签: asp.net vb.net date graph linegraph

我是asp和vb.net的初学者。 我想要发生的是从文本框'从'和'到'日期显示用户输入的日期。但在我的代码中,它显示一个随机日期,它不遵循我的日期。这是代码。

IOPatient.ascx.vb

Public Sub DoChart()
    Try
        Dim SQLStr As String = ""
        Dim SQLStr1 As String = ""
        Dim SQLStr2 As String = ""
        Dim SQLStr3 As String = ""
        Dim SQLStr4 As String = ""
        Dim SQLStr5 As String = ""
        Dim sqlConn As New SqlConnection(DataSource.ConnectionString)
        sqlConn.Open()
        Dim sqlConn1 As New SqlConnection(DataSource.ConnectionString)
        sqlConn1.Open()
        Dim sqlConn2 As New SqlConnection(DataSource.ConnectionString)
        sqlConn2.Open()
        Dim sqlConn3 As New SqlConnection(DataSource.ConnectionString)
        sqlConn3.Open()
        Dim sqlConn4 As New SqlConnection(DataSource.ConnectionString)
        sqlConn4.Open()
        Dim sqlConn5 As New SqlConnection(DataSource.ConnectionString)
        sqlConn5.Open()

        Dim sqlComm As New SqlCommand(SQLStr, sqlConn)
        Dim sqlAdapter As New SqlDataAdapter(sqlComm)
        Dim o_Dataset As New DataSet()
        Dim sqlReader As SqlDataReader

        Dim sqlComm1 As New SqlCommand(SQLStr1, sqlConn1)
        Dim sqlAdapter1 As New SqlDataAdapter(sqlComm1)
        Dim o_Dataset1 As New DataSet()
        Dim sqlReader1 As SqlDataReader


        Dim sqlComm2 As New SqlCommand(SQLStr2, sqlConn2)
        Dim sqlAdapter2 As New SqlDataAdapter(sqlComm2)
        Dim o_Dataset2 As New DataSet()
        Dim sqlReader2 As SqlDataReader

        Dim sqlComm3 As New SqlCommand(SQLStr3, sqlConn3)
        Dim sqlAdapter3 As New SqlDataAdapter(sqlComm3)
        Dim o_Dataset3 As New DataSet()
        Dim sqlReader3 As SqlDataReader

        Dim sqlComm4 As New SqlCommand(SQLStr4, sqlConn4)
        Dim sqlAdapter4 As New SqlDataAdapter(sqlComm4)
        Dim o_Dataset4 As New DataSet()
        Dim sqlReader4 As SqlDataReader

        Dim sqlComm5 As New SqlCommand(SQLStr5, sqlConn5)
        Dim sqlAdapter5 As New SqlDataAdapter(sqlComm5)
        Dim o_Dataset5 As New DataSet()
        Dim sqlReader5 As SqlDataReader



        ' New admissions
        SQLStr = "SELECT COUNT(*) AS newad, convert(varchar(11), DateAdd(day, DateDiff(day, 0, AdmDate), 0), 101) As AdmDate " _
                            & " FROM Patient_Data.dbo.tbpatient " _
                            & " WHERE  AdmDate >= '" & txtDateFrom.Text & " 00:00:00.000' And AdmDate <= '" & txtDateTO.Text & " 23:59:59.888' " _
                            & " GROUP BY DateAdd(day, DateDiff(day, 0, AdmDate), 0)"
        sqlComm.CommandText = SQLStr
        sqlAdapter.Fill(o_Dataset)

        ' In Patients
        ' Patient.DcrDate is  null  or  Patient.DcrDate >  @ReportDate

        SQLStr1 = "SELECT COUNT(*) AS inPatient, convert(varchar(11), DateAdd(day, DateDiff(day, 0, AdmDate), 0), 101) As AdmDate " _
                                        & " FROM Patient_Data.dbo.tbpatient " _
                                        & " WHERE DcrDate is NULL or DcrDate > '" & txtDateFrom.Text & " 00:00:00.000' and AdmDate >= '" & txtDateFrom.Text & " 00:00:00.000' And AdmDate <= '" & txtDateTO.Text & " 23:59:59.888' " _
                                        & " GROUP BY DateAdd(day, DateDiff(day, 0, AdmDate), 0)"

        sqlComm1.CommandText = SQLStr1
        sqlAdapter1.Fill(o_Dataset1)
        ' OutPatients
        SQLStr2 = "SELECT COUNT(*) AS OUTPatient, convert(varchar(11), DateAdd(day, DateDiff(day, 0, AdmDate), 0), 101) As AdmDate " _
                            & " FROM Patient_Data.dbo.tbOutPatient " _
                            & " WHERE  AdmDate >= '" & txtDateFrom.Text & " 00:00:00.000' And AdmDate <= '" & txtDateTO.Text & " 23:59:59.888' " _
                            & " GROUP BY DateAdd(day, DateDiff(day, 0, AdmDate), 0)"
        sqlComm2.CommandText = SQLStr2
        sqlAdapter2.Fill(o_Dataset2)
        ' Births
        SQLStr3 = "SELECT COUNT(*) AS mybirths, convert(varchar(11), DateAdd(day, DateDiff(day, 0, AdmDate), 0), 101) As AdmDate " _
                            & " FROM Patient_Data.dbo.tbpatient " _
                            & " WHERE ServiceID = '13' AND  AdmDate >= '" & txtDateFrom.Text & " 00:00:00.000' And AdmDate <= '" & txtDateTO.Text & " 23:59:59.888' " _
                            & " GROUP BY DateAdd(day, DateDiff(day, 0, AdmDate), 0)"
        sqlComm3.CommandText = SQLStr3
        sqlAdapter3.Fill(o_Dataset3)
        ' Deaths
        SQLStr4 = "SELECT COUNT(*) AS totdeaths, convert(varchar(11), DateAdd(day, DateDiff(day, 0, AdmDate), 0), 101) As AdmDate " _
                                 & " FROM Patient_Data.dbo.tbpatient " _
                                 & " WHERE ResultID = '4' And AdmDate >= '" & txtDateFrom.Text & " 00:00:00.000' And AdmDate <= '" & txtDateTO.Text & " 23:59:59.888' " _
                                 & " GROUP BY DateAdd(day, DateDiff(day, 0, AdmDate), 0)"
        sqlComm4.CommandText = SQLStr4
        sqlAdapter4.Fill(o_Dataset4)

        ' ER
        SQLStr5 = "SELECT COUNT(*) AS ER, convert(varchar(11), DateAdd(day, DateDiff(day, 0, AdmDate), 0), 101) As AdmDate " _
                                        & " FROM Patient_Data.dbo.tbERMaster " _
                                        & " WHERE AdmDate >= '" & txtDateFrom.Text & " 00:00:00.000' And AdmDate <= '" & txtDateTO.Text & " 23:59:59.888' " _
                                        & " GROUP BY DateAdd(day, DateDiff(day, 0, AdmDate), 0)"
        sqlComm5.CommandText = SQLStr5
        sqlAdapter5.Fill(o_Dataset5)



        sqlReader = sqlComm.ExecuteReader
        sqlReader1 = sqlComm1.ExecuteReader
        sqlReader2 = sqlComm2.ExecuteReader
        sqlReader3 = sqlComm3.ExecuteReader
        sqlReader4 = sqlComm4.ExecuteReader
        sqlReader5 = sqlComm5.ExecuteReader

        With Chart1

            .Series("New-Admissions").XValueType = DataVisualization.Charting.ChartValueType.Auto
            .Series("In-Patients").XValueType = DataVisualization.Charting.ChartValueType.Auto
            .Series("Out-Patients").XValueType = DataVisualization.Charting.ChartValueType.Auto
            .Series("Births").XValueType = DataVisualization.Charting.ChartValueType.Auto
            .Series("Deaths").XValueType = DataVisualization.Charting.ChartValueType.Auto
            .Series("ER").XValueType = DataVisualization.Charting.ChartValueType.Auto

            Dim Ixx As Integer

            Do While sqlReader.Read And sqlReader1.Read And sqlReader2.Read And sqlReader3.Read And sqlReader4.Read And sqlReader5.Read
                Ixx = Ixx + 1

                If IsDBNull(sqlReader("newad")) = False Then
                    Dim CountVal As String
                    CountVal = sqlReader("newad")
                    If Val(CountVal) <> "0" Then
                        .Series("New-Admissions").Points.AddXY(sqlReader("AdmDate"), sqlReader("newad"))
                    End If
                End If

                If IsDBNull(sqlReader1("inPatient")) = False Then
                    Dim CountVal1 As String
                    CountVal1 = sqlReader1("inPatient")
                    If Val(CountVal1) <> "0" Then
                        .Series("In-Patients").Points.AddXY(sqlReader1("AdmDate"), sqlReader1("inPatient"))
                    End If
                End If


                If IsDBNull(sqlReader2("OUTPatient")) = False Then
                    Dim CountVal2 As String
                    CountVal2 = sqlReader2("OUTPatient")
                    If Val(CountVal2) <> "0" Then
                        .Series("Out-Patients").Points.AddXY(sqlReader2("AdmDate"), sqlReader2("OUTPatient"))
                    End If
                End If

                If IsDBNull(sqlReader3("mybirths")) = False Then
                    Dim CountVal3 As String
                    CountVal3 = sqlReader3("mybirths")
                    If Val(CountVal3) <> "0" Then
                        .Series("Births").Points.AddXY(sqlReader3("AdmDate"), sqlReader3("mybirths"))
                    End If
                End If

                If IsDBNull(sqlReader4("totdeaths")) = False Then
                    Dim CountVal4 As String
                    CountVal4 = sqlReader4("totdeaths")
                    If Val(CountVal4) <> "0" Then
                        .Series("Deaths").Points.AddXY(sqlReader4("AdmDate"), sqlReader4("totdeaths"))
                    End If
                End If

                If IsDBNull(sqlReader5("ER")) = False Then
                    Dim CountVal5 As String
                    CountVal5 = sqlReader5("ER")
                    If Val(CountVal5) <> "0" Then
                        .Series("ER").Points.AddXY(sqlReader5("AdmDate"), sqlReader5("ER"))
                    End If
                End If

                '.DataSource = sqlReader
                '.DataBind()
            Loop
            If Ixx = 0 Then
                Chart1.Visible = False
            Else
                Chart1.Visible = True
            End If
        End With



    Catch ex As Exception
        Response.Redirect("Dashboard.aspx")
    End Try
End Sub

Dashboard.aspx.vb

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Page.IsPostBack = False Then
        txtDate.text = DateTime.Today.Month & "/" & DateTime.Today.Day & "/" & DateTime.Today.Year

        IOPatient1.TODate = txtDate.Text

        IOPatient1.FromDate = txtDate.Text
        IOPatient1.DoChart()

    End If
End Sub

IOPatient.ascx

From Date:&nbsp; <asp:TextBox ID="txtDateFrom" runat="server"></asp:TextBox>
&nbsp;To Date:&nbsp;&nbsp;&nbsp;<asp:TextBox ID="txtDateTO" runat="server">      </asp:TextBox>
&nbsp;<asp:Button ID="btnRefreshChart" runat="server" Text="Load Chart" />


                <br />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>" >
        </asp:SqlDataSource>


                <asp:Chart ID="Chart1" runat="server" Width="934px" Height="566px">
                <Series>
                    <asp:Series BorderWidth="2" ChartArea="MainChartArea" ChartType="Line" Color="#0066FF" Name="New-Admissions" Legend="Legend1">
                    </asp:Series>
                    <asp:Series BorderWidth="2" ChartArea="MainChartArea" ChartType="Line" Color="Yellow" Legend="Legend1" Name="In-Patients">
                    </asp:Series>
                    <asp:Series BorderWidth="2" ChartArea="MainChartArea" ChartType="Line" Color="Red" Name="Out-Patients" Legend="Legend1">
                    </asp:Series>
                    <asp:Series BorderWidth="2" ChartArea="MainChartArea" ChartType="Line" Color="Black" Legend="Legend1" Name="Deaths">
                    </asp:Series>
                    <asp:Series BorderWidth="2" ChartArea="MainChartArea" ChartType="Line" Color="Lime" Legend="Legend1" Name="Births">
                    </asp:Series>
                    <asp:Series BorderWidth="2" ChartArea="MainChartArea" ChartType="Line" Color="Fuchsia" Legend="Legend1" Name="ER">
                    </asp:Series>
                </Series>
                <ChartAreas>

                    <asp:ChartArea Name="MainChartArea" Area3DStyle-Enable3D="True" AlignmentStyle="None" BackColor="192, 192, 255" BackGradientStyle="LeftRight" BorderColor="Maroon">
                        <AxisY Interval="20">
                        </AxisY>
                        <AxisX IsLabelAutoFit="False">
                            <LabelStyle Angle="-90" />
                        </AxisX>

                        

                </ChartAreas>
                    <Legends>
                        <asp:Legend Name="Legend1">
                        </asp:Legend>
                    </Legends>
            </asp:Chart>

0 个答案:

没有答案