using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using BLL;
using Newtonsoft.Json.Linq;
namespace FineUIPro.Web.HJGL.WeldingManage
{
public partial class WeldReportEdit : PageBase
{
#region 定义项
///
/// 焊接日报主键
///
public string DReportID
{
get
{
return (string)ViewState["DReportID"];
}
set
{
ViewState["DReportID"] = value;
}
}
#endregion
#region 加载页面
///
/// 加载页面
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.DReportID = Request.Params["DReportID"];
this.drpProjectId.DataTextField = "ProjectCode";
this.drpProjectId.DataValueField = "ProjectId";
this.drpProjectId.DataSource = BLL.Base_ProjectService.GetProjectListByUserId(this.CurrUser.UserId, "1");
this.drpProjectId.DataBind();
Funs.FineUIPleaseSelect(drpProjectId);
this.drpProjectId.SelectedValue = this.CurrUser.LoginProjectId;
///焊接区域
this.drpCodeName.DataTextField = "Text";
this.drpCodeName.DataValueField = "Text";
this.drpCodeName.DataSource = BLL.DropListService.HJGL_WLO_CODEItem();
this.drpCodeName.DataBind();
///焊接位置
this.drpLocation.DataTextField = "Text";
this.drpLocation.DataValueField = "Value";
this.drpLocation.DataSource = BLL.DropListService.HJGL_JOT_LocationItem();
this.drpLocation.DataBind();
///焊口属性
this.drpJointAttribute.DataTextField = "Text";
this.drpJointAttribute.DataValueField = "Value";
this.drpJointAttribute.DataSource = BLL.DropListService.HJGL_JointAttributeItem();
this.drpJointAttribute.DataBind();
///焊接方法
this.ddlWME_ID.DataTextField = "WME_Name";
this.ddlWME_ID.DataValueField = "WME_Name";
this.ddlWME_ID.DataSource = BLL.HJGL_WeldingMethodService.GetWeldMethodNameList();
this.ddlWME_ID.DataBind();
///焊条
this.ddlWeldMat.DataTextField = "WMT_MatCode";
this.ddlWeldMat.DataValueField = "WMT_MatCode";
this.ddlWeldMat.DataSource = BLL.HJGL_ConsumablesService.GetMaterialList("2");
this.ddlWeldMat.DataBind();
Funs.FineUIPleaseSelect(this.ddlWeldMat);
///焊丝
this.ddlWeldSilk.DataTextField = "WMT_MatCode";
this.ddlWeldSilk.DataValueField = "WMT_MatCode";
this.ddlWeldSilk.DataSource = BLL.HJGL_ConsumablesService.GetMaterialList("1");
this.ddlWeldSilk.DataBind();
Funs.FineUIPleaseSelect(this.ddlWeldSilk);
// this.SetDailyReportNo();
List GetWeldReportItem = BLL.HJGL_WeldReportService.GetWeldReportItem(this.DReportID);
this.BindGrid(GetWeldReportItem); // 初始化页面
this.PageInfoLoad(); // 加载页面
this.CalculationAmount();
}
//else
//{
// string requestArg = GetRequestEventArgument(); // 此函数所在文件:PageBase.cs
// if (requestArg.StartsWith("ReloadGrid$"))
// {
// this.hdItemsString.Text = requestArg.Substring("ReloadGrid$".Length);
// List list = Funs.GetStrListByStr(hdItemsString.Text, '#');
// if (list.Count() == 2)
// {
// string welderLists = list[0];
// List welder = Funs.GetStrListByStr(welderLists, '|');
// string jotLists = list[1];
// List jot = Funs.GetStrListByStr(jotLists, '|');
// if (welder.Count() > 0 && jot.Count() > 0)
// {
// this.SetDailyReportNo(jot[0], welder[0]);
// }
// }
// List GetWeldReportItem = BLL.HJGL_WeldReportService.GetWeldReportAddItem(this.hdItemsString.Text);
// this.BindGrid(GetWeldReportItem);
// }
//}
}
#endregion
#region 超量焊工提示
///
/// 超量焊工提示
///
private void CalculationAmount()
{
this.lbAmount.Hidden = true;
this.lbAmount.Text = string.Empty;
DateTime? date = Funs.GetNewDateTime(this.txtJOT_WeldDate.Text);
string txtValue = string.Empty;
if (date.HasValue)
{
var jots = BLL.HJGL_PW_JointInfoService.GetJointInfoByDReportId(this.DReportID);
foreach (var item in jots)
{
bool cWelder = BLL.HJGL_PW_JointInfoService.GetWelderLimitDN(this.CurrUser.LoginProjectId, item.JOT_CellWelder, date.Value);
bool fWelder = cWelder;
if (item.JOT_FloorWelder != item.JOT_CellWelder)
{
fWelder = BLL.HJGL_PW_JointInfoService.GetWelderLimitDN(this.CurrUser.LoginProjectId, item.JOT_FloorWelder, date.Value);
}
if (cWelder || fWelder)
{
if (cWelder)
{
var cellWelder = BLL.HJGL_PersonManageService.GetWelderByWenId(item.JOT_CellWelder);
if (cellWelder != null)
{
string txt = cellWelder.WED_Code + ";";
if (!txtValue.Contains(txt))
{
txtValue += txt;
}
}
}
if (fWelder)
{
var floorWelder = BLL.HJGL_PersonManageService.GetWelderByWenId(item.JOT_FloorWelder);
if (floorWelder != null)
{
string txt = floorWelder.WED_Code + ";";
if (!txtValue.Contains(txt))
{
txtValue += txt;
}
}
}
}
}
}
if (!string.IsNullOrEmpty(txtValue))
{
this.lbAmount.Text = txtValue;
this.lbAmount.Hidden = false;
}
}
#endregion
#region 加载页面输入提交信息
///
/// 加载页面输入提交信息
///
private void PageInfoLoad()
{
this.drpProjectId.Enabled = false;
var report = BLL.HJGL_WeldReportService.GetWeldReportByDReportID(this.DReportID);
if (report != null)
{
this.txtDailyReportNo.Text = report.JOT_DailyReportNo;
this.txtJOT_WeldDate.Text = string.Format("{0:yyyy-MM-dd}", report.JOT_WeldDate);
this.txtCHT_TableDate.Text = string.Format("{0:yyyy-MM-dd}", report.CHT_TableDate);
this.txtJOT_Remark.Text = report.JOT_Remark;
this.drpProjectId.SelectedValue = report.ProjectId;
}
else
{
this.SimpleForm1.Reset(); ///重置所有字段
this.drpProjectId.SelectedValue = this.CurrUser.LoginProjectId;
this.txtJOT_WeldDate.Text = string.Format("{0:yyyy-MM-dd}", System.DateTime.Now);
this.txtCHT_TableDate.Text = string.Format("{0:yyyy-MM-dd}", System.DateTime.Now);
}
///制单人
this.drpCHT_Tabler.DataTextField = "UserName";
this.drpCHT_Tabler.DataValueField = "UserId";
this.drpCHT_Tabler.DataSource = BLL.Sys_UserService.GetUserListByProjectId(this.drpProjectId.SelectedValue);
this.drpCHT_Tabler.DataBind();
Funs.FineUIPleaseSelect(this.drpCHT_Tabler);
if (this.CurrUser.UserId != Const.GlyId)
{
this.drpCHT_Tabler.SelectedValue = this.CurrUser.UserId;
}
///盖面焊工
this.drpCellWelderCode.Items.Clear();
drpCellWelderCode.DataTextField = "Text";
drpCellWelderCode.DataValueField = "Value";
drpCellWelderCode.DataSource = BLL.HJGL_PersonManageService.GetProjectWelderCodeList(this.drpProjectId.SelectedValue);
drpCellWelderCode.DataBind();
///打底焊工
this.drpFloorWelderCode.Items.Clear();
drpFloorWelderCode.DataTextField = "Text";
drpFloorWelderCode.DataValueField = "Value";
drpFloorWelderCode.DataSource = BLL.HJGL_PersonManageService.GetProjectWelderCodeList(this.drpProjectId.SelectedValue);
drpFloorWelderCode.DataBind();
this.drpUnit.Items.Clear();
var pUnit = BLL.Base_UnitService.GetUnitsByProjectUnitType(this.drpProjectId.SelectedValue, BLL.Const.UnitType_4);
if (pUnit != null)
{
this.drpUnit.DataTextField = "UnitName";
this.drpUnit.DataValueField = "UnitId";
this.drpUnit.DataSource = pUnit;
this.drpUnit.DataBind();
}
if (report != null)
{
if (!string.IsNullOrEmpty(report.CHT_Tabler))
{
var tabler = this.drpCHT_Tabler.Items.FirstOrDefault(x => x.Value == report.CHT_Tabler);
if (tabler != null)
{
this.drpCHT_Tabler.SelectedValue = report.CHT_Tabler;
}
}
this.drpUnit.SelectedValue = report.BSU_ID;
this.drpUnit.Enabled = false;
}
}
#endregion
#region 数据绑定
///
/// 数据绑定
///
private void BindGrid(List GetWeldReportItem)
{
DataTable tb = this.LINQToDataTable(GetWeldReportItem);
// 2.获取当前分页数据
//var table = this.GetPagedDataTable(GridNewDynamic, tb1);
Grid1.RecordCount = tb.Rows.Count;
tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
#endregion
#region 下拉框联动事件 不用了
/////
///// 单位下拉框变化事件
/////
/////
/////
//protected void drpUnit_OnSelectedIndexChanged(object sender, EventArgs e)
//{
// //this.SetDrpByDrpUnitChange();
// this.BindGrid();
//}
//protected void drpProjectId_OnSelectedIndexChanged(object sender, EventArgs e)
//{
// this.drpUnit.Items.Clear();
// var pUnit = BLL.Base_UnitService.GetUnitsByProjectUnitType(this.drpProjectId.SelectedValue, BLL.Const.UnitType_4);
// if (pUnit != null)
// {
// this.drpUnit.DataTextField = "UnitName";
// this.drpUnit.DataValueField = "UnitId";
// this.drpUnit.DataSource = pUnit;
// this.drpUnit.DataBind();
// }
// this.drpCellWelderCode.Items.Clear();
// this.drpFloorWelderCode.Items.Clear();
// ///盖面焊工
// drpCellWelderCode.DataTextField = "Text";
// drpCellWelderCode.DataValueField = "Value";
// drpCellWelderCode.DataSource = BLL.HJGL_PersonManageService.GetProjectWelderCodeList(this.drpProjectId.SelectedValue);
// drpCellWelderCode.DataBind();
// ///打底焊工
// drpFloorWelderCode.DataTextField = "Text";
// drpFloorWelderCode.DataValueField = "Value";
// drpFloorWelderCode.DataSource = BLL.HJGL_PersonManageService.GetProjectWelderCodeList(this.drpProjectId.SelectedValue);
// drpFloorWelderCode.DataBind();
// ///制单人
// this.drpCHT_Tabler.DataTextField = "UserName";
// this.drpCHT_Tabler.DataValueField = "UserId";
// this.drpCHT_Tabler.DataSource = BLL.Sys_UserService.GetUserListByProjectId(this.drpProjectId.SelectedValue);
// this.drpCHT_Tabler.DataBind();
// Funs.FineUIPleaseSelect(this.drpCHT_Tabler);
//}
#endregion
#region 排序
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
List GetWeldReportItem = this.CollectGridJointInfo();
this.BindGrid(GetWeldReportItem);
}
#endregion
#region 焊接日报 提交事件
///
/// 编辑焊接日报
///
///
///
protected void btnSave_Click(object sender, EventArgs e)
{
string eventArg = string.Empty;
List GetWeldReportItem = this.CollectGridJointInfo();
foreach (var item in GetWeldReportItem)
{
bool canSave = false;
var jot = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(item.JOT_ID);
var joty = BLL.HJGL_WeldService.GetJointTypeByID(jot.JOTY_ID);
string weldType = joty.JOTY_Group;
string floorWelder = item.JOT_FloorWelderID;
string cellWelder = item.JOT_CellWelderID;
decimal? dia = item.JOT_Dia;
decimal? sch = Funs.GetNewDecimal(item.JOT_Sch);
string wme = item.WME_ID;
string wmeCode = string.Empty;
var wm = BLL.HJGL_WeldingMethodService.GetWeldMethodByWMEID(item.WME_ID);
if (wm != null)
{
wmeCode = wm.WME_Code;
}
string[] wmeCodes = wmeCode.Split('/');
string location = item.JOT_Location;
string ste = jot.STE_ID;
List floorWelderQualifys = (from x in Funs.DB.HJGL_BS_WelderQualifiedProject
where x.WED_ID == floorWelder && (x.IsSteelStru==false || x.IsSteelStru==null)
&& x.WeldingMethodId != null && x.LimitDate>=DateTime.Now
&& x.WeldingLocationId != null && x.MaterialType != null
&& x.WeldType!=null && x.ThicknessMax != null && x.SizesMin != null
select x).ToList();
List cellWelderQualifys = (from x in Funs.DB.HJGL_BS_WelderQualifiedProject
where x.WED_ID == cellWelder && (x.IsSteelStru == false || x.IsSteelStru == null)
&& x.WeldingMethodId != null && x.LimitDate >= DateTime.Now
&& 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, wmeCode, location, weldType, ste, dia, sch);
}
else // 大于一种焊接方法,如氩电联焊
{
//bool isok1 = IsOK(floorWelderQualifys, wmeCodes[0], location, ste, dia, sch);
//bool isok2 = IsOK(floorWelderQualifys, wmeCodes[1], location, ste, dia, sch);
//if (isok1 && isok2)
//{
// canSave = true;
//}
canSave = TwoWmeIsOK(floorWelderQualifys, cellWelderQualifys, wmeCodes[0], wmeCodes[1], location, weldType, ste, dia, sch);
}
}
}
// 打底和盖面焊工不同
else
{
bool isok1 = false;
bool isok2 = false;
if (wmeCodes.Count() <= 1) // 一种焊接方法
{
if (floorWelderQualifys != null && floorWelderQualifys.Count() > 0)
{
isok1 = IsOK(floorWelderQualifys, wmeCode, location,weldType, ste, dia, sch);
}
if (cellWelderQualifys != null && cellWelderQualifys.Count() > 0)
{
isok2 = IsOK(cellWelderQualifys, wmeCode, location, weldType, ste, dia, sch);
}
if (isok1 && isok2)
{
canSave = true;
}
}
else
{
//// wmeCodes[0]对应GTAW 对应打底焊工
//if (floorWelderQualifys != null && floorWelderQualifys.Count() > 0)
//{
// isok1 = IsOK(floorWelderQualifys, wmeCodes[0], location, ste, dia, sch);
//}
//// wmeCodes[1]对应SMAW 对应盖面焊工
//if (cellWelderQualifys != null && cellWelderQualifys.Count() > 0)
//{
// isok2 = IsOK(cellWelderQualifys, wmeCodes[1], location, ste, dia, sch);
//}
//if (isok1 && isok2)
//{
// canSave = true;
//}
canSave = TwoWmeIsOK(floorWelderQualifys, cellWelderQualifys, wmeCodes[0], wmeCodes[1], location, weldType, ste, dia, sch);
}
}
if (canSave == false)
{
eventArg = eventArg + jot.JOT_JointNo + ",";
}
}
if (eventArg != string.Empty)
{
eventArg = "焊口:" + eventArg.Substring(0, eventArg.Length - 1) + "中的焊工资质不符合!";
PageContext.RegisterStartupScript(Confirm.GetShowReference(eventArg + "点击确定按钮继续提交日报,点取消按钮取消!",
String.Empty,
MessageBoxIcon.Question,
PageManager1.GetCustomEventReference(false, "Confirm_OK"), // 第一个参数 false 用来指定当前不是AJAX请求
PageManager1.GetCustomEventReference("Confirm_Cancel")));
}
else
{
ComfirmSubmit(true);
}
}
private bool IsOK(List welderQualifys, string wmeCode,string location, string weldType,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(weldType))
{
if (welderQualify.WeldType.Contains(weldType))
{
okNum++;
}
}
else
{
okNum++;
}
var steel = BLL.HJGL_MaterialService.GetSteelBySteID(ste);
if (steel != null) //钢材类型
{
if (welderQualify.MaterialType.Contains(steel.STE_SteelType ?? ""))
{
okNum++;
}
}
else
{
okNum++;
}
if (weldType != "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 // 2表示角焊缝,当为角焊缝时,管径和壁厚不限制
{
okNum++;
okNum++;
}
if (okNum == 6) //全部条件符合
{
isok = true;
break;
}
}
return isok;
}
///
/// 两种焊接方法的资质判断
///
///
///
///
///
///
///
///
///
///
private bool TwoWmeIsOK(List floorWelderQualifys, List cellWelderQualifys, string wmeCode1, string wmeCode2, string location, string weldType, string ste, decimal? dia, decimal? sch)
{
bool isok = false;
decimal? fThicknessMax = 0;
decimal? cThicknessMax = 0;
var steel = BLL.HJGL_MaterialService.GetSteelBySteID(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.STE_SteelType ?? ""))
&& x.WeldType.Contains(weldType)
// && (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.STE_SteelType ?? ""))
&& x.WeldType.Contains(weldType)
// && (dia == null || x.SizesMin <= dia)
select x;
if (floorQ.Count() > 0 && cellQ.Count() > 0)
{
if (weldType != "2") // 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;
}
protected void PageManager1_CustomEvent(object sender, CustomEventArgs e)
{
if (e.EventArgument == "Confirm_OK")
{
ComfirmSubmit(true);
}
else if (e.EventArgument == "Confirm_Cancel")
{
// AJAX回发
ShowNotify("提交日报取消!");
}
}
private void ComfirmSubmit(bool isSave)
{
if (isSave == true)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_WeldReportMenuId, Const.BtnSave))
{
if (BLL.HJGL_WeldReportService.IsExistDailyReportNO(this.txtDailyReportNo.Text, this.DReportID, this.CurrUser.LoginProjectId))
{
ShowNotify("日报编号已存在,请重新录入!", MessageBoxIcon.Warning);
return;
}
if (string.IsNullOrEmpty(this.txtJOT_WeldDate.Text) || string.IsNullOrEmpty(this.txtDailyReportNo.Text.Trim()))
{
ShowNotify("日报告号、焊接日期不能为空!", MessageBoxIcon.Warning);
return;
}
bool isThisProject = true;
for (int i = 0; i < Grid1.Rows.Count; i++)
{
string jotId = Grid1.DataKeys[i][0].ToString();
var jot = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(jotId);
var iso = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(jot.ISO_ID);
if (jot.ProjectId != this.drpProjectId.SelectedValue || iso.BSU_ID != this.drpUnit.SelectedValue)
{
isThisProject = false;
break;
}
}
if (isThisProject == false)
{
ShowNotify("日报明细中焊口不在所选项目或单位中,不能提交!", MessageBoxIcon.Warning);
return;
}
Model.HJGL_BO_WeldReportMain newWeldReportMain = new Model.HJGL_BO_WeldReportMain();
newWeldReportMain.ProjectId = this.drpProjectId.SelectedValue;
newWeldReportMain.JOT_DailyReportNo = this.txtDailyReportNo.Text.Trim();
if (this.drpUnit.SelectedValue != BLL.Const._Null)
{
newWeldReportMain.BSU_ID = this.drpUnit.SelectedValue;
}
DateTime? weldDate = Funs.GetNewDateTime(this.txtJOT_WeldDate.Text);
if (weldDate.HasValue)
{
newWeldReportMain.JOT_WeldDate = weldDate.Value;
}
else
{
newWeldReportMain.JOT_WeldDate = System.DateTime.Now;
}
if (this.drpCHT_Tabler.SelectedValue != BLL.Const._Null)
{
newWeldReportMain.CHT_Tabler = this.drpCHT_Tabler.SelectedValue;
}
newWeldReportMain.CHT_TableDate = Funs.GetNewDateTime(this.txtCHT_TableDate.Text);
newWeldReportMain.JOT_Remark = this.txtJOT_Remark.Text.Trim();
if (!string.IsNullOrEmpty(this.DReportID))
{
newWeldReportMain.DReportID = this.DReportID;
BLL.HJGL_WeldReportService.UpdateWeldReport(newWeldReportMain);
BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "修改焊接日报信息");
}
else
{
this.DReportID = SQLHelper.GetNewID(typeof(Model.HJGL_BO_WeldReportMain));
newWeldReportMain.DReportID = this.DReportID;
BLL.HJGL_WeldReportService.AddWeldReport(newWeldReportMain);
BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "添加焊接日报信息");
}
List GetWeldReportItem = this.CollectGridJointInfo();
var jots = BLL.HJGL_PW_JointInfoService.GetJointInfoByDReportId(this.DReportID);
if (jots.Count() > 0)
{
foreach (var item in jots)
{
// 判断页面信息是否能修改 是否已点口
var removeJointInfo = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(item.JOT_ID);
if (removeJointInfo != null)
{
removeJointInfo.DReportID = null;
removeJointInfo.JOT_CellWelder = null;
removeJointInfo.JOT_FloorWelder = null;
BLL.HJGL_PW_JointInfoService.UpdateJointInfoByDReport(removeJointInfo);
}
// 删除批明细
BLL.HJGL_BO_BatchDetailService.DeleteBatchDetail(item.JOT_ID);
}
}
string errlog = string.Empty;
// 获取组批条件
var batchC = BLL.Project_SysSetService.GetSysSetBySetId("5", this.drpProjectId.SelectedValue);
if (batchC != null)
{
string batchCondition = batchC.SetValue;
string[] condition = batchCondition.Split('|');
foreach (var item in GetWeldReportItem)
{
var newJointInfo = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(item.JOT_ID);
var isoInfo = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(newJointInfo.ISO_ID);
if (newJointInfo != null && string.IsNullOrEmpty(newJointInfo.DReportID))
{
if (!string.IsNullOrEmpty(item.JOT_CellWelderID) && !string.IsNullOrEmpty(item.JOT_FloorWelderID)
&& newJointInfo.ProjectId == this.drpProjectId.SelectedValue)
{
newJointInfo.DReportID = this.DReportID;
newJointInfo.JOT_JointStatus = "100";
newJointInfo.JOT_CellWelder = item.JOT_CellWelderID;
newJointInfo.JOT_FloorWelder = item.JOT_FloorWelderID;
newJointInfo.WLO_Code = item.WLO_CodeID;
newJointInfo.JOT_Size = item.JOT_Size;
newJointInfo.JOT_DoneDin = item.JOT_DoneDin;
newJointInfo.JOT_JointAttribute = item.JOT_JointAttribute;
newJointInfo.JOT_Location = item.JOT_Location;
newJointInfo.JOT_Sch = item.JOT_Sch;
newJointInfo.WME_ID = item.WME_ID;
newJointInfo.JOT_WeldMat = item.JOT_WeldMat;
newJointInfo.JOT_WeldSilk = item.JOT_WeldSilk;
if (item.JOT_Dia.HasValue)
{
newJointInfo.JOT_Dia = item.JOT_Dia;
// 暂时不要这个逻辑 去除时间2021.05.12
//decimal dia = Funs.GetNewDecimalOrZero(newJointInfo.JOT_Dia.ToString());
//var inch = HJGL_ControlService.GetSizeByDia(dia);//焊口寸经根据外径改变
//if (inch != null)
//{
// newJointInfo.JOT_Size = inch;
// newJointInfo.JOT_DoneDin = inch;
//}
}
//焊口规格:Φ外径*壁厚
if (newJointInfo.JOT_Dia.HasValue && !string.IsNullOrEmpty(newJointInfo.JOT_Sch))
{
newJointInfo.JOT_JointDesc = "Φ" + item.JOT_Dia + "×" + item.JOT_Sch;
}
if (newJointInfo.WeldL.HasValue)
{
newJointInfo.JOT_JointDesc = "L=" + newJointInfo.WeldL.Value.ToString();
}
BLL.HJGL_PW_JointInfoService.UpdateJointInfoByDReport(newJointInfo);
//更新焊口号 修改固定焊口号后 +G
BLL.HJGL_PW_JointInfoService.UpdateJointNoAddG(newJointInfo.JOT_ID, newJointInfo.JOT_JointAttribute, Const.Add);
}
else
{
errlog += "焊口【" + newJointInfo.JOT_JointNo + "】未选择焊工。";
}
}
bool isPass = true;
foreach (string c in condition)
{
if (c == "1")
{
if (string.IsNullOrEmpty(newJointInfo.InstallationId))
{
isPass = false;
break;
}
}
if (c == "2")
{
if (string.IsNullOrEmpty(newJointInfo.NDTR_ID))
{
isPass = false;
break;
}
}
if (c == "3")
{
if (string.IsNullOrEmpty(newJointInfo.JOTY_ID))
{
isPass = false;
break;
}
}
if (c == "4")
{
if (string.IsNullOrEmpty(isoInfo.ISC_ID))
{
isPass = false;
break;
}
}
if (c == "5")
{
if (string.IsNullOrEmpty(isoInfo.STE_ID))
{
isPass = false;
break;
}
}
if (c == "6")
{
if (string.IsNullOrEmpty(isoInfo.ISO_Executive))
{
isPass = false;
break;
}
}
//if (c == "7") //是否特殊不会为空
//{
//}
//if (c == "8") // 焊工不会为空
//{
// if (string.IsNullOrEmpty(item.JOT_CellWelderID)|| string.IsNullOrEmpty(item.JOT_FloorWelderID))
// {
// isPass = false;
// break;
// }
//}
if (c == "9")
{
if (string.IsNullOrEmpty(newJointInfo.ISO_ID))
{
isPass = false;
break;
}
}
if (c == "10")
{
if (string.IsNullOrEmpty(isoInfo.SER_ID))
{
isPass = false;
break;
}
}
if (c == "11")
{
if (string.IsNullOrEmpty(newJointInfo.PressureTestPackageNo))
{
isPass = false;
break;
}
}
}
if (isPass)
{
string strSql = @"SELECT BatchId FROM dbo.HJGL_BO_Batch
WHERE (BatchIsClosed=0 OR BatchIsClosed IS NULL)
AND ProjectId = @ProjectId";
List listStr = new List();
listStr.Add(new SqlParameter("@ProjectId", this.drpProjectId.SelectedValue));
if (condition.Contains("1"))
{
strSql += " AND InstallationId =@InstallationId";
listStr.Add(new SqlParameter("@InstallationId", newJointInfo.InstallationId));
}
if (condition.Contains("2"))
{
strSql += " AND NDTR_ID =@NDTR_ID";
listStr.Add(new SqlParameter("@NDTR_ID", newJointInfo.NDTR_ID));
}
if (condition.Contains("3"))
{
strSql += " AND JOTY_ID =@JOTY_ID";
listStr.Add(new SqlParameter("@JOTY_ID", newJointInfo.JOTY_ID));
}
if (condition.Contains("4"))
{
strSql += " AND ISC_ID =@ISC_ID";
listStr.Add(new SqlParameter("@ISC_ID", isoInfo.ISC_ID));
}
if (condition.Contains("5"))
{
strSql += " AND STE_ID =@STE_ID";
listStr.Add(new SqlParameter("@STE_ID", isoInfo.STE_ID));
}
if (condition.Contains("6"))
{
strSql += " AND ExecStandardId =@ExecStandardId";
listStr.Add(new SqlParameter("@ExecStandardId", isoInfo.ISO_Executive));
}
if (condition.Contains("7"))
{
strSql += " AND IsSpecial =@IsSpecial";
listStr.Add(new SqlParameter("@IsSpecial", newJointInfo.IsSpecial));
}
if (condition.Contains("8"))
{
strSql += " AND WED_ID =@WED_ID";
listStr.Add(new SqlParameter("@WED_ID", item.JOT_CellWelderID));
}
if (condition.Contains("9"))
{
strSql += " AND ISO_ID =@ISO_ID";
listStr.Add(new SqlParameter("@ISO_ID", newJointInfo.ISO_ID));
}
if (condition.Contains("10"))
{
strSql += " AND SER_ID =@SER_ID";
listStr.Add(new SqlParameter("@SER_ID", isoInfo.SER_ID));
}
if (condition.Contains("11"))
{
strSql += " AND TestPackage =@TestPackage";
listStr.Add(new SqlParameter("@TestPackage", newJointInfo.PressureTestPackageNo));
}
SqlParameter[] parameter = listStr.ToArray();
DataTable batchInfo = SQLHelper.GetDataTableRunText(strSql, parameter);
//var batchInfo = from x in Funs.DB.HJGL_BO_Batch
// where x.ProjectId == this.drpProjectId.SelectedValue
// && x.InstallationId == newJointInfo.InstallationId && x.ISC_ID == isoInfo.ISC_ID
// && x.STE_ID == isoInfo.STE_ID
// && x.ExecStandardId == isoInfo.ISO_Executive && x.JOTY_ID == newJointInfo.JOTY_ID
// && x.NDTR_ID == newJointInfo.NDTR_ID && x.IsSpecial == newJointInfo.IsSpecial
// && (x.BatchIsClosed == null || x.BatchIsClosed == false)
// select x;
string batchId = string.Empty;
if (batchInfo.Rows.Count == 0)
{
Model.HJGL_BO_Batch batch = new Model.HJGL_BO_Batch();
batch.BatchId = SQLHelper.GetNewID(typeof(Model.HJGL_BO_Batch));
batchId = batch.BatchId;
//string perfix = ins.InstallationCode + "-" + isoC.ISC_IsoCode + "-" + ser.SER_Abbreviate + "-" + execS.ExecStandardName + "-";
batch.BatchCode = BLL.SQLHelper.RunProcFlowCode("SpGetFlowCode", "dbo.HJGL_BO_Batch", "BatchCode", this.drpProjectId.SelectedValue);
batch.ProjectId = this.drpProjectId.SelectedValue;
batch.InstallationId = newJointInfo.InstallationId;
batch.BatchCondition = batchC.SetValue;
batch.NDTR_ID = newJointInfo.NDTR_ID;
batch.JOTY_ID = newJointInfo.JOTY_ID;
batch.ISC_ID = isoInfo.ISC_ID;
batch.STE_ID = isoInfo.STE_ID;
batch.ExecStandardId = isoInfo.ISO_Executive;
batch.IsSpecial = newJointInfo.IsSpecial;
batch.WED_ID = item.JOT_CellWelderID;
batch.ISO_ID = newJointInfo.ISO_ID;
batch.SER_ID = isoInfo.SER_ID;
batch.TestPackage = newJointInfo.PressureTestPackageNo;
batch.BatchStartDate = DateTime.Now.Date;
BLL.HJGL_BO_BatchService.AddBatch(batch);
}
else
{
batchId = batchInfo.Rows[0][0].ToString();
}
var b = BLL.HJGL_BO_BatchDetailService.GetBatchDetailByJotId(item.JOT_ID);
if (b == null)
{
try
{
Model.HJGL_BO_BatchDetail batchDetail = new Model.HJGL_BO_BatchDetail();
batchDetail.BatchDetailId = SQLHelper.GetNewID(typeof(Model.HJGL_BO_BatchDetail));
batchDetail.BatchId = batchId;
batchDetail.ISO_ID = newJointInfo.ISO_ID;
batchDetail.JOT_ID = item.JOT_ID;
BLL.Funs.DB.HJGL_BO_BatchDetail.InsertOnSubmit(batchDetail);
BLL.Funs.DB.SubmitChanges();
}
catch
{
}
}
}
else
{
errlog += "焊口【" + newJointInfo.JOT_JointNo + "】组批条件不能为空。";
}
}
}
else
{
errlog += "请设置项目的组批条件";
}
#region 焊工焊接量限制,暂不用
//foreach (var item in GetWeldReportItem)
//{
// if (!string.IsNullOrEmpty(item.JOT_CellWelderID) && !string.IsNullOrEmpty(item.JOT_FloorWelderID))
// {
// bool cWelder = BLL.HJGL_PW_JointInfoService.GetWelderLimitDN(this.drpProjectId.SelectedValue, item.JOT_CellWelderID, newWeldReportMain.JOT_WeldDate);
// bool fWelder = cWelder;
// if (item.JOT_CellWelderID != item.JOT_FloorWelderID)
// {
// fWelder = BLL.HJGL_PW_JointInfoService.GetWelderLimitDN(this.drpProjectId.SelectedValue, item.JOT_FloorWelderID, newWeldReportMain.JOT_WeldDate);
// }
// if (cWelder || fWelder)
// {
// if (cWelder)
// {
// var cellWelder = BLL.HJGL_PersonManageService.GetWelderByWenId(item.JOT_CellWelderID);
// if (cellWelder != null)
// {
// string txt = "焊工" + cellWelder.WED_Code + "今日焊接寸径将超过60寸。";
// if (!errlog.Contains(txt))
// {
// errlog += txt;
// }
// }
// }
// if (fWelder)
// {
// var floorWelder = BLL.HJGL_PersonManageService.GetWelderByWenId(item.JOT_FloorWelderID);
// if (floorWelder != null)
// {
// string txt = "焊工" + floorWelder.WED_Code + "今日焊接寸径将超过60寸。";
// if (!errlog.Contains(txt))
// {
// errlog += txt;
// }
// }
// }
// }
// }
//}
#endregion
if (string.IsNullOrEmpty(errlog))
{
ShowNotify("提交成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(newWeldReportMain.DReportID)
+ ActiveWindow.GetHidePostBackReference());
}
else
{
// string okj = ActiveWindow.GetWriteBackValueReference(newWeldReportMain.DReportID) + ActiveWindow.GetHidePostBackReference();
Alert.ShowInTop("提交完成,焊接明细中" + errlog, "提交结果", MessageBoxIcon.Warning);
// ShowAlert("焊接明细中" + errlog, MessageBoxIcon.Warning);
}
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
else
{
ShowNotify("提交日报取消!", MessageBoxIcon.Success);
}
}
#endregion
#region 收集Grid页面信息
///
/// 收集Grid页面信息
///
///
private List CollectGridJointInfo()
{
List GetWeldReportItem = null;
List getNewWeldReportItem = new List();
if (!string.IsNullOrEmpty(this.hdItemsString.Text))
{
GetWeldReportItem = BLL.HJGL_WeldReportService.GetWeldReportAddItem(this.hdItemsString.Text);
}
else if (string.IsNullOrEmpty(this.hdItemsString.Text) && this.DReportID != null)
{
GetWeldReportItem = BLL.HJGL_WeldReportService.GetWeldReportItem(this.DReportID);
}
JArray mergedData = Grid1.GetMergedData();
foreach (JObject mergedRow in mergedData)
{
string status = mergedRow.Value("status");
JObject values = mergedRow.Value("values");
string rowID = values.Value("JOT_ID").ToString();
var item = GetWeldReportItem.FirstOrDefault(x => x.JOT_ID == rowID);
if (item != null)
{
var cellWelderCode = (from x in Funs.DB.HJGL_BS_Welder
join y in Funs.DB.Project_Welder
on x.WED_ID equals y.WED_ID
where y.ProjectId == drpProjectId.SelectedValue && x.WED_Code == values.Value("JOT_CellWelderID")
select x).FirstOrDefault();
if (cellWelderCode != null)
{
item.JOT_CellWelderCode = cellWelderCode.WED_Code;
item.JOT_CellWelderID = cellWelderCode.WED_ID;
}
var floorWelderCode = (from x in Funs.DB.HJGL_BS_Welder
join y in Funs.DB.Project_Welder
on x.WED_ID equals y.WED_ID
where y.ProjectId == drpProjectId.SelectedValue && x.WED_Code == values.Value("JOT_FloorWelderID")
select x).FirstOrDefault();
if (floorWelderCode != null)
{
item.JOT_FloorWelderCode = floorWelderCode.WED_Code;
item.JOT_FloorWelderID = floorWelderCode.WED_ID;
}
if (values.Value("WLO_CodeName").ToString() == "现场安装")
{
item.WLO_CodeName = "现场安装";
item.WLO_CodeID = "F";
}
else
{
item.WLO_CodeName = "预制";
item.WLO_CodeID = "S";
}
string s = values.Value("WME_ID");
var weldingMethod = (from x in Funs.DB.HJGL_BS_WeldMethod where x.WME_Name == values.Value("WME_ID") select x).FirstOrDefault();
if (weldingMethod != null)
{
item.WME_Name = weldingMethod.WME_Name;
item.WME_ID = weldingMethod.WME_ID;
}
var weldMat = (from x in Funs.DB.HJGL_BS_WeldMaterial where x.WMT_MatCode == values.Value("JOT_WeldMat") select x).FirstOrDefault();
if (weldMat != null)
{
item.JOT_WeldMat = weldMat.WMT_ID;
item.WeldMatCode = weldMat.WMT_MatCode;
}
else
{
item.JOT_WeldMat = null;
item.WeldMatCode = null;
}
var weldSilk = (from x in Funs.DB.HJGL_BS_WeldMaterial where x.WMT_MatCode == values.Value("JOT_WeldSilk") select x).FirstOrDefault();
if (weldSilk != null)
{
item.JOT_WeldSilk = weldSilk.WMT_ID;
item.WeldSilkCode = weldSilk.WMT_MatCode;
}
else
{
item.JOT_WeldSilk = null;
item.WeldSilkCode = null;
}
item.JOT_JointAttribute = values.Value("JOT_JointAttribute").ToString();
item.JOT_Location = values.Value("JOT_Location").ToString();
item.JOT_Size = Funs.GetNewDecimalOrZero(values.Value("JOT_Size").ToString());
item.JOT_DoneDin = Funs.GetNewDecimalOrZero(values.Value("JOT_DoneDin").ToString());
item.JOT_Dia = Funs.GetNewDecimal(values.Value("JOT_Dia"));
item.JOT_Sch = values.Value("JOT_Sch").ToString();
getNewWeldReportItem.Add(item);
}
}
return getNewWeldReportItem;
}
#endregion
#region Grid 关闭弹出窗口事件
///
/// 关闭弹出窗口
///
///
///
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
List list = Funs.GetStrListByStr(hdItemsString.Text, '#');
if (list.Count() > 0)
{
List GetWeldReportItem = BLL.HJGL_WeldReportService.GetWeldReportAddItem(this.hdItemsString.Text);
this.BindGrid(GetWeldReportItem);
this.SetDailyReportNo();
}
//if (list.Count() == 2)
//{
// string welderLists = list[0];
// List welder = Funs.GetStrListByStr(welderLists, '|');
// string jotLists = list[1];
// List jot = Funs.GetStrListByStr(jotLists, '|');
// if (welder.Count() > 0 && jot.Count() > 0)
// {
// this.SetDailyReportNo(jot[0], welder[0]);
// }
//}
//SetDrpByDrpUnitChange();
//this.hdItemsString.Text = string.Empty;
}
#endregion
#region 设置日报号
///
/// 设置日报号
///
private void SetDailyReportNo()
{
string projecName = BLL.Base_ProjectService.GetProjectCode(this.drpProjectId.SelectedValue);
string perfix = string.Empty;
string date = DateTime.Now.ToString("yyyyMM");
if (string.IsNullOrEmpty(this.txtDailyReportNo.Text))
{
perfix = projecName + "-" + date + "-";
this.txtDailyReportNo.Text = BLL.SQLHelper.RunProcNewIdByProjectId("SpGetNewCodeByProjectId", "dbo.HJGL_BO_WeldReportMain", "JOT_DailyReportNo", this.drpProjectId.SelectedValue, perfix);
}
//}
}
#endregion
#region 右键删除事件
///
/// 右键删除事件
///
///
///
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
List GetWeldReportItem = this.CollectGridJointInfo();
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
var batchDetail = BLL.HJGL_BO_BatchDetailService.GetBatchDetailByJotId(rowID);
if (batchDetail != null)
{
var batch = BLL.HJGL_BO_BatchService.GetBatchById(batchDetail.BatchId);
if (batch != null && (batch.BatchIsClosed == false || batch.BatchIsClosed == null))
{
BLL.HJGL_BO_BatchDetailService.DeleteBatchDetail(rowID);
}
}
var item = GetWeldReportItem.FirstOrDefault(x => x.JOT_ID == rowID);
if (item != null)
{
GetWeldReportItem.Remove(item);
}
}
BindGrid(GetWeldReportItem);
ShowNotify("操作完成!", MessageBoxIcon.Success);
}
}
#endregion
#region 查找
///
/// 查找未焊接焊口
///
///
///
protected void ckSelect_Click(object sender, EventArgs e)
{
string jotIds = string.Empty;
string jointList = string.Empty;
List GetWeldReportItem = this.CollectGridJointInfo();
if (GetWeldReportItem != null)
{
foreach (var item in GetWeldReportItem)
{
jotIds = jotIds + item.JOT_ID + "|";
jointList = jointList + item.JOT_ID + "|" + item.JOT_FloorWelderID + "|" + item.JOT_CellWelderID + ",";
}
}
if (jotIds != string.Empty)
{
jotIds = jotIds.Substring(0, jotIds.Length - 1);
jointList = jointList.Substring(0, jointList.Length - 1);
}
if (!string.IsNullOrEmpty(this.drpUnit.SelectedValue) && this.drpUnit.SelectedValue != BLL.Const._Null)
{
string strList = this.drpProjectId.SelectedValue + "|" + this.drpUnit.SelectedValue + "|" + this.DReportID;
string window = String.Format("WeldReportItemEdit.aspx?strList={0}&jotIds={1}&jointList={2}", strList, jotIds, jointList, "编辑 - ");
PageContext.RegisterStartupScript(Window1.GetSaveStateReference(hdItemsString.ClientID) + Window1.GetShowReference(window));
}
else
{
Alert.ShowInTop("请选择单位!", MessageBoxIcon.Warning);
}
}
#endregion
#region 格式化字符串
///
/// 得到是否热处理
///
///
///
protected string ConvertISProess(object JOT_ID)
{
string iSProess = string.Empty;
if (JOT_ID != null)
{
Model.HJGL_PW_JointInfo joint = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(JOT_ID.ToString());
if (joint != null)
{
if (joint.IS_Proess == "1")
{
iSProess = "是";
}
else if (joint.IS_Proess == "0")
{
iSProess = "否";
}
}
}
return iSProess;
}
#endregion
protected string getDiaSize()
{
string diaSize = "";
var ds = from x in Funs.DB.HJGL_BS_SchTab select x;
foreach (var q in ds)
{
diaSize += q.BST_Dia + "|" + q.BST_Inch + ",";
}
return diaSize.Substring(0, diaSize.Length - 1);
}
}
}