286 lines
		
	
	
		
			9.9 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			286 lines
		
	
	
		
			9.9 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using BLL; | |||
|  | using System; | |||
|  | using System.Data; | |||
|  | using System.Data.SqlClient; | |||
|  | using System.Linq; | |||
|  | using System.Text; | |||
|  | using AspNet = System.Web.UI.WebControls; | |||
|  | 
 | |||
|  | namespace FineUIPro.Web.OfficeCheck.ProjectEvaluation | |||
|  | { | |||
|  |     public partial class ProjectEvaluation : PageBase | |||
|  |     { | |||
|  |         protected void Page_Load(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (!IsPostBack) | |||
|  |             { | |||
|  |                 Funs.DropDownPageSize(this.ddlPageSize); | |||
|  |                 ////权限按钮方法 | |||
|  |                 this.GetButtonPower(); | |||
|  |                 if (this.CurrUser != null && this.CurrUser.PageSize.HasValue) | |||
|  |                 { | |||
|  |                     Grid1.PageSize = this.CurrUser.PageSize.Value; | |||
|  |                 }  | |||
|  |                 this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); | |||
|  | 
 | |||
|  |                 BindGrid2(); | |||
|  |                 BindGrid1(); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 加载Grid2 | |||
|  |         /// </summary> | |||
|  |         private void BindGrid2() | |||
|  |         { | |||
|  |             Grid2.DataSource = from x in Funs.DB.Base_Project                                | |||
|  |                                orderby x.ProjectCode  | |||
|  |                                select x; | |||
|  |             Grid2.DataBind(); | |||
|  |             Grid2.SelectedRowIndex = 0; | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 加载Grid1 | |||
|  |         /// </summary> | |||
|  |         private void BindGrid1() | |||
|  |         { | |||
|  |             if (Grid2.SelectedRowIndex < 0) | |||
|  |             { | |||
|  |                 return; | |||
|  |             } | |||
|  |             string projectId = Convert.ToString(Grid2.DataKeys[Grid2.SelectedRowIndex][0]); | |||
|  |             if (!string.IsNullOrEmpty(projectId)) | |||
|  |             { | |||
|  |                 string strSql = "select * from dbo.ProjectSupervision_ProjectEvaluation where ProjectId = @ProjectId"; | |||
|  |                 SqlParameter[] parameter = new SqlParameter[]        | |||
|  |                     { | |||
|  |                         new SqlParameter("@ProjectId",projectId), | |||
|  |                     }; | |||
|  |                 DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); | |||
|  |                 Grid1.RecordCount = tb.Rows.Count; | |||
|  |                 var table = this.GetPagedDataTable(Grid1, tb); | |||
|  |                 Grid1.DataSource = table; | |||
|  |                 Grid1.DataBind(); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// Grid2行选择事件 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void Grid2_RowSelect(object sender, GridRowSelectEventArgs e) | |||
|  |         { | |||
|  |             BindGrid1(); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 增加按钮 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void btnNew_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             string projectId = Convert.ToString(Grid2.DataKeys[Grid2.SelectedRowIndex][0]); | |||
|  |             if (!string.IsNullOrEmpty(projectId)) | |||
|  |             { | |||
|  |                 PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ProjectEvaluationEdit.aspx?ProjectId={0}", projectId, "编辑 - ")));                | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 ShowNotify("请选择一个单位!",MessageBoxIcon.Warning); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 修改按钮 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void btnMenuEdit_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (Grid1.SelectedRowIndexArray.Length == 0) | |||
|  |             { | |||
|  |                 Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); | |||
|  |                 return; | |||
|  |             } | |||
|  |             string Id = Grid1.SelectedRowID; | |||
|  |             PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ProjectEvaluationEdit.aspx?PerfomanceRecordId={0}", Id, "编辑 - "))); | |||
|  | 
 | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// Grid1行双击事件 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) | |||
|  |         { | |||
|  |             btnMenuEdit_Click(null, null); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 删除按钮 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void btnMenuDelete_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (Grid1.SelectedRowIndexArray.Length > 0) | |||
|  |             { | |||
|  |                 foreach (int rowIndex in Grid1.SelectedRowIndexArray) | |||
|  |                 { | |||
|  |                     string rowID = Grid1.DataKeys[rowIndex][0].ToString(); | |||
|  |                     BLL.ProjectEvaluationService.DeletePerfomanceRecordById(rowID); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 BindGrid1(); | |||
|  |                 ShowNotify("删除数据成功!", MessageBoxIcon.Success); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         #region 分页 | |||
|  |         /// <summary> | |||
|  |         /// 分页 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) | |||
|  |         { | |||
|  |             BindGrid1(); | |||
|  |         } | |||
|  |                 | |||
|  |         /// <summary> | |||
|  |         /// 排序 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void Grid1_Sort(object sender, GridSortEventArgs e) | |||
|  |         { | |||
|  |             BindGrid1(); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 分页下拉选择事件 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) | |||
|  |         { | |||
|  |             Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); | |||
|  |             BindGrid1(); | |||
|  |         } | |||
|  | 
 | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 关闭弹出窗口 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void Window1_Close(object sender, WindowCloseEventArgs e) | |||
|  |         { | |||
|  |             BindGrid1(); | |||
|  |         } | |||
|  | 
 | |||
|  |         #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.ProjectEvaluationMenuId); | |||
|  |             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 = this.Grid1.RecordCount; | |||
|  |             this.BindGrid1(); | |||
|  |             Response.Write(GetGridTableHtml(Grid1)); | |||
|  |             Response.End(); | |||
|  |         } | |||
|  | 
 | |||
|  | #pragma warning disable CS0108 // “ProjectEvaluation.GetGridTableHtml(Grid)”隐藏继承的成员“PageBase.GetGridTableHtml(Grid)”。如果是有意隐藏,请使用关键字 new。 | |||
|  |         /// <summary> | |||
|  |         /// 导出方法 | |||
|  |         /// </summary> | |||
|  |         /// <param name="grid"></param> | |||
|  |         /// <returns></returns> | |||
|  |         private string GetGridTableHtml(Grid grid) | |||
|  | #pragma warning restore CS0108 // “ProjectEvaluation.GetGridTableHtml(Grid)”隐藏继承的成员“PageBase.GetGridTableHtml(Grid)”。如果是有意隐藏,请使用关键字 new。 | |||
|  |         { | |||
|  |             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; | |||
|  |                     } | |||
|  |                     if (column.ColumnID == "tfAssessmentGroup") | |||
|  |                     { | |||
|  |                         html = (row.FindControl("lblAssessmentGroup") as AspNet.Label).Text; | |||
|  |                     } | |||
|  |                     if (column.ColumnID == "tfEvaluationDef") | |||
|  |                     { | |||
|  |                         html = (row.FindControl("lblEvaluationDef") as AspNet.Label).Text; | |||
|  |                     } | |||
|  |                     if (column.ColumnID == "tfAssessmentGroup") | |||
|  |                     { | |||
|  |                         html = (row.FindControl("lblAssessmentGroup") as AspNet.Label).Text; | |||
|  |                     } | |||
|  | 
 | |||
|  |                     sb.AppendFormat("<td>{0}</td>", html); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 sb.Append("</tr>"); | |||
|  |             } | |||
|  | 
 | |||
|  |             sb.Append("</table>"); | |||
|  | 
 | |||
|  |             return sb.ToString(); | |||
|  |         } | |||
|  |         #endregion         | |||
|  |     } | |||
|  | } |