Esempio n. 1
0
            public static DataSet GetDataSet(GridOptions options, string query, string orderBy)
            {
                //string sql = "SELECT * FROM " + tableName;
                DataSet gridDataSet = new DataSet();
                var     _connection = new CommonConnection();
                string  condition   = "";

                try
                {
                    query = query.Replace(';', ' ');

                    string sqlQuery = options != null ? GridQueryBuilder <T> .Query(options, query, orderBy, condition) : query;

                    if (!string.IsNullOrEmpty(condition))
                    {
                        condition = " WHERE " + condition;
                    }

                    var condition1 = options != null ? GridQueryBuilder <T> .FilterCondition(options.filter) : "";

                    if (!string.IsNullOrEmpty(condition1))
                    {
                        if (!string.IsNullOrEmpty(condition))
                        {
                            condition += " And " + condition1;
                        }
                        else
                        {
                            condition = " WHERE " + condition1;
                        }
                    }

                    DataTable dataTable = _connection.GetDataTable(sqlQuery);
                    gridDataSet.Tables.Add(dataTable);

                    var sqlCount = "SELECT COUNT(*) FROM (" + query + " ) As tbl " + condition;

                    int        totalCount   = Convert.ToInt32(_connection.ExecuteScalar(sqlCount));
                    DataTable  totalCountDt = new DataTable("TotalCount");
                    DataColumn col          = new DataColumn("totalCount");
                    col.DataType = Type.GetType("System.Int32");
                    totalCountDt.Columns.Add(col);
                    DataRow dr = totalCountDt.NewRow();
                    dr["totalCount"] = totalCount;
                    totalCountDt.Rows.Add(dr);
                    gridDataSet.Tables.Add(totalCountDt);


                    return(gridDataSet);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
Esempio n. 2
0
            public static GridEntity <T> DataSourceWithDateQuary(GridOptions options, string query, string orderBy, string condition, string withDateQuary)
            {
                //string sql = "SELECT * FROM " + tableName;
                var _connection = new CommonConnection();

                try
                {
                    query = query.Replace(';', ' ');

                    string sqlQuery = options != null ? GridQueryBuilder <T> .Query(options, query, orderBy, condition) : query;

                    if (!string.IsNullOrEmpty(condition))
                    {
                        condition = " WHERE " + condition;
                    }

                    var condition1 = options != null ? GridQueryBuilder <T> .FilterCondition(options.filter) : "";

                    if (!string.IsNullOrEmpty(condition1))
                    {
                        if (!string.IsNullOrEmpty(condition))
                        {
                            condition += " And " + condition1;
                        }
                        else
                        {
                            condition = " WHERE " + condition1;
                        }
                    }

                    if (withDateQuary != "")
                    {
                        sqlQuery = withDateQuary + sqlQuery;
                    }

                    DataTable dataTable = _connection.GetDataTable(sqlQuery);

                    var sqlCount = withDateQuary + " SELECT COUNT(*) FROM (" + query + " ) As tbl " + condition;


                    int totalCount = Convert.ToInt32(_connection.ExecuteScalar(sqlCount));

                    var dataList = (List <T>)ListConversion.ConvertTo <T>(dataTable);
                    var result   = new GridResult <T>().Data(dataList, totalCount);

                    return(result);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
Esempio n. 3
0
            public static GridEntity <T> GenericDataSource(GridOptions options, string query, string orderBy, string condition)
            {
                var           _connection = new CommonConnection();
                StringBuilder gridQuery;
                StringBuilder totalQuery;

                GetGridPagingQuery(options, query, orderBy, condition, out gridQuery, out totalQuery, _connection.DatabaseType);
                DataTable dataTable  = _connection.GetDataTable(gridQuery.ToString());
                int       totalCount = Convert.ToInt32(_connection.ExecuteScalar(totalQuery.ToString()));
                var       dataList   = (List <T>)GenericListGenerator.GetList <T>(dataTable);
                var       result     = new GridResult <T>().Data(dataList, totalCount);

                return(result);
            }
Esempio n. 4
0
        public static List <T> DataSource(string query)
        {
            var connection = new CommonConnection();

            try
            {
                DataTable dataTable = connection.GetDataTable(query);

                var objData = (List <T>)ListConversion.ConvertTo <T>(dataTable);
                return(objData);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                connection.Close();
            }
        }
Esempio n. 5
0
            public static List <T> DataSource(string query)
            {
                var returnList = new List <T>();

                try
                {
                    CommonConnection connection = new CommonConnection();
                    DataTable        dataTable  = connection.GetDataTable(query);

                    var data = (List <T>)ListConversion.ConvertTo <T>(dataTable);
                    if (data != null)
                    {
                        return(data);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                return(returnList);
            }
Esempio n. 6
0
        public static List <T> GenericDataSource(string query)
        {
            var connection = new CommonConnection();

            try
            {
                DataTable dataTable = connection.GetDataTable(query);

                var objData = (List <T>)GenericListGenerator.GetList <T>(dataTable);
                if (objData.Count == 0)
                {
                    return(new List <T>());
                }
                return(objData);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                connection.Close();
            }
        }