from main

September 8, 2008

from main.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Login
{
    public partial class frmMain : Form
    {
        string id;
        public frmMain()
        {
            InitializeComponent();
        }
        public frmMain(string user, string pass, string id)
        {
            InitializeComponent();
            textBox1.Text = user;
            textBox2.Text = pass;
            this.id = id;

        }
        private void button1_Click(object sender, EventArgs e)
        {
            Class1 newConnect = new Class1();
            newConnect.query_add("UPDATE loginTbl set Username = ‘"+textBox1.Text+"’, Password = ‘"+textBox2.Text+"’ WHERE UserID =’"+this.id+"’");
            MessageBox.Show("You have Successfully Updated Your Username and Password");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Class1 newConnect = new Class1();
            newConnect.query_add("DELETE from loginTbl WHERE UserID =’"+this.id+"’");
            MessageBox.Show("You have Successfully Deleted Your Username and Password");
        }
    }
}

class1

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;

namespace Login
{
    class Class1
    {
        private SqlDataReader _select;
        public SqlDataReader select
        {
            get
            {
                return _select;
            }
            set
            {
                _select = value;
            }
        }

        public void query_select(string query)
        {
            SqlConnection c = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\Admin\Desktop\Login Midterm\Login Midterm\loginDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
            c.Open();
            SqlCommand q = new SqlCommand(query, c);
            SqlDataReader r = q.ExecuteReader();
            this.select = r;
        }
        public void query_add(string query)
        {
            SqlConnection c = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\Admin\Desktop\Login Midterm\Login Midterm\loginDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
            c.Open();
            SqlCommand q = new SqlCommand();
            q.Connection = c;
            q.CommandText = query;
            q.ExecuteNonQuery();
            c.Close();
        }
    }
}

log.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Login
{
    public partial class frmLog : Form
    {
        public frmLog()
        {
            InitializeComponent();
        }
       
        private void button1_Click(object sender, EventArgs e)
        {
            Class1 newConnect = new Class1();
            newConnect.query_select("SELECT * FROM loginTbl WHERE Username like ‘"+textBox1.Text+"’ and Password like ‘"+textBox2.Text+"’");
            if (newConnect.select.HasRows == true)
            {
                newConnect.select.Read();
                string username = newConnect.select["Username"].ToString();
                string password = newConnect.select["Password"].ToString();
                string id = newConnect.select["UserID"].ToString();
                frmMain a = new frmMain(username,password,id);
                a.Show();
            }
            else
            {
                MessageBox.Show("Invalid Username and/or Password");
            }
        }
    }
}

Comments »

The URI to TrackBack this entry is: http://valkyrie.blogsome.com/2008/09/08/from-main/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.