/// <summary> /// 回来能耗统计分析(区间粒度) /// </summary> /// <param name="selKey">选择的对象</param> /// <param name="start">开始时间</param> /// <param name="end">结束时间</param> /// <returns></returns> public APIResult GetYdModuleCollectValList(string selKey, DateTime start, DateTime end) { APIResult rst = new APIResult(); try { string[] kk = selKey.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); int id = kk.Count() != 2 ? 0 : CommFunc.ConvertDBNullToInt32(kk[1]); int co_id = 0, meter_id = 0; if (selKey.Contains("M-")) { meter_id = id; } else { co_id = id; } DataTable dtSource = bll.GetYdModuleCollectValList(co_id, meter_id, start, end); var res1 = from s1 in dtSource.AsEnumerable() select new { RowId = dtSource.Rows.IndexOf(s1) + 1, Module_id = CommFunc.ConvertDBNullToInt32(s1["Module_id"]), ModuleAddr = CommFunc.ConvertDBNullToString(s1["ModuleAddr"]), Start = CommFunc.ConvertDBNullToDateTime(s1["Start"]).ToString("yyyy-MM-dd"), End = CommFunc.ConvertDBNullToDateTime(s1["End"]).ToString("yyyy-MM-dd"), FirstVal = s1["FirstVal"] == DBNull.Value ? "" : CommFunc.ConvertDBNullToDecimal(s1["FirstVal"]).ToString("f2"), LastVal = s1["LastVal"] == DBNull.Value ? "" : CommFunc.ConvertDBNullToDecimal(s1["LastVal"]).ToString("f2"), ModuleName = CommFunc.ConvertDBNullToString(s1["ModuleName"]), RoomName = CommFunc.ConvertDBNullToString(s1["RoomName"]), StrcName = CommFunc.ConvertDBNullToString(s1["StrcName"]), }; rst.Code = 0; rst.Msg = ""; rst.Data = new { total = dtSource.Rows.Count, rows = res1.ToList() }; } catch (Exception ex) { rst.Code = -1; rst.Msg = ex.Message; FileLog.WriteLog("获取按区间粒度列表错误(GetYdModuleCollectValList):" + ex.Message + ex.StackTrace); } return(rst); }
/// <summary> /// 站点场景类型统计分析 /// </summary> /// <param name="areaId">区域ID号</param> /// <param name="start">开始时间</param> /// <param name="end">结束时间</param> /// <param name="roomSightId">场景ID号</param> /// <returns></returns> public APIResult GetRptRoomSightList(int areaId, DateTime start, DateTime end, int roomSightId) { APIResult rst = new APIResult(); try { DataTable dtSource = bll.GetRptRoomSightList(areaId, start, end, roomSightId); var res1 = from s1 in dtSource.AsEnumerable() select new { RowId = dtSource.Rows.IndexOf(s1) + 1, RoomId = CommFunc.ConvertDBNullToInt32(s1["RoomId"]), RoomSightId = CommFunc.ConvertDBNullToInt32(s1["RoomSightId"]), RoomNo = CommFunc.ConvertDBNullToString(s1["RoomNo"]), RoomName = CommFunc.ConvertDBNullToString(s1["RoomName"]), Address = CommFunc.ConvertDBNullToString(s1["Address"]), RoomSightName = CommFunc.ConvertDBNullToString(s1["RoomSightName"]), StrcName = CommFunc.ConvertDBNullToString(s1["StrcName"]), UseVal = CommFunc.ConvertDBNullToDecimal(s1["UseVal"]).ToString("f2"), LastTime = CommFunc.ConvertDBNullToDateTime(s1["LastTime"]).ToString("yyyy-MM-dd HH:mm:ss"), }; var res2 = from s1 in dtSource.AsEnumerable() group s1 by new { RoomSightId = CommFunc.ConvertDBNullToInt32(s1["RoomSightId"]) } into g1 select new { RoomSightId = g1.Key.RoomSightId, RoomSightName = CommFunc.ConvertDBNullToString(g1.First()["RoomSightName"]), UseVal = g1.Sum(p => CommFunc.ConvertDBNullToDecimal(p["UseVal"])), Cnt = g1.Count() }; rst.Code = 0; rst.Msg = ""; rst.Data = new { total = dtSource.Rows.Count, rows = res1.ToList(), charts = res2.ToList() }; } catch (Exception ex) { rst.Code = -1; rst.Msg = ex.Message; FileLog.WriteLog("站点场景类型统计分析(GetRptRoomSightList):" + ex.Message + ex.StackTrace); } return(rst); }
/// <summary> /// 保存修改错误数据 /// </summary> /// <returns></returns> public APIRst SaveVal(int RowId, int Co_id, int Log_id, int Module_id, int Fun_id, string ModuleAddr, decimal LastValOld, decimal LastVal, decimal FirstVal) { decimal charge = LastValOld - FirstVal; FirstVal = LastVal - charge; APIRst rst = new APIRst(); try { int total = 0; bll.SetV2_infoInVal(Log_id, Co_id, Module_id, ModuleAddr, Fun_id, FirstVal, LastVal); DataTable dtSource = bll.GetTabVal(Co_id, ModuleAddr); total = dtSource.Rows.Count; var res1 = from s1 in dtSource.AsEnumerable() select new { RowId = RowId, Co_id = CommFunc.ConvertDBNullToInt32(s1["Co_id"]), Log_id = CommFunc.ConvertDBNullToInt32(s1["Log_id"]), CoStrcName = CommFunc.ConvertDBNullToString(s1["CoStrcName"]), CoName = CommFunc.ConvertDBNullToString(s1["CoName"]), ModuleAddr = CommFunc.ConvertDBNullToString(s1["ModuleAddr"]), AType = CommFunc.ConvertDBNullToString(s1["AType"]), Content = CommFunc.ConvertDBNullToString(s1["Content"]), ErrCode = CommFunc.ConvertDBNullToString(s1["ErrCode"]), CollectTime = CommFunc.ConvertDBNullToDateTime(s1["CollectTime"]).ToString("yyyy-MM-dd HH:mm:ss"), FirstVal = CommFunc.ConvertDBNullToDecimal(s1["FirstVal"]), LastVal = CommFunc.ConvertDBNullToDecimal(s1["LastVal"]), LastValOld = CommFunc.ConvertDBNullToDecimal(s1["LastVal"]), LastTime = CommFunc.ConvertDBNullToDateTime(s1["LastTime"]).ToString("yyyy-MM-dd HH:mm:ss"), }; rst.data = res1.ToList(); } catch (Exception ex) { rst.rst = false; rst.err.code = (int)ResultCodeDefine.Error; rst.err.msg = ex.Message; FileLog.WriteLog("保存修改错误数据错误:" + ex.Message + ex.StackTrace); } return(rst); }
public APIRst GetYdAlarmOfChargeList(string strcName, string coName, string isPay, string startTime, string endTime) { APIRst rst = new APIRst(); try { DataTable dtSource = bll.GetYdAlarmOfChargeList(strcName, coName, isPay, CommFunc.ConvertDBNullToDateTime(startTime), CommFunc.ConvertDBNullToDateTime(endTime)); int total = dtSource.Rows.Count; var res1 = from s1 in dtSource.AsEnumerable() select new { RowId = CommFunc.ConvertDBNullToInt32(s1["RowId"]), Co_id = CommFunc.ConvertDBNullToInt32(s1["Co_id"]), CoStrcName = CommFunc.ConvertDBNullToString(s1["CoStrcName"]), CoName = CommFunc.ConvertDBNullToString(s1["CoName"]), Module_id = CommFunc.ConvertDBNullToInt32(s1["Module_id"]), ModuleName = CommFunc.ConvertDBNullToString(s1["ModuleName"]), ModuleAddr = CommFunc.ConvertDBNullToString(s1["ModuleAddr"]), IsPay = CommFunc.ConvertDBNullToInt32(s1["IsPay"]), IsPayS = CommFunc.ConvertDBNullToString(s1["IsPayS"]), Trade_no = CommFunc.ConvertDBNullToString(s1["Trade_no"]), PayAmt = CommFunc.ConvertDBNullToDecimal(s1["PayAmt"]).ToString("f2"), PayVal = CommFunc.ConvertDBNullToDecimal(s1["PayVal"]).ToString("f2"), ErrCode = CommFunc.ConvertDBNullToInt32(s1["ErrCode"]), ErrTxt = ((CommFunc.ConvertDBNullToInt32(s1["IsPay"]) == 1 && CommFunc.ConvertDBNullToInt32(s1["ErrCode"]) == -2) || (CommFunc.ConvertDBNullToInt32(s1["IsPay"]) == 10 && CommFunc.ConvertDBNullToInt32(s1["ErrCode"]) == 0)) ? "用户取消" : CommFunc.ConvertDBNullToString(s1["ErrTxt"]), Create_by = CommFunc.ConvertDBNullToString(s1["Create_by"]), Create_dt = CommFunc.ConvertDBNullToDateTime(s1["Create_dt"]).ToString("yyyy-MM-dd HH:mm:ss"), PayType = CommFunc.ConvertDBNullToInt32(s1["PayType"]), PayTypeS = CommFunc.ConvertDBNullToString(s1["PayTypeS"]), }; object obj = new { total = total, rows = res1.ToList() }; rst.data = obj; } catch (Exception ex) { rst.rst = false; rst.err.code = (int)ResultCodeDefine.Error; rst.err.msg = ex.Message; FileLog.WriteLog("获取充值用电告警错误(YdAlarmOnList)", ex.Message + ex.StackTrace); } return(rst); }
/// <summary> /// 采集异常告警—获取采集异常告警列表 /// </summary> /// <param name="startTime">开始日期</param> /// <param name="endTime">结束日期</param> /// <param name="status">操作状态(可选)</param> /// <param name="strcName">建筑名称(可选)</param> /// <param name="coName">房间名称(可选)</param> /// <returns></returns> public APIRst GetYdAlarmList(string startTime, string endTime, int status = 0, string strcName = "", string coName = "") { APIRst rst = new APIRst(); try { if ("{strcName}".Equals(strcName)) { strcName = ""; } if ("{coName}".Equals(coName)) { coName = ""; } DataTable dtSource = bll.GetYdAlarmList(strcName, coName, status, CommFunc.ConvertDBNullToDateTime(startTime), CommFunc.ConvertDBNullToDateTime(endTime)); int total = dtSource.Rows.Count; var res1 = from s1 in dtSource.AsEnumerable() select new { Log_id = CommFunc.ConvertDBNullToInt32(s1["Log_id"]), Status = CommFunc.ConvertDBNullToInt32(s1["Status"]), Create_dt = CommFunc.ConvertDBNullToDateTime(s1["Create_dt"]).ToString("yyyy-MM-dd HH:mm:ss"), CoStrcName = CommFunc.ConvertDBNullToString(s1["CoStrcName"]), CustAddr = CommFunc.ConvertDBNullToString(s1["CustAddr"]), ModuleName = CommFunc.ConvertDBNullToString(s1["ModuleName"]), FunName = CommFunc.ConvertDBNullToString(s1["FunName"]), Content = CommFunc.ConvertDBNullToString(s1["Content"]), Appr_by = CommFunc.ConvertDBNullToInt32(s1["Appr_by"]), CollectValue = CommFunc.ConvertDBNullToString(s1["CollectValue"]), }; object obj = new { total = total, rows = res1.ToList() }; rst.data = obj; } catch (Exception ex) { rst.rst = false; rst.err.code = (int)ResultCodeDefine.Error; rst.err.msg = ex.Message; FileLog.WriteLog("获取告警内容错误(GetYdAlarmList)", ex.Message + ex.StackTrace); } return(rst); }
/// <summary> /// 采集异常告警列表 /// </summary> /// <returns></returns> public APIRst GetYdAlarmOfUnusualList(string strcName, string coName, string startTime, string endTime) { APIRst rst = new APIRst(); try { DataTable dtSource = bll.GetYdAlarmOfUnusualList(strcName, coName, CommFunc.ConvertDBNullToDateTime(startTime), CommFunc.ConvertDBNullToDateTime(endTime)); int total = dtSource.Rows.Count; var res1 = from s1 in dtSource.AsEnumerable() select new { RowId = CommFunc.ConvertDBNullToInt32(s1["RowId"]), Co_id = CommFunc.ConvertDBNullToInt32(s1["Co_id"]), Log_id = CommFunc.ConvertDBNullToInt32(s1["Log_id"]), Module_id = CommFunc.ConvertDBNullToInt32(s1["Module_id"]), ModuleName = CommFunc.ConvertDBNullToString(s1["ModuleName"]), Fun_id = CommFunc.ConvertDBNullToInt32(s1["Fun_id"]), CoStrcName = CommFunc.ConvertDBNullToString(s1["CoStrcName"]), CoName = CommFunc.ConvertDBNullToString(s1["CoName"]), ModuleAddr = CommFunc.ConvertDBNullToString(s1["ModuleAddr"]), ModuleAddrS = CommFunc.ConvertDBNullToString(s1["ModuleAddr"]), AType = CommFunc.ConvertDBNullToString(s1["AType"]), Content = CommFunc.ConvertDBNullToString(s1["Content"]), ErrCode = CommFunc.ConvertDBNullToString(s1["ErrCode"]), CollectTime = CommFunc.ConvertDBNullToDateTime(s1["CollectTime"]).ToString("yyyy-MM-dd HH:mm:ss"), FirstVal = CommFunc.ConvertDBNullToDecimal(s1["FirstVal"]), LastVal = CommFunc.ConvertDBNullToDecimal(s1["LastVal"]), LastValOld = CommFunc.ConvertDBNullToDecimal(s1["LastVal"]), LastTime = CommFunc.ConvertDBNullToDateTime(s1["LastTime"]).ToString("yyyy-MM-dd HH:mm:ss"), }; object obj = new { total = total, rows = res1.ToList() }; rst.data = obj; } catch (Exception ex) { rst.rst = false; rst.err.code = (int)ResultCodeDefine.Error; rst.err.msg = ex.Message; FileLog.WriteLog("获取告警内容错误(GetYdAlarmOfUnusualList)", ex.Message + ex.StackTrace); } return(rst); }
/// <summary> /// 获取用能小时数据 /// </summary> /// <param name="Module_ids">回路</param> /// <returns></returns> private Dictionary <DateTime, decimal> GetDayEnergyUseValList(string Module_ids, DateTime date) { DataRow[] rows = DT_USE_HOUR.Select(string.Format("Module_id in({0})", Module_ids)); Dictionary <DateTime, decimal> dic = new Dictionary <DateTime, decimal>(); for (int i = 0; i < 72; i++) { dic.Add(date.AddHours(i), 0); } //List<decimal> todayList = new List<decimal>(); //int nn = DateTime.Now.Hour; //while (nn-- >= 0) //{ // todayList.Add(0); //} foreach (DataRow dr in rows) { DataRow curDr = DT_SOURCE.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] }); if (curDr == null) { continue; } int scale = CommFunc.ConvertDBNullToInt32(curDr["Scale"]); decimal multiply = CommFunc.ConvertDBNullToDecimal(curDr["Multiply"]); scale = scale == 0 ? 2 : scale; DateTime tagTime = CommFunc.ConvertDBNullToDateTime(dr["TagTime"]); decimal firstVal = CommFunc.ConvertDBNullToDecimal(dr["FirstVal"]); decimal lastVal = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]); decimal useVal = lastVal - firstVal; useVal = Math.Round(useVal * multiply, scale, MidpointRounding.AwayFromZero); if (dic.ContainsKey(tagTime)) { dic[tagTime] = CommFunc.ConvertDBNullToDecimal(dic[tagTime]) + useVal; } //todayList[tagTime.Hour] = CommFunc.ConvertDBNullToDecimal(todayList[tagTime.Hour]) + useVal; } return(dic); }
/// <summary> /// 获取告警信息 /// </summary> /// <param name="co_id"></param> /// <param name="module_id"></param> /// <param name="moduleAddr"></param> /// <param name="aType"></param> /// <param name="rule"></param> /// <returns></returns> public v2_alarm_logVModel GetAlarmModel(int co_id, int module_id, string moduleAddr, string aType, decimal rule) { //double hh = (double)(0 - (rule * 24)); //int hh = (int)rule + 1; int hd = (int)Math.Ceiling(rule) - 1; DateTime cTime = DateTime.Now.AddDays(0 - hd); object params01 = new { Ledger = this.Ledger, CDate = new DateTime(cTime.Year, cTime.Month, cTime.Day), Co_id = co_id, Module_id = module_id, ModuleAddr = moduleAddr, AType = aType, CTime = new DateTime(cTime.Year, cTime.Month, cTime.Day, cTime.Hour, 59, 59), }; StringBuilder strSql = new StringBuilder(); strSql.Append("select Log_id,CDate,Co_id,Module_id,ModuleAddr,AType,Content,str_to_date(CONCAT(CDate,' ',CTime), '%Y-%m-%d %H:%i:%s') as CTime,ErrCode,ErrTxt"); strSql.Append(" from v2_alarm_log"); strSql.Append(" where CDate>=@CDate and Co_id=@Co_id and Module_id=@Module_id and ModuleAddr=@ModuleAddr and AType=@AType"); //strSql.Append(" and str_to_date(CONCAT(CDate,' ',CTime), '%Y-%m-%d %H:%i:%s')>=@CTime"); strSql.Append(" order by Log_id desc limit 1"); DataTable tab = SQLHelper.Query(strSql.ToString(), params01); v2_alarm_logVModel mm = null; if (tab.Rows.Count > 0) { DateTime cdt = CommFunc.ConvertDBNullToDateTime(tab.Rows[0]["CTime"]); decimal dd = ((int)(DateTime.Now - cdt).TotalDays) * 24; decimal hh = (decimal)(DateTime.Now - cdt).TotalHours; ///////////////////////////////////////////////////////////////////// decimal last = dd > hh ? dd : hh; if ((rule * 24) > last) { mm = ModelHandler <v2_alarm_logVModel> .FillModel(tab.Rows[0]); } } return(mm); }
private v2_alarm_logVModel AlarmInfo(DataRow dr, decimal cfValue, decimal cfRule) { int co_id = CommFunc.ConvertDBNullToInt32(dr["Co_id"]); string coName = CommFunc.ConvertDBNullToString(dr["CoName"]); int chrgType = CommFunc.ConvertDBNullToInt32(dr["ChrgType"]); DateTime lastTime = CommFunc.ConvertDBNullToDateTime(dr["LastTime"]); decimal rdVal = CommFunc.ConvertDBNullToDecimal(dr["RdVal"]); decimal price = CommFunc.ConvertDBNullToDecimal(dr["Price"]); decimal rdAmt = Math.Round(rdVal * price, 2, MidpointRounding.AwayFromZero); int module_id = 0; string moduleAddr = ""; string moduleName = CommFunc.ConvertDBNullToString(dr["ModuleName"]); if (chrgType >= 2) { module_id = CommFunc.ConvertDBNullToInt32(dr["Module_id"]); moduleAddr = CommFunc.ConvertDBNullToString(dr["ModuleAddr"]); } string ss = "你好当前设备:" + moduleName + "余额:" + rdAmt.ToString("f2"); v2_alarm_logVModel ems = bll.GetAlarmModel(co_id, module_id, moduleAddr, AlarmType.Alarm.ToString(), cfRule); if (ems == null) { ems = new v2_alarm_logVModel(); ems.Log_id = 0; ems.Co_id = co_id; ems.Module_id = module_id; ems.ModuleAddr = moduleAddr; ems.AType = AlarmType.Alarm.ToString(); } ems.Content = ss; ems.ErrTxt = ""; if (ems.Log_id == 0) { bll.AddAlarm(ems);//增加log } return(ems); }
/// <summary> /// 获取集中器信息 /// </summary> /// <returns></returns> public APIResult GetEspList(int esp_id, string espName) { APIResult rst = new APIResult(); try { DataTable dtSource = bll.GetEspList(esp_id, espName); var res1 = from s1 in dtSource.AsEnumerable() select new { RowId = dtSource.Rows.IndexOf(s1) + 1, Esp_id = CommFunc.ConvertDBNullToInt32(s1["Esp_id"]), EspName = CommFunc.ConvertDBNullToString(s1["EspName"]), EspAddr = CommFunc.ConvertDBNullToString(s1["EspAddr"]), //EspIp = CommFunc.ConvertDBNullToString(s1["EspIp"]), //EspPort = CommFunc.ConvertDBNullToInt32(s1["EspPort"]), //TransferType = CommFunc.ConvertDBNullToInt32(s1["TransferType"]), //TransferTypeName = CommFunc.GetEnumDisplay(typeof(TfAttrib), CommFunc.ConvertDBNullToInt32(s1["TransferType"])) EspType = CommFunc.ConvertDBNullToString(s1["EspType"]), Inst_loc = CommFunc.ConvertDBNullToString(s1["Inst_loc"]), Remark = CommFunc.ConvertDBNullToString(s1["Remark"]), Disabled = CommFunc.ConvertDBNullToInt32(s1["Disabled"]), Supplier = CommFunc.ConvertDBNullToString(s1["Supplier"]), ActiveTime = CommFunc.ConvertDBNullToDateTime(s1["ActiveTime"]).ToString("yyyy-MM-dd HH:mm:ss") }; object obj = new { total = dtSource.Rows.Count, rows = res1.ToList() }; rst.Code = 0; rst.Msg = ""; rst.Data = obj; } catch (Exception ex) { rst.Code = -1; rst.Msg = ex.Message; FileLog.WriteLog("获取获取集中器信息错误(GetEspList):" + ex.Message + ex.StackTrace); } return(rst); }
public static void UpV4_pay_charg(int ledger) { YDS6000.BLL.DataProcess.PayEstBLL bll = new YDS6000.BLL.DataProcess.PayEstBLL(ledger, Config.Uid); DataTable dtSource = bll.GetV4_pay_charg(); foreach (DataRow dr in dtSource.Rows) { long log_id = CommFunc.ConvertDBNullToLong(dr["Log_id"]); int co_id = CommFunc.ConvertDBNullToInt32(dr["Co_id"]); decimal firstVal = CommFunc.ConvertDBNullToDecimal(dr["FirstVal"]); decimal lastVal = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]); decimal price = CommFunc.ConvertDBNullToDecimal(dr["Price"]); decimal chargVal = CommFunc.ConvertDBNullToDecimal(dr["ChargVal"]); decimal useAmt = Math.Round((lastVal - firstVal) * price, 2, MidpointRounding.AwayFromZero) + chargVal; DateTime firstTime = CommFunc.ConvertDBNullToDateTime(dr["FirstTime"]); DateTime lastTime = CommFunc.ConvertDBNullToDateTime(dr["LastTime"]); if (DateTime.Now < lastTime) { continue; } bll.UpV4_pay_charg(log_id, co_id, useAmt); } }
/// <summary> /// 获取采集历史报表 /// </summary> /// <param name="StrcName">建筑名称</param> /// <param name="CoName">房间名称</param> /// <param name="FunType">电参量:0=全部,10=商户,20=商铺,30=宿舍,40=厂房</param> /// <param name="IsDefine">属性:E=电量,Ia=A相电流,Ib=B相电流,Ic=C相电流,Ua=A相电压,Ub=B相电压,Uc=C相电压,Psum=总有功功率,Pa=A相有功功率,Pb=B相有功功率,Pc=C相有功功率,Qsum=总无功功率,Qa=A相无功功率,Qb=B相无功功率,Qc=C相无功功率,Pfav=总功率因数,PFa=A相功率因数,PFb=B相功率因数,PFc=C相功率因数</param> /// <param name="StartTime">日期开始</param> /// <param name="EndTime">日期结束</param> /// <returns></returns> public APIRst GetYdCollectData(string StrcName, string CoName, string FunType, int IsDefine, DateTime StartTime, DateTime EndTime) { APIRst rst = new APIRst(); try { if (string.IsNullOrEmpty(FunType)) { FunType = "E"; } DataTable dtSource = bll.GetYdCollectData(StrcName, CoName, FunType, IsDefine, StartTime, EndTime); var res1 = from s1 in dtSource.AsEnumerable() orderby s1["Module_id"], s1["ModuleAddr"] select new { RowId = dtSource.Rows.IndexOf(s1) + 1, TagTime = CommFunc.ConvertDBNullToDateTime(s1["TagTime"]).ToString("yyyy-MM-dd HH:mm:ss"), Module_id = CommFunc.ConvertDBNullToInt32(s1["Module_id"]), ModuleAddr = CommFunc.ConvertDBNullToString(s1["ModuleAddr"]), ModuleName = CommFunc.ConvertDBNullToString(s1["ModuleName"]), LastVal = CommFunc.ConvertDBNullToDecimal(s1["LastVal"]), FunType = CommFunc.ConvertDBNullToString(s1["FunType"]), CoStrcName = CommFunc.ConvertDBNullToString(s1["CoStrcName"]), CoName = CommFunc.ConvertDBNullToString(s1["CoName"]), }; object obj = new { total = dtSource.Rows.Count, rows = res1.ToList() }; rst.data = obj; } catch (Exception ex) { rst.rst = false; rst.err.code = (int)ResultCodeDefine.Error; rst.err.msg = ex.Message; FileLog.WriteLog("获取采集历史报表(GetYdCollectData):" + ex.Message + ex.StackTrace); } return(rst); }
public DataTable GetYdModuleUseValList(int co_id, int meter_id, DateTime time, string dataType) { DateTime start = time, end = time; int cnt = dataType.Equals("hour") ? 24 : dataType.Equals("day") ? cnt = time.AddMonths(1).AddDays(-1).Day : 12; if (dataType.Equals("hour")) { start = new DateTime(time.Year, time.Month, time.Day); end = new DateTime(time.Year, time.Month, time.Day, 23, 59, 59); cnt = 24; } else if (dataType.Equals("day")) { start = new DateTime(time.Year, time.Month, 1); end = start.AddMonths(1).AddDays(-1); cnt = end.Day; } else { start = new DateTime(time.Year, 1, 1); end = start.AddYears(1).AddDays(-1); cnt = 12; } StringBuilder splitMdQuery = new StringBuilder(); DataTable dtRst = this.GetYdModuleUseValTabSchema(); DataTable dtSource = dal.GetYdModuleListParams(co_id, meter_id); dtRst.PrimaryKey = new DataColumn[] { dtRst.Columns["Module_id"], dtRst.Columns["ModuleAddr"] }; dtSource.PrimaryKey = new DataColumn[] { dtSource.Columns["Module_id"], dtSource.Columns["Fun_id"] }; foreach (DataRow dr in dtSource.Rows) { if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitMdQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["Module_id"]), ","))) { if (!string.IsNullOrEmpty(splitMdQuery.ToString())) { splitMdQuery.Append(","); } splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"])); } } DataTable dtUse = WholeBLL.GetCoreQueryData(this.Ledger, splitMdQuery.ToString(), start, end, dataType); foreach (DataRow dr in dtUse.Rows) { DataRow curDr = dtSource.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] }); if (curDr == null) { continue; } int scale = CommFunc.ConvertDBNullToInt32(curDr["Scale"]); scale = scale == 0 ? 2 : scale; decimal multiply = CommFunc.ConvertDBNullToDecimal(curDr["Multiply"]); DateTime tagtime = CommFunc.ConvertDBNullToDateTime(dr["TagTime"]); decimal firstVal = CommFunc.ConvertDBNullToDecimal(dr["FirstVal"]); decimal lastVal = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]); decimal useVal = (lastVal - firstVal) * multiply; useVal = Math.Round(useVal, scale, MidpointRounding.AwayFromZero); DataRow addDr = dtRst.Rows.Find(new object[] { dr["Module_id"], dr["ModuleAddr"] }); if (addDr == null) { addDr = dtRst.NewRow(); addDr["Module_id"] = dr["Module_id"]; addDr["ModuleAddr"] = dr["ModuleAddr"]; addDr["Cnt"] = cnt; addDr["ModuleName"] = curDr["ModuleName"]; addDr["RoomName"] = curDr["CoName"]; addDr["StrcName"] = curDr["CoStrcName"]; dtRst.Rows.Add(addDr); } string clsName = "V" + (dataType.Equals("hour") ? tagtime.Hour + 1 : dataType.Equals("day") ? tagtime.Day : tagtime.Month).ToString().PadLeft(2, '0'); addDr[clsName] = CommFunc.ConvertDBNullToDecimal(addDr[clsName]) + useVal; } return(dtRst); }
/// <summary> /// 设置用户信息 /// </summary> /// <param name="Uid">用户ID</param> /// <param name="sAct">操作类型:增加=1,修改=2,删除=3</param> /// <param name="Rid">用户权限</param> /// <param name="Name">用户名称</param> /// <param name="SName">登录名</param> /// <param name="Pwd">登录密码</param> /// <returns></returns> public APIRst SetUser(int Uid, int sAct, int Rid, string Name, string SName, string Pwd, string TelNo) { APIRst rst = new APIRst(); try { int id = CommFunc.ConvertDBNullToInt32(Uid);//用户ID号 int nAct = CommFunc.ConvertDBNullToInt32(sAct); sys_user uu = new sys_user(); uu.Uid = id; uu.TelNo = TelNo; if (nAct == 2 || nAct == 3) { if (Uid == 0) { throw new Exception(" 数据出错,请选择行再重试.."); } } if (nAct == 1 || nAct == 2) { uu.Role_id = Rid; //用户权限 uu.UName = Name; //用户名称 uu.USign = SName; //登录名 uu.UPasswd = Pwd; //登录密码 } if (nAct != 1 && nAct != 2 && nAct != 3) { throw new Exception(" 操作类型错误"); } if (nAct != 3 && string.IsNullOrEmpty(uu.UName)) { throw new Exception(" 请输入用户名称"); } if (nAct != 3 && uu.Role_id == 0) { throw new Exception(" 请选择用户角色"); } if (nAct != 3 && string.IsNullOrEmpty(uu.UPasswd)) { throw new Exception(" 请输入用户密码"); } if (nAct == 3) { bll.DelUser(Uid); } else { bll.EditUser(uu, nAct); } DataTable dtSource = bll.GetUser(uu.Uid); var res1 = from s1 in dtSource.AsEnumerable() select new { RowId = CommFunc.ConvertDBNullToInt32(s1["RowId"]), Rid = CommFunc.ConvertDBNullToInt32(s1["Role_id"]), Ledger = CommFunc.ConvertDBNullToInt32(s1["Ledger"]), Uid = CommFunc.ConvertDBNullToInt32(s1["Uid"]), Name = CommFunc.ConvertDBNullToString(s1["UName"]), Pwd = CommFunc.ConvertDBNullToString(s1["UPasswd"]), SName = CommFunc.ConvertDBNullToString(s1["USign"]), RName = CommFunc.ConvertDBNullToString(s1["Descr"]), TelNo = CommFunc.ConvertDBNullToString(s1["TelNo"]), Create_by = CommFunc.ConvertDBNullToInt32(s1["Create_by"]), Create_byName = CommFunc.ConvertDBNullToString(s1["Create_byName"]), Create_dt = CommFunc.ConvertDBNullToDateTime(s1["Create_dt"]).ToString("yyyy-MM-dd") }; rst.data = res1.ToList(); } catch (Exception ex) { rst.rst = false; rst.err.code = (int)ResultCodeDefine.Error; rst.err.msg = ex.Message; FileLog.WriteLog("获取充值参数信息错误:" + ex.Message + ex.StackTrace); } return(rst); }
/// <summary> /// 获取分项统计 /// </summary> /// <param name="co_id">支路ID号</param> /// <param name="time">时间</param> /// <param name="dataType">类型 日=day月=month年year</param> /// <returns></returns> public object GetEnergyUseVal(int co_id, DateTime time, string dataType, string moduleName) { DataTable dtRst = this.GetEnergyUseValTabSchema(); int cnt = 24; DateTime fm = time, to = time; if (dataType.ToLower().Equals("day")) { fm = new DateTime(time.Year, time.Month, time.Day); to = new DateTime(time.Year, time.Month, time.Day, 23, 59, 0); cnt = 24; dataType = "hour"; } else if (dataType.ToLower().Equals("month")) { fm = new DateTime(time.Year, time.Month, 1); to = fm.AddMonths(1).AddDays(-1); cnt = to.Day; dataType = "day"; } else if (dataType.ToLower().Equals("year")) { fm = new DateTime(time.Year, 1, 1); to = new DateTime(time.Year, 12, 1); cnt = 12; dataType = "month"; } else { throw new Exception("查询类型错误"); } DataTable dtSource = dal.GetEnergyUseVal(co_id, moduleName); dtSource.PrimaryKey = new DataColumn[] { dtSource.Columns["Module_id"], dtSource.Columns["Fun_id"] }; dtRst.PrimaryKey = new DataColumn[] { dtRst.Columns["Module_id"], dtRst.Columns["Fun_id"] }; // StringBuilder splitMdQuery = new StringBuilder(); StringBuilder splitTyQuery = new StringBuilder(); foreach (DataRow dr in dtSource.Rows) { if (!string.IsNullOrEmpty(splitMdQuery.ToString())) { splitMdQuery.Append(","); } splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"])); if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitTyQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["FunType"]), ","))) { if (!string.IsNullOrEmpty(splitTyQuery.ToString())) { splitTyQuery.Append(","); } splitTyQuery.Append(CommFunc.ConvertDBNullToString(dr["FunType"])); } DataRow addDr = dtRst.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] }); if (addDr == null) { addDr = dtRst.NewRow(); addDr["Module_id"] = dr["Module_id"]; addDr["Fun_id"] = dr["Fun_id"]; addDr["Cnt"] = cnt; addDr["ModuleName"] = dr["ModuleName"]; dtRst.Rows.Add(addDr); } } #region 获取存储数据 DataTable dtUse = WholeBLL.GetCoreQueryData(this.Ledger, splitMdQuery.ToString(), fm, to, dataType, splitTyQuery.ToString()); foreach (DataRow dr in dtUse.Rows) { DataRow curDr = dtSource.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] }); if (curDr == null) { continue; } int scale = CommFunc.ConvertDBNullToInt32(curDr["Scale"]); decimal multiply = CommFunc.ConvertDBNullToDecimal(curDr["Multiply"]); scale = scale == 0 ? 2 : scale; DataRow addDr = dtRst.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] }); if (addDr == null) { continue; } DateTime tagTime = CommFunc.ConvertDBNullToDateTime(dr["TagTime"]); decimal firstVal = CommFunc.ConvertDBNullToDecimal(dr["FirstVal"]); decimal lastVal = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]); decimal useVal = lastVal - firstVal; useVal = Math.Round(useVal * multiply, scale, MidpointRounding.AwayFromZero); if (dataType.Equals("hour")) { addDr["V" + (tagTime.Hour + 1).ToString().PadLeft(2, '0')] = CommFunc.ConvertDBNullToDecimal(addDr["V" + (tagTime.Hour + 1).ToString().PadLeft(2, '0')]) + useVal; } else if (dataType.Equals("day")) { addDr["V" + tagTime.Day.ToString().PadLeft(2, '0')] = CommFunc.ConvertDBNullToDecimal(addDr["V" + tagTime.Day.ToString().PadLeft(2, '0')]) + useVal; } else if (dataType.Equals("month")) { addDr["V" + tagTime.Month.ToString().PadLeft(2, '0')] = CommFunc.ConvertDBNullToDecimal(addDr["V" + tagTime.Month.ToString().PadLeft(2, '0')]) + useVal; } addDr["UseVal"] = CommFunc.ConvertDBNullToDecimal(addDr["UseVal"]) + useVal; } #endregion #region 获取结果集数据 var res1 = from s1 in dtRst.AsEnumerable() select new { ModuleName = CommFunc.ConvertDBNullToString(s1["ModuleName"]), Cnt = CommFunc.ConvertDBNullToInt32(s1["Cnt"]), V01 = CommFunc.ConvertDBNullToDecimal(s1["V01"]), V02 = CommFunc.ConvertDBNullToDecimal(s1["V02"]), V03 = CommFunc.ConvertDBNullToDecimal(s1["V03"]), V04 = CommFunc.ConvertDBNullToDecimal(s1["V04"]), V05 = CommFunc.ConvertDBNullToDecimal(s1["V05"]), V06 = CommFunc.ConvertDBNullToDecimal(s1["V06"]), V07 = CommFunc.ConvertDBNullToDecimal(s1["V07"]), V08 = CommFunc.ConvertDBNullToDecimal(s1["V08"]), V09 = CommFunc.ConvertDBNullToDecimal(s1["V09"]), V10 = CommFunc.ConvertDBNullToDecimal(s1["V10"]), V11 = CommFunc.ConvertDBNullToDecimal(s1["V11"]), V12 = CommFunc.ConvertDBNullToDecimal(s1["V12"]), V13 = CommFunc.ConvertDBNullToDecimal(s1["V13"]), V14 = CommFunc.ConvertDBNullToDecimal(s1["V14"]), V15 = CommFunc.ConvertDBNullToDecimal(s1["V15"]), V16 = CommFunc.ConvertDBNullToDecimal(s1["V16"]), V17 = CommFunc.ConvertDBNullToDecimal(s1["V17"]), V18 = CommFunc.ConvertDBNullToDecimal(s1["V18"]), V19 = CommFunc.ConvertDBNullToDecimal(s1["V19"]), V20 = CommFunc.ConvertDBNullToDecimal(s1["V20"]), V21 = CommFunc.ConvertDBNullToDecimal(s1["V21"]), V22 = CommFunc.ConvertDBNullToDecimal(s1["V22"]), V23 = CommFunc.ConvertDBNullToDecimal(s1["V23"]), V24 = CommFunc.ConvertDBNullToDecimal(s1["V24"]), V25 = CommFunc.ConvertDBNullToDecimal(s1["V25"]), V26 = CommFunc.ConvertDBNullToDecimal(s1["V26"]), V27 = CommFunc.ConvertDBNullToDecimal(s1["V27"]), V28 = CommFunc.ConvertDBNullToDecimal(s1["V28"]), V29 = CommFunc.ConvertDBNullToDecimal(s1["V29"]), V30 = CommFunc.ConvertDBNullToDecimal(s1["V30"]), V31 = CommFunc.ConvertDBNullToDecimal(s1["V31"]), }; return(res1.ToList()); #endregion }
public static void UpdatePayEst(int ledger) { YDS6000.BLL.DataProcess.PayEstBLL bll = new YDS6000.BLL.DataProcess.PayEstBLL(ledger, Config.Uid); // DateTime dtTime = DateTime.Now; DataTable dtRateInfo = bll.GetRateInfo(); DataTable dtSource = bll.GetPayEstInfo(); dtSource.Columns.Add("UseVal", typeof(System.Decimal)); /**/ dtSource.Columns.Add("UseAmt", typeof(System.Decimal)); /*物业费金额*/ StringBuilder strFilter = new StringBuilder(); int point = 2; #region 计算物业费 foreach (DataRow dr in dtSource.Rows) { int attrib = CommFunc.ConvertDBNullToInt32(dr["Attrib"]); int isDefine = CommFunc.ConvertDBNullToInt32(dr["IsDefine"]); int bank = CommFunc.ConvertDBNullToInt32(dr["Bank"]); int isCtl = CommFunc.ConvertDBNullToInt32(dr["IsCtl"]); decimal area = CommFunc.ConvertDBNullToDecimal(dr["Area"]); int rate_id = CommFunc.ConvertDBNullToInt32(dr["Rate_id"]); int rule = CommFunc.ConvertDBNullToInt32(dr["Rule"]); string unit = CommFunc.ConvertDBNullToString(dr["Unit"]); decimal unitBase = CommFunc.ConvertDBNullToDecimal(dr["UnitBase"]); unitBase = unitBase == 0 ? 1 : unitBase; if (rate_id == 0) { continue; } //////// //////// decimal useAmt = 0; #region 计算金额 if (isCtl == 0) {/*使用系统计算*/ foreach (DataRow drRate in dtRateInfo.Select("Rate_id=" + rate_id)) { string pStart = CommFunc.ConvertDBNullToString(drRate["PStart"]); string pEnd = CommFunc.ConvertDBNullToString(drRate["PEnd"]); decimal price = CommFunc.ConvertDBNullToDecimal(drRate["Price"]); ///////////////////////////////////////////////////////////////////// bool isBindGo = false; if (RateUnit.Area.ToString().Equals(unit)) { #region 平方计算 if (rule == 0) { isBindGo = true; } else if (rule == 1) { /*按平方的日期计算*/ DateTime dtFm = CommFunc.ConvertDBNullToDateTime(pStart); DateTime dtTo = CommFunc.ConvertDBNullToDateTime(pEnd); if (dtTime > dtFm && dtTime <= dtTo) { isBindGo = true; } } else if (rule == 2) { decimal nStart = CommFunc.ConvertDBNullToDecimal(pStart); decimal nEnd = CommFunc.ConvertDBNullToDecimal(pEnd); if (area > nStart && area <= nEnd) { isBindGo = true; } } if (isBindGo == true) { useAmt = Math.Round((area / unitBase) * price, point, MidpointRounding.AwayFromZero); } #endregion } else if (RateUnit.Bank.ToString().Equals(unit)) { /*按户数计算*/ #region 户数计算 if (rule == 0) { isBindGo = true; } else if (rule == 1) { /*按平方的日期计算*/ DateTime dtFm = CommFunc.ConvertDBNullToDateTime(pStart); DateTime dtTo = CommFunc.ConvertDBNullToDateTime(pEnd); if (dtTime > dtFm && dtTime <= dtTo) { isBindGo = true; } } else if (rule == 2) { decimal nStart = CommFunc.ConvertDBNullToDecimal(pStart); decimal nEnd = CommFunc.ConvertDBNullToDecimal(pEnd); if (bank > nStart && bank <= nEnd) { isBindGo = true; } } if (isBindGo == true) { useAmt = Math.Round((bank / unitBase) * price, point, MidpointRounding.AwayFromZero); } #endregion } if (isBindGo == true) { break; } } } else { } #endregion dr["UseAmt"] = useAmt; /////// } #endregion bll.UpdatePayEst(dtSource);/*更新*/ }
private void HandleCommand(CommandVModel command, NetworkResource Network) { if (Network == null) { FileLog.Error("ID:" + command.Module_id + "地址:" + command.ModuleAddr + "采集码:" + command.FunType + "采集ID:" + command.Fun_id + "采集名:" + command.FunName + "网络资源错误"); return; } string msg = ""; byte[] send = null, result = null; string lpszVal = null; AlarmType errCode = AlarmType.Sue; bool rst = false; command.CollectTime = DateTime.Now; DateTime lpszdateTime = DateTime.Now; if (command.FunType.Equals(V0Fun.E.ToString()))/*有功总电能*/ { rst = Drive.ARM(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.RdVal.ToString()))/*当前电表剩余电量*/ { rst = Drive.RdVal(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Ia.ToString()))/*当前电表剩余电量*/ { rst = Drive.GetIa(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Ib.ToString())) { rst = Drive.GetIb(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Ic.ToString())) { rst = Drive.GetIc(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Ua.ToString())) { rst = Drive.GetUa(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Ub.ToString())) { rst = Drive.GetUb(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Uc.ToString())) { rst = Drive.GetUc(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Psum.ToString())) { rst = Drive.GetPsum(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Pa.ToString())) { rst = Drive.GetPa(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Pb.ToString())) { rst = Drive.GetPb(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Pc.ToString())) { rst = Drive.GetPc(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Qsum.ToString())) { rst = Drive.GetQsum(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Qa.ToString())) { rst = Drive.GetQa(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Qb.ToString())) { rst = Drive.GetQb(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Qc.ToString())) { rst = Drive.GetQc(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Pfav.ToString())) { rst = Drive.GetPfav(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.PFa.ToString())) { rst = Drive.GetPFa(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.PFb.ToString())) { rst = Drive.GetPFb(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.PFc.ToString())) { rst = Drive.GetPFc(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Ssr.ToString()) && string.IsNullOrEmpty(command.DataValue))/*拉合闸状态*/ { rst = Drive.Ssr(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Ssr.ToString()) && CommFunc.ConvertDBNullToInt32(command.DataValue) == 0)/*合闸*/ { rst = Drive.Ssr0(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Ssr.ToString()) && CommFunc.ConvertDBNullToInt32(command.DataValue) == 1)/*拉闸*/ { rst = Drive.Ssr1(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Pay.ToString()))/*充值*/ { rst = Drive.Pay(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Refund.ToString()))/*退费*/ { rst = Drive.Refund(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.PaySb1.ToString()))/*充值*/ { rst = Drive.PaySb1(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.PaySb2.ToString()))/*充值*/ { rst = Drive.PaySb2(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.IsPaul.ToString()) && string.IsNullOrEmpty(command.DataValue))/*保电状态*/ { rst = Drive.SetPaul(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.IsPaul.ToString()) && !string.IsNullOrEmpty(command.DataValue))/*保电设置*/ { rst = Drive.SetPaul(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Nrp.ToString()))/*有功功率负荷限值(kW)*/ { rst = Drive.SetNrp(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.McNrp.ToString()))/*恶性负载判定有功功率增量(kW)(瞬时额定功率)*/ { rst = Drive.SetMcNrp(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Wpf.ToString()))/*恶性负载判定无功功率(kW)*/ { rst = Drive.SetWpf(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Uep.ToString()))/*违规用电判定功能的功率下限(kW)*/ { rst = Drive.SetUep(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Miss.ToString()))/*一天内违规断电次数限值(0~255)*/ { rst = Drive.SetMiss(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Rest.ToString()))/*违规断电后重启时间(S)*/ { rst = Drive.SetRest(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Saf.ToString()))/*单次功率增量限值(kW)*/ { rst = Drive.SetSaf(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Avlm.ToString()))/*过流门限值(A)*/ { rst = Drive.SetAvlm(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Phase.ToString()))/*启用移相器监测功率下限(kW)*/ { rst = Drive.SetPhase(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Resist.ToString()))/*设置阻行负载(kW)*/ { rst = Drive.SetResist(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.IsPhase.ToString()))/*移相器(=1启用)*/ { rst = Drive.SetIsPhase(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.IsRelay.ToString()))/*继电器参数(=0电平式A路继电器设置;=1电平式B路继电器设置;=127脉冲式设置)*/ { rst = Drive.SetIsRelay(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.IsStdby.ToString()))/*待机检测=0 不检测 =1 检测*/ { rst = Drive.SetStandby(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.TiVal.ToString()))/*获取定时断送电表*/ { rst = Drive.SetTiVal(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.ToLower().Length == 5 && command.FunType.ToLower().Contains("leak") && CommFunc.ConvertDBNullToInt32(command.FunType.Substring(command.FunType.Length - 1, 1)) > 0)/*漏电流*/ { rst = Drive.GetMeterLeak(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.ToLower().Length == 5 && command.FunType.ToLower().Contains("temp") && CommFunc.ConvertDBNullToInt32(command.FunType.Substring(command.FunType.Length - 1, 1)) > 0)/*漏电流*/ { rst = Drive.GetMeterTemp(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.ToLower().Length == 8 && command.FunType.ToLower().Contains("maxleak") && CommFunc.ConvertDBNullToInt32(command.FunType.Substring(command.FunType.Length - 1, 1)) > 0)/*电流阀值*/ { rst = Drive.SetMaxLeak(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.ToLower().Length == 8 && command.FunType.ToLower().Contains("maxtemp") && CommFunc.ConvertDBNullToInt32(command.FunType.Substring(command.FunType.Length - 1, 1)) > 0)/*温度阀值*/ { rst = Drive.SetMaxTemp(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.ToLower().Length >= 8 && command.FunType.ToLower().Contains("StatusLeak".ToLower()) && CommFunc.ConvertDBNullToInt32(command.FunType.Substring(command.FunType.Length - 1, 1)) > 0)/*电流使能*/ { rst = Drive.SetStatusLeak(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.ToLower().Length >= 8 && command.FunType.ToLower().Contains("StatusTemp".ToLower()) && CommFunc.ConvertDBNullToInt32(command.FunType.Substring(command.FunType.Length - 1, 1)) > 0)/*温度使能*/ { rst = Drive.SetStatusTemp(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Contains(V0Fun.LeakAlarm.ToString()))/*漏电设备告警*/ { rst = Drive.GetLeakAlarm(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.Alarm1.ToString()))/*获取报警电量1限值*/ { rst = Drive.GetAlarm1(command, Network, out send, out result, out lpszVal, out errCode, out msg); } else if (command.FunType.Equals(V0Fun.EventWpf.ToString()))/*记录恶性负载事件*/ { #region 记录恶性负载事件 Dictionary <string, string> list = new Dictionary <string, string>(); rst = Drive.GetEventWpf(command, Network, out send, out result, out list, out errCode, out msg); if (rst == true) { MalignantVModel mv = new MalignantVModel(); mv.CTime = new DateTime(1900, 1, 1); foreach (var item in list) { if (item.Key.Equals("CTime")) { mv.CTime = CommFunc.ConvertDBNullToDateTime(item.Value); } else if (item.Key.Equals("SsrS")) { mv.Status = item.Value; } else if (item.Key.Equals("Ua")) { mv.Ua = CommFunc.ConvertDBNullToDecimal(item.Value); } else if (item.Key.Equals("Ia")) { mv.Ia = CommFunc.ConvertDBNullToDecimal(item.Value); } else if (item.Key.Equals("Psum1")) { mv.Psum1 = CommFunc.ConvertDBNullToDecimal(item.Value); } else if (item.Key.Equals("Psum2")) { mv.Psum2 = CommFunc.ConvertDBNullToDecimal(item.Value); } else if (item.Key.Equals("Psum3")) { mv.Psum3 = CommFunc.ConvertDBNullToDecimal(item.Value); } else if (item.Key.Equals("Psum4")) { mv.Psum4 = CommFunc.ConvertDBNullToDecimal(item.Value); } } lpszVal = null; lpszdateTime = mv.CTime; if (mv.CTime.Year != 1900) { lpszVal = JsonHelper.Serialize(mv); lpszdateTime = mv.CTime; } } #endregion } else { errCode = AlarmType.Err_Nd; } try { DataProcess.YdProcess.Helper.YdDriveSaveCollectCache(command, lpszVal, lpszdateTime, 0, rst, errCode, msg, send, result); } catch (Exception ex) { FileLog.Error("处理ID号:" + this.HandledBY + "处理采集数据错误:" + ex.Message + ex.StackTrace); } }
public DataTable GetMonthAnalysis(int module_id, DateTime time) { DataTable dtRst = new DataTable(); dtRst.Columns.Add("Month", typeof(System.Int32)); /*月份*/ dtRst.Columns.Add("UseVal", typeof(System.Decimal)); /*当月电力*/ dtRst.Columns.Add("UseAmt", typeof(System.Decimal)); /*当月电力*/ dtRst.Columns.Add("Step", typeof(System.Int32)); dtRst.PrimaryKey = new DataColumn[] { dtRst.Columns["Month"] }; // DataTable dtSource = dal.GetPayUseVal(module_id); dtSource.PrimaryKey = new DataColumn[] { dtSource.Columns["Module_id"], dtSource.Columns["Fun_id"] }; StringBuilder splitMdQuery = new StringBuilder(); StringBuilder splitTyQuery = new StringBuilder(); foreach (DataRow dr in dtSource.Rows) { if (!string.IsNullOrEmpty(splitMdQuery.ToString())) { splitMdQuery.Append(","); } splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"])); if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitTyQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["FunType"]), ","))) { if (!string.IsNullOrEmpty(splitTyQuery.ToString())) { splitTyQuery.Append(","); } splitTyQuery.Append(CommFunc.ConvertDBNullToString(dr["FunType"])); } } #region 本月获取存储数据 DateTime fm = new DateTime(time.Year, 1, 1); DateTime to = fm.AddYears(1).AddDays(-1); // DataTable dtUse = WholeBLL.GetCoreQueryData(this.Ledger, splitMdQuery.ToString(), fm, to, "month", splitTyQuery.ToString()); foreach (DataRow dr in dtUse.Rows) { DataRow curDr = dtSource.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] }); if (curDr == null) { continue; } if (CommFunc.ConvertDBNullToInt32(curDr["Co_id"]) != CommFunc.ConvertDBNullToInt32(dr["Co_id"])) /*必须相同房间才计算*/ { continue; } int scale = CommFunc.ConvertDBNullToInt32(curDr["Scale"]); decimal multiply = CommFunc.ConvertDBNullToDecimal(curDr["Multiply"]); decimal price = CommFunc.ConvertDBNullToDecimal(curDr["Price"]); scale = scale == 0 ? 2 : scale; DateTime tagTime = CommFunc.ConvertDBNullToDateTime(dr["TagTime"]); decimal firstVal = CommFunc.ConvertDBNullToDecimal(dr["FirstVal"]); decimal lastVal = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]); decimal useVal = lastVal - firstVal; useVal = Math.Round(useVal * multiply, scale, MidpointRounding.AwayFromZero); decimal useAmt = Math.Round(useVal * price, 2, MidpointRounding.AwayFromZero); /////////////////////////////// DataRow addDr = dtRst.Rows.Find(tagTime.Month); if (addDr == null) { addDr = dtRst.NewRow(); addDr["Month"] = tagTime.Month; addDr["UseVal"] = 0; addDr["UseAmt"] = 0; addDr["Step"] = 1; dtRst.Rows.Add(addDr); } addDr["UseVal"] = CommFunc.ConvertDBNullToDecimal(addDr["UseVal"]) + useVal; addDr["UseAmt"] = CommFunc.ConvertDBNullToDecimal(addDr["UseAmt"]) + useAmt; } int i = 0; while (++i <= 12) { DataRow addDr = dtRst.Rows.Find(i); if (addDr == null) { addDr = dtRst.NewRow(); addDr["Month"] = i; addDr["UseVal"] = 0; addDr["UseAmt"] = 0; addDr["Step"] = 0;/*不存在月份*/ dtRst.Rows.Add(addDr); } } #endregion return(dtRst); }
/// <summary> /// 更新 设备采集状况表 /// </summary> /// <param name="conn1"></param> /// <param name="trans"></param> /// <param name="Co_id"></param> /// <param name="Module_id"></param> /// <param name="ModuleAddr"></param> /// <param name="PayVal"></param> private long YdPrePayInMdOnChangeV2Info(IDbConnection conn1, IDbTransaction trans, int Co_id, int Module_id, string ModuleAddr, decimal PayVal, int payType) { object params01 = new { Ledger = this.Ledger, Co_id = Co_id, Module_id = Module_id, ModuleAddr = ModuleAddr, FunType = (payType == 1 ? V0Fun.Pay.ToString() : V0Fun.Refund.ToString()), SysUid = this.SysUid, Fun_id = 0, PayVal = (decimal)0, DataValue = (decimal)0, DebtTime = DBNull.Value, }; StringBuilder strSql = new StringBuilder(); DataTable dt = new DataTable(); decimal chrgVal = 0, rdVal = 0, multiply = 0; DateTime? debtTime = null; int fun_id = 0, isCharg = 0; strSql.Clear(); strSql.Append("select vf.Fun_id,b.ChrgVal,b.RdVal,b.DebtTime,a.Multiply,a.IsCharg"); //strSql.Append(" from vp_mdinfo as a left join vp_v2info as b on a.Ledger=b.Ledger and a.Co_id=b.Co_id and a.Module_id=b.Module_id and a.ModuleAddr=b.ModuleAddr and b.FunType='E'"); strSql.Append(" from vp_mdinfo as a inner join v0_fun as vf on a.Ledger=vf.Ledger and a.Mm_id=vf.Mm_id and vf.FunType='E'"); strSql.Append(" left join vp_v2info as b on a.Ledger=b.Ledger and a.Co_id=b.Co_id and a.Module_id=b.Module_id and a.ModuleAddr=b.ModuleAddr and vf.Fun_id=b.Fun_id"); strSql.Append(" where a.Ledger=@Ledger and a.Module_id=@Module_id"); dt = SQLHelper.Query(strSql.ToString(), params01); foreach (DataRow dr in dt.Rows) { fun_id = CommFunc.ConvertDBNullToInt32(dr["Fun_id"]); chrgVal = CommFunc.ConvertDBNullToDecimal(dr["ChrgVal"]); rdVal = CommFunc.ConvertDBNullToDecimal(dr["RdVal"]); multiply = CommFunc.ConvertDBNullToDecimal(dr["Multiply"]); isCharg = CommFunc.ConvertDBNullToInt32(dr["IsCharg"]); if (CommFunc.ConvertDBNullToDateTime(dr["DebtTime"]).Year != 1900) { debtTime = CommFunc.ConvertDBNullToDateTime(dr["DebtTime"]); } } // if (multiply == 0) { throw new Exception("倍率不能为零"); } decimal dataValue = PayVal / multiply; decimal payVal = payType == 1 ? dataValue : 0 - dataValue; // if (rdVal + payVal < 0) { debtTime = debtTime == null ? DateTime.Now : debtTime;/*这里可能需要修改,有逻辑错误*/ } else { debtTime = null; } // params01 = new { Ledger = this.Ledger, Co_id = Co_id, Module_id = Module_id, ModuleAddr = ModuleAddr, FunType = (payType == 1 ? V0Fun.Pay.ToString() : V0Fun.Refund.ToString()), SysUid = this.SysUid, Fun_id = fun_id, PayVal = payVal, DataValue = dataValue, DebtTime = debtTime, }; // strSql.Clear(); strSql.Append("INSERT INTO v2_info (Ledger, Co_id, Module_id, ModuleAddr, Fun_id, YT_id, BeginVal, FirstVal, LastVal, MinVal, MaxVal, FirstTime, LastTime, MinTime ,MaxTime,"); strSql.Append("Val1st,Val2nd,Val3rd,val4th,E4Time,ChrgVal,RdVal,MRdVal,DebtTime,Create_by, Create_dt, Update_by, Update_dt)"); strSql.Append("VALUES (@Ledger, @Co_id, @Module_id, @ModuleAddr, @Fun_id, 0, 0, 0, 0, 0, 0, '1900-01-01', '1900-01-01', '1900-01-01', '1900-01-01', "); strSql.Append("0, 0, 0, 0, null , case when @PayVal <=0 then 0 else @PayVal end, @PayVal , @PayVal ,null, @SysUid, NOW(), @SysUid, NOW())"); strSql.Append("ON DUPLICATE KEY UPDATE ChrgVal=case when ChrgVal+@PayVal<=0 then 0 else ChrgVal+@PayVal end,RdVal= RdVal+@PayVal,DebtTime=@DebtTime"); conn1.Execute(strSql.ToString(), params01, trans); // long cmd_log_id = 0; if (isCharg == 1) {/*充值命令*/ strSql.Clear(); strSql.Append("insert into v2_command("); strSql.Append("CDate,Ledger,Co_id,Module_id,ModuleAddr,Fun_id,FunType,DataValue,Create_by,Create_dt,ErrCode)"); strSql.Append("select now(),a.Ledger,@Co_id,a.Module_id,@ModuleAddr,ifnull(b.Fun_id,0),@FunType,@DataValue,@SysUid,now(),0"); strSql.Append(" from vp_mdinfo as a left join v0_fun as b on a.Ledger=b.Ledger and a.Mm_id=b.Mm_id and b.FunType=@FunType"); strSql.Append(" where a.Ledger=@Ledger and a.Module_id=@Module_id;"); strSql.Append("select last_insert_id();"); object obj = conn1.ExecuteScalar(strSql.ToString(), params01, trans); cmd_log_id = CommFunc.ConvertDBNullToLong(obj); } return(cmd_log_id); }
private void GetYdStatusOnLine(DataTable dtSource) { foreach (DataRow dr in dtSource.Rows) { RstVar var = null; //RstVar varSsr = null; int frMd = CommFunc.ConvertDBNullToInt32(dr["FrMd"]); //int ssr = -1; string memcachKey = CommFunc.ConvertDBNullToString(dr["MemcachKey"]); string memcachKeySsr = memcachKey.Replace(".E", ".Ssr"); string cachComm = CommFunc.ConvertDBNullToString(dr["CachComm"]); DateTime lastTime = CommFunc.ConvertDBNullToDateTime(dr["LastTime"]); frMd = frMd == 0 ? 15 : frMd; dr["OnLine"] = 0; dr["Ssr"] = -1; if (lastTime.AddDays(1) < DateTime.Now) { continue; } #region 是否在线 if (!string.IsNullOrEmpty(cachComm)) { var = null; int i = 0; while (var == null && ++i < 2) { var = MemcachedMgr.GetVal <RstVar>(WebConfig.MemcachKey + cachComm); if (var != null) { break; } System.Threading.Thread.Sleep(2); } if (var != null) { dr["OnLine"] = ((int)CommFunc.ConvertDBNullToDecimal(var.lpszVal) == 0) ? 1 : 0; } } else if (!string.IsNullOrEmpty(CommFunc.ConvertDBNullToString(dr["MemcachKey"]))) { var = null; int i = 0; while (var == null && ++i < 2) { var = MemcachedMgr.GetVal <RstVar>(WebConfig.MemcachKey + memcachKey); if (var != null) { //FileLog.WriteLog("key:" + Common.GetMemcachKey + memcachKey + " Val:" + JsonHelper.Serialize(var)); break; } else { //FileLog.WriteLog("空值 key:" + Common.GetMemcachKey + memcachKey); //FileLog.WriteLog("空值 SSr key:" + Common.GetMemcachKey + memcachKeySsr); } System.Threading.Thread.Sleep(2); } if (var != null) { DateTime callTime = var.lpszdateTime; if (callTime >= DateTime.Now.AddMinutes(0 - frMd)) { dr["OnLine"] = 1; } } } #endregion #region 拉合闸状态 if (!string.IsNullOrEmpty(memcachKeySsr)) { var = null; int i = 0; while (var == null && ++i < 2) { var = MemcachedMgr.GetVal <RstVar>(WebConfig.MemcachKey + memcachKeySsr); if (var != null) { break; } System.Threading.Thread.Sleep(2); } if (var != null) { dr["Ssr"] = (int)CommFunc.ConvertDBNullToDecimal(var.lpszVal); } } #endregion //int i = 0; //int onLine = -1; //if (!string.IsNullOrEmpty(CommFunc.ConvertDBNullToString(dr["MemcachKey"]))) //{ // while (var == null && ++i < 2) // { // var = MemcachedMgr.GetVal<RstVar>(WebConfig.MemcachKey + memcachKey); // varSsr = MemcachedMgr.GetVal<RstVar>(WebConfig.MemcachKey + memcachKeySsr); // if (var != null || varSsr != null) // { // //FileLog.WriteLog("key:" + WebConfig.MemcachKey + memcachKey + " Val:" + JsonHelper.Serialize(var)); // break; // } // else // { // //FileLog.WriteLog("空值 key:" + WebConfig.MemcachKey + memcachKey); // //FileLog.WriteLog("空值 SSr key:" + WebConfig.MemcachKey + memcachKeySsr); // } // System.Threading.Thread.Sleep(2); // } //} //onLine = 0; //if (var != null) //{ // DateTime callTime = var.lpszdateTime; // if (callTime >= DateTime.Now.AddMinutes(0 - frMd)) // onLine = 1; //} //if (varSsr != null) // ssr = CommFunc.ConvertDBNullToInt32(varSsr.lpszVal); //dr["OnLine"] = onLine; //dr["Ssr"] = ssr; } }
public DataTable GetRptPSWayList(int areaId, DateTime start, DateTime end, string psWay) { #region 表结构 DataTable dtRst = new DataTable(); dtRst.Columns.Add("StationId", typeof(System.Int32)); // 机房ID号 dtRst.Columns.Add("PSWay", typeof(System.String)); // 供电方式 dtRst.Columns.Add("StationNo", typeof(System.String)); // 机房编号 dtRst.Columns.Add("Start", typeof(System.DateTime)); //当前开始时间 dtRst.Columns.Add("End", typeof(System.DateTime)); //当前结束时间 dtRst.Columns.Add("StationName", typeof(System.String)); // 机房名称 dtRst.Columns.Add("StrcName", typeof(System.String)); // 所属区域 dtRst.Columns.Add("Address", typeof(System.String)); // 机房地址 dtRst.Columns.Add("PSWayName", typeof(System.String)); // 机房类型名称 dtRst.Columns.Add("UseVal", typeof(System.Decimal)); //使用电值 dtRst.Columns.Add("LastTime", typeof(System.String)); // 最后录入时间 #endregion #region 填充基础数据 StringBuilder splitMdQuery = new StringBuilder(); DataTable dtSource = dal.GetRptPSWayData(areaId, psWay); dtRst.PrimaryKey = new DataColumn[] { dtRst.Columns["StationId"], dtRst.Columns["PSWay"] }; dtSource.PrimaryKey = new DataColumn[] { dtSource.Columns["Module_id"], dtSource.Columns["Fun_id"] }; foreach (DataRow dr in dtSource.Rows) { if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitMdQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["Module_id"]), ","))) { if (!string.IsNullOrEmpty(splitMdQuery.ToString())) { splitMdQuery.Append(","); } splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"])); } DataRow addDr = dtRst.Rows.Find(new object[] { dr["Parent_id"], dr["PSWay"] }); if (addDr == null) { addDr = dtRst.NewRow(); addDr["StationId"] = dr["Parent_id"]; addDr["PSWay"] = dr["PSWay"]; addDr["StationNo"] = dr["CoNo"]; addDr["Start"] = start; addDr["End"] = end; addDr["StationName"] = dr["CoName"]; addDr["StrcName"] = dr["CoStrcName"]; addDr["Address"] = dr["CustAddr"]; addDr["PSWayName"] = CommFunc.GetEnumDisplay(typeof(Switch), CommFunc.ConvertDBNullToString(dr["PSWay"])); dtRst.Rows.Add(addDr); } } #endregion #region 填充采集数据 DataTable dtUse = WholeBLL.GetCoreQueryData(this.Ledger, splitMdQuery.ToString(), start, end, "day"); foreach (DataRow dr in dtUse.Rows) { DataRow curDr = dtSource.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] }); if (curDr == null) { continue; } int scale = CommFunc.ConvertDBNullToInt32(curDr["Scale"]); int stationId = CommFunc.ConvertDBNullToInt32(curDr["Parent_id"]); decimal multiply = CommFunc.ConvertDBNullToDecimal(curDr["Multiply"]); DateTime tagtime = CommFunc.ConvertDBNullToDateTime(dr["TagTime"]); decimal firstVal = CommFunc.ConvertDBNullToDecimal(dr["FirstVal"]); decimal lastVal = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]); decimal useVal = (lastVal - firstVal) * multiply; scale = scale == 0 ? 2 : scale; useVal = Math.Round(useVal, scale, MidpointRounding.AwayFromZero); DataRow addDr = dtRst.Rows.Find(new object[] { stationId, curDr["PSWay"] }); if (addDr == null) { continue; } addDr["UseVal"] = CommFunc.ConvertDBNullToDecimal(addDr["UseVal"]) + useVal; if (CommFunc.ConvertDBNullToDateTime(addDr["LastTime"]) < CommFunc.ConvertDBNullToDateTime(dr["LastTime"])) { addDr["LastTime"] = dr["LastTime"]; } } #endregion return(dtRst); }
internal bool GetAlarm() { DataTable dtSource = null; DataTable dtAlarmConfig = null; try { dtAlarmConfig = bll.GetAlarmConfig(); int cnt = dtAlarmConfig.Rows.Count; decimal alarmVal1 = cnt == 0 ? 0 : CommFunc.ConvertDBNullToDecimal(dtAlarmConfig.Rows[0]["CfValue"]); string unit = cnt == 0 ? "" : CommFunc.ConvertDBNullToString(dtAlarmConfig.Rows[0]["Unit"]); dtSource = bll.GetAlarmData(alarmVal1, unit); } catch (Exception ex) { FileLog.WriteLog("获取告警数据错误:" + ex.Message + ex.StackTrace); } // if (dtSource == null) { return(false); } Thread.Sleep(100); int co_idPrev = -9999; foreach (DataRow dr in dtSource.Rows) { int co_id = CommFunc.ConvertDBNullToInt32(dr["Co_id"]); string coName = CommFunc.ConvertDBNullToString(dr["CoName"]); int chrgType = CommFunc.ConvertDBNullToInt32(dr["ChrgType"]); /*<=1 房间 >1电表*/ int isAlarm = CommFunc.ConvertDBNullToInt32(dr["IsAlarm"]); /*<=1 房间 >1电表*/ DateTime lastTime = CommFunc.ConvertDBNullToDateTime(dr["LastTime"]); int transferType = CommFunc.ConvertDBNullToInt32(dr["TransferType"]); decimal rdVal = CommFunc.ConvertDBNullToDecimal(dr["RdVal"]); decimal price = CommFunc.ConvertDBNullToDecimal(dr["Price"]); decimal rdAmt = CommFunc.ConvertDBNullToDecimal(dr["RdAmt"]); int module_id = CommFunc.ConvertDBNullToInt32(dr["Module_id"]); string moduleAddr = CommFunc.ConvertDBNullToString(dr["ModuleAddr"]); string moduleName = CommFunc.ConvertDBNullToString(dr["ModuleName"]); string cfKey = "", cfUnit = ""; decimal cfValue = 0; decimal cfRule = 1; bool isRun = true; if (chrgType <= 1 && co_idPrev == co_id) { isRun = false; } co_idPrev = co_id; if (isRun == false) { continue; } int ccc = dtAlarmConfig.Rows.Count; int crn = 0; foreach (DataRow drC in dtAlarmConfig.Rows) {/*从大到小排列*/ cfKey = CommFunc.ConvertDBNullToString(drC["CfKey"]); cfValue = CommFunc.ConvertDBNullToDecimal(drC["CfValue"]); cfRule = CommFunc.ConvertDBNullToDecimal(drC["Rule"]); cfUnit = CommFunc.ConvertDBNullToString(drC["Unit"]).ToLower(); if (pro.Project.Equals("YdXip") && cfKey.Equals("AlarmValOd")) {/*西安培华的拉闸电量*/ cfValue = CommFunc.ConvertDBNullToDecimal(dr["OdValue"]); } //if (!cfKey.ToLower().Equals("AlarmValOd".ToLower())) // cfRule = cfRule == 0 ? 1 : cfRule; decimal comVal = string.IsNullOrEmpty(cfUnit) || cfUnit.Equals("kWh".ToLower()) ? rdVal : rdAmt; decimal toValue = cfValue; if (crn < ccc - 1) { toValue = CommFunc.ConvertDBNullToDecimal(dtAlarmConfig.Rows[crn + 1]["CfValue"]); } if (cfValue >= comVal && comVal > toValue) { break; } crn = crn + 1; } //FileLog.WriteLog("电表ID:" + module_id + "地址:" + moduleAddr + "房间:" + coName + "剩余电量:" + rdVal + "告警类型:" + cfKey + "规则:" + cfRule + "告警值:" + cfValue); bool sendAlarm = true; if (cfKey.ToLower().Equals("AlarmValOd".ToLower()) && isAlarm == 1) { /*拉合闸*/ if (CommFunc.ConvertDBNullToInt32(cfRule) == 1) { /*发送拉合闸命令*/ sendAlarm = false; try { string key = pro.ProjectKey + CommFunc.ConvertDBNullToString(dr["LpszSsr"]); RstVar rstVar = MemcachedMgr.GetVal <RstVar>(key); bool isPass = false; if (rstVar != null && CommFunc.ConvertDBNullToDecimal(rstVar.lpszVal) == 0) { isPass = true; } if (isPass == true) { this.CtorlSsr1(module_id); } } catch (Exception ex) { FileLog.Error("透支电量发送拉合闸命令错误:" + ex.Message + ex.StackTrace); } } } if (sendAlarm == true) {/*发送告警*/ cfRule = cfRule == 0 ? 1 : cfRule; v2_alarm_logVModel alarmInfo = this.AlarmInfo(dr, cfValue, cfRule); if (isAlarm == 1) { if (!string.IsNullOrEmpty(EmailUtilities.EmConfig.MailFrom) && !string.IsNullOrEmpty(EmailUtilities.EmConfig.MailSmtpHost) && !string.IsNullOrEmpty(EmailUtilities.EmConfig.MailSmtpUser) && !string.IsNullOrEmpty(EmailUtilities.EmConfig.MailSmtpPassword) ) {/*邮件告警*/ this.AlarmEmail(alarmInfo.Log_id, co_id, coName, lastTime, rdVal); } if (!string.IsNullOrEmpty(pro.Sms.ComSmsConfig.ComSms) || (!string.IsNullOrEmpty(SmsFun.AliSmsConfig.AliAppKey) && !string.IsNullOrEmpty(SmsFun.AliSmsConfig.AliAppSecret) && !string.IsNullOrEmpty(SmsFun.AliSmsConfig.AliSignName)) ) {/*短信告警*/ this.AlarmSms(alarmInfo.Log_id, co_id, moduleName, coName, lastTime, rdVal, rdAmt); } if (!string.IsNullOrEmpty(pro.Wx.WxConfig.WxAPPID)) {/*微信告警*/ //this.AlarmWx(alarmInfo.Log_id, co_id, coName, lastTime, rdVal); } } } } return(true); }
private object GetYdMonitorOnList(DataTable dtSource) { var res1 = from s1 in dtSource.AsEnumerable() select new { RowId = CommFunc.ConvertDBNullToInt32(s1["RowId"]), Module_id = CommFunc.ConvertDBNullToInt32(s1["Module_id"]), ModuleAddr = CommFunc.ConvertDBNullToString(s1["ModuleAddr"]), ModuleName = CommFunc.ConvertDBNullToString(s1["ModuleName"]), Co_id = CommFunc.ConvertDBNullToInt32(s1["Co_id"]), CoStrcName = CommFunc.ConvertDBNullToString(s1["CoStrcName"]), CoName = CommFunc.ConvertDBNullToString(s1["CoName"]), Multiply = CommFunc.ConvertDBNullToDecimal(s1["Multiply"]).ToString("f2"), LastVal = Convert.IsDBNull(s1["LastVal"]) ? "" : CommFunc.ConvertDBNullToDecimal(s1["LastVal"]).ToString("f2"), CurVal = Convert.IsDBNull(s1["CurVal"]) ? "" : CommFunc.ConvertDBNullToDecimal(s1["CurVal"]).ToString("f2"), RdVal = Convert.IsDBNull(s1["RdVal"]) ? "" : CommFunc.ConvertDBNullToDecimal(s1["RdVal"]).ToString("f2"), SyZsVal = Convert.IsDBNull(s1["SyZsVal"]) ? "" : CommFunc.ConvertDBNullToDecimal(s1["SyZsVal"]).ToString("f2"), LastTime = (CommFunc.ConvertDBNullToDateTime(s1["LastTime"]).Year == 1900 || CommFunc.ConvertDBNullToDateTime(s1["LastTime"]).Year == 0) ? "" : CommFunc.ConvertDBNullToDateTime(s1["LastTime"]).ToString("yyyy-MM-dd HH:mm:ss"), Ssr = s1["Ssr"] == DBNull.Value ? -1 : CommFunc.ConvertDBNullToInt32(s1["Ssr"]), DayUseVal = "", MthUseVal = "", HandledBY = CommFunc.ConvertDBNullToString(s1["HandledBY"]), OnLine = CommFunc.ConvertDBNullToInt32(s1["OnLine"]), IsAlarm = CommFunc.ConvertDBNullToInt32(s1["IsAlarm"]), RdAmt = (CommFunc.ConvertDBNullToDecimal(s1["RdVal"]) * CommFunc.ConvertDBNullToDecimal(s1["Price"])).ToString("f2"), SyVal = (CommFunc.ConvertDBNullToDecimal(s1["RdVal"]) - CommFunc.ConvertDBNullToDecimal(s1["SyZsVal"])).ToString("f2"), PicType = CommFunc.ConvertDBNullToString(s1["ModuleType"]).Contains("-NB") ? 1 : 0, @checked = 0 }; return(res1.ToList()); }
//private static SendMessageApi send = new SendMessageApi();//uniPush初始化参数 public void Run() { while (true) { Thread.Sleep(100);/*每100毫秒*/ v2_alarm_logVModel cc = null; if (NCSys.AlarmCollect.TryDequeue(out cc) == true) { try { DataProcessBLL bll = new DataProcessBLL(cc.Ledger, Config.Uid); long log_id = bll.AddAlarm(cc); if (cc.IsMqtt == true) { object dy = new { cc = cc, time = DateTime.Now, count = 0 }; m2mqtt.TryAdd(log_id, dy); } } catch (Exception ex) { FileLog.Error("内容:" + JsonHelper.Serialize(cc) + "记录告警错误:" + ex.Message + ex.StackTrace); } } try {/*告警信息半个钟推一次,一共需要6次,现场确认下来了*/ /*2020.01.06 最新修改设置 告警信息一分钟推一次,一共需要10次*/ bool bIsNext = true; var enumer = m2mqtt.GetEnumerator(); while (bIsNext == true) { Thread.Sleep(1000);/*每100毫秒*/ bIsNext = enumer.MoveNext(); if (bIsNext == false) { break; } var s0 = enumer.Current; long key = s0.Key; object obj = s0.Value; v2_alarm_logVModel am = CommFunc.GetPropertyValue("cc", obj) as v2_alarm_logVModel; DateTime dd = CommFunc.ConvertDBNullToDateTime(CommFunc.GetPropertyValue("time", obj)); int count = CommFunc.ConvertDBNullToInt32(CommFunc.GetPropertyValue("count", obj)); bool isUp = false; int Log_id = 0; int Co_id = 0; if (count == 0 || DateTime.Now >= dd.AddMinutes(1)) //一分钟推一次 { //权限过滤 DataProcessBLL bll = new DataProcessBLL(am.Ledger, Config.Uid); //string AreaPowerStr = ""; //bool IsCheckAreaPower = bll.GetAlarmFisrt(am.Ledger, Config.Uid, out AreaPowerStr); //bool qx = false; //string[] sArray = AreaPowerStr.Split(','); var datas = bll.Getv2_alarm_log(CommFunc.ConvertDBNullToInt32(key)); //历史表 if (datas.Rows.Count > 0) { Log_id = CommFunc.ConvertDBNullToInt32(datas.Rows[0]["Log_id"].ToString()); Co_id = CommFunc.ConvertDBNullToInt32(datas.Rows[0]["Co_id"].ToString()); //var Content = datas.Rows[0]["Content"].ToString(); //foreach (string i in sArray) //{ // if (Co_id == CommFunc.ConvertDBNullToInt32(i)) // { // qx = true; // continue; // } //} } //if (qx) //{ var content = am.Content + "," + Co_id; DataProcess.Business.m2mqtt.Publish(content); //send.send(content,"CID");//uniPush推送 count = count + 1; isUp = true; FileLog.WriteLog("Log_id:" + key + " 推送次数:" + count); //} //FileLog.WriteLog("+++++++ Ledger;" + am.Ledger + " Uid;" + Config.Uid + " Log_id:" + key + " 库Log_id:" + am.Log_id + " 库Co_id:" + Co_id + " 权限ID:" + AreaPowerStr + " +++++++"); } if (count == 10) {//一共需要10次 m2mqtt.TryRemove(key, out obj); FileLog.WriteLog("Log_id:" + key + " 推送:" + count + "移除"); } else { if (isUp == true) { object newObj = new { cc = am, time = DateTime.Now, count = count }; if (m2mqtt.TryUpdate(key, newObj, obj)) { FileLog.WriteLog("Log_id:" + key + " 推送:" + count + " 更新成功!"); } } } } } catch (Exception ex) { //m2mqtt.Clear(); //移除所有的键和值. FileLog.Error("推送mqtt记录内容错误:" + ex.Message + ex.StackTrace); } } }
public List <YdRepHisVModel> GetYdRepHisList(DateTime dtFirst, DateTime dtLast, string CoStrcName, string CoName, int IsMultiply, params string[] funTypeParams) { List <YdRepHisVModel> list = new List <YdRepHisVModel>(); var dtModules = dal.GetModuleListByOrg(CoStrcName, CoName, funTypeParams); var modulesEnum = from s1 in dtModules.AsEnumerable() select new { Module_id = CommFunc.ConvertDBNullToInt32(s1["Module_id"]), ModuleName = CommFunc.ConvertDBNullToString(s1["ModuleName"]), ModuleAddr = CommFunc.ConvertDBNullToString(s1["ModuleAddr"]), Co_id = CommFunc.ConvertDBNullToInt32(s1["Co_id"]), CoStrcName = CommFunc.ConvertDBNullToString(s1["CoStrcName"]), CoName = CommFunc.ConvertDBNullToString(s1["CoName"]), Multiply = CommFunc.ConvertDBNullToDecimal(s1["Multiply"]), FunType = CommFunc.ConvertDBNullToString(s1["FunType"]) }; if (modulesEnum == null || modulesEnum.Count() == 0) { return(list); } var modulesList = modulesEnum.ToList(); HashSet <int> ds = new HashSet <int>(); for (int i = 0; i < modulesList.Count; i++) { ds.Add(modulesList[i].Module_id); } var dtSourceFirst = WholeBLL.GetCoreQueryData(this.Ledger, string.Join(",", ds), dtFirst, dtFirst, "day"); var dtSourceLast = WholeBLL.GetCoreQueryData(this.Ledger, string.Join(",", ds), dtLast, dtLast, "day"); var sourceFirst = from a in dtSourceFirst.AsEnumerable() select new { Tagtime = CommFunc.ConvertDBNullToDateTime(a["Tagtime"]), Co_id = CommFunc.ConvertDBNullToInt32(a["Co_id"]), Fun_id = CommFunc.ConvertDBNullToInt32(a["Fun_id"]), Module_id = CommFunc.ConvertDBNullToInt32(a["Module_id"]), ModuleAddr = CommFunc.ConvertDBNullToString(a["ModuleAddr"]), FirstVal = CommFunc.ConvertDBNullToDecimal(a["FirstVal"]), LastVal = CommFunc.ConvertDBNullToDecimal(a["LastVal"]) }; var sourceLast = from a in dtSourceLast.AsEnumerable() select new { Tagtime = CommFunc.ConvertDBNullToDateTime(a["Tagtime"]), Co_id = CommFunc.ConvertDBNullToInt32(a["Co_id"]), Fun_id = CommFunc.ConvertDBNullToInt32(a["Fun_id"]), Module_id = CommFunc.ConvertDBNullToInt32(a["Module_id"]), ModuleAddr = CommFunc.ConvertDBNullToString(a["ModuleAddr"]), FirstVal = CommFunc.ConvertDBNullToDecimal(a["FirstVal"]), LastVal = CommFunc.ConvertDBNullToDecimal(a["LastVal"]) }; var sourceFirstList = sourceFirst.ToList(); var sourceLastList = sourceLast.ToList(); for (int i = 0; i < modulesList.Count; i++) { var model = new YdRepHisVModel(); model.ID = i + 1; model.Co_id = modulesList[i].Co_id; model.CoName = modulesList[i].CoName; model.CoStrcName = modulesList[i].CoStrcName; model.Date = dtFirst.ToString("yyyy-MM-dd") + "~" + dtLast.ToString("yyyy-MM-dd"); model.Multiply = modulesList[i].Multiply.ToString("f2"); model.FirstVal = "NULL"; model.LastVal = "NULL"; model.UseVal = "NULL"; model.ModuleName = modulesList[i].ModuleName; model.ModuleAddr = modulesList[i].ModuleAddr; model.Module_id = modulesList[i].Module_id; var firstObj = sourceFirstList.Where(c => c.Co_id == model.Co_id && c.Module_id == model.Module_id && c.ModuleAddr == model.ModuleAddr).FirstOrDefault(); if (firstObj != null) { model.FirstVal = IsMultiply == 1 ? (firstObj.FirstVal * modulesList[i].Multiply).ToString("f2") : firstObj.FirstVal.ToString("f2"); } var lastObj = sourceLastList.Where(c => c.Co_id == model.Co_id && c.Module_id == model.Module_id && c.ModuleAddr == model.ModuleAddr).FirstOrDefault(); if (lastObj != null) { model.LastVal = IsMultiply == 1 ? (lastObj.LastVal * modulesList[i].Multiply).ToString("f2") : lastObj.LastVal.ToString("f2"); } if (firstObj != null && lastObj != null) { model.UseVal = IsMultiply == 1 ? ((lastObj.LastVal - firstObj.FirstVal) * modulesList[i].Multiply).ToString("f2") : (lastObj.LastVal - firstObj.FirstVal).ToString("f2"); } list.Add(model); } return(list); }
/// <summary> /// 电量电费 /// </summary> /// <param name="module_id"></param> /// <returns></returns> public DataTable GetElectricity(int module_id) { DataTable dtRst = new DataTable(); dtRst.Columns.Add("UseVal", typeof(System.Decimal)); /*当月电力*/ dtRst.Columns.Add("UseAmt", typeof(System.Decimal)); /*当月电力*/ dtRst.Columns.Add("UpUseVal", typeof(System.Decimal)); /*上一月电量*/ dtRst.Columns.Add("UpUseAmt", typeof(System.Decimal)); /*上一月电费*/ dtRst.Columns.Add("LastVal", typeof(System.Decimal)); /*当前表码值*/ // dtRst.Rows.Add(new object[] { 0, 0, 0, 0, 0 }); DataRow rstDr = dtRst.Rows[0]; // DataTable dtSource = dal.GetPayUseVal(module_id); dtSource.PrimaryKey = new DataColumn[] { dtSource.Columns["Module_id"], dtSource.Columns["Fun_id"] }; StringBuilder splitMdQuery = new StringBuilder(); StringBuilder splitTyQuery = new StringBuilder(); foreach (DataRow dr in dtSource.Rows) { if (!string.IsNullOrEmpty(splitMdQuery.ToString())) { splitMdQuery.Append(","); } splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"])); if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitTyQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["FunType"]), ","))) { if (!string.IsNullOrEmpty(splitTyQuery.ToString())) { splitTyQuery.Append(","); } splitTyQuery.Append(CommFunc.ConvertDBNullToString(dr["FunType"])); } rstDr["LastVal"] = dr["LastVal"]; } #region 本月获取存储数据 DateTime fm = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); DateTime to = fm.AddMonths(1).AddDays(-1); // DataTable dtUse = WholeBLL.GetCoreQueryData(this.Ledger, splitMdQuery.ToString(), fm, to, "month", splitTyQuery.ToString()); foreach (DataRow dr in dtUse.Rows) { DataRow curDr = dtSource.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] }); if (curDr == null) { continue; } if (CommFunc.ConvertDBNullToInt32(curDr["Co_id"]) != CommFunc.ConvertDBNullToInt32(dr["Co_id"])) /*必须相同房间才计算*/ { continue; } int scale = CommFunc.ConvertDBNullToInt32(curDr["Scale"]); decimal multiply = CommFunc.ConvertDBNullToDecimal(curDr["Multiply"]); decimal price = CommFunc.ConvertDBNullToDecimal(curDr["Price"]); scale = scale == 0 ? 2 : scale; DateTime tagTime = CommFunc.ConvertDBNullToDateTime(dr["TagTime"]); decimal firstVal = CommFunc.ConvertDBNullToDecimal(dr["FirstVal"]); decimal lastVal = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]); decimal useVal = lastVal - firstVal; useVal = Math.Round(useVal * multiply, scale, MidpointRounding.AwayFromZero); decimal useAmt = Math.Round(useVal * price, 2, MidpointRounding.AwayFromZero); rstDr["UseVal"] = CommFunc.ConvertDBNullToDecimal(rstDr["UseVal"]) + useVal; rstDr["UseAmt"] = CommFunc.ConvertDBNullToDecimal(rstDr["UseAmt"]) + useAmt; } #endregion #region 月月获取存储数据 fm = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); to = fm.AddDays(-1); fm = new DateTime(to.Year, to.Month, 1); // dtUse = WholeBLL.GetCoreQueryData(this.Ledger, splitMdQuery.ToString(), fm, to, "month", splitTyQuery.ToString()); foreach (DataRow dr in dtUse.Rows) { DataRow curDr = dtSource.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] }); if (curDr == null) { continue; } if (CommFunc.ConvertDBNullToInt32(curDr["Co_id"]) != CommFunc.ConvertDBNullToInt32(dr["Co_id"])) /*必须相同房间才计算*/ { continue; } int scale = CommFunc.ConvertDBNullToInt32(curDr["Scale"]); decimal multiply = CommFunc.ConvertDBNullToDecimal(curDr["Multiply"]); decimal price = CommFunc.ConvertDBNullToDecimal(curDr["Price"]); scale = scale == 0 ? 2 : scale; DateTime tagTime = CommFunc.ConvertDBNullToDateTime(dr["TagTime"]); decimal firstVal = CommFunc.ConvertDBNullToDecimal(dr["FirstVal"]); decimal lastVal = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]); decimal useVal = lastVal - firstVal; useVal = Math.Round(useVal * multiply, scale, MidpointRounding.AwayFromZero); decimal useAmt = Math.Round(useVal * price, 2, MidpointRounding.AwayFromZero); rstDr["UpUseVal"] = CommFunc.ConvertDBNullToDecimal(rstDr["UpUseVal"]) + useVal; rstDr["UpUseAmt"] = CommFunc.ConvertDBNullToDecimal(rstDr["UpUseAmt"]) + useAmt; } #endregion return(dtRst); }
/// <summary> /// 获取分项统计 /// </summary> /// <param name="co_id">支路ID号</param> /// <param name="time">时间</param> /// <param name="dataType">类型 日=day月=month年year</param> /// <returns></returns> public DataTable GetEnergyHisdata(int co_id, DateTime start, DateTime end, string moduleName, string funType) { DateTime dtFirst = new DateTime(start.Year, start.Month, start.Day, 0, 0, 0); DateTime dtLast = new DateTime(end.Year, end.Month, end.Day, 23, 59, 59); DataTable dtRst = new DataTable(); dtRst.Columns.Add("TagTime", typeof(System.DateTime)); dtRst.Columns.Add("Module_id", typeof(System.Int32)); dtRst.Columns.Add("Fun_id", typeof(System.Int32)); dtRst.Columns.Add("ModuleAddr", typeof(System.String)); dtRst.Columns.Add("ModuleName", typeof(System.String)); dtRst.Columns.Add("MeterNo", typeof(System.String)); dtRst.Columns.Add("LastVal", typeof(System.Decimal)); dtRst.Columns.Add("FunName", typeof(System.String)); dtRst.Columns.Add("CoName", typeof(System.String)); dtRst.PrimaryKey = new DataColumn[] { dtRst.Columns["TagTime"], dtRst.Columns["Module_id"], dtRst.Columns["Fun_id"] }; DataTable dtSource = dal.GetEnergyHisdata(co_id, moduleName, funType); dtSource.PrimaryKey = new DataColumn[] { dtSource.Columns["Module_id"], dtSource.Columns["Fun_id"] }; StringBuilder splitMdQuery = new StringBuilder(); StringBuilder splitTyQuery = new StringBuilder(); foreach (DataRow dr in dtSource.Rows) { if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitMdQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["Module_id"]), ","))) { if (!string.IsNullOrEmpty(splitMdQuery.ToString())) { splitMdQuery.Append(","); } splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"])); } if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitTyQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["FunType"]), ","))) { if (!string.IsNullOrEmpty(splitTyQuery.ToString())) { splitTyQuery.Append(","); } splitTyQuery.Append(CommFunc.ConvertDBNullToString(dr["FunType"])); } } DateTime ucStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long ucUnit = 10000000; #region 获取历史数据 DataTable dtUse = WholeBLL.GetCoreQueryData(this.Ledger, splitMdQuery.ToString(), dtFirst, dtLast, "hour", splitTyQuery.ToString()); foreach (DataRow dr in dtUse.Rows) { DataRow curDr = dtSource.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] }); if (curDr == null) { continue; } int scale = CommFunc.ConvertDBNullToInt32(curDr["Scale"]); decimal multiply = CommFunc.ConvertDBNullToDecimal(curDr["Multiply"]); // DateTime tagtime = CommFunc.ConvertDBNullToDateTime(dr["TagTime"]); decimal firstVal = CommFunc.ConvertDBNullToDecimal(dr["FirstVal"]); decimal lastVal = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]); //int interval = CommFunc.ConvertDBNullToInt32(dr["Interval"]); string dataCfg = CommFunc.ConvertDBNullToString(dr["DataCfg"]); dataCfg = string.IsNullOrEmpty(dataCfg) ? "0:0" : dataCfg; foreach (string s in dataCfg.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { string[] val = s.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (val.Length != 2) { continue; } long ticks = CommFunc.ConvertDBNullToLong(val[0]); decimal value = CommFunc.ConvertDBNullToDecimal(val[1]); if (CommFunc.ConvertDBNullToString(curDr["FunType"]).Equals(V0Fun.E.ToString()) || CommFunc.ConvertDBNullToString(curDr["FunType"]).Equals(V0Fun.EAnt.ToString()) || CommFunc.ConvertDBNullToInt32(curDr["IsChrg"]) == 1) { value = value + firstVal; } long ts = ticks + ((tagtime - ucStart).Ticks / 10000); TimeSpan toNow = new TimeSpan(ticks * ucUnit + ((tagtime - ucStart).Ticks)); DateTime tickTime = ucStart.Add(toNow); //tagtime.AddTicks(ticks); DataRow addDr = dtRst.Rows.Find(new object[] { tickTime, dr["Module_id"], dr["Fun_id"] }); if (addDr == null) { addDr = dtRst.NewRow(); addDr["TagTime"] = tickTime; addDr["Module_id"] = dr["Module_id"]; addDr["Fun_id"] = dr["Fun_id"]; addDr["ModuleAddr"] = curDr["ModuleAddr"]; addDr["ModuleName"] = curDr["ModuleName"]; addDr["FunName"] = curDr["FunName"]; addDr["CoName"] = curDr["CoName"]; addDr["MeterNo"] = curDr["MeterNo"]; dtRst.Rows.Add(addDr); } addDr["LastVal"] = value.ToString("f" + scale); } } #endregion return(dtRst); }
public object GetPduFunTypes(int co_id, string funTypes) { //string funType = string.Join(",", funTypes.ToArray()); string funType = funTypes;// DateTime today2 = DateTime.Now.AddHours(-1); DateTime today1 = new DateTime(today2.Year, today2.Month, today2.Day); Dictionary <string, List <decimal> > rr = new Dictionary <string, List <decimal> >(); foreach (string str in funTypes.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { List <decimal> todayList = new List <decimal>(); if (rr.TryGetValue(str, out todayList) == false) { todayList = new List <decimal>(); int nn = today2.Hour; while (nn-- >= 0) { todayList.Add(0); } rr.Add(str, todayList); } } // DataTable dtSource = dal.GetPduFunTypes(co_id, funType); dtSource.PrimaryKey = new DataColumn[] { dtSource.Columns["Module_id"], dtSource.Columns["Fun_id"] }; StringBuilder splitMdQuery = new StringBuilder(); StringBuilder splitTyQuery = new StringBuilder(); foreach (DataRow dr in dtSource.Rows) { if (string.IsNullOrEmpty(splitMdQuery.ToString())) { splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"])); } //if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitMdQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["Module_id"]), ","))) //{ // if (!string.IsNullOrEmpty(splitMdQuery.ToString())) // splitMdQuery.Append(","); // splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"])); //} if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitTyQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["FunType"]), ","))) { if (!string.IsNullOrEmpty(splitTyQuery.ToString())) { splitTyQuery.Append(","); } splitTyQuery.Append(CommFunc.ConvertDBNullToString(dr["FunType"])); } } DataTable dtUse1 = WholeBLL.GetCoreQueryData(this.Ledger, splitMdQuery.ToString(), today1, today2, "hour", splitTyQuery.ToString()); decimal todayUse = 0; foreach (DataRow dr in dtUse1.Rows) { DataRow curDr = dtSource.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] }); if (curDr == null) { continue; } int scale = CommFunc.ConvertDBNullToInt32(curDr["Scale"]); int isChrg = CommFunc.ConvertDBNullToInt32(curDr["IsChrg"]); decimal multiply = CommFunc.ConvertDBNullToDecimal(curDr["Multiply"]); scale = scale == 0 ? 2 : scale; // DateTime tagTime = CommFunc.ConvertDBNullToDateTime(dr["TagTime"]); decimal firstVal = CommFunc.ConvertDBNullToDecimal(dr["FirstVal"]); decimal lastVal = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]); decimal useVal = 0; if (isChrg == 1) { useVal = lastVal - firstVal; useVal = Math.Round(useVal * multiply, scale, MidpointRounding.AwayFromZero); // List <decimal> todayList = new List <decimal>(); if (rr.TryGetValue(CommFunc.ConvertDBNullToString(curDr["FunType"]), out todayList) == true) { todayList[tagTime.Hour] = CommFunc.ConvertDBNullToDecimal(todayList[tagTime.Hour]) + useVal; todayUse = todayUse + useVal; } } else { useVal = lastVal; useVal = Math.Round(useVal * multiply, scale, MidpointRounding.AwayFromZero); // List <decimal> todayList = new List <decimal>(); if (rr.TryGetValue(CommFunc.ConvertDBNullToString(curDr["FunType"]), out todayList) == true) { todayList[tagTime.Hour] = CommFunc.ConvertDBNullToDecimal(todayList[tagTime.Hour]) > useVal?CommFunc.ConvertDBNullToDecimal(todayList[tagTime.Hour]) : useVal; todayUse = todayUse > useVal ? todayUse : useVal; } } } List <object> dd = new List <object>(); foreach (var ss in rr) { dd.Add(new { funType = ss.Key, list = ss.Value }); } return(dd); }
public object GetEnergyForDayX261() { DateTime fm = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); DateTime to = DateTime.Now.AddHours(-1); List <decimal> dd = new List <decimal>(); int nn = to.Hour; while (nn-- >= 0) { dd.Add(0); } DataTable dtRst = new DataTable(); dtRst.Columns.Add("ModuleAddr", typeof(System.String)); dtRst.Columns.Add("ModuleName", typeof(System.String)); dtRst.Columns.Add("ParentName", typeof(System.String)); dtRst.Columns.Add("UseVal", typeof(System.Decimal)); dtRst.Columns.Add("UseObj", typeof(System.Object)); dtRst.Rows.Add("R6B2.X261.ⅠE", "X261 OP30/40", "焊接X261 OP30/40", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd))); dtRst.Rows.Add("R6B1.1#.LJ", "1# X261 OP30/40", "焊接X261 OP30/40", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd))); dtRst.Rows.Add("R6B1.2#.LJ", "2# X261 OP30/40", "焊接X261 OP30/40", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd))); dtRst.Rows.Add("R6B2.X261.ⅡE", "X261 OP45/50", "焊接X261 OP45/50", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd))); dtRst.Rows.Add("R6B1.3#.LJ", "3# X261 OP45/50", "焊接X261 OP45/50", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd))); dtRst.Rows.Add("R6B1.4#.LJ", "4# X261 OP45/50", "焊接X261 OP45/50", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd))); dtRst.Rows.Add("R6B2.X261.ⅢE", "X261 OP60/70", "焊接X261 OP60/70", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd))); dtRst.Rows.Add("R6B1.5#.LJ", "5# X261 OP60/70", "焊接X261 OP60/70", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd))); dtRst.Rows.Add("R6B1.6#.LJ", "6# X261 OP60/70", "焊接X261 OP60/70", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd))); dtRst.Rows.Add("R6B2.X261.ⅣE", "X261 OP80/85", "焊接X261 OP80/85", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd))); dtRst.Rows.Add("R6B1.7#.LJ", "7# X261 OP80/85", "焊接X261 OP80/85", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd))); dtRst.Rows.Add("R6B1.8#.LJ", "8# X261 OP80/85", "焊接X261 OP80/85", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd))); StringBuilder strAddrs = new StringBuilder(); foreach (DataRow dr in dtRst.Rows) { if (!string.IsNullOrEmpty(strAddrs.ToString())) { strAddrs.Append(","); } strAddrs.Append(CommFunc.ConvertDBNullToString(dr["ModuleAddr"])); } // DataTable dtSource = dal.GetEnergyForDayX261(strAddrs.ToString()); dtSource.PrimaryKey = new DataColumn[] { dtSource.Columns["Module_id"], dtSource.Columns["Fun_id"] }; dtRst.PrimaryKey = new DataColumn[] { dtRst.Columns["ModuleAddr"] }; // StringBuilder splitMdQuery = new StringBuilder(); StringBuilder splitTyQuery = new StringBuilder(); foreach (DataRow dr in dtSource.Rows) { if (!string.IsNullOrEmpty(splitMdQuery.ToString())) { splitMdQuery.Append(","); } splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"])); if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitTyQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["FunType"]), ","))) { if (!string.IsNullOrEmpty(splitTyQuery.ToString())) { splitTyQuery.Append(","); } splitTyQuery.Append(CommFunc.ConvertDBNullToString(dr["FunType"])); } } DataTable dtUse = WholeBLL.GetCoreQueryData(this.Ledger, splitMdQuery.ToString(), fm, to, "hour", splitTyQuery.ToString()); foreach (DataRow dr in dtUse.Rows) { DataRow curDr = dtSource.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] }); if (curDr == null) { continue; } int scale = CommFunc.ConvertDBNullToInt32(curDr["Scale"]); decimal multiply = CommFunc.ConvertDBNullToDecimal(curDr["Multiply"]); scale = scale == 0 ? 2 : scale; DataRow addDr = dtRst.Rows.Find(curDr["ModuleAddr"]); if (addDr == null) { continue; } DateTime tagTime = CommFunc.ConvertDBNullToDateTime(dr["TagTime"]); decimal firstVal = CommFunc.ConvertDBNullToDecimal(dr["FirstVal"]); decimal lastVal = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]); decimal useVal = lastVal - firstVal; useVal = Math.Round(useVal * multiply, scale, MidpointRounding.AwayFromZero); addDr["UseVal"] = CommFunc.ConvertDBNullToDecimal(addDr["UseVal"]) + useVal; List <decimal> rr = addDr["UseObj"] as List <decimal>; if (rr == null) { continue; } rr[tagTime.Hour] = rr[tagTime.Hour] + useVal; addDr["UseObj"] = rr; } var res1 = from s1 in dtRst.AsEnumerable() group s1 by new { ParentName = CommFunc.ConvertDBNullToString(s1["ParentName"]) } into g1 select new { ParentName = g1.Key.ParentName, UseVal = g1.Sum(p => CommFunc.ConvertDBNullToDecimal(p["UseVal"])) }; List <object> result = new List <object>(); foreach (var s1 in res1) { var res2 = from s2 in dtRst.AsEnumerable() where CommFunc.ConvertDBNullToString(s2["ParentName"]).Equals(s1.ParentName) select new { name = CommFunc.ConvertDBNullToString(s2["ModuleName"]), data = s2["UseObj"] as List <decimal>, }; result.Add(new { name = s1.ParentName, data = res2.ToList() }); } return(result); }
/// <summary> /// 设置定时电表策略 /// </summary> /// <param name="nAct">1=增加,2=修改,3=删除</param> /// <param name="si_id">策略Id,修改和删除需要,新增时传0即可</param> /// <param name="pRemark">描述</param> /// <param name="pIsClosed">是否启用:1=启用,0=不启用</param> /// <param name="pcT">日时区策略</param> /// <param name="pcM">日时区策略-定时段表号</param> /// <param name="pcW">星期策略</param> /// <param name="pcD">特殊日期策略</param> /// <param name="pcB">特殊日期策略-定时段表号</param> /// <param name="Timing"></param> /// <returns></returns> public APIRst SetTiming(int nAct, int si_id, string pRemark, int pIsClosed, string pcT, string pcM, string pcW, string pcD, string pcB, DataModels Timing) { APIRst rst = new APIRst(); string pcT1, pcT2, pcT3, pcT4, pcT5, pcT6, pcT7, pcM1, pcM2, pcM3, pcM4, pcM5, pcM6, pcM7, pcW1, pcW2, pcW3, pcW4, pcW5, pcW6, pcW7, pcD1, pcD2, pcD3, pcD4, pcD5, pcD6, pcD7, pcB1, pcB2, pcB3, pcB4, pcB5, pcB6, pcB7 = null; try { String[] pcTss = pcT.Split(','); //日时区策略 pcT1 = pcTss[0]; pcT2 = pcTss[1]; pcT3 = pcTss[2]; pcT4 = pcTss[3]; pcT5 = pcTss[4]; pcT6 = pcTss[5]; pcT7 = pcTss[6]; String[] pcMss = pcM.Split(','); //日时区策略-定时段表号 pcM1 = pcMss[0]; pcM2 = pcMss[1]; pcM3 = pcMss[2]; pcM4 = pcMss[3]; pcM5 = pcMss[4]; pcM6 = pcMss[5]; pcM7 = pcMss[6]; String[] pcWss = pcW.Split(','); //星期策略 pcW1 = pcWss[0]; pcW2 = pcWss[1]; pcW3 = pcWss[2]; pcW4 = pcWss[3]; pcW5 = pcWss[4]; pcW6 = pcWss[5]; pcW7 = pcWss[6]; String[] pcDWss = pcD.Split(','); //特殊日期策略 pcD1 = pcDWss[0]; pcD2 = pcDWss[1]; pcD3 = pcDWss[2]; pcD4 = pcDWss[3]; pcD5 = pcDWss[4]; pcD6 = pcDWss[5]; pcD7 = pcDWss[6]; String[] pcBWss = pcB.Split(','); //特殊日期策略-定时段表号 pcB1 = pcBWss[0]; pcB2 = pcBWss[1]; pcB3 = pcBWss[2]; pcB4 = pcBWss[3]; pcB5 = pcBWss[4]; pcB6 = pcBWss[5]; pcB7 = pcBWss[6]; v1_si_ssrVModel si_ssr = new v1_si_ssrVModel(); if (nAct != 1 && nAct != 2 && nAct != 3) { throw new Exception("执行操作类型错误"); } JsonSiModel si = ModelHandler <JsonSiModel> .jsonTextToModel(CommFunc.ConvertDBNullToString(si_ssr.siSSR)); JsonSiMdModel md = ModelHandler <JsonSiMdModel> .jsonTextToModel(CommFunc.ConvertDBNullToString(si_ssr.md)); JsonSiWkModel wk = ModelHandler <JsonSiWkModel> .jsonTextToModel(CommFunc.ConvertDBNullToString(si_ssr.wk)); JsonSiTsModel ts = ModelHandler <JsonSiTsModel> .jsonTextToModel(CommFunc.ConvertDBNullToString(si_ssr.ts)); si_ssr.descr = pRemark; //描述 si_ssr.disabled = pIsClosed; //是否启用 ////----8个时段的JSON值怎样获取----//// //string data1 = pData1; DataTable djson = ToDataTable(Timing.Data); //var djson = CreateTable<ExpTimingModels>(); //djson = FillData(djson, Timing); StringBuilder strD = new StringBuilder(); StringBuilder strT = new StringBuilder(); JsonSiModel.Value value; int rIndex = 0; string[] arrValue; object dObj; foreach (DataRow dr in djson.Rows) { rIndex = rIndex + 1; foreach (DataColumn dc in djson.Columns) { int cIndex = CommFunc.ConvertDBNullToInt32(dc.ColumnName.Trim().Substring(1, 2)); if (cIndex == 0) { continue; } //arrValue = CommFunc.ConvertDBNullToString(cell.Value).Trim().Split(new char[2] { ':', '-' }, StringSplitOptions.RemoveEmptyEntries); arrValue = CommFunc.ConvertDBNullToString(dr[dc]).Trim().Split('-'); strD.Clear(); strT.Clear(); strD.Append("d" + cIndex.ToString().Trim().PadLeft(2, '0')); strT.Append("t" + rIndex.ToString().Trim().PadLeft(2, '0')); System.Reflection.PropertyInfo dInfo = si.GetType().GetProperty(strD.ToString()); dObj = dInfo.GetValue(si, null); System.Reflection.PropertyInfo tInfo = dObj.GetType().GetProperty(strT.ToString()); value = (JsonSiModel.Value)tInfo.GetValue(dObj, null); value.hm = arrValue[0]; value.sr = arrValue[1]; //value.sr = arrValue[2]; } } ///// #region md.md01.md = "0000"; md.md02.md = "0000"; md.md03.md = "0000"; md.md04.md = "0000"; md.md05.md = "0000"; md.md06.md = "0000"; md.md07.md = "0000"; string ss; string a; a = pcT1; if (a.Length > 4 || a.Length < 4) { ss = (CommFunc.ConvertDBNullToDateTime(pcT1)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo); if (ss != "19000101" && ss != "00010101") { md.md01.md = ss.Substring(4, 4); } } else { md.md01.md = a; } a = pcT2; if (a.Length > 4 || a.Length < 4) { ss = (CommFunc.ConvertDBNullToDateTime(pcT2)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo); if (ss != "19000101" && ss != "00010101") { md.md02.md = ss.Substring(4, 4); } } else { md.md02.md = a; } a = pcT3; if (a.Length > 4 || a.Length < 4) { ss = (CommFunc.ConvertDBNullToDateTime(pcT3)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo); if (ss != "19000101" && ss != "00010101") { md.md03.md = ss.Substring(4, 4); } } else { md.md03.md = a; } a = pcT4; if (a.Length > 4 || a.Length < 4) { ss = (CommFunc.ConvertDBNullToDateTime(pcT4)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo); if (ss != "19000101" && ss != "00010101") { md.md04.md = ss.Substring(4, 4); } } else { md.md04.md = a; } a = pcT5; if (a.Length > 4 || a.Length < 4) { ss = (CommFunc.ConvertDBNullToDateTime(pcT5)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo); if (ss != "19000101" && ss != "00010101") { md.md05.md = ss.Substring(4, 4); } } else { md.md05.md = a; } a = pcT6; if (a.Length > 4 || a.Length < 4) { ss = (CommFunc.ConvertDBNullToDateTime(pcT6)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo); if (ss != "19000101" && ss != "00010101") { md.md06.md = ss.Substring(4, 4); } } else { md.md06.md = a; } a = pcT7; if (a.Length > 4 || a.Length < 4) { ss = (CommFunc.ConvertDBNullToDateTime(pcT7)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo); if (ss != "19000101" && ss != "00010101") { md.md07.md = ss.Substring(4, 4); } } else { md.md07.md = a; } //// md.md01.si = pcM1; md.md02.si = pcM2; md.md03.si = pcM3; md.md04.si = pcM4; md.md05.si = pcM5; md.md06.si = pcM6; md.md07.si = pcM7; ///// wk.si01 = pcW1; wk.si02 = pcW2; wk.si03 = pcW3; wk.si04 = pcW4; wk.si05 = pcW5; wk.si06 = pcW6; wk.si07 = pcW7; ///// ts.ts01.dt = "00000000"; ts.ts02.dt = "00000000"; ts.ts03.dt = "00000000"; ts.ts04.dt = "00000000"; ts.ts05.dt = "00000000"; ts.ts06.dt = "00000000"; ts.ts07.dt = "00000000"; string sd = ""; string st = ""; st = pcD1; if (st.Contains("-")) { sd = (CommFunc.ConvertDBNullToDateTime(pcD1)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo); if (sd != "19000101" && sd != "00010101") { ts.ts01.dt = sd; } } else if (st != "") { ts.ts01.dt = st; } st = pcD2; if (st.Contains("-")) { sd = (CommFunc.ConvertDBNullToDateTime(pcD2)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo); if (sd != "19000101" && sd != "00010101") { ts.ts02.dt = sd; } } else if (st != "") { ts.ts02.dt = st; } st = pcD3; if (st.Contains("-")) { sd = (CommFunc.ConvertDBNullToDateTime(pcD3)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo); if (sd != "19000101" && sd != "00010101") { ts.ts03.dt = sd; } } else if (st != "") { ts.ts03.dt = st; } st = pcD4; if (st.Contains("-")) { sd = (CommFunc.ConvertDBNullToDateTime(pcD4)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo); if (sd != "19000101" && sd != "00010101") { ts.ts04.dt = sd; } } else if (st != "") { ts.ts04.dt = st; } st = pcD5; if (st.Contains("-")) { sd = (CommFunc.ConvertDBNullToDateTime(pcD5)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo); if (sd != "19000101" && sd != "00010101") { ts.ts05.dt = sd; } } else if (st != "") { ts.ts05.dt = st; } st = pcD6; if (st.Contains("-")) { sd = (CommFunc.ConvertDBNullToDateTime(pcD6)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo); if (sd != "19000101" && sd != "00010101") { ts.ts06.dt = sd; } } else if (st != "") { ts.ts06.dt = st; } st = pcD7; if (st.Contains("-")) { sd = (CommFunc.ConvertDBNullToDateTime(pcD7)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo); if (sd != "19000101" && sd != "00010101") { ts.ts07.dt = sd; } } else if (st != "") { ts.ts07.dt = st; } ts.ts01.si = pcB1; ts.ts02.si = pcB2; ts.ts03.si = pcB3; ts.ts04.si = pcB4; ts.ts05.si = pcB5; ts.ts06.si = pcB6; ts.ts07.si = pcB7; #endregion ///////////////////////////////////////////////////////////////////////////////////// si_ssr.siSSR = ModelHandler <JsonSiModel> .modelToJsonText(si); si_ssr.md = ModelHandler <JsonSiMdModel> .modelToJsonText(md); si_ssr.wk = ModelHandler <JsonSiWkModel> .modelToJsonText(wk); si_ssr.ts = ModelHandler <JsonSiTsModel> .modelToJsonText(ts); int cnt = 0; if (nAct != 1 && Convert.IsDBNull(si_ssr.si_id)) { throw new Exception("请选中一行"); } if (nAct == 1)//新增 { cnt = bll.EditRow(si_ssr); } if (nAct == 2 || nAct == 3) { si_ssr.si_id = si_id;//策略ID if (nAct == 3) { bll.DelRow(si_ssr);//删除 } else { bll.EditRow(si_ssr); } } rst.data = cnt; } catch (Exception ex) { rst.rst = false; rst.err.code = (int)ResultCodeDefine.Error; rst.err.msg = ex.Message; FileLog.WriteLog("获取费率列表错误:" + ex.Message + ex.StackTrace); } return(rst); }