using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SystemX.Net.Platform.Common
{
    public static class DataTableQuery
    {
        public static List<DataRow> FindDataRow(DataTable dtTable, string strKeyName, string strFindingValue)
        {
            List<DataRow> adrResult = (from dtRow in dtTable.AsEnumerable() where dtRow[strKeyName].ToString() == strFindingValue select dtRow).ToList();

            return adrResult;
        }

        public static int GetDataRowHandle(DataTable dtTable, string strKeyFieldName, string strComparingValue)
        {
            int nIdx = 0;

            foreach (DataRow dtRow in dtTable.AsEnumerable())
            {
                if (dtRow[strKeyFieldName].ToString() == strComparingValue)
                    return nIdx;

                nIdx++;
            }

            return -1;
        }
    }
}
