コード例 #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["visitip"]))
            {
                DateTime[] darray = DataHelper.GetDateTime(DateTime.Now, 1);
                try
                {
                    string start = HttpUtility.UrlDecode(Request.QueryString["start"]);
                    string end   = HttpUtility.UrlDecode(Request.QueryString["end"]);
                    darray[0] = DateTime.Parse(start.Substring(0, start.LastIndexOf('-')) + " " + start.Substring(start.LastIndexOf('-') + 1, 2) + ":0:0");
                    darray[1] = DateTime.Parse(end.Substring(0, end.LastIndexOf('-')) + " " + end.Substring(end.LastIndexOf('-') + 1, 2) + ":0:0");
                }
                catch
                {
                }

                string nick    = HttpUtility.UrlDecode(Request.Cookies["nick"].Value);
                string session = Request.Cookies["nicksession"].Value;
                if (ViewState["GoodsClassList"] == null)
                {
                    GoodsClassList = TaoBaoAPI.GetGoodsClassInfoList(nick, Request.Cookies["nicksession"].Value);
                }
                Bind(nick, session, darray[0], darray[1]);
            }
        }
    }
コード例 #2
0
    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>");
    }