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;
using System.Data.OleDb;

public partial class Home : BasePage
{
    protected void Page_Load() {
        if( Utility.IsNull( Session["IP_ADDRESS"] ) )
        {
            Session["IP_ADDRESS"] =  Request.ServerVariables["REMOTE_ADDR"].ToString();
            //Request.ServerVariables["REMOTE_ADDR"].ToString()
        }
    }

    protected int DonationTarget() {
        try
        {
            return Int32.Parse(Utility.SiteSettings["FundRaisingGoal"]);
        }
        catch (Exception ex) { return 50000;  }
    }
    protected double CurrentDonations() {


        OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;;Data Source=" + Server.MapPath("~/db/MSdata.mdb") );
        OleDbCommand cmd = conn.CreateCommand();
        cmd.CommandText = "SELECT sum(amount) as CurrentDonations FROM contributions WHERE responsecode = 1 AND nDate >= '" + DateTime.Now.Month + "/1/"+DateTime.Now.Year+"'";
        OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
        
        DataSet ds = new DataSet("Results");
        adapter.Fill(ds);
        double result = 0;
        try
        {
            result = Double.Parse(ds.Tables[0].Rows[0][0].ToString());
        }
        catch (Exception ex)
        {            
        }

        conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;;Data Source=" + Server.MapPath("~/db/meter.mdb"));
        cmd = conn.CreateCommand();
        cmd.CommandText = "SELECT count FROM meter ";
        adapter = new OleDbDataAdapter(cmd);

        ds = new DataSet("Results");
        adapter.Fill(ds);
        try
        {
            result += Double.Parse(ds.Tables[0].Rows[0][0].ToString());
        }
        catch (Exception ex)
        {
        }

        return result;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
//       Response.Write( Server.MapPath("~/db"));

    }
}
