/// <summary>
 /// 从服务端下载配置应用到本地
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void barBtnItem_getFromServer_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     try
     {
         //判断服务器是否存在报警配置
         SettingInfo dto;
         dto = ClientAlarmServer.CheckAlarmConfigIsOnServer();
         if (dto == null || string.IsNullOrEmpty(dto.StrValue))
         {
             Sys.Safety.ClientFramework.View.Message.DevMessageBox.Show(Sys.Safety.ClientFramework.View.Message.DevMessageBox.MessageType.Information, "服务器上未发现配置文件,操作已取消。");
             return;
         }
         //从服务器下载配置到本地
         if (!ClientAlarmConfig.DownloadConfigFromServer())
         {
             Sys.Safety.ClientFramework.View.Message.DevMessageBox.Show(Sys.Safety.ClientFramework.View.Message.DevMessageBox.MessageType.Information, "服务器上未发现配置文件,操作已取消。");
             return;
         }
         //从本地配置加载到缓存
         ClientAlarmConfig.LoadConfigToCache();
         gridCtrl.DataSource             = null;
         lookUpEditDefProperty.EditValue = null;
         lookUpEditDefCalss.EditValue    = null;
         textEditDefPoint.EditValue      = null;
         bIsChangeType  = false;
         bIsChangeAlarm = false;
         LookupLoadData();
         Sys.Safety.ClientFramework.View.Message.DevMessageBox.Show(Sys.Safety.ClientFramework.View.Message.DevMessageBox.MessageType.Information, "从服务端下载配置应用到本地成功");
     }
     catch (Exception ex)
     {
         LogHelper.Error(ex);
     }
 }
        /// <summary>
        /// 保存当前报警配置到本地
        /// </summary>
        /// <returns></returns>
        private bool SaveToLocal()
        {
            bool b = false;

            try
            {
                if (InvalidGridDataBeforeSave())
                {
                    if (ClientAlarmConfig.SaveConfig(iFlag, gridCtrl.DataSource as List <ClientAlarmItems>))
                    {
                        ClientAlarmConfigCache.IsUsePopupAlarm  = this.chkIsUsePopupAlarm.Checked;
                        ClientAlarmConfigCache.IsUseAlarmConfig = this.chk_IsUseAlarmCfg.Checked;
                        ClientAlarmConfig.SaveOtherAlarmSwitch();

                        ClientAlarmConfig.LoadConfigToCache();
                        Sys.Safety.ClientFramework.View.Message.DevMessageBox.Show(Sys.Safety.ClientFramework.View.Message.DevMessageBox.MessageType.Information, "保存报警设置成功");
                        b = true;
                    }
                    else
                    {
                        Sys.Safety.ClientFramework.View.Message.DevMessageBox.Show(Sys.Safety.ClientFramework.View.Message.DevMessageBox.MessageType.Information, "保存报警设置失败");
                    }
                    //性质、种类、测点发生改变时
                    bIsChangeType  = false;
                    bIsChangeAlarm = false;
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(b);
        }
        public static IList <EnumcodeInfo> GetListEnumState()
        {
            IList <EnumcodeInfo> list = null;

            try
            {
                if (ClientAlarmConfig.getsererconnectstate())
                {
                    var request = new EnumcodeGetByEnumTypeIDRequest()
                    {
                        EnumTypeId = "4"
                    };
                    var response = enumcodeService.GetEnumcodeByEnumTypeID(request);
                    if (response.Data != null)
                    {
                        list = response.Data;
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(list);
        }
        public static List <ShowDataInfo> GetReleaseAlarmRecords(long id)
        {
            List <ShowDataInfo> list = new List <ShowDataInfo>();

            try
            {
                if (ClientAlarmConfig.getsererconnectstate())
                {
                    var request = new GetReleaseAlarmRecordsRequest()
                    {
                        Id = id
                    };
                    var response = alarmService.GetReleaseAlarmRecords(request);
                    if (response.Data != null)
                    {
                        list = response.Data;
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("ClientAlarmModle-GetReleaseAlarmRecords-发生异常 " + ex.Message);
            }
            return(list);
        }
        public static IList <Jc_DefInfo> QueryPointByDevpropertIDCache(int DevPropertID)
        {
            IList <Jc_DefInfo> list = null;

            try
            {
                if (ClientAlarmConfig.getsererconnectstate())
                {
                    var requst = new QueryPointByDevpropertRequest()
                    {
                        DevPropertId = DevPropertID
                    };
                    var response = alarmService.QueryPointByDevpropertIDCache(requst);
                    if (response.Data != null)
                    {
                        list = response.Data;
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(list);
        }
        public static Dictionary <int, EnumcodeInfo> QueryDevClassByDevpropertID(int DevPropertyID)
        {
            Dictionary <int, EnumcodeInfo> list = new Dictionary <int, EnumcodeInfo>();

            try
            {
                if (ClientAlarmConfig.getsererconnectstate())
                {
                    var request = new QueryDevClassByDevpropertRequest()
                    {
                        DevPropertId = DevPropertyID
                    };
                    var response = alarmService.QueryDevClassByDevpropertId(request);
                    if (response.Data != null)
                    {
                        list = response.Data;
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(list);
        }
        public static SettingInfo CheckAlarmConfigIsOnServer()
        {
            SettingInfo dto = new SettingInfo();

            try
            {
                if (ClientAlarmConfig.getsererconnectstate())
                {
                    var request = new GetSettingByKeyRequest()
                    {
                        StrKey = "AlarmShowConfig"
                    };
                    var response = settingService.GetSettingByKey(request);
                    if (response.Data != null)
                    {
                        dto = response.Data;
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(dto);
        }
        /// <summary>
        /// 保存配置到服务器,先保存到本地,再保存到数据库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barBtnItem_saveServer_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                //增加权限验证  20171011
                bool blnHaveRight = ClientPermission.Authorize("SaveAlarmConfigInServer");
                if (!blnHaveRight)
                {
                    Sys.Safety.ClientFramework.View.Message.DevMessageBox.Show(Sys.Safety.ClientFramework.View.Message.DevMessageBox.MessageType.Information, "当前用户无操作权限!");
                    return;
                }

                if (!InvalidGridDataBeforeSave())
                {
                    return;
                }
                //先保存报警配置到本地文件
                if (!ClientAlarmConfig.SaveConfig(iFlag, gridCtrl.DataSource as List <ClientAlarmItems>))
                {
                    Sys.Safety.ClientFramework.View.Message.DevMessageBox.Show(Sys.Safety.ClientFramework.View.Message.DevMessageBox.MessageType.Information, "保存报警设置到服务器失败");
                    return;
                }
                ClientAlarmConfigCache.IsUseAlarmConfig = this.chk_IsUseAlarmCfg.Checked;
                ClientAlarmConfigCache.IsUsePopupAlarm  = this.chkIsUsePopupAlarm.Checked;
                ClientAlarmConfig.SaveOtherAlarmSwitch();

                ClientAlarmConfig.LoadConfigToCache();

                //再保存到服务器数据库
                bool b = ClientAlarmConfig.SaveConfigToServer();
                //性质、种类、测点发生改变时
                bIsChangeType  = false;
                bIsChangeAlarm = false;
                if (b)
                {
                    Sys.Safety.ClientFramework.View.Message.DevMessageBox.Show(Sys.Safety.ClientFramework.View.Message.DevMessageBox.MessageType.Information, "保存报警设置到服务器成功");
                }
                else
                {
                    Sys.Safety.ClientFramework.View.Message.DevMessageBox.Show(Sys.Safety.ClientFramework.View.Message.DevMessageBox.MessageType.Information, "保存报警设置到服务器失败");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
        }
        public static string GetDBType()
        {
            string str = "";

            try
            {
                if (ClientAlarmConfig.getsererconnectstate())
                {
                    str = Basic.Framework.Configuration.Global.DatabaseType.GetEnumDescription();
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(str);
        }
        public static DateTime GetMaxTimeFromJCR()
        {
            DateTime dtm = new DateTime();

            try
            {
                if (ClientAlarmConfig.getsererconnectstate())
                {
                    var response = alarmService.GetMaxTimeFromJCR();
                    dtm = response.Data;
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("ClientAlarmModle-GetMaxID-发生异常 " + ex.Message);
            }
            return(dtm);
        }
        public static long GetMaxID()
        {
            long maxID = 0;

            try
            {
                if (ClientAlarmConfig.getsererconnectstate())
                {
                    var response = alarmService.GetMaxId();
                    maxID = response.Data;
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("ClientAlarmModle-GetMaxID-发生异常 " + ex.Message);
            }
            return(maxID);
        }
        public static string GetDevDefineChangeDatetime()
        {
            string str = "";

            try
            {
                if (ClientAlarmConfig.getsererconnectstate())
                {
                    var response = realMessageService.GetDefineChangeFlg();
                    str = response.Data;
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(str);
        }
        private void LookupLoadData()
        {
            try
            {
                this.repositoryItemCheckedComboBoxEdit1.DataSource = GetAlarmShow();
                this.lookUpEditDefProperty.Properties.DataSource   = ClientAlarmServer.GetListEnumProperty();

                ClientAlarmConfig.LoadConfigToCache();

                this.chk_IsUseAlarmCfg.Checked  = ClientAlarmConfigCache.IsUseAlarmConfig;
                this.chkIsUsePopupAlarm.Checked = ClientAlarmConfigCache.IsUsePopupAlarm;

                this.lookUpEditDefProperty.ItemIndex = 0;
            }
            catch (Exception ex)
            {
                LogHelper.Error("加载设备性质发生异常 " + ex.Message);
            }
        }
        public static List <EnumcodeInfo> GetListEnumProperty()
        {
            List <EnumcodeInfo> list = new List <EnumcodeInfo>();

            try
            {
                if (ClientAlarmConfig.getsererconnectstate())
                {
                    var response = alarmService.GetListEnumPropert();
                    if (response.Data != null)
                    {
                        list = response.Data;
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(list);
        }
        public static bool SaveConfigToDatabase(SettingInfo dto, string s)
        {
            bool flg = false;

            try
            {
                if (ClientAlarmConfig.getsererconnectstate())
                {
                    var request = new SaveConfigToDatabaseRequest();
                    request.SettingInfo = dto;
                    request.Config      = s;
                    var response = alarmService.SaveConfigToDatabase(request);
                    flg = response.Data;
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(flg);
        }