how to use componentone c1printdocument in asp.net for reading text file and convert into pdf with format? - pdf

I am using the C1PrintDocument class to read a text file and convert into pdf in web. Actually it converts into pdf but without the format as like in text file.
For eg. I have a text file which has only one page. But it makes into two pages while convert into pdf. Below is the code what I use.
Imports System.IO
Imports C1.C1Preview
Imports C1.C1Pdf
Imports C1.Web.Wijmo.Controls.C1ReportViewer
Imports System.Runtime.Serialization.Formatters.Binary
Imports C1.C1Pdf.PdfDocumentInfo
Imports C1.C1Preview.C1PrintDocument
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Try
Dim strmappath As String = System.Web.HttpContext.Current.Server.MapPath("~")
Dim filename As String
filename = Path.Combine(Server.MapPath("~"), "12214.txt")
Dim sr As New System.IO.StreamReader(filename, System.Text.Encoding.UTF8)
Dim str As [String] = sr.ReadToEnd()
Dim doc1 As C1PrintDocument = C1ReportViewer.CreateC1PrintDocument()
Dim doc As New C1PrintDocument
doc.Pages(1).PageSettings.TopMargin = 0
doc.Pages(1).PageSettings.LeftMargin = 0
doc.Pages(1).PageSettings.RightMargin = 0
doc.StartDoc()
Dim overlay As New RenderArea()
overlay.Width = "100%"
overlay.Height = "100%"
overlay.Style.Borders.All = LineDef.Default
doc.PageLayout.Overlay = overlay
Dim lines As String() = System.IO.File.ReadAllLines(filename)
Dim linecnt As Integer = System.IO.File.ReadLines(filename).Count
Dim strpages1 As String()
ReDim strpages1(Math.Abs(linecnt / 66) - 1)
Dim intcnt As Integer
Dim intlinereadcnt As Integer
intlinereadcnt = 0
intcnt = 0
intlinereadcnt = 0
For Each line In lines
If intcnt <= 66 Then
If intcnt <> 66 Then
strpages1(intlinereadcnt) = strpages1(intlinereadcnt) &
line & vbCrLf
End If
intcnt = intcnt + 1
ElseIf intcnt = 67 Then
intlinereadcnt = intlinereadcnt + 1
intcnt = 0
End If
Next
Dim strPages As String() = str.Split(Chr(12))
Dim strPage As String = String.Empty
Dim txtPage As New C1.C1Preview.RenderText(doc)
With doc
.AllowNonReflowableDocs = True
For Each strPage In strpages1
If strPage.Length > 0 Then
txtPage.Text = strPage
txtPage.X = 150
doc.Style.TextColor = Drawing.Color.Blue
.RenderBlockText(txtPage.Text)
.Style.WordWrapMode = False
.NewPage()
End If
Next
End With
Dim m_pdfExporter As C1.C1Preview.Export.PdfExporter
m_pdfExporter = C1.C1Preview.Export.ExportProviders.
PdfExportProvider.NewExporter()
m_pdfExporter.Document = doc
m_pdfExporter.Export(Server.MapPath("~") & "12214" & ".pdf")
Dim sr2 As System.IO.MemoryStream
sr2 = New MemoryStream
doc.Save(sr2)
Dim biteArray As Byte() = New Byte(sr2.Length - 1) {}
sr2.Position = 0
sr2.Read(biteArray, 0, CInt(sr2.Length))
'm_pdfExporter.Export(Path.GetTempPath & "\" & "12214" & ".pdf")
Response.Clear()
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/pdf"
'Response.BinaryWrite(biteArray)
Response.AddHeader("Content-Disposition", "attachment;filename=" & "12214" & ".pdf")
Response.BinaryWrite(System.IO.File.ReadAllBytes(Server.MapPath("~") & "12214" & ".pdf"))
Catch ex As Exception
End Try
End Sub

Try using c1PrintDocument1.Export("filename.pdf", true) instead.
Thanks,
Richa

Related

