334 lines
		
	
	
		
			14 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			334 lines
		
	
	
		
			14 KiB
		
	
	
	
		
			C#
		
	
	
	
using BLL;
 | 
						|
using Model;
 | 
						|
using Newtonsoft.Json.Linq;
 | 
						|
using RestSharp.Extensions;
 | 
						|
using System;
 | 
						|
using System.Collections.Generic;
 | 
						|
using System.Linq;
 | 
						|
using System.Web;
 | 
						|
using System.Web.UI;
 | 
						|
using System.Web.UI.WebControls;
 | 
						|
 | 
						|
namespace FineUIPro.Web.ZHGL.DataSync
 | 
						|
{
 | 
						|
    public partial class SYHSEData_DataEdit : PageBase
 | 
						|
    {
 | 
						|
        #region  
 | 
						|
        /// <summary>
 | 
						|
        /// 主键
 | 
						|
        /// </summary>
 | 
						|
        public string Id
 | 
						|
        {
 | 
						|
            get
 | 
						|
            {
 | 
						|
                return (string)ViewState["Id"];
 | 
						|
            }
 | 
						|
            set
 | 
						|
            {
 | 
						|
                ViewState["Id"] = value;
 | 
						|
            }
 | 
						|
        }
 | 
						|
        #endregion
 | 
						|
        protected void Page_Load(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            if (!IsPostBack)
 | 
						|
            {
 | 
						|
                this.btnClose.OnClientClick = ActiveWindow.GetHideReference();
 | 
						|
                ////权限按钮方法
 | 
						|
                this.GetButtonPower();
 | 
						|
                this.Id = Request.Params["Id"];
 | 
						|
                BLL.Base_FactoryService.InitBase_FactoryDownList(DropFactory, true);
 | 
						|
                if (!string.IsNullOrEmpty(this.Id))
 | 
						|
                {
 | 
						|
                  //  Model.SYHSEData_Data model = BLL.SYHSEData_DataService.GetSYHSEData_DataById(this.Id);
 | 
						|
 | 
						|
                    Model.SYHSEData_Data model = BLL.SYHSEData_DataService.GetSYHSEData_DataById(this.Id);
 | 
						|
                    if (model != null)
 | 
						|
                    {
 | 
						|
                        //this.txtUnitId.Text = model.UnitId;
 | 
						|
                        if (!string.IsNullOrEmpty(model.FactoryId))
 | 
						|
                        {
 | 
						|
                            DropFactory.SelectedValue=model.FactoryId;
 | 
						|
 | 
						|
                        }
 | 
						|
                        if (model.ReportDate != null)
 | 
						|
                        {
 | 
						|
                            this.txtReportDate.SelectedDate = model.ReportDate;
 | 
						|
                        }
 | 
						|
                        if (model.SafetyMnaHours.HasValue)
 | 
						|
                        {
 | 
						|
                            this.txtSafetyMnaHours.Text = model.SafetyMnaHours.Value.ToString();
 | 
						|
                        }
 | 
						|
                        if (model.GeneralRiskNum.HasValue)
 | 
						|
                        {
 | 
						|
                            this.txtGeneralRiskNum.Text = model.GeneralRiskNum.Value.ToString();
 | 
						|
                        }
 | 
						|
                        if (model.LowRiskNum.HasValue)
 | 
						|
                        {
 | 
						|
                            this.txtLowRiskNum.Text = model.LowRiskNum.Value.ToString();
 | 
						|
                        }
 | 
						|
                        if (model.MoreRiskNum.HasValue)
 | 
						|
                        {
 | 
						|
                            this.txtMoreRiskNum.Text = model.MoreRiskNum.Value.ToString();
 | 
						|
                        }
 | 
						|
                        if (model.GreatRiskNum.HasValue)
 | 
						|
                        {
 | 
						|
                            this.txtGreatRiskNum.Text = model.GreatRiskNum.Value.ToString();
 | 
						|
                        }
 | 
						|
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                else
 | 
						|
                {
 | 
						|
                    txtReportDate.SelectedDate = DateTime.Now;
 | 
						|
 | 
						|
                }
 | 
						|
                BindGrid();
 | 
						|
                #region Grid1
 | 
						|
                // 删除选中单元格的客户端脚本
 | 
						|
                string deleteScript_Realtimedevice = GetDeleteScript_Realtimedevice();
 | 
						|
                string deleteScript_Hidden = GetDeleteScript_Hidden();
 | 
						|
                string deleteScript_Risk = GetDeleteScript_Risk();
 | 
						|
 | 
						|
                JObject defaultObj_Realtimedevice = new JObject
 | 
						|
                {
 | 
						|
                    { "HazardName", "" },
 | 
						|
                    { "HazardLevel", "" },
 | 
						|
                    { "DeviceName", "" },
 | 
						|
                    { "Medium", "" },
 | 
						|
                    { "MeasurementUnit", "" },
 | 
						|
                    { "DateTime", "" },
 | 
						|
                    { "Value", "" }
 | 
						|
                };
 | 
						|
                // 在第一行新增一条数据
 | 
						|
                btnNew_Realtimedevice.OnClientClick = Grid_Realtimedevice.GetAddNewRecordReference(defaultObj_Realtimedevice, true);
 | 
						|
                // 删除选中行按钮
 | 
						|
                btnDelete_Realtimedevice.OnClientClick = Grid_Realtimedevice.GetNoSelectionAlertReference("请选择一条记录!") + deleteScript_Realtimedevice;
 | 
						|
 | 
						|
                JObject defaultObj_Hidden = new JObject
 | 
						|
                {
 | 
						|
                    { "HiddenDangerName", "" },
 | 
						|
                    { "TotalNum", "" },
 | 
						|
                    { "OKNum", "" }
 | 
						|
                };
 | 
						|
                // 在第一行新增一条数据
 | 
						|
                btnNew_Hidden.OnClientClick = Grid_Hidden.GetAddNewRecordReference(defaultObj_Hidden, true);
 | 
						|
                // 删除选中行按钮
 | 
						|
                btnDelete_Hidden.OnClientClick = Grid_Hidden.GetNoSelectionAlertReference("请选择一条记录!") + deleteScript_Hidden;
 | 
						|
 | 
						|
                JObject defaultObj_Risk = new JObject
 | 
						|
                {
 | 
						|
                    { "RiskControlName", "" }
 | 
						|
                };
 | 
						|
                // 在第一行新增一条数据
 | 
						|
                btnNew_Risk.OnClientClick = Grid_Risk.GetAddNewRecordReference(defaultObj_Risk, true);
 | 
						|
                // 删除选中行按钮
 | 
						|
                btnDelete_Risk.OnClientClick = Grid_Risk.GetNoSelectionAlertReference("请选择一条记录!") + deleteScript_Risk;
 | 
						|
 | 
						|
 | 
						|
                #endregion
 | 
						|
 | 
						|
            }
 | 
						|
        }
 | 
						|
        /// <summary>
 | 
						|
        /// 保存按钮
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="sender"></param>
 | 
						|
        /// <param name="e"></param>
 | 
						|
        protected void btnSave_Click(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            if (txtReportDate.SelectedDate == null)
 | 
						|
            {
 | 
						|
 | 
						|
                ShowNotify("请选择上报日期!");
 | 
						|
                return;
 | 
						|
 | 
						|
            }
 | 
						|
            if (DropFactory.SelectedValue==Const._Null)
 | 
						|
            {
 | 
						|
 | 
						|
                ShowNotify("请选择实业!");
 | 
						|
                return;
 | 
						|
 | 
						|
            }
 | 
						|
            Model.SYHSEData_Data table = new Model.SYHSEData_Data();
 | 
						|
            table.FactoryId = this.DropFactory.SelectedValue;
 | 
						|
            table.ReportDate = this.txtReportDate.SelectedDate;
 | 
						|
            table.SafetyMnaHours = Funs.GetNewInt(this.txtSafetyMnaHours.Text);
 | 
						|
            table.GeneralRiskNum = Funs.GetNewInt(this.txtGeneralRiskNum.Text);
 | 
						|
            table.LowRiskNum = Funs.GetNewInt(this.txtLowRiskNum.Text);
 | 
						|
            table.MoreRiskNum = Funs.GetNewInt(this.txtMoreRiskNum.Text);
 | 
						|
            table.GreatRiskNum = Funs.GetNewInt(this.txtGreatRiskNum.Text);
 | 
						|
            if (string.IsNullOrEmpty(this.Id))
 | 
						|
            {
 | 
						|
                table.Id = SQLHelper.GetNewID(typeof(Model.SYHSEData_Data));
 | 
						|
                BLL.SYHSEData_DataService.AddSYHSEData_Data(table);
 | 
						|
 | 
						|
            }
 | 
						|
            else
 | 
						|
            {
 | 
						|
                table.Id = this.Id;
 | 
						|
                BLL.SYHSEData_DataService.UpdateSYHSEData_Data(table);
 | 
						|
            }
 | 
						|
 | 
						|
            BLL.HazardRealtimedeviceService.DeleteHazard_RealTimeDeviceByDate(table.ReportDate);
 | 
						|
            JArray EditorArr_Realtimedevice = Grid_Realtimedevice.GetMergedData();
 | 
						|
            if (EditorArr_Realtimedevice.Count > 0)
 | 
						|
            {
 | 
						|
                Model.Hazard_RealTimeDevice defect = new Model.Hazard_RealTimeDevice();
 | 
						|
 | 
						|
                for (int i = 0; i < EditorArr_Realtimedevice.Count; i++)
 | 
						|
                {
 | 
						|
                    JObject objects = (JObject)EditorArr_Realtimedevice[i];
 | 
						|
                    defect.ID = SQLHelper.GetNewID(typeof(Model.Hazard_RealTimeDevice));
 | 
						|
                    defect.ReportDate = table.ReportDate;
 | 
						|
                    defect.FactoryId = DropFactory.SelectedValue;
 | 
						|
                    defect.HazardName = objects["values"]["HazardName"].ToString();
 | 
						|
                    defect.HazardLevel = objects["values"]["HazardLevel"].ToString();
 | 
						|
                    defect.DeviceName = objects["values"]["DeviceName"].ToString();
 | 
						|
                    defect.Medium = objects["values"]["Medium"].ToString();
 | 
						|
                    defect.MeasurementUnit = objects["values"]["MeasurementUnit"].ToString();
 | 
						|
                    defect.Value = objects["values"]["Value"].ToString();
 | 
						|
                    defect.DateTime =DateTime.Parse(objects["values"]["DateTime"].ToString()) ;
 | 
						|
                    //defect.HazardLevel = Funs.GetNewInt(objects["values"]["HazardLevel"].ToString());
 | 
						|
                    
 | 
						|
                    BLL.HazardRealtimedeviceService.AddHazard_RealTimeDevice(defect);
 | 
						|
                }
 | 
						|
            }
 | 
						|
 | 
						|
 | 
						|
 | 
						|
            BLL.SyhsedataHiddendangercheckService.DeleteSYHSEData_HiddenDangerCheckByDate(table.ReportDate);
 | 
						|
            JArray EditorArr_Hidden = Grid_Hidden.GetMergedData();
 | 
						|
            if (EditorArr_Hidden.Count > 0)
 | 
						|
            {
 | 
						|
                Model.SYHSEData_HiddenDangerCheck defect = new Model.SYHSEData_HiddenDangerCheck();
 | 
						|
 | 
						|
                for (int i = 0; i < EditorArr_Hidden.Count; i++)
 | 
						|
                {
 | 
						|
                    JObject objects = (JObject)EditorArr_Hidden[i];
 | 
						|
                    defect.Id = SQLHelper.GetNewID(typeof(Model.SYHSEData_HiddenDangerCheck));
 | 
						|
                    defect.ReportDate = table.ReportDate;
 | 
						|
                    defect.FactoryId = DropFactory.SelectedValue;
 | 
						|
                    defect.HiddenDangerName = objects["values"]["HiddenDangerName"].ToString();
 | 
						|
                    defect.TotalNum = Funs.GetNewInt(objects["values"]["TotalNum"].ToString());
 | 
						|
                    defect.OKNum = Funs.GetNewInt(objects["values"]["OKNum"].ToString());
 | 
						|
 | 
						|
                    BLL.SyhsedataHiddendangercheckService.AddSYHSEData_HiddenDangerCheck(defect);
 | 
						|
                }
 | 
						|
            }
 | 
						|
 | 
						|
 | 
						|
 | 
						|
            BLL.SyhsedataRiskcontrolService.DeleteSYHSEData_RiskControlByDate(table.ReportDate);
 | 
						|
            JArray EditorArr_Risk = Grid_Risk.GetMergedData();
 | 
						|
            if (EditorArr_Risk.Count > 0)
 | 
						|
            {
 | 
						|
                Model.SYHSEData_RiskControl defect = new Model.SYHSEData_RiskControl();
 | 
						|
 | 
						|
                for (int i = 0; i < EditorArr_Risk.Count; i++)
 | 
						|
                {
 | 
						|
                    JObject objects = (JObject)EditorArr_Risk[i];
 | 
						|
                    defect.Id = SQLHelper.GetNewID(typeof(Model.SYHSEData_RiskControl));
 | 
						|
                    defect.ReportDate = table.ReportDate;
 | 
						|
                    defect.FactoryId = DropFactory.SelectedValue;
 | 
						|
                    defect.RiskControlName = objects["values"]["RiskControlName"].ToString();
 | 
						|
                    BLL.SyhsedataRiskcontrolService.AddSYHSEData_RiskControl(defect);
 | 
						|
                }
 | 
						|
            }
 | 
						|
            PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
 | 
						|
        }
 | 
						|
 | 
						|
 | 
						|
        private void BindGrid()
 | 
						|
        {
 | 
						|
            if (!string.IsNullOrEmpty(this.Id))
 | 
						|
            {
 | 
						|
                Model.SYHSEData_Data model = BLL.SYHSEData_DataService.GetSYHSEData_DataById(this.Id);
 | 
						|
                if (model != null)
 | 
						|
                {
 | 
						|
                    var dt_Realtimedevice = BLL.HazardRealtimedeviceService.GetHazard_RealTimeDeviceByDate(model.ReportDate);
 | 
						|
                    Grid_Realtimedevice.RecordCount = dt_Realtimedevice.Count;
 | 
						|
                    Grid_Realtimedevice.DataSource = dt_Realtimedevice;
 | 
						|
                    Grid_Realtimedevice.DataBind();
 | 
						|
 | 
						|
                    var dt_Hidden= SyhsedataHiddendangercheckService.GetSYHSEData_HiddenDangerCheckByDate(model.ReportDate);
 | 
						|
                    Grid_Hidden.RecordCount = dt_Hidden.Count;
 | 
						|
                    Grid_Hidden.DataSource = dt_Hidden;
 | 
						|
                    Grid_Hidden.DataBind();
 | 
						|
 | 
						|
                    var dt_Risk = SyhsedataRiskcontrolService.GetSYHSEData_RiskControlByDate(model.ReportDate);
 | 
						|
                    Grid_Risk.RecordCount = dt_Risk.Count;
 | 
						|
                    Grid_Risk.DataSource = dt_Risk;
 | 
						|
                    Grid_Risk.DataBind();
 | 
						|
                }
 | 
						|
 | 
						|
            }
 | 
						|
 | 
						|
        }
 | 
						|
        protected void txtReportDate_DateSelect(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            if (txtReportDate.SelectedDate != null)
 | 
						|
            {
 | 
						|
                DateTime dt = (DateTime)txtReportDate.SelectedDate;
 | 
						|
                if (BLL.SYHSEData_DataService.IsReportByDate(dt))
 | 
						|
                {
 | 
						|
                    txtReportDate.SelectedDate = null;
 | 
						|
                    ShowNotify("该日期已上报!");
 | 
						|
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
        protected void btnSyn_Click(object sender, EventArgs e)
 | 
						|
        {
 | 
						|
            if (!string.IsNullOrEmpty(this.Id))
 | 
						|
            {
 | 
						|
                var responedata = SYHSEData_DataService.PushCNCEC(Id);
 | 
						|
                if (responedata.code == 1)
 | 
						|
                {
 | 
						|
                    ShowNotify("上报成功!");
 | 
						|
                    PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
 | 
						|
 | 
						|
                }
 | 
						|
                else
 | 
						|
                {
 | 
						|
                    ShowNotify(responedata.message);
 | 
						|
                    // PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
 | 
						|
                }
 | 
						|
 | 
						|
            }
 | 
						|
 | 
						|
 | 
						|
        }
 | 
						|
        private string GetDeleteScript_Realtimedevice()
 | 
						|
        {
 | 
						|
            return Confirm.GetShowReference("确定删除当前数据吗?", String.Empty, MessageBoxIcon.Question, Grid_Realtimedevice.GetDeleteSelectedRowsReference(), String.Empty);
 | 
						|
        }
 | 
						|
        private string GetDeleteScript_Hidden()
 | 
						|
        {
 | 
						|
            return Confirm.GetShowReference("确定删除当前数据吗?", String.Empty, MessageBoxIcon.Question, Grid_Hidden.GetDeleteSelectedRowsReference(), String.Empty);
 | 
						|
        }
 | 
						|
        private string GetDeleteScript_Risk()
 | 
						|
        {
 | 
						|
            return Confirm.GetShowReference("确定删除当前数据吗?", String.Empty, MessageBoxIcon.Question, Grid_Risk.GetDeleteSelectedRowsReference(), String.Empty);
 | 
						|
        }
 | 
						|
        #region 获取按钮权限
 | 
						|
        /// <summary>
 | 
						|
        /// 获取按钮权限
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="button"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        private void GetButtonPower()
 | 
						|
        {
 | 
						|
            var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.SYHSEData_DataMenuId);
 | 
						|
            if (buttonList.Count() > 0)
 | 
						|
            {
 | 
						|
                if (buttonList.Contains(BLL.Const.BtnSave))
 | 
						|
                {
 | 
						|
                    this.btnSave.Hidden = false;
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
        #endregion
 | 
						|
    }
 | 
						|
} |