using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class DeleteUser : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        divPageMessages.Visible = false;

        if (Page.IsPostBack == false)
        {
            Initialize();
        }
    }

    private void Initialize()
    {
    }

    protected void btnSubmit_Click(object sender, System.EventArgs e)
    {
        if (Page.IsValid)
        {
          
            DataSetTableAdapters.UsersTableAdapter oUsersTableAdapter =
                new DataSetTableAdapters.UsersTableAdapter();
            
            int intAffectedRows =
                oUsersTableAdapter.DeleteUserByUserName(txtUsername.Text);
          
            if (intAffectedRows == 0)
            {
                string strErrorMessage =
                    "There is no such a user with this username!";

                DisplayErrorMessage(strErrorMessage);
                return;
            }
         
            string strInformationMessage =
                string.Format("The user with this username [{0}] was deleted successfully.",
                txtUsername.Text);

            DisplayInformationMessage(strInformationMessage);
          
        }
    }
        protected virtual void DisplayErrorMessage(string message)
	{
		divPageMessages.Visible = true;

		litPageMessages.Text =
			string.Format("<div class='error'>{0}</div>", message);
	}

	protected virtual void DisplayWarningMessage(string message)
	{
		divPageMessages.Visible = true;

		litPageMessages.Text =
			string.Format("<div class='warning'>{0}</div>", message);
	}

	protected virtual void DisplayInformationMessage(string message)
	{
		divPageMessages.Visible = true;

		litPageMessages.Text =
			string.Format("<div class='information'>{0}</div>", message);
	}
    }
