This commit is contained in:
jackchenyang
2024-05-16 15:50:44 +08:00
parent d5f90004f5
commit 904833ad7e
13 changed files with 97 additions and 59 deletions
@@ -17,7 +17,8 @@ namespace FineUIPro.Web.Email_Send
{
if (!IsPostBack)
{
BindGrid();
BindGrid("");
DataBindDrpUnit();
}
}
@@ -27,13 +28,13 @@ namespace FineUIPro.Web.Email_Send
#region BindGrid
private void BindGrid()
private void BindGrid(string selectUnitId)
{
// 1.设置总项数(特别注意:数据库分页一定要设置总记录数RecordCount
Grid1.RecordCount = GetTotalCount();
Grid1.RecordCount = GetTotalCount(selectUnitId);
// 2.获取当前分页数据
DataTable table = GetPagedDataTable();
DataTable table = GetPagedDataTable(selectUnitId);
// 3.绑定到Grid
Grid1.DataSource = table;
@@ -44,21 +45,30 @@ namespace FineUIPro.Web.Email_Send
/// 模拟返回总项数
/// </summary>
/// <returns></returns>
private int GetTotalCount()
private int GetTotalCount(string selectUnitId)
{
return GetSource().Rows.Count;
return GetSource(selectUnitId).Rows.Count;
}
private void DataBindDrpUnit()
{
var data = Funs.DB.Base_Unit.ToList();
drpSearch.DataSource = data;
drpSearch.DataTextField = "UnitName";
drpSearch.DataValueField = "UnitId";
drpSearch.DataBind();
drpSearch.Items.Insert(0,new ListItem("请选择单位",""));
}
/// <summary>
/// 模拟数据库分页(实际项目中请直接使用SQL语句返回分页数据!)
/// </summary>
/// <returns></returns>
private DataTable GetPagedDataTable()
private DataTable GetPagedDataTable(string selectUnitId)
{
int pageIndex = Grid1.PageIndex;
int pageSize = Grid1.PageSize;
DataTable table = GetSource();
DataTable table = GetSource(selectUnitId);
DataTable paged = table.Clone();
int rowbegin = pageIndex * pageSize;
@@ -74,30 +84,36 @@ namespace FineUIPro.Web.Email_Send
return paged;
}
private DataTable GetSource()
protected void drpSearch_SelectedIndexChanged(object sender, EventArgs e)
{
string rowId = this.drpSearch.SelectedValue;
this.BindGrid(rowId);
}
private DataTable GetSource(string selectUnitId)
{
string sortField = Grid1.SortField;
string sortDirection = Grid1.SortDirection;
string strSql = @"select UserId,UserName,Email from Sys_User where 1=1";
string strSql = @"select a.UserId,b.UnitId,b.UserName,c.UnitName from Project_User as a inner join Sys_User as b on a.UserId=b.UserId
inner join Base_Unit as c on b.UnitId=c.UnitId where b.IsPost=1 order by c.UnitName ";
List<SqlParameter> listStr = new List<SqlParameter>();
SqlParameter[] parameter = listStr.ToArray();
DataTable table2 = SQLHelper.GetDataTableRunText(strSql, parameter);
DataView view2 = table2.DefaultView;
view2.Sort = String.Format("{0} {1}", sortField, sortDirection);
List<string> filters = new List<string>();
string searchKeyword = ttbSearch.Text.Trim();
if (!String.IsNullOrEmpty(searchKeyword) && ttbSearch.ShowTrigger1)
{
// RowFilter的用法:http://www.csharp-examples.net/dataview-rowfilter/
filters.Add(String.Format("UserName LIKE '*{0}*'", EscapeLikeValue(searchKeyword)));
filters.Add(String.Format("(UnitName LIKE '*{0}*' or UserName like '*{0}*')", EscapeLikeValue(searchKeyword)));
}
if (!string.IsNullOrEmpty(selectUnitId))
{
filters.Add(string.Format(" UnitId='{0}'", selectUnitId));
}
if (filters.Count > 0)
{
@@ -137,7 +153,7 @@ namespace FineUIPro.Web.Email_Send
{
//Grid1.PageIndex = e.NewPageIndex;
BindGrid();
BindGrid(string.Empty); ;
}
protected void Grid1_Sort(object sender, GridSortEventArgs e)
@@ -145,7 +161,7 @@ namespace FineUIPro.Web.Email_Send
//Grid1.SortDirection = e.SortDirection;
//Grid1.SortField = e.SortField;
BindGrid();
BindGrid(string.Empty);
}
@@ -154,14 +170,14 @@ namespace FineUIPro.Web.Email_Send
ttbSearch.Text = String.Empty;
ttbSearch.ShowTrigger1 = false;
BindGrid();
BindGrid(string.Empty);
}
protected void ttbSearch_Trigger2Click(object sender, EventArgs e)
{
ttbSearch.ShowTrigger1 = true;
BindGrid();
BindGrid(string.Empty);
}