342 lines
12 KiB
C#
342 lines
12 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Web;
|
||
using System.Web.UI;
|
||
using System.Web.UI.WebControls;
|
||
using BLL;
|
||
using System.Data.SqlClient;
|
||
using System.Data;
|
||
|
||
namespace FineUIPro.Web.common.ProjectSet
|
||
{
|
||
public partial class Installation : PageBase
|
||
{
|
||
protected void Page_Load(object sender, EventArgs e)
|
||
{
|
||
if (!IsPostBack)
|
||
{
|
||
this.drpProjectId.DataTextField = "ProjectCode";
|
||
this.drpProjectId.DataValueField = "ProjectId";
|
||
this.drpProjectId.DataSource = BLL.Base_ProjectService.GetProjectListByUserIdAndState(this.CurrUser.UserId, BLL.Const._False, CurrUser.LoginProjectArea);
|
||
this.drpProjectId.DataBind();
|
||
Funs.FineUIPleaseSelect(this.drpProjectId, Resources.Lan.PleaseSelect);
|
||
|
||
ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
|
||
|
||
InitTreeMenu();//加载树
|
||
}
|
||
}
|
||
|
||
#region
|
||
/// <summary>
|
||
/// 加载树
|
||
/// </summary>
|
||
private void InitTreeMenu()
|
||
{
|
||
this.tvProject.Nodes.Clear();
|
||
List<Model.Base_Project> projectLists = BLL.Base_ProjectService.GetProjectListByUserIdAndState(this.CurrUser.UserId, Const._False, CurrUser.LoginProjectArea);
|
||
if (this.drpProjectId.SelectedValue != BLL.Const._Null)
|
||
{
|
||
projectLists = projectLists.Where(e => e.ProjectId == this.drpProjectId.SelectedValue).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.ProjectName;
|
||
tn.EnableClickEvent = true;
|
||
this.tvProject.Nodes.Add(tn);
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
this.InitTreeMenu();
|
||
}
|
||
|
||
#region 点击TreeView
|
||
/// <summary>
|
||
/// 点击TreeView
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void tvProject_NodeCommand(object sender, TreeCommandEventArgs e)
|
||
{
|
||
if (this.tvProject.SelectedNodeID != "0" && this.tvProject.SelectedNode != null)
|
||
{
|
||
BindGrid();
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 绑定数据
|
||
/// </summary>
|
||
private void BindGrid()
|
||
{
|
||
string strSql = @"SELECT Installation.ProjectId,Project.ProjectCode,Project.ProjectName,Unit.UnitName as SupervisorUnitName,InstallationId,InstallationCode,InstallationName,Installation.Remark"
|
||
+ @" FROM Project_Installation AS Installation"
|
||
+ @" LEFT JOIN Base_Project AS Project ON Installation.ProjectId=Project.ProjectId"
|
||
+ @" LEFT JOIN Base_Unit AS Unit ON Installation.SupervisorUnitId=Unit.UnitId"
|
||
+ @" WHERE Installation.ProjectId=@ProjectId ";
|
||
List<SqlParameter> listStr = new List<SqlParameter>();
|
||
listStr.Add(new SqlParameter("@ProjectId", this.tvProject.SelectedNodeID));
|
||
if (!string.IsNullOrEmpty(this.txtInstallationCode.Text.Trim()))
|
||
{
|
||
strSql += " AND InstallationCode LIKE @InstallationCode";
|
||
listStr.Add(new SqlParameter("@InstallationCode", "%" + this.txtInstallationCode.Text.Trim() + "%"));
|
||
}
|
||
if (!string.IsNullOrEmpty(this.txtInstallationName.Text.Trim()))
|
||
{
|
||
strSql += " AND InstallationName LIKE @InstallationName";
|
||
listStr.Add(new SqlParameter("@InstallationName", "%" + this.txtInstallationName.Text.Trim() + "%"));
|
||
}
|
||
SqlParameter[] parameter = listStr.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();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 改变索引事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
||
{
|
||
BindGrid();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 分页下拉选择事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
|
||
BindGrid();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 排序
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
|
||
{
|
||
BindGrid();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 关闭弹出窗口
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Window1_Close(object sender, EventArgs e)
|
||
{
|
||
BindGrid();
|
||
}
|
||
|
||
#region 增加按钮事件
|
||
/// <summary>
|
||
/// 增加按钮事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnNew_Click(object sender, EventArgs e)
|
||
{
|
||
if (GetButtonPower(Const.BtnAdd))
|
||
{
|
||
if (this.tvProject.SelectedNodeID != "0" && this.tvProject.SelectedNode != null)
|
||
{
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("InstallationEdit.aspx?projectId={0}", tvProject.SelectedNodeID, "新增 - ")));
|
||
}
|
||
else
|
||
{
|
||
Alert.ShowInParent(Resources.Lan.PleaseSelectProject, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Alert.ShowInTop(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 编辑
|
||
/// <summary>
|
||
/// 双击事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
|
||
{
|
||
this.EditData();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 右键编辑事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnMenuEdit_Click(object sender, EventArgs e)
|
||
{
|
||
this.EditData();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 编辑数据方法
|
||
/// </summary>
|
||
private void EditData()
|
||
{
|
||
|
||
if (Grid1.SelectedRowIndexArray.Length == 0)
|
||
{
|
||
Alert.ShowInTop(Resources.Lan.SelectLeastOneRecord, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
|
||
////双击事件 编辑权限有:编辑页面,无:查看页面 或者状态是完成时查看页面
|
||
if (GetButtonPower(Const.BtnModify))
|
||
{
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("InstallationEdit.aspx?InstallationId={0}&projectId={1}", Grid1.SelectedRowID,tvProject.SelectedNodeID)));
|
||
}
|
||
else if (GetButtonPower(Const.BtnSave))
|
||
{
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("InstallationView.aspx?InstallationId={0}", Grid1.SelectedRowID, "查看 - ")));
|
||
}
|
||
else
|
||
{
|
||
Alert.ShowInTop(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 删除
|
||
/// <summary>
|
||
/// 右键删除事件
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnMenuDelete_Click(object sender, EventArgs e)
|
||
{
|
||
if (GetButtonPower(Const.BtnDelete))
|
||
{
|
||
if (Grid1.SelectedRowIndexArray.Length > 0)
|
||
{
|
||
string strShowNotify = string.Empty;
|
||
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
|
||
{
|
||
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
|
||
var getInstallation = BLL.Project_InstallationService.GetProject_InstallationByInstallationId(rowID);
|
||
if (getInstallation != null)
|
||
{
|
||
string cont = judgementDelete(rowID);
|
||
if (string.IsNullOrEmpty(cont))
|
||
{
|
||
BLL.Project_InstallationService.DeleteProject_InstallationByInstallationId(rowID);
|
||
BLL.Sys_LogService.AddLog(Const.System_1, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_InstallationMenuId, Const.BtnDelete, rowID);
|
||
}
|
||
else
|
||
{
|
||
strShowNotify += Resources.Lan.ProjectInformation + ":" + getInstallation.InstallationCode + cont;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(strShowNotify))
|
||
{
|
||
Alert.ShowInTop(strShowNotify, MessageBoxIcon.Warning);
|
||
}
|
||
else
|
||
{
|
||
BindGrid();
|
||
ShowNotify(Resources.Lan.DeletedSuccessfully, MessageBoxIcon.Success);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Alert.ShowInTop(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
}
|
||
|
||
#region 判断是否可删除
|
||
/// <summary>
|
||
/// 判断是否可以删除
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private string judgementDelete(string id)
|
||
{
|
||
string content = string.Empty;
|
||
if (Funs.DB.Project_WorkArea.FirstOrDefault(x => x.InstallationId == id) != null)
|
||
{
|
||
content += Resources.Lan.AreaExistsInstallation;
|
||
}
|
||
if (Funs.DB.Pipeline_Pipeline.FirstOrDefault(x => x.InstallationId == id) != null)
|
||
{
|
||
content += "已在【管线信息】中使用,不能删除!";
|
||
}
|
||
return content;
|
||
}
|
||
#endregion
|
||
#endregion
|
||
|
||
#region 查询
|
||
/// <summary>
|
||
/// 查询
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnQuery_Click(object sender, EventArgs e)
|
||
{
|
||
this.BindGrid();
|
||
}
|
||
#endregion
|
||
|
||
#region 查看
|
||
/// <summary>
|
||
/// 查看按钮
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
protected void btnView_Click(object sender, EventArgs e)
|
||
{
|
||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("InstallationView.aspx?InstallationId={0}", Grid1.SelectedRowID, "查看 - ")));
|
||
}
|
||
#endregion
|
||
|
||
#region 获取按钮权限
|
||
/// <summary>
|
||
/// 获取按钮权限
|
||
/// </summary>
|
||
/// <param name="button"></param>
|
||
/// <returns></returns>
|
||
private bool GetButtonPower(string button)
|
||
{
|
||
return BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_InstallationMenuId, button);
|
||
}
|
||
#endregion
|
||
}
|
||
} |