using System; using System.Collections.Generic; using QMAPP.BLL; using QMAPP.FJC.Entity.EnergyManage; using QMAPP.FJC.DAL.EnergyManage; using QMFrameWork.Data; using QMAPP.Entity; using System.Data; using QMAPP.FJC.Entity; namespace QMAPP.FJC.BLL.EnergyManage { /// /// 模块名称:能源仪表维护 /// 作 者:周晓东 /// 编写日期:2018年03月03日 /// public class MeterBLL : BaseBLL { #region 获取信息 /// /// 获取信息 /// /// 条件 /// 信息 public DataResult Get(Meter info) { DataResult result = new DataResult(); try { result.Result= new MeterDAL().Get(info); } catch (Exception ex) { result.IsSuccess = false; result.Msg = Resource.SystemException; throw ex; } result.IsSuccess = true; return result; } public DataResult GetMaxMeterReadings(MeterReadings info) { DataResult result = new DataResult(); try { result.Result = new MeterDAL().GetMaxMeterReadings(info); } catch (Exception ex) { result.IsSuccess = false; result.Msg = Resource.SystemException; throw ex; } result.IsSuccess = true; return result; } public DataResult GetMeterReadings(MeterReadings info) { DataResult result = new DataResult(); try { result.Result = new MeterDAL().GetMeterReadings(info); } catch (Exception ex) { result.IsSuccess = false; result.Msg = Resource.SystemException; throw ex; } result.IsSuccess = true; return result; } #endregion #region 获取列表 /// /// 获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataResult GetLists(Meter condition, DataPage page) { DataResult result = new DataResult(); try { DataPage dataPage = new MeterDAL().GetList(condition, page); #region 转换报警类别、工序类别显示类型 List List = dataPage.Result as List; foreach (Meter m in List) { //能源表状态 0 作废 1 自动 2 手动 if (m.STATE=="0") { m.STATE_TXT = "作废"; } else if (m.STATE == "1") { m.STATE_TXT = "自动"; } else if (m.STATE == "2") { m.STATE_TXT = "手动"; } //能源表类型 0 电 1 水 if (m.METER_TYPE == "0") { m.METER_TYPE_TXT = "电"; } else if (m.METER_TYPE == "1") { m.METER_TYPE_TXT = "水"; } else if (m.METER_TYPE == "2") { m.METER_TYPE_TXT = "气"; } } #endregion result.Result = dataPage; } catch (Exception ex) { result.IsSuccess = false; result.Msg = Resource.SystemException; throw ex; } result.IsSuccess = true; return result; } #endregion #region 获取电表读数列表 /// /// 获取电表读数列表 /// /// 条件 /// 数据页 /// 数据页 public DataResult MeterReadingsConfigList(MeterReadings condition, DataPage page) { DataResult result = new DataResult(); try { DataPage dataPage = new MeterDAL().MeterReadingsConfigList(condition, page); #region 转换报警类别、工序类别显示类型 List List = dataPage.Result as List; foreach (MeterReadings m in List) { //能源表状态 0 失败 1 自动 2 手动 if (m.READ_RESULT == "0") { m.READ_RESULT = "失败"; } else if (m.READ_RESULT == "1") { m.READ_RESULT = "自动"; } else if (m.READ_RESULT == "2") { m.READ_RESULT = "手动"; } //能源表类型 0 电 1 水 if (m.METER_TYPE == "0") { m.METER_TYPE_TXT = "电"; } else if (m.METER_TYPE == "1") { m.METER_TYPE_TXT = "水"; } else if (m.METER_TYPE == "2") { m.METER_TYPE_TXT = "气"; } } #endregion result.Result = dataPage; } catch (Exception ex) { result.IsSuccess = false; result.Msg = Resource.SystemException; throw ex; } result.IsSuccess = true; return result; } #endregion #region 信息是否重复 /// /// 判断名称是否存在 /// /// 信息 /// true:已存在;fasel:不存在。 public bool Exists(Meter info) { try { return new MeterDAL().Exists(info); } catch (Exception ex) { throw ex; } } public bool ExistsEqptCode(Meter info) { try { return new MeterDAL().ExistsEqptCode(info); } catch (Exception ex) { throw ex; } } #endregion #region 插入信息 /// /// 插入信息(单表) /// /// 信息 /// 插入行数 public DataResult InsertMeterReadings(MeterReadings info) { DataResult result = new DataResult(); info.READ_RESULT = "2"; var mrd=GetMaxMeterReadings(info); if (mrd.Result != null ) { if (info.READ_TIME <= mrd.Result.READ_TIME) { result.IsSuccess = false; result.Msg = "读取时间必须大于:" + mrd.Result.READ_TIME; return result; } if (info.READING < mrd.Result.READING) { result.IsSuccess = false; result.Msg = "电量必须大于等于:" + mrd.Result.READING; return result; } info.DIFF_WITH_LAST = info.READING - mrd.Result.READING; } else { info.DIFF_WITH_LAST = info.READING; } try { //基本信息 info.PID = Guid.NewGuid().ToString(); result.Result = new MeterDAL().InsertMeterReadings(info); result.IsSuccess = true; return result; } catch (Exception ex) { throw ex; } } public DataResult Insert(Meter info) { DataResult result = new DataResult(); try { //基本信息 info.PID = Guid.NewGuid().ToString(); result.Result = new MeterDAL().Insert(info); result.IsSuccess = true; return result; } catch (Exception ex) { throw ex; } } #endregion #region 更新信息 /// /// 更新信息 /// /// 信息 /// 更新行数 public DataResult UpdateMeterReadings(MeterReadings info) { DataResult result = new DataResult(); var mrd = GetMaxMeterReadings(info); if (info.PID != mrd.Result.PID) { result.IsSuccess = false; result.Msg = "只能修改最后一条" ; return result; } try { result.Result = new MeterDAL().UpdateMeterReadings(info); result.IsSuccess = true; return result; } catch (Exception ex) { throw ex; } } public DataResult Update(Meter info) { DataResult result = new DataResult(); try { result.Result = new MeterDAL().Update(info); result.IsSuccess = true; return result; } catch (Exception ex) { throw ex; } } #endregion #region 删除 /// /// 删除信息 /// /// 主键串 /// 删除个数 public DataResult DeleteMeterReadings(string str) { int count = 0; var mrd = new MeterReadings {PID = str}; var m1 = GetMeterReadings(mrd); var m2 = GetMaxMeterReadings(m1.Result); DataResult result = new DataResult(); if (m2.Result != null) { if (m1.Result.PID != m2.Result.PID) { result.IsSuccess = false; result.Msg = "只能删除最后一条"; return result; } } try { result.Result = new MeterDAL().DeleteMeterReadings(mrd); result.IsSuccess = true; return result; } catch (Exception ex) { throw ex; } } public DataResult DeleteArray(string strs) { int count = 0; DataResult result = new DataResult(); string[] list = strs.Split(":".ToCharArray()); try { foreach (string str in list) { count += this.Delete(new Meter { PID = str }); } result.Result = count; result.IsSuccess = true; return result; } catch (Exception ex) { throw ex; } } /// /// 删除信息 /// /// 信息 /// 删除个数 public int Delete(Meter info) { try { return new MeterDAL().Delete(info); } catch (Exception ex) { throw ex; } } #endregion #region 导出数据 /// /// 获取导出的数据 /// /// 查询条件 /// 数据 public DataTable GetExportData(Meter info) { return null; } #endregion #region 导入数据 /// /// 导入数据 /// /// 数据 /// 导入结果 public DataResult ImportData(List list) { DataResult result = new DataResult(); MeterDAL cmDal = new MeterDAL(); List List = new List(); int index = 0; try { result.Result = new ImportMessage(); result.Result.Errors = new List(); using (IDataSession session = AppDataFactory.CreateMainSession()) { //状态判断 foreach (Meter ma in list) { index++; if (!string.IsNullOrEmpty(ma.InfoError)) { ma.PID = null; result.Result.failureNum += 1; continue; } //修改改时根据主键等信息获取详细内容信息 Meter oldInfo = cmDal.Get(ma); if (oldInfo != null) { //更新 ma.PID = oldInfo.PID; ma.IsNewInfo = false; result.Result.updateNum += 1; } else { //新增 oldInfo = new Meter(); ma.PID = Guid.NewGuid().ToString(); ma.IsNewInfo = true; result.Result.insertNum += 1; } List.Add(ma); } } //导入 cmDal.GetImportData(List); result.Msg = "导入成功"; result.IsSuccess = true; return result; } catch (Exception ex) { result.IsSuccess = false; result.Ex = ex; return result; } } #endregion public List GetList(Meter condition) { try { return new MeterDAL().GetList(condition); } catch (Exception ex) { throw ex; } } /// /// 抄表(全部电表) /// /// public string ReadAllMeter() { MeterReader.ReadAllMeter(); return "READED"; } } }