예제 #1
0
 /// <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);
     }
 }
예제 #2
0
        /// <summary>
        /// 从服务端下载报警配置到本地
        /// </summary>
        /// <returns></returns>
        public static bool DownloadConfigFromServer()
        {
            bool b = false;

            try
            {
                SettingInfo dto = ClientAlarmServer.CheckAlarmConfigIsOnServer();
                if (!string.IsNullOrEmpty(dto.StrValue))
                {
                    byte[] by     = Convert.FromBase64String(dto.StrValue);
                    Stream stream = File.Open(_filePath, FileMode.Create, FileAccess.ReadWrite);
                    using (stream)
                    {
                        stream.Write(by, 0, by.Length);
                        stream.Close();
                    }
                    b = true;
                }
            }
            catch (Exception ex)
            {
                b = false;
                //写日志、抛异常
                LogHelper.Error("从服务端下载报警配置到本地 发生异常", ex);
            }
            return(b);
        }
예제 #3
0
        /// <summary>
        /// 保存报警配置文件到数据库
        /// </summary>
        /// <returns></returns>
        public static bool SaveConfigToServer()
        {
            bool   b = true;
            string s = string.Empty;

            try
            {
                if (File.Exists(_filePath))
                {
                    Stream stream = File.Open(_filePath, FileMode.Open);
                    using (stream)
                    {
                        byte[] by = new byte[stream.Length];
                        stream.Read(by, 0, (int)stream.Length);
                        s = Convert.ToBase64String(by);
                    }
                    SettingInfo dto = ClientAlarmServer.CheckAlarmConfigIsOnServer();
                    if (!ClientAlarmServer.SaveConfigToDatabase(dto, s))
                    {
                        b = false;
                    }
                }
            }
            catch (Exception ex)
            {
                //写日志、抛异常等
                LogHelper.Error("保存报警配置文件到数据库 发生异常", ex);
                b = false;
            }
            return(b);
        }
예제 #4
0
        /// <summary>
        /// 服务端上下文中设备定义是否发生变化(通过对比客户端设备定义时间和服务端上下文设备定义时间来判断)
        /// </summary>
        /// <returns></returns>
        public bool bIsDevChange()
        {
            bool b = false;

            try
            {
                string TempTime = ClientAlarmServer.GetDevDefineChangeDatetime();
                if (!string.IsNullOrEmpty(TempTime))
                {
                    DateTime dtmTemp = dtmLast;
                    DateTime.TryParse(TempTime, out dtmTemp);

                    if (dtmLast != dtmTemp)//20151028 txy
                    {
                        b       = true;
                        dtmLast = dtmTemp;
                    }
                }
                else
                {
                    b = false;
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("bIsDevChange-发生异常 " + ex.Message);
                b = false;
            }
            return(b);
        }
예제 #5
0
        private void gridControl1_MouseDown(object sender, MouseEventArgs e)
        {
            GridHitInfo hInfo = gridView1.CalcHitInfo(new Point(e.X, e.Y));

            if (e.Button == MouseButtons.Left && e.Clicks == 2)
            {
                //判断光标是否在行范围内
                if (hInfo.InRow)
                {
                    SensorCalibrationDetail dig = new SensorCalibrationDetail();
                    dig.ShowDialog();
                    if (dig.isSave)
                    {
                        string csStr = dig.csStr;

                        //var alarmId = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "id");
                        //if (alarmId != null)
                        //{

                        //    ClientAlarmServer.UpdateCalibrationRecord(alarmId.ToString(), csStr);
                        //}
                        //else
                        //{
                        Jc_BxexInfo bxInfo = new Jc_BxexInfo();

                        bxInfo.ID      = IdHelper.CreateLongId().ToString();
                        bxInfo.PointID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "pointid").ToString();
                        bxInfo.Point   = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Point").ToString();
                        ClientItem clientItem = new ClientItem();
                        if (Basic.Framework.Data.PlatRuntime.Items.ContainsKey(KeyConst.ClientItemKey))
                        {
                            clientItem = Basic.Framework.Data.PlatRuntime.Items[KeyConst.ClientItemKey] as ClientItem;
                        }
                        bxInfo.Name  = clientItem.UserName;
                        bxInfo.Stime = dig.stime;
                        bxInfo.Etime = dig.etime;
                        bxInfo.Cx    = (int)(dig.etime - dig.stime).TotalSeconds;
                        bxInfo.Zdz   = 0;
                        bxInfo.Zxz   = 0;
                        bxInfo.Pjz   = 0;

                        bxInfo.Zdztime = dig.etime;
                        bxInfo.Zxztime = dig.etime;
                        bxInfo.Bxzt    = 3;
                        bxInfo.Cs      = dig.csStr;

                        ClientAlarmServer.InsertCalibrationRecord(bxInfo);
                        // }
                    }
                }
            }
        }
