using System;
using System.Data;

namespace LLNet.BLL.General
{
	/// <summary>
	/// Summary description for General.
	/// </summary>
	public class General
	{
		public General()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		public static void GetNextCodeControlValue(BLL.BLLServer bllInstance, DAL.IDAL moduleInstance, ref DataSet param)
		{
		//-- Procedemos
			try
			{
			//-- Declaracion de variables
				Utils.QueryParams qp = new LLNet.Utils.QueryParams();
			//-- Empezamos la transaccion
				moduleInstance.BeginTransaction();
			//-- Establecemos los parametros iniciales
				System.Data.DataTable tb = param.Tables[0];
				System.Data.DataRow row = tb.Rows[0];
				string strCodigo = row[0].ToString();
				qp.AddReplaceParam("CODIGO", LLNet.Utils.Helpers.scm(strCodigo) );
			//-- Obtenemos el valor
				int intSequence = Convert.ToInt32( LLNet.Utils.Helpers.Nvl( bllInstance.GetSingleValue("internal_sequence", qp, "General"), -1) );
			//-- Incrementamos la secuencia
				bllInstance.ExecuteSql("upd_internal_sequence", qp, "General");
			//-- Guardamos el valor
				tb.Rows.Add( new object[] { intSequence.ToString() } );
				tb.AcceptChanges();
			//-- Completamos la transaccion
				moduleInstance.Commit();
			}
			catch(Exception e)
			{
				moduleInstance.Rollback();
                throw new Exception(e.Message);
			}
		}

	}
}
