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

589 lines
26 KiB
C#

using BLL;
using MiniExcelLibs;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
namespace FineUIPro.Web.HJGL.WeldingManage
{
public partial class WeldReport : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
// ctlAuditFlow.Url = BLL.Project_SysSetService.GetAvevaNetUrl(this.CurrUser.LoginProjectId);
if (!IsPostBack)
{
this.txtMonth.Text = string.Format("{0:yyyy-MM}", DateTime.Now);
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
this.InitTreeMenu();//加载树
}
}
#region -
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
if (!string.IsNullOrEmpty(this.txtMonth.Text.Trim()))
{
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)
{
var unitNamesUnitIds = BLL.UnitService.getUnitNamesUnitIds(q.UnitId);
TreeNode tn1 = new TreeNode();
tn1.NodeID = q.UnitWorkId;
tn1.Text = q.UnitWorkName;
tn1.ToolTip = "施工单位:" + unitNamesUnitIds;
tn1.CommandName = "UnitWork";
rootNode1.Nodes.Add(tn1);
BindNodes(tn1);
}
}
if (unitWork2.Count() > 0)
{
foreach (var q in unitWork2)
{
var unitNamesUnitIds = BLL.UnitService.getUnitNamesUnitIds(q.UnitId);
TreeNode tn2 = new TreeNode();
tn2.NodeID = q.UnitWorkId;
tn2.Text = q.UnitWorkName;
tn2.ToolTip = "施工单位:" + unitNamesUnitIds;
tn2.CommandName = "UnitWork";
rootNode2.Nodes.Add(tn2);
BindNodes(tn2);
}
}
}
else
{
Alert.ShowInTop("请选择月份!", MessageBoxIcon.Warning);
}
}
private void BindNodes(TreeNode node)
{
var p = from x in Funs.DB.HJGL_WeldingDaily
where x.UnitWorkId == node.NodeID
&& x.WeldingDate < Convert.ToDateTime(this.txtMonth.Text.Trim() + "-01").AddMonths(1)
&& x.WeldingDate >= Convert.ToDateTime(this.txtMonth.Text.Trim() + "-01")
orderby x.WeldingDailyCode descending
select x;
if (p.Count() > 0)
{
foreach (var item in p)
{
TreeNode newNode = new TreeNode();
newNode.Text = item.WeldingDailyCode+"("+BLL.UnitService.getUnitNamesUnitIds(item.UnitId)+")";
newNode.NodeID = item.WeldingDailyId;
newNode.EnableClickEvent = true;
newNode.CommandName = "WeldingDaily";
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 (!string.IsNullOrEmpty(tvControlItem.SelectedNodeID))
{
this.BindGrid();
var daily = BLL.WeldingDailyService.GetPipeline_WeldingDailyByWeldingDailyId(tvControlItem.SelectedNodeID);
txtUnitName.Text = BLL.UnitService.GetUnitNameByUnitId(daily.UnitId);
txtTabler.Text = BLL.Person_PersonsService.GetPersonsNameById(daily.Tabler);
txtTableDate.Text = string.Format("{0:yyyy-MM-dd}", daily.TableDate);
txtWeldingDate.Text = string.Format("{0:yyyy-MM-dd}", daily.WeldingDate);
//Model.Parameter3D parameter3D = new Model.Parameter3D();
//Model.ColorModel colorModel = new Model.ColorModel();
//colorModel = BLL.Project_SysSetService.GetColorModel(this.CurrUser.LoginProjectId);
//parameter3D.ColorModel = colorModel;
//parameter3D.TagNum = "";
//parameter3D.ButtonType = "0,2";
//parameter3D.ModelName = HJGL_DataImportService.Getlatest3DModelNameByUnitWorkId(tvControlItem.SelectedNodeID);
//ctlAuditFlow.Url_item = BLL.Project_SysSetService.GetAvevaNetUrl(this.CurrUser.LoginProjectId) + "item/IPE%7CVPD%7C" + parameter3D.ModelName;
//ctlAuditFlow.data = parameter3D;
//ctlAuditFlow.BindData();
}
}
#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 WeldingDailyId,WeldJointId,PipelineCode,WeldJointCode,
BackingWelderCode,CoverWelderCode,Material1Code,Material2Code,
Dia,DNDia,Thickness,WeldTypeCode,WeldingMethodCode,WeldingWireCode,WeldingMode,
WeldingRodCode,Size,JointAttribute
FROM dbo.View_HJGL_WeldJoint
WHERE WeldingDailyId=@WeldingDailyId";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@WeldingDailyId", tvControlItem.SelectedNodeID));
if (!string.IsNullOrEmpty(txtPipelineCode.Text.Trim()))
{
strSql += " AND PipelineCode LIKE @pipelineCode ";
listStr.Add(new SqlParameter("@pipelineCode", "%" + this.txtPipelineCode.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(txtWelderCode.Text.Trim()))
{
strSql += " AND (BackingWelderCode LIKE @welderCode OR CoverWelderCode LIKE @welderCode)";
listStr.Add(new SqlParameter("@welderCode", "%" + this.txtWelderCode.Text.Trim() + "%"));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
var SumDia = tb.AsEnumerable().Sum(x => x.Field<decimal>("Size"));
var WelderCount = tb.AsEnumerable().Select(x => x.Field<string>("CoverWelderCode")).ToList().Distinct().Count();
txtSumSize.Text= SumDia.ToString();
txtTeam.Text = WelderCount.ToString();
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(Grid1, tb1);
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
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>
/// Grid双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
//{
// if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.HJGL_WeldReportMenuId, BLL.Const.BtnModify))
// {
// PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeldReportEdit.aspx?WeldingDailyId={0}", Grid1.SelectedRowID, "编辑 - ")));
// }
// else
// {
// ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
// }
//}
protected void Grid1_RowClick(object sender, GridRowClickEventArgs e)
{
var model = (from x in Funs.DB.View_HJGL_WeldJoint
where x.WeldJointId == Grid1.SelectedRowID
select x).FirstOrDefault();
var q = PipelineService.GetPipelineByPipelineId(model.PipelineId);
var pipecode = "/" + q.PipelineCode;
//Model.Parameter3D parameter3D = new Model.Parameter3D();
//Model.ColorModel colorModel = new Model.ColorModel();
//colorModel = BLL.Project_SysSetService.GetColorModel(this.CurrUser.LoginProjectId);
//parameter3D.ColorModel = colorModel;
//parameter3D.TagNum = pipecode;
//parameter3D.ButtonType = "0,2";
//parameter3D.ModelName = HJGL_DataImportService.Getlatest3DModelNameByUnitWorkId(tvControlItem.SelectedNodeID);
//ctlAuditFlow.Url_item = BLL.Project_SysSetService.GetAvevaNetUrl(this.CurrUser.LoginProjectId) + "item/IPE%7CVPD%7C" + parameter3D.ModelName;
//ctlAuditFlow.data = parameter3D;
//ctlAuditFlow.BindData();
}
/// <summary>
/// 增加焊接日报
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuAdd_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, Const.HJGL_WeldReportMenuId, Const.BtnAdd))
{
var unitWork = BLL.UnitWorkService.getUnitWorkByUnitWorkId(tvControlItem.SelectedNodeID);
if (!string.IsNullOrEmpty(tvControlItem.SelectedNodeID) && unitWork != null)
{
//PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeldReportEdit.aspx?unitWorkId={0}", tvControlItem.SelectedNodeID, "新增 - ")));
string window = String.Format("WeldReportEdit.aspx?unitWorkId={0}", tvControlItem.SelectedNodeID, "编辑 - ");
PageContext.RegisterStartupScript(Window1.GetSaveStateReference(hdWeldingDailyCode.ClientID) + Window1.GetShowReference(window));
}
else
{
ShowNotify("请选择单位工程", MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
}
}
/// <summary>
/// 焊接日报编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.HJGL_WeldReportMenuId, BLL.Const.BtnModify))
{
var daily = BLL.WeldingDailyService.GetPipeline_WeldingDailyByWeldingDailyId(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?WeldingDailyId={0}", tvControlItem.SelectedNodeID, "维护 - ")));
string window = String.Format("WeldReportEdit.aspx?WeldingDailyId={0}", tvControlItem.SelectedNodeID, "编辑 - ");
PageContext.RegisterStartupScript(Window1.GetSaveStateReference(hdWeldingDailyCode.ClientID) + Window1.GetShowReference(window));
}
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 (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, Const.HJGL_WeldReportMenuId, Const.BtnDelete))
{
var daily = BLL.WeldingDailyService.GetPipeline_WeldingDailyByWeldingDailyId(tvControlItem.SelectedNodeID);
if (daily == null)
{
Alert.ShowInTop("请选择要删除的日报", MessageBoxIcon.Warning);
return;
}
else
{
string weldingDailyId = tvControlItem.SelectedNodeID;
var isHotProess = from x in Funs.DB.HJGL_HotProess_TrustItem
join y in Funs.DB.HJGL_WeldJoint on x.WeldJointId equals y.WeldJointId
where y.WeldingDailyId == weldingDailyId
select x;
if (isHotProess.Count() > 0)
{
Alert.ShowInTop("该日报已有焊口生成热处理委托,不能删除!", MessageBoxIcon.Warning);
return;
}
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;
}
var isTrust = from x in Funs.DB.HJGL_Batch_BatchTrustItem
join y in Funs.DB.HJGL_WeldJoint on x.WeldJointId equals y.WeldJointId
where y.WeldingDailyId == weldingDailyId
select x;
if (isTrust.Count() == 0)
{
var weldJoints = BLL.WeldJointService.GetWeldlinesByWeldingDailyId(weldingDailyId);
if (weldJoints.Count() > 0)
{
foreach (var item in weldJoints)
{
var updateWeldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(item.WeldJointId);
if (updateWeldJoint != null)
{
updateWeldJoint.WeldingDailyId = null;
updateWeldJoint.WeldingDailyCode = null;
updateWeldJoint.CoverWelderId = null;
updateWeldJoint.BackingWelderId = null;
BLL.WeldJointService.UpdateWeldJoint(updateWeldJoint);
var pointBatchItems = from x in Funs.DB.HJGL_Batch_PointBatchItem where x.WeldJointId == item.WeldJointId select x;
string pointBatchId = pointBatchItems.FirstOrDefault().PointBatchId;
// 删除焊口所在批明细信息
BLL.PointBatchDetailService.DeleteBatchDetail(item.WeldJointId);
// 删除批信息
var batch = from x in Funs.DB.HJGL_Batch_PointBatchItem where x.PointBatchId == pointBatchId select x;
if (pointBatchId != null && batch.Count() == 0)
{
BLL.PointBatchService.DeleteBatch(pointBatchId);
}
//BLL.Batch_NDEItemService.DeleteAllNDEInfoToWeldJoint(item.WeldJointId);
}
}
}
BLL.WeldingDailyService.DeleteWeldingDaily(weldingDailyId);
BLL.LogService.AddLog(this.CurrUser.PersonId, "删除焊接日报");
ShowNotify("删除成功!", MessageBoxIcon.Success);
this.InitTreeMenu();
this.BindGrid();
}
else
{
Alert.ShowInTop("该日报下已有焊口进委托单了,不能删除!", MessageBoxIcon.Warning);
}
}
}
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)
{
string weldingDailyCode = hdWeldingDailyCode.Text;
this.InitTreeMenu();//加载树
tvControlItem.SelectedNode.Expanded = true;
if (tvControlItem.SelectedNode.CommandName == "UnitWork")
{
tvControlItem.SelectedNode.Nodes.Clear();
BindNodes(tvControlItem.SelectedNode);
foreach (var item in tvControlItem.SelectedNode.Nodes)
{
if (item.Text.Contains(weldingDailyCode))
{
tvControlItem.SelectedNodeID = item.NodeID;
}
}
}
else
{
tvControlItem.SelectedNode.ParentNode.Expanded = true;
}
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 txtTextBox_TextChanged(object sender, EventArgs e)
{
BindGrid();
}
#endregion
protected void btnOut_Click(object sender, EventArgs e)
{
var value = new Dictionary<string, object>();
string filename = "";
switch (this.tvControlItem.SelectedNode.CommandName)
{
case "UnitWork":
value = BLL.WeldingDailyService.GetFileOutValueByUnitWorkId(this.tvControlItem.SelectedNodeID, this.txtMonth.Text.Trim());
var unitWork = BLL.UnitWorkService.getUnitWorkByUnitWorkId(tvControlItem.SelectedNodeID);
filename = "焊接日报-" + unitWork.UnitWorkName+ this.txtMonth.Text.Trim()+ ".xlsx";
break;
case "WeldingDaily":
value = WeldingDailyService.GetFileOutValueById(this.tvControlItem.SelectedNodeID);
var daily = BLL.WeldingDailyService.GetPipeline_WeldingDailyByWeldingDailyId(tvControlItem.SelectedNodeID);
var unitwork = UnitWorkService.getUnitWorkByUnitWorkId(daily.UnitWorkId);
filename = "焊接日报-" + unitwork.UnitWorkName + daily.WeldingDailyCode + ".xlsx";
break;
}
string path = Funs.RootPath + @"File\Excel\Temp\焊接日报.xlsx";
path = path.Replace(".xlsx", string.Format("{0:yyyy-MM-dd-HH-mm}", DateTime.Now) + ".xlsx");
if (value.Count>0)
{
MiniExcel.SaveAs(path, value);
FileInfo info = new FileInfo(path);
long fileSize = info.Length;
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
System.Web.HttpContext.Current.Response.TransmitFile(path, 0, fileSize);
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.Close();
File.Delete(path);
}
else
{
Alert.ShowInTop("无数据,无法导出!", MessageBoxIcon.Warning);
}
}
protected void btnMenuDeleteDetail_Click(object sender, EventArgs e)
{
if (!string .IsNullOrEmpty(Grid1.SelectedRowID))
{
string errlog= BLL.WeldingDailyService.DeleteWeldingDailyItemByweldJointId(Grid1.SelectedRowID);
if (string.IsNullOrEmpty(errlog) )
{
BindGrid();
ShowNotify("删除明细成功",MessageBoxIcon.Success);
}
else
{
ShowNotify(errlog, MessageBoxIcon.Error);
}
}
}
}
}