Ejemplo n.º 1
0
        public string CreateHomeLock(string address, string familyName, string userId, string city, string ownerName, string ownerMobile, string ownerId, string ownerAddress, string homeStatus)
        {
            if (!authentication.ValideLockUser())
            {
                return("{'headerError'}");
            }
            Dictionary <string, string> ret = new Dictionary <string, string>();

            try
            {
                NewLockManager manager = new NewLockManager();
                //传值校验
                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("address", address);
                dic.Add("familyName", familyName);
                dic.Add("userId", userId);
                dic.Add("city", city);
                dic.Add("ownerName", ownerName);
                dic.Add("ownerMobile", ownerMobile);
                dic.Add("ownerId", ownerId);
                dic.Add("ownerAddress", ownerAddress);
                dic.Add("homeStatus", homeStatus);
                string returnFiled = manager.checkIsNullFild(dic);
                if (returnFiled != string.Empty)
                {
                    ret.Add("ret", "1");
                    ret.Add("msg", "字段" + returnFiled + "不允许为空!");
                    return(JSONHelper.ToJson(ret));
                }
                if (manager.GetIsEnterprise(userId) == "2")
                {
                    ret.Add("ret", "1");
                    ret.Add("msg", "我公司暂无给贵公司授权,请核对再操做!");
                    return(JSONHelper.ToJson(ret));
                }
                //判断接口是否授权
                if (!manager.GetIsInterfacePermissions("1", userId))
                {
                    ret.Add("ret", "1");
                    ret.Add("msg", "我公司暂无给贵公司授权该接口,请核对再操做!");
                    return(JSONHelper.ToJson(ret));
                }
                if (!manager.checkidcard(ownerId)) //身份证格式校验
                {
                    ret.Add("ret", "1");
                    ret.Add("msg", "房主身份证号(ownerId)格式校验错误!");
                    return(JSONHelper.ToJson(ret));
                }
                if (!manager.IsTelephone(ownerMobile)) //手机号格式校验
                {
                    ret.Add("ret", "1");
                    ret.Add("msg", "房主手机号格式(ownerMobile)校验错误!");
                    return(JSONHelper.ToJson(ret));
                }
                if (homeStatus != "1" && homeStatus != "2")
                {
                    ret.Add("ret", "1");
                    ret.Add("msg", "homeStatus参数值超出允许范围!");
                    return(JSONHelper.ToJson(ret));
                }
                LogManager.WriteLog("Start......");
                string deviceID = Guid.NewGuid().ToString("N");
                string sql      = string.Empty;
                //请求远程创建家庭接口
                string familyReturn = manager.createHomeInfo(deviceID);
                LogManager.WriteLog("Start......" + familyReturn);
                Dictionary <string, object> returnInfo = new Dictionary <string, object>();
                returnInfo = JSONHelper.FromJson <Dictionary <string, object> >(familyReturn);
                if (returnInfo["ret"].ToString() == "0")
                {
                    string dateTime = DateTime.Now.ToString();
                    //信息记录
                    sql = "insert into Rent_NewLock_Process output inserted.NewLockId values('" + Guid.NewGuid().ToString() + "', '" + userId + "', '" + deviceID + "', '" + address + "', '','','true','','','','','" + dateTime + "','','" + familyName + "', '" + city + "')";
                    LogManager.WriteLog("SQL:" + sql);
                    DataTable dt = MySQLHelper.ExecuteDataset(MySQLHelper.SqlConnString, MySQLHelper.CreateCommand(sql)).Tables[0];
                    sql = "select * from Rent_NewLock_Process where NewLockID='" + dt.Rows[0]["NewLockID"].ToString() + "'";
                    LogManager.WriteLog("SQL:" + sql);
                    //锁房屋绑定
                    DataTable dtInfo = MySQLHelper.ExecuteDataset(MySQLHelper.SqlConnString, MySQLHelper.CreateCommand(sql)).Tables[0];
                    sql = "insert into Rent_Locks values('" + dtInfo.Rows[0]["DeviceID"].ToString() + "', 1, '0', 'NoConfiguration', '0', '" + dateTime + "', '0', '0', '" + dt.Rows[0]["NewLockID"].ToString() + "')";
                    LogManager.WriteLog("SQL:" + sql);
                    MySQLHelper.ExecuteNonQuery(MySQLHelper.SqlConnString, MySQLHelper.CreateCommand(sql));
                    //家庭信息创建
                    sql = "insert into Enterprise_Homeowner_Info values('" + Guid.NewGuid().ToString() + "', '" + ownerName + "', '" + ownerMobile + "',  '" + ownerId + "', '" + ownerAddress + "', '" + homeStatus + "', '" + userId + "', '" + dt.Rows[0]["NewLockID"].ToString() + "', '" + dateTime + "', '', '', '')";
                    LogManager.WriteLog("SQL:" + sql);
                    MySQLHelper.ExecuteNonQuery(MySQLHelper.SqlConnString, MySQLHelper.CreateCommand(sql));
                    ret.Add("ret", "0");
                    ret.Add("msg", dt.Rows[0]["NewLockID"].ToString());
                }
                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));
        }