vb.net readalllines fill form replace certain lines coding advice

What I'm trying to accomplish is reading a text file and selecting certain lines to modify by filling in text from a second form. Here is an example the code I'm currently using. What's happening is I'm looking for a line that starts with 718 and then somewhere after that line there will be a line that starts with 720. I need both lines to fill in the second form. The only way I can think of is to just keep adding 1 to the line until it reaches the line I need. I'm still new to this and I'm sure there's an easier way to do this maybe using Try or While but I'm not sure how. Appreciate any help.
Dim lines() As String = File.ReadAllLines(tempsave)
For i As Integer = 0 To lines.Length - 1
If lines(i).StartsWith("718") Then
If lines(i + 1).StartsWith("720") Then
Dim array() As String = lines(i).Split("*"c, "~"c)
Dim array2() As String = lines(i + 1).Split("*"c, "~"c)
FormFill.TextBox1.Text = array(3)
FormFill.TextBox2.Text = array(9)
FormFill.ShowDialog()
lines(i) = lines(i).Replace(array(3), FormFill.TextBox1.Text)
lines(i + 1) = lines(i + 1).Replace(array(9), FormFill.TextBox2.Text)
Else
If lines(i + 2).StartsWith("720") Then
Dim array() As String = lines(i).Split("*"c, "~"c)
Dim array2() As String = lines(i + 2).Split("*"c, "~"c)
FormFill.TextBox1.Text = array(3)
FormFill.TextBox2.Text = array(9)
FormFill.ShowDialog()
lines(i) = lines(i).Replace(array2(3),FormFill.TextBox1.Text)
lines(i + 2) = lines(i + 2).Replace(array(9), FormFill.TextBox2.Text)
End If
End If
End If
Next
Example Data:
Input:
123*test*test*test~
718*test*test*test~
543*test*test*test~
720*test*test*test~
Output:
123*test*test*test~
718*test*test*newdata~
543*test*test*test~
720*test*test*newdata~
Here, try this:
Public Sub Lines()
Dim _
aNextLines,
aAllLines As String()
Dim _
s718Line,
s720Line As String
aAllLines = IO.File.ReadAllLines("D:\Logs\Data.log")
For i As Integer = 0 To aAllLines.Length - 1
If aAllLines(i).StartsWith("718") Then
s718Line = aAllLines(i)
aNextLines = aAllLines.Skip(i + 1).ToArray
s720Line = aNextLines.FirstOrDefault(Function(Line) Line.StartsWith("720"))
' Process data here
End If
Next
End Sub
--UPDATE--
Here's a modified version that both reads and writes:
Public Sub Lines()
Dim oForm As FormFill
Dim _
aNextLines,
aAllLines As String()
Dim _
i718Index,
i720Index As Integer
Dim _
s718Line,
s720Line As String
oForm = New FormFill
aAllLines = IO.File.ReadAllLines(oForm.FilePath)
s718Line = String.Empty
s720Line = String.Empty
For i718Index = 0 To aAllLines.Length - 1
If aAllLines(i718Index).StartsWith("718") Then
s718Line = aAllLines(i718Index)
aNextLines = aAllLines.Skip(i718Index + 1).ToArray
For i720Index = 0 To aNextLines.Length - 1
If aNextLines(i720Index).StartsWith("720") Then
s720Line = aNextLines(i720Index)
Exit For ' Assumes only one 720 line in the file
End If
Next
Exit For ' Assumes only one 718 line in the file
End If
Next
oForm.TextBox718.Text = s718Line
oForm.TextBox720.Text = s720Line
oForm.TextBox718.Tag = i718Index
oForm.TextBox720.Tag = i720Index
End Sub
Now, in your Save button's Click event handler:
Private Sub SaveButton_Click(Sender As Button, e As EventArgs) Handles SaveButton.Click
Dim aAllLines As String()
Dim _
i718Index,
i720Index As Integer
Dim _
s718Line,
s720Line As String
s718Line = Me.TextBox718.Text
s720Line = Me.TextBox720.Text
i718Index = Me.TextBox718.Tag
i720Index = Me.TextBox720.Tag
aAllLines = IO.File.ReadAllLines(Me.FilePath)
aAllLines(i718Index) = s718Line
aAllLines(i720Index) = s720Line
IO.File.WriteAllLines(Me.FilePath, aAllLines)
End Sub
That should do it.

