示例#1
0
        private void LoadMsgData()
        {
            DataTable dtMsg = EbayMessageDAL.GetAllTransactionMessagesCompact(EbayTransaction.BuyerId, EbayTransaction.SellerName, EbayTransaction.ItemId);

            this.dataGridViewTransactionMessageSubject.DataSource = dtMsg;

            WebBrowser browser = new WebBrowser();

            this.tabPageAllMessage.Controls.Add(browser);
            browser.Dock = DockStyle.Fill;

            if (dtMsg != null && dtMsg.Rows.Count > 0)
            {
                String ebayMessageId = dtMsg.Rows[0]["EbayMessageId"].ToString();
                if (ebayMessageId == null)
                {
                    return;
                }

                // Display msg in web browser.
                EbayMessageType msg = EbayMessageDAL.GetOneMessage(ebayMessageId);
                if (msg == null)
                {
                    return;
                }

                browser.DocumentText = msg.Text;
            }
        }
示例#2
0
        private void dataGridViewTransactionMessageSubject_SelectionChanged(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection selectedRows = this.dataGridViewTransactionMessageSubject.SelectedRows;

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

            //String ebayMessageId = this.dataGridViewTransactionMessageSubject.Rows[rowIndex].Cells[MessageId_ColumnIndex].Value.ToString();
            String ebayMessageId = selectedRows[0].Cells[MessageId_ColumnIndex].Value.ToString();

            if (null == ebayMessageId)
            {
                return;
            }

            // Display msg in web browser.
            EbayMessageType msg = EbayMessageDAL.GetOneMessage(ebayMessageId);

            if (msg == null)
            {
                return;
            }

            if (msg.IsResponseEnabled && !msg.IsReplied)
            {
                this.buttonReplyMessage.Enabled = true;
            }
            else
            {
                this.buttonReplyMessage.Enabled = false;
            }
        }
示例#3
0
        private void contextMenuStripMsg_Opening(object sender, CancelEventArgs e)
        {
            bool enableMarkAsReplied = false;

            this.ToolStripMenuItemMarkAsReplied.Enabled = false;

            DataGridViewSelectedRowCollection selectedRows = this.dataGridViewTransactionMessageSubject.SelectedRows;

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

            String ebayMessageId = selectedRows[0].Cells[MessageId_ColumnIndex].Value.ToString();

            if (null == ebayMessageId)
            {
                return;
            }

            EbayMessageType msg = EbayMessageDAL.GetOneMessage(ebayMessageId);

            if (msg == null)
            {
                return;
            }

            if (msg.Sender != msg.SellerName && msg.IsReplied == false)
            {
                enableMarkAsReplied = true;
            }

            this.ToolStripMenuItemMarkAsReplied.Enabled = enableMarkAsReplied;
        }
示例#4
0
        private void buttonReplyMessage_Click(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection selectedRows = this.dataGridViewTransactionMessageSubject.SelectedRows;

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

            String ebayMessageId = selectedRows[0].Cells[MessageId_ColumnIndex].Value.ToString();

            if (null == ebayMessageId)
            {
                return;
            }

            // Display msg in web browser.
            EbayMessageType msg = EbayMessageDAL.GetOneMessage(ebayMessageId);

            if (msg == null)
            {
                return;
            }

            FrmReplyBuyerMessage frmReplyBuyer = new FrmReplyBuyerMessage(Account, EbayTransaction, msg);

            frmReplyBuyer.ShowDialog();

            //if (frmReplyBuyer.SentReply)
            //{
            //    FrmUserMessage_Load(sender, e);
            //}
        }
示例#5
0
        private void dataGridViewTransactionMessageSubject_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int colIndex = e.ColumnIndex;
            int rowIndex = e.RowIndex;

            if (rowIndex < 0 || colIndex < 0)
            {
                return;
            }

            String ebayMessageId = this.dataGridViewTransactionMessageSubject.Rows[rowIndex].Cells[MessageId_ColumnIndex].Value.ToString();

            if (null == ebayMessageId)
            {
                return;
            }

            // Display msg in web browser.
            EbayMessageType msg = EbayMessageDAL.GetOneMessage(ebayMessageId);

            if (msg == null)
            {
                return;
            }

            WebBrowser browser = (WebBrowser)this.tabPageAllMessage.Controls[0];

            if (browser == null)
            {
                return;
            }

            browser.DocumentText = msg.Text;
        }
