protected void btnUpdateUser_Click(object sender, EventArgs e)
        {
            DataSetTableAdapters.UsersTableAdapter taUser
                = new DataSetTableAdapters.UsersTableAdapter();

            taUser.Fill(ds.Users);//Get the latest and put into ds.Users table

            int selected = Convert.ToInt32(drdUserID.SelectedValue);


            DataRow[] dr = ds.Users.Select("UserID=" + selected);//Inside is where clause

            if (dr.Length == 1)
            {
                if (tbUsername.Text != "")
                {
                    dr[0]["Username"] = tbUsername.Text;
                }
                if (tbPass.Text != "")
                {
                    dr[0]["Password"] = tbPass.Text;
                }
                if (tbEmail.Text != "")
                {
                    dr[0]["Email"] = tbEmail.Text;
                }
                if (tbName.Text != "")
                {
                    dr[0]["Full Name"] = tbName.Text;
                }
                if (drdCountry.SelectedValue != "-1")
                {
                    dr[0]["Country"] = drdCountry.SelectedItem.Text;
                }
                if (rbtnAdmin.Checked)
                {
                    dr[0]["IsAdmin"] = true;
                }
                else
                {
                    dr[0]["IsAdmin"] = false;
                }

                taUser.Update(ds.Users);                 //Update to real db

                taUser.Fill(ds.Users);                   //Get the latest and put into ds.Users table
                gvUsers.DataSourceID = "SqlDataSource1"; //Update Grid View

                lblStatusUser.Text      = "Successfully updated";
                lblStatusUser.ForeColor = System.Drawing.Color.Green;
                lblStatusUser.Visible   = true;
            }
            else
            {
                lblStatusUser.Text      = "Unsuccessfully updated";
                lblStatusUser.ForeColor = System.Drawing.Color.Red;
                lblStatusUser.Visible   = true;
            }
        }
        protected void btnAddUser_Click(object sender, EventArgs e)
        {
            DataSetTableAdapters.UsersTableAdapter taUser
                = new DataSetTableAdapters.UsersTableAdapter();

            taUser.Fill(ds.Users);//Get the latest and put into ds.Users table

            DataRow[] dr = ds.Users.Select("Username = '******'");

            if (dr.Length == 1)
            {
                lblStatusUser.Visible   = true;
                lblStatusUser.Text      = "Account is already existed. Please choose another username!";
                lblStatusUser.ForeColor = System.Drawing.Color.Red;
                lblStatusUser.Visible   = true;
            }
            else
            {
                DataSet.UsersRow fRow = ds.Users.NewUsersRow();
                fRow.Username  = tbUsername.Text;
                fRow.Password  = tbPass.Text;
                fRow.Full_Name = tbName.Text;
                fRow.Email     = tbEmail.Text;
                fRow.Country   = drdCountry.SelectedItem.ToString();
                if (rbtnAdmin.Checked)
                {
                    fRow.IsAdmin = true;
                }
                else
                {
                    fRow.IsAdmin = false;
                }

                //In the offline database
                ds.Users.Rows.Add(fRow);
                //Get it back to the real database
                taUser.Update(ds.Users);

                //Get the latest database
                taUser.Fill(ds.Users);

                gvUsers.DataSourceID = "SqlDataSource1";//Update Grid View

                lblStatusUser.Text      = "Successfully Added New Account";
                lblStatusUser.ForeColor = System.Drawing.Color.Green;
                lblStatusUser.Visible   = true;
            }
        }
Пример #3
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();

            DataSetTableAdapters.UsersTableAdapter taUser
                = new DataSetTableAdapters.UsersTableAdapter();

            taUser.Fill(ds.Users);//Get the latest and put into ds.Users table

            DataRow[] dr = ds.Users.Select("Username = '******'");

            if (dr.Length == 1 && dr[0]["password"].ToString() == tbPassword.Text)
            {
                Session["Discount"] = 20.0;
                if ((bool)dr[0]["IsAdmin"] == true)
                {
                    Session["AdminStatus"] = true;
                    Server.Transfer("AdminPage.aspx");
                }
            }
            else
            {
                lblLoginStatus.Visible = true;
                lblLoginStatus.Text    = "Login failed. Username/Password is not correct";
            }

            taUser.Update(ds.Users);
        }
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();

            DataSetTableAdapters.UsersTableAdapter taUser
                = new DataSetTableAdapters.UsersTableAdapter();

            taUser.Fill(ds.Users);//Get the latest and put into ds.Users table

            DataRow[] dr = ds.Users.Select("Username = '******'");

            if (dr.Length == 1)
            {
                lblCreateStatus.Visible = true;
                lblCreateStatus.Text    = "Account is already existed. Please choose another username!";
            }
            else
            {
                DataSet.UsersRow fRow = ds.Users.NewUsersRow();
                fRow.Username  = tbUsername.Text;
                fRow.Password  = tbPass.Text;
                fRow.Full_Name = tbName.Text;
                fRow.Email     = tbEmail.Text;
                fRow.Country   = drdCountry.SelectedItem.ToString();
                fRow.IsAdmin   = false;

                //In the offline database
                ds.Users.Rows.Add(fRow);
                //Get it back to the real database
                taUser.Update(ds.Users);

                Response.Write("<script LANGUAGE='JavaScript' >alert('Successfully Registrated!!!')</script>");
                Server.Transfer("Login.aspx");
            }
        }
        protected void btnDeleteUser_Click(object sender, EventArgs e)
        {
            DataSetTableAdapters.UsersTableAdapter taUser
                = new DataSetTableAdapters.UsersTableAdapter();

            taUser.Fill(ds.Users);
            int selected = Convert.ToInt32(drdUserID.SelectedValue);

            DataRow[] dr = ds.Users.Select("UserID=" + selected);

            if (dr.Length == 1)
            {
                dr[0].Delete();
                lblStatusUser.Text      = "Successfully deleted";
                lblStatusUser.ForeColor = System.Drawing.Color.Green;
                lblStatusUser.Visible   = true;

                taUser.Update(ds.Users);                   //Update to real db
                taUser.Fill(ds.Users);                     //Get the latest and put into ds.Users table
                gvUsers.DataSourceID   = "SqlDataSource1"; //Update Grid View
                drdUserID.DataSourceID = "SqlDataSource1"; //Update Dropdownlist
            }
        }