VB.Net signedXml "Invalid character in a Base-64 string"

I'm getting an error everytime I try to upload a XML file to an specific server.
It returns "Invalid character in a Base-64 string". Here the code I'm using to sign:
Public Sub Assinar03(ByVal strArqXMLAssinar As String, ByVal strUri As String, ByVal x509Certificado As X509Certificate2, ByVal strArqXMLAssinado As String)
Dim SR As StreamReader = Nothing
SR = File.OpenText(strArqXMLAssinar)
Dim vXMLString As String = SR.ReadToEnd()
SR.Close()
Dim _xnome As String = String.Empty
Dim _serial As String = String.Empty
If x509Certificado IsNot Nothing Then
_xnome = x509Certificado.Subject.ToString()
_serial = x509Certificado.SerialNumber
End If
Dim _X509Cert As New X509Certificate2()
Dim store As New X509Store("MY", StoreLocation.CurrentUser)
store.Open(OpenFlags.[ReadOnly] Or OpenFlags.OpenExistingOnly)
Dim collection As X509Certificate2Collection = DirectCast(store.Certificates, X509Certificate2Collection)
Dim collection1 As X509Certificate2Collection = DirectCast(collection.Find(X509FindType.FindBySerialNumber, _serial, False), X509Certificate2Collection)
If collection1.Count > 0 Then
_X509Cert = Nothing
For i As Integer = 0 To collection1.Count - 1
If DateTime.Now < collection1(i).NotAfter OrElse Not _X509Cert Is Nothing AndAlso _X509Cert.NotAfter < collection1(i).NotAfter Then
_X509Cert = collection1(i)
End If
Next
If _X509Cert Is Nothing Then _X509Cert = collection1(0)
Dim doc As New XmlDocument()
doc.PreserveWhitespace = False
doc.LoadXml(vXMLString)
Dim qtdeRefUri As Integer = doc.GetElementsByTagName(strUri).Count
Dim reference As New Reference()
Dim keyInfo As New KeyInfo()
Dim signedXml As New SignedXml(doc)
signedXml.SigningKey = _X509Cert.PrivateKey
Dim _Uri As XmlAttributeCollection = doc.GetElementsByTagName(strUri).Item(0).Attributes
For Each _atributo As XmlAttribute In _Uri
If _atributo.Name.ToLower.Trim = "Id".ToLower.Trim Then
reference.Uri = "#" + _atributo.InnerText
End If
Next
If reference.Uri Is Nothing Then reference.Uri = ""
reference.DigestMethod = SignedXml.XmlDsigSHA1Url
'--------------------------------------------------
Dim env As New XmlDsigEnvelopedSignatureTransform()
env.Algorithm = "http://www.w3.org/2000/09/xmldsig#enveloped-signature"
reference.AddTransform(env)
'--------------------------
Dim c14 As New XmlDsigC14NTransform(False)
c14.Algorithm = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
reference.AddTransform(c14)
'--------------------------
signedXml.AddReference(reference)
keyInfo.AddClause(New KeyInfoX509Data(_X509Cert))
'--------------------------
signedXml.KeyInfo = keyInfo
signedXml.ComputeSignature()
'--
Dim xmlDigitalSignature As XmlElement = signedXml.GetXml()
doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, True))
XMLDoc = New XmlDocument()
XMLDoc.PreserveWhitespace = False
XMLDoc = doc
Me.vXMLStringAssinado = XMLDoc.OuterXml
'-----------
Dim SW_2 As StreamWriter = File.CreateText(strArqXMLAssinado)
SW_2.Write(Me.vXMLStringAssinado)
SW_2.Close()
'-----------
End If
SR.Close()
End Sub
Is there something else I should add to the code?
The manual tells me to follow the instructions from https://www.w3.org/TR/xmldsig-core/
Turns out it was a line break when saving the document. I set the .PreserveWhitespace property to true before saving the .xml file and not it seems to be working.

