예제 #1
0
        public string AddGateway(string gatewayId, string devKey, string newLockID, string userId)
        {
            if (!authentication.ValideLockUser())
            {
                return("{'headerError'}");
            }
            Dictionary <string, string> ret = new Dictionary <string, string>();

            try
            {
                NewLockManager managerNew = new NewLockManager();
                //传值校验
                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("gatewayId", gatewayId);
                dic.Add("devKey", devKey);
                dic.Add("newLockID", newLockID);
                string returnFiled = managerNew.checkIsNullFild(dic);
                if (returnFiled != string.Empty)
                {
                    ret.Add("ret", "1");
                    ret.Add("msg", "字段" + returnFiled + "不允许为空!");
                    return(JSONHelper.ToJson(ret));
                }
                //判断是否授权
                if (managerNew.GetIsEnterprise(userId) == "2")
                {
                    ret.Add("ret", "1");
                    ret.Add("msg", "我公司暂无给贵公司授权,请核对再操做!");
                    return(JSONHelper.ToJson(ret));
                }
                //判断接口是否授权
                if (!managerNew.GetIsInterfacePermissions("3", userId))
                {
                    ret.Add("ret", "1");
                    ret.Add("msg", "我公司暂无给贵公司授权该接口,请核对再操做!");
                    return(JSONHelper.ToJson(ret));
                }
                //网关查询
                string    selSql = "select * from Rent_NewLock_Process where GatewayId='" + gatewayId + "' and DevKey='" + devKey + "'and IsCreateGateway='true'";
                DataTable d1     = MySQLHelper.ExecuteDataset(MySQLHelper.SqlConnString, MySQLHelper.CreateCommand(selSql)).Tables[0];
                if (d1.Rows.Count > 0)
                {
                    ret.Add("ret", "1");
                    ret.Add("msg", "网关存在,请先解绑在绑定!");
                    return(JSONHelper.ToJson(ret));
                }
                //添加网关
                string addGatewayInfo = managerNew.createAddGateway(gatewayId, devKey, newLockID);
                Dictionary <string, object> returnInfo = new Dictionary <string, object>();
                returnInfo = JSONHelper.FromJson <Dictionary <string, object> >(addGatewayInfo);
                if (returnInfo["ret"].ToString() == "0")
                {
                    string sql = "Update Rent_NewLock_Process set GatewayId='" + gatewayId + "', DevKey='" + devKey + "', UpdatedOn='" + DateTime.Now.ToString() + "'where NewLockID='" + newLockID + "'";
                    MySQLHelper.ExecuteNonQuery(MySQLHelper.SqlConnString, MySQLHelper.CreateCommand(sql));
                    ret.Add("ret", "0");
                }
                else
                {
                    ret.Add("ret", "1");
                }
                ret.Add("msg", returnInfo["msg"].ToString());
            }
            catch (Exception ex)
            {
                ret.Add("ret", "1");
                ret.Add("msg", ex.Message);
            }
            return(JSONHelper.ToJson(ret));
        }