adding a textbox,with a column in the DB

Last post 04-29-2008 2:52 PM by etha66. 17 replies.

Sort Posts:

  • adding a textbox,with a column in the DB

    04-23-2008, 2:07 PM
    • Loading...
    • etha66
    • Joined on 02-25-2008, 8:05 AM
    • Posts 34

    I want to add a textbox "phone" in the postads page, and want to add the corresponding column in the classifiedads table (phone) to show it in a label in the showads page.

    It made me crazy!!! please can someone teach me how to do? Thank you

  • Re: adding a textbox,with a column in the DB

    04-23-2008, 2:31 PM
    • Loading...
    • lberan
    • Joined on 02-12-2008, 7:23 PM
    • Pittsburgh, PA
    • Posts 516

    I'm not sure what frustrates you.  These are steps to do this:

    1.  author a form page with the phone textbox
    2. update phone number in the table of the database with the value obtained from the above page
    3. retrieve the phone number from the database and display it on the second form page
    Lynn

  • Re: adding a textbox,with a column in the DB

    04-23-2008, 2:54 PM
    • Loading...
    • darkknight187
    • Joined on 09-14-2006, 12:35 AM
    • Bothell, Washington
    • Posts 727

    Once you get it more additions are simple, but there are 10 files that need modifications 

    The 10 starting in the classifieds_Ads database are of course in the "Tables" add your new column,

    for the phone number you could use a nvarchar(50) for the type.

    (I started out by copying the code for AdType and Location)

    2: In the Views folder "ClassifiedsView_Ads" Check the empty boxes next to your new addition.

    3: "Stored Procedures" There's a lot here so here they are GetAdById, GetSavedAds, InsertAd, RelistAd, UpdateAd.

    4: Now in the Solutions Explorer (I'm working off of VWD) go in App_Code folder, into BLL folder and change Ads.vb.

    Follow how the others are set like adtype, location, url . . . In this case when you declare it you can do it "As String"

    5: Now into DAL and into Ads.xsd, add your new addition. (don't forget to change the properties of your new column after you insert Phone.)

    I prefer to do this part manually to keep the Scheme,

    (NOW THIS PART IS VERY IMPORTANT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!)

    Still in Ads.xsd after you save, right click and choose view code.

    This file needs to be modified as well but you must be entering your new code in the same order, ie (1)(2)(3)(4)

    if you enter your new catagories in any order (1)(3)(2)(4) and then in (1)(2)(4)(3) it will end up uploading info to the wrong database column.

     Your Ads page will have errors until you have them all correct.

    And of course the postad, and editad page.

    So with that said the biggest piece of advise I can give you is copy your project folder and save it as a backup elsewhere just in case.

     

    Good luck, if you get stuck let me know.

    Daniel

     

    Please remember to click “Mark as Answer” on the post that helps you.
    This can be beneficial to other community members reading the thread.
  • Re: adding a textbox,with a column in the DB

    04-23-2008, 5:02 PM
    • Loading...
    • etha66
    • Joined on 02-25-2008, 8:05 AM
    • Posts 34

    Thank you Daniel,

    I've done all what you asked me to do, but still,messages!!! grr, you're right i think i didn't respected order ,i'll try again, and keep you informed.

    Thank you once again, Daniel

    'sorry for my bad english! lol'

  • Re: adding a textbox,with a column in the DB

    04-23-2008, 5:07 PM
    • Loading...
    • etha66
    • Joined on 02-25-2008, 8:05 AM
    • Posts 34

    darkknight187:

    Once you get it more additions are simple, but there are 10 files that need modifications 

    The 10 starting in the classifieds_Ads database are of course in the "Tables" add your new column,

    for the phone number you could use a nvarchar(50) for the type.

    (I started out by copying the code for AdType and Location)

    2: In the Views folder "ClassifiedsView_Ads" Check the empty boxes next to your new addition.

    3: "Stored Procedures" There's a lot here so here they are GetAdById, GetSavedAds, InsertAd, RelistAd, UpdateAd.

    4: Now in the Solutions Explorer (I'm working off of VWD) go in App_Code folder, into BLL folder and change Ads.vb.

    Follow how the others are set like adtype, location, url . . . In this case when you declare it you can do it "As String"

    5: Now into DAL and into Ads.xsd, add your new addition. (don't forget to change the properties of your new column after you insert Phone.)

    I prefer to do this part manually to keep the Scheme,

    (NOW THIS PART IS VERY IMPORTANT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!)

    Still in Ads.xsd after you save, right click and choose view code.

    This file needs to be modified as well but you must be entering your new code in the same order, ie (1)(2)(3)(4)

    if you enter your new catagories in any order (1)(3)(2)(4) and then in (1)(2)(4)(3) it will end up uploading info to the wrong database column.

     Your Ads page will have errors until you have them all correct.

    And of course the postad, and editad page.

    So with that said the biggest piece of advise I can give you is copy your project folder and save it as a backup elsewhere just in case.

     

    Good luck, if you get stuck let me know.

    Daniel

     

    darkknight187:

    Once you get it more additions are simple, but there are 10 files that need modifications 

    The 10 starting in the classifieds_Ads database are of course in the "Tables" add your new column,

    for the phone number you could use a nvarchar(50) for the type.

    (I started out by copying the code for AdType and Location)

    2: In the Views folder "ClassifiedsView_Ads" Check the empty boxes next to your new addition.

    3: "Stored Procedures" There's a lot here so here they are GetAdById, GetSavedAds, InsertAd, RelistAd, UpdateAd.

    4: Now in the Solutions Explorer (I'm working off of VWD) go in App_Code folder, into BLL folder and change Ads.vb.

    Follow how the others are set like adtype, location, url . . . In this case when you declare it you can do it "As String"

    5: Now into DAL and into Ads.xsd, add your new addition. (don't forget to change the properties of your new column after you insert Phone.)

    I prefer to do this part manually to keep the Scheme,

    (NOW THIS PART IS VERY IMPORTANT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!)

    Still in Ads.xsd after you save, right click and choose view code.

    This file needs to be modified as well but you must be entering your new code in the same order, ie (1)(2)(3)(4)

    if you enter your new catagories in any order (1)(3)(2)(4) and then in (1)(2)(4)(3) it will end up uploading info to the wrong database column.

     Your Ads page will have errors until you have them all correct.

    And of course the postad, and editad page.

    So with that said the biggest piece of advise I can give you is copy your project folder and save it as a backup elsewhere just in case.

     

    Good luck, if you get stuck let me know.

    Daniel

     

  • Re: adding a textbox,with a column in the DB

    04-23-2008, 5:18 PM
    • Loading...
    • etha66
    • Joined on 02-25-2008, 8:05 AM
    • Posts 34

    Very well done and beautifull your website!!

  • Re: adding a textbox,with a column in the DB

    04-23-2008, 5:55 PM
    • Loading...
    • darkknight187
    • Joined on 09-14-2006, 12:35 AM
    • Bothell, Washington
    • Posts 727

    Thank you for the compliment.

    Did you figure it out??

    Please remember to click “Mark as Answer” on the post that helps you.
    This can be beneficial to other community members reading the thread.
  • Re: adding a textbox,with a column in the DB

    04-25-2008, 11:19 AM
    • Loading...
    • etha66
    • Joined on 02-25-2008, 8:05 AM
    • Posts 34

    Hi!

    lol,Still got pbms! so i send you copy of my BLL/ads.vb code,and DAL/ads.xsd code as i modified it to add "phone". Can you say me what's wrong?

    BLL/ads.vb code:

    Imports System

    Imports System.Web

    Imports System.Web.Security

    Imports System.Text

    Imports System.Net.Mail

    Imports System.Collections

    Imports System.Collections.Generic

    Imports AdsDataComponentTableAdapters

    Imports AspNet.StarterKits.Classifieds.Web

    Namespace AspNet.StarterKits.Classifieds.BusinessLogicLayer

    ''' <summary>

    ''' Describes the type of an ad: "For Sale" or "Wanted."

    ''' "Unspecified" is used to indicate a variable of this type has not yet been set.

    ''' </summary>

    Public Enum AdType

    Unspecified = 0

    ForSale = 1

    Wanted = 2

    End Enum

    ''' <summary>

    ''' Describes the level, or priority, of an ad.

    ''' This value is used when ordering results (highest to lowest)

    ''' on search queries and it can affect the display of rows.

    '''

    ''' "Featured" indicates that the ad will be selected by the "Featured Ad" control

    ''' that rotates ads to display on the site.

    ''' "Unspecified" is used to indicate a variable of this type has not yet been set.

    '''

    ''' Use this enumeration to differentiate ads with different priorities

    ''' or even price points.

    ''' </summary>

    Public Enum AdLevel

    Unspecified = 0

    Normal = 10

    Featured = 50

    End Enum

    ''' <summary>

    ''' Describes the status of an ad:

    ''' Only ads with positive AdStatus values will be displayed on the public site;

    ''' administrators will be able to see all.

    '''

    '''

    '''

    ''' "Unspecified" is used to indicate a variable of this type has not yet been set.

    ''' </summary>

    Public Enum AdStatus

    ActivationPending = -200

    Deleted = -100

    Inactive = -50

    Unspecified = 0

    Activated = 100

    End Enum

    Public NotInheritable Class AdsDB

     

    Private Sub New()

    End Sub

    #Region "InsertingAds"

    Public Shared Function InsertAd(ByVal memberId As Integer, ByVal categoryId As Integer, ByVal title As String, ByVal description As String, ByVal url As String, ByVal price As Decimal, ByVal location As String, ByVal numDaysActive As Integer, ByVal adLevel As AdLevel, ByVal adStatus As AdStatus, ByVal adType As AdType, ByVal Phone As String) As Integer

    Dim s As SiteSettings = SiteSettings.GetSharedSettings()

    Dim numViews As Integer = 0

    Dim numResponses As Integer = 0

    Dim dateCreated As DateTime = DateTime.Now

    Dim dateApproved As System.Nullable(Of DateTime)

    If numDaysActive > s.MaxAdRunningDays Then

    numDaysActive = s.MaxAdRunningDays

    End If

    If numDaysActive < 1 Then

    numDaysActive = 1

    End If

    Dim expirationDate As DateTime = DateTime.Today.AddDays(numDaysActive)

    If s.AdActivationRequired Then

    adStatus = adStatus.ActivationPending

    dateApproved = Nothing

    Else

    adStatus = adStatus.Activated

    dateApproved = dateCreated

    End If

    If adLevel = adLevel.Unspecified Then

    adLevel = adLevel.Normal

    End If

    Dim adId As Integer = DefaultValues.IdNullValue

    Dim ad As AdsDataComponent.AdsRow = Nothing

    Using db As New AdsDataAdapter()

    adId = CInt(db.InsertAd(memberId, categoryId, title, description, url, price, location, expirationDate, dateCreated, dateApproved, numViews, numResponses, CInt(adLevel), CInt(adStatus), CInt(adType), ))

    If s.AdminNotification = AdminNotificationSetting.EachAd Then

    ad = GetFirstRow(db.GetAdById(adId))

    End If

    End Using

    If Not (ad Is Nothing) Then

    Maintenance.SendAdNotification(ad)

    End If

    Return adId

    End Function

    Public Shared Sub InsertSavedAd(ByVal adId As Integer, ByVal memberId As Integer)Using db As New AdsDataAdapter()

    db.InsertSavedAd(adId, memberId)

    End Using

    End Sub

    Public Shared Sub InsertSavedAdList(ByVal adIds As List(Of Integer), ByVal memberId As Integer)

    Using db As New AdsDataAdapter()

    Dim i As Integer

    For i = 0 To adIds.Count - 1

    db.InsertSavedAd(adIds(i), memberId)

    Next i

    End Using

    End Sub

    #End Region

    #Region "GetAds..."

    Public Shared Function GetAdById(ByVal adId As Integer) As AdsDataComponent.AdsRow

    Using db As New AdsDataAdapter()

    Return GetFirstRow(db.GetAdById(adId))

    End Using

    End Function

     

    Public Shared Function GetActiveAdsByQuery(ByVal recordLimit As Integer, ByVal categoryId As Integer, ByVal memberId As Integer, ByVal maxPrice As Decimal, ByVal searchTerm As String, ByVal location As String, ByVal adType As Integer, ByVal adLevel As Integer, ByVal dayRange As Integer, ByVal mustHaveImage As Boolean) As AdsDataComponent.AdsDataTable

    Dim escapedSearchTerm As String = AdsDB.EscapeWildcardCharacters(searchTerm)

    Dim escapedLocation As String = AdsDB.EscapeWildcardCharacters(location)Return GetAdsByQuery(recordLimit, _

    categoryId, memberId, maxPrice, _

    HttpUtility.HtmlEncode(escapedSearchTerm), _

    HttpUtility.HtmlEncode(escapedLocation), _

    adType,
    CInt(AdStatus.Activated), _

    adLevel, dayRange, mustHaveImage)

    End Function

     

     

    Public Shared Function GetAdsByQuery(ByVal recordLimit As Integer, ByVal categoryId As Integer, ByVal memberId As Integer, ByVal maxPrice As Decimal, ByVal searchTerm As String, ByVal location As String, ByVal adType As Integer, ByVal adStatus As Integer, ByVal adLevel As Integer, ByVal dayRange As Integer, ByVal mustHaveImage As Boolean) As AdsDataComponent.AdsDataTable

    Dim minCreatedDate As System.Nullable(Of DateTime)

    If location Is Nothing Then

    location = ""

    End If

    If dayRange > 0 Then

    minCreatedDate = DateTime.Now.Subtract(TimeSpan.FromDays(dayRange))

    End If

    ' To return no results if the searchTerm is empty remove the following

    ' check on the searchTerm.

    If searchTerm Is Nothing Then

    searchTerm = ""

    End If

    Using db As New AdsDataAdapter()

    Dim aa As AdsDataComponent.AdsDataTable = Nothing

    aa = db.GetAllAdsByQuery(recordLimit, categoryId, memberId, maxPrice, searchTerm, location, adType, adStatus, adLevel, minCreatedDate, mustHaveImage)

    Return aa

    End Using

    End Function

     

    Public Shared Function GetPendingAds() As AdsDataComponent.AdsDataTable

    Return GetAdsByStatus(AdStatus.ActivationPending, DefaultValues.IdNullValue)

    End Function

     

    Public Shared Function GetPendingAds(ByVal memberId As Integer) As AdsDataComponent.AdsDataTable

    Return GetAdsByStatus(AdStatus.ActivationPending, memberId)

    End Function

     

    Public Shared Function GetActiveAds(ByVal memberId As Integer) As AdsDataComponent.AdsDataTable

    Return GetAdsByStatus(AdStatus.Activated, memberId)

    End Function

     

    Public Shared Function GetInactiveAds(ByVal memberId As Integer) As AdsDataComponent.AdsDataTable

    Return GetAdsByStatus(AdStatus.Inactive, memberId)

    End Function 'GetInactiveAds

     

    Public Shared Function GetAdsByStatus(ByVal adStatus As AdStatus, ByVal memberId As Integer) As AdsDataComponent.AdsDataTable

    Using db As New AdsDataAdapter()

    Return db.GetAdsByStatus(CInt(adStatus), memberId)

    End Using

    End Function

     

    Public Shared Function GetAdsByStatus(ByVal adStatus As AdStatus) As AdsDataComponent.AdsDataTable

    Return GetAdsByStatus(adStatus, DefaultValues.IdNullValue)

    End Function

     

    Public Shared Function GetFeaturedAdsSelection(ByVal maxNumAds As Integer) As AdsDataComponent.AdsDataTable

    If maxNumAds < 1 Then

    Return Nothing

    End If

    Using db As New AdsDataAdapter()

    Return db.GetAdsByRandomOrder(maxNumAds, CInt(AdStatus.Activated), CInt(AdLevel.Featured))

    End Using

    End Function

     

    Public Shared Function GetSavedAds(ByVal memberId As Integer) As AdsDataComponent.AdsDataTable

    Using db As New AdsDataAdapter()

    Return db.GetSavedAds(memberId)

    End Using

    End Function

    #End Region

    #Region "Update Ads"

    Public Shared Sub UpdateAd(ByVal original_Id As Integer, ByVal memberId As Integer, ByVal title As String, ByVal description As String, ByVal url As String, ByVal price As Decimal, ByVal location As String, ByVal isRelisting As Boolean)

    If (url Is Nothing) Then

    url = String.Empty

    End If

    Using db As New AdsDataAdapter()

    db.UpdateAd(original_Id, memberId, _

    HttpUtility.HtmlEncode(title), _

    HttpUtility.HtmlEncode(description), _

    HttpUtility.UrlEncode(url), _

    price, _

    HttpUtility.HtmlEncode(location))

    End Using

    End Sub

     

    Public Shared Sub RelistAd(ByVal adId As Integer, ByVal categoryId As Integer, ByVal title As String, ByVal description As String, ByVal url As String, ByVal price As Decimal, ByVal location As String, ByVal numDaysActive As Integer, ByVal adLevel As AdLevel, ByVal adStatus As AdStatus, ByVal adType As AdType)

    Dim s As SiteSettings = SiteSettings.GetSharedSettings()

    Dim dateCreated As DateTime = DateTime.Now

    Dim dateApproved As System.Nullable(Of DateTime)

    If numDaysActive > s.MaxAdRunningDays Then

    numDaysActive = s.MaxAdRunningDays

    End If

    If numDaysActive < 1 Then

    numDaysActive = 1

    End If

    Dim expirationDate As DateTime = DateTime.Today.AddDays(numDaysActive)

    If s.AdActivationRequired Then

    adStatus = adStatus.ActivationPending

    dateApproved = Nothing

    Else

    adStatus = adStatus.Activated

    dateApproved = dateCreated

    End If

    If adLevel = adLevel.Unspecified Then

    adLevel = adLevel.Normal

    End If

    Dim ad As AdsDataComponent.AdsRow = Nothing

    Using db As New AdsDataAdapter()

    db.RelistAd(adId, categoryId, title, description, url, price, location, expirationDate, dateCreated, dateApproved, CInt(adLevel), CInt(adStatus), CInt(adType))

    If s.AdminNotification = AdminNotificationSetting.EachAd Then

    ad = GetFirstRow(db.GetAdById(adId))

    End If

    End Using

    If Not (ad Is Nothing) Then

    Maintenance.SendAdNotification(ad)

    End If

    End Sub

     

    Public Shared Sub IncrementViewCount(ByVal adId As Integer)Using db As New AdsDataAdapter()

    db.UpdateAdStats(adId, 1, 0)

    End Using

    End Sub

     

    Public Shared Sub IncrementResponseCount(ByVal adId As Integer)Using db As New AdsDataAdapter()

    db.UpdateAdStats(adId, 0, 1)

    End Using

    End Sub

     

    Public Shared Sub UpdateAdCategory(ByVal adId As Integer, ByVal categoryId As Integer)Using db As New AdsDataAdapter()

    db.UpdateAdCategory(adId, categoryId)

    End Using

    End Sub

     

     

    Public Shared Sub UpdateAdLevel(ByVal adId As Integer, ByVal adLevel As AdLevel)

    Using db As New AdsDataAdapter()

    db.UpdateAdLevel(adId, CInt(adLevel))

    End Using

    End Sub

     

    Public Shared Sub UpdateAdLevelList(ByVal adIds As List(Of Integer), ByVal adLevel As AdLevel