Exemplo n.º 1
0
        public Message Edit(IoT_PricePar info)
        {
            // 定义执行结果
            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 dbinfo = dd.GetTable <IoT_PricePar>().Where(p =>
                                                                         p.CompanyID == info.CompanyID && p.ID == info.ID).SingleOrDefault();

                ConvertHelper.Copy <IoT_PricePar>(dbinfo, info);

                // 更新操作
                dd.SubmitChanges();
                m = new Message()
                {
                    Result     = true,
                    TxtMessage = JSon.TToJson <IoT_PricePar>(dbinfo)
                };
            }
            catch (Exception e)
            {
                m = new Message()
                {
                    Result     = false,
                    TxtMessage = "编辑价格参数失败!" + e.Message
                };
            }
            return(m);
        }
Exemplo n.º 2
0
        public Message Delete(IoT_PricePar info)
        {
            // 定义执行结果
            Message m;
            string  configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"];
            //Linq to SQL 上下文对象
            DataContext dd = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString);

            try
            {
                string   checkSQL = $"Select count(*) from IoT_Meter where PriceID={info.ID}";
                object[] param    = new object[0];
                int      iCount   = dd.ExecuteQuery <int>(checkSQL, param).Single <int>();
                if (iCount > 0)
                {
                    throw new Exception("价格类型已被使用,不能删除");
                }
                //检查是否被调价计划试用
                checkSQL = $"Select count(*) from IoT_Pricing where PriceType={info.ID}";
                iCount   = dd.ExecuteQuery <int>(checkSQL, param).Single <int>();
                if (iCount > 0)
                {
                    throw new Exception("价格类型已被调价计划使用,不能删除");
                }
                // 获得上下文对象中的表信息
                Table <IoT_PricePar> tbl = dd.GetTable <IoT_PricePar>();
                var s = tbl.Where(p => p.CompanyID == info.CompanyID && p.ID == info.ID).Single();
                tbl.DeleteOnSubmit(s as IoT_PricePar);

                // 更新操作
                dd.SubmitChanges();
                m = new Message()
                {
                    Result     = true,
                    TxtMessage = "删除价格参数成功!"
                };
            }
            catch (Exception e)
            {
                m = new Message()
                {
                    Result     = false,
                    TxtMessage = "删除价格参数失败!" + e.Message
                };
            }
            return(m);
        }
Exemplo n.º 3
0
        public Message Add(IoT_PricePar 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_PricePar> tbl = dd.GetTable <IoT_PricePar>();
                string ser = GetSerNo();
                if (ser != "-1")
                {
                    info.Ser = ser;
                }

                // 调用新增方法
                tbl.InsertOnSubmit(info);
                // 更新操作
                dd.SubmitChanges();

                m = new Message()
                {
                    Result     = true,
                    TxtMessage = JSon.TToJson <IoT_PricePar>(info)
                };
            }
            catch (Exception e)
            {
                m = new Message()
                {
                    Result     = false,
                    TxtMessage = "新增价格参数失败!" + e.Message
                };
            }
            return(m);
        }
