using System;
using System.Data;
using System.Data.SqlClient;

using Remuneraciones.DataSetFT;
using Municipalidad.Utils;
using Remuneraciones.DataModel;

namespace Remuneraciones.DataAccess
{
	public class Cargos: CargosCRUD
	{
		//Field para almacenar la conexión
		private SqlConnection _connection = null;
		private SqlTransaction _transaction = null;

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="connection"></param>
		public Cargos(SqlConnection connection): base(connection)
		{
			_connection = connection;
		}

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="transaction"></param>
		public Cargos(SqlTransaction transaction): base(transaction)
		{
			_transaction = transaction;
		}

//		/// <summary>
//		/// 
//		/// </summary>
//		/// <param name="idIdentity"></param>
//		/// <returns></returns>
//		public DSCargos SelectBrowse(string idEmpresa, int Mes)
//		{
//			//Almacena retorno del SqlCommand
//			SqlDataReader dr;
//
//			try
//			{
//				//Ejecuta el SqlCommand
//				dr = UtilsDB.ExecuteDataReader(_connection, CommandType.StoredProcedure, Schema.Cargos.SP_SELECT_BROWSE, 
//					UtilsDB.MP("@OrderBy", SqlDbType.Int, 0, 1),
//					UtilsDB.MP("@idNumero", SqlDbType.VarChar, 3, (idEmpresa == ""? (object)null: idEmpresa)),
//					UtilsDB.MP("@Mes", SqlDbType.Int, 0, (Mes == int.MinValue? (object)null: Mes)));
//			}
//			catch (Exception ex)
//			{
//				throw ex;
//			}
//
//			return GetDSFT(dr);
//		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="idIdentity"></param>
		/// <returns></returns>
		public DSCargos SelectBrowse(string idEmpresa, int Mes)
		{
			//Almacena retorno del SqlCommand
			DataSet ds;

			try
			{
				//Ejecuta el SqlCommand
				ds = UtilsDB.ExecuteDataset(_connection, CommandType.StoredProcedure, Schema.Cargos.SP_SELECT_BROWSE, 
					UtilsDB.MP("@OrderBy", SqlDbType.Int, 0, 1),
					UtilsDB.MP("@idNumero", SqlDbType.VarChar, 3, (idEmpresa == ""? (object)null: idEmpresa)),
					UtilsDB.MP("@Mes", SqlDbType.Int, 0, (Mes == int.MinValue? (object)null: Mes)));
			}
			catch (Exception ex)
			{
				throw ex;
			}

			return GetDSFT(ds);
		}

		internal DSCargos GetDSFT(DataSet ds)
		{
			DSCargos DSFTCargos = new DSCargos();
			DataRow rowCargos;

			foreach(DataRow dr in ds.Tables[0].Rows)
			{
				rowCargos = DSFTCargos.Tables[0].NewRow();

				foreach(DataColumn dc in DSFTCargos.Tables[0].Columns)
				{
					rowCargos[dc.ColumnName] =  dr[dc.ColumnName];
				}
				DSFTCargos.Tables[0].Rows.Add(rowCargos);
			}

			return DSFTCargos;
		}
	}
}