وهذا هو الكود :
Dim connectionString As String = "Data Source=DB;Initial Catalog=OnlineTrading;Integrated Security=True"
Dim con As New Data.SqlClient.SqlConnection(connectionString)
Dim cmd As New Data.SqlClient.SqlCommand()
Dim cmd2 As New Data.SqlClient.SqlCommand()
Dim cmd3 As New Data.SqlClient.SqlCommand()
Dim cmd4 As New Data.SqlClient.SqlCommand()
Dim cmd5 As New Data.SqlClient.SqlCommand()
Dim cmd6 As New Data.SqlClient.SqlCommand()
Dim cmd7 As New Data.SqlClient.SqlCommand()
cmd.CommandType = Data.CommandType.Text
cmd.Connection = con
cmd.Parameters.Add("@DAT1", Data.SqlDbType.DateTime).Value = Calendar1.SelectedDate
cmd.Parameters.Add("@DAT2", Data.SqlDbType.DateTime).Value = Calendar2.SelectedDate
cmd.CommandText = "select count(*) from users where (CreationDate>= @DAT1) AND (CreationDate <= @DAT2)"
cmd2.CommandType = Data.CommandType.Text
cmd2.Connection = con
cmd2.Parameters.Add("@DAT1", Data.SqlDbType.DateTime).Value = Calendar1.SelectedDate
cmd2.Parameters.Add("@DAT2", Data.SqlDbType.DateTime).Value = Calendar2.SelectedDate
cmd2.CommandText = "select count(distinct(userid)) from orders where (OrderDate>= @DAT1) AND (OrderDate <= @DAT2)"
cmd3.CommandType = Data.CommandType.Text
cmd3.Connection = con
cmd3.Parameters.Add("@DAT1", Data.SqlDbType.DateTime).Value = Calendar1.SelectedDate
cmd3.Parameters.Add("@DAT2", Data.SqlDbType.DateTime).Value = Calendar2.SelectedDate
cmd3.CommandText = "select count (distinct(orderid)) from orders where ((brokerid != 1) and (brokerid != 0 and completed=1)) and ((OrderDate>= @DAT1) AND (OrderDate <= @DAT2))"
cmd4.CommandType = Data.CommandType.Text
cmd4.Connection = con
cmd4.Parameters.Add("@DAT1", Data.SqlDbType.DateTime).Value = Calendar1.SelectedDate
cmd4.Parameters.Add("@DAT2", Data.SqlDbType.DateTime).Value = Calendar2.SelectedDate
cmd4.CommandText = "select sum(quantity * price) from orders , tickers where (orders.tickerid=tickers.tickerid and completed=1 and (brokerid = 1 or brokerid = 0 )and marketid=2) and ((OrderDate>= @DAT1) AND (OrderDate <= @DAT2))"
cmd5.CommandType = Data.CommandType.Text
cmd5.Connection = con
cmd5.Parameters.Add("@DAT1", Data.SqlDbType.DateTime).Value = Calendar1.SelectedDate
cmd5.Parameters.Add("@DAT2", Data.SqlDbType.DateTime).Value = Calendar2.SelectedDate
cmd5.CommandText = "select sum(quantity * price) from orders , tickers where (orders.tickerid=tickers.tickerid and completed=1 and (brokerid = 1 or brokerid = 0 )and marketid=15) and ((OrderDate>= @DAT1) AND (OrderDate <= @DAT2))"
cmd6.CommandType = Data.CommandType.Text
cmd6.Connection = con
cmd6.Parameters.Add("@DAT1", Data.SqlDbType.DateTime).Value = Calendar1.SelectedDate
cmd6.Parameters.Add("@DAT2", Data.SqlDbType.DateTime).Value = Calendar2.SelectedDate
cmd6.CommandText = "select sum(quantity * price) from orders , tickers where (orders.tickerid=tickers.tickerid and completed=1 and (brokerid != 1 and brokerid != 0 )and marketid=2) and ((OrderDate>= @DAT1) AND (OrderDate <= @DAT2))"
cmd7.CommandType = Data.CommandType.Text
cmd7.Connection = con
cmd7.Parameters.Add("@DAT1", Data.SqlDbType.DateTime).Value = Calendar1.SelectedDate
cmd7.Parameters.Add("@DAT2", Data.SqlDbType.DateTime).Value = Calendar2.SelectedDate
cmd7.CommandText = "select sum(quantity * price) from orders , tickers where (orders.tickerid=tickers.tickerid and completed=1 and (brokerid != 1 and brokerid != 0 )and marketid=15) and ((OrderDate>= @DAT1) AND (OrderDate <= @DAT2))"
con.Open()
Dim numusers As String = CInt(cmd.ExecuteScalar())
Label1.Text = numusers.ToString
Dim numtrd As String = CInt(cmd2.ExecuteScalar())
Label2.Text = numtrd.ToString
Dim numontrd As String = CInt(cmd3.ExecuteScalar())
Label3.Text = numontrd.ToString
Dim numvoldfmotc As String = CInt(cmd4.ExecuteScalar() / 1000)
Label4.Text = numvoldfmotc.ToString
Dim numvoladsmotc As String = CInt(cmd5.ExecuteScalar() / 1000)
Label5.Text = numvoladsmotc.ToString
Dim numvoldfmot As String = CInt(cmd6.ExecuteScalar() / 1000)
Label6.Text = numvoldfmot.ToString
Dim numvoladsmot As String = CInt(cmd7.ExecuteScalar() / 1000)
Label7.Text = numvoladsmot.ToStringكما ترون في الكود انه تم استخدام 7 كوماند ابجكت , وهذا يبطأ الصفح و كيف يمكن لي ان اختصرها .
