using BLL; using Model; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace FineUIPro.Web.YLRQ.ConstructionManagement { public partial class WeldingMethod : PageBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BridProjectGrid(); BindGrid(); BindGrid1(); } } #region 绑定数据 /// /// 绑定项目 /// public void BridProjectGrid() { GridProject.DataSource = BLL.Base_ProjectService.GetYlrqProjectListByUserId(this.CurrUser.UserId, "2"); GridProject.DataBind(); drpProject.Value = this.CurrUser.LoginProjectId; } /// /// 绑定数据 /// public void BindGrid() { if (string.IsNullOrEmpty(drpProject.Value)) { Grid1.DataSource = null; Grid1.DataBind(); return; } string strSql = @"select a.WeldingId,a.WeldingCode,a.ProjectId,a.Negative,a.RepairMark,b.WME_ID,a.Confirmation,STUFF((SELECT ','+cl.NdtCode FROM PV_ManagementMethod as cl where cl.WeldingId=a.WeldingId for xml path('')),1,1,'') as NDT_Codes,STUFF((SELECT ','+cl.NdtId FROM PV_ManagementMethod as cl where cl.WeldingId=a.WeldingId for xml path('')),1,1,'') as NDT_Ids,c.HeatTreatmentType,a.SortField,a.CreateTime from PV_WeldInformation as a left join HJGL_BS_WeldMethod as b on a.WmeId=b.WME_ID left join PV_WeldInformation as c on c.WeldingId=a.WeldingId where 1=1 and a.ProjectId=@ProjectId "; //是否录入 if (rblIsEnter.SelectedValue == "1") { strSql += " and (select COUNT(1) from PV_ManagementMethod as manage where manage.WeldingId=a.WeldingId)=0 order by a.SortField asc"; } else { strSql += " and (select COUNT(1) from PV_ManagementMethod as manage where manage.WeldingId=a.WeldingId)>0 order by a.SortField asc"; } List listStr = new List(); listStr.Add(new SqlParameter("@ProjectId", drpProject.Value)); SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); // 2.获取当前分页数据 Grid1.RecordCount = tb.Rows.Count; var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); //焊接方法 DropDownList ddlWMECode = Grid1.FindColumn("WME_ID").FindControl("ddlWMECode") as DropDownList; ddlWMECode.DataTextField = "WME_Code"; ddlWMECode.DataValueField = "WME_ID"; ddlWMECode.DataSource = Funs.DB.HJGL_BS_WeldMethod; ddlWMECode.DataBind(); } /// /// 绑定Grid2 /// public void BindGrid1() { var list = Funs.DB.PV_TestMethod; // 2.获取当前分页数据 Grid2.RecordCount = list.Count(); var table = this.GetPagedDataTable(Grid2, list); Grid2.DataSource = table; Grid2.DataBind(); } /// /// 绑定Grid3 /// public void BindGrid2(string weldingId) { //获取当前焊缝信息 var ndtIds = Funs.DB.PV_ManagementMethod.Where(p => p.WeldingId == weldingId).Select(p => p.NdtId); if (ndtIds.Count() > 0) { var list = Funs.DB.PV_TestMethod.Where(p => ndtIds.Contains(p.Ndt_Id)); if (list.Count() > 0) { // 2.获取当前分页数据 Grid3.RecordCount = list.Count(); var table = this.GetPagedDataTable(Grid3, list); Grid3.DataSource = table; Grid3.DataBind(); } } } /// /// 热处理类型名称 /// /// protected string ConvertProessTypes(object ProessTypes) { string proessTypes = string.Empty; if (ProessTypes != null) { proessTypes = BLL.HJGL_PW_JointInfoService.ConvertProessTypes(ProessTypes.ToString()); } return proessTypes; } /// /// 关闭弹出框执行 /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { this.BindGrid(); } /// /// 是否录入 /// protected void rblIsEnter_SelectedIndexChanged(object sender, EventArgs e) { BindGrid(); } /// /// 单元格操作 /// protected void Grid1_RowDataBound(object sender, GridRowEventArgs e) { CheckBoxField Confirmation = Grid1.FindColumn("Confirmation") as CheckBoxField; RenderField WME_ID = Grid1.FindColumn("WME_ID") as RenderField; RenderField NDT_Ids = Grid1.FindColumn("NDT_Ids") as RenderField; if (Confirmation.GetCheckedState(e.RowIndex)) { e.CellCssClasses[WME_ID.ColumnIndex] = "f-grid-cell-uneditable"; e.CellCssClasses[NDT_Ids.ColumnIndex] = "f-grid-cell-uneditable"; } } /// /// 点击行事件 /// /// /// protected void Grid1_RowClick(object sender, GridRowClickEventArgs e) { if (!string.IsNullOrEmpty(this.Grid1.SelectedRowID)) { BindGrid2(this.Grid1.SelectedRowID); } } /// /// 施工号下拉框 /// protected void drpProject_TextChanged(object sender, EventArgs e) { BindGrid(); } #endregion #region 分页排序 /// /// 页索引改变事件 /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } /// /// 排序 /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { BindGrid(); } /// /// 分页选择下拉改变事件 /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #region 按钮操作 /// /// 保存 /// protected void btnSave_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.PV_WeldingTestingMethod, Const.BtnSubmit)) { Dictionary> modifiedDict = Grid1.GetModifiedDict(); //获取所有的焊接方法 foreach (int rowIndex in modifiedDict.Keys) { List mentMets = new List(); var weldingId = Grid1.DataKeys[rowIndex][0].ToString(); var weldModel = Funs.DB.PV_WeldInformation.FirstOrDefault(p => p.WeldingId == weldingId); var testMethods = Funs.DB.PV_TestMethod; if (weldModel == null) continue; if (weldModel.Confirmation == 1) { BindGrid(); ShowNotify($"焊缝{weldModel.WeldingCode}已确认委托,无法修改!"); return; } //检测方法 if (modifiedDict[rowIndex].ContainsKey("NDT_Ids")) { //删除所有的焊缝方法 var deleteMangMet = Funs.DB.PV_ManagementMethod.Where(p => p.WeldingId == weldModel.WeldingId).ToList(); Funs.DB.PV_ManagementMethod.DeleteAllOnSubmit(deleteMangMet); Funs.DB.SubmitChanges(); int i = 0; foreach (var itemId in modifiedDict[rowIndex]["NDT_Ids"].ToString().Split(',')) { var itemTestMethods = testMethods.FirstOrDefault(p => p.Ndt_Id == itemId); mentMets.Add(new PV_ManagementMethod() { MethodId = Guid.NewGuid().ToString(), NdtId = itemId, NdtCode = itemTestMethods != null ? itemTestMethods.Ndt_NdtCode : string.Empty, WeldingId = weldModel.WeldingId, CreateId = CurrUser.UserId, CreateTime = DateTime.Now }); i++; } } //焊接方法 if (modifiedDict[rowIndex].ContainsKey("WME_ID")) { weldModel.WmeId = modifiedDict[rowIndex]["WME_ID"].ToString(); } Funs.DB.PV_ManagementMethod.InsertAllOnSubmit(mentMets); Funs.DB.SubmitChanges(); } BindGrid(); ShowNotify("操作成功!"); } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } #endregion /// /// 检测方法下拉框 /// protected void ddlNDTCodes_TextChanged(object sender, EventArgs e) { var ndtIds = ddlNDTCodes.Values; if (ndtIds.Length > 0) { var nowId = ndtIds.Last(); var pvNdts = Funs.DB.PV_TestMethod.Where(p => ndtIds.Contains(p.Ndt_Id)).ToList(); if (pvNdts.Count() > 0) { var nowNdt = pvNdts.FirstOrDefault(p => p.Ndt_Id == nowId); if (pvNdts.Count(p => p.Ndt_NdtCode == nowNdt.Ndt_NdtCode) > 1) { var xtNdtIds = pvNdts.Where(p => p.Ndt_NdtCode == nowNdt.Ndt_NdtCode && p.Ndt_Id != nowId).Select(p => p.Ndt_Id); pvNdts.RemoveAll(p => xtNdtIds.Contains(p.Ndt_Id)); ddlNDTCodes.Values = pvNdts.ConvertAll(p => p.Ndt_Id).ToArray(); } } } } } }