using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web.HSSE.InformationProject
{
public partial class ConstructionStandardIdentify : PageBase
{
#region 加载页面
///
/// 加载页面
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Funs.DropDownPageSize(this.ddlPageSize);
////权限按钮方法
this.GetButtonPower();
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
// 绑定表格
BindGrid();
}
}
#endregion
#region 绑定数据
///
/// 查询
///
///
///
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
///
/// 绑定数据
///
private void BindGrid()
{
string projectId = this.CurrUser.LoginProjectId;
if (!string.IsNullOrEmpty(Request.Params["projectId"]))
{
projectId = Request.Params["projectId"];
}
List q = (from x in Funs.DB.View_InformationProject_ConstructionStandardIdentify
where x.ProjectId == projectId && x.State == BLL.Const.State_2
orderby x.IdentifyDate descending
select x).ToList();
if (!string.IsNullOrEmpty(txtConstructionStandardIdentifyCode.Text.Trim()))
{
q = q.Where(e => e.ConstructionStandardIdentifyCode.Contains(txtConstructionStandardIdentifyCode.Text.Trim())).ToList();
}
Grid1.RecordCount = q.Count();
// 2.获取当前分页数据
var table = GetPagedDataTable(Grid1.PageIndex, Grid1.PageSize);
Grid1.DataSource = table;
Grid1.DataBind();
}
///
/// 分页
///
///
private List GetPagedDataTable(int pageIndex, int pageSize)
{
List source = new List();
source = (from x in Funs.DB.View_InformationProject_ConstructionStandardIdentify
where x.ProjectId == this.CurrUser.LoginProjectId
orderby x.IdentifyDate descending
select x).ToList();
if (!string.IsNullOrEmpty(txtConstructionStandardIdentifyCode.Text.Trim()))
{
source = source.Where(e => e.ConstructionStandardIdentifyCode.Contains(txtConstructionStandardIdentifyCode.Text.Trim())).ToList();
}
List paged = new List();
int rowbegin = pageIndex * pageSize;
int rowend = (pageIndex + 1) * pageSize;
if (rowend > source.Count())
{
rowend = source.Count();
}
for (int i = rowbegin; i < rowend; i++)
{
paged.Add(source[i]);
}
return paged;
}
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
///
/// 分页下拉选择
///
///
///
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
protected void Grid1_FilterChange(object sender, EventArgs e)
{
BindGrid();
}
protected void Window1_Close(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region 编辑
///
/// 双击事件
///
///
///
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
///
/// 右键编辑事件
///
///
///
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
this.EditData();
}
///
/// 编辑数据方法
///
private void EditData()
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string id = Grid1.SelectedRowID;
var constructionStandardIdentify = BLL.ConstructionStandardIdentifyService.GetConstructionStandardIdentifyById(id);
if (constructionStandardIdentify != null)
{
if (constructionStandardIdentify.State == BLL.Const.State_2) ////双击事件 编辑权限有:编辑页面,无:查看页面 或者状态是完成时查看页面
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ConstructionStandardIdentifyView.aspx?ConstructionStandardIdentifyId={0}", id, "查看 - ")));
}
else
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ConstructionStandardIdentifyEdit.aspx?ConstructionStandardIdentifyId={0}", id, "编辑 - ")));
}
}
}
#endregion
#region 增加、删除数据方法
///
/// 增加按钮事件
///
///
///
protected void btnNew_Click(object sender, EventArgs e)
{
int count = BLL.ConstructionStandardIdentifyService.GetConstructionStandardIdentifyByVersionIsNull(this.CurrUser.LoginProjectId);
if (count == 0)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ConstructionStandardIdentifyEdit.aspx", "选择 - ")));
}
else
{
Alert.ShowInTop("标准规范版本号还未生成,不能编制!", MessageBoxIcon.Warning);
return;
}
}
///
/// 右键删除事件
///
///
///
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
this.DeleteData();
}
///
/// 删除方法
///
private void DeleteData()
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string constructionStandardIdentifyId = Grid1.DataKeys[rowIndex][0].ToString();
var getD = BLL.ConstructionStandardIdentifyService.GetConstructionStandardIdentifyById(constructionStandardIdentifyId);
if (getD != null)
{
BLL.ConstructionStandardSelectedItemService.DeleteConstructionStandardSelectedItemByConstructionStandardIdentifyId(constructionStandardIdentifyId);
BLL.ConstructionStandardIdentifyService.DeleteConstructionStandardIdentifyById(constructionStandardIdentifyId);
BLL.LogService.AddSys_Log(this.CurrUser, getD.ConstructionStandardIdentifyCode, getD.ConstructionStandardIdentifyId, BLL.Const.ConstructionStandardIdentifyMenuId, BLL.Const.BtnDelete);
}
}
BindGrid();
}
}
#endregion
#region 获取按钮权限
///
/// 获取按钮权限
///
///
///
private void GetButtonPower()
{
if (Request.Params["value"] == "0")
{
return;
}
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.ConstructionStandardIdentifyMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnAdd))
{
this.btnNew.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnModify))
{
this.btnMenuEdit.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.btnMenuDelete.Hidden = false;
}
}
}
#endregion
#region 导出按钮
/// 导出按钮
///
///
///
protected void btnOut_Click(object sender, EventArgs e)
{
Response.ClearContent();
string filename = Funs.GetNewFileName();
Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("标准规范清单" + filename, System.Text.Encoding.UTF8) + ".xls");
Response.ContentType = "application/excel";
Response.ContentEncoding = System.Text.Encoding.UTF8;
this.Grid1.PageSize = 500;
this.BindGrid();
Response.Write(GetGridTableHtml(Grid1));
Response.End();
}
#pragma warning disable CS0108 // “ConstructionStandardIdentify.GetGridTableHtml(Grid)”隐藏继承的成员“PageBase.GetGridTableHtml(Grid)”。如果是有意隐藏,请使用关键字 new。
///
/// 导出方法
///
///
///
private string GetGridTableHtml(Grid grid)
#pragma warning restore CS0108 // “ConstructionStandardIdentify.GetGridTableHtml(Grid)”隐藏继承的成员“PageBase.GetGridTableHtml(Grid)”。如果是有意隐藏,请使用关键字 new。
{
StringBuilder sb = new StringBuilder();
sb.Append("");
sb.Append("");
sb.Append("");
foreach (GridColumn column in grid.Columns)
{
sb.AppendFormat("{0} | ", column.HeaderText);
}
sb.Append("
");
foreach (GridRow row in grid.Rows)
{
sb.Append("");
foreach (GridColumn column in grid.Columns)
{
string html = row.Values[column.ColumnIndex].ToString();
if (column.ColumnID == "tfNumber")
{
html = (row.FindControl("lblNumber") as AspNet.Label).Text;
}
sb.AppendFormat("{0} | ", html);
}
sb.Append("
");
}
sb.Append("
");
return sb.ToString();
}
#endregion
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
BindGrid();
}
}
}