Imports BVSoftware.BVC.Core Public Class configuration_shipping_UPS_License Inherits BaseAdminPage Protected WithEvents lblLicense As System.Web.UI.WebControls.Label Protected WithEvents inName As System.Web.UI.WebControls.TextBox Protected WithEvents inCompany As System.Web.UI.WebControls.TextBox Protected WithEvents inURL As System.Web.UI.WebControls.TextBox Protected WithEvents inTitle As System.Web.UI.WebControls.TextBox Protected WithEvents inAddress1 As System.Web.UI.WebControls.TextBox Protected WithEvents inAddress2 As System.Web.UI.WebControls.TextBox Protected WithEvents inAddress3 As System.Web.UI.WebControls.TextBox Protected WithEvents inCity As System.Web.UI.WebControls.TextBox Protected WithEvents inZip As System.Web.UI.WebControls.TextBox Protected WithEvents inPhone As System.Web.UI.WebControls.TextBox Protected WithEvents inEmail As System.Web.UI.WebControls.TextBox Protected WithEvents inUPSAccountNumber As System.Web.UI.WebControls.TextBox Protected WithEvents rbContactYes As System.Web.UI.WebControls.RadioButton Protected WithEvents rbContactNo As System.Web.UI.WebControls.RadioButton Protected WithEvents btnCancel As System.Web.UI.WebControls.ImageButton Protected WithEvents btnAccept As System.Web.UI.WebControls.ImageButton Protected WithEvents FirstFocus1 As MetaBuilders.WebControls.FirstFocus Protected WithEvents MetaDescriptionControl As BVSoftware.WebControls.MetaTag Protected WithEvents MetaKeywordsControl As BVSoftware.WebControls.MetaTag Protected WithEvents inState As BVSoftware.WebControls.SelectDropDownList Protected WithEvents msg As BVSoftware.WebControls.WebPageMessage Protected WithEvents imgPrint As System.Web.UI.WebControls.Image Protected WithEvents inCountry As System.Web.UI.HtmlControls.HtmlSelect #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load BVC2004Store.CheckThisPage(Security.RolePermission.LoginToAdmin) BVC2004Store.CheckThisPage(Security.RolePermission.AccessSettingsArea) If Not Page.IsPostBack Then MetaKeywordsControl.Content = WebAppSettings.MetaKeywords MetaDescriptionControl.Content = WebAppSettings.MetaDescription End If If Not Page.IsPostBack Then Try Dim contactAddress As Contacts.Address = WebAppSettings.ContactAddress With contactAddress inAddress1.Text = .StreetLine1 inAddress2.Text = .StreetLine2 inCity.Text = .City inState.SelectByValue(.StateCode) inEmail.Text = WebAppSettings.ContactEmail inPhone.Text = .PhoneNumber inZip.Text = .PostalCode End With LoadStates() If Request.Params("state") <> Nothing Then SetState(Request.Params("state")) End If Catch Ex As Exception msg.ShowException(Ex) End Try ' Get License Try Dim UPSReg As New BVSoftware.UPS.OnlineTools.Registration If UPSReg.GetLicense(WebAppSettings.ShippingUPSServer) = True Then lblLicense.Text = Server.HtmlEncode(UPSReg.License) lblLicense.Text = lblLicense.Text.Replace(Chr(10), " 
") Else msg.ShowError("There was an error getting a license agreement: " & UPSReg.ErrorMessage) End If UPSReg = Nothing Catch Exx As Exception msg.ShowException(Exx) msg.Message += "There was an error loading a license agreement." End Try End If End Sub Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnCancel.Click Response.Redirect("configuration_Shipping_UPS.aspx", True) End Sub Private Sub btnAccept_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnAccept.Click Trace.Write("Starting btnAccept_OnClick") msg.Clear() If rbContactYes.Checked = False And rbContactNo.Checked = False Then msg.ShowWarning("Please select yes or no as your answer to the contact me question at the bottom of this page.") Else Try Dim UPSReg As New BVSoftware.UPS.OnlineTools.Registration UPSReg.Address1 = inAddress1.Text.Trim() If inAddress2.Text.Trim.Length() > 0 Then UPSReg.Address2 = inAddress2.Text.Trim() End If If inAddress3.Text.Trim.Length() > 0 Then UPSReg.Address3 = inAddress3.Text.Trim() End If UPSReg.City = inCity.Text.Trim() UPSReg.Company = inCompany.Text.Trim() UPSReg.Title = inTitle.Text.Trim() UPSReg.Country = inCountry.Value 'UPSReg.Country = inCountry.SelectedItem.Value UPSReg.Email = inEmail.Text.Trim() UPSReg.Name = inName.Text.Trim() UPSReg.URL = inURL.Text.Trim() UPSReg.Phone = inPhone.Text.Trim() If inCountry.Value = "US" Or inCountry.Value = "CA" Then UPSReg.State = inState.SelectedItem.Value() End If If inCountry.Value = "US" Or inCountry.Value = "CA" Then UPSReg.Zip = inZip.Text.Trim() End If If rbContactYes.Checked = True Then UPSReg.ContactMe = "yes" Else UPSReg.ContactMe = "no" End If UPSReg.AccountNumber = inUPSAccountNumber.Text.Trim() Dim sTempLicense = lblLicense.Text sTempLicense = sTempLicense.Replace(" 
", Chr(10)) sTempLicense = Server.HtmlDecode(sTempLicense) 'UPSReg.License = Server.HtmlDecode(lblLicense.Text) UPSReg.License = sTempLicense If UPSReg.AcceptLicense(WebAppSettings.ShippingUPSServer) = True Then WebAppSettings.ShippingUPSLicense = UPSReg.LicenseNumber Page.SmartNavigation = False ' Complete Registration process here... Dim tempUsername As String = "bvc2004" If Me.inPhone.Text.Trim.Length > 3 Then tempUsername += Me.inPhone.Text.Trim.Substring(inPhone.Text.Trim.Length - 4, 4) End If UPSReg.Password = BVSoftware.Utilities.PasswordGenerator.GeneratePassword() If UPSReg.Password.Length > 10 Then UPSReg.Password = UPSReg.Password.Substring(0, 10) End If Dim RegistrationComplete As Boolean = False Dim MaxRegistrationAttempts As Integer = 10 Dim CurrentAttempts As Integer = 0 While True CurrentAttempts += 1 If (RegistrationComplete = True) Or (CurrentAttempts > MaxRegistrationAttempts) Then Exit While Else UPSReg.Username = tempUsername UPSReg.RequestSuggestedUsername = True If UPSReg.Register(WebAppSettings.ShippingUPSServer) = True Then ' Got Suggested Username UPSReg.Username = UPSReg.SuggestedUsername ' Now attempt actual registration UPSReg.RequestSuggestedUsername = False If UPSReg.Register(WebAppSettings.ShippingUPSServer) = True Then WebAppSettings.ShippingUPSUsername = UPSReg.Username WebAppSettings.ShippingUPSPassword = UPSReg.Password RegistrationComplete = True Exit While End If End If UPSReg.RequestSuggestedUsername = False End If End While If RegistrationComplete = True Then Response.Redirect("Configuration_Shipping_UPS_Thanks.aspx") Else Me.msg.ShowError("The registration process could not be completed at this time. Please try again later.") End If Else msg.ShowError(UPSReg.ErrorMessage & "
ErrorCode:" & UPSReg.ErrorCode) End If Catch Ex As Exception msg.ShowException(Ex) End Try End If Trace.Write("Ending btnAccept_OnClick") End Sub Sub LoadStates() Trace.Write("Starting LoadStates") Try inState.DataSource = ContentServices.Countries.GetRegionsForCountry("en-US") inState.DataTextField = "Name" inState.DataValueField = "abbreviation" inState.DataBind() Dim li1 As ListItem = New ListItem li1.Value = "AB" li1.Text = "CANADA - Alberta" Dim li2 As ListItem = New ListItem li2.Value = "BC" li2.Text = "CANADA - British Columbia" Dim li3 As ListItem = New ListItem li3.Value = "MB" li3.Text = "CANADA - Manitoba" Dim li4 As ListItem = New ListItem li4.Value = "NB" li4.Text = "CANADA - New Brunswick" Dim li5 As ListItem = New ListItem li5.Value = "NF" li5.Text = "CANADA - Newfoundland" Dim li6 As ListItem = New ListItem li6.Value = "NT" li6.Text = "CANADA - Northwest Territories" Dim li7 As ListItem = New ListItem li7.Value = "NS" li7.Text = "CANADA - Nova Scotia" Dim li8 As ListItem = New ListItem li8.Value = "NU" li8.Text = "CANADA - Nunavut" Dim li9 As ListItem = New ListItem li9.Value = "ON" li9.Text = "CANADA - Ontario" Dim li10 As ListItem = New ListItem li10.Value = "PI" li10.Text = "CANADA - Prince Edward Island" Dim li11 As ListItem = New ListItem li11.Value = "PQ" li11.Text = "CANADA - Quebec" Dim li12 As ListItem = New ListItem li12.Value = "SK" li12.Text = "CANADA - Saskatchewan" Dim li13 As ListItem = New ListItem li13.Value = "YT" li13.Text = "CANADA - Yukon" inState.Items.Add(li1) inState.Items.Add(li2) inState.Items.Add(li3) inState.Items.Add(li4) inState.Items.Add(li5) inState.Items.Add(li6) inState.Items.Add(li7) inState.Items.Add(li8) inState.Items.Add(li9) inState.Items.Add(li10) inState.Items.Add(li11) inState.Items.Add(li12) inState.Items.Add(li13) li1 = Nothing li2 = Nothing li3 = Nothing li4 = Nothing li5 = Nothing li6 = Nothing li7 = Nothing li8 = Nothing li9 = Nothing li10 = Nothing li11 = Nothing li12 = Nothing li13 = Nothing Catch Ex As Exception msg.ShowException(Ex) End Try Trace.Write("Ending LoadStates") End Sub Sub LoadCountries() Trace.Write("Starting LoadCountries") inCountry.DataSource = ContentServices.Countries.GetAllCountries inCountry.DataTextField = "DisplayName" inCountry.DataValueField = "Code" inCountry.DataBind() Trace.Write("Ending LoadCountries") End Sub Sub SetCountry(ByVal sCode As String) Try Dim li As ListItem = New ListItem li = inCountry.Items.FindByValue(sCode) li.Selected = True li = Nothing Catch Ex As Exception Trace.Write("Couldn't Set Country: " & Ex.Message) End Try End Sub Sub SetState(ByVal sCode As String) Try Dim li As ListItem = New ListItem li = inState.Items.FindByValue(sCode) li.Selected = True li = Nothing Catch Ex As Exception Trace.Write("Couldn't Set State: " & Ex.Message) End Try End Sub End Class