示例#6
0
        }  // GetAllMessageByIds

        // Get all messages between buyers and sellers.
        public static bool GetAllMessages(AccountType account, DateTime startTime, DateTime endTime)
        {
            GetMyMessagesCall getMyMessageApiCall = new GetMyMessagesCall(account.SellerApiContext);

            getMyMessageApiCall.StartTime = startTime;
            getMyMessageApiCall.EndTime   = endTime;

            DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] { DetailLevelCodeType.ReturnHeaders };
            getMyMessageApiCall.DetailLevelList = new DetailLevelCodeTypeCollection(detailLevels);
            getMyMessageApiCall.GetMyMessages();
            MyMessagesMessageTypeCollection messages = getMyMessageApiCall.MessageList;

            foreach (MyMessagesMessageType msg in messages)
            {
                string            msgId = msg.MessageID;
                GetMyMessagesCall getMyMessageApiCall2 = new GetMyMessagesCall(account.SellerApiContext);

                StringCollection msgIds = new StringCollection();
                msgIds.Add(msgId);
                getMyMessageApiCall2.MessageIDList = msgIds;
                detailLevels = new DetailLevelCodeType[] { DetailLevelCodeType.ReturnMessages };
                getMyMessageApiCall2.DetailLevelList = new DetailLevelCodeTypeCollection(detailLevels);
                getMyMessageApiCall2.GetMyMessages();

                MyMessagesMessageType msg2 = getMyMessageApiCall2.MessageList[0];

                EbayMessageType ebayMsg = new EbayMessageType();
                ebayMsg.EbayMessageId     = msgId;
                ebayMsg.SellerName        = account.ebayAccount;
                ebayMsg.MessageType       = msg2.MessageType.ToString();
                ebayMsg.QuestionType      = msg2.QuestionType.ToString();
                ebayMsg.IsRead            = msg2.Read;
                ebayMsg.IsReplied         = msg2.Replied;
                ebayMsg.IsResponseEnabled = msg2.ResponseDetails != null ? msg2.ResponseDetails.ResponseEnabled : false;
                ebayMsg.ResponseURL       = msg2.ResponseDetails != null ? msg2.ResponseDetails.ResponseURL : "";
                ebayMsg.UserResponseDate  = msg2.ResponseDetails != null ? msg2.ResponseDetails.UserResponseDate : DateTime.MinValue;
                ebayMsg.ReceiveDate       = msg2.ReceiveDate;
                ebayMsg.RecipientUserId   = msg2.RecipientUserID;
                ebayMsg.Sender            = msg2.Sender;
                ebayMsg.Subject           = msg2.Subject;
                ebayMsg.IsHighPriority    = msg2.HighPriority;
                ebayMsg.Content           = msg2.Content;
                ebayMsg.Text = msg2.Text;
                ebayMsg.ExternalMessageId = msg2.ExternalMessageID;
                ebayMsg.FolderId          = msg2.Folder != null ? msg2.Folder.FolderID : -1;
                ebayMsg.ItemID            = msg2.ItemID;
                ebayMsg.ItemTitle         = msg2.ItemTitle;
                ebayMsg.ItemEndTime       = msg2.ItemEndTime;
                ebayMsg.ListingStatus     = msg2.ListingStatus.ToString();

                EbayMessageDAL.InsertOneMessage(ebayMsg);
            }

            return(true);
        }  // GetAllMessages
