コード例 #1
0
        public Message Delete(IoT_User 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_User> tbl = dd.GetTable <IoT_User>();
                var s = tbl.Where(p => p.CompanyID == info.CompanyID && p.UserID == info.UserID).Single();
                tbl.DeleteOnSubmit(s as IoT_User);


                // 更新操作
                dd.SubmitChanges();
                m = new Message()
                {
                    Result     = true,
                    TxtMessage = "删除用户成功!"
                };
            }
            catch (Exception e)
            {
                m = new Message()
                {
                    Result     = false,
                    TxtMessage = "删除用户失败!" + e.Message
                };
            }
            return(m);
        }
コード例 #2
0
        public Message Edit(IoT_User 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_User dbinfo = dd.GetTable <IoT_User>().Where(p =>
                                                                 p.CompanyID == info.CompanyID && p.UserID == info.UserID).SingleOrDefault();

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

                // 更新操作
                dd.SubmitChanges();
                m = new Message()
                {
                    Result     = true,
                    TxtMessage = JSon.TToJson <IoT_User>(dbinfo)
                };
            }
            catch (Exception e)
            {
                m = new Message()
                {
                    Result     = false,
                    TxtMessage = "编辑用户失败!" + e.Message
                };
            }
            return(m);
        }
コード例 #3
0
        public void UpdateIotUserTest()
        {
            IoT_User userInfo = new IoT_User()
            {
                UserID    = "2018040032",
                Address   = $"街道-测试地址-修改{DateTime.Now.ToString("yyyyMMddHHmmss.fff")}",
                Street    = $"街道",
                Community = "花语里(二期)",
                BGL       = true,
                Door      = "123",
                DY        = "1单元",
                Phone     = "13526487308",
                LD        = "28号楼",
                SFZH      = "1234567890123654",
                UserType  = "0",
                UserName  = "******"
            };
            IoT_Meter meterinfo = new IoT_Meter()
            {
                MeterNo      = "13526487308992",//表号,物联网表号,14位数字字符串
                Direction    = "左表",
                InstallDate  = DateTime.Now,
                InstallPlace = "低位安装",
                Installer    = "武宜波",
                MeterModel   = "户内"
            };

            User   user   = new User();
            string result = user.UpdateIotUser(userInfo, meterinfo);

            Assert.AreEqual(result, "", true);
        }
コード例 #4
0
        public void AddIotUserTest()
        {
            //测试添加燃气用户
            Random   random   = new System.Random();
            IoT_User userInfo = new IoT_User()
            {
                SF_UserId = $"{DateTime.Now.ToString("ddHHmm")}{random.Next(1000, 9999).ToString()}",
                Address   = $"街道-测试地址{DateTime.Now.ToString("yyyyMMddHHmmss.fff")}",
                Street    = $"街道-{random.Next(1, 9999).ToString()}",
                Community = "花语里(二期)",
                BGL       = true,
                Door      = "",
                DY        = "1单元",
                Phone     = "13526487308",
                LD        = "28号楼",
                SFZH      = "1234567890123657",
                UserType  = "0",
                UserName  = "******"
            };
            IoT_Meter meterinfo = new IoT_Meter()
            {
                MeterNo      = "13526487308995",//表号,物联网表号,14位数字字符串
                Direction    = "右表",
                InstallDate  = DateTime.Now,
                InstallPlace = "高位安装",
                Installer    = "",
                MeterModel   = "户内"
            };
            User   user   = new User();
            string result = user.AddIotUser(userInfo, meterinfo);

            Assert.AreEqual(result, "", true);
        }
コード例 #5
0
        /// <summary>
        /// 批量添加用户
        /// </summary>
        /// <param name="info"></param>
        /// <param name="meter"></param>
        /// <returns></returns>
        public Message BatchAddUserMeter(IoT_User info, IoT_Meter meter)
        {
            // 定义执行结果
            Message m;
            string  configName = System.Configuration.ConfigurationManager.AppSettings["defaultDatabase"];
            //Linq to SQL 上下文对象
            DataContext dd = new DataContext(System.Configuration.ConfigurationManager.ConnectionStrings[configName].ConnectionString);

            try
            {
                var count = dd.GetTable <IoT_Meter>().Where(p => p.CompanyID == meter.CompanyID && p.MeterNo == meter.MeterNo).Count();
                if (count > 0)
                {
                    m = new Message()
                    {
                        Result     = false,
                        TxtMessage = "表号不能重复!"
                    };
                    return(m);
                }


                Table <IoT_User> tbl = dd.GetTable <IoT_User>();
                info.UserID = GetUserID();
                if (info.UserID == "-1")
                {
                    m = new Message()
                    {
                        Result     = false,
                        TxtMessage = "新增用户失败!" + "获取用户id错误"
                    };
                    return(m);
                }
                // 调用新增方法
                tbl.InsertOnSubmit(info);
                // 更新操作
                dd.SubmitChanges();

                meter.UserID = info.UserID;
                MeterManageService meterService = new MeterManageService();
                m = meterService.Add(meter);
            }
            catch (Exception e)
            {
                m = new Message()
                {
                    Result     = false,
                    TxtMessage = "新增用户失败!" + e.Message
                };
            }
            return(m);
        }
