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.HotProessManage { public partial class HotProessManageItemEdit : PageBase { #region 定义项 /// /// 热处理主键 /// public string HotProessId { get { return (string)ViewState["HotProessId"]; } set { ViewState["HotProessId"] = value; } } #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.HotProessId = Request.Params["HotProessId"]; List units = new List(); var pUnit = BLL.Project_UnitService.GetProject_UnitByProjectIdUnitId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId); if (pUnit == null || pUnit.UnitType == Const.UnitType_5) { units = BLL.Base_UnitService.GetSubUnits(this.CurrUser.LoginProjectId); } else { units = BLL.Base_UnitService.GetUnitListByUnitId(this.CurrUser.LoginProjectId, this.CurrUser.UnitId); } this.drpUnit.DataTextField = "UnitName"; this.drpUnit.DataValueField = "UnitId"; this.drpUnit.DataSource = units; this.drpUnit.DataBind(); Funs.FineUIPleaseSelect(this.drpUnit); Funs.FineUIPleaseSelect(this.drpInstall); this.drpCheckUnit.DataTextField = "UnitName"; this.drpCheckUnit.DataValueField = "UnitId"; this.drpCheckUnit.DataSource = BLL.Base_UnitService.GetSubUnits(this.CurrUser.LoginProjectId); this.drpCheckUnit.DataBind(); Funs.FineUIPleaseSelect(this.drpCheckUnit); ///制单人 this.drpTabler.DataTextField = "UserName"; this.drpTabler.DataValueField = "UserId"; this.drpTabler.DataSource = BLL.Sys_UserService.GetUserListByProjectId(this.CurrUser.LoginProjectId); this.drpTabler.DataBind(); this.PageInfoLoad(); ///加载页面 var viewHotProessItemList = BLL.HJGL_HotProessManageEditService.GetViewHotProessItemListByID(this.HotProessId); this.BindGrid(viewHotProessItemList); ////初始化页面 if (!string.IsNullOrEmpty(Request.Params["type"])) { this.btnSave.Hidden = true; this.btnFind.Hidden = true; this.btnDelete.Hidden = true; } } } #endregion #region 加载页面输入提交信息 /// /// 加载页面输入提交信息 /// private void PageInfoLoad() { var hotProess = BLL.HJGL_HotProessManageEditService.GetHotProessByID(this.HotProessId); if (hotProess != null) { this.txtHotProessNo.Text = hotProess.HotProessNo; if (!string.IsNullOrEmpty(hotProess.UnitId)) { var unit = BLL.Base_UnitService.GetUnit(hotProess.UnitId); if (unit != null) { this.drpUnit.SelectedValue = unit.UnitId; if (!string.IsNullOrEmpty(hotProess.InstallationId)) { ///装置 this.drpInstall.DataTextField = "Text"; this.drpInstall.DataValueField = "Value"; this.drpInstall.DataSource = BLL.Project_InstallationService.GetInstallationList(this.CurrUser.LoginProjectId, this.drpUnit.SelectedValue); this.drpInstall.DataBind(); Funs.FineUIPleaseSelect(this.drpInstall); var install = this.drpInstall.Items.FirstOrDefault(x => x.Value == hotProess.InstallationId); if (install != null) { this.drpInstall.SelectedValue = hotProess.InstallationId; } } } } if (!string.IsNullOrEmpty(hotProess.CheckUnitId)) { this.drpCheckUnit.SelectedValue = hotProess.CheckUnitId; } if (!string.IsNullOrEmpty(hotProess.Tabler)) { var tabler = BLL.Sys_UserService.GetUsersByUserId(hotProess.Tabler); if (tabler != null) { this.drpTabler.SelectedValue = tabler.UserId; } } this.txtProessDate.Text = string.Format("{0:yyyy-MM-dd}", hotProess.ProessDate); this.txtProessMethod.Text = hotProess.ProessMethod; this.txtProessEquipment.Text = hotProess.ProessEquipment; this.txtRemark.Text = hotProess.Remark; this.txtNDTMethod.Text = hotProess.NDTMethod; this.txtNDTRate.Text = hotProess.NDTRate; this.txtStandards.Text = hotProess.Standards; this.txtInspectionNum.Text = hotProess.InspectionNum; this.txtCheckNum.Text = hotProess.CheckNum; this.txtTestWeldNum.Text = hotProess.TestWeldNum; this.txtSendee.Text = hotProess.Sendee; this.hdHotProessTrustId.Text = hotProess.HotProessTrustId; } else { this.SimpleForm1.Reset(); ///重置所有字段 this.drpTabler.SelectedValue = this.CurrUser.UserId; this.txtProessDate.Text = string.Format("{0:yyyy-MM-dd}", System.DateTime.Now); } } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid(List gvHotProessItemList) { Grid1.DataSource = this.GetPagedDataTable(Grid1, gvHotProessItemList); Grid1.DataBind(); } #endregion #region 收集Grid页面信息 /// /// 收集Grid页面信息 /// /// private List CollectGridPageInfo() { List viewHotProessItemList = new List(); JArray mergedData = Grid1.GetMergedData(); foreach (JObject mergedRow in mergedData) { string status = mergedRow.Value("status"); JObject values = mergedRow.Value("values"); string jot_id = values.Value("JOT_ID").ToString(); var newHotProessItem = BLL.HJGL_HotProessManageEditService.GetViewHotProessItemByJOT_ID(jot_id); if (newHotProessItem != null) { newHotProessItem.HotProessItemId = values.Value("HotProessItemId").ToString(); newHotProessItem.PointCount = Funs.GetNewInt(values.Value("PointCount").ToString()); newHotProessItem.RequiredT = values.Value("RequiredT").ToString(); newHotProessItem.ActualT = values.Value("ActualT").ToString(); newHotProessItem.RequestTime = values.Value("RequestTime").ToString(); newHotProessItem.ActualTime = values.Value("ActualTime").ToString(); newHotProessItem.RecordChartNo = values.Value("RecordChartNo").ToString(); newHotProessItem.HardnessReportNo = values.Value("HardnessReportNo").ToString(); viewHotProessItemList.Add(newHotProessItem); } } return viewHotProessItemList; } #endregion #region 下拉框联动事件 /// /// 单位下拉框变化事件 /// /// /// protected void drpUnit_OnSelectedIndexChanged(object sender, EventArgs e) { ///装置 this.drpInstall.Items.Clear(); this.drpInstall.DataTextField = "Text"; this.drpInstall.DataValueField = "Value"; this.drpInstall.DataSource = BLL.Project_InstallationService.GetInstallationList(this.CurrUser.LoginProjectId, this.drpUnit.SelectedValue); this.drpInstall.DataBind(); Funs.FineUIPleaseSelect(this.drpInstall); this.drpInstall.SelectedValue = BLL.Const._Null; this.BindGrid(this.CollectGridPageInfo()); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { this.BindGrid(this.CollectGridPageInfo()); } #endregion #region 热处理查找焊口 /// /// 热处理查找 /// /// /// protected void btnFind_Click(object sender, EventArgs e) { if (this.drpInstall.SelectedValue != BLL.Const._Null && !string.IsNullOrEmpty(this.drpInstall.SelectedValue)) { string jotIDString = this.HotProessId + "|" + this.drpUnit.SelectedValue + "|" + this.drpInstall.SelectedValue; string window = String.Format("HotProessManageItemFind.aspx?jotIDString={0}", jotIDString, "编辑 - "); PageContext.RegisterStartupScript(Window1.GetSaveStateReference(hdItemsString.ClientID) + Window1.GetShowReference(window)); } else { Alert.ShowInTop("请先选择单位、装置!", MessageBoxIcon.Warning); return; } } #endregion #region 热处理 提交事件 /// /// 编辑热处理 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_WeldReportMenuId, Const.BtnSave)) { if (BLL.HJGL_HotProessManageEditService.IsExistHotProessNO(this.txtHotProessNo.Text, this.HotProessId, this.CurrUser.LoginProjectId)) { Alert.ShowInTop("热处理编号已存在,请重新录入!", MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(this.txtProessDate.Text) || string.IsNullOrEmpty(this.txtHotProessNo.Text.Trim())) { Alert.ShowInTop("热处理告号、焊接日期不能为空!", MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(this.drpUnit.SelectedValue) || this.drpUnit.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择单位!", MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(this.drpInstall.SelectedValue) || this.drpInstall.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择装置!", MessageBoxIcon.Warning); return; } Model.HJGL_HotProess newHotProess = new Model.HJGL_HotProess(); newHotProess.ProjectId = this.CurrUser.LoginProjectId; newHotProess.HotProessNo = this.txtHotProessNo.Text.Trim(); newHotProess.ProessDate = Funs.GetNewDateTime(this.txtProessDate.Text.Trim()); if (this.drpInstall.SelectedValue != BLL.Const._Null) { newHotProess.InstallationId = this.drpInstall.SelectedValue; } if (this.drpUnit.SelectedValue != BLL.Const._Null) { newHotProess.UnitId = this.drpUnit.SelectedValue; } if (this.drpCheckUnit.SelectedValue != BLL.Const._Null) { newHotProess.CheckUnitId = this.drpCheckUnit.SelectedValue; } if (this.drpTabler.SelectedValue != BLL.Const._Null) { newHotProess.Tabler = this.drpTabler.SelectedValue; } newHotProess.Remark = this.txtRemark.Text.Trim(); newHotProess.ProessMethod = this.txtProessMethod.Text.Trim(); newHotProess.ProessEquipment = this.txtProessEquipment.Text.Trim(); newHotProess.NDTMethod = this.txtNDTMethod.Text.Trim(); newHotProess.NDTRate = this.txtNDTRate.Text.Trim(); newHotProess.Standards = this.txtStandards.Text.Trim(); newHotProess.InspectionNum = this.txtInspectionNum.Text.Trim(); newHotProess.TestWeldNum = this.txtTestWeldNum.Text.Trim(); newHotProess.CheckNum = this.txtCheckNum.Text.Trim(); newHotProess.Sendee = this.txtSendee.Text.Trim(); newHotProess.HotProessTrustId = this.hdHotProessTrustId.Text; if (!string.IsNullOrEmpty(this.HotProessId)) { newHotProess.HotProessId = this.HotProessId; BLL.HJGL_HotProessManageEditService.UpdateHotProess(newHotProess); BLL.HJGL_HotProessManageEditService.DeleteHotProessItemByHotProessId(this.HotProessId); BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "修改热处理单信息"); } else { newHotProess.HotProessId = SQLHelper.GetNewID(typeof(Model.HJGL_TP_TestPackage)); this.HotProessId = newHotProess.HotProessId; BLL.HJGL_HotProessManageEditService.AddHotProess(newHotProess); BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "添加热处理单信息"); } foreach (var item in this.CollectGridPageInfo()) { Model.HJGL_HotProessItem newitem = new Model.HJGL_HotProessItem(); newitem.HotProessId = this.HotProessId; newitem.HotProessItemId = item.HotProessItemId; newitem.JOT_ID = item.JOT_ID; newitem.PointCount = item.PointCount; newitem.RequiredT = item.RequiredT; newitem.ActualT = item.ActualT; newitem.RequestTime = item.RequestTime; newitem.ActualTime = item.ActualTime; newitem.RecordChartNo = item.RecordChartNo; newitem.HardnessReportNo = item.HardnessReportNo; BLL.HJGL_HotProessManageEditService.AddHotProessItem(newitem, this.txtHotProessNo.Text, this.txtProessDate.Text); } ShowNotify("提交成功!", MessageBoxIcon.Success); //PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(newHotProess.HotProessId) + ActiveWindow.GetHidePostBackReference()); } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } #endregion #region Grid 明细操作事件 /// /// 右键删除 /// /// /// protected void btnDelete_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请选择一条记录!", MessageBoxIcon.Warning); return; } var viewHotProessItemList = this.CollectGridPageInfo(); foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string jotID = Grid1.Rows[rowIndex].Values[13].ToString(); var itemList = (from x in viewHotProessItemList where x.JOT_ID == jotID orderby x.PointCount descending select x).FirstOrDefault(); if (itemList != null) { viewHotProessItemList.Remove(itemList); } } this.BindGrid(viewHotProessItemList); } /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { var viewHotProessItemList = this.CollectGridPageInfo(); if (!string.IsNullOrEmpty(hdItemsString.Text)) { List list = Funs.GetStrListByStr(hdItemsString.Text, '#'); this.hdHotProessTrustId.Text = list[0]; List jotList = Funs.GetStrListByStr(list[1], '|'); foreach (var item in jotList) { List itemstrs = Funs.GetStrListByStr(item, ','); string jotIditem = itemstrs[0]; int number = Funs.GetNewIntOrZero(itemstrs[1]); var jot = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(jotIditem); if (jot != null) { if (number > 0) { for (int i = 0; i < number; i++) { Model.View_HotProessItem info = Funs.DB.View_HotProessItem.FirstOrDefault(x => x.JOT_ID == jotIditem); info.HotProessItemId = SQLHelper.GetNewID(typeof(Model.HJGL_HotProessItem)); viewHotProessItemList.Add(info); } } } } } this.BindGrid(viewHotProessItemList); this.hdItemsString.Text = string.Empty; } #endregion } }