using System;
using System.Reflection;
using Cello.Reports;
using System.Data.SqlTypes;
using System.Data.SqlClient;
namespace Cello.Schemas
{

    partial class AgencyInvoice
    {
        partial class AgencyInvoiceItemDataTable
        {
        }

        partial class AgencyInvoiceListDataTable
        {
        }
        ///////////////////////////////
        // Members
        private bool disposed;

        private Schemas.AgencyInvoice.AgencyInvoiceListDataTable summaryData;
        public System.Data.DataTable SummaryData
        {
            get { return (System.Data.DataTable)summaryData; }
        }

        /*
        private Schemas.AgencyInvoice.AgencyInvoiceItemDataTable itemData;
        public System.Data.DataTable ItemData
        {
            get { return (System.Data.DataTable)itemData;}
        }
        */

        public AgencyInvoice(string OnlyShowUnallocated, string Status, string databaseName)
        {

            String connectionString = Setting.Application.GetDatabaseConnectionString(databaseName);

            // DEBUG
            // System.Windows.Forms.MessageBox.Show("Connection string = " + connectionString);

            SqlConnection dataConnection = new SqlConnection(connectionString);
            try
            {
                dataConnection = new SqlConnection(connectionString);

                using (AgencyInvoiceTableAdapters.AgencyInvoiceListTableAdapter summary = new AgencyInvoiceTableAdapters.AgencyInvoiceListTableAdapter())
                {
                    summary.Connection = dataConnection;
                    summary.Connection.ConnectionString = Helper.GetDatabaseConnectionString();
                    summaryData = summary.GetData("0", Status);
                }

                using (AgencyInvoiceTableAdapters.AgencyInvoiceItemTableAdapter itemData = new AgencyInvoiceTableAdapters.AgencyInvoiceItemTableAdapter())
                {
                    itemData.Connection = dataConnection;
                    itemData.Connection.ConnectionString = Helper.GetDatabaseConnectionString();
                }
            }
            finally
            {

                if (dataConnection != null)
                    dataConnection.Dispose();
            }
        }

        ~AgencyInvoice()
        {
            Dispose(false);
        }

        public new void Dispose()
        {

            Dispose(true);
            GC.SuppressFinalize(true);
        }

        protected override void Dispose(bool isDisposing)
        {

            if (disposed)
                return;

            if (isDisposing)
            {
                if (summaryData != null)
                    summaryData.Dispose();
            }

            disposed = true;
        }
    }
}
