Click here to Skip to main content
15,892,517 members
Articles / Desktop Programming / Win32

Address Book and Events Reminder

Rate me:
Please Sign up or sign in to vote.
4.74/5 (37 votes)
13 Feb 2009CPOL16 min read 105.5K   10.7K   106  
Allows to maintain and backup your contacts and also maintains a reminder. You can store data in any of the three different databases like Microsoft SQL Server, MySql, Microsoft Access
using System;
using System.Windows.Forms;

namespace AddressBook
{
    public partial class frmLogin : Form
    {
        public frmLogin()
        {
            InitializeComponent();
        }

        void CheckLogin(object sender, EventArgs e)
        {
            if (txtUserName.Text.Length == 0 || txtPassword.Text.Length == 0)
            {
                MessageBox.Show("The User Name and or Password cannot be blank.", "Login Failed");
                return;
            }
            System.Data.DataTable Table = new System.Data.DataTable();
            Program.Connection.CommandText = "select * from ContactsUserAccount where UserName='" + Converter.Encrypt(txtUserName.Text.ToUpper()) + "'";
            Program.Connection.FillDataTable(Table, true);

            if (Table.Rows.Count == 0)
            {
                MessageBox.Show("The specified user cannot be found.");
                return;
            }

            string CUPassword = Table.Rows[0][3].ToString();

            if (CUPassword != txtPassword.Text)
            {
                MessageBox.Show("Invalid Password", "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            UserPolicies.Password = CUPassword;
            if (Table.Rows[0][1].ToString() == "0") { MessageBox.Show("Your account had been disabled by your Administrator.", "Login Failed"); return; }
            if (Table.Rows[0][4].ToString() == "0") UserPolicies.IsAdministrator = true;
            else UserPolicies.IsAdministrator = false;

            UserPolicies.UserName = txtUserName.Text.ToUpper();
            UserPolicies.UserID = Table.Rows[0][0].ToString();
            UserPolicies.IsLoggedIn = true;
            Program.Connection.CommandText = "update ContactsUserAccount set LastLogin='" + Converter.Encrypt(DateTime.Now.ToLongDateString() + "  " + DateTime.Now.ToLongTimeString()) + "', Status='" + Converter.Encrypt("Logged In") + "' where UserID=" + UserPolicies.UserID;
            Program.Connection.ExecuteNonQuery();
            this.Close();
        }

        void ExitApplication(object sender, EventArgs e)
        {
            Close();
        }

        void CheckData(object sender, EventArgs e)
        {
            System.Data.DataTable Table;
        CheckAccountExist:
            Table = new System.Data.DataTable();
            Program.Connection.CommandText = "select * from ContactsUserAccount";
            Program.Connection.FillDataTable(Table, true);

            if (Table.Rows.Count == 0)
            {
                if (MessageBox.Show("You need to add User to login. Do you want to add it now?", "No User Found", MessageBoxButtons.YesNo) == DialogResult.No)
                { MessageBox.Show("Action Cancled... Login Failed."); this.Close(); return; }
                frmUserAccount ShowUserAccount = new frmUserAccount();
                ShowUserAccount.ShowDialog();
                goto CheckAccountExist;
            }
        }
    }
}

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 Code Project Open License (CPOL)


Written By
Software Developer
India India


Completed B.Com(CS) at DGVC and GNIIT Software Engineering at NIIT. Resident at Chennai and working as a Software Engineer.



 Language / Technology :

C#, ADO.NET, ASP.NET, MVC, WCF, ASP, PHP, XML, Java, J2EE, HTML, JavaScript, JQuery, AngularJS, VB Script, C++, MS SQL Server, SSRS, MySql, Oracle, Oracle Forms Development, Windows, Linux.



Click here to view other articles.


Mail Me at:  shridhar_tl@ymail.com


Visit my Site:  www.iCodeIt.in


Comments and Discussions