예제 #6
0
        /// <summary>
        /// 刷新加载Grid的数据源
        /// </summary>
        /// <param name="sProperty">性质代码</param>
        /// <param name="col">(性质)显示名称</param>
        /// <returns></returns>
        private static IList <ClientAlarmItems> GetDataGrid(string sProperty, string col)
        {
            IList <ClientAlarmItems> list = new List <ClientAlarmItems>();

            try
            {
                DataTable dt = ClientAlarmServer.GetAlarmTypeDataByProperty(sProperty, col);
                list = ObjectConverter.Copy <ClientAlarmItems>(dt);
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(list);
        }
예제 #7
0
        private void lookUpEditDefProperty_EditValueChanged(object sender, EventArgs e)
        {
            try
            {
                //根据性质选择联动种类、测点数据源
                object oProperty = lookUpEditDefProperty.EditValue;
                if (oProperty == null || string.IsNullOrEmpty(oProperty.ToString()))
                {
                    lookUpEditDefCalss.EditValue             = null;
                    lookUpEditDefCalss.Properties.DataSource = null;
                    textEditDefPoint.EditValue             = null;
                    textEditDefPoint.Properties.DataSource = null;
                    devlookUpEdit.EditValue             = null;
                    devlookUpEdit.Properties.DataSource = null;
                    gridCtrl.DataSource = null;
                    return;
                }
                //性质、种类、测点发生改变时
                bIsChangeType = true;
                //DataTable dt = new ClientAlarmServer().GetClassByProperty(oProperty.ToString());
                this.lookUpEditDefCalss.EditValue             = null;
                this.lookUpEditDefCalss.Properties.DataSource = ClientAlarmServer.GetDevClassByDevpropertyID(int.Parse(oProperty.ToString()));
                //联动设备类型
                this.devlookUpEdit.EditValue             = null;
                this.devlookUpEdit.Properties.DataSource = ClientAlarmServer.GetDevByProperty(int.Parse(oProperty.ToString()));
                //联动测点数据源,即根据性质找测点
                this.textEditDefPoint.EditValue             = null;
                this.textEditDefPoint.Properties.DataSource = ClientAlarmServer.GetPointByDevPropertyID(int.Parse(oProperty.ToString()));

                iFlag = 1;
                //根据选择的性质,展示该性质的报警类型,设置该性质的各报警类型对应的报警方式
                IList <ClientAlarmItems> list = Basic.Framework.Common.JSONHelper.ParseJSONString <List <ClientAlarmItems> >
                                                    (Basic.Framework.Common.JSONHelper.ToJSONString(ClientAlarmConfigCache.listProperty.FindAll(a => a.code == oProperty.ToString())));
                if (list == null || list.Count < 1)
                {
                    this.gridCtrl.DataSource = GetDataGrid(oProperty.ToString(), lookUpEditDefProperty.Text);
                }
                else
                {
                    this.gridCtrl.DataSource = list;
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
        }
예제 #8
0
        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);
            }
        }
