|
沙发
楼主 |
发表于 2013-10-22 11:04:55
|
只看该作者
/// <summary>
/// 分页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindDataGrid();
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
SortField = string.Format(@"{0}", e.SortField);
SortDirection = e.SortDirection;
BindDataGrid();
}
/// <summary>
/// 删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnBatchDelete_Click(object sender, EventArgs e)
{
IEnumerable<int> selectIds = GetSelectIds();
try
{
Log(string.Format(@"删除帐号记录ID:{0}成功。", selectIds));
AccountService.Update(p => selectIds.Contains(p.id), p => new base_account {deleteflag = 1});
Alert.Show("删除成功!", MessageBoxIcon.Information);
BindDataGrid();
}
catch (Exception)
{
Alert.Show("删除失败!", MessageBoxIcon.Warning);
}
}
//protected void btnDelete_Click(object sender, EventArgs e)
//{
// try
// {
// if (Grid1.SelectedRowIndexArray.Length == 0)
// {
// Alert.Show("请至少选择一项!", MessageBoxIcon.Information);
// }
// else if (Grid1.SelectedRowIndexArray.Length > 1)
// {
// Alert.Show("只能选择一项!", MessageBoxIcon.Information);
// }
// else
// {
// int sid = Convert.ToInt32(Grid1.DataKeys[Grid1.SelectedRowIndexArray[0]][0]);
// AccountService.Update(p => p.id == sid, p => new base_account {deleteflag = 1});
// Log(string.Format(@"删除帐号记录ID:{0}成功。", sid));
// Alert.Show("删除成功!", MessageBoxIcon.Information);
// BindDataGrid();
// }
// }
// catch (Exception)
// {
// Alert.Show("删除失败!", MessageBoxIcon.Warning);
// }
//}
/// <summary>
/// 编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnEdit_Click(object sender, EventArgs e)
{
try
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.Show("请至少选择一项!", MessageBoxIcon.Information);
}
else if (Grid1.SelectedRowIndexArray.Length > 1)
{
Alert.Show("只能选择一项!", MessageBoxIcon.Information);
}
else
{
int sid = Convert.ToInt32(Grid1.DataKeys[Grid1.SelectedRowIndexArray[0]][0]);
PageContext.RegisterStartupScript(
Window1.GetShowReference(string.Format("./account_edit.aspx?id={0}&orgid={1}&action=2",
sid, trDept.SelectedNodeID), "编辑用户"));
}
}
catch (Exception)
{
Alert.Show("删除失败!", MessageBoxIcon.Warning);
}
}
/// <summary>
/// 禁用/启用
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnEnabled_Click(object sender, EventArgs e)
{
try
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.Show("请至少选择一项!", MessageBoxIcon.Information);
}
else if (Grid1.SelectedRowIndexArray.Length > 1)
{
Alert.Show("只能选择一项!", MessageBoxIcon.Information);
}
else
{
int sid = Convert.ToInt32(Grid1.DataKeys[Grid1.SelectedRowIndexArray[0]][0]);
base_account account = AccountService.FirstOrDefault(p => p.id == sid);
account.account_flag = account.account_flag == 1 ? 0 : 1;
if (AccountService.SaveChanges() > 0)
{
BindDataGrid();
Alert.Show("提交成功。", MessageBoxIcon.Information);
//记录日志
Log(string.Format(@"禁用帐号{0}成功。", account.account_number));
}
else
{
Alert.Show("提交失败,请重试!", MessageBoxIcon.Error);
}
}
}
catch (Exception)
{
Alert.Show("删除失败!", MessageBoxIcon.Warning);
}
}
/// <summary>
/// 初始化密码
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnInitPassword_Click(object sender, EventArgs e)
{
IEnumerable<int> selectIds = GetSelectIds();
try
{
AccountService.Update(p => selectIds.Contains(p.id),
p => new base_account {account_password = LHEncrypt.Encrypt("123456")});
Alert.Show("密码初始化成功!", MessageBoxIcon.Information);
BindDataGrid();
}
catch (Exception)
{
Alert.Show("密码初始化失败!", MessageBoxIcon.Warning);
}
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSearch_Click(object sender, EventArgs e)
{
BindDataGrid();
}
/// <summary>
/// 导出本页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnExport_Click(object sender, EventArgs e)
{
int output;
dynamic orderingSelector;
Expression<Func<base_account, bool>> predicate = BuildPredicate(out orderingSelector);
//取数据源
IQueryable<base_account> list = AccountService.Where(predicate, Grid1.PageSize, Grid1.PageIndex + 1,
orderingSelector, EnumHelper.ParseEnumByString<OrderingOrders>(SortDirection), out output);
ExportData(list);
}
|
|