コード例 #1
0
 public void DeletePlan(PricingPlan pp)
 {
     try
     {
         MongoDBHelper <PricingPlan> mongo_plan = new MongoDBHelper <PricingPlan>();
         var iDelete = new QueryDocument();
         iDelete.Add("TaskID", pp.TaskID);
         //删除老计划
         mongo_plan.Delete(CollectionNameDefine.MeterPricingPlan, iDelete);
     }
     catch { }
 }
コード例 #2
0
        /// <summary>
        /// 向数据库中插入指令
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public static string Insert(Command command)
        {
            try
            {
                MongoDBHelper <Command> mongo_CMD = new MongoDBHelper <Command>();

                mongo_CMD.Insert(CollectionNameDefine.CommandCollectionName, command);
            }
            catch (Exception e)
            {
                return(e.Message);
            }
            return("");
        }
コード例 #3
0
        /// <summary>
        /// 新建账单
        /// </summary>
        /// <param name="bill"></param>
        public void AddBill(Bill bill)
        {
            try
            {
                if (bill == null)
                {
                    return;
                }

                MongoDBHelper <Bill> mongo = new MongoDBHelper <Bill>();
                mongo.Insert(CollectionNameDefine.Bill, bill);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #4
0
ファイル: TaskManageDA.cs プロジェクト: wuyb13526487308/-
        public string TaskCompile(Task task)
        {
            MongoDBHelper <Task> mongo = new MongoDBHelper <Task>();
            var query = new QueryDocument();

            query.Add("_id", task._id);
            var update = new UpdateDocument();

            update.Add("TaskState", task.TaskState);
            update.Add("Finished", QuShi.getDate());
            update.Add("MeterMac", task.MeterMac);
            update.Add("TaskDate", task.TaskDate);
            update.Add("TaskID", task.TaskID);
            update.Add("TaskType", task.TaskType);
            update.Add("TaskSource", task.TaskSource == null ?"":task.TaskSource);
            //update.Add("CommandList", task.CommandList);
            return(mongo.Update(CollectionNameDefine.TaskCollectionName, query, update));
        }
コード例 #5
0
        /// <summary>
        /// 设置报警参数任务
        /// </summary>
        /// <param name="info"></param>
        /// <param name="meter"></param>
        /// <returns></returns>
        public string SetWariningParameter(IoT_SetAlarm info, IoT_AlarmMeter meter)
        {
            string result = "";

            try
            {
                MongoDBHelper <Task> mongo_task = new MongoDBHelper <Task>();
                Task task = new Task();
                task.MeterMac  = meter.MeterNo.Trim();
                task.TaskDate  = QuShi.getDate();
                task.TaskID    = Guid.NewGuid().ToString(); //用于和指令进行进行关联
                task.TaskState = TaskState.Waitting;
                task.TaskType  = TaskType.TaskType_设置报警参数;  //
                //写任务
                mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task);
                meter.TaskID = task.TaskID;

                //3.设置报警参数
                DataItem_C103 item_C103 = new DataItem_C103(Convert.ToByte(new Random().Next(0, 255)), new WaringSwitchSign(info.SwitchTag));
                item_C103.长期未与服务器通讯报警时间 = Convert.ToByte(info.Par1);
                item_C103.燃气漏泄切断报警时间    = Convert.ToByte(info.Par2);
                item_C103.燃气流量过载切断报警时间  = Convert.ToByte(info.Par3);
                item_C103.异常大流量值        = MyDataConvert.TwoBCDStrToDecimal(info.Par4);
                item_C103.异常大流量切断报警时间   = Convert.ToByte(info.Par5);
                item_C103.异常微小流量切断报警时间  = Convert.ToByte(info.Par6);
                item_C103.持续流量切断报警时间    = Convert.ToByte(info.Par7);
                item_C103.长期未使用切断报警时间   = Convert.ToByte(info.Par8);
                //item_C103.长期未使用切断报警时间 = Convert.ToByte(info.Par7);

                Command cmd = new Command();
                cmd.TaskID         = task.TaskID;
                cmd.Identification = ((UInt16)item_C103.IdentityCode).ToString("X2");
                cmd.ControlCode    = (byte)ControlCode.CYWriteData;//设置参数
                cmd.DataLength     = Convert.ToByte(item_C103.Length);
                cmd.DataCommand    = MyDataConvert.BytesToHexStr(item_C103.GetBytes());
                cmd.Order          = 3;
                CommandDA.Insert(cmd);
            }
            catch (Exception e)
            {
                result = e.Message;
            }
            return(result);
        }
コード例 #6
0
        public static string Undo(string taskID)
        {
            //先读任务
            try
            {
                MongoDBHelper <Task> mongo = new MongoDBHelper <Task>();
                QueryDocument        query = new QueryDocument();
                query.Add("TaskID", taskID);
                MongoCursor <Task> mongoCursor = mongo.Query(CollectionNameDefine.TaskCollectionName, query);
                var dataList = mongoCursor.ToList();
                if (dataList == null || dataList.Count == 0)
                {
                    return("没有找到TaskID:【" + taskID + "】的任务。");
                }

                Task task = dataList[0];
                if (task.TaskState != TaskState.Waitting)
                {
                    return(string.Format("任务TaskID:{0}状态为:{1},不能撤销.", taskID, task.TaskState));
                }
                task.TaskState = TaskState.Undo;
                List <Command> list = CommandDA.QueryCommandList(task.TaskID);
                if (list != null && list.Count == 0)
                {
                    return(string.Format("任务TaskID:{0}的指令已执行,不能撤销.", taskID));
                }
                foreach (Command cmd in list)
                {
                    cmd.CommandState = CommandState.Undo;
                    cmd.AnswerDate   = QuShi.getDate();
                    CommandDA.Update(cmd);
                }
                new TaskManageDA().TaskCompile(task);
                return("");
            }
            catch (Exception e)
            {
                //记录日志
                Console.WriteLine(e.Message);
                return(e.Message);
            }
        }
コード例 #7
0
        public string TopUpFinished(string taskID, decimal money)
        {
            try
            {
                MongoDBHelper <Task> mongo = new MongoDBHelper <Task>();
                QueryDocument        query = new QueryDocument();
                query.Add("TaskID", taskID);
                MongoCursor <Task> mongoCursor = mongo.Query(CollectionNameDefine.TaskCollectionName, query);
                var dataList = mongoCursor.ToList();
                if (dataList == null || dataList.Count == 0)
                {
                    return("没有找到TaskID:【" + taskID + "】的任务。");
                }
                string    result = "";
                TaskState state  = TaskState.Finished;

                Task task = dataList[0];
                task.Finished  = QuShi.getDate();
                task.TaskState = state;

                TaskManageDA tm = new TaskManageDA();
                result = tm.TaskCompile(task);
                if (result != "")
                {
                    return(result);
                }
                if (state == TaskState.Finished)
                {
                    Meter _meter = tm.QueryMeter(task.MeterMac);
                    _meter.TotalTopUp           += money;
                    _meter.LastSettlementAmount += money;
                    _meter.CurrentBalance       += money;
                    result = tm.UpdateMeter(_meter);
                }
                return(result);
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
コード例 #8
0
        /// <summary>
        /// 记录资金结算记录
        /// </summary>
        /// <param name="record"></param>
        public void AddBillRecord(BillRecord record)
        {
            try
            {
                if (record == null)
                {
                    return;
                }

                MongoDBHelper <BillRecord> mongo = new MongoDBHelper <BillRecord>();
                mongo.Insert(CollectionNameDefine.BillRecord, record);
                if (record.BillRecordType == BillRecordType.结算点记录)
                {
                    //更新账单
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #9
0
        /// <summary>
        /// 创建充值任务
        /// </summary>
        /// <param name="topup">充值数据对象</param>
        /// <param name="taskID"></param>
        /// <returns></returns>
        public string TopUp(IoT_MeterTopUp topup, out string taskID)
        {
            //创建一个任务
            string result = "";
            MongoDBHelper <Task> mongo_task = new MongoDBHelper <Task>();
            Task task = new Task();

            task.MeterMac  = topup.MeterNo.Trim();
            task.TaskDate  = QuShi.getDate();
            task.TaskID    = Guid.NewGuid().ToString(); //用于和指令进行进行关联
            task.TaskState = TaskState.Waitting;
            task.TaskType  = TaskType.TaskType_充值;      //点火任务(DH),换表登记(HB)、开阀(KF)、关阀(GF)、充值(CZ)、调整价格(TJ)
            //写任务
            result = mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task);
            taskID = task.TaskID;
            if (result != "")
            {
                return(result);
            }

            //创建命令
            Command       cmd       = new Command();
            byte          ser       = Convert.ToByte(topup.Ser);//new Random().Next(0, 255));
            DataItem_A013 item_A013 = new DataItem_A013(ser, ser, (decimal)topup.Amount);

            cmd.TaskID         = task.TaskID;
            cmd.Identification = ((UInt16)item_A013.IdentityCode).ToString("X2");
            cmd.ControlCode    = (byte)ControlCode.WriteData;//写操作
            cmd.DataLength     = Convert.ToByte(item_A013.Length);
            cmd.DataCommand    = MyDataConvert.BytesToHexStr(item_A013.GetBytes());
            cmd.Order          = 1;
            result             = CommandDA.Insert(cmd);
            if (result != "")
            {
                return(result);
            }
            return("");
        }
コード例 #10
0
        public PricingPlan QueryPricingPlan(string meterNo)
        {
            MongoDBHelper <PricingPlan> mongo_plan = new MongoDBHelper <PricingPlan>();
            QueryDocument query = new QueryDocument();

            query.Add("MeterNo", meterNo);
            MongoCursor <PricingPlan> mongoCursor = mongo_plan.Query(CollectionNameDefine.MeterPricingPlan, query);

            if (mongoCursor == null)
            {
                return(null);
            }
            var dataList = mongoCursor.ToList();//.OrderBy(c => c.UseDate).ToList ();

            if (dataList != null && dataList.Count >= 1)
            {
                return(dataList[0]);
            }
            else
            {
                return(null);
            }
        }
コード例 #11
0
ファイル: TaskManageDA.cs プロジェクト: wuyb13526487308/-
        public Task QueryTask(string taskID)
        {
            try
            {
                MongoDBHelper <Task> mongo = new MongoDBHelper <Task>();
                QueryDocument        query = new QueryDocument();
                query.Add("TaskID", taskID);
                MongoCursor <Task> mongoCursor = mongo.Query(CollectionNameDefine.TaskCollectionName, query);
                var dataList = mongoCursor.ToList();


                if (dataList != null)
                {
                    return(dataList[0]);
                }
            }
            catch (Exception e)
            {
                //记录日志
                Console.WriteLine(e.Message);
            }
            return(null);
        }
コード例 #12
0
        //删除未执行的修正任务
        public void DeleteUnRunTask(string mac)
        {
            MongoDBHelper <Task> mongo = new MongoDBHelper <Task>();
            QueryDocument        query = new QueryDocument();

            query.Add("MeterMac", mac);
            query.Add("TaskState", 0);
            query.Add("TaskType", "XZ");

            MongoCursor <Task> mongoCursor = mongo.Query(CollectionNameDefine.TaskCollectionName, query);
            var dataList = mongoCursor.ToList();

            if (dataList != null && dataList.Count > 0)
            {
                foreach (Task task in dataList)
                {
                    var iDelete = new QueryDocument();
                    iDelete.Add("TaskID", task.TaskID);
                    mongo.Delete(CollectionNameDefine.CommandCollectionName, iDelete);
                }
                mongo.Delete(CollectionNameDefine.TaskCollectionName, query);
            }
        }
コード例 #13
0
        /// <summary>
        /// 设置结算日
        /// </summary>
        /// <param name="settlementDay"></param>
        /// <param name="meter"></param>
        /// <returns></returns>
        public string SetSettlementDay(IoT_SetSettlementDay settlementDay, IoT_SettlementDayMeter meter)
        {
            string result = "";

            try
            {
                MongoDBHelper <Task> mongo_task = new MongoDBHelper <Task>();
                Task task = new Task();
                task.MeterMac  = meter.MeterNo.Trim();
                task.TaskDate  = QuShi.getDate();
                task.TaskID    = Guid.NewGuid().ToString(); //用于和指令进行进行关联
                task.TaskState = TaskState.Waitting;
                task.TaskType  = TaskType.TaskType_设置结算日期;  //
                //写任务
                mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task);
                meter.TaskID = task.TaskID;

                //2.设置上传周期
                int JSDay   = (int)settlementDay.SettlementDay;
                int JSMonth = (int)settlementDay.SettlementMonth;

                DataItem_A011 item_A011 = new DataItem_A011(Convert.ToByte(new Random().Next(0, 255)), JSDay, JSMonth);
                Command       cmd       = new Command();
                cmd.TaskID         = task.TaskID;
                cmd.Identification = ((UInt16)item_A011.IdentityCode).ToString("X2");
                cmd.ControlCode    = (byte)ControlCode.WriteData;//设置参数
                cmd.DataLength     = Convert.ToByte(item_A011.Length);
                cmd.DataCommand    = MyDataConvert.BytesToHexStr(item_A011.GetBytes());
                cmd.Order          = 1;
                CommandDA.Insert(cmd);
            }
            catch (Exception e)
            {
                result = e.Message;
            }
            return(result);
        }
コード例 #14
0
        public static List <Command> QueryCommandList(string taskID)
        {
            MongoDBHelper <Command> mongo = new MongoDBHelper <Command>();

            try
            {
                QueryDocument query = new QueryDocument();
                query.Add("TaskID", taskID);
                query.Add("CommandState", 0);
                MongoCursor <Command> mongoCursor = mongo.Query(CollectionNameDefine.CommandCollectionName, query);
                var dataList = mongoCursor.ToList();
                if (dataList != null && dataList.Count >= 1)
                {
                    var qu = from p in dataList orderby p.Order ascending select p;
                    return(qu.ToList());
                }
            }
            catch (Exception e)
            {
                //记录日志
                Console.WriteLine(e.Message);
            }
            return(new List <Command>());
        }
コード例 #15
0
 public static string ValveControlFinished(string taskID, TaskState state)
 {
     try
     {
         MongoDBHelper <Task> mongo = new MongoDBHelper <Task>();
         QueryDocument        query = new QueryDocument();
         query.Add("TaskID", taskID);
         MongoCursor <Task> mongoCursor = mongo.Query(CollectionNameDefine.TaskCollectionName, query);
         var dataList = mongoCursor.ToList();
         if (dataList == null || dataList.Count == 0)
         {
             return("没有找到TaskID:【" + taskID + "】的任务。");
         }
         string result = "";
         Task   task   = dataList[0];
         task.Finished  = QuShi.getDate();
         task.TaskState = state;
         TaskManageDA tm = new TaskManageDA();
         result = tm.TaskCompile(task);
         if (result != "")
         {
             return(result);
         }
         Meter _meter = tm.QueryMeter(task.MeterMac);
         if (state == TaskState.Finished)
         {
             _meter.ValveState = task.TaskType == TaskType.TaskType_开阀 ? "0" : "1";
             result            = tm.UpdateMeter(_meter);
         }
         return(result);
     }
     catch (Exception e)
     {
         return(e.Message);
     }
 }
コード例 #16
0
        public static Meter QueryMeter(string mac)
        {
            Meter _m = null;

            try
            {
                MongoDBHelper <Meter> mongo = new MongoDBHelper <Meter>();
                QueryDocument         query = new QueryDocument();
                query.Add("Mac", mac);
                MongoCursor <Meter> mongoCursor = mongo.Query(CollectionNameDefine.MeterCollectionName, query);
                var dataList = mongoCursor.ToList();
                if (dataList != null && dataList.Count >= 1)
                {
                    _m             = dataList[0];
                    _m.PricingPlan = new PricingPlanDA().QueryPricingPlan(mac);
                }
            }
            catch (Exception e)
            {
                //记录日志
                Console.WriteLine(e.Message);
            }
            return(_m);
        }
コード例 #17
0
ファイル: TaskManageDA.cs プロジェクト: wuyb13526487308/-
        public string ChangeMeterInsert(IoT_Meter info, int currentLader, decimal currentPrice, decimal changeUseGas)
        {
            Meter _meter = QueryMeter(info.MeterNo.Trim());

            if (_meter != null)
            {
                MongoDBHelper <Meter> mongo = new MongoDBHelper <Meter>();
                var iDelete = new QueryDocument();
                iDelete.Add("Mac", info.MeterNo.Trim());
                mongo.Delete(CollectionNameDefine.MeterCollectionName, iDelete);
            }

            Meter meter = new Meter();

            meter.MeterID         = info.ID;
            meter.UserID          = info.CompanyID + info.UserID;
            meter.Key             = info.MKey;
            meter.Mac             = info.MeterNo.Trim();
            meter.MeterState      = info.MeterState.ToString();
            meter.MeterType       = info.MeterType;
            meter.MKeyVer         = (byte)(info.MKeyVer & 0xff);
            meter.PriceCheck      = info.PriceCheck.ToString();
            meter.SettlementDay   = (int)info.SettlementDay;
            meter.SettlementType  = info.SettlementType;
            meter.TotalAmount     = (decimal)info.TotalAmount; //表当前累计总量
            meter.TotalTopUp      = (decimal)info.TotalTopUp;  //充值金额
            meter.ValveState      = info.ValveState.ToString();
            meter.LastTopUpSer    = 0;                         //上次充值ver
            meter.IsUsedLadder    = (bool)info.IsUsed;
            meter.Ladder          = (int)info.Ladder;
            meter.MeterType       = info.MeterType;
            meter.Price1          = (decimal)info.Price1;
            meter.Price2          = (decimal)info.Price2;
            meter.Price3          = (decimal)info.Price3;
            meter.Price4          = (decimal)info.Price4;
            meter.Price5          = (decimal)info.Price5;
            meter.Gas1            = (decimal)info.Gas1;
            meter.Gas2            = (decimal)info.Gas2;
            meter.Gas3            = (decimal)info.Gas3;
            meter.Gas4            = (decimal)info.Gas4;
            meter.SettlementMonth = (int)info.SettlementMonth;
            meter.SettlementDay   = (int)info.SettlementDay;
            meter.SettlementType  = info.SettlementType;
            meter.CurrentLadder   = currentLader;
            meter.CurrentPrice    = currentPrice;
            decimal[] gas = new decimal[4];
            gas[0] = meter.Gas1;
            gas[1] = meter.Gas2;
            gas[2] = meter.Gas3;
            gas[3] = meter.Gas4;

            if (meter.IsUsedLadder)
            {
                meter.NextSettlementPointGas = meter.TotalAmount - changeUseGas;
                if (meter.CurrentLadder < meter.Ladder)
                {
                    for (int i = 0; i < meter.CurrentLadder; i++)
                    {
                        meter.NextSettlementPointGas += gas[i];
                    }
                }
                else
                {
                    meter.NextSettlementPointGas = -1;
                }
                meter.SetNextSettlementDateTime();
            }

            meter.LastGasPoint         = meter.TotalAmount;
            meter.CurrentBalance       = (decimal)info.TotalTopUp;
            meter.LastSettlementAmount = meter.CurrentBalance;
            meter.LastTotal            = meter.TotalAmount - changeUseGas;
            meter.LJMoney   = 0;
            meter.IsDianHuo = true;          //点火完成标记
            return(this.InsertMeter(meter)); //同时插入数据到mongoDB中
        }
コード例 #18
0
ファイル: TaskManageDA.cs プロジェクト: wuyb13526487308/-
        /// <summary>
        /// 添加表对象到mongodb库中(用于新表安装)
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public string InsertMeter(IoT_Meter info)
        {
            Meter _meter = QueryMeter(info.MeterNo.Trim());

            if (_meter != null)
            {
                MongoDBHelper <Meter> mongo = new MongoDBHelper <Meter>();
                var iDelete = new QueryDocument();
                iDelete.Add("Mac", info.MeterNo.Trim());
                mongo.Delete(CollectionNameDefine.MeterCollectionName, iDelete);
            }

            Meter meter = new Meter();

            meter.MeterID         = info.ID;
            meter.UserID          = info.CompanyID.Trim() + info.UserID.Trim();
            meter.Key             = info.MKey;
            meter.Mac             = info.MeterNo.Trim();
            meter.MeterState      = info.MeterState.ToString();
            meter.MeterType       = info.MeterType;
            meter.MKeyVer         = (byte)(info.MKeyVer & 0xff);
            meter.PriceCheck      = info.PriceCheck.ToString();
            meter.SettlementDay   = (int)info.SettlementDay;
            meter.SettlementType  = info.SettlementType;
            meter.TotalAmount     = (decimal)info.TotalAmount;
            meter.TotalTopUp      = (decimal)info.TotalTopUp;
            meter.ValveState      = info.ValveState.ToString();
            meter.LastTopUpSer    = 0;
            meter.IsUsedLadder    = (bool)info.IsUsed;
            meter.Ladder          = (int)info.Ladder;
            meter.MeterType       = info.MeterType;
            meter.Price1          = (decimal)info.Price1;
            meter.Price2          = (decimal)info.Price2;
            meter.Price3          = (decimal)info.Price3;
            meter.Price4          = (decimal)info.Price4;
            meter.Price5          = (decimal)info.Price5;
            meter.Gas1            = (decimal)info.Gas1;
            meter.Gas2            = (decimal)info.Gas2;
            meter.Gas3            = (decimal)info.Gas3;
            meter.Gas4            = (decimal)info.Gas4;
            meter.SettlementMonth = (int)info.SettlementMonth;
            meter.SettlementDay   = (int)info.SettlementDay;
            meter.SettlementType  = info.SettlementType;
            meter.CurrentLadder   = 1;
            meter.CurrentPrice    = meter.Price1;
            if (meter.IsUsedLadder && meter.CurrentLadder < meter.Ladder)
            {
                meter.NextSettlementPointGas = meter.TotalAmount + meter.Gas1;
                meter.SetNextSettlementDateTime();
            }
            meter.LastTotal            = meter.TotalAmount;
            meter.LastSettlementAmount = (decimal)info.TotalTopUp;
            meter.LastGasPoint         = meter.TotalAmount;
            meter.CurrentBalance       = (decimal)info.TotalTopUp;
            meter.LJMoney   = 0;
            meter.IsDianHuo = false;//点火标记 false 未点火
            meter.IsPricing = false;
            meter.CreateBillID();

            return(this.InsertMeter(meter));//同时插入数据到mongoDB中
        }
コード例 #19
0
        public string UpdateMeter(Meter meter)
        {
            MongoDBHelper <Meter> mongo = new MongoDBHelper <Meter>();
            var query = new QueryDocument();

            query.Add("_id", meter._id);
            var update = new UpdateDocument();

            update.Add("MeterID", meter.MeterID);
            update.Add("UserID", meter.UserID == null?"":meter.UserID);
            update.Add("Mac", meter.Mac);
            update.Add("MKeyVer", meter.MKeyVer);
            update.Add("Key", meter.Key);
            update.Add("MeterType", meter.MeterType);
            update.Add("TotalAmount", (double)meter.TotalAmount);
            update.Add("TotalTopUp", (double)meter.TotalTopUp);
            update.Add("SettlementType", meter.SettlementType);
            update.Add("SettlementDay", meter.SettlementDay);
            update.Add("SettlementMonth", meter.SettlementMonth);

            update.Add("ValveState", meter.ValveState);
            update.Add("MeterState", meter.MeterState);
            update.Add("PriceCheck", meter.PriceCheck);
            update.Add("LastTopUpSer", meter.LastTopUpSer);
            update.Add("LastJiaoShiDate", meter.LastJiaoShiDate == null ? DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : meter.LastJiaoShiDate);

            update.Add("IsUsedLadder", meter.IsUsedLadder);
            update.Add("Ladder", meter.Ladder);
            update.Add("Price1", (double)meter.Price1);
            update.Add("Price2", (double)meter.Price2);
            update.Add("Price3", (double)meter.Price3);
            update.Add("Price4", (double)meter.Price4);
            update.Add("Price5", (double)meter.Price5);
            update.Add("Gas1", (double)meter.Gas1);
            update.Add("Gas2", (double)meter.Gas2);
            update.Add("Gas3", (double)meter.Gas3);
            update.Add("Gas4", (double)meter.Gas4);
            update.Add("LastSettlementAmount", (double)meter.LastSettlementAmount);
            update.Add("LastTotal", (double)meter.LastTotal);

            //update.Add("MeterType", meter.MeterType);
            update.Add("NextSettlementPointGas", (double)meter.NextSettlementPointGas);//下一个结算点气量
            update.Add("CurrentLadder", meter.CurrentLadder);
            update.Add("CurrentPrice", (double)meter.CurrentPrice);
            update.Add("LastGasPoint", (double)meter.LastGasPoint);
            update.Add("CurrentBalance", (double)meter.CurrentBalance);
            update.Add("LJMoney", (double)meter.LJMoney);
            update.Add("SettlementDateTime", meter.SettlementDateTime == null ? "":meter.SettlementDateTime);
            update.Add("IsDianHuo", meter.IsDianHuo);
            update.Add("IsPricing", meter.IsPricing);
            update.Add("BillID", meter.BillID);
            update.Add("TiaoJiaPointGas", (double)meter.TiaoJiaPointGas);

            if (meter.PricingPlan != null)
            {
                MongoDB.Bson.BsonDocument b = new MongoDB.Bson.BsonDocument();
                b.Add("IsUsedLadder", meter.PricingPlan.IsUsedLadder);
                b.Add("Ladder", meter.PricingPlan.Ladder);
                b.Add("Price1", (double)meter.PricingPlan.Price1);
                b.Add("Gas1", (double)meter.PricingPlan.Gas1);
                b.Add("Price2", (double)meter.PricingPlan.Price2);
                b.Add("Gas2", (double)meter.PricingPlan.Gas2);
                b.Add("Price3", (double)meter.PricingPlan.Price3);
                b.Add("Gas3", (double)meter.PricingPlan.Gas3);
                b.Add("Price4", (double)meter.PricingPlan.Price4);
                b.Add("Gas4", (double)meter.PricingPlan.Gas4);
                b.Add("Price5", (double)meter.PricingPlan.Price5);
                b.Add("MeterType", meter.PricingPlan.MeterType);
                b.Add("UseDate", meter.PricingPlan.UseDate);
                update.Add("PricingPlan", b);
            }
            mongo.Update(CollectionNameDefine.MeterCollectionName, query, update);
            return("");
        }
コード例 #20
0
        /// <summary>
        /// 设置上传周期
        /// </summary>
        /// <param name="info"></param>
        /// <param name="meter"></param>
        /// <returns></returns>
        public string SetUploadCycle(IoT_SetUploadCycle info, IoT_UploadCycleMeter meter)
        {
            string result = "";

            try
            {
                MongoDBHelper <Task> mongo_task = new MongoDBHelper <Task>();
                Task task = new Task();
                task.MeterMac  = meter.MeterNo.Trim();
                task.TaskDate  = QuShi.getDate();
                task.TaskID    = Guid.NewGuid().ToString(); //用于和指令进行进行关联
                task.TaskState = TaskState.Waitting;
                task.TaskType  = TaskType.TaskType_设置上传周期;  //
                //写任务
                mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task);
                meter.TaskID = task.TaskID;

                /*上传周期模式:
                 * 00:以月为周期,在每个月的XX日YY时ZZ分上传数据;
                 * 01:以XX天为周期,在每XX天的YY时ZZ分上传数据,起点为每月的01日00时00分;
                 * 02:以YY时为周期,在每YY小时的ZZ分上传数据,起点为每天的00时00分;
                 * 03:以燃气表启动开始计时,以XX日YY时ZZ分上传数据
                 */
                ReportCycleType cycleType = ReportCycleType.时周期;

                if (info.ReportType == "00")
                {
                    cycleType = ReportCycleType.月周期;
                }
                else if (info.ReportType == "01")
                {
                    cycleType = ReportCycleType.天周期;
                }
                else if (info.ReportType == "02")
                {
                    cycleType = ReportCycleType.时周期;
                }
                else if (info.ReportType == "03")
                {
                    cycleType = ReportCycleType.周期采集;
                }

                /*周期参数,
                 * DD 天    范围:00-31
                 * HH 小时  范围:00-23
                 * MM 分钟  范围:00-59*/
                int DD = 1;
                int HH = 23;
                int MM = 59;
                try
                {
                    DD = Convert.ToInt32(info.Par.Substring(0, 2));
                    HH = Convert.ToInt32(info.Par.Substring(2, 2));
                    MM = Convert.ToInt32(info.Par.Substring(4, 2));
                }
                catch
                { }

                //2.设置上传周期
                DataItem_C105 item_C105 = new DataItem_C105(Convert.ToByte(new Random().Next(0, 255)), cycleType, DD, HH, MM);
                item_C105.type = (ReportCycleType)Convert.ToByte(info.ReportType);
                item_C105.XX   = Convert.ToUInt16(info.Par.Substring(0, 2));
                item_C105.YY   = Convert.ToUInt16(info.Par.Substring(2, 2));
                item_C105.ZZ   = Convert.ToUInt16(info.Par.Substring(4, 2));

                Command cmd = new Command();
                cmd.TaskID         = task.TaskID;
                cmd.Identification = ((UInt16)item_C105.IdentityCode).ToString("X2");
                cmd.ControlCode    = (byte)ControlCode.CYWriteData;//设置参数
                cmd.DataLength     = Convert.ToByte(item_C105.Length);
                cmd.DataCommand    = MyDataConvert.BytesToHexStr(item_C105.GetBytes());
                cmd.Order          = 2;
                CommandDA.Insert(cmd);
            }
            catch (Exception e)
            {
                result = e.Message;
            }
            return(result);
        }
コード例 #21
0
ファイル: M_ADService.cs プロジェクト: wuyb13526487308/-
        /// <summary>
        /// 发布广告
        /// </summary>
        /// <param name="ap">广告发布信息</param>
        /// <param name="listMeter">广告用户列表</param>
        /// <param name="aDItems">广告内容列表</param>
        /// <param name="type">发布类型</param>
        /// <returns></returns>
        public string PublishAD(ADPublish ap, List <ADPublisMeter> listMeter, List <ADItem> aDItems, PublishType type)
        {
            //创建一个任务
            ser++;

            MongoDBHelper <Task> mongo_task = new MongoDBHelper <Task>();
            // DataItem_C109(byte ser, ADPublishOperatorCode operatorCode,byte fileCount,List<ADFile> fileList)
            //发布文件列表
            List <Common.Item.ADFile> fileList = new List <Common.Item.ADFile>();
            //操作码
            ADPublishOperatorCode operatorCode = type == PublishType.NewPublish ? ADPublishOperatorCode.ReDefineList : ADPublishOperatorCode.AddList;
            //文件条数
            byte fileCount = (byte)aDItems.Count;

            foreach (ADItem item in aDItems)
            {
                Common.Item.ADFile aDfile = new Common.Item.ADFile((int)item.OrderID, item.StoreName, (DateTime)item.BDate, (DateTime)item.EDate, (int)item.Length, (int)item.FileLength);
                fileList.Add(aDfile);
            }

            foreach (ADPublisMeter meter in listMeter)
            {
                Task task = new Task();
                task.MeterMac   = meter.MeterNo.Trim();
                task.TaskDate   = QuShi.getDate();
                task.TaskID     = Guid.NewGuid().ToString(); //用于和指令进行进行关联
                task.TaskState  = TaskState.Waitting;
                task.TaskType   = TaskType.TaskType_发布广告;    //广告文件(GGF)
                task.TaskSource = string.Format("{0}|{1}|{2}", meter.AP_ID, meter.UserID, meter.CompanyID);
                mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task);

                //meter.TaskID = task.TaskID;  //设置任务编号
                //准备指令
                Command       cmd       = new Command();
                DataItem_C109 item_c109 = new DataItem_C109(ser, operatorCode, fileCount, fileList);
                cmd.Identification = ((UInt16)item_c109.IdentityCode).ToString("X2");;
                cmd.ControlCode    = (byte)ControlCode.CYWriteData;//设置参数
                byte[] tmp = item_c109.GetBytes();
                cmd.DataLength  = Convert.ToByte(tmp.Length);
                cmd.DataCommand = MyDataConvert.BytesToHexStr(tmp);  //指令内容
                cmd.Order       = (byte)1;

                cmd.TaskID = task.TaskID;

                CommandDA.Insert(cmd);
            }

            //Command cmd = new Command();
            //byte ser = Convert.ToByte(new Random().Next(0, 255));
            //byte fileid = (byte)adfile.id;//广告命令 只存储文件编号
            //byte[] contentAllBytes = new byte[1];
            //contentAllBytes[0] = fileid;
            ////1.文件发送
            //DataItem_C108 item_C108 = new DataItem_C108(ser, adfile.FileName, 1, 1, 1, 1, contentAllBytes);//
            //cmd.TaskID = task.TaskID;
            //cmd.Identification = ((UInt16)item_C108.IdentityCode).ToString("X2"); ;
            //cmd.ControlCode = (byte)ControlCode.CYWriteData;//设置参数
            //cmd.DataLength = Convert.ToByte(contentAllBytes.Length);
            //cmd.DataCommand = MyDataConvert.BytesToHexStr(item_C108.GetBytes()); ; //文件内容
            //cmd.Order = (byte)1;
            //CommandDA.Insert(cmd);


            //1.文件配置发送指令
            //cmd = new Command();
            //DataItem_C109 item_C109 = new DataItem_C109(Convert.ToByte(new Random().Next(0, 255)), adddfile.FileNO, adddfile.FileName, adddfile.DTStart, adddfile.DTEnd, adddfile.PollTime, adddfile.OpShowStatus, adddfile.OpDeleteStatus);//
            //cmd.TaskID = task.TaskID;
            //cmd.Identification = ((UInt16)item_C109.IdentityCode).ToString("X2");
            //cmd.ControlCode = (byte)ControlCode.CYWriteData;//设置参数
            //cmd.DataLength = Convert.ToByte(item_C109.Length);
            //cmd.DataCommand = MyDataConvert.BytesToHexStr(item_C109.GetBytes());
            //cmd.Order = (byte)(2);
            //CommandDA.Insert(cmd);

            return("");//返回空表示成功
        }
コード例 #22
0
        /// <summary>
        /// 换表申请指令
        /// </summary>
        /// <returns></returns>
        public string SubmitASK(string taskID, IoT_Meter meter, decimal LJGas)
        {
            /*数据标识DI,序号SER,当前累计用量(金额),当前剩余用量(气量/金额),本阶梯周期已使用累计用量(气量)*/

            //创建一个任务
            MongoDBHelper <Task> mongo_task = new MongoDBHelper <Task>();
            Task task = new Task();

            task.MeterMac  = meter.MeterNo.Trim();
            task.TaskDate  = QuShi.getDate();
            task.TaskID    = taskID;                 //用于和指令进行进行关联
            task.TaskState = TaskState.Waitting;
            task.TaskType  = TaskType.TaskType_换表登记; //点火任务(DH),换表登记(HB)、开阀(KF)、关阀(GF)、充值(CZ)、调整价格(TJ)
            //写任务
            mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task);

            Command cmd = new Command();
            byte    ser = Convert.ToByte(new Random().Next(0, 255));

            cmd = new Command();
            //1.写密钥
            //DataItem_A014 item_A014 = new DataItem_A014(ser, (byte)meter.MKeyVer, meter.MKey);//
            //cmd.TaskID = task.TaskID;
            //cmd.Identification = ((UInt16)item_A014.IdentityCode).ToString("X2");
            //cmd.ControlCode = (byte)ControlCode.WriteData;//写操作
            //cmd.DataLength = Convert.ToByte(item_A014.Length);
            //cmd.DataCommand = MyDataConvert.BytesToHexStr(item_A014.GetBytes());
            //cmd.Order = 1;
            //CommandDA.Insert(cmd);

            ////2.设置上传周期
            //DataItem_C105 item_C105 = new DataItem_C105(Convert.ToByte(new Random().Next(0, 255)), ReportCycleType.天周期, 1, 23, 59);
            //cmd = new Command();
            //cmd.TaskID = task.TaskID;
            //cmd.Identification = ((UInt16)item_C105.IdentityCode).ToString("X2");
            //cmd.ControlCode = (byte)ControlCode.CYWriteData;//设置参数
            //cmd.DataLength = Convert.ToByte(item_C105.Length);
            //cmd.DataCommand = MyDataConvert.BytesToHexStr(item_C105.GetBytes());
            //cmd.Order = 2;
            //CommandDA.Insert(cmd);

            ////3.设置报警参数
            //DataItem_C103 item_C103 = new DataItem_C103(Convert.ToByte(new Random().Next(0, 255)), new WaringSwitchSign() { 长期未使用切断报警 = true, 长期未与服务器通讯报警 = true });
            //cmd = new Command();
            //cmd.TaskID = task.TaskID;
            //cmd.Identification = ((UInt16)item_C103.IdentityCode).ToString("X2");
            //cmd.ControlCode = (byte)ControlCode.CYWriteData;//设置参数
            //cmd.DataLength = Convert.ToByte(item_C103.Length);
            //cmd.DataCommand = MyDataConvert.BytesToHexStr(item_C103.GetBytes());
            //cmd.Order = 3;
            //CommandDA.Insert(cmd);

            //4.写价格表
            DataItem_A010 item_A010 = null;
            CT            ct        = new CT(meter.MeterType == "00" ? MeterType.气量表 : MeterType.金额表,
                                             (bool)meter.IsUsed, (JieSuanType)Convert.ToInt16(meter.SettlementType.ToString()), meter.Ladder == null ? 1 : (int)meter.Ladder);

            item_A010           = new DataItem_A010(Convert.ToByte(new Random().Next(0, 255)), ct, DateTime.Now);
            item_A010.Price1    = (decimal)meter.Price1;
            item_A010.Price2    = (decimal)meter.Price2;
            item_A010.Price3    = (decimal)meter.Price3;
            item_A010.Price4    = (decimal)meter.Price4;
            item_A010.Price5    = (decimal)meter.Price5;
            item_A010.UseGas1   = (decimal)meter.Gas1;
            item_A010.UseGas2   = (decimal)meter.Gas2;
            item_A010.UseGas3   = (decimal)meter.Gas3;
            item_A010.UseGas4   = (decimal)meter.Gas4;
            item_A010.StartDate = DateTime.Now;

            cmd                = new Command();
            cmd.TaskID         = task.TaskID;
            cmd.Identification = ((UInt16)item_A010.IdentityCode).ToString("X2");
            cmd.ControlCode    = (byte)ControlCode.WriteData;//设置参数
            cmd.DataLength     = Convert.ToByte(item_A010.Length);
            cmd.DataCommand    = MyDataConvert.BytesToHexStr(item_A010.GetBytes());
            cmd.Order          = 4;
            CommandDA.Insert(cmd);

            //5.写结算日
            DataItem_A011 item_a011 = new DataItem_A011(Convert.ToByte(new Random().Next(0, 255)), Convert.ToByte(meter.SettlementDay));

            item_a011.JieSuanMonth = 1;//根据系统定义取值
            cmd                = new Command();
            cmd.TaskID         = task.TaskID;
            cmd.Identification = ((UInt16)item_a011.IdentityCode).ToString("X2");
            cmd.ControlCode    = (byte)ControlCode.WriteData;//设置参数
            cmd.DataLength     = Convert.ToByte(item_a011.Length);
            cmd.DataCommand    = MyDataConvert.BytesToHexStr(item_a011.GetBytes());

            cmd.Order = 5;
            CommandDA.Insert(cmd);
            //6.写换表指令
            DataItem_C107 item_C107 = new DataItem_C107(Convert.ToByte(new Random().Next(0, 255)), 0.0m, (decimal)meter.TotalTopUp, LJGas);

            cmd                = new Command();
            cmd.TaskID         = task.TaskID;
            cmd.Identification = ((UInt16)item_C107.IdentityCode).ToString("X2");
            cmd.ControlCode    = (byte)ControlCode.CYWriteData;//设置参数
            cmd.DataLength     = Convert.ToByte(item_C107.Length);
            cmd.DataCommand    = MyDataConvert.BytesToHexStr(item_C107.GetBytes());
            cmd.Order          = 6;
            CommandDA.Insert(cmd);
            return("");
        }