Click here to Skip to main content
15,891,874 members
Articles / Programming Languages / C#

AccountPlus

Rate me:
Please Sign up or sign in to vote.
4.47/5 (63 votes)
10 Sep 2009LGPL320 min read 241.6K   61.8K   209  
A Complete Account Management System
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using AccountPlus.BusinessLogic;
using AccountPlus.Messaging;
using AccountPlus.Formatting;
using System.Collections;



namespace AccountPlus.UI
{
    public partial class NewUser : AccountPlusBase
    {
        
        public NewUser()
        {          
            InitializeComponent();
            (new Arch()).FillDataInCombo(cmbRole, Arch.ComboBoxItem.Role);
            cmbRole.SelectedIndex = 0;
            GetData(-1, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty);
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            AddUpdateUser();
        }

        private void AddUpdateUser()
        {
            errorProvider1.Clear();
            lblMessage.Clear();
            Users user = new Users();
            string userName = txtUserId.Text.Trim();
            string password = txtPassword.Text.Trim();
            string confirmPassword = txtConfirmPassword.Text.Trim();
            string firstName = txtFirstName.Text.Trim();
            string lastName = txtLastName.Text.Trim();
            string email = txtEmail.Text.Trim();
            string mobile = txtMobile.Text.Trim();
            int roleId = DataFormat.GetInteger(((DictionaryEntry)(cmbRole.SelectedItem)).Key);

            string message = string.Empty;

            if (SessionParameters.UserRole != Common.UserRole.Admin)
            {
                lblMessage.SetMessage(MessageManager.GetMessage("4"));
                return;
            }

            if (roleId == -1)
            {
                message = MessageManager.GetMessage("19");
                errorProvider1.SetError(cmbRole, message);
                lblMessage.SetMessage(message);
                return;
            }

            if (userName == string.Empty)
            {
                message = MessageManager.GetMessage("20");
                errorProvider1.SetError(txtUserId, message);
                lblMessage.SetMessage(message);
                return;
            }
            else
            {
                if (!txtUserId.ReadOnly) 
                    if (user.CheckUserExist(userName))
                    {
                        message = MessageManager.GetMessage("27", userName);
                        errorProvider1.SetError(txtUserId, message);                    
                        return;
                    }                
            }

            if (password == string.Empty)
            {
                message = MessageManager.GetMessage("21");
                errorProvider1.SetError(txtPassword, message);
                lblMessage.SetMessage(message);
                return;
            }

            if (confirmPassword == string.Empty)
            {
                message = MessageManager.GetMessage("22");
                errorProvider1.SetError(txtConfirmPassword, message);
                lblMessage.SetMessage(message);
                return;
            }

            if (firstName == string.Empty)
            {
                message = MessageManager.GetMessage("23");
                errorProvider1.SetError(txtFirstName, message);
                lblMessage.SetMessage(message);
                return;
            }

            if (string.Compare(password, confirmPassword, true) != 0)
            {
                message = MessageManager.GetMessage("24");
                errorProvider1.SetError(txtPassword, message);
                errorProvider1.SetError(txtConfirmPassword, message);
                lblMessage.SetMessage(message);
                return;
            }

            if (_userId != 0)
            {
                if (user.UpdateUserDetails(_userId, roleId, password, firstName, lastName, email, mobile, chkActive.Checked ))
                {                                        
                    GetData(-1, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty);
                    Clear();
                    lblMessage.SetMessage(MessageManager.GetMessage("25"));
                }
                else
                    lblMessage.SetMessage(MessageManager.GetMessage("26"));
            }
            else
            {
                if (user.CreateNewUser(roleId, userName, password, firstName, lastName, email, mobile, chkActive.Checked))
                {                    
                    GetData(-1, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty);
                    Clear();
                    lblMessage.SetMessage(MessageManager.GetMessage("28", userName));
                }
                else
                    lblMessage.SetMessage(MessageManager.GetMessage("29", userName));                
            }
            
        }

        private void GetData(int roleId, string userName, string firstName, string lastName, string email, string mobile)
        {
            errorProvider1.Clear();
            lblMessage.Clear(); 
            StringBuilder sqlCommand = new StringBuilder("SELECT U.User_Id, U.Pwd , U.User_Name,U.RoleId, R.Role, U.First_Name, U.Last_Name, U.EMail, U.Mobile, U.IsActive "); 
            sqlCommand.Append("FROM User_Info AS U, RoleDetails AS R ");
            sqlCommand.Append("WHERE U.RoleId = R.RoleId ");

            if (userName != string.Empty)
                sqlCommand.Append("AND U.User_Name LIKE '" + userName + "'");

            if (firstName != string.Empty)
                sqlCommand.Append("AND U.First_Name LIKE '" + firstName + "' ");

            if (lastName != string.Empty)
                sqlCommand.Append("AND U.Last_Name LIKE '"+ lastName +"' ");

            if (roleId != -1)
                sqlCommand.Append("AND U.RoleId = " + roleId.ToString());

            if (email != string.Empty)
                sqlCommand.Append("AND U.Email LIKE '" + email + "'");

            if (mobile != string.Empty)
                sqlCommand.Append("AND U.Mobile = '" + mobile + "'");

            GRID_VIEW_USER_DETAILS.AutoGenerateColumns = false;
            GRID_VIEW_USER_DETAILS.DataSource = (new DataAccess.DBHelper()).ExecuteDataTable(sqlCommand.ToString());
                                        
        }

