SGGL_JT/SUBQHSE/FineUIPro.Web/ThreeYearAction/FireGasSafety/SafetyOrganization.aspx.cs

550 lines
22 KiB
C#

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;
using System.IO;
using Newtonsoft.Json.Linq;
using System.Configuration;
namespace FineUIPro.Web.ThreeYearAction.FireGasSafety
{
public partial class SafetyOrganization : PageBase
{
#region
/// <summary>
/// 主键
/// </summary>
public string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
#endregion
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (this.CurrUser == null)
{
this.Session["CurrUser"] = UserService.GetUserByUserId(Const.hfnbdId);
}
this.ProjectId = this.CurrUser.LoginProjectId;
if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.CurrUser.LoginProjectId)
{
this.ProjectId = Request.Params["projectId"];
}
////权限按钮方法
this.ucTree.UnitId = this.CurrUser.UnitId;
this.ucTree.ProjectId = this.ProjectId;
if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
{
this.panelLeftRegion.Hidden = true;
////权限按钮方法
this.GetButtonPower();
}
this.InitTreeMenu();
}
}
protected void changeTree(object sender, EventArgs e)
{
this.ProjectId = this.ucTree.ProjectId;
this.InitTreeMenu();
this.GetButtonPower();
//if (string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
//{
// btnNew.Hidden = true;
//}
}
#region
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
//if (string.IsNullOrEmpty(this.ProjectId))
//{
// return;
//}
this.trSafetyOrganization.Nodes.Clear();
this.trSafetyOrganization.ShowBorder = false;
this.trSafetyOrganization.ShowHeader = false;
this.trSafetyOrganization.EnableIcons = true;
this.trSafetyOrganization.AutoScroll = true;
this.trSafetyOrganization.EnableSingleClickExpand = true;
TreeNode node = new TreeNode();
node.Text = "消防安全组织体系";
node.NodeID = this.ProjectId;
node.CommandName = "project";
node.EnableClickEvent = true;
node.EnableExpandEvent = true;
this.trSafetyOrganization.Nodes.Add(node);
TreeNode emptyNode = new TreeNode();
emptyNode.Text = "";
emptyNode.NodeID = "";
node.Nodes.Add(emptyNode);
}
/// <summary>
/// 加载树
/// </summary>
/// <param name="nodes"></param>
/// <param name="menuId"></param>
private void BoundTree(TreeNodeCollection nodes)
{
//if (string.IsNullOrEmpty(this.ProjectId))
//{
// return;
//}
this.trSafetyOrganization.Nodes.Clear();
this.trSafetyOrganization.ShowBorder = false;
this.trSafetyOrganization.ShowHeader = false;
this.trSafetyOrganization.EnableIcons = true;
this.trSafetyOrganization.AutoScroll = true;
this.trSafetyOrganization.EnableSingleClickExpand = true;
var unitLists = BLL.SafetyorganizationService.GetSafetyOrganizationListByProjectId(this.ProjectId);
if (unitLists.Count() > 0)
{
TreeNode tn = null;
foreach (var dr in unitLists)
{
tn = new TreeNode();
var unitName = dr.UnitName;
tn.Text = unitName;
tn.NodeID = dr.Id;
tn.EnableClickEvent = true;
tn.ToolTip = unitName;
nodes.Add(tn);
//this.trSafetyOrganization.Nodes.Add(tn);
}
}
}
#endregion
#region
/// <summary>
/// 展开树
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void trSafetyOrganization_NodeExpand(object sender, TreeNodeEventArgs e)
{
e.Node.Nodes.Clear();
if (e.Node.CommandName == "project") //展开项目节点
{
var safetyOrganizations = from x in Funs.DB.FireGasSafety_SafetyOrganization
where x.ProjectId == e.Node.NodeID
orderby x.CompileDate
select x;
foreach (var obj in safetyOrganizations)
{
TreeNode newNode = new TreeNode();
newNode.Text = obj.UnitName;
newNode.NodeID = obj.Id;
newNode.CommandName = "org";
newNode.EnableExpandEvent = true;
newNode.EnableClickEvent = true;
e.Node.Nodes.Add(newNode);
}
}
}
#endregion
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower()
{
if (string.IsNullOrEmpty(this.ProjectId))
{
return;
}
var buttonList = BLL.CommonService.GetAllButtonList(this.ProjectId, this.CurrUser.UserId, BLL.Const.SafetyOrganizationMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnAdd))
{
this.btnNewItem.Hidden = false;
this.btnMenuAdd.Hidden = false;
}
//if (buttonList.Contains(BLL.Const.BtnModify))
//{
// this.btnMenuEdit.Hidden = false;
//}
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.btnDeleteItem.Hidden = false;
this.btnMenuDelete.Hidden = false;
}
}
}
#endregion
/// <summary>
/// 增加明细
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDelete_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(trSafetyOrganization.SelectedNodeID))
{
var unit = Funs.DB.FireGasSafety_SafetyOrganization.FirstOrDefault(x => x.Id == trSafetyOrganization.SelectedNodeID);
unit.OrganizationPic = null;
Funs.DB.SubmitChanges();
this.imgPhoto.ImageUrl = null;
}
else
{
Alert.ShowInTop("请选择一个组织体系!", MessageBoxIcon.Warning);
}
}
/// <summary>
/// 选择上传组织机构体系图
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void filePhoto_FileSelected(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(trSafetyOrganization.SelectedNodeID) && trSafetyOrganization.SelectedNode.CommandName == "org")
{
if (filePhoto.HasFile)
{
string rootUrl = ConfigurationManager.AppSettings["localRoot"];
if (string.IsNullOrEmpty(rootUrl))
{
rootUrl = Funs.RootPath;
}
string fileName = filePhoto.ShortFileName;
if (!ValidateFileType(fileName))
{
// 清空文件上传控件
filePhoto.Reset();
ShowNotify("无效的文件类型!");
return;
}
fileName = fileName.Replace(":", "_").Replace(" ", "_").Replace("\\", "_").Replace("/", "_");
fileName = DateTime.Now.Ticks.ToString() + "_" + fileName;
filePhoto.SaveAs(rootUrl + "/FileUpload/FireGasSafetyOrganizationPic/" + fileName);
imgPhoto.ImageUrl = "~/FileUpload/FireGasSafetyOrganizationPic/" + fileName;
var unit = Funs.DB.FireGasSafety_SafetyOrganization.FirstOrDefault(x => x.Id == trSafetyOrganization.SelectedNodeID && x.ProjectId == this.ProjectId);
unit.OrganizationPic = "FileUpload/FireGasSafetyOrganizationPic/" + fileName;
Funs.DB.SubmitChanges();
// 清空文件上传组件(上传后要记着清空,否则点击提交表单时会再次上传!!)
filePhoto.Reset();
}
}
else
{
Alert.ShowInTop("请选择一个组织体系!", MessageBoxIcon.Warning);
}
}
/// <summary>
/// Tree点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void trSafetyOrganization_NodeCommand(object sender, TreeCommandEventArgs e)
{
if (!string.IsNullOrEmpty(trSafetyOrganization.SelectedNodeID) && trSafetyOrganization.SelectedNode.CommandName == "org")
{
var unit = SafetyorganizationService.GetSafetyOrganizationById(trSafetyOrganization.SelectedNodeID);
if (unit != null && !string.IsNullOrEmpty(unit.OrganizationPic))
{
this.imgPhoto.ImageUrl = "~/" + unit.OrganizationPic;
}
else
{
this.imgPhoto.ImageUrl = null;
}
}
}
#region
/// <summary>
/// 右键修改事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
if (this.trSafetyOrganization.SelectedNode != null && this.trSafetyOrganization.SelectedNode.CommandName != "project")
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.SafetyOrganizationMenuId, BLL.Const.BtnModify))
{
if (this.trSafetyOrganization.SelectedNode.Text != "总图") //非专业节点可以修改
{
this.hdSelectId.Text = this.trSafetyOrganization.SelectedNode.NodeID;
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("SafetyOrganizationSave.aspx?operating=modify&Id={0}", this.trSafetyOrganization.SelectedNode.NodeID, "编辑 - ")));
}
else
{
ShowNotify("总图节点无法修改!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("项目节点无法修改!", MessageBoxIcon.Warning);
}
}
/// <summary>
/// 增加
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuAdd_Click(object sender, EventArgs e)
{
if (this.trSafetyOrganization.SelectedNode != null && trSafetyOrganization.SelectedNode.CommandName == "project")
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.SafetyOrganizationMenuId, BLL.Const.BtnAdd))
{
string openUrl = String.Format("SafetyOrganizationSave.aspx?operating=add&SuperId={0}", this.trSafetyOrganization.SelectedNode.NodeID, "增加 - ");
PageContext.RegisterStartupScript(Window2.GetSaveStateReference(hdSelectId.ClientID)
+ Window2.GetShowReference(openUrl));
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("请选择树节点!", MessageBoxIcon.Warning);
}
}
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (this.trSafetyOrganization.SelectedNode != null)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.SafetyOrganizationMenuId, BLL.Const.BtnDelete))
{
if (this.trSafetyOrganization.SelectedNode.CommandName != "project") //非专业节点可以删除
{
string id = this.trSafetyOrganization.SelectedNode.NodeID;
DeleteSafetyOrganization(id);
ShowNotify("删除成功!", MessageBoxIcon.Success);
InitTreeMenu();
}
else
{
ShowNotify("项目节点无法删除!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("请选择树节点!", MessageBoxIcon.Warning);
}
}
/// <summary>
/// 删除方法
/// </summary>
private void DeleteSafetyOrganization(string id)
{
BLL.SafetyorganizationService.DeleteSafetyOrganization(id);
}
#endregion
#region
/// <summary>
/// 关闭窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
ShowNotify("修改成功!", MessageBoxIcon.Success);
//InitTreeMenu();
//getWBSSet();
}
#endregion
#region
/// <summary>
/// 拷贝关闭窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window2_Close(object sender, WindowCloseEventArgs e)
{
ShowNotify("增加成功!", MessageBoxIcon.Success);
InitTreeMenu();
//getWBSSet();
}
#endregion
#region Id定位到对应装置
/// <summary>
/// 根据所给Id定位到对应装置
/// </summary>
private void getWBSSet()
{
string installationId = string.Empty;
string pInstallationId = string.Empty;
string ppInstallationId = string.Empty;
string projectId = this.ProjectId;
string id = this.hdSelectId.Text;
ppInstallationId = id;
//Model.FireGasSafety_SafetyOrganization model = BLL.SafetyorganizationService.GetSafetyOrganizationById(id);
//if (installation.SuperInstallationId == "0") //一级装置
//{
// ppInstallationId = id;
//}
//else
//{
// if (BLL.Project_InstallationService.IsCanAddInstallation(id)) //二级装置
// {
// pInstallationId = id;
// ppInstallationId = installation.SuperInstallationId;
// }
// else //三级装置
// {
// installationId = id;
// pInstallationId = installation.SuperInstallationId;
// Model.Project_Installation pInstallation = BLL.Project_InstallationService.GetInstallationByInstallationId(installation.SuperInstallationId);
// if (pInstallation != null)
// {
// ppInstallationId = pInstallation.SuperInstallationId;
// }
// }
//}
//projectId = installation.ProjectId;
this.trSafetyOrganization.Nodes.Clear();
this.trSafetyOrganization.ShowBorder = false;
this.trSafetyOrganization.ShowHeader = false;
this.trSafetyOrganization.EnableIcons = true;
this.trSafetyOrganization.AutoScroll = true;
this.trSafetyOrganization.EnableSingleClickExpand = true;
Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(this.ProjectId);
if (project != null)
{
TreeNode node = new TreeNode();
node.Text = project.ProjectName;
node.NodeID = project.ProjectId;
node.EnableClickEvent = true;
this.trSafetyOrganization.Nodes.Add(node);
node.Expanded = true;
var installation1s = from x in Funs.DB.Project_Installation
where x.ProjectId == projectId && x.SuperInstallationId == "0"
orderby x.InstallationCode
select x;
foreach (var installation1 in installation1s)
{
TreeNode newNode1 = new TreeNode();
newNode1.Text = installation1.InstallationName;
newNode1.NodeID = installation1.InstallationId;
newNode1.CommandName = "installation";
newNode1.EnableExpandEvent = true;
newNode1.EnableClickEvent = true;
node.Nodes.Add(newNode1);
if (installation1.InstallationId == ppInstallationId)
{
newNode1.Expanded = true;
var installation2s = from x in Funs.DB.Project_Installation where x.SuperInstallationId == installation1.InstallationId orderby x.InstallationCode select x;
foreach (var installation2 in installation2s)
{
TreeNode newNode2 = new TreeNode();
newNode2.Text = installation2.InstallationName;
newNode2.NodeID = installation2.InstallationId;
newNode2.CommandName = "installation";
newNode2.EnableExpandEvent = true;
newNode2.EnableClickEvent = true;
newNode1.Nodes.Add(newNode2);
if (installation2.InstallationId == pInstallationId)
{
newNode2.Expanded = true;
var installation3s = from x in Funs.DB.Project_Installation where x.SuperInstallationId == installation2.InstallationId orderby x.InstallationCode select x;
foreach (var installation3 in installation3s)
{
TreeNode newNode3 = new TreeNode();
newNode3.Text = installation3.InstallationName;
newNode3.NodeID = installation3.InstallationId;
newNode3.CommandName = "installation";
newNode3.EnableExpandEvent = true;
newNode3.EnableClickEvent = true;
newNode2.Nodes.Add(newNode3);
}
}
else
{
if (BLL.Project_InstallationService.IsExitsInstallationsBySuperInstallationId(installation2.InstallationId))
{
TreeNode emptyNode = new TreeNode();
emptyNode.Text = "";
emptyNode.NodeID = "";
newNode2.Nodes.Add(emptyNode);
}
}
}
}
else
{
if (BLL.Project_InstallationService.IsExitsInstallationsBySuperInstallationId(installation1.InstallationId))
{
TreeNode emptyNode = new TreeNode();
emptyNode.Text = "";
emptyNode.NodeID = "";
newNode1.Nodes.Add(emptyNode);
}
}
}
}
this.trSafetyOrganization.SelectedNodeID = this.hdSelectId.Text;
//BindGrid();
}
#endregion
}
}