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

namespace Remuneraciones.DataAccess
{
	/// <summary>
	/// Descripción breve de Mantenedores.
	/// </summary>
	public class Apv
	{
		//Field para almacenar la conexión
		private SqlConnection _connection = null;

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

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public DSApv SelectByID(string idApv, int Mes)
		{
			//Almacena retorno del SqlCommand
			DataSet dr;

			try
			{
				//Ejecuta el SqlCommand
				dr = UtilsDB.ExecuteDataset(_connection, CommandType.StoredProcedure, Schema.Apv.SP_SELECT_BY_PK, 
					UtilsDB.MP("@idInstitucion", SqlDbType.Char, 4, (idApv == ""? null: idApv)),
					UtilsDB.MP("@Mes", SqlDbType.Int, 0, 1));
			}
			catch (Exception ex)
			{
				throw ex;
			}

			return GetDSFT(dr);
		}

		internal DSApv GetDSFT(DataSet ds)
		{
			DSApv DSFT = new DSApv();
			DataRow rowDS;

			foreach(DataRow dr in ds.Tables[0].Rows)
			{
				rowDS = DSFT.Tables[0].NewRow();
				foreach(DataColumn dc in DSFT.Tables[0].Columns)
					rowDS[dc.ColumnName] =  dr[dc.ColumnName];
				DSFT.Tables[0].Rows.Add(rowDS);
			}

			return DSFT;
		}
	}
}
