|
Tady je výpis události při kliknutí na tlačítko:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'ViewState("pocet_sl") = CInt(TextBox6.Text)
Dim con As SqlConnection
Dim ada As SqlDataAdapter
'Dim ada2 As SqlDataAdapter
'Dim dst As DataSet
Dim dst As DataTable
Dim dst2 As DataTable
con = New SqlConnection("Data Source=DMCZQRSRV;Initial Catalog=CIGMA;User ID=cigma; Password=cigma;")
'Zjisteni poctu dnu v mesici
Dim strDays
Dim strYear
Dim strMonth
strYear = Left(TextBox1.Text, 4)
strMonth = Right(TextBox1.Text, 2)
Select Case CInt(strMonth)
Case 1, 3, 5, 7, 8, 10, 12
strDays = 31
Case 4, 6, 9, 11
strDays = 30
Case 2
If ((CInt(strYear) Mod 4 = 0 And _
CInt(strYear) Mod 100 <> 0) _
Or (CInt(strYear) Mod 400 = 0)) Then
strDays = 29
Else
strDays = 28
End If
End Select
'If DropDownList1.SelectedIndex = 0 Then
'TextBox6.Text = DropDownList1.SelectedItem.Value
If TextBox5.Text = "" Then
ada = New SqlDataAdapter("select warehouse,customerno,shiptono,truckno,partno,shippingdd,qty from HSprout where warehouse like '%" + DropDownList1.SelectedItem.Value + "%' and shippingym = '" + TextBox1.Text + "' and [partno] like '%" + TextBox2.Text + "%' and [customerno] like '%" + TextBox3.Text + "%' and [shiptono] like '" + TextBox4.Text + "%'order by warehouse,customerno,shiptono,partno", con)
dst = New DataTable
dst.Columns.Add(New DataColumn(("Sum1"), GetType(Single)))
con.Open()
ada.Fill(dst)
con.Close()
'Oznaceni duplicitnich zaznamu do sloupce 0,vzdy cislo udava pocet stejnych radku,ktere jsou bez cisel a odstrani se dale
Dim temp
Dim temp2
Dim pocitadlo As Integer = 0
Dim i As Integer = 0
Dim j As Integer = 0
If i <> dst.Rows.Count - 1 Then
For i = 1 To dst.Rows.Count - 1
temp = dst.Rows(i).Item(5)
temp2 = dst.Rows(i).Item(2)
If i = dst.Rows.Count Then
dst.Rows(i - 1 - pocitadlo).Item(0) = 1
End If
If temp = dst.Rows(i - 1).Item(5) And temp2 = dst.Rows(i - 1).Item(2) Then
pocitadlo = pocitadlo + 1
Else
dst.Rows(i - 1 - pocitadlo).Item(0) = pocitadlo + 1
pocitadlo = 0
End If
Next
If i = dst.Rows.Count Then
dst.Rows(i - 1 - pocitadlo).Item(0) = pocitadlo + 1
End If
Else
dst.Rows(dst.Rows.Count - 1).Item(0) = 1
End If
dst.Columns.Add(New DataColumn(("Sum"), GetType(Single)))
'Vygenerovani sloupcu pro data v mesicich/dnech
dst.Columns.Add(New DataColumn(("1st"), GetType(Single)))
dst.Columns.Add(New DataColumn(("2nd"), GetType(Single)))
dst.Columns.Add(New DataColumn(("3rd"), GetType(Single)))
For i = 4 To strDays
dst.Columns.Add(New DataColumn((i & "th"), GetType(Single)))
Next
'Nulovani vsech dnu
For i = 0 To dst.Rows.Count - 1
For j = 9 To dst.Columns.Count - 1
dst.Rows(i).Item(j) = 0
Next
Next
'Provedeni souctu duplicitnich zaznamu
Dim pocet As Integer = 0
Dim pole(31) As Integer
i = 0
j = 0
temp = 0
Dim zapis As Boolean = False
While i <> dst.Rows().Count
If Not dst.Rows(i).Item(0) Is DBNull.Value Then
temp = i
Array.Clear(pole, 0, 30)
pole(CInt(dst.Rows(i).Item(6))) = dst.Rows(i).Item(7)
dst.Rows(temp).Item(CInt(dst.Rows(i).Item(6)) + 8) = dst.Rows(i).Item(7)
'j = i
zapis = True
Else
If pole(CInt(dst.Rows(i).Item(6))) <> 0 Then
pole(CInt(dst.Rows(i).Item(6))) = pole(CInt(dst.Rows(i).Item(6))) + dst.Rows(i).Item(7)
dst.Rows(temp).Item(CInt(dst.Rows(i).Item(6)) + 8) = dst.Rows(temp).Item(CInt(dst.Rows(i).Item(6)) + 8) + dst.Rows(i).Item(7)
Else
pole(CInt(dst.Rows(i).Item(6))) = dst.Rows(i).Item(7)
dst.Rows(temp).Item(CInt(dst.Rows(i).Item(6)) + 8) = dst.Rows(i).Item(7)
End If
End If
i = i + 1
End While
'Smazani radku
For j = 0 To dst.Rows.Count - 1
If dst.Rows(j).Item(0) Is DBNull.Value Then
dst.Rows(j).Delete()
End If
Next
dst.Columns.Remove("truckno")
dst.Columns(4).ColumnName() = "Part No."
Else 'KOD PRO ZADANY TRUCKNO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ada = New SqlDataAdapter("select warehouse,customerno,shiptono,truckno,partno,shippingdd,qty from HSprout where warehouse like '%" + DropDownList1.SelectedItem.Value + "%' and shippingym = '" & TextBox1.Text & "' and [partno] like '%" + TextBox2.Text + "%' and [customerno] like '%" + TextBox3.Text + "%' and [shiptono] like '" + TextBox4.Text + "%' and [truckno] like '" + TextBox5.Text + "%'order by warehouse,customerno,shiptono,truckno,partno", con)
dst = New DataTable
dst.Columns.Add(New DataColumn(("Sum1"), GetType(Single)))
con.Open()
ada.Fill(dst)
con.Close()
'Oznaceni duplicitnich zaznamu
Dim temp
Dim temp2
Dim temp3
Dim pocitadlo As Integer = 0
Dim i As Integer = 0
Dim j As Integer = 0
If i <> dst.Rows.Count - 1 Then
For i = 1 To dst.Rows.Count - 1
temp = dst.Rows(i).Item(5)
temp2 = dst.Rows(i).Item(4)
temp3 = dst.Rows(i).Item(6)
If i = dst.Rows.Count Then
dst.Rows(i - 1 - pocitadlo).Item(0) = 1
End If
If temp = dst.Rows(i - 1).Item(5) And temp2 = dst.Rows(i - 1).Item(4) And temp3 = dst.Rows(i - 1).Item(6) Then
pocitadlo = pocitadlo + 1
Else
dst.Rows(i - 1 - pocitadlo).Item(0) = pocitadlo + 1
pocitadlo = 0
End If
Next
If i = dst.Rows.Count Then
dst.Rows(i - 1 - pocitadlo).Item(0) = pocitadlo + 1
End If
Else
dst.Rows(dst.Rows.Count - 1).Item(0) = 1
End If
dst.Columns.Add(New DataColumn(("Sum"), GetType(Single)))
'Vygenerovani sloupcu pro data v mesicich/dnech
dst.Columns.Add(New DataColumn(("1st"), GetType(Single)))
dst.Columns.Add(New DataColumn(("2nd"), GetType(Single)))
dst.Columns.Add(New DataColumn(("3rd"), GetType(Single)))
For i = 4 To strDays
dst.Columns.Add(New DataColumn((i & "th"), GetType(Single)))
Next
'Nulovani vsech dnu
For i = 0 To dst.Rows.Count - 1
For j = 9 To dst.Columns.Count - 1
dst.Rows(i).Item(j) = 0
Next
Next
'Provedeni souctu duplicitnich zaznamu
Dim pocet As Integer = 0
Dim pole(31) As Integer
i = 0
j = 0
temp = 0
Dim zapis As Boolean = False
While i <> dst.Rows().Count
If Not dst.Rows(i).Item(0) Is DBNull.Value Then
temp = i
Array.Clear(pole, 0, 30)
pole(CInt(dst.Rows(i).Item(6))) = dst.Rows(i).Item(7)
dst.Rows(temp).Item(CInt(dst.Rows(i).Item(6)) + 8) = dst.Rows(i).Item(7)
'j = i
zapis = True
Else
If pole(CInt(dst.Rows(i).Item(6))) <> 0 Then
pole(CInt(dst.Rows(i).Item(6))) = pole(CInt(dst.Rows(i).Item(6))) + dst.Rows(i).Item(7)
dst.Rows(temp).Item(CInt(dst.Rows(i).Item(6)) + 8) = dst.Rows(temp).Item(CInt(dst.Rows(i).Item(6)) + 8) + dst.Rows(i).Item(7)
Else
pole(CInt(dst.Rows(i).Item(6))) = dst.Rows(i).Item(7)
dst.Rows(temp).Item(CInt(dst.Rows(i).Item(6)) + 8) = dst.Rows(i).Item(7)
End If
End If
i = i + 1
End While
'Smazani(radku)
For j = 0 To dst.Rows.Count - 1
If dst.Rows(j).Item(0) Is DBNull.Value Then
dst.Rows(j).Delete()
End If
Next
dst.Columns(4).ColumnName() = "Truck No."
dst.Columns(5).ColumnName() = "Part No."
End If
dst.Columns.Remove("Sum1")
dst.Columns.Remove("shippingdd")
dst.Columns.Remove("qty")
dst.Columns(0).ColumnName() = "Warehouse"
dst.Columns(1).ColumnName() = "Customer"
dst.Columns(2).ColumnName() = "Ship to"
'dst.Columns(3).ColumnName() = "Part No."
ViewState("data") = dst
Dim duData As New DataView(dst)
'GvEmployee.Width = 2500
ViewState("pocet_sl") = 4
GvEmployee.DataSource = duData
'GridView1.DataSource = duData2
'GridView1.Sort(, SortDirection.Ascending)
GvEmployee.DataBind()
'GridView1.DataBind()
'TextBox3.Text = GvEmployee.Rows(1).Cells.Count
'TextBox1.Text = GvEmployee.Rows.Count
'TextBox1.Text = DropDownList1.SelectedIndex
'If Not GvEmployee.Rows.Count = 0 Then
'Dim soucet As Integer = 0
'Dim dgItem As GridViewRow '= GvEmployee.Rows(10)
'For i As Integer = 0 To GvEmployee.Rows.Count - 1 'projít všechny řádky
'For i As Integer = 0 To GvEmployee.Rows.Count - 1
'If GvEmployee.Rows(i).RowType = DataControlRowType.DataRow Then 'pouze pokud to je řádek s daty, nechceme záhlaví ani zápatí
'GvEmployee.FooterRow.Cells(3).Text = Decimal.Parse(dgItem.Cells(3).Text) 'CInt(GvEmployee.Rows(i).DataItem("sum1st")) 'přičteme do součtu hodnotu z každého řádku ze druhého sloupce
' soucet = soucet + GvEmployee.Rows(i)
'End If
' Next
'duData.RowFilter = "[state] LIKE '" & txtFilter.Text.ToUpper() & "%'"
'GvEmployee.Rows(2).Cells(2).Text = String.Format("{0:#,#.##}", CInt(GvEmployee.Rows(2).Cells(2).Text))
'TextBox3.Text = GvEmployee.Rows.Count
'Formatovani bunek (musime vylepsit)
'For i As Integer = 2 To GvEmployee.Rows(1).Cells.Count - 1
'For j As Integer = 0 To GvEmployee.Rows.Count - 1
'Next
'Next
'GvEmployee.FooterRow.Cells(1).Text = GvEmployee.Rows(0).DataItem("IdZak")
'soucet += Convert.ToInt32(DataBinder.Eval(GvEmployee.Row.DataItem, "IdTrida"))
'GvEmployee.FooterRow.Cells(9).Text = soucet.ToString()
'Dalsi(pokus)
' Dim i As Integer
' Dim dgItem As GridViewRow = GvEmployee.Rows(0)
' Dim dgItem2 As GridViewRow = GvEmployee.Rows(1)
' Dim lblid As Label = CType(dgItem.FindControl("IdZak"), Label)
' GvEmployee.FooterRow.Cells(5).Text = Decimal.Parse(dgItem.Cells(5).Text) + Decimal.Parse(dgItem2.Cells(5).Text)
' majne.Visible = False
' Else
' majne.Visible = True
'End If
GvEmployee.FooterRow.Cells(0).Text = "Sum"
'TextBox3.Text = GridView1.Rows.Count
' For i = 0 To 5
'Response.Write(pole(i) & "<br />")
' Next
GvEmployee.FooterRow.Cells(35).Visible = False
GvEmployee.FooterRow.Cells(34).Visible = False
' GvEmployee.FooterRow.Cells(33).Visible = False
'GvEmployee.FooterRow.Cells(32).Visible = False
End Sub
|