コード例 #6
0
ファイル: MeterTest.cs プロジェクト: wuyb13526487308/-
        /// <summary>
        /// 批量报装
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //起始表号
                long meterNoStart = Convert.ToInt64(this.textBox1.Text);

                //表数目
                int meterNum = Convert.ToInt32(this.textBox2.Text);

                userIdList  = new List <string>();
                meterIdList = new List <string>();

                for (int i = 0; i < meterNum; i++)
                {
                    //创建测试用户
                    IoT_User user = new IoT_User()
                    {
                        Address   = "测试用户" + i + "的地址",
                        Community = "1",
                        CompanyID = "zzcy",
                        Door      = "测试门牌号",
                        Phone     = "xxxxxxxxxxxx",
                        State     = '1',
                        Street    = "1",
                        UserName  = "******" + i
                    };
                    //创建测试表具
                    IoT_Meter meter = new IoT_Meter()
                    {
                        CompanyID = "zzcy",
                        MeterNo   = (meterNoStart + i).ToString(),
                        MeterType = "01"
                    };
                    CY.IotM.Common.Message m = userService.getChannel.BatchAddUserMeter(user, meter);
                    if (!m.Result)
                    {
                        MessageBox.Show(m.TxtMessage);
                        return;
                    }
                    userIdList.Add(user.UserID);
                    meterIdList.Add(meter.MeterNo);
                }
                MessageBox.Show("批量创建测试用户完成");
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #7
0
        /// <summary>
        /// 批量导入用户
        /// </summary>
        /// <param name="meterNo"></param>
        /// <returns></returns>
        public Message BatchImport(string meterNo)
        {
            // 定义执行结果
            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_UserTemp> tbl    = dd.GetTable <IoT_UserTemp>();
                IoT_UserTemp         dbInfo = tbl.Where(p => p.MeterNo == meterNo).SingleOrDefault();

                IoT_User user = new IoT_User()
                {
                    UserName  = dbInfo.UserName,
                    CompanyID = dbInfo.CompanyID,
                    Address   = dbInfo.Address,
                    Phone     = dbInfo.Phone,
                    UserType  = dbInfo.UserType,
                    State     = '1'
                };
                bool      result = DateTime.TryParse(dbInfo.InstallDate, out DateTime installDate);
                IoT_Meter meter  = new IoT_Meter()
                {
                    MeterNo     = dbInfo.MeterNo,
                    TotalAmount = dbInfo.MeterNum,
                    InstallType = dbInfo.InstallType,
                    Direction   = dbInfo.Direction,
                    InstallDate = result ? installDate : DateTime.Now,
                    CompanyID   = dbInfo.CompanyID
                };

                m = BatchAddUserMeter(user, meter);
                tbl.DeleteOnSubmit(dbInfo);
                dd.SubmitChanges();
            }
            catch (Exception e)
            {
                m = new Message()
                {
                    Result     = false,
                    TxtMessage = "新增用户失败!" + e.Message
                };
            }
            return(m);
        }
コード例 #8
0
        public Message Add(IoT_User 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_User> tbl = dd.GetTable <IoT_User>();

                info.UserID = GetUserID();
                if (info.UserID == "-1")
                {
                    m = new Message()
                    {
                        Result     = false,
                        TxtMessage = "新增用户失败!" + "获取用户id错误"
                    };
                    return(m);
                }

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

                m = new Message()
                {
                    Result     = true,
                    TxtMessage = JSon.TToJson <IoT_User>(info)
                };
            }
            catch (Exception e)
            {
                m = new Message()
                {
                    Result     = false,
                    TxtMessage = "新增用户失败!" + e.Message
                };
            }
            return(m);
        }
