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.HotHardManage { public partial class HardTestReportEdit : PageBase { #region 定义项 /// /// 硬度检测报告主键 /// public string HardTestReportId { get { return (string)ViewState["HardTestReportId"]; } set { ViewState["HardTestReportId"] = value; } } /// /// 项目主键 /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.HardTestReportId = Request.Params["HardTestReportId"]; ///材质 this.ddlSTE.DataTextField = "STE_Code"; this.ddlSTE.DataValueField = "STE_ID"; this.ddlSTE.DataSource = BLL.HJGL_MaterialService.GetSteelList(); this.ddlSTE.DataBind(); Funs.FineUIPleaseSelect(this.ddlSTE); var trust = Funs.DB.HJGL_View_CH_HardTestReport.FirstOrDefault(x => x.HardTestReportId == this.HardTestReportId); if (trust != null) { this.ProjectId = trust.ProjectId; } var pUnit = BLL.Base_UnitService.GetUnitsByProjectUnitType(this.ProjectId, BLL.Const.UnitType_4); if (pUnit != null) { this.drpUnit.DataTextField = "UnitName"; this.drpUnit.DataValueField = "UnitId"; this.drpUnit.DataSource = pUnit; this.drpUnit.DataBind(); } this.drpEquipment.DataTextField = "EquipmentName"; this.drpEquipment.DataValueField = "EquipmentId"; this.drpEquipment.DataSource = BLL.HJGL_EquipmentService.GetEquipmentList(); this.drpEquipment.DataBind(); Funs.FineUIPleaseSelect(this.drpEquipment); this.PageInfoLoad(); ///加载页面 this.BindGrid(); ////初始化页面 if (!string.IsNullOrEmpty(Request.Params["type"])) { this.btnSave.Hidden = true; //this.ckSelect.Hidden = true; } } } #endregion #region 加载页面输入提交信息 /// /// 加载页面输入提交信息 /// private void PageInfoLoad() { var trust = Funs.DB.HJGL_View_CH_HardTestReport.FirstOrDefault(x => x.HardTestReportId == this.HardTestReportId); if (trust != null) { this.ProjectId = trust.ProjectId; this.txtHardTestReportCode.Text = trust.HardTestReportCode; if (!string.IsNullOrEmpty(trust.TrustUnitId)) { this.drpUnit.SelectedValue = trust.TrustUnitId; } if (!string.IsNullOrEmpty(trust.ISO_ID)) { Model.HJGL_PW_IsoInfo isoInfo = BLL.HJGL_PW_IsoInfoService.GetIsoInfoByIsoInfoId(trust.ISO_ID); if (isoInfo != null) { this.txtIsoNo.Text = isoInfo.ISO_IsoNo; this.txtIsoNo2.Text = isoInfo.ISO_IsoNo; Model.HJGL_BS_Steel steel = BLL.HJGL_MaterialService.GetSteelBySteID(isoInfo.STE_ID); if (steel != null) { this.ddlSTE.SelectedValue = isoInfo.STE_ID; this.txtMaterialStandard.Text = steel.HardQuaStandard; } Model.HJGL_BS_Steel steel2 = BLL.HJGL_MaterialService.GetSteelBySteID(trust.STE_ID); if (steel2 != null) { this.ddlSTE.SelectedValue = trust.STE_ID; this.txtMaterialStandard.Text = steel2.HardQuaStandard; } } } this.txtContractUnit.Text = trust.ContractUnit; this.txtHotProessState.Text = trust.HotProessState; if (!string.IsNullOrEmpty(trust.TestMethod)) { this.txtTestMethod.Text = trust.TestMethod; } else { this.txtTestMethod.Text = "里氏硬度"; } this.txtTestStandard.Text = trust.TestStandard; if (!string.IsNullOrEmpty(trust.MaterialStandard)) { this.txtMaterialStandard.Text = trust.MaterialStandard; } if (!string.IsNullOrEmpty(trust.EquipmentId)) { this.drpEquipment.SelectedValue = trust.EquipmentId; } if (trust.TestCount != null) { this.txtTestCount.Text = trust.TestCount.ToString(); } } else { this.SimpleForm1.Reset(); ///重置所有字段 } } /// /// 材质下拉选择事件 /// /// /// protected void ddlSTE_SelectedIndexChanged(object sender, EventArgs e) { if (this.ddlSTE.SelectedValue != BLL.Const._Null) { var ste = BLL.HJGL_MaterialService.GetSteelBySteID(this.ddlSTE.SelectedValue); if (ste != null) { this.txtMaterialStandard.Text = ste.HardQuaStandard; } else { this.txtMaterialStandard.Text = string.Empty; } } else { this.txtMaterialStandard.Text = string.Empty; } } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindGrid() { List q = (from x in Funs.DB.HJGL_View_CH_HardTestReportItem where x.ProjectId == this.ProjectId && x.HardTestReportId == this.HardTestReportId select x).ToList(); DataTable tb = this.LINQToDataTable(q); // 2.获取当前分页数据 //var table = this.GetPagedDataTable(GridNewDynamic, tb1); Grid1.RecordCount = tb.Rows.Count; tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { this.CollectGridJointInfo(); this.BindGrid(); } #endregion #region 硬度检测报告 提交事件 /// /// 编辑硬度检测报告 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.HJGL_HardTestReportMenuId, Const.BtnSave)) { Model.HJGL_CH_HardTestReport newHardTestReport = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(this.HardTestReportId); if (newHardTestReport != null) { if (this.ddlSTE.SelectedValue == BLL.Const._Null) { ShowNotify("请选择检件牌号!", MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(this.txtMaterialStandard.Text.Trim())) { ShowNotify("被检验材料标准不能为空!", MessageBoxIcon.Warning); return; } if (this.drpUnit.SelectedValue != BLL.Const._Null) { newHardTestReport.TrustUnitId = this.drpUnit.SelectedValue; } newHardTestReport.STE_ID = this.ddlSTE.SelectedValue; newHardTestReport.ContractUnit = this.txtContractUnit.Text; newHardTestReport.SurfaceAppearance = this.txtSurfaceAppearance.Text; newHardTestReport.TestMethod = this.txtTestMethod.Text.Trim(); newHardTestReport.TestStandard = this.txtTestStandard.Text.Trim(); newHardTestReport.MaterialStandard = this.txtMaterialStandard.Text.Trim(); if (this.drpEquipment.SelectedValue != BLL.Const._Null) { newHardTestReport.EquipmentId = this.drpEquipment.SelectedValue; } newHardTestReport.TestRate = this.txtTestRate.Text.Trim(); newHardTestReport.TestCount = Funs.GetNewIntOrZero(this.txtTestCount.Text.Trim()); BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReport(newHardTestReport); BLL.Sys_LogService.AddLog(BLL.Const.System_3, newHardTestReport.ProjectId, this.CurrUser.UserId, "修改硬度检测报告信息"); } BLL.HJGL_CH_HardTestReportService.DeleteCH_HardTestReportItemByCH_HardTestReportID(this.HardTestReportId); this.CollectGridJointInfo(); ShowNotify("提交成功!", MessageBoxIcon.Success); if (string.IsNullOrEmpty(Request.Params["Report"])) { PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(newHardTestReport.HardTestReportId) + ActiveWindow.GetHidePostBackReference()); } else { PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } } else { ShowNotify("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } #endregion #region 收集Grid页面信息,提交明细 /// /// 收集Grid页面信息,提交明细 /// /// private void CollectGridJointInfo() { Model.HJGL_CH_HardTestReport newHardTestReport = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(this.HardTestReportId); JArray mergedData = Grid1.GetMergedData(); string jotId= mergedData[0].Value("values").Value("JOT_ID").ToString(); //int flag = 1; foreach (JObject mergedRow in mergedData) { Model.HJGL_CH_HardTestReportItem item1 = new Model.HJGL_CH_HardTestReportItem(); Model.HJGL_CH_HardTestReportItem item2 = new Model.HJGL_CH_HardTestReportItem(); Model.HJGL_CH_HardTestReportItem item3 = new Model.HJGL_CH_HardTestReportItem(); string status = mergedRow.Value("status"); JObject values = mergedRow.Value("values"); int rowIndex = mergedRow.Value("index"); item1.HardTestReportItemId = values.Value("HardTestReportItemId").ToString(); item1.HardTestReportId = this.HardTestReportId; item1.JOT_ID = values.Value("JOT_ID").ToString(); //if (item1.JOT_ID != jotId) //{ // flag++; // if (flag > 3) // { // flag = 1; // } // jotId = item1.JOT_ID; //} item1.SortIndex = Funs.GetNewIntOrZero(values.Value("SortIndex").ToString()); item1.Flag = Funs.GetNewIntOrZero(values.Value("Flag").ToString()); //if (values.Value("Flag") != null) //{ // item1.Flag = flag; //} //else //{ // item1.Flag = Funs.GetNewIntOrZero(values.Value("Flag").ToString()); //} if (values.Value("IsShow").ToString() == "True") { item1.IsShow = true; } item1.TestPart = values.Value("TestPart").ToString(); item1.HardNessValue = Funs.GetNewInt(values.Value("HardNessValue1").ToString()); item1.Remark = values.Value("Remark").ToString(); item1.HotProessTrustId = values.Value("HotProessTrustId").ToString(); BLL.HJGL_CH_HardTestReportService.AddCH_HardTestReportItem(item1); item2.HardTestReportItemId = SQLHelper.GetNewID(typeof(Model.HJGL_CH_HardTestReportItem)); item2.HardTestReportId = this.HardTestReportId; item2.JOT_ID = values.Value("JOT_ID").ToString(); item2.SortIndex = Funs.GetNewIntOrZero(values.Value("SortIndex").ToString()); item2.Flag = Funs.GetNewIntOrZero(values.Value("Flag").ToString()); //if (values.Value("Flag") != null) //{ // item2.Flag = flag; //} //else //{ // item2.Flag = Funs.GetNewIntOrZero(values.Value("Flag").ToString()); //} item2.TestPart = values.Value("TestPart").ToString(); item2.HardNessValue = Funs.GetNewInt(values.Value("HardNessValue2").ToString()); item2.IsShow = false; item2.Remark = values.Value("Remark").ToString(); item2.HotProessTrustId = values.Value("HotProessTrustId").ToString(); BLL.HJGL_CH_HardTestReportService.AddCH_HardTestReportItem(item2); item3.HardTestReportItemId = SQLHelper.GetNewID(typeof(Model.HJGL_CH_HardTestReportItem)); item3.HardTestReportId = this.HardTestReportId; item3.JOT_ID = values.Value("JOT_ID").ToString(); item3.SortIndex = Funs.GetNewIntOrZero(values.Value("SortIndex").ToString()); item3.Flag = Funs.GetNewIntOrZero(values.Value("Flag").ToString()); //if (values.Value("Flag") != null) //{ // item3.Flag = flag; //} //else //{ // item3.Flag = Funs.GetNewIntOrZero(values.Value("Flag").ToString()); //} item3.TestPart = values.Value("TestPart").ToString(); item3.HardNessValue = Funs.GetNewInt(values.Value("HardNessValue3").ToString()); item3.IsShow = null; item3.Remark = values.Value("Remark").ToString(); item3.HotProessTrustId = values.Value("HotProessTrustId").ToString(); BLL.HJGL_CH_HardTestReportService.AddCH_HardTestReportItem(item3); //回写焊口硬度委托时间 BLL.HJGL_PW_JointInfoService.WriteBackHardTrustDate(item1.JOT_ID, newHardTestReport.TestDate); } } #endregion #region Grid 关闭弹出窗口事件 /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { List list = Funs.GetStrListByStr(hdItemsString.Text, '|'); this.BindGrid(); this.hdItemsString.Text = string.Empty; } #endregion #region 右键删除事件 /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { var items = BLL.HJGL_CH_HardTestReportService.GetView_CH_HardTestReportItemByCH_HardTestReportID(this.HardTestReportId); foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); Model.HJGL_View_CH_HardTestReportItem item = items.FirstOrDefault(x => x.HardTestReportItemId == rowID); if (item.HardNessValue1.HasValue || item.HardNessValue2.HasValue || item.HardNessValue3.HasValue) { ShowNotify("硬度检验报告已录入数据,无法删除!", MessageBoxIcon.Warning); return; } else { Model.SGGLDB db = Funs.DB; var deleteItems = Funs.DB.HJGL_CH_HardTestReportItem.Where(x => x.JOT_ID == item.JOT_ID && x.TestPart == item.TestPart && x.SortIndex == item.SortIndex); db.HJGL_CH_HardTestReportItem.DeleteAllOnSubmit(deleteItems); db.SubmitChanges(); } } BindGrid(); ShowNotify("操作完成!", MessageBoxIcon.Success); } } #endregion /// /// 整行清空硬度值 /// /// /// protected void btnClearRow_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { BLL.HJGL_CH_HardTestReportService.DeleteCH_HardTestReportItemByCH_HardTestReportID(this.HardTestReportId); CollectGridJointInfo(); foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string id = this.Grid1.Rows[rowIndex].DataKeys[0].ToString(); List list = new List(); Model.HJGL_CH_HardTestReportItem item = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportItemByID(id); var other2Items = (from x in Funs.DB.HJGL_CH_HardTestReportItem where x.JOT_ID == item.JOT_ID && x.TestPart == item.TestPart && x.SortIndex == item.SortIndex && x.Flag == item.Flag select x).ToList(); list.Add(item); list.AddRange(other2Items); foreach (var l in list) { l.HardNessValue = null; l.Remark = null; Funs.DB.SubmitChanges(); } } BindGrid(); } else { ShowNotify("请选择要清空的行!", MessageBoxIcon.Warning); } } } }