' This file implements the code-behind class for ImportData.aspx. #region"Imports statements" Imports System Imports System.Data Imports System.Collections Imports System.ComponentModel Imports System.Web Imports System.Web.UI Imports System.Web.UI.WebControls Imports BaseClasses Imports BaseClasses.Utils Imports BaseClasses.Data Imports BaseClasses.Data.SqlProvider Imports BaseClasses.Web.UI.WebControls Imports Persons.Business Imports Persons.Data Imports System.Text Imports System.IO #end region Namespace Persons.UI Partial Public Class ImportData Inherits BaseApplicationPage #Region "Section 1: Place your customizations here." ' Code-behind class for the ImportData page. ' Place your customizations in Section 1. Do not modify Section 2. Private Const MAXIMUMCHAR As Integer = 100 Private Const CHARLIMIT As Integer = 2000 Private Const ENDING As String = "..." Private Const SKIPTHRESHOLD As Integer = 25 Public Sub New() MyBase.New() Me.Initialize() AddHandler Init, AddressOf Me.MyInit End Sub Public ReadOnly Property AppName() As String Get Return BaseClasses.Configuration.ApplicationSettings.Current.GetAppSetting(BaseClasses.Configuration.ApplicationSettings.ConfigurationKey.ApplicationName) End Get End Property Public ReadOnly Property TableName() As String Get Return Me.Decrypt(BaseClasses.Utils.NetUtils.GetUrlParam(Me, "TableName", True)) End Get End Property Public ReadOnly Property FilePath() As String Get Return CType(Session("FilePath"), String) End Get End Property Public Sub LoadData() ' LoadData reads database data and assigns it to UI controls. ' Customize by adding code before or after the call to LoadData_Base() ' or replace the call to LoadData_Base(). LoadData_Base() End Sub Private Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit Me.Page_PreInit_Base() End Sub _ Public Shared Function GetRecordFieldValue(ByVal tableName As String, ByVal recordID As String, ByVal columnName As String, ByVal title As String, ByVal persist As Boolean, ByVal popupWindowHeight As Integer, ByVal popupWindowWidth As Integer, ByVal popupWindowScrollBar As Boolean) As Object() ' GetRecordFieldValue gets the pop up window content from the column specified by ' columnName in the record specified by the recordID in data base table specified by tableName. ' Customize by adding code before or after the call to GetRecordFieldValue_Base() ' or replace the call to GetRecordFieldValue_Base(). Return GetRecordFieldValue_Base(tableName, recordID, columnName, title, persist, popupWindowHeight, popupWindowWidth, popupWindowScrollBar) End Function _ Public Shared Function GetImage(ByVal tableName As String, ByVal recordID As String, ByVal columnName As String, ByVal title As String, ByVal persist As Boolean, ByVal popupWindowHeight As Integer, ByVal popupWindowWidth As Integer, ByVal popupWindowScrollBar As Boolean) As Object() ' GetImage gets the Image url for the image in the column "columnName" and ' in the record specified by recordID in data base table specified by tableName. ' Customize by adding code before or after the call to GetImage_Base() ' or replace the call to GetImage_Base(). Return GetImage_Base(tableName, recordID, columnName, title, persist, popupWindowHeight, popupWindowWidth, popupWindowScrollBar) End Function Private Sub MyInit(ByVal sender As Object, ByVal e As System.EventArgs) If Not (Session("FilePath") Is Nothing) Then ' Retrieve information from session. Dim updatedRecordID As String = CType(Session("FilePath"), String) ParseCSVFile() End If Me.Page.Title = Me.GetResourceValue("Import:Step2", Me.AppName) Me.ImportFirstRowCheckBox.Checked = True Me.ImportResolveForeignKeys.Checked = True End Sub Public Sub PreviousButton_Click(ByVal sender As Object, ByVal args As EventArgs) ' Click handler for PreviousButton. ' Customize by adding code before the call or replace the call to the Base function with your own code. 'PreviousButton_Click_Base(sender, args); If (File.Exists(Me.FilePath)) Then File.Delete(Me.FilePath) End If Me.Page.Response.Redirect(("SelectFileToImport.aspx?TableName=" + Me.Encrypt(Me.TableName))) ' pass the table name as it is, without decryption. ' NOTE: If the Base function redirects to another page, any code here will not be executed. End Sub 'This is the Import button click Public Sub ImportButton_Click(ByVal sender As Object, ByVal args As EventArgs) ' Click handler for ImportButton. ' Customize by adding code before the call or replace the call to the Base function with your own code. 'ImportButton_Click_Base(sender, args); ImportButton_Click_Base(sender, args) End Sub Public Function GetTable() As BaseClasses.Data.BaseTable Try Return DatabaseObjects.GetTableObject(Me.TableName) Catch ex As System.Exception Return DatabaseObjects.GetTableObject(Me.TableName) End Try End Function #End Region #Region "Section 2: Do not modify this section." Private Sub Initialize() ' Called by the class constructor to initialize event handlers for Init and Load ' You can customize by modifying the constructor in Section 1. AddHandler Init, AddressOf Me.Page_InitializeEventHandlers AddHandler Load, AddressOf Me.Page_Load End Sub ' Handles base.Init. Registers event handler for any button, sort or links. ' You can add additional Init handlers in Section 1. Protected Overridable Sub Page_InitializeEventHandlers(ByVal sender As Object, ByVal e As System.EventArgs) ' Register the Event handler for any Events. AddHandler ImportButton.Button.Click, AddressOf Me.ImportButton_Click AddHandler PreviousButton.Button.Click, AddressOf Me.PreviousButton_Click End Sub Protected Sub Page_PreInit_Base() 'If this is multi-color theme assign proper theme Dim selectedTheme As String = Me.GetSelectedTheme() If Not String.IsNullOrEmpty(selectedTheme) Then Me.Page.Theme = selectedTheme End Sub ' Handles base.Load. Read database data and put into the UI controls. ' You can add additional Load handlers in Section 1. Protected Overridable Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) ' Check if user has access to this page. Redirects to either sign-in page ' or 'no access' page if not. Does not do anything if role-based security ' is not turned on, but you can override to add your own security. Me.Authorize(Me.GetAuthorizedRoles) ' Load data only when displaying the page for the first time If Not Me.IsPostBack Then ' Setup the header text for the validation summary control. Me.ValidationSummary1.HeaderText = GetResourceValue("ValidationSummaryHeaderText", Me.AppName) ' Show message on Click ' Read the data for all controls on the page. ' To change the behavior, override the DataBind method for the individual ' record or table UI controls. Me.LoadData() End If End Sub Public Shared Function GetRecordFieldValue_Base(ByVal tableName As String, ByVal recordID As String, ByVal columnName As String, ByVal title As String, ByVal persist As Boolean, ByVal popupWindowHeight As Integer, ByVal popupWindowWidth As Integer, ByVal popupWindowScrollBar As Boolean) As Object() Dim content As String = NetUtils.EncodeStringForHtmlDisplay(BaseClasses.Utils.MiscUtils.GetFieldData(tableName, recordID, columnName)) ' returnValue is an array of string values. ' returnValue(0) represents title of the pop up window. ' returnValue(1) represents content ie, image url. ' returnValue(2) represents whether pop up window should be made persistant ' or it should close as soon as mouse moves out. ' returnValue(3), (4) represents pop up window height and width respectivly ' returnValue(5) represents whether pop up window should contain scroll bar. ' (0),(2),(3) and (4) is initially set as pass through attribute. ' They can be modified by going to Attribute tab of the properties window of the control in aspx page. Dim returnValue() As Object = New Object((6) - 1) {} returnValue(0) = title returnValue(1) = content returnValue(2) = persist returnValue(3) = popupWindowWidth returnValue(4) = popupWindowHeight returnValue(5) = popupWindowScrollBar Return returnValue End Function Public Shared Function GetImage_Base(ByVal tableName As String, ByVal recordID As String, ByVal columnName As String, ByVal title As String, ByVal persist As Boolean, ByVal popupWindowHeight As Integer, ByVal popupWindowWidth As Integer, ByVal popupWindowScrollBar As Boolean) As Object() Dim content As String = ("\""""))))))) ' returnValue is an array of string values. ' returnValue(0) represents title of the pop up window. ' returnValue(1) represents content ie, image url. ' returnValue(2) represents whether pop up window should be made persistant ' or it should close as soon as mouse moves out. ' returnValue(3), (4) represents pop up window height and width respectivly ' returnValue(5) represents whether pop up window should contain scroll bar. ' (0),(2),(3), (4) and (5) is initially set as pass through attribute. ' They can be modified by going to Attribute tab of the properties window of the control in aspx page. Dim returnValue() As Object = New Object((6) - 1) {} returnValue(0) = title returnValue(1) = content returnValue(2) = persist returnValue(3) = popupWindowWidth returnValue(4) = popupWindowHeight returnValue(5) = popupWindowScrollBar Return returnValue End Function ' Load data from database into UI controls. ' Modify LoadData in Section 1 above to customize. Or override DataBind() in ' the individual table and record controls to customize. Public Sub LoadData_Base() Me.ImportFirstRowCheckBox.Text = GetResourceValue("Import:FirstRowText", Me.AppName) Me.ImportResolveForeignKeys.Text = GetResourceValue("Import:ResolveForeignKeys", Me.AppName) Me.DataBind() End Sub ' Write out event methods for the page events ' event handler for Button with Layout Public Sub ImportButton_Click_Base(ByVal sender As Object, ByVal args As EventArgs) Dim bt As BaseTable = Me.GetTable Dim success As Boolean = False Dim recordsImported As BaseClasses.Utils.ImportedResults = Nothing Try ' Get the column names list and importChkBox list. Dim disp As Table = CType(Me.Page.FindControl("DisplayTable"), Table) Dim cellcount As Integer = disp.Rows(0).Cells.Count Dim ddListSelected As ArrayList = New ArrayList Dim chkBoxList As ArrayList = New ArrayList Dim rc As Integer = 0 Do While (rc _ < (cellcount - 1)) Dim dd As DropDownList = CType(disp.FindControl(("dropDownList" & rc)), DropDownList) If ddListSelected.Contains(dd.SelectedValue) AndAlso dd.SelectedValue <> "" Then MiscUtils.RegisterJScriptAlert(Me, "Duplicate Column", Me.GetResourceValue("Import:DuplicateColumn", Me.AppName).Replace("{ColumnName}", dd.SelectedValue)) Return End If ddListSelected.Add(dd.SelectedValue) Dim chkBox As CheckBox = CType(disp.FindControl(("importChkBox" & rc)), CheckBox) chkBoxList.Add(chkBox) 'Store the index of the column which matches with the column name selected in the ColumnList drop down list. ' This will be used later to updated a row based on this index 'if (dd.SelectedValue == this.ColumnsList.SelectedValue) ' columnIndex = rc; rc = (rc + 1) Loop ' Validate selected columns. If Not validateColumns(ddListSelected, chkBoxList, bt) Then Return End If Dim imp As ImportDataItems = New ImportDataItems(Me.FilePath, GetFileType(), bt, ddListSelected, chkBoxList) recordsImported = imp.ImportRecords(Me.ImportFirstRowCheckBox.Checked, Me.ImportResolveForeignKeys.Checked) Catch e As Exception ScriptManager.RegisterStartupScript(Me.Page, Page.GetType, "ErrorMsg", ("alert(" _ & (BaseClasses.Web.AspxTextWriter.CreateJScriptStringLiteral(e.Message) & ");")), True) End Try If recordsImported Is Nothing Then recordsImported = New BaseClasses.Utils.ImportedResults Dim script As String = Me.ConstructScriptForSkippedRecords(recordsImported) If script.Contains("