J
jobs
Imports System.Data.SqlClient
Imports System.Data
Partial Class CreateRoute
Inherits System.Web.UI.Page
Private DATAFEED As RTEWEB.DataFeed
Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
End Sub
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
If Not IsPostBack Then
Dim up As New RTEWEB.UserProfile(Page.User.Identity)
'If Not up.IsAllowed(up.CurrentUser,
Request.AppRelativeCurrentExecutionFilePath.ToString) Then
' Response.Redirect("~/NoAccess.htm")
'End If
Else
StatusLabel.Text = Nothing
End If
End Sub
Sub GetControl(ByVal prt As Control)
For Each c As Control In prt.Controls
If c.GetType().ToString =
"System.Web.UI.WebControls.TextBox" Then
Dim tb As TextBox = c
Response.Write(tb.Text)
End If
If c.Controls.Count > 0 Then
GetControl(c)
End If
Next
End Sub
Function ValidData(ByVal whichformview As Control) As Boolean
Dim returnvalue As Boolean = True
Dim what, what2, what3, what4 As String
For Each c As Control In whichformview.Controls
what = c.ClientID
what2 = c.GetType().ToString
what3 = CType(RouteFormView.FindControl("iRouteDescr"),
TextBox).Text
what4 = CType(RouteFormView.FindControl("iRouteCode_req"),
TextBox).Text
If c.GetType().ToString =
"System.Web.UI.WebControls.TextBox" Then
If c.ClientID.Contains("_date") Then
End If
If c.ClientID.Contains("_num") Then
End If
If c.ClientID.Contains("_req") Then
If CType(c, TextBox).Text = Nothing Then
StatusLabel.Text = +c.ID + "is Required" +
vbCrLf
c.Focus()
returnvalue = False
End If
End If
End If
Next
Return returnvalue
End Function
Function ValidData2(ByVal whichformview As FormView) As Boolean
If IsPostBack Then
Dim returnvalue As Boolean = True
StatusLabel.Text = Nothing
'If Not
IsNumeric(CType(whichformview.Row.FindControl("RateTextBox"),
TextBox).Text.ToString) Then
' StatusLabel.Text = +"Invalid Rate entered" + vbCrLf
'CType(whichformview.Row.FindControl("RateTextBox"),
TextBox).Focus()
'returnvalue = False
'End If
If CType(whichformview.Row.FindControl("routecode"),
TextBox).Text = Nothing Then
StatusLabel.Text = +"Route Code is Required" + vbCrLf
CType(whichformview.Row.FindControl("RouteCodeTextBox"),
TextBox).Focus()
returnvalue = False
End If
If Not
Regex.IsMatch(CType(whichformview.Row.FindControl("StartDateTextBox"),
TextBox).Text, "^\d{1,2}/\d{1,2}/\d{4}\s\d{1,2}:\d{2}:\d{2}\s(AM|PM)$")
Then
CType(whichformview.Row.FindControl("StartDateTextBox"),
TextBox).Focus()
StatusLabel.Text = +"Start Date not in ""mm/dd/yyyy
12:00:00 AM"" Format" + vbCrLf
returnvalue = False
End If
If Not
Regex.IsMatch(CType(whichformview.Row.FindControl("EndDateTextBox"),
TextBox).Text, "^\d{1,2}/\d{1,2}/\d{4}\s\d{1,2}:\d{2}:\d{2}\s(AM|PM)$")
Then
CType(whichformview.Row.FindControl("EndDateTextBox"),
TextBox).Focus()
StatusLabel.Text = +"End Date not in ""mm/dd/yyyy
11:59:59 PM"" Format" + vbCrLf
returnvalue = False
End If
Return returnvalue
Else
Return False
End If
End Function
Function Already(ByVal vtable As String, ByVal vfield As String,
ByVal vvalue As String) As Boolean
Dim MySQL As String = "select distinct " + vfield + " from " +
vtable + " where " + vfield + " = '" + vvalue + "'"
Dim Conn As SqlConnection = New
SqlConnection(ConfigurationManager.ConnectionStrings("RTEWEBConnectionString").ConnectionString.ToString)
Dim Cmd As New SqlCommand(MySQL, Conn)
Conn.Open()
Cmd.ExecuteScalar()
If Cmd.ExecuteScalar() = 0 Then
Return True
Else
Return False
End If
Conn.Close()
End Function
Protected Sub RouteClear(ByVal sender As Object, ByVal e As
System.EventArgs)
Response.Redirect("CreateRoute.aspx")
End Sub
Protected Sub RouteInsert(ByVal sender As Object, ByVal e As
System.EventArgs)
End Sub
Protected Sub DestOninserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles
DestandRouteInsertSource.Inserting
If ValidData(RouteFormView) = True Then
If Already("Destination", "destcode",
CType(RouteFormView.Row.FindControl("RateTextBox"),
TextBox).Text.ToString) Then
StatusLabel.Text = +"Duplicate Destination Code" +
vbCrLf
e.Cancel = True
End If
Else
e.Cancel = True
End If
End Sub
Protected Sub DestOninserted(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles
DestandRouteInsertSource.Inserted
If e.Exception IsNot Nothing Then
If e.Exception.ToString.Contains("duplicate key") Then
StatusLabel.Text = "Duplicate Entry - No insert
performed"
Else
StatusLabel.Text = e.Exception.ToString.Substring(0,
250)
End If
e.ExceptionHandled = True
Else
StatusLabel.Text = "New Records Added"
End If
End Sub
End Class
Imports System.Data
Partial Class CreateRoute
Inherits System.Web.UI.Page
Private DATAFEED As RTEWEB.DataFeed
Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
End Sub
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
If Not IsPostBack Then
Dim up As New RTEWEB.UserProfile(Page.User.Identity)
'If Not up.IsAllowed(up.CurrentUser,
Request.AppRelativeCurrentExecutionFilePath.ToString) Then
' Response.Redirect("~/NoAccess.htm")
'End If
Else
StatusLabel.Text = Nothing
End If
End Sub
Sub GetControl(ByVal prt As Control)
For Each c As Control In prt.Controls
If c.GetType().ToString =
"System.Web.UI.WebControls.TextBox" Then
Dim tb As TextBox = c
Response.Write(tb.Text)
End If
If c.Controls.Count > 0 Then
GetControl(c)
End If
Next
End Sub
Function ValidData(ByVal whichformview As Control) As Boolean
Dim returnvalue As Boolean = True
Dim what, what2, what3, what4 As String
For Each c As Control In whichformview.Controls
what = c.ClientID
what2 = c.GetType().ToString
what3 = CType(RouteFormView.FindControl("iRouteDescr"),
TextBox).Text
what4 = CType(RouteFormView.FindControl("iRouteCode_req"),
TextBox).Text
If c.GetType().ToString =
"System.Web.UI.WebControls.TextBox" Then
If c.ClientID.Contains("_date") Then
End If
If c.ClientID.Contains("_num") Then
End If
If c.ClientID.Contains("_req") Then
If CType(c, TextBox).Text = Nothing Then
StatusLabel.Text = +c.ID + "is Required" +
vbCrLf
c.Focus()
returnvalue = False
End If
End If
End If
Next
Return returnvalue
End Function
Function ValidData2(ByVal whichformview As FormView) As Boolean
If IsPostBack Then
Dim returnvalue As Boolean = True
StatusLabel.Text = Nothing
'If Not
IsNumeric(CType(whichformview.Row.FindControl("RateTextBox"),
TextBox).Text.ToString) Then
' StatusLabel.Text = +"Invalid Rate entered" + vbCrLf
'CType(whichformview.Row.FindControl("RateTextBox"),
TextBox).Focus()
'returnvalue = False
'End If
If CType(whichformview.Row.FindControl("routecode"),
TextBox).Text = Nothing Then
StatusLabel.Text = +"Route Code is Required" + vbCrLf
CType(whichformview.Row.FindControl("RouteCodeTextBox"),
TextBox).Focus()
returnvalue = False
End If
If Not
Regex.IsMatch(CType(whichformview.Row.FindControl("StartDateTextBox"),
TextBox).Text, "^\d{1,2}/\d{1,2}/\d{4}\s\d{1,2}:\d{2}:\d{2}\s(AM|PM)$")
Then
CType(whichformview.Row.FindControl("StartDateTextBox"),
TextBox).Focus()
StatusLabel.Text = +"Start Date not in ""mm/dd/yyyy
12:00:00 AM"" Format" + vbCrLf
returnvalue = False
End If
If Not
Regex.IsMatch(CType(whichformview.Row.FindControl("EndDateTextBox"),
TextBox).Text, "^\d{1,2}/\d{1,2}/\d{4}\s\d{1,2}:\d{2}:\d{2}\s(AM|PM)$")
Then
CType(whichformview.Row.FindControl("EndDateTextBox"),
TextBox).Focus()
StatusLabel.Text = +"End Date not in ""mm/dd/yyyy
11:59:59 PM"" Format" + vbCrLf
returnvalue = False
End If
Return returnvalue
Else
Return False
End If
End Function
Function Already(ByVal vtable As String, ByVal vfield As String,
ByVal vvalue As String) As Boolean
Dim MySQL As String = "select distinct " + vfield + " from " +
vtable + " where " + vfield + " = '" + vvalue + "'"
Dim Conn As SqlConnection = New
SqlConnection(ConfigurationManager.ConnectionStrings("RTEWEBConnectionString").ConnectionString.ToString)
Dim Cmd As New SqlCommand(MySQL, Conn)
Conn.Open()
Cmd.ExecuteScalar()
If Cmd.ExecuteScalar() = 0 Then
Return True
Else
Return False
End If
Conn.Close()
End Function
Protected Sub RouteClear(ByVal sender As Object, ByVal e As
System.EventArgs)
Response.Redirect("CreateRoute.aspx")
End Sub
Protected Sub RouteInsert(ByVal sender As Object, ByVal e As
System.EventArgs)
End Sub
Protected Sub DestOninserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles
DestandRouteInsertSource.Inserting
If ValidData(RouteFormView) = True Then
If Already("Destination", "destcode",
CType(RouteFormView.Row.FindControl("RateTextBox"),
TextBox).Text.ToString) Then
StatusLabel.Text = +"Duplicate Destination Code" +
vbCrLf
e.Cancel = True
End If
Else
e.Cancel = True
End If
End Sub
Protected Sub DestOninserted(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles
DestandRouteInsertSource.Inserted
If e.Exception IsNot Nothing Then
If e.Exception.ToString.Contains("duplicate key") Then
StatusLabel.Text = "Duplicate Entry - No insert
performed"
Else
StatusLabel.Text = e.Exception.ToString.Substring(0,
250)
End If
e.ExceptionHandled = True
Else
StatusLabel.Text = "New Records Added"
End If
End Sub
End Class