Link to home
Start Free TrialLog in
Avatar of Mike B.
Mike B.

asked on

Visual Studio Community 2015: How to save a signature using Inkpicture object, either to a folder or to access

I'm creating a series of apps for my work to inventory orders, loaners, etc. and I've gotten most everything created. The problem I'm having is with signatures. The user will need to sign for whatever they're getting. To achieve this, I'm using an Inkpicture object. It works great, except when I use the save method, I get InvalidCast Exception.

Here is the code I'm using to save:

Private Sub SaveButton_Click(sender As System.Object, e As System.EventArgs) Handles SaveButton.Click


        If myConnection.State = ConnectionState.Closed Then

            myConnection.Open()

        End If

        Dim str As String

        str = "Update [Items] SET [Picked] = '" & escapeQutoes(Controls("Picked").Text) & "', [Datepicked] = '" & escapeQutoes(Controls("Datepicked").Text) & "', [Tech] = '" & escapeQutoes(Controls("Tech").Text) & "' WHERE [RITMWO] = '" & escapeQutoes(Controls("RITMWO").Text) & "'"

        Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)

        Dim targetFilename As String = "C:\Users\Dudeman\Desktop\Sigs\'" & RITMWO.Text & "'.jpg"

        Signature.Ink.Save(targetFilename)

        Try

            cmd.ExecuteNonQuery()

            cmd.Dispose()

            myConnection.Close()

            MsgBox("Records Updated Successfully")

        Catch ex As Exception

            MsgBox(ex.Message)

        End Try



    End Sub

 Public Function escapeQutoes(input As String) As String

        If input.Contains("'") Then

            input = input.Replace("'", "''")

        End If

        Return input

    End Function

Open in new window


I haven't been able to find anything useful in my two weeks of searching for the answer. Can anyone help me? I've tried changing the file type to .gif, bmp, and .isf with no change.

Ultimately, I'm looking to save this into the Access database it's pulling and saving to anyway (for the other information being saved), but I'm trying to get the signature saved any way I can.

User generated image
Avatar of it_saige
it_saige
Flag of United States of America image

Not that this is the root cause of your problem, but this may be incorrect:
Dim targetFilename As String = "C:\Users\Dudeman\Desktop\Sigs\'" & RITMWO.Text & "'.jpg"
' Produces a string like - C:\Users\Dudeman\Desktop\Sigs\'TEST'.jpg

Open in new window

You probably want it to be:
Dim targetFilename As String = "C:\Users\Dudeman\Desktop\Sigs\" & RITMWO.Text & ".jpg"
' Produces a string like - C:\Users\Dudeman\Desktop\Sigs\TEST.jpg

Open in new window


As to the root cause of your problem, the Save method that you have referenced is expecting a PersistenceFormat parameter, which is an int based enumeration.

The exception is that you cannot convert a string to an int.

So is the ink image actually stored and you are trying to load it?  Are you wishing to store it as a blob in the database (personally I would, that way any device that accesses the database can download and view/print the image)?

-saige-
Avatar of Mike B.
Mike B.

ASKER

It won't save at all. I would like to store it as a blob though, since I will eventually create a receipt to send the users (later project).
So I am assuming that Signature is your Ink object.  Is this a correct assumption?

-saige-
Avatar of Mike B.

ASKER

That is correct.
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike B.

ASKER

Thanks for the input! This is great. It's been rather busy so I'll try to apply it to my stuff this weekend. I'll let you know what happens on Monday.