public Message Add(IoT_SetUploadCycle info, List <IoT_UploadCycleMeter> meterList)
        {
            // 定义执行结果
            Message m;
            string  configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"];
            //Linq to SQL 上下文对象
            DataContext dd = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString);

            try
            {
                //添加设置上传周期参数任务到通讯队列
                string result = new SetMeterParameter().SetUploadCycle(info, meterList);
                if (result != "")
                {
                    throw new Exception(result);
                }

                Table <IoT_SetUploadCycle> tbl = dd.GetTable <IoT_SetUploadCycle>();

                // 调用新增方法
                tbl.InsertOnSubmit(info);
                // 更新操作
                dd.SubmitChanges();
                // 更新操作
                Table <IoT_UploadCycleMeter> tbl_meter = dd.GetTable <IoT_UploadCycleMeter>();
                foreach (IoT_UploadCycleMeter meter in meterList)
                {
                    IoT_Meter tempMeter = MeterManageService.QueryMeter(meter.MeterNo);
                    meter.MeterID = tempMeter.ID;
                    meter.ID      = info.ID;
                    meter.Context = info.Context;
                    meter.State   = '0';//申请
                    info.TaskID   = meter.TaskID;
                    tbl_meter.InsertOnSubmit(meter);
                }
                // 更新操作
                dd.SubmitChanges();

                m = new Message()
                {
                    Result     = true,
                    TxtMessage = JSon.TToJson <IoT_SetUploadCycle>(info)
                };
            }
            catch (Exception e)
            {
                m = new Message()
                {
                    Result     = false,
                    TxtMessage = "新增设置上传周期失败!" + e.Message
                };
            }
            return(m);
        }
        /// <summary>
        /// 撤销调价计划
        /// </summary>
        /// <param name="info"></param>
        /// <param name="meterList"></param>
        /// <returns></returns>
        public Message UnSetParamter(IoT_Pricing info)
        {
            // 定义执行结果
            Message m;
            string  configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"];
            //Linq to SQL 上下文对象
            DataContext dd = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString);

            try
            {
                Table <IoT_PricingMeter> tbl_meter = dd.GetTable <IoT_PricingMeter>();
                List <IoT_PricingMeter>  list      = tbl_meter.Where(p => p.ID == info.ID && p.State == '0').ToList();
                M_SetParameterService    ps        = new M_SetParameterService();
                foreach (IoT_PricingMeter meter in list)
                {
                    string result = new SetMeterParameter().UnSetParamter(meter.TaskID);
                    meter.State        = '2';
                    meter.FinishedDate = DateTime.Now;
                    ps.UnSetParameter(meter.TaskID);
                }
                if (list.Count > 0)
                {
                    Table <IoT_Pricing> tbl = dd.GetTable <IoT_Pricing>();
                    var dbinfo = tbl.Where(p => p.CompanyID == info.CompanyID && p.ID == info.ID).Single();

                    dbinfo.State   = '1';          //任务撤销
                    dbinfo.Context = info.Context; //撤销原因
                    dd.SubmitChanges();
                    m = new Message()
                    {
                        Result     = true,
                        TxtMessage = "操作成功"
                    };
                }
                else
                {
                    m = new Message()
                    {
                        Result     = false,
                        TxtMessage = "调价计划已执行完成。"
                    };
                }
            }
            catch (Exception e)
            {
                m = new Message()
                {
                    Result     = false,
                    TxtMessage = "撤销设置报警参数失败!" + e.Message
                };
            }
            return(m);
        }
        public Message Add(IoT_Pricing info, List <IoT_PricingMeter> meterList)
        {
            // 定义执行结果
            Message m;
            string  configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"];
            //Linq to SQL 上下文对象
            DataContext dd = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString);

            try
            {
                //获取价格信息
                IoT_PricePar priceInfo = dd.GetTable <IoT_PricePar>().Where(p =>
                                                                            p.CompanyID == info.CompanyID && p.ID == int.Parse(info.PriceType)).SingleOrDefault();

                info.Price1 = priceInfo.Price1 == null ? 0 : priceInfo.Price1;
                info.Gas1   = priceInfo.Gas1 == null ? 0 : priceInfo.Gas1;
                info.Price2 = priceInfo.Price2 == null ? 0 : priceInfo.Price2;
                info.Gas2   = priceInfo.Gas2 == null ? 0 : priceInfo.Gas2;
                info.Price3 = priceInfo.Price3 == null ? 0 : priceInfo.Price3;
                info.Gas3   = priceInfo.Gas3 == null ? 0 : priceInfo.Gas3;
                info.Price4 = priceInfo.Price4 == null ? 0 : priceInfo.Price4;
                info.Gas4   = priceInfo.Gas4 == null ? 0 : priceInfo.Gas4;
                info.Price5 = priceInfo.Price5 == null ? 0 : priceInfo.Price5;

                info.IsUsed         = priceInfo.IsUsed == null ? false : priceInfo.IsUsed;
                info.Ladder         = priceInfo.Ladder == null ? 3 : priceInfo.Ladder;
                info.SettlementType = priceInfo.SettlementType;
                info.MeterType      = "01";

                //设置调价计划参数和条件任务
                string result = new SetMeterParameter().SetPricingPlan(info, meterList);
                if (result != "")
                {
                    throw new Exception(result);
                }


                Table <IoT_Pricing> tbl = dd.GetTable <IoT_Pricing>();
                // 调用新增方法
                tbl.InsertOnSubmit(info);
                // 更新操作
                dd.SubmitChanges();

                Table <IoT_PricingMeter> tbl_meter = dd.GetTable <IoT_PricingMeter>();
                foreach (IoT_PricingMeter meter in meterList)
                {
                    IoT_Meter tempMeter = MeterManageService.QueryMeter(meter.MeterNo);
                    meter.MeterID = tempMeter.ID;
                    meter.ID      = info.ID;
                    meter.Context = info.Context;
                    meter.State   = '0';//申请
                    tbl_meter.InsertOnSubmit(meter);
                }
                // 更新操作
                dd.SubmitChanges();

                m = new Message()
                {
                    Result     = true,
                    TxtMessage = JSon.TToJson <IoT_Pricing>(info)
                };
            }
            catch (Exception e)
            {
                m = new Message()
                {
                    Result     = false,
                    TxtMessage = "新增调价计划失败!" + e.Message
                };
            }
            return(m);
        }