コード例 #1
0
ファイル: KendoDataSource.cs プロジェクト: Likhon69/BinderWeb
            public 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);
                DataTable dataTable  = _connection.GetDataTable(gridQuery.ToString());
                int       totalCount = _connection.GetScaler(totalQuery.ToString());

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

                return(result);
            }
コード例 #2
0
ファイル: KendoDataSource.cs プロジェクト: Likhon69/BinderWeb
            public GridEntity <T> DataSource(GridOptions options, string query, string orderBy, string condition)
            {
                //  var _connection = new CommonConnection();
                try
                {
                    query = query.Replace(';', ' ');
                    string orderby  = "";
                    string sqlQuery = query;
                    if (options != null)
                    {
                        if (options.pageSize > 0)
                        {
                            sqlQuery = GridQueryBuilder <T> .Query(options, query, orderBy, condition);
                        }
                        else
                        {
                            if (orderBy != "")
                            {
                                if (orderBy.ToLower().Contains("asc") || orderBy.ToLower().Contains("desc"))
                                {
                                    orderby = string.Format(" order by {0}", orderBy);
                                }
                                else
                                {
                                    orderby = string.Format(" order by {0} asc ", orderBy);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (orderBy != "")
                        {
                            if (orderBy.ToLower().Contains("asc") || orderBy.ToLower().Contains("desc"))
                            {
                                orderby = string.Format(" order by {0}", orderBy);
                            }
                            else
                            {
                                orderby = string.Format(" order by {0} asc ", orderBy);
                            }
                        }
                    }

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

                    var condition1 = "";
                    if (options != null)
                    {
                        if (options.filter != null)
                        {
                            condition1 = GridQueryBuilder <T> .FilterCondition(options.filter).Trim();
                        }
                    }
                    if (!string.IsNullOrEmpty(condition1))
                    {
                        if (!string.IsNullOrEmpty(condition))
                        {
                            condition += " And " + condition1;
                        }
                        else
                        {
                            condition = " WHERE " + condition1;
                        }
                    }
                    sqlQuery = "SELECT * FROM (" + sqlQuery + " ) As tbl " + condition;

                    DataTable dataTable = _connection.GetDataTable(sqlQuery + orderby);

                    String sqlCount = "";

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


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


                    return(result);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    _connection.Close();
                }
            }
コード例 #3
0
ファイル: KendoDataSource.cs プロジェクト: Likhon69/BinderWeb
            public 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);

                    String sqlCount = "";
                    //if (_connection.DatabaseType == DatabaseType.SQL)
                    //{
                    sqlCount = withDateQuary + " SELECT COUNT(*) FROM (" + query + " ) As tbl " + condition;
                    //}
                    //else if (_connection.DatabaseType == DatabaseType.Oracle)
                    //{
                    //    sqlCount = withDateQuary + " SELECT COUNT(*) FROM (" + query + " )" + condition;
                    //}

                    int totalCount = _connection.GetScaler(sqlCount);

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


                    return(result);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    _connection.Close();
                }
            }