How to Calculate estimated time remaining in downloading Using Xceed.Ftp.FtpClient() in VB.net?

I am downloading FTP files using Xceed.Ftp.FtpClient() how can i calculated the estimated remaining Time?
Dim HostName As String = (New Uri(RemoteFilePath).Host).ToString()
Dim RemoteFolderName As String = System.IO.Path.GetFileName((New Uri(RemoteFilePath).LocalPath).ToString())
Dim RemoteFileName As String = System.IO.Path.GetFileName((New Uri(RemoteFilePath).LocalPath).ToString())
Dim LocalFileName As String = System.IO.Path.GetFileName((New Uri(LocalFilePath).LocalPath).ToString())
Dim Ftp As New Xceed.Ftp.FtpClient()
Dim AuthMethod As AuthenticationMethod = AuthenticationMethod.Tls
Dim VeriFlag As VerificationFlags = VerificationFlags.None
Dim Cert As Certificate = Nothing
Ftp.Connect(HostName, 990, AuthMethod, VeriFlag, Cert)
'Console.WriteLine("Connected")
Ftp.Login(username, pass)
Dim s As String = Ftp.GetCurrentFolder()
'Console.WriteLine("LogedIn")
Ftp.ChangeCurrentFolder("WindowsPatches/" & RemoteFolderName)
'Console.WriteLine("Remote Folder Name:" & RemoteFolderName)
'Ftp.ChangeCurrentFolder(RemoteFolderName)
Dim files = Ftp.GetFolderContents()
If files IsNot Nothing AndAlso files.Count >= 0 Then
For index = 0 To files.Count - 1
If files.Item(index).Type = FtpItemType.File Then
RemoteFileName = files.Item(index).Name
LocalFileName = RemoteFileName
If Not Directory.Exists(RemoteFolderName) Then
Directory.CreateDirectory(RemoteFolderName)
End If
LocalFileName = RemoteFolderName & "\" & LocalFileName
If Not String.IsNullOrEmpty(LocalFilePath) AndAlso System.IO.File.Exists(LocalFilePath) Then
System.IO.File.Delete(LocalFilePath)
End If
'Console.WriteLine("Downloading started...")
Ftp.ReceiveFile(RemoteFileName, LocalFileName)
'Console.WriteLine("Downloading Complete")
'Console.WriteLine("Working Path" & Directory.GetCurrentDirectory())
Dim psi As New ProcessStartInfo()
Directory.SetCurrentDirectory(LocalFilePath & RemoteFolderName)
'Console.WriteLine("Local Directory Name: " & LocalFilePath & RemoteFolderName)
psi.CreateNoWindow = True
psi.FileName = RemoteFileName
psi.UseShellExecute = True
Dim myProcess As Process = Process.Start(psi)
Console.WriteLine("Update process started...")
'Exit For
End If
Next
'LocalFileName = RemoteFileName
End If
I am using this code, any suggestion please?

system.io.ioexception the process cannot access because it is being used by another process