コード例 #9
0
        public override void DoLoginedHandlerWork(HttpContext context)
        {
            Message jsonMessage;

            jsonMessage = new Message()
            {
                Result     = false,
                TxtMessage = "权限验证失败,可能原因:\n1、数据中心通讯失败。\n2、系统管理员未与您分配对应操作权限。"
            };
            //获取操作类型AType:ADD,EDIT,DELETE
            string   AjaxType = context.Request.QueryString["AType"] == null ? string.Empty : context.Request.QueryString["AType"].ToString().ToUpper();
            IoT_User Info; View_UserMeter viewInfo;
            WCFServiceProxy <IUserManage> proxy = null;

            try
            {
                switch (AjaxType)
                {
                //查询用户
                case "QUERY":

                    CommonSearch <IoT_User> InfoSearch = new CommonSearch <IoT_User>();
                    string Where = "1=1 ";
                    Where += "AND CompanyID='" + loginOperator.CompanyID + "' ";
                    if (context.Request.Form["TWhere"] != null && context.Request.Form["TWhere"].ToString().Trim() != string.Empty)
                    {
                        Where += context.Request.Form["TWhere"].ToString();
                    }
                    SearchCondition sCondition = new SearchCondition()
                    {
                        TBName = "IoT_User", TFieldKey = "UserID", TTotalCount = -1, TPageCurrent = 1, TFieldOrder = "UserID ASC", TWhere = Where
                    };
                    List <IoT_User> list = InfoSearch.GetList(ref sCondition, context);
                    jsonMessage = new Message()
                    {
                        Result     = true,
                        TxtMessage = JSon.ListToJson <IoT_User>(list, sCondition.TTotalCount)
                    };
                    break;

                //查询用户表具视图
                case "QUERYVIEW":

                    CommonSearch <View_UserMeter> InfoSearchView = new CommonSearch <View_UserMeter>();
                    Where  = "1=1 ";
                    Where += "AND CompanyID='" + loginOperator.CompanyID + "' ";
                    if (context.Request.Form["TWhere"] != null && context.Request.Form["TWhere"].ToString().Trim() != string.Empty)
                    {
                        Where += context.Request.Form["TWhere"].ToString();
                    }
                    sCondition = new SearchCondition()
                    {
                        TBName = "View_UserMeter", TFieldKey = "UserID", TTotalCount = -1, TPageCurrent = 1, TFieldOrder = "UserID ASC", TWhere = Where
                    };
                    List <View_UserMeter> listView = InfoSearchView.GetList(ref sCondition, context);
                    jsonMessage = new Message()
                    {
                        Result     = true,
                        TxtMessage = JSon.ListToJson <View_UserMeter>(listView, sCondition.TTotalCount)
                    };
                    break;

                //查询临时用户
                case "QUERYTEMP":

                    CommonSearch <IoT_UserTemp> InfoSearchTemp = new CommonSearch <IoT_UserTemp>();
                    Where  = "1=1 ";
                    Where += "AND CompanyID='" + loginOperator.CompanyID + "' ";
                    if (context.Request.Form["TWhere"] != null && context.Request.Form["TWhere"].ToString().Trim() != string.Empty)
                    {
                        Where += context.Request.Form["TWhere"].ToString();
                    }
                    sCondition = new SearchCondition()
                    {
                        TBName = "IoT_UserTemp", TFieldKey = "MeterNo", TTotalCount = -1, TPageCurrent = 1, TFieldOrder = "MeterNo ASC", TWhere = Where
                    };
                    List <IoT_UserTemp> listTemp = InfoSearchTemp.GetList(ref sCondition, context);
                    jsonMessage = new Message()
                    {
                        Result     = true,
                        TxtMessage = JSon.ListToJson <IoT_UserTemp>(listTemp, sCondition.TTotalCount)
                    };
                    break;

                case "QUERYALARMPARM":
                    //TODO:查询用户当前设置的报警参数
                    CommonSearch <Iot_MeterAlarmPara> meterAlarmPara = new CommonSearch <Iot_MeterAlarmPara>();
                    viewInfo = new CommonModelFactory <View_UserMeter>().GetModelFromContext(context);

                    if (viewInfo.MeterNo != null && viewInfo.MeterNo.ToString().Trim() != string.Empty)
                    {
                        Where      = $"MeterNo = '{viewInfo.MeterNo.ToString().Trim()}'";
                        sCondition = new SearchCondition()
                        {
                            TBName = "Iot_MeterAlarmPara", TFieldKey = "MeterNo", TTotalCount = -1, TPageCurrent = 1, TFieldOrder = "MeterNo ASC", TWhere = Where
                        };
                        List <Iot_MeterAlarmPara> listMAP = meterAlarmPara.GetList(ref sCondition, context);
                        if (listMAP.Count == 1)
                        {
                            jsonMessage = new Message()
                            {
                                Result     = true,
                                TxtMessage = JsToJson.SerializeToJsonString(listMAP[0])
                            };
                        }
                        else
                        {
                            jsonMessage = new Message()
                            {
                                Result     = false,
                                TxtMessage = "没有找到配置数据。"
                            };
                        }
                    }
                    break;

                //单户创建
                case "ADD":
                    if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "cjyh_dhcj"))
                    {
                        Info           = new CommonModelFactory <IoT_User>().GetModelFromContext(context);
                        Info.CompanyID = base.loginOperator.CompanyID;
                        proxy          = new WCFServiceProxy <IUserManage>();
                        jsonMessage    = proxy.getChannel.Add(Info);
                    }
                    break;


                //编辑用户信息和表信息
                case "EDITUSERMETER":
                    if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "dagl_bjyh"))
                    {
                        viewInfo    = new CommonModelFactory <View_UserMeter>().GetModelFromContext(context);
                        proxy       = new WCFServiceProxy <IUserManage>();
                        jsonMessage = proxy.getChannel.EditUserMeter(viewInfo);
                    }
                    break;

                //删除用户信息和表信息
                case "DELETEUSERMETER":
                    if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "dagl_scyh"))
                    {
                        viewInfo    = new CommonModelFactory <View_UserMeter>().GetModelFromContext(context);
                        proxy       = new WCFServiceProxy <IUserManage>();
                        jsonMessage = proxy.getChannel.DeleteUserMeter(viewInfo);
                    }
                    break;

                //批量删除用户
                case "BATCHDELETE":
                    if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "dagl_scyh"))
                    {
                        viewInfo = new CommonModelFactory <View_UserMeter>().GetModelFromContext(context);
                        proxy    = new WCFServiceProxy <IUserManage>();

                        if (context.Request.Form["strNo"] != null && context.Request.Form["strNo"].ToString().Trim() != string.Empty)
                        {
                            string strNo = context.Request.Form["strNo"];

                            string[] arrNo = strNo.Split(',');

                            for (int i = 0; i < arrNo.Length; i++)
                            {
                                proxy.getChannel.BatchDeleteUserMeter(arrNo[i]);
                            }
                        }
                        jsonMessage = new Message()
                        {
                            Result     = true,
                            TxtMessage = "删除用户成功"
                        };
                    }
                    break;

                //批量excel导入
                case "BATCHIMPORT":
                    if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "cjyh_dhcj"))
                    {
                        viewInfo = new CommonModelFactory <View_UserMeter>().GetModelFromContext(context);
                        proxy    = new WCFServiceProxy <IUserManage>();

                        if (context.Request.Form["strNo"] != null && context.Request.Form["strNo"].ToString().Trim() != string.Empty)
                        {
                            string strNo = context.Request.Form["strNo"];

                            string[] arrNo = strNo.Split(',');

                            for (int i = 0; i < arrNo.Length; i++)
                            {
                                proxy.getChannel.BatchImport(arrNo[i]);
                            }
                        }
                        jsonMessage = new Message()
                        {
                            Result     = true,
                            TxtMessage = "导入用户成功"
                        };
                    }
                    break;

                //批量添加用户
                case "BATCHADD":
                    if (CommonOperRightHelper.CheckMenuCode(base.loginOperator, "cjyh_dhcj"))
                    {
                        viewInfo = new CommonModelFactory <View_UserMeter>().GetModelFromContext(context);
                        proxy    = new WCFServiceProxy <IUserManage>();

                        string street = "";
                        if (context.Request.Form["Street"] != null && context.Request.Form["Street"].ToString().Trim() != string.Empty)
                        {
                            street = context.Request.Form["Street"].ToString().Trim();
                        }
                        string community = "";
                        if (context.Request.Form["Community"] != null && context.Request.Form["Community"].ToString().Trim() != string.Empty)
                        {
                            community = context.Request.Form["Community"].ToString().Trim();
                        }
                        string meterType = "";
                        if (context.Request.Form["MeterType"] != null && context.Request.Form["MeterType"].ToString().Trim() != string.Empty)
                        {
                            meterType = context.Request.Form["MeterType"].ToString().Trim();
                        }

                        if (context.Request.Form["Rows"] != null && context.Request.Form["Rows"].ToString().Trim() != string.Empty)
                        {
                            UserRows    rows     = JsToJson.Deserialize <UserRows>(context.Request.Form["Rows"].ToString());
                            List <User> userlist = rows.Rows;

                            int     count = 0; string error = "";
                            Message tempM = null;
                            foreach (User u in userlist)
                            {
                                if (u.MeterNo.Trim() == "")
                                {
                                    tempM = new Message()
                                    {
                                        Result = false, TxtMessage = string.Format("UserID={0}的表号未填写\r", u.UserID)
                                    };
                                }
                                else
                                {
                                    IoT_User tempUser = new IoT_User();

                                    tempUser.UserID    = u.UserID;
                                    tempUser.UserName  = u.UserName;
                                    tempUser.Address   = u.Address;
                                    tempUser.Community = community;
                                    tempUser.Street    = street;
                                    tempUser.CompanyID = loginOperator.CompanyID;
                                    tempUser.State     = '1';

                                    IoT_Meter tempMeter = new IoT_Meter();
                                    tempMeter.MeterType = meterType;
                                    tempMeter.MeterNo   = u.MeterNo;
                                    tempMeter.CompanyID = loginOperator.CompanyID;
                                    tempM = proxy.getChannel.BatchAddUserMeter(tempUser, tempMeter);
                                }
                                if (tempM.Result)
                                {
                                    count++;
                                }
                                else
                                {
                                    error = tempM.TxtMessage;
                                }
                            }
                            if (count > 0)
                            {
                                jsonMessage = new Message()
                                {
                                    Result     = true,
                                    TxtMessage = "批量添加用户" + count + "个成功," + (userlist.Count - count) + "个失败,失败原因:" + error
                                };
                            }
                            else
                            {
                                jsonMessage = new Message()
                                {
                                    Result     = false,
                                    TxtMessage = "批量添加用户失败"
                                };
                            }
                        }
                    }
                    break;

                default:
                    jsonMessage = new Message()
                    {
                        Result     = false,
                        TxtMessage = "操作未定义。"
                    };
                    break;
                }
            }
            catch (Exception ex) {
                jsonMessage = new Message()
                {
                    Result     = false,
                    TxtMessage = ex.Message
                };
            }
            finally
            {
                if (proxy != null)
                {
                    proxy.CloseChannel();
                }
            }
            context.Response.Write(JSon.TToJson <Message>(jsonMessage));
        }
