Click here to Skip to main content
15,885,366 members
Articles / Programming Languages / Visual Basic

TeamVision

Rate me:
Please Sign up or sign in to vote.
3.08/5 (11 votes)
16 Nov 2009CPL3 min read 83.9K   5.4K   69  
A simple project task management application. A managed approach to help keep on top of your projects.
Imports System
Imports System.Text.RegularExpressions

Namespace Forms.Users
    Public Class FrmAdd

        Private m_ActiveUser As New Business.User

        Private m_ResourceManager As New Resources.ResourceManager("TeamVision.Localize", System.Reflection.Assembly.GetExecutingAssembly())

        Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
            If IsFormValid() Then

                With m_ActiveUser
                    .Name = txtUserName.Text.Trim()
                    .Password = txtPassword.Text ' TODO: Add Encryption here
                    .FullName = txtUserFullName.Text.Trim()
                    .Email = txtUserEmail.Text.Trim()
                    .IsAdministrator = cbAdministrator.Checked
                    .IsLocked = cbLocked.Checked
                End With

                'if we were able to add the user to the database, update our local data
                If Not UserExist(m_ActiveUser) Then
                    m_ActiveUser.UserID = UserManager.Insert(m_ActiveUser)
                    Me.DialogResult = System.Windows.Forms.DialogResult.OK
                    Me.Close()
                Else
                    MessageBox.Show(m_ResourceManager.GetString("That_user_name_is_already_taken"))
                    txtUserName.Focus()
                End If
            Else
                MessageBox.Show(m_ResourceManager.GetString("Unable_to_add_user_at_this_time"))
                Me.DialogResult = System.Windows.Forms.DialogResult.None
            End If
        End Sub

        Public Sub Databind(ByVal e As EventArgs.UserEventArgs)
            m_ActiveUser = e.User
        End Sub

        Private Function UserExist(ByVal NewUser As Business.User) As Boolean
            Dim sql As String = Columns.User.Name + "=""" + NewUser.Name + """"

            If UserManager.GetUsersWhere(sql).Count = 0 Then Return False

            Return True
        End Function

        Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
            Me.Close()
        End Sub

        Private Function IsFormValid() As Boolean
            'check the fields for valid data and
            'display message boxes if neccessary

            If txtUserName.Text.IndexOf(" ") > -1 Then
                MessageBox.Show(m_ResourceManager.GetString("User_name_may_not_contain_spaces"))
                Return False
            ElseIf txtUserName.Text.Length < 3 Then
                MessageBox.Show(m_ResourceManager.GetString("User_name_must_be_between"))
                Return False
            ElseIf txtPassword.Text.IndexOf(" ") > -1 Then
                MessageBox.Show(m_ResourceManager.GetString("Password_may_not_contain_spaces"))
                Return False
            ElseIf txtPassword.Text.Length < 3 Then
                MessageBox.Show(m_ResourceManager.GetString("Password_must_be_between"))
                Return False
            ElseIf txtPassword.Text <> txtConfirmPassword.Text Then
                MessageBox.Show(m_ResourceManager.GetString("Password_fields_do_not_match"))
                Return False
            ElseIf txtUserFullName.Text.Trim().Length < 3 Then
                MessageBox.Show(m_ResourceManager.GetString("Full_name_must_be_between"))
                Return False
            End If

            Dim r As New Regex("\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", RegexOptions.IgnoreCase)
            If Not r.IsMatch(txtUserEmail.Text) Then
                MessageBox.Show(m_ResourceManager.GetString("Email_address_is_not_valid"))
                Return False
            End If

            Return True
        End Function
    End Class
End Namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Public License Version 1.0 (CPL)


Written By
Founder Arkitech EBC Corporation
United States United States
MS, BBA, software developer, consultant, and trainer. Specializing in building data-centric applications designed for business, university, community & faith based organizations. Started developing Excel VBA macros and never looked back. Freelance developer utilizing VB.Net, SQL Server, Microsoft Access, and ASP.Net.

Comments and Discussions