using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.YLRQ.ConstructionManagement
{
public partial class WeldingManagementBatchEdit : PageBase
{
///
/// 项目主键
///
private string ProjectId
{
get { return (string)ViewState["ProjectId"]; }
set { ViewState["ProjectId"] = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ProjectId = Request.Params["ProjectId"];
LoadData();
}
}
///
/// 首次加载绑定
///
public void LoadData()
{
///材质1
this.ddlTextureMaterial1.DataTextField = "STE_Code";
this.ddlTextureMaterial1.DataValueField = "STE_ID";
this.ddlTextureMaterial1.DataSource = BLL.HJGL_MaterialService.GetSteelList();
this.ddlTextureMaterial1.DataBind();
Funs.FineUIPleaseSelect(this.ddlTextureMaterial1);
///材质2
this.ddlTextureMaterial2.DataTextField = "STE_Code";
this.ddlTextureMaterial2.DataValueField = "STE_ID";
this.ddlTextureMaterial2.DataSource = BLL.HJGL_MaterialService.GetSteelList();
this.ddlTextureMaterial2.DataBind();
Funs.FineUIPleaseSelect(this.ddlTextureMaterial2);
///坡口类型
this.ddlGrooveType.DataTextField = "JST_Name";
this.ddlGrooveType.DataValueField = "JST_ID";
this.ddlGrooveType.DataSource = BLL.HJGL_GrooveService.GetSlopeTypeNameList();
this.ddlGrooveType.DataBind();
Funs.FineUIPleaseSelect(this.ddlGrooveType);
///创建人
this.drpCreate.DataTextField = "UserName";
this.drpCreate.DataValueField = "UserId";
this.drpCreate.DataSource = BLL.Sys_UserService.GetUserList();
this.drpCreate.DataBind();
Funs.FineUIPleaseSelect(this.drpCreate);
this.drpCreate.SelectedValue = this.CurrUser.UserId;
//施工单位
this.ddlUnit.DataTextField = "UnitName";
this.ddlUnit.DataValueField = "UnitId";
this.ddlUnit.DataSource = Funs.DB.View_Common_Project_UnitList.Where(p => p.ProjectId == this.ProjectId && p.UnitType.Contains("4")).ToList();
this.ddlUnit.DataBind();
Funs.FineUIPleaseSelect(this.ddlUnit);
}
///
/// 提交
///
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
if (this.ddlTextureMaterial1.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择材质1!", MessageBoxIcon.Warning);
return;
}
if (this.ddlTextureMaterial2.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择材质2!", MessageBoxIcon.Warning);
return;
}
if (this.ddlGrooveType.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择坡口类型!", MessageBoxIcon.Warning);
return;
}
if (this.ddlUnit.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择施工单位!", MessageBoxIcon.Warning);
return;
}
if (!IsInt(this.txtStart.Text.Trim()))
{
Alert.ShowInTop("开始编号非数字!", MessageBoxIcon.Warning);
return;
}
if (!IsInt(this.txtEnd.Text.Trim()))
{
Alert.ShowInTop("结束编号非数字!", MessageBoxIcon.Warning);
return;
}
int startInt = Funs.GetNewIntOrZero(this.txtStart.Text.Trim());
int endInt = Funs.GetNewIntOrZero(this.txtEnd.Text.Trim());
if (endInt < startInt)
{
Alert.ShowInTop("起编号应小于等于止编号!", MessageBoxIcon.Warning);
return;
}
List woldInfos = new List();
for (int i = startInt; i <= endInt; i++)
{
var sAddStr = this.txtStart.Text.Trim().Replace(startInt.ToString(), "");
var eAddStr = this.txtEnd.Text.Trim().Replace(endInt.ToString(), "");
PV_WeldInformation woldInfo = new PV_WeldInformation();
woldInfo.ProjectId = this.ProjectId;
woldInfo.TextureMaterial1 = ddlTextureMaterial1.SelectedValue;
woldInfo.TextureMaterial2 = ddlTextureMaterial2.SelectedValue;
woldInfo.WeldLength = txtWeldLength.Text;
woldInfo.WeldUnit = int.Parse(ddlWeldUnit.SelectedValue);
woldInfo.GrooveType = ddlGrooveType.SelectedValue;
woldInfo.Thickness = txtThickness.Text;
woldInfo.HeatTreatmentType = ddlHeatTreatmentType.Values.Length > 0 ? string.Join("|", ddlHeatTreatmentType.Values) : null;
woldInfo.CreateId = drpCreate.SelectedValue;
woldInfo.CreateTime = DateTime.Now;
woldInfo.WeldingId = Guid.NewGuid().ToString();
var code = i == endInt ? eAddStr + i.ToString() : sAddStr + i.ToString();
woldInfo.WeldingCode = string.Format("{0}{1}", txtWeldingCode.Text, code);
woldInfo.UnitId = ddlUnit.SelectedValue;
if (ddlWeldUnit.SelectedValue == "1")
{
woldInfo.JointDesc = $"{woldInfo.WeldLength}x{woldInfo.Thickness}";
}
else
{
woldInfo.JointDesc = $"Φ{woldInfo.WeldLength}x{woldInfo.Thickness}";
}
woldInfos.Add(woldInfo);
}
if (Funs.DB.PV_WeldInformation.Count(p => woldInfos.ConvertAll(x => x.WeldingCode).Contains(p.WeldingCode) && p.ProjectId == this.ProjectId) > 0)
{
Alert.ShowInTop("焊缝编号已存在!", MessageBoxIcon.Warning);
return;
}
Funs.DB.PV_WeldInformation.InsertAllOnSubmit(woldInfos);
BLL.Sys_LogService.AddLog(BLL.Const.System_4, this.CurrUser.Account, this.CurrUser.UserId, "批量添加焊缝信息!");
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
ShowNotify("提交成功!", MessageBoxIcon.Success);
}
catch (Exception ex)
{
Alert.ShowInTop(ex.Message, MessageBoxIcon.Warning);
return;
}
}
///
/// 引用
///
protected void btnCopy_Click(object sender, EventArgs e)
{
var woldInfo = Funs.DB.PV_WeldInformation.FirstOrDefault(p => p.WeldingCode == txtWeldingCodeS.Text.Trim());
if (woldInfo != null)
{
ddlTextureMaterial1.SelectedValue = woldInfo.TextureMaterial1;
ddlTextureMaterial2.SelectedValue = woldInfo.TextureMaterial2;
txtWeldLength.Text = woldInfo.WeldLength;
ddlWeldUnit.SelectedValue = woldInfo.WeldUnit != null ? woldInfo.WeldUnit.ToString() : "1";
ddlGrooveType.SelectedValue = woldInfo.GrooveType;
txtThickness.Text = woldInfo.Thickness;
ddlUnit.SelectedValue = woldInfo.UnitId;
if (!string.IsNullOrEmpty(woldInfo.HeatTreatmentType))
{
string[] proessTypes = woldInfo.HeatTreatmentType.Split('|');
this.ddlHeatTreatmentType.Values = proessTypes;
}
}
}
///
/// 材质1
///
protected void ddlTextureMaterial1_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.ddlTextureMaterial1.SelectedValue != BLL.Const._Null)
{
ddlTextureMaterial2.SelectedValue = ddlTextureMaterial1.SelectedValue;
}
}
///
/// 判断是否为数字
///
///
public bool IsInt(string value)
{
var result = true;
try
{
Convert.ToInt32(value);
}
catch (Exception ex)
{
result = false;
}
return result;
}
}
}