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 HotHardManageItemEdit : 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 = "EquipmentCode"; 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; } } } #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.txtHotHardCode.Text = trust.HotHardCode; 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) { 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; } } } if (!string.IsNullOrEmpty(trust.STE_ID)) { Model.HJGL_BS_Steel steel = BLL.HJGL_MaterialService.GetSteelBySteID(trust.STE_ID); if (steel != null) { this.ddlSTE.SelectedValue = trust.STE_ID; this.txtMaterialStandard.Text = steel.HardQuaStandard; } } if (trust.TestDate != null) { this.txtTestDate.Text = string.Format("{0:yyyy-MM-dd}", trust.TestDate); } this.txtInstrumentType.Text = trust.InstrumentType; if (!string.IsNullOrEmpty(trust.EquipmentId)) { this.drpEquipment.SelectedValue = trust.EquipmentId; } if (string.IsNullOrEmpty(trust.TestStandard)) { this.txtTestStandard.Text = "GB/T17394.1-2014"; } else { this.txtTestStandard.Text = trust.TestStandard; } } else { this.SimpleForm1.Reset(); ///重置所有字段 this.txtTestDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); } } /// /// 材质下拉选择事件 /// /// /// 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_HotHardManageEditMenuId, 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; } newHardTestReport.STE_ID = this.ddlSTE.SelectedValue; newHardTestReport.HotHardCode = this.txtHotHardCode.Text.Trim(); newHardTestReport.ProjectId = this.ProjectId; if (this.drpUnit.SelectedValue != BLL.Const._Null) { newHardTestReport.TrustUnitId = this.drpUnit.SelectedValue; } //newHardTestReport.TestDate = Funs.GetNewDateTime(this.txtTestDate.Text.Trim()); newHardTestReport.TestDate = DateTime.Now; newHardTestReport.InstrumentType = this.txtInstrumentType.Text.Trim(); if (this.drpEquipment.SelectedValue != BLL.Const._Null) { newHardTestReport.EquipmentId = this.drpEquipment.SelectedValue; } newHardTestReport.TestStandard = this.txtTestStandard.Text.Trim(); BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReport(newHardTestReport); BLL.Sys_LogService.AddLog(BLL.Const.System_3, newHardTestReport.ProjectId, this.CurrUser.UserId, "修改硬度委托信息"); } //else //{ // this.HardTestReportId = SQLHelper.GetNewID(typeof(Model.HJGL_CH_HardTestReport)); // newHardTestReport.HardTestReportId = this.HardTestReportId; // BLL.HJGL_CH_HardTestReportService.AddCH_HardTestReport(newHardTestReport); // BLL.Sys_LogService.AddLog(BLL.Const.System_3, this.CurrUser.LoginProjectId, 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() { for (int i = 0; i < Grid1.Rows.Count; i++) { } } #endregion //#region 管线查询 ///// ///// 管线查询 ///// ///// ///// //protected void txtIsono_OnSelectedIndexChanged(object sender, EventArgs e) //{ // this.CollectGridJointInfo(); // this.BindGrid(); //} //#endregion //#region 只显示选中项 ///// ///// 只显示选中项 ///// ///// ///// //protected void ckSelect_OnCheckedChanged(object sender, CheckedEventArgs e) //{ // this.CollectGridJointInfo(); // this.BindGrid(); //} //#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 drpEquipment_SelectedIndexChanged(object sender, EventArgs e) { if (this.drpEquipment.SelectedValue != BLL.Const._Null) { Model.HJGL_BS_Equipment equipment = BLL.HJGL_EquipmentService.GetEquipmentById(this.drpEquipment.SelectedValue); if (equipment != null) { this.txtInstrumentType.Text = equipment.EquipmentName; } } else { this.txtInstrumentType.Text = string.Empty; } } } }