using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using BLL; using System.Windows.Forms; using Newtonsoft.Json.Linq; using AspNet = System.Web.UI.WebControls; namespace FineUIPro.Web.HJGL.HotHardManage { public partial class HardReportSet : PageBase { #region 定义项 /// /// 选择集合 /// public List SelectList { get { return (List)ViewState["SelectList"]; } set { ViewState["SelectList"] = value; } } #endregion protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SelectList = new List(); 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; //var projects = BLL.Base_ProjectService.GetProjectListByUserIdAndState(this.CurrUser.UserId, this.drpIsProjectClosed.SelectedValue); //RadioButtonList1.DataTextField = "ProjectCode"; //RadioButtonList1.DataValueField = "ProjectId"; //RadioButtonList1.DataSource = projects; //RadioButtonList1.DataBind(); this.drpIsoNo.DataTextField = "ISO_IsoNo"; this.drpIsoNo.DataValueField = "ISO_ID"; Funs.FineUIPleaseSelect(this.drpIsoNo); //this.txtPointDate.Text = string.Format("{0:yyyy-MM}", DateTime.Now); //CheckBoxField cbVI = Grid1.FindColumn("IsVI") as CheckBoxField; //cbVI.HeaderText = " 外观检验"; this.InitTreeMenu();//加载树 } } #region 加载树项目 /// /// 加载树 /// private void InitTreeMenu() { this.tvControlItem.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Text = "项目"; rootNode.ToolTip = "项目"; rootNode.NodeID = "0"; rootNode.Expanded = true; this.tvControlItem.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(); } //var hardTestReportItemSets = from x in Funs.DB.HJGL_View_CH_HardTestReportItemSet where x.HardTestReportId == null select x; string strR = @"SELECT DISTINCT JointInfo.ProjectId FROM dbo.HJGL_PW_JointInfo AS JointInfo LEFT JOIN dbo.HJGL_CH_HardTestReportItem AS ReportItem ON JointInfo.JOT_ID = ReportItem.JOT_ID WHERE ReportItem.IsShow=1 AND ReportItem.HardTestReportId IS NULL"; DataTable dt = SQLHelper.GetDataTableRunText(strR, null); foreach (var item in projects) { // var projectHardTestReportItemSets = hardTestReportItemSets.Where(x => x.ProjectId == item.ProjectId); TreeNode rootProjectNode = new TreeNode();//定义根节点 if (dt.Select("ProjectId='"+item.ProjectId+"'").Count()>0) { rootProjectNode.Text = "" + item.ProjectCode + ""; } else { rootProjectNode.Text = item.ProjectCode; } rootProjectNode.NodeID = item.ProjectId; rootProjectNode.ToolTip = item.ProjectName; rootProjectNode.CommandName = "项目名称"; rootProjectNode.EnableClickEvent = true; rootNode.Nodes.Add(rootProjectNode); } } #endregion protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e) { this.InitTreeMenu(); } #region 生成硬度检测报告 /// /// 生成硬度检测报告 /// /// /// protected void btnGenerating_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_HardReportSetMenuId, Const.BtnGenerate)) { int[] selections = Grid1.SelectedRowIndexArray; int i = 0; //检验数量 int flag = 0; //打印标记 JArray mergedData = Grid1.GetMergedData(); string jot_id = string.Empty, hardTestReportId = string.Empty, hardTestReportItemId = string.Empty, hardTestReportItemId2 = string.Empty, hardTestReportItemId3 = string.Empty, isoidLog = string.Empty, jointIdLog = string.Empty; List steCodes = new List(); foreach (JObject mergedRow in mergedData) { JObject values = mergedRow.Value("values"); int rowIndex = mergedRow.Value("index"); if (selections.Contains(rowIndex)) { steCodes.Add(values.Value("STE_Code").ToString()); } } if (steCodes.Distinct().Count() > 1) { ShowNotify("必须是相同材质的焊缝才能生成报告!", MessageBoxIcon.Warning); return; } foreach (JObject mergedRow in mergedData) { string status = mergedRow.Value("status"); JObject values = mergedRow.Value("values"); int rowIndex = mergedRow.Value("index"); if (selections.Contains(rowIndex)) { jot_id = Grid1.DataKeys[rowIndex][3].ToString(); hardTestReportItemId = Grid1.DataKeys[rowIndex][0].ToString(); hardTestReportItemId2 = Grid1.DataKeys[rowIndex][1].ToString(); hardTestReportItemId3 = Grid1.DataKeys[rowIndex][2].ToString(); Model.HJGL_PW_JointInfo joint = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(jot_id); Model.HJGL_PW_IsoInfo iso = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(joint.ISO_ID); if (isoidLog != joint.ISO_ID) //新管线的记录 { flag = 0; Model.HJGL_CH_HardTestReport oldHardTestReport = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(hardTestReportId); if (oldHardTestReport != null) //更新之前硬度检验报告的热处理状态和检验数量 { oldHardTestReport.HotProessState = "消应力热处理"; oldHardTestReport.TestCount = i; BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReport(oldHardTestReport); } i = 0; //检验数量清零 i++; //检验数量+1 isoidLog = joint.ISO_ID; hardTestReportId = SQLHelper.GetNewID(typeof(Model.HJGL_CH_HardTestReport)); //生成硬度委托及硬度检验报告记录 Model.HJGL_CH_HardTestReport hardTestReport = new Model.HJGL_CH_HardTestReport(); hardTestReport.HardTestReportId = hardTestReportId; hardTestReport.HardTestReportCode = BLL.SQLHelper.RunProcNewIdByProjectId("SpGetNewCodeByProjectId", "dbo.HJGL_CH_HardTestReport", "HardTestReportCode", joint.ProjectId, BLL.Base_ProjectService.GetProjectCode(joint.ProjectId) + "-"); hardTestReport.ProjectId = joint.ProjectId; hardTestReport.ISO_ID = iso.ISO_ID; hardTestReport.TestDate = DateTime.Now; hardTestReport.TrustUnitId = iso.BSU_ID; hardTestReport.TestStandard = "GB/T17394.1-2014"; hardTestReport.STE_ID = iso.STE_ID; Model.Project_Sys_Set equipment = BLL.Project_SysSetService.GetSysSetBySetId("6", joint.ProjectId); if (equipment != null) { hardTestReport.EquipmentId = equipment.SetValue; Model.HJGL_BS_Equipment eq = BLL.HJGL_EquipmentService.GetEquipmentById(equipment.SetValue); if (eq != null) { hardTestReport.InstrumentType = eq.EquipmentName; } } hardTestReport.ReportName = hardTestReport.HardTestReportCode + "-" + iso.ISO_IsoNo; //项目承包单位信息 hardTestReport.ContractUnit = "镇海石化建安工程有限公司"; hardTestReport.TestMethod = "里氏硬度"; hardTestReport.FileType = "R"; //硬度检测报告 BLL.HJGL_CH_HardTestReportService.AddCH_HardTestReport(hardTestReport); //回写焊口硬度委托时间 //BLL.HJGL_PW_JointInfoService.WriteBackHardTrustDate(jot_id, hardTestReport.TestDate); } else { i++; //检验数量+1 //回写焊口硬度委托时间 //BLL.HJGL_PW_JointInfoService.WriteBackHardTrustDate(jot_id, DateTime.Now); } //更新硬度报告明细信息 if (jointIdLog != jot_id) { jointIdLog = jot_id; flag++; //打印标记+1 } Model.HJGL_CH_HardTestReportItem item1 = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportItemByID(hardTestReportItemId); item1.HardTestReportId = hardTestReportId; item1.HardNessValue = Funs.GetNewInt(values.Value("HardNessValue1").ToString()); item1.Remark = values.Value("Remark").ToString(); item1.Flag = flag; BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReportItem(item1); Model.HJGL_CH_HardTestReportItem item2 = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportItemByID(hardTestReportItemId2); item2.HardTestReportId = hardTestReportId; item2.HardNessValue = Funs.GetNewInt(values.Value("HardNessValue2").ToString()); item2.Remark = values.Value("Remark").ToString(); item2.Flag = flag; BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReportItem(item2); Model.HJGL_CH_HardTestReportItem item3 = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportItemByID(hardTestReportItemId3); item3.HardTestReportId = hardTestReportId; item3.HardNessValue = Funs.GetNewInt(values.Value("HardNessValue3").ToString()); item3.Remark = values.Value("Remark").ToString(); item3.Flag = flag; BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReportItem(item3); if (flag == 3) //逢3重置标识 { flag = 0; } } } //更新之前硬度检验报告的热处理状态和检验数量 Model.HJGL_CH_HardTestReport oldHardTestReport2 = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(hardTestReportId); if (oldHardTestReport2 != null) { oldHardTestReport2.HotProessState = "消应力热处理"; oldHardTestReport2.TestCount = i; Model.HJGL_PW_IsoInfo iso = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(oldHardTestReport2.ISO_ID); if (iso != null) { oldHardTestReport2.ReportName = BLL.SQLHelper.RunProcNewIdByProjectId("SpGetNewCodeByProjectId", "dbo.HJGL_CH_HardTestReport", "ReportName", iso.ProjectId, BLL.Base_ProjectService.GetProjectCode(iso.ProjectId) + "-" + iso.ISO_IsoNo + "-"); } BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReport(oldHardTestReport2); } BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "生成硬度检测报告!"); ShowNotify("成功生成硬度检测报告!", MessageBoxIcon.Success); BindGrid(); } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); } } #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// protected void tvControlItem_NodeCommand(object sender, TreeCommandEventArgs e) { var isoList = (from x in Funs.DB.HJGL_PW_IsoInfo where x.ProjectId == this.tvControlItem.SelectedNodeID select new { x.ISO_ID, x.ISO_IsoNo }).Distinct(); this.drpIsoNo.Items.Clear(); this.drpIsoNo.DataSource = isoList; this.drpIsoNo.DataBind(); Funs.FineUIPleaseSelect(this.drpIsoNo); this.drpIsoNo.SelectedValue = BLL.Const._Null; this.BindGrid(); } #endregion /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } #region 数据绑定 #region 加载明细表信息 /// /// 数据绑定 /// private void BindGrid() { int[] selections = Grid1.SelectedRowIndexArray; foreach (int rowIndex in selections) { SelectList.Add(Grid1.DataKeys[rowIndex][0] + "," + Grid1.DataKeys[rowIndex][1]); } string strSql = @"select * from dbo.HJGL_View_CH_HardTestReportItemSet Item where Item.ProjectId=@ProjectId and HardTestReportId is null "; List listStr = new List(); listStr.Add(new SqlParameter("@ProjectId", this.tvControlItem.SelectedNodeID)); if (this.drpIsoNo.SelectedValue != BLL.Const._Null) { strSql += " AND Item.ISO_ID = @IsoId"; listStr.Add(new SqlParameter("@IsoId", this.drpIsoNo.SelectedValue)); } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; tb = GetFilteredTable(Grid1.FilteredData, tb); // 2.获取当前排序(如不分页要调用这个排序方法) //var table = this.GetSortTable(Grid1, tb); // 2.获取当前分页数据 var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #endregion #endregion #region 分页 /// /// 页索引改变事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } #endregion #region 分页选择下拉改变事件 /// /// 分页选择下拉改变事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { //Grid1.SortDirection = e.SortDirection; //Grid1.SortField = e.SortField; BindGrid(); } #endregion #region 提交事件 /// /// /// /// /// protected void btnSave_Click(object sender, EventArgs e) { JArray mergedData = Grid1.GetMergedData(); string jot_id = string.Empty, hardTestReportId = string.Empty, hardTestReportItemId = string.Empty, hardTestReportItemId2 = string.Empty, hardTestReportItemId3 = string.Empty, isoidLog = string.Empty, jointIdLog = string.Empty; foreach (JObject mergedRow in mergedData) { string status = mergedRow.Value("status"); JObject values = mergedRow.Value("values"); int rowIndex = mergedRow.Value("index"); jot_id = Grid1.DataKeys[rowIndex][3].ToString(); hardTestReportItemId = Grid1.DataKeys[rowIndex][0].ToString(); hardTestReportItemId2 = Grid1.DataKeys[rowIndex][1].ToString(); hardTestReportItemId3 = Grid1.DataKeys[rowIndex][2].ToString(); Model.HJGL_PW_JointInfo joint = BLL.HJGL_PW_JointInfoService.GetJointInfoByJotID(jot_id); Model.HJGL_PW_IsoInfo iso = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(joint.ISO_ID); Model.HJGL_CH_HardTestReportItem item1 = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportItemByID(hardTestReportItemId); item1.HardNessValue = Funs.GetNewInt(values.Value("HardNessValue1").ToString()); item1.Remark = values.Value("Remark").ToString(); BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReportItem(item1); Model.HJGL_CH_HardTestReportItem item2 = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportItemByID(hardTestReportItemId2); item2.HardNessValue = Funs.GetNewInt(values.Value("HardNessValue2").ToString()); item2.Remark = values.Value("Remark").ToString(); BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReportItem(item2); Model.HJGL_CH_HardTestReportItem item3 = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportItemByID(hardTestReportItemId3); item3.HardNessValue = Funs.GetNewInt(values.Value("HardNessValue3").ToString()); item3.Remark = values.Value("Remark").ToString(); BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReportItem(item3); } ShowNotify("提交成功!", MessageBoxIcon.Success); BindGrid(); } #endregion } }