using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string data = DateTime.Now.ToLongDateString() + ", " + DateTime.Now.ToLongTimeString() + ": ";

        AccessDataSource1.SelectCommand = "SELECT Email FROM ListaAdresow WHERE Email='" + TextBox1.Text + "'";        
        DataView dv=(DataView)AccessDataSource1.Select(new DataSourceSelectArguments());
        if (dv.Count > 0)
        {
            Label1.Text += data + "<FONT COLOR=navy>Podany adres e-mail znajduje się już na liście</FONT><BR>";
            return;
        }
                
        AccessDataSource1.InsertCommand = "INSERT INTO ListaAdresow (Email) VALUES ('" + TextBox1.Text + "')";
        try
        {
            AccessDataSource1.Insert();
            Label1.Text += data + "dodałem do listy adres e-mail: " + TextBox1.Text + "<BR>";
            TextBox1.Text = "";
        }
        catch (Exception exc)
        {
            Label1.Text += data + "<FONT COLOR=red>" + exc.Message + "</FONT><BR>";
        }
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        string data = DateTime.Now.ToLongDateString() + ", " + DateTime.Now.ToLongTimeString() + ": ";
        AccessDataSource1.DeleteCommand = "DELETE FROM ListaAdresow WHERE Email='" + TextBox1.Text + "'";
        try
        {
            AccessDataSource1.Delete();
            Label1.Text += data + "usunąłem z listy adres e-mail: " + TextBox1.Text + "<BR>";
            TextBox1.Text = "";
        }
        catch (Exception exc)
        {
            Label1.Text += data + "<FONT COLOR=red>" + exc.Message + "</FONT>" + "<BR>";
        }
    }
}
