Basf_TCC7/HJGL/FineUIPro.Web/WeldingProcess/WeldingManage/WeldReport.aspx.cs

1934 lines
94 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 System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using System.Linq;
using BLL;
namespace FineUIPro.Web.WeldingProcess.WeldingManage
{
public partial class WeldReport : PageBase
{
//定义变量
/// <summary>
/// 上传预设的虚拟路径
/// </summary>
private string initPath = Const.ExcelUrl;
/// <summary>
/// 错误集合
/// </summary>
public static string errorInfos = string.Empty;
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();
BLL.Project_InstallationService.InitInstallationDropDownList(this.drpInstallation, true, this.CurrUser.LoginProjectId, Resources.Lan.PleaseSelect);
BindGrid();
//this.InitTreeMenu();//加载树
}
}
#region -
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
//if (!string.IsNullOrEmpty(this.txtMonth.Text.Trim()))
//{
// DateTime startTime = Convert.ToDateTime(this.txtMonth.Text.Trim() + "-01");
// DateTime endTime = startTime.AddMonths(1);
// this.tvControlItem.Nodes.Clear();
// var weldReports = (from x in Funs.DB.Pipeline_WeldingDaily
// where x.ProjectId == this.CurrUser.LoginProjectId
// select x).ToList();
// this.BindNodes(null, weldReports, startTime, endTime);
//}
//else
//{
// Alert.ShowInTop("请选择月份!", MessageBoxIcon.Warning);
//}
}
#endregion
#region
#region
/// <summary>
/// 绑定树节点
/// </summary>
/// <param name="node"></param>
private void BindNodes(TreeNode node, List<Model.Pipeline_WeldingDaily> projectWeldReports, DateTime startTime, DateTime endTime)
{
//var pUnitDepth = Funs.DB.Project_Unit.FirstOrDefault(x => x.UnitId == this.CurrUser.UnitId && x.ProjectId == this.CurrUser.LoginProjectId);
//if (node == null)
//{
// if (pUnitDepth!=null && pUnitDepth.UnitType == Const.UnitType_5)
// {
// var installations = (from x in projectWeldReports
// join y in Funs.DB.Project_Installation
// on x.InstallationId equals y.InstallationId
// where x.UnitId==this.CurrUser.UnitId && x.WeldingDate >= startTime && x.WeldingDate < endTime
// select y).Distinct().ToList();
// foreach (var q in installations)
// {
// TreeNode newNode = new TreeNode();
// newNode.NodeID = q.InstallationId;
// newNode.Text = q.InstallationName;
// newNode.ToolTip = Resources.Lan.InstallationName;
// newNode.Expanded = true;
// this.tvControlItem.Nodes.Add(newNode);
// this.BindNodes(newNode, projectWeldReports, startTime, endTime);
// }
// }
// else
// {
// var installations = (from x in projectWeldReports
// join y in Funs.DB.Project_Installation
// on x.InstallationId equals y.InstallationId
// where x.WeldingDate >= startTime && x.WeldingDate < endTime
// select y).Distinct().ToList();
// foreach (var q in installations)
// {
// TreeNode newNode = new TreeNode();
// newNode.NodeID = q.InstallationId;
// newNode.Text = q.InstallationName;
// newNode.ToolTip = Resources.Lan.InstallationName;
// newNode.Expanded = true;
// this.tvControlItem.Nodes.Add(newNode);
// this.BindNodes(newNode, projectWeldReports, startTime, endTime);
// }
// }
//}
//else if (node.ToolTip == Resources.Lan.InstallationName)
//{
// List<Model.Base_Unit> units = null;
// if (pUnitDepth != null && pUnitDepth.UnitType == Const.UnitType_5)
// {
// units = (from x in Funs.DB.Base_Unit
// where x.UnitId == this.CurrUser.UnitId
// select x).ToList();
// }
// else
// {
// units = (from x in projectWeldReports
// join y in Funs.DB.Project_Installation
// on x.InstallationId equals y.InstallationId
// join z in Funs.DB.Base_Unit
// on x.UnitId equals z.UnitId
// where x.InstallationId == node.NodeID && x.WeldingDate >= startTime && x.WeldingDate < endTime
// select z).Distinct().ToList();
// }
// units = units.OrderBy(x => x.InTime).Distinct().ToList();
// foreach (var q in units)
// {
// TreeNode newNode = new TreeNode();
// newNode.Text = q.UnitName;
// newNode.NodeID = q.UnitId + "|" + node.NodeID;
// newNode.ToolTip = Resources.Lan.UnitName;
// newNode.EnableClickEvent = true;
// 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)
{
this.BindGrid();
}
#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 && this.tvControlItem.SelectedNode.ToolTip == Resources.Lan.UnitName)
//{
//string[] strs = this.tvControlItem.SelectedNodeID.Split('|');
//DateTime startDate = Convert.ToDateTime(this.txtMonth.Text.Trim() + "-1");
//DateTime endDate = startDate.AddMonths(1);
//string startDateStr = string.Format("{0:yyyy-MM-dd}", startDate);
//string endDateStr = string.Format("{0:yyyy-MM-dd}", endDate);
string strSql = @"SELECT distinct d.WeldingDailyId,d.WeldingDailyCode,d.ProjectId,
d.InstallationId,d.UnitId,d.WeldingDate,d.Tabler,d.TableDate,d.Remark
FROM dbo.Pipeline_WeldingDaily d
left join dbo.View_Pipeline_WeldJoint w on w.WeldingDailyId=d.WeldingDailyId
WHERE 1=1 ";
List<SqlParameter> listStr = new List<SqlParameter>
{
};
strSql += " AND d.ProjectId =@ProjectId";
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
if (drpInstallation.SelectedValue != Const._Null)
{
strSql += " AND d.InstallationId =@InstallationId";
listStr.Add(new SqlParameter("@InstallationId", drpInstallation.SelectedValue));
}
//strSql += " AND d.UnitId =@UnitId";
//listStr.Add(new SqlParameter("@UnitId", strs[0]));
//strSql += " AND d.WeldingDate >=@startDateStr";
//listStr.Add(new SqlParameter("@startDateStr", startDateStr));
//strSql += " AND d.WeldingDate <@endDateStr";
//listStr.Add(new SqlParameter("@endDateStr", endDateStr));
if (!string.IsNullOrEmpty(this.txtWeldingDate.Text.Trim()))
{
strSql += " AND d.WeldingDate = @WeldingDate";
listStr.Add(new SqlParameter("@WeldingDate", this.txtWeldingDate.Text.Trim()));
}
if (!string.IsNullOrEmpty(this.txtPipelineCode.Text.Trim()))
{
strSql += " AND w.PipelineCode LIKE @PipelineCode";
listStr.Add(new SqlParameter("@PipelineCode", "%" + this.txtPipelineCode.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.txtWeldJointCode.Text.Trim()))
{
strSql += " AND w.WeldJointCode = @WeldJointCode";
listStr.Add(new SqlParameter("@WeldJointCode", this.txtWeldJointCode.Text.Trim()));
}
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);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
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.UserId, BLL.Const.HJGL_WeldReportMenuId, BLL.Const.BtnModify))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeldReportEdit.aspx?WeldingDailyId={0}", Grid1.SelectedRowID, "编辑 - ")));
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
}
}
/// <summary>
/// 增加焊接日报
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_WeldReportMenuId, Const.BtnAdd))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeldReportEdit.aspx?ProjectId={0}", this.CurrUser.LoginProjectId, "新增 - ")));
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, 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.UserId, BLL.Const.HJGL_WeldReportMenuId, BLL.Const.BtnModify))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop(Resources.Lan.SelectLeastOneRecord, MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("WeldReportEdit.aspx?WeldingDailyId={0}", Grid1.SelectedRowID, "维护 - ")));
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, 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.UserId, Const.HJGL_WeldReportMenuId, Const.BtnDelete))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop(Resources.Lan.SelectLeastOneRecord, MessageBoxIcon.Warning);
return;
}
else
{
string weldingDailyId = Grid1.SelectedRowID;
if (!BLL.Batch_NDEItemService.IsCheckedByWeldingDaily(weldingDailyId))
{
var weldJoints = BLL.Pipeline_WeldJointService.GetWeldlinesByWeldingDailyId(weldingDailyId);
if (weldJoints.Count() > 0)
{
foreach (var item in weldJoints)
{
var updateWeldJoint = BLL.Pipeline_WeldJointService.GetWeldJointByWeldJointId(item.WeldJointId);
if (updateWeldJoint != null)
{
updateWeldJoint.WeldingDailyId = null;
updateWeldJoint.WeldingDailyCode = null;
updateWeldJoint.CoverWelderId = null;
updateWeldJoint.BackingWelderId = null;
updateWeldJoint.WeldingDate = null;
BLL.Pipeline_WeldJointService.UpdateWeldJoint(updateWeldJoint);
// 删除焊口所在批和委托检测里信息
BLL.Batch_NDEItemService.DeleteAllNDEInfoToWeldJoint(item.WeldJointId);
}
}
}
BLL.Pipeline_WeldingDailyService.DeleteWeldingDailyByWeldingDailyId(weldingDailyId);
BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_WeldReportMenuId, Const.BtnDelete, weldingDailyId);
ShowNotify(Resources.Lan.DeletedSuccessfully, MessageBoxIcon.Success);
this.BindGrid();
}
else
{
Alert.ShowInTop("该日报下已有焊口检测了,不能删除!", MessageBoxIcon.Warning);
}
}
}
else
{
Alert.ShowInTop(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
}
}
#endregion
#region
/// <summary>
/// 模板下载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnDownLoad_Click(object sender, EventArgs e)
{
string rootPath = Server.MapPath("~/");
string uploadfilepath = rootPath + Const.DailyReportTemplateUrl;
string filePath = Const.DailyReportTemplateUrl;
string fileName = Path.GetFileName(filePath);
FileInfo info = new FileInfo(uploadfilepath);
long fileSize = info.Length;
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.ContentType = "excel/plain";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("Content-Length", fileSize.ToString().Trim());
Response.TransmitFile(uploadfilepath, 0, fileSize);
Response.End();
//PageContext.RegisterStartupScript(Confirm.GetShowReference("确定要下载焊接日报导入模板?", String.Empty, MessageBoxIcon.Question, PageManager1.GetCustomEventReference(false, "Confirm_OK"), PageManager1.GetCustomEventReference("Confirm_Cancel")));
}
/// <summary>
/// 下载导入模板
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void PageManager1_CustomEvent(object sender, CustomEventArgs e)
{
if (e.EventArgument == "Confirm_OK")
{
string rootPath = Server.MapPath("~/");
string uploadfilepath = rootPath + Const.DailyReportTemplateUrl;
string filePath = Const.DailyReportTemplateUrl;
string fileName = Path.GetFileName(filePath);
FileInfo info = new FileInfo(uploadfilepath);
long fileSize = info.Length;
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.ContentType = "excel/plain";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("Content-Length", fileSize.ToString().Trim());
Response.TransmitFile(uploadfilepath, 0, fileSize);
Response.End();
}
}
#endregion
#region
/// <summary>
/// 导入
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
string message = string.Empty;
errorInfos = string.Empty;
if (this.dailyReportUrl.HasFile == false)
{
ShowNotify("请选择Excel文件!", MessageBoxIcon.Warning);
return;
}
string IsXls = Path.GetExtension(this.dailyReportUrl.FileName).ToString().Trim().ToLower();
if (IsXls != ".xls" && IsXls != ".xlsx")
{
ShowNotify("只能选择Excel文件!", MessageBoxIcon.Warning);
return;
}
string rootPath = Server.MapPath("~/");
string initFullPath = rootPath + initPath;
if (!Directory.Exists(initFullPath))
{
Directory.CreateDirectory(initFullPath);
}
//指定上传文件名称
this.hidFileName.Text = BLL.Funs.GetNewFileName() + IsXls;
//上传文件路径
string filePath = initFullPath + this.hidFileName.Text;
//文件上传服务器
this.dailyReportUrl.PostedFile.SaveAs(filePath);
//文件上传服务器后的名称
string fileName = rootPath + initPath + this.hidFileName.Text;
//读取Excel
DataSet ds = NPOIHelper.ExcelToDataSet(fileName, out errorInfos, true);
//验证Excel读取是否有误
if (!string.IsNullOrEmpty(errorInfos))
{
ShowNotify(errorInfos, MessageBoxIcon.Warning);
return;
}
var project = BLL.Base_ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
// 管线ID的集合
List<string> pipelineIdList = new List<string>();
// 焊工资质不符合条件信息
string eventArg = string.Empty;
// 焊工WPS验证
string errorCheck = string.Empty;
string installationId = string.Empty;
string workAreaId = string.Empty;
string unitId = string.Empty;
string txtWeldDate = string.Empty;
if (ds.Tables.Count > 0)
{
var DNCompareList = BLL.Base_DNCompareService.GetDNCompareList();
var materials = from x in Funs.DB.Base_Material select x; //材质
var weldingLocation = from x in Funs.DB.Base_WeldingLocation select x; //焊接位置
var weldTypes = from x in Funs.DB.Base_WeldType select x; //焊缝类型
var weldingMethods = from x in Funs.DB.Base_WeldingMethod select x;//焊接方法
var componentss = from x in Funs.DB.Base_Components select x;//安装组件
var consumabless = from x in Funs.DB.Base_Consumables select x;//焊接耗材(焊丝、焊条)
var wpsList = from x in Funs.DB.WPQ_WPQList select x;
List<Model.Pipeline_WeldJoint> dayList = new List<Model.Pipeline_WeldJoint>();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
Model.Pipeline_WeldJoint d = new Model.Pipeline_WeldJoint();
#region
string insId = string.Empty;
if (ds.Tables[0].Rows[i]["装置编号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["装置编号"].ToString()))
{
var ins = from x in Funs.DB.Project_Installation
where x.ProjectId == this.CurrUser.LoginProjectId
&& x.InstallationCode == ds.Tables[0].Rows[i]["装置编号"].ToString()
select x;
if (ins.Count() > 0)
{
insId = ins.First().InstallationId;
if (i == 0)
{
installationId = insId;
}
}
else
{
errorInfos += (i + 2) + "行, 该项目装置编号不存在!</br>";
}
}
else
{
errorInfos += (i + 2) + "行, 装置编号不能为空!</br>";
}
string areaId = string.Empty;
if (ds.Tables[0].Rows[i]["区域编号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["区域编号"].ToString()))
{
var area = from x in Funs.DB.Project_WorkArea
where x.ProjectId == this.CurrUser.LoginProjectId
&& x.WorkAreaCode == ds.Tables[0].Rows[i]["区域编号"].ToString()
select x;
if (area.Count() > 0)
{
areaId = area.First().WorkAreaId;
if (i == 0)
{
workAreaId = areaId;
}
}
else
{
errorInfos += (i + 2) + "行, 该项目区域编号不存在!</br>";
}
}
else
{
errorInfos += (i + 2) + "行, 区域编号不能为空!</br>";
}
if (ds.Tables[0].Rows[i]["单位代码"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["单位代码"].ToString()))
{
var unit = from x in Funs.DB.Project_Unit
join y in Funs.DB.Base_Unit on x.UnitId equals y.UnitId
where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitType.Contains(Const.UnitType_5)
&& y.UnitCode == ds.Tables[0].Rows[i]["单位代码"].ToString()
select x;
if (unit.Count() > 0)
{
if (i == 0)
{
unitId = unit.First().UnitId;
}
}
else
{
errorInfos += (i + 2) + "行, 该项目单位代码不存在!</br>";
}
}
else
{
errorInfos += (i + 2) + "行, 单位代码不能为空!</br>";
}
string pipelineId = string.Empty;
if (ds.Tables[0].Rows[i]["管线号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["管线号"].ToString()))
{
var pipeline = from x in Funs.DB.Pipeline_Pipeline
where x.ProjectId == this.CurrUser.LoginProjectId
&& x.InstallationId == insId && x.WorkAreaId == areaId && x.PipelineCode == ds.Tables[0].Rows[i]["管线号"].ToString()
select x;
if (pipeline.Count() > 0)
{
pipelineId = pipeline.First().PipelineId;
pipelineIdList.Add(pipelineId);
}
else
{
errorInfos += (i + 2) + "行, 该项目管线编号不存在!</br>";
}
}
else
{
errorInfos += (i + 2) + "行,管线号不能为空!</br>";
}
string jotId = string.Empty;
string ansi = string.Empty;
decimal? size = null;
decimal? dia = null;
decimal? sch = null;
if (ds.Tables[0].Rows[i]["焊口号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊口号"].ToString()))
{
var jot = from x in Funs.DB.Pipeline_WeldJoint
where x.ProjectId == this.CurrUser.LoginProjectId
&& x.PipelineId == pipelineId && x.WeldJointCode == ds.Tables[0].Rows[i]["焊口号"].ToString()
&& (x.WeldingDailyId == null || x.WeldingDailyId == "")
select x;
if (jot.Count() > 0)
{
jotId = jot.First().WeldJointId;
d.WeldJointId = jot.First().WeldJointId;
d.Size = jot.First().Size;
d.Dia = jot.First().Dia;
d.ANSISCH = jot.First().ANSISCH;
d.Thickness = jot.First().Thickness;
d.Specification = jot.First().Specification;
d.JointAttribute = jot.First().JointAttribute;
d.WeldTypeId = jot.First().WeldTypeId;
d.WeldingLocationId = jot.First().WeldingLocationId;
d.Material1Id = jot.First().Material1Id;
d.Material2Id = jot.First().Material2Id;
d.PipeAssembly1Id = jot.First().PipeAssembly1Id;
d.PipeAssembly2Id = jot.First().PipeAssembly2Id;
d.HeartNo1 = jot.First().HeartNo1;
d.HeartNo2 = jot.First().HeartNo2;
d.WeldSilkId = jot.First().WeldSilkId;
d.WeldMatId = jot.First().WeldMatId;
d.PipeSegment = jot.First().PipeSegment;
d.WPQId = jot.First().WPQId;
d.WeldingMethodId = jot.First().WeldingMethodId;
ansi = jot.First().ANSISCH;
size = jot.First().Size;
dia = jot.First().Dia;
sch = jot.First().Thickness;
}
else
{
errorInfos += (i + 2) + "行, 该项目管线的焊口号不存在或已焊接!</br>";
}
}
else
{
errorInfos += (i + 2) + "行,焊口号不能为空!</br>";
}
if (ds.Tables[0].Rows[i]["焊接日期"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊接日期"].ToString()))
{
try
{
DateTime dd = Convert.ToDateTime(ds.Tables[0].Rows[i]["焊接日期"].ToString());
if (i == 0)
{
txtWeldDate = ds.Tables[0].Rows[i]["焊接日期"].ToString();
}
}
catch
{
errorInfos += (i + 2) + "行,焊接日期格式不正确!</br>";
}
}
else
{
errorInfos += (i + 2) + "行,焊接日期不能为空!</br>";
}
bool isExistFloor = false;
string floorWelderId = string.Empty;
if (ds.Tables[0].Rows[i]["打底焊工号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["打底焊工号"].ToString()))
{
var floorWelder = from x in Funs.DB.Welder_ProjectWelder
join y in Funs.DB.Welder_Welder on x.WelderId equals y.WelderId
where x.ProjectId == this.CurrUser.LoginProjectId
&& y.WelderCode == ds.Tables[0].Rows[i]["打底焊工号"].ToString()
select x;
if (floorWelder.Count() > 0)
{
isExistFloor = true;
floorWelderId = floorWelder.First().WelderId;
d.BackingWelderId = floorWelder.First().WelderId;
}
else
{
errorInfos += (i + 2) + "行,该项目打底焊工号不存在!</br>";
}
}
else
{
errorInfos += (i + 2) + "行,打底焊工号不能为空!</br>";
}
bool isExistCell = false;
string cellWelderId = string.Empty;
bool? welderQueIsUse = false;
if (ds.Tables[0].Rows[i]["盖面焊工号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["盖面焊工号"].ToString()))
{
var cellWelder = from x in Funs.DB.Welder_ProjectWelder
join y in Funs.DB.Welder_Welder on x.WelderId equals y.WelderId
where x.ProjectId == this.CurrUser.LoginProjectId
&& y.WelderCode == ds.Tables[0].Rows[i]["盖面焊工号"].ToString()
select x;
if (cellWelder.Count() > 0)
{
isExistCell = true;
cellWelderId = cellWelder.First().WelderId;
d.CoverWelderId = cellWelder.First().WelderId;
var projectUnit = BLL.Project_UnitService.GetProject_UnitByProjectIdUnitId(this.CurrUser.LoginProjectId, cellWelder.First().UnitId);
if (projectUnit != null)
{
welderQueIsUse = projectUnit.WelderQueIsUse;
}
}
else
{
errorInfos += (i + 2) + "行,该项目盖面焊工号不存在!</br>";
}
}
else
{
errorInfos += (i + 2) + "行,盖面焊工号不能为空!</br>";
}
if (ds.Tables[0].Rows[i]["焊缝类型"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊缝类型"].ToString()))
{
var weldType = weldTypes.FirstOrDefault(x => x.WeldTypeCode == ds.Tables[0].Rows[i]["焊缝类型"].ToString());
if (weldType == null)
{
errorInfos += (i + 2) + "行,焊缝类型[" + ds.Tables[0].Rows[i]["焊缝类型"].ToString() + "]不存在;";
}
else
{
if (!string.IsNullOrEmpty(d.WeldTypeId) && d.WeldTypeId != weldType.WeldTypeId)
{
errorInfos += (i + 2) + "行,焊缝类型[" + ds.Tables[0].Rows[i]["焊缝类型"].ToString() + "]验证不一至;";
}
else
{
d.WeldTypeId = weldType.WeldTypeId;
}
}
}
if (ds.Tables[0].Rows[i]["焊口属性活动S、固定F"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊口属性活动S、固定F"].ToString()))
{
string att = ds.Tables[0].Rows[i]["焊口属性活动S、固定F"].ToString();
if (att != "S" && att != "F")
{
errorInfos += (i + 2) + "行,焊口属性(S或F)不正确!</br>";
}
else
{
if (!string.IsNullOrEmpty(d.JointAttribute) && att != d.JointAttribute.Substring(2))
{
errorInfos += (i + 2) + "行,焊口属性[" + att + "]验证不一至;";
}
else
{
if (att == "S")
{
d.JointAttribute = "活动S";
}
else
{
d.JointAttribute = "固定F";
}
}
}
}
if (ds.Tables[0].Rows[i]["焊接位置"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊接位置"].ToString()))
{
var loc = weldingLocation.FirstOrDefault(x => x.WeldingLocationCode == ds.Tables[0].Rows[i]["焊接位置"].ToString());
if (loc == null)
{
errorInfos += (i + 2) + "行,焊接位置[" + ds.Tables[0].Rows[i]["焊接位置"].ToString() + "]不存在;";
}
else
{
d.WeldingLocationId = loc.WeldingLocationId;
//if (!string.IsNullOrEmpty(d.WeldingLocationId) && loc.WeldingLocationId != d.WeldingLocationId)
//{
// errorInfos += (i + 2) + "行,焊接位置[" + ds.Tables[0].Rows[i]["焊接位置"].ToString() + "]验证不一至;";
//}
//else
//{
// d.WeldingLocationId = loc.WeldingLocationId;
//}
}
}
if (ds.Tables[0].Rows[i]["管径"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["管径"].ToString()))
{
decimal? dd = Funs.GetNewDecimal(ds.Tables[0].Rows[i]["管径"].ToString());
if (dd != null)
{
if (d.Size != null && dd != d.Size)
{
errorInfos += (i + 2) + "行,管径[" + ds.Tables[0].Rows[i]["管径"].ToString() + "]验证不一至;";
}
else
{
d.Size = Funs.GetNewDecimal(ds.Tables[0].Rows[i]["管径"].ToString());
size = dd;
}
}
else
{
errorInfos += (i + 2) + "行,管径格式不正确!</br>";
}
}
if (ds.Tables[0].Rows[i]["美标壁厚"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["美标壁厚"].ToString()))
{
var q = from x in DNCompareList where x.Value == ds.Tables[0].Rows[i]["美标壁厚"].ToString() select x;
if (q.Count() > 0)
{
ansi = ds.Tables[0].Rows[i]["美标壁厚"].ToString();
if (!string.IsNullOrEmpty(d.ANSISCH) && ansi != d.ANSISCH)
{
errorInfos += (i + 2) + "行,美标壁厚[" + ansi + "]验证不一至;";
}
else
{
d.ANSISCH = ansi;
var dn = from x in Funs.DB.Base_DNCompare where x.PipeSize == size select x;
if (dn.Count() > 0)
{
if (dn.First().OutSizeDia != null)
{
dia = dn.First().OutSizeDia;
d.Dia = dia;
}
if (ansi == "5")
{
if (dn.First().SCH5 != null)
{
sch = dn.First().SCH5;
}
}
if (ansi == "5S")
{
if (dn.First().SCH5S != null)
{
sch = dn.First().SCH5S;
}
}
if (ansi == "10")
{
if (dn.First().SCH10 != null)
{
sch = dn.First().SCH10;
}
}
if (ansi == "10S")
{
if (dn.First().SCH10S != null)
{
sch = dn.First().SCH10S;
}
}
if (ansi == "20")
{
if (dn.First().SCH20 != null)
{
sch = dn.First().SCH20;
}
}
if (ansi == "30")
{
if (dn.First().SCH30 != null)
{
sch = dn.First().SCH30;
}
}
if (ansi == "40")
{
if (dn.First().SCH40 != null)
{
sch = dn.First().SCH40;
}
}
if (ansi == "40S")
{
if (dn.First().SCH40S != null)
{
sch = dn.First().SCH40S;
}
}
if (ansi == "STD")
{
if (dn.First().STD != null)
{
sch = dn.First().STD;
}
}
if (ansi == "60")
{
if (dn.First().SCH60 != null)
{
sch = dn.First().SCH60;
}
}
if (ansi == "80")
{
if (dn.First().SCH80 != null)
{
sch = dn.First().SCH80;
}
}
if (ansi == "80S")
{
if (dn.First().SCH80S != null)
{
sch = dn.First().SCH80S;
}
}
if (ansi == "XS")
{
if (dn.First().XS != null)
{
sch = dn.First().XS;
}
}
if (ansi == "100")
{
if (dn.First().SCH100 != null)
{
sch = dn.First().SCH100;
}
}
if (ansi == "120")
{
if (dn.First().SCH120 != null)
{
sch = dn.First().SCH120;
}
}
if (ansi == "140")
{
if (dn.First().SCH140 != null)
{
sch = dn.First().SCH140;
}
}
if (ansi == "160")
{
if (dn.First().SCH160 != null)
{
sch = dn.First().SCH160;
}
}
if (ansi == "XXS")
{
if (dn.First().XXS != null)
{
sch = dn.First().XXS;
}
}
d.Thickness = sch;
if (dia != null && sch != null)
{
d.Specification = "Φ" + Funs.GetClearZero(dia.Value) + "×" + Funs.GetClearZero(sch.Value);
}
}
}
}
else
{
errorInfos += (i + 2) + "行,美标壁厚[" + ds.Tables[0].Rows[i]["美标壁厚"].ToString() + "]错误;";
}
}
//if (ds.Tables[0].Rows[i]["焊接方法"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊接方法"].ToString()))
//{
// var weldMethod = weldingMethods.FirstOrDefault(x => x.WeldingMethodCode == ds.Tables[0].Rows[i]["焊接方法"].ToString());
// if (weldMethod == null)
// {
// errorInfos += "焊接方法[" + ds.Tables[0].Rows[i]["焊接方法"].ToString() + "]不存在;";
// }
// else
// {
// d.WeldingMethodId = weldMethod.WeldingMethodId;
// }
//}
if (ds.Tables[0].Rows[i]["材质1"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["材质1"].ToString()))
{
var steel = materials.FirstOrDefault(x => x.MaterialCode == ds.Tables[0].Rows[i]["材质1"].ToString());
if (steel == null)
{
errorInfos += (i + 2) + "行,材质1[" + ds.Tables[0].Rows[i]["材质1"].ToString() + "]不存在;";
}
else
{
if ((!string.IsNullOrEmpty(d.Material1Id) && steel.MaterialId != d.Material1Id)
&& (!string.IsNullOrEmpty(d.Material2Id) && steel.MaterialId != d.Material2Id))
{
errorInfos += (i + 2) + "行,材质1[" + ds.Tables[0].Rows[i]["材质1"].ToString() + "]验证不一至;";
}
else
{
d.Material1Id = steel.MaterialId;
}
}
}
if (ds.Tables[0].Rows[i]["材质2"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["材质2"].ToString()))
{
var steel = materials.FirstOrDefault(x => x.MaterialCode == ds.Tables[0].Rows[i]["材质2"].ToString());
if (steel == null)
{
errorInfos += (i + 2) + "行,材质2[" + ds.Tables[0].Rows[i]["材质2"].ToString() + "]不存在;";
}
else
{
if ((!string.IsNullOrEmpty(d.Material2Id) && steel.MaterialId != d.Material2Id)
&& (!string.IsNullOrEmpty(d.Material1Id) && steel.MaterialId != d.Material1Id))
{
errorInfos += (i + 2) + "行,材质2[" + ds.Tables[0].Rows[i]["材质2"].ToString() + "]验证不一至;";
}
else
{
d.Material2Id = steel.MaterialId;
}
}
}
if (ds.Tables[0].Rows[i]["组件1"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["组件1"].ToString()))
{
var com = componentss.FirstOrDefault(x => x.ComponentsCode == ds.Tables[0].Rows[i]["组件1"].ToString());
if (com == null)
{
errorInfos += (i + 2) + "行,组件1号[" + ds.Tables[0].Rows[i]["组件1"].ToString() + "]不存在;";
}
else
{
if ((!string.IsNullOrEmpty(d.PipeAssembly1Id) && com.ComponentsId != d.PipeAssembly1Id)
&& (!string.IsNullOrEmpty(d.PipeAssembly2Id) && com.ComponentsId != d.PipeAssembly2Id))
{
errorInfos += (i + 2) + "行,组件1[" + ds.Tables[0].Rows[i]["组件1"].ToString() + "]验证不一至;";
}
else
{
d.PipeAssembly1Id = com.ComponentsId;
}
}
}
if (ds.Tables[0].Rows[i]["组件2"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["组件2"].ToString()))
{
var com = componentss.FirstOrDefault(x => x.ComponentsCode == ds.Tables[0].Rows[i]["组件2"].ToString());
if (com == null)
{
errorInfos += (i + 2) + "行,组件2号[" + ds.Tables[0].Rows[i]["组件2"].ToString() + "]不存在;";
}
else
{
if ((!string.IsNullOrEmpty(d.PipeAssembly1Id) && com.ComponentsId != d.PipeAssembly1Id)
&& (!string.IsNullOrEmpty(d.PipeAssembly2Id) && com.ComponentsId != d.PipeAssembly2Id))
{
errorInfos += (i + 2) + "行,组件2[" + ds.Tables[0].Rows[i]["组件2"].ToString() + "]验证不一至;";
}
else
{
d.PipeAssembly2Id = com.ComponentsId;
}
}
}
if (ds.Tables[0].Rows[i]["炉批号1"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["炉批号1"].ToString()))
{
if ((!string.IsNullOrEmpty(d.HeartNo1) && ds.Tables[0].Rows[i]["炉批号1"].ToString() != d.HeartNo1)
&& (!string.IsNullOrEmpty(d.HeartNo2) && ds.Tables[0].Rows[i]["炉批号1"].ToString() != d.HeartNo2))
{
errorInfos += (i + 2) + "行,炉批号1[" + ds.Tables[0].Rows[i]["炉批号1"].ToString() + "]验证不一至;";
}
else
{
d.HeartNo1 = ds.Tables[0].Rows[i]["炉批号1"].ToString();
}
}
if (ds.Tables[0].Rows[i]["炉批号2"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["炉批号2"].ToString()))
{
if ((!string.IsNullOrEmpty(d.HeartNo1) && ds.Tables[0].Rows[i]["炉批号2"].ToString() != d.HeartNo1)
&& (!string.IsNullOrEmpty(d.HeartNo2) && ds.Tables[0].Rows[i]["炉批号2"].ToString() != d.HeartNo2))
{
errorInfos += (i + 2) + "行,炉批号2[" + ds.Tables[0].Rows[i]["炉批号2"].ToString() + "]验证不一至;";
}
else
{
d.HeartNo2 = ds.Tables[0].Rows[i]["炉批号2"].ToString();
}
}
//if (ds.Tables[0].Rows[i]["焊丝"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊丝"].ToString()))
//{
// var weldSilk = consumabless.FirstOrDefault(x => x.ConsumablesCode == ds.Tables[0].Rows[i]["焊丝"].ToString() && x.ConsumablesType == "1");
// if (weldSilk == null)
// {
// errorInfos += "焊丝[" + ds.Tables[0].Rows[i]["焊丝"].ToString() + "]不存在;";
// }
// else
// {
// d.WeldSilkId = weldSilk.ConsumablesId;
// }
//}
//if (ds.Tables[0].Rows[i]["焊丝"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊丝"].ToString()))
//{
// // 焊丝如多个用“,”隔开
// string[] silkList = ds.Tables[0].Rows[i]["焊丝"].ToString().Trim().Split(',');
// string silkIds = string.Empty;
// if (silkList.Count() > 0)
// {
// foreach (string silk in silkList)
// {
// if (!string.IsNullOrEmpty(silk))
// {
// var weldSilk = consumabless.FirstOrDefault(x => x.ConsumablesCode == silk && x.ConsumablesType == "1");
// if (weldSilk == null)
// {
// errorInfos += "焊丝[" + silk + "]不存在;";
// }
// else
// {
// silkIds = silkIds + weldSilk.ConsumablesId + ",";
// }
// }
// }
// if (silkIds != string.Empty)
// {
// d.WeldSilkId = silkIds.Substring(0, silkIds.Length - 1);
// }
// }
// else
// {
// errorInfos += "焊丝[" + ds.Tables[0].Rows[i]["焊丝"].ToString() + "]不正确,多个焊丝用,隔开;";
// }
//}
//if (ds.Tables[0].Rows[i]["焊条"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["焊条"].ToString()))
//{
// var weldMat = consumabless.FirstOrDefault(x => x.ConsumablesCode == ds.Tables[0].Rows[i]["焊条"].ToString() && x.ConsumablesType == "2");
// if (weldMat == null)
// {
// errorInfos += "焊条[" + ds.Tables[0].Rows[i]["焊条"].ToString() + "]不存在;";
// }
// else
// {
// d.WeldMatId = weldMat.ConsumablesId;
// }
//}
if (ds.Tables[0].Rows[i]["所属管段"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["所属管段"].ToString()))
{
if (!string.IsNullOrEmpty(d.PipeSegment) && d.PipeSegment != ds.Tables[0].Rows[i]["所属管段"].ToString())
{
errorInfos += (i + 2) + "行,所属管段[" + ds.Tables[0].Rows[i]["所属管段"].ToString() + "]验证不一至;";
}
else
{
d.PipeSegment = ds.Tables[0].Rows[i]["所属管段"].ToString();
}
}
if (ds.Tables[0].Rows[i]["WPS编号"] != null && !string.IsNullOrEmpty(ds.Tables[0].Rows[i]["WPS编号"].ToString()))
{
var wps = wpsList.FirstOrDefault(x => x.WPQCode == ds.Tables[0].Rows[i]["WPS编号"].ToString());
if (wps == null)
{
errorInfos += (i + 2) + "行,WPS编号[" + ds.Tables[0].Rows[i]["WPS编号"].ToString() + "]不存在;";
}
else
{
//if (!string.IsNullOrEmpty(d.WPQId) && d.WPQId != wps.WPQId)
//{
// errorInfos += (i + 2) + "行,WPS编号[" + ds.Tables[0].Rows[i]["WPS编号"].ToString() + "]验证不一至;";
//}
//else
//{
d.WPQId = wps.WPQId;
if (!string.IsNullOrEmpty(wps.WeldingMethodId))
{
d.WeldingMethodId = wps.WeldingMethodId;
}
if (!string.IsNullOrEmpty(wps.WeldMatId))
{
d.WeldMatId = wps.WeldMatId;
}
if (!string.IsNullOrEmpty(wps.WeldSilkId))
{
d.WeldSilkId = wps.WeldSilkId.Replace("|", ",");
}
//}
}
}
#endregion
dayList.Add(d);
// WPS焊工判断资质
if (isExistFloor && isExistCell)
{
var wps = BLL.WPQListServiceService.GetWPQById(d.WPQId);
if (!wps.WelderIds.Contains(cellWelderId))
{
errorCheck += (i + 2) + "行,盖面焊工号:[" + ds.Tables[0].Rows[i]["盖面焊工号"].ToString() + "]验证无焊WPS资质";
}
if (!wps.WelderIds.Contains(floorWelderId))
{
errorCheck += (i + 2) + "行,打底焊工号:[" + ds.Tables[0].Rows[i]["打底焊工号"].ToString() + "]验证无焊WPS资质";
}
}
#region
// 判断资质
if (welderQueIsUse == true)
{
if (isExistFloor && isExistCell)
{
bool canSave = false;
var jot = BLL.Pipeline_WeldJointService.GetWeldJointByWeldJointId(jotId);
var joty = BLL.Base_WeldTypeService.GetWeldTypeByWeldTypeId(jot.WeldTypeId);
string weldTypeGroup = joty.Flag;
string weldTypeCode = joty.WeldTypeCode;
string floorWelder = floorWelderId;
string cellWelder = cellWelderId;
//decimal? dia = jot.Dia;
//decimal? sch = jot.Thickness;
string weldingMethodCode = string.Empty;
var wm = BLL.Base_WeldingMethodService.GetWeldingMethodByWeldingMethodId(jot.WeldingMethodId);
if (wm != null)
{
weldingMethodCode = wm.WeldingMethodCode;
}
string[] wmeCodes = weldingMethodCode.Split('+');
string location = string.Empty;
var loc = BLL.Base_WeldingLocationServie.GetWeldingLocationById(jot.WeldingLocationId);
if (loc != null)
{
location = loc.WeldingLocationCode;
}
string ste = jot.Material1Id;
List<Model.Welder_WelderQualify> floorWelderQualifys = (from x in Funs.DB.Welder_WelderQualify
where x.WelderId == floorWelder && x.WeldingMethodId != null
&& x.WeldingLocationId != null && x.MaterialType != null
&& x.WeldType != null
&& x.ThicknessMax != null && x.SizesMin != null
select x).ToList();
List<Model.Welder_WelderQualify> cellWelderQualifys = (from x in Funs.DB.Welder_WelderQualify
where x.WelderId == cellWelder && x.WeldingMethodId != null
&& x.WeldingLocationId != null && x.MaterialType != null
&& x.WeldType != null
&& x.ThicknessMax != null && x.SizesMin != null
select x).ToList();
// 打底和盖面同一焊工
if (floorWelder == cellWelder)
{
if (floorWelderQualifys != null && floorWelderQualifys.Count() > 0)
{
if (wmeCodes.Count() <= 1) // 一种焊接方法
{
canSave = IsOK(floorWelderQualifys, wmeCodes[0], location, weldTypeGroup, ste, dia, sch);
}
else // 大于一种焊接方法,如氩电联焊
{
canSave = TwoWmeIsOK(floorWelderQualifys, cellWelderQualifys, wmeCodes[0], wmeCodes[1], location, weldTypeGroup, ste, dia, sch);
}
}
}
// 打底和盖面焊工不同
else
{
bool isok1 = false;
bool isok2 = false;
if (wmeCodes.Count() <= 1) // 一种焊接方法
{
if (floorWelderQualifys != null && floorWelderQualifys.Count() > 0)
{
isok1 = IsOK(floorWelderQualifys, wmeCodes[0], location, weldTypeGroup, ste, dia, sch);
}
if (cellWelderQualifys != null && cellWelderQualifys.Count() > 0)
{
isok2 = IsOK(cellWelderQualifys, wmeCodes[0], location, weldTypeGroup, ste, dia, sch);
}
if (isok1 && isok2)
{
canSave = true;
}
}
else
{
canSave = TwoWmeIsOK(floorWelderQualifys, cellWelderQualifys, wmeCodes[0], wmeCodes[1], location, weldTypeGroup, ste, dia, sch);
}
}
if (canSave == false)
{
eventArg = eventArg + jot.WeldJointCode + ",";
}
}
}
#endregion
}
// 数据验证错误,返回
if (!string.IsNullOrEmpty(errorInfos))
{
ShowNotify(errorInfos, MessageBoxIcon.Warning, 10000);
return;
}
else if (!string.IsNullOrEmpty(errorCheck))
{
ShowNotify(errorCheck+ "请更正后再提交保存", MessageBoxIcon.Warning, 10000);
return;
}
else
{
// 焊工资质符全条件
if (eventArg == string.Empty)
{
#region 线
// 生成管线的随机数
//var pro = BLL.Base_ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
//var romPipe = pipelineIdList.Distinct();
//if (romPipe.Count() > 0)
//{
// foreach (string pipeId in romPipe)
// {
// var iso = BLL.Pipeline_PipelineService.GetPipelineByPipelineId(pipeId);
// var pipe = Funs.DB.View_Pipeline_Random.FirstOrDefault(x => x.PipelineId == pipeId);
// int rate = Convert.ToInt32(pipe.DetectionRateValue);
// if (rate != 0)
// {
// // RT 随机数
// int rtTotalJotNum = Convert.ToInt32(pipe.RTTotalJointCount);
// // 已焊焊口数
// int rtWeldingJotNum = Convert.ToInt32(pipe.RTWeldingCount);
// // 已点口数
// int rtPointNum = Convert.ToInt32(pipe.RtPointCount);
// int rtMinValue = rtWeldingJotNum + 1;
// int rtMaxValue = rtTotalJotNum;
// int oldRandomNum = 0;
// if (pro.ProjectArea == "2")
// {
// // RT 活动口按管线比例
// int rtPointTotalNum = Convert.ToInt32(Math.Ceiling((double)(rtTotalJotNum * rate) / (double)100));
// int rtnum = rtPointTotalNum - rtPointNum;
// if (rtnum > 0)
// {
// int[] r = Funs.GetRandomNum(rtnum, rtMinValue, rtMaxValue);
// var q = from x in r orderby x select x;
// string random = string.Empty;
// foreach (int i in q)
// {
// if (i <= rtMaxValue)
// {
// random = random + i.ToString() + ",";
// }
// }
// if (random.Length > 0)
// {
// string randomNum = random.Substring(0, random.Length - 1);
// Pipeline_PipelineService.UpdatePipelineRTRandom(pipeId, randomNum);
// }
// }
// }
// else //福建: RT检测先按比例分段点口
// {
// if (iso != null && !string.IsNullOrEmpty(iso.RandomNum))
// {
// oldRandomNum = iso.RandomNum.Split(',').Count();
// }
// int totalJotNum = Convert.ToInt32(pipe.TotalJointCount);
// // 分段num1为向上取整
// int num1 = Convert.ToInt32(Math.Ceiling((double)(totalJotNum * rate) / (double)100));
// // num2为向下取整
// int num2 = Convert.ToInt32(Math.Floor((double)(totalJotNum * rate) / (double)100));
// // 如相等说明随机数已产生,并符合数量,否则重新计算
// if (oldRandomNum != num1)
// {
// int min = 1;
// int max = Convert.ToInt32(Math.Ceiling((double)(100) / (double)(rate)));
// string random = string.Empty;
// for (int i = 1; i <= num2; i++)
// {
// int[] r = Funs.GetRandomNum(1, min, max);
// random = random + r[0] + ",";
// }
// if (num1 > num2)
// {
// int y = totalJotNum - (num2 * max);
// int[] r = Funs.GetRandomNum(1, min, y);
// random = random + r[0] + ",";
// }
// if (random.Length > 0)
// {
// string randomNum = random.Substring(0, random.Length - 1);
// Pipeline_PipelineService.UpdatePipelineRTRandom(pipeId, randomNum);
// }
// }
// #region 暂不用:固定口(大于管线检测比例的40%这里按50%计算) 随机数
// // 先优先点固定口(大于管线检测比例的40%这里按50%计算) 随机数
// //int totalJotNum = Convert.ToInt32(pipe.TotalJointCount);
// //int gdTotalJotNum = Convert.ToInt32(pipe.GDTotalJointCount);
// //int gdWeldingJotNum = Convert.ToInt32(pipe.GDWeldingCount);
// //int gdPointNum = Convert.ToInt32(pipe.GDPointCount);
// //int gdMinValue = gdWeldingJotNum + 1;
// //int gdMaxValue = gdTotalJotNum;
// //int gdPointTotalNum = Convert.ToInt32(Math.Ceiling((double)(totalJotNum * rate * 0.5) / (double)100));
// //int gdnum = gdPointTotalNum - gdPointNum;
// //int gdRandomCount = 0;
// //if (gdnum > 0)
// //{
// // string random = string.Empty;
// // if (gdnum > gdMaxValue) // 说明固定口数量不够,所以所有固定口都点
// // {
// // for (int i = gdMinValue; i <= gdMaxValue; i++)
// // {
// // random = random + i.ToString() + ",";
// // }
// // gdRandomCount = gdMaxValue - gdMinValue + 1;
// // }
// // else
// // {
// // int[] r = Funs.GetRandomNum(gdnum, gdMinValue, gdMaxValue);
// // var q = from x in r orderby x select x;
// // foreach (int i in q)
// // {
// // if (i <= gdMaxValue)
// // {
// // random = random + i.ToString() + ",";
// // }
// // }
// // gdRandomCount = q.Count();
// // }
// // if (random.Length > 0)
// // {
// // string randomNum = random.Substring(0, random.Length - 1);
// // Pipeline_PipelineService.UpdatePipelineGDRandom(pipeId, randomNum);
// // }
// //}
// //// 活动口
// //// RT 活动口按管线比例
// //int pointTotalNum = Convert.ToInt32(Math.Ceiling((double)(totalJotNum * rate) / (double)100));
// //int rtnum = pointTotalNum - rtPointNum - gdPointNum - gdRandomCount;
// //if (rtnum > 0)
// //{
// // string random = string.Empty;
// // if (rtnum > rtMaxValue) // 说明活动口数量不够,所以所有活动口都点
// // {
// // for (int i = rtMinValue; i <= rtMaxValue; i++)
// // {
// // random = random + i.ToString() + ",";
// // }
// // }
// // else
// // {
// // int[] r = Funs.GetRandomNum(rtnum, rtMinValue, rtMaxValue);
// // var q = from x in r orderby x select x;
// // foreach (int i in q)
// // {
// // if (i <= rtMaxValue)
// // {
// // random = random + i.ToString() + ",";
// // }
// // }
// // }
// // if (random.Length > 0)
// // {
// // string randomNum = random.Substring(0, random.Length - 1);
// // Pipeline_PipelineService.UpdatePipelineRTRandom(pipeId, randomNum);
// // }
// //}
// #endregion
// }
// // PT 随机数
// int ptTotalJotNum = Convert.ToInt32(pipe.PTTotalJointCount);
// int ptWeldingJotNum = Convert.ToInt32(pipe.PTWeldingCount);
// int ptPointNum = Convert.ToInt32(pipe.PtPointCount);
// int ptMinValue = ptWeldingJotNum + 1;
// int ptMaxValue = ptTotalJotNum;
// int ptPointTotalNum = Convert.ToInt32(Math.Ceiling((double)(ptTotalJotNum * rate) / (double)100));
// int ptnum = ptPointTotalNum - ptPointNum;
// if (ptnum > 0)
// {
// int[] r = Funs.GetRandomNum(ptnum, ptMinValue, ptMaxValue);
// var q = from x in r orderby x select x;
// string random = string.Empty;
// foreach (int i in q)
// {
// if (i <= ptMaxValue)
// {
// random = random + i.ToString() + ",";
// }
// }
// if (random.Length > 0)
// {
// string randomNum = random.Substring(0, random.Length - 1);
// Pipeline_PipelineService.UpdatePipelinePTRandom(pipeId, randomNum);
// }
// }
// }
// }
//}
#endregion
Model.Pipeline_WeldingDaily newWeldingDaily = new Model.Pipeline_WeldingDaily();
string perfix = string.Format("{0:yyyyMMdd}", System.DateTime.Now) + "-";
string weldingDailyCode = BLL.SQLHelper.RunProcNewId("SpGetThreeNumber", "dbo.Pipeline_WeldingDaily", "WeldingDailyCode", this.CurrUser.LoginProjectId, perfix);
newWeldingDaily.WeldingDailyCode = weldingDailyCode;
newWeldingDaily.ProjectId = this.CurrUser.LoginProjectId;
newWeldingDaily.InstallationId = installationId;
newWeldingDaily.UnitId = unitId;
DateTime? weldDate = Funs.GetNewDateTime(txtWeldDate);
if (weldDate.HasValue)
{
newWeldingDaily.WeldingDate = weldDate.Value;
}
else
{
newWeldingDaily.WeldingDate = DateTime.Now;
}
newWeldingDaily.Tabler = this.CurrUser.UserId;
newWeldingDaily.TableDate = DateTime.Now;
newWeldingDaily.WeldingDailyId = SQLHelper.GetNewID(typeof(Model.Pipeline_WeldingDaily));
BLL.Pipeline_WeldingDailyService.AddPipeline_WeldingDaily(newWeldingDaily);
BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_WeldReportMenuId, Const.BtnAdd, newWeldingDaily.WeldingDailyId);
foreach (var item in dayList)
{
var newWeldJoint = BLL.Pipeline_WeldJointService.GetWeldJointByWeldJointId(item.WeldJointId);
//var pipeline = BLL.Pipeline_PipelineService.GetPipelineByPipelineId(newWeldJoint.PipelineId);
newWeldJoint.WeldingDailyId = newWeldingDaily.WeldingDailyId;
newWeldJoint.WeldingDailyCode = weldingDailyCode;
newWeldJoint.CoverWelderId = item.CoverWelderId;
newWeldJoint.BackingWelderId = item.BackingWelderId;
newWeldJoint.WeldingDate = newWeldingDaily.WeldingDate;
newWeldJoint.WeldTypeId = item.WeldTypeId;
newWeldJoint.JointAttribute = item.JointAttribute;
newWeldJoint.WeldingLocationId = item.WeldingLocationId;
newWeldJoint.Size = item.Size;
newWeldJoint.ANSISCH = item.ANSISCH;
newWeldJoint.Dia = item.Dia;
newWeldJoint.Thickness = item.Thickness;
newWeldJoint.DoneDin = item.Size;
newWeldJoint.Specification = item.Specification;
newWeldJoint.WeldingMethodId = item.WeldingMethodId;
newWeldJoint.Material1Id = item.Material1Id;
newWeldJoint.Material2Id = item.Material2Id;
newWeldJoint.PipeAssembly1Id = item.PipeAssembly1Id;
newWeldJoint.PipeAssembly2Id = item.PipeAssembly2Id;
newWeldJoint.HeartNo1 = item.HeartNo1;
newWeldJoint.HeartNo2 = item.HeartNo2;
newWeldJoint.WeldSilkId = item.WeldSilkId;
newWeldJoint.WeldMatId = item.WeldMatId;
newWeldJoint.PipeSegment = item.PipeSegment;
newWeldJoint.WPQId = item.WPQId;
BLL.Pipeline_WeldJointService.UpdateWeldJoint(newWeldJoint);
//更新焊口号 修改固定焊口号后 +G
//BLL.Pipeline_WeldJointService.UpdateWeldJointAddG(newWeldJoint.WeldJointId, newWeldJoint.JointAttribute, Const.BtnAdd);
BLL.Batch_PointBatchItemService.InsertPointBatch(this.CurrUser.LoginProjectId, unitId, installationId, item.BackingWelderId, item.CoverWelderId, item.WeldJointId, newWeldingDaily.WeldingDate);
}
ShowNotify("日报导入成功!", MessageBoxIcon.Success);
this.BindGrid();
//PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
else
{
Alert.ShowInTop(Resources.Lan.NoQualification + "【" + eventArg + "】" + Resources.Lan.WeldingConditions, Resources.Lan.SubmitResults, MessageBoxIcon.Warning);
}
}
}
else
{
ShowAlert("没有数据!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region
private bool IsOK(List<Model.Welder_WelderQualify> welderQualifys, string wmeCode, string location, string weldTypeGroup, string ste, decimal? dia, decimal? sch)
{
bool isok = false;
foreach (var welderQualify in welderQualifys)
{
int okNum = 0;
if (!string.IsNullOrEmpty(wmeCode)) //焊接方法
{
if (wmeCode.Contains(welderQualify.WeldingMethodId))
{
okNum++;
}
}
else
{
okNum++;
}
if (welderQualify.WeldingLocationId == "ALL") //焊接位置
{
okNum++;
}
else
{
if (!string.IsNullOrEmpty(location))
{
if (welderQualify.WeldingLocationId.Contains(location))
{
okNum++;
}
}
else
{
okNum++;
}
}
if (!string.IsNullOrEmpty(weldTypeGroup))
{
if (welderQualify.WeldType.Contains(weldTypeGroup))
{
okNum++;
}
}
else
{
okNum++;
}
var steel = BLL.Base_MaterialService.GetMaterialByMaterialId(ste);
if (steel != null) //钢材类型
{
if (welderQualify.MaterialType.Contains(steel.MaterialType ?? ""))
{
okNum++;
}
}
else
{
okNum++;
}
if (weldTypeGroup != "2") // 承插焊
{
if (welderQualify.SizesMin == 0) // 0表示不限
{
okNum++;
}
else //最小寸径
{
if (dia != null)
{
if (dia >= welderQualify.SizesMin)
{
okNum++;
}
}
else
{
okNum++;
}
}
if (welderQualify.ThicknessMax == 0) // 0表示不限
{
okNum++;
}
else
{
if (sch != null) //最大壁厚
{
if (sch <= welderQualify.ThicknessMax)
{
okNum++;
}
}
else
{
okNum++;
}
}
}
else // 当为角焊缝时,管径和壁厚不限制
{
okNum++;
okNum++;
}
if (okNum == 6) //全部条件符合
{
isok = true;
break;
}
}
return isok;
}
/// <summary>
/// 两种焊接方法的资质判断
/// </summary>
/// <param name="floorWelderQualifys"></param>
/// <param name="cellWelderQualifys"></param>
/// <param name="wmeCode1"></param>
/// <param name="wmeCode2"></param>
/// <param name="location"></param>
/// <param name="ste"></param>
/// <param name="dia"></param>
/// <param name="sch"></param>
/// <returns></returns>
private bool TwoWmeIsOK(List<Model.Welder_WelderQualify> floorWelderQualifys, List<Model.Welder_WelderQualify> cellWelderQualifys, string wmeCode1, string wmeCode2, string location, string weldTypeGroup, string ste, decimal? dia, decimal? sch)
{
bool isok = false;
decimal? fThicknessMax = 0;
decimal? cThicknessMax = 0;
var steel = BLL.Base_MaterialService.GetMaterialByMaterialId(ste);
var floorQ = from x in floorWelderQualifys
where wmeCode1.Contains(x.WeldingMethodId)
&& (x.WeldingLocationId == "ALL" || (location == null || location == "" || x.WeldingLocationId.Contains(location)))
&& (steel == null || x.MaterialType.Contains(steel.MaterialType ?? ""))
&& (weldTypeGroup == null || x.WeldType.Contains(weldTypeGroup))
// && (dia == null || x.SizesMin<=dia)
select x;
var cellQ = from x in cellWelderQualifys
where wmeCode2.Contains(x.WeldingMethodId)
&& (x.WeldingLocationId == "ALL" || (location == null || location == "" || x.WeldingLocationId.Contains(location)))
&& (steel == null || x.MaterialType.Contains(steel.MaterialType ?? ""))
&& (weldTypeGroup == null || x.WeldType.Contains(weldTypeGroup))
// && (dia == null || x.SizesMin <= dia)
select x;
if (floorQ.Count() > 0 && cellQ.Count() > 0)
{
if (weldTypeGroup != "2") // 当为角焊缝时,管径和壁厚不限制
{
var floorDiaQ = floorQ.Where(x => x.SizesMin <= dia);
var cellDiaQ = cellQ.Where(x => x.SizesMin <= dia);
if (floorDiaQ.Count() > 0 && cellDiaQ.Count() > 0)
{
var fThick = floorDiaQ.Where(x => x.ThicknessMax == 0);
var cThick = cellDiaQ.Where(x => x.ThicknessMax == 0);
// 只要有一个不限为0就通过
if (fThick.Count() > 0 || cThick.Count() > 0)
{
isok = true;
}
else
{
fThicknessMax = floorQ.Max(x => x.ThicknessMax);
cThicknessMax = cellQ.Max(x => x.ThicknessMax);
if ((fThicknessMax + cThicknessMax) >= sch)
{
isok = true;
}
}
}
}
else
{
isok = true;
}
}
return isok;
}
#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="bigType"></param>
/// <returns></returns>
protected string ConvertUnitName(object UnitId)
{
string name = string.Empty;
if (UnitId != null)
{
var unit = BLL.Base_UnitService.GetUnit(UnitId.ToString());
if (unit != null)
{
name = unit.UnitName;
}
}
return name;
}
/// <summary>
/// 获取装置名称
/// </summary>
/// <param name="bigType"></param>
/// <returns></returns>
protected string ConvertInstallationCode(object InstallationId)
{
string name = string.Empty;
if (InstallationId != null)
{
var installation = BLL.Project_InstallationService.GetProject_InstallationByInstallationId(InstallationId.ToString());
if (installation != null)
{
name = installation.InstallationCode;
}
}
return name;
}
/// <summary>
/// 获取填报人
/// </summary>
/// <param name="bigType"></param>
/// <returns></returns>
protected string ConvertTabler(object Tabler)
{
string name = string.Empty;
if (Tabler != null)
{
var user = BLL.Sys_UserService.GetUsersByUserId(Tabler.ToString());
if (user != null)
{
name = user.UserName;
}
}
return name;
}
#endregion
}
}