using BLL; using Model; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace FineUIPro.Web.ZHGL.Supervise { public partial class UnitHazardRegisterEdit : PageBase { #region Fields private List items = new List(); #endregion Fields #region Properties public string UnitHazardRegisterId { get { return (string)ViewState["UnitHazardRegisterId"]; } set { ViewState["UnitHazardRegisterId"] = value; } } public string type { get { return (string)ViewState["type"]; } set { ViewState["type"] = value; } } #endregion Properties #region Methods protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // 获取 Type 参数 type = Request["type"] ?? "0"; btnClose.OnClientClick = ActiveWindow.GetHideReference(); InitDropList(); var unitModel = UnitService.GetUnitByUnitId(this.CurrUser.UnitId); var thisUnitId = BLL.CommonService.GetThisUnitId(); this.UnitHazardRegisterId = Request.Params["UnitHazardRegisterId"]; var register = BLL.UnitHazardRegisterService.GetUnitHazardRegisterById(this.UnitHazardRegisterId); if (register != null) {// 编辑模式 - 加载数据 this.txtUnitHazardRegisterCode.Text = register.UnitHazardRegisterCode; if (register.CheckDate != null) { this.dpkCheckDate.Text = string.Format("{0:yyyy-MM-dd}", register.CheckDate); } this.drpCheckMainType.SelectedValue = register.CheckMainType; if (!string.IsNullOrWhiteSpace(register.CheckType)) { BLL.SuperviseCheckTypeService.InitCheckTypeDropDownListByMainType(this.drpCheckType, register.CheckMainType, false); this.drpCheckType.SelectedValue = register.CheckType; } if (!string.IsNullOrWhiteSpace(register.CheckUnitId)) { this.ddlCheckUnitId.SelectedValue = register.CheckUnitId; } if (!string.IsNullOrWhiteSpace(register.InspectionUnit)) { this.ddlInspectionUnit.SelectedValue = register.InspectionUnit; if (register.InspectionUnit != thisUnitId) { this.ddlCheckUnitId.Readonly = true; } } if (!string.IsNullOrWhiteSpace(register.ProjectId)) { this.ddlProjectId.SelectedValue = register.ProjectId; this.ddlInsResponsibleUserId.Items.Clear(); BLL.UserService.InitUserDropDownList(this.ddlInsResponsibleUserId, this.ddlProjectId.SelectedValue, true, null); if (!string.IsNullOrWhiteSpace(register.InsResponsibleUserId)) { this.ddlInsResponsibleUserId.SelectedValue = register.InsResponsibleUserId; } } else { UserService.InitIsOfficeUserUnitIdDropDownList(this.ddlInsResponsibleUserId, this.ddlCheckUnitId.SelectedValue, true); if (!string.IsNullOrWhiteSpace(register.InsResponsibleUserId)) { this.ddlInsResponsibleUserId.SelectedValue = register.InsResponsibleUserId; } } this.txtCheckTeam.Text = register.CheckTeam; BindDetailGrid(); if (register.States > (int)UnitHazardRegisterService.StateInt.待提交) { btnImport.Hidden = true; btnAdd.Hidden = true; btnSave.Hidden = true; btnSubmit.Hidden = true; } } else {// 新增模式 if (unitModel?.IsBranch == true) { this.ddlInspectionUnit.SelectedValue = this.CurrUser.UnitId; this.ddlCheckUnitId.SelectedValue = this.CurrUser.UnitId; } else { this.ddlInspectionUnit.SelectedValue = thisUnitId; this.ddlCheckUnitId.SelectedValue = thisUnitId; } BLL.UserService.InitUserDropDownList(this.ddlInsResponsibleUserId, null, true, this.ddlCheckUnitId.SelectedValue); BLL.UserService.InitIsOfficeUserUnitIdDropDownList(this.ddlInsResponsibleUserId, this.ddlCheckUnitId.SelectedValue, true); BLL.ProjectService.InitProjectDropDownList(this.ddlProjectId, this.ddlCheckUnitId.SelectedValue, true);//检查项目 this.txtCheckTeam.Text = BLL.UnitService.GetUnitNameByUnitId(this.CurrUser.UnitId) + " " + this.CurrUser.UserName; this.dpkCheckDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); // 自动生成编号 int newCount = UnitHazardRegisterService.GetCount(type) + 1; this.txtUnitHazardRegisterCode.Text = newCount.ToString().PadLeft(5, '0'); } if (unitModel?.IsBranch == true) { this.ddlInspectionUnit.Readonly = true; this.ddlCheckUnitId.Readonly = true; } } } /// /// 绑定数据 /// private void BindDetailGrid() { if (string.IsNullOrEmpty(this.UnitHazardRegisterId)) { return; } // 加载明细 items = BLL.UnitHazardRegisterItemService.GetItemsByRegisterId(this.UnitHazardRegisterId) .Select(x => new View_UnitHazardRegisterItem { UnitHazardRegisterItemId = x.UnitHazardRegisterItemId, ProblemDescription = x.ProblemDescription, ProblemType = x.ProblemType, RiskLevel = x.RiskLevel, RectifyRequirement = x.RectifyRequirement, CompleteStatus = x.CompleteStatus, CompletedDate = x.CompletedDate }).ToList(); Grid1.DataSource = items; Grid1.DataBind(); } protected void InitDropList() { drpCheckMainType.SelectedValue = type; // 初始化下拉框 BLL.UnitService.InitBranchUnitDropDownList(this.ddlInspectionUnit, false);//检查单位 BLL.UnitService.InitBranchUnitDropDownList(this.ddlCheckUnitId, false);//受检单位 BLL.ProjectService.InitProjectDropDownList(this.ddlProjectId, ddlCheckUnitId.SelectedValue, true);//检查项目 //BLL.UserService.InitUserDropDownList(this.ddlInsResponsibleUserId, this.ddlProjectId.SelectedValue, true, null); BLL.SuperviseCheckTypeService.InitCheckTypeDropDownListByMainType(this.drpCheckType, type, false); if (type == "0") { this.drpProblemType.DataTextField = "RegisterTypesName"; this.drpProblemType.DataValueField = "RegisterTypesName"; this.drpProblemType.DataSource = BLL.HSSE_Hazard_HazardRegisterTypesService.GetHazardRegisterTypesList("1"); //安全巡检类型 this.drpProblemType.DataBind(); } else { QualityQuestionTypeService.InitQualityQuestionType(drpProblemType, false); } } protected void btnAdd_Click(object sender, EventArgs e) { JArray teamGroupData = Grid1.GetMergedData(); List list = new List(); foreach (JObject teamGroupRow in teamGroupData) { JObject values = teamGroupRow.Value("values"); values.Add("UnitHazardRegisterItemId", teamGroupRow.Value("id")); list.Add(values); } JObject defaultObj = new JObject { { "UnitHazardRegisterItemId",Guid.NewGuid() }, { "ProblemDescription", "" }, { "ProblemType", "" }, { "RiskLevel","一般"}, { "RectifyRequirement", "" }, { "Delete", String.Format("", GetDeleteScript(), IconHelper.GetResolvedIconUrl(Icon.Delete)) } }; list.Add(defaultObj); Grid1.DataSource = list; Grid1.DataBind(); } protected void btnSave_Click(object sender, EventArgs e) { if (this.drpCheckMainType.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择检查大类!", MessageBoxIcon.Warning); return; } if (this.drpCheckType.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择检查类别!", MessageBoxIcon.Warning); return; } if (this.ddlInspectionUnit.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择检查单位!", MessageBoxIcon.Warning); return; } if (this.ddlCheckUnitId.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择受检单位!", MessageBoxIcon.Warning); return; } //if (this.ddlProjectId.SelectedValue == BLL.Const._Null) //{ // Alert.ShowInTop("请选择检查对象!", MessageBoxIcon.Warning); // return; //} SaveNew(); SaveItem(); ShowNotify("保存成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } protected void btnSubmit_Click(object sender, EventArgs e) { if (this.drpCheckMainType.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择检查大类!", MessageBoxIcon.Warning); return; } if (this.drpCheckType.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择检查类别!", MessageBoxIcon.Warning); return; } if (this.ddlInspectionUnit.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择检查单位!", MessageBoxIcon.Warning); return; } if (this.ddlCheckUnitId.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择受检单位!", MessageBoxIcon.Warning); return; } //if (this.ddlProjectId.SelectedValue == BLL.Const._Null) //{ // Alert.ShowInTop("请选择检查对象!", MessageBoxIcon.Warning); // return; //} SaveNew(Const.BtnSubmit); SaveItem(); ShowNotify("提交成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } /// /// 检查单位下拉触发事件 /// /// /// protected void ddlInspectionUnit_SelectedIndexChanged(object sender, EventArgs e) { this.ddlProjectId.Items.Clear(); this.ddlInsResponsibleUserId.Items.Clear(); var inspectionUnit = this.ddlInspectionUnit.SelectedValue; this.ddlCheckUnitId.SelectedValue = inspectionUnit; BLL.ProjectService.InitProjectDropDownList(this.ddlProjectId, this.ddlCheckUnitId.SelectedValue, true); UserService.InitIsOfficeUserUnitIdDropDownList(this.ddlInsResponsibleUserId, this.ddlCheckUnitId.SelectedValue, true); if (inspectionUnit == CommonService.GetIsThisUnit().UnitId) { this.ddlCheckUnitId.Readonly = false; } else { this.ddlCheckUnitId.Readonly = true; } } /// /// 受检单位下拉触发事件 /// /// /// protected void ddlCheckUnitId_SelectedIndexChanged(object sender, EventArgs e) { this.ddlProjectId.Items.Clear(); this.ddlInsResponsibleUserId.Items.Clear(); BLL.ProjectService.InitProjectDropDownList(this.ddlProjectId, this.ddlCheckUnitId.SelectedValue, true); UserService.InitIsOfficeUserUnitIdDropDownList(this.ddlInsResponsibleUserId, this.ddlCheckUnitId.SelectedValue, true); } /// /// 受检项目下拉触发事件 /// /// /// protected void ddlProjectId_SelectedIndexChanged(object sender, EventArgs e) { this.ddlInsResponsibleUserId.Items.Clear(); //BLL.UnitService.InitUnitNameByProjectIdUnitTypeDropDownList(this.ddlUnitId, this.ddlProjectId.SelectedValue, Const.ProjectUnitType_1, true); BLL.UserService.InitUserDropDownList(this.ddlInsResponsibleUserId, this.ddlProjectId.SelectedValue, true, null); } /// /// 检查大类下拉触发事件 /// /// /// protected void drpCheckMainType_SelectedIndexChanged(object sender, EventArgs e) { BLL.SuperviseCheckTypeService.InitCheckTypeDropDownListByMainType(this.drpCheckType, this.drpCheckMainType.SelectedValue, false); } /// ///设置LinkButtonField的点击客户端事件 /// /// /// protected void Grid1_PreDataBound(object sender, EventArgs e) { // 设置LinkButtonField的点击客户端事件 LinkButtonField deleteField = Grid1.FindColumn("Delete") as LinkButtonField; deleteField.OnClientClick = GetDeleteScript(); var register = BLL.UnitHazardRegisterService.GetUnitHazardRegisterById(this.UnitHazardRegisterId); if (register != null && register.States > (int)UnitHazardRegisterService.StateInt.待提交) { LinkButtonField lbUpload = Grid1.FindColumn(6) as LinkButtonField; LinkButtonField lbDelete = Grid1.FindColumn(7) as LinkButtonField; lbUpload.Enabled = false; lbDelete.Enabled = false; } } protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { string itemId = Grid1.DataKeys[e.RowIndex][0].ToString(); string menuId = Request["type"] == "0" ? BLL.Const.UnitHazardRegisterMenu_Safety : BLL.Const.UnitHazardRegisterMenu_Quality; if (e.CommandName == "attchUrl") { PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?toKeyId={0}&path=FileUpload/UnitHazardRegister&menuId={1}&edit=1", itemId, menuId))); } } protected void SaveItem() { JArray teamGroupData = Grid1.GetMergedData(); foreach (JObject teamGroupRow in teamGroupData) { JObject values = teamGroupRow.Value("values"); Model.Supervise_UnitHazardRegisterItem registerItem = new Model.Supervise_UnitHazardRegisterItem { UnitHazardRegisterItemId = teamGroupRow.Value("id"), UnitHazardRegisterId = this.UnitHazardRegisterId, ProblemDescription = values.Value("ProblemDescription"), ProblemType = values.Value("ProblemType"), RiskLevel = values.Value("RiskLevel"), RectifyRequirement = values.Value("RectifyRequirement"), CompleteStatus = 0 }; if (UnitHazardRegisterItemService.GetUnitHazardRegisterItemById(registerItem.UnitHazardRegisterItemId) != null) { UnitHazardRegisterItemService.UpdateUnitHazardRegisterItem(registerItem); } else { BLL.UnitHazardRegisterItemService.AddUnitHazardRegisterItem(registerItem); } } } protected void SaveNew(string type = "") { Supervise_UnitHazardRegister register = new Supervise_UnitHazardRegister { UnitHazardRegisterCode = this.txtUnitHazardRegisterCode.Text.Trim(), CheckDate = Funs.GetNewDateTime(this.dpkCheckDate.Text.Trim()), CheckMainType = this.drpCheckMainType.SelectedValue, CheckType = this.drpCheckType.SelectedValue, InspectionUnit = this.ddlInspectionUnit.SelectedValue, //ProjectId = this.ddlProjectId.SelectedValue, CheckUnitId = this.ddlCheckUnitId.SelectedValue, InsResponsibleUserId = this.ddlInsResponsibleUserId.SelectedValue, CheckTeam = this.txtCheckTeam.Text.Trim(), CompileMan = this.CurrUser.UserId, States = (int)UnitHazardRegisterService.StateInt.待提交 }; if (!string.IsNullOrEmpty(this.ddlProjectId.SelectedValue) && this.ddlProjectId.SelectedValue != Const._Null) { register.ProjectId = this.ddlProjectId.SelectedValue; } if (!string.IsNullOrEmpty(type)) { register.States = (int)UnitHazardRegisterService.StateInt.待整改; } if (string.IsNullOrWhiteSpace(this.UnitHazardRegisterId)) { // 新增 register.UnitHazardRegisterId = SQLHelper.GetNewID(typeof(Supervise_UnitHazardRegister)); this.UnitHazardRegisterId = register.UnitHazardRegisterId; BLL.UnitHazardRegisterService.AddUnitHazardRegister(register); // 增加一条编码记录 BLL.CodeRecordsService.InsertCodeRecordsByMenuIdProjectIdUnitId( BLL.Const.UnitHazardRegisterMenu_Safety, register.ProjectId, null, register.UnitHazardRegisterId, register.CheckDate); } else { // 更新 register.UnitHazardRegisterId = this.UnitHazardRegisterId; BLL.UnitHazardRegisterService.UpdateUnitHazardRegister(register); } } protected void Window1_Close(object sender, WindowCloseEventArgs e) { // 刷新Grid数据 items = BLL.UnitHazardRegisterItemService.GetItemsByRegisterId(this.UnitHazardRegisterId) .Select(x => new View_UnitHazardRegisterItem { UnitHazardRegisterItemId = x.UnitHazardRegisterItemId, ProblemDescription = x.ProblemDescription, ProblemType = x.ProblemType, RiskLevel = x.RiskLevel, RectifyRequirement = x.RectifyRequirement, CompleteStatus = x.CompleteStatus, CompletedDate = x.CompletedDate }).ToList(); Grid1.DataSource = items; Grid1.DataBind(); } protected void WindowAtt_Close(object sender, WindowCloseEventArgs e) { // 刷新Grid数据 JArray teamGroupData = Grid1.GetMergedData(); List list = new List(); foreach (JObject teamGroupRow in teamGroupData) { JObject values = teamGroupRow.Value("values"); values.Add("UnitHazardRegisterItemId", teamGroupRow.Value("id")); list.Add(values); } Grid1.DataSource = list; Grid1.DataBind(); } /// /// 删除提示 /// /// private string GetDeleteScript() { return Confirm.GetShowReference("删除选中行?", String.Empty, MessageBoxIcon.Question, Grid1.GetDeleteSelectedRowsReference(), String.Empty); } #endregion Methods #region 导入 /// /// 导入按钮 /// /// /// protected void btnImport_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.UnitHazardRegisterId)) { SaveNew(); } PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("UnitHazardRegisterDetailIn.aspx?Type={0}&UnitHazardRegisterId={1}", type, this.UnitHazardRegisterId, "导入 - "))); } /// /// 关闭导入弹出窗口 /// /// /// protected void Window2_Close(object sender, WindowCloseEventArgs e) { BindDetailGrid(); } #endregion } /// /// 企业级检查明细视图类 /// public class View_UnitHazardRegisterItem { #region Properties public DateTime? CompletedDate { get; set; } public int? CompleteStatus { get; set; } public string ProblemDescription { get; set; } public string ProblemImageUrl { get; set; } public string ProblemType { get; set; } public string RectifyRequirement { get; set; } public string RiskLevel { get; set; } public string UnitHazardRegisterItemId { get; set; } #endregion Properties } }