Basf_TCC7/HJGL/FineUIPro.Web/HotProcessHard/HotProessTrustEdit.aspx.cs

303 lines
13 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using BLL;
using System.Data;
using Newtonsoft.Json.Linq;
namespace FineUIPro.Web.HotProcessHard
{
public partial class HotProessTrustEdit : PageBase
{
#region
/// <summary>
/// 热处理委托主键
/// </summary>
public string HotProessTrustId
{
get
{
return (string)ViewState["HotProessTrustId"];
}
set
{
ViewState["HotProessTrustId"] = value;
}
}
///// <summary>
///// 项目主键
///// </summary>
//public string ProjectId
//{
// get
// {
// return (string)ViewState["ProjectId"];
// }
// set
// {
// ViewState["ProjectId"] = value;
// }
//}
#endregion
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.HotProessTrustId = Request.Params["HotProessTrustId"];
//this.ProjectId = Request.Params["ProjectId"];
//var trust = BLL.HotProess_TrustService.GetHotProessTrustById(this.HotProessTrustId);
//if (trust != null)
//{
// this.ProjectId = trust.ProjectId;
//}
BLL.Project_InstallationService.InitInstallationDropDownList(this.drpInstallationId, true, this.CurrUser.LoginProjectId,Resources.Lan.PleaseSelect);//装置
BLL.Base_UnitService.InitUnitDropDownList(this.drpUnitId, true, BLL.Const.UnitType_5, Resources.Lan.PleaseSelect);//单位
this.PageInfoLoad(); ///加载页面
List<Model.View_HotProess_TrustItem> lists = BLL.HotProessTrustItemService.GetViewHotProessTrustItem(this.CurrUser.LoginProjectId, this.HotProessTrustId);
this.BindGrid(lists); ////初始化页面
}
}
#endregion
#region
/// <summary>
/// 加载页面输入提交信息
/// </summary>
private void PageInfoLoad()
{
var trust = BLL.HotProess_TrustService.GetHotProessTrustById(this.HotProessTrustId);
if (trust != null)
{
//this.ProjectId = trust.ProjectId;
this.txtHotProessTrustNo.Text = trust.HotProessTrustNo;
if (trust.ProessDate.HasValue)
{
this.txtProessDate.Text = string.Format("{0:yyyy-MM-dd}", trust.ProessDate);
}
if (!string.IsNullOrEmpty(trust.InstallationId))
{
this.drpInstallationId.SelectedValue = trust.InstallationId;
}
if (!string.IsNullOrEmpty(trust.UnitId))
{
this.drpUnitId.SelectedValue = trust.UnitId;
}
this.txtProessMethod.Text = trust.ProessMethod;
this.txtProessEquipment.Text = trust.ProessEquipment;
if (!string.IsNullOrEmpty(trust.Tabler))
{
this.txtTabler.Text = BLL.Sys_UserService.GetUserNameByUserId(trust.Tabler);
}
this.txtRemark.Text = trust.Remark;
}
else
{
this.txtTabler.Text = this.CurrUser.UserName;
this.SimpleForm1.Reset(); //重置所有字段
}
}
#endregion
#region
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid(List<Model.View_HotProess_TrustItem> lists)
{
DataTable tb = this.LINQToDataTable(lists);
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 ckSelect_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.drpUnitId.SelectedValue) && this.drpUnitId.SelectedValue != BLL.Const._Null)
{
string weldJointIds = string.Empty;
for (int i = 0; i < Grid1.Rows.Count; i++)
{
string jotId = Grid1.DataKeys[i][0].ToString();
weldJointIds += jotId + "|";
}
if (weldJointIds != string.Empty)
{
weldJointIds = weldJointIds.Substring(0, weldJointIds.Length - 1);
}
string strList = this.drpUnitId.SelectedValue + "|" + this.HotProessTrustId + "|" + this.CurrUser.LoginProjectId;
string window = String.Format("HotProessTrustItemEdit.aspx?strList={0}&weldJointIds={1}", strList, weldJointIds, "编辑 - ");
PageContext.RegisterStartupScript(Window1.GetSaveStateReference(hdItemsString.ClientID) + Window1.GetShowReference(window));
}
else
{
Alert.ShowInTop(Resources.Lan.PleaseSelectCompany, MessageBoxIcon.Warning);
}
}
#endregion
#region Grid
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
string weldJointIds = string.Empty;
if (!string.IsNullOrEmpty(hdItemsString.Text))
{
weldJointIds = hdItemsString.Text.Substring(0, hdItemsString.Text.LastIndexOf('|'));
List<Model.View_HotProess_TrustItem> lists = BLL.HotProess_TrustService.GetHotProessTrustAddItem(weldJointIds);
this.BindGrid(lists);
}
}
#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.HotProessTrustMenuId, Const.BtnSave))
{
if (BLL.HotProess_TrustService.IsExistTrustCode(this.txtHotProessTrustNo.Text, this.HotProessTrustId, this.CurrUser.LoginProjectId))
{
ShowNotify(Resources.Lan.TrustCodeExists, MessageBoxIcon.Warning);
return;
}
Model.HotProess_Trust newHotProessTrust = new Model.HotProess_Trust();
newHotProessTrust.HotProessTrustNo = this.txtHotProessTrustNo.Text.Trim();
newHotProessTrust.ProessDate = Funs.GetNewDateTime(this.txtProessDate.Text.Trim());
if (this.drpInstallationId.SelectedValue != BLL.Const._Null)
{
newHotProessTrust.InstallationId = this.drpInstallationId.SelectedValue;
}
newHotProessTrust.ProjectId = this.CurrUser.LoginProjectId;
if (this.drpUnitId.SelectedValue != BLL.Const._Null)
{
newHotProessTrust.UnitId = this.drpUnitId.SelectedValue;
}
newHotProessTrust.Tabler = this.CurrUser.UserId;
newHotProessTrust.Remark = this.txtRemark.Text.Trim();
newHotProessTrust.ProessMethod = this.txtProessMethod.Text.Trim();
newHotProessTrust.ProessEquipment = this.txtProessEquipment.Text.Trim();
if (!string.IsNullOrEmpty(this.HotProessTrustId))
{
newHotProessTrust.HotProessTrustId = this.HotProessTrustId;
BLL.HotProess_TrustService.UpdateHotProessTrust(newHotProessTrust);
//BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, Resources.Lan.ModifyPWHT);
}
else
{
this.HotProessTrustId = SQLHelper.GetNewID(typeof(Model.HotProess_Trust));
newHotProessTrust.HotProessTrustId = this.HotProessTrustId;
BLL.HotProess_TrustService.AddHotProessTrust(newHotProessTrust);
//BLL.Sys_LogService.AddLog(BLL.Const.System_3,this.CurrUser.LoginProjectId, this.CurrUser.UserId, Resources.Lan.AddPWHT);
}
BLL.HotProessTrustItemService.DeleteHotProessTrustItemById(this.HotProessTrustId);
this.CollectGridJointInfo();//收集Grid页面信息,增加明细
ShowNotify(Resources.Lan.SaveSuccessfully, MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(newHotProessTrust.HotProessTrustId)
+ ActiveWindow.GetHidePostBackReference());
}
else
{
ShowNotify(Resources.Lan.NoPrivilegePrompt, MessageBoxIcon.Warning);
return;
}
}
#endregion
#region Grid页面信息,
/// <summary>
/// 收集Grid页面信息,提交明细
/// </summary>
/// <returns></returns>
private void CollectGridJointInfo()
{
JArray mergedData = Grid1.GetMergedData();
foreach (JObject mergedRow in mergedData)
{
JObject values = mergedRow.Value<JObject>("values");
Model.HotProess_TrustItem newTrustItem = new Model.HotProess_TrustItem();
newTrustItem.HotProessTrustId = this.HotProessTrustId;
newTrustItem.WeldJointId = values.Value<string>("WeldJointId").ToString();
string hotProessTrustItemId = values.Value<string>("HotProessTrustItemId").ToString();
if (!string.IsNullOrEmpty(hotProessTrustItemId))
{
newTrustItem.HotProessTrustItemId = hotProessTrustItemId;
}
BLL.HotProessTrustItemService.AddHotProessTrustItem(newTrustItem);
}
}
#endregion
#region
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.hdItemsString.Text))
{
this.hdItemsString.Text = this.hdItemsString.Text.Substring(0, this.hdItemsString.Text.LastIndexOf('|'));
}
var trust = BLL.HotProess_TrustService.GetHotProessTrustById(this.HotProessTrustId);
if (Grid1.SelectedRowIndexArray.Length > 0)
{
List<Model.View_HotProess_TrustItem> GetHotProessTrustItem = new List<Model.View_HotProess_TrustItem>();
if (!string.IsNullOrEmpty(this.hdItemsString.Text))
{
GetHotProessTrustItem = BLL.HotProess_TrustService.GetHotProessTrustAddItem(this.hdItemsString.Text);
}
else if (string.IsNullOrEmpty(this.hdItemsString.Text) && this.HotProessTrustId != null)
{
GetHotProessTrustItem = BLL.HotProess_TrustService.GetHotProessTrustItem(this.CurrUser.LoginProjectId, this.HotProessTrustId);
}
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
var item = GetHotProessTrustItem.FirstOrDefault(x => x.WeldJointId == rowID);
if (item != null)
{
if (string.IsNullOrEmpty(this.HotProessTrustId)) //新增记录可直接删除
{
GetHotProessTrustItem.Remove(item);
}
}
}
BindGrid(GetHotProessTrustItem);
ShowNotify(Resources.Lan.DeletedSuccessfully, MessageBoxIcon.Success);
}
}
#endregion
}
}