示例#1
0
        /// <summary>
        /// 批量更新选品库到数据库中
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void updateAllFavorites_Click(object sender, EventArgs e)
        {
            Tools.Base.ProgressBar pb = new Tools.Base.ProgressBar(this);
            IList <Entity.Taobao.Tbk.Favorites> list = new List <Entity.Taobao.Tbk.Favorites>();

            string favorites_title = "开始更新选品库......";

            for (int i = 0; i < DataGrid1.Items.Count; i++)
            {
                CheckBox chk = (CheckBox)DataGrid1.Items[i].FindControl("chkSelect");
                if (chk.Checked == true)
                {
                    Entity.Taobao.Tbk.Favorites favorites = new Entity.Taobao.Tbk.Favorites();
                    favorites.CId            = ((Entity.Owner.Consumer) this.Session["Consumer"]).CId;
                    favorites.FavoritesId    = long.Parse(DataGrid1.Items[i].Cells[0].Text);;
                    favorites.FavoritesTitle = DataGrid1.Items[i].Cells[1].Text;;
                    favorites.Type           = long.Parse(DataGrid1.Items[i].Cells[2].Text);
                    favorites.TotalResults   = 200;
                    list.Add(favorites);
                }
            }

            pb.SetMaxValue(list.Count);
            pb.InitProgress();
            pb.SetTitle("开始更新选品库.......");
            pb.SetHeader(favorites_title);

            //IsTotalResultsNumber(pb, tfvo, list);
            for (int i = 0; i < list.Count; i++)
            {
                long favorites_id = list[i].FavoritesId;  //获取对应的选品库id
                favorites_title = list[i].FavoritesTitle; //获取对应的选品组名称

                pb.AddProgress(1);
                //此处用线程休眠代替实际的操作,如加载数据等
                System.Threading.Thread.Sleep(int.Parse(ConfigurationManager.AppSettings["ProgressBarSleep"].ToString()));
                //IsUpdateOrInsertFavorites(favorites_id, favorites, i, list);
                Entity.Taobao.Tbk.Favorites favorites = FactoryBo.Taobao.Tbk.FavoritesFactoryBo.GetObject("FavoritesBoFactory")
                                                        .FavoritesBo.GetById(favorites_id);
                if (favorites == null)
                {
                    FactoryBo.Taobao.Tbk.FavoritesFactoryBo.GetObject("FavoritesBoFactory")
                    .FavoritesBo.Insert(list[i]);
                }
                else
                {
                    list[i].FId = favorites.FId;
                    FactoryBo.Taobao.Tbk.FavoritesFactoryBo.GetObject("FavoritesBoFactory")
                    .FavoritesBo.Update(list[i]);
                }

                pb.SetTitle("数据加载中......" + (i + 1) + "/" + list.Count);
                pb.SetHeader("开始更新选品库.......【" + favorites_title + "】");
            }

            pb.DisponseProgress();
        }
示例#2
0
        protected void updateAllFavoritesItems_Click(object sender, EventArgs e)
        {
            Tools.Base.ProgressBar pb = new Tools.Base.ProgressBar(this);// 新建线程
            IList <Entity.Taobao.Tbk.Favorites> listFavorites = new List <Entity.Taobao.Tbk.Favorites>();
            IList <FavoriteItem> listFavoriteItem             = new List <FavoriteItem>();

            consumer = (Entity.Owner.Consumer) this.Session["Consumer"];

            //被选中的 选品库集合
            for (int i = 0; i < DataGrid1.Items.Count; i++)
            {
                CheckBox chk = (CheckBox)DataGrid1.Items[i].FindControl("chkSelect");
                if (chk.Checked == true)
                {
                    //list.Add(GetTaobaokeFavoritesCheckBoxSelectList(tfvo, i, dg));
                    Entity.Taobao.Tbk.Favorites favorites = new Entity.Taobao.Tbk.Favorites();
                    favorites.CId            = ((Entity.Owner.Consumer) this.Session["Consumer"]).CId;
                    favorites.FavoritesId    = long.Parse(DataGrid1.Items[i].Cells[0].Text);;
                    favorites.FavoritesTitle = DataGrid1.Items[i].Cells[1].Text;;
                    favorites.Type           = long.Parse(DataGrid1.Items[i].Cells[2].Text);
                    favorites.TotalResults   = 200;
                    listFavorites.Add(favorites);
                }
            }

            if (listFavorites.Count > 0)
            {
                pb.InitProgress();
                pb.SetTitle("开始更新选品库.......");

                //获取选品库List 集合
                for (int i = 0; i < listFavorites.Count; i++)
                {//循环遍历选中项
                    pb.SetHeader("开始更新选品库......." + listFavorites[i].FavoritesTitle);
                    listFavoriteItem = FactoryBo.Taobao.Tbk.FactoryBo.GetObject("FavoriteItemBoFactory")
                                       .FavoriteItemBo.GetIList(listFavorites, i, 1, 100, 42120264,
                                                                FactoryBo.Taobao.Tbk.DiplomaFactoryBo.GetObject("DiplomaBoFactory").DiplomaBo.GetById(consumer.CId));

                    pb.SetMaxValue(listFavoriteItem.Count);
                    pb.SetThisValue(0);
                    System.Threading.Thread.Sleep(int.Parse(ConfigurationManager.AppSettings["ProgressBarSleep"].ToString()));
                    //IsTotalResultsNumber(pb, list[i].FavoritesId, rsp);

                    for (int row = 0; row < listFavoriteItem.Count; row++)
                    {
                        pb.AddProgress(1);
                        System.Threading.Thread.Sleep(int.Parse(ConfigurationManager.AppSettings["ProgressBarSleep"].ToString()));
                        FavoriteItem favoriteItem = new FavoriteItem();
                        //判断数据库中是否存在该产品 如果存在就进行更新操作
                        if (FactoryBo.Taobao.Tbk.FactoryBo.GetObject("FavoriteItemBoFactory")
                            .FavoriteItemBo.GetByNumIid(listFavoriteItem[row].NumIid) != null)
                        {
                            //主键赋值
                            listFavoriteItem[row].IId = FactoryBo.Taobao.Tbk.FactoryBo.GetObject("FavoriteItemBoFactory")
                                                        .FavoriteItemBo.GetByNumIid(listFavoriteItem[row].NumIid).IId;
                            //淘口令生成
                            listFavoriteItem[row].Model = (new Tools.Taobao.Tbk.RequestApi())
                                                          .TpwdCreate(listFavoriteItem[row],
                                                                      FactoryBo.Taobao.Tbk.DiplomaFactoryBo.GetObject("DiplomaBoFactory").DiplomaBo.GetById(consumer.CId));

                            FactoryBo.Taobao.Tbk.FactoryBo.GetObject("FavoriteItemBoFactory")
                            .FavoriteItemBo.Update(listFavoriteItem[row]);
                        }
                        else
                        {//如果不存在就进行插入操作
                            FactoryBo.Taobao.Tbk.FactoryBo.GetObject("FavoriteItemBoFactory")
                            .FavoriteItemBo.Insert(listFavoriteItem[row]);
                        }
                        pb.SetTitle("数据加载中......" + (row + 1) + "/" + listFavoriteItem.Count);
                    }
                }
                pb.DisponseProgress();
            }
        }