SGGL_HBAZ/SGGL/FineUIPro.Web/HJGL/TrustManage/PMITrustManageEditAdd.aspx.cs

513 lines
24 KiB
C#

using BLL;
using FineUIPro.Web.HJGL.WeldingManage;
using Model;
using Newtonsoft.Json.Linq;
using NPOI.HPSF;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web.UI.HtmlControls;
namespace FineUIPro.Web.HJGL.TrustManage
{
public partial class PMITrustManageEditAdd : PageBase
{
#region
/// <summary>
/// 无损委托主键
/// </summary>
public string PMITrustID
{
get
{
return (string)ViewState["PMITrustID"];
}
set
{
ViewState["PMITrustID"] = value;
}
}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.PMITrustID = Request.Params["PMITrustID"];
//drpInstallationDropDownList(this.drpInstallation,true);
//drpCH_TrustUnitDropDownList(this.drpCH_TrustUnit, true);
BLL.Project_InstallationService.InitInstallationDropDownList(this.drpInstallation, this.CurrUser.LoginProjectId, true);
Funs.FineUIPleaseSelect(this.drpWorkAreaId);
BLL.Base_DetectionTypeService.InitDetectionTypeDropDownList(this.ddlTestMethod, true);//检测方法
BLL.Base_DetectionRateService.InitDetectionRateDropDownList(this.ddlTesTratio, true);//检测比例
List<Model.PMI_TrustMangeItem> GetTrustItem = BLL.PMITrustManageItemService.GetView_PMI_TrustItemByCH_TrustID(this.PMITrustID);
this.BindGrid(GetTrustItem); // 初始化页面
this.PageInfoLoad(); // 加载页面
}
}
#endregion
#region
/// <summary>
/// 加载页面输入提交信息
/// </summary>
private void PageInfoLoad()
{
Model.PMI_TrustManage newPMI_TrustManage = BLL.PMITrustManageService.GetCH_TrustByID(this.PMITrustID);
if (newPMI_TrustManage != null)
{
if (!string.IsNullOrEmpty(newPMI_TrustManage.UnitCode))
{
this.drpInstallation.SelectedValue = newPMI_TrustManage.UnitCode;
//InitAreaIdDropDownList(drpInstallation, newPMI_TrustManage.UnitCode, false);
BLL.WorkAreaService.InitWorkAreaByProjectIdAndInstallationId(this.drpWorkAreaId, this.CurrUser.LoginProjectId, this.drpInstallation.SelectedValue, true);
if (!string.IsNullOrEmpty(newPMI_TrustManage.AreaIdCode))
{
this.drpWorkAreaId.SelectedValue = newPMI_TrustManage.AreaIdCode;
}
}
//工区--AreaId
//if (!string.IsNullOrEmpty(newPMI_TrustManage.AreaIdCode))
//{
// this.drpCH_TrustUnit.SelectedValue = newPMI_TrustManage.AreaIdCode;
//}
////工程名称--PMIProjectName
//this.txtPMIProjectName.Text = newPMI_TrustManage.PMIProjectName;
////单位工程名称--PMIUnitWorksName
//this.txtPMIUnitWorksName.Text = newPMI_TrustManage.PMIUnitWorksName;
//编号--SerialNum
this.txtSerialNum.Text = newPMI_TrustManage.SerialNum;
//检测方法--TestMethod
if (!string.IsNullOrEmpty(newPMI_TrustManage.TestMethod))
{
this.ddlTestMethod.SelectedItem.Text = newPMI_TrustManage.TestMethod;
}
//检测标准--TestStandard
this.txtTestStandard.Text = newPMI_TrustManage.TestStandard;
//检测比例--TesTratio
if (!string.IsNullOrEmpty(newPMI_TrustManage.TesTratio))
{
this.ddlTesTratio.SelectedItem.Text = newPMI_TrustManage.TesTratio;
}
//合格要求--QualifiedRequire
this.txtQualifiedRequire.Text = newPMI_TrustManage.QualifiedRequire;
//委托编号--EntrustmentNo
this.txtEntrustmentNo.Text = newPMI_TrustManage.EntrustmentNo;
////装置
//this.drpInstallation.SelectedValue = newPMI_TrustManage.UnitCode;
////工区
//this.drpCH_TrustUnit.SelectedValue = newPMI_TrustManage.AreaIdCode;
}
else
{
//工程名称--PMIProjectName
//this.txtPMIProjectName.Text =string.Empty;
////单位工程名称--PMIUnitWorksName
//this.txtPMIUnitWorksName.Text = string.Empty;
//编号--SerialNum
this.txtSerialNum.Text = "SH/T3543-G128";
//检测标准--TestStandard
this.txtTestStandard.Text = string.Empty;
//合格要求--QualifiedRequire
this.txtQualifiedRequire.Text = string.Empty;
//委托编号--EntrustmentNo
this.txtEntrustmentNo.Text = string.Empty;
//装置
this.drpInstallation.SelectedValue = BLL.Const._Null;
//工区
this.drpWorkAreaId.SelectedValue = BLL.Const._Null;
}
}
//public void drpInstallationDropDownList(DropDownList dropName, bool isShowPlease)
//{
// dropName.DataValueField = "InstallationId";
// dropName.DataTextField = "InstallationName";
// dropName.DataSource = (from x in Funs.DB.PIM_View_PmiMaterialTemplate where x.ProjectId == this.CurrUser.LoginProjectId select new { x.InstallationId, x.InstallationName }).Distinct().ToList();
// dropName.DataBind();
// if (isShowPlease)
// {
// Funs.FineUIPleaseSelect(dropName);
// }
//}
//public void drpCH_TrustUnitDropDownList(DropDownList dropName, bool isShowPlease)
//{
// dropName.DataValueField = "UnitId";
// dropName.DataTextField = "UnitName";
// dropName.DataSource = (from x in Funs.DB.PIM_View_PmiMaterialTemplate where x.ProjectId == this.CurrUser.LoginProjectId select new { x.UnitId, x.UnitName }).Distinct().ToList();
// dropName.DataBind();
// if (isShowPlease)
// {
// Funs.FineUIPleaseSelect(dropName);
// }
//}
//public void InitAreaIdDropDownList(DropDownList dropName, string ddlstringName, bool isShowPlease)
//{
// this.drpCH_TrustUnit.DataValueField = "UnitId";
// this.drpCH_TrustUnit.DataTextField = "UnitName";
// if (isShowPlease || string.IsNullOrEmpty(ddlstringName))
// {
// Funs.FineUIPleaseSelect(dropName);
// }
// else
// {
// var ddlunitString = ddlstringName;
// this.drpCH_TrustUnit.DataValueField = "UnitId";
// this.drpCH_TrustUnit.DataTextField = "UnitName";
// this.drpCH_TrustUnit.DataSource = (from x in Funs.DB.PIM_View_PmiMaterialTemplate where x.ProjectId == this.CurrUser.LoginProjectId && x.InstallationId == ddlunitString select new { x.UnitId, x.UnitName }).Distinct().ToList();
// this.drpCH_TrustUnit.DataBind();
// }
//}
#endregion
#region
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid(List<Model.PMI_TrustMangeItem> GetTrustItem)
{
DataTable tb = this.LINQToDataTable(GetTrustItem);
// 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
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
List<Model.PMI_TrustMangeItem> GetTrustItem = this.CollectGridJointInfo();
this.BindGrid(GetTrustItem);
}
#endregion
#region
/// <summary>
/// 编辑无损委托
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_PMITrustManageMenuId, Const.BtnSave))
{
if (string.IsNullOrEmpty(this.txtEntrustmentNo.Text.Trim()))
{
Alert.ShowInTop("请输入委托单号!", MessageBoxIcon.Warning);
return;
}
if (string.IsNullOrEmpty(this.drpInstallation.SelectedValue) || this.drpInstallation.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择装置名称!", MessageBoxIcon.Warning);
return;
}
if (string.IsNullOrEmpty(this.drpWorkAreaId.SelectedValue) || this.drpWorkAreaId.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择工区!", MessageBoxIcon.Warning);
return;
}
if (string.IsNullOrEmpty(this.ddlTestMethod.SelectedValue) || this.ddlTestMethod.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择检测方法!", MessageBoxIcon.Warning);
return;
}
if (string.IsNullOrEmpty(this.ddlTesTratio.SelectedValue) || this.ddlTesTratio.SelectedValue == BLL.Const._Null)
{
Alert.ShowInTop("请选择检测比例!", MessageBoxIcon.Warning);
return;
}
Model.PMI_TrustManage newPMI_TrustManage = new Model.PMI_TrustManage();
newPMI_TrustManage.ProjectId = this.CurrUser.LoginProjectId;
//工程名称--PMIProjectName
//newPMI_TrustManage.PMIProjectName = this.txtPMIProjectName.Text.Trim();
////单位工程名称--PMIUnitWorksName
//newPMI_TrustManage.PMIUnitWorksName = this.txtPMIUnitWorksName.Text.Trim();
//编号--SerialNum
newPMI_TrustManage.SerialNum = this.txtSerialNum.Text.Trim();
//检测方法--TestMethod
newPMI_TrustManage.TestMethod = this.ddlTestMethod.SelectedText.Trim();
//检测标准--TestStandard
newPMI_TrustManage.TestStandard = this.txtTestStandard.Text.Trim();
//检测比例--TesTratio
newPMI_TrustManage.TesTratio = this.ddlTesTratio.SelectedText.Trim();
//合格要求--QualifiedRequire
newPMI_TrustManage.QualifiedRequire = this.txtQualifiedRequire.Text.Trim();
//委托编号--EntrustmentNo
newPMI_TrustManage.EntrustmentNo = this.txtEntrustmentNo.Text.Trim();
//装置
newPMI_TrustManage.UnitCode = this.drpInstallation.SelectedValue.Trim();
//工区
newPMI_TrustManage.AreaIdCode = this.drpWorkAreaId.SelectedValue.Trim();
if (!string.IsNullOrEmpty(this.PMITrustID))
{
newPMI_TrustManage.PMITrustId = this.PMITrustID;
BLL.PMITrustManageService.UpdateCH_Trust(newPMI_TrustManage);
BLL.LogService.AddSys_Log(this.CurrUser, newPMI_TrustManage.PMITrustId, this.PMITrustID, BLL.Const.HJGL_PMITrustManageMenuId, "修改PMI委托信息");
}
else
{
if (BLL.PMITrustManageService.IsExistTrustCode(this.CurrUser.LoginProjectId, this.txtEntrustmentNo.Text.Trim()))
{
ShowNotify("此委托单号已经存在!", MessageBoxIcon.Warning);
return;
}
this.PMITrustID = SQLHelper.GetNewID(typeof(Model.PMI_TrustManage));
newPMI_TrustManage.PMITrustId = this.PMITrustID;
BLL.PMITrustManageService.AddCH_Trust(newPMI_TrustManage);
BLL.LogService.AddSys_Log(this.CurrUser, newPMI_TrustManage.PMITrustId, this.PMITrustID, BLL.Const.HJGL_PMITrustManageMenuId, "添加无损委托信息");
}
List<Model.PMI_TrustMangeItem> GetTrustItem = this.CollectGridJointInfo();
List<Model.PMI_TrustMangeItem> TrustItem = new List<Model.PMI_TrustMangeItem>();
foreach (var item in GetTrustItem)
{
Model.PMI_TrustMangeItem newitem = new Model.PMI_TrustMangeItem();
newitem.PMITrustID = this.PMITrustID;
newitem.PMITrustItemID = item.PMITrustItemID;
newitem.MaterialId = item.MaterialId;
newitem.PMITrustID = this.PMITrustID;
newitem.PipelineNum = item.PipelineNum;
newitem.PipelineName = item.PipelineName;
newitem.QualityNum = item.QualityNum;
newitem.LotNumber = item.LotNumber;
newitem.PipeIineSpecs = item.PipeIineSpecs;
newitem.PipelineMaterial = item.PipelineMaterial;
newitem.HotStatus = item.HotStatus;
newitem.AcceptanceCriteria = item.AcceptanceCriteria;
newitem.SamplingNum = item.SamplingNum;
newitem.RemarkNum = item.RemarkNum;
TrustItem.Add(newitem);
}
BLL.PMITrustManageItemService.upDataCH_TrustItem(this.PMITrustID, TrustItem);
ShowNotify("提交成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
else
{
ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region Grid页面信息
/// <summary>
/// 收集Grid页面信息
/// </summary>
/// <returns></returns>
private List<Model.PMI_TrustMangeItem> CollectGridJointInfo()
{
List<Model.PMI_TrustMangeItem> GetTrustItem = null;
List<Model.PMI_TrustMangeItem> getNewTrustItem = new List<Model.PMI_TrustMangeItem>();
List<Model.PMI_MaterialTemplate> getNewPMI_MaterialTemplate = new List<Model.PMI_MaterialTemplate>();
if (!string.IsNullOrEmpty(this.hdItemsString.Text))
{
getNewPMI_MaterialTemplate = BLL.PMI_MaterialTemplateService.GetPMI_MaterialTemplateAddItem(this.hdItemsString.Text.Trim());
if (getNewPMI_MaterialTemplate != null || getNewPMI_MaterialTemplate.Count != 0)
{
foreach (var item in getNewPMI_MaterialTemplate)
{
PMI_TrustMangeItem newItem = new PMI_TrustMangeItem();
newItem.PMITrustItemID = SQLHelper.GetNewID(typeof(Model.PMI_TrustMangeItem));
newItem.MaterialId = item.MaterialId;
newItem.PMITrustID = this.PMITrustID;
newItem.PipelineNum = item.Pipeline;
newItem.PipelineName = item.IdentName;
newItem.QualityNum = item.QuantityFileNum;
newItem.LotNumber = item.BatchNumber;
newItem.PipeIineSpecs = item.Size1;
newItem.PipelineMaterial = item.Material;
newItem.HotStatus = item.HotState;
newItem.AcceptanceCriteria = item.AcceptanceCriteria;
newItem.SamplingNum = Convert.ToString(item.Quantity);
newItem.RemarkNum = item.QuantitySum;
getNewTrustItem.Add(newItem);
}
}
}
else if (string.IsNullOrEmpty(this.hdItemsString.Text) && this.PMITrustID != null)
{
GetTrustItem = BLL.PMITrustManageItemService.GetView_PMI_TrustItemByCH_TrustID(this.PMITrustID);
}
JArray mergedData = Grid1.GetMergedData();
foreach (JObject mergedRow in mergedData)
{
string status = mergedRow.Value<string>("status");
JObject values = mergedRow.Value<JObject>("values");
string rowID = values.Value<string>("PMITrustItemID").ToString();
if (GetTrustItem != null)
{
var item = GetTrustItem.FirstOrDefault(x => x.PMITrustItemID == rowID);
if (item != null)
{
getNewTrustItem.Add(item);
}
}
}
return getNewTrustItem;
}
#endregion
#region Grid
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
List<Model.PMI_TrustMangeItem> GetTrustItem = new List<PMI_TrustMangeItem>();
List<Model.PMI_MaterialTemplate> getNewPMI_MaterialTemplate = BLL.PMI_MaterialTemplateService.GetPMI_MaterialTemplateAddItem(this.hdItemsString.Text.Trim());
if (getNewPMI_MaterialTemplate != null || getNewPMI_MaterialTemplate.Count != 0)
{
foreach (var item in getNewPMI_MaterialTemplate)
{
PMI_TrustMangeItem newItem = new PMI_TrustMangeItem();
newItem.PMITrustItemID = SQLHelper.GetNewID(typeof(Model.PMI_TrustMangeItem));
newItem.MaterialId = item.MaterialId;
newItem.PMITrustID = this.PMITrustID;
newItem.PipelineNum = item.Pipeline;
newItem.PipelineName = item.IdentName;
newItem.QualityNum = item.QuantityFileNum;
newItem.LotNumber = item.BatchNumber;
newItem.PipeIineSpecs = item.Size1;
newItem.PipelineMaterial = item.Material;
newItem.HotStatus = item.HotState;
newItem.AcceptanceCriteria = item.AcceptanceCriteria;
newItem.SamplingNum = Convert.ToString(item.Quantity);
newItem.RemarkNum = item.QuantitySum;
GetTrustItem.Add(newItem);
}
}
this.BindGrid(GetTrustItem);
//this.hdItemsString.Text = string.Empty;
}
#endregion
#region
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
List<Model.PMI_TrustMangeItem> GetTrustItem = this.CollectGridJointInfo();
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
System.Web.UI.WebControls.HiddenField lblMaterialId = (System.Web.UI.WebControls.HiddenField)(Grid1.Rows[rowIndex].FindControl("hidMaterialId"));
string[] jot = lblMaterialId.Value.Split(',');
string jotId = jot[0];
var item = GetTrustItem.FirstOrDefault(x => x.MaterialId == jotId);
GetTrustItem.Remove(item);
}
BindGrid(GetTrustItem);
ShowNotify("操作完成!", MessageBoxIcon.Success);
}
}
#endregion
#region
/// <summary>
/// 查找未焊接焊口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ckSelect_Click(object sender, EventArgs e)
{
string MaterialId = string.Empty;
for (int i = 0; i < Grid1.Rows.Count; i++)
{
System.Web.UI.WebControls.HiddenField lblMaterialId = (System.Web.UI.WebControls.HiddenField)(Grid1.Rows[i].FindControl("hidMaterialId"));
string[] jot = lblMaterialId.Value.Split(',');
string jotId = jot[0];
//string jotId = Grid1.DataKeys[i][0].ToString();
MaterialId += jotId + "|";
}
if (MaterialId != string.Empty)
{
MaterialId = MaterialId.Substring(0, MaterialId.Length - 1);
}
if (!string.IsNullOrEmpty(this.drpWorkAreaId.SelectedValue) && this.drpWorkAreaId.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpInstallation.SelectedValue) && this.drpInstallation.SelectedValue != BLL.Const._Null)
{
string strList = this.drpWorkAreaId.SelectedValue + "|" + this.PMITrustID + "|" + this.drpInstallation.SelectedValue;
string window = String.Format("PMIShowTrustSearch.aspx?strList={0}&MaterialId={1}", strList, MaterialId, "编辑 - ");
PageContext.RegisterStartupScript(Window1.GetSaveStateReference(hdItemsString.ClientID) + Window1.GetShowReference(window));
}
else
{
Alert.ShowInTop("请选择装置和工区!", MessageBoxIcon.Warning);
}
}
#endregion
protected void drpInstallation_SelectedIndexChanged(object sender, EventArgs e)
{
this.drpWorkAreaId.Items.Clear();
if (this.drpInstallation.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpInstallation.SelectedValue))
{
BLL.WorkAreaService.InitWorkAreaByProjectIdAndInstallationId(this.drpWorkAreaId, this.CurrUser.LoginProjectId, this.drpInstallation.SelectedValue, true);
}
else
{
Funs.FineUIPleaseSelect(this.drpWorkAreaId);
}
this.drpWorkAreaId.SelectedIndex = 0;
//if (this.drpInstallation.SelectedValue == BLL.Const._Null || string.IsNullOrEmpty(this.drpInstallation.SelectedValue))
//{
// Funs.FineUIPleaseSelect(this.drpInstallation);
//}
//else
//{
// var ddlunitString = this.drpInstallation.SelectedValue;
// this.drpCH_TrustUnit.DataValueField = "UnitId";
// this.drpCH_TrustUnit.DataTextField = "UnitName";
// this.drpCH_TrustUnit.DataSource = (from x in Funs.DB.PIM_View_PmiMaterialTemplate where x.ProjectId == this.CurrUser.LoginProjectId && x.InstallationId == ddlunitString select new { x.UnitId, x.UnitName }).Distinct().ToList();
// this.drpCH_TrustUnit.DataBind();
//}
}
}
}