/// <summary> /// 更新一条数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool UpdateUserShop(tbClientUserShop model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tbClientUserShop set "); strSql.Append("ShopId=@ShopId,"); strSql.Append("SessionKey=@SessionKey "); strSql.Append("where UserId=@UserId"); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@ShopId", SqlDbType.Int, 4), new SqlParameter("@SessionKey", SqlDbType.VarChar, 100) }; parameters[0].Value = model.UserId; parameters[1].Value = model.Shop.ShopId; parameters[2].Value = model.SessionKey; int rows = DBHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 查询数据 ( by ShopId) /// </summary> /// <param name="UserId"></param> /// <returns></returns> public IList <tbClientUserShop> SelectUserShopByShopId(string ShopId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select UserId,ShopId,SessionKey from tbClientUserShop "); strSql.Append(" where "); if (ShopId == null) { return(null); } strSql.Append("ShopId=@ShopId"); SqlParameter[] parameters = { new SqlParameter("@ShopId", SqlDbType.Int, 4) }; parameters[0].Value = ShopId; tbClientUserShop model = null; DataSet ds = DBHelper.ExecuteDataSet(CommandType.Text, strSql.ToString(), parameters); IList <tbClientUserShop> list = new List <tbClientUserShop>(); if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow item in ds.Tables[0].Rows) { model = new tbClientUserShop(); if (item["UserId"].ToString() != "") { model.UserId = int.Parse(item["UserId"].ToString()); } if (item["ShopId"].ToString() != "") { model.Shop = new Entity.Shop.tbShopInfo(); model.Shop.ShopId = int.Parse(item["ShopId"].ToString()); } if (item["SessionKey"] != null) { model.SessionKey = item["SessionKey"].ToString(); } list.Add(model); } return(list); } else { return(null); } }
public ViewResult Index() { // 仅做测试之用 tbClientUser User = new tbClientUser(); tbClientUserShop sh = new tbClientUserShop(); sh.SessionKey = "6201f00fhj8b68346bac1b7fae0cf20b50b30f6929dd558264760512"; sh.UserId = 15; sh.Shop = new Entity.Shop.tbShopInfo(); sh.Shop.ShopId = 20; User.UserNick = "andrinuo旗舰店"; User.UserShops = new List <tbClientUserShop>(); User.UserShops.Add(sh); User.UserId = 15; //tbClientUser User = new UserInfo().FromCodeToGetAccesToken(code); Session["UserInfo"] = User; return(View()); }
/// <summary> /// 插入一条数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public int InsertUserShop(tbClientUserShop model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tbClientUserShop("); strSql.Append("UserId,ShopId,SessionKey)"); strSql.Append(" values ("); strSql.Append("@UserId,@ShopId,@SessionKey)"); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@ShopId", SqlDbType.Int, 4), new SqlParameter("@SessionKey", SqlDbType.VarChar, 50) }; parameters[0].Value = model.UserId; parameters[1].Value = model.Shop.ShopId; parameters[2].Value = model.SessionKey; return(DBHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters)); }
/// <summary> /// 查询数据 ( by UserId) /// </summary> /// <param name="UserId"></param> /// <returns></returns> public tbClientUserShop SelectUserShopByUserId(string UserId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 UserId,ShopId,SessionKey from tbClientUserShop "); strSql.Append(" where "); if (UserId == null) { return(null); } strSql.Append("UserId=@UserId"); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.Int, 4) }; parameters[0].Value = UserId; tbClientUserShop model = new tbClientUserShop(); DataSet ds = DBHelper.ExecuteDataSet(CommandType.Text, strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["UserId"].ToString() != "") { model.UserId = int.Parse(ds.Tables[0].Rows[0]["UserId"].ToString()); } if (ds.Tables[0].Rows[0]["ShopId"].ToString() != "") { model.Shop = new Entity.Shop.tbShopInfo(); model.Shop.ShopId = int.Parse(ds.Tables[0].Rows[0]["ShopId"].ToString()); } if (ds.Tables[0].Rows[0]["SessionKey"] != null) { model.SessionKey = ds.Tables[0].Rows[0]["SessionKey"].ToString(); } return(model); } else { return(null); } }
/// <summary> /// 保存用户信息到数据库 /// </summary> /// <param name="us"></param> private tbClientUser Save(tbClientUser us, string token, string ExpiresIn) { GetShop gs = new GetShop(); using (TransactionScope scope = new TransactionScope()) { try { int shopid = 0; tbClientUser ClientUser = BClientUser.ExitisUser(us.TbUserId.ToString(), us.UserNick); if (ClientUser == null) { int ScoreId = 0; //从淘宝获取店铺信息 tbShopInfo ShopInfo = gs.GetInfoFromTb(us.UserNick, 0); if (ShopInfo.Score.ItemScore != null && ShopInfo.Score.ServiceScore != null) { //往数据库插入店铺评分表 ScoreId = BShopScore.InsertShopScore(ShopInfo.Score); } //获取返回自动生成的主键 ShopInfo.Score.ScoreId = ScoreId; //往店铺信息表中插入数据 shopid = BShopInfo.InsertShopInfo(ShopInfo); ShopInfo.ShopId = shopid; //插入用户信用表,并获取返回的ID int Creditid = BClientUserCredit.InsertUserCredit(new tbClientUserCredit { GoodNum = us.Credit.GoodNum, Level = us.Credit.Level, Score = us.Credit.Score, TotalNum = us.Credit.TotalNum }); us.UserShops = new List <tbClientUserShop>(); us.Credit.CreditId = Creditid; //插入用户信息表 int userid = BClientUser.InsertUser(us); //往用户店铺关系对应表中插入数据 BClientUserShop.InsertUserShop(new tbClientUserShop() { Shop = ShopInfo, SessionKey = token, UserId = userid }); us.UserShops.Add(new tbClientUserShop() { Shop = ShopInfo, SessionKey = token, UserId = userid }); } else { tbShopInfo shopinfo = new tbShopInfo(); tbClientUserShop usershop = BClientUserShop.SelectUserShopByUserId(ClientUser.UserId.ToString()); usershop.SessionKey = token; shopid = usershop.Shop.ShopId; shopinfo = BShopInfo.SelecttbShopInfoByShopId(shopid.ToString()); BClientUserShop.UpdateUserShop(usershop); //从淘宝获取店铺信息 tbShopInfo TBShopInfo = gs.GetInfoFromTb(us.UserNick, shopinfo.Score.ScoreId); TBShopInfo.ShopId = shopid; if (TBShopInfo.Score.ItemScore != null && TBShopInfo.Score.ServiceScore != null) { BShopScore.UpdateShopScore(new tbShopScore() { DeliveryScore = TBShopInfo.Score.DeliveryScore, ItemScore = TBShopInfo.Score.ItemScore, ServiceScore = TBShopInfo.Score.ServiceScore, ScoreId = shopinfo.Score.ScoreId }); } BShopInfo.UpdateShopInfo(TBShopInfo); us.UserId = ClientUser.UserId; BClientUserCredit.UpdateUserCredit(new tbClientUserCredit() { CreditId = ClientUser.Credit.CreditId, GoodNum = us.Credit.GoodNum, Level = us.Credit.Level, Score = us.Credit.Level, TotalNum = us.Credit.GoodNum }); us.Credit = new tbClientUserCredit(); us.Credit.CreditId = ClientUser.Credit.CreditId; BClientUser.UpdateUser(us); us.UserShops = new List <tbClientUserShop>(); us.UserShops.Add(usershop); usershop.Shop = new tbShopInfo(); usershop.Shop = shopinfo; } scope.Complete(); Hashtable ht = new Hashtable(); ht.Add("TBNick", us.UserNick); ht.Add("token", token); ht.Add("TbUserId", us.TbUserId); ht.Add("Shopid", shopid); DataCache.SetCache("UserInfo" + us.UserId, ht); } catch (Exception ex) { throw ex; } } return(us); }
public static bool UpdateUserShop(tbClientUserShop model) { return(SetUserShop.UpdateUserShop(model)); }
public static int InsertUserShop(tbClientUserShop model) { return(SetUserShop.InsertUserShop(model)); }