程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> 關於.NET >> LinQ 組合查詢與分頁,LinQ組合查詢分頁

LinQ 組合查詢與分頁,LinQ組合查詢分頁

編輯:關於.NET

LinQ 組合查詢與分頁,LinQ組合查詢分頁


 

1.以開頭查

public List<Car> Select1(string a){

return con.Car.Where(r => r.Name.StartsWith(a)).ToList();
}

 

2.以結尾查

public List<Car> Select2(string a)

{
return con.Car.Where(r => r.Name.EndsWith(a)).ToList();
}

 

3.最大值

public string Max()

{
return con.Car.Max(r => r.Price).ToString();
}

 

4.最小值

public string Min()

{
return con.Car.Min(r => r.Price).ToString();
}

 

5.總和

 

public string Sum()
{
return con.Car.Sum(r => r.Price).ToString();
}

 

6.平均值

public string avg()
{
return con.Car.Average(r => r.Price).ToString();
}

7.升序

 

public List<Car> ss()
{
return con.Car.OrderBy( r =>r.Price).ToList();
}

 

8.降序

 

public List<Car> s()
{
return con.Car.OrderByDescending(r => r.Price).ToList();
}

9.組合分頁查詢

 

    public List<Car> Selecta(int d, string a, string b, string c)
    {
        List<Car> list = new List<Car>();
        list = con.Car.ToList();
     if (a != "")
        {
            List<Car> list1 = con.Car.Where(r => r.Code.Contains(a)).ToList();

            list = list.Intersect(list1).ToList();
        }
        if (b != "")
        {
            List<Car> list1 = con.Car.Where(r => r.Name.Contains(b)).ToList();

            list = list.Intersect(list1).ToList();
        }
        if (c != "")
        {
            List<Car> list1 = con.Car.Where(r => r.Brand.Contains(c)).ToList();

            list = list.Intersect(list1).ToList();
        }
        return list.Skip((d-1-1) * PageCount).Take(PageCount).ToList();
        
    }

    int PageCount = 6;
    public List<Car> start()
    {
        return con.Car.Skip(0 * PageCount).Take(PageCount).ToList();
    }
    public List<Car> prev(string a)
    {
        return con.Car.Skip((Convert.ToInt32(a) - 1 - 1) * PageCount).Take(PageCount).ToList();
    }
    public List<Car> next(string a)
    {
        return con.Car.Skip(Convert.ToInt32(a) * PageCount).Take(PageCount).ToList();
    }
    public List<Car> end()
    {
        return con.Car.Skip((max() - 1) * PageCount).Take(PageCount).ToList();
    }

    private int max()
    {
        int count = new CarData().Select().Count;

        double aa = count / (PageCount * 1.0);

        return Convert.ToInt32(Math.Ceiling(aa));
    }
}
 void LinkButton4_Click(object sender, EventArgs e)
    {
        Repeater1.DataSource = new CarData().end();
        Repeater1.DataBind();
        Label2.Text = max().ToString();
    }
    
    private int max()
    {
        int count = new CarData().Select().Count;

        double aa = count / (PageCount * 1.0);

        return Convert.ToInt32(Math.Ceiling(aa));
    }
    void LinkButton3_Click(object sender, EventArgs e)
    {
        if (Convert.ToInt32(Label2.Text) < max())
        {
            int a = Convert.ToInt32(Label2.Text) + 1;
            Repeater1.DataSource = new CarData().next(Label2.Text);
            Repeater1.DataBind();
            Label2.Text = a.ToString();
        }
        else
        {
            return;
        }

    }

    void LinkButton2_Click(object sender, EventArgs e)
    {
        
        if (Convert.ToInt32(Label2.Text) > 1)
        {
            int a = Convert.ToInt32(Label2.Text) - 1;
            Repeater1.DataSource = new CarData().prev(Label2.Text);
            Repeater1.DataBind();
            Label2.Text = a.ToString();
        }
        else
        {
            return;
        }
    }

    void LinkButton1_Click(object sender, EventArgs e)//首頁
    {
        Repeater1.DataSource = new CarData().start();
        Repeater1.DataBind();
        Label2.Text = "1";
    }

    void Button13_Click(object sender, EventArgs e)
    {
        Label2.Text = "1";
        int a = Convert.ToInt32(Label2.Text) + 1;
        Repeater1.DataSource = new CarData().Selecta(a,TextBox3.Text, TextBox4.Text, TextBox5.Text);
        Repeater1.DataBind();
        
        int count = new CarData().Select().Count;

       
        Label3.Text = Math.Ceiling(Convert.ToDouble(count) / PageCount).ToString();
        

    }

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved