using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace FineUIPro.Web.common.BaseInfo { public partial class Unit : PageBase { #region 加载页面 protected void Page_Load(object sender, EventArgs e) { // 表头过滤 FilterDataRowItem = FilterDataRowItemImplement; if (!IsPostBack) { this.btnMenuDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("请至少选择一项!"); this.btnMenuDelete.ConfirmText = String.Format("你确定要删除选中的  行数据吗?", Grid1.GetSelectedCountReference()); ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); InitTreeMenu();//加载树 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,u.IsMain from dbo.Base_Unit u where IsSubUnit=@IsSubUnit"; List parms = new List(); if (this.tvUnit.SelectedNode == null) { parms.Add(new SqlParameter("@IsSubUnit", true)); } else { parms.Add(new SqlParameter("@IsSubUnit", Convert.ToBoolean(this.tvUnit.SelectedNode.NodeID))); //if (this.tvUnit.SelectedNode.NodeID == "true") //{ // strSql += " and r.PropertyId=@PropertyId "; // parms.Add(new SqlParameter("@PropertyId", Const.PropertyId_2)); //} //else //{ // strSql += " or IsSubUnit is null"; //} strSql += " order by UnitCode"; } SqlParameter[] parameter = parms.ToArray(); 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(); } #region 表头过滤 protected void Grid1_FilterChange(object sender, EventArgs e) { BindGrid(); } private bool FilterDataRowItemImplement(object sourceObj, string fillteredOperator, object fillteredObj, string column) { bool valid = false; if (column == "UnitCode") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal") { if (sourceValue == fillteredValue) { valid = true; } } else if (fillteredOperator == "contain") { if (sourceValue.Contains(fillteredValue)) { valid = true; } } } else if (column == "UnitName") { string sourceValue = sourceObj.ToString(); string fillteredValue = fillteredObj.ToString(); if (fillteredOperator == "equal") { if (sourceValue == fillteredValue) { valid = true; } } else if (fillteredOperator == "contain") { if (sourceValue.Contains(fillteredValue)) { valid = true; } } } return valid; } #endregion /// /// 加载树 /// private void InitTreeMenu() { this.tvUnit .Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = "单位性质"; rootNode.NodeID = null; rootNode.Expanded = true; this.tvUnit.Nodes.Add(rootNode); TreeNode tn = new TreeNode(); tn.Text="外部单位"; tn.NodeID = "false"; tn.EnableClickEvent = true; tn.Expanded = true; rootNode.Nodes.Add(tn); TreeNode tn1 = new TreeNode(); tn1.Text = "内部单位"; tn1.NodeID = "true"; tn1.Expanded = true; tn1.EnableClickEvent = true; rootNode.Nodes.Add(tn1); } #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvUnit_NodeCommand(object sender, TreeCommandEventArgs e) { if (!string.IsNullOrEmpty(this.tvUnit.SelectedNode.NodeID)) { BindGrid(); } } #endregion #region 页索引改变事件 /// /// 页索引改变事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } #endregion #region 分页选择下拉改变事件 /// /// 分页选择下拉改变事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #region 增加按钮 /// /// 增加按钮 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { if (this.tvUnit.SelectedNode!=null) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("UnitEdit.aspx?IsSubUnit={0}", this.tvUnit.SelectedNodeID, "编辑 - "))); //if (this.tvUnit.SelectedNode.NodeID == "true") //{ // Alert.ShowInTop("分包商信息由分包商管理系统审核通过增加,这里不能增加!", MessageBoxIcon.Warning); // return; //} //else //{ // PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("UnitEdit.aspx", "编辑 - "))); //} } else { Alert.ShowInTop("请选择单位属性!", MessageBoxIcon.Warning); return; } } #endregion #region 编辑 /// /// 右键编辑事件 /// /// /// protected void btnEdit_Click(object sender, EventArgs e) { this.EditData(); } protected void btnMenuEdit_Click(object sender, EventArgs e) { this.EditData(); } /// /// 编辑 /// private void EditData() { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } else { string rowID = Grid1.SelectedRowID; var unit = BLL.Base_UnitService.GetUnit(rowID); PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("UnitEdit.aspx?unitId={0}", Grid1.SelectedRowID, "编辑 - "))); //if (unit.IsSubUnit==true) //{ // Alert.ShowInTop("分包商信息由分包商管理系统编辑维护,这里不能编辑!", MessageBoxIcon.Warning); // return; //} //else //{ // PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("UnitEdit.aspx?unitId={0}", Grid1.SelectedRowID, "编辑 - "))); //} } } /// /// Grid双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { this.EditData(); } #endregion #region 删除 /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { this.DeleteData(); } protected void btnDelete_Click(object sender, EventArgs e) { this.DeleteData(); } /// /// 删除方法 /// private void DeleteData() { if (GetButtonPower(BLL.Const.BtnDelete)) { if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); var unit = BLL.Base_UnitService.GetUnit(rowID); if (unit != null) { if (unit.UnitId == BLL.Const.zzfgsId)//单位是制造分公司时,不允许删除 { ShowNotify("内置项,不允许删除!", MessageBoxIcon.Warning); return; } else { if (judgementDelete(rowID)) { BLL.Base_UnitService.DeleteUnitByUnitId(rowID); BLL.Sys_LogService.AddLog(BLL.Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除单位信息"); ShowNotify("删除数据成功!(表格数据已重新绑定)"); } } } } BindGrid(); } } else { ShowNotify("您没有这个权限,请与管理员联系!"); } } /// /// 判断是否可以删除 /// /// private bool judgementDelete(string unitId) { string content = ""; if (BLL.Project_WorkAreaService.GetWorkAreaCountByUnitId(unitId) > 0) { content = "项目区域中已经使用了该单位,不能删除!"; } if (BLL.Sys_UserService.GetUsersByUnitId(unitId).Count() > 0) { content = "用户中已经使用了该单位,不能删除!"; } if (content == "") { return true; } else { ShowNotify(content); return false; } } #endregion #region 关闭弹出窗口 /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #endregion #region 判断按钮权限 /// /// 获取按钮权限 /// /// /// private bool GetButtonPower(string button) { return BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId,this.CurrUser.UserId, BLL.Const.UnitMenuId, button); } #endregion } }