コード例 #10
0
        public string UpdateIotUser(string account, string pwd, string userInfoJson, string meterInfoJson)
        {
            string LoginPsw  = pwd;
            string CompanyID = string.Empty;
            string OperID    = string.Empty;

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

                //验证账号密码
                string result = Login(account, pwd);
                if (result != "")
                {
                    return(result);
                }
                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;

                View_UserMeter viewInfo = new View_UserMeter()
                {
                    CompanyID = user.CompanyID,
                    Address   = user.Address,
                    Community = user.Community,
                    Door      = user.Door,
                    BGL       = user.BGL,
                    BWGCD     = user.BWGCD,
                    BXGMRQ    = user.BXGMRQ,
                    BXGMRSFZ  = user.BXGMRSFZ,
                    BXYXQ     = user.BXYXQ,
                    BZCZYBH   = user.BZCZYBH,
                    BZFY      = user.BZFY,
                    BZRQ      = user.BZRQ,
                    DY        = user.DY,
                    LD        = user.LD,
                    Phone     = user.Phone,
                    FYQHTR    = user.FYQHTR,
                    UserID    = user.UserID,
                    UserName  = user.UserName,
                    UserType  = user.UserType,
                    SFZH      = user.SFZH,
                    Street    = user.Street,
                    SYBWG     = user.SYBWG,
                    YGBX      = user.YGBX,
                    QYQHTR    = user.QYQHTR,
                    YJBZFY    = user.YJBZFY,
                    YQHTBH    = user.YQHTBH,
                    YQHTQD    = user.YQHTQD,
                    YQHTQDRQ  = user.YQHTQDRQ,
                    ZCZJE     = user.ZCZJE,
                    ZQF       = user.ZQF,
                    ZS        = user.ZS,
                    ZYQL      = user.ZYQL,

                    MeterID      = meter.ID,
                    Direction    = meter.Direction,
                    Installer    = meter.Installer,
                    MeterNo      = meter.MeterNo,
                    IotPhone     = meter.IotPhone,
                    FDKH1        = meter.FDKH1,
                    InstallDate  = meter.InstallDate,
                    InstallPlace = meter.InstallPlace,
                    InstallType  = meter.InstallType,
                    MeterRange   = meter.MeterRange
                };

                WCFServiceProxy <IUserManage> proxy = new WCFServiceProxy <IUserManage>();
                Message jsonMessage = proxy.getChannel.EditUserMeter(viewInfo);
                if (!jsonMessage.Result)
                {
                    return(jsonMessage.TxtMessage);
                }
            }
            catch (Exception e)
            {
            }

            return("");
        }
