393 lines
16 KiB
C#
393 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using BLL;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace FineUIPro.Web.WeldingProcess.TestPackageManage
|
|
{
|
|
public partial class AItemEndCheck : PageBase
|
|
{
|
|
#region 定义项
|
|
/// <summary>
|
|
/// 管线主键
|
|
/// </summary>
|
|
public string PipelineId
|
|
{
|
|
get
|
|
{
|
|
return (string)ViewState["PipelineId"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["PipelineId"] = value;
|
|
}
|
|
}
|
|
|
|
private bool AppendToEnd = false;
|
|
#endregion
|
|
|
|
#region 加载页面
|
|
/// <summary>
|
|
/// 加载页面
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
this.PipelineId = string.Empty;
|
|
this.txtSearchDate.Text = string.Format("{0:yyyy-MM}", System.DateTime.Now);
|
|
this.InitTreeMenu();//加载树
|
|
// 删除选中单元格的客户端脚本
|
|
string deleteScript = GetDeleteScript();
|
|
// 新增数据初始值
|
|
JObject defaultObj = new JObject();
|
|
defaultObj.Add("Remark", "");
|
|
defaultObj.Add("CheckMan", "");
|
|
defaultObj.Add("CheckDate", "");
|
|
defaultObj.Add("DealMan", "");
|
|
defaultObj.Add("DealDate", "");
|
|
defaultObj.Add("Delete", String.Format("<a href=\"javascript:;\" onclick=\"{0}\"><img src=\"{1}\"/></a>", deleteScript, IconHelper.GetResolvedIconUrl(Icon.Delete)));
|
|
// 在第一行新增一条数据
|
|
btnNew.OnClientClick = Grid1.GetAddNewRecordReference(defaultObj, AppendToEnd);
|
|
// 删除选中行按钮
|
|
//btnDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("请至少选择一项!") + deleteScript;
|
|
// 绑定表格
|
|
BindGrid();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 加载树装置-单位-工作区
|
|
/// <summary>
|
|
/// 加载树
|
|
/// </summary>
|
|
private void InitTreeMenu()
|
|
{
|
|
this.tvControlItem.Nodes.Clear();
|
|
TreeNode rootNode = new TreeNode();
|
|
rootNode.Text = "单位-装置-月份";
|
|
rootNode.NodeID = "0";
|
|
rootNode.Expanded = true;
|
|
this.tvControlItem.Nodes.Add(rootNode);
|
|
DateTime startTime = Convert.ToDateTime(this.txtSearchDate.Text.Trim() + "-01");
|
|
DateTime endTime = startTime.AddMonths(1);
|
|
List<Model.Base_Unit> units = new List<Model.Base_Unit>(); ///单位
|
|
var pUnit = BLL.Project_UnitService.GetProject_UnitByProjectIdUnitId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId);
|
|
|
|
if (pUnit == null || pUnit.UnitType == BLL.Const.UnitType_1 || pUnit.UnitType == BLL.Const.UnitType_2
|
|
|| pUnit.UnitType == BLL.Const.UnitType_3 || pUnit.UnitType == BLL.Const.UnitType_4)
|
|
{
|
|
units = (from x in Funs.DB.Base_Unit
|
|
join y in Funs.DB.Project_Unit on x.UnitId equals y.UnitId
|
|
where y.ProjectId == this.CurrUser.LoginProjectId && y.UnitType.Contains(BLL.Const.UnitType_5)
|
|
select x).ToList();
|
|
}
|
|
else
|
|
{
|
|
units.Add(BLL.Base_UnitService.GetUnit(this.CurrUser.UnitId));
|
|
}
|
|
|
|
List<Model.PTP_TestPackage> testPackageLists = (from x in Funs.DB.PTP_TestPackage
|
|
where x.ProjectId == this.CurrUser.LoginProjectId && x.TableDate >= startTime && x.TableDate < endTime
|
|
select x).ToList();
|
|
if (units != null)
|
|
{
|
|
foreach (var unit in units)
|
|
{
|
|
TreeNode rootUnitNode = new TreeNode();//定义根节点
|
|
rootUnitNode.Text = unit.UnitName;
|
|
rootUnitNode.NodeID = unit.UnitId;
|
|
rootUnitNode.Expanded = true;
|
|
rootUnitNode.ToolTip = "施工单位";
|
|
rootNode.Nodes.Add(rootUnitNode);
|
|
var testPackageUnitList = testPackageLists.Where(x => x.UnitId == unit.UnitId).ToList();
|
|
this.BindNodes(rootUnitNode, testPackageUnitList);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ShowNotify("请先增加施工单位!", MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 绑定树节点
|
|
/// <summary>
|
|
/// 绑定树节点
|
|
/// </summary>
|
|
/// <param name="node"></param>
|
|
private void BindNodes(TreeNode node, List<Model.PTP_TestPackage> testPackageUnitList)
|
|
{
|
|
if (node.ToolTip == "施工单位")
|
|
{
|
|
var installId = (from x in testPackageUnitList
|
|
where x.UnitId == node.NodeID
|
|
select x.InstallationId).Distinct();
|
|
if (installId.Count() > 0)
|
|
{
|
|
var install = from x in Funs.DB.Project_Installation
|
|
where installId.Contains(x.InstallationId)
|
|
orderby x.InstallationCode
|
|
select x;
|
|
foreach (var q in install)
|
|
{
|
|
TreeNode newNode = new TreeNode();
|
|
newNode.Text = q.InstallationName;
|
|
newNode.NodeID = q.InstallationId + "|" + node.NodeID;
|
|
newNode.ToolTip = "装置";
|
|
newNode.Expanded = true;
|
|
node.Nodes.Add(newNode);
|
|
this.BindNodes(newNode, testPackageUnitList);
|
|
}
|
|
}
|
|
}
|
|
else if (node.ToolTip == "装置")
|
|
{
|
|
string installationId = Funs.GetStrListByStr(node.NodeID, '|')[0];
|
|
|
|
var pointListMonth = (from x in testPackageUnitList
|
|
where x.InstallationId == installationId
|
|
select string.Format("{0:yyyy-MM}", x.TableDate)).Distinct();
|
|
foreach (var item in pointListMonth)
|
|
{
|
|
TreeNode newNode = new TreeNode();
|
|
newNode.Text = item;
|
|
newNode.NodeID = item + "|" + node.NodeID;
|
|
newNode.ToolTip = "月份";
|
|
node.Nodes.Add(newNode);
|
|
this.BindNodes(newNode, testPackageUnitList);
|
|
}
|
|
}
|
|
//else if (node.ToolTip == "月份")
|
|
//{
|
|
// var days = (from x in testPackageUnitList
|
|
// where x.InstallationId == node.ParentNode.NodeID
|
|
// orderby x.PTP_TableDate descending
|
|
// select x.PTP_TableDate).Distinct();
|
|
// foreach (var item in days)
|
|
// {
|
|
// TreeNode newNode = new TreeNode();
|
|
// newNode.Text = string.Format("{0:yyyy-MM-dd}", item);
|
|
// newNode.NodeID = item.ToString();
|
|
// newNode.ToolTip = "日期";
|
|
// node.Nodes.Add(newNode);
|
|
// this.BindNodes(newNode, testPackageUnitList);
|
|
// }
|
|
//}
|
|
else if (node.ToolTip == "月份")
|
|
{
|
|
DateTime startTime = Convert.ToDateTime(this.txtSearchDate.Text.Trim() + "-01");
|
|
DateTime endTime = startTime.AddMonths(1);
|
|
string installationId = Funs.GetStrListByStr(node.ParentNode.NodeID, '|')[0];
|
|
var dReports = from x in testPackageUnitList
|
|
where x.InstallationId == installationId
|
|
&& x.TableDate >= startTime && x.TableDate < endTime
|
|
orderby x.TestPackageNo descending
|
|
select x;
|
|
foreach (var item in dReports)
|
|
{
|
|
TreeNode newNode = new TreeNode();
|
|
if (!string.IsNullOrEmpty(item.TestPackageNo))
|
|
{
|
|
newNode.Text = item.TestPackageNo;
|
|
}
|
|
else
|
|
{
|
|
newNode.Text = "未知";
|
|
}
|
|
newNode.ToolTip = "试压包";
|
|
newNode.NodeID = item.PTP_ID;
|
|
node.Nodes.Add(newNode);
|
|
this.BindNodes(newNode, testPackageUnitList);
|
|
}
|
|
}
|
|
else if (node.ToolTip == "试压包")
|
|
{
|
|
var isoIdList = from x in Funs.DB.PTP_PipelineList
|
|
where x.PTP_ID == node.NodeID
|
|
select x.PipelineId;
|
|
var isoInfos = from x in Funs.DB.Pipeline_Pipeline where isoIdList.Contains(x.PipelineId) select x;
|
|
foreach (var item in isoInfos)
|
|
{
|
|
TreeNode newNode = new TreeNode();
|
|
if (!string.IsNullOrEmpty(item.PipelineCode))
|
|
{
|
|
newNode.Text = item.PipelineCode;
|
|
}
|
|
else
|
|
{
|
|
newNode.Text = "未知";
|
|
}
|
|
newNode.ToolTip = "管线";
|
|
newNode.NodeID = item.PipelineId;
|
|
newNode.EnableClickEvent = true;
|
|
node.Nodes.Add(newNode);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 点击TreeView
|
|
/// <summary>
|
|
/// 点击TreeView
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
|
|
{
|
|
this.PipelineId = tvControlItem.SelectedNodeID;
|
|
this.BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
#region 数据绑定
|
|
/// <summary>
|
|
/// 数据绑定
|
|
/// </summary>
|
|
private void BindGrid()
|
|
{
|
|
this.Toolbar5.Hidden = true;
|
|
if (!string.IsNullOrEmpty(this.PipelineId))
|
|
{
|
|
this.Toolbar5.Hidden = false;
|
|
}
|
|
string strSql = @"SELECT * FROM dbo.PTP_AItemEndCheck WHERE PipelineId=@PipelineId";
|
|
SqlParameter[] parameter = new SqlParameter[]
|
|
{
|
|
new SqlParameter("@PipelineId",this.PipelineId),
|
|
};
|
|
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|
Grid1.DataSource = tb;
|
|
Grid1.DataBind();
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Grid1_PreDataBound(object sender, EventArgs e)
|
|
{
|
|
// 设置LinkButtonField的点击客户端事件
|
|
LinkButtonField deleteField = Grid1.FindColumn("Delete") as LinkButtonField;
|
|
deleteField.OnClientClick = GetDeleteScript();
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private string GetDeleteScript()
|
|
{
|
|
if (!CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.AItemEndCheckMenuId, Const.BtnDelete))
|
|
{
|
|
ShowNotify("您没有这个权限,请与管理员联系!");
|
|
return null;
|
|
}
|
|
else
|
|
{
|
|
return Confirm.GetShowReference("删除选中行?", String.Empty, MessageBoxIcon.Question, Grid1.GetDeleteSelectedRowsReference(), String.Empty);
|
|
}
|
|
}
|
|
|
|
#region 排序
|
|
/// <summary>
|
|
/// 排序
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Grid1_Sort(object sender, GridSortEventArgs e)
|
|
{
|
|
BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
#region 刷新页面
|
|
/// <summary>
|
|
/// 查询
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Tree_TextChanged(object sender, EventArgs e)
|
|
{
|
|
this.InitTreeMenu();
|
|
this.BindGrid();
|
|
}
|
|
#endregion
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
if (!CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.AItemEndCheckMenuId, Const.BtnSave))
|
|
{
|
|
ShowNotify("您没有这个权限,请与管理员联系!");
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(this.PipelineId))
|
|
{
|
|
ShowNotify("请先选择一条试压包下管线!");
|
|
return;
|
|
}
|
|
if (Grid1.GetModifiedData().Count > 0)
|
|
{
|
|
JArray teamGroupData = Grid1.GetMergedData();
|
|
foreach (JObject teamGroupRow in teamGroupData)
|
|
{
|
|
string status = teamGroupRow.Value<string>("status");
|
|
JObject values = teamGroupRow.Value<JObject>("values");
|
|
Model.PTP_AItemEndCheck newAItemEndCheck = new Model.PTP_AItemEndCheck();
|
|
newAItemEndCheck.PipelineId = this.PipelineId;
|
|
newAItemEndCheck.Remark = values.Value<string>("Remark");
|
|
newAItemEndCheck.CheckMan = values.Value<string>("CheckMan");
|
|
newAItemEndCheck.CheckDate = Funs.GetNewDateTime(values.Value<string>("CheckDate"));
|
|
newAItemEndCheck.DealMan = values.Value<string>("DealMan");
|
|
newAItemEndCheck.DealDate = Funs.GetNewDateTime(values.Value<string>("DealDate"));
|
|
if (status == "newadded")
|
|
{
|
|
BLL.AItemEndCheckService.AddAItemEndCheck(newAItemEndCheck);
|
|
}
|
|
else
|
|
{
|
|
newAItemEndCheck.AItemCheckId = teamGroupRow.Value<string>("id");
|
|
BLL.AItemEndCheckService.UpdateAItemEndCheck(newAItemEndCheck);
|
|
}
|
|
}
|
|
this.BindGrid();
|
|
}
|
|
|
|
ShowNotify("数据保存成功!(表格数据已重新绑定)");
|
|
}
|
|
|
|
protected void btnDelete_Click(object sender, EventArgs e)
|
|
{
|
|
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.AItemEndCheckMenuId, Const.BtnDelete))
|
|
{
|
|
string rowID = Grid1.SelectedRowID;
|
|
if (!string.IsNullOrEmpty(rowID))
|
|
{
|
|
BLL.AItemEndCheckService.DeleteAItemEndCheckByID(rowID);
|
|
BindGrid();
|
|
}
|
|
else
|
|
{
|
|
ShowNotify("请选中删除行!");
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
ShowNotify("您没有这个权限,请与管理员联系!");
|
|
}
|
|
}
|
|
}
|
|
} |