using System; using System.Collections.Generic; using System.Data; using System.Text; using System.Data.SqlClient; using System.Linq; using BLL; using Newtonsoft.Json.Linq; using AspNet = System.Web.UI.WebControls; namespace FineUIPro.Web.HJGL.HotHardManage { public partial class HardTestResult : PageBase { #region 定义项 /// /// 硬度检验报告主键 /// public string HardTestReportId { get { return (string)ViewState["HardTestReportId"]; } set { ViewState["HardTestReportId"] = value; } } #endregion protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); 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.tvHardTestTrust.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = "项目"; rootNode.NodeID = "0"; rootNode.ToolTip = "绿色为结果全部反馈,黑色为未完全反馈"; rootNode.Expanded = true; rootNode.EnableClickEvent = true; this.tvHardTestTrust.Nodes.Add(rootNode); //this.InitTreeMenu();//加载树 //this.tvHardTestTrust.SelectedNodeID = "0"; //BindGrid(); CheckBoxField cbf1 = Grid1.FindColumn("IsOK1") as CheckBoxField; cbf1.HeaderText = " 硬度合格"; CheckBoxField cbf2 = Grid1.FindColumn("IsOK2") as CheckBoxField; cbf2.HeaderText = " 硬度不合格"; } } protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e) { this.InitTreeMenu(); } protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } private void BindGrid() { string strSql = string.Empty; List listStr = new List(); string projectIds = BLL.Base_ProjectService.GetStrProjectIds(this.CurrUser.UserId, "1"); if (this.tvHardTestTrust.SelectedNode.CommandName == "报告编号") { strSql = @"SELECT *,newid() as New_ID FROM dbo.HJGL_View_CH_HardTestResult WHERE HardTestReportId=@HardTestReportId"; listStr.Add(new SqlParameter("@HardTestReportId", this.tvHardTestTrust.SelectedNodeID)); } else if (this.tvHardTestTrust.SelectedNode.CommandName == "项目名称") { strSql = @"SELECT *,newid() as New_ID FROM dbo.HJGL_View_CH_HardTestResult WHERE ProjectId= @ProjectId AND HardTestReportId is not null and (FileType='R' or FileType is null)"; listStr.Add(new SqlParameter("@ProjectId", this.tvHardTestTrust.SelectedNodeID)); } else if (this.tvHardTestTrust.SelectedNodeID == "0") //选择项目根节点 WHERE @ProjectId like '%'+ProjectId+'%' and HardTestReportId is not null"; { strSql = @"SELECT *,newid() as New_ID FROM dbo.HJGL_View_CH_HardTestResult WHERE CHARINDEX(ProjectId,@ProjectId)>0 and HardTestReportId is not null"; listStr.Add(new SqlParameter("@ProjectId", projectIds)); } if (!string.IsNullOrEmpty(this.txtIsoNo.Text.Trim())) { strSql += @" and ISO_IsoNo like @IsoNo "; listStr.Add(new SqlParameter("@IsoNo", "%" + this.txtIsoNo.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtJointNo.Text.Trim())) { strSql += @" and JOT_JointNo like @JointNo "; listStr.Add(new SqlParameter("@JointNo", "%" + this.txtJointNo.Text.Trim() + "%")); } if (this.rblState.SelectedValue == "1") { strSql += @" and IsOK =1 "; } else if (this.rblState.SelectedValue == "0") { strSql += @" and IsOK =0 "; } else if (this.rblState.SelectedValue == "3") { strSql += @" and IsOK is null and CannotCheck 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_HardTestResult result = BLL.HJGL_CH_HardTestResultService.GetHardTestResultByHardTestReportIdAndJotID(this.Grid1.Rows[i].DataKeys[1].ToString(), this.Grid1.Rows[i].DataKeys[0].ToString()); if (result != null) { if (result.IsOK == true) { this.Grid1.Rows[i].Values[4] = BLL.Const._True; this.Grid1.Rows[i].Values[5] = BLL.Const._False; } if (result.IsOK == false) { this.Grid1.Rows[i].Values[4] = BLL.Const._False; this.Grid1.Rows[i].Values[5] = BLL.Const._True; } if (result.CannotCheck == true) { this.Grid1.Rows[i].Values[6] = BLL.Const._True; } //System.Web.UI.WebControls.DropDownList drpIsOK = (System.Web.UI.WebControls.DropDownList)(this.Grid1.Rows[i].FindControl("drpIsOK")); //if (result.IsOK == true) //{ // drpIsOK.SelectedValue = "1"; //} //else if (result.IsOK == false) //{ // drpIsOK.SelectedValue = "0"; //} //else //{ // drpIsOK.SelectedValue = "2"; //} } } } #region 加载树单位-硬度检验报告单 /// /// 加载树 /// private void InitTreeMenu() { this.tvHardTestTrust.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = "项目"; rootNode.NodeID = "0"; rootNode.ToolTip = "绿色为结果全部反馈,黑色为未完全反馈"; rootNode.Expanded = true; rootNode.EnableClickEvent = true; this.tvHardTestTrust.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(); } List trustLists = new List(); ///硬度检验报告 trustLists = (from x in Funs.DB.HJGL_CH_HardTestReport where x.HotHardCode.Contains(this.txtSearchNo.Text.Trim()) select x).ToList(); foreach (var item in projects) { TreeNode rootUnitNode = new TreeNode();//定义根节点 rootUnitNode.Text = item.ProjectCode; rootUnitNode.NodeID = item.ProjectId; rootUnitNode.EnableClickEvent = true; rootUnitNode.EnableExpandEvent = true; rootUnitNode.ToolTip = item.ProjectName; rootUnitNode.CommandName = "项目名称"; rootNode.Nodes.Add(rootUnitNode); if (!string.IsNullOrEmpty(this.txtSearchNo.Text.Trim())) { var projectTrustLists = (from x in trustLists where x.ProjectId == item.ProjectId && (x.FileType == null || x.FileType == "T") orderby x.HotHardCode descending select x).ToList(); if (projectTrustLists.Count > 0) { rootUnitNode.Expanded = true; this.BindNodes(rootUnitNode, projectTrustLists); } } else { TreeNode tn = new TreeNode(); tn.NodeID = "temp"; tn.Text = "正在加载..."; rootUnitNode.Nodes.Add(tn); } } } #endregion /// /// 查询 /// /// /// protected void Tree_TextChanged(object sender, EventArgs e) { this.InitTreeMenu(); //this.BindGrid(); } protected void tvControlItem_NodeExpand(object sender, TreeNodeEventArgs e) { if (e.Node.Nodes != null) { e.Node.Nodes.Clear(); } var trustProjectLists = (from x in Funs.DB.HJGL_CH_HardTestReport where x.HotHardCode.Contains(this.txtSearchNo.Text.Trim()) && x.ProjectId == e.Node.NodeID orderby x.HotHardCode descending select x).ToList(); this.BindNodes(e.Node, trustProjectLists); } #region 绑定树节点 /// /// 绑定树节点 /// /// private void BindNodes(TreeNode node, List trustList) { foreach (var item in trustList) { TreeNode newNode = new TreeNode(); var hardTestReportShowItemsCount = (from x in Funs.DB.HJGL_CH_HardTestReportItem where x.HardTestReportId == item.HardTestReportId select x.JOT_ID).Distinct().Count(); var hardTestResults = from x in Funs.DB.HJGL_CH_HardTestResult where x.HardTestReportId == item.HardTestReportId && x.IsOK != null select x; var cannotCheckHardTestResults = from x in Funs.DB.HJGL_CH_HardTestResult where x.HardTestReportId == item.HardTestReportId && x.CannotCheck == true select x; if (hardTestReportShowItemsCount == (hardTestResults.Count() + cannotCheckHardTestResults.Count())) //单据数据全部反馈,记录为绿色 { newNode.Text = "" + item.HotHardCode + ""; } else { newNode.Text = item.HotHardCode; } newNode.NodeID = item.HardTestReportId; newNode.ToolTip = item.HotHardCode; newNode.CommandName = "报告编号"; newNode.EnableClickEvent = true; node.Nodes.Add(newNode); } } #endregion #region 行点击事件 /// /// Grid行点击事件 /// /// /// protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == "CheckBox1") { CheckBoxField checkField = (CheckBoxField)Grid1.FindColumn(e.ColumnIndex); bool checkState = checkField.GetCheckedState(e.RowIndex); if (checkState == true) { CheckBoxField checkField2 = (CheckBoxField)Grid1.FindColumn(e.ColumnIndex + 1); bool checkState2 = checkField2.GetCheckedState(e.RowIndex); if (checkState2) { checkField2.SetCheckedState(e.RowIndex, false); } } } if (e.CommandName == "CheckBox2") { CheckBoxField checkField = (CheckBoxField)Grid1.FindColumn(e.ColumnIndex); bool checkState = checkField.GetCheckedState(e.RowIndex); this.hdIndex.Text = string.Empty; if (checkState == true) { string isoNo = this.Grid1.Rows[e.RowIndex].Values[1].ToString(); string jointNo = this.Grid1.Rows[e.RowIndex].Values[2].ToString(); PageContext.RegisterStartupScript(Confirm.GetShowReference("是否确认管线" + isoNo + "的焊口" + jointNo + "硬度不合格?", String.Empty, MessageBoxIcon.Question, PageManager1.GetCustomEventReference(false, "Confirm_OK"), // 第一个参数 false 用来指定当前不是AJAX请求 PageManager1.GetCustomEventReference("Confirm_Cancel"))); this.hdIndex.Text = e.RowIndex.ToString(); CheckBoxField checkField2 = (CheckBoxField)Grid1.FindColumn(e.ColumnIndex - 1); bool checkState2 = checkField2.GetCheckedState(e.RowIndex); if (checkState2) { checkField2.SetCheckedState(e.RowIndex, false); } } } } #endregion /// /// 点口确定对话框 /// /// /// protected void PageManager1_CustomEvent(object sender, CustomEventArgs e) { if (!string.IsNullOrEmpty(this.hdIndex.Text)) { if (e.EventArgument == "Confirm_OK") { this.Grid1.Rows[Funs.GetNewIntOrZero(this.hdIndex.Text)].Values[5] = BLL.Const._True; } else if (e.EventArgument == "Confirm_Cancel") { this.Grid1.Rows[Funs.GetNewIntOrZero(this.hdIndex.Text)].Values[5] = BLL.Const._False; } } } #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvHardTestTrust_NodeCommand(object sender, TreeCommandEventArgs e) { this.HardTestReportId = this.tvHardTestTrust.SelectedNodeID; 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 report = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(this.HardTestReportId); if (report != null) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("HardTestReportEdit.aspx?HardTestReportId={0}&type=view", this.HardTestReportId, "查看 - "))); } 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_HardTestResultMenuId, Const.BtnSave)) { //var report = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(this.HardTestReportId); //if (report != null) //{ var hardTestResults = from x in Funs.DB.HJGL_CH_HardTestResult select x; for (int i = 0; i < this.Grid1.Rows.Count; i++) { string jot_id = this.Grid1.Rows[i].DataKeys[0].ToString(); string hardTestReportId = this.Grid1.Rows[i].DataKeys[1].ToString(); var hardTestResult = hardTestResults.FirstOrDefault(x => x.JOT_ID == jot_id && x.HardTestReportId == hardTestReportId); if (hardTestResult != null) { Funs.DB.HJGL_CH_HardTestResult.DeleteOnSubmit(hardTestResult); Funs.DB.SubmitChanges(); } } BLL.HJGL_CH_HardTestResultService.DeleteHardTestResultsyHardTestReportId(this.HardTestReportId); var hardTestReportItems = from x in Funs.DB.HJGL_CH_HardTestReportItem select x; var hotProessResults = from x in Funs.DB.HJGL_CH_HotProessResult select x; JArray mergedData = Grid1.GetMergedData(); foreach (JObject mergedRow in mergedData) { Model.HJGL_CH_HardTestResult result = new Model.HJGL_CH_HardTestResult(); string status = mergedRow.Value("status"); JObject values = mergedRow.Value("values"); int rowIndex = mergedRow.Value("index"); result.HardTestReportId = this.Grid1.Rows[rowIndex].DataKeys[1].ToString(); result.JOT_ID = values.Value("JOT_ID").ToString(); CheckBoxField IsOK1 = (CheckBoxField)Grid1.FindColumn("IsOK1"); CheckBoxField IsOK2 = (CheckBoxField)Grid1.FindColumn("IsOK2"); bool b1 = IsOK1.GetCheckedState(rowIndex); bool b2 = IsOK2.GetCheckedState(rowIndex); if (b1) { result.IsOK = true; result.ResultDate = DateTime.Now; //硬度合格,更新热处理反馈结果也为合格 Model.HJGL_CH_HardTestReportItem hardTestReportItem = (from x in hardTestReportItems where x.HardTestReportId == result.HardTestReportId && x.JOT_ID == result.JOT_ID select x).FirstOrDefault(); if (hardTestReportItem != null) { Model.HJGL_CH_HotProessResult hotProessResult = (from x in hotProessResults where x.HotProessTrustId == hardTestReportItem.HotProessTrustId && x.JOT_ID == result.JOT_ID select x).FirstOrDefault(); if (hotProessResult != null) { hotProessResult.IsOK = true; BLL.HJGL_CH_HotProessResultService.UpdateHotProessResult(hotProessResult); Model.HJGL_PW_JointInfo joint = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(hotProessResult.JOT_ID); if (joint != null) { if (joint.HotProessResultOK == null) { //回写热处理合格及反馈时间 BLL.HJGL_PW_JointInfoService.WriteBackHardTestResultOKAndDate(joint.JOT_ID, true); } } } } //回写硬度合格及反馈时间 BLL.HJGL_PW_JointInfoService.WriteBackHardTestResultOKAndDate(result.JOT_ID, true); } if (b2) { result.IsOK = false; result.ResultDate = DateTime.Now; //回写硬度合格及反馈时间 BLL.HJGL_PW_JointInfoService.WriteBackHardTestResultOKAndDate(result.JOT_ID, false); } CheckBoxField CannotCheck = (CheckBoxField)Grid1.FindColumn("CannotCheck"); bool b3 = CannotCheck.GetCheckedState(rowIndex); if (b3) { result.CannotCheck = true; } result.Remark = values.Value("Remark").ToString(); BLL.HJGL_CH_HardTestResultService.AddHardTestResult(result); } ShowNotify("提交成功!", MessageBoxIcon.Success); //} //else //{ // ShowNotify("请选择要处理的硬度检验报告记录!", MessageBoxIcon.Warning); //} } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } #endregion #region 导出按钮 /// 导出按钮 /// /// /// protected void btnOut_Click(object sender, EventArgs e) { Response.ClearContent(); string filename = Funs.GetNewFileName(); Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("硬度检验结果反馈" + filename, System.Text.Encoding.UTF8) + ".xls"); Response.ContentType = "application/excel"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Write(GetGridTableHtml(Grid1)); Response.End(); } /// /// 导出方法 /// /// /// private string GetGridTableHtml(Grid grid) { StringBuilder sb = new StringBuilder(); sb.Append(""); sb.Append(""); sb.Append(""); this.Grid1.PageSize = 10000; BindGrid(); foreach (GridColumn column in grid.Columns) { if (column.Hidden == false) { sb.AppendFormat("", column.HeaderText); } } sb.Append(""); foreach (GridRow row in grid.Rows) { sb.Append(""); foreach (GridColumn column in grid.Columns) { if (column.Hidden == false) { string html = row.Values[column.ColumnIndex].ToString(); if (column.ColumnID == "tfNumber") { html = (row.FindControl("labNumber") as AspNet.Label).Text; } if (html == "True") { html = "√"; } if (html == "False") { html = ""; } sb.AppendFormat("", html); } } sb.Append(""); } sb.Append("
{0}
{0}
"); return sb.ToString(); } #endregion } }