using System; using System.Collections.Generic; using System.Linq; using System.Data; using System.Data.SqlClient; using BLL; namespace FineUIPro.Web.common.BaseInfo { public partial class Unit : PageBase { #region 加载页面 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); BindGrid(); } } #endregion #region BindGrid private void BindGrid() { string strSql = @"select u.UnitId,u.UnitCode,u.UnitName,u.ProjectRange,u.Corporate,u.Address, u.Telephone,u.Fax,t.UnitTypeName from dbo.Base_Unit u LEFT JOIN dbo.Base_UnitType t ON t.UnitTypeId = u.UnitTypeId where 1=1 "; List parms = new List(); if (!string.IsNullOrEmpty(this.txtUnitName.Text)) { strSql += " and u.UnitName LIKE @UnitName"; parms.Add(new SqlParameter("@UnitName", "%" + this.txtUnitName.Text.Trim() + "%")); } strSql += " order by UnitCode"; SqlParameter[] parameter = parms.ToArray(); DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = dt.Rows.Count; var table = this.GetPagedDataTable(Grid1, dt); Grid1.DataSource = table; Grid1.DataBind(); } /// /// 查询 /// /// /// protected void btnQuery_Click(object sender, EventArgs e) { this.BindGrid(); } #endregion #region 增加按钮事件 /// /// 增加按钮事件 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { if (GetButtonPower(Const.BtnAdd)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("UnitEdit.aspx", "新增 - "))); } else { Alert.ShowInTop(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); return; } } #endregion #region 编辑/查看/删除数据 /// /// 编辑 /// private void EditData() { if (GetButtonPower(BLL.Const.BtnModify)) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInParent(Resources.Lan.SelectLeastOneRecord); return; } string Id = Grid1.SelectedRowID; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("UnitEdit.aspx?unitId={0}", Id, "编辑 - "))); } else { ShowNotify(Resources.Lan.NoPrivilegePrompt,MessageBoxIcon.Warning); } } /// /// Grid行双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { EditData(); } /// /// 右键编辑事件 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { this.EditData(); } protected void btnMenuView_Click(object sender, EventArgs e) { if (GetButtonPower(BLL.Const.BtnSee)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("UnitView.aspx?UnitId={0}", Grid1.SelectedRowID, "查看 - "))); } else { ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); return; } } /// /// 批量删除数据 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (GetButtonPower(BLL.Const.BtnDelete)) { string strShowNotify = string.Empty; if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); string content = judgementDelete(rowID); var unit = BLL.Base_UnitService.GetUnit(rowID); if (string.IsNullOrEmpty(content)) { BLL.Base_UnitService.DeleteUnitByUnitId(rowID); BLL.Sys_LogService.AddLog(Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.UnitMenuId, Const.BtnDelete, rowID); } else { strShowNotify += Resources.Lan.UnitName + ":" + unit.UnitName + content; } } } if (!string.IsNullOrEmpty(strShowNotify)) { Alert.ShowInTop(strShowNotify, MessageBoxIcon.Warning); } else { BindGrid(); ShowNotify(Resources.Lan.DeletedSuccessfully, MessageBoxIcon.Success); } } else { ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning); } } #endregion #region 分页/排序 /// /// 分页 /// /// /// 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_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } #endregion #region 关闭窗口 /// /// 关闭窗口 /// /// /// protected void Window1_Close(object sender, EventArgs e) { BindGrid(); } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private bool GetButtonPower(string button) { return BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.UnitMenuId, button); } #endregion #region 判断是否可删除 /// /// 判断是否可以删除 /// /// private string judgementDelete(string userId) { string content = string.Empty ; if (Funs.DB.Project_Unit.FirstOrDefault(x=>x.UnitId== userId)!=null) { content += "已在【项目单位】中使用,不能删除!"; } return content; } #endregion } }