using Students.BLL;
using Students.Modal;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Students
{
public partial class Frm_07 : Form
{
StudentBLL studentBLL = new StudentBLL();
List<StudentModal> studentModalList = null;
public Frm_07()
{
InitializeComponent();
studentModalList = studentBLL.FindStudentsAll();
}
private void btn_All_Click(object sender, EventArgs e)
{
var queryList = (from stu in studentModalList select stu).ToList();
dgv.DataSource = queryList;
}
private void btn_Query1_Click(object sender, EventArgs e)
{
var queryList = (from stu in studentModalList
where stu.Sname == txt_QueryName.Text.Trim()
select stu).ToList();
dgv.DataSource = queryList;
}
private void btn_Query2_Click(object sender, EventArgs e)
{
var queryList = (from stu in studentModalList
where stu.Sname == txt_QueryName.Text.Trim() && stu.Sage
== int.Parse(txt_QueryAge.Text.Trim())
select stu).ToList();
dgv.DataSource = queryList;
}
private void btn_Query3_Click(object sender, EventArgs e)
{
int index = txt_QueryAge.Text.Trim().Length > 0 ? int.Parse(txt_QueryAge.Text.Trim()) : 0;
var queryList = (from stu in studentModalList
where stu.Sname.Equals(txt_QueryName.Text.Trim()) ||
stu.Sage == index
select stu).ToList();
dgv.DataSource = queryList;
}
private void btn_Query4_Click(object sender, EventArgs e)
{
var queryList = (from stu in studentModalList
where stu.Sname.Contains(txt_QueryName.Text.Trim())
select stu).ToList();
dgv.DataSource = queryList;
}
private void btn_QueryOrderBy_Click(object sender, EventArgs e)
{
var queryList = (from stu in studentModalList
where stu.Sname.Contains(txt_QueryName.Text.Trim())
orderby stu.Sname descending
select stu).ToList();
dgv.DataSource = queryList;
}
private void btn_QueryGroupBy_Click(object sender, EventArgs e)
{
var queryList = (from stu in studentModalList
group stu by stu.Sage).ToList();
dgv.DataSource = queryList;
}
private void btn_Max_Click(object sender, EventArgs e)
{
//var queryList = studentModalList.Max(x => x.Sage);
var queryList = (from stu in studentModalList
orderby stu.Sage descending
select stu).Take(1).ToList();
dgv.DataSource = queryList;
}
private void btn_Avg_Click(object sender, EventArgs e)
{
var queryList = studentModalList.Average(x => x.Sage);
}
private void btn_Sum_Click(object sender, EventArgs e)
{
var queryList = studentModalList.Sum(x => x.Sage);
}
int page = 1;
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
page = 1;
var pageList = (from stu in studentModalList
orderby stu.Sname descending
select stu).Skip((page - 1) * 5)
.ToList().Take(5).ToList();
dgv.DataSource = pageList;
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
page = page - 1 > 1 ? page - 1 : 1;
var pageList = (from stu in studentModalList
orderby stu.Sname descending
select stu).Skip((page - 1) * 5)
.ToList().Take(5).ToList();
dgv.DataSource = pageList;
}
private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
int maxpage = studentModalList.Count() % 5 == 0 ? studentModalList.Count() / 5 : (studentModalList.Count() / 5) + 1;
page = page + 1 < maxpage ? page + 1 : maxpage;
var pageList = (from stu in studentModalList
orderby stu.Sname descending
select stu).Skip((page - 1) * 5)
.ToList().Take(5).ToList();
dgv.DataSource = pageList;
}
private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
page = studentModalList.Count() % 5 == 0 ? studentModalList.Count() / 5 : (studentModalList.Count() / 5) + 1;
var pageList = (from stu in studentModalList
orderby stu.Sname descending
select stu).Skip((page - 1) * 5)
.ToList().Take(5).ToList();
dgv.DataSource = pageList;
}
private void btn_DataTable_Click(object sender, EventArgs e)
{
dgv.DataSource = studentBLL.FindStudentsAllDataTable(new StudentModal()
{
Sname = txt_QueryName.Text.Trim()
});
//DataTable dt = studentBLL.FindStudentsAllDataTable();
dt.AsEnumerable() 将datayable 转换成为一个简单的迭代器的泛型结合
stu.Field<string>("sname") <当前需要作为查询条件的字段的数据类型>(字段的名称)
//var queryList = (from stu in dt.AsEnumerable()
// where stu.Field<string>("sname").Contains
// (txt_QueryName.Text.Trim())
// select stu).ToList();
//List<StudentModal> studentModalList = new List<StudentModal>();
//foreach (var item in queryList)
//{
// studentModalList.Add(new StudentModal()
// {
// Sname = item.Field<string>("sname"),
// Sid = item.Field<Guid>("sid")
// });
//}
// dgv.DataSource = queryList;
}
private void btn_join_Click(object sender, EventArgs e)
{
List<StudentModal> studentModalList = new StudentBLL().FindStudentsAll();
List<GradeModal> gradeModalList = new GradeBLL().FindGradeAll();
var queryList = (from stu in studentModalList
where stu.Sname.Contains(txt_QueryName.Text.Trim())
join gra in gradeModalList
on stu.gid equals gra.Gid
select new
{
stuName = stu.Sname,
stuGname = gra.Gname,
stuAge = stu.Sage
}).ToList();
dgv.DataSource = queryList;
}
}
}
语法糖(Frm_07)
最新推荐文章于 2023-04-03 18:15:18 发布