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 HotProessResult : PageBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); List myList = new List(); myList = BLL.HJGL_PW_JointInfoService.GetProessTypes(); drpProessTypes.DataTextField = "Name"; drpProessTypes.DataValueField = "Id"; drpProessTypes.DataSource = myList; drpProessTypes.DataBind(); Funs.FineUIPleaseSelect(drpProessTypes); this.drpProjectId.DataTextField = "ProjectCode"; this.drpProjectId.DataValueField = "ProjectId"; this.drpProjectId.DataSource = BLL.Base_ProjectService.GetOnProjectListByUserId(this.CurrUser.UserId, "1"); this.drpProjectId.DataBind(); Funs.FineUIPleaseSelect(this.drpProjectId); this.drpProjectId.SelectedValue = this.CurrUser.LoginProjectId; this.InitTreeMenu();//加载树 this.tvHotProessTrust.SelectedNodeID = this.CurrUser.LoginProjectId; BindGrid(); } } protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e) { this.InitTreeMenu(); } private void BindGrid() { string strSql = string.Empty; List listStr = new List(); string projectIds = BLL.Base_ProjectService.GetStrOnProjectIds(this.CurrUser.UserId, "1"); if (this.tvHotProessTrust.SelectedNode.CommandName == "项目名称") { strSql = @"SELECT * " + @" FROM dbo.HJGL_View_CH_HotProessResult AS Result" + @" WHERE Result.ProjectId= @ProjectId "; listStr.Add(new SqlParameter("@ProjectId", this.tvHotProessTrust.SelectedNodeID)); } else { strSql = @"SELECT * " + @" FROM dbo.HJGL_View_CH_HotProessResult AS Result WHERE CHARINDEX(Result.ProjectId,@ProjectId)>0 "; listStr.Add(new SqlParameter("@ProjectId", projectIds)); } if (this.drpProessTypes.SelectedValue != BLL.Const._Null) { strSql += " and Result.ProessTypes=@ProessTypes "; listStr.Add(new SqlParameter("@ProessTypes", this.drpProessTypes.SelectedValue)); } if (!string.IsNullOrEmpty(this.txtSearchNo.Text.Trim())) { strSql += @" AND RecordChartNo like @RecordChartNo"; listStr.Add(new SqlParameter("@RecordChartNo", "%" + this.txtSearchNo.Text.Trim() + "%")); } if (this.rblIsOK.SelectedValue == "1") //热处理已合格 { strSql += @" AND IsOK=1"; } else if (this.rblIsOK.SelectedValue == "0") //热处理未合格 { strSql += @" AND IsOK is null"; } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); // 2.获取当前分页数据 //var table = this.GetPagedDataTable(Grid1, tb1); Grid1.RecordCount = tb.Rows.Count; tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); for (int i = 0; i < this.Grid1.Rows.Count; i++) { Model.HJGL_CH_HotProessResult result = BLL.HJGL_CH_HotProessResultService.GetHotProessResultByID(this.Grid1.Rows[i].DataKeys[0].ToString()); if (result != null) { System.Web.UI.WebControls.CheckBox cbIsNeedHardTest = (System.Web.UI.WebControls.CheckBox)(this.Grid1.Rows[i].FindControl("cbIsNeedHardTest")); if (result.ProessTypes.Contains("4") && !string.IsNullOrEmpty(this.Grid1.Rows[i].Values[5].ToString())) { cbIsNeedHardTest.Visible = true; } else { cbIsNeedHardTest.Visible = false; } if (result.IsNeedHardTest == true) { cbIsNeedHardTest.Checked = true; } System.Web.UI.WebControls.CheckBox cbIsOK = (System.Web.UI.WebControls.CheckBox)(this.Grid1.Rows[i].FindControl("cbIsOK")); if (result.IsOK == true) { cbIsOK.Checked = true; } } } } protected void cbIsNeedHardTest_OnCheckedChanged(object sender, EventArgs e) { System.Web.UI.WebControls.CheckBox cbIsNeedHardTest = sender as System.Web.UI.WebControls.CheckBox; for (int i = 0; i < this.Grid1.Rows.Count; i++) { System.Web.UI.WebControls.CheckBox cbIsNeedHardTest1 = (System.Web.UI.WebControls.CheckBox)(this.Grid1.Rows[i].FindControl("cbIsNeedHardTest")); if (cbIsNeedHardTest.ClientID == cbIsNeedHardTest1.ClientID) { if (cbIsNeedHardTest.Checked) { Model.HJGL_CH_HotProessResult result = BLL.HJGL_CH_HotProessResultService.GetHotProessResultByID(this.Grid1.Rows[i].DataKeys[0].ToString()); result.IsNeedHardTest = true; result.IsOK = true; if (result.ResultDate == null) { result.ResultDate = DateTime.Now; } BLL.HJGL_CH_HotProessResultService.UpdateHotProessResult(result); if (result.ProessTypes == "4" || result.ProessTypes == "5") { //回写热处理合格及反馈时间 BLL.HJGL_PW_JointInfoService.WriteBackHotProessResultOKAndDate(result.JOT_ID, true); } BindGrid(); } } } } #region 查询 /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } #endregion #region 加载树单位 /// /// 加载树 /// private void InitTreeMenu() { this.tvHotProessTrust.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = "项目"; rootNode.NodeID = "0"; rootNode.Expanded = true; rootNode.EnableClickEvent = true; this.tvHotProessTrust.Nodes.Add(rootNode); List projects = BLL.Base_ProjectService.GetOnProjectListByUserId(this.CurrUser.UserId, "1"); if (this.drpProjectId.SelectedValueArray.Length > 1 || (this.drpProjectId.SelectedValueArray.Length == 1 && this.drpProjectId.SelectedValue != "null")) { projects = projects.Where(x => this.drpProjectId.SelectedValueArray.Contains(x.ProjectId)).ToList(); } foreach (var item in projects) { TreeNode rootUnitNode = new TreeNode();//定义根节点 rootUnitNode.Text = item.ProjectCode; rootUnitNode.NodeID = item.ProjectId; rootUnitNode.Expanded = true; rootUnitNode.ToolTip = item.ProjectName; rootUnitNode.CommandName = "项目名称"; rootUnitNode.EnableClickEvent = true; rootNode.Nodes.Add(rootUnitNode); } } #endregion /// /// 查询 /// /// /// protected void Tree_TextChanged(object sender, EventArgs e) { this.InitTreeMenu(); this.BindGrid(); } #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvHotProessTrust_NodeCommand(object sender, TreeCommandEventArgs e) { this.Grid1.DataSource = null; this.Grid1.DataBind(); BindGrid(); } #endregion #region 页索引改变事件 /// /// 页索引改变事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } #endregion #region 分页选择下拉改变事件 /// /// 分页选择下拉改变事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #region 查看按钮 /// /// 查看按钮 /// /// /// protected void btnView_Click(object sender, EventArgs e) { //var trust = BLL.HJGL_CH_HotProessTrustService.GetCH_HotProessTrustByID(this.HotProessTrustId); //if (trust != null) //{ // Model.HJGL_HotProess hotProess = BLL.HJGL_HotProessManageEditService.GetHotProessByHotProessTrustId(this.HotProessTrustId); // if (hotProess != null) // { // PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("HotProessManageItemEdit.aspx?HotProessId={0}&type=view", hotProess.HotProessId, "查看 - "))); // } // else // { // ShowNotify("热处理记录不存在!", MessageBoxIcon.Warning); // } //} //else //{ // ShowNotify("请选择要处理的热处理委托记录!", MessageBoxIcon.Warning); //} } #endregion #region 提交按钮 /// /// 提交按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_HotProessTrustMenuId, Const.BtnSave)) { string isoidLog = string.Empty; //是否同一管线标记 int i = 0; //检验数量 int flag = 0; //打印标记 string hotHardID = string.Empty; //硬度委托主键 string hardTestReportId = string.Empty; //硬度检验报告主键 List hotProessStates = new List(); //热处理状态 string hotProessState = string.Empty; JArray mergedData = Grid1.GetMergedData(); foreach (JObject mergedRow in mergedData) { string status = mergedRow.Value("status"); JObject values = mergedRow.Value("values"); int rowIndex = mergedRow.Value("index"); Model.HJGL_CH_HotProessResult result = BLL.HJGL_CH_HotProessResultService.GetHotProessResultByID(this.Grid1.Rows[rowIndex].DataKeys[0].ToString()); result.HotProessCurveNo = this.Grid1.Rows[rowIndex].Values[5].ToString(); System.Web.UI.WebControls.CheckBox cbIsNeedHardTest = (System.Web.UI.WebControls.CheckBox)(this.Grid1.Rows[rowIndex].FindControl("cbIsNeedHardTest")); if (cbIsNeedHardTest.Checked) //需要硬度委托的焊口 { //生成硬度委托功能已移至热处理录入页面提交按钮时操作 } else { bool b = true; //是否可以修改硬度委托状态 string jot_id = values.Value("JOT_ID").ToString(); string hotProessTrustId = values.Value("HotProessTrustId").ToString(); Model.HJGL_CH_HardTestReportItem oldHardTestReportItem = BLL.HJGL_CH_HardTestReportService.GetHardTestReportItemByJotIDAndHotProessTrustId(jot_id, hotProessTrustId); if (oldHardTestReportItem != null) { Model.HJGL_CH_HardTestReport report = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(oldHardTestReportItem.HardTestReportId); if (report != null) { if (report.IsPrintTrust == true) //硬度委托已打印则不能修改硬度委托状态 { b = false; result.IsNeedHardTest = true; } } } if (b) //可以修改硬度委托状态 { if (oldHardTestReportItem != null) { string id = oldHardTestReportItem.HardTestReportId; BLL.HJGL_CH_HardTestReportService.DeleteCH_HardTestReportItemByCH_HardTestReportID(id); BLL.HJGL_CH_HardTestReportService.DeleteCH_HardTestReportByCH_HardTestReportID(id); } result.IsNeedHardTest = false; } } result.Remark = values.Value("Remark").ToString(); System.Web.UI.WebControls.CheckBox cbIsOK = (System.Web.UI.WebControls.CheckBox)(this.Grid1.Rows[rowIndex].FindControl("cbIsOK")); if (cbIsOK.Checked) { result.IsOK = true; if (result.ResultDate == null) { result.ResultDate = DateTime.Now; } if (result.ProessTypes == "4" || result.ProessTypes == "5") { //回写热处理合格及反馈时间 BLL.HJGL_PW_JointInfoService.WriteBackHotProessResultOKAndDate(result.JOT_ID, true); } } else { result.IsOK = null; if (result.ProessTypes == "4" || result.ProessTypes == "5") { //回写热处理合格及反馈时间 BLL.HJGL_PW_JointInfoService.WriteBackHotProessResultOKAndDate(result.JOT_ID, null); } //if (result.ResultDate == null) //{ // result.ResultDate = DateTime.Now; //} } BLL.HJGL_CH_HotProessResultService.UpdateHotProessResult(result); } //更新之前硬度检验报告的热处理状态和检验数量 Model.HJGL_CH_HardTestReport oldHardTestReport2 = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(hardTestReportId); if (oldHardTestReport2 != null) { hotProessStates = hotProessStates.Distinct().ToList(); foreach (var item in hotProessStates) { hotProessState += item + ","; } hotProessState = hotProessState.Substring(0, hotProessState.LastIndexOf(",")); oldHardTestReport2.HotProessState = hotProessState; oldHardTestReport2.TestCount = i; BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReport(oldHardTestReport2); } ShowNotify("提交成功!", MessageBoxIcon.Success); } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } #endregion /// /// 得到热处理类型 /// /// /// protected string ConvertProessTypes(object ProessTypes) { string proessTypes = string.Empty; if (ProessTypes != null) { proessTypes = BLL.HJGL_PW_JointInfoService.ConvertProessTypes(ProessTypes.ToString()); } return proessTypes; } /// /// 得到热处理曲线编号 /// /// /// protected string ConvertHotProessCurveNo(object HotProessResultId) { string hotProessCurveNo = string.Empty; if (HotProessResultId != null) { Model.HJGL_CH_HotProessResult result = BLL.HJGL_CH_HotProessResultService.GetHotProessResultByID(HotProessResultId.ToString()); if (result != null) { Model.HJGL_HotProessItem item = Funs.DB.HJGL_HotProessItem.FirstOrDefault(x => x.HotProessTrustId == result.HotProessTrustId && x.JOT_ID == result.JOT_ID); if (item != null) { hotProessCurveNo = item.RecordChartNo; } } } return hotProessCurveNo; } /// /// 得到硬度检测结果 /// /// /// protected string ConvertHardTestResult(object HotProessResultId) { string result = string.Empty; if (HotProessResultId != null) { Model.HJGL_CH_HotProessResult hotProessResult = BLL.HJGL_CH_HotProessResultService.GetHotProessResultByID(HotProessResultId.ToString()); if (hotProessResult != null && hotProessResult.ProessTypes.Contains("4")) { Model.HJGL_CH_HardTestReportItem hardTestReportItem = Funs.DB.HJGL_CH_HardTestReportItem.FirstOrDefault(x => x.HotProessTrustId == hotProessResult.HotProessTrustId && x.JOT_ID == hotProessResult.JOT_ID); if (hardTestReportItem != null) { Model.HJGL_CH_HardTestResult hardTestResult = Funs.DB.HJGL_CH_HardTestResult.FirstOrDefault(x => x.HardTestReportId == hardTestReportItem.HardTestReportId && x.JOT_ID == hardTestReportItem.JOT_ID); if (hardTestResult != null) { if (hardTestResult.IsOK == true) { result = "是"; } else if (hardTestResult.IsOK == false) { result = "否"; } } } } } return result; } } }