i am getting this problem in some systems, some systems working properly, here my code is,
Dim fileName As String = "FaultTypesByMonth.csv"
Using writer As IO.StreamWriter = New IO.StreamWriter(fileName, True, System.Text.Encoding.Default) '------------ rao new ----
Dim Str As String
Dim i As Integer
Dim j As Integer
Dim headertext1(rsTerms.Columns.Count) As String
Dim k As Integer = 0
Dim arrcols As String = Nothing
For Each column As DataColumn In TempTab.Columns
arrcols += column.ColumnName.ToString() + ","c
k += 1
Next
writer.WriteLine(arrcols)
For i = 0 To (TempTab.Rows.Count - 1)
For j = 0 To (TempTab.Columns.Count - 1)
If j = (TempTab.Columns.Count - 1) Then
Str = (TempTab.Rows(i)(j).ToString)
Else
Str = (TempTab.Rows(i)(j).ToString & ",")
End If
writer.Write(Str)
Next
writer.WriteLine()
Next
writer.Close()
writer.Dispose()
End Using
Dim FileToDelete As String = Nothing
Dim sd As New SaveFileDialog
sd.Filter = "CSV Files (*.csv)|*.csv"
sd.FileName = "FaultTypesByMonth"
If sd.ShowDialog = Windows.Forms.DialogResult.OK Then
FileCopy(fileName, sd.FileName)
MsgBox(" File Saved in selected path")
FileToDelete = fileName
If System.IO.File.Exists(FileToDelete) = True Then
System.IO.File.Delete(FileToDelete)
End If
End If
FileToDelete = fileName
If System.IO.File.Exists(FileToDelete) = True Then
System.IO.File.Delete(FileToDelete)
End If
when i am trying to save this file in desired path, then i am getting this error.
if save in shared folder i am not getting this error
system.io.ioexception the process cannot access because it is being used by another process...
what i am doing wrong,Help me

not taking all images after editing from data grid view in vb.net winform application

