vb.net using string and custom objects
-
In a vb.net 2010 application, I am trying to determine the best way to accomplish this goal. Write now 1 letter is generated and sent to one guardian. However this application needs to be changed so that the same exact letter can be send to different mailing addresses since each student may have more than one parent/guardian at different mailing addresses. So basically I want to generate more than one letter with the same wording. The only differences between the letters would be the mailingaddresses. I want the letters to be written to the same varchar(max) column in a sql server 2012 database. The letters will be in the same field since the data will be sent to a sql server reporting server where the letters will be generated one after each other.Right now the letters are written to the 'Dim _al As Letters = New Letters()' object. The only way I know to modify text data is to use a string or stringbuilder objects. I do not know yo modify data is other objects. Basically I want to use a string.replace logic to replace the addresses in the second letter. I also want to use stringbuilder.append to place more than one letter following another to be placed in the osne varchar(max) field. I know I can use the following code to convert a custom object to a string.
Dim _LetterStr As String = String.Empty
Dim _LetterStrbldr As StringBuilder = New StringBuilder
_LetterStr = _Letter.Letter.ToString()However I do not know how to convert a string object back to a custom object. Here is the original code of the application:
#Region "Protected Sub btnSubmitModifiedLetter_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles btnSubmitModifiedLetter.Click"
Protected Sub btnSubmitModifiedLetter_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles btnSubmitModifiedLetter.Click
Dim _al As Letters = New Letters()
Dim _infinteCampusText As String
Dim _Letter As Letter = New Letter()
Dim _startDate As DateTime = Now()
Dim _term As Integer = 0\_Letter.SchoolYear = \_schoolyear \_Letter.Term = \_term \_Letter.Milestone = ddlMilestone.SelectedValue \_Letter.SchoolNumber = Right("000" & ddlSchools.SelectedValue,3) \_Letter.Printed = "Y" \_Letter.Letter = reLetterEditor.Content \_Letter.StudentLink = Right("0000000" & txtStuLink.Text, 7) \_Letter.Language = txtLanguage.Text \_infinteCampusText = \_al.BuildText(\_Letter)
-
In a vb.net 2010 application, I am trying to determine the best way to accomplish this goal. Write now 1 letter is generated and sent to one guardian. However this application needs to be changed so that the same exact letter can be send to different mailing addresses since each student may have more than one parent/guardian at different mailing addresses. So basically I want to generate more than one letter with the same wording. The only differences between the letters would be the mailingaddresses. I want the letters to be written to the same varchar(max) column in a sql server 2012 database. The letters will be in the same field since the data will be sent to a sql server reporting server where the letters will be generated one after each other.Right now the letters are written to the 'Dim _al As Letters = New Letters()' object. The only way I know to modify text data is to use a string or stringbuilder objects. I do not know yo modify data is other objects. Basically I want to use a string.replace logic to replace the addresses in the second letter. I also want to use stringbuilder.append to place more than one letter following another to be placed in the osne varchar(max) field. I know I can use the following code to convert a custom object to a string.
Dim _LetterStr As String = String.Empty
Dim _LetterStrbldr As StringBuilder = New StringBuilder
_LetterStr = _Letter.Letter.ToString()However I do not know how to convert a string object back to a custom object. Here is the original code of the application:
#Region "Protected Sub btnSubmitModifiedLetter_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles btnSubmitModifiedLetter.Click"
Protected Sub btnSubmitModifiedLetter_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles btnSubmitModifiedLetter.Click
Dim _al As Letters = New Letters()
Dim _infinteCampusText As String
Dim _Letter As Letter = New Letter()
Dim _startDate As DateTime = Now()
Dim _term As Integer = 0\_Letter.SchoolYear = \_schoolyear \_Letter.Term = \_term \_Letter.Milestone = ddlMilestone.SelectedValue \_Letter.SchoolNumber = Right("000" & ddlSchools.SelectedValue,3) \_Letter.Printed = "Y" \_Letter.Letter = reLetterEditor.Content \_Letter.StudentLink = Right("0000000" & txtStuLink.Text, 7) \_Letter.Language = txtLanguage.Text \_infinteCampusText = \_al.BuildText(\_Letter)
Why would you need to do such a conversion? All you need is a template that contains the main text of your letter, a _Letter object that contains the different properties (name, address etc), and a subroutine that formats the data into its printed form.
-
Why would you need to do such a conversion? All you need is a template that contains the main text of your letter, a _Letter object that contains the different properties (name, address etc), and a subroutine that formats the data into its printed form.
-
Would you show me an example of the code you are referring to? How should I convert a string object to a custom .net object?
-
Would you show me an example of the code you are referring to? How should I convert a string object to a custom .net object?
Serialization?
A guide to posting questions on CodeProject
Click this: Asking questions is a skill. Seriously, do it.
Dave Kreskowiak -
In a vb.net 2010 application, I am trying to determine the best way to accomplish this goal. Write now 1 letter is generated and sent to one guardian. However this application needs to be changed so that the same exact letter can be send to different mailing addresses since each student may have more than one parent/guardian at different mailing addresses. So basically I want to generate more than one letter with the same wording. The only differences between the letters would be the mailingaddresses. I want the letters to be written to the same varchar(max) column in a sql server 2012 database. The letters will be in the same field since the data will be sent to a sql server reporting server where the letters will be generated one after each other.Right now the letters are written to the 'Dim _al As Letters = New Letters()' object. The only way I know to modify text data is to use a string or stringbuilder objects. I do not know yo modify data is other objects. Basically I want to use a string.replace logic to replace the addresses in the second letter. I also want to use stringbuilder.append to place more than one letter following another to be placed in the osne varchar(max) field. I know I can use the following code to convert a custom object to a string.
Dim _LetterStr As String = String.Empty
Dim _LetterStrbldr As StringBuilder = New StringBuilder
_LetterStr = _Letter.Letter.ToString()However I do not know how to convert a string object back to a custom object. Here is the original code of the application:
#Region "Protected Sub btnSubmitModifiedLetter_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles btnSubmitModifiedLetter.Click"
Protected Sub btnSubmitModifiedLetter_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles btnSubmitModifiedLetter.Click
Dim _al As Letters = New Letters()
Dim _infinteCampusText As String
Dim _Letter As Letter = New Letter()
Dim _startDate As DateTime = Now()
Dim _term As Integer = 0\_Letter.SchoolYear = \_schoolyear \_Letter.Term = \_term \_Letter.Milestone = ddlMilestone.SelectedValue \_Letter.SchoolNumber = Right("000" & ddlSchools.SelectedValue,3) \_Letter.Printed = "Y" \_Letter.Letter = reLetterEditor.Content \_Letter.StudentLink = Right("0000000" & txtStuLink.Text, 7) \_Letter.Language = txtLanguage.Text \_infinteCampusText = \_al.BuildText(\_Letter)
I'll attempt to answer your question, but if it were me, I think I would re-design this solution. Do you really need to store the letter in the database ? Maybe create a template letter, give it a unique document ID, then you could store multiple records with the student ID, template ID and sequence number. To answer your question ... Create a class and call it LetterDetail; at a minimum it would have a string to store the letter. Create another class and call it MailedLetters; this would contain a List(Of LetterDetail) The second class gives you the ability to have as many letters as you want grouped together. Within the second class, you would need 2 methods, Save and Load. This would serialize the object to an XML string which you could then save in the database. I'll give you some rough code for serialization ...
Public Shared Function Load(sFname As String) As MailedLetters
Dim xr As XmlReader
Dim settings As XmlWriterSettings = New XmlWriterSettings()
settings.Indent = True
settings.IndentChars = (ControlChars.Tab)
settings.OmitXmlDeclaration = TrueDim obj As New MailedLetters Dim mySerializer As New XmlSerializer(obj.GetType) xr = XmlReader.Create(sFname) obj = mySerializer.Deserialize(xr) xr.Close() xr = Nothing Return obj End Function
Instead of serializing to a file, you want to serialize it to a string.
Sub Save(sFname As String)
Dim xw As XmlWriter
Dim mySerializer As New XmlSerializer(Me.GetType)
Dim settings As XmlWriterSettings = New XmlWriterSettings()
settings.Indent = True
settings.IndentChars = (ControlChars.Tab)
settings.OmitXmlDeclaration = Falsexw = XmlWriter.Create(sFname, settings) mySerializer.Serialize(xw, Me) xw.Close()
End Sub
That's the best I can do for you, hope it helps. :java: