/// <summary> /// 返回 电类数据json 每班数据用 /// </summary> private string jsonDianLei(CW_每班统计 Gstart, CW_每班统计 Gend, xzz xz) { string rowtext = "{\"total\":100,\"rows\":[行数据对象],\"footer\":脚对象}"; string row = " {{ \"电类\": \"{0}\",\"起数\":{1:f},\"止数\":{2:f},\"消耗量\":{3:f},\"修正\":{4:f} }}"; string temp = ""; temp += string.Format(row, "总电量(峰)", Gstart.SX_电量总峰, Gend.SX_电量总峰, Gend.SX_电量总峰 - Gstart.SX_电量总峰 + xz.zdf, xz.zdf) + ","; temp += string.Format(row, "总电量(平)", Gstart.SX_电量总平, Gend.SX_电量总平, Gend.SX_电量总平 - Gstart.SX_电量总平 + xz.zdp, xz.zdp) + ","; temp += string.Format(row, "总电量(谷)", Gstart.SX_电量总谷, Gend.SX_电量总谷, Gend.SX_电量总谷 - Gstart.SX_电量总谷 + xz.zdg, xz.zdg) + ","; temp += string.Format(row, "商电量(峰)", Gstart.SX_电量商峰, Gend.SX_电量商峰, Gend.SX_电量商峰 - Gstart.SX_电量商峰 + xz.sdf, xz.sdf) + ","; temp += string.Format(row, "商电量(平)", Gstart.SX_电量商平, Gend.SX_电量商平, Gend.SX_电量商平 - Gstart.SX_电量商平 + xz.sdp, xz.sdp) + ","; temp += string.Format(row, "商电量(谷)", Gstart.SX_电量商谷, Gend.SX_电量商谷, Gend.SX_电量商谷 - Gstart.SX_电量商谷 + xz.sdg, xz.sdg) + ","; temp += string.Format(row, "正无功", Gstart.SX_电量正无功, Gend.SX_电量正无功, Gend.SX_电量正无功 - Gstart.SX_电量正无功 + xz.zwg, xz.zwg) + ","; temp += string.Format(row, "反无功", Gstart.SX_电量反无功, Gend.SX_电量反无功, Gend.SX_电量反无功 - Gstart.SX_电量反无功 + xz.fwg, xz.fwg); rowtext = rowtext.Replace("行数据对象", temp); double zdl = (Gend.SX_电量总峰 - Gstart.SX_电量总峰 + xz.zdf) + (Gend.SX_电量总平 - Gstart.SX_电量总平 + xz.zdp) + (Gend.SX_电量总谷 - Gstart.SX_电量总谷 + xz.zdg); double zdlglys = zdl; double wgglys = (Gend.SX_电量正无功 - Gstart.SX_电量正无功 + xz.zwg) + (Gend.SX_电量反无功 - Gstart.SX_电量反无功 + xz.fwg); if (Gstart.SX_站点 == 4) {//麻柳沱 系数为400 zdl = zdl * 400; } else {//西路 南高 系数为800 zdl = zdl * 800; } double glys = 0;//功率因素 glys = zdlglys / (Math.Sqrt(zdlglys * zdlglys + wgglys * wgglys)); temp = " [{{ \"电类\": \"总电量:\",\"起数\":{0:f},\"止数\":\"单位电耗:\",\"消耗量\":{1:f4},\"修正\":\"功率因数:{2:f3}\" }}]"; temp = string.Format(temp, zdl, zdl / Gend.SX_生产气量, glys); rowtext = rowtext.Replace("脚对象", temp); return rowtext; }
/// <summary> /// 区间统计 修正值合计数据 /// </summary> /// <param name="Gstart">结束</param> /// <param name="Gend">起始</param> /// <returns>修正值模型</returns> private xzz getZDregXzz(CW_每班统计 Gstart, CW_每班统计 Gend) { string SQL = @"SELECT isnull(sum([总电峰]),0) as 总电峰 ,isnull(sum([总电平]),0) as 总电平 ,isnull(sum([总电谷]),0) as 总电谷 ,isnull(sum([商电峰]),0) as 商电峰 ,isnull(sum([商电平]),0) as 商电平 ,isnull(sum([商电谷]),0) as 商电谷 ,isnull(sum([正无功]),0) as 正无功 ,isnull(sum([反无功]),0) as 反无功 ,isnull(sum([普通水]),0) as 普通水 ,isnull(sum([消防水]),0) as 消防水 ,isnull(sum([流量计]),0) as 流量计 FROM [CNGQT].[dbo].[CW_每班修正] where 日期 BETWEEN @起始日期 AND @结束日期 AND 站点=@站点 "; DAL dal = new DAL(); xzz xz = new xzz(); xz.init(); SqlParameter par1 = new SqlParameter("@站点", Gstart.SX_站点); SqlParameter par2 = new SqlParameter("@起始日期", Gstart.SX_日期.AddDays(1)); SqlParameter par3 = new SqlParameter("@结束日期", Gend.SX_日期); string[] val = dal.RunSqlStrings(SQL, new SqlParameter[] { par1, par2, par3 }); if (val != null) { xz.zdf = double.Parse(val[0]); xz.zdp = double.Parse(val[1]); xz.zdg = double.Parse(val[2]); xz.sdf = double.Parse(val[3]); xz.sdp = double.Parse(val[4]); xz.sdg = double.Parse(val[5]); xz.zwg = double.Parse(val[6]); xz.fwg = double.Parse(val[7]); xz.pts = double.Parse(val[8]); xz.xfs = double.Parse(val[9]); xz.llj = double.Parse(val[10]); } return xz; }
/// <summary> /// 返回 水类数据json 每班数据用 /// </summary> private string jsonShuiLei(CW_每班统计 Gstart, CW_每班统计 Gend, xzz xz) { string rowtext = "{\"total\":100,\"rows\":[行数据对象],\"footer\":脚对象}"; string row = " {{ \"水类\": \"{0}\",\"起数\":{1:f},\"止数\":{2:f},\"消耗量\":{3:f},\"修正\":{4:f} }}"; string temp = ""; temp += string.Format(row, "普通水", Gstart.SX_普通水, Gend.SX_普通水, Gend.SX_普通水 - Gstart.SX_普通水 + xz.pts, xz.pts) + ","; temp += string.Format(row, "消防水", Gstart.SX_消防水, Gend.SX_消防水, Gend.SX_消防水 - Gstart.SX_消防水 + xz.xfs, xz.xfs); rowtext = rowtext.Replace("行数据对象", temp); temp = " [{{ \"水类\": \"普通水: 每m³气耗水量\",\"起数\":{0:f4} }}]"; temp = string.Format(temp, (Gend.SX_普通水 - Gstart.SX_普通水 + xz.pts) / Gend.SX_生产气量); rowtext = rowtext.Replace("脚对象", temp); return rowtext; }
/// <summary> /// 取得当班对象 /// </summary> /// <param name="dt">日期</param> /// <param name="zd">站点</param> /// <param name="bz">班组</param> /// <param name="yb">夜班</param> /// <param name="scql">生产气量</param> /// <returns></returns> private string getGasSc(DateTime dt, int zd, int bz, bool yb, double scql) { DAL dal = new DAL(); CW_每班统计 dqBz = new CW_每班统计();//当班数据 CW_每班统计 syBz = new CW_每班统计();//上一班数据 DateTime sydt; //上一班日期 string retext = "{\"sc\":输差对象,\"s\":水对象,\"y\":油对象,\"d\":电对象,\"ysj\":压缩机对象}"; int sybz;//上一班 班组 gassc sc = new gassc(); string SQL = "SELECT ID FROM [CNGQT].[dbo].[CW_每班统计] where [站点]=" + zd.ToString() + " and [日期]='" + dt.ToString() + "' and [班组]='" + bz.ToString() + "'"; string id = dal.RunSqlGetID(SQL); if (id == null) { return "[]"; } dqBz = ZDGAS.GetModel_CW_每班统计(int.Parse(id)); if (zd == 4) { sydt = dt.AddDays(-1); sybz = bz - 1; if (sybz == 0) { sybz = 4; } } else { if (yb)//当前班是否是夜班 { sydt = dt; } else { sydt = dt.AddDays(-1); } sybz = bz - 1; if (sybz == 0) { sybz = 3; } } SQL = "SELECT ID FROM [CNGQT].[dbo].[CW_每班统计] where [站点]=" + zd.ToString() + " and [日期]='" + sydt.ToString() + "' and [班组]='" + sybz.ToString() + "'"; id = dal.RunSqlGetID(SQL); syBz = ZDGAS.GetModel_CW_每班统计(int.Parse(id));//上一班数据 //取当班 流量计修正值 SQL = "SELECT [总电峰],[总电平],[总电谷],[商电峰],[商电平],[商电谷],[正无功],[反无功],[普通水],[消防水],[流量计] FROM [CNGQT].[dbo].[CW_每班修正] where 日期='" + dt.ToString() + "' AND 站点=" + zd.ToString() + " AND 班组=" + bz.ToString(); xzz dbxzz = new xzz(); dbxzz.init(); string[] val = dal.RunSqlStrings(SQL); if (val != null) { dbxzz.zdf = double.Parse(val[0]); dbxzz.zdp = double.Parse(val[1]); dbxzz.zdg = double.Parse(val[2]); dbxzz.sdf = double.Parse(val[3]); dbxzz.sdp = double.Parse(val[4]); dbxzz.sdg = double.Parse(val[5]); dbxzz.zwg = double.Parse(val[6]); dbxzz.fwg = double.Parse(val[7]); dbxzz.pts = double.Parse(val[8]); dbxzz.xfs = double.Parse(val[9]); dbxzz.llj = double.Parse(val[10]); } sc.进站起 = dqBz.SX_进站起数; sc.进站止 = dqBz.SX_进站止数; sc.进站气量 = sc.进站止 - sc.进站起; sc.再生起 = dqBz.SX_再生起数; sc.再生止 = dqBz.SX_再生止数; sc.再生气量 = sc.再生止 - sc.再生起; sc.生产气量 = scql; sc.购进气量 = sc.进站气量 - sc.再生气量 + dbxzz.llj; sc.罐储气 = dqBz.SX_罐储气; sc.罐差 = dqBz.SX_罐储气 - syBz.SX_罐储气; sc.罐储气起 = syBz.SX_罐储气; sc.罐储气止 = dqBz.SX_罐储气; sc.输差 = sc.购进气量 - sc.生产气量 - sc.罐差; sc.修正值 = dbxzz.llj; if (sc.生产气量 == 0 || sc.购进气量 == 0) { sc.输差率 = 0; } else { sc.输差率 = sc.输差 / sc.购进气量; } string temp = "{{ \"total\": 1, \"rows\": [{{ \"进站起\": {0:f},\"进站止\":{1:f},\"再生起\":{2:f},\"再生止\":{3:f},\"购进气量\":{4:f},\"生产气量\":{5:f},\"罐储气\":{6:f},\"罐差\":{7:f},\"输差\":{8:f},\"输差率\":{9:f},\"修正\":{10:f} }}]}}"; temp = string.Format(temp, sc.进站起, sc.进站止, sc.再生起, sc.再生止, sc.购进气量, sc.生产气量, sc.罐储气, sc.罐差, sc.输差, sc.输差率 * 100, sc.修正值); retext = retext.Replace("输差对象", temp); temp = jsonYouLei(syBz, dqBz); retext = retext.Replace("油对象", temp); temp = jsonDianLei(syBz, dqBz, dbxzz); retext = retext.Replace("电对象", temp); temp = jsonShuiLei(syBz, dqBz, dbxzz); retext = retext.Replace("水对象", temp); temp = jsonYaShoJi(syBz, dqBz); retext = retext.Replace("压缩机对象", temp); Sys.DebugMes(temp); return retext; }
/// <summary> /// 返回流量计数据 json对象 /// </summary> private string jsonLiuLianJi(CW_每班统计 Gstart, CW_每班统计 Gend, CW_每班统计 Gsum, xzz xz) { string rowtext = "{\"total\":100,\"rows\":行数据对象}"; string temp = " [{{ \"进站起\": {0:f},\"进站止\":{1:f},\"再生起\":{2:f},\"再生止\":{3:f},\"罐储气起\":{4:f},\"罐储气止\":{5:f},\"购进气量\":{6:f},\"生产气量\":{7:f},\"输差\":{8:f},\"输差率\":{9:f},\"修正值\":{10:f} }}]"; double GouJin = (Gend.SX_进站止数 - Gstart.SX_进站止数) - (Gend.SX_再生止数 - Gstart.SX_再生止数) + xz.llj;//购进气量 double ShuCha = GouJin - Gsum.SX_生产气量 - (Gend.SX_罐储气 - Gstart.SX_罐储气); temp = string.Format(temp, Gstart.SX_进站止数, Gend.SX_进站止数, Gstart.SX_再生止数, Gend.SX_再生止数, Gstart.SX_罐储气, Gend.SX_罐储气, GouJin, Gsum.SX_生产气量, ShuCha, ShuCha / GouJin * 100, xz.llj); rowtext = rowtext.Replace("行数据对象", temp); return rowtext; }