I am working on windows form application.
in cell content click i wrote code like this:
If e.ColumnIndex = 4 Then
Dim OFDLogo As New OpenFileDialog()
OFDLogo.Filter = "JPEG(*.jpg)|*.jpg|BMP(*.bmp)|*.bmp"
If OFDLogo.ShowDialog() = DialogResult.OK Then
gv.Rows(e.RowIndex).Cells(4).Value = Image.FromFile(OFDLogo.FileName)
End If
End If
and save button i wrote code like this:
Dim cmpny As String = "Delete from CompanyMaster_tbl"
Exetransaction(cmpny)
For i As Integer = 0 To gv.RowCount - 2
sqlInsertT2 = "Insert Into DepartmentMaster_tbl(dtname,dtphone,dtEmail,Cid) Values ('" + myTI.ToTitleCase(gv.Rows(i).Cells(1).Value) + "','" + gv.Rows(i).Cells(2).Value + "','" + gv.Rows(i).Cells(3).Value + "'," & Ccid & ");"
Exetransaction(sqlInsertT2)
Dim departmnt As String = gv.Rows(i).Cells(1).Value
Dim departid As Integer = RecordID("dtId", "DepartmentMaster_tbl", "dtName", departmnt)
Dim sql As String
'----------------------------------
Dim image As Image = TryCast(gv.Rows(i).Cells(4).Value, Image)
If image IsNot Nothing Then
Dim ms As New MemoryStream()
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif)
Dim imagedata As Byte() = ms.ToArray()
sql = "update DepartmentMaster_tbl set empimage=#photo where dtId='" & departid & "'"
Dim cmd As New SqlCommand(sql, con.connect)
cmd.Parameters.Add("#photo", SqlDbType.Image)
cmd.Parameters("#photo").Value = imagedata
cmd.ExecuteNonQuery()
con.disconnect()
End If
Next
in first time i can able to save all images form data grid view..but again i load the same page ,and i try to edit one image,,after that again i try save all images from data grid view..but thise time only saving edited image .i mean(that time thise line of code not working proper)
Dim image As Image = TryCast(gv.Rows(i).Cells(4).Value, Image)
In cell content click I am taking row_index..that s why happen
check this solution
Sub refreshgrid()
Dim cd As SqlCommandBuilder = New SqlCommandBuilder(adapter)
adapter = New SqlDataAdapter("select c.cid,c.CompanyName,d.dtId,d.dtName as Department,d.dtPhone as Phone,d.dtEmail as Email,d.empimage,0 as flag from CompanyMaster_tbl c join DepartmentMaster_tbl d on c.Cid=d.cId order by cid", con.connect)
dt1 = New DataTable
bSource = New BindingSource
adapter.Fill(dt1) 'Filling dt with the information from the DB
bSource.DataSource = dt1
gv.DataSource = bSource
gv.Columns("cid").Visible = False
gv.Columns("dtId").Visible = False
Dim img As New DataGridViewImageColumn
img.HeaderText = "Image"
gv.Columns.Insert(6, img)
For i As Integer = 0 To gv.Rows.Count - 1
gv.Rows(i).Cells(6).Value = gv.Rows(i).Cells(7).Value
Next
gv.Columns("empimage").Visible = False
For i As Integer = 0 To gv.Rows.Count - 2
If Not IsDBNull(gv.Rows(i).Cells(6).Value) Then
gv.Rows(i).Height = 75
Dim column As DataGridViewColumn = gv.Columns(6)
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
End If
Next
GenerateUniqueData(1)
End Sub
Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click
adapter = New SqlDataAdapter()
Dim cid As Integer
Dim dtid As Integer
Dim cmpname As String
Dim dtname As String
Dim dtPhone As String
Dim dtEmail As String
Dim dtimage As Image
For i As Integer = 0 To gv.RowCount - 2
' Dim rv = DirectCast(bSource.Current, DataRowView)
If (gv.Rows(i).Cells(8).Value = 1) Then
Dim rv = DirectCast(gv.Rows(i).DataBoundItem, DataRowView)
cid = rv.Row.Field(Of Integer)("Cid")
dtid = rv.Row.Field(Of Integer)("dtId")
cmpname = rv.Row.Field(Of String)("CompanyName")
dtname = rv.Row.Field(Of String)("Department")
dtPhone = rv.Row.Field(Of String)("Phone")
dtEmail = rv.Row.Field(Of String)("Email")
'Using ms As New MemoryStream(rv.Row.Field(Of Byte())("empimage"))
' dtimage = New Bitmap(ms)
'End Using
adapter.UpdateCommand = New SqlCommand("UPDATE CompanyMaster_tbl SET CompanyName = #CompanyName", con.connect)
'this code for updating image also..
adapter.UpdateCommand = New SqlCommand("update DepartmentMaster_tbl set dtName = #dtName,dtPhone = #dtPhone,dtEmail = #dtEmail,empimage=#dtimage where dtId=#dtid", con.connect)
' adapter.UpdateCommand = New SqlCommand("update DepartmentMaster_tbl set dtName = #dtName,dtPhone = #dtPhone,dtEmail = #dtEmail where dtId=#dtid", con.connect)
adapter.UpdateCommand.Parameters.AddWithValue("#Cid", cid)
adapter.UpdateCommand.Parameters.AddWithValue("#CompanyName", cmpname)
adapter.UpdateCommand.Parameters.AddWithValue("#dtId", dtid)
adapter.UpdateCommand.Parameters.AddWithValue("#dtName", dtname)
adapter.UpdateCommand.Parameters.AddWithValue("#dtPhone", dtPhone)
adapter.UpdateCommand.Parameters.AddWithValue("#dtEmail", dtEmail)
'Dim md As New MemoryStream()
'dtimage.Save(md, System.Drawing.Imaging.ImageFormat.Gif)
' Dim imagedata As Byte() = md.ToArray()
'Dim md As New MemoryStream()
'' Save to memory using the Jpeg format
'dtimage.Save(md, ImageFormat.Gif)
' read to end
'Dim bmpBytes As Byte() = md.GetBuffer()
' Dim image As Byte() = System.IO.File.ReadAllBytes()
Dim image As Image = TryCast(gv.Rows(i).Cells(6).Value, Image)
If image IsNot Nothing Then
Dim ms As New MemoryStream()
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif)
Dim imagedata As Byte() = ms.ToArray()
adapter.UpdateCommand.Parameters.AddWithValue("#dtimage", imagedata)
End If
'adapter.UpdateCommand.Parameters.AddWithValue("#dtimage", dtimage)
adapter.UpdateCommand.ExecuteNonQuery()
End If
Next
End Sub
Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclose.Click
Me.Close()
End Sub
Private Sub gv_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles gv.CellContentClick
If e.ColumnIndex = 6 Then
Dim OFDLogo As New OpenFileDialog()
OFDLogo.Filter = "JPEG(*.jpg)|*.jpg|BMP(*.bmp)|*.bmp"
If OFDLogo.ShowDialog() = DialogResult.OK Then
gv.Rows(e.RowIndex).Cells(6).Value = Image.FromFile(OFDLogo.FileName)
gv.Rows(e.RowIndex).Cells(8).Value = "1"
End If
End If
End Sub
Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
For i As Integer = 0 To gv.RowCount - 2
If gv.Rows(i).Cells(1).Value.ToString.Length <> 0 AndAlso Not IsDBNull(gv.Rows(i).Cells(1).Value) Then
If gv.Rows(i).Cells(3).Value.ToString.Length = 0 OrElse IsDBNull(gv.Rows(i).Cells(3).Value) Then
MsgBox("Please Enter Department Details")
Exit Sub
End If
End If
Next
'Dim deprt As String = "Delete from DepartmentMaster_tbl"
'Exetransaction(deprt)
'Dim cmpny As String = "Delete from CompanyMaster_tbl"
'Exetransaction(cmpny)
Dim sqlInsertT1 As String = ""
Dim sqlInsertT2 As String = ""
For i As Integer = 0 To gv.RowCount - 2
' If gv.Rows(i).Cells(1).Value IsNot System.DBNull.Value AndAlso gv.Rows(i).Cells(1).Value <> "" Then
If (gv.Rows(i).Cells(8).Value = 1) Then
If Not IsDBNull(gv.Rows(i).Cells(1).Value) AndAlso gv.Rows(i).Cells(1).Value.ToString.Length <> 0 Then
Dim cnt As Integer = RecordPresent("CompanyMaster_tbl", "CompanyName", gv.Rows(i).Cells(1).Value)
If cnt = 0 Then
sqlInsertT1 = "Insert Into CompanyMaster_tbl(CompanyName) Values ('" + myTI.ToTitleCase(gv.Rows(i).Cells(1).Value) + "')"
Exetransaction(sqlInsertT1)
Ccid = RecordID("Cid", "CompanyMaster_tbl", "CompanyName", gv.Rows(i).Cells(1).Value)
Else
Ccid = RecordID("Cid", "CompanyMaster_tbl", "CompanyName", gv.Rows(i).Cells(1).Value)
End If
End If
If Not IsDBNull(gv.Rows(i).Cells(3).Value) AndAlso gv.Rows(i).Cells(3).Value.ToString.Length <> 0 Then
sqlInsertT2 = "Insert Into DepartmentMaster_tbl(dtname,dtphone,dtEmail,Cid) Values ('" + myTI.ToTitleCase(gv.Rows(i).Cells(3).Value) + "','" + gv.Rows(i).Cells(4).Value + "','" + gv.Rows(i).Cells(5).Value + "'," & Ccid & ");"
Exetransaction(sqlInsertT2)
Dim departmnt As String = gv.Rows(i).Cells(3).Value
Dim departid As Integer = RecordID("dtId", "DepartmentMaster_tbl", "dtName", departmnt)
Dim sql As String
'----------------------------------
Dim image As Image = TryCast(gv.Rows(i).Cells(6).Value, Image)
If image IsNot Nothing Then
Dim ms As New MemoryStream()
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif)
Dim imagedata As Byte() = ms.ToArray()
sql = "update DepartmentMaster_tbl set empimage=#photo where dtId='" & departid & "'"
Dim cmd As New SqlCommand(sql, con.connect)
cmd.Parameters.Add("#photo", SqlDbType.Image)
cmd.Parameters("#photo").Value = imagedata
cmd.ExecuteNonQuery()
con.disconnect()
End If
End If
End If
Next
' refreshgrid()
End Sub