using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using BLL; namespace FineUIPro.Web.BaseInfo { public partial class PerfomanceContent : PageBase { #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ////权限按钮方法 this.GetButtonPower(); Funs.DropDownPageSize(this.ddlPageSize); Funs.FineUIPleaseSelect(this.drpCertificateType); ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); // 绑定表格 BindGrid(); } } /// /// 绑定数据 /// private void BindGrid() { int type = int.Parse(drpType.SelectedValue); var q = from x in Funs.DB.Perfomance_PerfomanceContent where x.PerfomanceType == type orderby x.ShowIndex select x; Grid1.RecordCount = q.Count(); // 2.获取当前分页数据 var table = GetPagedDataTable(Grid1.PageIndex, Grid1.PageSize); Grid1.DataSource = table; Grid1.DataBind(); } /// /// 过滤表头 /// /// /// protected void Grid1_FilterChange(object sender, EventArgs e) { BindGrid(); } /// /// 分页 /// /// private List GetPagedDataTable(int pageIndex, int pageSize) { int type = int.Parse(drpType.SelectedValue); List source = (from x in Funs.DB.Perfomance_PerfomanceContent where x.PerfomanceType == type orderby x.ShowIndex select x).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(); } #endregion #region 分页下拉选择 /// /// 分页下拉选择 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #region 删除 /// /// 删除 /// /// /// protected void btnDelete_Click(object sender, EventArgs e) { var getV = BLL.PerfomanceContentService.GetPerfomanceContentById(hfFormID.Text); if (getV != null) { BLL.LogService.AddSys_Log(this.CurrUser, getV.PerfomanceContent, getV.PerfomanceId, BLL.Const.CertificateMenuId, BLL.Const.BtnDelete); BLL.PerfomanceContentService.DeletePerfomanceContentById(getV.PerfomanceId); // 重新绑定表格,并模拟点击[新增按钮] BindGrid(); PageContext.RegisterStartupScript("onNewButtonClick();"); } } /// /// 右键删除事件 /// /// /// 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 rowID = Grid1.DataKeys[rowIndex][0].ToString(); var getV = BLL.PerfomanceContentService.GetPerfomanceContentById(hfFormID.Text); if (getV != null) { BLL.LogService.AddSys_Log(this.CurrUser, getV.PerfomanceContent, getV.PerfomanceId, BLL.Const.CertificateMenuId, BLL.Const.BtnDelete); BLL.PerfomanceContentService.DeletePerfomanceContentById (getV.PerfomanceId); } } BindGrid(); PageContext.RegisterStartupScript("onNewButtonClick();"); } } #endregion #region 编辑 /// /// 右键编辑事件 /// /// /// 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 perfomanceContent = BLL.PerfomanceContentService.GetPerfomanceContentById(Id); if (perfomanceContent != null) { this.txtPerfomanceContent.Text = perfomanceContent.PerfomanceContent; this.txtPerfomanceValue.Text = perfomanceContent.PerfomanceValue; if (perfomanceContent.ShowIndex.HasValue) { this.txtShowIndex.Text = perfomanceContent.ShowIndex.Value+""; } if ( perfomanceContent.PerfomanceType.HasValue) { this.drpCertificateType.SelectedValue = perfomanceContent.PerfomanceType.Value.ToString(); } this.txtRemark.Text = perfomanceContent.ReMark; hfFormID.Text = Id; this.btnDelete.Enabled = true; } } #endregion public string ConvertCertificateType(Object code) { switch (code.ToString()) { case "1": return "分包方"; case "2": return "项目组管理人员"; case "3": return "分包方主要负责人"; default: return ""; } } #region 保存 /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { string strRowID = hfFormID.Text; Model.Perfomance_PerfomanceContent certificate = new Model.Perfomance_PerfomanceContent { PerfomanceContent = this.txtPerfomanceContent.Text.Trim(), PerfomanceValue = this.txtPerfomanceValue.Text.Trim(), ReMark = txtRemark.Text.Trim() }; if (this.drpCertificateType.SelectedValue != BLL.Const._Null) { certificate.PerfomanceType = int.Parse( this.drpCertificateType.SelectedValue); } if (!string.IsNullOrEmpty(txtShowIndex.Text)) { certificate.ShowIndex = int.Parse(txtShowIndex.Text); } if (string.IsNullOrEmpty(strRowID)) { certificate.PerfomanceId = SQLHelper.GetNewID(typeof(Model.Base_Certificate)); BLL.PerfomanceContentService.AddPerfomanceContent(certificate); BLL.LogService.AddSys_Log(this.CurrUser, certificate.PerfomanceContent, certificate.PerfomanceId, BLL.Const.CertificateMenuId, BLL.Const.BtnAdd); } else { certificate.PerfomanceId = strRowID; BLL.PerfomanceContentService.UpdatePerfomanceContent(certificate); BLL.LogService.AddSys_Log(this.CurrUser, certificate.PerfomanceContent, certificate.PerfomanceId, BLL.Const.CertificateMenuId, BLL.Const.BtnModify); } this.SimpleForm1.Reset(); // 重新绑定表格,并点击当前编辑或者新增的行 BindGrid(); PageContext.RegisterStartupScript(String.Format("F('{0}').selectRow('{1}');", Grid1.ClientID, certificate.PerfomanceId)); } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.PerfomanceContentMenuId); 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.btnDelete.Hidden = false; this.btnMenuDelete.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnSave)) { this.btnSave.Hidden = false; } } } #endregion protected void drpType_SelectedIndexChanged(object sender, EventArgs e) { BindGrid(); } } }