using System;
using System.Data.SqlClient;
using Remuneraciones.DataSetFT;
using Remuneraciones.DataAccess;
using Municipalidad.Utils;

namespace Remuneraciones.BusinessObjects
{
	public class RlsEmpresa
	{
		/// <summary>
		/// Constructor
		/// </summary>
		public RlsEmpresa()
		{
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="idEmpresa"></param>
		/// <returns></returns>
		public DSEmpresa LoadBrowse(string idEmpresa, int Mes, int Ano)
		{
			//SqlConnection utilizado para ejecutar el SqlCommand
			SqlConnection connection = null;

			//Almacena retorno del DataAccess
			DSEmpresa ds;

			try
			{
				//Abre la conexion
				//connection = UtilsDB.GetConnection(UtilsConnectionManager.GetConnection(eConnectionString.Remuneraciones));
				connection = UtilsDB.GetConnection(Utils.GetAnoConnection(Ano));

				Empresa da = new Empresa(connection);
				ds = da.SelectBrowse(idEmpresa, Mes);
			}
			catch (Exception ex)
			{
				throw ex;
			}
			finally
			{
				if (connection != null)
					connection.Dispose();
			}

			return ds;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="idEmpresa"></param>
		/// <returns></returns>
		public int LastMonthActive(string idEmpresa, int Ano)
		{
			//SqlConnection utilizado para ejecutar el SqlCommand
			SqlConnection connection = null;

			//Almacena retorno del DataAccess
			int ds;

			try
			{
				//Abre la conexion
				connection = UtilsDB.GetConnection(Utils.GetAnoConnection(Ano));

				Empresa da = new Empresa(connection);
				ds = da.LastMonthActive(idEmpresa);
			}
			catch (Exception ex)
			{
				throw ex;
			}
			finally
			{
				if (connection != null)
					connection.Dispose();
			}

			return ds;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="idEmpresa"></param>
		/// <returns></returns>
		public DSEmpresaGeneral LoadGeneral(string idEmpresa, int idSistema)
		{
			//SqlConnection utilizado para ejecutar el SqlCommand
			SqlConnection connection = null;

			//Almacena retorno del DataAccess
			DSEmpresaGeneral ds;

			try
			{
				//Abre la conexion
				connection = UtilsDB.GetConnection(UtilsConnectionManager.GetConnection(eConnectionString.Empresa));

				Empresa da = new Empresa(connection);
				ds = da.SelectGeneral(idEmpresa, idSistema);
			}
			catch (Exception ex)
			{
				throw ex;
			}
			finally
			{
				if (connection != null)
					connection.Dispose();
			}

			return ds;
		}
	}
}