A part of a system I am creating has a kitchen display system but I dont get how to automatically display the contents in my form
Public Sub GetOrders()
Try
kitchenFlowLayoutPanel.Controls.Clear()
Dim i As Integer
Dim sql As String
sql = "SELECT c.cart_id, c.invoice_no, c.table_no, c.sale_time, f.item_name, c.serve_size, c.quantity FROM tbl_cart AS c INNER JOIN tbl_food AS f on f.item_id = c.items_id WHERE c.status='Pending'"
conn.Open()
cmd = New MySqlCommand(sql, conn)
cmd.ExecuteReader()
conn.Close()
Dim dTable1 As New DataTable()
Dim dAdaptor1 As New MySqlDataAdapter(cmd)
dAdaptor1.Fill(dTable1)
Dim panel1 As FlowLayoutPanel
Dim panel2 As FlowLayoutPanel
For i = 0 To dTable1.Rows.Count - 1
panel1 = New FlowLayoutPanel
panel1.AutoSize = True
panel1.Width = 260
panel1.Height = 500
panel1.FlowDirection = FlowDirection.TopDown
panel1.BorderStyle = BorderStyle.FixedSingle
panel1.Margin = New Padding(10, 10, 10, 10)
panel2 = New FlowLayoutPanel
panel2.BackColor = Color.FromArgb(50, 55, 89)
panel2.AutoSize = True
panel2.Width = 230
panel2.Height = 125
panel2.FlowDirection = FlowDirection.TopDown
panel2.Margin = New Padding(0, 0, 0, 0)
Dim label1 As New Label
label1.ForeColor = Color.White
label1.Margin = New Padding(10, 5, 3, 0)
label1.Font = New Font(label1.Font, FontStyle.Bold)
label1.AutoSize = True
Dim label2 As New Label
label2.ForeColor = Color.White
label2.Margin = New Padding(10, 5, 3, 0)
label2.AutoSize = True
Dim label3 As New Label
label3.ForeColor = Color.White
label3.Margin = New Padding(10, 5, 3, 0)
label3.AutoSize = True
Dim label4 As New Label
label4.ForeColor = Color.White
label4.Margin = New Padding(10, 5, 3, 0)
label4.AutoSize = True
Dim label5 As New Label
label5.ForeColor = Color.White
label5.Margin = New Padding(10, 5, 3, 0)
label5.AutoSize = True
label1.Text = "Entry ID : " & dTable1.Rows(i)("cart_id").ToString
label2.Text = "Invoice No : " & dTable1.Rows(i)("invoice_no").ToString
label3.Text = "Table No : " & dTable1.Rows(i)("table_no").ToString
label4.Text = "Order Time : " & dTable1.Rows(i)("sale_time").ToString
label5.Text = Environment.NewLine & "ORDERED ITEM : " & Environment.NewLine & Environment.NewLine & " Item : " & dTable1.Rows(i)("item_name").ToString & Environment.NewLine & " Serve Size : " & dTable1.Rows(i)("serve_size").ToString & Environment.NewLine & " Qty: " & dTable1.Rows(i)("quantity").ToString & Environment.NewLine & Environment.NewLine
panel2.Controls.Add(label1)
panel2.Controls.Add(label2)
panel2.Controls.Add(label3)
panel2.Controls.Add(label4)
panel2.Controls.Add(label5)
panel1.Controls.Add(panel2)
Dim btn As New Guna.UI2.WinForms.Guna2Button
btn.AutoRoundedCorners = True
btn.Size = New Size(100, 35)
btn.FillColor = Color.FromArgb(241, 85, 126)
btn.Margin = New Padding(60, 5, 3, 10)
btn.Location = New Point(0, 0)
btn.Text = "Complete"
btn.Tag = dTable1.Rows(i)("cart_id").ToString ' store id
AddHandler btn.Click, AddressOf btn_Click
panel2.Controls.Add(btn)
kitchenFlowLayoutPanel.Controls.Add(panel1)
Next
Catch ex As Exception
conn.Close()
MsgBox(ex.Message, vbCritical)
End Try
End Sub
I tried putting it in a do loop but it shows errors even before I can log in to the system.
I have also tried to use incorporate "GetOrders().refresh" but it was also not working.
It is difficult to understand what exactly you're trying to achieve.
In this example, a button named RefreshButton was added to the Form.
This shows your GetOrders method getting called from the ButtonClick event.
Private Sub GetOrders()
'your GetOrders code...
End Sub
Private Sub RefreshButton_Click(sender As Object, e As EventArgs) Handles RefreshButton.Click
Try
GetOrders() ' this will call your GetOrders method
Catch ex As Exception
MessageBox.Show(String.Concat("An error occurred: ", ex.Message))
End Try
End Sub
Related
I have a query in the SqlServer database, the result of that query is played inside a Datagridview, the result can contain from 0 to 100 data or even more if you doubt it.
I'm trying to print the "Identification" column of Datagridview horizontally, but without success. I have researched in several places and nothing too.
screenshot of form with DataGridView
Follow the form code:
Imports System.ComponentModel
Imports System.Data.SqlClient
Imports System.Drawing.Printing
Public Class frm_relatorio_entregas
' Variables used in the module
Dim RelatorioTitulo As String ' Report title
Dim paginaatual As Integer ' Page number being printed
Dim LinhaAtual As Integer ' Current line number being printed
Dim LinhasporPagina As Integer ' Number of lines per page
Dim PosicaoDaLinha As Single ' Position of the line being printed
Dim registro As Integer ' Record being printed
Private Sub Imprimir()
RelatorioTitulo = "Delivery Report"
Dim doc As PrintDocument = New PrintDocument
AddHandler doc.PrintPage, New Printing.PrintPageEventHandler(AddressOf Me.pdRelatorios_Printpage)
AddHandler doc.BeginPrint, New Printing.PrintEventHandler(AddressOf Me.Begin_Print)
Dim dialogo As PrintDialog = New PrintDialog
'dialogo.Document = doc
' If (dialogo.ShowDialog = DialogResult.OK) Then
Dim preview As PrintPreviewDialog = New PrintPreviewDialog()
preview.Document = doc
preview.WindowState = FormWindowState.Maximized
preview.PrintPreviewControl.Zoom = 1.0
preview.ShowDialog()
'End If
End Sub
Private Sub Begin_Print(ByVal sender As Object, ByVal e As Printing.PrintEventArgs)
' Assigning values to variables at the start of printing
LinhaAtual = 0
paginaatual = 1
PosicaoDaLinha = 0
registro = 0
End Sub
Private Sub pdRelatorios_Printpage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
' Margin variables (e.MarginBounds obtain the rectangular area that represents the part of the page within the margins.)
Dim MargemEsquerda As Single = e.MarginBounds.Left
Dim MargemDireita As Single = e.MarginBounds.Right
Dim MargemSuperior As Single = e.MarginBounds.Top
Dim MargemInferios As Single = e.MarginBounds.Bottom
'Pen class defines an object used to define lines and curves
Dim CanetaDaImpressora As Pen = New Pen(Color.Black, 1)
'Variables of the fonts used (the font class defines a specific format for text, including font face, size and style attributes.
Dim FonteNegrito As Font
Dim FonteTitulo As Font
Dim FonteSubTitulo As Font
Dim FonteRodape As Font
Dim FonteNormal As Font
Dim font1 As Font
'Define effects on fonts used
FonteNegrito = New Font("Arial", 9, FontStyle.Bold)
FonteTitulo = New Font("Arial", 13, FontStyle.Bold)
FonteSubTitulo = New Font("Arial", 9, FontStyle.Bold)
FonteRodape = New Font("Arial", 8)
FonteNormal = New Font("Calibri", 9)
font1 = New Font("Segoe UI", 8, FontStyle.Bold)
'Print the title of the report
e.Graphics.DrawString(RelatorioTitulo, FonteTitulo, Brushes.Black, MargemEsquerda + 200, 30, New StringFormat)
If DateTimePicker1.Value = DateTimePicker1.Value Then
e.Graphics.DrawString(DateTimePicker1.Value, FonteSubTitulo, Brushes.Black, MargemEsquerda + 900, 30, New StringFormat)
Else
e.Graphics.DrawString(DateTimePicker1.Value & " - " & DateTimePicker1.Value, FonteSubTitulo, Brushes.Black, MargemEsquerda + 900, 30, New StringFormat)
End If
'Define the number of lines per page
LinhasporPagina = CInt(e.MarginBounds.Height / New Font("Calibri", 18).GetHeight(e.Graphics) - 2)
While (LinhaAtual <= LinhasporPagina AndAlso registro <= DataGridView1.Rows.Count - 1)
PosicaoDaLinha = MargemSuperior + (LinhaAtual * New Font("Calibri", 18).GetHeight(e.Graphics) + 30)
e.Graphics.DrawString(DataGridView1.Rows(registro).Cells(0).Value.ToString, New Font("Calibri", 8, FontStyle.Bold), Brushes.Black, 30, PosicaoDaLinha, New StringFormat())
'Increment record
registro += 1
'increment line
LinhaAtual += 1
End While
'baseboard
e.Graphics.DrawLine(CanetaDaImpressora, 20, MargemInferios + 15, 1150, MargemInferios + 15)
e.Graphics.DrawString(System.DateTime.Now.ToString(), FonteRodape, Brushes.Black, 30, MargemInferios + 15, New StringFormat())
e.Graphics.DrawString("Página : " & paginaatual, FonteRodape, Brushes.Black, 1070, MargemInferios + 15, New StringFormat)
'Increase the page number
paginaatual += 1
'Here check if you are going to open a new page
If (LinhaAtual > LinhasporPagina) Then
' When you open a new page, you have to reset LlinhaAtual
e.HasMorePages = True
LinhaAtual = 0
Else
e.HasMorePages = False
End If
End Sub
Private Sub frm_relatorio_entregas_Load(sender As Object, e As EventArgs) Handles MyBase.Load
txtcod.Clear()
txtrazao.Clear()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
DateTimePicker1.ResetText()
DateTimePicker2.ResetText()
ComboBox1.SelectedIndex = 0
txtcod.Select()
End Sub
Private Sub txtcod_KeyUp(sender As Object, e As KeyEventArgs) Handles txtcod.KeyUp
If e.KeyCode = Keys.F2 Then
frm_consulta_cliente_cadastro.ShowDialog()
End If
End Sub
Private Sub consulta()
DataGridView1.Rows.Clear()
Cursor.Current = Cursors.WaitCursor
Dim consultando As New frm_aguarde_consultando
consultando.Show()
' Set cursor as hourglass
Application.DoEvents()
Dim ano, mes, dia As Integer
Dim var1data, var2data As Date
Dim dinicio, dfim As String
var1data = DateTimePicker1.Value '.ToString.Substring(0, 10)
dia = var1data.Day
mes = var1data.Month
ano = var1data.Year
dinicio = ano & "-" & mes & "-" & dia
var2data = DateTimePicker2.Value
dia = var2data.Day
mes = var2data.Month
ano = var2data.Year
dfim = ano & "-" & mes & "-" & dia
Using sqlcoon As SqlConnection = GetConnectionsql()
Dim READER As SqlDataReader
Try
sqlcoon.Open()
Dim Query As String
Query = "select MOV_IDENTIFICACAO,MOV_PROTOCOLO,MOV_DATADOC,MOV_SITUACAO,MOV_DATAENTREGA,MOV_HORAENTREGA,MOV_SITEND_CODIGO
from movimento where MOV_DATADOC = '" & dinicio & "'
AND MOV_CLI_CODIGO = '" & txtcod.Text & "' AND MOV_SITUACAO = '" & "E" & "'
AND CAST(MOV_DATAENTREGA AS DATE) = '" & dfim & "' "
Dim COMMAND As SqlCommand = New SqlCommand(Query, sqlcoon)
READER = COMMAND.ExecuteReader
While READER.Read
Dim MOV_IDENTIFICACAO = READER("MOV_IDENTIFICACAO")
Dim MOV_DATADOC = READER("MOV_DATADOC")
Dim MOV_DATAENTREGA = READER("MOV_DATAENTREGA")
Dim MOV_PROTOCOLO = READER("MOV_PROTOCOLO")
Dim MOV_SITUACAO = READER("MOV_SITUACAO")
Dim MOV_SITEND_CODIGO = READER("MOV_SITEND_CODIGO")
DataGridView1.Rows.Add(MOV_IDENTIFICACAO, MOV_PROTOCOLO, MOV_DATADOC, MOV_SITUACAO, MOV_DATAENTREGA, MOV_SITEND_CODIGO)
End While
READER.Close()
sqlcoon.Close()
''--------------'''''''''
Label9.Text = DataGridView1.Rows.Count
For Each linha In DataGridView1.Rows
Dim altura As Integer = 17
linha.height = altura
Next
If DataGridView1.Rows.Count >= 0 Then
' Set cursor as default arrow
Cursor.Current = Cursors.Default
' Hide the please wait form
consultando.Hide()
End If
Catch ex As SqlException
MessageBox.Show(ex.Message)
Finally
' sqlcoon.Dispose()
End Try
sqlcoon.Open()
Try
For r As Integer = 0 To DataGridView1.Rows.Count - 1
Dim COMMAND3 As SqlCommand
Dim READER3 As SqlDataReader
Dim Query_3 As String
Query_3 = "select IMOV_CODIGORECBTO from imovimento where IMOV_MOV_IDENTIFICACAO ='" & DataGridView1.Rows(r).Cells(0).Value.ToString & "'"
COMMAND3 = New SqlCommand(Query_3, sqlcoon)
READER3 = COMMAND3.ExecuteReader
While READER3.Read
Dim IMOV_CODIGORECBTO = READER3("IMOV_CODIGORECBTO")
'DataGridView1.Columns(6).HeaderCell.Value = "ID"
DataGridView1.Rows(r).Cells(6).Value = IMOV_CODIGORECBTO
End While
READER3.Close()
Next
DataGridView1.Sort(DataGridView1.Columns(6), ListSortDirection.Ascending)
sqlcoon.Close()
Catch ex As SqlException
MsgBox(ex.Message)
End Try
End Using
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
consulta()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Imprimir()
End Sub
End Class
screenshot of what is currently being printed
screenshot of I would like the result to be:
Would anyone have any ideas, tools or means to help me? I thank.
An alternative would be to:
Get just the column values that you want.
Join the values from #1 using a delimiter, such as a tab.
Use the Graphics.DrawString method (documentation) for the value from #2.
There will need to be some considerations:
You will need to measure the string from #3 to see if it exceeds the bounds of your print document
If so, then you will need to print multiple pages, picking up where you left off.
Update
Per the OP's request, here is an example. Keep in mind that it doesn't account for the considerations listed above. That will take a bit of effort in debugging to account for those points:
Private Sub pdRelatorios_PrintPage(sender As Object, e As PrintPageEventArgs) Handles pdRelatorios.PrintPage
Dim title = "Relatorio de Entregas"
Dim titleFont = New Font(Font.FontFamily, Convert.ToSingle(Font.Size * 1.5), FontStyle.Bold)
Dim titlePosition = New PointF(Convert.ToSingle(e.MarginBounds.X * 2 - e.PageBounds.Width / 2), e.MarginBounds.Y)
Dim titleSize = e.Graphics.MeasureString(title, titleFont)
e.Graphics.DrawString(title, titleFont, SystemBrushes.ControlText, titlePosition)
Dim cellValues = DataGridView1.Rows.Cast(Of DataGridViewRow).Select(Function(row) row.Cells(0)?.Value?.ToString())
Dim joinedCellValues = String.Join(Constants.vbTab, cellValues)
Dim bodyBounds = New RectangleF(e.MarginBounds.X, Convert.ToSingle(titleSize.Height + e.MarginBounds.Y), e.PageBounds.Width - e.MarginBounds.X * 2, e.PageBounds.Height - e.MarginBounds.Y * 2)
e.Graphics.DrawString(joinedCellValues, Font, SystemBrushes.ControlText, bodyBounds)
End Sub
I have create an application that need to generate about 100 to 1000 object programmatically. This object will be generated with the same amount in the database. In order to accomplish objective above, of course i need to call the data from database, then i looping through each data to generate each object. But it takes such a very long time before it done. I hoping that you have an alternative way beside how i do this.
Below is my code to call the data from database
Dim tbls As New DataTable
Using cons As New SqlConnection(stringconnection)
Dim sqls = "select * from tbsectiondetail where IDSection = '" & txtIDSection.Text &
"' AND KodeLocation like '%" & txtCari.Text &
"%' AND Status like '%" & cbStatus.Text &
"%' ORDER BY Status DESC"
Dim adps As New SqlDataAdapter(sqls, cons)
adps.Fill(tbls)
adps.Dispose()
cons.Dispose()
End Using
If i just generate the data only, its just take only 1 to 2 second. So i don't think there is problem about how i call the data from database
And below is how i generate the object through looping the data
Dim resultsx As DataRow() = tbls.Select("")
If resultsx.Count > 0 Then
For iX = 0 To resultsx.Count - 1
'CREATE A VARIABLE
Dim IDSectionDetail = resultsx(iX)("IDSectionDetail").ToString
Dim NamaLocation = resultsx(iX)("NamaLocation").ToString
Dim SectionKode = resultsx(iX)("KodeLocation").ToString
Dim StatusSection = resultsx(iX)("Status").ToString
Dim StatusSectionAt = resultsx(iX)("StatusAt").ToString
Dim StatusC1 = resultsx(iX)("StatusC1").ToString
Dim StatusC2 = resultsx(iX)("StatusC2").ToString
'GENERATE A PANEL
Dim pnlContainer As New Panel
pnlContainer.Size = New Size(290, 200)
Tablex.Controls.Add(pnlContainer, curColumn, rowNo)
pnlContainer.Dock = DockStyle.Fill
Dim pnlHeader As New Panel
pnlContainer.Controls.Add(pnlHeader)
pnlHeader.Dock = DockStyle.Top
pnlHeader.Size = New Size(pnlContainer.Width, 35)
If StatusSection = "Open" Then
pnlHeader.BackColor = Color.DarkSlateGray
Else
pnlHeader.BackColor = Color.FromArgb(185, 58, 50)
End If
pnlContainer.Controls.SetChildIndex(pnlHeader, 2)
'GENERATE LABEL HEADER
Dim lblHeader As New Label
lblHeader.Text = NamaLocation & " - " & SectionKode
pnlHeader.Controls.Add(lblHeader)
lblHeader.Font = New Font("Century Gothic", 9, FontStyle.Bold Or FontStyle.Italic)
lblHeader.ForeColor = Color.White
lblHeader.Location = New Point(8, 7)
lblHeader.AutoSize = True
'GENERATE LABEL STATUS
Dim lblStatus As New Label
lblStatus.Text = "Status : " & StatusSection
pnlHeader.Controls.Add(lblStatus)
lblStatus.Font = New Font("Century Gothic", 8, FontStyle.Bold Or FontStyle.Italic)
lblStatus.ForeColor = Color.White
lblStatus.TextAlign = ContentAlignment.MiddleRight
lblStatus.Height = pnlHeader.Height
lblStatus.Dock = DockStyle.Right
lblStatus.AutoSize = True
'GENERATE PANEL FOOTER
Dim pnlFooter As New Panel
pnlContainer.Controls.Add(pnlFooter)
pnlFooter.Dock = DockStyle.Fill
pnlFooter.Size = New Size(pnlFooter.Width, 35)
pnlFooter.BackColor = Color.White
pnlContainer.Controls.SetChildIndex(pnlFooter, 0)
'GENERATE BUTTON DETAIL
Dim btnDetail As New Button
pnlFooter.Controls.Add(btnDetail)
btnDetail.Name = "btn" & SectionKode
btnDetail.FlatStyle = FlatStyle.Flat
btnDetail.FlatAppearance.BorderColor = Color.FromArgb(46, 74, 98)
btnDetail.FlatAppearance.BorderSize = 1
btnDetail.FlatAppearance.MouseDownBackColor = Color.Gold
btnDetail.FlatAppearance.MouseOverBackColor = Color.Gold
btnDetail.BackColor = Color.DarkSlateGray
btnDetail.Text = "Detail"
btnDetail.Image = My.Resources.search2_icon
btnDetail.Font = New Font("Century Gothic", 8, FontStyle.Bold)
btnDetail.TextImageRelation = TextImageRelation.TextBeforeImage
btnDetail.Location = New Point(181, 84)
btnDetail.Anchor = AnchorStyles.Right And AnchorStyles.Top
btnDetail.Size = New Size(75, 28)
btnDetail.ForeColor = Color.White
AddHandler btnDetail.Click, Sub() DetailSection(IDSectionDetail, SectionKode)
curColumn += 1
If curColumn >= 5 Then
curColumn = 0
RowCount += 1
Tablex.RowCount = RowCount
rowNo += 1
End If
Next
End If
pnlFill.Controls.Add(Tablex)
Actually there is still more object to generate through that looping. But from my analysis, the looping already take such a long time already just from code above.
The result of the generated object
I just wonder if there is another and faster alternative to generate such object. Or do i need to give up to design and just make it simple black and white ?
I have a toolstrip menu button called Refresh. The button calls the sub LoadListview(). What this does, using a SQL Query and recordset to populate my listview with the oracle table contents. Works just fine.
However recently I've been asked to just update the listview automaticly after a change has occurred. So one of the columns is quantity and if someone edits the quantity from 10 to 9 rather than clicking refresh which query's the table again calling LoadListView() I just called LoadListView() in the code after making a change.
This is where it gets weird. When you click refresh calling LoadListView() it works fine.
When you call LoadListView() or even call the click for the refresh button in code ToolStripButtonRefresh.PerformClick() it errors on the below line with the following error:
The system cannot find message text for message number 0x80040e0c in the message file for OraOLEDB
Public Sub LoadListview()
rsMPCS_Con.Open(UCase(SQLQuery), conMPCS2, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockReadOnly)
.........
End Sub
So click refresh button which calls LoadListView() Fine. Call ToolStripButtonRefresh.PerformClick() which calls LoadListView() then the error. Can't figure it out.
Public Sub LoadListview()
Dim IT As Integer
Dim currentSize As Integer
Dim arrValues(10) As String
ConnectionCheck()
Try
iPageSize = cboPerPage.Text
Try
rsMPCS_Con.Close()
Catch ex As Exception
End Try
Try
conMPCS2.Close()
Catch ex As Exception
End Try
If conMPCS2.State = 0 Then
conMPCS2.Open(ConnectionStringToORACLE)
End If
rsMPCS_Con.PageSize = iPageSize
rsMPCS_Con.CacheSize = iPageSize
rsMPCS_Con.Open(UCase(LastSavedSTSQL), conMPCS2, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockReadOnly)
If Not rsMPCS_Con.EOF Then
iPageCount = rsMPCS_Con.PageCount
If iPageCurrent > iPageCount Then iPageCurrent = iPageCount
If iPageCurrent < 1 Then iPageCurrent = 1
rsMPCS_Con.AbsolutePage = iPageCurrent
lblpageofpage.Text = "Page: " & iPageCurrent & " of " & iPageCount
With ListView1
.Clear()
.View = View.Details
.FullRowSelect = True
.GridLines = True
.CheckBoxes = False
currentSize = 10
.Font = New Font(.Font.Name, currentSize, .Font.Style, .Font.Unit)
.Columns.Add("Description", 300, HorizontalAlignment.Left)
.Columns.Add("Quan.", 50, HorizontalAlignment.Center)
.Columns.Add("Min. Qty", 70, HorizontalAlignment.Center)
.Columns.Add("Build No.", 65, HorizontalAlignment.Center)
.Columns.Add("Rev.", 60, HorizontalAlignment.Center)
.Columns.Add("Weight/UOM", 110, HorizontalAlignment.Center)
.Columns.Add("Home Location", 110, HorizontalAlignment.Center)
.Columns.Add("Sub Location", 90, HorizontalAlignment.Center)
.Columns.Add("SI_KEY", 0, HorizontalAlignment.Center)
.Columns.Add("Email Alerts", 90, HorizontalAlignment.Center)
End With
iRecordsShown = 0
Do While iRecordsShown < iPageSize And Not rsMPCS_Con.EOF
iRecordsShown = iRecordsShown + 1
arrValues(0) = rsMPCS_Con("description").Value
arrValues(1) = rsMPCS_Con("StockQuan").Value
arrValues(2) = rsMPCS_Con("StockMin").Value
'fixtures
If rsMPCS_Con("BUILD_NO").Value = 0 Then
arrValues(3) = ""
Else
arrValues(3) = rsMPCS_Con("BUILD_NO").Value.ToString
End If
If rsMPCS_Con("BUILD_NO").Value = 0 Then
arrValues(4) = ""
Else
arrValues(4) = rsMPCS_Con("REVISION").Value.ToString
End If
'--------
arrValues(5) = rsMPCS_Con("Weight").Value & " " & rsMPCS_Con("STOCK_UOM").Value
arrValues(6) = rsMPCS_Con("LOCATION").Value
arrValues(7) = rsMPCS_Con("SUB_LOCATION").Value
arrValues(8) = rsMPCS_Con("SI_KEY").Value
If rsMPCS_Con("Email").Value.ToString IsNot "" And rsMPCS_Con("StockMin").Value > 0 Then
arrValues(9) = "Enabled"
Else
arrValues(9) = ""
End If
IT += 1
Dim lsvi As New ListViewItem(arrValues)
For Each row In lsvi.SubItems
If IT / 2 <> Int(IT / 2) Then
row.BackColor = Color.Ivory
Else
row.BackColor = Color.White
End If
Next
ListView1.Items.Add(lsvi)
rsMPCS_Con.MoveNext()
Loop
For i As Integer = ListView1.Items.Count - 1 To 0 Step -1
ListView1.Items(i).UseItemStyleForSubItems = False
Dim rowreadconsume As OleDbDataReader
query = "REDACTED"
Using Conn As New OleDbConnection(ConnectionStringToORACLE)
Using CMD As New OleDbCommand()
With CMD
.Connection = Conn
.CommandType = CommandType.Text
.CommandText = query
.Parameters.AddWithValue("SI_KEY", ListView1.Items(i).SubItems(8).Text)
End With
Conn.Open()
rowreadconsume = CMD.ExecuteReader()
rowreadconsume.Read()
If rowreadconsume("CONSUMABLE") = 1 Then
Dim rowreadquan As OleDbDataReader
query = "REDACTED"
Using Conn2 As New OleDbConnection(ConnectionStringToORACLE)
Using CMD2 As New OleDbCommand()
With CMD2
.Connection = Conn2
.CommandType = CommandType.Text
.CommandText = query
.Parameters.AddWithValue("SI_KEY", ListView1.Items(i).SubItems(8).Text)
.Parameters.AddWithValue("LOCATION", Stockkey)
End With
Conn2.Open()
rowreadquan = CMD2.ExecuteReader()
rowreadquan.Read()
If rowreadquan("QUANTITY_IN_STOCK") <= rowreadquan("LOW_STOCK_QTY") Then
ListView1.Items(i).SubItems(1).ForeColor = Color.Red
Else
ListView1.Items(i).SubItems(1).ForeColor = Color.Black
End If
End Using
End Using
End If
End Using
End Using
Next
rsMPCS_Con.Close()
'ListView1.Sort()
'ListView1.Sorting = SortOrder.Descending
With ListView2
.Clear()
.View = View.Details
.FullRowSelect = True
.GridLines = True
.CheckBoxes = False
currentSize = 8
.Font = New Font(.Font.Name, currentSize, .Font.Style, .Font.Unit)
.Columns.Add("Date/Time", 150, HorizontalAlignment.Left)
.Columns.Add("Employee", 75, HorizontalAlignment.Left)
.Columns.Add("Transaction Amount", 125, HorizontalAlignment.Center)
.Columns.Add("Job Number", 100, HorizontalAlignment.Center)
.Columns.Add("Machine No.", 100, HorizontalAlignment.Center)
.Columns.Add("Department No.", 100, HorizontalAlignment.Center)
.Columns.Add("Comments", 400, HorizontalAlignment.Left)
End With
PanelLoading.Visible = False
ListView1.Select()
Else
ListView1.Items.Clear()
ListView2.Items.Clear()
End If
If rsMPCS_Con.State = 1 Then rsMPCS_Con.Close()
If conMPCS2.State = 1 Then conMPCS2.Close()
cmdNextPage.Enabled = True
cmdNextPageEnd.Enabled = True
cmdPrevPage.Enabled = True
cmdPrevPageEnd.Enabled = True
If iPageCurrent = iPageCount Then
cmdNextPage.Enabled = False
cmdNextPageEnd.Enabled = False
End If
If iPageCurrent = 1 Then
cmdPrevPage.Enabled = False
cmdPrevPageEnd.Enabled = False
End If
CLOSECONNECTION()
Catch ex As Exception
MessageBox.Show(ex.ToString)
If rsMPCS_Con.State = 1 Then rsMPCS_Con.Close()
If conMPCS2.State = 1 Then conMPCS2.Close()
End Try
End Sub
First my code :
Sub festplatte()
Dim allDrives() As DriveInfo = DriveInfo.GetDrives()
Dim d As DriveInfo
Dim I As Integer
For Each d In allDrives
If d.IsReady = True Then
Try
' Intelize controls
Dim progressbar As ProgressBar = New ProgressBar
Dim pbgroup As GroupBox = New GroupBox
Dim info As Label = New Label
Dim type As Label = New Label
Dim format As Label = New Label
Dim Space As Double = d.TotalFreeSpace / d.TotalSize
' Add to tab
Me.Tab_M.Controls.Add(progressbar)
Me.Tab_M.Controls.Add(pbgroup)
Me.Tab_M.Controls.Add(info)
Me.Tab_M.Controls.Add(type)
Me.Tab_M.Controls.Add(format)
' Add to group
pbgroup.Controls.Add(progressbar)
pbgroup.Controls.Add(info)
pbgroup.Controls.Add(type)
pbgroup.Controls.Add(format)
pbgroup.Text = d.Name & " | Name : " & CheckName(d.VolumeLabel.ToString())
pbgroup.Size = New System.Drawing.Size(600, 65)
pbgroup.Location = New System.Drawing.Point(8, I * 70 + 40)
' format
format.AutoSize = True
format.Name = "format" & I
format.Location = New System.Drawing.Point(435, 36)
format.Text = "Format : " & d.DriveFormat
' Typ
type.AutoSize = True
type.Name = "type" & I
type.Location = New System.Drawing.Point(435, 16)
type.Text = "Art : " & GetDriverFormat(d)
' info
info.Name = "info" & I
info.Location = New System.Drawing.Point(6, 16)
info.AutoSize = True
' Info Text :: 1000 MB Grenze
If d.TotalFreeSpace > Math.Pow(1024, 3) Then
info.Text = "Benutzter Speicher beträgt : " & Math.Round((d.TotalSize - d.TotalFreeSpace) / btogb, 2) & " GB von " & Math.Round((d.TotalSize) / btogb, 2) & " GB (" & Math.Round(100 - Space * 100, 2) & " % )"
Else
info.Text = "Benutzter Speicher beträgt : " & Math.Round((d.TotalSize - d.TotalFreeSpace) / btomb, 2) & " MB von " & Math.Round((d.TotalSize) / btomb, 2) & " MB (" & Math.Round(100 - Space * 100, 2) & " % )"
End If
'Progressbar
progressbar.Size = New System.Drawing.Size(425, 23)
progressbar.Location = New System.Drawing.Point(6, 32)
progressbar.Name = "Memory" & I
progressbar.Value = 100 - Space * 100
Catch ex As Exception
MsgBox(ex.ToString())
End Try
I += 1
End If
Next
End Sub
The code does generate a groupbox with each a progressbar in it and 3 labels, where i would like to edit something.
How can I edit the text of for example a label ? And how could I add / remove generated elements from the form ? I tried with refresh but it doesnt work
The Form
This was something quick I tried:
Dim LabelList As New List(Of Integer)
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim LBL As New Label
LBL.Location = New Point(6, 23)
LBL.AutoSize = True
Me.Controls.Add(LBL)
LabelList.Add(Me.Controls.Count - 1)
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Me.Controls(LabelList(0)).Text = "HELLO WORLD!"
End Sub
This will add a label to the form and then add it's control index to LabelList. LabelList(0) will get the index for the first added label.
I am printing records from an ODBC connection but I am not able to print more than the first page. The code I have below generates multiple copies of the same first page. How can I iterate through my records and still create page breaks when necessary?
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
'MsgBox("Printing functionality is still under construction.", MsgBoxStyle.Information)
Dim RecordDoc As Drawing.Printing.PrintDocument
RecordDoc = New Drawing.Printing.PrintDocument
With RecordDoc.DefaultPageSettings
.Landscape = False
.Margins.Left = 50
.Margins.Right = 50
.Margins.Top = 50
.Margins.Bottom = 50
End With
RecordDoc.DocumentName = "Print Records"
AddHandler RecordDoc.PrintPage, AddressOf Me.printrecords
dlgPreview.Document = RecordDoc
dlgPreview.ShowDialog()
RecordDoc.Dispose()
End Sub
Private Sub PrintRecords(ByVal sender As Object, ByVal e As Drawing.Printing.PrintPageEventArgs)
Dim lvi As ListViewItem
Dim Conn As OdbcConnection
Dim Reader As OdbcDataReader
Dim strFname As String = ""
Dim strLname As String = ""
Dim strReportHdr As String = ""
Dim strMainCategory As String = ""
Dim strColumnHeader As String = ""
Dim intLinesPerPage As Integer = 0
Dim x, y As Single
Dim myfont As Font = New Font("Arial", 12, FontStyle.Regular)
Dim myPen As New Pen(Color.Black, 3)
'DEFINE THE REPORT HEADER BASED ON LISTVIEW SELECTIONS
'FIRST, GET THE COLUMN NUMBER SELECTED. YOU'LL USE THIS FOR THE REPORT HEADER AS WELL AS WHEN PRINTING DATA
Dim PrintColHeader As ColumnHeader = ListView1.Columns(intLViewColSort)
'REMOVE THE < OR > AS NECESSARY, IF PRESENT
If PrintColHeader.Text.StartsWith("> ") Then
strColumnHeader = Mid(PrintColHeader.Text, 3) & ", in descending order"
ElseIf PrintColHeader.Text.StartsWith("< ") Then
strColumnHeader = Mid(PrintColHeader.Text, 3) & ", in ascending order"
End If
If rdoCustInfo.Checked = True Then
strMainCategory = "Customer Information"
ElseIf rdoCustVendPrefs.Checked = True Then
strMainCategory = "Customer Vendor Preferences"
ElseIf rdoPricePts.Checked = True Then
strMainCategory = "Customer Price Points"
ElseIf rdoSalesHist.Checked = True Then
strMainCategory = "Customer Sales History"
ElseIf rdoSpecific.Checked = True Then
strMainCategory = "Other"
Else
MsgBox("System error with print function. Have a glass of wine.", MsgBoxStyle.Critical)
Exit Sub
End If
y = e.MarginBounds.Y
x = e.MarginBounds.X
e.Graphics.DrawRectangle(myPen, e.MarginBounds.X, e.MarginBounds.Y + 20, 500, 1)
e.Graphics.DrawString(strMainCategory & " - " & strColumnHeader, myfont, Brushes.Black, x, y)
y += CInt(2 * myfont.GetHeight(e.Graphics))
myfont = New Font("Arial", 10, FontStyle.Regular)
intLinesPerPage = e.MarginBounds.Height / myfont.GetHeight(e.Graphics)
'Open Connection TO ASC
Conn = New OdbcConnection(ConnString)
Conn.Open()
For Each lvi In ListView1.Items
'Execute Query
cmdString = "select lastname,firstname,street1,street2,city,state,zipcode,phonenum,emailaddress from customer where customernum=" & lvi.Text
Dim Cmd As New OdbcCommand(cmdString, Conn)
Reader = Cmd.ExecuteReader()
'Process The Result Set
While (Reader.Read())
Dim tempy As Integer
tempy = y
Dim CustName As String = Trim(Reader("firstname")) & " " & Trim(Reader("lastname"))
CustName = StrConv(CustName, VbStrConv.ProperCase)
e.Graphics.DrawString(CustName, myfont, Brushes.Black, e.MarginBounds.X, y)
y += CInt(myfont.GetHeight(e.Graphics))
Dim street As String = ""
If Trim(Reader("street2").ToString) <> "" And Not (IsDBNull(Reader("street2"))) Then
street += Trim(Reader("street1").ToString) & vbCrLf & Trim(Reader("street2"))
Else
street += Trim(Reader("street1").ToString)
End If
street = StrConv(street, VbStrConv.ProperCase)
e.Graphics.DrawString(street, myfont, Brushes.Black, e.MarginBounds.X, y)
y += CInt(myfont.GetHeight(e.Graphics))
Dim CityStateZip As String = ""
CityStateZip = StrConv(Trim(Reader("city")), VbStrConv.ProperCase) & ", " & Trim(Reader("state")) & ", " & Reader("zipcode")
e.Graphics.DrawString(CityStateZip, myfont, Brushes.Black, e.MarginBounds.X, y)
x += 200
e.Graphics.DrawString(Trim(Reader("phonenum")), myfont, Brushes.Black, x, tempy)
tempy += CInt(myfont.GetHeight(e.Graphics))
y += CInt(2 * myfont.GetHeight(e.Graphics))
e.Graphics.DrawString(Trim(Reader("emailaddress")), myfont, Brushes.Black, x, tempy)
x = e.MarginBounds.X
'If intPrintLineCount1 > intLinesPerPage Then
' e.HasMorePages = True
' intPrintLineCount1 = 0
'Else
' e.HasMorePages = False
'End If
If y + myfont.Height > e.MarginBounds.Bottom Then
e.HasMorePages = True
End If
'intPrintLineCount1 += 10
End While
Cmd.Dispose()
Next
Reader.Close()
Conn.Close()
Conn.Dispose()
End Sub