示例#7
0
        private void buttonSendMessage_Click(object sender, EventArgs e)
        {
            String msg = this.rtbMessageToSend.Text.Trim();

            if (msg == "")
            {
                MessageBox.Show("无效的消息正文", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (mAccount == null || mTransaction == null || mMessage == null)
            {
                return;
            }

            this.buttonSendMessage.Enabled = false;

            String subject = String.Format("{0} sent a message on item {1} with itemId {2}",
                                           mTransaction.SellerName,
                                           mTransaction.ItemTitle,
                                           mTransaction.ItemId);

            bool result = EbayMessageBiz.ReplyBuyerMessage(mAccount,
                                                           mTransaction.ItemId,
                                                           mMessage.ExternalMessageId,
                                                           mTransaction.BuyerId,
                                                           msg);

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

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

                StringCollection msgIds = EbayMessageBiz.GetAllMessageIds(mAccount, startTime, endTime);
                EbayMessageBiz.GetAllMessageByIds(mAccount, msgIds);

                //SentReply = true;

                EbayMessageDAL.MarkMessageAsReplied(mMessage.EbayMessageId);

                MessageBox.Show("回复消息成功\r\n", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("发送消息错误,请查看日志", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            this.buttonSendMessage.Enabled = true;
            Close();
        }
示例#8
0
        private void dataGridViewTransactionMessageSubject_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            if (e.ListChangedType == ListChangedType.ItemChanged)
            {
                return;
            }

            for (int rowIdx = 0; rowIdx < this.dataGridViewTransactionMessageSubject.Rows.Count; rowIdx++)
            {
                DataGridViewCell ebayMsgIdCell = this.dataGridViewTransactionMessageSubject.Rows[rowIdx].Cells[MessageId_ColumnIndex];
                if (ebayMsgIdCell.Value == null)
                {
                    continue;
                }

                String ebayMessageId = ebayMsgIdCell.Value.ToString();

                EbayMessageType msg = EbayMessageDAL.GetOneMessage(ebayMessageId);
                if (msg == null)
                {
                    continue;
                }

                if (msg.Sender == msg.SellerName)
                {
                    this.dataGridViewTransactionMessageSubject.Rows[rowIdx].DefaultCellStyle.BackColor = ColorTranslator.FromHtml("#90EE90");
                }
                else
                {
                    if (!msg.IsReplied)
                    {
                        this.dataGridViewTransactionMessageSubject.Rows[rowIdx].DefaultCellStyle.BackColor = ColorTranslator.FromHtml("#FFFF00");
                    }
                    else
                    {
                        this.dataGridViewTransactionMessageSubject.Rows[rowIdx].DefaultCellStyle.BackColor = ColorTranslator.FromHtml("#90EE90");
                    }
                }

                DataGridViewCell receiveDateCell = this.dataGridViewTransactionMessageSubject.Rows[rowIdx].Cells[ReceiveDate_ColumnIndex];
                if (receiveDateCell != null)
                {
                    //DateTime receiveDate = StringUtil.GetSafeDateTime(receiveDateCell.Value);
                    //receiveDate = receiveDate.ToLocalTime();
                    //receiveDateCell.Value = receiveDate;
                }
            }
        }
示例#9
0
        private void ToolStripMenuItemMarkAsReplied_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("你确认将该消息标记为已回复么?",
                                "确认标记?",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
            {
                return;
            }

            DataGridViewSelectedRowCollection selectedRows = this.dataGridViewTransactionMessageSubject.SelectedRows;

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

            String ebayMessageId = selectedRows[0].Cells[MessageId_ColumnIndex].Value.ToString();

            if (null == ebayMessageId)
            {
                return;
            }

            EbayMessageType msg = EbayMessageDAL.GetOneMessage(ebayMessageId);

            if (msg == null)
            {
                return;
            }

            EbayMessageDAL.MarkMessageAsReplied(msg.EbayMessageId);

            TransactionMessageStatus messageStatus
                = EbayMessageDAL.GetTransactionMessageStatus(EbayTransaction.BuyerId, EbayTransaction.SellerName, EbayTransaction.ItemId);

            EbayTransactionDAL.UpdateTransactionMessageStatus(EbayTransaction.TransactionId, messageStatus);

            MessageBox.Show("标记消息为已回复成功。", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);

            LoadMsgData();

            MarkMsgAsReplied = true;
        }
        private void OnDgvDataBindCompleted()
        {
            if (this.pagedDgvMessages.DgvData.Rows.Count == 0)
            {
                return;
            }

            String          ebayMessageId = this.pagedDgvMessages.DgvData.Rows[0].Cells[MessageId_ColumnIndex].Value.ToString();
            EbayMessageType msg           = EbayMessageDAL.GetOneMessage(ebayMessageId);

            if (msg == null)
            {
                return;
            }

            WebBrowser browser = (WebBrowser)this.tabPageAllMessage.Controls[0];

            if (browser == null)
            {
                return;
            }
            browser.DocumentText = msg.Text;
        }
示例#11
0
        private void dataGridViewPostSale_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            if (e.ListChangedType == ListChangedType.ItemChanged)
            {
                return;
            }

            for (int rowIdx = 0; rowIdx < this.dataGridViewPostSale.Rows.Count; rowIdx++)
            {
                DataGridViewCell orderLineItemIdCell = this.dataGridViewPostSale.Rows[rowIdx].Cells[PostSaleDgv_OrderLineItemIdIdx];
                if (orderLineItemIdCell.Value == null)
                {
                    continue;
                }

                String  orderLineItemId = orderLineItemIdCell.Value.ToString();
                DataRow dr = getPostSaleOrderLocally(orderLineItemId);
                if (dr == null)
                {
                    continue;
                }

                int    transId    = StringUtil.GetSafeInt(dr["TransactionId"]);
                String buyerId    = StringUtil.GetSafeString(dr["BuyerId"]);
                String sellerName = StringUtil.GetSafeString(dr["SellerName"]);
                String itemId     = StringUtil.GetSafeString(dr["ItemId"]);

                if (buyerId == "" || sellerName == "" || itemId == "")
                {
                    continue;
                }

                TransactionMessageStatus messageStatus = (TransactionMessageStatus)StringUtil.GetSafeInt(dr["MessageStatus"]);

                if (messageStatus == TransactionMessageStatus.BuyerRepliedSellerNotReplied)
                {
                    TransactionMessageStatus messageStatusComputed
                        = EbayMessageDAL.GetTransactionMessageStatus(buyerId, sellerName, itemId);

                    if (messageStatus != messageStatusComputed)
                    {
                        EbayTransactionDAL.UpdateTransactionMessageStatus(transId, messageStatusComputed);
                        messageStatus = messageStatusComputed;
                    }
                }

                Color rowBkColor = Color.White;
                if (messageStatus == TransactionMessageStatus.SellerInquired)
                {
                    rowBkColor = ColorTranslator.FromHtml("#90EE90");
                }
                else if (messageStatus == TransactionMessageStatus.BuyerRepliedSellerNotReplied)
                {
                    rowBkColor = ColorTranslator.FromHtml("#FFFF00");
                }
                else if (messageStatus == TransactionMessageStatus.BuyerRepliedSellerReplied)
                {
                    rowBkColor = ColorTranslator.FromHtml("#DAA520");
                }

                if (!StringUtil.GetSafeBool(dr["IsPaid"]))
                {
                    rowBkColor = ColorTranslator.FromHtml("#808080");
                }

                this.dataGridViewPostSale.Rows[rowIdx].DefaultCellStyle.BackColor = rowBkColor;
            }
        }
示例#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
        }  // GetAllMessageIds

        public static List <EbayMessageType> GetAllMessageByIds(AccountType account, StringCollection msgIds)
        {
            List <EbayMessageType> messageList = new List <EbayMessageType>();

            if (msgIds.Count > 10)
            {
                Logger.WriteSystemLog("[GetAllMessageByIds]: can only get at most 10 messages once.");
                return(messageList);
            }

            GetMyMessagesCall getMyMessageApiCall = new GetMyMessagesCall(account.SellerApiContext);

            getMyMessageApiCall.MessageIDList = msgIds;
            DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] { DetailLevelCodeType.ReturnMessages };
            getMyMessageApiCall.DetailLevelList = new DetailLevelCodeTypeCollection(detailLevels);
            getMyMessageApiCall.GetMyMessages();
            MyMessagesMessageTypeCollection messages = getMyMessageApiCall.MessageList;

            foreach (MyMessagesMessageType msg in messages)
            {
                // See if this message has already existed.
                String msgId = msg.MessageID;

                EbayMessageType tmpEbayMsg = EbayMessageDAL.GetOneMessage(msgId);
                if (tmpEbayMsg != null && tmpEbayMsg.EbayMessageId != "")
                {
                    Logger.WriteSystemLog(string.Format("[GetAllMessageByIds]: message with id={0} has already existed, skip and continue.", msgId));
                    continue;
                }

                EbayMessageType ebayMsg = new EbayMessageType();
                ebayMsg.EbayMessageId     = msg.MessageID;
                ebayMsg.SellerName        = account.ebayAccount;
                ebayMsg.MessageType       = msg.MessageType.ToString();
                ebayMsg.QuestionType      = msg.QuestionType.ToString();
                ebayMsg.IsRead            = msg.Read;
                ebayMsg.IsReplied         = msg.Replied;
                ebayMsg.IsResponseEnabled = msg.ResponseDetails != null ? msg.ResponseDetails.ResponseEnabled : false;
                ebayMsg.ResponseURL       = msg.ResponseDetails != null ? msg.ResponseDetails.ResponseURL : "";
                ebayMsg.UserResponseDate  = msg.ResponseDetails != null ? msg.ResponseDetails.UserResponseDate : DateTime.MinValue;
                ebayMsg.ReceiveDate       = msg.ReceiveDate;
                //ebayMsg.RecipientUserId = msg.RecipientUserID;
                ebayMsg.RecipientUserId = msg.SendToName;
                ebayMsg.Sender          = msg.Sender;
                ebayMsg.Subject         = msg.Subject;
                ebayMsg.IsHighPriority  = msg.HighPriority;
                // The message body. Plain text.
                ebayMsg.Content = msg.Content;
                // This field contains message content, and can contain a threaded message.
                // Max length: 2 megabytes in size.
                ebayMsg.Text = msg.Text;
                ebayMsg.ExternalMessageId = msg.ExternalMessageID;
                ebayMsg.FolderId          = msg.Folder != null ? msg.Folder.FolderID : -1;
                ebayMsg.ItemID            = msg.ItemID;
                ebayMsg.ItemTitle         = msg.ItemTitle;
                ebayMsg.ItemEndTime       = msg.ItemEndTime;
                ebayMsg.ListingStatus     = msg.ListingStatus.ToString();

                messageList.Add(ebayMsg);
            }

            return(messageList);
        }  // GetAllMessageByIds
示例#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