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

using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Collections.Generic;

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

        if ( !Utility.IsNull(Session["Admin"]) 
           && Session["Admin"].ToString() == "true" )
        {
            pnlLogIn.Visible = false;
            pnlIsAdmin.Visible = true;
        }

        if (!IsPostBack)
        {
            Utility.FlushSiteSettings();
            txtFundraisingGoal.Text = Utility.SiteSettings["FundRaisingGoal"];
            txtTickler.Text = Utility.SiteSettings["TicklerText"];
        }
    }
    protected void btnSaveTickler_Click(object sender, EventArgs e)
    {
        SqlParameterList spl = new SqlParameterList();
        spl.AddParameter("Text", txtTickler.Text, SqlDbType.Text);
        //string sql = "UPDATE SiteSettings SET SettingValue = '" + txtTickler.Text + "' WHERE SettingName = 'TicklerText' ";
        string sql = "UPDATE SiteSettings SET SettingValue = @Text WHERE SettingName = 'TicklerText' ";

        SqlHelper.ExecuteNonQuery(CommandType.Text, sql, spl.ToArray() );

        Utility.SiteSettings["TicklerText"] = txtTickler.Text;
        pnlResults.Visible = true;
        pnlResults.CssClass = "SuccessPanel";
        lblResults.Text = "Your tickler text was succesfully saved.";
     }

    protected void btnSaveFundRaisingGoal_Click(object sender, EventArgs e)
    {

        string sql = "UPDATE SiteSettings SET SettingValue = '"+Int32.Parse(txtFundraisingGoal.Text)+"' WHERE SettingName = 'FundRaisingGoal' ";
        SqlHelper.ExecuteNonQuery(CommandType.Text, sql);
        Utility.SiteSettings["FundRaisingGoal"] = txtFundraisingGoal.Text;
        pnlResults.Visible = true;
        pnlResults.CssClass = "SuccessPanel";
        lblResults.Text = "Your Fund Raising Goal text was succesfully saved.";

    }

    protected void btnLogIn_Clicked(object sender, EventArgs e)
    {
        if (txtUserName.Text == "msabrin303" && txtPassword.Text == "Crescent1")
        {
            Session["Admin"] = "true";
            pnlIsAdmin.Visible = true;
            pnlLogIn.Visible = false;
        }
        else {
            lblLoginMessage.Text = "Error! Incorrect username/password <br />";
        }
    
    }
}