예제 #9
0
 private void devlookUpEdit_EditValueChanged(object sender, EventArgs e)
 {
     try
     {
         //根据种类的选择联动测点数据源
         object oClass = this.devlookUpEdit.EditValue;
         if (devlookUpEdit.EditValue != null)
         {
             iFlag = 4;
         }
         else
         {
             return;
         }
         //else if (lookUpEditDefCalss.EditValue != null) { iFlag = 2; }
         //else { iFlag = 1; }
         //性质、种类、测点发生改变时
         bIsChangeType = true;
         //再根据种类,于Grid中展示该种类所有的测点
         //从数据库加载所有的该种类的测点,然后结合该性质的报警类型,作为Grid的数据源
         string name = "";
         string code = "";
         List <ClientAlarmItems>  listAll = new List <ClientAlarmItems>();;
         IList <ClientAlarmItems> Ilist   = null;
         switch (iFlag)
         {
         //case 1://性质
         //    name = lookUpEditDefProperty.Text;
         //    code = lookUpEditDefProperty.EditValue.ToString();
         //    listAll = DeepClone(ClientAlarmConfigCache.listProperty) as List<ClientAlarmItems>;
         //    Ilist = listAll.FindAll(a => a.code == code);
         //    if (Ilist == null || Ilist.Count < 1)
         //    {
         //        Ilist = GetDataGrid(code, name);//最后从枚举数据中找
         //    }
         //    this.textEditDefPoint.EditValue = null;
         //    this.textEditDefPoint.Properties.DataSource = ClientAlarmServer.GetPointByDevPropertyID(int.Parse(code));
         //    break;
         //case 2://种类
         //    name = lookUpEditDefCalss.Text;
         //    code = lookUpEditDefCalss.EditValue.ToString();
         //    listAll = DeepClone(ClientAlarmConfigCache.listClass) as List<ClientAlarmItems>;//先找当前种类的报警配置
         //    Ilist = listAll.FindAll(a => a.code == code);
         //    if (Ilist == null || Ilist.Count < 1)
         //    {
         //        Ilist = gridCtrl.DataSource as List<ClientAlarmItems>;
         //        if (Ilist == null || Ilist.Count < 1) { return; }
         //        for (int i = 0; i < Ilist.Count; i++)
         //        {
         //            Ilist[i].code = code;
         //            Ilist[i].name = name;
         //            Ilist[i].alarmShow = "";
         //        }
         //    }
         //    this.textEditDefPoint.EditValue = null;
         //    this.textEditDefPoint.Properties.DataSource = ClientAlarmServer.GetPointByDevClassID(int.Parse(code));
         //    break;
         case 4:
             name    = devlookUpEdit.Text;
             code    = devlookUpEdit.EditValue.ToString();
             listAll = DeepClone(ClientAlarmConfigCache.listDev) as List <ClientAlarmItems>;
             Ilist   = listAll.FindAll(a => a.code == code);
             if (Ilist == null || Ilist.Count < 1)
             {
                 Ilist = gridCtrl.DataSource as List <ClientAlarmItems>;
                 if (Ilist == null || Ilist.Count < 1)
                 {
                     return;
                 }
                 for (int i = 0; i < Ilist.Count; i++)
                 {
                     Ilist[i].code      = code;
                     Ilist[i].name      = name;
                     Ilist[i].alarmShow = "";
                 }
             }
             this.textEditDefPoint.EditValue             = null;
             this.textEditDefPoint.Properties.DataSource = ClientAlarmServer.GetPointByDevID(int.Parse(code));
             break;
         }
         this.gridCtrl.DataSource = Ilist;
         this.gridCtrl.RefreshDataSource();
     }
     catch (Exception ex)
     {
         LogHelper.Error(ex);
     }
 }
