YZ_BSF/HJGL/FineUIPro.Web/WeldingProcess/TrustManage/PointManage.aspx.cs

1273 lines
58 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.WeldingProcess.TrustManage
{
public partial class PointManage : PageBase
{
#region
/// <summary>
/// 批次主键
/// </summary>
public string PointBatchId
{
get
{
return (string)ViewState["PointBatchId"];
}
set
{
ViewState["PointBatchId"] = value;
}
}
#endregion
#region
/// <summary>
/// 加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
this.txtJotDate.Text = DateTime.Now.Date.ToShortDateString();
this.InitTreeMenu();//加载树
EndPoint();
}
}
/// <summary>
/// 当批超过15天时自动点口关闭
/// </summary>
private void EndPoint()
{
DateTime newDate = DateTime.Now.Date;
var point = from x in Funs.DB.Batch_PointBatch where x.StartDate <= newDate.AddDays(-15) && x.EndDate == null select x;
foreach(var p in point)
{
var pointBatchItem = (from x in Funs.DB.Batch_PointBatchItem
where x.PointBatchId == p.PointBatchId
orderby x.CreatDate
select x).ToList();
var rate = BLL.Base_DetectionRateService.GetDetectionRateByDetectionRateId(p.DetectionRateId);
if (pointBatchItem.Where(e => e.PointState == "1").Count() == 0) // 表示批里没有点口
{
if (pointBatchItem.Count() > 0 )
{
//int a = pointBatchItem.Count() - 1;
//string value = (pointBatchItem).ToList()[a].PointBatchItemId;
BLL.Batch_PointBatchItemService.UpdatePointBatchItem(pointBatchItem[0].PointBatchItemId, "1", System.DateTime.Now, null);
Batch_PointBatchService.UpdatePointBatch(p.PointBatchId, System.DateTime.Now);
}
}
if (pointBatchItem.Count() > 0 && pointBatchItem.Count() >= (100 / rate.DetectionRateValue))
{
//结束批前如点口未关闭,则先关闭点口
Batch_PointBatchService.UpdatePointBatch(p.PointBatchId, System.DateTime.Now);
Batch_PointBatchService.UpdatePointBatchClearDate(p.PointBatchId, System.DateTime.Now); //结束批
}
}
}
#region
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
if (string.IsNullOrEmpty(this.txtJotDate.Text))
{
Alert.ShowInTop("请选择月份!", MessageBoxIcon.Warning);
}
this.tvControlItem.Nodes.Clear();
//List<Model.Base_Unit> units = null;
Model.HJGLDB db = Funs.DB;
Model.Project_Unit pUnit = BLL.Project_UnitService.GetProject_UnitByProjectIdUnitId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId);
var unitList = (from x in db.Project_WorkArea
where x.ProjectId == this.CurrUser.LoginProjectId
select x.UnitId).Distinct();
var units = from x in unitList
join y in db.Base_Unit on x equals y.UnitId
select new { UnitId = x, y.UnitName };
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 = units.Where(x => x.UnitId == CurrUser.UnitId);
//units.Add(BLL.Base_UnitService.GetUnit(this.CurrUser.UnitId));
}
foreach (var unit in units)
{
TreeNode rootNode = new TreeNode
{
Text = unit.UnitName,
NodeID = unit.UnitId,
ToolTip = "施工单位",
Expanded = true
};//定义根节点
this.tvControlItem.Nodes.Add(rootNode);
var install = (from x in db.Project_Installation
join y in db.Batch_PointBatch on x.InstallationId equals y.InstallationId
where x.ProjectId == this.CurrUser.LoginProjectId
&& y.UnitId==unit.UnitId
orderby x.InstallationCode
select new { x.InstallationId, x.InstallationName }).Distinct();
foreach (var item in install)
{
TreeNode newNode = new TreeNode
{
Text = item.InstallationName,
NodeID = item.InstallationId + "|" + rootNode.NodeID,
EnableExpandEvent = true,
ToolTip = "装置",
};
rootNode.Nodes.Add(newNode);
TreeNode tn1 = new TreeNode
{
Text = "探伤类型",
NodeID = "探伤类型",
};
newNode.Nodes.Add(tn1);
}
}
}
#endregion
#endregion
#region
/// <summary>
/// 绑定树节点
/// </summary>
/// <param name="node"></param>
private void BindNodes(TreeNode node, List<Model.View_Batch_PointBatch> pointManages)
{
if (node.ToolTip == "施工单位")
{
var install = (from x in pointManages where x.ProjectId==this.CurrUser.LoginProjectId
orderby x.InstallationCode
select new { x.InstallationId, x.InstallationName }).Distinct();
foreach (var item in install)
{
TreeNode newNode = new TreeNode
{
Text = item.InstallationName,
NodeID = item.InstallationId + "|" + node.NodeID,
ToolTip = "装置",
};
node.Nodes.Add(newNode);
var installPointManages = pointManages.Where(x => x.InstallationId == item.InstallationId);
if (installPointManages.Count() > 0)
{
this.BindNodes(newNode, installPointManages.ToList());
}
}
}
else if (node.ToolTip == "装置")
{
var detectionTypes = (from x in pointManages
orderby x.DetectionTypeCode
select new { x.DetectionTypeId, x.DetectionTypeName }).Distinct();
foreach (var item in detectionTypes)
{
TreeNode newNode = new TreeNode
{
Text = item.DetectionTypeName,
NodeID = item.DetectionTypeId + "|" + node.NodeID,
ToolTip = "探伤类型",
};
node.Nodes.Add(newNode);
var detectionTypePointManages = pointManages.Where(x => x.DetectionTypeId == item.DetectionTypeId);
if (detectionTypePointManages.Count() > 0)
{
this.BindNodes(newNode, detectionTypePointManages.ToList());
}
}
}
else if (node.ToolTip == "探伤类型")
{
var detectionRates = (from x in pointManages
orderby x.DetectionRateCode
select new { x.DetectionRateId, x.DetectionRateCode }).Distinct();
foreach (var item in detectionRates)
{
TreeNode newNode = new TreeNode
{
Text = item.DetectionRateCode,
NodeID = item.DetectionRateId + "|" + node.NodeID,
ToolTip = "检测比例",
};
node.Nodes.Add(newNode);
var detectionRatePointManages = pointManages.Where(x => x.DetectionRateId == item.DetectionRateId);
if (detectionRatePointManages.Count() > 0)
{
this.BindNodes(newNode, detectionRatePointManages.ToList());
}
}
}
else if (node.ToolTip == "检测比例")
{
var pointManageItems = from x in pointManages
orderby x.PointBatchCode
select x;
foreach (var item in pointManageItems)
{
if (!string.IsNullOrEmpty(this.txtJotDate.Text))
{
DateTime start = Convert.ToDateTime(this.txtJotDate.Text.Trim());
string startDate = start.Year + "-" + start.Month + "-" + "01";
DateTime sar = Convert.ToDateTime(startDate);
DateTime end = sar.AddMonths(1);
var q = from x in Funs.DB.Batch_PointBatchItem
where x.PointBatchId == item.PointBatchId && x.WeldingDate >= sar && x.WeldingDate < end
select x;
if (q.Count() > 0)
{
TreeNode newNode = new TreeNode
{
NodeID = item.PointBatchId,
ToolTip = "批",
EnableClickEvent = true,
};
if (BLL.Batch_PointBatchService.GetIsShowPointRepairByPointBatchId(item.PointBatchId)) ////存在返修 蓝色
{
newNode.Text = "<font color='#0000FF'>" + item.PointBatchCode + "</font>";
newNode.ToolTip = "批中存在返修口";
}
else if (!item.EndDate.HasValue) ////批 没有关闭 粉色
{
newNode.Text = "<font color='#FA58D0'>" + item.PointBatchCode + "</font>";
newNode.ToolTip = "批尚未关闭";
}
else if (!item.IsTrust.HasValue || item.IsTrust == false) ////没有委托深黄色
{
newNode.Text = "<font color='#FF8C00'>" + item.PointBatchCode + "</font>";
newNode.ToolTip = "批未委托";
} ////当天批
else if (string.Format("{0:yyyy-MM-dd}", item.StartDate) == string.Format("{0:yyyy-MM-dd}", System.DateTime.Now)
|| string.Format("{0:yyyy-MM-dd}", item.EndDate) == string.Format("{0:yyyy-MM-dd}", System.DateTime.Now))
{
newNode.Text = "<font color='#EE0000'>" + item.PointBatchCode + "</font>";
newNode.ToolTip = "当天批";
}
else
{
newNode.Text = item.PointBatchCode;
}
node.Nodes.Add(newNode);
}
}
}
}
}
protected void tvControlItem_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
DateTime start = Convert.ToDateTime(this.txtJotDate.Text.Trim());
string startDate = start.Year + "-" + start.Month + "-" + "01";
DateTime sar = Convert.ToDateTime(startDate);
DateTime end = sar.AddMonths(1);
e.Node.Nodes.Clear();
if (e.Node.ToolTip == "装置")
{
var detectionTypes = from x in Funs.DB.Base_DetectionType
orderby x.DetectionTypeCode
select new { x.DetectionTypeId, x.DetectionTypeName };
foreach (var item in detectionTypes)
{
var pointManages = from x in Funs.DB.Batch_PointBatch
where x.ProjectId == this.CurrUser.LoginProjectId
&& x.InstallationId == e.Node.NodeID.Split('|')[0]
&& x.UnitId == e.Node.ParentNode.NodeID.Split('|')[0]
&& x.DetectionTypeId == item.DetectionTypeId
&& x.StartDate >= start && x.StartDate < end
select x;
TreeNode newNode = new TreeNode();
if (pointManages.Count() > 0)
{
newNode.Text = item.DetectionTypeName;
newNode.NodeID = item.DetectionTypeId + "|" + e.Node.NodeID;
newNode.EnableExpandEvent = true;
newNode.ToolTip = "探伤类型";
e.Node.Nodes.Add(newNode);
}
TreeNode tn1 = new TreeNode
{
Text = "检测比例",
NodeID = "检测比例",
};
newNode.Nodes.Add(tn1);
}
}
if (e.Node.ToolTip == "探伤类型")
{
var detectionRates = from x in Funs.DB.Base_DetectionRate
orderby x.DetectionRateCode
select new { x.DetectionRateId, x.DetectionRateCode };
foreach (var item in detectionRates)
{
var pointManages = from x in Funs.DB.Batch_PointBatch
where x.ProjectId == this.CurrUser.LoginProjectId
&& x.InstallationId == e.Node.ParentNode.NodeID.Split('|')[0]
&& x.UnitId == e.Node.ParentNode.ParentNode.NodeID.Split('|')[0]
&& x.DetectionTypeId == e.Node.NodeID.Split('|')[0]
&& x.DetectionRateId == item.DetectionRateId
&& x.StartDate >= start && x.StartDate < end
select x;
TreeNode newNode = new TreeNode();
if (pointManages.Count() > 0)
{
newNode.Text = item.DetectionRateCode;
newNode.NodeID = item.DetectionRateId + "|" + e.Node.NodeID;
newNode.EnableExpandEvent = true;
newNode.ToolTip = "检测比例";
e.Node.Nodes.Add(newNode);
}
TreeNode tn1 = new TreeNode
{
Text = "检测批",
NodeID = "检测批",
};
newNode.Nodes.Add(tn1);
}
}
if (e.Node.ToolTip == "检测比例")
{
var pointManages = from x in Funs.DB.Batch_PointBatch
join y in Funs.DB.Welder_Welder on x.WelderId equals y.WelderId
where x.ProjectId == this.CurrUser.LoginProjectId
&& x.DetectionRateId == e.NodeID.Split('|')[0]
&& x.DetectionTypeId == e.Node.ParentNode.NodeID.Split('|')[0]
&& x.InstallationId == e.Node.ParentNode.ParentNode.NodeID.Split('|')[0]
&& x.UnitId == e.Node.ParentNode.ParentNode.ParentNode.NodeID.Split('|')[0]
&& x.StartDate >= start && x.StartDate < end
select new { x.PointBatchId, x.PointBatchCode,x.StartDate, x.EndDate, x.ClearDate, x.IsTrust, x.IsCheck, y.WelderCode };
if (!string.IsNullOrEmpty(this.txtWelderCode.Text))
{
pointManages = pointManages.Where(x => x.WelderCode.Contains(this.txtWelderCode.Text.Trim()));
}
if (!string.IsNullOrEmpty(txtPointBatchCode.Text))
{
pointManages = pointManages.Where(x => x.PointBatchCode.Contains(this.txtPointBatchCode.Text.Trim()));
}
if (this.drpState.SelectedValue == "2")
{
pointManages = pointManages.Where(p => p.EndDate == null);
}
else if (this.drpState.SelectedValue == "3")
{
pointManages = pointManages.Where(p => p.EndDate != null);
}
else if (this.drpState.SelectedValue == "4")
{
pointManages = pointManages.Where(p => p.ClearDate == null);
}
else if (this.drpState.SelectedValue == "5")
{
pointManages = pointManages.Where(p => p.ClearDate != null);
}
if (this.drpTrust.SelectedValue == "2")
{
pointManages = pointManages.Where(p => !p.IsTrust.HasValue || !p.IsTrust.Value);
}
else if (this.drpTrust.SelectedValue == "3")
{
pointManages = pointManages.Where(p => p.IsTrust.HasValue && p.IsTrust.Value);
}
else if (this.drpTrust.SelectedValue == "4")
{
pointManages = pointManages.Where(p => p.IsCheck.HasValue && p.IsCheck.Value);
}
foreach (var item in pointManages)
{
var q = from x in Funs.DB.Batch_PointBatchItem
where x.PointBatchId == item.PointBatchId
select x;
if (q.Count() > 0)
{
TreeNode newNode = new TreeNode
{
NodeID = item.PointBatchId,
ToolTip = "批号",
EnableClickEvent = true,
};
if (BLL.Batch_PointBatchService.GetIsShowPointRepairByPointBatchId(item.PointBatchId)) ////存在返修 蓝色
{
newNode.Text = "<font color='#0000FF'>" + item.PointBatchCode + "</font>";
newNode.ToolTip = "批中存在返修口";
}
else if (!item.EndDate.HasValue) ////批 没有关闭 粉色
{
newNode.Text = "<font color='#FA58D0'>" + item.PointBatchCode + "</font>";
newNode.ToolTip = "批尚未关闭";
}
else if (!item.IsTrust.HasValue || item.IsTrust == false) ////没有委托深黄色
{
newNode.Text = "<font color='#FF8C00'>" + item.PointBatchCode + "</font>";
newNode.ToolTip = "批未委托";
} ////当天批
else if (string.Format("{0:yyyy-MM-dd}", item.StartDate) == string.Format("{0:yyyy-MM-dd}", System.DateTime.Now)
|| string.Format("{0:yyyy-MM-dd}", item.EndDate) == string.Format("{0:yyyy-MM-dd}", System.DateTime.Now))
{
newNode.Text = "<font color='#EE0000'>" + item.PointBatchCode + "</font>";
newNode.ToolTip = "当天批";
}
else
{
newNode.Text = item.PointBatchCode;
}
e.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)
{
if (this.tvControlItem.SelectedNodeID != "0")
{
this.PointBatchId = tvControlItem.SelectedNodeID;
this.BindGrid();
}
}
#endregion
#region
#region
/// <summary>
/// 加载页面输入提交信息
/// </summary>
private void PageInfoLoad()
{
this.txtStartDate.Text = string.Empty;
this.txtEndDate.Text = string.Empty;
this.txtState.Text = "未关闭";
this.txtClearDate.Text = string.Empty;
this.txtClearState.Text = "批未结束";
Model.Batch_PointBatch pointBatch = BLL.Batch_PointBatchService.GetPointBatchById(this.PointBatchId);
if (pointBatch != null)
{
if (pointBatch.StartDate.HasValue)
{
this.txtStartDate.Text = string.Format("{0:yyyy-MM-dd}", pointBatch.StartDate);
}
if (pointBatch.EndDate.HasValue)
{
this.txtEndDate.Text = string.Format("{0:yyyy-MM-dd}", pointBatch.EndDate);
this.txtState.Text = "已关闭";
}
if (pointBatch.ClearDate.HasValue)
{
this.txtClearDate.Text = string.Format("{0:yyyy-MM-dd}", pointBatch.ClearDate);
this.txtClearState.Text = "批结束";
}
}
}
#endregion
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid()
{
this.PageInfoLoad();
string strSql = @"SELECT PointBatchItemId,PointBatchId,WeldJointId,PointState,PointDate,RepairDate,CutDate,WorkAreaCode,
WeldJointCode,MaterialCode,JointArea,Size,WeldingDate,PipelineCode,PipingClassName,Remark
FROM dbo.View_Batch_PointBatchItem
WHERE PointBatchId='" + this.PointBatchId +"'";
List<SqlParameter> listStr = new List<SqlParameter>();
//if (!string.IsNullOrEmpty(Request.Params["userId"]))
//{
// strSql += " AND ProjectUser.UserId = @UserId ";
// listStr.Add(new SqlParameter("@UserId", Request.Params["userId"]));
//}
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();
for (int i = 0; i < this.Grid1.Rows.Count; i++)
{
var pointItem = BLL.Batch_PointBatchItemService.GetPointBatchItemByPointBatchItemId(this.Grid1.Rows[i].DataKeys[0].ToString());
if (pointItem != null)
{
if (pointItem.IsCheckRepair == true)
{
this.Grid1.Rows[i].CellCssClasses[3] = "colorredRed";
}
else if (pointItem.PointState != null)
{
this.Grid1.Rows[i].CellCssClasses[3] = "colorredBlue";
this.Grid1.Rows[i].CellCssClasses[6] = "colorredBlue";
}
}
}
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
#endregion
#region
#region
/// <summary>
/// 页索引改变事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
#endregion
#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 ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
#endregion
#endregion
#region
/// <summary>
/// 批关闭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
this.BindGrid();
}
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Tree_TextChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
}
#endregion
#endregion
#region
/// <summary>
/// 手动点口关闭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnClose_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PointManageMenuId, Const.BtnPointClose))
{
if (String.IsNullOrEmpty(this.PointBatchId))
{
Alert.ShowInTop("请选择所关闭的批次!", MessageBoxIcon.Warning);
return;
}
else
{
if (!BLL.Batch_PointBatchService.IsPointBatchClose(PointBatchId))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("ShowPointClose.aspx?PointBatchId={0}", this.PointBatchId, "手动点口关闭 - ")));
}
else
{
Alert.ShowInTop("该批次已关闭!", MessageBoxIcon.Warning);
}
}
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
/// <summary>
/// 打开重新点口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOpenResetPoint_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PointManageMenuId, Const.BtnOpenResetPoint))
{
var pointBatch = BLL.Batch_PointBatchService.GetPointBatchById(this.PointBatchId);
if (pointBatch != null && pointBatch.EndDate.HasValue && !pointBatch.IsCheck.HasValue)
{
var item = Funs.DB.Batch_PointBatchItem.FirstOrDefault(p => p.PointBatchId == PointBatchId && p.IsCheckRepair==true);
if (item != null)
{
Alert.ShowInTop("已检测,不能打开重新点口!");
return;
}
var q = from x in BLL.Funs.DB.Batch_BatchTrust where x.TopointBatch.Contains(PointBatchId) select x;
if (q.Count() > 1 && q.FirstOrDefault(x => x.IsCheck.Value) != null)
{
Alert.ShowInTop("已检测,不能打开重新点口!");
return;
}
else
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("OpenResetPoint.aspx?PointBatchId={0}", this.PointBatchId, "重新点口 - ")));
}
}
else
{
Alert.ShowInTop("请选择已关闭且未检测批!");
}
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
/// <summary>
/// 手动结束批
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnClear_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PointManageMenuId, Const.BtnClearBatch))
{
string info = "该批次已结束!";
var point = BLL.Batch_PointBatchService.GetPointBatchById(this.PointBatchId);
if (point != null && !point.ClearDate.HasValue)
{
// 修改:不点口也可结束批
//var q = Funs.DB.Batch_PointBatchItem.FirstOrDefault(x => x.PointBatchId == PointBatchId && x.PointState == "1");
//if (q != null)
//{
Batch_PointBatchService.UpdatePointBatch(PointBatchId, System.DateTime.Now);
BLL.Batch_PointBatchService.UpdatePointBatchClearDate(PointBatchId, System.DateTime.Now);
this.txtClearDate.Text = point.ClearDate.Value.ToShortDateString();
this.txtClearState.Text = "批结束";
BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PointManageMenuId, Const.BtnClearBatch, this.PointBatchId);
//}
//else
//{
// info = "该批次未点口,请手动点口后再结束批!";
//}
}
Alert.ShowInTop(info);
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
/// <summary>
/// 重新选择扩口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSelectExpandPoint_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PointManageMenuId, Const.BtnSelectResetExpand))
{
var pointBatch = BLL.Batch_PointBatchService.GetPointBatchById(this.PointBatchId);
if (pointBatch != null)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SelectExpandPoint.aspx?PointBatchId={0}", this.PointBatchId, "选择扩口 - ")));
//var pointBatchItem = from x in Funs.DB.Batch_PointBatchItem
// join y in Funs.DB.Batch_BatchTrustItem on x.PointBatchItemId equals y.TrustBatchItemId
// join z in Funs.DB.Batch_NDEItem on y.TrustBatchItemId equals z.TrustBatchItemId
// where x.IsCheckRepair.Value && z.SubmitDate.HasValue
// select x;
//if (pointBatchItem.Count() == 0)
//{
// Alert.ShowInTop("不存在返修口,无法选择扩透口!", MessageBoxIcon.Warning);
// return;
//}
//else
//{
// PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("SelectExpandPoint.aspx?PointBatchId={0}", this.PointBatchId, "选择扩口 - ")));
//}
}
else
{
Alert.ShowInTop("请选择扩透所在的批次!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
#endregion
#region
/// <summary>
/// 生成
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnGenerate_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PointManageMenuId, Const.BtnGenerate))
{
/////取当前项目所有未委托批
//var getViewPointBatchLists = (from x in Funs.DB.View_Batch_PointBatch
// where x.EndDate.HasValue && (!x.IsTrust.HasValue || !x.IsTrust.Value) && x.ProjectId == this.CurrUser.LoginProjectId
// select x).ToList();
var getViewGenerateTrustLists = (from x in Funs.DB.View_GenerateTrust where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList();
if (getViewGenerateTrustLists.Count() > 0)
{
var getUnit = BLL.Base_UnitService.GetUnit(this.CurrUser.UnitId);
if (getUnit == null || getUnit.UnitTypeId == "1" || getUnit.UnitTypeId == "2" || getUnit.UnitTypeId == "3")
{
GenerateTrust(getViewGenerateTrustLists);
}
else
{
var getUnitViewGenerateTrustLists = getViewGenerateTrustLists.Where(x => x.UnitId == this.CurrUser.UnitId);
if (getUnitViewGenerateTrustLists.Count() > 0)
{
// 当前单位未委托批
GenerateTrust(getUnitViewGenerateTrustLists.ToList());
}
else
{
Alert.ShowInTop("所属单位点口已全部生成委托单!", MessageBoxIcon.Warning);
}
}
BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PointManageMenuId, Const.BtnGenerate, null);
this.InitTreeMenu();//加载树
this.BindGrid();
}
else
{
Alert.ShowInTop("已全部生成委托单!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
/// <summary>
/// 生成委托单
/// </summary>
/// <param name="unitId"></param>
private void GenerateTrust(List<Model.View_GenerateTrust> GenerateTrustLists)
{
Model.HJGLDB db = Funs.DB;
foreach (var trust in GenerateTrustLists)
{
Model.Batch_BatchTrust newBatchTrust = new Model.Batch_BatchTrust();
var project = BLL.Base_ProjectService.GetProjectByProjectId(trust.ProjectId);
var unit = BLL.Base_UnitService.GetUnit(trust.UnitId);
var ndt = BLL.Base_DetectionTypeService.GetDetectionTypeByDetectionTypeId(trust.DetectionTypeId);
var area = BLL.Project_WorkAreaService.GetProject_WorkAreaByWorkAreaId(trust.WorkAreaId);
string perfix = string.Empty;
if (trust.PointState == "1" && trust.IsCheckRepair == false)
{
perfix = project.ProjectCode + "-" + unit.UnitCode + "-" + ndt.DetectionTypeCode + "-" + area.WorkAreaCode + "-";
newBatchTrust.TrustBatchCode = BLL.SQLHelper.RunProcNewId("SpGetNewCode", "dbo.Batch_BatchTrust", "TrustBatchCode", project.ProjectId, perfix);
}
//else if (trust.PointState == "1" && trust.IsCheckRepair == true)
//{
// newBatchTrust.TrustBatchCode = GetNewRTrust(trust.TrustBatchCode);
//}
else
{
newBatchTrust.TrustBatchCode = trust.TrustBatchCode;
// newBatchTrust.TrustBatchCode = GetNewKTrust(trust.TrustBatchCode);
}
string trustBatchId = SQLHelper.GetNewID(typeof(Model.Batch_BatchTrust));
newBatchTrust.TrustBatchId = trustBatchId;
newBatchTrust.TrustDate = DateTime.Now;
newBatchTrust.ProjectId = trust.ProjectId;
newBatchTrust.UnitId = trust.UnitId;
newBatchTrust.InstallationId = trust.InstallationId;
newBatchTrust.WorkAreaId = trust.WorkAreaId;
//newBatchTrust.PipelineId = trust.PipelineId;
newBatchTrust.DetectionTypeId = trust.DetectionTypeId;
if (trust.IsCheckRepair == true)
{
newBatchTrust.TrustType = "3"; // 返修委托
}
else
{
newBatchTrust.TrustType = trust.PointState;
}
BLL.Batch_BatchTrustService.AddBatchTrust(newBatchTrust); // 新增委托单
// 生成委托条件对比
List<Model.View_GenerateTrustItem> generateTrustItem = null;
if (trust.PointState == "1" && trust.IsCheckRepair == false)
{
generateTrustItem = (from x in db.View_GenerateTrustItem
where x.ProjectId == trust.ProjectId && x.InstallationId == trust.InstallationId
&& x.WorkAreaId == trust.WorkAreaId && x.UnitId == trust.UnitId
&& x.DetectionTypeId == trust.DetectionTypeId && x.PointState == trust.PointState
&& x.IsCheckRepair == trust.IsCheckRepair
select x).ToList();
}
else
{
generateTrustItem = (from x in db.View_GenerateTrustItem
where x.ProjectId == trust.ProjectId && x.InstallationId == trust.InstallationId
&& x.WorkAreaId == trust.WorkAreaId && x.UnitId == trust.UnitId
&& x.DetectionTypeId == trust.DetectionTypeId && x.PointState == trust.PointState
&& x.IsCheckRepair == trust.IsCheckRepair
&& x.TrustBatchCode==trust.TrustBatchCode
select x).ToList();
}
string toPointBatch = string.Empty;
// 生成委托明细,并回写点口明细信息
foreach (var item in generateTrustItem)
{
if (BLL.Batch_PointBatchService.GetIsGenerateTrust(item.PointBatchItemId)) ////生成委托单的条件判断
{
toPointBatch = toPointBatch + item.PointBatchId + ",";
Model.Batch_BatchTrustItem trustItem = new Model.Batch_BatchTrustItem
{
TrustBatchItemId = SQLHelper.GetNewID(typeof(Model.Batch_BatchTrustItem)),
TrustBatchId = trustBatchId,
PointBatchItemId = item.PointBatchItemId,
WeldJointId = item.WeldJointId,
CreateDate = DateTime.Now
};
Batch_BatchTrustItemService.AddBatchTrustItem(trustItem);
}
Model.Batch_PointBatchItem pointBatchItem = db.Batch_PointBatchItem.FirstOrDefault(e => e.PointBatchItemId == item.PointBatchItemId);
if (item.IsCheckRepair == true)
{
pointBatchItem.IsCheckRepair = false;
}
pointBatchItem.IsBuildTrust = true;
db.SubmitChanges();
}
// 回写委托批对应点口信息
if (!string.IsNullOrEmpty(toPointBatch))
{
List<string> pointBatchList = Funs.GetStrListByStr(toPointBatch, ',');
foreach (string pointBatchId in pointBatchList)
{
var updatePointBatch = BLL.Batch_PointBatchService.GetPointBatchById(pointBatchId);
if (updatePointBatch != null)
{
BLL.Batch_PointBatchService.UpdatePointTrustState(pointBatchId, true);
}
}
toPointBatch = toPointBatch.Substring(0, toPointBatch.Length - 1);
var updateTrut = BLL.Batch_BatchTrustService.GetBatchTrustById(trustBatchId);
if (updateTrut != null)
{
updateTrut.TopointBatch = toPointBatch;
BLL.Batch_BatchTrustService.UpdateBatchTrust(updateTrut);
}
}
}
#region
////TrustGroup 为委托分组条件项目+装置+单位+探伤类型
//var trustPointBatchList = PointBatchLists.Select(x => x.TrustGroup).Distinct();
//foreach (var item in trustPointBatchList)
//{
// var insertPointBatchList = PointBatchLists.Where(x => x.TrustGroup == item);
// var firstPointBatch = insertPointBatchList.FirstOrDefault(); ////委托分组条件 第一条记录
// if (insertPointBatchList.FirstOrDefault() != null)
// {
// Model.Batch_BatchTrust newBatchTrust = new Model.Batch_BatchTrust();
// var ndt = BLL.Base_DetectionTypeService.GetDetectionTypeByDetectionTypeId(firstPointBatch.DetectionTypeId);
// string perfix = firstPointBatch.ProjectCode + "-" + firstPointBatch.UnitCode + "-" + ndt.DetectionTypeCode + "-";
// string trustBatchId = SQLHelper.GetNewID(typeof(Model.Batch_BatchTrust));
// newBatchTrust.TrustBatchId = trustBatchId;
// newBatchTrust.TrustBatchCode = BLL.SQLHelper.RunProcNewId("SpGetNewCode", "dbo.Batch_BatchTrust", "TrustBatchCode", firstPointBatch.ProjectId, perfix); ;
// newBatchTrust.TrustDate = DateTime.Now;
// newBatchTrust.ProjectId = firstPointBatch.ProjectId;
// newBatchTrust.UnitId = firstPointBatch.UnitId;
// newBatchTrust.InstallationId = firstPointBatch.InstallationId;
// newBatchTrust.DetectionTypeId = firstPointBatch.DetectionTypeId;
// ////新增委托单
// BLL.Batch_BatchTrustService.AddBatchTrust(newBatchTrust);
// string toPointBatch = string.Empty;
// foreach (var insertItem in insertPointBatchList)
// {
// toPointBatch = toPointBatch + insertItem.PointBatchId + ",";
// var pointBatchItems = from y in db.Batch_PointBatchItem
// where y.PointBatchId == insertItem.PointBatchId && y.PointState != null && !y.CutDate.HasValue && (!y.IsBuildTrust.HasValue || y.IsBuildTrust == false)
// select y;
// if (pointBatchItems.Count() > 0)
// {
// foreach (var pointBatchItem in pointBatchItems)
// {
// if (BLL.Batch_PointBatchService.GetIsGenerateTrust(pointBatchItem.PointBatchItemId)) ////生成委托单的条件判断
// {
// Model.Batch_BatchTrustItem trustItem = new Model.Batch_BatchTrustItem
// {
// TrustBatchItemId = SQLHelper.GetNewID(typeof(Model.Batch_BatchTrustItem)),
// TrustBatchId = trustBatchId,
// PointBatchItemId = pointBatchItem.PointBatchItemId,
// WeldJointId = pointBatchItem.WeldJointId,
// CreateDate = DateTime.Now
// };
// Batch_BatchTrustItemService.AddBatchTrustItem(trustItem);
// }
// if (pointBatchItem.IsCheckRepair == true)
// {
// pointBatchItem.IsCheckRepair = false;
// }
// pointBatchItem.IsBuildTrust = true;
// db.SubmitChanges();
// }
// }
// var pointBatchItemCuts = db.Batch_PointBatchItem.FirstOrDefault(y => y.PointBatchId == insertItem.PointBatchId && !y.CutDate.HasValue && y.IsCheckRepair.Value);
// if (pointBatchItemCuts != null)
// {
// pointBatchItemCuts.IsCheckRepair = false;
// db.SubmitChanges();
// }
// }
// if (!string.IsNullOrEmpty(toPointBatch))
// {
// List<string> listPointBatchIds = Funs.GetStrListByStr(toPointBatch, ',');
// foreach (var tustPointBatchId in listPointBatchIds)
// {
// var updatePointBatch = BLL.Batch_PointBatchService.GetPointBatchById(tustPointBatchId);
// if (updatePointBatch != null)
// {
// updatePointBatch.IsTrust = true;
// BLL.Batch_PointBatchService.UpdatePointBatch(updatePointBatch);
// }
// }
// toPointBatch = toPointBatch.Substring(0, toPointBatch.Length - 1);
// }
// var updateTrut = BLL.Batch_BatchTrustService.GetBatchTrustById(trustBatchId);
// if (updateTrut != null)
// {
// updateTrut.TopointBatch = toPointBatch;
// BLL.Batch_BatchTrustService.UpdateBatchTrust(updateTrut);
// }
// }
//}
#endregion
Alert.ShowInTop("已成功生成委托单!", MessageBoxIcon.Success);
}
#endregion
#region
/// <summary>
/// 切除焊口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnCut_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop(Resources.Lan.SelectLeastOneRecord, MessageBoxIcon.Warning);
return;
}
var pointBatchItem = BLL.Batch_PointBatchItemService.GetPointBatchItemByPointBatchItemId(Grid1.SelectedRowID);
if (pointBatchItem != null)
{
if (pointBatchItem.PointState == null || pointBatchItem.IsBuildTrust == null || pointBatchItem.IsBuildTrust == false)
{
//pointBatchItem.IsCheckRepair = false;
pointBatchItem.OldPointDate = pointBatchItem.PointDate;
pointBatchItem.OldPointState = pointBatchItem.PointState;
pointBatchItem.CutDate = System.DateTime.Now;////更新批明细 切除日期
Funs.DB.SubmitChanges();
BLL.Batch_PointBatchService.UpdateNewKuoOrCutJointNo(pointBatchItem.PointBatchItemId, "C");
// 更新批 是否委托:否
var updatePointBatch = BLL.Batch_PointBatchService.GetPointBatchById(this.PointBatchId);
if (updatePointBatch != null)
{
updatePointBatch.IsTrust = false;
BLL.Batch_PointBatchService.UpdatePointBatch(updatePointBatch);
}
this.BindGrid();
ShowNotify("焊口切除成功!", MessageBoxIcon.Success);
}
else
{
Alert.ShowInTop("焊口已委托,不能切除!", MessageBoxIcon.Warning);
}
}
else
{
Alert.ShowInTop("未选中要切除的焊口!", MessageBoxIcon.Warning);
}
}
#endregion
#region
/// <summary>
/// 取消扩透
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnCancel_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop(Resources.Lan.SelectLeastOneRecord, MessageBoxIcon.Warning);
return;
}
string pointBatchItemId = Grid1.SelectedRowID;
if (BLL.Batch_PointBatchService.GetIsShowCancellation(pointBatchItemId))
{
var pointBatchItem = BLL.Batch_PointBatchItemService.GetPointBatchItemByPointBatchItemId(Grid1.SelectedRowID);
if (pointBatchItem != null)
{
Model.HJGLDB db = Funs.DB;
pointBatchItem.PointDate = pointBatchItem.OldPointDate;
pointBatchItem.PointState = pointBatchItem.OldPointState;
pointBatchItem.CutDate = null; // 更新批明细 切除日期
pointBatchItem.IsBuildTrust = null;
pointBatchItem.IsCheckRepair = null;
pointBatchItem.JointMark = null;
pointBatchItem.ToPointBatchItemId = null;
pointBatchItem.Remark = null;
pointBatchItem.TrustBatchCode = null;
Funs.DB.SubmitChanges();
var trust = db.Batch_BatchTrustItem.FirstOrDefault(p => p.PointBatchItemId == pointBatchItemId);
if (trust != null)
{
var checkItem = db.Batch_NDEItem.FirstOrDefault(x => x.TrustBatchItemId == trust.TrustBatchItemId && !x.SubmitDate.HasValue);
if (checkItem != null)
{
string ndeID = checkItem.NDEID;
// 删除检测单里明细
BLL.Batch_NDEItemService.DeleteNDEItemByNDEItemID(checkItem.NDEItemID);
var c = BLL.Batch_NDEItemService.GetNDEItemByNDEID(ndeID);
if (c.Count() == 0)
{
// 当没有明细时删除对应主表
BLL.Batch_NDEService.DeleteNDEById(ndeID);
}
}
string trustBatchId = trust.TrustBatchId;
// 删除委托单里明细
BLL.Batch_BatchTrustItemService.DeleteTrustItemByTrustBatchItemId(trust.TrustBatchItemId);
var t = BLL.Batch_BatchTrustItemService.GetBatchTrustItemByTrustBatchId(trustBatchId);
if (t.Count() == 0)
{
// 当没有明细时删除对应主表
BLL.Batch_BatchTrustService.DeleteBatchTrustById(trustBatchId);
}
}
db.SubmitChanges(); //更新批明细 返修日期 状态
BLL.Batch_PointBatchService.CancellationJointNo(pointBatchItem.WeldJointId);
}
}
}
#endregion
#region
/// <summary>
/// 打印
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnPrint_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.PointBatchId))
{
string parm = string.Empty;
var pointBatch = Funs.DB.View_Batch_PointBatch.FirstOrDefault(x => x.PointBatchId == this.PointBatchId);
if (pointBatch != null)
{
if (!string.IsNullOrEmpty(pointBatch.UnitCode))
{
parm = pointBatch.UnitCode;
}
else
{
parm = "NULL";
}
if (!string.IsNullOrEmpty(pointBatch.ProjectCode))
{
parm = parm + "|" + pointBatch.ProjectCode;
}
else
{
parm = parm + "|" + "NULL";
}
if (!string.IsNullOrEmpty(pointBatch.DetectionTypeCode))
{
parm = parm + "|" + "NDE Type" + pointBatch.DetectionTypeCode;
}
else
{
parm = parm + "|" + "NDE Type" + "NULL";
}
// PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../../Report/ReportPrint.aspx?report=1&pointBatchId={0}&parm={1}", this.PointBatchId, parm, "编辑 - ")));
}
}
}
#endregion
private string GetNewRTrust(string code)
{
int r_num = 0;
string newTrustCode = string.Empty;
if (code.Contains("R1") || code.Contains("R2") || code.Contains("R3") || code.Contains("R4"))
{
int indexR = code.LastIndexOf("R");
if (indexR > 0)
{
try
{
r_num = Convert.ToInt32(code.Substring(indexR + 1, 1)) + 1;
newTrustCode = code.Substring(0, code.Length - 1) + r_num.ToString();
}
catch { }
}
}
else
{
newTrustCode = code + "R1";
}
return newTrustCode;
}
#region -
private string GetNewKTrust(string code)
{
int r_num = 0;
string newTrustCode = string.Empty;
if (code.Contains("K1-1") || code.Contains("K1-2") || code.Contains("K1-3") || code.Contains("K1-4"))
{
int indexR = code.LastIndexOf("K1-");
if (indexR > 0)
{
try
{
r_num = Convert.ToInt32(code.Substring(indexR + 1, 1)) + 1;
newTrustCode = code.Substring(0, code.Length - 1) + r_num.ToString();
}
catch { }
}
}
else
{
newTrustCode = code + "K1-1";
}
return newTrustCode;
}
#endregion
}
}