ChengDa_English/SGGL/FineUIPro.Web/HJGL/WeldingManage/WeldReport.aspx.cs

571 lines
24 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using BLL;
namespace FineUIPro.Web.HJGL.WeldingManage
{
public partial class WeldReport : PageBase
{
#region
/// <summary>
/// 焊接日报主键
/// </summary>
public string DReportID
{
get
{
return (string)ViewState["DReportID"];
}
set
{
ViewState["DReportID"] = value;
}
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.txtMonth.Text = string.Format("{0:yyyy-MM}", DateTime.Now);
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
btnNew.OnClientClick = Window1.GetShowReference("WeldReportEdit.aspx") + "return false;";
this.InitTreeMenu();//加载树
}
}
#region -
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
if (!string.IsNullOrEmpty(this.txtMonth.Text.Trim()))
{
this.tvControlItem.Nodes.Clear();
List<Model.Base_Unit> units = null;
var getUnit = BLL.ProjectUnitService.GetProjectUnitByUnitIdProjectId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId);
if (getUnit != null && getUnit.UnitType == BLL.Const.ProjectUnitType_2)
{
units = (from x in Funs.DB.Base_Unit where x.UnitId == this.CurrUser.UnitId select x).ToList();
}
else
{
units = BLL.UnitService.GetUnitByProjectIdUnitTypeList(this.CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_2);
}
if (units != null)
{
foreach (var unit in units)
{
TreeNode rootNode = new TreeNode();//定义根节点
rootNode.Text = unit.UnitName;
rootNode.NodeID = unit.UnitId;
rootNode.Expanded = true;
rootNode.CommandName = "Unit";
this.tvControlItem.Nodes.Add(rootNode);
var instaRe = (from x in Funs.DB.BO_WeldReportMain
join y in Funs.DB.Project_Installation
on x.InstallationId equals y.InstallationId
where x.UnitId == unit.UnitId && x.ProjectId == this.CurrUser.LoginProjectId
select y).Distinct();
foreach (var ins in instaRe)
{
TreeNode newNode = new TreeNode();
newNode.Text = ins.InstallationName;
newNode.NodeID = ins.InstallationId;
newNode.EnableExpandEvent = true;
newNode.CommandName = "Installation";
rootNode.Nodes.Add(newNode);
TreeNode emptyNode = new TreeNode();
emptyNode.Text = "";
emptyNode.NodeID = "";
newNode.Nodes.Add(emptyNode);
}
}
}
else
{
Alert.ShowInTop("请先增加施工单位!", MessageBoxIcon.Warning);
return;
}
}
else
{
Alert.ShowInTop("请选择月份!", MessageBoxIcon.Warning);
}
}
#region
/// <summary>
/// 展开树
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeExpand(object sender, TreeNodeEventArgs e)
{
e.Node.Nodes.Clear();
if (e.Node.CommandName == "Installation") //展开装置
{
TreeNode newNode = new TreeNode();
newNode.Text = this.txtMonth.Text.Trim();
newNode.NodeID = this.txtMonth.Text.Trim();
newNode.EnableExpandEvent = true;
newNode.CommandName = "Month";
e.Node.Nodes.Add(newNode);
TreeNode emptyNode = new TreeNode();
emptyNode.Text = "";
emptyNode.NodeID = "";
newNode.Nodes.Add(emptyNode);
}
else if (e.Node.CommandName == "Month") //展开月份
{
DateTime startDate = Funs.GetNewDateTimeOrNow(e.Node.NodeID + "-01");
DateTime endDate = Funs.GetNewDateTimeOrNow(e.Node.NodeID + "-01").AddMonths(1);
var days = (from x in Funs.DB.BO_WeldReportMain
where x.InstallationId == e.Node.ParentNode.NodeID
&& x.UnitId == e.Node.ParentNode.ParentNode.NodeID
&& x.JOT_WeldDate >= startDate && x.JOT_WeldDate < endDate
orderby x.JOT_WeldDate
select x.JOT_WeldDate).Distinct();
foreach (var day in days)
{
TreeNode newNode = new TreeNode();
newNode.Text = string.Format("{0:yyyy-MM-dd}", day);
newNode.NodeID = day.ToString();
newNode.EnableExpandEvent = true;
newNode.CommandName = "Day";
e.Node.Nodes.Add(newNode);
TreeNode emptyNode = new TreeNode();
emptyNode.Text = "";
emptyNode.NodeID = "";
newNode.Nodes.Add(emptyNode);
}
}
else if (e.Node.CommandName == "Day") //展开日期
{
var dReports = from x in Funs.DB.BO_WeldReportMain
where x.InstallationId.ToString() == e.Node.ParentNode.ParentNode.NodeID
&& x.UnitId == e.Node.ParentNode.ParentNode.ParentNode.NodeID
&& x.JOT_WeldDate == Convert.ToDateTime(e.Node.NodeID)
orderby x.JOT_DailyReportNo
select x;
foreach (var dReport in dReports)
{
TreeNode newNode = new TreeNode();
newNode.Text = dReport.JOT_DailyReportNo;
newNode.NodeID = dReport.DReportID;
newNode.EnableClickEvent = true;
newNode.CommandName = "Report";
e.Node.Nodes.Add(newNode);
}
}
}
#endregion
#endregion
#region TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e)
{
if (!string.IsNullOrEmpty(tvControlItem.SelectedNodeID))
{
this.BindGrid();
DReportID = this.tvControlItem.SelectedNodeID;
Model.BO_WeldReportMain report = BLL.WeldReportService.GetWeldReportByDReportID(DReportID);
if (report != null)
{
this.txtDailyReportNo.Text = report.JOT_DailyReportNo;
if (!string.IsNullOrEmpty(report.UnitId))
{
this.txtUnit.Text = BLL.UnitService.GetUnitNameByUnitId(report.UnitId);
}
Model.Project_Installation ins = BLL.Project_InstallationService.GetInstallationByInstallationId(report.InstallationId);
if (ins != null)
{
this.txtInstallation.Text = ins.InstallationName;
}
if (!string.IsNullOrEmpty(report.CHT_Tabler))
{
this.txtCHT_Tabler.Text = BLL.UserService.GetUserNameByUserId(report.CHT_Tabler);
}
if (report.CHT_TableDate != null)
{
this.txtCHT_TableDate.Text = string.Format("{0:yyyy-MM-dd}", report.CHT_TableDate);
}
if (report.JOT_WeldDate != null)
{
this.txtJOT_WeldDate.Text = string.Format("{0:yyyy-MM-dd}", report.JOT_WeldDate);
}
this.txtJOT_Remark.Text = report.JOT_Remark;
}
}
}
#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>
private void BindGrid()
{
if (this.tvControlItem.SelectedNode != null)
{
string strSql = @"SELECT distinct 0 [index], [JOT_ID]
,[ProjectId]
,[JOT_JointNo]
,[DReportID]
,[DetectionTypeId]
,[DetectionRateId]
,[is_hj]
,[JOT_JointStatus]
,[JointStatusName]
,[JOT_TrustFlagName]
,[JOT_CheckFlagName]
,[ISO_ID]
,[ISO_IsoNo]
,[ISO_IsoNumber]
,[WorkAreaId]
,[MaterialId]
,[WorkAreaCode]
,[JOT_WeldDate]
,[JOT_DailyReportNo]
,[WLO_Code]
,[WLO_CodeStr]
,[STE_Name1]
,[STE_Name2]
,[Component1]
,[Component2]
,[JOT_CellWelder]
,[WED_Code1]
,[WED_Name1]
,[JOT_FloorWelder]
,[WED_Code2]
,[WED_Name2]
,[JOT_JointDesc]
,[JOT_Dia]
,[JOT_Size]
,[JOT_Sch]
,[JOT_FactSch]
,[GrooveTypeName]
,[JOTY_ID]
,[WeldTypeName]
,[WME_ID]
,[WeldingMethodName]
,[WeldSilk]
,[WeldMat]
,[WeldingLocationName]
,[JOT_DoneDin]
,[JOT_PrepareTemp]
,[ActualPrepareTemp]
,[JOT_JointAttribute]
,[JOT_Location]
,[JOT_CellTemp]
,[JOT_LastTemp]
,[JOT_HeartNo1]
,[JOT_HeartNo2]
,[PointDate]
,[PointNo]
,[JOT_FaceCheckResult]
,[JOT_FaceCheckDate]
,[JOT_FaceChecker]
,[IS_Proess]
,[JOT_BelongPipe]
,[JOT_Electricity]
,[JOT_Voltage]
,[WeldingSpeed]
,[JOT_ProessDate]
,[JOT_HotRpt]
,[PW_PointID]
,[NDTR_Name]
,[Extend_Length]
,[JOT_Remark]
FROM dbo.View_JointInfo jot
WHERE DReportID=@DReportID";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@DReportID", tvControlItem.SelectedNodeID));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
if (tb != null)
{
foreach (DataRow row in tb.Rows)
{
try
{
row["index"] = int.Parse(System.Text.RegularExpressions.Regex.Replace(row["JOT_JointNo"].ToString(), @"[^0-9]+", ""));
}
catch (Exception e)
{
row["index"] = 0;
}
}
}
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
else
{
Grid1.DataSource = null;
Grid1.DataBind();
}
}
#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 btnEdit_Click(object sender, EventArgs e)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_WeldReportMenuId, BLL.Const.BtnModify))
{
var daily = BLL.WeldReportService.GetWeldReportByDReportID(tvControlItem.SelectedNodeID);
if (!string.IsNullOrEmpty(tvControlItem.SelectedNodeID) && daily != null)
{
string weldingDailyId = tvControlItem.SelectedNodeID;
//var isPoint = from x in Funs.DB.HJGL_Batch_PointBatchItem
// join y in Funs.DB.HJGL_WeldJoint on x.WeldJointId equals y.WeldJointId
// where y.WeldingDailyId == weldingDailyId && x.PointState != null
// select x;
//if (isPoint.Count() > 1)
//{
// Alert.ShowInTop("该日报已点口,不能编辑!", MessageBoxIcon.Warning);
// return;
//}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeldReportEdit.aspx?DReportID={0}", tvControlItem.SelectedNodeID, "维护 - ")));
}
else
{
ShowNotify("请选择要编辑的日报!", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
/// <summary>
/// 删除按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDelete_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_WeldReportMenuId, Const.BtnDelete))
{
var daily = BLL.WeldReportService.GetWeldReportByDReportID(tvControlItem.SelectedNodeID);
if (daily == null)
{
Alert.ShowInTop("请选择要删除的日报", MessageBoxIcon.Warning);
return;
}
else
{
string dailyId = tvControlItem.SelectedNodeID;
List<Model.PW_JointInfo> infos = BLL.PW_JointInfoService.GetJointInfosAllByDReportID(DReportID);
bool isPoint = false;
foreach (var p in infos)
{
if (!String.IsNullOrEmpty(p.PW_PointID))
{
isPoint = true;
break;
}
}
if (isPoint == false)
{
foreach (var item in infos)
{
item.DReportID = null;
item.JOT_CellWelder = null;
item.JOT_FloorWelder = null;
item.JOT_DoneDin = null;
item.JOT_Electricity = null;
item.JOT_Voltage = null;
item.WeldingSpeed = null;
item.JOT_PrepareTemp = null;
item.ActualPrepareTemp = null;
item.JOT_CellTemp = null;
item.JOT_LastTemp = null;
BLL.PW_JointInfoService.UpdateJointInfoByDReport(item);
}
BLL.WeldReportService.DeleteWeldReportByDReportID(dailyId);
BLL.LogService.AddSys_Log(this.CurrUser, daily.JOT_DailyReportNo, dailyId, BLL.Const.HJGL_WeldReportMenuId, "删除焊接日报");
ShowNotify("删除成功!", MessageBoxIcon.Success);
}
else
{
Alert.ShowInTop("此日报已有点口数据,不能删除!", MessageBoxIcon.Warning);
}
this.InitTreeMenu();
this.BindGrid();
}
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
#endregion
#region
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
this.InitTreeMenu();//加载树
this.BindGrid();
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Tree_TextChanged(object sender, EventArgs e)
{
this.InitTreeMenu();
this.BindGrid();
}
#endregion
#region
/// <summary>
/// 报表打印
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnPrint_Click(object sender, EventArgs e)
{
DReportID = this.tvControlItem.SelectedNodeID;
Model.BO_WeldReportMain report = BLL.WeldReportService.GetWeldReportByDReportID(DReportID);
if (report != null)
{
string varValue = string.Empty;
var project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
var unitName = BLL.UnitService.GetUnitNameByUnitId(report.UnitId);
var ins = BLL.Project_InstallationService.GetInstallationByInstallationId(report.InstallationId);
varValue = ins.InstallationName + "|" + unitName + "|" + project.ProjectName;
if (!string.IsNullOrEmpty(varValue))
{
varValue = Microsoft.JScript.GlobalObject.escape(varValue.Replace("/", ","));
}
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("../../ReportPrint/ExReportPrint.aspx?ispop=1&reportId={0}&replaceParameter={1}&varValue={2}&projectId={3}", BLL.Const.HJGL_JointReportDayReportId, DReportID, varValue, this.CurrUser.LoginProjectId)));
}
else
{
Alert.ShowInTop("请选择管线!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region
/// <summary>
/// 导入焊接日报
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_WeldReportMenuId, BLL.Const.BtnSave))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeldReportDataIn.aspx", "导入 - ")));
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
#endregion
}
}