private void SyncEbayData_ActiveListingTab(object sender, EventArgs e) { this.buttonSyncEbayData.Enabled = false; // // For simplicity, we will delete all active listings before updating. // EbayListingDAL.DeleteAllListings(); List <AccountType> allAccounts = AccountUtil.GetAllAccounts(); foreach (AccountType account in allAccounts) { List <EbayActiveListingType> activeListings = EbaySellingBiz.GetMyActiveListing(account); if (activeListings == null) { continue; } foreach (EbayActiveListingType activeListing in activeListings) { EbayListingDAL.InsertOrUpdateOneActiveListing(activeListing); } } this.buttonSyncEbayData.Enabled = true; }
private void LoadAllAccounts() { this.listBoxAllAccounts.Items.Clear(); List <AccountType> accounts = AccountUtil.GetAllAccounts(); foreach (AccountType account in accounts) { this.listBoxAllAccounts.Items.Add(account); } }
// // User selected transactions and clicked "mark as shipped". // private void ToolStripMenuItemMarkAsShipped_Click(object sender, EventArgs e) { if (MessageBox.Show("你确认发货么?\r\n发货后,ebay会标记成已发货状态。", "确认发货?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { DataGridViewSelectedRowCollection selectedRows = this.dataGridViewAllOrders.SelectedRows; // First check if every transaction item has a related sku. foreach (DataGridViewRow row in selectedRows) { String orderLineItemId = row.Cells[OrderDgv_OrderLineItemIndex].Value.ToString(); EbayTransactionType trans = EbayTransactionDAL.GetOneTransaction(orderLineItemId); if (trans == null) { return; } if (trans.IsPaid == false) { MessageBox.Show("有些商品没有付款,不能发货!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (trans.IsShipped == true) { MessageBox.Show("有些商品已经发货,不能重新发货!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (trans.ItemSKU == null || trans.ItemSKU.Trim() == "") { MessageBox.Show("有些商品没有指定SKU!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } List <String> handledOrderIds = new List <String>(); foreach (DataGridViewRow row in selectedRows) { String orderLineItemId = row.Cells[OrderDgv_OrderLineItemIndex].Value.ToString(); EbayTransactionType trans = EbayTransactionDAL.GetOneTransaction(orderLineItemId); if (trans == null) { return; } if (trans.IsPaid == false || trans.IsShipped == true) { MessageBox.Show("商品未付款或者已经发货!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error); continue; } String orderId = trans.OrderId; if (handledOrderIds.Contains(orderId)) { continue; } AccountType account = null; List <AccountType> allAccounts = AccountUtil.GetAllAccounts(); foreach (AccountType accountType in allAccounts) { if (accountType.ebayAccount == trans.SellerName) { account = accountType; break; } } if (account == null || account.SellerApiContext == null) { MessageBox.Show("账号没有初始化!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } EbayTransactionBiz.CompleteSale(account, trans.OrderId, trans.BuyerId, trans.ItemId, trans.EbayTransactionId, false, true, true, true /*isShipped*/); handledOrderIds.Add(orderId); StringCollection orderIds = new StringCollection(); orderIds.Add(trans.OrderId); TimeFilter timeFilter = new TimeFilter(); timeFilter.TimeFrom = this.dateTimePickerStartTime.Value; timeFilter.TimeTo = this.dateTimePickerEndTime.Value; List <EbayTransactionType> transList = EbayTransactionBiz.GetAllOrders(account, timeFilter, orderIds); if (transList.Count != 1) { MessageBox.Show("交易在ebay系统中不存在!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error); continue; } if (transList[0].IsShipped == false) { MessageBox.Show(string.Format("该交易没有在ebay系统中标记成功! 用户id={0}", trans.BuyerId), "失败", MessageBoxButtons.OK, MessageBoxIcon.Error); continue; } // ZHI_TODO //ItemDAL.ShipItem(trans.ItemSKU, trans.SaleQuantity); // Update transaction shipped date. EbayTransactionDAL.UpdateTransactionShippedStatus(trans.TransactionId, true /*shipped*/, transList[0].ShippedDate); Logger.WriteSystemUserLog(string.Format("标记交易已发货成功: userId={0}, 商品名={1}", trans.BuyerId, trans.ItemTitle)); row.DefaultCellStyle.BackColor = ColorTranslator.FromHtml("#90EE90"); } MessageBox.Show("标记成发货成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
} // GetOrdersAsync // Get messages from ebay async. // Returns number of new messages retrieved. private int GetMessagesAsync(DateTime startDate, DateTime endDate, out bool canceled) { canceled = false; int messagesFetched = 0; List <AccountType> allAccounts = AccountUtil.GetAllAccounts(); foreach (AccountType account in allAccounts) { StringCollection messageIds = EbayMessageBiz.GetAllMessageIds(account, startDate, endDate); StringCollection newMessageIds = new StringCollection(); foreach (String messageId in messageIds) { EbayMessageType messageType = EbayMessageDAL.GetOneMessage(messageId); if (messageType == null) { newMessageIds.Add(messageId); } } int messageNumRetrievePerTime = 1; int apiCallTimes = newMessageIds.Count / messageNumRetrievePerTime; bool needExtraCall = (newMessageIds.Count % messageNumRetrievePerTime) != 0; if (needExtraCall) { apiCallTimes += 1; } List <EbayMessageType> allTrans = new List <EbayMessageType>(); for (int ii = 0; ii < apiCallTimes; ++ii) { StringCollection messageIdsLoc = new StringCollection(); for (int jj = ii * messageNumRetrievePerTime; jj < ii * messageNumRetrievePerTime + messageNumRetrievePerTime; ++jj) { if (jj > newMessageIds.Count - 1) { break; } messageIdsLoc.Add(newMessageIds[jj]); } TimeFilter timeFilter = new TimeFilter(); timeFilter.TimeFrom = startDate; timeFilter.TimeTo = endDate; // Update the description and progress on the modal form // using Control.Invoke. Invoke will run the anonymous // function to set the label's text on the UI thread. // Since it's illegal to touch the UI control on the worker // thread that we're on right now. int retrievedCount = (ii + 1) * messageNumRetrievePerTime; if (retrievedCount > newMessageIds.Count) { retrievedCount = newMessageIds.Count; } List <EbayMessageType> messageList = EbayMessageBiz.GetAllMessageByIds(account, messageIdsLoc); foreach (EbayMessageType messageType in messageList) { // We are pretty sure the message didn't exist. EbayMessageDAL.InsertOneMessage(messageType); // Update the transaction message status. String recipientUserId = messageType.RecipientUserId; String sender = messageType.Sender; String sellerName = messageType.SellerName; String buyerId = sellerName == sender ? recipientUserId : sender; TransactionMessageStatus messageStatus = EbayMessageDAL.GetTransactionMessageStatus(buyerId, sellerName, messageType.ItemID); List <EbayTransactionType> transList = EbayTransactionDAL.GetTransactionsBySellerBuyerItem(sellerName, buyerId, messageType.ItemID); foreach (EbayTransactionType trans in transList) { EbayTransactionDAL.UpdateTransactionMessageStatus(trans.TransactionId, messageStatus); } } String labelHintStr = string.Format("正在从Ebay获取消息信息, 账号 {0}, 共{1}个新消息, 已获得{2}个消息", account.ebayAccount, newMessageIds.Count, retrievedCount); int progressBarValue = (int)((double)(ii + 1) / apiCallTimes * 100); frmProgress.SetLabelHintAndProgressBarValue(labelHintStr, progressBarValue); // Periodically check for a Cancellation // If the user clicks the cancel button, or tries to close // the progress form the m_fmProgress.Cancel flag will be set to true. if (frmProgress.Cancel) { canceled = true; return(messagesFetched); } } // for (int ii = 0; ii < apiCallTimes; ++ii) messagesFetched += newMessageIds.Count; } // foreach (AccountType account in AllAccounts) canceled = false; return(messagesFetched); } // GetMessagesAsync
// Get the orders asynchronously. // Returns number of orders updated. private int GetOrdersAsync(DateTime startDate, DateTime endDate, out bool canceled) { canceled = false; int ordersFetched = 0; List <AccountType> allAccounts = AccountUtil.GetAllAccounts(); foreach (AccountType account in allAccounts) { StringCollection orderIds = EbayTransactionBiz.GetAllOrderIds(account, startDate, endDate); StringCollection newOrderIds = new StringCollection(); foreach (String orderId in orderIds) { newOrderIds.Add(orderId); } int orderNumRetrievePerTime = 1; int apiCallTimes = newOrderIds.Count / orderNumRetrievePerTime; bool needExtraCall = (newOrderIds.Count % orderNumRetrievePerTime) != 0; if (needExtraCall) { apiCallTimes += 1; } List <EbayTransactionType> allTrans = new List <EbayTransactionType>(); for (int ii = 0; ii < apiCallTimes; ++ii) { StringCollection orderIdsLoc = new StringCollection(); for (int jj = ii * orderNumRetrievePerTime; jj < ii * orderNumRetrievePerTime + orderNumRetrievePerTime; ++jj) { if (jj > newOrderIds.Count - 1) { break; } orderIdsLoc.Add(newOrderIds[jj]); } TimeFilter timeFilter = new TimeFilter(); timeFilter.TimeFrom = startDate; timeFilter.TimeTo = endDate; List <EbayTransactionType> transList = EbayTransactionBiz.GetAllOrders(account, timeFilter, orderIdsLoc); foreach (EbayTransactionType trans in transList) { allTrans.Add(trans); } // Update the description and progress on the modal form // using Control.Invoke. Invoke will run the anonymous // function to set the label's text on the UI thread. // Since it's illegal to touch the UI control on the worker // thread that we're on right now. int retrievedCount = (ii + 1) * orderNumRetrievePerTime; if (retrievedCount > newOrderIds.Count) { retrievedCount = newOrderIds.Count; } String labelHintStr = string.Format("正在从Ebay获取交易信息, 账号 {0}, 共{1}个订单, 已获得{2}个订单信息", account.ebayAccount, newOrderIds.Count, retrievedCount); int progressBarValue = (int)((double)(ii + 1) / apiCallTimes * 100); frmProgress.SetLabelHintAndProgressBarValue(labelHintStr, progressBarValue); foreach (EbayTransactionType trans in allTrans) { bool result = EbayTransactionDAL.InsertOrUpdateOneTransaction(trans); if (result == false) { canceled = true; return(ordersFetched); } } // Periodically check for a Cancellation // If the user clicks the cancel button, or tries to close // the progress form the m_fmProgress.Cancel flag will be set to true. if (frmProgress.Cancel) { canceled = true; return(ordersFetched); } } // for (int ii = 0; ii < apiCallTimes; ++ii) ordersFetched += newOrderIds.Count; } // foreach (AccountType account in AllAccounts) canceled = false; return(ordersFetched); } // GetOrdersAsync