public int ModifyTeteShopCategory(TeteShopCategoryInfo teteshopcategory) { string sql = "update TeteShopCategory set cateid=@cateid,catename=@catename,catecount=@catecount,parentid=@parentid,nick=@nick,catepicurl=@catepicurl where id=@id"; SqlParameter[] param = CreateParameter(teteshopcategory); return(DBHelper.ExecuteNonQuery(sql, param)); }
public int AddTeteShopCategory(TeteShopCategoryInfo teteshopcategory) { string sql = "insert TeteShopCategory values(@cateid,@catename,@catecount,@parentid,@nick,@catepicurl)"; SqlParameter[] param = CreateParameter(teteshopcategory); return(DBHelper.ExecuteNonQuery(sql, param)); }
private static void InitCate(string nick, GoodsClassInfo cinfo, TeteShopCategoryInfo ainfo) { ainfo.Cateid = cinfo.cid; ainfo.Parentid = cinfo.parent_cid; ainfo.Catename = cinfo.name; ainfo.Catepicurl = cinfo.pic_url; ainfo.Nick = Encrypt(nick); }
private SqlParameter[] CreateParameter(TeteShopCategoryInfo teteshopcategory) { SqlParameter[] param = new SqlParameter[] { new SqlParameter("@id", teteshopcategory.Id), new SqlParameter("@cateid", teteshopcategory.Cateid), new SqlParameter("@catename", teteshopcategory.Catename), new SqlParameter("@catecount", teteshopcategory.Catecount), new SqlParameter("@parentid", teteshopcategory.Parentid), new SqlParameter("@nick", teteshopcategory.Nick), new SqlParameter("@catepicurl", teteshopcategory.Catepicurl) }; return(param); }
private IList <TeteShopCategoryInfo> TeteShopCategoryPropertity(string sql, params SqlParameter[] param) { DataTable dt = DBHelper.ExecuteDataTable(sql, param); IList <TeteShopCategoryInfo> list = new List <TeteShopCategoryInfo>(); foreach (DataRow dr in dt.Rows) { TeteShopCategoryInfo teteshopcategory = new TeteShopCategoryInfo(); teteshopcategory.Id = Convert.ToInt32(dr["id"]); teteshopcategory.Cateid = Convert.ToString(dr["cateid"]); teteshopcategory.Catename = Convert.ToString(dr["catename"]); teteshopcategory.Catecount = Convert.ToInt32(dr["catecount"]); teteshopcategory.Parentid = Convert.ToString(dr["parentid"]); teteshopcategory.Nick = Convert.ToString(dr["nick"]); teteshopcategory.Catepicurl = dr["catepicurl"] == DBNull.Value ? "" : Convert.ToString(dr["catepicurl"]); list.Add(teteshopcategory); } return(list); }
protected void Btn_Update_Click(object sender, EventArgs e) { string nick = HttpUtility.UrlDecode(Request.Cookies["nick"].Value); string session = Request.Cookies["nicksession"].Value; TeteShopCategoryService cateDal = new TeteShopCategoryService(); IList <TeteShopInfo> list = CacheCollection.GetNickSessionList().Where(o => o.Short == nick && o.Session == session).ToList(); TeteShopInfo info = null; if (list.Count > 0) { info = list[0]; } if (info == null) { Page.RegisterStartupScript("错误", "<script>alert('您的身份不合法,请确定您已购买!');</script>"); return; } IList <TeteShopCategoryInfo> cateList = cateDal.GetAllTeteShopCategory(Encrypt(nick)); IList <GoodsClassInfo> classList = TaoBaoAPI.GetGoodsClassInfoList(info.Short, session, info.Appkey, info.Appsecret); if (classList == null) { Page.RegisterStartupScript("错误", "<script>alert('获取店铺分类出错!');</script>"); return; } List <TeteShopCategoryInfo> addList = new List <TeteShopCategoryInfo>(); List <TeteShopCategoryInfo> upList = new List <TeteShopCategoryInfo>(); foreach (GoodsClassInfo cinfo in classList) { List <TeteShopCategoryInfo> clist = cateList.Where(o => o.Cateid == cinfo.cid).ToList(); if (clist.Count > 0) { InitCate(nick, cinfo, clist[0]); clist[0].Catecount = classList.Count(o => o.parent_cid == cinfo.cid); upList.Add(clist[0]); } else { TeteShopCategoryInfo ainfo = new TeteShopCategoryInfo(); InitCate(nick, cinfo, ainfo); ainfo.Catecount = classList.Count(o => o.parent_cid == cinfo.cid); addList.Add(ainfo); } } //添加 foreach (TeteShopCategoryInfo cinfo in addList) { cateDal.AddTeteShopCategory(cinfo); } //修改 foreach (TeteShopCategoryInfo cinfo in upList) { cateDal.ModifyTeteShopCategory(cinfo); } //删除 //List<TeteShopCategoryInfo> delList = new List<TeteShopCategoryInfo>(); //foreach (TeteShopCategoryInfo cinfo in cateList) //{ // if (upList.Where(o => o.Cateid == cinfo.Cateid).ToList().Count == 0) // { // delList.Add(cinfo); // } //} //foreach (TeteShopCategoryInfo cinfo in upList) //{ // cateDal.DeleteTeteShopCategory(cinfo.Id); //} //更新商品 ActionGoods(nick, session, info); //更新商品分类包含商品数量 IList <TeteShopCategoryInfo> nowCateList = cateDal.GetAllTeteShopCategory(Encrypt(nick)); TeteShopItemService itemDal = new TeteShopItemService(); for (int i = 0; i < nowCateList.Count; i++) { int count = itemDal.GetItemCountByCId(nowCateList[i].Cateid); nowCateList[i].Catecount = count; } //修改 foreach (TeteShopCategoryInfo cinfo in nowCateList) { cateDal.ModifyTeteShopCategory(cinfo); } Page.RegisterStartupScript("更新提示", "<script>alert('更新成功!');</script>"); }