public static ApiPagedResult<List<ProductItem>> GetProductItemList(IHtmlElement stockTable, int page = 1) { var result = new ApiPagedResult<List<ProductItem>>(); var tableEntity = new TableEntity(stockTable); if (tableEntity.TBody.TrList.Count == 1 && tableEntity.TBody.TrList[0].TrElement.InnerHtml().IndexOf("没有符合条件的结果") != -1) { result.HasMore = false; result.Data = new List<ProductItem>(); } else { var list = tableEntity.TBody.TrList.Select(x => x.GetProductItem()).ToList(); var nextUrl = stockTable.Container.Find("a.page-next"); if (nextUrl.Any()) { var pageNext = UrlHelper.GetIntValue(nextUrl.First().Attribute("href").AttributeValue, "page"); result.HasMore = pageNext > page; } else { result.HasMore = false; } result.Data = list; } tableEntity.Dispose(); return result; }
public static ApiPagedResult <List <ProductItem> > GetProductItemList(IHtmlElement stockTable, int page = 1) { var result = new ApiPagedResult <List <ProductItem> >(); var tableEntity = new TableEntity(stockTable); if (tableEntity.TBody.TrList.Count == 1 && tableEntity.TBody.TrList[0].TrElement.InnerHtml().IndexOf("没有符合条件的结果") != -1) { result.HasMore = false; result.Data = new List <ProductItem>(); } else { var list = tableEntity.TBody.TrList.Select(x => x.GetProductItem()).ToList(); var nextUrl = stockTable.Container.Find("a.page-next"); if (nextUrl.Any()) { var pageNext = UrlHelper.GetIntValue(nextUrl.First().Attribute("href").AttributeValue, "page"); result.HasMore = pageNext > page; } else { result.HasMore = false; } result.Data = list; } tableEntity.Dispose(); return(result); }
private async Task <ActionResult> SearchGroups(GroupSearchViewModel model) { if (model.SearchType == eSearchType.Group && model.GroupSearchModel.Text.IsNullOrEmpty()) { return(RedirectToSearchPage(model)); } if (model.GroupSearchModel.AutoSuggestValueAsInt.HasValue) { return(RedirectToDetailPage(model.GroupSearchModel.AutoSuggestValueAsInt.Value)); } else { model.SearchQueryString = Request.QueryString.ToString(); var text = model.GroupSearchModel.Text.Clean(); model.GroupTypes = (await _lookupService.GroupTypesGetAllAsync()).Select(x => new LookupItemViewModel(x)).ToList(); model.GroupStatuses = (await _lookupService.GroupStatusesGetAllAsync()).Select(x => new LookupItemViewModel(x)).ToList(); ApiPagedResult <SearchGroupDocument> results = null; if (text != null) { results = await _groupReadService.SearchByIdsAsync(text, text.ToInteger(), text, text.ToInteger(), User); } if (results != null && results.Count > 0) { model.Results.Add(results.Items[0]); model.Count = 1; } else { var payload = CreateSearchPayload(model); results = await _groupReadService.SearchAsync(payload, User); model.Results = results.Items; if (model.StartIndex == 0) { model.Count = results.Count; } } if (model.Count == 1) { return(RedirectToDetailPage(model.Results.Single().GroupUId)); } if (model.Count == 0) { return(RedirectToSearchPage(model)); } return(View("GroupResults", model)); } }
private async Task <Tuple <int, string> > TryGetGoupUid(ChangeHistoryViewModel model) { int?groupUid = null; var groupName = ""; if (model.GroupSearchModel.AutoSuggestValueAsInt.HasValue) { groupUid = model.GroupSearchModel.AutoSuggestValueAsInt.Value; var group = await _groupReadService.GetAsync(groupUid.Value, User); if (group.Success) { groupName = group.ReturnValue.Name; } } if (groupUid == null || string.IsNullOrWhiteSpace(groupName)) { ApiPagedResult <SearchGroupDocument> results = null; var searchText = model.GroupSearchModel.Text.Clean(); if (searchText != null) { results = await _groupReadService.SearchByIdsAsync(searchText, searchText.ToInteger(), searchText, searchText.ToInteger(), User); } if (results == null || results.Count == 0) { var payload = new GroupSearchPayload(model.Skip, model.Take) { Text = model.GroupSearchModel.Text.Clean() }; results = await _groupReadService.SearchAsync(payload, User); } if (results != null && results.Count > 0) { groupUid = results.Items.First().GroupUId; groupName = results.Items.First().Name; } else { return(null); } } return(new Tuple <int, string>(groupUid.Value, groupName)); }
private async Task<ApiPagedResult<List<TopTrade>>> DownloadTbOrderList(string state, DateTime start) { ApiPagedResult<List<TopTrade>> tradeList = new ApiPagedResult<List<TopTrade>>(true, "") { HasMore = true }; int num = 1; List<TopTrade> list = new List<TopTrade>(); while (tradeList.HasMore) { tradeList = await this.InvokeTask(client.SyncTrade, state, (long)num, start); if (!tradeList.Success) { return new ApiPagedResult<List<TopTrade>>(false, tradeList.Message); } list.AddRange(tradeList.Data); num++; } AppendText("{0} SUCCESS.({1}个)", state, list.Count); return new ApiPagedResult<List<TopTrade>>() { Data = list }; }
private async Task<bool> SyncProductList(string where, string url) { var productList = new List<ProductItem>(); int page = 1; IHtmlDocument xdoc = null; ApiPagedResult<List<ProductItem>> pagedList = new ApiPagedResult<List<ProductItem>>(); while (pagedList.Success && pagedList.HasMore) { var nextUrl = UrlHelper.SetValue(url, "page", page.ToString()); using (var helper = new WBHelper(false)) { try { var result = await this.InvokeTask(helper.SynchronousLoadDocument, nextUrl); while (result.LoginRequired) { this.InvokeAction(ShowLoginWindow, helper.WB); result = await this.InvokeTask(helper.SynchronousLoadDocument, nextUrl); } xdoc = HtmlParser.Parse(result.Data.Body.InnerHtml); var table = xdoc.GetElementById("main").FindFirst(".stock-table"); pagedList = ProductItemHelper.GetProductItemList(table, page); tbcpCrumbs = xdoc.FindSingle("#tbcpCrumbs").Attribute("value").AttributeValue; xdoc = null; result = null; SetTaskName("同步{0}商品第{1}页({2}个)", where, page, pagedList.Data.Count); productList.AddRange(pagedList.Data); page++; } catch (Exception ex) { pagedList.Success = false; helper.Dispose(); //AppendException(ex); } } if (!pagedList.Success) { AppendText("同步{0}商品第{1}页出错,{2}", where, page, pagedList.Message); if (MessageBox.Show(string.Format("同步{0}商品第{1}页出错,是否重试?", where, page), Text, MessageBoxButtons.YesNo) == DialogResult.Yes) { pagedList.Success = true; continue; } } } foreach (var item in productList) { item.UpdateAt = ProductSyncTime; item.Where = where; item.原利润 = item.利润 = item.一口价 - item.进价; } AppDatabase.UpsertProductList(productList); BindDGViewProduct(); SetTaskName("就绪"); AppendText("同步{0}商品完成!({1}个)", where, productList.Count); return true; }
/// <summary> /// 同步已卖出的交易数据 /// </summary> /// <param name="orders"></param> /// <param name="orderOpr"></param> /// <param name="status"></param> /// <param name="pageno"></param> /// <param name="daysago"></param> /// <returns></returns> public ApiPagedResult <List <TopTrade> > SyncTrade(string status, long pageno, DateTime start, Models.UserTaoOAuth taoUserOAuth) { var orderList = new List <TbOrder>(); ITopClient client = new DefaultTopClient(url_api, this.AppKey, this.AppSecret); TradesSoldGetRequest request = new TradesSoldGetRequest { Fields = "tid,buyer_nick,num_iid,created,pay_time,payment,receiver_address,status,end_time,seller_rate,seller_can_rate" }; request.StartCreated = start; request.EndCreated = DateTime.Now; request.Status = status; request.Type = "guarantee_trade"; request.PageNo = pageno; request.PageSize = 50; request.UseHasNext = true; TradesSoldGetResponse response = client.Execute <TradesSoldGetResponse>(request, taoUserOAuth.access_token); var result = new ApiPagedResult <List <TopTrade> >(!response.IsError, response.ErrMsg + " " + response.SubErrMsg); if (!response.IsError) { result.Data = response.Trades.Select(x => TopTrade.FromTrade(x)).ToList(); result.HasMore = response.HasNext; } return(result); //XmlDocument doc = new XmlDocument(); //response.Trades.First().ser //doc.LoadXml(response.Body); ////string json = JsonConvert.SerializeXmlNode(doc); //XmlNodeList xnltrades = doc.SelectNodes("//trade"); //if (xnltrades != null && xnltrades.Count > 0) //{ // foreach (XmlNode xntrade in xnltrades) // { // string jsontrade = JsonConvert.SerializeXmlNode(xntrade); // var definition = new { trade = new { buyer_nick = "", created = new DateTime(), num_iid = "", tid = 0L, pay_time = (DateTime?)null, payment = 0.00, receiver_address = "", status = "" } }; // //{"trade":{"buyer_nick":"恋上你回眸","created":"2014-09-18 01:46:15","num_iid":"35071709812","tid":"807930976731116"}} // var trade = JsonConvert.DeserializeAnonymousType(jsontrade, definition); // TbOrder order = new TbOrder() // { // Tid = trade.trade.tid, // Name = trade.trade.buyer_nick, // BuyTime = trade.trade.created, // Itemid = trade.trade.num_iid, // Payment = trade.trade.payment, // PayTime = trade.trade.pay_time, // Status = trade.trade.status, // ReceiverAddress = trade.trade.receiver_address, // trade.seller_rate // }; // orderList.Add(order); // } //} //return new ApiPagedResult<List<TbOrder>>(true, "") //{ // HasMore = response.HasNext, // Data = orderList //}; }