2023-08-23
This commit is contained in:
@@ -0,0 +1,300 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using BLL;
|
||||
using Model;
|
||||
|
||||
namespace FineUIPro.Web.PHTGL.BillOfQuantities
|
||||
{
|
||||
public partial class TemQuantityList : PageBase
|
||||
{
|
||||
public string Type
|
||||
{
|
||||
get => (string)ViewState["Type"];
|
||||
set => ViewState["Type"] = value;
|
||||
}
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack)
|
||||
{
|
||||
Type = Request.Params["Type"];
|
||||
GetButtonPower();
|
||||
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
|
||||
// 绑定表格
|
||||
BindGrid();
|
||||
}
|
||||
}
|
||||
|
||||
#region 绑定数据
|
||||
|
||||
/// <summary>
|
||||
/// 绑定数据
|
||||
/// </summary>
|
||||
private void BindGrid()
|
||||
{
|
||||
var table = new PHTGL_Quantity();
|
||||
table.Major = BLL.PHTGL_QuantityService.GetMajorItems().Where(x => x.Text == Type).Select(x => x.Value).FirstOrDefault() ?? "";
|
||||
table.SubProject = txtSubProject.Text.Trim() ?? "";
|
||||
table.SubItemProject = txtSubItemProject.Text.Trim() ?? "";
|
||||
table.ProjectCode = txtProjectCode.Text.Trim() ?? "";
|
||||
table.ProjectName = txtProjectName.Text.Trim() ?? "";
|
||||
table.IsTemplate = true;
|
||||
var tb = PHTGL_QuantityService.getListData(table, Grid1);
|
||||
Grid1.RecordCount = PHTGL_QuantityService.count;
|
||||
//tb = GetFilteredTable(Grid1.FilteredData, tb);
|
||||
Grid1.DataSource = tb;
|
||||
Grid1.DataBind();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 关闭弹出窗
|
||||
|
||||
/// <summary>
|
||||
/// 关闭弹出窗
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void Window1_Close(object sender, WindowCloseEventArgs e)
|
||||
{
|
||||
BindGrid();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取权限按钮
|
||||
|
||||
/// <summary>
|
||||
/// 获取按钮权限
|
||||
/// </summary>
|
||||
/// <param name="button"></param>
|
||||
/// <returns></returns>
|
||||
private void GetButtonPower()
|
||||
{
|
||||
var menuid = "";
|
||||
switch (Type)
|
||||
{
|
||||
case "0":
|
||||
menuid = Const.TemQuantityListMenuId0;
|
||||
break;
|
||||
case "1":
|
||||
menuid = Const.TemQuantityListMenuId1;
|
||||
break;
|
||||
case "2":
|
||||
menuid = Const.TemQuantityListMenuId2;
|
||||
break;
|
||||
case "3":
|
||||
menuid = Const.TemQuantityListMenuId3;
|
||||
break;
|
||||
case "4":
|
||||
menuid = Const.TemQuantityListMenuId4;
|
||||
break;
|
||||
case "5":
|
||||
menuid = Const.TemQuantityListMenuId5;
|
||||
break;
|
||||
case "6":
|
||||
menuid = Const.TemQuantityListMenuId6;
|
||||
break;
|
||||
case "7":
|
||||
menuid = Const.TemQuantityListMenuId7;
|
||||
break;
|
||||
case "8":
|
||||
menuid = Const.TemQuantityListMenuId8;
|
||||
break;
|
||||
case "9":
|
||||
menuid = Const.TemQuantityListMenuId9;
|
||||
break;
|
||||
}
|
||||
|
||||
var buttonList = CommonService.GetAllButtonList(CurrUser.LoginProjectId, CurrUser.PersonId, menuid);
|
||||
if (buttonList.Count > 0)
|
||||
{
|
||||
if (buttonList.Contains(Const.BtnAdd)) btnNew.Hidden = false;
|
||||
if (buttonList.Contains(Const.BtnModify)) btnMenuEdit.Hidden = false;
|
||||
if (buttonList.Contains(Const.BtnDelete)) btnMenuDelete.Hidden = false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 导入
|
||||
|
||||
/// <summary>
|
||||
/// 导入按钮
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void btnImport_Click(object sender, EventArgs e)
|
||||
{
|
||||
PageContext.RegisterStartupScript(
|
||||
Window2.GetShowReference(string.Format("TemQuantityIn.aspx?Type={0}", Type, "导入 - ")));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region GV 数据操作
|
||||
|
||||
/// <summary>
|
||||
/// 分页
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
||||
{
|
||||
Grid1.PageIndex = e.NewPageIndex;
|
||||
BindGrid();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 排序
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void Grid1_Sort(object sender, GridSortEventArgs e)
|
||||
{
|
||||
Grid1.SortDirection = e.SortDirection;
|
||||
Grid1.SortField = e.SortField;
|
||||
BindGrid();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页显示条数下拉框
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
|
||||
BindGrid();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 数据编辑事件
|
||||
|
||||
/// <summary>
|
||||
/// 新增
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void btnNew_Click(object sender, EventArgs e)
|
||||
{
|
||||
PageContext.RegisterStartupScript(
|
||||
Window1.GetShowReference(string.Format("PHTGL_QuantityEdit.aspx?Id={0}&Type={1}", string.Empty,Type, "增加 - ")));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑按钮
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void btnEdit_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (Grid1.SelectedRowIndexArray.Length == 0)
|
||||
{
|
||||
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var ID = Grid1.SelectedRowID;
|
||||
var model = PHTGL_QuantityService.GetPHTGL_QuantityById(ID);
|
||||
if (model != null) ///已上报时不能删除
|
||||
PageContext.RegisterStartupScript(
|
||||
Window1.GetShowReference(string.Format("PHTGL_QuantityEdit.aspx?Id={0}", ID, "编辑 - ")));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grid行双击事件
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
|
||||
{
|
||||
btnEdit_Click(null, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量删除
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void btnDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (Grid1.SelectedRowIndexArray.Length > 0)
|
||||
{
|
||||
foreach (var rowIndex in Grid1.SelectedRowIndexArray)
|
||||
{
|
||||
var rowID = Grid1.DataKeys[rowIndex][0].ToString();
|
||||
var model = PHTGL_QuantityService.GetPHTGL_QuantityById(rowID);
|
||||
if (model != null) PHTGL_QuantityService.DeletePHTGL_QuantityById(rowID);
|
||||
}
|
||||
|
||||
BindGrid();
|
||||
ShowNotify("删除数据成功!", MessageBoxIcon.Success);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 导出按钮
|
||||
|
||||
/// 导出按钮
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void btnOut_Click(object sender, EventArgs e)
|
||||
{
|
||||
Response.ClearContent();
|
||||
var filename = Funs.GetNewFileName();
|
||||
Response.AddHeader("content-disposition",
|
||||
"attachment; filename=" + HttpUtility.UrlEncode("" + filename, Encoding.UTF8) + ".xls");
|
||||
Response.ContentType = "application/excel";
|
||||
Response.ContentEncoding = Encoding.UTF8;
|
||||
Grid1.PageSize = 500;
|
||||
BindGrid();
|
||||
Response.Write(GetGridTableHtml(Grid1));
|
||||
Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出方法
|
||||
/// </summary>
|
||||
/// <param name="grid"></param>
|
||||
/// <returns></returns>
|
||||
private string GetGridTableHtml(Grid grid)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
|
||||
sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
|
||||
sb.Append("<tr>");
|
||||
foreach (var column in grid.Columns) sb.AppendFormat("<td>{0}</td>", column.HeaderText);
|
||||
sb.Append("</tr>");
|
||||
foreach (var row in grid.Rows)
|
||||
{
|
||||
sb.Append("<tr>");
|
||||
foreach (var column in grid.Columns)
|
||||
{
|
||||
var html = row.Values[column.ColumnIndex].ToString();
|
||||
if (column.ColumnID == "tfNumber")
|
||||
html = (row.FindControl("lblNumber") as System.Web.UI.WebControls.Label).Text;
|
||||
sb.AppendFormat("<td>{0}</td>", html);
|
||||
}
|
||||
|
||||
sb.Append("</tr>");
|
||||
}
|
||||
|
||||
sb.Append("</table>");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected void btnSearch_Click(object sender, EventArgs e)
|
||||
{
|
||||
BindGrid();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user