Пример #1
0
        public string ReadIotUser(string account, string pwd, int index, int count)
        {
            IotUser user = new IotUser();

            //Query

            return(Newtonsoft.Json.JsonConvert.SerializeObject(user));
        }
Пример #2
0
        public string AddIotUser(string account, string pwd, string userInfoJson, string meterInfoJson)
        {
            string  LoginPsw  = pwd;
            string  CompanyID = string.Empty;
            string  OperID    = string.Empty;
            IotUser _iotUser  = new IotUser();

            try
            {
                string[] acc = account.Replace("-", "").Split('@');
                if (acc.Length != 2)
                {
                    return("账号错误");
                }
                //验证账号密码
                string result = Login(account, pwd);
                if (result != "")
                {
                    return(result);
                }
                OperID    = acc[0];
                CompanyID = acc[1];

                IoT_User  user  = Newtonsoft.Json.JsonConvert.DeserializeObject <IoT_User>(userInfoJson);
                IoT_Meter meter = Newtonsoft.Json.JsonConvert.DeserializeObject <IoT_Meter>(meterInfoJson);
                user.CompanyID  = CompanyID;
                meter.CompanyID = CompanyID;
                meter.UserID    = user.UserID;
                user.State      = '1';//设置为等待点火状态

                WCFServiceProxy <IUserManage> proxy = new WCFServiceProxy <IUserManage>();
                Message jsonMessage = proxy.getChannel.Add(user);
                if (!jsonMessage.Result)
                {
                    proxy.CloseChannel();
                    return(Newtonsoft.Json.JsonConvert.SerializeObject(jsonMessage));
                }
                IoT_User resultUser = Newtonsoft.Json.JsonConvert.DeserializeObject <IoT_User>(jsonMessage.TxtMessage);
                meter.UserID    = resultUser.UserID;
                meter.MeterType = "00";
                _iotUser.User   = resultUser;

                //表安装
                WCFServiceProxy <IMeterManage> _proxy = new WCFServiceProxy <IMeterManage>();
                jsonMessage = _proxy.getChannel.Add(meter);
                if (!jsonMessage.Result)
                {
                    //删除用户档案
                    proxy.getChannel.Delete(user);
                    proxy.CloseChannel();
                    _proxy.CloseChannel();
                    return(Newtonsoft.Json.JsonConvert.SerializeObject(jsonMessage));;
                }
                proxy.CloseChannel();
                _proxy.CloseChannel();
                IoT_Meter resultMeter = Newtonsoft.Json.JsonConvert.DeserializeObject <IoT_Meter>(jsonMessage.TxtMessage);
                _iotUser.Meter = resultMeter;

                return(Newtonsoft.Json.JsonConvert.SerializeObject(new Message()
                {
                    Result = true,
                    TxtMessage = Newtonsoft.Json.JsonConvert.SerializeObject(_iotUser)
                }));
            }
            catch (Exception e)
            {
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new Message()
                {
                    Result = false,
                    TxtMessage = e.Message
                }));
            }
        }