Beruflich Dokumente
Kultur Dokumente
Excel
Imports System.Data
Imports System.Data.SqlClient
Imports DocumentFormat.OpenXml
Public Class ExcelOperations
Dim arImportErrors As ImportException() = {}
Dim arWorksheets() As CitishareWorksheetConfiguration = {}
'Local collections to store Lookup values. Collections instead of arrays so
we can reference without iteration.
Dim colRegions As New Collection
Dim colLocationTypes As New Collection
Dim colFacilityTypes As New Collection
Dim colBranchAccessibility As New Collection
Dim colBranchServices As New Collection
Dim colLanguages As New Collection
Dim colHourTypes As New Collection
Dim colOwners As New Collection
Dim colTitles As New Collection
Dim colTerminalVendorServices As New Collection
Dim colTerminalServices As New Collection
Dim colBranchIDs As New Collection
Dim colTerminalIDs As New Collection
Dim colBrandingConfigs As New Collection
Public Enum ExportDatasetTable
WorksheetNames = 0
Branches = 1
End Enum
Public ReadOnly Property ImportErrors As ImportException()
Get
Return arImportErrors
End Get
End Property
''' <summary>
''' This sub will generate an excel workbook containing the specified group'
s data and output it using a naming convention.
''' </summary>
''' <param name="GroupID"></param>
''' <param name="CN"></param>
''' <remarks></remarks>
Public Sub GenerateExcelTemplate(ByVal GroupID As Integer, ByVal CN As SqlCo
nnection, FileName As String)
'Get the data into a dataset to represent the exportable group data....
Dim sda As SqlDataAdapter = Nothing
Dim strCurrentWorksheetName As String = ""
Try
sda = New SqlDataAdapter("", CN)
sda.SelectCommand.CommandText = "mgmt.ExportTemplate"
sda.SelectCommand.CommandType = CommandType.StoredProcedure
sda.SelectCommand.Parameters.Clear()
sda.SelectCommand.Parameters.AddWithValue("GroupID", GroupID)
Dim dsExportData As New DataSet
sda.Fill(dsExportData)
Dim objExcelWorkbook As New Infragistics.Excel.Workbook(WorkbookForm
at.Excel97To2003)
objExcelWorkbook.CellReferenceMode = CellReferenceMode.R1C1 'Set the
reference mode to Row/Column rather than alpha to more closely align to dataset
s/tables
Dim intTableCounter As Integer = 1 'Start at 1 since index 0 is the
sheet name records
Dim colIgnoreColumns As New Specialized.StringCollection
colIgnoreColumns.Add("group_id")
If dsExportData.Tables.Count <> dsExportData.Tables(ExportDatasetTab
le.WorksheetNames).Rows.Count + 1 Then
Throw New Exception("The number of worksheets expected [" & dsEx
portData.Tables(ExportDatasetTable.WorksheetNames).Rows.Count + 1 & "] does not
match the number of datasets returned [" & dsExportData.Tables.Count & "]")
End If
'The first datatable should represent the names we would like the wo
rksheets to be. They should be in the order of the worksheets to come.
For Each drWorksheetName As DataRow In dsExportData.Tables(ExportDat
asetTable.WorksheetNames).Rows
'Create new worksheet
strCurrentWorksheetName = drWorksheetName("worksheet_name").ToSt
ring()
Dim objCurrentWorksheet As Worksheet = objExcelWorkbook.Workshee
ts.Add(drWorksheetName("worksheet_name").ToString())
Dim objWorksheetConfig As New CitishareWorksheetConfiguration(dr
WorksheetName("worksheet_name").ToString(), CN)
objCurrentWorksheet.Protected = True
'Populate the worksheet
'The index of the data table we are interested in should be + 1
from the current worksheet record
Dim dtCurrentTable As DataTable = dsExportData.Tables(intTableCo
unter)
Dim intColumnCounter As Integer = 0
Dim intRowCounter As Integer = 0
'First write out all the column headings
For Each colExportColumn As CitishareWorksheetConfiguration.Citi
shareWorksheetColumn In objWorksheetConfig.Columns
If colExportColumn.ExportColumn Then
If colExportColumn.HyperlinkAddress <> "" Then
'We are adding a column header that has a hyperlink
objCurrentWorksheet.Rows
(intRowCounter).Cells(intColumnCounter).ApplyFormula("=HYPERLINK(""#"" & CELL(""
address"", " & colExportColumn.HyperlinkAddress & "),""" & colExportColumn.Expor
tColumnName & """)")
objCurrentWorksheet.Rows(intRowCounter).Cells(intCol
umnCounter).CellFormat.Font.Color = System.Drawing.Color.Blue
'We will tag the comment with the column name for va
lidation later. We have to do this since hyperlinks lose their value...
objCurrentWorksheet.Rows(intRowCounter).Cells(intCol
umnCounter).Comment = New WorksheetCellComment()
objCurrentWorksheet.Rows(intRowCounter).Cells(intCol
umnCounter).Comment.Text.UnformattedString = colExportColumn.ExportColumnName
Else
objCurrentWorksheet.Rows(intRowCounter).Cells(intCol
umnCounter).Value = colExportColumn.ExportColumnName
End If
If colExportColumn.ColumnFormat <> "" Then
objCurrentWorksheet.Columns(intColumnCounter).CellFo
rmat.FormatString = colExportColumn.ColumnFormat
End If
If colExportColumn.ColumnIsReadonly = ExcelDefaultableBo
olean.True Then
objCurrentWorksheet.Columns(intColumnCounter).CellFo
rmat.FillPatternForegroundColor = Drawing.Color.LightGray
End If
objCurrentWorksheet.Rows(intRowCounter).Cells(intColumnC
ounter).CellFormat.Font.Bold = ExcelDefaultableBoolean.True
objCurrentWorksheet.Columns(intColumnCounter).Width = co
lExportColumn.ColumnWidth
intColumnCounter += 1
End If
Next
'Now write all the data out.
intRowCounter = 0
For Each drDataRecord As DataRow In dtCurrentTable.Rows
intRowCounter += 1
intColumnCounter = 0
For Each colExportColumn As CitishareWorksheetConfiguration.
CitishareWorksheetColumn In objWorksheetConfig.Columns
If colExportColumn.ExportColumn Then
'Determine the type. We may need to map from SQL to
Excel
Select Case drDataRecord(colExportColumn.DatasourceC
olumnName).GetType.Name.ToLower()
Case "timespan"
'No comp
atible datatype in Excel for TimeSpan
Dim strT
imeValue As String = drDataRecord(colExportColumn.DatasourceColumnName).ToString
()
Try
If strTimeValue <> "" Then
If IsDate(strTimeValue) Then
strTimeValue = String.Format("{0:hh:mm tt}", CDate(strTimeValue))
End If
End If
Catch ex
As Exception
'Swallow error. Fall back on value
End Try
objCurre
ntWorksheet.Rows(intRowCounter).Cells(intColumnCounter).Value = strTimeValue
Case Else
objCurrentWorksheet.Rows(intRowCounter).Cell
s(intColumnCounter).Value = drDataRecord(colExportColumn.DatasourceColumnName)
End Select
If colExportColumn.ColumnIsReadonly = ExcelDefaultab
leBoolean.True Then
'WE lock all cells instead of columns so users c
an add additional records if they like.
objCurrentWorksheet.Rows(intRowCounter).Cells(in
tColumnCounter).CellFormat.Locked = colExportColumn.ColumnIsReadonly
End If
intColumnCounter += 1
End If
Next
Next
'Since we have protected the worksheet, we need to unlock rows t
o allow for additional records to be created.
'We will unlock 1000 rows over whatever we exported
For intUnlockCounter As Integer = (intRowCounter + 1) To (intRow
Counter + 1000)
objCurrentWorksheet.Rows(intUnlockCounter).CellFormat.Locked
= ExcelDefaultableBoolean.False
Next
'Lock the first column and row
objCurrentWorksheet.DisplayOptions.PanesAreFrozen = True
If objWorksheetConfig.NumberOfFrozenColumns > 0 Then
objCurrentWorksheet.DisplayOptions.FrozenPaneSettings.Frozen
Columns = objWorksheetConfig.NumberOfFrozenColumns
End If
objCurrentWorksheet.DisplayOptions.FrozenPaneSettings.FrozenRows
= 1
intTableCounter += 1
Next
objExcelWorkbook.Save(FileName)
Catch ex As Exception
My.Application.Log.WriteException(ex, Diagnostics.TraceEventType.Err
or, "An error occurred in GenerateExcelTemplate(); Worksheet: [" & strCurrentWor
ksheetName & "]" & vbCrLf & ex.StackTrace.ToString())
Throw ex
Finally
sda.Dispose()
End Try
End Sub
''' <summary>
''' This sub will open an excel workbook, expecting it to be setup as a temp
late generated above.
''' It will validate the schema, and then validate the data to be loaded.
''' Depending on the group's configuration, the data will be loaded into sta
ging or directly into production
''' </summary>
''' <param name="UserID"></param>
''' <param name="CN"></param>
''' <remarks></remarks>
Return intCounter
End If
intCounter += 1
Next
Return -1
End Function
Private Sub FillCollection(colCollection As Collection, strCommand As String
, CMD As SqlCommand)
Dim dtTemp As New DataTable
Dim sda As New SqlDataAdapter(CMD)
sda.SelectCommand.CommandType = CommandType.Text
sda.SelectCommand.CommandText = strCommand
sda.SelectCommand.Parameters.Clear()
sda.Fill(dtTemp)
For Each drRow As DataRow In dtTemp.Rows
colCollection.Add(drRow(0), drRow(0))
Next
sda.Dispose()
dtTemp.Dispose()
End Sub
Public Function GetValue(CurrentRow As WorksheetRow, CurrentColumn As Ci
tishareWorksheetConfiguration.CitishareWorksheetColumn, CurrentWorksheet As Citi
shareWorksheetConfiguration) As Object
Select Case CurrentColumn.ColumnDataType.ToUpper()
Case "TIME"
'TODO: Return a timespan object
Dim tmpTime As String = CurrentRow.Cells(Current
Column.ColumnIndex).Value
If IsNothing(tmpTime) Then
Return DBNull.Value
Else
'Determine if we can parse a date from t
his...
Dim dtTempDate As DateTime = Nothing
If DateTime.TryParse(tmpTime, dtTempDate
) = True Then
Return dtTempDate.TimeOfDay
End If
'It is possible we have an excel date as
well. If we make it here. try and parse excel date
Try
dtTempDate = Date.FromOADate(Cur
rentRow.Cells(CurrentColumn.ColumnIndex).Value)
Return dtTempDate.TimeOfDay
Catch ex As Exception
Me.AddException(New ImportExcept
ion("Could not parse a proper date/time from the value [" & CurrentRow.Cells(Cur
rentColumn.ColumnIndex).Value & "]", CurrentWorksheet, CurrentColumn, CurrentRow
.Index))
Return DBNull.Value
End Try
End If
'Return IIf(IsNothing(CurrentRow.Cells(CurrentCo
lumn.ColumnIndex).Value), DBNull.Value, .TimeOfDay.ToString())
Case "DATE"
If IsNothing(CurrentRow.Cells(CurrentColumn.Colu
mnIndex).Value) Then
Return DBNull.Value
End If
'We need to make sure we get a proper date value
. Excel may store the date as a serial/numeric format...
If IsDate(CurrentRow.Cells(CurrentColumn.ColumnI
ndex).Value) Then
Return Date.Parse(CurrentRow.Cells(Curre
ntColumn.ColumnIndex).Value)
Else
If IsDate(Date.FromOADate(CurrentRow.Cel
ls(CurrentColumn.ColumnIndex).Value)) Then
'We double check that the date p
assed from Excel is not a serial date. If it is, FromOADate should return a vali
d date.
Return Date.FromOADate(CurrentRo
w.Cells(CurrentColumn.ColumnIndex).Value)
End If
End If
Case "BOOLEAN"
'We handle bools in the TrueOrFalse function. An
ything "invalid" is treated as false
If IsNothing(CurrentRow.Cells(CurrentColumn.Colu
mnIndex).Value) Then
Return False
Else
Return TrueOrFalse(CurrentRow.Cells(Curr
entColumn.ColumnIndex).Value)
End If
Case Else
If IsNothing(CurrentRow.Cells(CurrentColumn.Colu
mnIndex).Value) Then
Return DBNull.Value
Else
Return CurrentRow.Cells(CurrentColumn.Co
lumnIndex).Value.ToString()
End If
End Select
'SHOULD NEVER GET HERE!
Return ""
End Function
Public Function ValidateWorkbookSchema(objExcelWorkbook As Workbook) As Bool
ean
Dim bSchemaValid = True
'Now that we have all the worksheets in an array, make sure all the actu
al worksheets and columns required exist in the template provided.
For Each objWorksheet As CitishareWorksheetConfiguration In arWorksheets
Try
If WorksheetExists(objWorksheet.WorksheetName, objExcelWorkbook)
= False Then
'We are missing a worksheet
Throw New ImportException("Worksheet [" & objWorksheet.Works
heetName & "] is missing.", objWorksheet)
Else
Dim tmpUploadedWorksheet As Worksheet = objExcelWorkbook.Wor
ksheets(objWorksheet.WorksheetName)
End If
End If
Next
Next
End If
Next
Return bValid
End Function
Private Function ValueIsValid(strValue As String, objColumn As CitishareWork
sheetConfiguration.CitishareWorksheetColumn) As Boolean
Select Case objColumn.ExportColumnName.ToUpper()
Case "ACCESSIBILITY_ID", "ACCESSIBILITY ID", "SURCHARGE FREE FOR"
Return colBranchAccessibility.Contains(strValue)
Case "REGION ID"
Return colRegions.Contains(strValue)
Case "SERVICE ID", "BRANCH SERVICE ID"
Return colBranchServices.Contains(strValue)
Case "LANGUAGE ID"
Return colLanguages.Contains(strValue)
Case "HOUR TYPE"
Return colHourTypes.Contains(strValue)
Case "TITLE ID"
Return colTitles.Contains(strValue)
Case "SERVICE 1 ID", "SERVICE 2 ID", "SERVICE 3 ID"
Return colTerminalVendorServices.Contains(strValue)
Case "TERMINAL SERVICE ID"
Return colTerminalServices.Contains(strValue)
Case "LOCATION ID"
Return colBranchIDs.Contains(strValue)
Case "TERMINAL ID"
Return colTerminalIDs.Contains(strValue)
Case "LOCATION TYPE ID"
Return colLocationTypes.Contains(strValue)
Case "FACILITY TYPE ID"
Return colFacilityTypes.Contains(strValue)
Case "BRANDING CONFIG ID"
Return colBrandingConfigs.Contains(strValue)
Case "OWNER ID"
Return colOwners.Contains(strValue)
Case "PHONE", "FAX", "INVESTMENT PHONE", "BRANCH OPEN PH
ONE", "BRANCH CLOSE PHONE", "EMERGENCY PHONE"
'Make sure that the phone is valid...
If strValue.Trim(" ").Length = 0 Then
Return True
Else
Return Text.RegularExpressions.Regex.IsMatch(strValue, "^[\d
]{10,15}$")
End If
Case "AIRPORT CODE"
Return Text.RegularExpressions.Regex.IsMatch(str
Value, "^[a-zA-Z]{3}$")
Case Else
Return True
End Select
End Function
Private Function DatatypeIsValid(strDataType As String, strDataToCheck As St
ring) As Boolean
Dim bReturn As Boolean = True
Select Case strDataType.ToUpper()
Case "STRING"
bReturn = True
Case "INTEGER"
If Not IsNumeric(strDataToCheck) Then
bReturn = False
End If
Case "DATE"
If Not IsDate(strDataToCheck) Then
If Not IsDate(Date.FromOADate(strDataToCheck)) Then
'We double check that the date passed from Excel is not
a serial date. If it is, FromOADate should return a valid date.
bReturn = False
End If
End If
Case "TIME"
'TODO: make sure value is actually a time
bReturn = True
Case "BOOLEAN"
'We handle bools in the TrueOrFalse function. Anything "invalid"
is treated as false
bReturn = True
Case Else
'Do we care???
bReturn = True
End Select
Return bReturn
End Function
Public Function LoadData(CMD As SqlCommand, GroupID As Integer, UploadID As
Integer, UserID As Integer) As Boolean
'Load all the data into the database
'At this point we will start a new transaction, if we encounter any erro
rs, we will rollback, otherwise once we make it through we will commit the data.
Dim trnsLoad As SqlTransaction = CMD.Connection.BeginTransaction(System.
Data.IsolationLevel.Snapshot)
CMD.Transaction = trnsLoad
Try
If CMD.Connection.State <> ConnectionState.Open Then
CMD.Connection.Open()
End If
'First wipe all the information in the database for the group ID pas
sed.
'Depending on the groups configuration, this may be wiped from Stagi
ng or Production
CMD.CommandType = CommandType.StoredProcedure
CMD.CommandText = "mgmt.ClearGroupInformationForUpload"
CMD.Parameters.Clear()
CMD.Parameters.AddWithValue("GroupID", GroupID)
CMD.Parameters.AddWithValue("UploadID", UploadID)
CMD.ExecuteNonQuery()
Dim intRowCounter As Integer = 1
For Each objWorksheet As CitishareWorksheetConfiguration In arWorksh
eets
If objWorksheet.WorksheetUploadCommand.ToString() <> "" Then
intRowCounter = 1
CMD.CommandType = CommandType.StoredProcedure
CMD.CommandText = objWorksheet.WorksheetUploadCommand
For Each objRow As WorksheetRow In objWorksheet.WorksheetObj
ect.Rows
'Loop through ALL branches and get all the values we nee
d to add to the SP
'Clear the parameters
CMD.Parameters.Clear()
If intRowCounter > 1 Then
'We skip the first row for headings..
If Not IsNothing(objRow.Cells(0).Value) AndAlso objR
ow.Cells(0).Value.ToString() <> "" Then
If objWorksheet.UploadRequiresRevisionID Then
CMD.Parameters.AddWithValue("RevisionID", DB
Null.Value) 'WE PASS NULL TO INDICATE THAT THE STORED PROC SHOULD LOOKUP THE REV
ISION ID
End If
If objWorksheet.UploadRequiresUserID Then
CMD.Parameters.AddWithValue("UserID", UserID
)
End If
For Each objColumn As CitishareWorksheetConfigur
ation.CitishareWorksheetColumn In objWorksheet.Columns
If objColumn.UploadParameterName <> "" Then
'Add the parameters
CMD.Parameters.AddWithValue(objColumn.UploadParameterName, GetValue(objRow, objC
olumn, objWorksheet))
End If
Next
CMD.ExecuteNonQuery()
Else
Exit For
End If
End If
intRowCounter += 1
Next
End If
Next
'Now we want to merge back in our backed up geocoding in
formation
CMD.CommandType = CommandType.StoredProcedure
CMD.CommandText = "mgmt.MergeGeocodeInformation"
CMD.Parameters.Clear()
CMD.Parameters.AddWithValue("GroupID", GroupID)
CMD.Parameters.AddWithValue("UploadID", UploadID)
CMD.ExecuteNonQuery()
'If we make it this far, commit the transaction
CMD.Transaction.Commit()
Catch ex As Exception
My.Application.Log.WriteException(ex, TraceEventType.Error, "An erro
r occurred when loading data for Group ID: [" & GroupID & "]" & vbCrLf & ex.Stac
kTrace)
Try
CMD.Transaction.Rollback()
Catch exRollback As Exception
My.Application.Log.WriteException(exRollback, TraceEventType.Err
or, "An error occurred when rolling back the transaction! Manual intervention ma
y be needed! Group ID: [" & GroupID & "]" & vbCrLf & exRollback.StackTrace)
End Try
Return False
Finally
CMD.Dispose()
End Try
Return True
End Function
''' <summary>
''' We will treat 'T', 'Y', 'TRUE' as true. Anything else is false
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Private Function TrueOrFalse(strValue As String) As Boolean
If Trim(strValue).ToUpper() = "T" Or Trim(strValue).ToUpper() = "TRUE" O
r Trim(strValue).ToUpper() = "Y" Then
Return True
Else
Return False
End If
End Function
Private Sub AddException(objException As Exception)
Array.Resize(arImportErrors, arImportErrors.Length + 1)
arImportErrors(arImportErrors.Length - 1) = objException
End Sub
Public Function WorksheetExists(WorksheetName As String, Workbook As Workboo
k) As Boolean
For Each Worksheet In Workbook.Worksheets
If Worksheet.Name.ToUpper() = WorksheetName.ToUpper() Then
Return True
End If
Next
Return False
End Function
Public Class CitishareWorksheetConfiguration
Dim _CurrentWorksheetName As String = ""
Dim _colColumns As New Collection
Dim _intNumberOfFrozenColumns As Integer = 0
Dim _bWorksheetEditable As Boolean = False
Dim _objWorksheet As Worksheet = Nothing
Dim _strWorksheetUploadCommand As String = ""
Dim _bUploadRequiresUserID As Boolean = True
Dim _bUploadRequiresRevisionID As Boolean = True
Public Class CitishareWorksheetColumn
Get
Return _strColumnDataType
End Get
End Property
Public Property HyperlinkAddress As String
Get
Return _strHyperlinkAddress
End Get
Set(value As String)
'=HYPERLINK("#" &CELL("address", 'Sheet3'!R1),"Test")
_strHyperlinkAddress = value
End Set
End Property
Public Property ColumnWidth As Integer
Get
Return _intColumnWidth
End Get
Set(value As Integer)
_intColumnWidth = value
End Set
End Property
Public ReadOnly Property ColumnIndex As Integer
Get
Return _intColumnIndex
End Get
End Property
Public ReadOnly Property ColumnHidden As Boolean
Get
Return _bColumnHidden
End Get
End Property
Public ReadOnly Property DataRequiredInColumn As Boolean
Get
Return _bDataRequired
End Get
End Property
Public ReadOnly Property UploadParameterName As String
Get
Return _strUploadParameterName
End Get
End Property
Public Sub New(ColumnIndex As Integer, ColumnDataType As String, Dat
aRequired As Boolean, ByVal DatasourceColumnName As String, ByVal ExportColumnNa
me As String, ByVal ColumnIsReadonly As ExcelDefaultableBoolean, ColumnWidth As
Integer, Optional HyperlinkAddress As String = "", Optional ByVal ExportColumn A
s Boolean = True, Optional ColumnFormat As String = "", Optional UploadParameter
Name As String = "")
_intColumnIndex = ColumnIndex
_DatasourceColumnName = DatasourceColumnName
_ExportColumnName = ExportColumnName
_ColumnReadonly = ColumnIsReadonly
_ExportColumn = ExportColumn
_intColumnWidth = ColumnWidth
_strHyperlinkAddress = HyperlinkAddress
_strColumnFormat = ColumnFormat
_strColumnDataType = ColumnDataType
_bDataRequired = DataRequired
_strUploadParameterName = UploadParameterName
End Sub
End Class
Public Property WorksheetObject As Worksheet
Get
Return _objWorksheet
End Get
Set(value As Worksheet)
_objWorksheet = value
End Set
End Property
Public ReadOnly Property NumberOfFrozenColumns As Integer
Get
Return _intNumberOfFrozenColumns
End Get
End Property
Public ReadOnly Property WorksheetName As String
Get
Return _CurrentWorksheetName
End Get
End Property
Public ReadOnly Property Columns As Collection
Get
Return _colColumns
End Get
End Property
Public ReadOnly Property WorksheetEditable As Boolean
Get
Return _bWorksheetEditable
End Get
End Property
Public ReadOnly Property UploadRequiresUserID As Boolean
Get
Return _bUploadRequiresUserID
End Get
End Property
Public ReadOnly Property UploadRequiresRevisionID As Boolean
Get
Return _bUploadRequiresRevisionID
End Get
End Property
Public ReadOnly Property WorksheetUploadCommand As String
Get
Return _strWorksheetUploadCommand
End Get
End Property
Public Sub New(ByVal strWorksheetName As String, ByVal CN As SqlConnecti
on)
_CurrentWorksheetName = strWorksheetName
Dim sda As New SqlDataAdapter("", CN)
Dim dtColumnDefinitions As New DataTable
sda.SelectCommand.CommandType = CommandType.StoredProcedure
sda.SelectCommand.CommandText = "mgmt.GetWorksheetConfiguration"
sda.SelectCommand.Parameters.Clear()
sda.SelectCommand.Parameters.AddWithValue("WorksheetName", strWorksh
eetName)
Dim parNumberOfFrozenColumns As New SqlParameter("NumberOfFrozenColu
mns", 0)
parNumberOfFrozenColumns.Size = 10
parNumberOfFrozenColumns.Direction = ParameterDirection.Output
sda.SelectCommand.Parameters.Add(parNumberOfFrozenColumns)
Dim parEditable As New SqlParameter("WorksheetEditable", False)
parEditable.Size = 10
parEditable.Direction = ParameterDirection.Output
sda.SelectCommand.Parameters.Add(parEditable)
Dim parWorksheetUploadCommand As New SqlParameter("WorksheetUploadCo
mmand", "")
parWorksheetUploadCommand.Size = 200
parWorksheetUploadCommand.Direction = ParameterDirection.Output
sda.SelectCommand.Parameters.Add(parWorksheetUploadCommand)
Dim parUploadRequiresUserID As New SqlParameter("UploadRequiresUserI
D", False)
parUploadRequiresUserID.Size = 10
parUploadRequiresUserID.Direction = ParameterDirection.Output
sda.SelectCommand.Parameters.Add(parUploadRequiresUserID)
Dim parUploadRequiresRevisionID As New SqlParameter("UploadRequiresR
evisionID", False)
parUploadRequiresRevisionID.Size = 10
parUploadRequiresRevisionID.Direction = ParameterDirection.Output
sda.SelectCommand.Parameters.Add(parUploadRequiresRevisionID)
sda.Fill(dtColumnDefinitions)
_intNumberOfFrozenColumns = parNumberOfFrozenColumns.Value
_bWorksheetEditable = CBool(parEditable.Value)
_strWorksheetUploadCommand = parWorksheetUploadCommand.Value.ToStrin
g()
_bUploadRequiresUserID = parUploadRequiresUserID.Value
_bUploadRequiresRevisionID = parUploadRequiresRevisionID.Value
Dim intExportedColumnIndex As Integer = 0
Dim intTmpColumnIndex As Integer = -1
For Each drColumn As DataRow In dtColumnDefinitions.Rows
If CBool(drColumn("output_to_excel")) = True Then
intTmpColumnIndex = intExportedColumnIndex
intExportedColumnIndex += 1
Else
intTmpColumnIndex = -1
End If
Me.Columns.Add(New CitishareWorksheetColumn(intTmpColumnIndex, d
rColumn("column_datatype"), drColumn("data_required"), drColumn("datasource_colu
mnname"), drColumn("export_columnname"), IIf(CBool(drColumn("allow_excel_edit"))