示例#1
0
        public Int64 List_Count(ClsQueryCondition Condition = null)
        {
            DataTable Dt          = Methods_Query.GetQuery(this.mHeader_ViewName, "Count(1) As [Ct]", Condition);
            Int64     ReturnValue = 0;

            try
            { ReturnValue = (Int64)Methods.IsNull(Dt.Rows[0]["Ct"], 0); }
            catch { }
            return(ReturnValue);
        }
        public static DataTable GetQuery(string ViewObject, string Fields, ClsQueryCondition Condition, string Sort = "", Int64 Top = 0, Int32 Page = 0)
        {
            ClsDataAccess Da = new ClsDataAccess();

            try
            {
                Da.Connect();
                return(GetQuery(Da, ViewObject, Fields, Condition, Sort, Top, Page));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Da.Close();
            }
        }
示例#3
0
        public virtual DataTable List(ClsQueryCondition Condition = null, string Sort = "", Int32 Top = 0, Int32 Page = 0)
        {
            DataTable Dt = Methods_Query.GetQuery(this.mHeader_ViewName, "*", Condition, Sort, Top, Page);

            return(Dt);
        }
        public static DataTable GetQuery(ClsDataAccess Da, string ViewObject, string Fields, ClsQueryCondition Condition, string Sort = "", Int64 Top = 0, Int32 Page = 0)
        {
            string Query_RowNumberSort = Sort;

            if (Query_RowNumberSort.Trim() == "")
            {
                Query_RowNumberSort = "(Select 0)";
            }

            string Query_Top = "";

            if (Top > 0)
            {
                Query_Top = "Top " + Top.ToString();
            }

            Int64 PageCondition = 0;

            if (Page > 0)
            {
                PageCondition = Top * (Page - 1);
            }

            if (ViewObject.Trim() != "")
            {
                ViewObject = " From " + ViewObject + " ";
            }
            if (Fields.Trim() == "")
            {
                Fields = " * ";
            }
            if (Sort.Trim() != "")
            {
                Sort = " Order By " + Sort;
            }

            ClsPreparedQuery Pq = new ClsPreparedQuery(Da);

            Pq.Add_Parameter("ViewObject", SqlDbType.VarChar, 8000, 0, 0, ViewObject);
            Pq.Add_Parameter("Fields", SqlDbType.VarChar, 8000, 0, 0, Fields);
            Pq.Add_Parameter("Sort", SqlDbType.VarChar, 8000, 0, 0, Sort);

            string Query_Condition = "";

            if (Condition != null)
            {
                Query_Condition  = " Where 1 = 1 ";
                Query_Condition += " And " + Condition.GetQueryCondition();
                Pq.Add_Parameter(Condition.GetParameters());
            }

            Pq.pQuery = @"Select " + Query_Top + @" [Tb].* From ( Select Row_Number() Over (Order By " + Query_RowNumberSort + @") As [RowNumber], " + Fields + " " + ViewObject + " " + Query_Condition + @" ) As [Tb] Where [Tb].RowNumber > " + PageCondition + " " + Sort;
            Pq.Prepare();

            return(Pq.ExecuteQuery().Tables[0]);
        }