Exemplo n.º 1
0
        private static ulong CalculateConsumption(DateRange readOutPeriod, ulong startReadOut, ulong endReadOut, IEnumerable <MeterConfig> meterConfigs)
        {
            Contract.Requires(meterConfigs != null);

            ulong realConsumption = 0U;

            MeterConfig firstConfig = meterConfigs.FirstOrDefault();

            if (firstConfig != null)
            {
                // if meter changed on start of period, use meter's start readout
                if (firstConfig.Start == readOutPeriod.Start)
                {
                    startReadOut = firstConfig.StartReadOut;
                }
                // if meter changed in the middle of period
                if (firstConfig.Start < readOutPeriod.Start && firstConfig.EndReadOut.HasValue)
                {
                    realConsumption = firstConfig.EndReadOut.Value - startReadOut;
                }
            }

            // add consumption of the period if meters changed many times
            realConsumption += Convert.ToUInt64(meterConfigs.GetMeterConfigHistoryInPeriod(readOutPeriod).Sum(config => config.GetConsumption()));

            MeterConfig lastConfig = meterConfigs.LastOrDefault();

            if (lastConfig != null)
            {
                // if meter not changed
                if (!lastConfig.EndReadOut.HasValue)
                {
                    if (lastConfig != firstConfig)
                    {
                        startReadOut = lastConfig.StartReadOut;
                    }
                    realConsumption += endReadOut - startReadOut;
                }
            }

            return(realConsumption);
        }
Exemplo n.º 2
0
        public ActionResult Param_MeterConfig_Upd(MeterConfig MeterConf)
        {
            CommonResult result = new CommonResult();

            MeterConf.VcUserIDUpd = userid.ToString();
            MeterConf.IntEndCode  = endcode;
            MeterConf.DtLstUpd    = DateTime.Now;
            var rs = new ServiceDbClient().Param_MeterConfig_Opr(MeterConf);

            if (rs == "0")
            {
                result.IsSuccess = true;
            }
            else
            {
                result.IsSuccess = false;
                result.ErrorMsg  = rs;
            }
            return(ToJsonContent(result));
        }
Exemplo n.º 3
0
        public ActionResult Param_MeterConfig_Upd(MeterConfig MeterConf)
        {
            CommonResult result  = new CommonResult();
            var          endcode = Session["EndCode"] ?? "0";

            MeterConf.VcUserIDUpd = Session["UserID"].ToString() ?? "";
            MeterConf.IntEndCode  = endcode.ToString().ToInt32();
            MeterConf.DtLstUpd    = DateTime.Now;
            var rs = new ServiceDbClient().Param_MeterConfig_Opr(MeterConf);

            if (rs == "0")
            {
                result.Success = true;
            }
            else
            {
                result.Success      = false;
                result.ErrorMessage = rs;
            }
            return(ToJsonContent(result));
        }
 public void CreateMeterConfig2(MeterConfig Payload)
 {
     //do nothing
 }