        private void CreaNewUser(int roleId, string userName, string password, string confirmPassword, string firstName, string lastName, string email, string mobile, bool isActive)
        {
            Users objUsers = new Users();                
                                
            if(objUsers.CreateNewUser(roleId, userName, password, firstName, lastName, email, mobile, isActive))
                lblMessage.SetMessage(MessageManager.GetMessage("28", userName));
            else 
                lblMessage.SetMessage(MessageManager.GetMessage("29", userName));
       }
        

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            Clear();
        }

        private void Clear()
        {
            errorProvider1.Clear();
            lblMessage.Clear();
            txtConfirmPassword.Clear();
            txtFirstName.Clear();
            txtLastName.Clear();
            txtPassword.Clear();
            txtUserId.Clear();
            txtEmail.Clear();
            txtMobile.Clear();
            txtUserId.ReadOnly = false;
            
            btnUpdate.Enabled = false;
            btnSubmit.Enabled = true;
            btnSearch.Enabled = true;
            cmbRole.SelectedIndex = 0;
            _userId = 0;
        }

        private void txtMobile_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (DataFormat.IsInteger(e.KeyChar) != true  && (Keys)e.KeyChar != Keys.Back)
                e.Handled = true ;
            
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            GetData(DataFormat.GetInteger(((System.Collections.DictionaryEntry)(cmbRole.SelectedItem)).Key), txtUserId.Text.Trim(), txtFirstName.Text.Trim(), txtLastName.Text.Trim(), txtEmail.Text.Trim(), txtMobile.Text.Trim());
        }

        int _userId = 0;
        private void GRID_VIEW_USER_DETAILS_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            errorProvider1.Clear();
            lblMessage.Clear();

            if (e.RowIndex == -1)
                return;
    
            int userId = DataFormat.GetInteger(GRID_VIEW_USER_DETAILS.Rows[e.RowIndex].Cells["UserId"].Value);
            string password = (new DataSecurity()).Decrypt(DataFormat.GetString(GRID_VIEW_USER_DETAILS.Rows[e.RowIndex].Cells["Password"].Value));
            _userId = userId;
            txtUserId.Text  = DataFormat.GetString(GRID_VIEW_USER_DETAILS.Rows[e.RowIndex].Cells["UserName"].Value);
            txtFirstName.Text = DataFormat.GetString(GRID_VIEW_USER_DETAILS.Rows[e.RowIndex].Cells["FirstName"].Value);
            txtLastName.Text = DataFormat.GetString(GRID_VIEW_USER_DETAILS.Rows[e.RowIndex].Cells["LastName"].Value);
            txtEmail.Text = DataFormat.GetString(GRID_VIEW_USER_DETAILS.Rows[e.RowIndex].Cells["Email"].Value);
            txtMobile.Text = DataFormat.GetString(GRID_VIEW_USER_DETAILS.Rows[e.RowIndex].Cells["Mobile"].Value);
            txtPassword.Text = password ;
            txtConfirmPassword.Text = password;
            chkActive.Checked = DataFormat.GetString(GRID_VIEW_USER_DETAILS.Rows[e.RowIndex].Cells["IsActive"].Value) =="0" ? false : true;
            cmbRole.SelectedItem = new DictionaryEntry(DataFormat.GetString(GRID_VIEW_USER_DETAILS.Rows[e.RowIndex].Cells["RoleId"].Value), DataFormat.GetString(GRID_VIEW_USER_DETAILS.Rows[e.RowIndex].Cells["Role"].Value));
           
            btnUpdate.Enabled = true;
            txtUserId.ReadOnly = true;
            btnSubmit.Enabled = false;
            btnSearch.Enabled = false;
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (MessageManager.DisplayMessage("31", txtUserId.Text.Trim() , MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                if ((new Users()).DeleteUser(_userId))
                {
                    Clear();
                    lblMessage.SetMessage(MessageManager.GetMessage("32"));
               }                
            }            
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            AddUpdateUser();            
        }

        private void NewUser_Load(object sender, EventArgs e)
        {
            base.SetBGColor(this);
        }

       

     
    }
}

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 GNU Lesser General Public License (LGPLv3)


Written By
Founder Aspirea Technologies Pvt Ltd
India India
• 8 years of experience in IT Industry as a Developer.
• Experience of End-To-End Software Development and Implementation (Entire SDLC i.e Software Development Life Cycle)
• Real time Exposure to Banking, Finance and Energy industry.
• Expertise in distributed application architecture as well as web based applications using Microsoft.NET platform.
• Expertise in database design, SQL programming and SQL performance tuning.
• Expertise in Web Services and WCF Services.
• Experience of Rich Internet Application using Adobe Flex.
• Experience in migration of legacy application to latest technology, migration of VB application to .NET.
• Knowledge of OOPS and Design Concepts.
• Expertise in Agile/ Scrum software development processes.

Specialties
• Languages\ Technologies-
.NET Framework 1.1/2.0/3.0/3.5, C#.NET, VB.NET, ASP.NET, VB6, AJAX, ASP.NET, Adobe Flex 3.0, Web Services, Windows Communication Foundation (WCF), LINQ, SQL Server, Oracle, MySql, MS Access, HTML, XML, JavaScript, C# Script, CSS and XSLT.

• Methodology/ Concepts-
OOPS, Data Structures, Design Concepts and Agile/ Scrum Software Development

Comments and Discussions