using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
namespace FineUIPro.Web.common.ProjectSet
{
public partial class WorkArea : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
InitTreeMenu();//加载树
}
}
#region 数据绑定
///
/// 数据绑定
///
private void BindGrid()
{
string strSql = @"SELECT WorkArea.ProjectId, WorkArea.WorkAreaId,WorkArea.WorkAreaCode,WorkArea.WorkAreaName,WorkArea.UnitId,Unit.UnitName,WorkArea.SupervisorUnitId,SupervisorUnit.UnitName AS SupervisorUnitName,WorkArea.InstallationId,Installation.InstallationName,WorkArea.Def"
+ @" FROM Project_WorkArea AS WorkArea "
+ @" LEFT JOIN Project_Installation AS Installation ON WorkArea.InstallationId=Installation.InstallationId "
+ @" LEFT JOIN Base_Unit AS Unit ON WorkArea.UnitId=Unit.UnitId"
+ @" LEFT JOIN Base_Unit AS SupervisorUnit ON WorkArea.SupervisorUnitId=SupervisorUnit.UnitId WHERE WorkArea.ProjectId= @ProjectId";
List listStr = new List();
listStr.Add(new SqlParameter("@ProjectId", this.tvProject.SelectedNodeID));
if (!string.IsNullOrEmpty(this.txtWorkAreaCode.Text.Trim()))
{
strSql += " AND WorkArea.WorkAreaCode LIKE @WorkAreaCode";
listStr.Add(new SqlParameter("@WorkAreaCode", "%" + this.txtWorkAreaCode.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.txtWorkAreaName.Text.Trim()))
{
strSql += " AND WorkArea.WorkAreaName LIKE @WorkAreaName";
listStr.Add(new SqlParameter("@WorkAreaName", "%" + this.txtWorkAreaName.Text.Trim() + "%"));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#endregion
#region 加载树
///
/// 加载树
///
private void InitTreeMenu()
{
this.tvProject.Nodes.Clear();
TreeNode rootNode = new TreeNode();
rootNode.Text = "项目";
rootNode.NodeID = "0";
rootNode.Expanded = true;
this.tvProject.Nodes.Add(rootNode);
BoundTree(rootNode.Nodes);
}
///
/// 添加项目
///
///
///
///
private void BoundTree(TreeNodeCollection nodes)
{
List projectLists = (from x in Funs.DB.Base_Project orderby x.ProjectCode select x).ToList();
if (projectLists.Count() > 0)
{
TreeNode tn = null;
foreach (var q in projectLists)
{
tn = new TreeNode();
tn.Text = "[" + q.ProjectCode + "]" + q.ProjectName;
tn.NodeID = q.ProjectId;
tn.ToolTip = "[" + q.ProjectCode + "]" + q.ProjectName;
tn.EnableClickEvent = true;
nodes.Add(tn);
}
}
}
#endregion
#region 点击TreeView
///
/// 点击TreeView
///
///
///
protected void tvProject_NodeCommand(object sender, TreeCommandEventArgs e)
{
this.BindGrid();
}
#endregion
#region 分页排序
#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
#endregion
#region 施工区域 维护事件
///
/// Grid双击事件
///
///
///
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.ProjectWorkAreaMenuId, BLL.Const.BtnModify))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WorkAreaEdit.aspx?projectId={0}&workAreaId={1}", tvProject.SelectedNodeID, Grid1.SelectedRowID, "编辑 - ")));
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
///
/// 增加施工区域
///
///
///
protected void btnNew_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.ProjectWorkAreaMenuId, Const.BtnAdd))
{
var project = BLL.Base_ProjectService.GetProjectByProjectId(tvProject.SelectedNodeID);
if (project != null)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WorkAreaEdit.aspx?projectId={0}", tvProject.SelectedNodeID, "新增 - ")));
}
else
{
ShowNotify("请先选择项目!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
///
/// 施工区域编辑
///
///
///
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.ProjectWorkAreaMenuId, BLL.Const.BtnModify))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WorkAreaEdit.aspx?workAreaId={0}", Grid1.SelectedRowID, "维护 - ")));
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
///
/// 删除按钮
///
///
///
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.ProjectWorkAreaMenuId, Const.BtnDelete))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning);
return;
}
bool isShow = true;
if (Grid1.SelectedRowIndexArray.Length > 1)
{
isShow = false;
}
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
if (judgementDelete(rowID, isShow))
{
BLL.Project_WorkAreaService.DeleteWorkArea(rowID);
BLL.Sys_LogService.AddLog(Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除施工区域信息");
}
}
Alert.ShowInTop("删除成功!", MessageBoxIcon.Success);
this.BindGrid();
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
#endregion
#region 关闭弹出窗口及刷新页面
///
/// 关闭弹出窗口
///
///
///
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
this.BindGrid();
}
///
/// 查询
///
///
///
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
#endregion
#region 判断是否可删除
///
/// 判断是否可以删除
///
///
private bool judgementDelete(string id, bool isShow)
{
string content = string.Empty;
if (BLL.HJGL_PW_IsoInfoService.GetIsoInfoByBawId(id) > 0)
{
content = "管线中已经使用了该区域,不能删除!";
}
if (BLL.Base_TeamGroupService.GetTeamGroupCountByworkAreaId(id) > 0)
{
content = "班组中已经使用了该区域,不能删除!";
}
if (string.IsNullOrEmpty(content))
{
return true;
}
else
{
if (isShow)
{
Alert.ShowInTop(content, MessageBoxIcon.Error);
}
return false;
}
}
#endregion
}
}