コード例 #11
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
                }));
            }
        }
コード例 #12
0
        /// <summary>
        /// 编辑用户档案
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public Message EditUserMeter(View_UserMeter 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_User dbinfo = dd.GetTable <IoT_User>().Where(p => p.CompanyID == info.CompanyID && p.UserID == info.UserID).SingleOrDefault();

                //dbinfo.UserID = info.UserID;
                dbinfo.UserName  = info.UserName;
                dbinfo.Street    = info.Street;
                dbinfo.Community = info.Community;
                dbinfo.Door      = info.Door;
                dbinfo.Address   = info.Address;
                dbinfo.Phone     = info.Phone;
                dbinfo.LD        = info.LD;
                dbinfo.DY        = info.DY;
                dbinfo.BGL       = info.BGL;
                dbinfo.BWGCD     = info.BWGCD;
                dbinfo.YGBX      = info.YGBX;
                dbinfo.BXGMRQ    = info.BXGMRQ;
                dbinfo.BXGMRSFZ  = info.BXGMRSFZ;
                dbinfo.BXYXQ     = info.BXYXQ;
                dbinfo.BZCZYBH   = info.BZCZYBH;
                dbinfo.BZFY      = info.BZFY;
                dbinfo.BZRQ      = info.BZRQ;
                dbinfo.FYQHTR    = info.FYQHTR;
                dbinfo.QYQHTR    = info.QYQHTR;
                dbinfo.SFZH      = info.SFZH;
                dbinfo.SYBWG     = info.SYBWG;
                dbinfo.UserType  = info.UserType;
                dbinfo.ZS        = info.ZS;
                dbinfo.YQHTQD    = info.YQHTQD;
                dbinfo.YQHTQDRQ  = info.YQHTQDRQ;
                dbinfo.YQHTBH    = info.YQHTBH;

                IoT_Meter dbMeterinfo = dd.GetTable <IoT_Meter>().Where(p =>
                                                                        p.CompanyID == info.CompanyID && p.UserID == info.UserID).SingleOrDefault();

                if (dbMeterinfo.MeterNo.Trim() != info.MeterNo.Trim())
                {
                    UpadteMeterNo(dbMeterinfo.MeterNo, info.MeterNo);
                }
                dbMeterinfo.FDKH1        = info.FDKH1;
                dbMeterinfo.FDKH2        = info.FDKH2;
                dbMeterinfo.InstallDate  = info.InstallDate;
                dbMeterinfo.Installer    = info.Installer;
                dbMeterinfo.InstallPlace = info.InstallPlace;
                dbMeterinfo.InstallType  = info.InstallType;
                dbMeterinfo.IotPhone     = info.IotPhone;
                dbMeterinfo.MeterRange   = info.MeterRange;
                dbMeterinfo.Direction    = info.Direction;
                dbMeterinfo.MeterModel   = info.MeterModel;



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

                View_UserMeter viewInfo = dd.GetTable <View_UserMeter>().Where(p =>
                                                                               p.CompanyID == info.CompanyID && p.UserID == info.UserID).SingleOrDefault();

                m = new Message()
                {
                    Result     = true,
                    TxtMessage = JSon.TToJson <View_UserMeter>(viewInfo)
                };
            }
            catch (Exception e)
            {
                m = new Message()
                {
                    Result     = false,
                    TxtMessage = "编辑用户失败!" + e.Message
                };
            }
            return(m);
        }
コード例 #13
0
ファイル: DianHuoService.cs プロジェクト: wuyb13526487308/-
        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);
        }