示例#1
0
        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;
        }
示例#2
0
        private void ToolStripMenuItemViewMessage_Click(object sender, EventArgs e)
        {
            int    rowIdx          = this.dataGridViewPostSale.CurrentRow.Index;
            String orderLineItemId = this.dataGridViewPostSale.Rows[rowIdx].Cells[PostSaleDgv_OrderLineItemIdIdx].Value.ToString();

            EbayTransactionType trans = EbayTransactionDAL.GetOneTransaction(orderLineItemId);

            if (trans == null)
            {
                return;
            }

            AccountType account = AccountUtil.GetAccount(trans.SellerName);

            if (account == null)
            {
                MessageBox.Show(String.Format("此账号{0}未绑定到系统", trans.SellerName),
                                "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            FrmUserMessage frmUserMessage = new FrmUserMessage();

            frmUserMessage.EbayTransaction = trans;
            frmUserMessage.Account         = account;
            frmUserMessage.ShowDialog();

            if (frmUserMessage.SentMessage || frmUserMessage.MarkMsgAsReplied)
            {
                LoadPostSaleData();
            }
        }
示例#3
0
        // Upload tracking number to ebay.
        // While uploading tracking number, ebay requires two fields:
        //  - tracking number
        //  - carrier
        // Use Ebay API CompleteSale to fulfill this task, see page:
        // https://developer.ebay.com/DevZone/XML/docs/Reference/ebay/CompleteSale.html
        private void ToolStripMenuItemUploadTrackingNum_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection selectedRows = this.dataGridViewAllOrders.SelectedRows;

            if (selectedRows.Count != 1)
            {
                return;
            }

            String orderLineItemId    = selectedRows[0].Cells[OrderDgv_OrderLineItemIndex].Value.ToString();
            EbayTransactionType trans = EbayTransactionDAL.GetOneTransaction(orderLineItemId);

            if (trans == null)
            {
                return;
            }

            if (trans.ShippingTrackingNo != "")
            {
                MessageBox.Show("该订单已经上传跟踪号", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            FrmUploadTrackingNumber frmUploadTrackingNumber = new FrmUploadTrackingNumber();

            frmUploadTrackingNumber.account   = AccountUtil.GetAccount(trans.SellerName);
            frmUploadTrackingNumber.ebayTrans = trans;
            frmUploadTrackingNumber.Show();

            trans = EbayTransactionDAL.GetOneTransaction(orderLineItemId);
            selectedRows[0].Cells[OrderDgv_TrackingNoIndex].Value = trans.ShippingTrackingNo;
        }
示例#4
0
        private void ToolStripMenuItemLeaveFeedback_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection selectedRows = this.dataGridViewAllOrders.SelectedRows;

            foreach (DataGridViewRow row in selectedRows)
            {
                String orderLineItemId    = row.Cells[OrderDgv_OrderLineItemIndex].Value.ToString();
                EbayTransactionType trans = EbayTransactionDAL.GetOneTransaction(orderLineItemId);
                if (trans == null)
                {
                    continue;
                }

                AccountType account = AccountUtil.GetAccount(trans.SellerName);
                if (account == null)
                {
                    continue;
                }

                EbayTransactionBiz.LeaveFeedback(account, trans.OrderId, trans.BuyerId, trans.ItemId, trans.EbayTransactionId);

                EbayTransactionDAL.UpdateTransactionSellerLeftFeedback(trans.TransactionId, true);

                row.Cells[OrderDgv_SellerLeftFeedbackIndex].Value = 1;
            }

            MessageBox.Show("留好评成功", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
示例#5
0
        private void btnAddOrUpdateAccount_Click(object sender, EventArgs e)
        {
            string ebayAccount = this.textBoxEbayAccount.Text;

            if (ebayAccount.Trim() == "")
            {
                MessageBox.Show("请输入Ebay账号", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string ebayToken = this.textBoxEbayToken.Text;

            if (ebayToken.Trim() == "")
            {
                MessageBox.Show("请输入Ebay Token", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            AccountType account = new AccountType();

            account.ebayAccount     = ebayAccount;
            account.ebayToken       = ebayToken;
            account.paypalAccount   = this.textBoxPayPalAccount.Text.Trim();
            account.paypalUsername  = this.textBoxPayPalUsername.Text.Trim();
            account.paypalPassword  = this.textBoxPayPalPassword.Text.Trim();
            account.paypalSignature = this.textBoxPayPalSignature.Text.Trim();

            bool update = false;

            AccountType existedAccount = AccountUtil.GetAccountByEbayUsername(ebayAccount);

            if (existedAccount != null)
            {
                if (existedAccount.isEqual(account))
                {
                    MessageBox.Show("无任何信息需要更新!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                update = true;
            }

            if (update)
            {
                AccountUtil.UpdateOneAccount(account);
                MessageBox.Show("更新账号信息成功!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                AccountUtil.AddOneAccount(account);
                this.listBoxAllAccounts.Items.Add(account);

                MessageBox.Show("添加账号信息成功!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
示例#6
0
        private void LoadAllAccounts()
        {
            this.listBoxAllAccounts.Items.Clear();

            List <AccountType> accounts = AccountUtil.GetAllAccounts();

            foreach (AccountType account in accounts)
            {
                this.listBoxAllAccounts.Items.Add(account);
            }
        }
        private void buttonFinish_Click(object sender, EventArgs e)
        {
            AccountType account = new AccountType();

            account.ebayAccount = UserName;
            account.ebayToken   = Token;

            AccountType existedAccount = AccountUtil.GetAccountByEbayUsername(UserName);

            if (existedAccount != null)
            {
                MessageBox.Show("已存在此账号token,需先删除已有账号!", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            AccountUtil.AddOneAccount(account);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
示例#8
0
        private void FrmMain_Load(object sender, EventArgs e)
        {
            // Maximize the main window.
            this.WindowState = FormWindowState.Maximized;

            // Adjust the tab page size to accomodate to the screen.
            // [ZHI_TODO]
            Size frmSize = this.Size;

            // Set the default startDate/endDate.
            TimeSpan timeSpan     = new TimeSpan(5, 0, 0, 0);
            DateTime prevThreeDay = DateTime.Now.Subtract(timeSpan);

            this.dateTimePickerStartTime.Value = prevThreeDay;

            // Initialize all account info.
            AccountUtil.ReloadAllAccounts();

            // Setup all the datagridview columns:
            //  - Active listing
            //  - Order
            //  - Message
            //  - Postsale
            SetupTabControlDataGridViewColumns();

            // Check whether the Access file is existed.
            if (DBConnectionUtil.CheckAccessFileExistence() == false)
            {
                MessageBox.Show("数据库文件路径没有配置\r\n系统设置->数据库设置", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //
            // Load all the data.
            //  - Order data.
            //  - Active listing data.
            //  - Message data.
            //  - Postsale data.
            //  This is a bit slow, however simple.
            LoadData();
        }
示例#9
0
        private void buttonDelAccount_Click(object sender, EventArgs e)
        {
            AccountType account = (AccountType)this.listBoxAllAccounts.SelectedItem;

            if (account == null)
            {
                MessageBox.Show("没有选中任何账号", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            bool result = AccountUtil.DeleteOneAccount(account.ebayAccount);

            if (result)
            {
                this.listBoxAllAccounts.Items.Remove(account);
                this.textBoxEbayAccount.Text = "";
                this.textBoxEbayToken.Text   = "";
                MessageBox.Show("删除账号信息成功!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("删除账号信息失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //
        // 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);
            }
        }
示例#11
0
        //
        // http://developer.ebay.com/DevZone/XML/docs/Reference/ebay/AddOrder.html
        //  Only incomplete transactions can be combined, otherwise there will be error message:
        //      "Some transactions have already been completed, you can only combine incomplete transactions".
        //
        public static bool MergeOrders(List <String> transactionIds)
        {
            if (transactionIds.Count < 2)
            {
                return(false);
            }

            // Verify that all transactions are between same buyer and seller.
            String buyer  = "";
            String seller = "";
            Double total  = 0.0;

            foreach (String tranId in transactionIds)
            {
                EbayTransactionType trans = EbayTransactionDAL.GetOneTransactonById(tranId);
                if (trans == null)
                {
                    return(false);
                }

                if (buyer != "" && buyer != trans.BuyerName)
                {
                    return(false);
                }

                if (seller != "" && seller != trans.SellerName)
                {
                    return(false);
                }

                buyer  = trans.BuyerName;
                seller = trans.SellerName;

                total += trans.ItemPrice * trans.SaleQuantity;
            }

            AccountType account = AccountUtil.GetAccount(seller);

            if (account == null)
            {
                return(false);
            }

            AddOrderCall addOrderCall = new AddOrderCall(account.SellerApiContext);
            OrderType    orderType    = new eBay.Service.Core.Soap.OrderType();

            orderType = new eBay.Service.Core.Soap.OrderType();
            orderType.CreatingUserRole = TradingRoleCodeType.Seller;
            orderType.PaymentMethods   = new eBay.Service.Core.Soap.BuyerPaymentMethodCodeTypeCollection();
            orderType.PaymentMethods.Add(BuyerPaymentMethodCodeType.PayPal);
            orderType.Total            = new eBay.Service.Core.Soap.AmountType();
            orderType.Total.Value      = total;
            orderType.Total.currencyID = CurrencyCodeType.USD;
            orderType.TransactionArray = new eBay.Service.Core.Soap.TransactionTypeCollection();

            foreach (String tranId in transactionIds)
            {
                EbayTransactionType trans = EbayTransactionDAL.GetOneTransactonById(tranId);
                if (trans == null)
                {
                    return(false);
                }

                TransactionType tranType = new TransactionType();
                tranType.Item          = new ItemType();
                tranType.Item.ItemID   = trans.ItemId;
                tranType.TransactionID = trans.EbayTransactionId;
                orderType.TransactionArray.Add(tranType);
            }

            String orderId = addOrderCall.AddOrder(orderType);

            return(true);
        }
示例#12
0
        }   // 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
示例#13
0
        // 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
示例#14
0
        private void SendMessageAsync(object sender, DoWorkEventArgs e)
        {
            object[]  paramArr      = e.Argument as object[];
            DataTable dtOrders      = (DataTable)paramArr[0];
            String    messageToSend = (String)paramArr[1];

            int curIdx = 0;

            foreach (DataRow row in dtOrders.Rows)
            {
                curIdx++;

                String sellerName      = StringUtil.GetSafeString(row["SellerName"]);
                String buyerId         = StringUtil.GetSafeString(row["BuyerId"]);
                String itemId          = StringUtil.GetSafeString(row["ItemId"]);
                String orderLineItemId = StringUtil.GetSafeString(row["OrderLineItemId"]);

                EbayTransactionType transLoc = EbayTransactionDAL.GetOneTransaction(orderLineItemId);
                if (transLoc == null)
                {
                    continue;
                }

                String subject = String.Format("{0} sent a message on item {1} with itemId {2}",
                                               sellerName,
                                               buyerId,
                                               itemId);

                AccountType account = AccountUtil.GetAccount(sellerName);
                if (account == null)
                {
                    continue;
                }

                String labelHintStr = String.Format("正在向买家 {0} 发送消息.... 进度 {1} / {2}",
                                                    buyerId, curIdx, dtOrders.Rows.Count);
                int progressBarValue = (int)((double)(curIdx) / dtOrders.Rows.Count * 100);
                frmProgress.SetLabelHintAndProgressBarValue(labelHintStr, progressBarValue);

                if (frmProgress.Cancel)
                {
                    e.Cancel = true;
                    e.Result = curIdx;
                    return;
                }

                messageToSend = replaceMessageMacros(messageToSend, transLoc);

                bool result = EbayMessageBiz.SendMessageToBuyer(account,
                                                                buyerId,
                                                                itemId,
                                                                subject,
                                                                messageToSend,
                                                                true /*emailCopyToSender*/,
                                                                eBay.Service.Core.Soap.QuestionTypeCodeType.General);

                if (result)
                {
                    DateTime startTime = DateTime.Now;
                    DateTime endTime   = startTime;
                    startTime = startTime.Subtract(new TimeSpan(0, 5, 0));

                    startTime = startTime.ToUniversalTime();
                    endTime   = endTime.ToUniversalTime();

                    // Get all message ids within this five minutes.
                    StringCollection msgIds = EbayMessageBiz.GetAllMessageIds(account, startTime, endTime);

                    // Skip the messages we have retrieved.
                    StringCollection newMsgIds = new StringCollection();
                    {
                        foreach (String msgId in msgIds)
                        {
                            EbayMessageType existedMessage = EbayMessageDAL.GetOneMessage(msgId);
                            if (existedMessage != null)
                            {
                                continue;
                            }

                            newMsgIds.Add(msgId);
                        }
                    }

                    List <EbayMessageType> newMessages = EbayMessageBiz.GetAllMessageByIds(account, newMsgIds);

                    Logger.WriteSystemLog(String.Format("Retrieved new messages count={0}", newMsgIds.Count));

                    foreach (EbayMessageType messageType in newMessages)
                    {
                        // We are pretty sure the message didn't exist.
                        EbayMessageDAL.InsertOneMessage(messageType);

                        // Update the transaction message status.
                        String recipientUserId = messageType.RecipientUserId;
                        String senderName      = messageType.Sender;
                        String sellerNameLoc   = messageType.SellerName;
                        String buyerIdLoc      = sellerNameLoc == senderName ? recipientUserId : senderName;

                        // [ZHI_TODO]
                        TransactionMessageStatus messageStatus = EbayMessageDAL.GetTransactionMessageStatus(buyerIdLoc, sellerNameLoc, messageType.ItemID);

                        List <EbayTransactionType> transList = EbayTransactionDAL.GetTransactionsBySellerBuyerItem(sellerNameLoc, buyerIdLoc, messageType.ItemID);
                        foreach (EbayTransactionType trans in transList)
                        {
                            EbayTransactionDAL.UpdateTransactionMessageStatus(trans.TransactionId, messageStatus);
                        }
                    }
                }
                else
                {
                    Logger.WriteSystemUserLog("发送消息失败!");
                }
            }
            e.Result = OrdersDataTable.Rows.Count;
        } // SendMessageAsync