SGGL_SHJ/SGGL/FineUIPro.Web/HJGL/PreDesign/YardPlanning.aspx.cs

369 lines
13 KiB
C#

using BLL;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web.UI.DataVisualization.Charting;
namespace FineUIPro.Web.HJGL.PreDesign
{
public partial class YardPlanning : 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)
{
this.ProjectId = this.CurrUser.LoginProjectId;
if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.CurrUser.LoginProjectId)
{
this.ProjectId = Request.Params["projectId"];
}
////权限按钮方法
this.GetButtonPower();
this.InitTreeMenu();
Bind();
}
}
private void Bind()
{
if (!string.IsNullOrEmpty(tvControlItem.SelectedNodeID))
{
var unit = HJGL_YardPlanningService.GetHJGL_YardPlanningById( tvControlItem.SelectedNodeID);
this.imgPhoto.ImageUrl = null;
if (unit != null)
{
this.imgPhoto.ImageUrl = "~/" + unit.FlowChartPic;
}
}
}
#region --
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
this.tvControlItem.Nodes.Clear();
TreeNode rootNode1 = new TreeNode();
rootNode1.NodeID = "1";
rootNode1.Text = "建筑工程";
rootNode1.CommandName = "建筑工程";
rootNode1.Selectable = false;
this.tvControlItem.Nodes.Add(rootNode1);
TreeNode rootNode2 = new TreeNode();
rootNode2.NodeID = "2";
rootNode2.Text = "安装工程";
rootNode2.CommandName = "安装工程";
rootNode2.Expanded = true;
this.tvControlItem.Nodes.Add(rootNode2);
var pUnits = (from x in Funs.DB.Project_ProjectUnit where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList();
// 获取当前用户所在单位
var currUnit = pUnits.FirstOrDefault(x => x.UnitId == this.CurrUser.UnitId);
var unitWorkList = (from x in Funs.DB.WBS_UnitWork
where x.ProjectId == this.CurrUser.LoginProjectId
&& x.SuperUnitWork == null && x.UnitId != null && x.ProjectType != null
select x).ToList();
List<Model.WBS_UnitWork> unitWork1 = null;
List<Model.WBS_UnitWork> unitWork2 = null;
//// 当前为施工单位,只能操作本单位的数据
//if (currUnit != null && currUnit.UnitType == Const.ProjectUnitType_2)
//{
// unitWork1 = (from x in unitWorkList
// where x.UnitId == this.CurrUser.UnitId && x.ProjectType == "1"
// select x).ToList();
// unitWork2 = (from x in unitWorkList
// where x.UnitId == this.CurrUser.UnitId && x.ProjectType == "2"
// select x).ToList();
//}
//else
//{
unitWork1 = (from x in unitWorkList where x.ProjectType == "1" select x).ToList();
unitWork2 = (from x in unitWorkList where x.ProjectType == "2" select x).ToList();
//}
if (unitWork1.Count() > 0)
{
foreach (var q in unitWork1)
{
//int a = (from x in Funs.DB.HJGL_Pipeline where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == q.UnitWorkId select x).Count();
int a = (from x in Funs.DB.HJGL_YardPlanning where x.SurperId == q.UnitWorkId select x).Count();
var unitNamesUnitIds = BLL.UnitService.getUnitNamesUnitIds(q.UnitId);
TreeNode tn1 = new TreeNode();
tn1.NodeID = q.UnitWorkId;
tn1.Text = q.UnitWorkName + "【" + a.ToString() + "】" + "管线";
tn1.ToolTip = "施工单位:" + unitNamesUnitIds;
tn1.EnableClickEvent = true;
rootNode1.Nodes.Add(tn1);
if (a > 0)
{
BoundTree(tn1.Nodes, tn1.NodeID);
}
}
}
if (unitWork2.Count() > 0)
{
foreach (var q in unitWork2)
{
int a = (from x in Funs.DB.HJGL_YardPlanning where x.SurperId==q.UnitWorkId select x).Count();
var unitNamesUnitIds = BLL.UnitService.getUnitNamesUnitIds(q.UnitId);
TreeNode tn2 = new TreeNode();
tn2.NodeID = q.UnitWorkId;
// tn2.Text = q.UnitWorkName + "【" + a.ToString() + "】" + "管线";
tn2.Text = q.UnitWorkName ;
tn2.CommandName = "主项";
tn2.ToolTip = "施工单位:" + unitNamesUnitIds;
tn2.EnableClickEvent = true;
rootNode2.Nodes.Add(tn2);
if (a>0)
{
BoundTree(tn2.Nodes, tn2.NodeID);
}
}
}
}
private void BoundTree(TreeNodeCollection nodes, string superId)
{
var mdoel = BLL.HJGL_YardPlanningService.GetHJGL_YardPlanningBySurperId(superId);
foreach (var m in mdoel)
{
TreeNode chidNode = new TreeNode
{
Text = m.YardPlanName,
NodeID = m.YardPlanningId,
Expanded = true,
Selectable = true,
EnableClickEvent= true,
};
nodes.Add(chidNode);
this.BoundTree(chidNode.Nodes, m.YardPlanningId);
}
}
#endregion
#region TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
this.Bind();
}
#endregion
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower()
{
var buttonList = BLL.CommonService.GetAllButtonList(this.ProjectId, this.CurrUser.PersonId, BLL.Const.HJGL_YardPlanningMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnAdd))
{
this.btnNewItem.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.btnDeleteItem.Hidden = false;
}
}
}
#endregion
/// <summary>
/// 删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDelete_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(tvControlItem.SelectedNodeID))
{
var model = HJGL_YardPlanningService.GetHJGL_YardPlanningByProjectId(this.CurrUser.LoginProjectId, tvControlItem.SelectedNodeID);
if (model != null)
{
HJGL_YardPlanningService.DeleteHJGL_YardPlanningById(model.YardPlanningId);
}
this.imgPhoto.ImageUrl = null;
}
else
{
Alert.ShowInTop("请选择一个主项!", MessageBoxIcon.Warning);
}
}
protected void filePhoto_FileSelected(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(tvControlItem.SelectedNodeID) && tvControlItem.SelectedNode.CommandName != "主项")
{
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/HJGL_YardPlanning/" + fileName);
imgPhoto.ImageUrl = "~/FileUpload/HJGL_YardPlanning/" + fileName;
HJGL_YardPlanningService.SavePic( tvControlItem.SelectedNodeID, "FileUpload/HJGL_YardPlanning/" + fileName);
// 清空文件上传组件(上传后要记着清空,否则点击提交表单时会再次上传!!)
filePhoto.Reset();
}
}
else
{
Alert.ShowInTop("主节点无法上传,请新增节点!", MessageBoxIcon.Warning);
}
}
#region
protected void btnMenuAdd_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("YardPlanningEdit.aspx?YardPlanningId={0}&&Type=Add", this.tvControlItem.SelectedNodeID, "增加 - ")));
}
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
if (this.tvControlItem.SelectedNode.CommandName == "主项")
{
ShowNotify("无法修改此节点!", MessageBoxIcon.Warning);
}
else
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("YardPlanningEdit.aspx?YardPlanningId={0}&&Type=Edit", this.tvControlItem.SelectedNodeID, "增加 - ")));
}
}
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
BLL.HJGL_YardPlanningService.DleteAllById(this.tvControlItem.SelectedNodeID);
this.InitTreeMenu();
}
/// <summary>
/// Tree点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void trSafetyOrganization_NodeCommand(object sender, TreeCommandEventArgs e)
{
if (!string.IsNullOrEmpty(tvControlItem.SelectedNodeID))
{
var unit = HJGL_YardPlanningService.GetHJGL_YardPlanningById( tvControlItem.SelectedNodeID);
this.imgPhoto.ImageUrl = null;
if (unit != null)
{
this.imgPhoto.ImageUrl = "~/" + unit.FlowChartPic;
}
}
else
{
this.imgPhoto.ImageUrl = null;
}
}
#endregion
protected void btnAttachUrl_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(tvControlItem.SelectedNodeID)&& tvControlItem.SelectedNode.CommandName!="主项")
{
var model = HJGL_YardPlanningService.GetHJGL_YardPlanningById( tvControlItem.SelectedNodeID);
if (model == null)
{
HJGL_YardPlanningService.SavePic( tvControlItem.SelectedNodeID, "");
// model = HJGL_YardPlanningService.GetHJGL_YardPlanningByProjectId(this.CurrUser.LoginProjectId, tvControlItem.SelectedNodeID);
}
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/HJGL_YardPlanning&menuId={1}", model.YardPlanningId, BLL.Const.HJGL_YardPlanningMenuId)));
}
else
{
Alert.ShowInTop("主节点无法上传,请新增节点!", MessageBoxIcon.Warning);
}
}
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
ShowNotify("修改成功!", MessageBoxIcon.Success);
this.InitTreeMenu();
}
}
}