using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;

namespace DAL
{
    public class Method:DataAccess
    {
        protected object ExecuteReader(string sql,SqlParameter[] p,bool sp)
        {
            con.Open();
            cmd.CommandText = sql;
            if (sp) cmd.CommandType = System.Data.CommandType.StoredProcedure;
            if (p != null && p.Length > 0) cmd.Parameters.AddRange(p);
            return cmd.ExecuteReader();
        }
        protected bool ExecuteNonQuery(string sql, SqlParameter[] p, bool sp)
        {

            con.Open();
            cmd.CommandText = sql;
            if (sp) cmd.CommandType = System.Data.CommandType.StoredProcedure;
            if (p != null && p.Length > 0) cmd.Parameters.AddRange(p);
            int rowEffect = cmd.ExecuteNonQuery();
            con.Close();

            if (rowEffect > 0)
                return true;
            return false;
        }
        protected object ExecuteScalar(string sql, SqlParameter[] p, bool sp)
        {
            con.Open();
            cmd.CommandText = sql;
            if (sp) cmd.CommandType = System.Data.CommandType.StoredProcedure;
            if (p != null && p.Length > 0) cmd.Parameters.AddRange(p);
            return cmd.ExecuteScalar();
        }
    }
}
