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; } }
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); //} }
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; }
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; } }
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; }
public static EbayMessageType GetOneMessage(String ebayMessageId) { String sql_getAllMessages = String.Format("select * from [Message] where EbayMessageId='{0}'", ebayMessageId); DataTable dt = DbAccess.ExecuteSqlReturnTable(sql_getAllMessages); if (dt.Rows.Count == 0) return null; DataRow dr = dt.Rows[0]; EbayMessageType msg = new EbayMessageType(); msg.MessageId = StringUtil.GetSafeInt(dr["MessageId"]); msg.SellerName = StringUtil.GetSafeString(dr["SellerName"]); msg.EbayMessageId = StringUtil.GetSafeString(dr["EbayMessageId"]); msg.MessageType = StringUtil.GetSafeString(dr["MessageType"]); msg.QuestionType = StringUtil.GetSafeString(dr["QuestionType"]); msg.IsRead = StringUtil.GetSafeBool(dr["IsRead"]); msg.IsReplied = StringUtil.GetSafeBool(dr["IsReplied"]); msg.IsResponseEnabled = StringUtil.GetSafeBool(dr["IsResponseEnabled"]); msg.ResponseURL = StringUtil.GetSafeString(dr["ResponseURL"]); msg.UserResponseDate = StringUtil.GetSafeDateTime(dr["UserResponseDate"]); msg.ReceiveDate = StringUtil.GetSafeDateTime(dr["ReceiveDate"]); msg.Sender = StringUtil.GetSafeString(dr["Sender"]); msg.RecipientUserId = StringUtil.GetSafeString(dr["RecipientUserId"]); msg.Subject = StringUtil.GetSafeString(dr["Subject"]); msg.Content = StringUtil.GetSafeString(dr["MessageContent"]); msg.Text = StringUtil.GetSafeString(dr["MessageText"]); msg.ExternalMessageId = StringUtil.GetSafeString(dr["ExternalMessageId"]); msg.FolderId = StringUtil.GetSafeInt(dr["FolderId"]); msg.ItemID = StringUtil.GetSafeString(dr["ItemID"]); msg.ItemTitle = StringUtil.GetSafeString(dr["ItemTitle"]); // ZHI_TODO: return msg; }
public FrmReplyBuyerMessage(AccountType account, EbayTransactionType trans, EbayMessageType message) { InitializeComponent(); mTransaction = trans; mAccount = account; mMessage = message; }
} // 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
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; } } }
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; }
// obsoleted public static EbayMessageType GetUserTransactionMessage(String senderId, String itemId) { String sql_getAllMessages = "select * from [Message] where Sender='" + senderId + "' and ItemId='" + itemId + "' order by ReceiveDate desc"; DataTable dt = DataFactory.ExecuteSqlReturnTable(sql_getAllMessages); if (dt.Rows.Count == 0) { return(null); } DataRow dr = dt.Rows[0]; EbayMessageType msg = new EbayMessageType(); msg.EbayMessageId = dr["EbayMessageId"].ToString(); msg.IsRead = (bool)dr["IsRead"]; msg.Sender = dr["Sender"].ToString(); msg.Subject = dr["Sender"].ToString(); msg.ItemID = dr["Sender"].ToString(); // ZHI_TODO: return(msg); }
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; }
public static EbayMessageType GetOneMessage(String ebayMessageId) { String sql_getAllMessages = String.Format("select * from [Message] where EbayMessageId='{0}'", ebayMessageId); DataTable dt = DbAccess.ExecuteSqlReturnTable(sql_getAllMessages); if (dt.Rows.Count == 0) { return(null); } DataRow dr = dt.Rows[0]; EbayMessageType msg = new EbayMessageType(); msg.MessageId = StringUtil.GetSafeInt(dr["MessageId"]); msg.SellerName = StringUtil.GetSafeString(dr["SellerName"]); msg.EbayMessageId = StringUtil.GetSafeString(dr["EbayMessageId"]); msg.MessageType = StringUtil.GetSafeString(dr["MessageType"]); msg.QuestionType = StringUtil.GetSafeString(dr["QuestionType"]); msg.IsRead = StringUtil.GetSafeBool(dr["IsRead"]); msg.IsReplied = StringUtil.GetSafeBool(dr["IsReplied"]); msg.IsResponseEnabled = StringUtil.GetSafeBool(dr["IsResponseEnabled"]); msg.ResponseURL = StringUtil.GetSafeString(dr["ResponseURL"]); msg.UserResponseDate = StringUtil.GetSafeDateTime(dr["UserResponseDate"]); msg.ReceiveDate = StringUtil.GetSafeDateTime(dr["ReceiveDate"]); msg.Sender = StringUtil.GetSafeString(dr["Sender"]); msg.RecipientUserId = StringUtil.GetSafeString(dr["RecipientUserId"]); msg.Subject = StringUtil.GetSafeString(dr["Subject"]); msg.Content = StringUtil.GetSafeString(dr["MessageContent"]); msg.Text = StringUtil.GetSafeString(dr["MessageText"]); msg.ExternalMessageId = StringUtil.GetSafeString(dr["ExternalMessageId"]); msg.FolderId = StringUtil.GetSafeInt(dr["FolderId"]); msg.ItemID = StringUtil.GetSafeString(dr["ItemID"]); msg.ItemTitle = StringUtil.GetSafeString(dr["ItemTitle"]); // ZHI_TODO: return(msg); } // GetOneMessage
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
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; }
// 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; }
public static bool InsertOneMessage(EbayMessageType msg) { if (!msg.isValid()) { return(false); } OleDbCommand cmd = new OleDbCommand(null, DbAccess.DbConn); cmd.CommandText = @"Insert into [Message] (EbayMessageId, SellerName, MessageType, QuestionType, IsRead, IsReplied, " + "IsResponseEnabled, ResponseURL, UserResponseDate, ReceiveDate, RecipientUserId," + "Sender, Subject, IsHighPriority, MessageContent, MessageText, " + "ExternalMessageId, FolderId, ItemID, ItemTitle, ItemEndTime, ListingStatus) values (" + " @EbayMessageId, @SellerName, @MessageType, @QuestionType, @IsRead, @IsReplied, " + " @IsResponseEnabled, @ResponseURL, @UserResponseDate, @ReceiveDate, @RecipientUserId," + " @Sender, @Subject, @IsHighPriority, @MessageContent, @MessageText, " + " @ExternalMessageId, @FolderId, @ItemID, @ItemTitle, @ItemEndTime, @ListingStatus)"; cmd.Parameters.Add("@EbayMessageId", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.EbayMessageId); cmd.Parameters.Add("@SellerName", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.SellerName); cmd.Parameters.Add("@MessageType", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.MessageType); cmd.Parameters.Add("@QuestionType", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.QuestionType); cmd.Parameters.Add("@IsRead", OleDbType.Boolean).Value = msg.IsRead; cmd.Parameters.Add("@IsReplied", OleDbType.Boolean).Value = msg.IsReplied; cmd.Parameters.Add("@IsResponseEnabled", OleDbType.Boolean).Value = msg.IsResponseEnabled; cmd.Parameters.Add("@ResponseURL", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.ResponseURL); cmd.Parameters.Add("@UserResponseDate", OleDbType.Date).Value = StringUtil.GetSafeDateTime(msg.UserResponseDate); cmd.Parameters.Add("@ReceiveDate", OleDbType.Date).Value = StringUtil.GetSafeDateTime(msg.ReceiveDate); cmd.Parameters.Add("@RecipientUserId", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.RecipientUserId); cmd.Parameters.Add("@Sender", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.Sender); cmd.Parameters.Add("@Subject", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.Subject); cmd.Parameters.Add("@IsHighPriority", OleDbType.Boolean).Value = msg.IsHighPriority; cmd.Parameters.Add("@MessageContent", OleDbType.LongVarChar).Value = StringUtil.GetSafeString(msg.Content); cmd.Parameters.Add("@MessageText", OleDbType.LongVarChar).Value = StringUtil.GetSafeString(msg.Text); cmd.Parameters.Add("@ExternalMessageId", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.ExternalMessageId); cmd.Parameters.Add("@FolderId", OleDbType.BigInt).Value = msg.FolderId; cmd.Parameters.Add("@ItemID", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.ItemID); cmd.Parameters.Add("@ItemTitle", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.ItemTitle); cmd.Parameters.Add("@ItemEndTime", OleDbType.Date).Value = StringUtil.GetSafeDateTime(msg.ItemEndTime); cmd.Parameters.Add("@ListingStatus", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.ListingStatus); bool result = false; try { if (DbAccess.DbConn.State == ConnectionState.Closed) { DbAccess.DbConn.Open(); } cmd.ExecuteNonQuery(); result = true; } catch (OleDbException ex) { // Write to log here. Logger.WriteSystemLog(string.Format("Error : {0}", ex.Message)); result = false; } finally { if (DbAccess.DbConn.State == ConnectionState.Open) { DbAccess.DbConn.Close(); } } return(result); } // InsertOneMessage
} // 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
public static bool InsertOneMessage(EbayMessageType msg) { if (!msg.isValid()) return false; OleDbCommand cmd = new OleDbCommand(null, DbAccess.DbConn); cmd.CommandText = @"Insert into [Message] (EbayMessageId, SellerName, MessageType, QuestionType, IsRead, IsReplied, " + "IsResponseEnabled, ResponseURL, UserResponseDate, ReceiveDate, RecipientUserId," + "Sender, Subject, IsHighPriority, MessageContent, MessageText, " + "ExternalMessageId, FolderId, ItemID, ItemTitle, ItemEndTime, ListingStatus) values (" + " @EbayMessageId, @SellerName, @MessageType, @QuestionType, @IsRead, @IsReplied, " + " @IsResponseEnabled, @ResponseURL, @UserResponseDate, @ReceiveDate, @RecipientUserId," + " @Sender, @Subject, @IsHighPriority, @MessageContent, @MessageText, " + " @ExternalMessageId, @FolderId, @ItemID, @ItemTitle, @ItemEndTime, @ListingStatus)"; cmd.Parameters.Add("@EbayMessageId", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.EbayMessageId); cmd.Parameters.Add("@SellerName", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.SellerName); cmd.Parameters.Add("@MessageType", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.MessageType); cmd.Parameters.Add("@QuestionType", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.QuestionType); cmd.Parameters.Add("@IsRead", OleDbType.Boolean).Value = msg.IsRead; cmd.Parameters.Add("@IsReplied", OleDbType.Boolean).Value = msg.IsReplied; cmd.Parameters.Add("@IsResponseEnabled", OleDbType.Boolean).Value = msg.IsResponseEnabled; cmd.Parameters.Add("@ResponseURL", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.ResponseURL); cmd.Parameters.Add("@UserResponseDate", OleDbType.Date).Value = StringUtil.GetSafeDateTime(msg.UserResponseDate); cmd.Parameters.Add("@ReceiveDate", OleDbType.Date).Value = StringUtil.GetSafeDateTime(msg.ReceiveDate); cmd.Parameters.Add("@RecipientUserId", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.RecipientUserId); cmd.Parameters.Add("@Sender", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.Sender); cmd.Parameters.Add("@Subject", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.Subject); cmd.Parameters.Add("@IsHighPriority", OleDbType.Boolean).Value = msg.IsHighPriority; cmd.Parameters.Add("@MessageContent", OleDbType.LongVarChar).Value = StringUtil.GetSafeString(msg.Content); cmd.Parameters.Add("@MessageText", OleDbType.LongVarChar).Value = StringUtil.GetSafeString(msg.Text); cmd.Parameters.Add("@ExternalMessageId", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.ExternalMessageId); cmd.Parameters.Add("@FolderId", OleDbType.BigInt).Value = msg.FolderId; cmd.Parameters.Add("@ItemID", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.ItemID); cmd.Parameters.Add("@ItemTitle", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.ItemTitle); cmd.Parameters.Add("@ItemEndTime", OleDbType.Date).Value = StringUtil.GetSafeDateTime(msg.ItemEndTime); cmd.Parameters.Add("@ListingStatus", OleDbType.VarChar).Value = StringUtil.GetSafeString(msg.ListingStatus); bool result = false; try { if (DbAccess.DbConn.State == ConnectionState.Closed) DbAccess.DbConn.Open(); cmd.ExecuteNonQuery(); result = true; } catch (OleDbException ex) { // Write to log here. Logger.WriteSystemLog(string.Format("Error : {0}", ex.Message)); result = false; } finally { if (DbAccess.DbConn.State == ConnectionState.Open) DbAccess.DbConn.Close(); } return result; }
// obsoleted public static EbayMessageType GetUserTransactionMessage(String senderId, String itemId) { String sql_getAllMessages = "select * from [Message] where Sender='" + senderId + "' and ItemId='" + itemId + "' order by ReceiveDate desc"; DataTable dt = DataFactory.ExecuteSqlReturnTable(sql_getAllMessages); if (dt.Rows.Count == 0) return null; DataRow dr = dt.Rows[0]; EbayMessageType msg = new EbayMessageType(); msg.EbayMessageId = dr["EbayMessageId"].ToString(); msg.IsRead = (bool)dr["IsRead"]; msg.Sender = dr["Sender"].ToString(); msg.Subject = dr["Sender"].ToString(); msg.ItemID = dr["Sender"].ToString(); // ZHI_TODO: return msg; }
} // 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