253 lines
		
	
	
		
			9.0 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			253 lines
		
	
	
		
			9.0 KiB
		
	
	
	
		
			C#
		
	
	
	
using System;
 | 
						|
using System.Data;
 | 
						|
using System.Data.SqlClient;
 | 
						|
using System.Text;
 | 
						|
using BLL;
 | 
						|
using AspNet = System.Web.UI.WebControls;
 | 
						|
 | 
						|
namespace FineUIPro.Web.ZHGL.ServerCheck
 | 
						|
{
 | 
						|
    public partial class UpCheckReport : PageBase
 | 
						|
    {
 | 
						|
        protected void Page_Load(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            if (!IsPostBack)
 | 
						|
            {
 | 
						|
                this.GetButtonPower();
 | 
						|
                this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
 | 
						|
                // 绑定表格
 | 
						|
                this.BindGrid();
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        #region 绑定数据
 | 
						|
        /// <summary>
 | 
						|
        /// 绑定数据
 | 
						|
        /// </summary>
 | 
						|
        private void BindGrid()
 | 
						|
        {
 | 
						|
            string strSql = string.Empty;
 | 
						|
            SqlParameter[] parameter = new SqlParameter[] { };
 | 
						|
            strSql = "SELECT Report.UpCheckReportId, Report.UnitId,Unit.UnitName,Report.CheckStartTime,Report.CheckEndTime,Report.CompileDate,Report.AuditDate,Report.UpState,Report.UpDateTime,"
 | 
						|
                       + @" (CASE WHEN Report.UpState='3' THEN '已上报' WHEN Report.UpState='4' THEN '上报失败' ELSE '待上报' END) AS UpStateName"
 | 
						|
                       + @" FROM  Supervise_UpCheckReport AS Report LEFT JOIN Base_Unit AS Unit ON Report.UnitId=Unit.UnitId ORDER BY Report.CheckStartTime DESC";
 | 
						|
 | 
						|
            DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
 | 
						|
            Grid1.RecordCount = tb.Rows.Count;
 | 
						|
            //tb = GetFilteredTable(Grid1.FilteredData, tb);
 | 
						|
            var table = this.GetPagedDataTable(Grid1, tb);
 | 
						|
            Grid1.DataSource = table;
 | 
						|
            Grid1.DataBind();
 | 
						|
        }
 | 
						|
        #endregion
 | 
						|
 | 
						|
        #region GV 数据操作
 | 
						|
        /// <summary>
 | 
						|
        /// 过滤表头
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sender"></param>
 | 
						|
        /// <param name="e"></param>
 | 
						|
        //protected void Grid1_FilterChange(object sender, EventArgs e)
 | 
						|
        //{
 | 
						|
        //    this.BindGrid();
 | 
						|
        //}
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 分页
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sender"></param>
 | 
						|
        /// <param name="e"></param>
 | 
						|
        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
 | 
						|
        {
 | 
						|
            this.Grid1.PageIndex = e.NewPageIndex;
 | 
						|
            this.BindGrid();
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 排序
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sender"></param>
 | 
						|
        /// <param name="e"></param>
 | 
						|
        protected void Grid1_Sort(object sender, GridSortEventArgs e)
 | 
						|
        {
 | 
						|
            this.Grid1.SortDirection = e.SortDirection;
 | 
						|
            this.Grid1.SortField = e.SortField;
 | 
						|
            this.BindGrid();
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 分页显示条数下拉框
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sender"></param>
 | 
						|
        /// <param name="e"></param>
 | 
						|
        protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            this.Grid1.PageSize = Convert.ToInt32(this.ddlPageSize.SelectedValue);
 | 
						|
            this.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("UpCheckReportEdit.aspx?UpCheckReportId={0}", string.Empty, "增加 - ")));
 | 
						|
        }
 | 
						|
 | 
						|
        /// <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;
 | 
						|
            }
 | 
						|
            string upCheckReportId = Grid1.SelectedRowID;
 | 
						|
            var upCheckReport = BLL.UpCheckReportService.GetUpCheckReportById(upCheckReportId);
 | 
						|
            if (upCheckReport != null) ///已上报时不能删除
 | 
						|
            {
 | 
						|
                PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("UpCheckReportEdit.aspx?UpCheckReportId={0}", upCheckReportId, "编辑 - ")));
 | 
						|
            }
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// Grid行双击事件
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sender"></param>
 | 
						|
        /// <param name="e"></param>
 | 
						|
        protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
 | 
						|
        {
 | 
						|
            this.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 (int rowIndex in Grid1.SelectedRowIndexArray)
 | 
						|
                {
 | 
						|
                    string rowID = Grid1.DataKeys[rowIndex][0].ToString();
 | 
						|
                    var upCheckReport = BLL.UpCheckReportService.GetUpCheckReportById(rowID);
 | 
						|
                    if (upCheckReport.UpState != BLL.Const.UpState_3) ///已上报时不能删除
 | 
						|
                    {
 | 
						|
                        BLL.UpCheckReportService.DeleteUpCheckReportItemByUpCheckReportId(rowID);
 | 
						|
                        BLL.UpCheckReportService.DeleteUpCheckReportItem2ByUpCheckReportId(rowID);
 | 
						|
                        BLL.UpCheckReportService.DeleteUpCheckReportById(rowID);
 | 
						|
                    }
 | 
						|
                }
 | 
						|
 | 
						|
                BindGrid();
 | 
						|
                ShowNotify("删除数据成功!", MessageBoxIcon.Success);
 | 
						|
            }
 | 
						|
        }
 | 
						|
        #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 buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.UpCheckReportMenuId);
 | 
						|
            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 导出按钮
 | 
						|
        /// 导出按钮
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sender"></param>
 | 
						|
        /// <param name="e"></param>
 | 
						|
        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();
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 导出方法
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="grid"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        private string GetGridTableHtml(Grid grid)
 | 
						|
        {
 | 
						|
            StringBuilder 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 (GridColumn column in grid.Columns)
 | 
						|
            {
 | 
						|
                sb.AppendFormat("<td>{0}</td>", column.HeaderText);
 | 
						|
            }
 | 
						|
            sb.Append("</tr>");
 | 
						|
            foreach (GridRow row in grid.Rows)
 | 
						|
            {
 | 
						|
                sb.Append("<tr>");
 | 
						|
                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("<td>{0}</td>", html);
 | 
						|
                }
 | 
						|
 | 
						|
                sb.Append("</tr>");
 | 
						|
            }
 | 
						|
 | 
						|
            sb.Append("</table>");
 | 
						|
 | 
						|
            return sb.ToString();
 | 
						|
        }
 | 
						|
        #endregion        
 | 
						|
    }
 | 
						|
} |