LinkQ 组合查询与分页

 

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();
        

    }

  

转载于:https://www.cnblogs.com/shi2172843/p/5973129.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值