예제 #10
0
        private void GetCalibrationDue()
        {
            try
            {
                List <EnumcodeInfo>            enumcodeInfos = new List <EnumcodeInfo>();
                EnumcodeInfo                   enumcodeInfo;
                EnumcodeGetByEnumTypeIDRequest enumcoderequest = new EnumcodeGetByEnumTypeIDRequest();
                enumcoderequest.EnumTypeId = "3";
                var result = enumcodeService.GetEnumcodeByEnumTypeID(enumcoderequest);
                if (result.IsSuccess & result.Data != null)
                {
                    enumcodeInfos = result.Data;
                }


                //获取设备类型及测点定义基础数据
                if (deviceDefineList.Count == 0 || bIsDevChange())
                {
                    deviceDefineList = deviceDefineService.GetAllDeviceDefineCache().Data;
                    pointDefineList  = pointDefineService.GetAllPointDefineCache().Data;
                }
                GetRealDataRequest request = new GetRealDataRequest();
                realDataList = realMessageService.GetRealData(request).Data;

                //标效及传感器到期提醒

                //查询近90天内的标效记录(统计前一天,及之前90天的记录)
                DateTime  startTime         = DateTime.Parse(DateTime.Now.AddDays(-91).ToShortDateString());
                DateTime  endTime           = DateTime.Parse(DateTime.Now.ToShortDateString() + " 23:59:59");
                DataTable calibrationRecord = ClientAlarmServer.GetCalibrationRecord(startTime, endTime);
                //按设备类型循环获取未标校、到期的传感器数量
                int NoCalibrationCount = 0;
                int DueCount           = 0;
                foreach (Jc_DevInfo dev in deviceDefineList)
                {
                    //2018.5.9 by AI
                    enumcodeInfo = enumcodeInfos.FirstOrDefault(a => a.LngEnumValue == dev.Bz4);
                    if (enumcodeInfo == null)
                    {
                        //LogHelper.Error("【GetCalibrationDue】枚举中未找到设备:" + dev.Bz4);
                        continue;
                    }
                    int tempCalibrationTime = 0;
                    int.TryParse(dev.Pl4.ToString(), out tempCalibrationTime);//标校周期
                    List <Jc_DefInfo> pointList = pointDefineList.FindAll(a => a.Devid == dev.Devid);
                    if (tempCalibrationTime > 0)
                    {
                        #region 标效周期报警
                        //计算当前设备类型下面的传感器是否到标效期
                        foreach (Jc_DefInfo def in pointList)
                        {
                            DataRow[] dr = calibrationRecord.Select("point='" + def.Point + "' and stime<='" + endTime + "'", "stime desc");
                            if (dr.Length > 0)
                            {
                                TimeSpan ts = endTime - DateTime.Parse(dr[0]["stime"].ToString());
                                if ((int)ts.TotalDays >= tempCalibrationTime)//如果上一次标校记录时间超过了设置的标校时间周期,则记入未标校数量
                                {
                                    NoCalibrationCount++;

                                    SensorCalibrationInfo tempSensorCalibrationInfo = new SensorCalibrationInfo();
                                    tempSensorCalibrationInfo.Point               = def.Point;
                                    tempSensorCalibrationInfo.Position            = def.Wz;
                                    tempSensorCalibrationInfo.DevName             = def.DevName;
                                    tempSensorCalibrationInfo.SetCalibrationTime  = tempCalibrationTime.ToString();
                                    tempSensorCalibrationInfo.LastCalibrationTime = dr[0]["stime"].ToString();
                                    tempSensorCalibrationInfo.CalibrationDays     = ((int)(ts.TotalDays)).ToString();
                                    tempSensorCalibrationInfo.id      = dr[0]["id"].ToString();
                                    tempSensorCalibrationInfo.pointid = def.PointID;
                                    if (ClientAlarmServer.sensorCalibrationInfoList.Find(a => a.Point == tempSensorCalibrationInfo.Point) == null)
                                    {
                                        ClientAlarmServer.sensorCalibrationInfoList.Add(tempSensorCalibrationInfo);
                                    }
                                }
                                else
                                {
                                    int index = ClientAlarmServer.sensorCalibrationInfoList.FindIndex(a => a.Point == def.Point);
                                    if (index >= 0)
                                    {
                                        ClientAlarmServer.sensorCalibrationInfoList.RemoveAt(index);
                                    }
                                }
                            }
                            else//未找到标校记录,则直接记入未标校
                            {
                                NoCalibrationCount++;

                                SensorCalibrationInfo tempSensorCalibrationInfo = new SensorCalibrationInfo();
                                tempSensorCalibrationInfo.Point               = def.Point;
                                tempSensorCalibrationInfo.Position            = def.Wz;
                                tempSensorCalibrationInfo.DevName             = def.DevName;
                                tempSensorCalibrationInfo.SetCalibrationTime  = tempCalibrationTime.ToString();
                                tempSensorCalibrationInfo.LastCalibrationTime = "未记录";
                                tempSensorCalibrationInfo.CalibrationDays     = "-";
                                tempSensorCalibrationInfo.pointid             = def.PointID;
                                //tempSensorCalibrationInfo.id = dr[0]["id"].ToString();
                                if (ClientAlarmServer.sensorCalibrationInfoList.Find(a => a.Point == tempSensorCalibrationInfo.Point) == null)
                                {
                                    ClientAlarmServer.sensorCalibrationInfoList.Add(tempSensorCalibrationInfo);
                                }
                            }
                        }
                        #endregion
                    }
                }
                //清除已删除的测点
                foreach (SensorCalibrationInfo tempSensorCalibrationInfo in ClientAlarmServer.sensorCalibrationInfoList)
                {
                    if (pointDefineList.FindAll(a => a.Point == tempSensorCalibrationInfo.Point).Count == 0)//如果测点定义缓存中不存在测点,则清除未标校集合中的记录
                    {
                        ClientAlarmServer.sensorCalibrationInfoList.Remove(tempSensorCalibrationInfo);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
        }