示例#1
0
        public List <T> LoadData(T Obj, string strQueryCondition, int intCurrPage, string SPName, int PageSize,
                                 Dictionary <string, object> Params)
        {
            var Cols = new List <T>();


            try
            {
                Conn.Open();
                comm = new SqlCommand(SPName, Conn);
                comm.CommandTimeout = 2000;
                comm.CommandType    = CommandType.StoredProcedure;
                comm.Parameters.Add("@CURRENTPAGE", SqlDbType.BigInt).Value     = intCurrPage;
                comm.Parameters.Add("@PAGESIZE", SqlDbType.BigInt).Value        = PageSize;
                comm.Parameters.Add("@STRQUERY", SqlDbType.VarChar, 4000).Value = strQueryCondition;

                if (Params != null)
                {
                    foreach (string Key in Params.Keys)
                    {
                        comm.Parameters.Add(Key, SqlDbType.DateTime).Value = Params[Key];
                    }
                }

                dr = comm.ExecuteReader();
                DynamicBuilder <T> DynamicBuilder = null;
                DynamicBuilder = DynamicBuilder <T> .CreateBuilder(dr);

                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        T col = DynamicBuilder.Build(dr); // CreateInstanceT();
                        Cols.Add(col);
                    }

                    dr.NextResult();
                    //Record Count
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            TotalRecord = Convert.ToInt32(dr[0]);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Conn.Close();
            }

            return(Cols);
        }
示例#2
0
        public List <T> LoadData(T Obj, string strQueryCondition, int intCurrPage, string SPName, int PageSize,
                                 string SortBy, string Sort)
        {
            var Cols = new List <T>();

            try
            {
                Conn.Open();
                comm = new SqlCommand(SPName, Conn);
                comm.CommandTimeout = 2000;
                comm.CommandType    = CommandType.StoredProcedure;
                comm.Parameters.Add("@CURRENTPAGE", SqlDbType.BigInt).Value     = intCurrPage;
                comm.Parameters.Add("@PAGESIZE", SqlDbType.BigInt).Value        = PageSize;
                comm.Parameters.Add("@STRQUERY", SqlDbType.VarChar, 4000).Value = strQueryCondition;
                comm.Parameters.Add("@SORT_BY", SqlDbType.VarChar, 50).Value    = SortBy;
                comm.Parameters.Add("@SORT", SqlDbType.VarChar, 50).Value       = Sort;

                dr = comm.ExecuteReader();
                DynamicBuilder <T> DynamicBuilder = null;
                DynamicBuilder = DynamicBuilder <T> .CreateBuilder(dr);

                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        T col = DynamicBuilder.Build(dr); // CreateInstanceT();
                    }

                    dr.NextResult();
                    //Record Count
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            TotalRecord = dr.GetInt32(0);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Conn.Close();
            }

            return(Cols);
        }
示例#3
0
        public List <T> GetData(string SQL)
        {
            var Cols = new List <T>();
            var conn = new SqlConnection(constr);

            try
            {
                conn.Open();

                comm = new SqlCommand(SQL, conn);
                comm.CommandTimeout = 30000;
                comm.CommandType    = CommandType.Text;
                dr = comm.ExecuteReader();
                DynamicBuilder <T> DynamicBuilder = null;
                DynamicBuilder = DynamicBuilder <T> .CreateBuilder(dr);

                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        T col = DynamicBuilder.Build(dr); // CreateInstanceT();
                        Cols.Add(col);
                    }
                    dr.NextResult();
                    //Record Count
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            TotalRecord = dr.GetInt32(0);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }

            return(Cols);
        }