You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
8.3 KiB

Imports Telerik.Web.UI
Imports System.Web.Configuration
Public Class Firmenansprechpartner
Inherits System.Web.UI.UserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim DH As New clsDatahandling
If UCase(DH.Get_Option(10)) = "JA" And Session("Admin") <> "True" Then
RadButton1.Visible = False
RadButton2.Visible = False
RadButton1.Enabled = False
RadButton2.Enabled = False
Me.RadGrid1.Enabled = False
End If
End Sub
Protected Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
Response.Redirect("~/Firmen/Firmendaten1.aspx?Tab=1")
End Sub
Protected Sub RadButton2_Click(sender As Object, e As EventArgs) Handles RadButton2.Click
Response.Redirect("~/Firmen/Firmendaten1.aspx?Tab=3")
End Sub
Private Sub RadGrid1_InsertCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand
Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
Dim editMan As GridEditManager = editedItem.EditManager
Dim haserror As Boolean = False
Dim column As GridColumn
Dim i As Integer = 0
For Each column In e.Item.OwnerTableView.Columns
If TypeOf column Is IGridEditableColumn Then
Dim editableCol As IGridEditableColumn = CType(column, IGridEditableColumn)
If (editableCol.IsEditable) Then
Dim editor As IGridColumnEditor = editMan.GetColumnEditor(editableCol)
Dim editorType As String = CType(editor, Object).ToString()
Dim editorText As String = "unknown"
Dim editorValue As Object = Nothing
If (TypeOf editor Is GridTextColumnEditor) Then
editorText = CType(editor, GridTextColumnEditor).Text
editorValue = CType(editor, GridTextColumnEditor).Text
If editorText.Trim = "" Then haserror = True
End If
i = i + 1
If i = 5 Then
If Verify_Mail(editorText).ToString = False Then
Show_Message(1, "Die eingegebene E-Mail-Adresse ist ungültig.")
e.Canceled = True
Return
End If
End If
If (TypeOf editor Is GridBoolColumnEditor) Then
editorText = CType(editor, GridBoolColumnEditor).Value.ToString()
editorValue = CType(editor, GridBoolColumnEditor).Value
End If
If (TypeOf editor Is GridDropDownColumnEditor) Then
editorText = CType(editor, GridDropDownColumnEditor).SelectedText & "; " & CType(editor, GridDropDownColumnEditor).SelectedValue
editorValue = CType(editor, GridDropDownColumnEditor).SelectedValue
End If
If (TypeOf editor Is GridDateTimeColumnEditor) Then
editorText = CType(editor, GridDateTimeColumnEditor).Text
editorValue = CType(editor, GridDateTimeColumnEditor).Text
End If
'Try
' Dim changedRows As DataRow() = Me.EmployeesData.Tables("Employees").Select("EmployeeID = " & editedItem.OwnerTableView.DataKeyValues(editedItem.ItemIndex)("EmployeeID"))
' changedRows(0)(column.UniqueName) = editorValue
' Me.EmployeesData.Tables("Employees").AcceptChanges()
'Catch ex As Exception
' RadGrid1.Controls.Add(New LiteralControl("<strong>Unable to set value of column '" & column.UniqueName & "'</strong> - " + ex.Message))
' e.Canceled = True
'End Try
End If
End If
Next
If haserror Then
Show_Message(1, "Daten können nicht gespeichert werden. Es sind zwinged alle Felder zu befüllen.")
e.Canceled = True
End If
End Sub
Private Sub RadGrid1_UpdateCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand
Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
Dim editMan As GridEditManager = editedItem.EditManager
Dim haserror As Boolean = False
Dim column As GridColumn
Dim i As Integer = 0
For Each column In e.Item.OwnerTableView.Columns
If TypeOf column Is IGridEditableColumn Then
Dim editableCol As IGridEditableColumn = CType(column, IGridEditableColumn)
If (editableCol.IsEditable) Then
Dim editor As IGridColumnEditor = editMan.GetColumnEditor(editableCol)
Dim editorType As String = CType(editor, Object).ToString()
Dim editorText As String = "unknown"
Dim editorValue As Object = Nothing
If (TypeOf editor Is GridTextColumnEditor) Then
editorText = CType(editor, GridTextColumnEditor).Text
editorValue = CType(editor, GridTextColumnEditor).Text
If editorText.Trim = "" Then haserror = True
End If
i = i + 1
If i = 5 Then
If Verify_Mail(editorText).ToString = False Then
Show_Message(1, "Die eingegebene E-Mail-Adresse ist ungültig.")
e.Canceled = True
Return
End If
End If
If (TypeOf editor Is GridBoolColumnEditor) Then
editorText = CType(editor, GridBoolColumnEditor).Value.ToString()
editorValue = CType(editor, GridBoolColumnEditor).Value
End If
If (TypeOf editor Is GridDropDownColumnEditor) Then
editorText = CType(editor, GridDropDownColumnEditor).SelectedText & "; " & CType(editor, GridDropDownColumnEditor).SelectedValue
editorValue = CType(editor, GridDropDownColumnEditor).SelectedValue
End If
If (TypeOf editor Is GridDateTimeColumnEditor) Then
editorText = CType(editor, GridDateTimeColumnEditor).Text
editorValue = CType(editor, GridDateTimeColumnEditor).Text
End If
'Try
' Dim changedRows As DataRow() = Me.EmployeesData.Tables("Employees").Select("EmployeeID = " & editedItem.OwnerTableView.DataKeyValues(editedItem.ItemIndex)("EmployeeID"))
' changedRows(0)(column.UniqueName) = editorValue
' Me.EmployeesData.Tables("Employees").AcceptChanges()
'Catch ex As Exception
' RadGrid1.Controls.Add(New LiteralControl("<strong>Unable to set value of column '" & column.UniqueName & "'</strong> - " + ex.Message))
' e.Canceled = True
'End Try
End If
End If
Next
If haserror Then
Show_Message(1, "Daten können nicht gespeichert werden. Es sind zwinged alle Felder zu befüllen.")
e.Canceled = True
End If
End Sub
Protected Sub Show_Message(ByVal type As Integer, ByVal meldung As String)
Dim image1 As String
Select Case type
Case 1
image1 = WebConfigurationManager.AppSettings("Imagepath") + "Error.png"
Case 2
image1 = WebConfigurationManager.AppSettings("Imagepath") + "Info1.png"
End Select
RadWindowManager1.RadAlert(meldung, 330, 100, "Fehler", "alertCallBackFnError", image1)
End Sub
Protected Function Verify_Mail(ByVal mail As String) As Boolean
Dim Expression As New System.Text.RegularExpressions.Regex("\S+@\S+\.\S+")
' If the email matches the regular expression
If Expression.IsMatch(mail) Then
Return True
Else
Return False
End If
End Function
End Class