ZHJA_HJGL/HJGL_ZH/FineUIPro.Web/YLRQ/HardProessManage/HardProessTrustEdit.aspx.cs

414 lines
20 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 BLL;
using Model;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.YLRQ.HardProessManage
{
public partial class HardProessTrustEdit : PageBase
{
/// <summary>
/// 硬度委托主键
/// </summary>
public string HardProessTrustId { get { return (string)ViewState["HardProessTrustId"]; } set { ViewState["HardProessTrustId"] = value; } }
/// <summary>
/// 项目主键
/// </summary>
public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } }
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.HardProessTrustId = Request.Params["HardProessTrustId"];
this.ProjectId = Request.Params["ProjectId"];
var trust = Funs.DB.PV_CH_HardProessTrust.FirstOrDefault(p => p.HardProessTrustId == this.HardProessTrustId);
if (trust != null) this.ProjectId = trust.ProjectId;
var pUnit = BLL.Base_UnitService.GetUnitsByProjectUnitType(this.ProjectId, BLL.Const.UnitType_4);
if (pUnit != null)
{
this.drpUnit.DataTextField = "UnitName";
this.drpUnit.DataValueField = "UnitId";
this.drpUnit.DataSource = pUnit;
this.drpUnit.DataBind();
}
///委托人
this.drpTrustMan.DataTextField = "UserName";
this.drpTrustMan.DataValueField = "UserId";
this.drpTrustMan.DataSource = Funs.DB.View_Common_Project_UserList.Where(p => p.ProjectId == this.ProjectId);
this.drpTrustMan.DataBind();
Funs.FineUIPleaseSelect(this.drpTrustMan);
this.drpTrustMan.SelectedValue = this.CurrUser.UserId;
this.PageInfoLoad(); ///加载页面
List<PV_View_CH_HardProessTrustItem> lists = Funs.DB.PV_View_CH_HardProessTrustItem.Where(x => x.ProjectId == this.ProjectId && x.HardProessTrustId == this.HardProessTrustId).ToList();
this.BindGrid(lists); //初始化页面
}
}
#endregion
#region
/// <summary>
/// 加载页面输入提交信息
/// </summary>
private void PageInfoLoad()
{
var trust = Funs.DB.PV_CH_HardProessTrust.FirstOrDefault(e => e.HardProessTrustId == this.HardProessTrustId);
if (trust != null)
{
this.ProjectId = trust.ProjectId;
this.txtProjectName.Text = trust.ProjectName;
this.txtHardProessTrustCode.Text = trust.HardProessTrustCode;
if (!string.IsNullOrEmpty(trust.TrustUnitId))
{
this.drpUnit.SelectedValue = trust.TrustUnitId;
}
this.txtConstructionNo.Text = trust.ConstructionNo;
if (!string.IsNullOrEmpty(trust.TrstManId))
{
this.drpTrustMan.SelectedValue = trust.TrstManId;
}
}
else
{
//重置所有字段
this.SimpleForm1.Reset();
//委托单号自动生成,规则:施工号-日期1127-两位流水
this.txtHardProessTrustCode.Text = SQLHelper.RunProcNewIdByProjectId("SpGetNewCode2ByProjectIdNoR", "dbo.PV_CH_HardProessTrust", "HardProessTrustCode", this.ProjectId, Base_ProjectService.GetProjectCode(this.ProjectId) + "-" + string.Format("{0:MMdd}", DateTime.Now) + "-");
Base_Project project = BLL.Base_ProjectService.GetProjectByProjectId(this.ProjectId);
if (project != null)
{
this.txtProjectName.Text = project.ProjectName;
this.txtConstructionNo.Text = project.ProjectCode;
}
if (this.CurrUser.UserId != Const.GlyId)
{
this.drpTrustMan.SelectedValue = this.CurrUser.UserId;
}
}
}
#endregion
#region
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid(List<PV_View_CH_HardProessTrustItem> lists)
{
DataTable tb = this.LINQToDataTable(lists);
// 2.获取当前分页数据
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 btnSave_Click(object sender, EventArgs e)
{
if (Funs.DB.PV_CH_HardProessTrust.Count(x => x.HardProessTrustCode == this.txtHardProessTrustCode.Text && x.ProjectId == this.ProjectId && x.HardProessTrustId != this.HardProessTrustId) > 0)
{
ShowNotify("委托单号已存在,请重新录入!", MessageBoxIcon.Warning);
return;
}
PV_CH_HardProessTrust newHardProessTrust = new PV_CH_HardProessTrust();
if (!string.IsNullOrEmpty(this.HardProessTrustId))
{
newHardProessTrust = Funs.DB.PV_CH_HardProessTrust.FirstOrDefault(p => p.HardProessTrustId == this.HardProessTrustId);
if (newHardProessTrust == null)
{
ShowNotify("修改传递数据存在错误!", MessageBoxIcon.Warning);
return;
}
}
newHardProessTrust.ProjectId = this.ProjectId;
newHardProessTrust.HardProessTrustCode = this.txtHardProessTrustCode.Text.Trim();
if (this.drpUnit.SelectedValue != BLL.Const._Null)
{
newHardProessTrust.TrustUnitId = this.drpUnit.SelectedValue;
}
newHardProessTrust.ProjectName = this.txtProjectName.Text.Trim();
newHardProessTrust.ConstructionNo = this.txtConstructionNo.Text.Trim();
if (this.drpTrustMan.SelectedValue != BLL.Const._Null)
{
newHardProessTrust.TrstManId = this.drpTrustMan.SelectedValue;
}
if (!string.IsNullOrEmpty(this.HardProessTrustId))
{
newHardProessTrust.HardProessTrustId = this.HardProessTrustId;
Funs.DB.SubmitChanges();
Sys_LogService.AddLog(BLL.Const.System_4, this.ProjectId, this.CurrUser.UserId, "修改硬度委托信息");
}
else
{
this.HardProessTrustId = SQLHelper.GetNewID(typeof(PV_CH_HardProessTrust));
newHardProessTrust.HardProessTrustId = this.HardProessTrustId;
newHardProessTrust.TrustType = "1"; //正常口
newHardProessTrust.CreateTime = newHardProessTrust.CreateDate = DateTime.Now;
Funs.DB.PV_CH_HardProessTrust.InsertOnSubmit(newHardProessTrust);
Funs.DB.SubmitChanges();
Sys_LogService.AddLog(Const.System_4, this.ProjectId, this.CurrUser.UserId, "添加硬度委托信息");
}
//删除委托明细
var cH_Trust = Funs.DB.PV_HardProessItem.Where(x => x.HardProessTrustId == this.HardProessTrustId);
if (cH_Trust != null)
{
Funs.DB.PV_HardProessItem.DeleteAllOnSubmit(cH_Trust);
Funs.DB.SubmitChanges();
}
this.CollectGridJointInfo();
ShowNotify("提交成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(newHardProessTrust.HardProessTrustId)
+ ActiveWindow.GetHidePostBackReference());
}
#endregion
#region Grid页面信息,
/// <summary>
/// 收集Grid页面信息,提交明细
/// </summary>
/// <returns></returns>
private void CollectGridJointInfo()
{
JArray mergedData = Grid1.GetMergedData();
foreach (JObject mergedRow in mergedData)
{
string status = mergedRow.Value<string>("status");
JObject values = mergedRow.Value<JObject>("values");
int rowIndex = mergedRow.Value<int>("index");
string hotProessTrustItemId = Grid1.DataKeys[rowIndex][1].ToString();
string hotProessTrustId = Grid1.DataKeys[rowIndex][2].ToString();
string weldingCode = Grid1.DataKeys[rowIndex][4].ToString();
string str = string.Empty;
PV_HardProessItem item = new PV_HardProessItem();
item.HardProessTrustId = this.HardProessTrustId;
item.ProjectId = this.ProjectId;
item.HotId = values.Value<string>("HotId").ToString();
item.TrustDate = Funs.GetNewDateTime(values.Value<string>("TrustDate").ToString());
item.Remark = values.Value<string>("Remark").ToString();
item.HotProessTrustId = hotProessTrustId;
item.HotProessTrustItemId = hotProessTrustItemId;
item.WeldingCode = weldingCode;
if (!string.IsNullOrEmpty(values.Value<string>("HardProessResultId").ToString()))
{
item.HardProessResultId = values.Value<string>("HardProessResultId").ToString();
}
item.HardProessItemId = SQLHelper.GetNewID(typeof(PV_HardProessItem));
if (Funs.DB.PV_HardProessItem.Count(x => x.HotId == item.HotId && x.HardProessTrustId == item.HardProessTrustId) == 0)
{
Funs.DB.PV_HardProessItem.InsertOnSubmit(item);
Funs.DB.SubmitChanges();
}
//回写焊口硬度委托时间
PV_WeldInformation newJointInfo = Funs.DB.PV_WeldInformation.FirstOrDefault(e => e.WeldingCode == weldingCode);
if (newJointInfo != null)
{
newJointInfo.HardProessTrustDate = item.TrustDate;
Funs.DB.SubmitChanges();
}
//进入硬度结果反馈
if (Funs.DB.PV_CH_HardProessResult.Count(x => x.HotId == item.HotId && x.HardProessTrustId == this.HardProessTrustId) == 0)
{
PV_CH_HardProessResult hardProessResult = new PV_CH_HardProessResult();
hardProessResult.HardProessResultId = Guid.NewGuid().ToString();
hardProessResult.ProjectId = this.ProjectId;
hardProessResult.HotId = item.HotId;
hardProessResult.HardProessTrustId = this.HardProessTrustId;
hardProessResult.HardProessItemId = item.HardProessItemId;
hardProessResult.HotProessTrustId = hotProessTrustId;
hardProessResult.HotProessTrustItemId = hotProessTrustItemId;
Funs.DB.PV_CH_HardProessResult.InsertOnSubmit(hardProessResult);
Funs.DB.SubmitChanges();
}
}
}
#endregion
#region Grid
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
List<string> list = Funs.GetStrListByStr(hdItemsString.Text, '|');
List<PV_View_CH_HardProessTrustItem> lists = GetHardProessTrustAddItem(this.hdItemsString.Text);
this.BindGrid(lists);
}
#endregion
#region
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
var trust = Funs.DB.PV_CH_HardProessTrust.FirstOrDefault(p => p.HardProessTrustId == this.HardProessTrustId);
if (trust != null && trust.IsPrint == true)
{
ShowNotify("硬度委托已打印,无法删除!", MessageBoxIcon.Warning);
return;
}
if (Grid1.SelectedRowIndexArray.Length > 0)
{
List<PV_View_CH_HardProessTrustItem> GetHardProessTrustItem = new List<PV_View_CH_HardProessTrustItem>();
if (!string.IsNullOrEmpty(this.hdItemsString.Text))
{
GetHardProessTrustItem = GetHardProessTrustAddItem(this.hdItemsString.Text);
}
else if (string.IsNullOrEmpty(this.hdItemsString.Text) && this.HardProessTrustId != null)
{
GetHardProessTrustItem = Funs.DB.PV_View_CH_HardProessTrustItem.Where(p => p.ProjectId == this.ProjectId && p.HardProessTrustId == this.HardProessTrustId).ToList();
}
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
var item = GetHardProessTrustItem.FirstOrDefault(x => x.HotId == rowID);
if (item != null)
{
//新增记录可直接删除
if (string.IsNullOrEmpty(this.HardProessTrustId))
{
GetHardProessTrustItem.Remove(item);
this.hdItemsString.Text = this.hdItemsString.Text.Replace(rowID, "");
}
else//修改记录时只能删除未处理的硬度记录
{
var result = Funs.DB.PV_CH_HardProessResult.FirstOrDefault(x => x.HardProessTrustId == item.HardProessTrustId && x.HotId == item.HotId);
if (result != null)
{
if (result.IsOK == null)
{
GetHardProessTrustItem.Remove(item);
this.hdItemsString.Text = this.hdItemsString.Text.Replace(rowID, "");
}
else
{
ShowNotify("硬度结果已反馈,无法删除!", MessageBoxIcon.Warning);
}
//删除硬度反馈明细
Funs.DB.PV_CH_HardProessResult.DeleteOnSubmit(result);
Funs.DB.SubmitChanges();
}
}
}
}
BindGrid(GetHardProessTrustItem);
ShowNotify("操作完成!", MessageBoxIcon.Success);
}
}
#endregion
/// <summary>
/// 查找未焊接焊口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ckSelect_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.drpUnit.SelectedValue) && this.drpUnit.SelectedValue != BLL.Const._Null)
{
string hotProessTrustItemIds = string.Empty;
for (int i = 0; i < Grid1.Rows.Count; i++)
{
string hotProessTrustItemId = Grid1.DataKeys[i][1].ToString();
if (!string.IsNullOrEmpty(hotProessTrustItemId))
{
hotProessTrustItemId += "," + hotProessTrustItemId;
}
hotProessTrustItemIds += hotProessTrustItemId + "|";
}
if (!string.IsNullOrEmpty(hotProessTrustItemIds))
{
hotProessTrustItemIds = hotProessTrustItemIds.Substring(0, hotProessTrustItemIds.Length - 1);
}
string strList = this.drpUnit.SelectedValue + "|" + this.HardProessTrustId + "|" + this.ProjectId;
string window = String.Format("HardProessTrustItemEdit.aspx?strList={0}&hotProessTrustItemIds={1}", strList, hotProessTrustItemIds, "编辑 - ");
PageContext.RegisterStartupScript(Window1.GetSaveStateReference(hdItemsString.ClientID) + Window1.GetShowReference(window));
}
else
{
Alert.ShowInTop("请选择单位!", MessageBoxIcon.Warning);
}
}
/// <summary>
/// 查找后返回集合增加到列表集团中
/// </summary>
/// <param name="hdItemsString"></param>
/// <returns></returns>
public List<PV_View_CH_HardProessTrustItem> GetHardProessTrustAddItem(string hdItemsString)
{
var jointInfos = Funs.DB.PV_View_HotWeldInformation.Where(p => p.ProjectId == this.ProjectId);
List<PV_View_CH_HardProessTrustItem> returnViewMatch = new List<PV_View_CH_HardProessTrustItem>();
if (!string.IsNullOrEmpty(hdItemsString))
{
List<string> jotIds = Funs.GetStrListByStr(hdItemsString, '|');
foreach (var jotItem in jotIds)
{
string[] strs = jotItem.Split(',');
var jotInfo = jointInfos.FirstOrDefault(x => x.HotId == strs[0]);
if (jotInfo != null)
{
PV_View_CH_HardProessTrustItem newItem = new PV_View_CH_HardProessTrustItem();
newItem.HardProessTrustId = SQLHelper.GetNewID(typeof(PV_View_CH_HardProessTrustItem));
newItem.HotId = jotInfo.HotId;
newItem.WeldingCode = jotInfo.WeldingCode;
newItem.JointDesc = jotInfo.JointDesc;
newItem.STE_Code = jotInfo.STE_Code;
newItem.TrustDate = DateTime.Now;
newItem.ProjectId = this.ProjectId;
newItem.RepairFalg = jotInfo.RepairFalg;
if (strs.Length > 1)
{
newItem.HotProessTrustId = strs[1];
}
if (strs.Length > 2)
{
newItem.HotProessTrustItemId = strs[2];
var data = Funs.DB.PV_CH_HotProessResult.FirstOrDefault(p => p.HotProessTrustItemId == newItem.HotProessTrustItemId);
if (data != null)
{
newItem.CompleteDate = data.CompleteDate;
}
var dataItem = Funs.DB.PV_CH_HotProessTrustItem.FirstOrDefault(p => p.HotProessTrustItemId == newItem.HotProessTrustItemId);
if (dataItem != null)
{
newItem.HotTrustDate = dataItem.TrustDate;
}
}
returnViewMatch.Add(newItem);
}
}
}
return returnViewMatch;
}
}
}