Exemplo n.º 4
0
        public Message DianHuo(List <String> meterNoList, string meterType, Int64 priceId, string companyId, DateTime enableDate, List <String> lstUserID, string EnableMeterOper)
        {
            // 定义执行结果
            Message m;
            string  configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"];
            //Linq to SQL 上下文对象
            DataContext dd = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString);

            try
            {
                List <IoT_Meter> dianHuoMeter = new List <IoT_Meter>();

                //获取价格信息
                IoT_PricePar priceInfo = dd.GetTable <IoT_PricePar>().Where(p =>
                                                                            p.CompanyID == companyId && p.ID == priceId).SingleOrDefault();
                //if (priceInfo==null)
                //{
                //     return new Message()
                //    {
                //        Result = false,
                //        TxtMessage = "该表具选择的价格不存在,请加载页面重新选择!"
                //    };
                //}
                foreach (string UserID in lstUserID)
                {
                    IoT_User dbinfo = dd.GetTable <IoT_User>().Where(p => p.UserID == UserID).SingleOrDefault();
                    if (dbinfo != null && dbinfo.State == '2')
                    {
                        return(new Message()
                        {
                            Result = false,
                            TxtMessage = "用户" + dbinfo.UserName + "已发送点火申请,请勿重复发送!"
                        });
                    }
                }
                foreach (string meterNo in meterNoList)
                {
                    IoT_Meter dbinfo = dd.GetTable <IoT_Meter>().Where(p => p.MeterNo == meterNo).SingleOrDefault();
                    if (priceInfo != null)
                    {
                        dbinfo.Price1          = priceInfo.Price1 == null ? 0 : priceInfo.Price1;
                        dbinfo.Gas1            = priceInfo.Gas1 == null ? 0 : priceInfo.Gas1;
                        dbinfo.Price2          = priceInfo.Price2 == null ? 0 : priceInfo.Price2;
                        dbinfo.Gas2            = priceInfo.Gas2 == null ? 0 : priceInfo.Gas2;
                        dbinfo.Price3          = priceInfo.Price3 == null ? 0 : priceInfo.Price3;
                        dbinfo.Gas3            = priceInfo.Gas3 == null ? 0 : priceInfo.Gas3;
                        dbinfo.Price4          = priceInfo.Price4 == null ? 0 : priceInfo.Price4;
                        dbinfo.Gas4            = priceInfo.Gas4 == null ? 0 : priceInfo.Gas4;
                        dbinfo.Price5          = priceInfo.Price5 == null ? 0 : priceInfo.Price5;
                        dbinfo.IsUsed          = priceInfo.IsUsed == null ? false : priceInfo.IsUsed;
                        dbinfo.Ladder          = priceInfo.Ladder == null ? 3 : priceInfo.Ladder;
                        dbinfo.SettlementDay   = priceInfo.SettlementDay;
                        dbinfo.SettlementMonth = priceInfo.SettlementMonth;
                        dbinfo.SettlementType  = priceInfo.SettlementType;
                    }
                    dbinfo.EnableMeterOper = EnableMeterOper;

                    dbinfo.PriceID         = (int)priceId;
                    dbinfo.MeterType       = meterType;
                    dbinfo.EnableMeterDate = enableDate;
                    dbinfo.MeterState      = '5';
                    dianHuoMeter.Add(dbinfo);
                }

                // 更新操作
                dd.SubmitChanges();

                string result = Do(dianHuoMeter);
                if (result == "")
                {
                    m = new Message()
                    {
                        Result     = true,
                        TxtMessage = "点火成功"
                    };
                }
                else
                {
                    m = new Message()
                    {
                        Result     = false,
                        TxtMessage = result
                    };
                }
            }
            catch (Exception e)
            {
                m = new Message()
                {
                    Result     = false,
                    TxtMessage = "" + e.Message
                };
            }
            return(m);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 更新调价任务状态
        /// </summary>
        /// <param name="taskID"></param>
        /// <param name="state">状态:0 申请 1 完成 2 撤销  3 失败</param>
        /// <returns></returns>
        public string UpdatePricingTaskState(string taskID, TaskState state)
        {
            if (state == TaskState.Waitting)
            {
                return("状态不能为申请");
            }

            string result     = "";
            string configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"];
            //Linq to SQL 上下文对象
            DataContext dd = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString);

            try
            {
                IoT_PricingMeter dbinfo = dd.GetTable <IoT_PricingMeter>().Where(p =>
                                                                                 p.TaskID == taskID).SingleOrDefault();

                dbinfo.State        = Convert.ToChar(((byte)state).ToString());
                dbinfo.FinishedDate = DateTime.Now;
                // 更新操作
                dd.SubmitChanges();

                IoT_Pricing uploadCycle = null;
                int         iCount      = dd.GetTable <IoT_PricingMeter>().Where(p => p.TaskID == taskID && p.State.ToString() == "0").Count();
                if (iCount == 0)//表具任务都执行完成后 更新调价任务状态
                {
                    uploadCycle       = dd.GetTable <IoT_Pricing>().Where(p => p.ID == dbinfo.ID).SingleOrDefault();
                    uploadCycle.State = Convert.ToChar(((byte)state).ToString());
                }
                dd.SubmitChanges();
                IoT_PricePar pricePar = dd.GetTable <IoT_PricePar>().Where(p => p.ID.ToString() == uploadCycle.PriceType).SingleOrDefault();


                if (state == TaskState.Undo)
                {
                    new M_SetParameterService().UnSetParameter(taskID);
                }
                if (state == TaskState.Finished)
                {
                    IoT_Meter meterInfo = dd.GetTable <IoT_Meter>().Where(p => p.MeterNo == dbinfo.MeterNo).SingleOrDefault();

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

                    meterInfo.IsUsed = uploadCycle.IsUsed == null ? false : uploadCycle.IsUsed;
                    meterInfo.Ladder = uploadCycle.Ladder == null ? 3 : uploadCycle.Ladder;

                    meterInfo.SettlementType  = uploadCycle.SettlementType;
                    meterInfo.SettlementDay   = pricePar.SettlementDay;
                    meterInfo.SettlementMonth = pricePar.SettlementMonth;

                    // 更新操作
                    dd.SubmitChanges();
                }
            }
            catch (Exception e)
            {
                result = e.Message;
            }
            return(result);
        }