using BLL; using FineUIPro.Web.BaseInfo; using FineUIPro.Web.SysManage; using Microsoft.Win32; using Model; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; 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(); 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.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; } } if (!string.IsNullOrWhiteSpace(register.CheckUnitId)) { this.ddlCheckUnitId.SelectedValue = register.CheckUnitId; } this.txtCheckTeam.Text = register.CheckTeam; // 加载明细 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(); if (register.States> (int)UnitHazardRegisterService.StateInt.待提交) { btnAdd.Hidden = true; btnSave.Hidden = true; btnSubmit.Hidden = true; } } else { // 新增模式 var unitModel = UnitService.GetUnitByUnitId(this.CurrUser.UnitId); if (unitModel?.IsBranch == true) { this.ddlCheckUnitId.SelectedValue = this.CurrUser.UnitId; } else { var thisUnit = BLL.CommonService.GetIsThisUnit(); this.ddlCheckUnitId.SelectedValue = thisUnit.UnitId; } 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'); } Grid1.DataSource = items; Grid1.DataBind(); } } protected void InitDropList() { drpCheckMainType.SelectedValue = type; // 初始化下拉框 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.ddlProjectId.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择检查对象!", MessageBoxIcon.Warning); return; } if (this.ddlCheckUnitId.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.ddlProjectId.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择检查对象!", MessageBoxIcon.Warning); return; } if (this.ddlCheckUnitId.SelectedValue == BLL.Const._Null) { Alert.ShowInTop("请选择检查单位!", MessageBoxIcon.Warning); return; } SaveNew(Const.BtnSubmit); SaveItem(); ShowNotify("提交成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } protected void ddlCheckUnitId_SelectedIndexChanged(object sender, EventArgs e) { this.ddlProjectId.Items.Clear(); this.ddlInsResponsibleUserId.Items.Clear(); BLL.ProjectService.InitProjectDropDownList(this.ddlProjectId,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); } /// /// /// /// /// 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, 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(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 } /// /// 企业级检查明细视图类 /// 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 } }