예제 #1
0
        public UserRsp GetUserRsp()
        {
            var result = new UserRsp();

            result.Id   = 1;
            result.Name = "peigen";
            return(new UserRsp(new MethodResultFull <UserRsp>(ModuleCodeEnum.Core_Area, 1)));
            //return result;
        }
예제 #2
0
        /// <summary>
        /// 点击更新店铺
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barBtnDownload_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            WaitDialogForm waitFrm = null;

            try
            {
                Alading.Entity.Shop focusShop = gridViewShop.GetFocusedRow() as Alading.Entity.Shop;
                if (focusShop == null)//未选中
                {
                    XtraMessageBox.Show("请先选中更新的店铺", Constants.SYSTEM_PROMPT, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                waitFrm = new WaitDialogForm(Constants.WAIT_LOAD_DATA);
                ShopRsp shopRsp = TopService.ShopGet(focusShop.nick);
                string  session = SystemHelper.GetSessionKey(focusShop.nick);
                UserRsp userRsp = TopService.UserGet(session, focusShop.nick, string.Empty);

                Alading.Entity.Shop shop = new Alading.Entity.Shop();

                if (shopRsp == null || userRsp == null)//从淘宝网未获取到数据
                {
                    waitFrm.Close();
                    XtraMessageBox.Show("未获取到数据", Constants.SYSTEM_PROMPT, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                ShopCopyData((int)shopShowType, shop, shopRsp.Shop, userRsp.User);

                Alading.Entity.Shop oldShop = ShopService.GetShopByNick(shop.nick);

                if (oldShop == null)//不存在时添加
                {
                    ShopService.AddShop(shop);
                }
                else//存在时更新
                {
                    ShopService.UpdateShop(shop);
                }

                LoadShop(shopShowType);//重新刷新界面
                waitFrm.Close();
                XtraMessageBox.Show("更新成功", Constants.SYSTEM_PROMPT, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                waitFrm.Close();
                XtraMessageBox.Show(ex.Message, Constants.SYSTEM_PROMPT, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
예제 #3
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            List <string>    nicklist = (List <string>)e.Argument;
            int              n        = nicklist.Count;
            int              temp     = 0;//作用是避免进度值propgress没有改变时得重复报告
            BackgroundWorker worker   = (BackgroundWorker)sender;

            for (int i = 0; i < n; i++)
            {
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }

                try
                {
                    string  session = SystemHelper.GetSessionKey(nicklist[i]);
                    ShopRsp shopRsp = TopService.ShopGet(nicklist[i]);
                    UserRsp userRsp = TopService.UserGet(session, nicklist[i], string.Empty);
                    if (shopRsp != null || userRsp != null)
                    {
                        Alading.Entity.Shop shop = new Alading.Entity.Shop();
                        UIHelper.ShopCopyData(shop, shopRsp.Shop, userRsp.User);
                        ShopService.UpdateShop(shop);
                    }

                    //进度报告
                    int propgress = (int)((float)(i + 1) / n * 100);
                    if (propgress > temp)
                    {
                        MyInfo myInfo = new MyInfo();
                        myInfo.nick      = nicklist[i];
                        myInfo.isSucceed = true;
                        worker.ReportProgress(propgress, myInfo);
                    }
                    temp = propgress;
                }
                catch (System.Exception ex)
                {
                    MyInfo myInfo = new MyInfo();
                    myInfo.nick      = nicklist[i];
                    myInfo.isSucceed = false;
                    myInfo.msg       = ex.Message;
                    worker.ReportProgress(0, myInfo);
                }
            }
        }
예제 #4
0
        void w_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            SycTaskArgs      task   = e.Argument as SycTaskArgs;

            foreach (var p in task.PageNoList)
            {
                #region get trade information
                //这里改成mainWorker,即主线程取消子线程工作全部停止
                if (mainWorker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                TradeReq request  = new TradeReq();
                TradeRsp response = null;
                request.Status       = null;
                request.PageSize     = task.PageSize;
                request.PageNo       = p;
                request.StartCreated = task.QueryBeginTime.ToString("yyyy-MM-dd HH:mm:ss");
                request.EndCreated   = task.QueryEndTime.ToString("yyyy-MM-dd HH:mm:ss");
                string sessionkey = SystemHelper.GetSessionKey(task.ShopNick);
                response = TopService.TradesSoldGet(sessionkey, request);

                #endregion

                #region if getting trade failed do next

                if (response == null || response.Trades == null)
                {
                    lock (vlock)
                    {
                        sub_done += task.PageSize;
                    }
                    continue;
                }

                #endregion

                foreach (var t in response.Trades.Trade)
                {
                    //if (worker.CancellationPending)
                    //这里改成mainWorker,即主线程取消子线程工作全部停止
                    if (mainWorker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    lock (vlock)
                    {
                        sub_done++;
                    }

                    TradeRsp fulltrade = TopService.TradeFullinfoGet(sessionkey, t.Tid);

                    #region if getting trade detail failed do next

                    if (fulltrade == null || fulltrade.Trade == null)
                    {
                        ReportState state = new ReportState
                        {
                            Total   = sub_total,
                            Current = sub_done,
                            Message = string.Format("同步客户 {0} 失败:无法获取交易信息!", t.BuyerNick),
                        };
                        worker.ReportProgress(0, state);
                        continue;
                    }

                    #endregion

                    UserRsp buyer = TopService.UserGet(sessionkey, fulltrade.Trade.BuyerNick, fulltrade.Trade.AlipayNo);

                    #region if getting buyer detail failed do next

                    if (buyer == null || buyer.User == null)
                    {
                        ReportState state = new ReportState
                        {
                            Total   = sub_total,
                            Current = sub_done,
                            Message = string.Format("同步客户 {0} 失败:无法获取买家信息!", t.BuyerNick),
                        };
                        worker.ReportProgress(0, state);
                        continue;
                    }

                    #endregion

                    Alading.Entity.Consumer consumer = Alading.Business.ConsumerService.GetConsumer(fulltrade.Trade.BuyerNick);

                    if (consumer == null)
                    {
                        #region Consumer is not existed and save it

                        consumer = new Alading.Entity.Consumer();

                        consumer.nick              = buyer.User.Nick;
                        consumer.sex               = buyer.User.Sex;
                        consumer.buyer_zip         = buyer.User.Location.Zip;
                        consumer.location_city     = buyer.User.Location.City;
                        consumer.location_state    = buyer.User.Location.State;
                        consumer.location_district = buyer.User.Location.District;
                        consumer.location_address  = buyer.User.Location.Address;
                        consumer.location_country  = buyer.User.Location.Address;
                        consumer.birthday          = buyer.User.Birthday;
                        consumer.credit            = buyer.User.BuyerCredit.ToString();
                        consumer.level             = buyer.User.BuyerCredit.Level;
                        consumer.score             = buyer.User.BuyerCredit.Score;
                        consumer.status            = buyer.User.Status;
                        consumer.created           = DateTime.Parse(buyer.User.Created);
                        consumer.last_visit        = buyer.User.LastVisit;
                        consumer.mobilephone       = fulltrade.Trade.ReceiverMobile;
                        consumer.phone             = fulltrade.Trade.ReceiverPhone;
                        consumer.email             = fulltrade.Trade.BuyerEmail;
                        consumer.buyer_name        = fulltrade.Trade.ReceiverName;
                        consumer.alipay            = fulltrade.Trade.AlipayNo;

                        ReturnType result = Alading.Business.ConsumerService.AddConsumer(consumer);

                        if (result == ReturnType.Success)
                        {
                            ReportState state = new ReportState
                            {
                                Total   = sub_total,
                                Current = sub_done,
                                Message = string.Format("同步客户 {0} 信息成功!", consumer.nick),
                            };
                            worker.ReportProgress(1, state);

                            Alading.Entity.ConsumerAddress addr = Alading.Business.ConsumerAddressService.GetConsumerAddress(
                                c => c.tid == fulltrade.Trade.Tid).FirstOrDefault();

                            if (addr == null)
                            {
                                addr = new Alading.Entity.ConsumerAddress
                                {
                                    buyer_nick        = fulltrade.Trade.BuyerNick,
                                    location_address  = fulltrade.Trade.ReceiverAddress,
                                    location_city     = fulltrade.Trade.ReceiverCity,
                                    location_country  = buyer.User.Location.Country,
                                    location_district = fulltrade.Trade.ReceiverDistrict,
                                    location_state    = fulltrade.Trade.ReceiverState,
                                    location_zip      = fulltrade.Trade.ReceiverZip,
                                    receiver_mobile   = fulltrade.Trade.ReceiverMobile,
                                    receiver_name     = fulltrade.Trade.ReceiverName,
                                    receiver_phone    = fulltrade.Trade.ReceiverPhone,
                                    receiver_zip      = fulltrade.Trade.ReceiverZip,
                                    tid = fulltrade.Trade.Tid,
                                };

                                result = Alading.Business.ConsumerAddressService.AddConsumerAddress(addr);

                                if (result == ReturnType.Success)
                                {
                                    state = new ReportState
                                    {
                                        Total   = sub_total,
                                        Current = sub_done,
                                        Message = string.Format("同步客户 {0} 地址信息成功!", consumer.nick),
                                    };
                                    worker.ReportProgress(1, state);
                                }
                                else
                                {
                                    state = new ReportState
                                    {
                                        Total   = sub_total,
                                        Current = sub_done,
                                        Message = string.Format("同步客户 {0} 地址信息失败:数据保存失败!", consumer.nick),
                                    };
                                    worker.ReportProgress(1, state);
                                }
                            }
                        }
                        else
                        {
                            ReportState state = new ReportState
                            {
                                Total   = sub_total,
                                Current = sub_done,
                                Message = string.Format("同步客户 {0} 信息失败:数据保存失败!", consumer.nick),
                            };
                            worker.ReportProgress(1, state);
                            continue;
                        }
                        #endregion
                    }
                    else
                    {
                        #region Consumer existed and update address information

                        ReportState state0 = new ReportState
                        {
                            Total   = sub_total,
                            Current = sub_done,
                            Message = string.Format("客户 {0} 已存在!", consumer.nick),
                        };
                        worker.ReportProgress(0, state0);

                        Alading.Entity.ConsumerAddress addr = Alading.Business.ConsumerAddressService.GetConsumerAddress(
                            c => c.tid == fulltrade.Trade.Tid).FirstOrDefault();

                        if (addr == null)
                        {
                            addr = new Alading.Entity.ConsumerAddress
                            {
                                buyer_nick        = fulltrade.Trade.BuyerNick,
                                location_address  = fulltrade.Trade.ReceiverAddress,
                                location_city     = fulltrade.Trade.ReceiverCity,
                                location_country  = buyer.User.Location.Country,
                                location_district = fulltrade.Trade.ReceiverDistrict,
                                location_state    = fulltrade.Trade.ReceiverState,
                                location_zip      = fulltrade.Trade.ReceiverZip,
                                receiver_mobile   = fulltrade.Trade.ReceiverMobile,
                                receiver_name     = fulltrade.Trade.ReceiverName,
                                receiver_phone    = fulltrade.Trade.ReceiverPhone,
                                receiver_zip      = fulltrade.Trade.ReceiverZip,
                                tid = fulltrade.Trade.Tid,
                            };

                            ReturnType result = Alading.Business.ConsumerAddressService.AddConsumerAddress(addr);

                            if (result == ReturnType.Success)
                            {
                                ReportState state = new ReportState
                                {
                                    Total   = sub_total,
                                    Current = sub_done,
                                    Message = string.Format("同步客户 {0} 地址信息成功!", consumer.nick),
                                };
                                worker.ReportProgress(1, state);
                            }
                            else
                            {
                                ReportState state = new ReportState
                                {
                                    Total   = sub_total,
                                    Current = sub_done,
                                    Message = string.Format("同步客户 {0} 地址信息失败:数据保存失败!", consumer.nick),
                                };
                                worker.ReportProgress(1, state);
                            }
                        }

                        #endregion
                    }
                }
            }
        }