2024-05-16 14:30:14 +08:00
|
|
|
|
using BLL;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Data.SqlClient;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Web.UI;
|
|
|
|
|
using System.Web.UI.WebControls;
|
|
|
|
|
|
|
|
|
|
namespace FineUIPro.Web.Email_Send
|
|
|
|
|
{
|
|
|
|
|
public partial class SelectUserControl : System.Web.UI.UserControl
|
|
|
|
|
{
|
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!IsPostBack)
|
|
|
|
|
{
|
2024-05-16 15:50:44 +08:00
|
|
|
|
BindGrid("");
|
|
|
|
|
DataBindDrpUnit();
|
2024-05-16 14:30:14 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region BindGrid
|
|
|
|
|
|
|
|
|
|
|
2024-05-16 15:50:44 +08:00
|
|
|
|
private void BindGrid(string selectUnitId)
|
2024-05-16 14:30:14 +08:00
|
|
|
|
{
|
|
|
|
|
// 1.设置总项数(特别注意:数据库分页一定要设置总记录数RecordCount)
|
2024-05-16 15:50:44 +08:00
|
|
|
|
Grid1.RecordCount = GetTotalCount(selectUnitId);
|
2024-05-16 14:30:14 +08:00
|
|
|
|
|
|
|
|
|
// 2.获取当前分页数据
|
2024-05-16 15:50:44 +08:00
|
|
|
|
DataTable table = GetPagedDataTable(selectUnitId);
|
2024-05-16 14:30:14 +08:00
|
|
|
|
|
|
|
|
|
// 3.绑定到Grid
|
|
|
|
|
Grid1.DataSource = table;
|
|
|
|
|
Grid1.DataBind();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 模拟返回总项数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2024-05-16 15:50:44 +08:00
|
|
|
|
private int GetTotalCount(string selectUnitId)
|
2024-05-16 14:30:14 +08:00
|
|
|
|
{
|
2024-05-16 15:50:44 +08:00
|
|
|
|
return GetSource(selectUnitId).Rows.Count;
|
2024-05-16 14:30:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-16 15:50:44 +08:00
|
|
|
|
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("请选择单位",""));
|
|
|
|
|
}
|
2024-05-16 14:30:14 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 模拟数据库分页(实际项目中请直接使用SQL语句返回分页数据!)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2024-05-16 15:50:44 +08:00
|
|
|
|
private DataTable GetPagedDataTable(string selectUnitId)
|
2024-05-16 14:30:14 +08:00
|
|
|
|
{
|
|
|
|
|
int pageIndex = Grid1.PageIndex;
|
|
|
|
|
int pageSize = Grid1.PageSize;
|
|
|
|
|
|
2024-05-16 15:50:44 +08:00
|
|
|
|
DataTable table = GetSource(selectUnitId);
|
2024-05-16 14:30:14 +08:00
|
|
|
|
|
|
|
|
|
DataTable paged = table.Clone();
|
|
|
|
|
int rowbegin = pageIndex * pageSize;
|
|
|
|
|
int rowend = (pageIndex + 1) * pageSize;
|
|
|
|
|
if (rowend > table.Rows.Count)
|
|
|
|
|
{
|
|
|
|
|
rowend = table.Rows.Count;
|
|
|
|
|
}
|
|
|
|
|
for (int i = rowbegin; i < rowend; i++)
|
|
|
|
|
{
|
|
|
|
|
paged.ImportRow(table.Rows[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return paged;
|
|
|
|
|
}
|
2024-05-16 15:50:44 +08:00
|
|
|
|
protected void drpSearch_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string rowId = this.drpSearch.SelectedValue;
|
|
|
|
|
this.BindGrid(rowId);
|
|
|
|
|
}
|
|
|
|
|
private DataTable GetSource(string selectUnitId)
|
2024-05-16 14:30:14 +08:00
|
|
|
|
{
|
|
|
|
|
string sortField = Grid1.SortField;
|
|
|
|
|
string sortDirection = Grid1.SortDirection;
|
|
|
|
|
|
2024-05-17 15:28:32 +08:00
|
|
|
|
string strSql = @"select a.UserId,b.UnitId,b.UserName,c.UnitName,b.Email from Project_User as a inner join Sys_User as b on a.UserId=b.UserId
|
2024-05-16 15:50:44 +08:00
|
|
|
|
inner join Base_Unit as c on b.UnitId=c.UnitId where b.IsPost=1 order by c.UnitName ";
|
2024-05-16 14:30:14 +08:00
|
|
|
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|
|
|
|
SqlParameter[] parameter = listStr.ToArray();
|
|
|
|
|
DataTable table2 = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|
|
|
|
|
|
|
|
|
DataView view2 = table2.DefaultView;
|
2024-05-16 15:50:44 +08:00
|
|
|
|
|
2024-05-16 14:30:14 +08:00
|
|
|
|
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/
|
2024-05-16 15:50:44 +08:00
|
|
|
|
filters.Add(String.Format("(UnitName LIKE '*{0}*' or UserName like '*{0}*')", EscapeLikeValue(searchKeyword)));
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrEmpty(selectUnitId))
|
|
|
|
|
{
|
|
|
|
|
filters.Add(string.Format(" UnitId='{0}'", selectUnitId));
|
2024-05-16 14:30:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (filters.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
view2.RowFilter = String.Join(" AND ", filters.ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return view2.ToTable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// From: http://www.csharp-examples.net/dataview-rowfilter/
|
|
|
|
|
public static string EscapeLikeValue(string valueWithoutWildcards)
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
for (int i = 0; i < valueWithoutWildcards.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
char c = valueWithoutWildcards[i];
|
|
|
|
|
if (c == '*' || c == '%' || c == '[' || c == ']')
|
|
|
|
|
sb.Append("[").Append(c).Append("]");
|
|
|
|
|
else if (c == '\'')
|
|
|
|
|
sb.Append("''");
|
|
|
|
|
else
|
|
|
|
|
sb.Append(c);
|
|
|
|
|
}
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Events
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//Grid1.PageIndex = e.NewPageIndex;
|
|
|
|
|
|
2024-05-16 15:50:44 +08:00
|
|
|
|
BindGrid(string.Empty); ;
|
2024-05-16 14:30:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void Grid1_Sort(object sender, GridSortEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
//Grid1.SortDirection = e.SortDirection;
|
|
|
|
|
//Grid1.SortField = e.SortField;
|
|
|
|
|
|
2024-05-16 15:50:44 +08:00
|
|
|
|
BindGrid(string.Empty);
|
2024-05-16 14:30:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void ttbSearch_Trigger1Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ttbSearch.Text = String.Empty;
|
|
|
|
|
ttbSearch.ShowTrigger1 = false;
|
|
|
|
|
|
2024-05-16 15:50:44 +08:00
|
|
|
|
BindGrid(string.Empty);
|
2024-05-16 14:30:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void ttbSearch_Trigger2Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ttbSearch.ShowTrigger1 = true;
|
|
|
|
|
|
2024-05-16 15:50:44 +08:00
|
|
|
|
BindGrid(string.Empty);
|
2024-05-16 14:30:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|