TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Naidu AMMAN
NA
37
35.2k
how to show error message for button click as given code blw
Oct 10 2014 3:03 AM
when i click the generate button some data showing and after i am saving the data by using button2 click event and it is running successfully. But i want
without data while click on button2 click event before Generate button how to show the error message for this.Please send this as soon as possible.
Imports System.IO
Imports System.Data
Imports System.Reflection
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Public Class frmVechilewiseReports
Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
Dim strsql As String = ""
''If rdbBetweenDates.Checked = True Then
'' If Date > DTto.Value.Date Then
'' MsgBox("From date should not be greater than To Date Please Change To Date", MsgBoxStyle.Critical, "Dates")
'' Exit Sub
'' ElseIf DTto.Value.Date.Subtract.Days > 31 Then
'' MsgBox("Duration between Dates Should not be greater than 31 days", MsgBoxStyle.Critical, "Dates")
'' Exit Sub
'' End If
''End If
''strsql = "select VehicleNumber,VehicleType,format(INDATE,'dd/MM/yyyy') as VehicleINDATE,format(INDATE,'HH:mm:ss') as VehicleINTIME,InSlip,OutSlip,DeviceID,Amount,SupervisorID,Fromtime,Totime,ExtraAmountperHour,Billtype,SupervisorName,ShiftNo from tblcollection where VehicleType='" & cmbvehicletype.Text & "'" ''where INDATE>=#" & DtFrom.Value.Date & "# and INDATE<=#" & DTto.Value.Date & "#"
strsql = "SELECT tblCollection.Amount, tblCollection.VehicleNumber, tblCollection.VehicleType, format(INDATE,'dd/MM/yyyy') AS VehicleINDATE, format(INDATE,'HH:mm:ss') AS VehicleINTIME, tblCollection.DeviceID, tblCollection.SupervisorID, tblCollection.Fromtime, tblCollection.Totime, tblCollection.Billtype, tblCollection.SupervisorName, tblCollection.ShiftNo, tblCollection.ExtraAmountperHour FROM tblCollection WHERE tblCollection.INDATE Between #" & DtFrom.Value.Date.ToString("MM/dd/yyyy 06:00:00") & "# And #" & DTto.Value.Date.ToString("MM/dd/yyyy 05:59:59") & "# AND VehicleType='" & cmbvehicletype.Text & "'"
Dim m_ds As New DataSet
Dim m_db As New CDataAccess
m_ds = m_db.getdata(strsql, strconnection)
If Not m_ds Is Nothing Then
DataGridView1.DataSource = m_ds.Tables(0)
Else
MsgBox("No Records found", MsgBoxStyle.Information)
End If
End Sub
Private Sub loaddata()
Dim strsql As String = ""
Dim m_ds As DataSet
Dim m_db As New CDataAccess
strsql = "select VehicleNumber,format(INDATE,'dd/MM/yyyy') as VehicleINDATE,format(INDATE,'HH:mm:ss') as VehicleINTIME,DeviceID,Amount,SupervisorID,Fromtime,Totime,ExtraAmountperHour,Billtype,SupervisorName,ShiftNo from tblcollection"
m_ds = m_db.getdata(strsql, strconnection)
If Not m_ds Is Nothing Then
DataGridView1.DataSource = m_ds.Tables(0).DefaultView
DataGridView1.AutoResizeColumns()
DataGridView1.ReadOnly = True
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
''Dim m_excel As String = ""
''If SfdlgDownload.ShowDialog() = Windows.Forms.DialogResult.OK Then
'' ExportDataToExcel(SfdlgDownload.FileName, DataGridView1)
''End If
SaveFileDialog1.ShowDialog()
If Not (txtbrowse.Text.Contains("pdf")) Then
txtbrowse.Text = SaveFileDialog1.FileName() + ".pdf"
End If
Dim pdfTable As New PdfPTable(DataGridView1.ColumnCount)
pdfTable.DefaultCell.Padding = 10 '3
pdfTable.WidthPercentage = 90 '30
pdfTable.HorizontalAlignment = Element.ALIGN_LEFT
pdfTable.DefaultCell.BorderWidth = 1
'Adding Header row
For Each column As DataGridViewColumn In DataGridView1.Columns
Dim cell As New PdfPCell(New Phrase(column.HeaderText))
cell.BackgroundColor = New iTextSharp.text.BaseColor(240, 240, 240)
pdfTable.AddCell(cell)
Next
'Adding DataRow
For Each row As DataGridViewRow In DataGridView1.Rows
For Each cell As DataGridViewCell In row.Cells
pdfTable.AddCell(cell.Value.ToString())
Next
Next
'Exporting to PDF
Dim folderPath As String = txtbrowse.Text
If Not Directory.Exists(folderPath) Then
Directory.CreateDirectory(folderPath)
End If
'Dim pdfFilename As String = "dbtopdf.pdf"
' '' pdfFilename.Save(pdfFilename)
'Process.Start(pdfFilename)
Using stream As New FileStream(folderPath & "DataGridViewExport.pdf ", FileMode.Create)
Dim pdfDoc As New Document(PageSize.A4, 14.0F, 14.0F, 14.0F, 0.0F)
PdfWriter.GetInstance(pdfDoc, stream)
pdfDoc.Open()
pdfDoc.Add(pdfTable)
pdfDoc.Close()
stream.Close()
End Using
End Sub
Public Sub ExportDataToExcel(ByVal FilePath As String, ByVal DataGrid As DataGridView)
Dim _mFileStream As New IO.StreamWriter(FilePath, False)
Try
_mFileStream.WriteLine("<?xml version=""1.0""?>")
_mFileStream.WriteLine("<?mso-application progid=""Excel.Sheet""?>")
_mFileStream.WriteLine("<ss:Workbook xmlns:ss=""urn:schemas-microsoft-com:office:spreadsheet"">")
_mFileStream.WriteLine(" <ss:Styles>")
_mFileStream.WriteLine(" <ss:Style ss:ID=""1"">")
_mFileStream.WriteLine(" <ss:Font ss:Bold=""1""/>")
_mFileStream.WriteLine(" <ss:FontName=""Courier New""/>")
_mFileStream.WriteLine(" </ss:Style>")
_mFileStream.WriteLine(" </ss:Styles>")
_mFileStream.WriteLine(" <ss:Worksheet ss:Name=""Sheet1"">")
_mFileStream.WriteLine(" <ss:Table>")
For x As Integer = 0 To DataGrid.Columns.Count - 1
_mFileStream.WriteLine(" <ss:Column ss:Width=""{0}""/>", DataGrid.Columns.Item(x).Width)
Next
_mFileStream.WriteLine(" <ss:Row ss:StyleID=""1"">")
For i As Integer = 0 To DataGrid.Columns.Count - 1
_mFileStream.WriteLine(" <ss:Cell>")
_mFileStream.WriteLine(String.Format(" <ss:Data ss:Type=""String"">{0}</ss:Data>", DataGrid.Columns.Item(i).HeaderText))
_mFileStream.WriteLine("</ss:Cell>")
Next
_mFileStream.WriteLine(" </ss:Row>")
For intRow As Integer = 0 To DataGrid.RowCount - 2
_mFileStream.WriteLine(String.Format(" <ss:Row ss:Height =""{0}"">", DataGrid.Rows(intRow).Height))
For intCol As Integer = 0 To DataGrid.Columns.Count - 1
_mFileStream.WriteLine(" <ss:Cell>")
_mFileStream.WriteLine(String.Format(" <ss:Data ss:Type=""String"">{0}</ss:Data>", DataGrid.Item(intCol, intRow).Value.ToString))
_mFileStream.WriteLine(" </ss:Cell>")
Next
_mFileStream.WriteLine(" </ss:Row>")
Next
_mFileStream.WriteLine(" </ss:Table>")
_mFileStream.WriteLine(" </ss:Worksheet>")
_mFileStream.WriteLine("</ss:Workbook>")
_mFileStream.Close()
_mFileStream.Dispose()
_mFileStream = Nothing
Catch ex As Exception
_mFileStream.Close()
_mFileStream.Dispose()
_mFileStream = Nothing
MessageBox.Show("Error While Exporting Data To Excel. Error : " & ex.Message)
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub frmVechilewiseReports_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim m_passtypes As New frmVechilewiseReports
If DataGridView1.SelectedRows.Count > 0 Then
m_passtypes.txtAmount.Text = DataGridView1.SelectedRows(0).Cells(0).Value.ToString()
''m_passtypes.txtVehicleType.Text = DataGridView1.SelectedRows(0).Cells(2).Value.ToString()
m_passtypes.txtVehicleNumber.Text = DataGridView1.SelectedRows(0).Cells(1).Value.ToString()
m_passtypes.txtINDATE.Text = DataGridView1.SelectedRows(0).Cells(3).Value.ToString()
''m_passtypes.txtInslip.Text = DataGridView1.SelectedRows(0).Cells(5).Value.ToString()
''m_passtypes.txtoutslip.Text = DataGridView1.SelectedRows(0).Cells(6).Value.ToString()
m_passtypes.txtDevice.Text = DataGridView1.SelectedRows(0).Cells(5).Value.ToString()
m_passtypes.txtsupervisorId.Text = DataGridView1.SelectedRows(0).Cells(6).Value.ToString()
m_passtypes.Txtfromtime.Text = DataGridView1.SelectedRows(0).Cells(7).Value.ToString()
m_passtypes.txttotime.Text = DataGridView1.SelectedRows(0).Cells(8).Value.ToString()
m_passtypes.txtBillType.Text = DataGridView1.SelectedRows(0).Cells(9).Value.ToString()
m_passtypes.txtsupervisorName.Text = DataGridView1.SelectedRows(0).Cells(10).Value.ToString()
m_passtypes.txtShiftno.Text = DataGridView1.SelectedRows(0).Cells(11).Value.ToString()
m_passtypes.txtExtraamountperh.Text = DataGridView1.SelectedRows(0).Cells(12).Value.ToString()
End If
Dim m_db As New CDataAccess
Dim m_ds As New DataSet, strqry As String = ""
Dim i As Integer
strqry = "SELECT DISTINCT VehicleType FROM tblcollection "
m_ds = m_db.getdata(strqry, strconnection)
If Not m_ds Is Nothing Then
If m_ds.Tables(0).Rows.Count > 0 Then
For i = 0 To m_ds.Tables(0).Rows.Count - 1
cmbvehicletype.Items.Add(m_ds.Tables(0).Rows(i)(0))
Next i
End If
m_ds.Dispose()
End If
End Sub
Private Sub DataGridView1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
If DataGridView1.SelectedRows.Count > 0 Then
txtAmount.Text = DataGridView1.SelectedRows(0).Cells(0).Value.ToString()
''m_passtypes.txtVehicleType.Text = DataGridView1.SelectedRows(0).Cells(2).Value.ToString()
txtVehicleNumber.Text = DataGridView1.SelectedRows(0).Cells(1).Value.ToString()
txtINDATE.Text = DataGridView1.SelectedRows(0).Cells(3).Value.ToString()
''txtInslip.Text = DataGridView1.SelectedRows(0).Cells(5).Value.ToString()
''txtoutslip.Text = DataGridView1.SelectedRows(0).Cells(6).Value.ToString()
txtDevice.Text = DataGridView1.SelectedRows(0).Cells(5).Value.ToString()
txtsupervisorId.Text = DataGridView1.SelectedRows(0).Cells(6).Value.ToString()
Txtfromtime.Text = DataGridView1.SelectedRows(0).Cells(7).Value.ToString()
txttotime.Text = DataGridView1.SelectedRows(0).Cells(8).Value.ToString()
txtBillType.Text = DataGridView1.SelectedRows(0).Cells(9).Value.ToString()
txtsupervisorName.Text = DataGridView1.SelectedRows(0).Cells(10).Value.ToString()
txtShiftno.Text = DataGridView1.SelectedRows(0).Cells(11).Value.ToString()
txtExtraamountperh.Text = DataGridView1.SelectedRows(0).Cells(12).Value.ToString()
End If
''If DataGridView1.SelectedRows.Count > 0 Then
'' txtAgentname.Text = DataGridView1.SelectedRows(0).Cells(9).Value.ToString()
'' txtAgentcode.Text = DataGridView1.SelectedRows(0).Cells(8).Value.ToString()
'' txtPolicyno.Text = DataGridView1.SelectedRows(0).Cells(1).Value.ToString()
'' txtPaymentDate.Text = DataGridView1.SelectedRows(0).Cells(2).Value.ToString()
'' txtPaymentTime.Text = DataGridView1.SelectedRows(0).Cells(3).Value.ToString()
'' txtCheqno.Text = DataGridView1.SelectedRows(0).Cells(11).Value.ToString()
'' txtCheqDate.Text = DataGridView1.SelectedRows(0).Cells(12).Value.ToString()
'' txtCheqMicr.Text = DataGridView1.SelectedRows(0).Cells(13).Value.ToString()
'' txtChaeqamount.Text = DataGridView1.SelectedRows(0).Cells(14).Value.ToString()
'' txtPremiumpaid.Text = DataGridView1.SelectedRows(0).Cells(5).Value.ToString()
'' txtPremiumbalance.Text = DataGridView1.SelectedRows(0).Cells(6).Value.ToString()
'' txtDeviceId.Text = DataGridView1.SelectedRows(0).Cells(7).Value.ToString()
''End If
End Sub
Private Sub DataGridView1_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
Dim specialCellStyle As New DataGridViewCellStyle
specialCellStyle.BackColor = Color.Snow
specialCellStyle.ForeColor = Color.Black
Dim regularCellStyle As New DataGridViewCellStyle
regularCellStyle.BackColor = Color.AliceBlue
regularCellStyle.ForeColor = Color.Black
If e.RowIndex Mod 2 = 0 Then
DataGridView1.Rows(e.RowIndex).DefaultCellStyle = specialCellStyle
Else
DataGridView1.Rows(e.RowIndex).DefaultCellStyle = regularCellStyle
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Left -= 10
If Label1.Left <= -Width Then
Label1.Left = Width
End If
End Sub
End Class
With Regards
sumanth
Reply
Answers (
1
)
c# window application deployment
How to traspose the sparse Matrix in C++?